[igt-dev] [PATCH i-g-t] lib/i915: Return false in gem_has_lmem for kernels not having DRM_I915_QUERY_MEMORY_REGIONS support

Vidya Srinivas vidya.srinivas at intel.com
Mon Jul 26 06:06:30 UTC 2021


Starting commit (tests/kms: Create buffer object from LMEM for discrete)
it checks for LMEM. This is breaking older kernels like 5.4 without
DRM_I915_QUERY_MEMORY_REGIONS support.

Kernel writes length back to userspace if ret and
length differ, indicating an error condition. In this case, the length
written back is -22 which is EINVAL. Patch checks negative item length
and returns false from gem_has_lmem.

Credits-to: Ashutosh Dixit <ashutosh.dixit at intel.com>
Signed-off-by: Lin Charlton <charlton.lin at intel.com>
Signed-off-by: Vidya Srinivas <vidya.srinivas at intel.com>
Change-Id: Ia404b77fbe4c1fc22ca462a15f26640f9ffa4120
---
 lib/i915/intel_memory_region.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lib/i915/intel_memory_region.c b/lib/i915/intel_memory_region.c
index 144ae12ca7a0..8db3e69e9913 100644
--- a/lib/i915/intel_memory_region.c
+++ b/lib/i915/intel_memory_region.c
@@ -164,6 +164,15 @@ uint8_t gem_get_lmem_region_count(int fd)
  */
 bool gem_has_lmem(int fd)
 {
+	struct drm_i915_query_item item;
+	int ret;
+
+	memset(&item, 0, sizeof(item));
+	item.query_id = DRM_I915_QUERY_MEMORY_REGIONS;
+	ret = __i915_query_items(fd, &item, 1);
+	if (ret != 0 || item.length < 0)
+		return false;
+
 	return gem_get_lmem_region_count(fd) > 0;
 }
 
-- 
2.32.0



More information about the igt-dev mailing list