Daniel Vetter | cd3850e | 2014-04-23 20:23:28 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 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 | * Authors: |
| 24 | * Daniel Vetter |
| 25 | * |
| 26 | */ |
| 27 | |
Thomas Wood | 804e11f | 2015-08-17 17:57:43 +0100 | [diff] [blame] | 28 | #include "igt.h" |
Daniel Vetter | cd3850e | 2014-04-23 20:23:28 +0200 | [diff] [blame] | 29 | #include <unistd.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <stdint.h> |
| 32 | #include <stdio.h> |
| 33 | #include <string.h> |
| 34 | #include <fcntl.h> |
| 35 | #include <inttypes.h> |
| 36 | #include <errno.h> |
| 37 | #include <sys/stat.h> |
| 38 | #include <sys/ioctl.h> |
| 39 | #include <sys/time.h> |
| 40 | #include "drm.h" |
| 41 | |
Daniel Vetter | cd3850e | 2014-04-23 20:23:28 +0200 | [diff] [blame] | 42 | |
| 43 | #define LOCAL_I915_EXEC_VEBOX (4<<0) |
Zhipeng Gong | f8d47cb | 2015-01-13 08:50:20 +0800 | [diff] [blame] | 44 | #define LOCAL_I915_EXEC_BSD_MASK (3<<13) |
| 45 | #define LOCAL_I915_EXEC_BSD_RING1 (1<<13) |
| 46 | #define LOCAL_I915_EXEC_BSD_RING2 (2<<13) |
Abdiel Janulgue | 8ad1e40 | 2015-06-16 13:37:44 +0300 | [diff] [blame] | 47 | #define LOCAL_I915_EXEC_RESOURCE_STREAMER (1<<15) |
Daniel Vetter | cd3850e | 2014-04-23 20:23:28 +0200 | [diff] [blame] | 48 | |
| 49 | struct drm_i915_gem_execbuffer2 execbuf; |
| 50 | struct drm_i915_gem_exec_object2 gem_exec[1]; |
| 51 | uint32_t batch[2] = {MI_BATCH_BUFFER_END}; |
| 52 | uint32_t handle, devid; |
| 53 | int fd; |
| 54 | |
| 55 | igt_main |
| 56 | { |
| 57 | igt_fixture { |
Micah Fedke | c81d293 | 2015-07-22 21:54:02 +0000 | [diff] [blame^] | 58 | fd = drm_open_driver(DRIVER_INTEL); |
Daniel Vetter | cd3850e | 2014-04-23 20:23:28 +0200 | [diff] [blame] | 59 | |
| 60 | devid = intel_get_drm_devid(fd); |
| 61 | |
| 62 | handle = gem_create(fd, 4096); |
| 63 | gem_write(fd, handle, 0, batch, sizeof(batch)); |
| 64 | |
| 65 | gem_exec[0].handle = handle; |
| 66 | gem_exec[0].relocation_count = 0; |
| 67 | gem_exec[0].relocs_ptr = 0; |
| 68 | gem_exec[0].alignment = 0; |
| 69 | gem_exec[0].offset = 0; |
| 70 | gem_exec[0].flags = 0; |
| 71 | gem_exec[0].rsvd1 = 0; |
| 72 | gem_exec[0].rsvd2 = 0; |
| 73 | |
| 74 | execbuf.buffers_ptr = (uintptr_t)gem_exec; |
| 75 | execbuf.buffer_count = 1; |
| 76 | execbuf.batch_start_offset = 0; |
| 77 | execbuf.batch_len = 8; |
| 78 | execbuf.cliprects_ptr = 0; |
| 79 | execbuf.num_cliprects = 0; |
| 80 | execbuf.DR1 = 0; |
| 81 | execbuf.DR4 = 0; |
| 82 | execbuf.flags = 0; |
| 83 | i915_execbuffer2_set_context_id(execbuf, 0); |
| 84 | execbuf.rsvd2 = 0; |
| 85 | } |
| 86 | |
| 87 | igt_subtest("control") { |
| 88 | igt_assert(drmIoctl(fd, |
| 89 | DRM_IOCTL_I915_GEM_EXECBUFFER2, |
| 90 | &execbuf) == 0); |
| 91 | execbuf.flags = I915_EXEC_RENDER; |
| 92 | igt_assert(drmIoctl(fd, |
| 93 | DRM_IOCTL_I915_GEM_EXECBUFFER2, |
| 94 | &execbuf) == 0); |
| 95 | } |
| 96 | |
| 97 | #define RUN_FAIL(expected_errno) do { \ |
| 98 | igt_assert(drmIoctl(fd, \ |
| 99 | DRM_IOCTL_I915_GEM_EXECBUFFER2, \ |
| 100 | &execbuf) == -1); \ |
Chris Wilson | 3b94d3f | 2014-08-29 13:11:40 +0100 | [diff] [blame] | 101 | igt_assert_eq(errno, expected_errno); \ |
Daniel Vetter | cd3850e | 2014-04-23 20:23:28 +0200 | [diff] [blame] | 102 | } while(0) |
| 103 | |
| 104 | igt_subtest("no-bsd") { |
| 105 | igt_require(!gem_has_bsd(fd)); |
| 106 | execbuf.flags = I915_EXEC_BSD; |
| 107 | RUN_FAIL(EINVAL); |
| 108 | } |
| 109 | igt_subtest("no-blt") { |
| 110 | igt_require(!gem_has_blt(fd)); |
| 111 | execbuf.flags = I915_EXEC_BLT; |
| 112 | RUN_FAIL(EINVAL); |
| 113 | } |
| 114 | igt_subtest("no-vebox") { |
| 115 | igt_require(!gem_has_vebox(fd)); |
| 116 | execbuf.flags = LOCAL_I915_EXEC_VEBOX; |
| 117 | RUN_FAIL(EINVAL); |
| 118 | } |
| 119 | igt_subtest("invalid-ring") { |
Daniel Vetter | 6abfe2f | 2014-04-28 15:26:15 +0200 | [diff] [blame] | 120 | execbuf.flags = I915_EXEC_RING_MASK; |
| 121 | RUN_FAIL(EINVAL); |
| 122 | } |
| 123 | |
| 124 | igt_subtest("invalid-ring2") { |
Daniel Vetter | cd3850e | 2014-04-23 20:23:28 +0200 | [diff] [blame] | 125 | execbuf.flags = LOCAL_I915_EXEC_VEBOX+1; |
| 126 | RUN_FAIL(EINVAL); |
| 127 | } |
| 128 | |
Zhipeng Gong | f8d47cb | 2015-01-13 08:50:20 +0800 | [diff] [blame] | 129 | igt_subtest("invalid-bsd-ring") { |
| 130 | igt_require(gem_has_bsd2(fd)); |
| 131 | execbuf.flags = I915_EXEC_BSD | LOCAL_I915_EXEC_BSD_MASK; |
| 132 | RUN_FAIL(EINVAL); |
| 133 | } |
| 134 | |
| 135 | igt_subtest("invalid-bsd1-flag-on-render") { |
| 136 | execbuf.flags = I915_EXEC_RENDER | LOCAL_I915_EXEC_BSD_RING1; |
| 137 | RUN_FAIL(EINVAL); |
| 138 | } |
| 139 | |
| 140 | igt_subtest("invalid-bsd2-flag-on-render") { |
| 141 | execbuf.flags = I915_EXEC_RENDER | LOCAL_I915_EXEC_BSD_RING2; |
| 142 | RUN_FAIL(EINVAL); |
| 143 | } |
| 144 | |
| 145 | igt_subtest("invalid-bsd1-flag-on-blt") { |
| 146 | execbuf.flags = I915_EXEC_BLT | LOCAL_I915_EXEC_BSD_RING1; |
| 147 | RUN_FAIL(EINVAL); |
| 148 | } |
| 149 | |
| 150 | igt_subtest("invalid-bsd2-flag-on-blt") { |
| 151 | execbuf.flags = I915_EXEC_BLT | LOCAL_I915_EXEC_BSD_RING2; |
| 152 | RUN_FAIL(EINVAL); |
| 153 | } |
| 154 | |
| 155 | igt_subtest("invalid-bsd1-flag-on-vebox") { |
| 156 | igt_require(gem_has_vebox(fd)); |
| 157 | execbuf.flags = LOCAL_I915_EXEC_VEBOX | LOCAL_I915_EXEC_BSD_RING1; |
| 158 | RUN_FAIL(EINVAL); |
| 159 | } |
| 160 | |
| 161 | igt_subtest("invalid-bsd2-flag-on-vebox") { |
| 162 | igt_require(gem_has_vebox(fd)); |
| 163 | execbuf.flags = LOCAL_I915_EXEC_VEBOX | LOCAL_I915_EXEC_BSD_RING2; |
| 164 | RUN_FAIL(EINVAL); |
| 165 | } |
| 166 | |
Daniel Vetter | cd3850e | 2014-04-23 20:23:28 +0200 | [diff] [blame] | 167 | igt_subtest("rel-constants-invalid-ring") { |
| 168 | igt_require(gem_has_bsd(fd)); |
| 169 | execbuf.flags = I915_EXEC_BSD | I915_EXEC_CONSTANTS_ABSOLUTE; |
| 170 | RUN_FAIL(EINVAL); |
| 171 | } |
| 172 | |
| 173 | igt_subtest("rel-constants-invalid-rel-gen5") { |
| 174 | igt_require(intel_gen(devid) > 5); |
| 175 | execbuf.flags = I915_EXEC_RENDER | I915_EXEC_CONSTANTS_REL_SURFACE; |
| 176 | RUN_FAIL(EINVAL); |
| 177 | } |
| 178 | |
| 179 | igt_subtest("rel-constants-invalid") { |
Daniel Vetter | 1639022 | 2014-04-24 10:43:38 +0200 | [diff] [blame] | 180 | execbuf.flags = I915_EXEC_RENDER | (I915_EXEC_CONSTANTS_REL_SURFACE+(1<<6)); |
Daniel Vetter | cd3850e | 2014-04-23 20:23:28 +0200 | [diff] [blame] | 181 | RUN_FAIL(EINVAL); |
| 182 | } |
| 183 | |
| 184 | igt_subtest("sol-reset-invalid") { |
| 185 | igt_require(gem_has_bsd(fd)); |
| 186 | execbuf.flags = I915_EXEC_BSD | I915_EXEC_GEN7_SOL_RESET; |
| 187 | RUN_FAIL(EINVAL); |
| 188 | } |
| 189 | |
| 190 | igt_subtest("sol-reset-not-gen7") { |
| 191 | igt_require(intel_gen(devid) != 7); |
| 192 | execbuf.flags = I915_EXEC_RENDER | I915_EXEC_GEN7_SOL_RESET; |
| 193 | RUN_FAIL(EINVAL); |
| 194 | } |
| 195 | |
| 196 | igt_subtest("secure-non-root") { |
| 197 | igt_fork(child, 1) { |
| 198 | igt_drop_root(); |
| 199 | |
| 200 | execbuf.flags = I915_EXEC_RENDER | I915_EXEC_SECURE; |
| 201 | RUN_FAIL(EPERM); |
| 202 | } |
| 203 | |
| 204 | igt_waitchildren(); |
| 205 | } |
| 206 | |
| 207 | igt_subtest("secure-non-master") { |
| 208 | do_or_die(drmDropMaster(fd)); |
| 209 | execbuf.flags = I915_EXEC_RENDER | I915_EXEC_SECURE; |
| 210 | RUN_FAIL(EPERM); |
| 211 | do_or_die(drmSetMaster(fd)); |
| 212 | igt_assert(drmIoctl(fd, |
| 213 | DRM_IOCTL_I915_GEM_EXECBUFFER2, |
| 214 | &execbuf) == 0); |
| 215 | } |
| 216 | |
| 217 | /* HANDLE_LUT and NO_RELOC are already exercised by gem_exec_lut_handle */ |
| 218 | |
| 219 | igt_subtest("invalid-flag") { |
Daniel Vetter | adfc294 | 2015-08-07 19:27:30 +0200 | [diff] [blame] | 220 | /* NOTE: This test intentionally exercise the next available |
| 221 | * flag. Don't "fix" this testcase without adding the required |
| 222 | * tests for the new flag first. */ |
Abdiel Janulgue | 8ad1e40 | 2015-06-16 13:37:44 +0300 | [diff] [blame] | 223 | execbuf.flags = I915_EXEC_RENDER | (LOCAL_I915_EXEC_RESOURCE_STREAMER << 1); |
Daniel Vetter | cd3850e | 2014-04-23 20:23:28 +0200 | [diff] [blame] | 224 | RUN_FAIL(EINVAL); |
| 225 | } |
| 226 | |
| 227 | /* rsvd1 aka context id is already exercised by gem_ctx_bad_exec */ |
| 228 | |
| 229 | igt_subtest("cliprects-invalid") { |
| 230 | igt_require(intel_gen(devid) >= 5); |
| 231 | execbuf.flags = 0; |
| 232 | execbuf.num_cliprects = 1; |
| 233 | RUN_FAIL(EINVAL); |
| 234 | execbuf.num_cliprects = 0; |
| 235 | } |
| 236 | |
Abdiel Janulgue | 8ad1e40 | 2015-06-16 13:37:44 +0300 | [diff] [blame] | 237 | igt_subtest("rs-invalid-on-bsd-ring") { |
| 238 | igt_require(IS_HASWELL(devid) || intel_gen(devid) >= 8); |
| 239 | execbuf.flags = I915_EXEC_BSD | LOCAL_I915_EXEC_RESOURCE_STREAMER; |
| 240 | RUN_FAIL(EINVAL); |
| 241 | } |
| 242 | |
| 243 | igt_subtest("rs-invalid-on-blt-ring") { |
| 244 | igt_require(IS_HASWELL(devid) || intel_gen(devid) >= 8); |
| 245 | execbuf.flags = I915_EXEC_BLT | LOCAL_I915_EXEC_RESOURCE_STREAMER; |
| 246 | RUN_FAIL(EINVAL); |
| 247 | } |
| 248 | |
| 249 | igt_subtest("rs-invalid-on-vebox-ring") { |
| 250 | igt_require(IS_HASWELL(devid) || intel_gen(devid) >= 8); |
| 251 | execbuf.flags = I915_EXEC_VEBOX | LOCAL_I915_EXEC_RESOURCE_STREAMER; |
| 252 | RUN_FAIL(EINVAL); |
| 253 | } |
| 254 | |
| 255 | igt_subtest("rs-invalid-gen") { |
| 256 | igt_require(!IS_HASWELL(devid) && intel_gen(devid) < 8); |
| 257 | execbuf.flags = I915_EXEC_RENDER | LOCAL_I915_EXEC_RESOURCE_STREAMER; |
| 258 | RUN_FAIL(EINVAL); |
| 259 | } |
| 260 | |
Daniel Vetter | cd3850e | 2014-04-23 20:23:28 +0200 | [diff] [blame] | 261 | #define DIRT(name) \ |
| 262 | igt_subtest(#name "-dirt") { \ |
| 263 | execbuf.flags = 0; \ |
| 264 | execbuf.name = 1; \ |
| 265 | RUN_FAIL(EINVAL); \ |
| 266 | execbuf.name = 0; \ |
| 267 | } |
| 268 | |
| 269 | DIRT(rsvd2); |
| 270 | DIRT(cliprects_ptr); |
| 271 | DIRT(DR1); |
| 272 | DIRT(DR4); |
| 273 | #undef DIRT |
| 274 | |
| 275 | #undef RUN_FAIL |
| 276 | |
| 277 | igt_fixture { |
| 278 | gem_close(fd, handle); |
| 279 | |
| 280 | close(fd); |
| 281 | } |
| 282 | } |