All of lore.kernel.org
 help / color / mirror / Atom feed
* patch to kaweth.c to align IP header
@ 2002-09-04 18:26 Quinn Jensen
  2002-09-04 23:34 ` Alan Cox
  0 siblings, 1 reply; 6+ messages in thread
From: Quinn Jensen @ 2002-09-04 18:26 UTC (permalink / raw)
  To: linux-mips

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

All,

The Kawasaki LSI USB Ethernet driver was causing a crash
in ipt_do_table() on mips because the address fields in
the IP header were not word aligned.  Many (all?) other
ethernet drivers do an skb_reserve of 2 to word align
the address fields, and doing this in kaweth.c fixed
my crash.

kernel: 2.4.17
hardware: Netgear EA101 USB Ethernet

Quinn



[-- Attachment #2: linuxtx-kaweth.patch --]
[-- Type: text/plain, Size: 439 bytes --]

diff -puN -r -X - linux/drivers/usb/kaweth.c linux.modified/drivers/usb/kaweth.c
--- linux/drivers/usb/kaweth.c	Tue Nov 13 10:19:41 2001
+++ linux.modified/drivers/usb/kaweth.c	Tue Sep  3 16:07:08 2002
@@ -514,6 +514,7 @@ static void kaweth_usb_receive(struct ur
 
 		skb->dev = net;
 
+		skb_reserve(skb, 2);    /* Align IP on 16 byte boundaries */
 		eth_copy_and_sum(skb, kaweth->rx_buf + 2, pkt_len, 0);
 		
 		skb_put(skb, pkt_len);


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

* Re: patch to kaweth.c to align IP header
  2002-09-04 18:26 patch to kaweth.c to align IP header Quinn Jensen
@ 2002-09-04 23:34 ` Alan Cox
  2002-09-05  8:23     ` Kevin D. Kissell
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Cox @ 2002-09-04 23:34 UTC (permalink / raw)
  To: Quinn Jensen; +Cc: linux-mips

On Wed, 2002-09-04 at 19:26, Quinn Jensen wrote:
> All,
> 
> The Kawasaki LSI USB Ethernet driver was causing a crash
> in ipt_do_table() on mips because the address fields in
> the IP header were not word aligned.  Many (all?) other

You -must- handle alignment traps in the kernel for networking. The
network code assumes and relies on this property and there are plenty of
other ways to get misaligned datagrams through things like ip in ip.

> ethernet drivers do an skb_reserve of 2 to word align
> the address fields, and doing this in kaweth.c fixed
> my crash.

Its not the crash fix, its however right in the sense its a good
performance optimisation for most platforms

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

* Re: patch to kaweth.c to align IP header
@ 2002-09-05  8:23     ` Kevin D. Kissell
  0 siblings, 0 replies; 6+ messages in thread
From: Kevin D. Kissell @ 2002-09-05  8:23 UTC (permalink / raw)
  To: Alan Cox, Quinn Jensen; +Cc: linux-mips

----- Original Message ----- 
From: "Alan Cox" <alan@lxorguk.ukuu.org.uk>
To: "Quinn Jensen" <jensenq@lineo.com>
Cc: <linux-mips@linux-mips.org>
Sent: Thursday, September 05, 2002 1:34 AM
Subject: Re: patch to kaweth.c to align IP header


> On Wed, 2002-09-04 at 19:26, Quinn Jensen wrote:
> > All,
> > 
> > The Kawasaki LSI USB Ethernet driver was causing a crash
> > in ipt_do_table() on mips because the address fields in
> > the IP header were not word aligned.  Many (all?) other
> 
> You -must- handle alignment traps in the kernel for networking. The
> network code assumes and relies on this property and there are plenty of
> other ways to get misaligned datagrams through things like ip in ip.
> 
> > ethernet drivers do an skb_reserve of 2 to word align
> > the address fields, and doing this in kaweth.c fixed
> > my crash.
> 
> Its not the crash fix, its however right in the sense its a good
> performance optimisation for most platforms

It is true that, due to the unfortunate lack of foresight in the
design of IP, no pre-alignment of buffers will *guarantee*
that the address or other fields of IP headers will be aligned.

But I note that a design which assumes, for non x86 CPUs,
that unaligned references will be handled by a kernel trap
handler had darn well better assure itself that the misaligned
case is extemely infrequent.  Otherwise, it would be a distinctly
better design to extract all multi-byte IP header values using
a macro which could map to a direct, possibly unaligned,
load for CISC architectures, and to appropriate sequences
of instructions for RISC architectures.  I haven't measured
the alignment fault path for MIPS/Linux (in any case, MIPS
isn't the only architecture affected here), but if we assume for
the sake of the argument that it's 50 instructions, and that an
unaligned halfword costs 4 inline instructions (lbu,lbu,sll,or),
then using the unaligned reference trap as a crutch is a win
only if the fields are correctly aligned roughtly 94% of the time.

If full 32-bit or 64-bit words are being extracted, a MIPS CPU
can do the unaligned accesses in only 2 in-line instructions,
which would push the breakeven point out even further.

Does anyone have any actual statistical data on the cost
and frequency of this use of the unaligned access fixup?

            Regards,

            Kevin K.

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

* Re: patch to kaweth.c to align IP header
@ 2002-09-05  8:23     ` Kevin D. Kissell
  0 siblings, 0 replies; 6+ messages in thread
From: Kevin D. Kissell @ 2002-09-05  8:23 UTC (permalink / raw)
  To: Alan Cox, Quinn Jensen; +Cc: linux-mips

----- Original Message ----- 
From: "Alan Cox" <alan@lxorguk.ukuu.org.uk>
To: "Quinn Jensen" <jensenq@lineo.com>
Cc: <linux-mips@linux-mips.org>
Sent: Thursday, September 05, 2002 1:34 AM
Subject: Re: patch to kaweth.c to align IP header


> On Wed, 2002-09-04 at 19:26, Quinn Jensen wrote:
> > All,
> > 
> > The Kawasaki LSI USB Ethernet driver was causing a crash
> > in ipt_do_table() on mips because the address fields in
> > the IP header were not word aligned.  Many (all?) other
> 
> You -must- handle alignment traps in the kernel for networking. The
> network code assumes and relies on this property and there are plenty of
> other ways to get misaligned datagrams through things like ip in ip.
> 
> > ethernet drivers do an skb_reserve of 2 to word align
> > the address fields, and doing this in kaweth.c fixed
> > my crash.
> 
> Its not the crash fix, its however right in the sense its a good
> performance optimisation for most platforms

It is true that, due to the unfortunate lack of foresight in the
design of IP, no pre-alignment of buffers will *guarantee*
that the address or other fields of IP headers will be aligned.

But I note that a design which assumes, for non x86 CPUs,
that unaligned references will be handled by a kernel trap
handler had darn well better assure itself that the misaligned
case is extemely infrequent.  Otherwise, it would be a distinctly
better design to extract all multi-byte IP header values using
a macro which could map to a direct, possibly unaligned,
load for CISC architectures, and to appropriate sequences
of instructions for RISC architectures.  I haven't measured
the alignment fault path for MIPS/Linux (in any case, MIPS
isn't the only architecture affected here), but if we assume for
the sake of the argument that it's 50 instructions, and that an
unaligned halfword costs 4 inline instructions (lbu,lbu,sll,or),
then using the unaligned reference trap as a crutch is a win
only if the fields are correctly aligned roughtly 94% of the time.

If full 32-bit or 64-bit words are being extracted, a MIPS CPU
can do the unaligned accesses in only 2 in-line instructions,
which would push the breakeven point out even further.

Does anyone have any actual statistical data on the cost
and frequency of this use of the unaligned access fixup?

            Regards,

            Kevin K.

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

* Re: patch to kaweth.c to align IP header
  2002-09-05  8:23     ` Kevin D. Kissell
  (?)
@ 2002-09-05  8:57     ` Carsten Langgaard
  -1 siblings, 0 replies; 6+ messages in thread
From: Carsten Langgaard @ 2002-09-05  8:57 UTC (permalink / raw)
  To: Kevin D. Kissell; +Cc: Alan Cox, Quinn Jensen, linux-mips

"Kevin D. Kissell" wrote:

> ----- Original Message -----
> From: "Alan Cox" <alan@lxorguk.ukuu.org.uk>
> To: "Quinn Jensen" <jensenq@lineo.com>
> Cc: <linux-mips@linux-mips.org>
> Sent: Thursday, September 05, 2002 1:34 AM
> Subject: Re: patch to kaweth.c to align IP header
>
> > On Wed, 2002-09-04 at 19:26, Quinn Jensen wrote:
> > > All,
> > >
> > > The Kawasaki LSI USB Ethernet driver was causing a crash
> > > in ipt_do_table() on mips because the address fields in
> > > the IP header were not word aligned.  Many (all?) other
> >
> > You -must- handle alignment traps in the kernel for networking. The
> > network code assumes and relies on this property and there are plenty of
> > other ways to get misaligned datagrams through things like ip in ip.
> >
> > > ethernet drivers do an skb_reserve of 2 to word align
> > > the address fields, and doing this in kaweth.c fixed
> > > my crash.
> >
> > Its not the crash fix, its however right in the sense its a good
> > performance optimisation for most platforms
>
> It is true that, due to the unfortunate lack of foresight in the
> design of IP, no pre-alignment of buffers will *guarantee*
> that the address or other fields of IP headers will be aligned.
>
> But I note that a design which assumes, for non x86 CPUs,
> that unaligned references will be handled by a kernel trap
> handler had darn well better assure itself that the misaligned
> case is extemely infrequent.  Otherwise, it would be a distinctly
> better design to extract all multi-byte IP header values using
> a macro which could map to a direct, possibly unaligned,
> load for CISC architectures, and to appropriate sequences
> of instructions for RISC architectures.  I haven't measured
> the alignment fault path for MIPS/Linux (in any case, MIPS
> isn't the only architecture affected here), but if we assume for
> the sake of the argument that it's 50 instructions, and that an
> unaligned halfword costs 4 inline instructions (lbu,lbu,sll,or),
> then using the unaligned reference trap as a crutch is a win
> only if the fields are correctly aligned roughtly 94% of the time.
>
> If full 32-bit or 64-bit words are being extracted, a MIPS CPU
> can do the unaligned accesses in only 2 in-line instructions,
> which would push the breakeven point out even further.
>
> Does anyone have any actual statistical data on the cost
> and frequency of this use of the unaligned access fixup?
>

There is implemented a counter in the unaligned exception handler, you used
to get hold of the value through /proc/cpuinfo, but this has apparently been
removed from the latest kernels.


>
>             Regards,
>
>             Kevin K.

--
_    _ ____  ___   Carsten Langgaard   Mailto:carstenl@mips.com
|\  /|||___)(___   MIPS Denmark        Direct: +45 4486 5527
| \/ |||    ____)  Lautrupvang 4B      Switch: +45 4486 5555
  TECHNOLOGIES     2750 Ballerup       Fax...: +45 4486 5556
                   Denmark             http://www.mips.com

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

* Re: patch to kaweth.c to align IP header
  2002-09-05  8:23     ` Kevin D. Kissell
  (?)
  (?)
@ 2002-09-05 11:22     ` Alan Cox
  -1 siblings, 0 replies; 6+ messages in thread
From: Alan Cox @ 2002-09-05 11:22 UTC (permalink / raw)
  To: Kevin D. Kissell; +Cc: Quinn Jensen, linux-mips

On Thu, 2002-09-05 at 09:23, Kevin D. Kissell wrote:
> It is true that, due to the unfortunate lack of foresight in the
> design of IP, no pre-alignment of buffers will *guarantee*
> that the address or other fields of IP headers will be aligned.

It was not done for lack of foresight. It was carefully instrumented
measured and assessed.

> But I note that a design which assumes, for non x86 CPUs,
> that unaligned references will be handled by a kernel trap
> handler had darn well better assure itself that the misaligned
> case is extemely infrequent.  Otherwise, it would be a distinctly

It does

> then using the unaligned reference trap as a crutch is a win
> only if the fields are correctly aligned roughtly 94% of the time.

With properly set up network cards (and that can be a problem some can't
DMA to half word start points) the benched numbers I got for normal use
back when we decided to go this way were that no packet appeared
unaligned unless deeply weird stuff like IPX over 802.2 without SNAP was
being used. Nevertheless there are several way users can trigger such
alignment so your code must handle them. Another case it can occur is
PPP. 

Hitting 94% aligned is trivially the norm.

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

end of thread, other threads:[~2002-09-05 11:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-04 18:26 patch to kaweth.c to align IP header Quinn Jensen
2002-09-04 23:34 ` Alan Cox
2002-09-05  8:23   ` Kevin D. Kissell
2002-09-05  8:23     ` Kevin D. Kissell
2002-09-05  8:57     ` Carsten Langgaard
2002-09-05 11:22     ` Alan Cox

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.