Skip to content

Commit 440b789

Browse files
committed
Merge tag 'mm-hotfixes-stable-2022-10-20' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Pull misc fixes from Andrew Morron: "Seventeen hotfixes, mainly for MM. Five are cc:stable and the remainder address post-6.0 issues" * tag 'mm-hotfixes-stable-2022-10-20' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: nouveau: fix migrate_to_ram() for faulting page mm/huge_memory: do not clobber swp_entry_t during THP split hugetlb: fix memory leak associated with vma_lock structure mm/page_alloc: reduce potential fragmentation in make_alloc_exact() mm: /proc/pid/smaps_rollup: fix maple tree search mm,hugetlb: take hugetlb_lock before decrementing h->resv_huge_pages mm/mmap: fix MAP_FIXED address return on VMA merge mm/mmap.c: __vma_adjust(): suppress uninitialized var warning mm/mmap: undo ->mmap() when mas_preallocate() fails init: Kconfig: fix spelling mistake "satify" -> "satisfy" ocfs2: clear dinode links count in case of error ocfs2: fix BUG when iput after ocfs2_mknod fails gcov: support GCC 12.1 and newer compilers zsmalloc: zs_destroy_pool: add size_class NULL check mm/mempolicy: fix mbind_range() arguments to vma_merge() mailmap: update email for Qais Yousef mailmap: update Dan Carpenter's email address
2 parents ce3d90a + 97061d4 commit 440b789

File tree

12 files changed

+107
-51
lines changed

12 files changed

+107
-51
lines changed

.mailmap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ Christoph Hellwig <[email protected]>
104104
105105
Corey Minyard <[email protected]>
106106
Damian Hobson-Garcia <[email protected]>
107+
107108
108109
109110
@@ -353,7 +354,8 @@ Peter Oruba <[email protected]>
353354
354355
Praveen BP <[email protected]>
355356
356-
357+
358+
357359
358360
359361

drivers/gpu/drm/nouveau/nouveau_dmem.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ static vm_fault_t nouveau_dmem_migrate_to_ram(struct vm_fault *vmf)
176176
.src = &src,
177177
.dst = &dst,
178178
.pgmap_owner = drm->dev,
179+
.fault_page = vmf->page,
179180
.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE,
180181
};
181182

fs/ocfs2/namei.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ static int ocfs2_mknod(struct user_namespace *mnt_userns,
232232
handle_t *handle = NULL;
233233
struct ocfs2_super *osb;
234234
struct ocfs2_dinode *dirfe;
235+
struct ocfs2_dinode *fe = NULL;
235236
struct buffer_head *new_fe_bh = NULL;
236237
struct inode *inode = NULL;
237238
struct ocfs2_alloc_context *inode_ac = NULL;
@@ -382,6 +383,7 @@ static int ocfs2_mknod(struct user_namespace *mnt_userns,
382383
goto leave;
383384
}
384385

386+
fe = (struct ocfs2_dinode *) new_fe_bh->b_data;
385387
if (S_ISDIR(mode)) {
386388
status = ocfs2_fill_new_dir(osb, handle, dir, inode,
387389
new_fe_bh, data_ac, meta_ac);
@@ -454,8 +456,11 @@ static int ocfs2_mknod(struct user_namespace *mnt_userns,
454456
leave:
455457
if (status < 0 && did_quota_inode)
456458
dquot_free_inode(inode);
457-
if (handle)
459+
if (handle) {
460+
if (status < 0 && fe)
461+
ocfs2_set_links_count(fe, 0);
458462
ocfs2_commit_trans(osb, handle);
463+
}
459464

460465
ocfs2_inode_unlock(dir, 1);
461466
if (did_block_signals)
@@ -632,18 +637,9 @@ static int ocfs2_mknod_locked(struct ocfs2_super *osb,
632637
return status;
633638
}
634639

635-
status = __ocfs2_mknod_locked(dir, inode, dev, new_fe_bh,
640+
return __ocfs2_mknod_locked(dir, inode, dev, new_fe_bh,
636641
parent_fe_bh, handle, inode_ac,
637642
fe_blkno, suballoc_loc, suballoc_bit);
638-
if (status < 0) {
639-
u64 bg_blkno = ocfs2_which_suballoc_group(fe_blkno, suballoc_bit);
640-
int tmp = ocfs2_free_suballoc_bits(handle, inode_ac->ac_inode,
641-
inode_ac->ac_bh, suballoc_bit, bg_blkno, 1);
642-
if (tmp)
643-
mlog_errno(tmp);
644-
}
645-
646-
return status;
647643
}
648644

649645
static int ocfs2_mkdir(struct user_namespace *mnt_userns,
@@ -2028,8 +2024,11 @@ static int ocfs2_symlink(struct user_namespace *mnt_userns,
20282024
ocfs2_clusters_to_bytes(osb->sb, 1));
20292025
if (status < 0 && did_quota_inode)
20302026
dquot_free_inode(inode);
2031-
if (handle)
2027+
if (handle) {
2028+
if (status < 0 && fe)
2029+
ocfs2_set_links_count(fe, 0);
20322030
ocfs2_commit_trans(osb, handle);
2031+
}
20332032

20342033
ocfs2_inode_unlock(dir, 1);
20352034
if (did_block_signals)

fs/proc/task_mmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ static int show_smaps_rollup(struct seq_file *m, void *v)
902902
goto out_put_mm;
903903

904904
hold_task_mempolicy(priv);
905-
vma = mas_find(&mas, 0);
905+
vma = mas_find(&mas, ULONG_MAX);
906906

907907
if (unlikely(!vma))
908908
goto empty_set;

init/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ config RUST_IS_AVAILABLE
6666
This shows whether a suitable Rust toolchain is available (found).
6767

6868
Please see Documentation/rust/quick-start.rst for instructions on how
69-
to satify the build requirements of Rust support.
69+
to satisfy the build requirements of Rust support.
7070

7171
In particular, the Makefile target 'rustavailable' is useful to check
7272
why the Rust toolchain is not being detected.

kernel/gcov/gcc_4_7.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030

3131
#define GCOV_TAG_FUNCTION_LENGTH 3
3232

33+
/* Since GCC 12.1 sizes are in BYTES and not in WORDS (4B). */
34+
#if (__GNUC__ >= 12)
35+
#define GCOV_UNIT_SIZE 4
36+
#else
37+
#define GCOV_UNIT_SIZE 1
38+
#endif
39+
3340
static struct gcov_info *gcov_info_head;
3441

3542
/**
@@ -383,12 +390,18 @@ size_t convert_to_gcda(char *buffer, struct gcov_info *info)
383390
pos += store_gcov_u32(buffer, pos, info->version);
384391
pos += store_gcov_u32(buffer, pos, info->stamp);
385392

393+
#if (__GNUC__ >= 12)
394+
/* Use zero as checksum of the compilation unit. */
395+
pos += store_gcov_u32(buffer, pos, 0);
396+
#endif
397+
386398
for (fi_idx = 0; fi_idx < info->n_functions; fi_idx++) {
387399
fi_ptr = info->functions[fi_idx];
388400

389401
/* Function record. */
390402
pos += store_gcov_u32(buffer, pos, GCOV_TAG_FUNCTION);
391-
pos += store_gcov_u32(buffer, pos, GCOV_TAG_FUNCTION_LENGTH);
403+
pos += store_gcov_u32(buffer, pos,
404+
GCOV_TAG_FUNCTION_LENGTH * GCOV_UNIT_SIZE);
392405
pos += store_gcov_u32(buffer, pos, fi_ptr->ident);
393406
pos += store_gcov_u32(buffer, pos, fi_ptr->lineno_checksum);
394407
pos += store_gcov_u32(buffer, pos, fi_ptr->cfg_checksum);
@@ -402,7 +415,8 @@ size_t convert_to_gcda(char *buffer, struct gcov_info *info)
402415
/* Counter record. */
403416
pos += store_gcov_u32(buffer, pos,
404417
GCOV_TAG_FOR_COUNTER(ct_idx));
405-
pos += store_gcov_u32(buffer, pos, ci_ptr->num * 2);
418+
pos += store_gcov_u32(buffer, pos,
419+
ci_ptr->num * 2 * GCOV_UNIT_SIZE);
406420

407421
for (cv_idx = 0; cv_idx < ci_ptr->num; cv_idx++) {
408422
pos += store_gcov_u64(buffer, pos,

mm/huge_memory.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2455,7 +2455,16 @@ static void __split_huge_page_tail(struct page *head, int tail,
24552455
page_tail);
24562456
page_tail->mapping = head->mapping;
24572457
page_tail->index = head->index + tail;
2458-
page_tail->private = 0;
2458+
2459+
/*
2460+
* page->private should not be set in tail pages with the exception
2461+
* of swap cache pages that store the swp_entry_t in tail pages.
2462+
* Fix up and warn once if private is unexpectedly set.
2463+
*/
2464+
if (!folio_test_swapcache(page_folio(head))) {
2465+
VM_WARN_ON_ONCE_PAGE(page_tail->private != 0, head);
2466+
page_tail->private = 0;
2467+
}
24592468

24602469
/* Page flags must be visible before we make the page non-compound. */
24612470
smp_wmb();

mm/hugetlb.c

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,15 +1014,23 @@ void hugetlb_dup_vma_private(struct vm_area_struct *vma)
10141014
VM_BUG_ON_VMA(!is_vm_hugetlb_page(vma), vma);
10151015
/*
10161016
* Clear vm_private_data
1017+
* - For shared mappings this is a per-vma semaphore that may be
1018+
* allocated in a subsequent call to hugetlb_vm_op_open.
1019+
* Before clearing, make sure pointer is not associated with vma
1020+
* as this will leak the structure. This is the case when called
1021+
* via clear_vma_resv_huge_pages() and hugetlb_vm_op_open has already
1022+
* been called to allocate a new structure.
10171023
* - For MAP_PRIVATE mappings, this is the reserve map which does
10181024
* not apply to children. Faults generated by the children are
10191025
* not guaranteed to succeed, even if read-only.
1020-
* - For shared mappings this is a per-vma semaphore that may be
1021-
* allocated in a subsequent call to hugetlb_vm_op_open.
10221026
*/
1023-
vma->vm_private_data = (void *)0;
1024-
if (!(vma->vm_flags & VM_MAYSHARE))
1025-
return;
1027+
if (vma->vm_flags & VM_MAYSHARE) {
1028+
struct hugetlb_vma_lock *vma_lock = vma->vm_private_data;
1029+
1030+
if (vma_lock && vma_lock->vma != vma)
1031+
vma->vm_private_data = NULL;
1032+
} else
1033+
vma->vm_private_data = NULL;
10261034
}
10271035

10281036
/*
@@ -2924,11 +2932,11 @@ struct page *alloc_huge_page(struct vm_area_struct *vma,
29242932
page = alloc_buddy_huge_page_with_mpol(h, vma, addr);
29252933
if (!page)
29262934
goto out_uncharge_cgroup;
2935+
spin_lock_irq(&hugetlb_lock);
29272936
if (!avoid_reserve && vma_has_reserves(vma, gbl_chg)) {
29282937
SetHPageRestoreReserve(page);
29292938
h->resv_huge_pages--;
29302939
}
2931-
spin_lock_irq(&hugetlb_lock);
29322940
list_add(&page->lru, &h->hugepage_activelist);
29332941
set_page_refcounted(page);
29342942
/* Fall through */
@@ -4601,6 +4609,7 @@ static void hugetlb_vm_op_open(struct vm_area_struct *vma)
46014609
struct resv_map *resv = vma_resv_map(vma);
46024610

46034611
/*
4612+
* HPAGE_RESV_OWNER indicates a private mapping.
46044613
* This new VMA should share its siblings reservation map if present.
46054614
* The VMA will only ever have a valid reservation map pointer where
46064615
* it is being copied for another still existing VMA. As that VMA
@@ -4615,11 +4624,21 @@ static void hugetlb_vm_op_open(struct vm_area_struct *vma)
46154624

46164625
/*
46174626
* vma_lock structure for sharable mappings is vma specific.
4618-
* Clear old pointer (if copied via vm_area_dup) and create new.
4627+
* Clear old pointer (if copied via vm_area_dup) and allocate
4628+
* new structure. Before clearing, make sure vma_lock is not
4629+
* for this vma.
46194630
*/
46204631
if (vma->vm_flags & VM_MAYSHARE) {
4621-
vma->vm_private_data = NULL;
4622-
hugetlb_vma_lock_alloc(vma);
4632+
struct hugetlb_vma_lock *vma_lock = vma->vm_private_data;
4633+
4634+
if (vma_lock) {
4635+
if (vma_lock->vma != vma) {
4636+
vma->vm_private_data = NULL;
4637+
hugetlb_vma_lock_alloc(vma);
4638+
} else
4639+
pr_warn("HugeTLB: vma_lock already exists in %s.\n", __func__);
4640+
} else
4641+
hugetlb_vma_lock_alloc(vma);
46234642
}
46244643
}
46254644

mm/mempolicy.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -787,17 +787,22 @@ static int vma_replace_policy(struct vm_area_struct *vma,
787787
static int mbind_range(struct mm_struct *mm, unsigned long start,
788788
unsigned long end, struct mempolicy *new_pol)
789789
{
790-
MA_STATE(mas, &mm->mm_mt, start - 1, start - 1);
790+
MA_STATE(mas, &mm->mm_mt, start, start);
791791
struct vm_area_struct *prev;
792792
struct vm_area_struct *vma;
793793
int err = 0;
794794
pgoff_t pgoff;
795795

796-
prev = mas_find_rev(&mas, 0);
797-
if (prev && (start < prev->vm_end))
798-
vma = prev;
799-
else
800-
vma = mas_next(&mas, end - 1);
796+
prev = mas_prev(&mas, 0);
797+
if (unlikely(!prev))
798+
mas_set(&mas, start);
799+
800+
vma = mas_find(&mas, end - 1);
801+
if (WARN_ON(!vma))
802+
return 0;
803+
804+
if (start > vma->vm_start)
805+
prev = vma;
801806

802807
for (; vma; vma = mas_next(&mas, end - 1)) {
803808
unsigned long vmstart = max(start, vma->vm_start);

mm/mmap.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,8 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
618618
struct vm_area_struct *expand)
619619
{
620620
struct mm_struct *mm = vma->vm_mm;
621-
struct vm_area_struct *next_next, *next = find_vma(mm, vma->vm_end);
621+
struct vm_area_struct *next_next = NULL; /* uninit var warning */
622+
struct vm_area_struct *next = find_vma(mm, vma->vm_end);
622623
struct vm_area_struct *orig_vma = vma;
623624
struct address_space *mapping = NULL;
624625
struct rb_root_cached *root = NULL;
@@ -2625,14 +2626,14 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
26252626
if (error)
26262627
goto unmap_and_free_vma;
26272628

2628-
/* Can addr have changed??
2629-
*
2630-
* Answer: Yes, several device drivers can do it in their
2631-
* f_op->mmap method. -DaveM
2629+
/*
2630+
* Expansion is handled above, merging is handled below.
2631+
* Drivers should not alter the address of the VMA.
26322632
*/
2633-
WARN_ON_ONCE(addr != vma->vm_start);
2634-
2635-
addr = vma->vm_start;
2633+
if (WARN_ON((addr != vma->vm_start))) {
2634+
error = -EINVAL;
2635+
goto close_and_free_vma;
2636+
}
26362637
mas_reset(&mas);
26372638

26382639
/*
@@ -2654,7 +2655,6 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
26542655
vm_area_free(vma);
26552656
vma = merge;
26562657
/* Update vm_flags to pick up the change. */
2657-
addr = vma->vm_start;
26582658
vm_flags = vma->vm_flags;
26592659
goto unmap_writable;
26602660
}
@@ -2681,7 +2681,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
26812681
if (mas_preallocate(&mas, vma, GFP_KERNEL)) {
26822682
error = -ENOMEM;
26832683
if (file)
2684-
goto unmap_and_free_vma;
2684+
goto close_and_free_vma;
26852685
else
26862686
goto free_vma;
26872687
}

0 commit comments

Comments
 (0)