From patchwork Wed May 31 17:39:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 101558 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3068669vqr; Wed, 31 May 2023 11:00:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4s5Y2V5qCx1ju+pWQ4QrspYqAyCo8lADh/+8ShTiK1PpmX5XZCmQ02cNTZFHKzN7MorqU1 X-Received: by 2002:a05:6a00:aca:b0:64b:43d8:a57d with SMTP id c10-20020a056a000aca00b0064b43d8a57dmr6434588pfl.13.1685556033438; Wed, 31 May 2023 11:00:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1685556033; cv=pass; d=google.com; s=arc-20160816; b=ZG+JOYoi1OiIjeWWrL2tXnuiAQymVuKmkn01VlnxkCDWMcsS5103KCXgPkf+w7Xok+ GqfTvMyNq6aYoTnK0j7LFTcqeE3Y2x/dCHpGLRg42tBhpWoezxdsffFqvSZDC3DQ29eM Kc7juU4j4bTKeuRpw6e4+xGPwmC11TwRS2FZR8ijj1+IxJkLEJUG4qIis8VEJcisSSLP aQAY6Z+xDkMa4x1F1w73uIqj/snZZt/7el2ApdHMWcs1Zh/AKoBkOsi3ThGBmkED/Oq8 Ho5646kMdiZiNHRm/fIu9nAKmRN+QWIthyH8SpfE74/knq1aYSPGnAj/FxDeW4tpdIa1 QYKQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=j2NIe3uM/y4O56qmrtdqLZ6MoKG1xfC+qdNDtgfdlP4=; b=S1p6jkX5RhmaDjJuDEvPQwVi7BnHywwayMX/lAJEN7J05htHMFFEoKcYq5baID025s zRro77DlYVXtig4qK2d6aUBRfQ90PiTUxGYl+/UsPzYmI2if90f5nP0f9xpRtnTdfRQW klCt6sagXMdQUJyP09VfsFprDhBblDHhxyHNOF2rKk7YYNE2ioIMmMRVV7QZruPq2pZ3 byN+0Sb8jOnrz1rdjFCLpBAMFlzDJXkgU23E9ocYuoFSAzSBIj5DDawAb6kSWeXKtnZl PardTURyumhyx1XepFD/X8SDqZDjVDm7/7UXaoqMOWGEUBCiytdVuJk4MzXRP9hBkY3z aOAA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=VGwVRj9b; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); 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=nxp.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q21-20020aa78435000000b006501b3c200bsi467312pfn.57.2023.05.31.11.00.18; Wed, 31 May 2023 11:00:33 -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=@nxp.com header.s=selector2 header.b=VGwVRj9b; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); 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=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230192AbjEaRjx (ORCPT + 99 others); Wed, 31 May 2023 13:39:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229787AbjEaRju (ORCPT ); Wed, 31 May 2023 13:39:50 -0400 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on0615.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0c::615]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61EB1BE; Wed, 31 May 2023 10:39:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bBL5Wq8VZw0Yllvm7nPkv0GnZDf4N+e+G8RaNWlPKlrISDOH2niKqD95f+vBU9V+GsxYGwgGxIWZXBzRr8kXqiEkKDbu/jN8i/xIowYiphrA89biJm+CThjkbS7WKsdIlJLUJ04OnkWy13OKNO/513pTB3hwKs2Rdymv2IErp4lOOu18fnqfLZOI8K2bMNXOooLkgCy1pQ9aK9k/Z96F83FGnerdnt5b7CEhoig2PbvlIXaC3nSBriKXzcK2cmHapkhVBT9egWdliOxNKe26o/gC0zubhJ+WlrP1ZzWi+ZxqK42bewgIYgBp+DeaXsiw796gZKICsodGw3ow9DZ10w== 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=j2NIe3uM/y4O56qmrtdqLZ6MoKG1xfC+qdNDtgfdlP4=; b=OS4KRO/ANrecVJWosNLhbgnVt50sUZIleRu9K+J1NxjLwx5B3vEchtPBnB077eB5DgTiNC3QbBWZUz//QkXH73ZoK2W3ZNnMcm56+4kDO7rHXW5Yk8RDhFZrRNsZ3a6bFat/Kkt/Nu5j/F2opkudi110ZJNReGgG1OmkCErkkGwgUn/P7gfemP+9yLLRmjkoWAbw+TPR6Qdea5ongli694TMH2WvGp4Ge6cVPpQQWlVgjtZcDD/r5JQIWJZ4WcUd3wMH7nqKbELw8sVsxmP1W7Ky+BSzcI/PXu219gtPeB8b25I2f86Pu0761m//X9vQjKgAUu3phbLvAdRne7HZng== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=j2NIe3uM/y4O56qmrtdqLZ6MoKG1xfC+qdNDtgfdlP4=; b=VGwVRj9b7ODhCPzMRHiySbjIqrZgdYDnMptwZgrXxsUf33Lc+8tlNODfaBUBe5lh/keaEFgKpAt6WD0nmUzzPtg6AME8Q3wHHmYcJxNA1BJwgpdoaC0L1TfRBM+t8IzghyDWDiy+vpByQhIXRtjNnkTKTzRZ3TegKUn17wJamEM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by AM9PR04MB8571.eurprd04.prod.outlook.com (2603:10a6:20b:436::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Wed, 31 May 2023 17:39:44 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::47e4:eb1:e83c:fa4a]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::47e4:eb1:e83c:fa4a%4]) with mapi id 15.20.6455.020; Wed, 31 May 2023 17:39:44 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Vinicius Costa Gomes , linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, Muhammad Husaini Zulkifli , Peilin Ye , Pedro Tammela Subject: [PATCH net-next 2/5] net/sched: taprio: keep child Qdisc refcount elevated at 2 in offload mode Date: Wed, 31 May 2023 20:39:25 +0300 Message-Id: <20230531173928.1942027-3-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230531173928.1942027-1-vladimir.oltean@nxp.com> References: <20230531173928.1942027-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VI1PR08CA0104.eurprd08.prod.outlook.com (2603:10a6:800:d3::30) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|AM9PR04MB8571:EE_ X-MS-Office365-Filtering-Correlation-Id: 84939dca-fbd5-4749-1e28-08db61fe054f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MTD2espPGsy94iLpGMzoLEfDb8AwFmUEUCSUj5ua501BOZ7Qz46nLp2gm1ezoC/hBerJolaK0R6ehW5r9/RXyU6KST1RIXJ1E2J6RXjK6moHDM+Lri1M2znXh+Q5bXKBSZdp8lMPSXLP1MaOib0wykBC7rq7BSVAtcZFZZ6H6HCFWCOd287iy/Y+QkJldE4XPudoZ+QZh+zv57XZFHUKTnnZZ8yr6GJQoPRonmKTE0xWLb8cREm6205L1D/K3CenELP3eHWpv6uJh0sAB5tisxGQXKAB+a3qKiWrnuoPsiDTemUqCfsPBE2BvfSQxKreRRzHeIq1vxGuLkCmw4fyphbBwHVCE7MLoIU1smL4dgCbltDMM2KKwfJXB+t9sYWkjYYdlNxojIw/O1zUby0iAwBfl/ZC+32QX0NmfhbY90cCQRpsLuQQyvaVgGYQW2tmxCz9C0XNSuA0xgzEGLHtT2XuxIPc+kmi/L7Woc/MUI/GAiZwWlktIRqas+IUkt6Qhmrh/dJkltRFp2Zch5f4J7dv3QPL0XNpU/sWQvSxFwwuEj7NtUs58VOdx91o6kPg+BHVPyrIqUBRttFCzgGR9myrN3RBZXkI1uHgceTiEvZQpwn0Q5yPl5Qp8u3V+5NXrQ2yDIDO66Wsl2FVj4qcm6pkrMeHeTA0zKjOThNNzCM= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(39860400002)(366004)(136003)(346002)(376002)(451199021)(4326008)(86362001)(38350700002)(38100700002)(478600001)(2616005)(66946007)(66476007)(83380400001)(66556008)(54906003)(6916009)(2906002)(6666004)(1076003)(186003)(26005)(6486002)(6512007)(316002)(52116002)(6506007)(36756003)(41300700001)(7416002)(44832011)(5660300002)(8676002)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gJVJCApdLkGsa+O4MpwSZbYHaRA6l+GaNuIh4UuBYmzv/FkhfblxNdO9hchkp/Kmzhp2aAzKY5R8p2dv4vJvLAy4+FvJR+eerwW9Cbj3V2mk58Tm3Dhi7KBg/fRMiDzrKfVwte0CAz+k3phx1cGSEU7S58rm7kBceJZiyCHI+1yLaxAm6hECDQ7hd7FT3feG+AINdxZ66yhewlTfC0gldETD7qK6c4qyRj7vCpY9Wu7CCxxqh0l+bcAJdXV9x6LibG+d59iJVcosZ0USNfDF1Zt8eGX/6Lj90OCPFz5jSV5nGvE5nZ1KXEzlAT+7O9ZxtjUmuaPLAyh0/H7uLVra+4W9TxqTKrRWA8OeAuOMDc2iW0+QivweTT6hF+LPDc12nZy3cLzQ9qCydRnau/rMD9J9aRC0VhvSr4HGa1jxjWHFTk1KETa8u0tF4isBRs6UZkYPX4BIbB3r4aVN313RV5y1vRtQeMKJlSfMYoI6prVWBefNxmedFE1BAYMOuYVj3BqOPZH0/B1VGbz65QSE7KNJ/3ciO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orOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 84939dca-fbd5-4749-1e28-08db61fe054f X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2023 17:39:44.3423 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3JeTs6GRglSvhlP6QrrA/ZrhIi+PAYP15HzUYIjwR7L9MXljdic11S9Qtcn4TRf62yySjTp9f6PMmTXFjetrLA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8571 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO,SPF_HELO_PASS, T_SCC_BODY_TEXT_LINE,T_SPF_PERMERROR,URIBL_BLOCKED autolearn=no 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767433603404217364?= X-GMAIL-MSGID: =?utf-8?q?1767433603404217364?= The taprio qdisc currently lives in the following equilibrium. In the software scheduling case, taprio attaches itself to all TXQs, thus having a refcount of 1 + the number of TX queues. In this mode, q->qdiscs[] is not visible directly to the Qdisc API. The lifetime of the Qdiscs from this private array lasts until qdisc_destroy() -> taprio_destroy(). In the fully offloaded case, the root taprio has a refcount of 1, and all child q->qdiscs[] also have a refcount of 1. The child q->qdiscs[] are visible to the Qdisc API (they are attached to the netdev TXQs directly), however taprio loses a reference to them very early - during qdisc_graft(parent==NULL) -> taprio_attach(). At that time, taprio frees the q->qdiscs[] array to not leak memory, but interestingly, it does not release a reference on these qdiscs because it doesn't effectively own them - they are created by taprio but owned by the Qdisc core, and will be freed by qdisc_graft(parent==NULL, new==NULL) -> qdisc_put(old) when the Qdisc is deleted or when the child Qdisc is replaced with something else. My interest is to change this equilibrium such that taprio also owns a reference on the q->qdiscs[] child Qdiscs for the lifetime of the root Qdisc, including in full offload mode. I want this because I would like taprio_leaf(), taprio_dump_class(), taprio_dump_class_stats() to have insight into q->qdiscs[] for the software scheduling mode - currently they look at dev_queue->qdisc_sleeping, which is, as mentioned, the same as the root taprio. The following set of changes is necessary: - don't free q->qdiscs[] early in taprio_attach(), free it late in taprio_destroy() for consistency with software mode. But: - currently that's not possible, because taprio doesn't own a reference on q->qdiscs[]. So hold that reference - once during the initial attach() and once during subsequent graft() calls when the child is changed. - always keep track of the current child in q->qdiscs[], even for full offload mode, so that we free in taprio_destroy() what we should, and not something stale. Signed-off-by: Vladimir Oltean --- net/sched/sch_taprio.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c index b1c611c72aa4..8807fc915b79 100644 --- a/net/sched/sch_taprio.c +++ b/net/sched/sch_taprio.c @@ -2138,23 +2138,20 @@ static void taprio_attach(struct Qdisc *sch) qdisc->flags |= TCQ_F_ONETXQUEUE | TCQ_F_NOPARENT; old = dev_graft_qdisc(dev_queue, qdisc); + /* Keep refcount of q->qdiscs[ntx] at 2 */ + qdisc_refcount_inc(qdisc); } else { /* In software mode, attach the root taprio qdisc * to all netdev TX queues, so that dev_qdisc_enqueue() * goes through taprio_enqueue(). */ old = dev_graft_qdisc(dev_queue, sch); + /* Keep root refcount at 1 + num_tx_queues */ qdisc_refcount_inc(sch); } if (old) qdisc_put(old); } - - /* access to the child qdiscs is not needed in offload mode */ - if (FULL_OFFLOAD_IS_ENABLED(q->flags)) { - kfree(q->qdiscs); - q->qdiscs = NULL; - } } static struct netdev_queue *taprio_queue_get(struct Qdisc *sch, @@ -2183,15 +2180,24 @@ static int taprio_graft(struct Qdisc *sch, unsigned long cl, if (dev->flags & IFF_UP) dev_deactivate(dev); - if (FULL_OFFLOAD_IS_ENABLED(q->flags)) { + /* In software mode, the root taprio qdisc is still the one attached to + * all netdev TX queues, and hence responsible for taprio_enqueue() to + * forward the skbs to the child qdiscs from the private q->qdiscs[] + * array. So only attach the new qdisc to the netdev queue in offload + * mode, where the enqueue must bypass taprio. However, save the + * reference to the new qdisc in the private array in both cases, to + * have an up-to-date reference to our children. + */ + if (FULL_OFFLOAD_IS_ENABLED(q->flags)) *old = dev_graft_qdisc(dev_queue, new); - } else { + else *old = q->qdiscs[cl - 1]; - q->qdiscs[cl - 1] = new; - } - if (new) + q->qdiscs[cl - 1] = new; + if (new) { + qdisc_refcount_inc(new); new->flags |= TCQ_F_ONETXQUEUE | TCQ_F_NOPARENT; + } if (dev->flags & IFF_UP) dev_activate(dev);