On Wed, 2022-12-14 at 13:39 -0600, Michael Roth wrote: > From: Nikunj A Dadhania <nikunj@xxxxxxx> > > KVM should use private memory for guests that have upm_mode flag set. > > Add a kvm_x86_ops hook for determining UPM support that accounts for > this situation by only enabling UPM test mode in the case of non-SEV > guests. > > Signed-off-by: Nikunj A Dadhania <nikunj@xxxxxxx> > [mdr: add x86 hook for determining restricted/private memory support] > Signed-off-by: Michael Roth <michael.roth@xxxxxxx> > --- > arch/x86/include/asm/kvm-x86-ops.h | 1 + > arch/x86/include/asm/kvm_host.h | 1 + > arch/x86/kvm/svm/svm.c | 10 ++++++++++ > arch/x86/kvm/x86.c | 8 ++++++++ > 4 files changed, 20 insertions(+) > > diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h > index abccd51dcfca..f530a550c092 100644 > --- a/arch/x86/include/asm/kvm-x86-ops.h > +++ b/arch/x86/include/asm/kvm-x86-ops.h > @@ -131,6 +131,7 @@ KVM_X86_OP(msr_filter_changed) > KVM_X86_OP(complete_emulated_msr) > KVM_X86_OP(vcpu_deliver_sipi_vector) > KVM_X86_OP_OPTIONAL_RET0(vcpu_get_apicv_inhibit_reasons); > +KVM_X86_OP_OPTIONAL_RET0(private_mem_enabled); > > #undef KVM_X86_OP > #undef KVM_X86_OP_OPTIONAL > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index 2b6244525107..9317abffbf68 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -1635,6 +1635,7 @@ struct kvm_x86_ops { > > void (*load_mmu_pgd)(struct kvm_vcpu *vcpu, hpa_t root_hpa, > int root_level); > + int (*private_mem_enabled)(struct kvm *kvm); > > bool (*has_wbinvd_exit)(void); > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index 91352d692845..7f3e4d91c0c6 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c > @@ -4694,6 +4694,14 @@ static int svm_vm_init(struct kvm *kvm) > return 0; > } > > +static int svm_private_mem_enabled(struct kvm *kvm) > +{ > + if (sev_guest(kvm)) > + return kvm->arch.upm_mode ? 1 : 0; > + > + return IS_ENABLED(CONFIG_HAVE_KVM_PRIVATE_MEM_TESTING) ? 1 : 0; > +} > + Is this new callback really needed? Shouldn't kvm->arch.upm_mode be sufficient enough to indicate whether the private memory will be used or not? Probably the CONFIG_HAVE_KVM_PRIVATE_MEM_TESTING is the concern here. But this Kconfig option is not even x86-specific, so shouldn't the handling of it be done in common code too? For instance, can we explicitly set 'kvm->arch.upm_mode' to 'true' at some point of creating the VM if we see CONFIG_HAVE_KVM_PRIVATE_MEM_TESTING is true? [snip]