target/i386: Add more features enumerated by CPUID.7.2.EDX
PATCH 1/1 target/i386: Add more features enumerated by CPUID.7.2.EDX
Following 5 bits in CPUID.7.2.EDX are supported by KVM. Add their supports in QEMU. Each of them indicates certain bits of IA32_SPEC_CTRL are supported. Those bits can control CPU speculation behavior which can be used to defend against side-channel attacks.
bit0: intel-psfd
if 1, indicates bit 7 of the IA32_SPEC_CTRL MSR is supported. Bit 7 of this MSR disables Fast Store Forwarding Predictor without disabling Speculative Store Bypass
bit1: ipred-ctrl
If 1, indicates bits 3 and 4 of the IA32_SPEC_CTRL MSR are supported. Bit 3 of this MSR enables IPRED_DIS control for CPL3. Bit 4 of this MSR enables IPRED_DIS control for CPL0/1/2
bit2: rrsba-ctrl
If 1, indicates bits 5 and 6 of the IA32_SPEC_CTRL MSR are supported. Bit 5 of this MSR disables RRSBA behavior for CPL3. Bit 6 of this MSR disables RRSBA behavior for CPL0/1/2
bit3: ddpd-u
If 1, indicates bit 8 of the IA32_SPEC_CTRL MSR is supported. Bit 8 of this MSR disables Data Dependent Prefetcher.
bit4: bhi-ctrl
if 1, indicates bit 10 of the IA32_SPEC_CTRL MSR is supported. Bit 10 of this MSR enables BHI_DIS_S behavior.
--- target/i386/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/cpu.c +2 -2
@@ -1148,8 +1148,8 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { [FEAT_7_2_EDX] = { .type = CPUID_FEATURE_WORD, .feat_names = { -NULL ,NULL ,NULL ,NULL , -NULL ,"mcdt-no" ,NULL ,NULL , +"intel-psfd" ,"ipred-ctrl" ,"rrsba-ctrl" ,"ddpd-u" , +"bhi-ctrl" ,"mcdt-no" ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , NULL, NULL, NULL, NULL,
Signature · 1 line
2.46.1
Quoted 43 lines · Chao Gao
Date: Thu, 19 Sep 2024 13:10:11 +0800
From: Chao Gao <[email protected]>
Subject: [PATCH] target/i386: Add more features enumerated by CPUID.7.2.EDX
X-Mailer: git-send-email 2.46.1Following 5 bits in CPUID.7.2.EDX are supported by KVM. Add their supports in QEMU. Each of them indicates certain bits of
IA32_SPEC_CTRLare supported. Those bits can control CPU speculation behavior which can be used to defend against side-channel attacks.bit0: intel-psfd
if 1, indicates bit 7 of theIA32_SPEC_CTRLMSR is supported. Bit 7 of this MSR disables Fast Store Forwarding Predictor without disabling Speculative Store Bypassbit1: ipred-ctrl
If 1, indicates bits 3 and 4 of theIA32_SPEC_CTRLMSR are supported. Bit 3 of this MSR enablesIPRED_DIScontrol for CPL3. Bit 4 of this MSR enablesIPRED_DIScontrol for CPL0/1/2bit2: rrsba-ctrl
If 1, indicates bits 5 and 6 of theIA32_SPEC_CTRLMSR are supported. Bit 5 of this MSR disables RRSBA behavior for CPL3. Bit 6 of this MSR disables RRSBA behavior for CPL0/1/2bit3: ddpd-u
If 1, indicates bit 8 of theIA32_SPEC_CTRLMSR is supported. Bit 8 of this MSR disables Data Dependent Prefetcher.bit4: bhi-ctrl
if 1, indicates bit 10 of theIA32_SPEC_CTRLMSR is supported. Bit 10 of this MSR enablesBHI_DIS_Sbehavior.Signed-off-by Chao Gao <[email protected]>--- target/i386/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/i386/cpu.c +0
-0
target/i386/cpu.c FeatureWordInfo feature_word_info[FEATURE_WORDS] = { · line 1152
Quoted 7 lines
target/i386/cpu.c +2
-2@@ -1148,8 +1148,8 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { [FEAT_7_2_EDX] = { .type = CPUID_FEATURE_WORD, .feat_names = { -NULL ,NULL ,NULL ,NULL , - NULL, "mcdt-no", NULL, NULL, +"intel-psfd" ,"ipred-ctrl" ,"rrsba-ctrl" ,"ddpd-u" , + "bhi-ctrl", "mcdt-no", NULL, NULL,
IIUC, these bits depend on "spec-ctrl", which indicates the presence of IA32_SPEC_CTRL.
Then I think we'd better add dependencies in feature_dependencies[].
-Zhao
Quoted 7 lines
target/i386/cpu.c +0
-0NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , NULL, NULL, NULL, NULL,Signature · 1 line
2.46.1
Quoted 16 lines
target/i386/cpu.c FeatureWordInfo feature_word_info[FEATURE_WORDS] = { · line 1152
Quoted 12 lines
target/i386/cpu.c +2
-2@@ -1148,8 +1148,8 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { [FEAT_7_2_EDX] = { .type = CPUID_FEATURE_WORD, .feat_names = { -NULL ,NULL ,NULL ,NULL , - NULL, "mcdt-no", NULL, NULL, +"intel-psfd" ,"ipred-ctrl" ,"rrsba-ctrl" ,"ddpd-u" , + "bhi-ctrl", "mcdt-no", NULL, NULL,IIUC, these bits depend on "spec-ctrl", which indicates the presence of
IA32_SPEC_CTRL.
Quoted 1 line
Then I think we'd better add dependencies in feature_dependencies[].
(+ kvm mailing list)
Thanks for pointing that out. It seems that any of these bits imply the presence of IA32_SPEC_CTRL. According to SDM vol4, chapter 2, table 2.2, the 'Comment' column for the IA32_SPEC_CTRL MSR states:
If any one of the enumeration conditions for defined bit field positions holds.
So, it might be more appropriate to fix KVM's handling of the IA32_SPEC_CTRL MSR (i.e., guest_has_spec_ctrl_msr()).
what do you think?
Quoted 10 lines
-Zhao
Quoted 7 lines
target/i386/cpu.c +0
-0NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , NULL, NULL, NULL, NULL,Signature · 1 line
2.46.1
Paolo Bonzini
maintainerQuoted 24 lines · Chao Gao
Quoted 16 lines
target/i386/cpu.c FeatureWordInfo feature_word_info[FEATURE_WORDS] = { · line 1152
Quoted 12 lines
target/i386/cpu.c +2
-2@@ -1148,8 +1148,8 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { [FEAT_7_2_EDX] = { .type = CPUID_FEATURE_WORD, .feat_names = { -NULL ,NULL ,NULL ,NULL , - NULL, "mcdt-no", NULL, NULL, +"intel-psfd" ,"ipred-ctrl" ,"rrsba-ctrl" ,"ddpd-u" , + "bhi-ctrl", "mcdt-no", NULL, NULL,IIUC, these bits depend on "spec-ctrl", which indicates the presence of
IA32_SPEC_CTRL.Quoted 1 line
Then I think we'd better add dependencies in feature_dependencies[].
(+ kvm mailing list)
Thanks for pointing that out. It seems that any of these bits imply the presence of
IA32_SPEC_CTRL. According to SDM vol4, chapter 2, table 2.2, the 'Comment' column for theIA32_SPEC_CTRLMSR states:
Quoted 6 lines
If any one of the enumeration conditions for defined bit field positions holds.
So, it might be more appropriate to fix KVM's handling of the
IA32_SPEC_CTRLMSR (i.e.,guest_has_spec_ctrl_msr()).what do you think?
You're right, the spec-ctrl CPUID feature covers the IBRS bit of MSR_IA32_SPEC_CTRL and also the IBPB feature of MSR_IA32_PRED_CMD. It does not specify the existence of MSR_IA32_SPEC_CTRL.
In practice it's probably not a good idea to omit spec-ctrl when passing other features to the guest that cover that MSR; but the specification says it's fine.
Paolo
Quoted 37 lines · Paolo Bonzini
Date: Thu, 10 Oct 2024 15:17:16 +0200
From: Paolo Bonzini <[email protected]>
Subject: Re: [PATCH] target/i386: Add more features enumerated by
CPUID.7.2.EDXQuoted 24 lines · Chao Gao
Quoted 16 lines
target/i386/cpu.c FeatureWordInfo feature_word_info[FEATURE_WORDS] = { · line 1152
Quoted 12 lines
target/i386/cpu.c +2
-2@@ -1148,8 +1148,8 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { [FEAT_7_2_EDX] = { .type = CPUID_FEATURE_WORD, .feat_names = { -NULL ,NULL ,NULL ,NULL , - NULL, "mcdt-no", NULL, NULL, +"intel-psfd" ,"ipred-ctrl" ,"rrsba-ctrl" ,"ddpd-u" , + "bhi-ctrl", "mcdt-no", NULL, NULL,IIUC, these bits depend on "spec-ctrl", which indicates the presence of
IA32_SPEC_CTRL.Quoted 1 line
Then I think we'd better add dependencies in feature_dependencies[].
(+ kvm mailing list)
Thanks for pointing that out. It seems that any of these bits imply the presence of
IA32_SPEC_CTRL. According to SDM vol4, chapter 2, table 2.2, the 'Comment' column for theIA32_SPEC_CTRLMSR states:Quoted 6 lines
If any one of the enumeration conditions for defined bit field positions holds.
So, it might be more appropriate to fix KVM's handling of the
IA32_SPEC_CTRLMSR (i.e.,guest_has_spec_ctrl_msr()).what do you think?
Quoted 7 lines
You're right, the spec-ctrl CPUID feature covers the IBRS bit of
MSR_IA32_SPEC_CTRLand also the IBPB feature ofMSR_IA32_PRED_CMD. It does not specify the existence ofMSR_IA32_SPEC_CTRL.In practice it's probably not a good idea to omit spec-ctrl when passing other features to the guest that cover that MSR; but the specification says it's fine.
I think these features are also worth updating in the CPU models, as well as in this document: 'cpu-models-x86.rst.inc' - section 'Important CPU features for Intel x86 hosts' (maybe in the followup patches :))
Thanks,
Zhao
Queued, thanks.
Paolo