Skip to contentSkip to conversation

mm/hmm/test: add self tests for HMM

PATCH Superseded Ralph Campbell 4 participants 17 messages Mar 21, 2020 – Apr 15, 2020

Subsystems (5)

v8 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v8 cover mm/hmm/test: add self tests for HMM

This series adds basic self tests for HMM and are intended for Jason Gunthorpe's rdma tree which has a number of HMM patches applied.

Changes v7 -> v8:
Rebased to Jason's rdma/hmm tree, plus Jason's 6 patch series
"Small hmm_range_fault() cleanups".
Applied a number of changes from Jason's comments.

Changes v6 -> v7:
Rebased to linux-5.6.0-rc6
Reverted back to just using mmu_interval_notifier_insert() and making
this series only introduce HMM self tests.

Changes v5 -> v6:
Rebased to linux-5.5.0-rc6
Refactored mmu interval notifier patches Converted nouveau to use the new mmu interval notifier API

Changes v4 -> v5:
Added mmu interval notifier insert/remove/update callable from the
invalidate() callback
Updated HMM tests to use the new core interval notifier API

Changes v1 -> v4:
https://lore.kernel.org/linux-mm/[email protected]

Ralph Campbell (3):
mm/hmm/test: add selftest driver for HMM
mm/hmm/test: add selftests for HMM
MAINTAINERS: add HMM selftests

 MAINTAINERS                            |    3 +
 include/uapi/linux/test_hmm.h          |   59 ++
 lib/Kconfig.debug                      |   12 +
 lib/Makefile                           |    1 +
 lib/test_hmm.c                         | 1177 +++++++++++++++++++++
 tools/testing/selftests/vm/.gitignore  |    1 +
 tools/testing/selftests/vm/Makefile    |    3 +
 tools/testing/selftests/vm/config      |    2 +
 tools/testing/selftests/vm/hmm-tests.c | 1353 ++++++++++++++++++++++++
 tools/testing/selftests/vm/run_vmtests |   16 +
 tools/testing/selftests/vm/test_hmm.sh |   97 ++
 11 files changed, 2724 insertions(+)
 create mode 100644 include/uapi/linux/test_hmm.h
 create mode 100644 lib/test_hmm.c
 create mode 100644 tools/testing/selftests/vm/hmm-tests.c
 create mode 100755 tools/testing/selftests/vm/test_hmm.sh
Signature · 1 line
2.20.1
#1 lore raw

PATCH v8 1/3 mm/hmm/test: add selftest driver for HMM

This driver is for testing device private memory migration and devices which use hmm_range_fault() to access system memory via device page tables.

---
 include/uapi/linux/test_hmm.h |   59 ++
 lib/Kconfig.debug             |   12 +
 lib/Makefile                  |    1 +
 lib/test_hmm.c                | 1177 +++++++++++++++++++++++++++++++++
 4 files changed, 1249 insertions(+)
 create mode 100644 include/uapi/linux/test_hmm.h
 create mode 100644 lib/test_hmm.c
include/uapi/linux/test_hmm.h new file +59 -0
new file mode 100644
index 000000000000..8c5f70c160bf
@@ -0,0 +1,59 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * This is a module to test the HMM (Heterogeneous Memory Management) API
+ * of the kernel. It allows a userspace program to expose its entire address
+ * space through the HMM test module device file.
+ */
+#ifndef _UAPI_LINUX_HMM_DMIRROR_H
+#define _UAPI_LINUX_HMM_DMIRROR_H
+
+#include <linux/types.h>
+#include <linux/ioctl.h>
+
+/*
+ * Structure to pass to the HMM test driver to mimic a device accessing
+ * system memory and ZONE_DEVICE private memory through device page tables.
+ *
+ * @addr: (in) user address the device will read/write
+ * @ptr: (in) user address where device data is copied to/from
+ * @npages: (in) number of pages to read/write
+ * @cpages: (out) number of pages copied
+ * @faults: (out) number of device page faults seen
+ */
+struct hmm_dmirror_cmd {
+	__u64		addr;
+	__u64		ptr;
+	__u64		npages;
+	__u64		cpages;
+	__u64		faults;
+};
+
+/* Expose the address space of the calling process through hmm device file */
+#define HMM_DMIRROR_READ		_IOWR('H', 0x00, struct hmm_dmirror_cmd)
+#define HMM_DMIRROR_WRITE		_IOWR('H', 0x01, struct hmm_dmirror_cmd)
+#define HMM_DMIRROR_MIGRATE		_IOWR('H', 0x02, struct hmm_dmirror_cmd)
+#define HMM_DMIRROR_SNAPSHOT		_IOWR('H', 0x03, struct hmm_dmirror_cmd)
+
+/*
+ * Values returned in hmm_dmirror_cmd.ptr for HMM_DMIRROR_SNAPSHOT.
+ * HMM_DMIRROR_PROT_ERROR: no valid mirror PTE for this page
+ * HMM_DMIRROR_PROT_NONE: unpopulated PTE or PTE with no access
+ * HMM_DMIRROR_PROT_READ: read-only PTE
+ * HMM_DMIRROR_PROT_WRITE: read/write PTE
+ * HMM_DMIRROR_PROT_ZERO: special read-only zero page
+ * HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL: Migrated device private page on the
+ *					device the ioctl() is made
+ * HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE: Migrated device private page on some
+ *					other device
+ */
+enum {
+	HMM_DMIRROR_PROT_ERROR			= 0xFF,
+	HMM_DMIRROR_PROT_NONE			= 0x00,
+	HMM_DMIRROR_PROT_READ			= 0x01,
+	HMM_DMIRROR_PROT_WRITE			= 0x02,
+	HMM_DMIRROR_PROT_ZERO			= 0x10,
+	HMM_DMIRROR_PROT_DEV_PRIVATE_LOCAL	= 0x20,
+	HMM_DMIRROR_PROT_DEV_PRIVATE_REMOTE	= 0x30,
+};
+
+#endif /* _UAPI_LINUX_HMM_DMIRROR_H */
lib/Kconfig.debug +12 -0
index 69def4a9df00..f777e1215e33 100644
@@ -2162,6 +2162,18 @@ config TEST_MEMINIT
 
 	  If unsure, say N.
 
+config TEST_HMM
+	tristate "Test HMM (Heterogeneous Memory Management)"
+	depends on DEVICE_PRIVATE
+	select HMM_MIRROR
+	select MMU_NOTIFIER
+	help
+	  This is a pseudo device driver solely for testing HMM.
+	  Say M here if you want to build the HMM test module.
+	  Doing so will allow you to run tools/testing/selftest/vm/hmm-tests.
+
+	  If unsure, say N.
+
 endif # RUNTIME_TESTING_MENU
 
 config MEMTEST
lib/Makefile +1 -0
index 611872c06926..c168bdc803dc 100644
@@ -89,6 +89,7 @@ obj-$(CONFIG_TEST_OBJAGG) += test_objagg.o
 obj-$(CONFIG_TEST_STACKINIT) += test_stackinit.o
 obj-$(CONFIG_TEST_BLACKHOLE_DEV) += test_blackhole_dev.o
 obj-$(CONFIG_TEST_MEMINIT) += test_meminit.o
+obj-$(CONFIG_TEST_HMM) += test_hmm.o
 
 obj-$(CONFIG_TEST_LIVEPATCH) += livepatch/
 
lib/test_hmm.c new file +1177 -0

1,177 lines not on this page · raw message

Signature · 1 line
2.20.1
#2 lore raw

PATCH v8 2/3 mm/hmm/test: add selftests for HMM

In reply to Ralph Campbell

Add some basic stand alone self tests for HMM.
The test program and shell scripts use the test_hmm.ko driver to exercise HMM functionality in the kernel.

---
 tools/testing/selftests/vm/.gitignore  |    1 +
 tools/testing/selftests/vm/Makefile    |    3 +
 tools/testing/selftests/vm/config      |    2 +
 tools/testing/selftests/vm/hmm-tests.c | 1353 ++++++++++++++++++++++++
 tools/testing/selftests/vm/run_vmtests |   16 +
 tools/testing/selftests/vm/test_hmm.sh |   97 ++
 6 files changed, 1472 insertions(+)
 create mode 100644 tools/testing/selftests/vm/hmm-tests.c
 create mode 100755 tools/testing/selftests/vm/test_hmm.sh
tools/testing/selftests/vm/.gitignore +1 -0
index 31b3c98b6d34..3054565b3f07 100644
@@ -14,3 +14,4 @@ virtual_address_range
 gup_benchmark
 va_128TBswitch
 map_fixed_noreplace
+hmm-tests
tools/testing/selftests/vm/Makefile +3 -0
index 7f9a8a8c31da..3fadab99d991 100644
@@ -7,6 +7,7 @@ CFLAGS = -Wall -I ../../../../usr/include $(EXTRA_CFLAGS)
 LDLIBS = -lrt
 TEST_GEN_FILES = compaction_test
 TEST_GEN_FILES += gup_benchmark
+TEST_GEN_FILES += hmm-tests
 TEST_GEN_FILES += hugepage-mmap
 TEST_GEN_FILES += hugepage-shm
 TEST_GEN_FILES += map_hugetlb
@@ -31,6 +32,8 @@ TEST_FILES := test_vmalloc.sh
 KSFT_KHDR_INSTALL := 1
 include ../lib.mk
 
+$(OUTPUT)/hmm-tests: LDLIBS += -lhugetlbfs -lpthread
+
 $(OUTPUT)/userfaultfd: LDLIBS += -lpthread
 
 $(OUTPUT)/mlock-random-test: LDLIBS += -lcap
tools/testing/selftests/vm/config +2 -0
index 93b90a9b1eeb..6b64d61ec455 100644
@@ -1,3 +1,5 @@
 CONFIG_SYSVIPC=y
 CONFIG_USERFAULTFD=y
 CONFIG_TEST_VMALLOC=m
+CONFIG_DEVICE_PRIVATE=y
+CONFIG_TEST_HMM=y
tools/testing/selftests/vm/hmm-tests.c new file +1353 -0

1,353 lines not on this page · raw message

tools/testing/selftests/vm/run_vmtests +16 -0
index f33714843198..5e82b2574d54 100755
@@ -270,4 +270,20 @@ else
 	exitcode=1
 fi
 
+echo "------------------------------------"
+echo "running HMM smoke test"
+echo "------------------------------------"
+./test_hmm.sh smoke
+ret_val=$?
+
+if [ $ret_val -eq 0 ]; then
+	echo "[PASS]"
+elif [ $ret_val -eq $ksft_skip ]; then
+	echo "[SKIP]"
+	exitcode=$ksft_skip
+else
+	echo "[FAIL]"
+	exitcode=1
+fi
+
 exit $exitcode
tools/testing/selftests/vm/test_hmm.sh new file +97 -0

97 lines not on this page · raw message

Signature · 1 line
2.20.1
#3 lore raw

PATCH v8 3/3 MAINTAINERS: add HMM selftests

In reply to Ralph Campbell

Add files for HMM selftests.

---
 MAINTAINERS | 3 +++
 1 file changed, 3 insertions(+)
MAINTAINERS +3 -0
index fcd79fc38928..d9f5869d6cda 100644
@@ -7610,7 +7610,10 @@ L:	[email protected]
 S:	Maintained
 F:	mm/hmm*
 F:	include/linux/hmm*
+F:	include/uapi/linux/test_hmm*
 F:	Documentation/vm/hmm.rst
+F:	lib/test_hmm*
+F:	tools/testing/selftests/vm/*hmm*
 
 HOST AP DRIVER
 M:	Jouni Malinen <[email protected]>
Signature · 1 line
2.20.1
#4 lore raw
In reply to Ralph Campbell
Quoted 26 lines · Ralph Campbell

This series adds basic self tests for HMM and are intended for Jason Gunthorpe's rdma tree which has a number of HMM patches applied.

Changes v7 -> v8:
Rebased to Jason's rdma/hmm tree, plus Jason's 6 patch series
"Small hmm_range_fault() cleanups".
Applied a number of changes from Jason's comments.

Changes v6 -> v7:
Rebased to linux-5.6.0-rc6
Reverted back to just using mmu_interval_notifier_insert() and making
this series only introduce HMM self tests.

Changes v5 -> v6:
Rebased to linux-5.5.0-rc6
Refactored mmu interval notifier patches Converted nouveau to use the new mmu interval notifier API

Changes v4 -> v5:
Added mmu interval notifier insert/remove/update callable from the
invalidate() callback
Updated HMM tests to use the new core interval notifier API

Changes v1 -> v4:
https://lore.kernel.org/linux-mm/[email protected]

Quoted 7 lines

Ralph Campbell (3):
mm/hmm/test: add selftest driver for HMM
mm/hmm/test: add selftests for HMM
MAINTAINERS: add HMM selftests

 MAINTAINERS                            |    3 +
 include/uapi/linux/test_hmm.h          |   59 ++

Isn't UAPI folder supposed to be for user-visible interfaces that follow the rule of non-breaking user space and not for selftests?

Thanks

#5 lore raw
Quoted 32 lines · Leon Romanovsky
Quoted 31 lines · Ralph Campbell

This series adds basic self tests for HMM and are intended for Jason Gunthorpe's rdma tree which has a number of HMM patches applied.

Changes v7 -> v8:
Rebased to Jason's rdma/hmm tree, plus Jason's 6 patch series
"Small hmm_range_fault() cleanups".
Applied a number of changes from Jason's comments.

Changes v6 -> v7:
Rebased to linux-5.6.0-rc6
Reverted back to just using mmu_interval_notifier_insert() and making
this series only introduce HMM self tests.

Changes v5 -> v6:
Rebased to linux-5.5.0-rc6
Refactored mmu interval notifier patches Converted nouveau to use the new mmu interval notifier API

Changes v4 -> v5:
Added mmu interval notifier insert/remove/update callable from the
invalidate() callback
Updated HMM tests to use the new core interval notifier API

Changes v1 -> v4:
https://lore.kernel.org/linux-mm/[email protected]

Ralph Campbell (3):
mm/hmm/test: add selftest driver for HMM
mm/hmm/test: add selftests for HMM
MAINTAINERS: add HMM selftests

Quoted 8 lines
Quoted 2 lines
  MAINTAINERS                            |    3 +
  include/uapi/linux/test_hmm.h          |   59 ++

Isn't UAPI folder supposed to be for user-visible interfaces that follow the rule of non-breaking user space and not for selftests?

Thanks

Most of the other kernel module tests seem to invoke the test as part of the module load/init. I'm open to moving it if there is a more appropriate location.

#6 lore raw
Quoted 37 lines · Ralph Campbell
Quoted 35 lines · Leon Romanovsky
Quoted 33 lines · Ralph Campbell

This series adds basic self tests for HMM and are intended for Jason Gunthorpe's rdma tree which has a number of HMM patches applied.

Changes v7 -> v8:
Rebased to Jason's rdma/hmm tree, plus Jason's 6 patch series
"Small hmm_range_fault() cleanups".
Applied a number of changes from Jason's comments.

Changes v6 -> v7:
Rebased to linux-5.6.0-rc6
Reverted back to just using mmu_interval_notifier_insert() and making
this series only introduce HMM self tests.

Changes v5 -> v6:
Rebased to linux-5.5.0-rc6
Refactored mmu interval notifier patches Converted nouveau to use the new mmu interval notifier API

Changes v4 -> v5:
Added mmu interval notifier insert/remove/update callable from the
invalidate() callback
Updated HMM tests to use the new core interval notifier API

Changes v1 -> v4:
https://lore.kernel.org/linux-mm/[email protected]

Ralph Campbell (3):
mm/hmm/test: add selftest driver for HMM
mm/hmm/test: add selftests for HMM
MAINTAINERS: add HMM selftests

  MAINTAINERS                            |    3 +
  include/uapi/linux/test_hmm.h          |   59 ++
Quoted 8 lines
Quoted 5 lines

Isn't UAPI folder supposed to be for user-visible interfaces that follow the rule of non-breaking user space and not for selftests?

Thanks

Most of the other kernel module tests seem to invoke the test as part of the module load/init. I'm open to moving it if there is a more appropriate location.

Is it even possible to create a user mm_struct and put crazy things in it soley from a kernel module?

Jason

#7 lore raw
Quoted 41 lines · Jason Gunthorpe
Quoted 40 lines · Ralph Campbell
Quoted 38 lines · Leon Romanovsky
Quoted 26 lines · Ralph Campbell

This series adds basic self tests for HMM and are intended for Jason Gunthorpe's rdma tree which has a number of HMM patches applied.

Changes v7 -> v8:
Rebased to Jason's rdma/hmm tree, plus Jason's 6 patch series
"Small hmm_range_fault() cleanups".
Applied a number of changes from Jason's comments.

Changes v6 -> v7:
Rebased to linux-5.6.0-rc6
Reverted back to just using mmu_interval_notifier_insert() and making
this series only introduce HMM self tests.

Changes v5 -> v6:
Rebased to linux-5.5.0-rc6
Refactored mmu interval notifier patches Converted nouveau to use the new mmu interval notifier API

Changes v4 -> v5:
Added mmu interval notifier insert/remove/update callable from the
invalidate() callback
Updated HMM tests to use the new core interval notifier API

Changes v1 -> v4:
https://lore.kernel.org/linux-mm/[email protected]

Quoted 7 lines

Ralph Campbell (3):
mm/hmm/test: add selftest driver for HMM
mm/hmm/test: add selftests for HMM
MAINTAINERS: add HMM selftests

  MAINTAINERS                            |    3 +
  include/uapi/linux/test_hmm.h          |   59 ++

Isn't UAPI folder supposed to be for user-visible interfaces that follow the rule of non-breaking user space and not for selftests?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Thanks

Most of the other kernel module tests seem to invoke the test as part of the module load/init. I'm open to moving it if there is a more appropriate location.

Is it even possible to create a user mm_struct and put crazy things in it soley from a kernel module?

I didn't look very closely of what Ralph did in his patchsets, but from what I know, if you want in-kernel interface, you use in-kernel module, if you want to test user visible uapi, you write application. You don't create new UAPI just to test something in the kernel.

Can kunit help here?
https://www.kernel.org/doc/html/latest/dev-tools/kunit/index.html

Thanks

Quoted 3 lines

Jason

#8 lore raw
Quoted 56 lines · Leon Romanovsky
Quoted 41 lines · Jason Gunthorpe
Quoted 40 lines · Ralph Campbell
Quoted 38 lines · Leon Romanovsky
Quoted 26 lines · Ralph Campbell

This series adds basic self tests for HMM and are intended for Jason Gunthorpe's rdma tree which has a number of HMM patches applied.

Changes v7 -> v8:
Rebased to Jason's rdma/hmm tree, plus Jason's 6 patch series
"Small hmm_range_fault() cleanups".
Applied a number of changes from Jason's comments.

Changes v6 -> v7:
Rebased to linux-5.6.0-rc6
Reverted back to just using mmu_interval_notifier_insert() and making
this series only introduce HMM self tests.

Changes v5 -> v6:
Rebased to linux-5.5.0-rc6
Refactored mmu interval notifier patches Converted nouveau to use the new mmu interval notifier API

Changes v4 -> v5:
Added mmu interval notifier insert/remove/update callable from the
invalidate() callback
Updated HMM tests to use the new core interval notifier API

Changes v1 -> v4:
https://lore.kernel.org/linux-mm/[email protected]

Quoted 7 lines

Ralph Campbell (3):
mm/hmm/test: add selftest driver for HMM
mm/hmm/test: add selftests for HMM
MAINTAINERS: add HMM selftests

   MAINTAINERS                            |    3 +
   include/uapi/linux/test_hmm.h          |   59 ++

Isn't UAPI folder supposed to be for user-visible interfaces that follow the rule of non-breaking user space and not for selftests?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Thanks

Most of the other kernel module tests seem to invoke the test as part of the module load/init. I'm open to moving it if there is a more appropriate location.

Is it even possible to create a user mm_struct and put crazy things in it soley from a kernel module?

I didn't look very closely of what Ralph did in his patchsets, but from what I know, if you want in-kernel interface, you use in-kernel module, if you want to test user visible uapi, you write application. You don't create new UAPI just to test something in the kernel.

Quoted 7 lines

Can kunit help here?
https://www.kernel.org/doc/html/latest/dev-tools/kunit/index.html

Thanks

Quoted 2 lines

Jason

The tests are intended to cover hmm_range_fault() and the migrate_vma_setup(), migrate_vma_pages(), and migrate_vma_finalize() kernel functions that a device driver can call to initialize hardware that has its own page tables. An example is a GPU where the code on the GPU sees the same address space as code running on the host CPU. This means the test has to have a user process to create a user process address space and a device driver to simulate some real device driver. The UAPI is for the user level test program to tell the kernel module test driver what to do and return results.
The complexity is all around maintaining coherent copies of the user process page tables while hardware and CPUs are accessing the same physical addresses. The pages are not pinned as with most I/O so system activity like pagein/pageout, LRU page reclaim, compaction, and the process calling functions like mmap(), mprotect(), madvise(), fork(), etc. all update the CPU and device page tables and would be very hard to duplicate in a kernel level only KUNIT style of test.

#9 lore raw
In reply to Leon Romanovsky
Quoted 48 lines · Leon Romanovsky
Quoted 47 lines · Jason Gunthorpe
Quoted 45 lines · Ralph Campbell
Quoted 32 lines · Leon Romanovsky
Quoted 31 lines · Ralph Campbell

This series adds basic self tests for HMM and are intended for Jason Gunthorpe's rdma tree which has a number of HMM patches applied.

Changes v7 -> v8:
Rebased to Jason's rdma/hmm tree, plus Jason's 6 patch series
"Small hmm_range_fault() cleanups".
Applied a number of changes from Jason's comments.

Changes v6 -> v7:
Rebased to linux-5.6.0-rc6
Reverted back to just using mmu_interval_notifier_insert() and making
this series only introduce HMM self tests.

Changes v5 -> v6:
Rebased to linux-5.5.0-rc6
Refactored mmu interval notifier patches Converted nouveau to use the new mmu interval notifier API

Changes v4 -> v5:
Added mmu interval notifier insert/remove/update callable from the
invalidate() callback
Updated HMM tests to use the new core interval notifier API

Changes v1 -> v4:
https://lore.kernel.org/linux-mm/[email protected]

Ralph Campbell (3):
mm/hmm/test: add selftest driver for HMM
mm/hmm/test: add selftests for HMM
MAINTAINERS: add HMM selftests

Quoted 8 lines
Quoted 2 lines
  MAINTAINERS                            |    3 +
  include/uapi/linux/test_hmm.h          |   59 ++

Isn't UAPI folder supposed to be for user-visible interfaces that follow the rule of non-breaking user space and not for selftests?

Thanks

Most of the other kernel module tests seem to invoke the test as part of the module load/init. I'm open to moving it if there is a more appropriate location.

Quoted 7 lines
Quoted 2 lines

Is it even possible to create a user mm_struct and put crazy things in it soley from a kernel module?

I didn't look very closely of what Ralph did in his patchsets, but from what I know, if you want in-kernel interface, you use in-kernel module, if you want to test user visible uapi, you write application. You don't create new UAPI just to test something in the kernel.

That works fine as long as the in-kernel interfaces don't require user created objects like mm_struct and vmas, which is the case here.

So there must be some special uAPI between the kerne/user to make it work.

Jason

#10 lore raw
In reply to Ralph Campbell
Quoted 2 lines · Ralph Campbell

This series adds basic self tests for HMM and are intended for Jason Gunthorpe's rdma tree which has a number of HMM patches applied.

We are at v8 of this series and noboy from the selftests land has commented, can someone help?

Jason

#11 lore raw
In reply to Ralph Campbell
Quoted 2 lines · Ralph Campbell

This series adds basic self tests for HMM and are intended for Jason Gunthorpe's rdma tree which has a number of HMM patches applied.

Here are some hunks I noticed while testing this:

lib/Kconfig.debug +2 -1
@@ -2201,7 +2201,8 @@ config TEST_MEMINIT
 
 config TEST_HMM
 	tristate "Test HMM (Heterogeneous Memory Management)"
-	depends on DEVICE_PRIVATE
+	depends on TRANSPARENT_HUGEPAGE
+	select DEVICE_PRIVATE
 	select HMM_MIRROR
 	select MMU_NOTIFIER
 	help

It fails testing if TRANSPARENT_HUGEPAGE is not on

@@ -1097,6 +1071,7 @@ static int dmirror_device_init(struct dmirror_device *mdevice, int id)
spin_lock_init(&mdevice->lock);

cdev_init(&mdevice->cdevice, &dmirror_fops);
+ mdevice->cdevice.owner = THIS_MODULE;
ret = cdev_add(&mdevice->cdevice, dev, 1); if (ret)
return ret;

The use of cdev without a struct device is super weird, but it still needs this

tools/testing/selftests/vm/test_hmm.sh +1 -1
index 461e4a99a362cf..0647b525a62564 100755
@@ -59,7 +59,7 @@ run_smoke()
 	echo "Running smoke test. Note, this test provides basic coverage."
 
 	load_driver
-	./hmm-tests
+	$(dirname "${BASH_SOURCE[0]}")/hmm-tests
 	unload_driver
 }
 

Make it runnably reliably

Jason

#12 lore raw
Quoted 48 lines · Jason Gunthorpe
Quoted 2 lines · Ralph Campbell

This series adds basic self tests for HMM and are intended for Jason Gunthorpe's rdma tree which has a number of HMM patches applied.

Here are some hunks I noticed while testing this:

lib/Kconfig.debug +2 -1
@@ -2201,7 +2201,8 @@ config TEST_MEMINIT
 
  config TEST_HMM
  	tristate "Test HMM (Heterogeneous Memory Management)"
-	depends on DEVICE_PRIVATE
+	depends on TRANSPARENT_HUGEPAGE
+	select DEVICE_PRIVATE
  	select HMM_MIRROR
  	select MMU_NOTIFIER
  	help

It fails testing if TRANSPARENT_HUGEPAGE is not on

lib/Kconfig.debug +1 -0
@@ -1097,6 +1071,7 @@ static int dmirror_device_init(struct dmirror_device *mdevice, int id)
  	spin_lock_init(&mdevice->lock);
 
  	cdev_init(&mdevice->cdevice, &dmirror_fops);
+	mdevice->cdevice.owner = THIS_MODULE;
  	ret = cdev_add(&mdevice->cdevice, dev, 1);
  	if (ret)
  		return ret;

The use of cdev without a struct device is super weird, but it still needs this

tools/testing/selftests/vm/test_hmm.sh +1 -1
index 461e4a99a362cf..0647b525a62564 100755
@@ -59,7 +59,7 @@ run_smoke()
  	echo "Running smoke test. Note, this test provides basic coverage."
 
  	load_driver
-	./hmm-tests
+	$(dirname "${BASH_SOURCE[0]}")/hmm-tests
  	unload_driver
  }
 

Make it runnably reliably

Quoted 1 line

Jason

Thanks for the fixes. I'll apply these and send a v9.
I will also add missing calls to release_mem_region() to free the reserved device private addresses.

#13 lore raw
Quoted 45 lines · Ralph Campbell
Quoted 43 lines · Jason Gunthorpe
Quoted 2 lines · Ralph Campbell

This series adds basic self tests for HMM and are intended for Jason Gunthorpe's rdma tree which has a number of HMM patches applied.

Here are some hunks I noticed while testing this:

lib/Kconfig.debug +2 -1
@@ -2201,7 +2201,8 @@ config TEST_MEMINIT
  config TEST_HMM
  	tristate "Test HMM (Heterogeneous Memory Management)"
-	depends on DEVICE_PRIVATE
+	depends on TRANSPARENT_HUGEPAGE
+	select DEVICE_PRIVATE
  	select HMM_MIRROR
  	select MMU_NOTIFIER
  	help
 

It fails testing if TRANSPARENT_HUGEPAGE is not on

lib/Kconfig.debug +1 -0
@@ -1097,6 +1071,7 @@ static int dmirror_device_init(struct dmirror_device *mdevice, int id)
  	spin_lock_init(&mdevice->lock);
  	cdev_init(&mdevice->cdevice, &dmirror_fops);
+	mdevice->cdevice.owner = THIS_MODULE;
  	ret = cdev_add(&mdevice->cdevice, dev, 1);
  	if (ret)
  		return ret;
 

The use of cdev without a struct device is super weird, but it still needs this

tools/testing/selftests/vm/test_hmm.sh +1 -1
index 461e4a99a362cf..0647b525a62564 100755
@@ -59,7 +59,7 @@ run_smoke()
  	echo "Running smoke test. Note, this test provides basic coverage."
  	load_driver
-	./hmm-tests
+	$(dirname "${BASH_SOURCE[0]}")/hmm-tests
  	unload_driver
  }
 
Quoted 7 lines
Quoted 3 lines

Make it runnably reliably

Jason

Thanks for the fixes. I'll apply these and send a v9.
I will also add missing calls to release_mem_region() to free the reserved device private addresses.

If you decide to ignore my request to avoid addition of special header file to UAPI, at least don't copy and install that file without some special CONFIG option (TEST_HMM ???) requested by the users. It also will be good to get Acked-by on this change from HMM people.

However, I still think that include/uapi/linux/test_hmm.h opens pandora box of having UAPI files without real promise to keep it backward compatible.

Thanks

Quoted 1 line
#14 lore raw
Quoted 52 lines · Leon Romanovsky
Quoted 43 lines · Ralph Campbell
Quoted 41 lines · Jason Gunthorpe
Quoted 2 lines · Ralph Campbell

This series adds basic self tests for HMM and are intended for Jason Gunthorpe's rdma tree which has a number of HMM patches applied.

Here are some hunks I noticed while testing this:

+++ b/lib/Kconfig.debug

lib/Kconfig.debug +2 -1
@@ -2201,7 +2201,8 @@ config TEST_MEMINIT
  config TEST_HMM
  	tristate "Test HMM (Heterogeneous Memory Management)"
-	depends on DEVICE_PRIVATE
+	depends on TRANSPARENT_HUGEPAGE
+	select DEVICE_PRIVATE
  	select HMM_MIRROR
  	select MMU_NOTIFIER
  	help
 

It fails testing if TRANSPARENT_HUGEPAGE is not on

(quoted diff) +1 -0
@@ -1097,6 +1071,7 @@ static int dmirror_device_init(struct dmirror_device *mdevice, int id)
  	spin_lock_init(&mdevice->lock);
  	cdev_init(&mdevice->cdevice, &dmirror_fops);
+	mdevice->cdevice.owner = THIS_MODULE;
  	ret = cdev_add(&mdevice->cdevice, dev, 1);
  	if (ret)
  		return ret;
 

The use of cdev without a struct device is super weird, but it still needs this

tools/testing/selftests/vm/test_hmm.sh +2 -1
index 461e4a99a362cf..0647b525a62564 100755
+++ b/tools/testing/selftests/vm/test_hmm.sh
@@ -59,7 +59,7 @@ run_smoke()
  	echo "Running smoke test. Note, this test provides basic coverage."
  	load_driver
-	./hmm-tests
+	$(dirname "${BASH_SOURCE[0]}")/hmm-tests
  	unload_driver
  }
 
Quoted 7 lines
Quoted 3 lines

Make it runnably reliably

Jason

Thanks for the fixes. I'll apply these and send a v9.
I will also add missing calls to release_mem_region() to free the reserved device private addresses.

Quoted 8 lines

If you decide to ignore my request to avoid addition of special header file to UAPI, at least don't copy and install that file without some special CONFIG option (TEST_HMM ???) requested by the users. It also will be good to get Acked-by on this change from HMM people.

However, I still think that include/uapi/linux/test_hmm.h opens pandora box of having UAPI files without real promise to keep it backward compatible.

It would be nice if we could put the header outside the uapi directory and outside the install machinery

Maybe for now hackery some relative include like
#include "../../../lib/hmm_test_uapi.h"

?

I don't see any sane way to avoid the dedicate module and special ioctl though.

Jason

#15 lore raw
In reply to Leon Romanovsky
Quoted 59 lines · Leon Romanovsky
Quoted 45 lines · Ralph Campbell
Quoted 43 lines · Jason Gunthorpe
Quoted 2 lines · Ralph Campbell

This series adds basic self tests for HMM and are intended for Jason Gunthorpe's rdma tree which has a number of HMM patches applied.

Here are some hunks I noticed while testing this:

lib/Kconfig.debug +2 -1
@@ -2201,7 +2201,8 @@ config TEST_MEMINIT
   config TEST_HMM
   	tristate "Test HMM (Heterogeneous Memory Management)"
-	depends on DEVICE_PRIVATE
+	depends on TRANSPARENT_HUGEPAGE
+	select DEVICE_PRIVATE
   	select HMM_MIRROR
   	select MMU_NOTIFIER
   	help
 

It fails testing if TRANSPARENT_HUGEPAGE is not on

lib/Kconfig.debug +1 -0
@@ -1097,6 +1071,7 @@ static int dmirror_device_init(struct dmirror_device *mdevice, int id)
   	spin_lock_init(&mdevice->lock);
   	cdev_init(&mdevice->cdevice, &dmirror_fops);
+	mdevice->cdevice.owner = THIS_MODULE;
   	ret = cdev_add(&mdevice->cdevice, dev, 1);
   	if (ret)
   		return ret;
 

The use of cdev without a struct device is super weird, but it still needs this

tools/testing/selftests/vm/test_hmm.sh +1 -1
index 461e4a99a362cf..0647b525a62564 100755
@@ -59,7 +59,7 @@ run_smoke()
   	echo "Running smoke test. Note, this test provides basic coverage."
   	load_driver
-	./hmm-tests
+	$(dirname "${BASH_SOURCE[0]}")/hmm-tests
   	unload_driver
   }
 
Quoted 7 lines
Quoted 3 lines

Make it runnably reliably

Jason

Thanks for the fixes. I'll apply these and send a v9.
I will also add missing calls to release_mem_region() to free the reserved device private addresses.

If you decide to ignore my request to avoid addition of special header file to UAPI, at least don't copy and install that file without some special CONFIG option (TEST_HMM ???) requested by the users. It also will be good to get Acked-by on this change from HMM people.

Quoted 5 lines

However, I still think that include/uapi/linux/test_hmm.h opens pandora box of having UAPI files without real promise to keep it backward compatible.

Thanks

I think that is a valid point. I would expect the test<->driver UAPI to track the kernel version since the sources are "released" together. I suppose a version number could be included in the request structure to handle mismatch driver and test program but that may be overkill.
Are you suggesting that include/linux/test_hmm.h is a better location?

#16 lore raw
Quoted 65 lines · Ralph Campbell
Quoted 63 lines · Leon Romanovsky
Quoted 45 lines · Ralph Campbell
Quoted 43 lines · Jason Gunthorpe
Quoted 2 lines · Ralph Campbell

This series adds basic self tests for HMM and are intended for Jason Gunthorpe's rdma tree which has a number of HMM patches applied.

Here are some hunks I noticed while testing this:

lib/Kconfig.debug +2 -1
@@ -2201,7 +2201,8 @@ config TEST_MEMINIT
   config TEST_HMM
   	tristate "Test HMM (Heterogeneous Memory Management)"
-	depends on DEVICE_PRIVATE
+	depends on TRANSPARENT_HUGEPAGE
+	select DEVICE_PRIVATE
   	select HMM_MIRROR
   	select MMU_NOTIFIER
   	help
 

It fails testing if TRANSPARENT_HUGEPAGE is not on

lib/Kconfig.debug +1 -0
@@ -1097,6 +1071,7 @@ static int dmirror_device_init(struct dmirror_device *mdevice, int id)
   	spin_lock_init(&mdevice->lock);
   	cdev_init(&mdevice->cdevice, &dmirror_fops);
+	mdevice->cdevice.owner = THIS_MODULE;
   	ret = cdev_add(&mdevice->cdevice, dev, 1);
   	if (ret)
   		return ret;
 

The use of cdev without a struct device is super weird, but it still needs this

tools/testing/selftests/vm/test_hmm.sh +1 -1
index 461e4a99a362cf..0647b525a62564 100755
@@ -59,7 +59,7 @@ run_smoke()
   	echo "Running smoke test. Note, this test provides basic coverage."
   	load_driver
-	./hmm-tests
+	$(dirname "${BASH_SOURCE[0]}")/hmm-tests
   	unload_driver
   }
 
Quoted 7 lines
Quoted 3 lines

Make it runnably reliably

Jason

Thanks for the fixes. I'll apply these and send a v9.
I will also add missing calls to release_mem_region() to free the reserved device private addresses.

If you decide to ignore my request to avoid addition of special header file to UAPI, at least don't copy and install that file without some special CONFIG option (TEST_HMM ???) requested by the users. It also will be good to get Acked-by on this change from HMM people.

However, I still think that include/uapi/linux/test_hmm.h opens pandora box of having UAPI files without real promise to keep it backward compatible.

Quoted 6 lines
Quoted 1 line

Thanks

I think that is a valid point. I would expect the test<->driver UAPI to track the kernel version since the sources are "released" together. I suppose a version number could be included in the request structure to handle mismatch driver and test program but that may be overkill.

Yes, it is really overkill.

Quoted 1 line

Are you suggesting that include/linux/test_hmm.h is a better location?

It is one of options, another option maybe similar to that is done in scripts/mod/modpost.c [1], where C file is generated on the fly.

[1] https://lore.kernel.org/netdev/[email protected]