Skip to content

Commit f2228aa

Browse files
committed
KVM: selftests: Read per-page value into local var when verifying dirty_log_test
Cache the page's value during verification in a local variable, re-reading from the pointer is ugly and error prone, e.g. allows for bugs like checking the pointer itself instead of the value. No functional change intended. Reviewed-by: Maxim Levitsky <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent af2d85d commit f2228aa

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

tools/testing/selftests/kvm/dirty_log_test.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,10 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap)
520520
{
521521
uint64_t page, nr_dirty_pages = 0, nr_clean_pages = 0;
522522
uint64_t step = vm_num_host_pages(mode, 1);
523-
uint64_t *value_ptr;
524523
uint64_t min_iter = 0;
525524

526525
for (page = 0; page < host_num_pages; page += step) {
527-
value_ptr = host_test_mem + page * host_page_size;
526+
uint64_t val = *(uint64_t *)(host_test_mem + page * host_page_size);
528527

529528
/* If this is a special page that we were tracking... */
530529
if (__test_and_clear_bit_le(page, host_bmap_track)) {
@@ -545,11 +544,10 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap)
545544
* the corresponding page should be either the
546545
* previous iteration number or the current one.
547546
*/
548-
matched = (*value_ptr == iteration ||
549-
*value_ptr == iteration - 1);
547+
matched = (val == iteration || val == iteration - 1);
550548

551549
if (host_log_mode == LOG_MODE_DIRTY_RING && !matched) {
552-
if (*value_ptr == iteration - 2 && min_iter <= iteration - 2) {
550+
if (val == iteration - 2 && min_iter <= iteration - 2) {
553551
/*
554552
* Short answer: this case is special
555553
* only for dirty ring test where the
@@ -597,7 +595,7 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap)
597595
TEST_ASSERT(matched,
598596
"Set page %"PRIu64" value %"PRIu64
599597
" incorrect (iteration=%"PRIu64")",
600-
page, *value_ptr, iteration);
598+
page, val, iteration);
601599
} else {
602600
nr_clean_pages++;
603601
/*
@@ -619,11 +617,11 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap)
619617
* we'll see that page P is cleared, with
620618
* value "iteration-1".
621619
*/
622-
TEST_ASSERT(*value_ptr <= iteration,
620+
TEST_ASSERT(val <= iteration,
623621
"Clear page %"PRIu64" value %"PRIu64
624622
" incorrect (iteration=%"PRIu64")",
625-
page, *value_ptr, iteration);
626-
if (*value_ptr == iteration) {
623+
page, val, iteration);
624+
if (val == iteration) {
627625
/*
628626
* This page is _just_ modified; it
629627
* should report its dirtyness in the

0 commit comments

Comments
 (0)