x86: Add in-scope files under cpu/ to MISRA scans
v3 cover x86: Add in-scope files under cpu/ to MISRA scans
Hi,
v3:
* Bring back Fam12h
* Fix off by one error in Fam12h handling inside errata 383
v2: https://lore.kernel.org/xen-devel/[email protected]/
v1: https://lore.kernel.org/xen-devel/[email protected]/
Original cover letter:
The files under cpu/ are excluded from MISRA scans due to their Linux provenance but they aren't kept in close sync. At best they get semiregular updates (mwait_idle.c), but most often the files grow with Xen specifics bops that get a free pass on MISRA scans merely due to colocation with ancient Linux code. Some files just were never part of Linux (hygon.c) to begin with, which makes the blanket exclusion even less credible.
This series brings everything under the MISRA scan umbrella, with the surprisingly few fixes involved
Cheers,
Alejandro
Alejandro Vallejo (3):
x86/amd: Fix off by one error in Fam12h range of erratum 383 x86/amd: Drop cpu_has_amd_erratum()
eclair/x86: Scan in-scope files inside cpu/
.../eclair_analysis/ECLAIR/deviations.ecl | 3 - docs/misra/exclude-list.json | 36 ---------- xen/arch/x86/cpu/amd.c | 47 +------------ 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 | 66 +++++++------------ xen/arch/x86/x86_emulate/fpu.c | 7 +- xen/arch/x86/x86_emulate/x86_emulate.c | 5 -- 9 files changed, 32 insertions(+), 138 deletions(-)
base-commit: 13d4a6776b931481984e0c1caf5a228ace3ec701
Signature · 1 line
2.43.0
PATCH v3 1/3 x86/amd: Fix off by one error in Fam12h range of erratum 383
Model 1 isn't affected, but the macro says it is (end is inclusive). Mark the limit as model0/steppingF.
While at it, note that OSVW is purely redundant with the fallback list. We only use it for errata 383, but that has a well known set of processors it affects so we can rely on the exhaustive list.
---
v3:
* Kept Fam12h on errata 383, because there might be someone hoarding a 15yo engineering sample and expecting a 2026 Xen to work well on it.
--- xen/arch/x86/cpu/amd.c | 21 +++------------------ xen/arch/x86/include/asm/amd.h | 22 ++++++++-------------- 2 files changed, 11 insertions(+), 32 deletions(-)
xen/arch/x86/cpu/amd.c +3 -18
@@ -321,7 +321,7 @@ void amd_set_cpuid_user_dis(bool enable)* 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,int osvw_id, ...) +int cpu_has_amd_erratum (const struct cpuinfo_x86 *cpu, ...) {va_list ap;u32 range;
@@ -330,23 +330,8 @@ int cpu_has_amd_erratum(const struct cpuinfo_x86 *cpu, int osvw_id, ...)if (cpu->vendor !=X86_VENDOR_AMD )return 0 ; -if (osvw_id >=0 &&cpu_has (cpu,X86_FEATURE_OSVW )) { -u64 osvw_len; - -rdmsrl (MSR_AMD_OSVW_ID_LENGTH , osvw_len); - -if (osvw_id < osvw_len) { -u64 osvw_bits; - -rdmsrl (MSR_AMD_OSVW_STATUS + (osvw_id >>6 ), - osvw_bits); - -return (osvw_bits >> (osvw_id &0x3f )) &1 ; - } - } - -/* OSVW unavailable or ID unknown, match family-model-stepping range */ -va_start (ap, osvw_id); +/* Match family-model-stepping range */ +va_start (ap, cpu); ms = (cpu->model <<4 ) | cpu->stepping;while ((range =va_arg (ap, int))) {
xen/arch/x86/include/asm/amd.h +8 -14
@@ -9,25 +9,19 @@/* AMD errata checking * -* Errata are defined using the AMD_LEGACY_ERRATUM() or AMD_OSVW_ERRATUM() -* macros. The latter is intended for newer errata that have an OSVW id -* assigned, which it takes as first argument. Both take a variable number -* of family-specific model-stepping ranges created by AMD_MODEL_RANGE(). +* 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 1: +* 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)) -* Example 2: -* #define AMD_ERRATUM_400 \ -* AMD_OSVW_ERRATUM(1, AMD_MODEL_RANGE(0xf, 0x41, 0x2, 0xff, 0xf), \ -* AMD_MODEL_RANGE(0x10, 0x2, 0x1, 0xff, 0xf)) * */ -#define AMD_LEGACY_ERRATUM(...) -1 /* legacy */, __VA_ARGS__, 0 -#define AMD_OSVW_ERRATUM (osvw_id, ...) osvw_id, __VA_ARGS__, 0 +#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))
@@ -42,8 +36,8 @@ AMD_LEGACY_ERRATUM(AMD_MODEL_RANGE(0x0f, 0x0, 0x0, 0x67, 0xf))#define AMD_ERRATUM_383 \ - AMD_OSVW_ERRATUM(3, AMD_MODEL_RANGE(0x10, 0x2, 0x1, 0xff, 0xf), \ - AMD_MODEL_RANGE(0x12, 0x0, 0x0, 0x1, 0x0)) + AMD_LEGACY_ERRATUM(AMD_MODEL_RANGE(0x10, 0x2, 0x1, 0xff, 0xf), \ + AMD_MODEL_RANGE(0x12, 0x0, 0x0, 0x00, 0xf))#define AMD_ERRATUM_573 \ AMD_LEGACY_ERRATUM(AMD_MODEL_RANGE(0x0f, 0x0, 0x0, 0xff, 0xf), \
@@ -72,7 +66,7 @@#define is_zen6_uarch () boot_cpu_has(X86_FEATURE_FRED)struct cpuinfo_x86 ; -int cpu_has_amd_erratum (const struct cpuinfo_x86 *cpu,int osvw_id, ...); +int cpu_has_amd_erratum (const struct cpuinfo_x86 *cpu, ...);extern int8_t opt_allow_unsafe;
Signature · 1 line
2.43.0
PATCH v3 2/3 x86/amd: Drop cpu_has_amd_erratum()
In reply to Alejandro Vallejocpu_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.
For errata 383 specifically, take all of Fam10h as affected.
---
v3:
* Change the commit message to highlight Fam10h starts being universally filtered.
--- 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 | 60 +++++++++++--------------- xen/arch/x86/x86_emulate/fpu.c | 7 ++- xen/arch/x86/x86_emulate/x86_emulate.c | 5 --- 7 files changed, 32 insertions(+), 78 deletions(-)
xen/arch/x86/cpu/amd.c +1 -31
@@ -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"
xen/arch/x86/domain.c +1 -1
@@ -845,7 +845,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 ) {
xen/arch/x86/hvm/svm/asid.c +1 -1
@@ -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);
xen/arch/x86/hvm/svm/svm.c +1 -1
@@ -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 */
xen/arch/x86/include/asm/amd.h +25 -35
78 lines not on this page · raw message
xen/arch/x86/x86_emulate/fpu.c +3 -4
@@ -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 */
xen/arch/x86/x86_emulate/x86_emulate.c +0 -5
@@ -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)
Signature · 1 line
2.43.0
PATCH v3 3/3 eclair/x86: Scan in-scope files inside cpu/
In reply to Alejandro VallejoRemove the exclusions now that all in-scope files inside are clean on the regression subset.
--- .../eclair_analysis/ECLAIR/deviations.ecl | 3 -- docs/misra/exclude-list.json | 36 ------------------- 2 files changed, 39 deletions(-)
automation/eclair_analysis/ECLAIR/deviations.ecl +0 -3
@@ -189,9 +189,6 @@ context of R7.2." -file_tag+={adopted_r7_2,"^xen/include/efi/efiapi\\.h$"} -file_tag+={adopted_r7_2,"^xen/include/efi/efidef\\.h$"} -file_tag+={adopted_r7_2,"^xen/include/efi/efiprot\\.h$"} --file_tag+={adopted_r7_2,"^xen/arch/x86/cpu/intel\\.c$"} --file_tag+={adopted_r7_2,"^xen/arch/x86/cpu/amd\\.c$"} --file_tag+={adopted_r7_2,"^xen/arch/x86/cpu/common\\.c$"} -config=MC3A2.R7.2,reports+={deliberate,"any_area(any_loc(file(adopted_r7_2)))"} -doc_end
docs/misra/exclude-list.json +0 -36
@@ -33,42 +33,6 @@ "rel_path": "arch/x86/acpi/lib.c", "comment": "Imported from Linux, ignore for now" }, - { - "rel_path": "arch/x86/cpu/amd.c", - "comment": "Imported from Linux, ignore for now" - }, - { - "rel_path": "arch/x86/cpu/centaur.c", - "comment": "Imported from Linux, ignore for now" - }, - { - "rel_path": "arch/x86/cpu/common.c", - "comment": "Imported from Linux, ignore for now" - }, - { - "rel_path": "arch/x86/cpu/hygon.c", - "comment": "Imported from Linux, ignore for now" - }, - { - "rel_path": "arch/x86/cpu/intel.c", - "comment": "Imported from Linux, ignore for now" - }, - { - "rel_path": "arch/x86/cpu/intel_cacheinfo.c", - "comment": "Imported from Linux, ignore for now" - }, - { - "rel_path": "arch/x86/cpu/mcheck/non-fatal.c", - "comment": "Imported from Linux, ignore for now" - }, - { - "rel_path": "arch/x86/cpu/mtrr/*", - "comment": "Imported from Linux, ignore for now" - }, - { - "rel_path": "arch/x86/cpu/mwait-idle.c", - "comment": "Imported from Linux, ignore for now" - }, { "rel_path": "arch/x86/delay.c", "comment": "Imported from Linux, ignore for now"
Signature · 1 line
2.43.0