Skip to content

Commit 4aa748d

Browse files
committed
Merge tag 'mm-hotfixes-stable-2024-12-21-12-09' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Pull misc fixes from Andrew Morton: "25 hotfixes. 16 are cc:stable. 19 are MM and 6 are non-MM. The usual bunch of singletons and doubletons - please see the relevant changelogs for details" * tag 'mm-hotfixes-stable-2024-12-21-12-09' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (25 commits) mm: huge_memory: handle strsep not finding delimiter alloc_tag: fix set_codetag_empty() when !CONFIG_MEM_ALLOC_PROFILING_DEBUG alloc_tag: fix module allocation tags populated area calculation mm/codetag: clear tags before swap mm/vmstat: fix a W=1 clang compiler warning mm: convert partially_mapped set/clear operations to be atomic nilfs2: fix buffer head leaks in calls to truncate_inode_pages() vmalloc: fix accounting with i915 mm/page_alloc: don't call pfn_to_page() on possibly non-existent PFN in split_large_buddy() fork: avoid inappropriate uprobe access to invalid mm nilfs2: prevent use of deleted inode zram: fix uninitialized ZRAM not releasing backing device zram: refuse to use zero sized block device as backing device mm: use clear_user_(high)page() for arch with special user folio handling mm: introduce cpu_icache_is_aliasing() across all architectures mm: add RCU annotation to pte_offset_map(_lock) mm: correctly reference merged VMA mm: use aligned address in copy_user_gigantic_page() mm: use aligned address in clear_gigantic_page() mm: shmem: fix ShmemHugePages at swapout ...
2 parents e84a3bf + d3ac65d commit 4aa748d

File tree

30 files changed

+1049
-102
lines changed

30 files changed

+1049
-102
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ Wolfram Sang <[email protected]> <[email protected]>
735735
736736
737737
738+
738739
Yusuke Goda <[email protected]>
739740
740741

Documentation/mm/process_addrs.rst

Lines changed: 850 additions & 0 deletions
Large diffs are not rendered by default.

arch/arc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
config ARC
77
def_bool y
88
select ARC_TIMERS
9+
select ARCH_HAS_CPU_CACHE_ALIASING
910
select ARCH_HAS_CACHE_LINE_SIZE
1011
select ARCH_HAS_DEBUG_VM_PGTABLE
1112
select ARCH_HAS_DMA_PREP_COHERENT

arch/arc/include/asm/cachetype.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef __ASM_ARC_CACHETYPE_H
3+
#define __ASM_ARC_CACHETYPE_H
4+
5+
#define cpu_dcache_is_aliasing() false
6+
#define cpu_icache_is_aliasing() true
7+
8+
#endif

drivers/block/zram/zram_drv.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,12 @@ static ssize_t backing_dev_store(struct device *dev,
614614
}
615615

616616
nr_pages = i_size_read(inode) >> PAGE_SHIFT;
617+
/* Refuse to use zero sized device (also prevents self reference) */
618+
if (!nr_pages) {
619+
err = -EINVAL;
620+
goto out;
621+
}
622+
617623
bitmap_sz = BITS_TO_LONGS(nr_pages) * sizeof(long);
618624
bitmap = kvzalloc(bitmap_sz, GFP_KERNEL);
619625
if (!bitmap) {
@@ -1438,12 +1444,16 @@ static void zram_meta_free(struct zram *zram, u64 disksize)
14381444
size_t num_pages = disksize >> PAGE_SHIFT;
14391445
size_t index;
14401446

1447+
if (!zram->table)
1448+
return;
1449+
14411450
/* Free all pages that are still in this zram device */
14421451
for (index = 0; index < num_pages; index++)
14431452
zram_free_page(zram, index);
14441453

14451454
zs_destroy_pool(zram->mem_pool);
14461455
vfree(zram->table);
1456+
zram->table = NULL;
14471457
}
14481458

14491459
static bool zram_meta_alloc(struct zram *zram, u64 disksize)
@@ -2320,11 +2330,6 @@ static void zram_reset_device(struct zram *zram)
23202330

23212331
zram->limit_pages = 0;
23222332

2323-
if (!init_done(zram)) {
2324-
up_write(&zram->init_lock);
2325-
return;
2326-
}
2327-
23282333
set_capacity_and_notify(zram->disk, 0);
23292334
part_stat_set_all(zram->disk->part0, 0);
23302335

fs/hugetlbfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,
825825
error = PTR_ERR(folio);
826826
goto out;
827827
}
828-
folio_zero_user(folio, ALIGN_DOWN(addr, hpage_size));
828+
folio_zero_user(folio, addr);
829829
__folio_mark_uptodate(folio);
830830
error = hugetlb_add_to_page_cache(folio, mapping, index);
831831
if (unlikely(error)) {

fs/nilfs2/btnode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void nilfs_init_btnc_inode(struct inode *btnc_inode)
3535
ii->i_flags = 0;
3636
memset(&ii->i_bmap_data, 0, sizeof(struct nilfs_bmap));
3737
mapping_set_gfp_mask(btnc_inode->i_mapping, GFP_NOFS);
38+
btnc_inode->i_mapping->a_ops = &nilfs_buffer_cache_aops;
3839
}
3940

4041
void nilfs_btnode_cache_clear(struct address_space *btnc)

fs/nilfs2/gcinode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ int nilfs_init_gcinode(struct inode *inode)
163163

164164
inode->i_mode = S_IFREG;
165165
mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
166-
inode->i_mapping->a_ops = &empty_aops;
166+
inode->i_mapping->a_ops = &nilfs_buffer_cache_aops;
167167

168168
ii->i_flags = 0;
169169
nilfs_bmap_init_gc(ii->i_bmap);

fs/nilfs2/inode.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ const struct address_space_operations nilfs_aops = {
276276
.is_partially_uptodate = block_is_partially_uptodate,
277277
};
278278

279+
const struct address_space_operations nilfs_buffer_cache_aops = {
280+
.invalidate_folio = block_invalidate_folio,
281+
};
282+
279283
static int nilfs_insert_inode_locked(struct inode *inode,
280284
struct nilfs_root *root,
281285
unsigned long ino)
@@ -544,8 +548,14 @@ struct inode *nilfs_iget(struct super_block *sb, struct nilfs_root *root,
544548
inode = nilfs_iget_locked(sb, root, ino);
545549
if (unlikely(!inode))
546550
return ERR_PTR(-ENOMEM);
547-
if (!(inode->i_state & I_NEW))
551+
552+
if (!(inode->i_state & I_NEW)) {
553+
if (!inode->i_nlink) {
554+
iput(inode);
555+
return ERR_PTR(-ESTALE);
556+
}
548557
return inode;
558+
}
549559

550560
err = __nilfs_read_inode(sb, root, ino, inode);
551561
if (unlikely(err)) {
@@ -675,6 +685,7 @@ struct inode *nilfs_iget_for_shadow(struct inode *inode)
675685
NILFS_I(s_inode)->i_flags = 0;
676686
memset(NILFS_I(s_inode)->i_bmap, 0, sizeof(struct nilfs_bmap));
677687
mapping_set_gfp_mask(s_inode->i_mapping, GFP_NOFS);
688+
s_inode->i_mapping->a_ops = &nilfs_buffer_cache_aops;
678689

679690
err = nilfs_attach_btree_node_cache(s_inode);
680691
if (unlikely(err)) {

fs/nilfs2/namei.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ nilfs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
6767
inode = NULL;
6868
} else {
6969
inode = nilfs_iget(dir->i_sb, NILFS_I(dir)->i_root, ino);
70+
if (inode == ERR_PTR(-ESTALE)) {
71+
nilfs_error(dir->i_sb,
72+
"deleted inode referenced: %lu", ino);
73+
return ERR_PTR(-EIO);
74+
}
7075
}
7176

7277
return d_splice_alias(inode, dentry);

fs/nilfs2/nilfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ extern const struct file_operations nilfs_dir_operations;
401401
extern const struct inode_operations nilfs_file_inode_operations;
402402
extern const struct file_operations nilfs_file_operations;
403403
extern const struct address_space_operations nilfs_aops;
404+
extern const struct address_space_operations nilfs_buffer_cache_aops;
404405
extern const struct inode_operations nilfs_dir_inode_operations;
405406
extern const struct inode_operations nilfs_special_inode_operations;
406407
extern const struct inode_operations nilfs_symlink_inode_operations;

fs/ocfs2/localalloc.c

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -971,9 +971,9 @@ static int ocfs2_sync_local_to_main(struct ocfs2_super *osb,
971971
start = count = 0;
972972
left = le32_to_cpu(alloc->id1.bitmap1.i_total);
973973

974-
while ((bit_off = ocfs2_find_next_zero_bit(bitmap, left, start)) <
975-
left) {
976-
if (bit_off == start) {
974+
while (1) {
975+
bit_off = ocfs2_find_next_zero_bit(bitmap, left, start);
976+
if ((bit_off < left) && (bit_off == start)) {
977977
count++;
978978
start++;
979979
continue;
@@ -998,29 +998,12 @@ static int ocfs2_sync_local_to_main(struct ocfs2_super *osb,
998998
}
999999
}
10001000

1001+
if (bit_off >= left)
1002+
break;
10011003
count = 1;
10021004
start = bit_off + 1;
10031005
}
10041006

1005-
/* clear the contiguous bits until the end boundary */
1006-
if (count) {
1007-
blkno = la_start_blk +
1008-
ocfs2_clusters_to_blocks(osb->sb,
1009-
start - count);
1010-
1011-
trace_ocfs2_sync_local_to_main_free(
1012-
count, start - count,
1013-
(unsigned long long)la_start_blk,
1014-
(unsigned long long)blkno);
1015-
1016-
status = ocfs2_release_clusters(handle,
1017-
main_bm_inode,
1018-
main_bm_bh, blkno,
1019-
count);
1020-
if (status < 0)
1021-
mlog_errno(status);
1022-
}
1023-
10241007
bail:
10251008
if (status)
10261009
mlog_errno(status);

include/linux/alloc_tag.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ static inline void set_codetag_empty(union codetag_ref *ref)
6363
#else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */
6464

6565
static inline bool is_codetag_empty(union codetag_ref *ref) { return false; }
66-
static inline void set_codetag_empty(union codetag_ref *ref) {}
66+
67+
static inline void set_codetag_empty(union codetag_ref *ref)
68+
{
69+
if (ref)
70+
ref->ct = NULL;
71+
}
6772

6873
#endif /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */
6974

@@ -135,7 +140,7 @@ static inline struct alloc_tag_counters alloc_tag_read(struct alloc_tag *tag)
135140
#ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG
136141
static inline void alloc_tag_add_check(union codetag_ref *ref, struct alloc_tag *tag)
137142
{
138-
WARN_ONCE(ref && ref->ct,
143+
WARN_ONCE(ref && ref->ct && !is_codetag_empty(ref),
139144
"alloc_tag was not cleared (got tag for %s:%u)\n",
140145
ref->ct->filename, ref->ct->lineno);
141146

include/linux/cacheinfo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,14 @@ static inline int get_cpu_cacheinfo_id(int cpu, int level)
155155

156156
#ifndef CONFIG_ARCH_HAS_CPU_CACHE_ALIASING
157157
#define cpu_dcache_is_aliasing() false
158+
#define cpu_icache_is_aliasing() cpu_dcache_is_aliasing()
158159
#else
159160
#include <asm/cachetype.h>
161+
162+
#ifndef cpu_icache_is_aliasing
163+
#define cpu_icache_is_aliasing() cpu_dcache_is_aliasing()
164+
#endif
165+
160166
#endif
161167

162168
#endif /* _LINUX_CACHEINFO_H */

include/linux/highmem.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,13 @@ static inline
224224
struct folio *vma_alloc_zeroed_movable_folio(struct vm_area_struct *vma,
225225
unsigned long vaddr)
226226
{
227-
return vma_alloc_folio(GFP_HIGHUSER_MOVABLE | __GFP_ZERO, 0, vma, vaddr);
227+
struct folio *folio;
228+
229+
folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, vaddr);
230+
if (folio && user_alloc_needs_zeroing())
231+
clear_user_highpage(&folio->page, vaddr);
232+
233+
return folio;
228234
}
229235
#endif
230236

include/linux/mm.h

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <linux/kasan.h>
3232
#include <linux/memremap.h>
3333
#include <linux/slab.h>
34+
#include <linux/cacheinfo.h>
3435

3536
struct mempolicy;
3637
struct anon_vma;
@@ -3010,7 +3011,15 @@ static inline void pagetable_pte_dtor(struct ptdesc *ptdesc)
30103011
lruvec_stat_sub_folio(folio, NR_PAGETABLE);
30113012
}
30123013

3013-
pte_t *__pte_offset_map(pmd_t *pmd, unsigned long addr, pmd_t *pmdvalp);
3014+
pte_t *___pte_offset_map(pmd_t *pmd, unsigned long addr, pmd_t *pmdvalp);
3015+
static inline pte_t *__pte_offset_map(pmd_t *pmd, unsigned long addr,
3016+
pmd_t *pmdvalp)
3017+
{
3018+
pte_t *pte;
3019+
3020+
__cond_lock(RCU, pte = ___pte_offset_map(pmd, addr, pmdvalp));
3021+
return pte;
3022+
}
30143023
static inline pte_t *pte_offset_map(pmd_t *pmd, unsigned long addr)
30153024
{
30163025
return __pte_offset_map(pmd, addr, NULL);
@@ -3023,7 +3032,8 @@ static inline pte_t *pte_offset_map_lock(struct mm_struct *mm, pmd_t *pmd,
30233032
{
30243033
pte_t *pte;
30253034

3026-
__cond_lock(*ptlp, pte = __pte_offset_map_lock(mm, pmd, addr, ptlp));
3035+
__cond_lock(RCU, __cond_lock(*ptlp,
3036+
pte = __pte_offset_map_lock(mm, pmd, addr, ptlp)));
30273037
return pte;
30283038
}
30293039

@@ -4175,6 +4185,23 @@ static inline int do_mseal(unsigned long start, size_t len_in, unsigned long fla
41754185
}
41764186
#endif
41774187

4188+
/*
4189+
* user_alloc_needs_zeroing checks if a user folio from page allocator needs to
4190+
* be zeroed or not.
4191+
*/
4192+
static inline bool user_alloc_needs_zeroing(void)
4193+
{
4194+
/*
4195+
* for user folios, arch with cache aliasing requires cache flush and
4196+
* arc changes folio->flags to make icache coherent with dcache, so
4197+
* always return false to make caller use
4198+
* clear_user_page()/clear_user_highpage().
4199+
*/
4200+
return cpu_dcache_is_aliasing() || cpu_icache_is_aliasing() ||
4201+
!static_branch_maybe(CONFIG_INIT_ON_ALLOC_DEFAULT_ON,
4202+
&init_on_alloc);
4203+
}
4204+
41784205
int arch_get_shadow_stack_status(struct task_struct *t, unsigned long __user *status);
41794206
int arch_set_shadow_stack_status(struct task_struct *t, unsigned long status);
41804207
int arch_lock_shadow_stack_status(struct task_struct *t, unsigned long status);

include/linux/page-flags.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -862,18 +862,10 @@ static inline void ClearPageCompound(struct page *page)
862862
ClearPageHead(page);
863863
}
864864
FOLIO_FLAG(large_rmappable, FOLIO_SECOND_PAGE)
865-
FOLIO_TEST_FLAG(partially_mapped, FOLIO_SECOND_PAGE)
866-
/*
867-
* PG_partially_mapped is protected by deferred_split split_queue_lock,
868-
* so its safe to use non-atomic set/clear.
869-
*/
870-
__FOLIO_SET_FLAG(partially_mapped, FOLIO_SECOND_PAGE)
871-
__FOLIO_CLEAR_FLAG(partially_mapped, FOLIO_SECOND_PAGE)
865+
FOLIO_FLAG(partially_mapped, FOLIO_SECOND_PAGE)
872866
#else
873867
FOLIO_FLAG_FALSE(large_rmappable)
874-
FOLIO_TEST_FLAG_FALSE(partially_mapped)
875-
__FOLIO_SET_FLAG_NOOP(partially_mapped)
876-
__FOLIO_CLEAR_FLAG_NOOP(partially_mapped)
868+
FOLIO_FLAG_FALSE(partially_mapped)
877869
#endif
878870

879871
#define PG_head_mask ((1UL << PG_head))

include/linux/vmstat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ static inline const char *node_stat_name(enum node_stat_item item)
515515

516516
static inline const char *lru_list_name(enum lru_list lru)
517517
{
518-
return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
518+
return node_stat_name(NR_LRU_BASE + (enum node_stat_item)lru) + 3; // skip "nr_"
519519
}
520520

521521
#if defined(CONFIG_VM_EVENT_COUNTERS) || defined(CONFIG_MEMCG)

kernel/fork.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -639,11 +639,8 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
639639
LIST_HEAD(uf);
640640
VMA_ITERATOR(vmi, mm, 0);
641641

642-
uprobe_start_dup_mmap();
643-
if (mmap_write_lock_killable(oldmm)) {
644-
retval = -EINTR;
645-
goto fail_uprobe_end;
646-
}
642+
if (mmap_write_lock_killable(oldmm))
643+
return -EINTR;
647644
flush_cache_dup_mm(oldmm);
648645
uprobe_dup_mmap(oldmm, mm);
649646
/*
@@ -782,8 +779,6 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
782779
dup_userfaultfd_complete(&uf);
783780
else
784781
dup_userfaultfd_fail(&uf);
785-
fail_uprobe_end:
786-
uprobe_end_dup_mmap();
787782
return retval;
788783

789784
fail_nomem_anon_vma_fork:
@@ -1692,9 +1687,11 @@ static struct mm_struct *dup_mm(struct task_struct *tsk,
16921687
if (!mm_init(mm, tsk, mm->user_ns))
16931688
goto fail_nomem;
16941689

1690+
uprobe_start_dup_mmap();
16951691
err = dup_mmap(mm, oldmm);
16961692
if (err)
16971693
goto free_pt;
1694+
uprobe_end_dup_mmap();
16981695

16991696
mm->hiwater_rss = get_mm_rss(mm);
17001697
mm->hiwater_vm = mm->total_vm;
@@ -1709,6 +1706,8 @@ static struct mm_struct *dup_mm(struct task_struct *tsk,
17091706
mm->binfmt = NULL;
17101707
mm_init_owner(mm, NULL);
17111708
mmput(mm);
1709+
if (err)
1710+
uprobe_end_dup_mmap();
17121711

17131712
fail_nomem:
17141713
return NULL;

0 commit comments

Comments
 (0)