{"id":817947,"url":"http://patchwork.ozlabs.org/api/patches/817947/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/patch/20170924172212.10096-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":"<20170924172212.10096-3-jiri@resnulli.us>","list_archive_url":null,"date":"2017-09-24T17:22:02","name":"[net-next,v2,02/12] ipmr: Add reference count to MFC entries","commit_ref":null,"pull_url":null,"state":"changes-requested","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/20170924172212.10096-3-jiri@resnulli.us/mbox/","series":[{"id":4828,"url":"http://patchwork.ozlabs.org/api/series/4828/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/list/?series=4828","date":"2017-09-24T17:22:00","name":"mlxsw: Add support for offloading IPv4 multicast routes","version":2,"mbox":"http://patchwork.ozlabs.org/series/4828/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/817947/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/817947/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=\"vGv8Og93\"; dkim-atps=neutral"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3y0YvQ26ZMz9sRm\n\tfor <patchwork-incoming@ozlabs.org>;\n\tMon, 25 Sep 2017 03:22:58 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1752754AbdIXRWW (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tSun, 24 Sep 2017 13:22:22 -0400","from mail-wr0-f194.google.com ([209.85.128.194]:37324 \"EHLO\n\tmail-wr0-f194.google.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1752624AbdIXRWR (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Sun, 24 Sep 2017 13:22:17 -0400","by mail-wr0-f194.google.com with SMTP id u48so63989wrf.4\n\tfor <netdev@vger.kernel.org>; Sun, 24 Sep 2017 10:22:16 -0700 (PDT)","from localhost (ip-89-177-136-69.net.upcbroadband.cz.\n\t[89.177.136.69]) by smtp.gmail.com with ESMTPSA id\n\to59sm9354325wrc.45.2017.09.24.10.22.15\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tSun, 24 Sep 2017 10:22:15 -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=sCfD50lGYpeOGdL3cn4CjssRpITQPPajSE/zCzq4r1g=;\n\tb=vGv8Og93P+Alw5xQQZ6H/b6iJwB3zMWyi/UVjF468IBGAUZXUMg4Sg+8HcmjeXT51L\n\truCm11t2jtM3cu5xG72EIFdPyBFkc456M///Xs32QOcOG9n1pzL9IguPVYf5sxu9oceO\n\t2oid4dzEJWb21hw1dkJ2K1CvoKR32e/u37Z8S31jPs4orwSJIuT69+2RXoj5ZTSRxRwf\n\t2MLq0JMeOcTu8UPXDiF/p4imdxzSsFRUq3BFQOjDIMhWAEBvESDCBzJ6OvX23yffxuPZ\n\tR8/5ZvjUEUFfggHzCOfnL92iaEXJf7xGKwIMwa4tTkomXLQJ++xUfJ6j+D7RodnnNI4F\n\tOu5w==","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=sCfD50lGYpeOGdL3cn4CjssRpITQPPajSE/zCzq4r1g=;\n\tb=pokH2q7cIzkDY5LtTjmZAFke7LpiyyzrVoOlZpRQRNK5P1NGxDOjXy3656Q9XoPjq7\n\txr1cyStejfUro+H8/rMRXD7nlm0nsnTgQRLUtlYFp6NLnY0IUfzwttgEuYXSTbsrSkac\n\t7T/30q8sENvwxSufAs8nRArVaBjBoh93mlwSa99jv7eaUEUzSQfbYjW7BTV889lAsVbe\n\tFv69Z+XYr8BmgETl9w7MqYHhH8nXolKdkH1NVYZkXnk6Ypnijh703WU/YMugHzHn0wNk\n\tyBAuvkPBoCSaQ15mMI6m9y8V/05kFslgzLiRRk3qYF/cO8C7UySWJP6dQVjomWFJzW5n\n\tMqWA==","X-Gm-Message-State":"AHPjjUj69FoQ8+hoag+n8GtjPkR1duiI5vyKdn9Vsgz7qjq/cZh25XvA\n\tuAaLzhrhmoQcEpXr55pkKfPcNLy5","X-Google-Smtp-Source":"AOwi7QBx5wW5+UL1toguhK0D595qit9v4y1TciCtWcKHyMtwubwXUwZYFg4JwGriVx9sN/0Wn9IhTw==","X-Received":"by 10.223.175.100 with SMTP id z91mr4553824wrc.177.1506273735693;\n\tSun, 24 Sep 2017 10:22:15 -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","Subject":"[patch net-next v2 02/12] ipmr: Add reference count to MFC entries","Date":"Sun, 24 Sep 2017 19:22:02 +0200","Message-Id":"<20170924172212.10096-3-jiri@resnulli.us>","X-Mailer":"git-send-email 2.9.5","In-Reply-To":"<20170924172212.10096-1-jiri@resnulli.us>","References":"<20170924172212.10096-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>\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","v2","02/12"]}