Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "kasong(宋恺睿)" <kasong@tencent.com>
To: "Dan Carpenter" <error27@gmail.com>
Cc: "Linux Memory Management List" <linux-mm@kvack.org>
Subject: 回复:[Internet][bug report] mm, swap: add support for stable large allocation in swap cache directly
Date: Tue, 2 Jun 2026 16:21:40 +0800	[thread overview]
Message-ID: <tencent_563412614416DBC00F511C21@qq.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 6106 bytes --]

Hello Dan


Currently, no caller in kernel will pass NULL mpol with NULL vmf with CONFIG_NUMA. Do do_swap_page always have vmf set, and shmem always have either vmf or mpol set (unless !CONFIG_NUMA).


I used to have a WARN_ON for this but some AI reviewers complained that the WARN_ON is redundant so I removed it. I can add that back later just to be safer, I will add a Reported-by for you. Is that OK?





                    Dan Carpenter<error27@gmail.com&gt;&nbsp;在 2026年6月2日 周二 16:02 写道:

Hello Kairui Song,

Commit 128460ca95cf ("mm, swap: add support for stable large
allocation in swap cache directly") from May 17, 2026 (linux-next),
leads to the following Smatch static checker warning:

	mm/swap_state.c:434 __swap_cache_alloc()
	error: we previously assumed 'mpol' could be null (see line 433)

mm/swap_state.c
&nbsp;&nbsp;&nbsp; 403 static struct folio *__swap_cache_alloc(struct swap_cluster_info *ci,
&nbsp;&nbsp;&nbsp; 404&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; swp_entry_t targ_entry, gfp_t gfp,
&nbsp;&nbsp;&nbsp; 405&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned int order, struct vm_fault *vmf,
&nbsp;&nbsp;&nbsp; 406&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; struct mempolicy *mpol, pgoff_t ilx)
&nbsp;&nbsp;&nbsp; 407 {
&nbsp;&nbsp;&nbsp; 408&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int err;
&nbsp;&nbsp;&nbsp; 409&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; swp_entry_t entry;
&nbsp;&nbsp;&nbsp; 410&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; struct folio *folio;
&nbsp;&nbsp;&nbsp; 411&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void *shadow = NULL;
&nbsp;&nbsp;&nbsp; 412&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned short memcg_id;
&nbsp;&nbsp;&nbsp; 413&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long address, nr_pages = 1UL << order;
&nbsp;&nbsp;&nbsp; 414&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; struct vm_area_struct *vma = vmf ? vmf-&gt;vma : NULL;
&nbsp;&nbsp;&nbsp; 415 
&nbsp;&nbsp;&nbsp; 416&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VM_WARN_ON_ONCE(nr_pages &gt; SWAPFILE_CLUSTER);
&nbsp;&nbsp;&nbsp; 417&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; entry.val = round_down(targ_entry.val, nr_pages);
&nbsp;&nbsp;&nbsp; 418 
&nbsp;&nbsp;&nbsp; 419&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Check if the slot and range are available, skip allocation if not */
&nbsp;&nbsp;&nbsp; 420&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; spin_lock(&amp;ci-&gt;lock);
&nbsp;&nbsp;&nbsp; 421&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; err = __swap_cache_add_check(ci, targ_entry, nr_pages, NULL, NULL);
&nbsp;&nbsp;&nbsp; 422&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; spin_unlock(&amp;ci-&gt;lock);
&nbsp;&nbsp;&nbsp; 423&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (unlikely(err))
&nbsp;&nbsp;&nbsp; 424&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ERR_PTR(err);
&nbsp;&nbsp;&nbsp; 425 
&nbsp;&nbsp;&nbsp; 426&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*
&nbsp;&nbsp;&nbsp; 427&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * Limit THP gfp. The limitation is a no-op for typical
&nbsp;&nbsp;&nbsp; 428&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * GFP_HIGHUSER_MOVABLE but matters for shmem.
&nbsp;&nbsp;&nbsp; 429&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */
&nbsp;&nbsp;&nbsp; 430&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (order)
&nbsp;&nbsp;&nbsp; 431&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gfp = thp_shmem_limit_gfp_mask(vma_thp_gfp_mask(vma), gfp);
&nbsp;&nbsp;&nbsp; 432 
&nbsp;&nbsp;&nbsp; 433&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (mpol || !vmf) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ^^^^
imagine mpol is mpol is NULL and so is vmf.

--&gt; 434&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; folio = folio_alloc_mpol(gfp, order, mpol, ilx, numa_node_id());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ^^^^
We can't pass a NULL mpol to folio_alloc_mpol() or it will crash.&nbsp; Unless
mpol can't be NULL when CONFIG_NUMA is disabled?&nbsp; I think mpol can be NULL
from do_swap_page() so this looks pretty suspect.

&nbsp;&nbsp;&nbsp; 435&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {
&nbsp;&nbsp;&nbsp; 436&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; address = round_down(vmf-&gt;address, PAGE_SIZE << order);
&nbsp;&nbsp;&nbsp; 437&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; folio = vma_alloc_folio(gfp, order, vmf-&gt;vma, address);
&nbsp;&nbsp;&nbsp; 438&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; 439&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (unlikely(!folio))

This email is a free service from the Smatch-CI project [smatch.sf.net].

regards,
dan carpenter

[-- Attachment #2: Type: text/html, Size: 7599 bytes --]

             reply	other threads:[~2026-06-02  8:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-02  8:21 kasong(宋恺睿) [this message]
2026-06-02  8:38 ` 回复:[Internet][bug report] mm, swap: add support for stable large allocation in swap cache directly Dan Carpenter

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=tencent_563412614416DBC00F511C21@qq.com \
    --to=kasong@tencent.com \
    --cc=error27@gmail.com \
    --cc=linux-mm@kvack.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