Skip to content

Commit 9cbacb8

Browse files
chleroympe
authored andcommitted
powerpc: Don't ignore errors from set_memory_{n}p() in __kernel_map_pages()
set_memory_p() and set_memory_np() can fail. As mentioned in linux/mm.h: /* * To support DEBUG_PAGEALLOC architecture must ensure that * __kernel_map_pages() never fails */ So panic in case set_memory_p() or set_memory_np() fail in __kernel_map_pages(). Link: KSPP#7 Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://msgid.link/20ef75884aa6a636e8298736f3d1056b0793d3d9.1708078640.git.christophe.leroy@csgroup.eu
1 parent 3c8016e commit 9cbacb8

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

arch/powerpc/mm/book3s64/hash_utils.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2172,7 +2172,7 @@ static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lmi)
21722172
mmu_kernel_ssize, 0);
21732173
}
21742174

2175-
void hash__kernel_map_pages(struct page *page, int numpages, int enable)
2175+
int hash__kernel_map_pages(struct page *page, int numpages, int enable)
21762176
{
21772177
unsigned long flags, vaddr, lmi;
21782178
int i;
@@ -2189,6 +2189,7 @@ void hash__kernel_map_pages(struct page *page, int numpages, int enable)
21892189
kernel_unmap_linear_page(vaddr, lmi);
21902190
}
21912191
local_irq_restore(flags);
2192+
return 0;
21922193
}
21932194
#endif /* CONFIG_DEBUG_PAGEALLOC || CONFIG_KFENCE */
21942195

arch/powerpc/mm/mmu_decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,4 @@ int create_section_mapping(unsigned long start, unsigned long end,
187187
int nid, pgprot_t prot);
188188
#endif
189189

190-
void hash__kernel_map_pages(struct page *page, int numpages, int enable);
190+
int hash__kernel_map_pages(struct page *page, int numpages, int enable);

arch/powerpc/mm/pageattr.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,21 @@ int change_memory_attr(unsigned long addr, int numpages, long action)
107107
#ifdef CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC
108108
void __kernel_map_pages(struct page *page, int numpages, int enable)
109109
{
110+
int err;
110111
unsigned long addr = (unsigned long)page_address(page);
111112

112113
if (PageHighMem(page))
113114
return;
114115

115116
if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && !radix_enabled())
116-
hash__kernel_map_pages(page, numpages, enable);
117+
err = hash__kernel_map_pages(page, numpages, enable);
117118
else if (enable)
118-
set_memory_p(addr, numpages);
119+
err = set_memory_p(addr, numpages);
119120
else
120-
set_memory_np(addr, numpages);
121+
err = set_memory_np(addr, numpages);
122+
123+
if (err)
124+
panic("%s: changing memory protections failed\n", __func__);
121125
}
122126
#endif
123127
#endif

0 commit comments

Comments
 (0)