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

x86: remove custom definition of mk_pte()

Move the shadow stack check to pfn_pte() which lets us use the common
definition of mk_pte().

Link: https://lkml.kernel.org/r/20250402181709.2386022-5-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Richard Weinberger <richard@nod.at>
Cc: <x86@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Matthew Wilcox (Oracle) and committed by
Andrew Morton
a03079e4 aec44171

+3 -16
+3 -16
arch/x86/include/asm/pgtable.h
··· 784 784 static inline pte_t pfn_pte(unsigned long page_nr, pgprot_t pgprot) 785 785 { 786 786 phys_addr_t pfn = (phys_addr_t)page_nr << PAGE_SHIFT; 787 + /* This bit combination is used to mark shadow stacks */ 788 + WARN_ON_ONCE((pgprot_val(pgprot) & (_PAGE_DIRTY | _PAGE_RW)) == 789 + _PAGE_DIRTY); 787 790 pfn ^= protnone_mask(pgprot_val(pgprot)); 788 791 pfn &= PTE_PFN_MASK; 789 792 return __pte(pfn | check_pgprot(pgprot)); ··· 1082 1079 * linux/mmzone.h's __section_mem_map_addr() definition: 1083 1080 */ 1084 1081 #define pmd_page(pmd) pfn_to_page(pmd_pfn(pmd)) 1085 - 1086 - /* 1087 - * Conversion functions: convert a page and protection to a page entry, 1088 - * and a page entry and page directory to the page they refer to. 1089 - * 1090 - * (Currently stuck as a macro because of indirect forward reference 1091 - * to linux/mm.h:page_to_nid()) 1092 - */ 1093 - #define mk_pte(page, pgprot) \ 1094 - ({ \ 1095 - pgprot_t __pgprot = pgprot; \ 1096 - \ 1097 - WARN_ON_ONCE((pgprot_val(__pgprot) & (_PAGE_DIRTY | _PAGE_RW)) == \ 1098 - _PAGE_DIRTY); \ 1099 - pfn_pte(page_to_pfn(page), __pgprot); \ 1100 - }) 1101 1082 1102 1083 static inline int pmd_bad(pmd_t pmd) 1103 1084 {