|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v2 2/3] x86/amd: Drop cpu_has_amd_erratum()
cpu_has_amd_erratum() takes the family-model-stepping ranges of an
erratum as variadic arguments, which MISRA C Rule 17.1 forbids, and the
ranges themselves are packed into integers by AMD_MODEL_RANGE(), which
makes them hard to read.
Replace it with one static inline predicate per erratum in asm/amd.h,
stating the vendor, family and models it covers.
No functional change.
Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
---
xen/arch/x86/cpu/amd.c | 32 +--------------
xen/arch/x86/domain.c | 2 +-
xen/arch/x86/hvm/svm/asid.c | 2 +-
xen/arch/x86/hvm/svm/svm.c | 2 +-
xen/arch/x86/include/asm/amd.h | 55 ++++++++++----------------
xen/arch/x86/x86_emulate/fpu.c | 7 ++--
xen/arch/x86/x86_emulate/x86_emulate.c | 5 ---
7 files changed, 27 insertions(+), 78 deletions(-)
diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c
index 0515a314dc..a2386cbfa4 100644
--- a/xen/arch/x86/cpu/amd.c
+++ b/xen/arch/x86/cpu/amd.c
@@ -317,36 +317,6 @@ void amd_set_cpuid_user_dis(bool enable)
wrmsrl(MSR_K8_HWCR, val);
}
-/*
- * Check for the presence of an AMD erratum. Arguments are defined in amd.h
- * for each known erratum. Return 1 if erratum is found.
- */
-int cpu_has_amd_erratum(const struct cpuinfo_x86 *cpu, ...)
-{
- va_list ap;
- u32 range;
- u32 ms;
-
- if (cpu->vendor != X86_VENDOR_AMD)
- return 0;
-
- /* Match family-model-stepping range */
- va_start(ap, cpu);
-
- ms = (cpu->model << 4) | cpu->stepping;
- while ((range = va_arg(ap, int))) {
- if ((cpu->family == AMD_MODEL_RANGE_FAMILY(range)) &&
- (ms >= AMD_MODEL_RANGE_START(range)) &&
- (ms <= AMD_MODEL_RANGE_END(range))) {
- va_end(ap);
- return 1;
- }
- }
-
- va_end(ap);
- return 0;
-}
-
/*
* Disable C1-Clock ramping if enabled in PMM7.CpuLowPwrEnh on 8th-generation
* cores only. Assume BIOS has setup all Northbridges equivalently.
@@ -1208,7 +1178,7 @@ static void cf_check init_amd(struct cpuinfo_x86 *c)
if (c->family == 0x10)
__clear_bit(X86_FEATURE_MONITOR, c->x86_capability);
- if (!cpu_has_amd_erratum(c, AMD_ERRATUM_121))
+ if (!cpu_has_amd_erratum_121(c))
opt_allow_unsafe = 1;
else if (opt_allow_unsafe < 0)
panic("Xen will not boot on this CPU for security reasons"
diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 74513a79a7..031b292b08 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -833,7 +833,7 @@ int arch_domain_create(struct domain *d,
if ( !is_hvm_domain(d) )
d->options |= XEN_DOMCTL_CDF_oos_off;
- if ( d->domain_id && cpu_has_amd_erratum(&boot_cpu_data, AMD_ERRATUM_121) )
+ if ( d->domain_id && cpu_has_amd_erratum_121(&boot_cpu_data) )
{
if ( !opt_allow_unsafe )
{
diff --git a/xen/arch/x86/hvm/svm/asid.c b/xen/arch/x86/hvm/svm/asid.c
index c8d86938d1..e070d97ef8 100644
--- a/xen/arch/x86/hvm/svm/asid.c
+++ b/xen/arch/x86/hvm/svm/asid.c
@@ -16,7 +16,7 @@ void svm_asid_init(const struct cpuinfo_x86 *c)
unsigned int nasids = 0;
/* Check for erratum #170, and leave ASIDs disabled if it's present. */
- if ( !cpu_has_amd_erratum(c, AMD_ERRATUM_170) )
+ if ( !cpu_has_amd_erratum_170(c) )
nasids = cpuid_ebx(0x8000000aU);
hvm_asid_init(nasids);
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index bfca1eda4a..fd89b9bd36 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1439,7 +1439,7 @@ static void svm_init_erratum_383(const struct cpuinfo_x86
*c)
uint64_t msr_content;
/* check whether CPU is affected */
- if ( !cpu_has_amd_erratum(c, AMD_ERRATUM_383) )
+ if ( !cpu_has_amd_erratum_383(c) )
return;
/* use safe methods to be compatible with nested virtualization */
diff --git a/xen/arch/x86/include/asm/amd.h b/xen/arch/x86/include/asm/amd.h
index 762b1fbf7a..3ed133fcd5 100644
--- a/xen/arch/x86/include/asm/amd.h
+++ b/xen/arch/x86/include/asm/amd.h
@@ -6,43 +6,31 @@
#define __AMD_H__
#include <asm/cpufeature.h>
+#include <asm/x86-vendors.h>
-/* AMD errata checking
- *
- * Errata are defined using the AMD_LEGACY_ERRATUM() macro, which takes a
- * variable number of family-specific model-stepping ranges created by
- * AMD_MODEL_RANGE().
- *
- * Example:
- * #define AMD_ERRATUM_319 \
- * AMD_LEGACY_ERRATUM(AMD_MODEL_RANGE(0x10, 0x2, 0x1, 0x4, 0x2), \
- * AMD_MODEL_RANGE(0x10, 0x8, 0x0, 0x8, 0x0), \
- * AMD_MODEL_RANGE(0x10, 0x9, 0x0, 0x9, 0x0))
- *
+/*
+ * AMD errata Xen works around, each named after its number in the Revision
+ * Guide for the families it affects.
*/
+static inline bool cpu_has_amd_erratum_121(const struct cpuinfo_x86 *c)
+{
+ return c->vendor == X86_VENDOR_AMD && c->family == 0xf && c->model <= 0x3f;
+}
-#define AMD_LEGACY_ERRATUM(...) __VA_ARGS__, 0
-#define AMD_MODEL_RANGE(f, m_start, s_start, m_end, s_end) \
- (((f) << 24) | ((m_start) << 16) | ((s_start) << 12) | \
- ((m_end) << 4) | (s_end))
-#define AMD_MODEL_RANGE_FAMILY(range) (((range) >> 24) & 0xff)
-#define AMD_MODEL_RANGE_START(range) (((range) >> 12) & 0xfff)
-#define AMD_MODEL_RANGE_END(range) ((range) & 0xfff)
+static inline bool cpu_has_amd_erratum_170(const struct cpuinfo_x86 *c)
+{
+ return c->vendor == X86_VENDOR_AMD && c->family == 0xf && c->model <= 0x67;
+}
-#define AMD_ERRATUM_121 \
- AMD_LEGACY_ERRATUM(AMD_MODEL_RANGE(0x0f, 0x0, 0x0, 0x3f, 0xf))
+static inline bool cpu_has_amd_erratum_383(const struct cpuinfo_x86 *c)
+{
+ return c->vendor == X86_VENDOR_AMD && c->family == 0x10;
+}
-#define AMD_ERRATUM_170 \
- AMD_LEGACY_ERRATUM(AMD_MODEL_RANGE(0x0f, 0x0, 0x0, 0x67, 0xf))
-
-#define AMD_ERRATUM_383 \
- AMD_LEGACY_ERRATUM(AMD_MODEL_RANGE(0x10, 0x0, 0x0, 0xff, 0xf))
-
-#define AMD_ERRATUM_573
\
- AMD_LEGACY_ERRATUM(AMD_MODEL_RANGE(0x0f, 0x0, 0x0, 0xff, 0xf), \
- AMD_MODEL_RANGE(0x10, 0x0, 0x0, 0xff, 0xf), \
- AMD_MODEL_RANGE(0x11, 0x0, 0x0, 0xff, 0xf), \
- AMD_MODEL_RANGE(0x12, 0x0, 0x0, 0xff, 0xf))
+static inline bool cpu_has_amd_erratum_573(const struct cpuinfo_x86 *c)
+{
+ return c->vendor == X86_VENDOR_AMD && c->family >= 0xf && c->family <=
0x12;
+}
/*
* The Zen1 and Zen2 microarchitectures are implemented by AMD (Fam17h) and
@@ -64,9 +52,6 @@
#define is_zen5_uarch() (!boot_cpu_has(X86_FEATURE_FRED))
#define is_zen6_uarch() boot_cpu_has(X86_FEATURE_FRED)
-struct cpuinfo_x86;
-int cpu_has_amd_erratum(const struct cpuinfo_x86 *cpu, ...);
-
extern int8_t opt_allow_unsafe;
void fam10h_check_enable_mmcfg(void);
diff --git a/xen/arch/x86/x86_emulate/fpu.c b/xen/arch/x86/x86_emulate/fpu.c
index 88df238981..c024f3c601 100644
--- a/xen/arch/x86/x86_emulate/fpu.c
+++ b/xen/arch/x86/x86_emulate/fpu.c
@@ -12,10 +12,9 @@
#ifdef __XEN__
# include <asm/amd.h>
-# define cpu_has_amd_erratum(nr) \
- cpu_has_amd_erratum(¤t_cpu_data, AMD_ERRATUM_##nr)
+# define cpu_has_amd_erratum_573() cpu_has_amd_erratum_573(¤t_cpu_data)
#else
-# define cpu_has_amd_erratum(nr) 0
+# define cpu_has_amd_erratum_573() false
#endif
/* Floating point status word definitions. */
@@ -133,7 +132,7 @@ int x86emul_fpu(struct x86_emulate_state *s,
switch ( s->modrm )
{
case 0xfb: /* fsincos */
- fail_if(cpu_has_amd_erratum(573));
+ fail_if(cpu_has_amd_erratum_573());
/* fall through */
case 0xc0 ... 0xc7: /* fld %stN */
case 0xc8 ... 0xcf: /* fxch %stN */
diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c
b/xen/arch/x86/x86_emulate/x86_emulate.c
index 09d43d204b..2027f7ee6a 100644
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -12,7 +12,6 @@
# include <xen/event.h>
-# include <asm/amd.h> /* cpu_has_amd_erratum() */
# include <asm/processor.h> /* current_cpu_info */
# include <asm/x86_emulate.h>
# include <asm/xstate.h>
@@ -22,9 +21,6 @@
# undef cpuid
# undef wbinvd
-# define cpu_has_amd_erratum(nr) \
- cpu_has_amd_erratum(¤t_cpu_data, AMD_ERRATUM_##nr)
-
#else /* !__XEN__ */
/* See gcc bug 100680, but here don't bother making this version dependent. */
@@ -34,7 +30,6 @@
(typeof(x))x_; \
})
-# define cpu_has_amd_erratum(nr) 0
# define cpu_has_mpx false
# define read_bndcfgu() 0
# define xstate_set_init(what)
--
2.43.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |