From patchwork Tue Aug 4 05:09:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 503332 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id DEB3B140307 for ; Tue, 4 Aug 2015 15:09:38 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751667AbbHDFJV (ORCPT ); Tue, 4 Aug 2015 01:09:21 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:36834 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750956AbbHDFJU (ORCPT ); Tue, 4 Aug 2015 01:09:20 -0400 Received: by pacgq8 with SMTP id gq8so41511491pac.3 for ; Mon, 03 Aug 2015 22:09:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=HcPtsANkxsNuj+x8ZtIssFuMGiBERGJLON1jvJhI/sY=; b=hGkLiGWyQ0YDwUa1G3dB6y5XHBCsvZeUYsU95SasoIuNt5uGFtXOVNurBvjSauHm9W DBjqxI4E0cU7pf6NdTXR3u2h866EhUX0vBQdYcD0DTn2vvJyKKQuatoRetyy3lXXcdJT KNwiU6amad9kmsQiTh6B6tFOrcXEv0bFvZSG0fqBY032vePoSaNCalO40ATR/kSloUVP rxOHsqY9IfHmD+4lwcg/yKk/hJ/gva242n1J78+KncRM4yCq6pDU5eAAxPQ7SqY6PW/i smP6HomV6Nsil4qvvIEsY+jS9JVd0nTgepR5oKtHz+WQFjFmU0iQdzjqstUweoSbOg3R lOPQ== X-Gm-Message-State: ALoCoQm9RZG8/pySjSSHbljlSqFKzwO/UJnLnm7kRKqwRm0Ws2Ads8/DAdnPxAx/JwHhPkqc7EYh X-Received: by 10.69.2.69 with SMTP id bm5mr3745576pbd.41.1438664959556; Mon, 03 Aug 2015 22:09:19 -0700 (PDT) Received: from localhost.localdomain ([12.97.19.195]) by smtp.gmail.com with ESMTPSA id b4sm19312746pdn.42.2015.08.03.22.09.18 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Aug 2015 22:09:19 -0700 (PDT) From: Alexei Starovoitov To: "David S. Miller" Cc: Eric Dumazet , Daniel Borkmann , Jiri Pirko , netdev@vger.kernel.org Subject: [PATCH net-next] net_sched: act_bpf: remove spinlock in fast path Date: Mon, 3 Aug 2015 22:09:12 -0700 Message-Id: <1438664952-24712-1-git-send-email-ast@plumgrid.com> X-Mailer: git-send-email 1.7.9.5 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Similar to act_gact/act_mirred, act_bpf can be lockless in packet processing. Also similar to gact/mirred there is a race between prog->filter and prog->tcf_action. Meaning that the program being replaced may use previous default action if it happened to return TC_ACT_UNSPEC. act_mirred race betwen tcf_action and tcfm_dev is similar. In all cases the race is harmless. Long term we may want to improve the situation by replacing the whole struct tc_action as single pointer instead of updating inner fields one by one. Signed-off-by: Alexei Starovoitov --- net/sched/act_bpf.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/net/sched/act_bpf.c b/net/sched/act_bpf.c index 1b97dabc621a..2b8c47200152 100644 --- a/net/sched/act_bpf.c +++ b/net/sched/act_bpf.c @@ -43,10 +43,8 @@ static int tcf_bpf(struct sk_buff *skb, const struct tc_action *act, if (unlikely(!skb_mac_header_was_set(skb))) return TC_ACT_UNSPEC; - spin_lock(&prog->tcf_lock); - - prog->tcf_tm.lastuse = jiffies; - bstats_update(&prog->tcf_bstats, skb); + tcf_lastuse_update(&prog->tcf_tm); + bstats_cpu_update(this_cpu_ptr(prog->common.cpu_bstats), skb); /* Needed here for accessing maps. */ rcu_read_lock(); @@ -77,7 +75,7 @@ static int tcf_bpf(struct sk_buff *skb, const struct tc_action *act, break; case TC_ACT_SHOT: action = filter_res; - prog->tcf_qstats.drops++; + qstats_drop_inc(this_cpu_ptr(prog->common.cpu_qstats)); break; case TC_ACT_UNSPEC: action = prog->tcf_action; @@ -87,7 +85,6 @@ static int tcf_bpf(struct sk_buff *skb, const struct tc_action *act, break; } - spin_unlock(&prog->tcf_lock); return action; } @@ -294,7 +291,7 @@ static int tcf_bpf_init(struct net *net, struct nlattr *nla, if (!tcf_hash_check(parm->index, act, bind)) { ret = tcf_hash_create(parm->index, est, act, - sizeof(*prog), bind, false); + sizeof(*prog), bind, true); if (ret < 0) return ret; @@ -325,7 +322,7 @@ static int tcf_bpf_init(struct net *net, struct nlattr *nla, goto out; prog = to_bpf(act); - spin_lock_bh(&prog->tcf_lock); + ASSERT_RTNL(); if (ret != ACT_P_CREATED) tcf_bpf_prog_fill_cfg(prog, &old); @@ -341,8 +338,6 @@ static int tcf_bpf_init(struct net *net, struct nlattr *nla, prog->tcf_action = parm->action; prog->filter = cfg.filter; - spin_unlock_bh(&prog->tcf_lock); - if (res == ACT_P_CREATED) tcf_hash_insert(act); else