All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jesper Dangaard Brouer <brouer@redhat.com>
To: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>
Cc: saeedm@mellanox.com, gerlitz.or@gmail.com, eugenia@mellanox.com,
	Alexander Duyck <alexander.duyck@gmail.com>,
	Jesper Dangaard Brouer <brouer@redhat.com>
Subject: [net-next PATCH V1 3/3] net: warn on napi_alloc_skb being called in wrong context
Date: Mon, 09 May 2016 15:44:39 +0200	[thread overview]
Message-ID: <20160509134439.3573.97841.stgit@firesoul> (raw)
In-Reply-To: <20160509134352.3573.37044.stgit@firesoul>

It have always been required to call napi_alloc_skb from NAPI/softirq
context, which implies running with local_bh_disable'ed.  Thus, this
code path should already be well tested. But recent SKB bulk changes
introduced will make this more volatile and bugs more subtle, if this
is violated.

To catch any driver violating this add a loud WARN_ON.

Performance wise, I do worry about adding this runtime check code into
the hotpath, of this highly optimized function call.  I've
micro-benchmarked it with both IP-forwarding and local UDP delivery,
and didn't see any regressions.  It does adds extra code size (icache).

add/remove: 0/0 grow/shrink: 1/0 up/down: 43/0 (43)
function                                     old     new   delta
__napi_alloc_skb                             461     504     +43

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
---
 net/core/skbuff.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index e85f1065b263..99addbf66f2e 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -498,6 +498,9 @@ struct sk_buff *__napi_alloc_skb(struct napi_struct *napi, unsigned int len,
 	struct sk_buff *skb;
 	void *data;
 
+	/* Catch drivers violating, not having local BH disabled */
+	WARN_ON(!in_softirq());
+
 	len += NET_SKB_PAD + NET_IP_ALIGN;
 
 	if (unlikely((len > SKB_WITH_OVERHEAD(PAGE_SIZE)) ||

  parent reply	other threads:[~2016-05-09 13:44 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-09 13:44 [net-next PATCH V1 0/3] net: enable use of kmem_cache_alloc_bulk in network stack Jesper Dangaard Brouer
2016-05-09 13:44 ` [net-next PATCH V1 1/3] net: bulk alloc and reuse of SKBs in NAPI context Jesper Dangaard Brouer
2016-05-09 16:20   ` Alexander Duyck
2016-05-09 19:59     ` Jesper Dangaard Brouer
2016-05-09 20:46       ` Alexander Duyck
2016-05-10  9:29         ` Jesper Dangaard Brouer
2016-05-10 12:30         ` Jesper Dangaard Brouer
2016-05-10 13:48           ` Eric Dumazet
2016-05-10 14:48             ` Jesper Dangaard Brouer
2016-05-10 15:44               ` Eric Dumazet
2016-05-10 17:46           ` Alexander Duyck
2016-05-09 13:44 ` [net-next PATCH V1 2/3] mlx4: use napi_alloc_skb API to get SKB bulk allocations Jesper Dangaard Brouer
2016-05-09 16:47   ` Alexander Duyck
2016-05-09 20:05     ` Jesper Dangaard Brouer
2016-05-09 13:44 ` Jesper Dangaard Brouer [this message]
2016-05-09 13:53   ` [net-next PATCH V1 3/3] net: warn on napi_alloc_skb being called in wrong context Sergei Shtylyov
2016-05-09 13:53   ` Sergei Shtylyov
2016-05-09 16:33   ` Alexander Duyck
2016-05-09 20:03     ` Jesper Dangaard Brouer
2016-05-20  8:14 ` [net-next PATCH V1 0/3] net: enable use of kmem_cache_alloc_bulk in network stack Jesper Dangaard Brouer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160509134439.3573.97841.stgit@firesoul \
    --to=brouer@redhat.com \
    --cc=alexander.duyck@gmail.com \
    --cc=davem@davemloft.net \
    --cc=eugenia@mellanox.com \
    --cc=gerlitz.or@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.