Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Pratyush Yadav" <pratyush@kernel.org>,
	"Alexander Viro" <viro@zeniv.linux.org.uk>,
	"Christian Brauner" <brauner@kernel.org>,
	"Jan Kara" <jack@suse.cz>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	"Hugh Dickins" <hughd@google.com>,
	"Baolin Wang" <baolin.wang@linux.alibaba.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"David Hildenbrand" <david@kernel.org>, "Zi Yan" <ziy@nvidia.com>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Nico Pache" <nico.pache@linux.dev>,
	"Ryan Roberts" <ryan.roberts@arm.com>,
	"Dev Jain" <dev.jain@arm.com>, "Barry Song" <baohua@kernel.org>,
	"Lance Yang" <lance.yang@linux.dev>,
	"Usama Arif" <usama.arif@linux.dev>,
	"Kiryl Shutsemau" <kas@kernel.org>,
	"Pasha Tatashin" <pasha.tatashin@soleen.com>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Matthew Brost" <matthew.brost@intel.com>,
	"Joshua Hahn" <joshua.hahnjy@gmail.com>,
	"Byungchul Park" <byungchul@sk.com>,
	"Gregory Price" <gourry@gourry.net>,
	"Ying Huang" <ying.huang@linux.alibaba.com>,
	"Alistair Popple" <apopple@nvidia.com>,
	"Kairui Song" <kasong@tencent.com>,
	"Qi Zheng" <qi.zheng@linux.dev>,
	"Shakeel Butt" <shakeel.butt@linux.dev>,
	"Axel Rasmussen" <axelrasmussen@google.com>,
	"Yuanchu Xie" <yuanchu@google.com>, "Wei Xu" <weixugc@google.com>,
	"Baoquan He" <baoquan.he@linux.dev>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Hocko" <mhocko@kernel.org>,
	"Lorenzo Stoakes" <ljs@kernel.org>
Cc: linux-mm@kvack.org, kexec@lists.infradead.org
Subject: Re: [PATCH 3/3] mm: shmem: use mapping_set_frozen() for memfd preservation
Date: Wed, 28 Oct 2026 17:31:21 +0000	[thread overview]
Message-ID: <sashiko-outbox-188237@kernel.org> (raw)
In-Reply-To: <20261027173031.763213-4-pratyush@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] mm: shmem: broken mapping_frozen() check ordering in shmem_setattr()
- [High] mm: shmem: shmem_write_begin() allows extending i_size on frozen mappings
--

commit f05d5b8fc61839cbb16ea914eab638cf83da5354
Author: Pratyush Yadav (Google) <pratyush@kernel.org>

mm: shmem: use mapping_set_frozen() for memfd preservation

This commit replaces the shmem-specific SHMEM_F_MAPPING_FROZEN flag with
generic page cache mapping_set_frozen() and mapping_frozen() helpers for
memfd live update preservation. It also updates shmem_setattr(),
shmem_write_begin(), and shmem_fallocate() to rely on the frozen mapping
state.

> diff --git a/mm/shmem.c b/mm/shmem.c
> index 6507b4246c8af..1c70fd306bec2 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -1570,8 +1570,6 @@ static int shmem_setattr(struct mnt_idmap *idmap,
>  			return -EPERM;
>  
>  		if (newsize != oldsize) {
> -			if (info->flags & SHMEM_F_MAPPING_FROZEN)
> -				return -EPERM;
>  			error = shmem_reacct_size(SHMEM_I(inode)->flags,
>  					oldsize, newsize);
>  			if (error)
> @@ -1583,6 +1581,11 @@ static int shmem_setattr(struct mnt_idmap *idmap,
>  		}
>  		if (newsize <= oldsize) {
>  			loff_t holebegin = round_up(newsize, PAGE_SIZE);
> +
> +			/* No truncation allowed on a frozen mapping. */
> +			if (mapping_frozen(inode->i_mapping))
> +				return -EBUSY;

[Severity: High]
Does moving the frozen check after the newsize != oldsize block corrupt
inode->i_size and VM memory accounting on shrink, while allowing a frozen
memfd to grow via truncate()?

In mm/shmem.c:shmem_setattr(), when attr->ia_valid & ATTR_SIZE is set:

	if (newsize != oldsize) {
		error = shmem_reacct_size(SHMEM_I(inode)->flags,
				oldsize, newsize);
		if (error)
			return error;
		i_size_write(inode, newsize);
		update_mtime = true;
	}

When shrinking a frozen file (newsize < oldsize), shmem_reacct_size()
unaccounts VM_ACCT(oldsize) - VM_ACCT(newsize) via vm_unacct_memory() and
i_size_write() updates inode->i_size before the newsize <= oldsize block
checks mapping_frozen(inode->i_mapping) and returns -EBUSY without rolling
back either change or truncating the pages past the new EOF.

When growing a frozen file (newsize > oldsize), the newsize <= oldsize
branch is not taken at all, so mapping_frozen() is never checked and
inode->i_size increases even though memfd_luo_preserve() already recorded
ser->size and memfd_luo_freeze() only updates ser->pos.

Should mapping_frozen(inode->i_mapping) be checked before the
newsize != oldsize block so all ATTR_SIZE changes on frozen mappings are
rejected before modifying state?

> @@ -3482,10 +3485,6 @@ shmem_write_begin(const struct kiocb *iocb, struct address_space *mapping,
>  			return -EPERM;
>  	}
>  
> -	if (unlikely((info->flags & SHMEM_F_MAPPING_FROZEN) &&
> -		     pos + len > inode->i_size))
> -		return -EPERM;
> -
>  	ret = shmem_get_folio(inode, index, pos + len, &folio, SGP_WRITE);
>  	if (ret)
>  		return ret;

[Severity: High]
Can removing this check allow buffered writes to extend inode->i_size on a
frozen mapping when a folio is already resident at index?

If a preserved memfd has an unaligned i_size, a large folio spanning past
i_size, or folios preallocated beyond i_size with FALLOC_FL_KEEP_SIZE,
shmem_get_folio() finds the existing folio in i_pages without allocating and
inserting a new folio, so the frozen mapping check in page cache insertion
is not triggered.

Then mm/shmem.c:shmem_write_end() extends inode->i_size:

	if (pos + copied > inode->i_size)
		i_size_write(inode, pos + copied);

Because mm/memfd_luo.c:memfd_luo_preserve() captures ser->size during
preservation and memfd_luo_freeze() only updates ser->pos, any size extension
and data written past the preserved size will be lost across kexec.

Should shmem_write_begin() still reject writes with pos + len > inode->i_size
when mapping_frozen(mapping) is true?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261027173031.763213-1-pratyush@kernel.org?part=3


  reply	other threads:[~2026-10-28 17:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 17:30 [PATCH 0/3] mm: allow freezing mappings Pratyush Yadav
2026-10-27 17:30 ` [PATCH 1/3] mm/memfd_luo: don't use memfd_pin_folios() Pratyush Yadav
2026-10-28 17:31   ` sashiko-bot
2026-10-28 20:18   ` Pasha Tatashin
2026-10-28 23:04     ` Pratyush Yadav
2026-10-29  0:01       ` Pasha Tatashin
2026-10-29 13:15         ` Pratyush Yadav
2026-10-27 17:30 ` [PATCH 2/3] mm: allow freezing i_pages Pratyush Yadav
2026-10-28 17:31   ` sashiko-bot
2026-10-27 17:30 ` [PATCH 3/3] mm: shmem: use mapping_set_frozen() for memfd preservation Pratyush Yadav
2026-10-28 17:31   ` sashiko-bot [this message]
2026-10-27 17:35 ` [PATCH 0/3] mm: allow freezing mappings David Hildenbrand (Arm)
2026-10-27 17:38   ` Pratyush Yadav
2026-10-27 18:59     ` David Hildenbrand (Arm)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-188237@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=apopple@nvidia.com \
    --cc=axelrasmussen@google.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=baoquan.he@linux.dev \
    --cc=brauner@kernel.org \
    --cc=byungchul@sk.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=gourry@gourry.net \
    --cc=hannes@cmpxchg.org \
    --cc=hughd@google.com \
    --cc=jack@suse.cz \
    --cc=joshua.hahnjy@gmail.com \
    --cc=kas@kernel.org \
    --cc=kasong@tencent.com \
    --cc=kexec@lists.infradead.org \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=matthew.brost@intel.com \
    --cc=mhocko@kernel.org \
    --cc=nico.pache@linux.dev \
    --cc=pasha.tatashin@soleen.com \
    --cc=pratyush@kernel.org \
    --cc=qi.zheng@linux.dev \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=usama.arif@linux.dev \
    --cc=viro@zeniv.linux.org.uk \
    --cc=weixugc@google.com \
    --cc=willy@infradead.org \
    --cc=ying.huang@linux.alibaba.com \
    --cc=yuanchu@google.com \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox