mm: Do not enable PG_arch_2 for all 64-bit architectures
authorCatalin Marinas <catalin.marinas@arm.com>
Fri, 4 Nov 2022 01:10:34 +0000 (18:10 -0700)
committerMarc Zyngier <maz@kernel.org>
Tue, 29 Nov 2022 09:26:06 +0000 (09:26 +0000)
Commit 4beba9486abd ("mm: Add PG_arch_2 page flag") introduced a new
page flag for all 64-bit architectures. However, even if an architecture
is 64-bit, it may still have limited spare bits in the 'flags' member of
'struct page'. This may happen if an architecture enables SPARSEMEM
without SPARSEMEM_VMEMMAP as is the case with the newly added loongarch.
This architecture port needs 19 more bits for the sparsemem section
information and, while it is currently fine with PG_arch_2, adding any
more PG_arch_* flags will trigger build-time warnings.

Add a new CONFIG_ARCH_USES_PG_ARCH_X option which can be selected by
architectures that need more PG_arch_* flags beyond PG_arch_1. Select it
on arm64.

Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
[pcc@google.com: fix build with CONFIG_ARM64_MTE disabled]
Signed-off-by: Peter Collingbourne <pcc@google.com>
Reported-by: kernel test robot <lkp@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Steven Price <steven.price@arm.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20221104011041.290951-2-pcc@google.com
arch/arm64/Kconfig
fs/proc/page.c
include/linux/page-flags.h
include/trace/events/mmflags.h
mm/Kconfig
mm/huge_memory.c

index 505c8a1..cd93d07 100644 (file)
@@ -1965,6 +1965,7 @@ config ARM64_MTE
        depends on ARM64_PAN
        select ARCH_HAS_SUBPAGE_FAULTS
        select ARCH_USES_HIGH_VMA_FLAGS
+       select ARCH_USES_PG_ARCH_X
        help
          Memory Tagging (part of the ARMv8.5 Extensions) provides
          architectural support for run-time, always-on detection of
index f2273b1..882525c 100644 (file)
@@ -219,7 +219,7 @@ u64 stable_page_flags(struct page *page)
        u |= kpf_copy_bit(k, KPF_PRIVATE_2,     PG_private_2);
        u |= kpf_copy_bit(k, KPF_OWNER_PRIVATE, PG_owner_priv_1);
        u |= kpf_copy_bit(k, KPF_ARCH,          PG_arch_1);
-#ifdef CONFIG_64BIT
+#ifdef CONFIG_ARCH_USES_PG_ARCH_X
        u |= kpf_copy_bit(k, KPF_ARCH_2,        PG_arch_2);
 #endif
 
index 0b0ae50..5dc7977 100644 (file)
@@ -132,7 +132,7 @@ enum pageflags {
        PG_young,
        PG_idle,
 #endif
-#ifdef CONFIG_64BIT
+#ifdef CONFIG_ARCH_USES_PG_ARCH_X
        PG_arch_2,
 #endif
 #ifdef CONFIG_KASAN_HW_TAGS
index e87cb2b..d9f6d35 100644 (file)
 #define IF_HAVE_PG_IDLE(flag,string)
 #endif
 
-#ifdef CONFIG_64BIT
-#define IF_HAVE_PG_ARCH_2(flag,string) ,{1UL << flag, string}
+#ifdef CONFIG_ARCH_USES_PG_ARCH_X
+#define IF_HAVE_PG_ARCH_X(flag,string) ,{1UL << flag, string}
 #else
-#define IF_HAVE_PG_ARCH_2(flag,string)
+#define IF_HAVE_PG_ARCH_X(flag,string)
 #endif
 
 #ifdef CONFIG_KASAN_HW_TAGS
@@ -130,7 +130,7 @@ IF_HAVE_PG_UNCACHED(PG_uncached,    "uncached"      )               \
 IF_HAVE_PG_HWPOISON(PG_hwpoison,       "hwpoison"      )               \
 IF_HAVE_PG_IDLE(PG_young,              "young"         )               \
 IF_HAVE_PG_IDLE(PG_idle,               "idle"          )               \
-IF_HAVE_PG_ARCH_2(PG_arch_2,           "arch_2"        )               \
+IF_HAVE_PG_ARCH_X(PG_arch_2,           "arch_2"        )               \
 IF_HAVE_PG_SKIP_KASAN_POISON(PG_skip_kasan_poison, "skip_kasan_poison")
 
 #define show_page_flags(flags)                                         \
index 57e1d8c..807bd71 100644 (file)
@@ -1005,6 +1005,14 @@ config ARCH_USES_HIGH_VMA_FLAGS
 config ARCH_HAS_PKEYS
        bool
 
+config ARCH_USES_PG_ARCH_X
+       bool
+       help
+         Enable the definition of PG_arch_x page flags with x > 1. Only
+         suitable for 64-bit architectures with CONFIG_FLATMEM or
+         CONFIG_SPARSEMEM_VMEMMAP enabled, otherwise there may not be
+         enough room for additional bits in page->flags.
+
 config VM_EVENT_COUNTERS
        default y
        bool "Enable VM event counters for /proc/vmstat" if EXPERT
index 561a425..76e7b97 100644 (file)
@@ -2444,7 +2444,7 @@ static void __split_huge_page_tail(struct page *head, int tail,
                         (1L << PG_workingset) |
                         (1L << PG_locked) |
                         (1L << PG_unevictable) |
-#ifdef CONFIG_64BIT
+#ifdef CONFIG_ARCH_USES_PG_ARCH_X
                         (1L << PG_arch_2) |
 #endif
                         (1L << PG_dirty) |