]>
Commit | Line | Data |
---|---|---|
45d80ddf SL |
1 | From 00486d04e0f6e1f6acb008568c29df4cc0e93eb3 Mon Sep 17 00:00:00 2001 |
2 | From: Michal Suchanek <msuchanek@suse.de> | |
3 | Date: Thu, 11 Apr 2019 21:46:00 +1000 | |
4 | Subject: powerpc/64s: Patch barrier_nospec in modules | |
5 | ||
6 | commit 815069ca57c142eb71d27439bc27f41a433a67b3 upstream. | |
7 | ||
8 | Note that unlike RFI which is patched only in kernel the nospec state | |
9 | reflects settings at the time the module was loaded. | |
10 | ||
11 | Iterating all modules and re-patching every time the settings change | |
12 | is not implemented. | |
13 | ||
14 | Based on lwsync patching. | |
15 | ||
16 | Signed-off-by: Michal Suchanek <msuchanek@suse.de> | |
17 | Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> | |
18 | Signed-off-by: Sasha Levin <sashal@kernel.org> | |
19 | --- | |
20 | arch/powerpc/include/asm/setup.h | 7 +++++++ | |
21 | arch/powerpc/kernel/module.c | 6 ++++++ | |
22 | arch/powerpc/kernel/security.c | 2 +- | |
23 | arch/powerpc/lib/feature-fixups.c | 16 +++++++++++++--- | |
24 | 4 files changed, 27 insertions(+), 4 deletions(-) | |
25 | ||
26 | diff --git a/arch/powerpc/include/asm/setup.h b/arch/powerpc/include/asm/setup.h | |
27 | index 709f4e739ae8..a225b5c42e76 100644 | |
28 | --- a/arch/powerpc/include/asm/setup.h | |
29 | +++ b/arch/powerpc/include/asm/setup.h | |
30 | @@ -52,6 +52,13 @@ enum l1d_flush_type { | |
31 | void setup_rfi_flush(enum l1d_flush_type, bool enable); | |
32 | void do_rfi_flush_fixups(enum l1d_flush_type types); | |
33 | void do_barrier_nospec_fixups(bool enable); | |
34 | +extern bool barrier_nospec_enabled; | |
35 | + | |
36 | +#ifdef CONFIG_PPC_BOOK3S_64 | |
37 | +void do_barrier_nospec_fixups_range(bool enable, void *start, void *end); | |
38 | +#else | |
39 | +static inline void do_barrier_nospec_fixups_range(bool enable, void *start, void *end) { }; | |
40 | +#endif | |
41 | ||
42 | #endif /* !__ASSEMBLY__ */ | |
43 | ||
44 | diff --git a/arch/powerpc/kernel/module.c b/arch/powerpc/kernel/module.c | |
45 | index 30b89d5cbb03..d30f0626dcd0 100644 | |
46 | --- a/arch/powerpc/kernel/module.c | |
47 | +++ b/arch/powerpc/kernel/module.c | |
48 | @@ -72,6 +72,12 @@ int module_finalize(const Elf_Ehdr *hdr, | |
49 | do_feature_fixups(powerpc_firmware_features, | |
50 | (void *)sect->sh_addr, | |
51 | (void *)sect->sh_addr + sect->sh_size); | |
52 | + | |
53 | + sect = find_section(hdr, sechdrs, "__spec_barrier_fixup"); | |
54 | + if (sect != NULL) | |
55 | + do_barrier_nospec_fixups_range(barrier_nospec_enabled, | |
56 | + (void *)sect->sh_addr, | |
57 | + (void *)sect->sh_addr + sect->sh_size); | |
58 | #endif | |
59 | ||
60 | sect = find_section(hdr, sechdrs, "__lwsync_fixup"); | |
61 | diff --git a/arch/powerpc/kernel/security.c b/arch/powerpc/kernel/security.c | |
62 | index 8b1cf9c81b82..34d436fe2498 100644 | |
63 | --- a/arch/powerpc/kernel/security.c | |
64 | +++ b/arch/powerpc/kernel/security.c | |
65 | @@ -15,7 +15,7 @@ | |
66 | ||
67 | unsigned long powerpc_security_features __read_mostly = SEC_FTR_DEFAULT; | |
68 | ||
69 | -static bool barrier_nospec_enabled; | |
70 | +bool barrier_nospec_enabled; | |
71 | ||
72 | static void enable_barrier_nospec(bool enable) | |
73 | { | |
74 | diff --git a/arch/powerpc/lib/feature-fixups.c b/arch/powerpc/lib/feature-fixups.c | |
75 | index f82ae6bb2365..a1222c441df5 100644 | |
76 | --- a/arch/powerpc/lib/feature-fixups.c | |
77 | +++ b/arch/powerpc/lib/feature-fixups.c | |
78 | @@ -278,14 +278,14 @@ void do_rfi_flush_fixups(enum l1d_flush_type types) | |
79 | : "unknown"); | |
80 | } | |
81 | ||
82 | -void do_barrier_nospec_fixups(bool enable) | |
83 | +void do_barrier_nospec_fixups_range(bool enable, void *fixup_start, void *fixup_end) | |
84 | { | |
85 | unsigned int instr, *dest; | |
86 | long *start, *end; | |
87 | int i; | |
88 | ||
89 | - start = PTRRELOC(&__start___barrier_nospec_fixup), | |
90 | - end = PTRRELOC(&__stop___barrier_nospec_fixup); | |
91 | + start = fixup_start; | |
92 | + end = fixup_end; | |
93 | ||
94 | instr = 0x60000000; /* nop */ | |
95 | ||
96 | @@ -304,6 +304,16 @@ void do_barrier_nospec_fixups(bool enable) | |
97 | printk(KERN_DEBUG "barrier-nospec: patched %d locations\n", i); | |
98 | } | |
99 | ||
100 | +void do_barrier_nospec_fixups(bool enable) | |
101 | +{ | |
102 | + void *start, *end; | |
103 | + | |
104 | + start = PTRRELOC(&__start___barrier_nospec_fixup), | |
105 | + end = PTRRELOC(&__stop___barrier_nospec_fixup); | |
106 | + | |
107 | + do_barrier_nospec_fixups_range(enable, start, end); | |
108 | +} | |
109 | + | |
110 | #endif /* CONFIG_PPC_BOOK3S_64 */ | |
111 | ||
112 | void do_lwsync_fixups(unsigned long value, void *fixup_start, void *fixup_end) | |
113 | -- | |
114 | 2.19.1 | |
115 |