From patchwork Mon Oct 16 09:35:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jamal Hadi Salim X-Patchwork-Id: 13422840 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 E62C31CA97 for ; Mon, 16 Oct 2023 09:36:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mojatatu-com.20230601.gappssmtp.com header.i=@mojatatu-com.20230601.gappssmtp.com header.b="gSvOHUgB" Received: from mail-qv1-xf2b.google.com (mail-qv1-xf2b.google.com [IPv6:2607:f8b0:4864:20::f2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38195F0 for ; Mon, 16 Oct 2023 02:36:04 -0700 (PDT) Received: by mail-qv1-xf2b.google.com with SMTP id 6a1803df08f44-66d24ccc6f2so24795206d6.0 for ; Mon, 16 Oct 2023 02:36:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1697448963; x=1698053763; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=S1+zOFHNmfu3Lgi1rv9Jsao7L+8+OIYJ/zCOlMFLQbs=; b=gSvOHUgBr6whiI5XUQeiP6gWOqwTET8nbTO8I+JkHWVm7wBKtpjMlpWIdRnwaiIUwD 1GaUdIjFP/81u1/NcjWbrdekwa8bXgYI5CoKu+T/X7keOL5GD0UXyfy3hYkbyNbnLewp GbywiV2QkgCQ3nGgHjYUl9jEetbcfmyWKM8keaFal5PAyMpO8MOnQejNHyx9hVLDvJkE T3VMxT+K+Q7N2FHX1l1x6Q3tLRrQMB+uvH8uJmLiGmp13uObkGmY1rFBbu0pfQweHn5d QIzvmkldpI+R6+JulpUsM+96bXGGx+33ShSGzb09zrrZLksLpwtg3tdCjSY935wH7vo2 9EEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697448963; x=1698053763; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S1+zOFHNmfu3Lgi1rv9Jsao7L+8+OIYJ/zCOlMFLQbs=; b=B75dGYmKEN0xh9RsUWoF9FwCLWr6TTR1gpfJey3g9/yizVBbUe15hnApfYOZjEvgIq WHcMWmogjLaWo8xDDltb0R+Jyyyy5VHsvhakpdHJCyohU2tyoNUWtN0IZ0LE1wGMdKO/ 6Tm3jzvniOP21qgayJE8NrDyXmEJtRALvwcnjDGoB7ZalU0qgVzSw2ajYFrORynU77jl iq1ZIFmkfAiGiIoKNr2OfFw8Q8fzAycGkApGqdkOOPqdxG9CMpaGucIKKi13k6laFuZn sJUUUjcxtPRatgG1sj7CnkHsveyk4vFXgPPBpFzYc5qgs7rrDoMHYiMWHKT96YBC2er4 Q/3g== X-Gm-Message-State: AOJu0YxY/mdn6A29IJb05qL2UVNM+5yZqMOT1OePGFWqY2kZse+gheUK mOjkFK/59NAMfqW3LJ4yQmf0EIH3u+TisgGm7iU= X-Google-Smtp-Source: AGHT+IENrpKYlJDeoXjk23ZL/MvUM74XWQmyD147CVskatAUGm5NInhQRS0vRYnMfmKwBPPSiqlLHA== X-Received: by 2002:a05:6214:c83:b0:66d:66cf:e62f with SMTP id r3-20020a0562140c8300b0066d66cfe62fmr48543qvr.8.1697448962968; Mon, 16 Oct 2023 02:36:02 -0700 (PDT) Received: from majuu.waya ([174.91.6.24]) by smtp.gmail.com with ESMTPSA id g4-20020a0cf844000000b0065b1bcd0d33sm3292551qvo.93.2023.10.16.02.36.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 02:36:02 -0700 (PDT) From: Jamal Hadi Salim To: netdev@vger.kernel.org Cc: anjali.singhai@intel.com, namrata.limaye@intel.com, tom@sipanda.io, mleitner@redhat.com, Mahesh.Shirshyad@amd.com, tomasz.osinski@intel.com, jiri@resnulli.us, xiyou.wangcong@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, vladbu@nvidia.com, horms@kernel.org, khalidm@nvidia.com, toke@redhat.com, mattyk@nvidia.com Subject: [PATCH v7 net-next 03/18] net/sched: act_api: Update tc_action_ops to account for dynamic actions Date: Mon, 16 Oct 2023 05:35:34 -0400 Message-Id: <20231016093549.181952-4-jhs@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016093549.181952-1-jhs@mojatatu.com> References: <20231016093549.181952-1-jhs@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org The initialisation of P4TC action instances require access to a struct p4tc_act (which appears in later patches) to help us to retrieve information like the dynamic action parameters etc. In order to retrieve struct p4tc_act we need the pipeline name or id and the action name or id. Also recall that P4TC action IDs are dynamic and are net namespace specific. The init callback from tc_action_ops parameters had no way of supplying us that information. To solve this issue, we decided to create a new tc_action_ops callback (init_ops), that provies us with the tc_action_ops struct which then provides us with the pipeline and action name. In addition we add a new refcount to struct tc_action_ops called dyn_ref, which accounts for how many action instances we have of a specific action. Co-developed-by: Victor Nogueira Signed-off-by: Victor Nogueira Co-developed-by: Pedro Tammela Signed-off-by: Pedro Tammela Signed-off-by: Jamal Hadi Salim Reviewed-by: Vlad Buslov --- include/net/act_api.h | 6 ++++++ net/sched/act_api.c | 14 +++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/net/act_api.h b/include/net/act_api.h index b38a7029a..1fdf502a5 100644 --- a/include/net/act_api.h +++ b/include/net/act_api.h @@ -109,6 +109,7 @@ struct tc_action_ops { char kind[ACTNAMSIZ]; enum tca_id id; /* identifier should match kind */ unsigned int net_id; + refcount_t dyn_ref; size_t size; struct module *owner; int (*act)(struct sk_buff *, const struct tc_action *, @@ -120,6 +121,11 @@ struct tc_action_ops { struct nlattr *est, struct tc_action **act, struct tcf_proto *tp, u32 flags, struct netlink_ext_ack *extack); + /* This should be merged with the original init action */ + int (*init_ops)(struct net *net, struct nlattr *nla, + struct nlattr *est, struct tc_action **act, + struct tcf_proto *tp, struct tc_action_ops *ops, + u32 flags, struct netlink_ext_ack *extack); int (*walk)(struct net *, struct sk_buff *, struct netlink_callback *, int, const struct tc_action_ops *, diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 70c9eba62..f0ec70b42 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -1023,7 +1023,7 @@ int tcf_register_action(struct tc_action_ops *act, struct tc_action_ops *a; int ret; - if (!act->act || !act->dump || !act->init) + if (!act->act || !act->dump || (!act->init && !act->init_ops)) return -EINVAL; /* We have to register pernet ops before making the action ops visible, @@ -1484,8 +1484,16 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp, } } - err = a_o->init(net, tb[TCA_ACT_OPTIONS], est, &a, tp, - userflags.value | flags, extack); + /* When we arrive here we guarantee that a_o->init or + * a_o->init_ops exist. + */ + if (a_o->init) + err = a_o->init(net, tb[TCA_ACT_OPTIONS], est, &a, tp, + userflags.value | flags, extack); + else + err = a_o->init_ops(net, tb[TCA_ACT_OPTIONS], est, &a, + tp, a_o, userflags.value | flags, + extack); } else { err = a_o->init(net, nla, est, &a, tp, userflags.value | flags, extack);