* [PATCH 0/5] x86: Add in-scope files under cpu/ to MISRA scans
@ 2026-11-18 17:17 Alejandro Vallejo
2026-11-18 17:17 ` [PATCH 1/5] x86/cpu: Add break to early_cpu_init() switch Alejandro Vallejo
` (4 more replies)
0 siblings, 5 replies; 13+ messages in thread
From: Alejandro Vallejo @ 2026-11-18 17:17 UTC (permalink / raw)
To: xen-devel
Cc: Alejandro Vallejo, Jan Beulich, Andrew Cooper,
Roger Pau Monné, Teddy Astie, Nicola Vetrini, Doug Goldstein,
Stefano Stabellini, Anthony PERARD, Michal Orzel, Julien Grall
Hi,
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.
eclair pipeline: https://gitlab.com/xen-project/people/agvallejo/xen/-/jobs/18149225087
regular pipeline (still running): https://gitlab.com/xen-project/people/agvallejo/xen/-/pipelines/3085381461
Alejandro Vallejo (5):
x86/cpu: Add break to early_cpu_init() switch
x86/mtrr: Address MISRA C Rules 5.3, 8.3 and 8.4
x86/cpu: Use U suffixes on integer constants
x86/amd: Make cpu_has_amd_erratum() non-variadic
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 | 62 +++++++++----------
xen/arch/x86/cpu/centaur.c | 4 +-
xen/arch/x86/cpu/common.c | 49 ++++++++-------
xen/arch/x86/cpu/hygon.c | 8 +--
xen/arch/x86/cpu/mtrr/generic.c | 6 +-
xen/arch/x86/cpu/mtrr/main.c | 4 +-
xen/arch/x86/include/asm/amd.h | 11 ++--
9 files changed, 73 insertions(+), 110 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 1/5] x86/cpu: Add break to early_cpu_init() switch
2026-11-18 17:17 [PATCH 0/5] x86: Add in-scope files under cpu/ to MISRA scans Alejandro Vallejo
@ 2026-11-18 17:17 ` Alejandro Vallejo
2026-11-18 18:45 ` Andrew Cooper
2026-11-18 17:17 ` [PATCH 2/5] x86/mtrr: Address MISRA C Rules 5.3, 8.3 and 8.4 Alejandro Vallejo
` (3 subsequent siblings)
4 siblings, 1 reply; 13+ messages in thread
From: Alejandro Vallejo @ 2026-11-18 17:17 UTC (permalink / raw)
To: xen-devel
Cc: Alejandro Vallejo, Jan Beulich, Andrew Cooper,
Roger Pau Monné, Teddy Astie
MISRA C Rule 16.3 requires every switch clause to be terminated by an
unconditional break statement.
No functional change.
Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@amd.com>
---
xen/arch/x86/cpu/common.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c
index 43785d19cc..54e3a02dd1 100644
--- a/xen/arch/x86/cpu/common.c
+++ b/xen/arch/x86/cpu/common.c
@@ -341,6 +341,7 @@ void __init early_cpu_init(bool verbose)
printk(XENLOG_ERR
"Unrecognised or unsupported CPU vendor '%.12s'\n",
c->x86_vendor_id);
+ break;
}
cpuid(0x00000001, &eax, &ebx, &ecx, &edx);
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 2/5] x86/mtrr: Address MISRA C Rules 5.3, 8.3 and 8.4
2026-11-18 17:17 [PATCH 0/5] x86: Add in-scope files under cpu/ to MISRA scans Alejandro Vallejo
2026-11-18 17:17 ` [PATCH 1/5] x86/cpu: Add break to early_cpu_init() switch Alejandro Vallejo
@ 2026-11-18 17:17 ` Alejandro Vallejo
2026-11-18 18:46 ` Andrew Cooper
2026-11-18 17:17 ` [PATCH 3/5] x86/cpu: Use U suffixes on integer constants Alejandro Vallejo
` (2 subsequent siblings)
4 siblings, 1 reply; 13+ messages in thread
From: Alejandro Vallejo @ 2026-11-18 17:17 UTC (permalink / raw)
To: xen-devel
Cc: Alejandro Vallejo, Jan Beulich, Andrew Cooper,
Roger Pau Monné, Teddy Astie
Define num_var_ranges with the type it is declared with in mtrr.h
(Rule 8.3), make usage_table static as nothing outside main.c uses it
(Rule 8.4), and rename the local variable in is_var_mtrr_overlapped()
that hides the global num_var_ranges (Rule 5.3).
No functional change.
Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@amd.com>
---
xen/arch/x86/cpu/mtrr/generic.c | 6 +++---
xen/arch/x86/cpu/mtrr/main.c | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/xen/arch/x86/cpu/mtrr/generic.c b/xen/arch/x86/cpu/mtrr/generic.c
index 4cc7c8bd5d..5df3cf491c 100644
--- a/xen/arch/x86/cpu/mtrr/generic.c
+++ b/xen/arch/x86/cpu/mtrr/generic.c
@@ -57,9 +57,9 @@ get_fixed_ranges(mtrr_type * frs)
bool is_var_mtrr_overlapped(const struct mtrr_state *m)
{
unsigned int seg, i;
- unsigned int num_var_ranges = MASK_EXTR(m->mtrr_cap, MTRRcap_VCNT);
+ unsigned int nr_ranges = MASK_EXTR(m->mtrr_cap, MTRRcap_VCNT);
- for ( i = 0; i < num_var_ranges; i++ )
+ for ( i = 0; i < nr_ranges; i++ )
{
uint64_t base1 = m->var_ranges[i].base >> PAGE_SHIFT;
uint64_t mask1 = m->var_ranges[i].mask >> PAGE_SHIFT;
@@ -67,7 +67,7 @@ bool is_var_mtrr_overlapped(const struct mtrr_state *m)
if ( !(m->var_ranges[i].mask & MTRR_PHYSMASK_VALID) )
continue;
- for ( seg = i + 1; seg < num_var_ranges; seg++ )
+ for ( seg = i + 1; seg < nr_ranges; seg++ )
{
uint64_t base2 = m->var_ranges[seg].base >> PAGE_SHIFT;
uint64_t mask2 = m->var_ranges[seg].mask >> PAGE_SHIFT;
diff --git a/xen/arch/x86/cpu/mtrr/main.c b/xen/arch/x86/cpu/mtrr/main.c
index eff0500f0d..e49ac1b508 100644
--- a/xen/arch/x86/cpu/mtrr/main.c
+++ b/xen/arch/x86/cpu/mtrr/main.c
@@ -50,9 +50,9 @@
#define get_cpu() smp_processor_id()
#define put_cpu() do {} while(0)
-u32 __read_mostly num_var_ranges = 0;
+unsigned int __read_mostly num_var_ranges = 0;
-unsigned int *__read_mostly usage_table;
+static unsigned int *__read_mostly usage_table;
static DEFINE_MUTEX(mtrr_mutex);
u64 __read_mostly size_or_mask;
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 3/5] x86/cpu: Use U suffixes on integer constants
2026-11-18 17:17 [PATCH 0/5] x86: Add in-scope files under cpu/ to MISRA scans Alejandro Vallejo
2026-11-18 17:17 ` [PATCH 1/5] x86/cpu: Add break to early_cpu_init() switch Alejandro Vallejo
2026-11-18 17:17 ` [PATCH 2/5] x86/mtrr: Address MISRA C Rules 5.3, 8.3 and 8.4 Alejandro Vallejo
@ 2026-11-18 17:17 ` Alejandro Vallejo
2026-11-18 18:49 ` Andrew Cooper
2026-11-18 17:17 ` [PATCH 4/5] x86/amd: Make cpu_has_amd_erratum() non-variadic Alejandro Vallejo
2026-11-18 17:17 ` [PATCH 5/5] eclair/x86: Scan in-scope files inside cpu/ Alejandro Vallejo
4 siblings, 1 reply; 13+ messages in thread
From: Alejandro Vallejo @ 2026-11-18 17:17 UTC (permalink / raw)
To: xen-devel
Cc: Alejandro Vallejo, Jan Beulich, Andrew Cooper,
Roger Pau Monné, Teddy Astie
MISRA C Rule 7.2 requires a 'U' suffix on integer constants of unsigned
type, and Rule 7.3 forbids the lowercase 'l' in literal suffixes.
Add the 'U' suffix to the CPUID leaves, MSR indices and other constants
above INT_MAX in amd.c, centaur.c, common.c and hygon.c, and uppercase
the existing "ul" and "ull" suffixes. While at it, use MSR_K8_PSTATE0
rather than open-coding its value.
No functional change.
Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@amd.com>
---
xen/arch/x86/cpu/amd.c | 48 +++++++++++++++++++-------------------
xen/arch/x86/cpu/centaur.c | 4 ++--
xen/arch/x86/cpu/common.c | 48 +++++++++++++++++++-------------------
xen/arch/x86/cpu/hygon.c | 8 +++----
4 files changed, 54 insertions(+), 54 deletions(-)
diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c
index 21f82990db..fbbba0005c 100644
--- a/xen/arch/x86/cpu/amd.c
+++ b/xen/arch/x86/cpu/amd.c
@@ -58,7 +58,7 @@ static inline int rdmsr_amd_safe(unsigned int msr, unsigned int *lo,
".previous\n"
_ASM_EXTABLE(1b, 3b)
: "=a" (*lo), "=d" (*hi), "=r" (err)
- : "c" (msr), "D" (0x9c5a203a), "2" (0), "i" (-EFAULT) );
+ : "c" (msr), "D" (0x9c5a203aU), "2" (0), "i" (-EFAULT) );
return err;
#endif
@@ -71,7 +71,7 @@ static inline int wrmsr_amd_safe(unsigned int msr, unsigned int lo,
"1: wrmsr\n\t"
_ASM_EXTABLE(1b, %l[fault])
:
- : "c" (msr), "a" (lo), "d" (hi), "D" (0x9c5a203a)
+ : "c" (msr), "a" (lo), "d" (hi), "D" (0x9c5a203aU)
:
: fault );
@@ -85,7 +85,7 @@ static void wrmsr_amd(unsigned int msr, uint64_t val)
{
asm volatile("wrmsr" ::
"c" (msr), "a" ((uint32_t)val),
- "d" (val >> 32), "D" (0x9c5a203a));
+ "d" (val >> 32), "D" (0x9c5a203aU));
}
/*
@@ -263,7 +263,7 @@ static void __init noinline amd_init_levelling(void)
if (levelling_caps & LCAP_e1cd) {
uint32_t ecx, edx, tmp;
- cpuid(0x80000001, &tmp, &tmp, &ecx, &edx);
+ cpuid(0x80000001U, &tmp, &tmp, &ecx, &edx);
/* Fast-forward bits - Must be set. */
edx |= cpufeat_mask(X86_FEATURE_APIC);
@@ -444,7 +444,7 @@ static void amd_get_topology(struct cpuinfo_x86 *c)
* distingush the cores.
*/
cpu = smp_processor_id();
- bits = (cpuid_ecx(0x80000008) >> 12) & 0xf;
+ bits = (cpuid_ecx(0x80000008U) >> 12) & 0xf;
if (bits == 0) {
while ((1 << bits) < c->x86_max_cores)
@@ -459,7 +459,7 @@ static void amd_get_topology(struct cpuinfo_x86 *c)
if (cpu_has(c, X86_FEATURE_TOPOEXT)) {
u32 eax, ebx, ecx, edx;
- cpuid(0x8000001e, &eax, &ebx, &ecx, &edx);
+ cpuid(0x8000001eU, &eax, &ebx, &ecx, &edx);
c->x86_num_siblings = ((ebx >> 8) & 0xff) + 1;
if (c->family < 0x17)
@@ -531,13 +531,13 @@ void amd_process_freq(const struct cpuinfo_x86 *c,
* Make an attempt at determining the node ID, but assume
* symmetric setup (using node 0) if this fails.
*/
- if (c->extended_cpuid_level >= 0x8000001e &&
+ if (c->extended_cpuid_level >= 0x8000001eU &&
cpu_has(c, X86_FEATURE_TOPOEXT)) {
- node = cpuid_ecx(0x8000001e) & 0xff;
+ node = cpuid_ecx(0x8000001eU) & 0xff;
if (node > 7)
node = 0;
} else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) {
- rdmsrl(0xC001100C, val);
+ rdmsrl(0xC001100CU, val);
node = val & 7;
}
@@ -549,14 +549,14 @@ void amd_process_freq(const struct cpuinfo_x86 *c,
wrmsrl(MSR_AMD64_NB_CFG,
nbcfg | (1ULL << AMD64_NB_CFG_CF8_EXT_ENABLE_BIT));
#define PCI_ECS_ADDRESS(sbdf, reg) \
- (0x80000000 | ((sbdf).bdf << 8) | ((reg) & 0xfc) | (((reg) & 0xf00) << 16))
+ (0x80000000U | ((sbdf).bdf << 8) | ((reg) & 0xfc) | (((reg) & 0xf00) << 16))
for ( ; ; ) {
pci_sbdf_t sbdf = PCI_SBDF(0, 0, 0x18 | node, 4);
switch (pci_conf_read32(sbdf, PCI_VENDOR_ID)) {
case 0x00000000:
- case 0xffffffff:
+ case 0xffffffffU:
/* No device at this SBDF. */
if (!node)
break;
@@ -594,21 +594,21 @@ void amd_process_freq(const struct cpuinfo_x86 *c,
lo = 0; /* gcc may not recognize the loop having at least 5 iterations */
for (h = c->family == 0x10 ? 5 : 8; h--; )
- if (!rdmsr_safe(0xC0010064 + h, &lo) && (lo >> 63))
+ if (!rdmsr_safe(MSR_K8_PSTATE0 + h, &lo) && (lo >> 63))
break;
if (!(lo >> 63))
return;
if (idx && idx < h &&
- !rdmsr_safe(0xC0010064 + idx, &val) && (val >> 63) &&
- !rdmsr_safe(0xC0010064, &hi) && (hi >> 63)) {
+ !rdmsr_safe(MSR_K8_PSTATE0 + idx, &val) && (val >> 63) &&
+ !rdmsr_safe(MSR_K8_PSTATE0, &hi) && (hi >> 63)) {
if (nom_mhz)
*nom_mhz = amd_parse_freq(c->family, val);
if (low_mhz)
*low_mhz = amd_parse_freq(c->family, lo);
if (hi_mhz)
*hi_mhz = amd_parse_freq(c->family, hi);
- } else if (h && !rdmsr_safe(0xC0010064, &hi) && (hi >> 63)) {
+ } else if (h && !rdmsr_safe(MSR_K8_PSTATE0, &hi) && (hi >> 63)) {
if (low_mhz)
*low_mhz = amd_parse_freq(c->family, lo);
if (hi_mhz)
@@ -662,7 +662,7 @@ static bool set_legacy_ssbd(const struct cpuinfo_x86 *c, bool enable)
}
if (bit >= 0) {
- uint64_t val, mask = 1ull << bit;
+ uint64_t val, mask = 1ULL << bit;
if (rdmsr_safe(MSR_AMD64_LS_CFG, &val) ||
({
@@ -728,8 +728,8 @@ bool __init amd_setup_legacy_ssbd(void)
* c->cpu_core_id is sparse on all but the top end CPUs. Derive
* max_cpus from ApicIdCoreIdSize which will cover any sparseness.
*/
- if (boot_cpu_data.extended_cpuid_level >= 0x80000008) {
- ssbd_max_cores = 1u << MASK_EXTR(cpuid_ecx(0x80000008), 0xf000);
+ if (boot_cpu_data.extended_cpuid_level >= 0x80000008U) {
+ ssbd_max_cores = 1u << MASK_EXTR(cpuid_ecx(0x80000008U), 0xf000);
ssbd_max_cores /= boot_cpu_data.x86_num_siblings;
}
if (!ssbd_max_cores)
@@ -838,7 +838,7 @@ void __init detect_zen2_null_seg_behaviour(void)
static void cf_check fam17_disable_c6(void *arg)
{
/* Disable C6 by clearing the CCR{0,1,2}_CC6EN bits. */
- const uint64_t mask = ~((1ul << 6) | (1ul << 14) | (1ul << 22));
+ const uint64_t mask = ~((1UL << 6) | (1UL << 14) | (1UL << 22));
uint64_t val;
if (!fam17_c6_disabled) {
@@ -1095,8 +1095,8 @@ static void cf_check init_amd(struct cpuinfo_x86 *c)
* (AMD Erratum #110, docId: 25759).
*/
__clear_bit(X86_FEATURE_LAHF_LM, c->x86_capability);
- if (!rdmsr_amd_safe(0xc001100d, &l, &h))
- wrmsr_amd_safe(0xc001100d, l, h & ~1);
+ if (!rdmsr_amd_safe(0xc001100dU, &l, &h))
+ wrmsr_amd_safe(0xc001100dU, l, h & ~1);
}
/*
@@ -1180,11 +1180,11 @@ static void cf_check init_amd(struct cpuinfo_x86 *c)
display_cacheinfo(c);
- if (c->extended_cpuid_level >= 0x80000008) {
- c->x86_max_cores = (cpuid_ecx(0x80000008) & 0xff) + 1;
+ if (c->extended_cpuid_level >= 0x80000008U) {
+ c->x86_max_cores = (cpuid_ecx(0x80000008U) & 0xff) + 1;
}
- if (c->extended_cpuid_level >= 0x80000007) {
+ if (c->extended_cpuid_level >= 0x80000007U) {
if (cpu_has(c, X86_FEATURE_ITSC)) {
__set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);
__set_bit(X86_FEATURE_NONSTOP_TSC, c->x86_capability);
diff --git a/xen/arch/x86/cpu/centaur.c b/xen/arch/x86/cpu/centaur.c
index 9123b05dc1..1e756d6c36 100644
--- a/xen/arch/x86/cpu/centaur.c
+++ b/xen/arch/x86/cpu/centaur.c
@@ -21,8 +21,8 @@ static void init_c3(struct cpuinfo_x86 *c)
uint64_t msr_content;
/* Test for Centaur Extended Feature Flags presence */
- if (cpuid_eax(0xC0000000) >= 0xC0000001) {
- u32 tmp = cpuid_edx(0xC0000001);
+ if (cpuid_eax(0xC0000000U) >= 0xC0000001U) {
+ u32 tmp = cpuid_edx(0xC0000001U);
/* enable ACE unit, if present and disabled */
if ((tmp & (ACE_PRESENT | ACE_ENABLED)) == ACE_PRESENT) {
diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c
index 54e3a02dd1..78f26105c5 100644
--- a/xen/arch/x86/cpu/common.c
+++ b/xen/arch/x86/cpu/common.c
@@ -226,13 +226,13 @@ int get_model_name(struct cpuinfo_x86 *c)
unsigned int *v;
char *p, *q;
- if (c->extended_cpuid_level < 0x80000004)
+ if (c->extended_cpuid_level < 0x80000004U)
return 0;
v = (unsigned int *) c->x86_model_id;
- cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
- cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
- cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
+ cpuid(0x80000002U, &v[0], &v[1], &v[2], &v[3]);
+ cpuid(0x80000003U, &v[4], &v[5], &v[6], &v[7]);
+ cpuid(0x80000004U, &v[8], &v[9], &v[10], &v[11]);
c->x86_model_id[48] = 0;
/* Intel chips right-justify this string for some dumb reason;
@@ -255,8 +255,8 @@ void display_cacheinfo(struct cpuinfo_x86 *c)
{
unsigned int dummy, ecx, edx, size;
- if (c->extended_cpuid_level >= 0x80000005) {
- cpuid(0x80000005, &dummy, &dummy, &ecx, &edx);
+ if (c->extended_cpuid_level >= 0x80000005U) {
+ cpuid(0x80000005U, &dummy, &dummy, &ecx, &edx);
if ((edx | ecx) >> 24) {
if (opt_cpu_info)
printk("CPU: L1 I cache %uK (%u bytes/line),"
@@ -266,10 +266,10 @@ void display_cacheinfo(struct cpuinfo_x86 *c)
}
}
- if (c->extended_cpuid_level < 0x80000006) /* Some chips just has a large L1. */
+ if (c->extended_cpuid_level < 0x80000006U) /* Some chips just has a large L1. */
return;
- cpuid(0x80000006, &dummy, &dummy, &ecx, &edx);
+ cpuid(0x80000006U, &dummy, &dummy, &ecx, &edx);
size = ecx >> 16;
if (size) {
@@ -413,10 +413,10 @@ void __init early_cpu_init(bool verbose)
&c->x86_capability[FEATURESET_7d1]);
}
- eax = cpuid_eax(0x80000000);
- if ((eax >> 16) == 0x8000 && eax >= 0x80000008) {
- ebx = eax >= 0x8000001f ? cpuid_ebx(0x8000001f) : 0;
- eax = cpuid_eax(0x80000008);
+ eax = cpuid_eax(0x80000000U);
+ if ((eax >> 16) == 0x8000 && eax >= 0x80000008U) {
+ ebx = eax >= 0x8000001fU ? cpuid_ebx(0x8000001fU) : 0;
+ eax = cpuid_eax(0x80000008U);
paddr_bits = eax & 0xff;
if (paddr_bits > PADDR_BITS)
@@ -530,7 +530,7 @@ void identify_cpu(struct cpuinfo_x86 *c)
c->x86_capability[FEATURESET_1c] = ecx;
c->x86_capability[FEATURESET_1d] = edx;
- eax = cpuid_eax(0x80000000);
+ eax = cpuid_eax(0x80000000U);
if ((eax >> 16) == 0x8000)
c->extended_cpuid_level = eax;
@@ -538,8 +538,8 @@ void identify_cpu(struct cpuinfo_x86 *c)
* These AMD-defined flags are out of place, but we need
* them early for the CPUID faulting probe code
*/
- if (c->extended_cpuid_level >= 0x80000021)
- c->x86_capability[FEATURESET_e21a] = cpuid_eax(0x80000021);
+ if (c->extended_cpuid_level >= 0x80000021U)
+ c->x86_capability[FEATURESET_e21a] = cpuid_eax(0x80000021U);
if (actual_cpu.c_early_init)
alternative_vcall(actual_cpu.c_early_init, c);
@@ -554,19 +554,19 @@ void identify_cpu(struct cpuinfo_x86 *c)
c->x86_clflush_size = ((ebx >> 8) & 0xff) * 8;
/* AMD-defined flags: level 0x80000001 */
- if (c->extended_cpuid_level >= 0x80000001)
- cpuid(0x80000001, &tmp, &tmp,
+ if (c->extended_cpuid_level >= 0x80000001U)
+ cpuid(0x80000001U, &tmp, &tmp,
&c->x86_capability[FEATURESET_e1c],
&c->x86_capability[FEATURESET_e1d]);
- if (c->extended_cpuid_level >= 0x80000004)
+ if (c->extended_cpuid_level >= 0x80000004U)
get_model_name(c); /* Default name */
- if (c->extended_cpuid_level >= 0x80000007)
- c->x86_capability[FEATURESET_e7d] = cpuid_edx(0x80000007);
- if (c->extended_cpuid_level >= 0x80000008)
- c->x86_capability[FEATURESET_e8b] = cpuid_ebx(0x80000008);
- if (c->extended_cpuid_level >= 0x80000021)
- cpuid(0x80000021,
+ if (c->extended_cpuid_level >= 0x80000007U)
+ c->x86_capability[FEATURESET_e7d] = cpuid_edx(0x80000007U);
+ if (c->extended_cpuid_level >= 0x80000008U)
+ c->x86_capability[FEATURESET_e8b] = cpuid_ebx(0x80000008U);
+ if (c->extended_cpuid_level >= 0x80000021U)
+ cpuid(0x80000021U,
&c->x86_capability[FEATURESET_e21a], &tmp,
&c->x86_capability[FEATURESET_e21c], &tmp);
diff --git a/xen/arch/x86/cpu/hygon.c b/xen/arch/x86/cpu/hygon.c
index ef19c2b367..1f88275ce2 100644
--- a/xen/arch/x86/cpu/hygon.c
+++ b/xen/arch/x86/cpu/hygon.c
@@ -17,7 +17,7 @@ static void hygon_get_topology(struct cpuinfo_x86 *c)
/* Socket ID is ApicId[6] for Hygon processors. */
c->phys_proc_id >>= APICID_SOCKET_ID_BIT;
- ebx = cpuid_ebx(0x8000001e);
+ ebx = cpuid_ebx(0x8000001eU);
c->x86_num_siblings = ((ebx >> 8) & 0x3) + 1;
c->x86_max_cores /= c->x86_num_siblings;
c->cpu_core_id = ebx & 0xff;
@@ -66,10 +66,10 @@ static void cf_check init_hygon(struct cpuinfo_x86 *c)
display_cacheinfo(c);
- if (c->extended_cpuid_level >= 0x80000008)
- c->x86_max_cores = (cpuid_ecx(0x80000008) & 0xff) + 1;
+ if (c->extended_cpuid_level >= 0x80000008U)
+ c->x86_max_cores = (cpuid_ecx(0x80000008U) & 0xff) + 1;
- if (c->extended_cpuid_level >= 0x80000007) {
+ if (c->extended_cpuid_level >= 0x80000007U) {
if (cpu_has(c, X86_FEATURE_ITSC)) {
__set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);
__set_bit(X86_FEATURE_NONSTOP_TSC, c->x86_capability);
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 4/5] x86/amd: Make cpu_has_amd_erratum() non-variadic
2026-11-18 17:17 [PATCH 0/5] x86: Add in-scope files under cpu/ to MISRA scans Alejandro Vallejo
` (2 preceding siblings ...)
2026-11-18 17:17 ` [PATCH 3/5] x86/cpu: Use U suffixes on integer constants Alejandro Vallejo
@ 2026-11-18 17:17 ` Alejandro Vallejo
2026-11-18 19:06 ` Andrew Cooper
2026-11-18 17:17 ` [PATCH 5/5] eclair/x86: Scan in-scope files inside cpu/ Alejandro Vallejo
4 siblings, 1 reply; 13+ messages in thread
From: Alejandro Vallejo @ 2026-11-18 17:17 UTC (permalink / raw)
To: xen-devel
Cc: Alejandro Vallejo, Jan Beulich, Andrew Cooper,
Roger Pau Monné, Teddy Astie
cpu_has_amd_erratum() takes the OSVW id and the family-model-stepping
ranges of an erratum as variadic arguments, which MISRA C Rule 17.1
forbids.
Have AMD_LEGACY_ERRATUM() and AMD_OSVW_ERRATUM() expand to a
zero-terminated array instead, and have cpu_has_amd_erratum() walk it.
Callers pass the AMD_ERRATUM_* macros, so they are unaffected.
No functional change.
Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@amd.com>
---
xen/arch/x86/cpu/amd.c | 14 ++++++--------
xen/arch/x86/include/asm/amd.h | 11 +++++++----
2 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c
index fbbba0005c..5e22fff81c 100644
--- a/xen/arch/x86/cpu/amd.c
+++ b/xen/arch/x86/cpu/amd.c
@@ -321,10 +321,10 @@ 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, const int *erratum)
{
- va_list ap;
- u32 range;
+ int osvw_id = erratum[0];
+ const int *p;
u32 ms;
if (cpu->vendor != X86_VENDOR_AMD)
@@ -346,19 +346,17 @@ int cpu_has_amd_erratum(const struct cpuinfo_x86 *cpu, int osvw_id, ...)
}
/* OSVW unavailable or ID unknown, match family-model-stepping range */
- va_start(ap, osvw_id);
-
ms = (cpu->model << 4) | cpu->stepping;
- while ((range = va_arg(ap, int))) {
+ for (p = &erratum[1]; *p; p++) {
+ u32 range = *p;
+
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;
}
diff --git a/xen/arch/x86/include/asm/amd.h b/xen/arch/x86/include/asm/amd.h
index d21df0741a..d897943210 100644
--- a/xen/arch/x86/include/asm/amd.h
+++ b/xen/arch/x86/include/asm/amd.h
@@ -12,7 +12,8 @@
* 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().
+ * of family-specific model-stepping ranges created by AMD_MODEL_RANGE(),
+ * and yield a zero-terminated array to pass to cpu_has_amd_erratum().
*
* Example 1:
* #define AMD_ERRATUM_319 \
@@ -26,8 +27,10 @@
*
*/
-#define AMD_LEGACY_ERRATUM(...) -1 /* legacy */, __VA_ARGS__, 0
-#define AMD_OSVW_ERRATUM(osvw_id, ...) osvw_id, __VA_ARGS__, 0
+#define AMD_LEGACY_ERRATUM(...) \
+ ((const int[]){ -1 /* legacy */, __VA_ARGS__, 0 })
+#define AMD_OSVW_ERRATUM(osvw_id, ...) \
+ ((const int[]){ osvw_id, __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))
@@ -72,7 +75,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, const int *erratum);
extern int8_t opt_allow_unsafe;
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 5/5] eclair/x86: Scan in-scope files inside cpu/
2026-11-18 17:17 [PATCH 0/5] x86: Add in-scope files under cpu/ to MISRA scans Alejandro Vallejo
` (3 preceding siblings ...)
2026-11-18 17:17 ` [PATCH 4/5] x86/amd: Make cpu_has_amd_erratum() non-variadic Alejandro Vallejo
@ 2026-11-18 17:17 ` Alejandro Vallejo
2026-11-18 17:32 ` Nicola Vetrini
4 siblings, 1 reply; 13+ messages in thread
From: Alejandro Vallejo @ 2026-11-18 17:17 UTC (permalink / raw)
To: xen-devel
Cc: Alejandro Vallejo, Nicola Vetrini, Doug Goldstein,
Stefano Stabellini, Andrew Cooper, Anthony PERARD, Michal Orzel,
Jan Beulich, Julien Grall, Roger Pau Monné
Remove the exclusions now that all in-scope files inside are clean on
the regression subset.
Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@amd.com>
---
.../eclair_analysis/ECLAIR/deviations.ecl | 3 --
docs/misra/exclude-list.json | 36 -------------------
2 files changed, 39 deletions(-)
diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl b/automation/eclair_analysis/ECLAIR/deviations.ecl
index d49af53055..9fcba4df16 100644
--- a/automation/eclair_analysis/ECLAIR/deviations.ecl
+++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
@@ -186,9 +186,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
diff --git a/docs/misra/exclude-list.json b/docs/misra/exclude-list.json
index 2b874dfd3b..a52f0d6429 100644
--- a/docs/misra/exclude-list.json
+++ b/docs/misra/exclude-list.json
@@ -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"
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH 5/5] eclair/x86: Scan in-scope files inside cpu/
2026-11-18 17:17 ` [PATCH 5/5] eclair/x86: Scan in-scope files inside cpu/ Alejandro Vallejo
@ 2026-11-18 17:32 ` Nicola Vetrini
0 siblings, 0 replies; 13+ messages in thread
From: Nicola Vetrini @ 2026-11-18 17:32 UTC (permalink / raw)
To: Alejandro Vallejo
Cc: xen-devel, Doug Goldstein, Stefano Stabellini, Andrew Cooper,
Anthony PERARD, Michal Orzel, Jan Beulich, Julien Grall,
Roger Pau Monné
On 2026-11-18 18:17, Alejandro Vallejo wrote:
> Remove the exclusions now that all in-scope files inside are clean on
> the regression subset.
>
> Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@amd.com>
Acked-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Thanks for taking care of this. I think further cleanup can be done,
looking at the output of
git grep out_of_scope
but probably it's better in a follow-up patch
> ---
> .../eclair_analysis/ECLAIR/deviations.ecl | 3 --
> docs/misra/exclude-list.json | 36 -------------------
> 2 files changed, 39 deletions(-)
>
> diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl
> b/automation/eclair_analysis/ECLAIR/deviations.ecl
> index d49af53055..9fcba4df16 100644
> --- a/automation/eclair_analysis/ECLAIR/deviations.ecl
> +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
> @@ -186,9 +186,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
>
> diff --git a/docs/misra/exclude-list.json
> b/docs/misra/exclude-list.json
> index 2b874dfd3b..a52f0d6429 100644
> --- a/docs/misra/exclude-list.json
> +++ b/docs/misra/exclude-list.json
> @@ -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"
--
Nicola Vetrini, B.Sc.
Software Engineer
BUGSENG (https://bugseng.com)
LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/5] x86/cpu: Add break to early_cpu_init() switch
2026-11-18 17:17 ` [PATCH 1/5] x86/cpu: Add break to early_cpu_init() switch Alejandro Vallejo
@ 2026-11-18 18:45 ` Andrew Cooper
0 siblings, 0 replies; 13+ messages in thread
From: Andrew Cooper @ 2026-11-18 18:45 UTC (permalink / raw)
To: Alejandro Vallejo, xen-devel
Cc: Andrew Cooper, Jan Beulich, Roger Pau Monné, Teddy Astie
On 18/11/2026 5:17 pm, Alejandro Vallejo wrote:
> MISRA C Rule 16.3 requires every switch clause to be terminated by an
> unconditional break statement.
>
> No functional change.
>
> Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@amd.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 2/5] x86/mtrr: Address MISRA C Rules 5.3, 8.3 and 8.4
2026-11-18 17:17 ` [PATCH 2/5] x86/mtrr: Address MISRA C Rules 5.3, 8.3 and 8.4 Alejandro Vallejo
@ 2026-11-18 18:46 ` Andrew Cooper
0 siblings, 0 replies; 13+ messages in thread
From: Andrew Cooper @ 2026-11-18 18:46 UTC (permalink / raw)
To: Alejandro Vallejo, xen-devel
Cc: Andrew Cooper, Jan Beulich, Roger Pau Monné, Teddy Astie
On 18/11/2026 5:17 pm, Alejandro Vallejo wrote:
> diff --git a/xen/arch/x86/cpu/mtrr/main.c b/xen/arch/x86/cpu/mtrr/main.c
> index eff0500f0d..e49ac1b508 100644
> --- a/xen/arch/x86/cpu/mtrr/main.c
> +++ b/xen/arch/x86/cpu/mtrr/main.c
> @@ -50,9 +50,9 @@
> #define get_cpu() smp_processor_id()
> #define put_cpu() do {} while(0)
>
> -u32 __read_mostly num_var_ranges = 0;
> +unsigned int __read_mostly num_var_ranges = 0;
As you're editing the line anyway, the = 0 can be dropped. Can be fixed
on commit.
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 3/5] x86/cpu: Use U suffixes on integer constants
2026-11-18 17:17 ` [PATCH 3/5] x86/cpu: Use U suffixes on integer constants Alejandro Vallejo
@ 2026-11-18 18:49 ` Andrew Cooper
2026-11-19 7:51 ` Jan Beulich
0 siblings, 1 reply; 13+ messages in thread
From: Andrew Cooper @ 2026-11-18 18:49 UTC (permalink / raw)
To: Alejandro Vallejo, xen-devel
Cc: Andrew Cooper, Jan Beulich, Roger Pau Monné, Teddy Astie
On 18/11/2026 5:17 pm, Alejandro Vallejo wrote:
> diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c
> index 21f82990db..fbbba0005c 100644
> --- a/xen/arch/x86/cpu/amd.c
> +++ b/xen/arch/x86/cpu/amd.c
> @@ -728,8 +728,8 @@ bool __init amd_setup_legacy_ssbd(void)
> * c->cpu_core_id is sparse on all but the top end CPUs. Derive
> * max_cpus from ApicIdCoreIdSize which will cover any sparseness.
> */
> - if (boot_cpu_data.extended_cpuid_level >= 0x80000008) {
> - ssbd_max_cores = 1u << MASK_EXTR(cpuid_ecx(0x80000008), 0xf000);
> + if (boot_cpu_data.extended_cpuid_level >= 0x80000008U) {
> + ssbd_max_cores = 1u << MASK_EXTR(cpuid_ecx(0x80000008U), 0xf000);
1U.
I guess the case of u/U isn't blocking in Eclair?
Can be fixed on commit, if this is the only example.
~Andrew
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 4/5] x86/amd: Make cpu_has_amd_erratum() non-variadic
2026-11-18 17:17 ` [PATCH 4/5] x86/amd: Make cpu_has_amd_erratum() non-variadic Alejandro Vallejo
@ 2026-11-18 19:06 ` Andrew Cooper
2026-11-19 10:41 ` Alejandro Vallejo
0 siblings, 1 reply; 13+ messages in thread
From: Andrew Cooper @ 2026-11-18 19:06 UTC (permalink / raw)
To: Alejandro Vallejo, xen-devel
Cc: Andrew Cooper, Jan Beulich, Roger Pau Monné, Teddy Astie
On 18/11/2026 5:17 pm, Alejandro Vallejo wrote:
> cpu_has_amd_erratum() takes the OSVW id and the family-model-stepping
> ranges of an erratum as variadic arguments, which MISRA C Rule 17.1
> forbids.
>
> Have AMD_LEGACY_ERRATUM() and AMD_OSVW_ERRATUM() expand to a
> zero-terminated array instead, and have cpu_has_amd_erratum() walk it.
> Callers pass the AMD_ERRATUM_* macros, so they are unaffected.
>
> No functional change.
>
> Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@amd.com>
> ---
> xen/arch/x86/cpu/amd.c | 14 ++++++--------
> xen/arch/x86/include/asm/amd.h | 11 +++++++----
> 2 files changed, 13 insertions(+), 12 deletions(-)
>
> diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c
> index fbbba0005c..5e22fff81c 100644
> --- a/xen/arch/x86/cpu/amd.c
> +++ b/xen/arch/x86/cpu/amd.c
> @@ -321,10 +321,10 @@ 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, const int *erratum)
> {
> - va_list ap;
> - u32 range;
> + int osvw_id = erratum[0];
> + const int *p;
> u32 ms;
>
> if (cpu->vendor != X86_VENDOR_AMD)
> @@ -346,19 +346,17 @@ int cpu_has_amd_erratum(const struct cpuinfo_x86 *cpu, int osvw_id, ...)
> }
>
> /* OSVW unavailable or ID unknown, match family-model-stepping range */
> - va_start(ap, osvw_id);
> -
> ms = (cpu->model << 4) | cpu->stepping;
> - while ((range = va_arg(ap, int))) {
> + for (p = &erratum[1]; *p; p++) {
> + u32 range = *p;
> +
> 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;
> }
>
> diff --git a/xen/arch/x86/include/asm/amd.h b/xen/arch/x86/include/asm/amd.h
> index d21df0741a..d897943210 100644
> --- a/xen/arch/x86/include/asm/amd.h
> +++ b/xen/arch/x86/include/asm/amd.h
> @@ -12,7 +12,8 @@
> * 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().
> + * of family-specific model-stepping ranges created by AMD_MODEL_RANGE(),
> + * and yield a zero-terminated array to pass to cpu_has_amd_erratum().
> *
> * Example 1:
> * #define AMD_ERRATUM_319 \
> @@ -26,8 +27,10 @@
> *
> */
>
> -#define AMD_LEGACY_ERRATUM(...) -1 /* legacy */, __VA_ARGS__, 0
> -#define AMD_OSVW_ERRATUM(osvw_id, ...) osvw_id, __VA_ARGS__, 0
> +#define AMD_LEGACY_ERRATUM(...) \
> + ((const int[]){ -1 /* legacy */, __VA_ARGS__, 0 })
> +#define AMD_OSVW_ERRATUM(osvw_id, ...) \
> + ((const int[]){ osvw_id, __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))
> @@ -72,7 +75,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, const int *erratum);
>
> extern int8_t opt_allow_unsafe;
>
This whole infrastructure is garbage. I believe Linux dropped it a long
time back.
If you see, we only ever encode LEGACY errata with it, meaning the
osvw_id is always -1, meaning the OSVW MSR accesses is
cpu_has_amd_erratum() are truly unreachable even in safety builds.
Next, have you seen what a disaster of code generation this actually
causes at callers? It's an anonymous array on the stack, which means
it's (re)initialised every time it's called. One of these is even in
domain_create().
OSVW was a short-sighted and now abandoned idea of AMDs. There are
something like 4(?) bits defined, but there's no index of what they are
so you have to search all the revision guides to find them.
Could I at least talk you into dropping the osvw_id part? Xen does
nothing with OSVW at all, and if we ever feel the need to gain some use,
it will not be like this.
But, if you were to see about moving the arrays out to being static
objects too, I think the result would be a whole lot less unpalatable.
~Andrew
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 3/5] x86/cpu: Use U suffixes on integer constants
2026-11-18 18:49 ` Andrew Cooper
@ 2026-11-19 7:51 ` Jan Beulich
0 siblings, 0 replies; 13+ messages in thread
From: Jan Beulich @ 2026-11-19 7:51 UTC (permalink / raw)
To: Andrew Cooper
Cc: Roger Pau Monné, Teddy Astie, Alejandro Vallejo, xen-devel
On 18.11.2026 19:49, Andrew Cooper wrote:
> On 18/11/2026 5:17 pm, Alejandro Vallejo wrote:
>> diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c
>> index 21f82990db..fbbba0005c 100644
>> --- a/xen/arch/x86/cpu/amd.c
>> +++ b/xen/arch/x86/cpu/amd.c
>> @@ -728,8 +728,8 @@ bool __init amd_setup_legacy_ssbd(void)
>> * c->cpu_core_id is sparse on all but the top end CPUs. Derive
>> * max_cpus from ApicIdCoreIdSize which will cover any sparseness.
>> */
>> - if (boot_cpu_data.extended_cpuid_level >= 0x80000008) {
>> - ssbd_max_cores = 1u << MASK_EXTR(cpuid_ecx(0x80000008), 0xf000);
>> + if (boot_cpu_data.extended_cpuid_level >= 0x80000008U) {
>> + ssbd_max_cores = 1u << MASK_EXTR(cpuid_ecx(0x80000008U), 0xf000);
>
> 1U.
>
> I guess the case of u/U isn't blocking in Eclair?
Iirc Misra only objects to l, not u. Us also wanting U (alongside L) is
therefore purely a style decision.
Jan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 4/5] x86/amd: Make cpu_has_amd_erratum() non-variadic
2026-11-18 19:06 ` Andrew Cooper
@ 2026-11-19 10:41 ` Alejandro Vallejo
0 siblings, 0 replies; 13+ messages in thread
From: Alejandro Vallejo @ 2026-11-19 10:41 UTC (permalink / raw)
To: Andrew Cooper, xen-devel; +Cc: Jan Beulich, Roger Pau Monné, Teddy Astie
On Wed Nov 18, 2026 at 8:06 PM CET, Andrew Cooper wrote:
> On 18/11/2026 5:17 pm, Alejandro Vallejo wrote:
> > cpu_has_amd_erratum() takes the OSVW id and the family-model-stepping
> > ranges of an erratum as variadic arguments, which MISRA C Rule 17.1
> > forbids.
> >
> > Have AMD_LEGACY_ERRATUM() and AMD_OSVW_ERRATUM() expand to a
> > zero-terminated array instead, and have cpu_has_amd_erratum() walk it.
> > Callers pass the AMD_ERRATUM_* macros, so they are unaffected.
> >
> > No functional change.
> >
> > Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@amd.com>
> > ---
> > xen/arch/x86/cpu/amd.c | 14 ++++++--------
> > xen/arch/x86/include/asm/amd.h | 11 +++++++----
> > 2 files changed, 13 insertions(+), 12 deletions(-)
> >
> > diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c
> > index fbbba0005c..5e22fff81c 100644
> > --- a/xen/arch/x86/cpu/amd.c
> > +++ b/xen/arch/x86/cpu/amd.c
> > @@ -321,10 +321,10 @@ 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, const int *erratum)
> > {
> > - va_list ap;
> > - u32 range;
> > + int osvw_id = erratum[0];
> > + const int *p;
> > u32 ms;
> >
> > if (cpu->vendor != X86_VENDOR_AMD)
> > @@ -346,19 +346,17 @@ int cpu_has_amd_erratum(const struct cpuinfo_x86 *cpu, int osvw_id, ...)
> > }
> >
> > /* OSVW unavailable or ID unknown, match family-model-stepping range */
> > - va_start(ap, osvw_id);
> > -
> > ms = (cpu->model << 4) | cpu->stepping;
> > - while ((range = va_arg(ap, int))) {
> > + for (p = &erratum[1]; *p; p++) {
> > + u32 range = *p;
> > +
> > 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;
> > }
> >
> > diff --git a/xen/arch/x86/include/asm/amd.h b/xen/arch/x86/include/asm/amd.h
> > index d21df0741a..d897943210 100644
> > --- a/xen/arch/x86/include/asm/amd.h
> > +++ b/xen/arch/x86/include/asm/amd.h
> > @@ -12,7 +12,8 @@
> > * 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().
> > + * of family-specific model-stepping ranges created by AMD_MODEL_RANGE(),
> > + * and yield a zero-terminated array to pass to cpu_has_amd_erratum().
> > *
> > * Example 1:
> > * #define AMD_ERRATUM_319 \
> > @@ -26,8 +27,10 @@
> > *
> > */
> >
> > -#define AMD_LEGACY_ERRATUM(...) -1 /* legacy */, __VA_ARGS__, 0
> > -#define AMD_OSVW_ERRATUM(osvw_id, ...) osvw_id, __VA_ARGS__, 0
> > +#define AMD_LEGACY_ERRATUM(...) \
> > + ((const int[]){ -1 /* legacy */, __VA_ARGS__, 0 })
> > +#define AMD_OSVW_ERRATUM(osvw_id, ...) \
> > + ((const int[]){ osvw_id, __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))
> > @@ -72,7 +75,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, const int *erratum);
> >
> > extern int8_t opt_allow_unsafe;
> >
>
> This whole infrastructure is garbage. I believe Linux dropped it a long
> time back.
I agree. I can only describe it as an overcomplicated mess.
>
> If you see, we only ever encode LEGACY errata with it, meaning the
> osvw_id is always -1, meaning the OSVW MSR accesses is
> cpu_has_amd_erratum() are truly unreachable even in safety builds.
errata 383 (out of context) matches on OSVW before attempting the
fam/model match.
>
> Next, have you seen what a disaster of code generation this actually
> causes at callers? It's an anonymous array on the stack, which means
> it's (re)initialised every time it's called. One of these is even in
> domain_create().
Not to say any of this is GOOD. But it is very definitely not worse.
A variadic function is... pretty much that. They are largely equivalent.
Debug builds are slightly bigger with the anonymous arrays due to
optimisation quirks, but release builds are slightly smaller (See
bloat-o-meter):
add/remove: 0/0 grow/shrink: 4/2 up/down: 61/-113 (-52)
Function old new delta
svm_asid_init 39 60 +21
init_amd 2419 2435 +16
arch_domain_create 1043 1059 +16
_svm_cpu_up 444 452 +8
x86emul_fpu 7369 7321 -48
cpu_has_amd_erratum 260 195 -65
Total: Before=3607126, After=3607074, chg -0.00%
>
> OSVW was a short-sighted and now abandoned idea of AMDs. There are
> something like 4(?) bits defined, but there's no index of what they are
> so you have to search all the revision guides to find them.
>
> Could I at least talk you into dropping the osvw_id part? Xen does
> nothing with OSVW at all, and if we ever feel the need to gain some use,
> it will not be like this.
>
> But, if you were to see about moving the arrays out to being static
> objects too, I think the result would be a whole lot less unpalatable.
I don't mind refactoring this mess a bit more. I may try removing the
arrays altogether and integrating them into the function itself.
Note cpu_has_amd_erratum() does perform the OSVW lookup for errata 383.
Did you _really_ mean to drop that? It's not immediately obvious to me
whether the fam/models listed cover everything OSVW does.
Cheers,
Alejandro
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2026-11-19 10:41 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 17:17 [PATCH 0/5] x86: Add in-scope files under cpu/ to MISRA scans Alejandro Vallejo
2026-11-18 17:17 ` [PATCH 1/5] x86/cpu: Add break to early_cpu_init() switch Alejandro Vallejo
2026-11-18 18:45 ` Andrew Cooper
2026-11-18 17:17 ` [PATCH 2/5] x86/mtrr: Address MISRA C Rules 5.3, 8.3 and 8.4 Alejandro Vallejo
2026-11-18 18:46 ` Andrew Cooper
2026-11-18 17:17 ` [PATCH 3/5] x86/cpu: Use U suffixes on integer constants Alejandro Vallejo
2026-11-18 18:49 ` Andrew Cooper
2026-11-19 7:51 ` Jan Beulich
2026-11-18 17:17 ` [PATCH 4/5] x86/amd: Make cpu_has_amd_erratum() non-variadic Alejandro Vallejo
2026-11-18 19:06 ` Andrew Cooper
2026-11-19 10:41 ` Alejandro Vallejo
2026-11-18 17:17 ` [PATCH 5/5] eclair/x86: Scan in-scope files inside cpu/ Alejandro Vallejo
2026-11-18 17:32 ` Nicola Vetrini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.