linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Harry Yoo <harry.yoo@oracle.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: rientjes@google.com, cl@gentwo.org, akpm@linux-foundation.org,
	roman.gushchin@linux.dev, willy@infradead.org,
	linux-mm@kvack.org
Subject: Re: [PATCH] mm/slab: fix folio_test_{anon,ksm}() false positive on slabs
Date: Tue, 10 Jun 2025 22:17:57 +0900	[thread overview]
Message-ID: <aEgwhbOnpEv1dlSF@hyeyoo> (raw)
In-Reply-To: <83e262c2-419d-42cf-84db-b4ea2befbb72@suse.cz>

On Tue, Jun 10, 2025 at 03:03:12PM +0200, Vlastimil Babka wrote:
> On 6/10/25 14:38, Harry Yoo wrote:
> > On Mon, Jun 09, 2025 at 04:22:01PM +0200, Vlastimil Babka wrote:
> >> > With the change, the nonsense slab pages disappear:
> >> > 
> >> >   $ sudo ./page-types | grep slab
> >> >   _______S___________________________________	slab
> >> > 
> >> > Fixes: 130d4df57390 ("mm/sl[au]b: rearrange struct slab fields to allow larger rcu_head")
> >> > Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
> >> > ---
> >> > 
> >> > No Cc: stable because we don't usually check folio_test_anon() on slabs.
> >> 
> >> Hmm maybe we could just make the code generating /proc/kpageflags stop
> >> testing/reporting those "flags" for slab pages?
> >>
> >> It could be even more future proof code for when struct slab is separated.
> > 
> > Not sure if I follow. When struct slab is separated, checking if a memdesc
> > refers to slab or not will not have false positives, and thus no need for
> > "must check folio_test_slab() before checking folio_test_anon()" rule?
> 
> Not sure I follow either. I mean today we can add code testing
> folio_test_slab() and only evaluating the mapping flags (ksm, anon) if it's
> not slab. Once we convert to memdescs, that code will stay logically the
> same even the testing functions will be named differently, no?

Ah, I thought you were saying it is unnecessary to fix folio_test_slab()
false positives as long as we always check folio_test_slab() before
folio_test_anon().

Changing /proc/kpageflags in that direction will work and will be
future proof. Will do that.

-- 
Cheers,
Harry / Hyeonggon
 
> > Of course, to fix false positive completely, I think we need to add
> > something like:
> > 
> > __aligned(4) or __aligned(CONFIG_FUNCTION_ALIGNMENT) (whichever alignment is bigger)
> > 
> > to rcu_free_slab().
> 
> OK.
> 
> >> I mean there's even a comment above PAGE_MAPPING_ANON:
> >>
> >>  * For slab pages, since slab reuses the bits in struct page to store its
> >>  * internal states, the folio->mapping does not exist as such, nor do
> >>  * these flags below.  So in order to avoid testing non-existent bits,
> >>  * please make sure that folio_test_slab(folio) actually evaluates to
> >>  * false before calling the following functions (e.g., folio_test_anon).
> >>  * See mm/slab.h.
> > 
> > That comment was added because it was a hard lesson learned from
> > false positive. 
> > 
> 


  reply	other threads:[~2025-06-10 13:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-09 13:27 Harry Yoo
2025-06-09 14:12 ` Harry Yoo
2025-06-09 14:22 ` Vlastimil Babka
2025-06-10 12:38   ` Harry Yoo
2025-06-10 13:03     ` Vlastimil Babka
2025-06-10 13:17       ` Harry Yoo [this message]
2025-06-12 12:44         ` David Hildenbrand
2025-06-09 16:06 ` Christoph Lameter (Ampere)
2025-06-10 12:39   ` Harry Yoo

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=aEgwhbOnpEv1dlSF@hyeyoo \
    --to=harry.yoo@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@gentwo.org \
    --cc=linux-mm@kvack.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.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