Mesa (main): iris: Use the new I915_USERPTR_PROBE API

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Aug 12 20:22:45 UTC 2021


Module: Mesa
Branch: main
Commit: 468c3c83b4a5a2a4ff6b6a29e81522a11672d427
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=468c3c83b4a5a2a4ff6b6a29e81522a11672d427

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Wed Jul 21 12:02:54 2021 -0700

iris: Use the new I915_USERPTR_PROBE API

We need to raise an error when importing a user pointer as a BO if the
supplied pointer can't actually be used on the GPU.  Previously, we were
(ab)using the SET_DOMAIN ioctl for this, but it's not really intended
for that purpose, and is going away on discrete.

Fortunately, there's a new kernel API for this: the I915_USERPTR_PROBE
flag tries to perform basic sanity checking of the supplied pointer so
that we can at least reject obvious misuse of this API up front.

Use the new API where available.  Fall back to SET_DOMAIN if it isn't.

Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12044>

---

 src/gallium/drivers/iris/iris_bufmgr.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c
index 76c73918be3..dd694921064 100644
--- a/src/gallium/drivers/iris/iris_bufmgr.c
+++ b/src/gallium/drivers/iris/iris_bufmgr.c
@@ -210,6 +210,7 @@ struct iris_bufmgr {
    bool has_local_mem:1;
    bool has_mmap_offset:1;
    bool has_tiling_uapi:1;
+   bool has_userptr_probe:1;
    bool bo_reuse:1;
 
    struct intel_aux_map_context *aux_map_ctx;
@@ -707,18 +708,21 @@ iris_bo_create_userptr(struct iris_bufmgr *bufmgr, const char *name,
    struct drm_i915_gem_userptr arg = {
       .user_ptr = (uintptr_t)ptr,
       .user_size = size,
+      .flags = bufmgr->has_userptr_probe ? I915_USERPTR_PROBE : 0,
    };
    if (intel_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_USERPTR, &arg))
       goto err_free;
    bo->gem_handle = arg.handle;
 
-   /* Check the buffer for validity before we try and use it in a batch */
-   struct drm_i915_gem_set_domain sd = {
-      .handle = bo->gem_handle,
-      .read_domains = I915_GEM_DOMAIN_CPU,
-   };
-   if (intel_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &sd))
-      goto err_close;
+   if (!bufmgr->has_userptr_probe) {
+      /* Check the buffer for validity before we try and use it in a batch */
+      struct drm_i915_gem_set_domain sd = {
+         .handle = bo->gem_handle,
+         .read_domains = I915_GEM_DOMAIN_CPU,
+      };
+      if (intel_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &sd))
+         goto err_close;
+   }
 
    bo->name = name;
    bo->size = size;
@@ -1774,6 +1778,8 @@ iris_bufmgr_create(struct intel_device_info *devinfo, int fd, bool bo_reuse)
    bufmgr->has_tiling_uapi = devinfo->has_tiling_uapi;
    bufmgr->bo_reuse = bo_reuse;
    bufmgr->has_mmap_offset = gem_param(fd, I915_PARAM_MMAP_GTT_VERSION) >= 4;
+   bufmgr->has_userptr_probe =
+      gem_param(fd, I915_PARAM_HAS_USERPTR_PROBE) >= 1;
    iris_bufmgr_query_meminfo(bufmgr);
 
    STATIC_ASSERT(IRIS_MEMZONE_SHADER_START == 0ull);



More information about the mesa-commit mailing list