From patchwork Wed Jun 22 05:12:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12890145 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54EEEC433EF for ; Wed, 22 Jun 2022 05:13:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356602AbiFVFNK (ORCPT ); Wed, 22 Jun 2022 01:13:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356580AbiFVFND (ORCPT ); Wed, 22 Jun 2022 01:13:03 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A539634677 for ; Tue, 21 Jun 2022 22:13:02 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id m68-20020a253f47000000b006683bd91962so13762599yba.0 for ; Tue, 21 Jun 2022 22:13:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=wwSFzfJ2SWCyUmQ5lfdkSc585bMTz54WWciPG1drR9k=; b=iiIkdUb0DjlyAlcyjfNGEe3jXtSi0qOd68fEW2hV/j9y6UCnAZOzQSpQg4fRb+jyRp AIAPvS5VOE+VvNLr3oeopI09vHEhMFFqMMrU6mRILMQfXFG61NelWVOGa+bgHa5l9pOw wghHxxXjFoZclu3tog/zBsBWbOb+E3k85v2ec7SulVTZagM0sniHZLdLdqFHf4r8Mlto MZyOO3DY2jQBsXzp6MPEm0ESubH0b86aTHseKEbm/RBdq+CBCzy4ZqfD1q8KLjjkKCkA X0jP0reRy3eb+hi+AO2SRYUzy6dI6gAQkMwGIuI9hMRaTExSrnXmKyDd6fU8IKN3f+JR QmvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=wwSFzfJ2SWCyUmQ5lfdkSc585bMTz54WWciPG1drR9k=; b=V1CS00byh2Mstfq7GhPjvOkKzSR1SgG7IyspehJGmdBmjICxUEbf/bUV6mQ1/IfEyc bmD1grEUpUn3OpBu87IPjl+19KG9SbKorvQQuPs1ikahhGIiwNoqAs9AdGP1qBKGoH9S 05kjfgCypjfiMYq81ZwNkNRiUmFXjKSsth4PvLb0Dy8+hHaUh0JYevO72JP5DelkEP2a JqDp/SsTbU6Ss+/smagWW0JB6buL5H3zrEPPfKdoDyU9OZXRcvDcZmyE/zhxfgh7buh5 dCtkpN55BeVAVlPiFmwyVtzot9cjKSz7z1ZlAEdJ6nBQTGho4oRuoSAfUK+2yBLnDdqj bR+A== X-Gm-Message-State: AJIora9uQJGFQfFrPWAhiG3Zmg86+oo6Vpzdph5S2fIWxe6NXgKuvczQ Bs2Hu09/2bLEHefBSqMu9kJln1SZJsMLDw== X-Google-Smtp-Source: AGRyM1ubtKpqhlhItj0Unnk9R7vs+4xKuFGW8Rr8Ho+wPiw64C4lzwFUstwu9FU1x0/IagbhGx6Y6H8xgxd7fw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a0d:d9cb:0:b0:317:760e:991e with SMTP id b194-20020a0dd9cb000000b00317760e991emr2167503ywe.6.1655874781834; Tue, 21 Jun 2022 22:13:01 -0700 (PDT) Date: Wed, 22 Jun 2022 05:12:37 +0000 In-Reply-To: <20220622051255.700309-1-edumazet@google.com> Message-Id: <20220622051255.700309-2-edumazet@google.com> Mime-Version: 1.0 References: <20220622051255.700309-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH net-next 01/19] ip6mr: do not get a device reference in pim6_rcv() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org pim6_rcv() is called under rcu_read_lock(), there is no need to use dev_hold()/dev_put() pair. IPv4 side was handled in commit 55747a0a73ea ("ipmr: __pim_rcv() is called under rcu_read_lock") Signed-off-by: Eric Dumazet --- net/ipv6/ip6mr.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index d4aad41c9849f977e395e9e07a4442dbfec07b1b..aa66c032ba979e7a14e5e296b68c55bc73d98398 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -554,7 +554,6 @@ static int pim6_rcv(struct sk_buff *skb) read_lock(&mrt_lock); if (reg_vif_num >= 0) reg_dev = mrt->vif_table[reg_vif_num].dev; - dev_hold(reg_dev); read_unlock(&mrt_lock); if (!reg_dev) @@ -570,7 +569,6 @@ static int pim6_rcv(struct sk_buff *skb) netif_rx(skb); - dev_put(reg_dev); return 0; drop: kfree_skb(skb); From patchwork Wed Jun 22 05:12:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12890146 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C07D7C43334 for ; Wed, 22 Jun 2022 05:13:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356633AbiFVFNJ (ORCPT ); Wed, 22 Jun 2022 01:13:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356602AbiFVFNG (ORCPT ); Wed, 22 Jun 2022 01:13:06 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5AEC34678 for ; Tue, 21 Jun 2022 22:13:04 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-3177d1fe9f1so120218057b3.0 for ; Tue, 21 Jun 2022 22:13:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=LnGapFElVHJ5Xu6TsypR+UtkUB7GlltsZy8jxki75xQ=; b=HiNiwCY9ctKgCw4WprOnnsMInUIAJCK3X8Xzbz/YTpt1yr8v+Ok+73aVhC+QdbGy2u RVt2Rk/wsQUuW5QO6cVrrbqsOPS6xMv0ky23G2IlnKVqPcbt0whR4qXOg0Wnz2/TPCnm mWPRY/kXuqWbKCOyBRoK/zsyBg2j6paNMejKQ9CT2/uhPtAIwfkz0ABm7cKeMOU9Y82O k2PVoPnYqZ6OkeLysYmTvrCzyZCN6HeR4cL9IUpYaIeayvalQ5LLsKbxkVRh1fgzK1zj fYtjpII30aG/Oc9yaTeMBz/szii7HSGDAbbp0156tsbMl+Vpuy/6xcvC67JU0yJJY60I iZqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=LnGapFElVHJ5Xu6TsypR+UtkUB7GlltsZy8jxki75xQ=; b=dYGyxq24aeGoj8ljUm0yf+4EHbVNkhTKoPlitxuPy3jEf2CXd7t6Yal4ypxTVAEJVv VbD/q6cPfcVuhsfjKRJDAvRoLWqCoXglJZYELNYw2RYO7YBtrZoT4H42PzDnP8BaFAd/ Tg+Z9Oa1XNPxfBPY1us1Vviazvb5r90XEcg7o5+erkDwUUsiwYPpZSZA3NvI8sqhM+b+ Dex6gDUsO1PAiXsFj64zZLIzNnTcgD7KL/lZef0kq6S6F8TJBcNt/hT6O36Ffr9ILtLZ U0xskY69VU3frPgmL7rA7YTN3Swx+RjcmcgLpGVDt0ojawEP7gPrW5nmG325B+0K2a2j 7MYA== X-Gm-Message-State: AJIora8Qq8nWGYpKpgtdd+jvbNF93FVx8cSa9qhcTfD78iG0ZtiT0bUi jCqOYcwp40tc+oiCsUDmzDY2Y84tcmmaoQ== X-Google-Smtp-Source: AGRyM1tNfqAdC+LQw6M2XGvQtcNGERedPp8NmNJq4sesqh+ZmYGhDoCsR4Va4aiReCxBsU0G27kZwu2zi5xRVA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:d48:0:b0:669:4ac2:9d4b with SMTP id 69-20020a250d48000000b006694ac29d4bmr1725266ybn.491.1655874784059; Tue, 21 Jun 2022 22:13:04 -0700 (PDT) Date: Wed, 22 Jun 2022 05:12:38 +0000 In-Reply-To: <20220622051255.700309-1-edumazet@google.com> Message-Id: <20220622051255.700309-3-edumazet@google.com> Mime-Version: 1.0 References: <20220622051255.700309-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH net-next 02/19] ipmr: add rcu protection over (struct vif_device)->dev From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org We will soon use RCU instead of rwlock in impr. This preliminary patch adds proper rcu verbs to read/write (struct vif_device)->dev Signed-off-by: Eric Dumazet --- include/linux/mroute_base.h | 11 ++++--- net/ipv4/ipmr.c | 65 ++++++++++++++++++++++--------------- net/ipv4/ipmr_base.c | 49 ++++++++++++++++++---------- net/ipv6/ip6mr.c | 63 +++++++++++++++++++---------------- 4 files changed, 111 insertions(+), 77 deletions(-) diff --git a/include/linux/mroute_base.h b/include/linux/mroute_base.h index e05ee9f001ffbf30f7b26ab5555e2db5cc058560..10d1e4fb4e9fe387d914c83d135ed6a8f284c374 100644 --- a/include/linux/mroute_base.h +++ b/include/linux/mroute_base.h @@ -26,7 +26,7 @@ * @remote: Remote address for tunnels */ struct vif_device { - struct net_device *dev; + struct net_device __rcu *dev; netdevice_tracker dev_tracker; unsigned long bytes_in, bytes_out; unsigned long pkt_in, pkt_out; @@ -52,6 +52,7 @@ static inline int mr_call_vif_notifier(struct notifier_block *nb, unsigned short family, enum fib_event_type event_type, struct vif_device *vif, + struct net_device *vif_dev, unsigned short vif_index, u32 tb_id, struct netlink_ext_ack *extack) { @@ -60,7 +61,7 @@ static inline int mr_call_vif_notifier(struct notifier_block *nb, .family = family, .extack = extack, }, - .dev = vif->dev, + .dev = vif_dev, .vif_index = vif_index, .vif_flags = vif->flags, .tb_id = tb_id, @@ -73,6 +74,7 @@ static inline int mr_call_vif_notifiers(struct net *net, unsigned short family, enum fib_event_type event_type, struct vif_device *vif, + struct net_device *vif_dev, unsigned short vif_index, u32 tb_id, unsigned int *ipmr_seq) { @@ -80,7 +82,7 @@ static inline int mr_call_vif_notifiers(struct net *net, .info = { .family = family, }, - .dev = vif->dev, + .dev = vif_dev, .vif_index = vif_index, .vif_flags = vif->flags, .tb_id = tb_id, @@ -98,7 +100,8 @@ static inline int mr_call_vif_notifiers(struct net *net, #define MAXVIFS 32 #endif -#define VIF_EXISTS(_mrt, _idx) (!!((_mrt)->vif_table[_idx].dev)) +/* Note: This helper is deprecated. */ +#define VIF_EXISTS(_mrt, _idx) (!!rcu_access_pointer((_mrt)->vif_table[_idx].dev)) /* mfc_flags: * MFC_STATIC - the entry was added statically (not by a routing daemon) diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 8324e541d193b0024a82d83149a0ee3b5967f2a9..10371a9e78fc41e8562fa8d81222a8ae24e2fbb6 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -79,6 +79,12 @@ struct ipmr_result { static DEFINE_RWLOCK(mrt_lock); +static struct net_device *vif_dev_read(const struct vif_device *vif) +{ + return rcu_dereference_check(vif->dev, + lockdep_is_held(&mrt_lock)); +} + /* Multicast router control variables */ /* Special spinlock for queue of unresolved entries */ @@ -586,7 +592,7 @@ static int __pim_rcv(struct mr_table *mrt, struct sk_buff *skb, read_lock(&mrt_lock); if (mrt->mroute_reg_vif_num >= 0) - reg_dev = mrt->vif_table[mrt->mroute_reg_vif_num].dev; + reg_dev = vif_dev_read(&mrt->vif_table[mrt->mroute_reg_vif_num]); read_unlock(&mrt_lock); if (!reg_dev) @@ -614,10 +620,11 @@ static struct net_device *ipmr_reg_vif(struct net *net, struct mr_table *mrt) static int call_ipmr_vif_entry_notifiers(struct net *net, enum fib_event_type event_type, struct vif_device *vif, + struct net_device *vif_dev, vifi_t vif_index, u32 tb_id) { return mr_call_vif_notifiers(net, RTNL_FAMILY_IPMR, event_type, - vif, vif_index, tb_id, + vif, vif_dev, vif_index, tb_id, &net->ipv4.ipmr_seq); } @@ -649,18 +656,14 @@ static int vif_delete(struct mr_table *mrt, int vifi, int notify, v = &mrt->vif_table[vifi]; - if (VIF_EXISTS(mrt, vifi)) - call_ipmr_vif_entry_notifiers(net, FIB_EVENT_VIF_DEL, v, vifi, - mrt->id); + dev = rtnl_dereference(v->dev); + if (!dev) + return -EADDRNOTAVAIL; write_lock_bh(&mrt_lock); - dev = v->dev; - v->dev = NULL; - - if (!dev) { - write_unlock_bh(&mrt_lock); - return -EADDRNOTAVAIL; - } + call_ipmr_vif_entry_notifiers(net, FIB_EVENT_VIF_DEL, v, dev, + vifi, mrt->id); + RCU_INIT_POINTER(v->dev, NULL); if (vifi == mrt->mroute_reg_vif_num) mrt->mroute_reg_vif_num = -1; @@ -890,14 +893,15 @@ static int vif_add(struct net *net, struct mr_table *mrt, /* And finish update writing critical data */ write_lock_bh(&mrt_lock); - v->dev = dev; + rcu_assign_pointer(v->dev, dev); netdev_tracker_alloc(dev, &v->dev_tracker, GFP_ATOMIC); if (v->flags & VIFF_REGISTER) mrt->mroute_reg_vif_num = vifi; if (vifi+1 > mrt->maxvif) mrt->maxvif = vifi+1; write_unlock_bh(&mrt_lock); - call_ipmr_vif_entry_notifiers(net, FIB_EVENT_VIF_ADD, v, vifi, mrt->id); + call_ipmr_vif_entry_notifiers(net, FIB_EVENT_VIF_ADD, v, dev, + vifi, mrt->id); return 0; } @@ -1726,7 +1730,7 @@ static int ipmr_device_event(struct notifier_block *this, unsigned long event, v ipmr_for_each_table(mrt, net) { v = &mrt->vif_table[0]; for (ct = 0; ct < mrt->maxvif; ct++, v++) { - if (v->dev == dev) + if (rcu_access_pointer(v->dev) == dev) vif_delete(mrt, ct, 1, NULL); } } @@ -1811,19 +1815,21 @@ static void ipmr_queue_xmit(struct net *net, struct mr_table *mrt, { const struct iphdr *iph = ip_hdr(skb); struct vif_device *vif = &mrt->vif_table[vifi]; + struct net_device *vif_dev; struct net_device *dev; struct rtable *rt; struct flowi4 fl4; int encap = 0; - if (!vif->dev) + vif_dev = vif_dev_read(vif); + if (!vif_dev) goto out_free; if (vif->flags & VIFF_REGISTER) { vif->pkt_out++; vif->bytes_out += skb->len; - vif->dev->stats.tx_bytes += skb->len; - vif->dev->stats.tx_packets++; + vif_dev->stats.tx_bytes += skb->len; + vif_dev->stats.tx_packets++; ipmr_cache_report(mrt, skb, vifi, IGMPMSG_WHOLEPKT); goto out_free; } @@ -1881,8 +1887,8 @@ static void ipmr_queue_xmit(struct net *net, struct mr_table *mrt, if (vif->flags & VIFF_TUNNEL) { ip_encap(net, skb, vif->local, vif->remote); /* FIXME: extra output firewall step used to be here. --RR */ - vif->dev->stats.tx_packets++; - vif->dev->stats.tx_bytes += skb->len; + vif_dev->stats.tx_packets++; + vif_dev->stats.tx_bytes += skb->len; } IPCB(skb)->flags |= IPSKB_FORWARDED; @@ -1911,7 +1917,7 @@ static int ipmr_find_vif(struct mr_table *mrt, struct net_device *dev) int ct; for (ct = mrt->maxvif-1; ct >= 0; ct--) { - if (mrt->vif_table[ct].dev == dev) + if (rcu_access_pointer(mrt->vif_table[ct].dev) == dev) break; } return ct; @@ -1944,7 +1950,7 @@ static void ip_mr_forward(struct net *net, struct mr_table *mrt, } /* Wrong interface: drop packet and (maybe) send PIM assert. */ - if (mrt->vif_table[vif].dev != dev) { + if (rcu_access_pointer(mrt->vif_table[vif].dev) != dev) { if (rt_is_output_route(skb_rtable(skb))) { /* It is our own packet, looped back. * Very complicated situation... @@ -2744,18 +2750,21 @@ static bool ipmr_fill_table(struct mr_table *mrt, struct sk_buff *skb) static bool ipmr_fill_vif(struct mr_table *mrt, u32 vifid, struct sk_buff *skb) { + struct net_device *vif_dev; struct nlattr *vif_nest; struct vif_device *vif; + vif = &mrt->vif_table[vifid]; + vif_dev = vif_dev_read(vif); /* if the VIF doesn't exist just continue */ - if (!VIF_EXISTS(mrt, vifid)) + if (!vif_dev) return true; - vif = &mrt->vif_table[vifid]; vif_nest = nla_nest_start_noflag(skb, IPMRA_VIF); if (!vif_nest) return false; - if (nla_put_u32(skb, IPMRA_VIFA_IFINDEX, vif->dev->ifindex) || + + if (nla_put_u32(skb, IPMRA_VIFA_IFINDEX, vif_dev->ifindex) || nla_put_u32(skb, IPMRA_VIFA_VIF_ID, vifid) || nla_put_u16(skb, IPMRA_VIFA_FLAGS, vif->flags) || nla_put_u64_64bit(skb, IPMRA_VIFA_BYTES_IN, vif->bytes_in, @@ -2919,9 +2928,11 @@ static int ipmr_vif_seq_show(struct seq_file *seq, void *v) "Interface BytesIn PktsIn BytesOut PktsOut Flags Local Remote\n"); } else { const struct vif_device *vif = v; - const char *name = vif->dev ? - vif->dev->name : "none"; + const struct net_device *vif_dev; + const char *name; + vif_dev = vif_dev_read(vif); + name = vif_dev ? vif_dev->name : "none"; seq_printf(seq, "%2td %-10s %8ld %7ld %8ld %7ld %05X %08X %08X\n", vif - mrt->vif_table, diff --git a/net/ipv4/ipmr_base.c b/net/ipv4/ipmr_base.c index aa8738a91210a563a2bd7ee1fe17f3bcde1936de..59f62b938472aef79b4eb3ade706bf4d111e1e3a 100644 --- a/net/ipv4/ipmr_base.c +++ b/net/ipv4/ipmr_base.c @@ -13,7 +13,7 @@ void vif_device_init(struct vif_device *v, unsigned short flags, unsigned short get_iflink_mask) { - v->dev = NULL; + RCU_INIT_POINTER(v->dev, NULL); v->bytes_in = 0; v->bytes_out = 0; v->pkt_in = 0; @@ -208,6 +208,7 @@ EXPORT_SYMBOL(mr_mfc_seq_next); int mr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb, struct mr_mfc *c, struct rtmsg *rtm) { + struct net_device *vif_dev; struct rta_mfc_stats mfcs; struct nlattr *mp_attr; struct rtnexthop *nhp; @@ -220,10 +221,13 @@ int mr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb, return -ENOENT; } - if (VIF_EXISTS(mrt, c->mfc_parent) && - nla_put_u32(skb, RTA_IIF, - mrt->vif_table[c->mfc_parent].dev->ifindex) < 0) + rcu_read_lock(); + vif_dev = rcu_dereference(mrt->vif_table[c->mfc_parent].dev); + if (vif_dev && nla_put_u32(skb, RTA_IIF, vif_dev->ifindex) < 0) { + rcu_read_unlock(); return -EMSGSIZE; + } + rcu_read_unlock(); if (c->mfc_flags & MFC_OFFLOAD) rtm->rtm_flags |= RTNH_F_OFFLOAD; @@ -232,23 +236,27 @@ int mr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb, if (!mp_attr) return -EMSGSIZE; + rcu_read_lock(); for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) { - if (VIF_EXISTS(mrt, ct) && c->mfc_un.res.ttls[ct] < 255) { - struct vif_device *vif; + struct vif_device *vif = &mrt->vif_table[ct]; + + vif_dev = rcu_dereference(vif->dev); + if (vif_dev && c->mfc_un.res.ttls[ct] < 255) { nhp = nla_reserve_nohdr(skb, sizeof(*nhp)); if (!nhp) { + rcu_read_unlock(); nla_nest_cancel(skb, mp_attr); return -EMSGSIZE; } nhp->rtnh_flags = 0; nhp->rtnh_hops = c->mfc_un.res.ttls[ct]; - vif = &mrt->vif_table[ct]; - nhp->rtnh_ifindex = vif->dev->ifindex; + nhp->rtnh_ifindex = vif_dev->ifindex; nhp->rtnh_len = sizeof(*nhp); } } + rcu_read_unlock(); nla_nest_end(skb, mp_attr); @@ -275,13 +283,14 @@ static bool mr_mfc_uses_dev(const struct mr_table *mrt, int ct; for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) { - if (VIF_EXISTS(mrt, ct) && c->mfc_un.res.ttls[ct] < 255) { - const struct vif_device *vif; - - vif = &mrt->vif_table[ct]; - if (vif->dev == dev) - return true; - } + const struct net_device *vif_dev; + const struct vif_device *vif; + + vif = &mrt->vif_table[ct]; + vif_dev = rcu_access_pointer(vif->dev); + if (vif_dev && c->mfc_un.res.ttls[ct] < 255 && + vif_dev == dev) + return true; } return false; } @@ -402,18 +411,22 @@ int mr_dump(struct net *net, struct notifier_block *nb, unsigned short family, for (mrt = mr_iter(net, NULL); mrt; mrt = mr_iter(net, mrt)) { struct vif_device *v = &mrt->vif_table[0]; + struct net_device *vif_dev; struct mr_mfc *mfc; int vifi; /* Notifiy on table VIF entries */ read_lock(mrt_lock); for (vifi = 0; vifi < mrt->maxvif; vifi++, v++) { - if (!v->dev) + vif_dev = rcu_dereference_check(v->dev, + lockdep_is_held(mrt_lock)); + if (!vif_dev) continue; err = mr_call_vif_notifier(nb, family, - FIB_EVENT_VIF_ADD, - v, vifi, mrt->id, extack); + FIB_EVENT_VIF_ADD, v, + vif_dev, vifi, + mrt->id, extack); if (err) break; } diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index aa66c032ba979e7a14e5e296b68c55bc73d98398..44cb3d88bbd6f85ce0c8e9054dd3d578b7b3733b 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -64,6 +64,12 @@ struct ip6mr_result { static DEFINE_RWLOCK(mrt_lock); +static struct net_device *vif_dev_read(const struct vif_device *vif) +{ + return rcu_dereference_check(vif->dev, + lockdep_is_held(&mrt_lock)); +} + /* Multicast router control variables */ /* Special spinlock for queue of unresolved entries */ @@ -430,7 +436,11 @@ static int ip6mr_vif_seq_show(struct seq_file *seq, void *v) "Interface BytesIn PktsIn BytesOut PktsOut Flags\n"); } else { const struct vif_device *vif = v; - const char *name = vif->dev ? vif->dev->name : "none"; + const struct net_device *vif_dev; + const char *name; + + vif_dev = vif_dev_read(vif); + name = vif_dev ? vif_dev->name : "none"; seq_printf(seq, "%2td %-10s %8ld %7ld %8ld %7ld %05X\n", @@ -553,7 +563,7 @@ static int pim6_rcv(struct sk_buff *skb) read_lock(&mrt_lock); if (reg_vif_num >= 0) - reg_dev = mrt->vif_table[reg_vif_num].dev; + reg_dev = vif_dev_read(&mrt->vif_table[reg_vif_num]); read_unlock(&mrt_lock); if (!reg_dev) @@ -668,10 +678,11 @@ static struct net_device *ip6mr_reg_vif(struct net *net, struct mr_table *mrt) static int call_ip6mr_vif_entry_notifiers(struct net *net, enum fib_event_type event_type, struct vif_device *vif, + struct net_device *vif_dev, mifi_t vif_index, u32 tb_id) { return mr_call_vif_notifiers(net, RTNL_FAMILY_IP6MR, event_type, - vif, vif_index, tb_id, + vif, vif_dev, vif_index, tb_id, &net->ipv6.ipmr_seq); } @@ -696,19 +707,15 @@ static int mif6_delete(struct mr_table *mrt, int vifi, int notify, v = &mrt->vif_table[vifi]; - if (VIF_EXISTS(mrt, vifi)) - call_ip6mr_vif_entry_notifiers(read_pnet(&mrt->net), - FIB_EVENT_VIF_DEL, v, vifi, - mrt->id); + dev = rtnl_dereference(v->dev); + if (!dev) + return -EADDRNOTAVAIL; + call_ip6mr_vif_entry_notifiers(read_pnet(&mrt->net), + FIB_EVENT_VIF_DEL, v, dev, + vifi, mrt->id); write_lock_bh(&mrt_lock); - dev = v->dev; - v->dev = NULL; - - if (!dev) { - write_unlock_bh(&mrt_lock); - return -EADDRNOTAVAIL; - } + RCU_INIT_POINTER(v->dev, NULL); #ifdef CONFIG_IPV6_PIMSM_V2 if (vifi == mrt->mroute_reg_vif_num) @@ -911,7 +918,7 @@ static int mif6_add(struct net *net, struct mr_table *mrt, /* And finish update writing critical data */ write_lock_bh(&mrt_lock); - v->dev = dev; + rcu_assign_pointer(v->dev, dev); netdev_tracker_alloc(dev, &v->dev_tracker, GFP_ATOMIC); #ifdef CONFIG_IPV6_PIMSM_V2 if (v->flags & MIFF_REGISTER) @@ -921,7 +928,7 @@ static int mif6_add(struct net *net, struct mr_table *mrt, mrt->maxvif = vifi + 1; write_unlock_bh(&mrt_lock); call_ip6mr_vif_entry_notifiers(net, FIB_EVENT_VIF_ADD, - v, vifi, mrt->id); + v, dev, vifi, mrt->id); return 0; } @@ -1241,7 +1248,7 @@ static int ip6mr_device_event(struct notifier_block *this, ip6mr_for_each_table(mrt, net) { v = &mrt->vif_table[0]; for (ct = 0; ct < mrt->maxvif; ct++, v++) { - if (v->dev == dev) + if (rcu_access_pointer(v->dev) == dev) mif6_delete(mrt, ct, 1, NULL); } } @@ -2019,21 +2026,22 @@ static inline int ip6mr_forward2_finish(struct net *net, struct sock *sk, struct static int ip6mr_forward2(struct net *net, struct mr_table *mrt, struct sk_buff *skb, int vifi) { - struct ipv6hdr *ipv6h; struct vif_device *vif = &mrt->vif_table[vifi]; - struct net_device *dev; + struct net_device *vif_dev; + struct ipv6hdr *ipv6h; struct dst_entry *dst; struct flowi6 fl6; - if (!vif->dev) + vif_dev = vif_dev_read(vif); + if (!vif_dev) goto out_free; #ifdef CONFIG_IPV6_PIMSM_V2 if (vif->flags & MIFF_REGISTER) { vif->pkt_out++; vif->bytes_out += skb->len; - vif->dev->stats.tx_bytes += skb->len; - vif->dev->stats.tx_packets++; + vif_dev->stats.tx_bytes += skb->len; + vif_dev->stats.tx_packets++; ip6mr_cache_report(mrt, skb, vifi, MRT6MSG_WHOLEPKT); goto out_free; } @@ -2066,14 +2074,13 @@ static int ip6mr_forward2(struct net *net, struct mr_table *mrt, * not mrouter) cannot join to more than one interface - it will * result in receiving multiple packets. */ - dev = vif->dev; - skb->dev = dev; + skb->dev = vif_dev; vif->pkt_out++; vif->bytes_out += skb->len; /* We are about to write */ /* XXX: extension headers? */ - if (skb_cow(skb, sizeof(*ipv6h) + LL_RESERVED_SPACE(dev))) + if (skb_cow(skb, sizeof(*ipv6h) + LL_RESERVED_SPACE(vif_dev))) goto out_free; ipv6h = ipv6_hdr(skb); @@ -2082,7 +2089,7 @@ static int ip6mr_forward2(struct net *net, struct mr_table *mrt, IP6CB(skb)->flags |= IP6SKB_FORWARDED; return NF_HOOK(NFPROTO_IPV6, NF_INET_FORWARD, - net, NULL, skb, skb->dev, dev, + net, NULL, skb, skb->dev, vif_dev, ip6mr_forward2_finish); out_free: @@ -2095,7 +2102,7 @@ static int ip6mr_find_vif(struct mr_table *mrt, struct net_device *dev) int ct; for (ct = mrt->maxvif - 1; ct >= 0; ct--) { - if (mrt->vif_table[ct].dev == dev) + if (rcu_access_pointer(mrt->vif_table[ct].dev) == dev) break; } return ct; @@ -2133,7 +2140,7 @@ static void ip6_mr_forward(struct net *net, struct mr_table *mrt, /* * Wrong interface: drop packet and (maybe) send PIM assert. */ - if (mrt->vif_table[vif].dev != dev) { + if (rcu_access_pointer(mrt->vif_table[vif].dev) != dev) { c->_c.mfc_un.res.wrong_if++; if (true_vifi >= 0 && mrt->mroute_do_assert && From patchwork Wed Jun 22 05:12:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12890147 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7E46CCA47A for ; Wed, 22 Jun 2022 05:13:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356672AbiFVFNL (ORCPT ); Wed, 22 Jun 2022 01:13:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356622AbiFVFNH (ORCPT ); Wed, 22 Jun 2022 01:13:07 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D03AF3467F for ; Tue, 21 Jun 2022 22:13:06 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-31797057755so85871327b3.16 for ; Tue, 21 Jun 2022 22:13:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=2CUsOTdK8JALIGsuTPLTtiAjA4wcVESU0aO5OJ+gE5o=; b=obNtajvdIrRaOSJaHNvQQdojvtUhS+yWQ4Q111NpNYKksDIAUG2dWAubGgLtczYXP8 incdinEv6YVHSRldNQO/58vE3oGRKEDWhTA0waE701AAZMLUAYK6q7v619dIkWz7XQrb Y2LowSrrsb3bJu/j0dtS++Plbqyque7E5avDp9p+g4rhOD3cgsPNNRC2I3KDdfW5Fv97 EsFytQkbSQSSDR8aYghxn4zzSK53ldnGfnnxWH/Y/MqbMKzeUNc3CsckWO+uje/I7Ewk 7/+s805Kg4t6ix/p5JuXyJbNm8rpGBZSB8r+/1bAGpfJ/bSqYml9dh5SS8P7pdYsyeK+ aANw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=2CUsOTdK8JALIGsuTPLTtiAjA4wcVESU0aO5OJ+gE5o=; b=vGtzlS85dagzMXKBFeBu2cNfCCFQ8LwMRvvVA+H7C8ijIpaJuJPggMRwweA+rEtXeM r9sCw/94NbXEPDpqAXp/I2WYa5Vr4zFkNi/9fKAfAW/5krvN7bdQ42I+ICTm9bGLmNI0 TKLxBPvU2xGeSBo+5DWCGm85dAiq9043mUPw/Z02zKKR75SA2Kr8mWWV/ThVpxYSofDq +mr2INpvp8WVk+MXOayHgrBBu6bm58HSKGzBXqN56JC1/vhPeJ7eavbUgxvjYPPNL4WP 2pDsGmBdVw0IchrDLLyYRMCKhW4WLlxo6gAShzvuSxtqB7dzTZb+fOYWqtS9eZHeFAJM AVRg== X-Gm-Message-State: AJIora82LN75eEF3v0fHAYWZYuYXBhQ2hBXLOQyYyB9CmomC2nel09X+ /6PvSvryPm4Mz5cKRiLAMNPu7V4Dico1GA== X-Google-Smtp-Source: AGRyM1tVR+qVuidEpvZgd9gYeBVqmQEJgYSfYjNcPkq898MExM+fmg/ORsBFynFiipK7QkE2/zOr1bDopJsL6w== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:cf43:0:b0:669:3851:6dc0 with SMTP id f64-20020a25cf43000000b0066938516dc0mr1762986ybg.279.1655874786143; Tue, 21 Jun 2022 22:13:06 -0700 (PDT) Date: Wed, 22 Jun 2022 05:12:39 +0000 In-Reply-To: <20220622051255.700309-1-edumazet@google.com> Message-Id: <20220622051255.700309-4-edumazet@google.com> Mime-Version: 1.0 References: <20220622051255.700309-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH net-next 03/19] ipmr: change igmpmsg_netlink_event() prototype From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org igmpmsg_netlink_event() first argument can be marked const. igmpmsg_netlink_event() reads mrt->net and mrt->id, both being set once in mr_table_alloc(). Signed-off-by: Eric Dumazet --- net/ipv4/ipmr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 10371a9e78fc41e8562fa8d81222a8ae24e2fbb6..6710324497cae3bbc2fcdd12d6e1d44eed5215b3 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -110,7 +110,7 @@ static int ipmr_cache_report(struct mr_table *mrt, struct sk_buff *pkt, vifi_t vifi, int assert); static void mroute_netlink_event(struct mr_table *mrt, struct mfc_cache *mfc, int cmd); -static void igmpmsg_netlink_event(struct mr_table *mrt, struct sk_buff *pkt); +static void igmpmsg_netlink_event(const struct mr_table *mrt, struct sk_buff *pkt); static void mroute_clean_tables(struct mr_table *mrt, int flags); static void ipmr_expire_process(struct timer_list *t); @@ -2410,7 +2410,7 @@ static size_t igmpmsg_netlink_msgsize(size_t payloadlen) return len; } -static void igmpmsg_netlink_event(struct mr_table *mrt, struct sk_buff *pkt) +static void igmpmsg_netlink_event(const struct mr_table *mrt, struct sk_buff *pkt) { struct net *net = read_pnet(&mrt->net); struct nlmsghdr *nlh; From patchwork Wed Jun 22 05:12:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12890148 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19525C43334 for ; Wed, 22 Jun 2022 05:13:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356733AbiFVFNM (ORCPT ); Wed, 22 Jun 2022 01:13:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356625AbiFVFNJ (ORCPT ); Wed, 22 Jun 2022 01:13:09 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DE4534B82 for ; Tue, 21 Jun 2022 22:13:08 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id l6-20020a25bf86000000b00668c915a3f2so10477245ybk.4 for ; Tue, 21 Jun 2022 22:13:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=mZRbJA5T4re50Qrp6655mQ8KrSQgpuu0qDvl8PjRB/M=; b=kY3pDd7DhbHn07dJS5j0VF6hsXgQcYcXTT23pOoOj+rgYDKMa4F9LzTbhIodEiwQ7O dYMrbjg09GWJI56iyAnm9kQAElVdA4+NjJjZZJ5V6G0djj992j+/9y0qyEFpK/rVKyaF O+CG22Try8fgzgt2lBFpCTjojLCArR0ImX07PjecIDvl3ikynDipz0RLAEX88aN15kpw Z76shgF92QGzNMnRn1K9/FmRyQruSt0t+w3pdohrwmmCS8uPdyVlxxKBxYBRFZ30C/mz 4Kv4Z2D/BLgfJxRdwVeG+Kvbp/c4FxabJGllFDAjKSaXwSyNW0koI46swikZTrFydWrH kfqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=mZRbJA5T4re50Qrp6655mQ8KrSQgpuu0qDvl8PjRB/M=; b=EqMIVs4yoH31t/l2l6CYfuj8Lhm0ezvcRdCmW6HcqlIfYuH/EwRRvTSPS/NgslUnG8 uHx0LTMnfAa3eM/2xai+LL8uBym+W5yG202pJY7pDfOjT0gKGP2N7UHDvkR/kLfd7XWb uyBeEP4h+ih8mFChpdNXKniG0kctxFMefUnfQvv7RFIlZgz35BbzOjX658ZtyManWb1Q 8vL5FMR831+9lXrTdpYtSUJHlpilqiacpcOwuRLbMSiDCCFSPyC98A3P8+1u4HwiPiCN gaJRSvFd76URGQHInpRGTojbEtUEhCzPCiqO73hZAKO4oygr8siSITGVN63T8xKqaRqQ WS6g== X-Gm-Message-State: AJIora+69iuTihANvH21euQuOVVrs9f9orjf1ZZ/zyvUuR/9llCfYjOT VhuyEPrgImTWT2Ap3yAR+a+xM4vxWUBnQg== X-Google-Smtp-Source: AGRyM1vhQDnbazpnoLktp8Y4aoUUIylELGj8s5yWlRgXItCKe19PwntY5XPYquy6VT7vkg0u2wNRLUxKfPs/Dw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a0d:d7c7:0:b0:317:bfe8:4f2 with SMTP id z190-20020a0dd7c7000000b00317bfe804f2mr2146007ywd.276.1655874787878; Tue, 21 Jun 2022 22:13:07 -0700 (PDT) Date: Wed, 22 Jun 2022 05:12:40 +0000 In-Reply-To: <20220622051255.700309-1-edumazet@google.com> Message-Id: <20220622051255.700309-5-edumazet@google.com> Mime-Version: 1.0 References: <20220622051255.700309-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH net-next 04/19] ipmr: ipmr_cache_report() changes From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org ipmr_cache_report() first argument can be marked const, and we change the caller convention about which lock needs to be held. Instead of read_lock(&mrt_lock), we can use rcu_read_lock(). Signed-off-by: Eric Dumazet --- net/ipv4/ipmr.c | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 6710324497cae3bbc2fcdd12d6e1d44eed5215b3..8fe7a688cf41deeb99c7ca554f1788a956d2fdb9 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -106,7 +106,7 @@ static void ipmr_free_table(struct mr_table *mrt); static void ip_mr_forward(struct net *net, struct mr_table *mrt, struct net_device *dev, struct sk_buff *skb, struct mfc_cache *cache, int local); -static int ipmr_cache_report(struct mr_table *mrt, +static int ipmr_cache_report(const struct mr_table *mrt, struct sk_buff *pkt, vifi_t vifi, int assert); static void mroute_netlink_event(struct mr_table *mrt, struct mfc_cache *mfc, int cmd); @@ -507,11 +507,15 @@ static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, struct net_device *dev) return err; } - read_lock(&mrt_lock); dev->stats.tx_bytes += skb->len; dev->stats.tx_packets++; - ipmr_cache_report(mrt, skb, mrt->mroute_reg_vif_num, IGMPMSG_WHOLEPKT); - read_unlock(&mrt_lock); + rcu_read_lock(); + + /* Pairs with WRITE_ONCE() in vif_add() and vif_delete() */ + ipmr_cache_report(mrt, skb, READ_ONCE(mrt->mroute_reg_vif_num), + IGMPMSG_WHOLEPKT); + + rcu_read_unlock(); kfree_skb(skb); return NETDEV_TX_OK; } @@ -665,9 +669,10 @@ static int vif_delete(struct mr_table *mrt, int vifi, int notify, vifi, mrt->id); RCU_INIT_POINTER(v->dev, NULL); - if (vifi == mrt->mroute_reg_vif_num) - mrt->mroute_reg_vif_num = -1; - + if (vifi == mrt->mroute_reg_vif_num) { + /* Pairs with READ_ONCE() in ipmr_cache_report() and reg_vif_xmit() */ + WRITE_ONCE(mrt->mroute_reg_vif_num, -1); + } if (vifi + 1 == mrt->maxvif) { int tmp; @@ -895,8 +900,10 @@ static int vif_add(struct net *net, struct mr_table *mrt, write_lock_bh(&mrt_lock); rcu_assign_pointer(v->dev, dev); netdev_tracker_alloc(dev, &v->dev_tracker, GFP_ATOMIC); - if (v->flags & VIFF_REGISTER) - mrt->mroute_reg_vif_num = vifi; + if (v->flags & VIFF_REGISTER) { + /* Pairs with READ_ONCE() in ipmr_cache_report() and reg_vif_xmit() */ + WRITE_ONCE(mrt->mroute_reg_vif_num, vifi); + } if (vifi+1 > mrt->maxvif) mrt->maxvif = vifi+1; write_unlock_bh(&mrt_lock); @@ -1005,9 +1012,9 @@ static void ipmr_cache_resolve(struct net *net, struct mr_table *mrt, /* Bounce a cache query up to mrouted and netlink. * - * Called under mrt_lock. + * Called under rcu_read_lock(). */ -static int ipmr_cache_report(struct mr_table *mrt, +static int ipmr_cache_report(const struct mr_table *mrt, struct sk_buff *pkt, vifi_t vifi, int assert) { const int ihl = ip_hdrlen(pkt); @@ -1042,8 +1049,11 @@ static int ipmr_cache_report(struct mr_table *mrt, msg->im_vif = vifi; msg->im_vif_hi = vifi >> 8; } else { - msg->im_vif = mrt->mroute_reg_vif_num; - msg->im_vif_hi = mrt->mroute_reg_vif_num >> 8; + /* Pairs with WRITE_ONCE() in vif_add() and vif_delete() */ + int vif_num = READ_ONCE(mrt->mroute_reg_vif_num); + + msg->im_vif = vif_num; + msg->im_vif_hi = vif_num >> 8; } ip_hdr(skb)->ihl = sizeof(struct iphdr) >> 2; ip_hdr(skb)->tot_len = htons(ntohs(ip_hdr(pkt)->tot_len) + @@ -1068,10 +1078,8 @@ static int ipmr_cache_report(struct mr_table *mrt, skb->transport_header = skb->network_header; } - rcu_read_lock(); mroute_sk = rcu_dereference(mrt->mroute_sk); if (!mroute_sk) { - rcu_read_unlock(); kfree_skb(skb); return -EINVAL; } @@ -1080,7 +1088,7 @@ static int ipmr_cache_report(struct mr_table *mrt, /* Deliver to mrouted */ ret = sock_queue_rcv_skb(mroute_sk, skb); - rcu_read_unlock(); + if (ret < 0) { net_warn_ratelimited("mroute: pending queue full, dropping entries\n"); kfree_skb(skb); @@ -1090,6 +1098,7 @@ static int ipmr_cache_report(struct mr_table *mrt, } /* Queue a packet for resolution. It gets locked cache entry! */ +/* Called under rcu_read_lock() */ static int ipmr_cache_unresolved(struct mr_table *mrt, vifi_t vifi, struct sk_buff *skb, struct net_device *dev) { @@ -1830,7 +1839,9 @@ static void ipmr_queue_xmit(struct net *net, struct mr_table *mrt, vif->bytes_out += skb->len; vif_dev->stats.tx_bytes += skb->len; vif_dev->stats.tx_packets++; + rcu_read_lock(); ipmr_cache_report(mrt, skb, vifi, IGMPMSG_WHOLEPKT); + rcu_read_unlock(); goto out_free; } @@ -1980,10 +1991,12 @@ static void ip_mr_forward(struct net *net, struct mr_table *mrt, c->_c.mfc_un.res.last_assert + MFC_ASSERT_THRESH)) { c->_c.mfc_un.res.last_assert = jiffies; + rcu_read_lock(); ipmr_cache_report(mrt, skb, true_vifi, IGMPMSG_WRONGVIF); if (mrt->mroute_do_wrvifwhole) ipmr_cache_report(mrt, skb, true_vifi, IGMPMSG_WRVIFWHOLE); + rcu_read_unlock(); } goto dont_forward; } From patchwork Wed Jun 22 05:12:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12890156 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 601C0C433EF for ; Wed, 22 Jun 2022 05:13:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356759AbiFVFNY (ORCPT ); Wed, 22 Jun 2022 01:13:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356622AbiFVFNL (ORCPT ); Wed, 22 Jun 2022 01:13:11 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B110A34B80 for ; Tue, 21 Jun 2022 22:13:10 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id v191-20020a25c5c8000000b00663d6d41f5aso13753693ybe.12 for ; Tue, 21 Jun 2022 22:13:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=EvQ1EeBfzcaZ2NY/562e7h1W6s3GP0FJiq4bYltHlnA=; b=Qw2yU4sXT/dMWDllGXWWW4aEff3DuHl5z33dytP0ZXc+T+x/GEtu7jJ3N9P+jGx6Nn DGJY3YGdNI24M4qC7g9oTFj7U0OupGrqs79w35bmc/pv+zAy80vcoV9URU07W2CRygD0 qIxEjFzUNw2s73SasD1a8ncVGw67QwJHTnAKCgu2ZVVsWO3aGANVC+x5ZQ9xe+OYseMX 0pX7Yfhj+IeDraTI9iUvQ92+jbSqNMg2es2PTPkpqEOVg2ZhBSPsxW8bIiA1kXwrRjNY M7QCGawSsf1lyjYa0hiG5v5bygTQn00xNP7FyPreeAM/n8za9tri5hUUhJGfNfuF7sQW cEUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=EvQ1EeBfzcaZ2NY/562e7h1W6s3GP0FJiq4bYltHlnA=; b=u5nZCuA+mENhBuuaQxdmswSan9gQPQnsJKi7xBjBzABQRoyTTR8kSYwxxOverqmezb oOp488YFpA9HxvTZ0n3buwRsm+CaXmJ7RbkgoMW9jJ++XklYs37aPu9cKKEu2e8tvQUW 9NgK68Ou0/4kPPnwOMTvpN2Lxz8f3zJz0wJW09ozYWqSeXD6VY3qr3PTTynKuYHOgXSy 14Hh27kl08HqA6+Q0K2fjTdfEQ/IIqBoxy1T31LKIxePmpd3bNrjzZfsYMNQVq4NGwSf 0NgFt4NOebecez2AXMQMhCrmYDjS56p2PQ8jXE8swvy7N7lMXBtwFBkW4VmJvq531sIm 9Gnw== X-Gm-Message-State: AJIora/cXGQJd19JL0N5lKx7k/YOdhuFoii8eD0A7kDQ2yOWr8ARIwN+ +MOatX+siZ5MxZMpox5NkRjBikx2lK3SzA== X-Google-Smtp-Source: AGRyM1vdIm5oHQd9A/2fCJdGCj1W9VA5d5iSHOF4hMAk2MNiAp/2Z4E797MdBGoD8umDstWVqHtWley9Ceqp4w== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:690c:3a1:b0:317:7c2d:a81a with SMTP id bh33-20020a05690c03a100b003177c2da81amr2179165ywb.380.1655874789563; Tue, 21 Jun 2022 22:13:09 -0700 (PDT) Date: Wed, 22 Jun 2022 05:12:41 +0000 In-Reply-To: <20220622051255.700309-1-edumazet@google.com> Message-Id: <20220622051255.700309-6-edumazet@google.com> Mime-Version: 1.0 References: <20220622051255.700309-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH net-next 05/19] ipmr: do not acquire mrt_lock in __pim_rcv() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org rcu_read_lock() protection is more than enough. vif_dev_read() supports either mrt_lock or rcu_read_lock(). Signed-off-by: Eric Dumazet --- net/ipv4/ipmr.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 8fe7a688cf41deeb99c7ca554f1788a956d2fdb9..8a94f9a459cd077d74b5e38c3d2f248620d4ecfc 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -582,6 +582,7 @@ static int __pim_rcv(struct mr_table *mrt, struct sk_buff *skb, { struct net_device *reg_dev = NULL; struct iphdr *encap; + int vif_num; encap = (struct iphdr *)(skb_transport_header(skb) + pimlen); /* Check that: @@ -594,11 +595,10 @@ static int __pim_rcv(struct mr_table *mrt, struct sk_buff *skb, ntohs(encap->tot_len) + pimlen > skb->len) return 1; - read_lock(&mrt_lock); - if (mrt->mroute_reg_vif_num >= 0) - reg_dev = vif_dev_read(&mrt->vif_table[mrt->mroute_reg_vif_num]); - read_unlock(&mrt_lock); - + /* Pairs with WRITE_ONCE() in vif_add()/vid_delete() */ + vif_num = READ_ONCE(mrt->mroute_reg_vif_num); + if (vif_num >= 0) + reg_dev = vif_dev_read(&mrt->vif_table[vif_num]); if (!reg_dev) return 1; From patchwork Wed Jun 22 05:12:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12890158 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 727B6C433EF for ; Wed, 22 Jun 2022 05:13:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356920AbiFVFN1 (ORCPT ); Wed, 22 Jun 2022 01:13:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356783AbiFVFNM (ORCPT ); Wed, 22 Jun 2022 01:13:12 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1B5035A88 for ; Tue, 21 Jun 2022 22:13:11 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-317bfb7aaacso68225167b3.1 for ; Tue, 21 Jun 2022 22:13:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Q6zxvPds/JEM81DuSyUCoS9FcG5gc9gJ3cgYpcc9rFw=; b=qsYiWrkfm+NDL6WamE5xDK/htzaG7INzh7PNSREvciuG+ZXkJ73MIjy3TPJ6ecmPVH qcmXrzMAvN5xLoHjyOnaYF8zl0Yw55ALcQS+Pxus61exiR3kFrZHBMYzdLo12NgUVE9p l4E/GSjw/1SwjNO+KMJDtpbi+2J+GfXeKDJZMckTvW8S9SZoQxtxEy0Kz/4re3H22Kgb 4nQ5GxE6znp5lcr6hreSC151wBSpStCnNrClJ3hCtHEcbIGnw11+vBoOPK/qeIoQ8JsG y+KmkxAH3r4aYwTl1gsckm2aWXWFQPKlendBOVBgLQ13N2QcVxpD/9vAfpmvdgDsQ/I+ JHvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Q6zxvPds/JEM81DuSyUCoS9FcG5gc9gJ3cgYpcc9rFw=; b=mAzX+4u5ICPUxnItMr2bxKuDurGu1yGeCnbupc/JTSOiDcCYGt4DGMfB+narHMzOxu 5WVx5F7XsTj+9r9qb9YHwQKW9L9Rf8FVC1K1UUoxz1/tZYfrK94p/CThzzMJnXVcEo/8 AWRIG0mK3kFxtlX7GmeqXCQEoNr0tQTZfwDYHiJNt+ACWETExOOFVXdxwK4CesV015FA GPmODND8cPclIRbYyREc434GDA3H8Ti5pIECJ9/hC1dWO2ejAeLd2gfPE3BnqcpMuKR0 iDn7A5PalHnhD1xEjkW6idLrVeDOtNTv2As14CaaKm5hHgDY1RjmNFAsnnBMyvJJKwGS MnHw== X-Gm-Message-State: AJIora+omPC9UKyKz8PeMzPC0bN/y72ZFNVL8TyDBR3vBvZ/zry92IM9 +ONveX/+t2CwxVVgF1neYgvbxY33sEORUw== X-Google-Smtp-Source: AGRyM1vnvXFM39fDMQqt29WqHKdME9ih9kqdT/oESYFdxf4puQCiliC91fy8fTQPA0w4zXWOocDQlIYWVpu+vA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a0d:cad1:0:b0:318:1eeb:3cce with SMTP id m200-20020a0dcad1000000b003181eeb3ccemr2132544ywd.371.1655874791141; Tue, 21 Jun 2022 22:13:11 -0700 (PDT) Date: Wed, 22 Jun 2022 05:12:42 +0000 In-Reply-To: <20220622051255.700309-1-edumazet@google.com> Message-Id: <20220622051255.700309-7-edumazet@google.com> Mime-Version: 1.0 References: <20220622051255.700309-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH net-next 06/19] ipmr: do not acquire mrt_lock in ioctl(SIOCGETVIFCNT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org rcu_read_lock() protection is good enough. Signed-off-by: Eric Dumazet --- net/ipv4/ipmr.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 8a94f9a459cd077d74b5e38c3d2f248620d4ecfc..bc8b7504fde6ec3aadd6c0962f23e59c0aac702a 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -1611,20 +1611,20 @@ int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg) if (vr.vifi >= mrt->maxvif) return -EINVAL; vr.vifi = array_index_nospec(vr.vifi, mrt->maxvif); - read_lock(&mrt_lock); + rcu_read_lock(); vif = &mrt->vif_table[vr.vifi]; if (VIF_EXISTS(mrt, vr.vifi)) { - vr.icount = vif->pkt_in; - vr.ocount = vif->pkt_out; - vr.ibytes = vif->bytes_in; - vr.obytes = vif->bytes_out; - read_unlock(&mrt_lock); + vr.icount = READ_ONCE(vif->pkt_in); + vr.ocount = READ_ONCE(vif->pkt_out); + vr.ibytes = READ_ONCE(vif->bytes_in); + vr.obytes = READ_ONCE(vif->bytes_out); + rcu_read_unlock(); if (copy_to_user(arg, &vr, sizeof(vr))) return -EFAULT; return 0; } - read_unlock(&mrt_lock); + rcu_read_unlock(); return -EADDRNOTAVAIL; case SIOCGETSGCNT: if (copy_from_user(&sr, arg, sizeof(sr))) @@ -1686,20 +1686,20 @@ int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg) if (vr.vifi >= mrt->maxvif) return -EINVAL; vr.vifi = array_index_nospec(vr.vifi, mrt->maxvif); - read_lock(&mrt_lock); + rcu_read_lock(); vif = &mrt->vif_table[vr.vifi]; if (VIF_EXISTS(mrt, vr.vifi)) { - vr.icount = vif->pkt_in; - vr.ocount = vif->pkt_out; - vr.ibytes = vif->bytes_in; - vr.obytes = vif->bytes_out; - read_unlock(&mrt_lock); + vr.icount = READ_ONCE(vif->pkt_in); + vr.ocount = READ_ONCE(vif->pkt_out); + vr.ibytes = READ_ONCE(vif->bytes_in); + vr.obytes = READ_ONCE(vif->bytes_out); + rcu_read_unlock(); if (copy_to_user(arg, &vr, sizeof(vr))) return -EFAULT; return 0; } - read_unlock(&mrt_lock); + rcu_read_unlock(); return -EADDRNOTAVAIL; case SIOCGETSGCNT: if (copy_from_user(&sr, arg, sizeof(sr))) @@ -1835,8 +1835,8 @@ static void ipmr_queue_xmit(struct net *net, struct mr_table *mrt, goto out_free; if (vif->flags & VIFF_REGISTER) { - vif->pkt_out++; - vif->bytes_out += skb->len; + WRITE_ONCE(vif->pkt_out, vif->pkt_out + 1); + WRITE_ONCE(vif->bytes_out, vif->bytes_out + skb->len); vif_dev->stats.tx_bytes += skb->len; vif_dev->stats.tx_packets++; rcu_read_lock(); @@ -1885,8 +1885,8 @@ static void ipmr_queue_xmit(struct net *net, struct mr_table *mrt, goto out_free; } - vif->pkt_out++; - vif->bytes_out += skb->len; + WRITE_ONCE(vif->pkt_out, vif->pkt_out + 1); + WRITE_ONCE(vif->bytes_out, vif->bytes_out + skb->len); skb_dst_drop(skb); skb_dst_set(skb, &rt->dst); @@ -2002,8 +2002,10 @@ static void ip_mr_forward(struct net *net, struct mr_table *mrt, } forward: - mrt->vif_table[vif].pkt_in++; - mrt->vif_table[vif].bytes_in += skb->len; + WRITE_ONCE(mrt->vif_table[vif].pkt_in, + mrt->vif_table[vif].pkt_in + 1); + WRITE_ONCE(mrt->vif_table[vif].bytes_in, + mrt->vif_table[vif].bytes_in + skb->len); /* Forward the frame */ if (c->mfc_origin == htonl(INADDR_ANY) && From patchwork Wed Jun 22 05:12:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12890157 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13469C43334 for ; Wed, 22 Jun 2022 05:13:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356900AbiFVFNZ (ORCPT ); Wed, 22 Jun 2022 01:13:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356785AbiFVFNO (ORCPT ); Wed, 22 Jun 2022 01:13:14 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F13535DE0 for ; Tue, 21 Jun 2022 22:13:13 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id a8-20020a25a188000000b0066839c45fe8so13667064ybi.17 for ; Tue, 21 Jun 2022 22:13:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ieF6vXeFFn+xrybKfdCGWxcLeig/WsIdEGabofxCaJA=; b=Ki9W8TSOm3tpM/R59XTy7+HEmQNJ+yyYp/zy9EDTXbTS59dHkPbTQTSLakAsYj0sbZ gFxkfC7szyIzFmmp4KdzHCWE3aai/cwlBp+Dhj0VgNqsSaxVTR9UX+TUJX6HH2lfsoQl vpBfDsuJNDbxhFaiQcNQy583Dsst/39SDg64QyuhXBoOEvivaYPuNkmUDkQaHmnHmTBH LfdBDmpKT2DySSCo6trMFdkksy0WTi1wIzlrbZiYhctcG7rprdB6mZqPd62Ik2Gguwn5 DdopCiQ4oCohwYFIlCKpBQgZ4YODHyAo1IAJrd6oXfY4Pan1kj5BfXS+DI06Z8LT+DtE ljeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ieF6vXeFFn+xrybKfdCGWxcLeig/WsIdEGabofxCaJA=; b=pShmhz9HuK/CiHcHGfHvnWsZy6t9jpuf+rUWer1/JApRBTsD5HL9YRdGfB5k2r3FCE mnc+rkovdTYrxK3mZwxH22b4JYL+LT+c9+PblHIH7tpzH5iMqHQl1yxm/nR5Y3pOw026 Jl1YeIYo2X9TSvrUZdtdnNODiqnEculmpVKk/FQgo1/sXJltWN+oNYZWgwcBm4RojVlO 2diWEMthbrPKYosSv3pNbljhdZ7j3dWDVptJb9tc0ryFhPQXnaZjdFLA+w5zZDRhqKQE WkiPxaEMmfn7dJYeT5U5dXJ049cahDz4poTkcrCwmJY/Ky7LrRzOOIHHlYxDrp91nbU4 gprA== X-Gm-Message-State: AJIora+MroFkfoB1as96ZrfzFXdhBFTdRgCpOpT+mZ6cUIzsbDv+LazO A7V844YTYp6AOddlBdg/djtm8i8cI+pXOg== X-Google-Smtp-Source: AGRyM1vtZoul9UPlxBorPds7I9CObhq9CYIyevLna7uS+pyPLa1xvRSuSutm7S7B7JgjxQX/ex8d3v3WKAhb/Q== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:30c1:0:b0:64d:f030:b01a with SMTP id w184-20020a2530c1000000b0064df030b01amr1732098ybw.330.1655874792831; Tue, 21 Jun 2022 22:13:12 -0700 (PDT) Date: Wed, 22 Jun 2022 05:12:43 +0000 In-Reply-To: <20220622051255.700309-1-edumazet@google.com> Message-Id: <20220622051255.700309-8-edumazet@google.com> Mime-Version: 1.0 References: <20220622051255.700309-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH net-next 07/19] ipmr: do not acquire mrt_lock before calling ipmr_cache_unresolved() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org rcu_read_lock() protection is good enough. ipmr_cache_unresolved() uses a dedicated spinlock (mfc_unres_lock) Signed-off-by: Eric Dumazet --- net/ipv4/ipmr.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index bc8b7504fde6ec3aadd6c0962f23e59c0aac702a..6ea54bc3d9b6555aaa9974d81ba4acd47481724f 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -680,7 +680,7 @@ static int vif_delete(struct mr_table *mrt, int vifi, int notify, if (VIF_EXISTS(mrt, tmp)) break; } - mrt->maxvif = tmp+1; + WRITE_ONCE(mrt->maxvif, tmp + 1); } write_unlock_bh(&mrt_lock); @@ -905,7 +905,7 @@ static int vif_add(struct net *net, struct mr_table *mrt, WRITE_ONCE(mrt->mroute_reg_vif_num, vifi); } if (vifi+1 > mrt->maxvif) - mrt->maxvif = vifi+1; + WRITE_ONCE(mrt->maxvif, vifi + 1); write_unlock_bh(&mrt_lock); call_ipmr_vif_entry_notifiers(net, FIB_EVENT_VIF_ADD, v, dev, vifi, mrt->id); @@ -1923,11 +1923,12 @@ static void ipmr_queue_xmit(struct net *net, struct mr_table *mrt, kfree_skb(skb); } -static int ipmr_find_vif(struct mr_table *mrt, struct net_device *dev) +/* Called with mrt_lock or rcu_read_lock() */ +static int ipmr_find_vif(const struct mr_table *mrt, struct net_device *dev) { int ct; - - for (ct = mrt->maxvif-1; ct >= 0; ct--) { + /* Pairs with WRITE_ONCE() in vif_delete()/vif_add() */ + for (ct = READ_ONCE(mrt->maxvif) - 1; ct >= 0; ct--) { if (rcu_access_pointer(mrt->vif_table[ct].dev) == dev) break; } @@ -2161,15 +2162,9 @@ int ip_mr_input(struct sk_buff *skb) skb = skb2; } - read_lock(&mrt_lock); vif = ipmr_find_vif(mrt, dev); - if (vif >= 0) { - int err2 = ipmr_cache_unresolved(mrt, vif, skb, dev); - read_unlock(&mrt_lock); - - return err2; - } - read_unlock(&mrt_lock); + if (vif >= 0) + return ipmr_cache_unresolved(mrt, vif, skb, dev); kfree_skb(skb); return -ENODEV; } @@ -2273,18 +2268,15 @@ int ipmr_get_route(struct net *net, struct sk_buff *skb, int vif = -1; dev = skb->dev; - read_lock(&mrt_lock); if (dev) vif = ipmr_find_vif(mrt, dev); if (vif < 0) { - read_unlock(&mrt_lock); rcu_read_unlock(); return -ENODEV; } skb2 = skb_realloc_headroom(skb, sizeof(struct iphdr)); if (!skb2) { - read_unlock(&mrt_lock); rcu_read_unlock(); return -ENOMEM; } @@ -2298,7 +2290,6 @@ int ipmr_get_route(struct net *net, struct sk_buff *skb, iph->daddr = daddr; iph->version = 0; err = ipmr_cache_unresolved(mrt, vif, skb2, dev); - read_unlock(&mrt_lock); rcu_read_unlock(); return err; } From patchwork Wed Jun 22 05:12:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12890160 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2AA0C43334 for ; Wed, 22 Jun 2022 05:13:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356939AbiFVFN2 (ORCPT ); Wed, 22 Jun 2022 01:13:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356912AbiFVFNT (ORCPT ); Wed, 22 Jun 2022 01:13:19 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A081535DE5 for ; Tue, 21 Jun 2022 22:13:14 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id m68-20020a253f47000000b006683bd91962so13762599yba.0 for ; Tue, 21 Jun 2022 22:13:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=MbAa01ayooLRjvmZvMsHwzRjI7CpSiorxRvp5VWlJKg=; b=lFxaMyJoMNDYKOZnodD1Q75etFtJnz/kbZF+a+wBiWlzEpGzQZNjTPeivJK+BhAjOg /L4M8jbibxdtTLJGTq5Evi6qUxV1y9rc1VBzfspVeekCn45WzPmzXZq6g7nS1pE9eahf anRtvBNdiu04AkP75v2OCSUYU+sZdtmnP6nX+vMPPAc0nVcHGBAAsX0gVAGjfBRpjBL0 xo0rkj7Hlnik9dTjw26mhAmBJtta5Jpk9jqS41x8s71AM8fl4UrmDYgOJS5khGqV74r9 tpILDkaoOsKH7XVUpqRVIswFJjlAhgARw485WqJh82n0A5QRXDTn4FZBZ8z5D9msLnXt 9/Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=MbAa01ayooLRjvmZvMsHwzRjI7CpSiorxRvp5VWlJKg=; b=zlMyV/Cv1fI625xgNN9sK9ES98Y9wGPtkI3QMG6pnbAaC0OdfbYOGBW3qkkd2vbN9W NMASeZzqafGCp/+BvNQsOtny5wHpPau8pd362qARpiXrw2YPJtnp419YlbqS/GvtQNH1 NUO/swXeO1X39sBVWffhnNEf04fFWvhAyDG8eUs8Nl0Qkk6IwhIBjLvIXvQT7QhMCKU6 2E+7ZuTJkHmIOgYnlMZugLcAQ3owAibcQCt7cSMx1mjcazzbazMTJW75mRhsWfO8mgcE aG4pYCrpTenrlGmrPT5RAk519/xSuspEbANQqXR/A2p1XW7MhmLInxjIcDqw6ATdv2CI r1CQ== X-Gm-Message-State: AJIora9A9b8LzrqF1Dt8q9WVF+Bx1GG+N2Rv6Y/bzddTci4m4OKoYRj6 u1Ekm5zeT+fn5GhnqKNglDUQEX3FXhRVog== X-Google-Smtp-Source: AGRyM1sPBtsgreVfUCk2KH/JF6UCLMGB0N2QZSw76EbKMDXlrnzfHH4W9hK5NAZpV+vLK7ecGdNNMMRd2eVD+g== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:6d55:0:b0:317:90a6:83b1 with SMTP id i82-20020a816d55000000b0031790a683b1mr2138253ywc.170.1655874794444; Tue, 21 Jun 2022 22:13:14 -0700 (PDT) Date: Wed, 22 Jun 2022 05:12:44 +0000 In-Reply-To: <20220622051255.700309-1-edumazet@google.com> Message-Id: <20220622051255.700309-9-edumazet@google.com> Mime-Version: 1.0 References: <20220622051255.700309-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH net-next 08/19] ipmr: do not acquire mrt_lock while calling ip_mr_forward() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org ip_mr_forward() uses standard RCU protection already. Signed-off-by: Eric Dumazet --- net/ipv4/ipmr.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 6ea54bc3d9b6555aaa9974d81ba4acd47481724f..b0f2e6d79d62273c8c2682f28cb45fe5ec3df6f3 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -1817,7 +1817,7 @@ static bool ipmr_forward_offloaded(struct sk_buff *skb, struct mr_table *mrt, } #endif -/* Processing handlers for ipmr_forward */ +/* Processing handlers for ipmr_forward, under rcu_read_lock() */ static void ipmr_queue_xmit(struct net *net, struct mr_table *mrt, int in_vifi, struct sk_buff *skb, int vifi) @@ -1839,9 +1839,7 @@ static void ipmr_queue_xmit(struct net *net, struct mr_table *mrt, WRITE_ONCE(vif->bytes_out, vif->bytes_out + skb->len); vif_dev->stats.tx_bytes += skb->len; vif_dev->stats.tx_packets++; - rcu_read_lock(); ipmr_cache_report(mrt, skb, vifi, IGMPMSG_WHOLEPKT); - rcu_read_unlock(); goto out_free; } @@ -1936,6 +1934,7 @@ static int ipmr_find_vif(const struct mr_table *mrt, struct net_device *dev) } /* "local" means that we should preserve one skb (for local delivery) */ +/* Called uner rcu_read_lock() */ static void ip_mr_forward(struct net *net, struct mr_table *mrt, struct net_device *dev, struct sk_buff *skb, struct mfc_cache *c, int local) @@ -1992,12 +1991,10 @@ static void ip_mr_forward(struct net *net, struct mr_table *mrt, c->_c.mfc_un.res.last_assert + MFC_ASSERT_THRESH)) { c->_c.mfc_un.res.last_assert = jiffies; - rcu_read_lock(); ipmr_cache_report(mrt, skb, true_vifi, IGMPMSG_WRONGVIF); if (mrt->mroute_do_wrvifwhole) ipmr_cache_report(mrt, skb, true_vifi, IGMPMSG_WRVIFWHOLE); - rcu_read_unlock(); } goto dont_forward; } @@ -2169,9 +2166,7 @@ int ip_mr_input(struct sk_buff *skb) return -ENODEV; } - read_lock(&mrt_lock); ip_mr_forward(net, mrt, dev, skb, cache, local); - read_unlock(&mrt_lock); if (local) return ip_local_deliver(skb); From patchwork Wed Jun 22 05:12:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12890159 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A249BC43334 for ; Wed, 22 Jun 2022 05:13:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356923AbiFVFN1 (ORCPT ); Wed, 22 Jun 2022 01:13:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356932AbiFVFNU (ORCPT ); Wed, 22 Jun 2022 01:13:20 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B970435DE7 for ; Tue, 21 Jun 2022 22:13:16 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id d6-20020a256806000000b00668a3d90e95so13749688ybc.2 for ; Tue, 21 Jun 2022 22:13:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=RObd3TiRkqvkoKMe+QwcB26i+/ARD+OA3IafA9Z7HpI=; b=fupddBHJrPixwqHCGwFKlw24Nz7HiqjO6n4cZuLnawpMh9lsheWvBHlanw2AY+1BW5 F3lrADz9q1daIJfLOGzU+LV+XuKRZ+9ula5KdwY0IW/OzcsmvSSbTgj+Zx6/HCzFUY3+ NhguBFjcxMpYLOjqHMtL9FuRi4Td105NzpvGuIxg1pediMmZ/rxYUg12RGx4D2nXiGF5 hK/lFdSWJPSrV+csmSRzUBH244qoq72JXiNDT2EQ8vD4AUDx1J7AcTOSrl4Pv0UVe8bY AzaGc1wbt2hSXq2hP+uob0RUK1cUAEvIwx02V4cZq5vaUJkurJIAJA0OvuOTpBtCi7kx oHZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=RObd3TiRkqvkoKMe+QwcB26i+/ARD+OA3IafA9Z7HpI=; b=s1NSkHgjvEO+uaV2aqfBmpOxmQMWdQAh9OrFPJLv1tvhqk7f88xKkisqTzO80HWw0L EDywDW3oxHGn6tOqysnv1/pmou1j/flWGGe+BkFC3A0gcoGjHtjawCXsljXxMq2pzQvd G80CDc+IlCYWqcpCE4+BlkTt+y6yc0j+m7ek5SbX99POVnknBnvGqkZ1XP4VuOrUMyOn bi/64rq68vn00YFPEzaEiL19+DvAn5fD8xU7X4ozOVA7nsR/x1e1iRd//mfxwqdDgXRI G87weoHylzajsQi4T8i+IHCx0nUuXeULrA6og7M/yxDY9qk38mOD6Ks3psSd8KMQz+8q 0GHg== X-Gm-Message-State: AJIora/zJKVl4xamrwxFI2ZeErTF1nGdi8Z+oF/tAdsG2PJGWLO0DDuW QFcUjtN1YTCW10kCiGG+7/+Y8zayeTHUPg== X-Google-Smtp-Source: AGRyM1t9LgNI2Pp2O85WHOAa1mqMTDEfX/dSnyhXIMCOf+8WbypzLxmelPscWCM6DiwgtSCiqi5VKRg6h+HHDw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a5b:246:0:b0:619:5651:3907 with SMTP id g6-20020a5b0246000000b0061956513907mr1884945ybp.190.1655874796065; Tue, 21 Jun 2022 22:13:16 -0700 (PDT) Date: Wed, 22 Jun 2022 05:12:45 +0000 In-Reply-To: <20220622051255.700309-1-edumazet@google.com> Message-Id: <20220622051255.700309-10-edumazet@google.com> Mime-Version: 1.0 References: <20220622051255.700309-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH net-next 09/19] ipmr: do not acquire mrt_lock in ipmr_get_route() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org mr_fill_mroute() uses standard rcu_read_unlock(), no need to grab mrt_lock anymore. Signed-off-by: Eric Dumazet --- net/ipv4/ipmr.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index b0f2e6d79d62273c8c2682f28cb45fe5ec3df6f3..69ccd3d7c655a53d3cf1ac9104b9da94213416f6 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -2289,9 +2289,7 @@ int ipmr_get_route(struct net *net, struct sk_buff *skb, return err; } - read_lock(&mrt_lock); err = mr_fill_mroute(mrt, skb, &cache->_c, rtm); - read_unlock(&mrt_lock); rcu_read_unlock(); return err; } From patchwork Wed Jun 22 05:12:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12890169 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4813CCA47A for ; Wed, 22 Jun 2022 05:15:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356131AbiFVFPQ (ORCPT ); Wed, 22 Jun 2022 01:15:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356975AbiFVFNW (ORCPT ); Wed, 22 Jun 2022 01:13:22 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7657D35DEA for ; Tue, 21 Jun 2022 22:13:18 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-317f6128c86so47401857b3.22 for ; Tue, 21 Jun 2022 22:13:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=VrbWSc5Rvr0QaUW4lFQUf++mBAUZtrxHkQQzmsdcRk0=; b=lFr8g+J2yygc7gP9acMYbX5p+2YxnlA29iCFvRqAdN6Lv7RE7M7lj2DDJYii1iPbDR YIZuhKubKqHl7rh9CNgJ1WenmdP7NPSsSJsg++Uka1rZPNTvn9HKxxPnTgNoIRS+Almw 3DhvPt26Qnq/ztIbGFaU9qp3NFeO7iFPWYiYZRRtBqtNs8QQWeENs3GQ0VwD+VHs/K1h OraB2Xi6ILSUpbV5XZ9hFc6ob5UnRDK3fQJ+CFte6DOfEcyDetuDvZb7hI/uzMwOt3BQ K1gNDYhOMJEhCtpBmLVdEes2BUD2voyo+bD35YeivE8Qc26OyTWRo0FL0qzxGzUM4DlU xinw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=VrbWSc5Rvr0QaUW4lFQUf++mBAUZtrxHkQQzmsdcRk0=; b=OgX2D+q9e24aCYqO9onN7eJogHAuKB90HO+8jO92Nd9OfyIUqC4uHlXyddT4CaAqj5 4Wjgw6KKcDZ+u4eLR8ceVf7kjklT4DyzYbmIxgWbpf/ZC/rvV3F0Lwzn9br7y8szqz0f 7cZaLoGZ9HjFlyQspsuDGkN8dl3Z73DDt4nBZvaaKPXL6hcEC1C90tfeIzkClJRS/rRH QX+pLRrNhLAk15cTGLctBxkuOFPXkmrcM3h2oWuZgKzv933SSXM8ZZdUFgGi8zRJf8SO 1g+8pI57IdQGu+g+tlwG5Y7BQhOGd51ajAkgBg5iA0nGuisox8g/yJH5ni7CiDEMI+1E 05rA== X-Gm-Message-State: AJIora83hab3qXrom+Esxum0+JufQ+vgWFrcKWJTRoo1vWDFEPQ/sels DrmNcMOyVZqRRu3Ku3EHetdTtZGLljPAlw== X-Google-Smtp-Source: AGRyM1thzYG74QoIY75/LFGIjygNwZzH23N6wgF7a/Enu1Znz5QyHrD77/VPxVD/87xv0359eFBssQz81Dld9w== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:5ad4:0:b0:317:7320:4c23 with SMTP id o203-20020a815ad4000000b0031773204c23mr2018505ywb.520.1655874797836; Tue, 21 Jun 2022 22:13:17 -0700 (PDT) Date: Wed, 22 Jun 2022 05:12:46 +0000 In-Reply-To: <20220622051255.700309-1-edumazet@google.com> Message-Id: <20220622051255.700309-11-edumazet@google.com> Mime-Version: 1.0 References: <20220622051255.700309-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH net-next 10/19] ip6mr: ip6mr_cache_report() changes From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org ip6mr_cache_report() first argument can be marked const, and we change the caller convention about which lock needs to be held. Instead of read_lock(&mrt_lock), we can use rcu_read_lock(). Signed-off-by: Eric Dumazet --- net/ipv6/ip6mr.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index 44cb3d88bbd6f85ce0c8e9054dd3d578b7b3733b..a6d97952bf5306c245996c612107d0c851bbc822 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -91,11 +91,11 @@ static void ip6mr_free_table(struct mr_table *mrt); static void ip6_mr_forward(struct net *net, struct mr_table *mrt, struct net_device *dev, struct sk_buff *skb, struct mfc6_cache *cache); -static int ip6mr_cache_report(struct mr_table *mrt, struct sk_buff *pkt, +static int ip6mr_cache_report(const struct mr_table *mrt, struct sk_buff *pkt, mifi_t mifi, int assert); static void mr6_netlink_event(struct mr_table *mrt, struct mfc6_cache *mfc, int cmd); -static void mrt6msg_netlink_event(struct mr_table *mrt, struct sk_buff *pkt); +static void mrt6msg_netlink_event(const struct mr_table *mrt, struct sk_buff *pkt); static int ip6mr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb); static void mroute_clean_tables(struct mr_table *mrt, int flags); @@ -608,11 +608,12 @@ static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, if (ip6mr_fib_lookup(net, &fl6, &mrt) < 0) goto tx_err; - read_lock(&mrt_lock); dev->stats.tx_bytes += skb->len; dev->stats.tx_packets++; - ip6mr_cache_report(mrt, skb, mrt->mroute_reg_vif_num, MRT6MSG_WHOLEPKT); - read_unlock(&mrt_lock); + rcu_read_lock(); + ip6mr_cache_report(mrt, skb, READ_ONCE(mrt->mroute_reg_vif_num), + MRT6MSG_WHOLEPKT); + rcu_read_unlock(); kfree_skb(skb); return NETDEV_TX_OK; @@ -718,8 +719,10 @@ static int mif6_delete(struct mr_table *mrt, int vifi, int notify, RCU_INIT_POINTER(v->dev, NULL); #ifdef CONFIG_IPV6_PIMSM_V2 - if (vifi == mrt->mroute_reg_vif_num) - mrt->mroute_reg_vif_num = -1; + if (vifi == mrt->mroute_reg_vif_num) { + /* Pairs with READ_ONCE() in ip6mr_cache_report() and reg_vif_xmit() */ + WRITE_ONCE(mrt->mroute_reg_vif_num, -1); + } #endif if (vifi + 1 == mrt->maxvif) { @@ -922,7 +925,7 @@ static int mif6_add(struct net *net, struct mr_table *mrt, netdev_tracker_alloc(dev, &v->dev_tracker, GFP_ATOMIC); #ifdef CONFIG_IPV6_PIMSM_V2 if (v->flags & MIFF_REGISTER) - mrt->mroute_reg_vif_num = vifi; + WRITE_ONCE(mrt->mroute_reg_vif_num, vifi); #endif if (vifi + 1 > mrt->maxvif) mrt->maxvif = vifi + 1; @@ -1033,10 +1036,10 @@ static void ip6mr_cache_resolve(struct net *net, struct mr_table *mrt, /* * Bounce a cache query up to pim6sd and netlink. * - * Called under mrt_lock. + * Called under rcu_read_lock() */ -static int ip6mr_cache_report(struct mr_table *mrt, struct sk_buff *pkt, +static int ip6mr_cache_report(const struct mr_table *mrt, struct sk_buff *pkt, mifi_t mifi, int assert) { struct sock *mroute6_sk; @@ -1077,7 +1080,7 @@ static int ip6mr_cache_report(struct mr_table *mrt, struct sk_buff *pkt, if (assert == MRT6MSG_WRMIFWHOLE) msg->im6_mif = mifi; else - msg->im6_mif = mrt->mroute_reg_vif_num; + msg->im6_mif = READ_ONCE(mrt->mroute_reg_vif_num); msg->im6_pad = 0; msg->im6_src = ipv6_hdr(pkt)->saddr; msg->im6_dst = ipv6_hdr(pkt)->daddr; @@ -1112,10 +1115,8 @@ static int ip6mr_cache_report(struct mr_table *mrt, struct sk_buff *pkt, skb->ip_summed = CHECKSUM_UNNECESSARY; } - rcu_read_lock(); mroute6_sk = rcu_dereference(mrt->mroute_sk); if (!mroute6_sk) { - rcu_read_unlock(); kfree_skb(skb); return -EINVAL; } @@ -1124,7 +1125,7 @@ static int ip6mr_cache_report(struct mr_table *mrt, struct sk_buff *pkt, /* Deliver to user space multicast routing algorithms */ ret = sock_queue_rcv_skb(mroute6_sk, skb); - rcu_read_unlock(); + if (ret < 0) { net_warn_ratelimited("mroute6: pending queue full, dropping entries\n"); kfree_skb(skb); @@ -2042,7 +2043,9 @@ static int ip6mr_forward2(struct net *net, struct mr_table *mrt, vif->bytes_out += skb->len; vif_dev->stats.tx_bytes += skb->len; vif_dev->stats.tx_packets++; + rcu_read_lock(); ip6mr_cache_report(mrt, skb, vifi, MRT6MSG_WHOLEPKT); + rcu_read_unlock(); goto out_free; } #endif @@ -2155,10 +2158,12 @@ static void ip6_mr_forward(struct net *net, struct mr_table *mrt, c->_c.mfc_un.res.last_assert + MFC_ASSERT_THRESH)) { c->_c.mfc_un.res.last_assert = jiffies; + rcu_read_lock(); ip6mr_cache_report(mrt, skb, true_vifi, MRT6MSG_WRONGMIF); if (mrt->mroute_do_wrvifwhole) ip6mr_cache_report(mrt, skb, true_vifi, MRT6MSG_WRMIFWHOLE); + rcu_read_unlock(); } goto dont_forward; } @@ -2465,7 +2470,7 @@ static size_t mrt6msg_netlink_msgsize(size_t payloadlen) return len; } -static void mrt6msg_netlink_event(struct mr_table *mrt, struct sk_buff *pkt) +static void mrt6msg_netlink_event(const struct mr_table *mrt, struct sk_buff *pkt) { struct net *net = read_pnet(&mrt->net); struct nlmsghdr *nlh; From patchwork Wed Jun 22 05:12:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12890161 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0490C43334 for ; Wed, 22 Jun 2022 05:13:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357032AbiFVFNe (ORCPT ); Wed, 22 Jun 2022 01:13:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356992AbiFVFNW (ORCPT ); Wed, 22 Jun 2022 01:13:22 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7310335DF8 for ; Tue, 21 Jun 2022 22:13:20 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id h82-20020a25d055000000b00668b6a4ee32so11654608ybg.3 for ; Tue, 21 Jun 2022 22:13:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=261UTc4ygE5ZNxBbiTD0X/wTjRF7aQkJ1aLKjWjIVn8=; b=p+9t8E5QOu1s/LB8JvD4VhI3LFV/y09LaTnJdaLMKcLZoph2IaYxySTtoJyugqGt0Q pywMnheABMGKW4kGhb75Nf+QMWGqQS7au1mWnJgGQS+zIsD+pz8m/EHLu560lSi6Hqya WdD0XYCdf4zFCFt3utYzDu1zKD5R869QRu18qXZYRFsj9pzFnmRn6EvtfaW3qjScOTDz IeiYwSvoaY9Mt0XlaTNEXQEg5m7dZXuG3Lcwn+937BTyYRD1o3HGnDC5HBDuueMP3y4N 8QU6ARxXLsu47VDumq5rxRthMk0kXNK8wHAeFUui3vnEA2627C77+IM9nyJISX94yndw ieMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=261UTc4ygE5ZNxBbiTD0X/wTjRF7aQkJ1aLKjWjIVn8=; b=j1fh4/KhDDZ6NYjqrTgYP1Yn7ZdG6xGqdxAZIlR9zYnIMyinrbpSH0e27zYaQMWXjT Ga60gnyeW5wlXYGVLKx//d16GgQAu8TEzGTZ81ulmBgFpAYNPRdPUf0c7OiwK7JczLyB oZvtLwG4HFmg4cP9ld6JOBGYkJTVpptwoZUQ/QSkjSQYOXOuIbWQnGofqNcrB+ECpf6k iTQd3kNN23qaz1/SOPMFmoBY8oC91NfN8y0FVw9bp+8zh91y8lymHkd89zA/4yGZRpct hrC0A95wzNU4xWgiC6erp2hw8FnJMyJbDYg6/LkoJ2YgzhPzziwuNBFeiF5oaqRPSWR8 /wLg== X-Gm-Message-State: AJIora/3Vavd7vAopet3kXIad3DSa3HEw08dCPto/r7s1t/0nEXQmiYq B27VANBnNoM91ZUciW3XfSp4TwJo/mFi2Q== X-Google-Smtp-Source: AGRyM1vmuZMmaK3j0K/7qGDDW2eWC0h74Q12D32T5ZwRYhLCZfZs3Il2vZdcU3VHnGuN2jMoNMI6GDQE3sT4kA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:e0c3:0:b0:65c:a85b:b546 with SMTP id x186-20020a25e0c3000000b0065ca85bb546mr1776479ybg.111.1655874799752; Tue, 21 Jun 2022 22:13:19 -0700 (PDT) Date: Wed, 22 Jun 2022 05:12:47 +0000 In-Reply-To: <20220622051255.700309-1-edumazet@google.com> Message-Id: <20220622051255.700309-12-edumazet@google.com> Mime-Version: 1.0 References: <20220622051255.700309-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH net-next 11/19] ip6mr: do not acquire mrt_lock in pim6_rcv() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org rcu_read_lock() protection is more than enough. vif_dev_read() supports either mrt_lock or rcu_read_lock(). Signed-off-by: Eric Dumazet --- net/ipv6/ip6mr.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index a6d97952bf5306c245996c612107d0c851bbc822..fa6720377e82d732ccafa02b37cc28e0ab1cea07 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -559,12 +559,11 @@ static int pim6_rcv(struct sk_buff *skb) if (ip6mr_fib_lookup(net, &fl6, &mrt) < 0) goto drop; - reg_vif_num = mrt->mroute_reg_vif_num; - read_lock(&mrt_lock); + /* Pairs with WRITE_ONCE() in mif6_add()/mif6_delete() */ + reg_vif_num = READ_ONCE(mrt->mroute_reg_vif_num); if (reg_vif_num >= 0) reg_dev = vif_dev_read(&mrt->vif_table[reg_vif_num]); - read_unlock(&mrt_lock); if (!reg_dev) goto drop; From patchwork Wed Jun 22 05:12:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12890162 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6FBBC433EF for ; Wed, 22 Jun 2022 05:13:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356992AbiFVFNh (ORCPT ); Wed, 22 Jun 2022 01:13:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357010AbiFVFNW (ORCPT ); Wed, 22 Jun 2022 01:13:22 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AEF234678 for ; Tue, 21 Jun 2022 22:13:22 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id g132-20020a25db8a000000b00668a2ef6a95so13649865ybf.22 for ; Tue, 21 Jun 2022 22:13:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=wU6WCF7T9LlGsf1erjP98rpgqQYf0p7+pD0Eq8p6bVo=; b=QCPqmqebglnsEXPRluifa8ufTUiEhazdOmQWKyfneVEEycPr5Kdpki9mTFbxLxF7zp a6epUJkVQ8BlQJQ42lNHa6/fIJvKlL4RfwRLhMId9tx6nYaHsqlJpAJyFeUs6dcaD+eY A9Fgp/RBIvh2eKdNfyI2OillzWUw6kkt3YAvNokrDMJytxQ81SEcaad86u2cSsHWGD1/ 03FdgIL1/e/nKOOxBdiSReUFJEonpMZa1LqdaGqRlx92iAbamM7AcTvUWm8ij6EzeY4Z FAfBYDKmhVcStYkNFyVDPZg9RmGDEfmI5JwzdJlzWIrr7Gf/aCl2Zp212qEJw/XVHkxu OpEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=wU6WCF7T9LlGsf1erjP98rpgqQYf0p7+pD0Eq8p6bVo=; b=m1Cbz1RPT/ZSPaAWV2PCiKb4g11v0vT1hp3E6kNTeBgN0MzPONYDmD3as8zVebsLOa BswyLJLseu7AnugIyq7JYIZoOLso2OqQo0vf0pHkIGmWZwPtm8RSlRCqHa2tlQeZ+fOB Jt+wJn+U6vBeLvbKeYdDzi6GewdpOwJqDCezyLeLicxFdXNR2v4Zg8pUINKjP08ECM6E QU33u+i0bAoDriSJ0Qj4PkbwzK+JDiBEvDODFWSc9jI6hFICSbhK3fzjcbJ8+oa3Oijn HCa8TbQsaP0DQoDetEyFaExQqveZ8ouVrW7aoLHFjSPkaFWPmj2B3+Eg1eNv61fVGwHy JSLg== X-Gm-Message-State: AJIora8qRh9TLUZA3wkFa5vfprTNMmh+rR+ZxLvB/GqHHSRXL7D6U70g bKY7ndDmUPKaKNmLQwfe0rNQL7rA7l9aiQ== X-Google-Smtp-Source: AGRyM1vixpAXNAkvMFzEGUpsvC1+XQ3tJXKs2QKZPBiNYiiWwwHjcTv8K6xsfKh3Z4q8YglJh3tx9v5bXg1wgQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:ca17:0:b0:664:60ce:9369 with SMTP id a23-20020a25ca17000000b0066460ce9369mr1783052ybg.455.1655874801528; Tue, 21 Jun 2022 22:13:21 -0700 (PDT) Date: Wed, 22 Jun 2022 05:12:48 +0000 In-Reply-To: <20220622051255.700309-1-edumazet@google.com> Message-Id: <20220622051255.700309-13-edumazet@google.com> Mime-Version: 1.0 References: <20220622051255.700309-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH net-next 12/19] ip6mr: do not acquire mrt_lock in ioctl(SIOCGETMIFCNT_IN6) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org rcu_read_lock() protection is good enough. Signed-off-by: Eric Dumazet --- net/ipv6/ip6mr.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index fa6720377e82d732ccafa02b37cc28e0ab1cea07..b4ad606e24bdaf12c233f642cee303f06ccfa4eb 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -1896,20 +1896,20 @@ int ip6mr_ioctl(struct sock *sk, int cmd, void __user *arg) if (vr.mifi >= mrt->maxvif) return -EINVAL; vr.mifi = array_index_nospec(vr.mifi, mrt->maxvif); - read_lock(&mrt_lock); + rcu_read_lock(); vif = &mrt->vif_table[vr.mifi]; if (VIF_EXISTS(mrt, vr.mifi)) { - vr.icount = vif->pkt_in; - vr.ocount = vif->pkt_out; - vr.ibytes = vif->bytes_in; - vr.obytes = vif->bytes_out; - read_unlock(&mrt_lock); + vr.icount = READ_ONCE(vif->pkt_in); + vr.ocount = READ_ONCE(vif->pkt_out); + vr.ibytes = READ_ONCE(vif->bytes_in); + vr.obytes = READ_ONCE(vif->bytes_out); + rcu_read_unlock(); if (copy_to_user(arg, &vr, sizeof(vr))) return -EFAULT; return 0; } - read_unlock(&mrt_lock); + rcu_read_unlock(); return -EADDRNOTAVAIL; case SIOCGETSGCNT_IN6: if (copy_from_user(&sr, arg, sizeof(sr))) @@ -1971,20 +1971,20 @@ int ip6mr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg) if (vr.mifi >= mrt->maxvif) return -EINVAL; vr.mifi = array_index_nospec(vr.mifi, mrt->maxvif); - read_lock(&mrt_lock); + rcu_read_lock(); vif = &mrt->vif_table[vr.mifi]; if (VIF_EXISTS(mrt, vr.mifi)) { - vr.icount = vif->pkt_in; - vr.ocount = vif->pkt_out; - vr.ibytes = vif->bytes_in; - vr.obytes = vif->bytes_out; - read_unlock(&mrt_lock); + vr.icount = READ_ONCE(vif->pkt_in); + vr.ocount = READ_ONCE(vif->pkt_out); + vr.ibytes = READ_ONCE(vif->bytes_in); + vr.obytes = READ_ONCE(vif->bytes_out); + rcu_read_unlock(); if (copy_to_user(arg, &vr, sizeof(vr))) return -EFAULT; return 0; } - read_unlock(&mrt_lock); + rcu_read_unlock(); return -EADDRNOTAVAIL; case SIOCGETSGCNT_IN6: if (copy_from_user(&sr, arg, sizeof(sr))) @@ -2038,8 +2038,8 @@ static int ip6mr_forward2(struct net *net, struct mr_table *mrt, #ifdef CONFIG_IPV6_PIMSM_V2 if (vif->flags & MIFF_REGISTER) { - vif->pkt_out++; - vif->bytes_out += skb->len; + WRITE_ONCE(vif->pkt_out, vif->pkt_out + 1); + WRITE_ONCE(vif->bytes_out, vif->bytes_out + skb->len); vif_dev->stats.tx_bytes += skb->len; vif_dev->stats.tx_packets++; rcu_read_lock(); @@ -2077,8 +2077,8 @@ static int ip6mr_forward2(struct net *net, struct mr_table *mrt, * result in receiving multiple packets. */ skb->dev = vif_dev; - vif->pkt_out++; - vif->bytes_out += skb->len; + WRITE_ONCE(vif->pkt_out, vif->pkt_out + 1); + WRITE_ONCE(vif->bytes_out, vif->bytes_out + skb->len); /* We are about to write */ /* XXX: extension headers? */ @@ -2168,8 +2168,10 @@ static void ip6_mr_forward(struct net *net, struct mr_table *mrt, } forward: - mrt->vif_table[vif].pkt_in++; - mrt->vif_table[vif].bytes_in += skb->len; + WRITE_ONCE(mrt->vif_table[vif].pkt_in, + mrt->vif_table[vif].pkt_in + 1); + WRITE_ONCE(mrt->vif_table[vif].bytes_in, + mrt->vif_table[vif].bytes_in + skb->len); /* * Forward the frame From patchwork Wed Jun 22 05:12:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12890163 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05E60C43334 for ; Wed, 22 Jun 2022 05:13:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357028AbiFVFNi (ORCPT ); Wed, 22 Jun 2022 01:13:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356897AbiFVFNY (ORCPT ); Wed, 22 Jun 2022 01:13:24 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15EC934B82 for ; Tue, 21 Jun 2022 22:13:24 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-317b6ecba61so71247207b3.9 for ; Tue, 21 Jun 2022 22:13:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=lhJAm38lB4oAVvBzY5Ysr2c9THun3k9dpinkYqVIY4o=; b=pmZedvPyUXhlNDtQ0Qx5wl3oxXnt38sa8B+n85gdjmMib3kGb0dR/CLa1RJPq6ngJi KrNIOwu04dZk63s/5yt4GL0s//ZU53UaXay5/QPtUAn44XN7vR977+8mFxBlSt246HtK 7LWO0dNbWr9/eKRYKuXweULrNZxWP/bX8amdfoizXDj80i46UC0FF3FYCPtDhuEyyH6n efidc2QbxAoLf9lcdR6pUhix2ZohbGGRFCR6MDlz+ve2PNLiFq3tpFEemBrE0CAkC0f6 5i55Nm0Juv51EeDJdYU04tkLgMQIsYnJdp+CeOlEZj/PxKjjkf7QGUsM5fWDvSMxMg49 Sx0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=lhJAm38lB4oAVvBzY5Ysr2c9THun3k9dpinkYqVIY4o=; b=CtyUeHEZ/G5W6CdBZnU02q0HHxEtdW+m6RcM0ruKjgSp24SoAE8dPCKd28bihDwcuK RR8lDAZHJ0bAdw74jpk/GnZa/3GW/t8//bdzZ7TzJ02I2wJW7kHkc30j3oeZZBHbQDh+ oQ2DSnFq0HAUx0i1nlzLDkBLuqmrBeA78+zUwQpRQjK8zpmGIPhdCDpiqHFvfA6sbXWr 5/fuQYqttOyrYBJ5vLRYj3znj/DqeQuF1jZEJ3jM78yXc4ReAr1WPJmenCMjnlN+0N1w VUdTvDMQi1SbfDQABWy5jVgqGgvYIRBLmwjSFKtFuiZ5Y8Lpi1S7x3yXCyR/5ZnZoT+L h9oQ== X-Gm-Message-State: AJIora/4cXy+tJoIvbvsR9ZSckKmtVrrO8v87hKJhfE8E2RmgXwvQ7/A xn9PDvEHjkezLDTXkF5U8ZC3ncJ6EgGF5g== X-Google-Smtp-Source: AGRyM1vwG9JGuwwhq7y2L4mcQxGUUR5WSvCrvmFCFrt4xCuB+c52vNQ8njyXVya4jog0s7eYiZjEdBsMW86g7A== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:1085:b0:669:1652:9f23 with SMTP id v5-20020a056902108500b0066916529f23mr1713239ybu.465.1655874803362; Tue, 21 Jun 2022 22:13:23 -0700 (PDT) Date: Wed, 22 Jun 2022 05:12:49 +0000 In-Reply-To: <20220622051255.700309-1-edumazet@google.com> Message-Id: <20220622051255.700309-14-edumazet@google.com> Mime-Version: 1.0 References: <20220622051255.700309-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH net-next 13/19] ip6mr: do not acquire mrt_lock before calling ip6mr_cache_unresolved From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org rcu_read_lock() protection is good enough. ip6mr_cache_unresolved() uses a dedicated spinlock (mfc_unres_lock) Signed-off-by: Eric Dumazet --- net/ipv6/ip6mr.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index b4ad606e24bdaf12c233f642cee303f06ccfa4eb..089c26af3120d198ccfdda631294ed9712568ac0 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -730,7 +730,7 @@ static int mif6_delete(struct mr_table *mrt, int vifi, int notify, if (VIF_EXISTS(mrt, tmp)) break; } - mrt->maxvif = tmp + 1; + WRITE_ONCE(mrt->maxvif, tmp + 1); } write_unlock_bh(&mrt_lock); @@ -927,7 +927,7 @@ static int mif6_add(struct net *net, struct mr_table *mrt, WRITE_ONCE(mrt->mroute_reg_vif_num, vifi); #endif if (vifi + 1 > mrt->maxvif) - mrt->maxvif = vifi + 1; + WRITE_ONCE(mrt->maxvif, vifi + 1); write_unlock_bh(&mrt_lock); call_ip6mr_vif_entry_notifiers(net, FIB_EVENT_VIF_ADD, v, dev, vifi, mrt->id); @@ -2099,11 +2099,13 @@ static int ip6mr_forward2(struct net *net, struct mr_table *mrt, return 0; } +/* Called with mrt_lock or rcu_read_lock() */ static int ip6mr_find_vif(struct mr_table *mrt, struct net_device *dev) { int ct; - for (ct = mrt->maxvif - 1; ct >= 0; ct--) { + /* Pairs with WRITE_ONCE() in mif6_delete()/mif6_add() */ + for (ct = READ_ONCE(mrt->maxvif) - 1; ct >= 0; ct--) { if (rcu_access_pointer(mrt->vif_table[ct].dev) == dev) break; } @@ -2249,7 +2251,6 @@ int ip6_mr_input(struct sk_buff *skb) return err; } - read_lock(&mrt_lock); cache = ip6mr_cache_find(mrt, &ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr); if (!cache) { @@ -2270,15 +2271,14 @@ int ip6_mr_input(struct sk_buff *skb) vif = ip6mr_find_vif(mrt, dev); if (vif >= 0) { int err = ip6mr_cache_unresolved(mrt, vif, skb, dev); - read_unlock(&mrt_lock); return err; } - read_unlock(&mrt_lock); kfree_skb(skb); return -ENODEV; } + read_lock(&mrt_lock); ip6_mr_forward(net, mrt, dev, skb, cache); read_unlock(&mrt_lock); From patchwork Wed Jun 22 05:12:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12890164 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C175C433EF for ; Wed, 22 Jun 2022 05:13:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357035AbiFVFNj (ORCPT ); Wed, 22 Jun 2022 01:13:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356904AbiFVFN0 (ORCPT ); Wed, 22 Jun 2022 01:13:26 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABDCC35DE2 for ; Tue, 21 Jun 2022 22:13:25 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-30ffc75d920so136322197b3.2 for ; Tue, 21 Jun 2022 22:13:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=FqrzbrlJqIQQUjGW5dvrMp33HGa4GU4gREXFl8wp6ts=; b=H+4rRm/tbi/VflEcVKnzv/Yn+CiNVJDNvD6sMQFSGzrJ1kwowwbT1fJtUXindPMDjJ L5Y0K/eTTvK9QkWzu+yeT25BCzQ3ADO5KfYGloI+KiusXaMF0f+VTgybgYn6o4jyzMEj hoDsVn8JLdS9Eojbk/VBoh2Yx0nrCq/Yx/V0TIi3ti2ty6UTtNdYKh6zkHl21dyOFdNU SR4qpHdCmcRlEYElQtVxY6c6HvTQgHq5MtEeWnYSDsxlvKkxbP2gdvqJjX4w8jRrPH+b 9I3hNXekrfJKX5Eksms7L/+2uRODA/rHsect1sblWYwyj631YltdyEHjIz2DvXRmdPiJ i8tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=FqrzbrlJqIQQUjGW5dvrMp33HGa4GU4gREXFl8wp6ts=; b=q2Bn7CRweIeLBl9JOt02Na3Ly0ID9vqka/uKdDjtmsEZrhvGfE2F/6iy0kBAL0IYvZ SkHRfDNT0s+BVfAdSAD2zrN5KvSums5weB6U91EpOmqORNpPTVJmdnahDPrdvbHMle12 AAKjIL0iY5LbvFPZTEKjgtJU4SU4GN7PmReXo1sbSzPBimNMqlUruIyHnoOyyaWfOiSD StqWm1xCxpTs+qv+5XN1z2pcE2te4uhjFaNcUYBjxPjEgTpvY9dG6ickTD43sUY3+Rps Z5I2vDCYo5GyLhxGz2v0Xr0mlkyUxS9UkAeLjQ0SuB/k9jxnvenht7ZWV+FXBL8+Gq9S p8fg== X-Gm-Message-State: AJIora9oVw5181MXlED/yBKHpOtdwOSVntvpO2e8plFt0GzhW8TxhpIZ P0z1CGUGzuE5fhPcE+bsPepUR3tRrxi0nQ== X-Google-Smtp-Source: AGRyM1up/o8Ox6WK5urEZxm8aS912pWxBvJ5ED+S8i7AiPiQoPEb95M3xY390FdqmjySO1jxaCgcYpEJG9QI+A== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a5b:289:0:b0:65b:7312:c849 with SMTP id x9-20020a5b0289000000b0065b7312c849mr1690767ybl.469.1655874805020; Tue, 21 Jun 2022 22:13:25 -0700 (PDT) Date: Wed, 22 Jun 2022 05:12:50 +0000 In-Reply-To: <20220622051255.700309-1-edumazet@google.com> Message-Id: <20220622051255.700309-15-edumazet@google.com> Mime-Version: 1.0 References: <20220622051255.700309-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH net-next 14/19] ip6mr: do not acquire mrt_lock while calling ip6_mr_forward() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org ip6_mr_forward() uses standard RCU protection already. Signed-off-by: Eric Dumazet --- net/ipv6/ip6mr.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index 089c26af3120d198ccfdda631294ed9712568ac0..8a751a36020334168fe87c98ea38d561e2fa1d94 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -2042,9 +2042,7 @@ static int ip6mr_forward2(struct net *net, struct mr_table *mrt, WRITE_ONCE(vif->bytes_out, vif->bytes_out + skb->len); vif_dev->stats.tx_bytes += skb->len; vif_dev->stats.tx_packets++; - rcu_read_lock(); ip6mr_cache_report(mrt, skb, vifi, MRT6MSG_WHOLEPKT); - rcu_read_unlock(); goto out_free; } #endif @@ -2112,6 +2110,7 @@ static int ip6mr_find_vif(struct mr_table *mrt, struct net_device *dev) return ct; } +/* Called under rcu_read_lock() */ static void ip6_mr_forward(struct net *net, struct mr_table *mrt, struct net_device *dev, struct sk_buff *skb, struct mfc6_cache *c) @@ -2131,14 +2130,12 @@ static void ip6_mr_forward(struct net *net, struct mr_table *mrt, /* For an (*,G) entry, we only check that the incoming * interface is part of the static tree. */ - rcu_read_lock(); cache_proxy = mr_mfc_find_any_parent(mrt, vif); if (cache_proxy && cache_proxy->_c.mfc_un.res.ttls[true_vifi] < 255) { rcu_read_unlock(); goto forward; } - rcu_read_unlock(); } /* @@ -2159,12 +2156,10 @@ static void ip6_mr_forward(struct net *net, struct mr_table *mrt, c->_c.mfc_un.res.last_assert + MFC_ASSERT_THRESH)) { c->_c.mfc_un.res.last_assert = jiffies; - rcu_read_lock(); ip6mr_cache_report(mrt, skb, true_vifi, MRT6MSG_WRONGMIF); if (mrt->mroute_do_wrvifwhole) ip6mr_cache_report(mrt, skb, true_vifi, MRT6MSG_WRMIFWHOLE); - rcu_read_unlock(); } goto dont_forward; } @@ -2278,11 +2273,8 @@ int ip6_mr_input(struct sk_buff *skb) return -ENODEV; } - read_lock(&mrt_lock); ip6_mr_forward(net, mrt, dev, skb, cache); - read_unlock(&mrt_lock); - return 0; } From patchwork Wed Jun 22 05:12:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12890165 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38229C43334 for ; Wed, 22 Jun 2022 05:13:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357040AbiFVFNl (ORCPT ); Wed, 22 Jun 2022 01:13:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356924AbiFVFN2 (ORCPT ); Wed, 22 Jun 2022 01:13:28 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 563C535DEE for ; Tue, 21 Jun 2022 22:13:27 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2eb7d137101so136292017b3.12 for ; Tue, 21 Jun 2022 22:13:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=1mcBhyhkyYvUwin15ciKRtLj/bHT6HY5NDONX+E6MMM=; b=kfGlyiY8/tzXSmp+KRhULB6SjCgfmqgaoVgGuGzy/kV3pu3ojstYvNBvJDHqFNhUa4 JUXz59ANXPO/HG0mI96GiNBa9lxZMIlrTJLoTqC9U2bOVTeQGXdAKp/pJRD1FAxp7bso m89ilJFuOJCgOdFTiWBOBuWlZEJeSRluE0zQAn12zBIOs/wAJY0HBnt6ynZCjgfCR/4F Gd3LOSGfIJ3GQAqd8i2RdQ+zIm1HuPKn4ZTVs2eEOiExwgd2SoPr2+IKHLWpEz/ndHp9 Se2BgvcQ39Ntduv7SFr4GU+5I89j0mHLFtwJO9iuf+TKOVM5VRL1RAS1pvQ2R3XWOVR+ MJzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=1mcBhyhkyYvUwin15ciKRtLj/bHT6HY5NDONX+E6MMM=; b=rRNybELX6s8pPz05rJ0ZqxiFcArNoZ2skIJuMh8An9XaKsnPsn6o8dnUHa8U0VKhr7 VRDumY2VD1zBg07PpSi47L57FZ8tAL4j4gZ/4w0SYAMcLHrwzA3tDON1oeP9gY6SJOQh vHHdqwSe9bh7/enQVW4OP3CGKPWeY3ujZ0yMD2r2LEPJUsRdixU9fI0gMyqtiu2O5tE9 mAP8SKMj5UKB7tPXESM4Nh8gqkUs4vtr8Af9+5O4rXyqfmmU0WIXA3QfZ/c+5agVW555 H5jZafidRw/8Ey3reNZhQT0oX8QGMNqykf2dXuaWuOgI05TL5Mw/rD4ktV2HgP7DT3TU Or0g== X-Gm-Message-State: AJIora82TYtGpIbGrueO8Fu30ktdev4kBNFwYjhmRlzgLDcSYayPc6M9 mDUQoGgJ8AMwovFQdHZT8GoSpWtZjjiovg== X-Google-Smtp-Source: AGRyM1sPgMdgj1lF3Y4VSNffOkrcXAU6rNPN6NG3LA72Tmqxdz79R9C/6RJZ5bFwpPRO6BNr34AnTQo8yl59/A== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:8909:0:b0:656:ae08:d91a with SMTP id e9-20020a258909000000b00656ae08d91amr1887126ybl.414.1655874806670; Tue, 21 Jun 2022 22:13:26 -0700 (PDT) Date: Wed, 22 Jun 2022 05:12:51 +0000 In-Reply-To: <20220622051255.700309-1-edumazet@google.com> Message-Id: <20220622051255.700309-16-edumazet@google.com> Mime-Version: 1.0 References: <20220622051255.700309-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH net-next 15/19] ip6mr: switch ip6mr_get_route() to rcu_read_lock() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Like ipmr_get_route(), we can use standard RCU here. Signed-off-by: Eric Dumazet --- net/ipv6/ip6mr.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index 8a751a36020334168fe87c98ea38d561e2fa1d94..08ac177fe30ca3bfbc50cd73b41cdc3da56d23e0 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -2290,7 +2290,7 @@ int ip6mr_get_route(struct net *net, struct sk_buff *skb, struct rtmsg *rtm, if (!mrt) return -ENOENT; - read_lock(&mrt_lock); + rcu_read_lock(); cache = ip6mr_cache_find(mrt, &rt->rt6i_src.addr, &rt->rt6i_dst.addr); if (!cache && skb->dev) { int vif = ip6mr_find_vif(mrt, skb->dev); @@ -2308,14 +2308,14 @@ int ip6mr_get_route(struct net *net, struct sk_buff *skb, struct rtmsg *rtm, dev = skb->dev; if (!dev || (vif = ip6mr_find_vif(mrt, dev)) < 0) { - read_unlock(&mrt_lock); + rcu_read_unlock(); return -ENODEV; } /* really correct? */ skb2 = alloc_skb(sizeof(struct ipv6hdr), GFP_ATOMIC); if (!skb2) { - read_unlock(&mrt_lock); + rcu_read_unlock(); return -ENOMEM; } @@ -2338,13 +2338,13 @@ int ip6mr_get_route(struct net *net, struct sk_buff *skb, struct rtmsg *rtm, iph->daddr = rt->rt6i_dst.addr; err = ip6mr_cache_unresolved(mrt, vif, skb2, dev); - read_unlock(&mrt_lock); + rcu_read_unlock(); return err; } err = mr_fill_mroute(mrt, skb, &cache->_c, rtm); - read_unlock(&mrt_lock); + rcu_read_unlock(); return err; } From patchwork Wed Jun 22 05:12:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12890166 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E756C433EF for ; Wed, 22 Jun 2022 05:13:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357051AbiFVFNo (ORCPT ); Wed, 22 Jun 2022 01:13:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356969AbiFVFN3 (ORCPT ); Wed, 22 Jun 2022 01:13:29 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B87A435DF2 for ; Tue, 21 Jun 2022 22:13:28 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id a8-20020a25a188000000b0066839c45fe8so13667064ybi.17 for ; Tue, 21 Jun 2022 22:13:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=7rjrQ3wFza4ZoUN3WC5B+Xi/dWO10C5OH6N7utNmGIw=; b=LETSOc/bssPVooI/vaNgy4jS0YBe6yd7yiRnZCZ6kwrxfK1ITNI1kmJ5tTrwosMcBr /hgQP8G8MhkD+Sjr6cYE8C+MwE3DO2DNAiFsbcGCCZzDO8gCQnZjEuKEdx42jWD2C4ue n/cHD7hHkxO3I8TlXvqpf1oKsep8NNM7LJWASuCzDTZbDbJYes6iE3Gz06nwPJkNmhU2 vS16RE+lFo6i04aj+swmz7+e6lxOB2antwKIDY4gc0wayalgYFb0+SbvbdFfare21Fzt Wf/GNc2xgXe19WTTbeTPVmqaiZXmT7RrHR3S/+6uTvzUXP+ZG99bVgGwojPT0ElqXAaA 73PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=7rjrQ3wFza4ZoUN3WC5B+Xi/dWO10C5OH6N7utNmGIw=; b=DBy/SOZR3CJrGF/2IO4QAVWo/Q4Cuxgopa43PABmGOcb9AbXZzJMPZ6KvCfmxcZlX9 Dd6/oWe3cgEKr7rOV7ddsMyojVYpiOtGrqKSdGXBqxm8CbNUwqJjlZYz+DnqyLImpFqD vL6K0pO9QTJkrKejLZZAp0XPhaKU7R2Mg3mDepMnVChcXJrG2hnNWHUVA9pVTgf3QSqi PXAnzyxtfdO7VnMiaqn5x0D/1xYibX0F7a1t7XvaqhyKrJyU436JqdmSTHwa+a5HfWKC 6osXuA7jHbbBjIwUA8LQEvzc+BkDqqRzjohfa2SfwrzUZE2HV659kqOesrl8XqeNjl/p DHmw== X-Gm-Message-State: AJIora+nq242VPylgAm8MrQmCmtVJwZUaT0mQ9c0LoVza2NbOyafqO5W N/CxuwVskS+oiGbE2Uq85qgSt+6xJUqxBQ== X-Google-Smtp-Source: AGRyM1vhrc76EprVw5CApFmzsMttOfvoXPREFJDmb3jUuhPwqzFvpQ2smIL3KOD1FvJNkbdrG+hM+W28ZHnenA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a0d:d8c5:0:b0:318:3994:cc3e with SMTP id a188-20020a0dd8c5000000b003183994cc3emr2115457ywe.225.1655874808494; Tue, 21 Jun 2022 22:13:28 -0700 (PDT) Date: Wed, 22 Jun 2022 05:12:52 +0000 In-Reply-To: <20220622051255.700309-1-edumazet@google.com> Message-Id: <20220622051255.700309-17-edumazet@google.com> Mime-Version: 1.0 References: <20220622051255.700309-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH net-next 16/19] ipmr: adopt rcu_read_lock() in mr_dump() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org We no longer need to acquire mrt_lock() in mr_dump, using rcu_read_lock() is enough. Signed-off-by: Eric Dumazet --- include/linux/mroute_base.h | 4 ++-- net/ipv4/ipmr.c | 2 +- net/ipv4/ipmr_base.c | 8 +++----- net/ipv6/ip6mr.c | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/include/linux/mroute_base.h b/include/linux/mroute_base.h index 10d1e4fb4e9fe387d914c83d135ed6a8f284c374..9dd4bf1572553ffbf41bade97393fac091797a8d 100644 --- a/include/linux/mroute_base.h +++ b/include/linux/mroute_base.h @@ -308,7 +308,7 @@ int mr_dump(struct net *net, struct notifier_block *nb, unsigned short family, struct netlink_ext_ack *extack), struct mr_table *(*mr_iter)(struct net *net, struct mr_table *mrt), - rwlock_t *mrt_lock, struct netlink_ext_ack *extack); + struct netlink_ext_ack *extack); #else static inline void vif_device_init(struct vif_device *v, struct net_device *dev, @@ -363,7 +363,7 @@ static inline int mr_dump(struct net *net, struct notifier_block *nb, struct netlink_ext_ack *extack), struct mr_table *(*mr_iter)(struct net *net, struct mr_table *mrt), - rwlock_t *mrt_lock, struct netlink_ext_ack *extack) + struct netlink_ext_ack *extack) { return -EINVAL; } diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 69ccd3d7c655a53d3cf1ac9104b9da94213416f6..38963b8de7af65cabd09894a816d342cd3cee5df 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -3027,7 +3027,7 @@ static int ipmr_dump(struct net *net, struct notifier_block *nb, struct netlink_ext_ack *extack) { return mr_dump(net, nb, RTNL_FAMILY_IPMR, ipmr_rules_dump, - ipmr_mr_table_iter, &mrt_lock, extack); + ipmr_mr_table_iter, extack); } static const struct fib_notifier_ops ipmr_notifier_ops_template = { diff --git a/net/ipv4/ipmr_base.c b/net/ipv4/ipmr_base.c index 59f62b938472aef79b4eb3ade706bf4d111e1e3a..271dc03fc6dbd9b35db4d5782716679134f225e4 100644 --- a/net/ipv4/ipmr_base.c +++ b/net/ipv4/ipmr_base.c @@ -399,7 +399,6 @@ int mr_dump(struct net *net, struct notifier_block *nb, unsigned short family, struct netlink_ext_ack *extack), struct mr_table *(*mr_iter)(struct net *net, struct mr_table *mrt), - rwlock_t *mrt_lock, struct netlink_ext_ack *extack) { struct mr_table *mrt; @@ -416,10 +415,9 @@ int mr_dump(struct net *net, struct notifier_block *nb, unsigned short family, int vifi; /* Notifiy on table VIF entries */ - read_lock(mrt_lock); + rcu_read_lock(); for (vifi = 0; vifi < mrt->maxvif; vifi++, v++) { - vif_dev = rcu_dereference_check(v->dev, - lockdep_is_held(mrt_lock)); + vif_dev = rcu_dereference(v->dev); if (!vif_dev) continue; @@ -430,7 +428,7 @@ int mr_dump(struct net *net, struct notifier_block *nb, unsigned short family, if (err) break; } - read_unlock(mrt_lock); + rcu_read_unlock(); if (err) return err; diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index 08ac177fe30ca3bfbc50cd73b41cdc3da56d23e0..f0a9bceb8e3c05ab45e95e8983e505edc005917e 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -1267,7 +1267,7 @@ static int ip6mr_dump(struct net *net, struct notifier_block *nb, struct netlink_ext_ack *extack) { return mr_dump(net, nb, RTNL_FAMILY_IP6MR, ip6mr_rules_dump, - ip6mr_mr_table_iter, &mrt_lock, extack); + ip6mr_mr_table_iter, extack); } static struct notifier_block ip6_mr_notifier = { From patchwork Wed Jun 22 05:12:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12890167 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FEBFC43334 for ; Wed, 22 Jun 2022 05:13:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357056AbiFVFNq (ORCPT ); Wed, 22 Jun 2022 01:13:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356996AbiFVFNb (ORCPT ); Wed, 22 Jun 2022 01:13:31 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 169E536141 for ; Tue, 21 Jun 2022 22:13:31 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id j2-20020a2597c2000000b0064b3e54191aso13717231ybo.20 for ; Tue, 21 Jun 2022 22:13:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=pMVAfLUneu2rDqkIvgFtPAjyay5c/7uMbjWw3cM7zHg=; b=bAL5WrrniLAoDWqRLWvW2V3SQ1DaNL3X3bCamPOr+NT3ENQXxBnt2UTEgs/9oCFiJq RFEgbjEIHD/XQNTexRybNADQmtHPrsZhNgtvmCV0H+T4pBBIwO2Ri5S8fMpmt7Nytfmw cwVTXWB4vY5MxkFyNl5tNcu+/r6MbVjYkGjyyJHAOufbUL5Oh1nH21OE8jt1n/t06X5g isyc3f4Bif4Q/KTPZmVA2cePL5Ht3rkamo8KA37mFw+AMdjp7EhF9hwEePfKOkvjg7jI jhn8cjs2A5EangZHUy7yYIxclJxy4iuhOTNGda2+YsYSO7U/J4zmMHUFvzJq8YM+4LgL PWeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=pMVAfLUneu2rDqkIvgFtPAjyay5c/7uMbjWw3cM7zHg=; b=csxk872ZZEtGwMolzJ3fnNEttSNi/BRW0w8JzN9SePEZvxCKWFnjS4v+lACLFocJq+ yBQ/APqDntDwVDVRyqJ/K7w1Ki38wkYg9DIV1wn95u4Xq7q9Bvus7wzn82CySqOsFUTs GHsEaxYH/aPOxVm/5s92IGpDn3p0e4XEo9+PCtMvOvMIm4SJX6JjDeSLRgcq8UXfhwiY EyB2k1BDPn8U7Fc/6b/TK753cVuCnOvSgC8jVBWBalaLYmpuuXPDOJDXy+CS8PJbBgfq YCzmRBqdM5ejyEv2UENZgVs/AJ0jmFYEcmVdbu5F308DHC2L8GbbZ+P5CU0qWGZFVRKG 4jMg== X-Gm-Message-State: AJIora8WoapGgBnPpKZXegslNYkfJVFkYPzQSn+XuK3kUBDICfMYxgt1 g2S3Oit3sinfjWo+rmCMJ0XOnNygAE7H+Q== X-Google-Smtp-Source: AGRyM1tTMxCarc9JW6GMLXivU0LAvFvlhurgve9xJRsBKbAd/AqjbQ+AkNzN4e684LQkjZoVwps93VlO7CIhlA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:690c:582:b0:317:72d3:cd12 with SMTP id bo2-20020a05690c058200b0031772d3cd12mr2091067ywb.299.1655874810250; Tue, 21 Jun 2022 22:13:30 -0700 (PDT) Date: Wed, 22 Jun 2022 05:12:53 +0000 In-Reply-To: <20220622051255.700309-1-edumazet@google.com> Message-Id: <20220622051255.700309-18-edumazet@google.com> Mime-Version: 1.0 References: <20220622051255.700309-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH net-next 17/19] ipmr: conver /proc handlers to rcu_read_lock() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org We can use standard rcu_read_lock(), to get rid of last read_lock(&mrt_lock) call points. Signed-off-by: Eric Dumazet --- net/ipv4/ipmr.c | 8 ++++---- net/ipv6/ip6mr.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 38963b8de7af65cabd09894a816d342cd3cee5df..2e39f73fe81a2392e07af83fd933033964e3a730 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -2895,7 +2895,7 @@ static int ipmr_rtm_dumplink(struct sk_buff *skb, struct netlink_callback *cb) */ static void *ipmr_vif_seq_start(struct seq_file *seq, loff_t *pos) - __acquires(mrt_lock) + __acquires(RCU) { struct mr_vif_iter *iter = seq->private; struct net *net = seq_file_net(seq); @@ -2907,14 +2907,14 @@ static void *ipmr_vif_seq_start(struct seq_file *seq, loff_t *pos) iter->mrt = mrt; - read_lock(&mrt_lock); + rcu_read_lock(); return mr_vif_seq_start(seq, pos); } static void ipmr_vif_seq_stop(struct seq_file *seq, void *v) - __releases(mrt_lock) + __releases(RCU) { - read_unlock(&mrt_lock); + rcu_read_unlock(); } static int ipmr_vif_seq_show(struct seq_file *seq, void *v) diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index f0a9bceb8e3c05ab45e95e8983e505edc005917e..7381cfdac3e376c97917465918a464bd61643f2a 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -404,7 +404,7 @@ static void ip6mr_free_table(struct mr_table *mrt) */ static void *ip6mr_vif_seq_start(struct seq_file *seq, loff_t *pos) - __acquires(mrt_lock) + __acquires(RCU) { struct mr_vif_iter *iter = seq->private; struct net *net = seq_file_net(seq); @@ -416,14 +416,14 @@ static void *ip6mr_vif_seq_start(struct seq_file *seq, loff_t *pos) iter->mrt = mrt; - read_lock(&mrt_lock); + rcu_read_lock(); return mr_vif_seq_start(seq, pos); } static void ip6mr_vif_seq_stop(struct seq_file *seq, void *v) - __releases(mrt_lock) + __releases(RCU) { - read_unlock(&mrt_lock); + rcu_read_unlock(); } static int ip6mr_vif_seq_show(struct seq_file *seq, void *v) From patchwork Wed Jun 22 05:12:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12890168 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A6F0CCA47A for ; Wed, 22 Jun 2022 05:13:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357034AbiFVFNr (ORCPT ); Wed, 22 Jun 2022 01:13:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357039AbiFVFNf (ORCPT ); Wed, 22 Jun 2022 01:13:35 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C3BD36147 for ; Tue, 21 Jun 2022 22:13:32 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2eb7d137101so136292017b3.12 for ; Tue, 21 Jun 2022 22:13:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=e+ZYZ7kE/qwElnjvjgd5Ved7ybd2g9symWMcNhHL2Fs=; b=SAiZkXEHtKfmLwWnGLPkHsq0G1CGDclcpVWr7qag7B3kVud1TBi578Q6/Vaixwq/XN sBqtuMtabcsRN2w0lgELHfEOuK5LCo9hIMECc5a4KOBP0h3e9ZmQVNMi5KRMp4tCDOtV kXL+PgHSXv1NVVNjnjYIwAmrnFm2V1oBHQ2yo1HROGHD9KGQh6lqWHRFZvzUvXieel8K IWPYb/x5jgpsqTu3Gr88J/TX9tAnMIIWIBDwGi8O9EnFKVvmF+sz0OgmuiVKndrgg1oo WltTr39Wycjv+Uv8h4SYTTXUmBAHWHUDraQ4oObyFyCpyoyTMfmwpzIO1AJz9Ej4OcFh PWBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=e+ZYZ7kE/qwElnjvjgd5Ved7ybd2g9symWMcNhHL2Fs=; b=4HBoUrzRWV0KS4b3u8X/85MCcufWJ+SOFx61wy3U2zklq6jXe2XTPwQvrsVe7kHEJQ LUVIycEd7c+molC4Ulm1XXWJKhu5ShwheMvBmysCz/J7Jd0swjA8xqBODtsAMZAnwnoD nyILrNabZ3aFl3OHMA6DCv3dF9amptD9JHJEaID6tKGjqTiiYzGjmy5Y8xAmajMRAzY+ 456w1EKUYYu/CH4ikr/fFZ/Ywpq79m7nUnV4DPoW1ynUaxAT4ysinD6gk9PzB+GzVZuy YUWA/E4+qztDrkIb1O0wHz98c5VUxzkf29M5/aKroHIwu63sbIDAY/oGo/cV1tWz0KxD AMag== X-Gm-Message-State: AJIora9aXexZzScbP+bLQT2fWIKBz9LcNoyNOC+A5B+Z1jwqtXjPXD0z tli3l3FifeSDd70vZgq+dhFHJYzscIbydA== X-Google-Smtp-Source: AGRyM1uXD2Sz/Ql/FNpGd+2teGdMLIkHEBnSpeK3ygxYbvStySpRpPAinC4fzAkNqdneiNHsY2ZEH7sEhDKBtg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a0d:cb90:0:b0:317:946c:30fe with SMTP id n138-20020a0dcb90000000b00317946c30femr2110852ywd.82.1655874812092; Tue, 21 Jun 2022 22:13:32 -0700 (PDT) Date: Wed, 22 Jun 2022 05:12:54 +0000 In-Reply-To: <20220622051255.700309-1-edumazet@google.com> Message-Id: <20220622051255.700309-19-edumazet@google.com> Mime-Version: 1.0 References: <20220622051255.700309-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH net-next 18/19] ipmr: convert mrt_lock to a spinlock From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org mrt_lock is only held in write mode, from process context only. We can switch to a mere spinlock, and avoid blocking BH. Also, vif_dev_read() is always called under standard rcu_read_lock(). Signed-off-by: Eric Dumazet --- net/ipv4/ipmr.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 2e39f73fe81a2392e07af83fd933033964e3a730..f095b6c8100bd24262c949390b68865b8b3987c3 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -77,12 +77,11 @@ struct ipmr_result { * Note that the changes are semaphored via rtnl_lock. */ -static DEFINE_RWLOCK(mrt_lock); +static DEFINE_SPINLOCK(mrt_lock); static struct net_device *vif_dev_read(const struct vif_device *vif) { - return rcu_dereference_check(vif->dev, - lockdep_is_held(&mrt_lock)); + return rcu_dereference(vif->dev); } /* Multicast router control variables */ @@ -664,7 +663,7 @@ static int vif_delete(struct mr_table *mrt, int vifi, int notify, if (!dev) return -EADDRNOTAVAIL; - write_lock_bh(&mrt_lock); + spin_lock(&mrt_lock); call_ipmr_vif_entry_notifiers(net, FIB_EVENT_VIF_DEL, v, dev, vifi, mrt->id); RCU_INIT_POINTER(v->dev, NULL); @@ -683,7 +682,7 @@ static int vif_delete(struct mr_table *mrt, int vifi, int notify, WRITE_ONCE(mrt->maxvif, tmp + 1); } - write_unlock_bh(&mrt_lock); + spin_unlock(&mrt_lock); dev_set_allmulti(dev, -1); @@ -785,7 +784,7 @@ static void ipmr_expire_process(struct timer_list *t) spin_unlock(&mfc_unres_lock); } -/* Fill oifs list. It is called under write locked mrt_lock. */ +/* Fill oifs list. It is called under locked mrt_lock. */ static void ipmr_update_thresholds(struct mr_table *mrt, struct mr_mfc *cache, unsigned char *ttls) { @@ -897,7 +896,7 @@ static int vif_add(struct net *net, struct mr_table *mrt, v->remote = vifc->vifc_rmt_addr.s_addr; /* And finish update writing critical data */ - write_lock_bh(&mrt_lock); + spin_lock(&mrt_lock); rcu_assign_pointer(v->dev, dev); netdev_tracker_alloc(dev, &v->dev_tracker, GFP_ATOMIC); if (v->flags & VIFF_REGISTER) { @@ -906,7 +905,7 @@ static int vif_add(struct net *net, struct mr_table *mrt, } if (vifi+1 > mrt->maxvif) WRITE_ONCE(mrt->maxvif, vifi + 1); - write_unlock_bh(&mrt_lock); + spin_unlock(&mrt_lock); call_ipmr_vif_entry_notifiers(net, FIB_EVENT_VIF_ADD, v, dev, vifi, mrt->id); return 0; @@ -1211,12 +1210,12 @@ static int ipmr_mfc_add(struct net *net, struct mr_table *mrt, mfc->mfcc_mcastgrp.s_addr, parent); rcu_read_unlock(); if (c) { - write_lock_bh(&mrt_lock); + spin_lock(&mrt_lock); c->_c.mfc_parent = mfc->mfcc_parent; ipmr_update_thresholds(mrt, &c->_c, mfc->mfcc_ttls); if (!mrtsock) c->_c.mfc_flags |= MFC_STATIC; - write_unlock_bh(&mrt_lock); + spin_unlock(&mrt_lock); call_ipmr_mfc_entry_notifiers(net, FIB_EVENT_ENTRY_REPLACE, c, mrt->id); mroute_netlink_event(mrt, c, RTM_NEWROUTE);