Skip to content

Commit

Permalink
powerpc: Don't ignore errors from set_memory_{n}p() in __kernel_map_p…
Browse files Browse the repository at this point in the history
…ages()

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/linux#7
Signed-off-by: Christophe Leroy <[email protected]>
Signed-off-by: Michael Ellerman <[email protected]>
Link: https://msgid.link/20ef75884aa6a636e8298736f3d1056b0793d3d9.1708078640.git.christophe.leroy@csgroup.eu
  • Loading branch information
chleroy authored and mpe committed Mar 3, 2024
1 parent 3c8016e commit 9cbacb8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion arch/powerpc/mm/book3s64/hash_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2172,7 +2172,7 @@ static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lmi)
mmu_kernel_ssize, 0);
}

void hash__kernel_map_pages(struct page *page, int numpages, int enable)
int hash__kernel_map_pages(struct page *page, int numpages, int enable)
{
unsigned long flags, vaddr, lmi;
int i;
Expand All @@ -2189,6 +2189,7 @@ void hash__kernel_map_pages(struct page *page, int numpages, int enable)
kernel_unmap_linear_page(vaddr, lmi);
}
local_irq_restore(flags);
return 0;
}
#endif /* CONFIG_DEBUG_PAGEALLOC || CONFIG_KFENCE */

Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/mm/mmu_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,4 @@ int create_section_mapping(unsigned long start, unsigned long end,
int nid, pgprot_t prot);
#endif

void hash__kernel_map_pages(struct page *page, int numpages, int enable);
int hash__kernel_map_pages(struct page *page, int numpages, int enable);
10 changes: 7 additions & 3 deletions arch/powerpc/mm/pageattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,21 @@ int change_memory_attr(unsigned long addr, int numpages, long action)
#ifdef CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC
void __kernel_map_pages(struct page *page, int numpages, int enable)
{
int err;
unsigned long addr = (unsigned long)page_address(page);

if (PageHighMem(page))
return;

if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && !radix_enabled())
hash__kernel_map_pages(page, numpages, enable);
err = hash__kernel_map_pages(page, numpages, enable);
else if (enable)
set_memory_p(addr, numpages);
err = set_memory_p(addr, numpages);
else
set_memory_np(addr, numpages);
err = set_memory_np(addr, numpages);

if (err)
panic("%s: changing memory protections failed\n", __func__);
}
#endif
#endif

0 comments on commit 9cbacb8

Please sign in to comment.