diff mbox series

[1/2] kvm: x86: IA32_ARCH_CAPABILITIES is only emulated for Intel

Message ID 20190128181252.245510-1-jmattson@google.com (mailing list archive)
State New, archived
Headers show
Series [1/2] kvm: x86: IA32_ARCH_CAPABILITIES is only emulated for Intel | expand

Commit Message

Jim Mattson Jan. 28, 2019, 6:12 p.m. UTC
This MSR is not emulated on AMD hosts.

Fixes: 1eaafe91a0df ("kvm: x86: IA32_ARCH_CAPABILITIES is always supported")
Reported-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Jim Mattson <jmattson@google.com>
Reviewed-by: Marc Orr <marcorr@google.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Tested-by: Eduardo Habkost <ehabkost@redhat.com>
---
 arch/x86/include/asm/kvm_host.h | 3 ++-
 arch/x86/kvm/cpuid.c            | 7 +------
 arch/x86/kvm/svm.c              | 3 ++-
 arch/x86/kvm/vmx/vmx.c          | 9 ++++++++-
 4 files changed, 13 insertions(+), 9 deletions(-)

Comments

Jim Mattson Feb. 8, 2019, 11:03 p.m. UTC | #1
On Mon, Jan 28, 2019 at 10:13 AM Jim Mattson <jmattson@google.com> wrote:
>
> This MSR is not emulated on AMD hosts.
>
> Fixes: 1eaafe91a0df ("kvm: x86: IA32_ARCH_CAPABILITIES is always supported")
> Reported-by: Eduardo Habkost <ehabkost@redhat.com>
> Signed-off-by: Jim Mattson <jmattson@google.com>
> Reviewed-by: Marc Orr <marcorr@google.com>
> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
> Tested-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  arch/x86/include/asm/kvm_host.h | 3 ++-
>  arch/x86/kvm/cpuid.c            | 7 +------
>  arch/x86/kvm/svm.c              | 3 ++-
>  arch/x86/kvm/vmx/vmx.c          | 9 ++++++++-
>  4 files changed, 13 insertions(+), 9 deletions(-)
>
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 4660ce90de7f..cd84d1bf33d0 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -1095,7 +1095,8 @@ struct kvm_x86_ops {
>
>         void (*set_tdp_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3);
>
> -       void (*set_supported_cpuid)(u32 func, struct kvm_cpuid_entry2 *entry);
> +       void (*set_supported_cpuid)(u32 func, u32 index,
> +                                   struct kvm_cpuid_entry2 *entry);
>
>         bool (*has_wbinvd_exit)(void);
>
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index bbffa6c54697..39b92f3409b6 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -496,11 +496,6 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
>                                 entry->ecx &= ~F(PKU);
>                         entry->edx &= kvm_cpuid_7_0_edx_x86_features;
>                         cpuid_mask(&entry->edx, CPUID_7_EDX);
> -                       /*
> -                        * We emulate ARCH_CAPABILITIES in software even
> -                        * if the host doesn't support it.
> -                        */
> -                       entry->edx |= F(ARCH_CAPABILITIES);
>                 } else {
>                         entry->ebx = 0;
>                         entry->ecx = 0;
> @@ -718,7 +713,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
>                 break;
>         }
>
> -       kvm_x86_ops->set_supported_cpuid(function, entry);
> +       kvm_x86_ops->set_supported_cpuid(function, index, entry);
>
>         r = 0;
>
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index a157ca5b6869..c34a6d77d8e4 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -5882,7 +5882,8 @@ static void svm_cpuid_update(struct kvm_vcpu *vcpu)
>         guest_cpuid_clear(vcpu, X86_FEATURE_X2APIC);
>  }
>
> -static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)
> +static void svm_set_supported_cpuid(u32 func, u32 index,
> +                                   struct kvm_cpuid_entry2 *entry)
>  {
>         switch (func) {
>         case 0x1:
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index f6915f10e584..18e0975486ee 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -7073,10 +7073,17 @@ static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
>                 update_intel_pt_cfg(vcpu);
>  }
>
> -static void vmx_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)
> +static void vmx_set_supported_cpuid(u32 func, u32 index,
> +                                   struct kvm_cpuid_entry2 *entry)
>  {
>         if (func == 1 && nested)
>                 entry->ecx |= bit(X86_FEATURE_VMX);
> +       else if (func == 7 && index == 0)
> +               /*
> +                * We emulate ARCH_CAPABILITIES in software even
> +                * if the host doesn't support it.
> +                */
> +               entry->edx |= bit(X86_FEATURE_ARCH_CAPABILITIES);
>  }
>
>  static void vmx_request_immediate_exit(struct kvm_vcpu *vcpu)
> --
> 2.20.1.495.gaa96b0ce6b-goog
>

Ping?
diff mbox series

Patch

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 4660ce90de7f..cd84d1bf33d0 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1095,7 +1095,8 @@  struct kvm_x86_ops {
 
 	void (*set_tdp_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3);
 
-	void (*set_supported_cpuid)(u32 func, struct kvm_cpuid_entry2 *entry);
+	void (*set_supported_cpuid)(u32 func, u32 index,
+				    struct kvm_cpuid_entry2 *entry);
 
 	bool (*has_wbinvd_exit)(void);
 
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index bbffa6c54697..39b92f3409b6 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -496,11 +496,6 @@  static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
 				entry->ecx &= ~F(PKU);
 			entry->edx &= kvm_cpuid_7_0_edx_x86_features;
 			cpuid_mask(&entry->edx, CPUID_7_EDX);
-			/*
-			 * We emulate ARCH_CAPABILITIES in software even
-			 * if the host doesn't support it.
-			 */
-			entry->edx |= F(ARCH_CAPABILITIES);
 		} else {
 			entry->ebx = 0;
 			entry->ecx = 0;
@@ -718,7 +713,7 @@  static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
 		break;
 	}
 
-	kvm_x86_ops->set_supported_cpuid(function, entry);
+	kvm_x86_ops->set_supported_cpuid(function, index, entry);
 
 	r = 0;
 
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index a157ca5b6869..c34a6d77d8e4 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -5882,7 +5882,8 @@  static void svm_cpuid_update(struct kvm_vcpu *vcpu)
 	guest_cpuid_clear(vcpu, X86_FEATURE_X2APIC);
 }
 
-static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)
+static void svm_set_supported_cpuid(u32 func, u32 index,
+				    struct kvm_cpuid_entry2 *entry)
 {
 	switch (func) {
 	case 0x1:
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index f6915f10e584..18e0975486ee 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -7073,10 +7073,17 @@  static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
 		update_intel_pt_cfg(vcpu);
 }
 
-static void vmx_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)
+static void vmx_set_supported_cpuid(u32 func, u32 index,
+				    struct kvm_cpuid_entry2 *entry)
 {
 	if (func == 1 && nested)
 		entry->ecx |= bit(X86_FEATURE_VMX);
+	else if (func == 7 && index == 0)
+		/*
+		 * We emulate ARCH_CAPABILITIES in software even
+		 * if the host doesn't support it.
+		 */
+		entry->edx |= bit(X86_FEATURE_ARCH_CAPABILITIES);
 }
 
 static void vmx_request_immediate_exit(struct kvm_vcpu *vcpu)