From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A07BA606A322 for ; Fri, 4 Dec 2026 16:48:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dQVIS/Ly Received: by kanga.kvack.org (Postfix) id A9BEB6B05BC; Fri, 4 Dec 2026 11:48:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A4C566B05BE; Fri, 4 Dec 2026 11:48:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 986836B05BC; Fri, 4 Dec 2026 11:48:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1B0C66B05BC for ; Fri, 4 Dec 2026 11:48:25 -0500 (EST) Received: from smtpin22.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 09B7AC0523 for ; Fri, 4 Dec 2026 16:48:24 +0000 (UTC) X-FDA: 85506883728.22.B812390 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf18.hostedemail.com (Postfix) with ESMTP id 647E11C0015 for ; Fri, 4 Dec 2026 16:48:22 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b="dQVIS/Ly"; spf=pass (imf18.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796402902; b=FYo2YG/v4d0I9pI8tNkyZOV+iLgjBUCEJ8l+nke0adriFfwrhWOTtnGtpz9KUXE9lc4Avg 47XvDf8ZKQMR8yhXi/4QXJ9EmQYIzdUEJOFqLpP5yMrkAcWPyAzmZBnN7dmSpvded3QG1j Dn4MuXcyV1G3XxRHyMAI//7kBk7/7lY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796402902; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VxsfQd6dg5CYmvfv1BCqmr9luYAEhY3eK1BYLthF3oo=; b=a+2gyNxNQCMTg14fPQQzgzbcMOIlp5xheHi2r6SiM51BxfuW0M+V0Uy/nJcT3cyR7aTrct u5DpmGTgld8gDOgc+NRxi/0LkgFZK3t3AJXCxlQeuOr149APNsj/0p/JLvbHxA7apAuq/8 fy3pKJ/kFlGL/RBVSoN/AfGBwA1m3qk= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b="dQVIS/Ly"; spf=pass (imf18.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id ED67462026; Fri, 4 Dec 2026 16:48:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80FA91F00A0E; Fri, 4 Dec 2026 16:48:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796402901; bh=VxsfQd6dg5CYmvfv1BCqmr9luYAEhY3eK1BYLthF3oo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=dQVIS/Lyc9X2nm46ovS7kxh7SUK/61dc7Z4a9nkTeJNf/0VhNeIhK7NqIkBAhuFuS VwC0SfyX0rXtNL9l6FfqDwGmLnE0H4OnDRinRzselS+nvhKzcynD1cv3KoycseEoAx vNSoS6ZakiOSu2bM0W96XCEXgv6Y0eYf9LBrvdI9TVk3vDElWsuEiWL8jocR4OVgmu 0t64DDHiKLo7miO2WkM0PrkJit50pxf4MnYdLrquOVul91G28HVVIMKJozNEm9a+cp Uyz3Z5Nm5C8NIRyNx/PFQQFWpH3Hbmk34Dg2PPb6LaS4A+XA+keHAve4PKYS/NbjDT 9ShfgpSWHWrBA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v8 07/14] mm, swap: refactor swapoff and add xswap_destroy Reply-To: sashiko-reviews@lists.linux.dev To: "Baoquan He" , linux-mm@kvack.org Cc: akpm@linux-foundation.org, david@kernel.org, corbet@lwn.net, chrisl@kernel.org, kasong@tencent.com, urezki@gmail.com, hannes@cmpxchg.org, yosry@kernel.org, nphamcs@gmail.com, baohua@kernel.org, youngjun.park@lge.com, kunwu.chan@gmail.com, klarasmodin@gmail.com, "Baoquan He" In-Reply-To: <20261203164336.864691-8-baoquan.he@linux.dev> References: <20261203164336.864691-1-baoquan.he@linux.dev> <20261203164336.864691-8-baoquan.he@linux.dev> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 16:48:20 +0000 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 647E11C0015 X-Rspam-User: X-Stat-Signature: z67x6ptespetk7ozjnpj87qwdo9uwg5m X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796402902-545317 X-HE-Meta: U2FsdGVkX1/6t7VNq1xB2qIGKT75SMyNEZPWuiX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WXp31nX6tQXTJECyS4ZNFzZWDGcKZv4dayW1TAsIUrDGOnwlogzXBXLs45oroJHFCwSdryuIDjzAZHTYqnRuAZduK3V7jy4SPVdMAUxVSjgzv5b2DwxJZVZFJigwL6DsJBps01Mx3f3Kd+UqIUJZULMCmYWtYhMGJF6+53She027nhxjxqqXpKPB0FGi1/CbctRBJfPqWxgWz156X1TLOux8F/J6l82BxCs1MMGcACn/kAcAlqg0Ap94gKD7nTJKp0aEjSD5OPtDjOeawB40rAM9rpqW0gbLMJJLDCKKwOUjzhl2h+eMhO6r5I6zjD3rVAD6yxWp/UEQfe+mQPIMD14mrgkGfrBBxR+x5BvJd1n7uiEEDNTg+ryG7HGTG/K4DIH5qT0ydkrEqbkoZxw2Xt2MPKube9tgko1ICcQWBNZR0Kc7jHKM2Yd91rAOetYkzV0dIs46MZsJMkhM1xMFeLyhOp/miwFn3EIBqA9e6kT+yrbyiRcz89fPW5KeiIxqdv8KMletnNhXG3w5VFOh/QbeSC4LpPDysT7+2Sk/G8FvZ/Uzjlhx/x9n0worAT2IEICg5mdroMHah0uW39AwHo4P49r3VHlU2aAP6nDucHtP/fhrSHhPqMx7Ctc3fwQcX+iyRKRw4uIhlhJ0GcidlMy8FniV9qXDzui8pgE0w8oLcJsroWCt7fE3OcGFM39/4Y+pLR8rUmnnSfBJ3ruB1BWwVVd2eNbekPPcETy9yQAFFOr1bwxv7dqEo3ehZasxMvmpdNiOCFgSeMzz/zweawXQlqgkqtqqLyjFlQQB0KpRSyAtri Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] mm: swapoff() open-first relative lookup for xswap enables CWD shadowing - [Medium] mm: xswap_destroy() holds uninterruptible xswap_ctl_lock across __swapoff() - [Low] mm: unannotated data race on si->flags in /proc/swaps vs xswap_destroy() -- commit 238343efb8d379276ae632b33dfaa8a1b5aa260e Author: Baoquan He mm, swap: refactor swapoff and add xswap_destroy This commit extracts swap_info_remove() and __swapoff() from sys_swapoff() to support file-less swap devices, and adds xswap_destroy() reached via the name printed in /proc/swaps. > diff --git a/mm/swapfile.c b/mm/swapfile.c > index 4e598ab8da656..1f319e365b68e 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c [ ... ] > @@ -3375,15 +3383,30 @@ SYSCALL_DEFINE1(swapoff, const char __user *, spe= cialfile) > BUG_ON(!current->mm); > =20 > CLASS(filename, pathname)(specialfile); > + if (IS_ERR(pathname)) > + return PTR_ERR(pathname); > + > victim =3D file_open_name(pathname, O_RDWR|O_LARGEFILE, 0); > - if (IS_ERR(victim)) > - return PTR_ERR(victim); > + if (IS_ERR(victim)) { > + /* > + * /proc/swaps shows a name that cannot be opened; accept it > + * so swapoff -a works. Only -ENOENT means "no such path", > + * so a file of that name keeps precedence. > + */ > + if (PTR_ERR(victim) !=3D -ENOENT) > + return PTR_ERR(victim); > + > + err =3D xswap_destroy_by_name(pathname->name); > + if (err =3D=3D -ENOENT) > + return PTR_ERR(victim); > + return err; > + } [Severity: Medium] Can resolving "xswap" through file_open_name() first break swapoff -a and allow working-directory shadowing? file_open_name() resolves relative names against AT_FDCWD, so any ./xswap file or directory in the working directory makes swapoff -a fail with -EINVAL or -EISDIR instead of reaching xswap_destroy_by_name(). Userspace then has no unambiguous path to deactivate xswap. A symlink ./xswap can also redirect root's O_RDWR open to another swap device or device node, and a dangling symlink returns -ENOENT and falls through to xswap_destroy() despite a filesystem entry existing. [ ... ] > @@ -3485,13 +3544,10 @@ SYSCALL_DEFINE1(swapoff, const char __user *, spe= cialfile) > p->flags =3D 0; > spin_unlock(&swap_lock); [Severity: Low] Is there an unannotated data race on p->flags between xswap teardown and /proc/swaps readers? swap_start(), swap_next(), and swap_type_str() hold only swapon_mutex and read si->flags directly without READ_ONCE() or swap_lock: CPU0 CPU1 __swapoff() swap_start() mutex_lock(&swapon_mutex) ... mutex_unlock(&swapon_mutex) mutex_lock(&swapon_mutex) spin_lock(&swap_lock) p->flags =3D 0 if (!si->swap_file && !((si->flags & SWP_XSWAP) && (si->flags & SWP_WRITEOK))) <-- data race on si->flags del_from_avail_list() and reinsert_swap_info() also modify si->flags without swapon_mutex or WRITE_ONCE(). This triggers KCSAN reports and allows tearing across the two flag checks; annotating these accesses with READ_ONCE()/WRITE_ONCE() would fix the race. [ ... ] > @@ -4114,7 +4170,57 @@ static int xswap_create(int prio) > goto out; > } > =20 > -/* A name, not a path: only -ENOENT from opening it gets here. */ > +/* Tear down the file-less xswap device. */ > +static int xswap_destroy(void) > +{ > + struct swap_info_struct *p =3D NULL; > + unsigned int type; > + int err; > + > + mutex_lock(&xswap_ctl_lock); > + > + spin_lock(&swap_lock); > + /* Only a fully enabled device; a half-created one does not count. */ > + for (type =3D 0; type < nr_swapfiles; type++) { > + struct swap_info_struct *q =3D swap_info[type]; > + > + if (q && (q->flags & (SWP_XSWAP | SWP_WRITEOK)) =3D=3D > + (SWP_XSWAP | SWP_WRITEOK)) { > + p =3D q; > + break; > + } > + } > + if (!p) { > + spin_unlock(&swap_lock); > + err =3D -ENOENT; > + goto out; > + } > + /* Refuse swapoff while the device is pinned for hibernation */ > + if (p->flags & SWP_HIBERNATION) { > + spin_unlock(&swap_lock); > + err =3D -EBUSY; > + goto out; > + } > + > + err =3D swap_info_remove(p); > + spin_unlock(&swap_lock); > + if (!err) > + err =3D __swapoff(p); > +out: > + mutex_unlock(&xswap_ctl_lock); > + return err; > +} [Severity: Medium] Can holding xswap_ctl_lock across __swapoff() stall concurrent swapon and swapoff callers in unkillable D-state? __swapoff() runs try_to_unuse(), which retries without a cap while draining swap, followed by synchronize_rcu(), wait_for_completion(), and flush_work(). Both xswap_create() and xswap_destroy() take xswap_ctl_lock with mutex_lock(), so a concurrent caller cannot be killed and can trigger hung-task warnings or panics. Releasing xswap_ctl_lock before __swapoff() still keeps the single device invariant: swap_info_remove() already cleared SWP_WRITEOK (so another xswap_destroy() gets -ENOENT), while SWP_XSWAP stays set until __swapoff() finishes (so xswap_create() gets -EBUSY). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203164336.8646= 91-1-baoquan.he@linux.dev?part=3D7