From patchwork Fri Feb 23 13:17:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jamal Hadi Salim X-Patchwork-Id: 13569072 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C54A7E581 for ; Fri, 23 Feb 2024 13:17:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708694263; cv=none; b=n6dKzF7dVIE0w9GYLJEyC2j1+E6Fc5MyA901sFjD5AUvSC1OCCg1gWU5YGZk5rZFDQ25udghNDAHsXaacBUzYFCvb+XRs2QRFq5bnT6alS1grWoC2UeF9wdcFZhZsO8bm51y+/ZYPXpaJGAwEqd9n3ifxIFY9K2mLrCUU8iVJYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708694263; c=relaxed/simple; bh=DuN16/GHtiXicqQjZnAyJxVvt/HpXSnC+FHTG0u57aI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=thB9n1UbCZGGKE/lLUaN4nVn+tKk4eZrmsxYxLhqelebtGibxoOW/XaIQf6y1NWnhemIrA5xwKp/LAPT8yPJnecHNWKZvuwKMiNd6ytdS1AH+mx8wkRpMGXRX0XEFQCW5bxlrVsTh1LBgzbyAy0O/StO2N/fnfdTWQEAmcB3EsY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mojatatu.com; spf=none smtp.mailfrom=mojatatu.com; dkim=pass (2048-bit key) header.d=mojatatu-com.20230601.gappssmtp.com header.i=@mojatatu-com.20230601.gappssmtp.com header.b=NROovgdO; arc=none smtp.client-ip=209.85.222.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mojatatu.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=mojatatu.com 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="NROovgdO" Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-787bb0d85eeso6010985a.0 for ; Fri, 23 Feb 2024 05:17:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1708694260; x=1709299060; 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=NAHOQV4oPNy02lcG5z08rhQUzQ6DMeoFljHIxr5JlHM=; b=NROovgdOZOuKosdTiNHRoWBcFL721O2DUDRSbFkSbO+txfa2wz7WAlceWd/TIEX2Af xQjIXvGvDF67k8HWEO0E9/0EM9D6zUrNq0R28tOvDOVVLrw2FBH8tZaRhO8rP7gsLduo j7VpOwDIzB5Kym7FRArjAMqQ1TzmwoPS7Fy/jCjU3IJ7caJNqpI57hUI08u3xf6JtsM9 EahHXdddxVD7yfNxzDo4bgrqNT0d1LEBhPZCUQh27tgzPL7krcLUX/eMM5sseOq/7Xor sP4DMsKfx99fLt4+QDJm6tWV15fnYGoMRUbiZTPxn3RxlL+aLq3lh32umPtQ9Hcx1T1w yOcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708694260; x=1709299060; 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=NAHOQV4oPNy02lcG5z08rhQUzQ6DMeoFljHIxr5JlHM=; b=G13qvaz25B95KeIDqSPFdLH8TxErPRYLlW9lye/ImUS+GDb8YZ8U9zXsSSShKTbDDt MfH5jQF6iaePrwhQ6dO02gDpK2pOl74llKVAy90pmNRJkJ6+eUGsCg1+Zp2Y57MDDLQQ njG/WaEG8luM4rhAqoJxRjBJil0KuLoJoitUdCrHwasOHOESTrOtbF9dmtbQa6LBBQ94 muap0Xg8GzlkRVYSAI8hBQUiUdpJGwG4MTbLc0m6omsz3jeQEWqkOHFAFt6n7lUo+AKy Wyx0pywWn90MnXVcGFR+AeBFE51qFPhafuY5n8SkFz2wLCsD1/Glg3PFUmsIDMHHFBUt Rq3w== X-Forwarded-Encrypted: i=1; AJvYcCVTIuKvUIVLIGv6XCoLs7ZIbAK/2pRb4+8qi41DKFZoxOpgZ3Vn5xWq2lGbZM2rL8lnE5FimqP9ojujpk9W4gBaHaxn X-Gm-Message-State: AOJu0YwxOVF+JTtxoLzLkpmB0yCN+V1O6cUytT0nHAU8OZi5qyUbX/IT mud3mZn4a2LdTdydr5SbVckyS8R6pU7B+Z3gurscG4hcvcRaHcolEtVJaBHtvg== X-Google-Smtp-Source: AGHT+IGQeZC37HePou7qZuHot10nlvPbQu3mgsTSUdaqqj8hbuYqrU3C4+j2zmCSq1RMAwm44AXDEg== X-Received: by 2002:a05:620a:3711:b0:783:d369:6e5a with SMTP id de17-20020a05620a371100b00783d3696e5amr2683529qkb.76.1708694260010; Fri, 23 Feb 2024 05:17:40 -0800 (PST) Received: from majuu.waya ([174.94.28.98]) by smtp.gmail.com with ESMTPSA id f3-20020a05620a15a300b00787ae919d02sm844869qkk.17.2024.02.23.05.17.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 05:17:39 -0800 (PST) From: Jamal Hadi Salim To: netdev@vger.kernel.org Cc: deb.chatterjee@intel.com, anjali.singhai@intel.com, namrata.limaye@intel.com, tom@sipanda.io, mleitner@redhat.com, Mahesh.Shirshyad@amd.com, Vipin.Jain@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, daniel@iogearbox.net, bpf@vger.kernel.org, pctammela@mojatatu.com, victor@mojatatu.com Subject: [PATCH net-next v11 1/5] net: sched: act_api: Introduce P4 actions list Date: Fri, 23 Feb 2024 08:17:24 -0500 Message-Id: <20240223131728.116717-2-jhs@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223131728.116717-1-jhs@mojatatu.com> References: <20240223131728.116717-1-jhs@mojatatu.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org In P4 we require to generate new actions "on the fly" based on the specified P4 action definition. P4 action kinds, like the pipeline they are attached to, must be per net namespace, as opposed to native action kinds which are global. For that reason, we chose to create a separate structure to store P4 actions. 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 Reviewed-by: Marcelo Ricardo Leitner --- include/net/act_api.h | 8 ++- net/sched/act_api.c | 123 +++++++++++++++++++++++++++++++++++++----- net/sched/cls_api.c | 2 +- 3 files changed, 116 insertions(+), 17 deletions(-) diff --git a/include/net/act_api.h b/include/net/act_api.h index 77ee0c657..f22be14bb 100644 --- a/include/net/act_api.h +++ b/include/net/act_api.h @@ -105,6 +105,7 @@ typedef void (*tc_action_priv_destructor)(void *priv); struct tc_action_ops { struct list_head head; + struct list_head p4_head; char kind[IFNAMSIZ]; enum tca_id id; /* identifier should match kind */ unsigned int net_id; @@ -199,10 +200,12 @@ int tcf_idr_check_alloc(struct tc_action_net *tn, u32 *index, int tcf_idr_release(struct tc_action *a, bool bind); int tcf_register_action(struct tc_action_ops *a, struct pernet_operations *ops); +int tcf_register_p4_action(struct net *net, struct tc_action_ops *act); int tcf_unregister_action(struct tc_action_ops *a, struct pernet_operations *ops); #define NET_ACT_ALIAS_PREFIX "net-act-" #define MODULE_ALIAS_NET_ACT(kind) MODULE_ALIAS(NET_ACT_ALIAS_PREFIX kind) +void tcf_unregister_p4_action(struct net *net, struct tc_action_ops *act); int tcf_action_destroy(struct tc_action *actions[], int bind); int tcf_action_exec(struct sk_buff *skb, struct tc_action **actions, int nr_actions, struct tcf_result *res); @@ -210,8 +213,9 @@ int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla, struct nlattr *est, struct tc_action *actions[], int init_res[], size_t *attr_size, u32 flags, u32 fl_flags, struct netlink_ext_ack *extack); -struct tc_action_ops *tc_action_load_ops(struct nlattr *nla, u32 flags, - struct netlink_ext_ack *extack); +struct tc_action_ops * +tc_action_load_ops(struct net *net, struct nlattr *nla, + u32 flags, struct netlink_ext_ack *extack); struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp, struct nlattr *nla, struct nlattr *est, struct tc_action_ops *a_o, int *init_res, diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 9ee622fb1..23ef394f2 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -57,6 +57,40 @@ static void tcf_free_cookie_rcu(struct rcu_head *p) kfree(cookie); } +static unsigned int p4_act_net_id; + +struct tcf_p4_act_net { + struct list_head act_base; + rwlock_t act_mod_lock; +}; + +static __net_init int tcf_p4_act_base_init_net(struct net *net) +{ + struct tcf_p4_act_net *p4_base_net = net_generic(net, p4_act_net_id); + + INIT_LIST_HEAD(&p4_base_net->act_base); + rwlock_init(&p4_base_net->act_mod_lock); + + return 0; +} + +static void __net_exit tcf_p4_act_base_exit_net(struct net *net) +{ + struct tcf_p4_act_net *p4_base_net = net_generic(net, p4_act_net_id); + struct tc_action_ops *ops, *tmp; + + list_for_each_entry_safe(ops, tmp, &p4_base_net->act_base, p4_head) { + list_del(&ops->p4_head); + } +} + +static struct pernet_operations tcf_p4_act_base_net_ops = { + .init = tcf_p4_act_base_init_net, + .exit = tcf_p4_act_base_exit_net, + .id = &p4_act_net_id, + .size = sizeof(struct tc_action_ops), +}; + static void tcf_set_action_cookie(struct tc_cookie __rcu **old_cookie, struct tc_cookie *new_cookie) { @@ -962,6 +996,48 @@ static void tcf_pernet_del_id_list(unsigned int id) mutex_unlock(&act_id_mutex); } +static struct tc_action_ops *tc_lookup_p4_action(struct net *net, char *kind) +{ + struct tcf_p4_act_net *p4_base_net = net_generic(net, p4_act_net_id); + struct tc_action_ops *a, *res = NULL; + + read_lock(&p4_base_net->act_mod_lock); + list_for_each_entry(a, &p4_base_net->act_base, p4_head) { + if (strcmp(kind, a->kind) == 0) { + if (try_module_get(a->owner)) + res = a; + break; + } + } + read_unlock(&p4_base_net->act_mod_lock); + + return res; +} + +void tcf_unregister_p4_action(struct net *net, struct tc_action_ops *act) +{ + struct tcf_p4_act_net *p4_base_net = net_generic(net, p4_act_net_id); + + write_lock(&p4_base_net->act_mod_lock); + list_del(&act->p4_head); + write_unlock(&p4_base_net->act_mod_lock); +} +EXPORT_SYMBOL(tcf_unregister_p4_action); + +int tcf_register_p4_action(struct net *net, struct tc_action_ops *act) +{ + struct tcf_p4_act_net *p4_base_net = net_generic(net, p4_act_net_id); + + if (tc_lookup_p4_action(net, act->kind)) + return -EEXIST; + + write_lock(&p4_base_net->act_mod_lock); + list_add(&act->p4_head, &p4_base_net->act_base); + write_unlock(&p4_base_net->act_mod_lock); + + return 0; +} + int tcf_register_action(struct tc_action_ops *act, struct pernet_operations *ops) { @@ -1032,7 +1108,7 @@ int tcf_unregister_action(struct tc_action_ops *act, EXPORT_SYMBOL(tcf_unregister_action); /* lookup by name */ -static struct tc_action_ops *tc_lookup_action_n(char *kind) +static struct tc_action_ops *tc_lookup_action_n(struct net *net, char *kind) { struct tc_action_ops *a, *res = NULL; @@ -1040,31 +1116,48 @@ static struct tc_action_ops *tc_lookup_action_n(char *kind) read_lock(&act_mod_lock); list_for_each_entry(a, &act_base, head) { if (strcmp(kind, a->kind) == 0) { - if (try_module_get(a->owner)) - res = a; - break; + if (try_module_get(a->owner)) { + read_unlock(&act_mod_lock); + return a; + } } } read_unlock(&act_mod_lock); + + return tc_lookup_p4_action(net, kind); } + return res; } /* lookup by nlattr */ -static struct tc_action_ops *tc_lookup_action(struct nlattr *kind) +static struct tc_action_ops *tc_lookup_action(struct net *net, + struct nlattr *kind) { + struct tcf_p4_act_net *p4_base_net = net_generic(net, p4_act_net_id); struct tc_action_ops *a, *res = NULL; if (kind) { read_lock(&act_mod_lock); list_for_each_entry(a, &act_base, head) { + if (nla_strcmp(kind, a->kind) == 0) { + if (try_module_get(a->owner)) { + read_unlock(&act_mod_lock); + return a; + } + } + } + read_unlock(&act_mod_lock); + + read_lock(&p4_base_net->act_mod_lock); + list_for_each_entry(a, &p4_base_net->act_base, p4_head) { if (nla_strcmp(kind, a->kind) == 0) { if (try_module_get(a->owner)) res = a; break; } } - read_unlock(&act_mod_lock); + read_unlock(&p4_base_net->act_mod_lock); } return res; } @@ -1324,8 +1417,9 @@ void tcf_idr_insert_many(struct tc_action *actions[], int init_res[]) } } -struct tc_action_ops *tc_action_load_ops(struct nlattr *nla, u32 flags, - struct netlink_ext_ack *extack) +struct tc_action_ops * +tc_action_load_ops(struct net *net, struct nlattr *nla, + u32 flags, struct netlink_ext_ack *extack) { bool police = flags & TCA_ACT_FLAGS_POLICE; struct nlattr *tb[TCA_ACT_MAX + 1]; @@ -1356,7 +1450,7 @@ struct tc_action_ops *tc_action_load_ops(struct nlattr *nla, u32 flags, } } - a_o = tc_lookup_action_n(act_name); + a_o = tc_lookup_action_n(net, act_name); if (a_o == NULL) { #ifdef CONFIG_MODULES bool rtnl_held = !(flags & TCA_ACT_FLAGS_NO_RTNL); @@ -1367,7 +1461,7 @@ struct tc_action_ops *tc_action_load_ops(struct nlattr *nla, u32 flags, if (rtnl_held) rtnl_lock(); - a_o = tc_lookup_action_n(act_name); + a_o = tc_lookup_action_n(net, act_name); /* We dropped the RTNL semaphore in order to * perform the module load. So, even if we @@ -1477,7 +1571,7 @@ int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla, for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) { struct tc_action_ops *a_o; - a_o = tc_action_load_ops(tb[i], flags, extack); + a_o = tc_action_load_ops(net, tb[i], flags, extack); if (IS_ERR(a_o)) { err = PTR_ERR(a_o); goto err_mod; @@ -1683,7 +1777,7 @@ static struct tc_action *tcf_action_get_1(struct net *net, struct nlattr *nla, index = nla_get_u32(tb[TCA_ACT_INDEX]); err = -EINVAL; - ops = tc_lookup_action(tb[TCA_ACT_KIND]); + ops = tc_lookup_action(net, tb[TCA_ACT_KIND]); if (!ops) { /* could happen in batch of actions */ NL_SET_ERR_MSG(extack, "Specified TC action kind not found"); goto err_out; @@ -1731,7 +1825,7 @@ static int tca_action_flush(struct net *net, struct nlattr *nla, err = -EINVAL; kind = tb[TCA_ACT_KIND]; - ops = tc_lookup_action(kind); + ops = tc_lookup_action(net, kind); if (!ops) { /*some idjot trying to flush unknown action */ NL_SET_ERR_MSG(extack, "Cannot flush unknown TC action"); goto err_out; @@ -2184,7 +2278,7 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb) return 0; } - a_o = tc_lookup_action(kind); + a_o = tc_lookup_action(net, kind); if (a_o == NULL) return 0; @@ -2251,6 +2345,7 @@ static int __init tc_action_init(void) rtnl_register(PF_UNSPEC, RTM_GETACTION, tc_ctl_action, tc_dump_action, 0); + register_pernet_subsys(&tcf_p4_act_base_net_ops); return 0; } diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index ca5676b26..142f49a2c 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c @@ -3330,7 +3330,7 @@ int tcf_exts_validate_ex(struct net *net, struct tcf_proto *tp, struct nlattr ** struct tc_action_ops *a_o; flags |= TCA_ACT_FLAGS_POLICE | TCA_ACT_FLAGS_BIND; - a_o = tc_action_load_ops(tb[exts->police], flags, + a_o = tc_action_load_ops(net, tb[exts->police], flags, extack); if (IS_ERR(a_o)) return PTR_ERR(a_o); From patchwork Fri Feb 23 13:17:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jamal Hadi Salim X-Patchwork-Id: 13569073 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D6407E786 for ; Fri, 23 Feb 2024 13:17:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708694264; cv=none; b=ebagAYaXGhQue9A1CPzBw8OunWJSQ/GdyKrbU2axRX1nMheo/OJhidnmJrIrsMhlCp1EG9R1HHUF6J1NxYl3/sCPAOTIooVsP2epD3KuVqpoKlow5GCpV6RC/5Zoq/ArtuABxegEIR6GpqhHdGhY8RGwwSmfZyymS04TCwWl8ZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708694264; c=relaxed/simple; bh=h2OjL8DTef4pDIjurdT4Gb7ejDmXMDQVGK1rQdmsTzM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tVXAOQ52XBlrl5XFPJ9P6XrGnknEovJNdXP+5jouYtIh8miyQnUrMEn64isMeDiyhfu5NS8PjbT1OstGw1H0xhb6oYs/cDxK6+pJRkwIW/tQ/24f9nPPSPhe4KT1z3W/LPdsvcppJ912k9c+ZQrbDRhVpC6TmQxVEAOGlUXj0+o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mojatatu.com; spf=none smtp.mailfrom=mojatatu.com; dkim=pass (2048-bit key) header.d=mojatatu-com.20230601.gappssmtp.com header.i=@mojatatu-com.20230601.gappssmtp.com header.b=JAGscflM; arc=none smtp.client-ip=209.85.222.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mojatatu.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=mojatatu.com 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="JAGscflM" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-787a2a14cd1so62055685a.0 for ; Fri, 23 Feb 2024 05:17:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1708694261; x=1709299061; 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=Itaq/2pNFLS1usTIRCj/iY6c0mWm3fl7hW59JF53sZ4=; b=JAGscflMxRzsFrMC1LileV7ao3WNjmHE2PXxXaXM9y5IqZxcv5rDzY0z7/D1mxeOGb zaFIZC3VhfbZmEPtTHjEvDHotZmXhD92uIwmAiWiPj894/+tYFiOvkCSGk/QaC+cYd5M huG8SBfG4JsN1/JZCTZuOK+M6kvqC7XyWPTsmxG+N8zdpqSxL0OL8W3ey/nWlgiCJOeB 9VKQv2OiBW3f6maxWpzoUie+9X5PoBz4udzRVMRhes4fCGiVjNpt0W3sGXPOukeyKBTf JMc0un36lph40U9K2Q7UySCCA7BflyjLWqyO0izrgr75Yp+QKveanFAJZC++IvKbzCuA 8LSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708694261; x=1709299061; 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=Itaq/2pNFLS1usTIRCj/iY6c0mWm3fl7hW59JF53sZ4=; b=FN+y2b8Kdyg9DGK9mvFPsLvVjVmjo+vawra+ZJiFghTpjdNvafWB40WRNxbB+pg7zc JdzLGq4aqiWRaWdpNHqQhHwBZHJQbdOGYxdnh6Psvc7pSntCDp1knpb5ax9gs9ueYYX0 ajuxBIfA9PttmKza6PRBR25x7ly5Ex4OoRveI97UHBI1wC8l3t83Eg36Ot00vNOhSbCX czr+8m9bFJPROh8uol8S0fjCWwMMN7uEg4mUlR0Q4Pb/MRFhjE+620rze2WBISd8W5mJ AopVAdRW3SzEWr41fvpngPB5zODcQ7FFlNfTXjOSCg7chE/C1v7llSwq+8wCovXYqRc+ YJ9w== X-Forwarded-Encrypted: i=1; AJvYcCVYQYvGeV63Y9olkGzIoeQRBwgQL4mOzR8o8bCoDBSFl5zHvcMo1fmwdWNZGmK0AdoiQk2nsHWbD/1xF112WRZMj5hz X-Gm-Message-State: AOJu0Yx1mng2qowEBHgssqFmdNujSJeIzvB5x95DkZ8s/wPiLftHaNex ufM4hwS2Zo1GNyxo0lCAo3dU/dQOXpOVJf2+n1Wn4/PetU1KwKUbEsUa7UXIrQ== X-Google-Smtp-Source: AGHT+IHE39YBoKYgoopYX/X+/C4d2FHXKyFQcFjDaDHA2t7OS/xDrhW0jJ6H5htoef1bDgWG9Ikq+Q== X-Received: by 2002:a05:620a:5652:b0:787:2224:5cbb with SMTP id vw18-20020a05620a565200b0078722245cbbmr1931974qkn.50.1708694261538; Fri, 23 Feb 2024 05:17:41 -0800 (PST) Received: from majuu.waya ([174.94.28.98]) by smtp.gmail.com with ESMTPSA id f3-20020a05620a15a300b00787ae919d02sm844869qkk.17.2024.02.23.05.17.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 05:17:41 -0800 (PST) From: Jamal Hadi Salim To: netdev@vger.kernel.org Cc: deb.chatterjee@intel.com, anjali.singhai@intel.com, namrata.limaye@intel.com, tom@sipanda.io, mleitner@redhat.com, Mahesh.Shirshyad@amd.com, Vipin.Jain@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, daniel@iogearbox.net, bpf@vger.kernel.org, pctammela@mojatatu.com, victor@mojatatu.com Subject: [PATCH net-next v11 2/5] net/sched: act_api: increase action kind string length Date: Fri, 23 Feb 2024 08:17:25 -0500 Message-Id: <20240223131728.116717-3-jhs@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223131728.116717-1-jhs@mojatatu.com> References: <20240223131728.116717-1-jhs@mojatatu.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Increase action kind string length from IFNAMSIZ to 64 The new P4 actions, created via templates, will have longer names of format: "pipeline_name/act_name". IFNAMSIZ is currently 16 and is most of the times undersized for the above format. So, to conform to this new format, we increase the maximum name length and change its definition from IFNAMSIZ to ACTNAMSIZ to account for this extra string (pipeline name) and the '/' character. 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 Reviewed-by: Marcelo Ricardo Leitner --- include/net/act_api.h | 2 +- include/uapi/linux/pkt_cls.h | 1 + net/sched/act_api.c | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/net/act_api.h b/include/net/act_api.h index f22be14bb..c839ff57c 100644 --- a/include/net/act_api.h +++ b/include/net/act_api.h @@ -106,7 +106,7 @@ typedef void (*tc_action_priv_destructor)(void *priv); struct tc_action_ops { struct list_head head; struct list_head p4_head; - char kind[IFNAMSIZ]; + char kind[ACTNAMSIZ]; enum tca_id id; /* identifier should match kind */ unsigned int net_id; size_t size; diff --git a/include/uapi/linux/pkt_cls.h b/include/uapi/linux/pkt_cls.h index ea277039f..dd313a727 100644 --- a/include/uapi/linux/pkt_cls.h +++ b/include/uapi/linux/pkt_cls.h @@ -6,6 +6,7 @@ #include #define TC_COOKIE_MAX_SIZE 16 +#define ACTNAMSIZ 64 /* Action attributes */ enum { diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 23ef394f2..ce10d2c6e 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -476,7 +476,7 @@ static size_t tcf_action_shared_attrs_size(const struct tc_action *act) rcu_read_unlock(); return nla_total_size(0) /* action number nested */ - + nla_total_size(IFNAMSIZ) /* TCA_ACT_KIND */ + + nla_total_size(ACTNAMSIZ) /* TCA_ACT_KIND */ + cookie_len /* TCA_ACT_COOKIE */ + nla_total_size(sizeof(struct nla_bitfield32)) /* TCA_ACT_HW_STATS */ + nla_total_size(0) /* TCA_ACT_STATS nested */ @@ -1424,7 +1424,7 @@ tc_action_load_ops(struct net *net, struct nlattr *nla, bool police = flags & TCA_ACT_FLAGS_POLICE; struct nlattr *tb[TCA_ACT_MAX + 1]; struct tc_action_ops *a_o; - char act_name[IFNAMSIZ]; + char act_name[ACTNAMSIZ]; struct nlattr *kind; int err; @@ -1439,12 +1439,12 @@ tc_action_load_ops(struct net *net, struct nlattr *nla, NL_SET_ERR_MSG(extack, "TC action kind must be specified"); return ERR_PTR(err); } - if (nla_strscpy(act_name, kind, IFNAMSIZ) < 0) { + if (nla_strscpy(act_name, kind, ACTNAMSIZ) < 0) { NL_SET_ERR_MSG(extack, "TC action name too long"); return ERR_PTR(err); } } else { - if (strscpy(act_name, "police", IFNAMSIZ) < 0) { + if (strscpy(act_name, "police", ACTNAMSIZ) < 0) { NL_SET_ERR_MSG(extack, "TC action name too long"); return ERR_PTR(-EINVAL); } From patchwork Fri Feb 23 13:17:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jamal Hadi Salim X-Patchwork-Id: 13569074 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AFC07EF00 for ; Fri, 23 Feb 2024 13:17:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708694265; cv=none; b=gyjoVUqOTQUK5SCq3O8oF52RN6SgitT314o54YYMBXbUYZ5ZrYP1ksQewp0OKnF6iJ1YpLT4pswfRdnmFsvxibIPHAXNgeLWv/2PjDOWaa7f/sGTLNFRiJPE2dE8NDXcsWTNrHkJ4Pk2EA/+OV80fyORWibnVZCP9mYqRxNm6qE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708694265; c=relaxed/simple; bh=M4If/UOYvi0X5ofyVN5k561/nL5KTpuzPE6SiFq38Ew=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oJTtmN4SJoWI1CZYYlVbuwApuxs99qgAsLFwrxU0Tu7iwhym5G3XkAOo/QSh5aTfmSTudLTUsHTX+CZF9Q60kRg33p3cNNEvVQdZjKIFFph3FG5pRctmQCOVDxloSUwdpKNJC7kVfC/J6bxYGQg+Si4v4Uu/pWi7qO48fk4Wjpg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mojatatu.com; spf=none smtp.mailfrom=mojatatu.com; dkim=pass (2048-bit key) header.d=mojatatu-com.20230601.gappssmtp.com header.i=@mojatatu-com.20230601.gappssmtp.com header.b=HoMkIe9Z; arc=none smtp.client-ip=209.85.222.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mojatatu.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=mojatatu.com 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="HoMkIe9Z" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-787bb013422so5221585a.0 for ; Fri, 23 Feb 2024 05:17:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1708694263; x=1709299063; 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=UKOnDKEjrpcKuEtJ9C4jK4dD7Y3mugzMjgQ2qo2O6Vc=; b=HoMkIe9ZvHSYpZ77ZZg/BWucghITKikQC9uSaaJ1o+hQrguy+OkJK4I4keCq2wjLmA 2QmB11+FGBJ3w6XmBp/hnHn+KqpwFsLSzhld7LiYZl9nmvsadsR8tiR1MYFHORHd5k9K QpOW2pmg6lYK7gygyDSO6FmZTtEqslGVvD+wnMQNWKv1otYMPwqw/X5uKYoQsqpu3yvl cpIX6D/hJtCMNTwsRylSrcRE/LF77yKSvdgecqBSo4MPhvkmt2Trka9hUvk1lAWF/vfK 4Jz9EP9B1UGYCXxWH5Z1ByH4G1pSC1823esBM1bMHgcLpbdaN7TySkHUVgH7cWY8i353 GDyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708694263; x=1709299063; 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=UKOnDKEjrpcKuEtJ9C4jK4dD7Y3mugzMjgQ2qo2O6Vc=; b=DfScRV+Pr3PmEt6lUsU/FsxSNfNv4G8r5puT9M39L2JOhxsiL7R9MT0W3xAK1zOuHp us/xMQK5+VjpnqVAk42zYWZZDqA4IHkLOFCwYl5+W/JLIyNJk1nbUw7z/BodTZX/E6o4 SG9PDw/8dfLkP9B9NXeXj2H+T5r48mqM8RUyU+NGYVzyTvT6KvBNxiNT0bzCbcDyj1Z/ ro8FHhrrFhIJGb7j1TfDDtYtsPPn13AqKRZ8vFq5ntyM/4b04Lah8Z6CFQ9Gc0HS1Bx6 JU8z3Rts8fRFvH5LiBwuw8NBMFL4lmaTbUCftUHhmoAyIFbsw+TNLSwhCd7tp+q+ZH+V Jxyg== X-Forwarded-Encrypted: i=1; AJvYcCXhVguFpWwUSZ8w32vQgNfyDzskZ0NPUTMpAfiKFaL8Wetkh01NtXYFVMNCzzC2q0LX5R7mulAEgT2SNk/44RTTDMwg X-Gm-Message-State: AOJu0YzZJ/ikDazwZ4TY5zMw9Vr+pBNwJADLBIwQlnza9vC/a+6VeAtx QuDpOWqu/sYqX8kmXPTxh91gw7eJLR9avz3aad31atvhXkt6gw96EvzfU7iFPg== X-Google-Smtp-Source: AGHT+IF2PKC7Pynbc1M4DjhxglVtwZtdZgWh62Cbp1FJUuX8roOXxt0B5zTj/sY+326RHFLcEgdx1Q== X-Received: by 2002:a05:620a:12ce:b0:787:1fb5:7e61 with SMTP id e14-20020a05620a12ce00b007871fb57e61mr1833574qkl.46.1708694262935; Fri, 23 Feb 2024 05:17:42 -0800 (PST) Received: from majuu.waya ([174.94.28.98]) by smtp.gmail.com with ESMTPSA id f3-20020a05620a15a300b00787ae919d02sm844869qkk.17.2024.02.23.05.17.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 05:17:42 -0800 (PST) From: Jamal Hadi Salim To: netdev@vger.kernel.org Cc: deb.chatterjee@intel.com, anjali.singhai@intel.com, namrata.limaye@intel.com, tom@sipanda.io, mleitner@redhat.com, Mahesh.Shirshyad@amd.com, Vipin.Jain@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, daniel@iogearbox.net, bpf@vger.kernel.org, pctammela@mojatatu.com, victor@mojatatu.com Subject: [PATCH net-next v11 3/5] net/sched: act_api: Update tc_action_ops to account for P4 actions Date: Fri, 23 Feb 2024 08:17:26 -0500 Message-Id: <20240223131728.116717-4-jhs@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223131728.116717-1-jhs@mojatatu.com> References: <20240223131728.116717-1-jhs@mojatatu.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 P4 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 P4 and are net namespace specific and not global like standard tc actions. 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 Reviewed-by: Marcelo Ricardo Leitner --- 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 c839ff57c..69be5ed83 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 p4_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 ce10d2c6e..3d1fb8da1 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -1044,7 +1044,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, @@ -1517,8 +1517,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); From patchwork Fri Feb 23 13:17:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jamal Hadi Salim X-Patchwork-Id: 13569075 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E1387E579 for ; Fri, 23 Feb 2024 13:17:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708694266; cv=none; b=sdJWPOLUrtJ3RRCrNjFW3D8hpoKh5/D1eqx5FrXOk4szr4wW3/o1GeWe1SS78xTqmHyhzwz9+F70qhBj/XxrY5MgBio1d7oVfJAgi9/PRtUADghFAW999gMdyG0hVLEY9R/I1+w02DoWE6MAdWoTr1m4VecRaVKT7Rn+tyxATTQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708694266; c=relaxed/simple; bh=YXSQQ0uQGokFV2UfiJU2Y96Z22+5kUS1rG2wL0NsELU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q0ISEI8XxmgU8R9TCk5OS5DoZrFbjKGAionZh+sjJaaPE2NjLCILbU0L6tTcs84YO2Z6po0HHXAqPRB6oekjcJGBgn5sWHFGt9RVjSThx6fPmC0/jA6/DnvDGbj8+rRpFBQTw7agLKb2Lxw6cj7v6np7i/dI7MyF8+qabB+9cLI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mojatatu.com; spf=none smtp.mailfrom=mojatatu.com; dkim=pass (2048-bit key) header.d=mojatatu-com.20230601.gappssmtp.com header.i=@mojatatu-com.20230601.gappssmtp.com header.b=h2bot8A9; arc=none smtp.client-ip=209.85.222.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mojatatu.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=mojatatu.com 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="h2bot8A9" Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-787b958b3f8so15829885a.0 for ; Fri, 23 Feb 2024 05:17:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1708694264; x=1709299064; 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=YGymPU1YTSNaMGYDgceX+N7ZQ90LxxvlYMbgFPW1GZA=; b=h2bot8A9NhMV8XHowOVt3RT3K1nBy5B1CureMlGrmKE9JQC0i5jFXktd+6psmm60P8 FeQlZUnRCRUK5WkU6fFCSVyzr+ZphOrw5/UdZXNMN5P5Nld0VNK7tvY8YKdzldsVoGSH W+JmXCc3Zg865ziiALiripA0tL8IDKWGtFiXr4HCtd7w4PQUpE1E25Bhm19eubzjgC4F xFD4s2v9WEVNOevkaq7uKbk3nblnGgclCtdPrlFhhvT2S/qtadR5p1aqD80D5nZKmi+h iO4FnuxbTStmvuUZkRjt7N3TKOa/aJzYSgQaid66lECjCD/nCb3CMHfIaJyyJxgRjQ4g hhIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708694264; x=1709299064; 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=YGymPU1YTSNaMGYDgceX+N7ZQ90LxxvlYMbgFPW1GZA=; b=fRNZm3hAT9qlXw7E2Ln5kSJCDr+IUEtF7eAwDAYJhSX5hXpkY89YOD8WDdfzDOkY5x CpF0TZROveCgQsVX2u1JVrdLMLrly7Y3yNUH8bHP3gnAMKB686TVERhg8jH3AdQbryii yzMB+gEMoGSC+Hl97Tjain7H+ZYWNqMCvUWyOkxqUKExKsAptfZqaDMvGvT4/3TdXor/ 7m3N040kuQL/WjphA+W71TN+htRKB4LIiVvDY2PSdPJw9IpXYQ/J3/E/klvn/cm4bc5Q 3omtBHf/BQrfPcJBn0cNfq+elVnYcWhgo2s0Z3gokSgB3ioiXxgTDoKmlUOyWbEN/YtI 8nKQ== X-Forwarded-Encrypted: i=1; AJvYcCUoXo0uYj5QWDWA9ZXjN4shV/cgUqss6Z+r6jWY0qZiPbQGf1MUADUg0WA4waW4qNYdIP3q3IE3R2nig19qoxQkdqv0 X-Gm-Message-State: AOJu0YxdWQ1mss/8WvjeFC4bobbwxD04+4o53WZwXoZFR/cbv+o6Ob/a j1zcvZLz6EcaDs0bpHlRmFL2Xz6811PYWH1gyaqO1X8q7RnlayS56azKxQayvg== X-Google-Smtp-Source: AGHT+IE3mheVfugS1y89UaawYfATltZItVLyh0DP4+H4+xt0zPasHl0WfRp7fhmyF+KJeC2VJcqdfQ== X-Received: by 2002:a05:620a:2881:b0:787:2b5a:31b0 with SMTP id j1-20020a05620a288100b007872b5a31b0mr1961353qkp.71.1708694264419; Fri, 23 Feb 2024 05:17:44 -0800 (PST) Received: from majuu.waya ([174.94.28.98]) by smtp.gmail.com with ESMTPSA id f3-20020a05620a15a300b00787ae919d02sm844869qkk.17.2024.02.23.05.17.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 05:17:44 -0800 (PST) From: Jamal Hadi Salim To: netdev@vger.kernel.org Cc: deb.chatterjee@intel.com, anjali.singhai@intel.com, namrata.limaye@intel.com, tom@sipanda.io, mleitner@redhat.com, Mahesh.Shirshyad@amd.com, Vipin.Jain@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, daniel@iogearbox.net, bpf@vger.kernel.org, pctammela@mojatatu.com, victor@mojatatu.com Subject: [PATCH net-next v11 4/5] net/sched: act_api: add struct p4tc_action_ops as a parameter to lookup callback Date: Fri, 23 Feb 2024 08:17:27 -0500 Message-Id: <20240223131728.116717-5-jhs@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223131728.116717-1-jhs@mojatatu.com> References: <20240223131728.116717-1-jhs@mojatatu.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org For P4 actions, we require information from struct tc_action_ops, specifically the action kind, to find and locate the P4 action information for the lookup operation. 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 Reviewed-by: Marcelo Ricardo Leitner --- include/net/act_api.h | 3 ++- net/sched/act_api.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/net/act_api.h b/include/net/act_api.h index 69be5ed83..49f471c58 100644 --- a/include/net/act_api.h +++ b/include/net/act_api.h @@ -116,7 +116,8 @@ struct tc_action_ops { struct tcf_result *); /* called under RCU BH lock*/ int (*dump)(struct sk_buff *, struct tc_action *, int, int); void (*cleanup)(struct tc_action *); - int (*lookup)(struct net *net, struct tc_action **a, u32 index); + int (*lookup)(struct net *net, const struct tc_action_ops *ops, + struct tc_action **a, u32 index); int (*init)(struct net *net, struct nlattr *nla, struct nlattr *est, struct tc_action **act, struct tcf_proto *tp, diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 3d1fb8da1..835ead746 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -726,7 +726,7 @@ static int __tcf_idr_search(struct net *net, struct tc_action_net *tn = net_generic(net, ops->net_id); if (unlikely(ops->lookup)) - return ops->lookup(net, a, index); + return ops->lookup(net, ops, a, index); return tcf_idr_search(tn, a, index); } From patchwork Fri Feb 23 13:17:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jamal Hadi Salim X-Patchwork-Id: 13569076 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E464D7E78A for ; Fri, 23 Feb 2024 13:17:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708694268; cv=none; b=qrnV3YBENIMgSyeMx0Q5fkninyJQFXAMRi/J+IXBDs/DVjF9aTSD3njwRHC+Ujgqk5BxJDMLSF+eWpg1e6bVxn17XWlOEPpVuQXAv+2nCddlrh7Ur9onSE3g0ZlJjFKKAF0B8AldAFfOw2DGuA/9Fe4hJUukR73IuY3Dc9ZIoNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708694268; c=relaxed/simple; bh=0DhGdU85buiKZ6gE/vKFkpiU6PLSJnvgVIVPpPyrqaU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pmewRL5eGqpb0tWZ6wumCCtfQsSVfb7g3iE/4aR38vyKxEa/W01S9jFFDa+fIDZ2xUWSarQwopNhbmZTMsC9uN8u3graMyImQmaHIp+sJLASR+H+bpmnh81JFTdauGZbwgcnamXPfHLBDc3bY9KhsfsCGvmfAsOC+L4IC4I4t+Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mojatatu.com; spf=none smtp.mailfrom=mojatatu.com; dkim=pass (2048-bit key) header.d=mojatatu-com.20230601.gappssmtp.com header.i=@mojatatu-com.20230601.gappssmtp.com header.b=K4cLbt1f; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mojatatu.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=mojatatu.com 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="K4cLbt1f" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7874a96a01dso19129185a.3 for ; Fri, 23 Feb 2024 05:17:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20230601.gappssmtp.com; s=20230601; t=1708694266; x=1709299066; 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=H9AIcnsxEM8NnMIh0oZV+QmkJ4BpMVmS49VYo2k2mSE=; b=K4cLbt1f4ukuuqZQXwxzGWKRiAogh7Yv7bE59mTKReCL1BLAJVCJI2s1VSQrqD6ke6 3YI9jwH128zOSyCQ0Nbs2jEiWQLPOTPCOTiwBqgLnwDFG5RpFEuH9ct+i+qM4nOQj+Fy //A5sKTISS5r6pyrJy+RQgLZILEBvZxvKmuTZYL/wMuEDnCw1WzSQphbwG0xXKiyUoxu ZZl+9DQytizsRDNpK+KUezczK2kkUVRpUWj/JXdSdyzYdLf1fqOAkrkRRTbjqT+ndCu6 SlF/C1rEYTiQ1f2Njlispma1yiNjV5OyOEvv8FTslRt++OugH2Q1bC95fEpHnwuReG+R gHmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708694266; x=1709299066; 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=H9AIcnsxEM8NnMIh0oZV+QmkJ4BpMVmS49VYo2k2mSE=; b=tcP3AdqanPrcOBDT1pn5Psvb5/FYQzzN656/+5wAfeLjoKLY/QrsjNDVVkEP8NCxTN Z+wxNV+1CabXmlLMLR9v+XVA5utZCKroMHlptbDtpuGB2IF6H9GG4p4PkotzZbbV5K8H ph5GGZJvdvSsEKYbWnxsGQeJz5BJJ5pJoP+mduv6DnqPivZlqR6WMkCmuD48wS3QyqaW Ctnrmmj8JfqO6YVIwoOXapNgyGG757Fwzdk7utCZaWeEoPDyzUZ03KpSBDeXzVT11EAv Wj4PXXDf/XejL9ECYFgLGih3w7Q1uV7w+ZOqoWvvPZ4pKqWP1jTSqOUgjmTmSF2okxim fjNg== X-Forwarded-Encrypted: i=1; AJvYcCWfRZLFZDiF0cOikgb0paTB15vqlkUGHPoBUSUseoJMnBBHvtU0L7onvm+62hWdMXwfHFovJRv3r+LWgk3Uubq0VPnz X-Gm-Message-State: AOJu0YwhyVL+PkCKQNfBKRdC5x4lizDjUDMwuYIKkTUPPR7TeweUvCPr a+XGFegQwAGCE8+iHt9QTWBS55UGGzMBjOBzcV58MdX0A+N+FgbrON8eC2RJYQ== X-Google-Smtp-Source: AGHT+IEvLAlXJJPSSfmEiVPqOqWHPP+NdjSs5uwg32f4GRgDxTZ8AK//Hgrd4I6ArugOyBIKdcBBtg== X-Received: by 2002:a05:620a:479b:b0:787:2b66:a088 with SMTP id dt27-20020a05620a479b00b007872b66a088mr1871565qkb.1.1708694265839; Fri, 23 Feb 2024 05:17:45 -0800 (PST) Received: from majuu.waya ([174.94.28.98]) by smtp.gmail.com with ESMTPSA id f3-20020a05620a15a300b00787ae919d02sm844869qkk.17.2024.02.23.05.17.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 05:17:45 -0800 (PST) From: Jamal Hadi Salim To: netdev@vger.kernel.org Cc: deb.chatterjee@intel.com, anjali.singhai@intel.com, namrata.limaye@intel.com, tom@sipanda.io, mleitner@redhat.com, Mahesh.Shirshyad@amd.com, Vipin.Jain@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, daniel@iogearbox.net, bpf@vger.kernel.org, pctammela@mojatatu.com, victor@mojatatu.com Subject: [PATCH net-next v11 5/5] net: sched: act_api: Add support for preallocated P4 action instances Date: Fri, 23 Feb 2024 08:17:28 -0500 Message-Id: <20240223131728.116717-6-jhs@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223131728.116717-1-jhs@mojatatu.com> References: <20240223131728.116717-1-jhs@mojatatu.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org In P4, actions are assumed to pre exist and have an upper bound number of instances. Typically if you a table defined with 1M table entries you want to allocate enough action instances to cover the 1M entries. However, this is a big waste of memory if the action instances are not in use. So for our case, we allow the user to specify a minimal amount of actions in the template and then if more P4 action instances are needed then they will be added on demand as in the current approach with tc filter-action relationship. Add the necessary code to preallocate actions instances for P4 actions. We add 2 new actions flags: - TCA_ACT_FLAGS_PREALLOC: Indicates the action instance is a P4 action and was preallocated for future use the templating phase of P4TC - TCA_ACT_FLAGS_UNREFERENCED: Indicates the action instance was preallocated and is currently not being referenced by any other object. Which means it won't show up in an action instance dump. Once an action instance is created we don't free it when the last table entry referring to it is deleted. Instead we add it to the pool/cache of action instances for that specific action kind i.e it counts as if it is preallocated. Preallocated actions can't be deleted by the tc actions runtime commands and a dump or a get will only show preallocated actions instances which are being used (i.e TCA_ACT_FLAGS_UNREFERENCED == false). The preallocated actions will be deleted once the pipeline is deleted (which will purge the P4 action kind and its instances). For example, if we were to create a P4 action that preallocates 128 elements and dumped: $ tc -j p4template get action/myprog/send_nh | jq . We'd see the following: [ { "obj": "action template", "pname": "myprog", "pipeid": 1 }, { "templates": [ { "aname": "myprog/send_nh", "actid": 1, "params": [ { "name": "port", "type": "dev", "id": 1 } ], "prealloc": 128 } ] } ] If we try to dump the P4 action instances, we won't see any: $ tc -j actions ls action myprog/send_nh | jq . [] However, if we create a table entry which references this action kind: $ tc p4ctrl create myprog/table/cb/FDB \ dstAddr d2:96:91:5d:02:86 action myprog/send_nh \ param port type dev dummy0 Dumping the action instance will now show this one instance which is associated with the table entry: $ tc -j actions ls action myprog/send_nh | jq . [ { "total acts": 1 }, { "actions": [ { "order": 0, "kind": "myprog/send_nh", "index": 1, "ref": 1, "bind": 1, "params": [ { "name": "port", "type": "dev", "value": "dummy0", "id": 1 } ], "not_in_hw": true } ] } ] 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 Reviewed-by: Marcelo Ricardo Leitner --- include/net/act_api.h | 3 +++ net/sched/act_api.c | 45 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/include/net/act_api.h b/include/net/act_api.h index 49f471c58..d35870fbf 100644 --- a/include/net/act_api.h +++ b/include/net/act_api.h @@ -68,6 +68,8 @@ struct tc_action { #define TCA_ACT_FLAGS_REPLACE (1U << (TCA_ACT_FLAGS_USER_BITS + 2)) #define TCA_ACT_FLAGS_NO_RTNL (1U << (TCA_ACT_FLAGS_USER_BITS + 3)) #define TCA_ACT_FLAGS_AT_INGRESS (1U << (TCA_ACT_FLAGS_USER_BITS + 4)) +#define TCA_ACT_FLAGS_PREALLOC (1U << (TCA_ACT_FLAGS_USER_BITS + 5)) +#define TCA_ACT_FLAGS_UNREFERENCED (1U << (TCA_ACT_FLAGS_USER_BITS + 6)) /* Update lastuse only if needed, to avoid dirtying a cache line. * We use a temp variable to avoid fetching jiffies twice. @@ -201,6 +203,7 @@ int tcf_idr_create_from_flags(struct tc_action_net *tn, u32 index, const struct tc_action_ops *ops, int bind, u32 flags); void tcf_idr_insert_many(struct tc_action *actions[], int init_res[]); +void tcf_idr_insert_n(struct tc_action *actions[], const u32 n); void tcf_idr_cleanup(struct tc_action_net *tn, u32 index); int tcf_idr_check_alloc(struct tc_action_net *tn, u32 *index, struct tc_action **a, int bind); diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 835ead746..418e44235 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -560,6 +560,8 @@ static int tcf_dump_walker(struct tcf_idrinfo *idrinfo, struct sk_buff *skb, continue; if (IS_ERR(p)) continue; + if (p->tcfa_flags & TCA_ACT_FLAGS_UNREFERENCED) + continue; if (jiffy_since && time_after(jiffy_since, @@ -640,6 +642,9 @@ static int tcf_del_walker(struct tcf_idrinfo *idrinfo, struct sk_buff *skb, idr_for_each_entry_ul(idr, p, tmp, id) { if (IS_ERR(p)) continue; + if (p->tcfa_flags & TCA_ACT_FLAGS_PREALLOC) + continue; + ret = tcf_idr_release_unsafe(p); if (ret == ACT_P_DELETED) module_put(ops->owner); @@ -1398,25 +1403,40 @@ static const struct nla_policy tcf_action_policy[TCA_ACT_MAX + 1] = { [TCA_ACT_HW_STATS] = NLA_POLICY_BITFIELD32(TCA_ACT_HW_STATS_ANY), }; +static void tcf_idr_insert_1(struct tc_action *a) +{ + struct tcf_idrinfo *idrinfo; + + idrinfo = a->idrinfo; + mutex_lock(&idrinfo->lock); + /* Replace ERR_PTR(-EBUSY) allocated by tcf_idr_check_alloc if + * it is just created, otherwise this is just a nop. + */ + idr_replace(&idrinfo->action_idr, a, a->tcfa_index); + mutex_unlock(&idrinfo->lock); +} + void tcf_idr_insert_many(struct tc_action *actions[], int init_res[]) { struct tc_action *a; int i; tcf_act_for_each_action(i, a, actions) { - struct tcf_idrinfo *idrinfo; - if (init_res[i] == ACT_P_BOUND) continue; - idrinfo = a->idrinfo; - mutex_lock(&idrinfo->lock); - /* Replace ERR_PTR(-EBUSY) allocated by tcf_idr_check_alloc */ - idr_replace(&idrinfo->action_idr, a, a->tcfa_index); - mutex_unlock(&idrinfo->lock); + tcf_idr_insert_1(a); } } +void tcf_idr_insert_n(struct tc_action *actions[], const u32 n) +{ + int i; + + for (i = 0; i < n; i++) + tcf_idr_insert_1(actions[i]); +} + struct tc_action_ops * tc_action_load_ops(struct net *net, struct nlattr *nla, u32 flags, struct netlink_ext_ack *extack) @@ -2092,8 +2112,17 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n, ret = PTR_ERR(act); goto err; } - attr_size += tcf_action_fill_size(act); actions[i - 1] = act; + + if (event == RTM_DELACTION && + act->tcfa_flags & TCA_ACT_FLAGS_PREALLOC) { + ret = -EINVAL; + NL_SET_ERR_MSG_FMT(extack, + "Unable to delete preallocated action %s", + act->ops->kind); + goto err; + } + attr_size += tcf_action_fill_size(act); } attr_size = tcf_action_full_attrs_size(attr_size);