Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1699909

[RFC][PATCH]: x86: clarify/fix no-op barriers for text_poke_bp()

From Peter Zijlstra <peterz@infradead.org>
Newsgroups linux.kernel
Subject [RFC][PATCH]: x86: clarify/fix no-op barriers for text_poke_bp()
Date 2017-07-31 12:30 +0200
Message-ID <u9g7x-54B-33@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


So I was looking at text_poke_bp() today and I couldn't make sense of
the barriers there.

How's for something like so?

---
 arch/x86/kernel/alternative.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index 32e14d137416..3344d3382e91 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -742,7 +742,16 @@ static void *bp_int3_handler, *bp_int3_addr;
 
 int poke_int3_handler(struct pt_regs *regs)
 {
-	/* bp_patching_in_progress */
+	/*
+	 * Having observed our INT3 instruction, we now must observe
+	 * bp_patching_in_progress.
+	 *
+	 * 	in_progress = TRUE		INT3
+	 * 	WMB				RMB
+	 * 	write INT3			if (in_progress)
+	 *
+	 * Idem for bp_int3_handler.
+	 */
 	smp_rmb();
 
 	if (likely(!bp_patching_in_progress))
@@ -788,9 +797,8 @@ void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
 	bp_int3_addr = (u8 *)addr + sizeof(int3);
 	bp_patching_in_progress = true;
 	/*
-	 * Corresponding read barrier in int3 notifier for
-	 * making sure the in_progress flags is correctly ordered wrt.
-	 * patching
+	 * Corresponding read barrier in int3 notifier for making sure the
+	 * in_progress and handler are correctly ordered wrt. patching.
 	 */
 	smp_wmb();
 
@@ -815,9 +823,11 @@ void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
 	text_poke(addr, opcode, sizeof(int3));
 
 	on_each_cpu(do_sync_core, NULL, 1);
-
+	/*
+	 * sync_core() implies an smp_mb() and orders this store against
+	 * the writing of the new instruction.
+	 */
 	bp_patching_in_progress = false;
-	smp_wmb();
 
 	return addr;
 }

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[RFC][PATCH]: x86: clarify/fix no-op barriers for text_poke_bp() Peter Zijlstra <peterz@infradead.org> - 2017-07-31 12:30 +0200
  Re: [RFC][PATCH]: x86: clarify/fix no-op barriers for  text_poke_bp() Steven Rostedt <rostedt@goodmis.org> - 2017-07-31 16:30 +0200
    Re: [RFC][PATCH]: x86: clarify/fix no-op barriers for text_poke_bp() Peter Zijlstra <peterz@infradead.org> - 2017-07-31 17:10 +0200
      Re: [RFC][PATCH]: x86: clarify/fix no-op barriers for  text_poke_bp() Steven Rostedt <rostedt@goodmis.org> - 2017-07-31 17:20 +0200
        Re: [RFC][PATCH]: x86: clarify/fix no-op barriers for text_poke_bp() Peter Zijlstra <peterz@infradead.org> - 2017-07-31 17:30 +0200
  Re: [RFC][PATCH]: x86: clarify/fix no-op barriers for  text_poke_bp() Jiri Kosina <jikos@kernel.org> - 2017-08-01 11:20 +0200
  [tip:x86/asm] x86: Clarify/fix no-op barriers for text_poke_bp() tip-bot for Peter Zijlstra <tipbot@zytor.com> - 2017-08-10 18:50 +0200

csiph-web