Re: [PATCH] selftests: KVM: avoid failures due to reserved HyperTransport region

From: Maxim Levitsky
Date: Thu Aug 05 2021 - 07:23:39 EST


On Thu, 2021-08-05 at 06:54 -0400, Paolo Bonzini wrote:
> Accessing guest physical addresses at 0xFFFD_0000_0000 and above causes
> a failure on AMD processors because those addresses are reserved by
> HyperTransport (this is not documented). Avoid selftests failures
> by reserving those guest physical addresses.
>
> Fixes: ef4c9f4f6546 ("KVM: selftests: Fix 32-bit truncation of vm_get_max_gfn()")
> Cc: stable@xxxxxxxxxxxxxxx
> Cc: David Matlack <dmatlack@xxxxxxxxxx>
> Reported-by: Maxim Levitsky <mlevitsk@xxxxxxxxxx>
> Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
> ---
> tools/testing/selftests/kvm/lib/kvm_util.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> index 10a8ed691c66..d995cc9836ee 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> @@ -309,6 +309,12 @@ struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm)
> /* Limit physical addresses to PA-bits. */
> vm->max_gfn = ((1ULL << vm->pa_bits) >> vm->page_shift) - 1;
>
> +#ifdef __x86_64__
> + /* Avoid reserved HyperTransport region on AMD processors. */
> + if (vm->pa_bits == 48)
> + vm->max_gfn = 0xfffcfffff;
> +#endif
> +
> /* Allocate and setup memory for guest. */
> vm->vpages_mapped = sparsebit_alloc();
> if (phy_pages != 0)

I probably would have restricted this workaround to AMD vendor string,
but I don't mind this to be like that as well at least for now.

Reviewed-by: Maxim Levitsky <mlevitsk@xxxxxxxxxx>

Best regards,
Maxim Levitsky