* [RFC PATCH v3 0/4] virtio: obtain SHM page size from device
@ 2025-02-20 14:28 Sergio Lopez
2025-02-20 14:28 ` [PATCH RFC v3 1/4] virtio: introduce VIRTIO_F_SHM_PAGE_SIZE Sergio Lopez
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Sergio Lopez @ 2025-02-20 14:28 UTC (permalink / raw)
To: Michael S. Tsirkin, Daniel Verkamp, Jason Wang, Xuan Zhuo,
Eugenio Pérez, David Airlie, Gerd Hoffmann, Gurchetan Singh,
Chia-I Wu, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
Simona Vetter, Rob Clark, Dmitry Osipenko, fnkl.kernel
Cc: virtualization, linux-kernel, dri-devel, 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 with
different pages sizes.
In addition to this, there might be devices that have a required and/or
preferred page size for mapping memory.
In this series, we extend virtio_shm_region with a field to hold the
page size. The PCI and MMIO transports are updated to read the page
shift for each region and derive the page size accordingly. For the PCI
transport we're borrowing 8 bits from the 16 bit padding, so the
transition is seamless. But for MMIO we need to access a new register,
which could potentially be interpreted by the VMM as an error. For this
reason we're gating this behavior, for every transport, behind the
VIRTIO_F_SHM_PAGE_SIZE feature bit.
How the SHM page size information is used depends on each device. Some
may silently round up allocations, some may expose this information to
userspace. This series includes a patch that extends virtio-gpu to
expose the information via the VIRTGPU_GETPARAM ioctl, as an example of
the second approach.
This patch series is an RFC because it requires changes to the VIRTIO
specifications. This patch series will be used as a reference to
propose such changes.
Signed-off-by: Sergio Lopez <slp@redhat.com>
---
Changes in v3:
- Merge patch 2 (virtio: introduce VIRTIO_F_SHM_PAGE_SIZE) into the
changes for virtio-pci (thanks Dmitry Osipenko).
- In virtio_gpu_getparam_ioctl(), return ENOENT instead of EINVAL
if the device lacks a host visible region (thanks Dmitry Osipenko).
- Link to v2: https://lore.kernel.org/r/20250214-virtio-shm-page-size-v2-0-aa1619e6908b@redhat.com
Changes in v2:
- Use "page_shift" instead of "page_size" in the transport-related
structures to clarify its contents (thanks Daniel Verkamp).
- Update the command for "page_shift" in "virtio_pci_cap" to clarify
that it's only relevant for VIRTIO_PCI_CAP_SHARED_MEMORY_CFG regions.
(thanks Daniel Verkamp).
- Instead of a derived value, store page size in virtio_shm_region.
- Update the cover page to reflect that the functionality is gated
behind the VIRTIO_F_SHM_PAGE_SIZE feature bit.
- Link to v1: https://lore.kernel.org/r/20250213-virtio-shm-page-size-v1-0-5ee1f9984350@redhat.com
---
Sergio Lopez (4):
virtio: introduce VIRTIO_F_SHM_PAGE_SIZE
virtio-pci: extend virtio_pci_cap with page_shift
virtio-mmio: read shm region page size
drm/virtio: add VIRTGPU_PARAM_HOST_SHM_PAGE_SIZE to params
drivers/gpu/drm/virtio/virtgpu_ioctl.c | 5 +++++
drivers/virtio/virtio_mmio.c | 11 +++++++++++
drivers/virtio/virtio_pci_modern.c | 24 ++++++++++++++++++++----
drivers/virtio/virtio_ring.c | 2 ++
include/linux/virtio_config.h | 1 +
include/uapi/drm/virtgpu_drm.h | 1 +
include/uapi/linux/virtio_config.h | 7 ++++++-
include/uapi/linux/virtio_mmio.h | 3 +++
include/uapi/linux/virtio_pci.h | 3 ++-
9 files changed, 51 insertions(+), 6 deletions(-)
---
base-commit: 4dc1d1bec89864d8076e5ab314f86f46442bfb02
change-id: 20250213-virtio-shm-page-size-6e9a08c7ded1
Best regards,
--
Sergio Lopez <slp@redhat.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH RFC v3 1/4] virtio: introduce VIRTIO_F_SHM_PAGE_SIZE
2025-02-20 14:28 [RFC PATCH v3 0/4] virtio: obtain SHM page size from device Sergio Lopez
@ 2025-02-20 14:28 ` Sergio Lopez
2025-02-20 14:28 ` [PATCH RFC v3 2/4] virtio-pci: extend virtio_pci_cap with page_shift Sergio Lopez
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Sergio Lopez @ 2025-02-20 14:28 UTC (permalink / raw)
To: Michael S. Tsirkin, Daniel Verkamp, Jason Wang, Xuan Zhuo,
Eugenio Pérez, David Airlie, Gerd Hoffmann, Gurchetan Singh,
Chia-I Wu, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
Simona Vetter, Rob Clark, Dmitry Osipenko, fnkl.kernel
Cc: virtualization, linux-kernel, dri-devel, Sergio Lopez
Introduce VIRTIO_F_SHM_PAGE_SIZE, a feature bit which indicates that the
transport provides the page size for SHM regions.
Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Sergio Lopez <slp@redhat.com>
---
drivers/virtio/virtio_pci_modern.c | 3 +++
drivers/virtio/virtio_ring.c | 2 ++
include/uapi/linux/virtio_config.h | 7 ++++++-
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c
index 5eaade7578606e4b02af0d66447417ad6aa11064..104ba08f82d4a6268240bbad15385dd44b3a71d6 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -367,6 +367,9 @@ static void vp_transport_features(struct virtio_device *vdev, u64 features)
if (features & BIT_ULL(VIRTIO_F_ADMIN_VQ))
__virtio_set_bit(vdev, VIRTIO_F_ADMIN_VQ);
+
+ if (features & BIT_ULL(VIRTIO_F_SHM_PAGE_SIZE))
+ __virtio_set_bit(vdev, VIRTIO_F_SHM_PAGE_SIZE);
}
static int __vp_check_common_size_one_feature(struct virtio_device *vdev, u32 fbit,
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index fdd2d2b07b5a2aca864bc917306536685afb66a6..d853d5cf7e553be8bbe0ff461dc7312b258c6e58 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -2983,6 +2983,8 @@ void vring_transport_features(struct virtio_device *vdev)
break;
case VIRTIO_F_NOTIFICATION_DATA:
break;
+ case VIRTIO_F_SHM_PAGE_SIZE:
+ break;
default:
/* We don't understand this bit. */
__virtio_clear_bit(vdev, i);
diff --git a/include/uapi/linux/virtio_config.h b/include/uapi/linux/virtio_config.h
index 2445f365bce74b4e926c6929322b269252ab6830..3171e3792263c2cd472ac09da18e593ab400751d 100644
--- a/include/uapi/linux/virtio_config.h
+++ b/include/uapi/linux/virtio_config.h
@@ -52,7 +52,7 @@
* rest are per-device feature bits.
*/
#define VIRTIO_TRANSPORT_F_START 28
-#define VIRTIO_TRANSPORT_F_END 42
+#define VIRTIO_TRANSPORT_F_END 43
#ifndef VIRTIO_CONFIG_NO_LEGACY
/* Do we get callbacks when the ring is completely used, even if we've
@@ -120,4 +120,9 @@
*/
#define VIRTIO_F_ADMIN_VQ 41
+/*
+ * This feature indicates that the transport provides the SHM page size.
+ */
+#define VIRTIO_F_SHM_PAGE_SIZE 42
+
#endif /* _UAPI_LINUX_VIRTIO_CONFIG_H */
--
2.48.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH RFC v3 2/4] virtio-pci: extend virtio_pci_cap with page_shift
2025-02-20 14:28 [RFC PATCH v3 0/4] virtio: obtain SHM page size from device Sergio Lopez
2025-02-20 14:28 ` [PATCH RFC v3 1/4] virtio: introduce VIRTIO_F_SHM_PAGE_SIZE Sergio Lopez
@ 2025-02-20 14:28 ` Sergio Lopez
2025-02-20 19:19 ` Daniel Verkamp
2025-02-20 14:28 ` [PATCH RFC v3 3/4] virtio-mmio: read shm region page size Sergio Lopez
2025-02-20 14:28 ` [PATCH RFC v3 4/4] drm/virtio: add VIRTGPU_PARAM_HOST_SHM_PAGE_SIZE to params Sergio Lopez
3 siblings, 1 reply; 7+ messages in thread
From: Sergio Lopez @ 2025-02-20 14:28 UTC (permalink / raw)
To: Michael S. Tsirkin, Daniel Verkamp, Jason Wang, Xuan Zhuo,
Eugenio Pérez, David Airlie, Gerd Hoffmann, Gurchetan Singh,
Chia-I Wu, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
Simona Vetter, Rob Clark, Dmitry Osipenko, fnkl.kernel
Cc: virtualization, linux-kernel, dri-devel, Sergio Lopez
If VIRTIO_F_SHM_PAGE_SIZE has been negotiated and cfg_type is
VIRTIO_PCI_CAP_SHARED_MEMORY_CFG, the driver must read the page_shift
field, derive the supported page size from it, and honor it when
requesting the map of memory into the shared memory region to the
device.
Extend virtio_pci_cap to hold that field, and use it to feed
virtio_shm_region with the corresponding page size.
Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Sergio Lopez <slp@redhat.com>
---
drivers/virtio/virtio_mmio.c | 2 ++
drivers/virtio/virtio_pci_modern.c | 21 +++++++++++++++++----
include/linux/virtio_config.h | 1 +
include/uapi/linux/virtio_pci.h | 3 ++-
4 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index 5d78c2d572abfcfe2b84cdd82df622320fe97d5d..1f594b626d7a7734e8ec58766737a118c26bad94 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -560,6 +560,8 @@ static bool vm_get_shm_region(struct virtio_device *vdev,
region->addr = addr;
+ region->page_size = 4096;
+
return true;
}
diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c
index 104ba08f82d4a6268240bbad15385dd44b3a71d6..562a8e1c2bfe6876cffabe26f02cd61ad7fea2cd 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -770,14 +770,15 @@ static void del_vq(struct virtio_pci_vq_info *info)
vring_del_virtqueue(vq);
}
-static int virtio_pci_find_shm_cap(struct pci_dev *dev, u8 required_id,
- u8 *bar, u64 *offset, u64 *len)
+static int virtio_pci_find_shm_cap(struct virtio_device *vdev, struct pci_dev *dev,
+ u8 required_id, u8 *bar, u64 *offset, u64 *len,
+ u32 *page_size)
{
int pos;
for (pos = pci_find_capability(dev, PCI_CAP_ID_VNDR); pos > 0;
pos = pci_find_next_capability(dev, pos, PCI_CAP_ID_VNDR)) {
- u8 type, cap_len, id, res_bar;
+ u8 type, cap_len, id, res_bar, page_shift = 0;
u32 tmp32;
u64 res_offset, res_length;
@@ -808,6 +809,15 @@ static int virtio_pci_find_shm_cap(struct pci_dev *dev, u8 required_id,
* Looks good.
*/
+ /* Read the page shift if supported. The page_shift variable is
+ * initialized to zero above, so if this feature isn't supported it
+ * will result in a page_size of 4096, a default safe value.
+ */
+ if (__virtio_test_bit(vdev, VIRTIO_F_SHM_PAGE_SIZE)) {
+ pci_read_config_byte(dev, pos + offsetof(struct virtio_pci_cap,
+ page_shift), &page_shift);
+ }
+
/* Read the lower 32bit of length and offset */
pci_read_config_dword(dev, pos + offsetof(struct virtio_pci_cap,
offset), &tmp32);
@@ -829,6 +839,7 @@ static int virtio_pci_find_shm_cap(struct pci_dev *dev, u8 required_id,
*bar = res_bar;
*offset = res_offset;
*len = res_length;
+ *page_size = 1 << (page_shift + 12);
return pos;
}
@@ -841,11 +852,12 @@ static bool vp_get_shm_region(struct virtio_device *vdev,
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
struct pci_dev *pci_dev = vp_dev->pci_dev;
u8 bar;
+ u32 page_size;
u64 offset, len;
phys_addr_t phys_addr;
size_t bar_len;
- if (!virtio_pci_find_shm_cap(pci_dev, id, &bar, &offset, &len))
+ if (!virtio_pci_find_shm_cap(vdev, pci_dev, id, &bar, &offset, &len, &page_size))
return false;
phys_addr = pci_resource_start(pci_dev, bar);
@@ -865,6 +877,7 @@ static bool vp_get_shm_region(struct virtio_device *vdev,
region->len = len;
region->addr = (u64) phys_addr + offset;
+ region->page_size = page_size;
return true;
}
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index 169c7d367facb36dcabf9596068580ea8b8516c7..c1b2ce71ea55e81978e18db05494deab193fa4fb 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -14,6 +14,7 @@ struct irq_affinity;
struct virtio_shm_region {
u64 addr;
u64 len;
+ u32 page_size;
};
typedef void vq_callback_t(struct virtqueue *);
diff --git a/include/uapi/linux/virtio_pci.h b/include/uapi/linux/virtio_pci.h
index 8549d4571257142ac6c9dad5c01369923791a85a..1a76df52b4eccf548df78a8ee7d3a04591f55522 100644
--- a/include/uapi/linux/virtio_pci.h
+++ b/include/uapi/linux/virtio_pci.h
@@ -127,7 +127,8 @@ struct virtio_pci_cap {
__u8 cfg_type; /* Identifies the structure. */
__u8 bar; /* Where to find it. */
__u8 id; /* Multiple capabilities of the same type */
- __u8 padding[2]; /* Pad to full dword. */
+ __u8 page_shift; /* Page shift for VIRTIO_PCI_CAP_SHARED_MEMORY_CFG. */
+ __u8 padding[1]; /* Pad to full dword. */
__le32 offset; /* Offset within bar. */
__le32 length; /* Length of the structure, in bytes. */
};
--
2.48.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH RFC v3 3/4] virtio-mmio: read shm region page size
2025-02-20 14:28 [RFC PATCH v3 0/4] virtio: obtain SHM page size from device Sergio Lopez
2025-02-20 14:28 ` [PATCH RFC v3 1/4] virtio: introduce VIRTIO_F_SHM_PAGE_SIZE Sergio Lopez
2025-02-20 14:28 ` [PATCH RFC v3 2/4] virtio-pci: extend virtio_pci_cap with page_shift Sergio Lopez
@ 2025-02-20 14:28 ` Sergio Lopez
2025-02-20 14:28 ` [PATCH RFC v3 4/4] drm/virtio: add VIRTGPU_PARAM_HOST_SHM_PAGE_SIZE to params Sergio Lopez
3 siblings, 0 replies; 7+ messages in thread
From: Sergio Lopez @ 2025-02-20 14:28 UTC (permalink / raw)
To: Michael S. Tsirkin, Daniel Verkamp, Jason Wang, Xuan Zhuo,
Eugenio Pérez, David Airlie, Gerd Hoffmann, Gurchetan Singh,
Chia-I Wu, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
Simona Vetter, Rob Clark, Dmitry Osipenko, fnkl.kernel
Cc: virtualization, linux-kernel, dri-devel, Sergio Lopez
Use the newly introduced SHM_PAGE_SHIFT register to read the page shift
for the shared memory region, derive the page size from it and store the
resulting value into virtio_shm_region.
Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Sergio Lopez <slp@redhat.com>
---
drivers/virtio/virtio_mmio.c | 11 ++++++++++-
include/uapi/linux/virtio_mmio.h | 3 +++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index 1f594b626d7a7734e8ec58766737a118c26bad94..0f892770739ea84b3e7be5615332773049b10ab1 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -537,6 +537,7 @@ static bool vm_get_shm_region(struct virtio_device *vdev,
struct virtio_shm_region *region, u8 id)
{
struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
+ u8 page_shift = 0;
u64 len, addr;
/* Select the region we're interested in */
@@ -560,7 +561,15 @@ static bool vm_get_shm_region(struct virtio_device *vdev,
region->addr = addr;
- region->page_size = 4096;
+ /* If supported by the device transport, read the region page size.
+ * The page_shift variable is initialized to zero above, so if this
+ * feature isn't supported it will result in a page_size of 4096, a
+ * default safe value.
+ */
+ if (__virtio_test_bit(vdev, VIRTIO_F_SHM_PAGE_SIZE))
+ page_shift = (u8) readl(vm_dev->base + VIRTIO_MMIO_SHM_PAGE_SHIFT);
+
+ region->page_size = 1 << (page_shift + 12);
return true;
}
diff --git a/include/uapi/linux/virtio_mmio.h b/include/uapi/linux/virtio_mmio.h
index 0650f91bea6c70f935764070d825d181a2379afb..43348be30eff90ee228b6490b9d3c35ba4c50aa5 100644
--- a/include/uapi/linux/virtio_mmio.h
+++ b/include/uapi/linux/virtio_mmio.h
@@ -133,6 +133,9 @@
#define VIRTIO_MMIO_SHM_BASE_LOW 0x0b8
#define VIRTIO_MMIO_SHM_BASE_HIGH 0x0bc
+/* Shared memory region page shift */
+#define VIRTIO_MMIO_SHM_PAGE_SHIFT 0x0c4
+
/* Configuration atomicity value */
#define VIRTIO_MMIO_CONFIG_GENERATION 0x0fc
--
2.48.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH RFC v3 4/4] drm/virtio: add VIRTGPU_PARAM_HOST_SHM_PAGE_SIZE to params
2025-02-20 14:28 [RFC PATCH v3 0/4] virtio: obtain SHM page size from device Sergio Lopez
` (2 preceding siblings ...)
2025-02-20 14:28 ` [PATCH RFC v3 3/4] virtio-mmio: read shm region page size Sergio Lopez
@ 2025-02-20 14:28 ` Sergio Lopez
2025-02-20 15:21 ` Dmitry Osipenko
3 siblings, 1 reply; 7+ messages in thread
From: Sergio Lopez @ 2025-02-20 14:28 UTC (permalink / raw)
To: Michael S. Tsirkin, Daniel Verkamp, Jason Wang, Xuan Zhuo,
Eugenio Pérez, David Airlie, Gerd Hoffmann, Gurchetan Singh,
Chia-I Wu, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
Simona Vetter, Rob Clark, Dmitry Osipenko, fnkl.kernel
Cc: virtualization, linux-kernel, dri-devel, Sergio Lopez
Add VIRTGPU_PARAM_HOST_SHM_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.
Signed-off-by: Sergio Lopez <slp@redhat.com>
---
drivers/gpu/drm/virtio/virtgpu_ioctl.c | 5 +++++
include/uapi/drm/virtgpu_drm.h | 1 +
2 files changed, 6 insertions(+)
diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
index c33c057365f85a2ace536f91655c903036827312..f112b862c2de4d021fb6a54a080f42ad75034227 100644
--- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c
+++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
@@ -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_SHM_PAGE_SIZE:
+ if (!vgdev->has_host_visible)
+ return -ENOENT;
+ value = vgdev->host_visible_region.page_size;
+ break;
default:
return -EINVAL;
}
diff --git a/include/uapi/drm/virtgpu_drm.h b/include/uapi/drm/virtgpu_drm.h
index c2ce71987e9bb816d13a300679336cb756f1cbcf..72db6b3339e0dcaf550acbf5ac4381a6e5c2216d 100644
--- a/include/uapi/drm/virtgpu_drm.h
+++ b/include/uapi/drm/virtgpu_drm.h
@@ -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_SHM_PAGE_SIZE 9 /* Host SHM page size, with format PAGE_SIZE >> 12 */
struct drm_virtgpu_getparam {
__u64 param;
--
2.48.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH RFC v3 4/4] drm/virtio: add VIRTGPU_PARAM_HOST_SHM_PAGE_SIZE to params
2025-02-20 14:28 ` [PATCH RFC v3 4/4] drm/virtio: add VIRTGPU_PARAM_HOST_SHM_PAGE_SIZE to params Sergio Lopez
@ 2025-02-20 15:21 ` Dmitry Osipenko
0 siblings, 0 replies; 7+ messages in thread
From: Dmitry Osipenko @ 2025-02-20 15:21 UTC (permalink / raw)
To: Sergio Lopez, Michael S. Tsirkin, Daniel Verkamp, Jason Wang,
Xuan Zhuo, Eugenio Pérez, David Airlie, Gerd Hoffmann,
Gurchetan Singh, Chia-I Wu, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, Simona Vetter, Rob Clark, fnkl.kernel
Cc: virtualization, linux-kernel, dri-devel
On 2/20/25 17:28, Sergio Lopez wrote:
> Add VIRTGPU_PARAM_HOST_SHM_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.
>
> Signed-off-by: Sergio Lopez <slp@redhat.com>
> ---
> drivers/gpu/drm/virtio/virtgpu_ioctl.c | 5 +++++
> include/uapi/drm/virtgpu_drm.h | 1 +
> 2 files changed, 6 insertions(+)
>
> diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> index c33c057365f85a2ace536f91655c903036827312..f112b862c2de4d021fb6a54a080f42ad75034227 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> @@ -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_SHM_PAGE_SIZE:
> + if (!vgdev->has_host_visible)
> + return -ENOENT;
> + value = vgdev->host_visible_region.page_size;
> + break;
> default:
> return -EINVAL;
> }
> diff --git a/include/uapi/drm/virtgpu_drm.h b/include/uapi/drm/virtgpu_drm.h
> index c2ce71987e9bb816d13a300679336cb756f1cbcf..72db6b3339e0dcaf550acbf5ac4381a6e5c2216d 100644
> --- a/include/uapi/drm/virtgpu_drm.h
> +++ b/include/uapi/drm/virtgpu_drm.h
> @@ -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_SHM_PAGE_SIZE 9 /* Host SHM page size, with format PAGE_SIZE >> 12 */
>
> struct drm_virtgpu_getparam {
> __u64 param;
>
Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
--
Best regards,
Dmitry
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH RFC v3 2/4] virtio-pci: extend virtio_pci_cap with page_shift
2025-02-20 14:28 ` [PATCH RFC v3 2/4] virtio-pci: extend virtio_pci_cap with page_shift Sergio Lopez
@ 2025-02-20 19:19 ` Daniel Verkamp
0 siblings, 0 replies; 7+ messages in thread
From: Daniel Verkamp @ 2025-02-20 19:19 UTC (permalink / raw)
To: Sergio Lopez
Cc: Michael S. Tsirkin, Jason Wang, Xuan Zhuo, Eugenio Pérez,
David Airlie, Gerd Hoffmann, Gurchetan Singh, Chia-I Wu,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
Simona Vetter, Rob Clark, Dmitry Osipenko, fnkl.kernel,
virtualization, linux-kernel, dri-devel
On Thu, Feb 20, 2025 at 6:30 AM Sergio Lopez <slp@redhat.com> wrote:
[...]
> @@ -829,6 +839,7 @@ static int virtio_pci_find_shm_cap(struct pci_dev *dev, u8 required_id,
> *bar = res_bar;
> *offset = res_offset;
> *len = res_length;
> + *page_size = 1 << (page_shift + 12);
Maybe this should validate that page_shift is in range to avoid any
funny business from the device; since page_size is u32, this needs
page_shift + 12 < 32. (If it's out of range, I am not sure what this
should do; maybe just warn and set it to the default 4096?)
Also shifting into the sign bit is technically undefined (or
implementation-defined? I don't recall) behavior, so perhaps make the
constant unsigned, e.g. `1U << (page_shift + 12)`.
Other than that, looks reasonable to me:
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Thanks,
-- Daniel
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-02-20 19:20 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-20 14:28 [RFC PATCH v3 0/4] virtio: obtain SHM page size from device Sergio Lopez
2025-02-20 14:28 ` [PATCH RFC v3 1/4] virtio: introduce VIRTIO_F_SHM_PAGE_SIZE Sergio Lopez
2025-02-20 14:28 ` [PATCH RFC v3 2/4] virtio-pci: extend virtio_pci_cap with page_shift Sergio Lopez
2025-02-20 19:19 ` Daniel Verkamp
2025-02-20 14:28 ` [PATCH RFC v3 3/4] virtio-mmio: read shm region page size Sergio Lopez
2025-02-20 14:28 ` [PATCH RFC v3 4/4] drm/virtio: add VIRTGPU_PARAM_HOST_SHM_PAGE_SIZE to params Sergio Lopez
2025-02-20 15:21 ` Dmitry Osipenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®