Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3009611lqp; Mon, 25 Mar 2024 16:50:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXIlSLyrBoVOg721wvZBVcjO8AmWdqhlYY3ZwqLqetASBOrewQJe3i4RpTyvPmuOtEchPXtAeD50vaKutBc4wxQulGCy1CGXb5TiYXhlw== X-Google-Smtp-Source: AGHT+IHdc8nquau90ozSa/ZxPARF9aTZk0YAdv6sAVq6asu8/bwi9UX62JHEMLZdTe8ykM+B2TAH X-Received: by 2002:a05:6a20:d80b:b0:1a3:c2b8:f5d4 with SMTP id iv11-20020a056a20d80b00b001a3c2b8f5d4mr5922055pzb.17.1711410624269; Mon, 25 Mar 2024 16:50:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711410624; cv=pass; d=google.com; s=arc-20160816; b=bsL2FPXFSEN9ymV7LXmUULO3d/qiwyX7dHE8P6IpgXFxRYtevEIDOxsOD4Y0j9IUIk 1DYwXSrEUM7eZL9136++kVfAlPxj+iNJJmRBL4uFR/VIFbLsi32qWB/b+taz2YSrXU09 1GOnZDHVvHI2RRh8erKyf7C/sQAmwDV1hiQ8wT4H5dhT4CmZ2f34UX66qLeobwkptwv+ ZhfFro/z+T0V5f0JUpSWe1KELSPi4H/1whWHZi5eHccF3YPk3rPzaYGygEBC5xAADiik 2kaJUaqn9X8ziuPs8F/VagYQznS2Y4rjOxIR+Ow3QnCLRxEH4jAREOm9TbQsdQ3naEq9 gS3A== 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=sMuAvwkJCMPSV5MZ3/MuCnr+scxn9zMDDYBRe4tUid0=; fh=RSvj/pmCfJtwbi0orEkCSPZTV2N1NMPra5E6NwdRcTc=; b=I3KvolaFSj01LzkAw5oBVkwzPvleTzc0NXfxLtUA1OqDkz5oBUGdI2QONWkR8yCxjh t4uqArFm9310qQmoABpL3Yeo5PUHYipC6e+nz7sRfGWeL+Pfac1GL2zxFaMEHqf2IkSy pxi0HMpXyhN8IMssKhvzgTIG7U5usNDeZ6X/Ynxlpi2VziIgZGSg+Ib8HkYhxv2GvFLM TJ3hnWRjTQrKFXP5i1EfANxcsBbOcvmrcY2SHFkzoKSvo6FSCkM5gsnkTw0h+mnikVCW WEboVmGNLzoIdOhaIZJcznQ6J1E1snNlr6MphNPU/86ZYDIxHKYv7aa0JBU3AJWYvcI4 51KQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fiberby.net header.s=202008 header.b=CL+8RpkF; 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-117991-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117991-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fiberby.net Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id l2-20020a170902ec0200b001dc69aeefafsi5876473pld.517.2024.03.25.16.50.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 16:50:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117991-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@fiberby.net header.s=202008 header.b=CL+8RpkF; 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-117991-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117991-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id D192DB38092 for ; Mon, 25 Mar 2024 20:54:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DFDA56E617; Mon, 25 Mar 2024 20:54:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fiberby.net header.i=@fiberby.net header.b="CL+8RpkF" 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 DB9AA5C613; Mon, 25 Mar 2024 20:54:06 +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=1711400050; cv=none; b=A3uatDzxX1FAf6r2I6Pgx2z7PGzBef8dZHVm7FpyEXUl+vmjcmFAsMhZDWTDX5GvSAQ4WMYVF39x1czx425mSeh3Pt9d5ZWYiY8yqsY4dPk/tO6FpHT9NeiH5gyhBGB8TAzuq2Z5WSaQNdLSt3kJCvXMkj/aGwPw0n31EXWOySo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711400050; c=relaxed/simple; bh=UsuadOPE5XUQNgscef/NyQQnyL0c3yDFZvzX9R4Pwe8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=o3XjHF669geeudnvbuALWxkvIzzuQu3e735BEGHpfQ7KnbeL4TRcnOqMh7ZIVkehSzAxxxTuvm5h5THZkY9swWuFrPoLDwhhPktgiwt5Zqf3uCmdi2L/8vtS/k7AlaDnvzuYrMXuplakK+bs6n4ZXBC1ZaD78WhCwsRGPDxH0lY= 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=CL+8RpkF; 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 5C71D6030A; Mon, 25 Mar 2024 20:48:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1711399726; bh=UsuadOPE5XUQNgscef/NyQQnyL0c3yDFZvzX9R4Pwe8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CL+8RpkFaNKXpH6sJVL24f37GOWJ5scHuI+tTnaxOOoWQZrF42pm8EzjKbt4LAuzW iH3mVd3X+lPa/P/qt1K0TK32q9OMzxX7A6MFXR9nX5Q+042UswnNLwcbFgDursA8L8 Jp6il8ivBKqZ8r9G8G66Y+H0IhpeRZVQNvWo+uw269/04YqCU6iGo4bFc6u0ptNYFd 2kadXIv3B9x3n5iL11H47jfpzrt0hzC34uFDDAGjDBfN6T0WNDt59tuKrBANeNA/xe WV8FsEDVHWLe7kpYWwAvDxL/DYWaWE1AbsAbv24327Gmc0rFyEIIMvbBqn4ep7ljYL 7sPgy1gTwKHLg== Received: by x201s (Postfix, from userid 1000) id C7CB8204BA9; Mon, 25 Mar 2024 20:47:51 +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 , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Vlad Buslov , Marcelo Ricardo Leitner , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, llu@fiberby.dk Subject: [PATCH net-next v4 2/3] net: sched: cls_api: add filter counter Date: Mon, 25 Mar 2024 20:47:35 +0000 Message-ID: <20240325204740.1393349-3-ast@fiberby.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325204740.1393349-1-ast@fiberby.net> References: <20240325204740.1393349-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 120a4ca6ec9b..eb3872c22fcd 100644 --- a/include/net/sch_generic.h +++ b/include/net/sch_generic.h @@ -422,6 +422,7 @@ struct tcf_proto { */ spinlock_t lock; bool deleting; + bool counted; refcount_t refcnt; struct rcu_head rcu; struct hlist_node destroy_ht_node; @@ -471,6 +472,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