Skip to contentSkip to conversation

riscv: Grab text_mutex before patching jump-labels

PATCH In review Emil Renner Berthing 2 participants 2 messages Jul 23, 2020 – Jul 27, 2020

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

PATCH 1/1 riscv: Grab text_mutex before patching jump-labels

Like other arch's we use patch_text_nosync or equivalent to patch the jump-labels, but also like other arch's we need to hold the text_mutex before calling that.

---

Fixes b6e0878a4ec8 ("riscv: Add jump-label implementation")

..that is already in riscv/for-next.

Palmer: Sorry, I didn't notice this before. Feel free to squash this into the commit above if you like.

---
 arch/riscv/kernel/jump_label.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/riscv/kernel/jump_label.c +5 -1
index 1bab1abc1aa5..20e09056d141 100644
@@ -4,8 +4,10 @@
  *
  * Based on arch/arm64/kernel/jump_label.c
  */
-#include <linux/kernel.h>
 #include <linux/jump_label.h>
+#include <linux/kernel.h>
+#include <linux/memory.h>
+#include <linux/mutex.h>
 #include <asm/bug.h>
 #include <asm/patch.h>
 
@@ -33,7 +35,9 @@ void arch_jump_label_transform(struct jump_entry *entry,
 		insn = RISCV_INSN_NOP;
 	}
 
+	mutex_lock(&text_mutex);
 	patch_text_nosync(addr, &insn, sizeof(insn));
+	mutex_unlock(&text_mutex);
 }
 
 void arch_jump_label_transform_static(struct jump_entry *entry,
Signature · 1 line
2.27.0
maintainer
#1 lore raw
Quoted 33 lines · On Thu, 23 Jul 2020 09:36:28 PDT (-0700), [email protected] wrote:

Like other arch's we use patch_text_nosync or equivalent to patch the jump-labels, but also like other arch's we need to hold the text_mutex before calling that.

---

Fixes b6e0878a4ec8 ("riscv: Add jump-label implementation")

..that is already in riscv/for-next.

Palmer: Sorry, I didn't notice this before. Feel free to squash this into the commit above if you like.

---
 arch/riscv/kernel/jump_label.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/riscv/kernel/jump_label.c +3 -1
index 1bab1abc1aa5..20e09056d141 100644
@@ -4,8 +4,10 @@
  *
  * Based on arch/arm64/kernel/jump_label.c
  */
-#include <linux/kernel.h>
 #include <linux/jump_label.h>
+#include <linux/kernel.h>
+#include <linux/memory.h>
+#include <linux/mutex.h>
 #include <asm/bug.h>
 #include <asm/patch.h>
 

arch/riscv/kernel/jump_label.c void arch_jump_label_transform(struct jump_entry *entry, · line 43

Quoted 9 lines
arch/riscv/kernel/jump_label.c +2 -0
@@ -33,7 +35,9 @@ void arch_jump_label_transform(struct jump_entry *entry,
 		insn = RISCV_INSN_NOP;
 	}
 
+	mutex_lock(&text_mutex);
 	patch_text_nosync(addr, &insn, sizeof(insn));
+	mutex_unlock(&text_mutex);
 }
 
 void arch_jump_label_transform_static(struct jump_entry *entry,

I've just put this on for-next as is. I generally try to avoid rebasing stuff, but I think I saw a message today about a patch I put there prematurely so I might have to rewrite history anyway. If I do I'll squash it and a few other small fixes.

Thanks!