Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp7143190ybf; Fri, 6 Mar 2020 11:11:47 -0800 (PST) X-Google-Smtp-Source: ADFU+vsIpzxUOTyBJm1ZXAa/lsURxWzhWFeV/19pmbiqkJL+SJZvNlrHfs8/x//oarXoJGXWc0Ag X-Received: by 2002:aca:474e:: with SMTP id u75mr3575846oia.52.1583521907770; Fri, 06 Mar 2020 11:11:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583521907; cv=none; d=google.com; s=arc-20160816; b=E9omDNt84AH0Z8mFrs7HbrbeznHvOWmMfRCzJSx1ZnDjLz7sHBECjHBJxprYH9BwCo XfpLfRb6UFXrY5XJ759rSsZVy4B1rXRQQE4sgkP8nZIPjtu++nK7U5Fl2jxoL8GIkf1b lLrlXwzEaK8iY0FkYgvlyAUEuRZb1sldI46xf4seZzT7ptZI7t4pxA1txxigbUDYzwt9 ZPOun7X+UEDCtO6ZZk7H0ILrUUHds2PChrQDvG+LXMAzfIb1DIbXOhSFlnovjk/dTRXV fqpPTrjSZ8BZPt1XwdwCZ+5Ta9gYEmvNArwywnFn82PFCkRHWfttsXWwmwm14FQ6Cu0C psmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=6m9lNpN0oC5XeH8W12OhvHHGL9gYP/fkUkoIG6d3xXI=; b=BD66g4kF8mS0HDxs0wUqpPYDJ35hkXbwzP1Y1aVFlcTv45o9LG/12xeEetDdQNuj0t kVgb8D24k34eZldqo9yUUKLKvbo7gT+0Uf2sNleHDzW2uMBzi8oaG1inYROehlLrOosv 7R8+aqSUB7AhxvevHyIEjXKyuV7JaG87Rw8T2IyfR/UowIVBHZnxm6qFiDbRtE5sbp3a G61N/pJocXXQ8XEuhT9/3qogQfol+SjK+tcGcDNECyTI1GxcqpIx2fol8rRBIHdBJhM8 UuyhkyXMizwehIt7IZJ7lMIW24K4pbiAa8x0ika0NgFrHTqQqueSxUuzMEuvJ8DiNY0a Ll4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sVeVXl5p; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b24si1873765otq.72.2020.03.06.11.11.36; Fri, 06 Mar 2020 11:11:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sVeVXl5p; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726811AbgCFTLK (ORCPT + 99 others); Fri, 6 Mar 2020 14:11:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:38886 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726194AbgCFTLK (ORCPT ); Fri, 6 Mar 2020 14:11:10 -0500 Received: from kicinski-fedora-PC1C0HJN (unknown [163.114.132.128]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F29BC20656; Fri, 6 Mar 2020 19:11:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583521869; bh=I5XbT8QZEW6+CEYOiuZ0DU2H6PyHZynEgjZpEpbsnZ4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=sVeVXl5pj9av2XR9MjMwsvB2SUSwWJ7mN6asO6kfYFkmcNrnR/Jc/I0D/E1c6mI1A nKBcTtMmBD3cZR3rlM/wuh+C/B9PauxDpS9efUXLzZCDKSHjwLYdAXC7ANMb7zQ3iA EudlYYRLU2UCpf8F1ntZ2n3IMG0zWADrGgxMuUUw= Date: Fri, 6 Mar 2020 11:11:06 -0800 From: Jakub Kicinski To: Po Liu Cc: davem@davemloft.net, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, vinicius.gomes@intel.com, claudiu.manoil@nxp.com, vladimir.oltean@nxp.com, alexandru.marginean@nxp.com, xiaoliang.yang_1@nxp.com, roy.zang@nxp.com, mingkai.hu@nxp.com, jerry.huang@nxp.com, leoyang.li@nxp.com, michael.chan@broadcom.com, vishal@chelsio.com, saeedm@mellanox.com, leon@kernel.org, jiri@mellanox.com, idosch@mellanox.com, alexandre.belloni@bootlin.com, UNGLinuxDriver@microchip.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com, john.hurley@netronome.com, simon.horman@netronome.com, pieter.jansenvanvuuren@netronome.com, pablo@netfilter.org, moshe@mellanox.com, ivan.khoronzhuk@linaro.org, m-karicheri2@ti.com, andre.guedes@linux.intel.com, jakub.kicinski@netronome.com Subject: Re: [RFC,net-next 2/9] net: qos: introduce a gate control flow action Message-ID: <20200306111106.09416f43@kicinski-fedora-PC1C0HJN> In-Reply-To: <20200306125608.11717-3-Po.Liu@nxp.com> References: <20200306125608.11717-1-Po.Liu@nxp.com> <20200306125608.11717-3-Po.Liu@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 6 Mar 2020 20:56:00 +0800 Po Liu wrote: > Introduce a ingress frame gate control flow action. tc create a gate > action would provide a gate list to control when open/close state. when > the gate open state, the flow could pass but not when gate state is > close. The driver would repeat the gate list cyclically. User also could > assign a time point to start the gate list by the basetime parameter. if > the basetime has passed current time, start time would calculate by the > cycletime of the gate list. > The action gate behavior try to keep according to the IEEE 802.1Qci spec. > For the software simulation, require the user input the clock type. > > Below is the setting example in user space: > > > tc qdisc add dev eth0 ingress > > > tc filter add dev eth0 parent ffff: protocol ip \ > flower src_ip 192.168.0.20 \ > action gate index 2 \ > sched-entry OPEN 200000000 -1 -1 \ > sched-entry CLOSE 100000000 -1 -1 > > > tc chain del dev eth0 ingress chain 0 > > "sched-entry" follow the name taprio style. gate state is > "OPEN"/"CLOSE". Follow the period nanosecond. Then next -1 is internal > priority value means which ingress queue should put. "-1" means > wildcard. The last value optional specifies the maximum number of > MSDU octets that are permitted to pass the gate during the specified > time interval. > > NOTE: This software simulator version not separate the admin/operation > state machine. Update setting would overwrite stop the previos setting > and waiting new cycle start. > > Signed-off-by: Po Liu > diff --git a/net/sched/act_gate.c b/net/sched/act_gate.c > new file mode 100644 > index 000000000000..c2c243ca028c > --- /dev/null > +++ b/net/sched/act_gate.c > @@ -0,0 +1,645 @@ > +// SPDX-License-Identifier: (GPL-2.0+) Why the parenthesis? > +static const struct nla_policy entry_policy[TCA_GATE_ENTRY_MAX + 1] = { > + [TCA_GATE_ENTRY_INDEX] = { .type = NLA_U32 }, > + [TCA_GATE_ENTRY_GATE] = { .type = NLA_FLAG }, > + [TCA_GATE_ENTRY_INTERVAL] = { .type = NLA_U32 }, > + [TCA_GATE_ENTRY_IPV] = { .type = NLA_S32 }, > + [TCA_GATE_ENTRY_MAX_OCTETS] = { .type = NLA_S32 }, > +}; > + > +static const struct nla_policy gate_policy[TCA_GATE_MAX + 1] = { > + [TCA_GATE_PARMS] = { .len = sizeof(struct tc_gate) }, > + [TCA_GATE_PRIORITY] = { .type = NLA_S32 }, > + [TCA_GATE_ENTRY_LIST] = { .type = NLA_NESTED }, > + [TCA_GATE_BASE_TIME] = { .type = NLA_U64 }, > + [TCA_GATE_CYCLE_TIME] = { .type = NLA_U64 }, > + [TCA_GATE_CYCLE_TIME_EXT] = { .type = NLA_U64 }, > + [TCA_GATE_FLAGS] = { .type = NLA_U32 }, > + [TCA_GATE_CLOCKID] = { .type = NLA_S32 }, > +}; > + > +static int fill_gate_entry(struct nlattr **tb, struct tcfg_gate_entry *entry, > + struct netlink_ext_ack *extack) > +{ > + u32 interval = 0; > + > + if (tb[TCA_GATE_ENTRY_GATE]) > + entry->gate_state = 1; > + else > + entry->gate_state = 0; nla_get_flag() > + > + if (tb[TCA_GATE_ENTRY_INTERVAL]) > + interval = nla_get_u32(tb[TCA_GATE_ENTRY_INTERVAL]); > + > + if (interval == 0) { > + NL_SET_ERR_MSG(extack, "Invalid interval for schedule entry"); > + return -EINVAL; > + } > +static int parse_gate_list(struct nlattr *list, > + struct tcf_gate_params *sched, > + struct netlink_ext_ack *extack) > +{ > + struct nlattr *n; > + int err, rem; > + int i = 0; > + > + if (!list) > + return -EINVAL; > + > + nla_for_each_nested(n, list, rem) { > + struct tcfg_gate_entry *entry; > + > + if (nla_type(n) != TCA_GATE_ONE_ENTRY) { > + NL_SET_ERR_MSG(extack, "Attribute isn't type 'entry'"); > + continue; > + } > + > + entry = kzalloc(sizeof(*entry), GFP_KERNEL); > + if (!entry) { > + NL_SET_ERR_MSG(extack, "Not enough memory for entry"); > + return -ENOMEM; > + } > + > + err = parse_gate_entry(n, entry, i, extack); > + if (err < 0) { > + kfree(entry); doesn't this leak previously added entries? > + return err; > + } > + > + list_add_tail(&entry->list, &sched->entries); > + i++; > + } > + > + sched->num_entries = i; > + > + return i; > +} > +static int parse_gate_entry(struct nlattr *n, struct tcfg_gate_entry *entry, > + int index, struct netlink_ext_ack *extack) > +{ > + struct nlattr *tb[TCA_GATE_ENTRY_MAX + 1] = { }; > + int err; > + > + err = nla_parse_nested_deprecated(tb, TCA_GATE_ENTRY_MAX, n, Please don't use the deprecated calls in new code. > + entry_policy, NULL); > + if (err < 0) { > + NL_SET_ERR_MSG(extack, "Could not parse nested entry"); > + return -EINVAL; > + } > + > + entry->index = index; > + > + return fill_gate_entry(tb, entry, extack); > +}