From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Maxim Levitsky <mlevitsk@redhat.com>,
Ben Gardon <bgardon@google.com>,
David Matlack <dmatlack@google.com>
Subject: Re: [PATCH] KVM: x86/mmu: Do not create SPTEs for GFNs that exceed host.MAXPHYADDR
Date: Fri, 29 Apr 2022 14:24:35 +0000 [thread overview]
Message-ID: <Ymv1I5ixX1+k8Nst@google.com> (raw)
In-Reply-To: <337332ca-835c-087c-c99b-92c35ea8dcd3@redhat.com>
On Fri, Apr 29, 2022, Paolo Bonzini wrote:
> On 4/29/22 01:34, Sean Christopherson wrote:
>
> > +static inline gfn_t kvm_mmu_max_gfn_host(void)
> > +{
> > + /*
> > + * Disallow SPTEs (via memslots or cached MMIO) whose gfn would exceed
> > + * host.MAXPHYADDR. Assuming KVM is running on bare metal, guest
> > + * accesses beyond host.MAXPHYADDR will hit a #PF(RSVD) and never hit
> > + * an EPT Violation/Misconfig / #NPF, and so KVM will never install a
> > + * SPTE for such addresses. That doesn't hold true if KVM is running
> > + * as a VM itself, e.g. if the MAXPHYADDR KVM sees is less than
> > + * hardware's real MAXPHYADDR, but since KVM can't honor such behavior
> > + * on bare metal, disallow it entirely to simplify e.g. the TDP MMU.
> > + */
> > + return (1ULL << (shadow_phys_bits - PAGE_SHIFT)) - 1;
>
> The host.MAXPHYADDR however does not matter if EPT/NPT is not in use, because
> the shadow paging fault path can accept any gfn.
...
> diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
> index e6cae6f22683..dba275d323a7 100644
> --- a/arch/x86/kvm/mmu.h
> +++ b/arch/x86/kvm/mmu.h
> @@ -65,6 +65,30 @@ static __always_inline u64 rsvd_bits(int s, int e)
> return ((2ULL << (e - s)) - 1) << s;
> }
> +/*
> + * The number of non-reserved physical address bits irrespective of features
> + * that repurpose legal bits, e.g. MKTME.
> + */
> +extern u8 __read_mostly shadow_phys_bits;
> +
> +static inline gfn_t kvm_mmu_max_gfn(void)
> +{
> + /*
> + * Note that this uses the host MAXPHYADDR, not the guest's.
> + * EPT/NPT cannot support GPAs that would exceed host.MAXPHYADDR;
> + * assuming KVM is running on bare metal, guest accesses beyond
> + * host.MAXPHYADDR will hit a #PF(RSVD) and never cause a vmexit
> + * (either EPT Violation/Misconfig or #NPF), and so KVM will never
> + * install a SPTE for such addresses. If KVM is running as a VM
> + * itself, on the other hand, it might see a MAXPHYADDR that is less
> + * than hardware's real MAXPHYADDR. Using the host MAXPHYADDR
> + * disallows such SPTEs entirely and simplifies the TDP MMU.
> + */
> + int max_gpa_bits = likely(tdp_enabled) ? shadow_phys_bits : 52;
I don't love the divergent memslot behavior, but it's technically correct, so I
can't really argue. Do we want to "officially" document the memslot behavior?
> +
> + return (1ULL << (max_gpa_bits - PAGE_SHIFT)) - 1;
> +}
> +
> void kvm_mmu_set_mmio_spte_mask(u64 mmio_value, u64 mmio_mask, u64 access_mask);
> void kvm_mmu_set_ept_masks(bool has_ad_bits, bool has_exec_only);
next prev parent reply other threads:[~2022-04-29 14:24 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-28 23:34 [PATCH] KVM: x86/mmu: Do not create SPTEs for GFNs that exceed host.MAXPHYADDR Sean Christopherson
2022-04-29 10:36 ` Paolo Bonzini
2022-04-29 14:24 ` Sean Christopherson [this message]
2022-04-29 14:37 ` Paolo Bonzini
2022-04-29 14:42 ` Sean Christopherson
2022-04-29 14:50 ` Paolo Bonzini
2022-04-29 16:01 ` Sean Christopherson
2022-05-01 14:28 ` Maxim Levitsky
2022-05-01 14:32 ` Maxim Levitsky
2022-05-02 7:59 ` Maxim Levitsky
2022-05-02 8:56 ` Maxim Levitsky
2022-05-02 16:51 ` Sean Christopherson
[not found] ` <e11c21e99e7c4ac758b4417e0ae66d3a2f1fe663.camel@redhat.com>
2022-05-03 15:12 ` Maxim Levitsky
2022-05-03 20:30 ` Sean Christopherson
2022-05-04 12:08 ` Maxim Levitsky
2022-05-04 14:47 ` Sean Christopherson
2022-05-04 19:11 ` Paolo Bonzini
2022-05-02 11:12 ` Kai Huang
2022-05-02 11:52 ` Paolo Bonzini
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=Ymv1I5ixX1+k8Nst@google.com \
--to=seanjc@google.com \
--cc=bgardon@google.com \
--cc=dmatlack@google.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mlevitsk@redhat.com \
--cc=pbonzini@redhat.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.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