powerpc: Don't ignore errors from set_memory_{n}p() in __kernel_map_pages()
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Fri, 16 Feb 2024 10:17:34 +0000 (11:17 +0100)
committerMichael Ellerman <mpe@ellerman.id.au>
Sun, 3 Mar 2024 11:18:45 +0000 (22:18 +1100)
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: https://github.com/KSPP/linux/issues/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
arch/powerpc/mm/book3s64/hash_utils.c
arch/powerpc/mm/mmu_decl.h
arch/powerpc/mm/pageattr.c

index 0626a25b0d728be1a33aa36012327f1ddc71374f..01c3b4b652410904a06fb45721233ee84d6fbe3b 100644 (file)
@@ -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;
@@ -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 */
 
index 4eb62bb51d49d34ac383797c51dc1e882da6157a..b4b662a6148575b74d93b33721500048fc9cc8c0 100644 (file)
@@ -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);
index 8a9d24218b74ba79800ef8a47f364152dcec4092..ac22bf28086fac5c5973d29190a6adfe5caa50b8 100644 (file)
@@ -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