From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Sean Christopherson <seanjc@google.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 28/43] KVM: nVMX: Don't evaluate "emulation required" on VM-Exit
Date: Fri, 23 Apr 2021 17:46:30 -0700 [thread overview]
Message-ID: <20210424004645.3950558-29-seanjc@google.com> (raw)
In-Reply-To: <20210424004645.3950558-1-seanjc@google.com>
Use the "internal" variants of setting segment registers when stuffing
state on nested VM-Exit in order to skip the "emulation required"
updates. VM-Exit must always go to protected mode, and all segments are
mostly hardcoded (to valid values) on VM-Exit. The bits of the segments
that aren't hardcoded are explicitly checked during VM-Enter, e.g. the
selector RPLs must all be zero.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/vmx/nested.c | 16 ++++++++--------
arch/x86/kvm/vmx/vmx.c | 6 ++----
arch/x86/kvm/vmx/vmx.h | 2 +-
3 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 32126fa0c4d8..f811bb7f2dc3 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -4245,7 +4245,7 @@ static void load_vmcs12_host_state(struct kvm_vcpu *vcpu,
seg.l = 1;
else
seg.db = 1;
- vmx_set_segment(vcpu, &seg, VCPU_SREG_CS);
+ __vmx_set_segment(vcpu, &seg, VCPU_SREG_CS);
seg = (struct kvm_segment) {
.base = 0,
.limit = 0xFFFFFFFF,
@@ -4256,17 +4256,17 @@ static void load_vmcs12_host_state(struct kvm_vcpu *vcpu,
.g = 1
};
seg.selector = vmcs12->host_ds_selector;
- vmx_set_segment(vcpu, &seg, VCPU_SREG_DS);
+ __vmx_set_segment(vcpu, &seg, VCPU_SREG_DS);
seg.selector = vmcs12->host_es_selector;
- vmx_set_segment(vcpu, &seg, VCPU_SREG_ES);
+ __vmx_set_segment(vcpu, &seg, VCPU_SREG_ES);
seg.selector = vmcs12->host_ss_selector;
- vmx_set_segment(vcpu, &seg, VCPU_SREG_SS);
+ __vmx_set_segment(vcpu, &seg, VCPU_SREG_SS);
seg.selector = vmcs12->host_fs_selector;
seg.base = vmcs12->host_fs_base;
- vmx_set_segment(vcpu, &seg, VCPU_SREG_FS);
+ __vmx_set_segment(vcpu, &seg, VCPU_SREG_FS);
seg.selector = vmcs12->host_gs_selector;
seg.base = vmcs12->host_gs_base;
- vmx_set_segment(vcpu, &seg, VCPU_SREG_GS);
+ __vmx_set_segment(vcpu, &seg, VCPU_SREG_GS);
seg = (struct kvm_segment) {
.base = vmcs12->host_tr_base,
.limit = 0x67,
@@ -4274,11 +4274,11 @@ static void load_vmcs12_host_state(struct kvm_vcpu *vcpu,
.type = 11,
.present = 1
};
- vmx_set_segment(vcpu, &seg, VCPU_SREG_TR);
+ __vmx_set_segment(vcpu, &seg, VCPU_SREG_TR);
memset(&seg, 0, sizeof(seg));
seg.unusable = 1;
- vmx_set_segment(vcpu, &seg, VCPU_SREG_LDTR);
+ __vmx_set_segment(vcpu, &seg, VCPU_SREG_LDTR);
kvm_set_dr(vcpu, 7, 0x400);
vmcs_write64(GUEST_IA32_DEBUGCTL, 0);
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 37bfa20a04dd..594975dc3f94 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -2827,8 +2827,6 @@ static __init int alloc_kvm_area(void)
return 0;
}
-static void __vmx_set_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg);
-
static void fix_pmode_seg(struct kvm_vcpu *vcpu, int seg,
struct kvm_segment *save)
{
@@ -3401,7 +3399,7 @@ static u32 vmx_segment_access_rights(struct kvm_segment *var)
return ar;
}
-static void __vmx_set_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg)
+void __vmx_set_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
const struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
@@ -3438,7 +3436,7 @@ static void __vmx_set_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, in
vmcs_write32(sf->ar_bytes, vmx_segment_access_rights(var));
}
-void vmx_set_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg)
+static void vmx_set_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg)
{
__vmx_set_segment(vcpu, var, seg);
diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h
index 19fe09fad2fe..1283ad0e592d 100644
--- a/arch/x86/kvm/vmx/vmx.h
+++ b/arch/x86/kvm/vmx/vmx.h
@@ -376,7 +376,7 @@ void vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4);
void set_cr4_guest_host_mask(struct vcpu_vmx *vmx);
void ept_save_pdptrs(struct kvm_vcpu *vcpu);
void vmx_get_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg);
-void vmx_set_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg);
+void __vmx_set_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg);
u64 construct_eptp(struct kvm_vcpu *vcpu, hpa_t root_hpa, int root_level);
void vmx_update_exception_bitmap(struct kvm_vcpu *vcpu);
--
2.31.1.498.g6c1eba8ee3d-goog
next prev parent reply other threads:[~2021-04-24 0:52 UTC|newest]
Thread overview: 88+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-24 0:46 [PATCH 00/43] KVM: x86: vCPU RESET/INIT fixes and consolidation Sean Christopherson
2021-04-24 0:46 ` [PATCH 01/43] KVM: nVMX: Set LDTR to its architecturally defined value on nested VM-Exit Sean Christopherson
2021-05-19 5:30 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 02/43] KVM: VMX: Set EDX at INIT with CPUID.0x1, Family-Model-Stepping Sean Christopherson
2021-05-19 5:59 ` Reiji Watanabe
2021-05-19 18:47 ` Sean Christopherson
2021-05-21 7:07 ` Reiji Watanabe
2021-05-21 15:28 ` Sean Christopherson
2021-05-24 4:29 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 03/43] KVM: SVM: Require exact CPUID.0x1 match when stuffing EDX at INIT Sean Christopherson
2021-05-19 5:30 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 04/43] KVM: SVM: Fall back to KVM's hardcoded value for EDX at RESET/INIT Sean Christopherson
2021-05-19 5:41 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 05/43] KVM: x86: Split out CR0/CR4 MMU role change detectors to separate helpers Sean Christopherson
2021-05-19 5:31 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 06/43] KVM: x86: Properly reset MMU context at vCPU RESET/INIT Sean Christopherson
2021-05-17 16:57 ` Reiji Watanabe
2021-05-18 20:23 ` Sean Christopherson
2021-05-18 22:42 ` Reiji Watanabe
2021-05-19 17:16 ` Sean Christopherson
2021-05-24 4:57 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 07/43] KVM: VMX: Remove explicit MMU reset in enter_rmode() Sean Christopherson
2021-04-24 0:46 ` [PATCH 08/43] KVM: SVM: Drop explicit MMU reset at RESET/INIT Sean Christopherson
2021-05-19 5:32 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 09/43] KVM: SVM: Drop a redundant init_vmcb() from svm_create_vcpu() Sean Christopherson
2021-05-19 5:32 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 10/43] KVM: VMX: Move init_vmcs() invocation to vmx_vcpu_reset() Sean Christopherson
2021-05-19 5:33 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 11/43] KVM: x86: WARN if the APIC map is dirty without an in-kernel local APIC Sean Christopherson
2021-04-24 0:46 ` [PATCH 12/43] KVM: x86: Remove defunct BSP "update" in local APIC reset Sean Christopherson
2021-05-26 6:54 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 13/43] KVM: x86: Migrate the PIT only if vcpu0 is migrated, not any BSP Sean Christopherson
2021-04-24 0:46 ` [PATCH 14/43] KVM: x86: Don't force set BSP bit when local APIC is managed by userspace Sean Christopherson
2021-05-26 6:55 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 15/43] KVM: x86: Set BSP bit in reset BSP vCPU's APIC base by default Sean Christopherson
2021-05-26 6:55 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 16/43] KVM: VMX: Stuff vcpu->arch.apic_base directly at vCPU RESET Sean Christopherson
2021-05-26 6:55 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 17/43] KVM: x86: Open code necessary bits of kvm_lapic_set_base() " Sean Christopherson
2021-05-26 7:04 ` Reiji Watanabe
2021-05-26 15:15 ` Sean Christopherson
2021-04-24 0:46 ` [PATCH 18/43] KVM: x86: Consolidate APIC base RESET initialization code Sean Christopherson
2021-05-26 7:04 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 19/43] KVM: x86: Move EDX initialization at vCPU RESET to common code Sean Christopherson
2021-05-19 5:45 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 20/43] KVM: SVM: Don't bother writing vmcb->save.rip at vCPU RESET/INIT Sean Christopherson
2021-05-19 5:34 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 21/43] KVM: VMX: Invert handling of CR0.WP for EPT without unrestricted guest Sean Christopherson
2021-04-24 0:46 ` [PATCH 22/43] KVM: VMX: Remove direct write to vcpu->arch.cr0 during vCPU RESET/INIT Sean Christopherson
2021-05-19 5:34 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 23/43] KVM: VMX: Fold ept_update_paging_mode_cr0() back into vmx_set_cr0() Sean Christopherson
2021-04-24 0:46 ` [PATCH 24/43] KVM: nVMX: Do not clear CR3 load/store exiting bits if L1 wants 'em Sean Christopherson
2021-04-24 0:46 ` [PATCH 25/43] KVM: VMX: Pull GUEST_CR3 from the VMCS iff CR3 load exiting is disabled Sean Christopherson
2021-04-24 0:46 ` [PATCH 26/43] KVM: VMX: Process CR0.PG side effects after setting CR0 assets Sean Christopherson
2021-04-24 0:46 ` [PATCH 27/43] KVM: VMX: Skip emulation required checks during pmode/rmode transitions Sean Christopherson
2021-04-24 0:46 ` Sean Christopherson [this message]
2021-04-24 0:46 ` [PATCH 29/43] KVM: SVM: Tweak order of cr0/cr4/efer writes at RESET/INIT Sean Christopherson
2021-05-19 18:16 ` Reiji Watanabe
2021-05-19 19:58 ` Sean Christopherson
2021-05-23 23:04 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 30/43] KVM: SVM: Drop redundant writes to vmcb->save.cr4 " Sean Christopherson
2021-05-19 5:35 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 31/43] KVM: SVM: Stuff save->dr6 at during VMSA sync, not " Sean Christopherson
2021-04-24 0:46 ` [PATCH 32/43] KVM: VMX: Skip pointless MSR bitmap update when setting EFER Sean Christopherson
2021-04-24 0:46 ` [PATCH 33/43] KVM: VMX: Refresh list of user return MSRs after setting guest CPUID Sean Christopherson
2021-05-19 5:35 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 34/43] KVM: VMX: Don't _explicitly_ reconfigure user return MSRs on vCPU INIT Sean Christopherson
2021-04-24 0:46 ` [PATCH 35/43] KVM: x86: Move setting of sregs during vCPU RESET/INIT to common x86 Sean Christopherson
2021-05-17 23:50 ` Reiji Watanabe
2021-05-18 21:45 ` Sean Christopherson
2021-05-21 5:19 ` Reiji Watanabe
2021-04-24 0:46 ` [PATCH 36/43] KVM: VMX: Remove obsolete MSR bitmap refresh at vCPU RESET/INIT Sean Christopherson
2021-04-24 0:46 ` [PATCH 37/43] KVM: nVMX: Remove obsolete MSR bitmap refresh at nested transitions Sean Christopherson
2021-04-24 0:46 ` [PATCH 38/43] KVM: VMX: Don't redo x2APIC MSR bitmaps when userspace filter is changed Sean Christopherson
2021-04-24 0:46 ` [PATCH 39/43] KVM: VMX: Remove unnecessary initialization of msr_bitmap_mode Sean Christopherson
2021-04-24 0:46 ` [PATCH 40/43] KVM: VMX: Smush x2APIC MSR bitmap adjustments into single function Sean Christopherson
2021-04-24 0:46 ` [PATCH 41/43] KVM: VMX: Remove redundant write to set vCPU as active at RESET/INIT Sean Christopherson
2021-04-24 0:46 ` [PATCH 42/43] KVM: VMX: Drop VMWRITEs to zero fields at vCPU RESET Sean Christopherson
2021-05-24 21:15 ` Paolo Bonzini
2021-05-24 22:21 ` Jim Mattson
2021-05-24 22:28 ` Sean Christopherson
2021-05-24 22:48 ` Jim Mattson
2021-05-25 1:02 ` Sean Christopherson
2021-04-24 0:46 ` [PATCH 43/43] KVM: x86: Drop pointless @reset_roots from kvm_init_mmu() Sean Christopherson
2021-05-27 19:11 ` Sean Christopherson
2021-05-27 19:25 ` Sean Christopherson
2021-06-10 16:54 ` [PATCH 00/43] KVM: x86: vCPU RESET/INIT fixes and consolidation Paolo Bonzini
2021-06-10 19:22 ` Sean Christopherson
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=20210424004645.3950558-29-seanjc@google.com \
--to=seanjc@google.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.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;
as well as URLs for NNTP newsgroup(s).