[ovs-dev] [RFC PATCH 4/5] tun_metadata: Use OVS_ALIGNED_VAR to align opts field

Toshiaki Makita toshiaki.makita1 at gmail.com
Tue Mar 10 15:29:10 UTC 2020


In the following commit I want to include flow.h from BPF programs, but
with "clang -target bpf" with clang 9, UINTPTR_MAX somehow equals to
UINT32_MAX while the size of pointer is 8. As a result unnecessary pad
is added in struct tun_metadata in bpf code and cannot build bpf code
due to build assertion.

Use OVS_ALIGNED_VAR instead of pad. This works for clang BPF as well as
other compilers and architectures.

Signed-off-by: Toshiaki Makita <toshiaki.makita1 at gmail.com>
---
 include/openvswitch/tun-metadata.h | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/include/openvswitch/tun-metadata.h b/include/openvswitch/tun-metadata.h
index dc0312ecb..1009d82e1 100644
--- a/include/openvswitch/tun-metadata.h
+++ b/include/openvswitch/tun-metadata.h
@@ -54,14 +54,10 @@ struct tun_metadata {
     } present;
     const struct tun_table *tab; /* Types & lengths for 'opts' and 'opt_map'. */
 
-#if UINTPTR_MAX == UINT32_MAX
-    uint8_t pad[4];             /* Pad to 64-bit boundary. */
-#endif
-
     union {
         uint8_t u8[TUN_METADATA_TOT_OPT_SIZE]; /* Values from tunnel TLVs. */
         struct geneve_opt gnv[TLV_TOT_OPT_SIZE / sizeof(struct geneve_opt)];
-    } opts;
+    } opts OVS_ALIGNED_VAR(8);
 };
 BUILD_ASSERT_DECL(offsetof(struct tun_metadata, opts) % 8 == 0);
 BUILD_ASSERT_DECL(sizeof(((struct tun_metadata *)0)->present.map) * 8 >=
-- 
2.24.1



More information about the dev mailing list