]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-6.6/riscv-disable-preemption-when-using-patch_map.patch
dbe7d1a8f2ba9272842b85230ec8e4f8cca5926a
[thirdparty/kernel/stable-queue.git] / queue-6.6 / riscv-disable-preemption-when-using-patch_map.patch
1 From 71e74f4f04dc64c68587d54afba7ea005c538e55 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Tue, 26 Mar 2024 21:30:17 +0100
4 Subject: riscv: Disable preemption when using patch_map()
5
6 From: Alexandre Ghiti <alexghiti@rivosinc.com>
7
8 [ Upstream commit a370c2419e4680a27382d9231edcf739d5d74efc ]
9
10 patch_map() uses fixmap mappings to circumvent the non-writability of
11 the kernel text mapping.
12
13 The __set_fixmap() function only flushes the current cpu tlb, it does
14 not emit an IPI so we must make sure that while we use a fixmap mapping,
15 the current task is not migrated on another cpu which could miss the
16 newly introduced fixmap mapping.
17
18 So in order to avoid any task migration, disable the preemption.
19
20 Reported-by: Andrea Parri <andrea@rivosinc.com>
21 Closes: https://lore.kernel.org/all/ZcS+GAaM25LXsBOl@andrea/
22 Reported-by: Andy Chiu <andy.chiu@sifive.com>
23 Closes: https://lore.kernel.org/linux-riscv/CABgGipUMz3Sffu-CkmeUB1dKVwVQ73+7=sgC45-m0AE9RCjOZg@mail.gmail.com/
24 Fixes: cad539baa48f ("riscv: implement a memset like function for text")
25 Fixes: 0ff7c3b33127 ("riscv: Use text_mutex instead of patch_lock")
26 Co-developed-by: Andy Chiu <andy.chiu@sifive.com>
27 Signed-off-by: Andy Chiu <andy.chiu@sifive.com>
28 Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
29 Acked-by: Puranjay Mohan <puranjay12@gmail.com>
30 Link: https://lore.kernel.org/r/20240326203017.310422-3-alexghiti@rivosinc.com
31 Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
32 Signed-off-by: Sasha Levin <sashal@kernel.org>
33 ---
34 arch/riscv/kernel/patch.c | 8 ++++++++
35 1 file changed, 8 insertions(+)
36
37 diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c
38 index 37e87fdcf6a00..30e12b310cab7 100644
39 --- a/arch/riscv/kernel/patch.c
40 +++ b/arch/riscv/kernel/patch.c
41 @@ -80,6 +80,8 @@ static int __patch_insn_set(void *addr, u8 c, size_t len)
42 */
43 lockdep_assert_held(&text_mutex);
44
45 + preempt_disable();
46 +
47 if (across_pages)
48 patch_map(addr + PAGE_SIZE, FIX_TEXT_POKE1);
49
50 @@ -92,6 +94,8 @@ static int __patch_insn_set(void *addr, u8 c, size_t len)
51 if (across_pages)
52 patch_unmap(FIX_TEXT_POKE1);
53
54 + preempt_enable();
55 +
56 return 0;
57 }
58 NOKPROBE_SYMBOL(__patch_insn_set);
59 @@ -122,6 +126,8 @@ static int __patch_insn_write(void *addr, const void *insn, size_t len)
60 if (!riscv_patch_in_stop_machine)
61 lockdep_assert_held(&text_mutex);
62
63 + preempt_disable();
64 +
65 if (across_pages)
66 patch_map(addr + PAGE_SIZE, FIX_TEXT_POKE1);
67
68 @@ -134,6 +140,8 @@ static int __patch_insn_write(void *addr, const void *insn, size_t len)
69 if (across_pages)
70 patch_unmap(FIX_TEXT_POKE1);
71
72 + preempt_enable();
73 +
74 return ret;
75 }
76 NOKPROBE_SYMBOL(__patch_insn_write);
77 --
78 2.43.0
79