From patchwork Thu Jun 23 04:34:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12891744 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 41DDDCCA480 for ; Thu, 23 Jun 2022 04:41:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231293AbiFWEko (ORCPT ); Thu, 23 Jun 2022 00:40:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245056AbiFWEe7 (ORCPT ); Thu, 23 Jun 2022 00:34:59 -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 1050830F71 for ; Wed, 22 Jun 2022 21:34:59 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id o199-20020a25d7d0000000b00668ab46306bso15570583ybg.6 for ; Wed, 22 Jun 2022 21:34:59 -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=lODiJuaPbRG2t6Tlrk+7EudZx62eCyBbEZMr06Gs+Kqhpw1vn1/b9yi7zmn/Z5RvpN mgMgp1cAoCTnIeKSnSaK8fW1qT0oLsApG6UpPqbbnjAJ3CJ6iXuYMMjKLsfYNUvbyXfc Og5a7p82ZD5b3N3O8pBcFC86yX760A+82oBVtoD8iMz/U0klgFOIR1U5zIgAteS4P97q 272BPCH9WK2KzDgtKET77r29U3b6QVa6jye0UKIsGPcvKJRWucNLLdHKppELhLWcRy7B swC2mbDHGHOPkgw3C1ohyHkAiHbPC3J5fuphtVvop1GGbkrT3p0FaoqwsmRI7jsgBmus fPqA== 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=CUYQq4l95Lj0rZLhf4ddFicp1JW04nn8EeRgHWNdbDdccw/XPhOnlexhGTs2qBTRUe jUhZ3FSBugHk7WfuNqxhB8TOURk9IgQCRXxqiQ1hWGd+6RIjWrMBIdhhyoxg2ra7TxSI iPgcXR7n/WrUaS42iAD7lX9e5FnwTHtRkc5Il2qbwJKQf93lDBK8xEN7DmTFZnaf5quN spJpJANH5D6d5ZW/VpKpBUzphSyLYyJcmw9S+zzAANx7XqUVqajBrMqVpiIoFoTvVqQ6 m8CIfXdlrYvpwqKW8v/e3hocBDS5Uz2+AFEFkymI5jglZ32KqIuCUhTUvjyaxZouylox 25QA== X-Gm-Message-State: AJIora/UGoXhNqEfpNKVzYo5EIgRCE4Mxch2++4CdYHejWquWRbBJk/F mU7gMwFlWwXQ3wtFlxGgSrLKCRMSsXeEEg== X-Google-Smtp-Source: AGRyM1us6DUZYvkSErwnmkBJTpD5Z8il+EDnU5VL1pLSPfvCGFLtqJ6qOWxmFxaHKy525K41e1J8yx1aHzFhrQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:3ac5:0:b0:317:8cb0:99b0 with SMTP id h188-20020a813ac5000000b003178cb099b0mr8502286ywa.71.1655958898321; Wed, 22 Jun 2022 21:34:58 -0700 (PDT) Date: Thu, 23 Jun 2022 04:34:31 +0000 In-Reply-To: <20220623043449.1217288-1-edumazet@google.com> Message-Id: <20220623043449.1217288-2-edumazet@google.com> Mime-Version: 1.0 References: <20220623043449.1217288-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH v2 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 Thu Jun 23 04:34:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12891748 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 E5ED5CCA47C for ; Thu, 23 Jun 2022 04:41:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231373AbiFWEks (ORCPT ); Thu, 23 Jun 2022 00:40:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347305AbiFWEfD (ORCPT ); Thu, 23 Jun 2022 00:35:03 -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 2CFDB30F71 for ; Wed, 22 Jun 2022 21:35:02 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-317597643bfso161087877b3.20 for ; Wed, 22 Jun 2022 21:35: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=c2wz7LbHeakkTWyR1zhuUeJxWRArN7mrF64XlXKfDjk=; b=r7M1YEhXIHtud2V6EHB1r+UEsTd6uvAp8kgE0aU7tnjdu3zLmvuL2BA1Wp8F6h6RIE tJp/9GazZ0R7fybMtKMYEjhQqOc2Z55S5Tm69sdgFlRTTfDrRT5Xd4fNUkQHKPDLc3Sa A1MRoAl9sYOcBFQvdtDsIxXlD0mpjtio5SW617FL+SXbSfRzh/fI+EO3rEQ8Jd+XCHtY fgb05T294UCloJk/kqAd8cUAfDJrW9z8VeoeStsTuZVObx8Qc1bIR3hJBSCDcG7cCeV7 w4hJ3LFZAu1AoqlNwrW9oKxKZw0BpVhpOYOJX0qHZiOp2puC7GQBhdSP8hb8UwIIT11k FimQ== 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=c2wz7LbHeakkTWyR1zhuUeJxWRArN7mrF64XlXKfDjk=; b=A0CWBRU7kDf/XGl3qCVSZvaUVA1LA2QU3lF5Rq5mEMCj7k33Gw92LR04WPUpIgYCKB rpyFv/25kgAkOw5WHh6hD0XSdPz6y8SZIKdx/YYW7tpJ1WzETWSRLP/X2eaRQimkjHZI 7+gO5TK6qBpUjV8DL+IBvkAN8tkFkm/VYYzGVUwhhffbCQ8WoBORDEIKwjJqxW3XHw76 F9bWqKc5DXDwzD/Q2G0VeVWgQ5SR4W34eTJ5LYgHIFHEdJhkz//1+PqJmxU/4MJR3unH DAi1nh1txLI7BmaAtzJcdpX5O3KPmfYklJeybisgF0EXUpgXSJaSnAgTJZb6DwOtt7l1 0QzA== X-Gm-Message-State: AJIora9fqKl3Nhy3inaX6OoS1Vu5Ge2BdYYeiI9kc31fpSx/otIe8nB5 Fg79fC4hQrej5hU48mtbQ3PrLVRH0r0M9Q== X-Google-Smtp-Source: AGRyM1t4yA/rpi0qF9N3N50FSoJlE9417bgHKFVP3t6+7XFEvjK05g2B9T0n8X2/wjO4C0iVAei1X6aY0ZBdMw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:6357:0:b0:30f:dbe5:b8ff with SMTP id x84-20020a816357000000b0030fdbe5b8ffmr8450160ywb.67.1655958901470; Wed, 22 Jun 2022 21:35:01 -0700 (PDT) Date: Thu, 23 Jun 2022 04:34:32 +0000 In-Reply-To: <20220623043449.1217288-1-edumazet@google.com> Message-Id: <20220623043449.1217288-3-edumazet@google.com> Mime-Version: 1.0 References: <20220623043449.1217288-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH v2 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 ipmr & ip6mr 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 Thu Jun 23 04:34:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12891751 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 D9DD9C433EF for ; Thu, 23 Jun 2022 04:41:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231388AbiFWEkt (ORCPT ); Thu, 23 Jun 2022 00:40:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233701AbiFWEfG (ORCPT ); Thu, 23 Jun 2022 00:35:06 -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 9FFC530F71 for ; Wed, 22 Jun 2022 21:35:05 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-30ffc75d920so161291137b3.2 for ; Wed, 22 Jun 2022 21:35:05 -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=cxmJ3M19EBvZcOkQ2fK8ZyXJxZM2h3M05KXpqCdgUDgIpMizKk/GBjRk011s28GSVS gy61PvyYBIZPlf+n8hK0YxqDENJi2BatbvXJqdx5p4t0jC0cDiqYH34hWgWEVj+OGAvq qiB6tfDGJaZKhEcZIQaNyRxLTGhmFNZHkMhJYtbPCaSmN+ycaOUbT6nFXuLrF575vsCK Da9rrFPjEntf+zjb7YNjefESaOmZ27QF7MOwo4qLZpSHSaLZGUoL9hqjetvtSaG/lWBy p2QW3asDecrYPJzVnutuoCEN0ady2JQFuUOXSKRQo+/XAigH+yjvnrpSAI6Ar8B0ZbQs fPTw== 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=ySnhODoZNyJ412L4xiirroZmMFA4PMSNlgkaITbOuEMgyrxe8yrFXbb7eAmPVTBkr0 eITnMbGlW0elzsG2KxZiwKHZ7bTfJGTFc8qSWWzvZIdIQTQzg5o4rs+lVkJ0IZ1FLfT+ iUV1c9BeC8WL92xBsn/+w9Mrw6HecwLcKv9u6JkZDPD56l3DcCIAgzzAWN5cbMQK6FBq TX47nGSXsK4jmv8ODr0aOH1+r4hYfSoOhTbwvugPawFjXX5oiaXHBm9sBaSfP3QV0mt5 oi4iXVI0/728qs/eGRuFyEaHxiWRNn1A/fp1qJf9FJR0gRLUgqFujdBI2y7jIy22NBwN pGcw== X-Gm-Message-State: AJIora9sbgf+ELzNCw3FJwR98zBthbJZ12DZtpEmDpGfBgEAIQtjOie9 w4vp3QBUbQOBgabNGAk0ZxfE2cI6k4XmtQ== X-Google-Smtp-Source: AGRyM1sY9qD6OnTK4MXwrCVaYd1GRCgIGrzrRuj9mKZ6mjD0Hwjx+7+GJcOnVgE0BMI5iivyN6/ZEb0fSccoPA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a0d:f446:0:b0:318:5c8a:a41c with SMTP id d67-20020a0df446000000b003185c8aa41cmr5339674ywf.290.1655958904982; Wed, 22 Jun 2022 21:35:04 -0700 (PDT) Date: Thu, 23 Jun 2022 04:34:33 +0000 In-Reply-To: <20220623043449.1217288-1-edumazet@google.com> Message-Id: <20220623043449.1217288-4-edumazet@google.com> Mime-Version: 1.0 References: <20220623043449.1217288-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH v2 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 Thu Jun 23 04:34:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12891752 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 EA64CCCA47E for ; Thu, 23 Jun 2022 04:41:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231415AbiFWEkw (ORCPT ); Thu, 23 Jun 2022 00:40:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347318AbiFWEfK (ORCPT ); Thu, 23 Jun 2022 00:35:10 -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 8BF3530F71 for ; Wed, 22 Jun 2022 21:35:09 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-317765eb7ccso156829137b3.13 for ; Wed, 22 Jun 2022 21:35:09 -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=npAUnBoD4NEvzk4J/fUK28YJ337Zcoyrxtt8ljucKHheL73wfsS2GQ1NYcamlIZaLS +ZE3QP5/YlJ2UKRwDwqyU2G/QdVWxUN475OtN65S/pXm5JooNmSdqDq/SOfNqaXerNU5 d91hab/fXjM6zxYr3JwC3fJ5xaHhxpKRbRLTPtgJybGDdjCBePd7D6r4fdcXmbOyhPPR w2ydD3HUNkSDF8JWgPpK7uAZ4mbgED1LEfiLOxa79Gh8hQByV8SFDCyVHkwkE1QoZIYg okVB1Ola7CUnsOVZ7s3wCe3AS9PEiTAKQeedyV1YGzUM4qmRSg6xXpjg+ok+4yOOn1nB GHfA== 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=JojDbmehM72qCpo43Zd33iv8Lm9YrcKBOnFhAHQ0pBWLsMkPUQ66RIPFMNbdhkmRb6 CIibGNMDjregHKfP3fdKdw06OPC06KsN010ygZYHNb1BaKrfu8woEkNSSTFJd33a/2US LnRampmZhdcIs3TkjEWuEkfIEKF3FC/vB6RM05UBqXc93ud5EllFRcgW+dXo9RMlLhBg AdQc77iQB2THIetu/Phhukk822uK7N/aRTNjg+86HDmhacjBwn5H/1jXwwQ+05mD12sN qgGIXBCAkHN8wopL8WPNzRNSQU75k3E2+ZETezzygXdHk1kLkkrAw9CUFpd9IF+8qlGc e7SA== X-Gm-Message-State: AJIora+gdN1yJ+5SDeBf3aENjSN6qFPqpzUwrruRPo+XYiCSjTdqxtaw b9Js3neoWtFQbtgRp2DzEIR77ns2SgNyCw== X-Google-Smtp-Source: AGRyM1siVasfF+Gvj5/K4q8iM0M1NrY9F6RFLGBeJjOvknVsZlJDP1tdY6eUsNAz8qHeu2yeOsPDh/tb3x1HpQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:a090:0:b0:664:83b4:bbd3 with SMTP id y16-20020a25a090000000b0066483b4bbd3mr7740038ybh.243.1655958908780; Wed, 22 Jun 2022 21:35:08 -0700 (PDT) Date: Thu, 23 Jun 2022 04:34:34 +0000 In-Reply-To: <20220623043449.1217288-1-edumazet@google.com> Message-Id: <20220623043449.1217288-5-edumazet@google.com> Mime-Version: 1.0 References: <20220623043449.1217288-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH v2 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 Thu Jun 23 04:34:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12891749 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 04F1CCCA481 for ; Thu, 23 Jun 2022 04:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231440AbiFWEky (ORCPT ); Thu, 23 Jun 2022 00:40:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347325AbiFWEfP (ORCPT ); Thu, 23 Jun 2022 00:35:15 -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 E263E30F71 for ; Wed, 22 Jun 2022 21:35:13 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-317a4c8a662so104865007b3.6 for ; Wed, 22 Jun 2022 21:35: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=EvQ1EeBfzcaZ2NY/562e7h1W6s3GP0FJiq4bYltHlnA=; b=CVm3/2R6G9U82RK/T7/94wY9Cu0iTcP6FW8aBJUtwg95d8aVCBWKyH1O8M1pvh1s5D bJJCsgZGscLpANNVi4GKPApocwJLyRw9AdUqVeY6e1lZg3bNBCfTyZJOTZFHD2Rtgc1Q OjOv33HEVKNtTeqTuAqFdj1fBlccDp051KvA67BwuUJ/RzE/KL0pyr/Ez5qUG2UukJMM rxofqiYfSYjgMYq9ciwxlyGjFqbdM3I3TOrpbLp8KhPALBGnGmNhl990KLQaMDfECD5n 7EKcIPQ7CgXopGupnTVacKndEeSlTWyckPY49TGA8lMz8ykGlkPnSNnmIn1ESIgHvNAp NNMw== 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=l2B1ioVzdGMwyo/pDGSpOoyo+3fllDv5iEIYEyyNHz6tOUdrXrQWFFOydwKjlY8TH2 RppDTi8nDWBA93pPLdZOfsdu8rnJlmuj3YekqKRtrT4Oj5RJ3JrFG6/l3/kggO3JwR0G 7vl//dHjEPHuMhtmEW+qG7aKe2wG/djiWNkctLBBFzgv40vmOAHNYbWCwxFtywZnAjPz MQ66b/bZKU8FSPih23+gPebXmA87FNgFXJ44gTvo2CVGiagmH13y4IiOy+6XUJT13AEU Vx/7xfnJ6zXAXnN4bfKnIoejh1qpE1kezcl0fx/lFTPD2ePX1vGBsvWok/SkvAVYGBA6 ZuMA== X-Gm-Message-State: AJIora81CHnWHLJKWWdg+fBcLjZxC1HGzCmMnruIRUtMzKjV+7vyMF3j kfT2stvtWDjKEGE+LLoPc8Q9vgE71R6SGA== X-Google-Smtp-Source: AGRyM1t1arsiteTIqRl6h2O2AwwFU5w6iOSvOgBQ57CWxvDc8dMzpSFBctBR7DGsQHYDvYcI+1ugJ5rumCSLAA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:a1d7:0:b0:317:d4ce:3b42 with SMTP id y206-20020a81a1d7000000b00317d4ce3b42mr8595755ywg.317.1655958913181; Wed, 22 Jun 2022 21:35:13 -0700 (PDT) Date: Thu, 23 Jun 2022 04:34:35 +0000 In-Reply-To: <20220623043449.1217288-1-edumazet@google.com> Message-Id: <20220623043449.1217288-6-edumazet@google.com> Mime-Version: 1.0 References: <20220623043449.1217288-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH v2 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 Thu Jun 23 04:34:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12891753 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 1B1F7CCA480 for ; Thu, 23 Jun 2022 04:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231461AbiFWEk4 (ORCPT ); Thu, 23 Jun 2022 00:40:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347334AbiFWEfT (ORCPT ); Thu, 23 Jun 2022 00:35:19 -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 0308630F71 for ; Wed, 22 Jun 2022 21:35:19 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2fed274f3fbso160525717b3.17 for ; Wed, 22 Jun 2022 21:35: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=Q6zxvPds/JEM81DuSyUCoS9FcG5gc9gJ3cgYpcc9rFw=; b=n60/C1U/chc1f1Mi9qN3h0/wK/ahYXG2JcX5NIoYiIMPIoYrAJ547zkUfUxKKPKPN3 fcZfhfZf34bKEfNSvUI3DdLwiE1vFaW1BQwHgrawghnfDM459TilzJ8OYtIUoHk1p7n/ FA8JK3kWwwK9wrMvr5GLqkyNlkvFie/X/DZfP7WT6N+hwiUBxiUfBxCUtttVOVxh08mk wfLe1kBfflk8qg+2qkXjMbqRprqPLqd1mwDUoevyraiKXWR2q+zlgY6KwpwXhyJDQGP7 4S3Bh68h5b8FmkkZw86G71uM2wxpop7C14V0aSk2RFV3uo9uIGIlP9GeRFS48018cW89 zV7g== 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=0W7xRGKOVHTAcwd5dIisSfmbA2pm4GZ2cx8Ub8F3ohiw25MGq4don7deGxunRSaL5C iFzl+43+GX5ElMZfzK6lErQJVqtTB/y5fQ5Mge34SgVSUdKx/nwrynukMf856Wz5xalH 6rrV3zMqve/7VnyqKNgi9HH7/ddycl8BC3jixOJVaQ55aom0B1u2J13yJwAJk6bTX5Mf RURJURt2Czy72DOntBa1Rj8pKhu8g4y3YF56C97aQ0wvMCzZJnv+nXIhffJ0+OPz1Cze wnHhsUKTHriJDj9zn6kgf/OSD4fFMnagG09dVKhZTSmOmOuCW/KO5Pc8TprSPUoHhyAk acGw== X-Gm-Message-State: AJIora+ktKZmU8bebFy+f//rlF4A3iZKIs7VFQkMLF0XVzlDkWFKz1Wo hZxjjfQ/DC4hVH50VzKbqLEJEcJVlxyKmg== X-Google-Smtp-Source: AGRyM1tSscW5DI7Apetd2YmVQvvuaO/A6xohpYcUI/4va1kSrSMA6nZb9VlqLZIbKXZpv2Fqo3pa1+tl1cSX2A== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:1e05:0:b0:318:cdd:7e13 with SMTP id e5-20020a811e05000000b003180cdd7e13mr8386234ywe.5.1655958918266; Wed, 22 Jun 2022 21:35:18 -0700 (PDT) Date: Thu, 23 Jun 2022 04:34:36 +0000 In-Reply-To: <20220623043449.1217288-1-edumazet@google.com> Message-Id: <20220623043449.1217288-7-edumazet@google.com> Mime-Version: 1.0 References: <20220623043449.1217288-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH v2 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 Thu Jun 23 04:34: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: 12891750 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 36E9BCCA483 for ; Thu, 23 Jun 2022 04:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231483AbiFWEk4 (ORCPT ); Thu, 23 Jun 2022 00:40:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347343AbiFWEfX (ORCPT ); Thu, 23 Jun 2022 00:35:23 -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 4418130F71 for ; Wed, 22 Jun 2022 21:35:22 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id j11-20020a05690212cb00b006454988d225so16187510ybu.10 for ; Wed, 22 Jun 2022 21:35: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=ieF6vXeFFn+xrybKfdCGWxcLeig/WsIdEGabofxCaJA=; b=oFoYWCtvGpRg+mwf0B8RRXKlhqG/sKQjd5ie2f65uO2As4YaUBvqIUw9F0eZLeUaci qKDZPw8vtWG9DcnG/B2RpnUVIFgWUQho1EkKkjATYA10gwTMxCyuJADyole//g4xl/CB nYfrZy/3zoBXMnzNvkMFkAwZex+dvI6p9FP7SzgG0wJOWhieY8m9WD1SpjPBF7fCOK9W EuE/UoKCDutUj5xR3GAeikxXGLcxOX2zvCQCaFaOY00ZK/f+0ZkpGINSrIxHjZto+YIQ w7xU+XHHRQVv7VJuo3tPU78DL0cUc91yXqNpjKg4StEzitw/D+lkf5jiUEX1u2r9OPCp BzcQ== 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=J/ZPi5PObRN3W/szzAJS22UaNsFQbC/ac9S+oSIxBTTU9znoCzRoyyP1f3rPPQr727 dTKGuuZ9oe9DKmFNV3kmgvAswEtGf935acDGmhF3dJrr17uCLJc+se/KajYxmJzrDXd6 MXb1qdNjZv9p2g4rG5tAuYJT28gfCQ8vXotzbyO1OsiW5UX6V4jzOZNkQU4DakrLcHBO THpmKvmOKAEKN7Ut90MrfgGDrL15s7qEQDseJ2ao77q0i3QJAjjwe//ckPEXOPvZRmx/ c2MGnlmuylMIQVOQLRRiew5er4NDqDaZ7eGnB68P9XVzJKG3S2YcsTfi+YxQM4nhiPNU XTSQ== X-Gm-Message-State: AJIora8V0QOsJSLk5TOIZ4j8kuG9Mg6USVY/9RdECVs0tkzxnx1+WMbK rHfe/PzWOogRGnmya8kNEG7zWnbGxNueKg== X-Google-Smtp-Source: AGRyM1ulYxRDkGPoMzkIy82DcFIyWODOLtOeQoeP6wW+GPOPtWtbrD0MbZppVCGSdUtbeafx8hI24QX2sg07HA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:2fc3:0:b0:314:2bfd:ab9c with SMTP id v186-20020a812fc3000000b003142bfdab9cmr8675206ywv.22.1655958921557; Wed, 22 Jun 2022 21:35:21 -0700 (PDT) Date: Thu, 23 Jun 2022 04:34:37 +0000 In-Reply-To: <20220623043449.1217288-1-edumazet@google.com> Message-Id: <20220623043449.1217288-8-edumazet@google.com> Mime-Version: 1.0 References: <20220623043449.1217288-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH v2 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 Thu Jun 23 04:34: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: 12891755 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 45DFBCCA482 for ; Thu, 23 Jun 2022 04:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231526AbiFWEk5 (ORCPT ); Thu, 23 Jun 2022 00:40:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347352AbiFWEfb (ORCPT ); Thu, 23 Jun 2022 00:35:31 -0400 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A47D030F71 for ; Wed, 22 Jun 2022 21:35:29 -0700 (PDT) Received: by mail-qk1-x749.google.com with SMTP id i16-20020a05620a249000b006aedb25493cso4402969qkn.15 for ; Wed, 22 Jun 2022 21:35:29 -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=R5yKs+TGPSSk0dPi0tql3fdBhWEBjmH5WOGtTGWWqAS3A/tmYMnl8mi5783CtZfkdV WfQVI+5Ab+o6FPtUi+fR3Kny0UYLq8wyYXka1WJpREu/3NqfA3tFedefb0fRazEmNjnW jguS3qvcw2YBlV3rCo73lPjPy3D87XuNEiN56Ons4108OZavuaKqG+vo9hfDZo0qi33z kSwzjEN1ahn/jLzlOz7KtCypbLqzCC1QkrOpCWUSWCfbatAaYheyTZT92ELx3omQ/BPg cJr5UH5WN4NMsUF3LZksXNNZDZC0e2Gt0zYUdPm0rGkrBNRCxxLDGtsnkEt66vOCqwH+ zzbQ== 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=t+rj4ffcVXPbbBJY9QbF0ff55n5r1zJ1LGHadISb2NpcUzCv76CfkjvsUS7gWktRRv OeXrYqO3FUMGrrUymHmAlqxsj/kB/udu51I3lWyQr4hLujkw3l/NW8gq8XbM+TdpSGJC l7r4AOaiHno612hZdPrdoC1naZrEofNRdatRoHqjVe7sBHEzSot8O2ovkudog9dBRoze 9qbfsboiH+tbRpLGfDs3Y/lEI3tRLrsB//b6Ekhva6EYjIFhXaJrjg5sZP+xudiZLPED LVXBiehtPsDHcK1aDXm21MwS0iKAFhD/75o4yXQ3LX7Aoe6tm8hoAWcopbvsaxDD6n9s xV2w== X-Gm-Message-State: AJIora92aFd8iu4B3uv4rTjHJ8uPeGhOqDB+O6T8FAWSWewnR3gXRkP5 aK4SD4G3dHGMBVXPymDQISw2Jn6RY5RCsQ== X-Google-Smtp-Source: AGRyM1uJTOBiJFGaJb61+pJRDfw3N7K/r2sicszLPSiK/AqVJHCgKL2qBk4k8AFGKWA48V9S0p7aHDx7tZpvNQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:ad4:5aea:0:b0:470:57a0:f95 with SMTP id c10-20020ad45aea000000b0047057a00f95mr8821510qvh.51.1655958928803; Wed, 22 Jun 2022 21:35:28 -0700 (PDT) Date: Thu, 23 Jun 2022 04:34:38 +0000 In-Reply-To: <20220623043449.1217288-1-edumazet@google.com> Message-Id: <20220623043449.1217288-9-edumazet@google.com> Mime-Version: 1.0 References: <20220623043449.1217288-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH v2 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 Thu Jun 23 04:34: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: 12891754 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 54206CCA486 for ; Thu, 23 Jun 2022 04:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231534AbiFWEk7 (ORCPT ); Thu, 23 Jun 2022 00:40:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347358AbiFWEfe (ORCPT ); Thu, 23 Jun 2022 00:35:34 -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 35D0030F71 for ; Wed, 22 Jun 2022 21:35:34 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id d67-20020a251d46000000b006694b8ea9f2so6406705ybd.9 for ; Wed, 22 Jun 2022 21:35:34 -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=BK7w3uLpZyehLpi5ouPL0wVHrSbaSEV8AYwkgbNMQA/Iahw3oTXQLQO7zcyZ5nUMve xIPehQIXm/c4/RpyEzSCB0f2Zz1bgwNBOisxzOfw8l37gF5Zk/P1fJ/Scw/XYBjIi7ya 1+BNLuuz8Z3EU6QbnnWLpVRjIx5PPhlKpcLUBlG2mbj1PcbEf5U6Jz3jENztPdw716yq D6RXnC7HKaJUfbkelWf2OlJ9uAqUmCB/kyBXD0yCDzR8nTFwxNKFDxlIHUHzSyvXmQ3L 0ahJat0PvQiTnBjlDS00DbX/LNmVFx/mfodi6+bQAp8oarnH//asQGgs+6iNA2V9qkj1 cUvw== 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=P+w6l+QsxcFFIH3F4ZQIP39OTnsRkRJ1MzzbLYo0lvp/wEeQl1zWSuPIWb0p2ZMhsK AEVxvnFFrk4mpPgy+HdslXStd9AJuYQxwAFzuA2aK8lKzD1tNyOvS+ohhVT7NSmHS0w1 pjkj1dM6rZQFbaDKT/MZlKgp3+pTlwi5gFk+YIl0bnVgrHWwVuJf6rcGUTJyJ1BGWyU1 +WaL7OyiPJpC/hlhXYNAo8fO3GM54bsQxjzQyd3YrNiBmsCrZ38RbXwcqhTj+stNFUN6 IbSA8vAMF4GdDWvv/MeC3cN2u1gk9qRVDpLMiLHoaJHyZWMHX8flxYf9PAoFuXC2LQS5 bYrw== X-Gm-Message-State: AJIora+p2IpBsh9In0cTJ5wZ6vGh2qVrpLZ2yUxjJxIAJxb4dDz+qbA9 jp+SyRyCwLxzcA/GOaxTA4sgRlAXqXl3EQ== X-Google-Smtp-Source: AGRyM1v35qz2db7X2RVAt2R27DDIhZkj8V8dv2+aGRvpJM9PvslRC12UM1a9xPi/Y4cr3NYYJHZ1z2ATqP8JSg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:c646:0:b0:669:b341:a595 with SMTP id k67-20020a25c646000000b00669b341a595mr298538ybf.304.1655958933558; Wed, 22 Jun 2022 21:35:33 -0700 (PDT) Date: Thu, 23 Jun 2022 04:34:39 +0000 In-Reply-To: <20220623043449.1217288-1-edumazet@google.com> Message-Id: <20220623043449.1217288-10-edumazet@google.com> Mime-Version: 1.0 References: <20220623043449.1217288-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH v2 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 Thu Jun 23 04:34: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: 12891762 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 6549ACCA485 for ; Thu, 23 Jun 2022 04:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231542AbiFWElA (ORCPT ); Thu, 23 Jun 2022 00:41:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343729AbiFWEfj (ORCPT ); Thu, 23 Jun 2022 00:35:39 -0400 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EB2830F71 for ; Wed, 22 Jun 2022 21:35:38 -0700 (PDT) Received: by mail-qv1-xf49.google.com with SMTP id q36-20020a0c9127000000b00461e3828064so19239899qvq.12 for ; Wed, 22 Jun 2022 21:35:38 -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=acUNJv9uE8euzyPgoQzEzY7E95DW0FuBWVPV0D8RBEJrRTZ75HTpm3kPs7GgLBBPYq xrZ/fLtDQIFf6yZmfBA4Hm9qYaKRgZ4JAx6Zt+3JbvDXBOQgDa4RnFIRZSHb1ndajp+8 qdTpbAKlvBUo8VQHPLcDPd/6I4r9n2ZqyyA34u98Mpkd9xl+tmteyFn2Vz2gbNt8orHa snJx6R3ETX2w31nDB/BC5hAw+iJk4fubxOjftI/czKxJE4FQmenw3/JYu0TNxAoutQQ6 Hh4xx/dXXZS3UQbJUFKXnZrPszRfXUshWUBxe2wg7JPgLclvD/yvdJ3s75LtFYppkn7/ 4NXQ== 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=zZ4NyEHApubHxhwSr9x0rFJB6jKVuJDcDEjFD8A1HhrzNO3TNTy6nWhl4a6rVZzNZ/ sCLnpUoEo7hVEC2G7ofi3X8I6LztblUBjwz17tA1xSNFbkynyPoUSIPTRa/rrKrsRv3M /CBfHdPJ5Oum5vzX23C8AFnqZjmktse3NhpvzRO08rg8jhqInX2DgslwJWAl61Zsrbki Cw+TYl4jpWLy3zkxhw2SOx7WwAizL6m/uoQJdCeIIVznYmTf06AmZb0fIraIHCHY9h6H fk5GfN5+cDmpvsjUrD8IMmKrUbXJ1zRuOiVgxNV7biMsNJghtQzuXYiH+sVVj1CRwLkT JIKg== X-Gm-Message-State: AJIora+776WeCUtNAxZNBJUquQdxBVf1m2SLbc1JjnLAsTGZISk+nLlv nTCn4YCGBXwOsEdnXCzkqKg2qfgKS390bw== X-Google-Smtp-Source: AGRyM1u9XX+GtMx+sI+nPxT+hynZD0YAM98sDVZZ5xLKuhwwS3Hc+Nrk/zOkhT64iVELVdF1TXBLdxDwq9WABA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a0c:b388:0:b0:470:6c46:71c9 with SMTP id t8-20020a0cb388000000b004706c4671c9mr4589849qve.16.1655958937654; Wed, 22 Jun 2022 21:35:37 -0700 (PDT) Date: Thu, 23 Jun 2022 04:34:40 +0000 In-Reply-To: <20220623043449.1217288-1-edumazet@google.com> Message-Id: <20220623043449.1217288-11-edumazet@google.com> Mime-Version: 1.0 References: <20220623043449.1217288-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH v2 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 Thu Jun 23 04:34: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: 12891756 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 78586CCA489 for ; Thu, 23 Jun 2022 04:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231561AbiFWElB (ORCPT ); Thu, 23 Jun 2022 00:41:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347402AbiFWEfq (ORCPT ); Thu, 23 Jun 2022 00:35:46 -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 2DD2530F71 for ; Wed, 22 Jun 2022 21:35:46 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-3178a95ec78so129982287b3.4 for ; Wed, 22 Jun 2022 21:35:46 -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=GtvcgA6R4Zmr7fxvQzoFAZH92dPnJi89CavOfgZDxl4Fk5bCU6P8SdJ5ANlrAbID8+ PZE2tRMGnsE60CDIVHMZudiAqVEi7EFiWJqnZWsF46amfaD/+8q8kjJFWJvdhYfa9T8u ZRWeb7r8f1B+KjpfoZ1VOSIrlCqN+Yx2RH4HBi5KIfs8/PnrL329BBjvhud8rCIGSZxO 4jw4JOggSufJ90fI2+3t6nF6soSvGimCFgnnCxHQzD8KlvYdz9GN+2t1HyvlEZtVS6RY OZ5yY53gSf1FVaKVzjdNNrBVTQgRLcP9h9tiOn79/64G4pstLF3JtiAY2G84k5Jjsmxd iXYg== 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=S4HVZjrQXvX+YE10LpHJHyt8mMml+4XJyX+SDFtoHSHkO1Udi4wee/G0G5gHnWOlxI WzzDIbMaGtk1TmXrQPWkIR/XNOhXSuE/zhHKwH8IUjlnhZSv9vAWe1DbpiytDm028CMM 0Mlbylodtx2mc9F/4tlIs5Rpb/IsHuoaEf+TEk+571wac2ADdAKmE7BDMjM+sXsox63W yVE5AYg+vIfwyK/zveAoZUG5olVgi8uLysHvbt7Y2W+gYEzJ/GK4xskrtE0fdrTs++1Y mEucSLGX0np1KwTeNeXUHg6NNofmY2tAVpTun6Zptpt+9tsu0IwsxIHtIAGrIyptX4Wx 1Nsg== X-Gm-Message-State: AJIora+NVE+wOUuVyz7NBQW7F+RwaQs/nT8oBUB7iAqwMqYn7ZogCT3v 0M6vzKSBLm+OO9aS1L3FhzwKpN4dxpOuqw== X-Google-Smtp-Source: AGRyM1tfK78Fs1vnrVdxJEhzrvb9l97KcYMn62iw+8DFXSa6gbWNDygP95yplG+H8k5BmPLAzQYMHVetpd2ODw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:729:b0:669:1646:b04 with SMTP id l9-20020a056902072900b0066916460b04mr7693919ybt.107.1655958945509; Wed, 22 Jun 2022 21:35:45 -0700 (PDT) Date: Thu, 23 Jun 2022 04:34:41 +0000 In-Reply-To: <20220623043449.1217288-1-edumazet@google.com> Message-Id: <20220623043449.1217288-12-edumazet@google.com> Mime-Version: 1.0 References: <20220623043449.1217288-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH v2 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 Thu Jun 23 04:34: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: 12891757 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 91E3FCCA487 for ; Thu, 23 Jun 2022 04:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231570AbiFWElD (ORCPT ); Thu, 23 Jun 2022 00:41:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347410AbiFWEfu (ORCPT ); Thu, 23 Jun 2022 00:35:50 -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 F37D430F71 for ; Wed, 22 Jun 2022 21:35:49 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id q138-20020a252a90000000b006694ac29d4eso6491897ybq.14 for ; Wed, 22 Jun 2022 21:35:49 -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=pUmZPhVXrjdGlbnaeLKzElu9MnfSPZmne1g+/EL1Qox1l1ERItxLLf2rQpzjnPBndM fO42fUMCiDHbtk9oV8UENZPj0LK0QOI/uUskrWf2+rOj2XT5/j5bT0tfi1EyZDMP+OfU 8z6JzwKA1ny7Dw/0dsc/d60TLvnXs/a3NvzDa0EuRe68lq6EJtYFaQayYwwBhXo0t0CH Fqv1LQ7fm1WehgKhEkUDDcEB9wL3a6CIHlk6YkpQxg8Z7epqcO38Icg+eJvjG6j44Fnz KjqWw8qkOE0tpwDUrn9paqSvvMicx6cYFs6hTPNyGQxdfQlToBUFHNu++N9gc/OriBx4 5p7g== 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=OPlrPUCgS/3wjv30AmHvnQqP+Rc60qND36qOgroVw5N+4nqQroPIxt7W4/vn5u2MM8 nAx3Jl8FUQ8iB0hsfA4So9ixTDLmcalWmT+JcDRzX1psD3tUOL/vwAis5GbzZjp9Q47f UTDaWz6ISmE9JXXkpscKDKkrYiT/8AvTnrWCdvhO7BPVQP+H+wdKLHC11HdMHBlgIHhj YCeRuVmBJPAG4M+bhk5LJjXqDqectYn9DjvGfAYQWDPpLv0IPHGFGJHJcubhHMb2a9St Vswfwug3cURPyWsjqXqKcPhTaagesyfI2RlN3iajaLo0zqRA9m7Rx96ULWKLvlilbJGL dxsA== X-Gm-Message-State: AJIora+mC3uq6qD5rkW+z8/EEzZH6pnuZl2Wqcv9PYMaMAXKRt3/fnUi dXeYj+2SPKuFnh04MuT1IdwrGI9FQnMqZg== X-Google-Smtp-Source: AGRyM1uORbST/ujU7iR5N3jptcAZ+KkY1L7yoeCeRF/X4xZIKP62Uho+9kIzJivnPhNLJ9BEfPQKCQYQaZAtNQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:7456:0:b0:668:ed94:7744 with SMTP id p83-20020a257456000000b00668ed947744mr6990705ybc.259.1655958949324; Wed, 22 Jun 2022 21:35:49 -0700 (PDT) Date: Thu, 23 Jun 2022 04:34:42 +0000 In-Reply-To: <20220623043449.1217288-1-edumazet@google.com> Message-Id: <20220623043449.1217288-13-edumazet@google.com> Mime-Version: 1.0 References: <20220623043449.1217288-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH v2 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 Thu Jun 23 04:34: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: 12891760 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 B20E8CCA48A for ; Thu, 23 Jun 2022 04:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231579AbiFWElE (ORCPT ); Thu, 23 Jun 2022 00:41:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347415AbiFWEf5 (ORCPT ); Thu, 23 Jun 2022 00:35:57 -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 73AD930F71 for ; Wed, 22 Jun 2022 21:35:56 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-31838c41186so38691407b3.23 for ; Wed, 22 Jun 2022 21:35:56 -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=YBBKiNKqVhttXqdy4f7yctvmSiQKtUm9zJxFrLhx2qPT8PTdUanduaVTl+7tQi29EQ bAsBuaiT9VTVbNh7Y+OiU2fX4m6uWaMp6yhhfX+OCp/F6zry4o39VHJ3qq/QR4zeXzq9 FaS7F7d/jsAJrTKDYOK2aM4Mp45Cs/pFk7qlJF31OBQuCPm5raKVOSu/rIAKy9GHrVGg m0Fu6gpSK1f2tFAulBN0efPVrEtZ3aNpyj4ffcnzWboCY+BuIdMutX21Fg93ycgQyR4H V6aDFgcbaF3KFVaE06LVAJs9g3WRKrRcKNtl8SIt/HQZHCvnv5OAapN77lwysyv0Lo4a WR7w== 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=y0ZR0MQ3I2Wz3UG5lKlvZdVx0cG8+1iR/d7szB8Zgvuak7MIhiPJwhX4ZbOkB29dqA yTliwqpg272d3SS0ItHpzjckIO6mW4v2YM+J3Lw9a+FVSYAt9WD0S3AXMK5vjhDYvt2m RH4KytiNQ8sVb0ttwflMkYEkxi75giSChZ2ucAncP7zQlpESzXfDoLDYm7eAgYJfTyUS h/DZPAOmB1CLMbucAxk209cwVsOumLutre7glMi8Y1ZmAgXQT9JXXjTch8Q0B+CJfiEb K6/KnyO5u8Vv3dWBuhboIIq4oAJKWfaXx35PM0vl0NmzptWiaB6cKTndXdLqJ8U3nS4E FmOw== X-Gm-Message-State: AJIora+SPD17ne4QyWHmGr8DyCpCE0lHXAIV87DWGz5VUWZKUP7CA0aK jpY6+ezhdto0bWdmtqsMbMnQoiAfRl9w8A== X-Google-Smtp-Source: AGRyM1vhkwY4y0b/VkWqUxCiwk9DLOwyoQvMpKB5nuSi3yZNr4iRa+PHmtCgNhDljiiC1Pm6UDAVCkn8s5hgsw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:6ed4:0:b0:664:b4b6:a480 with SMTP id j203-20020a256ed4000000b00664b4b6a480mr7463223ybc.120.1655958955795; Wed, 22 Jun 2022 21:35:55 -0700 (PDT) Date: Thu, 23 Jun 2022 04:34:43 +0000 In-Reply-To: <20220623043449.1217288-1-edumazet@google.com> Message-Id: <20220623043449.1217288-14-edumazet@google.com> Mime-Version: 1.0 References: <20220623043449.1217288-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH v2 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 Thu Jun 23 04:34: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: 12891745 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 4D8BEC433EF for ; Thu, 23 Jun 2022 04:41:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231594AbiFWElG (ORCPT ); Thu, 23 Jun 2022 00:41:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347424AbiFWEgB (ORCPT ); Thu, 23 Jun 2022 00:36:01 -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 D254530F71 for ; Wed, 22 Jun 2022 21:35:59 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-317b6ecba61so96385577b3.9 for ; Wed, 22 Jun 2022 21:35:59 -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=M5KIBZ1LrL60PItHYIsOl6tYrJH8qP6gvKQYwXXYFksDjVL+5E+CspJGLU0my0BIQr sqxMSiJ8mbuL+K58wW+NNdYHjmW4bWDlwedfYXOarpTQUXZe1sWsalL342ZdSsT3Bn94 GSRcEERyZmTN7gjk0xkBRbQ2eO938jGGmUyZ2LPuiGL5l+AF/J3XewplCCNQcuT5wuyW VKFXEtt7HQzuLsMFblSAlC3Og7MF20+S25VG21a70fHduIMyzsrw5rLEEEpupbW95Hm1 3oxLC2164kwto/wGv6OqFlyBPwj/aIN63ihGZdZrV8k6OhKlMlFaGoqR0SV3dyG6Xc4G 3Nug== 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=isQLTRbMT6DV3dcqb1Kwx/MQpQ4zSyyHk4AFPqkvHFJ5e8nkCFvONUP9q58s4hSLdZ IgV3q+m1d3lIyx9M0RRUXVHtILKLp5AzHoHgDDBV1ROiYI28sjAW/dqKb24RqO7tbUWE I3eMJEx98WGRytsb7y07BvqFqdcbZo9C+x/zB8o3SYZH5ZWf33NTejukG/ph4j90TJsD DG8+D4ebK7WgphLIRt/CvaNh/SeZIiUsX8xcZ83u/J/GnkI6dZD4dNyHBZFdIm5jTEbG 50kvQOO8dYYWc/V9rPG1KLTuG+6F/UaSSUbsmI0ZrqrY7gfcizVp9BzDTMkXmid+izxf 6dSQ== X-Gm-Message-State: AJIora8L3P8zBHIu5WYv+nyynw5K+rxpE1Ps+M50WALcpaa4vUqzBsHy mMS1Va+q2474Zj3v5UbIYalrOdBtwvry0A== X-Google-Smtp-Source: AGRyM1saYGInX1aGG7ipnueXSl08hv+Xyl68UNWxvzSAo1uJHQtl+AGaxdtGvw1LBL+DvjcRRAeUnE7M7crybg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:dcc5:0:b0:664:7913:46af with SMTP id y188-20020a25dcc5000000b00664791346afmr7489138ybe.339.1655958959145; Wed, 22 Jun 2022 21:35:59 -0700 (PDT) Date: Thu, 23 Jun 2022 04:34:44 +0000 In-Reply-To: <20220623043449.1217288-1-edumazet@google.com> Message-Id: <20220623043449.1217288-15-edumazet@google.com> Mime-Version: 1.0 References: <20220623043449.1217288-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH v2 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 Thu Jun 23 04:34: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: 12891746 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 5F69AC43334 for ; Thu, 23 Jun 2022 04:41:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229545AbiFWElH (ORCPT ); Thu, 23 Jun 2022 00:41:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237157AbiFWEgD (ORCPT ); Thu, 23 Jun 2022 00:36: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 AC49730F71 for ; Wed, 22 Jun 2022 21:36:02 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id b11-20020a5b008b000000b00624ea481d55so16361850ybp.19 for ; Wed, 22 Jun 2022 21:36: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=1mcBhyhkyYvUwin15ciKRtLj/bHT6HY5NDONX+E6MMM=; b=DOginrh/azzPHXR1RdvWdZlu6WV7mnOS7e/tflHGMkK2f1hnleallGApSK5vdmOuv2 dhxxZepcit/X1R0HWBvZ1BJk3BpdMjfPz4O8SvFuLkV6OTqMxvTR0vzaPI7XNWgClNz5 8UhFrzgp6UhtLiT9S5EZs0c5wylvs54gjCXsIgfdjL+XLH27CMbmAdsomCpy0eeRani+ J95/FaihgSayxhQ9P2Lkny+dyPVvQIbjnlOfuuCm21Yejo6RfKzV20jrL/wXzAEsM4kg 6eX+RSi0daNVyTRqtHXIbMYoMdmqrwVTnRt0b30Nv8SYqTTu/akHLZIj7RJew1L03fVW Pq0A== 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=xjKE/Nq7/ryifARhYwdHVPlVAJOOQLT+TnyBdOVm+6omtGWYQeRvKhroMOxPpoTXC2 2jwDCmy+CIecKe5GjdEDyWD45YfX00jrAG+JdZXLofdE6ZiobZTTf7llzkNaxdnrY+IB 54tFKLhxO44p166O3m39afKx0WnsI5NtdaaznbtU3K0rOYmyR5wHp+EgWW/CCDLOFfaW xSn2/70kt9xJnj6d4Qi3kSMdxoRqF2J9qqUBfzkOJukyu+sqpil+JjhuHKaCV7R97QGB nCTQXo2sil5dvwetRZGqXIX5qxGrM0wfw2RtIs8qfKh4f7Q0ybPq9sO/OzywZ8J+reRR fOMQ== X-Gm-Message-State: AJIora+ZcH7ClzA+qrLSKUUIt1D6m6EiqEZTAXRa5h2rJb8OCAUvSuwJ FKdH8XkepTbkvk0F6MgEtZ2Nh1QrI4JunA== X-Google-Smtp-Source: AGRyM1uDrehv+wg6Ia+zZH28QY6cVXv2eFuenStE853j2zs2xcBkAdmI5c2SSdtt06FcdBbRl9YA84pudp6FUQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:57d2:0:b0:317:81b3:2460 with SMTP id l201-20020a8157d2000000b0031781b32460mr8672055ywb.493.1655958961931; Wed, 22 Jun 2022 21:36:01 -0700 (PDT) Date: Thu, 23 Jun 2022 04:34:45 +0000 In-Reply-To: <20220623043449.1217288-1-edumazet@google.com> Message-Id: <20220623043449.1217288-16-edumazet@google.com> Mime-Version: 1.0 References: <20220623043449.1217288-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH v2 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 Thu Jun 23 04:34: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: 12891747 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 D66D6C43334 for ; Thu, 23 Jun 2022 04:41:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231602AbiFWElI (ORCPT ); Thu, 23 Jun 2022 00:41:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347428AbiFWEgG (ORCPT ); Thu, 23 Jun 2022 00:36:06 -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 0ADCA30F71 for ; Wed, 22 Jun 2022 21:36:06 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id u128-20020a25dd86000000b0066073927e92so16375136ybg.13 for ; Wed, 22 Jun 2022 21:36: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=7rjrQ3wFza4ZoUN3WC5B+Xi/dWO10C5OH6N7utNmGIw=; b=XPKp+yeTV8kBer50XdEliSxmVxI5FdyYS54U+YJCZu2Vimo5kG1Fnaqq6wN77Ixysk fNOzsOFrLUDrkk7qoPt47M1Gm+PVCFu0PojkH+7nASs36bsUc4U8M6klrKudM657xf/K aFq5SucgvDF3Gfx1YAtjxId1zhBrsQU0ykx3d/k5wsQBjfQCwxH+GVSOxxZf8hwgbvH8 Kvqa5XDG4EMPFXIsneonstlj+3LGl6IUTE7eqqZm2N1I8jAnTrRGnbB3JMQ7Vmqy5JfG 7Cwk80WJmWdZ0kTrGOjGTJ+JH0XeImfwOiaFyRSm0uzrKR6GcTTjp28pDKqIWmVGKNgj gviA== 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=Kaiojym1qD/oWnrk0T/t0MtvQkCrDlAhEJ2yTZtBRwb/P6pRJQXkqlgtWZgSELA1Am IE2zsiCLsrqSpITNeR0kV6jj/kJbQrfwCLgimrz4it5rYpM0K2wR8kiN+mkK8GFEu3j4 zhC4v6GIHaPjYQl+KnCBAR7+ELgHTHFey0CpUDGD/O2uaXKzi4AKdSl3sGuJarWrasGd TZTLGqVPfax5GnUnu4qjb1BpWqOJrkadQG6cKHenss/GPi8xABWPchx3JPfCEN7e3C9t kcPuvqQCrjQxSGLBfpcv7004vrJ3OOqaMQWwROk+gEGgECvxG4oZlspTQGIjjeBHLmUA 4FkQ== X-Gm-Message-State: AJIora8XsNC1kAqF2Uee37FPJ0zTucHw+xjX9f/X8QGbDm1hLdqxRlFs ySVHbbJZk4iSvc7NVx5pGUP8OxTRwKkwYQ== X-Google-Smtp-Source: AGRyM1vaFIwLnSAoamL0yoOoGLJURmnQyfZlV54MhqpYeGPYyRYFdH2BZj0rsA4pINRJgKNcf7IhdwB45d2Wlw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:e30a:0:b0:664:be46:1577 with SMTP id z10-20020a25e30a000000b00664be461577mr7475359ybd.418.1655958965362; Wed, 22 Jun 2022 21:36:05 -0700 (PDT) Date: Thu, 23 Jun 2022 04:34:46 +0000 In-Reply-To: <20220623043449.1217288-1-edumazet@google.com> Message-Id: <20220623043449.1217288-17-edumazet@google.com> Mime-Version: 1.0 References: <20220623043449.1217288-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH v2 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 Thu Jun 23 04:34: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: 12891758 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 C1D97CCA48B for ; Thu, 23 Jun 2022 04:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229975AbiFWElP (ORCPT ); Thu, 23 Jun 2022 00:41:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347436AbiFWEgM (ORCPT ); Thu, 23 Jun 2022 00:36:12 -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 0175530F71 for ; Wed, 22 Jun 2022 21:36:12 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-31814f7654dso55513497b3.15 for ; Wed, 22 Jun 2022 21:36: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=pMVAfLUneu2rDqkIvgFtPAjyay5c/7uMbjWw3cM7zHg=; b=pMd86Be5TmWcdvffOplX7AkPp7j+d3STtyxbVjr3qZv5JcfsM87d8ZS/+IC3NkWFfW yysBNOpReCBUHmodZF7OZTGiEhLzBKHCRO7WCl6Qe/Sqa7NUQUTcbQnzr4RwNqZFlP4q 6y6AeaZnCfvm4BVy7YRWz/gxcsbUkekIJntad5cu32aC0E759GYjvK35Pst5LAg5QcMX zcbAYvUjJ8l3IripzPwc8Qh9nes+3mHPE7JtnH9SKEDteYlXg5Cp6Iadj6I6vfRi60/e FL4e7ogFYlPsuinjXq/aiCJHKIUVveabNLiF0VhL1SNhfq5rUzuX2rnirbTWGUJAp/Pz 1VWg== 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=rFEtwO1rXlhV8K16u8zlPElUV1S0Q2DFXGumxBCki82BzZsp0zIF6d6f2g39L0Paca 9Dj8mcc+5NTWlPkm8CvsvUvJYSWRyHduZGhEMOOJYX43UOqG4C6Pnqcpdg0+ldzqW+TS eUNdyAnW2YgmbxHsnGCDXBb0qpSYSDQRX254DovYxZl0+OOsMf+/ji8DgNfVRyOxEmOy Ytbyzl2wjiaZQ9wIne7hJmxymvnQ6tjmL0ttd3Wou0TxL/3JreqABMsC+eIZP9SuMtnW iEUsbC+4kGUxuLq59Qfqm6YduAZVj8CBG/BNYzMrbpvljBBD7DKSQUYDyJATbUQlxurV 8ewA== X-Gm-Message-State: AJIora+dbBD1nDSP8DPlPave9km1Y4JS4RCN1/mfUwBiTQLziZc3iftE fDOVCJPq7jPZArAJkjHYJbSFxvLhwSd4qQ== X-Google-Smtp-Source: AGRyM1so+89CtzrzvXQYOfRQviGyVnY5Ljko+lZt7fqyToC9zTZUVnSVmV8/fLLMUrDqPlqFpp2NVAlR40ZqvA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:9891:0:b0:317:a4a7:fdb0 with SMTP id p139-20020a819891000000b00317a4a7fdb0mr8185784ywg.313.1655958971335; Wed, 22 Jun 2022 21:36:11 -0700 (PDT) Date: Thu, 23 Jun 2022 04:34:47 +0000 In-Reply-To: <20220623043449.1217288-1-edumazet@google.com> Message-Id: <20220623043449.1217288-18-edumazet@google.com> Mime-Version: 1.0 References: <20220623043449.1217288-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH v2 net-next 17/19] ipmr: convert /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 Thu Jun 23 04:34: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: 12891759 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 D444AC43334 for ; Thu, 23 Jun 2022 04:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229607AbiFWElZ (ORCPT ); Thu, 23 Jun 2022 00:41:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347442AbiFWEgP (ORCPT ); Thu, 23 Jun 2022 00:36:15 -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 9E21C30F71 for ; Wed, 22 Jun 2022 21:36:14 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2dc7bdd666fso160682707b3.7 for ; Wed, 22 Jun 2022 21:36: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=e+ZYZ7kE/qwElnjvjgd5Ved7ybd2g9symWMcNhHL2Fs=; b=T9LHPc7ATfTlMXS52Bz3DwE8sYmoQ7FMmqx0RLiV4j1NKy/NRhwU+/Kc+eAShzgKWX EEFam0IyxUgv1h0glqBj4ViFTGQaEt5oH8uw8Is05qq5A/cmXKK1sYAIT8b5miTIqOxt pAzCPUAk50r0T3aNw/DNz7Bk+sZvDn4HEX60lcuXKvbVxOOEtRfjm6ZEn4BpkO7myzEi nC8dYAEKcWqAt2g8YckzMq05EIESUSI7VYQMMRmdXDgeQxzTMppNJU4qXZzu2TwM2G3U 8lyNEQEXGM15hwiLwgHN/qj/IT4McVDHbbrhNCu63JZBokg68+EEnmvvieXsKsO+QC72 RwhA== 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=idrGLZQLK5q+DFBpF/XpyAuRgonLtMFLitAfqpwUOhpEFraF+YGCEYvBOTzUTYwJ6D RHaBTexxNr3CpXJ4VOmk8fLjpgyh2rI3Ge1uyG9/CqBSRBlnsL7NGawJlPKgD6p7Gp/b DWPqjBYjCbxyIqyB1v6EHQvx0iWKxKHZQJRgs3rbgx+LyC4DppXYwLz6ULKFH5Rntye1 PkRFIY4L8etCCjg9BbMy/JIp0bKyBYXNr/uN4ajcpnUViufY/Wn+N2dyC87LC11WazMi fPds6Zh+oMU/wYE0gKQvyFuVoon617Mzn3a3/QtSLwc9d6dgVx8ZvGp+9qBlDhdOzJ99 xN+g== X-Gm-Message-State: AJIora/dSMxU1G7FbusXhYS2+dth0z2dVfLffJPPrh3guZn/sgTu7Usn vHDc22AqIx1RB+Ro8JIvT62FE+Bz3OlX/A== X-Google-Smtp-Source: AGRyM1tjFnDF5Q91lXODf/pFhllq9hr7e4ZL3LLtHhaKEgJ2ddrSFUGi1CkSIMgaTRoKFoB5HZHz9wqEWFjxRA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:140a:b0:663:896e:4a86 with SMTP id z10-20020a056902140a00b00663896e4a86mr7797722ybu.574.1655958973933; Wed, 22 Jun 2022 21:36:13 -0700 (PDT) Date: Thu, 23 Jun 2022 04:34:48 +0000 In-Reply-To: <20220623043449.1217288-1-edumazet@google.com> Message-Id: <20220623043449.1217288-19-edumazet@google.com> Mime-Version: 1.0 References: <20220623043449.1217288-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH v2 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); From patchwork Thu Jun 23 04:34: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: 12891761 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 EC355CCA48D for ; Thu, 23 Jun 2022 04:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229759AbiFWEl1 (ORCPT ); Thu, 23 Jun 2022 00:41:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347452AbiFWEgX (ORCPT ); Thu, 23 Jun 2022 00:36:23 -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 A886130F71 for ; Wed, 22 Jun 2022 21:36:22 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-317a4c8a662so104882337b3.6 for ; Wed, 22 Jun 2022 21:36: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=9hpBdccy74sS7LhLCkjUZlDSBI954GNR5j1me5KZlE8=; b=GK+fixkDrlsidXLSyvKPfC26rPClSnVyscxqQvDt6bdZlYFdj+UEKmxOZc+iqq0QGx JzgwarjIGJDA2CHcwsa0P2MrJqJCuQ1E7zn8QwVbC8wQmunmEtyhJ2OMUTWvYf0cFRIC JcbrSO/YO9lcKDBCtK+pvGNmlP3IzO8w2HQUiQ8zg+jN/zzGCKEmR1axqxjHQkvBYIKx wLgndPtbSxmE+CTuNcYuyjK1ggG5/LONDKFr8ZzQMubnfeY+wPuniSFo195dEhycp5l4 plxfiGts4gT72Wh0qkpPNOCoj/3RWtsyB4oBr0Ehy9zfwVltQfKufK8DRNi+7ETBoChc FPgg== 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=9hpBdccy74sS7LhLCkjUZlDSBI954GNR5j1me5KZlE8=; b=fk7bOYjEt4NZOhmOueNMp5ZKoVTqEKoVdcE5rGp5/hyVnDZWcKfqO7AWOMfbdybu5t 2VGsvOizsvVqFyojO3sA5ycaBzUAwHPRSbk8CK60x5pjvFH0HwJ/9b/VzxVTqswLy40x 8LB74OroSG6CrZXVF0ksKrq0NuyWLE7WZsEIibO8o/67WD3sbzeqSlel85zKB16quriy 5XBAZQlDDKnTVpDsTMGV6J5mYFnCSoBdF67H/A0Hd+Q3AgSNaCYA9T38Rw6kQnFwKsHa oVmLxgesCUOAJX3dhVlfpL1RK5F8qxoKaQLnas83Kw47Np29AZyCxDjbb2LAh3pj9XoA SBNg== X-Gm-Message-State: AJIora+aXDaPzJgh21URdQpyMMbQ8uTitsB1SpvxHn019Wd3KLzWaLdS lnT2eELkgmcBgZP7LiRwrd4IIk2gTJXdNQ== X-Google-Smtp-Source: AGRyM1s8s7CK3vj94kIHeXK3IdC7Z6EIP0PaznQeLb46bmW50K5lwNfUk7e2aHeUe4YaqsqyW4NXwjPDfls3FQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:12d6:0:b0:314:6097:b272 with SMTP id 205-20020a8112d6000000b003146097b272mr8522541yws.159.1655958981873; Wed, 22 Jun 2022 21:36:21 -0700 (PDT) Date: Thu, 23 Jun 2022 04:34:49 +0000 In-Reply-To: <20220623043449.1217288-1-edumazet@google.com> Message-Id: <20220623043449.1217288-20-edumazet@google.com> Mime-Version: 1.0 References: <20220623043449.1217288-1-edumazet@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH v2 net-next 19/19] ip6mr: 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/ipv6/ip6mr.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index 7381cfdac3e376c97917465918a464bd61643f2a..ec6e1509fc7cdfaf55bc79034f43b6e3ce0434ed 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -62,12 +62,11 @@ struct ip6mr_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 */ @@ -714,7 +713,7 @@ static int mif6_delete(struct mr_table *mrt, int vifi, int notify, call_ip6mr_vif_entry_notifiers(read_pnet(&mrt->net), FIB_EVENT_VIF_DEL, v, dev, vifi, mrt->id); - write_lock_bh(&mrt_lock); + spin_lock(&mrt_lock); RCU_INIT_POINTER(v->dev, NULL); #ifdef CONFIG_IPV6_PIMSM_V2 @@ -733,7 +732,7 @@ static int mif6_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); @@ -833,7 +832,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 ip6mr_update_thresholds(struct mr_table *mrt, struct mr_mfc *cache, @@ -919,7 +918,7 @@ static int mif6_add(struct net *net, struct mr_table *mrt, MIFF_REGISTER); /* 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); #ifdef CONFIG_IPV6_PIMSM_V2 @@ -928,7 +927,7 @@ static int mif6_add(struct net *net, struct mr_table *mrt, #endif if (vifi + 1 > mrt->maxvif) WRITE_ONCE(mrt->maxvif, vifi + 1); - write_unlock_bh(&mrt_lock); + spin_unlock(&mrt_lock); call_ip6mr_vif_entry_notifiers(net, FIB_EVENT_VIF_ADD, v, dev, vifi, mrt->id); return 0; @@ -1442,12 +1441,12 @@ static int ip6mr_mfc_add(struct net *net, struct mr_table *mrt, &mfc->mf6cc_mcastgrp.sin6_addr, parent); rcu_read_unlock(); if (c) { - write_lock_bh(&mrt_lock); + spin_lock(&mrt_lock); c->_c.mfc_parent = mfc->mf6cc_parent; ip6mr_update_thresholds(mrt, &c->_c, ttls); if (!mrtsock) c->_c.mfc_flags |= MFC_STATIC; - write_unlock_bh(&mrt_lock); + spin_unlock(&mrt_lock); call_ip6mr_mfc_entry_notifiers(net, FIB_EVENT_ENTRY_REPLACE, c, mrt->id); mr6_netlink_event(mrt, c, RTM_NEWROUTE); @@ -1565,7 +1564,7 @@ static int ip6mr_sk_init(struct mr_table *mrt, struct sock *sk) struct net *net = sock_net(sk); rtnl_lock(); - write_lock_bh(&mrt_lock); + spin_lock(&mrt_lock); if (rtnl_dereference(mrt->mroute_sk)) { err = -EADDRINUSE; } else { @@ -1573,7 +1572,7 @@ static int ip6mr_sk_init(struct mr_table *mrt, struct sock *sk) sock_set_flag(sk, SOCK_RCU_FREE); atomic_inc(&net->ipv6.devconf_all->mc_forwarding); } - write_unlock_bh(&mrt_lock); + spin_unlock(&mrt_lock); if (!err) inet6_netconf_notify_devconf(net, RTM_NEWNETCONF, @@ -1603,14 +1602,14 @@ int ip6mr_sk_done(struct sock *sk) rtnl_lock(); ip6mr_for_each_table(mrt, net) { if (sk == rtnl_dereference(mrt->mroute_sk)) { - write_lock_bh(&mrt_lock); + spin_lock(&mrt_lock); RCU_INIT_POINTER(mrt->mroute_sk, NULL); /* Note that mroute_sk had SOCK_RCU_FREE set, * so the RCU grace period before sk freeing * is guaranteed by sk_destruct() */ atomic_dec(&devconf->mc_forwarding); - write_unlock_bh(&mrt_lock); + spin_unlock(&mrt_lock); inet6_netconf_notify_devconf(net, RTM_NEWNETCONF, NETCONFA_MC_FORWARDING, NETCONFA_IFINDEX_ALL, @@ -2097,7 +2096,7 @@ static int ip6mr_forward2(struct net *net, struct mr_table *mrt, return 0; } -/* Called with mrt_lock or rcu_read_lock() */ +/* Called with rcu_read_lock() */ static int ip6mr_find_vif(struct mr_table *mrt, struct net_device *dev) { int ct;