All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yury Norov <ynorov@nvidia.com>
To: Thorsten Blum <thorsten.blum@linux.dev>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@kernel.org>,
	Lorenzo Stoakes <ljs@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>, Andy Lutomirski <luto@kernel.org>,
	Thomas Gleixner <tglx@kernel.org>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	Kees Cook <kees@kernel.org>, Andy Shevchenko <andy@kernel.org>,
	Yury Norov <yury.norov@gmail.com>,
	David Laight <david.laight.linux@gmail.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 0/2] mm/vdso: make offset_in_page() usable without linux/mm.h
Date: Thu, 21 May 2026 09:59:10 -0400	[thread overview]
Message-ID: <ag8PrpLzeuWmnfIW@yury> (raw)
In-Reply-To: <20260521090655.160282-4-thorsten.blum@linux.dev>

On Thu, May 21, 2026 at 11:06:56AM +0200, Thorsten Blum wrote:
> offset_in_page() is a small page-arithmetic helper that has been around
> for 20+ years. However, page-offset calculations are still open-coded in
> many places and in different ways:
> 
> 	(unsigned long)p & ~PAGE_MASK
> 	(unsigned long)p & (PAGE_SIZE - 1)
> 	(long)p & (PAGE_SIZE - 1)
> 	...
> 
> Some of these open-coded instances may be due to offset_in_page() being
> buried 3000+ lines into linux/mm.h; others may have avoided including
> linux/mm.h, which is a large header that pulls in many others.
> 
> Patch 1 moves offset_in_page() from linux/mm.h to vdso/page.h, which
> keeps the helper with other low-level page definitions and allows users
> that only need offset_in_page() to avoid including linux/mm.h.
> 
> Patch 2 shows a concrete example where including vdso/page.h is
> sufficient and including the large linux/mm.h would be unnecessary.

mm.h is already included there indirectly, otherwise it would be a
compile error, isn't?

--

Example for who? Are you expecting somebody to pick it up from you and
cleanup the whole kernel?

I'm not interested in 'example', I'm interested in a broad picture and
an estimate of how realistically would it be to switch kernel to
consistently use the helper.

So this is the broad picture for you:

 - 660 uses of offset_in_page()
 - 570 uses of & ~PAGE_MASK
 - 176 uses of & (PAGE_SIZE - 1)
 - 135 high-confidence candidates

Those 135 candidates are found with:

$ git grep -n -E \
  '\b(offset|off|ofs|poff|pg_off|pg_ofs|page_offset|page_offs|start_offset|dest_off|src_off|from|to|remainder)\b[^=]*= [^;]*&[[:space:]]*(~PAGE_MASK|\(?PAGE_SIZE[[:space:]]*-[[:space:]]*1\)?)' \
  -- ':(exclude)drivers/gpu/drm/amd/include/asic_reg/**' \
  ':(exclude)include/trace/events/**'

If you want to go ahead and convert at least those good candidates -
it would be about a couple dozens of patches. And it would look like a
meaningful commitment.

If you want to move the macro out of linux/mm.h and drop the header
from some inclusion paths - it would be another meaningful commitment.

In this series you move the macro to a questionable vdso header, and
convert just one user, which leads to *adding* another dependency,
instead of removing some. This doesn't look like a valuable commitment,
sorry.

Thanks,
Yury
 
> Existing users of offset_in_page() do not need to change because patch 1
> also includes vdso/page.h from linux/mm.h.
> 
> This series is based on akpm/mm.git mm-nonmm-unstable commit
> d067a83c8063 ("string: use min in sized_strscpy"), which is also in
> linux-next.
> 
> Changes in v2:
> - Add a cover letter and drop the bytes_to_page_end() helper
> - Move offset_in_page() to vdso/page.h as suggested by David and Lorenzo
> - Use offset_in_page() in lib/string.c as an example since
>   bitmap_print_to_pagebuf() in lib/bitmap-str.c is being removed [1]
> - v1: https://lore.kernel.org/lkml/20260517123428.1181981-4-thorsten.blum@linux.dev/
> 
> [1] https://lore.kernel.org/lkml/20260519163058.953690-3-ynorov@nvidia.com/
> ---
> Thorsten Blum (2):
>   vdso: move offset_in_page() from linux/mm.h to vdso/page.h
>   string: use offset_in_page() in sized_strscpy()
> 
>  include/linux/mm.h  | 2 +-
>  include/vdso/page.h | 2 ++
>  lib/string.c        | 3 ++-
>  3 files changed, 5 insertions(+), 2 deletions(-)
> 
> 
> base-commit: d067a83c8063d1bdcbd9af8e1326d846f85138b8

      parent reply	other threads:[~2026-05-21 13:59 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21  9:06 [PATCH v2 0/2] mm/vdso: make offset_in_page() usable without linux/mm.h Thorsten Blum
2026-05-21  9:06 ` [PATCH v2 1/2] vdso: move offset_in_page() from linux/mm.h to vdso/page.h Thorsten Blum
2026-05-21  9:30   ` David Laight
2026-05-21 11:45     ` Thomas Gleixner
2026-05-21 11:15   ` Lorenzo Stoakes
2026-05-21 14:56     ` Lorenzo Stoakes
2026-05-21 18:34       ` Andy Shevchenko
2026-05-22 10:52         ` Lorenzo Stoakes
2026-05-22 12:18       ` Thorsten Blum
2026-05-21 14:03   ` Yury Norov
2026-05-21  9:06 ` [PATCH v2 2/2] string: use offset_in_page() in sized_strscpy() Thorsten Blum
2026-05-21 11:31   ` Lorenzo Stoakes
2026-05-21 13:47     ` Thorsten Blum
2026-05-21 14:53       ` Lorenzo Stoakes
2026-05-21 11:33 ` [PATCH v2 0/2] mm/vdso: make offset_in_page() usable without linux/mm.h Lorenzo Stoakes
2026-05-21 13:59 ` Yury Norov [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=ag8PrpLzeuWmnfIW@yury \
    --to=ynorov@nvidia.com \
    --cc=akpm@linux-foundation.org \
    --cc=andy@kernel.org \
    --cc=david.laight.linux@gmail.com \
    --cc=david@kernel.org \
    --cc=kees@kernel.org \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=luto@kernel.org \
    --cc=mhocko@suse.com \
    --cc=rppt@kernel.org \
    --cc=surenb@google.com \
    --cc=tglx@kernel.org \
    --cc=thorsten.blum@linux.dev \
    --cc=vbabka@kernel.org \
    --cc=vincenzo.frascino@arm.com \
    --cc=yury.norov@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.