From a2175b7ec365e1c52756f91e45fef3c3bd9af549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Tue, 31 Mar 2026 11:47:40 -0700 Subject: [PATCH] iris: Improve and standardize the behavior of madvice in i915 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This removes the conversion between iris_madvice and i915 values, placing it by a static assert in case this values ever don't match. Also adds a warn once in case of DRM_IOCTL_I915_GEM_MADVISE ever fails. As at last in case of failure of DRM_IOCTL_I915_GEM_MADVISE returns as if the bo is not retained anymore to have a safe behavior. Reviewed-by: Paulo Zanoni Suggested-by: Paulo Zanoni Signed-off-by: José Roberto de Souza Part-of: --- src/gallium/drivers/iris/i915/iris_kmd_backend.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/gallium/drivers/iris/i915/iris_kmd_backend.c b/src/gallium/drivers/iris/i915/iris_kmd_backend.c index d0c3a775afd..b5933921663 100644 --- a/src/gallium/drivers/iris/i915/iris_kmd_backend.c +++ b/src/gallium/drivers/iris/i915/iris_kmd_backend.c @@ -28,6 +28,7 @@ #include "common/intel_gem.h" #include "common/i915/intel_gem.h" #include "dev/intel_debug.h" +#include "util/u_debug.h" #include "drm-uapi/i915_drm.h" @@ -147,17 +148,20 @@ i915_gem_create(struct iris_bufmgr *bufmgr, static bool i915_bo_madvise(struct iris_bo *bo, enum iris_madvice state) { - uint32_t i915_state = state == IRIS_MADVICE_WILL_NEED ? - I915_MADV_WILLNEED : I915_MADV_DONTNEED; struct drm_i915_gem_madvise madv = { .handle = bo->gem_handle, - .madv = i915_state, + .madv = state, .retained = 1, }; - intel_ioctl(iris_bufmgr_get_fd(bo->bufmgr), DRM_IOCTL_I915_GEM_MADVISE, &madv); + /* Make sure iris_madvice values match with i915 values */ + STATIC_ASSERT(IRIS_MADVICE_WILL_NEED == I915_MADV_WILLNEED); + STATIC_ASSERT(IRIS_MADVICE_DONT_NEED == I915_MADV_DONTNEED); - return madv.retained; + int ret = intel_ioctl(iris_bufmgr_get_fd(bo->bufmgr), DRM_IOCTL_I915_GEM_MADVISE, &madv); + if (ret) + debug_warn_once("DRM_IOCTL_I915_GEM_MADVISE failed at least once\n"); + return ret == 0 ? madv.retained : false; } static int