Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1221261 > unrolled thread
| Started by | Xiao Guangrong <guangrong.xiao@linux.intel.com> |
|---|---|
| First post | 2015-09-09 08:20 +0200 |
| Last post | 2015-09-09 08:20 +0200 |
| Articles | 6 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH v2 0/8] KVM: x86: enable cflushopt/clwb/pcommit and simplify code Xiao Guangrong <guangrong.xiao@linux.intel.com> - 2015-09-09 08:20 +0200
[PATCH v2 7/8] KVM: VMX: clean up bit operation on SECONDARY_VM_EXEC_CONTROL Xiao Guangrong <guangrong.xiao@linux.intel.com> - 2015-09-09 08:20 +0200
[PATCH v2 5/8] KVM: VMX: simplify invpcid handling in vmx_cpuid_update() Xiao Guangrong <guangrong.xiao@linux.intel.com> - 2015-09-09 08:20 +0200
[PATCH v2 6/8] KVM: VMX: unify SECONDARY_VM_EXEC_CONTROL update Xiao Guangrong <guangrong.xiao@linux.intel.com> - 2015-09-09 08:20 +0200
Re: [PATCH v2 6/8] KVM: VMX: unify SECONDARY_VM_EXEC_CONTROL update Paolo Bonzini <pbonzini@redhat.com> - 2015-09-15 17:50 +0200
[PATCH v2 3/8] KVM: VMX: drop rdtscp_enabled check in prepare_vmcs02() Xiao Guangrong <guangrong.xiao@linux.intel.com> - 2015-09-09 08:20 +0200
| From | Xiao Guangrong <guangrong.xiao@linux.intel.com> |
|---|---|
| Date | 2015-09-09 08:20 +0200 |
| Subject | [PATCH v2 0/8] KVM: x86: enable cflushopt/clwb/pcommit and simplify code |
| Message-ID | <q6GTD-332-3@gated-at.bofh.it> |
Changelog:
Thanks for Paolo's review, there are the changes in v2:
- use WARN_ON(1) instead of BUG() if PCOMMIT-exit happend for L1 guest
- drop set_clear_2nd_exec_ctrl() and use vmcs_{set,clear}_bits instead
- improve commit log and adjust code style
This pachset enables clfushopt, clwb and pcommit instructions for guest which
are used by NVDIMM.
The specification locates at:
https://software.intel.com/sites/default/files/managed/0d/53/319433-022.pdf
patch 1 and patch 2 enable these three instructions for guest and other patches
simplify current VMX code
Xiao Guangrong (8):
KVM: x86: allow guest to use cflushopt and clwb
KVM: x86: add pcommit support
KVM: VMX: drop rdtscp_enabled check in prepare_vmcs02()
KVM: VMX: simplify rdtscp handling in vmx_cpuid_update()
KVM: VMX: simplify invpcid handling in vmx_cpuid_update()
KVM: VMX: unify SECONDARY_VM_EXEC_CONTROL update
KVM: VMX: clean up bit operation on SECONDARY_VM_EXEC_CONTROL
KVM: VMX: drop rdtscp_enabled field
arch/x86/include/asm/vmx.h | 2 +-
arch/x86/include/uapi/asm/vmx.h | 4 +-
arch/x86/kvm/cpuid.c | 2 +-
arch/x86/kvm/cpuid.h | 16 +++++++
arch/x86/kvm/vmx.c | 103 ++++++++++++++++++----------------------
5 files changed, 67 insertions(+), 60 deletions(-)
--
2.4.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Xiao Guangrong <guangrong.xiao@linux.intel.com> |
|---|---|
| Date | 2015-09-09 08:20 +0200 |
| Subject | [PATCH v2 7/8] KVM: VMX: clean up bit operation on SECONDARY_VM_EXEC_CONTROL |
| Message-ID | <q6GTE-332-19@gated-at.bofh.it> |
| In reply to | #1221261 |
Use vmcs_set_bits() and vmcs_clear_bits() to clean up the code
Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
---
arch/x86/kvm/vmx.c | 31 ++++++++-----------------------
1 file changed, 8 insertions(+), 23 deletions(-)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 5a074d0..f18f744 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -6643,7 +6643,6 @@ static int nested_vmx_check_permission(struct kvm_vcpu *vcpu)
static inline void nested_release_vmcs12(struct vcpu_vmx *vmx)
{
- u32 exec_control;
if (vmx->nested.current_vmptr == -1ull)
return;
@@ -6656,9 +6655,8 @@ static inline void nested_release_vmcs12(struct vcpu_vmx *vmx)
they were modified */
copy_shadow_to_vmcs12(vmx);
vmx->nested.sync_shadow_vmcs = false;
- exec_control = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);
- exec_control &= ~SECONDARY_EXEC_SHADOW_VMCS;
- vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_control);
+ vmcs_clear_bits(SECONDARY_VM_EXEC_CONTROL,
+ SECONDARY_EXEC_SHADOW_VMCS);
vmcs_write64(VMCS_LINK_POINTER, -1ull);
}
vmx->nested.posted_intr_nv = -1;
@@ -7054,7 +7052,6 @@ static int handle_vmptrld(struct kvm_vcpu *vcpu)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
gpa_t vmptr;
- u32 exec_control;
if (!nested_vmx_check_permission(vcpu))
return 1;
@@ -7086,9 +7083,8 @@ static int handle_vmptrld(struct kvm_vcpu *vcpu)
vmx->nested.current_vmcs12 = new_vmcs12;
vmx->nested.current_vmcs12_page = page;
if (enable_shadow_vmcs) {
- exec_control = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);
- exec_control |= SECONDARY_EXEC_SHADOW_VMCS;
- vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_control);
+ vmcs_set_bits(SECONDARY_VM_EXEC_CONTROL,
+ SECONDARY_EXEC_SHADOW_VMCS);
vmcs_write64(VMCS_LINK_POINTER,
__pa(vmx->nested.current_shadow_vmcs));
vmx->nested.sync_shadow_vmcs = true;
@@ -7598,7 +7594,6 @@ static void vmx_get_exit_info(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2)
static int vmx_enable_pml(struct vcpu_vmx *vmx)
{
struct page *pml_pg;
- u32 exec_control;
pml_pg = alloc_page(GFP_KERNEL | __GFP_ZERO);
if (!pml_pg)
@@ -7609,24 +7604,18 @@ static int vmx_enable_pml(struct vcpu_vmx *vmx)
vmcs_write64(PML_ADDRESS, page_to_phys(vmx->pml_pg));
vmcs_write16(GUEST_PML_INDEX, PML_ENTITY_NUM - 1);
- exec_control = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);
- exec_control |= SECONDARY_EXEC_ENABLE_PML;
- vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_control);
+ vmcs_set_bits(SECONDARY_VM_EXEC_CONTROL, SECONDARY_EXEC_ENABLE_PML);
return 0;
}
static void vmx_disable_pml(struct vcpu_vmx *vmx)
{
- u32 exec_control;
-
ASSERT(vmx->pml_pg);
__free_page(vmx->pml_pg);
vmx->pml_pg = NULL;
- exec_control = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);
- exec_control &= ~SECONDARY_EXEC_ENABLE_PML;
- vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_control);
+ vmcs_clear_bits(SECONDARY_VM_EXEC_CONTROL, SECONDARY_EXEC_ENABLE_PML);
}
static void vmx_flush_pml_buffer(struct kvm_vcpu *vcpu)
@@ -8699,12 +8688,8 @@ static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
best->ebx &= ~bit(X86_FEATURE_INVPCID);
}
- if (clear_exe_ctrl) {
- u32 exec_ctl = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);
-
- exec_ctl &= ~clear_exe_ctrl;
- vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_ctl);
- }
+ if (clear_exe_ctrl)
+ vmcs_clear_bits(SECONDARY_VM_EXEC_CONTROL, clear_exe_ctrl);
if (!guest_cpuid_has_pcommit(vcpu) && nested)
vmx->nested.nested_vmx_secondary_ctls_high &=
--
2.4.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Xiao Guangrong <guangrong.xiao@linux.intel.com> |
|---|---|
| Date | 2015-09-09 08:20 +0200 |
| Subject | [PATCH v2 5/8] KVM: VMX: simplify invpcid handling in vmx_cpuid_update() |
| Message-ID | <q6GTE-332-23@gated-at.bofh.it> |
| In reply to | #1221261 |
If vmx_invpcid_supported() is true, second execution control
filed must be supported and SECONDARY_EXEC_ENABLE_INVPCID
must have already been set in current vmcs by
vmx_secondary_exec_control()
If vmx_invpcid_supported() is false, no need to clear
SECONDARY_EXEC_ENABLE_INVPCID
Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
---
arch/x86/kvm/vmx.c | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index bcc69de..97e3340 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -8695,19 +8695,12 @@ static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
/* Exposing INVPCID only when PCID is exposed */
best = kvm_find_cpuid_entry(vcpu, 0x7, 0);
if (vmx_invpcid_supported() &&
- best && (best->ebx & bit(X86_FEATURE_INVPCID)) &&
- guest_cpuid_has_pcid(vcpu)) {
+ (!best || !(best->ebx & bit(X86_FEATURE_INVPCID)) ||
+ !guest_cpuid_has_pcid(vcpu))) {
exec_control = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);
- exec_control |= SECONDARY_EXEC_ENABLE_INVPCID;
- vmcs_write32(SECONDARY_VM_EXEC_CONTROL,
- exec_control);
- } else {
- if (cpu_has_secondary_exec_ctrls()) {
- exec_control = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);
- exec_control &= ~SECONDARY_EXEC_ENABLE_INVPCID;
- vmcs_write32(SECONDARY_VM_EXEC_CONTROL,
- exec_control);
- }
+ exec_control &= ~SECONDARY_EXEC_ENABLE_INVPCID;
+ vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_control);
+
if (best)
best->ebx &= ~bit(X86_FEATURE_INVPCID);
}
--
2.4.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Xiao Guangrong <guangrong.xiao@linux.intel.com> |
|---|---|
| Date | 2015-09-09 08:20 +0200 |
| Subject | [PATCH v2 6/8] KVM: VMX: unify SECONDARY_VM_EXEC_CONTROL update |
| Message-ID | <q6GTE-332-27@gated-at.bofh.it> |
| In reply to | #1221261 |
Unify the update in vmx_cpuid_update()
Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
---
arch/x86/kvm/vmx.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 97e3340..5a074d0 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -8673,19 +8673,15 @@ static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
{
struct kvm_cpuid_entry2 *best;
struct vcpu_vmx *vmx = to_vmx(vcpu);
- u32 exec_control;
+ u32 clear_exe_ctrl = 0;
vmx->rdtscp_enabled = false;
if (vmx_rdtscp_supported()) {
- exec_control = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);
best = kvm_find_cpuid_entry(vcpu, 0x80000001, 0);
if (best && (best->edx & bit(X86_FEATURE_RDTSCP)))
vmx->rdtscp_enabled = true;
- else {
- exec_control &= ~SECONDARY_EXEC_RDTSCP;
- vmcs_write32(SECONDARY_VM_EXEC_CONTROL,
- exec_control);
- }
+ else
+ clear_exe_ctrl |= SECONDARY_EXEC_RDTSCP;
if (nested && !vmx->rdtscp_enabled)
vmx->nested.nested_vmx_secondary_ctls_high &=
@@ -8697,14 +8693,19 @@ static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
if (vmx_invpcid_supported() &&
(!best || !(best->ebx & bit(X86_FEATURE_INVPCID)) ||
!guest_cpuid_has_pcid(vcpu))) {
- exec_control = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);
- exec_control &= ~SECONDARY_EXEC_ENABLE_INVPCID;
- vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_control);
+ clear_exe_ctrl |= SECONDARY_EXEC_ENABLE_INVPCID;
if (best)
best->ebx &= ~bit(X86_FEATURE_INVPCID);
}
+ if (clear_exe_ctrl) {
+ u32 exec_ctl = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);
+
+ exec_ctl &= ~clear_exe_ctrl;
+ vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_ctl);
+ }
+
if (!guest_cpuid_has_pcommit(vcpu) && nested)
vmx->nested.nested_vmx_secondary_ctls_high &=
~SECONDARY_EXEC_PCOMMIT;
--
2.4.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Paolo Bonzini <pbonzini@redhat.com> |
|---|---|
| Date | 2015-09-15 17:50 +0200 |
| Subject | Re: [PATCH v2 6/8] KVM: VMX: unify SECONDARY_VM_EXEC_CONTROL update |
| Message-ID | <q90EA-Jd-59@gated-at.bofh.it> |
| In reply to | #1221264 |
On 09/09/2015 08:05, Xiao Guangrong wrote:
> Unify the update in vmx_cpuid_update()
>
> Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
What if we instead start fresh from vmx_secondary_exec_control, like this:
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 4504cbc1b287..98c4d3f1653a 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -8660,11 +8660,26 @@ static int vmx_get_lpage_level(void)
return PT_PDPE_LEVEL;
}
+static void vmcs_set_secondary_exec_control(u32 new_ctl)
+{
+ /*
+ * These bits in the secondary execution controls field
+ * are dynamic, the others are mostly based on the hypervisor
+ * architecture and the guest's CPUID. Do not touch the
+ * dynamic bits.
+ */
+ u32 mask = SECONDARY_EXEC_ENABLE_PML | SECONDARY_EXEC_SHADOW_VMCS;
+ u32 cur_ctl = vmcs_read32(SECONDARY_EXEC_CONTROL);
+
+ vmcs_write32(SECONDARY_EXEC_CONTROL,
+ (new_ctl & ~mask) | (cur_ctl & mask));
+}
+
static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
{
struct kvm_cpuid_entry2 *best;
struct vcpu_vmx *vmx = to_vmx(vcpu);
- u32 clear_exe_ctrl = 0;
+ u32 secondary_exec_ctl = vmx_secondary_exec_control(vmx);
vmx->rdtscp_enabled = false;
if (vmx_rdtscp_supported()) {
@@ -8672,7 +8681,7 @@ static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
if (best && (best->edx & bit(X86_FEATURE_RDTSCP)))
vmx->rdtscp_enabled = true;
else
- clear_exe_ctrl |= SECONDARY_EXEC_RDTSCP;
+ secondary_exec_ctl &= ~SECONDARY_EXEC_RDTSCP;
if (nested) {
if (vmx->rdtscp_enabled)
@@ -8689,18 +8698,13 @@ static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
if (vmx_invpcid_supported() &&
(!best || !(best->ebx & bit(X86_FEATURE_INVPCID)) ||
!guest_cpuid_has_pcid(vcpu))) {
- clear_exe_ctrl |= SECONDARY_EXEC_ENABLE_INVPCID;
+ secondary_exec_ctl &= ~SECONDARY_EXEC_ENABLE_INVPCID;
if (best)
best->ebx &= ~bit(X86_FEATURE_INVPCID);
}
- if (clear_exe_ctrl) {
- u32 exec_ctl = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);
-
- exec_ctl &= ~clear_exe_ctrl;
- vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_ctl);
- }
+ vmcs_set_secondary_exec_control(secondary_exec_ctl);
if (static_cpu_has(X86_FEATURE_PCOMMIT) && nested) {
if (guest_cpuid_has_pcommit(vcpu))
> ---
> arch/x86/kvm/vmx.c | 21 +++++++++++----------
> 1 file changed, 11 insertions(+), 10 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 97e3340..5a074d0 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -8673,19 +8673,15 @@ static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
> {
> struct kvm_cpuid_entry2 *best;
> struct vcpu_vmx *vmx = to_vmx(vcpu);
> - u32 exec_control;
> + u32 clear_exe_ctrl = 0;
>
> vmx->rdtscp_enabled = false;
> if (vmx_rdtscp_supported()) {
> - exec_control = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);
> best = kvm_find_cpuid_entry(vcpu, 0x80000001, 0);
> if (best && (best->edx & bit(X86_FEATURE_RDTSCP)))
> vmx->rdtscp_enabled = true;
> - else {
> - exec_control &= ~SECONDARY_EXEC_RDTSCP;
> - vmcs_write32(SECONDARY_VM_EXEC_CONTROL,
> - exec_control);
> - }
> + else
> + clear_exe_ctrl |= SECONDARY_EXEC_RDTSCP;
>
> if (nested && !vmx->rdtscp_enabled)
> vmx->nested.nested_vmx_secondary_ctls_high &=
> @@ -8697,14 +8693,19 @@ static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
> if (vmx_invpcid_supported() &&
> (!best || !(best->ebx & bit(X86_FEATURE_INVPCID)) ||
> !guest_cpuid_has_pcid(vcpu))) {
> - exec_control = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);
> - exec_control &= ~SECONDARY_EXEC_ENABLE_INVPCID;
> - vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_control);
> + clear_exe_ctrl |= SECONDARY_EXEC_ENABLE_INVPCID;
>
> if (best)
> best->ebx &= ~bit(X86_FEATURE_INVPCID);
> }
>
> + if (clear_exe_ctrl) {
> + u32 exec_ctl = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);
> +
> + exec_ctl &= ~clear_exe_ctrl;
> + vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_ctl);
> + }
> +
> if (!guest_cpuid_has_pcommit(vcpu) && nested)
> vmx->nested.nested_vmx_secondary_ctls_high &=
> ~SECONDARY_EXEC_PCOMMIT;
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Xiao Guangrong <guangrong.xiao@linux.intel.com> |
|---|---|
| Date | 2015-09-09 08:20 +0200 |
| Subject | [PATCH v2 3/8] KVM: VMX: drop rdtscp_enabled check in prepare_vmcs02() |
| Message-ID | <q6GTE-332-29@gated-at.bofh.it> |
| In reply to | #1221261 |
SECONDARY_EXEC_RDTSCP set for L2 guest comes from vmcs12
Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
---
arch/x86/kvm/vmx.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 073cbc8..61d44b0 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -9323,8 +9323,7 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
if (cpu_has_secondary_exec_ctrls()) {
exec_control = vmx_secondary_exec_control(vmx);
- if (!vmx->rdtscp_enabled)
- exec_control &= ~SECONDARY_EXEC_RDTSCP;
+
/* Take the following fields only from vmcs12 */
exec_control &= ~(SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES |
SECONDARY_EXEC_RDTSCP |
--
2.4.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web