Skip to contentSkip to conversation

selftest: Add test for Soft-Dirty PTE bit

PATCH In review Gabriel Krisman Bertazi 2 participants 3 messages Jun 3, 2021 – Aug 13, 2021 Kselftest

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selftest: Add test for Soft-Dirty PTE bit

This introduces three tests:

1) Sanity check soft dirty basic semantics: allocate area, clean, dirty, check if the SD bit flipped.

2) Check VMA reuse: validate the VM_SOFTDIRTY usage

3) Check soft-dirty on huge pages

This was motivated by Will Deacon's fix commit 912efa17e512 ("mm: proc:
Invalidate TLB after clearing soft-dirty page state"). I was tracking the same issue that he fixed, and this test would have caught it.

--
Changes since V1:
- Fix last minute build break with page_size

---
 tools/testing/selftests/Makefile              |   1 +
 tools/testing/selftests/soft-dirty/.gitignore |   1 +
 tools/testing/selftests/soft-dirty/Makefile   |   9 +
 .../testing/selftests/soft-dirty/soft-dirty.c | 254 ++++++++++++++++++
 4 files changed, 265 insertions(+)
 create mode 100644 tools/testing/selftests/soft-dirty/.gitignore
 create mode 100644 tools/testing/selftests/soft-dirty/Makefile
 create mode 100644 tools/testing/selftests/soft-dirty/soft-dirty.c
tools/testing/selftests/Makefile +1 -0
index bc3299a20338..c8dcd7defd33 100644
@@ -55,6 +55,7 @@ TARGETS += seccomp
 TARGETS += sgx
 TARGETS += sigaltstack
 TARGETS += size
+TARGETS += soft-dirty
 TARGETS += sparc64
 TARGETS += splice
 TARGETS += static_keys
tools/testing/selftests/soft-dirty/.gitignore new file +1 -0
new file mode 100644
index 000000000000..cfb0cfda9bdf
@@ -0,0 +1 @@
+soft-dirty
tools/testing/selftests/soft-dirty/Makefile new file +9 -0
new file mode 100644
index 000000000000..d76ad8e0f10d
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0
+top_srcdir = ../../../..
+INSTALL_HDR_PATH = $(top_srcdir)/usr
+LINUX_HDR_PATH = $(INSTALL_HDR_PATH)/include/
+
+CFLAGS += -Wall -I$(LINUX_HDR_PATH) -O0 -g3
+
+TEST_GEN_PROGS := soft-dirty
+include ../lib.mk
tools/testing/selftests/soft-dirty/soft-dirty.c new file +254 -0

254 lines not on this page · raw message

Signature · 1 line
2.31.0
#1 lore raw
Quoted 19 lines · Gabriel Krisman Bertazi

This introduces three tests:

1) Sanity check soft dirty basic semantics: allocate area, clean, dirty, check if the SD bit flipped.

2) Check VMA reuse: validate the VM_SOFTDIRTY usage

3) Check soft-dirty on huge pages

This was motivated by Will Deacon's fix commit 912efa17e512 ("mm: proc:
Invalidate TLB after clearing soft-dirty page state"). I was tracking the same issue that he fixed, and this test would have caught it.

--
Changes since V1:
- Fix last minute build break with page_size

Quoted 9 lines
---
 tools/testing/selftests/Makefile              |   1 +
 tools/testing/selftests/soft-dirty/.gitignore |   1 +
 tools/testing/selftests/soft-dirty/Makefile   |   9 +
 .../testing/selftests/soft-dirty/soft-dirty.c | 254 ++++++++++++++++++
 4 files changed, 265 insertions(+)
 create mode 100644 tools/testing/selftests/soft-dirty/.gitignore
 create mode 100644 tools/testing/selftests/soft-dirty/Makefile
 create mode 100644 tools/testing/selftests/soft-dirty/soft-dirty.c

Although I think adding a test for this is great (and I certainly wouldn't want to get in the way of that; quite the opposite), I notice that we already have test_softdirty() in selftests/vm/madv_populate.c. Would we be better off extending that test instead of introducing another one?

Will

#2 lore raw
Quoted 30 lines · Will Deacon
Quoted 19 lines · Gabriel Krisman Bertazi

This introduces three tests:

1) Sanity check soft dirty basic semantics: allocate area, clean, dirty, check if the SD bit flipped.

2) Check VMA reuse: validate the VM_SOFTDIRTY usage

3) Check soft-dirty on huge pages

This was motivated by Will Deacon's fix commit 912efa17e512 ("mm: proc:
Invalidate TLB after clearing soft-dirty page state"). I was tracking the same issue that he fixed, and this test would have caught it.

--
Changes since V1:
- Fix last minute build break with page_size

Quoted 9 lines
---
 tools/testing/selftests/Makefile              |   1 +
 tools/testing/selftests/soft-dirty/.gitignore |   1 +
 tools/testing/selftests/soft-dirty/Makefile   |   9 +
 .../testing/selftests/soft-dirty/soft-dirty.c | 254 ++++++++++++++++++
 4 files changed, 265 insertions(+)
 create mode 100644 tools/testing/selftests/soft-dirty/.gitignore
 create mode 100644 tools/testing/selftests/soft-dirty/Makefile
 create mode 100644 tools/testing/selftests/soft-dirty/soft-dirty.c
Quoted 4 lines

Although I think adding a test for this is great (and I certainly wouldn't want to get in the way of that; quite the opposite), I notice that we already have test_softdirty() in selftests/vm/madv_populate.c. Would we be better off extending that test instead of introducing another one?

Hi, Will. Thanks for the review.

Looks like selftests/vm/madv_populate.c was merged after I sent this, which explains why I missed it. From a quick look, it also doesn't verify the corner case of I'm checking here. I will look into merging the two tests, or at least moving this to vm/ and remove the overlap.

Thanks,

Signature · 1 line
Gabriel Krisman Bertazi