From: "Radim Krčmář" <rkrcmar@redhat.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>, David Matlack <dmatlack@google.com>
Subject: [PATCH 3/3] KVM: nVMX: refactor nested_vmx_entry_failure()
Date: Wed, 21 Dec 2016 21:24:04 +0100 [thread overview]
Message-ID: <20161221202404.24020-4-rkrcmar@redhat.com> (raw)
In-Reply-To: <20161221202404.24020-1-rkrcmar@redhat.com>
Change recurring pattern
leave_guest_mode(vcpu);
vmx_load_vmcs01(vcpu);
nested_vmx_entry_failure(vcpu, ...);
return 1;
into
return nested_vmx_entry_failure(vcpu, ...)
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
arch/x86/kvm/vmx.c | 46 ++++++++++++++++------------------------------
1 file changed, 16 insertions(+), 30 deletions(-)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 050899431b5e..a74cde40e349 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -1398,7 +1398,7 @@ static inline bool is_nmi(u32 intr_info)
static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
u32 exit_intr_info,
unsigned long exit_qualification);
-static void nested_vmx_entry_failure(struct kvm_vcpu *vcpu,
+static int nested_vmx_entry_failure(struct kvm_vcpu *vcpu,
struct vmcs12 *vmcs12,
u32 reason, unsigned long qualification);
@@ -10529,20 +10529,13 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)
vmx_segment_cache_clear(vmx);
if (!nested_guest_cr0_valid(vcpu, vmcs12->guest_cr0) ||
- !nested_guest_cr4_valid(vcpu, vmcs12->guest_cr4)) {
- leave_guest_mode(vcpu);
- vmx_load_vmcs01(vcpu);
- nested_vmx_entry_failure(vcpu, vmcs12,
+ !nested_guest_cr4_valid(vcpu, vmcs12->guest_cr4))
+ return nested_vmx_entry_failure(vcpu, vmcs12,
EXIT_REASON_INVALID_STATE, ENTRY_FAIL_DEFAULT);
- return 1;
- }
- if (vmcs12->vmcs_link_pointer != -1ull) {
- leave_guest_mode(vcpu);
- vmx_load_vmcs01(vcpu);
- nested_vmx_entry_failure(vcpu, vmcs12,
+
+ if (vmcs12->vmcs_link_pointer != -1ull)
+ return nested_vmx_entry_failure(vcpu, vmcs12,
EXIT_REASON_INVALID_STATE, ENTRY_FAIL_VMCS_LINK_PTR);
- return 1;
- }
/*
* If the load IA32_EFER VM-entry control is 1, the following checks
@@ -10559,32 +10552,21 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)
ia32e != !!(vmcs12->guest_ia32_efer & EFER_LMA) ||
((vmcs12->guest_cr0 & X86_CR0_PG) &&
ia32e != !!(vmcs12->guest_ia32_efer & EFER_LME))) {
- leave_guest_mode(vcpu);
- vmx_load_vmcs01(vcpu);
- nested_vmx_entry_failure(vcpu, vmcs12,
+ return nested_vmx_entry_failure(vcpu, vmcs12,
EXIT_REASON_INVALID_STATE, ENTRY_FAIL_DEFAULT);
- return 1;
}
}
- if (prepare_vmcs02(vcpu, vmcs12, &exit_qualification)) {
- leave_guest_mode(vcpu);
- vmx_load_vmcs01(vcpu);
- nested_vmx_entry_failure(vcpu, vmcs12,
+ if (prepare_vmcs02(vcpu, vmcs12, &exit_qualification))
+ return nested_vmx_entry_failure(vcpu, vmcs12,
EXIT_REASON_INVALID_STATE, exit_qualification);
- return 1;
- }
msr_entry_idx = nested_vmx_load_msr(vcpu,
vmcs12->vm_entry_msr_load_addr,
vmcs12->vm_entry_msr_load_count);
- if (msr_entry_idx) {
- leave_guest_mode(vcpu);
- vmx_load_vmcs01(vcpu);
- nested_vmx_entry_failure(vcpu, vmcs12,
+ if (msr_entry_idx)
+ return nested_vmx_entry_failure(vcpu, vmcs12,
EXIT_REASON_MSR_LOAD_FAIL, msr_entry_idx);
- return 1;
- }
vmcs12->launch_state = 1;
@@ -11173,16 +11155,20 @@ static void vmx_leave_nested(struct kvm_vcpu *vcpu)
* It should only be called before L2 actually succeeded to run, and when
* vmcs01 is current (it doesn't leave_guest_mode() or switch vmcss).
*/
-static void nested_vmx_entry_failure(struct kvm_vcpu *vcpu,
+static int nested_vmx_entry_failure(struct kvm_vcpu *vcpu,
struct vmcs12 *vmcs12,
u32 reason, unsigned long qualification)
{
+ leave_guest_mode(vcpu);
+ vmx_load_vmcs01(vcpu);
load_vmcs12_host_state(vcpu, vmcs12);
vmcs12->vm_exit_reason = reason | VMX_EXIT_REASONS_FAILED_VMENTRY;
vmcs12->exit_qualification = qualification;
nested_vmx_succeed(vcpu);
if (enable_shadow_vmcs)
to_vmx(vcpu)->nested.sync_shadow_vmcs = true;
+
+ return 1;
}
static int vmx_check_intercept(struct kvm_vcpu *vcpu,
--
2.11.0
prev parent reply other threads:[~2016-12-21 20:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-21 20:24 [PATCH 0/3] KVM: nVMX: fix one guest vmcs check and refactor a bunch more Radim Krčmář
2016-12-21 20:24 ` [PATCH 1/3] KVM: nVMX: fix handling of invalid host efer Radim Krčmář
2016-12-21 20:24 ` [PATCH 2/3] KVM: nVMX: colocate guest vmcs checks Radim Krčmář
2016-12-21 20:24 ` Radim Krčmář [this message]
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=20161221202404.24020-4-rkrcmar@redhat.com \
--to=rkrcmar@redhat.com \
--cc=dmatlack@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.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
all inboxes | Powered by JetHome®