Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp19882lqi; Wed, 6 Mar 2024 08:59:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXfLPF6xaKO4oL6xBzt6tNH1zpyqR80gCw0CuUUVvyk0kg33Ff6jyofwrQm6u56Mo6pLQpq4zNeIzxOfn6w7Cya/3wHfPhuuKBYqiXxMA== X-Google-Smtp-Source: AGHT+IFBl1AOyhZpAals5L1s1q8BjvxBFTFuyFJjD1t8zXulHHEbRgPcxX9qFrDlRP2ijx9vlorH X-Received: by 2002:a17:902:a9ca:b0:1dc:cc64:b3e0 with SMTP id b10-20020a170902a9ca00b001dccc64b3e0mr5083067plr.69.1709744387768; Wed, 06 Mar 2024 08:59:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709744387; cv=pass; d=google.com; s=arc-20160816; b=BMXH0t8SHqR0wOXBnKfrKJADvazyy4q+OuWJmBvciGu9JFO/eYH+vqBv38dup3u5IQ pg4WUoYRRfDsX1v2fE8Asq06GvTx7POT7K8mMHEdTb19lm3OXxfNVpeCI4hpKf2mHFGF E1YjNHGSE1x4sxxIKyz5N9zgtK1fQvm4e5aZL1s/Bq0mp9sDrZbdHcLxD1NxtOdkDYpC ZzuFgk+/IEaJ5vDNOy+7QeCfify7LJlP8jDLgSfJPn4L69qLwD40wqIvSKanRrbnyAC1 e6Wlbn7gRPIweWQdG/bMCOhSz18/vp3RvT/Tk+9zV2K1tXP6/Yxn0SgjDHm/Wy/uKnXc TgYQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Q8ErYe8I/GS4KBnAGiq9LTVyLF8AzPbUxZVT3/Bxya0=; fh=H/GM0QF78Qx6X9IR7gHM7NBaq2mJ7ByoMQ4LB8ra6lM=; b=iRskAyHzBnTFBayHsrvkjRJY0dph4d2Kiy23IKilOWixXKFBbUNii9MhfTRCiyCMbm I74b/7f7gu1nxiEuQBfxB59l2oGNKY8IYe/IWX+AVS/aDBUH5HIZGBG+wfqasQuS3VDR H5euK5kL6rc5bjFWSYn7l0mh9fizfbX0YT50fFNEbW0582Jn/VMjcZKAnSbps26XX8ZR +SnU6J+Cq4A+F5y2twxRMSS+SDlO0XpzMB8NuvaEK+M93bkmFYrURig+rRHxS68ieD/d kCWnzdpQZaSWTtCb4/apDXm6akKYSbs0XNNuVe/uLplVYnzc7W2xBgeNZwE8IuK/2Vfo YQ9g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fiberby.net header.s=202008 header.b=h9Vju3EQ; arc=pass (i=1 spf=pass spfdomain=fiberby.net dkim=pass dkdomain=fiberby.net dmarc=pass fromdomain=fiberby.net); spf=pass (google.com: domain of linux-kernel+bounces-94303-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94303-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fiberby.net Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id n5-20020a170903110500b001dd151bfaa6si5512718plh.617.2024.03.06.08.59.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 08:59:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94303-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@fiberby.net header.s=202008 header.b=h9Vju3EQ; arc=pass (i=1 spf=pass spfdomain=fiberby.net dkim=pass dkdomain=fiberby.net dmarc=pass fromdomain=fiberby.net); spf=pass (google.com: domain of linux-kernel+bounces-94303-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94303-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fiberby.net Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 740BE2866FF for ; Wed, 6 Mar 2024 16:59:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9193B13DB8C; Wed, 6 Mar 2024 16:59:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b="h9Vju3EQ" Received: from mail1.fiberby.net (mail1.fiberby.net [193.104.135.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EC2B13B7BD; Wed, 6 Mar 2024 16:58:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.104.135.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709744340; cv=none; b=RMGI7XqhA2nKcflWEM/JLTtssV6KePvcBcqzU7eMunQGd+9UCQ4R0M61+02Gnq0d1Mz4MxiLkkgzmeuKJ6qi2bRvTlmPfsmK9DxHW+seSTFcnBhdWskV1JZTMoESxxo3VDR6TpLq4VX5R+IulwwhhbHK55e8p92Io76ffp7sprg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709744340; c=relaxed/simple; bh=pULFdc99bT3kGEpnmoQAhimYHSPZ/ND5NNhVMP7CCsw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=K6EAyTNSdVFMbHGe8VX69/FL8aOdeHvAokQJ0GvY4LJq8J2yeTSJmlKrCqXhlxnZUrRLI8YqVfdae6ATxfHQD1/uCXEOW7Z7WJIbK6WUxXEpHeQ7hnG/S2ywiVR7koFqxtlciSCt61P5NzebOpeJK0Az/fmH8+Gde5GNYLFKy7w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net; spf=pass smtp.mailfrom=fiberby.net; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b=h9Vju3EQ; arc=none smtp.client-ip=193.104.135.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fiberby.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fiberby.net Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 3A0496030D; Wed, 6 Mar 2024 16:58:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1709744330; bh=pULFdc99bT3kGEpnmoQAhimYHSPZ/ND5NNhVMP7CCsw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h9Vju3EQfOt6JdPYLHlJJ3quowNMNibzAbJvtjjidydjEeajM06yFf26QThTbmuM7 k+eFkrKxae03FnTzCE/ahfF8hj4yZOq0fiLIW8ycDUc7Fjlh+aWWsjZ7bnQ2353Xx7 tdPIFZP8Um0lGyD/QzBSqzUCGuZa7x6/Kt+IAIahEPgHE+GQL3QhDzXvpBH0kEr2EJ ANHf75Qd0j+hdd0ScFu8QBmIbth3OurMifQDFUbOeU6WczkLMRugfpNOwr1sPtACdf DJ3ImdEW07vF8KF67b9rCywnKtVsruFWXwJNG/1LRV4POi4MoyLiGUTVruhEwmU3T5 2xBzAaLL6jmeQ== Received: by x201s (Postfix, from userid 1000) id ACF7B20376D; Wed, 6 Mar 2024 16:58:26 +0000 (UTC) From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= To: Jamal Hadi Salim , Cong Wang , Jiri Pirko Cc: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= , Daniel Borkmann , Vlad Buslov , Marcelo Ricardo Leitner , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, llu@fiberby.dk Subject: [PATCH net-next v3 2/3] net: sched: cls_api: add filter counter Date: Wed, 6 Mar 2024 16:58:10 +0000 Message-ID: <20240306165813.656931-3-ast@fiberby.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306165813.656931-1-ast@fiberby.net> References: <20240306165813.656931-1-ast@fiberby.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Maintain a count of filters per block. Counter updates are protected by cb_lock, which is also used to protect the offload counters. Signed-off-by: Asbjørn Sloth Tønnesen --- include/net/sch_generic.h | 2 ++ net/sched/cls_api.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h index 46a63d1818a0..7af0621db226 100644 --- a/include/net/sch_generic.h +++ b/include/net/sch_generic.h @@ -427,6 +427,7 @@ struct tcf_proto { */ spinlock_t lock; bool deleting; + bool counted; refcount_t refcnt; struct rcu_head rcu; struct hlist_node destroy_ht_node; @@ -476,6 +477,7 @@ struct tcf_block { struct flow_block flow_block; struct list_head owner_list; bool keep_dst; + atomic_t filtercnt; /* Number of filters */ atomic_t skipswcnt; /* Number of skip_sw filters */ atomic_t offloadcnt; /* Number of oddloaded filters */ unsigned int nooffloaddevcnt; /* Number of devs unable to do offload */ diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index 397c3d29659c..304a46ab0e0b 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c @@ -410,12 +410,30 @@ static void tcf_proto_get(struct tcf_proto *tp) refcount_inc(&tp->refcnt); } +static void tcf_block_filter_cnt_update(struct tcf_block *block, bool *counted, bool add) +{ + lockdep_assert_not_held(&block->cb_lock); + + down_write(&block->cb_lock); + if (*counted != add) { + if (add) { + atomic_inc(&block->filtercnt); + *counted = true; + } else { + atomic_dec(&block->filtercnt); + *counted = false; + } + } + up_write(&block->cb_lock); +} + static void tcf_chain_put(struct tcf_chain *chain); static void tcf_proto_destroy(struct tcf_proto *tp, bool rtnl_held, bool sig_destroy, struct netlink_ext_ack *extack) { tp->ops->destroy(tp, rtnl_held, extack); + tcf_block_filter_cnt_update(tp->chain->block, &tp->counted, false); if (sig_destroy) tcf_proto_signal_destroyed(tp->chain, tp); tcf_chain_put(tp->chain); @@ -2364,6 +2382,7 @@ static int tc_new_tfilter(struct sk_buff *skb, struct nlmsghdr *n, err = tp->ops->change(net, skb, tp, cl, t->tcm_handle, tca, &fh, flags, extack); if (err == 0) { + tcf_block_filter_cnt_update(block, &tp->counted, true); tfilter_notify(net, skb, n, tp, block, q, parent, fh, RTM_NEWTFILTER, false, rtnl_held, extack); tfilter_put(tp, fh); -- 2.43.0