From patchwork Fri Jan 13 00:55:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rahul Rameshbabu X-Patchwork-Id: 13099627 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8C86C54EBE for ; Fri, 13 Jan 2023 00:56:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239204AbjAMA4x (ORCPT ); Thu, 12 Jan 2023 19:56:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234657AbjAMA4v (ORCPT ); Thu, 12 Jan 2023 19:56:51 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2048.outbound.protection.outlook.com [40.107.94.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99BD61C416 for ; Thu, 12 Jan 2023 16:56:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PzWucWZzBAwHIRzgDf7b4GmiyphKl8TUrUEk5dmVaKfLYNurScKexRHNeH9EwX9gfjiosU6dInseAn4bDk5ONjeWOCviemBRunhAe5et2Ao3YudCs1VkEw7nN7T0liFI1IUJGyf0qRabivSztLaVcPUl2Aa5MYVUTgHRQYy8r4EF9fP8hTQEdjvZN1tzy60vqqJy0vRDvNP7eiYtKvRxXO1qyi+5lIveWQrCY1u/2wePPJIT+KFRi7b+MOUje0pM21b9ue2uOK3T6sqz0PUhyA1JzxJD5dnLS89LYBW9FHsLYUyQOSxkG8iQsj2SAtr5rRE5qu3tKEsrwxojVBUEVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YLrqgAMXKSJjgfz/YSWmu2yWm4Ar01e8CQb2lsv4UD4=; b=MFnvBGsHCIAQD3lA0eBaNClDXp6qOplHcCgXoC4O8WN/UBNPqrlPHcK0apEJb5RGZRPAsN8cVGXJUtzzt560PQfNPNqN7cLAW4IDMFO+ehLT/lsIkYYZ8G5y9O2Pw5SZwl2Lw7ep9Jfp0sfqIms6TKiH4pvuzU7ssOaWUBhBF6KdrpMEI2UtjM4xCDgRRY7UOV0Z3hgvEXZHijD/6xnW+GlfxgNpSVrxBn0iPEB0ZEJNGkpysj1woLK6VmII6cLmLgp6e4stAHMKSD0hRwZcBIOcMFjtSrwlvFb5xrYynJ94zFVqr6YyEdRMbELM610n0/1HEYgPuMfQGPOe2YmZjw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YLrqgAMXKSJjgfz/YSWmu2yWm4Ar01e8CQb2lsv4UD4=; b=gbS/kCvQtLBDFlPh9cZQoTsnX68vuFrWTZMleHnRLa9JijdOkG/aw+uY7uFlE4COlzWYQPmc2EORW6VfDq2/uEVi5hDRMwyrJPZMkYNXjtflTf6oiJTjtKJ1X7LB10YJjkr/erYIptWOLwYxirAIp3LVeOqIB3Tvq14cHKwwdLQ/fYrY/xiQz7L7wRb++1tLOCXblZJvj/SACKQXpuKKW9v3t79vyPVC+ohciX2843wXR6D0mDoO3q4yBP1S+Ixd/YcDevRnbMiWWCBVy7qktOtPsuvmiu3NQH1p0dA+TWB3CdAYpRY9BP+VMRuRka/hGQlBA7IGbc8lN7fxZIVJIQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BYAPR12MB2743.namprd12.prod.outlook.com (2603:10b6:a03:61::28) by DS0PR12MB6606.namprd12.prod.outlook.com (2603:10b6:8:d2::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Fri, 13 Jan 2023 00:56:48 +0000 Received: from BYAPR12MB2743.namprd12.prod.outlook.com ([fe80::8031:8093:2f25:f2ab]) by BYAPR12MB2743.namprd12.prod.outlook.com ([fe80::8031:8093:2f25:f2ab%7]) with mapi id 15.20.5986.018; Fri, 13 Jan 2023 00:56:47 +0000 From: Rahul Rameshbabu To: netdev@vger.kernel.org Cc: Tariq Toukan , Gal Pressman , Saeed Mahameed , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Jakub Kicinski , Paolo Abeni , David Miller , Rahul Rameshbabu , Eric Dumazet , Maxim Mikityanskiy Subject: [PATCH net v3] sch_htb: Avoid grafting on htb_destroy_class_offload when destroying htb Date: Thu, 12 Jan 2023 16:55:29 -0800 Message-Id: <20230113005528.302625-1-rrameshbabu@nvidia.com> X-Mailer: git-send-email 2.36.2 X-ClientProxiedBy: SJ0PR13CA0154.namprd13.prod.outlook.com (2603:10b6:a03:2c7::9) To BYAPR12MB2743.namprd12.prod.outlook.com (2603:10b6:a03:61::28) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB2743:EE_|DS0PR12MB6606:EE_ X-MS-Office365-Filtering-Correlation-Id: b0f21628-b395-4cd8-ec13-08daf5010c39 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5tnRblSKio9YgVOP+voi84247wU4Wy0mcN7QYLNCjQtzWUaslwNYZq7cE4KfqSJCwJzM91/kdXkbByLseFMCkRL7t3i+xfbP/gXjUN9kWweuLy9X7Q5nGjbNaaCwDWiVser7TYLowYxWNfSGm2oZPEGqOjvGESfPdVat4btumySHL1zkMI44Pp7V4YHOqCRgM0tcz/yDK+9h7akzYGZEGlpvHlgMh4wEjdhJbRY9Vf0SNkgYN8u2IdWwJ47jcUp5ReVrpnJOrgvjVRl1q2V9uJNDd4Dfz35tJRjg9YG1afupH1yfXrh/S89QSylNuc2gir2zgkzGMBnfwwiYR3aZ+HRoR4CI9stPE4AR3/iiC2MMngHmnMt82XdK8dJ2d5aUlAKO9gj2chDufFN0o+4Ck+clKwtFc+MgtJynho9IOq1ccJTQHZXrEEEF04boNqLLFW4o7iHPtDkAm2x0yficwWtmO+DabRXNMBSHXWGUZ5ewV8uf2ZYFVMp6apwciXtSGefAJdtPaO5dDdkEoWK34aNZK3XlEkN+EtvPGln62Lpdij1JeM8F1x8jgvXGYCVZqDOCUGGBec4W7kSz3ujudUt3cBTFIRhqsmRc3611C5MFK1Fw63OKXuUUSTwuKJS6msZgVYMHcul833EBbd6OFJoEMhWNS0B5BqzeKj/Y/wf62SyCknjOWK6ISsPbHVtbF3Z26xpVW9oS30ufBp1oOFBfL2uu+JI3Ov3K4FZohd8lwNvt6i8Jzc9HjIfNwqe1XebUQndjOdO+0PIPRG6P5g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR12MB2743.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(376002)(136003)(39860400002)(396003)(366004)(451199015)(36756003)(4326008)(66946007)(66556008)(54906003)(6916009)(8676002)(41300700001)(86362001)(66476007)(38100700002)(6666004)(966005)(6486002)(186003)(26005)(6506007)(478600001)(5660300002)(316002)(8936002)(83380400001)(1076003)(2906002)(2616005)(6512007);DIR:OUT;SFP:1101; X-MS-Ex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YLlJxiHclgopNJJKHmQJ4LnPEOJEKniJafIUik3/6pJ4RHQIoQ9aw+RRbBsXwp5YDIlW6g+5UzQZKJnfcyM+Ek7FGnzQGTZt+NZYUkJWQ6uRH7KXBss6arQja8W9UpolmZDQScLIgbl9l4efXOibwk2hAreOECiGo02KU0jzWGLRlMKlnj7hvDAqkX0Rv7YdYSZCdNHmvCIgwh7oVcsIyIzoXbKtx25VtBF+nldGsHoK4RrLVTKHbhXXn3rvpwkQaJq4dRdZifCvRjuwuwy1LZkIQr6vRAxO//vCNMZFRCNqfiqt7t1C3nIbT18jxc2zdR+TUNxfTQ13LBtABLmgNAk5p3I76p9TJ3FGllk6ruLx4rITAKv2ANJkOyEZ6JMPY0g+y1fuCgPjryQ6sWV+ZrzvUKiqed+KMFyafXAJlztpyevX+IOm+ERwjbXwyJhUXwZGzQ40wXad+kCgtPY1OOxnbCCY0ITL2vwWPKbDikB1bE8eVDdcSniN/rprF6ihHvYXqfryHkHblWwRj7vEGuLLBnhPiQUysNo03rdUvm70eg9I/z1m0yS0D8fSeP2PUHgRlXNc8w== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b0f21628-b395-4cd8-ec13-08daf5010c39 X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB2743.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jan 2023 00:56:47.8053 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: F+rIwuf/c65Cwk73hbNyqpvTyHbBbHTHzHD4VzqGom+jAbq/GOXLQDUPFmNRznNilc++fzBZV5FtVSmTXEr9Yg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6606 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Peek at old qdisc and graft only when deleting a leaf class in the htb, rather than when deleting the htb itself. Do not peek at the qdisc of the netdev queue when destroying the htb. The caller may already have grafted a new qdisc that is not part of the htb structure being destroyed. This fix resolves two use cases. 1. Using tc to destroy the htb. - Netdev was being prematurely activated before the htb was fully destroyed. 2. Using tc to replace the htb with another qdisc (which also leads to the htb being destroyed). - Premature netdev activation like previous case. Newly grafted qdisc was also getting accidentally overwritten when destroying the htb. Fixes: d03b195b5aa0 ("sch_htb: Hierarchical QoS hardware offload") Signed-off-by: Rahul Rameshbabu Reviewed-by: Saeed Mahameed Cc: Eric Dumazet Cc: Maxim Mikityanskiy Reviewed-by: Maxim Mikityanskiy Reviewed-by: Jiri Pirko --- Notes: Changelog v2->v3: - Removed NULL assignment to struct Qdisc *old to catch uninitialized usage - Improved code comments based on previous review feedback - Removed WARN_ON(err && destroying) to avoid being triggered when the TC_HTB_LEAF_DEL_LAST_FORCE offload operation is used - Described underlying design errors that caused issues for use cases mentioned in commit message v1->v2: - Added use cases that were triggering relevant issues in commit message net/sched/sch_htb.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c index 2238edece1a4..f46643850df8 100644 --- a/net/sched/sch_htb.c +++ b/net/sched/sch_htb.c @@ -1549,7 +1549,7 @@ static int htb_destroy_class_offload(struct Qdisc *sch, struct htb_class *cl, struct tc_htb_qopt_offload offload_opt; struct netdev_queue *dev_queue; struct Qdisc *q = cl->leaf.q; - struct Qdisc *old = NULL; + struct Qdisc *old; int err; if (cl->level) @@ -1557,14 +1557,17 @@ static int htb_destroy_class_offload(struct Qdisc *sch, struct htb_class *cl, WARN_ON(!q); dev_queue = htb_offload_get_queue(cl); - old = htb_graft_helper(dev_queue, NULL); - if (destroying) - /* Before HTB is destroyed, the kernel grafts noop_qdisc to - * all queues. + /* When destroying, caller qdisc_graft grafts the new qdisc and invokes + * qdisc_put for the qdisc being destroyed. htb_destroy_class_offload + * does not need to graft or qdisc_put the qdisc being destroyed. + */ + if (!destroying) { + old = htb_graft_helper(dev_queue, NULL); + /* Last qdisc grafted should be the same as cl->leaf.q when + * calling htb_delete. */ - WARN_ON(!(old->flags & TCQ_F_BUILTIN)); - else WARN_ON(old != q); + } if (cl->parent) { _bstats_update(&cl->parent->bstats_bias, @@ -1581,10 +1584,12 @@ static int htb_destroy_class_offload(struct Qdisc *sch, struct htb_class *cl, }; err = htb_offload(qdisc_dev(sch), &offload_opt); - if (!err || destroying) - qdisc_put(old); - else - htb_graft_helper(dev_queue, old); + if (!destroying) { + if (!err) + qdisc_put(old); + else + htb_graft_helper(dev_queue, old); + } if (last_child) return err;