From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90DEE287503 for ; Thu, 2 Apr 2026 17:54:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775152458; cv=none; b=cQWbEwbISTZpNG5udI1fwtzMdT+YfIEObt8EWSzKZaufqFSd6E01gw6Klom3PZpnHMkmsBLsHQVIv9D5N61kobL8Ck3TKqXWf7ZERfH1sMKC9zNvmx7wtYwO83at3AgwE6SIcBu+yF5PZJi2Jm1N63nVa9UsGjbGZ+e4vqiZHJs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775152458; c=relaxed/simple; bh=ohA1vLaZYkMMUT2MxNiBsI1iR7gLzjDmahvd/sGiQgs=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=spJFu/9uXuWneYF9GdE0UZNWjB6HVnlLx9qlnI3oJWS0sovg9G4Aen7IuXnDzSVM+oQLrvqt9k95sHMQm1jOz/DNsFihXoSB2u6Jd5GeG5JwdrXy63oHfq5yw9h5ZI8m+fFnYkpwDhKTGTPwtL9wPbdcUcE5dntXZk9TDZVAARM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=CWCGGADv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="CWCGGADv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3C29C116C6; Thu, 2 Apr 2026 17:54:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1775152458; bh=ohA1vLaZYkMMUT2MxNiBsI1iR7gLzjDmahvd/sGiQgs=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=CWCGGADvtvRKN2WyO+UfdjqpjwayOjBtuRXAbw/bh2xZ5Se6sGj8zMiOafMSdWuvR u7w7E0C9EduOGZ/bZc+9XF/6qveWEBuEJcp6/zLtWg8yoXTj4t6A8nOye8aldpy5/p Y7u7HvO4mbIh8zcfOor0A5wZY1y1GbqKQRn9sbdU= Date: Thu, 2 Apr 2026 10:54:17 -0700 From: Andrew Morton To: Pratyush Yadav Cc: Chenghao Duan , pasha.tatashin@soleen.com, rppt@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, jianghaoran@kylinos.cn Subject: Re: [PATCH v3 6/7] mm/memfd_luo: remove folio from page cache when accounting fails Message-Id: <20260402105417.b495f2fbe9069caa19ea7b05@linux-foundation.org> In-Reply-To: <2vxzzf3lfujq.fsf@kernel.org> References: <20260326084727.118437-1-duanchenghao@kylinos.cn> <20260326084727.118437-7-duanchenghao@kylinos.cn> <2vxzzf3lfujq.fsf@kernel.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 02 Apr 2026 11:52:57 +0000 Pratyush Yadav wrote: > So I think the commit message needs reworking. Perhaps something like > the below: > > ... > > With that, > > Reviewed-by: Pratyush Yadav Thanks, I did this: From: Chenghao Duan Subject: mm/memfd_luo: remove folio from page cache when accounting fails Date: Thu, 26 Mar 2026 16:47:26 +0800 In memfd_luo_retrieve_folios(), when shmem_inode_acct_blocks() fails after successfully adding the folio to the page cache, the code jumps to unlock_folio without removing the folio from the page cache. While the folio eventually will be freed when the file is released by memfd_luo_retrieve(), it is a good idea to directly remove a folio that was not fully added to the file. This avoids the possibility of accounting mismatches in shmem or filemap core. Fix by adding a remove_from_cache label that calls filemap_remove_folio() before unlocking, matching the error handling pattern in shmem_alloc_and_add_folio(). This issue was identified by AI review: https://sashiko.dev/#/patchset/20260323110747.193569-1-duanchenghao@kylinos.cn [pratyush@kernel.org: changelog alterations] Link: https://lkml.kernel.org/r/2vxzzf3lfujq.fsf@kernel.org Link: https://lkml.kernel.org/r/20260326084727.118437-7-duanchenghao@kylinos.cn Signed-off-by: Chenghao Duan Reviewed-by: Pasha Tatashin Reviewed-by: Pratyush Yadav Cc: Haoran Jiang Cc: Mike Rapoport (Microsoft) Signed-off-by: Andrew Morton --- mm/memfd_luo.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/mm/memfd_luo.c~mm-memfd_luo-remove-folio-from-page-cache-when-accounting-fails +++ a/mm/memfd_luo.c @@ -461,7 +461,7 @@ static int memfd_luo_retrieve_folios(str if (err) { pr_err("shmem: failed to account folio index %ld(%ld pages): %d\n", i, npages, err); - goto unlock_folio; + goto remove_from_cache; } nr_added_pages += npages; @@ -474,6 +474,8 @@ static int memfd_luo_retrieve_folios(str return 0; +remove_from_cache: + filemap_remove_folio(folio); unlock_folio: folio_unlock(folio); folio_put(folio); _