drm/virtio: introduce the HOST_PAGE_SIZE feature
Subsystems (4)
cover drm/virtio: introduce the HOST_PAGE_SIZE feature
There's an incresing number of machines supporting multiple page sizes and on these machines the host and a guest can be running, each one, with a different page size.
For what pertains to virtio-gpu, this is not a problem if the page size of the guest happens to be bigger or equal than the host, but will potentially lead to failures in memory allocations and/or mappings otherwise.
To improve this situation, we introduce here the HOST_PAGE_SIZE feature. This feature indicates that the host has an extended virtio_gpu_config structure that include it's own page size a new field.
On the second commit, we also add a new param that can be read with VIRTGPU_GETPARAM by userspace applications running in the guest to obtain the host's page size and find out the right alignment to be used in shared memory allocations.
Sergio Lopez (2):
drm/virtio: introduce the HOST_PAGE_SIZE feature drm/virtio: add VIRTGPU_PARAM_HOST_PAGE_SIZE to params
drivers/gpu/drm/virtio/virtgpu_drv.c | 1 + drivers/gpu/drm/virtio/virtgpu_drv.h | 2 ++ drivers/gpu/drm/virtio/virtgpu_ioctl.c | 5 +++++ drivers/gpu/drm/virtio/virtgpu_kms.c | 13 ++++++++++--- include/uapi/drm/virtgpu_drm.h | 1 + include/uapi/linux/virtio_gpu.h | 5 +++++ 6 files changed, 24 insertions(+), 3 deletions(-)
Signature · 1 line
2.45.2
PATCH 1/2 drm/virtio: introduce the HOST_PAGE_SIZE feature
Introduce a new feature, HOST_PAGE_SIZE, that indicates the host provides its page size as a value in virtio_gpu_config.
--- drivers/gpu/drm/virtio/virtgpu_drv.c | 1 + drivers/gpu/drm/virtio/virtgpu_drv.h | 2 ++ drivers/gpu/drm/virtio/virtgpu_kms.c | 13 ++++++++++--- include/uapi/linux/virtio_gpu.h | 5 +++++ 4 files changed, 18 insertions(+), 3 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.c +1 -0
@@ -149,6 +149,7 @@ static unsigned int features[] = {VIRTIO_GPU_F_RESOURCE_UUID ,VIRTIO_GPU_F_RESOURCE_BLOB ,VIRTIO_GPU_F_CONTEXT_INIT , + VIRTIO_GPU_F_HOST_PAGE_SIZE, };static struct virtio_driver virtio_gpu_driver = { .feature_table = features,
drivers/gpu/drm/virtio/virtgpu_drv.h +2 -0
@@ -249,6 +249,7 @@ struct virtio_gpu_device {bool has_resource_blob;bool has_host_visible;bool has_context_init; +bool has_host_page_size;struct virtio_shm_region host_visible_region;struct drm_mm host_visible_mm;
@@ -262,6 +263,7 @@ struct virtio_gpu_device {uint32_t num_capsets;uint64_t capset_id_mask;struct list_head cap_cache; +uint32_t host_page_size;/* protects uuid state when exporting */ spinlock_t resource_export_lock;
drivers/gpu/drm/virtio/virtgpu_kms.c +10 -3
@@ -124,7 +124,7 @@ int virtio_gpu_init(struct virtio_device *vdev, struct drm_device *dev)struct virtio_gpu_device *vgdev;/* this will expand later */ struct virtqueue *vqs[2 ]; -u32 num_scanouts, num_capsets; +u32 num_scanouts, num_capsets, host_page_size;int ret =0 ;if (!virtio_has_feature (vdev,VIRTIO_F_VERSION_1 ))
@@ -197,6 +197,12 @@ int virtio_gpu_init(struct virtio_device *vdev, struct drm_device *dev)if (virtio_has_feature (vgdev->vdev,VIRTIO_GPU_F_CONTEXT_INIT )) { vgdev->has_context_init = true; } +if (virtio_has_feature (vgdev->vdev,VIRTIO_GPU_F_HOST_PAGE_SIZE )) { + vgdev->has_host_page_size = true; + virtio_cread_le(vgdev->vdev, struct virtio_gpu_config, + host_page_size, &host_page_size); + vgdev->host_page_size = host_page_size; + } DRM_INFO("features: %cvirgl %cedid %cresource_blob %chost_visible", vgdev->has_virgl_3d ? '+' : '-',
@@ -204,8 +210,9 @@ int virtio_gpu_init(struct virtio_device *vdev, struct drm_device *dev) vgdev->has_resource_blob ?'+' :'-' , vgdev->has_host_visible ? '+' : '-'); -DRM_INFO ("features: %ccontext_init\n" , - vgdev->has_context_init ?'+' :'-' ); +DRM_INFO ("features: %ccontext_init %chost_page_size\n" , + vgdev->has_context_init ?'+' :'-' , + vgdev->has_host_page_size ?'+' :'-' ); ret =virtio_find_vqs (vgdev->vdev,2 , vqs, callbacks, names,NULL );if (ret) {
include/uapi/linux/virtio_gpu.h +5 -0
@@ -64,6 +64,10 @@* context_init and multiple timelines */ #define VIRTIO_GPU_F_CONTEXT_INIT 4 +/* +* Config struct contains host page size +*/ +#define VIRTIO_GPU_F_HOST_PAGE_SIZE 5enum virtio_gpu_ctrl_type {VIRTIO_GPU_UNDEFINED =0 ,
@@ -363,6 +367,7 @@ struct virtio_gpu_config {__le32 events_clear;__le32 num_scanouts;__le32 num_capsets; +__le32 host_page_size; };/* simple formats for fbcon/X use */
Signature · 1 line
2.45.2
PATCH 2/2 drm/virtio: add VIRTGPU_PARAM_HOST_PAGE_SIZE to params
In reply to Sergio LopezAdd VIRTGPU_PARAM_HOST_PAGE_SIZE as a param that can be read with VIRTGPU_GETPARAM by userspace applications running in the guest to obtain the host's page size and find out the right alignment to be used in shared memory allocations.
--- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 5 +++++ include/uapi/drm/virtgpu_drm.h | 1 + 2 files changed, 6 insertions(+)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +5 -0
@@ -117,6 +117,11 @@ static int virtio_gpu_getparam_ioctl(struct drm_device *dev, void *data,case VIRTGPU_PARAM_EXPLICIT_DEBUG_NAME : value = vgdev->has_context_init ?1 :0 ;break ; +case VIRTGPU_PARAM_HOST_PAGE_SIZE : +if (!vgdev->has_host_page_size) +return -EINVAL ; + value = vgdev->host_page_size; +break ;default :return -EINVAL ; }
include/uapi/drm/virtgpu_drm.h +1 -0
@@ -98,6 +98,7 @@ struct drm_virtgpu_execbuffer {#define VIRTGPU_PARAM_CONTEXT_INIT 6/* DRM_VIRTGPU_CONTEXT_INIT */ #define VIRTGPU_PARAM_SUPPORTED_CAPSET_IDs 7/* Bitmask of supported capability set ids */ #define VIRTGPU_PARAM_EXPLICIT_DEBUG_NAME 8/* Ability to set debug name from userspace */ +#define VIRTGPU_PARAM_HOST_PAGE_SIZE 9/* Host's page size */ struct drm_virtgpu_getparam {__u64 param;
Signature · 1 line
2.45.2
Dmitry Osipenko
maintainerQuoted 8 lines · Sergio Lopez
There's an incresing number of machines supporting multiple page sizes and on these machines the host and a guest can be running, each one, with a different page size.
For what pertains to virtio-gpu, this is not a problem if the page size of the guest happens to be bigger or equal than the host, but will potentially lead to failures in memory allocations and/or mappings otherwise.
Please describe concrete problem you're trying to solve. Guest memory allocation consists of guest pages, I don't see how knowledge of host page size helps anything in userspace.
I suspect you want this for host blobs, but then it should be virtio_gpu_vram_create() that should use max(host_page_sz, guest_page_size), AFAICT. It's kernel who is responsible for memory management, userspace can't be trusted for doing that.
Signature · 2 lines
Best regards, Dmitry
Quoted 10 lines · Dmitry Osipenko
Quoted 8 lines · Sergio Lopez
There's an incresing number of machines supporting multiple page sizes and on these machines the host and a guest can be running, each one, with a different page size.
For what pertains to virtio-gpu, this is not a problem if the page size of the guest happens to be bigger or equal than the host, but will potentially lead to failures in memory allocations and/or mappings otherwise.
Quoted 8 lines
Please describe concrete problem you're trying to solve. Guest memory allocation consists of guest pages, I don't see how knowledge of host page size helps anything in userspace.
I suspect you want this for host blobs, but then it should be
virtio_gpu_vram_create()that should usemax(host_page_sz, guest_page_size), AFAICT. It's kernel who is responsible for memory management, userspace can't be trusted for doing that.
Mesa's Vulkan/Venus uses CREATE_BLOB to request the host the creation and mapping into the guest of device-backed memory and shmem regions. The CREATE_BLOB ioctl doesn't update drm_virtgpu_resource_create->size, so the guest kernel (and, as a consequence, the host kernel) can't override the user's request.
I'd like Mesa's Vulkan/Venus in the guest to be able to obtain the host page size to align the size of the CREATE_BLOB requests as required.
Thanks,
Sergio.
Quoted 11 lines · Dmitry Osipenko
Quoted 8 lines · Sergio Lopez
There's an incresing number of machines supporting multiple page sizes and on these machines the host and a guest can be running, each one, with a different page size.
For what pertains to virtio-gpu, this is not a problem if the page size of the guest happens to be bigger or equal than the host, but will potentially lead to failures in memory allocations and/or mappings otherwise.
Quoted 8 lines
Please describe concrete problem you're trying to solve. Guest memory allocation consists of guest pages, I don't see how knowledge of host page size helps anything in userspace.
I suspect you want this for host blobs, but then it should be
virtio_gpu_vram_create()that should usemax(host_page_sz, guest_page_size), AFAICT. It's kernel who is responsible for memory management, userspace can't be trusted for doing that.
fwiw virtgpu native context would require this as well, mesa would need to know the host page size to correctly align GPU VA allocations (which must be a multiple of the host page size).
So a-b for adding this and exposing it to userspace.
BR,
-R
Quoted 4 lines
--
Best regards,
Dmitry
Gurchetan Singh
reviewerQuoted 21 lines · Sergio Lopez Pascual
Quoted 10 lines · Dmitry Osipenko
Quoted 8 lines · Sergio Lopez
There's an incresing number of machines supporting multiple page sizes and on these machines the host and a guest can be running, each one, with a different page size.
For what pertains to virtio-gpu, this is not a problem if the page size of the guest happens to be bigger or equal than the host, but will potentially lead to failures in memory allocations and/or mappings otherwise.
Quoted 8 lines
Please describe concrete problem you're trying to solve. Guest memory allocation consists of guest pages, I don't see how knowledge of host page size helps anything in userspace.
I suspect you want this for host blobs, but then it should be
virtio_gpu_vram_create()that should usemax(host_page_sz, guest_page_size), AFAICT. It's kernel who is responsible for memory management, userspace can't be trusted for doing that.
Quoted 9 lines
Mesa's Vulkan/Venus uses
CREATE_BLOBto request the host the creation and mapping into the guest of device-backed memory and shmem regions. TheCREATE_BLOBioctl doesn't updatedrm_virtgpu_resource_create->size, so the guest kernel (and, as a consequence, the host kernel) can't override the user's request.I'd like Mesa's Vulkan/Venus in the guest to be able to obtain the host page size to align the size of the
CREATE_BLOBrequests as required.
gfxstream solves this problem by putting the relevant information in the capabilities obtained from the host:
If you want to be paranoid, you can also validate the ResourceCreateBlob::size is properly host-page aligned when that request reaches the host.
So you can probably solve this problem using current interfaces. Whether it's cleaner for all context types to use the capabilities, or have all VMMs to expose VIRTIO_GPU_F_HOST_PAGE_SIZE, would be the cost/benefit tradeoff.
Quoted 5 lines
Thanks,
Sergio.
Quoted 36 lines · Gurchetan Singh
Quoted 22 lines · Sergio Lopez Pascual
Quoted 10 lines · Dmitry Osipenko
Quoted 8 lines · Sergio Lopez
There's an incresing number of machines supporting multiple page sizes and on these machines the host and a guest can be running, each one, with a different page size.
For what pertains to virtio-gpu, this is not a problem if the page size of the guest happens to be bigger or equal than the host, but will potentially lead to failures in memory allocations and/or mappings otherwise.
Quoted 8 lines
Please describe concrete problem you're trying to solve. Guest memory allocation consists of guest pages, I don't see how knowledge of host page size helps anything in userspace.
I suspect you want this for host blobs, but then it should be
virtio_gpu_vram_create()that should usemax(host_page_sz, guest_page_size), AFAICT. It's kernel who is responsible for memory management, userspace can't be trusted for doing that.Quoted 8 lines
Mesa's Vulkan/Venus uses
CREATE_BLOBto request the host the creation and mapping into the guest of device-backed memory and shmem regions. TheCREATE_BLOBioctl doesn't updatedrm_virtgpu_resource_create->size, so the guest kernel (and, as a consequence, the host kernel) can't override the user's request.I'd like Mesa's Vulkan/Venus in the guest to be able to obtain the host page size to align the size of the
CREATE_BLOBrequests as required.
Quoted 8 lines
gfxstream solves this problem by putting the relevant information in the capabilities obtained from the host:
If you want to be paranoid, you can also validate the
ResourceCreateBlob::sizeis properly host-page aligned when that request reaches the host.So you can probably solve this problem using current interfaces. Whether it's cleaner for all context types to use the capabilities, or have all VMMs to expose
VIRTIO_GPU_F_HOST_PAGE_SIZE, would be the cost/benefit tradeoff.
I guess solving it in a context-type specific way is possible. But I think it is a relatively universal constraint. And maybe it makes sense for virtgpu guest kernel to enforce alignment (at least it can return an error synchronously) in addition to the host.
BR,
-R
Quoted 5 lines
Quoted 5 lines
Thanks,
Sergio.
Gurchetan Singh
reviewerQuoted 57 lines · Rob Clark
Quoted 4 lines · Gurchetan Singh
On Mon, Aug 5, 2024 at 2:14 AM Sergio Lopez Pascual <[email protected]>
Quoted 5 lines · wrote:
Quoted 5 lines
Quoted 2 lines · Dmitry Osipenko
Quoted 1 line · Sergio Lopez
There's an incresing number of machines supporting multiple page
sizes
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
and on these machines the host and a guest can be running, each one, with a different page size.
For what pertains to virtio-gpu, this is not a problem if the page
size
Quoted 19 lines
Quoted 19 lines
Quoted 4 lines
Quoted 3 lines
of the guest happens to be bigger or equal than the host, but will potentially lead to failures in memory allocations and/or mappings otherwise.
Quoted 8 lines
Please describe concrete problem you're trying to solve. Guest memory allocation consists of guest pages, I don't see how knowledge of host page size helps anything in userspace.
I suspect you want this for host blobs, but then it should be
virtio_gpu_vram_create()that should usemax(host_page_sz, guest_page_size), AFAICT. It's kernel who is responsible for memory management, userspace can't be trusted for doing that.Mesa's Vulkan/Venus uses
CREATE_BLOBto request the host the creation and mapping into the guest of device-backed memory and shmem regions. TheCREATE_BLOBioctl doesn't updatedrm_virtgpu_resource_create->size, so the guest kernel (and, as a consequence, the host kernel) can't override the user's request.Quoted 5 lines
Quoted 2 lines
I'd like Mesa's Vulkan/Venus in the guest to be able to obtain the host page size to align the size of the
CREATE_BLOBrequests as required.gfxstream solves this problem by putting the relevant information in the
capabilities obtained from the host:
Quoted 2 lines
Quoted 2 lines
If you want to be paranoid, you can also validate the
ResourceCreateBlob::sizeis properly host-page aligned when that request reaches the host.Quoted 2 lines
So you can probably solve this problem using current interfaces.
Whether it's cleaner for all context types to use the capabilities, or have all VMMs to expose
VIRTIO_GPU_F_HOST_PAGE_SIZE, would be the cost/benefit tradeoff.Quoted 1 line
Quoted 5 lines
I guess solving it in a context-type specific way is possible. But I think it is a relatively universal constraint. And maybe it makes sense for virtgpu guest kernel to enforce alignment (at least it can return an error synchronously) in addition to the host.
virtio-media may have support for VIRTIO_MEDIA_CMD_MMAP too, so could run into this issue.
https://github.com/chromeos/virtio-media?tab=readme-ov-file#shared-memory-regions
virtio-fs also has the DAX window which uses the same memory mapping mechanism.
https://virtio-fs.gitlab.io/design.html
Maybe this should not be a virtio-gpu thing, but a virtio thing?
Quoted 10 lines
BR,
-RQuoted 5 lines
Quoted 5 lines
Thanks,
Sergio.
Quoted 68 lines · Gurchetan Singh
Quoted 57 lines · Rob Clark
Quoted 4 lines · Gurchetan Singh
On Mon, Aug 5, 2024 at 2:14 AM Sergio Lopez Pascual <[email protected]>
Quoted 5 lines · wrote:
Quoted 5 lines
Quoted 2 lines · Dmitry Osipenko
Quoted 1 line · Sergio Lopez
There's an incresing number of machines supporting multiple page
sizes
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
and on these machines the host and a guest can be running, each one, with a different page size.
For what pertains to virtio-gpu, this is not a problem if the page
size
Quoted 19 lines
Quoted 19 lines
Quoted 4 lines
Quoted 3 lines
of the guest happens to be bigger or equal than the host, but will potentially lead to failures in memory allocations and/or mappings otherwise.
Quoted 8 lines
Please describe concrete problem you're trying to solve. Guest memory allocation consists of guest pages, I don't see how knowledge of host page size helps anything in userspace.
I suspect you want this for host blobs, but then it should be
virtio_gpu_vram_create()that should usemax(host_page_sz, guest_page_size), AFAICT. It's kernel who is responsible for memory management, userspace can't be trusted for doing that.Mesa's Vulkan/Venus uses
CREATE_BLOBto request the host the creation and mapping into the guest of device-backed memory and shmem regions. TheCREATE_BLOBioctl doesn't updatedrm_virtgpu_resource_create->size, so the guest kernel (and, as a consequence, the host kernel) can't override the user's request.Quoted 5 lines
Quoted 2 lines
I'd like Mesa's Vulkan/Venus in the guest to be able to obtain the host page size to align the size of the
CREATE_BLOBrequests as required.gfxstream solves this problem by putting the relevant information in the
capabilities obtained from the host:
Quoted 2 lines
Quoted 2 lines
If you want to be paranoid, you can also validate the
ResourceCreateBlob::sizeis properly host-page aligned when that request reaches the host.Quoted 2 lines
So you can probably solve this problem using current interfaces.
Whether it's cleaner for all context types to use the capabilities, or have all VMMs to expose
VIRTIO_GPU_F_HOST_PAGE_SIZE, would be the cost/benefit tradeoff.Quoted 1 line
Quoted 5 lines
I guess solving it in a context-type specific way is possible. But I think it is a relatively universal constraint. And maybe it makes sense for virtgpu guest kernel to enforce alignment (at least it can return an error synchronously) in addition to the host.
virtio-media may have support for
VIRTIO_MEDIA_CMD_MMAPtoo, so could run into this issue.
Quoted 8 lines
https://github.com/chromeos/virtio-media?tab=readme-ov-file#shared-memory-regions
virtio-fs also has the DAX window which uses the same memory mapping mechanism.
https://virtio-fs.gitlab.io/design.html
Maybe this should not be a virtio-gpu thing, but a virtio thing?
This is true, but finding a common place to put the page size is really hard in practice. I don't think we can borrow space in the feature bits for that (and that would probably be abusing its purpose quite a bit) and extending the transport configuration registers is quite cumbersome and, in general, undesirable.
That leaves us with the device-specific config space, and that implies a device-specific feature bit as it's implemented in this series.
The Shared Memory Regions on the VIRTIO spec, while doesn't talk specifically about page size, also gives us a hint about this being the right direction:
"
2.10 Shared Memory Regions
(...)
Memory consistency rules vary depending on the region and the device and they will be specified as required by each device."
"
Thanks,
Sergio.
Dmitry Osipenko
maintainerQuoted 22 lines · Rob Clark
Quoted 11 lines · Dmitry Osipenko
Quoted 8 lines · Sergio Lopez
There's an incresing number of machines supporting multiple page sizes and on these machines the host and a guest can be running, each one, with a different page size.
For what pertains to virtio-gpu, this is not a problem if the page size of the guest happens to be bigger or equal than the host, but will potentially lead to failures in memory allocations and/or mappings otherwise.
Quoted 8 lines
Please describe concrete problem you're trying to solve. Guest memory allocation consists of guest pages, I don't see how knowledge of host page size helps anything in userspace.
I suspect you want this for host blobs, but then it should be
virtio_gpu_vram_create()that should usemax(host_page_sz, guest_page_size), AFAICT. It's kernel who is responsible for memory management, userspace can't be trusted for doing that.
Quoted 5 lines
fwiw virtgpu native context would require this as well, mesa would need to know the host page size to correctly align GPU VA allocations (which must be a multiple of the host page size).
So a-b for adding this and exposing it to userspace.
In general, GPU page size has no connection to the CPU page size. It happens that MSM driver uses same page size for both GPU and CPU. Likely you could configure a different GPU page size if you wanted. dGPUs would often use 64k pages.
Signature · 2 lines
Best regards, Dmitry
Gurchetan Singh
reviewerQuoted 95 lines · Sergio Lopez Pascual
Quoted 8 lines · Gurchetan Singh
Quoted 6 lines · Rob Clark
Quoted 4 lines · Gurchetan Singh
On Mon, Aug 5, 2024 at 2:14 AM Sergio Lopez Pascual <[email protected]>
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines · wrote:
Quoted 5 lines
Quoted 2 lines · Dmitry Osipenko
Quoted 1 line · Sergio Lopez
There's an incresing number of machines supporting multiple page
sizes
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
and on these machines the host and a guest can be running, each
one,
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
with a different page size.
For what pertains to virtio-gpu, this is not a problem if the page
size
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
of the guest happens to be bigger or equal than the host, but will potentially lead to failures in memory allocations and/or mappings otherwise.
Please describe concrete problem you're trying to solve. Guest
memory
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
allocation consists of guest pages, I don't see how knowledge of
host
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 6 lines
page size helps anything in userspace.
I suspect you want this for host blobs, but then it should be
virtio_gpu_vram_create()that should usemax(host_page_sz, guest_page_size), AFAICT. It's kernel who is responsible for memory management, userspace can't be trusted for doing that.Mesa's Vulkan/Venus uses
CREATE_BLOBto request the host the creation and mapping into the guest of device-backed memory and shmem regions. TheCREATE_BLOBioctl doesn't update
drm_virtgpu_resource_create->size,Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
so the guest kernel (and, as a consequence, the host kernel) can't override the user's request.
I'd like Mesa's Vulkan/Venus in the guest to be able to obtain the
host
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
page size to align the size of the
CREATE_BLOBrequests as required.gfxstream solves this problem by putting the relevant information in
the
Quoted 4 lines
Quoted 4 lines
capabilities obtained from the host:
Quoted 2 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
If you want to be paranoid, you can also validate the
ResourceCreateBlob::sizeis properly host-page aligned when that request reaches the host.Quoted 2 lines
So you can probably solve this problem using current interfaces.
Whether it's cleaner for all context types to use the capabilities, or
have
Quoted 1 line
Quoted 1 line
all VMMs to expose
VIRTIO_GPU_F_HOST_PAGE_SIZE, would be thecost/benefit
Quoted 13 lines
Quoted 8 lines
tradeoff.
Quoted 1 line
I guess solving it in a context-type specific way is possible. But I think it is a relatively universal constraint. And maybe it makes sense for virtgpu guest kernel to enforce alignment (at least it can return an error synchronously) in addition to the host.
virtio-media may have support for
VIRTIO_MEDIA_CMD_MMAPtoo, so could run into this issue.https://github.com/chromeos/virtio-media?tab=readme-ov-file#shared-memory-regions
Quoted 7 lines
virtio-fs also has the DAX window which uses the same memory mapping mechanism.
https://virtio-fs.gitlab.io/design.html
Maybe this should not be a virtio-gpu thing, but a virtio thing?
This is true, but finding a common place to put the page size is really hard in practice. I don't think we can borrow space in the feature bits for that (and that would probably be abusing its purpose quite a bit) and extending the transport configuration registers is quite cumbersome and, in general, undesirable.
Quoted 7 lines
That leaves us with the device-specific config space, and that implies a device-specific feature bit as it's implemented in this series.
The Shared Memory Regions on the VIRTIO spec, while doesn't talk specifically about page size, also gives us a hint about this being the right direction:
Can't we just modify the Shared Memory region PCI capability to include page size? We can either:
1) keep the same size struct + header (VIRTIO_PCI_CAP_SHARED_MEMORY_CFG), and just hijack one of the padding fields. If the padding field is zero, we can just say it's 4096.
or
2) Or expand the size of the struct, withVIRTIO_PCI_CAP_SHARED_MEMORY_CFG2.
(sketch here: crrev.com/c/5778179)
The benefit of this would work with virtio-fs (though I'm not sure anyone uses the DAX window), and possibly virtio-media in the future.
Quoted 12 lines
"
2.10 Shared Memory Regions
(...)
Memory consistency rules vary depending on the region and the device and they will be specified as required by each device."
"Thanks,
Sergio.
Quoted 28 lines · Dmitry Osipenko
Quoted 26 lines · Rob Clark
Quoted 11 lines · Dmitry Osipenko
Quoted 8 lines · Sergio Lopez
There's an incresing number of machines supporting multiple page sizes and on these machines the host and a guest can be running, each one, with a different page size.
For what pertains to virtio-gpu, this is not a problem if the page size of the guest happens to be bigger or equal than the host, but will potentially lead to failures in memory allocations and/or mappings otherwise.
Quoted 8 lines
Please describe concrete problem you're trying to solve. Guest memory allocation consists of guest pages, I don't see how knowledge of host page size helps anything in userspace.
I suspect you want this for host blobs, but then it should be
virtio_gpu_vram_create()that should usemax(host_page_sz, guest_page_size), AFAICT. It's kernel who is responsible for memory management, userspace can't be trusted for doing that.fwiw virtgpu native context would require this as well, mesa would need to know the host page size to correctly align GPU VA allocations (which must be a multiple of the host page size).
Quoted 6 lines
Quoted 1 line
So a-b for adding this and exposing it to userspace.
In general, GPU page size has no connection to the CPU page size. It happens that MSM driver uses same page size for both GPU and CPU. Likely you could configure a different GPU page size if you wanted. dGPUs would often use 64k pages.
The smmu actually supports various different page sizes (4k, 64k, etc.. I think up to 2g), and will try to map larger contiguous sets of pages using larger page sizes to reduce TLB pressure. This restriction about aligning to host page size is because the kernel expects allocations and therefore (currently, pre-sparse) gpu mappings to be a multiple of the host page size.
As far as whether this should be something outside of virtio-gpu, this does feel a bit specific to how GEM buffer allocations work and how host blob resources work. Maybe other subsystems like media end up with similar constraints for similar reasons, idk. But it at least feels like something applicable to all/most virtgpu context types.
BR,
-R
Quoted 105 lines · Gurchetan Singh
Quoted 95 lines · Sergio Lopez Pascual
Quoted 8 lines · Gurchetan Singh
Quoted 6 lines · Rob Clark
Quoted 4 lines · Gurchetan Singh
On Mon, Aug 5, 2024 at 2:14 AM Sergio Lopez Pascual <[email protected]>
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines · wrote:
Quoted 5 lines
Quoted 2 lines · Dmitry Osipenko
Quoted 1 line · Sergio Lopez
There's an incresing number of machines supporting multiple page
sizes
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
and on these machines the host and a guest can be running, each
one,
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
with a different page size.
For what pertains to virtio-gpu, this is not a problem if the page
size
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
of the guest happens to be bigger or equal than the host, but will potentially lead to failures in memory allocations and/or mappings otherwise.
Please describe concrete problem you're trying to solve. Guest
memory
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
allocation consists of guest pages, I don't see how knowledge of
host
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 6 lines
page size helps anything in userspace.
I suspect you want this for host blobs, but then it should be
virtio_gpu_vram_create()that should usemax(host_page_sz, guest_page_size), AFAICT. It's kernel who is responsible for memory management, userspace can't be trusted for doing that.Mesa's Vulkan/Venus uses
CREATE_BLOBto request the host the creation and mapping into the guest of device-backed memory and shmem regions. TheCREATE_BLOBioctl doesn't update
drm_virtgpu_resource_create->size,Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
so the guest kernel (and, as a consequence, the host kernel) can't override the user's request.
I'd like Mesa's Vulkan/Venus in the guest to be able to obtain the
host
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
page size to align the size of the
CREATE_BLOBrequests as required.gfxstream solves this problem by putting the relevant information in
the
Quoted 4 lines
Quoted 4 lines
capabilities obtained from the host:
Quoted 2 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
If you want to be paranoid, you can also validate the
ResourceCreateBlob::sizeis properly host-page aligned when that request reaches the host.Quoted 2 lines
So you can probably solve this problem using current interfaces.
Whether it's cleaner for all context types to use the capabilities, or
have
Quoted 1 line
Quoted 1 line
all VMMs to expose
VIRTIO_GPU_F_HOST_PAGE_SIZE, would be thecost/benefit
Quoted 13 lines
Quoted 8 lines
tradeoff.
Quoted 1 line
I guess solving it in a context-type specific way is possible. But I think it is a relatively universal constraint. And maybe it makes sense for virtgpu guest kernel to enforce alignment (at least it can return an error synchronously) in addition to the host.
virtio-media may have support for
VIRTIO_MEDIA_CMD_MMAPtoo, so could run into this issue.https://github.com/chromeos/virtio-media?tab=readme-ov-file#shared-memory-regions
Quoted 7 lines
virtio-fs also has the DAX window which uses the same memory mapping mechanism.
https://virtio-fs.gitlab.io/design.html
Maybe this should not be a virtio-gpu thing, but a virtio thing?
This is true, but finding a common place to put the page size is really hard in practice. I don't think we can borrow space in the feature bits for that (and that would probably be abusing its purpose quite a bit) and extending the transport configuration registers is quite cumbersome and, in general, undesirable.
Quoted 7 lines
That leaves us with the device-specific config space, and that implies a device-specific feature bit as it's implemented in this series.
The Shared Memory Regions on the VIRTIO spec, while doesn't talk specifically about page size, also gives us a hint about this being the right direction:
Quoted 6 lines
Can't we just modify the Shared Memory region PCI capability to include page size? We can either:
1) keep the same size struct + header (
VIRTIO_PCI_CAP_SHARED_MEMORY_CFG), and just hijack one of the padding fields. If the padding field is zero, we can just say it's 4096.
Yes, we can turn that padding into "__le16 page_size_order" to store "PAGE_SIZE >> 12". That should be enough to secure some future-proofing. There's also some space in the "MMIO Device Register Layout" to store it as a 16 bit or 32 bit value.
This would require proposing it as a change to the VIRTIO specs. Do you want to do it yourself or should I take the initiative?
Thanks,
Sergio.
Gurchetan Singh
reviewerQuoted 131 lines · Sergio Lopez Pascual
Quoted 1 line · Gurchetan Singh
On Thu, Aug 8, 2024 at 3:38 AM Sergio Lopez Pascual <[email protected]>
Quoted 11 lines · wrote:
Quoted 11 lines
Quoted 8 lines · Gurchetan Singh
Quoted 6 lines · Rob Clark
Quoted 4 lines · Gurchetan Singh
On Mon, Aug 5, 2024 at 2:14 AM Sergio Lopez Pascual <
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines · wrote:
Quoted 5 lines
Quoted 2 lines · Dmitry Osipenko
Quoted 1 line · Sergio Lopez
There's an incresing number of machines supporting multiple
page
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
sizes
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
and on these machines the host and a guest can be running, each
one,
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
with a different page size.
For what pertains to virtio-gpu, this is not a problem if the
page
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
size
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
of the guest happens to be bigger or equal than the host, but
will
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
potentially lead to failures in memory allocations and/or
mappings
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
otherwise.
Please describe concrete problem you're trying to solve. Guest
memory
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
allocation consists of guest pages, I don't see how knowledge of
host
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
page size helps anything in userspace.
I suspect you want this for host blobs, but then it should be
virtio_gpu_vram_create()that should usemax(host_page_sz, guest_page_size), AFAICT. It's kernel who is responsible formemory
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
management, userspace can't be trusted for doing that.
Mesa's Vulkan/Venus uses
CREATE_BLOBto request the host thecreation
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
and mapping into the guest of device-backed memory and shmem
regions.
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
The
CREATE_BLOBioctl doesn't update
drm_virtgpu_resource_create->size,Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
so the guest kernel (and, as a consequence, the host kernel) can't override the user's request.
I'd like Mesa's Vulkan/Venus in the guest to be able to obtain the
host
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
page size to align the size of the
CREATE_BLOBrequests asrequired.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
gfxstream solves this problem by putting the relevant information
in
Quoted 6 lines
Quoted 6 lines
the
Quoted 4 lines
Quoted 4 lines
capabilities obtained from the host:
Quoted 2 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
If you want to be paranoid, you can also validate the
ResourceCreateBlob::sizeis properly host-page aligned when thatrequest
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
reaches the host.
Quoted 2 lines
So you can probably solve this problem using current interfaces.
Whether it's cleaner for all context types to use the capabilities,
or
Quoted 6 lines
Quoted 6 lines
have
Quoted 1 line
Quoted 1 line
all VMMs to expose
VIRTIO_GPU_F_HOST_PAGE_SIZE, would be thecost/benefit
Quoted 3 lines
Quoted 3 lines
tradeoff.
Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
I guess solving it in a context-type specific way is possible. But I think it is a relatively universal constraint. And maybe it makes sense for virtgpu guest kernel to enforce alignment (at least it can return an error synchronously) in addition to the host.
virtio-media may have support for
VIRTIO_MEDIA_CMD_MMAPtoo, so couldrun
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
into this issue.
https://github.com/chromeos/virtio-media?tab=readme-ov-file#shared-memory-regions
Quoted 22 lines
Quoted 14 lines
Quoted 7 lines
virtio-fs also has the DAX window which uses the same memory mapping mechanism.
https://virtio-fs.gitlab.io/design.html
Maybe this should not be a virtio-gpu thing, but a virtio thing?
This is true, but finding a common place to put the page size is really hard in practice. I don't think we can borrow space in the feature bits for that (and that would probably be abusing its purpose quite a bit) and extending the transport configuration registers is quite cumbersome and, in general, undesirable.
Quoted 7 lines
That leaves us with the device-specific config space, and that implies a device-specific feature bit as it's implemented in this series.
The Shared Memory Regions on the VIRTIO spec, while doesn't talk specifically about page size, also gives us a hint about this being the right direction:
Quoted 5 lines
Can't we just modify the Shared Memory region PCI capability to include page size? We can either:
1) keep the same size struct + header (
VIRTIO_PCI_CAP_SHARED_MEMORY_CFG), and just hijack one of the padding fields. If the padding field is zero,we
Quoted 1 line
can just say it's 4096.
Quoted 8 lines
Yes, we can turn that padding into "
__le16page_size_order" to store "PAGE_SIZE>> 12". That should be enough to secure some future-proofing. There's also some space in the "MMIO Device Register Layout" to store it as a 16 bit or 32 bit value.This would require proposing it as a change to the VIRTIO specs. Do you want to do it yourself or should I take the initiative?
You should do it.
Quoted 5 lines
Thanks,
Sergio.
Quoted 68 lines · Gurchetan Singh
Quoted 57 lines · Rob Clark
Quoted 4 lines · Gurchetan Singh
On Mon, Aug 5, 2024 at 2:14 AM Sergio Lopez Pascual <[email protected]>
Quoted 5 lines · wrote:
Quoted 5 lines
Quoted 2 lines · Dmitry Osipenko
Quoted 1 line · Sergio Lopez
There's an incresing number of machines supporting multiple page
sizes
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
and on these machines the host and a guest can be running, each one, with a different page size.
For what pertains to virtio-gpu, this is not a problem if the page
size
Quoted 19 lines
Quoted 19 lines
Quoted 4 lines
Quoted 3 lines
of the guest happens to be bigger or equal than the host, but will potentially lead to failures in memory allocations and/or mappings otherwise.
Quoted 8 lines
Please describe concrete problem you're trying to solve. Guest memory allocation consists of guest pages, I don't see how knowledge of host page size helps anything in userspace.
I suspect you want this for host blobs, but then it should be
virtio_gpu_vram_create()that should usemax(host_page_sz, guest_page_size), AFAICT. It's kernel who is responsible for memory management, userspace can't be trusted for doing that.Mesa's Vulkan/Venus uses
CREATE_BLOBto request the host the creation and mapping into the guest of device-backed memory and shmem regions. TheCREATE_BLOBioctl doesn't updatedrm_virtgpu_resource_create->size, so the guest kernel (and, as a consequence, the host kernel) can't override the user's request.Quoted 5 lines
Quoted 2 lines
I'd like Mesa's Vulkan/Venus in the guest to be able to obtain the host page size to align the size of the
CREATE_BLOBrequests as required.gfxstream solves this problem by putting the relevant information in the
capabilities obtained from the host:
Quoted 2 lines
Quoted 2 lines
If you want to be paranoid, you can also validate the
ResourceCreateBlob::sizeis properly host-page aligned when that request reaches the host.Quoted 2 lines
So you can probably solve this problem using current interfaces.
Whether it's cleaner for all context types to use the capabilities, or have all VMMs to expose
VIRTIO_GPU_F_HOST_PAGE_SIZE, would be the cost/benefit tradeoff.Quoted 1 line
Quoted 5 lines
I guess solving it in a context-type specific way is possible. But I think it is a relatively universal constraint. And maybe it makes sense for virtgpu guest kernel to enforce alignment (at least it can return an error synchronously) in addition to the host.
virtio-media may have support for
VIRTIO_MEDIA_CMD_MMAPtoo, so could run into this issue.
Quoted 8 lines
https://github.com/chromeos/virtio-media?tab=readme-ov-file#shared-memory-regions
virtio-fs also has the DAX window which uses the same memory mapping mechanism.
https://virtio-fs.gitlab.io/design.html
Maybe this should not be a virtio-gpu thing, but a virtio thing?
There seem to be certain consensus that the information about alignment restrictions must be shared in a device-specific way:
There's also the precedent of virtio-fs already sharing the alignment restrictions through FUSE_INIT (from VIRTIO SPECS 1.3, section 5.11.6.4).
---
The driver maps a file range into the DAX window using the FUSE_SETUPMAPPING request. Alignment
constraints for FUSE_SETUPMAPPING and FUSE_REMOVEMAPPING requests are communicated dur-
ing FUSE_INIT negotiation.
---
Given this information, I'm going to rebase and respin this series.
Thanks,
Sergio.