diff options
author | Bruce Ashfield <bruce.ashfield@gmail.com> | 2021-01-05 10:21:49 -0500 |
---|---|---|
committer | Armin Kuster <akuster808@gmail.com> | 2021-07-19 16:22:55 -0700 |
commit | 9c33c4219650acd46cd34688a7c3fcf6afcae92d (patch) | |
tree | ff86806c1e9cd288eab427214729a666e80634c3 | |
parent | 0066ffb6eb2a81b827ba0aa9e229105cabf098cc (diff) | |
download | meta-openembedded-9c33c4219650acd46cd34688a7c3fcf6afcae92d.tar.gz |
vboxguestdrivers: fix build against kernel v5.10+
We need to adjust the vboxguest drivers to build against kernels
5.10+.
These are backports from the virtual box SVN repository and can be
dropped in future uprevs.
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
(cherry picked from commit 22eaac640f80df44108a5565127181c94645a032)
Signed-off-by: Armin Kuster <akuster808@gmail.com>
4 files changed, 489 insertions, 0 deletions
diff --git a/meta-oe/recipes-support/vboxguestdrivers/vboxguestdrivers/0001-Additions-linux-drm-Adjustment-for-Linux-5.10.patch b/meta-oe/recipes-support/vboxguestdrivers/vboxguestdrivers/0001-Additions-linux-drm-Adjustment-for-Linux-5.10.patch new file mode 100644 index 000000000..a444901f8 --- /dev/null +++ b/meta-oe/recipes-support/vboxguestdrivers/vboxguestdrivers/0001-Additions-linux-drm-Adjustment-for-Linux-5.10.patch | |||
@@ -0,0 +1,321 @@ | |||
1 | From b6c765d693a0833b94cb2e91b32842570c3458d2 Mon Sep 17 00:00:00 2001 | ||
2 | From: vboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f> | ||
3 | Date: Tue, 15 Dec 2020 22:29:56 +0000 | ||
4 | Subject: [PATCH] Additions/linux/drm: Adjustment for Linux 5.10. | ||
5 | |||
6 | Upstream-Status: Backport | ||
7 | |||
8 | git-svn-id: http://www.virtualbox.org/svn/vbox@87092 cfe28804-0f27-0410-a406-dd0f0b0b656f | ||
9 | |||
10 | Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com> | ||
11 | |||
12 | --- | ||
13 | src/VBox/Additions/linux/drm/vbox_drv.h | 10 +- | ||
14 | src/VBox/Additions/linux/drm/vbox_fb.c | 2 +- | ||
15 | .../src/VBox/Additions/linux/drm/vbox_mode.c | 2 +- | ||
16 | src/VBox/Additions/linux/drm/vbox_ttm.c | 99 +++++++++++++++++-- | ||
17 | 4 files changed, 99 insertions(+), 14 deletions(-) | ||
18 | |||
19 | diff --git a/src/VBox/Additions/linux/drm/vbox_drv.h b/src/VBox/Additions/linux/drm/vbox_drv.h | ||
20 | index 8c85371749..7937f2f2d2 100644 | ||
21 | --- a/src/VBox/Additions/linux/drm/vbox_drv.h | ||
22 | +++ b/src/VBox/Additions/linux/drm/vbox_drv.h | ||
23 | @@ -175,6 +175,9 @@ | ||
24 | #include <drm/ttm/ttm_placement.h> | ||
25 | #include <drm/ttm/ttm_memory.h> | ||
26 | #include <drm/ttm/ttm_module.h> | ||
27 | +#if RTLNX_VER_MIN(5,10,0) | ||
28 | +# include <drm/ttm/ttm_resource.h> | ||
29 | +#endif | ||
30 | |||
31 | #include "vboxvideo_guest.h" | ||
32 | #include "vboxvideo_vbe.h" | ||
33 | @@ -444,7 +447,10 @@ int vbox_bo_create(struct drm_device *dev, int size, int align, | ||
34 | int vbox_gem_create(struct drm_device *dev, | ||
35 | u32 size, bool iskernel, struct drm_gem_object **obj); | ||
36 | |||
37 | -int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag, u64 *gpu_addr); | ||
38 | +#define VBOX_MEM_TYPE_VRAM 0x1 | ||
39 | +#define VBOX_MEM_TYPE_SYSTEM 0x2 | ||
40 | + | ||
41 | +int vbox_bo_pin(struct vbox_bo *bo, u32 mem_type, u64 *gpu_addr); | ||
42 | int vbox_bo_unpin(struct vbox_bo *bo); | ||
43 | |||
44 | static inline int vbox_bo_reserve(struct vbox_bo *bo, bool no_wait) | ||
45 | @@ -469,7 +475,7 @@ static inline void vbox_bo_unreserve(struct vbox_bo *bo) | ||
46 | ttm_bo_unreserve(&bo->bo); | ||
47 | } | ||
48 | |||
49 | -void vbox_ttm_placement(struct vbox_bo *bo, int domain); | ||
50 | +void vbox_ttm_placement(struct vbox_bo *bo, u32 mem_type); | ||
51 | int vbox_bo_push_sysram(struct vbox_bo *bo); | ||
52 | int vbox_mmap(struct file *filp, struct vm_area_struct *vma); | ||
53 | |||
54 | diff --git a/src/VBox/Additions/linux/drm/vbox_fb.c b/src/VBox/Additions/linux/drm/vbox_fb.c | ||
55 | index adead98d3d..7182d9da1a 100644 | ||
56 | --- a/src/VBox/Additions/linux/drm/vbox_fb.c | ||
57 | +++ b/src/VBox/Additions/linux/drm/vbox_fb.c | ||
58 | @@ -295,7 +295,7 @@ static int vboxfb_create(struct drm_fb_helper *helper, | ||
59 | if (ret) | ||
60 | return ret; | ||
61 | |||
62 | - ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM, NULL); | ||
63 | + ret = vbox_bo_pin(bo, VBOX_MEM_TYPE_VRAM, NULL); | ||
64 | if (ret) { | ||
65 | vbox_bo_unreserve(bo); | ||
66 | return ret; | ||
67 | diff --git a/src/VBox/Additions/linux/drm/vbox_mode.c b/src/VBox/Additions/linux/drm/vbox_mode.c | ||
68 | index ce7d135cb6..5557db5ef8 100644 | ||
69 | --- a/src/VBox/Additions/linux/drm/vbox_mode.c | ||
70 | +++ b/src/VBox/Additions/linux/drm/vbox_mode.c | ||
71 | @@ -227,7 +227,7 @@ static int vbox_crtc_set_base(struct drm_crtc *crtc, | ||
72 | if (ret) | ||
73 | return ret; | ||
74 | |||
75 | - ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM, &gpu_addr); | ||
76 | + ret = vbox_bo_pin(bo, VBOX_MEM_TYPE_VRAM, &gpu_addr); | ||
77 | vbox_bo_unreserve(bo); | ||
78 | if (ret) | ||
79 | return ret; | ||
80 | diff --git a/src/VBox/Additions/linux/drm/vbox_ttm.c b/src/VBox/Additions/linux/drm/vbox_ttm.c | ||
81 | index bf87aabc05..5eac926a42 100644 | ||
82 | --- a/src/VBox/Additions/linux/drm/vbox_ttm.c | ||
83 | +++ b/src/VBox/Additions/linux/drm/vbox_ttm.c | ||
84 | @@ -41,6 +41,7 @@ | ||
85 | #define PLACEMENT_FLAGS(placement) ((placement).flags) | ||
86 | #endif | ||
87 | |||
88 | + | ||
89 | static inline struct vbox_private *vbox_bdev(struct ttm_bo_device *bd) | ||
90 | { | ||
91 | return container_of(bd, struct vbox_private, ttm.bdev); | ||
92 | @@ -125,6 +126,7 @@ static bool vbox_ttm_bo_is_vbox_bo(struct ttm_buffer_object *bo) | ||
93 | return false; | ||
94 | } | ||
95 | |||
96 | +#if RTLNX_VER_MAX(5,10,0) | ||
97 | static int | ||
98 | vbox_bo_init_mem_type(struct ttm_bo_device *bdev, u32 type, | ||
99 | struct ttm_mem_type_manager *man) | ||
100 | @@ -148,6 +150,7 @@ vbox_bo_init_mem_type(struct ttm_bo_device *bdev, u32 type, | ||
101 | |||
102 | return 0; | ||
103 | } | ||
104 | +#endif | ||
105 | |||
106 | static void | ||
107 | vbox_bo_evict_flags(struct ttm_buffer_object *bo, struct ttm_placement *pl) | ||
108 | @@ -157,7 +160,7 @@ vbox_bo_evict_flags(struct ttm_buffer_object *bo, struct ttm_placement *pl) | ||
109 | if (!vbox_ttm_bo_is_vbox_bo(bo)) | ||
110 | return; | ||
111 | |||
112 | - vbox_ttm_placement(vboxbo, TTM_PL_FLAG_SYSTEM); | ||
113 | + vbox_ttm_placement(vboxbo, VBOX_MEM_TYPE_SYSTEM); | ||
114 | *pl = vboxbo->placement; | ||
115 | } | ||
116 | |||
117 | @@ -167,11 +170,12 @@ static int vbox_bo_verify_access(struct ttm_buffer_object *bo, | ||
118 | return 0; | ||
119 | } | ||
120 | |||
121 | +#if RTLNX_VER_MAX(5,10,0) | ||
122 | static int vbox_ttm_io_mem_reserve(struct ttm_bo_device *bdev, | ||
123 | struct ttm_mem_reg *mem) | ||
124 | { | ||
125 | - struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type]; | ||
126 | struct vbox_private *vbox = vbox_bdev(bdev); | ||
127 | + struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type]; | ||
128 | |||
129 | mem->bus.addr = NULL; | ||
130 | mem->bus.offset = 0; | ||
131 | @@ -194,12 +198,53 @@ static int vbox_ttm_io_mem_reserve(struct ttm_bo_device *bdev, | ||
132 | } | ||
133 | return 0; | ||
134 | } | ||
135 | +#else | ||
136 | +static int vbox_ttm_io_mem_reserve(struct ttm_bo_device *bdev, | ||
137 | + struct ttm_resource *mem) | ||
138 | +{ | ||
139 | + struct vbox_private *vbox = vbox_bdev(bdev); | ||
140 | + mem->bus.addr = NULL; | ||
141 | + mem->bus.offset = 0; | ||
142 | + mem->size = mem->num_pages << PAGE_SHIFT; | ||
143 | + mem->start = 0; | ||
144 | + mem->bus.is_iomem = false; | ||
145 | + switch (mem->mem_type) { | ||
146 | + case TTM_PL_SYSTEM: | ||
147 | + /* system memory */ | ||
148 | + return 0; | ||
149 | + case TTM_PL_VRAM: | ||
150 | + mem->bus.offset = mem->start << PAGE_SHIFT; | ||
151 | + mem->start = pci_resource_start(vbox->dev->pdev, 0); | ||
152 | + mem->bus.is_iomem = true; | ||
153 | + break; | ||
154 | + default: | ||
155 | + return -EINVAL; | ||
156 | + } | ||
157 | + return 0; | ||
158 | +} | ||
159 | +#endif | ||
160 | |||
161 | + | ||
162 | + | ||
163 | +#if RTLNX_VER_MIN(5,10,0) | ||
164 | +static void vbox_ttm_io_mem_free(struct ttm_bo_device *bdev, | ||
165 | + struct ttm_resource *mem) | ||
166 | +{ | ||
167 | +} | ||
168 | +#else | ||
169 | static void vbox_ttm_io_mem_free(struct ttm_bo_device *bdev, | ||
170 | struct ttm_mem_reg *mem) | ||
171 | { | ||
172 | } | ||
173 | +#endif | ||
174 | |||
175 | +#if RTLNX_VER_MIN(5,10,0) | ||
176 | +static void vbox_ttm_tt_destroy(struct ttm_bo_device *bdev, struct ttm_tt *tt) | ||
177 | +{ | ||
178 | + ttm_tt_fini(tt); | ||
179 | + kfree(tt); | ||
180 | +} | ||
181 | +#else | ||
182 | static void vbox_ttm_backend_destroy(struct ttm_tt *tt) | ||
183 | { | ||
184 | ttm_tt_fini(tt); | ||
185 | @@ -209,6 +254,7 @@ static void vbox_ttm_backend_destroy(struct ttm_tt *tt) | ||
186 | static struct ttm_backend_func vbox_tt_backend_func = { | ||
187 | .destroy = &vbox_ttm_backend_destroy, | ||
188 | }; | ||
189 | +#endif | ||
190 | |||
191 | #if RTLNX_VER_MAX(4,17,0) && !RTLNX_RHEL_MAJ_PREREQ(7,6) && !RTLNX_SUSE_MAJ_PREREQ(15,1) && !RTLNX_SUSE_MAJ_PREREQ(12,5) | ||
192 | static struct ttm_tt *vbox_ttm_tt_create(struct ttm_bo_device *bdev, | ||
193 | @@ -226,7 +272,9 @@ static struct ttm_tt *vbox_ttm_tt_create(struct ttm_buffer_object *bo, | ||
194 | if (!tt) | ||
195 | return NULL; | ||
196 | |||
197 | +#if RTLNX_VER_MAX(5,10,0) | ||
198 | tt->func = &vbox_tt_backend_func; | ||
199 | +#endif | ||
200 | #if RTLNX_VER_MAX(4,17,0) && !RTLNX_RHEL_MAJ_PREREQ(7,6) && !RTLNX_SUSE_MAJ_PREREQ(15,1) && !RTLNX_SUSE_MAJ_PREREQ(12,5) | ||
201 | if (ttm_tt_init(tt, bdev, size, page_flags, dummy_read_page)) { | ||
202 | #else | ||
203 | @@ -261,11 +309,16 @@ static void vbox_ttm_tt_unpopulate(struct ttm_tt *ttm) | ||
204 | |||
205 | static struct ttm_bo_driver vbox_bo_driver = { | ||
206 | .ttm_tt_create = vbox_ttm_tt_create, | ||
207 | +#if RTLNX_VER_MIN(5,10,0) | ||
208 | + .ttm_tt_destroy = vbox_ttm_tt_destroy, | ||
209 | +#endif | ||
210 | #if RTLNX_VER_MAX(4,17,0) | ||
211 | .ttm_tt_populate = vbox_ttm_tt_populate, | ||
212 | .ttm_tt_unpopulate = vbox_ttm_tt_unpopulate, | ||
213 | #endif | ||
214 | +#if RTLNX_VER_MAX(5,10,0) | ||
215 | .init_mem_type = vbox_bo_init_mem_type, | ||
216 | +#endif | ||
217 | #if RTLNX_VER_MIN(4,10,0) || RTLNX_RHEL_MAJ_PREREQ(7,4) | ||
218 | .eviction_valuable = ttm_bo_eviction_valuable, | ||
219 | #endif | ||
220 | @@ -318,8 +371,13 @@ int vbox_mm_init(struct vbox_private *vbox) | ||
221 | #endif | ||
222 | } | ||
223 | |||
224 | +#if RTLNX_VER_MIN(5,10,0) | ||
225 | + ret = ttm_range_man_init(bdev, TTM_PL_VRAM, false, | ||
226 | + vbox->available_vram_size >> PAGE_SHIFT); | ||
227 | +#else | ||
228 | ret = ttm_bo_init_mm(bdev, TTM_PL_VRAM, | ||
229 | vbox->available_vram_size >> PAGE_SHIFT); | ||
230 | +#endif | ||
231 | if (ret) { | ||
232 | DRM_ERROR("Failed ttm VRAM init: %d\n", ret); | ||
233 | goto err_device_release; | ||
234 | @@ -359,7 +417,7 @@ void vbox_mm_fini(struct vbox_private *vbox) | ||
235 | #endif | ||
236 | } | ||
237 | |||
238 | -void vbox_ttm_placement(struct vbox_bo *bo, int domain) | ||
239 | +void vbox_ttm_placement(struct vbox_bo *bo, u32 mem_type) | ||
240 | { | ||
241 | u32 c = 0; | ||
242 | #if RTLNX_VER_MAX(3,18,0) && !RTLNX_RHEL_MAJ_PREREQ(7,2) | ||
243 | @@ -372,15 +430,36 @@ void vbox_ttm_placement(struct vbox_bo *bo, int domain) | ||
244 | bo->placement.placement = bo->placements; | ||
245 | bo->placement.busy_placement = bo->placements; | ||
246 | |||
247 | - if (domain & TTM_PL_FLAG_VRAM) | ||
248 | + if (mem_type & VBOX_MEM_TYPE_VRAM) { | ||
249 | +#if RTLNX_VER_MIN(5,10,0) | ||
250 | + bo->placements[c].mem_type = TTM_PL_VRAM; | ||
251 | + PLACEMENT_FLAGS(bo->placements[c++]) = | ||
252 | + TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED; | ||
253 | +#else | ||
254 | PLACEMENT_FLAGS(bo->placements[c++]) = | ||
255 | TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_VRAM; | ||
256 | - if (domain & TTM_PL_FLAG_SYSTEM) | ||
257 | +#endif | ||
258 | + } | ||
259 | + if (mem_type & VBOX_MEM_TYPE_SYSTEM) { | ||
260 | +#if RTLNX_VER_MIN(5,10,0) | ||
261 | + bo->placements[c].mem_type = TTM_PL_SYSTEM; | ||
262 | + PLACEMENT_FLAGS(bo->placements[c++]) = | ||
263 | + TTM_PL_MASK_CACHING; | ||
264 | +#else | ||
265 | PLACEMENT_FLAGS(bo->placements[c++]) = | ||
266 | TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM; | ||
267 | - if (!c) | ||
268 | +#endif | ||
269 | + } | ||
270 | + if (!c) { | ||
271 | +#if RTLNX_VER_MIN(5,10,0) | ||
272 | + bo->placements[c].mem_type = TTM_PL_SYSTEM; | ||
273 | + PLACEMENT_FLAGS(bo->placements[c++]) = | ||
274 | + TTM_PL_MASK_CACHING; | ||
275 | +#else | ||
276 | PLACEMENT_FLAGS(bo->placements[c++]) = | ||
277 | TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM; | ||
278 | +#endif | ||
279 | + } | ||
280 | |||
281 | bo->placement.num_placement = c; | ||
282 | bo->placement.num_busy_placement = c; | ||
283 | @@ -414,7 +493,7 @@ int vbox_bo_create(struct drm_device *dev, int size, int align, | ||
284 | vboxbo->bo.bdev->dev_mapping = dev->dev_mapping; | ||
285 | #endif | ||
286 | |||
287 | - vbox_ttm_placement(vboxbo, TTM_PL_FLAG_VRAM | TTM_PL_FLAG_SYSTEM); | ||
288 | + vbox_ttm_placement(vboxbo, VBOX_MEM_TYPE_VRAM | VBOX_MEM_TYPE_SYSTEM); | ||
289 | |||
290 | acc_size = ttm_bo_dma_acc_size(&vbox->ttm.bdev, size, | ||
291 | sizeof(struct vbox_bo)); | ||
292 | @@ -452,7 +531,7 @@ static inline u64 vbox_bo_gpu_offset(struct vbox_bo *bo) | ||
293 | #endif | ||
294 | } | ||
295 | |||
296 | -int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag, u64 *gpu_addr) | ||
297 | +int vbox_bo_pin(struct vbox_bo *bo, u32 mem_type, u64 *gpu_addr) | ||
298 | { | ||
299 | #if RTLNX_VER_MIN(4,16,0) || RTLNX_RHEL_MAJ_PREREQ(7,6) || RTLNX_SUSE_MAJ_PREREQ(15,1) || RTLNX_SUSE_MAJ_PREREQ(12,5) | ||
300 | struct ttm_operation_ctx ctx = { false, false }; | ||
301 | @@ -467,7 +546,7 @@ int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag, u64 *gpu_addr) | ||
302 | return 0; | ||
303 | } | ||
304 | |||
305 | - vbox_ttm_placement(bo, pl_flag); | ||
306 | + vbox_ttm_placement(bo, mem_type); | ||
307 | |||
308 | for (i = 0; i < bo->placement.num_placement; i++) | ||
309 | PLACEMENT_FLAGS(bo->placements[i]) |= TTM_PL_FLAG_NO_EVICT; | ||
310 | @@ -540,7 +619,7 @@ int vbox_bo_push_sysram(struct vbox_bo *bo) | ||
311 | if (bo->kmap.virtual) | ||
312 | ttm_bo_kunmap(&bo->kmap); | ||
313 | |||
314 | - vbox_ttm_placement(bo, TTM_PL_FLAG_SYSTEM); | ||
315 | + vbox_ttm_placement(bo, VBOX_MEM_TYPE_SYSTEM); | ||
316 | |||
317 | for (i = 0; i < bo->placement.num_placement; i++) | ||
318 | PLACEMENT_FLAGS(bo->placements[i]) |= TTM_PL_FLAG_NO_EVICT; | ||
319 | -- | ||
320 | 2.19.1 | ||
321 | |||
diff --git a/meta-oe/recipes-support/vboxguestdrivers/vboxguestdrivers/0001-Runtime-memobj-r0drv-linux.c-Changes-to-support-the-.patch b/meta-oe/recipes-support/vboxguestdrivers/vboxguestdrivers/0001-Runtime-memobj-r0drv-linux.c-Changes-to-support-the-.patch new file mode 100644 index 000000000..db27cb883 --- /dev/null +++ b/meta-oe/recipes-support/vboxguestdrivers/vboxguestdrivers/0001-Runtime-memobj-r0drv-linux.c-Changes-to-support-the-.patch | |||
@@ -0,0 +1,119 @@ | |||
1 | From 2a6e3cf63f58e289802a11faad5fb495e2d04e97 Mon Sep 17 00:00:00 2001 | ||
2 | From: vboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f> | ||
3 | Date: Wed, 9 Dec 2020 18:59:04 +0000 | ||
4 | Subject: [PATCH] Runtime/memobj-r0drv-linux.c: Changes to support the upcoming | ||
5 | 5.10 kernel, bugref:9879 | ||
6 | |||
7 | Upstream-Status: Backport | ||
8 | |||
9 | git-svn-id: http://www.virtualbox.org/svn/vbox@87074 cfe28804-0f27-0410-a406-dd0f0b0b656f | ||
10 | |||
11 | Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com> | ||
12 | --- | ||
13 | .../Runtime/r0drv/linux/memobj-r0drv-linux.c | 68 ++++++++++++++++++- | ||
14 | 1 file changed, 67 insertions(+), 1 deletion(-) | ||
15 | |||
16 | --- a/src/VBox/Runtime/r0drv/linux/memobj-r0drv-linux.c | ||
17 | +++ b/src/VBox/Runtime/r0drv/linux/memobj-r0drv-linux.c | ||
18 | @@ -56,9 +56,19 @@ | ||
19 | * Whether we use alloc_vm_area (3.2+) for executable memory. | ||
20 | * This is a must for 5.8+, but we enable it all the way back to 3.2.x for | ||
21 | * better W^R compliance (fExecutable flag). */ | ||
22 | -#if RTLNX_VER_MIN(3,2,0) || defined(DOXYGEN_RUNNING) | ||
23 | +#if RTLNX_VER_RANGE(3,2,0, 5,10,0) || defined(DOXYGEN_RUNNING) | ||
24 | # define IPRT_USE_ALLOC_VM_AREA_FOR_EXEC | ||
25 | #endif | ||
26 | +/** @def IPRT_USE_APPLY_TO_PAGE_RANGE_FOR_EXEC | ||
27 | + * alloc_vm_area was removed with 5.10 so we have to resort to a different way | ||
28 | + * to allocate executable memory. | ||
29 | + * It would be possible to remove IPRT_USE_ALLOC_VM_AREA_FOR_EXEC and use | ||
30 | + * this path execlusively for 3.2+ but no time to test it really works on every | ||
31 | + * supported kernel, so better play safe for now. | ||
32 | + */ | ||
33 | +#if RTLNX_VER_MIN(5,10,0) || defined(DOXYGEN_RUNNING) | ||
34 | +# define IPRT_USE_APPLY_TO_PAGE_RANGE_FOR_EXEC | ||
35 | +#endif | ||
36 | |||
37 | /* | ||
38 | * 2.6.29+ kernels don't work with remap_pfn_range() anymore because | ||
39 | @@ -502,6 +512,46 @@ static void rtR0MemObjLinuxFreePages(PRT | ||
40 | } | ||
41 | |||
42 | |||
43 | +#ifdef IPRT_USE_APPLY_TO_PAGE_RANGE_FOR_EXEC | ||
44 | +/** | ||
45 | + * User data passed to the apply_to_page_range() callback. | ||
46 | + */ | ||
47 | +typedef struct LNXAPPLYPGRANGE | ||
48 | +{ | ||
49 | + /** Pointer to the memory object. */ | ||
50 | + PRTR0MEMOBJLNX pMemLnx; | ||
51 | + /** The page protection flags to apply. */ | ||
52 | + pgprot_t fPg; | ||
53 | +} LNXAPPLYPGRANGE; | ||
54 | +/** Pointer to the user data. */ | ||
55 | +typedef LNXAPPLYPGRANGE *PLNXAPPLYPGRANGE; | ||
56 | +/** Pointer to the const user data. */ | ||
57 | +typedef const LNXAPPLYPGRANGE *PCLNXAPPLYPGRANGE; | ||
58 | + | ||
59 | +/** | ||
60 | + * Callback called in apply_to_page_range(). | ||
61 | + * | ||
62 | + * @returns Linux status code. | ||
63 | + * @param pPte Pointer to the page table entry for the given address. | ||
64 | + * @param uAddr The address to apply the new protection to. | ||
65 | + * @param pvUser The opaque user data. | ||
66 | + */ | ||
67 | +#ifdef __i386__ | ||
68 | +static int rtR0MemObjLinuxApplyPageRange(pte_t *pPte, unsigned long uAddr, void *pvUser) | ||
69 | +#else | ||
70 | +static DECLCALLBACK(int) rtR0MemObjLinuxApplyPageRange(pte_t *pPte, unsigned long uAddr, void *pvUser) | ||
71 | +#endif | ||
72 | +{ | ||
73 | + PCLNXAPPLYPGRANGE pArgs = (PCLNXAPPLYPGRANGE)pvUser; | ||
74 | + PRTR0MEMOBJLNX pMemLnx = pArgs->pMemLnx; | ||
75 | + size_t idxPg = (uAddr - (unsigned long)pMemLnx->Core.pv) >> PAGE_SHIFT; | ||
76 | + | ||
77 | + set_pte(pPte, mk_pte(pMemLnx->apPages[idxPg], pArgs->fPg)); | ||
78 | + return 0; | ||
79 | +} | ||
80 | +#endif | ||
81 | + | ||
82 | + | ||
83 | /** | ||
84 | * Maps the allocation into ring-0. | ||
85 | * | ||
86 | @@ -584,6 +634,11 @@ static int rtR0MemObjLinuxVMap(PRTR0MEMO | ||
87 | else | ||
88 | # endif | ||
89 | { | ||
90 | +# if defined(IPRT_USE_APPLY_TO_PAGE_RANGE_FOR_EXEC) | ||
91 | + if (fExecutable) | ||
92 | + pgprot_val(fPg) |= _PAGE_NX; /* Uses RTR0MemObjProtect to clear NX when memory ready, W^X fashion. */ | ||
93 | +# endif | ||
94 | + | ||
95 | # ifdef VM_MAP | ||
96 | pMemLnx->Core.pv = vmap(&pMemLnx->apPages[0], pMemLnx->cPages, VM_MAP, fPg); | ||
97 | # else | ||
98 | @@ -1851,6 +1906,21 @@ DECLHIDDEN(int) rtR0MemObjNativeProtect( | ||
99 | preempt_enable(); | ||
100 | return VINF_SUCCESS; | ||
101 | } | ||
102 | +# elif defined(IPRT_USE_APPLY_TO_PAGE_RANGE_FOR_EXEC) | ||
103 | + PRTR0MEMOBJLNX pMemLnx = (PRTR0MEMOBJLNX)pMem; | ||
104 | + if ( pMemLnx->fExecutable | ||
105 | + && pMemLnx->fMappedToRing0) | ||
106 | + { | ||
107 | + LNXAPPLYPGRANGE Args; | ||
108 | + Args.pMemLnx = pMemLnx; | ||
109 | + Args.fPg = rtR0MemObjLinuxConvertProt(fProt, true /*fKernel*/); | ||
110 | + int rcLnx = apply_to_page_range(current->active_mm, (unsigned long)pMemLnx->Core.pv + offSub, cbSub, | ||
111 | + rtR0MemObjLinuxApplyPageRange, (void *)&Args); | ||
112 | + if (rcLnx) | ||
113 | + return VERR_NOT_SUPPORTED; | ||
114 | + | ||
115 | + return VINF_SUCCESS; | ||
116 | + } | ||
117 | # endif | ||
118 | |||
119 | NOREF(pMem); | ||
diff --git a/meta-oe/recipes-support/vboxguestdrivers/vboxguestdrivers/0001-linser-vboxsf-Adjustment-for-linux-5.10-TASK_SIZE_MA.patch b/meta-oe/recipes-support/vboxguestdrivers/vboxguestdrivers/0001-linser-vboxsf-Adjustment-for-linux-5.10-TASK_SIZE_MA.patch new file mode 100644 index 000000000..3cfe2e917 --- /dev/null +++ b/meta-oe/recipes-support/vboxguestdrivers/vboxguestdrivers/0001-linser-vboxsf-Adjustment-for-linux-5.10-TASK_SIZE_MA.patch | |||
@@ -0,0 +1,46 @@ | |||
1 | From a276f8bc5e4515f7ea51e2c56e0e634a723ca104 Mon Sep 17 00:00:00 2001 | ||
2 | From: vboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f> | ||
3 | Date: Tue, 8 Dec 2020 13:52:53 +0000 | ||
4 | Subject: [PATCH] linser/vboxsf: Adjustment for linux 5.10 - TASK_SIZE_MAX | ||
5 | replaces USER_DS.seg. bugref:9879 | ||
6 | |||
7 | Upstream-Status: Backport | ||
8 | |||
9 | git-svn-id: http://www.virtualbox.org/svn/vbox@87053 cfe28804-0f27-0410-a406-dd0f0b0b656f | ||
10 | |||
11 | Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com> | ||
12 | --- | ||
13 | src/VBox/Additions/linux/sharedfolders/regops.c | 9 ++++++++- | ||
14 | 1 file changed, 8 insertions(+), 1 deletion(-) | ||
15 | |||
16 | diff --git a/src/VBox/Additions/linux/sharedfolders/regops.c b/src/VBox/Additions/linux/sharedfolders/regops.c | ||
17 | index e1fad3d820..401fd69930 100644 | ||
18 | --- a/src/VBox/Additions/linux/sharedfolders/regops.c | ||
19 | +++ b/src/VBox/Additions/linux/sharedfolders/regops.c | ||
20 | @@ -147,7 +147,11 @@ static int vbsf_iov_iter_detect_type(struct iovec const *paIov, size_t cSegs) | ||
21 | while (cSegs-- > 0) { | ||
22 | if (paIov->iov_len > 0) { | ||
23 | if (access_ok(VERIFY_READ, paIov->iov_base, paIov->iov_len)) | ||
24 | +#if RTLNX_VER_MIN(5,10,0) | ||
25 | + return (uintptr_t)paIov->iov_base >= TASK_SIZE_MAX ? ITER_KVEC : 0; | ||
26 | +#else | ||
27 | return (uintptr_t)paIov->iov_base >= USER_DS.seg ? ITER_KVEC : 0; | ||
28 | +#endif | ||
29 | AssertMsgFailed(("%p LB %#zx\n", paIov->iov_base, paIov->iov_len)); | ||
30 | break; | ||
31 | } | ||
32 | @@ -1401,7 +1405,10 @@ static int vbsf_lock_user_pages_failed_check_kernel(uintptr_t uPtrFrom, size_t c | ||
33 | /* | ||
34 | * Check that this is valid user memory that is actually in the kernel range. | ||
35 | */ | ||
36 | -#if RTLNX_VER_MIN(5,0,0) || RTLNX_RHEL_MIN(8,1) | ||
37 | +#if RTLNX_VER_MIN(5,10,0) | ||
38 | + if ( access_ok((void *)uPtrFrom, cPages << PAGE_SHIFT) | ||
39 | + && uPtrFrom >= TASK_SIZE_MAX) | ||
40 | +#elif RTLNX_VER_MIN(5,0,0) || RTLNX_RHEL_MIN(8,1) | ||
41 | if ( access_ok((void *)uPtrFrom, cPages << PAGE_SHIFT) | ||
42 | && uPtrFrom >= USER_DS.seg) | ||
43 | #else | ||
44 | -- | ||
45 | 2.19.1 | ||
46 | |||
diff --git a/meta-oe/recipes-support/vboxguestdrivers/vboxguestdrivers_6.1.16.bb b/meta-oe/recipes-support/vboxguestdrivers/vboxguestdrivers_6.1.16.bb index 9282f663b..ff639c09f 100644 --- a/meta-oe/recipes-support/vboxguestdrivers/vboxguestdrivers_6.1.16.bb +++ b/meta-oe/recipes-support/vboxguestdrivers/vboxguestdrivers_6.1.16.bb | |||
@@ -13,6 +13,9 @@ VBOX_NAME = "VirtualBox-${PV}" | |||
13 | 13 | ||
14 | SRC_URI = "http://download.virtualbox.org/virtualbox/${PV}/${VBOX_NAME}.tar.bz2 \ | 14 | SRC_URI = "http://download.virtualbox.org/virtualbox/${PV}/${VBOX_NAME}.tar.bz2 \ |
15 | file://Makefile.utils \ | 15 | file://Makefile.utils \ |
16 | file://0001-Additions-linux-drm-Adjustment-for-Linux-5.10.patch \ | ||
17 | file://0001-Runtime-memobj-r0drv-linux.c-Changes-to-support-the-.patch \ | ||
18 | file://0001-linser-vboxsf-Adjustment-for-linux-5.10-TASK_SIZE_MA.patch \ | ||
16 | " | 19 | " |
17 | SRC_URI[md5sum] = "a12a647f6c114f2cb1571089b36841fe" | 20 | SRC_URI[md5sum] = "a12a647f6c114f2cb1571089b36841fe" |
18 | SRC_URI[sha256sum] = "49c1990da16d8a3d5bda8cdb961ec8195a901e67e4c79aea44c1521a5fc2f9f1" | 21 | SRC_URI[sha256sum] = "49c1990da16d8a3d5bda8cdb961ec8195a901e67e4c79aea44c1521a5fc2f9f1" |