* [PATCH v1] selftests: udmabuf: fix hugepage size calculation
@ 2026-01-18 13:51 zishun yi
2026-01-18 20:38 ` Andrew Morton
0 siblings, 1 reply; 5+ messages in thread
From: zishun yi @ 2026-01-18 13:51 UTC (permalink / raw)
To: shuah
Cc: vivek.kasireddy, akpm, linux-kselftest, linux-kernel,
richard.weiyang, reddybalavignesh9979, zishun yi
udmabuf's test 6 and 7 is intended to verify the behavior of 2MB huge pages migration,
but the helper function still calculates the size using standard (4KB) pages.
Signed-off-by: zishun yi <zishun.yi.dev@gmail.com>
---
tools/testing/selftests/drivers/dma-buf/udmabuf.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/drivers/dma-buf/udmabuf.c b/tools/testing/selftests/drivers/dma-buf/udmabuf.c
index d78aec662586..8887fb9b79df 100644
--- a/tools/testing/selftests/drivers/dma-buf/udmabuf.c
+++ b/tools/testing/selftests/drivers/dma-buf/udmabuf.c
@@ -69,7 +69,7 @@ static int create_udmabuf_list(int devfd, int memfd, off64_t memfd_size)
for (i = 0; i < NUM_ENTRIES; i++) {
list->list[i].memfd = memfd;
list->list[i].offset = i * (memfd_size / NUM_ENTRIES);
- list->list[i].size = getpagesize() * NUM_PAGES;
+ list->list[i].size = page_size * NUM_PAGES;
}
list->count = NUM_ENTRIES;
@@ -115,8 +115,8 @@ static int compare_chunks(void *addr1, void *addr2, off64_t memfd_size)
while (i < NUM_ENTRIES) {
off = i * (memfd_size / NUM_ENTRIES);
for (j = 0; j < NUM_PAGES; j++, k++) {
- char1 = *((char *)addr1 + off + (j * getpagesize()));
- char2 = *((char *)addr2 + (k * getpagesize()));
+ char1 = *((char *)addr1 + off + (j * page_size));
+ char2 = *((char *)addr2 + (k * page_size));
if (char1 != char2) {
ret = -1;
goto err;
@@ -126,7 +126,7 @@ static int compare_chunks(void *addr1, void *addr2, off64_t memfd_size)
}
err:
munmap(addr1, memfd_size);
- munmap(addr2, NUM_ENTRIES * NUM_PAGES * getpagesize());
+ munmap(addr2, NUM_ENTRIES * NUM_PAGES * page_size);
return ret;
}
@@ -240,7 +240,7 @@ int main(int argc, char *argv[])
addr1 = mmap_fd(memfd, size);
write_to_memfd(addr1, size, 'a');
buf = create_udmabuf_list(devfd, memfd, size);
- addr2 = mmap_fd(buf, NUM_PAGES * NUM_ENTRIES * getpagesize());
+ addr2 = mmap_fd(buf, NUM_PAGES * NUM_ENTRIES * page_size);
write_to_memfd(addr1, size, 'b');
ret = compare_chunks(addr1, addr2, size);
if (ret < 0)
@@ -256,7 +256,7 @@ int main(int argc, char *argv[])
size = MEMFD_SIZE * page_size;
memfd = create_memfd_with_seals(size, true);
buf = create_udmabuf_list(devfd, memfd, size);
- addr2 = mmap_fd(buf, NUM_PAGES * NUM_ENTRIES * getpagesize());
+ addr2 = mmap_fd(buf, NUM_PAGES * NUM_ENTRIES * page_size);
addr1 = mmap_fd(memfd, size);
write_to_memfd(addr1, size, 'a');
write_to_memfd(addr1, size, 'b');
--
2.52.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v1] selftests: udmabuf: fix hugepage size calculation
2026-01-18 13:51 [PATCH v1] selftests: udmabuf: fix hugepage size calculation zishun yi
@ 2026-01-18 20:38 ` Andrew Morton
2026-01-22 6:47 ` Kasireddy, Vivek
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2026-01-18 20:38 UTC (permalink / raw)
To: zishun yi
Cc: shuah, vivek.kasireddy, linux-kselftest, linux-kernel,
richard.weiyang, reddybalavignesh9979
On Sun, 18 Jan 2026 21:51:26 +0800 zishun yi <zishun.yi.dev@gmail.com> wrote:
> udmabuf's test 6 and 7 is intended to verify the behavior of 2MB huge pages migration,
> but the helper function still calculates the size using standard (4KB) pages.
>
lgtm. Vivek, can you please check it? Feel free to merge into another
tree and I'll drop the mm.git ccopy.
> --- a/tools/testing/selftests/drivers/dma-buf/udmabuf.c
> +++ b/tools/testing/selftests/drivers/dma-buf/udmabuf.c
> @@ -69,7 +69,7 @@ static int create_udmabuf_list(int devfd, int memfd, off64_t memfd_size)
> for (i = 0; i < NUM_ENTRIES; i++) {
> list->list[i].memfd = memfd;
> list->list[i].offset = i * (memfd_size / NUM_ENTRIES);
> - list->list[i].size = getpagesize() * NUM_PAGES;
> + list->list[i].size = page_size * NUM_PAGES;
> }
>
> list->count = NUM_ENTRIES;
> @@ -115,8 +115,8 @@ static int compare_chunks(void *addr1, void *addr2, off64_t memfd_size)
> while (i < NUM_ENTRIES) {
> off = i * (memfd_size / NUM_ENTRIES);
> for (j = 0; j < NUM_PAGES; j++, k++) {
> - char1 = *((char *)addr1 + off + (j * getpagesize()));
> - char2 = *((char *)addr2 + (k * getpagesize()));
> + char1 = *((char *)addr1 + off + (j * page_size));
> + char2 = *((char *)addr2 + (k * page_size));
> if (char1 != char2) {
> ret = -1;
> goto err;
> @@ -126,7 +126,7 @@ static int compare_chunks(void *addr1, void *addr2, off64_t memfd_size)
> }
> err:
> munmap(addr1, memfd_size);
> - munmap(addr2, NUM_ENTRIES * NUM_PAGES * getpagesize());
> + munmap(addr2, NUM_ENTRIES * NUM_PAGES * page_size);
> return ret;
> }
>
> @@ -240,7 +240,7 @@ int main(int argc, char *argv[])
> addr1 = mmap_fd(memfd, size);
> write_to_memfd(addr1, size, 'a');
> buf = create_udmabuf_list(devfd, memfd, size);
> - addr2 = mmap_fd(buf, NUM_PAGES * NUM_ENTRIES * getpagesize());
> + addr2 = mmap_fd(buf, NUM_PAGES * NUM_ENTRIES * page_size);
> write_to_memfd(addr1, size, 'b');
> ret = compare_chunks(addr1, addr2, size);
> if (ret < 0)
> @@ -256,7 +256,7 @@ int main(int argc, char *argv[])
> size = MEMFD_SIZE * page_size;
> memfd = create_memfd_with_seals(size, true);
> buf = create_udmabuf_list(devfd, memfd, size);
> - addr2 = mmap_fd(buf, NUM_PAGES * NUM_ENTRIES * getpagesize());
> + addr2 = mmap_fd(buf, NUM_PAGES * NUM_ENTRIES * page_size);
> addr1 = mmap_fd(memfd, size);
> write_to_memfd(addr1, size, 'a');
> write_to_memfd(addr1, size, 'b');
> --
> 2.52.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH v1] selftests: udmabuf: fix hugepage size calculation
2026-01-18 20:38 ` Andrew Morton
@ 2026-01-22 6:47 ` Kasireddy, Vivek
2026-01-22 21:45 ` Andrew Morton
2026-01-23 0:21 ` zishun yi
0 siblings, 2 replies; 5+ messages in thread
From: Kasireddy, Vivek @ 2026-01-22 6:47 UTC (permalink / raw)
To: Andrew Morton, zishun yi
Cc: shuah@kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org, richard.weiyang@gmail.com,
reddybalavignesh9979@gmail.com
Hi Andrew, Zishun Yi,
> Subject: Re: [PATCH v1] selftests: udmabuf: fix hugepage size calculation
>
> On Sun, 18 Jan 2026 21:51:26 +0800 zishun yi <zishun.yi.dev@gmail.com>
> wrote:
>
> > udmabuf's test 6 and 7 is intended to verify the behavior of 2MB huge
> pages migration,
> > but the helper function still calculates the size using standard (4KB)
> pages.
This behavior is intentional given that a udmabuf is often created for memfd
ranges that do not coincide with huge page (size) boundaries. In other words,
udmabuf is not always populated with full huge pages. Instead, the ranges
mostly align with regular 4K sized page boundaries (which means subpages of
huge page), which is exactly what the tests verify.
> >
>
> lgtm. Vivek, can you please check it? Feel free to merge into another
> tree and I'll drop the mm.git ccopy.
I think you can go ahead and drop it as this patch is not fixing a bug but is
modifying the tests' behavior to create the udmabuf with huge page sized
chunks which, although not wrong, but is not the intended objective for the
given tests.
Thanks,
Vivek
>
> > --- a/tools/testing/selftests/drivers/dma-buf/udmabuf.c
> > +++ b/tools/testing/selftests/drivers/dma-buf/udmabuf.c
> > @@ -69,7 +69,7 @@ static int create_udmabuf_list(int devfd, int
> memfd, off64_t memfd_size)
> > for (i = 0; i < NUM_ENTRIES; i++) {
> > list->list[i].memfd = memfd;
> > list->list[i].offset = i * (memfd_size / NUM_ENTRIES);
> > - list->list[i].size = getpagesize() * NUM_PAGES;
> > + list->list[i].size = page_size * NUM_PAGES;
> > }
> >
> > list->count = NUM_ENTRIES;
> > @@ -115,8 +115,8 @@ static int compare_chunks(void *addr1, void
> *addr2, off64_t memfd_size)
> > while (i < NUM_ENTRIES) {
> > off = i * (memfd_size / NUM_ENTRIES);
> > for (j = 0; j < NUM_PAGES; j++, k++) {
> > - char1 = *((char *)addr1 + off + (j * getpagesize()));
> > - char2 = *((char *)addr2 + (k * getpagesize()));
> > + char1 = *((char *)addr1 + off + (j * page_size));
> > + char2 = *((char *)addr2 + (k * page_size));
> > if (char1 != char2) {
> > ret = -1;
> > goto err;
> > @@ -126,7 +126,7 @@ static int compare_chunks(void *addr1, void
> *addr2, off64_t memfd_size)
> > }
> > err:
> > munmap(addr1, memfd_size);
> > - munmap(addr2, NUM_ENTRIES * NUM_PAGES * getpagesize());
> > + munmap(addr2, NUM_ENTRIES * NUM_PAGES * page_size);
> > return ret;
> > }
> >
> > @@ -240,7 +240,7 @@ int main(int argc, char *argv[])
> > addr1 = mmap_fd(memfd, size);
> > write_to_memfd(addr1, size, 'a');
> > buf = create_udmabuf_list(devfd, memfd, size);
> > - addr2 = mmap_fd(buf, NUM_PAGES * NUM_ENTRIES *
> getpagesize());
> > + addr2 = mmap_fd(buf, NUM_PAGES * NUM_ENTRIES * page_size);
> > write_to_memfd(addr1, size, 'b');
> > ret = compare_chunks(addr1, addr2, size);
> > if (ret < 0)
> > @@ -256,7 +256,7 @@ int main(int argc, char *argv[])
> > size = MEMFD_SIZE * page_size;
> > memfd = create_memfd_with_seals(size, true);
> > buf = create_udmabuf_list(devfd, memfd, size);
> > - addr2 = mmap_fd(buf, NUM_PAGES * NUM_ENTRIES *
> getpagesize());
> > + addr2 = mmap_fd(buf, NUM_PAGES * NUM_ENTRIES * page_size);
> > addr1 = mmap_fd(memfd, size);
> > write_to_memfd(addr1, size, 'a');
> > write_to_memfd(addr1, size, 'b');
> > --
> > 2.52.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] selftests: udmabuf: fix hugepage size calculation
2026-01-22 6:47 ` Kasireddy, Vivek
@ 2026-01-22 21:45 ` Andrew Morton
2026-01-23 0:21 ` zishun yi
1 sibling, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2026-01-22 21:45 UTC (permalink / raw)
To: Kasireddy, Vivek
Cc: zishun yi, shuah@kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org, richard.weiyang@gmail.com,
reddybalavignesh9979@gmail.com
On Thu, 22 Jan 2026 06:47:54 +0000 "Kasireddy, Vivek" <vivek.kasireddy@intel.com> wrote:
> > >
> >
> > lgtm. Vivek, can you please check it? Feel free to merge into another
> > tree and I'll drop the mm.git ccopy.
> I think you can go ahead and drop it as this patch is not fixing a bug but is
> modifying the tests' behavior to create the udmabuf with huge page sized
> chunks which, although not wrong, but is not the intended objective for the
> given tests.
Great, thanks, I've removed this patch from mm.git.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] selftests: udmabuf: fix hugepage size calculation
2026-01-22 6:47 ` Kasireddy, Vivek
2026-01-22 21:45 ` Andrew Morton
@ 2026-01-23 0:21 ` zishun yi
1 sibling, 0 replies; 5+ messages in thread
From: zishun yi @ 2026-01-23 0:21 UTC (permalink / raw)
To: Kasireddy, Vivek
Cc: Andrew Morton, shuah@kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org, richard.weiyang@gmail.com,
reddybalavignesh9979@gmail.com
On Thu, Jan 22, 2026 at 06:47:54AM +0000, Kasireddy, Vivek wrote:
> This behavior is intentional given that a udmabuf is often created for memfd
> ranges that do not coincide with huge page (size) boundaries. In other words,
> udmabuf is not always populated with full huge pages. Instead, the ranges
> mostly align with regular 4K sized page boundaries (which means subpages of
> huge page), which is exactly what the tests verify.
Thanks for the clarification.
I agree with dropping this patch. Thanks for your review.
Best regards, Zishun
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-01-23 0:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-18 13:51 [PATCH v1] selftests: udmabuf: fix hugepage size calculation zishun yi
2026-01-18 20:38 ` Andrew Morton
2026-01-22 6:47 ` Kasireddy, Vivek
2026-01-22 21:45 ` Andrew Morton
2026-01-23 0:21 ` zishun yi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox