]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: sched: rename qdisc_destroy() to qdisc_put()
authorVlad Buslov <vladbu@mellanox.com>
Fri, 10 Dec 2021 10:47:26 +0000 (10:47 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 14 Dec 2021 09:18:04 +0000 (10:18 +0100)
[ Upstream commit 86bd446b5cebd783187ea3772ff258210de77d99 ]

Current implementation of qdisc_destroy() decrements Qdisc reference
counter and only actually destroy Qdisc if reference counter value reached
zero. Rename qdisc_destroy() to qdisc_put() in order for it to better
describe the way in which this function currently implemented and used.

Extract code that deallocates Qdisc into new private qdisc_destroy()
function. It is intended to be shared between regular qdisc_put() and its
unlocked version that is introduced in next patch in this series.

Signed-off-by: Vlad Buslov <vladbu@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
[Lee: Sent to Stable]
Link: https://syzkaller.appspot.com/bug?id=d7e411c5472dd5da33d8cc921ccadc747743a568
Reported-by: syzbot+5f229e48cccc804062c0@syzkaller.appspotmail.com
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
20 files changed:
include/net/sch_generic.h
net/sched/sch_api.c
net/sched/sch_atm.c
net/sched/sch_cbq.c
net/sched/sch_cbs.c
net/sched/sch_drr.c
net/sched/sch_dsmark.c
net/sched/sch_fifo.c
net/sched/sch_generic.c
net/sched/sch_hfsc.c
net/sched/sch_htb.c
net/sched/sch_mq.c
net/sched/sch_mqprio.c
net/sched/sch_multiq.c
net/sched/sch_netem.c
net/sched/sch_prio.c
net/sched/sch_qfq.c
net/sched/sch_red.c
net/sched/sch_sfb.c
net/sched/sch_tbf.c

index 286bc674a6e79f508dbfbdefb47d78146b0ef10c..70dfbd0437530d122a09d326e360b3e601a9d8c8 100644 (file)
@@ -559,7 +559,7 @@ void dev_deactivate_many(struct list_head *head);
 struct Qdisc *dev_graft_qdisc(struct netdev_queue *dev_queue,
                              struct Qdisc *qdisc);
 void qdisc_reset(struct Qdisc *qdisc);
-void qdisc_destroy(struct Qdisc *qdisc);
+void qdisc_put(struct Qdisc *qdisc);
 void qdisc_tree_reduce_backlog(struct Qdisc *qdisc, unsigned int n,
                               unsigned int len);
 struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
index 0bb4f7a94a3c84d908b388cf5f1e40097125b200..60f40a396a039f20c6f455c55aa6711206ed764a 100644 (file)
@@ -928,7 +928,7 @@ static void notify_and_destroy(struct net *net, struct sk_buff *skb,
                qdisc_notify(net, skb, n, clid, old, new);
 
        if (old)
-               qdisc_destroy(old);
+               qdisc_put(old);
 }
 
 /* Graft qdisc "new" to class "classid" of qdisc "parent" or
@@ -981,7 +981,7 @@ static int qdisc_graft(struct net_device *dev, struct Qdisc *parent,
                                qdisc_refcount_inc(new);
 
                        if (!ingress)
-                               qdisc_destroy(old);
+                               qdisc_put(old);
                }
 
 skip:
@@ -1589,7 +1589,7 @@ graft:
        err = qdisc_graft(dev, p, skb, n, clid, q, NULL, extack);
        if (err) {
                if (q)
-                       qdisc_destroy(q);
+                       qdisc_put(q);
                return err;
        }
 
index 91bd5c8393036e9c23fb161e150a98b06387ad0a..9a1bfa13a6cd6fdac5ba8f52aa0518f694610650 100644 (file)
@@ -150,7 +150,7 @@ static void atm_tc_put(struct Qdisc *sch, unsigned long cl)
        pr_debug("atm_tc_put: destroying\n");
        list_del_init(&flow->list);
        pr_debug("atm_tc_put: qdisc %p\n", flow->q);
-       qdisc_destroy(flow->q);
+       qdisc_put(flow->q);
        tcf_block_put(flow->block);
        if (flow->sock) {
                pr_debug("atm_tc_put: f_count %ld\n",
index bc62e1b246539a9acffc175dbf1b735e29a04f2f..0a76ad05e5ae58cb988fbbe5e951b0a48e352b3e 100644 (file)
@@ -1439,7 +1439,7 @@ static void cbq_destroy_class(struct Qdisc *sch, struct cbq_class *cl)
        WARN_ON(cl->filters);
 
        tcf_block_put(cl->block);
-       qdisc_destroy(cl->q);
+       qdisc_put(cl->q);
        qdisc_put_rtab(cl->R_tab);
        gen_kill_estimator(&cl->rate_est);
        if (cl != &q->link)
index d5e22452d597682fb491697c760720eb57724523..f95dc899e989ad7e1315dadadb60ca8e6665ffd6 100644 (file)
@@ -452,7 +452,7 @@ static void cbs_destroy(struct Qdisc *sch)
        cbs_disable_offload(dev, q);
 
        if (q->qdisc)
-               qdisc_destroy(q->qdisc);
+               qdisc_put(q->qdisc);
 }
 
 static int cbs_dump(struct Qdisc *sch, struct sk_buff *skb)
index e0b0cf8a993933b06adeeec8798b44fbe9e9cb90..cdebaed0f8cfdc79a4f4902b2d211d03f4b1ff27 100644 (file)
@@ -134,7 +134,7 @@ static int drr_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
                                            tca[TCA_RATE]);
                if (err) {
                        NL_SET_ERR_MSG(extack, "Failed to replace estimator");
-                       qdisc_destroy(cl->qdisc);
+                       qdisc_put(cl->qdisc);
                        kfree(cl);
                        return err;
                }
@@ -153,7 +153,7 @@ static int drr_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
 static void drr_destroy_class(struct Qdisc *sch, struct drr_class *cl)
 {
        gen_kill_estimator(&cl->rate_est);
-       qdisc_destroy(cl->qdisc);
+       qdisc_put(cl->qdisc);
        kfree(cl);
 }
 
index fe030af9272c4e22b4dbf03ff4590d529c55aa02..47a61689dadbc0e64fc7d64388258afb924981b9 100644 (file)
@@ -415,7 +415,7 @@ static void dsmark_destroy(struct Qdisc *sch)
        pr_debug("%s(sch %p,[qdisc %p])\n", __func__, sch, p);
 
        tcf_block_put(p->block);
-       qdisc_destroy(p->q);
+       qdisc_put(p->q);
        if (p->mv != p->embedded)
                kfree(p->mv);
 }
index bcd3ca97caea16ca54752ba65b869c5abe6f82ab..3697cd79976783f531f785aef5b0fdd495a5da96 100644 (file)
@@ -180,7 +180,7 @@ struct Qdisc *fifo_create_dflt(struct Qdisc *sch, struct Qdisc_ops *ops,
        if (q) {
                err = fifo_set_limit(q, limit);
                if (err < 0) {
-                       qdisc_destroy(q);
+                       qdisc_put(q);
                        q = NULL;
                }
        }
index 2128b77d5cb33c49db4ebee3e6ffa4001b44d61c..6fee2731b4c22f936b59532f5ac1f92a7de8ca18 100644 (file)
@@ -918,7 +918,7 @@ struct Qdisc *qdisc_create_dflt(struct netdev_queue *dev_queue,
        if (!ops->init || ops->init(sch, NULL, extack) == 0)
                return sch;
 
-       qdisc_destroy(sch);
+       qdisc_put(sch);
        return NULL;
 }
 EXPORT_SYMBOL(qdisc_create_dflt);
@@ -958,7 +958,7 @@ void qdisc_free(struct Qdisc *qdisc)
        kfree((char *) qdisc - qdisc->padded);
 }
 
-void qdisc_destroy(struct Qdisc *qdisc)
+static void qdisc_destroy(struct Qdisc *qdisc)
 {
        const struct Qdisc_ops *ops;
        struct sk_buff *skb, *tmp;
@@ -967,10 +967,6 @@ void qdisc_destroy(struct Qdisc *qdisc)
                return;
        ops = qdisc->ops;
 
-       if (qdisc->flags & TCQ_F_BUILTIN ||
-           !refcount_dec_and_test(&qdisc->refcnt))
-               return;
-
 #ifdef CONFIG_NET_SCHED
        qdisc_hash_del(qdisc);
 
@@ -997,7 +993,16 @@ void qdisc_destroy(struct Qdisc *qdisc)
 
        qdisc_free(qdisc);
 }
-EXPORT_SYMBOL(qdisc_destroy);
+
+void qdisc_put(struct Qdisc *qdisc)
+{
+       if (qdisc->flags & TCQ_F_BUILTIN ||
+           !refcount_dec_and_test(&qdisc->refcnt))
+               return;
+
+       qdisc_destroy(qdisc);
+}
+EXPORT_SYMBOL(qdisc_put);
 
 /* Attach toplevel qdisc to device queue. */
 struct Qdisc *dev_graft_qdisc(struct netdev_queue *dev_queue,
@@ -1318,7 +1323,7 @@ static void shutdown_scheduler_queue(struct net_device *dev,
                rcu_assign_pointer(dev_queue->qdisc, qdisc_default);
                dev_queue->qdisc_sleeping = qdisc_default;
 
-               qdisc_destroy(qdisc);
+               qdisc_put(qdisc);
        }
 }
 
@@ -1327,7 +1332,7 @@ void dev_shutdown(struct net_device *dev)
        netdev_for_each_tx_queue(dev, shutdown_scheduler_queue, &noop_qdisc);
        if (dev_ingress_queue(dev))
                shutdown_scheduler_queue(dev, dev_ingress_queue(dev), &noop_qdisc);
-       qdisc_destroy(dev->qdisc);
+       qdisc_put(dev->qdisc);
        dev->qdisc = &noop_qdisc;
 
        WARN_ON(timer_pending(&dev->watchdog_timer));
index 3278a76f6861576ba7e42cf9f91a62f96443cb3a..b18ec1f6de60cf584f8a2f421c5cbabfca188ff1 100644 (file)
@@ -1092,7 +1092,7 @@ hfsc_destroy_class(struct Qdisc *sch, struct hfsc_class *cl)
        struct hfsc_sched *q = qdisc_priv(sch);
 
        tcf_block_put(cl->block);
-       qdisc_destroy(cl->qdisc);
+       qdisc_put(cl->qdisc);
        gen_kill_estimator(&cl->rate_est);
        if (cl != &q->root)
                kfree(cl);
index 43c4bfe625a917e1447b08f1875351f8d22ec2c8..862a33b9e2e0f25b7040f0056506480e1d8625a4 100644 (file)
@@ -1224,7 +1224,7 @@ static void htb_destroy_class(struct Qdisc *sch, struct htb_class *cl)
 {
        if (!cl->level) {
                WARN_ON(!cl->un.leaf.q);
-               qdisc_destroy(cl->un.leaf.q);
+               qdisc_put(cl->un.leaf.q);
        }
        gen_kill_estimator(&cl->rate_est);
        tcf_block_put(cl->block);
@@ -1425,7 +1425,7 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
                        /* turn parent into inner node */
                        qdisc_reset(parent->un.leaf.q);
                        qdisc_tree_reduce_backlog(parent->un.leaf.q, qlen, backlog);
-                       qdisc_destroy(parent->un.leaf.q);
+                       qdisc_put(parent->un.leaf.q);
                        if (parent->prio_activity)
                                htb_deactivate(q, parent);
 
index 699b6bb444ceaa1e3c764190db578048478e2614..0ab13a495af959338a0d451600da1c0f04c8a42d 100644 (file)
@@ -65,7 +65,7 @@ static void mq_destroy(struct Qdisc *sch)
        if (!priv->qdiscs)
                return;
        for (ntx = 0; ntx < dev->num_tx_queues && priv->qdiscs[ntx]; ntx++)
-               qdisc_destroy(priv->qdiscs[ntx]);
+               qdisc_put(priv->qdiscs[ntx]);
        kfree(priv->qdiscs);
 }
 
@@ -119,7 +119,7 @@ static void mq_attach(struct Qdisc *sch)
                qdisc = priv->qdiscs[ntx];
                old = dev_graft_qdisc(qdisc->dev_queue, qdisc);
                if (old)
-                       qdisc_destroy(old);
+                       qdisc_put(old);
 #ifdef CONFIG_NET_SCHED
                if (ntx < dev->real_num_tx_queues)
                        qdisc_hash_add(qdisc, false);
index 3fd0e5dd7ae3ed39a37f42c097e348fc1dc7e49b..64d7f876d7de23b135673501d9994365591febb0 100644 (file)
@@ -40,7 +40,7 @@ static void mqprio_destroy(struct Qdisc *sch)
                for (ntx = 0;
                     ntx < dev->num_tx_queues && priv->qdiscs[ntx];
                     ntx++)
-                       qdisc_destroy(priv->qdiscs[ntx]);
+                       qdisc_put(priv->qdiscs[ntx]);
                kfree(priv->qdiscs);
        }
 
@@ -300,7 +300,7 @@ static void mqprio_attach(struct Qdisc *sch)
                qdisc = priv->qdiscs[ntx];
                old = dev_graft_qdisc(qdisc->dev_queue, qdisc);
                if (old)
-                       qdisc_destroy(old);
+                       qdisc_put(old);
                if (ntx < dev->real_num_tx_queues)
                        qdisc_hash_add(qdisc, false);
        }
index 1df78e361ef9473b3bcdb45b28c577d497639757..1c2f9a3ab1ca704eade5966785363ae16e73649f 100644 (file)
@@ -175,7 +175,7 @@ multiq_destroy(struct Qdisc *sch)
 
        tcf_block_put(q->block);
        for (band = 0; band < q->bands; band++)
-               qdisc_destroy(q->queues[band]);
+               qdisc_put(q->queues[band]);
 
        kfree(q->queues);
 }
@@ -204,7 +204,7 @@ static int multiq_tune(struct Qdisc *sch, struct nlattr *opt,
                        q->queues[i] = &noop_qdisc;
                        qdisc_tree_reduce_backlog(child, child->q.qlen,
                                                  child->qstats.backlog);
-                       qdisc_destroy(child);
+                       qdisc_put(child);
                }
        }
 
@@ -228,7 +228,7 @@ static int multiq_tune(struct Qdisc *sch, struct nlattr *opt,
                                        qdisc_tree_reduce_backlog(old,
                                                                  old->q.qlen,
                                                                  old->qstats.backlog);
-                                       qdisc_destroy(old);
+                                       qdisc_put(old);
                                }
                                sch_tree_unlock(sch);
                        }
index 02d8d3fd84a5cb211e64cba0014f880db47ed1c0..ad400f4f9a2d620cea783003d732f6151765481a 100644 (file)
@@ -1054,7 +1054,7 @@ static void netem_destroy(struct Qdisc *sch)
 
        qdisc_watchdog_cancel(&q->watchdog);
        if (q->qdisc)
-               qdisc_destroy(q->qdisc);
+               qdisc_put(q->qdisc);
        dist_free(q->delay_dist);
        dist_free(q->slot_dist);
 }
index 1cbbd8c31405bd4b7fe95de71f58e58b641a915c..0e6f34bd9a683725f568f6485df4314f2c9a32ab 100644 (file)
@@ -175,7 +175,7 @@ prio_destroy(struct Qdisc *sch)
        tcf_block_put(q->block);
        prio_offload(sch, NULL);
        for (prio = 0; prio < q->bands; prio++)
-               qdisc_destroy(q->queues[prio]);
+               qdisc_put(q->queues[prio]);
 }
 
 static int prio_tune(struct Qdisc *sch, struct nlattr *opt,
@@ -205,7 +205,7 @@ static int prio_tune(struct Qdisc *sch, struct nlattr *opt,
                                              extack);
                if (!queues[i]) {
                        while (i > oldbands)
-                               qdisc_destroy(queues[--i]);
+                               qdisc_put(queues[--i]);
                        return -ENOMEM;
                }
        }
@@ -220,7 +220,7 @@ static int prio_tune(struct Qdisc *sch, struct nlattr *opt,
 
                qdisc_tree_reduce_backlog(child, child->q.qlen,
                                          child->qstats.backlog);
-               qdisc_destroy(child);
+               qdisc_put(child);
        }
 
        for (i = oldbands; i < q->bands; i++) {
index a93402fe1a9f8f4161be8dd4b96b13ef13449453..fa6ad95fb6fb4f88132f77696dd7b8c023611a95 100644 (file)
@@ -524,7 +524,7 @@ set_change_agg:
        return 0;
 
 destroy_class:
-       qdisc_destroy(cl->qdisc);
+       qdisc_put(cl->qdisc);
        kfree(cl);
        return err;
 }
@@ -535,7 +535,7 @@ static void qfq_destroy_class(struct Qdisc *sch, struct qfq_class *cl)
 
        qfq_rm_from_agg(q, cl);
        gen_kill_estimator(&cl->rate_est);
-       qdisc_destroy(cl->qdisc);
+       qdisc_put(cl->qdisc);
        kfree(cl);
 }
 
index e42f890fa1478e0ffa9dbe19bdde1d4b32e6670f..0424aa747c341ca49f164355774c0a6b8e555b82 100644 (file)
@@ -181,7 +181,7 @@ static void red_destroy(struct Qdisc *sch)
 
        del_timer_sync(&q->adapt_timer);
        red_offload(sch, false);
-       qdisc_destroy(q->qdisc);
+       qdisc_put(q->qdisc);
 }
 
 static const struct nla_policy red_policy[TCA_RED_MAX + 1] = {
@@ -236,7 +236,7 @@ static int red_change(struct Qdisc *sch, struct nlattr *opt,
        if (child) {
                qdisc_tree_reduce_backlog(q->qdisc, q->qdisc->q.qlen,
                                          q->qdisc->qstats.backlog);
-               qdisc_destroy(q->qdisc);
+               qdisc_put(q->qdisc);
                q->qdisc = child;
        }
 
index 1aa95e761671e9d5d376b4fe4b503263f0f42714..81d205acb1b6aafcd41bc4dcc344711f4ae82dc8 100644 (file)
@@ -470,7 +470,7 @@ static void sfb_destroy(struct Qdisc *sch)
        struct sfb_sched_data *q = qdisc_priv(sch);
 
        tcf_block_put(q->block);
-       qdisc_destroy(q->qdisc);
+       qdisc_put(q->qdisc);
 }
 
 static const struct nla_policy sfb_policy[TCA_SFB_MAX + 1] = {
@@ -524,7 +524,7 @@ static int sfb_change(struct Qdisc *sch, struct nlattr *opt,
 
        qdisc_tree_reduce_backlog(q->qdisc, q->qdisc->q.qlen,
                                  q->qdisc->qstats.backlog);
-       qdisc_destroy(q->qdisc);
+       qdisc_put(q->qdisc);
        q->qdisc = child;
 
        q->rehash_interval = msecs_to_jiffies(ctl->rehash_interval);
index 6f74a426f159e440f33755e13656c849408bbc18..dd29de1418b76adbc5d5cc742809807b57eb9de9 100644 (file)
@@ -392,7 +392,7 @@ static int tbf_change(struct Qdisc *sch, struct nlattr *opt,
        if (child) {
                qdisc_tree_reduce_backlog(q->qdisc, q->qdisc->q.qlen,
                                          q->qdisc->qstats.backlog);
-               qdisc_destroy(q->qdisc);
+               qdisc_put(q->qdisc);
                q->qdisc = child;
        }
        q->limit = qopt->limit;
@@ -438,7 +438,7 @@ static void tbf_destroy(struct Qdisc *sch)
        struct tbf_sched_data *q = qdisc_priv(sch);
 
        qdisc_watchdog_cancel(&q->watchdog);
-       qdisc_destroy(q->qdisc);
+       qdisc_put(q->qdisc);
 }
 
 static int tbf_dump(struct Qdisc *sch, struct sk_buff *skb)