[PATCH RFC v3 25/43] KVM: selftests: Test precision of conversion

From: Ackerley Tng

Date: Fri Mar 13 2026 - 02:27:23 EST


Enhance the guest_memfd indexing selftest to also verify the precision of
memory conversions between private and shared.

The existing test converted a single page within a multi-page mapping but
did not explicitly check the state of the surrounding pages after the
conversion loop.

Add checks to confirm that converting a single page from shared to private
only affects the target page. Iterate through all other pages in the
guest_memfd region to ensure they remain in their original shared state,
thus verifying that the conversion operation is precise and does not have
unintended side effects.

Signed-off-by: Ackerley Tng <ackerleytng@xxxxxxxxxx>
---
tools/testing/selftests/kvm/guest_memfd_conversions_test.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/kvm/guest_memfd_conversions_test.c b/tools/testing/selftests/kvm/guest_memfd_conversions_test.c
index 9dc47316112fa..b109f078bc6bd 100644
--- a/tools/testing/selftests/kvm/guest_memfd_conversions_test.c
+++ b/tools/testing/selftests/kvm/guest_memfd_conversions_test.c
@@ -227,7 +227,8 @@ GMEM_CONVERSION_TEST_INIT_SHARED(init_shared)

/*
* Test indexing of pages within guest_memfd, using test data that is a multiple
- * of page index.
+ * of page index. Also test the precision of conversion, that it does not
+ * affect surrounding pages.
*/
GMEM_CONVERSION_MULTIPAGE_TEST_INIT_SHARED(indexing, 4)
{
@@ -247,12 +248,20 @@ GMEM_CONVERSION_MULTIPAGE_TEST_INIT_SHARED(indexing, 4)
test_shared(t, i, i * 2, i * 3, i * 4);
}

+ /* Confirm that only one page was converted */
for (i = 0; i < nr_pages; ++i) {
if (i == test_page)
- test_convert_to_shared(t, i, i * 4, i * 5, i * 6);
+ test_private(t, i, i * 4, i * 6);
else
test_shared(t, i, i * 4, i * 5, i * 6);
}
+
+ for (i = 0; i < nr_pages; ++i) {
+ if (i == test_page)
+ test_convert_to_shared(t, i, i * 6, i * 7, i * 8);
+ else
+ test_shared(t, i, i * 6, i * 7, i * 8);
+ }
}

/*

--
2.53.0.851.ga537e3e6e9-goog