Skip to contentSkip to conversation

Introduce a flow gate control action and apply IEEE

RFC In review Po Liu 18 participants 125 messages Mar 6, 2020 – Jun 25, 2020 Page 2 of 2

Subsystems (13)
lore
Share & tools
lore
#75 lore raw

Re: [EXT] Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

In reply to Po Liu
Quoted 451 lines · Po Liu

Hi Vlad Buslov,

Quoted 310 lines

-----Original Message-----
From: Vlad Buslov <[email protected]>
Sent: 2020年4月22日 21:23
To: Po Liu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Claudiu Manoil <[email protected]>; Vladimir Oltean <[email protected]>; Alexandru Marginean <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [EXT] Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

Caution: EXT Email

Hi Po,

Quoted 39 lines · Po Liu

Introduce a ingress frame gate control flow action.
Tc gate action does the work like this:
Assume there is a gate allow specified ingress frames can be passed at specific time slot, and be dropped at specific time slot. Tc filter chooses the ingress frames, and tc gate action would specify what slot does these frames can be passed to device and what time slot would be dropped.
Tc gate action would provide an entry list to tell how much time gate keep open and how much time gate keep state close. Gate action also assign a start time to tell when the entry list start. Then driver would repeat the gate entry list cyclically.
For the software simulation, gate action requires the user assign a time clock type.

Below is the setting example in user space. Tc filter a stream source ip address is 192.168.0.20 and gate action own two time slots. One is last 200ms gate open let frame pass another is last 100ms gate close let frames dropped. When the frames have passed total frames over 8000000 bytes, frames will be dropped in one 200000000ns time slot.

Quoted 3 lines

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 clockid CLOCK_TAI \
         sched-entry open 200000000 -1 8000000 \
         sched-entry close 100000000 -1 -1
Quoted 1 line

tc chain del dev eth0 ingress chain 0

"sched-entry" follow the name taprio style. Gate state is "open"/"close". Follow with period nanosecond. Then next item 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.
Base-time is not set will be 0 as default, as result start time would be ((N + 1) * cycletime) which is the minimal of future time.

Quoted 3 lines

Below example shows filtering a stream with destination mac address is 10:00:80:00:00:00 and ip type is ICMP, follow the action gate. The gate action would run with one close time slot which means always keep

close.

Quoted 87 lines

The time cycle is total 200000000ns. The base-time would calculate by:

1357000000000 + (N + 1) * cycletime

When the total value is the future time, it will be the start time. The cycletime here would be 200000000ns for this case.

Quoted 1 line

tc filter add dev eth0 parent ffff: protocol ip \

         flower skip_hw ip_proto icmp dst_mac 10:00:80:00:00:00 \
         action gate index 12 base-time 1357000000000 \
         sched-entry close 200000000 -1 -1 \
         clockid CLOCK_TAI
---
 include/net/tc_act/tc_gate.h        |  54 +++
 include/uapi/linux/pkt_cls.h        |   1 +
 include/uapi/linux/tc_act/tc_gate.h |  47 ++
 net/sched/Kconfig                   |  13 +
 net/sched/Makefile                  |   1 +
 net/sched/act_gate.c                | 647 ++++++++++++++++++++++++++++
 6 files changed, 763 insertions(+)
 create mode 100644 include/net/tc_act/tc_gate.h  create mode 100644
include/uapi/linux/tc_act/tc_gate.h
 create mode 100644 net/sched/act_gate.c
(quoted diff) +0 -0

b/include/net/tc_act/tc_gate.h new file mode 100644 index 000000000000..b0ace55b2aaa

include/net/tc_act/tc_gate.h new file +54 -0
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright 2020 NXP */
+
+#ifndef __NET_TC_GATE_H
+#define __NET_TC_GATE_H
+
+#include <net/act_api.h>
+#include <linux/tc_act/tc_gate.h>
+
+struct tcfg_gate_entry {
+     int                     index;
+     u8                      gate_state;
+     u32                     interval;
+     s32                     ipv;
+     s32                     maxoctets;
+     struct list_head        list;
+};
+
+struct tcf_gate_params {
+     s32                     tcfg_priority;
+     u64                     tcfg_basetime;
+     u64                     tcfg_cycletime;
+     u64                     tcfg_cycletime_ext;
+     u32                     tcfg_flags;
+     s32                     tcfg_clockid;
+     size_t                  num_entries;
+     struct list_head        entries;
+};
+
+#define GATE_ACT_GATE_OPEN   BIT(0)
+#define GATE_ACT_PENDING     BIT(1)
+struct gate_action {
+     struct tcf_gate_params param;
+     spinlock_t entry_lock;
+     u8 current_gate_status;
+     ktime_t current_close_time;
+     u32 current_entry_octets;
+     s32 current_max_octets;
+     struct tcfg_gate_entry __rcu *next_entry;
+     struct hrtimer hitimer;
+     enum tk_offsets tk_offset;
+     struct rcu_head rcu;
+};
+
+struct tcf_gate {
+     struct tc_action                common;
+     struct gate_action __rcu        *actg;
+};
+#define to_gate(a) ((struct tcf_gate *)a)
+
+#define get_gate_param(act) ((struct tcf_gate_params *)act) #define
+get_gate_action(p) ((struct gate_action *)p)
+
+#endif
(quoted diff) +0 -0
Quoted 1 line

b/include/uapi/linux/pkt_cls.h index 9f06d29cab70..fc672b232437

100644

Quoted 36 lines
include/uapi/linux/pkt_cls.h +1 -0
@@ -134,6 +134,7 @@ enum tca_id {
      TCA_ID_CTINFO,
      TCA_ID_MPLS,
      TCA_ID_CT,
+     TCA_ID_GATE,
      /* other actions go here */
      __TCA_ID_MAX = 255
 };
include/uapi/linux/tc_act/tc_gate.h new file +19 -0
new file mode 100644
index 000000000000..f214b3a6d44f
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
+/* Copyright 2020 NXP */
+
+#ifndef __LINUX_TC_GATE_H
+#define __LINUX_TC_GATE_H
+
+#include <linux/pkt_cls.h>
+
+struct tc_gate {
+     tc_gen;
+};
+
+enum {
+     TCA_GATE_ENTRY_UNSPEC,
+     TCA_GATE_ENTRY_INDEX,
+     TCA_GATE_ENTRY_GATE,
+     TCA_GATE_ENTRY_INTERVAL,
+     TCA_GATE_ENTRY_IPV,
+     TCA_GATE_ENTRY_MAX_OCTETS,

include/uapi/linux/tc_act/tc_gate.h line 29

Quoted 10 lines
include/uapi/linux/tc_act/tc_gate.h new file +10 -0
+     __TCA_GATE_ENTRY_MAX,
+};
+#define TCA_GATE_ENTRY_MAX (__TCA_GATE_ENTRY_MAX - 1)
+
+enum {
+     TCA_GATE_ONE_ENTRY_UNSPEC,
+     TCA_GATE_ONE_ENTRY,
+     __TCA_GATE_ONE_ENTRY_MAX,
+};
+#define TCA_GATE_ONE_ENTRY_MAX (__TCA_GATE_ONE_ENTRY_MAX

- 1)

net/sched/Makefile obj-$(CONFIG_NET_IFE_SKBPRIO) +=

Quoted 47 lines
include/uapi/linux/tc_act/tc_gate.h new file +18 -0
+
+enum {
+     TCA_GATE_UNSPEC,
+     TCA_GATE_TM,
+     TCA_GATE_PARMS,
+     TCA_GATE_PAD,
+     TCA_GATE_PRIORITY,
+     TCA_GATE_ENTRY_LIST,
+     TCA_GATE_BASE_TIME,
+     TCA_GATE_CYCLE_TIME,
+     TCA_GATE_CYCLE_TIME_EXT,
+     TCA_GATE_FLAGS,
+     TCA_GATE_CLOCKID,
+     __TCA_GATE_MAX,
+};
+#define TCA_GATE_MAX (__TCA_GATE_MAX - 1)
+
+#endif
net/sched/Kconfig index renamed from net/sched/Kconfig +0 -0

bfbefb7bff9d..1314549c7567 100644

net/sched/Kconfig +13 -0
@@ -981,6 +981,19 @@ config NET_ACT_CT
        To compile this code as a module, choose M here: the
        module will be called act_ct.
 
+config NET_ACT_GATE
+     tristate "Frame gate entry list control tc action"
+     depends on NET_CLS_ACT
+     help
+       Say Y here to allow to control the ingress flow to be passed at
+       specific time slot and be dropped at other specific time slot by
+       the gate entry list. The manipulation will simulate the IEEE
+       802.1Qci stream gate control behavior.
+
+       If unsure, say N.
+       To compile this code as a module, choose M here: the
+       module will be called act_gate.
+
 config NET_IFE_SKBMARK
      tristate "Support to encoding decoding skb mark on IFE action"
      depends on NET_ACT_IFE
net/sched/Makefile index renamed from net/sched/Makefile +0 -0

31c367a6cd09..66bbf9a98f9e 100644

net/sched/Makefile +0 -0
@@ -30,6 +30,7 @@ obj-$(CONFIG_NET_IFE_SKBPRIO)       +=

act_meta_skbprio.o

Quoted 60 lines
net/sched/Makefile +1 -0
 obj-$(CONFIG_NET_IFE_SKBTCINDEX)     += act_meta_skbtcindex.o
 obj-$(CONFIG_NET_ACT_TUNNEL_KEY)+= act_tunnel_key.o
 obj-$(CONFIG_NET_ACT_CT)     += act_ct.o
+obj-$(CONFIG_NET_ACT_GATE)   += act_gate.o
 obj-$(CONFIG_NET_SCH_FIFO)   += sch_fifo.o
 obj-$(CONFIG_NET_SCH_CBQ)    += sch_cbq.o
 obj-$(CONFIG_NET_SCH_HTB)    += sch_htb.o
net/sched/act_gate.c new file mode renamed from net/sched/act_gate.c +0 -0

100644 index 000000000000..e932f402b4f1

net/sched/act_gate.c new file +48 -0
@@ -0,0 +1,647 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright 2020 NXP */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/skbuff.h>
+#include <linux/rtnetlink.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <net/act_api.h>
+#include <net/netlink.h>
+#include <net/pkt_cls.h>
+#include <net/tc_act/tc_gate.h>
+
+static unsigned int gate_net_id;
+static struct tc_action_ops act_gate_ops;
+
+static ktime_t gate_get_time(struct gate_action *gact) {
+     ktime_t mono = ktime_get();
+
+     switch (gact->tk_offset) {
+     case TK_OFFS_MAX:
+             return mono;
+     default:
+             return ktime_mono_to_any(mono, gact->tk_offset);
+     }
+
+     return KTIME_MAX;
+}
+
+static int gate_get_start_time(struct gate_action *gact, ktime_t
+*start) {
+     struct tcf_gate_params *param = get_gate_param(gact);
+     ktime_t now, base, cycle;
+     u64 n;
+
+     base = ns_to_ktime(param->tcfg_basetime);
+     now = gate_get_time(gact);
+
+     if (ktime_after(base, now)) {
+             *start = base;
+             return 0;
+     }
+
+     cycle = param->tcfg_cycletime;
Quoted 8 lines

net/sched/act_gate.c line 53

Quoted 4 lines
net/sched/act_gate.c new file +4 -0
+
+     /* cycle time should not be zero */
+     if (WARN_ON(!cycle))
+             return -EFAULT;

Looking at the init code it seems that this value can be set to 0 directly from netlink packet without further validation, which would allow user to trigger warning here.

Yes, will avoid at ahead point.

Quoted 66 lines
Quoted 24 lines
net/sched/act_gate.c new file +23 -0
+
+     n = div64_u64(ktime_sub_ns(now, base), cycle);
+     *start = ktime_add_ns(base, (n + 1) * cycle);
+     return 0;
+}
+
+static void gate_start_timer(struct gate_action *gact, ktime_t start)
+{
+     ktime_t expires;
+
+     expires = hrtimer_get_expires(&gact->hitimer);
+     if (expires == 0)
+             expires = KTIME_MAX;
+
+     start = min_t(ktime_t, start, expires);
+
+     hrtimer_start(&gact->hitimer, start, HRTIMER_MODE_ABS); }
+
+static enum hrtimer_restart gate_timer_func(struct hrtimer *timer) {
+     struct gate_action *gact = container_of(timer, struct gate_action,
+                                             hitimer);
+     struct tcf_gate_params *p = get_gate_param(gact);
+     struct tcfg_gate_entry *next;

net/sched/act_gate.c

Quoted 10 lines
net/sched/act_gate.c new file +10 -0
+     ktime_t close_time, now;
+
+     spin_lock(&gact->entry_lock);
+
+     next = rcu_dereference_protected(gact->next_entry,
+
+ lockdep_is_held(&gact->entry_lock));
+
+     /* cycle start, clear pending bit, clear total octets */
+     gact->current_gate_status = next->gate_state ?

GATE_ACT_GATE_OPEN : 0;

Quoted 18 lines
net/sched/act_gate.c new file +18 -0
+     gact->current_entry_octets = 0;
+     gact->current_max_octets = next->maxoctets;
+
+     gact->current_close_time = ktime_add_ns(gact->current_close_time,
+                                             next->interval);
+
+     close_time = gact->current_close_time;
+
+     if (list_is_last(&next->list, &p->entries))
+             next = list_first_entry(&p->entries,
+                                     struct tcfg_gate_entry, list);
+     else
+             next = list_next_entry(next, list);
+
+     now = gate_get_time(gact);
+
+     if (ktime_after(now, close_time)) {
+             ktime_t cycle, base;

net/sched/act_gate.c line 115

Quoted 10 lines
net/sched/act_gate.c new file +10 -0
+             u64 n;
+
+             cycle = p->tcfg_cycletime;
+             base = ns_to_ktime(p->tcfg_basetime);
+             n = div64_u64(ktime_sub_ns(now, base), cycle);
+             close_time = ktime_add_ns(base, (n + 1) * cycle);
+     }
+
+     rcu_assign_pointer(gact->next_entry, next);
+     spin_unlock(&gact->entry_lock);

I have couple of question about synchronization here:

Quoted 7 lines

- Why do you need next_entry to be rcu pointer? It is only assigned here with entry_lock protection and in init code before action is visible to concurrent users. I don't see any unlocked rcu-protected readers here that could benefit from it.

- Why create dedicated entry_lock instead of using already existing per- action tcf_lock?

Will try to use the tcf_lock for verification.
The thoughts came from that the timer period arrived then check through the list and then update next time would take much more time. Action function would be busy when traffic. So use a separate lock here for

Quoted 13 lines
Quoted 13 lines
net/sched/act_gate.c new file +12 -0
+
+     hrtimer_set_expires(&gact->hitimer, close_time);
+
+     return HRTIMER_RESTART;
+}
+
+static int tcf_gate_act(struct sk_buff *skb, const struct tc_action *a,
+                     struct tcf_result *res) {
+     struct tcf_gate *g = to_gate(a);
+     struct gate_action *gact;
+     int action;
+
Quoted 8 lines

net/sched/act_gate.c line 133

Quoted 5 lines
net/sched/act_gate.c new file +5 -0
+     tcf_lastuse_update(&g->tcf_tm);
+     bstats_cpu_update(this_cpu_ptr(g->common.cpu_bstats), skb);
+
+     action = READ_ONCE(g->tcf_action);
+     rcu_read_lock();

Action fastpath is already rcu read lock protected, you don't need to manually obtain it.

Will be removed.

Quoted 6 lines

net/sched/act_gate.c line 135

Quoted 3 lines
net/sched/act_gate.c new file +2 -0
+     gact = rcu_dereference_bh(g->actg);
+     if (unlikely(gact->current_gate_status & GATE_ACT_PENDING)) {

Can't current_gate_status be concurrently modified by timer callback? This function doesn't use entry_lock to synchronize with timer.

Will try tcf_lock either.

Quoted 18 lines

net/sched/act_gate.c line 140

Quoted 6 lines
net/sched/act_gate.c new file +5 -0
+             rcu_read_unlock();
+             return action;
+     }
+
+     if (!(gact->current_gate_status & GATE_ACT_GATE_OPEN))

...and here

net/sched/act_gate.c

Quoted 6 lines
net/sched/act_gate.c new file +6 -0
+             goto drop;
+
+     if (gact->current_max_octets >= 0) {
+             gact->current_entry_octets += qdisc_pkt_len(skb);
+             if (gact->current_entry_octets >
+ gact->current_max_octets) {

here also.

Quoted 8 lines
Quoted 6 lines

net/sched/act_gate.c line 146

Quoted 2 lines
net/sched/act_gate.c new file +2 -0
+
+ qstats_overlimit_inc(this_cpu_ptr(g->common.cpu_qstats));

Please use tcf_action_inc_overlimit_qstats() and other wrappers for stats. Otherwise it will crash if user passes TCA_ACT_FLAGS_NO_PERCPU_STATS flag.

The tcf_action_inc_overlimit_qstats() can't show limit counts in tc show command. Is there anything need to do?

What do you mean? Internally tcf_action_inc_overlimit_qstats() just calls qstats_overlimit_inc, if cpu_qstats percpu counter is not NULL:

	if (likely(a->cpu_qstats)) {
		qstats_overlimit_inc(this_cpu_ptr(a->cpu_qstats));
		return;
	}

Is there a subtle bug somewhere in this function?

Quoted 499 lines
Quoted 281 lines
Quoted 5 lines
net/sched/act_gate.c new file +3 -0
+                     goto drop;
+             }
+     }

net/sched/act_gate.c

Quoted 10 lines
net/sched/act_gate.c new file +10 -0
+     rcu_read_unlock();
+
+     return action;
+drop:
+     rcu_read_unlock();
+     qstats_drop_inc(this_cpu_ptr(g->common.cpu_qstats));
+     return TC_ACT_SHOT;
+}
+
+static const struct nla_policy entry_policy[TCA_GATE_ENTRY_MAX + 1]

= {

Quoted 32 lines
net/sched/act_gate.c new file +32 -0
+     [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),
+                                         .type = NLA_EXACT_LEN },
+     [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;
+
+     entry->gate_state = nla_get_flag(tb[TCA_GATE_ENTRY_GATE]);
+
+     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;
+     }

net/sched/act_gate.c

Quoted 10 lines
net/sched/act_gate.c new file +10 -0
+
+     entry->interval = interval;
+
+     if (tb[TCA_GATE_ENTRY_IPV])
+             entry->ipv = nla_get_s32(tb[TCA_GATE_ENTRY_IPV]);
+     else
+             entry->ipv = -1;
+
+     if (tb[TCA_GATE_ENTRY_MAX_OCTETS])
+             entry->maxoctets =

nla_get_s32(tb[TCA_GATE_ENTRY_MAX_OCTETS]);

net/sched/act_gate.c

Quoted 7 lines
net/sched/act_gate.c new file +7 -0
+     else
+             entry->maxoctets = -1;
+
+     return 0;
+}
+
+static int parse_gate_entry(struct nlattr *n, struct  tcfg_gate_entry

*entry,

net/sched/act_gate.c

Quoted 5 lines
net/sched/act_gate.c new file +4 -0
+                         int index, struct netlink_ext_ack *extack) {
+     struct nlattr *tb[TCA_GATE_ENTRY_MAX + 1] = { };
+     int err;
 
+     err = nla_parse_nested(tb, TCA_GATE_ENTRY_MAX, n, entry_policy,

extack);

Quoted 208 lines
net/sched/act_gate.c new file +208 -0
+     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); }
+
+static int parse_gate_list(struct nlattr *list_attr,
+                        struct tcf_gate_params *sched,
+                        struct netlink_ext_ack *extack) {
+     struct tcfg_gate_entry *entry, *e;
+     struct nlattr *n;
+     int err, rem;
+     int i = 0;
+
+     if (!list_attr)
+             return -EINVAL;
+
+     nla_for_each_nested(n, list_attr, rem) {
+             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");
+                     err = -ENOMEM;
+                     goto release_list;
+             }
+
+             err = parse_gate_entry(n, entry, i, extack);
+             if (err < 0) {
+                     kfree(entry);
+                     goto release_list;
+             }
+
+             list_add_tail(&entry->list, &sched->entries);
+             i++;
+     }
+
+     sched->num_entries = i;
+
+     return i;
+
+release_list:
+     list_for_each_entry_safe(entry, e, &sched->entries, list) {
+             list_del(&entry->list);
+             kfree(entry);
+     }
+
+     return err;
+}
+
+static int tcf_gate_init(struct net *net, struct nlattr *nla,
+                      struct nlattr *est, struct tc_action **a,
+                      int ovr, int bind, bool rtnl_held,
+                      struct tcf_proto *tp, u32 flags,
+                      struct netlink_ext_ack *extack) {
+     struct tc_action_net *tn = net_generic(net, gate_net_id);
+     enum tk_offsets tk_offset = TK_OFFS_TAI;
+     struct nlattr *tb[TCA_GATE_MAX + 1];
+     struct tcf_chain *goto_ch = NULL;
+     struct tcfg_gate_entry *next;
+     struct tcf_gate_params *p;
+     struct gate_action *gact;
+     s32 clockid = CLOCK_TAI;
+     struct tc_gate *parm;
+     struct tcf_gate *g;
+     int ret = 0, err;
+     u64 basetime = 0;
+     u32 gflags = 0;
+     s32 prio = -1;
+     ktime_t start;
+     u32 index;
+
+     if (!nla)
+             return -EINVAL;
+
+     err = nla_parse_nested(tb, TCA_GATE_MAX, nla, gate_policy, extack);
+     if (err < 0)
+             return err;
+
+     if (!tb[TCA_GATE_PARMS])
+             return -EINVAL;
+     parm = nla_data(tb[TCA_GATE_PARMS]);
+     index = parm->index;
+     err = tcf_idr_check_alloc(tn, &index, a, bind);
+     if (err < 0)
+             return err;
+
+     if (err && bind)
+             return 0;
+
+     if (!err) {
+             ret = tcf_idr_create_from_flags(tn, index, est, a,
+                                             &act_gate_ops, bind, flags);
+             if (ret) {
+                     tcf_idr_cleanup(tn, index);
+                     return ret;
+             }
+
+             ret = ACT_P_CREATED;
+     } else if (!ovr) {
+             tcf_idr_release(*a, bind);
+             return -EEXIST;
+     }
+
+     if (tb[TCA_GATE_PRIORITY])
+             prio = nla_get_s32(tb[TCA_GATE_PRIORITY]);
+
+     if (tb[TCA_GATE_BASE_TIME])
+             basetime = nla_get_u64(tb[TCA_GATE_BASE_TIME]);
+
+     if (tb[TCA_GATE_FLAGS])
+             gflags = nla_get_u32(tb[TCA_GATE_FLAGS]);
+
+     if (tb[TCA_GATE_CLOCKID]) {
+             clockid = nla_get_s32(tb[TCA_GATE_CLOCKID]);
+             switch (clockid) {
+             case CLOCK_REALTIME:
+                     tk_offset = TK_OFFS_REAL;
+                     break;
+             case CLOCK_MONOTONIC:
+                     tk_offset = TK_OFFS_MAX;
+                     break;
+             case CLOCK_BOOTTIME:
+                     tk_offset = TK_OFFS_BOOT;
+                     break;
+             case CLOCK_TAI:
+                     tk_offset = TK_OFFS_TAI;
+                     break;
+             default:
+                     NL_SET_ERR_MSG(extack, "Invalid 'clockid'");
+                     goto release_idr;
+             }
+     }
+
+     err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack);
+     if (err < 0)
+             goto release_idr;
+
+     g = to_gate(*a);
+
+     gact = kzalloc(sizeof(*gact), GFP_KERNEL);
+     if (!gact) {
+             err = -ENOMEM;
+             goto put_chain;
+     }
+
+     p = get_gate_param(gact);
+
+     INIT_LIST_HEAD(&p->entries);
+     if (tb[TCA_GATE_ENTRY_LIST]) {
+             err = parse_gate_list(tb[TCA_GATE_ENTRY_LIST], p, extack);
+             if (err < 0)
+                     goto release_mem;
+     }
+
+     if (tb[TCA_GATE_CYCLE_TIME]) {
+             p->tcfg_cycletime = nla_get_u64(tb[TCA_GATE_CYCLE_TIME]);
+     } else {
+             struct tcfg_gate_entry *entry;
+             ktime_t cycle = 0;
+
+             list_for_each_entry(entry, &p->entries, list)
+                     cycle = ktime_add_ns(cycle, entry->interval);
+             p->tcfg_cycletime = cycle;
+     }
+
+     if (tb[TCA_GATE_CYCLE_TIME_EXT])
+             p->tcfg_cycletime_ext =
+                     nla_get_u64(tb[TCA_GATE_CYCLE_TIME_EXT]);
+
+     p->tcfg_priority = prio;
+     p->tcfg_basetime = basetime;
+     p->tcfg_clockid = clockid;
+     p->tcfg_flags = gflags;
+
+     gact->tk_offset = tk_offset;
+     spin_lock_init(&gact->entry_lock);
+     hrtimer_init(&gact->hitimer, clockid, HRTIMER_MODE_ABS);
+     gact->hitimer.function = gate_timer_func;
+
+     err = gate_get_start_time(gact, &start);
+     if (err < 0) {
+             NL_SET_ERR_MSG(extack,
+                            "Internal error: failed get start time");
+             goto release_mem;
+     }
+
+     gact->current_close_time = start;
+     gact->current_gate_status = GATE_ACT_GATE_OPEN |
+ GATE_ACT_PENDING;
+
+     next = list_first_entry(&p->entries, struct tcfg_gate_entry, list);
+     rcu_assign_pointer(gact->next_entry, next);
+
+     gate_start_timer(gact, start);
+
+     spin_lock_bh(&g->tcf_lock);
+     goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
+     gact = rcu_replace_pointer(g->actg, gact,
+                                lockdep_is_held(&g->tcf_lock));
+     spin_unlock_bh(&g->tcf_lock);
+
Quoted 9 lines

net/sched/act_gate.c line 429

Quoted 4 lines
net/sched/act_gate.c new file +4 -0
+     if (goto_ch)
+             tcf_chain_put_by_act(goto_ch);
+     if (gact)
+             kfree_rcu(gact, rcu);

This leaks entries. For example, tunnel key action implements tunnel_key_release_params() helper that is used by both init and release code. I guess that would be the best approach here as well.

Will refer the tunnel action. Thanks for pointing out.

Quoted 193 lines
Quoted 136 lines
net/sched/act_gate.c new file +54 -0
+
+     if (ret == ACT_P_CREATED)
+             tcf_idr_insert(tn, *a);
+     return ret;
+
+release_mem:
+     kfree(gact);
+put_chain:
+     if (goto_ch)
+             tcf_chain_put_by_act(goto_ch);
+release_idr:
+     tcf_idr_release(*a, bind);
+     return err;
+}
+
+static void tcf_gate_cleanup(struct tc_action *a) {
+     struct tcf_gate *g = to_gate(a);
+     struct tcfg_gate_entry *entry, *n;
+     struct tcf_gate_params *p;
+     struct gate_action *gact;
+
+     spin_lock_bh(&g->tcf_lock);
+     gact = rcu_dereference_protected(g->actg,
+                                      lockdep_is_held(&g->tcf_lock));
+     hrtimer_cancel(&gact->hitimer);
+
+     p = get_gate_param(gact);
+     list_for_each_entry_safe(entry, n, &p->entries, list) {
+             list_del(&entry->list);
+             kfree(entry);
+     }
+     spin_unlock_bh(&g->tcf_lock);
+
+     kfree_rcu(gact, rcu);
+}
+
+static int dumping_entry(struct sk_buff *skb,
+                      struct tcfg_gate_entry *entry) {
+     struct nlattr *item;
+
+     item = nla_nest_start_noflag(skb, TCA_GATE_ONE_ENTRY);
+     if (!item)
+             return -ENOSPC;
+
+     if (nla_put_u32(skb, TCA_GATE_ENTRY_INDEX, entry->index))
+             goto nla_put_failure;
+
+     if (entry->gate_state && nla_put_flag(skb, TCA_GATE_ENTRY_GATE))
+             goto nla_put_failure;
+
+     if (nla_put_u32(skb, TCA_GATE_ENTRY_INTERVAL, entry->interval))
+             goto nla_put_failure;
+
+     if (nla_put_s32(skb, TCA_GATE_ENTRY_MAX_OCTETS, entry-

maxoctets))

net/sched/act_gate.c new file +81 -0
+             goto nla_put_failure;
+
+     if (nla_put_s32(skb, TCA_GATE_ENTRY_IPV, entry->ipv))
+             goto nla_put_failure;
+
+     return nla_nest_end(skb, item);
+
+nla_put_failure:
+     nla_nest_cancel(skb, item);
+     return -1;
+}
+
+static int tcf_gate_dump(struct sk_buff *skb, struct tc_action *a,
+                      int bind, int ref) {
+     unsigned char *b = skb_tail_pointer(skb);
+     struct tcf_gate *g = to_gate(a);
+     struct tc_gate opt = {
+             .index    = g->tcf_index,
+             .refcnt   = refcount_read(&g->tcf_refcnt) - ref,
+             .bindcnt  = atomic_read(&g->tcf_bindcnt) - bind,
+     };
+     struct tcfg_gate_entry *entry;
+     struct gate_action *gact;
+     struct tcf_gate_params *p;
+     struct nlattr *entry_list;
+     struct tcf_t t;
+
+     spin_lock_bh(&g->tcf_lock);
+     opt.action = g->tcf_action;
+     gact = rcu_dereference_protected(g->actg,
+                                      lockdep_is_held(&g->tcf_lock));
+
+     p = get_gate_param(gact);
+
+     if (nla_put(skb, TCA_GATE_PARMS, sizeof(opt), &opt))
+             goto nla_put_failure;
+
+     if (nla_put_u64_64bit(skb, TCA_GATE_BASE_TIME,
+                           p->tcfg_basetime, TCA_GATE_PAD))
+             goto nla_put_failure;
+
+     if (nla_put_u64_64bit(skb, TCA_GATE_CYCLE_TIME,
+                           p->tcfg_cycletime, TCA_GATE_PAD))
+             goto nla_put_failure;
+
+     if (nla_put_u64_64bit(skb, TCA_GATE_CYCLE_TIME_EXT,
+                           p->tcfg_cycletime_ext, TCA_GATE_PAD))
+             goto nla_put_failure;
+
+     if (nla_put_s32(skb, TCA_GATE_CLOCKID, p->tcfg_clockid))
+             goto nla_put_failure;
+
+     if (nla_put_u32(skb, TCA_GATE_FLAGS, p->tcfg_flags))
+             goto nla_put_failure;
+
+     if (nla_put_s32(skb, TCA_GATE_PRIORITY, p->tcfg_priority))
+             goto nla_put_failure;
+
+     entry_list = nla_nest_start_noflag(skb, TCA_GATE_ENTRY_LIST);
+     if (!entry_list)
+             goto nla_put_failure;
+
+     list_for_each_entry(entry, &p->entries, list) {
+             if (dumping_entry(skb, entry) < 0)
+                     goto nla_put_failure;
+     }
+
+     nla_nest_end(skb, entry_list);
+
+     tcf_tm_dump(&t, &g->tcf_tm);
+     if (nla_put_64bit(skb, TCA_GATE_TM, sizeof(t), &t, TCA_GATE_PAD))
+             goto nla_put_failure;
+     spin_unlock_bh(&g->tcf_lock);
+
+     return skb->len;
+
+nla_put_failure:
+     spin_unlock_bh(&g->tcf_lock);
+     nlmsg_trim(skb, b);
+     return -1;
+}

net/sched/act_gate.c

Quoted 10 lines
net/sched/act_gate.c new file +10 -0
+
+static int tcf_gate_walker(struct net *net, struct sk_buff *skb,
+                        struct netlink_callback *cb, int type,
+                        const struct tc_action_ops *ops,
+                        struct netlink_ext_ack *extack) {
+     struct tc_action_net *tn = net_generic(net, gate_net_id);
+
+     return tcf_generic_walker(tn, skb, cb, type, ops, extack); }
+
+static void tcf_gate_stats_update(struct tc_action *a, u64 bytes, u32

packets,

Quoted 46 lines
net/sched/act_gate.c new file +46 -0
+                               u64 lastuse, bool hw) {
+     struct tcf_gate *g = to_gate(a);
+     struct tcf_t *tm = &g->tcf_tm;
+
+     tcf_action_update_stats(a, bytes, packets, false, hw);
+     tm->lastuse = max_t(u64, tm->lastuse, lastuse); }
+
+static int tcf_gate_search(struct net *net, struct tc_action **a, u32
+index) {
+     struct tc_action_net *tn = net_generic(net, gate_net_id);
+
+     return tcf_idr_search(tn, a, index); }
+
+static size_t tcf_gate_get_fill_size(const struct tc_action *act) {
+     return nla_total_size(sizeof(struct tc_gate)); }
+
+static struct tc_action_ops act_gate_ops = {
+     .kind           =       "gate",
+     .id             =       TCA_ID_GATE,
+     .owner          =       THIS_MODULE,
+     .act            =       tcf_gate_act,
+     .dump           =       tcf_gate_dump,
+     .init           =       tcf_gate_init,
+     .cleanup        =       tcf_gate_cleanup,
+     .walk           =       tcf_gate_walker,
+     .stats_update   =       tcf_gate_stats_update,
+     .get_fill_size  =       tcf_gate_get_fill_size,
+     .lookup         =       tcf_gate_search,
+     .size           =       sizeof(struct gate_action),
+};
+
+static __net_init int gate_init_net(struct net *net) {
+     struct tc_action_net *tn = net_generic(net, gate_net_id);
+
+     return tc_action_net_init(net, tn, &act_gate_ops); }
+
+static void __net_exit gate_exit_net(struct list_head *net_list) {
+     tc_action_net_exit(net_list, gate_net_id); }
+
+static struct pernet_operations gate_net_ops = {
+     .init = gate_init_net,
+     .exit_batch = gate_exit_net,
+     .id   = &gate_net_id,
+     .size = sizeof(struct tc_action_net), };
+
+static int __init gate_init_module(void) {
Quoted 8 lines

net/sched/act_gate.c line 647

Quoted 8 lines
net/sched/act_gate.c new file +8 -0
+     return tcf_register_action(&act_gate_ops, &gate_net_ops); }
+
+static void __exit gate_cleanup_module(void) {
+     tcf_unregister_action(&act_gate_ops, &gate_net_ops); }
+
+module_init(gate_init_module);
+module_exit(gate_cleanup_module);
+MODULE_LICENSE("GPL v2");

Thanks a lot.

Br,
Po Liu

author
#76 lore raw

RE: [EXT] Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

Quoted 507 lines

-----Original Message-----
From: Vlad Buslov <[email protected]>
Sent: 2020年4月23日 15:43
To: Po Liu <[email protected]>
Cc: Vlad Buslov <[email protected]>; [email protected]; linux- [email protected]; [email protected]; [email protected]; Claudiu Manoil <[email protected]>; Vladimir Oltean <[email protected]>; Alexandru Marginean <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [EXT] Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

Caution: EXT Email

Quoted 9 lines · Po Liu

Hi Vlad Buslov,

Quoted 7 lines

-----Original Message-----
From: Vlad Buslov <[email protected]>
Sent: 2020年4月22日 21:23
To: Po Liu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Claudiu Manoil <[email protected]>; Vladimir Oltean

<[email protected]>;

Quoted 2 lines
Quoted 2 lines

Alexandru Marginean <[email protected]>; [email protected]; [email protected];

[email protected];

Quoted 4 lines
Quoted 4 lines

[email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected];

[email protected];

Quoted 10 lines
Quoted 10 lines

[email protected]; [email protected]; [email protected]
Subject: [EXT] Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

Caution: EXT Email

Hi Po,

On Wed 22 Apr 2020 at 05:48, Po Liu <[email protected]> wrote:

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Introduce a ingress frame gate control flow action.
Tc gate action does the work like this:
Assume there is a gate allow specified ingress frames can be passed at specific time slot, and be dropped at specific time slot. Tc filter chooses the ingress frames, and tc gate action would specify what slot does these frames can be passed to device and what time slot would be dropped.
Tc gate action would provide an entry list to tell how much time gate keep open and how much time gate keep state close. Gate

action

Quoted 50 lines
Quoted 50 lines
Quoted 31 lines

also assign a start time to tell when the entry list start. Then driver would repeat the gate entry list cyclically.
For the software simulation, gate action requires the user assign a time clock type.

Below is the setting example in user space. Tc filter a stream source ip address is 192.168.0.20 and gate action own two time slots. One is last 200ms gate open let frame pass another is last 100ms gate close let frames dropped. When the frames have passed total frames over
8000000 bytes, frames will be dropped in one 200000000ns time slot.

Quoted 3 lines

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 clockid CLOCK_TAI \
         sched-entry open 200000000 -1 8000000 \
         sched-entry close 100000000 -1 -1
Quoted 1 line

tc chain del dev eth0 ingress chain 0

"sched-entry" follow the name taprio style. Gate state is "open"/"close". Follow with period nanosecond. Then next item 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.
Base-time is not set will be 0 as default, as result start time would be ((N + 1) * cycletime) which is the minimal of future time.

Quoted 5 lines

Below example shows filtering a stream with destination mac address is
10:00:80:00:00:00 and ip type is ICMP, follow the action gate. The gate action would run with one close time slot which means always keep

close.

Quoted 13 lines

The time cycle is total 200000000ns. The base-time would calculate by:

1357000000000 + (N + 1) * cycletime

When the total value is the future time, it will be the start time. The cycletime here would be 200000000ns for this case.

Quoted 1 line

tc filter add dev eth0 parent ffff: protocol ip \

         flower skip_hw ip_proto icmp dst_mac 10:00:80:00:00:00 \
         action gate index 12 base-time 1357000000000 \
         sched-entry close 200000000 -1 -1 \
         clockid CLOCK_TAI
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
---
 include/net/tc_act/tc_gate.h        |  54 +++
 include/uapi/linux/pkt_cls.h        |   1 +
 include/uapi/linux/tc_act/tc_gate.h |  47 ++
 net/sched/Kconfig                   |  13 +
 net/sched/Makefile                  |   1 +
 net/sched/act_gate.c                | 647

++++++++++++++++++++++++++++

Quoted 107 lines
Quoted 107 lines
Quoted 67 lines
 6 files changed, 763 insertions(+)  create mode 100644
include/net/tc_act/tc_gate.h  create mode 100644
include/uapi/linux/tc_act/tc_gate.h
 create mode 100644 net/sched/act_gate.c
(quoted diff) +0 -0

b/include/net/tc_act/tc_gate.h new file mode 100644 index 000000000000..b0ace55b2aaa

include/net/tc_act/tc_gate.h new file +55 -0
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright 2020 NXP */
+
+#ifndef __NET_TC_GATE_H
+#define __NET_TC_GATE_H
+
+#include <net/act_api.h>
+#include <linux/tc_act/tc_gate.h>
+
+struct tcfg_gate_entry {
+     int                     index;
+     u8                      gate_state;
+     u32                     interval;
+     s32                     ipv;
+     s32                     maxoctets;
+     struct list_head        list;
+};
+
+struct tcf_gate_params {
+     s32                     tcfg_priority;
+     u64                     tcfg_basetime;
+     u64                     tcfg_cycletime;
+     u64                     tcfg_cycletime_ext;
+     u32                     tcfg_flags;
+     s32                     tcfg_clockid;
+     size_t                  num_entries;
+     struct list_head        entries;
+};
+
+#define GATE_ACT_GATE_OPEN   BIT(0)
+#define GATE_ACT_PENDING     BIT(1)
+struct gate_action {
+     struct tcf_gate_params param;
+     spinlock_t entry_lock;
+     u8 current_gate_status;
+     ktime_t current_close_time;
+     u32 current_entry_octets;
+     s32 current_max_octets;
+     struct tcfg_gate_entry __rcu *next_entry;
+     struct hrtimer hitimer;
+     enum tk_offsets tk_offset;
+     struct rcu_head rcu;
+};
+
+struct tcf_gate {
+     struct tc_action                common;
+     struct gate_action __rcu        *actg;
+};
+#define to_gate(a) ((struct tcf_gate *)a)
+
+#define get_gate_param(act) ((struct tcf_gate_params *)act)
+#define
+get_gate_action(p) ((struct gate_action *)p)
+
+#endif
(quoted diff) +0 -0
Quoted 1 line

b/include/uapi/linux/pkt_cls.h index 9f06d29cab70..fc672b232437

100644

Quoted 38 lines
include/uapi/linux/pkt_cls.h +1 -0
@@ -134,6 +134,7 @@ enum tca_id {
      TCA_ID_CTINFO,
      TCA_ID_MPLS,
      TCA_ID_CT,
+     TCA_ID_GATE,
      /* other actions go here */
      __TCA_ID_MAX = 255
 };
include/uapi/linux/tc_act/tc_gate.h new file +21 -0
new file mode 100644
index 000000000000..f214b3a6d44f
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
+/* Copyright 2020 NXP */
+
+#ifndef __LINUX_TC_GATE_H
+#define __LINUX_TC_GATE_H
+
+#include <linux/pkt_cls.h>
+
+struct tc_gate {
+     tc_gen;
+};
+
+enum {
+     TCA_GATE_ENTRY_UNSPEC,
+     TCA_GATE_ENTRY_INDEX,
+     TCA_GATE_ENTRY_GATE,
+     TCA_GATE_ENTRY_INTERVAL,
+     TCA_GATE_ENTRY_IPV,
+     TCA_GATE_ENTRY_MAX_OCTETS,
+     __TCA_GATE_ENTRY_MAX,
+};
Quoted 8 lines
Quoted 8 lines

include/uapi/linux/tc_act/tc_gate.h

Quoted 8 lines
include/uapi/linux/tc_act/tc_gate.h new file +8 -0
+#define TCA_GATE_ENTRY_MAX (__TCA_GATE_ENTRY_MAX - 1)
+
+enum {
+     TCA_GATE_ONE_ENTRY_UNSPEC,
+     TCA_GATE_ONE_ENTRY,
+     __TCA_GATE_ONE_ENTRY_MAX,
+};
+#define TCA_GATE_ONE_ENTRY_MAX

(__TCA_GATE_ONE_ENTRY_MAX

Quoted 227 lines
Quoted 110 lines

- 1)

net/sched/Makefile obj-$(CONFIG_NET_IFE_SKBPRIO) +=

Quoted 47 lines
include/uapi/linux/tc_act/tc_gate.h new file +18 -0
+
+enum {
+     TCA_GATE_UNSPEC,
+     TCA_GATE_TM,
+     TCA_GATE_PARMS,
+     TCA_GATE_PAD,
+     TCA_GATE_PRIORITY,
+     TCA_GATE_ENTRY_LIST,
+     TCA_GATE_BASE_TIME,
+     TCA_GATE_CYCLE_TIME,
+     TCA_GATE_CYCLE_TIME_EXT,
+     TCA_GATE_FLAGS,
+     TCA_GATE_CLOCKID,
+     __TCA_GATE_MAX,
+};
+#define TCA_GATE_MAX (__TCA_GATE_MAX - 1)
+
+#endif
net/sched/Kconfig index renamed from net/sched/Kconfig +0 -0

bfbefb7bff9d..1314549c7567 100644

net/sched/Kconfig +13 -0
@@ -981,6 +981,19 @@ config NET_ACT_CT
        To compile this code as a module, choose M here: the
        module will be called act_ct.
 
+config NET_ACT_GATE
+     tristate "Frame gate entry list control tc action"
+     depends on NET_CLS_ACT
+     help
+       Say Y here to allow to control the ingress flow to be passed at
+       specific time slot and be dropped at other specific time slot by
+       the gate entry list. The manipulation will simulate the IEEE
+       802.1Qci stream gate control behavior.
+
+       If unsure, say N.
+       To compile this code as a module, choose M here: the
+       module will be called act_gate.
+
 config NET_IFE_SKBMARK
      tristate "Support to encoding decoding skb mark on IFE action"
      depends on NET_ACT_IFE
net/sched/Makefile index renamed from net/sched/Makefile +0 -0

31c367a6cd09..66bbf9a98f9e 100644

net/sched/Makefile +0 -0
@@ -30,6 +30,7 @@ obj-$(CONFIG_NET_IFE_SKBPRIO)       +=

act_meta_skbprio.o

Quoted 61 lines
net/sched/Makefile +1 -0
 obj-$(CONFIG_NET_IFE_SKBTCINDEX)     += act_meta_skbtcindex.o
 obj-$(CONFIG_NET_ACT_TUNNEL_KEY)+= act_tunnel_key.o
 obj-$(CONFIG_NET_ACT_CT)     += act_ct.o
+obj-$(CONFIG_NET_ACT_GATE)   += act_gate.o
 obj-$(CONFIG_NET_SCH_FIFO)   += sch_fifo.o
 obj-$(CONFIG_NET_SCH_CBQ)    += sch_cbq.o
 obj-$(CONFIG_NET_SCH_HTB)    += sch_htb.o
net/sched/act_gate.c new file renamed from net/sched/act_gate.c +0 -0

mode
100644 index 000000000000..e932f402b4f1

net/sched/act_gate.c new file +48 -0
@@ -0,0 +1,647 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright 2020 NXP */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/skbuff.h>
+#include <linux/rtnetlink.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <net/act_api.h>
+#include <net/netlink.h>
+#include <net/pkt_cls.h>
+#include <net/tc_act/tc_gate.h>
+
+static unsigned int gate_net_id;
+static struct tc_action_ops act_gate_ops;
+
+static ktime_t gate_get_time(struct gate_action *gact) {
+     ktime_t mono = ktime_get();
+
+     switch (gact->tk_offset) {
+     case TK_OFFS_MAX:
+             return mono;
+     default:
+             return ktime_mono_to_any(mono, gact->tk_offset);
+     }
+
+     return KTIME_MAX;
+}
+
+static int gate_get_start_time(struct gate_action *gact, ktime_t
+*start) {
+     struct tcf_gate_params *param = get_gate_param(gact);
+     ktime_t now, base, cycle;
+     u64 n;
+
+     base = ns_to_ktime(param->tcfg_basetime);
+     now = gate_get_time(gact);
+
+     if (ktime_after(base, now)) {
+             *start = base;
+             return 0;
+     }
+
+     cycle = param->tcfg_cycletime;
Quoted 8 lines

net/sched/act_gate.c line 53

Quoted 4 lines
net/sched/act_gate.c new file +4 -0
+
+     /* cycle time should not be zero */
+     if (WARN_ON(!cycle))
+             return -EFAULT;

Looking at the init code it seems that this value can be set to 0 directly from netlink packet without further validation, which would allow user to trigger warning here.

Yes, will avoid at ahead point.

Quoted 27 lines
Quoted 27 lines
net/sched/act_gate.c new file +26 -0
+
+     n = div64_u64(ktime_sub_ns(now, base), cycle);
+     *start = ktime_add_ns(base, (n + 1) * cycle);
+     return 0;
+}
+
+static void gate_start_timer(struct gate_action *gact, ktime_t
+start) {
+     ktime_t expires;
+
+     expires = hrtimer_get_expires(&gact->hitimer);
+     if (expires == 0)
+             expires = KTIME_MAX;
+
+     start = min_t(ktime_t, start, expires);
+
+     hrtimer_start(&gact->hitimer, start, HRTIMER_MODE_ABS); }
+
+static enum hrtimer_restart gate_timer_func(struct hrtimer *timer) {
+     struct gate_action *gact = container_of(timer, struct gate_action,
+                                             hitimer);
+     struct tcf_gate_params *p = get_gate_param(gact);
+     struct tcfg_gate_entry *next;
+     ktime_t close_time, now;
+
+     spin_lock(&gact->entry_lock);
Quoted 12 lines

net/sched/act_gate.c

Quoted 7 lines
net/sched/act_gate.c new file +7 -0
+
+     next = rcu_dereference_protected(gact->next_entry,
+
+ lockdep_is_held(&gact->entry_lock));
+
+     /* cycle start, clear pending bit, clear total octets */
+     gact->current_gate_status = next->gate_state ?

GATE_ACT_GATE_OPEN : 0;

Quoted 4 lines
net/sched/act_gate.c new file +4 -0
+     gact->current_entry_octets = 0;
+     gact->current_max_octets = next->maxoctets;
+
+     gact->current_close_time = ktime_add_ns(gact-

current_close_time,

Quoted 27 lines
Quoted 14 lines
net/sched/act_gate.c new file +14 -0
+                                             next->interval);
+
+     close_time = gact->current_close_time;
+
+     if (list_is_last(&next->list, &p->entries))
+             next = list_first_entry(&p->entries,
+                                     struct tcfg_gate_entry, list);
+     else
+             next = list_next_entry(next, list);
+
+     now = gate_get_time(gact);
+
+     if (ktime_after(now, close_time)) {
+             ktime_t cycle, base;

net/sched/act_gate.c line 115

Quoted 10 lines
net/sched/act_gate.c new file +10 -0
+             u64 n;
+
+             cycle = p->tcfg_cycletime;
+             base = ns_to_ktime(p->tcfg_basetime);
+             n = div64_u64(ktime_sub_ns(now, base), cycle);
+             close_time = ktime_add_ns(base, (n + 1) * cycle);
+     }
+
+     rcu_assign_pointer(gact->next_entry, next);
+     spin_unlock(&gact->entry_lock);

I have couple of question about synchronization here:

Quoted 7 lines

- Why do you need next_entry to be rcu pointer? It is only assigned here with entry_lock protection and in init code before action is visible to concurrent users. I don't see any unlocked rcu-protected readers here that could benefit from it.

- Why create dedicated entry_lock instead of using already existing per- action tcf_lock?

Will try to use the tcf_lock for verification.
The thoughts came from that the timer period arrived then check through the list and then update next time would take much more time. Action function would be busy when traffic. So use a separate lock here for

Quoted 13 lines
Quoted 13 lines
net/sched/act_gate.c new file +12 -0
+
+     hrtimer_set_expires(&gact->hitimer, close_time);
+
+     return HRTIMER_RESTART;
+}
+
+static int tcf_gate_act(struct sk_buff *skb, const struct tc_action *a,
+                     struct tcf_result *res) {
+     struct tcf_gate *g = to_gate(a);
+     struct gate_action *gact;
+     int action;
+
Quoted 8 lines

net/sched/act_gate.c line 133

Quoted 5 lines
net/sched/act_gate.c new file +5 -0
+     tcf_lastuse_update(&g->tcf_tm);
+     bstats_cpu_update(this_cpu_ptr(g->common.cpu_bstats), skb);
+
+     action = READ_ONCE(g->tcf_action);
+     rcu_read_lock();

Action fastpath is already rcu read lock protected, you don't need to manually obtain it.

Will be removed.

Quoted 1 line
Quoted 30 lines
Quoted 5 lines

net/sched/act_gate.c line 135

Quoted 2 lines
net/sched/act_gate.c new file +2 -0
+     gact = rcu_dereference_bh(g->actg);
+     if (unlikely(gact->current_gate_status & GATE_ACT_PENDING)) {

Can't current_gate_status be concurrently modified by timer callback? This function doesn't use entry_lock to synchronize with timer.

Will try tcf_lock either.

Quoted 22 lines

net/sched/act_gate.c line 140

Quoted 6 lines
net/sched/act_gate.c new file +5 -0
+             rcu_read_unlock();
+             return action;
+     }
+
+     if (!(gact->current_gate_status & GATE_ACT_GATE_OPEN))

...and here

net/sched/act_gate.c

Quoted 6 lines
net/sched/act_gate.c new file +6 -0
+             goto drop;
+
+     if (gact->current_max_octets >= 0) {
+             gact->current_entry_octets += qdisc_pkt_len(skb);
+             if (gact->current_entry_octets >
+ gact->current_max_octets) {

here also.

net/sched/act_gate.c line 146

Quoted 2 lines
net/sched/act_gate.c new file +2 -0
+
+ qstats_overlimit_inc(this_cpu_ptr(g->common.cpu_qstats));

Please use tcf_action_inc_overlimit_qstats() and other wrappers for

stats.

Quoted 1 line
Quoted 1 line

Otherwise it will crash if user passes

TCA_ACT_FLAGS_NO_PERCPU_STATS

Quoted 3 lines
Quoted 1 line

flag.

The tcf_action_inc_overlimit_qstats() can't show limit counts in tc show

command. Is there anything need to do?

What do you mean? Internally tcf_action_inc_overlimit_qstats() just calls qstats_overlimit_inc, if cpu_qstats percpu counter is not NULL:

Quoted 6 lines
        if (likely(a->cpu_qstats)) {
                qstats_overlimit_inc(this_cpu_ptr(a->cpu_qstats));
                return;
        }

Is there a subtle bug somewhere in this function?

Sorry, I updated using the tcf_action_*, and the counting is ok. I moved back to the qstats_overlimit_inc() because tcf_action_* () include the spin_lock(&a->tcfa_lock). I would update to tcf_action_* () increate.

Quoted 4 lines
Quoted 4 lines

Br,
Po Liu

Thanks a lot.

Br,
Po Liu

author
#77 lore raw

RE: [EXT] Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

Hi Vlad Buslov,

Quoted 59 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+static enum hrtimer_restart gate_timer_func(struct hrtimer *timer)

{

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ struct gate_action *gact = container_of(timer, struct

gate_action,

Quoted 55 lines
Quoted 55 lines
Quoted 6 lines
Quoted 6 lines
net/sched/act_gate.c new file +6 -0
+                                             hitimer);
+     struct tcf_gate_params *p = get_gate_param(gact);
+     struct tcfg_gate_entry *next;
+     ktime_t close_time, now;
+
+     spin_lock(&gact->entry_lock);
Quoted 12 lines

net/sched/act_gate.c

Quoted 7 lines
net/sched/act_gate.c new file +7 -0
+
+     next = rcu_dereference_protected(gact->next_entry,
+
+ lockdep_is_held(&gact->entry_lock));
+
+     /* cycle start, clear pending bit, clear total octets */
+     gact->current_gate_status = next->gate_state ?

GATE_ACT_GATE_OPEN : 0;

Quoted 4 lines
net/sched/act_gate.c new file +4 -0
+     gact->current_entry_octets = 0;
+     gact->current_max_octets = next->maxoctets;
+
+     gact->current_close_time = ktime_add_ns(gact-

current_close_time,

Quoted 27 lines
Quoted 14 lines
net/sched/act_gate.c new file +14 -0
+                                             next->interval);
+
+     close_time = gact->current_close_time;
+
+     if (list_is_last(&next->list, &p->entries))
+             next = list_first_entry(&p->entries,
+                                     struct tcfg_gate_entry, list);
+     else
+             next = list_next_entry(next, list);
+
+     now = gate_get_time(gact);
+
+     if (ktime_after(now, close_time)) {
+             ktime_t cycle, base;

net/sched/act_gate.c line 115

Quoted 10 lines
net/sched/act_gate.c new file +10 -0
+             u64 n;
+
+             cycle = p->tcfg_cycletime;
+             base = ns_to_ktime(p->tcfg_basetime);
+             n = div64_u64(ktime_sub_ns(now, base), cycle);
+             close_time = ktime_add_ns(base, (n + 1) * cycle);
+     }
+
+     rcu_assign_pointer(gact->next_entry, next);
+     spin_unlock(&gact->entry_lock);

I have couple of question about synchronization here:

Quoted 7 lines

- Why do you need next_entry to be rcu pointer? It is only assigned here with entry_lock protection and in init code before action is visible to concurrent users. I don't see any unlocked rcu-protected readers here that could benefit from it.

- Why create dedicated entry_lock instead of using already existing per- action tcf_lock?

Will try to use the tcf_lock for verification.

I think I added entry_lock was that I can't get the tc_action common parameter in this timer function. If I insist to use the tcf_lock, I have to move the hrtimer to struct tcf_gate which has tc_action common. What do you think?

Quoted 89 lines
Quoted 2 lines
Quoted 2 lines

The thoughts came from that the timer period arrived then check through the list and then update next time would take much more

time.

Quoted 72 lines
Quoted 28 lines

Action function would be busy when traffic. So use a separate lock here for

Quoted 13 lines
Quoted 13 lines
net/sched/act_gate.c new file +12 -0
+
+     hrtimer_set_expires(&gact->hitimer, close_time);
+
+     return HRTIMER_RESTART;
+}
+
+static int tcf_gate_act(struct sk_buff *skb, const struct tc_action *a,
+                     struct tcf_result *res) {
+     struct tcf_gate *g = to_gate(a);
+     struct gate_action *gact;
+     int action;
+
Quoted 8 lines

net/sched/act_gate.c line 133

Quoted 5 lines
net/sched/act_gate.c new file +5 -0
+     tcf_lastuse_update(&g->tcf_tm);
+     bstats_cpu_update(this_cpu_ptr(g->common.cpu_bstats), skb);
+
+     action = READ_ONCE(g->tcf_action);
+     rcu_read_lock();

Action fastpath is already rcu read lock protected, you don't need to manually obtain it.

Will be removed.

Quoted 1 line
Quoted 31 lines
Quoted 6 lines

net/sched/act_gate.c line 181

Quoted 3 lines
net/sched/act_gate.c new file +3 -0
+     gact = rcu_dereference_bh(g->actg);
+     if (unlikely(gact->current_gate_status & GATE_ACT_PENDING))
+ {

Can't current_gate_status be concurrently modified by timer callback? This function doesn't use entry_lock to synchronize with timer.

Will try tcf_lock either.

Quoted 22 lines

net/sched/act_gate.c line 140

Quoted 6 lines
net/sched/act_gate.c new file +5 -0
+             rcu_read_unlock();
+             return action;
+     }
+
+     if (!(gact->current_gate_status & GATE_ACT_GATE_OPEN))

...and here

net/sched/act_gate.c

Quoted 6 lines
net/sched/act_gate.c new file +6 -0
+             goto drop;
+
+     if (gact->current_max_octets >= 0) {
+             gact->current_entry_octets += qdisc_pkt_len(skb);
+             if (gact->current_entry_octets >
+ gact->current_max_octets) {

here also.

Quoted 2 lines

+
+ qstats_overlimit_inc(this_cpu_ptr(g->common.cpu_qstats));

Please use tcf_action_inc_overlimit_qstats() and other wrappers for

stats.

Quoted 1 line
Quoted 1 line

Otherwise it will crash if user passes

TCA_ACT_FLAGS_NO_PERCPU_STATS

Quoted 4 lines
Quoted 1 line

flag.

The tcf_action_inc_overlimit_qstats() can't show limit counts in tc show

command. Is there anything need to do?

What do you mean? Internally tcf_action_inc_overlimit_qstats() just calls qstats_overlimit_inc, if cpu_qstats percpu counter is not NULL:

Quoted 6 lines
        if (likely(a->cpu_qstats)) {
                qstats_overlimit_inc(this_cpu_ptr(a->cpu_qstats));
                return;
        }

Is there a subtle bug somewhere in this function?

Sorry, I updated using the tcf_action_*, and the counting is ok. I moved back to the qstats_overlimit_inc() because tcf_action_* () include the spin_lock(&a->tcfa_lock).
I would update to tcf_action_* () increate.

Quoted 2 lines
Quoted 2 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Br,
Po Liu

Thanks a lot.

Br,
Po Liu

Thanks a lot.

Br,
Po Liu

#78 lore raw

Re: [EXT] Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

Quoted 57 lines · Po Liu

Hi Vlad Buslov,

Quoted 55 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+static enum hrtimer_restart gate_timer_func(struct hrtimer *timer)

{

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ struct gate_action *gact = container_of(timer, struct

gate_action,

Quoted 51 lines
Quoted 51 lines
Quoted 6 lines
Quoted 6 lines
net/sched/act_gate.c new file +6 -0
+                                             hitimer);
+     struct tcf_gate_params *p = get_gate_param(gact);
+     struct tcfg_gate_entry *next;
+     ktime_t close_time, now;
+
+     spin_lock(&gact->entry_lock);
Quoted 12 lines

net/sched/act_gate.c

Quoted 7 lines
net/sched/act_gate.c new file +7 -0
+
+     next = rcu_dereference_protected(gact->next_entry,
+
+ lockdep_is_held(&gact->entry_lock));
+
+     /* cycle start, clear pending bit, clear total octets */
+     gact->current_gate_status = next->gate_state ?

GATE_ACT_GATE_OPEN : 0;

Quoted 4 lines
net/sched/act_gate.c new file +4 -0
+     gact->current_entry_octets = 0;
+     gact->current_max_octets = next->maxoctets;
+
+     gact->current_close_time = ktime_add_ns(gact-

current_close_time,

Quoted 32 lines
Quoted 14 lines
net/sched/act_gate.c new file +14 -0
+                                             next->interval);
+
+     close_time = gact->current_close_time;
+
+     if (list_is_last(&next->list, &p->entries))
+             next = list_first_entry(&p->entries,
+                                     struct tcfg_gate_entry, list);
+     else
+             next = list_next_entry(next, list);
+
+     now = gate_get_time(gact);
+
+     if (ktime_after(now, close_time)) {
+             ktime_t cycle, base;

net/sched/act_gate.c line 115

Quoted 10 lines
net/sched/act_gate.c new file +10 -0
+             u64 n;
+
+             cycle = p->tcfg_cycletime;
+             base = ns_to_ktime(p->tcfg_basetime);
+             n = div64_u64(ktime_sub_ns(now, base), cycle);
+             close_time = ktime_add_ns(base, (n + 1) * cycle);
+     }
+
+     rcu_assign_pointer(gact->next_entry, next);
+     spin_unlock(&gact->entry_lock);

I have couple of question about synchronization here:

- Why do you need next_entry to be rcu pointer? It is only assigned here with entry_lock protection and in init code before action is visible to concurrent users. I don't see any unlocked rcu-protected readers here that could benefit from it.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

- Why create dedicated entry_lock instead of using already existing per- action tcf_lock?

Will try to use the tcf_lock for verification.

I think I added entry_lock was that I can't get the tc_action common parameter in this timer function. If I insist to use the tcf_lock, I have to move the hrtimer to struct tcf_gate which has tc_action common. What do you think?

Well, if you use tcf_lock instead of rcu to sync with fastpath, the you don't need to implement struct gate_action as standalone object pointed to by rcu pointer from base structure that includes tc_action common. All the necessary data can be included in tcf_gate structure directly and used from both timer and action fastpath. See pedit for example of action that doesn't use rcu for fastpath.

Quoted 102 lines
Quoted 90 lines
Quoted 3 lines
Quoted 3 lines

The thoughts came from that the timer period arrived then check through the list and then update next time would take much more

time.

Quoted 72 lines
Quoted 28 lines

Action function would be busy when traffic. So use a separate lock here for

Quoted 13 lines
Quoted 13 lines
net/sched/act_gate.c new file +12 -0
+
+     hrtimer_set_expires(&gact->hitimer, close_time);
+
+     return HRTIMER_RESTART;
+}
+
+static int tcf_gate_act(struct sk_buff *skb, const struct tc_action *a,
+                     struct tcf_result *res) {
+     struct tcf_gate *g = to_gate(a);
+     struct gate_action *gact;
+     int action;
+
Quoted 8 lines

net/sched/act_gate.c line 133

Quoted 5 lines
net/sched/act_gate.c new file +5 -0
+     tcf_lastuse_update(&g->tcf_tm);
+     bstats_cpu_update(this_cpu_ptr(g->common.cpu_bstats), skb);
+
+     action = READ_ONCE(g->tcf_action);
+     rcu_read_lock();

Action fastpath is already rcu read lock protected, you don't need to manually obtain it.

Will be removed.

Quoted 1 line
Quoted 31 lines
Quoted 6 lines

net/sched/act_gate.c line 181

Quoted 3 lines
net/sched/act_gate.c new file +3 -0
+     gact = rcu_dereference_bh(g->actg);
+     if (unlikely(gact->current_gate_status & GATE_ACT_PENDING))
+ {

Can't current_gate_status be concurrently modified by timer callback? This function doesn't use entry_lock to synchronize with timer.

Will try tcf_lock either.

Quoted 22 lines

net/sched/act_gate.c line 140

Quoted 6 lines
net/sched/act_gate.c new file +5 -0
+             rcu_read_unlock();
+             return action;
+     }
+
+     if (!(gact->current_gate_status & GATE_ACT_GATE_OPEN))

...and here

net/sched/act_gate.c

Quoted 6 lines
net/sched/act_gate.c new file +6 -0
+             goto drop;
+
+     if (gact->current_max_octets >= 0) {
+             gact->current_entry_octets += qdisc_pkt_len(skb);
+             if (gact->current_entry_octets >
+ gact->current_max_octets) {

here also.

Quoted 2 lines

+
+ qstats_overlimit_inc(this_cpu_ptr(g->common.cpu_qstats));

Please use tcf_action_inc_overlimit_qstats() and other wrappers for

stats.

Quoted 1 line
Quoted 1 line

Otherwise it will crash if user passes

TCA_ACT_FLAGS_NO_PERCPU_STATS

Quoted 4 lines
Quoted 1 line

flag.

The tcf_action_inc_overlimit_qstats() can't show limit counts in tc show

command. Is there anything need to do?

What do you mean? Internally tcf_action_inc_overlimit_qstats() just calls qstats_overlimit_inc, if cpu_qstats percpu counter is not NULL:

Quoted 6 lines
        if (likely(a->cpu_qstats)) {
                qstats_overlimit_inc(this_cpu_ptr(a->cpu_qstats));
                return;
        }

Is there a subtle bug somewhere in this function?

Sorry, I updated using the tcf_action_*, and the counting is ok. I moved back to the qstats_overlimit_inc() because tcf_action_* () include the spin_lock(&a->tcfa_lock).
I would update to tcf_action_* () increate.

Quoted 2 lines
Quoted 2 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Br,
Po Liu

Thanks a lot.

Br,
Po Liu

Thanks a lot.

Br,
Po Liu

#79 lore raw

Re: [EXT] Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

In reply to Po Liu
Quoted 509 lines · Po Liu
Quoted 509 lines

-----Original Message-----
From: Vlad Buslov <[email protected]>
Sent: 2020年4月23日 15:43
To: Po Liu <[email protected]>
Cc: Vlad Buslov <[email protected]>; [email protected]; linux- [email protected]; [email protected]; [email protected]; Claudiu Manoil <[email protected]>; Vladimir Oltean <[email protected]>; Alexandru Marginean <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [EXT] Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

Caution: EXT Email

Quoted 9 lines · Po Liu

Hi Vlad Buslov,

Quoted 7 lines

-----Original Message-----
From: Vlad Buslov <[email protected]>
Sent: 2020年4月22日 21:23
To: Po Liu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Claudiu Manoil <[email protected]>; Vladimir Oltean

<[email protected]>;

Quoted 2 lines
Quoted 2 lines

Alexandru Marginean <[email protected]>; [email protected]; [email protected];

[email protected];

Quoted 4 lines
Quoted 4 lines

[email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected];

[email protected];

Quoted 10 lines
Quoted 10 lines

[email protected]; [email protected]; [email protected]
Subject: [EXT] Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

Caution: EXT Email

Hi Po,

On Wed 22 Apr 2020 at 05:48, Po Liu <[email protected]> wrote:

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Introduce a ingress frame gate control flow action.
Tc gate action does the work like this:
Assume there is a gate allow specified ingress frames can be passed at specific time slot, and be dropped at specific time slot. Tc filter chooses the ingress frames, and tc gate action would specify what slot does these frames can be passed to device and what time slot would be dropped.
Tc gate action would provide an entry list to tell how much time gate keep open and how much time gate keep state close. Gate

action

Quoted 50 lines
Quoted 50 lines
Quoted 31 lines

also assign a start time to tell when the entry list start. Then driver would repeat the gate entry list cyclically.
For the software simulation, gate action requires the user assign a time clock type.

Below is the setting example in user space. Tc filter a stream source ip address is 192.168.0.20 and gate action own two time slots. One is last 200ms gate open let frame pass another is last 100ms gate close let frames dropped. When the frames have passed total frames over
8000000 bytes, frames will be dropped in one 200000000ns time slot.

Quoted 3 lines

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 clockid CLOCK_TAI \
         sched-entry open 200000000 -1 8000000 \
         sched-entry close 100000000 -1 -1
Quoted 1 line

tc chain del dev eth0 ingress chain 0

"sched-entry" follow the name taprio style. Gate state is "open"/"close". Follow with period nanosecond. Then next item 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.
Base-time is not set will be 0 as default, as result start time would be ((N + 1) * cycletime) which is the minimal of future time.

Quoted 5 lines

Below example shows filtering a stream with destination mac address is
10:00:80:00:00:00 and ip type is ICMP, follow the action gate. The gate action would run with one close time slot which means always keep

close.

Quoted 13 lines

The time cycle is total 200000000ns. The base-time would calculate by:

1357000000000 + (N + 1) * cycletime

When the total value is the future time, it will be the start time. The cycletime here would be 200000000ns for this case.

Quoted 1 line

tc filter add dev eth0 parent ffff: protocol ip \

         flower skip_hw ip_proto icmp dst_mac 10:00:80:00:00:00 \
         action gate index 12 base-time 1357000000000 \
         sched-entry close 200000000 -1 -1 \
         clockid CLOCK_TAI
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
---
 include/net/tc_act/tc_gate.h        |  54 +++
 include/uapi/linux/pkt_cls.h        |   1 +
 include/uapi/linux/tc_act/tc_gate.h |  47 ++
 net/sched/Kconfig                   |  13 +
 net/sched/Makefile                  |   1 +
 net/sched/act_gate.c                | 647

++++++++++++++++++++++++++++

Quoted 107 lines
Quoted 107 lines
Quoted 67 lines
 6 files changed, 763 insertions(+)  create mode 100644
include/net/tc_act/tc_gate.h  create mode 100644
include/uapi/linux/tc_act/tc_gate.h
 create mode 100644 net/sched/act_gate.c
(quoted diff) +0 -0

b/include/net/tc_act/tc_gate.h new file mode 100644 index 000000000000..b0ace55b2aaa

include/net/tc_act/tc_gate.h new file +55 -0
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright 2020 NXP */
+
+#ifndef __NET_TC_GATE_H
+#define __NET_TC_GATE_H
+
+#include <net/act_api.h>
+#include <linux/tc_act/tc_gate.h>
+
+struct tcfg_gate_entry {
+     int                     index;
+     u8                      gate_state;
+     u32                     interval;
+     s32                     ipv;
+     s32                     maxoctets;
+     struct list_head        list;
+};
+
+struct tcf_gate_params {
+     s32                     tcfg_priority;
+     u64                     tcfg_basetime;
+     u64                     tcfg_cycletime;
+     u64                     tcfg_cycletime_ext;
+     u32                     tcfg_flags;
+     s32                     tcfg_clockid;
+     size_t                  num_entries;
+     struct list_head        entries;
+};
+
+#define GATE_ACT_GATE_OPEN   BIT(0)
+#define GATE_ACT_PENDING     BIT(1)
+struct gate_action {
+     struct tcf_gate_params param;
+     spinlock_t entry_lock;
+     u8 current_gate_status;
+     ktime_t current_close_time;
+     u32 current_entry_octets;
+     s32 current_max_octets;
+     struct tcfg_gate_entry __rcu *next_entry;
+     struct hrtimer hitimer;
+     enum tk_offsets tk_offset;
+     struct rcu_head rcu;
+};
+
+struct tcf_gate {
+     struct tc_action                common;
+     struct gate_action __rcu        *actg;
+};
+#define to_gate(a) ((struct tcf_gate *)a)
+
+#define get_gate_param(act) ((struct tcf_gate_params *)act)
+#define
+get_gate_action(p) ((struct gate_action *)p)
+
+#endif
(quoted diff) +0 -0
Quoted 1 line

b/include/uapi/linux/pkt_cls.h index 9f06d29cab70..fc672b232437

100644

Quoted 38 lines
include/uapi/linux/pkt_cls.h +1 -0
@@ -134,6 +134,7 @@ enum tca_id {
      TCA_ID_CTINFO,
      TCA_ID_MPLS,
      TCA_ID_CT,
+     TCA_ID_GATE,
      /* other actions go here */
      __TCA_ID_MAX = 255
 };
include/uapi/linux/tc_act/tc_gate.h new file +21 -0
new file mode 100644
index 000000000000..f214b3a6d44f
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
+/* Copyright 2020 NXP */
+
+#ifndef __LINUX_TC_GATE_H
+#define __LINUX_TC_GATE_H
+
+#include <linux/pkt_cls.h>
+
+struct tc_gate {
+     tc_gen;
+};
+
+enum {
+     TCA_GATE_ENTRY_UNSPEC,
+     TCA_GATE_ENTRY_INDEX,
+     TCA_GATE_ENTRY_GATE,
+     TCA_GATE_ENTRY_INTERVAL,
+     TCA_GATE_ENTRY_IPV,
+     TCA_GATE_ENTRY_MAX_OCTETS,
+     __TCA_GATE_ENTRY_MAX,
+};
Quoted 8 lines
Quoted 8 lines

include/uapi/linux/tc_act/tc_gate.h

Quoted 8 lines
include/uapi/linux/tc_act/tc_gate.h new file +8 -0
+#define TCA_GATE_ENTRY_MAX (__TCA_GATE_ENTRY_MAX - 1)
+
+enum {
+     TCA_GATE_ONE_ENTRY_UNSPEC,
+     TCA_GATE_ONE_ENTRY,
+     __TCA_GATE_ONE_ENTRY_MAX,
+};
+#define TCA_GATE_ONE_ENTRY_MAX

(__TCA_GATE_ONE_ENTRY_MAX

Quoted 227 lines
Quoted 110 lines

- 1)

net/sched/Makefile obj-$(CONFIG_NET_IFE_SKBPRIO) +=

Quoted 47 lines
include/uapi/linux/tc_act/tc_gate.h new file +18 -0
+
+enum {
+     TCA_GATE_UNSPEC,
+     TCA_GATE_TM,
+     TCA_GATE_PARMS,
+     TCA_GATE_PAD,
+     TCA_GATE_PRIORITY,
+     TCA_GATE_ENTRY_LIST,
+     TCA_GATE_BASE_TIME,
+     TCA_GATE_CYCLE_TIME,
+     TCA_GATE_CYCLE_TIME_EXT,
+     TCA_GATE_FLAGS,
+     TCA_GATE_CLOCKID,
+     __TCA_GATE_MAX,
+};
+#define TCA_GATE_MAX (__TCA_GATE_MAX - 1)
+
+#endif
net/sched/Kconfig index renamed from net/sched/Kconfig +0 -0

bfbefb7bff9d..1314549c7567 100644

net/sched/Kconfig +13 -0
@@ -981,6 +981,19 @@ config NET_ACT_CT
        To compile this code as a module, choose M here: the
        module will be called act_ct.
 
+config NET_ACT_GATE
+     tristate "Frame gate entry list control tc action"
+     depends on NET_CLS_ACT
+     help
+       Say Y here to allow to control the ingress flow to be passed at
+       specific time slot and be dropped at other specific time slot by
+       the gate entry list. The manipulation will simulate the IEEE
+       802.1Qci stream gate control behavior.
+
+       If unsure, say N.
+       To compile this code as a module, choose M here: the
+       module will be called act_gate.
+
 config NET_IFE_SKBMARK
      tristate "Support to encoding decoding skb mark on IFE action"
      depends on NET_ACT_IFE
net/sched/Makefile index renamed from net/sched/Makefile +0 -0

31c367a6cd09..66bbf9a98f9e 100644

net/sched/Makefile +0 -0
@@ -30,6 +30,7 @@ obj-$(CONFIG_NET_IFE_SKBPRIO)       +=

act_meta_skbprio.o

Quoted 61 lines
net/sched/Makefile +1 -0
 obj-$(CONFIG_NET_IFE_SKBTCINDEX)     += act_meta_skbtcindex.o
 obj-$(CONFIG_NET_ACT_TUNNEL_KEY)+= act_tunnel_key.o
 obj-$(CONFIG_NET_ACT_CT)     += act_ct.o
+obj-$(CONFIG_NET_ACT_GATE)   += act_gate.o
 obj-$(CONFIG_NET_SCH_FIFO)   += sch_fifo.o
 obj-$(CONFIG_NET_SCH_CBQ)    += sch_cbq.o
 obj-$(CONFIG_NET_SCH_HTB)    += sch_htb.o
net/sched/act_gate.c new file renamed from net/sched/act_gate.c +0 -0

mode
100644 index 000000000000..e932f402b4f1

net/sched/act_gate.c new file +48 -0
@@ -0,0 +1,647 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright 2020 NXP */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/skbuff.h>
+#include <linux/rtnetlink.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <net/act_api.h>
+#include <net/netlink.h>
+#include <net/pkt_cls.h>
+#include <net/tc_act/tc_gate.h>
+
+static unsigned int gate_net_id;
+static struct tc_action_ops act_gate_ops;
+
+static ktime_t gate_get_time(struct gate_action *gact) {
+     ktime_t mono = ktime_get();
+
+     switch (gact->tk_offset) {
+     case TK_OFFS_MAX:
+             return mono;
+     default:
+             return ktime_mono_to_any(mono, gact->tk_offset);
+     }
+
+     return KTIME_MAX;
+}
+
+static int gate_get_start_time(struct gate_action *gact, ktime_t
+*start) {
+     struct tcf_gate_params *param = get_gate_param(gact);
+     ktime_t now, base, cycle;
+     u64 n;
+
+     base = ns_to_ktime(param->tcfg_basetime);
+     now = gate_get_time(gact);
+
+     if (ktime_after(base, now)) {
+             *start = base;
+             return 0;
+     }
+
+     cycle = param->tcfg_cycletime;
Quoted 8 lines

net/sched/act_gate.c line 53

Quoted 4 lines
net/sched/act_gate.c new file +4 -0
+
+     /* cycle time should not be zero */
+     if (WARN_ON(!cycle))
+             return -EFAULT;

Looking at the init code it seems that this value can be set to 0 directly from netlink packet without further validation, which would allow user to trigger warning here.

Yes, will avoid at ahead point.

Quoted 27 lines
Quoted 27 lines
net/sched/act_gate.c new file +26 -0
+
+     n = div64_u64(ktime_sub_ns(now, base), cycle);
+     *start = ktime_add_ns(base, (n + 1) * cycle);
+     return 0;
+}
+
+static void gate_start_timer(struct gate_action *gact, ktime_t
+start) {
+     ktime_t expires;
+
+     expires = hrtimer_get_expires(&gact->hitimer);
+     if (expires == 0)
+             expires = KTIME_MAX;
+
+     start = min_t(ktime_t, start, expires);
+
+     hrtimer_start(&gact->hitimer, start, HRTIMER_MODE_ABS); }
+
+static enum hrtimer_restart gate_timer_func(struct hrtimer *timer) {
+     struct gate_action *gact = container_of(timer, struct gate_action,
+                                             hitimer);
+     struct tcf_gate_params *p = get_gate_param(gact);
+     struct tcfg_gate_entry *next;
+     ktime_t close_time, now;
+
+     spin_lock(&gact->entry_lock);
Quoted 12 lines

net/sched/act_gate.c

Quoted 7 lines
net/sched/act_gate.c new file +7 -0
+
+     next = rcu_dereference_protected(gact->next_entry,
+
+ lockdep_is_held(&gact->entry_lock));
+
+     /* cycle start, clear pending bit, clear total octets */
+     gact->current_gate_status = next->gate_state ?

GATE_ACT_GATE_OPEN : 0;

Quoted 4 lines
net/sched/act_gate.c new file +4 -0
+     gact->current_entry_octets = 0;
+     gact->current_max_octets = next->maxoctets;
+
+     gact->current_close_time = ktime_add_ns(gact-

current_close_time,

Quoted 27 lines
Quoted 14 lines
net/sched/act_gate.c new file +14 -0
+                                             next->interval);
+
+     close_time = gact->current_close_time;
+
+     if (list_is_last(&next->list, &p->entries))
+             next = list_first_entry(&p->entries,
+                                     struct tcfg_gate_entry, list);
+     else
+             next = list_next_entry(next, list);
+
+     now = gate_get_time(gact);
+
+     if (ktime_after(now, close_time)) {
+             ktime_t cycle, base;

net/sched/act_gate.c line 115

Quoted 10 lines
net/sched/act_gate.c new file +10 -0
+             u64 n;
+
+             cycle = p->tcfg_cycletime;
+             base = ns_to_ktime(p->tcfg_basetime);
+             n = div64_u64(ktime_sub_ns(now, base), cycle);
+             close_time = ktime_add_ns(base, (n + 1) * cycle);
+     }
+
+     rcu_assign_pointer(gact->next_entry, next);
+     spin_unlock(&gact->entry_lock);

I have couple of question about synchronization here:

Quoted 7 lines

- Why do you need next_entry to be rcu pointer? It is only assigned here with entry_lock protection and in init code before action is visible to concurrent users. I don't see any unlocked rcu-protected readers here that could benefit from it.

- Why create dedicated entry_lock instead of using already existing per- action tcf_lock?

Will try to use the tcf_lock for verification.
The thoughts came from that the timer period arrived then check through the list and then update next time would take much more time. Action function would be busy when traffic. So use a separate lock here for

Quoted 13 lines
Quoted 13 lines
net/sched/act_gate.c new file +12 -0
+
+     hrtimer_set_expires(&gact->hitimer, close_time);
+
+     return HRTIMER_RESTART;
+}
+
+static int tcf_gate_act(struct sk_buff *skb, const struct tc_action *a,
+                     struct tcf_result *res) {
+     struct tcf_gate *g = to_gate(a);
+     struct gate_action *gact;
+     int action;
+
Quoted 8 lines

net/sched/act_gate.c line 133

Quoted 5 lines
net/sched/act_gate.c new file +5 -0
+     tcf_lastuse_update(&g->tcf_tm);
+     bstats_cpu_update(this_cpu_ptr(g->common.cpu_bstats), skb);
+
+     action = READ_ONCE(g->tcf_action);
+     rcu_read_lock();

Action fastpath is already rcu read lock protected, you don't need to manually obtain it.

Will be removed.

Quoted 1 line
Quoted 30 lines
Quoted 5 lines

net/sched/act_gate.c line 135

Quoted 2 lines
net/sched/act_gate.c new file +2 -0
+     gact = rcu_dereference_bh(g->actg);
+     if (unlikely(gact->current_gate_status & GATE_ACT_PENDING)) {

Can't current_gate_status be concurrently modified by timer callback? This function doesn't use entry_lock to synchronize with timer.

Will try tcf_lock either.

Quoted 22 lines

net/sched/act_gate.c line 140

Quoted 6 lines
net/sched/act_gate.c new file +5 -0
+             rcu_read_unlock();
+             return action;
+     }
+
+     if (!(gact->current_gate_status & GATE_ACT_GATE_OPEN))

...and here

net/sched/act_gate.c

Quoted 6 lines
net/sched/act_gate.c new file +6 -0
+             goto drop;
+
+     if (gact->current_max_octets >= 0) {
+             gact->current_entry_octets += qdisc_pkt_len(skb);
+             if (gact->current_entry_octets >
+ gact->current_max_octets) {

here also.

net/sched/act_gate.c line 146

Quoted 2 lines
net/sched/act_gate.c new file +2 -0
+
+ qstats_overlimit_inc(this_cpu_ptr(g->common.cpu_qstats));

Please use tcf_action_inc_overlimit_qstats() and other wrappers for

stats.

Quoted 1 line
Quoted 1 line

Otherwise it will crash if user passes

TCA_ACT_FLAGS_NO_PERCPU_STATS

Quoted 3 lines
Quoted 1 line

flag.

The tcf_action_inc_overlimit_qstats() can't show limit counts in tc show

command. Is there anything need to do?

What do you mean? Internally tcf_action_inc_overlimit_qstats() just calls qstats_overlimit_inc, if cpu_qstats percpu counter is not NULL:

        if (likely(a->cpu_qstats)) {
                qstats_overlimit_inc(this_cpu_ptr(a->cpu_qstats));
                return;
        }
Quoted 4 lines
Quoted 1 line

Is there a subtle bug somewhere in this function?

Sorry, I updated using the tcf_action_*, and the counting is ok. I moved back to the qstats_overlimit_inc() because tcf_action_* () include the spin_lock(&a->tcfa_lock). I would update to tcf_action_* () increate.

BTW if you end up with synchronizing fastpath with tcfa_lock, then you don't need to use tcf_action_*stats() helpers and percpu counters (they will only slow down action init and increase memory usage without providing any improvements for parallelism). Instead, you can just directly change the tcf_{q|b}stats while holding the tcfa_lock. Check pedit for example of such action.

Quoted 10 lines
Quoted 5 lines
Quoted 5 lines

Br,
Po Liu

Thanks a lot.

Br,
Po Liu

#80 lore raw

Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

In reply to Po Liu

Hi Po,

Nice to see even more work on the TSN standards in the upstream kernel.

Quoted 22 lines · Po Liu

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Introduce a ingress frame gate control flow action.
Tc gate action does the work like this:
Assume there is a gate allow specified ingress frames can be passed at specific time slot, and be dropped at specific time slot. Tc filter chooses the ingress frames, and tc gate action would specify what slot does these frames can be passed to device and what time slot would be dropped.
Tc gate action would provide an entry list to tell how much time gate keep open and how much time gate keep state close. Gate action also assign a start time to tell when the entry list start. Then driver would repeat the gate entry list cyclically.
For the software simulation, gate action requires the user assign a time clock type.

Below is the setting example in user space. Tc filter a stream source ip address is 192.168.0.20 and gate action own two time slots. One is last 200ms gate open let frame pass another is last 100ms gate close let frames dropped. When the frames have passed total frames over 8000000 bytes, frames will be dropped in one 200000000ns time slot.

Quoted 7 lines
Quoted 3 lines

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 clockid CLOCK_TAI \
          sched-entry open 200000000 -1 8000000 \
          sched-entry close 100000000 -1 -1

First of all, it is a long time since I read the 802.1Qci and when I did it, it was a draft. So please let me know if I'm completly off here.

I know you are focusing on the gate control in this patch serie, but I assume that you later will want to do the policing and flow-meter as well. And it could make sense to consider how all of this work toghether.

A common use-case for the policing is to have multiple rules pointing at the same policing instance. Maybe you want the sum of the traffic on 2 ports to be limited to 100mbit. If you specify such action on the individual rule (like done with the gate), then you can not have two rules pointing at the same policer instance.

Long storry short, have you considered if it would be better to do something like:

  tc filter add dev eth0 parent ffff: protocol ip \
           flower src_ip 192.168.0.20 \
           action psfp-id 42

And then have some other function to configure the properties of psfp-id 42?

/Allan

maintainer
#81 lore raw

Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

Hi Allan,

Quoted 57 lines · Allan W. Nielsen

Hi Po,

Nice to see even more work on the TSN standards in the upstream kernel.

Quoted 22 lines · Po Liu

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Introduce a ingress frame gate control flow action.
Tc gate action does the work like this:
Assume there is a gate allow specified ingress frames can be passed at specific time slot, and be dropped at specific time slot. Tc filter chooses the ingress frames, and tc gate action would specify what slot does these frames can be passed to device and what time slot would be dropped.
Tc gate action would provide an entry list to tell how much time gate keep open and how much time gate keep state close. Gate action also assign a start time to tell when the entry list start. Then driver would repeat the gate entry list cyclically.
For the software simulation, gate action requires the user assign a time clock type.

Below is the setting example in user space. Tc filter a stream source ip address is 192.168.0.20 and gate action own two time slots. One is last 200ms gate open let frame pass another is last 100ms gate close let frames dropped. When the frames have passed total frames over 8000000 bytes, frames will be dropped in one 200000000ns time slot.

Quoted 7 lines
Quoted 3 lines

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 clockid CLOCK_TAI \
          sched-entry open 200000000 -1 8000000 \
          sched-entry close 100000000 -1 -1

First of all, it is a long time since I read the 802.1Qci and when I did it, it was a draft. So please let me know if I'm completly off here.

I know you are focusing on the gate control in this patch serie, but I assume that you later will want to do the policing and flow-meter as well. And it could make sense to consider how all of this work toghether.

A common use-case for the policing is to have multiple rules pointing at the same policing instance. Maybe you want the sum of the traffic on 2 ports to be limited to 100mbit. If you specify such action on the individual rule (like done with the gate), then you can not have two rules pointing at the same policer instance.

Long storry short, have you considered if it would be better to do something like:

   tc filter add dev eth0 parent ffff: protocol ip \
            flower src_ip 192.168.0.20 \
            action psfp-id 42
Quoted 6 lines

And then have some other function to configure the properties of psfp-id 42?

/Allan

It is very good that you brought it up though, since in my opinion too it is a rather important aspect, and it seems that the fact this feature is already designed-in was a bit too subtle.

"psfp-id" is actually his "index" argument.

You can actually do this:
tc filter add dev eth0 ingress \

        flower skip_hw dst_mac 01:80:c2:00:00:0e \
        action gate index 1 clockid CLOCK_TAI \
        base-time 200000000000 \
        sched-entry OPEN 200000000 -1 -1 \
        sched-entry CLOSE 100000000 -1 -1

tc filter add dev eth0 ingress \
flower skip_hw dst_mac 01:80:c2:00:00:0f \
action gate index 1

Then 2 filters get created with the same action:

tc -s filter show dev swp2 ingress
filter protocol all pref 49151 flower chain 0
filter protocol all pref 49151 flower chain 0 handle 0x1
dst_mac 01:80:c2:00:00:0f
skip_hw
not_in_hw
action order 1:
priority wildcard clockid TAI flags 0x6404f
base-time 200000000000 cycle-time 300000000
cycle-time-ext 0
number 0 gate-state open interval 200000000
ipv wildcard max-octets wildcard
number 1 gate-state close interval 100000000
ipv wildcard max-octets wildcard
pipe
index 2 ref 2 bind 2 installed 168 sec used 168 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0

filter protocol all pref 49152 flower chain 0
filter protocol all pref 49152 flower chain 0 handle 0x1
dst_mac 01:80:c2:00:00:0e
skip_hw
not_in_hw
action order 1:
priority wildcard clockid TAI flags 0x6404f
base-time 200000000000 cycle-time 300000000
cycle-time-ext 0
number 0 gate-state open interval 200000000
ipv wildcard max-octets wildcard
number 1 gate-state close interval 100000000
ipv wildcard max-octets wildcard
pipe
index 2 ref 2 bind 2 installed 168 sec used 168 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0

Actually my only concern is that maybe this mechanism should (?) have been more generic. At the moment, this patch series implements it via a TCA_GATE_ENTRY_INDEX netlink attribute, so every action which wants to be shared across filters needs to reinvent this wheel.

Thoughts, everyone?

Thanks,
-Vladimir

#82 lore raw

Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

Quoted 127 lines · Vladimir Oltean

Hi Allan,

Quoted 57 lines · Allan W. Nielsen

Hi Po,

Nice to see even more work on the TSN standards in the upstream kernel.

Quoted 22 lines · Po Liu

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Introduce a ingress frame gate control flow action.
Tc gate action does the work like this:
Assume there is a gate allow specified ingress frames can be passed at specific time slot, and be dropped at specific time slot. Tc filter chooses the ingress frames, and tc gate action would specify what slot does these frames can be passed to device and what time slot would be dropped.
Tc gate action would provide an entry list to tell how much time gate keep open and how much time gate keep state close. Gate action also assign a start time to tell when the entry list start. Then driver would repeat the gate entry list cyclically.
For the software simulation, gate action requires the user assign a time clock type.

Below is the setting example in user space. Tc filter a stream source ip address is 192.168.0.20 and gate action own two time slots. One is last 200ms gate open let frame pass another is last 100ms gate close let frames dropped. When the frames have passed total frames over 8000000 bytes, frames will be dropped in one 200000000ns time slot.

Quoted 7 lines
Quoted 3 lines

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 clockid CLOCK_TAI \
          sched-entry open 200000000 -1 8000000 \
          sched-entry close 100000000 -1 -1

First of all, it is a long time since I read the 802.1Qci and when I did it, it was a draft. So please let me know if I'm completly off here.

I know you are focusing on the gate control in this patch serie, but I assume that you later will want to do the policing and flow-meter as well. And it could make sense to consider how all of this work toghether.

A common use-case for the policing is to have multiple rules pointing at the same policing instance. Maybe you want the sum of the traffic on 2 ports to be limited to 100mbit. If you specify such action on the individual rule (like done with the gate), then you can not have two rules pointing at the same policer instance.

Long storry short, have you considered if it would be better to do something like:

   tc filter add dev eth0 parent ffff: protocol ip \
            flower src_ip 192.168.0.20 \
            action psfp-id 42
Quoted 6 lines

And then have some other function to configure the properties of psfp-id 42?

/Allan

It is very good that you brought it up though, since in my opinion too it is a rather important aspect, and it seems that the fact this feature is already designed-in was a bit too subtle.

"psfp-id" is actually his "index" argument.

You can actually do this:
tc filter add dev eth0 ingress \

        flower skip_hw dst_mac 01:80:c2:00:00:0e \
        action gate index 1 clockid CLOCK_TAI \
        base-time 200000000000 \
        sched-entry OPEN 200000000 -1 -1 \
        sched-entry CLOSE 100000000 -1 -1

tc filter add dev eth0 ingress \
flower skip_hw dst_mac 01:80:c2:00:00:0f \
action gate index 1

Then 2 filters get created with the same action:

tc -s filter show dev swp2 ingress
filter protocol all pref 49151 flower chain 0
filter protocol all pref 49151 flower chain 0 handle 0x1
dst_mac 01:80:c2:00:00:0f
skip_hw
not_in_hw
action order 1:
priority wildcard clockid TAI flags 0x6404f
base-time 200000000000 cycle-time 300000000
cycle-time-ext 0
number 0 gate-state open interval 200000000
ipv wildcard max-octets wildcard
number 1 gate-state close interval 100000000
ipv wildcard max-octets wildcard
pipe
index 2 ref 2 bind 2 installed 168 sec used 168 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0

filter protocol all pref 49152 flower chain 0
filter protocol all pref 49152 flower chain 0 handle 0x1
dst_mac 01:80:c2:00:00:0e
skip_hw
not_in_hw
action order 1:
priority wildcard clockid TAI flags 0x6404f
base-time 200000000000 cycle-time 300000000
cycle-time-ext 0
number 0 gate-state open interval 200000000
ipv wildcard max-octets wildcard
number 1 gate-state close interval 100000000
ipv wildcard max-octets wildcard
pipe
index 2 ref 2 bind 2 installed 168 sec used 168 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0

Quoted 6 lines

Actually my only concern is that maybe this mechanism should (?) have been more generic. At the moment, this patch series implements it via a TCA_GATE_ENTRY_INDEX netlink attribute, so every action which wants to be shared across filters needs to reinvent this wheel.

Thoughts, everyone?

I don't have anything valuable to add, aside from commenting this whole thing makes my brain hurt.

Quoted 2 lines

Thanks,
-Vladimir

Signature · 6 lines
Make Music, Not War

Dave Täht
CTO, TekLibre, LLC
http://www.teklibre.com
Tel: 1-831-435-0729
author
#83 lore raw

RE: [EXT] Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

Hi Dave That,

Quoted 162 lines

-----Original Message-----
From: Dave Taht <[email protected]>
Sent: 2020年4月23日 4:06
To: Vladimir Oltean <[email protected]>
Cc: Allan W. Nielsen <[email protected]>; Po Liu <[email protected]>; David S. Miller <[email protected]>; lkml <linux- [email protected]>; netdev <[email protected]>; Vinicius Costa Gomes <[email protected]>; Claudiu Manoil <[email protected]>; Vladimir Oltean <[email protected]>; Alexandru Marginean <[email protected]>; [email protected]; [email protected]; Saeed Mahameed <[email protected]>; [email protected]; Jiri Pirko <[email protected]>; Ido Schimmel <[email protected]>; Alexandre Belloni <[email protected]>; Microchip Linux Driver Support <[email protected]>; Jakub Kicinski <[email protected]>; Jamal Hadi Salim <[email protected]>; Cong Wang <[email protected]>; [email protected]; Pablo Neira Ayuso <[email protected]>; [email protected]; Murali Karicheri <[email protected]>; Andre Guedes <[email protected]>; Stephen Hemminger <[email protected]>
Subject: [EXT] Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

Caution: EXT Email

Quoted 9 lines · Vladimir Oltean

Hi Allan,

Quoted 4 lines · Allan W. Nielsen

Hi Po,

Nice to see even more work on the TSN standards in the upstream

kernel.

Quoted 5 lines
Quoted 5 lines · Po Liu
Quoted 3 lines

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Introduce a ingress frame gate control flow action.
Tc gate action does the work like this:
Assume there is a gate allow specified ingress frames can be passed at specific time slot, and be dropped at specific time slot. Tc filter chooses the ingress frames, and tc gate action would specify what slot does these frames can be passed to device and what time slot would be dropped.
Tc gate action would provide an entry list to tell how much time gate keep open and how much time gate keep state close. Gate

action

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

also assign a start time to tell when the entry list start. Then driver would repeat the gate entry list cyclically.
For the software simulation, gate action requires the user assign a time clock type.

Below is the setting example in user space. Tc filter a stream source ip address is 192.168.0.20 and gate action own two time slots. One is last 200ms gate open let frame pass another is last 100ms gate close let frames dropped. When the frames have passed total frames over 8000000 bytes, frames will be dropped in one

200000000ns time slot.

Quoted 95 lines
Quoted 30 lines
Quoted 8 lines
Quoted 4 lines

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 clockid CLOCK_TAI \
          sched-entry open 200000000 -1 8000000 \
          sched-entry close 100000000 -1 -1

First of all, it is a long time since I read the 802.1Qci and when I did it, it was a draft. So please let me know if I'm completly off here.

I know you are focusing on the gate control in this patch serie, but I assume that you later will want to do the policing and flow-meter as well. And it could make sense to consider how all of this work toghether.

A common use-case for the policing is to have multiple rules pointing at the same policing instance. Maybe you want the sum of the traffic on 2 ports to be limited to 100mbit. If you specify such action on the individual rule (like done with the gate), then you can not have two rules pointing at the same policer instance.

Long storry short, have you considered if it would be better to do something like:

   tc filter add dev eth0 parent ffff: protocol ip \
            flower src_ip 192.168.0.20 \
            action psfp-id 42
Quoted 6 lines

And then have some other function to configure the properties of psfp-id 42?

/Allan

It is very good that you brought it up though, since in my opinion too it is a rather important aspect, and it seems that the fact this feature is already designed-in was a bit too subtle.

"psfp-id" is actually his "index" argument.

You can actually do this:
tc filter add dev eth0 ingress \

        flower skip_hw dst_mac 01:80:c2:00:00:0e \
        action gate index 1 clockid CLOCK_TAI \
        base-time 200000000000 \
        sched-entry OPEN 200000000 -1 -1 \
        sched-entry CLOSE 100000000 -1 -1 tc filter add dev eth0

ingress \
flower skip_hw dst_mac 01:80:c2:00:00:0f \
action gate index 1

Then 2 filters get created with the same action:

tc -s filter show dev swp2 ingress
filter protocol all pref 49151 flower chain 0 filter protocol all pref 49151 flower chain 0 handle 0x1
dst_mac 01:80:c2:00:00:0f
skip_hw
not_in_hw
action order 1:
priority wildcard clockid TAI flags 0x6404f
base-time 200000000000 cycle-time 300000000
cycle-time-ext 0
number 0 gate-state open interval 200000000
ipv wildcard max-octets wildcard
number 1 gate-state close interval 100000000
ipv wildcard max-octets wildcard
pipe
index 2 ref 2 bind 2 installed 168 sec used 168 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0

filter protocol all pref 49152 flower chain 0 filter protocol all pref 49152 flower chain 0 handle 0x1
dst_mac 01:80:c2:00:00:0e
skip_hw
not_in_hw
action order 1:
priority wildcard clockid TAI flags 0x6404f
base-time 200000000000 cycle-time 300000000
cycle-time-ext 0
number 0 gate-state open interval 200000000
ipv wildcard max-octets wildcard
number 1 gate-state close interval 100000000
ipv wildcard max-octets wildcard
pipe
index 2 ref 2 bind 2 installed 168 sec used 168 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0

Quoted 3 lines

Actually my only concern is that maybe this mechanism should (?) have been more generic. At the moment, this patch series implements it via a TCA_GATE_ENTRY_INDEX netlink attribute, so every action which

Quoted 7 lines

wants

Quoted 3 lines

to be shared across filters needs to reinvent this wheel.

Thoughts, everyone?

I don't have anything valuable to add, aside from commenting this whole thing makes my brain hurt.

Thanks for express your thoughts.

Quoted 8 lines
Quoted 3 lines

Thanks,
-Vladimir

--
Make Music, Not War

Thanks!

Quoted 9 lines

Dave Täht
CTO, TekLibre, LLC
https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww
.teklibre.com%2F&amp;data=02%7C01%7CPo.Liu%40nxp.com%7C09cf63bb 73ee4fb2e08108d7e6f8929f%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0 %7C0%7C637231827599217479&amp;sdata=u3ILmBlK6RsVYDLy9gtFythp%2 FbG2%2Bw40xea2N1sJvr4%3D&amp;reserved=0
Tel: 1-831-435-0729

Br,
Po Liu

#84 lore raw

Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

In reply to Vladimir Oltean
Quoted 33 lines · Vladimir Oltean
Quoted 33 lines
Quoted 7 lines
Quoted 3 lines

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 clockid CLOCK_TAI \
          sched-entry open 200000000 -1 8000000 \
          sched-entry close 100000000 -1 -1

First of all, it is a long time since I read the 802.1Qci and when I did it, it was a draft. So please let me know if I'm completly off here.

I know you are focusing on the gate control in this patch serie, but I assume that you later will want to do the policing and flow-meter as well. And it could make sense to consider how all of this work toghether.

A common use-case for the policing is to have multiple rules pointing at the same policing instance. Maybe you want the sum of the traffic on 2 ports to be limited to 100mbit. If you specify such action on the individual rule (like done with the gate), then you can not have two rules pointing at the same policer instance.

Long storry short, have you considered if it would be better to do something like:

   tc filter add dev eth0 parent ffff: protocol ip \
            flower src_ip 192.168.0.20 \
            action psfp-id 42

And then have some other function to configure the properties of psfp-id 42?

Quoted 8 lines
Quoted 2 lines

/Allan

It is very good that you brought it up though, since in my opinion too it is a rather important aspect, and it seems that the fact this feature is already designed-in was a bit too subtle.

"psfp-id" is actually his "index" argument.

Ahh.. Thanks for clarifying, I missed this point completly.

author
#85 lore raw

RE: [EXT] Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

In reply to Allan W. Nielsen

Hi Nielsen,

Quoted 56 lines

-----Original Message-----
From: Allan W. Nielsen <[email protected]>
Sent: 2020年4月23日 3:19
To: Po Liu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Claudiu Manoil <[email protected]>; Vladimir Oltean <[email protected]>; Alexandru Marginean <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [EXT] Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

Caution: EXT Email

Hi Po,

Nice to see even more work on the TSN standards in the upstream kernel.

Quoted 23 lines · Po Liu

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Introduce a ingress frame gate control flow action.
Tc gate action does the work like this:
Assume there is a gate allow specified ingress frames can be passed at specific time slot, and be dropped at specific time slot. Tc filter chooses the ingress frames, and tc gate action would specify what slot does these frames can be passed to device and what time slot would be dropped.
Tc gate action would provide an entry list to tell how much time gate keep open and how much time gate keep state close. Gate action also assign a start time to tell when the entry list start. Then driver would repeat the gate entry list cyclically.
For the software simulation, gate action requires the user assign a time clock type.

Below is the setting example in user space. Tc filter a stream source ip address is 192.168.0.20 and gate action own two time slots. One is last 200ms gate open let frame pass another is last 100ms gate close let frames dropped. When the frames have passed total frames over 8000000 bytes, frames will be dropped in one 200000000ns time slot.

Quoted 7 lines
Quoted 3 lines

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 clockid CLOCK_TAI \
          sched-entry open 200000000 -1 8000000 \
          sched-entry close 100000000 -1 -1
Quoted 6 lines

First of all, it is a long time since I read the 802.1Qci and when I did it, it was a draft. So please let me know if I'm completly off here.

I know you are focusing on the gate control in this patch serie, but I assume that you later will want to do the policing and flow-meter as well. And it could make sense to consider how all of this work toghether.

The gate action is the must have feature, so here is the part of it. And provide the stream filter implementation part in the driver. I provided a whole thoughts, with flow-meter apply to policing action and other throughs in the RFC version. You can look back to that version for reference.

Quoted 10 lines

A common use-case for the policing is to have multiple rules pointing at the same policing instance. Maybe you want the sum of the traffic on 2 ports to be limited to 100mbit. If you specify such action on the individual rule (like done with the gate), then you can not have two rules pointing at the same policer instance.

Long storry short, have you considered if it would be better to do something like:

Quoted 6 lines
   tc filter add dev eth0 parent ffff: protocol ip \
            flower src_ip 192.168.0.20 \
            action psfp-id 42

And then have some other function to configure the properties of psfp-id 42?

I think the psfp-id you mention is for the gate and stream filter and flow meter and stream-identify. For each they should have an index.
The stream-identify index come from the chain value. Gate index comes from the index in the gate action, two ports or more can share one same index gate index. Will same for the flow-meter action.

Quoted 3 lines

/Allan

Thanks!

Br,
Po Liu

#86 lore raw

Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

In reply to Po Liu
Quoted 20 lines · Po Liu

Introduce a ingress frame gate control flow action.
Tc gate action does the work like this:
Assume there is a gate allow specified ingress frames can be passed at specific time slot, and be dropped at specific time slot. Tc filter chooses the ingress frames, and tc gate action would specify what slot does these frames can be passed to device and what time slot would be dropped.
Tc gate action would provide an entry list to tell how much time gate keep open and how much time gate keep state close. Gate action also assign a start time to tell when the entry list start. Then driver would repeat the gate entry list cyclically.
For the software simulation, gate action requires the user assign a time clock type.

Below is the setting example in user space. Tc filter a stream source ip address is 192.168.0.20 and gate action own two time slots. One is last 200ms gate open let frame pass another is last 100ms gate close let frames dropped. When the frames have passed total frames over 8000000 bytes, frames will be dropped in one 200000000ns time slot.

Quoted 7 lines
Quoted 3 lines

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 clockid CLOCK_TAI \
	   sched-entry open 200000000 -1 8000000 \
	   sched-entry close 100000000 -1 -1

From the insight that Vladimir gave, it really makes it easier for me to understand if you added these filters and actions in two steps. The first, you would add the "time based" actions and the second you would plug the filters into the actions. And I think this would match real world usage better.

Another small usability improvement is to make the "extra" parameters to 'sched-entry close' optional, if packets that arrive during a closed gate are dropped, those parameters don't make much sense.

Quoted 602 lines
Quoted 2 lines

tc chain del dev eth0 ingress chain 0

"sched-entry" follow the name taprio style. Gate state is "open"/"close". Follow with period nanosecond. Then next item 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.
Base-time is not set will be 0 as default, as result start time would be ((N + 1) * cycletime) which is the minimal of future time.

Below example shows filtering a stream with destination mac address is 10:00:80:00:00:00 and ip type is ICMP, follow the action gate. The gate action would run with one close time slot which means always keep close. The time cycle is total 200000000ns. The base-time would calculate by:

1357000000000 + (N + 1) * cycletime

When the total value is the future time, it will be the start time. The cycletime here would be 200000000ns for this case.

Quoted 1 line

tc filter add dev eth0 parent ffff: protocol ip \

	   flower skip_hw ip_proto icmp dst_mac 10:00:80:00:00:00 \
	   action gate index 12 base-time 1357000000000 \
	   sched-entry close 200000000 -1 -1 \
	   clockid CLOCK_TAI
---
 include/net/tc_act/tc_gate.h        |  54 +++
 include/uapi/linux/pkt_cls.h        |   1 +
 include/uapi/linux/tc_act/tc_gate.h |  47 ++
 net/sched/Kconfig                   |  13 +
 net/sched/Makefile                  |   1 +
 net/sched/act_gate.c                | 647 ++++++++++++++++++++++++++++
 6 files changed, 763 insertions(+)
 create mode 100644 include/net/tc_act/tc_gate.h
 create mode 100644 include/uapi/linux/tc_act/tc_gate.h
 create mode 100644 net/sched/act_gate.c
include/net/tc_act/tc_gate.h new file +54 -0
new file mode 100644
index 000000000000..b0ace55b2aaa
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright 2020 NXP */
+
+#ifndef __NET_TC_GATE_H
+#define __NET_TC_GATE_H
+
+#include <net/act_api.h>
+#include <linux/tc_act/tc_gate.h>
+
+struct tcfg_gate_entry {
+	int			index;
+	u8			gate_state;
+	u32			interval;
+	s32			ipv;
+	s32			maxoctets;
+	struct list_head	list;
+};
+
+struct tcf_gate_params {
+	s32			tcfg_priority;
+	u64			tcfg_basetime;
+	u64			tcfg_cycletime;
+	u64			tcfg_cycletime_ext;
+	u32			tcfg_flags;
+	s32			tcfg_clockid;
+	size_t			num_entries;
+	struct list_head	entries;
+};
+
+#define GATE_ACT_GATE_OPEN	BIT(0)
+#define GATE_ACT_PENDING	BIT(1)
+struct gate_action {
+	struct tcf_gate_params param;
+	spinlock_t entry_lock;
+	u8 current_gate_status;
+	ktime_t current_close_time;
+	u32 current_entry_octets;
+	s32 current_max_octets;
+	struct tcfg_gate_entry __rcu *next_entry;
+	struct hrtimer hitimer;
+	enum tk_offsets tk_offset;
+	struct rcu_head rcu;
+};
+
+struct tcf_gate {
+	struct tc_action		common;
+	struct gate_action __rcu	*actg;
+};
+#define to_gate(a) ((struct tcf_gate *)a)
+
+#define get_gate_param(act) ((struct tcf_gate_params *)act)
+#define get_gate_action(p) ((struct gate_action *)p)
+
+#endif
include/uapi/linux/pkt_cls.h +1 -0
index 9f06d29cab70..fc672b232437 100644
@@ -134,6 +134,7 @@ enum tca_id {
 	TCA_ID_CTINFO,
 	TCA_ID_MPLS,
 	TCA_ID_CT,
+	TCA_ID_GATE,
 	/* other actions go here */
 	__TCA_ID_MAX = 255
 };
include/uapi/linux/tc_act/tc_gate.h new file +47 -0
new file mode 100644
index 000000000000..f214b3a6d44f
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
+/* Copyright 2020 NXP */
+
+#ifndef __LINUX_TC_GATE_H
+#define __LINUX_TC_GATE_H
+
+#include <linux/pkt_cls.h>
+
+struct tc_gate {
+	tc_gen;
+};
+
+enum {
+	TCA_GATE_ENTRY_UNSPEC,
+	TCA_GATE_ENTRY_INDEX,
+	TCA_GATE_ENTRY_GATE,
+	TCA_GATE_ENTRY_INTERVAL,
+	TCA_GATE_ENTRY_IPV,
+	TCA_GATE_ENTRY_MAX_OCTETS,
+	__TCA_GATE_ENTRY_MAX,
+};
+#define TCA_GATE_ENTRY_MAX (__TCA_GATE_ENTRY_MAX - 1)
+
+enum {
+	TCA_GATE_ONE_ENTRY_UNSPEC,
+	TCA_GATE_ONE_ENTRY,
+	__TCA_GATE_ONE_ENTRY_MAX,
+};
+#define TCA_GATE_ONE_ENTRY_MAX (__TCA_GATE_ONE_ENTRY_MAX - 1)
+
+enum {
+	TCA_GATE_UNSPEC,
+	TCA_GATE_TM,
+	TCA_GATE_PARMS,
+	TCA_GATE_PAD,
+	TCA_GATE_PRIORITY,
+	TCA_GATE_ENTRY_LIST,
+	TCA_GATE_BASE_TIME,
+	TCA_GATE_CYCLE_TIME,
+	TCA_GATE_CYCLE_TIME_EXT,
+	TCA_GATE_FLAGS,
+	TCA_GATE_CLOCKID,
+	__TCA_GATE_MAX,
+};
+#define TCA_GATE_MAX (__TCA_GATE_MAX - 1)
+
+#endif
net/sched/Kconfig +13 -0
index bfbefb7bff9d..1314549c7567 100644
@@ -981,6 +981,19 @@ config NET_ACT_CT
 	  To compile this code as a module, choose M here: the
 	  module will be called act_ct.
 
+config NET_ACT_GATE
+	tristate "Frame gate entry list control tc action"
+	depends on NET_CLS_ACT
+	help
+	  Say Y here to allow to control the ingress flow to be passed at
+	  specific time slot and be dropped at other specific time slot by
+	  the gate entry list. The manipulation will simulate the IEEE
+	  802.1Qci stream gate control behavior.
+
+	  If unsure, say N.
+	  To compile this code as a module, choose M here: the
+	  module will be called act_gate.
+
 config NET_IFE_SKBMARK
 	tristate "Support to encoding decoding skb mark on IFE action"
 	depends on NET_ACT_IFE
net/sched/Makefile +1 -0
index 31c367a6cd09..66bbf9a98f9e 100644
@@ -30,6 +30,7 @@ obj-$(CONFIG_NET_IFE_SKBPRIO)	+= act_meta_skbprio.o
 obj-$(CONFIG_NET_IFE_SKBTCINDEX)	+= act_meta_skbtcindex.o
 obj-$(CONFIG_NET_ACT_TUNNEL_KEY)+= act_tunnel_key.o
 obj-$(CONFIG_NET_ACT_CT)	+= act_ct.o
+obj-$(CONFIG_NET_ACT_GATE)	+= act_gate.o
 obj-$(CONFIG_NET_SCH_FIFO)	+= sch_fifo.o
 obj-$(CONFIG_NET_SCH_CBQ)	+= sch_cbq.o
 obj-$(CONFIG_NET_SCH_HTB)	+= sch_htb.o
net/sched/act_gate.c new file +394 -0
new file mode 100644
index 000000000000..e932f402b4f1
@@ -0,0 +1,647 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright 2020 NXP */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/skbuff.h>
+#include <linux/rtnetlink.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <net/act_api.h>
+#include <net/netlink.h>
+#include <net/pkt_cls.h>
+#include <net/tc_act/tc_gate.h>
+
+static unsigned int gate_net_id;
+static struct tc_action_ops act_gate_ops;
+
+static ktime_t gate_get_time(struct gate_action *gact)
+{
+	ktime_t mono = ktime_get();
+
+	switch (gact->tk_offset) {
+	case TK_OFFS_MAX:
+		return mono;
+	default:
+		return ktime_mono_to_any(mono, gact->tk_offset);
+	}
+
+	return KTIME_MAX;
+}
+
+static int gate_get_start_time(struct gate_action *gact, ktime_t *start)
+{
+	struct tcf_gate_params *param = get_gate_param(gact);
+	ktime_t now, base, cycle;
+	u64 n;
+
+	base = ns_to_ktime(param->tcfg_basetime);
+	now = gate_get_time(gact);
+
+	if (ktime_after(base, now)) {
+		*start = base;
+		return 0;
+	}
+
+	cycle = param->tcfg_cycletime;
+
+	/* cycle time should not be zero */
+	if (WARN_ON(!cycle))
+		return -EFAULT;
+
+	n = div64_u64(ktime_sub_ns(now, base), cycle);
+	*start = ktime_add_ns(base, (n + 1) * cycle);
+	return 0;
+}
+
+static void gate_start_timer(struct gate_action *gact, ktime_t start)
+{
+	ktime_t expires;
+
+	expires = hrtimer_get_expires(&gact->hitimer);
+	if (expires == 0)
+		expires = KTIME_MAX;
+
+	start = min_t(ktime_t, start, expires);
+
+	hrtimer_start(&gact->hitimer, start, HRTIMER_MODE_ABS);
+}
+
+static enum hrtimer_restart gate_timer_func(struct hrtimer *timer)
+{
+	struct gate_action *gact = container_of(timer, struct gate_action,
+						hitimer);
+	struct tcf_gate_params *p = get_gate_param(gact);
+	struct tcfg_gate_entry *next;
+	ktime_t close_time, now;
+
+	spin_lock(&gact->entry_lock);
+
+	next = rcu_dereference_protected(gact->next_entry,
+					 lockdep_is_held(&gact->entry_lock));
+
+	/* cycle start, clear pending bit, clear total octets */
+	gact->current_gate_status = next->gate_state ? GATE_ACT_GATE_OPEN : 0;
+	gact->current_entry_octets = 0;
+	gact->current_max_octets = next->maxoctets;
+
+	gact->current_close_time = ktime_add_ns(gact->current_close_time,
+						next->interval);
+
+	close_time = gact->current_close_time;
+
+	if (list_is_last(&next->list, &p->entries))
+		next = list_first_entry(&p->entries,
+					struct tcfg_gate_entry, list);
+	else
+		next = list_next_entry(next, list);
+
+	now = gate_get_time(gact);
+
+	if (ktime_after(now, close_time)) {
+		ktime_t cycle, base;
+		u64 n;
+
+		cycle = p->tcfg_cycletime;
+		base = ns_to_ktime(p->tcfg_basetime);
+		n = div64_u64(ktime_sub_ns(now, base), cycle);
+		close_time = ktime_add_ns(base, (n + 1) * cycle);
+	}
+
+	rcu_assign_pointer(gact->next_entry, next);
+	spin_unlock(&gact->entry_lock);
+
+	hrtimer_set_expires(&gact->hitimer, close_time);
+
+	return HRTIMER_RESTART;
+}
+
+static int tcf_gate_act(struct sk_buff *skb, const struct tc_action *a,
+			struct tcf_result *res)
+{
+	struct tcf_gate *g = to_gate(a);
+	struct gate_action *gact;
+	int action;
+
+	tcf_lastuse_update(&g->tcf_tm);
+	bstats_cpu_update(this_cpu_ptr(g->common.cpu_bstats), skb);
+
+	action = READ_ONCE(g->tcf_action);
+	rcu_read_lock();
+	gact = rcu_dereference_bh(g->actg);
+	if (unlikely(gact->current_gate_status & GATE_ACT_PENDING)) {
+		rcu_read_unlock();
+		return action;
+	}
+
+	if (!(gact->current_gate_status & GATE_ACT_GATE_OPEN))
+		goto drop;
+
+	if (gact->current_max_octets >= 0) {
+		gact->current_entry_octets += qdisc_pkt_len(skb);
+		if (gact->current_entry_octets > gact->current_max_octets) {
+			qstats_overlimit_inc(this_cpu_ptr(g->common.cpu_qstats));
+			goto drop;
+		}
+	}
+	rcu_read_unlock();
+
+	return action;
+drop:
+	rcu_read_unlock();
+	qstats_drop_inc(this_cpu_ptr(g->common.cpu_qstats));
+	return TC_ACT_SHOT;
+}
+
+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),
+					    .type = NLA_EXACT_LEN },
+	[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;
+
+	entry->gate_state = nla_get_flag(tb[TCA_GATE_ENTRY_GATE]);
+
+	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;
+	}
+
+	entry->interval = interval;
+
+	if (tb[TCA_GATE_ENTRY_IPV])
+		entry->ipv = nla_get_s32(tb[TCA_GATE_ENTRY_IPV]);
+	else
+		entry->ipv = -1;
+
+	if (tb[TCA_GATE_ENTRY_MAX_OCTETS])
+		entry->maxoctets = nla_get_s32(tb[TCA_GATE_ENTRY_MAX_OCTETS]);
+	else
+		entry->maxoctets = -1;
+
+	return 0;
+}
+
+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(tb, TCA_GATE_ENTRY_MAX, n, entry_policy, extack);
+	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);
+}
+
+static int parse_gate_list(struct nlattr *list_attr,
+			   struct tcf_gate_params *sched,
+			   struct netlink_ext_ack *extack)
+{
+	struct tcfg_gate_entry *entry, *e;
+	struct nlattr *n;
+	int err, rem;
+	int i = 0;
+
+	if (!list_attr)
+		return -EINVAL;
+
+	nla_for_each_nested(n, list_attr, rem) {
+		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");
+			err = -ENOMEM;
+			goto release_list;
+		}
+
+		err = parse_gate_entry(n, entry, i, extack);
+		if (err < 0) {
+			kfree(entry);
+			goto release_list;
+		}
+
+		list_add_tail(&entry->list, &sched->entries);
+		i++;
+	}
+
+	sched->num_entries = i;
+
+	return i;
+
+release_list:
+	list_for_each_entry_safe(entry, e, &sched->entries, list) {
+		list_del(&entry->list);
+		kfree(entry);
+	}
+
+	return err;
+}
+
+static int tcf_gate_init(struct net *net, struct nlattr *nla,
+			 struct nlattr *est, struct tc_action **a,
+			 int ovr, int bind, bool rtnl_held,
+			 struct tcf_proto *tp, u32 flags,
+			 struct netlink_ext_ack *extack)
+{
+	struct tc_action_net *tn = net_generic(net, gate_net_id);
+	enum tk_offsets tk_offset = TK_OFFS_TAI;
+	struct nlattr *tb[TCA_GATE_MAX + 1];
+	struct tcf_chain *goto_ch = NULL;
+	struct tcfg_gate_entry *next;
+	struct tcf_gate_params *p;
+	struct gate_action *gact;
+	s32 clockid = CLOCK_TAI;
+	struct tc_gate *parm;
+	struct tcf_gate *g;
+	int ret = 0, err;
+	u64 basetime = 0;
+	u32 gflags = 0;
+	s32 prio = -1;
+	ktime_t start;
+	u32 index;
+
+	if (!nla)
+		return -EINVAL;
+
+	err = nla_parse_nested(tb, TCA_GATE_MAX, nla, gate_policy, extack);
+	if (err < 0)
+		return err;
+
+	if (!tb[TCA_GATE_PARMS])
+		return -EINVAL;
+	parm = nla_data(tb[TCA_GATE_PARMS]);
+	index = parm->index;
+	err = tcf_idr_check_alloc(tn, &index, a, bind);
+	if (err < 0)
+		return err;
+
+	if (err && bind)
+		return 0;
+
+	if (!err) {
+		ret = tcf_idr_create_from_flags(tn, index, est, a,
+						&act_gate_ops, bind, flags);
+		if (ret) {
+			tcf_idr_cleanup(tn, index);
+			return ret;
+		}
+
+		ret = ACT_P_CREATED;
+	} else if (!ovr) {
+		tcf_idr_release(*a, bind);
+		return -EEXIST;
+	}
+
+	if (tb[TCA_GATE_PRIORITY])
+		prio = nla_get_s32(tb[TCA_GATE_PRIORITY]);
+
+	if (tb[TCA_GATE_BASE_TIME])
+		basetime = nla_get_u64(tb[TCA_GATE_BASE_TIME]);
+
+	if (tb[TCA_GATE_FLAGS])
+		gflags = nla_get_u32(tb[TCA_GATE_FLAGS]);
+
+	if (tb[TCA_GATE_CLOCKID]) {
+		clockid = nla_get_s32(tb[TCA_GATE_CLOCKID]);
+		switch (clockid) {
+		case CLOCK_REALTIME:
+			tk_offset = TK_OFFS_REAL;
+			break;
+		case CLOCK_MONOTONIC:
+			tk_offset = TK_OFFS_MAX;
+			break;
+		case CLOCK_BOOTTIME:
+			tk_offset = TK_OFFS_BOOT;
+			break;
+		case CLOCK_TAI:
+			tk_offset = TK_OFFS_TAI;
+			break;
+		default:
+			NL_SET_ERR_MSG(extack, "Invalid 'clockid'");
+			goto release_idr;
+		}
+	}
+
+	err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack);
+	if (err < 0)
+		goto release_idr;
+
+	g = to_gate(*a);
+
+	gact = kzalloc(sizeof(*gact), GFP_KERNEL);
+	if (!gact) {
+		err = -ENOMEM;
+		goto put_chain;
+	}
+
+	p = get_gate_param(gact);
+
+	INIT_LIST_HEAD(&p->entries);
+	if (tb[TCA_GATE_ENTRY_LIST]) {
+		err = parse_gate_list(tb[TCA_GATE_ENTRY_LIST], p, extack);
+		if (err < 0)
+			goto release_mem;
+	}
+
+	if (tb[TCA_GATE_CYCLE_TIME]) {
+		p->tcfg_cycletime = nla_get_u64(tb[TCA_GATE_CYCLE_TIME]);
+	} else {
+		struct tcfg_gate_entry *entry;
+		ktime_t cycle = 0;
+
+		list_for_each_entry(entry, &p->entries, list)
+			cycle = ktime_add_ns(cycle, entry->interval);
+		p->tcfg_cycletime = cycle;
+	}
+
+	if (tb[TCA_GATE_CYCLE_TIME_EXT])
+		p->tcfg_cycletime_ext =
+			nla_get_u64(tb[TCA_GATE_CYCLE_TIME_EXT]);
+

net/sched/act_gate.c line 404

Quoted 10 lines
net/sched/act_gate.c new file +10 -0
+	p->tcfg_priority = prio;
+	p->tcfg_basetime = basetime;
+	p->tcfg_clockid = clockid;
+	p->tcfg_flags = gflags;
+
+	gact->tk_offset = tk_offset;
+	spin_lock_init(&gact->entry_lock);
+	hrtimer_init(&gact->hitimer, clockid, HRTIMER_MODE_ABS);
+	gact->hitimer.function = gate_timer_func;
+

One idea that just happened, if you find a way to enable RX timestamping and can rely that all packets have a timestamp, the code can simplified a lot. You wouldn't need any hrtimers, and deciding to drop or not a packet becomes a couple of mathematical operations. Seems worth a thought.

The real question is: if requiring for the driver to support at least software RX timestamping is excessive (doesn't seem so to me).

Cheers,

Signature · 1 line
Vinicius
#87 lore raw

Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

Quoted 9 lines · Vinicius Costa Gomes

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 5 lines · Po Liu
Quoted 1 line

tc filter add dev eth0 parent ffff: protocol ip \

         flower src_ip 192.168.0.20 \
         action gate index 2 clockid CLOCK_TAI \
         sched-entry open 200000000 -1 8000000 \
         sched-entry close 100000000 -1 -1
Quoted 5 lines

From the insight that Vladimir gave, it really makes it easier for me to understand if you added these filters and actions in two steps. The first, you would add the "time based" actions and the second you would plug the filters into the actions. And I think this would match real world usage better.

I agree.

/Allan

author
#88 lore raw

RE: [EXT] Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

In reply to Vinicius Costa Gomes

Hi Vinicius,

Quoted 57 lines

-----Original Message-----
From: Vinicius Costa Gomes <[email protected]>
Sent: 2020年4月24日 1:38
To: Po Liu <[email protected]>; [email protected]; linux- [email protected]; [email protected]
Cc: Po Liu <[email protected]>; Claudiu Manoil <[email protected]>; Vladimir Oltean <[email protected]>; Alexandru Marginean <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Po Liu <[email protected]>
Subject: [EXT] Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

Caution: EXT Email

Quoted 20 lines · Po Liu

Introduce a ingress frame gate control flow action.
Tc gate action does the work like this:
Assume there is a gate allow specified ingress frames can be passed at specific time slot, and be dropped at specific time slot. Tc filter chooses the ingress frames, and tc gate action would specify what slot does these frames can be passed to device and what time slot would be dropped.
Tc gate action would provide an entry list to tell how much time gate keep open and how much time gate keep state close. Gate action also assign a start time to tell when the entry list start. Then driver would repeat the gate entry list cyclically.
For the software simulation, gate action requires the user assign a time clock type.

Below is the setting example in user space. Tc filter a stream source ip address is 192.168.0.20 and gate action own two time slots. One is last 200ms gate open let frame pass another is last 100ms gate close let frames dropped. When the frames have passed total frames over 8000000 bytes, frames will be dropped in one 200000000ns time slot.

Quoted 7 lines
Quoted 3 lines

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 clockid CLOCK_TAI \
         sched-entry open 200000000 -1 8000000 \
         sched-entry close 100000000 -1 -1

From the insight that Vladimir gave, it really makes it easier for me to understand if you added these filters and actions in two steps. The first, you would add the "time based" actions and the second you would plug the filters into the actions. And I think this would match real world usage better.

Quoted 4 lines

Another small usability improvement is to make the "extra" parameters to 'sched-entry close' optional, if packets that arrive during a closed gate are dropped, those parameters don't make much sense.

This is make sense. Vladmir Oltean also suggest to default value if not set the last two parameters. I would modify it on the user space iproute2 patch.

Quoted 610 lines
Quoted 12 lines
Quoted 2 lines

tc chain del dev eth0 ingress chain 0

"sched-entry" follow the name taprio style. Gate state is "open"/"close". Follow with period nanosecond. Then next item 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.
Base-time is not set will be 0 as default, as result start time would be ((N + 1) * cycletime) which is the minimal of future time.

Quoted 3 lines

Below example shows filtering a stream with destination mac address is 10:00:80:00:00:00 and ip type is ICMP, follow the action gate. The gate action would run with one close time slot which means always keep

close.

Quoted 87 lines

The time cycle is total 200000000ns. The base-time would calculate by:

1357000000000 + (N + 1) * cycletime

When the total value is the future time, it will be the start time. The cycletime here would be 200000000ns for this case.

Quoted 1 line

tc filter add dev eth0 parent ffff: protocol ip \

         flower skip_hw ip_proto icmp dst_mac 10:00:80:00:00:00 \
         action gate index 12 base-time 1357000000000 \
         sched-entry close 200000000 -1 -1 \
         clockid CLOCK_TAI
---
 include/net/tc_act/tc_gate.h        |  54 +++
 include/uapi/linux/pkt_cls.h        |   1 +
 include/uapi/linux/tc_act/tc_gate.h |  47 ++
 net/sched/Kconfig                   |  13 +
 net/sched/Makefile                  |   1 +
 net/sched/act_gate.c                | 647 ++++++++++++++++++++++++++++
 6 files changed, 763 insertions(+)
 create mode 100644 include/net/tc_act/tc_gate.h  create mode 100644
include/uapi/linux/tc_act/tc_gate.h
 create mode 100644 net/sched/act_gate.c
(quoted diff) +0 -0

b/include/net/tc_act/tc_gate.h new file mode 100644 index 000000000000..b0ace55b2aaa

include/net/tc_act/tc_gate.h new file +54 -0
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright 2020 NXP */
+
+#ifndef __NET_TC_GATE_H
+#define __NET_TC_GATE_H
+
+#include <net/act_api.h>
+#include <linux/tc_act/tc_gate.h>
+
+struct tcfg_gate_entry {
+     int                     index;
+     u8                      gate_state;
+     u32                     interval;
+     s32                     ipv;
+     s32                     maxoctets;
+     struct list_head        list;
+};
+
+struct tcf_gate_params {
+     s32                     tcfg_priority;
+     u64                     tcfg_basetime;
+     u64                     tcfg_cycletime;
+     u64                     tcfg_cycletime_ext;
+     u32                     tcfg_flags;
+     s32                     tcfg_clockid;
+     size_t                  num_entries;
+     struct list_head        entries;
+};
+
+#define GATE_ACT_GATE_OPEN   BIT(0)
+#define GATE_ACT_PENDING     BIT(1)
+struct gate_action {
+     struct tcf_gate_params param;
+     spinlock_t entry_lock;
+     u8 current_gate_status;
+     ktime_t current_close_time;
+     u32 current_entry_octets;
+     s32 current_max_octets;
+     struct tcfg_gate_entry __rcu *next_entry;
+     struct hrtimer hitimer;
+     enum tk_offsets tk_offset;
+     struct rcu_head rcu;
+};
+
+struct tcf_gate {
+     struct tc_action                common;
+     struct gate_action __rcu        *actg;
+};
+#define to_gate(a) ((struct tcf_gate *)a)
+
+#define get_gate_param(act) ((struct tcf_gate_params *)act) #define
+get_gate_action(p) ((struct gate_action *)p)
+
+#endif
(quoted diff) +0 -0
Quoted 1 line

b/include/uapi/linux/pkt_cls.h index 9f06d29cab70..fc672b232437

100644

Quoted 36 lines
include/uapi/linux/pkt_cls.h +1 -0
@@ -134,6 +134,7 @@ enum tca_id {
      TCA_ID_CTINFO,
      TCA_ID_MPLS,
      TCA_ID_CT,
+     TCA_ID_GATE,
      /* other actions go here */
      __TCA_ID_MAX = 255
 };
include/uapi/linux/tc_act/tc_gate.h new file +19 -0
new file mode 100644
index 000000000000..f214b3a6d44f
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
+/* Copyright 2020 NXP */
+
+#ifndef __LINUX_TC_GATE_H
+#define __LINUX_TC_GATE_H
+
+#include <linux/pkt_cls.h>
+
+struct tc_gate {
+     tc_gen;
+};
+
+enum {
+     TCA_GATE_ENTRY_UNSPEC,
+     TCA_GATE_ENTRY_INDEX,
+     TCA_GATE_ENTRY_GATE,
+     TCA_GATE_ENTRY_INTERVAL,
+     TCA_GATE_ENTRY_IPV,
+     TCA_GATE_ENTRY_MAX_OCTETS,

include/uapi/linux/tc_act/tc_gate.h line 29

Quoted 10 lines
include/uapi/linux/tc_act/tc_gate.h new file +10 -0
+     __TCA_GATE_ENTRY_MAX,
+};
+#define TCA_GATE_ENTRY_MAX (__TCA_GATE_ENTRY_MAX - 1)
+
+enum {
+     TCA_GATE_ONE_ENTRY_UNSPEC,
+     TCA_GATE_ONE_ENTRY,
+     __TCA_GATE_ONE_ENTRY_MAX,
+};
+#define TCA_GATE_ONE_ENTRY_MAX (__TCA_GATE_ONE_ENTRY_MAX

- 1)

net/sched/Makefile obj-$(CONFIG_NET_IFE_SKBPRIO) +=

Quoted 47 lines
include/uapi/linux/tc_act/tc_gate.h new file +18 -0
+
+enum {
+     TCA_GATE_UNSPEC,
+     TCA_GATE_TM,
+     TCA_GATE_PARMS,
+     TCA_GATE_PAD,
+     TCA_GATE_PRIORITY,
+     TCA_GATE_ENTRY_LIST,
+     TCA_GATE_BASE_TIME,
+     TCA_GATE_CYCLE_TIME,
+     TCA_GATE_CYCLE_TIME_EXT,
+     TCA_GATE_FLAGS,
+     TCA_GATE_CLOCKID,
+     __TCA_GATE_MAX,
+};
+#define TCA_GATE_MAX (__TCA_GATE_MAX - 1)
+
+#endif
net/sched/Kconfig index renamed from net/sched/Kconfig +0 -0

bfbefb7bff9d..1314549c7567 100644

net/sched/Kconfig +13 -0
@@ -981,6 +981,19 @@ config NET_ACT_CT
        To compile this code as a module, choose M here: the
        module will be called act_ct.
 
+config NET_ACT_GATE
+     tristate "Frame gate entry list control tc action"
+     depends on NET_CLS_ACT
+     help
+       Say Y here to allow to control the ingress flow to be passed at
+       specific time slot and be dropped at other specific time slot by
+       the gate entry list. The manipulation will simulate the IEEE
+       802.1Qci stream gate control behavior.
+
+       If unsure, say N.
+       To compile this code as a module, choose M here: the
+       module will be called act_gate.
+
 config NET_IFE_SKBMARK
      tristate "Support to encoding decoding skb mark on IFE action"
      depends on NET_ACT_IFE
net/sched/Makefile index renamed from net/sched/Makefile +0 -0

31c367a6cd09..66bbf9a98f9e 100644

net/sched/Makefile +0 -0
@@ -30,6 +30,7 @@ obj-$(CONFIG_NET_IFE_SKBPRIO)       +=

act_meta_skbprio.o

Quoted 87 lines
net/sched/Makefile +1 -0
 obj-$(CONFIG_NET_IFE_SKBTCINDEX)     += act_meta_skbtcindex.o
 obj-$(CONFIG_NET_ACT_TUNNEL_KEY)+= act_tunnel_key.o
 obj-$(CONFIG_NET_ACT_CT)     += act_ct.o
+obj-$(CONFIG_NET_ACT_GATE)   += act_gate.o
 obj-$(CONFIG_NET_SCH_FIFO)   += sch_fifo.o
 obj-$(CONFIG_NET_SCH_CBQ)    += sch_cbq.o
 obj-$(CONFIG_NET_SCH_HTB)    += sch_htb.o
net/sched/act_gate.c new file mode renamed from net/sched/act_gate.c +0 -0

100644 index 000000000000..e932f402b4f1

net/sched/act_gate.c new file +75 -0
@@ -0,0 +1,647 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright 2020 NXP */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/skbuff.h>
+#include <linux/rtnetlink.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <net/act_api.h>
+#include <net/netlink.h>
+#include <net/pkt_cls.h>
+#include <net/tc_act/tc_gate.h>
+
+static unsigned int gate_net_id;
+static struct tc_action_ops act_gate_ops;
+
+static ktime_t gate_get_time(struct gate_action *gact) {
+     ktime_t mono = ktime_get();
+
+     switch (gact->tk_offset) {
+     case TK_OFFS_MAX:
+             return mono;
+     default:
+             return ktime_mono_to_any(mono, gact->tk_offset);
+     }
+
+     return KTIME_MAX;
+}
+
+static int gate_get_start_time(struct gate_action *gact, ktime_t
+*start) {
+     struct tcf_gate_params *param = get_gate_param(gact);
+     ktime_t now, base, cycle;
+     u64 n;
+
+     base = ns_to_ktime(param->tcfg_basetime);
+     now = gate_get_time(gact);
+
+     if (ktime_after(base, now)) {
+             *start = base;
+             return 0;
+     }
+
+     cycle = param->tcfg_cycletime;
+
+     /* cycle time should not be zero */
+     if (WARN_ON(!cycle))
+             return -EFAULT;
+
+     n = div64_u64(ktime_sub_ns(now, base), cycle);
+     *start = ktime_add_ns(base, (n + 1) * cycle);
+     return 0;
+}
+
+static void gate_start_timer(struct gate_action *gact, ktime_t start)
+{
+     ktime_t expires;
+
+     expires = hrtimer_get_expires(&gact->hitimer);
+     if (expires == 0)
+             expires = KTIME_MAX;
+
+     start = min_t(ktime_t, start, expires);
+
+     hrtimer_start(&gact->hitimer, start, HRTIMER_MODE_ABS); }
+
+static enum hrtimer_restart gate_timer_func(struct hrtimer *timer) {
+     struct gate_action *gact = container_of(timer, struct gate_action,
+                                             hitimer);
+     struct tcf_gate_params *p = get_gate_param(gact);
+     struct tcfg_gate_entry *next;

net/sched/act_gate.c line 85

Quoted 10 lines
net/sched/act_gate.c new file +10 -0
+     ktime_t close_time, now;
+
+     spin_lock(&gact->entry_lock);
+
+     next = rcu_dereference_protected(gact->next_entry,
+
+ lockdep_is_held(&gact->entry_lock));
+
+     /* cycle start, clear pending bit, clear total octets */
+     gact->current_gate_status = next->gate_state ?

GATE_ACT_GATE_OPEN : 0;

Quoted 61 lines
net/sched/act_gate.c new file +61 -0
+     gact->current_entry_octets = 0;
+     gact->current_max_octets = next->maxoctets;
+
+     gact->current_close_time = ktime_add_ns(gact->current_close_time,
+                                             next->interval);
+
+     close_time = gact->current_close_time;
+
+     if (list_is_last(&next->list, &p->entries))
+             next = list_first_entry(&p->entries,
+                                     struct tcfg_gate_entry, list);
+     else
+             next = list_next_entry(next, list);
+
+     now = gate_get_time(gact);
+
+     if (ktime_after(now, close_time)) {
+             ktime_t cycle, base;
+             u64 n;
+
+             cycle = p->tcfg_cycletime;
+             base = ns_to_ktime(p->tcfg_basetime);
+             n = div64_u64(ktime_sub_ns(now, base), cycle);
+             close_time = ktime_add_ns(base, (n + 1) * cycle);
+     }
+
+     rcu_assign_pointer(gact->next_entry, next);
+     spin_unlock(&gact->entry_lock);
+
+     hrtimer_set_expires(&gact->hitimer, close_time);
+
+     return HRTIMER_RESTART;
+}
+
+static int tcf_gate_act(struct sk_buff *skb, const struct tc_action *a,
+                     struct tcf_result *res) {
+     struct tcf_gate *g = to_gate(a);
+     struct gate_action *gact;
+     int action;
+
+     tcf_lastuse_update(&g->tcf_tm);
+     bstats_cpu_update(this_cpu_ptr(g->common.cpu_bstats), skb);
+
+     action = READ_ONCE(g->tcf_action);
+     rcu_read_lock();
+     gact = rcu_dereference_bh(g->actg);
+     if (unlikely(gact->current_gate_status & GATE_ACT_PENDING)) {
+             rcu_read_unlock();
+             return action;
+     }
+
+     if (!(gact->current_gate_status & GATE_ACT_GATE_OPEN))
+             goto drop;
+
+     if (gact->current_max_octets >= 0) {
+             gact->current_entry_octets += qdisc_pkt_len(skb);
+             if (gact->current_entry_octets > gact->current_max_octets) {
+                     qstats_overlimit_inc(this_cpu_ptr(g->common.cpu_qstats));
+                     goto drop;
+             }
+     }

net/sched/act_gate.c

Quoted 10 lines
net/sched/act_gate.c new file +10 -0
+     rcu_read_unlock();
+
+     return action;
+drop:
+     rcu_read_unlock();
+     qstats_drop_inc(this_cpu_ptr(g->common.cpu_qstats));
+     return TC_ACT_SHOT;
+}
+
+static const struct nla_policy entry_policy[TCA_GATE_ENTRY_MAX + 1]

= {

Quoted 32 lines
net/sched/act_gate.c new file +32 -0
+     [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),
+                                         .type = NLA_EXACT_LEN },
+     [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;
+
+     entry->gate_state = nla_get_flag(tb[TCA_GATE_ENTRY_GATE]);
+
+     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;
+     }

net/sched/act_gate.c

Quoted 10 lines
net/sched/act_gate.c new file +10 -0
+
+     entry->interval = interval;
+
+     if (tb[TCA_GATE_ENTRY_IPV])
+             entry->ipv = nla_get_s32(tb[TCA_GATE_ENTRY_IPV]);
+     else
+             entry->ipv = -1;
+
+     if (tb[TCA_GATE_ENTRY_MAX_OCTETS])
+             entry->maxoctets =

nla_get_s32(tb[TCA_GATE_ENTRY_MAX_OCTETS]);

net/sched/act_gate.c

Quoted 7 lines
net/sched/act_gate.c new file +7 -0
+     else
+             entry->maxoctets = -1;
+
+     return 0;
+}
+
+static int parse_gate_entry(struct nlattr *n, struct  tcfg_gate_entry

*entry,

net/sched/act_gate.c

Quoted 5 lines
net/sched/act_gate.c new file +5 -0
+                         int index, struct netlink_ext_ack *extack) {
+     struct nlattr *tb[TCA_GATE_ENTRY_MAX + 1] = { };
+     int err;
+
+     err = nla_parse_nested(tb, TCA_GATE_ENTRY_MAX, n, entry_policy,

extack);

Quoted 183 lines
net/sched/act_gate.c new file +183 -0
+     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); }
+
+static int parse_gate_list(struct nlattr *list_attr,
+                        struct tcf_gate_params *sched,
+                        struct netlink_ext_ack *extack) {
+     struct tcfg_gate_entry *entry, *e;
+     struct nlattr *n;
+     int err, rem;
+     int i = 0;
+
+     if (!list_attr)
+             return -EINVAL;
+
+     nla_for_each_nested(n, list_attr, rem) {
+             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");
+                     err = -ENOMEM;
+                     goto release_list;
+             }
+
+             err = parse_gate_entry(n, entry, i, extack);
+             if (err < 0) {
+                     kfree(entry);
+                     goto release_list;
+             }
+
+             list_add_tail(&entry->list, &sched->entries);
+             i++;
+     }
+
+     sched->num_entries = i;
+
+     return i;
+
+release_list:
+     list_for_each_entry_safe(entry, e, &sched->entries, list) {
+             list_del(&entry->list);
+             kfree(entry);
+     }
+
+     return err;
+}
+
+static int tcf_gate_init(struct net *net, struct nlattr *nla,
+                      struct nlattr *est, struct tc_action **a,
+                      int ovr, int bind, bool rtnl_held,
+                      struct tcf_proto *tp, u32 flags,
+                      struct netlink_ext_ack *extack) {
+     struct tc_action_net *tn = net_generic(net, gate_net_id);
+     enum tk_offsets tk_offset = TK_OFFS_TAI;
+     struct nlattr *tb[TCA_GATE_MAX + 1];
+     struct tcf_chain *goto_ch = NULL;
+     struct tcfg_gate_entry *next;
+     struct tcf_gate_params *p;
+     struct gate_action *gact;
+     s32 clockid = CLOCK_TAI;
+     struct tc_gate *parm;
+     struct tcf_gate *g;
+     int ret = 0, err;
+     u64 basetime = 0;
+     u32 gflags = 0;
+     s32 prio = -1;
+     ktime_t start;
+     u32 index;
+
+     if (!nla)
+             return -EINVAL;
+
+     err = nla_parse_nested(tb, TCA_GATE_MAX, nla, gate_policy, extack);
+     if (err < 0)
+             return err;
+
+     if (!tb[TCA_GATE_PARMS])
+             return -EINVAL;
+     parm = nla_data(tb[TCA_GATE_PARMS]);
+     index = parm->index;
+     err = tcf_idr_check_alloc(tn, &index, a, bind);
+     if (err < 0)
+             return err;
+
+     if (err && bind)
+             return 0;
+
+     if (!err) {
+             ret = tcf_idr_create_from_flags(tn, index, est, a,
+                                             &act_gate_ops, bind, flags);
+             if (ret) {
+                     tcf_idr_cleanup(tn, index);
+                     return ret;
+             }
+
+             ret = ACT_P_CREATED;
+     } else if (!ovr) {
+             tcf_idr_release(*a, bind);
+             return -EEXIST;
+     }
+
+     if (tb[TCA_GATE_PRIORITY])
+             prio = nla_get_s32(tb[TCA_GATE_PRIORITY]);
+
+     if (tb[TCA_GATE_BASE_TIME])
+             basetime = nla_get_u64(tb[TCA_GATE_BASE_TIME]);
+
+     if (tb[TCA_GATE_FLAGS])
+             gflags = nla_get_u32(tb[TCA_GATE_FLAGS]);
+
+     if (tb[TCA_GATE_CLOCKID]) {
+             clockid = nla_get_s32(tb[TCA_GATE_CLOCKID]);
+             switch (clockid) {
+             case CLOCK_REALTIME:
+                     tk_offset = TK_OFFS_REAL;
+                     break;
+             case CLOCK_MONOTONIC:
+                     tk_offset = TK_OFFS_MAX;
+                     break;
+             case CLOCK_BOOTTIME:
+                     tk_offset = TK_OFFS_BOOT;
+                     break;
+             case CLOCK_TAI:
+                     tk_offset = TK_OFFS_TAI;
+                     break;
+             default:
+                     NL_SET_ERR_MSG(extack, "Invalid 'clockid'");
+                     goto release_idr;
+             }
+     }
+
+     err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack);
+     if (err < 0)
+             goto release_idr;
+
+     g = to_gate(*a);
+
+     gact = kzalloc(sizeof(*gact), GFP_KERNEL);
+     if (!gact) {
+             err = -ENOMEM;
+             goto put_chain;
+     }
+
+     p = get_gate_param(gact);
+
+     INIT_LIST_HEAD(&p->entries);
+     if (tb[TCA_GATE_ENTRY_LIST]) {
+             err = parse_gate_list(tb[TCA_GATE_ENTRY_LIST], p, extack);
+             if (err < 0)
+                     goto release_mem;
+     }
+
+     if (tb[TCA_GATE_CYCLE_TIME]) {
+             p->tcfg_cycletime = nla_get_u64(tb[TCA_GATE_CYCLE_TIME]);
+     } else {
+             struct tcfg_gate_entry *entry;
+             ktime_t cycle = 0;
+
+             list_for_each_entry(entry, &p->entries, list)
+                     cycle = ktime_add_ns(cycle, entry->interval);
+             p->tcfg_cycletime = cycle;
+     }
+
+     if (tb[TCA_GATE_CYCLE_TIME_EXT])
+             p->tcfg_cycletime_ext =
+                     nla_get_u64(tb[TCA_GATE_CYCLE_TIME_EXT]);
+
+     p->tcfg_priority = prio;
+     p->tcfg_basetime = basetime;
+     p->tcfg_clockid = clockid;
+     p->tcfg_flags = gflags;
+
+     gact->tk_offset = tk_offset;
+     spin_lock_init(&gact->entry_lock);
Quoted 8 lines

net/sched/act_gate.c line 404

Quoted 3 lines
net/sched/act_gate.c new file +3 -0
+     hrtimer_init(&gact->hitimer, clockid, HRTIMER_MODE_ABS);
+     gact->hitimer.function = gate_timer_func;
+

One idea that just happened, if you find a way to enable RX timestamping and can rely that all packets have a timestamp, the code can simplified a lot. You wouldn't need any hrtimers, and deciding to drop or not a packet becomes a couple of mathematical operations. Seems worth a thought.

Thanks for the different ideas. The basic problem is we need to know now is a close time or open time in action. But I still don't know a better way than hrtimer to set the flag.

Quoted 3 lines

The real question is: if requiring for the driver to support at least software RX timestamping is excessive (doesn't seem so to me).

I understand.

Quoted 5 lines

Cheers,
--
Vinicius

Thanks a lot!

Br,
Po Liu

#89 lore raw

RE: [EXT] Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

Quoted 9 lines · Po Liu
Quoted 5 lines

One idea that just happened, if you find a way to enable RX timestamping and can rely that all packets have a timestamp, the code can simplified a lot. You wouldn't need any hrtimers, and deciding to drop or not a packet becomes a couple of mathematical operations. Seems worth a thought.

Thanks for the different ideas. The basic problem is we need to know now is a close time or open time in action. But I still don't know a better way than hrtimer to set the flag.

That's the point, if you have the timestamp of when the packet arrived, you can calculate if the gate is open and closed at that point. You don't need to know "now", you work only in terms of "skb->tstamp" (supposing that's where the timestamp is stored). In other words, it doesn't matter when the packet arrives at the qdisc action, but when it arrived at the controller, and the actions should be taken based on that time.

Quoted 17 lines
Quoted 4 lines

The real question is: if requiring for the driver to support at least software RX timestamping is excessive (doesn't seem so to me).

I understand.

Quoted 5 lines

Cheers,
--
Vinicius

Thanks a lot!

Br,
Po Liu

Signature · 1 line
Vinicius
author
#90 lore raw

RE: [EXT] Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

Br,
Po Liu

Quoted 33 lines

-----Original Message-----
From: Vinicius Costa Gomes <[email protected]>
Sent: 2020年4月25日 1:41
To: Po Liu <[email protected]>; [email protected]; linux- [email protected]; [email protected]
Cc: Claudiu Manoil <[email protected]>; Vladimir Oltean <[email protected]>; Alexandru Marginean <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [EXT] Re: [v3,net-next 1/4] net: qos: introduce a gate control flow action

Caution: EXT Email

Quoted 5 lines · Po Liu
Quoted 5 lines

One idea that just happened, if you find a way to enable RX timestamping and can rely that all packets have a timestamp, the code can simplified a lot. You wouldn't need any hrtimers, and deciding to drop or not a packet becomes a couple of mathematical operations.

Seems worth a thought.

Quoted 4 lines

Thanks for the different ideas. The basic problem is we need to know now is a close time or open time in action. But I still don't know a better way than hrtimer to set the flag.

Quoted 7 lines

That's the point, if you have the timestamp of when the packet arrived, you can calculate if the gate is open and closed at that point. You don't need to know "now", you work only in terms of "skb->tstamp" (supposing that's where the timestamp is stored). In other words, it doesn't matter when the packet arrives at the qdisc action, but when it arrived at the controller, and the actions should be taken based on that time.

I get your idea. But that would rely on the software timestamping on driver to be set. By set all streams or by filtered stream each time set with tc flower filter. Also how the virtue net fix it is unknow.

Quoted 21 lines
Quoted 10 lines
Quoted 5 lines

The real question is: if requiring for the driver to support at least software RX timestamping is excessive (doesn't seem so to me).

I understand.

Quoted 2 lines
Quoted 8 lines
Quoted 3 lines

Cheers,
--
Vinicius

Thanks a lot!

Br,
Po Liu

--
Vinicius

author
#91 lore raw

PATCH v3 2/4 net: schedule: add action gate offloading

In reply to Po Liu

Add the gate action to the flow action entry. Add the gate parameters to the tc_setup_flow_action() queueing to the entries of flow_action_entry array provide to the driver.

---
 include/net/flow_offload.h   |  10 +++
 include/net/tc_act/tc_gate.h | 115 +++++++++++++++++++++++++++++++++++
 net/sched/cls_api.c          |  33 ++++++++++
 3 files changed, 158 insertions(+)
include/net/flow_offload.h +10 -0
index 3619c6acf60f..94a30fe02e6d 100644
@@ -147,6 +147,7 @@ enum flow_action_id {
 	FLOW_ACTION_MPLS_PUSH,
 	FLOW_ACTION_MPLS_POP,
 	FLOW_ACTION_MPLS_MANGLE,
+	FLOW_ACTION_GATE,
 	NUM_FLOW_ACTIONS,
 };
 
@@ -255,6 +256,15 @@ struct flow_action_entry {
 			u8		bos;
 			u8		ttl;
 		} mpls_mangle;
+		struct {
+			u32		index;
+			s32		prio;
+			u64		basetime;
+			u64		cycletime;
+			u64		cycletimeext;
+			u32		num_entries;
+			struct action_gate_entry *entries;
+		} gate;
 	};
 	struct flow_action_cookie *cookie; /* user defined action cookie */
 };
include/net/tc_act/tc_gate.h +115 -0

125 lines not on this page · raw message

net/sched/cls_api.c +33 -0
index 55bd1429678f..ca8bf74be4ba 100644
@@ -39,6 +39,7 @@
 #include <net/tc_act/tc_skbedit.h>
 #include <net/tc_act/tc_ct.h>
 #include <net/tc_act/tc_mpls.h>
+#include <net/tc_act/tc_gate.h>
 #include <net/flow_offload.h>
 
 extern const struct nla_policy rtm_tca_policy[TCA_MAX + 1];
@@ -3523,6 +3524,27 @@ static void tcf_sample_get_group(struct flow_action_entry *entry,
 #endif
 }
 
+static void tcf_gate_entry_destructor(void *priv)
+{
+	struct action_gate_entry *oe = priv;
+
+	kfree(oe);
+}
+
+static int tcf_gate_get_entries(struct flow_action_entry *entry,
+				const struct tc_action *act)
+{
+	entry->gate.entries = tcf_gate_get_list(act);
+
+	if (!entry->gate.entries)
+		return -EINVAL;
+
+	entry->destructor = tcf_gate_entry_destructor;
+	entry->destructor_priv = entry->gate.entries;
+
+	return 0;
+}
+
 int tc_setup_flow_action(struct flow_action *flow_action,
 			 const struct tcf_exts *exts)
 {
@@ -3669,6 +3691,17 @@ int tc_setup_flow_action(struct flow_action *flow_action,
 		} else if (is_tcf_skbedit_priority(act)) {
 			entry->id = FLOW_ACTION_PRIORITY;
 			entry->priority = tcf_skbedit_priority(act);
+		} else if (is_tcf_gate(act)) {
+			entry->id = FLOW_ACTION_GATE;
+			entry->gate.index = tcf_gate_index(act);
+			entry->gate.prio = tcf_gate_prio(act);
+			entry->gate.basetime = tcf_gate_basetime(act);
+			entry->gate.cycletime = tcf_gate_cycletime(act);
+			entry->gate.cycletimeext = tcf_gate_cycletimeext(act);
+			entry->gate.num_entries = tcf_gate_num_entries(act);
+			err = tcf_gate_get_entries(entry, act);
+			if (err)
+				goto err_out;
 		} else {
 			err = -EOPNOTSUPP;
 			goto err_out_locked;
Signature · 1 line
2.17.1
#92 lore raw

Re: [v3,net-next 2/4] net: schedule: add action gate offloading

Quoted 137 lines · Po Liu

Add the gate action to the flow action entry. Add the gate parameters to the tc_setup_flow_action() queueing to the entries of flow_action_entry array provide to the driver.

---
 include/net/flow_offload.h   |  10 +++
 include/net/tc_act/tc_gate.h | 115 +++++++++++++++++++++++++++++++++++
 net/sched/cls_api.c          |  33 ++++++++++
 3 files changed, 158 insertions(+)
include/net/flow_offload.h +10 -0
index 3619c6acf60f..94a30fe02e6d 100644
@@ -147,6 +147,7 @@ enum flow_action_id {
 	FLOW_ACTION_MPLS_PUSH,
 	FLOW_ACTION_MPLS_POP,
 	FLOW_ACTION_MPLS_MANGLE,
+	FLOW_ACTION_GATE,
 	NUM_FLOW_ACTIONS,
 };
 
@@ -255,6 +256,15 @@ struct flow_action_entry {
 			u8		bos;
 			u8		ttl;
 		} mpls_mangle;
+		struct {
+			u32		index;
+			s32		prio;
+			u64		basetime;
+			u64		cycletime;
+			u64		cycletimeext;
+			u32		num_entries;
+			struct action_gate_entry *entries;
+		} gate;
 	};
 	struct flow_action_cookie *cookie; /* user defined action cookie */
 };
include/net/tc_act/tc_gate.h +83 -0
index b0ace55b2aaa..62633cb02c7a 100644
@@ -7,6 +7,13 @@
 #include <net/act_api.h>
 #include <linux/tc_act/tc_gate.h>
 
+struct action_gate_entry {
+	u8			gate_state;
+	u32			interval;
+	s32			ipv;
+	s32			maxoctets;
+};
+
 struct tcfg_gate_entry {
 	int			index;
 	u8			gate_state;
@@ -51,4 +58,112 @@ struct tcf_gate {
 #define get_gate_param(act) ((struct tcf_gate_params *)act)
 #define get_gate_action(p) ((struct gate_action *)p)
 
+static inline bool is_tcf_gate(const struct tc_action *a)
+{
+#ifdef CONFIG_NET_CLS_ACT
+	if (a->ops && a->ops->id == TCA_ID_GATE)
+		return true;
+#endif
+	return false;
+}
+
+static inline u32 tcf_gate_index(const struct tc_action *a)
+{
+	return a->tcfa_index;
+}
+
+static inline s32 tcf_gate_prio(const struct tc_action *a)
+{
+	s32 tcfg_prio;
+
+	rcu_read_lock();
+	tcfg_prio = rcu_dereference(to_gate(a)->actg)->param.tcfg_priority;
+	rcu_read_unlock();
+
+	return tcfg_prio;
+}
+
+static inline u64 tcf_gate_basetime(const struct tc_action *a)
+{
+	u64 tcfg_basetime;
+
+	rcu_read_lock();
+	tcfg_basetime =
+		rcu_dereference(to_gate(a)->actg)->param.tcfg_basetime;
+	rcu_read_unlock();
+
+	return tcfg_basetime;
+}
+
+static inline u64 tcf_gate_cycletime(const struct tc_action *a)
+{
+	u64 tcfg_cycletime;
+
+	rcu_read_lock();
+	tcfg_cycletime =
+		rcu_dereference(to_gate(a)->actg)->param.tcfg_cycletime;
+	rcu_read_unlock();
+
+	return tcfg_cycletime;
+}
+
+static inline u64 tcf_gate_cycletimeext(const struct tc_action *a)
+{
+	u64 tcfg_cycletimeext;
+
+	rcu_read_lock();
+	tcfg_cycletimeext =
+		rcu_dereference(to_gate(a)->actg)->param.tcfg_cycletime_ext;
+	rcu_read_unlock();
+
+	return tcfg_cycletimeext;
+}
+
+static inline u32 tcf_gate_num_entries(const struct tc_action *a)
+{
+	u32 num_entries;
+
+	rcu_read_lock();
+	num_entries =
+		rcu_dereference(to_gate(a)->actg)->param.num_entries;
+	rcu_read_unlock();
+
+	return num_entries;
+}
+
+static inline struct action_gate_entry
+			*tcf_gate_get_list(const struct tc_action *a)
+{

include/net/tc_act/tc_gate.h struct tcf_gate { · line 146

Quoted 10 lines
include/net/tc_act/tc_gate.h +10 -0
+	struct action_gate_entry *oe;
+	struct tcf_gate_params *p;
+	struct tcfg_gate_entry *entry;
+	u32 num_entries;
+	int i = 0;
+
+	rcu_read_lock();
+	p = &(rcu_dereference(to_gate(a)->actg)->param);
+	num_entries = p->num_entries;
+	rcu_read_unlock();

Here you obtain a pointer to part of rcu-protected object and use it past rcu read lock block.

Quoted 81 lines
include/net/tc_act/tc_gate.h +22 -0
+
+	list_for_each_entry(entry, &p->entries, list)
+		i++;
+
+	if (i != num_entries)
+		return NULL;
+
+	oe = kzalloc(sizeof(*oe) * num_entries, GFP_KERNEL);
+	if (!oe)
+		return NULL;
+
+	i = 0;
+	list_for_each_entry(entry, &p->entries, list) {
+		oe[i].gate_state = entry->gate_state;
+		oe[i].interval = entry->interval;
+		oe[i].ipv = entry->ipv;
+		oe[i].maxoctets = entry->maxoctets;
+		i++;
+	}
+
+	return oe;
+}
 #endif
net/sched/cls_api.c +33 -0
index 55bd1429678f..ca8bf74be4ba 100644
@@ -39,6 +39,7 @@
 #include <net/tc_act/tc_skbedit.h>
 #include <net/tc_act/tc_ct.h>
 #include <net/tc_act/tc_mpls.h>
+#include <net/tc_act/tc_gate.h>
 #include <net/flow_offload.h>
 
 extern const struct nla_policy rtm_tca_policy[TCA_MAX + 1];
@@ -3523,6 +3524,27 @@ static void tcf_sample_get_group(struct flow_action_entry *entry,
 #endif
 }
 
+static void tcf_gate_entry_destructor(void *priv)
+{
+	struct action_gate_entry *oe = priv;
+
+	kfree(oe);
+}
+
+static int tcf_gate_get_entries(struct flow_action_entry *entry,
+				const struct tc_action *act)
+{
+	entry->gate.entries = tcf_gate_get_list(act);
+
+	if (!entry->gate.entries)
+		return -EINVAL;
+
+	entry->destructor = tcf_gate_entry_destructor;
+	entry->destructor_priv = entry->gate.entries;
+
+	return 0;
+}
+
 int tc_setup_flow_action(struct flow_action *flow_action,
 			 const struct tcf_exts *exts)
 {
@@ -3669,6 +3691,17 @@ int tc_setup_flow_action(struct flow_action *flow_action,
 		} else if (is_tcf_skbedit_priority(act)) {
 			entry->id = FLOW_ACTION_PRIORITY;
 			entry->priority = tcf_skbedit_priority(act);
+		} else if (is_tcf_gate(act)) {
+			entry->id = FLOW_ACTION_GATE;
+			entry->gate.index = tcf_gate_index(act);
+			entry->gate.prio = tcf_gate_prio(act);
+			entry->gate.basetime = tcf_gate_basetime(act);
+			entry->gate.cycletime = tcf_gate_cycletime(act);
+			entry->gate.cycletimeext = tcf_gate_cycletimeext(act);
+			entry->gate.num_entries = tcf_gate_num_entries(act);
+			err = tcf_gate_get_entries(entry, act);
+			if (err)
+				goto err_out;
 		} else {
 			err = -EOPNOTSUPP;
 			goto err_out_locked;
author
#93 lore raw

PATCH v3 3/4 net: enetc: add hw tc hw offload features for PSPF capability

In reply to Po Liu

This patch is to let ethtool enable/disable the tc flower offload features. Hardware ENETC has the feature of PSFP which is for per-stream policing. When enable the tc hw offloading feature, driver would enable the IEEE 802.1Qci feature. It is only set the register enable bit for this feature not enable for any entry of per stream filtering and stream gate or stream identify but get how much capabilities for each feature.

---
 drivers/net/ethernet/freescale/enetc/enetc.c  | 23 +++++++++
 drivers/net/ethernet/freescale/enetc/enetc.h  | 48 +++++++++++++++++++
 .../net/ethernet/freescale/enetc/enetc_hw.h   | 17 +++++++
 .../net/ethernet/freescale/enetc/enetc_pf.c   |  8 ++++
 4 files changed, 96 insertions(+)
drivers/net/ethernet/freescale/enetc/enetc.c +23 -0
index ccf2611f4a20..04aac7cbb506 100644
@@ -756,6 +756,9 @@ void enetc_get_si_caps(struct enetc_si *si)
 
 	if (val & ENETC_SIPCAPR0_QBV)
 		si->hw_features |= ENETC_SI_F_QBV;
+
+	if (val & ENETC_SIPCAPR0_PSFP)
+		si->hw_features |= ENETC_SI_F_PSFP;
 }
 
 static int enetc_dma_alloc_bdr(struct enetc_bdr *r, size_t bd_size)
@@ -1567,6 +1570,23 @@ static int enetc_set_rss(struct net_device *ndev, int en)
 	return 0;
 }
 
+static int enetc_set_psfp(struct net_device *ndev, int en)
+{
+	struct enetc_ndev_priv *priv = netdev_priv(ndev);
+
+	if (en) {
+		priv->active_offloads |= ENETC_F_QCI;
+		enetc_get_max_cap(priv);
+		enetc_psfp_enable(&priv->si->hw);
+	} else {
+		priv->active_offloads &= ~ENETC_F_QCI;
+		memset(&priv->psfp_cap, 0, sizeof(struct psfp_cap));
+		enetc_psfp_disable(&priv->si->hw);
+	}
+
+	return 0;
+}
+
 int enetc_set_features(struct net_device *ndev,
 		       netdev_features_t features)
 {
@@ -1575,6 +1595,9 @@ int enetc_set_features(struct net_device *ndev,
 	if (changed & NETIF_F_RXHASH)
 		enetc_set_rss(ndev, !!(features & NETIF_F_RXHASH));
 
+	if (changed & NETIF_F_HW_TC)
+		enetc_set_psfp(ndev, !!(features & NETIF_F_HW_TC));
+
 	return 0;
 }
 
drivers/net/ethernet/freescale/enetc/enetc.h +48 -0

81 lines not on this page · raw message

drivers/net/ethernet/freescale/enetc/enetc_hw.h +17 -0
index 2a6523136947..587974862f48 100644
@@ -19,6 +19,7 @@
 #define ENETC_SICTR1	0x1c
 #define ENETC_SIPCAPR0	0x20
 #define ENETC_SIPCAPR0_QBV	BIT(4)
+#define ENETC_SIPCAPR0_PSFP	BIT(9)
 #define ENETC_SIPCAPR0_RSS	BIT(8)
 #define ENETC_SIPCAPR1	0x24
 #define ENETC_SITGTGR	0x30
@@ -228,6 +229,15 @@ enum enetc_bdr_type {TX, RX};
 #define ENETC_PM0_IFM_RLP	(BIT(5) | BIT(11))
 #define ENETC_PM0_IFM_RGAUTO	(BIT(15) | ENETC_PMO_IFM_RG | BIT(1))
 #define ENETC_PM0_IFM_XGMII	BIT(12)
+#define ENETC_PSIDCAPR		0x1b08
+#define ENETC_PSIDCAPR_MSK	GENMASK(15, 0)
+#define ENETC_PSFCAPR		0x1b18
+#define ENETC_PSFCAPR_MSK	GENMASK(15, 0)
+#define ENETC_PSGCAPR		0x1b28
+#define ENETC_PSGCAPR_GCL_MSK	GENMASK(18, 16)
+#define ENETC_PSGCAPR_SGIT_MSK	GENMASK(15, 0)
+#define ENETC_PFMCAPR		0x1b38
+#define ENETC_PFMCAPR_MSK	GENMASK(15, 0)
 
 /* MAC counters */
 #define ENETC_PM0_REOCT		0x8100
@@ -621,3 +631,10 @@ struct enetc_cbd {
 /* Port time specific departure */
 #define ENETC_PTCTSDR(n)	(0x1210 + 4 * (n))
 #define ENETC_TSDE		BIT(31)
+
+/* PSFP setting */
+#define ENETC_PPSFPMR 0x11b00
+#define ENETC_PPSFPMR_PSFPEN BIT(0)
+#define ENETC_PPSFPMR_VS BIT(1)
+#define ENETC_PPSFPMR_PVC BIT(2)
+#define ENETC_PPSFPMR_PVZC BIT(3)
drivers/net/ethernet/freescale/enetc/enetc_pf.c +8 -0
index de1ad4975074..cef9fbfdb056 100644
@@ -727,6 +727,14 @@ static void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
 	if (si->hw_features & ENETC_SI_F_QBV)
 		priv->active_offloads |= ENETC_F_QBV;
 
+	if (si->hw_features & ENETC_SI_F_PSFP) {
+		priv->active_offloads |= ENETC_F_QCI;
+		ndev->features |= NETIF_F_HW_TC;
+		ndev->hw_features |= NETIF_F_HW_TC;
+		enetc_get_max_cap(priv);
+		enetc_psfp_enable(&si->hw);
+	}
+
 	/* pick up primary MAC address from SI */
 	enetc_get_primary_mac_addr(&si->hw, ndev->dev_addr);
 }
Signature · 1 line
2.17.1
author
#94 lore raw

PATCH v3 4/4 net: enetc: add tc flower psfp offload driver

In reply to Po Liu

This patch is to add tc flower offload for the enetc IEEE 802.1Qci(PSFP) function. There are four main feature parts to implement the flow policing and filtering for ingress flow with IEEE 802.1Qci features. They are stream identify(this is defined in the P802.1cb exactly but needed for 802.1Qci), stream filtering, stream gate and flow metering. Each function block includes many entries by index to assign parameters. So for one frame would be filtered by stream identify first, then flow into stream filter block by the same handle between stream identify and stream filtering. Then flow into stream gate control which assigned by the stream filtering entry. And then policing by the gate and limited by the max sdu in the filter block(optional). At last, policing by the flow metering block, index choosing at the fitering block. So you can see that each entry of block may link to many upper entries since they can be assigned same index means more streams want to share the same feature in the stream filtering or stream gate or flow metering.
To implement such features, each stream filtered by source/destination mac address, some stream maybe also plus the vlan id value would be treated as one flow chain. This would be identified by the chain_index which already in the tc filter concept. Driver would maintain this chain and also with gate modules. The stream filter entry create by the gate index and flow meter(optional) entry id and also one priority value. Offloading only transfer the gate action and flow filtering parameters. Driver would create (or search same gate id and flow meter id and
priority) one stream filter entry to set to the hardware. So stream
filtering do not need transfer by the action offloading. This architecture is same with tc filter and actions relationship. tc filter maintain the list for each flow feature by keys. And actions maintain by the action list.

Below showing a example commands by tc:

Quoted 3 lines

tc qdisc add dev eth0 ingress
ip link set eth0 address 10:00:80:00:00:00
tc filter add dev eth0 parent ffff: protocol ip chain 11 \

	flower skip_sw dst_mac 10:00:80:00:00:00 \
	action gate index 10 \
	sched-entry OPEN 200000000 1 8000000 \
	sched-entry CLOSE 100000000 -1 -1

Command means to set the dst_mac 10:00:80:00:00:00 to index 11 of stream identify module. And the set the gate index 10 of stream gate module. The gate list is keeping OPEN state 200ms, and through the frames to the ingress queue 1, and max octets are the 8Mbytes.

---
 drivers/net/ethernet/freescale/enetc/enetc.c  |   25 +-
 drivers/net/ethernet/freescale/enetc/enetc.h  |   46 +-
 .../net/ethernet/freescale/enetc/enetc_hw.h   |  142 +++
 .../net/ethernet/freescale/enetc/enetc_pf.c   |    4 +-
 .../net/ethernet/freescale/enetc/enetc_qos.c  | 1082 +++++++++++++++++
 5 files changed, 1284 insertions(+), 15 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc.c +17 -8
index 04aac7cbb506..298c55786fd9 100644
@@ -1521,6 +1521,8 @@ int enetc_setup_tc(struct net_device *ndev, enum tc_setup_type type,
 		return enetc_setup_tc_cbs(ndev, type_data);
 	case TC_SETUP_QDISC_ETF:
 		return enetc_setup_tc_txtime(ndev, type_data);
+	case TC_SETUP_BLOCK:
+		return enetc_setup_tc_psfp(ndev, type_data);
 	default:
 		return -EOPNOTSUPP;
 	}
@@ -1573,17 +1575,23 @@ static int enetc_set_rss(struct net_device *ndev, int en)
 static int enetc_set_psfp(struct net_device *ndev, int en)
 {
 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
+	int err;
 
 	if (en) {
+		err = enetc_psfp_enable(priv);
+		if (err)
+			return err;
+
 		priv->active_offloads |= ENETC_F_QCI;
-		enetc_get_max_cap(priv);
-		enetc_psfp_enable(&priv->si->hw);
-	} else {
-		priv->active_offloads &= ~ENETC_F_QCI;
-		memset(&priv->psfp_cap, 0, sizeof(struct psfp_cap));
-		enetc_psfp_disable(&priv->si->hw);
+		return 0;
 	}
 
+	err = enetc_psfp_disable(priv);
+	if (err)
+		return err;
+
+	priv->active_offloads &= ~ENETC_F_QCI;
+
 	return 0;
 }
 
@@ -1591,14 +1599,15 @@ int enetc_set_features(struct net_device *ndev,
 		       netdev_features_t features)
 {
 	netdev_features_t changed = ndev->features ^ features;
+	int err = 0;
 
 	if (changed & NETIF_F_RXHASH)
 		enetc_set_rss(ndev, !!(features & NETIF_F_RXHASH));
 
 	if (changed & NETIF_F_HW_TC)
-		enetc_set_psfp(ndev, !!(features & NETIF_F_HW_TC));
+		err = enetc_set_psfp(ndev, !!(features & NETIF_F_HW_TC));
 
-	return 0;
+	return err;
 }
 
 #ifdef CONFIG_FSL_ENETC_PTP_CLOCK
drivers/net/ethernet/freescale/enetc/enetc.h +42 -4

75 lines not on this page · raw message

drivers/net/ethernet/freescale/enetc/enetc_hw.h +142 -0

161 lines not on this page · raw message

drivers/net/ethernet/freescale/enetc/enetc_pf.c +1 -3
index cef9fbfdb056..824d211ec00f 100644
@@ -727,12 +727,10 @@ static void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
 	if (si->hw_features & ENETC_SI_F_QBV)
 		priv->active_offloads |= ENETC_F_QBV;
 
-	if (si->hw_features & ENETC_SI_F_PSFP) {
+	if (si->hw_features & ENETC_SI_F_PSFP && !enetc_psfp_enable(priv)) {
 		priv->active_offloads |= ENETC_F_QCI;
 		ndev->features |= NETIF_F_HW_TC;
 		ndev->hw_features |= NETIF_F_HW_TC;
-		enetc_get_max_cap(priv);
-		enetc_psfp_enable(&si->hw);
 	}
 
 	/* pick up primary MAC address from SI */
drivers/net/ethernet/freescale/enetc/enetc_qos.c +1082 -0

1,091 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#95 lore raw

v4 cover Introduce a flow gate control action and apply IEEE

Changes from V3:

0001:

Fix and modify according to Vlid Buslov:
- Remove the struct gate_action and move the parameters to the struct tcf_gate align with tc_action parameters. This would not need to alloc rcu type memory with pointer.
- Remove the spin_lock type entry_lock which do not needed anymore, will use the tcf_lock system provided.
- Provide lockep protect for the status parameters in the tcf_gate_act().
- Remove the cycletime 0 input warning, return error directly.

And:
- Remove Qci related description in the Kconfig for gate action.

0002:
- Fix rcu_read_lock protect range suggested by Vlid Buslov.

0003:
- No changes.

0004:
- Fix bug of gate maxoct wildcard condition not included.
- Fix the pass time basetime calculation report by Vladimir Otlean.

Changes from V2:
0001: No changes.
0002: No changes.
0003: No changes.
0004: Fix the vlan id filter parameter and add reject src mac FF-FF-FF-FF-FF-FF filter in driver.

Changes from V1:
0000: Update description make it more clear
0001: Removed 'add update dropped stats' patch, will provide pull request as standalone patches.
0001: Update commit description make it more clear ack by Jiri Pirko. 0002: No changes
0003: Fix some code style ack by Jiri Pirko.
0004: Fix enetc_psfp_enable/disable parameter type ack by test robot

iprout2 command patches:
Not attach with these serial patches, will provide separate pull
request after kernel accept these patches.

Changes from RFC:
0000: Reduce to 5 patches and remove the 4 max frame size offload and flow metering in the policing offload action, Only keep gate action offloading implementation.
0001: No changes.
0002:
- fix kfree lead ack by Jakub Kicinski and Cong Wang
- License fix from Jakub Kicinski and Stephen Hemminger
- Update example in commit acked by Vinicius Costa Gomes
- Fix the rcu protect in tcf_gate_act() acked by Vinicius

0003: No changes
0004: No changes
0005:
Acked by Vinicius Costa Gomes
- Use refcount kernel lib
- Update stream gate check code position
- Update reduce ref names more clear

iprout2 command patches:
0000: Update license expression and add gate id
0001: Add tc action gate man page

--------------------------------------------------------------------
These patches add stream gate action policing in IEEE802.1Qci (Per-Stream Filtering and Policing) software support and hardware offload support in tc flower, and implement the stream identify, stream filtering and stream gate filtering action in the NXP ENETC ethernet driver. Per-Stream Filtering and Policing (PSFP) specifies flow policing and filtering for ingress flows, and has three main parts:
1. The stream filter instance table consists of an ordered list of
stream filters that determine the filtering and policing actions that are to be applied to frames received on a specific stream. The main elements are stream gate id, flow metering id and maximum SDU size.
2. The stream gate function setup a gate list to control ingress traffic
class open/close state. When the gate is running at open state, the flow could pass but dropped when gate state is running to close. User setup a bastime to tell gate when start running the entry list, then the hardware would periodiclly. There is no compare qdisc action support.
3. Flow metering is two rates two buckets and three-color marker to
policing the frames. Flow metering instance are as specified in the algorithm in MEF10.3. The most likely qdisc action is policing action.

The first patch introduces an ingress frame flow control gate action, for the point 2. The tc gate action maintains the open/close state gate list, allowing flows to pass when the gate is open. Each gate action may policing one or more qdisc filters. When the start time arrived, The driver would repeat the gate list periodiclly. User can assign a passed time, the driver would calculate a new future time by the cycletime of the gate list.

The 0002 patch introduces the gate flow hardware offloading.

The 0003 patch adds support control the on/off for the tc flower offloading by ethtool.

The 0004 patch implement the stream identify and stream filtering and stream gate filtering action in the NXP ENETC ethernet driver. Tc filter command provide filtering keys with MAC address and VLAN id. These keys would be set to stream identify instance entry. Stream gate instance entry would refer the gate action parameters. Stream filter instance entry would refer the stream gate index and assign a stream handle value matches to the stream identify instance.

Po Liu (4):
net: qos: introduce a gate control flow action
net: schedule: add action gate offloading
net: enetc: add hw tc hw offload features for PSPF capability
net: enetc: add tc flower psfp offload driver

 drivers/net/ethernet/freescale/enetc/enetc.c  |   34 +-
 drivers/net/ethernet/freescale/enetc/enetc.h  |   86 ++
 .../net/ethernet/freescale/enetc/enetc_hw.h   |  159 +++
 .../net/ethernet/freescale/enetc/enetc_pf.c   |    6 +
 .../net/ethernet/freescale/enetc/enetc_qos.c  | 1098 +++++++++++++++++
 include/net/flow_offload.h                    |   10 +
 include/net/tc_act/tc_gate.h                  |  160 +++
 include/uapi/linux/pkt_cls.h                  |    1 +
 include/uapi/linux/tc_act/tc_gate.h           |   47 +
 net/sched/Kconfig                             |   12 +
 net/sched/Makefile                            |    1 +
 net/sched/act_gate.c                          |  637 ++++++++++
 net/sched/cls_api.c                           |   33 +
 13 files changed, 2283 insertions(+), 1 deletion(-)
 create mode 100644 include/net/tc_act/tc_gate.h
 create mode 100644 include/uapi/linux/tc_act/tc_gate.h
 create mode 100644 net/sched/act_gate.c
Signature · 1 line
2.17.1
author
#96 lore raw

PATCH v4 1/4 net: qos: introduce a gate control flow action

Introduce a ingress frame gate control flow action.
Tc gate action does the work like this:
Assume there is a gate allow specified ingress frames can be passed at specific time slot, and be dropped at specific time slot. Tc filter chooses the ingress frames, and tc gate action would specify what slot does these frames can be passed to device and what time slot would be dropped.
Tc gate action would provide an entry list to tell how much time gate keep open and how much time gate keep state close. Gate action also assign a start time to tell when the entry list start. Then driver would repeat the gate entry list cyclically.
For the software simulation, gate action requires the user assign a time clock type.

Below is the setting example in user space. Tc filter a stream source ip address is 192.168.0.20 and gate action own two time slots. One is last 200ms gate open let frame pass another is last 100ms gate close let frames dropped. When the ingress frames have reach total frames over 8000000 bytes, the excessive frames will be dropped in that 200000000ns time slot.

Quoted 3 lines

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 clockid CLOCK_TAI \
	   sched-entry open 200000000 -1 8000000 \
	   sched-entry close 100000000 -1 -1
Quoted 1 line

tc chain del dev eth0 ingress chain 0

"sched-entry" follow the name taprio style. Gate state is "open"/"close". Follow with period nanosecond. Then next item 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.
Base-time is not set will be 0 as default, as result start time would be ((N + 1) * cycletime) which is the minimal of future time.

Below example shows filtering a stream with destination mac address is 10:00:80:00:00:00 and ip type is ICMP, follow the action gate. The gate action would run with one close time slot which means always keep close. The time cycle is total 200000000ns. The base-time would calculate by:

1357000000000 + (N + 1) * cycletime

When the total value is the future time, it will be the start time. The cycletime here would be 200000000ns for this case.

Quoted 1 line

tc filter add dev eth0 parent ffff: protocol ip \

	   flower skip_hw ip_proto icmp dst_mac 10:00:80:00:00:00 \
	   action gate index 12 base-time 1357000000000 \
	   sched-entry close 200000000 -1 -1 \
	   clockid CLOCK_TAI
---
 include/net/tc_act/tc_gate.h        |  47 ++
 include/uapi/linux/pkt_cls.h        |   1 +
 include/uapi/linux/tc_act/tc_gate.h |  47 ++
 net/sched/Kconfig                   |  12 +
 net/sched/Makefile                  |   1 +
 net/sched/act_gate.c                | 638 ++++++++++++++++++++++++++++
 6 files changed, 746 insertions(+)
 create mode 100644 include/net/tc_act/tc_gate.h
 create mode 100644 include/uapi/linux/tc_act/tc_gate.h
 create mode 100644 net/sched/act_gate.c
include/net/tc_act/tc_gate.h new file +47 -0
new file mode 100644
index 000000000000..330ad8b02495
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright 2020 NXP */
+
+#ifndef __NET_TC_GATE_H
+#define __NET_TC_GATE_H
+
+#include <net/act_api.h>
+#include <linux/tc_act/tc_gate.h>
+
+struct tcfg_gate_entry {
+	int			index;
+	u8			gate_state;
+	u32			interval;
+	s32			ipv;
+	s32			maxoctets;
+	struct list_head	list;
+};
+
+struct tcf_gate_params {
+	s32			tcfg_priority;
+	u64			tcfg_basetime;
+	u64			tcfg_cycletime;
+	u64			tcfg_cycletime_ext;
+	u32			tcfg_flags;
+	s32			tcfg_clockid;
+	size_t			num_entries;
+	struct list_head	entries;
+};
+
+#define GATE_ACT_GATE_OPEN	BIT(0)
+#define GATE_ACT_PENDING	BIT(1)
+
+struct tcf_gate {
+	struct tc_action	common;
+	struct tcf_gate_params	param;
+	u8			current_gate_status;
+	ktime_t			current_close_time;
+	u32			current_entry_octets;
+	s32			current_max_octets;
+	struct tcfg_gate_entry	*next_entry;
+	struct hrtimer		hitimer;
+	enum tk_offsets		tk_offset;
+};
+
+#define to_gate(a) ((struct tcf_gate *)a)
+
+#endif
include/uapi/linux/pkt_cls.h +1 -0
index 9f06d29cab70..fc672b232437 100644
@@ -134,6 +134,7 @@ enum tca_id {
 	TCA_ID_CTINFO,
 	TCA_ID_MPLS,
 	TCA_ID_CT,
+	TCA_ID_GATE,
 	/* other actions go here */
 	__TCA_ID_MAX = 255
 };
include/uapi/linux/tc_act/tc_gate.h new file +47 -0

47 lines not on this page · raw message

net/sched/Kconfig +12 -0
index bfbefb7bff9d..2f20073f4f84 100644
@@ -981,6 +981,18 @@ config NET_ACT_CT
 	  To compile this code as a module, choose M here: the
 	  module will be called act_ct.
 
+config NET_ACT_GATE
+	tristate "Frame gate entry list control tc action"
+	depends on NET_CLS_ACT
+	help
+	  Say Y here to allow to control the ingress flow to be passed at
+	  specific time slot and be dropped at other specific time slot by
+	  the gate entry list.
+
+	  If unsure, say N.
+	  To compile this code as a module, choose M here: the
+	  module will be called act_gate.
+
 config NET_IFE_SKBMARK
 	tristate "Support to encoding decoding skb mark on IFE action"
 	depends on NET_ACT_IFE
net/sched/Makefile +1 -0
index 31c367a6cd09..66bbf9a98f9e 100644
@@ -30,6 +30,7 @@ obj-$(CONFIG_NET_IFE_SKBPRIO)	+= act_meta_skbprio.o
 obj-$(CONFIG_NET_IFE_SKBTCINDEX)	+= act_meta_skbtcindex.o
 obj-$(CONFIG_NET_ACT_TUNNEL_KEY)+= act_tunnel_key.o
 obj-$(CONFIG_NET_ACT_CT)	+= act_ct.o
+obj-$(CONFIG_NET_ACT_GATE)	+= act_gate.o
 obj-$(CONFIG_NET_SCH_FIFO)	+= sch_fifo.o
 obj-$(CONFIG_NET_SCH_CBQ)	+= sch_cbq.o
 obj-$(CONFIG_NET_SCH_HTB)	+= sch_htb.o
net/sched/act_gate.c new file +638 -0

638 lines not on this page · raw message

Signature · 1 line
2.17.1
#97 lore raw

Re: [v4,net-next 1/4] net: qos: introduce a gate control flow action

Hi Po,

Quoted 345 lines · Po Liu

Introduce a ingress frame gate control flow action.
Tc gate action does the work like this:
Assume there is a gate allow specified ingress frames can be passed at specific time slot, and be dropped at specific time slot. Tc filter chooses the ingress frames, and tc gate action would specify what slot does these frames can be passed to device and what time slot would be dropped.
Tc gate action would provide an entry list to tell how much time gate keep open and how much time gate keep state close. Gate action also assign a start time to tell when the entry list start. Then driver would repeat the gate entry list cyclically.
For the software simulation, gate action requires the user assign a time clock type.

Below is the setting example in user space. Tc filter a stream source ip address is 192.168.0.20 and gate action own two time slots. One is last 200ms gate open let frame pass another is last 100ms gate close let frames dropped. When the ingress frames have reach total frames over 8000000 bytes, the excessive frames will be dropped in that 200000000ns time slot.

Quoted 3 lines

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 clockid CLOCK_TAI \
	   sched-entry open 200000000 -1 8000000 \
	   sched-entry close 100000000 -1 -1
Quoted 1 line

tc chain del dev eth0 ingress chain 0

"sched-entry" follow the name taprio style. Gate state is "open"/"close". Follow with period nanosecond. Then next item 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.
Base-time is not set will be 0 as default, as result start time would be ((N + 1) * cycletime) which is the minimal of future time.

Below example shows filtering a stream with destination mac address is 10:00:80:00:00:00 and ip type is ICMP, follow the action gate. The gate action would run with one close time slot which means always keep close. The time cycle is total 200000000ns. The base-time would calculate by:

1357000000000 + (N + 1) * cycletime

When the total value is the future time, it will be the start time. The cycletime here would be 200000000ns for this case.

Quoted 1 line

tc filter add dev eth0 parent ffff: protocol ip \

	   flower skip_hw ip_proto icmp dst_mac 10:00:80:00:00:00 \
	   action gate index 12 base-time 1357000000000 \
	   sched-entry close 200000000 -1 -1 \
	   clockid CLOCK_TAI
---
 include/net/tc_act/tc_gate.h        |  47 ++
 include/uapi/linux/pkt_cls.h        |   1 +
 include/uapi/linux/tc_act/tc_gate.h |  47 ++
 net/sched/Kconfig                   |  12 +
 net/sched/Makefile                  |   1 +
 net/sched/act_gate.c                | 638 ++++++++++++++++++++++++++++
 6 files changed, 746 insertions(+)
 create mode 100644 include/net/tc_act/tc_gate.h
 create mode 100644 include/uapi/linux/tc_act/tc_gate.h
 create mode 100644 net/sched/act_gate.c
include/net/tc_act/tc_gate.h new file +47 -0
new file mode 100644
index 000000000000..330ad8b02495
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright 2020 NXP */
+
+#ifndef __NET_TC_GATE_H
+#define __NET_TC_GATE_H
+
+#include <net/act_api.h>
+#include <linux/tc_act/tc_gate.h>
+
+struct tcfg_gate_entry {
+	int			index;
+	u8			gate_state;
+	u32			interval;
+	s32			ipv;
+	s32			maxoctets;
+	struct list_head	list;
+};
+
+struct tcf_gate_params {
+	s32			tcfg_priority;
+	u64			tcfg_basetime;
+	u64			tcfg_cycletime;
+	u64			tcfg_cycletime_ext;
+	u32			tcfg_flags;
+	s32			tcfg_clockid;
+	size_t			num_entries;
+	struct list_head	entries;
+};
+
+#define GATE_ACT_GATE_OPEN	BIT(0)
+#define GATE_ACT_PENDING	BIT(1)
+
+struct tcf_gate {
+	struct tc_action	common;
+	struct tcf_gate_params	param;
+	u8			current_gate_status;
+	ktime_t			current_close_time;
+	u32			current_entry_octets;
+	s32			current_max_octets;
+	struct tcfg_gate_entry	*next_entry;
+	struct hrtimer		hitimer;
+	enum tk_offsets		tk_offset;
+};
+
+#define to_gate(a) ((struct tcf_gate *)a)
+
+#endif
include/uapi/linux/pkt_cls.h +1 -0
index 9f06d29cab70..fc672b232437 100644
@@ -134,6 +134,7 @@ enum tca_id {
 	TCA_ID_CTINFO,
 	TCA_ID_MPLS,
 	TCA_ID_CT,
+	TCA_ID_GATE,
 	/* other actions go here */
 	__TCA_ID_MAX = 255
 };
include/uapi/linux/tc_act/tc_gate.h new file +47 -0
new file mode 100644
index 000000000000..f214b3a6d44f
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
+/* Copyright 2020 NXP */
+
+#ifndef __LINUX_TC_GATE_H
+#define __LINUX_TC_GATE_H
+
+#include <linux/pkt_cls.h>
+
+struct tc_gate {
+	tc_gen;
+};
+
+enum {
+	TCA_GATE_ENTRY_UNSPEC,
+	TCA_GATE_ENTRY_INDEX,
+	TCA_GATE_ENTRY_GATE,
+	TCA_GATE_ENTRY_INTERVAL,
+	TCA_GATE_ENTRY_IPV,
+	TCA_GATE_ENTRY_MAX_OCTETS,
+	__TCA_GATE_ENTRY_MAX,
+};
+#define TCA_GATE_ENTRY_MAX (__TCA_GATE_ENTRY_MAX - 1)
+
+enum {
+	TCA_GATE_ONE_ENTRY_UNSPEC,
+	TCA_GATE_ONE_ENTRY,
+	__TCA_GATE_ONE_ENTRY_MAX,
+};
+#define TCA_GATE_ONE_ENTRY_MAX (__TCA_GATE_ONE_ENTRY_MAX - 1)
+
+enum {
+	TCA_GATE_UNSPEC,
+	TCA_GATE_TM,
+	TCA_GATE_PARMS,
+	TCA_GATE_PAD,
+	TCA_GATE_PRIORITY,
+	TCA_GATE_ENTRY_LIST,
+	TCA_GATE_BASE_TIME,
+	TCA_GATE_CYCLE_TIME,
+	TCA_GATE_CYCLE_TIME_EXT,
+	TCA_GATE_FLAGS,
+	TCA_GATE_CLOCKID,
+	__TCA_GATE_MAX,
+};
+#define TCA_GATE_MAX (__TCA_GATE_MAX - 1)
+
+#endif
net/sched/Kconfig +12 -0
index bfbefb7bff9d..2f20073f4f84 100644
@@ -981,6 +981,18 @@ config NET_ACT_CT
 	  To compile this code as a module, choose M here: the
 	  module will be called act_ct.
 
+config NET_ACT_GATE
+	tristate "Frame gate entry list control tc action"
+	depends on NET_CLS_ACT
+	help
+	  Say Y here to allow to control the ingress flow to be passed at
+	  specific time slot and be dropped at other specific time slot by
+	  the gate entry list.
+
+	  If unsure, say N.
+	  To compile this code as a module, choose M here: the
+	  module will be called act_gate.
+
 config NET_IFE_SKBMARK
 	tristate "Support to encoding decoding skb mark on IFE action"
 	depends on NET_ACT_IFE
net/sched/Makefile +1 -0
index 31c367a6cd09..66bbf9a98f9e 100644
@@ -30,6 +30,7 @@ obj-$(CONFIG_NET_IFE_SKBPRIO)	+= act_meta_skbprio.o
 obj-$(CONFIG_NET_IFE_SKBTCINDEX)	+= act_meta_skbtcindex.o
 obj-$(CONFIG_NET_ACT_TUNNEL_KEY)+= act_tunnel_key.o
 obj-$(CONFIG_NET_ACT_CT)	+= act_ct.o
+obj-$(CONFIG_NET_ACT_GATE)	+= act_gate.o
 obj-$(CONFIG_NET_SCH_FIFO)	+= sch_fifo.o
 obj-$(CONFIG_NET_SCH_CBQ)	+= sch_cbq.o
 obj-$(CONFIG_NET_SCH_HTB)	+= sch_htb.o
net/sched/act_gate.c new file +117 -0
new file mode 100644
index 000000000000..916f6fe56692
@@ -0,0 +1,638 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright 2020 NXP */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/skbuff.h>
+#include <linux/rtnetlink.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <net/act_api.h>
+#include <net/netlink.h>
+#include <net/pkt_cls.h>
+#include <net/tc_act/tc_gate.h>
+
+static unsigned int gate_net_id;
+static struct tc_action_ops act_gate_ops;
+
+static ktime_t gate_get_time(struct tcf_gate *gact)
+{
+	ktime_t mono = ktime_get();
+
+	switch (gact->tk_offset) {
+	case TK_OFFS_MAX:
+		return mono;
+	default:
+		return ktime_mono_to_any(mono, gact->tk_offset);
+	}
+
+	return KTIME_MAX;
+}
+
+static int gate_get_start_time(struct tcf_gate *gact, ktime_t *start)
+{
+	struct tcf_gate_params *param = &gact->param;
+	ktime_t now, base, cycle;
+	u64 n;
+
+	base = ns_to_ktime(param->tcfg_basetime);
+	now = gate_get_time(gact);
+
+	if (ktime_after(base, now)) {
+		*start = base;
+		return 0;
+	}
+
+	cycle = param->tcfg_cycletime;
+
+	/* cycle time should not be zero */
+	if (!cycle)
+		return -EFAULT;
+
+	n = div64_u64(ktime_sub_ns(now, base), cycle);
+	*start = ktime_add_ns(base, (n + 1) * cycle);
+	return 0;
+}
+
+static void gate_start_timer(struct tcf_gate *gact, ktime_t start)
+{
+	ktime_t expires;
+
+	expires = hrtimer_get_expires(&gact->hitimer);
+	if (expires == 0)
+		expires = KTIME_MAX;
+
+	start = min_t(ktime_t, start, expires);
+
+	hrtimer_start(&gact->hitimer, start, HRTIMER_MODE_ABS);
+}
+
+static enum hrtimer_restart gate_timer_func(struct hrtimer *timer)
+{
+	struct tcf_gate *gact = container_of(timer, struct tcf_gate,
+					     hitimer);
+	struct tcf_gate_params *p = &gact->param;
+	struct tcfg_gate_entry *next;
+	ktime_t close_time, now;
+
+	spin_lock(&gact->tcf_lock);
+
+	next = gact->next_entry;
+
+	/* cycle start, clear pending bit, clear total octets */
+	gact->current_gate_status = next->gate_state ? GATE_ACT_GATE_OPEN : 0;
+	gact->current_entry_octets = 0;
+	gact->current_max_octets = next->maxoctets;
+
+	gact->current_close_time = ktime_add_ns(gact->current_close_time,
+						next->interval);
+
+	close_time = gact->current_close_time;
+
+	if (list_is_last(&next->list, &p->entries))
+		next = list_first_entry(&p->entries,
+					struct tcfg_gate_entry, list);
+	else
+		next = list_next_entry(next, list);
+
+	now = gate_get_time(gact);
+
+	if (ktime_after(now, close_time)) {
+		ktime_t cycle, base;
+		u64 n;
+
+		cycle = p->tcfg_cycletime;
+		base = ns_to_ktime(p->tcfg_basetime);
+		n = div64_u64(ktime_sub_ns(now, base), cycle);
+		close_time = ktime_add_ns(base, (n + 1) * cycle);
+	}
+
+	gact->next_entry = next;
+
+	hrtimer_set_expires(&gact->hitimer, close_time);
+
+	spin_unlock(&gact->tcf_lock);

net/sched/act_gate.c line 127

Quoted 10 lines
net/sched/act_gate.c new file +10 -0
+
+	return HRTIMER_RESTART;
+}
+
+static int tcf_gate_act(struct sk_buff *skb, const struct tc_action *a,
+			struct tcf_result *res)
+{
+	struct tcf_gate *gact = to_gate(a);
+
+	spin_lock_bh(&gact->tcf_lock);

I think you need to use regular spin_lock() function here because this function is called from softirq context.

Quoted 314 lines
net/sched/act_gate.c new file +314 -0
+
+	tcf_lastuse_update(&gact->tcf_tm);
+	bstats_update(&gact->tcf_bstats, skb);
+
+	if (unlikely(gact->current_gate_status & GATE_ACT_PENDING)) {
+		spin_unlock_bh(&gact->tcf_lock);
+		return gact->tcf_action;
+	}
+
+	if (!(gact->current_gate_status & GATE_ACT_GATE_OPEN))
+		goto drop;
+
+	if (gact->current_max_octets >= 0) {
+		gact->current_entry_octets += qdisc_pkt_len(skb);
+		if (gact->current_entry_octets > gact->current_max_octets) {
+			gact->tcf_qstats.overlimits++;
+			goto drop;
+		}
+	}
+
+	spin_unlock_bh(&gact->tcf_lock);
+
+	return gact->tcf_action;
+drop:
+	gact->tcf_qstats.drops++;
+	spin_unlock_bh(&gact->tcf_lock);
+
+	return TC_ACT_SHOT;
+}
+
+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),
+					    .type = NLA_EXACT_LEN },
+	[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;
+
+	entry->gate_state = nla_get_flag(tb[TCA_GATE_ENTRY_GATE]);
+
+	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;
+	}
+
+	entry->interval = interval;
+
+	if (tb[TCA_GATE_ENTRY_IPV])
+		entry->ipv = nla_get_s32(tb[TCA_GATE_ENTRY_IPV]);
+	else
+		entry->ipv = -1;
+
+	if (tb[TCA_GATE_ENTRY_MAX_OCTETS])
+		entry->maxoctets = nla_get_s32(tb[TCA_GATE_ENTRY_MAX_OCTETS]);
+	else
+		entry->maxoctets = -1;
+
+	return 0;
+}
+
+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(tb, TCA_GATE_ENTRY_MAX, n, entry_policy, extack);
+	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);
+}
+
+static void release_entry_list(struct list_head *entries)
+{
+	struct tcfg_gate_entry *entry, *e;
+
+	list_for_each_entry_safe(entry, e, entries, list) {
+		list_del(&entry->list);
+		kfree(entry);
+	}
+}
+
+static int parse_gate_list(struct nlattr *list_attr,
+			   struct tcf_gate_params *sched,
+			   struct netlink_ext_ack *extack)
+{
+	struct tcfg_gate_entry *entry;
+	struct nlattr *n;
+	int err, rem;
+	int i = 0;
+
+	if (!list_attr)
+		return -EINVAL;
+
+	nla_for_each_nested(n, list_attr, rem) {
+		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");
+			err = -ENOMEM;
+			goto release_list;
+		}
+
+		err = parse_gate_entry(n, entry, i, extack);
+		if (err < 0) {
+			kfree(entry);
+			goto release_list;
+		}
+
+		list_add_tail(&entry->list, &sched->entries);
+		i++;
+	}
+
+	sched->num_entries = i;
+
+	return i;
+
+release_list:
+	release_entry_list(&sched->entries);
+
+	return err;
+}
+
+static int tcf_gate_init(struct net *net, struct nlattr *nla,
+			 struct nlattr *est, struct tc_action **a,
+			 int ovr, int bind, bool rtnl_held,
+			 struct tcf_proto *tp, u32 flags,
+			 struct netlink_ext_ack *extack)
+{
+	struct tc_action_net *tn = net_generic(net, gate_net_id);
+	enum tk_offsets tk_offset = TK_OFFS_TAI;
+	struct nlattr *tb[TCA_GATE_MAX + 1];
+	struct tcf_chain *goto_ch = NULL;
+	struct tcf_gate_params *p;
+	s32 clockid = CLOCK_TAI;
+	struct tcf_gate *gact;
+	struct tc_gate *parm;
+	int ret = 0, err;
+	u64 basetime = 0;
+	u32 gflags = 0;
+	s32 prio = -1;
+	ktime_t start;
+	u32 index;
+
+	if (!nla)
+		return -EINVAL;
+
+	err = nla_parse_nested(tb, TCA_GATE_MAX, nla, gate_policy, extack);
+	if (err < 0)
+		return err;
+
+	if (!tb[TCA_GATE_PARMS])
+		return -EINVAL;
+
+	parm = nla_data(tb[TCA_GATE_PARMS]);
+	index = parm->index;
+
+	err = tcf_idr_check_alloc(tn, &index, a, bind);
+	if (err < 0)
+		return err;
+
+	if (err && bind)
+		return 0;
+
+	if (!err) {
+		ret = tcf_idr_create(tn, index, est, a,
+				     &act_gate_ops, bind, false, 0);
+		if (ret) {
+			tcf_idr_cleanup(tn, index);
+			return ret;
+		}
+
+		ret = ACT_P_CREATED;
+	} else if (!ovr) {
+		tcf_idr_release(*a, bind);
+		return -EEXIST;
+	}
+
+	if (tb[TCA_GATE_PRIORITY])
+		prio = nla_get_s32(tb[TCA_GATE_PRIORITY]);
+
+	if (tb[TCA_GATE_BASE_TIME])
+		basetime = nla_get_u64(tb[TCA_GATE_BASE_TIME]);
+
+	if (tb[TCA_GATE_FLAGS])
+		gflags = nla_get_u32(tb[TCA_GATE_FLAGS]);
+
+	if (tb[TCA_GATE_CLOCKID]) {
+		clockid = nla_get_s32(tb[TCA_GATE_CLOCKID]);
+		switch (clockid) {
+		case CLOCK_REALTIME:
+			tk_offset = TK_OFFS_REAL;
+			break;
+		case CLOCK_MONOTONIC:
+			tk_offset = TK_OFFS_MAX;
+			break;
+		case CLOCK_BOOTTIME:
+			tk_offset = TK_OFFS_BOOT;
+			break;
+		case CLOCK_TAI:
+			tk_offset = TK_OFFS_TAI;
+			break;
+		default:
+			NL_SET_ERR_MSG(extack, "Invalid 'clockid'");
+			goto release_idr;
+		}
+	}
+
+	err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack);
+	if (err < 0)
+		goto release_idr;
+
+	gact = to_gate(*a);
+
+	spin_lock_bh(&gact->tcf_lock);
+	p = &gact->param;
+
+	if (tb[TCA_GATE_CYCLE_TIME]) {
+		p->tcfg_cycletime = nla_get_u64(tb[TCA_GATE_CYCLE_TIME]);
+		if (!p->tcfg_cycletime_ext)
+			goto chain_put;
+	}
+
+	INIT_LIST_HEAD(&p->entries);
+	if (tb[TCA_GATE_ENTRY_LIST]) {
+		err = parse_gate_list(tb[TCA_GATE_ENTRY_LIST], p, extack);
+		if (err < 0)
+			goto chain_put;
+	}
+
+	if (!p->tcfg_cycletime) {
+		struct tcfg_gate_entry *entry;
+		ktime_t cycle = 0;
+
+		list_for_each_entry(entry, &p->entries, list)
+			cycle = ktime_add_ns(cycle, entry->interval);
+		p->tcfg_cycletime = cycle;
+	}
+
+	if (tb[TCA_GATE_CYCLE_TIME_EXT])
+		p->tcfg_cycletime_ext =
+			nla_get_u64(tb[TCA_GATE_CYCLE_TIME_EXT]);
+
+	p->tcfg_priority = prio;
+	p->tcfg_basetime = basetime;
+	p->tcfg_clockid = clockid;
+	p->tcfg_flags = gflags;
+
+	gact->tk_offset = tk_offset;
+	hrtimer_init(&gact->hitimer, clockid, HRTIMER_MODE_ABS);
+	gact->hitimer.function = gate_timer_func;
+
+	err = gate_get_start_time(gact, &start);
+	if (err < 0) {
+		NL_SET_ERR_MSG(extack,
+			       "Internal error: failed get start time");
+		release_entry_list(&p->entries);
+		goto chain_put;
+	}
+
+	gact->current_close_time = start;
+	gact->current_gate_status = GATE_ACT_GATE_OPEN | GATE_ACT_PENDING;
+
+	gact->next_entry = list_first_entry(&p->entries,
+					    struct tcfg_gate_entry, list);
+
+	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
+
+	gate_start_timer(gact, start);
+
+	spin_unlock_bh(&gact->tcf_lock);
+
+	if (goto_ch)
+		tcf_chain_put_by_act(goto_ch);
+
+	if (ret == ACT_P_CREATED)
+		tcf_idr_insert(tn, *a);
+	return ret;
+
+chain_put:
+	spin_unlock_bh(&gact->tcf_lock);
+
+	if (goto_ch)
+		tcf_chain_put_by_act(goto_ch);
+release_idr:

net/sched/act_gate.c line 451

Quoted 10 lines
net/sched/act_gate.c new file +10 -0
+	tcf_idr_release(*a, bind);
+	return err;
+}
+
+static void tcf_gate_cleanup(struct tc_action *a)
+{
+	struct tcf_gate *gact = to_gate(a);
+	struct tcf_gate_params *p;
+
+	spin_lock_bh(&gact->tcf_lock);

No need to lock in tc_action_ops->cleanup() callbacks.

Quoted 187 lines
net/sched/act_gate.c new file +187 -0
+
+	hrtimer_cancel(&gact->hitimer);
+
+	p = &gact->param;
+	release_entry_list(&p->entries);
+
+	spin_unlock_bh(&gact->tcf_lock);
+}
+
+static int dumping_entry(struct sk_buff *skb,
+			 struct tcfg_gate_entry *entry)
+{
+	struct nlattr *item;
+
+	item = nla_nest_start_noflag(skb, TCA_GATE_ONE_ENTRY);
+	if (!item)
+		return -ENOSPC;
+
+	if (nla_put_u32(skb, TCA_GATE_ENTRY_INDEX, entry->index))
+		goto nla_put_failure;
+
+	if (entry->gate_state && nla_put_flag(skb, TCA_GATE_ENTRY_GATE))
+		goto nla_put_failure;
+
+	if (nla_put_u32(skb, TCA_GATE_ENTRY_INTERVAL, entry->interval))
+		goto nla_put_failure;
+
+	if (nla_put_s32(skb, TCA_GATE_ENTRY_MAX_OCTETS, entry->maxoctets))
+		goto nla_put_failure;
+
+	if (nla_put_s32(skb, TCA_GATE_ENTRY_IPV, entry->ipv))
+		goto nla_put_failure;
+
+	return nla_nest_end(skb, item);
+
+nla_put_failure:
+	nla_nest_cancel(skb, item);
+	return -1;
+}
+
+static int tcf_gate_dump(struct sk_buff *skb, struct tc_action *a,
+			 int bind, int ref)
+{
+	unsigned char *b = skb_tail_pointer(skb);
+	struct tcf_gate *gact = to_gate(a);
+	struct tc_gate opt = {
+		.index    = gact->tcf_index,
+		.refcnt   = refcount_read(&gact->tcf_refcnt) - ref,
+		.bindcnt  = atomic_read(&gact->tcf_bindcnt) - bind,
+	};
+	struct tcfg_gate_entry *entry;
+	struct tcf_gate_params *p;
+	struct nlattr *entry_list;
+	struct tcf_t t;
+
+	spin_lock_bh(&gact->tcf_lock);
+	opt.action = gact->tcf_action;
+
+	p = &gact->param;
+
+	if (nla_put(skb, TCA_GATE_PARMS, sizeof(opt), &opt))
+		goto nla_put_failure;
+
+	if (nla_put_u64_64bit(skb, TCA_GATE_BASE_TIME,
+			      p->tcfg_basetime, TCA_GATE_PAD))
+		goto nla_put_failure;
+
+	if (nla_put_u64_64bit(skb, TCA_GATE_CYCLE_TIME,
+			      p->tcfg_cycletime, TCA_GATE_PAD))
+		goto nla_put_failure;
+
+	if (nla_put_u64_64bit(skb, TCA_GATE_CYCLE_TIME_EXT,
+			      p->tcfg_cycletime_ext, TCA_GATE_PAD))
+		goto nla_put_failure;
+
+	if (nla_put_s32(skb, TCA_GATE_CLOCKID, p->tcfg_clockid))
+		goto nla_put_failure;
+
+	if (nla_put_u32(skb, TCA_GATE_FLAGS, p->tcfg_flags))
+		goto nla_put_failure;
+
+	if (nla_put_s32(skb, TCA_GATE_PRIORITY, p->tcfg_priority))
+		goto nla_put_failure;
+
+	entry_list = nla_nest_start_noflag(skb, TCA_GATE_ENTRY_LIST);
+	if (!entry_list)
+		goto nla_put_failure;
+
+	list_for_each_entry(entry, &p->entries, list) {
+		if (dumping_entry(skb, entry) < 0)
+			goto nla_put_failure;
+	}
+
+	nla_nest_end(skb, entry_list);
+
+	tcf_tm_dump(&t, &gact->tcf_tm);
+	if (nla_put_64bit(skb, TCA_GATE_TM, sizeof(t), &t, TCA_GATE_PAD))
+		goto nla_put_failure;
+	spin_unlock_bh(&gact->tcf_lock);
+
+	return skb->len;
+
+nla_put_failure:
+	spin_unlock_bh(&gact->tcf_lock);
+	nlmsg_trim(skb, b);
+	return -1;
+}
+
+static int tcf_gate_walker(struct net *net, struct sk_buff *skb,
+			   struct netlink_callback *cb, int type,
+			   const struct tc_action_ops *ops,
+			   struct netlink_ext_ack *extack)
+{
+	struct tc_action_net *tn = net_generic(net, gate_net_id);
+
+	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
+}
+
+static void tcf_gate_stats_update(struct tc_action *a, u64 bytes, u32 packets,
+				  u64 lastuse, bool hw)
+{
+	struct tcf_gate *gact = to_gate(a);
+	struct tcf_t *tm = &gact->tcf_tm;
+
+	tcf_action_update_stats(a, bytes, packets, false, hw);
+	tm->lastuse = max_t(u64, tm->lastuse, lastuse);
+}
+
+static int tcf_gate_search(struct net *net, struct tc_action **a, u32 index)
+{
+	struct tc_action_net *tn = net_generic(net, gate_net_id);
+
+	return tcf_idr_search(tn, a, index);
+}
+
+static size_t tcf_gate_get_fill_size(const struct tc_action *act)
+{
+	return nla_total_size(sizeof(struct tc_gate));
+}
+
+static struct tc_action_ops act_gate_ops = {
+	.kind		=	"gate",
+	.id		=	TCA_ID_GATE,
+	.owner		=	THIS_MODULE,
+	.act		=	tcf_gate_act,
+	.dump		=	tcf_gate_dump,
+	.init		=	tcf_gate_init,
+	.cleanup	=	tcf_gate_cleanup,
+	.walk		=	tcf_gate_walker,
+	.stats_update	=	tcf_gate_stats_update,
+	.get_fill_size	=	tcf_gate_get_fill_size,
+	.lookup		=	tcf_gate_search,
+	.size		=	sizeof(struct tcf_gate),
+};
+
+static __net_init int gate_init_net(struct net *net)
+{
+	struct tc_action_net *tn = net_generic(net, gate_net_id);
+
+	return tc_action_net_init(net, tn, &act_gate_ops);
+}
+
+static void __net_exit gate_exit_net(struct list_head *net_list)
+{
+	tc_action_net_exit(net_list, gate_net_id);
+}
+
+static struct pernet_operations gate_net_ops = {
+	.init = gate_init_net,
+	.exit_batch = gate_exit_net,
+	.id   = &gate_net_id,
+	.size = sizeof(struct tc_action_net),
+};
+
+static int __init gate_init_module(void)
+{
+	return tcf_register_action(&act_gate_ops, &gate_net_ops);
+}
+
+static void __exit gate_cleanup_module(void)
+{
+	tcf_unregister_action(&act_gate_ops, &gate_net_ops);
+}
+
+module_init(gate_init_module);
+module_exit(gate_cleanup_module);
+MODULE_LICENSE("GPL v2");
author
#98 lore raw

RE: [EXT] Re: [v4,net-next 1/4] net: qos: introduce a gate control flow action

Hi Vlad,

Quoted 374 lines

-----Original Message-----
From: Vlad Buslov <[email protected]>
Sent: 2020年4月30日 1:04
To: Po Liu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Claudiu Manoil <[email protected]>; Vladimir Oltean <[email protected]>; Alexandru Marginean <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [EXT] Re: [v4,net-next 1/4] net: qos: introduce a gate control flow action

Caution: EXT Email

Hi Po,

Quoted 41 lines · Po Liu

Introduce a ingress frame gate control flow action.
Tc gate action does the work like this:
Assume there is a gate allow specified ingress frames can be passed at specific time slot, and be dropped at specific time slot. Tc filter chooses the ingress frames, and tc gate action would specify what slot does these frames can be passed to device and what time slot would be dropped.
Tc gate action would provide an entry list to tell how much time gate keep open and how much time gate keep state close. Gate action also assign a start time to tell when the entry list start. Then driver would repeat the gate entry list cyclically.
For the software simulation, gate action requires the user assign a time clock type.

Below is the setting example in user space. Tc filter a stream source ip address is 192.168.0.20 and gate action own two time slots. One is last 200ms gate open let frame pass another is last 100ms gate close let frames dropped. When the ingress frames have reach total frames over
8000000 bytes, the excessive frames will be dropped in that 200000000ns time slot.

Quoted 3 lines

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 clockid CLOCK_TAI \
         sched-entry open 200000000 -1 8000000 \
         sched-entry close 100000000 -1 -1
Quoted 1 line

tc chain del dev eth0 ingress chain 0

"sched-entry" follow the name taprio style. Gate state is "open"/"close". Follow with period nanosecond. Then next item 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.
Base-time is not set will be 0 as default, as result start time would be ((N + 1) * cycletime) which is the minimal of future time.

Quoted 3 lines

Below example shows filtering a stream with destination mac address is 10:00:80:00:00:00 and ip type is ICMP, follow the action gate. The gate action would run with one close time slot which means always keep

close.

Quoted 80 lines

The time cycle is total 200000000ns. The base-time would calculate by:

1357000000000 + (N + 1) * cycletime

When the total value is the future time, it will be the start time. The cycletime here would be 200000000ns for this case.

Quoted 1 line

tc filter add dev eth0 parent ffff: protocol ip \

         flower skip_hw ip_proto icmp dst_mac 10:00:80:00:00:00 \
         action gate index 12 base-time 1357000000000 \
         sched-entry close 200000000 -1 -1 \
         clockid CLOCK_TAI
---
 include/net/tc_act/tc_gate.h        |  47 ++
 include/uapi/linux/pkt_cls.h        |   1 +
 include/uapi/linux/tc_act/tc_gate.h |  47 ++
 net/sched/Kconfig                   |  12 +
 net/sched/Makefile                  |   1 +
 net/sched/act_gate.c                | 638 ++++++++++++++++++++++++++++
 6 files changed, 746 insertions(+)
 create mode 100644 include/net/tc_act/tc_gate.h  create mode 100644
include/uapi/linux/tc_act/tc_gate.h
 create mode 100644 net/sched/act_gate.c
(quoted diff) +0 -0

b/include/net/tc_act/tc_gate.h new file mode 100644 index 000000000000..330ad8b02495

include/net/tc_act/tc_gate.h new file +47 -0
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright 2020 NXP */
+
+#ifndef __NET_TC_GATE_H
+#define __NET_TC_GATE_H
+
+#include <net/act_api.h>
+#include <linux/tc_act/tc_gate.h>
+
+struct tcfg_gate_entry {
+     int                     index;
+     u8                      gate_state;
+     u32                     interval;
+     s32                     ipv;
+     s32                     maxoctets;
+     struct list_head        list;
+};
+
+struct tcf_gate_params {
+     s32                     tcfg_priority;
+     u64                     tcfg_basetime;
+     u64                     tcfg_cycletime;
+     u64                     tcfg_cycletime_ext;
+     u32                     tcfg_flags;
+     s32                     tcfg_clockid;
+     size_t                  num_entries;
+     struct list_head        entries;
+};
+
+#define GATE_ACT_GATE_OPEN   BIT(0)
+#define GATE_ACT_PENDING     BIT(1)
+
+struct tcf_gate {
+     struct tc_action        common;
+     struct tcf_gate_params  param;
+     u8                      current_gate_status;
+     ktime_t                 current_close_time;
+     u32                     current_entry_octets;
+     s32                     current_max_octets;
+     struct tcfg_gate_entry  *next_entry;
+     struct hrtimer          hitimer;
+     enum tk_offsets         tk_offset;
+};
+
+#define to_gate(a) ((struct tcf_gate *)a)
+
+#endif
(quoted diff) +0 -0
Quoted 1 line

b/include/uapi/linux/pkt_cls.h index 9f06d29cab70..fc672b232437

100644

Quoted 36 lines
include/uapi/linux/pkt_cls.h +1 -0
@@ -134,6 +134,7 @@ enum tca_id {
      TCA_ID_CTINFO,
      TCA_ID_MPLS,
      TCA_ID_CT,
+     TCA_ID_GATE,
      /* other actions go here */
      __TCA_ID_MAX = 255
 };
include/uapi/linux/tc_act/tc_gate.h new file +19 -0
new file mode 100644
index 000000000000..f214b3a6d44f
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
+/* Copyright 2020 NXP */
+
+#ifndef __LINUX_TC_GATE_H
+#define __LINUX_TC_GATE_H
+
+#include <linux/pkt_cls.h>
+
+struct tc_gate {
+     tc_gen;
+};
+
+enum {
+     TCA_GATE_ENTRY_UNSPEC,
+     TCA_GATE_ENTRY_INDEX,
+     TCA_GATE_ENTRY_GATE,
+     TCA_GATE_ENTRY_INTERVAL,
+     TCA_GATE_ENTRY_IPV,
+     TCA_GATE_ENTRY_MAX_OCTETS,

include/uapi/linux/tc_act/tc_gate.h line 29

Quoted 10 lines
include/uapi/linux/tc_act/tc_gate.h new file +10 -0
+     __TCA_GATE_ENTRY_MAX,
+};
+#define TCA_GATE_ENTRY_MAX (__TCA_GATE_ENTRY_MAX - 1)
+
+enum {
+     TCA_GATE_ONE_ENTRY_UNSPEC,
+     TCA_GATE_ONE_ENTRY,
+     __TCA_GATE_ONE_ENTRY_MAX,
+};
+#define TCA_GATE_ONE_ENTRY_MAX (__TCA_GATE_ONE_ENTRY_MAX

- 1)

net/sched/Makefile obj-$(CONFIG_NET_IFE_SKBPRIO) +=

Quoted 46 lines
include/uapi/linux/tc_act/tc_gate.h new file +18 -0
+
+enum {
+     TCA_GATE_UNSPEC,
+     TCA_GATE_TM,
+     TCA_GATE_PARMS,
+     TCA_GATE_PAD,
+     TCA_GATE_PRIORITY,
+     TCA_GATE_ENTRY_LIST,
+     TCA_GATE_BASE_TIME,
+     TCA_GATE_CYCLE_TIME,
+     TCA_GATE_CYCLE_TIME_EXT,
+     TCA_GATE_FLAGS,
+     TCA_GATE_CLOCKID,
+     __TCA_GATE_MAX,
+};
+#define TCA_GATE_MAX (__TCA_GATE_MAX - 1)
+
+#endif
net/sched/Kconfig index renamed from net/sched/Kconfig +0 -0

bfbefb7bff9d..2f20073f4f84 100644

net/sched/Kconfig +12 -0
@@ -981,6 +981,18 @@ config NET_ACT_CT
        To compile this code as a module, choose M here: the
        module will be called act_ct.
 
+config NET_ACT_GATE
+     tristate "Frame gate entry list control tc action"
+     depends on NET_CLS_ACT
+     help
+       Say Y here to allow to control the ingress flow to be passed at
+       specific time slot and be dropped at other specific time slot by
+       the gate entry list.
+
+       If unsure, say N.
+       To compile this code as a module, choose M here: the
+       module will be called act_gate.
+
 config NET_IFE_SKBMARK
      tristate "Support to encoding decoding skb mark on IFE action"
      depends on NET_ACT_IFE
net/sched/Makefile index renamed from net/sched/Makefile +0 -0

31c367a6cd09..66bbf9a98f9e 100644

net/sched/Makefile +0 -0
@@ -30,6 +30,7 @@ obj-$(CONFIG_NET_IFE_SKBPRIO)       +=

act_meta_skbprio.o

Quoted 84 lines
net/sched/Makefile +1 -0
 obj-$(CONFIG_NET_IFE_SKBTCINDEX)     += act_meta_skbtcindex.o
 obj-$(CONFIG_NET_ACT_TUNNEL_KEY)+= act_tunnel_key.o
 obj-$(CONFIG_NET_ACT_CT)     += act_ct.o
+obj-$(CONFIG_NET_ACT_GATE)   += act_gate.o
 obj-$(CONFIG_NET_SCH_FIFO)   += sch_fifo.o
 obj-$(CONFIG_NET_SCH_CBQ)    += sch_cbq.o
 obj-$(CONFIG_NET_SCH_HTB)    += sch_htb.o
net/sched/act_gate.c new file mode renamed from net/sched/act_gate.c +0 -0

100644 index 000000000000..916f6fe56692

net/sched/act_gate.c new file +72 -0
@@ -0,0 +1,638 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright 2020 NXP */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/skbuff.h>
+#include <linux/rtnetlink.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <net/act_api.h>
+#include <net/netlink.h>
+#include <net/pkt_cls.h>
+#include <net/tc_act/tc_gate.h>
+
+static unsigned int gate_net_id;
+static struct tc_action_ops act_gate_ops;
+
+static ktime_t gate_get_time(struct tcf_gate *gact) {
+     ktime_t mono = ktime_get();
+
+     switch (gact->tk_offset) {
+     case TK_OFFS_MAX:
+             return mono;
+     default:
+             return ktime_mono_to_any(mono, gact->tk_offset);
+     }
+
+     return KTIME_MAX;
+}
+
+static int gate_get_start_time(struct tcf_gate *gact, ktime_t *start)
+{
+     struct tcf_gate_params *param = &gact->param;
+     ktime_t now, base, cycle;
+     u64 n;
+
+     base = ns_to_ktime(param->tcfg_basetime);
+     now = gate_get_time(gact);
+
+     if (ktime_after(base, now)) {
+             *start = base;
+             return 0;
+     }
+
+     cycle = param->tcfg_cycletime;
+
+     /* cycle time should not be zero */
+     if (!cycle)
+             return -EFAULT;
+
+     n = div64_u64(ktime_sub_ns(now, base), cycle);
+     *start = ktime_add_ns(base, (n + 1) * cycle);
+     return 0;
+}
+
+static void gate_start_timer(struct tcf_gate *gact, ktime_t start) {
+     ktime_t expires;
+
+     expires = hrtimer_get_expires(&gact->hitimer);
+     if (expires == 0)
+             expires = KTIME_MAX;
+
+     start = min_t(ktime_t, start, expires);
+
+     hrtimer_start(&gact->hitimer, start, HRTIMER_MODE_ABS); }
+
+static enum hrtimer_restart gate_timer_func(struct hrtimer *timer) {
+     struct tcf_gate *gact = container_of(timer, struct tcf_gate,
+                                          hitimer);

net/sched/act_gate.c line 82

Quoted 10 lines
net/sched/act_gate.c new file +10 -0
+     struct tcf_gate_params *p = &gact->param;
+     struct tcfg_gate_entry *next;
+     ktime_t close_time, now;
+
+     spin_lock(&gact->tcf_lock);
+
+     next = gact->next_entry;
+
+     /* cycle start, clear pending bit, clear total octets */
+     gact->current_gate_status = next->gate_state ?

GATE_ACT_GATE_OPEN : 0;

Quoted 35 lines
net/sched/act_gate.c new file +35 -0
+     gact->current_entry_octets = 0;
+     gact->current_max_octets = next->maxoctets;
+
+     gact->current_close_time = ktime_add_ns(gact->current_close_time,
+                                             next->interval);
+
+     close_time = gact->current_close_time;
+
+     if (list_is_last(&next->list, &p->entries))
+             next = list_first_entry(&p->entries,
+                                     struct tcfg_gate_entry, list);
+     else
+             next = list_next_entry(next, list);
+
+     now = gate_get_time(gact);
+
+     if (ktime_after(now, close_time)) {
+             ktime_t cycle, base;
+             u64 n;
+
+             cycle = p->tcfg_cycletime;
+             base = ns_to_ktime(p->tcfg_basetime);
+             n = div64_u64(ktime_sub_ns(now, base), cycle);
+             close_time = ktime_add_ns(base, (n + 1) * cycle);
+     }
+
+     gact->next_entry = next;
+
+     hrtimer_set_expires(&gact->hitimer, close_time);
+
+     spin_unlock(&gact->tcf_lock);
+
+     return HRTIMER_RESTART;
+}
+
Quoted 8 lines

net/sched/act_gate.c line 127

Quoted 5 lines
net/sched/act_gate.c new file +5 -0
+static int tcf_gate_act(struct sk_buff *skb, const struct tc_action *a,
+                     struct tcf_result *res) {
+     struct tcf_gate *gact = to_gate(a);
+
+     spin_lock_bh(&gact->tcf_lock);

I think you need to use regular spin_lock() function here because this function is called from softirq context.

Understand, I'll change to spin_lock().

Quoted 318 lines
Quoted 22 lines
net/sched/act_gate.c new file +21 -0
+
+     tcf_lastuse_update(&gact->tcf_tm);
+     bstats_update(&gact->tcf_bstats, skb);
+
+     if (unlikely(gact->current_gate_status & GATE_ACT_PENDING)) {
+             spin_unlock_bh(&gact->tcf_lock);
+             return gact->tcf_action;
+     }
+
+     if (!(gact->current_gate_status & GATE_ACT_GATE_OPEN))
+             goto drop;
+
+     if (gact->current_max_octets >= 0) {
+             gact->current_entry_octets += qdisc_pkt_len(skb);
+             if (gact->current_entry_octets > gact->current_max_octets) {
+                     gact->tcf_qstats.overlimits++;
+                     goto drop;
+             }
+     }
+
+     spin_unlock_bh(&gact->tcf_lock);

net/sched/act_gate.c

Quoted 10 lines
net/sched/act_gate.c new file +10 -0
+
+     return gact->tcf_action;
+drop:
+     gact->tcf_qstats.drops++;
+     spin_unlock_bh(&gact->tcf_lock);
+
+     return TC_ACT_SHOT;
+}
+
+static const struct nla_policy entry_policy[TCA_GATE_ENTRY_MAX + 1]

= {

Quoted 32 lines
net/sched/act_gate.c new file +32 -0
+     [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),
+                                         .type = NLA_EXACT_LEN },
+     [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;
+
+     entry->gate_state = nla_get_flag(tb[TCA_GATE_ENTRY_GATE]);
+
+     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;
+     }

net/sched/act_gate.c

Quoted 10 lines
net/sched/act_gate.c new file +10 -0
+
+     entry->interval = interval;
+
+     if (tb[TCA_GATE_ENTRY_IPV])
+             entry->ipv = nla_get_s32(tb[TCA_GATE_ENTRY_IPV]);
+     else
+             entry->ipv = -1;
+
+     if (tb[TCA_GATE_ENTRY_MAX_OCTETS])
+             entry->maxoctets =

nla_get_s32(tb[TCA_GATE_ENTRY_MAX_OCTETS]);

net/sched/act_gate.c

Quoted 7 lines
net/sched/act_gate.c new file +7 -0
+     else
+             entry->maxoctets = -1;
+
+     return 0;
+}
+
+static int parse_gate_entry(struct nlattr *n, struct  tcfg_gate_entry

*entry,

net/sched/act_gate.c

Quoted 5 lines
net/sched/act_gate.c new file +5 -0
+                         int index, struct netlink_ext_ack *extack) {
+     struct nlattr *tb[TCA_GATE_ENTRY_MAX + 1] = { };
+     int err;
+
+     err = nla_parse_nested(tb, TCA_GATE_ENTRY_MAX, n, entry_policy,

extack);

Quoted 228 lines
net/sched/act_gate.c new file +228 -0
+     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); }
+
+static void release_entry_list(struct list_head *entries) {
+     struct tcfg_gate_entry *entry, *e;
+
+     list_for_each_entry_safe(entry, e, entries, list) {
+             list_del(&entry->list);
+             kfree(entry);
+     }
+}
+
+static int parse_gate_list(struct nlattr *list_attr,
+                        struct tcf_gate_params *sched,
+                        struct netlink_ext_ack *extack) {
+     struct tcfg_gate_entry *entry;
+     struct nlattr *n;
+     int err, rem;
+     int i = 0;
+
+     if (!list_attr)
+             return -EINVAL;
+
+     nla_for_each_nested(n, list_attr, rem) {
+             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");
+                     err = -ENOMEM;
+                     goto release_list;
+             }
+
+             err = parse_gate_entry(n, entry, i, extack);
+             if (err < 0) {
+                     kfree(entry);
+                     goto release_list;
+             }
+
+             list_add_tail(&entry->list, &sched->entries);
+             i++;
+     }
+
+     sched->num_entries = i;
+
+     return i;
+
+release_list:
+     release_entry_list(&sched->entries);
+
+     return err;
+}
+
+static int tcf_gate_init(struct net *net, struct nlattr *nla,
+                      struct nlattr *est, struct tc_action **a,
+                      int ovr, int bind, bool rtnl_held,
+                      struct tcf_proto *tp, u32 flags,
+                      struct netlink_ext_ack *extack) {
+     struct tc_action_net *tn = net_generic(net, gate_net_id);
+     enum tk_offsets tk_offset = TK_OFFS_TAI;
+     struct nlattr *tb[TCA_GATE_MAX + 1];
+     struct tcf_chain *goto_ch = NULL;
+     struct tcf_gate_params *p;
+     s32 clockid = CLOCK_TAI;
+     struct tcf_gate *gact;
+     struct tc_gate *parm;
+     int ret = 0, err;
+     u64 basetime = 0;
+     u32 gflags = 0;
+     s32 prio = -1;
+     ktime_t start;
+     u32 index;
+
+     if (!nla)
+             return -EINVAL;
+
+     err = nla_parse_nested(tb, TCA_GATE_MAX, nla, gate_policy, extack);
+     if (err < 0)
+             return err;
+
+     if (!tb[TCA_GATE_PARMS])
+             return -EINVAL;
+
+     parm = nla_data(tb[TCA_GATE_PARMS]);
+     index = parm->index;
+
+     err = tcf_idr_check_alloc(tn, &index, a, bind);
+     if (err < 0)
+             return err;
+
+     if (err && bind)
+             return 0;
+
+     if (!err) {
+             ret = tcf_idr_create(tn, index, est, a,
+                                  &act_gate_ops, bind, false, 0);
+             if (ret) {
+                     tcf_idr_cleanup(tn, index);
+                     return ret;
+             }
+
+             ret = ACT_P_CREATED;
+     } else if (!ovr) {
+             tcf_idr_release(*a, bind);
+             return -EEXIST;
+     }
+
+     if (tb[TCA_GATE_PRIORITY])
+             prio = nla_get_s32(tb[TCA_GATE_PRIORITY]);
+
+     if (tb[TCA_GATE_BASE_TIME])
+             basetime = nla_get_u64(tb[TCA_GATE_BASE_TIME]);
+
+     if (tb[TCA_GATE_FLAGS])
+             gflags = nla_get_u32(tb[TCA_GATE_FLAGS]);
+
+     if (tb[TCA_GATE_CLOCKID]) {
+             clockid = nla_get_s32(tb[TCA_GATE_CLOCKID]);
+             switch (clockid) {
+             case CLOCK_REALTIME:
+                     tk_offset = TK_OFFS_REAL;
+                     break;
+             case CLOCK_MONOTONIC:
+                     tk_offset = TK_OFFS_MAX;
+                     break;
+             case CLOCK_BOOTTIME:
+                     tk_offset = TK_OFFS_BOOT;
+                     break;
+             case CLOCK_TAI:
+                     tk_offset = TK_OFFS_TAI;
+                     break;
+             default:
+                     NL_SET_ERR_MSG(extack, "Invalid 'clockid'");
+                     goto release_idr;
+             }
+     }
+
+     err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack);
+     if (err < 0)
+             goto release_idr;
+
+     gact = to_gate(*a);
+
+     spin_lock_bh(&gact->tcf_lock);
+     p = &gact->param;
+
+     if (tb[TCA_GATE_CYCLE_TIME]) {
+             p->tcfg_cycletime = nla_get_u64(tb[TCA_GATE_CYCLE_TIME]);
+             if (!p->tcfg_cycletime_ext)
+                     goto chain_put;
+     }
+
+     INIT_LIST_HEAD(&p->entries);
+     if (tb[TCA_GATE_ENTRY_LIST]) {
+             err = parse_gate_list(tb[TCA_GATE_ENTRY_LIST], p, extack);
+             if (err < 0)
+                     goto chain_put;
+     }
+
+     if (!p->tcfg_cycletime) {
+             struct tcfg_gate_entry *entry;
+             ktime_t cycle = 0;
+
+             list_for_each_entry(entry, &p->entries, list)
+                     cycle = ktime_add_ns(cycle, entry->interval);
+             p->tcfg_cycletime = cycle;
+     }
+
+     if (tb[TCA_GATE_CYCLE_TIME_EXT])
+             p->tcfg_cycletime_ext =
+                     nla_get_u64(tb[TCA_GATE_CYCLE_TIME_EXT]);
+
+     p->tcfg_priority = prio;
+     p->tcfg_basetime = basetime;
+     p->tcfg_clockid = clockid;
+     p->tcfg_flags = gflags;
+
+     gact->tk_offset = tk_offset;
+     hrtimer_init(&gact->hitimer, clockid, HRTIMER_MODE_ABS);
+     gact->hitimer.function = gate_timer_func;
+
+     err = gate_get_start_time(gact, &start);
+     if (err < 0) {
+             NL_SET_ERR_MSG(extack,
+                            "Internal error: failed get start time");
+             release_entry_list(&p->entries);
+             goto chain_put;
+     }
+
+     gact->current_close_time = start;
+     gact->current_gate_status = GATE_ACT_GATE_OPEN |
+ GATE_ACT_PENDING;
+
+     gact->next_entry = list_first_entry(&p->entries,
+                                         struct tcfg_gate_entry,
+ list);
+
+     goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
+
+     gate_start_timer(gact, start);
+
+     spin_unlock_bh(&gact->tcf_lock);
+
+     if (goto_ch)
+             tcf_chain_put_by_act(goto_ch);
+
+     if (ret == ACT_P_CREATED)
+             tcf_idr_insert(tn, *a);
+     return ret;
+
+chain_put:
+     spin_unlock_bh(&gact->tcf_lock);
+
+     if (goto_ch)
+             tcf_chain_put_by_act(goto_ch);
+release_idr:
+     tcf_idr_release(*a, bind);
+     return err;
+}
Quoted 8 lines

net/sched/act_gate.c line 451

Quoted 6 lines
net/sched/act_gate.c new file +6 -0
+
+static void tcf_gate_cleanup(struct tc_action *a) {
+     struct tcf_gate *gact = to_gate(a);
+     struct tcf_gate_params *p;
+
+     spin_lock_bh(&gact->tcf_lock);

No need to lock in tc_action_ops->cleanup() callbacks.

I'll remove the lock in cleanup callback. Thanks!

Quoted 163 lines
Quoted 106 lines
net/sched/act_gate.c new file +26 -0
+
+     hrtimer_cancel(&gact->hitimer);
+
+     p = &gact->param;
+     release_entry_list(&p->entries);
+
+     spin_unlock_bh(&gact->tcf_lock); }
+
+static int dumping_entry(struct sk_buff *skb,
+                      struct tcfg_gate_entry *entry) {
+     struct nlattr *item;
+
+     item = nla_nest_start_noflag(skb, TCA_GATE_ONE_ENTRY);
+     if (!item)
+             return -ENOSPC;
+
+     if (nla_put_u32(skb, TCA_GATE_ENTRY_INDEX, entry->index))
+             goto nla_put_failure;
+
+     if (entry->gate_state && nla_put_flag(skb, TCA_GATE_ENTRY_GATE))
+             goto nla_put_failure;
+
+     if (nla_put_u32(skb, TCA_GATE_ENTRY_INTERVAL, entry->interval))
+             goto nla_put_failure;
+
+     if (nla_put_s32(skb, TCA_GATE_ENTRY_MAX_OCTETS, entry-

maxoctets))

net/sched/act_gate.c new file +78 -0
+             goto nla_put_failure;
+
+     if (nla_put_s32(skb, TCA_GATE_ENTRY_IPV, entry->ipv))
+             goto nla_put_failure;
+
+     return nla_nest_end(skb, item);
+
+nla_put_failure:
+     nla_nest_cancel(skb, item);
+     return -1;
+}
+
+static int tcf_gate_dump(struct sk_buff *skb, struct tc_action *a,
+                      int bind, int ref) {
+     unsigned char *b = skb_tail_pointer(skb);
+     struct tcf_gate *gact = to_gate(a);
+     struct tc_gate opt = {
+             .index    = gact->tcf_index,
+             .refcnt   = refcount_read(&gact->tcf_refcnt) - ref,
+             .bindcnt  = atomic_read(&gact->tcf_bindcnt) - bind,
+     };
+     struct tcfg_gate_entry *entry;
+     struct tcf_gate_params *p;
+     struct nlattr *entry_list;
+     struct tcf_t t;
+
+     spin_lock_bh(&gact->tcf_lock);
+     opt.action = gact->tcf_action;
+
+     p = &gact->param;
+
+     if (nla_put(skb, TCA_GATE_PARMS, sizeof(opt), &opt))
+             goto nla_put_failure;
+
+     if (nla_put_u64_64bit(skb, TCA_GATE_BASE_TIME,
+                           p->tcfg_basetime, TCA_GATE_PAD))
+             goto nla_put_failure;
+
+     if (nla_put_u64_64bit(skb, TCA_GATE_CYCLE_TIME,
+                           p->tcfg_cycletime, TCA_GATE_PAD))
+             goto nla_put_failure;
+
+     if (nla_put_u64_64bit(skb, TCA_GATE_CYCLE_TIME_EXT,
+                           p->tcfg_cycletime_ext, TCA_GATE_PAD))
+             goto nla_put_failure;
+
+     if (nla_put_s32(skb, TCA_GATE_CLOCKID, p->tcfg_clockid))
+             goto nla_put_failure;
+
+     if (nla_put_u32(skb, TCA_GATE_FLAGS, p->tcfg_flags))
+             goto nla_put_failure;
+
+     if (nla_put_s32(skb, TCA_GATE_PRIORITY, p->tcfg_priority))
+             goto nla_put_failure;
+
+     entry_list = nla_nest_start_noflag(skb, TCA_GATE_ENTRY_LIST);
+     if (!entry_list)
+             goto nla_put_failure;
+
+     list_for_each_entry(entry, &p->entries, list) {
+             if (dumping_entry(skb, entry) < 0)
+                     goto nla_put_failure;
+     }
+
+     nla_nest_end(skb, entry_list);
+
+     tcf_tm_dump(&t, &gact->tcf_tm);
+     if (nla_put_64bit(skb, TCA_GATE_TM, sizeof(t), &t, TCA_GATE_PAD))
+             goto nla_put_failure;
+     spin_unlock_bh(&gact->tcf_lock);
+
+     return skb->len;
+
+nla_put_failure:
+     spin_unlock_bh(&gact->tcf_lock);
+     nlmsg_trim(skb, b);
+     return -1;
+}

net/sched/act_gate.c

Quoted 10 lines
net/sched/act_gate.c new file +10 -0
+
+static int tcf_gate_walker(struct net *net, struct sk_buff *skb,
+                        struct netlink_callback *cb, int type,
+                        const struct tc_action_ops *ops,
+                        struct netlink_ext_ack *extack) {
+     struct tc_action_net *tn = net_generic(net, gate_net_id);
+
+     return tcf_generic_walker(tn, skb, cb, type, ops, extack); }
+
+static void tcf_gate_stats_update(struct tc_action *a, u64 bytes, u32

packets,

Quoted 46 lines
net/sched/act_gate.c new file +46 -0
+                               u64 lastuse, bool hw) {
+     struct tcf_gate *gact = to_gate(a);
+     struct tcf_t *tm = &gact->tcf_tm;
+
+     tcf_action_update_stats(a, bytes, packets, false, hw);
+     tm->lastuse = max_t(u64, tm->lastuse, lastuse); }
+
+static int tcf_gate_search(struct net *net, struct tc_action **a, u32
+index) {
+     struct tc_action_net *tn = net_generic(net, gate_net_id);
+
+     return tcf_idr_search(tn, a, index); }
+
+static size_t tcf_gate_get_fill_size(const struct tc_action *act) {
+     return nla_total_size(sizeof(struct tc_gate)); }
+
+static struct tc_action_ops act_gate_ops = {
+     .kind           =       "gate",
+     .id             =       TCA_ID_GATE,
+     .owner          =       THIS_MODULE,
+     .act            =       tcf_gate_act,
+     .dump           =       tcf_gate_dump,
+     .init           =       tcf_gate_init,
+     .cleanup        =       tcf_gate_cleanup,
+     .walk           =       tcf_gate_walker,
+     .stats_update   =       tcf_gate_stats_update,
+     .get_fill_size  =       tcf_gate_get_fill_size,
+     .lookup         =       tcf_gate_search,
+     .size           =       sizeof(struct tcf_gate),
+};
+
+static __net_init int gate_init_net(struct net *net) {
+     struct tc_action_net *tn = net_generic(net, gate_net_id);
+
+     return tc_action_net_init(net, tn, &act_gate_ops); }
+
+static void __net_exit gate_exit_net(struct list_head *net_list) {
+     tc_action_net_exit(net_list, gate_net_id); }
+
+static struct pernet_operations gate_net_ops = {
+     .init = gate_init_net,
+     .exit_batch = gate_exit_net,
+     .id   = &gate_net_id,
+     .size = sizeof(struct tc_action_net), };
+
+static int __init gate_init_module(void) {
Quoted 8 lines

net/sched/act_gate.c line 638

Quoted 8 lines
net/sched/act_gate.c new file +8 -0
+     return tcf_register_action(&act_gate_ops, &gate_net_ops); }
+
+static void __exit gate_cleanup_module(void) {
+     tcf_unregister_action(&act_gate_ops, &gate_net_ops); }
+
+module_init(gate_init_module);
+module_exit(gate_cleanup_module);
+MODULE_LICENSE("GPL v2");

Thanks a lot.

Br,
Po Liu

author
#99 lore raw

PATCH v4 2/4 net: schedule: add action gate offloading

In reply to Po Liu

Add the gate action to the flow action entry. Add the gate parameters to the tc_setup_flow_action() queueing to the entries of flow_action_entry array provide to the driver.

---
 include/net/flow_offload.h   |  10 ++++
 include/net/tc_act/tc_gate.h | 113 +++++++++++++++++++++++++++++++++++
 net/sched/cls_api.c          |  33 ++++++++++
 3 files changed, 156 insertions(+)
include/net/flow_offload.h +10 -0
index 3619c6acf60f..94a30fe02e6d 100644
@@ -147,6 +147,7 @@ enum flow_action_id {
 	FLOW_ACTION_MPLS_PUSH,
 	FLOW_ACTION_MPLS_POP,
 	FLOW_ACTION_MPLS_MANGLE,
+	FLOW_ACTION_GATE,
 	NUM_FLOW_ACTIONS,
 };
 
@@ -255,6 +256,15 @@ struct flow_action_entry {
 			u8		bos;
 			u8		ttl;
 		} mpls_mangle;
+		struct {
+			u32		index;
+			s32		prio;
+			u64		basetime;
+			u64		cycletime;
+			u64		cycletimeext;
+			u32		num_entries;
+			struct action_gate_entry *entries;
+		} gate;
 	};
 	struct flow_action_cookie *cookie; /* user defined action cookie */
 };
include/net/tc_act/tc_gate.h +113 -0

123 lines not on this page · raw message

net/sched/cls_api.c +33 -0
index 11b683c45c28..7e85c91d0752 100644
@@ -39,6 +39,7 @@
 #include <net/tc_act/tc_skbedit.h>
 #include <net/tc_act/tc_ct.h>
 #include <net/tc_act/tc_mpls.h>
+#include <net/tc_act/tc_gate.h>
 #include <net/flow_offload.h>
 
 extern const struct nla_policy rtm_tca_policy[TCA_MAX + 1];
@@ -3526,6 +3527,27 @@ static void tcf_sample_get_group(struct flow_action_entry *entry,
 #endif
 }
 
+static void tcf_gate_entry_destructor(void *priv)
+{
+	struct action_gate_entry *oe = priv;
+
+	kfree(oe);
+}
+
+static int tcf_gate_get_entries(struct flow_action_entry *entry,
+				const struct tc_action *act)
+{
+	entry->gate.entries = tcf_gate_get_list(act);
+
+	if (!entry->gate.entries)
+		return -EINVAL;
+
+	entry->destructor = tcf_gate_entry_destructor;
+	entry->destructor_priv = entry->gate.entries;
+
+	return 0;
+}
+
 int tc_setup_flow_action(struct flow_action *flow_action,
 			 const struct tcf_exts *exts)
 {
@@ -3672,6 +3694,17 @@ int tc_setup_flow_action(struct flow_action *flow_action,
 		} else if (is_tcf_skbedit_priority(act)) {
 			entry->id = FLOW_ACTION_PRIORITY;
 			entry->priority = tcf_skbedit_priority(act);
+		} else if (is_tcf_gate(act)) {
+			entry->id = FLOW_ACTION_GATE;
+			entry->gate.index = tcf_gate_index(act);
+			entry->gate.prio = tcf_gate_prio(act);
+			entry->gate.basetime = tcf_gate_basetime(act);
+			entry->gate.cycletime = tcf_gate_cycletime(act);
+			entry->gate.cycletimeext = tcf_gate_cycletimeext(act);
+			entry->gate.num_entries = tcf_gate_num_entries(act);
+			err = tcf_gate_get_entries(entry, act);
+			if (err)
+				goto err_out;
 		} else {
 			err = -EOPNOTSUPP;
 			goto err_out_locked;
Signature · 1 line
2.17.1
#100 lore raw

Re: [v4,net-next 2/4] net: schedule: add action gate offloading

Quoted 70 lines · Po Liu

Add the gate action to the flow action entry. Add the gate parameters to the tc_setup_flow_action() queueing to the entries of flow_action_entry array provide to the driver.

---
 include/net/flow_offload.h   |  10 ++++
 include/net/tc_act/tc_gate.h | 113 +++++++++++++++++++++++++++++++++++
 net/sched/cls_api.c          |  33 ++++++++++
 3 files changed, 156 insertions(+)
include/net/flow_offload.h +10 -0
index 3619c6acf60f..94a30fe02e6d 100644
@@ -147,6 +147,7 @@ enum flow_action_id {
 	FLOW_ACTION_MPLS_PUSH,
 	FLOW_ACTION_MPLS_POP,
 	FLOW_ACTION_MPLS_MANGLE,
+	FLOW_ACTION_GATE,
 	NUM_FLOW_ACTIONS,
 };
 
@@ -255,6 +256,15 @@ struct flow_action_entry {
 			u8		bos;
 			u8		ttl;
 		} mpls_mangle;
+		struct {
+			u32		index;
+			s32		prio;
+			u64		basetime;
+			u64		cycletime;
+			u64		cycletimeext;
+			u32		num_entries;
+			struct action_gate_entry *entries;
+		} gate;
 	};
 	struct flow_action_cookie *cookie; /* user defined action cookie */
 };
include/net/tc_act/tc_gate.h +16 -0
index 330ad8b02495..9e698c7d64cd 100644
@@ -7,6 +7,13 @@
 #include <net/act_api.h>
 #include <linux/tc_act/tc_gate.h>
 
+struct action_gate_entry {
+	u8			gate_state;
+	u32			interval;
+	s32			ipv;
+	s32			maxoctets;
+};
+
 struct tcfg_gate_entry {
 	int			index;
 	u8			gate_state;
@@ -44,4 +51,110 @@ struct tcf_gate {
 
 #define to_gate(a) ((struct tcf_gate *)a)
 
+static inline bool is_tcf_gate(const struct tc_action *a)
+{
+#ifdef CONFIG_NET_CLS_ACT
+	if (a->ops && a->ops->id == TCA_ID_GATE)
+		return true;
+#endif
+	return false;
+}
+

include/net/tc_act/tc_gate.h struct tcf_gate { · line 72

Quoted 10 lines
include/net/tc_act/tc_gate.h +10 -0
+static inline u32 tcf_gate_index(const struct tc_action *a)
+{
+	return a->tcfa_index;
+}
+
+static inline s32 tcf_gate_prio(const struct tc_action *a)
+{
+	s32 tcfg_prio;
+
+	rcu_read_lock();

This action no longer uses rcu, so you don't need protect with rcu_read_lock() in all these helpers.

Quoted 61 lines
include/net/tc_act/tc_gate.h +61 -0
+	tcfg_prio = to_gate(a)->param.tcfg_priority;
+	rcu_read_unlock();
+
+	return tcfg_prio;
+}
+
+static inline u64 tcf_gate_basetime(const struct tc_action *a)
+{
+	u64 tcfg_basetime;
+
+	rcu_read_lock();
+	tcfg_basetime = to_gate(a)->param.tcfg_basetime;
+	rcu_read_unlock();
+
+	return tcfg_basetime;
+}
+
+static inline u64 tcf_gate_cycletime(const struct tc_action *a)
+{
+	u64 tcfg_cycletime;
+
+	rcu_read_lock();
+	tcfg_cycletime = to_gate(a)->param.tcfg_cycletime;
+	rcu_read_unlock();
+
+	return tcfg_cycletime;
+}
+
+static inline u64 tcf_gate_cycletimeext(const struct tc_action *a)
+{
+	u64 tcfg_cycletimeext;
+
+	rcu_read_lock();
+	tcfg_cycletimeext = to_gate(a)->param.tcfg_cycletime_ext;
+	rcu_read_unlock();
+
+	return tcfg_cycletimeext;
+}
+
+static inline u32 tcf_gate_num_entries(const struct tc_action *a)
+{
+	u32 num_entries;
+
+	rcu_read_lock();
+	num_entries = to_gate(a)->param.num_entries;
+	rcu_read_unlock();
+
+	return num_entries;
+}
+
+static inline struct action_gate_entry
+			*tcf_gate_get_list(const struct tc_action *a)
+{
+	struct action_gate_entry *oe;
+	struct tcf_gate_params *p;
+	struct tcfg_gate_entry *entry;
+	u32 num_entries;
+	int i = 0;
+
+	rcu_read_lock();
+

include/net/tc_act/tc_gate.h struct tcf_gate { · line 143

Quoted 10 lines
include/net/tc_act/tc_gate.h +10 -0
+	p = &to_gate(a)->param;
+	num_entries = p->num_entries;
+
+	list_for_each_entry(entry, &p->entries, list)
+		i++;
+
+	if (i != num_entries)
+		return NULL;
+
+	oe = kzalloc(sizeof(*oe) * num_entries, GFP_KERNEL);

Can't allocate with GFP_KERNEL flag in rcu read blocks, but you don't need the rcu read lock here anyway. However, tc_setup_flow_action() calls this function while holding tcfa_lock spinlock, which also precludes allocating memory with that flag. You can test for such problems by enabling CONFIG_DEBUG_ATOMIC_SLEEP. To help uncover such errors all new act APIs and action implementations are usually accompanied by tdc tests. If you chose to implement such tests you can look at 6e52fca36c67 ("tc-tests: Add tc action ct tests") for recent example.

include/net/tc_act/tc_gate.h struct tcf_gate { · line 145

Quoted 2 lines
include/net/tc_act/tc_gate.h +2 -0
+	if (!oe)
+		return NULL;

This returns without releasing rcu read lock, but as I said before you probably don't need rcu protection here anyway.

Quoted 73 lines
include/net/tc_act/tc_gate.h +14 -0
+
+	i = 0;
+	list_for_each_entry(entry, &p->entries, list) {
+		oe[i].gate_state = entry->gate_state;
+		oe[i].interval = entry->interval;
+		oe[i].ipv = entry->ipv;
+		oe[i].maxoctets = entry->maxoctets;
+		i++;
+	}
+
+	rcu_read_unlock();
+
+	return oe;
+}
 #endif
net/sched/cls_api.c +33 -0
index 11b683c45c28..7e85c91d0752 100644
@@ -39,6 +39,7 @@
 #include <net/tc_act/tc_skbedit.h>
 #include <net/tc_act/tc_ct.h>
 #include <net/tc_act/tc_mpls.h>
+#include <net/tc_act/tc_gate.h>
 #include <net/flow_offload.h>
 
 extern const struct nla_policy rtm_tca_policy[TCA_MAX + 1];
@@ -3526,6 +3527,27 @@ static void tcf_sample_get_group(struct flow_action_entry *entry,
 #endif
 }
 
+static void tcf_gate_entry_destructor(void *priv)
+{
+	struct action_gate_entry *oe = priv;
+
+	kfree(oe);
+}
+
+static int tcf_gate_get_entries(struct flow_action_entry *entry,
+				const struct tc_action *act)
+{
+	entry->gate.entries = tcf_gate_get_list(act);
+
+	if (!entry->gate.entries)
+		return -EINVAL;
+
+	entry->destructor = tcf_gate_entry_destructor;
+	entry->destructor_priv = entry->gate.entries;
+
+	return 0;
+}
+
 int tc_setup_flow_action(struct flow_action *flow_action,
 			 const struct tcf_exts *exts)
 {
@@ -3672,6 +3694,17 @@ int tc_setup_flow_action(struct flow_action *flow_action,
 		} else if (is_tcf_skbedit_priority(act)) {
 			entry->id = FLOW_ACTION_PRIORITY;
 			entry->priority = tcf_skbedit_priority(act);
+		} else if (is_tcf_gate(act)) {
+			entry->id = FLOW_ACTION_GATE;
+			entry->gate.index = tcf_gate_index(act);
+			entry->gate.prio = tcf_gate_prio(act);
+			entry->gate.basetime = tcf_gate_basetime(act);
+			entry->gate.cycletime = tcf_gate_cycletime(act);
+			entry->gate.cycletimeext = tcf_gate_cycletimeext(act);
+			entry->gate.num_entries = tcf_gate_num_entries(act);
+			err = tcf_gate_get_entries(entry, act);
+			if (err)
+				goto err_out;
 		} else {
 			err = -EOPNOTSUPP;
 			goto err_out_locked;
author
#101 lore raw

PATCH v4 3/4 net: enetc: add hw tc hw offload features for PSPF capability

In reply to Po Liu

This patch is to let ethtool enable/disable the tc flower offload features. Hardware ENETC has the feature of PSFP which is for per-stream policing. When enable the tc hw offloading feature, driver would enable the IEEE 802.1Qci feature. It is only set the register enable bit for this feature not enable for any entry of per stream filtering and stream gate or stream identify but get how much capabilities for each feature.

---
 drivers/net/ethernet/freescale/enetc/enetc.c  | 23 +++++++++
 drivers/net/ethernet/freescale/enetc/enetc.h  | 48 +++++++++++++++++++
 .../net/ethernet/freescale/enetc/enetc_hw.h   | 17 +++++++
 .../net/ethernet/freescale/enetc/enetc_pf.c   |  8 ++++
 4 files changed, 96 insertions(+)
drivers/net/ethernet/freescale/enetc/enetc.c +23 -0
index ccf2611f4a20..04aac7cbb506 100644
@@ -756,6 +756,9 @@ void enetc_get_si_caps(struct enetc_si *si)
 
 	if (val & ENETC_SIPCAPR0_QBV)
 		si->hw_features |= ENETC_SI_F_QBV;
+
+	if (val & ENETC_SIPCAPR0_PSFP)
+		si->hw_features |= ENETC_SI_F_PSFP;
 }
 
 static int enetc_dma_alloc_bdr(struct enetc_bdr *r, size_t bd_size)
@@ -1567,6 +1570,23 @@ static int enetc_set_rss(struct net_device *ndev, int en)
 	return 0;
 }
 
+static int enetc_set_psfp(struct net_device *ndev, int en)
+{
+	struct enetc_ndev_priv *priv = netdev_priv(ndev);
+
+	if (en) {
+		priv->active_offloads |= ENETC_F_QCI;
+		enetc_get_max_cap(priv);
+		enetc_psfp_enable(&priv->si->hw);
+	} else {
+		priv->active_offloads &= ~ENETC_F_QCI;
+		memset(&priv->psfp_cap, 0, sizeof(struct psfp_cap));
+		enetc_psfp_disable(&priv->si->hw);
+	}
+
+	return 0;
+}
+
 int enetc_set_features(struct net_device *ndev,
 		       netdev_features_t features)
 {
@@ -1575,6 +1595,9 @@ int enetc_set_features(struct net_device *ndev,
 	if (changed & NETIF_F_RXHASH)
 		enetc_set_rss(ndev, !!(features & NETIF_F_RXHASH));
 
+	if (changed & NETIF_F_HW_TC)
+		enetc_set_psfp(ndev, !!(features & NETIF_F_HW_TC));
+
 	return 0;
 }
 
drivers/net/ethernet/freescale/enetc/enetc.h +48 -0

81 lines not on this page · raw message

drivers/net/ethernet/freescale/enetc/enetc_hw.h +17 -0
index 2a6523136947..587974862f48 100644
@@ -19,6 +19,7 @@
 #define ENETC_SICTR1	0x1c
 #define ENETC_SIPCAPR0	0x20
 #define ENETC_SIPCAPR0_QBV	BIT(4)
+#define ENETC_SIPCAPR0_PSFP	BIT(9)
 #define ENETC_SIPCAPR0_RSS	BIT(8)
 #define ENETC_SIPCAPR1	0x24
 #define ENETC_SITGTGR	0x30
@@ -228,6 +229,15 @@ enum enetc_bdr_type {TX, RX};
 #define ENETC_PM0_IFM_RLP	(BIT(5) | BIT(11))
 #define ENETC_PM0_IFM_RGAUTO	(BIT(15) | ENETC_PMO_IFM_RG | BIT(1))
 #define ENETC_PM0_IFM_XGMII	BIT(12)
+#define ENETC_PSIDCAPR		0x1b08
+#define ENETC_PSIDCAPR_MSK	GENMASK(15, 0)
+#define ENETC_PSFCAPR		0x1b18
+#define ENETC_PSFCAPR_MSK	GENMASK(15, 0)
+#define ENETC_PSGCAPR		0x1b28
+#define ENETC_PSGCAPR_GCL_MSK	GENMASK(18, 16)
+#define ENETC_PSGCAPR_SGIT_MSK	GENMASK(15, 0)
+#define ENETC_PFMCAPR		0x1b38
+#define ENETC_PFMCAPR_MSK	GENMASK(15, 0)
 
 /* MAC counters */
 #define ENETC_PM0_REOCT		0x8100
@@ -621,3 +631,10 @@ struct enetc_cbd {
 /* Port time specific departure */
 #define ENETC_PTCTSDR(n)	(0x1210 + 4 * (n))
 #define ENETC_TSDE		BIT(31)
+
+/* PSFP setting */
+#define ENETC_PPSFPMR 0x11b00
+#define ENETC_PPSFPMR_PSFPEN BIT(0)
+#define ENETC_PPSFPMR_VS BIT(1)
+#define ENETC_PPSFPMR_PVC BIT(2)
+#define ENETC_PPSFPMR_PVZC BIT(3)
drivers/net/ethernet/freescale/enetc/enetc_pf.c +8 -0
index de1ad4975074..cef9fbfdb056 100644
@@ -727,6 +727,14 @@ static void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
 	if (si->hw_features & ENETC_SI_F_QBV)
 		priv->active_offloads |= ENETC_F_QBV;
 
+	if (si->hw_features & ENETC_SI_F_PSFP) {
+		priv->active_offloads |= ENETC_F_QCI;
+		ndev->features |= NETIF_F_HW_TC;
+		ndev->hw_features |= NETIF_F_HW_TC;
+		enetc_get_max_cap(priv);
+		enetc_psfp_enable(&si->hw);
+	}
+
 	/* pick up primary MAC address from SI */
 	enetc_get_primary_mac_addr(&si->hw, ndev->dev_addr);
 }
Signature · 1 line
2.17.1
author
#102 lore raw

PATCH v4 4/4 net: enetc: add tc flower psfp offload driver

In reply to Po Liu

This patch is to add tc flower offload for the enetc IEEE 802.1Qci(PSFP) function. There are four main feature parts to implement the flow policing and filtering for ingress flow with IEEE 802.1Qci features. They are stream identify(this is defined in the P802.1cb exactly but needed for 802.1Qci), stream filtering, stream gate and flow metering. Each function block includes many entries by index to assign parameters. So for one frame would be filtered by stream identify first, then flow into stream filter block by the same handle between stream identify and stream filtering. Then flow into stream gate control which assigned by the stream filtering entry. And then policing by the gate and limited by the max sdu in the filter block(optional). At last, policing by the flow metering block, index choosing at the fitering block. So you can see that each entry of block may link to many upper entries since they can be assigned same index means more streams want to share the same feature in the stream filtering or stream gate or flow metering.
To implement such features, each stream filtered by source/destination mac address, some stream maybe also plus the vlan id value would be treated as one flow chain. This would be identified by the chain_index which already in the tc filter concept. Driver would maintain this chain and also with gate modules. The stream filter entry create by the gate index and flow meter(optional) entry id and also one priority value. Offloading only transfer the gate action and flow filtering parameters. Driver would create (or search same gate id and flow meter id and
priority) one stream filter entry to set to the hardware. So stream
filtering do not need transfer by the action offloading. This architecture is same with tc filter and actions relationship. tc filter maintain the list for each flow feature by keys. And actions maintain by the action list.

Below showing a example commands by tc:

Quoted 3 lines

tc qdisc add dev eth0 ingress
ip link set eth0 address 10:00:80:00:00:00
tc filter add dev eth0 parent ffff: protocol ip chain 11 \

	flower skip_sw dst_mac 10:00:80:00:00:00 \
	action gate index 10 \
	sched-entry OPEN 200000000 1 8000000 \
	sched-entry CLOSE 100000000 -1 -1

Command means to set the dst_mac 10:00:80:00:00:00 to index 11 of stream identify module. And the set the gate index 10 of stream gate module. The gate list is keeping OPEN state 200ms, and through the frames to the ingress queue 1, and max octets are the 8Mbytes.

---
 drivers/net/ethernet/freescale/enetc/enetc.c  |   25 +-
 drivers/net/ethernet/freescale/enetc/enetc.h  |   46 +-
 .../net/ethernet/freescale/enetc/enetc_hw.h   |  142 +++
 .../net/ethernet/freescale/enetc/enetc_pf.c   |    4 +-
 .../net/ethernet/freescale/enetc/enetc_qos.c  | 1098 +++++++++++++++++
 5 files changed, 1300 insertions(+), 15 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc.c +17 -8
index 04aac7cbb506..298c55786fd9 100644
@@ -1521,6 +1521,8 @@ int enetc_setup_tc(struct net_device *ndev, enum tc_setup_type type,
 		return enetc_setup_tc_cbs(ndev, type_data);
 	case TC_SETUP_QDISC_ETF:
 		return enetc_setup_tc_txtime(ndev, type_data);
+	case TC_SETUP_BLOCK:
+		return enetc_setup_tc_psfp(ndev, type_data);
 	default:
 		return -EOPNOTSUPP;
 	}
@@ -1573,17 +1575,23 @@ static int enetc_set_rss(struct net_device *ndev, int en)
 static int enetc_set_psfp(struct net_device *ndev, int en)
 {
 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
+	int err;
 
 	if (en) {
+		err = enetc_psfp_enable(priv);
+		if (err)
+			return err;
+
 		priv->active_offloads |= ENETC_F_QCI;
-		enetc_get_max_cap(priv);
-		enetc_psfp_enable(&priv->si->hw);
-	} else {
-		priv->active_offloads &= ~ENETC_F_QCI;
-		memset(&priv->psfp_cap, 0, sizeof(struct psfp_cap));
-		enetc_psfp_disable(&priv->si->hw);
+		return 0;
 	}
 
+	err = enetc_psfp_disable(priv);
+	if (err)
+		return err;
+
+	priv->active_offloads &= ~ENETC_F_QCI;
+
 	return 0;
 }
 
@@ -1591,14 +1599,15 @@ int enetc_set_features(struct net_device *ndev,
 		       netdev_features_t features)
 {
 	netdev_features_t changed = ndev->features ^ features;
+	int err = 0;
 
 	if (changed & NETIF_F_RXHASH)
 		enetc_set_rss(ndev, !!(features & NETIF_F_RXHASH));
 
 	if (changed & NETIF_F_HW_TC)
-		enetc_set_psfp(ndev, !!(features & NETIF_F_HW_TC));
+		err = enetc_set_psfp(ndev, !!(features & NETIF_F_HW_TC));
 
-	return 0;
+	return err;
 }
 
 #ifdef CONFIG_FSL_ENETC_PTP_CLOCK
drivers/net/ethernet/freescale/enetc/enetc.h +42 -4

75 lines not on this page · raw message

drivers/net/ethernet/freescale/enetc/enetc_hw.h +142 -0

161 lines not on this page · raw message

drivers/net/ethernet/freescale/enetc/enetc_pf.c +1 -3
index cef9fbfdb056..824d211ec00f 100644
@@ -727,12 +727,10 @@ static void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
 	if (si->hw_features & ENETC_SI_F_QBV)
 		priv->active_offloads |= ENETC_F_QBV;
 
-	if (si->hw_features & ENETC_SI_F_PSFP) {
+	if (si->hw_features & ENETC_SI_F_PSFP && !enetc_psfp_enable(priv)) {
 		priv->active_offloads |= ENETC_F_QCI;
 		ndev->features |= NETIF_F_HW_TC;
 		ndev->hw_features |= NETIF_F_HW_TC;
-		enetc_get_max_cap(priv);
-		enetc_psfp_enable(&si->hw);
 	}
 
 	/* pick up primary MAC address from SI */
drivers/net/ethernet/freescale/enetc/enetc_qos.c +1098 -0

1,107 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#103 lore raw

v5 cover Introduce a flow gate control action and apply IEEE

Changes from V4:
----------------
0001:
Fix and modify according to Vlid Buslov suggestions:
- Change spin_lock_bh() to spin_lock() since tcf_gate_act() already in software irq.
- Remove spin lock protect in the ops->cleanup function.
- Enable the CONFIG_DEBUG_ATOMIC_SLEEP and CONFIG_PROVE_LOCKING checking, then fix as kzalloc flag type and lock deadlock.
- Change kzalloc() flag type from GFP_KERNEL to GFP_ATOMIC since function in the spin_lock protect.
- Change hrtimer type from HRTIMER_MODE_ABS to HRTIMER_MODE_ABS_SOFT to avoid deadlock.

0002:
Fix and modify according to Vlid Buslov suggestions:
- Remove all rcu_read_lock protection since no rcu parameters.
- Enable the CONFIG_DEBUG_ATOMIC_SLEEP and CONFIG_PROVE_LOCKING checking, then check kzalloc sleeping flag.
- Change kzalloc to kcalloc for array memory alloc and change GFP_KERNEL flag to GFP_ATOMIC since function holding spin_lock protect.

0003:
- No changes.

0004:
- Commit comments rephrase act by Claudiu Manoil.

Changes from V3:
----------------
0001:

Fix and modify according to Vlid Buslov:
- Remove the struct gate_action and move the parameters to the struct tcf_gate align with tc_action parameters. This would not need to alloc rcu type memory with pointer.
- Remove the spin_lock type entry_lock which do not needed anymore, will use the tcf_lock system provided.
- Provide lockep protect for the status parameters in the tcf_gate_act().
- Remove the cycletime 0 input warning, return error directly.

And:
- Remove Qci related description in the Kconfig for gate action.

0002:
- Fix rcu_read_lock protect range suggested by Vlid Buslov.

0003:
- No changes.

0004:
- Fix bug of gate maxoct wildcard condition not included.
- Fix the pass time basetime calculation report by Vladimir Otlean.

Changes from V2:
0001: No changes.
0002: No changes.
0003: No changes.
0004: Fix the vlan id filter parameter and add reject src mac FF-FF-FF-FF-FF-FF filter in driver.

Changes from V1:
----------------
0000: Update description make it more clear
0001: Removed 'add update dropped stats' patch, will provide pull request as standalone patches.
0001: Update commit description make it more clear ack by Jiri Pirko. 0002: No changes
0003: Fix some code style ack by Jiri Pirko.
0004: Fix enetc_psfp_enable/disable parameter type ack by test robot

iprout2 command patches:
Not attach with these serial patches, will provide separate pull
request after kernel accept these patches.

Changes from RFC:
-----------------
0000: Reduce to 5 patches and remove the 4 max frame size offload and flow metering in the policing offload action, Only keep gate action offloading implementation.
0001: No changes.
0002:
- fix kfree lead ack by Jakub Kicinski and Cong Wang
- License fix from Jakub Kicinski and Stephen Hemminger
- Update example in commit acked by Vinicius Costa Gomes
- Fix the rcu protect in tcf_gate_act() acked by Vinicius

0003: No changes
0004: No changes
0005:
Acked by Vinicius Costa Gomes
- Use refcount kernel lib
- Update stream gate check code position
- Update reduce ref names more clear

iprout2 command patches:
0000: Update license expression and add gate id
0001: Add tc action gate man page

--------------------------------------------------------------------
These patches add stream gate action policing in IEEE802.1Qci (Per-Stream Filtering and Policing) software support and hardware offload support in tc flower, and implement the stream identify, stream filtering and stream gate filtering action in the NXP ENETC ethernet driver. Per-Stream Filtering and Policing (PSFP) specifies flow policing and filtering for ingress flows, and has three main parts:
1. The stream filter instance table consists of an ordered list of
stream filters that determine the filtering and policing actions that are to be applied to frames received on a specific stream. The main elements are stream gate id, flow metering id and maximum SDU size.
2. The stream gate function setup a gate list to control ingress traffic
class open/close state. When the gate is running at open state, the flow could pass but dropped when gate state is running to close. User setup a bastime to tell gate when start running the entry list, then the hardware would periodiclly. There is no compare qdisc action support.
3. Flow metering is two rates two buckets and three-color marker to
policing the frames. Flow metering instance are as specified in the algorithm in MEF10.3. The most likely qdisc action is policing action.

The first patch introduces an ingress frame flow control gate action, for the point 2. The tc gate action maintains the open/close state gate list, allowing flows to pass when the gate is open. Each gate action may policing one or more qdisc filters. When the start time arrived, The driver would repeat the gate list periodiclly. User can assign a passed time, the driver would calculate a new future time by the cycletime of the gate list.

The 0002 patch introduces the gate flow hardware offloading.

The 0003 patch adds support control the on/off for the tc flower offloading by ethtool.

The 0004 patch implement the stream identify and stream filtering and stream gate filtering action in the NXP ENETC ethernet driver. Tc filter command provide filtering keys with MAC address and VLAN id. These keys would be set to stream identify instance entry. Stream gate instance entry would refer the gate action parameters. Stream filter instance entry would refer the stream gate index and assign a stream handle value matches to the stream identify instance.

Po Liu (4):
net: qos: introduce a gate control flow action
net: schedule: add action gate offloading
net: enetc: add hw tc hw offload features for PSPF capability
net: enetc: add tc flower psfp offload driver

 drivers/net/ethernet/freescale/enetc/enetc.c  |   34 +-
 drivers/net/ethernet/freescale/enetc/enetc.h  |   86 ++
 .../net/ethernet/freescale/enetc/enetc_hw.h   |  159 +++
 .../net/ethernet/freescale/enetc/enetc_pf.c   |    6 +
 .../net/ethernet/freescale/enetc/enetc_qos.c  | 1098 +++++++++++++++++
 include/net/flow_offload.h                    |   10 +
 include/net/tc_act/tc_gate.h                  |  146 +++
 include/uapi/linux/pkt_cls.h                  |    1 +
 include/uapi/linux/tc_act/tc_gate.h           |   47 +
 net/sched/Kconfig                             |   12 +
 net/sched/Makefile                            |    1 +
 net/sched/act_gate.c                          |  636 ++++++++++
 net/sched/cls_api.c                           |   33 +
 13 files changed, 2268 insertions(+), 1 deletion(-)
 create mode 100644 include/net/tc_act/tc_gate.h
 create mode 100644 include/uapi/linux/tc_act/tc_gate.h
 create mode 100644 net/sched/act_gate.c
Signature · 1 line
2.17.1
author
#104 lore raw

PATCH v5 1/4 net: qos: introduce a gate control flow action

Introduce a ingress frame gate control flow action.
Tc gate action does the work like this:
Assume there is a gate allow specified ingress frames can be passed at specific time slot, and be dropped at specific time slot. Tc filter chooses the ingress frames, and tc gate action would specify what slot does these frames can be passed to device and what time slot would be dropped.
Tc gate action would provide an entry list to tell how much time gate keep open and how much time gate keep state close. Gate action also assign a start time to tell when the entry list start. Then driver would repeat the gate entry list cyclically.
For the software simulation, gate action requires the user assign a time clock type.

Below is the setting example in user space. Tc filter a stream source ip address is 192.168.0.20 and gate action own two time slots. One is last 200ms gate open let frame pass another is last 100ms gate close let frames dropped. When the ingress frames have reach total frames over 8000000 bytes, the excessive frames will be dropped in that 200000000ns time slot.

Quoted 3 lines

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 clockid CLOCK_TAI \
	   sched-entry open 200000000 -1 8000000 \
	   sched-entry close 100000000 -1 -1
Quoted 1 line

tc chain del dev eth0 ingress chain 0

"sched-entry" follow the name taprio style. Gate state is "open"/"close". Follow with period nanosecond. Then next item 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.
Base-time is not set will be 0 as default, as result start time would be ((N + 1) * cycletime) which is the minimal of future time.

Below example shows filtering a stream with destination mac address is 10:00:80:00:00:00 and ip type is ICMP, follow the action gate. The gate action would run with one close time slot which means always keep close. The time cycle is total 200000000ns. The base-time would calculate by:

1357000000000 + (N + 1) * cycletime

When the total value is the future time, it will be the start time. The cycletime here would be 200000000ns for this case.

Quoted 1 line

tc filter add dev eth0 parent ffff: protocol ip \

	   flower skip_hw ip_proto icmp dst_mac 10:00:80:00:00:00 \
	   action gate index 12 base-time 1357000000000 \
	   sched-entry close 200000000 -1 -1 \
	   clockid CLOCK_TAI
---
 include/net/tc_act/tc_gate.h        |  47 ++
 include/uapi/linux/pkt_cls.h        |   1 +
 include/uapi/linux/tc_act/tc_gate.h |  47 ++
 net/sched/Kconfig                   |  12 +
 net/sched/Makefile                  |   1 +
 net/sched/act_gate.c                | 636 ++++++++++++++++++++++++++++
 6 files changed, 744 insertions(+)
 create mode 100644 include/net/tc_act/tc_gate.h
 create mode 100644 include/uapi/linux/tc_act/tc_gate.h
 create mode 100644 net/sched/act_gate.c
include/net/tc_act/tc_gate.h new file +47 -0
new file mode 100644
index 000000000000..330ad8b02495
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright 2020 NXP */
+
+#ifndef __NET_TC_GATE_H
+#define __NET_TC_GATE_H
+
+#include <net/act_api.h>
+#include <linux/tc_act/tc_gate.h>
+
+struct tcfg_gate_entry {
+	int			index;
+	u8			gate_state;
+	u32			interval;
+	s32			ipv;
+	s32			maxoctets;
+	struct list_head	list;
+};
+
+struct tcf_gate_params {
+	s32			tcfg_priority;
+	u64			tcfg_basetime;
+	u64			tcfg_cycletime;
+	u64			tcfg_cycletime_ext;
+	u32			tcfg_flags;
+	s32			tcfg_clockid;
+	size_t			num_entries;
+	struct list_head	entries;
+};
+
+#define GATE_ACT_GATE_OPEN	BIT(0)
+#define GATE_ACT_PENDING	BIT(1)
+
+struct tcf_gate {
+	struct tc_action	common;
+	struct tcf_gate_params	param;
+	u8			current_gate_status;
+	ktime_t			current_close_time;
+	u32			current_entry_octets;
+	s32			current_max_octets;
+	struct tcfg_gate_entry	*next_entry;
+	struct hrtimer		hitimer;
+	enum tk_offsets		tk_offset;
+};
+
+#define to_gate(a) ((struct tcf_gate *)a)
+
+#endif
include/uapi/linux/pkt_cls.h +1 -0
index 9f06d29cab70..fc672b232437 100644
@@ -134,6 +134,7 @@ enum tca_id {
 	TCA_ID_CTINFO,
 	TCA_ID_MPLS,
 	TCA_ID_CT,
+	TCA_ID_GATE,
 	/* other actions go here */
 	__TCA_ID_MAX = 255
 };
include/uapi/linux/tc_act/tc_gate.h new file +47 -0

47 lines not on this page · raw message

net/sched/Kconfig +12 -0
index bfbefb7bff9d..2f20073f4f84 100644
@@ -981,6 +981,18 @@ config NET_ACT_CT
 	  To compile this code as a module, choose M here: the
 	  module will be called act_ct.
 
+config NET_ACT_GATE
+	tristate "Frame gate entry list control tc action"
+	depends on NET_CLS_ACT
+	help
+	  Say Y here to allow to control the ingress flow to be passed at
+	  specific time slot and be dropped at other specific time slot by
+	  the gate entry list.
+
+	  If unsure, say N.
+	  To compile this code as a module, choose M here: the
+	  module will be called act_gate.
+
 config NET_IFE_SKBMARK
 	tristate "Support to encoding decoding skb mark on IFE action"
 	depends on NET_ACT_IFE
net/sched/Makefile +1 -0
index 31c367a6cd09..66bbf9a98f9e 100644
@@ -30,6 +30,7 @@ obj-$(CONFIG_NET_IFE_SKBPRIO)	+= act_meta_skbprio.o
 obj-$(CONFIG_NET_IFE_SKBTCINDEX)	+= act_meta_skbtcindex.o
 obj-$(CONFIG_NET_ACT_TUNNEL_KEY)+= act_tunnel_key.o
 obj-$(CONFIG_NET_ACT_CT)	+= act_ct.o
+obj-$(CONFIG_NET_ACT_GATE)	+= act_gate.o
 obj-$(CONFIG_NET_SCH_FIFO)	+= sch_fifo.o
 obj-$(CONFIG_NET_SCH_CBQ)	+= sch_cbq.o
 obj-$(CONFIG_NET_SCH_HTB)	+= sch_htb.o
net/sched/act_gate.c new file +636 -0

636 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#105 lore raw

PATCH v5 2/4 net: schedule: add action gate offloading

In reply to Po Liu

Add the gate action to the flow action entry. Add the gate parameters to the tc_setup_flow_action() queueing to the entries of flow_action_entry array provide to the driver.

---
 include/net/flow_offload.h   | 10 ++++
 include/net/tc_act/tc_gate.h | 99 ++++++++++++++++++++++++++++++++++++
 net/sched/cls_api.c          | 33 ++++++++++++
 3 files changed, 142 insertions(+)
include/net/flow_offload.h +10 -0
index 3619c6acf60f..94a30fe02e6d 100644
@@ -147,6 +147,7 @@ enum flow_action_id {
 	FLOW_ACTION_MPLS_PUSH,
 	FLOW_ACTION_MPLS_POP,
 	FLOW_ACTION_MPLS_MANGLE,
+	FLOW_ACTION_GATE,
 	NUM_FLOW_ACTIONS,
 };
 
@@ -255,6 +256,15 @@ struct flow_action_entry {
 			u8		bos;
 			u8		ttl;
 		} mpls_mangle;
+		struct {
+			u32		index;
+			s32		prio;
+			u64		basetime;
+			u64		cycletime;
+			u64		cycletimeext;
+			u32		num_entries;
+			struct action_gate_entry *entries;
+		} gate;
 	};
 	struct flow_action_cookie *cookie; /* user defined action cookie */
 };
include/net/tc_act/tc_gate.h +99 -0

109 lines not on this page · raw message

net/sched/cls_api.c +33 -0
index 11b683c45c28..7e85c91d0752 100644
@@ -39,6 +39,7 @@
 #include <net/tc_act/tc_skbedit.h>
 #include <net/tc_act/tc_ct.h>
 #include <net/tc_act/tc_mpls.h>
+#include <net/tc_act/tc_gate.h>
 #include <net/flow_offload.h>
 
 extern const struct nla_policy rtm_tca_policy[TCA_MAX + 1];
@@ -3526,6 +3527,27 @@ static void tcf_sample_get_group(struct flow_action_entry *entry,
 #endif
 }
 
+static void tcf_gate_entry_destructor(void *priv)
+{
+	struct action_gate_entry *oe = priv;
+
+	kfree(oe);
+}
+
+static int tcf_gate_get_entries(struct flow_action_entry *entry,
+				const struct tc_action *act)
+{
+	entry->gate.entries = tcf_gate_get_list(act);
+
+	if (!entry->gate.entries)
+		return -EINVAL;
+
+	entry->destructor = tcf_gate_entry_destructor;
+	entry->destructor_priv = entry->gate.entries;
+
+	return 0;
+}
+
 int tc_setup_flow_action(struct flow_action *flow_action,
 			 const struct tcf_exts *exts)
 {
@@ -3672,6 +3694,17 @@ int tc_setup_flow_action(struct flow_action *flow_action,
 		} else if (is_tcf_skbedit_priority(act)) {
 			entry->id = FLOW_ACTION_PRIORITY;
 			entry->priority = tcf_skbedit_priority(act);
+		} else if (is_tcf_gate(act)) {
+			entry->id = FLOW_ACTION_GATE;
+			entry->gate.index = tcf_gate_index(act);
+			entry->gate.prio = tcf_gate_prio(act);
+			entry->gate.basetime = tcf_gate_basetime(act);
+			entry->gate.cycletime = tcf_gate_cycletime(act);
+			entry->gate.cycletimeext = tcf_gate_cycletimeext(act);
+			entry->gate.num_entries = tcf_gate_num_entries(act);
+			err = tcf_gate_get_entries(entry, act);
+			if (err)
+				goto err_out;
 		} else {
 			err = -EOPNOTSUPP;
 			goto err_out_locked;
Signature · 1 line
2.17.1
author
#106 lore raw

PATCH v5 3/4 net: enetc: add hw tc hw offload features for PSPF capability

In reply to Po Liu

This patch is to let ethtool enable/disable the tc flower offload features. Hardware ENETC has the feature of PSFP which is for per-stream policing. When enable the tc hw offloading feature, driver would enable the IEEE 802.1Qci feature. It is only set the register enable bit for this feature not enable for any entry of per stream filtering and stream gate or stream identify but get how much capabilities for each feature.

---
 drivers/net/ethernet/freescale/enetc/enetc.c  | 23 +++++++++
 drivers/net/ethernet/freescale/enetc/enetc.h  | 48 +++++++++++++++++++
 .../net/ethernet/freescale/enetc/enetc_hw.h   | 17 +++++++
 .../net/ethernet/freescale/enetc/enetc_pf.c   |  8 ++++
 4 files changed, 96 insertions(+)
drivers/net/ethernet/freescale/enetc/enetc.c +23 -0
index ccf2611f4a20..04aac7cbb506 100644
@@ -756,6 +756,9 @@ void enetc_get_si_caps(struct enetc_si *si)
 
 	if (val & ENETC_SIPCAPR0_QBV)
 		si->hw_features |= ENETC_SI_F_QBV;
+
+	if (val & ENETC_SIPCAPR0_PSFP)
+		si->hw_features |= ENETC_SI_F_PSFP;
 }
 
 static int enetc_dma_alloc_bdr(struct enetc_bdr *r, size_t bd_size)
@@ -1567,6 +1570,23 @@ static int enetc_set_rss(struct net_device *ndev, int en)
 	return 0;
 }
 
+static int enetc_set_psfp(struct net_device *ndev, int en)
+{
+	struct enetc_ndev_priv *priv = netdev_priv(ndev);
+
+	if (en) {
+		priv->active_offloads |= ENETC_F_QCI;
+		enetc_get_max_cap(priv);
+		enetc_psfp_enable(&priv->si->hw);
+	} else {
+		priv->active_offloads &= ~ENETC_F_QCI;
+		memset(&priv->psfp_cap, 0, sizeof(struct psfp_cap));
+		enetc_psfp_disable(&priv->si->hw);
+	}
+
+	return 0;
+}
+
 int enetc_set_features(struct net_device *ndev,
 		       netdev_features_t features)
 {
@@ -1575,6 +1595,9 @@ int enetc_set_features(struct net_device *ndev,
 	if (changed & NETIF_F_RXHASH)
 		enetc_set_rss(ndev, !!(features & NETIF_F_RXHASH));
 
+	if (changed & NETIF_F_HW_TC)
+		enetc_set_psfp(ndev, !!(features & NETIF_F_HW_TC));
+
 	return 0;
 }
 
drivers/net/ethernet/freescale/enetc/enetc.h +48 -0

81 lines not on this page · raw message

drivers/net/ethernet/freescale/enetc/enetc_hw.h +17 -0
index 2a6523136947..587974862f48 100644
@@ -19,6 +19,7 @@
 #define ENETC_SICTR1	0x1c
 #define ENETC_SIPCAPR0	0x20
 #define ENETC_SIPCAPR0_QBV	BIT(4)
+#define ENETC_SIPCAPR0_PSFP	BIT(9)
 #define ENETC_SIPCAPR0_RSS	BIT(8)
 #define ENETC_SIPCAPR1	0x24
 #define ENETC_SITGTGR	0x30
@@ -228,6 +229,15 @@ enum enetc_bdr_type {TX, RX};
 #define ENETC_PM0_IFM_RLP	(BIT(5) | BIT(11))
 #define ENETC_PM0_IFM_RGAUTO	(BIT(15) | ENETC_PMO_IFM_RG | BIT(1))
 #define ENETC_PM0_IFM_XGMII	BIT(12)
+#define ENETC_PSIDCAPR		0x1b08
+#define ENETC_PSIDCAPR_MSK	GENMASK(15, 0)
+#define ENETC_PSFCAPR		0x1b18
+#define ENETC_PSFCAPR_MSK	GENMASK(15, 0)
+#define ENETC_PSGCAPR		0x1b28
+#define ENETC_PSGCAPR_GCL_MSK	GENMASK(18, 16)
+#define ENETC_PSGCAPR_SGIT_MSK	GENMASK(15, 0)
+#define ENETC_PFMCAPR		0x1b38
+#define ENETC_PFMCAPR_MSK	GENMASK(15, 0)
 
 /* MAC counters */
 #define ENETC_PM0_REOCT		0x8100
@@ -621,3 +631,10 @@ struct enetc_cbd {
 /* Port time specific departure */
 #define ENETC_PTCTSDR(n)	(0x1210 + 4 * (n))
 #define ENETC_TSDE		BIT(31)
+
+/* PSFP setting */
+#define ENETC_PPSFPMR 0x11b00
+#define ENETC_PPSFPMR_PSFPEN BIT(0)
+#define ENETC_PPSFPMR_VS BIT(1)
+#define ENETC_PPSFPMR_PVC BIT(2)
+#define ENETC_PPSFPMR_PVZC BIT(3)
drivers/net/ethernet/freescale/enetc/enetc_pf.c +8 -0
index de1ad4975074..cef9fbfdb056 100644
@@ -727,6 +727,14 @@ static void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
 	if (si->hw_features & ENETC_SI_F_QBV)
 		priv->active_offloads |= ENETC_F_QBV;
 
+	if (si->hw_features & ENETC_SI_F_PSFP) {
+		priv->active_offloads |= ENETC_F_QCI;
+		ndev->features |= NETIF_F_HW_TC;
+		ndev->hw_features |= NETIF_F_HW_TC;
+		enetc_get_max_cap(priv);
+		enetc_psfp_enable(&si->hw);
+	}
+
 	/* pick up primary MAC address from SI */
 	enetc_get_primary_mac_addr(&si->hw, ndev->dev_addr);
 }
Signature · 1 line
2.17.1
author
#107 lore raw

PATCH v5 4/4 net: enetc: add tc flower psfp offload driver

In reply to Po Liu

This patch is to add tc flower offload for the enetc IEEE 802.1Qci(PSFP) function. There are four main feature parts to implement the flow policing and filtering for ingress flow with IEEE 802.1Qci features. They are stream identify(this is defined in the P802.1cb exactly but needed for 802.1Qci), stream filtering, stream gate and flow metering. Each function block includes many entries by index to assign parameters. So for one frame would be filtered by stream identify first, then flow into stream filter block by the same handle between stream identify and stream filtering. Then flow into stream gate control which assigned by the stream filtering entry. And then policing by the gate and limited by the max sdu in the filter block(optional). At last, policing by the flow metering block, index choosing at the fitering block. So you can see that each entry of block may link to many upper entries since they can be assigned same index means more streams want to share the same feature in the stream filtering or stream gate or flow metering.
To implement such features, each stream filtered by source/destination mac address, some stream maybe also plus the vlan id value would be treated as one flow chain. This would be identified by the chain_index which already in the tc filter concept. Driver would maintain this chain and also with gate modules. The stream filter entry create by the gate index and flow meter(optional) entry id and also one priority value. Offloading only transfer the gate action and flow filtering parameters. Driver would create (or search same gate id and flow meter id and
priority) one stream filter entry to set to the hardware. So stream
filtering do not need transfer by the action offloading. This architecture is same with tc filter and actions relationship. tc filter maintain the list for each flow feature by keys. And actions maintain by the action list.

Below showing a example commands by tc:

Quoted 3 lines

tc qdisc add dev eth0 ingress
ip link set eth0 address 10:00:80:00:00:00
tc filter add dev eth0 parent ffff: protocol ip chain 11 \

	flower skip_sw dst_mac 10:00:80:00:00:00 \
	action gate index 10 \
	sched-entry open 200000000 1 8000000 \
	sched-entry close 100000000 -1 -1

Command means to set the dst_mac 10:00:80:00:00:00 to index 11 of stream identify module. Then setting the gate index 10 of stream gate module. Keep the gate open for 200ms and limit the traffic volume to 8MB in this sched-entry. Then direct the frames to the ingress queue 1.

---
 drivers/net/ethernet/freescale/enetc/enetc.c  |   25 +-
 drivers/net/ethernet/freescale/enetc/enetc.h  |   46 +-
 .../net/ethernet/freescale/enetc/enetc_hw.h   |  142 +++
 .../net/ethernet/freescale/enetc/enetc_pf.c   |    4 +-
 .../net/ethernet/freescale/enetc/enetc_qos.c  | 1098 +++++++++++++++++
 5 files changed, 1300 insertions(+), 15 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc.c +17 -8
index 04aac7cbb506..298c55786fd9 100644
@@ -1521,6 +1521,8 @@ int enetc_setup_tc(struct net_device *ndev, enum tc_setup_type type,
 		return enetc_setup_tc_cbs(ndev, type_data);
 	case TC_SETUP_QDISC_ETF:
 		return enetc_setup_tc_txtime(ndev, type_data);
+	case TC_SETUP_BLOCK:
+		return enetc_setup_tc_psfp(ndev, type_data);
 	default:
 		return -EOPNOTSUPP;
 	}
@@ -1573,17 +1575,23 @@ static int enetc_set_rss(struct net_device *ndev, int en)
 static int enetc_set_psfp(struct net_device *ndev, int en)
 {
 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
+	int err;
 
 	if (en) {
+		err = enetc_psfp_enable(priv);
+		if (err)
+			return err;
+
 		priv->active_offloads |= ENETC_F_QCI;
-		enetc_get_max_cap(priv);
-		enetc_psfp_enable(&priv->si->hw);
-	} else {
-		priv->active_offloads &= ~ENETC_F_QCI;
-		memset(&priv->psfp_cap, 0, sizeof(struct psfp_cap));
-		enetc_psfp_disable(&priv->si->hw);
+		return 0;
 	}
 
+	err = enetc_psfp_disable(priv);
+	if (err)
+		return err;
+
+	priv->active_offloads &= ~ENETC_F_QCI;
+
 	return 0;
 }
 
@@ -1591,14 +1599,15 @@ int enetc_set_features(struct net_device *ndev,
 		       netdev_features_t features)
 {
 	netdev_features_t changed = ndev->features ^ features;
+	int err = 0;
 
 	if (changed & NETIF_F_RXHASH)
 		enetc_set_rss(ndev, !!(features & NETIF_F_RXHASH));
 
 	if (changed & NETIF_F_HW_TC)
-		enetc_set_psfp(ndev, !!(features & NETIF_F_HW_TC));
+		err = enetc_set_psfp(ndev, !!(features & NETIF_F_HW_TC));
 
-	return 0;
+	return err;
 }
 
 #ifdef CONFIG_FSL_ENETC_PTP_CLOCK
drivers/net/ethernet/freescale/enetc/enetc.h +42 -4

75 lines not on this page · raw message

drivers/net/ethernet/freescale/enetc/enetc_hw.h +142 -0

161 lines not on this page · raw message

drivers/net/ethernet/freescale/enetc/enetc_pf.c +1 -3
index cef9fbfdb056..824d211ec00f 100644
@@ -727,12 +727,10 @@ static void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
 	if (si->hw_features & ENETC_SI_F_QBV)
 		priv->active_offloads |= ENETC_F_QBV;
 
-	if (si->hw_features & ENETC_SI_F_PSFP) {
+	if (si->hw_features & ENETC_SI_F_PSFP && !enetc_psfp_enable(priv)) {
 		priv->active_offloads |= ENETC_F_QCI;
 		ndev->features |= NETIF_F_HW_TC;
 		ndev->hw_features |= NETIF_F_HW_TC;
-		enetc_get_max_cap(priv);
-		enetc_psfp_enable(&si->hw);
 	}
 
 	/* pick up primary MAC address from SI */
drivers/net/ethernet/freescale/enetc/enetc_qos.c +1098 -0

1,107 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#108 lore raw

PATCH v3 1/2 iproute2:tc:action: add a gate control action

Introduce a ingress frame gate control flow action.
Tc gate action does the work like this:
Assume there is a gate allow specified ingress frames can pass at specific time slot, and also drop at specific time slot. Tc filter chooses the ingress frames, and tc gate action would specify what slot does these frames can be passed to device and what time slot would be dropped.
Tc gate action would provide an entry list to tell how much time gate keep open and how much time gate keep state close. Gate action also assign a start time to tell when the entry list start. Then driver would repeat the gate entry list cyclically.
For the software simulation, gate action require the user assign a time clock type.

Below is the setting example in user space. Tc filter a stream source ip address is 192.168.0.20 and gate action own two time slots. One is last 200ms gate open let frame pass another is last 100ms gate close let frames dropped.

 # 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 clockid CLOCK_TAI \
            sched-entry open 200000000 -1 -1 \
            sched-entry close 100000000
 # 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 to. "-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.

Below example shows filtering a stream with destination mac address is 10:00:80:00:00:00 and ip type is ICMP, follow the action gate. The gate action would run with one close time slot which means always keep close. The time cycle is total 200000000ns. The base-time would calculate by:

     1357000000000 + (N + 1) * cycletime

When the total value is the future time, it will be the start time. The cycletime here would be 200000000ns for this case.

#tc filter add dev eth0 parent ffff: protocol ip \

           flower skip_hw ip_proto icmp dst_mac 10:00:80:00:00:00 \
           action gate index 12 base-time 1357000000000 \
           sched-entry CLOSE 200000000 \
           clockid CLOCK_TAI

---
These patches continue request for support iprout2 tc command input gate action since kernel patch applied (a51c328df310 net: qos: introduce a gate control flow action).
Continue the version 3.
Changes from v2:
Fix flexible input for a time slot - sched-entry suggested by Vladimir Oltean and Vinicius Gomes:
- ipv and maxoctets in a sched-entry can be ignore input default to be wildcard(values are -1).

 include/uapi/linux/pkt_cls.h        |   1 +
 include/uapi/linux/tc_act/tc_gate.h |  47 +++
 tc/Makefile                         |   1 +
 tc/m_gate.c                         | 533 ++++++++++++++++++++++++++++
 4 files changed, 582 insertions(+)
 create mode 100644 include/uapi/linux/tc_act/tc_gate.h
 create mode 100644 tc/m_gate.c
include/uapi/linux/pkt_cls.h +1 -0
index 9f06d29c..fc672b23 100644
@@ -134,6 +134,7 @@ enum tca_id {
 	TCA_ID_CTINFO,
 	TCA_ID_MPLS,
 	TCA_ID_CT,
+	TCA_ID_GATE,
 	/* other actions go here */
 	__TCA_ID_MAX = 255
 };
include/uapi/linux/tc_act/tc_gate.h new file +47 -0

47 lines not on this page · raw message

tc/Makefile +1 -0
index e31cbc12..79c9c1dd 100644
@@ -54,6 +54,7 @@ TCMODULES += m_bpf.o
 TCMODULES += m_tunnel_key.o
 TCMODULES += m_sample.o
 TCMODULES += m_ct.o
+TCMODULES += m_gate.o
 TCMODULES += p_ip.o
 TCMODULES += p_ip6.o
 TCMODULES += p_icmp.o
tc/m_gate.c new file +533 -0

533 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#109 lore raw

PATCH v3 2/2 iproute2: add gate action man page

This patch is to add the man page for the tc gate action.

---
 man/man8/tc-gate.8 | 123 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 123 insertions(+)
 create mode 100644 man/man8/tc-gate.8
man/man8/tc-gate.8 new file +123 -0
new file mode 100644
index 00000000..0f48d7f3
@@ -0,0 +1,123 @@
+.TH GATE 8 "12 Mar 2020" "iproute2" "Linux"
+.SH NAME
+gate \- Stream Gate Action
+.SH SYNOPSIS
+.B tc " ... " action gate
+.ti +8
+.B [ base-time
+BASETIME ]
+.B [ clockid
+CLOCKID ]
+.ti +8
+.B sched-entry
+<gate state> <interval 1> [ <internal priority> <max octets> ]
+.ti +8
+.B sched-entry
+<gate state> <interval 2> [ <internal priority> <max octets> ]
+.ti +8
+.B sched-entry
+<gate state> <interval 3> [ <internal priority> <max octets> ]
+.ti +8
+.B ......
+.ti +8
+.B sched-entry
+<gate state> <interval N> [ <internal priority> <max octets> ]
+
+.SH DESCRIPTION
+GATE action allows specified ingress frames can be passed at
+specific time slot, or be dropped at specific time slot. Tc filter
+filters the ingress frames, then tc gate action would specify which time
+slot and how many bytes these frames can be passed to device and
+which time slot frames would be dropped.
+Gate action also assign a base-time to tell when the entry list start.
+Then gate action would start to repeat the gate entry list cyclically
+at the start base-time.
+For the software simulation, gate action requires the user assign reference
+time clock type.
+
+.SH PARAMETERS
+
+.TP
+base-time
+.br
+Specifies the instant in nanoseconds, defining the time when the schedule
+starts. If 'base-time' is a time in the past, the schedule will start at
+
+base-time + (N * cycle-time)
+
+where N is the smallest integer so the resulting time is greater than
+"now", and "cycle-time" is the sum of all the intervals of the entries
+in the schedule. Without base-time specified, will default to be 0.
+
+.TP
+clockid
+.br
+Specifies the clock to be used by qdisc's internal timer for measuring
+time and scheduling events. Not valid if gate action is used for offloading
+filter.
+For example, tc filter command with
+.B skip_sw
+parameter.
+
+.TP
+sched-entry
+.br
+There may multiple
+.B sched-entry
+parameters in a single schedule. Each one has the format:
+
+sched-entry <gate state> <interval> [ <internal priority> <max octets> ]
+
+.br
+<gate state> means gate states. 'open' keep gate open, 'close' keep gate close.
+.br
+<interval> means how much nano seconds for this time slot.
+.br
+<internal priority> means internal priority value. Present of the
+internal receiving queue for this stream. "-1" means wildcard.
+<internal priority> and <max octets> can be omit default to be "-1" which both
+ value to be "-1" for this <sched-entry>.
+.br
+<max octets> means how many octets size for this time slot. Dropped
+if overlimited. "-1" means wildcard. <max octets> can be omit default to be
+"-1" which value to be "-1" for this <sched-entry>.
+.br
+Note that <internal priority> and <max octets> are nothing meaning for gate state
+is "close" in a "sched-entry". All frames are dropped when "sched-entry" with
+"close" state.
+
+.SH EXAMPLES
+
+The following example shows tc filter frames source ip match to the
+192.168.0.20 will keep the gate open for 200ms and limit the traffic to 8MB
+in this sched-entry. Then keep the traffic gate to be close for 100ms.
+Frames arrived at gate close state would be dropped. Then the cycle would
+run the gate entries periodically. The schedule will start at instant 200.0s
+using the reference CLOCK_TAI. The schedule is composed of two entries
+each of 300ms duration.
+
+.EX
+# tc qdisc add dev eth0 ingress
+# tc filter add dev eth0 parent ffff: protocol ip \\
+           flower skip_hw src_ip 192.168.0.20 \\
+           action gate index 2 clockid CLOCK_TAI \\
+           base-time 200000000000 \\
+           sched-entry open 200000000 -1 8000000 \\
+           sched-entry close 100000000
+
+.EE
+
+Following commands is an example to filter a stream source mac match to the
+10:00:80:00:00:00 icmp frames will be dropped at any time with cycle 200ms.
+With a default basetime 0 and clockid is CLOCK_TAI as default.
+
+.EX
+# tc qdisc add dev eth0 ingress
+# tc filter add dev eth0 parent ffff:  protocol ip \\
+	flower ip_proto icmp dst_mac 10:00:80:00:00:00 \\
+	action gate index 12 sched-entry close 200000000
+
+.EE
+
+.SH AUTHORS
+Po Liu <[email protected]>
Signature · 1 line
2.17.1
author
#110 lore raw

PATCH v4 1/2 iproute2-next:tc:action: add a gate control action

Introduce a ingress frame gate control flow action.
Tc gate action does the work like this:
Assume there is a gate allow specified ingress frames can pass at specific time slot, and also drop at specific time slot. Tc filter chooses the ingress frames, and tc gate action would specify what slot does these frames can be passed to device and what time slot would be dropped.
Tc gate action would provide an entry list to tell how much time gate keep open and how much time gate keep state close. Gate action also assign a start time to tell when the entry list start. Then driver would repeat the gate entry list cyclically.
For the software simulation, gate action require the user assign a time clock type.

Below is the setting example in user space. Tc filter a stream source ip address is 192.168.0.20 and gate action own two time slots. One is last 200ms gate open let frame pass another is last 100ms gate close let frames dropped.

 # 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 clockid CLOCK_TAI \
            sched-entry open 200000000 -1 -1 \
            sched-entry close 100000000
 # 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 to. "-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.

Below example shows filtering a stream with destination mac address is 10:00:80:00:00:00 and ip type is ICMP, follow the action gate. The gate action would run with one close time slot which means always keep close. The time cycle is total 200000000ns. The base-time would calculate by:

     1357000000000 + (N + 1) * cycletime

When the total value is the future time, it will be the start time. The cycletime here would be 200000000ns for this case.

#tc filter add dev eth0 parent ffff: protocol ip \

           flower skip_hw ip_proto icmp dst_mac 10:00:80:00:00:00 \
           action gate index 12 base-time 1357000000000 \
           sched-entry CLOSE 200000000 \
           clockid CLOCK_TAI

---
These patches continue request for support iprout2 tc command input gate action since kernel patch applied (a51c328df310 net: qos: introduce a gate control flow action).
Continue the version 3.

Changes from v2:
Fix flexible input for a time slot - sched-entry suggested by Vladimir Oltean and Vinicius Gomes:
- ipv and maxoctets in a sched-entry can be ignore input default to be wildcard(values are -1).

Changes from v3:
- Fix json 'gate state' output update json format output: add array for 'sched-entry'
- Update input for 'sched-entry' parameters absense conditions

 include/uapi/linux/pkt_cls.h        |   1 +
 include/uapi/linux/tc_act/tc_gate.h |  47 +++
 tc/Makefile                         |   1 +
 tc/m_gate.c                         | 556 ++++++++++++++++++++++++++++
 4 files changed, 605 insertions(+)
 create mode 100644 include/uapi/linux/tc_act/tc_gate.h
 create mode 100644 tc/m_gate.c
include/uapi/linux/pkt_cls.h +1 -0
index 9f06d29c..fc672b23 100644
@@ -134,6 +134,7 @@ enum tca_id {
 	TCA_ID_CTINFO,
 	TCA_ID_MPLS,
 	TCA_ID_CT,
+	TCA_ID_GATE,
 	/* other actions go here */
 	__TCA_ID_MAX = 255
 };
include/uapi/linux/tc_act/tc_gate.h new file +47 -0

47 lines not on this page · raw message

tc/Makefile +1 -0
index e31cbc12..79c9c1dd 100644
@@ -54,6 +54,7 @@ TCMODULES += m_bpf.o
 TCMODULES += m_tunnel_key.o
 TCMODULES += m_sample.o
 TCMODULES += m_ct.o
+TCMODULES += m_gate.o
 TCMODULES += p_ip.o
 TCMODULES += p_ip6.o
 TCMODULES += p_icmp.o
tc/m_gate.c new file +556 -0

556 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#111 lore raw

PATCH v4 2/2 iproute2-next: add gate action man page

This patch is to add the man page for the tc gate action.

---
 man/man8/tc-gate.8 | 123 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 123 insertions(+)
 create mode 100644 man/man8/tc-gate.8
man/man8/tc-gate.8 new file +123 -0
new file mode 100644
index 00000000..0f48d7f3
@@ -0,0 +1,123 @@
+.TH GATE 8 "12 Mar 2020" "iproute2" "Linux"
+.SH NAME
+gate \- Stream Gate Action
+.SH SYNOPSIS
+.B tc " ... " action gate
+.ti +8
+.B [ base-time
+BASETIME ]
+.B [ clockid
+CLOCKID ]
+.ti +8
+.B sched-entry
+<gate state> <interval 1> [ <internal priority> <max octets> ]
+.ti +8
+.B sched-entry
+<gate state> <interval 2> [ <internal priority> <max octets> ]
+.ti +8
+.B sched-entry
+<gate state> <interval 3> [ <internal priority> <max octets> ]
+.ti +8
+.B ......
+.ti +8
+.B sched-entry
+<gate state> <interval N> [ <internal priority> <max octets> ]
+
+.SH DESCRIPTION
+GATE action allows specified ingress frames can be passed at
+specific time slot, or be dropped at specific time slot. Tc filter
+filters the ingress frames, then tc gate action would specify which time
+slot and how many bytes these frames can be passed to device and
+which time slot frames would be dropped.
+Gate action also assign a base-time to tell when the entry list start.
+Then gate action would start to repeat the gate entry list cyclically
+at the start base-time.
+For the software simulation, gate action requires the user assign reference
+time clock type.
+
+.SH PARAMETERS
+
+.TP
+base-time
+.br
+Specifies the instant in nanoseconds, defining the time when the schedule
+starts. If 'base-time' is a time in the past, the schedule will start at
+
+base-time + (N * cycle-time)
+
+where N is the smallest integer so the resulting time is greater than
+"now", and "cycle-time" is the sum of all the intervals of the entries
+in the schedule. Without base-time specified, will default to be 0.
+
+.TP
+clockid
+.br
+Specifies the clock to be used by qdisc's internal timer for measuring
+time and scheduling events. Not valid if gate action is used for offloading
+filter.
+For example, tc filter command with
+.B skip_sw
+parameter.
+
+.TP
+sched-entry
+.br
+There may multiple
+.B sched-entry
+parameters in a single schedule. Each one has the format:
+
+sched-entry <gate state> <interval> [ <internal priority> <max octets> ]
+
+.br
+<gate state> means gate states. 'open' keep gate open, 'close' keep gate close.
+.br
+<interval> means how much nano seconds for this time slot.
+.br
+<internal priority> means internal priority value. Present of the
+internal receiving queue for this stream. "-1" means wildcard.
+<internal priority> and <max octets> can be omit default to be "-1" which both
+ value to be "-1" for this <sched-entry>.
+.br
+<max octets> means how many octets size for this time slot. Dropped
+if overlimited. "-1" means wildcard. <max octets> can be omit default to be
+"-1" which value to be "-1" for this <sched-entry>.
+.br
+Note that <internal priority> and <max octets> are nothing meaning for gate state
+is "close" in a "sched-entry". All frames are dropped when "sched-entry" with
+"close" state.
+
+.SH EXAMPLES
+
+The following example shows tc filter frames source ip match to the
+192.168.0.20 will keep the gate open for 200ms and limit the traffic to 8MB
+in this sched-entry. Then keep the traffic gate to be close for 100ms.
+Frames arrived at gate close state would be dropped. Then the cycle would
+run the gate entries periodically. The schedule will start at instant 200.0s
+using the reference CLOCK_TAI. The schedule is composed of two entries
+each of 300ms duration.
+
+.EX
+# tc qdisc add dev eth0 ingress
+# tc filter add dev eth0 parent ffff: protocol ip \\
+           flower skip_hw src_ip 192.168.0.20 \\
+           action gate index 2 clockid CLOCK_TAI \\
+           base-time 200000000000 \\
+           sched-entry open 200000000 -1 8000000 \\
+           sched-entry close 100000000
+
+.EE
+
+Following commands is an example to filter a stream source mac match to the
+10:00:80:00:00:00 icmp frames will be dropped at any time with cycle 200ms.
+With a default basetime 0 and clockid is CLOCK_TAI as default.
+
+.EX
+# tc qdisc add dev eth0 ingress
+# tc filter add dev eth0 parent ffff:  protocol ip \\
+	flower ip_proto icmp dst_mac 10:00:80:00:00:00 \\
+	action gate index 12 sched-entry close 200000000
+
+.EE
+
+.SH AUTHORS
+Po Liu <[email protected]>
Signature · 1 line
2.17.1
author
#112 lore raw

PATCH v5 1/2 iproute2-next:tc:action: add a gate control action

Introduce a ingress frame gate control flow action.
Tc gate action does the work like this:
Assume there is a gate allow specified ingress frames can pass at specific time slot, and also drop at specific time slot. Tc filter chooses the ingress frames, and tc gate action would specify what slot does these frames can be passed to device and what time slot would be dropped.
Tc gate action would provide an entry list to tell how much time gate keep open and how much time gate keep state close. Gate action also assign a start time to tell when the entry list start. Then driver would repeat the gate entry list cyclically.
For the software simulation, gate action require the user assign a time clock type.

Below is the setting example in user space. Tc filter a stream source ip address is 192.168.0.20 and gate action own two time slots. One is last 200ms gate open let frame pass another is last 100ms gate close let frames dropped.

 # 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 clockid CLOCK_TAI \
            sched-entry open 200000000ns -1 8000000b \
            sched-entry close 100000000ns
 # 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 to. "-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, the overlimit frames would be dropped.

Below example shows filtering a stream with destination mac address is 10:00:80:00:00:00 and ip type is ICMP, follow the action gate. The gate action would run with one close time slot which means always keep close. The time cycle is total 200000000ns. The base-time would calculate by:

     1357000000000 + (N + 1) * cycletime

When the total value is the future time, it will be the start time. The cycletime here would be 200000000ns for this case.

#tc filter add dev eth0 parent ffff: protocol ip \

           flower skip_hw ip_proto icmp dst_mac 10:00:80:00:00:00 \
           action gate index 12 base-time 1357000000000ns \
           sched-entry CLOSE 200000000ns \
           clockid CLOCK_TAI

---
These patches continue request for support iprout2 tc command input gate action since kernel patch applied (a51c328df310 net: qos: introduce a gate control flow action).
Continue the version 3.

Changes from v2:
Fix flexible input for a time slot - sched-entry suggested by Vladimir Oltean and Vinicius Gomes:
- ipv and maxoctets in a sched-entry can be ignore input default to be wildcard(values are -1).

Changes from v3:
- Fix json 'gate state' output update json format output: add array for 'sched-entry'
- Update input for 'sched-entry' parameters absense conditions

Changes from v4:
- Add support unified tc command time and size routine suggested by 'Stephen Hemminger':
input 'base-time' 'cycle-time' could input as '100ns' '200.0ms' and also support the default decimal number input as how many nano-seconds. input 'maxoctets' support as tc command size routine and also support the default decimal number input as how many byte.

- Update the commit example with input/output time and size routine

- Fix duplicate parse_action_control* action control suggested by 'Davide Caratti'

---------------------------------------------------------------

 include/uapi/linux/pkt_cls.h        |   1 +
 include/uapi/linux/tc_act/tc_gate.h |  47 +++
 tc/Makefile                         |   1 +
 tc/m_gate.c                         | 580 ++++++++++++++++++++++++++++
 4 files changed, 629 insertions(+)
 create mode 100644 include/uapi/linux/tc_act/tc_gate.h
 create mode 100644 tc/m_gate.c
include/uapi/linux/pkt_cls.h +1 -0
index 9f06d29c..fc672b23 100644
@@ -134,6 +134,7 @@ enum tca_id {
 	TCA_ID_CTINFO,
 	TCA_ID_MPLS,
 	TCA_ID_CT,
+	TCA_ID_GATE,
 	/* other actions go here */
 	__TCA_ID_MAX = 255
 };
include/uapi/linux/tc_act/tc_gate.h new file +47 -0

47 lines not on this page · raw message

tc/Makefile +1 -0
index e31cbc12..79c9c1dd 100644
@@ -54,6 +54,7 @@ TCMODULES += m_bpf.o
 TCMODULES += m_tunnel_key.o
 TCMODULES += m_sample.o
 TCMODULES += m_ct.o
+TCMODULES += m_gate.o
 TCMODULES += p_ip.o
 TCMODULES += p_ip6.o
 TCMODULES += p_icmp.o
tc/m_gate.c new file +580 -0

580 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#113 lore raw

PATCH v5 2/2 iproute2-next: add gate action man page

This patch is to add the man page for the tc gate action.

---
changes before v4:
No changes.

changes from v4:
- Update the examples with input/output time and size routine support

 man/man8/tc-gate.8 | 123 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 123 insertions(+)
 create mode 100644 man/man8/tc-gate.8
man/man8/tc-gate.8 new file +123 -0
new file mode 100644
index 00000000..23d93ca4
@@ -0,0 +1,123 @@
+.TH GATE 8 "12 Mar 2020" "iproute2" "Linux"
+.SH NAME
+gate \- Stream Gate Action
+.SH SYNOPSIS
+.B tc " ... " action gate
+.ti +8
+.B [ base-time
+BASETIME ]
+.B [ clockid
+CLOCKID ]
+.ti +8
+.B sched-entry
+<gate state> <interval 1> [ <internal priority> <max octets> ]
+.ti +8
+.B sched-entry
+<gate state> <interval 2> [ <internal priority> <max octets> ]
+.ti +8
+.B sched-entry
+<gate state> <interval 3> [ <internal priority> <max octets> ]
+.ti +8
+.B ......
+.ti +8
+.B sched-entry
+<gate state> <interval N> [ <internal priority> <max octets> ]
+
+.SH DESCRIPTION
+GATE action allows specified ingress frames can be passed at
+specific time slot, or be dropped at specific time slot. Tc filter
+filters the ingress frames, then tc gate action would specify which time
+slot and how many bytes these frames can be passed to device and
+which time slot frames would be dropped.
+Gate action also assign a base-time to tell when the entry list start.
+Then gate action would start to repeat the gate entry list cyclically
+at the start base-time.
+For the software simulation, gate action requires the user assign reference
+time clock type.
+
+.SH PARAMETERS
+
+.TP
+base-time
+.br
+Specifies the instant in nanoseconds, defining the time when the schedule
+starts. If 'base-time' is a time in the past, the schedule will start at
+
+base-time + (N * cycle-time)
+
+where N is the smallest integer so the resulting time is greater than
+"now", and "cycle-time" is the sum of all the intervals of the entries
+in the schedule. Without base-time specified, will default to be 0.
+
+.TP
+clockid
+.br
+Specifies the clock to be used by qdisc's internal timer for measuring
+time and scheduling events. Not valid if gate action is used for offloading
+filter.
+For example, tc filter command with
+.B skip_sw
+parameter.
+
+.TP
+sched-entry
+.br
+There may multiple
+.B sched-entry
+parameters in a single schedule. Each one has the format:
+
+sched-entry <gate state> <interval> [ <internal priority> <max octets> ]
+
+.br
+<gate state> means gate states. 'open' keep gate open, 'close' keep gate close.
+.br
+<interval> means how much nano seconds for this time slot.
+.br
+<internal priority> means internal priority value. Present of the
+internal receiving queue for this stream. "-1" means wildcard.
+<internal priority> and <max octets> can be omit default to be "-1" which both
+ value to be "-1" for this <sched-entry>.
+.br
+<max octets> means how many octets size could pass in this time slot. Dropped
+if overlimited. "-1" means wildcard. <max octets> can be omit default to be
+"-1" which value to be "-1" for this <sched-entry>.
+.br
+Note that <internal priority> and <max octets> are nothing meaning for gate state
+is "close" in a "sched-entry". All frames are dropped when "sched-entry" with
+"close" state.
+
+.SH EXAMPLES
+
+The following example shows tc filter frames source ip match to the
+192.168.0.20 will keep the gate open for 200ms and limit the traffic to 8MB
+in this sched-entry. Then keep the traffic gate to be close for 100ms.
+Frames arrived at gate close state would be dropped. Then the cycle would
+run the gate entries periodically. The schedule will start at instant 200.0s
+using the reference CLOCK_TAI. The schedule is composed of two entries
+each of 300ms duration.
+
+.EX
+# tc qdisc add dev eth0 ingress
+# tc filter add dev eth0 parent ffff: protocol ip \\
+           flower skip_hw src_ip 192.168.0.20 \\
+           action gate index 2 clockid CLOCK_TAI \\
+           base-time 200000000000ns \\
+           sched-entry open 200000000ns -1 8000000b \\
+           sched-entry close 100000000ns
+
+.EE
+
+Following commands is an example to filter a stream source mac match to the
+10:00:80:00:00:00 icmp frames will be dropped at any time with cycle 200ms.
+With a default basetime 0 and clockid is CLOCK_TAI as default.
+
+.EX
+# tc qdisc add dev eth0 ingress
+# tc filter add dev eth0 parent ffff:  protocol ip \\
+	flower ip_proto icmp dst_mac 10:00:80:00:00:00 \\
+	action gate index 12 sched-entry close 200000000ns
+
+.EE
+
+.SH AUTHORS
+Po Liu <[email protected]>
Signature · 1 line
2.17.1
Applied
#114 lore raw

Re: [v5,iproute2-next 1/2] iproute2-next:tc:action: add a gate control action

In reply to Po Liu
Quoted 46 lines · Po Liu

Introduce a ingress frame gate control flow action.
Tc gate action does the work like this:
Assume there is a gate allow specified ingress frames can pass at specific time slot, and also drop at specific time slot. Tc filter chooses the ingress frames, and tc gate action would specify what slot does these frames can be passed to device and what time slot would be dropped.
Tc gate action would provide an entry list to tell how much time gate keep open and how much time gate keep state close. Gate action also assign a start time to tell when the entry list start. Then driver would repeat the gate entry list cyclically.
For the software simulation, gate action require the user assign a time clock type.

Below is the setting example in user space. Tc filter a stream source ip address is 192.168.0.20 and gate action own two time slots. One is last 200ms gate open let frame pass another is last 100ms gate close let frames dropped.

 # 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 clockid CLOCK_TAI \
            sched-entry open 200000000ns -1 8000000b \
            sched-entry close 100000000ns
 # 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 to. "-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, the overlimit frames would be dropped.

Below example shows filtering a stream with destination mac address is 10:00:80:00:00:00 and ip type is ICMP, follow the action gate. The gate action would run with one close time slot which means always keep close. The time cycle is total 200000000ns. The base-time would calculate by:

     1357000000000 + (N + 1) * cycletime

When the total value is the future time, it will be the start time. The cycletime here would be 200000000ns for this case.

Quoted 9 lines

#tc filter add dev eth0 parent ffff: protocol ip \

           flower skip_hw ip_proto icmp dst_mac 10:00:80:00:00:00 \
           action gate index 12 base-time 1357000000000ns \
           sched-entry CLOSE 200000000ns \
           clockid CLOCK_TAI

---

applied to iproute2-next. Thanks,

#115 lore raw

Re: [v4,iproute2-next 1/2] iproute2-next:tc:action: add a gate control action

In reply to Po Liu
Quoted 1 line · Po Liu

Introduce a ingress frame gate control flow action.

[...]

hello Po Liu,

[...]

Quoted 27 lines
tc/m_gate.c new file +27 -0
+create_entry:
+			e = create_gate_entry(gate_state, interval,
+					      ipv, maxoctets);
+			if (!e) {
+				fprintf(stderr, "gate: not enough memory\n");
+				free_entries(&gate_entries);
+				return -1;
+			}
+
+			list_add_tail(&e->list, &gate_entries);
+			entry_num++;
+
+		} else if (matches(*argv, "reclassify") == 0 ||
+			   matches(*argv, "drop") == 0 ||
+			   matches(*argv, "shot") == 0 ||
+			   matches(*argv, "continue") == 0 ||
+			   matches(*argv, "pass") == 0 ||
+			   matches(*argv, "ok") == 0 ||
+			   matches(*argv, "pipe") == 0 ||
+			   matches(*argv, "goto") == 0) {
+			if (parse_action_control(&argc, &argv,
+						 &parm.action, false)) {
+				free_entries(&gate_entries);
+				return -1;
+			}
+		} else if (matches(*argv, "help") == 0) {
+			usage();

tc/m_gate.c line 349

Quoted 10 lines
tc/m_gate.c new file +10 -0
+		} else {
+			break;
+		}
+
+		argc--;
+		argv++;
+	}
+
+	parse_action_control_dflt(&argc, &argv, &parm.action,
+				  false, TC_ACT_PIPE);

it seems that the control action is parsed twice, and the first time it does not allow "jump" and "trap". Is that intentional? IOW, are there some "act_gate" configurations that don't allow jump or trap?

I don't see anything similar in kernel act_gate.c, where tcf_gate_act() can return TC_ACT_SHOT or whatever is written in parm.action. That's why I'm asking, if these two control actions are forbidden you should let the kernel return -EINVAL with a proper extack in tcf_gate_init(). Can you please clarify?

thank you in advance!

Signature · 1 line
davide
author
#116 lore raw

RE: [EXT] Re: [v4,iproute2-next 1/2] iproute2-next:tc:action: add a gate control action

Hi Davide,

Quoted 55 lines

-----Original Message-----
From: Davide Caratti <[email protected]>
Sent: 2020年5月6日 20:54
To: Po Liu <[email protected]>; [email protected]; linux- [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Claudiu Manoil <[email protected]>; Vladimir Oltean <[email protected]>; Alexandru Marginean <[email protected]>
Subject: [EXT] Re: [v4,iproute2-next 1/2] iproute2-next:tc:action: add a gate control action

Caution: EXT Email

Quoted 1 line · Po Liu

Introduce a ingress frame gate control flow action.

[...]

hello Po Liu,

[...]

Quoted 33 lines
tc/m_gate.c new file +33 -0
+create_entry:
+                     e = create_gate_entry(gate_state, interval,
+                                           ipv, maxoctets);
+                     if (!e) {
+                             fprintf(stderr, "gate: not enough memory\n");
+                             free_entries(&gate_entries);
+                             return -1;
+                     }
+
+                     list_add_tail(&e->list, &gate_entries);
+                     entry_num++;
+
+             } else if (matches(*argv, "reclassify") == 0 ||
+                        matches(*argv, "drop") == 0 ||
+                        matches(*argv, "shot") == 0 ||
+                        matches(*argv, "continue") == 0 ||
+                        matches(*argv, "pass") == 0 ||
+                        matches(*argv, "ok") == 0 ||
+                        matches(*argv, "pipe") == 0 ||
+                        matches(*argv, "goto") == 0) {
+                     if (parse_action_control(&argc, &argv,
+                                              &parm.action, false)) {
+                             free_entries(&gate_entries);
+                             return -1;
+                     }
+             } else if (matches(*argv, "help") == 0) {
+                     usage();
+             } else {
+                     break;
+             }
+
+             argc--;
+             argv++;
Quoted 8 lines

tc/m_gate.c line 349

Quoted 4 lines
tc/m_gate.c new file +4 -0
+     }
+
+     parse_action_control_dflt(&argc, &argv, &parm.action,
+                               false, TC_ACT_PIPE);

it seems that the control action is parsed twice, and the first time it does not allow "jump" and "trap". Is that intentional? IOW, are there some "act_gate" configurations that don't allow jump or trap?

It is allowed to jump and trap. I didn't notice it was loaded twice. I would correct here and remove one parse_action_control() Thanks a lot!

Quoted 11 lines

I don't see anything similar in kernel act_gate.c, where tcf_gate_act() can return TC_ACT_SHOT or whatever is written in parm.action. That's why I'm asking, if these two control actions are forbidden you should let the kernel return -EINVAL with a proper extack in tcf_gate_init(). Can you please clarify?

thank you in advance!
--
davide

Br,
Po Liu

#117 lore raw

Re: [v4,iproute2-next 1/2] iproute2-next:tc:action: add a gate control action

In reply to Po Liu
Quoted 8 lines · On Wed, 6 May 2020 16:40:19 +0800 Po Liu <[email protected]> wrote:
		} else if (matches(*argv, "base-time") == 0) {
tc/m_gate.c new file +7 -0
+			NEXT_ARG();
+			if (get_u64(&base_time, *argv, 10)) {
+				invalidarg = "base-time";
+				goto err_arg;
+			}
+		} else if (matches(*argv, "cycle-time") == 0) {
+			NEXT_ARG();

tc/m_gate.c line 237

Quoted 10 lines
tc/m_gate.c new file +10 -0
+			if (get_u64(&cycle_time, *argv, 10)) {
+				invalidarg = "cycle-time";
+				goto err_arg;
+			}
+		} else if (matches(*argv, "cycle-time-ext") == 0) {
+			NEXT_ARG();
+			if (get_u64(&cycle_time_ext, *argv, 10)) {
+				invalidarg = "cycle-time-ext";
+				goto err_arg;
+			}

Could all these time values use existing TC helper routines? See get_time(). The way you have it makes sense for hardware but stands out versus the rest of tc.

It maybe that the kernel UAPI is wrong, and should be using same time units as rest of tc. Forgot to review that part of the patch.

#118 lore raw

Re: [v3,iproute2 1/2] iproute2:tc:action: add a gate control action

In reply to Po Liu
Quoted 46 lines · On Sun, 3 May 2020 14:32:50 +0800 Po Liu <[email protected]> wrote:

Introduce a ingress frame gate control flow action.
Tc gate action does the work like this:
Assume there is a gate allow specified ingress frames can pass at specific time slot, and also drop at specific time slot. Tc filter chooses the ingress frames, and tc gate action would specify what slot does these frames can be passed to device and what time slot would be dropped.
Tc gate action would provide an entry list to tell how much time gate keep open and how much time gate keep state close. Gate action also assign a start time to tell when the entry list start. Then driver would repeat the gate entry list cyclically.
For the software simulation, gate action require the user assign a time clock type.

Below is the setting example in user space. Tc filter a stream source ip address is 192.168.0.20 and gate action own two time slots. One is last 200ms gate open let frame pass another is last 100ms gate close let frames dropped.

 # 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 clockid CLOCK_TAI \
            sched-entry open 200000000 -1 -1 \
            sched-entry close 100000000
 # 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 to. "-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.

Below example shows filtering a stream with destination mac address is 10:00:80:00:00:00 and ip type is ICMP, follow the action gate. The gate action would run with one close time slot which means always keep close. The time cycle is total 200000000ns. The base-time would calculate by:

     1357000000000 + (N + 1) * cycletime

When the total value is the future time, it will be the start time. The cycletime here would be 200000000ns for this case.

Quoted 7 lines

#tc filter add dev eth0 parent ffff: protocol ip \

           flower skip_hw ip_proto icmp dst_mac 10:00:80:00:00:00 \
           action gate index 12 base-time 1357000000000 \
           sched-entry CLOSE 200000000 \
           clockid CLOCK_TAI

These changes are specific to net-next should be assigned to iproute2-next. Will change delegation.

#119 lore raw

Re: [v3,iproute2 1/2] iproute2:tc:action: add a gate control action

In reply to Po Liu

tc/m_gate.c line 427

Quoted 1 line · On Sun, 3 May 2020 14:32:50 +0800 Po Liu <[email protected]> wrote:
tc/m_gate.c new file +1 -0
+		print_string(PRINT_ANY, "gate state", "\tgate-state %-8s",

NAK
Space in a json tag is not valid.

Please run a dump command and feed it into JSON validation checker like Python.

maintainer
#120 lore raw
In reply to Po Liu

From: Po Liu <[email protected]>
Date: Fri, 1 May 2020 08:53:14 +0800

...

Quoted 4 lines

These patches add stream gate action policing in IEEE802.1Qci (Per-Stream Filtering and Policing) software support and hardware offload support in tc flower, and implement the stream identify, stream filtering and stream gate filtering action in the NXP ENETC ethernet driver.

...

Series applied, thanks.

author
#121 lore raw

PATCH v2 1/1 net: qos offload add flow status with dropped count

In reply to Po Liu

From: Po Liu <[email protected]>

This patch adds a drop frames counter to tc flower offloading. Reporting h/w dropped frames is necessary for some actions. Some actions like police action and the coming introduced stream gate action would produce dropped frames which is necessary for user. Status update shows how many filtered packets increasing and how many dropped in those packets.

v2: Changes
- Update commit comments suggest by Jiri Pirko.

---
This patch is continue the thread [email protected]

 drivers/net/dsa/sja1105/sja1105_vl.c                  |  2 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c          |  2 +-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c  |  2 +-
 .../net/ethernet/chelsio/cxgb4/cxgb4_tc_matchall.c    |  2 +-
 drivers/net/ethernet/freescale/enetc/enetc_qos.c      |  7 +++++--
 drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c    |  2 +-
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c       |  4 ++--
 drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c |  2 +-
 drivers/net/ethernet/mscc/ocelot_flower.c             |  2 +-
 drivers/net/ethernet/netronome/nfp/flower/offload.c   |  2 +-
 drivers/net/ethernet/netronome/nfp/flower/qos_conf.c  |  2 +-
 include/net/act_api.h                                 | 11 ++++++-----
 include/net/flow_offload.h                            |  5 ++++-
 include/net/pkt_cls.h                                 |  5 +++--
 net/sched/act_api.c                                   | 10 ++++------
 net/sched/act_ct.c                                    |  6 +++---
 net/sched/act_gact.c                                  |  7 ++++---
 net/sched/act_gate.c                                  |  6 +++---
 net/sched/act_mirred.c                                |  6 +++---
 net/sched/act_pedit.c                                 |  6 +++---
 net/sched/act_police.c                                |  4 ++--
 net/sched/act_skbedit.c                               |  5 +++--
 net/sched/act_vlan.c                                  |  6 +++---
 net/sched/cls_flower.c                                |  1 +
 net/sched/cls_matchall.c                              |  3 ++-
 25 files changed, 60 insertions(+), 50 deletions(-)
drivers/net/dsa/sja1105/sja1105_vl.c +1 -1
index bdfd6c4e190d..9ddc49b7eb8f 100644
@@ -771,7 +771,7 @@ int sja1105_vl_stats(struct sja1105_private *priv, int port,
 
 	pkts = timingerr + unreleased + lengtherr;
 
-	flow_stats_update(stats, 0, pkts - rule->vl.stats.pkts,
+	flow_stats_update(stats, 0, pkts - rule->vl.stats.pkts, 0,
 			  jiffies - rule->vl.stats.lastused,
 			  FLOW_ACTION_HW_STATS_IMMEDIATE);
 
drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c +1 -1
index 0eef4f5e4a46..4d482d75a20b 100644
@@ -1638,7 +1638,7 @@ static int bnxt_tc_get_flow_stats(struct bnxt *bp,
 	lastused = flow->lastused;
 	spin_unlock(&flow->stats_lock);
 
-	flow_stats_update(&tc_flow_cmd->stats, stats.bytes, stats.packets,
+	flow_stats_update(&tc_flow_cmd->stats, stats.bytes, stats.packets, 0,
 			  lastused, FLOW_ACTION_HW_STATS_DELAYED);
 	return 0;
 }
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c +1 -1
index 4a5fa9eba0b6..030de20a5d27 100644
@@ -902,7 +902,7 @@ int cxgb4_tc_flower_stats(struct net_device *dev,
 		if (ofld_stats->prev_packet_count != packets)
 			ofld_stats->last_used = jiffies;
 		flow_stats_update(&cls->stats, bytes - ofld_stats->byte_count,
-				  packets - ofld_stats->packet_count,
+				  packets - ofld_stats->packet_count, 0,
 				  ofld_stats->last_used,
 				  FLOW_ACTION_HW_STATS_IMMEDIATE);
 
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_matchall.c +1 -1
index c88c47a14fbb..c439b5bce9c9 100644
@@ -346,7 +346,7 @@ int cxgb4_tc_matchall_stats(struct net_device *dev,
 		flow_stats_update(&cls_matchall->stats,
 				  bytes - tc_port_matchall->ingress.bytes,
 				  packets - tc_port_matchall->ingress.packets,
-				  tc_port_matchall->ingress.last_used,
+				  0, tc_port_matchall->ingress.last_used,
 				  FLOW_ACTION_HW_STATS_IMMEDIATE);
 
 		tc_port_matchall->ingress.packets = packets;
drivers/net/ethernet/freescale/enetc/enetc_qos.c +5 -2
index fd3df19eaa32..fb76903eca90 100644
@@ -1291,12 +1291,15 @@ static int enetc_psfp_get_stats(struct enetc_ndev_priv *priv,
 
 	spin_lock(&epsfp.psfp_lock);
 	stats.pkts = counters.matching_frames_count - filter->stats.pkts;
+	stats.drops = counters.not_passing_frames_count -
+					filter->stats.drops;
 	stats.lastused = filter->stats.lastused;
 	filter->stats.pkts += stats.pkts;
+	filter->stats.drops += stats.drops;
 	spin_unlock(&epsfp.psfp_lock);
 
-	flow_stats_update(&f->stats, 0x0, stats.pkts, stats.lastused,
-			  FLOW_ACTION_HW_STATS_DELAYED);
+	flow_stats_update(&f->stats, 0x0, stats.pkts, stats.drops,
+			  stats.lastused, FLOW_ACTION_HW_STATS_DELAYED);
 
 	return 0;
 }
drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c +1 -1
index 430025550fad..c7107da03212 100644
@@ -672,7 +672,7 @@ mlx5_tc_ct_block_flow_offload_stats(struct mlx5_ct_ft *ft,
 		return -ENOENT;
 
 	mlx5_fc_query_cached(entry->counter, &bytes, &packets, &lastuse);
-	flow_stats_update(&f->stats, bytes, packets, lastuse,
+	flow_stats_update(&f->stats, bytes, packets, 0, lastuse,
 			  FLOW_ACTION_HW_STATS_DELAYED);
 
 	return 0;
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +2 -2
index 7fc84f58e28a..bc9c0ac15f99 100644
@@ -4828,7 +4828,7 @@ int mlx5e_stats_flower(struct net_device *dev, struct mlx5e_priv *priv,
 no_peer_counter:
 	mlx5_devcom_release_peer_data(devcom, MLX5_DEVCOM_ESW_OFFLOADS);
 out:
-	flow_stats_update(&f->stats, bytes, packets, lastuse,
+	flow_stats_update(&f->stats, bytes, packets, 0, lastuse,
 			  FLOW_ACTION_HW_STATS_DELAYED);
 	trace_mlx5e_stats_flower(f);
 errout:
@@ -4946,7 +4946,7 @@ void mlx5e_tc_stats_matchall(struct mlx5e_priv *priv,
 	dpkts = cur_stats.rx_packets - rpriv->prev_vf_vport_stats.rx_packets;
 	dbytes = cur_stats.rx_bytes - rpriv->prev_vf_vport_stats.rx_bytes;
 	rpriv->prev_vf_vport_stats = cur_stats;
-	flow_stats_update(&ma->stats, dbytes, dpkts, jiffies,
+	flow_stats_update(&ma->stats, dbytes, dpkts, 0, jiffies,
 			  FLOW_ACTION_HW_STATS_DELAYED);
 }
 
drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c +1 -1
index 51e1b3930c56..61d21043d83a 100644
@@ -633,7 +633,7 @@ int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
 	if (err)
 		goto err_rule_get_stats;
 
-	flow_stats_update(&f->stats, bytes, packets, lastuse, used_hw_stats);
+	flow_stats_update(&f->stats, bytes, packets, 0, lastuse, used_hw_stats);
 
 	mlxsw_sp_acl_ruleset_put(mlxsw_sp, ruleset);
 	return 0;
drivers/net/ethernet/mscc/ocelot_flower.c +1 -1
index 5ce172e22b43..c90bafbd651f 100644
@@ -244,7 +244,7 @@ int ocelot_cls_flower_stats(struct ocelot *ocelot, int port,
 	if (ret)
 		return ret;
 
-	flow_stats_update(&f->stats, 0x0, ace.stats.pkts, 0x0,
+	flow_stats_update(&f->stats, 0x0, ace.stats.pkts, 0, 0x0,
 			  FLOW_ACTION_HW_STATS_IMMEDIATE);
 	return 0;
 }
drivers/net/ethernet/netronome/nfp/flower/offload.c +1 -1
index 695d24b9dd92..234c652700e1 100644
@@ -1491,7 +1491,7 @@ nfp_flower_get_stats(struct nfp_app *app, struct net_device *netdev,
 		nfp_flower_update_merge_stats(app, nfp_flow);
 
 	flow_stats_update(&flow->stats, priv->stats[ctx_id].bytes,
-			  priv->stats[ctx_id].pkts, priv->stats[ctx_id].used,
+			  priv->stats[ctx_id].pkts, 0, priv->stats[ctx_id].used,
 			  FLOW_ACTION_HW_STATS_DELAYED);
 
 	priv->stats[ctx_id].pkts = 0;
drivers/net/ethernet/netronome/nfp/flower/qos_conf.c +1 -1
index d18a830e4264..bb327d48d1ab 100644
@@ -319,7 +319,7 @@ nfp_flower_stats_rate_limiter(struct nfp_app *app, struct net_device *netdev,
 	prev_stats->bytes = curr_stats->bytes;
 	spin_unlock_bh(&fl_priv->qos_stats_lock);
 
-	flow_stats_update(&flow->stats, diff_bytes, diff_pkts,
+	flow_stats_update(&flow->stats, diff_bytes, diff_pkts, 0,
 			  repr_priv->qos_table.last_update,
 			  FLOW_ACTION_HW_STATS_DELAYED);
 	return 0;
include/net/act_api.h +6 -5
index 8c3934880670..cb382a89ea58 100644
@@ -106,7 +106,7 @@ struct tc_action_ops {
 			struct netlink_callback *, int,
 			const struct tc_action_ops *,
 			struct netlink_ext_ack *);
-	void	(*stats_update)(struct tc_action *, u64, u32, u64, bool);
+	void	(*stats_update)(struct tc_action *, u64, u64, u64, u64, bool);
 	size_t  (*get_fill_size)(const struct tc_action *act);
 	struct net_device *(*get_dev)(const struct tc_action *a,
 				      tc_action_priv_destructor *destructor);
@@ -232,8 +232,8 @@ static inline void tcf_action_inc_overlimit_qstats(struct tc_action *a)
 	spin_unlock(&a->tcfa_lock);
 }
 
-void tcf_action_update_stats(struct tc_action *a, u64 bytes, u32 packets,
-			     bool drop, bool hw);
+void tcf_action_update_stats(struct tc_action *a, u64 bytes, u64 packets,
+			     u64 drops, bool hw);
 int tcf_action_copy_stats(struct sk_buff *, struct tc_action *, int);
 
 int tcf_action_check_ctrlact(int action, struct tcf_proto *tp,
@@ -244,13 +244,14 @@ struct tcf_chain *tcf_action_set_ctrlact(struct tc_action *a, int action,
 #endif /* CONFIG_NET_CLS_ACT */
 
 static inline void tcf_action_stats_update(struct tc_action *a, u64 bytes,
-					   u64 packets, u64 lastuse, bool hw)
+					   u64 packets, u64 drops,
+					   u64 lastuse, bool hw)
 {
 #ifdef CONFIG_NET_CLS_ACT
 	if (!a->ops->stats_update)
 		return;
 
-	a->ops->stats_update(a, bytes, packets, lastuse, hw);
+	a->ops->stats_update(a, bytes, packets, drops, lastuse, hw);
 #endif
 }
 
include/net/flow_offload.h +4 -1
index f2c8311a0433..00c15f14c434 100644
@@ -389,17 +389,20 @@ static inline bool flow_rule_match_key(const struct flow_rule *rule,
 struct flow_stats {
 	u64	pkts;
 	u64	bytes;
+	u64	drops;
 	u64	lastused;
 	enum flow_action_hw_stats used_hw_stats;
 	bool used_hw_stats_valid;
 };
 
 static inline void flow_stats_update(struct flow_stats *flow_stats,
-				     u64 bytes, u64 pkts, u64 lastused,
+				     u64 bytes, u64 pkts,
+				     u64 drops, u64 lastused,
 				     enum flow_action_hw_stats used_hw_stats)
 {
 	flow_stats->pkts	+= pkts;
 	flow_stats->bytes	+= bytes;
+	flow_stats->drops	+= drops;
 	flow_stats->lastused	= max_t(u64, flow_stats->lastused, lastused);
 
 	/* The driver should pass value with a maximum of one bit set.
include/net/pkt_cls.h +3 -2
index ed65619cbc47..ff017e5b3ea2 100644
@@ -262,7 +262,7 @@ static inline void tcf_exts_put_net(struct tcf_exts *exts)
 
 static inline void
 tcf_exts_stats_update(const struct tcf_exts *exts,
-		      u64 bytes, u64 packets, u64 lastuse,
+		      u64 bytes, u64 packets, u64 drops, u64 lastuse,
 		      u8 used_hw_stats, bool used_hw_stats_valid)
 {
 #ifdef CONFIG_NET_CLS_ACT
@@ -273,7 +273,8 @@ tcf_exts_stats_update(const struct tcf_exts *exts,
 	for (i = 0; i < exts->nr_actions; i++) {
 		struct tc_action *a = exts->actions[i];
 
-		tcf_action_stats_update(a, bytes, packets, lastuse, true);
+		tcf_action_stats_update(a, bytes, packets, drops,
+					lastuse, true);
 		a->used_hw_stats = used_hw_stats;
 		a->used_hw_stats_valid = used_hw_stats_valid;
 	}
net/sched/act_api.c +4 -6
index 8ac7eb0a8309..4c4466f18801 100644
@@ -1059,14 +1059,13 @@ int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla,
 	return err;
 }
 
-void tcf_action_update_stats(struct tc_action *a, u64 bytes, u32 packets,
-			     bool drop, bool hw)
+void tcf_action_update_stats(struct tc_action *a, u64 bytes, u64 packets,
+			     u64 drops, bool hw)
 {
 	if (a->cpu_bstats) {
 		_bstats_cpu_update(this_cpu_ptr(a->cpu_bstats), bytes, packets);
 
-		if (drop)
-			this_cpu_ptr(a->cpu_qstats)->drops += packets;
+		this_cpu_ptr(a->cpu_qstats)->drops += drops;
 
 		if (hw)
 			_bstats_cpu_update(this_cpu_ptr(a->cpu_bstats_hw),
@@ -1075,8 +1074,7 @@ void tcf_action_update_stats(struct tc_action *a, u64 bytes, u32 packets,
 	}
 
 	_bstats_update(&a->tcfa_bstats, bytes, packets);
-	if (drop)
-		a->tcfa_qstats.drops += packets;
+	a->tcfa_qstats.drops += drops;
 	if (hw)
 		_bstats_update(&a->tcfa_bstats_hw, bytes, packets);
 }
net/sched/act_ct.c +3 -3
index e9f3576cbf71..1b9c6d4a1b6b 100644
@@ -1450,12 +1450,12 @@ static int tcf_ct_search(struct net *net, struct tc_action **a, u32 index)
 	return tcf_idr_search(tn, a, index);
 }
 
-static void tcf_stats_update(struct tc_action *a, u64 bytes, u32 packets,
-			     u64 lastuse, bool hw)
+static void tcf_stats_update(struct tc_action *a, u64 bytes, u64 packets,
+			     u64 drops, u64 lastuse, bool hw)
 {
 	struct tcf_ct *c = to_ct(a);
 
-	tcf_action_update_stats(a, bytes, packets, false, hw);
+	tcf_action_update_stats(a, bytes, packets, drops, hw);
 	c->tcf_tm.lastuse = max_t(u64, c->tcf_tm.lastuse, lastuse);
 }
 
net/sched/act_gact.c +4 -3
index 416065772719..410e3bbfb9ca 100644
@@ -171,14 +171,15 @@ static int tcf_gact_act(struct sk_buff *skb, const struct tc_action *a,
 	return action;
 }
 
-static void tcf_gact_stats_update(struct tc_action *a, u64 bytes, u32 packets,
-				  u64 lastuse, bool hw)
+static void tcf_gact_stats_update(struct tc_action *a, u64 bytes, u64 packets,
+				  u64 drops, u64 lastuse, bool hw)
 {
 	struct tcf_gact *gact = to_gact(a);
 	int action = READ_ONCE(gact->tcf_action);
 	struct tcf_t *tm = &gact->tcf_tm;
 
-	tcf_action_update_stats(a, bytes, packets, action == TC_ACT_SHOT, hw);
+	tcf_action_update_stats(a, bytes, packets,
+				action == TC_ACT_SHOT ? packets : drops, hw);
 	tm->lastuse = max_t(u64, tm->lastuse, lastuse);
 }
 
net/sched/act_gate.c +3 -3
index 9c628591f452..c818844846b1 100644
@@ -568,13 +568,13 @@ static int tcf_gate_walker(struct net *net, struct sk_buff *skb,
 	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
 }
 
-static void tcf_gate_stats_update(struct tc_action *a, u64 bytes, u32 packets,
-				  u64 lastuse, bool hw)
+static void tcf_gate_stats_update(struct tc_action *a, u64 bytes, u64 packets,
+				  u64 drops, u64 lastuse, bool hw)
 {
 	struct tcf_gate *gact = to_gate(a);
 	struct tcf_t *tm = &gact->tcf_tm;
 
-	tcf_action_update_stats(a, bytes, packets, false, hw);
+	tcf_action_update_stats(a, bytes, packets, drops, hw);
 	tm->lastuse = max_t(u64, tm->lastuse, lastuse);
 }
 
net/sched/act_mirred.c +3 -3
index 83dd82fc9f40..b2705318993b 100644
@@ -312,13 +312,13 @@ static int tcf_mirred_act(struct sk_buff *skb, const struct tc_action *a,
 	return retval;
 }
 
-static void tcf_stats_update(struct tc_action *a, u64 bytes, u32 packets,
-			     u64 lastuse, bool hw)
+static void tcf_stats_update(struct tc_action *a, u64 bytes, u64 packets,
+			     u64 drops, u64 lastuse, bool hw)
 {
 	struct tcf_mirred *m = to_mirred(a);
 	struct tcf_t *tm = &m->tcf_tm;
 
-	tcf_action_update_stats(a, bytes, packets, false, hw);
+	tcf_action_update_stats(a, bytes, packets, drops, hw);
 	tm->lastuse = max_t(u64, tm->lastuse, lastuse);
 }
 
net/sched/act_pedit.c +3 -3
index d41d6200d9de..66986db062ed 100644
@@ -409,13 +409,13 @@ static int tcf_pedit_act(struct sk_buff *skb, const struct tc_action *a,
 	return p->tcf_action;
 }
 
-static void tcf_pedit_stats_update(struct tc_action *a, u64 bytes, u32 packets,
-				   u64 lastuse, bool hw)
+static void tcf_pedit_stats_update(struct tc_action *a, u64 bytes, u64 packets,
+				   u64 drops, u64 lastuse, bool hw)
 {
 	struct tcf_pedit *d = to_pedit(a);
 	struct tcf_t *tm = &d->tcf_tm;
 
-	tcf_action_update_stats(a, bytes, packets, false, hw);
+	tcf_action_update_stats(a, bytes, packets, drops, hw);
 	tm->lastuse = max_t(u64, tm->lastuse, lastuse);
 }
 
net/sched/act_police.c +2 -2
index 8b7a0ac96c51..0b431d493768 100644
@@ -288,13 +288,13 @@ static void tcf_police_cleanup(struct tc_action *a)
 }
 
 static void tcf_police_stats_update(struct tc_action *a,
-				    u64 bytes, u32 packets,
+				    u64 bytes, u64 packets, u64 drops,
 				    u64 lastuse, bool hw)
 {
 	struct tcf_police *police = to_police(a);
 	struct tcf_t *tm = &police->tcf_tm;
 
-	tcf_action_update_stats(a, bytes, packets, false, hw);
+	tcf_action_update_stats(a, bytes, packets, drops, hw);
 	tm->lastuse = max_t(u64, tm->lastuse, lastuse);
 }
 
net/sched/act_skbedit.c +3 -2
index b125b2be4467..361b863e0634 100644
@@ -74,12 +74,13 @@ static int tcf_skbedit_act(struct sk_buff *skb, const struct tc_action *a,
 }
 
 static void tcf_skbedit_stats_update(struct tc_action *a, u64 bytes,
-				     u32 packets, u64 lastuse, bool hw)
+				     u64 packets, u64 drops,
+				     u64 lastuse, bool hw)
 {
 	struct tcf_skbedit *d = to_skbedit(a);
 	struct tcf_t *tm = &d->tcf_tm;
 
-	tcf_action_update_stats(a, bytes, packets, false, hw);
+	tcf_action_update_stats(a, bytes, packets, drops, hw);
 	tm->lastuse = max_t(u64, tm->lastuse, lastuse);
 }
 
net/sched/act_vlan.c +3 -3
index c91d3958fcbb..a5ff9f68ab02 100644
@@ -302,13 +302,13 @@ static int tcf_vlan_walker(struct net *net, struct sk_buff *skb,
 	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
 }
 
-static void tcf_vlan_stats_update(struct tc_action *a, u64 bytes, u32 packets,
-				  u64 lastuse, bool hw)
+static void tcf_vlan_stats_update(struct tc_action *a, u64 bytes, u64 packets,
+				  u64 drops, u64 lastuse, bool hw)
 {
 	struct tcf_vlan *v = to_vlan(a);
 	struct tcf_t *tm = &v->tcf_tm;
 
-	tcf_action_update_stats(a, bytes, packets, false, hw);
+	tcf_action_update_stats(a, bytes, packets, drops, hw);
 	tm->lastuse = max_t(u64, tm->lastuse, lastuse);
 }
 
net/sched/cls_flower.c +1 -0
index b2da37286082..391971672d54 100644
@@ -491,6 +491,7 @@ static void fl_hw_update_stats(struct tcf_proto *tp, struct cls_fl_filter *f,
 
 	tcf_exts_stats_update(&f->exts, cls_flower.stats.bytes,
 			      cls_flower.stats.pkts,
+			      cls_flower.stats.drops,
 			      cls_flower.stats.lastused,
 			      cls_flower.stats.used_hw_stats,
 			      cls_flower.stats.used_hw_stats_valid);
net/sched/cls_matchall.c +2 -1
index 8d39dbcf1746..cafb84480bab 100644
@@ -338,7 +338,8 @@ static void mall_stats_hw_filter(struct tcf_proto *tp,
 	tc_setup_cb_call(block, TC_SETUP_CLSMATCHALL, &cls_mall, false, true);
 
 	tcf_exts_stats_update(&head->exts, cls_mall.stats.bytes,
-			      cls_mall.stats.pkts, cls_mall.stats.lastused,
+			      cls_mall.stats.pkts, cls_mall.stats.drops,
+			      cls_mall.stats.lastused,
 			      cls_mall.stats.used_hw_stats,
 			      cls_mall.stats.used_hw_stats_valid);
 }
Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#122 lore raw

Re: [v2,net-next] net: qos offload add flow status with dropped count

Quoted 34 lines · Po Liu

From: Po Liu <[email protected]>

This patch adds a drop frames counter to tc flower offloading. Reporting h/w dropped frames is necessary for some actions. Some actions like police action and the coming introduced stream gate action would produce dropped frames which is necessary for user. Status update shows how many filtered packets increasing and how many dropped in those packets.

v2: Changes
- Update commit comments suggest by Jiri Pirko.

---
This patch is continue the thread [email protected]

 drivers/net/dsa/sja1105/sja1105_vl.c                  |  2 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c          |  2 +-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c  |  2 +-
 .../net/ethernet/chelsio/cxgb4/cxgb4_tc_matchall.c    |  2 +-
 drivers/net/ethernet/freescale/enetc/enetc_qos.c      |  7 +++++--
 drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c    |  2 +-
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c       |  4 ++--
 drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c |  2 +-
 drivers/net/ethernet/mscc/ocelot_flower.c             |  2 +-
 drivers/net/ethernet/netronome/nfp/flower/offload.c   |  2 +-
 drivers/net/ethernet/netronome/nfp/flower/qos_conf.c  |  2 +-
 include/net/act_api.h                                 | 11 ++++++-----
 include/net/flow_offload.h                            |  5 ++++-
 include/net/pkt_cls.h                                 |  5 +++--
 net/sched/act_api.c                                   | 10 ++++------
 net/sched/act_ct.c                                    |  6 +++---
 net/sched/act_gact.c                                  |  7 ++++---
 net/sched/act_gate.c                                  |  6 +++---
Quoted 8 lines
 net/sched/act_mirred.c                                |  6 +++---
 net/sched/act_pedit.c                                 |  6 +++---
 net/sched/act_police.c                                |  4 ++--
 net/sched/act_skbedit.c                               |  5 +++--
 net/sched/act_vlan.c                                  |  6 +++---
 net/sched/cls_flower.c                                |  1 +
 net/sched/cls_matchall.c                              |  3 ++-
 25 files changed, 60 insertions(+), 50 deletions(-)

Netronome portion:

Reviewed-by on v2 1/1
#123 lore raw

Re: [v2,net-next] net: qos offload add flow status with dropped count

In reply to Po Liu
Quoted 9 lines · Po Liu

From: Po Liu <[email protected]>

This patch adds a drop frames counter to tc flower offloading. Reporting h/w dropped frames is necessary for some actions. Some actions like police action and the coming introduced stream gate action would produce dropped frames which is necessary for user. Status update shows how many filtered packets increasing and how many dropped in those packets.

Quoted 5 lines

v2: Changes
- Update commit comments suggest by Jiri Pirko.

---

maintainer Applied
#124 lore raw

Re: [v2,net-next] net: qos offload add flow status with dropped count

In reply to Po Liu

From: Po Liu <[email protected]>
Date: Fri, 19 Jun 2020 14:01:07 +0800

Quoted 9 lines

From: Po Liu <[email protected]>

This patch adds a drop frames counter to tc flower offloading. Reporting h/w dropped frames is necessary for some actions. Some actions like police action and the coming introduced stream gate action would produce dropped frames which is necessary for user. Status update shows how many filtered packets increasing and how many dropped in those packets.

Quoted 4 lines

v2: Changes
- Update commit comments suggest by Jiri Pirko.

Applied, thank you.