mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Use atomic_xchg() instead atomic_dec_and_test() for stop_machine
@ 2012-06-07 13:20 OGAWA Hirofumi
  2012-06-14  8:41 ` [tip:x86/asm] x86/alternatives: Use atomic_xchg() instead atomic_dec_and_test() for stop_machine_text_poke() tip-bot for OGAWA Hirofumi
  0 siblings, 1 reply; 2+ messages in thread
From: OGAWA Hirofumi @ 2012-06-07 13:20 UTC (permalink / raw)
  To: Ingo Molnar, Masami Hiramatsu; +Cc: linux-kernel, Andrew Morton, Steven Rostedt


stop_machine_first is just to see if it is first one or not.  In this
usage, atomic_dec_and_test() makes value less than 0.

I think it is not desirable, because it only triggers
atomic_dec_and_test() less than 0 debug patch. (the patch tests result
of atomic_dec_and_test() is < 0)

So, this uses atomic_xchg() instead.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
---

 arch/x86/kernel/alternative.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff -puN arch/x86/kernel/alternative.c~stop_machine-use-atomic_xchg arch/x86/kernel/alternative.c
--- linux/arch/x86/kernel/alternative.c~stop_machine-use-atomic_xchg	2012-05-23 13:10:03.000000000 +0900
+++ linux-hirofumi/arch/x86/kernel/alternative.c	2012-05-23 13:10:03.000000000 +0900
@@ -664,7 +664,7 @@ static int __kprobes stop_machine_text_p
 	struct text_poke_param *p;
 	int i;
 
-	if (atomic_dec_and_test(&stop_machine_first)) {
+	if (atomic_xchg(&stop_machine_first, 0)) {
 		for (i = 0; i < tpp->nparams; i++) {
 			p = &tpp->params[i];
 			text_poke(p->addr, p->opcode, p->len);
_
-- 
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [tip:x86/asm] x86/alternatives: Use atomic_xchg() instead atomic_dec_and_test() for stop_machine_text_poke()
  2012-06-07 13:20 [PATCH] Use atomic_xchg() instead atomic_dec_and_test() for stop_machine OGAWA Hirofumi
@ 2012-06-14  8:41 ` tip-bot for OGAWA Hirofumi
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for OGAWA Hirofumi @ 2012-06-14  8:41 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, a.p.zijlstra, rostedt, hirofumi, tglx

Commit-ID:  2f74759056797054122cdc70844137f70bb3f626
Gitweb:     http://git.kernel.org/tip/2f74759056797054122cdc70844137f70bb3f626
Author:     OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
AuthorDate: Thu, 7 Jun 2012 22:20:18 +0900
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 13 Jun 2012 15:08:37 +0200

x86/alternatives: Use atomic_xchg() instead atomic_dec_and_test() for stop_machine_text_poke()

stop_machine_text_poke() uses atomic_dec_and_test() to select one of
the CPUs executing that function to actually modify the code.

Since the variable is initialized to 1, subsequent CPUs will make the
variable go negative. Since going negative is uncommon/unexpected in
typical dec_and_test usage change this user to atomic_xchg().

This was found using a patch that warns on dec_and_test going
negative.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
[ Rewrote changelog ]
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/87zk8fgsx9.fsf@devron.myhome.or.jp
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/alternative.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index 1f84794..53231a0 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -664,7 +664,7 @@ static int __kprobes stop_machine_text_poke(void *data)
 	struct text_poke_param *p;
 	int i;
 
-	if (atomic_dec_and_test(&stop_machine_first)) {
+	if (atomic_xchg(&stop_machine_first, 0)) {
 		for (i = 0; i < tpp->nparams; i++) {
 			p = &tpp->params[i];
 			text_poke(p->addr, p->opcode, p->len);

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-06-14  8:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-07 13:20 [PATCH] Use atomic_xchg() instead atomic_dec_and_test() for stop_machine OGAWA Hirofumi
2012-06-14  8:41 ` [tip:x86/asm] x86/alternatives: Use atomic_xchg() instead atomic_dec_and_test() for stop_machine_text_poke() tip-bot for OGAWA Hirofumi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome