UPSTREAM: xfrm: Remove xfrmi interface ID from flowi
authorBenedict Wong <benedictwong@google.com>
Thu, 19 Jul 2018 17:50:44 +0000 (10:50 -0700)
committerxiest1 <xiest1@lenovo.com>
Tue, 5 Nov 2019 09:32:14 +0000 (17:32 +0800)
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 Defenderault 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

Signed-off-by: Benedict Wong <benedictwong@google.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
(cherry picked from commit bc56b33404599edc412b91933d74b36873e8ea25)
Bug: 113046120
Change-Id: Icd3a1ea08427b91c54a64318d9dbb9acfb5d429a

include/net/flow.h
net/xfrm/xfrm_policy.c
net/xfrm/xfrm_state.c

index 6c2272213a6b6cdcdbbf0e58e6057b1883b56ec5..f1624fd5b1d03630c09f34106ba4aa2de45d7e5c 100644 (file)
@@ -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.xfrm
        struct 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)
index 1ca20fa8e001052576aa502ba5152cf605715e1b..7fc1b252317de4f42e45092ace7ddde4efa48ba5 100644 (file)
@@ -2418,8 +2418,6 @@ int __xfrm_decode_session(struct sk_buff *skb, struct flowi *fl,
                          unsigned int family, int reverse)
 {
        const struct xfrm_policy_afinfo *afinfo = xfrm_policy_get_afinfo(family);
-       const struct xfrm_if_cb *ifcb = xfrm_if_get_cb();
-       struct xfrm_if *xi;
        int err;
 
        if (unlikely(afinfo == NULL))
index ebdbce2703ce511f4d37287675b1287233fd65a0..7fbe478f83ca4adc6ffca52eb23610feca0a4c32 100644 (file)
@@ -941,7 +941,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;