netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [TCP]: Fix truesize underflow
@ 2006-04-18 12:32 Herbert Xu
  2006-04-18 16:29 ` Ingo Oeser
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Herbert Xu @ 2006-04-18 12:32 UTC (permalink / raw)
  To: Boris B. Zhmurov, Phil Oester, Mark Nipper, David S. Miller,
	jesse.brandeburg, jrlundgren, cat, djani22, yoseph.basri, mykleb,
	olel, michal, chris, netdev, jesse.brandeburg, Andi Kleen,
	Jeff Garzik

[-- Attachment #1: Type: text/plain, Size: 1124 bytes --]

Hi Dave:

You're absolutely right about there being a problem with the TSO packet
trimming code.  The cause of this lies in the tcp_fragment() function.

When we allocate a fragment for a completely non-linear packet the
truesize is calculated for a payload length of zero.  This means that
truesize could in fact be less than the real payload length.

When that happens the TSO packet trimming can cause truesize to become
negative.  This in turn can cause sk_forward_alloc to be -n * PAGE_SIZE
which would trigger the warning.

I've copied the code you used in tso_fragment which should work here.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Everyone who's having the sk_forward_alloc warning problem should give
this patch a go to see if it cures things.

Just in case this still doesn't fix it, could everyone please also verify
whether disabling SMP has any effect on reproducing this?

Thanks,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

[-- Attachment #2: tcp-fragment.patch --]
[-- Type: text/plain, Size: 484 bytes --]

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index b871db6..44df1db 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -551,7 +551,9 @@
 	buff = sk_stream_alloc_skb(sk, nsize, GFP_ATOMIC);
 	if (buff == NULL)
 		return -ENOMEM; /* We'll just try again later. */
-	sk_charge_skb(sk, buff);
+
+	buff->truesize = skb->len - len;
+	skb->truesize -= buff->truesize;
 
 	/* Correct the sequence numbers. */
 	TCP_SKB_CB(buff)->seq = TCP_SKB_CB(skb)->seq + len;

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [TCP]: Fix truesize underflow
  2006-04-18 12:32 [TCP]: Fix truesize underflow Herbert Xu
@ 2006-04-18 16:29 ` Ingo Oeser
  2006-04-18 20:19   ` David S. Miller
  2006-04-18 20:22 ` David S. Miller
  2006-04-19 16:53 ` Stephen Hemminger
  2 siblings, 1 reply; 11+ messages in thread
From: Ingo Oeser @ 2006-04-18 16:29 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Boris B. Zhmurov, Phil Oester, Mark Nipper, David S. Miller,
	jesse.brandeburg, jrlundgren, cat, djani22, yoseph.basri, mykleb,
	olel, michal, chris, netdev, jesse.brandeburg, Andi Kleen,
	Jeff Garzik

Hi Herbert,

Herbert Xu wrote:
> I've copied the code you used in tso_fragment which should work here.

I'm happy to see, that this got resolved and this is a nice minimalistic fix 
for -stable. 

But shouldn't we put this kind of hairy manipulation into some nice functions?
Driver writers were already confused by all that size, len and truesize stuff, 
as this bug showed.


Regards

Ingo Oeser

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [TCP]: Fix truesize underflow
  2006-04-18 16:29 ` Ingo Oeser
@ 2006-04-18 20:19   ` David S. Miller
  0 siblings, 0 replies; 11+ messages in thread
From: David S. Miller @ 2006-04-18 20:19 UTC (permalink / raw)
  To: netdev
  Cc: herbert, bb, kernel, nipsy, jesse.brandeburg, jrlundgren, cat,
	djani22, yoseph.basri, mykleb, olel, michal, chris, netdev,
	jesse.brandeburg, ak, jgarzik

From: Ingo Oeser <netdev@axxeo.de>
Date: Tue, 18 Apr 2006 18:29:59 +0200

> But shouldn't we put this kind of hairy manipulation into some nice
> functions?  Driver writers were already confused by all that size,
> len and truesize stuff, as this bug showed.

It's 2 lines and frankly it's a bit context dependant.  I think
Herbert's fix is fine for now.

In the long term, yes, a lot of these weird manipulations need to
be consolidated in well defined functions to make maintainence
and auditing easier.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [TCP]: Fix truesize underflow
  2006-04-18 12:32 [TCP]: Fix truesize underflow Herbert Xu
  2006-04-18 16:29 ` Ingo Oeser
@ 2006-04-18 20:22 ` David S. Miller
  2006-04-18 23:27   ` Herbert Xu
  2006-04-19 16:53 ` Stephen Hemminger
  2 siblings, 1 reply; 11+ messages in thread
From: David S. Miller @ 2006-04-18 20:22 UTC (permalink / raw)
  To: herbert
  Cc: bb, kernel, nipsy, jesse.brandeburg, jrlundgren, cat, djani22,
	yoseph.basri, mykleb, olel, michal, chris, netdev,
	jesse.brandeburg, ak, jgarzik

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: Tue, 18 Apr 2006 22:32:04 +1000

> You're absolutely right about there being a problem with the TSO packet
> trimming code.  The cause of this lies in the tcp_fragment() function.
> 
> When we allocate a fragment for a completely non-linear packet the
> truesize is calculated for a payload length of zero.  This means that
> truesize could in fact be less than the real payload length.
> 
> When that happens the TSO packet trimming can cause truesize to become
> negative.  This in turn can cause sk_forward_alloc to be -n * PAGE_SIZE
> which would trigger the warning.
> 
> I've copied the code you used in tso_fragment which should work here.
> 
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Thanks for discovering this, very nice work Herbert.

So what we find out time and time again, is that the TSO splitting and
trimming code enforces that the skb->truesize of every TCP packet must
be accurate at all times.

I think it is deserving of some run time assertions, else these bugs
will elude us continually.  Luckily there are only a few places that
would need the run time assertion checks on skb->truesize, and I'll
try to spend a few cycles on implementing this soon.

Patch applied, thanks a lot!


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [TCP]: Fix truesize underflow
  2006-04-18 20:22 ` David S. Miller
@ 2006-04-18 23:27   ` Herbert Xu
  2006-04-19  6:04     ` Boris B. Zhmurov
  0 siblings, 1 reply; 11+ messages in thread
From: Herbert Xu @ 2006-04-18 23:27 UTC (permalink / raw)
  To: David S. Miller
  Cc: bb, kernel, nipsy, jesse.brandeburg, jrlundgren, cat, djani22,
	yoseph.basri, mykleb, olel, michal, chris, netdev,
	jesse.brandeburg, ak, jgarzik

On Tue, Apr 18, 2006 at 01:22:56PM -0700, David S. Miller wrote:
> 
> I think it is deserving of some run time assertions, else these bugs
> will elude us continually.  Luckily there are only a few places that
> would need the run time assertion checks on skb->truesize, and I'll
> try to spend a few cycles on implementing this soon.

Yes indeed.  One place that comes to mind would be tcp_trim_head just
before we munge truesize.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [TCP]: Fix truesize underflow
  2006-04-18 23:27   ` Herbert Xu
@ 2006-04-19  6:04     ` Boris B. Zhmurov
  2006-04-19  6:40       ` Herbert Xu
  2006-04-19 16:07       ` Jesse Brandeburg
  0 siblings, 2 replies; 11+ messages in thread
From: Boris B. Zhmurov @ 2006-04-19  6:04 UTC (permalink / raw)
  To: Herbert Xu
  Cc: David S. Miller, kernel, nipsy, jesse.brandeburg, jrlundgren, cat,
	djani22, yoseph.basri, mykleb, olel, michal, chris, netdev,
	jesse.brandeburg, ak, jgarzik

Hello, Herbert Xu.

On 19.04.2006 03:27 you said the following:

> On Tue, Apr 18, 2006 at 01:22:56PM -0700, David S. Miller wrote:
> 
>>I think it is deserving of some run time assertions, else these bugs
>>will elude us continually.  Luckily there are only a few places that
>>would need the run time assertion checks on skb->truesize, and I'll
>>try to spend a few cycles on implementing this soon.
> 
> 
> Yes indeed.  One place that comes to mind would be tcp_trim_head just
> before we munge truesize.
> 
> Cheers,


I confirm, finally I don't see messages in dmesg about assertions. Nice 
work :)

-- 
Boris B. Zhmurov
mailto: bb@kernelpanic.ru
"wget http://kernelpanic.ru/bb_public_key.pgp -O - | gpg --import"


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [TCP]: Fix truesize underflow
  2006-04-19  6:04     ` Boris B. Zhmurov
@ 2006-04-19  6:40       ` Herbert Xu
  2006-04-19 16:07       ` Jesse Brandeburg
  1 sibling, 0 replies; 11+ messages in thread
From: Herbert Xu @ 2006-04-19  6:40 UTC (permalink / raw)
  To: Boris B. Zhmurov
  Cc: David S. Miller, kernel, nipsy, jesse.brandeburg, jrlundgren, cat,
	djani22, yoseph.basri, mykleb, olel, michal, chris, netdev,
	jesse.brandeburg, ak, jgarzik

On Wed, Apr 19, 2006 at 10:04:53AM +0400, Boris B. Zhmurov wrote:
> 
> I confirm, finally I don't see messages in dmesg about assertions. Nice 
> work :)

That's great.  Thanks a lot for your and everyone else's help in
tracking down.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [TCP]: Fix truesize underflow
  2006-04-19  6:04     ` Boris B. Zhmurov
  2006-04-19  6:40       ` Herbert Xu
@ 2006-04-19 16:07       ` Jesse Brandeburg
  2006-04-19 21:29         ` Krzysztof Oledzki
  1 sibling, 1 reply; 11+ messages in thread
From: Jesse Brandeburg @ 2006-04-19 16:07 UTC (permalink / raw)
  To: bb
  Cc: Herbert Xu, David S. Miller, kernel, nipsy, jrlundgren, cat,
	djani22, yoseph.basri, mykleb, olel, michal, chris, netdev,
	jesse.brandeburg, ak, jgarzik

Boris B. Zhmurov wrote:
> Hello, Herbert Xu.
>
> On 19.04.2006 03:27 you said the following:
>
>> On Tue, Apr 18, 2006 at 01:22:56PM -0700, David S. Miller wrote:
>>
>>> I think it is deserving of some run time assertions, else these bugs
>>> will elude us continually.  Luckily there are only a few places that
>>> would need the run time assertion checks on skb->truesize, and I'll
>>> try to spend a few cycles on implementing this soon.
>>
>>
>> Yes indeed.  One place that comes to mind would be tcp_trim_head just
>> before we munge truesize.
>>
>> Cheers,
>
>
> I confirm, finally I don't see messages in dmesg about assertions. 
> Nice work :)
>
I can also confirm that both machines here had no problems after 
applying this patch. Good work!

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [TCP]: Fix truesize underflow
  2006-04-18 12:32 [TCP]: Fix truesize underflow Herbert Xu
  2006-04-18 16:29 ` Ingo Oeser
  2006-04-18 20:22 ` David S. Miller
@ 2006-04-19 16:53 ` Stephen Hemminger
  2006-04-19 20:07   ` David S. Miller
  2 siblings, 1 reply; 11+ messages in thread
From: Stephen Hemminger @ 2006-04-19 16:53 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Boris B. Zhmurov, Phil Oester, Mark Nipper, David S. Miller,
	jesse.brandeburg, jrlundgren, cat, djani22, yoseph.basri, mykleb,
	olel, michal, chris, netdev, jesse.brandeburg, Andi Kleen,
	Jeff Garzik

On Tue, 18 Apr 2006 22:32:04 +1000
Herbert Xu <herbert@gondor.apana.org.au> wrote:

> Hi Dave:
> 
> You're absolutely right about there being a problem with the TSO packet
> trimming code.  The cause of this lies in the tcp_fragment() function.
> 
> When we allocate a fragment for a completely non-linear packet the
> truesize is calculated for a payload length of zero.  This means that
> truesize could in fact be less than the real payload length.
> 
> When that happens the TSO packet trimming can cause truesize to become
> negative.  This in turn can cause sk_forward_alloc to be -n * PAGE_SIZE
> which would trigger the warning.
> 
> I've copied the code you used in tso_fragment which should work here.
> 
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
> 
> Everyone who's having the sk_forward_alloc warning problem should give
> this patch a go to see if it cures things.
> 
> Just in case this still doesn't fix it, could everyone please also verify
> whether disabling SMP has any effect on reproducing this?
> 
> Thanks,

Please put this in the next -stable load...

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [TCP]: Fix truesize underflow
  2006-04-19 16:53 ` Stephen Hemminger
@ 2006-04-19 20:07   ` David S. Miller
  0 siblings, 0 replies; 11+ messages in thread
From: David S. Miller @ 2006-04-19 20:07 UTC (permalink / raw)
  To: shemminger
  Cc: herbert, bb, kernel, nipsy, jesse.brandeburg, jrlundgren, cat,
	djani22, yoseph.basri, mykleb, olel, michal, chris, netdev,
	jesse.brandeburg, ak, jgarzik

From: Stephen Hemminger <shemminger@osdl.org>
Date: Wed, 19 Apr 2006 09:53:48 -0700

> Please put this in the next -stable load...

I already sent it to -stable.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [TCP]: Fix truesize underflow
  2006-04-19 16:07       ` Jesse Brandeburg
@ 2006-04-19 21:29         ` Krzysztof Oledzki
  0 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Oledzki @ 2006-04-19 21:29 UTC (permalink / raw)
  To: Jesse Brandeburg
  Cc: bb, Herbert Xu, David S. Miller, kernel, nipsy, jrlundgren, cat,
	djani22, yoseph.basri, mykleb, michal, chris, netdev,
	jesse.brandeburg, ak, jgarzik

[-- Attachment #1: Type: TEXT/PLAIN, Size: 938 bytes --]



On Wed, 19 Apr 2006, Jesse Brandeburg wrote:

> Boris B. Zhmurov wrote:
>> Hello, Herbert Xu.
>> 
>> On 19.04.2006 03:27 you said the following:
>> 
>>> On Tue, Apr 18, 2006 at 01:22:56PM -0700, David S. Miller wrote:
>>> 
>>>> I think it is deserving of some run time assertions, else these bugs
>>>> will elude us continually.  Luckily there are only a few places that
>>>> would need the run time assertion checks on skb->truesize, and I'll
>>>> try to spend a few cycles on implementing this soon.
>>> 
>>> 
>>> Yes indeed.  One place that comes to mind would be tcp_trim_head just
>>> before we munge truesize.
>>> 
>>> Cheers,
>> 
>> 
>> I confirm, finally I don't see messages in dmesg about assertions. Nice 
>> work :)
>> 
> I can also confirm that both machines here had no problems after applying 
> this patch. Good work!

Me too, me too. Thank you! :)

Best regards,

 				Krzysztof Olędzki

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2006-04-19 21:31 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-18 12:32 [TCP]: Fix truesize underflow Herbert Xu
2006-04-18 16:29 ` Ingo Oeser
2006-04-18 20:19   ` David S. Miller
2006-04-18 20:22 ` David S. Miller
2006-04-18 23:27   ` Herbert Xu
2006-04-19  6:04     ` Boris B. Zhmurov
2006-04-19  6:40       ` Herbert Xu
2006-04-19 16:07       ` Jesse Brandeburg
2006-04-19 21:29         ` Krzysztof Oledzki
2006-04-19 16:53 ` Stephen Hemminger
2006-04-19 20:07   ` David S. Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).