History

Merge tag 'mm-hotfixes-stable-2026-01-29-09-41' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Pull misc fixes from Andrew Morton: "16 hotfixes. 9 are cc:stable, 12 are for MM. There's a patch series from Pratyush Yadav which fixes a few things in the new-in-6.19 LUO memfd code. Plus the usual shower of singletons - please see the changelogs for details" * tag 'mm-hotfixes-stable-2026-01-29-09-41' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: vmcoreinfo: make hwerr_data visible for debugging mm/zone_device: reinitialize large zone device private folios mm/mm_init: don't cond_resched() in deferred_init_memmap_chunk() if called from deferred_grow_zone() mm/kfence: randomize the freelist on initialization kho: kho_preserve_vmalloc(): don't return 0 when ENOMEM kho: init alloc tags when restoring pages from reserved memory mm: memfd_luo: restore and free memfd_luo_ser on failure mm: memfd_luo: use memfd_alloc_file() instead of shmem_file_setup() memfd: export alloc_file() flex_proportions: make fprop_new_period() hardirq safe mailmap: add entry for Viacheslav Bocharov mm/memory-failure: teach kill_accessing_process to accept hugetlb tail page pfn mm/memory-failure: fix missing ->mf_stats count in hugetlb poison mm, swap: restore swap_space attr aviod kernel panic mm/kasan: fix KASAN poisoning in vrealloc() mm/shmem, swap: fix race of truncate and swap entry split

Linus Torvalds committed 9 months ago

Commit bcb60582 parents 1cac389 bd5878223 files · +239 −87Browse files

Unified · Split

23 files
  1. .mailmap +1 −0
  2. arch/powerpc/kvm/book3s_hv_uvmem.c +1 −1
  3. drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +1 −1
  4. drivers/gpu/drm/drm_pagemap.c +1 −1
  5. drivers/gpu/drm/nouveau/nouveau_dmem.c +1 −1
  6. include/linux/kasan.h +14 −0
  7. include/linux/memfd.h +6 −0
  8. include/linux/memremap.h +6 −3
  9. kernel/liveupdate/kexec_handover.c +11 −1
  10. kernel/vmcore_info.c +5 −1
  11. lib/flex_proportions.c +3 −2
  12. lib/test_hmm.c +3 −1
  13. mm/kasan/common.c +21 −0
  14. mm/kfence/core.c +19 −4
  15. mm/memfd.c +2 −2
  16. mm/memfd_luo.c +6 −4
  17. mm/memory-failure.c +60 −39
  18. mm/memremap.c +34 −1
  19. mm/mm_init.c +6 −6
  20. mm/shmem.c +34 −11
  21. mm/swap.h +1 −1
  22. mm/swap_state.c +1 −2
  23. mm/vmalloc.c +2 −5
.mailmap+1−0
@@ -851,6 +851,7 @@ Valentin Schneider <vschneid@redhat.com> <valentin.schneider@arm.com> · 850 unmodified lines
851851 Veera Sundaram Sankaran <quic_veeras@quicinc.com> <veeras@codeaurora.org>
852852 Veerabhadrarao Badiganti <quic_vbadigan@quicinc.com> <vbadigan@codeaurora.org>
853853 Venkateswara Naralasetty <quic_vnaralas@quicinc.com> <vnaralas@codeaurora.org>
854+Viacheslav Bocharov <v@baodeep.com> <adeep@lexina.in>
854855 Vikash Garodia <vikash.garodia@oss.qualcomm.com> <vgarodia@codeaurora.org>
855856 Vikash Garodia <vikash.garodia@oss.qualcomm.com> <quic_vgarodia@quicinc.com>
856857 Vincent Mailhol <mailhol@kernel.org> <mailhol.vincent@wanadoo.fr>
arch/powerpc/kvm/book3s_hv_uvmem.c+1−1
@@ -723,7 +723,7 @@ static struct page *kvmppc_uvmem_get_page(unsigned long gpa, struct kvm *kvm) · 722 unmodified lines
723723
724724 dpage = pfn_to_page(uvmem_pfn);
725725 dpage->zone_device_data = pvt;
726− zone_device_page_init(dpage, 0);
726+ zone_device_page_init(dpage, &kvmppc_uvmem_pgmap, 0);
727727 return dpage;
728728 out_clear:
729729 spin_lock(&kvmppc_uvmem_bitmap_lock);
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c+1−1
@@ -217,7 +217,7 @@ svm_migrate_get_vram_page(struct svm_range *prange, unsigned long pfn) · 216 unmodified lines
217217 page = pfn_to_page(pfn);
218218 svm_range_bo_ref(prange->svm_bo);
219219 page->zone_device_data = prange->svm_bo;
220− zone_device_page_init(page, 0);
220+ zone_device_page_init(page, page_pgmap(page), 0);
221221 }
222222
223223 static void
drivers/gpu/drm/drm_pagemap.c+1−1
@@ -197,7 +197,7 @@ static void drm_pagemap_get_devmem_page(struct page *page, · 196 unmodified lines
197197 struct drm_pagemap_zdd *zdd)
198198 {
199199 page->zone_device_data = drm_pagemap_zdd_get(zdd);
200− zone_device_page_init(page, 0);
200+ zone_device_page_init(page, page_pgmap(page), 0);
201201 }
202202
203203 /**
drivers/gpu/drm/nouveau/nouveau_dmem.c+1−1
@@ -425,7 +425,7 @@ nouveau_dmem_page_alloc_locked(struct nouveau_drm *drm, bool is_large) · 424 unmodified lines
425425 order = ilog2(DMEM_CHUNK_NPAGES);
426426 }
427427
428− zone_device_folio_init(folio, order);
428+ zone_device_folio_init(folio, page_pgmap(folio_page(folio, 0)), order);
429429 return page;
430430 }
431431
include/linux/kasan.h+14−0
@@ -641,6 +641,17 @@ kasan_unpoison_vmap_areas(struct vm_struct **vms, int nr_vms, · 640 unmodified lines
641641 __kasan_unpoison_vmap_areas(vms, nr_vms, flags);
642642 }
643643
644+void __kasan_vrealloc(const void *start, unsigned long old_size,
645+ unsigned long new_size);
646+
647+static __always_inline void kasan_vrealloc(const void *start,
648+ unsigned long old_size,
649+ unsigned long new_size)
650+{
651+ if (kasan_enabled())
652+ __kasan_vrealloc(start, old_size, new_size);
653+}
654+
644655 #else /* CONFIG_KASAN_VMALLOC */
645656
646657 static inline void kasan_populate_early_vm_area_shadow(void *start,
@@ -670,6 +681,9 @@ kasan_unpoison_vmap_areas(struct vm_struct **vms, int nr_vms, · 23 unmodified lines
670681 kasan_vmalloc_flags_t flags)
671682 { }
672683
684+static inline void kasan_vrealloc(const void *start, unsigned long old_size,
685+ unsigned long new_size) { }
686+
673687 #endif /* CONFIG_KASAN_VMALLOC */
674688
675689 #if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \
include/linux/memfd.h+6−0
@@ -17,6 +17,7 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx); · 16 unmodified lines
1717 * to by vm_flags_ptr.
1818 */
1919 int memfd_check_seals_mmap(struct file *file, vm_flags_t *vm_flags_ptr);
20+struct file *memfd_alloc_file(const char *name, unsigned int flags);
2021 #else
2122 static inline long memfd_fcntl(struct file *f, unsigned int c, unsigned int a)
2223 {
@@ -31,6 +32,11 @@ static inline int memfd_check_seals_mmap(struct file *file, · 8 unmodified lines
3132 {
3233 return 0;
3334 }
35+
36+static inline struct file *memfd_alloc_file(const char *name, unsigned int flags)
37+{
38+ return ERR_PTR(-EINVAL);
39+}
3440 #endif
3541
3642 #endif /* __LINUX_MEMFD_H */
include/linux/memremap.h+6−3
@@ -224,7 +224,8 @@ static inline bool is_fsdax_page(const struct page *page) · 223 unmodified lines
224224 }
225225
226226 #ifdef CONFIG_ZONE_DEVICE
227−void zone_device_page_init(struct page *page, unsigned int order);
227+void zone_device_page_init(struct page *page, struct dev_pagemap *pgmap,
228+ unsigned int order);
228229 void *memremap_pages(struct dev_pagemap *pgmap, int nid);
229230 void memunmap_pages(struct dev_pagemap *pgmap);
230231 void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap);
@@ -234,9 +235,11 @@ bool pgmap_pfn_valid(struct dev_pagemap *pgmap, unsigned long pfn); · 3 unmodified lines
234235
235236 unsigned long memremap_compat_align(void);
236237
237−static inline void zone_device_folio_init(struct folio *folio, unsigned int order)
238+static inline void zone_device_folio_init(struct folio *folio,
239+ struct dev_pagemap *pgmap,
240+ unsigned int order)
238241 {
239− zone_device_page_init(&folio->page, order);
242+ zone_device_page_init(&folio->page, pgmap, order);
240243 if (order)
241244 folio_set_large_rmappable(folio);
242245 }
kernel/liveupdate/kexec_handover.c+11−1
@@ -255,6 +255,14 @@ static struct page *kho_restore_page(phys_addr_t phys, bool is_folio) · 254 unmodified lines
255255 if (is_folio && info.order)
256256 prep_compound_page(page, info.order);
257257
258+ /* Always mark headpage's codetag as empty to avoid accounting mismatch */
259+ clear_page_tag_ref(page);
260+ if (!is_folio) {
261+ /* Also do that for the non-compound tail pages */
262+ for (unsigned int i = 1; i < nr_pages; i++)
263+ clear_page_tag_ref(page + i);
264+ }
265+
258266 adjust_managed_page_count(page, nr_pages);
259267 return page;
260268 }
@@ -1006,8 +1014,10 @@ int kho_preserve_vmalloc(void *ptr, struct kho_vmalloc *preservation) · 745 unmodified lines
10061014 chunk->phys[idx++] = phys;
10071015 if (idx == ARRAY_SIZE(chunk->phys)) {
10081016 chunk = new_vmalloc_chunk(chunk);
1009− if (!chunk)
1017+ if (!chunk) {
1018+ err = -ENOMEM;
10101019 goto err_free;
1020+ }
10111021 idx = 0;
10121022 }
10131023 }
kernel/vmcore_info.c+5−1
@@ -36,7 +36,11 @@ struct hwerr_info { · 35 unmodified lines
3636 time64_t timestamp;
3737 };
3838
39−static struct hwerr_info hwerr_data[HWERR_RECOV_MAX];
39+/*
40+ * The hwerr_data[] array is declared with global scope so that it remains
41+ * accessible to vmcoreinfo even when Link Time Optimization (LTO) is enabled.
42+ */
43+struct hwerr_info hwerr_data[HWERR_RECOV_MAX];
4044
4145 Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type,
4246 void *data, size_t data_len)
lib/flex_proportions.c+3−2
@@ -64,13 +64,14 @@ void fprop_global_destroy(struct fprop_global *p) · 63 unmodified lines
6464 bool fprop_new_period(struct fprop_global *p, int periods)
6565 {
6666 s64 events = percpu_counter_sum(&p->events);
67+ unsigned long flags;
6768
6869 /*
6970 * Don't do anything if there are no events.
7071 */
7172 if (events <= 1)
7273 return false;
73− preempt_disable_nested();
74+ local_irq_save(flags);
7475 write_seqcount_begin(&p->sequence);
7576 if (periods < 64)
7677 events -= events >> periods;
@@ -78,7 +79,7 @@ bool fprop_new_period(struct fprop_global *p, int periods) · 1 unmodified line
7879 percpu_counter_add(&p->events, -events);
7980 p->period += periods;
8081 write_seqcount_end(&p->sequence);
81− preempt_enable_nested();
82+ local_irq_restore(flags);
8283
8384 return true;
8485 }
lib/test_hmm.c+3−1
@@ -662,7 +662,9 @@ static struct page *dmirror_devmem_alloc_page(struct dmirror *dmirror, · 661 unmodified lines
662662 goto error;
663663 }
664664
665− zone_device_folio_init(page_folio(dpage), order);
665+ zone_device_folio_init(page_folio(dpage),
666+ page_pgmap(folio_page(page_folio(dpage), 0)),
667+ order);
666668 dpage->zone_device_data = rpage;
667669 return dpage;
668670
mm/kasan/common.c+21−0
@@ -606,4 +606,25 @@ void __kasan_unpoison_vmap_areas(struct vm_struct **vms, int nr_vms, · 605 unmodified lines
606606 __kasan_unpoison_vmalloc(addr, size, flags | KASAN_VMALLOC_KEEP_TAG);
607607 }
608608 }
609+
610+void __kasan_vrealloc(const void *addr, unsigned long old_size,
611+ unsigned long new_size)
612+{
613+ if (new_size < old_size) {
614+ kasan_poison_last_granule(addr, new_size);
615+
616+ new_size = round_up(new_size, KASAN_GRANULE_SIZE);
617+ old_size = round_up(old_size, KASAN_GRANULE_SIZE);
618+ if (new_size < old_size)
619+ __kasan_poison_vmalloc(addr + new_size,
620+ old_size - new_size);
621+ } else if (new_size > old_size) {
622+ old_size = round_down(old_size, KASAN_GRANULE_SIZE);
623+ __kasan_unpoison_vmalloc(addr + old_size,
624+ new_size - old_size,
625+ KASAN_VMALLOC_PROT_NORMAL |
626+ KASAN_VMALLOC_VM_ALLOC |
627+ KASAN_VMALLOC_KEEP_TAG);
628+ }
629+}
609630 #endif
mm/kfence/core.c+19−4
@@ -596,7 +596,7 @@ static void rcu_guarded_free(struct rcu_head *h) · 595 unmodified lines
596596 static unsigned long kfence_init_pool(void)
597597 {
598598 unsigned long addr, start_pfn;
599− int i;
599+ int i, rand;
600600
601601 if (!arch_kfence_init_pool())
602602 return (unsigned long)__kfence_pool;
@@ -647,13 +647,27 @@ static unsigned long kfence_init_pool(void) · 44 unmodified lines
647647 INIT_LIST_HEAD(&meta->list);
648648 raw_spin_lock_init(&meta->lock);
649649 meta->state = KFENCE_OBJECT_UNUSED;
650− meta->addr = addr; /* Initialize for validation in metadata_to_pageaddr(). */
651− list_add_tail(&meta->list, &kfence_freelist);
650+ /* Use addr to randomize the freelist. */
651+ meta->addr = i;
652652
653653 /* Protect the right redzone. */
654− if (unlikely(!kfence_protect(addr + PAGE_SIZE)))
654+ if (unlikely(!kfence_protect(addr + 2 * i * PAGE_SIZE + PAGE_SIZE)))
655655 goto reset_slab;
656+ }
657+
658+ for (i = CONFIG_KFENCE_NUM_OBJECTS; i > 0; i--) {
659+ rand = get_random_u32_below(i);
660+ swap(kfence_metadata_init[i - 1].addr, kfence_metadata_init[rand].addr);
661+ }
656662
663+ for (i = 0; i < CONFIG_KFENCE_NUM_OBJECTS; i++) {
664+ struct kfence_metadata *meta_1 = &kfence_metadata_init[i];
665+ struct kfence_metadata *meta_2 = &kfence_metadata_init[meta_1->addr];
666+
667+ list_add_tail(&meta_2->list, &kfence_freelist);
668+ }
669+ for (i = 0; i < CONFIG_KFENCE_NUM_OBJECTS; i++) {
670+ kfence_metadata_init[i].addr = addr;
657671 addr += 2 * PAGE_SIZE;
658672 }
659673
@@ -666,6 +680,7 @@ static unsigned long kfence_init_pool(void) · 6 unmodified lines
666680 return 0;
667681
668682 reset_slab:
683+ addr += 2 * i * PAGE_SIZE;
669684 for (i = 0; i < KFENCE_POOL_SIZE / PAGE_SIZE; i++) {
670685 struct page *page;
671686
mm/memfd.c+2−2
@@ -456,7 +456,7 @@ err_name: · 455 unmodified lines
456456 return ERR_PTR(error);
457457 }
458458
459−static struct file *alloc_file(const char *name, unsigned int flags)
459+struct file *memfd_alloc_file(const char *name, unsigned int flags)
460460 {
461461 unsigned int *file_seals;
462462 struct file *file;
@@ -520,5 +520,5 @@ SYSCALL_DEFINE2(memfd_create, · 57 unmodified lines
520520 return PTR_ERR(name);
521521
522522 fd_flags = (flags & MFD_CLOEXEC) ? O_CLOEXEC : 0;
523− return FD_ADD(fd_flags, alloc_file(name, flags));
523+ return FD_ADD(fd_flags, memfd_alloc_file(name, flags));
524524 }
mm/memfd_luo.c+6−4
@@ -78,6 +78,7 @@ · 77 unmodified lines
7878 #include <linux/liveupdate.h>
7979 #include <linux/shmem_fs.h>
8080 #include <linux/vmalloc.h>
81+#include <linux/memfd.h>
8182 #include "internal.h"
8283
8384 static int memfd_luo_preserve_folios(struct file *file,
@@ -443,11 +444,11 @@ static int memfd_luo_retrieve(struct liveupdate_file_op_args *args) · 359 unmodified lines
443444 if (!ser)
444445 return -EINVAL;
445446
446− file = shmem_file_setup("", 0, VM_NORESERVE);
447−
447+ file = memfd_alloc_file("", 0);
448448 if (IS_ERR(file)) {
449449 pr_err("failed to setup file: %pe\n", file);
450− return PTR_ERR(file);
450+ err = PTR_ERR(file);
451+ goto free_ser;
451452 }
452453
453454 vfs_setpos(file, ser->pos, MAX_LFS_FILESIZE);
@@ -473,7 +474,8 @@ static int memfd_luo_retrieve(struct liveupdate_file_op_args *args) · 19 unmodified lines
473474
474475 put_file:
475476 fput(file);
476−
477+free_ser:
478+ kho_restore_free(ser);
477479 return err;
478480 }
479481
mm/memory-failure.c+60−39
@@ -692,6 +692,8 @@ static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift, · 691 unmodified lines
692692 unsigned long poisoned_pfn, struct to_kill *tk)
693693 {
694694 unsigned long pfn = 0;
695+ unsigned long hwpoison_vaddr;
696+ unsigned long mask;
695697
696698 if (pte_present(pte)) {
697699 pfn = pte_pfn(pte);
@@ -702,10 +704,12 @@ static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift, · 4 unmodified lines
702704 pfn = softleaf_to_pfn(entry);
703705 }
704706
705− if (!pfn || pfn != poisoned_pfn)
707+ mask = ~((1UL << (shift - PAGE_SHIFT)) - 1);
708+ if (!pfn || pfn != (poisoned_pfn & mask))
706709 return 0;
707710
708− set_to_kill(tk, addr, shift);
711+ hwpoison_vaddr = addr + ((poisoned_pfn - pfn) << PAGE_SHIFT);
712+ set_to_kill(tk, hwpoison_vaddr, shift);
709713 return 1;
710714 }
711715
@@ -1883,12 +1887,22 @@ static unsigned long __folio_free_raw_hwp(struct folio *folio, bool move_flag) · 1171 unmodified lines
18831887 return count;
18841888 }
18851889
1886−static int folio_set_hugetlb_hwpoison(struct folio *folio, struct page *page)
1890+#define MF_HUGETLB_FREED 0 /* freed hugepage */
1891+#define MF_HUGETLB_IN_USED 1 /* in-use hugepage */
1892+#define MF_HUGETLB_NON_HUGEPAGE 2 /* not a hugepage */
1893+#define MF_HUGETLB_FOLIO_PRE_POISONED 3 /* folio already poisoned */
1894+#define MF_HUGETLB_PAGE_PRE_POISONED 4 /* exact page already poisoned */
1895+#define MF_HUGETLB_RETRY 5 /* hugepage is busy, retry */
1896+/*
1897+ * Set hugetlb folio as hwpoisoned, update folio private raw hwpoison list
1898+ * to keep track of the poisoned pages.
1899+ */
1900+static int hugetlb_update_hwpoison(struct folio *folio, struct page *page)
18871901 {
18881902 struct llist_head *head;
18891903 struct raw_hwp_page *raw_hwp;
18901904 struct raw_hwp_page *p;
1891− int ret = folio_test_set_hwpoison(folio) ? -EHWPOISON : 0;
1905+ int ret = folio_test_set_hwpoison(folio) ? MF_HUGETLB_FOLIO_PRE_POISONED : 0;
18921906
18931907 /*
18941908 * Once the hwpoison hugepage has lost reliable raw error info,
@@ -1896,20 +1910,17 @@ static int folio_set_hugetlb_hwpoison(struct folio *folio, struct page *page) · 1 unmodified line
18961910 * so skip to add additional raw error info.
18971911 */
18981912 if (folio_test_hugetlb_raw_hwp_unreliable(folio))
1899− return -EHWPOISON;
1913+ return MF_HUGETLB_FOLIO_PRE_POISONED;
19001914 head = raw_hwp_list_head(folio);
19011915 llist_for_each_entry(p, head->first, node) {
19021916 if (p->page == page)
1903− return -EHWPOISON;
1917+ return MF_HUGETLB_PAGE_PRE_POISONED;
19041918 }
19051919
19061920 raw_hwp = kmalloc(sizeof(struct raw_hwp_page), GFP_ATOMIC);
19071921 if (raw_hwp) {
19081922 raw_hwp->page = page;
19091923 llist_add(&raw_hwp->node, head);
1910− /* the first error event will be counted in action_result(). */
1911− if (ret)
1912− num_poisoned_pages_inc(page_to_pfn(page));
19131924 } else {
19141925 /*
19151926 * Failed to save raw error info. We no longer trace all
@@ -1957,42 +1968,39 @@ void folio_clear_hugetlb_hwpoison(struct folio *folio) · 41 unmodified lines
19571968
19581969 /*
19591970 * Called from hugetlb code with hugetlb_lock held.
1960− *
1961− * Return values:
1962− * 0 - free hugepage
1963− * 1 - in-use hugepage
1964− * 2 - not a hugepage
1965− * -EBUSY - the hugepage is busy (try to retry)
1966− * -EHWPOISON - the hugepage is already hwpoisoned
19671971 */
19681972 int __get_huge_page_for_hwpoison(unsigned long pfn, int flags,
19691973 bool *migratable_cleared)
19701974 {
19711975 struct page *page = pfn_to_page(pfn);
19721976 struct folio *folio = page_folio(page);
1973− int ret = 2; /* fallback to normal page handling */
19741977 bool count_increased = false;
1978+ int ret, rc;
19751979
1976− if (!folio_test_hugetlb(folio))
1980+ if (!folio_test_hugetlb(folio)) {
1981+ ret = MF_HUGETLB_NON_HUGEPAGE;
19771982 goto out;
1978−
1979− if (flags & MF_COUNT_INCREASED) {
1980− ret = 1;
1983+ } else if (flags & MF_COUNT_INCREASED) {
1984+ ret = MF_HUGETLB_IN_USED;
19811985 count_increased = true;
19821986 } else if (folio_test_hugetlb_freed(folio)) {
1983− ret = 0;
1987+ ret = MF_HUGETLB_FREED;
19841988 } else if (folio_test_hugetlb_migratable(folio)) {
1985− ret = folio_try_get(folio);
1986− if (ret)
1989+ if (folio_try_get(folio)) {
1990+ ret = MF_HUGETLB_IN_USED;
19871991 count_increased = true;
1992+ } else {
1993+ ret = MF_HUGETLB_FREED;
1994+ }
19881995 } else {
1989− ret = -EBUSY;
1996+ ret = MF_HUGETLB_RETRY;
19901997 if (!(flags & MF_NO_RETRY))
19911998 goto out;
19921999 }
19932000
1994− if (folio_set_hugetlb_hwpoison(folio, page)) {
1995− ret = -EHWPOISON;
2001+ rc = hugetlb_update_hwpoison(folio, page);
2002+ if (rc >= MF_HUGETLB_FOLIO_PRE_POISONED) {
2003+ ret = rc;
19962004 goto out;
19972005 }
19982006
@@ -2017,10 +2025,16 @@ out: · 18 unmodified lines
20172025 * with basic operations like hugepage allocation/free/demotion.
20182026 * So some of prechecks for hwpoison (pinning, and testing/setting
20192027 * PageHWPoison) should be done in single hugetlb_lock range.
2028+ * Returns:
2029+ * 0 - not hugetlb, or recovered
2030+ * -EBUSY - not recovered
2031+ * -EOPNOTSUPP - hwpoison_filter'ed
2032+ * -EHWPOISON - folio or exact page already poisoned
2033+ * -EFAULT - kill_accessing_process finds current->mm null
20202034 */
20212035 static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb)
20222036 {
2023− int res;
2037+ int res, rv;
20242038 struct page *p = pfn_to_page(pfn);
20252039 struct folio *folio;
20262040 unsigned long page_flags;
@@ -2029,22 +2043,29 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb · 2 unmodified lines
20292043 *hugetlb = 1;
20302044 retry:
20312045 res = get_huge_page_for_hwpoison(pfn, flags, &migratable_cleared);
2032− if (res == 2) { /* fallback to normal page handling */
2046+ switch (res) {
2047+ case MF_HUGETLB_NON_HUGEPAGE: /* fallback to normal page handling */
20332048 *hugetlb = 0;
20342049 return 0;
2035− } else if (res == -EHWPOISON) {
2036− if (flags & MF_ACTION_REQUIRED) {
2037− folio = page_folio(p);
2038− res = kill_accessing_process(current, folio_pfn(folio), flags);
2039− }
2040− action_result(pfn, MF_MSG_ALREADY_POISONED, MF_FAILED);
2041− return res;
2042− } else if (res == -EBUSY) {
2050+ case MF_HUGETLB_RETRY:
20432051 if (!(flags & MF_NO_RETRY)) {
20442052 flags |= MF_NO_RETRY;
20452053 goto retry;
20462054 }
20472055 return action_result(pfn, MF_MSG_GET_HWPOISON, MF_IGNORED);
2056+ case MF_HUGETLB_FOLIO_PRE_POISONED:
2057+ case MF_HUGETLB_PAGE_PRE_POISONED:
2058+ rv = -EHWPOISON;
2059+ if (flags & MF_ACTION_REQUIRED)
2060+ rv = kill_accessing_process(current, pfn, flags);
2061+ if (res == MF_HUGETLB_PAGE_PRE_POISONED)
2062+ action_result(pfn, MF_MSG_ALREADY_POISONED, MF_FAILED);
2063+ else
2064+ action_result(pfn, MF_MSG_HUGE, MF_FAILED);
2065+ return rv;
2066+ default:
2067+ WARN_ON((res != MF_HUGETLB_FREED) && (res != MF_HUGETLB_IN_USED));
2068+ break;
20482069 }
20492070
20502071 folio = page_folio(p);
@@ -2055,7 +2076,7 @@ retry: · 4 unmodified lines
20552076 if (migratable_cleared)
20562077 folio_set_hugetlb_migratable(folio);
20572078 folio_unlock(folio);
2058− if (res == 1)
2079+ if (res == MF_HUGETLB_IN_USED)
20592080 folio_put(folio);
20602081 return -EOPNOTSUPP;
20612082 }
@@ -2064,7 +2085,7 @@ retry: · 2 unmodified lines
20642085 * Handling free hugepage. The possible race with hugepage allocation
20652086 * or demotion can be prevented by PageHWPoison flag.
20662087 */
2067− if (res == 0) {
2088+ if (res == MF_HUGETLB_FREED) {
20682089 folio_unlock(folio);
20692090 if (__page_handle_poison(p) > 0) {
20702091 page_ref_inc(p);
mm/memremap.c+34−1
@@ -477,10 +477,43 @@ void free_zone_device_folio(struct folio *folio) · 476 unmodified lines
477477 }
478478 }
479479
480−void zone_device_page_init(struct page *page, unsigned int order)
480+void zone_device_page_init(struct page *page, struct dev_pagemap *pgmap,
481+ unsigned int order)
481482 {
483+ struct page *new_page = page;
484+ unsigned int i;
485+
482486 VM_WARN_ON_ONCE(order > MAX_ORDER_NR_PAGES);
483487
488+ for (i = 0; i < (1UL << order); ++i, ++new_page) {
489+ struct folio *new_folio = (struct folio *)new_page;
490+
491+ /*
492+ * new_page could have been part of previous higher order folio
493+ * which encodes the order, in page + 1, in the flags bits. We
494+ * blindly clear bits which could have set my order field here,
495+ * including page head.
496+ */
497+ new_page->flags.f &= ~0xffUL; /* Clear possible order, page head */
498+
499+#ifdef NR_PAGES_IN_LARGE_FOLIO
500+ /*
501+ * This pointer math looks odd, but new_page could have been
502+ * part of a previous higher order folio, which sets _nr_pages
503+ * in page + 1 (new_page). Therefore, we use pointer casting to
504+ * correctly locate the _nr_pages bits within new_page which
505+ * could have modified by previous higher order folio.
506+ */
507+ ((struct folio *)(new_page - 1))->_nr_pages = 0;
508+#endif
509+
510+ new_folio->mapping = NULL;
511+ new_folio->pgmap = pgmap; /* Also clear compound head */
512+ new_folio->share = 0; /* fsdax only, unused for device private */
513+ VM_WARN_ON_FOLIO(folio_ref_count(new_folio), new_folio);
514+ VM_WARN_ON_FOLIO(!folio_is_zone_device(new_folio), new_folio);
515+ }
516+
484517 /*
485518 * Drivers shouldn't be allocating pages after calling
486519 * memunmap_pages().
mm/mm_init.c+6−6
@@ -2059,7 +2059,7 @@ static unsigned long __init deferred_init_pages(struct zone *zone, · 2058 unmodified lines
20592059 */
20602060 static unsigned long __init
20612061 deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn,
2062− struct zone *zone)
2062+ struct zone *zone, bool can_resched)
20632063 {
20642064 int nid = zone_to_nid(zone);
20652065 unsigned long nr_pages = 0;
@@ -2085,10 +2085,10 @@ deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn, · 19 unmodified lines
20852085
20862086 spfn = chunk_end;
20872087
2088− if (irqs_disabled())
2089− touch_nmi_watchdog();
2090− else
2088+ if (can_resched)
20912089 cond_resched();
2090+ else
2091+ touch_nmi_watchdog();
20922092 }
20932093 }
20942094
@@ -2101,7 +2101,7 @@ deferred_init_memmap_job(unsigned long start_pfn, unsigned long end_pfn, · 6 unmodified lines
21012101 {
21022102 struct zone *zone = arg;
21032103
2104− deferred_init_memmap_chunk(start_pfn, end_pfn, zone);
2104+ deferred_init_memmap_chunk(start_pfn, end_pfn, zone, true);
21052105 }
21062106
21072107 static unsigned int __init
@@ -2216,7 +2216,7 @@ bool __init deferred_grow_zone(struct zone *zone, unsigned int order) · 108 unmodified lines
22162216 for (spfn = first_deferred_pfn, epfn = SECTION_ALIGN_UP(spfn + 1);
22172217 nr_pages < nr_pages_needed && spfn < zone_end_pfn(zone);
22182218 spfn = epfn, epfn += PAGES_PER_SECTION) {
2219− nr_pages += deferred_init_memmap_chunk(spfn, epfn, zone);
2219+ nr_pages += deferred_init_memmap_chunk(spfn, epfn, zone, false);
22202220 }
22212221
22222222 /*
mm/shmem.c+34−11
@@ -962,17 +962,29 @@ static void shmem_delete_from_page_cache(struct folio *folio, void *radswap) · 961 unmodified lines
962962 * being freed).
963963 */
964964 static long shmem_free_swap(struct address_space *mapping,
965− pgoff_t index, void *radswap)
965+ pgoff_t index, pgoff_t end, void *radswap)
966966 {
967− int order = xa_get_order(&mapping->i_pages, index);
968− void *old;
967+ XA_STATE(xas, &mapping->i_pages, index);
968+ unsigned int nr_pages = 0;
969+ pgoff_t base;
970+ void *entry;
969971
970− old = xa_cmpxchg_irq(&mapping->i_pages, index, radswap, NULL, 0);
971− if (old != radswap)
972− return 0;
973− free_swap_and_cache_nr(radix_to_swp_entry(radswap), 1 << order);
972+ xas_lock_irq(&xas);
973+ entry = xas_load(&xas);
974+ if (entry == radswap) {
975+ nr_pages = 1 << xas_get_order(&xas);
976+ base = round_down(xas.xa_index, nr_pages);
977+ if (base < index || base + nr_pages - 1 > end)
978+ nr_pages = 0;
979+ else
980+ xas_store(&xas, NULL);
981+ }
982+ xas_unlock_irq(&xas);
983+
984+ if (nr_pages)
985+ free_swap_and_cache_nr(radix_to_swp_entry(radswap), nr_pages);
974986
975− return 1 << order;
987+ return nr_pages;
976988 }
977989
978990 /*
@@ -1124,8 +1136,8 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, uoff_t lend, · 145 unmodified lines
11241136 if (xa_is_value(folio)) {
11251137 if (unfalloc)
11261138 continue;
1127− nr_swaps_freed += shmem_free_swap(mapping,
1128− indices[i], folio);
1139+ nr_swaps_freed += shmem_free_swap(mapping, indices[i],
1140+ end - 1, folio);
11291141 continue;
11301142 }
11311143
@@ -1191,12 +1203,23 @@ whole_folios: · 59 unmodified lines
11911203 folio = fbatch.folios[i];
11921204
11931205 if (xa_is_value(folio)) {
1206+ int order;
11941207 long swaps_freed;
11951208
11961209 if (unfalloc)
11971210 continue;
1198− swaps_freed = shmem_free_swap(mapping, indices[i], folio);
1211+ swaps_freed = shmem_free_swap(mapping, indices[i],
1212+ end - 1, folio);
11991213 if (!swaps_freed) {
1214+ /*
1215+ * If found a large swap entry cross the end border,
1216+ * skip it as the truncate_inode_partial_folio above
1217+ * should have at least zerod its content once.
1218+ */
1219+ order = shmem_confirm_swap(mapping, indices[i],
1220+ radix_to_swp_entry(folio));
1221+ if (order > 0 && indices[i] + (1 << order) > end)
1222+ continue;
12001223 /* Swap was replaced by page: retry */
12011224 index = indices[i];
12021225 break;
mm/swap.h+1−1
@@ -198,7 +198,7 @@ int swap_writeout(struct folio *folio, struct swap_iocb **swap_plug); · 197 unmodified lines
198198 void __swap_writepage(struct folio *folio, struct swap_iocb **swap_plug);
199199
200200 /* linux/mm/swap_state.c */
201−extern struct address_space swap_space __ro_after_init;
201+extern struct address_space swap_space __read_mostly;
202202 static inline struct address_space *swap_address_space(swp_entry_t entry)
203203 {
204204 return &swap_space;
mm/swap_state.c+1−2
@@ -37,8 +37,7 @@ static const struct address_space_operations swap_aops = { · 36 unmodified lines
3737 #endif
3838 };
3939
40−/* Set swap_space as read only as swap cache is handled by swap table */
41−struct address_space swap_space __ro_after_init = {
40+struct address_space swap_space __read_mostly = {
4241 .a_ops = &swap_aops,
4342 };
4443
mm/vmalloc.c+2−5
@@ -4322,7 +4322,7 @@ void *vrealloc_node_align_noprof(const void *p, size_t size, unsigned long align · 4321 unmodified lines
43224322 if (want_init_on_free() || want_init_on_alloc(flags))
43234323 memset((void *)p + size, 0, old_size - size);
43244324 vm->requested_size = size;
4325− kasan_poison_vmalloc(p + size, old_size - size);
4325+ kasan_vrealloc(p, old_size, size);
43264326 return (void *)p;
43274327 }
43284328
@@ -4330,16 +4330,13 @@ void *vrealloc_node_align_noprof(const void *p, size_t size, unsigned long align · 1 unmodified line
43304330 * We already have the bytes available in the allocation; use them.
43314331 */
43324332 if (size <= alloced_size) {
4333− kasan_unpoison_vmalloc(p + old_size, size - old_size,
4334− KASAN_VMALLOC_PROT_NORMAL |
4335− KASAN_VMALLOC_VM_ALLOC |
4336− KASAN_VMALLOC_KEEP_TAG);
43374333 /*
43384334 * No need to zero memory here, as unused memory will have
43394335 * already been zeroed at initial allocation time or during
43404336 * realloc shrink time.
43414337 */
43424338 vm->requested_size = size;
4339+ kasan_vrealloc(p, old_size, size);
43434340 return (void *)p;
43444341 }
43454342