netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Li RongQing <lirongqing@baidu.com>, netfilter-devel@vger.kernel.org
Subject: Re: [PATCH] netfilter: force access of RCU protected data in nft_update_chain_stats
Date: Sun, 24 Feb 2019 19:50:08 -0800	[thread overview]
Message-ID: <4818220f-1c66-df00-e397-4efbeba82665@gmail.com> (raw)
In-Reply-To: <1551059920-14120-1-git-send-email-lirongqing@baidu.com>



On 02/24/2019 05:58 PM, Li RongQing wrote:
> basechain->stats is rcu protected data, cannot assure that
> twice accesses have the same result, so dereference it once.
> 
> basechain->stats is allocated by percpu allocater, if it is not NULL,
> its percpu variable does not need to be checked with NULL
> 
> Signed-off-by: Zhang Yu <zhangyu31@baidu.com>
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
>  net/netfilter/nf_tables_core.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/net/netfilter/nf_tables_core.c b/net/netfilter/nf_tables_core.c
> index 2a00aef7b6d4..9be622c76a62 100644
> --- a/net/netfilter/nf_tables_core.c
> +++ b/net/netfilter/nf_tables_core.c
> @@ -98,20 +98,20 @@ static noinline void nft_update_chain_stats(const struct nft_chain *chain,
>  					    const struct nft_pktinfo *pkt)
>  {
>  	struct nft_base_chain *base_chain;
> -	struct nft_stats *stats;
> +	struct nft_stats *stats, *pstat;
>  
>  	base_chain = nft_base_chain(chain);
> -	if (!rcu_access_pointer(base_chain->stats))
> +
> +	stats = rcu_dereference(base_chain->stats);

This looks bogus to me.

Where is the needed rcu_read_lock() before rcu_dereference() ?

This rcu_access_pointer() test is fine, and avoids a local_bh_disable()/local_bh_enable()
if they are not needed.


> +	if (!stats)
>  		return;
>  
>  	local_bh_disable();
> -	stats = this_cpu_ptr(rcu_dereference(base_chain->stats));
> -	if (stats) {
> -		u64_stats_update_begin(&stats->syncp);
> -		stats->pkts++;
> -		stats->bytes += pkt->skb->len;
> -		u64_stats_update_end(&stats->syncp);
> -	}
> +	pstat = this_cpu_ptr(stats);
> +	u64_stats_update_begin(&pstat->syncp);
> +	pstat->pkts++;
> +	pstat->bytes += pkt->skb->len;
> +	u64_stats_update_end(&pstat->syncp);
>  	local_bh_enable();
>  }
>  
> 



  reply	other threads:[~2019-02-25  3:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-25  1:58 [PATCH] netfilter: force access of RCU protected data in nft_update_chain_stats Li RongQing
2019-02-25  3:50 ` Eric Dumazet [this message]
2019-02-25  4:03   ` 答复: " Li,Rongqing
2019-02-25  4:10     ` Eric Dumazet
2019-02-25  6:00       ` 答复: " Li,Rongqing
2019-02-25 15:55         ` Eric Dumazet
2019-02-26  2:53           ` 答复: " Li,Rongqing
2019-02-26  3:16             ` Eric Dumazet

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=4818220f-1c66-df00-e397-4efbeba82665@gmail.com \
    --to=eric.dumazet@gmail.com \
    --cc=lirongqing@baidu.com \
    --cc=netfilter-devel@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).