Add support for physical counter offsetting to counter_state_test. Assert that guest reads of the physical counter are within the expected bounds. Reviewed-by: Peter Shier <pshier@xxxxxxxxxx> Reviewed-by: Ricardo Koller <ricarkol@xxxxxxxxxx> Signed-off-by: Oliver Upton <oupton@xxxxxxxxxx> --- .../selftests/kvm/system_counter_state_test.c | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/system_counter_state_test.c b/tools/testing/selftests/kvm/system_counter_state_test.c index 059971f6cb87..f537eb7b928c 100644 --- a/tools/testing/selftests/kvm/system_counter_state_test.c +++ b/tools/testing/selftests/kvm/system_counter_state_test.c @@ -62,11 +62,34 @@ static struct system_counter_state_test test_cases[] = { .cntvoff = -1 } }, + { + .counter = PHYSICAL, + .state = { + .flags = KVM_SYSTEM_COUNTER_STATE_PHYS_OFFSET, + .cntpoff = 0 + } + }, + { + .counter = PHYSICAL, + .state = { + .flags = KVM_SYSTEM_COUNTER_STATE_PHYS_OFFSET, + .cntpoff = 1000000 + } + }, + { + .counter = PHYSICAL, + .state = { + .flags = KVM_SYSTEM_COUNTER_STATE_PHYS_OFFSET, + .cntpoff = -1 + } + }, }; static void pr_test(struct system_counter_state_test *test) { - pr_info("counter: %s, cntvoff: %lld\n", counter_name(test->counter), test->state.cntvoff); + pr_info("counter: %s, cntvoff: %lld, cntpoff: %lld\n", + counter_name(test->counter), test->state.cntvoff, + test->state.cntpoff); } static struct kvm_system_counter_state * @@ -103,6 +126,8 @@ static uint64_t host_read_guest_counter(struct system_counter_state_test *test) r = read_cntvct_ordered(); switch (test->counter) { + case PHYSICAL: + r -= test->state.cntpoff; case VIRTUAL: r -= test->state.cntvoff; break; -- 2.32.0.rc1.229.g3e70b5a671-goog