Skip to content

Commit d7c2b1f

Browse files
committed
Merge tag 'mm-hotfixes-stable-2022-11-11' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Pull misc hotfixes from Andrew Morton: "22 hotfixes. Eight are cc:stable and the remainder address issues which were introduced post-6.0 or which aren't considered serious enough to justify a -stable backport" * tag 'mm-hotfixes-stable-2022-11-11' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (22 commits) docs: kmsan: fix formatting of "Example report" mm/damon/dbgfs: check if rm_contexts input is for a real context maple_tree: don't set a new maximum on the node when not reusing nodes maple_tree: fix depth tracking in maple_state arch/x86/mm/hugetlbpage.c: pud_huge() returns 0 when using 2-level paging fs: fix leaked psi pressure state nilfs2: fix use-after-free bug of ns_writer on remount x86/traps: avoid KMSAN bugs originating from handle_bug() kmsan: make sure PREEMPT_RT is off Kconfig.debug: ensure early check for KMSAN in CONFIG_KMSAN_WARN x86/uaccess: instrument copy_from_user_nmi() kmsan: core: kmsan_in_runtime() should return true in NMI context mm: hugetlb_vmemmap: include missing linux/moduleparam.h mm/shmem: use page_mapping() to detect page cache for uffd continue mm/memremap.c: map FS_DAX device memory as decrypted Partly revert "mm/thp: carry over dirty bit when thp splits on pmd" nilfs2: fix deadlock in nilfs_count_free_blocks() mm/mmap: fix memory leak in mmap_region() hugetlbfs: don't delete error page from pagecache maple_tree: reorganize testing to restore module testing ...
2 parents 5ad6e7b + 436fa4a commit d7c2b1f

File tree

30 files changed

+37118
-36793
lines changed

30 files changed

+37118
-36793
lines changed

Documentation/dev-tools/kmsan.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ uninitialized in the local variable, as well as the stack where the value was
6767
copied to another memory location before use.
6868

6969
A use of uninitialized value ``v`` is reported by KMSAN in the following cases:
70+
7071
- in a condition, e.g. ``if (v) { ... }``;
7172
- in an indexing or pointer dereferencing, e.g. ``array[v]`` or ``*v``;
7273
- when it is copied to userspace or hardware, e.g. ``copy_to_user(..., &v, ...)``;

arch/x86/kernel/traps.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/context_tracking.h>
1616
#include <linux/interrupt.h>
1717
#include <linux/kallsyms.h>
18+
#include <linux/kmsan.h>
1819
#include <linux/spinlock.h>
1920
#include <linux/kprobes.h>
2021
#include <linux/uaccess.h>
@@ -301,6 +302,12 @@ static noinstr bool handle_bug(struct pt_regs *regs)
301302
{
302303
bool handled = false;
303304

305+
/*
306+
* Normally @regs are unpoisoned by irqentry_enter(), but handle_bug()
307+
* is a rare case that uses @regs without passing them to
308+
* irqentry_enter().
309+
*/
310+
kmsan_unpoison_entry_regs(regs);
304311
if (!is_valid_bugaddr(regs->ip))
305312
return handled;
306313

arch/x86/lib/usercopy.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <linux/uaccess.h>
88
#include <linux/export.h>
9+
#include <linux/instrumented.h>
910

1011
#include <asm/tlbflush.h>
1112

@@ -44,7 +45,9 @@ copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
4445
* called from other contexts.
4546
*/
4647
pagefault_disable();
48+
instrument_copy_from_user_before(to, from, n);
4749
ret = raw_copy_from_user(to, from, n);
50+
instrument_copy_from_user_after(to, from, n, ret);
4851
pagefault_enable();
4952

5053
return ret;

arch/x86/mm/hugetlbpage.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ int pmd_huge(pmd_t pmd)
3737
*/
3838
int pud_huge(pud_t pud)
3939
{
40+
#if CONFIG_PGTABLE_LEVELS > 2
4041
return !pud_none(pud) &&
4142
(pud_val(pud) & (_PAGE_PRESENT|_PAGE_PSE)) != _PAGE_PRESENT;
43+
#else
44+
return 0;
45+
#endif
4246
}
4347

4448
#ifdef CONFIG_HUGETLB_PAGE

fs/btrfs/compression.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ static u64 bio_end_offset(struct bio *bio)
512512
static noinline int add_ra_bio_pages(struct inode *inode,
513513
u64 compressed_end,
514514
struct compressed_bio *cb,
515-
unsigned long *pflags)
515+
int *memstall, unsigned long *pflags)
516516
{
517517
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
518518
unsigned long end_index;
@@ -581,8 +581,10 @@ static noinline int add_ra_bio_pages(struct inode *inode,
581581
continue;
582582
}
583583

584-
if (PageWorkingset(page))
584+
if (!*memstall && PageWorkingset(page)) {
585585
psi_memstall_enter(pflags);
586+
*memstall = 1;
587+
}
586588

587589
ret = set_page_extent_mapped(page);
588590
if (ret < 0) {
@@ -670,8 +672,8 @@ void btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
670672
u64 em_len;
671673
u64 em_start;
672674
struct extent_map *em;
673-
/* Initialize to 1 to make skip psi_memstall_leave unless needed */
674-
unsigned long pflags = 1;
675+
unsigned long pflags;
676+
int memstall = 0;
675677
blk_status_t ret;
676678
int ret2;
677679
int i;
@@ -727,7 +729,7 @@ void btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
727729
goto fail;
728730
}
729731

730-
add_ra_bio_pages(inode, em_start + em_len, cb, &pflags);
732+
add_ra_bio_pages(inode, em_start + em_len, cb, &memstall, &pflags);
731733

732734
/* include any pages we added in add_ra-bio_pages */
733735
cb->len = bio->bi_iter.bi_size;
@@ -807,7 +809,7 @@ void btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
807809
}
808810
}
809811

810-
if (!pflags)
812+
if (memstall)
811813
psi_memstall_leave(&pflags);
812814

813815
if (refcount_dec_and_test(&cb->pending_ios))

fs/erofs/zdata.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,8 +1412,8 @@ static void z_erofs_submit_queue(struct z_erofs_decompress_frontend *f,
14121412
struct block_device *last_bdev;
14131413
unsigned int nr_bios = 0;
14141414
struct bio *bio = NULL;
1415-
/* initialize to 1 to make skip psi_memstall_leave unless needed */
1416-
unsigned long pflags = 1;
1415+
unsigned long pflags;
1416+
int memstall = 0;
14171417

14181418
bi_private = jobqueueset_init(sb, q, fgq, force_fg);
14191419
qtail[JQ_BYPASS] = &q[JQ_BYPASS]->head;
@@ -1463,14 +1463,18 @@ static void z_erofs_submit_queue(struct z_erofs_decompress_frontend *f,
14631463
if (bio && (cur != last_index + 1 ||
14641464
last_bdev != mdev.m_bdev)) {
14651465
submit_bio_retry:
1466-
if (!pflags)
1467-
psi_memstall_leave(&pflags);
14681466
submit_bio(bio);
1467+
if (memstall) {
1468+
psi_memstall_leave(&pflags);
1469+
memstall = 0;
1470+
}
14691471
bio = NULL;
14701472
}
14711473

1472-
if (unlikely(PageWorkingset(page)))
1474+
if (unlikely(PageWorkingset(page)) && !memstall) {
14731475
psi_memstall_enter(&pflags);
1476+
memstall = 1;
1477+
}
14741478

14751479
if (!bio) {
14761480
bio = bio_alloc(mdev.m_bdev, BIO_MAX_VECS,
@@ -1500,9 +1504,9 @@ static void z_erofs_submit_queue(struct z_erofs_decompress_frontend *f,
15001504
} while (owned_head != Z_EROFS_PCLUSTER_TAIL);
15011505

15021506
if (bio) {
1503-
if (!pflags)
1504-
psi_memstall_leave(&pflags);
15051507
submit_bio(bio);
1508+
if (memstall)
1509+
psi_memstall_leave(&pflags);
15061510
}
15071511

15081512
/*

fs/hugetlbfs/inode.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,12 @@ static ssize_t hugetlbfs_read_iter(struct kiocb *iocb, struct iov_iter *to)
328328
} else {
329329
unlock_page(page);
330330

331+
if (PageHWPoison(page)) {
332+
put_page(page);
333+
retval = -EIO;
334+
break;
335+
}
336+
331337
/*
332338
* We have the page, copy it to user space buffer.
333339
*/
@@ -1111,13 +1117,6 @@ static int hugetlbfs_migrate_folio(struct address_space *mapping,
11111117
static int hugetlbfs_error_remove_page(struct address_space *mapping,
11121118
struct page *page)
11131119
{
1114-
struct inode *inode = mapping->host;
1115-
pgoff_t index = page->index;
1116-
1117-
hugetlb_delete_from_page_cache(page);
1118-
if (unlikely(hugetlb_unreserve_pages(inode, index, index + 1, 1)))
1119-
hugetlb_fix_reserve_counts(inode);
1120-
11211120
return 0;
11221121
}
11231122

fs/nilfs2/segment.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ void nilfs_relax_pressure_in_lock(struct super_block *sb)
317317
struct the_nilfs *nilfs = sb->s_fs_info;
318318
struct nilfs_sc_info *sci = nilfs->ns_writer;
319319

320-
if (!sci || !sci->sc_flush_request)
320+
if (sb_rdonly(sb) || unlikely(!sci) || !sci->sc_flush_request)
321321
return;
322322

323323
set_bit(NILFS_SC_PRIOR_FLUSH, &sci->sc_flags);
@@ -2242,7 +2242,7 @@ int nilfs_construct_segment(struct super_block *sb)
22422242
struct nilfs_sc_info *sci = nilfs->ns_writer;
22432243
struct nilfs_transaction_info *ti;
22442244

2245-
if (!sci)
2245+
if (sb_rdonly(sb) || unlikely(!sci))
22462246
return -EROFS;
22472247

22482248
/* A call inside transactions causes a deadlock. */
@@ -2280,7 +2280,7 @@ int nilfs_construct_dsync_segment(struct super_block *sb, struct inode *inode,
22802280
struct nilfs_transaction_info ti;
22812281
int err = 0;
22822282

2283-
if (!sci)
2283+
if (sb_rdonly(sb) || unlikely(!sci))
22842284
return -EROFS;
22852285

22862286
nilfs_transaction_lock(sb, &ti, 0);
@@ -2776,11 +2776,12 @@ int nilfs_attach_log_writer(struct super_block *sb, struct nilfs_root *root)
27762776

27772777
if (nilfs->ns_writer) {
27782778
/*
2779-
* This happens if the filesystem was remounted
2780-
* read/write after nilfs_error degenerated it into a
2781-
* read-only mount.
2779+
* This happens if the filesystem is made read-only by
2780+
* __nilfs_error or nilfs_remount and then remounted
2781+
* read/write. In these cases, reuse the existing
2782+
* writer.
27822783
*/
2783-
nilfs_detach_log_writer(sb);
2784+
return 0;
27842785
}
27852786

27862787
nilfs->ns_writer = nilfs_segctor_new(sb, root);

fs/nilfs2/super.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,8 +1133,6 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
11331133
if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb))
11341134
goto out;
11351135
if (*flags & SB_RDONLY) {
1136-
/* Shutting down log writer */
1137-
nilfs_detach_log_writer(sb);
11381136
sb->s_flags |= SB_RDONLY;
11391137

11401138
/*

fs/nilfs2/the_nilfs.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,7 @@ int nilfs_count_free_blocks(struct the_nilfs *nilfs, sector_t *nblocks)
690690
{
691691
unsigned long ncleansegs;
692692

693-
down_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem);
694693
ncleansegs = nilfs_sufile_get_ncleansegs(nilfs->ns_sufile);
695-
up_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem);
696694
*nblocks = (sector_t)ncleansegs * nilfs->ns_blocks_per_segment;
697695
return 0;
698696
}

0 commit comments

Comments
 (0)