diff mbox series

[2/3] KVM: x86: always expose VIRT_SSBD to guests

Message ID 1566376002-17121-3-git-send-email-pbonzini@redhat.com (mailing list archive)
State New, archived
Headers show
Series KVM: x86: fixes for speculation bug feature reporting | expand

Commit Message

Paolo Bonzini Aug. 21, 2019, 8:26 a.m. UTC
Even though it is preferrable to use SPEC_CTRL (represented by
X86_FEATURE_AMD_SSBD) instead of VIRT_SPEC, VIRT_SPEC is always
supported anyway because otherwise it would be impossible to
migrate from old to new CPUs.  Make this apparent in the
result of KVM_GET_SUPPORTED_CPUID as well.

While at it, reuse X86_FEATURE_* constants for the SVM leaf too.

However, we need to hide the bit on Intel processors, so move
the setting to svm_set_supported_cpuid.

Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reported-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 arch/x86/kvm/svm.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

Comments

Jim Mattson Aug. 21, 2019, 7:47 p.m. UTC | #1
On Wed, Aug 21, 2019 at 1:27 AM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> Even though it is preferrable to use SPEC_CTRL (represented by
> X86_FEATURE_AMD_SSBD) instead of VIRT_SPEC, VIRT_SPEC is always
> supported anyway because otherwise it would be impossible to
> migrate from old to new CPUs.  Make this apparent in the
> result of KVM_GET_SUPPORTED_CPUID as well.
>
> While at it, reuse X86_FEATURE_* constants for the SVM leaf too.
>
> However, we need to hide the bit on Intel processors, so move
> the setting to svm_set_supported_cpuid.
>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Reported-by: Eduardo Habkost <ehabkost@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Jim Mattson <jmattson@google.com>
Konrad Rzeszutek Wilk Aug. 22, 2019, 6:44 p.m. UTC | #2
On Wed, Aug 21, 2019 at 10:26:41AM +0200, Paolo Bonzini wrote:
> Even though it is preferrable to use SPEC_CTRL (represented by
> X86_FEATURE_AMD_SSBD) instead of VIRT_SPEC, VIRT_SPEC is always
> supported anyway because otherwise it would be impossible to
> migrate from old to new CPUs.  Make this apparent in the
> result of KVM_GET_SUPPORTED_CPUID as well.
> 
> While at it, reuse X86_FEATURE_* constants for the SVM leaf too.
> 
> However, we need to hide the bit on Intel processors, so move
> the setting to svm_set_supported_cpuid.
> 
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Thank you!
Eduardo Habkost Oct. 1, 2019, 10:16 p.m. UTC | #3
On Wed, Aug 21, 2019 at 10:26:41AM +0200, Paolo Bonzini wrote:
> Even though it is preferrable to use SPEC_CTRL (represented by
> X86_FEATURE_AMD_SSBD) instead of VIRT_SPEC, VIRT_SPEC is always
> supported anyway because otherwise it would be impossible to
> migrate from old to new CPUs.  Make this apparent in the
> result of KVM_GET_SUPPORTED_CPUID as well.
> 
> While at it, reuse X86_FEATURE_* constants for the SVM leaf too.
> 
> However, we need to hide the bit on Intel processors, so move
> the setting to svm_set_supported_cpuid.
> 
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Reported-by: Eduardo Habkost <ehabkost@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
[...]
> @@ -5944,6 +5944,11 @@ static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)
>  		if (nested)
>  			entry->ecx |= (1 << 2); /* Set SVM bit */
>  		break;
> +	case 0x80000008:
> +		if (boot_cpu_has(X86_FEATURE_LS_CFG_SSBD) ||
> +		     boot_cpu_has(X86_FEATURE_AMD_SSBD))
> +			entry->ebx |= F(VIRT_SSBD);
> +		break;

Wasn't the old code at arch/x86/kvm/cpuid.c:__do_cpuid_func()
supposed to be deleted?

               /*
                * The preference is to use SPEC CTRL MSR instead of the
                * VIRT_SPEC MSR.
                */
               if (boot_cpu_has(X86_FEATURE_LS_CFG_SSBD) &&
                   !boot_cpu_has(X86_FEATURE_AMD_SSBD))
                       entry->ebx |= F(VIRT_SSBD);
Paolo Bonzini Oct. 6, 2019, 4:08 p.m. UTC | #4
On 02/10/19 00:16, Eduardo Habkost wrote:
> Wasn't the old code at arch/x86/kvm/cpuid.c:__do_cpuid_func()
> supposed to be deleted?
> 
>                /*
>                 * The preference is to use SPEC CTRL MSR instead of the
>                 * VIRT_SPEC MSR.
>                 */
>                if (boot_cpu_has(X86_FEATURE_LS_CFG_SSBD) &&
>                    !boot_cpu_has(X86_FEATURE_AMD_SSBD))
>                        entry->ebx |= F(VIRT_SSBD);

Yeah, it's harmless but also useless.

Paolo
diff mbox series

Patch

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index e3d3b2128f2b..c5120a9519f3 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -68,10 +68,8 @@ 
 #define SEG_TYPE_LDT 2
 #define SEG_TYPE_BUSY_TSS16 3
 
-#define SVM_FEATURE_NPT            (1 <<  0)
 #define SVM_FEATURE_LBRV           (1 <<  1)
 #define SVM_FEATURE_SVML           (1 <<  2)
-#define SVM_FEATURE_NRIP           (1 <<  3)
 #define SVM_FEATURE_TSC_RATE       (1 <<  4)
 #define SVM_FEATURE_VMCB_CLEAN     (1 <<  5)
 #define SVM_FEATURE_FLUSH_ASID     (1 <<  6)
@@ -5933,6 +5931,8 @@  static void svm_cpuid_update(struct kvm_vcpu *vcpu)
 	guest_cpuid_clear(vcpu, X86_FEATURE_X2APIC);
 }
 
+#define F(x) bit(X86_FEATURE_##x)
+
 static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)
 {
 	switch (func) {
@@ -5944,6 +5944,11 @@  static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)
 		if (nested)
 			entry->ecx |= (1 << 2); /* Set SVM bit */
 		break;
+	case 0x80000008:
+		if (boot_cpu_has(X86_FEATURE_LS_CFG_SSBD) ||
+		     boot_cpu_has(X86_FEATURE_AMD_SSBD))
+			entry->ebx |= F(VIRT_SSBD);
+		break;
 	case 0x8000000A:
 		entry->eax = 1; /* SVM revision 1 */
 		entry->ebx = 8; /* Lets support 8 ASIDs in case we add proper
@@ -5954,11 +5959,11 @@  static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)
 
 		/* Support next_rip if host supports it */
 		if (boot_cpu_has(X86_FEATURE_NRIPS))
-			entry->edx |= SVM_FEATURE_NRIP;
+			entry->edx |= F(NRIPS);
 
 		/* Support NPT for the guest if enabled */
 		if (npt_enabled)
-			entry->edx |= SVM_FEATURE_NPT;
+			entry->edx |= F(NPT);
 
 		break;
 	case 0x8000001F: