From patchwork Mon Feb 25 01:58:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li RongQing X-Patchwork-Id: 1047556 X-Patchwork-Delegate: pablo@netfilter.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netfilter-devel-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=baidu.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 4474qg3YF6z9sB3 for ; Mon, 25 Feb 2019 12:58:55 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726511AbfBYB6y (ORCPT ); Sun, 24 Feb 2019 20:58:54 -0500 Received: from mx140-tc.baidu.com ([61.135.168.140]:42265 "EHLO tc-sys-mailedm02.tc.baidu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726168AbfBYB6y (ORCPT ); Sun, 24 Feb 2019 20:58:54 -0500 Received: from localhost (cp01-cos-dev01.cp01.baidu.com [10.92.119.46]) by tc-sys-mailedm02.tc.baidu.com (Postfix) with ESMTP id 755C211C005B for ; Mon, 25 Feb 2019 09:58:40 +0800 (CST) From: Li RongQing To: netfilter-devel@vger.kernel.org Subject: [PATCH] netfilter: force access of RCU protected data in nft_update_chain_stats Date: Mon, 25 Feb 2019 09:58:40 +0800 Message-Id: <1551059920-14120-1-git-send-email-lirongqing@baidu.com> X-Mailer: git-send-email 1.7.1 Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org 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 Signed-off-by: Li RongQing --- 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); + 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(); }