* [PATCH 0/8] mm: globalize rest_of_page() macro
@ 2026-03-04 1:27 Yury Norov
2026-03-04 1:27 ` [PATCH 1/8] mm: add " Yury Norov
` (8 more replies)
0 siblings, 9 replies; 12+ messages in thread
From: Yury Norov @ 2026-03-04 1:27 UTC (permalink / raw)
To: Andrew Morton, David S. Miller, Michael S. Tsirkin,
Theodore Ts'o, Albert Ou, Alexander Duyck, Alexander Gordeev,
Alexander Viro, Alexandra Winter, Andreas Dilger, Andrew Lunn,
Anna Schumaker, Anton Yakovlev, Arnaldo Carvalho de Melo,
Aswin Karuvally, Borislav Petkov, Carlos Maiolino,
Catalin Marinas, Chao Yu, Christian Borntraeger,
Christian Brauner, Claudio Imbrenda, Dave Hansen, David Airlie,
Dominique Martinet, Dongsheng Yang, Eric Dumazet,
Eric Van Hensbergen, Heiko Carstens, Herbert Xu, Ingo Molnar,
Jaegeuk Kim, Jakub Kicinski, Jani Nikula, Janosch Frank,
Jaroslav Kysela, Jens Axboe, Joonas Lahtinen, Latchesar Ionkov,
Linus Walleij, Madhavan Srinivasan, Mark Brown, Michael Ellerman,
Miklos Szeredi, Namhyung Kim, Palmer Dabbelt, Paolo Abeni,
Paolo Bonzini, Paul Walmsley, Peter Zijlstra, Rodrigo Vivi,
Sean Christopherson, Simona Vetter, Takashi Iwai,
Thomas Gleixner, Trond Myklebust, Tvrtko Ursulin, Vasily Gorbik,
Will Deacon, Yury Norov, Zheng Gu
Cc: Yury Norov, linux-kernel, x86, linux-arm-kernel, linuxppc-dev,
linux-riscv, kvm, linux-s390, linux-block, intel-gfx, dri-devel,
dm-devel, netdev, linux-spi, linux-ext4, linux-f2fs-devel,
linux-fsdevel, linux-xfs, linux-nfs, linux-crypto, linux-mm,
linux-perf-users, v9fs, virtualization, linux-sound
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/8] mm: add rest_of_page() macro
2026-03-04 1:27 [PATCH 0/8] mm: globalize rest_of_page() macro Yury Norov
@ 2026-03-04 1:27 ` Yury Norov
2026-03-04 1:27 ` [PATCH 2/8] fs: use rest_of_page() macro where appropriate Yury Norov
` (7 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Yury Norov @ 2026-03-04 1:27 UTC (permalink / raw)
To: Andrew Morton, David S. Miller, Michael S. Tsirkin,
Theodore Ts'o, Albert Ou, Alexander Duyck, Alexander Gordeev,
Alexander Viro, Alexandra Winter, Andreas Dilger, Andrew Lunn,
Anna Schumaker, Anton Yakovlev, Arnaldo Carvalho de Melo,
Aswin Karuvally, Borislav Petkov, Carlos Maiolino,
Catalin Marinas, Chao Yu, Christian Borntraeger,
Christian Brauner, Claudio Imbrenda, Dave Hansen, David Airlie,
Dominique Martinet, Dongsheng Yang, Eric Dumazet,
Eric Van Hensbergen, Heiko Carstens, Herbert Xu, Ingo Molnar,
Jaegeuk Kim, Jakub Kicinski, Jani Nikula, Janosch Frank,
Jaroslav Kysela, Jens Axboe, Joonas Lahtinen, Latchesar Ionkov,
Linus Walleij, Madhavan Srinivasan, Mark Brown, Michael Ellerman,
Miklos Szeredi, Namhyung Kim, Palmer Dabbelt, Paolo Abeni,
Paolo Bonzini, Paul Walmsley, Peter Zijlstra, Rodrigo Vivi,
Sean Christopherson, Simona Vetter, Takashi Iwai,
Thomas Gleixner, Trond Myklebust, Tvrtko Ursulin, Vasily Gorbik,
Will Deacon, Yury Norov, Zheng Gu
Cc: Yury Norov, linux-kernel, x86, linux-arm-kernel, linuxppc-dev,
linux-riscv, kvm, linux-s390, linux-block, intel-gfx, dri-devel,
dm-devel, netdev, linux-spi, linux-ext4, linux-f2fs-devel,
linux-fsdevel, linux-xfs, linux-nfs, linux-crypto, linux-mm,
linux-perf-users, v9fs, virtualization, linux-sound
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 mm. The following patches apply it tree-wide.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
include/linux/mm.h | 2 ++
net/9p/trans_virtio.c | 6 ------
2 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 5be3d8a8f806..6d1025c6249a 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2793,6 +2793,8 @@ extern void pagefault_out_of_memory(void);
#define offset_in_page(p) ((unsigned long)(p) & ~PAGE_MASK)
#define offset_in_folio(folio, p) ((unsigned long)(p) & (folio_size(folio) - 1))
+#define rest_of_page(p) (PAGE_SIZE - offset_in_page(p))
+
/*
* Parameter block passed down to zap_pte_range in exceptional cases.
*/
diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
index 4cdab7094b27..1ca53209d036 100644
--- a/net/9p/trans_virtio.c
+++ b/net/9p/trans_virtio.c
@@ -87,12 +87,6 @@ struct virtio_chan {
static struct list_head virtio_chan_list;
-/* How many bytes left in this page. */
-static unsigned int rest_of_page(void *data)
-{
- return PAGE_SIZE - offset_in_page(data);
-}
-
/**
* p9_virtio_close - reclaim resources of a channel
* @client: client instance
--
2.43.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 2/8] fs: use rest_of_page() macro where appropriate
2026-03-04 1:27 [PATCH 0/8] mm: globalize rest_of_page() macro Yury Norov
2026-03-04 1:27 ` [PATCH 1/8] mm: add " Yury Norov
@ 2026-03-04 1:27 ` Yury Norov
2026-03-04 1:27 ` [PATCH 3/8] net: " Yury Norov
` (6 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Yury Norov @ 2026-03-04 1:27 UTC (permalink / raw)
To: Andrew Morton, David S. Miller, Michael S. Tsirkin,
Theodore Ts'o, Albert Ou, Alexander Duyck, Alexander Gordeev,
Alexander Viro, Alexandra Winter, Andreas Dilger, Andrew Lunn,
Anna Schumaker, Anton Yakovlev, Arnaldo Carvalho de Melo,
Aswin Karuvally, Borislav Petkov, Carlos Maiolino,
Catalin Marinas, Chao Yu, Christian Borntraeger,
Christian Brauner, Claudio Imbrenda, Dave Hansen, David Airlie,
Dominique Martinet, Dongsheng Yang, Eric Dumazet,
Eric Van Hensbergen, Heiko Carstens, Herbert Xu, Ingo Molnar,
Jaegeuk Kim, Jakub Kicinski, Jani Nikula, Janosch Frank,
Jaroslav Kysela, Jens Axboe, Joonas Lahtinen, Latchesar Ionkov,
Linus Walleij, Madhavan Srinivasan, Mark Brown, Michael Ellerman,
Miklos Szeredi, Namhyung Kim, Palmer Dabbelt, Paolo Abeni,
Paolo Bonzini, Paul Walmsley, Peter Zijlstra, Rodrigo Vivi,
Sean Christopherson, Simona Vetter, Takashi Iwai,
Thomas Gleixner, Trond Myklebust, Tvrtko Ursulin, Vasily Gorbik,
Will Deacon, Yury Norov, Zheng Gu
Cc: Yury Norov, linux-kernel, x86, linux-arm-kernel, linuxppc-dev,
linux-riscv, kvm, linux-s390, linux-block, intel-gfx, dri-devel,
dm-devel, netdev, linux-spi, linux-ext4, linux-f2fs-devel,
linux-fsdevel, linux-xfs, linux-nfs, linux-crypto, linux-mm,
linux-perf-users, v9fs, virtualization, linux-sound
Switch filesystem codebase to using the macro. No functional changes
intended.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
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 +--
7 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/fs/ext4/verity.c b/fs/ext4/verity.c
index ca61da53f313..3dc95581e4b1 100644
--- a/fs/ext4/verity.c
+++ b/fs/ext4/verity.c
@@ -74,8 +74,7 @@ static int pagecache_write(struct inode *inode, const void *buf, size_t count,
return -EFBIG;
while (count) {
- size_t n = min_t(size_t, count,
- PAGE_SIZE - offset_in_page(pos));
+ size_t n = min_t(size_t, count, rest_of_page(pos));
struct folio *folio;
void *fsdata = NULL;
int res;
diff --git a/fs/f2fs/verity.c b/fs/f2fs/verity.c
index 92ebcc19cab0..1c3403fbf2a8 100644
--- a/fs/f2fs/verity.c
+++ b/fs/f2fs/verity.c
@@ -44,8 +44,7 @@ static int pagecache_read(struct inode *inode, void *buf, size_t count,
loff_t pos)
{
while (count) {
- size_t n = min_t(size_t, count,
- PAGE_SIZE - offset_in_page(pos));
+ size_t n = min_t(size_t, count, rest_of_page(pos));
struct page *page;
page = read_mapping_page(inode->i_mapping, pos >> PAGE_SHIFT,
@@ -78,8 +77,7 @@ static int pagecache_write(struct inode *inode, const void *buf, size_t count,
return -EFBIG;
while (count) {
- size_t n = min_t(size_t, count,
- PAGE_SIZE - offset_in_page(pos));
+ size_t n = min_t(size_t, count, rest_of_page(pos));
struct folio *folio;
void *fsdata = NULL;
int res;
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 0b0241f47170..efd7e6ca929e 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1157,8 +1157,8 @@ static int fuse_copy_folio(struct fuse_copy_state *cs, struct folio **foliop,
unsigned int copy = count;
unsigned int bytes_copied;
- if (folio_test_highmem(folio) && count > PAGE_SIZE - offset_in_page(offset))
- copy = PAGE_SIZE - offset_in_page(offset);
+ if (folio_test_highmem(folio) && count > rest_of_page(offset))
+ copy = rest_of_page(offset);
bytes_copied = fuse_copy_do(cs, &buf, ©);
kunmap_local(mapaddr);
diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index bc82083e420a..99e56ee6c3d6 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -852,7 +852,7 @@ static struct folio *__iomap_get_folio(struct iomap_iter *iter,
loff_t pos = iter->pos;
if (!mapping_large_folio_support(iter->inode->i_mapping))
- len = min_t(size_t, len, PAGE_SIZE - offset_in_page(pos));
+ len = min_t(size_t, len, rest_of_page(pos));
if (iter->iomap.flags & IOMAP_F_FOLIO_BATCH) {
struct folio *folio = folio_batch_next(iter->fbatch);
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
index a9373de891c9..221a90f57812 100644
--- a/fs/nfs/pagelist.c
+++ b/fs/nfs/pagelist.c
@@ -60,7 +60,7 @@ static struct page *nfs_page_iter_page_get(struct nfs_page_iter_page *i)
if (i->count != req->wb_bytes) {
size_t base = i->count + req->wb_pgbase;
- size_t len = PAGE_SIZE - offset_in_page(base);
+ size_t len = rest_of_page(base);
page = nfs_page_to_page(req, base);
nfs_page_iter_page_advance(i, len);
diff --git a/fs/remap_range.c b/fs/remap_range.c
index 26afbbbfb10c..83f325e7f96b 100644
--- a/fs/remap_range.c
+++ b/fs/remap_range.c
@@ -199,8 +199,7 @@ static int vfs_dedupe_file_range_compare(struct file *src, loff_t srcoff,
while (len) {
struct folio *src_folio, *dst_folio;
void *src_addr, *dst_addr;
- 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));
cmp_len = min(cmp_len, len);
if (cmp_len <= 0)
diff --git a/fs/xfs/scrub/xfile.c b/fs/xfs/scrub/xfile.c
index 05581571854d..95707407aa6b 100644
--- a/fs/xfs/scrub/xfile.c
+++ b/fs/xfs/scrub/xfile.c
@@ -135,8 +135,7 @@ xfile_load(
* No data stored at this offset, just zero the output
* buffer until the next page boundary.
*/
- len = min_t(ssize_t, count,
- PAGE_SIZE - offset_in_page(pos));
+ len = min_t(ssize_t, count, rest_of_page(pos));
memset(buf, 0, len);
} else {
if (filemap_check_wb_err(inode->i_mapping, 0)) {
--
2.43.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 3/8] net: use rest_of_page() macro where appropriate
2026-03-04 1:27 [PATCH 0/8] mm: globalize rest_of_page() macro Yury Norov
2026-03-04 1:27 ` [PATCH 1/8] mm: add " Yury Norov
2026-03-04 1:27 ` [PATCH 2/8] fs: use rest_of_page() macro where appropriate Yury Norov
@ 2026-03-04 1:27 ` Yury Norov
2026-03-04 1:27 ` [PATCH 4/8] core: " Yury Norov
` (5 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Yury Norov @ 2026-03-04 1:27 UTC (permalink / raw)
To: Andrew Morton, David S. Miller, Michael S. Tsirkin,
Theodore Ts'o, Albert Ou, Alexander Duyck, Alexander Gordeev,
Alexander Viro, Alexandra Winter, Andreas Dilger, Andrew Lunn,
Anna Schumaker, Anton Yakovlev, Arnaldo Carvalho de Melo,
Aswin Karuvally, Borislav Petkov, Carlos Maiolino,
Catalin Marinas, Chao Yu, Christian Borntraeger,
Christian Brauner, Claudio Imbrenda, Dave Hansen, David Airlie,
Dominique Martinet, Dongsheng Yang, Eric Dumazet,
Eric Van Hensbergen, Heiko Carstens, Herbert Xu, Ingo Molnar,
Jaegeuk Kim, Jakub Kicinski, Jani Nikula, Janosch Frank,
Jaroslav Kysela, Jens Axboe, Joonas Lahtinen, Latchesar Ionkov,
Linus Walleij, Madhavan Srinivasan, Mark Brown, Michael Ellerman,
Miklos Szeredi, Namhyung Kim, Palmer Dabbelt, Paolo Abeni,
Paolo Bonzini, Paul Walmsley, Peter Zijlstra, Rodrigo Vivi,
Sean Christopherson, Simona Vetter, Takashi Iwai,
Thomas Gleixner, Trond Myklebust, Tvrtko Ursulin, Vasily Gorbik,
Will Deacon, Yury Norov, Zheng Gu
Cc: Yury Norov, linux-kernel, x86, linux-arm-kernel, linuxppc-dev,
linux-riscv, kvm, linux-s390, linux-block, intel-gfx, dri-devel,
dm-devel, netdev, linux-spi, linux-ext4, linux-f2fs-devel,
linux-fsdevel, linux-xfs, linux-nfs, linux-crypto, linux-mm,
linux-perf-users, v9fs, virtualization, linux-sound
Switch networking codebase to using the macro. No functional changes
intended.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
drivers/net/ethernet/meta/fbnic/fbnic_tlv.c | 6 +++---
drivers/s390/net/qeth_core_main.c | 6 ++----
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_tlv.c b/drivers/net/ethernet/meta/fbnic/fbnic_tlv.c
index 517ed8b2f1cb..2e80c25ba3c8 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_tlv.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_tlv.c
@@ -52,7 +52,7 @@ struct fbnic_tlv_msg *fbnic_tlv_msg_alloc(u16 msg_id)
**/
int fbnic_tlv_attr_put_flag(struct fbnic_tlv_msg *msg, const u16 attr_id)
{
- int attr_max_len = PAGE_SIZE - offset_in_page(msg) - sizeof(*msg);
+ int attr_max_len = rest_of_page(msg) - sizeof(*msg);
struct fbnic_tlv_hdr hdr = { 0 };
struct fbnic_tlv_msg *attr;
@@ -94,7 +94,7 @@ int fbnic_tlv_attr_put_flag(struct fbnic_tlv_msg *msg, const u16 attr_id)
int fbnic_tlv_attr_put_value(struct fbnic_tlv_msg *msg, const u16 attr_id,
const void *value, const int len)
{
- int attr_max_len = PAGE_SIZE - offset_in_page(msg) - sizeof(*msg);
+ int attr_max_len = rest_of_page(msg) - sizeof(*msg);
struct fbnic_tlv_hdr hdr = { 0 };
struct fbnic_tlv_msg *attr;
@@ -292,7 +292,7 @@ ssize_t fbnic_tlv_attr_get_string(struct fbnic_tlv_msg *attr, char *dst,
struct fbnic_tlv_msg *fbnic_tlv_attr_nest_start(struct fbnic_tlv_msg *msg,
u16 attr_id)
{
- int attr_max_len = PAGE_SIZE - offset_in_page(msg) - sizeof(*msg);
+ int attr_max_len = rest_of_page(msg) - sizeof(*msg);
struct fbnic_tlv_msg *attr = &msg[le16_to_cpu(msg->hdr.len)];
struct fbnic_tlv_hdr hdr = { 0 };
diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index cf5f760d0e02..5012c22d8f37 100644
--- a/drivers/s390/net/qeth_core_main.c
+++ b/drivers/s390/net/qeth_core_main.c
@@ -4087,8 +4087,7 @@ static unsigned int qeth_fill_buffer(struct qeth_qdio_out_buffer *buf,
/* map linear part into buffer element(s) */
while (length > 0) {
- elem_length = min_t(unsigned int, length,
- PAGE_SIZE - offset_in_page(data));
+ elem_length = min_t(unsigned int, length, rest_of_page(data));
buffer->element[element].addr = virt_to_dma64(data);
buffer->element[element].length = elem_length;
@@ -4117,8 +4116,7 @@ static unsigned int qeth_fill_buffer(struct qeth_qdio_out_buffer *buf,
data = skb_frag_address(frag);
length = skb_frag_size(frag);
while (length > 0) {
- elem_length = min_t(unsigned int, length,
- PAGE_SIZE - offset_in_page(data));
+ elem_length = min_t(unsigned int, length, rest_of_page(data));
buffer->element[element].addr = virt_to_dma64(data);
buffer->element[element].length = elem_length;
--
2.43.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 4/8] core: use rest_of_page() macro where appropriate
2026-03-04 1:27 [PATCH 0/8] mm: globalize rest_of_page() macro Yury Norov
` (2 preceding siblings ...)
2026-03-04 1:27 ` [PATCH 3/8] net: " Yury Norov
@ 2026-03-04 1:27 ` Yury Norov
2026-03-04 1:27 ` [PATCH 5/8] spi: " Yury Norov
` (4 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Yury Norov @ 2026-03-04 1:27 UTC (permalink / raw)
To: Andrew Morton, David S. Miller, Michael S. Tsirkin,
Theodore Ts'o, Albert Ou, Alexander Duyck, Alexander Gordeev,
Alexander Viro, Alexandra Winter, Andreas Dilger, Andrew Lunn,
Anna Schumaker, Anton Yakovlev, Arnaldo Carvalho de Melo,
Aswin Karuvally, Borislav Petkov, Carlos Maiolino,
Catalin Marinas, Chao Yu, Christian Borntraeger,
Christian Brauner, Claudio Imbrenda, Dave Hansen, David Airlie,
Dominique Martinet, Dongsheng Yang, Eric Dumazet,
Eric Van Hensbergen, Heiko Carstens, Herbert Xu, Ingo Molnar,
Jaegeuk Kim, Jakub Kicinski, Jani Nikula, Janosch Frank,
Jaroslav Kysela, Jens Axboe, Joonas Lahtinen, Latchesar Ionkov,
Linus Walleij, Madhavan Srinivasan, Mark Brown, Michael Ellerman,
Miklos Szeredi, Namhyung Kim, Palmer Dabbelt, Paolo Abeni,
Paolo Bonzini, Paul Walmsley, Peter Zijlstra, Rodrigo Vivi,
Sean Christopherson, Simona Vetter, Takashi Iwai,
Thomas Gleixner, Trond Myklebust, Tvrtko Ursulin, Vasily Gorbik,
Will Deacon, Yury Norov, Zheng Gu
Cc: Yury Norov, linux-kernel, x86, linux-arm-kernel, linuxppc-dev,
linux-riscv, kvm, linux-s390, linux-block, intel-gfx, dri-devel,
dm-devel, netdev, linux-spi, linux-ext4, linux-f2fs-devel,
linux-fsdevel, linux-xfs, linux-nfs, linux-crypto, linux-mm,
linux-perf-users, v9fs, virtualization, linux-sound
Switch core and library code to using the macro. No functional
changes intended.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
include/crypto/scatterwalk.h | 2 +-
include/linux/highmem.h | 24 ++++++++++--------------
include/linux/iomap.h | 2 +-
include/linux/iov_iter.h | 3 +--
kernel/events/ring_buffer.c | 2 +-
lib/bitmap-str.c | 2 +-
lib/iov_iter.c | 5 ++---
7 files changed, 17 insertions(+), 23 deletions(-)
diff --git a/include/crypto/scatterwalk.h b/include/crypto/scatterwalk.h
index 624fab589c2c..c671d5383c12 100644
--- a/include/crypto/scatterwalk.h
+++ b/include/crypto/scatterwalk.h
@@ -73,7 +73,7 @@ static inline unsigned int scatterwalk_clamp(struct scatter_walk *walk,
* page due to the data not being aligned to the algorithm's alignmask.
*/
if (IS_ENABLED(CONFIG_HIGHMEM))
- limit = PAGE_SIZE - offset_in_page(walk->offset);
+ limit = rest_of_page(walk->offset);
else
limit = PAGE_SIZE;
diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index af03db851a1d..05528ba886fb 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -507,12 +507,10 @@ static inline void memcpy_folio(struct folio *dst_folio, size_t dst_off,
const char *src = kmap_local_folio(src_folio, src_off);
size_t chunk = len;
- 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);
memcpy(dst, src, chunk);
kunmap_local(src);
kunmap_local(dst);
@@ -580,9 +578,8 @@ static inline void memcpy_from_folio(char *to, struct folio *folio,
const char *from = kmap_local_folio(folio, offset);
size_t chunk = len;
- if (folio_test_partial_kmap(folio) &&
- chunk > PAGE_SIZE - offset_in_page(offset))
- chunk = PAGE_SIZE - offset_in_page(offset);
+ if (folio_test_partial_kmap(folio) && chunk > rest_of_page(offset))
+ chunk = rest_of_page(offset);
memcpy(to, from, chunk);
kunmap_local(from);
@@ -608,9 +605,8 @@ static inline void memcpy_to_folio(struct folio *folio, size_t offset,
char *to = kmap_local_folio(folio, offset);
size_t chunk = len;
- if (folio_test_partial_kmap(folio) &&
- chunk > PAGE_SIZE - offset_in_page(offset))
- chunk = PAGE_SIZE - offset_in_page(offset);
+ if (folio_test_partial_kmap(folio) && chunk > rest_of_page(offset))
+ chunk = rest_of_page(offset);
memcpy(to, from, chunk);
kunmap_local(to);
@@ -642,7 +638,7 @@ static inline __must_check void *folio_zero_tail(struct folio *folio,
size_t len = folio_size(folio) - offset;
if (folio_test_partial_kmap(folio)) {
- size_t max = PAGE_SIZE - offset_in_page(offset);
+ size_t max = rest_of_page(offset);
while (len > max) {
memset(kaddr, 0, max);
@@ -680,7 +676,7 @@ static inline void folio_fill_tail(struct folio *folio, size_t offset,
VM_BUG_ON(offset + len > folio_size(folio));
if (folio_test_partial_kmap(folio)) {
- size_t max = PAGE_SIZE - offset_in_page(offset);
+ size_t max = rest_of_page(offset);
while (len > max) {
memcpy(to, from, max);
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index 99b7209dabd7..6ae549192adb 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -142,7 +142,7 @@ static inline void *iomap_inline_data(const struct iomap *iomap, loff_t pos)
*/
static inline bool iomap_inline_data_valid(const struct iomap *iomap)
{
- return iomap->length <= PAGE_SIZE - offset_in_page(iomap->inline_data);
+ return iomap->length <= rest_of_page(iomap->inline_data);
}
/*
diff --git a/include/linux/iov_iter.h b/include/linux/iov_iter.h
index f9a17fbbd398..13a9ee653ef8 100644
--- a/include/linux/iov_iter.h
+++ b/include/linux/iov_iter.h
@@ -227,8 +227,7 @@ size_t iterate_xarray(struct iov_iter *iter, size_t len, void *priv, void *priv2
while (flen) {
void *base = kmap_local_folio(folio, offset);
- part = min_t(size_t, flen,
- PAGE_SIZE - offset_in_page(offset));
+ part = min_t(size_t, flen, rest_of_page(offset));
remain = step(base, progress, part, priv, priv2);
kunmap_local(base);
diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index 3e7de2661417..1db2868b90c9 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -590,7 +590,7 @@ long perf_output_copy_aux(struct perf_output_handle *aux_handle,
to &= (rb->aux_nr_pages << PAGE_SHIFT) - 1;
do {
- tocopy = PAGE_SIZE - offset_in_page(from);
+ tocopy = rest_of_page(from);
if (to > from)
tocopy = min(tocopy, to - from);
if (!tocopy)
diff --git a/lib/bitmap-str.c b/lib/bitmap-str.c
index be745209507a..a357342d5d6c 100644
--- a/lib/bitmap-str.c
+++ b/lib/bitmap-str.c
@@ -58,7 +58,7 @@ EXPORT_SYMBOL(bitmap_parse_user);
int bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp,
int nmaskbits)
{
- ptrdiff_t len = PAGE_SIZE - offset_in_page(buf);
+ ptrdiff_t len = rest_of_page(buf);
return list ? scnprintf(buf, len, "%*pbl\n", nmaskbits, maskp) :
scnprintf(buf, len, "%*pb\n", nmaskbits, maskp);
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 0a63c7fba313..c7e812349ca2 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -483,9 +483,8 @@ size_t copy_folio_from_iter_atomic(struct folio *folio, size_t offset,
char *to = kmap_local_folio(folio, offset);
n = bytes - copied;
- if (folio_test_partial_kmap(folio) &&
- n > PAGE_SIZE - offset_in_page(offset))
- n = PAGE_SIZE - offset_in_page(offset);
+ if (folio_test_partial_kmap(folio) && n > rest_of_page(offset))
+ n = rest_of_page(offset);
pagefault_disable();
n = __copy_from_iter(to, n, i);
--
2.43.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 5/8] spi: use rest_of_page() macro where appropriate
2026-03-04 1:27 [PATCH 0/8] mm: globalize rest_of_page() macro Yury Norov
` (3 preceding siblings ...)
2026-03-04 1:27 ` [PATCH 4/8] core: " Yury Norov
@ 2026-03-04 1:27 ` Yury Norov
2026-03-04 1:27 ` [PATCH 6/8] KVM: " Yury Norov
` (3 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Yury Norov @ 2026-03-04 1:27 UTC (permalink / raw)
To: Andrew Morton, David S. Miller, Michael S. Tsirkin,
Theodore Ts'o, Albert Ou, Alexander Duyck, Alexander Gordeev,
Alexander Viro, Alexandra Winter, Andreas Dilger, Andrew Lunn,
Anna Schumaker, Anton Yakovlev, Arnaldo Carvalho de Melo,
Aswin Karuvally, Borislav Petkov, Carlos Maiolino,
Catalin Marinas, Chao Yu, Christian Borntraeger,
Christian Brauner, Claudio Imbrenda, Dave Hansen, David Airlie,
Dominique Martinet, Dongsheng Yang, Eric Dumazet,
Eric Van Hensbergen, Heiko Carstens, Herbert Xu, Ingo Molnar,
Jaegeuk Kim, Jakub Kicinski, Jani Nikula, Janosch Frank,
Jaroslav Kysela, Jens Axboe, Joonas Lahtinen, Latchesar Ionkov,
Linus Walleij, Madhavan Srinivasan, Mark Brown, Michael Ellerman,
Miklos Szeredi, Namhyung Kim, Palmer Dabbelt, Paolo Abeni,
Paolo Bonzini, Paul Walmsley, Peter Zijlstra, Rodrigo Vivi,
Sean Christopherson, Simona Vetter, Takashi Iwai,
Thomas Gleixner, Trond Myklebust, Tvrtko Ursulin, Vasily Gorbik,
Will Deacon, Yury Norov, Zheng Gu
Cc: Yury Norov, linux-kernel, x86, linux-arm-kernel, linuxppc-dev,
linux-riscv, kvm, linux-s390, linux-block, intel-gfx, dri-devel,
dm-devel, netdev, linux-spi, linux-ext4, linux-f2fs-devel,
linux-fsdevel, linux-xfs, linux-nfs, linux-crypto, linux-mm,
linux-perf-users, v9fs, virtualization, linux-sound
Switch SPI code to using the macro. No functional changes intended.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
drivers/spi/spi-pl022.c | 3 +--
drivers/spi/spi.c | 4 +---
2 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c
index c82cc522776d..78fce33ff422 100644
--- a/drivers/spi/spi-pl022.c
+++ b/drivers/spi/spi-pl022.c
@@ -761,8 +761,7 @@ static void setup_dma_scatter(struct pl022 *pl022,
* we just feed in this, else we stuff in as much
* as we can.
*/
- mapbytes = min_t(int, bytesleft,
- PAGE_SIZE - offset_in_page(bufp));
+ mapbytes = min_t(int, bytesleft, rest_of_page(bufp));
sg_set_page(sg, virt_to_page(bufp),
mapbytes, offset_in_page(bufp));
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 61f7bde8c7fb..cd4a18f3afaf 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1162,9 +1162,7 @@ static int spi_map_buf_attrs(struct spi_controller *ctlr, struct device *dev,
* the desc_len and the remaining buffer length that
* fits in a page.
*/
- min = min_t(size_t, desc_len,
- min_t(size_t, len,
- PAGE_SIZE - offset_in_page(buf)));
+ min = min_t(size_t, desc_len, min_t(size_t, len, rest_of_page(buf)));
if (vmalloced_buf)
vm_page = vmalloc_to_page(buf);
else
--
2.43.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 6/8] KVM: use rest_of_page() macro where appropriate
2026-03-04 1:27 [PATCH 0/8] mm: globalize rest_of_page() macro Yury Norov
` (4 preceding siblings ...)
2026-03-04 1:27 ` [PATCH 5/8] spi: " Yury Norov
@ 2026-03-04 1:27 ` Yury Norov
2026-03-04 1:27 ` [PATCH 7/8] drivers: ALSA: " Yury Norov
` (2 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Yury Norov @ 2026-03-04 1:27 UTC (permalink / raw)
To: Andrew Morton, David S. Miller, Michael S. Tsirkin,
Theodore Ts'o, Albert Ou, Alexander Duyck, Alexander Gordeev,
Alexander Viro, Alexandra Winter, Andreas Dilger, Andrew Lunn,
Anna Schumaker, Anton Yakovlev, Arnaldo Carvalho de Melo,
Aswin Karuvally, Borislav Petkov, Carlos Maiolino,
Catalin Marinas, Chao Yu, Christian Borntraeger,
Christian Brauner, Claudio Imbrenda, Dave Hansen, David Airlie,
Dominique Martinet, Dongsheng Yang, Eric Dumazet,
Eric Van Hensbergen, Heiko Carstens, Herbert Xu, Ingo Molnar,
Jaegeuk Kim, Jakub Kicinski, Jani Nikula, Janosch Frank,
Jaroslav Kysela, Jens Axboe, Joonas Lahtinen, Latchesar Ionkov,
Linus Walleij, Madhavan Srinivasan, Mark Brown, Michael Ellerman,
Miklos Szeredi, Namhyung Kim, Palmer Dabbelt, Paolo Abeni,
Paolo Bonzini, Paul Walmsley, Peter Zijlstra, Rodrigo Vivi,
Sean Christopherson, Simona Vetter, Takashi Iwai,
Thomas Gleixner, Trond Myklebust, Tvrtko Ursulin, Vasily Gorbik,
Will Deacon, Yury Norov, Zheng Gu
Cc: Yury Norov, linux-kernel, x86, linux-arm-kernel, linuxppc-dev,
linux-riscv, kvm, linux-s390, linux-block, intel-gfx, dri-devel,
dm-devel, netdev, linux-spi, linux-ext4, linux-f2fs-devel,
linux-fsdevel, linux-xfs, linux-nfs, linux-crypto, linux-mm,
linux-perf-users, v9fs, virtualization, linux-sound
Switch KVM code to using the macro. No functional changes intended.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
arch/s390/kvm/gaccess.c | 6 +++---
arch/x86/kvm/emulate.c | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/arch/s390/kvm/gaccess.c b/arch/s390/kvm/gaccess.c
index 4630b2a067ea..40f85b7eca63 100644
--- a/arch/s390/kvm/gaccess.c
+++ b/arch/s390/kvm/gaccess.c
@@ -973,7 +973,7 @@ int access_guest_with_key(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar,
if (rc)
goto out_unlock;
for (idx = 0; idx < nr_pages; idx++) {
- fragment_len = min(PAGE_SIZE - offset_in_page(gpas[idx]), len);
+ fragment_len = min(rest_of_page(gpas[idx]), len);
if (try_fetch_prot_override && fetch_prot_override_applies(ga, fragment_len)) {
rc = access_guest_page_gpa(vcpu->kvm, mode, gpas[idx], data, fragment_len);
} else {
@@ -1015,7 +1015,7 @@ int access_guest_real(struct kvm_vcpu *vcpu, unsigned long gra,
while (len && !rc) {
gpa = kvm_s390_real_to_abs(vcpu, gra);
- fragment_len = min(PAGE_SIZE - offset_in_page(gpa), len);
+ fragment_len = min(rest_of_page(gpa), len);
rc = access_guest_page_gpa(vcpu->kvm, mode, gpa, data, fragment_len);
len -= fragment_len;
gra += fragment_len;
@@ -1237,7 +1237,7 @@ int check_gpa_range(struct kvm *kvm, unsigned long gpa, unsigned long length,
int rc = 0;
while (length && !rc) {
- fragment_len = min(PAGE_SIZE - offset_in_page(gpa), length);
+ fragment_len = min(rest_of_page(gpa), length);
rc = vm_check_access_key_gpa(kvm, access_key, mode, gpa);
length -= fragment_len;
gpa += fragment_len;
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index c8e292e9a24d..c060d1e2bb94 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -864,7 +864,7 @@ static int __do_insn_fetch_bytes(struct x86_emulate_ctxt *ctxt, int op_size)
return rc;
size = min_t(unsigned, 15UL ^ cur_size, max_size);
- size = min_t(unsigned, size, PAGE_SIZE - offset_in_page(linear));
+ size = min_t(unsigned int, size, rest_of_page(linear));
/*
* One instruction can only straddle two pages,
@@ -1372,7 +1372,7 @@ static int pio_in_emulated(struct x86_emulate_ctxt *ctxt,
address_mask(ctxt, reg_read(ctxt, VCPU_REGS_RCX)) : 1;
in_page = (ctxt->eflags & X86_EFLAGS_DF) ?
offset_in_page(reg_read(ctxt, VCPU_REGS_RDI)) :
- PAGE_SIZE - offset_in_page(reg_read(ctxt, VCPU_REGS_RDI));
+ rest_of_page(reg_read(ctxt, VCPU_REGS_RDI));
n = min3(in_page, (unsigned int)sizeof(rc->data) / size, count);
if (n == 0)
n = 1;
--
2.43.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 7/8] drivers: ALSA: use rest_of_page() macro where appropriate
2026-03-04 1:27 [PATCH 0/8] mm: globalize rest_of_page() macro Yury Norov
` (5 preceding siblings ...)
2026-03-04 1:27 ` [PATCH 6/8] KVM: " Yury Norov
@ 2026-03-04 1:27 ` Yury Norov
2026-03-04 1:27 ` [PATCH 8/8] arch: " Yury Norov
2026-03-04 2:28 ` [PATCH 0/8] mm: globalize rest_of_page() macro Jakub Kicinski
8 siblings, 0 replies; 12+ messages in thread
From: Yury Norov @ 2026-03-04 1:27 UTC (permalink / raw)
To: Andrew Morton, David S. Miller, Michael S. Tsirkin,
Theodore Ts'o, Albert Ou, Alexander Duyck, Alexander Gordeev,
Alexander Viro, Alexandra Winter, Andreas Dilger, Andrew Lunn,
Anna Schumaker, Anton Yakovlev, Arnaldo Carvalho de Melo,
Aswin Karuvally, Borislav Petkov, Carlos Maiolino,
Catalin Marinas, Chao Yu, Christian Borntraeger,
Christian Brauner, Claudio Imbrenda, Dave Hansen, David Airlie,
Dominique Martinet, Dongsheng Yang, Eric Dumazet,
Eric Van Hensbergen, Heiko Carstens, Herbert Xu, Ingo Molnar,
Jaegeuk Kim, Jakub Kicinski, Jani Nikula, Janosch Frank,
Jaroslav Kysela, Jens Axboe, Joonas Lahtinen, Latchesar Ionkov,
Linus Walleij, Madhavan Srinivasan, Mark Brown, Michael Ellerman,
Miklos Szeredi, Namhyung Kim, Palmer Dabbelt, Paolo Abeni,
Paolo Bonzini, Paul Walmsley, Peter Zijlstra, Rodrigo Vivi,
Sean Christopherson, Simona Vetter, Takashi Iwai,
Thomas Gleixner, Trond Myklebust, Tvrtko Ursulin, Vasily Gorbik,
Will Deacon, Yury Norov, Zheng Gu
Cc: Yury Norov, linux-kernel, x86, linux-arm-kernel, linuxppc-dev,
linux-riscv, kvm, linux-s390, linux-block, intel-gfx, dri-devel,
dm-devel, netdev, linux-spi, linux-ext4, linux-f2fs-devel,
linux-fsdevel, linux-xfs, linux-nfs, linux-crypto, linux-mm,
linux-perf-users, v9fs, virtualization, linux-sound
Switch drivers to using the macro. No functional changes intended.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
drivers/block/null_blk/main.c | 6 ++----
drivers/gpu/drm/i915/gt/shmem_utils.c | 5 ++---
drivers/md/dm-pcache/backing_dev.h | 2 +-
sound/virtio/virtio_pcm_msg.c | 4 ++--
4 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index f8c0fd57e041..89e9651b09a9 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -1147,8 +1147,7 @@ static blk_status_t copy_to_nullb(struct nullb *nullb, void *source,
sector_t sector;
while (count < n) {
- temp = min3(nullb->dev->blocksize, n - count,
- PAGE_SIZE - offset_in_page(pos));
+ temp = min3(nullb->dev->blocksize, n - count, rest_of_page(pos));
sector = pos >> SECTOR_SHIFT;
if (null_cache_active(nullb) && !is_fua)
@@ -1181,8 +1180,7 @@ static void copy_from_nullb(struct nullb *nullb, void *dest, loff_t pos,
sector_t sector;
while (count < n) {
- temp = min3(nullb->dev->blocksize, n - count,
- PAGE_SIZE - offset_in_page(pos));
+ temp = min3(nullb->dev->blocksize, n - count, rest_of_page(pos));
sector = pos >> SECTOR_SHIFT;
t_page = null_lookup_page(nullb, sector, false,
diff --git a/drivers/gpu/drm/i915/gt/shmem_utils.c b/drivers/gpu/drm/i915/gt/shmem_utils.c
index 5850adaebf82..9a0a6f67fef0 100644
--- a/drivers/gpu/drm/i915/gt/shmem_utils.c
+++ b/drivers/gpu/drm/i915/gt/shmem_utils.c
@@ -99,8 +99,7 @@ static int __shmem_rw(struct file *file, loff_t off,
unsigned long pfn;
for (pfn = off >> PAGE_SHIFT; len; pfn++) {
- unsigned int this =
- min_t(size_t, PAGE_SIZE - offset_in_page(off), len);
+ unsigned int this = min_t(size_t, rest_of_page(off), len);
struct page *page;
void *vaddr;
@@ -135,7 +134,7 @@ int shmem_read_to_iosys_map(struct file *file, loff_t off,
for (pfn = off >> PAGE_SHIFT; len; pfn++) {
unsigned int this =
- min_t(size_t, PAGE_SIZE - offset_in_page(off), len);
+ min_t(size_t, rest_of_page(off), len);
struct page *page;
void *vaddr;
diff --git a/drivers/md/dm-pcache/backing_dev.h b/drivers/md/dm-pcache/backing_dev.h
index b371cba483b9..17e83b38b845 100644
--- a/drivers/md/dm-pcache/backing_dev.h
+++ b/drivers/md/dm-pcache/backing_dev.h
@@ -96,7 +96,7 @@ static inline u32 backing_dev_req_coalesced_max_len(const void *data, u32 len)
first_page = vmalloc_to_page(p);
advance:
- in_page = PAGE_SIZE - offset_in_page(p);
+ in_page = rest_of_page(p);
to_advance = min_t(u32, in_page, len - done);
done += to_advance;
diff --git a/sound/virtio/virtio_pcm_msg.c b/sound/virtio/virtio_pcm_msg.c
index a5c4e7027717..5d1b0dc08234 100644
--- a/sound/virtio/virtio_pcm_msg.c
+++ b/sound/virtio/virtio_pcm_msg.c
@@ -56,7 +56,7 @@ static int virtsnd_pcm_sg_num(u8 *data, unsigned int length)
phys_addr_t pg_address = page_to_phys(pg);
size_t pg_length;
- pg_length = PAGE_SIZE - offset_in_page(data);
+ pg_length = rest_of_page(data);
if (pg_length > length)
pg_length = length;
@@ -96,7 +96,7 @@ static void virtsnd_pcm_sg_from(struct scatterlist *sgs, int nsgs, u8 *data,
struct page *pg = vmalloc_to_page(data);
size_t pg_length;
- pg_length = PAGE_SIZE - offset_in_page(data);
+ pg_length = rest_of_page(data);
if (pg_length > length)
pg_length = length;
--
2.43.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 8/8] arch: use rest_of_page() macro where appropriate
2026-03-04 1:27 [PATCH 0/8] mm: globalize rest_of_page() macro Yury Norov
` (6 preceding siblings ...)
2026-03-04 1:27 ` [PATCH 7/8] drivers: ALSA: " Yury Norov
@ 2026-03-04 1:27 ` Yury Norov
2026-03-04 2:28 ` [PATCH 0/8] mm: globalize rest_of_page() macro Jakub Kicinski
8 siblings, 0 replies; 12+ messages in thread
From: Yury Norov @ 2026-03-04 1:27 UTC (permalink / raw)
To: Andrew Morton, David S. Miller, Michael S. Tsirkin,
Theodore Ts'o, Albert Ou, Alexander Duyck, Alexander Gordeev,
Alexander Viro, Alexandra Winter, Andreas Dilger, Andrew Lunn,
Anna Schumaker, Anton Yakovlev, Arnaldo Carvalho de Melo,
Aswin Karuvally, Borislav Petkov, Carlos Maiolino,
Catalin Marinas, Chao Yu, Christian Borntraeger,
Christian Brauner, Claudio Imbrenda, Dave Hansen, David Airlie,
Dominique Martinet, Dongsheng Yang, Eric Dumazet,
Eric Van Hensbergen, Heiko Carstens, Herbert Xu, Ingo Molnar,
Jaegeuk Kim, Jakub Kicinski, Jani Nikula, Janosch Frank,
Jaroslav Kysela, Jens Axboe, Joonas Lahtinen, Latchesar Ionkov,
Linus Walleij, Madhavan Srinivasan, Mark Brown, Michael Ellerman,
Miklos Szeredi, Namhyung Kim, Palmer Dabbelt, Paolo Abeni,
Paolo Bonzini, Paul Walmsley, Peter Zijlstra, Rodrigo Vivi,
Sean Christopherson, Simona Vetter, Takashi Iwai,
Thomas Gleixner, Trond Myklebust, Tvrtko Ursulin, Vasily Gorbik,
Will Deacon, Yury Norov, Zheng Gu
Cc: Yury Norov, linux-kernel, x86, linux-arm-kernel, linuxppc-dev,
linux-riscv, kvm, linux-s390, linux-block, intel-gfx, dri-devel,
dm-devel, netdev, linux-spi, linux-ext4, linux-f2fs-devel,
linux-fsdevel, linux-xfs, linux-nfs, linux-crypto, linux-mm,
linux-perf-users, v9fs, virtualization, linux-sound
Switch arch code to using the macro. No functional changes intended.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
arch/arm64/kernel/patching.c | 4 +---
arch/powerpc/lib/code-patching.c | 6 +++---
arch/riscv/kernel/sbi.c | 4 ++--
3 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/arch/arm64/kernel/patching.c b/arch/arm64/kernel/patching.c
index 1041bc67a3ee..4c3a4401719b 100644
--- a/arch/arm64/kernel/patching.c
+++ b/arch/arm64/kernel/patching.c
@@ -116,9 +116,7 @@ static void *__text_poke(text_poke_f func, void *addr, void *src, size_t len)
while (patched < len) {
ptr = addr + patched;
- size = min_t(size_t, PAGE_SIZE - offset_in_page(ptr),
- len - patched);
-
+ size = min_t(size_t, rest_of_page(ptr), len - patched);
waddr = patch_map(ptr, FIX_TEXT_POKE0);
func(waddr, src, patched, size);
patch_unmap(FIX_TEXT_POKE0);
diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c
index f84e0337cc02..186a9cb79ee3 100644
--- a/arch/powerpc/lib/code-patching.c
+++ b/arch/powerpc/lib/code-patching.c
@@ -463,7 +463,7 @@ static int __patch_instructions(u32 *patch_addr, u32 *code, size_t len, bool rep
/*
* A page is mapped and instructions that fit the page are patched.
- * Assumes 'len' to be (PAGE_SIZE - offset_in_page(addr)) or below.
+ * Assumes 'len' to be rest_of_page(addr) or below.
*/
static int __do_patch_instructions_mm(u32 *addr, u32 *code, size_t len, bool repeat_instr)
{
@@ -514,7 +514,7 @@ static int __do_patch_instructions_mm(u32 *addr, u32 *code, size_t len, bool rep
/*
* A page is mapped and instructions that fit the page are patched.
- * Assumes 'len' to be (PAGE_SIZE - offset_in_page(addr)) or below.
+ * Assumes 'len' to be rest_of_page(addr) or below.
*/
static int __do_patch_instructions(u32 *addr, u32 *code, size_t len, bool repeat_instr)
{
@@ -554,7 +554,7 @@ int patch_instructions(u32 *addr, u32 *code, size_t len, bool repeat_instr)
size_t plen;
int err;
- plen = min_t(size_t, PAGE_SIZE - offset_in_page(addr), len);
+ plen = min_t(size_t, rest_of_page(addr), len);
local_irq_save(flags);
if (mm_patch_enabled())
diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
index c443337056ab..9a2f656f776f 100644
--- a/arch/riscv/kernel/sbi.c
+++ b/arch/riscv/kernel/sbi.c
@@ -602,7 +602,7 @@ int sbi_debug_console_write(const char *bytes, unsigned int num_bytes)
else
base_addr = __pa(bytes);
if (PAGE_SIZE < (offset_in_page(bytes) + num_bytes))
- num_bytes = PAGE_SIZE - offset_in_page(bytes);
+ num_bytes = rest_of_page(bytes);
if (IS_ENABLED(CONFIG_32BIT))
ret = sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE,
@@ -631,7 +631,7 @@ int sbi_debug_console_read(char *bytes, unsigned int num_bytes)
else
base_addr = __pa(bytes);
if (PAGE_SIZE < (offset_in_page(bytes) + num_bytes))
- num_bytes = PAGE_SIZE - offset_in_page(bytes);
+ num_bytes = rest_of_page(bytes);
if (IS_ENABLED(CONFIG_32BIT))
ret = sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_READ,
--
2.43.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/8] mm: globalize rest_of_page() macro
2026-03-04 1:27 [PATCH 0/8] mm: globalize rest_of_page() macro Yury Norov
` (7 preceding siblings ...)
2026-03-04 1:27 ` [PATCH 8/8] arch: " Yury Norov
@ 2026-03-04 2:28 ` Jakub Kicinski
2026-03-04 2:42 ` Jens Axboe
8 siblings, 1 reply; 12+ messages in thread
From: Jakub Kicinski @ 2026-03-04 2:28 UTC (permalink / raw)
To: Yury Norov
Cc: Andrew Morton, David S. Miller, Michael S. Tsirkin,
Theodore Ts'o, Albert Ou, Alexander Duyck, Alexander Gordeev,
Alexander Viro, Alexandra Winter, Andreas Dilger, Andrew Lunn,
Anna Schumaker, Anton Yakovlev, Arnaldo Carvalho de Melo,
Aswin Karuvally, Borislav Petkov, Carlos Maiolino,
Catalin Marinas, Chao Yu, Christian Borntraeger,
Christian Brauner, Claudio Imbrenda, Dave Hansen, David Airlie,
Dominique Martinet, Dongsheng Yang, Eric Dumazet,
Eric Van Hensbergen, Heiko Carstens, Herbert Xu, Ingo Molnar,
Jaegeuk Kim, Jani Nikula, Janosch Frank, Jaroslav Kysela,
Jens Axboe, Joonas Lahtinen, Latchesar Ionkov, Linus Walleij,
Madhavan Srinivasan, Mark Brown, Michael Ellerman,
Miklos Szeredi, Namhyung Kim, Palmer Dabbelt, Paolo Abeni,
Paolo Bonzini, Paul Walmsley, Peter Zijlstra, Rodrigo Vivi,
Sean Christopherson, Simona Vetter, Takashi Iwai,
Thomas Gleixner, Trond Myklebust, Tvrtko Ursulin, Vasily Gorbik,
Will Deacon, Yury Norov, Zheng Gu, linux-kernel, x86,
linux-arm-kernel, linuxppc-dev, linux-riscv, kvm, linux-s390,
linux-block, intel-gfx, dri-devel, dm-devel, netdev, linux-spi,
linux-ext4, linux-f2fs-devel, linux-fsdevel, linux-xfs,
linux-nfs, linux-crypto, linux-mm, linux-perf-users, v9fs,
virtualization, linux-sound
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.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/8] mm: globalize rest_of_page() macro
2026-03-04 2:28 ` [PATCH 0/8] mm: globalize rest_of_page() macro Jakub Kicinski
@ 2026-03-04 2:42 ` Jens Axboe
2026-03-04 2:49 ` Sean Christopherson
0 siblings, 1 reply; 12+ messages in thread
From: Jens Axboe @ 2026-03-04 2:42 UTC (permalink / raw)
To: Jakub Kicinski, Yury Norov
Cc: Andrew Morton, David S. Miller, Michael S. Tsirkin,
Theodore Ts'o, Albert Ou, Alexander Duyck, Alexander Gordeev,
Alexander Viro, Alexandra Winter, Andreas Dilger, Andrew Lunn,
Anna Schumaker, Anton Yakovlev, Arnaldo Carvalho de Melo,
Aswin Karuvally, Borislav Petkov, Carlos Maiolino,
Catalin Marinas, Chao Yu, Christian Borntraeger,
Christian Brauner, Claudio Imbrenda, Dave Hansen, David Airlie,
Dominique Martinet, Dongsheng Yang, Eric Dumazet,
Eric Van Hensbergen, Heiko Carstens, Herbert Xu, Ingo Molnar,
Jaegeuk Kim, Jani Nikula, Janosch Frank, Jaroslav Kysela,
Joonas Lahtinen, Latchesar Ionkov, Linus Walleij,
Madhavan Srinivasan, Mark Brown, Michael Ellerman,
Miklos Szeredi, Namhyung Kim, Palmer Dabbelt, Paolo Abeni,
Paolo Bonzini, Paul Walmsley, Peter Zijlstra, Rodrigo Vivi,
Sean Christopherson, Simona Vetter, Takashi Iwai,
Thomas Gleixner, Trond Myklebust, Tvrtko Ursulin, Vasily Gorbik,
Will Deacon, Yury Norov, Zheng Gu, linux-kernel, x86,
linux-arm-kernel, linuxppc-dev, linux-riscv, kvm, linux-s390,
linux-block, intel-gfx, dri-devel, dm-devel, netdev, linux-spi,
linux-ext4, linux-f2fs-devel, linux-fsdevel, linux-xfs,
linux-nfs, linux-crypto, linux-mm, linux-perf-users, v9fs,
virtualization, linux-sound
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/8] mm: globalize rest_of_page() macro
2026-03-04 2:42 ` Jens Axboe
@ 2026-03-04 2:49 ` Sean Christopherson
0 siblings, 0 replies; 12+ messages in thread
From: Sean Christopherson @ 2026-03-04 2:49 UTC (permalink / raw)
To: Jens Axboe
Cc: Jakub Kicinski, Yury Norov, Andrew Morton, David S. Miller,
Michael S. Tsirkin, Theodore Ts'o, Albert Ou,
Alexander Duyck, Alexander Gordeev, Alexander Viro,
Alexandra Winter, Andreas Dilger, Andrew Lunn, Anna Schumaker,
Anton Yakovlev, Arnaldo Carvalho de Melo, Aswin Karuvally,
Borislav Petkov, Carlos Maiolino, Catalin Marinas, Chao Yu,
Christian Borntraeger, Christian Brauner, Claudio Imbrenda,
Dave Hansen, David Airlie, Dominique Martinet, Dongsheng Yang,
Eric Dumazet, Eric Van Hensbergen, Heiko Carstens, Herbert Xu,
Ingo Molnar, Jaegeuk Kim, Jani Nikula, Janosch Frank,
Jaroslav Kysela, Joonas Lahtinen, Latchesar Ionkov,
Linus Walleij, Madhavan Srinivasan, Mark Brown, Michael Ellerman,
Miklos Szeredi, Namhyung Kim, Palmer Dabbelt, Paolo Abeni,
Paolo Bonzini, Paul Walmsley, Peter Zijlstra, Rodrigo Vivi,
Simona Vetter, Takashi Iwai, Thomas Gleixner, Trond Myklebust,
Tvrtko Ursulin, Vasily Gorbik, Will Deacon, Yury Norov, Zheng Gu,
linux-kernel, x86, linux-arm-kernel, linuxppc-dev, linux-riscv,
kvm, linux-s390, linux-block, intel-gfx, dri-devel, dm-devel,
netdev, linux-spi, linux-ext4, linux-f2fs-devel, linux-fsdevel,
linux-xfs, linux-nfs, linux-crypto, linux-mm, linux-perf-users,
v9fs, virtualization, linux-sound
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.
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-03-04 2:49 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-04 1:27 [PATCH 0/8] mm: globalize rest_of_page() macro Yury Norov
2026-03-04 1:27 ` [PATCH 1/8] mm: add " Yury Norov
2026-03-04 1:27 ` [PATCH 2/8] fs: use rest_of_page() macro where appropriate Yury Norov
2026-03-04 1:27 ` [PATCH 3/8] net: " Yury Norov
2026-03-04 1:27 ` [PATCH 4/8] core: " Yury Norov
2026-03-04 1:27 ` [PATCH 5/8] spi: " Yury Norov
2026-03-04 1:27 ` [PATCH 6/8] KVM: " Yury Norov
2026-03-04 1:27 ` [PATCH 7/8] drivers: ALSA: " Yury Norov
2026-03-04 1:27 ` [PATCH 8/8] arch: " Yury Norov
2026-03-04 2:28 ` [PATCH 0/8] mm: globalize rest_of_page() macro Jakub Kicinski
2026-03-04 2:42 ` Jens Axboe
2026-03-04 2:49 ` Sean Christopherson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox