Re: [PATCH v11 09/35] KVM: x86: Determine shared/private faults based on vm_type

From: Sean Christopherson
Date: Mon Feb 12 2024 - 11:27:40 EST


On Mon, Feb 12, 2024, Paolo Bonzini wrote:
> On Sat, Dec 30, 2023 at 6:24 PM Michael Roth <michael.roth@xxxxxxx> wrote:
> >
> > For KVM_X86_SNP_VM, only the PFERR_GUEST_ENC_MASK flag is needed to
> > determine with an #NPF is due to a private/shared access by the guest.
> > Implement that handling here. Also add handling needed to deal with
> > SNP guests which in some cases will make MMIO accesses with the
> > encryption bit.
> >
> > Signed-off-by: Michael Roth <michael.roth@xxxxxxx>
> > ---
> > arch/x86/kvm/mmu/mmu.c | 12 ++++++++++--
> > arch/x86/kvm/mmu/mmu_internal.h | 20 +++++++++++++++++++-
> > 2 files changed, 29 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> > index d3fbfe0686a0..61213f6648a1 100644
> > --- a/arch/x86/kvm/mmu/mmu.c
> > +++ b/arch/x86/kvm/mmu/mmu.c
> > @@ -4331,6 +4331,7 @@ static int kvm_faultin_pfn_private(struct kvm_vcpu *vcpu,
> > static int __kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
> > {
> > struct kvm_memory_slot *slot = fault->slot;
> > + bool private_fault = fault->is_private;
>
> I think it's nicer to just make the fault !is_private in
> kvm_mmu_do_page_fault().

Yeah. I'm starting to recall more of this discussion. This is one of the reasons
I suggested/requested stuffing the error code to piggy-back the new SNP bit; doing
so allows is_private to be computed from the get-go without needing any vendor
specific hooks.