{"id":818943,"url":"http://patchwork.ozlabs.org/api/patches/818943/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/patch/20170927062322.5476-3-jiri@resnulli.us/","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170927062322.5476-3-jiri@resnulli.us>","list_archive_url":null,"date":"2017-09-27T06:23:12","name":"[net-next,v3,02/12] ipmr: Add reference count to MFC entries","commit_ref":null,"pull_url":null,"state":"accepted","archived":true,"hash":"2a19e14fd643180acaa41eaf1c21f1bf84ee5e0f","submitter":{"id":15321,"url":"http://patchwork.ozlabs.org/api/people/15321/?format=json","name":"Jiri Pirko","email":"jiri@resnulli.us"},"delegate":{"id":34,"url":"http://patchwork.ozlabs.org/api/users/34/?format=json","username":"davem","first_name":"David","last_name":"Miller","email":"davem@davemloft.net"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/20170927062322.5476-3-jiri@resnulli.us/mbox/","series":[{"id":5290,"url":"http://patchwork.ozlabs.org/api/series/5290/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/list/?series=5290","date":"2017-09-27T06:23:12","name":"mlxsw: Add support for offloading IPv4 multicast routes","version":3,"mbox":"http://patchwork.ozlabs.org/series/5290/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/818943/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/818943/checks/","tags":{},"related":[],"headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=resnulli-us.20150623.gappssmtp.com\n\theader.i=@resnulli-us.20150623.gappssmtp.com\n\theader.b=\"QIGPlDhR\"; dkim-atps=neutral"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3y277G3DJjz9sBW\n\tfor <patchwork-incoming@ozlabs.org>;\n\tWed, 27 Sep 2017 16:23:38 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1751832AbdI0GXe (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tWed, 27 Sep 2017 02:23:34 -0400","from mail-wm0-f68.google.com ([74.125.82.68]:47248 \"EHLO\n\tmail-wm0-f68.google.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1751059AbdI0GX1 (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Wed, 27 Sep 2017 02:23:27 -0400","by mail-wm0-f68.google.com with SMTP id r136so14285773wmf.2\n\tfor <netdev@vger.kernel.org>; Tue, 26 Sep 2017 23:23:26 -0700 (PDT)","from localhost (jirka.pirko.cz. [84.16.102.26])\n\tby smtp.gmail.com with ESMTPSA id\n\tg25sm3571879wmc.16.2017.09.26.23.23.25\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tTue, 26 Sep 2017 23:23:25 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=resnulli-us.20150623.gappssmtp.com; s=20150623;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=EvWmEsRlGNX6zHH5OsnSY27I//X7brK5d30J/W+Fc1Q=;\n\tb=QIGPlDhRTshwyspapXZriFv2U0A6es9o5hJMMW488bQs5vntiDAlimWlIf7W9Sg8sE\n\tkrY2nSVXRa6tdb9cbXURKXI3iqd9uxn0Ql3adp/FcUdClgLuIuZccHH52e+KaJtfrVSz\n\tvDxGuO9WOtdoRF2bbvWb4C1D281zJea0NHW6ztzHCkySChfntla1kdt2ApqhNHGTPyMJ\n\tV8oGmhWeQ8ZV5ts1G+U2manSuEHL+bnVsagg37dr3vD71PAFM0fBqluTDoViuI6iPrne\n\tHJd/C7chcKjkxWan49LNmyFLc0pHiwvTYd+D9IU9CfNxOuQT+k8xD5/0VhK3j6/Dstz9\n\tcdVg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=EvWmEsRlGNX6zHH5OsnSY27I//X7brK5d30J/W+Fc1Q=;\n\tb=XitWHX+2UjKOXpJ9Xbcloqt/7J0BLRiJ1VY3KopsIQ2dRgQvjeFbeFmGtw/0nhu6AE\n\tMvzyVvG4wd3WWWNvXpabBKak3fb04JBIJ4zWMIc9GHoFKlP7flhtkzLiT3DQgmk9J669\n\tq+8+xZXPr+7MrgK7VcSnIUmnCOrdGItaUV6BI4jlfeksdQrrmC1ziw3wtU+rYqKJgQRd\n\tic2A3wGzcCJKsFumBFh4HVLLAvQFU5rTNcRpXC38wBwohrcjvz6pPormNDan+6doqEvW\n\tcpBQMgeI4x6hFdTzIpgOqnVnFNNAkKpn0RDbOAbywTz9XQihhkVX1a2bhDeAnz4/ywsa\n\twsqg==","X-Gm-Message-State":"AHPjjUhjCkYhTxD5uJ5GMs1N4gom5aZeG/RLsbwUHcjx6lGfwXFqFv6S\n\t1BtZ6aSZUkT70AoHY4g1rG0DMooT","X-Google-Smtp-Source":"AOwi7QC1mDlzgqbjtR/heoSpe83j3zSHi63yCb8pIvz1EbYUMPUJt/jSmav5hWSBwDSZBWUsS+dang==","X-Received":"by 10.28.92.19 with SMTP id q19mr546018wmb.150.1506493405707;\n\tTue, 26 Sep 2017 23:23:25 -0700 (PDT)","From":"Jiri Pirko <jiri@resnulli.us>","To":"netdev@vger.kernel.org","Cc":"davem@davemloft.net, yotamg@mellanox.com, idosch@mellanox.com,\n\tmlxsw@mellanox.com, nikolay@cumulusnetworks.com, andrew@lunn.ch,\n\tlinyunsheng@huawei.com","Subject":"[patch net-next v3 02/12] ipmr: Add reference count to MFC entries","Date":"Wed, 27 Sep 2017 08:23:12 +0200","Message-Id":"<20170927062322.5476-3-jiri@resnulli.us>","X-Mailer":"git-send-email 2.9.5","In-Reply-To":"<20170927062322.5476-1-jiri@resnulli.us>","References":"<20170927062322.5476-1-jiri@resnulli.us>","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"From: Yotam Gigi <yotamg@mellanox.com>\n\nNext commits will introduce MFC notifications through the atomic\nfib_notification chain, thus allowing modules to be aware of MFC entries.\n\nDue to the fact that modules may need to hold a reference to an MFC entry,\nadd reference count to MFC entries to prevent them from being freed while\nthese modules use them.\n\nThe reference counting is done only on resolved MFC entries currently.\n\nSigned-off-by: Yotam Gigi <yotamg@mellanox.com>\nReviewed-by: Ido Schimmel <idosch@mellanox.com>\nSigned-off-by: Jiri Pirko <jiri@mellanox.com>\nReviewed-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>\n---\nv1->v2:\n - Add comment for the mfc_cache.mfc_un.res.refcount field, similarly to\n   all other fields in the struct\n---\n include/linux/mroute.h | 21 +++++++++++++++++++++\n net/ipv4/ipmr.c        |  8 +++++---\n 2 files changed, 26 insertions(+), 3 deletions(-)","diff":"diff --git a/include/linux/mroute.h b/include/linux/mroute.h\nindex d7f6333..10028f2 100644\n--- a/include/linux/mroute.h\n+++ b/include/linux/mroute.h\n@@ -109,6 +109,7 @@ struct mfc_cache_cmp_arg {\n  * @wrong_if: number of wrong source interface hits\n  * @lastuse: time of last use of the group (traffic or update)\n  * @ttls: OIF TTL threshold array\n+ * @refcount: reference count for this entry\n  * @list: global entry list\n  * @rcu: used for entry destruction\n  */\n@@ -138,6 +139,7 @@ struct mfc_cache {\n \t\t\tunsigned long wrong_if;\n \t\t\tunsigned long lastuse;\n \t\t\tunsigned char ttls[MAXVIFS];\n+\t\t\trefcount_t refcount;\n \t\t} res;\n \t} mfc_un;\n \tstruct list_head list;\n@@ -148,4 +150,23 @@ struct rtmsg;\n int ipmr_get_route(struct net *net, struct sk_buff *skb,\n \t\t   __be32 saddr, __be32 daddr,\n \t\t   struct rtmsg *rtm, u32 portid);\n+\n+#ifdef CONFIG_IP_MROUTE\n+void ipmr_cache_free(struct mfc_cache *mfc_cache);\n+#else\n+static inline void ipmr_cache_free(struct mfc_cache *mfc_cache)\n+{\n+}\n+#endif\n+\n+static inline void ipmr_cache_put(struct mfc_cache *c)\n+{\n+\tif (refcount_dec_and_test(&c->mfc_un.res.refcount))\n+\t\tipmr_cache_free(c);\n+}\n+static inline void ipmr_cache_hold(struct mfc_cache *c)\n+{\n+\trefcount_inc(&c->mfc_un.res.refcount);\n+}\n+\n #endif\ndiff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c\nindex c9b3e6e..86dc5f9 100644\n--- a/net/ipv4/ipmr.c\n+++ b/net/ipv4/ipmr.c\n@@ -652,10 +652,11 @@ static void ipmr_cache_free_rcu(struct rcu_head *head)\n \tkmem_cache_free(mrt_cachep, c);\n }\n \n-static inline void ipmr_cache_free(struct mfc_cache *c)\n+void ipmr_cache_free(struct mfc_cache *c)\n {\n \tcall_rcu(&c->rcu, ipmr_cache_free_rcu);\n }\n+EXPORT_SYMBOL(ipmr_cache_free);\n \n /* Destroy an unresolved cache entry, killing queued skbs\n  * and reporting error to netlink readers.\n@@ -949,6 +950,7 @@ static struct mfc_cache *ipmr_cache_alloc(void)\n \tif (c) {\n \t\tc->mfc_un.res.last_assert = jiffies - MFC_ASSERT_THRESH - 1;\n \t\tc->mfc_un.res.minvif = MAXVIFS;\n+\t\trefcount_set(&c->mfc_un.res.refcount, 1);\n \t}\n \treturn c;\n }\n@@ -1162,7 +1164,7 @@ static int ipmr_mfc_delete(struct mr_table *mrt, struct mfcctl *mfc, int parent)\n \trhltable_remove(&mrt->mfc_hash, &c->mnode, ipmr_rht_params);\n \tlist_del_rcu(&c->list);\n \tmroute_netlink_event(mrt, c, RTM_DELROUTE);\n-\tipmr_cache_free(c);\n+\tipmr_cache_put(c);\n \n \treturn 0;\n }\n@@ -1264,7 +1266,7 @@ static void mroute_clean_tables(struct mr_table *mrt, bool all)\n \t\trhltable_remove(&mrt->mfc_hash, &c->mnode, ipmr_rht_params);\n \t\tlist_del_rcu(&c->list);\n \t\tmroute_netlink_event(mrt, c, RTM_DELROUTE);\n-\t\tipmr_cache_free(c);\n+\t\tipmr_cache_put(c);\n \t}\n \n \tif (atomic_read(&mrt->cache_resolve_queue_len) != 0) {\n","prefixes":["net-next","v3","02/12"]}