diff mbox series

selftests/kvm: touch all pages of args on each memstress iteration

Message ID 20230412200913.1570873-1-pbonzini@redhat.com (mailing list archive)
State New, archived
Headers show
Series selftests/kvm: touch all pages of args on each memstress iteration | expand

Commit Message

Paolo Bonzini April 12, 2023, 8:09 p.m. UTC
Access the same memory addresses on each iteration of the memstress
guest code.  This ensures that the state of KVM's page tables
is the same after every iteration, including the pages that host the
guest page tables for args and vcpu_args.

This difference is visible on the dirty_log_page_splitting_test
on AMD machines.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 tools/testing/selftests/kvm/lib/memstress.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Vipin Sharma April 13, 2023, 5:36 p.m. UTC | #1
On Wed, Apr 12, 2023 at 1:09 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> Access the same memory addresses on each iteration of the memstress
> guest code.  This ensures that the state of KVM's page tables
> is the same after every iteration, including the pages that host the
> guest page tables for args and vcpu_args.
>

AMD and eptad=0 reasoning you gave in
https://lore.kernel.org/lkml/199f404d-c08e-3895-6ce3-36b21514f487@redhat.com
should also be included here.

"It also reproduces on Intel with pml=0 and eptad=0; the reason is due
to the different semantics of dirty bits for page-table pages on AMD
and Intel.  Both AMD and eptad=0 Intel treat those as writes, therefore
more pages are dropped before the repopulation phase when dirty logging
is disabled.

The "missing" page had been included in the population phase because it
hosts the page tables for vcpu_args, but repopulation does not need it."

> This difference is visible on the dirty_log_page_splitting_test
> on AMD machines.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  tools/testing/selftests/kvm/lib/memstress.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/tools/testing/selftests/kvm/lib/memstress.c b/tools/testing/selftests/kvm/lib/memstress.c
> index 3632956c6bcf..df457452d146 100644
> --- a/tools/testing/selftests/kvm/lib/memstress.c
> +++ b/tools/testing/selftests/kvm/lib/memstress.c
> @@ -65,6 +65,9 @@ void memstress_guest_code(uint32_t vcpu_idx)
>         GUEST_ASSERT(vcpu_args->vcpu_idx == vcpu_idx);
>
>         while (true) {
> +               for (i = 0; i < sizeof(memstress_args); i += args->guest_page_size)
> +                       (void) *((volatile char *)args + i);
> +
>                 for (i = 0; i < pages; i++) {
>                         if (args->random_access)
>                                 page = guest_random_u32(&rand_state) % pages;
> --
> 2.39.1
>

Apart from the commit log.
Reviewed-by: Vipin Sharma <vipinsh@google.com>
Sean Christopherson June 2, 2023, 1:23 a.m. UTC | #2
On Wed, 12 Apr 2023 16:09:13 -0400, Paolo Bonzini wrote:
> Access the same memory addresses on each iteration of the memstress
> guest code.  This ensures that the state of KVM's page tables
> is the same after every iteration, including the pages that host the
> guest page tables for args and vcpu_args.
> 
> This difference is visible on the dirty_log_page_splitting_test
> on AMD machines.
> 
> [...]

Applied to kvm-x86 selftests, thanks!

[1/1] selftests/kvm: touch all pages of args on each memstress iteration
      https://github.com/kvm-x86/linux/commit/07b4b2f4047f

--
https://github.com/kvm-x86/linux/tree/next
https://github.com/kvm-x86/linux/tree/fixes
diff mbox series

Patch

diff --git a/tools/testing/selftests/kvm/lib/memstress.c b/tools/testing/selftests/kvm/lib/memstress.c
index 3632956c6bcf..df457452d146 100644
--- a/tools/testing/selftests/kvm/lib/memstress.c
+++ b/tools/testing/selftests/kvm/lib/memstress.c
@@ -65,6 +65,9 @@  void memstress_guest_code(uint32_t vcpu_idx)
 	GUEST_ASSERT(vcpu_args->vcpu_idx == vcpu_idx);
 
 	while (true) {
+		for (i = 0; i < sizeof(memstress_args); i += args->guest_page_size)
+			(void) *((volatile char *)args + i);
+
 		for (i = 0; i < pages; i++) {
 			if (args->random_access)
 				page = guest_random_u32(&rand_state) % pages;