netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] openvswitch: Fix alignment of struct sw_flow_key.
@ 2013-09-05 17:41 Jesse Gross
  2013-09-05 18:17 ` David Miller
  2013-09-06 10:18 ` David Laight
  0 siblings, 2 replies; 13+ messages in thread
From: Jesse Gross @ 2013-09-05 17:41 UTC (permalink / raw)
  To: David Miller
  Cc: netdev, dev, Andy Zhou, Fengguang Wu, Geert Uytterhoeven,
	Jesse Gross

sw_flow_key alignment was declared as " __aligned(__alignof__(long))".
However, this breaks on the m68k architecture where long is 32 bit in
size but 16 bit aligned by default. This aligns to 8 bytes to ensure
that long is always covered without reducing native alignment. It also
adds an additional build check to catch any reduction in alignment.

CC: Andy Zhou <azhou@nicira.com>
Reported-by: Fengguang Wu <fengguan.wu@intel.com>
Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Jesse Gross <jesse@nicira.com>
---
 net/openvswitch/flow.c | 1 +
 net/openvswitch/flow.h | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/openvswitch/flow.c b/net/openvswitch/flow.c
index ad1aeeb..fb36f85 100644
--- a/net/openvswitch/flow.c
+++ b/net/openvswitch/flow.c
@@ -1981,6 +1981,7 @@ nla_put_failure:
  * Returns zero if successful or a negative error code. */
 int ovs_flow_init(void)
 {
+	BUILD_BUG_ON(__alignof__(struct sw_flow_key) % __alignof__(long));
 	BUILD_BUG_ON(sizeof(struct sw_flow_key) % sizeof(long));
 
 	flow_cache = kmem_cache_create("sw_flow", sizeof(struct sw_flow), 0,
diff --git a/net/openvswitch/flow.h b/net/openvswitch/flow.h
index b65f885..3dc3b52 100644
--- a/net/openvswitch/flow.h
+++ b/net/openvswitch/flow.h
@@ -125,7 +125,7 @@ struct sw_flow_key {
 			} nd;
 		} ipv6;
 	};
-} __aligned(__alignof__(long));
+} __aligned(8); /* 8 byte alignment ensures this can be accessed as a long */
 
 struct sw_flow {
 	struct rcu_head rcu;
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 13+ messages in thread
* [PATCH] openvswitch: Fix alignment of struct sw_flow_key.
@ 2013-09-05 19:17 Jesse Gross
  2013-09-05 19:25 ` Geert Uytterhoeven
  2013-09-05 19:54 ` David Miller
  0 siblings, 2 replies; 13+ messages in thread
From: Jesse Gross @ 2013-09-05 19:17 UTC (permalink / raw)
  To: David Miller
  Cc: netdev, dev, Andy Zhou, Fengguang Wu, Geert Uytterhoeven,
	Jesse Gross

sw_flow_key alignment was declared as " __aligned(__alignof__(long))".
However, this breaks on the m68k architecture where long is 32 bit in
size but 16 bit aligned by default. This aligns to the size of a long to
ensure that we can always do comparsions in full long-sized chunks. It
also adds an additional build check to catch any reduction in alignment.

CC: Andy Zhou <azhou@nicira.com>
Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Jesse Gross <jesse@nicira.com>
---
 net/openvswitch/flow.c | 1 +
 net/openvswitch/flow.h | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/openvswitch/flow.c b/net/openvswitch/flow.c
index ad1aeeb..fb36f85 100644
--- a/net/openvswitch/flow.c
+++ b/net/openvswitch/flow.c
@@ -1981,6 +1981,7 @@ nla_put_failure:
  * Returns zero if successful or a negative error code. */
 int ovs_flow_init(void)
 {
+	BUILD_BUG_ON(__alignof__(struct sw_flow_key) % __alignof__(long));
 	BUILD_BUG_ON(sizeof(struct sw_flow_key) % sizeof(long));
 
 	flow_cache = kmem_cache_create("sw_flow", sizeof(struct sw_flow), 0,
diff --git a/net/openvswitch/flow.h b/net/openvswitch/flow.h
index b65f885..212fbf7 100644
--- a/net/openvswitch/flow.h
+++ b/net/openvswitch/flow.h
@@ -125,7 +125,7 @@ struct sw_flow_key {
 			} nd;
 		} ipv6;
 	};
-} __aligned(__alignof__(long));
+} __aligned(BITS_PER_LONG/8); /* Ensure that we can do comparisons as longs. */
 
 struct sw_flow {
 	struct rcu_head rcu;
-- 
1.8.1.2

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

end of thread, other threads:[~2013-09-06 10:20 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-05 17:41 [PATCH] openvswitch: Fix alignment of struct sw_flow_key Jesse Gross
2013-09-05 18:17 ` David Miller
2013-09-05 18:36   ` Jesse Gross
     [not found]     ` <CAEP_g=8gcCtkv=no=HkVmS+NDWPM-Uu-SVyR+vb-YQ=7TWJsXA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-09-05 18:40       ` David Miller
     [not found]         ` <20130905.144044.1053960608071929025.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2013-09-05 19:14           ` Jesse Gross
2013-09-05 19:20         ` Geert Uytterhoeven
2013-09-05 19:25           ` Jesse Gross
2013-09-05 19:49           ` David Miller
2013-09-05 19:47         ` Joe Perches
2013-09-06 10:18 ` David Laight
  -- strict thread matches above, loose matches on Subject: below --
2013-09-05 19:17 Jesse Gross
2013-09-05 19:25 ` Geert Uytterhoeven
2013-09-05 19:54 ` David 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).