From: Jiri Pirko <jiri@resnulli.us>
To: Cong Wang <xiyou.wangcong@gmail.com>
Cc: netdev@vger.kernel.org, jakub.kicinski@netronome.com,
Jiri Pirko <jiri@mellanox.com>
Subject: Re: [Patch net] net_sched: fix a memory leak of filter chain
Date: Wed, 6 Sep 2017 09:38:39 +0200 [thread overview]
Message-ID: <20170906073839.GD2523@nanopsycho> (raw)
In-Reply-To: <20170906050310.26474-1-xiyou.wangcong@gmail.com>
Wed, Sep 06, 2017 at 07:03:10AM CEST, xiyou.wangcong@gmail.com wrote:
>tcf_chain_destroy() is called by tcf_block_put() and tcf_chain_put().
>tcf_chain_put() is refcn'ed and paired with tcf_chain_get(),
>but tcf_block_put() is not, it should be paired with tcf_block_get()
>and we still need to decrease the refcnt. However, tcf_block_put()
>is special, it stores the chains too, we have to detach them if
>it is not the last user.
You don't describe the original issue, or I am missing that from your
description.
>
>What's more, index 0 is not special at all, it should be treated
>like other chains. This also makes the code more readable.
[...]
>@@ -246,10 +246,7 @@ EXPORT_SYMBOL(tcf_chain_get);
>
> void tcf_chain_put(struct tcf_chain *chain)
> {
>- /* Destroy unused chain, with exception of chain 0, which is the
>- * default one and has to be always present.
>- */
>- if (--chain->refcnt == 0 && !chain->filter_chain && chain->index != 0)
>+ if (--chain->refcnt == 0)
The refcounting is only done for actions holding reference to the chain.
You still need to check is the filter chain is not empty.
See tc_ctl_tfilter.
Also, chain 0 is created by default on a block creation. It has to be
present always for a reason. Please see tcf_block_get. The pointer to
chain 0 is assigned to the qdisc filter list pointer.
> tcf_chain_destroy(chain);
> }
> EXPORT_SYMBOL(tcf_chain_put);
>@@ -296,8 +293,11 @@ void tcf_block_put(struct tcf_block *block)
>
> list_for_each_entry_safe(chain, tmp, &block->chain_list, list) {
> tcf_chain_flush(chain);
>- tcf_chain_destroy(chain);
>+ tcf_chain_put(chain);
> }
>+ /* If tc actions still hold the chain, just detach it. */
>+ list_for_each_entry_safe(chain, tmp, &block->chain_list, list)
>+ tcf_chain_detach(chain);
> kfree(block);
> }
> EXPORT_SYMBOL(tcf_block_put);
>--
>2.13.0
>
next prev parent reply other threads:[~2017-09-06 7:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-06 5:03 [Patch net] net_sched: fix a memory leak of filter chain Cong Wang
2017-09-06 7:38 ` Jiri Pirko [this message]
2017-09-06 17:25 ` Cong Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170906073839.GD2523@nanopsycho \
--to=jiri@resnulli.us \
--cc=jakub.kicinski@netronome.com \
--cc=jiri@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox