History

Merge tag 'mm-hotfixes-stable-2024-04-26-13-30' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Pull misc fixes from Andrew Morton: "11 hotfixes. 8 are cc:stable and the remaining 3 (nice ratio!) address post-6.8 issues or aren't considered suitable for backporting. All except one of these are for MM. I see no particular theme - it's singletons all over" * tag 'mm-hotfixes-stable-2024-04-26-13-30' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: mm/hugetlb: fix DEBUG_LOCKS_WARN_ON(1) when dissolve_free_hugetlb_folio() selftests: mm: protection_keys: save/restore nr_hugepages value from launch script stackdepot: respect __GFP_NOLOCKDEP allocation flag hugetlb: check for anon_vma prior to folio allocation mm: zswap: fix shrinker NULL crash with cgroup_disable=memory mm: turn folio_test_hugetlb into a PageType mm: support page_mapcount() on page_has_type() pages mm: create FOLIO_FLAG_FALSE and FOLIO_TYPE_OPS macros mm/hugetlb: fix missing hugetlb_lock for resv uncharge selftests: mm: fix unused and uninitialized variable warning selftests/harness: remove use of LINE_MAX

Linus Torvalds committed 2 years ago

Commit e6ebf012 parents 4630932 52ccdde13 files · +137 −152Browse files

Unified · Split

13 files
  1. fs/proc/page.c +2 −5
  2. include/linux/mm.h +5 −3
  3. include/linux/page-flags.h +82 −62
  4. include/trace/events/mmflags.h +1 −0
  5. kernel/vmcore_info.c +2 −3
  6. lib/stackdepot.c +2 −2
  7. mm/hugetlb.c +15 −25
  8. mm/zswap.c +16 −9
  9. tools/testing/selftests/kselftest_harness.h +8 −4
  10. tools/testing/selftests/mm/mdwe_test.c +1 −0
  11. tools/testing/selftests/mm/protection_keys.c +0 −38
  12. tools/testing/selftests/mm/run_vmtests.sh +2 −0
  13. tools/testing/selftests/mm/split_huge_page_test.c +1 −1
fs/proc/page.c+2−5
@@ -67,7 +67,7 @@ static ssize_t kpagecount_read(struct file *file, char __user *buf, · 66 unmodified lines
6767 */
6868 ppage = pfn_to_online_page(pfn);
6969
70− if (!ppage || PageSlab(ppage) || page_has_type(ppage))
70+ if (!ppage)
7171 pcount = 0;
7272 else
7373 pcount = page_mapcount(ppage);
@@ -124,11 +124,8 @@ u64 stable_page_flags(struct page *page) · 50 unmodified lines
124124
125125 /*
126126 * pseudo flags for the well known (anonymous) memory mapped pages
127− *
128− * Note that page->_mapcount is overloaded in SLAB, so the
129− * simple test in page_mapped() is not enough.
130127 */
131− if (!PageSlab(page) && page_mapped(page))
128+ if (page_mapped(page))
132129 u |= 1 << KPF_MMAP;
133130 if (PageAnon(page))
134131 u |= 1 << KPF_ANON;
include/linux/mm.h+5−3
@@ -1223,14 +1223,16 @@ static inline void page_mapcount_reset(struct page *page) · 1222 unmodified lines
12231223 * a large folio, it includes the number of times this page is mapped
12241224 * as part of that folio.
12251225 *
1226− * The result is undefined for pages which cannot be mapped into userspace.
1227− * For example SLAB or special types of pages. See function page_has_type().
1228− * They use this field in struct page differently.
1226+ * Will report 0 for pages which cannot be mapped into userspace, eg
1227+ * slab, page tables and similar.
12291228 */
12301229 static inline int page_mapcount(struct page *page)
12311230 {
12321231 int mapcount = atomic_read(&page->_mapcount) + 1;
12331232
1233+ /* Handle page_has_type() pages */
1234+ if (mapcount < 0)
1235+ mapcount = 0;
12341236 if (unlikely(PageCompound(page)))
12351237 mapcount += folio_entire_mapcount(page_folio(page));
12361238
include/linux/page-flags.h+82−62
@@ -190,7 +190,6 @@ enum pageflags { · 189 unmodified lines
190190
191191 /* At least one page in this folio has the hwpoison flag set */
192192 PG_has_hwpoisoned = PG_error,
193− PG_hugetlb = PG_active,
194193 PG_large_rmappable = PG_workingset, /* anon or file-backed */
195194 };
196195
@@ -458,30 +457,51 @@ static __always_inline int TestClearPage##uname(struct page *page) \ · 261 unmodified lines
458457 TESTSETFLAG(uname, lname, policy) \
459458 TESTCLEARFLAG(uname, lname, policy)
460459
460+#define FOLIO_TEST_FLAG_FALSE(name) \
461+static inline bool folio_test_##name(const struct folio *folio) \
462+{ return false; }
463+#define FOLIO_SET_FLAG_NOOP(name) \
464+static inline void folio_set_##name(struct folio *folio) { }
465+#define FOLIO_CLEAR_FLAG_NOOP(name) \
466+static inline void folio_clear_##name(struct folio *folio) { }
467+#define __FOLIO_SET_FLAG_NOOP(name) \
468+static inline void __folio_set_##name(struct folio *folio) { }
469+#define __FOLIO_CLEAR_FLAG_NOOP(name) \
470+static inline void __folio_clear_##name(struct folio *folio) { }
471+#define FOLIO_TEST_SET_FLAG_FALSE(name) \
472+static inline bool folio_test_set_##name(struct folio *folio) \
473+{ return false; }
474+#define FOLIO_TEST_CLEAR_FLAG_FALSE(name) \
475+static inline bool folio_test_clear_##name(struct folio *folio) \
476+{ return false; }
477+
478+#define FOLIO_FLAG_FALSE(name) \
479+FOLIO_TEST_FLAG_FALSE(name) \
480+FOLIO_SET_FLAG_NOOP(name) \
481+FOLIO_CLEAR_FLAG_NOOP(name)
482+
461483 #define TESTPAGEFLAG_FALSE(uname, lname) \
462−static inline bool folio_test_##lname(const struct folio *folio) { return false; } \
484+FOLIO_TEST_FLAG_FALSE(lname) \
463485 static inline int Page##uname(const struct page *page) { return 0; }
464486
465487 #define SETPAGEFLAG_NOOP(uname, lname) \
466−static inline void folio_set_##lname(struct folio *folio) { } \
488+FOLIO_SET_FLAG_NOOP(lname) \
467489 static inline void SetPage##uname(struct page *page) { }
468490
469491 #define CLEARPAGEFLAG_NOOP(uname, lname) \
470−static inline void folio_clear_##lname(struct folio *folio) { } \
492+FOLIO_CLEAR_FLAG_NOOP(lname) \
471493 static inline void ClearPage##uname(struct page *page) { }
472494
473495 #define __CLEARPAGEFLAG_NOOP(uname, lname) \
474−static inline void __folio_clear_##lname(struct folio *folio) { } \
496+__FOLIO_CLEAR_FLAG_NOOP(lname) \
475497 static inline void __ClearPage##uname(struct page *page) { }
476498
477499 #define TESTSETFLAG_FALSE(uname, lname) \
478−static inline bool folio_test_set_##lname(struct folio *folio) \
479−{ return 0; } \
500+FOLIO_TEST_SET_FLAG_FALSE(lname) \
480501 static inline int TestSetPage##uname(struct page *page) { return 0; }
481502
482503 #define TESTCLEARFLAG_FALSE(uname, lname) \
483−static inline bool folio_test_clear_##lname(struct folio *folio) \
484−{ return 0; } \
504+FOLIO_TEST_CLEAR_FLAG_FALSE(lname) \
485505 static inline int TestClearPage##uname(struct page *page) { return 0; }
486506
487507 #define PAGEFLAG_FALSE(uname, lname) TESTPAGEFLAG_FALSE(uname, lname) \
@@ -855,29 +875,6 @@ TESTPAGEFLAG_FALSE(LargeRmappable, large_rmappable) · 367 unmodified lines
855875
856876 #define PG_head_mask ((1UL << PG_head))
857877
858−#ifdef CONFIG_HUGETLB_PAGE
859−int PageHuge(const struct page *page);
860−SETPAGEFLAG(HugeTLB, hugetlb, PF_SECOND)
861−CLEARPAGEFLAG(HugeTLB, hugetlb, PF_SECOND)
862−
863−/**
864− * folio_test_hugetlb - Determine if the folio belongs to hugetlbfs
865− * @folio: The folio to test.
866− *
867− * Context: Any context. Caller should have a reference on the folio to
868− * prevent it from being turned into a tail page.
869− * Return: True for hugetlbfs folios, false for anon folios or folios
870− * belonging to other filesystems.
871− */
872−static inline bool folio_test_hugetlb(const struct folio *folio)
873−{
874− return folio_test_large(folio) &&
875− test_bit(PG_hugetlb, const_folio_flags(folio, 1));
876−}
877−#else
878−TESTPAGEFLAG_FALSE(Huge, hugetlb)
879−#endif
880−
881878 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
882879 /*
883880 * PageHuge() only returns true for hugetlbfs pages, but not for
@@ -933,34 +930,23 @@ PAGEFLAG_FALSE(HasHWPoisoned, has_hwpoisoned) · 49 unmodified lines
933930 TESTSCFLAG_FALSE(HasHWPoisoned, has_hwpoisoned)
934931 #endif
935932
936−/*
937− * Check if a page is currently marked HWPoisoned. Note that this check is
938− * best effort only and inherently racy: there is no way to synchronize with
939− * failing hardware.
940− */
941−static inline bool is_page_hwpoison(struct page *page)
942−{
943− if (PageHWPoison(page))
944− return true;
945− return PageHuge(page) && PageHWPoison(compound_head(page));
946−}
947−
948933 /*
949934 * For pages that are never mapped to userspace (and aren't PageSlab),
950935 * page_type may be used. Because it is initialised to -1, we invert the
951936 * sense of the bit, so __SetPageFoo *clears* the bit used for PageFoo, and
952937 * __ClearPageFoo *sets* the bit used for PageFoo. We reserve a few high and
953− * low bits so that an underflow or overflow of page_mapcount() won't be
938+ * low bits so that an underflow or overflow of _mapcount won't be
954939 * mistaken for a page type value.
955940 */
956941
957942 #define PAGE_TYPE_BASE 0xf0000000
958−/* Reserve 0x0000007f to catch underflows of page_mapcount */
943+/* Reserve 0x0000007f to catch underflows of _mapcount */
959944 #define PAGE_MAPCOUNT_RESERVE -128
960945 #define PG_buddy 0x00000080
961946 #define PG_offline 0x00000100
962947 #define PG_table 0x00000200
963948 #define PG_guard 0x00000400
949+#define PG_hugetlb 0x00000800
964950
965951 #define PageType(page, flag) \
966952 ((page->page_type & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE)
@@ -977,35 +963,38 @@ static inline int page_has_type(const struct page *page) · 10 unmodified lines
977963 return page_type_has_type(page->page_type);
978964 }
979965
966+#define FOLIO_TYPE_OPS(lname, fname) \
967+static __always_inline bool folio_test_##fname(const struct folio *folio)\
968+{ \
969+ return folio_test_type(folio, PG_##lname); \
970+} \
971+static __always_inline void __folio_set_##fname(struct folio *folio) \
972+{ \
973+ VM_BUG_ON_FOLIO(!folio_test_type(folio, 0), folio); \
974+ folio->page.page_type &= ~PG_##lname; \
975+} \
976+static __always_inline void __folio_clear_##fname(struct folio *folio) \
977+{ \
978+ VM_BUG_ON_FOLIO(!folio_test_##fname(folio), folio); \
979+ folio->page.page_type |= PG_##lname; \
980+}
981+
980982 #define PAGE_TYPE_OPS(uname, lname, fname) \
983+FOLIO_TYPE_OPS(lname, fname) \
981984 static __always_inline int Page##uname(const struct page *page) \
982985 { \
983986 return PageType(page, PG_##lname); \
984987 } \
985−static __always_inline int folio_test_##fname(const struct folio *folio)\
986−{ \
987− return folio_test_type(folio, PG_##lname); \
988−} \
989988 static __always_inline void __SetPage##uname(struct page *page) \
990989 { \
991990 VM_BUG_ON_PAGE(!PageType(page, 0), page); \
992991 page->page_type &= ~PG_##lname; \
993992 } \
994−static __always_inline void __folio_set_##fname(struct folio *folio) \
995−{ \
996− VM_BUG_ON_FOLIO(!folio_test_type(folio, 0), folio); \
997− folio->page.page_type &= ~PG_##lname; \
998−} \
999993 static __always_inline void __ClearPage##uname(struct page *page) \
1000994 { \
1001995 VM_BUG_ON_PAGE(!Page##uname(page), page); \
1002996 page->page_type |= PG_##lname; \
1003−} \
1004−static __always_inline void __folio_clear_##fname(struct folio *folio) \
1005−{ \
1006− VM_BUG_ON_FOLIO(!folio_test_##fname(folio), folio); \
1007− folio->page.page_type |= PG_##lname; \
1008−} \
997+}
1009998
1010999 /*
10111000 * PageBuddy() indicates that the page is free and in the buddy system
@@ -1052,6 +1041,37 @@ PAGE_TYPE_OPS(Table, table, pgtable) · 40 unmodified lines
10521041 */
10531042 PAGE_TYPE_OPS(Guard, guard, guard)
10541043
1044+#ifdef CONFIG_HUGETLB_PAGE
1045+FOLIO_TYPE_OPS(hugetlb, hugetlb)
1046+#else
1047+FOLIO_TEST_FLAG_FALSE(hugetlb)
1048+#endif
1049+
1050+/**
1051+ * PageHuge - Determine if the page belongs to hugetlbfs
1052+ * @page: The page to test.
1053+ *
1054+ * Context: Any context.
1055+ * Return: True for hugetlbfs pages, false for anon pages or pages
1056+ * belonging to other filesystems.
1057+ */
1058+static inline bool PageHuge(const struct page *page)
1059+{
1060+ return folio_test_hugetlb(page_folio(page));
1061+}
1062+
1063+/*
1064+ * Check if a page is currently marked HWPoisoned. Note that this check is
1065+ * best effort only and inherently racy: there is no way to synchronize with
1066+ * failing hardware.
1067+ */
1068+static inline bool is_page_hwpoison(struct page *page)
1069+{
1070+ if (PageHWPoison(page))
1071+ return true;
1072+ return PageHuge(page) && PageHWPoison(compound_head(page));
1073+}
1074+
10551075 extern bool is_free_buddy_page(struct page *page);
10561076
10571077 PAGEFLAG(Isolated, isolated, PF_ANY);
@@ -1118,7 +1138,7 @@ static __always_inline void __ClearPageAnonExclusive(struct page *page) · 60 unmodified lines
11181138 */
11191139 #define PAGE_FLAGS_SECOND \
11201140 (0xffUL /* order */ | 1UL << PG_has_hwpoisoned | \
1121− 1UL << PG_hugetlb | 1UL << PG_large_rmappable)
1141+ 1UL << PG_large_rmappable)
11221142
11231143 #define PAGE_FLAGS_PRIVATE \
11241144 (1UL << PG_private | 1UL << PG_private_2)
include/trace/events/mmflags.h+1−0
@@ -135,6 +135,7 @@ IF_HAVE_PG_ARCH_X(arch_3) · 134 unmodified lines
135135 #define DEF_PAGETYPE_NAME(_name) { PG_##_name, __stringify(_name) }
136136
137137 #define __def_pagetype_names \
138+ DEF_PAGETYPE_NAME(hugetlb), \
138139 DEF_PAGETYPE_NAME(offline), \
139140 DEF_PAGETYPE_NAME(guard), \
140141 DEF_PAGETYPE_NAME(table), \
kernel/vmcore_info.c+2−3
@@ -205,11 +205,10 @@ static int __init crash_save_vmcoreinfo_init(void) · 204 unmodified lines
205205 VMCOREINFO_NUMBER(PG_head_mask);
206206 #define PAGE_BUDDY_MAPCOUNT_VALUE (~PG_buddy)
207207 VMCOREINFO_NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE);
208−#ifdef CONFIG_HUGETLB_PAGE
209− VMCOREINFO_NUMBER(PG_hugetlb);
208+#define PAGE_HUGETLB_MAPCOUNT_VALUE (~PG_hugetlb)
209+ VMCOREINFO_NUMBER(PAGE_HUGETLB_MAPCOUNT_VALUE);
210210 #define PAGE_OFFLINE_MAPCOUNT_VALUE (~PG_offline)
211211 VMCOREINFO_NUMBER(PAGE_OFFLINE_MAPCOUNT_VALUE);
212−#endif
213212
214213 #ifdef CONFIG_KALLSYMS
215214 VMCOREINFO_SYMBOL(kallsyms_names);
lib/stackdepot.c+2−2
@@ -627,10 +627,10 @@ depot_stack_handle_t stack_depot_save_flags(unsigned long *entries, · 626 unmodified lines
627627 /*
628628 * Zero out zone modifiers, as we don't have specific zone
629629 * requirements. Keep the flags related to allocation in atomic
630− * contexts and I/O.
630+ * contexts, I/O, nolockdep.
631631 */
632632 alloc_flags &= ~GFP_ZONEMASK;
633− alloc_flags &= (GFP_ATOMIC | GFP_KERNEL);
633+ alloc_flags &= (GFP_ATOMIC | GFP_KERNEL | __GFP_NOLOCKDEP);
634634 alloc_flags |= __GFP_NOWARN;
635635 page = alloc_pages(alloc_flags, DEPOT_POOL_ORDER);
636636 if (page)
mm/hugetlb.c+15−25
@@ -1624,7 +1624,7 @@ static inline void __clear_hugetlb_destructor(struct hstate *h, · 1623 unmodified lines
16241624 {
16251625 lockdep_assert_held(&hugetlb_lock);
16261626
1627− folio_clear_hugetlb(folio);
1627+ __folio_clear_hugetlb(folio);
16281628 }
16291629
16301630 /*
@@ -1711,7 +1711,7 @@ static void add_hugetlb_folio(struct hstate *h, struct folio *folio, · 80 unmodified lines
17111711 h->surplus_huge_pages_node[nid]++;
17121712 }
17131713
1714− folio_set_hugetlb(folio);
1714+ __folio_set_hugetlb(folio);
17151715 folio_change_private(folio, NULL);
17161716 /*
17171717 * We have to set hugetlb_vmemmap_optimized again as above
@@ -1781,7 +1781,7 @@ static void __update_and_free_hugetlb_folio(struct hstate *h, · 63 unmodified lines
17811781 * If vmemmap pages were allocated above, then we need to clear the
17821782 * hugetlb destructor under the hugetlb lock.
17831783 */
1784− if (clear_dtor) {
1784+ if (folio_test_hugetlb(folio)) {
17851785 spin_lock_irq(&hugetlb_lock);
17861786 __clear_hugetlb_destructor(h, folio);
17871787 spin_unlock_irq(&hugetlb_lock);
@@ -2049,7 +2049,7 @@ static void __prep_account_new_huge_page(struct hstate *h, int nid) · 261 unmodified lines
20492049
20502050 static void init_new_hugetlb_folio(struct hstate *h, struct folio *folio)
20512051 {
2052− folio_set_hugetlb(folio);
2052+ __folio_set_hugetlb(folio);
20532053 INIT_LIST_HEAD(&folio->lru);
20542054 hugetlb_set_folio_subpool(folio, NULL);
20552055 set_hugetlb_cgroup(folio, NULL);
@@ -2159,22 +2159,6 @@ static bool prep_compound_gigantic_folio_for_demote(struct folio *folio, · 103 unmodified lines
21592159 return __prep_compound_gigantic_folio(folio, order, true);
21602160 }
21612161
2162−/*
2163− * PageHuge() only returns true for hugetlbfs pages, but not for normal or
2164− * transparent huge pages. See the PageTransHuge() documentation for more
2165− * details.
2166− */
2167−int PageHuge(const struct page *page)
2168−{
2169− const struct folio *folio;
2170−
2171− if (!PageCompound(page))
2172− return 0;
2173− folio = page_folio(page);
2174− return folio_test_hugetlb(folio);
2175−}
2176−EXPORT_SYMBOL_GPL(PageHuge);
2177−
21782162 /*
21792163 * Find and lock address space (mapping) in write mode.
21802164 *
@@ -3268,9 +3252,12 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, · 1087 unmodified lines
32683252
32693253 rsv_adjust = hugepage_subpool_put_pages(spool, 1);
32703254 hugetlb_acct_memory(h, -rsv_adjust);
3271− if (deferred_reserve)
3255+ if (deferred_reserve) {
3256+ spin_lock_irq(&hugetlb_lock);
32723257 hugetlb_cgroup_uncharge_folio_rsvd(hstate_index(h),
32733258 pages_per_huge_page(h), folio);
3259+ spin_unlock_irq(&hugetlb_lock);
3260+ }
32743261 }
32753262
32763263 if (!memcg_charge_ret)
@@ -6274,6 +6261,12 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm, · 2997 unmodified lines
62746261 VM_UFFD_MISSING);
62756262 }
62766263
6264+ if (!(vma->vm_flags & VM_MAYSHARE)) {
6265+ ret = vmf_anon_prepare(vmf);
6266+ if (unlikely(ret))
6267+ goto out;
6268+ }
6269+
62776270 folio = alloc_hugetlb_folio(vma, haddr, 0);
62786271 if (IS_ERR(folio)) {
62796272 /*
@@ -6310,15 +6303,12 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm, · 30 unmodified lines
63106303 */
63116304 restore_reserve_on_error(h, vma, haddr, folio);
63126305 folio_put(folio);
6306+ ret = VM_FAULT_SIGBUS;
63136307 goto out;
63146308 }
63156309 new_pagecache_folio = true;
63166310 } else {
63176311 folio_lock(folio);
6318−
6319− ret = vmf_anon_prepare(vmf);
6320− if (unlikely(ret))
6321− goto backout_unlocked;
63226312 anon_rmap = 1;
63236313 }
63246314 } else {
mm/zswap.c+16−9
@@ -1331,15 +1331,22 @@ static unsigned long zswap_shrinker_count(struct shrinker *shrinker, · 1330 unmodified lines
13311331 if (!gfp_has_io_fs(sc->gfp_mask))
13321332 return 0;
13331333
1334−#ifdef CONFIG_MEMCG_KMEM
1335− mem_cgroup_flush_stats(memcg);
1336− nr_backing = memcg_page_state(memcg, MEMCG_ZSWAP_B) >> PAGE_SHIFT;
1337− nr_stored = memcg_page_state(memcg, MEMCG_ZSWAPPED);
1338−#else
1339− /* use pool stats instead of memcg stats */
1340− nr_backing = zswap_pool_total_size >> PAGE_SHIFT;
1341− nr_stored = atomic_read(&zswap_nr_stored);
1342−#endif
1334+ /*
1335+ * For memcg, use the cgroup-wide ZSWAP stats since we don't
1336+ * have them per-node and thus per-lruvec. Careful if memcg is
1337+ * runtime-disabled: we can get sc->memcg == NULL, which is ok
1338+ * for the lruvec, but not for memcg_page_state().
1339+ *
1340+ * Without memcg, use the zswap pool-wide metrics.
1341+ */
1342+ if (!mem_cgroup_disabled()) {
1343+ mem_cgroup_flush_stats(memcg);
1344+ nr_backing = memcg_page_state(memcg, MEMCG_ZSWAP_B) >> PAGE_SHIFT;
1345+ nr_stored = memcg_page_state(memcg, MEMCG_ZSWAPPED);
1346+ } else {
1347+ nr_backing = zswap_pool_total_size >> PAGE_SHIFT;
1348+ nr_stored = atomic_read(&zswap_nr_stored);
1349+ }
13431350
13441351 if (!nr_stored)
13451352 return 0;
tools/testing/selftests/kselftest_harness.h+8−4
@@ -56,7 +56,6 @@ · 55 unmodified lines
5656 #include <asm/types.h>
5757 #include <ctype.h>
5858 #include <errno.h>
59−#include <limits.h>
6059 #include <stdbool.h>
6160 #include <stdint.h>
6261 #include <stdio.h>
@@ -1159,7 +1158,7 @@ void __run_test(struct __fixture_metadata *f, · 1096 unmodified lines
11591158 struct __test_metadata *t)
11601159 {
11611160 struct __test_xfail *xfail;
1162− char test_name[LINE_MAX];
1161+ char *test_name;
11631162 const char *diagnostic;
11641163
11651164 /* reset test struct */
@@ -1167,8 +1166,12 @@ void __run_test(struct __fixture_metadata *f, · 1 unmodified line
11671166 t->trigger = 0;
11681167 memset(t->results->reason, 0, sizeof(t->results->reason));
11691168
1170− snprintf(test_name, sizeof(test_name), "%s%s%s.%s",
1171− f->name, variant->name[0] ? "." : "", variant->name, t->name);
1169+ if (asprintf(&test_name, "%s%s%s.%s", f->name,
1170+ variant->name[0] ? "." : "", variant->name, t->name) == -1) {
1171+ ksft_print_msg("ERROR ALLOCATING MEMORY\n");
1172+ t->exit_code = KSFT_FAIL;
1173+ _exit(t->exit_code);
1174+ }
11721175
11731176 ksft_print_msg(" RUN %s ...\n", test_name);
11741177
@@ -1206,6 +1209,7 @@ void __run_test(struct __fixture_metadata *f, · 31 unmodified lines
12061209
12071210 ksft_test_result_code(t->exit_code, test_name,
12081211 diagnostic ? "%s" : NULL, diagnostic);
1212+ free(test_name);
12091213 }
12101214
12111215 static int test_harness_run(int argc, char **argv)
tools/testing/selftests/mm/mdwe_test.c+1−0
@@ -7,6 +7,7 @@ · 6 unmodified lines
77 #include <linux/mman.h>
88 #include <linux/prctl.h>
99
10+#define _GNU_SOURCE
1011 #include <stdio.h>
1112 #include <stdlib.h>
1213 #include <sys/auxv.h>
tools/testing/selftests/mm/protection_keys.c+0−38
@@ -54,7 +54,6 @@ int test_nr; · 53 unmodified lines
5454 u64 shadow_pkey_reg;
5555 int dprint_in_signal;
5656 char dprint_in_signal_buffer[DPRINT_IN_SIGNAL_BUF_SIZE];
57−char buf[256];
5857
5958 void cat_into_file(char *str, char *file)
6059 {
@@ -1745,42 +1744,6 @@ void pkey_setup_shadow(void) · 1684 unmodified lines
17451744 shadow_pkey_reg = __read_pkey_reg();
17461745 }
17471746
1748−pid_t parent_pid;
1749−
1750−void restore_settings_atexit(void)
1751−{
1752− if (parent_pid == getpid())
1753− cat_into_file(buf, "/proc/sys/vm/nr_hugepages");
1754−}
1755−
1756−void save_settings(void)
1757−{
1758− int fd;
1759− int err;
1760−
1761− if (geteuid())
1762− return;
1763−
1764− fd = open("/proc/sys/vm/nr_hugepages", O_RDONLY);
1765− if (fd < 0) {
1766− fprintf(stderr, "error opening\n");
1767− perror("error: ");
1768− exit(__LINE__);
1769− }
1770−
1771− /* -1 to guarantee leaving the trailing \0 */
1772− err = read(fd, buf, sizeof(buf)-1);
1773− if (err < 0) {
1774− fprintf(stderr, "error reading\n");
1775− perror("error: ");
1776− exit(__LINE__);
1777− }
1778−
1779− parent_pid = getpid();
1780− atexit(restore_settings_atexit);
1781− close(fd);
1782−}
1783−
17841747 int main(void)
17851748 {
17861749 int nr_iterations = 22;
@@ -1788,7 +1751,6 @@ int main(void) · 1 unmodified line
17881751
17891752 srand((unsigned int)time(NULL));
17901753
1791− save_settings();
17921754 setup_handlers();
17931755
17941756 printf("has pkeys: %d\n", pkeys_supported);
tools/testing/selftests/mm/run_vmtests.sh+2−0
@@ -385,6 +385,7 @@ CATEGORY="ksm_numa" run_test ./ksm_tests -N -m 0 · 384 unmodified lines
385385 CATEGORY="ksm" run_test ./ksm_functional_tests
386386
387387 # protection_keys tests
388+nr_hugepgs=$(cat /proc/sys/vm/nr_hugepages)
388389 if [ -x ./protection_keys_32 ]
389390 then
390391 CATEGORY="pkey" run_test ./protection_keys_32
@@ -394,6 +395,7 @@ if [ -x ./protection_keys_64 ] · 3 unmodified lines
394395 then
395396 CATEGORY="pkey" run_test ./protection_keys_64
396397 fi
398+echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages
397399
398400 if [ -x ./soft-dirty ]
399401 then
tools/testing/selftests/mm/split_huge_page_test.c+1−1
@@ -300,7 +300,7 @@ int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd, · 299 unmodified lines
300300 char **addr)
301301 {
302302 size_t i;
303− int dummy;
303+ int __attribute__((unused)) dummy = 0;
304304
305305 srand(time(NULL));
306306