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 <[email protected]>
---
 .../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 b42b1b27cb727..43efe4af1403c 100644
--- a/tools/testing/selftests/kvm/guest_memfd_conversions_test.c
+++ b/tools/testing/selftests/kvm/guest_memfd_conversions_test.c
@@ -235,7 +235,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)
 {
@@ -255,12 +256,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.51.0.858.gf9c4a03a3a-goog


Reply via email to