blob: 15120842b3fc07b278051b33d27eb6840b215ea2 [file] [log] [blame]
Chris Wilsoneb7d60e2015-06-17 18:29:49 +01001/*
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 Wood804e11f2015-08-17 17:57:43 +010030#include "igt.h"
Chris Wilsoneb7d60e2015-06-17 18:29:49 +010031#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 Wilson9bbf6422016-11-18 08:50:33 +000042#include "igt_vgem.h"
Chris Wilsoneb7d60e2015-06-17 18:29:49 +010043
44IGT_TEST_DESCRIPTION("Test that specific ioctls report a wedged GPU (EIO).");
45
46static 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
Chris Wilson6b2dddd2017-07-25 17:11:16 +010056 ret = write(fd, &"01"[enable], 1) == 1;
Chris Wilsoneb7d60e2015-06-17 18:29:49 +010057 close(fd);
58
59 return ret;
60}
61
Chris Wilsoneb7d60e2015-06-17 18:29:49 +010062static void trigger_reset(int fd)
63{
Chris Wilson83884e92017-03-21 17:16:03 +000064 igt_force_gpu_reset(fd);
Chris Wilsoneb7d60e2015-06-17 18:29:49 +010065
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
71static 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
84static 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
92static 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 Wilsoneb7d60e2015-06-17 18:29:49 +0100101static 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 Wilson4de67b22017-01-02 11:05:21 +0000113 execbuf.buffers_ptr = to_user_pointer(&exec);
Chris Wilsoneb7d60e2015-06-17 18:29:49 +0100114 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 Wilson32c89882015-07-15 16:18:10 +0100124static 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
138static void test_wait(int fd)
139{
Chris Wilson0a1fc452016-09-13 11:13:14 +0100140 igt_hang_t hang;
Chris Wilson32c89882015-07-15 16:18:10 +0100141
Daniel Vetter40798ef2015-12-16 13:13:58 +0000142 /* 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 Wilson32c89882015-07-15 16:18:10 +0100145 hang = igt_hang_ring(fd, I915_EXEC_DEFAULT);
Daniel Vetter40798ef2015-12-16 13:13:58 +0000146 igt_assert_eq(__gem_wait(fd, hang.handle, -1), 0);
Chris Wilson32c89882015-07-15 16:18:10 +0100147 igt_post_hang_ring(fd, hang);
148
Daniel Vetter40798ef2015-12-16 13:13:58 +0000149 /* 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 Wilson32c89882015-07-15 16:18:10 +0100158 trigger_reset(fd);
159}
160
Chris Wilson9bbf6422016-11-18 08:50:33 +0000161struct cork {
162 int device;
163 uint32_t handle;
164 uint32_t fence;
165};
166
167static 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
185static void unplug(struct cork *c)
186{
187 vgem_fence_signal(c->device, c->fence);
188 close(c->device);
189}
190
191static void test_inflight(int fd)
192{
193 struct drm_i915_gem_execbuffer2 execbuf;
Chris Wilson40a3ada2016-11-18 13:55:21 +0000194 struct drm_i915_gem_exec_object2 obj[2];
Chris Wilson9bbf6422016-11-18 08:50:33 +0000195 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 Wilson40a3ada2016-11-18 13:55:21 +0000204 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 Wilson9bbf6422016-11-18 08:50:33 +0000208
209 memset(&execbuf, 0, sizeof(execbuf));
Chris Wilson4de67b22017-01-02 11:05:21 +0000210 execbuf.buffers_ptr = to_user_pointer(obj);
Chris Wilson9bbf6422016-11-18 08:50:33 +0000211 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 Wilson40a3ada2016-11-18 13:55:21 +0000217 igt_assert_eq(__gem_wait(fd, obj[1].handle, -1), 0);
Chris Wilson9bbf6422016-11-18 08:50:33 +0000218
219 igt_require(i915_reset_control(true));
220 trigger_reset(fd);
221}
222
Chris Wilsoneb7d60e2015-06-17 18:29:49 +0100223igt_main
224{
Chris Wilson32c89882015-07-15 16:18:10 +0100225 int fd = -1;
Chris Wilsoneb7d60e2015-06-17 18:29:49 +0100226
227 igt_skip_on_simulation();
228
229 igt_fixture {
Micah Fedkec81d2932015-07-22 21:54:02 +0000230 fd = drm_open_driver(DRIVER_INTEL);
Chris Wilson28a2f142017-03-08 12:22:13 +0000231 igt_require_gem(fd);
Chris Wilson92caf132015-12-16 09:23:56 +0000232 igt_require_hang_ring(fd, I915_EXEC_DEFAULT);
Chris Wilsoneb7d60e2015-06-17 18:29:49 +0100233 }
234
235 igt_subtest("throttle")
236 test_throttle(fd);
237
238 igt_subtest("execbuf")
239 test_execbuf(fd);
240
Chris Wilson32c89882015-07-15 16:18:10 +0100241 igt_subtest("wait")
242 test_wait(fd);
243
Chris Wilson9bbf6422016-11-18 08:50:33 +0000244 igt_subtest("in-flight")
245 test_inflight(fd);
246
Chris Wilsoneb7d60e2015-06-17 18:29:49 +0100247 igt_fixture
248 close(fd);
249}