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@google.com>
---
.../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 9dc47316112f..b109f078bc6b 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.rc1.225.gd81095ad13-goog