linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc/64s: Fix __pte_needs_flush() false positive warning
@ 2023-03-02 22:52 Benjamin Gray
  2023-03-02 23:01 ` Benjamin Gray
  0 siblings, 1 reply; 2+ messages in thread
From: Benjamin Gray @ 2023-03-02 22:52 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Benjamin Gray, npiggin, ruscur

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.

Reported-by: Russell Currey <ruscur@russell.cc>
Fixes: b11931e9adc1 ("powerpc/64s: add pte_needs_flush and huge_pmd_needs_flush")
Signed-off-by: Benjamin Gray <bgray@linux.ibm.com>
---
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 | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/tlbflush.h b/arch/powerpc/include/asm/book3s/64/tlbflush.h
index 2bbc0fcce04a..68f25977fff7 100644
--- a/arch/powerpc/include/asm/book3s/64/tlbflush.h
+++ b/arch/powerpc/include/asm/book3s/64/tlbflush.h
@@ -2,6 +2,7 @@
 #ifndef _ASM_POWERPC_BOOK3S_64_TLBFLUSH_H
 #define _ASM_POWERPC_BOOK3S_64_TLBFLUSH_H
 
+#include "asm/book3s/64/pgtable.h"
 #define MMU_NO_CONTEXT	~0UL
 
 #include <linux/mm_types.h>
@@ -148,6 +149,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 +170,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
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] powerpc/64s: Fix __pte_needs_flush() false positive warning
  2023-03-02 22:52 [PATCH] powerpc/64s: Fix __pte_needs_flush() false positive warning Benjamin Gray
@ 2023-03-02 23:01 ` Benjamin Gray
  0 siblings, 0 replies; 2+ messages in thread
From: Benjamin Gray @ 2023-03-02 23:01 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: npiggin, ruscur

Accidentally added a bad auto-import, V2 sent
https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20230302225947.81083-1-bgray@linux.ibm.com/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-02 23:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-02 22:52 [PATCH] powerpc/64s: Fix __pte_needs_flush() false positive warning Benjamin Gray
2023-03-02 23:01 ` Benjamin Gray

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).