From: Kairui Song <ryncsn@gmail.com>
To: Youngjun Park <youngjun.park@lge.com>
Cc: "Rafael J . Wysocki" <rafael@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Chris Li <chrisl@kernel.org>, Kairui Song <kasong@tencent.com>,
Pavel Machek <pavel@kernel.org>,
Kemeng Shi <shikemeng@huaweicloud.com>,
Nhat Pham <nphamcs@gmail.com>, Baoquan He <bhe@redhat.com>,
Barry Song <baohua@kernel.org>,
Usama Arif <usama.arif@linux.dev>,
linux-pm@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH v8 1/2] mm/swap, PM: hibernate: fix swapoff race in uswsusp by pinning swap device
Date: Tue, 24 Mar 2026 13:53:33 +0800 [thread overview]
Message-ID: <acH_svpUwaNtFeJN@KASONG-MC4> (raw)
In-Reply-To: <20260323160822.1409904-2-youngjun.park@lge.com>
On Tue, Mar 24, 2026 at 01:08:21AM +0800, Youngjun Park wrote:
> Hibernation via uswsusp (/dev/snapshot ioctls) has a race window:
> after selecting the resume swap area but before user space is frozen,
> swapoff may run and invalidate the selected swap device.
>
> Fix this by pinning the swap device with SWP_HIBERNATION while it is
> in use. The pin is exclusive, which is sufficient since
> hibernate_acquire() already prevents concurrent hibernation sessions.
>
> The kernel swsusp path (sysfs-based hibernate/resume) uses
> find_hibernation_swap_type() which is not affected by the pin. It
> freezes user space before touching swap, so swapoff cannot race.
>
> Introduce dedicated helpers:
> - pin_hibernation_swap_type(): Look up and pin the swap device.
> Used by the uswsusp path.
> - find_hibernation_swap_type(): Lookup without pinning.
> Used by the kernel swsusp path.
> - unpin_hibernation_swap_type(): Clear the hibernation pin.
Looks good to me, thanks!
Reviewed-by: Kairui Song <kasong@tencent.com>
Just one trivial nit picks below.
> +/**
> + * unpin_hibernation_swap_type - Unpin the swap device for hibernation
> + * @type: Swap type previously returned by pin_hibernation_swap_type()
> + *
> + * Clear the hibernation pin on the given swap device, allowing
> + * swapoff() to proceed normally.
> + *
> + * If @type does not refer to a valid swap device, this function
> + * does nothing.
> + */
> +void unpin_hibernation_swap_type(int type)
> +{
> + struct swap_info_struct *si;
> +
> + spin_lock(&swap_lock);
> + si = swap_type_to_info(type);
> + if (!si) {
> + spin_unlock(&swap_lock);
> + return;
> + }
> + si->flags &= ~SWP_HIBERNATION;
Will the code will be simpler if you just:
if (si)
si->flags &= ~SWP_HIBERNATION;
Just personal taste, free feel to ignore.
And as you mentioned this is on top of swap table p3 so you based
it on mm-new - but isn't p3 already in mm-unstable? Maybe we can
have it there? Not sure how much conflict are there with PM.
The code and design looks OK.
next prev parent reply other threads:[~2026-03-24 5:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-23 16:08 [PATCH v8 0/2] mm/swap, PM: hibernate: fix swapoff race in uswsusp by pinning swap device Youngjun Park
2026-03-23 16:08 ` [PATCH v8 1/2] " Youngjun Park
2026-03-24 5:53 ` Kairui Song [this message]
2026-03-24 12:48 ` YoungJun Park
2026-03-23 16:08 ` [PATCH v8 2/2] mm/swap: remove redundant swap device reference in alloc/free Youngjun Park
2026-03-24 6:49 ` Kairui Song
2026-03-23 22:48 ` [PATCH v8 0/2] mm/swap, PM: hibernate: fix swapoff race in uswsusp by pinning swap device Andrew Morton
2026-03-24 2:51 ` YoungJun Park
2026-03-24 3:03 ` Andrew Morton
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=acH_svpUwaNtFeJN@KASONG-MC4 \
--to=ryncsn@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=bhe@redhat.com \
--cc=chrisl@kernel.org \
--cc=kasong@tencent.com \
--cc=linux-mm@kvack.org \
--cc=linux-pm@vger.kernel.org \
--cc=nphamcs@gmail.com \
--cc=pavel@kernel.org \
--cc=rafael@kernel.org \
--cc=shikemeng@huaweicloud.com \
--cc=usama.arif@linux.dev \
--cc=youngjun.park@lge.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