[{"id":1772738,"web_url":"http://patchwork.ozlabs.org/comment/1772738/","msgid":"<54cb367e-3769-ce9f-27dc-e08ee710bd98@cumulusnetworks.com>","list_archive_url":null,"date":"2017-09-21T11:56:59","subject":"Re: [patch net-next 02/12] ipmr: Add reference count to MFC entries","submitter":{"id":66448,"url":"http://patchwork.ozlabs.org/api/people/66448/","name":"Nikolay Aleksandrov","email":"nikolay@cumulusnetworks.com"},"content":"On 21/09/17 09:43, Jiri Pirko wrote:\n> From: Yotam Gigi <yotamg@mellanox.com>\n> \n> Next commits will introduce MFC notifications through the atomic\n> fib_notification chain, thus allowing modules to be aware of MFC entries.\n> \n> Due to the fact that modules may need to hold a reference to an MFC entry,\n> add reference count to MFC entries to prevent them from being freed while\n> these modules use them.\n> \n> The reference counting is done only on resolved MFC entries currently.\n> \n> Signed-off-by: Yotam Gigi <yotamg@mellanox.com>\n> Reviewed-by: Ido Schimmel <idosch@mellanox.com>\n> Signed-off-by: Jiri Pirko <jiri@mellanox.com>\n> ---\n>  include/linux/mroute.h | 20 ++++++++++++++++++++\n>  net/ipv4/ipmr.c        |  8 +++++---\n>  2 files changed, 25 insertions(+), 3 deletions(-)\n> \n> diff --git a/include/linux/mroute.h b/include/linux/mroute.h\n> index d7f6333..2f88e3d 100644\n> --- a/include/linux/mroute.h\n> +++ b/include/linux/mroute.h\n> @@ -138,6 +138,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\nThere's a struct comment above that has a short description for each entry,\nI know it seems redundant, but could you please add one for this ?\n\n>  \t\t} res;\n>  \t} mfc_un;\n>  \tstruct list_head list;\n> @@ -148,4 +149,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\n> diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c\n> index 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>","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 (1024-bit key;\n\tunprotected) header.d=cumulusnetworks.com\n\theader.i=@cumulusnetworks.com header.b=\"FomGyRX8\"; \n\tdkim-atps=neutral"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xyZpp0ND6z9s5L\n\tfor <patchwork-incoming@ozlabs.org>;\n\tThu, 21 Sep 2017 21:57:06 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1751782AbdIUL5D (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tThu, 21 Sep 2017 07:57:03 -0400","from mail-wm0-f54.google.com ([74.125.82.54]:44486 \"EHLO\n\tmail-wm0-f54.google.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1751387AbdIUL5C (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Thu, 21 Sep 2017 07:57:02 -0400","by mail-wm0-f54.google.com with SMTP id m127so529624wmm.1\n\tfor <netdev@vger.kernel.org>; Thu, 21 Sep 2017 04:57:02 -0700 (PDT)","from [192.168.0.103] (46-10-142-144.ip.btc-net.bg. [46.10.142.144])\n\tby smtp.googlemail.com with ESMTPSA id\n\tv80sm1011990wmv.37.2017.09.21.04.56.59\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tThu, 21 Sep 2017 04:57:00 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=cumulusnetworks.com; s=google;\n\th=subject:to:references:cc:from:message-id:date:user-agent\n\t:mime-version:in-reply-to:content-transfer-encoding;\n\tbh=/NNDs64OEkzMv7xJh/VRJkrlQ9Xdp7WurAu79HZCOBk=;\n\tb=FomGyRX8XC4hgpwd0pS01FYkIvGFX6cILiTxLCaadDW9Lnv4IqTnbPBPf3jVzU5F1s\n\tTgTf/SN0v5yu6+jEdMi1Vs57xn+kgwqJEGXyGsgD5Wvw/f2+khoG7QqDfRbvKmWZ0l3C\n\tMSYzRZyl5Wh6qBU2Xc5Uzw1kvp2Jbvs9GWCL0=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:subject:to:references:cc:from:message-id:date\n\t:user-agent:mime-version:in-reply-to:content-transfer-encoding;\n\tbh=/NNDs64OEkzMv7xJh/VRJkrlQ9Xdp7WurAu79HZCOBk=;\n\tb=cQkCBKFevGJpQactKqL7a4tQ9SzL7UCfR2HRDunXbB49qCFexcR3ZjBcdAvIDYW3eI\n\tdeqZjwXYWVMlmw0CDKrRZLvZKdTQbTcnm+VdiSB5j/vflLb9H8X2TyyT1qPgY8ITO7aV\n\ttgeTLLwxdbK4uZWDzJULmzjvTY6NCypCBogPayRtPaw/IUBxKqZ3PSyt5rOCThTJxrVj\n\tGQNsgDIguaphWgxqhsNFQVFCSJpCUxhYt7xkeYOMYaj9+u1ak9t+qT1SqBUEM3niPGTg\n\tfRyzAeP4XKcubjKcSz9F7/t3y0wMrlFEy1XXP0jPCzGMP1mEP+d1nr7LquywZEXJlXbv\n\tiQIQ==","X-Gm-Message-State":"AHPjjUjBwWZrH0HPbDJxu5L4BdA3K7ZXyVbmCpDN/P9k8oJ0z74gnoap\n\tC6Ide8MkE07uYUjobACeutXS7g==","X-Google-Smtp-Source":"AOwi7QAh27FOpDUWjJSNpMUL577JLvcjgCupVG19AnVghadDQXBr4YTJJHjkfNfem4vxe0AITa/EKg==","X-Received":"by 10.28.236.25 with SMTP id k25mr865317wmh.146.1505995021481;\n\tThu, 21 Sep 2017 04:57:01 -0700 (PDT)","Subject":"Re: [patch net-next 02/12] ipmr: Add reference count to MFC entries","To":"Jiri Pirko <jiri@resnulli.us>, netdev@vger.kernel.org","References":"<20170921064338.1282-1-jiri@resnulli.us>\n\t<20170921064338.1282-3-jiri@resnulli.us>","Cc":"davem@davemloft.net, yotamg@mellanox.com, idosch@mellanox.com,\n\tmlxsw@mellanox.com","From":"Nikolay Aleksandrov <nikolay@cumulusnetworks.com>","X-Enigmail-Draft-Status":"N1110","Message-ID":"<54cb367e-3769-ce9f-27dc-e08ee710bd98@cumulusnetworks.com>","Date":"Thu, 21 Sep 2017 14:56:59 +0300","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101\n\tIcedove/45.6.0","MIME-Version":"1.0","In-Reply-To":"<20170921064338.1282-3-jiri@resnulli.us>","Content-Type":"text/plain; charset=windows-1252","Content-Transfer-Encoding":"7bit","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"}}]