Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Baoquan He" <baoquan.he@linux.dev>, 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" <hebaoquan@kylinos.cn>
Subject: Re: [PATCH v8 14/14] mm, swap: skip the overcommit probe when removing xswap
Date: Fri, 04 Dec 2026 16:48:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-250232@kernel.org> (raw)
In-Reply-To: <20261203164336.864691-15-baoquan.he@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] mm: swap_info_remove() breaks OVERCOMMIT_NEVER by skipping
  xswap probe
--

commit 11c3ffbafc7523059ca6fb8d3aa9ae7249ff0268
Author: Baoquan He <hebaoquan@kylinos.cn>

mm, swap: skip the overcommit probe when removing xswap

This commit skips the security_vm_enough_memory_mm() overcommit check in
swap_info_remove() for SWP_XSWAP devices while keeping it for real swap
devices.

> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 6c1cfa0d693b5..c66b4bbc3af7f 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -3703,10 +3703,17 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
>   */
>  static int swap_info_remove(struct swap_info_struct *p)
>  {
> -	if (!security_vm_enough_memory_mm(current->mm, p->pages))
> -		vm_unacct_memory(p->pages);
> -	else
> -		return -ENOMEM;
> +	/*
> +	 * The device's pages are its address space, not backing storage.
> +	 * The commit limit it added may have been committed against, so
> +	 * skip the probe until the limit stops counting that space.
> +	 */
> +	if (!(p->flags & SWP_XSWAP)) {
> +		if (!security_vm_enough_memory_mm(current->mm, p->pages))
> +			vm_unacct_memory(p->pages);
> +		else
> +			return -ENOMEM;
> +	}
>  
>  	spin_lock(&p->lock);
>  	del_from_avail_list(p, true);

[Severity: High]
Can skipping this probe break OVERCOMMIT_NEVER by dropping vm_commit_limit()
below vm_committed_as?

_enable_swap_info() still adds xswap's pages to total_swap_pages, which
vm_commit_limit() includes.  Once swap_info_remove() subtracts p->pages
without probing, __vm_enough_memory() rejects every later accounted
allocation system-wide with -ENOMEM, even for CAP_SYS_ADMIN processes.

This also defeats OVERCOMMIT_NEVER protection for real swap devices when
xswap is active.  Because /proc/swaps lists devices in ascending type order,
swapoff -a probes a lower-type real swap device against xswap's inflated
total_swap_pages, then removes xswap without probing.

Excluding xswap's virtual address space from vm_commit_limit() at activation
and removal would preserve OVERCOMMIT_NEVER for both xswap and real swap
devices.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203164336.864691-1-baoquan.he@linux.dev?part=14


      reply	other threads:[~2026-12-04 16:49 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 16:43 [PATCH v8 00/14] mm, swap: extendable swap devices (xswap phase I) Baoquan He
2026-12-03 16:43 ` [PATCH v8 01/14] mm/vmalloc: support vmalloc-backed VM_SPARSE areas Baoquan He
2026-12-04 16:48   ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 02/14] mm: xswap support for zswap Baoquan He
2026-12-04 16:48   ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 03/14] mm, swap: refactor free_swap_cluster_info to take swap_info_struct Baoquan He
2026-12-04 16:48   ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 04/14] mm, swap: use a VM_SPARSE cluster array for xswap devices Baoquan He
2026-12-04 16:48   ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 05/14] mm, swap: widen swap_info_struct max/pages to unsigned long Baoquan He
2026-12-03 16:43 ` [PATCH v8 06/14] mm, swap: create the xswap device from swapon(2) Baoquan He
2026-12-04 16:48   ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 07/14] mm, swap: refactor swapoff and add xswap_destroy Baoquan He
2026-12-04 16:48   ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 08/14] mm, swap: require zswap for xswap devices Baoquan He
2026-12-04 16:48   ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 09/14] mm, swap: let the command line set the xswap device size Baoquan He
2026-12-04 16:48   ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 10/14] mm, swap: add CONFIG_XSWAP_DEFAULT_MAX Baoquan He
2026-12-03 16:43 ` [PATCH v8 11/14] mm, swap: add xswap grow trigger on cluster allocation Baoquan He
2026-12-04 16:48   ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 12/14] mm, swap: add debugfs counters for xswap Baoquan He
2026-12-04 16:48   ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 13/14] mm, swap: do not give an xswap slot to a cgroup that cannot zswap Baoquan He
2026-12-04 16:48   ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 14/14] mm, swap: skip the overcommit probe when removing xswap Baoquan He
2026-12-04 16:48   ` sashiko-bot [this message]

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=sashiko-outbox-250232@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baoquan.he@linux.dev \
    --cc=chrisl@kernel.org \
    --cc=corbet@lwn.net \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=hebaoquan@kylinos.cn \
    --cc=kasong@tencent.com \
    --cc=klarasmodin@gmail.com \
    --cc=kunwu.chan@gmail.com \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=urezki@gmail.com \
    --cc=yosry@kernel.org \
    --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