]> www.infradead.org Git - users/hch/misc.git/commitdiff
x86/mce/amd: Put list_head in threshold_bank
authorYazen Ghannam <yazen.ghannam@amd.com>
Tue, 24 Jun 2025 14:16:03 +0000 (14:16 +0000)
committerBorislav Petkov (AMD) <bp@alien8.de>
Fri, 5 Sep 2025 10:42:21 +0000 (12:42 +0200)
The threshold_bank structure is a container for one or more threshold_block
structures. Currently, the container has a single pointer to the 'first'
threshold_block structure which then has a linked list of the remaining
threshold_block structures.

This results in an extra level of indirection where the 'first' block is
checked before iterating over the remaining blocks.

Remove the indirection by including the head of the block list in the
threshold_bank structure which already acts as a container for all the bank's
thresholding blocks.

Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Tested-by: Tony Luck <tony.luck@intel.com>
Link: https://lore.kernel.org/20250624-wip-mca-updates-v4-8-236dd74f645f@amd.com
arch/x86/kernel/cpu/mce/amd.c

index 7e36bc0d0e6c0f52cd26b23eb0ccc7f5a66252db..e9b9be2215edfb521552fc7fe86ce4ca0b90b4d4 100644 (file)
@@ -241,7 +241,8 @@ struct threshold_block {
 
 struct threshold_bank {
        struct kobject          *kobj;
-       struct threshold_block  *blocks;
+       /* List of threshold blocks within this MCA bank. */
+       struct list_head        miscj;
 };
 
 static DEFINE_PER_CPU(struct threshold_bank **, threshold_banks);
@@ -898,9 +899,9 @@ static void log_and_reset_block(struct threshold_block *block)
  */
 static void amd_threshold_interrupt(void)
 {
-       struct threshold_block *first_block = NULL, *block = NULL, *tmp = NULL;
-       struct threshold_bank **bp = this_cpu_read(threshold_banks);
+       struct threshold_bank **bp = this_cpu_read(threshold_banks), *thr_bank;
        unsigned int bank, cpu = smp_processor_id();
+       struct threshold_block *block, *tmp;
 
        /*
         * Validate that the threshold bank has been initialized already. The
@@ -914,16 +915,11 @@ static void amd_threshold_interrupt(void)
                if (!(per_cpu(bank_map, cpu) & BIT_ULL(bank)))
                        continue;
 
-               first_block = bp[bank]->blocks;
-               if (!first_block)
+               thr_bank = bp[bank];
+               if (!thr_bank)
                        continue;
 
-               /*
-                * The first block is also the head of the list. Check it first
-                * before iterating over the rest.
-                */
-               log_and_reset_block(first_block);
-               list_for_each_entry_safe(block, tmp, &first_block->miscj, miscj)
+               list_for_each_entry_safe(block, tmp, &thr_bank->miscj, miscj)
                        log_and_reset_block(block);
        }
 }
@@ -1149,13 +1145,7 @@ static int allocate_threshold_blocks(unsigned int cpu, struct threshold_bank *tb
                default_attrs[2] = NULL;
        }
 
-       INIT_LIST_HEAD(&b->miscj);
-
-       /* This is safe as @tb is not visible yet */
-       if (tb->blocks)
-               list_add(&b->miscj, &tb->blocks->miscj);
-       else
-               tb->blocks = b;
+       list_add(&b->miscj, &tb->miscj);
 
        err = kobject_init_and_add(&b->kobj, &threshold_ktype, tb->kobj, get_name(cpu, bank, b));
        if (err)
@@ -1206,6 +1196,8 @@ static int threshold_create_bank(struct threshold_bank **bp, unsigned int cpu,
                goto out_free;
        }
 
+       INIT_LIST_HEAD(&b->miscj);
+
        err = allocate_threshold_blocks(cpu, b, bank, 0, mca_msr_reg(bank, MCA_MISC));
        if (err)
                goto out_kobj;
@@ -1226,26 +1218,15 @@ static void threshold_block_release(struct kobject *kobj)
        kfree(to_block(kobj));
 }
 
-static void deallocate_threshold_blocks(struct threshold_bank *bank)
+static void threshold_remove_bank(struct threshold_bank *bank)
 {
        struct threshold_block *pos, *tmp;
 
-       list_for_each_entry_safe(pos, tmp, &bank->blocks->miscj, miscj) {
+       list_for_each_entry_safe(pos, tmp, &bank->miscj, miscj) {
                list_del(&pos->miscj);
                kobject_put(&pos->kobj);
        }
 
-       kobject_put(&bank->blocks->kobj);
-}
-
-static void threshold_remove_bank(struct threshold_bank *bank)
-{
-       if (!bank->blocks)
-               goto out_free;
-
-       deallocate_threshold_blocks(bank);
-
-out_free:
        kobject_put(bank->kobj);
        kfree(bank);
 }