Skip to contentSkip to conversation

x86/mce: Use atomic_inc_return barrier when starting monad sync

PATCH Applied Davidlohr Bueso 4 participants 12 messages Mar 21, 2016 – Apr 13, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/mce: Use atomic_inc_return barrier when starting monad sync

mce_start() has an explicit smp_wmb to serialize writes to global_nwo and mce_callin. However, atomic_inc_return() implies barriers on both sides of the call, as such simply rely on this full smp barrier.

---
 arch/x86/kernel/cpu/mcheck/mce.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +2 -2
index f0c921b03e42..6b7039c166b8 100644
@@ -830,9 +830,9 @@ static int mce_start(int *no_way_out)
 
 	atomic_add(*no_way_out, &global_nwo);
 	/*
-	 * global_nwo should be updated before mce_callin
+	 * Rely on the implied barrier below, such that global_nwo
+	 * is updated before mce_callin.
 	 */
-	smp_wmb();
 	order = atomic_inc_return(&mce_callin);
 
 	/*
Signature · 1 line
2.1.4
maintainer Applied
#1 lore raw
Quoted 9 lines · Davidlohr Bueso

mce_start() has an explicit smp_wmb to serialize writes to global_nwo and mce_callin. However, atomic_inc_return() implies barriers on both sides of the call, as such simply rely on this full smp barrier.

---
 arch/x86/kernel/cpu/mcheck/mce.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks.

Signature · 4 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
#2 lore raw

PATCH 1/1 x86/mce: Avoid using object after free in genpool.

When we loop over all queued machine check error records to pass them to the registered notifiers we use llist_for_each_entry(). But the loop calls gen_pool_free() for the entry in the body of the loop - and then the iterator looks at node->next after the free.

Use llist_for_each_entry_safe() instead.

---
 arch/x86/kernel/cpu/mcheck/mce-genpool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/mcheck/mce-genpool.c +2 -2
index 0a850100c594..2658e2af74ec 100644
@@ -29,7 +29,7 @@ static char gen_pool_buf[MCE_POOLSZ];
 void mce_gen_pool_process(void)
 {
 	struct llist_node *head;
-	struct mce_evt_llist *node;
+	struct mce_evt_llist *node, *tmp;
 	struct mce *mce;
 
 	head = llist_del_all(&mce_event_llist);
@@ -37,7 +37,7 @@ void mce_gen_pool_process(void)
 		return;
 
 	head = llist_reverse_order(head);
-	llist_for_each_entry(node, head, llnode) {
+	llist_for_each_entry_safe(node, tmp, head, llnode) {
 		mce = &node->mce;
 		atomic_notifier_call_chain(&x86_mce_decoder_chain, 0, mce);
 		gen_pool_free(mce_evt_pool, (unsigned long)node, sizeof(*node));
Signature · 1 line
2.5.0
maintainer Acked-by on v1 1/1
#3 lore raw

Re: [PATCH] x86/mce: Avoid using object after free in genpool.

Quoted 29 lines · Tony Luck

When we loop over all queued machine check error records to pass them to the registered notifiers we use llist_for_each_entry(). But the loop calls gen_pool_free() for the entry in the body of the loop - and then the iterator looks at node->next after the free.

Use llist_for_each_entry_safe() instead.

---
 arch/x86/kernel/cpu/mcheck/mce-genpool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/mcheck/mce-genpool.c +1 -1
index 0a850100c594..2658e2af74ec 100644
@@ -29,7 +29,7 @@ static char gen_pool_buf[MCE_POOLSZ];
 void mce_gen_pool_process(void)
 {
 	struct llist_node *head;
-	struct mce_evt_llist *node;
+	struct mce_evt_llist *node, *tmp;
 	struct mce *mce;
 
 	head = llist_del_all(&mce_event_llist);

arch/x86/kernel/cpu/mcheck/mce-genpool.c void mce_gen_pool_process(void) · line 43

Quoted 8 lines
arch/x86/kernel/cpu/mcheck/mce-genpool.c +1 -1
@@ -37,7 +37,7 @@ void mce_gen_pool_process(void)
 		return;
 
 	head = llist_reverse_order(head);
-	llist_for_each_entry(node, head, llnode) {
+	llist_for_each_entry_safe(node, tmp, head, llnode) {
 		mce = &node->mce;
 		atomic_notifier_call_chain(&x86_mce_decoder_chain, 0, mce);
 		gen_pool_free(mce_evt_pool, (unsigned long)node, sizeof(*node));

I have a couple more RAS patches for tip, want me to pick that one up too? I'm going to send my pile to tip guys after -rc1 is out.

Signature · 4 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
#4 lore raw

RE: [PATCH] x86/mce: Avoid using object after free in genpool.

Quoted 1 line

Thanks

Quoted 2 lines

I have a couple more RAS patches for tip, want me to pick that one up too? I'm going to send my pile to tip guys after -rc1 is out.

Yes please ... throw this one on the pile.

-Tony

maintainer
#5 lore raw

cover x86/RAS: Some small things for tip

From: Borislav Petkov <[email protected]>

Hi,

just a couple of smallish fixes. Tony's is CC:stable so please queue this into tip:x86/urgent.

Thanks.

Borislav Petkov (1):
x86/RAS: Rename AMD MCE injectior config item

Davidlohr Bueso (1):
x86/mce: Remove explicit smp_rmb() when starting CPUs sync

Tony Luck (1):
x86/mce: Avoid using object after free in genpool

 arch/x86/kernel/cpu/mcheck/mce-genpool.c | 4 ++--
 arch/x86/kernel/cpu/mcheck/mce.c         | 4 ++--
 arch/x86/ras/Kconfig                     | 2 +-
 arch/x86/ras/Makefile                    | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
2.7.3
maintainer
#6 lore raw

PATCH 1/3 x86/RAS: Rename AMD MCE injectior config item

From: Borislav Petkov <[email protected]>

... to be the same like the file name of injection module itself to avoid confusion when grepping.

No functionality change.

---
 arch/x86/ras/Kconfig  | 2 +-
 arch/x86/ras/Makefile | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/ras/Kconfig +1 -1
index df280da34825..d957d5f21a86 100644
@@ -1,4 +1,4 @@
-config AMD_MCE_INJ
+config MCE_AMD_INJ
 	tristate "Simple MCE injection interface for AMD processors"
 	depends on RAS && EDAC_DECODE_MCE && DEBUG_FS && AMD_NB
 	default n
arch/x86/ras/Makefile +1 -1
index dd2c98b84037..5f94546db280 100644
@@ -1,2 +1,2 @@
-obj-$(CONFIG_AMD_MCE_INJ)		+= mce_amd_inj.o
+obj-$(CONFIG_MCE_AMD_INJ)		+= mce_amd_inj.o
 
Signature · 1 line
2.7.3
#7 lore raw

[tip:ras/core] x86/RAS: Rename AMD MCE injector config item

x86/RAS: Rename AMD MCE injector config item
Commit-ID:  69385f8879344f4a1f078f761bd3523fcf697131
Gitweb:     http://git.kernel.org/tip/69385f8879344f4a1f078f761bd3523fcf697131
Author:     Borislav Petkov <[email protected]>
AuthorDate: Wed, 6 Apr 2016 10:05:14 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 13 Apr 2016 10:54:23 +0200

x86/RAS: Rename AMD MCE injector config item

... to be the same like the file name of injection module itself to avoid confusion when grepping.

No functionality change.

---
 arch/x86/ras/Kconfig  | 2 +-
 arch/x86/ras/Makefile | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/ras/Kconfig +1 -1
index df280da..d957d5f 100644
@@ -1,4 +1,4 @@
-config AMD_MCE_INJ
+config MCE_AMD_INJ
 	tristate "Simple MCE injection interface for AMD processors"
 	depends on RAS && EDAC_DECODE_MCE && DEBUG_FS && AMD_NB
 	default n
arch/x86/ras/Makefile +1 -1
index dd2c98b..5f94546 100644
@@ -1,2 +1,2 @@
-obj-$(CONFIG_AMD_MCE_INJ)		+= mce_amd_inj.o
+obj-$(CONFIG_MCE_AMD_INJ)		+= mce_amd_inj.o
 
maintainer
#8 lore raw

PATCH 2/3 x86/mce: Remove explicit smp_rmb() when starting CPUs sync

In reply to Borislav Petkov

From: Davidlohr Bueso <[email protected]>

mce_start() has an explicit smp_wmb() to serialize writes to global_nwo and mce_callin. However, atomic_inc_return() implies barriers on both sides of the call, as such simply rely on this full SMP barrier.

---
 arch/x86/kernel/cpu/mcheck/mce.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +2 -2
index f0c921b03e42..6b7039c166b8 100644
@@ -830,9 +830,9 @@ static int mce_start(int *no_way_out)
 
 	atomic_add(*no_way_out, &global_nwo);
 	/*
-	 * global_nwo should be updated before mce_callin
+	 * Rely on the implied barrier below, such that global_nwo
+	 * is updated before mce_callin.
 	 */
-	smp_wmb();
 	order = atomic_inc_return(&mce_callin);
 
 	/*
Signature · 1 line
2.7.3
#9 lore raw

[tip:ras/core] x86/mce: Remove explicit smp_rmb() when starting CPUs sync

x86/mce: Remove explicit smp_rmb() when starting CPUs sync
Commit-ID:  bf92b1feb658f6a262daf3a87d790997a1dca0ff
Gitweb:     http://git.kernel.org/tip/bf92b1feb658f6a262daf3a87d790997a1dca0ff
Author:     Davidlohr Bueso <[email protected]>
AuthorDate: Wed, 6 Apr 2016 10:05:15 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 13 Apr 2016 10:54:23 +0200

x86/mce: Remove explicit smp_rmb() when starting CPUs sync

mce_start() has an explicit smp_wmb() to serialize writes to global_nwo and mce_callin. However, atomic_inc_return() implies barriers on both sides of the call, as such simply rely on this full SMP barrier.

---
 arch/x86/kernel/cpu/mcheck/mce.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +2 -2
index f0c921b..6b7039c 100644
@@ -830,9 +830,9 @@ static int mce_start(int *no_way_out)
 
 	atomic_add(*no_way_out, &global_nwo);
 	/*
-	 * global_nwo should be updated before mce_callin
+	 * Rely on the implied barrier below, such that global_nwo
+	 * is updated before mce_callin.
 	 */
-	smp_wmb();
 	order = atomic_inc_return(&mce_callin);
 
 	/*
maintainer
#10 lore raw

PATCH 3/3 x86/mce: Avoid using object after free in genpool

In reply to Borislav Petkov

From: Tony Luck <[email protected]>

When we loop over all queued machine check error records to pass them to the registered notifiers we use llist_for_each_entry(). But the loop calls gen_pool_free() for the entry in the body of the loop - and then the iterator looks at node->next after the free.

Use llist_for_each_entry_safe() instead.

---
 arch/x86/kernel/cpu/mcheck/mce-genpool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/mcheck/mce-genpool.c +2 -2
index 0a850100c594..2658e2af74ec 100644
@@ -29,7 +29,7 @@ static char gen_pool_buf[MCE_POOLSZ];
 void mce_gen_pool_process(void)
 {
 	struct llist_node *head;
-	struct mce_evt_llist *node;
+	struct mce_evt_llist *node, *tmp;
 	struct mce *mce;
 
 	head = llist_del_all(&mce_event_llist);
@@ -37,7 +37,7 @@ void mce_gen_pool_process(void)
 		return;
 
 	head = llist_reverse_order(head);
-	llist_for_each_entry(node, head, llnode) {
+	llist_for_each_entry_safe(node, tmp, head, llnode) {
 		mce = &node->mce;
 		atomic_notifier_call_chain(&x86_mce_decoder_chain, 0, mce);
 		gen_pool_free(mce_evt_pool, (unsigned long)node, sizeof(*node));
Signature · 1 line
2.7.3
#11 lore raw

[tip:ras/core] x86/mce: Avoid using object after free in genpool

x86/mce: Avoid using object after free in genpool
Commit-ID:  a3125494cff084b098c80bb36fbe2061ffed9d52
Gitweb:     http://git.kernel.org/tip/a3125494cff084b098c80bb36fbe2061ffed9d52
Author:     Tony Luck <[email protected]>
AuthorDate: Wed, 6 Apr 2016 10:05:16 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 13 Apr 2016 10:54:00 +0200

x86/mce: Avoid using object after free in genpool

When we loop over all queued machine check error records to pass them to the registered notifiers we use llist_for_each_entry(). But the loop calls gen_pool_free() for the entry in the body of the loop - and then the iterator looks at node->next after the free.

Use llist_for_each_entry_safe() instead.

---
 arch/x86/kernel/cpu/mcheck/mce-genpool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/mcheck/mce-genpool.c +2 -2
index 0a85010..2658e2a 100644
@@ -29,7 +29,7 @@ static char gen_pool_buf[MCE_POOLSZ];
 void mce_gen_pool_process(void)
 {
 	struct llist_node *head;
-	struct mce_evt_llist *node;
+	struct mce_evt_llist *node, *tmp;
 	struct mce *mce;
 
 	head = llist_del_all(&mce_event_llist);
@@ -37,7 +37,7 @@ void mce_gen_pool_process(void)
 		return;
 
 	head = llist_reverse_order(head);
-	llist_for_each_entry(node, head, llnode) {
+	llist_for_each_entry_safe(node, tmp, head, llnode) {
 		mce = &node->mce;
 		atomic_notifier_call_chain(&x86_mce_decoder_chain, 0, mce);
 		gen_pool_free(mce_evt_pool, (unsigned long)node, sizeof(*node));