All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH i-g-t 0/2] panfrost: Test accessing a purged buffer via mmap
@ 2021-03-05 11:12 Neil Roberts
  2021-03-05 11:12 ` [PATCH i-g-t 1/2] lib/panfrost: Add a utility to madvise a buffer Neil Roberts
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Neil Roberts @ 2021-03-05 11:12 UTC (permalink / raw)
  To: igt-dev; +Cc: dri-devel

This adds a test for Panfrost to make sure that accessing a buffer
that has been madvised and then purged causes a bus fault. It is
intended to test the fix provided by this series:

https://patchwork.freedesktop.org/series/87324/

The series has now been merged into drm-misc-fixes (thanks!)

In order to trigger the purge, the test just tries to allocate a bunch
of buffers until one of them causes the original buffer to be purged.
During the review of the kernel patch series, Daniel Vetter suggested
it would be better to use debugfs or vm_drop_caches file from proc.
However, I noticed that there are other tests that use the same method
as in this series (eg, igt_vc4_trigger_purge). Seeing as there is
already a precedent for IGT tests to do this, I wonder if we could
leave that as a later change for someone who is more active in
Panfrost development.

Neil Roberts (2):
  lib/panfrost: Add a utility to madvise a buffer
  tests/panfrost: Add a test for accessing a purged buffer

 lib/igt_panfrost.c        |  12 ++++
 lib/igt_panfrost.h        |   1 +
 tests/meson.build         |   1 +
 tests/panfrost_purgemap.c | 146 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 160 insertions(+)
 create mode 100644 tests/panfrost_purgemap.c

-- 
2.29.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* [PATCH i-g-t 1/2] lib/panfrost: Add a utility to madvise a buffer
  2021-03-05 11:12 [PATCH i-g-t 0/2] panfrost: Test accessing a purged buffer via mmap Neil Roberts
@ 2021-03-05 11:12 ` Neil Roberts
  2021-03-05 11:12 ` [PATCH i-g-t 2/2] tests/panfrost: Add a test for accessing a purged buffer Neil Roberts
  2021-03-05 11:45 ` [igt-dev] ✗ Fi.CI.BAT: failure for panfrost: Test accessing a purged buffer via mmap Patchwork
  2 siblings, 0 replies; 4+ messages in thread
From: Neil Roberts @ 2021-03-05 11:12 UTC (permalink / raw)
  To: igt-dev; +Cc: dri-devel

Signed-off-by: Neil Roberts <nroberts@igalia.com>
---
 lib/igt_panfrost.c | 12 ++++++++++++
 lib/igt_panfrost.h |  1 +
 2 files changed, 13 insertions(+)

diff --git a/lib/igt_panfrost.c b/lib/igt_panfrost.c
index 8b0c2b77..ffce66a2 100644
--- a/lib/igt_panfrost.c
+++ b/lib/igt_panfrost.c
@@ -127,6 +127,18 @@ void igt_panfrost_bo_mmap(int fd, struct panfrost_bo *bo)
         igt_assert(bo->map);
 }
 
+bool igt_panfrost_bo_madvise(int fd, struct panfrost_bo *bo, uint32_t madv)
+{
+        struct drm_panfrost_madvise madvise = {
+                .handle = bo->handle,
+                .madv = madv,
+        };
+
+        do_ioctl(fd, DRM_IOCTL_PANFROST_MADVISE, &madvise);
+
+        return madvise.retained;
+}
+
 struct panfrost_submit *igt_panfrost_trivial_job(int fd, bool do_crash, int width, int height, uint32_t color)
 {
         struct panfrost_submit *submit;
diff --git a/lib/igt_panfrost.h b/lib/igt_panfrost.h
index cc7998dc..df326a6c 100644
--- a/lib/igt_panfrost.h
+++ b/lib/igt_panfrost.h
@@ -56,5 +56,6 @@ uint32_t igt_panfrost_get_param(int fd, int param);
 void *igt_panfrost_mmap_bo(int fd, uint32_t handle, uint32_t size, unsigned prot);
 
 void igt_panfrost_bo_mmap(int fd, struct panfrost_bo *bo);
+bool igt_panfrost_bo_madvise(int fd, struct panfrost_bo *bo, uint32_t madv);
 
 #endif /* IGT_PANFROST_H */
-- 
2.29.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* [PATCH i-g-t 2/2] tests/panfrost: Add a test for accessing a purged buffer
  2021-03-05 11:12 [PATCH i-g-t 0/2] panfrost: Test accessing a purged buffer via mmap Neil Roberts
  2021-03-05 11:12 ` [PATCH i-g-t 1/2] lib/panfrost: Add a utility to madvise a buffer Neil Roberts
@ 2021-03-05 11:12 ` Neil Roberts
  2021-03-05 11:45 ` [igt-dev] ✗ Fi.CI.BAT: failure for panfrost: Test accessing a purged buffer via mmap Patchwork
  2 siblings, 0 replies; 4+ messages in thread
From: Neil Roberts @ 2021-03-05 11:12 UTC (permalink / raw)
  To: igt-dev; +Cc: dri-devel

The test creates a buffer, sets it as DONTNEED via madvise, tries to
trigger a purge of buffers and then accesses the buffer via a user-space
mapping. This should generate a bus error, but due to a bug in the
kernel driver it fails to invalidate the mapping when the buffer is
purged.

Signed-off-by: Neil Roberts <nroberts@igalia.com>
---
 tests/meson.build         |   1 +
 tests/panfrost_purgemap.c | 146 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 147 insertions(+)
 create mode 100644 tests/panfrost_purgemap.c

diff --git a/tests/meson.build b/tests/meson.build
index 825e0183..af24427a 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -82,6 +82,7 @@ test_progs = [
 	'panfrost_get_param',
 	'panfrost_gem_new',
 	'panfrost_prime',
+	'panfrost_purgemap',
 	'panfrost_submit',
 	'prime_busy',
 	'prime_mmap',
diff --git a/tests/panfrost_purgemap.c b/tests/panfrost_purgemap.c
new file mode 100644
index 00000000..096fb95a
--- /dev/null
+++ b/tests/panfrost_purgemap.c
@@ -0,0 +1,146 @@
+/*
+ * Copyright © 2021 Igalia
+ *
+ * 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.
+ */
+
+#include "igt.h"
+#include "igt_panfrost.h"
+#include "igt_syncobj.h"
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <setjmp.h>
+#include <signal.h>
+#include "panfrost-job.h"
+#include "panfrost_drm.h"
+
+IGT_TEST_DESCRIPTION("Checks that accessing an mmapping of a buffer that has "
+		     "been purged causes a bus fault signal.");
+
+#define BUF_SIZE (32 * 1024 * 1024)
+
+struct buf_link {
+	struct panfrost_bo *bo;
+	struct buf_link *next;
+};
+
+static jmp_buf jmp;
+
+__noreturn static void sigtrap(int sig)
+{
+	siglongjmp(jmp, sig);
+}
+
+static void
+try_writing_to_mmap(uint8_t *ptr)
+{
+	sighandler_t old_sigsegv, old_sigbus;
+
+	old_sigsegv = signal(SIGSEGV, sigtrap);
+	old_sigbus = signal(SIGBUS, sigtrap);
+
+	switch (sigsetjmp(jmp, SIGBUS | SIGSEGV)) {
+	case SIGBUS:
+		break;
+	case 0:
+		*ptr = 0;
+	default:
+		igt_assert(!"reached");
+		break;
+	}
+
+	signal(SIGBUS, old_sigsegv);
+	signal(SIGSEGV, old_sigbus);
+}
+
+static void
+trigger_purge(int fd, struct panfrost_bo *madv_bo)
+{
+	struct buf_link *buf_list = NULL, *next, *buf;
+	bool retained;
+
+	/* Try to trigger a purge by allocating buffers until the main
+	 * buffer is no longer retained. This should probably be
+	 * replaced with a more reliable way to do this such as a
+	 * debugfs trigger.
+	 */
+
+	while (true) {
+		/* Mark the buffer as purgeable */
+		retained = igt_panfrost_bo_madvise(fd,
+						   madv_bo,
+						   PANFROST_MADV_DONTNEED);
+		igt_assert(retained);
+
+		buf = malloc(sizeof(*buf));
+		buf->bo = igt_panfrost_gem_new(fd, BUF_SIZE);
+		buf->next = buf_list;
+		buf_list = buf;
+
+		/* Check if that caused the buffer to be purged */
+		retained = igt_panfrost_bo_madvise(fd,
+						   madv_bo,
+						   PANFROST_MADV_WILLNEED);
+
+		if (!retained)
+			break;
+	}
+
+	/* Free all the temporary buffers that we created */
+	for (buf = buf_list; buf; buf = next) {
+		next = buf->next;
+		igt_panfrost_free_bo(fd, buf->bo);
+		free(buf);
+	}
+}
+
+igt_simple_main
+{
+	int fd;
+	struct panfrost_bo *bo;
+
+	fd = drm_open_driver(DRIVER_PANFROST);
+
+	bo = igt_panfrost_gem_new(fd, BUF_SIZE);
+
+	igt_panfrost_bo_mmap(fd, bo);
+
+	/* Write to the buffer to make sure the first page is
+	 * paged in
+	 */
+	memset(bo->map, 42, 64);
+
+	/* Try to cause the buffer to be purged */
+	trigger_purge(fd, bo);
+
+	/* Write through the mapping. This should cause a bus fault. */
+	try_writing_to_mmap(bo->map);
+
+	igt_panfrost_free_bo(fd, bo);
+
+	close(fd);
+}
-- 
2.29.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* [igt-dev] ✗ Fi.CI.BAT: failure for panfrost: Test accessing a purged buffer via mmap
  2021-03-05 11:12 [PATCH i-g-t 0/2] panfrost: Test accessing a purged buffer via mmap Neil Roberts
  2021-03-05 11:12 ` [PATCH i-g-t 1/2] lib/panfrost: Add a utility to madvise a buffer Neil Roberts
  2021-03-05 11:12 ` [PATCH i-g-t 2/2] tests/panfrost: Add a test for accessing a purged buffer Neil Roberts
@ 2021-03-05 11:45 ` Patchwork
  2 siblings, 0 replies; 4+ messages in thread
From: Patchwork @ 2021-03-05 11:45 UTC (permalink / raw)
  To: Neil Roberts; +Cc: igt-dev


[-- Attachment #1.1: Type: text/plain, Size: 6222 bytes --]

== Series Details ==

Series: panfrost: Test accessing a purged buffer via mmap
URL   : https://patchwork.freedesktop.org/series/87679/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_9834 -> IGTPW_5577
====================================================

Summary
-------

  **FAILURE**

  Serious unknown changes coming with IGTPW_5577 absolutely need to be
  verified manually.
  
  If you think the reported changes have nothing to do with the changes
  introduced in IGTPW_5577, please notify your bug team to allow them
  to document this new failure mode, which will reduce false positives in CI.

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

Possible new issues
-------------------

  Here are the unknown changes that may have been introduced in IGTPW_5577:

### IGT changes ###

#### Possible regressions ####

  * igt@i915_selftest@live@workarounds:
    - fi-tgl-u2:          [PASS][1] -> [DMESG-WARN][2] +17 similar issues
   [1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_9834/fi-tgl-u2/igt@i915_selftest@live@workarounds.html
   [2]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5577/fi-tgl-u2/igt@i915_selftest@live@workarounds.html

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

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

### IGT changes ###

#### Issues hit ####

  * igt@amdgpu/amd_basic@semaphore:
    - fi-icl-y:           NOTRUN -> [SKIP][3] ([fdo#109315]) +17 similar issues
   [3]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5577/fi-icl-y/igt@amdgpu/amd_basic@semaphore.html
    - fi-bdw-5557u:       NOTRUN -> [SKIP][4] ([fdo#109271]) +26 similar issues
   [4]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5577/fi-bdw-5557u/igt@amdgpu/amd_basic@semaphore.html

  * igt@core_hotunplug@unbind-rebind:
    - fi-bdw-5557u:       NOTRUN -> [WARN][5] ([i915#2283])
   [5]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5577/fi-bdw-5557u/igt@core_hotunplug@unbind-rebind.html

  * igt@gem_huc_copy@huc-copy:
    - fi-icl-y:           NOTRUN -> [SKIP][6] ([i915#2190])
   [6]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5577/fi-icl-y/igt@gem_huc_copy@huc-copy.html

  * igt@i915_pm_rpm@module-reload:
    - fi-tgl-u2:          [PASS][7] -> [FAIL][8] ([i915#579])
   [7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_9834/fi-tgl-u2/igt@i915_pm_rpm@module-reload.html
   [8]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5577/fi-tgl-u2/igt@i915_pm_rpm@module-reload.html

  * igt@i915_selftest@live@client:
    - fi-glk-dsi:         [PASS][9] -> [DMESG-FAIL][10] ([i915#3047])
   [9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_9834/fi-glk-dsi/igt@i915_selftest@live@client.html
   [10]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5577/fi-glk-dsi/igt@i915_selftest@live@client.html

  * igt@kms_chamelium@dp-crc-fast:
    - fi-bdw-5557u:       NOTRUN -> [SKIP][11] ([fdo#109271] / [fdo#111827]) +8 similar issues
   [11]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5577/fi-bdw-5557u/igt@kms_chamelium@dp-crc-fast.html
    - fi-icl-y:           NOTRUN -> [SKIP][12] ([fdo#109284] / [fdo#111827]) +8 similar issues
   [12]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5577/fi-icl-y/igt@kms_chamelium@dp-crc-fast.html

  * igt@kms_force_connector_basic@force-load-detect:
    - fi-icl-y:           NOTRUN -> [SKIP][13] ([fdo#109285])
   [13]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5577/fi-icl-y/igt@kms_force_connector_basic@force-load-detect.html

  * igt@kms_pipe_crc_basic@compare-crc-sanitycheck-pipe-d:
    - fi-icl-y:           NOTRUN -> [SKIP][14] ([fdo#109278])
   [14]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5577/fi-icl-y/igt@kms_pipe_crc_basic@compare-crc-sanitycheck-pipe-d.html

  * igt@kms_psr@primary_mmap_gtt:
    - fi-icl-y:           NOTRUN -> [SKIP][15] ([fdo#110189]) +3 similar issues
   [15]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5577/fi-icl-y/igt@kms_psr@primary_mmap_gtt.html

  
#### Possible fixes ####

  * igt@gem_exec_gttfill@basic:
    - fi-kbl-8809g:       [TIMEOUT][16] ([i915#3145]) -> [PASS][17]
   [16]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_9834/fi-kbl-8809g/igt@gem_exec_gttfill@basic.html
   [17]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5577/fi-kbl-8809g/igt@gem_exec_gttfill@basic.html

  * igt@gem_tiled_blits@basic:
    - fi-kbl-8809g:       [TIMEOUT][18] ([i915#2502] / [i915#3145]) -> [PASS][19]
   [18]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_9834/fi-kbl-8809g/igt@gem_tiled_blits@basic.html
   [19]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5577/fi-kbl-8809g/igt@gem_tiled_blits@basic.html

  
  [fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
  [fdo#109278]: https://bugs.freedesktop.org/show_bug.cgi?id=109278
  [fdo#109284]: https://bugs.freedesktop.org/show_bug.cgi?id=109284
  [fdo#109285]: https://bugs.freedesktop.org/show_bug.cgi?id=109285
  [fdo#109315]: https://bugs.freedesktop.org/show_bug.cgi?id=109315
  [fdo#110189]: https://bugs.freedesktop.org/show_bug.cgi?id=110189
  [fdo#111827]: https://bugs.freedesktop.org/show_bug.cgi?id=111827
  [i915#2190]: https://gitlab.freedesktop.org/drm/intel/issues/2190
  [i915#2283]: https://gitlab.freedesktop.org/drm/intel/issues/2283
  [i915#2502]: https://gitlab.freedesktop.org/drm/intel/issues/2502
  [i915#3047]: https://gitlab.freedesktop.org/drm/intel/issues/3047
  [i915#3145]: https://gitlab.freedesktop.org/drm/intel/issues/3145
  [i915#579]: https://gitlab.freedesktop.org/drm/intel/issues/579


Participating hosts (43 -> 39)
------------------------------

  Additional (1): fi-icl-y 
  Missing    (5): fi-ilk-m540 fi-hsw-4200u fi-bsw-cyan fi-dg1-1 fi-bdw-samus 


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

  * CI: CI-20190529 -> None
  * IGT: IGT_6024 -> IGTPW_5577

  CI-20190529: 20190529
  CI_DRM_9834: 8521e3afc19577adaf9200da00548826ee64e9a0 @ git://anongit.freedesktop.org/gfx-ci/linux
  IGTPW_5577: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5577/index.html
  IGT_6024: d8e03fe437f0c328c96717a92ad97719c02ba2cd @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools



== Testlist changes ==

+igt@panfrost_purgemap

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5577/index.html

[-- Attachment #1.2: Type: text/html, Size: 7372 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

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

end of thread, other threads:[~2021-03-05 11:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-05 11:12 [PATCH i-g-t 0/2] panfrost: Test accessing a purged buffer via mmap Neil Roberts
2021-03-05 11:12 ` [PATCH i-g-t 1/2] lib/panfrost: Add a utility to madvise a buffer Neil Roberts
2021-03-05 11:12 ` [PATCH i-g-t 2/2] tests/panfrost: Add a test for accessing a purged buffer Neil Roberts
2021-03-05 11:45 ` [igt-dev] ✗ Fi.CI.BAT: failure for panfrost: Test accessing a purged buffer via mmap Patchwork

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.