diff mbox series

[net-next,v2,12/12] gtp: add dst_cache to tunnels

Message ID 20201211122612.869225-13-jonas@norrbonn.se (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series gtp: IPv6 support | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 87 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Jonas Bonn Dec. 11, 2020, 12:26 p.m. UTC
Destination caching on a per-tunnel basis is a performance win, so we
enable this unconditionally for the module.

Signed-off-by: Jonas Bonn <jonas@norrbonn.se>
---
 drivers/net/Kconfig |  1 +
 drivers/net/gtp.c   | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)

Comments

kernel test robot Dec. 11, 2020, 5:25 p.m. UTC | #1
Hi Jonas,

I love your patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Jonas-Bonn/gtp-IPv6-support/20201211-203639
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 91163f82143630a9629a8bf0227d49173697c69c
config: mips-randconfig-r026-20201209 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 5ff35356f1af2bb92785b38c657463924d9ec386)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install mips cross compiling tool for clang build
        # apt-get install binutils-mips-linux-gnu
        # https://github.com/0day-ci/linux/commit/a8ea47bc0c1903be018f4d566bb96146c156ddce
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Jonas-Bonn/gtp-IPv6-support/20201211-203639
        git checkout a8ea47bc0c1903be018f4d566bb96146c156ddce
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=mips 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

   drivers/net/gtp.c:471:2: warning: variable 'err' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (!ptype)
           ^~~~~~~~~~~
   include/linux/compiler.h:56:28: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:58:30: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/net/gtp.c:482:9: note: uninitialized use occurs here
           return err;
                  ^~~
   drivers/net/gtp.c:471:2: note: remove the 'if' if its condition is always false
           if (!ptype)
           ^~~~~~~~~~~
   include/linux/compiler.h:56:23: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                         ^
   drivers/net/gtp.c:465:2: warning: variable 'err' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
           default:
           ^~~~~~~
   drivers/net/gtp.c:482:9: note: uninitialized use occurs here
           return err;
                  ^~~
   drivers/net/gtp.c:441:9: note: initialize the variable 'err' to silence this warning
           int err;
                  ^
                   = 0
>> drivers/net/gtp.c:627:8: error: implicit declaration of function 'dst_cache_get_ip6' [-Werror,-Wimplicit-function-declaration]
           dst = dst_cache_get_ip6(dst_cache, saddr);
                 ^
   drivers/net/gtp.c:627:8: note: did you mean 'dst_cache_get_ip4'?
   include/net/dst_cache.h:33:16: note: 'dst_cache_get_ip4' declared here
   struct rtable *dst_cache_get_ip4(struct dst_cache *dst_cache, __be32 *saddr);
                  ^
>> drivers/net/gtp.c:627:6: warning: incompatible integer to pointer conversion assigning to 'struct dst_entry *' from 'int' [-Wint-conversion]
           dst = dst_cache_get_ip6(dst_cache, saddr);
               ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/net/gtp.c:649:2: error: implicit declaration of function 'dst_cache_set_ip6' [-Werror,-Wimplicit-function-declaration]
           dst_cache_set_ip6(dst_cache, dst, saddr);
           ^
   3 warnings and 2 errors generated.

vim +/dst_cache_get_ip6 +627 drivers/net/gtp.c

   615	
   616	static struct dst_entry *gtp_get_v6_dst(struct sk_buff *skb,
   617						struct net_device *dev,
   618						struct pdp_ctx *pctx,
   619						struct in6_addr *saddr)
   620	{
   621		const struct sock *sk = pctx->sk;
   622		struct dst_entry *dst = NULL;
   623		struct dst_cache *dst_cache;
   624		struct flowi6 fl6;
   625	
   626		dst_cache = (struct dst_cache *)&pctx->dst_cache;
 > 627		dst = dst_cache_get_ip6(dst_cache, saddr);
   628		if (dst)
   629			return dst;
   630	
   631		memset(&fl6, 0, sizeof(fl6));
   632		fl6.flowi6_mark = skb->mark;
   633		fl6.flowi6_proto = IPPROTO_UDP;
   634		fl6.daddr = pctx->peer_addr;
   635	
   636		dst = ipv6_stub->ipv6_dst_lookup_flow(sock_net(sk), sk, &fl6, NULL);
   637		if (IS_ERR(dst)) {
   638			netdev_dbg(pctx->dev, "no route to %pI6\n", &fl6.daddr);
   639			return ERR_PTR(-ENETUNREACH);
   640		}
   641		if (dst->dev == pctx->dev) {
   642			netdev_dbg(pctx->dev, "circular route to %pI6\n", &fl6.daddr);
   643			dst_release(dst);
   644			return ERR_PTR(-ELOOP);
   645		}
   646	
   647		*saddr = fl6.saddr;
   648	
 > 649		dst_cache_set_ip6(dst_cache, dst, saddr);
   650	
   651		return dst;
   652	}
   653	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 260f9f46668b..f79277222125 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -276,6 +276,7 @@  config GTP
 	tristate "GPRS Tunneling Protocol datapath (GTP-U)"
 	depends on INET
 	select NET_UDP_TUNNEL
+	select DST_CACHE
 	help
 	  This allows one to create gtp virtual interfaces that provide
 	  the GPRS Tunneling Protocol datapath (GTP-U). This tunneling protocol
diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c
index 40bbbe8cfad6..6708738681d2 100644
--- a/drivers/net/gtp.c
+++ b/drivers/net/gtp.c
@@ -64,6 +64,8 @@  struct pdp_ctx {
 	struct sock		*sk;
 	struct net_device       *dev;
 
+	struct dst_cache dst_cache;
+
 	atomic_t		tx_seq;
 	struct rcu_head		rcu_head;
 };
@@ -577,9 +579,15 @@  static struct rtable *gtp_get_v4_rt(struct sk_buff *skb,
 				    __be32 *saddr)
 {
 	const struct sock *sk = pctx->sk;
+	struct dst_cache *dst_cache;
 	struct rtable *rt = NULL;
 	struct flowi4 fl4;
 
+	dst_cache = (struct dst_cache *)&pctx->dst_cache;
+	rt = dst_cache_get_ip4(dst_cache, saddr);
+	if (rt)
+		return rt;
+
 	memset(&fl4, 0, sizeof(fl4));
 	fl4.flowi4_oif		= sk->sk_bound_dev_if;
 	fl4.daddr		= ipv4(&pctx->peer_addr);
@@ -600,6 +608,8 @@  static struct rtable *gtp_get_v4_rt(struct sk_buff *skb,
 
 	*saddr = fl4.saddr;
 
+	dst_cache_set_ip4(dst_cache, &rt->dst, *saddr);
+
 	return rt;
 }
 
@@ -610,8 +620,14 @@  static struct dst_entry *gtp_get_v6_dst(struct sk_buff *skb,
 {
 	const struct sock *sk = pctx->sk;
 	struct dst_entry *dst = NULL;
+	struct dst_cache *dst_cache;
 	struct flowi6 fl6;
 
+	dst_cache = (struct dst_cache *)&pctx->dst_cache;
+	dst = dst_cache_get_ip6(dst_cache, saddr);
+	if (dst)
+		return dst;
+
 	memset(&fl6, 0, sizeof(fl6));
 	fl6.flowi6_mark = skb->mark;
 	fl6.flowi6_proto = IPPROTO_UDP;
@@ -630,6 +646,8 @@  static struct dst_entry *gtp_get_v6_dst(struct sk_buff *skb,
 
 	*saddr = fl6.saddr;
 
+	dst_cache_set_ip6(dst_cache, dst, saddr);
+
 	return dst;
 }
 
@@ -1236,6 +1254,8 @@  static void pdp_fill(struct pdp_ctx *pctx, struct genl_info *info)
 	pctx->gtp_version = nla_get_u32(info->attrs[GTPA_VERSION]);
 	pctx->flags = 0;
 
+	dst_cache_reset(&pctx->dst_cache);
+
 	if (info->attrs[GTPA_PEER_IPV6]) {
 		pctx->flags |= PDP_F_PEER_V6;
 		pctx->peer_addr = nla_get_in6_addr(info->attrs[GTPA_PEER_IPV6]);
@@ -1331,6 +1351,11 @@  static struct pdp_ctx *gtp_pdp_add(struct gtp_dev *gtp, struct sock *sk,
 	if (pctx == NULL)
 		return ERR_PTR(-ENOMEM);
 
+	if (dst_cache_init(&pctx->dst_cache, GFP_ATOMIC)) {
+		kfree(pctx);
+		return ERR_PTR(-ENOBUFS);
+	}
+
 	sock_hold(sk);
 	pctx->sk = sk;
 	pctx->dev = gtp->dev;
@@ -1374,6 +1399,8 @@  static void pdp_context_free(struct rcu_head *head)
 {
 	struct pdp_ctx *pctx = container_of(head, struct pdp_ctx, rcu_head);
 
+	dst_cache_destroy(&pctx->dst_cache);
+
 	sock_put(pctx->sk);
 	kfree(pctx);
 }