[PATCH 0/8] mm: globalize rest_of_page() macro

Yury Norov posted 8 patches 1 month, 1 week ago
arch/arm64/kernel/patching.c                |  4 +---
arch/powerpc/lib/code-patching.c            |  6 +++---
arch/riscv/kernel/sbi.c                     |  4 ++--
arch/s390/kvm/gaccess.c                     |  6 +++---
arch/x86/kvm/emulate.c                      |  4 ++--
drivers/block/null_blk/main.c               |  6 ++----
drivers/gpu/drm/i915/gt/shmem_utils.c       |  5 ++---
drivers/md/dm-pcache/backing_dev.h          |  2 +-
drivers/net/ethernet/meta/fbnic/fbnic_tlv.c |  6 +++---
drivers/s390/net/qeth_core_main.c           |  6 ++----
drivers/spi/spi-pl022.c                     |  3 +--
drivers/spi/spi.c                           |  4 +---
fs/ext4/verity.c                            |  3 +--
fs/f2fs/verity.c                            |  6 ++----
fs/fuse/dev.c                               |  4 ++--
fs/iomap/buffered-io.c                      |  2 +-
fs/nfs/pagelist.c                           |  2 +-
fs/remap_range.c                            |  3 +--
fs/xfs/scrub/xfile.c                        |  3 +--
include/crypto/scatterwalk.h                |  2 +-
include/linux/highmem.h                     | 24 +++++++++------------
include/linux/iomap.h                       |  2 +-
include/linux/iov_iter.h                    |  3 +--
include/linux/mm.h                          |  2 ++
kernel/events/ring_buffer.c                 |  2 +-
lib/bitmap-str.c                            |  2 +-
lib/iov_iter.c                              |  5 ++---
net/9p/trans_virtio.c                       |  6 ------
sound/virtio/virtio_pcm_msg.c               |  4 ++--
29 files changed, 53 insertions(+), 78 deletions(-)
[PATCH 0/8] mm: globalize rest_of_page() macro
Posted by Yury Norov 1 month, 1 week ago
The net/9p networking driver has a handy macro to calculate the
amount of bytes from a given pointer to the end of page. Move it
to core/mm, and apply tree-wide. No functional changes intended.

This series was originally introduced as a single patch #07/12 in:

https://lore.kernel.org/all/20260219181407.290201-1-ynorov@nvidia.com/

Split it for better granularity and submit separately.

Yury Norov (8):
  mm: add rest_of_page() macro
  fs: use rest_of_page() macro where appropriate
  net: use rest_of_page() macro where appropriate
  core: use rest_of_page() macro where appropriate
  spi: use rest_of_page() macro where appropriate
  KVM: use rest_of_page() macro where appropriate
  drivers: ALSA: use rest_of_page() macro where appropriate
  arch: use rest_of_page() macro where appropriate

 arch/arm64/kernel/patching.c                |  4 +---
 arch/powerpc/lib/code-patching.c            |  6 +++---
 arch/riscv/kernel/sbi.c                     |  4 ++--
 arch/s390/kvm/gaccess.c                     |  6 +++---
 arch/x86/kvm/emulate.c                      |  4 ++--
 drivers/block/null_blk/main.c               |  6 ++----
 drivers/gpu/drm/i915/gt/shmem_utils.c       |  5 ++---
 drivers/md/dm-pcache/backing_dev.h          |  2 +-
 drivers/net/ethernet/meta/fbnic/fbnic_tlv.c |  6 +++---
 drivers/s390/net/qeth_core_main.c           |  6 ++----
 drivers/spi/spi-pl022.c                     |  3 +--
 drivers/spi/spi.c                           |  4 +---
 fs/ext4/verity.c                            |  3 +--
 fs/f2fs/verity.c                            |  6 ++----
 fs/fuse/dev.c                               |  4 ++--
 fs/iomap/buffered-io.c                      |  2 +-
 fs/nfs/pagelist.c                           |  2 +-
 fs/remap_range.c                            |  3 +--
 fs/xfs/scrub/xfile.c                        |  3 +--
 include/crypto/scatterwalk.h                |  2 +-
 include/linux/highmem.h                     | 24 +++++++++------------
 include/linux/iomap.h                       |  2 +-
 include/linux/iov_iter.h                    |  3 +--
 include/linux/mm.h                          |  2 ++
 kernel/events/ring_buffer.c                 |  2 +-
 lib/bitmap-str.c                            |  2 +-
 lib/iov_iter.c                              |  5 ++---
 net/9p/trans_virtio.c                       |  6 ------
 sound/virtio/virtio_pcm_msg.c               |  4 ++--
 29 files changed, 53 insertions(+), 78 deletions(-)

-- 
2.43.0
Re: [PATCH 0/8] mm: globalize rest_of_page() macro
Posted by Jakub Kicinski 1 month, 1 week ago
On Tue,  3 Mar 2026 20:27:08 -0500 Yury Norov wrote:
> The net/9p networking driver has a handy macro to calculate the
> amount of bytes from a given pointer to the end of page. Move it
> to core/mm, and apply tree-wide. No functional changes intended.
> 
> This series was originally introduced as a single patch #07/12 in:
> 
> https://lore.kernel.org/all/20260219181407.290201-1-ynorov@nvidia.com/
> 
> Split it for better granularity and submit separately.

I don't get what the motivation is here. Another helper developers
and readers of the code will need to know about just to replace 
obvious and easy to comprehend math.
Re: [PATCH 0/8] mm: globalize rest_of_page() macro
Posted by Jens Axboe 1 month, 1 week ago
On 3/3/26 7:28 PM, Jakub Kicinski wrote:
> On Tue,  3 Mar 2026 20:27:08 -0500 Yury Norov wrote:
>> The net/9p networking driver has a handy macro to calculate the
>> amount of bytes from a given pointer to the end of page. Move it
>> to core/mm, and apply tree-wide. No functional changes intended.
>>
>> This series was originally introduced as a single patch #07/12 in:
>>
>> https://lore.kernel.org/all/20260219181407.290201-1-ynorov@nvidia.com/
>>
>> Split it for better granularity and submit separately.
> 
> I don't get what the motivation is here. Another helper developers
> and readers of the code will need to know about just to replace 
> obvious and easy to comprehend math.

I fully agree, I had the same thought reading this.

-- 
Jens Axboe
Re: [PATCH 0/8] mm: globalize rest_of_page() macro
Posted by Sean Christopherson 1 month, 1 week ago
On Tue, Mar 03, 2026, Jens Axboe wrote:
> On 3/3/26 7:28 PM, Jakub Kicinski wrote:
> > On Tue,  3 Mar 2026 20:27:08 -0500 Yury Norov wrote:
> >> The net/9p networking driver has a handy macro to calculate the
> >> amount of bytes from a given pointer to the end of page. Move it
> >> to core/mm, and apply tree-wide. No functional changes intended.
> >>
> >> This series was originally introduced as a single patch #07/12 in:
> >>
> >> https://lore.kernel.org/all/20260219181407.290201-1-ynorov@nvidia.com/
> >>
> >> Split it for better granularity and submit separately.
> > 
> > I don't get what the motivation is here. Another helper developers
> > and readers of the code will need to know about just to replace 
> > obvious and easy to comprehend math.
> 
> I fully agree, I had the same thought reading this.

+1 from KVM-land.
Re: [PATCH 0/8] mm: globalize rest_of_page() macro
Posted by Peter Zijlstra 1 month, 1 week ago
On Tue, Mar 03, 2026 at 06:49:36PM -0800, Sean Christopherson wrote:
> On Tue, Mar 03, 2026, Jens Axboe wrote:
> > On 3/3/26 7:28 PM, Jakub Kicinski wrote:
> > > On Tue,  3 Mar 2026 20:27:08 -0500 Yury Norov wrote:
> > >> The net/9p networking driver has a handy macro to calculate the
> > >> amount of bytes from a given pointer to the end of page. Move it
> > >> to core/mm, and apply tree-wide. No functional changes intended.
> > >>
> > >> This series was originally introduced as a single patch #07/12 in:
> > >>
> > >> https://lore.kernel.org/all/20260219181407.290201-1-ynorov@nvidia.com/
> > >>
> > >> Split it for better granularity and submit separately.
> > > 
> > > I don't get what the motivation is here. Another helper developers
> > > and readers of the code will need to know about just to replace 
> > > obvious and easy to comprehend math.
> > 
> > I fully agree, I had the same thought reading this.
> 
> +1 from KVM-land.

Right, this. I hate these pointless helpers that obscure perfectly
sensible and obvious code -- and for me that includes things like
rounddown() and DIV_ROUND_UP().

It just makes the code harder to read.
Re: [PATCH 0/8] mm: globalize rest_of_page() macro
Posted by Yury Norov 1 month, 1 week ago
On Tue, Mar 03, 2026 at 06:49:36PM -0800, Sean Christopherson wrote:
> On Tue, Mar 03, 2026, Jens Axboe wrote:
> > On 3/3/26 7:28 PM, Jakub Kicinski wrote:
> > > On Tue,  3 Mar 2026 20:27:08 -0500 Yury Norov wrote:
> > >> The net/9p networking driver has a handy macro to calculate the
> > >> amount of bytes from a given pointer to the end of page. Move it
> > >> to core/mm, and apply tree-wide. No functional changes intended.
> > >>
> > >> This series was originally introduced as a single patch #07/12 in:
> > >>
> > >> https://lore.kernel.org/all/20260219181407.290201-1-ynorov@nvidia.com/
> > >>
> > >> Split it for better granularity and submit separately.
> > > 
> > > I don't get what the motivation is here. Another helper developers
> > > and readers of the code will need to know about just to replace 
> > > obvious and easy to comprehend math.
> > 
> > I fully agree, I had the same thought reading this.
> 
> +1 from KVM-land.

My motivation is that it helps to simplify constructions like this:

-               loff_t cmp_len = min(PAGE_SIZE - offset_in_page(srcoff),
-                                    PAGE_SIZE - offset_in_page(dstoff));
+               loff_t cmp_len = min(rest_of_page(srcoff), rest_of_page(dstoff));

Or this:

-               if (folio_test_highmem(dst_folio) &&
-                   chunk > PAGE_SIZE - offset_in_page(dst_off))
-                       chunk = PAGE_SIZE - offset_in_page(dst_off);
-               if (folio_test_highmem(src_folio) &&
-                   chunk > PAGE_SIZE - offset_in_page(src_off))
-                       chunk = PAGE_SIZE - offset_in_page(src_off);
+               if (folio_test_highmem(dst_folio) && chunk > rest_of_page(dst_off))
+                       chunk = rest_of_page(dst_off);
+               if (folio_test_highmem(src_folio) && chunk > rest_of_page(src_off))
+                       chunk = rest_of_page(src_off);

To a point where I don't have to use my brains to decode them. I agree
it's an easy math. It's just too bulky to my (and 9p guys too) taste.

Thanks,
Yury
Re: [PATCH 0/8] mm: globalize rest_of_page() macro
Posted by Jens Axboe 1 month, 1 week ago
On 3/3/26 8:32 PM, Yury Norov wrote:
> My motivation is that it helps to simplify constructions like this:
> 
> -               loff_t cmp_len = min(PAGE_SIZE - offset_in_page(srcoff),
> -                                    PAGE_SIZE - offset_in_page(dstoff));
> +               loff_t cmp_len = min(rest_of_page(srcoff), rest_of_page(dstoff));
> 
> Or this:
> 
> -               if (folio_test_highmem(dst_folio) &&
> -                   chunk > PAGE_SIZE - offset_in_page(dst_off))
> -                       chunk = PAGE_SIZE - offset_in_page(dst_off);
> -               if (folio_test_highmem(src_folio) &&
> -                   chunk > PAGE_SIZE - offset_in_page(src_off))
> -                       chunk = PAGE_SIZE - offset_in_page(src_off);
> +               if (folio_test_highmem(dst_folio) && chunk > rest_of_page(dst_off))
> +                       chunk = rest_of_page(dst_off);
> +               if (folio_test_highmem(src_folio) && chunk > rest_of_page(src_off))
> +                       chunk = rest_of_page(src_off);
> 
> To a point where I don't have to use my brains to decode them. I agree
> it's an easy math. It's just too bulky to my (and 9p guys too) taste.

The thing is, now I have to go lookup what on earth rest_of_page() does,
whereas PAGE_SIZE - offset_in_page(page) is immediately obvious. It's a
classic case of "oh let's add this helper to simplify things" which
really just makes it worse, because now you have to jump to the
definition of rest_of_page().

IOW, just no.

-- 
Jens Axboe