drm/virtio: do not enforce blob_alignment in cross-domain contexts
Subsystems (4)
PATCH v2 1/1 drm/virtio: do not enforce blob_alignment in cross-domain contexts
VIRTIO_GPU_F_BLOB_ALIGNMENT is designed for GPU rendering context types, however VIRTIO_GPU_CAPSET_CROSS_DOMAIN is not one of those. Resources created under cross-domain contexts are arbitrary shared system memory files, which includes unusual things like Wayland keymaps received from the host compositor. Do not enforce alignment requirements there.
---
v2: also check has_virgl_3d to prevent dereferencing NULL vfpriv
v1: https://lore.kernel.org/all/[email protected]/
~val
--- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +3 -1
@@ -551,7 +551,9 @@ static int verify_blob(struct virtio_gpu_device *vgdev, params->blob_flags = rc_blob->blob_flags; params->blob_hints = rc_blob->blob_hints; -if (vgdev->has_blob_alignment && +if (vgdev->has_blob_alignment && vgdev->has_virgl_3d && + (vfpriv->context_init &VIRTIO_GPU_CONTEXT_INIT_CAPSET_ID_MASK ) != +VIRTIO_GPU_CAPSET_CROSS_DOMAIN && !IS_ALIGNED (params->size, vgdev->blob_alignment))return -EINVAL ;
Signature · 1 line
2.55.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] drm/virtio: blob size alignment check is bypassed for 2D devices --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] drm/virtio: blob size alignment check is bypassed for 2D devices --
commit e9be6e8827fcf796e95413bb22d054eb21acf9b4
Author: Val Packett <[email protected]>
drm/virtio: do not enforce blob_alignment in cross-domain contexts
This commit stops enforcing blob_alignment requirements in cross-domain contexts. Resources created under these contexts are arbitrary shared system memory files rather than GPU rendering contexts, so alignment is no longer strictly enforced.
Quoted 5 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +0
-0
drivers/gpu/drm/virtio/virtgpu_ioctl.c static int verify_blob(struct virtio_gpu_device *vgdev, · line 546
Quoted 9 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +3
-1@@ -539,7 +539,9 @@ static int verify_blob(struct virtio_gpu_device *vgdev, params->blob_flags = rc_blob->blob_flags; params->blob_hints = rc_blob->blob_hints; -if (vgdev->has_blob_alignment && +if (vgdev->has_blob_alignment && vgdev->has_virgl_3d && + (vfpriv->context_init &VIRTIO_GPU_CONTEXT_INIT_CAPSET_ID_MASK ) != +VIRTIO_GPU_CAPSET_CROSS_DOMAIN && !IS_ALIGNED (params->size, vgdev->blob_alignment))return -EINVAL ;
[Severity: Medium]
Does adding the vgdev->has_virgl_3d check here completely bypass the size alignment validation for 2D devices?
If has_virgl_3d is false, the condition short-circuits and skips the IS_ALIGNED() check entirely. This seems to allow userspace to request unaligned blob sizes on non-3D devices, which could potentially cause host-side errors or command rejection.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Dmitry Osipenko
maintainerQuoted 24 lines · Val Packett
VIRTIO_GPU_F_BLOB_ALIGNMENTis designed for GPU rendering context types, howeverVIRTIO_GPU_CAPSET_CROSS_DOMAINis not one of those. Resources created under cross-domain contexts are arbitrary shared system memory files, which includes unusual things like Wayland keymaps received from the host compositor. Do not enforce alignment requirements there.Fixes 47248e0d8264 ("drm/virtio: honor blob_alignment requirements")Signed-off-by Val Packett <[email protected]>---
v2: also check
has_virgl_3dto prevent dereferencing NULL vfpriv
v1: https://lore.kernel.org/all/[email protected]/~val
--- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/virtio/virtgpu_ioctl.c +0
-0
drivers/gpu/drm/virtio/virtgpu_ioctl.c static int verify_blob(struct virtio_gpu_device *vgdev, · line 559
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +3
-1@@ -551,7 +551,9 @@ static int verify_blob(struct virtio_gpu_device *vgdev, params->blob_flags = rc_blob->blob_flags; params->blob_hints = rc_blob->blob_hints; -if (vgdev->has_blob_alignment && +if (vgdev->has_blob_alignment && vgdev->has_virgl_3d && + (vfpriv->context_init &VIRTIO_GPU_CONTEXT_INIT_CAPSET_ID_MASK ) != +VIRTIO_GPU_CAPSET_CROSS_DOMAIN && !IS_ALIGNED (params->size, vgdev->blob_alignment))return -EINVAL ;
What userspace has this problem and why it re-purposes virtio-gpu to act as udmabuf for arbitrary data that never reaches host?
Signature · 2 lines
Best regards, Dmitry
Quoted 28 lines · Dmitry Osipenko
Quoted 27 lines · Val Packett
VIRTIO_GPU_F_BLOB_ALIGNMENTis designed for GPU rendering context types, howeverVIRTIO_GPU_CAPSET_CROSS_DOMAINis not one of those. Resources created under cross-domain contexts are arbitrary shared system memory files, which includes unusual things like Wayland keymaps received from the host compositor. Do not enforce alignment requirements there.Fixes 47248e0d8264 ("drm/virtio: honor blob_alignment requirements")Signed-off-by Val Packett <[email protected]>---
v2: also check
has_virgl_3dto prevent dereferencing NULL vfpriv
v1: https://lore.kernel.org/all/[email protected]/~val
--- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/virtio/virtgpu_ioctl.c +0
-0@@ -551,7 +551,9 @@ static int verify_blob(struct virtio_gpu_device *vgdev, params->blob_flags = rc_blob->blob_flags; params->blob_hints = rc_blob->blob_hints;
Quoted 9 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c static int verify_blob(struct virtio_gpu_device *vgdev, · line 559
Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +3
-1-if (vgdev->has_blob_alignment && +if (vgdev->has_blob_alignment && vgdev->has_virgl_3d && + (vfpriv->context_init &VIRTIO_GPU_CONTEXT_INIT_CAPSET_ID_MASK ) != +VIRTIO_GPU_CAPSET_CROSS_DOMAIN && !IS_ALIGNED (params->size, vgdev->blob_alignment))return -EINVAL ;What userspace has this problem and why it re-purposes virtio-gpu to act as udmabuf for arbitrary data that never reaches host?
Sorry, what do you mean by that?
This is not related to data that "never reaches host" at all! The error I referred to in the patch message literally says "received *from* the host"…??
Guest userspace is any of the cross-domain proxies:
* https://codeberg.org/drakulix/wl-cross-domain-proxy
* https://github.com/talex5/wayland-proxy-virtwl
* https://github.com/google/sommelier-rs (or old C++ version)
VIRTIO_GPU_CAPSET_CROSS_DOMAIN "repurposes virtio-gpu" to act as a cross-VM UNIX socket transport that supports fd passing. By referring to virtio-gpu resources in the send command the guest can make the device send the resources' corresponding host fds to the host Wayland compositor. It can refer to resources from other contexts, in order to present drm/venus/etc rendered buffers on Wayland surfaces. (i.e. the host would send the actual dma-buf from virglrenderer) But the resources created on the cross-domain context itself are system memory buffers, generally used for software rendering and miscellaneous Wayland "stuff" like keymaps which are sent *from* the host, and exposed to Wayland clients in the guest. Socket receive handling in rutabaga-gfx stores incoming fds and returns their IDs to the guest, then the guest does a CREATE_BLOB with matching blob_id, which creates a virtio-gpu resource from the incoming buffer, so the guest can just MAP_BLOB it. These are the blobs that are not aligned to anything because they're just arbitrary memfds on the host.
~val
Dmitry Osipenko
maintainerQuoted 55 lines · Val Packett
Quoted 32 lines · Dmitry Osipenko
Quoted 31 lines · Val Packett
VIRTIO_GPU_F_BLOB_ALIGNMENTis designed for GPU rendering context types, howeverVIRTIO_GPU_CAPSET_CROSS_DOMAINis not one of those. Resources created under cross-domain contexts are arbitrary shared system memory files, which includes unusual things like Wayland keymaps received from the host compositor. Do not enforce alignment requirements there.Fixes 47248e0d8264 ("drm/virtio: honor blob_alignment requirements")Signed-off-by Val Packett <[email protected]>---
v2: also check
has_virgl_3dto prevent dereferencing NULL vfpriv
v1: https://lore.kernel.org/all/20261006004044.2242154-1-
[email protected]/~val
---
drivers/gpu/drm/virtio/virtgpu_ioctl.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/ renamed from drivers/gpu/drm/virtio/virtgpu_ioctl.c +0
-0
drm/virtio/virtgpu_ioctl.c
index3ddd5481d6bc..4d5ae062834d100644drivers/gpu/drm/virtio/virtgpu_ioctl.c +0
-0@@ -551,7 +551,9 @@ static int verify_blob(struct virtio_gpu_device *vgdev, params->blob_flags = rc_blob->blob_flags; params->blob_hints = rc_blob->blob_hints;- if (
vgdev->has_blob_alignment&&
+ if (vgdev->has_blob_alignment&&vgdev->has_virgl_3d&&Quoted 8 lines
Quoted 6 lines
+ (
vfpriv->context_init&VIRTIO_GPU_CONTEXT_INIT_CAPSET_ID_MASK) !=
+VIRTIO_GPU_CAPSET_CROSS_DOMAIN&& !IS_ALIGNED(params->size,vgdev->blob_alignment)) return-EINVAL;What userspace has this problem and why it re-purposes virtio-gpu to act as udmabuf for arbitrary data that never reaches host?
Sorry, what do you mean by that?
This is not related to data that "never reaches host" at all! The error I referred to in the patch message literally says "received *from* the host"…??
Guest userspace is any of the cross-domain proxies:
* https://codeberg.org/drakulix/wl-cross-domain-proxy
* https://github.com/talex5/wayland-proxy-virtwl
* https://github.com/google/sommelier-rs (or old C++ version)
Quoted 16 lines
VIRTIO_GPU_CAPSET_CROSS_DOMAIN"repurposes virtio-gpu" to act as a cross-VM UNIX socket transport that supports fd passing. By referring to virtio-gpu resources in the send command the guest can make the device send the resources' corresponding host fds to the host Wayland compositor. It can refer to resources from other contexts, in order to present drm/venus/etc rendered buffers on Wayland surfaces. (i.e. the host would send the actual dma-buf from virglrenderer) But the resources created on the cross-domain context itself are system memory buffers, generally used for software rendering and miscellaneous Wayland "stuff" like keymaps which are sent *from* the host, and exposed to Wayland clients in the guest. Socket receive handling in rutabaga-gfx stores incoming fds and returns their IDs to the guest, then the guest does aCREATE_BLOBwith matchingblob_id, which creates a virtio-gpu resource from the incoming buffer, so the guest can justMAP_BLOBit. These are the blobs that are not aligned to anything because they're just arbitrary memfds on the host.
Blob is a chunk of memory intended to be shared between host and guest.
The shared mappable buffer size must be aligned to a page size granularity that satisfies both host and guest requirement.
If I'm now reading correctly, you're saying that here blob size is arbitrary payload data size, even not the the aligned size of memory blob that contains payload. And userspace code implicitly relies on kernel to round-up payload size to a guest's page size.
We now have blob_alignment and verifying the unaligned params->size. Given the userspace dependency on the kernel's implicit round-up, we should be checking blob_alignment of the rounded-up params->size:
+ if (*guest_blob)
+ params->size = roundup(params->size, PAGE_SIZE);
if (vgdev->has_blob_alignment && !IS_ALIGNED(params->size, vgdev->blob_alignment)) return -EINVAL;
Does it work for you?
Signature · 2 lines
Best regards, Dmitry
Dmitry Osipenko
maintainerQuoted 55 lines · Val Packett
Quoted 32 lines · Dmitry Osipenko
Quoted 31 lines · Val Packett
VIRTIO_GPU_F_BLOB_ALIGNMENTis designed for GPU rendering context types, howeverVIRTIO_GPU_CAPSET_CROSS_DOMAINis not one of those. Resources created under cross-domain contexts are arbitrary shared system memory files, which includes unusual things like Wayland keymaps received from the host compositor. Do not enforce alignment requirements there.Fixes 47248e0d8264 ("drm/virtio: honor blob_alignment requirements")Signed-off-by Val Packett <[email protected]>---
v2: also check
has_virgl_3dto prevent dereferencing NULL vfpriv
v1: https://lore.kernel.org/all/20261006004044.2242154-1-
[email protected]/~val
---
drivers/gpu/drm/virtio/virtgpu_ioctl.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/ renamed from drivers/gpu/drm/virtio/virtgpu_ioctl.c +0
-0
drm/virtio/virtgpu_ioctl.c
index3ddd5481d6bc..4d5ae062834d100644drivers/gpu/drm/virtio/virtgpu_ioctl.c +0
-0@@ -551,7 +551,9 @@ static int verify_blob(struct virtio_gpu_device *vgdev, params->blob_flags = rc_blob->blob_flags; params->blob_hints = rc_blob->blob_hints;- if (
vgdev->has_blob_alignment&&
+ if (vgdev->has_blob_alignment&&vgdev->has_virgl_3d&&Quoted 8 lines
Quoted 6 lines
+ (
vfpriv->context_init&VIRTIO_GPU_CONTEXT_INIT_CAPSET_ID_MASK) !=
+VIRTIO_GPU_CAPSET_CROSS_DOMAIN&& !IS_ALIGNED(params->size,vgdev->blob_alignment)) return-EINVAL;What userspace has this problem and why it re-purposes virtio-gpu to act as udmabuf for arbitrary data that never reaches host?
Sorry, what do you mean by that?
This is not related to data that "never reaches host" at all! The error I referred to in the patch message literally says "received *from* the host"…??
Guest userspace is any of the cross-domain proxies:
* https://codeberg.org/drakulix/wl-cross-domain-proxy
* https://github.com/talex5/wayland-proxy-virtwl
* https://github.com/google/sommelier-rs (or old C++ version)
Quoted 16 lines
VIRTIO_GPU_CAPSET_CROSS_DOMAIN"repurposes virtio-gpu" to act as a cross-VM UNIX socket transport that supports fd passing. By referring to virtio-gpu resources in the send command the guest can make the device send the resources' corresponding host fds to the host Wayland compositor. It can refer to resources from other contexts, in order to present drm/venus/etc rendered buffers on Wayland surfaces. (i.e. the host would send the actual dma-buf from virglrenderer) But the resources created on the cross-domain context itself are system memory buffers, generally used for software rendering and miscellaneous Wayland "stuff" like keymaps which are sent *from* the host, and exposed to Wayland clients in the guest. Socket receive handling in rutabaga-gfx stores incoming fds and returns their IDs to the guest, then the guest does aCREATE_BLOBwith matchingblob_id, which creates a virtio-gpu resource from the incoming buffer, so the guest can justMAP_BLOBit. These are the blobs that are not aligned to anything because they're just arbitrary memfds on the host.
RE "These are the blobs that are not aligned to anything because they're just arbitrary memfds on the host." I'll appreciate confirmation from people more familiar with Sommelier internals like Gurchetan, Yiwei or Ryan.
In a case it is a correct claim, might be better to remove the blob_alignment check entirely and let blob sharing fail naturally if alignment is wrong.
Signature · 2 lines
Best regards, Dmitry
Dmitry Osipenko
maintainerQuoted 73 lines · Dmitry Osipenko
Quoted 55 lines · Val Packett
Quoted 32 lines · Dmitry Osipenko
Quoted 31 lines · Val Packett
VIRTIO_GPU_F_BLOB_ALIGNMENTis designed for GPU rendering context types, howeverVIRTIO_GPU_CAPSET_CROSS_DOMAINis not one of those. Resources created under cross-domain contexts are arbitrary shared system memory files, which includes unusual things like Wayland keymaps received from the host compositor. Do not enforce alignment requirements there.Fixes 47248e0d8264 ("drm/virtio: honor blob_alignment requirements")Signed-off-by Val Packett <[email protected]>---
v2: also check
has_virgl_3dto prevent dereferencing NULL vfpriv
v1: https://lore.kernel.org/all/20261006004044.2242154-1-
[email protected]/~val
---
drivers/gpu/drm/virtio/virtgpu_ioctl.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/ renamed from drivers/gpu/drm/virtio/virtgpu_ioctl.c +0
-0
drm/virtio/virtgpu_ioctl.c
index3ddd5481d6bc..4d5ae062834d100644drivers/gpu/drm/virtio/virtgpu_ioctl.c +0
-0@@ -551,7 +551,9 @@ static int verify_blob(struct virtio_gpu_device *vgdev, params->blob_flags = rc_blob->blob_flags; params->blob_hints = rc_blob->blob_hints;- if (
vgdev->has_blob_alignment&&
+ if (vgdev->has_blob_alignment&&vgdev->has_virgl_3d&&Quoted 8 lines
Quoted 6 lines
+ (
vfpriv->context_init&VIRTIO_GPU_CONTEXT_INIT_CAPSET_ID_MASK) !=
+VIRTIO_GPU_CAPSET_CROSS_DOMAIN&& !IS_ALIGNED(params->size,vgdev->blob_alignment)) return-EINVAL;What userspace has this problem and why it re-purposes virtio-gpu to act as udmabuf for arbitrary data that never reaches host?
Sorry, what do you mean by that?
This is not related to data that "never reaches host" at all! The error I referred to in the patch message literally says "received *from* the host"…??
Guest userspace is any of the cross-domain proxies:
* https://codeberg.org/drakulix/wl-cross-domain-proxy
* https://github.com/talex5/wayland-proxy-virtwl
* https://github.com/google/sommelier-rs (or old C++ version)Quoted 16 lines
VIRTIO_GPU_CAPSET_CROSS_DOMAIN"repurposes virtio-gpu" to act as a cross-VM UNIX socket transport that supports fd passing. By referring to virtio-gpu resources in the send command the guest can make the device send the resources' corresponding host fds to the host Wayland compositor. It can refer to resources from other contexts, in order to present drm/venus/etc rendered buffers on Wayland surfaces. (i.e. the host would send the actual dma-buf from virglrenderer) But the resources created on the cross-domain context itself are system memory buffers, generally used for software rendering and miscellaneous Wayland "stuff" like keymaps which are sent *from* the host, and exposed to Wayland clients in the guest. Socket receive handling in rutabaga-gfx stores incoming fds and returns their IDs to the guest, then the guest does aCREATE_BLOBwith matchingblob_id, which creates a virtio-gpu resource from the incoming buffer, so the guest can justMAP_BLOBit. These are the blobs that are not aligned to anything because they're just arbitrary memfds on the host.
Quoted 8 lines
RE "These are the blobs that are not aligned to anything because they're just arbitrary memfds on the host." I'll appreciate confirmation from people more familiar with Sommelier internals like Gurchetan, Yiwei or Ryan.
In a case it is a correct claim, might be better to remove the
blob_alignmentcheck entirely and let blob sharing fail naturally if alignment is wrong.
Reproduced the bug with Sommelier.
Driver always implicitly rounds up BO size up to PAGE_SIZE for both guest and host blobs [1][2], hence need to retain this old behavior to fix the problem properly.
Please send v2
[1]
https://elixir.bootlin.com/linux/v7.2.10/source/drivers/gpu/drm/virtio/virtgpu_object.c#L217
[2]
https://elixir.bootlin.com/linux/v7.2.10/source/drivers/gpu/drm/virtio/virtgpu_vram.c#L210
drivers/gpu/drm/virtio/virtgpu_ioctl.c +8 -3
@@ -539,9 +539,15 @@ static int verify_blob(struct virtio_gpu_device *vgdev, params->blob_flags = rc_blob->blob_flags; params->blob_hints = rc_blob->blob_hints; -if (vgdev->has_blob_alignment && - !IS_ALIGNED (params->size, vgdev->blob_alignment)) -return -EINVAL ; +/* +* Blob sizes always implicitly rounded up to PAGE_SIZE by the +* driver, userspace may be unaware of the host's alignment. +* Round up to the larger of the host and guest page sizes. +*/ +if (vgdev->has_blob_alignment) + params->size = ALIGN(params->size, + max_t(u32, vgdev->blob_alignment,
PAGE_SIZE));
return 0;
}
Signature · 2 lines
Best regards, Dmitry
Quoted 75 lines · Dmitry Osipenko
Quoted 73 lines · Dmitry Osipenko
Quoted 71 lines · Val Packett
Quoted 32 lines · Dmitry Osipenko
Quoted 31 lines · Val Packett
VIRTIO_GPU_F_BLOB_ALIGNMENTis designed for GPU rendering context types, howeverVIRTIO_GPU_CAPSET_CROSS_DOMAINis not one of those. Resources created under cross-domain contexts are arbitrary shared system memory files, which includes unusual things like Wayland keymaps received from the host compositor. Do not enforce alignment requirements there.Fixes 47248e0d8264 ("drm/virtio: honor blob_alignment requirements")Signed-off-by Val Packett <[email protected]>---
v2: also check
has_virgl_3dto prevent dereferencing NULL vfpriv
v1: https://lore.kernel.org/all/20261006004044.2242154-1-
[email protected]/~val
--- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/ renamed from drivers/gpu/drm/virtio/virtgpu_ioctl.c +0
-0
drm/virtio/virtgpu_ioctl.c
index3ddd5481d6bc..4d5ae062834d100644drivers/gpu/drm/virtio/virtgpu_ioctl.c +1
-0@@ -551,7 +551,9 @@ static int verify_blob(struct virtio_gpu_device *vgdev, params->blob_flags = rc_blob->blob_flags; params->blob_hints = rc_blob->blob_hints; - if (vgdev->has_blob_alignment && + if (vgdev->has_blob_alignment && vgdev->has_virgl_3d &&Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_ioctl.c +1
-0+ (vfpriv->context_init &
VIRTIO_GPU_CONTEXT_INIT_CAPSET_ID_MASK) !=
+VIRTIO_GPU_CAPSET_CROSS_DOMAIN&&!IS_ALIGNED(params->size, vgdev->blob_alignment)) return -EINVAL;What userspace has this problem and why it re-purposes virtio-gpu to act as udmabuf for arbitrary data that never reaches host?
Sorry, what do you mean by that?
This is not related to data that "never reaches host" at all! The error I referred to in the patch message literally says "received *from* the host"…??
Guest userspace is any of the cross-domain proxies:
* https://codeberg.org/drakulix/wl-cross-domain-proxy
* https://github.com/talex5/wayland-proxy-virtwl
* https://github.com/google/sommelier-rs (or old C++ version)
VIRTIO_GPU_CAPSET_CROSS_DOMAIN"repurposes virtio-gpu" to act as a cross-VM UNIX socket transport that supports fd passing. By referring to virtio-gpu resources in the send command the guest can make the device send the resources' corresponding host fds to the host Wayland compositor. It can refer to resources from other contexts, in order to present drm/venus/etc rendered buffers on Wayland surfaces. (i.e. the host would send the actual dma-buf from virglrenderer) But the resources created on the cross-domain context itself are system memory buffers, generally used for software rendering and miscellaneous Wayland "stuff" like keymaps which are sent *from* the host, and exposed to Wayland clients in the guest. Socket receive handling in rutabaga-gfx stores incoming fds and returns their IDs to the guest, then the guest does aCREATE_BLOBwith matchingblob_id, which creates a virtio-gpu resource from the incoming buffer, so the guest can justMAP_BLOBit. These are the blobs that are not aligned to anything because they're just arbitrary memfds on the host.
Quoted 3 lines
Quoted 3 lines
RE "These are the blobs that are not aligned to anything because they're just arbitrary memfds on the host." I'll appreciate confirmation from people more familiar with Sommelier internals like Gurchetan, Yiwei or Ryan.
Technically there's no need to enforce alignment on keymaps backed by memfds, meanwhile those consumed by GPU have the proper alignment told by CROSS_DOMAIN_CMD_GET_IMAGE_REQUIREMENTS (unless it fails to do the right thing).
Quoted 44 lines
Quoted 5 lines
In a case it is a correct claim, might be better to remove the
blob_alignmentcheck entirely and let blob sharing fail naturally if alignment is wrong.Reproduced the bug with Sommelier.
Driver always implicitly rounds up BO size up to
PAGE_SIZEfor both guest and host blobs [1][2], hence need to retain this old behavior to fix the problem properly.Please send v2
[1]
https://elixir.bootlin.com/linux/v7.2.10/source/drivers/gpu/drm/virtio/virtgpu_object.c#L217
[2]
https://elixir.bootlin.com/linux/v7.2.10/source/drivers/gpu/drm/virtio/virtgpu_vram.c#L210drivers/gpu/drm/virtio/virtgpu_ioctl.c +8
-4@@ -539,9 +539,15 @@ static int verify_blob(struct virtio_gpu_device *vgdev, params->blob_flags = rc_blob->blob_flags; params->blob_hints = rc_blob->blob_hints; -if (vgdev->has_blob_alignment && - !IS_ALIGNED (params->size, vgdev->blob_alignment)) -return -EINVAL ; +/* +* Blob sizes always implicitly rounded up to PAGE_SIZE by the +* driver, userspace may be unaware of the host's alignment. +* Round up to the larger of the host and guest page sizes. +*/ +if (vgdev->has_blob_alignment) + params->size =ALIGN (params->size, +max_t (u32, vgdev->blob_alignment,PAGE_SIZE ));return 0 ; } --
Quoted 2 lines
Best regards,
Dmitry
I like Dmitry's latest proposal much better. Keeping the alignment agnostic to the guest userspace is more seamless, which also covers the implicit 4k alignment case without forcing userspace to adapt.
Best,
Yiwei