* [PATCH v3 0/4] Minor cleanup and refactor about vmcs
@ 2019-10-20 9:10 Xiaoyao Li
2019-10-20 9:10 ` [PATCH v3 1/4] KVM: VMX: Write VPID to vmcs when creating vcpu Xiaoyao Li
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Xiaoyao Li @ 2019-10-20 9:10 UTC (permalink / raw)
To: Paolo Bonzini, Radim Krčmář,
Sean Christopherson, Vitaly Kuznetsov, Jim Mattson, Joerg Roedel
Cc: Xiaoyao Li, Krish Sadhukhan, kvm, linux-kernel
There is no functional changs, just some cleanup and renaming to increase
readability.
Patch 1 is newly added from v2.
Patcd 2 and 3 is seperated from Patch 4.
Xiaoyao Li (4):
KVM: VMX: Write VPID to vmcs when creating vcpu
KVM: VMX: Remove vmx->hv_deadline_tsc initialization from
vmx_vcpu_setup()
KVM: VMX: Initialize vmx->guest_msrs[] right after allocation
KVM: VMX: Rename {vmx,nested_vmx}_vcpu_setup()
arch/x86/kvm/vmx/nested.c | 2 +-
arch/x86/kvm/vmx/nested.h | 2 +-
arch/x86/kvm/vmx/vmx.c | 50 +++++++++++++++++++--------------------
3 files changed, 26 insertions(+), 28 deletions(-)
--
2.19.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 1/4] KVM: VMX: Write VPID to vmcs when creating vcpu
2019-10-20 9:10 [PATCH v3 0/4] Minor cleanup and refactor about vmcs Xiaoyao Li
@ 2019-10-20 9:10 ` Xiaoyao Li
2019-10-20 9:10 ` [PATCH v3 2/4] KVM: VMX: Remove vmx->hv_deadline_tsc initialization from vmx_vcpu_setup() Xiaoyao Li
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Xiaoyao Li @ 2019-10-20 9:10 UTC (permalink / raw)
To: Paolo Bonzini, Radim Krčmář,
Sean Christopherson, Vitaly Kuznetsov, Jim Mattson, Joerg Roedel
Cc: Xiaoyao Li, Krish Sadhukhan, kvm, linux-kernel
Move the code that writes vmx->vpid to vmcs from vmx_vcpu_reset() to
vmx_vcpu_setup(), because vmx->vpid is allocated when creating vcpu and
never changed. So we don't need to update the vmcs.vpid when resetting
vcpu.
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
arch/x86/kvm/vmx/vmx.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index e660e28e9ae0..279f855d892b 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -4252,6 +4252,9 @@ static void vmx_vcpu_setup(struct vcpu_vmx *vmx)
set_cr4_guest_host_mask(vmx);
+ if (vmx->vpid != 0)
+ vmcs_write16(VIRTUAL_PROCESSOR_ID, vmx->vpid);
+
if (vmx_xsaves_supported())
vmcs_write64(XSS_EXIT_BITMAP, VMX_XSS_EXIT_BITMAP);
@@ -4354,9 +4357,6 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
kvm_make_request(KVM_REQ_APIC_PAGE_RELOAD, vcpu);
- if (vmx->vpid != 0)
- vmcs_write16(VIRTUAL_PROCESSOR_ID, vmx->vpid);
-
cr0 = X86_CR0_NW | X86_CR0_CD | X86_CR0_ET;
vmx->vcpu.arch.cr0 = cr0;
vmx_set_cr0(vcpu, cr0); /* enter rmode */
--
2.19.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 2/4] KVM: VMX: Remove vmx->hv_deadline_tsc initialization from vmx_vcpu_setup()
2019-10-20 9:10 [PATCH v3 0/4] Minor cleanup and refactor about vmcs Xiaoyao Li
2019-10-20 9:10 ` [PATCH v3 1/4] KVM: VMX: Write VPID to vmcs when creating vcpu Xiaoyao Li
@ 2019-10-20 9:10 ` Xiaoyao Li
2019-10-20 9:11 ` [PATCH v3 3/4] KVM: VMX: Initialize vmx->guest_msrs[] right after allocation Xiaoyao Li
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Xiaoyao Li @ 2019-10-20 9:10 UTC (permalink / raw)
To: Paolo Bonzini, Radim Krčmář,
Sean Christopherson, Vitaly Kuznetsov, Jim Mattson, Joerg Roedel
Cc: Xiaoyao Li, Krish Sadhukhan, kvm, linux-kernel
... It can be removed here because the same code is called later in
vmx_vcpu_reset() as the flow:
kvm_arch_vcpu_setup()
-> kvm_vcpu_reset()
-> vmx_vcpu_reset()
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
arch/x86/kvm/vmx/vmx.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 279f855d892b..ec7c42f57b65 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -4178,7 +4178,6 @@ static void vmx_vcpu_setup(struct vcpu_vmx *vmx)
/* Control */
pin_controls_set(vmx, vmx_pin_based_exec_ctrl(vmx));
- vmx->hv_deadline_tsc = -1;
exec_controls_set(vmx, vmx_exec_control(vmx));
--
2.19.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 3/4] KVM: VMX: Initialize vmx->guest_msrs[] right after allocation
2019-10-20 9:10 [PATCH v3 0/4] Minor cleanup and refactor about vmcs Xiaoyao Li
2019-10-20 9:10 ` [PATCH v3 1/4] KVM: VMX: Write VPID to vmcs when creating vcpu Xiaoyao Li
2019-10-20 9:10 ` [PATCH v3 2/4] KVM: VMX: Remove vmx->hv_deadline_tsc initialization from vmx_vcpu_setup() Xiaoyao Li
@ 2019-10-20 9:11 ` Xiaoyao Li
2019-10-20 9:11 ` [PATCH v3 4/4] KVM: VMX: Rename {vmx,nested_vmx}_vcpu_setup() Xiaoyao Li
2019-10-22 13:42 ` [PATCH v3 0/4] Minor cleanup and refactor about vmcs Paolo Bonzini
4 siblings, 0 replies; 6+ messages in thread
From: Xiaoyao Li @ 2019-10-20 9:11 UTC (permalink / raw)
To: Paolo Bonzini, Radim Krčmář,
Sean Christopherson, Vitaly Kuznetsov, Jim Mattson, Joerg Roedel
Cc: Xiaoyao Li, Krish Sadhukhan, kvm, linux-kernel
Move the initialization of vmx->guest_msrs[] from vmx_vcpu_setup() to
vmx_create_vcpu(), and put it right after its allocation.
This also is the preperation for next patch.
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
arch/x86/kvm/vmx/vmx.c | 34 ++++++++++++++++------------------
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index ec7c42f57b65..84c32395d887 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -4166,8 +4166,6 @@ static void ept_set_mmio_spte_mask(void)
*/
static void vmx_vcpu_setup(struct vcpu_vmx *vmx)
{
- int i;
-
if (nested)
nested_vmx_vcpu_setup();
@@ -4226,21 +4224,6 @@ static void vmx_vcpu_setup(struct vcpu_vmx *vmx)
if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_PAT)
vmcs_write64(GUEST_IA32_PAT, vmx->vcpu.arch.pat);
- for (i = 0; i < ARRAY_SIZE(vmx_msr_index); ++i) {
- u32 index = vmx_msr_index[i];
- u32 data_low, data_high;
- int j = vmx->nmsrs;
-
- if (rdmsr_safe(index, &data_low, &data_high) < 0)
- continue;
- if (wrmsr_safe(index, data_low, data_high) < 0)
- continue;
- vmx->guest_msrs[j].index = i;
- vmx->guest_msrs[j].data = 0;
- vmx->guest_msrs[j].mask = -1ull;
- ++vmx->nmsrs;
- }
-
vm_exit_controls_set(vmx, vmx_vmexit_ctrl());
/* 22.2.1, 20.8.1 */
@@ -6700,7 +6683,7 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
int err;
struct vcpu_vmx *vmx;
unsigned long *msr_bitmap;
- int cpu;
+ int i, cpu;
BUILD_BUG_ON_MSG(offsetof(struct vcpu_vmx, vcpu) != 0,
"struct kvm_vcpu must be at offset 0 for arch usercopy region");
@@ -6752,6 +6735,21 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
if (!vmx->guest_msrs)
goto free_pml;
+ for (i = 0; i < ARRAY_SIZE(vmx_msr_index); ++i) {
+ u32 index = vmx_msr_index[i];
+ u32 data_low, data_high;
+ int j = vmx->nmsrs;
+
+ if (rdmsr_safe(index, &data_low, &data_high) < 0)
+ continue;
+ if (wrmsr_safe(index, data_low, data_high) < 0)
+ continue;
+ vmx->guest_msrs[j].index = i;
+ vmx->guest_msrs[j].data = 0;
+ vmx->guest_msrs[j].mask = -1ull;
+ ++vmx->nmsrs;
+ }
+
err = alloc_loaded_vmcs(&vmx->vmcs01);
if (err < 0)
goto free_msrs;
--
2.19.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 4/4] KVM: VMX: Rename {vmx,nested_vmx}_vcpu_setup()
2019-10-20 9:10 [PATCH v3 0/4] Minor cleanup and refactor about vmcs Xiaoyao Li
` (2 preceding siblings ...)
2019-10-20 9:11 ` [PATCH v3 3/4] KVM: VMX: Initialize vmx->guest_msrs[] right after allocation Xiaoyao Li
@ 2019-10-20 9:11 ` Xiaoyao Li
2019-10-22 13:42 ` [PATCH v3 0/4] Minor cleanup and refactor about vmcs Paolo Bonzini
4 siblings, 0 replies; 6+ messages in thread
From: Xiaoyao Li @ 2019-10-20 9:11 UTC (permalink / raw)
To: Paolo Bonzini, Radim Krčmář,
Sean Christopherson, Vitaly Kuznetsov, Jim Mattson, Joerg Roedel
Cc: Xiaoyao Li, Krish Sadhukhan, kvm, linux-kernel
Rename {vmx,nested_vmx}_vcpu_setup() to match what they really do.
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
Changes in v3:
- Move vmcs unrelated changes into 2 seperate patches.
- refine the function name.
---
arch/x86/kvm/vmx/nested.c | 2 +-
arch/x86/kvm/vmx/nested.h | 2 +-
arch/x86/kvm/vmx/vmx.c | 9 +++++----
3 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 5e231da00310..55c5791ac52b 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -5768,7 +5768,7 @@ static int vmx_set_nested_state(struct kvm_vcpu *vcpu,
return ret;
}
-void nested_vmx_vcpu_setup(void)
+void nested_vmx_set_vmcs_shadowing_bitmap(void)
{
if (enable_shadow_vmcs) {
vmcs_write64(VMREAD_BITMAP, __pa(vmx_vmread_bitmap));
diff --git a/arch/x86/kvm/vmx/nested.h b/arch/x86/kvm/vmx/nested.h
index 187d39bf0bf1..4cf1d40da15f 100644
--- a/arch/x86/kvm/vmx/nested.h
+++ b/arch/x86/kvm/vmx/nested.h
@@ -11,7 +11,7 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps,
bool apicv);
void nested_vmx_hardware_unsetup(void);
__init int nested_vmx_hardware_setup(int (*exit_handlers[])(struct kvm_vcpu *));
-void nested_vmx_vcpu_setup(void);
+void nested_vmx_set_vmcs_shadowing_bitmap(void);
void nested_vmx_free_vcpu(struct kvm_vcpu *vcpu);
int nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu, bool from_vmentry);
bool nested_vmx_exit_reflected(struct kvm_vcpu *vcpu, u32 exit_reason);
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 84c32395d887..4211f72a1a01 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -4162,12 +4162,13 @@ static void ept_set_mmio_spte_mask(void)
#define VMX_XSS_EXIT_BITMAP 0
/*
- * Sets up the vmcs for emulated real mode.
+ * Noting that the initialization of Guest-state Area of VMCS is in
+ * vmx_vcpu_reset().
*/
-static void vmx_vcpu_setup(struct vcpu_vmx *vmx)
+static void init_vmcs(struct vcpu_vmx *vmx)
{
if (nested)
- nested_vmx_vcpu_setup();
+ nested_vmx_set_vmcs_shadowing_bitmap();
if (cpu_has_vmx_msr_bitmap())
vmcs_write64(MSR_BITMAP, __pa(vmx->vmcs01.msr_bitmap));
@@ -6774,7 +6775,7 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
cpu = get_cpu();
vmx_vcpu_load(&vmx->vcpu, cpu);
vmx->vcpu.cpu = cpu;
- vmx_vcpu_setup(vmx);
+ init_vmcs(vmx);
vmx_vcpu_put(&vmx->vcpu);
put_cpu();
if (cpu_need_virtualize_apic_accesses(&vmx->vcpu)) {
--
2.19.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v3 0/4] Minor cleanup and refactor about vmcs
2019-10-20 9:10 [PATCH v3 0/4] Minor cleanup and refactor about vmcs Xiaoyao Li
` (3 preceding siblings ...)
2019-10-20 9:11 ` [PATCH v3 4/4] KVM: VMX: Rename {vmx,nested_vmx}_vcpu_setup() Xiaoyao Li
@ 2019-10-22 13:42 ` Paolo Bonzini
4 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2019-10-22 13:42 UTC (permalink / raw)
To: Xiaoyao Li, Radim Krčmář,
Sean Christopherson, Vitaly Kuznetsov, Jim Mattson, Joerg Roedel
Cc: Krish Sadhukhan, kvm, linux-kernel
On 20/10/19 11:10, Xiaoyao Li wrote:
> There is no functional changs, just some cleanup and renaming to increase
> readability.
>
> Patch 1 is newly added from v2.
> Patcd 2 and 3 is seperated from Patch 4.
>
> Xiaoyao Li (4):
> KVM: VMX: Write VPID to vmcs when creating vcpu
> KVM: VMX: Remove vmx->hv_deadline_tsc initialization from
> vmx_vcpu_setup()
> KVM: VMX: Initialize vmx->guest_msrs[] right after allocation
> KVM: VMX: Rename {vmx,nested_vmx}_vcpu_setup()
>
> arch/x86/kvm/vmx/nested.c | 2 +-
> arch/x86/kvm/vmx/nested.h | 2 +-
> arch/x86/kvm/vmx/vmx.c | 50 +++++++++++++++++++--------------------
> 3 files changed, 26 insertions(+), 28 deletions(-)
>
Queued, thanks.
Paolo
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-10-22 13:42 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-20 9:10 [PATCH v3 0/4] Minor cleanup and refactor about vmcs Xiaoyao Li
2019-10-20 9:10 ` [PATCH v3 1/4] KVM: VMX: Write VPID to vmcs when creating vcpu Xiaoyao Li
2019-10-20 9:10 ` [PATCH v3 2/4] KVM: VMX: Remove vmx->hv_deadline_tsc initialization from vmx_vcpu_setup() Xiaoyao Li
2019-10-20 9:11 ` [PATCH v3 3/4] KVM: VMX: Initialize vmx->guest_msrs[] right after allocation Xiaoyao Li
2019-10-20 9:11 ` [PATCH v3 4/4] KVM: VMX: Rename {vmx,nested_vmx}_vcpu_setup() Xiaoyao Li
2019-10-22 13:42 ` [PATCH v3 0/4] Minor cleanup and refactor about vmcs Paolo Bonzini
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).