Re: [PATCH v1 1/3] x86/mce: Add centaur vendor to support Zhaoxin MCA
From: Dave Hansen
Date: Fri Sep 13 2024 - 11:48:25 EST
On 9/13/24 07:27, Borislav Petkov wrote:
>> + if (c->x86_vendor == X86_VENDOR_CENTAUR) {
>> + /*
>> + * All newer Centaur CPUs support MCE broadcasting. Enable
>> + * synchronization with a one second timeout.
>> + */
>> + if ((c->x86 == 6 && c->x86_model == 0xf && c->x86_stepping >= 0xe) ||
>> + c->x86 > 6) {
>> + if (cfg->monarch_timeout < 0)
>> + cfg->monarch_timeout = USEC_PER_SEC;
>> + }
>> + }
> So if centaur == zhaoxin, why aren't you moving this hunk to
> mce_zhaoxin_feature_init() instead?
The centaur and zhaoxin logic is also _really_ close here:
> if (c->x86 > 6 || (c->x86_model == 0x19 || c->x86_model == 0x1f)) {
> if (cfg->monarch_timeout < 0)
> cfg->monarch_timeout = USEC_PER_SEC;
> }
vs
> if ((c->x86 == 6 && c->x86_model == 0xf && c->x86_stepping >= 0xe) ||
> c->x86 > 6) {
> if (cfg->monarch_timeout < 0)
> cfg->monarch_timeout = USEC_PER_SEC;
> }
I'd just randomly guess that the zhaoxin version is buggy because it
doesn't do a c->x86 check before the "(c->x86_model == 0x19 ||
c->x86_model == 0x1f)".
So instead of copying and pasting the same block over and over, can we
consolidate it a bit?
foo()
{
/* Older CPUs do not do MCE broadcast: */
if (c->x86 < 6)
return;
/* All newer ones do: */
if (c->x86 > 6)
goto mce_broadcast;
/* Family 6 is mixed: */
if (c->x86_vendor == X86_VENDOR_CENTAUR) {
if (c->x86_model == 0xf &&
c->x86_stepping >= 0xe)
goto mce_broadcast;
} else if (c->x86_vendor == X86_VENDOR_ZHAOXIN) {
if (c->x86_model == 0x19 ||
c->x86_model == 0x1f))
goto mce_broadcast;
}
return;
mce_broadcast:
if (cfg->monarch_timeout < 0)
cfg->monarch_timeout = USEC_PER_SEC;
}
Heck, the Intel code can even go in there I think. Wouldn't that tell
the story a bit better?