mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [tip: x86/mm] x86/mm: Clear _PAGE_DIRTY when we clear _PAGE_RW
@ 2025-02-25 20:10 tip-bot2 for Matthew Wilcox (Oracle)
  2025-02-25 21:07 ` Linus Torvalds
  2025-02-27  9:04 ` [tip: x86/mm] x86/mm: Clear _PAGE_DIRTY for kernel mappings " tip-bot2 for Matthew Wilcox (Oracle)
  0 siblings, 2 replies; 9+ messages in thread
From: tip-bot2 for Matthew Wilcox (Oracle) @ 2025-02-25 20:10 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: kernel test robot, Matthew Wilcox (Oracle),
	Ingo Molnar, Linus Torvalds, x86, linux-kernel

The following commit has been merged into the x86/mm branch of tip:

Commit-ID:     d75a256b6a64132fc7aab57ad4c96218e3ae383b
Gitweb:        https://git.kernel.org/tip/d75a256b6a64132fc7aab57ad4c96218e3ae383b
Author:        Matthew Wilcox (Oracle) <willy@infradead.org>
AuthorDate:    Tue, 25 Feb 2025 19:37:32 
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 25 Feb 2025 20:59:32 +01:00

x86/mm: Clear _PAGE_DIRTY when we clear _PAGE_RW

The bit pattern of _PAGE_DIRTY set and _PAGE_RW clear is used to
mark shadow stacks.  This is currently checked for in mk_pte() but
not pfn_pte().  If we add the check to pfn_pte(), it catches vfree()
calling set_direct_map_invalid_noflush() which calls __change_page_attr()
which loads the old protection bits from the PTE, clears the specified
bits and uses pfn_pte() to construct the new PTE.

We should, therefore, clear the _PAGE_DIRTY bit whenever we clear
_PAGE_RW.  I opted to do it in the callers in case we want to use
__change_page_attr() to create shadow stacks inside the kernel at some
point in the future.  Arguably, we might also want to clear _PAGE_ACCESSED
here.

Reported-by: kernel test robot <oliver.sang@intel.com>
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Closes: https://lore.kernel.org/oe-lkp/202502241646.719f4651-lkp@intel.com
---
 arch/x86/mm/pat/set_memory.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
index 84d0bca..d174015 100644
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -2628,7 +2628,7 @@ static int __set_pages_np(struct page *page, int numpages)
 				.pgd = NULL,
 				.numpages = numpages,
 				.mask_set = __pgprot(0),
-				.mask_clr = __pgprot(_PAGE_PRESENT | _PAGE_RW),
+				.mask_clr = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY),
 				.flags = CPA_NO_CHECK_ALIAS };
 
 	/*
@@ -2715,7 +2715,7 @@ int __init kernel_map_pages_in_pgd(pgd_t *pgd, u64 pfn, unsigned long address,
 		.pgd = pgd,
 		.numpages = numpages,
 		.mask_set = __pgprot(0),
-		.mask_clr = __pgprot(~page_flags & (_PAGE_NX|_PAGE_RW)),
+		.mask_clr = __pgprot(~page_flags & (_PAGE_NX|_PAGE_RW|_PAGE_DIRTY)),
 		.flags = CPA_NO_CHECK_ALIAS,
 	};
 
@@ -2758,7 +2758,7 @@ int __init kernel_unmap_pages_in_pgd(pgd_t *pgd, unsigned long address,
 		.pgd		= pgd,
 		.numpages	= numpages,
 		.mask_set	= __pgprot(0),
-		.mask_clr	= __pgprot(_PAGE_PRESENT | _PAGE_RW),
+		.mask_clr	= __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY),
 		.flags		= CPA_NO_CHECK_ALIAS,
 	};
 

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

end of thread, other threads:[~2025-02-27  9:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-25 20:10 [tip: x86/mm] x86/mm: Clear _PAGE_DIRTY when we clear _PAGE_RW tip-bot2 for Matthew Wilcox (Oracle)
2025-02-25 21:07 ` Linus Torvalds
2025-02-26  2:45   ` Matthew Wilcox
2025-02-26  3:31     ` Linus Torvalds
2025-02-26  4:00       ` Matthew Wilcox
2025-02-26  4:06         ` Linus Torvalds
2025-02-26 10:55           ` Ingo Molnar
2025-02-26 19:46             ` Linus Torvalds
2025-02-27  9:04 ` [tip: x86/mm] x86/mm: Clear _PAGE_DIRTY for kernel mappings " tip-bot2 for Matthew Wilcox (Oracle)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®