xfrm: Remove xfrmi interface ID from flowi
Subsystems (3)
PATCH 1/1 xfrm: Remove xfrmi interface ID from flowi
In order to remove performance impact of having the extra u32 in every single flowi, this change removes the flowi_xfrm struct, prefering to take the if_id as a method parameter where needed.
In the inbound direction, if_id is only needed during the __xfrm_check_policy() function, and the if_id can be determined at that point based on the skb. As such, xfrmi_decode_session() is only called with the skb in __xfrm_check_policy().
In the outbound direction, the only place where if_id is needed is the xfrm_lookup() call in xfrmi_xmit2(). With this change, the if_id is directly passed into the xfrm_lookup_with_ifid() call. All existing callers can still call xfrm_lookup(), which uses a default if_id of 0.
This change does not change any behavior of XFRMIs except for improving overall system performance via flowi size reduction.
This change has been tested against the Android Kernel Networking Tests:
https://android.googlesource.com/kernel/tests/+/master/net/test
--- include/net/dst.h | 14 ++++++ include/net/flow.h | 9 ---- include/net/xfrm.h | 2 +- net/xfrm/xfrm_interface.c | 4 +- net/xfrm/xfrm_policy.c | 98 ++++++++++++++++++++++++++------------- net/xfrm/xfrm_state.c | 3 +- 6 files changed, 83 insertions(+), 47 deletions(-)
include/net/dst.h +14 -0
@@ -475,6 +475,14 @@ static inline struct dst_entry *xfrm_lookup(struct net *net,return dst_orig; } +static inline struct dst_entry * +xfrm_lookup_with_ifid (struct net *net,struct dst_entry *dst_orig, +const struct flowi *fl,const struct sock *sk, +int flags,u32 if_id) +{ +return dst_orig; +} + static inline struct dst_entry *xfrm_lookup_route(struct net *net, struct dst_entry *dst_orig, const struct flowi *fl,
@@ -494,6 +502,12 @@ struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig, const struct flowi *fl, const struct sock *sk, int flags); +struct dst_entry *xfrm_lookup_with_ifid (struct net *net, +struct dst_entry *dst_orig, +const struct flowi *fl, +const struct sock *sk,int flags, +u32 if_id); +struct dst_entry *xfrm_lookup_route (struct net *net,struct dst_entry *dst_orig,const struct flowi *fl,const struct sock *sk,int flags);
include/net/flow.h +0 -9
@@ -26,10 +26,6 @@ struct flowi_tunnel {__be64 tun_id; }; -struct flowi_xfrm { -__u32 if_id; -}; -struct flowi_common {int flowic_oif;int flowic_iif;
@@ -43,7 +39,6 @@ struct flowi_common {#define FLOWI_FLAG_SKIP_NH_OIF 0x04__u32 flowic_secid;struct flowi_tunnel flowic_tun_key; -struct flowi_xfrm xfrm;kuid_t flowic_uid; };
@@ -83,7 +78,6 @@ struct flowi4 {#define flowi4_secid __fl_common.flowic_secid#define flowi4_tun_key __fl_common.flowic_tun_key#define flowi4_uid __fl_common.flowic_uid -#define flowi4_xfrm __fl_common.xfrm/* (saddr,daddr) must be grouped, same order as in IP header */ __be32 saddr;
@@ -115,7 +109,6 @@ static inline void flowi4_init_output(struct flowi4 *fl4, int oif, fl4->flowi4_flags = flags; fl4->flowi4_secid =0 ; fl4->flowi4_tun_key.tun_id =0 ; - fl4->flowi4_xfrm.if_id =0 ; fl4->flowi4_uid = uid; fl4->daddr = daddr; fl4->saddr = saddr;
@@ -145,7 +138,6 @@ struct flowi6 {#define flowi6_secid __fl_common.flowic_secid#define flowi6_tun_key __fl_common.flowic_tun_key#define flowi6_uid __fl_common.flowic_uid -#define flowi6_xfrm __fl_common.xfrmstruct in6_addr daddr;struct in6_addr saddr;/* Note: flowi6_tos is encoded in flowlabel, too. */
@@ -193,7 +185,6 @@ struct flowi {#define flowi_secid u.__fl_common.flowic_secid#define flowi_tun_key u.__fl_common.flowic_tun_key#define flowi_uid u.__fl_common.flowic_uid -#define flowi_xfrm u.__fl_common.xfrm } __attribute__((__aligned__(BITS_PER_LONG/8)));static inline struct flowi *flowi4_to_flowi (struct flowi4 *fl4)
include/net/xfrm.h +1 -1
@@ -1557,7 +1557,7 @@ struct xfrm_state *xfrm_state_find(const xfrm_address_t *daddr,const struct flowi *fl, struct xfrm_tmpl *tmpl, struct xfrm_policy *pol, int *err, - unsigned short family); + unsigned short family, u32 if_id); struct xfrm_state *xfrm_stateonly_find(struct net *net, u32 mark, u32 if_id, xfrm_address_t *daddr, xfrm_address_t *saddr,
net/xfrm/xfrm_interface.c +1 -3
@@ -307,10 +307,8 @@ xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)if (!dst) goto tx_err_link_failure; - fl->flowi_xfrm.if_id = xi->p.if_id; -dst_hold (dst); - dst =xfrm_lookup (xi->net, dst, fl,NULL ,0 ); + dst =xfrm_lookup_with_ifid (xi->net, dst, fl,NULL ,0 , xi->p.if_id);if (IS_ERR (dst)) { err =PTR_ERR (dst); dst =NULL ;
net/xfrm/xfrm_policy.c +66 -32
238 lines not on this page · raw message
net/xfrm/xfrm_state.c +1 -2
@@ -930,7 +930,7 @@ struct xfrm_state * xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr, const struct flowi *fl, struct xfrm_tmpl *tmpl, struct xfrm_policy *pol, int *err, - unsigned short family) + unsigned short family, u32 if_id) { static xfrm_address_t saddr_wildcard = { };struct net *net =xp_net (pol);
@@ -940,7 +940,6 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,int error =0 ;struct xfrm_state *best =NULL ;u32 mark = pol->mark.v & pol->mark.m; -u32 if_id = fl->flowi_xfrm.if_id;unsigned short encap_family = tmpl->encap_family;unsigned int sequence;struct km_event c;
Signature · 1 line
2.18.0.233.g985f88cf7e-goog
Steffen Klassert
maintainerQuoted 14 lines · Benedict Wong
In order to remove performance impact of having the extra u32 in every single flowi, this change removes the
flowi_xfrmstruct, prefering to take theif_idas a method parameter where needed.In the inbound direction,
if_idis only needed during the__xfrm_check_policy()function, and theif_idcan be determined at that point based on the skb. As such,xfrmi_decode_session()is only called with the skb in__xfrm_check_policy().In the outbound direction, the only place where
if_idis needed is thexfrm_lookup()call inxfrmi_xmit2(). With this change, theif_idis directly passed into thexfrm_lookup_with_ifid()call. All existing callers can still callxfrm_lookup(), which uses a defaultif_idof 0.
Quoted 8 lines
This change does not change any behavior of XFRMIs except for improving overall system performance via flowi size reduction.
This change has been tested against the Android Kernel Networking Tests:
https://android.googlesource.com/kernel/tests/+/master/net/test
Signed-off-by Benedict Wong <[email protected]>
Nice improvement. Applied to ipsec-next, thanks a lot!