[PATCH] x86/MCE/AMD: Delete kobject for block instead of bank

From: Yazen Ghannam
Date: Tue May 31 2022 - 12:29:37 EST


The AMD Thresholding kobjects are laid out such that each "bank" is parent
to one or more "blocks". Systems from Family 10h to 16h have bank4 shared
between logical CPUs that are attached to the same Northbridge. This
sharing behavior is handled when creating and removing kobjects.

During removal, the block kobjects are deleted from each CPU sharing bank4.
The final CPU puts all the block kobjects, which also deletes them, and
then puts the bank kobject.

However, __threshold_remove_blocks() deletes the bank kobject before
deleting the block kobjects. This essentially deletes the parent before all
the children, and this may cause kernel warnings.

Don't delete the bank kobject in __threshold_remove_blocks(). Leave this
for the put at the end of threshold_remove_bank(). Instead delete the block
kobject which is used as the head of the list of blocks, after deleting
all the other blocks in the list. This follows the same behavior seen in
deallocate_threshold_blocks().

Fixes: 019f34fccfd5 ("x86, MCE, AMD: Move shared bank to node descriptor")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Yazen Ghannam <yazen.ghannam@xxxxxxx>
---
arch/x86/kernel/cpu/mce/amd.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/cpu/mce/amd.c b/arch/x86/kernel/cpu/mce/amd.c
index 1c87501e0fa3..cda75aed8ea0 100644
--- a/arch/x86/kernel/cpu/mce/amd.c
+++ b/arch/x86/kernel/cpu/mce/amd.c
@@ -1258,10 +1258,10 @@ static void __threshold_remove_blocks(struct threshold_bank *b)
struct threshold_block *pos = NULL;
struct threshold_block *tmp = NULL;

- kobject_del(b->kobj);
-
list_for_each_entry_safe(pos, tmp, &b->blocks->miscj, miscj)
kobject_del(&pos->kobj);
+
+ kobject_del(&b->blocks->kobj);
}

static void threshold_remove_bank(struct threshold_bank *bank)
--
2.25.1