Skip to contentSkip to conversation

xfs: kmalloc/kfree conversion fixes

PATCH In review Dave Chinner 4 participants 12 messages Feb 27, 2024 – Feb 28, 2024 XFS filesystem

lore
Share & tools
lore
#0 lore raw

cover xfs: kmalloc/kfree conversion fixes

Hi Chandan,

These two patches are fixes for the two recently reported issues with the kmem removal patchset. They've passes fstests and fsmark scalability tests with 64kB directory block size, should should have been exercising >64kB allocations through xlog_kvmalloc(). These should (eventuallly) trigger the vmalloc() path and so should exercise the vfree path through kvfree() instead of crashing...

-Dave.

#1 lore raw

PATCH 1/2 xfs: xfs_btree_bload_prep_block() should use __GFP_NOFAIL

From: Dave Chinner <[email protected]>

This was missed in the conversion from KM* flags.

Fixes 10634530f7ba ("xfs: convert kmem_zalloc() to kzalloc()")
---
 fs/xfs/libxfs/xfs_btree_staging.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/libxfs/xfs_btree_staging.c +1 -1
index f0c69f9bb169..e6ec01f25d90 100644
@@ -406,7 +406,7 @@ xfs_btree_bload_prep_block(
 
 		/* Allocate a new incore btree root block. */
 		new_size = bbl->iroot_size(cur, level, nr_this_block, priv);
-		ifp->if_broot = kzalloc(new_size, GFP_KERNEL);
+		ifp->if_broot = kzalloc(new_size, GFP_KERNEL | __GFP_NOFAIL);
 		ifp->if_broot_bytes = (int)new_size;
 
 		/* Initialize it and send it out. */
Signature · 1 line
2.43.0
#4 lore raw

PATCH 2/2 xfs: use kvfree() in xlog_cil_free_logvec()

In reply to Dave Chinner

From: Dave Chinner <[email protected]>

The xfs_log_vec items are allocated by xlog_kvmalloc(), and so need to be freed with kvfree. This was missed when coverting from the kmem_free() API.

Fixes 49292576136f ("xfs: convert kmem_free() for kvmalloc users to kvfree()")
---
 fs/xfs/xfs_log_cil.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_log_cil.c +1 -1
index f15735d0296a..9544ddaef066 100644
@@ -877,7 +877,7 @@ xlog_cil_free_logvec(
 	while (!list_empty(lv_chain)) {
 		lv = list_first_entry(lv_chain, struct xfs_log_vec, lv_list);
 		list_del_init(&lv->lv_list);
-		kfree(lv);
+		kvfree(lv);
 	}
 }
 
Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH 2/2] xfs: use kvfree() in xlog_cil_free_logvec()

Quoted 18 lines · Dave Chinner

From: Dave Chinner <[email protected]>

The xfs_log_vec items are allocated by xlog_kvmalloc(), and so need to be freed with kvfree. This was missed when coverting from the kmem_free() API.

Fixes 49292576136f ("xfs: convert kmem_free() for kvmalloc users to kvfree()")
---
 fs/xfs/xfs_log_cil.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_log_cil.c +0 -0
index f15735d0296a..9544ddaef066 100644

fs/xfs/xfs_log_cil.c xlog_cil_free_logvec( · line 880

Quoted 5 lines
fs/xfs/xfs_log_cil.c +1 -1
@@ -877,7 +877,7 @@ xlog_cil_free_logvec(
 	while (!list_empty(lv_chain)) {
 		lv = list_first_entry(lv_chain, struct xfs_log_vec, lv_list);
 		list_del_init(&lv->lv_list);
-		kfree(lv);
+		kvfree(lv);

Is it necessary to s/kfree/kvfree/ in xlog_cil_process_intents when we free the xfs_log_vec that's attached to a xfs_log_item?

--D

Quoted 7 lines
fs/xfs/xfs_log_cil.c +0 -0
 	}
 }
 
Signature · 1 line
2.43.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] xfs: xfs_btree_bload_prep_block() should use __GFP_NOFAIL

In reply to Dave Chinner
Quoted 7 lines · Dave Chinner

From: Dave Chinner <[email protected]>

This was missed in the conversion from KM* flags.

Fixes 10634530f7ba ("xfs: convert kmem_zalloc() to kzalloc()")

Looks correct to me,

--D

Quoted 21 lines
---
 fs/xfs/libxfs/xfs_btree_staging.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/libxfs/xfs_btree_staging.c +1 -1
index f0c69f9bb169..e6ec01f25d90 100644
@@ -406,7 +406,7 @@ xfs_btree_bload_prep_block(
 
 		/* Allocate a new incore btree root block. */
 		new_size = bbl->iroot_size(cur, level, nr_this_block, priv);
-		ifp->if_broot = kzalloc(new_size, GFP_KERNEL);
+		ifp->if_broot = kzalloc(new_size, GFP_KERNEL | __GFP_NOFAIL);
 		ifp->if_broot_bytes = (int)new_size;
 
 		/* Initialize it and send it out. */
Signature · 1 line
2.43.0
#6 lore raw

Re: [PATCH 2/2] xfs: use kvfree() in xlog_cil_free_logvec()

In reply to Darrick J. Wong
Quoted 14 lines · Darrick J. Wong
Quoted 13 lines · Dave Chinner

From: Dave Chinner <[email protected]>

The xfs_log_vec items are allocated by xlog_kvmalloc(), and so need to be freed with kvfree. This was missed when coverting from the kmem_free() API.

Fixes 49292576136f ("xfs: convert kmem_free() for kvmalloc users to kvfree()")
---
 fs/xfs/xfs_log_cil.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

fs/xfs/xfs_log_cil.c xlog_cil_free_logvec( · line 880

Quoted 10 lines
fs/xfs/xfs_log_cil.c +1 -1
index f15735d0296a..9544ddaef066 100644
@@ -877,7 +877,7 @@ xlog_cil_free_logvec(
 	while (!list_empty(lv_chain)) {
 		lv = list_first_entry(lv_chain, struct xfs_log_vec, lv_list);
 		list_del_init(&lv->lv_list);
-		kfree(lv);
+		kvfree(lv);

Is it necessary to s/kfree/kvfree/ in xlog_cil_process_intents when we free the xfs_log_vec that's attached to a xfs_log_item?

Yes, it should, even though intents are pretty much guaranteed to be small enough they will never use vmalloc.

Good catch.

-Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#7 lore raw

PATCH v2 2/2 xfs: use kvfree() in xlog_cil_free_logvec()

In reply to Darrick J. Wong

From: Dave Chinner <[email protected]>

The xfs_log_vec items are allocated by xlog_kvmalloc(), and so need to be freed with kvfree. This was missed when coverting from the kmem_free() API.

Fixes 49292576136f ("xfs: convert kmem_free() for kvmalloc users to kvfree()")

---

Version 2:
- also fix kfree() in xlog_cil_process_intents().
- checked that kvfree() is used for all lip->li_lv_shadow freeing calls.

 fs/xfs/xfs_log_cil.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/xfs/xfs_log_cil.c +2 -2
index f15735d0296a..4d52854bcb29 100644
@@ -877,7 +877,7 @@ xlog_cil_free_logvec(
 	while (!list_empty(lv_chain)) {
 		lv = list_first_entry(lv_chain, struct xfs_log_vec, lv_list);
 		list_del_init(&lv->lv_list);
-		kfree(lv);
+		kvfree(lv);
 	}
 }
 
@@ -1717,7 +1717,7 @@ xlog_cil_process_intents(
 		set_bit(XFS_LI_WHITEOUT, &ilip->li_flags);
 		trace_xfs_cil_whiteout_mark(ilip);
 		len += ilip->li_lv->lv_bytes;
-		kfree(ilip->li_lv);
+		kvfree(ilip->li_lv);
 		ilip->li_lv = NULL;
 
 		xfs_trans_del_item(lip);
Reviewed-by on v2 2/2
#8 lore raw

Re: [PATCH v2 2/2] xfs: use kvfree() in xlog_cil_free_logvec()

Quoted 9 lines · Dave Chinner

From: Dave Chinner <[email protected]>

The xfs_log_vec items are allocated by xlog_kvmalloc(), and so need to be freed with kvfree. This was missed when coverting from the kmem_free() API.

Fixes 49292576136f ("xfs: convert kmem_free() for kvmalloc users to kvfree()")

Looks good to me, will run this one through fstestsclod overnight...

--D

Quoted 33 lines

---

Version 2:
- also fix kfree() in xlog_cil_process_intents().
- checked that kvfree() is used for all lip->li_lv_shadow freeing calls.

 fs/xfs/xfs_log_cil.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/xfs/xfs_log_cil.c +2 -2
index f15735d0296a..4d52854bcb29 100644
@@ -877,7 +877,7 @@ xlog_cil_free_logvec(
 	while (!list_empty(lv_chain)) {
 		lv = list_first_entry(lv_chain, struct xfs_log_vec, lv_list);
 		list_del_init(&lv->lv_list);
-		kfree(lv);
+		kvfree(lv);
 	}
 }
 
@@ -1717,7 +1717,7 @@ xlog_cil_process_intents(
 		set_bit(XFS_LI_WHITEOUT, &ilip->li_flags);
 		trace_xfs_cil_whiteout_mark(ilip);
 		len += ilip->li_lv->lv_bytes;
-		kfree(ilip->li_lv);
+		kvfree(ilip->li_lv);
 		ilip->li_lv = NULL;
 
 		xfs_trans_del_item(lip);
#10 lore raw

Re: [PATCH v2 2/2] xfs: use kvfree() in xlog_cil_free_logvec()

In reply to Dave Chinner
Quoted 7 lines · Dave Chinner

From: Dave Chinner <[email protected]>

The xfs_log_vec items are allocated by xlog_kvmalloc(), and so need to be freed with kvfree. This was missed when coverting from the kmem_free() API.

I have changed the Reported-by tag value to Darrick (since he reported it first) when applying the patches to my local Git tree.

Signature · 1 line
Chandan
Tested-by
#9 lore raw

Re: [PATCH v2 2/2] xfs: use kvfree() in xlog_cil_free_logvec()

In reply to Darrick J. Wong
Quoted 7 lines · Darrick J. Wong
Quoted 6 lines · Dave Chinner

From: Dave Chinner <[email protected]>

The xfs_log_vec items are allocated by xlog_kvmalloc(), and so need to be freed with kvfree. This was missed when coverting from the kmem_free() API.

Quoted 6 lines
Quoted 3 lines
Fixes 49292576136f ("xfs: convert kmem_free() for kvmalloc users to kvfree()")

Looks good to me, will run this one through fstestsclod overnight...

FWIW I didn't see any further crashes after applying this patch, so:

--D

Quoted 36 lines

--D

Quoted 33 lines

---

Version 2:
- also fix kfree() in xlog_cil_process_intents().
- checked that kvfree() is used for all lip->li_lv_shadow freeing calls.

 fs/xfs/xfs_log_cil.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/xfs/xfs_log_cil.c +2 -2
index f15735d0296a..4d52854bcb29 100644
@@ -877,7 +877,7 @@ xlog_cil_free_logvec(
 	while (!list_empty(lv_chain)) {
 		lv = list_first_entry(lv_chain, struct xfs_log_vec, lv_list);
 		list_del_init(&lv->lv_list);
-		kfree(lv);
+		kvfree(lv);
 	}
 }
 
@@ -1717,7 +1717,7 @@ xlog_cil_process_intents(
 		set_bit(XFS_LI_WHITEOUT, &ilip->li_flags);
 		trace_xfs_cil_whiteout_mark(ilip);
 		len += ilip->li_lv->lv_bytes;
-		kfree(ilip->li_lv);
+		kvfree(ilip->li_lv);
 		ilip->li_lv = NULL;
 
 		xfs_trans_del_item(lip);