Page MenuHomeFreeBSD

D61640.1794945161.diff
No OneTemporary

Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None

D61640.1794945161.diff

diff --git a/sys/amd64/acpica/acpi_wakeup.c b/sys/amd64/acpica/acpi_wakeup.c
--- a/sys/amd64/acpica/acpi_wakeup.c
+++ b/sys/amd64/acpica/acpi_wakeup.c
@@ -213,6 +213,7 @@
hw_ibrs_ibpb_active = 0;
hw_ssb_active = 0;
cpu_stdext_feature3 = 0;
+ hw_spec_ctrl = 0;
CPU_FOREACH(i) {
pc = pcpu_find(i);
pc->pc_ibpb_set = 0;
diff --git a/sys/amd64/amd64/exception.S b/sys/amd64/amd64/exception.S
--- a/sys/amd64/amd64/exception.S
+++ b/sys/amd64/amd64/exception.S
@@ -670,7 +670,7 @@
cmpq $~0,%rax
je 1f
movq %rax,%cr3
-1: testl $CPUID_STDEXT3_IBPB,cpu_stdext_feature3(%rip)
+1: cmpl $0,hw_spec_ctrl(%rip)
je 2f
movl $MSR_IA32_SPEC_CTRL,%ecx
rdmsr
@@ -678,7 +678,7 @@
call handle_ibrs_entry
2: movq %rsp,%rdi
call trap
- testl $CPUID_STDEXT3_IBPB,cpu_stdext_feature3(%rip)
+ cmpl $0,hw_spec_ctrl(%rip)
je 3f
movl %r14d,%eax
xorl %edx,%edx
@@ -807,7 +807,7 @@
cmpq $~0,%rax
je 1f
movq %rax,%cr3
-1: testl $CPUID_STDEXT3_IBPB,cpu_stdext_feature3(%rip)
+1: cmpl $0,hw_spec_ctrl(%rip)
je nmi_calltrap
movl $MSR_IA32_SPEC_CTRL,%ecx
rdmsr
@@ -919,7 +919,7 @@
/*
* Restore speculation control MSR, if preserved.
*/
- testl $CPUID_STDEXT3_IBPB,cpu_stdext_feature3(%rip)
+ cmpl $0,hw_spec_ctrl(%rip)
je 1f
movl %r14d,%eax
xorl %edx,%edx
@@ -1011,7 +1011,7 @@
cmpq $~0,%rax
je 1f
movq %rax,%cr3
-1: testl $CPUID_STDEXT3_IBPB,cpu_stdext_feature3(%rip)
+1: cmpl $0,hw_spec_ctrl(%rip)
je mchk_calltrap
movl $MSR_IA32_SPEC_CTRL,%ecx
rdmsr
@@ -1038,7 +1038,7 @@
/*
* Restore speculation control MSR, if preserved.
*/
- testl $CPUID_STDEXT3_IBPB,cpu_stdext_feature3(%rip)
+ cmpl $0,hw_spec_ctrl(%rip)
je 1f
movl %r14d,%eax
xorl %edx,%edx
diff --git a/sys/x86/include/x86_var.h b/sys/x86/include/x86_var.h
--- a/sys/x86/include/x86_var.h
+++ b/sys/x86/include/x86_var.h
@@ -92,6 +92,7 @@
extern int i386_read_exec;
extern int pti;
extern int hw_ibrs_ibpb_active;
+extern int hw_spec_ctrl;
extern int hw_mds_disable;
extern int hw_ssb_active;
extern int x86_taa_enable;
diff --git a/sys/x86/x86/cpu_machdep.c b/sys/x86/x86/cpu_machdep.c
--- a/sys/x86/x86/cpu_machdep.c
+++ b/sys/x86/x86/cpu_machdep.c
@@ -1172,6 +1172,7 @@
static int hw_ibrs_active;
int hw_ibrs_ibpb_active;
+int hw_spec_ctrl; /* MSR_IA32_SPEC_CTRL is present */
int hw_ibrs_disable = 1;
SYSCTL_INT(_hw, OID_AUTO, ibrs_active, CTLFLAG_RD, &hw_ibrs_active, 0,
@@ -1184,6 +1185,21 @@
SYSCTL_INT(_machdep_mitigations_ibrs, OID_AUTO, active, CTLFLAG_RD,
&hw_ibrs_active, 0, "Indirect Branch Restricted Speculation active");
+/*
+ * handle_ibrs_entry() sets IBRS and STIBP in SPEC_CTRL. Intel reports
+ * both with CPUID 7 EDX, AMD reports them in CPUID 0x80000008 EBX.
+ */
+static bool
+hw_ibrs_entry_ok(void)
+{
+ u_int amd;
+
+ if ((cpu_stdext_feature3 & CPUID_STDEXT3_IBPB) != 0)
+ return (true);
+ amd = AMDFEID_IBRS | AMDFEID_STIBP;
+ return ((amd_extended_feature_extensions & amd) == amd);
+}
+
void
hw_ibrs_recalculate(bool for_all_cpus)
{
@@ -1195,8 +1211,8 @@
hw_ibrs_active = hw_ibrs_disable == 0;
hw_ibrs_ibpb_active = 0;
} else {
- hw_ibrs_active = hw_ibrs_ibpb_active = (cpu_stdext_feature3 &
- CPUID_STDEXT3_IBPB) != 0 && !hw_ibrs_disable;
+ hw_ibrs_active = hw_ibrs_ibpb_active = hw_ibrs_entry_ok() &&
+ !hw_ibrs_disable;
}
}
@@ -1240,7 +1256,8 @@
hw_ssb_set(bool enable, bool for_all_cpus)
{
- if ((cpu_stdext_feature3 & CPUID_STDEXT3_SSBD) == 0) {
+ if ((cpu_stdext_feature3 & CPUID_STDEXT3_SSBD) == 0 &&
+ (amd_extended_feature_extensions & AMDFEID_SSBD) == 0) {
hw_ssb_active = 0;
return;
}
@@ -1266,8 +1283,9 @@
hw_ssb_set(true, all_cpus);
break;
case 2: /* auto */
- hw_ssb_set((cpu_ia32_arch_caps & IA32_ARCH_CAP_SSB_NO) != 0 ?
- false : true, all_cpus);
+ hw_ssb_set((cpu_ia32_arch_caps & IA32_ARCH_CAP_SSB_NO) == 0 &&
+ (amd_extended_feature_extensions & AMDFEID_SSB_NO) == 0,
+ all_cpus);
break;
}
}
diff --git a/sys/x86/x86/identcpu.c b/sys/x86/x86/identcpu.c
--- a/sys/x86/x86/identcpu.c
+++ b/sys/x86/x86/identcpu.c
@@ -1673,6 +1673,19 @@
}
}
+/*
+ * MSR_IA32_SPEC_CTRL is present if either vendor reports a feature
+ * controlled by it.
+ */
+static void
+identify_spec_ctrl(void)
+{
+
+ hw_spec_ctrl = (cpu_stdext_feature3 & CPUID_STDEXT3_IBPB) != 0 ||
+ (amd_extended_feature_extensions & (AMDFEID_IBRS | AMDFEID_STIBP |
+ AMDFEID_SSBD)) != 0;
+}
+
void
identify_cpu_ext_features(void)
{
@@ -1683,6 +1696,7 @@
cpu_stdext_feature2 = regs[2];
cpu_stdext_feature3 = regs[3];
}
+ identify_spec_ctrl();
}
void
@@ -1766,6 +1780,7 @@
amd_extended_feature2 = regs[0];
amd_extended_feature2_ecx = regs[2];
}
+ identify_spec_ctrl();
#ifdef __i386__
if (cpu_vendor_id == CPU_VENDOR_CYRIX) {

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 17, 7:52 PM (23 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41806483
Default Alt Text
D61640.1794945161.diff (4 KB)

Event Timeline