[PATCH v2] mm/gup_test: report actual pinned bytes

Sarthak Sharma posted 1 patch 3 weeks, 5 days ago
mm/gup_test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH v2] mm/gup_test: report actual pinned bytes
Posted by Sarthak Sharma 3 weeks, 5 days ago
__gup_test_ioctl() advances addr to the end of the current batch before
checking if GUP pinned the entire requested batch. If GUP pins more than
0 pages but less than the requested batch size, addr still advances by
the requested batch size.

The next iteration detects the partial pinning and breaks out of the loop.
Again gup->size is calculated using addr - gup->addr, so it also includes
the unpinned pages of the requested batch.

Calculate gup->size using the actual number of pages pinned multiplied
by PAGE_SIZE.

Fixes: 64c349f4ae78 ("mm: add infrastructure for get_user_pages_fast() benchmarking")
Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
Signed-off-by: Sarthak Sharma <sarthak.sharma@arm.com>
---
Changes in v2:
- Fix typo in the commit message

v1: lore.kernel.org/all/20260831064808.77768-1-sarthak.sharma@arm.com/

 mm/gup_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/gup_test.c b/mm/gup_test.c
index 44c1cdfb9c37..185ba3bb8ed1 100644
--- a/mm/gup_test.c
+++ b/mm/gup_test.c
@@ -188,7 +188,7 @@ static int __gup_test_ioctl(unsigned int cmd,
 	nr_pages = i;
 
 	gup->get_delta_usec = ktime_us_delta(end_time, start_time);
-	gup->size = addr - gup->addr;
+	gup->size = nr_pages * PAGE_SIZE;
 
 	/*
 	 * Take an un-benchmark-timed moment to verify DMA pinned
-- 
2.53.0
Re: [PATCH v2] mm/gup_test: report actual pinned bytes
Posted by David Hildenbrand (Arm) 2 weeks, 5 days ago
On 8/31/26 12:13, Sarthak Sharma wrote:
> __gup_test_ioctl() advances addr to the end of the current batch before
> checking if GUP pinned the entire requested batch. If GUP pins more than
> 0 pages but less than the requested batch size, addr still advances by
> the requested batch size.
> 
> The next iteration detects the partial pinning and breaks out of the loop.
> Again gup->size is calculated using addr - gup->addr, so it also includes
> the unpinned pages of the requested batch.
> 
> Calculate gup->size using the actual number of pages pinned multiplied
> by PAGE_SIZE.
> 
> Fixes: 64c349f4ae78 ("mm: add infrastructure for get_user_pages_fast() benchmarking")
> Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
> Signed-off-by: Sarthak Sharma <sarthak.sharma@arm.com>
> ---
> Changes in v2:
> - Fix typo in the commit message
> 
> v1: lore.kernel.org/all/20260831064808.77768-1-sarthak.sharma@arm.com/
> 
>  mm/gup_test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/gup_test.c b/mm/gup_test.c
> index 44c1cdfb9c37..185ba3bb8ed1 100644
> --- a/mm/gup_test.c
> +++ b/mm/gup_test.c
> @@ -188,7 +188,7 @@ static int __gup_test_ioctl(unsigned int cmd,
>  	nr_pages = i;
>  
>  	gup->get_delta_usec = ktime_us_delta(end_time, start_time);
> -	gup->size = addr - gup->addr;
> +	gup->size = nr_pages * PAGE_SIZE;
>  
>  	/*
>  	 * Take an un-benchmark-timed moment to verify DMA pinned

Acked-by: David Hildenbrand (Arm) <david@kernel.org>


I assume that loop handling could get cleaned up a bit.

-- 
Cheers,

David
Re: [PATCH v2] mm/gup_test: report actual pinned bytes
Posted by Andrew Morton 3 weeks, 4 days ago
On Mon, 31 Aug 2026 15:43:04 +0530 Sarthak Sharma <sarthak.sharma@arm.com> wrote:

> __gup_test_ioctl() advances addr to the end of the current batch before
> checking if GUP pinned the entire requested batch. If GUP pins more than
> 0 pages but less than the requested batch size, addr still advances by
> the requested batch size.
> 
> The next iteration detects the partial pinning and breaks out of the loop.
> Again gup->size is calculated using addr - gup->addr, so it also includes
> the unpinned pages of the requested batch.
> 
> Calculate gup->size using the actual number of pages pinned multiplied
> by PAGE_SIZE.

Thanks.  Sashiko might have found a somewhat-related overflow on
32-bit.  Maybe fix that while we're in there?

	https://sashiko.dev/#/patchset/20260831101304.162867-1-sarthak.sharma@arm.com