Re: [PATCH] [NET] warn when accounting an skb that already has a destructor

Previous thread: S/G operation, skb checksums, data copying by Johannes Berg on Sunday, May 4, 2008 - 2:28 pm. (3 messages)

Next thread: [RFC] [NET] restructure LL_MAX_HEADER code, increase headroom for 802.11 by Johannes Berg on Sunday, May 4, 2008 - 2:44 pm. (1 message)
To: David S. Miller <davem@...>
Cc: netdev <netdev@...>
Date: Sunday, May 4, 2008 - 2:32 pm

This makes the networking layer warn when something tries to
charge an skb to a socket that already is charged to another
socket (or has a destructor from somewhere else.)

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
---
Not sure if the code size increase is prohibitive, haven't really
checked. Might have helped in early mac80211 days (when we didn't
have the skb_orphan call) but for normal skb usage this shouldn't
ever happen.

include/net/sock.h | 2 ++
1 file changed, 2 insertions(+)

--- everything.orig/include/net/sock.h 2008-05-03 15:51:36.000000000 +0200
+++ everything/include/net/sock.h 2008-05-03 15:51:56.000000000 +0200
@@ -1167,6 +1167,7 @@ static inline void skb_set_owner_w(struc
{
sock_hold(sk);
skb->sk = sk;
+ WARN_ON(skb->destructor);
skb->destructor = sock_wfree;
atomic_add(skb->truesize, &sk->sk_wmem_alloc);
}
@@ -1174,6 +1175,7 @@ static inline void skb_set_owner_w(struc
static inline void skb_set_owner_r(struct sk_buff *skb, struct sock *sk)
{
skb->sk = sk;
+ WARN_ON(skb->destructor);
skb->destructor = sock_rfree;
atomic_add(skb->truesize, &sk->sk_rmem_alloc);
sk_mem_charge(sk, skb->truesize);

--

To: <johannes@...>
Cc: <netdev@...>
Date: Monday, May 5, 2008 - 3:20 am

From: Johannes Berg <johannes@sipsolutions.net>

I completely agree that this a correct assertion, that
absolutely should never happen in the current tree.

But if we are going to do this, I'm pretty sure we'll
need to uninline these two routines.

I'll leave it up to you, if you think it's still worthwhile
with the uninlining, please resubmit :-)
--

To: David Miller <davem@...>
Cc: <netdev@...>
Date: Monday, May 5, 2008 - 3:31 am

Given that it's a corner case and no regular net drivers would ever want
to do something that could possibly cause this condition to be true,
it's probably not worth it either way. Even mac80211 doesn't run into
it, although it might have helped a bit to remember to add skb_orphan()
to the re-injection.

If we decide to uninline those functions for another reason (used too
much, code size, ...) then we can still do that.

johannes

To: <johannes@...>
Cc: <netdev@...>
Date: Monday, May 5, 2008 - 3:40 am

From: Johannes Berg <johannes@sipsolutions.net>

Agreed.
--

To: David Miller <davem@...>
Cc: <johannes@...>, Netdev <netdev@...>
Date: Monday, May 5, 2008 - 5:43 am

According to my measurements the size bloat of those two is
(x86/32bit, gcc 4.1.2 redhat something):

-1091 40 funcs, 89 +, 1180 -, diff: -1091 --- skb_set_owner_r
-495 46 funcs, 70 +, 565 -, diff: -495 --- skb_set_owner_w

--
i.
--

To: <ilpo.jarvinen@...>
Cc: <johannes@...>, <netdev@...>
Date: Monday, May 5, 2008 - 3:08 pm

From: "Ilpo_Järvinen" <ilpo.jarvinen@helsinki.fi>

That's not too bad, but adding the WARN_ON() we're discussing
will plump that up a bit, percentage wise, which is why I
said we should inline it in such a case.
--

To: David Miller <davem@...>
Cc: <ilpo.jarvinen@...>, <johannes@...>, <netdev@...>
Date: Monday, May 5, 2008 - 5:57 pm

s/inline/uninline/g

According to some long e-mail today its worth ~198 unexport patches! 8-)

- Arnaldo
--

To: Arnaldo Carvalho de Melo <acme@...>
Cc: David Miller <davem@...>, <johannes@...>, Netdev <netdev@...>
Date: Tuesday, May 6, 2008 - 4:39 am

> > From: "Ilpo_J

To: Ilpo <ilpo.jarvinen@...>
Cc: David Miller <davem@...>, Netdev <netdev@...>
Date: Monday, May 5, 2008 - 7:37 am

So do we want to out-line them? I don't really know the scale involved.
If so I can resubmit this patch with them outlined and the warnings
added (but did you account for the EXPORT_SYMBOL space?)

johannes

To: Johannes Berg <johannes@...>
Cc: David Miller <davem@...>, Netdev <netdev@...>
Date: Monday, May 5, 2008 - 7:58 am

On Mon, 5 May 2008, Johannes Berg wrote:

> On Mon, 2008-05-05 at 12:43 +0300, Ilpo J

To: Ilpo <ilpo.jarvinen@...>
Cc: David Miller <davem@...>, Netdev <netdev@...>
Date: Monday, May 5, 2008 - 8:04 am

I guess it's not much, it seems to be an unsigned long, a pointer and
the name string.

johannes

Previous thread: S/G operation, skb checksums, data copying by Johannes Berg on Sunday, May 4, 2008 - 2:28 pm. (3 messages)

Next thread: [RFC] [NET] restructure LL_MAX_HEADER code, increase headroom for 802.11 by Johannes Berg on Sunday, May 4, 2008 - 2:44 pm. (1 message)