Skip to content

Commit 134b1ea

Browse files
yghannambp3tk0v
authored andcommitted
x86/mce/amd: Enable interrupt vectors once per-CPU on SMCA systems
Scalable MCA systems have a per-CPU register that gives the APIC LVT offset for the thresholding and deferred error interrupts. Currently, this register is read once to set up the deferred error interrupt and then read again for each thresholding block. Furthermore, the APIC LVT registers are configured each time, but they only need to be configured once per-CPU. Move the APIC LVT setup to the early part of CPU init, so that the registers are set up once. Also, this ensures that the kernel is ready to service the interrupts before the individual error sources (each MCA bank) are enabled. Apply this change only to SMCA systems to avoid breaking any legacy behavior. The deferred error interrupt is technically advertised by the SUCCOR feature. However, this was first made available on SMCA systems. Therefore, only set up the deferred error interrupt on SMCA systems and simplify the code. Guidance from hardware designers is that the LVT offsets provided from the platform should be used. The kernel should not try to enforce specific values. However, the kernel should check that an LVT offset is not reused for multiple sources. Therefore, remove the extra checking and value enforcement from the MCE code. The "reuse/conflict" case is already handled in setup_APIC_eilvt(). Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Tony Luck <tony.luck@intel.com> Tested-by: Tony Luck <tony.luck@intel.com> Link: https://lore.kernel.org/20251104-wip-mca-updates-v8-0-66c8eacf67b9@amd.com
1 parent 7cb735d commit 134b1ea

1 file changed

Lines changed: 53 additions & 68 deletions

File tree

  • arch/x86/kernel/cpu/mce

arch/x86/kernel/cpu/mce/amd.c

Lines changed: 53 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@
4343
/* Deferred error settings */
4444
#define MSR_CU_DEF_ERR 0xC0000410
4545
#define MASK_DEF_LVTOFF 0x000000F0
46-
#define MASK_DEF_INT_TYPE 0x00000006
47-
#define DEF_LVT_OFF 0x2
48-
#define DEF_INT_TYPE_APIC 0x2
4946

5047
/* Scalable MCA: */
5148

@@ -57,6 +54,10 @@ static bool thresholding_irq_en;
5754
struct mce_amd_cpu_data {
5855
mce_banks_t thr_intr_banks;
5956
mce_banks_t dfr_intr_banks;
57+
58+
u32 thr_intr_en: 1,
59+
dfr_intr_en: 1,
60+
__resv: 30;
6061
};
6162

6263
static DEFINE_PER_CPU_READ_MOSTLY(struct mce_amd_cpu_data, mce_amd_data);
@@ -271,6 +272,7 @@ void (*deferred_error_int_vector)(void) = default_deferred_error_interrupt;
271272

272273
static void smca_configure(unsigned int bank, unsigned int cpu)
273274
{
275+
struct mce_amd_cpu_data *data = this_cpu_ptr(&mce_amd_data);
274276
u8 *bank_counts = this_cpu_ptr(smca_bank_counts);
275277
const struct smca_hwid *s_hwid;
276278
unsigned int i, hwid_mcatype;
@@ -301,8 +303,8 @@ static void smca_configure(unsigned int bank, unsigned int cpu)
301303
* APIC based interrupt. First, check that no interrupt has been
302304
* set.
303305
*/
304-
if ((low & BIT(5)) && !((high >> 5) & 0x3)) {
305-
__set_bit(bank, this_cpu_ptr(&mce_amd_data)->dfr_intr_banks);
306+
if ((low & BIT(5)) && !((high >> 5) & 0x3) && data->dfr_intr_en) {
307+
__set_bit(bank, data->dfr_intr_banks);
306308
high |= BIT(5);
307309
}
308310

@@ -377,6 +379,14 @@ static bool lvt_off_valid(struct threshold_block *b, int apic, u32 lo, u32 hi)
377379
{
378380
int msr = (hi & MASK_LVTOFF_HI) >> 20;
379381

382+
/*
383+
* On SMCA CPUs, LVT offset is programmed at a different MSR, and
384+
* the BIOS provides the value. The original field where LVT offset
385+
* was set is reserved. Return early here:
386+
*/
387+
if (mce_flags.smca)
388+
return false;
389+
380390
if (apic < 0) {
381391
pr_err(FW_BUG "cpu %d, failed to setup threshold interrupt "
382392
"for bank %d, block %d (MSR%08X=0x%x%08x)\n", b->cpu,
@@ -385,14 +395,6 @@ static bool lvt_off_valid(struct threshold_block *b, int apic, u32 lo, u32 hi)
385395
}
386396

387397
if (apic != msr) {
388-
/*
389-
* On SMCA CPUs, LVT offset is programmed at a different MSR, and
390-
* the BIOS provides the value. The original field where LVT offset
391-
* was set is reserved. Return early here:
392-
*/
393-
if (mce_flags.smca)
394-
return false;
395-
396398
pr_err(FW_BUG "cpu %d, invalid threshold interrupt offset %d "
397399
"for bank %d, block %d (MSR%08X=0x%x%08x)\n",
398400
b->cpu, apic, b->bank, b->block, b->address, hi, lo);
@@ -473,41 +475,6 @@ static int setup_APIC_mce_threshold(int reserved, int new)
473475
return reserved;
474476
}
475477

476-
static int setup_APIC_deferred_error(int reserved, int new)
477-
{
478-
if (reserved < 0 && !setup_APIC_eilvt(new, DEFERRED_ERROR_VECTOR,
479-
APIC_EILVT_MSG_FIX, 0))
480-
return new;
481-
482-
return reserved;
483-
}
484-
485-
static void deferred_error_interrupt_enable(struct cpuinfo_x86 *c)
486-
{
487-
u32 low = 0, high = 0;
488-
int def_offset = -1, def_new;
489-
490-
if (rdmsr_safe(MSR_CU_DEF_ERR, &low, &high))
491-
return;
492-
493-
def_new = (low & MASK_DEF_LVTOFF) >> 4;
494-
if (!(low & MASK_DEF_LVTOFF)) {
495-
pr_err(FW_BUG "Your BIOS is not setting up LVT offset 0x2 for deferred error IRQs correctly.\n");
496-
def_new = DEF_LVT_OFF;
497-
low = (low & ~MASK_DEF_LVTOFF) | (DEF_LVT_OFF << 4);
498-
}
499-
500-
def_offset = setup_APIC_deferred_error(def_offset, def_new);
501-
if ((def_offset == def_new) &&
502-
(deferred_error_int_vector != amd_deferred_error_interrupt))
503-
deferred_error_int_vector = amd_deferred_error_interrupt;
504-
505-
if (!mce_flags.smca)
506-
low = (low & ~MASK_DEF_INT_TYPE) | DEF_INT_TYPE_APIC;
507-
508-
wrmsr(MSR_CU_DEF_ERR, low, high);
509-
}
510-
511478
static u32 get_block_address(u32 current_addr, u32 low, u32 high,
512479
unsigned int bank, unsigned int block,
513480
unsigned int cpu)
@@ -543,12 +510,10 @@ static u32 get_block_address(u32 current_addr, u32 low, u32 high,
543510
return addr;
544511
}
545512

546-
static int
547-
prepare_threshold_block(unsigned int bank, unsigned int block, u32 addr,
548-
int offset, u32 misc_high)
513+
static int prepare_threshold_block(unsigned int bank, unsigned int block, u32 addr,
514+
int offset, u32 misc_high)
549515
{
550516
unsigned int cpu = smp_processor_id();
551-
u32 smca_low, smca_high;
552517
struct threshold_block b;
553518
int new;
554519

@@ -568,26 +533,17 @@ prepare_threshold_block(unsigned int bank, unsigned int block, u32 addr,
568533
__set_bit(bank, this_cpu_ptr(&mce_amd_data)->thr_intr_banks);
569534
b.interrupt_enable = 1;
570535

571-
if (!mce_flags.smca) {
572-
new = (misc_high & MASK_LVTOFF_HI) >> 20;
573-
goto set_offset;
574-
}
575-
576-
/* Gather LVT offset for thresholding: */
577-
if (rdmsr_safe(MSR_CU_DEF_ERR, &smca_low, &smca_high))
578-
goto out;
579-
580-
new = (smca_low & SMCA_THR_LVT_OFF) >> 12;
536+
if (mce_flags.smca)
537+
goto done;
581538

582-
set_offset:
539+
new = (misc_high & MASK_LVTOFF_HI) >> 20;
583540
offset = setup_APIC_mce_threshold(offset, new);
584541
if (offset == new)
585542
thresholding_irq_en = true;
586543

587544
done:
588545
mce_threshold_block_init(&b, offset);
589546

590-
out:
591547
return offset;
592548
}
593549

@@ -678,6 +634,32 @@ static void amd_apply_cpu_quirks(struct cpuinfo_x86 *c)
678634
mce_banks[0].ctl = 0;
679635
}
680636

637+
/*
638+
* Enable the APIC LVT interrupt vectors once per-CPU. This should be done before hardware is
639+
* ready to send interrupts.
640+
*
641+
* Individual error sources are enabled later during per-bank init.
642+
*/
643+
static void smca_enable_interrupt_vectors(void)
644+
{
645+
struct mce_amd_cpu_data *data = this_cpu_ptr(&mce_amd_data);
646+
u64 mca_intr_cfg, offset;
647+
648+
if (!mce_flags.smca || !mce_flags.succor)
649+
return;
650+
651+
if (rdmsrq_safe(MSR_CU_DEF_ERR, &mca_intr_cfg))
652+
return;
653+
654+
offset = (mca_intr_cfg & SMCA_THR_LVT_OFF) >> 12;
655+
if (!setup_APIC_eilvt(offset, THRESHOLD_APIC_VECTOR, APIC_EILVT_MSG_FIX, 0))
656+
data->thr_intr_en = 1;
657+
658+
offset = (mca_intr_cfg & MASK_DEF_LVTOFF) >> 4;
659+
if (!setup_APIC_eilvt(offset, DEFERRED_ERROR_VECTOR, APIC_EILVT_MSG_FIX, 0))
660+
data->dfr_intr_en = 1;
661+
}
662+
681663
/* cpu init entry point, called from mce.c with preempt off */
682664
void mce_amd_feature_init(struct cpuinfo_x86 *c)
683665
{
@@ -689,10 +671,16 @@ void mce_amd_feature_init(struct cpuinfo_x86 *c)
689671

690672
mce_flags.amd_threshold = 1;
691673

674+
smca_enable_interrupt_vectors();
675+
692676
for (bank = 0; bank < this_cpu_read(mce_num_banks); ++bank) {
693-
if (mce_flags.smca)
677+
if (mce_flags.smca) {
694678
smca_configure(bank, cpu);
695679

680+
if (!this_cpu_ptr(&mce_amd_data)->thr_intr_en)
681+
continue;
682+
}
683+
696684
disable_err_thresholding(c, bank);
697685

698686
for (block = 0; block < NR_BLOCKS; ++block) {
@@ -713,9 +701,6 @@ void mce_amd_feature_init(struct cpuinfo_x86 *c)
713701
offset = prepare_threshold_block(bank, block, address, offset, high);
714702
}
715703
}
716-
717-
if (mce_flags.succor)
718-
deferred_error_interrupt_enable(c);
719704
}
720705

721706
void smca_bsp_init(void)

0 commit comments

Comments
 (0)