summarylogtreecommitdiffstats
path: root/vmnet.patch
blob: 4bfb6c58c075586681bbd8a991e864c351f43161 (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
--- 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
From f404bc6855ea2c731b617d3b0a2971481eb31cbd Mon Sep 17 00:00:00 2001
From: Michal Kubecek <mkubecek@suse.cz>
Date: Thu, 19 Sep 2019 12:20:20 +0200
Subject: [PATCH] vmnet: handle switch of skb_frag_t to bio_vec

The switch from custom skb_frag_t implementation to bio_vec in v5.4-rc1 is
mostly transparent for modules which use accessor for skb_frag_t members.
Unfortunately many users access the members directly and function
VNetCsumCopyDatagram() in vmnet is one of those.

Use accessors everywhere so that vmnet code is compatible with kernel 5.4
and newer. Use "compat_" prefix to avoid clashes with backports adding the
accessors to older codebase.
---
 vmnet-only/userif.c | 39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)

diff --git a/vmnet-only/userif.c b/vmnet-only/userif.c
index d385088..aab9478 100644
--- a/vmnet-only/userif.c
+++ b/vmnet-only/userif.c
@@ -78,13 +78,31 @@ static int  VNetUserIfSetUplinkState(VNetPort *port, uint8 linkUp);
 extern unsigned int  vnet_max_qlen;
 
 #if COMPAT_LINUX_VERSION_CHECK_LT(3, 2, 0)
-#   define compat_kmap(page) kmap(page)
-#   define compat_kunmap(page) kunmap(page)
+#   define compat_kmap_frag(frag) kmap((frag)->page)
+#   define compat_kunmap_frag(page) kunmap((frag)->page)
 #else
-#   define compat_kmap(page) kmap((page).p)
-#   define compat_kunmap(page) kunmap((page).p)
+#   define compat_kmap_frag(frag) kmap(skb_frag_page(frag))
+#   define compat_kunmap_frag(frag) kunmap(skb_frag_page(frag))
 #endif
 
+static unsigned int compat_skb_frag_size(const skb_frag_t *frag)
+{
+#if COMPAT_LINUX_VERSION_CHECK_LT(3, 2, 0)
+	return frag->size;
+#else
+	return skb_frag_size(frag);
+#endif
+}
+
+static unsigned int compat_skb_frag_off(const skb_frag_t *frag)
+{
+#if COMPAT_LINUX_VERSION_CHECK_LT(5, 4, 0)
+	return frag->page_offset;
+#else
+	return skb_frag_off(frag);
+#endif
+}
+
 /*
  *-----------------------------------------------------------------------------
  *
@@ -568,20 +586,21 @@ VNetCsumCopyDatagram(const struct sk_buff *skb,	// IN: skb to copy
    for (frag = skb_shinfo(skb)->frags;
 	frag != skb_shinfo(skb)->frags + skb_shinfo(skb)->nr_frags;
 	frag++) {
-      if (frag->size > 0) {
+      if (compat_skb_frag_size(frag) > 0) {
 	 unsigned int tmpCsum;
 	 const void *vaddr;
 
-	 vaddr = compat_kmap(frag->page);
-	 tmpCsum = csum_and_copy_to_user(vaddr + frag->page_offset,
-					 curr, frag->size, 0, &err);
-	 compat_kunmap(frag->page);
+	 vaddr = compat_kmap_frag(frag);
+	 tmpCsum = csum_and_copy_to_user(vaddr + compat_skb_frag_off(frag),
+					 curr, compat_skb_frag_size(frag), 0,
+					 &err);
+	 compat_kunmap_frag(frag);
 
 	 if (err) {
 	    return err;
 	 }
 	 csum = csum_block_add(csum, tmpCsum, curr - buf);
-	 curr += frag->size;
+	 curr += compat_skb_frag_size(frag);
       }
    }
 
From d8e6c50b735f95af01ddfe8b9d2775ed68aaa625 Mon Sep 17 00:00:00 2001
From: Michal Kubecek <mkubecek@suse.cz>
Date: Wed, 5 Feb 2020 07:29:14 +0100
Subject: [PATCH] vmnet: convert from file_operations to proc_ops

Manline commit 97a32539b956 ("proc: convert everything to "struct
proc_ops"") in v5.6-rc1 introduces struct proc_ops and converts procfs file
operations to it. Convert vmnet to do the same.

As the same commit also introduces DEFINE_PROC_SHOW_ATTRIBUTE macro, we can
use it for detection rather than rely on version comparison.
---
 vmnet-only/procfs.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/vmnet-only/procfs.c b/vmnet-only/procfs.c
index 165cda0..58e1c4e 100644
--- a/vmnet-only/procfs.c
+++ b/vmnet-only/procfs.c
@@ -161,6 +161,14 @@ VNetProcOpen(struct inode *inode,   // IN:
 }
 
 /* Our procfs callbacks.  We only need to specialize open. */
+#ifdef DEFINE_PROC_SHOW_ATTRIBUTE
+static const struct proc_ops fops = {
+   .proc_open    = VNetProcOpen,
+   .proc_read    = seq_read,
+   .proc_lseek   = seq_lseek,
+   .proc_release = single_release,
+};
+#else
 static struct file_operations fops = {
    .open    = VNetProcOpen,
    .read    = seq_read,
@@ -168,6 +176,7 @@ static struct file_operations fops = {
    .release = single_release,
 };
 #endif
+#endif
 
 
 /*