All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philip Craig <philipc@snapgear.com>
To: Patrick McHardy <kaber@trash.net>
Cc: davem@davemloft.net, netfilter-devel@vger.kernel.org,
	Russell King <rmk@arm.linux.org.uk>
Subject: Re: [NETFILTER 42/69]: nf_conntrack: optimize hash_conntrack()
Date: Tue, 29 Apr 2008 14:48:27 +1000	[thread overview]
Message-ID: <4816A89B.7050300@snapgear.com> (raw)
In-Reply-To: <4815D842.8010303@trash.net>

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

Patrick McHardy wrote:
> Thanks for tracking this down, I didn't realize we had holes
> in struct nf_conntrack_tuple on ARM. There are two ways to
> fix this, one is two remove the padding, the other one is to
> clear the padding as you did. We could join all the tuple
> structs to avoid padding, but unfortunately that probably
> won't help because the port structs are also padded. Maybe
> attribute(packed) on the individual port structs within the
> union will work, I'm not sure about that.

I prefer to remove the padding so that we don't change how other
architectures work.  The attached patch does this.  I'm not sure
if this has any performance penalties on ARM. 

The attribute(packed) is required on both the port structs
and the unions.


[-- Attachment #2: conntrack-hash-padding.patch --]
[-- Type: text/x-diff, Size: 6768 bytes --]

[NETFILTER]: nf_conntrack: padding breaks conntrack hash on ARM

commit 0794935e "[NETFILTER]: nf_conntrack: optimize hash_conntrack()"
relies on struct nf_conntrack_tuple containing no padding, because
NF_CT_TUPLE_U_BLANK() would leave any padding uninitialised.

But on ARM, structures are normally padded to 4 bytes.  So use
__attribute__(packed) to eliminate this padding.

However, we must be careful to keep the userspace ABI unchanged.

Signed-off-by: Philip Craig <philipc@snapgear.com>

--- linux-2.6.25/include/net/netfilter/nf_conntrack_tuple.h	22 Apr 2008 01:36:51 -0000	1.1.1.5
+++ linux-2.6.25/include/net/netfilter/nf_conntrack_tuple.h	29 Apr 2008 04:14:14 -0000
@@ -32,20 +32,20 @@ union nf_conntrack_man_proto
 
 	struct {
 		__be16 port;
-	} tcp;
+	} __attribute__ ((packed)) tcp;
 	struct {
 		__be16 port;
-	} udp;
+	} __attribute__ ((packed)) udp;
 	struct {
 		__be16 id;
-	} icmp;
+	} __attribute__ ((packed)) icmp;
 	struct {
 		__be16 port;
-	} sctp;
+	} __attribute__ ((packed)) sctp;
 	struct {
 		__be16 key;	/* GRE key is 32bit, PPtP only uses 16bit */
-	} gre;
-};
+	} __attribute__ ((packed)) gre;
+} __attribute__ ((packed));
 
 /* The manipulable part of the tuple. */
 struct nf_conntrack_man
@@ -56,7 +56,10 @@ struct nf_conntrack_man
 	u_int16_t l3num;
 };
 
-/* This contains the information to distinguish a connection. */
+/* This contains the information to distinguish a connection.
+ * This must be packed because the contents are used for the conntrack
+ * hash, but NF_CT_TUPLE_U_BLANK() would leave any padding uninitialised.
+ */
 struct nf_conntrack_tuple
 {
 	struct nf_conntrack_man src;
@@ -70,20 +73,20 @@ struct nf_conntrack_tuple
 
 			struct {
 				__be16 port;
-			} tcp;
+			} __attribute__ ((packed)) tcp;
 			struct {
 				__be16 port;
-			} udp;
+			} __attribute__ ((packed)) udp;
 			struct {
 				u_int8_t type, code;
-			} icmp;
+			} __attribute__ ((packed)) icmp;
 			struct {
 				__be16 port;
-			} sctp;
+			} __attribute__ ((packed)) sctp;
 			struct {
 				__be16 key;
-			} gre;
-		} u;
+			} __attribute__ ((packed)) gre;
+		} __attribute__ ((packed)) u;
 
 		/* The protocol. */
 		u_int8_t protonum;
--- linux-2.6.25/include/net/netfilter/nf_nat.h	22 Apr 2008 01:36:51 -0000	1.1.1.4
+++ linux-2.6.25/include/net/netfilter/nf_nat.h	29 Apr 2008 04:14:14 -0000
@@ -42,12 +42,50 @@ struct nf_nat_range
 };
 
 /* For backwards compat: don't use in modern code. */
+
+/* The protocol-specific manipulable parts of the tuple: always in
+   network order! */
+union nf_conntrack_man_proto_compat
+{
+	/* Add other protocols here. */
+	__be16 all;
+
+	struct {
+		__be16 port;
+	} tcp;
+	struct {
+		__be16 port;
+	} udp;
+	struct {
+		__be16 id;
+	} icmp;
+	struct {
+		__be16 port;
+	} sctp;
+	struct {
+		__be16 key;	/* GRE key is 32bit, PPtP only uses 16bit */
+	} gre;
+};
+
+/* Single range specification. */
+struct nf_nat_range_compat
+{
+	/* Set to OR of flags above. */
+	unsigned int flags;
+
+	/* Inclusive: network order. */
+	__be32 min_ip, max_ip;
+
+	/* Inclusive: network order */
+	union nf_conntrack_man_proto_compat min, max;
+};
+
 struct nf_nat_multi_range_compat
 {
 	unsigned int rangesize; /* Must be 1. */
 
 	/* hangs off end. */
-	struct nf_nat_range range[1];
+	struct nf_nat_range_compat range[1];
 };
 
 #ifdef __KERNEL__
--- linux-2.6.25/net/ipv4/netfilter/ipt_MASQUERADE.c	22 Apr 2008 01:38:00 -0000	1.1.1.26
+++ linux-2.6.25/net/ipv4/netfilter/ipt_MASQUERADE.c	29 Apr 2008 04:14:14 -0000
@@ -92,7 +92,8 @@ masquerade_tg(struct sk_buff *skb, const
 	newrange = ((struct nf_nat_range)
 		{ mr->range[0].flags | IP_NAT_RANGE_MAP_IPS,
 		  newsrc, newsrc,
-		  mr->range[0].min, mr->range[0].max });
+		  { .all = mr->range[0].min.all },
+		  { .all = mr->range[0].max.all } });
 
 	/* Hand modified range to generic setup. */
 	return nf_nat_setup_info(ct, &newrange, IP_NAT_MANIP_SRC);
--- linux-2.6.25/net/ipv4/netfilter/ipt_NETMAP.c	22 Apr 2008 01:38:00 -0000	1.1.1.14
+++ linux-2.6.25/net/ipv4/netfilter/ipt_NETMAP.c	29 Apr 2008 04:14:14 -0000
@@ -67,7 +67,8 @@ netmap_tg(struct sk_buff *skb, const str
 	newrange = ((struct nf_nat_range)
 		{ mr->range[0].flags | IP_NAT_RANGE_MAP_IPS,
 		  new_ip, new_ip,
-		  mr->range[0].min, mr->range[0].max });
+		  { .all = mr->range[0].min.all },
+		  { .all = mr->range[0].max.all } });
 
 	/* Hand modified range to generic setup. */
 	return nf_nat_setup_info(ct, &newrange, HOOK2MANIP(hooknum));
--- linux-2.6.25/net/ipv4/netfilter/ipt_REDIRECT.c	22 Apr 2008 01:38:00 -0000	1.1.1.18
+++ linux-2.6.25/net/ipv4/netfilter/ipt_REDIRECT.c	29 Apr 2008 04:14:14 -0000
@@ -84,7 +84,8 @@ redirect_tg(struct sk_buff *skb, const s
 	newrange = ((struct nf_nat_range)
 		{ mr->range[0].flags | IP_NAT_RANGE_MAP_IPS,
 		  newdst, newdst,
-		  mr->range[0].min, mr->range[0].max });
+		  { .all = mr->range[0].min.all },
+		  { .all = mr->range[0].max.all } });
 
 	/* Hand modified range to generic setup. */
 	return nf_nat_setup_info(ct, &newrange, IP_NAT_MANIP_DST);
--- linux-2.6.25/net/ipv4/netfilter/nf_nat_rule.c	22 Apr 2008 01:38:00 -0000	1.1.1.6
+++ linux-2.6.25/net/ipv4/netfilter/nf_nat_rule.c	29 Apr 2008 04:14:14 -0000
@@ -78,6 +78,7 @@ static unsigned int ipt_snat_target(stru
 	struct nf_conn *ct;
 	enum ip_conntrack_info ctinfo;
 	const struct nf_nat_multi_range_compat *mr = targinfo;
+	struct nf_nat_range newrange;
 
 	NF_CT_ASSERT(hooknum == NF_INET_POST_ROUTING);
 
@@ -88,7 +89,13 @@ static unsigned int ipt_snat_target(stru
 			    ctinfo == IP_CT_RELATED + IP_CT_IS_REPLY));
 	NF_CT_ASSERT(out);
 
-	return nf_nat_setup_info(ct, &mr->range[0], IP_NAT_MANIP_SRC);
+	newrange = ((struct nf_nat_range)
+		{ mr->range[0].flags,
+		  mr->range[0].min_ip, mr->range[0].max_ip,
+		  { .all = mr->range[0].min.all },
+		  { .all = mr->range[0].max.all } });
+
+	return nf_nat_setup_info(ct, &newrange, IP_NAT_MANIP_SRC);
 }
 
 /* Before 2.6.11 we did implicit source NAT if required. Warn about change. */
@@ -120,6 +127,7 @@ static unsigned int ipt_dnat_target(stru
 	struct nf_conn *ct;
 	enum ip_conntrack_info ctinfo;
 	const struct nf_nat_multi_range_compat *mr = targinfo;
+	struct nf_nat_range newrange;
 
 	NF_CT_ASSERT(hooknum == NF_INET_PRE_ROUTING ||
 		     hooknum == NF_INET_LOCAL_OUT);
@@ -134,7 +142,13 @@ static unsigned int ipt_dnat_target(stru
 		warn_if_extra_mangle(ip_hdr(skb)->daddr,
 				     mr->range[0].min_ip);
 
-	return nf_nat_setup_info(ct, &mr->range[0], IP_NAT_MANIP_DST);
+	newrange = ((struct nf_nat_range)
+		{ mr->range[0].flags,
+		  mr->range[0].min_ip, mr->range[0].max_ip,
+		  { .all = mr->range[0].min.all },
+		  { .all = mr->range[0].max.all } });
+
+	return nf_nat_setup_info(ct, &newrange, IP_NAT_MANIP_DST);
 }
 
 static bool ipt_snat_checkentry(const char *tablename,

  reply	other threads:[~2008-04-29  4:48 UTC|newest]

Thread overview: 95+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-30 20:16 [NETFILTER 00/69]: Netfilter Update Patrick McHardy
2008-01-30 20:16 ` [NETFILTER 01/69]: Supress some sparse warnings Patrick McHardy
2008-01-30 20:16 ` [NETFILTER 02/69]: Use const in struct xt_match, xt_target, xt_table Patrick McHardy
2008-01-30 20:16 ` linux/types.h: Use __u64 for aligned_u64 Patrick McHardy
2008-01-30 20:16 ` [NETFILTER 04/69]: nf_nat: remove double bysource hash initialization Patrick McHardy
2008-01-30 20:16 ` [NETFILTER 05/69]: bridge netfilter: remove nf_bridge_info read-only netoutdev member Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 06/69]: nfnetlink_log: fix typo Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 07/69]: xt_conntrack: add port and direction matching Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 08/69]: nf_log: add netfilter gcc printf format checking Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 09/69]: ebtables: remove casts, use consts Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 10/69]: ebtables: Update modules' descriptions Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 11/69]: ebtables: mark matches, targets and watchers __read_mostly Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 12/69]: x_tables: change xt_table_register() return value convention Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 13/69]: x_tables: per-netns xt_tables Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 14/69]: x_tables: return new table from {arp,ip,ip6}t_register_table() Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 15/69]: ip_tables: propagate netns from userspace Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 16/69]: ip_tables: per-netns FILTER, MANGLE, RAW Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 17/69]: ip6_tables: netns preparation Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 18/69]: ip6_tables: per-netns IPv6 FILTER, MANGLE, RAW Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 19/69]: arp_tables: netns preparation Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 20/69]: arp_tables: per-netns arp_tables FILTER Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 21/69]: netns: put table module on netns stop Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 22/69]: xt_TCPMSS: consider reverse route's MTU in clamp-to-pmtu Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 23/69]: xt_owner: allow matching UID/GID ranges Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 24/69]: nf_nat_snmp: sparse warning Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 25/69]: nf_conntrack: sparse warnings Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 26/69]: nfnetlink_log: sparse warning fixes Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 27/69]: conntrack: get rid of sparse warnings Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 28/69]: more sparse fixes Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 29/69]: nf_conntrack_h3223: " Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 30/69]: ipt_recent: fix sparse warnings Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 31/69]: {ip,arp,ip6}_tables: fix sparse warnings in compat code Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 32/69]: nf_conntrack_ipv6: fix sparse warnings Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 33/69]: nf_conntrack_netlink: fix unbalanced locking Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 34/69]: nf_conntrack: fix accounting with fixed timeouts Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 35/69]: nf_conntrack: use RCU for conntrack helpers Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 36/69]: nf_conntrack_core: avoid taking nf_conntrack_lock in nf_conntrack_alter_reply Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 37/69]: nf_conntrack_expect: use RCU for expectation hash Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 38/69]: nf_conntrack: use RCU for conntrack hash Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 39/69]: nf_conntrack: switch rwlock to spinlock Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 40/69]: nf_conntrack: optimize __nf_conntrack_find() Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 41/69]: nf_conntrack: avoid duplicate protocol comparison in nf_ct_tuple_equal() Patrick McHardy
2008-01-30 20:17 ` [NETFILTER 42/69]: nf_conntrack: optimize hash_conntrack() Patrick McHardy
2008-04-28  8:24   ` Philip Craig
2008-04-28 13:59     ` Patrick McHardy
2008-04-29  4:48       ` Philip Craig [this message]
2008-04-29  5:44         ` David Miller
2008-04-29  6:00           ` Philip Craig
2008-04-29  6:14             ` David Miller
2008-04-29  6:50               ` Philip Craig
2008-04-29  6:56                 ` David Miller
2008-04-29  7:00                   ` Philip Craig
2008-04-29  5:44         ` Philip Craig
2008-04-29  5:54           ` Patrick McHardy
2008-04-29  8:40             ` Philip Craig
2008-04-29 10:20               ` David Miller
2008-04-29 10:22                 ` Patrick McHardy
2008-04-29 10:35                   ` David Miller
2008-01-30 20:18 ` [NETFILTER 43/69]: nf_conntrack: reorder struct nf_conntrack_l4proto Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 44/69]: nf_conntrack: don't inline early_drop() Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 45/69]: nf_conntrack: naming unification Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 46/69]: nf_nat: use RCU for bysource hash Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 47/69]: nf_nat: switch rwlock to spinlock Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 48/69]: nf_conntrack_h323: clean up code a bit Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 49/69]: nf_conntrack_netlink: transmit mark during all events Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 50/69]: ipt_CLUSTERIP: kill clusterip_config_entry_get Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 51/69]: nf_conntrack: kill unused static inline (do_iter) Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 52/69]: xt_hashlimit match, revision 1 Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 53/69]: x_tables: semi-rewrite of /proc/net/foo_tables_* Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 54/69]: x_tables: netns propagation for /proc/net/*_tables_names Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 55/69]: x_tables: create per-netns /proc/net/*_tables_* Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 56/69]: nf_conntrack_h323: constify and annotate H.323 helper Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 57/69]: nf_{conntrack,nat}_sip: annotate SIP helper with const Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 58/69]: nf_{conntrack,nat}_tftp: annotate TFTP " Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 59/69]: nf_{conntrack,nat}_pptp: annotate PPtP " Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 60/69]: nf_conntrack_sane: annotate SANE " Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 61/69]: nf_{conntrack,nat}_proto_tcp: constify and annotate TCP modules Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 62/69]: nf_{conntrack,nat}_proto_udp{,lite}: annotate with const Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 63/69]: nf_{conntrack,nat}_proto_gre: " Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 64/69]: nf_{conntrack,nat}_icmp: constify and annotate Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 65/69]: nf_conntrack: annotate l3protos with const Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 66/69]: {ip,ip6}_queue: fix build error Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 67/69]: nf_conntrack: fix sparse warning Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 68/69]: nf_nat: " Patrick McHardy
2008-01-30 20:18 ` [NETFILTER 69/69]: xt_iprange: fix sparse warnings Patrick McHardy
2008-01-30 20:20 ` [NETFILTER 00/69]: Netfilter Update Jan Engelhardt
2008-01-30 20:22   ` Patrick McHardy
2008-01-30 20:26     ` Jan Engelhardt
2008-01-30 20:55 ` Jan Engelhardt
2008-01-30 21:27   ` Patrick McHardy
2008-01-30 21:30     ` Jan Engelhardt
2008-01-30 21:31       ` Patrick McHardy
2008-01-30 21:34     ` Patrick McHardy
2008-01-31  0:54   ` David Miller
2008-01-31 12:56 ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4816A89B.7050300@snapgear.com \
    --to=philipc@snapgear.com \
    --cc=davem@davemloft.net \
    --cc=kaber@trash.net \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=rmk@arm.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.