summarylogtreecommitdiffstats
path: root/vmnet.patch
blob: 7b3f07e10e8be55443d3a0d3f672a34ae00015da (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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
diff --git a/vmnet/Makefile b/vmnet/Makefile
index 459846e..cd29652 100644
--- a/vmnet/Makefile
+++ b/vmnet/Makefile
@@ -43,7 +43,11 @@ 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/vmnet/Makefile.kernel b/vmnet/Makefile.kernel
index 2d8e6f6..a14166b 100644
--- a/vmnet/Makefile.kernel
+++ b/vmnet/Makefile.kernel
@@ -19,7 +19,7 @@
 
 INCLUDE := -I$(SRCROOT)
 
-EXTRA_CFLAGS := $(CC_OPTS) $(INCLUDE)
+EXTRA_CFLAGS := $(CC_OPTS) $(INCLUDE) $(LINUXINCLUDE)
 EXTRA_CFLAGS += $(call vm_check_build, $(SRCROOT)/netdev_has_net.c,-DVMW_NETDEV_HAS_NET, )
 EXTRA_CFLAGS += $(call vm_check_build, $(SRCROOT)/netdev_has_dev_net.c,-DVMW_NETDEV_HAS_DEV_NET, )
 EXTRA_CFLAGS += $(call vm_check_build, $(SRCROOT)/nfhook_uses_skb.c,-DVMW_NFHOOK_USES_SKB, )
diff --git a/vmnet/driver.c b/vmnet/driver.c
index 7e7ad99..5f508f6 100644
--- a/vmnet/driver.c
+++ b/vmnet/driver.c
@@ -137,7 +137,16 @@ static ssize_t  VNetFileOpWrite(struct file *filp, const char *buf, size_t count
 static long  VNetFileOpUnlockedIoctl(struct file * filp,
                                      unsigned int iocmd, unsigned long ioarg);
 
-static struct file_operations vnetFileOps;
+static struct file_operations vnetFileOps = {
+   .owner = THIS_MODULE,
+   .read = VNetFileOpRead,
+   .write = VNetFileOpWrite,
+   .poll = VNetFileOpPoll,
+   .unlocked_ioctl = VNetFileOpUnlockedIoctl,
+   .compat_ioctl = VNetFileOpUnlockedIoctl,
+   .open = VNetFileOpOpen,
+   .release = VNetFileOpClose
+};
 
 /*
  * Utility functions
@@ -317,22 +326,6 @@ init_module(void)
       goto err_proto;
    }
 
-   /*
-    * Initialize the file_operations structure. Because this code is always
-    * compiled as a module, this is fine to do it here and not in a static
-    * initializer.
-    */
-
-   memset(&vnetFileOps, 0, sizeof vnetFileOps);
-   vnetFileOps.owner = THIS_MODULE;
-   vnetFileOps.read = VNetFileOpRead;
-   vnetFileOps.write = VNetFileOpWrite;
-   vnetFileOps.poll = VNetFileOpPoll;
-   vnetFileOps.unlocked_ioctl = VNetFileOpUnlockedIoctl;
-   vnetFileOps.compat_ioctl = VNetFileOpUnlockedIoctl;
-   vnetFileOps.open = VNetFileOpOpen;
-   vnetFileOps.release = VNetFileOpClose;
-
    retval = register_chrdev(VNET_MAJOR_NUMBER, "vmnet", &vnetFileOps);
    if (retval) {
       LOG(0, (KERN_NOTICE "/dev/vmnet: could not register major device %d\n",
@@ -1145,12 +1138,12 @@ VNetMulticastFilter(const uint8 *destAddr,        // IN: multicast MAC
       }
       /*
        * Do not need to further compute and check ladrf if no match
-       * in exact multicast filter, since only one of them is 
+       * in exact multicast filter, since only one of them is
        * used at a time.
        */
       return FALSE;
    }
-   
+
 
    crc = 0xffffffff;                  /* init CRC for each address */
    for (byte = 0; byte < ETH_ALEN; byte++) { /* for each address byte */
diff --git a/vmnet/userif.c b/vmnet/userif.c
index 94146f6..5298406 100644
--- a/vmnet/userif.c
+++ b/vmnet/userif.c
@@ -113,14 +113,18 @@ UserifLockPage(VA addr) // IN
    int retval;
 
    down_read(&current->mm->mmap_sem);
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
-   retval = get_user_pages(addr, 1, FOLL_WRITE, &page, NULL);
-#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)
-   retval = get_user_pages(addr, 1, 1, 0, &page, NULL);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 99)
+   retval = get_user_pages(addr,
 #else
    retval = get_user_pages(current, current->mm, addr,
-                           1, 1, 0, &page, NULL);
 #endif
+                           1,
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0)
+                           1, 0,
+#else
+                           FOLL_WRITE,
+#endif
+                           &page, NULL);
    up_read(&current->mm->mmap_sem);
 
    if (retval != 1) {
@@ -184,13 +188,13 @@ VNetUserIfMapUint32Ptr(VA uAddr,        // IN: pointer to user memory
  *
  *    Sets up notification by filling in pollPtr, actPtr, and recvClusterCount
  *    fields.
- * 
- * Results: 
+ *
+ * Results:
  *    0 on success
  *    < 0 on failure: the actual value determines the type of failure
  *
  * Side effects:
- *    Fields pollPtr, actPtr, recvClusterCount, pollPage, actPage, and 
+ *    Fields pollPtr, actPtr, recvClusterCount, pollPage, actPage, and
  *    recvClusterPage are filled in VNetUserIf structure.
  *
  *-----------------------------------------------------------------------------
@@ -280,8 +284,8 @@ VNetUserIfSetupNotify(VNetUserIF *userIf, // IN
  * VNetUserIfUnsetupNotify --
  *
  *      Destroys permanent mapping for notify structure provided by user.
- * 
- * Results: 
+ *
+ * Results:
  *      None.
  *
  * Side effects:
@@ -335,7 +339,7 @@ VNetUserIfUnsetupNotify(VNetUserIF *userIf) // IN
  *
  *      Free the user interface port.
  *
- * Results: 
+ * Results:
  *      None.
  *
  * Side effects:
@@ -357,7 +361,7 @@ VNetUserIfFree(VNetJack *this) // IN
       }
       dev_kfree_skb(skb);
    }
-   
+
    if (userIf->pollPtr) {
       VNetUserIfUnsetupNotify(userIf);
    }
@@ -381,7 +385,7 @@ VNetUserIfFree(VNetJack *this) // IN
  *
  *      This jack is receiving a packet. Take appropriate action.
  *
- * Results: 
+ * Results:
  *      None.
  *
  * Side effects:
@@ -397,12 +401,12 @@ VNetUserIfReceive(VNetJack       *this, // IN
    VNetUserIF *userIf = (VNetUserIF*)this->private;
    uint8 *dest = SKB_2_DESTMAC(skb);
    unsigned long flags;
-   
+
    if (!UP_AND_RUNNING(userIf->port.flags)) {
       userIf->stats.droppedDown++;
       goto drop_packet;
    }
-   
+
    if (!VNetPacketMatch(dest,
                         userIf->port.paddr,
                         (const uint8 *)userIf->port.exactFilter,
@@ -412,12 +416,12 @@ VNetUserIfReceive(VNetJack       *this, // IN
       userIf->stats.droppedMismatch++;
       goto drop_packet;
    }
-   
+
    if (skb_queue_len(&userIf->packetQueue) >= vnet_max_qlen) {
       userIf->stats.droppedOverflow++;
       goto drop_packet;
    }
-   
+
    if (skb->len > ETHER_MAX_QUEUED_PACKET) {
       userIf->stats.droppedLargePacket++;
       goto drop_packet;
@@ -441,7 +445,7 @@ VNetUserIfReceive(VNetJack       *this, // IN
 
    wake_up(&userIf->waitQueue);
    return;
-   
+
  drop_packet:
    dev_kfree_skb(skb);
 }
@@ -454,7 +458,7 @@ VNetUserIfReceive(VNetJack       *this, // IN
  *
  *      Callback for read operation on this userif entry in vnets proc fs.
  *
- * Results: 
+ * Results:
  *      Length of read operation.
  *
  * Side effects:
@@ -473,21 +477,21 @@ VNetUserIfProcRead(char    *page,  // IN/OUT: buffer to write into
                                    //      read
                    void    *data)  // IN: client data - not used
 {
-   VNetUserIF *userIf = (VNetUserIF*)data; 
+   VNetUserIF *userIf = (VNetUserIF*)data;
    int len = 0;
-   
+
    if (!userIf) {
       return len;
    }
-   
+
    len += VNetPrintPort(&userIf->port, page+len);
-   
+
    len += sprintf(page+len, "read %u written %u queued %u ",
                   userIf->stats.read,
                   userIf->stats.written,
                   userIf->stats.queued);
-   
-   len += sprintf(page+len, 
+
+   len += sprintf(page+len,
 		  "dropped.down %u dropped.mismatch %u "
 		  "dropped.overflow %u dropped.largePacket %u",
                   userIf->stats.droppedDown,
@@ -496,7 +500,7 @@ VNetUserIfProcRead(char    *page,  // IN/OUT: buffer to write into
 		  userIf->stats.droppedLargePacket);
 
    len += sprintf(page+len, "\n");
-   
+
    *start = 0;
    *eof   = 1;
    return len;
@@ -510,7 +514,7 @@ VNetUserIfProcRead(char    *page,  // IN/OUT: buffer to write into
  *
  *      Copy part of datagram to userspace.
  *
- * Results: 
+ * Results:
  *	zero    on success,
  *	-EFAULT if buffer is an invalid area
  *
@@ -547,12 +551,12 @@ VNetCopyDatagram(const struct sk_buff *skb,	// IN: skb to copy
  *
  *      Copy part of datagram to userspace doing checksum at same time.
  *
- *	Do not mark this function INLINE, it is recursive! With all gcc's 
+ *	Do not mark this function INLINE, it is recursive! With all gcc's
  *	released up to now (<= gcc-3.3.1) inlining this function just
  *	consumes 120 more bytes of code and goes completely mad on
  *	register allocation, storing almost everything in the memory.
  *
- * Results: 
+ * Results:
  *	folded checksum (non-negative value) on success,
  *	-EINVAL if offset is too big,
  *	-EFAULT if buffer is an invalid area
@@ -574,7 +578,7 @@ VNetCsumCopyDatagram(const struct sk_buff *skb,	// IN: skb to copy
    char *curr = buf;
    const skb_frag_t *frag;
 
-   /* 
+   /*
     * Something bad happened. We skip only up to skb->nh.raw, and skb->nh.raw
     * must be in the header, otherwise we are in the big troubles.
     */
@@ -631,7 +635,7 @@ VNetCsumCopyDatagram(const struct sk_buff *skb,	// IN: skb to copy
  *      Copy complete datagram to the user space. Fill correct checksum
  *	into the copied datagram if nobody did it yet.
  *
- * Results: 
+ * Results:
  *      On success byte count, on failure -EFAULT.
  *
  * Side effects:
@@ -660,7 +664,7 @@ VNetCopyDatagramToUser(const struct sk_buff *skb,	// IN
       size_t skl;
       int csum;
       u_int16_t csum16;
-     
+
       skl = compat_skb_csum_start(skb);
       if (VNetCopyDatagram(skb, buf, skl)) {
 	 return -EFAULT;
@@ -691,7 +695,7 @@ VNetCopyDatagramToUser(const struct sk_buff *skb,	// IN
  *      The virtual network's read file operation. Reads the next pending
  *      packet for this network connection.
  *
- * Results: 
+ * Results:
  *      On success the len of the packet received,
  *      else if no packet waiting and nonblocking 0,
  *      else -errno.
@@ -702,7 +706,7 @@ VNetCopyDatagramToUser(const struct sk_buff *skb,	// IN
  *----------------------------------------------------------------------
  */
 
-static int 
+static int
 VNetUserIfRead(VNetPort    *port, // IN
                struct file *filp, // IN
                char        *buf,  // OUT
@@ -770,7 +774,7 @@ VNetUserIfRead(VNetPort    *port, // IN
  *      The virtual network's write file operation. Send the raw packet
  *      to the network.
  *
- * Results: 
+ * Results:
  *      On success the count of bytes written else errno.
  *
  * Side effects:
@@ -779,7 +783,7 @@ VNetUserIfRead(VNetPort    *port, // IN
  *----------------------------------------------------------------------
  */
 
-static int 
+static int
 VNetUserIfWrite(VNetPort    *port, // IN
                 struct file *filp, // IN
                 const char  *buf,  // IN
@@ -791,8 +795,8 @@ VNetUserIfWrite(VNetPort    *port, // IN
    /*
     * Check size
     */
-   
-   if (count < sizeof (struct ethhdr) || 
+
+   if (count < sizeof (struct ethhdr) ||
        count > ETHER_MAX_QUEUED_PACKET) {
       return -EINVAL;
    }
@@ -809,25 +813,25 @@ VNetUserIfWrite(VNetPort    *port, // IN
    /*
     * Allocate an sk_buff.
     */
-   
+
    skb = dev_alloc_skb(count + 7);
    if (skb == NULL) {
       // XXX obey O_NONBLOCK?
       return -ENOBUFS;
    }
-   
+
    skb_reserve(skb, 2);
-   
+
    /*
     * Copy the data and send it.
     */
-   
+
    userIf->stats.written++;
    if (copy_from_user(skb_put(skb, count), buf, count)) {
       dev_kfree_skb(skb);
       return -EFAULT;
    }
-   
+
    VNetSend(&userIf->port.jack, skb);
 
    return count;
@@ -841,7 +845,7 @@ VNetUserIfWrite(VNetPort    *port, // IN
  *
  *      XXX
  *
- * Results: 
+ * Results:
  *      0 on success
  *      -errno on failure
  *
@@ -864,8 +868,8 @@ VNetUserIfIoctl(VNetPort      *port,  // IN
       return -EINVAL;
    case SIOCSETNOTIFY2:
 #ifdef VMX86_SERVER
-      /* 
-       * This ioctl always return failure on ESX since we cannot map pages into 
+      /*
+       * This ioctl always return failure on ESX since we cannot map pages into
        * the console os that are from the VMKernel address space which  was the
        * only case we used this.
        */
@@ -908,20 +912,20 @@ VNetUserIfIoctl(VNetPort      *port,  // IN
       break;
 
    case SIOCSIFFLAGS:
-      /* 
-       * Drain queue when interface is no longer active. We drain the queue to 
+      /*
+       * Drain queue when interface is no longer active. We drain the queue to
        * avoid having old packets delivered to the guest when reneabled.
        */
-      
+
       if (!UP_AND_RUNNING(userIf->port.flags)) {
          struct sk_buff *skb;
          unsigned long flags;
          struct sk_buff_head *q = &userIf->packetQueue;
-         
+
          while ((skb = skb_dequeue(q)) != NULL) {
             dev_kfree_skb(skb);
          }
-         
+
          spin_lock_irqsave(&q->lock, flags);
          if (userIf->pollPtr) {
             if (skb_queue_empty(q)) {
@@ -938,11 +942,11 @@ VNetUserIfIoctl(VNetPort      *port,  // IN
    case SIOCINJECTLINKSTATE:
       {
          uint8 linkUpFromUser;
-         if (copy_from_user(&linkUpFromUser, (void *)ioarg, 
+         if (copy_from_user(&linkUpFromUser, (void *)ioarg,
                             sizeof linkUpFromUser)) {
             return -EFAULT;
          }
-         
+
          if (linkUpFromUser != 0 && linkUpFromUser != 1) {
             return -EINVAL;
          }
@@ -954,7 +958,7 @@ VNetUserIfIoctl(VNetPort      *port,  // IN
       return -ENOIOCTLCMD;
       break;
    }
-   
+
    return 0;
 }
 
@@ -966,7 +970,7 @@ VNetUserIfIoctl(VNetPort      *port,  // IN
  *
  *      The virtual network's file poll operation.
  *
- * Results: 
+ * Results:
  *      Return POLLIN if success, else sleep and return 0.
  *      FIXME: Should not we always return POLLOUT?
  *
@@ -982,7 +986,7 @@ VNetUserIfPoll(VNetPort     *port, // IN
                poll_table   *wait) // IN
 {
    VNetUserIF *userIf = (VNetUserIF*)port->jack.private;
-   
+
    poll_wait(filp, &userIf->waitQueue, wait);
    if (!skb_queue_empty(&userIf->packetQueue)) {
       return POLLIN;
@@ -997,8 +1001,8 @@ VNetUserIfPoll(VNetPort     *port, // IN
  * VNetUserIfSetUplinkState --
  *
  *      Sends link state change event.
- * 
- * Results: 
+ *
+ * Results:
  *      0 on success, errno on failure.
  *
  * Side effects:
@@ -1040,7 +1044,7 @@ VNetUserIfSetUplinkState(VNetPort *port, uint8 linkUp)
    event.header.eventId = 0;
    event.header.classSet = VNET_EVENT_CLASS_UPLINK;
    event.header.type = VNET_EVENT_TYPE_LINK_STATE;
-   /* 
+   /*
     * XXX kind of a hack, vmx will coalesce linkup/down if they come from the
     * same adapter.
     */
@@ -1065,8 +1069,8 @@ VNetUserIfSetUplinkState(VNetPort *port, uint8 linkUp)
  *
  *      Create a user level port to the wonderful world of virtual
  *      networking.
- * 
- * Results: 
+ *
+ * Results:
  *      Errno. Also returns an allocated port to connect to,
  *      NULL on error.
  *
@@ -1082,7 +1086,7 @@ VNetUserIf_Create(VNetPort **ret) // OUT
    VNetUserIF *userIf;
    static unsigned id = 0;
    int retval;
-   
+
    userIf = kmalloc(sizeof *userIf, GFP_USER);
    if (!userIf) {
       return -ENOMEM;
@@ -1091,7 +1095,7 @@ VNetUserIf_Create(VNetPort **ret) // OUT
    /*
     * Initialize fields.
     */
-   
+
    userIf->port.id = id++;
 
    userIf->port.jack.peer = NULL;
@@ -1136,7 +1140,7 @@ VNetUserIf_Create(VNetPort **ret) // OUT
    /*
     * Rest of fields.
     */
-   
+
    userIf->port.flags = IFF_RUNNING;
 
    memset(userIf->port.paddr, 0, sizeof userIf->port.paddr);
@@ -1149,12 +1153,12 @@ VNetUserIf_Create(VNetPort **ret) // OUT
    userIf->port.fileOpWrite = VNetUserIfWrite;
    userIf->port.fileOpIoctl = VNetUserIfIoctl;
    userIf->port.fileOpPoll = VNetUserIfPoll;
-   
+
    skb_queue_head_init(&(userIf->packetQueue));
    init_waitqueue_head(&userIf->waitQueue);
 
    memset(&userIf->stats, 0, sizeof userIf->stats);
-   
+
    *ret = &userIf->port;
    return 0;
 }
diff --git a/vmnet/vm_device_version.h b/vmnet/vm_device_version.h
index e2cb477..3dd7097 100644
--- a/vmnet/vm_device_version.h
+++ b/vmnet/vm_device_version.h
@@ -53,7 +53,9 @@
  *    VMware HD Audio codec
  *    VMware HD Audio controller
  */
+#ifndef PCI_VENDOR_ID_VMWARE
 #define PCI_VENDOR_ID_VMWARE                    0x15AD
+#endif
 #define PCI_DEVICE_ID_VMWARE_SVGA2              0x0405
 #define PCI_DEVICE_ID_VMWARE_SVGA               0x0710
 #define PCI_DEVICE_ID_VMWARE_VGA                0x0711
diff --git a/vmnet/vmnetInt.h b/vmnet/vmnetInt.h
index 0ee52ec..4e3b923 100644
--- a/vmnet/vmnetInt.h
+++ b/vmnet/vmnetInt.h
@@ -77,9 +77,9 @@
 
 
 extern struct proto vmnet_proto;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 99)
 #   define compat_sk_alloc(_bri, _pri) sk_alloc(&init_net, \
-                                                PF_NETLINK, _pri, &vmnet_proto, 1)
+                                                PF_NETLINK, _pri, &vmnet_proto, 0)
 #elif defined(VMW_NETDEV_HAS_NET)
 #   define compat_sk_alloc(_bri, _pri) sk_alloc(&init_net, \
                                                 PF_NETLINK, _pri, &vmnet_proto)