alignment problem in net/core/flow.c:flow_key_compare
Subsystems (2)
This is in 2.6.4:
Begin forwarded message:
Date: Thu, 18 Mar 2004 11:53:02 +0100
From: [email protected] (Måns Rullgård)
To: [email protected]
Subject: [BUG] alignment problem in net/core/flow.c:flow_key_compare
There is a problem with alignment in the flow_key_compare function in net/core/flow.c. It takes arguments of type struct flowi * and casts them to flow_compare_t *, which is 64 bits on 64-bit machines. It then proceeds to read and compare 64-bit values from these pointers. The problem is that struct flowi only requires 32-bit alignment, so these reads cause numerous unaligned exceptions. On average, I get nearly 1000 unaligned exceptions per second.
The solutions I see are either to force the alignment of struct flowi to 64 bits, or to use 32-bit access in flow_key_compare.
Signature · 7 lines
Måns Rullgård [email protected] - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
In article <[email protected]> (at Thu, 18 Mar 2004 16:29:03 -0800), Andrew Morton <[email protected]> says:
Quoted 2 lines
The solutions I see are either to force the alignment of struct flowi to 64 bits, or to use 32-bit access in
flow_key_compare.
Here's the patch.
===== include/net/flow.h 1.10 vs edited =====
include/net/flow.h +7 -1
@@ -10,6 +10,12 @@#include <linux/in6.h> #include <asm/atomic.h> +#if (BITS_PER_LONG ==64 ) +#define FLOWI_ALIGN_BYTES 8 +#else +#define FLOWI_ALIGN_BYTES 4 +#endif +struct flowi {int oif;int iif;
@@ -77,7 +83,7 @@#define fl_icmp_type uli_u.icmpt.type#define fl_icmp_code uli_u.icmpt.code#define fl_ipsec_spi uli_u.spi -}; +} __attribute__((__aligned__(FLOWI_ALIGN_BYTES)));#define FLOW_DIR_IN 0#define FLOW_DIR_OUT 1
Signature · 2 lines
Hideaki YOSHIFUJI @ USAGI Project <[email protected]> GPG FP: 9022 65EB 1ECF 3AD1 0BDF 80D8 4807 F894 E062 0EEA
Quoted 18 lines · YOSHIFUJI Hideaki / ____________
+#if (
BITS_PER_LONG== 64)
+#defineFLOWI_ALIGN_BYTES8
+#else
+#defineFLOWI_ALIGN_BYTES4
+#endif
+
struct flowi {
int oif;
int iif;
@@ -77,7 +83,7 @@
#definefl_icmp_typeuli_u.icmpt.type
#definefl_icmp_codeuli_u.icmpt.code
#definefl_ipsec_spiuli_u.spi
-};
+} __attribute__((__aligned__(FLOWI_ALIGN_BYTES)));
Why not simply
Quoted 1 line
+} __attribute__((__aligned__(BITS_PER_LONG/8)));
?
Quoted 7 lines · On Thu, 18 Mar 2004 18:59:40 -0800 Andrew Morton <[email protected]> wrote:
Quoted 3 lines
-};
+} __attribute__((__aligned__(FLOWI_ALIGN_BYTES)));Why not simply
Quoted 1 line
+} __attribute__((__aligned__(BITS_PER_LONG/8)));
Works for me :-)
In article <[email protected]> (at Thu, 18 Mar 2004 18:59:40 -0800), Andrew Morton <[email protected]> says:
Quoted 5 lines
Why not simply
Quoted 1 line
+} __attribute__((__aligned__(BITS_PER_LONG/8)));
?
Okay;
===== include/net/flow.h 1.10 vs edited =====
include/net/flow.h +1 -1
@@ -77,7 +77,7 @@#define fl_icmp_type uli_u.icmpt.type#define fl_icmp_code uli_u.icmpt.code#define fl_ipsec_spi uli_u.spi -}; +} __attribute__((__aligned__(BITS_PER_LONG/8)));#define FLOW_DIR_IN 0#define FLOW_DIR_OUT 1
Signature · 2 lines
Hideaki YOSHIFUJI @ USAGI Project <[email protected]> GPG FP: 9022 65EB 1ECF 3AD1 0BDF 80D8 4807 F894 E062 0EEA