From: "yu kuai" <yukuai@fygo.io>
To: "Chen Cheng" <chencheng@fnnas.com>, <linux-raid@vger.kernel.org>,
<yukuai@fygo.io>
Cc: <chencheng@fygo.io>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] md: scope memalloc_noio to allocation critical sections
Date: Sun, 19 Jul 2026 18:03:52 +0800 [thread overview]
Message-ID: <4a684c2f-6e24-4545-8b3d-6aaf7ace3cda@fygo.io> (raw)
In-Reply-To: <20260718084218.417895-1-chencheng@fnnas.com>
在 2026/7/18 16:42, Chen Cheng 写道:
> From: Chen Cheng<chencheng@fnnas.com>
>
> Save token as mddev-scoped in mddev->noio_flags cause PF_MEMALLOC_NOIO
> leak into task A, while task B restores a token that it never saved.
>
> scenario:
>
> task A mddev task B
> ====== ======= ============
> write suspend_lo
> mddev_suspend()
> suspended == 0
> drain active_io
> suspended = 1
> A: noio_A = memalloc_noio_save()
> A returns with PF_MEMALLOC_NOIO set
>
> write suspend_hi
> mddev_suspend()
> suspended == 1
> suspended = 2
> B returns
> (no save)
>
> mddev_resume()
> suspended = 1
> not last resume
> A returns
> A still has PF_MEMALLOC_NOIO <-- leaked
>
> mddev_resume()
> suspended = 0
> memalloc_noio_restore(noio_A)
> (restores A's token in B)
>
> Fixed by:
> call flags = memalloc_noio_save() directly in mdraid, where:
> 1) after array suspend succeed;
> 2) before allocating memory
>
> Validation:
> repeatedly updates the array's suspend_lo and suspend_hi sysfs from many
> concurrent userspace workers. That makes multiple tasks to call
> mddev_suspend()/mddev_resume() concurrently.
>
> Each worker:
> - reads its initial /proc/self/stat flags and verifies that PF_MEMALLOC_NOIO is not already
> set
> - writes 0 to either suspend_lo or suspend_hi
> - immediately reads its own task flags again
> - reports success if flags & PF_MEMALLOC_NOIO is true after the write returns
>
> Link:https://github.com/chencheng-fnnas/reproducer/blob/main/repro-md-noio-token-leak.sh
> Fixes: 78f57ef9d50a ("md: use memalloc scope APIs in mddev_suspend()/mddev_resume()")
>
> Signed-off-by: Chen Cheng<chencheng@fnnas.com>
> ---
>
> rfc -> v1:
> - dm-raid side just bypass because suspend and resume not in the
> same task context..
>
> v1 -> v2:
> - just call flags = memalloc_noio_save() directly in mdraid
> (suggest by Yu Kuai)
> ---
> drivers/md/md-bitmap.c | 3 +++
> drivers/md/md.c | 52 ++++++++++++++++++++++++++++--------------
> drivers/md/md.h | 1 -
> drivers/md/raid5.c | 14 ++++++++----
> 4 files changed, 47 insertions(+), 23 deletions(-)
Reviewed-by: Yu Kuai <yukuai@fygo.io>
--
Thanks,
Kuai
next prev parent reply other threads:[~2026-07-19 10:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-18 8:42 Chen Cheng
2026-07-19 10:03 ` yu kuai [this message]
2026-07-31 5:30 ` yu kuai
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=4a684c2f-6e24-4545-8b3d-6aaf7ace3cda@fygo.io \
--to=yukuai@fygo.io \
--cc=chencheng@fnnas.com \
--cc=chencheng@fygo.io \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.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
all inboxes | Powered by JetHome®