Skip to content

Commit 6ce474a

Browse files
author
Fox Snowpatch
committed
1 parent 35d5936 commit 6ce474a

File tree

5 files changed

+65
-32
lines changed

5 files changed

+65
-32
lines changed

arch/powerpc/mm/book3s32/mmu.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static bool is_module_segment(unsigned long addr)
193193
return true;
194194
}
195195

196-
void mmu_mark_initmem_nx(void)
196+
int mmu_mark_initmem_nx(void)
197197
{
198198
int nb = mmu_has_feature(MMU_FTR_USE_HIGH_BATS) ? 8 : 4;
199199
int i;
@@ -230,9 +230,10 @@ void mmu_mark_initmem_nx(void)
230230

231231
mtsr(mfsr(i << 28) | 0x10000000, i << 28);
232232
}
233+
return 0;
233234
}
234235

235-
void mmu_mark_rodata_ro(void)
236+
int mmu_mark_rodata_ro(void)
236237
{
237238
int nb = mmu_has_feature(MMU_FTR_USE_HIGH_BATS) ? 8 : 4;
238239
int i;
@@ -245,6 +246,8 @@ void mmu_mark_rodata_ro(void)
245246
}
246247

247248
update_bats();
249+
250+
return 0;
248251
}
249252

250253
/*

arch/powerpc/mm/mmu_decl.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ static inline unsigned long p_block_mapped(phys_addr_t pa) { return 0; }
160160
#endif
161161

162162
#if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_PPC_8xx) || defined(CONFIG_PPC_E500)
163-
void mmu_mark_initmem_nx(void);
164-
void mmu_mark_rodata_ro(void);
163+
int mmu_mark_initmem_nx(void);
164+
int mmu_mark_rodata_ro(void);
165165
#else
166-
static inline void mmu_mark_initmem_nx(void) { }
167-
static inline void mmu_mark_rodata_ro(void) { }
166+
static inline int mmu_mark_initmem_nx(void) { return 0; }
167+
static inline int mmu_mark_rodata_ro(void) { return 0; }
168168
#endif
169169

170170
#ifdef CONFIG_PPC_8xx

arch/powerpc/mm/nohash/8xx.c

+21-12
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,26 @@ void __init mmu_mapin_immr(void)
119119
PAGE_KERNEL_NCG, MMU_PAGE_512K, true);
120120
}
121121

122-
static void mmu_mapin_ram_chunk(unsigned long offset, unsigned long top,
123-
pgprot_t prot, bool new)
122+
static int mmu_mapin_ram_chunk(unsigned long offset, unsigned long top,
123+
pgprot_t prot, bool new)
124124
{
125125
unsigned long v = PAGE_OFFSET + offset;
126126
unsigned long p = offset;
127+
int err = 0;
127128

128129
WARN_ON(!IS_ALIGNED(offset, SZ_512K) || !IS_ALIGNED(top, SZ_512K));
129130

130-
for (; p < ALIGN(p, SZ_8M) && p < top; p += SZ_512K, v += SZ_512K)
131-
__early_map_kernel_hugepage(v, p, prot, MMU_PAGE_512K, new);
132-
for (; p < ALIGN_DOWN(top, SZ_8M) && p < top; p += SZ_8M, v += SZ_8M)
133-
__early_map_kernel_hugepage(v, p, prot, MMU_PAGE_8M, new);
134-
for (; p < ALIGN_DOWN(top, SZ_512K) && p < top; p += SZ_512K, v += SZ_512K)
135-
__early_map_kernel_hugepage(v, p, prot, MMU_PAGE_512K, new);
131+
for (; p < ALIGN(p, SZ_8M) && p < top && !err; p += SZ_512K, v += SZ_512K)
132+
err = __early_map_kernel_hugepage(v, p, prot, MMU_PAGE_512K, new);
133+
for (; p < ALIGN_DOWN(top, SZ_8M) && p < top && !err; p += SZ_8M, v += SZ_8M)
134+
err = __early_map_kernel_hugepage(v, p, prot, MMU_PAGE_8M, new);
135+
for (; p < ALIGN_DOWN(top, SZ_512K) && p < top && !err; p += SZ_512K, v += SZ_512K)
136+
err = __early_map_kernel_hugepage(v, p, prot, MMU_PAGE_512K, new);
136137

137138
if (!new)
138139
flush_tlb_kernel_range(PAGE_OFFSET + v, PAGE_OFFSET + top);
140+
141+
return err;
139142
}
140143

141144
unsigned long __init mmu_mapin_ram(unsigned long base, unsigned long top)
@@ -166,27 +169,33 @@ unsigned long __init mmu_mapin_ram(unsigned long base, unsigned long top)
166169
return top;
167170
}
168171

169-
void mmu_mark_initmem_nx(void)
172+
int mmu_mark_initmem_nx(void)
170173
{
171174
unsigned long etext8 = ALIGN(__pa(_etext), SZ_8M);
172175
unsigned long sinittext = __pa(_sinittext);
173176
unsigned long boundary = strict_kernel_rwx_enabled() ? sinittext : etext8;
174177
unsigned long einittext8 = ALIGN(__pa(_einittext), SZ_8M);
178+
int err = 0;
175179

176180
if (!debug_pagealloc_enabled_or_kfence())
177-
mmu_mapin_ram_chunk(boundary, einittext8, PAGE_KERNEL, false);
181+
err = mmu_mapin_ram_chunk(boundary, einittext8, PAGE_KERNEL, false);
178182

179183
mmu_pin_tlb(block_mapped_ram, false);
184+
185+
return err;
180186
}
181187

182188
#ifdef CONFIG_STRICT_KERNEL_RWX
183-
void mmu_mark_rodata_ro(void)
189+
int mmu_mark_rodata_ro(void)
184190
{
185191
unsigned long sinittext = __pa(_sinittext);
192+
int err;
186193

187-
mmu_mapin_ram_chunk(0, sinittext, PAGE_KERNEL_ROX, false);
194+
err = mmu_mapin_ram_chunk(0, sinittext, PAGE_KERNEL_ROX, false);
188195
if (IS_ENABLED(CONFIG_PIN_TLB_DATA))
189196
mmu_pin_tlb(block_mapped_ram, true);
197+
198+
return err;
190199
}
191200
#endif
192201

arch/powerpc/mm/nohash/e500.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -285,19 +285,23 @@ void __init adjust_total_lowmem(void)
285285
}
286286

287287
#ifdef CONFIG_STRICT_KERNEL_RWX
288-
void mmu_mark_rodata_ro(void)
288+
int mmu_mark_rodata_ro(void)
289289
{
290290
unsigned long remapped;
291291

292292
remapped = map_mem_in_cams(__max_low_memory, CONFIG_LOWMEM_CAM_NUM, false, false);
293293

294-
WARN_ON(__max_low_memory != remapped);
294+
if (WARN_ON(__max_low_memory != remapped))
295+
return -EINVAL;
296+
297+
return 0;
295298
}
296299
#endif
297300

298-
void mmu_mark_initmem_nx(void)
301+
int mmu_mark_initmem_nx(void)
299302
{
300303
/* Everything is done in mmu_mark_rodata_ro() */
304+
return 0;
301305
}
302306

303307
void setup_initial_memory_limit(phys_addr_t first_memblock_base,

arch/powerpc/mm/pgtable_32.c

+28-11
Original file line numberDiff line numberDiff line change
@@ -130,32 +130,41 @@ void __init mapin_ram(void)
130130
}
131131
}
132132

133-
void mark_initmem_nx(void)
133+
static int __mark_initmem_nx(void)
134134
{
135135
unsigned long numpages = PFN_UP((unsigned long)_einittext) -
136136
PFN_DOWN((unsigned long)_sinittext);
137+
int err;
137138

138-
mmu_mark_initmem_nx();
139+
err = mmu_mark_initmem_nx();
139140

140141
if (!v_block_mapped((unsigned long)_sinittext)) {
141-
set_memory_nx((unsigned long)_sinittext, numpages);
142-
set_memory_rw((unsigned long)_sinittext, numpages);
142+
err = set_memory_nx((unsigned long)_sinittext, numpages);
143+
if (err)
144+
return err;
145+
err = set_memory_rw((unsigned long)_sinittext, numpages);
143146
}
147+
return err;
148+
}
149+
150+
void mark_initmem_nx(void)
151+
{
152+
int err = __mark_initmem_nx();
153+
154+
if (err)
155+
panic("%s() failed, err = %d\n", __func__, err);
144156
}
145157

146158
#ifdef CONFIG_STRICT_KERNEL_RWX
147-
void mark_rodata_ro(void)
159+
static int __mark_rodata_ro(void)
148160
{
149161
unsigned long numpages;
150162

151163
if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX) && mmu_has_feature(MMU_FTR_HPTE_TABLE))
152164
pr_warn("This platform has HASH MMU, STRICT_MODULE_RWX won't work\n");
153165

154-
if (v_block_mapped((unsigned long)_stext + 1)) {
155-
mmu_mark_rodata_ro();
156-
ptdump_check_wx();
157-
return;
158-
}
166+
if (v_block_mapped((unsigned long)_stext + 1))
167+
return mmu_mark_rodata_ro();
159168

160169
/*
161170
* mark text and rodata as read only. __end_rodata is set by
@@ -165,7 +174,15 @@ void mark_rodata_ro(void)
165174
numpages = PFN_UP((unsigned long)__end_rodata) -
166175
PFN_DOWN((unsigned long)_stext);
167176

168-
set_memory_ro((unsigned long)_stext, numpages);
177+
return set_memory_ro((unsigned long)_stext, numpages);
178+
}
179+
180+
void mark_rodata_ro(void)
181+
{
182+
int err = __mark_rodata_ro();
183+
184+
if (err)
185+
panic("%s() failed, err = %d\n", __func__, err);
169186

170187
// mark_initmem_nx() should have already run by now
171188
ptdump_check_wx();

0 commit comments

Comments
 (0)