powerpc/64s: Fix __pte_needs_flush() false positive warning
PATCH v2 1/1 powerpc/64s: Fix __pte_needs_flush() false positive warning
Userspace PROT_NONE ptes set _PAGE_PRIVILEGED, triggering a false positive debug assertion that __pte_flags_need_flush() is not called on a kernel mapping.
Detect when it is a userspace PROT_NONE page by checking the required bits of PAGE_NONE are set, and none of the RWX bits are set. pte_protnone() is insufficient here because it always returns 0 when CONFIG_NUMA_BALANCING=n.
---
v2: removed an auto-import that slipped in
MRE (CONFIG_DEBUG_VM must be enabled):
int main(int argc, char **argv)
{
char *buf = mmap(NULL, getpagesize(), PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
buf[0] = '1';
mprotect(buf, getpagesize(), PROT_NONE);
return 0;
}
---
arch/powerpc/include/asm/book3s/64/tlbflush.h | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)arch/powerpc/include/asm/book3s/64/tlbflush.h +7 -2
@@ -148,6 +148,11 @@ static inline void flush_tlb_fix_spurious_fault(struct vm_area_struct *vma,*/ } +static inline bool __pte_protnone (unsigned long pte) +{ +return (pte & (pgprot_val (PAGE_NONE ) | _PAGE_RWX)) ==pgprot_val (PAGE_NONE ); +} +static inline bool __pte_flags_need_flush (unsigned long oldval,unsigned long newval) {
@@ -164,8 +169,8 @@ static inline bool __pte_flags_need_flush(unsigned long oldval,/* * We do not expect kernel mappings or non-PTEs or not-present PTEs. */ -VM_WARN_ON_ONCE (oldval & _PAGE_PRIVILEGED); -VM_WARN_ON_ONCE (newval & _PAGE_PRIVILEGED); +VM_WARN_ON_ONCE (!__pte_protnone (oldval) && oldval & _PAGE_PRIVILEGED); +VM_WARN_ON_ONCE (!__pte_protnone (newval) && newval & _PAGE_PRIVILEGED);VM_WARN_ON_ONCE (!(oldval & _PAGE_PTE));VM_WARN_ON_ONCE (!(newval & _PAGE_PTE));VM_WARN_ON_ONCE (!(oldval & _PAGE_PRESENT));
base-commit: 90dbf76e470bc4b973052a8f26ea43bae30f9aec
Signature · 1 line
2.39.2
Michael Ellerman
AppliedQuoted 10 lines · Benjamin Gray
Userspace
PROT_NONEptes set_PAGE_PRIVILEGED, triggering a false positive debug assertion that__pte_flags_need_flush()is not called on a kernel mapping.Detect when it is a userspace
PROT_NONEpage by checking the required bits ofPAGE_NONEare set, and none of the RWX bits are set.pte_protnone()is insufficient here because it always returns 0 whenCONFIG_NUMA_BALANCING=n.[...]
Applied to powerpc/fixes.
[1/1] powerpc/64s: Fix __pte_needs_flush() false positive warning
https://git.kernel.org/powerpc/c/1abce0580b89464546ae06abd5891ebec43c9470
cheers