tests/gem_reset_stats: add support for BDW+
PATCH 1/3 tests/gem_reset_stats: add support for BDW+
For BDW+, there BATCH_BUFFER_START is 3 * 32bits in length and length needs to be encoded into the opcode.
Suggested-by Damien Lespiau <[email protected]>
Signed-off-by Mika Kuoppala <[email protected]>
--- tests/gem_reset_stats.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
tests/gem_reset_stats.c +9 -3
@@ -202,9 +202,13 @@ static int inject_hang(int fd, int ctx)uint64_t gtt_off;uint32_t *buf;int roff, i; +unsigned cmd_len =2 ;srandom (time (NULL )); +if (intel_gen (intel_get_drm_devid (fd)) >=8 ) + cmd_len =3 ; + buf =malloc (BUFSIZE );igt_assert (buf !=NULL );
@@ -240,9 +244,11 @@ static int inject_hang(int fd, int ctx)for (i =0 ; i <ITEMS ; i++) buf[i] =MI_NOOP ; - roff =random () % (ITEMS -2 ); - buf[roff] =MI_BATCH_BUFFER_START ; - buf[roff +1 ] = gtt_off + (roff <<2 ); + roff =random () % (ITEMS - cmd_len); + buf[roff] =MI_BATCH_BUFFER_START | (cmd_len -2 ); + buf[roff +1 ] = (gtt_off &0xfffffffc ) + (roff <<2 ); +if (cmd_len ==3 ) + buf[roff +2 ] = gtt_off &0xffffffff00000000ull ;#ifdef VERBOSE printf("loop injected at 0x%lx (off 0x%x, bo_start 0x%lx, bo_end 0x%lx)\n",
Signature · 1 line
1.7.9.5
PATCH 2/3 tests/gem_reset_stats: stop rings after injecting hang
To make driver report a simulated hang in dmesg.
Suggested-by Daniel Vetter <[email protected]>
Signed-off-by Mika Kuoppala <[email protected]>
--- tests/gem_reset_stats.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
tests/gem_reset_stats.c +18 -0
@@ -42,6 +42,7 @@#include "intel_batchbuffer.h" #include "intel_gpu_tools.h" #include "rendercopy.h" +#include "igt_debugfs.h" #define RS_NO_ERROR 0#define RS_BATCH_ACTIVE (1 << 0)
@@ -73,6 +74,8 @@ struct local_drm_i915_gem_context_destroy {#define CONTEXT_DESTROY_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x2e, struct local_drm_i915_gem_context_destroy)#define GET_RESET_STATS_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x32, struct local_drm_i915_reset_stats) +static igt_debugfs_t dfs; +static uint32_t context_create (int fd) {struct local_drm_i915_gem_context_create create;
@@ -192,6 +195,17 @@ static int exec_valid(int fd, int ctx)return exec.handle; } +static void stop_rings (void ) +{ +int fd; + + fd =igt_debugfs_open (&dfs,"i915_ring_stop" ,O_WRONLY ); +igt_assert (fd >=0 ); + +igt_assert (write (fd,"0xff" ,4 ) ==4 ); +close (fd); +} +#define BUFSIZE (4 * 1024)#define ITEMS (BUFSIZE >> 2)
@@ -284,6 +298,8 @@ static int inject_hang(int fd, int ctx)free (buf); +stop_rings (); +return exec.handle; }
@@ -743,6 +759,8 @@ igt_mainigt_skip ("Kernel is too old, or contexts not supported: %s\n" ,strerror (errno)); +assert (igt_debugfs_init (&dfs) ==0 ); +close (fd); }
Signature · 1 line
1.7.9.5
PATCH 3/3 tests/gem_reset_stats: check non root access to reset_stats
In reply to Mika KuoppalaGetting global reset count needs to be tested with root and non root access.
Signed-off-by Mika Kuoppala <[email protected]>
--- tests/gem_reset_stats.c | 70 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 9 deletions(-)
tests/gem_reset_stats.c +61 -9
@@ -637,6 +637,17 @@ static void test_close_pending(void)close (fd); } +static void drop_root (void ) +{ +igt_assert (getuid () ==0 ); + +igt_assert (setgid (2 ) ==0 ); +igt_assert (setuid (2 ) ==0 ); + +igt_assert (getgid () ==2 ); +igt_assert (getuid () ==2 ); +} +static void __test_count (const bool create_ctx) {int fd, h, ctx;
@@ -661,9 +672,21 @@ static void __test_count(const bool create_ctx)assert_reset_status (fd, ctx,RS_BATCH_ACTIVE ); c2 =get_reset_count (fd, ctx);igt_assert (c2 >=0 ); -igt_assert (c2 == (c1 +1 )); + igt_fork(child, 1) { +drop_root (); + + c2 =get_reset_count (fd, ctx); + +if (ctx ==0 ) +igt_assert (c2 == -EPERM ); +else +igt_assert (c2 ==0 ); + } + +igt_waitchildren (); +gem_close (fd, h);if (create_ctx)
@@ -710,16 +733,50 @@ static int _test_params(int fd, int ctx, uint32_t flags, uint32_t pad)return 0 ; } -static void test_param_ctx (int fd,int ctx) +typedef enum { root =0 , user }cap_t ; + +static void test_param_ctx (const int fd,const int ctx,const cap_t cap) {const uint32_t bad =rand () +1 ; -igt_assert (_test_params (fd, ctx,0 ,0 ) ==0 ); +if (ctx ==0 ) { +if (cap == root) +igt_assert (_test_params (fd, ctx,0 ,0 ) ==0 ); +else +igt_assert (_test_params (fd, ctx,0 ,0 ) == -EPERM ); + } +igt_assert (_test_params (fd, ctx,0 , bad) == -EINVAL );igt_assert (_test_params (fd, ctx, bad,0 ) == -EINVAL );igt_assert (_test_params (fd, ctx, bad, bad) == -EINVAL ); } +static void check_params (const int fd,const int ctx,cap_t cap) +{ +igt_assert (ioctl (fd,GET_RESET_STATS_IOCTL ,0 ) ==-1 ); +igt_assert (_test_params (fd,0xbadbad ,0 ,0 ) == -ENOENT ); + +test_param_ctx (fd,0 , cap); +test_param_ctx (fd, ctx, cap); +} + +static void _test_param (const int fd,const int ctx) +{ +check_params (fd, ctx, root); + + igt_fork(child, 1) { +check_params (fd, ctx, root); + +drop_root (); + +check_params (fd, ctx, user); + } + +check_params (fd, ctx, root); + +igt_waitchildren (); +} +static void test_params (void ) {int fd, ctx;
@@ -728,12 +785,7 @@ static void test_params(void)igt_assert (fd >=0 ); ctx =context_create (fd); -igt_assert (ioctl (fd,GET_RESET_STATS_IOCTL ,0 ) ==-1 ); - -igt_assert (_test_params (fd,0xbadbad ,0 ,0 ) == -ENOENT ); - -test_param_ctx (fd,0 ); -test_param_ctx (fd, ctx); +_test_param (fd, ctx);close (fd); }
Signature · 1 line
1.7.9.5
Re: [PATCH 3/3] tests/gem_reset_stats: check non root access to reset_stats
Quoted 4 lines · Mika Kuoppala
Getting global reset count needs to be tested with root and non root access.
Signed-off-by Mika Kuoppala <[email protected]>
All merged to igt, thanks for the patches.
-Daniel
Quoted 123 lines
--- tests/gem_reset_stats.c | 70 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 9 deletions(-)tests/gem_reset_stats.c +61
-9@@ -637,6 +637,17 @@ static void test_close_pending(void)close (fd); } +static void drop_root (void ) +{ +igt_assert (getuid () ==0 ); + +igt_assert (setgid (2 ) ==0 ); +igt_assert (setuid (2 ) ==0 ); + +igt_assert (getgid () ==2 ); +igt_assert (getuid () ==2 ); +} +static void __test_count (const bool create_ctx) {int fd, h, ctx;@@ -661,9 +672,21 @@ static void __test_count(const bool create_ctx)assert_reset_status (fd, ctx,RS_BATCH_ACTIVE ); c2 =get_reset_count (fd, ctx);igt_assert (c2 >=0 ); -igt_assert (c2 == (c1 +1 )); + igt_fork(child, 1) { +drop_root (); + + c2 =get_reset_count (fd, ctx); + +if (ctx ==0 ) +igt_assert (c2 == -EPERM ); +else +igt_assert (c2 ==0 ); + } + +igt_waitchildren (); +gem_close (fd, h);if (create_ctx)@@ -710,16 +733,50 @@ static int _test_params(int fd, int ctx, uint32_t flags, uint32_t pad)return 0 ; } -static void test_param_ctx (int fd,int ctx) +typedef enum { root =0 , user }cap_t ; + +static void test_param_ctx (const int fd,const int ctx,const cap_t cap) {const uint32_t bad =rand () +1 ; -igt_assert (_test_params (fd, ctx,0 ,0 ) ==0 ); +if (ctx ==0 ) { +if (cap == root) +igt_assert (_test_params (fd, ctx,0 ,0 ) ==0 ); +else +igt_assert (_test_params (fd, ctx,0 ,0 ) == -EPERM ); + } +igt_assert (_test_params (fd, ctx,0 , bad) == -EINVAL );igt_assert (_test_params (fd, ctx, bad,0 ) == -EINVAL );igt_assert (_test_params (fd, ctx, bad, bad) == -EINVAL ); } +static void check_params (const int fd,const int ctx,cap_t cap) +{ +igt_assert (ioctl (fd,GET_RESET_STATS_IOCTL ,0 ) ==-1 ); +igt_assert (_test_params (fd,0xbadbad ,0 ,0 ) == -ENOENT ); + +test_param_ctx (fd,0 , cap); +test_param_ctx (fd, ctx, cap); +} + +static void _test_param (const int fd,const int ctx) +{ +check_params (fd, ctx, root); + + igt_fork(child, 1) { +check_params (fd, ctx, root); + +drop_root (); + +check_params (fd, ctx, user); + } + +check_params (fd, ctx, root); + +igt_waitchildren (); +} +static void test_params (void ) {int fd, ctx;@@ -728,12 +785,7 @@ static void test_params(void)igt_assert (fd >=0 ); ctx =context_create (fd); -igt_assert (ioctl (fd,GET_RESET_STATS_IOCTL ,0 ) ==-1 ); - -igt_assert (_test_params (fd,0xbadbad ,0 ,0 ) == -ENOENT ); - -test_param_ctx (fd,0 ); -test_param_ctx (fd, ctx); +_test_param (fd, ctx);close (fd); }Signature · 6 lines
1.7.9.5 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch