Commit 3ed38570 authored by David S. Miller's avatar David S. Miller

Merge branch 'net-sched-prepare-for-more-Qdisc-offloads'

Jakub Kicinski says:

====================
net: sched: prepare for more Qdisc offloads

This series refactors the "switchdev" Qdisc offloads a little.  We have
a few Qdiscs which can be fully offloaded today to the forwarding plane
of switching devices.

First patch adds a helper for handing statistic dumps, the code seems
to be copy pasted between PRIO and RED.  Second patch removes unnecessary
parameter from RED offload function.  Third patch makes the MQ offload
use the dump helper which helps it behave much like PRIO and RED when
it comes to the TCQ_F_OFFLOADED flag.  Patch 4 adds a graft helper,
similar to the dump helper.

Patch 5 is unrelated to offloads, qdisc_graft() code seemed ripe for a
small refactor - no functional changes there.

Last two patches move the qdisc_put() call outside of the sch_tree_lock
section for RED and PRIO.  The child Qdiscs will get removed from the
hierarchy under the lock, but having the put (and potentially destroy)
called outside of the lock helps offload which may choose to sleep,
and it should generally lower the Qdisc change impact.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 80b6265c 7b8e0b6e
...@@ -579,6 +579,30 @@ void qdisc_put(struct Qdisc *qdisc); ...@@ -579,6 +579,30 @@ void qdisc_put(struct Qdisc *qdisc);
void qdisc_put_unlocked(struct Qdisc *qdisc); void qdisc_put_unlocked(struct Qdisc *qdisc);
void qdisc_tree_reduce_backlog(struct Qdisc *qdisc, unsigned int n, void qdisc_tree_reduce_backlog(struct Qdisc *qdisc, unsigned int n,
unsigned int len); unsigned int len);
#ifdef CONFIG_NET_SCHED
int qdisc_offload_dump_helper(struct Qdisc *q, enum tc_setup_type type,
void *type_data);
void qdisc_offload_graft_helper(struct net_device *dev, struct Qdisc *sch,
struct Qdisc *new, struct Qdisc *old,
enum tc_setup_type type, void *type_data,
struct netlink_ext_ack *extack);
#else
static inline int
qdisc_offload_dump_helper(struct Qdisc *q, enum tc_setup_type type,
void *type_data)
{
q->flags &= ~TCQ_F_OFFLOADED;
return 0;
}
static inline void
qdisc_offload_graft_helper(struct net_device *dev, struct Qdisc *sch,
struct Qdisc *new, struct Qdisc *old,
enum tc_setup_type type, void *type_data,
struct netlink_ext_ack *extack)
{
}
#endif
struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue, struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
const struct Qdisc_ops *ops, const struct Qdisc_ops *ops,
struct netlink_ext_ack *extack); struct netlink_ext_ack *extack);
......
...@@ -810,6 +810,56 @@ void qdisc_tree_reduce_backlog(struct Qdisc *sch, unsigned int n, ...@@ -810,6 +810,56 @@ void qdisc_tree_reduce_backlog(struct Qdisc *sch, unsigned int n,
} }
EXPORT_SYMBOL(qdisc_tree_reduce_backlog); EXPORT_SYMBOL(qdisc_tree_reduce_backlog);
int qdisc_offload_dump_helper(struct Qdisc *sch, enum tc_setup_type type,
void *type_data)
{
struct net_device *dev = qdisc_dev(sch);
int err;
sch->flags &= ~TCQ_F_OFFLOADED;
if (!tc_can_offload(dev) || !dev->netdev_ops->ndo_setup_tc)
return 0;
err = dev->netdev_ops->ndo_setup_tc(dev, type, type_data);
if (err == -EOPNOTSUPP)
return 0;
if (!err)
sch->flags |= TCQ_F_OFFLOADED;
return err;
}
EXPORT_SYMBOL(qdisc_offload_dump_helper);
void qdisc_offload_graft_helper(struct net_device *dev, struct Qdisc *sch,
struct Qdisc *new, struct Qdisc *old,
enum tc_setup_type type, void *type_data,
struct netlink_ext_ack *extack)
{
bool any_qdisc_is_offloaded;
int err;
if (!tc_can_offload(dev) || !dev->netdev_ops->ndo_setup_tc)
return;
err = dev->netdev_ops->ndo_setup_tc(dev, type, type_data);
/* Don't report error if the graft is part of destroy operation. */
if (!err || !new || new == &noop_qdisc)
return;
/* Don't report error if the parent, the old child and the new
* one are not offloaded.
*/
any_qdisc_is_offloaded = new->flags & TCQ_F_OFFLOADED;
any_qdisc_is_offloaded |= sch && sch->flags & TCQ_F_OFFLOADED;
any_qdisc_is_offloaded |= old && old->flags & TCQ_F_OFFLOADED;
if (any_qdisc_is_offloaded)
NL_SET_ERR_MSG(extack, "Offloading graft operation failed.");
}
EXPORT_SYMBOL(qdisc_offload_graft_helper);
static int tc_fill_qdisc(struct sk_buff *skb, struct Qdisc *q, u32 clid, static int tc_fill_qdisc(struct sk_buff *skb, struct Qdisc *q, u32 clid,
u32 portid, u32 seq, u16 flags, int event) u32 portid, u32 seq, u16 flags, int event)
{ {
...@@ -957,7 +1007,6 @@ static int qdisc_graft(struct net_device *dev, struct Qdisc *parent, ...@@ -957,7 +1007,6 @@ static int qdisc_graft(struct net_device *dev, struct Qdisc *parent,
{ {
struct Qdisc *q = old; struct Qdisc *q = old;
struct net *net = dev_net(dev); struct net *net = dev_net(dev);
int err = 0;
if (parent == NULL) { if (parent == NULL) {
unsigned int i, num_q, ingress; unsigned int i, num_q, ingress;
...@@ -1012,28 +1061,29 @@ static int qdisc_graft(struct net_device *dev, struct Qdisc *parent, ...@@ -1012,28 +1061,29 @@ static int qdisc_graft(struct net_device *dev, struct Qdisc *parent,
dev_activate(dev); dev_activate(dev);
} else { } else {
const struct Qdisc_class_ops *cops = parent->ops->cl_ops; const struct Qdisc_class_ops *cops = parent->ops->cl_ops;
unsigned long cl;
int err;
/* Only support running class lockless if parent is lockless */ /* Only support running class lockless if parent is lockless */
if (new && (new->flags & TCQ_F_NOLOCK) && if (new && (new->flags & TCQ_F_NOLOCK) &&
parent && !(parent->flags & TCQ_F_NOLOCK)) parent && !(parent->flags & TCQ_F_NOLOCK))
new->flags &= ~TCQ_F_NOLOCK; new->flags &= ~TCQ_F_NOLOCK;
err = -EOPNOTSUPP; if (!cops || !cops->graft)
if (cops && cops->graft) { return -EOPNOTSUPP;
unsigned long cl = cops->find(parent, classid);
if (cl) { cl = cops->find(parent, classid);
err = cops->graft(parent, cl, new, &old, if (!cl) {
extack);
} else {
NL_SET_ERR_MSG(extack, "Specified class not found"); NL_SET_ERR_MSG(extack, "Specified class not found");
err = -ENOENT; return -ENOENT;
}
} }
if (!err)
err = cops->graft(parent, cl, new, &old, extack);
if (err)
return err;
notify_and_destroy(net, skb, n, classid, old, new); notify_and_destroy(net, skb, n, classid, old, new);
} }
return err; return 0;
} }
static int qdisc_block_indexes_set(struct Qdisc *sch, struct nlattr **tca, static int qdisc_block_indexes_set(struct Qdisc *sch, struct nlattr **tca,
......
...@@ -38,9 +38,8 @@ static int mq_offload(struct Qdisc *sch, enum tc_mq_command cmd) ...@@ -38,9 +38,8 @@ static int mq_offload(struct Qdisc *sch, enum tc_mq_command cmd)
return dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_QDISC_MQ, &opt); return dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_QDISC_MQ, &opt);
} }
static void mq_offload_stats(struct Qdisc *sch) static int mq_offload_stats(struct Qdisc *sch)
{ {
struct net_device *dev = qdisc_dev(sch);
struct tc_mq_qopt_offload opt = { struct tc_mq_qopt_offload opt = {
.command = TC_MQ_STATS, .command = TC_MQ_STATS,
.handle = sch->handle, .handle = sch->handle,
...@@ -50,8 +49,7 @@ static void mq_offload_stats(struct Qdisc *sch) ...@@ -50,8 +49,7 @@ static void mq_offload_stats(struct Qdisc *sch)
}, },
}; };
if (tc_can_offload(dev) && dev->netdev_ops->ndo_setup_tc) return qdisc_offload_dump_helper(sch, TC_SETUP_QDISC_MQ, &opt);
dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_QDISC_MQ, &opt);
} }
static void mq_destroy(struct Qdisc *sch) static void mq_destroy(struct Qdisc *sch)
...@@ -171,9 +169,8 @@ static int mq_dump(struct Qdisc *sch, struct sk_buff *skb) ...@@ -171,9 +169,8 @@ static int mq_dump(struct Qdisc *sch, struct sk_buff *skb)
spin_unlock_bh(qdisc_lock(qdisc)); spin_unlock_bh(qdisc_lock(qdisc));
} }
mq_offload_stats(sch);
return 0; return mq_offload_stats(sch);
} }
static struct netdev_queue *mq_queue_get(struct Qdisc *sch, unsigned long cl) static struct netdev_queue *mq_queue_get(struct Qdisc *sch, unsigned long cl)
......
...@@ -220,7 +220,6 @@ static int prio_tune(struct Qdisc *sch, struct nlattr *opt, ...@@ -220,7 +220,6 @@ static int prio_tune(struct Qdisc *sch, struct nlattr *opt,
qdisc_tree_reduce_backlog(child, child->q.qlen, qdisc_tree_reduce_backlog(child, child->q.qlen,
child->qstats.backlog); child->qstats.backlog);
qdisc_put(child);
} }
for (i = oldbands; i < q->bands; i++) { for (i = oldbands; i < q->bands; i++) {
...@@ -230,6 +229,9 @@ static int prio_tune(struct Qdisc *sch, struct nlattr *opt, ...@@ -230,6 +229,9 @@ static int prio_tune(struct Qdisc *sch, struct nlattr *opt,
} }
sch_tree_unlock(sch); sch_tree_unlock(sch);
for (i = q->bands; i < oldbands; i++)
qdisc_put(q->queues[i]);
return 0; return 0;
} }
...@@ -251,7 +253,6 @@ static int prio_init(struct Qdisc *sch, struct nlattr *opt, ...@@ -251,7 +253,6 @@ static int prio_init(struct Qdisc *sch, struct nlattr *opt,
static int prio_dump_offload(struct Qdisc *sch) static int prio_dump_offload(struct Qdisc *sch)
{ {
struct net_device *dev = qdisc_dev(sch);
struct tc_prio_qopt_offload hw_stats = { struct tc_prio_qopt_offload hw_stats = {
.command = TC_PRIO_STATS, .command = TC_PRIO_STATS,
.handle = sch->handle, .handle = sch->handle,
...@@ -263,21 +264,8 @@ static int prio_dump_offload(struct Qdisc *sch) ...@@ -263,21 +264,8 @@ static int prio_dump_offload(struct Qdisc *sch)
}, },
}, },
}; };
int err;
sch->flags &= ~TCQ_F_OFFLOADED;
if (!tc_can_offload(dev) || !dev->netdev_ops->ndo_setup_tc)
return 0;
err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_QDISC_PRIO,
&hw_stats);
if (err == -EOPNOTSUPP)
return 0;
if (!err) return qdisc_offload_dump_helper(sch, TC_SETUP_QDISC_PRIO, &hw_stats);
sch->flags |= TCQ_F_OFFLOADED;
return err;
} }
static int prio_dump(struct Qdisc *sch, struct sk_buff *skb) static int prio_dump(struct Qdisc *sch, struct sk_buff *skb)
...@@ -309,43 +297,22 @@ static int prio_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, ...@@ -309,43 +297,22 @@ static int prio_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
{ {
struct prio_sched_data *q = qdisc_priv(sch); struct prio_sched_data *q = qdisc_priv(sch);
struct tc_prio_qopt_offload graft_offload; struct tc_prio_qopt_offload graft_offload;
struct net_device *dev = qdisc_dev(sch);
unsigned long band = arg - 1; unsigned long band = arg - 1;
bool any_qdisc_is_offloaded;
int err;
if (new == NULL) if (new == NULL)
new = &noop_qdisc; new = &noop_qdisc;
*old = qdisc_replace(sch, new, &q->queues[band]); *old = qdisc_replace(sch, new, &q->queues[band]);
if (!tc_can_offload(dev))
return 0;
graft_offload.handle = sch->handle; graft_offload.handle = sch->handle;
graft_offload.parent = sch->parent; graft_offload.parent = sch->parent;
graft_offload.graft_params.band = band; graft_offload.graft_params.band = band;
graft_offload.graft_params.child_handle = new->handle; graft_offload.graft_params.child_handle = new->handle;
graft_offload.command = TC_PRIO_GRAFT; graft_offload.command = TC_PRIO_GRAFT;
err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_QDISC_PRIO, qdisc_offload_graft_helper(qdisc_dev(sch), sch, new, *old,
&graft_offload); TC_SETUP_QDISC_PRIO, &graft_offload,
extack);
/* Don't report error if the graft is part of destroy operation. */
if (err && new != &noop_qdisc) {
/* Don't report error if the parent, the old child and the new
* one are not offloaded.
*/
any_qdisc_is_offloaded = sch->flags & TCQ_F_OFFLOADED;
any_qdisc_is_offloaded |= new->flags & TCQ_F_OFFLOADED;
if (*old)
any_qdisc_is_offloaded |= (*old)->flags &
TCQ_F_OFFLOADED;
if (any_qdisc_is_offloaded)
NL_SET_ERR_MSG(extack, "Offloading graft operation failed.");
}
return 0; return 0;
} }
......
...@@ -193,10 +193,10 @@ static const struct nla_policy red_policy[TCA_RED_MAX + 1] = { ...@@ -193,10 +193,10 @@ static const struct nla_policy red_policy[TCA_RED_MAX + 1] = {
static int red_change(struct Qdisc *sch, struct nlattr *opt, static int red_change(struct Qdisc *sch, struct nlattr *opt,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct Qdisc *old_child = NULL, *child = NULL;
struct red_sched_data *q = qdisc_priv(sch); struct red_sched_data *q = qdisc_priv(sch);
struct nlattr *tb[TCA_RED_MAX + 1]; struct nlattr *tb[TCA_RED_MAX + 1];
struct tc_red_qopt *ctl; struct tc_red_qopt *ctl;
struct Qdisc *child = NULL;
int err; int err;
u32 max_P; u32 max_P;
...@@ -233,7 +233,7 @@ static int red_change(struct Qdisc *sch, struct nlattr *opt, ...@@ -233,7 +233,7 @@ static int red_change(struct Qdisc *sch, struct nlattr *opt,
if (child) { if (child) {
qdisc_tree_reduce_backlog(q->qdisc, q->qdisc->q.qlen, qdisc_tree_reduce_backlog(q->qdisc, q->qdisc->q.qlen,
q->qdisc->qstats.backlog); q->qdisc->qstats.backlog);
qdisc_put(q->qdisc); old_child = q->qdisc;
q->qdisc = child; q->qdisc = child;
} }
...@@ -252,7 +252,11 @@ static int red_change(struct Qdisc *sch, struct nlattr *opt, ...@@ -252,7 +252,11 @@ static int red_change(struct Qdisc *sch, struct nlattr *opt,
red_start_of_idle_period(&q->vars); red_start_of_idle_period(&q->vars);
sch_tree_unlock(sch); sch_tree_unlock(sch);
red_offload(sch, true); red_offload(sch, true);
if (old_child)
qdisc_put(old_child);
return 0; return 0;
} }
...@@ -279,9 +283,8 @@ static int red_init(struct Qdisc *sch, struct nlattr *opt, ...@@ -279,9 +283,8 @@ static int red_init(struct Qdisc *sch, struct nlattr *opt,
return red_change(sch, opt, extack); return red_change(sch, opt, extack);
} }
static int red_dump_offload_stats(struct Qdisc *sch, struct tc_red_qopt *opt) static int red_dump_offload_stats(struct Qdisc *sch)
{ {
struct net_device *dev = qdisc_dev(sch);
struct tc_red_qopt_offload hw_stats = { struct tc_red_qopt_offload hw_stats = {
.command = TC_RED_STATS, .command = TC_RED_STATS,
.handle = sch->handle, .handle = sch->handle,
...@@ -291,22 +294,8 @@ static int red_dump_offload_stats(struct Qdisc *sch, struct tc_red_qopt *opt) ...@@ -291,22 +294,8 @@ static int red_dump_offload_stats(struct Qdisc *sch, struct tc_red_qopt *opt)
.stats.qstats = &sch->qstats, .stats.qstats = &sch->qstats,
}, },
}; };
int err;
sch->flags &= ~TCQ_F_OFFLOADED;
if (!tc_can_offload(dev) || !dev->netdev_ops->ndo_setup_tc) return qdisc_offload_dump_helper(sch, TC_SETUP_QDISC_RED, &hw_stats);
return 0;
err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_QDISC_RED,
&hw_stats);
if (err == -EOPNOTSUPP)
return 0;
if (!err)
sch->flags |= TCQ_F_OFFLOADED;
return err;
} }
static int red_dump(struct Qdisc *sch, struct sk_buff *skb) static int red_dump(struct Qdisc *sch, struct sk_buff *skb)
...@@ -324,7 +313,7 @@ static int red_dump(struct Qdisc *sch, struct sk_buff *skb) ...@@ -324,7 +313,7 @@ static int red_dump(struct Qdisc *sch, struct sk_buff *skb)
}; };
int err; int err;
err = red_dump_offload_stats(sch, &opt); err = red_dump_offload_stats(sch);
if (err) if (err)
goto nla_put_failure; goto nla_put_failure;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment