summarylogtreecommitdiffstats
path: root/vmmon.patch
blob: e960a58a905c6b0d3117066706221c695a895452 (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
diff --git a/vmmon/Makefile b/vmmon/Makefile
index de8162e..6124a71 100644
--- a/vmmon/Makefile
+++ b/vmmon/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: Michal Kubecek <mkubecek@suse.cz>
Date: Mon, 26 Mar 2018 13:33:32 +0200
Subject: [PATCH] vmmon: fix indirect call with retpoline build
diff --git a/vmmon/common/task.c b/vmmon/common/task.c
index 98cc74a..400ebfe 100644
--- a/vmmon/common/task.c
+++ b/vmmon/common/task.c
@@ -2203,12 +2203,23 @@ TaskSwitchToMonitor(VMCrossPage *crosspage)
    {
       uint64 raxGetsWiped, rcxGetsWiped;
 
+#ifdef CALL_NOSPEC
+      __asm__ __volatile__(CALL_NOSPEC
+                           : "=a" (raxGetsWiped),
+                             "=c" (rcxGetsWiped)
+                           : "0" (codePtr),
+                             "1" (crosspage),
+                             THUNK_TARGET(codePtr)
+                           : "rdx", "r8", "r9", "r10", "r11", "cc", "memory");
+#else
       __asm__ __volatile__("call *%%rax"
                            : "=a" (raxGetsWiped),
                              "=c" (rcxGetsWiped)
                            : "0" (codePtr),
                              "1" (crosspage)
                            : "rdx", "r8", "r9", "r10", "r11", "cc", "memory");
+#endif
+
    }
 #elif defined(_MSC_VER)
    /*
From 8ba37a5023f939ba8d2e0d91b916ff442b1c18dd Mon Sep 17 00:00:00 2001
From: Michal Kubecek <mkubecek@suse.cz>
Date: Mon, 31 Dec 2018 00:05:42 +0100
Subject: [PATCH] modules: replace SUBDIRS with M

Since commit 0126be38d988 ("kbuild: announce removal of SUBDIRS if used")
in v5.0-rc1, using SUBDIRS when building out of tree modules produces
a deprecation warning. As M used to work since pretty much ever, use it
unconditionally.
---
 vmmon-only/Makefile | 2 +-
 vmnet-only/Makefile | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/vmmon-only/Makefile b/vmmon-only/Makefile
index ccdd295..b4b71fb 100644
--- a/vmmon-only/Makefile
+++ b/vmmon-only/Makefile
@@ -111,7 +111,7 @@ prebuild:: ;
 postbuild:: ;
 
 $(DRIVER_KO): prebuild
-	$(MAKE) -C $(BUILD_DIR) SUBDIRS=$$PWD SRCROOT=$$PWD/$(SRCROOT) \
+	$(MAKE) -C $(BUILD_DIR) M=$$PWD SRCROOT=$$PWD/$(SRCROOT) \
 	  MODULEBUILDDIR=$(MODULEBUILDDIR) modules
 	$(MAKE) -C $$PWD SRCROOT=$$PWD/$(SRCROOT) \
 	  MODULEBUILDDIR=$(MODULEBUILDDIR) postbuild
From ca44ce7215b91f82ff500843784b4e86a720fffe Mon Sep 17 00:00:00 2001
From: Michal Kubecek <mkubecek@suse.cz>
Date: Mon, 31 Dec 2018 00:11:35 +0100
Subject: [PATCH] vmmon: totalram_pages is a function since 5.0

Since commit ca79b0c211af ("mm: convert totalram_pages and totalhigh_pages
variables to atomic") in v5.0-rc1, totalram_pages() is an accessor function
and the actual variable is an atomic.
---
 vmmon-only/linux/hostif.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/vmmon-only/linux/hostif.c b/vmmon-only/linux/hostif.c
index af4b1d9..d32653c 100644
--- a/vmmon-only/linux/hostif.c
+++ b/vmmon-only/linux/hostif.c
@@ -180,6 +180,15 @@ static void UnlockEntry(void *clientData, MemTrackEntry *entryPtr);
 uint8 monitorIPIVector;
 uint8 hvIPIVector;
 
+static unsigned long compat_totalram_pages(void)
+{
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0)
+	return totalram_pages;
+#else
+	return totalram_pages();
+#endif
+}
+
 /*
  *-----------------------------------------------------------------------------
  *
@@ -1494,14 +1503,7 @@ unsigned int
 HostIF_EstimateLockedPageLimit(const VMDriver* vm,                // IN
                                unsigned int currentlyLockedPages) // IN
 {
-   /*
-    * This variable is available and exported to modules,
-    * since at least 2.6.0.
-    */
-
-   extern unsigned long totalram_pages;
-
-   unsigned int totalPhysicalPages = totalram_pages;
+   unsigned int totalPhysicalPages = compat_totalram_pages();
 
    /*
     * Use the memory information linux exports as of late for a more
From 97d03d41984a0ade064fa6ac0400eb61de7929ff Mon Sep 17 00:00:00 2001
From: Michal Kubecek <mkubecek@suse.cz>
Date: Mon, 31 Dec 2018 00:15:11 +0100
Subject: [PATCH] vmmon: bring back the do_gettimeofday() helper

The do_gettimeofday() helper was removed by commit e4b92b108c6c
("timekeeping: remove obsolete time accessors") in v5.0-rc1. Bring it back
for users in vmmon-only/linux/hostif.c.

This feels like a quick and clumsy band aid to allow build with post-4.20
kernels. On a closer look, the whole gymnastics around uptimeState and
HostIFReadUptimeWork() with jiffies and wall time checking and correcting
each other seems to be a workaround for an absence of high resolution
monotonic time. Considering ktime_get_ts64() is available since 3.17 and
before that, ktime_get_ts() since 2.6.17, perhaps the time has come to
clean all this machinery up. But something like this would be beyond the
scope of this repository.
---
 vmmon-only/linux/hostif.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/vmmon-only/linux/hostif.c b/vmmon-only/linux/hostif.c
index d32653c..cf4197b 100644
--- a/vmmon-only/linux/hostif.c
+++ b/vmmon-only/linux/hostif.c
@@ -189,6 +189,17 @@ static unsigned long compat_totalram_pages(void)
 #endif
 }
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
+static void do_gettimeofday(struct timeval *tv)
+{
+	struct timespec64 now;
+
+	ktime_get_real_ts64(&now);
+	tv->tv_sec = now.tv_sec;
+	tv->tv_usec = now.tv_nsec / 1000;
+}
+#endif
+
 /*
  *-----------------------------------------------------------------------------
  *
From 92b90ac11baf215ba73cb94e5aebf0576f1966a0 Mon Sep 17 00:00:00 2001
From: Michal Kubecek <mkubecek@suse.cz>
Date: Sat, 5 Jan 2019 01:54:57 +0100
Subject: [PATCH] modules: handle access_ok() with two arguments

Since commit 96d4f267e40f ("Remove 'type' argument from access_ok()
function") in v5.0-rc1, the type argument of access_ok() was dropped.
The same commit also dropped macros VERIFY_READ and VERIFY_WRITE so check
for their existence on pre-5.0 kernels to allow build against kernels with
this change backported.
---
 vmmon-only/linux/hostif.c | 8 +++++++-
 vmnet-only/userif.c       | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/vmmon-only/linux/hostif.c b/vmmon-only/linux/hostif.c
index cf4197b..ef88a22 100644
--- a/vmmon-only/linux/hostif.c
+++ b/vmmon-only/linux/hostif.c
@@ -200,6 +200,12 @@ static void do_gettimeofday(struct timeval *tv)
 }
 #endif
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0) && defined(VERIFY_WRITE)
+	#define write_access_ok(addr, size) access_ok(VERIFY_WRITE, addr, size)
+#else
+	#define write_access_ok(addr, size) access_ok(addr, size)
+#endif
+
 /*
  *-----------------------------------------------------------------------------
  *
@@ -3213,7 +3219,7 @@ HostIF_MapUserMem(VA addr,                  // IN: User memory virtual address
 
    ASSERT(handle);
 
-   if (!access_ok(VERIFY_WRITE, p, size)) {
+   if (!write_access_ok(p, size)) {
       printk(KERN_ERR "%s: Couldn't verify write to uva 0x%p with size %"
              FMTSZ"u\n", __func__, p, size);
 
From 41413a9b6e660a93600a438944d85b6f51eb680c Mon Sep 17 00:00:00 2001
From: Michal Kubecek <mkubecek@suse.cz>
Date: Tue, 5 Mar 2019 13:21:35 +0100
Subject: [PATCH] vmmon: use KERNEL_DS rather than get_ds()

Commit 736706bee329 ("get rid of legacy 'get_ds()' function") in v5.1-rc1
removed get_ds() helper. As this helper always returned KERNEL_DS on x86_64
since the architecture was introduced (and even on i386, it did so since
v2.1.0), simply use KERNEL_DS regardless of kernel version.
---
 vmmon-only/linux/hostif.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/vmmon-only/linux/hostif.c b/vmmon-only/linux/hostif.c
index ef88a22..8ca17de 100644
--- a/vmmon-only/linux/hostif.c
+++ b/vmmon-only/linux/hostif.c
@@ -2183,7 +2183,7 @@ isVAReadable(VA r)  // IN:
    int ret;
 
    old_fs = get_fs();
-   set_fs(get_ds());
+   set_fs(KERNEL_DS);
    r = APICR_TO_ADDR(r, APICR_VERSION);
    ret = HostIF_CopyFromUser(&dummy, r, sizeof dummy);
    set_fs(old_fs);
@@ -2384,7 +2384,7 @@ HostIF_SemaphoreWait(VMDriver *vm,   // IN:
    }
 
    old_fs = get_fs();
-   set_fs(get_ds());
+   set_fs(KERNEL_DS);
 
    {
       struct poll_wqueues table;
@@ -2513,7 +2513,7 @@ HostIF_SemaphoreSignal(uint64 *args)  // IN:
    }
 
    old_fs = get_fs();
-   set_fs(get_ds());
+   set_fs(KERNEL_DS);
 
    /*
     * Always write sizeof(uint64) bytes. This works fine for eventfd and
From 2af9d566d0ccc78a93b46a79d23902e5ba2bc933 Mon Sep 17 00:00:00 2001
From: Michal Kubecek <mkubecek@suse.cz>
Date: Sat, 9 Mar 2019 11:11:29 +0100
Subject: [PATCH] vmmon: fix return type of vm_operations_struct::fault handler

Commit 3d3539018d2c ("mm: create the new vm_fault_t type") in mainline
5.1-rc1 changed the definition of vm_fault_t type to unsigned to catch
vm_operations_struct::fault handlers which still have int as return value.
LinuxDriverFault() in vmmon module is one of those.

As handler return type was changed by commit 1c8f422059ae ("mm: change
return type to vm_fault_t") in 4.17-rc1, make LinuxDriverFault() always
return vm_fault_t and define vm_fault_t as int when building against
a pre-4.17 kernel.
---
 vmmon-only/linux/driver.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/vmmon-only/linux/driver.c b/vmmon-only/linux/driver.c
index 92a3529..248a95d 100644
--- a/vmmon-only/linux/driver.c
+++ b/vmmon-only/linux/driver.c
@@ -73,6 +73,9 @@ static Bool LinuxDriverCheckPadding(void);
 
 struct VMXLinuxState linuxState;
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 17, 0)
+typedef int vm_fault_t;
+#endif
 
 /*
  *----------------------------------------------------------------------
@@ -97,9 +100,9 @@ long LinuxDriver_Ioctl(struct file *filp, u_int iocmd,
 
 static int LinuxDriver_Close(struct inode *inode, struct file *filp);
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
-static int LinuxDriverFault(struct vm_fault *fault);
+static vm_fault_t LinuxDriverFault(struct vm_fault *fault);
 #else
-static int LinuxDriverFault(struct vm_area_struct *vma, struct vm_fault *fault);
+static vm_fault_t LinuxDriverFault(struct vm_area_struct *vma, struct vm_fault *fault);
 #endif
 static int LinuxDriverMmap(struct file *filp, struct vm_area_struct *vma);
 
@@ -594,7 +597,7 @@ LinuxDriver_Close(struct inode *inode, // IN
  *-----------------------------------------------------------------------------
  */
 
-static int
+static vm_fault_t
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
 LinuxDriverFault(struct vm_fault *fault)     //IN/OUT
 #else