Skip to contentSkip to conversation

tests/drm_hw_lock: Tests for hw_lock fixes.

PATCH Superseded Peter Antoine 4 participants 9 messages Apr 23, 2015 – May 13, 2015 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/drm_hw_lock: Tests for hw_lock fixes.

There are several issues with the hardware locks functions that stretch from kernel crashes to priority escalations. This new test will test the the fixes for these features.

This test will cause a driver/kernel crash on un-patched kernels, the following patches should be applied to stop the crashes:

drm: Kernel Crash in drm_unlock
drm: Fixes unsafe deference in locks.

Issue: VIZ-5485

---
 lib/ioctl_wrappers.c   |  19 +++++
 lib/ioctl_wrappers.h   |   1 +
 tests/Makefile.sources |   1 +
 tests/drm_hw_lock.c    | 207 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 228 insertions(+)
 create mode 100644 tests/drm_hw_lock.c
lib/ioctl_wrappers.c +19 -0
index 000d394..ad8b3d3 100644
@@ -964,6 +964,25 @@ bool gem_has_bsd2(int fd)
 {
 	return gem_has_enable_ring(fd,LOCAL_I915_PARAM_HAS_BSD2);
 }
+#define I915_PARAM_HAS_LEGACY_CONTEXT	 35
+bool drm_has_legacy_context(int fd)
+{
+	int tmp = 0;
+	drm_i915_getparam_t gp;
+
+	memset(&gp, 0, sizeof(gp));
+	gp.value = &tmp;
+	gp.param = I915_PARAM_HAS_LEGACY_CONTEXT;
+
+	/*
+	 * if legacy context param is not supported, then it's old and we
+	 * can assume that the HW_LOCKS are supported.
+	 */
+	if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp) != 0)
+		return true;
+
+	return tmp == 1;
+}
 /**
  * gem_available_aperture_size:
  * @fd: open i915 drm file descriptor
lib/ioctl_wrappers.h +1 -0
index ced7ef3..3adc700 100644
@@ -120,6 +120,7 @@ bool gem_has_bsd(int fd);
 bool gem_has_blt(int fd);
 bool gem_has_vebox(int fd);
 bool gem_has_bsd2(int fd);
+bool drm_has_legacy_context(int fd);
 bool gem_uses_aliasing_ppgtt(int fd);
 int gem_available_fences(int fd);
 uint64_t gem_available_aperture_size(int fd);
tests/Makefile.sources +1 -0
index 71de6de..2f69afc 100644
@@ -84,6 +84,7 @@ TESTS_progs_M = \
 	pm_sseu \
 	prime_self_import \
 	template \
+	drm_hw_lock \
 	$(NULL)
 
 TESTS_progs = \
tests/drm_hw_lock.c new file +207 -0

207 lines not on this page · raw message

Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw
Quoted 25 lines · Peter Antoine

There are several issues with the hardware locks functions that stretch from kernel crashes to priority escalations. This new test will test the the fixes for these features.

This test will cause a driver/kernel crash on un-patched kernels, the following patches should be applied to stop the crashes:

drm: Kernel Crash in drm_unlock
drm: Fixes unsafe deference in locks.

Issue: VIZ-5485

---
 lib/ioctl_wrappers.c   |  19 +++++
 lib/ioctl_wrappers.h   |   1 +
 tests/Makefile.sources |   1 +
 tests/drm_hw_lock.c    | 207 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 228 insertions(+)
 create mode 100644 tests/drm_hw_lock.c
lib/ioctl_wrappers.c +0 -0
index 000d394..ad8b3d3 100644

lib/ioctl_wrappers.c bool gem_has_bsd2(int fd) · line 967

Quoted 4 lines
lib/ioctl_wrappers.c +1 -0
@@ -964,6 +964,25 @@ bool gem_has_bsd2(int fd)
 {
        return gem_has_enable_ring(fd,LOCAL_I915_PARAM_HAS_BSD2);
 }
+#define I915_PARAM_HAS_LEGACY_CONTEXT   35

Please add some API documentation for this new function here.

Quoted 38 lines
lib/ioctl_wrappers.c +18 -0
+bool drm_has_legacy_context(int fd)
+{
+       int tmp = 0;
+       drm_i915_getparam_t gp;
+
+       memset(&gp, 0, sizeof(gp));
+       gp.value = &tmp;
+       gp.param = I915_PARAM_HAS_LEGACY_CONTEXT;
+
+       /*
+        * if legacy context param is not supported, then it's old and we
+        * can assume that the HW_LOCKS are supported.
+        */
+       if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp) != 0)
+               return true;
+
+       return tmp == 1;
+}
 /**
  * gem_available_aperture_size:
  * @fd: open i915 drm file descriptor
lib/ioctl_wrappers.h +1 -0
index ced7ef3..3adc700 100644
@@ -120,6 +120,7 @@ bool gem_has_bsd(int fd);
 bool gem_has_blt(int fd);
 bool gem_has_vebox(int fd);
 bool gem_has_bsd2(int fd);
+bool drm_has_legacy_context(int fd);
 bool gem_uses_aliasing_ppgtt(int fd);
 int gem_available_fences(int fd);
 uint64_t gem_available_aperture_size(int fd);
tests/Makefile.sources +0 -0
index 71de6de..2f69afc 100644

tests/Makefile.sources TESTS_progs_M = \ · line 87

Quoted 4 lines
tests/Makefile.sources +1 -0
@@ -84,6 +84,7 @@ TESTS_progs_M = \
        pm_sseu \
        prime_self_import \
        template \
+       drm_hw_lock \

Please also add the binary name to .gitignore.

Quoted 27 lines
tests/Makefile.sources +0 -0
        $(NULL)
 
 TESTS_progs = \
tests/drm_hw_lock.c new file +18 -0
new file mode 100644
index 0000000..aad50ba
@@ -0,0 +1,207 @@
+/*
+ * Copyright © 2015 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

tests/drm_hw_lock.c line 28

Quoted 10 lines
tests/drm_hw_lock.c new file +10 -0
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Peter Antoine <[email protected]>
+ */
+
+/*
+ * Testcase: Test the HW_LOCKs for correct support and non-crashing.

This would be a good sentence to use in the IGT_TEST_DESCRIPTION macro, to add a description for the test.

Quoted 58 lines
tests/drm_hw_lock.c new file +58 -0
+ *
+ * This test will check that he hw_locks are only g_supported for drivers that
+ * require that support. If it is not g_supported then the functions all return
+ * the correct error code.
+ *
+ * If g_supported it will check that the functions do not crash when the crash
+ * tests are used, also that one of the tests is a security level escalation
+ * that should be rejected.
+ */
+#include <stdlib.h>
+#include <signal.h>
+#include <sys/ioctl.h>
+#include <drm.h>
+#include "drmtest.h"
+#include "igt_core.h"
+#include "ioctl_wrappers.h"
+
+#ifndef DRM_KERNEL_CONTEXT
+#      define DRM_KERNEL_CONTEXT       (0)
+#endif
+
+#ifndef _DRM_LOCK_HELD
+#      define _DRM_LOCK_HELD   0x80000000U /**< Hardware lock is held */
+#endif
+
+#ifndef _DRM_LOCK_CONT
+#      define _DRM_LOCK_CONT   0x40000000U /**< Hardware lock is contended */
+#endif
+
+static bool    g_sig_fired;
+static bool    g_supported;
+static struct sigaction old_action;
+
+static void sig_term_handler(int value)
+{
+       g_sig_fired = true;
+}
+
+static bool set_term_handler(void)
+{
+       static struct sigaction new_action;
+
+       new_action.sa_handler = sig_term_handler;
+       sigemptyset(&new_action.sa_mask);
+       new_action.sa_flags = 0;
+
+       igt_assert(sigaction(SIGTERM, &new_action, &old_action) == 0);
+
+       if (old_action.sa_handler != SIG_IGN)
+               return true;
+       else
+               return false;
+}
+
+static void restore_term_handler(void)
+{
+       sigaction(SIGTERM, &old_action, NULL);
+}

tests/drm_hw_lock.c line 96

Quoted 10 lines
tests/drm_hw_lock.c new file +10 -0
+
+static void does_lock_crash(int fd)
+{
+       struct drm_lock rubbish;
+       int ret;
+
+       memset(&rubbish, 'A', sizeof(struct drm_lock));
+
+       g_sig_fired = false;
+       igt_assert(set_term_handler());

Since set_term_handler and restore_term_handler are called at the start and end of every subtest, they could be placed in the respective igt_fixture blocks before and after the subtests in igt_main.

Quoted 24 lines
tests/drm_hw_lock.c new file +24 -0
+
+       ret = ioctl(fd, DRM_IOCTL_LOCK, &rubbish);
+
+       igt_assert(ret == -1 && (!g_supported || g_sig_fired));
+       igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+       restore_term_handler();
+}
+
+static void does_unlock_crash(int fd)
+{
+       struct drm_lock rubbish;
+       int ret;
+
+       g_sig_fired = false;
+       igt_assert(set_term_handler());
+
+       memset(&rubbish, 'A', sizeof(struct drm_lock));
+
+       ret = ioctl(fd, DRM_IOCTL_UNLOCK, &rubbish);
+
+       igt_assert(ret == -1 && (!g_supported || g_sig_fired));
+       igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+

tests/drm_hw_lock.c line 130

Quoted 10 lines
tests/drm_hw_lock.c new file +10 -0
+       restore_term_handler();
+}
+
+static void priority_escalation(int fd)
+{
+       struct drm_lock rubbish;
+       int ret;
+
+       g_sig_fired = false;
+       igt_assert(set_term_handler());

g_sig_fired is not checked in these tests, so presumably it doesn't need to be set before each test?

Quoted 45 lines
tests/drm_hw_lock.c new file +45 -0
+
+       /* this should be rejected */
+       rubbish.context = DRM_KERNEL_CONTEXT;
+       ret = ioctl(fd, DRM_IOCTL_LOCK, &rubbish);
+       igt_assert(ret == -1 && (!g_supported || errno == EPERM));
+       igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+       /* this should also be rejected */
+       rubbish.context = _DRM_LOCK_HELD | DRM_KERNEL_CONTEXT;
+       g_sig_fired = false;
+       ret = ioctl(fd, DRM_IOCTL_LOCK, &rubbish);
+       igt_assert(ret == -1 && (!g_supported || errno == EPERM));
+       igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+       /* this should also be rejected */
+       rubbish.context = _DRM_LOCK_CONT | DRM_KERNEL_CONTEXT;
+       g_sig_fired = false;
+       ret = ioctl(fd, DRM_IOCTL_LOCK, &rubbish);
+       igt_assert(ret == -1 && (!g_supported || errno == EPERM));
+       igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+       /* this should be rejected */
+       rubbish.context = DRM_KERNEL_CONTEXT;
+       g_sig_fired = false;
+       ret = ioctl(fd, DRM_IOCTL_UNLOCK, &rubbish);
+       igt_assert(ret == -1 && (!g_supported || errno == EPERM));
+       igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+       /* this should also be rejected */
+       rubbish.context = _DRM_LOCK_HELD | DRM_KERNEL_CONTEXT;
+       g_sig_fired = false;
+       ret = ioctl(fd, DRM_IOCTL_UNLOCK, &rubbish);
+       igt_assert(ret == -1 && (!g_supported || errno == EPERM));
+       igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+       /* this should also be rejected */
+       rubbish.context = _DRM_LOCK_CONT | DRM_KERNEL_CONTEXT;
+       g_sig_fired = false;
+       ret = ioctl(fd, DRM_IOCTL_UNLOCK, &rubbish);
+       igt_assert(ret == -1 && (!g_supported || errno == EPERM));
+       igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+       restore_term_handler();
+}
+

tests/drm_hw_lock.c line 185

Quoted 10 lines
tests/drm_hw_lock.c new file +10 -0
+igt_main
+{
+       int fd = -1;
+
+       g_sig_fired = false;
+       g_supported = false;
+
+       igt_fixture {
+               fd = drm_open_any();
+               igt_assert(fd >= 0);

drm_open_any will always return a valid file descriptor. If no device is found, it will call igt_skip.

tests/drm_hw_lock.c line 188

Quoted 3 lines
tests/drm_hw_lock.c new file +3 -0
+       }
+
+       g_supported = drm_has_legacy_context(fd);

This needs to be inside the igt_fixture block above, otherwise it may interfere with subtest enumeration.

Quoted 22 lines
tests/drm_hw_lock.c new file +19 -1
+
+       igt_info("HW LOCK Supported: %s\n", g_supported?"Yes":"No");
+
+       igt_subtest("lock-crash") {
+               does_lock_crash(fd);
+       }
+
+       igt_subtest("unlock-crash") {
+               does_unlock_crash(fd);
+       }
+
+       igt_subtest("priority-escalation") {
+               priority_escalation(fd);
+       }
+
+       igt_fixture
+               close(fd);
+}
+
--

1.9.1

Quoted 4 lines

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#2 lore raw
Quoted 34 lines · Thomas Wood
Quoted 25 lines · Peter Antoine

There are several issues with the hardware locks functions that stretch from kernel crashes to priority escalations. This new test will test the the fixes for these features.

This test will cause a driver/kernel crash on un-patched kernels, the following patches should be applied to stop the crashes:

drm: Kernel Crash in drm_unlock
drm: Fixes unsafe deference in locks.

Issue: VIZ-5485

---
 lib/ioctl_wrappers.c   |  19 +++++
 lib/ioctl_wrappers.h   |   1 +
 tests/Makefile.sources |   1 +
 tests/drm_hw_lock.c    | 207 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 228 insertions(+)
 create mode 100644 tests/drm_hw_lock.c
lib/ioctl_wrappers.c +0 -0
index 000d394..ad8b3d3 100644

lib/ioctl_wrappers.c bool gem_has_bsd2(int fd) · line 967

Quoted 4 lines
lib/ioctl_wrappers.c +1 -0
@@ -964,6 +964,25 @@ bool gem_has_bsd2(int fd)
 {
        return gem_has_enable_ring(fd,LOCAL_I915_PARAM_HAS_BSD2);
 }
+#define I915_PARAM_HAS_LEGACY_CONTEXT   35

Please add some API documentation for this new function here.

Quoted 15 lines
Quoted 5 lines
lib/ioctl_wrappers.c +5 -0
+bool drm_has_legacy_context(int fd)
+{
+       int tmp = 0;
+       drm_i915_getparam_t gp;
+

lib/ioctl_wrappers.c bool gem_has_bsd2(int fd) · line 982

Quoted 10 lines
lib/ioctl_wrappers.c +10 -0
+       memset(&gp, 0, sizeof(gp));
+       gp.value = &tmp;
+       gp.param = I915_PARAM_HAS_LEGACY_CONTEXT;
+
+       /*
+        * if legacy context param is not supported, then it's old and we
+        * can assume that the HW_LOCKS are supported.
+        */
+       if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp) != 0)
+               return true;

Would not a simpler test be to try and legally acquire a hwlock? If it fails, hwlocks are not supported. No need for a PARAM. -Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw
Quoted 46 lines · Chris Wilson
Quoted 45 lines · Thomas Wood
Quoted 25 lines · Peter Antoine

There are several issues with the hardware locks functions that stretch from kernel crashes to priority escalations. This new test will test the the fixes for these features.

This test will cause a driver/kernel crash on un-patched kernels, the following patches should be applied to stop the crashes:

drm: Kernel Crash in drm_unlock
drm: Fixes unsafe deference in locks.

Issue: VIZ-5485

---
 lib/ioctl_wrappers.c   |  19 +++++
 lib/ioctl_wrappers.h   |   1 +
 tests/Makefile.sources |   1 +
 tests/drm_hw_lock.c    | 207 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 228 insertions(+)
 create mode 100644 tests/drm_hw_lock.c
lib/ioctl_wrappers.c +0 -0
index 000d394..ad8b3d3 100644

lib/ioctl_wrappers.c bool gem_has_bsd2(int fd) · line 967

Quoted 4 lines
lib/ioctl_wrappers.c +1 -0
@@ -964,6 +964,25 @@ bool gem_has_bsd2(int fd)
 {
        return gem_has_enable_ring(fd,LOCAL_I915_PARAM_HAS_BSD2);
 }
+#define I915_PARAM_HAS_LEGACY_CONTEXT   35

Please add some API documentation for this new function here.

Quoted 11 lines
lib/ioctl_wrappers.c +11 -0
+bool drm_has_legacy_context(int fd)
+{
+       int tmp = 0;
+       drm_i915_getparam_t gp;
+
+       memset(&gp, 0, sizeof(gp));
+       gp.value = &tmp;
+       gp.param = I915_PARAM_HAS_LEGACY_CONTEXT;
+
+       /*
+        * if legacy context param is not supported, then it's old and we
Quoted 9 lines
Quoted 4 lines

lib/ioctl_wrappers.c bool gem_has_bsd2(int fd) · line 982

Quoted 4 lines
lib/ioctl_wrappers.c +4 -0
+        * can assume that the HW_LOCKS are supported.
+        */
+       if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp) != 0)
+               return true;

Would not a simpler test be to try and legally acquire a hwlock? If it fails, hwlocks are not supported. No need for a PARAM. -Chris

The test relies on the hw_lock not being created (f the HW-LOCKs are supported). If I grab, then delete the lock I might find more problems with this code. :)

As you have to be root to create and delete the hwlock the security issues are minimal as you have root already you don't really need to use these ioctls to harm the system. So as the exposure is minimal, any more fixes on code that is legacy and being turned off seems to be a bit of a time waste.

Also, the PARAM should give legitimate code the opportunity to avoid the problems but avoiding these features completely.

Peter.

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#4 lore raw
Quoted 2 lines · Peter

Also, the PARAM should give legitimate code the opportunity to avoid the problems but avoiding these features completely.

There are no legitimate users.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw
In reply to Antoine, Peter
Quoted 61 lines · Peter
Quoted 46 lines · Chris Wilson
Quoted 45 lines · Thomas Wood
Quoted 25 lines · Peter Antoine

There are several issues with the hardware locks functions that stretch from kernel crashes to priority escalations. This new test will test the the fixes for these features.

This test will cause a driver/kernel crash on un-patched kernels, the following patches should be applied to stop the crashes:

drm: Kernel Crash in drm_unlock
drm: Fixes unsafe deference in locks.

Issue: VIZ-5485

---
 lib/ioctl_wrappers.c   |  19 +++++
 lib/ioctl_wrappers.h   |   1 +
 tests/Makefile.sources |   1 +
 tests/drm_hw_lock.c    | 207 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 228 insertions(+)
 create mode 100644 tests/drm_hw_lock.c
lib/ioctl_wrappers.c +0 -0
index 000d394..ad8b3d3 100644

lib/ioctl_wrappers.c bool gem_has_bsd2(int fd) · line 967

Quoted 4 lines
lib/ioctl_wrappers.c +1 -0
@@ -964,6 +964,25 @@ bool gem_has_bsd2(int fd)
 {
        return gem_has_enable_ring(fd,LOCAL_I915_PARAM_HAS_BSD2);
 }
+#define I915_PARAM_HAS_LEGACY_CONTEXT   35

Please add some API documentation for this new function here.

Quoted 11 lines
lib/ioctl_wrappers.c +11 -0
+bool drm_has_legacy_context(int fd)
+{
+       int tmp = 0;
+       drm_i915_getparam_t gp;
+
+       memset(&gp, 0, sizeof(gp));
+       gp.value = &tmp;
+       gp.param = I915_PARAM_HAS_LEGACY_CONTEXT;
+
+       /*
+        * if legacy context param is not supported, then it's old and we
Quoted 9 lines
Quoted 4 lines

lib/ioctl_wrappers.c bool gem_has_bsd2(int fd) · line 982

Quoted 4 lines
lib/ioctl_wrappers.c +4 -0
+        * can assume that the HW_LOCKS are supported.
+        */
+       if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp) != 0)
+               return true;

Would not a simpler test be to try and legally acquire a hwlock? If it fails, hwlocks are not supported. No need for a PARAM. -Chris

The test relies on the hw_lock not being created (f the HW-LOCKs are supported). If I grab, then delete the lock I might find more problems with this code. :)

Quoted 8 lines

As you have to be root to create and delete the hwlock the security issues are minimal as you have root already you don't really need to use these ioctls to harm the system. So as the exposure is minimal, any more fixes on code that is legacy and being turned off seems to be a bit of a time waste.

Also, the PARAM should give legitimate code the opportunity to avoid the problems but avoiding these features completely.

root != kernel, at least in secure boot enviroments. Which means not even root is allowed to crash/exploit the kernel ... Yes there's a pile of .config options and stuff you need to set correctly to fully lock out root from the kernel, but in general drivers really shouldn't have their own root2kernel backdoors.
-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#6 lore raw
In reply to Thomas Wood

Thanks for the review, new patch inbound.

-----Original Message-----
From: Thomas Wood [mailto:[email protected]]
Sent: Monday, April 27, 2015 4:25 PM
To: Antoine, Peter
Cc: Intel Graphics Development; [email protected]; [email protected]; Daniel Vetter
Subject: Re: [Intel-gfx] [PATCH i-g-t] tests/drm_hw_lock: Tests for hw_lock fixes.

Quoted 25 lines · Peter Antoine

There are several issues with the hardware locks functions that stretch from kernel crashes to priority escalations. This new test will test the the fixes for these features.

This test will cause a driver/kernel crash on un-patched kernels, the following patches should be applied to stop the crashes:

drm: Kernel Crash in drm_unlock
drm: Fixes unsafe deference in locks.

Issue: VIZ-5485

---
 lib/ioctl_wrappers.c   |  19 +++++
 lib/ioctl_wrappers.h   |   1 +
 tests/Makefile.sources |   1 +
 tests/drm_hw_lock.c    | 207 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 228 insertions(+)
 create mode 100644 tests/drm_hw_lock.c
lib/ioctl_wrappers.c index renamed from lib/ioctl_wrappers.c +0 -0

000d394..ad8b3d3 100644

lib/ioctl_wrappers.c bool gem_has_bsd2(int fd) { · line 966

Quoted 3 lines
lib/ioctl_wrappers.c +1 -0
@@ -964,6 +964,25 @@ bool gem_has_bsd2(int fd)  {
        return gem_has_enable_ring(fd,LOCAL_I915_PARAM_HAS_BSD2);
 }
+#define I915_PARAM_HAS_LEGACY_CONTEXT   35

Please add some API documentation for this new function here.

Quoted 35 lines
lib/ioctl_wrappers.c +18 -0
+bool drm_has_legacy_context(int fd)
+{
+       int tmp = 0;
+       drm_i915_getparam_t gp;
+
+       memset(&gp, 0, sizeof(gp));
+       gp.value = &tmp;
+       gp.param = I915_PARAM_HAS_LEGACY_CONTEXT;
+
+       /*
+        * if legacy context param is not supported, then it's old and we
+        * can assume that the HW_LOCKS are supported.
+        */
+       if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp) != 0)
+               return true;
+
+       return tmp == 1;
+}
 /**
  * gem_available_aperture_size:
  * @fd: open i915 drm file descriptor diff --git 

a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h index ced7ef3..3adc700 100644

lib/ioctl_wrappers.h +1 -0
@@ -120,6 +120,7 @@ bool gem_has_bsd(int fd);  bool gem_has_blt(int 
 fd);  bool gem_has_vebox(int fd);  bool gem_has_bsd2(int fd);
+bool drm_has_legacy_context(int fd);
 bool gem_uses_aliasing_ppgtt(int fd);  int gem_available_fences(int 

fd); uint64_t gem_available_aperture_size(int fd); diff --git a/tests/Makefile.sources b/tests/Makefile.sources index 71de6de..2f69afc 100644

tests/Makefile.sources TESTS_progs_M = \ · line 87

Quoted 4 lines
tests/Makefile.sources +1 -0
@@ -84,6 +84,7 @@ TESTS_progs_M = \
        pm_sseu \
        prime_self_import \
        template \
+       drm_hw_lock \

Please also add the binary name to .gitignore.

Quoted 39 lines
tests/Makefile.sources +0 -0
        $(NULL)
 
 TESTS_progs = \
tests/drm_hw_lock.c new file mode renamed from tests/drm_hw_lock.c +0 -0

100644 index 0000000..aad50ba

tests/drm_hw_lock.c new file +31 -0
@@ -0,0 +1,207 @@
+/*
+ * Copyright © 2015 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person 
+obtaining a
+ * copy of this software and associated documentation files (the 
+"Software"),
+ * to deal in the Software without restriction, including without 
+limitation
+ * the rights to use, copy, modify, merge, publish, distribute, 
+sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom 
+the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including 
+the next
+ * paragraph) shall be included in all copies or substantial portions 
+of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
+EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
+MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT 
+SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 
+OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
+ARISING

tests/drm_hw_lock.c line 41

Quoted 10 lines
tests/drm_hw_lock.c new file +10 -0
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
+OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Peter Antoine <[email protected]>
+ */
+
+/*
+ * Testcase: Test the HW_LOCKs for correct support and non-crashing.

This would be a good sentence to use in the IGT_TEST_DESCRIPTION macro, to add a description for the test.

Quoted 59 lines
tests/drm_hw_lock.c new file +59 -0
+ *
+ * This test will check that he hw_locks are only g_supported for 
+drivers that
+ * require that support. If it is not g_supported then the functions 
+all return
+ * the correct error code.
+ *
+ * If g_supported it will check that the functions do not crash when 
+the crash
+ * tests are used, also that one of the tests is a security level 
+escalation
+ * that should be rejected.
+ */
+#include <stdlib.h>
+#include <signal.h>
+#include <sys/ioctl.h>
+#include <drm.h>
+#include "drmtest.h"
+#include "igt_core.h"
+#include "ioctl_wrappers.h"
+
+#ifndef DRM_KERNEL_CONTEXT
+#      define DRM_KERNEL_CONTEXT       (0)
+#endif
+
+#ifndef _DRM_LOCK_HELD
+#      define _DRM_LOCK_HELD   0x80000000U /**< Hardware lock is held */
+#endif
+
+#ifndef _DRM_LOCK_CONT
+#      define _DRM_LOCK_CONT   0x40000000U /**< Hardware lock is contended */
+#endif
+
+static bool    g_sig_fired;
+static bool    g_supported;
+static struct sigaction old_action;
+
+static void sig_term_handler(int value) {
+       g_sig_fired = true;
+}
+
+static bool set_term_handler(void)
+{
+       static struct sigaction new_action;
+
+       new_action.sa_handler = sig_term_handler;
+       sigemptyset(&new_action.sa_mask);
+       new_action.sa_flags = 0;
+
+       igt_assert(sigaction(SIGTERM, &new_action, &old_action) == 0);
+
+       if (old_action.sa_handler != SIG_IGN)
+               return true;
+       else
+               return false;
+}
+
+static void restore_term_handler(void) {
+       sigaction(SIGTERM, &old_action, NULL); }

tests/drm_hw_lock.c line 96

Quoted 10 lines
tests/drm_hw_lock.c new file +10 -0
+
+static void does_lock_crash(int fd)
+{
+       struct drm_lock rubbish;
+       int ret;
+
+       memset(&rubbish, 'A', sizeof(struct drm_lock));
+
+       g_sig_fired = false;
+       igt_assert(set_term_handler());

Since set_term_handler and restore_term_handler are called at the start and end of every subtest, they could be placed in the respective igt_fixture blocks before and after the subtests in igt_main.

Quoted 22 lines
tests/drm_hw_lock.c new file +22 -0
+
+       ret = ioctl(fd, DRM_IOCTL_LOCK, &rubbish);
+
+       igt_assert(ret == -1 && (!g_supported || g_sig_fired));
+       igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+       restore_term_handler();
+}
+
+static void does_unlock_crash(int fd) {
+       struct drm_lock rubbish;
+       int ret;
+
+       g_sig_fired = false;
+       igt_assert(set_term_handler());
+
+       memset(&rubbish, 'A', sizeof(struct drm_lock));
+
+       ret = ioctl(fd, DRM_IOCTL_UNLOCK, &rubbish);
+
+       igt_assert(ret == -1 && (!g_supported || g_sig_fired));
+       igt_assert(ret == -1 && (g_supported || errno == EINVAL));

tests/drm_hw_lock.c line 130

Quoted 10 lines
tests/drm_hw_lock.c new file +10 -0
+
+       restore_term_handler();
+}
+
+static void priority_escalation(int fd) {
+       struct drm_lock rubbish;
+       int ret;
+
+       g_sig_fired = false;
+       igt_assert(set_term_handler());

g_sig_fired is not checked in these tests, so presumably it doesn't need to be set before each test?

Quoted 45 lines
tests/drm_hw_lock.c new file +45 -0
+
+       /* this should be rejected */
+       rubbish.context = DRM_KERNEL_CONTEXT;
+       ret = ioctl(fd, DRM_IOCTL_LOCK, &rubbish);
+       igt_assert(ret == -1 && (!g_supported || errno == EPERM));
+       igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+       /* this should also be rejected */
+       rubbish.context = _DRM_LOCK_HELD | DRM_KERNEL_CONTEXT;
+       g_sig_fired = false;
+       ret = ioctl(fd, DRM_IOCTL_LOCK, &rubbish);
+       igt_assert(ret == -1 && (!g_supported || errno == EPERM));
+       igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+       /* this should also be rejected */
+       rubbish.context = _DRM_LOCK_CONT | DRM_KERNEL_CONTEXT;
+       g_sig_fired = false;
+       ret = ioctl(fd, DRM_IOCTL_LOCK, &rubbish);
+       igt_assert(ret == -1 && (!g_supported || errno == EPERM));
+       igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+       /* this should be rejected */
+       rubbish.context = DRM_KERNEL_CONTEXT;
+       g_sig_fired = false;
+       ret = ioctl(fd, DRM_IOCTL_UNLOCK, &rubbish);
+       igt_assert(ret == -1 && (!g_supported || errno == EPERM));
+       igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+       /* this should also be rejected */
+       rubbish.context = _DRM_LOCK_HELD | DRM_KERNEL_CONTEXT;
+       g_sig_fired = false;
+       ret = ioctl(fd, DRM_IOCTL_UNLOCK, &rubbish);
+       igt_assert(ret == -1 && (!g_supported || errno == EPERM));
+       igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+       /* this should also be rejected */
+       rubbish.context = _DRM_LOCK_CONT | DRM_KERNEL_CONTEXT;
+       g_sig_fired = false;
+       ret = ioctl(fd, DRM_IOCTL_UNLOCK, &rubbish);
+       igt_assert(ret == -1 && (!g_supported || errno == EPERM));
+       igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+       restore_term_handler();
+}
+

tests/drm_hw_lock.c line 185

Quoted 10 lines
tests/drm_hw_lock.c new file +10 -0
+igt_main
+{
+       int fd = -1;
+
+       g_sig_fired = false;
+       g_supported = false;
+
+       igt_fixture {
+               fd = drm_open_any();
+               igt_assert(fd >= 0);

drm_open_any will always return a valid file descriptor. If no device is found, it will call igt_skip.

tests/drm_hw_lock.c line 188

Quoted 3 lines
tests/drm_hw_lock.c new file +3 -0
+       }
+
+       g_supported = drm_has_legacy_context(fd);

This needs to be inside the igt_fixture block above, otherwise it may interfere with subtest enumeration.

Quoted 22 lines
tests/drm_hw_lock.c new file +19 -1
+
+       igt_info("HW LOCK Supported: %s\n", g_supported?"Yes":"No");
+
+       igt_subtest("lock-crash") {
+               does_lock_crash(fd);
+       }
+
+       igt_subtest("unlock-crash") {
+               does_unlock_crash(fd);
+       }
+
+       igt_subtest("priority-escalation") {
+               priority_escalation(fd);
+       }
+
+       igt_fixture
+               close(fd);
+}
+
--

1.9.1

Quoted 4 lines

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#7 lore raw

PATCH v2 1/1 tests/drm_hw_lock: Tests for hw_lock fixes.

In reply to Peter Antoine

There are several issues with the hardware locks functions that stretch from kernel crashes to priority escalations. This new test will test the the fixes for these features.

This test will cause a driver/kernel crash on un-patched kernels, the following patches should be applied to stop the crashes:

drm: Kernel Crash in drm_unlock
drm: Fixes unsafe deference in locks.

v2:
- add API documentation for drm_has_legacy_context (T.Wood)
- update tests/.gitignore (T.Wood)
- add IGT_TEST_DESCRIPTION (T.Wood)
- changes to igt_fixtures (T.Wood)

Issue: VIZ-5485

---
 lib/ioctl_wrappers.c   |  30 ++++++++
 lib/ioctl_wrappers.h   |   1 +
 tests/.gitignore       |   1 +
 tests/Makefile.sources |   1 +
 tests/drm_hw_lock.c    | 193 +++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 226 insertions(+)
 create mode 100644 tests/drm_hw_lock.c
lib/ioctl_wrappers.c +30 -0
index 000d394..e0bef8d 100644
@@ -964,6 +964,36 @@ bool gem_has_bsd2(int fd)
 {
 	return gem_has_enable_ring(fd,LOCAL_I915_PARAM_HAS_BSD2);
 }
+
+#define I915_PARAM_HAS_LEGACY_CONTEXT	 35
+/**
+ * drm_has_legacy_context:
+ * @fd: open i915 drm file descriptor
+ *
+ * This helper function checks to see if the LEGACY CONTEXT functionality is
+ * supported by the driver. This feature is compiled in and cannot be changed
+ * at run time so only needs checking once.
+ *
+ * Returns: true if the legacy context is support, else false.
+ */
+bool drm_has_legacy_context(int fd)
+{
+	int tmp = 0;
+	drm_i915_getparam_t gp;
+
+	memset(&gp, 0, sizeof(gp));
+	gp.value = &tmp;
+	gp.param = I915_PARAM_HAS_LEGACY_CONTEXT;
+
+	/*
+	 * if legacy context param is not supported, then it's old and we
+	 * can assume that the HW_LOCKS are supported.
+	 */
+	if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp) != 0)
+		return true;
+
+	return tmp == 1;
+}
 /**
  * gem_available_aperture_size:
  * @fd: open i915 drm file descriptor
lib/ioctl_wrappers.h +1 -0
index ced7ef3..3adc700 100644
@@ -120,6 +120,7 @@ bool gem_has_bsd(int fd);
 bool gem_has_blt(int fd);
 bool gem_has_vebox(int fd);
 bool gem_has_bsd2(int fd);
+bool drm_has_legacy_context(int fd);
 bool gem_uses_aliasing_ppgtt(int fd);
 int gem_available_fences(int fd);
 uint64_t gem_available_aperture_size(int fd);
tests/.gitignore +1 -0
index 54caa4c..b93ced8 100644
@@ -160,3 +160,4 @@ prime_udl
 single-tests.txt
 template
 testdisplay
+drm_hw_lock
tests/Makefile.sources +1 -0
index 71de6de..2f69afc 100644
@@ -84,6 +84,7 @@ TESTS_progs_M = \
 	pm_sseu \
 	prime_self_import \
 	template \
+	drm_hw_lock \
 	$(NULL)
 
 TESTS_progs = \
tests/drm_hw_lock.c new file +193 -0

193 lines not on this page · raw message

Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#8 lore raw
In reply to Peter Antoine

Please ignore this test as fixes are being implemented differently.

Quoted 277 lines · Peter Antoine

There are several issues with the hardware locks functions that stretch from kernel crashes to priority escalations. This new test will test the the fixes for these features.

This test will cause a driver/kernel crash on un-patched kernels, the following patches should be applied to stop the crashes:

drm: Kernel Crash in drm_unlock
drm: Fixes unsafe deference in locks.

Issue: VIZ-5485

---
 lib/ioctl_wrappers.c   |  19 +++++
 lib/ioctl_wrappers.h   |   1 +
 tests/Makefile.sources |   1 +
 tests/drm_hw_lock.c    | 207 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 228 insertions(+)
 create mode 100644 tests/drm_hw_lock.c
lib/ioctl_wrappers.c +19 -0
index 000d394..ad8b3d3 100644
@@ -964,6 +964,25 @@ bool gem_has_bsd2(int fd)
 {
 	return gem_has_enable_ring(fd,LOCAL_I915_PARAM_HAS_BSD2);
 }
+#define I915_PARAM_HAS_LEGACY_CONTEXT	 35
+bool drm_has_legacy_context(int fd)
+{
+	int tmp = 0;
+	drm_i915_getparam_t gp;
+
+	memset(&gp, 0, sizeof(gp));
+	gp.value = &tmp;
+	gp.param = I915_PARAM_HAS_LEGACY_CONTEXT;
+
+	/*
+	 * if legacy context param is not supported, then it's old and we
+	 * can assume that the HW_LOCKS are supported.
+	 */
+	if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp) != 0)
+		return true;
+
+	return tmp == 1;
+}
 /**
  * gem_available_aperture_size:
  * @fd: open i915 drm file descriptor
lib/ioctl_wrappers.h +1 -0
index ced7ef3..3adc700 100644
@@ -120,6 +120,7 @@ bool gem_has_bsd(int fd);
 bool gem_has_blt(int fd);
 bool gem_has_vebox(int fd);
 bool gem_has_bsd2(int fd);
+bool drm_has_legacy_context(int fd);
 bool gem_uses_aliasing_ppgtt(int fd);
 int gem_available_fences(int fd);
 uint64_t gem_available_aperture_size(int fd);
tests/Makefile.sources +1 -0
index 71de6de..2f69afc 100644
@@ -84,6 +84,7 @@ TESTS_progs_M = \
 	pm_sseu \
 	prime_self_import \
 	template \
+	drm_hw_lock \
 	$(NULL)
 
 TESTS_progs = \
tests/drm_hw_lock.c new file +197 -0
new file mode 100644
index 0000000..aad50ba
@@ -0,0 +1,207 @@
+/*
+ * Copyright © 2015 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Peter Antoine <[email protected]>
+ */
+
+/*
+ * Testcase: Test the HW_LOCKs for correct support and non-crashing.
+ *
+ * This test will check that he hw_locks are only g_supported for drivers that
+ * require that support. If it is not g_supported then the functions all return
+ * the correct error code.
+ *
+ * If g_supported it will check that the functions do not crash when the crash
+ * tests are used, also that one of the tests is a security level escalation
+ * that should be rejected.
+ */
+#include <stdlib.h>
+#include <signal.h>
+#include <sys/ioctl.h>
+#include <drm.h>
+#include "drmtest.h"
+#include "igt_core.h"
+#include "ioctl_wrappers.h"
+
+#ifndef DRM_KERNEL_CONTEXT
+#	define DRM_KERNEL_CONTEXT	(0)
+#endif
+
+#ifndef _DRM_LOCK_HELD
+#	define _DRM_LOCK_HELD	0x80000000U /**< Hardware lock is held */
+#endif
+
+#ifndef _DRM_LOCK_CONT
+#	define _DRM_LOCK_CONT	0x40000000U /**< Hardware lock is contended */
+#endif
+
+static bool	g_sig_fired;
+static bool	g_supported;
+static struct sigaction old_action;
+
+static void sig_term_handler(int value)
+{
+	g_sig_fired = true;
+}
+
+static bool set_term_handler(void)
+{
+	static struct sigaction new_action;
+
+	new_action.sa_handler = sig_term_handler;
+	sigemptyset(&new_action.sa_mask);
+	new_action.sa_flags = 0;
+
+	igt_assert(sigaction(SIGTERM, &new_action, &old_action) == 0);
+
+	if (old_action.sa_handler != SIG_IGN)
+		return true;
+	else
+		return false;
+}
+
+static void restore_term_handler(void)
+{
+	sigaction(SIGTERM, &old_action, NULL);
+}
+
+static void does_lock_crash(int fd)
+{
+	struct drm_lock	rubbish;
+	int ret;
+
+	memset(&rubbish, 'A', sizeof(struct drm_lock));
+
+	g_sig_fired = false;
+	igt_assert(set_term_handler());
+
+	ret = ioctl(fd, DRM_IOCTL_LOCK, &rubbish);
+
+	igt_assert(ret == -1 && (!g_supported || g_sig_fired));
+	igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+	restore_term_handler();
+}
+
+static void does_unlock_crash(int fd)
+{
+	struct drm_lock	rubbish;
+	int ret;
+
+	g_sig_fired = false;
+	igt_assert(set_term_handler());
+
+	memset(&rubbish, 'A', sizeof(struct drm_lock));
+
+	ret = ioctl(fd, DRM_IOCTL_UNLOCK, &rubbish);
+
+	igt_assert(ret == -1 && (!g_supported || g_sig_fired));
+	igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+	restore_term_handler();
+}
+
+static void priority_escalation(int fd)
+{
+	struct drm_lock	rubbish;
+	int ret;
+
+	g_sig_fired = false;
+	igt_assert(set_term_handler());
+
+	/* this should be rejected */
+	rubbish.context = DRM_KERNEL_CONTEXT;
+	ret = ioctl(fd, DRM_IOCTL_LOCK, &rubbish);
+	igt_assert(ret == -1 && (!g_supported || errno == EPERM));
+	igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+	/* this should also be rejected */
+	rubbish.context = _DRM_LOCK_HELD | DRM_KERNEL_CONTEXT;
+	g_sig_fired = false;
+	ret = ioctl(fd, DRM_IOCTL_LOCK, &rubbish);
+	igt_assert(ret == -1 && (!g_supported || errno == EPERM));
+	igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+	/* this should also be rejected */
+	rubbish.context = _DRM_LOCK_CONT | DRM_KERNEL_CONTEXT;
+	g_sig_fired = false;
+	ret = ioctl(fd, DRM_IOCTL_LOCK, &rubbish);
+	igt_assert(ret == -1 && (!g_supported || errno == EPERM));
+	igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+	/* this should be rejected */
+	rubbish.context = DRM_KERNEL_CONTEXT;
+	g_sig_fired = false;
+	ret = ioctl(fd, DRM_IOCTL_UNLOCK, &rubbish);
+	igt_assert(ret == -1 && (!g_supported || errno == EPERM));
+	igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+	/* this should also be rejected */
+	rubbish.context = _DRM_LOCK_HELD | DRM_KERNEL_CONTEXT;
+	g_sig_fired = false;
+	ret = ioctl(fd, DRM_IOCTL_UNLOCK, &rubbish);
+	igt_assert(ret == -1 && (!g_supported || errno == EPERM));
+	igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+	/* this should also be rejected */
+	rubbish.context = _DRM_LOCK_CONT | DRM_KERNEL_CONTEXT;
+	g_sig_fired = false;
+	ret = ioctl(fd, DRM_IOCTL_UNLOCK, &rubbish);
+	igt_assert(ret == -1 && (!g_supported || errno == EPERM));
+	igt_assert(ret == -1 && (g_supported || errno == EINVAL));
+
+	restore_term_handler();
+}
+
+igt_main
+{
+	int fd = -1;
+
+	g_sig_fired = false;
+	g_supported = false;
+
+	igt_fixture {
+		fd = drm_open_any();
+		igt_assert(fd >= 0);
+	}
+
+	g_supported = drm_has_legacy_context(fd);
+
+	igt_info("HW LOCK Supported: %s\n", g_supported?"Yes":"No");
+
+	igt_subtest("lock-crash") {
+		does_lock_crash(fd);
+	}
+
+	igt_subtest("unlock-crash") {
+		does_unlock_crash(fd);

tests/drm_hw_lock.c line 207

Quoted 10 lines
tests/drm_hw_lock.c new file +10 -0
+	}
+
+	igt_subtest("priority-escalation") {
+		priority_escalation(fd);
+	}
+
+	igt_fixture
+		close(fd);
+}
+

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx