diff mbox series

[RFC,2/5] mm/mprotect: minor can_change_pte_writable() cleanups

Message ID 20220926152618.194810-3-david@redhat.com (mailing list archive)
State New
Headers show
Series mm/autonuma: replace savedwrite infrastructure | expand

Commit Message

David Hildenbrand Sept. 26, 2022, 3:26 p.m. UTC
We want to replicate this code for handling PMDs soon. No need to crash
the kernel, warning and rejecting is good enough. As this will no longer
get optimized out, drop the pte_write() check: no harm would be done.

While at it, add a comment why PROT_NONE mapped pages are excluded.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 mm/mprotect.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/mm/mprotect.c b/mm/mprotect.c
index c6c13a0a4bcc..95323bc9a951 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -43,8 +43,10 @@  static inline bool can_change_pte_writable(struct vm_area_struct *vma,
 {
 	struct page *page;
 
-	VM_BUG_ON(!(vma->vm_flags & VM_WRITE) || pte_write(pte));
+	if (WARN_ON_ONCE(!(vma->vm_flags & VM_WRITE)))
+		return false;
 
+	/* Don't touch entries that are not even readable (NUMA hinting). */
 	if (pte_protnone(pte))
 		return false;