2019-06-04 16:11:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2011-01-17 16:06:09 +08:00
|
|
|
/*
|
|
|
|
* net/sched/sch_mqprio.c
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010 John Fastabend <john.r.fastabend@intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/skbuff.h>
|
2011-05-27 21:12:25 +08:00
|
|
|
#include <linux/module.h>
|
2011-01-17 16:06:09 +08:00
|
|
|
#include <net/netlink.h>
|
|
|
|
#include <net/pkt_sched.h>
|
|
|
|
#include <net/sch_generic.h>
|
2017-09-07 19:00:06 +08:00
|
|
|
#include <net/pkt_cls.h>
|
2011-01-17 16:06:09 +08:00
|
|
|
|
|
|
|
struct mqprio_sched {
|
|
|
|
struct Qdisc **qdiscs;
|
2017-09-07 19:00:06 +08:00
|
|
|
u16 mode;
|
|
|
|
u16 shaper;
|
2017-03-16 01:39:18 +08:00
|
|
|
int hw_offload;
|
2017-09-07 19:00:06 +08:00
|
|
|
u32 flags;
|
|
|
|
u64 min_rate[TC_QOPT_MAX_QUEUE];
|
|
|
|
u64 max_rate[TC_QOPT_MAX_QUEUE];
|
2011-01-17 16:06:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static void mqprio_destroy(struct Qdisc *sch)
|
|
|
|
{
|
|
|
|
struct net_device *dev = qdisc_dev(sch);
|
|
|
|
struct mqprio_sched *priv = qdisc_priv(sch);
|
|
|
|
unsigned int ntx;
|
|
|
|
|
2011-02-15 03:02:23 +08:00
|
|
|
if (priv->qdiscs) {
|
|
|
|
for (ntx = 0;
|
|
|
|
ntx < dev->num_tx_queues && priv->qdiscs[ntx];
|
|
|
|
ntx++)
|
2018-09-25 00:22:50 +08:00
|
|
|
qdisc_put(priv->qdiscs[ntx]);
|
2011-02-15 03:02:23 +08:00
|
|
|
kfree(priv->qdiscs);
|
|
|
|
}
|
2011-01-17 16:06:09 +08:00
|
|
|
|
2017-03-16 01:39:25 +08:00
|
|
|
if (priv->hw_offload && dev->netdev_ops->ndo_setup_tc) {
|
2017-09-07 19:00:06 +08:00
|
|
|
struct tc_mqprio_qopt_offload mqprio = { { 0 } };
|
|
|
|
|
|
|
|
switch (priv->mode) {
|
|
|
|
case TC_MQPRIO_MODE_DCB:
|
|
|
|
case TC_MQPRIO_MODE_CHANNEL:
|
2017-11-06 14:23:42 +08:00
|
|
|
dev->netdev_ops->ndo_setup_tc(dev,
|
|
|
|
TC_SETUP_QDISC_MQPRIO,
|
2017-09-07 19:00:06 +08:00
|
|
|
&mqprio);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2017-03-16 01:39:25 +08:00
|
|
|
} else {
|
2011-01-17 16:06:09 +08:00
|
|
|
netdev_set_num_tc(dev, 0);
|
2017-03-16 01:39:25 +08:00
|
|
|
}
|
2011-01-17 16:06:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mqprio_parse_opt(struct net_device *dev, struct tc_mqprio_qopt *qopt)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
/* Verify num_tc is not out of max range */
|
|
|
|
if (qopt->num_tc > TC_MAX_QUEUE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Verify priority mapping uses valid tcs */
|
|
|
|
for (i = 0; i < TC_BITMASK + 1; i++) {
|
|
|
|
if (qopt->prio_tc_map[i] >= qopt->num_tc)
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-03-16 01:39:18 +08:00
|
|
|
/* Limit qopt->hw to maximum supported offload value. Drivers have
|
|
|
|
* the option of overriding this later if they don't support the a
|
|
|
|
* given offload type.
|
|
|
|
*/
|
|
|
|
if (qopt->hw > TC_MQPRIO_HW_OFFLOAD_MAX)
|
|
|
|
qopt->hw = TC_MQPRIO_HW_OFFLOAD_MAX;
|
2011-01-17 16:06:09 +08:00
|
|
|
|
2017-03-16 01:39:18 +08:00
|
|
|
/* If hardware offload is requested we will leave it to the device
|
|
|
|
* to either populate the queue counts itself or to validate the
|
|
|
|
* provided queue counts. If ndo_setup_tc is not present then
|
|
|
|
* hardware doesn't support offload and we should return an error.
|
2011-01-17 16:06:09 +08:00
|
|
|
*/
|
|
|
|
if (qopt->hw)
|
2017-03-16 01:39:18 +08:00
|
|
|
return dev->netdev_ops->ndo_setup_tc ? 0 : -EINVAL;
|
2011-01-17 16:06:09 +08:00
|
|
|
|
|
|
|
for (i = 0; i < qopt->num_tc; i++) {
|
|
|
|
unsigned int last = qopt->offset[i] + qopt->count[i];
|
|
|
|
|
|
|
|
/* Verify the queue count is in tx range being equal to the
|
|
|
|
* real_num_tx_queues indicates the last queue is in use.
|
|
|
|
*/
|
|
|
|
if (qopt->offset[i] >= dev->real_num_tx_queues ||
|
|
|
|
!qopt->count[i] ||
|
|
|
|
last > dev->real_num_tx_queues)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Verify that the offset and counts do not overlap */
|
|
|
|
for (j = i + 1; j < qopt->num_tc; j++) {
|
|
|
|
if (last > qopt->offset[j])
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-07 19:00:06 +08:00
|
|
|
static const struct nla_policy mqprio_policy[TCA_MQPRIO_MAX + 1] = {
|
|
|
|
[TCA_MQPRIO_MODE] = { .len = sizeof(u16) },
|
|
|
|
[TCA_MQPRIO_SHAPER] = { .len = sizeof(u16) },
|
|
|
|
[TCA_MQPRIO_MIN_RATE64] = { .type = NLA_NESTED },
|
|
|
|
[TCA_MQPRIO_MAX_RATE64] = { .type = NLA_NESTED },
|
|
|
|
};
|
|
|
|
|
|
|
|
static int parse_attr(struct nlattr *tb[], int maxtype, struct nlattr *nla,
|
|
|
|
const struct nla_policy *policy, int len)
|
|
|
|
{
|
|
|
|
int nested_len = nla_len(nla) - NLA_ALIGN(len);
|
|
|
|
|
|
|
|
if (nested_len >= nla_attr_size(0))
|
netlink: make validation more configurable for future strictness
We currently have two levels of strict validation:
1) liberal (default)
- undefined (type >= max) & NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
- garbage at end of message accepted
2) strict (opt-in)
- NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
Split out parsing strictness into four different options:
* TRAILING - check that there's no trailing data after parsing
attributes (in message or nested)
* MAXTYPE - reject attrs > max known type
* UNSPEC - reject attributes with NLA_UNSPEC policy entries
* STRICT_ATTRS - strictly validate attribute size
The default for future things should be *everything*.
The current *_strict() is a combination of TRAILING and MAXTYPE,
and is renamed to _deprecated_strict().
The current regular parsing has none of this, and is renamed to
*_parse_deprecated().
Additionally it allows us to selectively set one of the new flags
even on old policies. Notably, the UNSPEC flag could be useful in
this case, since it can be arranged (by filling in the policy) to
not be an incompatible userspace ABI change, but would then going
forward prevent forgetting attribute entries. Similar can apply
to the POLICY flag.
We end up with the following renames:
* nla_parse -> nla_parse_deprecated
* nla_parse_strict -> nla_parse_deprecated_strict
* nlmsg_parse -> nlmsg_parse_deprecated
* nlmsg_parse_strict -> nlmsg_parse_deprecated_strict
* nla_parse_nested -> nla_parse_nested_deprecated
* nla_validate_nested -> nla_validate_nested_deprecated
Using spatch, of course:
@@
expression TB, MAX, HEAD, LEN, POL, EXT;
@@
-nla_parse(TB, MAX, HEAD, LEN, POL, EXT)
+nla_parse_deprecated(TB, MAX, HEAD, LEN, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression TB, MAX, NLA, POL, EXT;
@@
-nla_parse_nested(TB, MAX, NLA, POL, EXT)
+nla_parse_nested_deprecated(TB, MAX, NLA, POL, EXT)
@@
expression START, MAX, POL, EXT;
@@
-nla_validate_nested(START, MAX, POL, EXT)
+nla_validate_nested_deprecated(START, MAX, POL, EXT)
@@
expression NLH, HDRLEN, MAX, POL, EXT;
@@
-nlmsg_validate(NLH, HDRLEN, MAX, POL, EXT)
+nlmsg_validate_deprecated(NLH, HDRLEN, MAX, POL, EXT)
For this patch, don't actually add the strict, non-renamed versions
yet so that it breaks compile if I get it wrong.
Also, while at it, make nla_validate and nla_parse go down to a
common __nla_validate_parse() function to avoid code duplication.
Ultimately, this allows us to have very strict validation for every
new caller of nla_parse()/nlmsg_parse() etc as re-introduced in the
next patch, while existing things will continue to work as is.
In effect then, this adds fully strict validation for any new command.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-04-26 20:07:28 +08:00
|
|
|
return nla_parse_deprecated(tb, maxtype,
|
|
|
|
nla_data(nla) + NLA_ALIGN(len),
|
|
|
|
nested_len, policy, NULL);
|
2017-09-07 19:00:06 +08:00
|
|
|
|
|
|
|
memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-12-21 01:35:13 +08:00
|
|
|
static int mqprio_init(struct Qdisc *sch, struct nlattr *opt,
|
|
|
|
struct netlink_ext_ack *extack)
|
2011-01-17 16:06:09 +08:00
|
|
|
{
|
|
|
|
struct net_device *dev = qdisc_dev(sch);
|
|
|
|
struct mqprio_sched *priv = qdisc_priv(sch);
|
|
|
|
struct netdev_queue *dev_queue;
|
|
|
|
struct Qdisc *qdisc;
|
|
|
|
int i, err = -EOPNOTSUPP;
|
|
|
|
struct tc_mqprio_qopt *qopt = NULL;
|
2017-09-07 19:00:06 +08:00
|
|
|
struct nlattr *tb[TCA_MQPRIO_MAX + 1];
|
|
|
|
struct nlattr *attr;
|
|
|
|
int rem;
|
2017-10-17 23:01:30 +08:00
|
|
|
int len;
|
2011-01-17 16:06:09 +08:00
|
|
|
|
|
|
|
BUILD_BUG_ON(TC_MAX_QUEUE != TC_QOPT_MAX_QUEUE);
|
|
|
|
BUILD_BUG_ON(TC_BITMASK != TC_QOPT_BITMASK);
|
|
|
|
|
|
|
|
if (sch->parent != TC_H_ROOT)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
if (!netif_is_multiqueue(dev))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2017-10-13 02:38:45 +08:00
|
|
|
/* make certain can allocate enough classids to handle queues */
|
|
|
|
if (dev->num_tx_queues >= TC_H_MIN_PRIORITY)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2011-12-22 10:05:07 +08:00
|
|
|
if (!opt || nla_len(opt) < sizeof(*qopt))
|
2011-01-17 16:06:09 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
qopt = nla_data(opt);
|
|
|
|
if (mqprio_parse_opt(dev, qopt))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2017-10-17 23:01:30 +08:00
|
|
|
len = nla_len(opt) - NLA_ALIGN(sizeof(*qopt));
|
2017-09-07 19:00:06 +08:00
|
|
|
if (len > 0) {
|
|
|
|
err = parse_attr(tb, TCA_MQPRIO_MAX, opt, mqprio_policy,
|
|
|
|
sizeof(*qopt));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (!qopt->hw)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (tb[TCA_MQPRIO_MODE]) {
|
|
|
|
priv->flags |= TC_MQPRIO_F_MODE;
|
|
|
|
priv->mode = *(u16 *)nla_data(tb[TCA_MQPRIO_MODE]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tb[TCA_MQPRIO_SHAPER]) {
|
|
|
|
priv->flags |= TC_MQPRIO_F_SHAPER;
|
|
|
|
priv->shaper = *(u16 *)nla_data(tb[TCA_MQPRIO_SHAPER]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tb[TCA_MQPRIO_MIN_RATE64]) {
|
|
|
|
if (priv->shaper != TC_MQPRIO_SHAPER_BW_RATE)
|
|
|
|
return -EINVAL;
|
|
|
|
i = 0;
|
|
|
|
nla_for_each_nested(attr, tb[TCA_MQPRIO_MIN_RATE64],
|
|
|
|
rem) {
|
|
|
|
if (nla_type(attr) != TCA_MQPRIO_MIN_RATE64)
|
|
|
|
return -EINVAL;
|
|
|
|
if (i >= qopt->num_tc)
|
|
|
|
break;
|
|
|
|
priv->min_rate[i] = *(u64 *)nla_data(attr);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
priv->flags |= TC_MQPRIO_F_MIN_RATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tb[TCA_MQPRIO_MAX_RATE64]) {
|
|
|
|
if (priv->shaper != TC_MQPRIO_SHAPER_BW_RATE)
|
|
|
|
return -EINVAL;
|
|
|
|
i = 0;
|
|
|
|
nla_for_each_nested(attr, tb[TCA_MQPRIO_MAX_RATE64],
|
|
|
|
rem) {
|
|
|
|
if (nla_type(attr) != TCA_MQPRIO_MAX_RATE64)
|
|
|
|
return -EINVAL;
|
|
|
|
if (i >= qopt->num_tc)
|
|
|
|
break;
|
|
|
|
priv->max_rate[i] = *(u64 *)nla_data(attr);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
priv->flags |= TC_MQPRIO_F_MAX_RATE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-17 16:06:09 +08:00
|
|
|
/* pre-allocate qdisc, attachment can't fail */
|
|
|
|
priv->qdiscs = kcalloc(dev->num_tx_queues, sizeof(priv->qdiscs[0]),
|
|
|
|
GFP_KERNEL);
|
2017-02-11 02:31:49 +08:00
|
|
|
if (!priv->qdiscs)
|
|
|
|
return -ENOMEM;
|
2011-01-17 16:06:09 +08:00
|
|
|
|
|
|
|
for (i = 0; i < dev->num_tx_queues; i++) {
|
|
|
|
dev_queue = netdev_get_tx_queue(dev, i);
|
2016-03-03 00:21:43 +08:00
|
|
|
qdisc = qdisc_create_dflt(dev_queue,
|
|
|
|
get_default_qdisc_ops(dev, i),
|
2011-01-17 16:06:09 +08:00
|
|
|
TC_H_MAKE(TC_H_MAJ(sch->handle),
|
2017-12-21 01:35:21 +08:00
|
|
|
TC_H_MIN(i + 1)), extack);
|
2017-02-11 02:31:49 +08:00
|
|
|
if (!qdisc)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2011-01-17 16:06:09 +08:00
|
|
|
priv->qdiscs[i] = qdisc;
|
2015-12-02 12:08:51 +08:00
|
|
|
qdisc->flags |= TCQ_F_ONETXQUEUE | TCQ_F_NOPARENT;
|
2011-01-17 16:06:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If the mqprio options indicate that hardware should own
|
|
|
|
* the queue mapping then run ndo_setup_tc otherwise use the
|
|
|
|
* supplied and verified mapping
|
|
|
|
*/
|
|
|
|
if (qopt->hw) {
|
2017-09-07 19:00:06 +08:00
|
|
|
struct tc_mqprio_qopt_offload mqprio = {.qopt = *qopt};
|
2016-02-17 13:16:43 +08:00
|
|
|
|
2017-09-07 19:00:06 +08:00
|
|
|
switch (priv->mode) {
|
|
|
|
case TC_MQPRIO_MODE_DCB:
|
|
|
|
if (priv->shaper != TC_MQPRIO_SHAPER_DCB)
|
|
|
|
return -EINVAL;
|
|
|
|
break;
|
|
|
|
case TC_MQPRIO_MODE_CHANNEL:
|
|
|
|
mqprio.flags = priv->flags;
|
|
|
|
if (priv->flags & TC_MQPRIO_F_MODE)
|
|
|
|
mqprio.mode = priv->mode;
|
|
|
|
if (priv->flags & TC_MQPRIO_F_SHAPER)
|
|
|
|
mqprio.shaper = priv->shaper;
|
|
|
|
if (priv->flags & TC_MQPRIO_F_MIN_RATE)
|
|
|
|
for (i = 0; i < mqprio.qopt.num_tc; i++)
|
|
|
|
mqprio.min_rate[i] = priv->min_rate[i];
|
|
|
|
if (priv->flags & TC_MQPRIO_F_MAX_RATE)
|
|
|
|
for (i = 0; i < mqprio.qopt.num_tc; i++)
|
|
|
|
mqprio.max_rate[i] = priv->max_rate[i];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
err = dev->netdev_ops->ndo_setup_tc(dev,
|
2017-11-06 14:23:42 +08:00
|
|
|
TC_SETUP_QDISC_MQPRIO,
|
2017-08-07 16:15:32 +08:00
|
|
|
&mqprio);
|
2011-01-17 16:06:09 +08:00
|
|
|
if (err)
|
2017-02-11 02:31:49 +08:00
|
|
|
return err;
|
2017-03-16 01:39:18 +08:00
|
|
|
|
2017-09-07 19:00:06 +08:00
|
|
|
priv->hw_offload = mqprio.qopt.hw;
|
2011-01-17 16:06:09 +08:00
|
|
|
} else {
|
|
|
|
netdev_set_num_tc(dev, qopt->num_tc);
|
|
|
|
for (i = 0; i < qopt->num_tc; i++)
|
|
|
|
netdev_set_tc_queue(dev, i,
|
|
|
|
qopt->count[i], qopt->offset[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Always use supplied priority mappings */
|
|
|
|
for (i = 0; i < TC_BITMASK + 1; i++)
|
|
|
|
netdev_set_prio_tc_map(dev, i, qopt->prio_tc_map[i]);
|
|
|
|
|
|
|
|
sch->flags |= TCQ_F_MQROOT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mqprio_attach(struct Qdisc *sch)
|
|
|
|
{
|
|
|
|
struct net_device *dev = qdisc_dev(sch);
|
|
|
|
struct mqprio_sched *priv = qdisc_priv(sch);
|
2013-12-06 03:12:02 +08:00
|
|
|
struct Qdisc *qdisc, *old;
|
2011-01-17 16:06:09 +08:00
|
|
|
unsigned int ntx;
|
|
|
|
|
|
|
|
/* Attach underlying qdisc */
|
|
|
|
for (ntx = 0; ntx < dev->num_tx_queues; ntx++) {
|
|
|
|
qdisc = priv->qdiscs[ntx];
|
2013-12-06 03:12:02 +08:00
|
|
|
old = dev_graft_qdisc(qdisc->dev_queue, qdisc);
|
|
|
|
if (old)
|
2018-09-25 00:22:50 +08:00
|
|
|
qdisc_put(old);
|
2013-12-06 03:12:02 +08:00
|
|
|
if (ntx < dev->real_num_tx_queues)
|
2017-03-08 23:03:32 +08:00
|
|
|
qdisc_hash_add(qdisc, false);
|
2011-01-17 16:06:09 +08:00
|
|
|
}
|
|
|
|
kfree(priv->qdiscs);
|
|
|
|
priv->qdiscs = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct netdev_queue *mqprio_queue_get(struct Qdisc *sch,
|
|
|
|
unsigned long cl)
|
|
|
|
{
|
|
|
|
struct net_device *dev = qdisc_dev(sch);
|
2017-10-13 02:38:45 +08:00
|
|
|
unsigned long ntx = cl - 1;
|
2011-01-17 16:06:09 +08:00
|
|
|
|
|
|
|
if (ntx >= dev->num_tx_queues)
|
|
|
|
return NULL;
|
|
|
|
return netdev_get_tx_queue(dev, ntx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mqprio_graft(struct Qdisc *sch, unsigned long cl, struct Qdisc *new,
|
2017-12-21 01:35:17 +08:00
|
|
|
struct Qdisc **old, struct netlink_ext_ack *extack)
|
2011-01-17 16:06:09 +08:00
|
|
|
{
|
|
|
|
struct net_device *dev = qdisc_dev(sch);
|
|
|
|
struct netdev_queue *dev_queue = mqprio_queue_get(sch, cl);
|
|
|
|
|
|
|
|
if (!dev_queue)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (dev->flags & IFF_UP)
|
|
|
|
dev_deactivate(dev);
|
|
|
|
|
|
|
|
*old = dev_graft_qdisc(dev_queue, new);
|
|
|
|
|
2012-12-11 23:54:33 +08:00
|
|
|
if (new)
|
2015-12-02 12:08:51 +08:00
|
|
|
new->flags |= TCQ_F_ONETXQUEUE | TCQ_F_NOPARENT;
|
2012-12-11 23:54:33 +08:00
|
|
|
|
2011-01-17 16:06:09 +08:00
|
|
|
if (dev->flags & IFF_UP)
|
|
|
|
dev_activate(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-07 19:00:06 +08:00
|
|
|
static int dump_rates(struct mqprio_sched *priv,
|
|
|
|
struct tc_mqprio_qopt *opt, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct nlattr *nest;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (priv->flags & TC_MQPRIO_F_MIN_RATE) {
|
2019-04-26 17:13:06 +08:00
|
|
|
nest = nla_nest_start_noflag(skb, TCA_MQPRIO_MIN_RATE64);
|
2017-09-07 19:00:06 +08:00
|
|
|
if (!nest)
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
for (i = 0; i < opt->num_tc; i++) {
|
|
|
|
if (nla_put(skb, TCA_MQPRIO_MIN_RATE64,
|
|
|
|
sizeof(priv->min_rate[i]),
|
|
|
|
&priv->min_rate[i]))
|
|
|
|
goto nla_put_failure;
|
|
|
|
}
|
|
|
|
nla_nest_end(skb, nest);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->flags & TC_MQPRIO_F_MAX_RATE) {
|
2019-04-26 17:13:06 +08:00
|
|
|
nest = nla_nest_start_noflag(skb, TCA_MQPRIO_MAX_RATE64);
|
2017-09-07 19:00:06 +08:00
|
|
|
if (!nest)
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
for (i = 0; i < opt->num_tc; i++) {
|
|
|
|
if (nla_put(skb, TCA_MQPRIO_MAX_RATE64,
|
|
|
|
sizeof(priv->max_rate[i]),
|
|
|
|
&priv->max_rate[i]))
|
|
|
|
goto nla_put_failure;
|
|
|
|
}
|
|
|
|
nla_nest_end(skb, nest);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
nla_nest_cancel(skb, nest);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-01-17 16:06:09 +08:00
|
|
|
static int mqprio_dump(struct Qdisc *sch, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct net_device *dev = qdisc_dev(sch);
|
|
|
|
struct mqprio_sched *priv = qdisc_priv(sch);
|
2017-09-07 19:00:06 +08:00
|
|
|
struct nlattr *nla = (struct nlattr *)skb_tail_pointer(skb);
|
2011-01-26 15:21:57 +08:00
|
|
|
struct tc_mqprio_qopt opt = { 0 };
|
2011-01-17 16:06:09 +08:00
|
|
|
struct Qdisc *qdisc;
|
2017-12-08 01:57:39 +08:00
|
|
|
unsigned int ntx, tc;
|
2011-01-17 16:06:09 +08:00
|
|
|
|
|
|
|
sch->q.qlen = 0;
|
2021-10-16 16:49:09 +08:00
|
|
|
gnet_stats_basic_sync_init(&sch->bstats);
|
2011-01-17 16:06:09 +08:00
|
|
|
memset(&sch->qstats, 0, sizeof(sch->qstats));
|
|
|
|
|
2017-12-08 01:57:39 +08:00
|
|
|
/* MQ supports lockless qdiscs. However, statistics accounting needs
|
|
|
|
* to account for all, none, or a mix of locked and unlocked child
|
|
|
|
* qdiscs. Percpu stats are added to counters in-band and locking
|
|
|
|
* qdisc totals are added at end.
|
|
|
|
*/
|
|
|
|
for (ntx = 0; ntx < dev->num_tx_queues; ntx++) {
|
|
|
|
qdisc = netdev_get_tx_queue(dev, ntx)->qdisc_sleeping;
|
2011-01-17 16:06:09 +08:00
|
|
|
spin_lock_bh(qdisc_lock(qdisc));
|
2017-12-08 01:57:39 +08:00
|
|
|
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 16:49:10 +08:00
|
|
|
gnet_stats_add_basic(&sch->bstats, qdisc->cpu_bstats,
|
|
|
|
&qdisc->bstats, false);
|
2021-10-16 16:49:04 +08:00
|
|
|
gnet_stats_add_queue(&sch->qstats, qdisc->cpu_qstats,
|
|
|
|
&qdisc->qstats);
|
|
|
|
sch->q.qlen += qdisc_qlen(qdisc);
|
2017-12-08 01:57:39 +08:00
|
|
|
|
2011-01-17 16:06:09 +08:00
|
|
|
spin_unlock_bh(qdisc_lock(qdisc));
|
|
|
|
}
|
|
|
|
|
|
|
|
opt.num_tc = netdev_get_num_tc(dev);
|
|
|
|
memcpy(opt.prio_tc_map, dev->prio_tc_map, sizeof(opt.prio_tc_map));
|
2017-03-16 01:39:18 +08:00
|
|
|
opt.hw = priv->hw_offload;
|
2011-01-17 16:06:09 +08:00
|
|
|
|
2017-12-08 01:57:39 +08:00
|
|
|
for (tc = 0; tc < netdev_get_num_tc(dev); tc++) {
|
|
|
|
opt.count[tc] = dev->tc_to_txq[tc].count;
|
|
|
|
opt.offset[tc] = dev->tc_to_txq[tc].offset;
|
2011-01-17 16:06:09 +08:00
|
|
|
}
|
|
|
|
|
2019-12-06 21:51:05 +08:00
|
|
|
if (nla_put(skb, TCA_OPTIONS, sizeof(opt), &opt))
|
2017-09-07 19:00:06 +08:00
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
if ((priv->flags & TC_MQPRIO_F_MODE) &&
|
|
|
|
nla_put_u16(skb, TCA_MQPRIO_MODE, priv->mode))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
if ((priv->flags & TC_MQPRIO_F_SHAPER) &&
|
|
|
|
nla_put_u16(skb, TCA_MQPRIO_SHAPER, priv->shaper))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
if ((priv->flags & TC_MQPRIO_F_MIN_RATE ||
|
|
|
|
priv->flags & TC_MQPRIO_F_MAX_RATE) &&
|
|
|
|
(dump_rates(priv, &opt, skb) != 0))
|
2012-03-29 17:11:39 +08:00
|
|
|
goto nla_put_failure;
|
2011-01-17 16:06:09 +08:00
|
|
|
|
2017-09-07 19:00:06 +08:00
|
|
|
return nla_nest_end(skb, nla);
|
2011-01-17 16:06:09 +08:00
|
|
|
nla_put_failure:
|
2017-09-07 19:00:06 +08:00
|
|
|
nlmsg_trim(skb, nla);
|
2011-01-17 16:06:09 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct Qdisc *mqprio_leaf(struct Qdisc *sch, unsigned long cl)
|
|
|
|
{
|
|
|
|
struct netdev_queue *dev_queue = mqprio_queue_get(sch, cl);
|
|
|
|
|
|
|
|
if (!dev_queue)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return dev_queue->qdisc_sleeping;
|
|
|
|
}
|
|
|
|
|
net_sched: remove tc class reference counting
For TC classes, their ->get() and ->put() are always paired, and the
reference counting is completely useless, because:
1) For class modification and dumping paths, we already hold RTNL lock,
so all of these ->get(),->change(),->put() are atomic.
2) For filter bindiing/unbinding, we use other reference counter than
this one, and they should have RTNL lock too.
3) For ->qlen_notify(), it is special because it is called on ->enqueue()
path, but we already hold qdisc tree lock there, and we hold this
tree lock when graft or delete the class too, so it should not be gone
or changed until we release the tree lock.
Therefore, this patch removes ->get() and ->put(), but:
1) Adds a new ->find() to find the pointer to a class by classid, no
refcnt.
2) Move the original class destroy upon the last refcnt into ->delete(),
right after releasing tree lock. This is fine because the class is
already removed from hash when holding the lock.
For those who also use ->put() as ->unbind(), just rename them to reflect
this change.
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-08-25 07:51:29 +08:00
|
|
|
static unsigned long mqprio_find(struct Qdisc *sch, u32 classid)
|
2011-01-17 16:06:09 +08:00
|
|
|
{
|
|
|
|
struct net_device *dev = qdisc_dev(sch);
|
|
|
|
unsigned int ntx = TC_H_MIN(classid);
|
|
|
|
|
2017-10-13 02:38:45 +08:00
|
|
|
/* There are essentially two regions here that have valid classid
|
|
|
|
* values. The first region will have a classid value of 1 through
|
|
|
|
* num_tx_queues. All of these are backed by actual Qdiscs.
|
|
|
|
*/
|
|
|
|
if (ntx < TC_H_MIN_PRIORITY)
|
|
|
|
return (ntx <= dev->num_tx_queues) ? ntx : 0;
|
|
|
|
|
|
|
|
/* The second region represents the hardware traffic classes. These
|
|
|
|
* are represented by classid values of TC_H_MIN_PRIORITY through
|
|
|
|
* TC_H_MIN_PRIORITY + netdev_get_num_tc - 1
|
|
|
|
*/
|
|
|
|
return ((ntx - TC_H_MIN_PRIORITY) < netdev_get_num_tc(dev)) ? ntx : 0;
|
2011-01-17 16:06:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mqprio_dump_class(struct Qdisc *sch, unsigned long cl,
|
|
|
|
struct sk_buff *skb, struct tcmsg *tcm)
|
|
|
|
{
|
2017-10-13 02:38:45 +08:00
|
|
|
if (cl < TC_H_MIN_PRIORITY) {
|
|
|
|
struct netdev_queue *dev_queue = mqprio_queue_get(sch, cl);
|
|
|
|
struct net_device *dev = qdisc_dev(sch);
|
|
|
|
int tc = netdev_txq_to_tc(dev, cl - 1);
|
2011-01-17 16:06:09 +08:00
|
|
|
|
2017-10-13 02:38:45 +08:00
|
|
|
tcm->tcm_parent = (tc < 0) ? 0 :
|
|
|
|
TC_H_MAKE(TC_H_MAJ(sch->handle),
|
|
|
|
TC_H_MIN(tc + TC_H_MIN_PRIORITY));
|
|
|
|
tcm->tcm_info = dev_queue->qdisc_sleeping->handle;
|
|
|
|
} else {
|
2011-01-17 16:06:09 +08:00
|
|
|
tcm->tcm_parent = TC_H_ROOT;
|
|
|
|
tcm->tcm_info = 0;
|
|
|
|
}
|
|
|
|
tcm->tcm_handle |= TC_H_MIN(cl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mqprio_dump_class_stats(struct Qdisc *sch, unsigned long cl,
|
2011-02-23 17:06:51 +08:00
|
|
|
struct gnet_dump *d)
|
|
|
|
__releases(d->lock)
|
|
|
|
__acquires(d->lock)
|
2011-01-17 16:06:09 +08:00
|
|
|
{
|
2017-10-13 02:38:45 +08:00
|
|
|
if (cl >= TC_H_MIN_PRIORITY) {
|
2011-01-17 16:06:09 +08:00
|
|
|
int i;
|
2021-10-16 16:49:04 +08:00
|
|
|
__u32 qlen;
|
2011-01-17 16:06:09 +08:00
|
|
|
struct gnet_stats_queue qstats = {0};
|
2021-10-16 16:49:09 +08:00
|
|
|
struct gnet_stats_basic_sync bstats;
|
2017-10-13 02:38:45 +08:00
|
|
|
struct net_device *dev = qdisc_dev(sch);
|
|
|
|
struct netdev_tc_txq tc = dev->tc_to_txq[cl & TC_BITMASK];
|
2011-01-17 16:06:09 +08:00
|
|
|
|
2021-10-16 16:49:09 +08:00
|
|
|
gnet_stats_basic_sync_init(&bstats);
|
2011-01-17 16:06:09 +08:00
|
|
|
/* Drop lock here it will be reclaimed before touching
|
|
|
|
* statistics this is required because the d->lock we
|
|
|
|
* hold here is the look on dev_queue->qdisc_sleeping
|
|
|
|
* also acquired below.
|
|
|
|
*/
|
2016-06-07 00:37:16 +08:00
|
|
|
if (d->lock)
|
|
|
|
spin_unlock_bh(d->lock);
|
2011-01-17 16:06:09 +08:00
|
|
|
|
|
|
|
for (i = tc.offset; i < tc.offset + tc.count; i++) {
|
2014-09-13 11:04:52 +08:00
|
|
|
struct netdev_queue *q = netdev_get_tx_queue(dev, i);
|
2017-12-08 01:57:39 +08:00
|
|
|
struct Qdisc *qdisc = rtnl_dereference(q->qdisc);
|
2014-09-13 11:04:52 +08:00
|
|
|
|
2011-01-17 16:06:09 +08:00
|
|
|
spin_lock_bh(qdisc_lock(qdisc));
|
2021-10-08 01:49:57 +08:00
|
|
|
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 16:49:10 +08:00
|
|
|
gnet_stats_add_basic(&bstats, qdisc->cpu_bstats,
|
|
|
|
&qdisc->bstats, false);
|
2021-10-16 16:49:04 +08:00
|
|
|
gnet_stats_add_queue(&qstats, qdisc->cpu_qstats,
|
|
|
|
&qdisc->qstats);
|
|
|
|
sch->q.qlen += qdisc_qlen(qdisc);
|
|
|
|
|
2011-01-17 16:06:09 +08:00
|
|
|
spin_unlock_bh(qdisc_lock(qdisc));
|
|
|
|
}
|
2021-10-16 16:49:04 +08:00
|
|
|
qlen = qdisc_qlen(sch) + qstats.qlen;
|
2017-12-08 01:57:39 +08:00
|
|
|
|
2011-01-17 16:06:09 +08:00
|
|
|
/* Reclaim root sleeping lock before completing stats */
|
2016-06-07 00:37:16 +08:00
|
|
|
if (d->lock)
|
|
|
|
spin_lock_bh(d->lock);
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 16:49:10 +08:00
|
|
|
if (gnet_stats_copy_basic(d, NULL, &bstats, false) < 0 ||
|
2014-09-29 02:54:24 +08:00
|
|
|
gnet_stats_copy_queue(d, NULL, &qstats, qlen) < 0)
|
2011-01-17 16:06:09 +08:00
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
struct netdev_queue *dev_queue = mqprio_queue_get(sch, cl);
|
|
|
|
|
|
|
|
sch = dev_queue->qdisc_sleeping;
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 16:49:10 +08:00
|
|
|
if (gnet_stats_copy_basic(d, sch->cpu_bstats,
|
|
|
|
&sch->bstats, true) < 0 ||
|
2019-03-28 23:53:12 +08:00
|
|
|
qdisc_qstats_copy(d, sch) < 0)
|
2011-01-17 16:06:09 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mqprio_walk(struct Qdisc *sch, struct qdisc_walker *arg)
|
|
|
|
{
|
|
|
|
struct net_device *dev = qdisc_dev(sch);
|
|
|
|
unsigned long ntx;
|
|
|
|
|
|
|
|
if (arg->stop)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Walk hierarchy with a virtual class per tc */
|
|
|
|
arg->count = arg->skip;
|
2017-10-13 02:38:45 +08:00
|
|
|
for (ntx = arg->skip; ntx < netdev_get_num_tc(dev); ntx++) {
|
|
|
|
if (arg->fn(sch, ntx + TC_H_MIN_PRIORITY, arg) < 0) {
|
|
|
|
arg->stop = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
arg->count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pad the values and skip over unused traffic classes */
|
|
|
|
if (ntx < TC_MAX_QUEUE) {
|
|
|
|
arg->count = TC_MAX_QUEUE;
|
|
|
|
ntx = TC_MAX_QUEUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset offset, sort out remaining per-queue qdiscs */
|
|
|
|
for (ntx -= TC_MAX_QUEUE; ntx < dev->num_tx_queues; ntx++) {
|
2011-01-17 16:06:09 +08:00
|
|
|
if (arg->fn(sch, ntx + 1, arg) < 0) {
|
|
|
|
arg->stop = 1;
|
2017-10-13 02:38:45 +08:00
|
|
|
return;
|
2011-01-17 16:06:09 +08:00
|
|
|
}
|
|
|
|
arg->count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-17 09:01:25 +08:00
|
|
|
static struct netdev_queue *mqprio_select_queue(struct Qdisc *sch,
|
|
|
|
struct tcmsg *tcm)
|
|
|
|
{
|
|
|
|
return mqprio_queue_get(sch, TC_H_MIN(tcm->tcm_parent));
|
|
|
|
}
|
|
|
|
|
2011-01-17 16:06:09 +08:00
|
|
|
static const struct Qdisc_class_ops mqprio_class_ops = {
|
|
|
|
.graft = mqprio_graft,
|
|
|
|
.leaf = mqprio_leaf,
|
net_sched: remove tc class reference counting
For TC classes, their ->get() and ->put() are always paired, and the
reference counting is completely useless, because:
1) For class modification and dumping paths, we already hold RTNL lock,
so all of these ->get(),->change(),->put() are atomic.
2) For filter bindiing/unbinding, we use other reference counter than
this one, and they should have RTNL lock too.
3) For ->qlen_notify(), it is special because it is called on ->enqueue()
path, but we already hold qdisc tree lock there, and we hold this
tree lock when graft or delete the class too, so it should not be gone
or changed until we release the tree lock.
Therefore, this patch removes ->get() and ->put(), but:
1) Adds a new ->find() to find the pointer to a class by classid, no
refcnt.
2) Move the original class destroy upon the last refcnt into ->delete(),
right after releasing tree lock. This is fine because the class is
already removed from hash when holding the lock.
For those who also use ->put() as ->unbind(), just rename them to reflect
this change.
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-08-25 07:51:29 +08:00
|
|
|
.find = mqprio_find,
|
2011-01-17 16:06:09 +08:00
|
|
|
.walk = mqprio_walk,
|
|
|
|
.dump = mqprio_dump_class,
|
|
|
|
.dump_stats = mqprio_dump_class_stats,
|
2017-10-17 09:01:25 +08:00
|
|
|
.select_queue = mqprio_select_queue,
|
2011-01-17 16:06:09 +08:00
|
|
|
};
|
|
|
|
|
2011-02-23 17:06:51 +08:00
|
|
|
static struct Qdisc_ops mqprio_qdisc_ops __read_mostly = {
|
2011-01-17 16:06:09 +08:00
|
|
|
.cl_ops = &mqprio_class_ops,
|
|
|
|
.id = "mqprio",
|
|
|
|
.priv_size = sizeof(struct mqprio_sched),
|
|
|
|
.init = mqprio_init,
|
|
|
|
.destroy = mqprio_destroy,
|
|
|
|
.attach = mqprio_attach,
|
2021-09-17 21:55:06 +08:00
|
|
|
.change_real_num_tx = mq_change_real_num_tx,
|
2011-01-17 16:06:09 +08:00
|
|
|
.dump = mqprio_dump,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init mqprio_module_init(void)
|
|
|
|
{
|
|
|
|
return register_qdisc(&mqprio_qdisc_ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit mqprio_module_exit(void)
|
|
|
|
{
|
|
|
|
unregister_qdisc(&mqprio_qdisc_ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(mqprio_module_init);
|
|
|
|
module_exit(mqprio_module_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|