Skip to content

Commit 6fd78be

Browse files
committed
KVM: selftests: Don't assert on exact number of 4KiB in dirty log split test
Drop dirty_log_page_splitting_test's assertion that the number of 4KiB pages remains the same across dirty logging being enabled and disabled, as the test doesn't guarantee that mappings outside of the memslots being dirty logged are stable, e.g. KVM's mappings for code and pages in memslot0 can be zapped by things like NUMA balancing. To preserve the spirit of the check, assert that (a) the number of 4KiB pages after splitting is _at least_ the number of 4KiB pages across all memslots under test, and (b) the number of hugepages before splitting adds up to the number of pages across all memslots under test. (b) is a little tenuous as it relies on memslot0 being incompatible with transparent hugepages, but that holds true for now as selftests explicitly madvise() MADV_NOHUGEPAGE for memslot0 (__vm_create() unconditionally specifies the backing type as VM_MEM_SRC_ANONYMOUS). Reported-by: Yi Lai <yi1.lai@intel.com> Reported-by: Tao Su <tao1.su@linux.intel.com> Reviewed-by: Tao Su <tao1.su@linux.intel.com> Link: https://lore.kernel.org/r/20240131222728.4100079-1-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent ba58f87 commit 6fd78be

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

tools/testing/selftests/kvm/x86_64/dirty_log_page_splitting_test.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ static void run_test(enum vm_guest_mode mode, void *unused)
9292
uint64_t host_num_pages;
9393
uint64_t pages_per_slot;
9494
int i;
95-
uint64_t total_4k_pages;
9695
struct kvm_page_stats stats_populated;
9796
struct kvm_page_stats stats_dirty_logging_enabled;
9897
struct kvm_page_stats stats_dirty_pass[ITERATIONS];
@@ -107,6 +106,9 @@ static void run_test(enum vm_guest_mode mode, void *unused)
107106
guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages);
108107
host_num_pages = vm_num_host_pages(mode, guest_num_pages);
109108
pages_per_slot = host_num_pages / SLOTS;
109+
TEST_ASSERT_EQ(host_num_pages, pages_per_slot * SLOTS);
110+
TEST_ASSERT(!(host_num_pages % 512),
111+
"Number of pages, '%lu' not a multiple of 2MiB", host_num_pages);
110112

111113
bitmaps = memstress_alloc_bitmaps(SLOTS, pages_per_slot);
112114

@@ -165,10 +167,8 @@ static void run_test(enum vm_guest_mode mode, void *unused)
165167
memstress_free_bitmaps(bitmaps, SLOTS);
166168
memstress_destroy_vm(vm);
167169

168-
/* Make assertions about the page counts. */
169-
total_4k_pages = stats_populated.pages_4k;
170-
total_4k_pages += stats_populated.pages_2m * 512;
171-
total_4k_pages += stats_populated.pages_1g * 512 * 512;
170+
TEST_ASSERT_EQ((stats_populated.pages_2m * 512 +
171+
stats_populated.pages_1g * 512 * 512), host_num_pages);
172172

173173
/*
174174
* Check that all huge pages were split. Since large pages can only
@@ -180,19 +180,22 @@ static void run_test(enum vm_guest_mode mode, void *unused)
180180
*/
181181
if (dirty_log_manual_caps) {
182182
TEST_ASSERT_EQ(stats_clear_pass[0].hugepages, 0);
183-
TEST_ASSERT_EQ(stats_clear_pass[0].pages_4k, total_4k_pages);
183+
TEST_ASSERT(stats_clear_pass[0].pages_4k >= host_num_pages,
184+
"Expected at least '%lu' 4KiB pages, found only '%lu'",
185+
host_num_pages, stats_clear_pass[0].pages_4k);
184186
TEST_ASSERT_EQ(stats_dirty_logging_enabled.hugepages, stats_populated.hugepages);
185187
} else {
186188
TEST_ASSERT_EQ(stats_dirty_logging_enabled.hugepages, 0);
187-
TEST_ASSERT_EQ(stats_dirty_logging_enabled.pages_4k, total_4k_pages);
189+
TEST_ASSERT(stats_dirty_logging_enabled.pages_4k >= host_num_pages,
190+
"Expected at least '%lu' 4KiB pages, found only '%lu'",
191+
host_num_pages, stats_dirty_logging_enabled.pages_4k);
188192
}
189193

190194
/*
191195
* Once dirty logging is disabled and the vCPUs have touched all their
192-
* memory again, the page counts should be the same as they were
196+
* memory again, the hugepage counts should be the same as they were
193197
* right after initial population of memory.
194198
*/
195-
TEST_ASSERT_EQ(stats_populated.pages_4k, stats_repopulated.pages_4k);
196199
TEST_ASSERT_EQ(stats_populated.pages_2m, stats_repopulated.pages_2m);
197200
TEST_ASSERT_EQ(stats_populated.pages_1g, stats_repopulated.pages_1g);
198201
}

0 commit comments

Comments
 (0)