kernel: bump 5.15 to 5.15.125
[openwrt/openwrt.git] / target / linux / generic / backport-5.15 / 020-v6.1-02-mm-x86-add-CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG.patch
1 From 493de1c4b0f2cd909169401da8c445f6c8a7e29d Mon Sep 17 00:00:00 2001
2 From: Yu Zhao <yuzhao@google.com>
3 Date: Sun, 18 Sep 2022 01:59:59 -0600
4 Subject: [PATCH 02/29] mm: x86: add CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Some architectures support the accessed bit in non-leaf PMD entries, e.g.,
10 x86 sets the accessed bit in a non-leaf PMD entry when using it as part of
11 linear address translation [1]. Page table walkers that clear the
12 accessed bit may use this capability to reduce their search space.
13
14 Note that:
15 1. Although an inline function is preferable, this capability is added
16 as a configuration option for consistency with the existing macros.
17 2. Due to the little interest in other varieties, this capability was
18 only tested on Intel and AMD CPUs.
19
20 Thanks to the following developers for their efforts [2][3].
21 Randy Dunlap <rdunlap@infradead.org>
22 Stephen Rothwell <sfr@canb.auug.org.au>
23
24 [1]: Intel 64 and IA-32 Architectures Software Developer's Manual
25 Volume 3 (June 2021), section 4.8
26 [2] https://lore.kernel.org/r/bfdcc7c8-922f-61a9-aa15-7e7250f04af7@infradead.org/
27 [3] https://lore.kernel.org/r/20220413151513.5a0d7a7e@canb.auug.org.au/
28
29 Link: https://lkml.kernel.org/r/20220918080010.2920238-3-yuzhao@google.com
30 Signed-off-by: Yu Zhao <yuzhao@google.com>
31 Reviewed-by: Barry Song <baohua@kernel.org>
32 Acked-by: Brian Geffon <bgeffon@google.com>
33 Acked-by: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
34 Acked-by: Oleksandr Natalenko <oleksandr@natalenko.name>
35 Acked-by: Steven Barrett <steven@liquorix.net>
36 Acked-by: Suleiman Souhlal <suleiman@google.com>
37 Tested-by: Daniel Byrne <djbyrne@mtu.edu>
38 Tested-by: Donald Carr <d@chaos-reins.com>
39 Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
40 Tested-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
41 Tested-by: Shuang Zhai <szhai2@cs.rochester.edu>
42 Tested-by: Sofia Trinh <sofia.trinh@edi.works>
43 Tested-by: Vaibhav Jain <vaibhav@linux.ibm.com>
44 Cc: Andi Kleen <ak@linux.intel.com>
45 Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
46 Cc: Catalin Marinas <catalin.marinas@arm.com>
47 Cc: Dave Hansen <dave.hansen@linux.intel.com>
48 Cc: Hillf Danton <hdanton@sina.com>
49 Cc: Jens Axboe <axboe@kernel.dk>
50 Cc: Johannes Weiner <hannes@cmpxchg.org>
51 Cc: Jonathan Corbet <corbet@lwn.net>
52 Cc: Linus Torvalds <torvalds@linux-foundation.org>
53 Cc: Matthew Wilcox <willy@infradead.org>
54 Cc: Mel Gorman <mgorman@suse.de>
55 Cc: Miaohe Lin <linmiaohe@huawei.com>
56 Cc: Michael Larabel <Michael@MichaelLarabel.com>
57 Cc: Michal Hocko <mhocko@kernel.org>
58 Cc: Mike Rapoport <rppt@kernel.org>
59 Cc: Mike Rapoport <rppt@linux.ibm.com>
60 Cc: Peter Zijlstra <peterz@infradead.org>
61 Cc: Qi Zheng <zhengqi.arch@bytedance.com>
62 Cc: Tejun Heo <tj@kernel.org>
63 Cc: Vlastimil Babka <vbabka@suse.cz>
64 Cc: Will Deacon <will@kernel.org>
65 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
66 ---
67 arch/Kconfig | 8 ++++++++
68 arch/x86/Kconfig | 1 +
69 arch/x86/include/asm/pgtable.h | 3 ++-
70 arch/x86/mm/pgtable.c | 5 ++++-
71 include/linux/pgtable.h | 4 ++--
72 5 files changed, 17 insertions(+), 4 deletions(-)
73
74 --- a/arch/Kconfig
75 +++ b/arch/Kconfig
76 @@ -1298,6 +1298,14 @@ config ARCH_HAS_ELFCORE_COMPAT
77 config ARCH_HAS_PARANOID_L1D_FLUSH
78 bool
79
80 +config ARCH_HAS_NONLEAF_PMD_YOUNG
81 + bool
82 + help
83 + Architectures that select this option are capable of setting the
84 + accessed bit in non-leaf PMD entries when using them as part of linear
85 + address translations. Page table walkers that clear the accessed bit
86 + may use this capability to reduce their search space.
87 +
88 source "kernel/gcov/Kconfig"
89
90 source "scripts/gcc-plugins/Kconfig"
91 --- a/arch/x86/Kconfig
92 +++ b/arch/x86/Kconfig
93 @@ -85,6 +85,7 @@ config X86
94 select ARCH_HAS_PMEM_API if X86_64
95 select ARCH_HAS_PTE_DEVMAP if X86_64
96 select ARCH_HAS_PTE_SPECIAL
97 + select ARCH_HAS_NONLEAF_PMD_YOUNG if PGTABLE_LEVELS > 2
98 select ARCH_HAS_UACCESS_FLUSHCACHE if X86_64
99 select ARCH_HAS_COPY_MC if X86_64
100 select ARCH_HAS_SET_MEMORY
101 --- a/arch/x86/include/asm/pgtable.h
102 +++ b/arch/x86/include/asm/pgtable.h
103 @@ -817,7 +817,8 @@ static inline unsigned long pmd_page_vad
104
105 static inline int pmd_bad(pmd_t pmd)
106 {
107 - return (pmd_flags(pmd) & ~_PAGE_USER) != _KERNPG_TABLE;
108 + return (pmd_flags(pmd) & ~(_PAGE_USER | _PAGE_ACCESSED)) !=
109 + (_KERNPG_TABLE & ~_PAGE_ACCESSED);
110 }
111
112 static inline unsigned long pages_to_mb(unsigned long npg)
113 --- a/arch/x86/mm/pgtable.c
114 +++ b/arch/x86/mm/pgtable.c
115 @@ -550,7 +550,7 @@ int ptep_test_and_clear_young(struct vm_
116 return ret;
117 }
118
119 -#ifdef CONFIG_TRANSPARENT_HUGEPAGE
120 +#if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG)
121 int pmdp_test_and_clear_young(struct vm_area_struct *vma,
122 unsigned long addr, pmd_t *pmdp)
123 {
124 @@ -562,6 +562,9 @@ int pmdp_test_and_clear_young(struct vm_
125
126 return ret;
127 }
128 +#endif
129 +
130 +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
131 int pudp_test_and_clear_young(struct vm_area_struct *vma,
132 unsigned long addr, pud_t *pudp)
133 {
134 --- a/include/linux/pgtable.h
135 +++ b/include/linux/pgtable.h
136 @@ -212,7 +212,7 @@ static inline int ptep_test_and_clear_yo
137 #endif
138
139 #ifndef __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
140 -#ifdef CONFIG_TRANSPARENT_HUGEPAGE
141 +#if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG)
142 static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
143 unsigned long address,
144 pmd_t *pmdp)
145 @@ -233,7 +233,7 @@ static inline int pmdp_test_and_clear_yo
146 BUILD_BUG();
147 return 0;
148 }
149 -#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
150 +#endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG */
151 #endif
152
153 #ifndef __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH