From patchwork Mon Aug 7 19:33:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13344851 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42DE9171B2 for ; Mon, 7 Aug 2023 19:38:34 +0000 (UTC) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2074.outbound.protection.outlook.com [40.107.104.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A99CD210E; Mon, 7 Aug 2023 12:38:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YqSt/FMT9/09rCOkXl7L6Zwz4BPAQcGj2CHLl2edE5JB6WW4ZxVJ9s0cktBxcuv2F9vA9VMnvEXJ5gyx0xt+O1FUBQoQQqfiuEkqHU5fMyJBkL+6Tj8WgzccbN4SUEC1mYdfdduAUa0yiaLmhfEdB2rDmWSAE43gYthqv7ZwTgGFs7xQ8wRmuRrYC/o5MX9OC9lSh5IK5j/5i2Ou6lPV3aQwtR+Bo46xfYT+7cKcKrTDqYYyCOxIDfjVr+Y2WFMYs2kZrvTogm2LrJwWvqR3VY0VCnoWGbbpR8ewUUakiHF9UgD8fwq+ygsvqdX1y9UD/MaItDI5dxDFCKsWqLTluw== 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=kjrN9GQQoUjes+E+zAVZMFtIhSOlOE/TXQ5ItcnhiRs=; b=bZ2AaD0O/gwxxQOrNChI7oUPSPzSCGWDMYvwLRx+bf+jrlo+9zjMTL+egCu/ZFZFEhlt8R74Jv8z08IGTLqCBNZ8Gq9mNC1VYnDGjwibYD2/0mlRKl+XHMdvnyS4D/mGTxfi9zbuUAnwAxmnPc8OUppGm1YVP30CVtqytnOlQBQno3VfByQWyDVBFq36PHu+v8Z6f4W/G5M6O8V2ZjalVk8OignZgPIgOwquxPCThQsewb1aeRGoUJ9e8zHhs6CGkV743AYecv9iP6vZAzYAejgLPZxpZ98ATIyrxv/HUiOkn1SYQKSyDaVC/VMBgWq7LX/IOdguZdrhh4mLb03Mkg== 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=kjrN9GQQoUjes+E+zAVZMFtIhSOlOE/TXQ5ItcnhiRs=; b=fpg6cjLnJWRinsiD0eVTkgit39rs6ZePoFcCfMyKxpd/+B29btsTsyNVXVJwRgpE8q3CmVzsG98QEUIHI5qBTyvCpm+Nzgkb+MqalrJJBbWMu9nZ8mulk6slQJJBsycNlrRc21lhyPn7IY0lTqu0LAZMUvpGS99KILvM7Q6afz0= 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 DB9PR04MB9451.eurprd04.prod.outlook.com (2603:10a6:10:368::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.26; Mon, 7 Aug 2023 19:37:44 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::d4ed:20a0:8c0a:d9cf]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::d4ed:20a0:8c0a:d9cf%6]) with mapi id 15.20.6652.026; Mon, 7 Aug 2023 19:37: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 , Richard Cochran , Zhengchao Shao , Maxim Georgiev Subject: [PATCH v4 net-next 10/11] selftests/tc-testing: test that taprio can only be attached as root Date: Mon, 7 Aug 2023 22:33:23 +0300 Message-Id: <20230807193324.4128292-11-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230807193324.4128292-1-vladimir.oltean@nxp.com> References: <20230807193324.4128292-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM0PR01CA0136.eurprd01.prod.exchangelabs.com (2603:10a6:208:168::41) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|DB9PR04MB9451:EE_ X-MS-Office365-Filtering-Correlation-Id: 2e2f995f-0551-44d1-7394-08db977dc557 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ayit6om9XjCkI4jDOP5+tqVtf2mvYEiZXfoCQMM5zH8gXlPCkm90HPsV2T10Il6MqQIcSMQj1mgXZuX067xUWJ9s2gJzzV75tP4KMKw9tyd6cEAEtZ4G4+VGJu7Vr7SmoSJ9UWEWnQ9GcXNYxiOzGpEhRvvUUa/bx7F9hQ87e+l+F6SszarswpUe3LNsHUpOpbQf3bQ86w5OxF8SO4nhQ6x3sJZjUU2ZgGd1eNIkdvuWC9E4U09VvRutpjf+nmeNIgJq1Np2bMkzraxWoQBfE8C07a/4mI7FpO/ibbvJYHVDKs4021kwBlI9OS0+t7jqJ+XQSk0iETh73vj0uQaDippVjRwsPCjOeMbVOsqS2InxSmWy7fyDkwIe1yANBfx9YG7Agc+wV8Q5a6OQvlReNOR2yYKAlcERmhMpIUYEju3WKw+d0Nt7IUSw2lf1DcIZPj8ZqEQOryYFm8J+vYoa+F7pTgEmhWoRzbCPFTALucxcJMIPqyZoRUa/CPRtzccjmi5I0v/2r9Nzr2liZRL7eCUqmo5OkX8GdOzeXp6vHQkKdCnDLzc8JbpeamzTsECJICfsdE8ljrf922YTwgoASnUt2Nzt82U3tEMP/ErFC3SdX8SXM4GejN4u+0bITP6M5ITNKhNY3QnDfXgTuCm0DQ== 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)(376002)(39860400002)(346002)(136003)(396003)(366004)(186006)(1800799003)(451199021)(1076003)(41300700001)(26005)(2906002)(5660300002)(44832011)(83380400001)(7416002)(8676002)(8936002)(2616005)(6916009)(86362001)(316002)(6506007)(54906003)(38350700002)(38100700002)(6486002)(66476007)(66556008)(478600001)(52116002)(66946007)(6666004)(6512007)(966005)(4326008)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NiD0/lpznLJfeeRp9ffS8GIpByRidJ6yoRXAMB6yqRshhyp35QsTFTFyRI+Q4AEGU/8qhiVWtfir3wN+/ps3dNPwhTgOywRw0ofRkkrAJorWOin0Xx0FDCgqfG7SmwI8rs06vssaiUlgLcYGxfKBr/XY1fQ6P/LkbcjUzpDV6FzzTh+bhUkevOiz4ZlFkxOSi+fu5WXSmlvj8LyIwOD1z3M2VH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/IveppcRyRLa0XNZnO/MQ7OE5oOvX8sQZw4pdBSEGK2DMMccoKgR3WaNKlSTSQBj4SS22mxsL1bQq+tYyS+P+xheo74kM3HgljWQuNvvQWsoniNUmJAidscrMp9ZbFFSPPRoc/XrZiGWLjdmd4yNBLlTXKXXv/eCZLOw/lrJJ3Y/BNhKfBtHq7JgLUyt9QoTCLNOTVvJk2ssOb9jhfHSde8h94CjBsaGvLwCYlfz2hGQb7l8R/VEZDeGkcg7nC8OlRfpB9S3kG5EQuLLSxF7q9n6dwOYNowXczUeyFogJ0cAZBNdGv5mMP2lfq6ArBd6lCktFMPXg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2e2f995f-0551-44d1-7394-08db977dc557 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2023 19:37:44.1633 (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: YzJnwEa4RkTfP0/vNZSGIT3a/1hwdSuRac7nbKPV7y1hPGxUQt4f9WDaHUINRkL19f+ydPd2+2rFEp64vCrudA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9451 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,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 X-Patchwork-Delegate: kuba@kernel.org Check that the "Can only be attached as root qdisc" error message from taprio is effective by attempting to attach it to a class of another taprio qdisc. That operation should fail. In the bug that was squashed by change "net/sched: taprio: try again to report q->qdiscs[] to qdisc_leaf()", grafting a child taprio to a root software taprio would be misinterpreted as a change() to the root taprio. Catch this by looking at whether the base-time of the root taprio has changed to follow the base-time of the child taprio, something which should have absolutely never happened assuming correct semantics. Vinicius points out that looking at "base_time" in the tc qdisc show output is unreliable because user space is in a race with the kernel applying the setting. So we create a helper bash script which waits while there is any pending schedule. Link: https://lore.kernel.org/netdev/87il9w0xx7.fsf@intel.com/ Signed-off-by: Vladimir Oltean Reviewed-by: Pedro Tammela --- v3->v4: introduce (and use) taprio_wait_for_admin.sh. The test depends upon this taprio patch to work properly: https://patchwork.kernel.org/project/netdevbpf/patch/20230807160827.4087483-2-vladimir.oltean@nxp.com/ Note: I couldn't find a way around the horrible tcmd.safe_substitute(NAMES) and the string quoting (no possibility to perform complex shell operations) than to put the logic I needed in a separate shell script and execute that. v2->v3: none v1->v2: patch is new .../tc-testing/taprio_wait_for_admin.sh | 16 ++++++ .../tc-testing/tc-tests/qdiscs/taprio.json | 50 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100755 tools/testing/selftests/tc-testing/taprio_wait_for_admin.sh diff --git a/tools/testing/selftests/tc-testing/taprio_wait_for_admin.sh b/tools/testing/selftests/tc-testing/taprio_wait_for_admin.sh new file mode 100755 index 000000000000..f5335e8ad6b4 --- /dev/null +++ b/tools/testing/selftests/tc-testing/taprio_wait_for_admin.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +TC="$1"; shift +ETH="$1"; shift + +# The taprio architecture changes the admin schedule from a hrtimer and not +# from process context, so we need to wait in order to make sure that any +# schedule change actually took place. +while :; do + has_admin="$($TC -j qdisc show dev $ETH root | jq '.[].options | has("admin")')" + if [ "$has_admin" = "false" ]; then + break; + fi + + sleep 1 +done diff --git a/tools/testing/selftests/tc-testing/tc-tests/qdiscs/taprio.json b/tools/testing/selftests/tc-testing/tc-tests/qdiscs/taprio.json index 860b55df0d6d..f475967c509f 100644 --- a/tools/testing/selftests/tc-testing/tc-tests/qdiscs/taprio.json +++ b/tools/testing/selftests/tc-testing/tc-tests/qdiscs/taprio.json @@ -156,5 +156,55 @@ "teardown": [ "echo \"1\" > /sys/bus/netdevsim/del_device" ] + }, + { + "id": "39b4", + "name": "Reject grafting taprio as child qdisc of software taprio", + "category": [ + "qdisc", + "taprio" + ], + "plugins": { + "requires": "nsPlugin" + }, + "setup": [ + "echo \"1 1 8\" > /sys/bus/netdevsim/new_device", + "$TC qdisc replace dev $ETH handle 8001: parent root stab overhead 24 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 ff 20000000 clockid CLOCK_TAI", + "./taprio_wait_for_admin.sh $TC $ETH" + ], + "cmdUnderTest": "$TC qdisc replace dev $ETH parent 8001:7 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 200 sched-entry S ff 20000000 clockid CLOCK_TAI", + "expExitCode": "2", + "verifyCmd": "bash -c \"./taprio_wait_for_admin.sh $TC $ETH && $TC -j qdisc show dev $ETH root | jq '.[].options.base_time'\"", + "matchPattern": "0", + "matchCount": "1", + "teardown": [ + "$TC qdisc del dev $ETH root", + "echo \"1\" > /sys/bus/netdevsim/del_device" + ] + }, + { + "id": "e8a1", + "name": "Reject grafting taprio as child qdisc of offloaded taprio", + "category": [ + "qdisc", + "taprio" + ], + "plugins": { + "requires": "nsPlugin" + }, + "setup": [ + "echo \"1 1 8\" > /sys/bus/netdevsim/new_device", + "$TC qdisc replace dev $ETH handle 8001: parent root stab overhead 24 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 ff 20000000 flags 0x2", + "./taprio_wait_for_admin.sh $TC $ETH" + ], + "cmdUnderTest": "$TC qdisc replace dev $ETH parent 8001:7 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 200 sched-entry S ff 20000000 flags 0x2", + "expExitCode": "2", + "verifyCmd": "bash -c \"./taprio_wait_for_admin.sh $TC $ETH && $TC -j qdisc show dev $ETH root | jq '.[].options.base_time'\"", + "matchPattern": "0", + "matchCount": "1", + "teardown": [ + "$TC qdisc del dev $ETH root", + "echo \"1\" > /sys/bus/netdevsim/del_device" + ] } ]