From patchwork Tue Jun 18 18:25:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Wang X-Patchwork-Id: 1118276 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lqXtaVqs"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45SxNs1dbzz9s3C for ; Wed, 19 Jun 2019 04:26:21 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730318AbfFRS0U (ORCPT ); Tue, 18 Jun 2019 14:26:20 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:45336 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727616AbfFRS0T (ORCPT ); Tue, 18 Jun 2019 14:26:19 -0400 Received: by mail-pg1-f195.google.com with SMTP id s21so8117641pga.12 for ; Tue, 18 Jun 2019 11:26:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6K7yZXHFPP2wKshtf+TUy7FQS3tnc0HHzK+82UP50PA=; b=lqXtaVqskpXJrCMMHLnWkZUbZYWXxP/ZEpyJye3+ZWyEXBNxtYuS33hfcfXv/srit0 gc0SGMRR4YGUVUWjtYm+Mz/ITnaT1Rwz1nHzJaMsBAADHLHv44cIeXkfgmfPG+Rx7y0K WMr42NYOAt59OjtezAFzbq1gRHczcgMh0QgiKwiQXcUVQV8BxhRLGlYcYRjo0fHoJM85 8aQs3NyfvzNBS82J3TQ5o9vbytZpuC1ceFPPx4jbRz+EMo5xnAG7yy5eHnxQNHm/ODJp bZLKF2u7w5avMYrh0uqlteEv2kn9soEXcGYW6A2Rmwm/hBSa7ogJ6Q6e4y2oQKJwpqvs +YsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6K7yZXHFPP2wKshtf+TUy7FQS3tnc0HHzK+82UP50PA=; b=kel/dNE1MW/nihByJ+HAMRtCrP9FxCxIQE6HTS2Q4Ti0YMMm/pqTMs4OqcsjGoLpWV 50tanSf4wV54ggLJry7y8H5b6nE4V4h0/ZeN8xTusuoCmxewauSMalwdbHKwx/AyC7KU HORFWtlaArR4BG4S9C38hsatGnC923e/CSLvBWOv4NZJakkPLTnn1SfB7VIY3P0GooSu DYRzb8jiVvw5goLUdWBOw9RAvkJ9gtybLbriFuXvSyXrk+lK4BaIwA17JwvC7J8Br1hD 7K7oFjF8sQzbstnAy3JsEbo48kRXuywoiDrtvw5zSf4Y/cKZeRp0d7ppdRH7RAiJtjss C82w== X-Gm-Message-State: APjAAAWh7k6yyztoJZC7e0tY5SPBk7qLs+LRK0koQkpcxXANo9CKwV4j DQRQAImRtmcaqc6qM4i7uYg= X-Google-Smtp-Source: APXvYqy1io5jxM08SceGiB7bjhfzxw68/F708FZr9qQWj47fSLXarv0JIBeakOfoyQOjEbPMtNMjzg== X-Received: by 2002:a63:2a0f:: with SMTP id q15mr3979356pgq.163.1560882379120; Tue, 18 Jun 2019 11:26:19 -0700 (PDT) Received: from weiwan0.svl.corp.google.com ([2620:15c:2c4:201:9310:64cb:677b:dcba]) by smtp.gmail.com with ESMTPSA id h6sm2845859pjs.2.2019.06.18.11.26.18 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 18 Jun 2019 11:26:18 -0700 (PDT) From: Wei Wang To: David Miller , netdev@vger.kernel.org Cc: Martin KaFai Lau , Eric Dumazet , Mahesh Bandewar , David Ahern , Wei Wang Subject: [PATCH net-next 1/5] ipv6: introduce RT6_LOOKUP_F_DST_NOREF flag in ip6_pol_route() Date: Tue, 18 Jun 2019 11:25:39 -0700 Message-Id: <20190618182543.65477-2-tracywwnj@gmail.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190618182543.65477-1-tracywwnj@gmail.com> References: <20190618182543.65477-1-tracywwnj@gmail.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Wei Wang This new flag is to instruct the route lookup function to not take refcnt on the dst entry. The user which does route lookup with this flag must properly use rcu protection. ip6_pol_route() is the major route lookup function for both tx and rx path. In this function: Do not take refcnt on dst if RT6_LOOKUP_F_DST_NOREF flag is set, and directly return the route entry. The caller should be holding rcu lock when using this flag, and decide whether to take refcnt or not. One note on the dst cache in the uncached_list: As uncached_list does not consume refcnt, one refcnt is always returned back to the caller even if RT6_LOOKUP_F_DST_NOREF flag is set. Uncached dst is only possible in the output path. So in such call path, caller MUST check if the dst is in the uncached_list before assuming that there is no refcnt taken on the returned dst. Signed-off-by: Wei Wang Acked-by: Eric Dumazet Acked-by: Mahesh Bandewar --- include/net/ip6_route.h | 1 + net/ipv6/route.c | 73 +++++++++++++++++------------------------ 2 files changed, 31 insertions(+), 43 deletions(-) diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h index 7375a165fd98..82bced2fc1e3 100644 --- a/include/net/ip6_route.h +++ b/include/net/ip6_route.h @@ -36,6 +36,7 @@ struct route_info { #define RT6_LOOKUP_F_SRCPREF_PUBLIC 0x00000010 #define RT6_LOOKUP_F_SRCPREF_COA 0x00000020 #define RT6_LOOKUP_F_IGNORE_LINKSTATE 0x00000040 +#define RT6_LOOKUP_F_DST_NOREF 0x00000080 /* We do not (yet ?) support IPv6 jumbograms (RFC 2675) * Unlike IPv4, hdr->seg_len doesn't include the IPv6 header diff --git a/net/ipv6/route.c b/net/ipv6/route.c index c4d285fe0adc..9dcbc56e4151 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -1391,9 +1391,6 @@ static struct rt6_info *rt6_get_pcpu_route(const struct fib6_result *res) pcpu_rt = this_cpu_read(*res->nh->rt6i_pcpu); - if (pcpu_rt) - ip6_hold_safe(NULL, &pcpu_rt); - return pcpu_rt; } @@ -1403,12 +1400,9 @@ static struct rt6_info *rt6_make_pcpu_route(struct net *net, struct rt6_info *pcpu_rt, *prev, **p; pcpu_rt = ip6_rt_pcpu_alloc(res); - if (!pcpu_rt) { - dst_hold(&net->ipv6.ip6_null_entry->dst); - return net->ipv6.ip6_null_entry; - } + if (!pcpu_rt) + return NULL; - dst_hold(&pcpu_rt->dst); p = this_cpu_ptr(res->nh->rt6i_pcpu); prev = cmpxchg(p, NULL, pcpu_rt); BUG_ON(prev); @@ -2189,9 +2183,12 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table, const struct sk_buff *skb, int flags) { struct fib6_result res = {}; - struct rt6_info *rt; + struct rt6_info *rt = NULL; int strict = 0; + WARN_ON_ONCE((flags & RT6_LOOKUP_F_DST_NOREF) && + !rcu_read_lock_held()); + strict |= flags & RT6_LOOKUP_F_IFACE; strict |= flags & RT6_LOOKUP_F_IGNORE_LINKSTATE; if (net->ipv6.devconf_all->forwarding == 0) @@ -2200,23 +2197,15 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table, rcu_read_lock(); fib6_table_lookup(net, table, oif, fl6, &res, strict); - if (res.f6i == net->ipv6.fib6_null_entry) { - rt = net->ipv6.ip6_null_entry; - rcu_read_unlock(); - dst_hold(&rt->dst); - return rt; - } + if (res.f6i == net->ipv6.fib6_null_entry) + goto out; fib6_select_path(net, &res, fl6, oif, false, skb, strict); /*Search through exception table */ rt = rt6_find_cached_rt(&res, &fl6->daddr, &fl6->saddr); if (rt) { - if (ip6_hold_safe(net, &rt)) - dst_use_noref(&rt->dst, jiffies); - - rcu_read_unlock(); - return rt; + goto out; } else if (unlikely((fl6->flowi6_flags & FLOWI_FLAG_KNOWN_NH) && !res.nh->fib_nh_gw_family)) { /* Create a RTF_CACHE clone which will not be @@ -2224,40 +2213,38 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table, * the daddr in the skb during the neighbor look-up is different * from the fl6->daddr used to look-up route here. */ - struct rt6_info *uncached_rt; + rt = ip6_rt_cache_alloc(&res, &fl6->daddr, NULL); - uncached_rt = ip6_rt_cache_alloc(&res, &fl6->daddr, NULL); - - rcu_read_unlock(); - - if (uncached_rt) { - /* Uncached_rt's refcnt is taken during ip6_rt_cache_alloc() - * No need for another dst_hold() + if (rt) { + /* 1 refcnt is taken during ip6_rt_cache_alloc(). + * As rt6_uncached_list_add() does not consume refcnt, + * this refcnt is always returned to the caller even + * if caller sets RT6_LOOKUP_F_DST_NOREF flag. */ - rt6_uncached_list_add(uncached_rt); + rt6_uncached_list_add(rt); atomic_inc(&net->ipv6.rt6_stats->fib_rt_uncache); - } else { - uncached_rt = net->ipv6.ip6_null_entry; - dst_hold(&uncached_rt->dst); - } + rcu_read_unlock(); - return uncached_rt; + return rt; + } } else { /* Get a percpu copy */ - - struct rt6_info *pcpu_rt; - local_bh_disable(); - pcpu_rt = rt6_get_pcpu_route(&res); + rt = rt6_get_pcpu_route(&res); - if (!pcpu_rt) - pcpu_rt = rt6_make_pcpu_route(net, &res); + if (!rt) + rt = rt6_make_pcpu_route(net, &res); local_bh_enable(); - rcu_read_unlock(); - - return pcpu_rt; } +out: + if (!rt) + rt = net->ipv6.ip6_null_entry; + if (!(flags & RT6_LOOKUP_F_DST_NOREF)) + ip6_hold_safe(net, &rt); + rcu_read_unlock(); + + return rt; } EXPORT_SYMBOL_GPL(ip6_pol_route); From patchwork Tue Jun 18 18:25:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Wang X-Patchwork-Id: 1118277 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="dd/okHKQ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45SxNw1J6bz9s3C for ; Wed, 19 Jun 2019 04:26:24 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730248AbfFRS0X (ORCPT ); Tue, 18 Jun 2019 14:26:23 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:45294 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727616AbfFRS0W (ORCPT ); Tue, 18 Jun 2019 14:26:22 -0400 Received: by mail-pf1-f196.google.com with SMTP id r1so8131181pfq.12 for ; Tue, 18 Jun 2019 11:26:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZBRiDHj2Qi4Q8hZbrg7ij7OVMKRMOh5DuaaYEMelFvk=; b=dd/okHKQEJK9fBmiN+68X/nPxl70q4G6aY7miQDoqqYPfD2EdADjMYQlW0+TCeETxV nO4IJ5E6qnLbYgbSKltfIKoLmO8CMxV11Tw5Y+yW0SYoTBiNhkIdv0Qs74V0aWXVaxRf n5Il1suFZlPUcjvZlQovqvxo/fiagTr4TjCunDAWNDa9z8YGQQMvjrchkRc17ZKt3zrB S0gJS2f7v3Fxm8UNX0xqUrA+GZAY3qBwe0tMt2DBh7jjV7Ocf5RpMI24hnXcuzKE9jb7 ey/isAZYF5eQgWYAbiO7X+jdFq0+e2Qd6GNCiXsNvWb8kZ4T96SQKk69y2nH2ek7fL5Z DIBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZBRiDHj2Qi4Q8hZbrg7ij7OVMKRMOh5DuaaYEMelFvk=; b=O1r89EUZIabYhBJLKyHzffl835ssxDDRk5GxRgBwQ4ACnaryCczk9yCYu3PpB4bg1Z OqC4Pyqi5yo5uEbz5SfHvs0WU5ayEuKfoWjBAlegD5/1GMl0gef/EuMaFYuTrsj7H6SB h3wYP8hBHkskgByMmuvVsYjcnweQtd5+4UxL1rB0ys2ZZaoFnQ2HRAqw9zkPTmoWCE0i aZrG6x6xde0Rs9Yc0yiIjl8JCtKoVcfgfYOB2Yriv5UzsVR2fkCxGhTigefdu4/ya3zU VwQPrm4iveU9wFfZdO5JVWWTfNlbZlN6D/B91Nzi2gaRr8CbkQSfuDoktz98rKk6N7hC 241Q== X-Gm-Message-State: APjAAAX2RpVIyXPIj/3qbuqyeml3eyrcWFJNLX1e6FDGLxhoTl4bCWdw ry4FJxj0AweBrq/oddItZ44= X-Google-Smtp-Source: APXvYqwFNm1wbbiSmKs/akJGfM8rbTKsg7B9ZM0jQ+LN5/9ZdlLN8vtetk3liHp64j98WYef7a86+Q== X-Received: by 2002:a63:e14:: with SMTP id d20mr3930438pgl.264.1560882382112; Tue, 18 Jun 2019 11:26:22 -0700 (PDT) Received: from weiwan0.svl.corp.google.com ([2620:15c:2c4:201:9310:64cb:677b:dcba]) by smtp.gmail.com with ESMTPSA id h6sm2845859pjs.2.2019.06.18.11.26.21 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 18 Jun 2019 11:26:21 -0700 (PDT) From: Wei Wang To: David Miller , netdev@vger.kernel.org Cc: Martin KaFai Lau , Eric Dumazet , Mahesh Bandewar , David Ahern , Wei Wang Subject: [PATCH net-next 2/5] ipv6: initialize rt6->rt6i_uncached in all pre-allocated dst entries Date: Tue, 18 Jun 2019 11:25:40 -0700 Message-Id: <20190618182543.65477-3-tracywwnj@gmail.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190618182543.65477-1-tracywwnj@gmail.com> References: <20190618182543.65477-1-tracywwnj@gmail.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Wei Wang Initialize rt6->rt6i_uncached on the following pre-allocated dsts: net->ipv6.ip6_null_entry net->ipv6.ip6_prohibit_entry net->ipv6.ip6_blk_hole_entry This is a preparation patch for later commits to be able to distinguish dst entries in uncached list by doing: !list_empty(rt6->rt6i_uncached) Signed-off-by: Wei Wang Acked-by: Eric Dumazet Acked-by: Mahesh Bandewar --- net/ipv6/route.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 9dcbc56e4151..33dc8af9a4bf 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -6010,6 +6010,7 @@ static int __net_init ip6_route_net_init(struct net *net) net->ipv6.ip6_null_entry->dst.ops = &net->ipv6.ip6_dst_ops; dst_init_metrics(&net->ipv6.ip6_null_entry->dst, ip6_template_metrics, true); + INIT_LIST_HEAD(&net->ipv6.ip6_null_entry->rt6i_uncached); #ifdef CONFIG_IPV6_MULTIPLE_TABLES net->ipv6.fib6_has_custom_rules = false; @@ -6021,6 +6022,7 @@ static int __net_init ip6_route_net_init(struct net *net) net->ipv6.ip6_prohibit_entry->dst.ops = &net->ipv6.ip6_dst_ops; dst_init_metrics(&net->ipv6.ip6_prohibit_entry->dst, ip6_template_metrics, true); + INIT_LIST_HEAD(&net->ipv6.ip6_prohibit_entry->rt6i_uncached); net->ipv6.ip6_blk_hole_entry = kmemdup(&ip6_blk_hole_entry_template, sizeof(*net->ipv6.ip6_blk_hole_entry), @@ -6030,6 +6032,7 @@ static int __net_init ip6_route_net_init(struct net *net) net->ipv6.ip6_blk_hole_entry->dst.ops = &net->ipv6.ip6_dst_ops; dst_init_metrics(&net->ipv6.ip6_blk_hole_entry->dst, ip6_template_metrics, true); + INIT_LIST_HEAD(&net->ipv6.ip6_blk_hole_entry->rt6i_uncached); #endif net->ipv6.sysctl.flush_delay = 0; From patchwork Tue Jun 18 18:25:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Wang X-Patchwork-Id: 1118278 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Qq4NCp6D"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45SxNy1hm9z9s3C for ; Wed, 19 Jun 2019 04:26:26 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730321AbfFRS0Z (ORCPT ); Tue, 18 Jun 2019 14:26:25 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:45625 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727616AbfFRS0Y (ORCPT ); Tue, 18 Jun 2019 14:26:24 -0400 Received: by mail-pl1-f194.google.com with SMTP id bi6so6037512plb.12 for ; Tue, 18 Jun 2019 11:26:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KZfn7NbJ04uTddCXuYKWyb5rgFZ6AjmZM0F8GgNTxFM=; b=Qq4NCp6Dc2YYF/+3mWlep94OvEJJYVemx3i9A5v3zFi/CIzMMTW9Za0FVn0BY9I0aM PdX3KiIcG7e/Feh+WD3Vm6igPVxjAUSzF25zkio7FM5YUZ8ZkEbHweQxLahLW4ZsC19L /c70BkGQIA7FraoWkhetGsQG0OKgwJ6e7Bb3BUc+pRYL6orLMgkE5sE7yroCvqK/MRM+ 0iwVqWnd4T0f7UcazyUgTDkwyKsKkZf8KFKG6o29zHICViSz72G4oAKN3mVEEElowHcx piSX02fgviqk4uxOSxV2JtqfDjjlbS1v5RZ+U4JFHlbWA0KomDKrAgPX5SyYRvWSWhTm jlYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KZfn7NbJ04uTddCXuYKWyb5rgFZ6AjmZM0F8GgNTxFM=; b=f0sna8apSKc+G4PVdSwDNGyjf/y9YvH/cKxWufjpj6CXKYOX3V131qbapMGzdYl1l+ PT8UY0UJ46VGvcu+PbbiXkU8YCFinLjAB1yB01Kh5Qr/b5zSDyr2vI/gDJMrFxO9XvTE xX3eGOaiULkbtnom4Cin0APM2JjLcrroa5lBEt5F8rxSBAMfJDQgmio4JaGtGosTrsW+ L8izqlEctPZxDDWjrYBHYVBA4nYtTaPtqjz84kXA8OzRE6JvAXUJN1T42/6t03E+XzS/ XXcXjJ1TJZAK3rXr/4McCqZnAmw1HapiDfAmuG07jV/uPweQg1alXblyhcDHSSTtB26f y+/Q== X-Gm-Message-State: APjAAAU8BoC4wsnIRHkUOG8cm1gtgcOP8ncgZfIh+N848g03fQfpbeEl j3jDGw/4ZGqDI8pdWwUuHUM= X-Google-Smtp-Source: APXvYqzUKQa+1J6LnWRJBz5+gcw2CUmhebn4DN3Z4PgSnDAd9Hrhxy6fp3Bt2I8gkKTM5GPrccckZw== X-Received: by 2002:a17:902:8489:: with SMTP id c9mr35169074plo.327.1560882384028; Tue, 18 Jun 2019 11:26:24 -0700 (PDT) Received: from weiwan0.svl.corp.google.com ([2620:15c:2c4:201:9310:64cb:677b:dcba]) by smtp.gmail.com with ESMTPSA id h6sm2845859pjs.2.2019.06.18.11.26.23 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 18 Jun 2019 11:26:23 -0700 (PDT) From: Wei Wang To: David Miller , netdev@vger.kernel.org Cc: Martin KaFai Lau , Eric Dumazet , Mahesh Bandewar , David Ahern , Wei Wang Subject: [PATCH net-next 3/5] ipv6: honor RT6_LOOKUP_F_DST_NOREF in rule lookup logic Date: Tue, 18 Jun 2019 11:25:41 -0700 Message-Id: <20190618182543.65477-4-tracywwnj@gmail.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190618182543.65477-1-tracywwnj@gmail.com> References: <20190618182543.65477-1-tracywwnj@gmail.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Wei Wang This patch specifically converts the rule lookup logic to honor this flag and not release refcnt when traversing each rule and calling lookup() on each routing table. Similar to previous patch, we also need some special handling of dst entries in uncached list because there is always 1 refcnt taken for them even if RT6_LOOKUP_F_DST_NOREF flag is set. Signed-off-by: Wei Wang Acked-by: Eric Dumazet Acked-by: Mahesh Bandewar --- net/ipv6/fib6_rules.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/net/ipv6/fib6_rules.c b/net/ipv6/fib6_rules.c index bcfae13409b5..9bbcf550cceb 100644 --- a/net/ipv6/fib6_rules.c +++ b/net/ipv6/fib6_rules.c @@ -113,14 +113,17 @@ struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6, rt = lookup(net, net->ipv6.fib6_local_tbl, fl6, skb, flags); if (rt != net->ipv6.ip6_null_entry && rt->dst.error != -EAGAIN) return &rt->dst; - ip6_rt_put(rt); + if (!(flags & RT6_LOOKUP_F_DST_NOREF)) + ip6_rt_put(rt); rt = lookup(net, net->ipv6.fib6_main_tbl, fl6, skb, flags); if (rt->dst.error != -EAGAIN) return &rt->dst; - ip6_rt_put(rt); + if (!(flags & RT6_LOOKUP_F_DST_NOREF)) + ip6_rt_put(rt); } - dst_hold(&net->ipv6.ip6_null_entry->dst); + if (!(flags & RT6_LOOKUP_F_DST_NOREF)) + dst_hold(&net->ipv6.ip6_null_entry->dst); return &net->ipv6.ip6_null_entry->dst; } @@ -237,13 +240,16 @@ static int __fib6_rule_action(struct fib_rule *rule, struct flowi *flp, goto out; } again: - ip6_rt_put(rt); + if (!(flags & RT6_LOOKUP_F_DST_NOREF) || + !list_empty(&rt->rt6i_uncached)) + ip6_rt_put(rt); err = -EAGAIN; rt = NULL; goto out; discard_pkt: - dst_hold(&rt->dst); + if (!(flags & RT6_LOOKUP_F_DST_NOREF)) + dst_hold(&rt->dst); out: res->rt6 = rt; return err; From patchwork Tue Jun 18 18:25:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Wang X-Patchwork-Id: 1118279 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="pulipwSI"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45SxP13fbnz9s3C for ; Wed, 19 Jun 2019 04:26:29 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730329AbfFRS02 (ORCPT ); Tue, 18 Jun 2019 14:26:28 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:34098 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727616AbfFRS02 (ORCPT ); Tue, 18 Jun 2019 14:26:28 -0400 Received: by mail-pf1-f195.google.com with SMTP id c85so8148660pfc.1 for ; Tue, 18 Jun 2019 11:26:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2F/7HrSaq4HN4leZCeGphvq0LzpgNEDY/DjINVDcoZ8=; b=pulipwSIt/lrwx7JUaUosKVgEhtOf+VjX9gGmlhll9DH3l7tXU92D3uq8+DHXYhExa 9gKOYUVDNFjLZs+FdL+5Wb3jRHvwdRahCSjSikfNuJ7EJDJkiuubTu5TBnFUfczx8r6I RXCLqutLSUuCWysiKgVjCP0V5v8rwNFptC0k9r1QEqhnQvucFaASRfL9xeQgipSYIuC7 CZaJKBIF8OcC0vjKgiB+GM0mQ7Y88Flys9zeyoAvzlMnw0Ac23lgre+iaeSsgXmgiSop d8x53M0yKnBP2pxEPpFOX3wEpatMqxmZz7xuXQlrczGnWDXRQBXO52idq57NIaOdX/8N Gx1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2F/7HrSaq4HN4leZCeGphvq0LzpgNEDY/DjINVDcoZ8=; b=tqTtzsOtGsHrFIxvEiuc79tAM9EeuemqOjOZmXvbPzEb+zYMxZhWNOF5vpMzUj8st3 35o7LdcxY0XbJlN/F/OGrZLdwo9LsrabMJ53ixUFezZQ5rRkAnSgjV3+jBstqaHwNwlF lCzHJcIH6aswjdMU9CMrFXAPr/i5+oICJ7xLp/OwAM6X32tzrQgl1yKKoxzvKcls33vB snN4Pp+zu2vrVeAuzFWA+puqhYjy9Ar4mlc86oBAyys0alrgzMc7aPHD3/mOlyHKTPxl fpbHd84XMptxE0rO6NdVOdpLHzQOaenZAGM3TdUPeSzJLf/Tn94aq8OsqsS6GyxRGEuX 1okQ== X-Gm-Message-State: APjAAAXx8Zxt4+iMnRk+kCCrBwfJihzj6YUR/L27lCeXeIYotD4Q2Ou6 nrFJm6qwfsvvCEQCb8E6ywY= X-Google-Smtp-Source: APXvYqxGjcXqkq54Gk/99CGJjkIra4Up16/1Akpfa2xbWfMs+jRE4owj6dZ3xcsqdu3fFQXbE+e/JA== X-Received: by 2002:aa7:97bb:: with SMTP id d27mr53458685pfq.93.1560882387398; Tue, 18 Jun 2019 11:26:27 -0700 (PDT) Received: from weiwan0.svl.corp.google.com ([2620:15c:2c4:201:9310:64cb:677b:dcba]) by smtp.gmail.com with ESMTPSA id h6sm2845859pjs.2.2019.06.18.11.26.26 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 18 Jun 2019 11:26:26 -0700 (PDT) From: Wei Wang To: David Miller , netdev@vger.kernel.org Cc: Martin KaFai Lau , Eric Dumazet , Mahesh Bandewar , David Ahern , Wei Wang Subject: [PATCH net-next 4/5] ipv6: convert rx data path to not take refcnt on dst Date: Tue, 18 Jun 2019 11:25:42 -0700 Message-Id: <20190618182543.65477-5-tracywwnj@gmail.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190618182543.65477-1-tracywwnj@gmail.com> References: <20190618182543.65477-1-tracywwnj@gmail.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Wei Wang ip6_route_input() is the key function to do the route lookup in the rx data path. All the callers to this function are already holding rcu lock. So it is fairly easy to convert it to not take refcnt on the dst: We pass in flag RT6_LOOKUP_F_DST_NOREF and do skb_dst_set_noref(). This saves a few atomic inc or dec operations and should boost performance overall. This also makes the logic more aligned with v4. Signed-off-by: Wei Wang Acked-by: Eric Dumazet Acked-by: Mahesh Bandewar --- net/ipv6/route.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 33dc8af9a4bf..d2b287635aab 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -2375,11 +2375,12 @@ u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6, return mhash >> 1; } +/* Called with rcu held */ void ip6_route_input(struct sk_buff *skb) { const struct ipv6hdr *iph = ipv6_hdr(skb); struct net *net = dev_net(skb->dev); - int flags = RT6_LOOKUP_F_HAS_SADDR; + int flags = RT6_LOOKUP_F_HAS_SADDR | RT6_LOOKUP_F_DST_NOREF; struct ip_tunnel_info *tun_info; struct flowi6 fl6 = { .flowi6_iif = skb->dev->ifindex, @@ -2401,8 +2402,8 @@ void ip6_route_input(struct sk_buff *skb) if (unlikely(fl6.flowi6_proto == IPPROTO_ICMPV6)) fl6.mp_hash = rt6_multipath_hash(net, &fl6, skb, flkeys); skb_dst_drop(skb); - skb_dst_set(skb, - ip6_route_input_lookup(net, skb->dev, &fl6, skb, flags)); + skb_dst_set_noref(skb, ip6_route_input_lookup(net, skb->dev, + &fl6, skb, flags)); } static struct rt6_info *ip6_pol_route_output(struct net *net, From patchwork Tue Jun 18 18:25:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Wang X-Patchwork-Id: 1118280 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="m43XeUBz"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45SxP36rTfz9s7h for ; Wed, 19 Jun 2019 04:26:31 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730341AbfFRS0b (ORCPT ); Tue, 18 Jun 2019 14:26:31 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:46940 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727616AbfFRS0a (ORCPT ); Tue, 18 Jun 2019 14:26:30 -0400 Received: by mail-pf1-f195.google.com with SMTP id 81so8123555pfy.13 for ; Tue, 18 Jun 2019 11:26:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i+jVDnZqlS8Fcpero0ZTuTKJG6BWe/9VcMfcFclCD40=; b=m43XeUBzrbF4lN3MXz5e9EzzPgPHHfX7exbkSMYiFdhcAkW9iWWSclxeo58IYLAnb4 slhfxbnJBzOxWWBjfosQppUsaXGGMxzCdhkeQsPPcxGnnBgVbbEIj/MfQZPa8GGrkFkj 7pgKNzjYvt9yKDU934zrNduwdF8RmCJXgvTmg/WPXkvw/M0yI883IEplJ3itUMKU+cuz nwiS92NntsxwZiGJ03wu8IyMpbeX3IdzcD5Rv9/ptviA/Y1TLix+mRw/h32SWqC5XInj gXsnD34Nyqp7mBCElaYz7B1TWXFpveIXcxlj/yo67IjFM3KsL9eaLiLccmdOjBdfKZXx +sqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i+jVDnZqlS8Fcpero0ZTuTKJG6BWe/9VcMfcFclCD40=; b=QKumgolQfOO3Gy1OhUOxXEL13+nGVMLB7090FfCff06S141epyn5BVyFiOTFTDxwtY 2FIVrHSQer3IJLzng6Wd0SkwwHiwNOpnBSWevrYCq9F1LgHSKTIFZub1Xms7enodH/UJ HKf+eMYx/V/lwswZ41LeBSxqHZ8DXRXg97FZENtONczocH3/GTEte77dlAkLLgdgb3py 8gq2rfwL5F0tN0ii6n2eDLMS76QO/uUZSjUKV5UxVE2Zgp4tL/FLlmkDzk7HDUc4boMz Sz+jELvpg8V6biMgGPumvNuXq3Byn+u3yisecEx8coXbzxBzeO9nuLB3TBc9cQA4Xmmn yemQ== X-Gm-Message-State: APjAAAX1RJnb6K1nnhi/leZT3dB4PZhmFFnvwD1QorthW78F5wmPLZZ9 IXCqXko6AzM4xzf/t5fgooSzoJTdqFI= X-Google-Smtp-Source: APXvYqw4shZZHE8bDVHYfDXF+lNjRKkrjZ6N9TpK4cVOrHE0nrCyvLuS/yUJWyUi4anxbN88cg0ajg== X-Received: by 2002:a62:5cc6:: with SMTP id q189mr121016864pfb.114.1560882389529; Tue, 18 Jun 2019 11:26:29 -0700 (PDT) Received: from weiwan0.svl.corp.google.com ([2620:15c:2c4:201:9310:64cb:677b:dcba]) by smtp.gmail.com with ESMTPSA id h6sm2845859pjs.2.2019.06.18.11.26.28 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 18 Jun 2019 11:26:28 -0700 (PDT) From: Wei Wang To: David Miller , netdev@vger.kernel.org Cc: Martin KaFai Lau , Eric Dumazet , Mahesh Bandewar , David Ahern , Wei Wang Subject: [PATCH net-next 5/5] ipv6: convert major tx path to use RT6_LOOKUP_F_DST_NOREF Date: Tue, 18 Jun 2019 11:25:43 -0700 Message-Id: <20190618182543.65477-6-tracywwnj@gmail.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190618182543.65477-1-tracywwnj@gmail.com> References: <20190618182543.65477-1-tracywwnj@gmail.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Wei Wang For tx path, in most cases, we still have to take refcnt on the dst cause the caller is caching the dst somewhere. But it still is beneficial to make use of RT6_LOOKUP_F_DST_NOREF flag while doing the route lookup. It is cause this flag prevents manipulating refcnt on net->ipv6.ip6_null_entry when doing fib6_rule_lookup() to traverse each routing table. The null_entry is a shared object and constant updates on it cause false sharing. We converted the current major lookup function ip6_route_output_flags() to make use of RT6_LOOKUP_F_DST_NOREF. Together with the change in the rx path, we see noticable performance boost: I ran synflood tests between 2 hosts under the same switch. Both hosts have 20G mlx NIC, and 8 tx/rx queues. Sender sends pure SYN flood with random src IPs and ports using trafgen. Receiver has a simple TCP listener on the target port. Both hosts have multiple custom rules: - For incoming packets, only local table is traversed. - For outgoing packets, 3 tables are traversed to find the route. The packet processing rate on the receiver is as follows: - Before the fix: 3.78Mpps - After the fix: 5.50Mpps Signed-off-by: Wei Wang Acked-by: Eric Dumazet Acked-by: Mahesh Bandewar --- drivers/net/vrf.c | 11 ++++++----- include/net/ip6_route.h | 25 +++++++++++++++++++++++-- include/net/l3mdev.h | 11 +++++++---- net/ipv6/route.c | 10 ++++++---- net/l3mdev/l3mdev.c | 22 +++++++++++----------- 5 files changed, 53 insertions(+), 26 deletions(-) diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c index 11b9525dff27..1d1ac78b167e 100644 --- a/drivers/net/vrf.c +++ b/drivers/net/vrf.c @@ -1072,12 +1072,14 @@ static struct sk_buff *vrf_l3_rcv(struct net_device *vrf_dev, #if IS_ENABLED(CONFIG_IPV6) /* send to link-local or multicast address via interface enslaved to * VRF device. Force lookup to VRF table without changing flow struct + * No refcnt is taken on the dst. */ -static struct dst_entry *vrf_link_scope_lookup(const struct net_device *dev, - struct flowi6 *fl6) +static struct dst_entry *vrf_link_scope_lookup_noref( + const struct net_device *dev, + struct flowi6 *fl6) { struct net *net = dev_net(dev); - int flags = RT6_LOOKUP_F_IFACE; + int flags = RT6_LOOKUP_F_IFACE | RT6_LOOKUP_F_DST_NOREF; struct dst_entry *dst = NULL; struct rt6_info *rt; @@ -1087,7 +1089,6 @@ static struct dst_entry *vrf_link_scope_lookup(const struct net_device *dev, */ if (fl6->flowi6_oif == dev->ifindex) { dst = &net->ipv6.ip6_null_entry->dst; - dst_hold(dst); return dst; } @@ -1107,7 +1108,7 @@ static const struct l3mdev_ops vrf_l3mdev_ops = { .l3mdev_l3_rcv = vrf_l3_rcv, .l3mdev_l3_out = vrf_l3_out, #if IS_ENABLED(CONFIG_IPV6) - .l3mdev_link_scope_lookup = vrf_link_scope_lookup, + .l3mdev_link_scope_lookup_noref = vrf_link_scope_lookup_noref, #endif }; diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h index 82bced2fc1e3..d587d73a5120 100644 --- a/include/net/ip6_route.h +++ b/include/net/ip6_route.h @@ -84,8 +84,29 @@ struct dst_entry *ip6_route_input_lookup(struct net *net, struct flowi6 *fl6, const struct sk_buff *skb, int flags); -struct dst_entry *ip6_route_output_flags(struct net *net, const struct sock *sk, - struct flowi6 *fl6, int flags); +struct dst_entry *ip6_route_output_flags_noref(struct net *net, + const struct sock *sk, + struct flowi6 *fl6, int flags); + +static inline struct dst_entry *ip6_route_output_flags(struct net *net, + const struct sock *sk, + struct flowi6 *fl6, + int flags) { + struct dst_entry *dst; + struct rt6_info *rt6; + + rcu_read_lock(); + dst = ip6_route_output_flags_noref(net, sk, fl6, flags); + rt6 = (struct rt6_info *)dst; + /* For dst cached in uncached_list, refcnt is already taken. */ + if (list_empty(&rt6->rt6i_uncached) && !dst_hold_safe(dst)) { + dst = &net->ipv6.ip6_null_entry->dst; + dst_hold(dst); + } + rcu_read_unlock(); + + return dst; +} static inline struct dst_entry *ip6_route_output(struct net *net, const struct sock *sk, diff --git a/include/net/l3mdev.h b/include/net/l3mdev.h index e942372b077b..d8c37317bb86 100644 --- a/include/net/l3mdev.h +++ b/include/net/l3mdev.h @@ -31,8 +31,9 @@ struct l3mdev_ops { u16 proto); /* IPv6 ops */ - struct dst_entry * (*l3mdev_link_scope_lookup)(const struct net_device *dev, - struct flowi6 *fl6); + struct dst_entry * (*l3mdev_link_scope_lookup_noref)( + const struct net_device *dev, + struct flowi6 *fl6); }; #ifdef CONFIG_NET_L3_MASTER_DEV @@ -140,7 +141,8 @@ static inline bool netif_index_is_l3_master(struct net *net, int ifindex) return rc; } -struct dst_entry *l3mdev_link_scope_lookup(struct net *net, struct flowi6 *fl6); +struct dst_entry *l3mdev_link_scope_lookup_noref(struct net *net, + struct flowi6 *fl6); static inline struct sk_buff *l3mdev_l3_rcv(struct sk_buff *skb, u16 proto) @@ -251,7 +253,8 @@ static inline bool netif_index_is_l3_master(struct net *net, int ifindex) } static inline -struct dst_entry *l3mdev_link_scope_lookup(struct net *net, struct flowi6 *fl6) +struct dst_entry *l3mdev_link_scope_lookup_noref(struct net *net, + struct flowi6 *fl6) { return NULL; } diff --git a/net/ipv6/route.c b/net/ipv6/route.c index d2b287635aab..602d00794b30 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -2415,8 +2415,9 @@ static struct rt6_info *ip6_pol_route_output(struct net *net, return ip6_pol_route(net, table, fl6->flowi6_oif, fl6, skb, flags); } -struct dst_entry *ip6_route_output_flags(struct net *net, const struct sock *sk, - struct flowi6 *fl6, int flags) +struct dst_entry *ip6_route_output_flags_noref(struct net *net, + const struct sock *sk, + struct flowi6 *fl6, int flags) { bool any_src; @@ -2424,13 +2425,14 @@ struct dst_entry *ip6_route_output_flags(struct net *net, const struct sock *sk, (IPV6_ADDR_MULTICAST | IPV6_ADDR_LINKLOCAL)) { struct dst_entry *dst; - dst = l3mdev_link_scope_lookup(net, fl6); + dst = l3mdev_link_scope_lookup_noref(net, fl6); if (dst) return dst; } fl6->flowi6_iif = LOOPBACK_IFINDEX; + flags |= RT6_LOOKUP_F_DST_NOREF; any_src = ipv6_addr_any(&fl6->saddr); if ((sk && sk->sk_bound_dev_if) || rt6_need_strict(&fl6->daddr) || (fl6->flowi6_oif && any_src)) @@ -2443,7 +2445,7 @@ struct dst_entry *ip6_route_output_flags(struct net *net, const struct sock *sk, return fib6_rule_lookup(net, fl6, NULL, flags, ip6_pol_route_output); } -EXPORT_SYMBOL_GPL(ip6_route_output_flags); +EXPORT_SYMBOL_GPL(ip6_route_output_flags_noref); struct dst_entry *ip6_blackhole_route(struct net *net, struct dst_entry *dst_orig) { diff --git a/net/l3mdev/l3mdev.c b/net/l3mdev/l3mdev.c index cfc9fcb97465..06133426549b 100644 --- a/net/l3mdev/l3mdev.c +++ b/net/l3mdev/l3mdev.c @@ -114,35 +114,35 @@ u32 l3mdev_fib_table_by_index(struct net *net, int ifindex) EXPORT_SYMBOL_GPL(l3mdev_fib_table_by_index); /** - * l3mdev_link_scope_lookup - IPv6 route lookup based on flow for link - * local and multicast addresses + * l3mdev_link_scope_lookup_noref - IPv6 route lookup based on flow + * for link local and multicast addresses * @net: network namespace for device index lookup * @fl6: IPv6 flow struct for lookup + * This function does not hold refcnt on the returned dst. + * Caller must hold rcu_read_lock(). */ -struct dst_entry *l3mdev_link_scope_lookup(struct net *net, - struct flowi6 *fl6) +struct dst_entry *l3mdev_link_scope_lookup_noref(struct net *net, + struct flowi6 *fl6) { struct dst_entry *dst = NULL; struct net_device *dev; + WARN_ON_ONCE(!rcu_read_lock_held()); if (fl6->flowi6_oif) { - rcu_read_lock(); - dev = dev_get_by_index_rcu(net, fl6->flowi6_oif); if (dev && netif_is_l3_slave(dev)) dev = netdev_master_upper_dev_get_rcu(dev); if (dev && netif_is_l3_master(dev) && - dev->l3mdev_ops->l3mdev_link_scope_lookup) - dst = dev->l3mdev_ops->l3mdev_link_scope_lookup(dev, fl6); - - rcu_read_unlock(); + dev->l3mdev_ops->l3mdev_link_scope_lookup_noref) + dst = dev->l3mdev_ops-> + l3mdev_link_scope_lookup_noref(dev, fl6); } return dst; } -EXPORT_SYMBOL_GPL(l3mdev_link_scope_lookup); +EXPORT_SYMBOL_GPL(l3mdev_link_scope_lookup_noref); /** * l3mdev_fib_rule_match - Determine if flowi references an