public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Kairui Song <ryncsn@gmail.com>
To: stable@vger.kernel.org, Greg KH <gregkh@linuxfoundation.org>
Cc: Matthew Wilcox <willy@infradead.org>,
	Jens Axboe <axboe@kernel.dk>, David Howells <dhowells@redhat.com>,
	Dave Chinner <david@fromorbit.com>,
	Christian Theune <ct@flyingcircus.io>,
	Christian Brauner <brauner@kernel.org>,
	Chris Mason <clm@meta.com>, Sam James <sam@gentoo.org>,
	Daniel Dao <dqminh@cloudflare.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Kairui Song <kasong@tencent.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH 6.1.y 6.6.y 1/3] mm/filemap: return early if failed to allocate memory for split
Date: Wed,  2 Oct 2024 05:06:23 +0800	[thread overview]
Message-ID: <20241001210625.95825-2-ryncsn@gmail.com> (raw)
In-Reply-To: <20241001210625.95825-1-ryncsn@gmail.com>

From: Kairui Song <kasong@tencent.com>

commit de60fd8ddeda2b41fbe11df11733838c5f684616 upstream.

xas_split_alloc could fail with NOMEM, and in such case, it should abort
early instead of keep going and fail the xas_split below.

Link: https://lkml.kernel.org/r/20240416071722.45997-1-ryncsn@gmail.com
Link: https://lkml.kernel.org/r/20240415171857.19244-1-ryncsn@gmail.com
Link: https://lkml.kernel.org/r/20240415171857.19244-2-ryncsn@gmail.com
Signed-off-by: Kairui Song <kasong@tencent.com>
Acked-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Stable-dep-of: 6758c1128ceb ("mm/filemap: optimize filemap folio adding")
---
 mm/filemap.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mm/filemap.c b/mm/filemap.c
index 2809b1174f04..f85c13a1b739 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -867,9 +867,12 @@ noinline int __filemap_add_folio(struct address_space *mapping,
 		unsigned int order = xa_get_order(xas.xa, xas.xa_index);
 		void *entry, *old = NULL;
 
-		if (order > folio_order(folio))
+		if (order > folio_order(folio)) {
 			xas_split_alloc(&xas, xa_load(xas.xa, xas.xa_index),
 					order, gfp);
+			if (xas_error(&xas))
+				goto error;
+		}
 		xas_lock_irq(&xas);
 		xas_for_each_conflict(&xas, entry) {
 			old = entry;
-- 
2.46.1


  reply	other threads:[~2024-10-01 21:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-01 21:06 [PATCH 6.1.y 6.6.y 0/3] mm/filemap: fix page cache corruption with large folios Kairui Song
2024-10-01 21:06 ` Kairui Song [this message]
2025-03-22 21:51   ` [PATCH 6.1.y 6.6.y 1/3] mm/filemap: return early if failed to allocate memory for split Sasha Levin
2024-10-01 21:06 ` [PATCH 6.1.y 6.6.y 2/3] lib/xarray: introduce a new helper xas_get_order Kairui Song
2025-03-22 21:51   ` Sasha Levin
2024-10-01 21:06 ` [PATCH 6.1.y 6.6.y 3/3] mm/filemap: optimize filemap folio adding Kairui Song
2025-03-22 21:50   ` Sasha Levin
2024-10-02  9:58 ` [PATCH 6.1.y 6.6.y 0/3] mm/filemap: fix page cache corruption with large folios Greg KH
2025-03-22 12:16 ` Yafang Shao
2025-03-22 15:53   ` Linus Torvalds
2025-03-23 11:18     ` Christian Theune
2025-03-23 13:20     ` Yafang Shao
2025-03-24  3:02     ` [PATCH 6.1.y] Revert "xfs: Support large folios" Yafang Shao
2025-03-24 15:40       ` Greg KH
2025-03-25 11:33       ` Sasha Levin

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=20241001210625.95825-2-ryncsn@gmail.com \
    --to=ryncsn@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=clm@meta.com \
    --cc=ct@flyingcircus.io \
    --cc=david@fromorbit.com \
    --cc=dhowells@redhat.com \
    --cc=dqminh@cloudflare.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kasong@tencent.com \
    --cc=sam@gentoo.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=willy@infradead.org \
    /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