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

mm: change vm_get_page_prot() to accept vm_flags_t argument

Patch series "use vm_flags_t consistently".

The VMA flags field vma->vm_flags is of type vm_flags_t. Right now this
is exactly equivalent to unsigned long, but it should not be assumed to
be.

Much code that references vma->vm_flags already correctly uses vm_flags_t,
but a fairly large chunk of code simply uses unsigned long and assumes
that the two are equivalent.

This series corrects that and has us use vm_flags_t consistently.

This series is motivated by the desire to, in a future series, adjust
vm_flags_t to be a u64 regardless of whether the kernel is 32-bit or
64-bit in order to deal with the VMA flag exhaustion issue and avoid all
the various problems that arise from it (being unable to use certain
features in 32-bit, being unable to add new flags except for 64-bit, etc.)

This is therefore a critical first step towards that goal. At any rate,
using the correct type is of value regardless.

We additionally take the opportunity to refer to VMA flags as vm_flags
where possible to make clear what we're referring to.

Overall, this series does not introduce any functional change.


This patch (of 3):

We abstract the type of the VMA flags to vm_flags_t, however in may places
it is simply assumed this is unsigned long, which is simply incorrect.

At the moment this is simply an incongruity, however in future we plan to
change this type and therefore this change is a critical requirement for
doing so.

Overall, this patch does not introduce any functional change.

[lorenzo.stoakes@oracle.com: add missing vm_get_page_prot() instance, remove include]
Link: https://lkml.kernel.org/r/552f88e1-2df8-4e95-92b8-812f7c8db829@lucifer.local
Link: https://lkml.kernel.org/r/cover.1750274467.git.lorenzo.stoakes@oracle.com
Link: https://lkml.kernel.org/r/a12769720a2743f235643b158c4f4f0a9911daf0.1750274467.git.lorenzo.stoakes@oracle.com
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Acked-by: Christian Brauner <brauner@kernel.org>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: Oscar Salvador <osalvador@suse.de>
Reviewed-by: Pedro Falcato <pfalcato@suse.de>
Acked-by: Catalin Marinas <catalin.marinas@arm.com> [arm64]
Acked-by: Zi Yan <ziy@nvidia.com>
Acked-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Jann Horn <jannh@google.com>
Cc: Kees Cook <kees@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Lorenzo Stoakes and committed by
Andrew Morton
78ddaa35 e1b1fe45

+9 -9
+1 -1
arch/arm64/mm/mmap.c
··· 81 81 } 82 82 arch_initcall(adjust_protection_map); 83 83 84 - pgprot_t vm_get_page_prot(unsigned long vm_flags) 84 + pgprot_t vm_get_page_prot(vm_flags_t vm_flags) 85 85 { 86 86 ptdesc_t prot; 87 87
+1 -1
arch/powerpc/include/asm/book3s/64/pkeys.h
··· 5 5 6 6 #include <asm/book3s/64/hash-pkey.h> 7 7 8 - static inline u64 vmflag_to_pte_pkey_bits(u64 vm_flags) 8 + static inline u64 vmflag_to_pte_pkey_bits(vm_flags_t vm_flags) 9 9 { 10 10 if (!mmu_has_feature(MMU_FTR_PKEY)) 11 11 return 0x0UL;
+1 -1
arch/powerpc/mm/book3s64/pgtable.c
··· 644 644 EXPORT_SYMBOL_GPL(memremap_compat_align); 645 645 #endif 646 646 647 - pgprot_t vm_get_page_prot(unsigned long vm_flags) 647 + pgprot_t vm_get_page_prot(vm_flags_t vm_flags) 648 648 { 649 649 unsigned long prot; 650 650
+1 -1
arch/sparc/mm/init_64.c
··· 3201 3201 } 3202 3202 EXPORT_SYMBOL(copy_highpage); 3203 3203 3204 - pgprot_t vm_get_page_prot(unsigned long vm_flags) 3204 + pgprot_t vm_get_page_prot(vm_flags_t vm_flags) 3205 3205 { 3206 3206 unsigned long prot = pgprot_val(protection_map[vm_flags & 3207 3207 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]);
+1 -1
arch/x86/mm/pgprot.c
··· 32 32 protection_map[i] = pgprot_encrypted(protection_map[i]); 33 33 } 34 34 35 - pgprot_t vm_get_page_prot(unsigned long vm_flags) 35 + pgprot_t vm_get_page_prot(vm_flags_t vm_flags) 36 36 { 37 37 unsigned long val = pgprot_val(protection_map[vm_flags & 38 38 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]);
+2 -2
include/linux/mm.h
··· 3489 3489 } 3490 3490 3491 3491 #ifdef CONFIG_MMU 3492 - pgprot_t vm_get_page_prot(unsigned long vm_flags); 3492 + pgprot_t vm_get_page_prot(vm_flags_t vm_flags); 3493 3493 void vma_set_page_prot(struct vm_area_struct *vma); 3494 3494 #else 3495 - static inline pgprot_t vm_get_page_prot(unsigned long vm_flags) 3495 + static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags) 3496 3496 { 3497 3497 return __pgprot(0); 3498 3498 }
+1 -1
include/linux/pgtable.h
··· 2016 2016 * x: (yes) yes 2017 2017 */ 2018 2018 #define DECLARE_VM_GET_PAGE_PROT \ 2019 - pgprot_t vm_get_page_prot(unsigned long vm_flags) \ 2019 + pgprot_t vm_get_page_prot(vm_flags_t vm_flags) \ 2020 2020 { \ 2021 2021 return protection_map[vm_flags & \ 2022 2022 (VM_READ | VM_WRITE | VM_EXEC | VM_SHARED)]; \
+1 -1
tools/testing/vma/vma_internal.h
··· 576 576 return __pgprot(pgprot_val(oldprot) | pgprot_val(newprot)); 577 577 } 578 578 579 - static inline pgprot_t vm_get_page_prot(unsigned long vm_flags) 579 + static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags) 580 580 { 581 581 return __pgprot(vm_flags); 582 582 }