[PATCH 1/2] drm/imagination: clamp stride of heaps and static areas for legacy UM

From: Luigi Santivetti

Date: Wed Nov 04 2026 - 13:17:21 EST


Userspace before 4c18bbc6 in [1] failed to set the stride when doing the
DRM_PVR_DEV_QUERY_HEAP_INFO_GET and DRM_PVR_DEV_QUERY_STATIC_DATA_AREAS_GET
query ioctl calls. This isn't a problem as long as the kernel and userspace
use the same version of struct drm_pvr_heap and of drm_pvr_static_data_area
and at present this is the case. However, nothing prevents it to change in
the future, allowing userspace and kernel to run with a different version
of either of those structures.

In order to protect userspace before 4c18bbc6, change those ioctl calls now
future proofing the value of the stride that is returned by the kernel.
This means to take a snapshot of the size of struct drm_pvr_heap and of
drm_pvr_static_data_area as of today and return it to old UMDs. Since the
size has never changed so far, we may refer to this size in docs, code and
comments as version 1, first released version, legacy or minimum supported
version of the stride.

In order to be safe for userspace, make use of the following properties
that hold in UM code before 4c18bbc6:

1. for both DRM_PVR_DEV_QUERY_{HEAP_INFO,STATIC_DATA_AREAS}_GET, it makes
two ioctl calls
2. it never sets struct drm_pvr_obj_array::stride in either ioctl calls
3. it assumes the stride from the kernel to match the stride of userspace

In the second ioctl call the value of the stride is set to what the kernel
had set it to in the first. Therefore, special case what is returned to UM
in the first call, so that the value of the stride matches with the one
userspace uses before 4c18bbc6.

Although backwards compatible, this commit alters the semantics of how to
retrieve the non-legacy or maximum supported stride going forward. The new
pattern for interacting with the kernel is documented in the UAPI header.

[1] https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/44456

Signed-off-by: Luigi Santivetti <luigi.santivetti@xxxxxxxxxx>
---
drivers/gpu/drm/imagination/pvr_drv.h | 21 +++++++++++++++++++++
drivers/gpu/drm/imagination/pvr_vm.c | 14 ++++++++++++--
include/uapi/drm/pvr_drm.h | 33 +++++++++++++++++++++++++++------
3 files changed, 60 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/imagination/pvr_drv.h b/drivers/gpu/drm/imagination/pvr_drv.h
index 7fa147312dd1..b9e0146c90b1 100644
--- a/drivers/gpu/drm/imagination/pvr_drv.h
+++ b/drivers/gpu/drm/imagination/pvr_drv.h
@@ -70,6 +70,27 @@ int pvr_set_uobj_array(const struct drm_pvr_obj_array *out, u32 min_stride, u32
PVR_UOBJ_DECL(struct drm_pvr_dev_query_static_data_areas, static_data_areas) \
)

+/*
+ * Minimum supported values that are fetched by DRM_PVR_DEV_QUERY_HEAP_INFO_GET
+ * and DRM_PVR_DEV_QUERY_STATIC_DATA_AREAS_GET ioctl calls from userspace.
+ *
+ * These values may depend on the GPU hardware and they must not change for
+ * cores that are already supported. However, new cores (and architectures)
+ * may have different minimum values and they should be introduced
+ * respecting the semantics described in the UAPI for Rogue.
+ */
+
+/* Size of the first released version of struct drm_pvr_heap for Rogue cores. */
+#define DRM_PVR_HEAP_STRIDE_MIN_SUPPORTED \
+ PVR_UOBJ_MIN_SIZE_INTERNAL(struct drm_pvr_heap, page_size_log2)
+
+/*
+ * Size of the first released version of struct drm_pvr_static_data_area for
+ * Rogue cores.
+ */
+#define DRM_PVR_STATIC_DATA_AREA_STRIDE_MIN_SUPPORTED \
+ PVR_UOBJ_MIN_SIZE_INTERNAL(struct drm_pvr_static_data_area, offset)
+
/**
* PVR_UOBJ_GET() - Copies from _src_usr_ptr to &_dest_obj.
* @_dest_obj: The destination container object in kernel space.
diff --git a/drivers/gpu/drm/imagination/pvr_vm.c b/drivers/gpu/drm/imagination/pvr_vm.c
index 304d0743c5aa..a369d73c6969 100644
--- a/drivers/gpu/drm/imagination/pvr_vm.c
+++ b/drivers/gpu/drm/imagination/pvr_vm.c
@@ -984,8 +984,14 @@ pvr_static_data_areas_get(const struct pvr_device *pvr_dev,
return err;

if (!query.static_data_areas.array) {
+ u32 *stride = &query.static_data_areas.stride;
+
+ if (!query.static_data_areas.stride)
+ *stride = DRM_PVR_STATIC_DATA_AREA_STRIDE_MIN_SUPPORTED;
+ else
+ *stride = sizeof(struct drm_pvr_static_data_area);
+
query.static_data_areas.count = ARRAY_SIZE(static_data_areas);
- query.static_data_areas.stride = sizeof(struct drm_pvr_static_data_area);
goto copy_out;
}

@@ -1024,8 +1030,12 @@ pvr_heap_info_get(const struct pvr_device *pvr_dev,
return err;

if (!query.heaps.array) {
+ if (!query.heaps.stride)
+ query.heaps.stride = DRM_PVR_HEAP_STRIDE_MIN_SUPPORTED;
+ else
+ query.heaps.stride = sizeof(struct drm_pvr_heap);
+
query.heaps.count = ARRAY_SIZE(pvr_heaps);
- query.heaps.stride = sizeof(struct drm_pvr_heap);
goto copy_out;
}

diff --git a/include/uapi/drm/pvr_drm.h b/include/uapi/drm/pvr_drm.h
index ccf6c2112468..fd7cf9e230c3 100644
--- a/include/uapi/drm/pvr_drm.h
+++ b/include/uapi/drm/pvr_drm.h
@@ -319,9 +319,19 @@ struct drm_pvr_heap {
*/
struct drm_pvr_dev_query_heap_info {
/**
- * @heaps: Array of &struct drm_pvr_heap. If pointer is NULL, the count
- * and stride will be updated with those known to the driver version, to
- * facilitate allocation by the caller.
+ * @heaps: Array of &struct drm_pvr_heap. To facilitate allocation by
+ * the caller:
+ *
+ * - if &heaps.array is NULL, the count will be updated with the count
+ * of heaps known to the kernel driver.
+ *
+ * - If &heaps.array is NULL and &heaps.stride is set by the caller, the
+ * stride will be updated to the size of &struct drm_pvr_heap known to
+ * the kernel driver.
+ *
+ * - If &heaps.array is NULL and &heaps.stride is zero, the stride will
+ * be updated with a value that is the minimum supported by the kernel
+ * and this may differ based on the GPU ID.
*/
struct drm_pvr_obj_array heaps;
};
@@ -427,9 +437,20 @@ struct drm_pvr_static_data_area {
*/
struct drm_pvr_dev_query_static_data_areas {
/**
- * @static_data_areas: Array of &struct drm_pvr_static_data_area. If
- * pointer is NULL, the count and stride will be updated with those
- * known to the driver version, to facilitate allocation by the caller.
+ * @static_data_areas: Array of &struct drm_pvr_static_data_area. To
+ * facilitate allocation by the caller:
+ *
+ * - if &static_data_areas.array is NULL, the count will be updated with
+ * the count of static areas known to the kernel driver.
+ *
+ * - If &static_data_areas.array is NULL and &static_data_areas.stride
+ * is set by the caller, the stride will be updated to the size of
+ * &struct drm_pvr_static_data_area known to the kernel driver.
+ *
+ * - If &static_data_areas.array is NULL and &static_data_areas.stride
+ * is zero, the stride will be updated with a value that is the
+ * minimum supported by the kernel and this may differ based on the
+ * GPU ID.
*/
struct drm_pvr_obj_array static_data_areas;
};

--
2.43.0