2022-12-10 16:35:22

by Zhang, Chen

[permalink] [raw]
Subject: [RFC PATCH 2/9] KVM: x86: Add a kvm-only leaf for RRSBA_CTRL

KVM needs to check if guests can see RRSBA_CTRL. If a guest is using
retpoline and cannot see RRSBA_CTRL and the host enumerates RRSBA,
KVM is responsible for setting RRSBA_DIS_S for the guest.

This allows VM migration from parts doesn't enumerates RRSBA to those
that enumerate RRSBA.

Signed-off-by: Zhang Chen <[email protected]>
---
arch/x86/kvm/cpuid.c | 4 ++++
arch/x86/kvm/reverse_cpuid.h | 7 +++++++
2 files changed, 11 insertions(+)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 62bc7a01cecc..8d45bc0b4b7c 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -668,6 +668,10 @@ void kvm_set_cpu_caps(void)
SF(SGX1) | SF(SGX2)
);

+ kvm_cpu_cap_init_scattered(CPUID_7_2_EDX,
+ SF(RRSBA_CTRL)
+ );
+
kvm_cpu_cap_mask(CPUID_8000_0001_ECX,
F(LAHF_LM) | F(CMP_LEGACY) | 0 /*SVM*/ | 0 /* ExtApicSpace */ |
F(CR8_LEGACY) | F(ABM) | F(SSE4A) | F(MISALIGNSSE) |
diff --git a/arch/x86/kvm/reverse_cpuid.h b/arch/x86/kvm/reverse_cpuid.h
index a19d473d0184..4c38ed61c505 100644
--- a/arch/x86/kvm/reverse_cpuid.h
+++ b/arch/x86/kvm/reverse_cpuid.h
@@ -13,6 +13,7 @@
*/
enum kvm_only_cpuid_leafs {
CPUID_12_EAX = NCAPINTS,
+ CPUID_7_2_EDX,
NR_KVM_CPU_CAPS,

NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS,
@@ -24,6 +25,9 @@ enum kvm_only_cpuid_leafs {
#define KVM_X86_FEATURE_SGX1 KVM_X86_FEATURE(CPUID_12_EAX, 0)
#define KVM_X86_FEATURE_SGX2 KVM_X86_FEATURE(CPUID_12_EAX, 1)

+/* Intel-defined sub-features, CPUID level 0x00000007:2 (EDX)*/
+#define KVM_X86_FEATURE_RRSBA_CTRL KVM_X86_FEATURE(CPUID_7_2_EDX, 2)
+
struct cpuid_reg {
u32 function;
u32 index;
@@ -46,6 +50,7 @@ static const struct cpuid_reg reverse_cpuid[] = {
[CPUID_8000_0007_EBX] = {0x80000007, 0, CPUID_EBX},
[CPUID_7_EDX] = { 7, 0, CPUID_EDX},
[CPUID_7_1_EAX] = { 7, 1, CPUID_EAX},
+ [CPUID_7_2_EDX] = { 7, 2, CPUID_EDX},
[CPUID_12_EAX] = {0x00000012, 0, CPUID_EAX},
[CPUID_8000_001F_EAX] = {0x8000001f, 0, CPUID_EAX},
};
@@ -78,6 +83,8 @@ static __always_inline u32 __feature_translate(int x86_feature)
return KVM_X86_FEATURE_SGX1;
else if (x86_feature == X86_FEATURE_SGX2)
return KVM_X86_FEATURE_SGX2;
+ else if (x86_feature == X86_FEATURE_RRSBA_CTRL)
+ return KVM_X86_FEATURE_RRSBA_CTRL;

return x86_feature;
}
--
2.25.1


2022-12-14 21:51:03

by Ricardo Neri

[permalink] [raw]
Subject: Re: [RFC PATCH 2/9] KVM: x86: Add a kvm-only leaf for RRSBA_CTRL

On Sun, Dec 11, 2022 at 12:00:39AM +0800, Zhang Chen wrote:
> KVM needs to check if guests can see RRSBA_CTRL. If a guest is using
> retpoline and cannot see RRSBA_CTRL and the host enumerates RRSBA,
> KVM is responsible for setting RRSBA_DIS_S for the guest.
>
> This allows VM migration from parts doesn't enumerates RRSBA to those

perhaps s/parts doesn't enumerates/parts that do not enumerate/ reads
better?

> that enumerate RRSBA.

and here maybe s/that enumerate RRSBA/do/ ?

Thanks and BR,
Ricardo

2022-12-15 03:22:01

by Zhang, Chen

[permalink] [raw]
Subject: RE: [RFC PATCH 2/9] KVM: x86: Add a kvm-only leaf for RRSBA_CTRL



> -----Original Message-----
> From: Ricardo Neri <[email protected]>
> Sent: Thursday, December 15, 2022 5:34 AM
> To: Zhang, Chen <[email protected]>
> Cc: [email protected]; [email protected]; [email protected]; Gao,
> Chao <[email protected]>; Pawan Gupta
> <[email protected]>; Paolo Bonzini
> <[email protected]>; Christopherson,, Sean <[email protected]>; H.
> Peter Anvin <[email protected]>; Dave Hansen <[email protected]>;
> Borislav Petkov <[email protected]>; Ingo Molnar <[email protected]>; Thomas
> Gleixner <[email protected]>
> Subject: Re: [RFC PATCH 2/9] KVM: x86: Add a kvm-only leaf for RRSBA_CTRL
>
> On Sun, Dec 11, 2022 at 12:00:39AM +0800, Zhang Chen wrote:
> > KVM needs to check if guests can see RRSBA_CTRL. If a guest is using
> > retpoline and cannot see RRSBA_CTRL and the host enumerates RRSBA, KVM
> > is responsible for setting RRSBA_DIS_S for the guest.
> >
> > This allows VM migration from parts doesn't enumerates RRSBA to those
>
> perhaps s/parts doesn't enumerates/parts that do not enumerate/ reads
> better?

OK.

>
> > that enumerate RRSBA.
>
> and here maybe s/that enumerate RRSBA/do/ ?

Looks good to me. Thanks for your comments.
I will fix patch2/3 in the next version.

Thanks
Chen

>
> Thanks and BR,
> Ricardo