]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm: change vm_get_page_prot() to accept vm_flags_t argument
authorLorenzo Stoakes <lorenzo.stoakes@oracle.com>
Wed, 18 Jun 2025 19:42:52 +0000 (20:42 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 10 Jul 2025 05:42:13 +0000 (22:42 -0700)
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>
arch/arm64/mm/mmap.c
arch/powerpc/include/asm/book3s/64/pkeys.h
arch/powerpc/mm/book3s64/pgtable.c
arch/sparc/mm/init_64.c
arch/x86/mm/pgprot.c
include/linux/mm.h
include/linux/pgtable.h
tools/testing/vma/vma_internal.h

index c86c348857c405ee138970511649e161b3ec2fca..08ee177432c2f7492c921d9bd56e302d464a1e0c 100644 (file)
@@ -81,7 +81,7 @@ static int __init adjust_protection_map(void)
 }
 arch_initcall(adjust_protection_map);
 
-pgprot_t vm_get_page_prot(unsigned long vm_flags)
+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
 {
        ptdesc_t prot;
 
index 5b178139f3c08a00e84a9571c1919aa72c864b2c..ff911b4251d970523e15dedfc82af527fa6a10f1 100644 (file)
@@ -5,7 +5,7 @@
 
 #include <asm/book3s/64/hash-pkey.h>
 
-static inline u64 vmflag_to_pte_pkey_bits(u64 vm_flags)
+static inline u64 vmflag_to_pte_pkey_bits(vm_flags_t vm_flags)
 {
        if (!mmu_has_feature(MMU_FTR_PKEY))
                return 0x0UL;
index 0db01e10a3f842bc622ab654a7044a8e2259eef3..a89ef89101fc6bf6a947446c833547adfecc6599 100644 (file)
@@ -644,7 +644,7 @@ unsigned long memremap_compat_align(void)
 EXPORT_SYMBOL_GPL(memremap_compat_align);
 #endif
 
-pgprot_t vm_get_page_prot(unsigned long vm_flags)
+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
 {
        unsigned long prot;
 
index 25ae4c897aae763c504272a5f347c554a3351ff1..7ed58bf3aacaa46e5300bc743e9b73c881fa56cd 100644 (file)
@@ -3201,7 +3201,7 @@ void copy_highpage(struct page *to, struct page *from)
 }
 EXPORT_SYMBOL(copy_highpage);
 
-pgprot_t vm_get_page_prot(unsigned long vm_flags)
+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
 {
        unsigned long prot = pgprot_val(protection_map[vm_flags &
                                        (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]);
index c84bd9540b163dbcda2f34ed3644bfc661e4ae82..dc1afd5c839de0af43498191e64ba415c5268d38 100644 (file)
@@ -32,7 +32,7 @@ void add_encrypt_protection_map(void)
                protection_map[i] = pgprot_encrypted(protection_map[i]);
 }
 
-pgprot_t vm_get_page_prot(unsigned long vm_flags)
+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
 {
        unsigned long val = pgprot_val(protection_map[vm_flags &
                                      (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]);
index b7e2abd8ce0dfb58f0a796bca712ccf237074bf6..78bb177ba55f6f5d5362a69cdc70c38c347687a1 100644 (file)
@@ -3489,10 +3489,10 @@ static inline bool range_in_vma(struct vm_area_struct *vma,
 }
 
 #ifdef CONFIG_MMU
-pgprot_t vm_get_page_prot(unsigned long vm_flags);
+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
 void vma_set_page_prot(struct vm_area_struct *vma);
 #else
-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
 {
        return __pgprot(0);
 }
index e4a3895c043be9b8f07f22d5129e80832047f45b..d05e35a0facffcb28d3c86bbf34db9db3e2c8bef 100644 (file)
@@ -2016,7 +2016,7 @@ typedef unsigned int pgtbl_mod_mask;
  *                                                             x: (yes) yes
  */
 #define DECLARE_VM_GET_PAGE_PROT                                       \
-pgprot_t vm_get_page_prot(unsigned long vm_flags)                      \
+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)                         \
 {                                                                      \
                return protection_map[vm_flags &                        \
                        (VM_READ | VM_WRITE | VM_EXEC | VM_SHARED)];    \
index 0f013784da897e68ef1e54973aacbba814d7615d..3b1b45256d5628593724e5f13a1fb1c98a35b0c1 100644 (file)
@@ -576,7 +576,7 @@ static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
        return __pgprot(pgprot_val(oldprot) | pgprot_val(newprot));
 }
 
-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
 {
        return __pgprot(vm_flags);
 }