Skip to contentSkip to conversation

Clarify and cleanup some __GFP_NOFAIL usage

RFC PATCH In review Michal Hocko 4 participants 15 messages Mar 2, 2015 – Mar 3, 2015

Subsystems (10)
lore
Share & tools
lore
#0 lore raw

cover Clarify and cleanup some __GFP_NOFAIL usage

Hi,
from the last discussion about __GFP_NOFAIL it turned out that the flag cannot be deprecated as easily as MM people hoped for.
The current flag description leads people to inventing their own loops around GFP_{KERNEL|NOFS} allocations without any fallback failure policy. This makes the situation much worse for the MM layer because it is not aware of the hard no-fail requirements.

First patch in this series tries to rephrase the documentation to be more clear about our intention. __GFP_NOFAIL is generally discouraged but users shouldn't lie to the allocator if they really cannot have any failure strategy.

Second patch removes such an open coded retry loop in the jbd2 code which was introduced exactly because of the deprecation wording. I am not sure the patch is still required because Ted has mentioned something about changing this code. If he was faster then we can simply drop this one. I was hoping for more such opencoded paths but wasn't very successful. The next plan is to abuse coccinelle to find such patterns.

The last two patches are attempts to get rid of __GFP_NOFAIL when it seemed they are not needed because there are error paths handled properly. I am not familiar with that code so I might be clearly wrong here and I would appreciate double checking from the respective maintainer.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw

RFC 1/4 mm: Clarify __GFP_NOFAIL deprecation status

__GFP_NOFAIL is documented as a deprecated flag since 478352e789f5 (mm:
add comment about deprecation of __GFP_NOFAIL). This has discouraged people from using it but in some cases an opencoded endless loop around allocator has been used instead. So the allocator is not aware of the de facto __GFP_NOFAIL allocation because this information was not communicated properly.

Let's make clear that if the allocation context really cannot effort failure because there is no good failure policy then using __GFP_NOFAIL is preferable to opencoding the loop outside of the allocator.

---
 include/linux/gfp.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
include/linux/gfp.h +4 -2
index 51bd1e72a917..0cf9c2772988 100644
@@ -57,8 +57,10 @@ struct vm_area_struct;
  * _might_ fail.  This depends upon the particular VM implementation.
  *
  * __GFP_NOFAIL: The VM implementation _must_ retry infinitely: the caller
- * cannot handle allocation failures.  This modifier is deprecated and no new
- * users should be added.
+ * cannot handle allocation failures. New users should be evaluated carefuly
+ * (and the flag should be used only when there is no reasonable failure policy)
+ * but it is definitely preferable to use the flag rather than opencode endless
+ * loop around allocator.
  *
  * __GFP_NORETRY: The VM implementation must not retry indefinitely.
  *
Signature · 7 lines
2.1.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on v1 1/4
#2 lore raw

Re: [RFC 1/4] mm: Clarify __GFP_NOFAIL deprecation status

Quoted 7 lines · Michal Hocko
include/linux/gfp.h +0 -0
index 51bd1e72a917..0cf9c2772988 100644
@@ -57,8 +57,10 @@ struct vm_area_struct;
  * _might_ fail.  This depends upon the particular VM implementation.
  *

include/linux/gfp.h struct vm_area_struct; · line 66

Quoted 10 lines
include/linux/gfp.h +4 -2
  * __GFP_NOFAIL: The VM implementation _must_ retry infinitely: the caller
- * cannot handle allocation failures.  This modifier is deprecated and no new
- * users should be added.
+ * cannot handle allocation failures. New users should be evaluated carefuly
+ * (and the flag should be used only when there is no reasonable failure policy)
+ * but it is definitely preferable to use the flag rather than opencode endless
+ * loop around allocator.
  *
  * __GFP_NORETRY: The VM implementation must not retry indefinitely.
  *

s/carefuly/carefully/

#3 lore raw

RFC 2/4 jbd2: revert must-not-fail allocation loops back to GFP_NOFAIL

In reply to Michal Hocko

This basically reverts 47def82672b3 (jbd2: Remove __GFP_NOFAIL from jbd2 layer). The deprecation of __GFP_NOFAIL was a bad choice because it led to open coding the endless loop around the allocator rather than removing the dependency on the non failing allocation. So the deprecation was a clear failure and the reality tells us that __GFP_NOFAIL is not even close to go away.

It is still true that __GFP_NOFAIL allocations are generally discouraged and new uses should be evaluated and an alternative (pre-allocations or reservations) should be considered but it doesn't make any sense to lie the allocator about the requirements. Allocator can take steps to help making a progress if it knows the requirements.

---
 fs/jbd2/journal.c     | 11 +----------
 fs/jbd2/transaction.c | 20 +++++++-------------
 2 files changed, 8 insertions(+), 23 deletions(-)
fs/jbd2/journal.c +1 -10
index b96bd8076b70..0bc333b4a594 100644
@@ -371,16 +371,7 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
 	 */
 	J_ASSERT_BH(bh_in, buffer_jbddirty(bh_in));
 
-retry_alloc:
-	new_bh = alloc_buffer_head(GFP_NOFS);
-	if (!new_bh) {
-		/*
-		 * Failure is not an option, but __GFP_NOFAIL is going
-		 * away; so we retry ourselves here.
-		 */
-		congestion_wait(BLK_RW_ASYNC, HZ/50);
-		goto retry_alloc;
-	}
+	new_bh = alloc_buffer_head(GFP_NOFS|__GFP_NOFAIL);
 
 	/* keep subsequent assertions sane */
 	atomic_set(&new_bh->b_count, 1);
fs/jbd2/transaction.c +7 -13
index 5f09370c90a8..dac4523fa142 100644
@@ -278,22 +278,16 @@ static int start_this_handle(journal_t *journal, handle_t *handle,
 
 alloc_transaction:
 	if (!journal->j_running_transaction) {
+		/*
+		 * If __GFP_FS is not present, then we may be being called from
+		 * inside the fs writeback layer, so we MUST NOT fail.
+		 */
+		if ((gfp_mask & __GFP_FS) == 0)
+			gfp_mask |= __GFP_NOFAIL;
 		new_transaction = kmem_cache_zalloc(transaction_cache,
 						    gfp_mask);
-		if (!new_transaction) {
-			/*
-			 * If __GFP_FS is not present, then we may be
-			 * being called from inside the fs writeback
-			 * layer, so we MUST NOT fail.  Since
-			 * __GFP_NOFAIL is going away, we will arrange
-			 * to retry the allocation ourselves.
-			 */
-			if ((gfp_mask & __GFP_FS) == 0) {
-				congestion_wait(BLK_RW_ASYNC, HZ/50);
-				goto alloc_transaction;
-			}
+		if (!new_transaction)
 			return -ENOMEM;
-		}
 	}
 
 	jbd_debug(3, "New handle %p going live.\n", handle);
Signature · 7 lines
2.1.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on v1 2/4
#4 lore raw

Re: [RFC 2/4] jbd2: revert must-not-fail allocation loops back to GFP_NOFAIL

Quoted 7 lines · Michal Hocko

This basically reverts 47def82672b3 (jbd2: Remove __GFP_NOFAIL from jbd2 layer). The deprecation of __GFP_NOFAIL was a bad choice because it led to open coding the endless loop around the allocator rather than removing the dependency on the non failing allocation. So the deprecation was a clear failure and the reality tells us that __GFP_NOFAIL is not even close to go away.

Quoted 6 lines

It is still true that __GFP_NOFAIL allocations are generally discouraged and new uses should be evaluated and an alternative (pre-allocations or reservations) should be considered but it doesn't make any sense to lie the allocator about the requirements. Allocator can take steps to help making a progress if it knows the requirements.

The changelog should state that this only changes the source code, there is no functional change since alloc_buffer_head() and kmem_cache_zalloc(transaction_cache) are already implicitly nofail due to the allocation order. The failure code added by the commit you cite are never executed.

I agree that if the implementation of the page allocator were to change with respect to PAGE_ALLOC_COSTLY_ORDER that we'd need __GFP_NOFAIL and that such an allocation is better handled in the page allocator.

Quoted 1 line

GFP_NOFS|__GFP_NOFAIL is scary.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw

Re: [RFC 2/4] jbd2: revert must-not-fail allocation loops back to GFP_NOFAIL

Quoted 16 lines · David Rientjes
Quoted 7 lines · Michal Hocko

This basically reverts 47def82672b3 (jbd2: Remove __GFP_NOFAIL from jbd2 layer). The deprecation of __GFP_NOFAIL was a bad choice because it led to open coding the endless loop around the allocator rather than removing the dependency on the non failing allocation. So the deprecation was a clear failure and the reality tells us that __GFP_NOFAIL is not even close to go away.

Quoted 6 lines

It is still true that __GFP_NOFAIL allocations are generally discouraged and new uses should be evaluated and an alternative (pre-allocations or reservations) should be considered but it doesn't make any sense to lie the allocator about the requirements. Allocator can take steps to help making a progress if it knows the requirements.

Quoted 5 lines

The changelog should state that this only changes the source code, there is no functional change since alloc_buffer_head() and kmem_cache_zalloc(transaction_cache) are already implicitly nofail due to the allocation order. The failure code added by the commit you cite are never executed.

Well, even when those allocation would fail the resulting behavior is basically the same (modulo congestion_wait which imho doesn't make much difference). So I would prefer not getting that way and simply stay with the external loop vs. looping within the allocator.

Quoted 7 lines

I agree that if the implementation of the page allocator were to change with respect to PAGE_ALLOC_COSTLY_ORDER that we'd need __GFP_NOFAIL and that such an allocation is better handled in the page allocator.

Quoted 1 line

Thanks

Quoted 1 line

GFP_NOFS|__GFP_NOFAIL is scary.

Yes it is but as I've learned nothing unusual in the fs land and the situation should be improved a lot if we go reservation way suggested by David. Then __GFP_NOFAIL would consume the pre-reserved memory rather than trigger OOM killer.

Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#6 lore raw

RFC 3/4 sparc: remove __GFP_NOFAIL reuquirement

In reply to Michal Hocko

mdesc_kmalloc is currently requiring __GFP_NOFAIL allocation although it seems that the allocation failure is handled by all callers (via mdesc_alloc). __GFP_NOFAIL is a strong liability for the memory allocator and so the users are discouraged to use the flag unless the allocation failure is really a nogo. Drop the flag here as this doesn't seem to be the case.

---
 arch/sparc/kernel/mdesc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/kernel/mdesc.c +1 -1
index 99632a87e697..6801bd778af2 100644
@@ -136,7 +136,7 @@ static struct mdesc_handle *mdesc_kmalloc(unsigned int mdesc_size)
 		       sizeof(struct mdesc_hdr) +
 		       mdesc_size);
 
-	base = kmalloc(handle_size + 15, GFP_KERNEL | __GFP_NOFAIL);
+	base = kmalloc(handle_size + 15, GFP_KERNEL);
 	if (base) {
 		struct mdesc_handle *hp;
 		unsigned long addr;
Signature · 7 lines
2.1.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#7 lore raw

Re: [RFC 3/4] sparc: remove __GFP_NOFAIL reuquirement

From: Michal Hocko <[email protected]>
Date: Mon, 2 Mar 2015 14:54:42 +0100

Quoted 8 lines

mdesc_kmalloc is currently requiring __GFP_NOFAIL allocation although it seems that the allocation failure is handled by all callers (via mdesc_alloc). __GFP_NOFAIL is a strong liability for the memory allocator and so the users are discouraged to use the flag unless the allocation failure is really a nogo. Drop the flag here as this doesn't seem to be the case.

It is a serious failure.

If we miss an MDESC update due to this allocation failure, the update is not an event which gets retransmitted so we will lose the updated machine description forever.

We really need this allocation to succeed.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw

Re: [RFC 3/4] sparc: remove __GFP_NOFAIL reuquirement

Quoted 12 lines · David S. Miller

From: Michal Hocko <[email protected]>
Date: Mon, 2 Mar 2015 14:54:42 +0100

Quoted 8 lines

mdesc_kmalloc is currently requiring __GFP_NOFAIL allocation although it seems that the allocation failure is handled by all callers (via mdesc_alloc). __GFP_NOFAIL is a strong liability for the memory allocator and so the users are discouraged to use the flag unless the allocation failure is really a nogo. Drop the flag here as this doesn't seem to be the case.

Quoted 7 lines

It is a serious failure.

If we miss an MDESC update due to this allocation failure, the update is not an event which gets retransmitted so we will lose the updated machine description forever.

We really need this allocation to succeed.

OK, thanks for the clarification. This wasn't clear from the commit which has introduced this code. I will drop this patch. Would you accept something like the following instead?
---

arch/sparc/kernel/mdesc.c +11 -11
index 99632a87e697..26c80e18d7b1 100644
@@ -130,26 +130,26 @@ static struct mdesc_mem_ops memblock_mdesc_ops = {
 static struct mdesc_handle *mdesc_kmalloc(unsigned int mdesc_size)
 {
 	unsigned int handle_size;
+	struct mdesc_handle *hp;
+	unsigned long addr;
 	void *base;
 
 	handle_size = (sizeof(struct mdesc_handle) -
 		       sizeof(struct mdesc_hdr) +
 		       mdesc_size);
 
+	/*
+	 * Allocation has to succeed because mdesc update would be missed
+	 * and such events are not retransmitted.
+	 */
 	base = kmalloc(handle_size + 15, GFP_KERNEL | __GFP_NOFAIL);
-	if (base) {
-		struct mdesc_handle *hp;
-		unsigned long addr;
-
-		addr = (unsigned long)base;
-		addr = (addr + 15UL) & ~15UL;
-		hp = (struct mdesc_handle *) addr;
+	addr = (unsigned long)base;
+	addr = (addr + 15UL) & ~15UL;
+	hp = (struct mdesc_handle *) addr;
 
-		mdesc_handle_init(hp, handle_size, base);
-		return hp;
-	}
+	mdesc_handle_init(hp, handle_size, base);
 
-	return NULL;
+	return hp;
 }
 
 static void mdesc_kfree(struct mdesc_handle *hp)
Signature · 2 lines
Michal Hocko
SUSE Labs
maintainer
#9 lore raw

Re: [RFC 3/4] sparc: remove __GFP_NOFAIL reuquirement

From: Michal Hocko <[email protected]>
Date: Mon, 2 Mar 2015 21:33:04 +0100

Quoted 19 lines · David S. Miller
Quoted 18 lines

From: Michal Hocko <[email protected]>
Date: Mon, 2 Mar 2015 14:54:42 +0100

Quoted 8 lines

mdesc_kmalloc is currently requiring __GFP_NOFAIL allocation although it seems that the allocation failure is handled by all callers (via mdesc_alloc). __GFP_NOFAIL is a strong liability for the memory allocator and so the users are discouraged to use the flag unless the allocation failure is really a nogo. Drop the flag here as this doesn't seem to be the case.

It is a serious failure.

If we miss an MDESC update due to this allocation failure, the update is not an event which gets retransmitted so we will lose the updated machine description forever.

Quoted 5 lines
Quoted 1 line

We really need this allocation to succeed.

OK, thanks for the clarification. This wasn't clear from the commit which has introduced this code. I will drop this patch. Would you accept something like the following instead?

Sure.

#10 lore raw

PATCH 1/1 sparc: clarify __GFP_NOFAIL allocation

On Mon 02-03-15 15:44:24, David S. Miller wrote:
[...]

Quoted 5 lines
Quoted 3 lines

OK, thanks for the clarification. This wasn't clear from the commit which has introduced this code. I will drop this patch. Would you accept something like the following instead?

Sure.

Thanks!

---

Quoted 1 line

From dac5829e3a1d44ba7759b4188de01f15ddb77b8b Mon Sep 17 00:00:00 2001

From: Michal Hocko <[email protected]>
Date: Mon, 2 Mar 2015 22:27:02 +0100
Subject: [PATCH] sparc: clarify __GFP_NOFAIL allocation

920c3ed74134 ([SPARC64]: Add basic infrastructure for MD add/remove notification.) has added __GFP_NOFAIL for the allocation request but it hasn't mentioned why is this strict requirement really needed. The code was handling an allocation failure and propagated it properly up the callchain so it is not clear why it is needed.

Dave has clarified the intention when I tried to remove the flag as not being necessary:
"
It is a serious failure.

If we miss an MDESC update due to this allocation failure, the update is not an event which gets retransmitted so we will lose the updated machine description forever.

We really need this allocation to succeed.
"

So add a comment to clarify the nofail flag and get rid of the failure check because __GFP_NOFAIL allocation doesn't fail.

---
 arch/sparc/kernel/mdesc.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
arch/sparc/kernel/mdesc.c +11 -11
index 99632a87e697..26c80e18d7b1 100644
@@ -130,26 +130,26 @@ static struct mdesc_mem_ops memblock_mdesc_ops = {
 static struct mdesc_handle *mdesc_kmalloc(unsigned int mdesc_size)
 {
 	unsigned int handle_size;
+	struct mdesc_handle *hp;
+	unsigned long addr;
 	void *base;
 
 	handle_size = (sizeof(struct mdesc_handle) -
 		       sizeof(struct mdesc_hdr) +
 		       mdesc_size);
 
+	/*
+	 * Allocation has to succeed because mdesc update would be missed
+	 * and such events are not retransmitted.
+	 */
 	base = kmalloc(handle_size + 15, GFP_KERNEL | __GFP_NOFAIL);
-	if (base) {
-		struct mdesc_handle *hp;
-		unsigned long addr;
-
-		addr = (unsigned long)base;
-		addr = (addr + 15UL) & ~15UL;
-		hp = (struct mdesc_handle *) addr;
+	addr = (unsigned long)base;
+	addr = (addr + 15UL) & ~15UL;
+	hp = (struct mdesc_handle *) addr;
 
-		mdesc_handle_init(hp, handle_size, base);
-		return hp;
-	}
+	mdesc_handle_init(hp, handle_size, base);
 
-	return NULL;
+	return hp;
 }
 
 static void mdesc_kfree(struct mdesc_handle *hp)
Signature · 6 lines
2.1.4


-- 
Michal Hocko
SUSE Labs
maintainer Acked-by on v1 1/1
#11 lore raw

Re: [PATCH] sparc: clarify __GFP_NOFAIL allocation

From: Michal Hocko <[email protected]>
Date: Mon, 2 Mar 2015 22:36:10 +0100

Quoted 15 lines

920c3ed74134 ([SPARC64]: Add basic infrastructure for MD add/remove notification.) has added __GFP_NOFAIL for the allocation request but it hasn't mentioned why is this strict requirement really needed. The code was handling an allocation failure and propagated it properly up the callchain so it is not clear why it is needed.

Dave has clarified the intention when I tried to remove the flag as not being necessary:
"
It is a serious failure.

If we miss an MDESC update due to this allocation failure, the update is not an event which gets retransmitted so we will lose the updated machine description forever.

Quoted 7 lines

We really need this allocation to succeed.
"

So add a comment to clarify the nofail flag and get rid of the failure check because __GFP_NOFAIL allocation doesn't fail.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#12 lore raw

RFC 4/4 cxgb4: drop __GFP_NOFAIL allocation

In reply to Michal Hocko

set_filter_wr is requesting __GFP_NOFAIL allocation although it can return ENOMEM without any problems obviously (t4_l2t_set_switching does that already). So the non-failing requirement is too strong without any obvious reason. Drop __GFP_NOFAIL and reorganize the code to have the failure paths easier.

The same applies to _c4iw_write_mem_dma_aligned which uses __GFP_NOFAIL and then checks the return value and returns -ENOMEM on failure. This doesn't make any sense what so ever. Either the allocation cannot fail or it can.

del_filter_wr seems to be safe as well because the filter entry is not marked as pending and the return value is propagated up the stack up to c4iw_destroy_listen.

---
 drivers/infiniband/hw/cxgb4/mem.c               |  2 +-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 15 ++++++++++++---
 2 files changed, 13 insertions(+), 4 deletions(-)
drivers/infiniband/hw/cxgb4/mem.c +1 -1
index cb43c2299ac0..81b028eaf1f5 100644
@@ -73,7 +73,7 @@ static int _c4iw_write_mem_dma_aligned(struct c4iw_rdev *rdev, u32 addr,
 		c4iw_init_wr_wait(&wr_wait);
 	wr_len = roundup(sizeof(*req) + sizeof(*sgl), 16);
 
-	skb = alloc_skb(wr_len, GFP_KERNEL | __GFP_NOFAIL);
+	skb = alloc_skb(wr_len, GFP_KERNEL);
 	if (!skb)
 		return -ENOMEM;
 	set_wr_txq(skb, CPL_PRIORITY_CONTROL, 0);
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +12 -3
index ccf3436024bc..f351920fc293 100644
@@ -1220,6 +1220,10 @@ static int set_filter_wr(struct adapter *adapter, int fidx)
 	struct fw_filter_wr *fwr;
 	unsigned int ftid;
 
+	skb = alloc_skb(sizeof(*fwr), GFP_KERNEL);
+	if (!skb)
+		return -ENOMEM;
+
 	/* If the new filter requires loopback Destination MAC and/or VLAN
 	 * rewriting then we need to allocate a Layer 2 Table (L2T) entry for
 	 * the filter.
@@ -1227,19 +1231,21 @@ static int set_filter_wr(struct adapter *adapter, int fidx)
 	if (f->fs.newdmac || f->fs.newvlan) {
 		/* allocate L2T entry for new filter */
 		f->l2t = t4_l2t_alloc_switching(adapter->l2t);
-		if (f->l2t == NULL)
+		if (f->l2t == NULL) {
+			kfree(skb);
 			return -EAGAIN;
+		}
 		if (t4_l2t_set_switching(adapter, f->l2t, f->fs.vlan,
 					f->fs.eport, f->fs.dmac)) {
 			cxgb4_l2t_release(f->l2t);
 			f->l2t = NULL;
+			kfree(skb);
 			return -ENOMEM;
 		}
 	}
 
 	ftid = adapter->tids.ftid_base + fidx;
 
-	skb = alloc_skb(sizeof(*fwr), GFP_KERNEL | __GFP_NOFAIL);
 	fwr = (struct fw_filter_wr *)__skb_put(skb, sizeof(*fwr));
 	memset(fwr, 0, sizeof(*fwr));
 
@@ -1337,7 +1343,10 @@ static int del_filter_wr(struct adapter *adapter, int fidx)
 	len = sizeof(*fwr);
 	ftid = adapter->tids.ftid_base + fidx;
 
-	skb = alloc_skb(len, GFP_KERNEL | __GFP_NOFAIL);
+	skb = alloc_skb(len, GFP_KERNEL);
+	if (!skb)
+		return -ENOMEM;
+
 	fwr = (struct fw_filter_wr *)__skb_put(skb, len);
 	t4_mk_filtdelwr(ftid, fwr, adapter->sge.fw_evtq.abs_id);
 
Signature · 1 line
2.1.4
#13 lore raw

Re: [RFC 4/4] cxgb4: drop __GFP_NOFAIL allocation

Quoted 16 lines · Michal Hocko
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +4 -0
index ccf3436024bc..f351920fc293 100644
@@ -1220,6 +1220,10 @@ static int set_filter_wr(struct adapter *adapter, int fidx)
 	struct fw_filter_wr *fwr;
 	unsigned int ftid;
 
+	skb = alloc_skb(sizeof(*fwr), GFP_KERNEL);
+	if (!skb)
+		return -ENOMEM;
+
 	/* If the new filter requires loopback Destination MAC and/or VLAN
 	 * rewriting then we need to allocate a Layer 2 Table (L2T) entry for
 	 * the filter.

drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c static int set_filter_wr(struct adapter *adapter, int fidx) · line 1235

Quoted 6 lines
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +2 -1
@@ -1227,19 +1231,21 @@ static int set_filter_wr(struct adapter *adapter, int fidx)
 	if (f->fs.newdmac || f->fs.newvlan) {
 		/* allocate L2T entry for new filter */
 		f->l2t = t4_l2t_alloc_switching(adapter->l2t);
-		if (f->l2t == NULL)
+		if (f->l2t == NULL) {
+			kfree(skb);

I think we need to use kfree_skb() than kfree() for memory allocated by alloc_skb().

drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c static int set_filter_wr(struct adapter *adapter, int fidx) · line 1242

Quoted 7 lines
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +2 -0
 			return -EAGAIN;
+		}
 		if (t4_l2t_set_switching(adapter, f->l2t, f->fs.vlan,
 					f->fs.eport, f->fs.dmac)) {
 			cxgb4_l2t_release(f->l2t);
 			f->l2t = NULL;
+			kfree(skb);

Ditto.

Quoted 10 lines
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +0 -1
 			return -ENOMEM;
 		}
 	}
 
 	ftid = adapter->tids.ftid_base + fidx;
 
-	skb = alloc_skb(sizeof(*fwr), GFP_KERNEL | __GFP_NOFAIL);
 	fwr = (struct fw_filter_wr *)__skb_put(skb, sizeof(*fwr));
 	memset(fwr, 0, sizeof(*fwr));
 
#14 lore raw

Re: [RFC 4/4] cxgb4: drop __GFP_NOFAIL allocation

Quoted 9 lines · Tetsuo Handa
Quoted 8 lines · Michal Hocko
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +0 -0
index ccf3436024bc..f351920fc293 100644
@@ -1220,6 +1220,10 @@ static int set_filter_wr(struct adapter *adapter, int fidx)
 	struct fw_filter_wr *fwr;
 	unsigned int ftid;
 
Quoted 16 lines
Quoted 8 lines
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +4 -0
+	skb = alloc_skb(sizeof(*fwr), GFP_KERNEL);
+	if (!skb)
+		return -ENOMEM;
+
 	/* If the new filter requires loopback Destination MAC and/or VLAN
 	 * rewriting then we need to allocate a Layer 2 Table (L2T) entry for
 	 * the filter.

drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c static int set_filter_wr(struct adapter *adapter, int fidx) · line 1235

Quoted 6 lines
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +2 -1
@@ -1227,19 +1231,21 @@ static int set_filter_wr(struct adapter *adapter, int fidx)
 	if (f->fs.newdmac || f->fs.newvlan) {
 		/* allocate L2T entry for new filter */
 		f->l2t = t4_l2t_alloc_switching(adapter->l2t);
-		if (f->l2t == NULL)
+		if (f->l2t == NULL) {
+			kfree(skb);

I think we need to use kfree_skb() than kfree() for memory allocated by alloc_skb().

Definitely! Good point, thanks!

Andrew, I've noticed you have picked up the patch. Should I resend or the below incremental one is good enough?
---

Quoted 1 line

From eee05867dd55efa236ba065a3e7b7eb6e6ea511d Mon Sep 17 00:00:00 2001

From: Michal Hocko <[email protected]>
Date: Tue, 3 Mar 2015 14:16:30 +0100
Subject: [PATCH] mmotm: cxgb4-drop-__gfp_nofail-allocation-fix

Use kfree_skb instead of kfree because the allocation is done by alloc_skb.

---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +2 -2
index f351920fc293..e1e5028a714c 100644
@@ -1232,14 +1232,14 @@ static int set_filter_wr(struct adapter *adapter, int fidx)
 		/* allocate L2T entry for new filter */
 		f->l2t = t4_l2t_alloc_switching(adapter->l2t);
 		if (f->l2t == NULL) {
-			kfree(skb);
+			kfree_skb(skb);
 			return -EAGAIN;
 		}
 		if (t4_l2t_set_switching(adapter, f->l2t, f->fs.vlan,
 					f->fs.eport, f->fs.dmac)) {
 			cxgb4_l2t_release(f->l2t);
 			f->l2t = NULL;
-			kfree(skb);
+			kfree_skb(skb);
 			return -ENOMEM;
 		}
 	}
Signature · 6 lines
2.1.4


-- 
Michal Hocko
SUSE Labs