From: SeongJae Park <sj@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: SeongJae Park <sj@kernel.org>,
"Liam R. Howlett" <howlett@gmail.com>,
Davidlohr Bueso <dave@stgolabs.net>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
Shakeel Butt <shakeel.butt@linux.dev>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org, "Lai,
Yi" <yi1.lai@linux.intel.com>
Subject: [PATCH mm-unstable] mm/madvise: handle MADV_{HWPOISON,SOFT_OFFLINE} from madvise_unlock()
Date: Mon, 10 Feb 2025 22:32:01 -0800 [thread overview]
Message-ID: <20250211063201.5106-1-sj@kernel.org> (raw)
madvise_lock() does nothing for MADV_HWPOSION and MADV_SOFT_OFFLINE
behavior, but madvise_unlock() does mmap_lock unlocking regardless of
the behavior. Commit 948a0a9ea070 ("mm/madvise: split out mmap locking
operations for madvise()") in mm-unstable, which introduced the wrong
function didn't cause a real problem because do_madvise() was not
calling madvise_unlock() for the behavior.
Later, commit f19c9d7b57cf ("mm/madvise: split out madvise() behavior
execution") in mm-unstable made do_madvise() to call madvise_unlock()
even for the two behaviors. As a result, the kernel tries to unlock
unlocked mmap_lock.
Fix the issue by handling the two behaviors in madvise_unlock(). For
the two behaviors, do nothing but just return. Also remove an
unnecessary blank line in madvise_lock().
Technically speaking this patch fixes commit f19c9d7b57cf ("mm/madvise:
split out madvise() behavior execution"). But since the broken commit
is not in the mainline yet, squashing this fix into commit 948a0a9ea070
("mm/madvise: split out mmap locking operations for madvise()") would
make more sense, so adding Fixes: tag with it.
Fixes: 948a0a9ea070 ("mm/madvise: split out mmap locking operations for madvise()") # mm-unstable
Reported-by: "Lai, Yi" <yi1.lai@linux.intel.com>
Closes: https://lore.kernel.org/Z6rgiVp7221r4JZ5@ly-workstation
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/madvise.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/mm/madvise.c b/mm/madvise.c
index b5ef8e03d8b0..b8969457f3ef 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -1577,7 +1577,6 @@ int madvise_set_anon_name(struct mm_struct *mm, unsigned long start,
static int madvise_lock(struct mm_struct *mm, int behavior)
{
-
#ifdef CONFIG_MEMORY_FAILURE
if (behavior == MADV_HWPOISON || behavior == MADV_SOFT_OFFLINE)
return 0;
@@ -1595,6 +1594,11 @@ static int madvise_lock(struct mm_struct *mm, int behavior)
static void madvise_unlock(struct mm_struct *mm, int behavior)
{
+#ifdef CONFIG_MEMORY_FAILURE
+ if (behavior == MADV_HWPOISON || behavior == MADV_SOFT_OFFLINE)
+ return;
+#endif
+
if (madvise_need_mmap_write(behavior))
mmap_write_unlock(mm);
else
base-commit: 8bf30f9d23eb5040d37e6e712789cee8e71e1577
--
2.39.5
next reply other threads:[~2025-02-11 6:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-11 6:32 SeongJae Park [this message]
2025-02-11 10:51 ` Lorenzo Stoakes
2025-02-11 18:20 ` SeongJae Park
2025-02-12 11:35 ` Lorenzo Stoakes
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=20250211063201.5106-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=dave@stgolabs.net \
--cc=howlett@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=shakeel.butt@linux.dev \
--cc=yi1.lai@linux.intel.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