Skip to content

Commit

Permalink
x86/alternatives: Use atomic_xchg() instead atomic_dec_and_test() for…
Browse files Browse the repository at this point in the history
… 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 <[email protected]>
Acked-by: Steven Rostedt <[email protected]>
[ Rewrote changelog ]
Signed-off-by: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
OGAWAHirofumi authored and Ingo Molnar committed Jun 13, 2012
1 parent b0a4c6f commit 2f74759
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion arch/x86/kernel/alternative.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2f74759

Please sign in to comment.