2018-05-21 22:00:25

by Konrad Rzeszutek Wilk

[permalink] [raw]
Subject: [PATCH] Fix SSBD not being exposed to guests. (v1)

Hi,

Without this patch, when launching QEMU with -cpu +ssbd I ended up
with a warning seeing that the CPU does not support - which in fact it does.

The issue was the X86_FEATURE_ - the kvm_cpuid_7_0_edx_x86_features
had bit 17 set (X86_FEATURE_SSBD), while the right bit should have been
bit 31 ( X86_FEATURE_SPEC_CTRL_SSBD). That meant the masking:

entry->edx &= kvm_cpuid_7_0_edx_x86_features;

would nicely clear the SSBD bit.

This fixes:
Fixes: 52817587e706 ("x86/cpufeatures: Disentangle SSBD enumeration")

arch/x86/kvm/cpuid.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

Konrad Rzeszutek Wilk (1):
KVM: VMX: Expose SSBD properly to guests.



2018-05-21 22:00:40

by Konrad Rzeszutek Wilk

[permalink] [raw]
Subject: [PATCH] KVM: VMX: Expose SSBD properly to guests.

The X86_FEATURE_SSBD is an synthetic CPU feature - that is
it bit location has no relevance to the real CPUID 0x7.EBX[31]
bit position. For that we need the new CPU feature name.

Fixes: 52817587e706 ("x86/cpufeatures: Disentangle SSBD enumeration")

CC: Paolo Bonzini <[email protected]>
Cc: "Radim Krčmář" <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]
Signed-off-by: Konrad Rzeszutek Wilk <[email protected]>
---
arch/x86/kvm/cpuid.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index ced851169730..598461e24be3 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -407,8 +407,8 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,

/* cpuid 7.0.edx*/
const u32 kvm_cpuid_7_0_edx_x86_features =
- F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(SPEC_CTRL) | F(SSBD) |
- F(ARCH_CAPABILITIES);
+ F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(SPEC_CTRL) |
+ F(SPEC_CTRL_SSBD) | F(ARCH_CAPABILITIES);

/* all calls to cpuid_count() should be made on the same cpu */
get_cpu();
--
2.13.4


2018-05-22 23:53:07

by Ben Hutchings

[permalink] [raw]
Subject: Re: [PATCH] KVM: VMX: Expose SSBD properly to guests.

On Mon, 2018-05-21 at 17:54 -0400, Konrad Rzeszutek Wilk wrote:
> The X86_FEATURE_SSBD is an synthetic CPU feature - that is
> it bit location has no relevance to the real CPUID 0x7.EBX[31]
> bit position. For that we need the new CPU feature name.
>
> Fixes: 52817587e706 ("x86/cpufeatures: Disentangle SSBD enumeration")
>
> CC: Paolo Bonzini <[email protected]>
> Cc: "Radim Krčmář" <[email protected]>
> Cc: Thomas Gleixner <[email protected]>
> Cc: Ingo Molnar <[email protected]>
> Cc: "H. Peter Anvin" <[email protected]>
> Cc: [email protected]
> Signed-off-by: Konrad Rzeszutek Wilk <[email protected]>
> ---
> arch/x86/kvm/cpuid.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index ced851169730..598461e24be3 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -407,8 +407,8 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
>
> /* cpuid 7.0.edx*/
> const u32 kvm_cpuid_7_0_edx_x86_features =
> - F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(SPEC_CTRL) | F(SSBD) |
> - F(ARCH_CAPABILITIES);
> + F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(SPEC_CTRL) |
> + F(SPEC_CTRL_SSBD) | F(ARCH_CAPABILITIES);
>
> /* all calls to cpuid_count() should be made on the same cpu */
> get_cpu();

For 4.9-stable, guest_cpuid_has_spec_ctrl() needs a similar fix.

Ben.

--
Ben Hutchings
It is easier to change the specification to fit the program
than vice versa.


Attachments:
signature.asc (849.00 B)
This is a digitally signed message part
Subject: [tip:x86/pti] KVM/VMX: Expose SSBD properly to guests

Commit-ID: 0aa48468d00959c8a37cd3ac727284f4f7359151
Gitweb: https://git.kernel.org/tip/0aa48468d00959c8a37cd3ac727284f4f7359151
Author: Konrad Rzeszutek Wilk <[email protected]>
AuthorDate: Mon, 21 May 2018 17:54:49 -0400
Committer: Thomas Gleixner <[email protected]>
CommitDate: Wed, 23 May 2018 10:55:52 +0200

KVM/VMX: Expose SSBD properly to guests

The X86_FEATURE_SSBD is an synthetic CPU feature - that is
it bit location has no relevance to the real CPUID 0x7.EBX[31]
bit position. For that we need the new CPU feature name.

Fixes: 52817587e706 ("x86/cpufeatures: Disentangle SSBD enumeration")
Signed-off-by: Konrad Rzeszutek Wilk <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Cc: [email protected]
Cc: "Radim Krčmář" <[email protected]>
Cc: [email protected]
Cc: "H. Peter Anvin" <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]

---
arch/x86/kvm/cpuid.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index ced851169730..598461e24be3 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -407,8 +407,8 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,

/* cpuid 7.0.edx*/
const u32 kvm_cpuid_7_0_edx_x86_features =
- F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(SPEC_CTRL) | F(SSBD) |
- F(ARCH_CAPABILITIES);
+ F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(SPEC_CTRL) |
+ F(SPEC_CTRL_SSBD) | F(ARCH_CAPABILITIES);

/* all calls to cpuid_count() should be made on the same cpu */
get_cpu();

2018-06-07 13:39:21

by Thomas Voegtle

[permalink] [raw]
Subject: Re: [PATCH] KVM: VMX: Expose SSBD properly to guests.

On Wed, 23 May 2018, Ben Hutchings wrote:

> On Mon, 2018-05-21 at 17:54 -0400, Konrad Rzeszutek Wilk wrote:
>> The X86_FEATURE_SSBD is an synthetic CPU feature - that is
>> it bit location has no relevance to the real CPUID 0x7.EBX[31]
>> bit position. For that we need the new CPU feature name.
>>
>> Fixes: 52817587e706 ("x86/cpufeatures: Disentangle SSBD enumeration")
>>
>> CC: Paolo Bonzini <[email protected]>
>> Cc: "Radim Krčmář" <[email protected]>
>> Cc: Thomas Gleixner <[email protected]>
>> Cc: Ingo Molnar <[email protected]>
>> Cc: "H. Peter Anvin" <[email protected]>
>> Cc: [email protected]
>> Signed-off-by: Konrad Rzeszutek Wilk <[email protected]>
>> ---
>> arch/x86/kvm/cpuid.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
>> index ced851169730..598461e24be3 100644
>> --- a/arch/x86/kvm/cpuid.c
>> +++ b/arch/x86/kvm/cpuid.c
>> @@ -407,8 +407,8 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
>>
>> /* cpuid 7.0.edx*/
>> const u32 kvm_cpuid_7_0_edx_x86_features =
>> - F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(SPEC_CTRL) | F(SSBD) |
>> - F(ARCH_CAPABILITIES);
>> + F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(SPEC_CTRL) |
>> + F(SPEC_CTRL_SSBD) | F(ARCH_CAPABILITIES);
>>
>> /* all calls to cpuid_count() should be made on the same cpu */
>> get_cpu();
>
> For 4.9-stable, guest_cpuid_has_spec_ctrl() needs a similar fix.
>
> Ben.

Do you mean something like this?

--- a/arch/x86/kvm/cpuid.h
+++ b/arch/x86/kvm/cpuid.h
@@ -179,7 +179,7 @@ static inline bool guest_cpuid_has_spec_ctrl(struct
kvm_vcpu *vcpu)
if (best && (best->ebx & bit(X86_FEATURE_AMD_IBRS)))
return true;
best = kvm_find_cpuid_entry(vcpu, 7, 0);
- return best && (best->edx & (bit(X86_FEATURE_SPEC_CTRL) |
bit(X86_FEATURE_SSBD)));
+ return best && (best->edx & (bit(X86_FEATURE_SPEC_CTRL) |
bit(X86_FEATURE_SPEC_CTRL_SSBD)));
}

static inline bool guest_cpuid_has_arch_capabilities(struct kvm_vcpu
*vcpu)