Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/32: use set_memory_attr()

Use set_memory_attr() instead of the PPC32 specific change_page_attr()

change_page_attr() was checking that the address was not mapped by
blocks and was handling highmem, but that's unneeded because the
affected pages can't be in highmem and block mapping verification
is already done by the callers.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
[ruscur: rebase on powerpc/merge with Christophe's new patches]
Signed-off-by: Russell Currey <ruscur@russell.cc>
Signed-off-by: Jordan Niethe <jniethe5@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20210609013431.9805-10-jniethe5@gmail.com

authored by

Christophe Leroy and committed by
Michael Ellerman
c988cfd3 4d1755b6

+10 -50
+10 -50
arch/powerpc/mm/pgtable_32.c
··· 23 23 #include <linux/highmem.h> 24 24 #include <linux/memblock.h> 25 25 #include <linux/slab.h> 26 + #include <linux/set_memory.h> 26 27 27 28 #include <asm/pgalloc.h> 28 29 #include <asm/fixmap.h> ··· 133 132 } 134 133 } 135 134 136 - static int __change_page_attr_noflush(struct page *page, pgprot_t prot) 137 - { 138 - pte_t *kpte; 139 - unsigned long address; 140 - 141 - BUG_ON(PageHighMem(page)); 142 - address = (unsigned long)page_address(page); 143 - 144 - if (v_block_mapped(address)) 145 - return 0; 146 - kpte = virt_to_kpte(address); 147 - if (!kpte) 148 - return -EINVAL; 149 - __set_pte_at(&init_mm, address, kpte, mk_pte(page, prot), 0); 150 - 151 - return 0; 152 - } 153 - 154 - /* 155 - * Change the page attributes of an page in the linear mapping. 156 - * 157 - * THIS DOES NOTHING WITH BAT MAPPINGS, DEBUG USE ONLY 158 - */ 159 - static int change_page_attr(struct page *page, int numpages, pgprot_t prot) 160 - { 161 - int i, err = 0; 162 - unsigned long flags; 163 - struct page *start = page; 164 - 165 - local_irq_save(flags); 166 - for (i = 0; i < numpages; i++, page++) { 167 - err = __change_page_attr_noflush(page, prot); 168 - if (err) 169 - break; 170 - } 171 - wmb(); 172 - local_irq_restore(flags); 173 - flush_tlb_kernel_range((unsigned long)page_address(start), 174 - (unsigned long)page_address(page)); 175 - return err; 176 - } 177 - 178 135 void mark_initmem_nx(void) 179 136 { 180 - struct page *page = virt_to_page(_sinittext); 181 137 unsigned long numpages = PFN_UP((unsigned long)_einittext) - 182 138 PFN_DOWN((unsigned long)_sinittext); 183 139 184 140 if (v_block_mapped((unsigned long)_sinittext)) 185 141 mmu_mark_initmem_nx(); 186 142 else 187 - change_page_attr(page, numpages, PAGE_KERNEL); 143 + set_memory_attr((unsigned long)_sinittext, numpages, PAGE_KERNEL); 188 144 } 189 145 190 146 #ifdef CONFIG_STRICT_KERNEL_RWX 191 147 void mark_rodata_ro(void) 192 148 { 193 - struct page *page; 194 149 unsigned long numpages; 195 150 196 151 if (v_block_mapped((unsigned long)_stext + 1)) { ··· 155 198 return; 156 199 } 157 200 158 - page = virt_to_page(_stext); 159 201 numpages = PFN_UP((unsigned long)_etext) - 160 202 PFN_DOWN((unsigned long)_stext); 161 203 162 - change_page_attr(page, numpages, PAGE_KERNEL_ROX); 204 + set_memory_attr((unsigned long)_stext, numpages, PAGE_KERNEL_ROX); 163 205 /* 164 206 * mark .rodata as read only. Use __init_begin rather than __end_rodata 165 207 * to cover NOTES and EXCEPTION_TABLE. 166 208 */ 167 - page = virt_to_page(__start_rodata); 168 209 numpages = PFN_UP((unsigned long)__init_begin) - 169 210 PFN_DOWN((unsigned long)__start_rodata); 170 211 171 - change_page_attr(page, numpages, PAGE_KERNEL_RO); 212 + set_memory_attr((unsigned long)__start_rodata, numpages, PAGE_KERNEL_RO); 172 213 173 214 // mark_initmem_nx() should have already run by now 174 215 ptdump_check_wx(); ··· 176 221 #ifdef CONFIG_DEBUG_PAGEALLOC 177 222 void __kernel_map_pages(struct page *page, int numpages, int enable) 178 223 { 224 + unsigned long addr = (unsigned long)page_address(page); 225 + 179 226 if (PageHighMem(page)) 180 227 return; 181 228 182 - change_page_attr(page, numpages, enable ? PAGE_KERNEL : __pgprot(0)); 229 + if (enable) 230 + set_memory_attr(addr, numpages, PAGE_KERNEL); 231 + else 232 + set_memory_attr(addr, numpages, __pgprot(0)); 183 233 } 184 234 #endif /* CONFIG_DEBUG_PAGEALLOC */