Skip to contentSkip to conversation

alignment problem in net/core/flow.c:flow_key_compare

BUG Måns Rullgård 2 participants 4 messages Mar 18, 2004

lore
Share & tools
lore
#0 lore raw

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 · 2 lines
Måns Rullgård
[email protected]
#1 lore raw
Quoted 10 lines · [email protected] (Måns Rullgård) writes:

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.

I forgot to mention that this is kernel 2.6.4.

Signature · 2 lines
Måns Rullgård
[email protected]
#2 lore raw
Quoted 6 lines · On Thu, 18 Mar 2004 12:25:57 +0100 [email protected] (Måns Rullgård) wrote:
Quoted 2 lines · [email protected] (Måns Rullgård) writes:

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.

I forgot to mention that this is kernel 2.6.4.

Yes, just add an alignment attribute of some kind to the struct is probably the best idea.

#3 lore raw
Quoted 5 lines · David S. Miller
Quoted 2 lines · On Thu, 18 Mar 2004 12:25:57 +0100 [email protected] (Måns Rullgård) wrote:

[email protected] (Måns Rullgård) writes:

Quoted 7 lines
Quoted 4 lines
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.

I forgot to mention that this is kernel 2.6.4.

Yes, just add an alignment attribute of some kind to the struct is probably the best idea.

What's the proper way of doing that in kernel code? Should I use gcc __attribute__ directly or is there some macro that's preferred?

Signature · 2 lines
Måns Rullgård
[email protected]