linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Maxim Levitsky <mlevitsk@redhat.com>
To: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Wanpeng Li <wanpengli@tencent.com>,
	Borislav Petkov <bp@alien8.de>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Joerg Roedel <joro@8bytes.org>, Jim Mattson <jmattson@google.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Sean Christopherson <seanjc@google.com>,
	"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
	<x86@kernel.org>, Thomas Gleixner <tglx@linutronix.de>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	Ingo Molnar <mingo@redhat.com>
Subject: Re: [PATCH 5/7] KVM: nSVM: fix running nested guests when npt=0
Date: Wed, 17 Feb 2021 17:27:11 +0200	[thread overview]
Message-ID: <a458e946b469329b03a3f58ffa7ebd48c27005bb.camel@redhat.com> (raw)
In-Reply-To: <20210217145718.1217358-6-mlevitsk@redhat.com>

On Wed, 2021-02-17 at 16:57 +0200, Maxim Levitsky wrote:
> In case of npt=0 on host,
> nSVM needs the same .inject_page_fault tweak as VMX has,
> to make sure that shadow mmu faults are injected as vmexits.
> 
> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> ---
>  arch/x86/kvm/svm/nested.c | 18 ++++++++++++++++++
>  arch/x86/kvm/svm/svm.c    |  5 ++++-
>  arch/x86/kvm/svm/svm.h    |  1 +
>  3 files changed, 23 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
> index 1bc31e2e8fe0..53b9037259b5 100644
> --- a/arch/x86/kvm/svm/nested.c
> +++ b/arch/x86/kvm/svm/nested.c
> @@ -53,6 +53,23 @@ static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu,
>  	nested_svm_vmexit(svm);
>  }
>  
> +void svm_inject_page_fault_nested(struct kvm_vcpu *vcpu, struct x86_exception *fault)
> +{
> +       struct vcpu_svm *svm = to_svm(vcpu);
> +       WARN_ON(!is_guest_mode(vcpu));
> +
> +       if (vmcb_is_intercept(&svm->nested.ctl, INTERCEPT_EXCEPTION_OFFSET + PF_VECTOR) &&
> +	   !svm->nested.nested_run_pending) {
> +               svm->vmcb->control.exit_code = SVM_EXIT_EXCP_BASE + PF_VECTOR;
> +               svm->vmcb->control.exit_code_hi = 0;
> +               svm->vmcb->control.exit_info_1 = fault->error_code;
> +               svm->vmcb->control.exit_info_2 = fault->address;
> +               nested_svm_vmexit(svm);
> +       } else {
> +               kvm_inject_page_fault(vcpu, fault);
> +       }
> +}
> +
>  static u64 nested_svm_get_tdp_pdptr(struct kvm_vcpu *vcpu, int index)
>  {
>  	struct vcpu_svm *svm = to_svm(vcpu);
> @@ -531,6 +548,7 @@ int enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb12_gpa,
>  	if (ret)
>  		return ret;
>  
> +
Sorry for this whitespace change.
Best regards,
	Maxim Levitsky
>  	svm_set_gif(svm, true);
>  
>  	return 0;
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index 74a334c9902a..59e1767df030 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -3915,7 +3915,10 @@ static void svm_load_mmu_pgd(struct kvm_vcpu *vcpu, unsigned long root,
>  
>  static void svm_complete_mmu_init(struct kvm_vcpu *vcpu)
>  {
> -
> +	if (!npt_enabled && is_guest_mode(vcpu)) {
> +		WARN_ON(mmu_is_nested(vcpu));
> +		vcpu->arch.mmu->inject_page_fault = svm_inject_page_fault_nested;
> +	}
>  }
>  
>  static int is_disabled(void)
> diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h
> index 7b6ca0e49a14..fda80d56c6e3 100644
> --- a/arch/x86/kvm/svm/svm.h
> +++ b/arch/x86/kvm/svm/svm.h
> @@ -437,6 +437,7 @@ static inline bool nested_exit_on_nmi(struct vcpu_svm *svm)
>  	return vmcb_is_intercept(&svm->nested.ctl, INTERCEPT_NMI);
>  }
>  
> +void svm_inject_page_fault_nested(struct kvm_vcpu *vcpu, struct x86_exception *fault);
>  int enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa, struct vmcb *vmcb12);
>  void svm_leave_nested(struct vcpu_svm *svm);
>  void svm_free_nested(struct vcpu_svm *svm);



  reply	other threads:[~2021-02-17 15:33 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-17 14:57 [PATCH 0/7] KVM: random nested fixes Maxim Levitsky
2021-02-17 14:57 ` [PATCH 1/7] KVM: VMX: read idt_vectoring_info a bit earlier Maxim Levitsky
2021-02-17 16:06   ` Paolo Bonzini
2021-02-17 16:18     ` Maxim Levitsky
2021-02-17 16:21       ` Sean Christopherson
2021-02-17 16:29         ` Paolo Bonzini
2021-02-17 14:57 ` [PATCH 2/7] KVM: nSVM: move nested vmrun tracepoint to enter_svm_guest_mode Maxim Levitsky
2021-02-17 14:57 ` [PATCH 3/7] KVM: x86: add .complete_mmu_init arch callback Maxim Levitsky
2021-02-17 14:57 ` [PATCH 4/7] KVM: nVMX: move inject_page_fault tweak to .complete_mmu_init Maxim Levitsky
2021-02-17 17:29   ` Sean Christopherson
2021-02-17 17:37     ` Paolo Bonzini
2021-02-17 17:57       ` Sean Christopherson
2021-02-17 18:00         ` Paolo Bonzini
2021-02-17 18:49       ` Maxim Levitsky
2021-02-17 18:43     ` Maxim Levitsky
2021-02-18  9:45       ` Paolo Bonzini
2021-02-17 14:57 ` [PATCH 5/7] KVM: nSVM: fix running nested guests when npt=0 Maxim Levitsky
2021-02-17 15:27   ` Maxim Levitsky [this message]
2021-02-17 14:57 ` [PATCH 6/7] KVM: nVMX: don't load PDPTRS right after nested state set Maxim Levitsky
2021-02-17 17:52   ` Sean Christopherson
2021-02-17 18:06     ` Paolo Bonzini
2021-02-17 14:57 ` [PATCH 7/7] KVM: nSVM: call nested_svm_load_cr3 on nested state load Maxim Levitsky

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=a458e946b469329b03a3f58ffa7ebd48c27005bb.camel@redhat.com \
    --to=mlevitsk@redhat.com \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    --cc=x86@kernel.org \
    /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 NNTP newsgroup(s).