All of lore.kernel.org
 help / color / mirror / Atom feed
* [Intel-gfx] [PATCH i-g-t] i915/gem_mmap_gtt: Simulate gdb inspecting a GTT mmap using ptrace()
@ 2020-04-30 19:41 Chris Wilson
  2020-04-30 20:54 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
  2020-05-01 14:58   ` [igt-dev] " Matthew Auld
  0 siblings, 2 replies; 5+ messages in thread
From: Chris Wilson @ 2020-04-30 19:41 UTC (permalink / raw)
  To: intel-gfx; +Cc: igt-dev, Chris Wilson

gdb uses ptrace() to peek and poke bytes of the target's address space.
The kernel must implement an vm_ops->access() handler or else gdb will
be unable to inspect the pointer and report it as out-of-bounds. Worse
than useless as it causes immediate suspicion of the valid GTT pointer.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 tests/i915/gem_mmap_gtt.c | 79 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 78 insertions(+), 1 deletion(-)

diff --git a/tests/i915/gem_mmap_gtt.c b/tests/i915/gem_mmap_gtt.c
index 1f4655af4..38b4d02d7 100644
--- a/tests/i915/gem_mmap_gtt.c
+++ b/tests/i915/gem_mmap_gtt.c
@@ -34,8 +34,11 @@
 #include <inttypes.h>
 #include <pthread.h>
 #include <errno.h>
-#include <sys/stat.h>
+#include <signal.h>
 #include <sys/ioctl.h>
+#include <sys/ptrace.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
 #include "drm.h"
 
 #include "igt.h"
@@ -501,6 +504,78 @@ test_write_gtt(int fd)
 	munmap(src, OBJECT_SIZE);
 }
 
+static void *memchr_inv(const void *s, int c, size_t n)
+{
+	const uint8_t *us = s;
+	const uint8_t uc = c;
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-qual"
+	while (n--) {
+		if (*us != uc)
+			return (void *) us;
+		us++;
+	}
+#pragma GCC diagnostic pop
+
+	return NULL;
+}
+
+static void
+test_ptrace(int fd)
+{
+	unsigned long AA, CC;
+	unsigned long *gtt, *cpy;
+	uint32_t bo;
+	pid_t pid;
+
+	memset(&AA, 0xaa, sizeof(AA));
+	memset(&CC, 0x55, sizeof(CC));
+
+	cpy = malloc(OBJECT_SIZE);
+	memset(cpy, AA, OBJECT_SIZE);
+
+	bo = gem_create(fd, OBJECT_SIZE);
+	gtt = mmap_bo(fd, bo, OBJECT_SIZE);
+	memset(gtt, CC, OBJECT_SIZE);
+	gem_close(fd, bo);
+
+	igt_assert(!memchr_inv(gtt, CC, OBJECT_SIZE));
+	igt_assert(!memchr_inv(cpy, AA, OBJECT_SIZE));
+
+	igt_fork(child, 1) {
+		ptrace(PTRACE_TRACEME, 0, NULL, NULL);
+		raise(SIGSTOP);
+	}
+
+	/* Wait for the child to ready themselves [SIGSTOP] */
+	pid = wait(NULL);
+
+	ptrace(PTRACE_ATTACH, pid, NULL, NULL);
+	for (int i = 0; i < OBJECT_SIZE / sizeof(long); i++) {
+		long ret;
+
+		ret = ptrace(PTRACE_PEEKDATA, pid, gtt + i);
+		igt_assert_eq_u64(ret, CC);
+		cpy[i] = ret;
+
+		ret = ptrace(PTRACE_POKEDATA, pid, gtt + i, AA);
+		igt_assert_eq(ret, 0l);
+	}
+	ptrace(PTRACE_DETACH, pid, NULL, NULL);
+
+	/* Wakeup the child for it to exit */
+	kill(SIGCONT, pid);
+	igt_waitchildren();
+
+	/* The contents of the two buffers should now be swapped */
+	igt_assert(!memchr_inv(gtt, AA, OBJECT_SIZE));
+	igt_assert(!memchr_inv(cpy, CC, OBJECT_SIZE));
+
+	munmap(gtt, OBJECT_SIZE);
+	free(cpy);
+}
+
 static bool is_coherent(int i915)
 {
 	int val = 1; /* by default, we assume GTT is coherent, hence the test */
@@ -1084,6 +1159,8 @@ igt_main
 		test_write(fd);
 	igt_subtest("basic-write-gtt")
 		test_write_gtt(fd);
+	igt_subtest("ptrace")
+		test_ptrace(fd);
 	igt_subtest("coherency")
 		test_coherency(fd);
 	igt_subtest("clflush")
-- 
2.26.2

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [igt-dev] ✓ Fi.CI.BAT: success for i915/gem_mmap_gtt: Simulate gdb inspecting a GTT mmap using ptrace()
  2020-04-30 19:41 [Intel-gfx] [PATCH i-g-t] i915/gem_mmap_gtt: Simulate gdb inspecting a GTT mmap using ptrace() Chris Wilson
@ 2020-04-30 20:54 ` Patchwork
  2020-05-01 14:58   ` [igt-dev] " Matthew Auld
  1 sibling, 0 replies; 5+ messages in thread
From: Patchwork @ 2020-04-30 20:54 UTC (permalink / raw)
  To: Chris Wilson; +Cc: igt-dev

== Series Details ==

Series: i915/gem_mmap_gtt: Simulate gdb inspecting a GTT mmap using ptrace()
URL   : https://patchwork.freedesktop.org/series/76784/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_8403 -> IGTPW_4523
====================================================

Summary
-------

  **SUCCESS**

  No regressions found.

  External URL: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4523/index.html

Known issues
------------

  Here are the changes found in IGTPW_4523 that come from known issues:

### IGT changes ###

#### Issues hit ####

  * igt@kms_pipe_crc_basic@suspend-read-crc-pipe-a:
    - fi-hsw-4770:        [PASS][1] -> [INCOMPLETE][2] ([i915#61])
   [1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8403/fi-hsw-4770/igt@kms_pipe_crc_basic@suspend-read-crc-pipe-a.html
   [2]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4523/fi-hsw-4770/igt@kms_pipe_crc_basic@suspend-read-crc-pipe-a.html

  
#### Possible fixes ####

  * igt@i915_selftest@live@gt_engines:
    - fi-bwr-2160:        [INCOMPLETE][3] ([i915#489]) -> [PASS][4]
   [3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8403/fi-bwr-2160/igt@i915_selftest@live@gt_engines.html
   [4]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4523/fi-bwr-2160/igt@i915_selftest@live@gt_engines.html

  
  [i915#489]: https://gitlab.freedesktop.org/drm/intel/issues/489
  [i915#61]: https://gitlab.freedesktop.org/drm/intel/issues/61


Participating hosts (51 -> 43)
------------------------------

  Missing    (8): fi-ilk-m540 fi-hsw-4200u fi-byt-squawks fi-bsw-cyan fi-ctg-p8600 fi-kbl-7560u fi-byt-clapper fi-bdw-samus 


Build changes
-------------

  * CI: CI-20190529 -> None
  * IGT: IGT_5619 -> IGTPW_4523

  CI-20190529: 20190529
  CI_DRM_8403: 09978e99929f6e5acfe1e959f6499a134f210887 @ git://anongit.freedesktop.org/gfx-ci/linux
  IGTPW_4523: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4523/index.html
  IGT_5619: 94de923ca8d4cc8f532b8062d87aaad9da6ef956 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools



== Testlist changes ==

+igt@gem_mmap_gtt@ptrace

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4523/index.html
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Intel-gfx] [PATCH i-g-t] i915/gem_mmap_gtt: Simulate gdb inspecting a GTT mmap using ptrace()
  2020-04-30 19:41 [Intel-gfx] [PATCH i-g-t] i915/gem_mmap_gtt: Simulate gdb inspecting a GTT mmap using ptrace() Chris Wilson
@ 2020-05-01 14:58   ` Matthew Auld
  2020-05-01 14:58   ` [igt-dev] " Matthew Auld
  1 sibling, 0 replies; 5+ messages in thread
From: Matthew Auld @ 2020-05-01 14:58 UTC (permalink / raw)
  To: Chris Wilson; +Cc: igt-dev, Intel Graphics Development

On Thu, 30 Apr 2020 at 20:42, Chris Wilson <chris@chris-wilson.co.uk> wrote:
>
> gdb uses ptrace() to peek and poke bytes of the target's address space.
> The kernel must implement an vm_ops->access() handler or else gdb will
> be unable to inspect the pointer and report it as out-of-bounds. Worse
> than useless as it causes immediate suspicion of the valid GTT pointer.
>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> ---
>  tests/i915/gem_mmap_gtt.c | 79 ++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 78 insertions(+), 1 deletion(-)
>
> diff --git a/tests/i915/gem_mmap_gtt.c b/tests/i915/gem_mmap_gtt.c
> index 1f4655af4..38b4d02d7 100644
> --- a/tests/i915/gem_mmap_gtt.c
> +++ b/tests/i915/gem_mmap_gtt.c
> @@ -34,8 +34,11 @@
>  #include <inttypes.h>
>  #include <pthread.h>
>  #include <errno.h>
> -#include <sys/stat.h>
> +#include <signal.h>
>  #include <sys/ioctl.h>
> +#include <sys/ptrace.h>
> +#include <sys/stat.h>
> +#include <sys/wait.h>
>  #include "drm.h"
>
>  #include "igt.h"
> @@ -501,6 +504,78 @@ test_write_gtt(int fd)
>         munmap(src, OBJECT_SIZE);
>  }
>
> +static void *memchr_inv(const void *s, int c, size_t n)
> +{
> +       const uint8_t *us = s;
> +       const uint8_t uc = c;
> +
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wcast-qual"
> +       while (n--) {
> +               if (*us != uc)
> +                       return (void *) us;
> +               us++;
> +       }
> +#pragma GCC diagnostic pop
> +
> +       return NULL;
> +}
> +
> +static void
> +test_ptrace(int fd)
> +{
> +       unsigned long AA, CC;
> +       unsigned long *gtt, *cpy;
> +       uint32_t bo;
> +       pid_t pid;
> +
> +       memset(&AA, 0xaa, sizeof(AA));
> +       memset(&CC, 0x55, sizeof(CC));
> +
> +       cpy = malloc(OBJECT_SIZE);
> +       memset(cpy, AA, OBJECT_SIZE);
> +
> +       bo = gem_create(fd, OBJECT_SIZE);
> +       gtt = mmap_bo(fd, bo, OBJECT_SIZE);
> +       memset(gtt, CC, OBJECT_SIZE);
> +       gem_close(fd, bo);
> +
> +       igt_assert(!memchr_inv(gtt, CC, OBJECT_SIZE));
> +       igt_assert(!memchr_inv(cpy, AA, OBJECT_SIZE));
> +
> +       igt_fork(child, 1) {
> +               ptrace(PTRACE_TRACEME, 0, NULL, NULL);
> +               raise(SIGSTOP);
> +       }
> +
> +       /* Wait for the child to ready themselves [SIGSTOP] */
> +       pid = wait(NULL);
> +
> +       ptrace(PTRACE_ATTACH, pid, NULL, NULL);
> +       for (int i = 0; i < OBJECT_SIZE / sizeof(long); i++) {
> +               long ret;
> +
> +               ret = ptrace(PTRACE_PEEKDATA, pid, gtt + i);
> +               igt_assert_eq_u64(ret, CC);
> +               cpy[i] = ret;
> +
> +               ret = ptrace(PTRACE_POKEDATA, pid, gtt + i, AA);
> +               igt_assert_eq(ret, 0l);

igt_assert_eq_u64() ?

Reviewed-by: Matthew Auld <matthew.auld@intel.com>
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [igt-dev] [Intel-gfx] [PATCH i-g-t] i915/gem_mmap_gtt: Simulate gdb inspecting a GTT mmap using ptrace()
@ 2020-05-01 14:58   ` Matthew Auld
  0 siblings, 0 replies; 5+ messages in thread
From: Matthew Auld @ 2020-05-01 14:58 UTC (permalink / raw)
  To: Chris Wilson; +Cc: igt-dev, Intel Graphics Development

On Thu, 30 Apr 2020 at 20:42, Chris Wilson <chris@chris-wilson.co.uk> wrote:
>
> gdb uses ptrace() to peek and poke bytes of the target's address space.
> The kernel must implement an vm_ops->access() handler or else gdb will
> be unable to inspect the pointer and report it as out-of-bounds. Worse
> than useless as it causes immediate suspicion of the valid GTT pointer.
>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> ---
>  tests/i915/gem_mmap_gtt.c | 79 ++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 78 insertions(+), 1 deletion(-)
>
> diff --git a/tests/i915/gem_mmap_gtt.c b/tests/i915/gem_mmap_gtt.c
> index 1f4655af4..38b4d02d7 100644
> --- a/tests/i915/gem_mmap_gtt.c
> +++ b/tests/i915/gem_mmap_gtt.c
> @@ -34,8 +34,11 @@
>  #include <inttypes.h>
>  #include <pthread.h>
>  #include <errno.h>
> -#include <sys/stat.h>
> +#include <signal.h>
>  #include <sys/ioctl.h>
> +#include <sys/ptrace.h>
> +#include <sys/stat.h>
> +#include <sys/wait.h>
>  #include "drm.h"
>
>  #include "igt.h"
> @@ -501,6 +504,78 @@ test_write_gtt(int fd)
>         munmap(src, OBJECT_SIZE);
>  }
>
> +static void *memchr_inv(const void *s, int c, size_t n)
> +{
> +       const uint8_t *us = s;
> +       const uint8_t uc = c;
> +
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wcast-qual"
> +       while (n--) {
> +               if (*us != uc)
> +                       return (void *) us;
> +               us++;
> +       }
> +#pragma GCC diagnostic pop
> +
> +       return NULL;
> +}
> +
> +static void
> +test_ptrace(int fd)
> +{
> +       unsigned long AA, CC;
> +       unsigned long *gtt, *cpy;
> +       uint32_t bo;
> +       pid_t pid;
> +
> +       memset(&AA, 0xaa, sizeof(AA));
> +       memset(&CC, 0x55, sizeof(CC));
> +
> +       cpy = malloc(OBJECT_SIZE);
> +       memset(cpy, AA, OBJECT_SIZE);
> +
> +       bo = gem_create(fd, OBJECT_SIZE);
> +       gtt = mmap_bo(fd, bo, OBJECT_SIZE);
> +       memset(gtt, CC, OBJECT_SIZE);
> +       gem_close(fd, bo);
> +
> +       igt_assert(!memchr_inv(gtt, CC, OBJECT_SIZE));
> +       igt_assert(!memchr_inv(cpy, AA, OBJECT_SIZE));
> +
> +       igt_fork(child, 1) {
> +               ptrace(PTRACE_TRACEME, 0, NULL, NULL);
> +               raise(SIGSTOP);
> +       }
> +
> +       /* Wait for the child to ready themselves [SIGSTOP] */
> +       pid = wait(NULL);
> +
> +       ptrace(PTRACE_ATTACH, pid, NULL, NULL);
> +       for (int i = 0; i < OBJECT_SIZE / sizeof(long); i++) {
> +               long ret;
> +
> +               ret = ptrace(PTRACE_PEEKDATA, pid, gtt + i);
> +               igt_assert_eq_u64(ret, CC);
> +               cpy[i] = ret;
> +
> +               ret = ptrace(PTRACE_POKEDATA, pid, gtt + i, AA);
> +               igt_assert_eq(ret, 0l);

igt_assert_eq_u64() ?

Reviewed-by: Matthew Auld <matthew.auld@intel.com>
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Intel-gfx] [PATCH i-g-t] i915/gem_mmap_gtt: Simulate gdb inspecting a GTT mmap using ptrace()
  2020-05-01 14:58   ` [igt-dev] " Matthew Auld
  (?)
@ 2020-05-01 15:01   ` Chris Wilson
  -1 siblings, 0 replies; 5+ messages in thread
From: Chris Wilson @ 2020-05-01 15:01 UTC (permalink / raw)
  To: Matthew Auld; +Cc: igt-dev, Intel Graphics Development

Quoting Matthew Auld (2020-05-01 15:58:29)
> On Thu, 30 Apr 2020 at 20:42, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> > +       ptrace(PTRACE_ATTACH, pid, NULL, NULL);
> > +       for (int i = 0; i < OBJECT_SIZE / sizeof(long); i++) {
> > +               long ret;
> > +
> > +               ret = ptrace(PTRACE_PEEKDATA, pid, gtt + i);
> > +               igt_assert_eq_u64(ret, CC);
> > +               cpy[i] = ret;
> > +
> > +               ret = ptrace(PTRACE_POKEDATA, pid, gtt + i, AA);
> > +               igt_assert_eq(ret, 0l);
> 
> igt_assert_eq_u64() ?

In this case it will either be 0 or -1 + errno.

So "%d" vs "%llx" should not affect debugging.
-Chris
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-05-01 15:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-30 19:41 [Intel-gfx] [PATCH i-g-t] i915/gem_mmap_gtt: Simulate gdb inspecting a GTT mmap using ptrace() Chris Wilson
2020-04-30 20:54 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2020-05-01 14:58 ` [Intel-gfx] [PATCH i-g-t] " Matthew Auld
2020-05-01 14:58   ` [igt-dev] " Matthew Auld
2020-05-01 15:01   ` Chris Wilson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.