linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@redhat.com>,
	Hyeonggon Yoo <42.hyeyoo@gmail.com>,
	linux-mm@kvack.org, Kent Overstreet <kent.overstreet@linux.dev>
Subject: Re: [PATCH 3/4] mm: Support only one page_type per page
Date: Fri, 1 Aug 2025 03:43:47 +0100	[thread overview]
Message-ID: <aIwp48CTft68fssD@casper.infradead.org> (raw)
In-Reply-To: <2d19c48a-c550-4345-bf36-d05cd303c5de@huawei.com>

On Wed, Aug 28, 2024 at 11:35:28AM +0800, Kefeng Wang wrote:
> There are some UBSAN warning about  __folio_set_##fname/__SetPage##uname,
> 
> UBSAN: shift-out-of-bounds in ../include/linux/page-flags.h:998:1
> left shift of 240 by 24 places cannot be represented in type 'int'

I can't reproduce this.  I know Andrew merged this patch in, but I
tried backing it out and enabling UBSAN and it doesn't show up for me.
Relevant part of .config:

CONFIG_ARCH_HAS_UBSAN=y
CONFIG_UBSAN=y
CONFIG_UBSAN_TRAP=y
CONFIG_CC_HAS_UBSAN_BOUNDS_STRICT=y
CONFIG_UBSAN_BOUNDS=y
CONFIG_UBSAN_BOUNDS_STRICT=y
CONFIG_UBSAN_SHIFT=y
# CONFIG_UBSAN_DIV_ZERO is not set
CONFIG_UBSAN_BOOL=y
CONFIG_UBSAN_ENUM=y
# CONFIG_TEST_UBSAN is not set

(I tried CONFIG_UBSAN_TRAP both on and off)

> Changing significant bit to unsigned to fix it.
> 
> diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
> index 28d2337525d1..2175ebceb41c 100644
> --- a/include/linux/page-flags.h
> +++ b/include/linux/page-flags.h
> @@ -966,7 +966,7 @@ static __always_inline void __folio_set_##fname(struct
> folio *folio)        \
>  {                                                                      \
>         VM_BUG_ON_FOLIO(data_race(folio->page.page_type) != UINT_MAX,   \
>                         folio);                                         \
> -       folio->page.page_type = PGTY_##lname << 24;                     \
> +       folio->page.page_type = (unsigned int)PGTY_##lname << 24;       \
>  }                                                                      \
>  static __always_inline void __folio_clear_##fname(struct folio *folio) \
>  {                                                                      \
> @@ -983,7 +983,7 @@ static __always_inline int Page##uname(const struct page
> *page)             \
>  static __always_inline void __SetPage##uname(struct page *page)         \
>  {                                                                      \
>         VM_BUG_ON_PAGE(data_race(page->page_type) != UINT_MAX, page);   \
> -       page->page_type = PGTY_##lname << 24;                           \
> +       page->page_type = (unsigned int)PGTY_##lname << 24;             \
>  }                                                                      \
> 
> 
> 


  reply	other threads:[~2025-08-01  2:43 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-21 17:39 [PATCH 0/4] Increase the number of bits available in page_type Matthew Wilcox (Oracle)
2024-08-21 17:39 ` [PATCH 1/4] printf: Remove %pGt support Matthew Wilcox (Oracle)
2024-08-21 21:00   ` David Hildenbrand
2024-08-21 21:08     ` Matthew Wilcox
2024-08-21 17:39 ` [PATCH 2/4] mm: Introduce page_mapcount_is_type() Matthew Wilcox (Oracle)
2024-08-21 21:01   ` David Hildenbrand
2024-08-21 17:39 ` [PATCH 3/4] mm: Support only one page_type per page Matthew Wilcox (Oracle)
2024-08-21 21:05   ` David Hildenbrand
2024-08-28  3:35   ` Kefeng Wang
2025-08-01  2:43     ` Matthew Wilcox [this message]
2025-08-01  2:49       ` Kent Overstreet
2025-08-01  8:13       ` Kefeng Wang
2025-08-01 14:27         ` Matthew Wilcox
2025-08-02  2:00           ` Kefeng Wang
2024-08-21 17:39 ` [PATCH 4/4] zsmalloc: Use all available 24 bits of page_type Matthew Wilcox (Oracle)
2024-08-21 21:06   ` David Hildenbrand
2024-08-21 21:15 ` [PATCH 0/4] Increase the number of bits available in page_type Kent Overstreet

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=aIwp48CTft68fssD@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-mm@kvack.org \
    --cc=wangkefeng.wang@huawei.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