From: Tao Su <tao1.su@linux.intel.com>
To: Sean Christopherson <seanjc@google.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, chao.gao@intel.com,
xiaoyao.li@intel.com
Subject: Re: [PATCH] KVM: selftests: x86: Prioritize getting max_gfn from GuestPhysBits
Date: Thu, 9 May 2024 13:12:57 +0800 [thread overview]
Message-ID: <ZjxbWc+qw/LRL/KY@linux.bj.intel.com> (raw)
In-Reply-To: <ZjuHrGROhuBylm4x@google.com>
On Wed, May 08, 2024 at 07:09:48AM -0700, Sean Christopherson wrote:
> On Wed, May 08, 2024, Tao Su wrote:
> > Use the max mappable GPA via GuestPhysBits advertised by KVM to calculate
> > max_gfn. Currently some selftests (e.g. access_tracking_perf_test,
> > dirty_log_test...) add RAM regions close to max_gfn, so guest may access
> > GPA beyond its mappable range and cause infinite loop.
> >
> > Prioritize obtaining pa_bits from the GuestPhysBits field advertised by
> > KVM, so max_gfn can be limited to the mappable range.
> >
> > Signed-off-by: Tao Su <tao1.su@linux.intel.com>
> > ---
> > This patch is based on https://github.com/kvm-x86/linux/commit/b628cb523c65
> > ---
> > tools/testing/selftests/kvm/include/x86_64/processor.h | 1 +
> > tools/testing/selftests/kvm/lib/x86_64/processor.c | 4 +++-
> > 2 files changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h
> > index 81ce37ec407d..ff99f66d81a0 100644
> > --- a/tools/testing/selftests/kvm/include/x86_64/processor.h
> > +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h
> > @@ -282,6 +282,7 @@ struct kvm_x86_cpu_property {
> > #define X86_PROPERTY_MAX_EXT_LEAF KVM_X86_CPU_PROPERTY(0x80000000, 0, EAX, 0, 31)
> > #define X86_PROPERTY_MAX_PHY_ADDR KVM_X86_CPU_PROPERTY(0x80000008, 0, EAX, 0, 7)
> > #define X86_PROPERTY_MAX_VIRT_ADDR KVM_X86_CPU_PROPERTY(0x80000008, 0, EAX, 8, 15)
> > +#define X86_PROPERTY_MAX_GUEST_PHY_ADDR KVM_X86_CPU_PROPERTY(0x80000008, 0, EAX, 16, 23)
> > #define X86_PROPERTY_SEV_C_BIT KVM_X86_CPU_PROPERTY(0x8000001F, 0, EBX, 0, 5)
> > #define X86_PROPERTY_PHYS_ADDR_REDUCTION KVM_X86_CPU_PROPERTY(0x8000001F, 0, EBX, 6, 11)
> >
> > diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c
> > index 74a4c736c9ae..6c69f1dfeed2 100644
> > --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c
> > +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c
> > @@ -1074,7 +1074,9 @@ void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits)
> > *pa_bits = kvm_cpu_has(X86_FEATURE_PAE) ? 36 : 32;
> > *va_bits = 32;
> > } else {
> > - *pa_bits = kvm_cpu_property(X86_PROPERTY_MAX_PHY_ADDR);
> > + *pa_bits = kvm_cpu_property(X86_PROPERTY_MAX_GUEST_PHY_ADDR);
> > + if (*pa_bits == 0)
> > + *pa_bits = kvm_cpu_property(X86_PROPERTY_MAX_PHY_ADDR);
>
> This is the wrong place to incorporaate the max mappable GPA. The pa_bits field
> should reflect the "real" MAXPHYADDR, it's vm->max_gfn that needs to be adjusted,
> and x86 selftests already overrides vm_compute_max_gfn() specifically to deal with
> goofy edge cases like this.
Thanks for pointing out! I will adjust max_gfn in the vm_compute_max_gfn() overrided
by x86 selftests.
>
> > *va_bits = kvm_cpu_property(X86_PROPERTY_MAX_VIRT_ADDR);
> > }
> > }
> >
> > base-commit: dccb07f2914cdab2ac3a5b6c98406f765acab803
> > --
> > 2.34.1
> >
prev parent reply other threads:[~2024-05-09 5:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-08 6:42 [PATCH] KVM: selftests: x86: Prioritize getting max_gfn from GuestPhysBits Tao Su
2024-05-08 14:09 ` Sean Christopherson
2024-05-09 5:12 ` Tao Su [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZjxbWc+qw/LRL/KY@linux.bj.intel.com \
--to=tao1.su@linux.intel.com \
--cc=chao.gao@intel.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=xiaoyao.li@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).