2022-05-06 21:06:21

by Isaku Yamahata

[permalink] [raw]
Subject: [RFC PATCH v6 036/104] KVM: x86/mmu: Explicitly check for MMIO spte in fast page fault

From: Sean Christopherson <[email protected]>

Explicitly check for an MMIO spte in the fast page fault flow. TDX will
use a not-present entry for MMIO sptes, which can be mistaken for an
access-tracked spte since both have SPTE_SPECIAL_MASK set.

MMIO sptes are handled in handle_mmio_page_fault for non-TDX VMs, so this
patch does not affect them. TDX will handle MMIO emulation through a
hypercall instead.

Signed-off-by: Sean Christopherson <[email protected]>
Signed-off-by: Isaku Yamahata <[email protected]>
---
arch/x86/kvm/mmu/mmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index d1c37295bb6e..4a12d862bbb6 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -3184,7 +3184,7 @@ static int fast_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
else
sptep = fast_pf_get_last_sptep(vcpu, fault->addr, &spte);

- if (!is_shadow_present_pte(spte))
+ if (!is_shadow_present_pte(spte) || is_mmio_spte(spte))
break;

sp = sptep_to_sp(sptep);
--
2.25.1



2022-08-01 22:58:42

by David Matlack

[permalink] [raw]
Subject: Re: [RFC PATCH v6 036/104] KVM: x86/mmu: Explicitly check for MMIO spte in fast page fault

On Thu, May 05, 2022 at 11:14:30AM -0700, [email protected] wrote:
> From: Sean Christopherson <[email protected]>
>
> Explicitly check for an MMIO spte in the fast page fault flow. TDX will
> use a not-present entry for MMIO sptes, which can be mistaken for an
> access-tracked spte since both have SPTE_SPECIAL_MASK set.
>
> MMIO sptes are handled in handle_mmio_page_fault for non-TDX VMs, so this
> patch does not affect them. TDX will handle MMIO emulation through a
> hypercall instead.
>
> Signed-off-by: Sean Christopherson <[email protected]>
> Signed-off-by: Isaku Yamahata <[email protected]>
> ---
> arch/x86/kvm/mmu/mmu.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index d1c37295bb6e..4a12d862bbb6 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
> @@ -3184,7 +3184,7 @@ static int fast_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
> else
> sptep = fast_pf_get_last_sptep(vcpu, fault->addr, &spte);
>
> - if (!is_shadow_present_pte(spte))
> + if (!is_shadow_present_pte(spte) || is_mmio_spte(spte))

I wonder if this patch is really necessary. is_shadow_present_pte()
checks if SPTE_MMU_PRESENT_MASK is set (which is bit 11, not
shadow_present_mask). Do TDX VMs set bit 11 in MMIO SPTEs?

> break;
>
> sp = sptep_to_sp(sptep);
> --
> 2.25.1
>

2022-08-01 23:34:43

by Sean Christopherson

[permalink] [raw]
Subject: Re: [RFC PATCH v6 036/104] KVM: x86/mmu: Explicitly check for MMIO spte in fast page fault

On Mon, Aug 01, 2022, David Matlack wrote:
> On Thu, May 05, 2022 at 11:14:30AM -0700, [email protected] wrote:
> > From: Sean Christopherson <[email protected]>
> >
> > Explicitly check for an MMIO spte in the fast page fault flow. TDX will
> > use a not-present entry for MMIO sptes, which can be mistaken for an
> > access-tracked spte since both have SPTE_SPECIAL_MASK set.
> >
> > MMIO sptes are handled in handle_mmio_page_fault for non-TDX VMs, so this
> > patch does not affect them. TDX will handle MMIO emulation through a
> > hypercall instead.
> >
> > Signed-off-by: Sean Christopherson <[email protected]>
> > Signed-off-by: Isaku Yamahata <[email protected]>
> > ---
> > arch/x86/kvm/mmu/mmu.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> > index d1c37295bb6e..4a12d862bbb6 100644
> > --- a/arch/x86/kvm/mmu/mmu.c
> > +++ b/arch/x86/kvm/mmu/mmu.c
> > @@ -3184,7 +3184,7 @@ static int fast_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
> > else
> > sptep = fast_pf_get_last_sptep(vcpu, fault->addr, &spte);
> >
> > - if (!is_shadow_present_pte(spte))
> > + if (!is_shadow_present_pte(spte) || is_mmio_spte(spte))
>
> I wonder if this patch is really necessary. is_shadow_present_pte()
> checks if SPTE_MMU_PRESENT_MASK is set (which is bit 11, not
> shadow_present_mask). Do TDX VMs set bit 11 in MMIO SPTEs?

This patch should be unnecessary, TDX's not-present SPTEs was one of my motivations
for adding MMU_PRESENT. Bit 11 most definitely must not be set for MMIO SPTEs.

2022-08-02 02:31:48

by Kai Huang

[permalink] [raw]
Subject: RE: [RFC PATCH v6 036/104] KVM: x86/mmu: Explicitly check for MMIO spte in fast page fault

> On Mon, Aug 01, 2022, David Matlack wrote:
> > On Thu, May 05, 2022 at 11:14:30AM -0700, [email protected] wrote:
> > > From: Sean Christopherson <[email protected]>
> > >
> > > Explicitly check for an MMIO spte in the fast page fault flow. TDX
> > > will use a not-present entry for MMIO sptes, which can be mistaken
> > > for an access-tracked spte since both have SPTE_SPECIAL_MASK set.
> > >
> > > MMIO sptes are handled in handle_mmio_page_fault for non-TDX VMs, so
> > > this patch does not affect them. TDX will handle MMIO emulation
> > > through a hypercall instead.
> > >
> > > Signed-off-by: Sean Christopherson <[email protected]>
> > > Signed-off-by: Isaku Yamahata <[email protected]>
> > > ---
> > > arch/x86/kvm/mmu/mmu.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index
> > > d1c37295bb6e..4a12d862bbb6 100644
> > > --- a/arch/x86/kvm/mmu/mmu.c
> > > +++ b/arch/x86/kvm/mmu/mmu.c
> > > @@ -3184,7 +3184,7 @@ static int fast_page_fault(struct kvm_vcpu *vcpu,
> struct kvm_page_fault *fault)
> > > else
> > > sptep = fast_pf_get_last_sptep(vcpu, fault->addr,
> &spte);
> > >
> > > - if (!is_shadow_present_pte(spte))
> > > + if (!is_shadow_present_pte(spte) || is_mmio_spte(spte))
> >
> > I wonder if this patch is really necessary. is_shadow_present_pte()
> > checks if SPTE_MMU_PRESENT_MASK is set (which is bit 11, not
> > shadow_present_mask). Do TDX VMs set bit 11 in MMIO SPTEs?
>
> This patch should be unnecessary, TDX's not-present SPTEs was one of my
> motivations
> for adding MMU_PRESENT. Bit 11 most definitely must not be set for MMIO
> SPTEs.

As we already discussed, Isaku will drop this patch.

2022-08-02 16:38:53

by David Matlack

[permalink] [raw]
Subject: Re: [RFC PATCH v6 036/104] KVM: x86/mmu: Explicitly check for MMIO spte in fast page fault

On Mon, Aug 1, 2022 at 6:46 PM Huang, Kai <[email protected]> wrote:
>
> > On Mon, Aug 01, 2022, David Matlack wrote:
> > > On Thu, May 05, 2022 at 11:14:30AM -0700, [email protected] wrote:
> > > > From: Sean Christopherson <[email protected]>
> > > >
> > > > Explicitly check for an MMIO spte in the fast page fault flow. TDX
> > > > will use a not-present entry for MMIO sptes, which can be mistaken
> > > > for an access-tracked spte since both have SPTE_SPECIAL_MASK set.
> > > >
> > > > MMIO sptes are handled in handle_mmio_page_fault for non-TDX VMs, so
> > > > this patch does not affect them. TDX will handle MMIO emulation
> > > > through a hypercall instead.
> > > >
> > > > Signed-off-by: Sean Christopherson <[email protected]>
> > > > Signed-off-by: Isaku Yamahata <[email protected]>
> > > > ---
> > > > arch/x86/kvm/mmu/mmu.c | 2 +-
> > > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index
> > > > d1c37295bb6e..4a12d862bbb6 100644
> > > > --- a/arch/x86/kvm/mmu/mmu.c
> > > > +++ b/arch/x86/kvm/mmu/mmu.c
> > > > @@ -3184,7 +3184,7 @@ static int fast_page_fault(struct kvm_vcpu *vcpu,
> > struct kvm_page_fault *fault)
> > > > else
> > > > sptep = fast_pf_get_last_sptep(vcpu, fault->addr,
> > &spte);
> > > >
> > > > - if (!is_shadow_present_pte(spte))
> > > > + if (!is_shadow_present_pte(spte) || is_mmio_spte(spte))
> > >
> > > I wonder if this patch is really necessary. is_shadow_present_pte()
> > > checks if SPTE_MMU_PRESENT_MASK is set (which is bit 11, not
> > > shadow_present_mask). Do TDX VMs set bit 11 in MMIO SPTEs?
> >
> > This patch should be unnecessary, TDX's not-present SPTEs was one of my
> > motivations
> > for adding MMU_PRESENT. Bit 11 most definitely must not be set for MMIO
> > SPTEs.
>
> As we already discussed, Isaku will drop this patch.

Ah, I missed that discussion. Can you share a link so I can catch up?

2022-08-03 00:59:00

by Kai Huang

[permalink] [raw]
Subject: Re: [RFC PATCH v6 036/104] KVM: x86/mmu: Explicitly check for MMIO spte in fast page fault

On Tue, 2022-08-02 at 09:34 -0700, David Matlack wrote:
> On Mon, Aug 1, 2022 at 6:46 PM Huang, Kai <[email protected]> wrote:
> >
> > > On Mon, Aug 01, 2022, David Matlack wrote:
> > > > On Thu, May 05, 2022 at 11:14:30AM -0700, [email protected] wrote:
> > > > > From: Sean Christopherson <[email protected]>
> > > > >
> > > > > Explicitly check for an MMIO spte in the fast page fault flow. TDX
> > > > > will use a not-present entry for MMIO sptes, which can be mistaken
> > > > > for an access-tracked spte since both have SPTE_SPECIAL_MASK set.
> > > > >
> > > > > MMIO sptes are handled in handle_mmio_page_fault for non-TDX VMs, so
> > > > > this patch does not affect them. TDX will handle MMIO emulation
> > > > > through a hypercall instead.
> > > > >
> > > > > Signed-off-by: Sean Christopherson <[email protected]>
> > > > > Signed-off-by: Isaku Yamahata <[email protected]>
> > > > > ---
> > > > > arch/x86/kvm/mmu/mmu.c | 2 +-
> > > > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > > > >
> > > > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index
> > > > > d1c37295bb6e..4a12d862bbb6 100644
> > > > > --- a/arch/x86/kvm/mmu/mmu.c
> > > > > +++ b/arch/x86/kvm/mmu/mmu.c
> > > > > @@ -3184,7 +3184,7 @@ static int fast_page_fault(struct kvm_vcpu *vcpu,
> > > struct kvm_page_fault *fault)
> > > > > else
> > > > > sptep = fast_pf_get_last_sptep(vcpu, fault->addr,
> > > &spte);
> > > > >
> > > > > - if (!is_shadow_present_pte(spte))
> > > > > + if (!is_shadow_present_pte(spte) || is_mmio_spte(spte))
> > > >
> > > > I wonder if this patch is really necessary. is_shadow_present_pte()
> > > > checks if SPTE_MMU_PRESENT_MASK is set (which is bit 11, not
> > > > shadow_present_mask). Do TDX VMs set bit 11 in MMIO SPTEs?
> > >
> > > This patch should be unnecessary, TDX's not-present SPTEs was one of my
> > > motivations
> > > for adding MMU_PRESENT. Bit 11 most definitely must not be set for MMIO
> > > SPTEs.
> >
> > As we already discussed, Isaku will drop this patch.
>
> Ah, I missed that discussion. Can you share a link so I can catch up?

Sure. Isaku has sent out v7 of this series:

https://lore.kernel.org/lkml/[email protected]/T/#m8d2229ce31b9bcd084cc43e3478154f5f24d7506

For this particular patch, see here:

https://lore.kernel.org/lkml/[email protected]/T/#mcdb118103460c55f8b850e784d1ed57724c0fe2f

--
Thanks,
-Kai