lib: Move __gem_context_create to common ioctl wrapper library.
PATCH v2 1/2 lib: Move __gem_context_create to common ioctl wrapper library.
This patch adds a context creation ioctl wrapper that returns the error for the caller to consume. Multiple tests that implemented this already, have been changed to use the new library function.
v2:
- Add gem_require_contexts() to check for contexts support (Chris)
--- benchmarks/gem_exec_ctx.c | 6 +++--- benchmarks/gem_exec_trace.c | 4 ++-- lib/ioctl_wrappers.c | 46 +++++++++++++++++++++++++++++++++++---------- lib/ioctl_wrappers.h | 2 ++ tests/gem_ctx_create.c | 10 +++++----- tests/gem_ctx_switch.c | 13 ------------- tests/gem_eio.c | 13 +------------ tests/gem_exec_await.c | 14 ++------------ tests/gem_exec_nop.c | 13 ------------- tests/gem_exec_parallel.c | 15 +++------------ tests/gem_exec_reuse.c | 13 ------------- tests/gem_exec_whisper.c | 13 ------------- 12 files changed, 54 insertions(+), 108 deletions(-)
benchmarks/gem_exec_ctx.c +3 -3
@@ -64,7 +64,7 @@ static uint32_t batch(int fd)return handle; } -static uint32_t __gem_context_create (int fd) +static uint32_t __gem_context_create_local (int fd) {struct drm_i915_gem_context_create create;
@@ -101,7 +101,7 @@ static int loop(unsigned ring, execbuf.flags |=LOCAL_I915_EXEC_HANDLE_LUT ; execbuf.flags |=LOCAL_I915_EXEC_NO_RELOC ;if (mode !=DEFAULT ) { - execbuf.rsvd1 =__gem_context_create (fd); + execbuf.rsvd1 =__gem_context_create_local (fd);if (execbuf.rsvd1 ==0 )return 77 ; }
@@ -125,7 +125,7 @@ static int loop(unsigned ring,uint32_t ctx =0 ;if (mode !=DEFAULT && mode !=NOP ) { - execbuf.rsvd1 =__gem_context_create (fd); + execbuf.rsvd1 =__gem_context_create_local (fd); ctx =gem_context_create (fd); }
benchmarks/gem_exec_trace.c +2 -2
@@ -105,7 +105,7 @@ static double elapsed(const struct timespec *start, const struct timespec *end)return 1e3 *(end->tv_sec - start->tv_sec) +1e-6 *(end->tv_nsec - start->tv_nsec); } -static uint32_t __gem_context_create (int fd) +static uint32_t __gem_context_create_local (int fd) {struct drm_i915_gem_context_create arg = {};drmIoctl (fd,DRM_IOCTL_I915_GEM_CONTEXT_CREATE , &arg);
@@ -216,7 +216,7 @@ static double replay(const char *filename, long nop, long range) num_ctx = new_ctx; } - ctx[t->handle] =__gem_context_create (fd); + ctx[t->handle] =__gem_context_create_local (fd);break ; }case DEL_CTX :
lib/ioctl_wrappers.c +36 -10
60 lines not on this page · raw message
lib/ioctl_wrappers.h +2 -0
@@ -119,6 +119,7 @@ int gem_munmap(void *ptr, uint64_t size);int gem_madvise (int fd,uint32_t handle,int state); +int __gem_context_create (int fd,uint32_t *ctx_id);uint32_t gem_context_create (int fd);void gem_context_destroy (int fd,uint32_t ctx_id);int __gem_context_destroy (int fd,uint32_t ctx_id);
@@ -133,6 +134,7 @@ struct local_i915_gem_context_param {#define LOCAL_CONTEXT_PARAM_BANNABLE 0x5uint64_t value; }; +void gem_require_contexts (int fd);void gem_context_require_bannable (int fd);void gem_context_require_param (int fd,uint64_t param);void gem_context_get_param (int fd,struct local_i915_gem_context_param *p);
tests/gem_ctx_create.c +5 -5
@@ -45,7 +45,7 @@ static unsigned all_nengine;static unsigned ppgtt_engines[16 ];static unsigned ppgtt_nengine; -static int __gem_context_create (int fd,struct drm_i915_gem_context_create *arg) +static int __gem_context_create_local (int fd,struct drm_i915_gem_context_create *arg) {int ret =0 ;if (drmIoctl (fd,DRM_IOCTL_I915_GEM_CONTEXT_CREATE , arg))
@@ -255,7 +255,7 @@ static void maximum(int fd, int ncpus, unsigned mode) err = -ENOMEM ;if (avail_mem > (count +1 ) * ctx_size) - err =__gem_context_create (fd, &create); + err =__gem_context_create_local (fd, &create);if (err) {igt_info ("Created %lu contexts, before failing with '%s' [%d]\n" , count,strerror (-err), -err);
@@ -322,7 +322,7 @@ igt_mainigt_require_gem (fd);memset (&create,0 ,sizeof (create)); -igt_require (__gem_context_create (fd, &create) ==0 ); +igt_require (__gem_context_create_local (fd, &create) ==0 );gem_context_destroy (fd, create.ctx_id);for_each_engine (fd, engine) {
@@ -347,7 +347,7 @@ igt_mainmemset (&create,0 ,sizeof (create)); create.ctx_id =rand (); create.pad =0 ; -igt_assert_eq (__gem_context_create (fd, &create),0 ); +igt_assert_eq (__gem_context_create_local (fd, &create),0 );igt_assert (create.ctx_id !=0 );gem_context_destroy (fd, create.ctx_id); }
@@ -356,7 +356,7 @@ igt_mainmemset (&create,0 ,sizeof (create)); create.ctx_id =rand (); create.pad =1 ; -igt_assert_eq (__gem_context_create (fd, &create), -EINVAL ); +igt_assert_eq (__gem_context_create_local (fd, &create), -EINVAL ); }igt_subtest ("maximum-mem" )
tests/gem_ctx_switch.c +0 -13
@@ -45,19 +45,6 @@#define INTERRUPTIBLE 1 -static int __gem_context_create (int fd,uint32_t *ctx_id) -{ -struct drm_i915_gem_context_create arg; -int ret =0 ; - -memset (&arg,0 ,sizeof (arg)); -if (drmIoctl (fd,DRM_IOCTL_I915_GEM_CONTEXT_CREATE , &arg)) - ret = -errno; - - *ctx_id = arg.ctx_id; -return ret; -} -static double elapsed (const struct timespec *start,const struct timespec *end) { return ((end->tv_sec - start->tv_sec) +
tests/gem_eio.c +1 -12
@@ -207,17 +207,6 @@ static void test_inflight(int fd) } } -static uint32_t __gem_context_create (int fd) -{ -struct drm_i915_gem_context_create create; - -memset (&create,0 ,sizeof (create)); -if (ioctl (fd,DRM_IOCTL_I915_GEM_CONTEXT_CREATE , &create)) -return 0 ; - -return create.ctx_id; -} -static void test_inflight_contexts (int fd) {struct drm_i915_gem_execbuffer2 execbuf;
@@ -229,7 +218,7 @@ static void test_inflight_contexts(int fd)igt_require (gem_has_exec_fence (fd)); - ctx[0 ] =__gem_context_create (fd); + ctx[0 ] =gem_context_create (fd);igt_require (ctx[0 ]);for (unsigned int n =1 ; n <ARRAY_SIZE (ctx); n++) ctx[n] =gem_context_create (fd);
tests/gem_exec_await.c +2 -12
@@ -55,15 +55,6 @@ static bool ignore_engine(int fd, unsigned engine)return false; } -static uint32_t __gem_context_create (int fd) -{ -struct drm_i915_gem_context_create arg; - -memset (&arg,0 ,sizeof (arg)); -drmIoctl (fd,DRM_IOCTL_I915_GEM_CONTEXT_CREATE , &arg); -return arg.ctx_id; -} -static void xchg_obj (void *array,unsigned i,unsigned j) {struct drm_i915_gem_exec_object2 *obj = array;
@@ -130,8 +121,7 @@ static void wide(int fd, int ring_size, int timeout, unsigned int flags) LOCAL_I915_EXEC_HANDLE_LUT);if (flags &CONTEXTS ) { - exec[e].execbuf.rsvd1 =__gem_context_create (fd); -igt_require (exec[e].execbuf.rsvd1); + exec[e].execbuf.rsvd1 =gem_context_create (fd); } exec[e].exec[0 ].handle =gem_create (fd,4096 );
@@ -174,7 +164,7 @@ static void wide(int fd, int ring_size, int timeout, unsigned int flags)if (flags &CONTEXTS ) {gem_context_destroy (fd, exec[e].execbuf.rsvd1); - exec[e].execbuf.rsvd1 =__gem_context_create (fd); + exec[e].execbuf.rsvd1 =gem_context_create (fd); } exec[e].reloc.presumed_offset = exec[e].exec[1 ].offset;
tests/gem_exec_nop.c +0 -13
@@ -365,19 +365,6 @@ static void xchg(void *array, unsigned i, unsigned j) u[j] = tmp; } -static int __gem_context_create (int fd,uint32_t *ctx_id) -{ -struct drm_i915_gem_context_create arg; -int ret =0 ; - -memset (&arg,0 ,sizeof (arg)); -if (drmIoctl (fd,DRM_IOCTL_I915_GEM_CONTEXT_CREATE , &arg)) - ret = -errno; - - *ctx_id = arg.ctx_id; -return ret; -} -static void sequential (int fd,uint32_t handle,unsigned flags,int timeout) {const int ncpus = flags &FORKED ?sysconf (_SC_NPROCESSORS_ONLN) :1 ;
tests/gem_exec_parallel.c +3 -12
@@ -55,20 +55,11 @@ static void check_bo(int fd, uint32_t handle, int pass)munmap (map,4096 ); } -static uint32_t __gem_context_create (int fd) -{ -struct drm_i915_gem_context_create arg; - -memset (&arg,0 ,sizeof (arg)); -if (drmIoctl (fd,DRM_IOCTL_I915_GEM_CONTEXT_CREATE , &arg) ==0 ) -gem_context_destroy (fd, arg.ctx_id); - -return arg.ctx_id; -} -static void gem_require_context (int fd) { -igt_require (__gem_context_create (fd)); +uint32_t ctx_id =0 ; +__gem_context_create (fd, &ctx_id); +igt_require (ctx_id); }static bool ignore_engine (int fd,unsigned engine)
tests/gem_exec_reuse.c +0 -13
@@ -56,19 +56,6 @@ static void noop(struct noop *n,gem_execbuf (n->fd, &execbuf); } -static int __gem_context_create (int fd,uint32_t *ctx_id) -{ -struct drm_i915_gem_context_create arg; -int ret =0 ; - -memset (&arg,0 ,sizeof (arg)); -if (drmIoctl (fd,DRM_IOCTL_I915_GEM_CONTEXT_CREATE , &arg)) - ret = -errno; - - *ctx_id = arg.ctx_id; -return ret; -} -static int fls (uint64_t x) {int t;
tests/gem_exec_whisper.c +0 -13
@@ -79,19 +79,6 @@ static void verify_reloc(int fd, uint32_t handle, } } -static int __gem_context_create (int fd,uint32_t *ctx_id) -{ -struct drm_i915_gem_context_create arg; -int ret =0 ; - -memset (&arg,0 ,sizeof (arg)); -if (drmIoctl (fd,DRM_IOCTL_I915_GEM_CONTEXT_CREATE , &arg)) - ret = -errno; - - *ctx_id = arg.ctx_id; -return ret; -} -static bool ignore_engine (int fd,unsigned engine) {if (engine ==0 )
Signature · 6 lines
2.14.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v2 2/2 tests/gem_reset_stats: Add client ban test
A client that submits 'bad' contexts will be banned eventually while other clients are not affected. Add a test for this.
v2
- Do not use a fixed number of contexts to ban client (Chris)
--- tests/gem_reset_stats.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+)
tests/gem_reset_stats.c +58 -0
@@ -438,6 +438,61 @@ static void test_ban_ctx(const struct intel_execution_engine *e)close (fd); } +static void test_client_ban (const struct intel_execution_engine *e) +{ +int fd_bad,fd_good; +struct local_drm_i915_reset_stats rs_bad, rs_good; +int ban, ctx_bans_retry =10 ; +int client_ban, client_bans_retry =10 ; +uint32_t ctx_bad; +uint32_t test_ctx; +int active_count =0 ; + + fd_bad =drm_open_driver (DRIVER_INTEL ); + fd_good =drm_open_driver (DRIVER_INTEL ); + +assert_reset_status (fd_bad, fd_bad,0 ,RS_NO_ERROR ); +assert_reset_status (fd_good, fd_good,0 ,RS_NO_ERROR ); + +while (client_bans_retry--) { + client_ban =__gem_context_create (fd_bad, &ctx_bad); +if (client_ban == -EIO ) +break ; + +noop (fd_bad, ctx_bad, e); +assert_reset_status (fd_bad, fd_bad, ctx_bad,RS_NO_ERROR ); + + ctx_bans_retry =10 ; + active_count =0 ; +while (ctx_bans_retry--) { +inject_hang (fd_bad, ctx_bad, e,BAN ); + active_count++; + + ban =noop (fd_bad, ctx_bad, e); +if (ban == -EIO ) +break ; + } + +igt_assert_eq (ban, -EIO ); + +assert_reset_status (fd_bad, fd_bad, ctx_bad,RS_BATCH_ACTIVE ); +igt_assert_eq (gem_reset_stats (fd_bad, ctx_bad, &rs_bad),0 ); +igt_assert_eq (rs_bad.batch_active, active_count); + +igt_debug ("retrying for client ban (%d)\n" , client_bans_retry); + } + +igt_assert_eq (__gem_context_create (fd_bad, &test_ctx), -EIO ); + +igt_assert_lt (0 ,noop (fd_good,0 , e)); +assert_reset_status (fd_good, fd_good,0 ,RS_NO_ERROR ); +igt_assert_eq (gem_reset_stats (fd_good,0 , &rs_good),0 ); +igt_assert_eq (rs_good.batch_active,0 ); + +close (fd_bad); +close (fd_good); +} +static void test_unrelated_ctx (const struct intel_execution_engine *e) {int fd1,fd2;
@@ -817,6 +872,9 @@ igt_main igt_subtest_f("ban-ctx-%s", e->name)RUN_CTX_TEST (test_ban_ctx (e)); + igt_subtest_f("ban-client-%s", e->name) +RUN_CTX_TEST (test_client_ban (e)); + igt_subtest_f("reset-count-%s", e->name)RUN_TEST (test_reset_count (e, false));
Signature · 6 lines
2.14.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH i-g-t v2 2/2] tests/gem_reset_stats: Add client ban test
Quoting Antonio Argenziano (2017-10-13 21:49:29)
Quoted 21 lines
A client that submits 'bad' contexts will be banned eventually while other clients are not affected. Add a test for this.
v2
- Do not use a fixed number of contexts to ban client (Chris)Signed-off-by Antonio Argenziano <[email protected]>Cc Michel Thierry <[email protected]>Cc Chris Wilson <[email protected]>--- tests/gem_reset_stats.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+)tests/gem_reset_stats.c +0
-0@@ -438,6 +438,61 @@ static void test_ban_ctx(const struct intel_execution_engine *e)close (fd); }
tests/gem_reset_stats.c static void test_ban_ctx(const struct intel_execution_engine *e) · line 449
Quoted 10 lines
tests/gem_reset_stats.c +9
-0+static void test_client_ban (const struct intel_execution_engine *e) +{ +int fd_bad,fd_good; +struct local_drm_i915_reset_stats rs_bad, rs_good; +int ban, ctx_bans_retry =10 ; +int client_ban, client_bans_retry =10 ; +uint32_t ctx_bad; +uint32_t test_ctx; +int active_count =0 ;
/*
* We try to prevent DoS GPU hang attacks from one client affecting the
* service of other clients by banning the malicious client. *
* To simulate this, we have one client submit a sequence of GPU hangs
* that we expect to be banned (the client will no longer be allowed
* to submit new work). Meanwhile a second client will not be affected
* and allowed to continue.
*
* Note this is an extremely simplistic mechanism. For example, each
* context inside an fd may represent a separate client (e.g. WebGL)
* in which case the per-fd ban allow one client to DoS a second.
* On the other hand, a malicious client may be creating a new context
* for each hang to circumvent per-context restrictions. It may even be
* creating a new fd each time to circumvent the per-fd restrictions.
* Finally, the most malicious of all clients may succeed in wedging
* the driver, bringing everyone to a standstill. In short, this DoS
* prevention is itself suspect.
*
* So given the above what exactly to we want to define as the
* expected behaviour? The answer is none of the above; use a
* timeslicing scheduler and no banning. Any context is then allowed to
* use as much as its time slice spinning as it wants; it won't be
* allowed to steal GPU time from other processes. DoS averted. */
I keep coming to the conclusion that banning is a temporary hack, and not mandatory uABI, like hangcheck. The usual answer is that we then describe the implementation's behaviour through say a CONTEXT_GETPARAM and let userspace factor that into account. But again, I to have ask what requirements has userspace?
https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_robustness.txt
(And how are the requirements going to change?)
The implication from that is that we could ban a context after the first hang, but mesa isn't ready for that!
Maybe you should try writing an explanation of exactly what behaviour you are trying to elicit here and why? :)
One thing that seems nice on the surface for execlists is repriotising after a hang to allow all innocent parties to make progress at the expense of the guilty. You will probably think of a few other approaches that make sense as you think about what userspace expects.
Quoted 13 lines
tests/gem_reset_stats.c +13
-0+ fd_bad =drm_open_driver (DRIVER_INTEL ); + fd_good =drm_open_driver (DRIVER_INTEL ); + +assert_reset_status (fd_bad, fd_bad,0 ,RS_NO_ERROR ); +assert_reset_status (fd_good, fd_good,0 ,RS_NO_ERROR ); + +while (client_bans_retry--) { + client_ban =__gem_context_create (fd_bad, &ctx_bad); +if (client_ban == -EIO ) +break ; + +noop (fd_bad, ctx_bad, e); +assert_reset_status (fd_bad, fd_bad, ctx_bad,RS_NO_ERROR );
tests/gem_reset_stats.c static void test_ban_ctx(const struct intel_execution_engine *e) · line 473
Quoted 10 lines
tests/gem_reset_stats.c +10
-0+ + ctx_bans_retry =10 ; + active_count =0 ; +while (ctx_bans_retry--) { +inject_hang (fd_bad, ctx_bad, e,BAN ); + active_count++; + + ban =noop (fd_bad, ctx_bad, e); +if (ban == -EIO ) +break ;
There's a major variation in submitting a queue of hangs that also needs to be taken into account (with different code paths in the kernel). -Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoting Antonio Argenziano (2017-10-13 21:49:28)
tests/gem_exec_parallel.c static void check_bo(int fd, uint32_t handle, int pass) · line 62
Quoted 6 lines
static void
gem_require_context(int fd)
{tests/gem_exec_parallel.c +3
-1-igt_require (__gem_context_create (fd)); +uint32_t ctx_id =0 ; +__gem_context_create (fd, &ctx_id); +igt_require (ctx_id);
Still that leaks.
uint32_t has_contexts = 0;__gem_context_create(fd, &has_contexts);
if (has_contexts)
gem_context_destroy(fd, has_contexts);
igt_require(has_contexts);
Note that before we can drop the require from gem_context_create() we have to go throw and teach all users to do the manual gem_require_context() first.
Second note,
static bool gem_has_contexts(int fd)
{
uint32_t ctx_id = 0;
__gem_context_create(fd, &ctx_id);
if (ctx_id)
gem_context_destroy(fd, ctx_id);
return ctx_id;
}void gem_require_contexts(int fd)
{
igt_require(gem_has_contexts(fd));
}-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✗ Fi.CI.BAT: failure for series starting with [v2,1/2] lib: Move __gem_context_create to common ioctl wrapper library.
In reply to Antonio Argenziano== Series Details ==
== Series Details ==
Series: series starting with [v2,1/2] lib: Move __gem_context_create to common ioctl wrapper library.
URL : https://patchwork.freedesktop.org/series/31960/
State : failure
== Summary ==
Series 31960 revision 1 was fully merged or fully failed: no git log
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx