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 | |
| 28 | #include <unistd.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <stdint.h> |
| 31 | #include <stdio.h> |
| 32 | #include <string.h> |
| 33 | #include <fcntl.h> |
| 34 | #include <inttypes.h> |
| 35 | #include <errno.h> |
| 36 | #include <sys/stat.h> |
| 37 | #include <sys/ioctl.h> |
| 38 | #include <sys/time.h> |
| 39 | #include "drm.h" |
| 40 | |
| 41 | #include "ioctl_wrappers.h" |
| 42 | #include "drmtest.h" |
| 43 | #include "intel_io.h" |
| 44 | #include "intel_chipset.h" |
| 45 | #include "igt_aux.h" |
| 46 | |
| 47 | #define LOCAL_I915_EXEC_VEBOX (4<<0) |
Zhipeng Gong | f8d47cb | 2015-01-13 08:50:20 +0800 | [diff] [blame^] | 48 | #define LOCAL_I915_EXEC_BSD_MASK (3<<13) |
| 49 | #define LOCAL_I915_EXEC_BSD_RING1 (1<<13) |
| 50 | #define LOCAL_I915_EXEC_BSD_RING2 (2<<13) |
Daniel Vetter | cd3850e | 2014-04-23 20:23:28 +0200 | [diff] [blame] | 51 | |
| 52 | struct drm_i915_gem_execbuffer2 execbuf; |
| 53 | struct drm_i915_gem_exec_object2 gem_exec[1]; |
| 54 | uint32_t batch[2] = {MI_BATCH_BUFFER_END}; |
| 55 | uint32_t handle, devid; |
| 56 | int fd; |
| 57 | |
| 58 | igt_main |
| 59 | { |
| 60 | igt_fixture { |
| 61 | fd = drm_open_any(); |
| 62 | |
| 63 | devid = intel_get_drm_devid(fd); |
| 64 | |
| 65 | handle = gem_create(fd, 4096); |
| 66 | gem_write(fd, handle, 0, batch, sizeof(batch)); |
| 67 | |
| 68 | gem_exec[0].handle = handle; |
| 69 | gem_exec[0].relocation_count = 0; |
| 70 | gem_exec[0].relocs_ptr = 0; |
| 71 | gem_exec[0].alignment = 0; |
| 72 | gem_exec[0].offset = 0; |
| 73 | gem_exec[0].flags = 0; |
| 74 | gem_exec[0].rsvd1 = 0; |
| 75 | gem_exec[0].rsvd2 = 0; |
| 76 | |
| 77 | execbuf.buffers_ptr = (uintptr_t)gem_exec; |
| 78 | execbuf.buffer_count = 1; |
| 79 | execbuf.batch_start_offset = 0; |
| 80 | execbuf.batch_len = 8; |
| 81 | execbuf.cliprects_ptr = 0; |
| 82 | execbuf.num_cliprects = 0; |
| 83 | execbuf.DR1 = 0; |
| 84 | execbuf.DR4 = 0; |
| 85 | execbuf.flags = 0; |
| 86 | i915_execbuffer2_set_context_id(execbuf, 0); |
| 87 | execbuf.rsvd2 = 0; |
| 88 | } |
| 89 | |
| 90 | igt_subtest("control") { |
| 91 | igt_assert(drmIoctl(fd, |
| 92 | DRM_IOCTL_I915_GEM_EXECBUFFER2, |
| 93 | &execbuf) == 0); |
| 94 | execbuf.flags = I915_EXEC_RENDER; |
| 95 | igt_assert(drmIoctl(fd, |
| 96 | DRM_IOCTL_I915_GEM_EXECBUFFER2, |
| 97 | &execbuf) == 0); |
| 98 | } |
| 99 | |
| 100 | #define RUN_FAIL(expected_errno) do { \ |
| 101 | igt_assert(drmIoctl(fd, \ |
| 102 | DRM_IOCTL_I915_GEM_EXECBUFFER2, \ |
| 103 | &execbuf) == -1); \ |
Chris Wilson | 3b94d3f | 2014-08-29 13:11:40 +0100 | [diff] [blame] | 104 | igt_assert_eq(errno, expected_errno); \ |
Daniel Vetter | cd3850e | 2014-04-23 20:23:28 +0200 | [diff] [blame] | 105 | } while(0) |
| 106 | |
| 107 | igt_subtest("no-bsd") { |
| 108 | igt_require(!gem_has_bsd(fd)); |
| 109 | execbuf.flags = I915_EXEC_BSD; |
| 110 | RUN_FAIL(EINVAL); |
| 111 | } |
| 112 | igt_subtest("no-blt") { |
| 113 | igt_require(!gem_has_blt(fd)); |
| 114 | execbuf.flags = I915_EXEC_BLT; |
| 115 | RUN_FAIL(EINVAL); |
| 116 | } |
| 117 | igt_subtest("no-vebox") { |
| 118 | igt_require(!gem_has_vebox(fd)); |
| 119 | execbuf.flags = LOCAL_I915_EXEC_VEBOX; |
| 120 | RUN_FAIL(EINVAL); |
| 121 | } |
| 122 | igt_subtest("invalid-ring") { |
Daniel Vetter | 6abfe2f | 2014-04-28 15:26:15 +0200 | [diff] [blame] | 123 | execbuf.flags = I915_EXEC_RING_MASK; |
| 124 | RUN_FAIL(EINVAL); |
| 125 | } |
| 126 | |
| 127 | igt_subtest("invalid-ring2") { |
Daniel Vetter | cd3850e | 2014-04-23 20:23:28 +0200 | [diff] [blame] | 128 | execbuf.flags = LOCAL_I915_EXEC_VEBOX+1; |
| 129 | RUN_FAIL(EINVAL); |
| 130 | } |
| 131 | |
Zhipeng Gong | f8d47cb | 2015-01-13 08:50:20 +0800 | [diff] [blame^] | 132 | igt_subtest("invalid-bsd-ring") { |
| 133 | igt_require(gem_has_bsd2(fd)); |
| 134 | execbuf.flags = I915_EXEC_BSD | LOCAL_I915_EXEC_BSD_MASK; |
| 135 | RUN_FAIL(EINVAL); |
| 136 | } |
| 137 | |
| 138 | igt_subtest("invalid-bsd1-flag-on-render") { |
| 139 | execbuf.flags = I915_EXEC_RENDER | LOCAL_I915_EXEC_BSD_RING1; |
| 140 | RUN_FAIL(EINVAL); |
| 141 | } |
| 142 | |
| 143 | igt_subtest("invalid-bsd2-flag-on-render") { |
| 144 | execbuf.flags = I915_EXEC_RENDER | LOCAL_I915_EXEC_BSD_RING2; |
| 145 | RUN_FAIL(EINVAL); |
| 146 | } |
| 147 | |
| 148 | igt_subtest("invalid-bsd1-flag-on-blt") { |
| 149 | execbuf.flags = I915_EXEC_BLT | LOCAL_I915_EXEC_BSD_RING1; |
| 150 | RUN_FAIL(EINVAL); |
| 151 | } |
| 152 | |
| 153 | igt_subtest("invalid-bsd2-flag-on-blt") { |
| 154 | execbuf.flags = I915_EXEC_BLT | LOCAL_I915_EXEC_BSD_RING2; |
| 155 | RUN_FAIL(EINVAL); |
| 156 | } |
| 157 | |
| 158 | igt_subtest("invalid-bsd1-flag-on-vebox") { |
| 159 | igt_require(gem_has_vebox(fd)); |
| 160 | execbuf.flags = LOCAL_I915_EXEC_VEBOX | LOCAL_I915_EXEC_BSD_RING1; |
| 161 | RUN_FAIL(EINVAL); |
| 162 | } |
| 163 | |
| 164 | igt_subtest("invalid-bsd2-flag-on-vebox") { |
| 165 | igt_require(gem_has_vebox(fd)); |
| 166 | execbuf.flags = LOCAL_I915_EXEC_VEBOX | LOCAL_I915_EXEC_BSD_RING2; |
| 167 | RUN_FAIL(EINVAL); |
| 168 | } |
| 169 | |
Daniel Vetter | cd3850e | 2014-04-23 20:23:28 +0200 | [diff] [blame] | 170 | igt_subtest("rel-constants-invalid-ring") { |
| 171 | igt_require(gem_has_bsd(fd)); |
| 172 | execbuf.flags = I915_EXEC_BSD | I915_EXEC_CONSTANTS_ABSOLUTE; |
| 173 | RUN_FAIL(EINVAL); |
| 174 | } |
| 175 | |
| 176 | igt_subtest("rel-constants-invalid-rel-gen5") { |
| 177 | igt_require(intel_gen(devid) > 5); |
| 178 | execbuf.flags = I915_EXEC_RENDER | I915_EXEC_CONSTANTS_REL_SURFACE; |
| 179 | RUN_FAIL(EINVAL); |
| 180 | } |
| 181 | |
| 182 | igt_subtest("rel-constants-invalid") { |
Daniel Vetter | 1639022 | 2014-04-24 10:43:38 +0200 | [diff] [blame] | 183 | execbuf.flags = I915_EXEC_RENDER | (I915_EXEC_CONSTANTS_REL_SURFACE+(1<<6)); |
Daniel Vetter | cd3850e | 2014-04-23 20:23:28 +0200 | [diff] [blame] | 184 | RUN_FAIL(EINVAL); |
| 185 | } |
| 186 | |
| 187 | igt_subtest("sol-reset-invalid") { |
| 188 | igt_require(gem_has_bsd(fd)); |
| 189 | execbuf.flags = I915_EXEC_BSD | I915_EXEC_GEN7_SOL_RESET; |
| 190 | RUN_FAIL(EINVAL); |
| 191 | } |
| 192 | |
| 193 | igt_subtest("sol-reset-not-gen7") { |
| 194 | igt_require(intel_gen(devid) != 7); |
| 195 | execbuf.flags = I915_EXEC_RENDER | I915_EXEC_GEN7_SOL_RESET; |
| 196 | RUN_FAIL(EINVAL); |
| 197 | } |
| 198 | |
| 199 | igt_subtest("secure-non-root") { |
| 200 | igt_fork(child, 1) { |
| 201 | igt_drop_root(); |
| 202 | |
| 203 | execbuf.flags = I915_EXEC_RENDER | I915_EXEC_SECURE; |
| 204 | RUN_FAIL(EPERM); |
| 205 | } |
| 206 | |
| 207 | igt_waitchildren(); |
| 208 | } |
| 209 | |
| 210 | igt_subtest("secure-non-master") { |
| 211 | do_or_die(drmDropMaster(fd)); |
| 212 | execbuf.flags = I915_EXEC_RENDER | I915_EXEC_SECURE; |
| 213 | RUN_FAIL(EPERM); |
| 214 | do_or_die(drmSetMaster(fd)); |
| 215 | igt_assert(drmIoctl(fd, |
| 216 | DRM_IOCTL_I915_GEM_EXECBUFFER2, |
| 217 | &execbuf) == 0); |
| 218 | } |
| 219 | |
| 220 | /* HANDLE_LUT and NO_RELOC are already exercised by gem_exec_lut_handle */ |
| 221 | |
| 222 | igt_subtest("invalid-flag") { |
| 223 | execbuf.flags = I915_EXEC_RENDER | (I915_EXEC_HANDLE_LUT << 1); |
| 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 | |
| 237 | #define DIRT(name) \ |
| 238 | igt_subtest(#name "-dirt") { \ |
| 239 | execbuf.flags = 0; \ |
| 240 | execbuf.name = 1; \ |
| 241 | RUN_FAIL(EINVAL); \ |
| 242 | execbuf.name = 0; \ |
| 243 | } |
| 244 | |
| 245 | DIRT(rsvd2); |
| 246 | DIRT(cliprects_ptr); |
| 247 | DIRT(DR1); |
| 248 | DIRT(DR4); |
| 249 | #undef DIRT |
| 250 | |
| 251 | #undef RUN_FAIL |
| 252 | |
| 253 | igt_fixture { |
| 254 | gem_close(fd, handle); |
| 255 | |
| 256 | close(fd); |
| 257 | } |
| 258 | } |