summaryrefslogtreecommitdiff
blob: d77402aff52b135966012f43f2f969db8e310886 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
diff --git a/vsock-only/Makefile b/vsock-only/Makefile
index 5d92e9b..7d315e8 100644
--- a/vsock-only/Makefile
+++ b/vsock-only/Makefile
@@ -42,8 +42,11 @@ AUTOCONF_DIR := $(SRCROOT)/shared/autoconf
 INCLUDE      += -I$(SRCROOT)/shared
 endif
 
-
+ifdef KVERSION
+VM_UNAME = $(KVERSION)
+else
 VM_UNAME = $(shell uname -r)
+endif
 
 # Header directory for the running kernel
 ifdef LINUXINCLUDE
diff --git a/vsock-only/Makefile.kernel b/vsock-only/Makefile.kernel
index 5218df2..374cc1f 100644
--- a/vsock-only/Makefile.kernel
+++ b/vsock-only/Makefile.kernel
@@ -25,7 +25,7 @@ INCLUDE += -I$(SRCROOT)/include
 INCLUDE += -I$(SRCROOT)/linux
 INCLUDE += -I$(SRCROOT)/common
 
-EXTRA_CFLAGS := $(CC_OPTS) $(INCLUDE)
+EXTRA_CFLAGS := $(CC_OPTS) $(INCLUDE) $(LINUXINCLUDE)
 EXTRA_CFLAGS += $(call vm_check_build, $(AUTOCONF_DIR)/netcreate_num_params.c, -DVMW_NETCREATE_KERNARG, )
 
 
diff --git a/vsock-only/linux/af_vsock.c b/vsock-only/linux/af_vsock.c
index bde1497..9f8f843 100644
--- a/vsock-only/linux/af_vsock.c
+++ b/vsock-only/linux/af_vsock.c
@@ -113,6 +113,9 @@
 asmlinkage __attribute__((weak)) long
 sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg);
 #endif
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 99)
+#include <linux/sched/signal.h>
+#endif
 
 #include "compat_cred.h"
 #include "compat_module.h"
@@ -213,7 +216,11 @@
                                  struct sockaddr *addr, int addrLen, int flags);
 static int VSockVmciStreamConnect(struct socket *sock,
                                   struct sockaddr *addr, int addrLen, int flags);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
 static int VSockVmciAccept(struct socket *sock, struct socket *newsock, int flags);
+#else
+static int VSockVmciAccept(struct socket *sock, struct socket *newsock, int flags, bool kern);
+#endif
 static int VSockVmciGetname(struct socket *sock,
                             struct sockaddr *addr, int *addrLen, int peer);
 static unsigned int VSockVmciPoll(struct file *file,
@@ -233,13 +240,29 @@ static int VSockVmciStreamSetsockopt(struct socket *sock, int level, int optname
 static int VSockVmciStreamGetsockopt(struct socket *sock, int level, int optname,
                                      char __user *optval, int __user * optlen);
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 99)
 static int VSockVmciDgramSendmsg(struct kiocb *kiocb,
+#else
+static int VSockVmciDgramSendmsg(
+#endif
                                  struct socket *sock, struct msghdr *msg, size_t len);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 99)
 static int VSockVmciDgramRecvmsg(struct kiocb *kiocb, struct socket *sock,
+#else
+static int VSockVmciDgramRecvmsg(struct socket *sock,
+#endif
                                  struct msghdr *msg, size_t len, int flags);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 99)
 static int VSockVmciStreamSendmsg(struct kiocb *kiocb,
+#else
+static int VSockVmciStreamSendmsg(
+#endif
                                  struct socket *sock, struct msghdr *msg, size_t len);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 99)
 static int VSockVmciStreamRecvmsg(struct kiocb *kiocb, struct socket *sock,
+#else
+static int VSockVmciStreamRecvmsg(struct socket *sock,
+#endif
                                  struct msghdr *msg, size_t len, int flags);
 
 static int VSockVmciCreate(
@@ -2872,11 +2895,18 @@ __VSockVmciCreate(struct net *net,       // IN: Network namespace
     * From 2.6.9 to until 2.6.12 sk_alloc() used a cache in
     * the protocol structure, but you still had to specify the size and cache
     * yourself.
-    * Most recently (in 2.6.24), sk_alloc() was changed to expect the
+    * In 2.6.24, sk_alloc() was changed to expect the
     * network namespace, and the option to zero the sock was dropped.
     *
+    * In 4.2, another parameter was added to sk_alloc() allowing you to specify
+    * whether or not the socket is to be a kernel socket. Previously, we passed
+    * 1 to this new parameter, but following Gentoo's lead
+    * ( https://github.com/gentoo/vmware/blob/master/app-emulation/vmware-modules/files/308-4.02-01-sk_alloc.patch#L19 )
+    * we have switched to passing 0.
     */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 12)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 99)
+   sk = sk_alloc(net, vsockVmciFamilyOps.family, priority, &vsockVmciProto, 0);
+#elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 12)
    sk = sk_alloc(vsockVmciFamilyOps.family, priority,
                  vsockVmciProto.slab_obj_size, vsockVmciProto.slab);
 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
@@ -3825,7 +3855,12 @@
 static int
 VSockVmciAccept(struct socket *sock,     // IN
                 struct socket *newsock,  // IN/OUT
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
                 int flags)               // IN
+#else
+                int flags,               // IN
+                bool kern)
+#endif
 {
    struct sock *listener;
    int err;
@@ -4260,7 +4295,11 @@ VSockVmciShutdown(struct socket *sock,  // IN
  */
 
 static int
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 99)
 VSockVmciDgramSendmsg(struct kiocb *kiocb,          // UNUSED
+#else
+VSockVmciDgramSendmsg(
+#endif
                       struct socket *sock,          // IN: socket to send on
                       struct msghdr *msg,           // IN: message to send
                       size_t len)                   // IN: length of message
@@ -4352,7 +4391,11 @@ VSockVmciDgramSendmsg(struct kiocb *kiocb,          // UNUSED
       goto out;
    }
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)
    memcpy_fromiovec(VMCI_DG_PAYLOAD(dg), msg->msg_iov, len);
+#else
+   memcpy_from_msg(VMCI_DG_PAYLOAD(dg), msg, len);
+#endif
 
    dg->dst = VMCI_MAKE_HANDLE(remoteAddr->svm_cid, remoteAddr->svm_port);
    dg->src = VMCI_MAKE_HANDLE(vsk->localAddr.svm_cid, vsk->localAddr.svm_port);
@@ -4590,7 +4633,11 @@ VSockVmciStreamGetsockopt(struct socket *sock,          // IN
  */
 
 static int
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 99)
 VSockVmciStreamSendmsg(struct kiocb *kiocb,          // UNUSED
+#else
+VSockVmciStreamSendmsg(
+#endif
                        struct socket *sock,          // IN: socket to send on
                        struct msghdr *msg,           // IN: message to send
                        size_t len)                   // IN: length of message
@@ -4712,7 +4759,11 @@ VSockVmciStreamSendmsg(struct kiocb *kiocb,          // UNUSED
        * able to send.
        */
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)
       written = vmci_qpair_enquev(vsk->qpair, msg->msg_iov,
+#else
+      written = vmci_qpair_enquev(vsk->qpair, &msg->msg_iter.iov,
+#endif
                                   len - totalWritten, 0);
       if (written < 0) {
          err = -ENOMEM;
@@ -4759,7 +4810,11 @@ out:
  */
 
 static int
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 99)
 VSockVmciDgramRecvmsg(struct kiocb *kiocb,          // UNUSED
+#else
+VSockVmciDgramRecvmsg(
+#endif
                       struct socket *sock,          // IN: socket to receive from
                       struct msghdr *msg,           // IN/OUT: message to receive into
                       size_t len,                   // IN: length of receive buffer
@@ -4809,7 +4864,11 @@ VSockVmciDgramRecvmsg(struct kiocb *kiocb,          // UNUSED
    }
 
    /* Place the datagram payload in the user's iovec. */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)
    err = skb_copy_datagram_iovec(skb, sizeof *dg, msg->msg_iov, payloadLen);
+#else
+   err = skb_copy_datagram_iter(skb, sizeof *dg, &msg->msg_iter, payloadLen);
+#endif
    if (err) {
       goto out;
    }
@@ -4850,7 +4909,11 @@ out:
  */
 
 static int
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 99)
 VSockVmciStreamRecvmsg(struct kiocb *kiocb,          // UNUSED
+#else
+VSockVmciStreamRecvmsg(
+#endif
                        struct socket *sock,          // IN: socket to receive from
                        struct msghdr *msg,           // IN/OUT: message to receive into
                        size_t len,                   // IN: length of receive buffer
@@ -4955,9 +5018,17 @@ VSockVmciStreamRecvmsg(struct kiocb *kiocb,          // UNUSED
          }
 
          if (flags & MSG_PEEK) {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)
             read = vmci_qpair_peekv(vsk->qpair, msg->msg_iov, len - copied, 0);
+#else
+            read = vmci_qpair_peekv(vsk->qpair, &msg->msg_iter.iov, len - copied, 0);
+#endif
          } else {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)
             read = vmci_qpair_dequev(vsk->qpair, msg->msg_iov, len - copied, 0);
+#else
+            read = vmci_qpair_dequev(vsk->qpair, &msg->msg_iter.iov, len - copied, 0);
+#endif
          }
 
          if (read < 0) {
diff --git a/vsock-only/linux/notify.c b/vsock-only/linux/notify.c
index 5b1e134..82d8738 100644
--- a/vsock-only/linux/notify.c
+++ b/vsock-only/linux/notify.c
@@ -516,7 +516,11 @@ VSockVmciHandleWrote(struct sock *sk,            // IN
    PKT_FIELD(vsk, sentWaitingRead) = FALSE;
 #endif
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0)
    sk->sk_data_ready(sk, 0);
+#else
+   sk->sk_data_ready(sk);
+#endif
 }
 
 
diff --git a/vsock-only/linux/notifyQState.c b/vsock-only/linux/notifyQState.c
index 464454b..7933be7 100644
--- a/vsock-only/linux/notifyQState.c
+++ b/vsock-only/linux/notifyQState.c
@@ -164,7 +164,11 @@ VSockVmciHandleWrote(struct sock *sk,            // IN
                      struct sockaddr_vm *dst,    // IN: unused
                      struct sockaddr_vm *src)    // IN: unused
 {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0)
    sk->sk_data_ready(sk, 0);
+#else
+   sk->sk_data_ready(sk);
+#endif
 }
 
 
@@ -566,7 +570,11 @@ VSockVmciNotifyPktRecvPostDequeue(struct sock *sk,               // IN
       }
 
       /* See the comment in VSockVmciNotifyPktSendPostEnqueue */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0)
       sk->sk_data_ready(sk, 0);
+#else
+      sk->sk_data_ready(sk);
+#endif
    }
 
    return err;