[PATCH] mm/memfd_luo: use real folio index in retrieve error logs

Giorgi Tchankvetadze posted 1 patch 1 month, 3 weeks ago
mm/memfd_luo.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
[PATCH] mm/memfd_luo: use real folio index in retrieve error logs
Posted by Giorgi Tchankvetadze 1 month, 3 weeks ago
From: Giorgi Tchankvetadze <giorgi@tchankvetadze.com>

memfd_luo_retrieve_folios() logs "folio index %ld" on its error paths
but passes the loop counter 'i' instead of the folio's actual index
held in the local 'index' variable (pfolio->index).

Pass 'index' to the three pr_err() calls so the logged index matches
the folio that actually failed. Since the saved index is a u64, use %llu with an
unsigned long long cast when printing it.

Fixes: b3749f174d68 ("mm: memfd_luo: allow preserving memfd")
Signed-off-by: Giorgi Tchankvetadze <giorgi@tchankvetadze.com>
---
 mm/memfd_luo.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c
index 59de210bee5f..652dd21e6ef0 100644
--- a/mm/memfd_luo.c
+++ b/mm/memfd_luo.c
@@ -451,16 +451,16 @@ static int memfd_luo_retrieve_folios(struct file *file,
 
 		err = mem_cgroup_charge(folio, NULL, mapping_gfp_mask(mapping));
 		if (err) {
-			pr_err("shmem: failed to charge folio index %ld: %d\n",
-			       i, err);
+			pr_err("shmem: failed to charge folio index %llu: %d\n",
+			       (unsigned long long)index, err);
 			goto unlock_folio;
 		}
 
 		err = shmem_add_to_page_cache(folio, mapping, index, NULL,
 					      mapping_gfp_mask(mapping));
 		if (err) {
-			pr_err("shmem: failed to add to page cache folio index %ld: %d\n",
-			       i, err);
+			pr_err("shmem: failed to add to page cache folio index %llu: %d\n",
+			       (unsigned long long)index, err);
 			goto unlock_folio;
 		}
 
@@ -472,8 +472,8 @@ static int memfd_luo_retrieve_folios(struct file *file,
 		npages = folio_nr_pages(folio);
 		err = shmem_inode_acct_blocks(inode, npages);
 		if (err) {
-			pr_err("shmem: failed to account folio index %ld(%ld pages): %d\n",
-			       i, npages, err);
+			pr_err("shmem: failed to account folio index %llu(%ld pages): %d\n",
+			       (unsigned long long)index, npages, err);
 			goto remove_from_cache;
 		}
 
-- 
2.52.0
Re: [PATCH] mm/memfd_luo: use real folio index in retrieve error logs
Posted by Pratyush Yadav 1 month, 3 weeks ago
On Thu, Aug 06 2026, Giorgi Tchankvetadze wrote:

> From: Giorgi Tchankvetadze <giorgi@tchankvetadze.com>
>
> memfd_luo_retrieve_folios() logs "folio index %ld" on its error paths
> but passes the loop counter 'i' instead of the folio's actual index
> held in the local 'index' variable (pfolio->index).
>
> Pass 'index' to the three pr_err() calls so the logged index matches
> the folio that actually failed. Since the saved index is a u64, use %llu with an
> unsigned long long cast when printing it.
>
> Fixes: b3749f174d68 ("mm: memfd_luo: allow preserving memfd")
> Signed-off-by: Giorgi Tchankvetadze <giorgi@tchankvetadze.com>
> ---
>  mm/memfd_luo.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c
> index 59de210bee5f..652dd21e6ef0 100644
> --- a/mm/memfd_luo.c
> +++ b/mm/memfd_luo.c
> @@ -451,16 +451,16 @@ static int memfd_luo_retrieve_folios(struct file *file,
>  
>  		err = mem_cgroup_charge(folio, NULL, mapping_gfp_mask(mapping));
>  		if (err) {
> -			pr_err("shmem: failed to charge folio index %ld: %d\n",
> -			       i, err);
> +			pr_err("shmem: failed to charge folio index %llu: %d\n",
> +			       (unsigned long long)index, err);

Why the cast here? u64 is always printed by %llu. See
Documentation/core-api/printk-formats.rst.

>  			goto unlock_folio;
>  		}
>  
>  		err = shmem_add_to_page_cache(folio, mapping, index, NULL,
>  					      mapping_gfp_mask(mapping));
>  		if (err) {
> -			pr_err("shmem: failed to add to page cache folio index %ld: %d\n",
> -			       i, err);
> +			pr_err("shmem: failed to add to page cache folio index %llu: %d\n",
> +			       (unsigned long long)index, err);
>  			goto unlock_folio;
>  		}
>  
> @@ -472,8 +472,8 @@ static int memfd_luo_retrieve_folios(struct file *file,
>  		npages = folio_nr_pages(folio);
>  		err = shmem_inode_acct_blocks(inode, npages);
>  		if (err) {
> -			pr_err("shmem: failed to account folio index %ld(%ld pages): %d\n",
> -			       i, npages, err);
> +			pr_err("shmem: failed to account folio index %llu(%ld pages): %d\n",
> +			       (unsigned long long)index, npages, err);
>  			goto remove_from_cache;
>  		}

-- 
Regards,
Pratyush Yadav
Re: [PATCH] mm/memfd_luo: use real folio index in retrieve error logs
Posted by Giorgi Tchankvetadze 1 month, 3 weeks ago
On Mon, Aug 10, 2026 at 9:56 PM Pratyush Yadav <pratyush@kernel.org> wrote:
>
>
> Why the cast here? u64 is always printed by %llu. See
> Documentation/core-api/printk-formats.rst.
>

Wow, the cast really is unnecessary. Thanks, I'll drop it.