[PATCH v3 1/6] binder: Fix selftest page indexing

Tiffany Yang posted 6 patches 2 months, 3 weeks ago
There is a newer version of this series
[PATCH v3 1/6] binder: Fix selftest page indexing
Posted by Tiffany Yang 2 months, 3 weeks ago
The binder allocator selftest was only checking the last page of buffers
that ended on a page boundary. Correct the page indexing to account for
buffers that are not page-aligned.

Signed-off-by: Tiffany Yang <ynaffit@google.com>
---
 drivers/android/binder_alloc_selftest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/android/binder_alloc_selftest.c b/drivers/android/binder_alloc_selftest.c
index c88735c54848..486af3ec3c02 100644
--- a/drivers/android/binder_alloc_selftest.c
+++ b/drivers/android/binder_alloc_selftest.c
@@ -142,12 +142,12 @@ static void binder_selftest_free_buf(struct binder_alloc *alloc,
 	for (i = 0; i < BUFFER_NUM; i++)
 		binder_alloc_free_buf(alloc, buffers[seq[i]]);
 
-	for (i = 0; i < end / PAGE_SIZE; i++) {
 		/**
 		 * Error message on a free page can be false positive
 		 * if binder shrinker ran during binder_alloc_free_buf
 		 * calls above.
 		 */
+	for (i = 0; i <= (end - 1) / PAGE_SIZE; i++) {
 		if (list_empty(page_to_lru(alloc->pages[i]))) {
 			pr_err_size_seq(sizes, seq);
 			pr_err("expect lru but is %s at page index %d\n",
-- 
2.50.0.727.gbf7dc18ff4-goog
Re: [PATCH v3 1/6] binder: Fix selftest page indexing
Posted by Kees Cook 2 months, 3 weeks ago
On Mon, Jul 14, 2025 at 11:53:14AM -0700, Tiffany Yang wrote:
> The binder allocator selftest was only checking the last page of buffers
> that ended on a page boundary. Correct the page indexing to account for
> buffers that are not page-aligned.
> 
> Signed-off-by: Tiffany Yang <ynaffit@google.com>
> ---
>  drivers/android/binder_alloc_selftest.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/android/binder_alloc_selftest.c b/drivers/android/binder_alloc_selftest.c
> index c88735c54848..486af3ec3c02 100644
> --- a/drivers/android/binder_alloc_selftest.c
> +++ b/drivers/android/binder_alloc_selftest.c
> @@ -142,12 +142,12 @@ static void binder_selftest_free_buf(struct binder_alloc *alloc,
>  	for (i = 0; i < BUFFER_NUM; i++)
>  		binder_alloc_free_buf(alloc, buffers[seq[i]]);
>  
> -	for (i = 0; i < end / PAGE_SIZE; i++) {
>  		/**
>  		 * Error message on a free page can be false positive
>  		 * if binder shrinker ran during binder_alloc_free_buf
>  		 * calls above.
>  		 */
> +	for (i = 0; i <= (end - 1) / PAGE_SIZE; i++) {

Nit: this comment is now not aligned correctly. Probably the best would
be the leave the "for" line above the comment.

-Kees

>  		if (list_empty(page_to_lru(alloc->pages[i]))) {
>  			pr_err_size_seq(sizes, seq);
>  			pr_err("expect lru but is %s at page index %d\n",
> -- 
> 2.50.0.727.gbf7dc18ff4-goog
> 

-- 
Kees Cook
Re: [PATCH v3 1/6] binder: Fix selftest page indexing
Posted by Tiffany Yang 2 months, 3 weeks ago
Kees Cook <kees@kernel.org> writes:

> On Mon, Jul 14, 2025 at 11:53:14AM -0700, Tiffany Yang wrote:
>> The binder allocator selftest was only checking the last page of buffers
>> that ended on a page boundary. Correct the page indexing to account for
>> buffers that are not page-aligned.

>> Signed-off-by: Tiffany Yang <ynaffit@google.com>
>> ---
>>   drivers/android/binder_alloc_selftest.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)

>> diff --git a/drivers/android/binder_alloc_selftest.c  
>> b/drivers/android/binder_alloc_selftest.c
>> index c88735c54848..486af3ec3c02 100644
>> --- a/drivers/android/binder_alloc_selftest.c
>> +++ b/drivers/android/binder_alloc_selftest.c
>> @@ -142,12 +142,12 @@ static void binder_selftest_free_buf(struct  
>> binder_alloc *alloc,
>>   	for (i = 0; i < BUFFER_NUM; i++)
>>   		binder_alloc_free_buf(alloc, buffers[seq[i]]);

>> -	for (i = 0; i < end / PAGE_SIZE; i++) {
>>   		/**
>>   		 * Error message on a free page can be false positive
>>   		 * if binder shrinker ran during binder_alloc_free_buf
>>   		 * calls above.
>>   		 */
>> +	for (i = 0; i <= (end - 1) / PAGE_SIZE; i++) {

> Nit: this comment is now not aligned correctly. Probably the best would
> be the leave the "for" line above the comment.

> -Kees


Thank you for catching this! Will be fixed in v4.

>>   		if (list_empty(page_to_lru(alloc->pages[i]))) {
>>   			pr_err_size_seq(sizes, seq);
>>   			pr_err("expect lru but is %s at page index %d\n",
>> --
>> 2.50.0.727.gbf7dc18ff4-goog


-- 
Tiffany Y. Yang
Re: [PATCH v3 1/6] binder: Fix selftest page indexing
Posted by Carlos Llamas 2 months, 3 weeks ago
On Mon, Jul 14, 2025 at 11:53:14AM -0700, Tiffany Yang wrote:
> The binder allocator selftest was only checking the last page of buffers
> that ended on a page boundary. Correct the page indexing to account for
> buffers that are not page-aligned.
>
> Signed-off-by: Tiffany Yang <ynaffit@google.com>
> ---
>  drivers/android/binder_alloc_selftest.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/android/binder_alloc_selftest.c b/drivers/android/binder_alloc_selftest.c
> index c88735c54848..486af3ec3c02 100644
> --- a/drivers/android/binder_alloc_selftest.c
> +++ b/drivers/android/binder_alloc_selftest.c
> @@ -142,12 +142,12 @@ static void binder_selftest_free_buf(struct binder_alloc *alloc,
>       for (i = 0; i < BUFFER_NUM; i++)
>               binder_alloc_free_buf(alloc, buffers[seq[i]]);
>
> -     for (i = 0; i < end / PAGE_SIZE; i++) {
>               /**
>                * Error message on a free page can be false positive
>                * if binder shrinker ran during binder_alloc_free_buf
>                * calls above.
>                */
> +     for (i = 0; i <= (end - 1) / PAGE_SIZE; i++) {
>               if (list_empty(page_to_lru(alloc->pages[i]))) {
>                       pr_err_size_seq(sizes, seq);
>                       pr_err("expect lru but is %s at page index %d\n",
> --
> 2.50.0.727.gbf7dc18ff4-goog
>

LGTM!

Acked-by: Carlos Llamas <cmllamas@google.com>