Chris Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2015 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | /* |
| 26 | * Testcase: Test that only specific ioctl report a wedged GPU. |
| 27 | * |
| 28 | */ |
| 29 | |
Thomas Wood | 804e11f | 2015-08-17 17:57:43 +0100 | [diff] [blame] | 30 | #include "igt.h" |
Chris Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 31 | #include <stdlib.h> |
| 32 | #include <stdio.h> |
| 33 | #include <string.h> |
| 34 | #include <unistd.h> |
| 35 | #include <fcntl.h> |
| 36 | #include <inttypes.h> |
| 37 | #include <errno.h> |
| 38 | #include <sys/ioctl.h> |
| 39 | |
| 40 | #include <drm.h> |
| 41 | |
Chris Wilson | 9bbf642 | 2016-11-18 08:50:33 +0000 | [diff] [blame] | 42 | #include "igt_vgem.h" |
Chris Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 43 | |
| 44 | IGT_TEST_DESCRIPTION("Test that specific ioctls report a wedged GPU (EIO)."); |
| 45 | |
| 46 | static bool i915_reset_control(bool enable) |
| 47 | { |
| 48 | const char *path = "/sys/module/i915/parameters/reset"; |
| 49 | int fd, ret; |
| 50 | |
| 51 | igt_debug("%s GPU reset\n", enable ? "Enabling" : "Disabling"); |
| 52 | |
| 53 | fd = open(path, O_RDWR); |
| 54 | igt_require(fd >= 0); |
| 55 | |
| 56 | ret = write(fd, &"NY"[enable], 1) == 1; |
| 57 | close(fd); |
| 58 | |
| 59 | return ret; |
| 60 | } |
| 61 | |
Chris Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 62 | static void trigger_reset(int fd) |
| 63 | { |
Daniele Ceraolo Spurio | 03c7f84 | 2016-03-01 11:01:32 +0000 | [diff] [blame] | 64 | igt_force_gpu_reset(); |
Chris Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 65 | |
| 66 | /* And just check the gpu is indeed running again */ |
| 67 | igt_debug("Checking that the GPU recovered\n"); |
| 68 | gem_quiescent_gpu(fd); |
| 69 | } |
| 70 | |
| 71 | static void wedge_gpu(int fd) |
| 72 | { |
| 73 | /* First idle the GPU then disable GPU resets before injecting a hang */ |
| 74 | gem_quiescent_gpu(fd); |
| 75 | |
| 76 | igt_require(i915_reset_control(false)); |
| 77 | |
| 78 | igt_debug("Wedging GPU by injecting hang\n"); |
| 79 | igt_post_hang_ring(fd, igt_hang_ring(fd, I915_EXEC_DEFAULT)); |
| 80 | |
| 81 | igt_assert(i915_reset_control(true)); |
| 82 | } |
| 83 | |
| 84 | static int __gem_throttle(int fd) |
| 85 | { |
| 86 | int err = 0; |
| 87 | if (drmIoctl(fd, DRM_IOCTL_I915_GEM_THROTTLE, NULL)) |
| 88 | err = -errno; |
| 89 | return err; |
| 90 | } |
| 91 | |
| 92 | static void test_throttle(int fd) |
| 93 | { |
| 94 | wedge_gpu(fd); |
| 95 | |
| 96 | igt_assert_eq(__gem_throttle(fd), -EIO); |
| 97 | |
| 98 | trigger_reset(fd); |
| 99 | } |
| 100 | |
Chris Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 101 | static void test_execbuf(int fd) |
| 102 | { |
| 103 | struct drm_i915_gem_execbuffer2 execbuf; |
| 104 | struct drm_i915_gem_exec_object2 exec; |
| 105 | uint32_t tmp[] = { MI_BATCH_BUFFER_END }; |
| 106 | |
| 107 | memset(&exec, 0, sizeof(exec)); |
| 108 | memset(&execbuf, 0, sizeof(execbuf)); |
| 109 | |
| 110 | exec.handle = gem_create(fd, 4096); |
| 111 | gem_write(fd, exec.handle, 0, tmp, sizeof(tmp)); |
| 112 | |
Chris Wilson | 4de67b2 | 2017-01-02 11:05:21 +0000 | [diff] [blame^] | 113 | execbuf.buffers_ptr = to_user_pointer(&exec); |
Chris Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 114 | execbuf.buffer_count = 1; |
| 115 | |
| 116 | wedge_gpu(fd); |
| 117 | |
| 118 | igt_assert_eq(__gem_execbuf(fd, &execbuf), -EIO); |
| 119 | gem_close(fd, exec.handle); |
| 120 | |
| 121 | trigger_reset(fd); |
| 122 | } |
| 123 | |
Chris Wilson | 32c8988 | 2015-07-15 16:18:10 +0100 | [diff] [blame] | 124 | static int __gem_wait(int fd, uint32_t handle, int64_t timeout) |
| 125 | { |
| 126 | struct drm_i915_gem_wait wait; |
| 127 | int err = 0; |
| 128 | |
| 129 | memset(&wait, 0, sizeof(wait)); |
| 130 | wait.bo_handle = handle; |
| 131 | wait.timeout_ns = timeout; |
| 132 | if (drmIoctl(fd, DRM_IOCTL_I915_GEM_WAIT, &wait)) |
| 133 | err = -errno; |
| 134 | |
| 135 | return err; |
| 136 | } |
| 137 | |
| 138 | static void test_wait(int fd) |
| 139 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 140 | igt_hang_t hang; |
Chris Wilson | 32c8988 | 2015-07-15 16:18:10 +0100 | [diff] [blame] | 141 | |
Daniel Vetter | 40798ef | 2015-12-16 13:13:58 +0000 | [diff] [blame] | 142 | /* If the request we wait on completes due to a hang (even for |
| 143 | * that request), the user expects the return value to 0 (success). |
| 144 | */ |
Chris Wilson | 32c8988 | 2015-07-15 16:18:10 +0100 | [diff] [blame] | 145 | hang = igt_hang_ring(fd, I915_EXEC_DEFAULT); |
Daniel Vetter | 40798ef | 2015-12-16 13:13:58 +0000 | [diff] [blame] | 146 | igt_assert_eq(__gem_wait(fd, hang.handle, -1), 0); |
Chris Wilson | 32c8988 | 2015-07-15 16:18:10 +0100 | [diff] [blame] | 147 | igt_post_hang_ring(fd, hang); |
| 148 | |
Daniel Vetter | 40798ef | 2015-12-16 13:13:58 +0000 | [diff] [blame] | 149 | /* If the GPU is wedged during the wait, again we expect the return |
| 150 | * value to be 0 (success). |
| 151 | */ |
| 152 | igt_require(i915_reset_control(false)); |
| 153 | hang = igt_hang_ring(fd, I915_EXEC_DEFAULT); |
| 154 | igt_assert_eq(__gem_wait(fd, hang.handle, -1), 0); |
| 155 | igt_post_hang_ring(fd, hang); |
| 156 | igt_require(i915_reset_control(true)); |
| 157 | |
Chris Wilson | 32c8988 | 2015-07-15 16:18:10 +0100 | [diff] [blame] | 158 | trigger_reset(fd); |
| 159 | } |
| 160 | |
Chris Wilson | 9bbf642 | 2016-11-18 08:50:33 +0000 | [diff] [blame] | 161 | struct cork { |
| 162 | int device; |
| 163 | uint32_t handle; |
| 164 | uint32_t fence; |
| 165 | }; |
| 166 | |
| 167 | static void plug(int fd, struct cork *c) |
| 168 | { |
| 169 | struct vgem_bo bo; |
| 170 | int dmabuf; |
| 171 | |
| 172 | c->device = __drm_open_driver(DRIVER_VGEM); |
| 173 | igt_require(c->device != -1); |
| 174 | |
| 175 | bo.width = bo.height = 1; |
| 176 | bo.bpp = 4; |
| 177 | vgem_create(c->device, &bo); |
| 178 | c->fence = vgem_fence_attach(c->device, &bo, VGEM_FENCE_WRITE); |
| 179 | |
| 180 | dmabuf = prime_handle_to_fd(c->device, bo.handle); |
| 181 | c->handle = prime_fd_to_handle(fd, dmabuf); |
| 182 | close(dmabuf); |
| 183 | } |
| 184 | |
| 185 | static void unplug(struct cork *c) |
| 186 | { |
| 187 | vgem_fence_signal(c->device, c->fence); |
| 188 | close(c->device); |
| 189 | } |
| 190 | |
| 191 | static void test_inflight(int fd) |
| 192 | { |
| 193 | struct drm_i915_gem_execbuffer2 execbuf; |
Chris Wilson | 40a3ada | 2016-11-18 13:55:21 +0000 | [diff] [blame] | 194 | struct drm_i915_gem_exec_object2 obj[2]; |
Chris Wilson | 9bbf642 | 2016-11-18 08:50:33 +0000 | [diff] [blame] | 195 | uint32_t bbe = MI_BATCH_BUFFER_END; |
| 196 | igt_hang_t hang; |
| 197 | struct cork cork; |
| 198 | |
| 199 | igt_require(i915_reset_control(false)); |
| 200 | hang = igt_hang_ring(fd, I915_EXEC_DEFAULT); |
| 201 | |
| 202 | plug(fd, &cork); |
| 203 | |
Chris Wilson | 40a3ada | 2016-11-18 13:55:21 +0000 | [diff] [blame] | 204 | memset(obj, 0, sizeof(obj)); |
| 205 | obj[0].handle = cork.handle; |
| 206 | obj[1].handle = gem_create(fd, 4096); |
| 207 | gem_write(fd, obj[1].handle, 0, &bbe, sizeof(bbe)); |
Chris Wilson | 9bbf642 | 2016-11-18 08:50:33 +0000 | [diff] [blame] | 208 | |
| 209 | memset(&execbuf, 0, sizeof(execbuf)); |
Chris Wilson | 4de67b2 | 2017-01-02 11:05:21 +0000 | [diff] [blame^] | 210 | execbuf.buffers_ptr = to_user_pointer(obj); |
Chris Wilson | 9bbf642 | 2016-11-18 08:50:33 +0000 | [diff] [blame] | 211 | execbuf.buffer_count = 2; |
| 212 | |
| 213 | gem_execbuf(fd, &execbuf); |
| 214 | |
| 215 | igt_post_hang_ring(fd, hang); |
| 216 | unplug(&cork); /* only now submit our batches */ |
Chris Wilson | 40a3ada | 2016-11-18 13:55:21 +0000 | [diff] [blame] | 217 | igt_assert_eq(__gem_wait(fd, obj[1].handle, -1), 0); |
Chris Wilson | 9bbf642 | 2016-11-18 08:50:33 +0000 | [diff] [blame] | 218 | |
| 219 | igt_require(i915_reset_control(true)); |
| 220 | trigger_reset(fd); |
| 221 | } |
| 222 | |
Chris Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 223 | igt_main |
| 224 | { |
Chris Wilson | 32c8988 | 2015-07-15 16:18:10 +0100 | [diff] [blame] | 225 | int fd = -1; |
Chris Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 226 | |
| 227 | igt_skip_on_simulation(); |
| 228 | |
| 229 | igt_fixture { |
Micah Fedke | c81d293 | 2015-07-22 21:54:02 +0000 | [diff] [blame] | 230 | fd = drm_open_driver(DRIVER_INTEL); |
Chris Wilson | 92caf13 | 2015-12-16 09:23:56 +0000 | [diff] [blame] | 231 | igt_require_hang_ring(fd, I915_EXEC_DEFAULT); |
Chris Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | igt_subtest("throttle") |
| 235 | test_throttle(fd); |
| 236 | |
| 237 | igt_subtest("execbuf") |
| 238 | test_execbuf(fd); |
| 239 | |
Chris Wilson | 32c8988 | 2015-07-15 16:18:10 +0100 | [diff] [blame] | 240 | igt_subtest("wait") |
| 241 | test_wait(fd); |
| 242 | |
Chris Wilson | 9bbf642 | 2016-11-18 08:50:33 +0000 | [diff] [blame] | 243 | igt_subtest("in-flight") |
| 244 | test_inflight(fd); |
| 245 | |
Chris Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 246 | igt_fixture |
| 247 | close(fd); |
| 248 | } |