From: Alex Sierra <alex.sierra@amd.com>
To: <akpm@linux-foundation.org>, <Felix.Kuehling@amd.com>,
<linux-mm@kvack.org>, <rcampbell@nvidia.com>,
<linux-ext4@vger.kernel.org>, <linux-xfs@vger.kernel.org>
Cc: willy@infradead.org, apopple@nvidia.com,
dri-devel@lists.freedesktop.org, jglisse@redhat.com,
amd-gfx@lists.freedesktop.org, jgg@nvidia.com, hch@lst.de
Subject: [PATCH v2 11/11] tools: add hmm gup test for long term pinned device pages
Date: Mon, 6 Dec 2021 12:52:51 -0600 [thread overview]
Message-ID: <20211206185251.20646-12-alex.sierra@amd.com> (raw)
In-Reply-To: <20211206185251.20646-1-alex.sierra@amd.com>
The intention is to test device coherent type pages that have been
called through get user pages with PIN_LONGTERM flag set.
Signed-off-by: Alex Sierra <alex.sierra@amd.com>
---
tools/testing/selftests/vm/Makefile | 2 +-
tools/testing/selftests/vm/hmm-tests.c | 81 ++++++++++++++++++++++++++
2 files changed, 82 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile
index d9605bd10f2d..527a7bfd80bd 100644
--- a/tools/testing/selftests/vm/Makefile
+++ b/tools/testing/selftests/vm/Makefile
@@ -141,7 +141,7 @@ $(OUTPUT)/mlock-random-test $(OUTPUT)/memfd_secret: LDLIBS += -lcap
$(OUTPUT)/gup_test: ../../../../mm/gup_test.h
-$(OUTPUT)/hmm-tests: local_config.h
+$(OUTPUT)/hmm-tests: local_config.h ../../../../mm/gup_test.h
# HMM_EXTRA_LIBS may get set in local_config.mk, or it may be left empty.
$(OUTPUT)/hmm-tests: LDLIBS += $(HMM_EXTRA_LIBS)
diff --git a/tools/testing/selftests/vm/hmm-tests.c b/tools/testing/selftests/vm/hmm-tests.c
index 8eb81dfba4b3..9a0b7e44a674 100644
--- a/tools/testing/selftests/vm/hmm-tests.c
+++ b/tools/testing/selftests/vm/hmm-tests.c
@@ -36,6 +36,7 @@
* in the usual include/uapi/... directory.
*/
#include "../../../../lib/test_hmm_uapi.h"
+#include "../../../../mm/gup_test.h"
struct hmm_buffer {
void *ptr;
@@ -60,6 +61,8 @@ enum {
#define NTIMES 10
#define ALIGN(x, a) (((x) + (a - 1)) & (~((a) - 1)))
+/* Just the flags we need, copied from mm.h: */
+#define FOLL_WRITE 0x01 /* check pte is writable */
FIXTURE(hmm)
{
@@ -1723,4 +1726,82 @@ TEST_F(hmm, exclusive_cow)
hmm_buffer_free(buffer);
}
+/*
+ * Test get user device pages through gup_test. Setting PIN_LONGTERM flag.
+ * This should trigger a migration back to system memory for both, private
+ * and coherent type pages.
+ * This test makes use of gup_test module. Make sure GUP_TEST_CONFIG is added
+ * to your configuration before you run it.
+ */
+TEST_F(hmm, hmm_gup_test)
+{
+ struct hmm_buffer *buffer;
+ struct gup_test gup;
+ int gup_fd;
+ unsigned long npages;
+ unsigned long size;
+ unsigned long i;
+ int *ptr;
+ int ret;
+ unsigned char *m;
+
+ gup_fd = open("/sys/kernel/debug/gup_test", O_RDWR);
+ if (gup_fd == -1)
+ SKIP(return, "Skipping test, could not find gup_test driver");
+
+ npages = 4;
+ ASSERT_NE(npages, 0);
+ size = npages << self->page_shift;
+
+ buffer = malloc(sizeof(*buffer));
+ ASSERT_NE(buffer, NULL);
+
+ buffer->fd = -1;
+ buffer->size = size;
+ buffer->mirror = malloc(size);
+ ASSERT_NE(buffer->mirror, NULL);
+
+ buffer->ptr = mmap(NULL, size,
+ PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS,
+ buffer->fd, 0);
+ ASSERT_NE(buffer->ptr, MAP_FAILED);
+
+ /* Initialize buffer in system memory. */
+ for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i)
+ ptr[i] = i;
+
+ /* Migrate memory to device. */
+ ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages);
+ ASSERT_EQ(ret, 0);
+ ASSERT_EQ(buffer->cpages, npages);
+ /* Check what the device read. */
+ for (i = 0, ptr = buffer->mirror; i < size / sizeof(*ptr); ++i)
+ ASSERT_EQ(ptr[i], i);
+
+ gup.nr_pages_per_call = npages;
+ gup.addr = (unsigned long)buffer->ptr;
+ gup.gup_flags = FOLL_WRITE;
+ gup.size = size;
+ /*
+ * Calling gup_test ioctl. It will try to PIN_LONGTERM these device pages
+ * causing a migration back to system memory for both, private and coherent
+ * type pages.
+ */
+ if (ioctl(gup_fd, PIN_LONGTERM_BENCHMARK, &gup)) {
+ perror("ioctl on PIN_LONGTERM_BENCHMARK\n");
+ goto out_test;
+ }
+
+ /* Take snapshot to make sure pages have been migrated to sys memory */
+ ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_SNAPSHOT, buffer, npages);
+ ASSERT_EQ(ret, 0);
+ ASSERT_EQ(buffer->cpages, npages);
+ m = buffer->mirror;
+ for (i = 0; i < npages; i++)
+ ASSERT_EQ(m[i], HMM_DMIRROR_PROT_WRITE);
+out_test:
+ close(gup_fd);
+ hmm_buffer_free(buffer);
+}
TEST_HARNESS_MAIN
--
2.32.0
next prev parent reply other threads:[~2021-12-06 18:53 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-06 18:52 [PATCH v2 00/11] Add MEMORY_DEVICE_COHERENT for coherent device memory mapping Alex Sierra
2021-12-06 18:52 ` [PATCH v2 01/11] mm: add zone device coherent type memory support Alex Sierra
2021-12-06 18:52 ` [PATCH v2 02/11] mm: add device coherent vma selection for memory migration Alex Sierra
2021-12-06 18:52 ` [PATCH v2 03/11] mm/gup: migrate PIN_LONGTERM dev coherent pages to system Alex Sierra
2021-12-08 11:31 ` Alistair Popple
2021-12-08 13:53 ` Jason Gunthorpe
2021-12-09 1:45 ` Alistair Popple
2021-12-09 2:53 ` Jason Gunthorpe
2021-12-08 16:58 ` Felix Kuehling
2021-12-08 17:30 ` Felix Kuehling
2021-12-08 18:55 ` Sierra Guiza, Alejandro (Alex)
2021-12-09 10:53 ` Alistair Popple
2021-12-09 16:29 ` Felix Kuehling
2021-12-09 16:54 ` Sierra Guiza, Alejandro (Alex)
2021-12-10 1:31 ` Alistair Popple
2021-12-10 16:39 ` Felix Kuehling
2021-12-06 18:52 ` [PATCH v2 04/11] drm/amdkfd: add SPM support for SVM Alex Sierra
2021-12-06 18:52 ` [PATCH v2 05/11] drm/amdkfd: coherent type as sys mem on migration to ram Alex Sierra
2021-12-06 18:52 ` [PATCH v2 06/11] lib: test_hmm add ioctl to get zone device type Alex Sierra
2021-12-06 18:52 ` [PATCH v2 07/11] lib: test_hmm add module param for " Alex Sierra
2021-12-06 18:52 ` [PATCH v2 08/11] lib: add support for device coherent type in test_hmm Alex Sierra
2022-01-03 20:24 ` Liam Howlett
2021-12-06 18:52 ` [PATCH v2 09/11] tools: update hmm-test to support device coherent type Alex Sierra
2021-12-06 18:52 ` [PATCH v2 10/11] tools: update test_hmm script to support SP config Alex Sierra
2021-12-06 18:52 ` Alex Sierra [this message]
2021-12-07 19:31 ` [PATCH v2 11/11] tools: add hmm gup test for long term pinned device pages Jason Gunthorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211206185251.20646-12-alex.sierra@amd.com \
--to=alex.sierra@amd.com \
--cc=Felix.Kuehling@amd.com \
--cc=akpm@linux-foundation.org \
--cc=amd-gfx@lists.freedesktop.org \
--cc=apopple@nvidia.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=hch@lst.de \
--cc=jgg@nvidia.com \
--cc=jglisse@redhat.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-xfs@vger.kernel.org \
--cc=rcampbell@nvidia.com \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).