summaryrefslogtreecommitdiff
path: root/graphics/mesa-devel/files/patch-userptr
blob: 7c94dba02122c20d0124c61170437b6498837e10 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
Try unsynchronized userptr if regular one fails.
https://github.com/FreeBSDDesktop/kms-drm/issues/197
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13162

--- src/gallium/drivers/crocus/crocus_bufmgr.c.orig	2023-07-19 23:28:31 UTC
+++ src/gallium/drivers/crocus/crocus_bufmgr.c
@@ -487,8 +487,20 @@ crocus_bo_create_userptr(struct crocus_bufmgr *bufmgr,
       .user_ptr = (uintptr_t)ptr,
       .user_size = size,
    };
-   if (intel_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_USERPTR, &arg))
+
+   int ret;
+retry:
+   ret = intel_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_USERPTR, &arg);
+   if (ret) {
+      if (errno == ENODEV && arg.flags == 0) {
+         arg.flags = I915_USERPTR_UNSYNCHRONIZED;
+         goto retry;
+      }
+      if (geteuid() != 0) {
+         fprintf(stderr, "%s", "ioctl(I915_GEM_USERPTR) failed. Try running as root but expect poor stability.\n");
+      }
       goto err_free;
+   }
    bo->gem_handle = arg.handle;
 
    /* Check the buffer for validity before we try and use it in a batch */
--- src/gallium/drivers/iris/i915/iris_kmd_backend.c.orig	2023-07-31 18:56:34 UTC
+++ src/gallium/drivers/iris/i915/iris_kmd_backend.c
@@ -430,8 +430,20 @@ i915_gem_create_userptr(struct iris_bufmgr *bufmgr, vo
       .user_size = size,
       .flags = devinfo->has_userptr_probe ? I915_USERPTR_PROBE : 0,
    };
-   if (intel_ioctl(iris_bufmgr_get_fd(bufmgr), DRM_IOCTL_I915_GEM_USERPTR, &arg))
+
+   int ret;
+retry:
+   ret = intel_ioctl(iris_bufmgr_get_fd(bufmgr), DRM_IOCTL_I915_GEM_USERPTR, &arg);
+   if (ret) {
+      if (errno == ENODEV && arg.flags == 0) {
+         arg.flags = I915_USERPTR_UNSYNCHRONIZED;
+         goto retry;
+      }
+      if (geteuid() != 0) {
+         fprintf(stderr, "%s", "ioctl(I915_GEM_USERPTR) failed. Try running as root but expect poor stability.\n");
+      }
       return 0;
+   }
 
    if (!devinfo->has_userptr_probe) {
       /* Check the buffer for validity before we try and use it in a batch */
--- src/intel/vulkan_hasvk/anv_gem.c.orig	2023-07-19 23:28:31 UTC
+++ src/intel/vulkan_hasvk/anv_gem.c
@@ -150,9 +150,19 @@ anv_gem_userptr(struct anv_device *device, void *mem, 
    if (device->physical->info.has_userptr_probe)
       userptr.flags |= I915_USERPTR_PROBE;
 
-   int ret = intel_ioctl(device->fd, DRM_IOCTL_I915_GEM_USERPTR, &userptr);
-   if (ret == -1)
+   int ret;
+retry:
+   ret = intel_ioctl(device->fd, DRM_IOCTL_I915_GEM_USERPTR, &userptr);
+   if (ret == -1) {
+      if (errno == ENODEV && userptr.flags == 0) {
+         userptr.flags = I915_USERPTR_UNSYNCHRONIZED;
+         goto retry;
+      }
+      if (geteuid() != 0) {
+         fprintf(stderr, "%s", "ioctl(I915_GEM_USERPTR) failed. Try running as root but expect poor stability.\n");
+      }
       return 0;
+   }
 
    return userptr.handle;
 }
--- src/intel/vulkan/i915/anv_kmd_backend.c.orig	2023-07-19 23:28:31 UTC
+++ src/intel/vulkan/i915/anv_kmd_backend.c
@@ -191,9 +191,19 @@ i915_gem_create_userptr(struct anv_device *device, voi
    if (device->physical->info.has_userptr_probe)
       userptr.flags |= I915_USERPTR_PROBE;
 
-   int ret = intel_ioctl(device->fd, DRM_IOCTL_I915_GEM_USERPTR, &userptr);
-   if (ret == -1)
+   int ret;
+retry:
+   ret = intel_ioctl(device->fd, DRM_IOCTL_I915_GEM_USERPTR, &userptr);
+   if (ret == -1) {
+      if (errno == ENODEV && userptr.flags == 0) {
+         userptr.flags = I915_USERPTR_UNSYNCHRONIZED;
+         goto retry;
+      }
+      if (geteuid() != 0) {
+         fprintf(stderr, "%s", "ioctl(I915_GEM_USERPTR) failed. Try running as root but expect poor stability.\n");
+      }
       return 0;
+   }
 
    return userptr.handle;
 }