From: YoungJun Park <youngjun.park@lge.com>
To: Kairui Song <ryncsn@gmail.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 21:48:04 +0900 [thread overview]
Message-ID: <acKIBGjQDZrMQXjF@yjaykim-PowerEdge-T330> (raw)
In-Reply-To: <acH_svpUwaNtFeJN@KASONG-MC4>
On Tue, Mar 24, 2026 at 01:53:33PM +0800, Kairui Song wrote:
> 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>
Thanks for the review, Kairui, and for all your feedback throughout
the revisions!
> 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.
Noted on the style preference. I'll keep it in mind. :D
> 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.
Regarding the base branch. Andrew is already aware of the
potential conflicts in linux-next, and we've discussed possibly
parking this for the next cycle depending on Rafael's input.
So I think we can keep it as-is for now and see how things go!
Best regards,
Youngjun Park
next prev parent reply other threads:[~2026-03-24 12:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-23 16:08 [PATCH v8 0/2] " Youngjun Park
2026-03-23 16:08 ` [PATCH v8 1/2] " Youngjun Park
2026-03-24 5:53 ` Kairui Song
2026-03-24 12:48 ` YoungJun Park [this message]
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=acKIBGjQDZrMQXjF@yjaykim-PowerEdge-T330 \
--to=youngjun.park@lge.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=ryncsn@gmail.com \
--cc=shikemeng@huaweicloud.com \
--cc=usama.arif@linux.dev \
/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