Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp866598rwb; Mon, 26 Sep 2022 06:54:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM652r/YzEjk0/h0qTCU8+y7DrdIKLzhq0OamQwCwtn4ClyAR3IDzi89MvogUpjl2bgsK4kt X-Received: by 2002:a17:907:2bcf:b0:772:4b8e:6b29 with SMTP id gv15-20020a1709072bcf00b007724b8e6b29mr17739407ejc.412.1664200495257; Mon, 26 Sep 2022 06:54:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664200495; cv=none; d=google.com; s=arc-20160816; b=yNGwllBRlDxE7jqW7gq6OFEQoAQXlAed+PsRK2XvdKAKnJ5980hnCQAi3+pkMBDH0j QRqwSZuFPuLtewo8p2+uU4F5nyVUU/zYJT7O2Km+adNObV+nyO7hNeqqfvpGoeYc2iP6 DasUF1D6mf4Rlvwj6n8i1e3kHaGs9zTg7RX9YxcQvuWuHuqMXlmpH7bpw9fcF710tadg b6UMAluicm+oTdwsR+V95B+8WlWhbYT89DMJjP5LQtKDjTJ0hyzfJ5AvjXaUMs9TEXJf K5MJgTp/6v1ptnySbHC22pBceZHOHRTV5KMNI+eAFeXPaRi3zhZRIdFfc1zdK4MgMPgQ I4bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xW/yW4t7wa/iNVeRCuw817T96bWWOMGZB9+fQ1oOYUg=; b=GiGFgm0pDMsnG5yQQkopbqW+r3Wf6wAefLiwsD1ROeh1g7yQY9rJEMMc7ibQyC+n9B x7wvq/5PCqxo/hS92A4IthgHVt3swM5Ztx9IDRujBHQBpCRgoW25DLTY2fo+8+RvE/WV lnvAGoh1FxjwvdDQ1IAFBdha3vFNzclpEjiHJeRzWZ7pY2H+pNLL7XxqW+ACTBr0okku pYbiGpTi9HP/bwZ1Hu6sOXYat/Ae4SOdWwlM99WR+FAl3wykFhbNoZZjrRfE9/dKGnbC w2P6UCda/VmDm+hqtvO3rutPrlkd8l8utXevT+rOmeSrsj7wJgmXo6hzDClNPJQ8urGX S7iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="K3vFyDa/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dp14-20020a170906c14e00b0077ea290986fsi16878523ejc.584.2022.09.26.06.54.30; Mon, 26 Sep 2022 06:54:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="K3vFyDa/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236801AbiIZMnN (ORCPT + 99 others); Mon, 26 Sep 2022 08:43:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234300AbiIZMms (ORCPT ); Mon, 26 Sep 2022 08:42:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0A0652DF6; Mon, 26 Sep 2022 04:19:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A9A5B601D2; Mon, 26 Sep 2022 10:31:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FD2CC4314B; Mon, 26 Sep 2022 10:31:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664188295; bh=MQWCacXaiT3sfO+v4HVVkbMllXj95r07jF7oJQLchGc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K3vFyDa/Y/v1KNXG0/yRTws2PLYk3yw3tF2NCfb6gdNrO9twX1MVmrv+pJClEcWPE dl8ji/Mj+6SotSSrmEBFi1mlTPBsc7CQzKu0EPzZeMJIfpaFNJoAtGXtiIdM1A8UsW OuHisTIeiqi2EumkzpiwdfxV4tNiXbrSJUS9nLyk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vladimir Oltean , Vinicius Costa Gomes , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.10 104/141] net/sched: taprio: make qdisc_leaf() see the per-netdev-queue pfifo child qdiscs Date: Mon, 26 Sep 2022 12:12:10 +0200 Message-Id: <20220926100758.204237352@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100754.639112000@linuxfoundation.org> References: <20220926100754.639112000@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vladimir Oltean [ Upstream commit 1461d212ab277d8bba1a753d33e9afe03d81f9d4 ] taprio can only operate as root qdisc, and to that end, there exists the following check in taprio_init(), just as in mqprio: if (sch->parent != TC_H_ROOT) return -EOPNOTSUPP; And indeed, when we try to attach taprio to an mqprio child, it fails as expected: $ tc qdisc add dev swp0 root handle 1: mqprio num_tc 8 \ map 0 1 2 3 4 5 6 7 \ queues 1@0 1@1 1@2 1@3 1@4 1@5 1@6 1@7 hw 0 $ tc qdisc replace dev swp0 parent 1:2 taprio num_tc 8 \ map 0 1 2 3 4 5 6 7 \ queues 1@0 1@1 1@2 1@3 1@4 1@5 1@6 1@7 \ base-time 0 sched-entry S 0x7f 990000 sched-entry S 0x80 100000 \ flags 0x0 clockid CLOCK_TAI Error: sch_taprio: Can only be attached as root qdisc. (extack message added by me) But when we try to attach a taprio child to a taprio root qdisc, surprisingly it doesn't fail: $ tc qdisc replace dev swp0 root handle 1: taprio num_tc 8 \ map 0 1 2 3 4 5 6 7 queues 1@0 1@1 1@2 1@3 1@4 1@5 1@6 1@7 \ base-time 0 sched-entry S 0x7f 990000 sched-entry S 0x80 100000 \ flags 0x0 clockid CLOCK_TAI $ tc qdisc replace dev swp0 parent 1:2 taprio num_tc 8 \ map 0 1 2 3 4 5 6 7 \ queues 1@0 1@1 1@2 1@3 1@4 1@5 1@6 1@7 \ base-time 0 sched-entry S 0x7f 990000 sched-entry S 0x80 100000 \ flags 0x0 clockid CLOCK_TAI This is because tc_modify_qdisc() behaves differently when mqprio is root, vs when taprio is root. In the mqprio case, it finds the parent qdisc through p = qdisc_lookup(dev, TC_H_MAJ(clid)), and then the child qdisc through q = qdisc_leaf(p, clid). This leaf qdisc q has handle 0, so it is ignored according to the comment right below ("It may be default qdisc, ignore it"). As a result, tc_modify_qdisc() goes through the qdisc_create() code path, and this gives taprio_init() a chance to check for sch_parent != TC_H_ROOT and error out. Whereas in the taprio case, the returned q = qdisc_leaf(p, clid) is different. It is not the default qdisc created for each netdev queue (both taprio and mqprio call qdisc_create_dflt() and keep them in a private q->qdiscs[], or priv->qdiscs[], respectively). Instead, taprio makes qdisc_leaf() return the _root_ qdisc, aka itself. When taprio does that, tc_modify_qdisc() goes through the qdisc_change() code path, because the qdisc layer never finds out about the child qdisc of the root. And through the ->change() ops, taprio has no reason to check whether its parent is root or not, just through ->init(), which is not called. The problem is the taprio_leaf() implementation. Even though code wise, it does the exact same thing as mqprio_leaf() which it is copied from, it works with different input data. This is because mqprio does not attach itself (the root) to each device TX queue, but one of the default qdiscs from its private array. In fact, since commit 13511704f8d7 ("net: taprio offload: enforce qdisc to netdev queue mapping"), taprio does this too, but just for the full offload case. So if we tried to attach a taprio child to a fully offloaded taprio root qdisc, it would properly fail too; just not to a software root taprio. To fix the problem, stop looking at the Qdisc that's attached to the TX queue, and instead, always return the default qdiscs that we've allocated (and to which we privately enqueue and dequeue, in software scheduling mode). Since Qdisc_class_ops :: leaf is only called from tc_modify_qdisc(), the risk of unforeseen side effects introduced by this change is minimal. Fixes: 5a781ccbd19e ("tc: Add support for configuring the taprio scheduler") Signed-off-by: Vladimir Oltean Reviewed-by: Vinicius Costa Gomes Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/sched/sch_taprio.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c index 384316c11e98..ab8835a72cee 100644 --- a/net/sched/sch_taprio.c +++ b/net/sched/sch_taprio.c @@ -1906,12 +1906,14 @@ static int taprio_dump(struct Qdisc *sch, struct sk_buff *skb) static struct Qdisc *taprio_leaf(struct Qdisc *sch, unsigned long cl) { - struct netdev_queue *dev_queue = taprio_queue_get(sch, cl); + struct taprio_sched *q = qdisc_priv(sch); + struct net_device *dev = qdisc_dev(sch); + unsigned int ntx = cl - 1; - if (!dev_queue) + if (ntx >= dev->num_tx_queues) return NULL; - return dev_queue->qdisc_sleeping; + return q->qdiscs[ntx]; } static unsigned long taprio_find(struct Qdisc *sch, u32 classid) -- 2.35.1