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

s390/pageattr: avoid unnecessary page table splitting

The kernel page table splitting code will split page tables even for
features the CPU does not support. E.g. a CPU may not support the NX
feature.
In order to avoid this, remove those bits from the flags parameter
that correlate with unsupported CPU features within __set_memory(). In
addition add an early exit if the flags parameter does not have any
bits set afterwards.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>

authored by

Heiko Carstens and committed by
Martin Schwidefsky
1366def3 9b11c791

+7 -3
+7 -3
arch/s390/mm/pageattr.c
··· 94 94 new = pte_wrprotect(new); 95 95 else if (flags & SET_MEMORY_RW) 96 96 new = pte_mkwrite(pte_mkdirty(new)); 97 - if ((flags & SET_MEMORY_NX) && MACHINE_HAS_NX) 97 + if (flags & SET_MEMORY_NX) 98 98 pte_val(new) |= _PAGE_NOEXEC; 99 99 else if (flags & SET_MEMORY_X) 100 100 pte_val(new) &= ~_PAGE_NOEXEC; ··· 144 144 new = pmd_wrprotect(new); 145 145 else if (flags & SET_MEMORY_RW) 146 146 new = pmd_mkwrite(pmd_mkdirty(new)); 147 - if ((flags & SET_MEMORY_NX) && MACHINE_HAS_NX) 147 + if (flags & SET_MEMORY_NX) 148 148 pmd_val(new) |= _SEGMENT_ENTRY_NOEXEC; 149 149 else if (flags & SET_MEMORY_X) 150 150 pmd_val(new) &= ~_SEGMENT_ENTRY_NOEXEC; ··· 221 221 new = pud_wrprotect(new); 222 222 else if (flags & SET_MEMORY_RW) 223 223 new = pud_mkwrite(pud_mkdirty(new)); 224 - if ((flags & SET_MEMORY_NX) && MACHINE_HAS_NX) 224 + if (flags & SET_MEMORY_NX) 225 225 pud_val(new) |= _REGION_ENTRY_NOEXEC; 226 226 else if (flags & SET_MEMORY_X) 227 227 pud_val(new) &= ~_REGION_ENTRY_NOEXEC; ··· 288 288 289 289 int __set_memory(unsigned long addr, int numpages, unsigned long flags) 290 290 { 291 + if (!MACHINE_HAS_NX) 292 + flags &= ~(SET_MEMORY_NX | SET_MEMORY_X); 293 + if (!flags) 294 + return 0; 291 295 addr &= PAGE_MASK; 292 296 return change_page_attr(addr, addr + numpages * PAGE_SIZE, flags); 293 297 }