From patchwork Mon May 27 15:39:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 799339 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2059.outbound.protection.outlook.com [40.107.7.59]) (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 7380A17E919; Mon, 27 May 2024 15:40:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.7.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716824419; cv=fail; b=HFyFzUYAjrpnFkyVDESeB6CEs3Ch5KN0I/9SwN2Wb2/IamTOZFL+XpaaWR6ysm+NNfsg4y6la0k9Al+RhcBXzEOm0WAmuEFddzvi1HVWYlXPLX5G8TRMjKOjBjEFGPjZHVmTIZDMcio28XwHBxXrvn511z3OfAlxc6MU3ySptFw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716824419; c=relaxed/simple; bh=m/wkENAXXx6u1PI5bg2VtZGzw68HESibN8Zkx23L8C4=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=WBJnrNEelrzuZUlevqB2+QMKm4i4fgPM0EXgcg9FxC7syX75U27s8bS8yLGNN/PMUXDqjNJK/YPMFEuagz17VNI7TwByUxKR4rZA2Zi7GS110KBwnaJ/3r723cV1yHNxY8nBTHvrNIdC1g89Ygb007MsiXsHbdPp9f1N6q9QIJw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b=INTejVd3; arc=fail smtp.client-ip=40.107.7.59 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="INTejVd3" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q8IWmw8MRU/CGubOmQci9ELDwGfGoanxnsrugtidcni91FwWqlMHMdyGrPbsM6UcGqJfE7nBPoQap6N+3wQWp+PSwrALFTvQfUvftsDZmud1kEbJ5MtseoF7235kcwmVGDxDe30nYok/H14G85Aq0D4dQpgn6YLGt2Ot9ykVHK65MwCrL38e7pijyrvh7ErlSP5L39xBisA4dHOXTc2tGHaM9SdQshdHxJdd6D4vP+q06dkXriZmVGmbQWSoVaSlWWl7ZYoAyES4Vx68VTcHI3FujshjRH/3qUO3zz0Q3wuAcVwy/FIOTawl8nhzMVXO5/DZPQApKox60dubQGeXRQ== 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=wT4tNKXB+u3mQBtVjwjrKpUly0ew9Nb94YgWxVvtcVM=; b=LAlgg3oarS4LUB9lS6Tzbybz4GwZe5pnAM0UoaMT/TKJKafPQ4RChiSWGoVdcxYOUY3ScbJOMAjA55ksEtD3hDSZsJWz04JRumqweDcCpdMDEHX8QLA7H6QCnqHtpf6En11eFEbErzvfDrYZ9oEHbbM0FgNBl7d9eEduK9VW/tYLms3c6sCqqKLq0nIOXI8MbeHZfmdcXSR4nug8b722IWpLcEdjyoJcYKEV464gWTzxsQtzeEvZSHfwsZkyGD91i1cbrE/lw4yu2ij4QubiSwIV3/wRsAH4EnPWqev/WzdIYqAV/YoebNvRMfITy1hZPaCCj8qIOviBCYDGz5ClSA== 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=wT4tNKXB+u3mQBtVjwjrKpUly0ew9Nb94YgWxVvtcVM=; b=INTejVd32ar5kNd6+NiJdCa/Sq5r+IbrKqHXOsLoIT/Cm0HaoClodOjQ5zwHBErlbAEOCchWdJfY6hq1hifbrwFJPD1se5l4oDP5dtn8OiNyY29ebB770VSAsOtotmC1StAI8ybiQ/YS47zR05I+fHuchGroqnP0XA9u4cCP8bI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB7PR04MB4555.eurprd04.prod.outlook.com (2603:10a6:5:33::26) by DB9PR04MB9961.eurprd04.prod.outlook.com (2603:10a6:10:4ee::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.29; Mon, 27 May 2024 15:40:14 +0000 Received: from DB7PR04MB4555.eurprd04.prod.outlook.com ([fe80::86ff:def:c14a:a72a]) by DB7PR04MB4555.eurprd04.prod.outlook.com ([fe80::86ff:def:c14a:a72a%7]) with mapi id 15.20.7611.025; Mon, 27 May 2024 15:40:13 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: linux-kselftest@vger.kernel.org, Vinicius Costa Gomes , Jamal Hadi Salim , Cong Wang , Jiri Pirko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan , Pedro Tammela Subject: [PATCH net 1/2] net/sched: taprio: make q->picos_per_byte available to fill_sched_entry() Date: Mon, 27 May 2024 18:39:54 +0300 Message-Id: <20240527153955.553333-1-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: VI1PR06CA0116.eurprd06.prod.outlook.com (2603:10a6:803:8c::45) To DB7PR04MB4555.eurprd04.prod.outlook.com (2603:10a6:5:33::26) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4555:EE_|DB9PR04MB9961:EE_ X-MS-Office365-Filtering-Correlation-Id: c3f85d8a-b7cf-47fa-703c-08dc7e634ce6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|376005|366007|1800799015|52116005|7416005|38350700005; X-Microsoft-Antispam-Message-Info: vtl2jXZI1c80IN4ixF6XH/x6IcTSyYr9Lm73Wfh+JEOtpXOWYKVpMpQ4b1mopO6TOnGAFuq32YXFedSlZ1x3rhJ6xSCkSwJrKaOnKW0QEpkWfLR0sD1WsH1FaDhi4ShoN5ieDh7d8orSw7BV5nt094hf+QKYcNbqjFJPMkYWxbSD0QHgUA9lCBxvMqq/AsLW9tCIxCWhATaoAcub9OLAaE/as+o5Y0fmb72X2ove9Tv7w/+fSe6gKmG6QwDRULHhHOQ2KLmXu9FQcOOv0QSc6LQustytN+znRcf2nMPteKEDy+QAeD3V9qGNfYoDF/8rorKNI3vHu/C/hUV1ejcLDF+4Wkva6qudhP5KCSOTbJIbfNMq05RWZs876rMohu8sbpYjykCC5BGtU+0n7cd5WKYddLiPOWJ6zpCJG83XMiJo4Ks/047VvsJmXh6kGUGVsTg1YS5ormHcKLDDM6+pEMguxTuEmtnS1kBFykRAkXeydYEWnQMbS2ap171Z2o2VfX3wnqK1Au60CiIx0QcYzrQ4xZw4FjoA78IPLl7yumTq+Lh9ZyXlHtbwCJEuog665pbSS/SidXUu5JWKdSj9qpuO1zEIU4KJKHwEfYt0gYCtllMrdsAnjyDO9DANh0hZ7gfySLvgEmyRExyT71ErIwstEhF+Cd9c1UeekES71NLwCVuySz9+eQ5JOdPd6qq+mLA22IvlIDm3drsfKlwSn9BkDMa+BzjJj0Mnxngip+m+sQuSxTdbC/NH2Imy6PdTuo4Oajx1r+BLJBlWhy1fZ9IHIqKldWhHPPr/jNCUQLRZF3yrethYBvqBW2Fi4lg2fAUViyp+SpnUr2vLg9610FWucpva7AF77YcrYl6xH84dEdd2dXWo3WU7Lbbgy3M4xd/hS2Q2MiyX+3dXExmNsf8u1KnxV1Wv0Q/yysM46iQjLOB1HHbedkQ+RIorYL7NUjnlpvTkU8ib1fQqheuxGeoEAqskWz3QnPnngMpGGorgMYvYAKRMaGXhGZFjcPdVo5deOxwDP1QCpeOWUFHHgTkpTbYnEjuHVmZA5pZScf9XWIDzEldhk5M0SqGNcxyPaK+sAcKfVwWk6NlyXwNWi3XtNVom1SyftACJmgUn/+SorG7KWnDUZqtND4gAI4IP3Cm8IPBke+fAWsnVgDdSrqLOdfkPk5dU3bKGfPQlrej9iYWiroQ15OGRXPQapVWADHDafYrnaghm2OKvRMWC6UUVgPMyBjPQCnGz9LN1y1ElasIW1cCPxoEN0/Nc6OL3pvMqzk9f9dem3DNsKAU7qkc17oLmVDl7j3uU3cbgYBosG2gkkuAzylSZw4twId8I3dp8nLedTSnwho3G0MiVvA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR04MB4555.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(376005)(366007)(1800799015)(52116005)(7416005)(38350700005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QU3kiKSJjjAOY2hyf9ezEaXyYs0oHndBfnoZjZ5tGyTXa4EU5zAQmD1lo+uhz7dlxculjJ7OEgmcefdDsY6yqhFboojqm5wWSBfioIv+UrbfaBGZY42Ggeh2nLKbWHYLIVg6kBfBXDx2G6TCLn19m60HC+zhUfXhLP8DDfhMJSp2QW6qLJckdpcuwKdQdicKyFQ4nyMs+KM4oh7TeqnA0FmZJOJRdt+fA8fwHZUs8w+y2U5ub9rqGXQTJVmtzrUY4zSFGlTqGse8qXYhjgrw/MVmXnm0RLbQp3DDCaHXp5CEVq6OSM46b/oXluJlYMh0rDpSyh/sAULU+IoX53NgLQyvDud8G+qqTKrD7jajaQBuYUWpU17K8u3J681RqTavs+o2z6NkbRLnkbep8yN6bk6WjL4DZEXwdbizS4e7Kgdm24CEv+alSRHuadTBXqBmLxiif9M2rD45ZdXxcd01tj0MB9s4CxnF2Tlm0tIh7uxJpZzp5YM4Jm/VdObzHBVcyyr5IxMgMr6roR5fu3WGk1oH/nAwVJ1a9IoFwCm6DjTlob/SVGKCI+BcLxrshSC0T87KauByeXkwQDutb2iCCnX7rPr9uzx6+79FGElMwQcb+gpaEtwRfzef1TtLAyCptS3rUMH04oR4XoTlCe/gwf2uN4OcEnrknjP0MZ3LFjLUcIFzNThPjFkLydAJhGk2vXgJHcGq1GJbFu+lHzBMEwaxugec0VzSoclLdLj6ZPyUrfTj9JB9I+Vyl6g46HIDkIgAZG3IWP0tgszG/DIlIqAmS9k2pXODHq7Q8wQWZ9gs84ZzBVahVsvLiMB9bByFTxtbWNUKYiR9aqRbBMnyKFJvhW9eUBJJQqPCaVFV0VmOTDHUXtOwkFJbm1kgOvLGNGSVK+Sup06BIRwJet+npQUsns3lCb1jZkES/8UCcf5uijd4k0I33V39egOdbG63ApsYCMnxSUHXFX9RmJbtxwnZzNBA6uH3MwfyC2FyNTf+VOlfrjW3JGP0pRRo8dL+r3PiY8PfkZYUaIvXqZmKr8N0QYARCZMAniXUsmVWxnIAiQdLosnsHJU2oNpjZWYhMUCnsI36BmY1SYZhYCRFInFvTCePH/gUnfyDnm7lkjer8i/aFJ729Ryos913W2122sWAoi7olri6lzmHDOO+IMb4v4v224pNfIa4wslH87ouMEPcBwEAEHVe0NeOpjeXn0cxUSyzXwiVEKjQn7/LSnIOI7v4YDNoI7eulYB0UAuE61zxS6SLPscbRTu0nPE4TzD6PcDw9IB90yckd5+bQsnZJY3WkhIdIkQeCsYxDKs6sNKWFAjh6Usj9GBTJ8u5OneB0Ysdyl5xEuTtWUvPEXGH6WgKlviWi+pDadmxtgctVUIn9mutnStxn5hrS169bzLzfHYBN/zwsFs2Fh+U5mh2GhtEO2BBfsx/YXPnMV0Nc9mhHKH+8iWhFhEVuLU4JhqU6yXYoSHFRcE4oaM20QTLgWmx/WLyjM3qhg30Vci7OxYF2t96LVQsZs/YrdD6zj+LnXuTRI61ePIUpl7VrLGRNZ2TnwsO1YY3O+uoASKWWV3TJUqHPLWI6AU4z5N0P4R2IIdONZY4qJHuXM/DCg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c3f85d8a-b7cf-47fa-703c-08dc7e634ce6 X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4555.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2024 15:40:13.8616 (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: ABnEv5K4R2k55pAj0QxmsJAGpgPsPmZ1RMt77H3LdMB1XLE695UjAXYkFPClX5f6a5Bd+tqF1egQp3pZX6h6CA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9961 In commit b5b73b26b3ca ("taprio: Fix allowing too small intervals"), a comparison of user input against length_to_duration(q, ETH_ZLEN) was introduced, to avoid RCU stalls due to frequent hrtimers. The implementation of length_to_duration() depends on q->picos_per_byte being set for the link speed. The blamed commit in the Fixes: tag has moved this too late, so the checks introduced above are ineffective. The q->picos_per_byte is zero at parse_taprio_schedule() -> parse_sched_list() -> parse_sched_entry() -> fill_sched_entry() time. Move the taprio_set_picos_per_byte() call as one of the first things in taprio_change(), before the bulk of the netlink attribute parsing is done. That's because it is needed there. Add a selftest to make sure the issue doesn't get reintroduced. Fixes: 09dbdf28f9f9 ("net/sched: taprio: fix calculation of maximum gate durations") Signed-off-by: Vladimir Oltean Reviewed-by: Eric Dumazet --- net/sched/sch_taprio.c | 4 +++- .../tc-testing/tc-tests/qdiscs/taprio.json | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c index 1ab17e8a7260..118915055360 100644 --- a/net/sched/sch_taprio.c +++ b/net/sched/sch_taprio.c @@ -1848,6 +1848,9 @@ static int taprio_change(struct Qdisc *sch, struct nlattr *opt, } q->flags = taprio_flags; + /* Needed for length_to_duration() during netlink attribute parsing */ + taprio_set_picos_per_byte(dev, q); + err = taprio_parse_mqprio_opt(dev, mqprio, extack, q->flags); if (err < 0) return err; @@ -1907,7 +1910,6 @@ static int taprio_change(struct Qdisc *sch, struct nlattr *opt, if (err < 0) goto free_sched; - taprio_set_picos_per_byte(dev, q); taprio_update_queue_max_sdu(q, new_admin, stab); if (FULL_OFFLOAD_IS_ENABLED(q->flags)) 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 12da0a939e3e..8f12f00a4f57 100644 --- a/tools/testing/selftests/tc-testing/tc-tests/qdiscs/taprio.json +++ b/tools/testing/selftests/tc-testing/tc-tests/qdiscs/taprio.json @@ -132,6 +132,28 @@ "echo \"1\" > /sys/bus/netdevsim/del_device" ] }, + { + "id": "6f62", + "name": "Add taprio Qdisc with too short interval", + "category": [ + "qdisc", + "taprio" + ], + "plugins": { + "requires": "nsPlugin" + }, + "setup": [ + "echo \"1 1 8\" > /sys/bus/netdevsim/new_device" + ], + "cmdUnderTest": "$TC qdisc add dev $ETH root handle 1: taprio num_tc 2 queues 1@0 1@1 sched-entry S 01 300 sched-entry S 02 1700 clockid CLOCK_TAI", + "expExitCode": "2", + "verifyCmd": "$TC qdisc show dev $ETH", + "matchPattern": "qdisc taprio 1: root refcnt", + "matchCount": "0", + "teardown": [ + "echo \"1\" > /sys/bus/netdevsim/del_device" + ] + }, { "id": "3e1e", "name": "Add taprio Qdisc with an invalid cycle-time", From patchwork Mon May 27 15:39:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 799695 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2059.outbound.protection.outlook.com [40.107.7.59]) (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 291BE1640B; Mon, 27 May 2024 15:40:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.7.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716824422; cv=fail; b=kO5TjmZmiGqXvS8DwPxEDYS+oZlcoyKlohX5ylyItjAvFuMNjJ0ivj2fMt2rW5MMFPqecSvOcE8N2BfvTScssbXVB0Vc73+XliUeEkRJ6DWAEr6hf4D2RNgaCbLEhA4gkcvE7nZZ2RdadywVxqb0AJP7RMSYmUB9L+TzNH4sw2U= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716824422; c=relaxed/simple; bh=zhZfaShmwLFs/C8gLPXDvxVY21ttAXUQ8peaVE84q3U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=PL3hhmNkSQMC+Hx6Yu8Ve/rU8DJ5RcAiu5PzFmkrChCMxDsQUNLO3fyTYiV8oBOs1tyvzG5mzptGVxjltemdgbPgkzC2ndhBU/7mAds6J9Yw+6jfFR1tHzzoEHabU5nnDuz71WjWOiM3prlSZ7wuG4poZbDTyuB6Plj0keupO8Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b=Q1cxWoWu; arc=fail smtp.client-ip=40.107.7.59 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="Q1cxWoWu" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EgqkxW9wFa4rlmFjP4nLiaFjfVIyEBtCEx6Dd1KsiTlwQiq1FSUI+BJ3qmxaQ30LLGGFbfOAOl5PEHg+fMIqKxLzVf2V0vcL0sC/D3AIpierAfJ/NEpwCin9coSgO53YTHJJL+/Sa0TVyLWoqe48wp+f9hae/OLG+3W7vUiTg/aLIHMuT7R06b/qgWdmxX3eUaCdcXxHpuVhdK2Zu9yRiHyVK4Zm+1111y/XVk8BUiMQST7hKHN8p3UbGa48kmmsNt5EISMHBmaOq/la98ViDoABmUGvFoQfBeXg0ijYLEtbwao9NvUyIus63Jw9kE8+9+5OoNXqL/bmkIye6retMg== 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=h7MVHDWb0SpZ5n3e6NWejnLCquP1pdFAYS5n8jnRT6o=; b=l28mfKDHpIICSwNfOqAE/gMEHOYdTRPThLefzsxsVVlZxcGYHqB6RR9E/5ASrQ46Zamt47mN+wBPwHTzP1kcVEY71yCBCZ0WGC0orel+D2Hhn0WVgQiq0znJBEu0OU9RzSzxShg716QqvBfpPcPIopvZd9++Bz7BKGaSGoqFjSobHKc/fdEGHj8Rjf/Q6u7gcEG0C1IG9Z5Hxwey2d8pUNA07x/qNtkKh4+uk9IYbKWjvx136o2V6HfSaS+ek9LPqCGpNfohny5n1xT9iBHmhFjWZ8GfuWtXbRPYIA6wPYNjUEiBNrafIieeSw7Ad+yOMh1Q2RwusKE59+1BHpkXPg== 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=h7MVHDWb0SpZ5n3e6NWejnLCquP1pdFAYS5n8jnRT6o=; b=Q1cxWoWu7CypwozwZZJeT4dgej6K8C3oE4qKExAF0UwE0u70yb7c80tfyyt/jcIStyJCHEZoqRD5gc0m3tNG8NmI2N3+YTA04wGQJKAppFusjSSztVEft3LMNVzOZEHVOgn+QgiuzHKlvRVWLNVANt5xK4x0rR/25glyYN6NT/I= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB7PR04MB4555.eurprd04.prod.outlook.com (2603:10a6:5:33::26) by DB9PR04MB9961.eurprd04.prod.outlook.com (2603:10a6:10:4ee::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.29; Mon, 27 May 2024 15:40:15 +0000 Received: from DB7PR04MB4555.eurprd04.prod.outlook.com ([fe80::86ff:def:c14a:a72a]) by DB7PR04MB4555.eurprd04.prod.outlook.com ([fe80::86ff:def:c14a:a72a%7]) with mapi id 15.20.7611.025; Mon, 27 May 2024 15:40:15 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: linux-kselftest@vger.kernel.org, Vinicius Costa Gomes , Jamal Hadi Salim , Cong Wang , Jiri Pirko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan , Pedro Tammela , syzbot+a7d2b1d5d1af83035567@syzkaller.appspotmail.com Subject: [PATCH net 2/2] net/sched: taprio: extend minimum interval restriction to entire cycle too Date: Mon, 27 May 2024 18:39:55 +0300 Message-Id: <20240527153955.553333-2-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240527153955.553333-1-vladimir.oltean@nxp.com> References: <20240527153955.553333-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VI1PR06CA0116.eurprd06.prod.outlook.com (2603:10a6:803:8c::45) To DB7PR04MB4555.eurprd04.prod.outlook.com (2603:10a6:5:33::26) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4555:EE_|DB9PR04MB9961:EE_ X-MS-Office365-Filtering-Correlation-Id: 29239629-6871-42cf-f9bd-08dc7e634dae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|376005|366007|1800799015|52116005|7416005|38350700005; X-Microsoft-Antispam-Message-Info: ZFGjM8/118U2ZJVdsKG7C53XbO62BkDyyg8i6Q3bryZE97YzxwmO8rF+O98W1C3LaCtO+7fZpzMHNR+023b7mHZMQJEJ0Zp2k1rdEkdraf794b4bUEX2Fl4fj5DWmP92yyIi3F9m+hgmVMgAKYsThpfO1QTqf6DNriRsCU0zuIPbmCSaji8GFH10mAUmERcCvsC9Zqi1nXVImxlLV7gympD7DjpW9wGbRUUa+GvfkGXeb+6haeZObq8sBOmGvC55acLD6QZgckSSzdf7eBGeZukPKi/cQK813fNqcwSLn1BZH/asP43kWm7IIkvgkjFqAGe06OWYsoLQjcSYpu5R8//Ge1UVfkP7PO3DHEhnliOtkD0wd0pHAFEFKEgjaBOwkOPYB0IxP42RQMwQvWXgPQlS0pZcj8iBDP0cn1dAdv2gjZaMtV1D4Dv3RX9yOWlOkXaJgvgs27UKhRLgM5IvDs4D7XvLUIUBnKhM1nDiMbcSkEpVohKZPhAIL9CARC4OYMVmjzliEWJXjhF3wVr5oJyd4OeMAFxavNv90gjlfOBlgtQn0+1S6lYzpPkk38yaPV5bmeIl89Pp+lHH7AIuN45RFOAbRhz/Wybe22UIcPz/TgVTGilC2hQJysPnUQyjli7czwx3ARgGSg75CcgRNNdYEtSoNinA20ifINeJn50bWoKMepatclkYBOV2sQxa0C5iPer35qlmXeZ0Usr8whidKyUI9dNMFW5xB/a2BijSBxlslCc2NRhySc3H01mYRA2o9QN9IhNxbx0CR3AsHd6DPbAKJUdIda7GEFXcY/85d4WnRZitENmyphv9EZ+sAp0xg0IxjGv9ia5AtGMdkS68jr53RP7Xvz56VARszrbq03P4y4nFpuE6O9zPqc+XqVfHGB+c8g4aB4eIt6MhzOU8yt8ljUIZgZlJjzHYTrIFo6wvmdyiP4idl1iOSQA6U9Zx9D9/vgAJDqsv5hF1sD8/jRadXqiqwNJ/uMU9kxvKc+kJmyvL7/TKdFNMFPAd2h4Ze39NXkT4dmn/3LYL+ucbYa+peZnXrxLdwec6ME/8vJu5qqsX6cnvDDKT8qwv/xLlGhohGEvEXr0zW+quXcYjNSyzMKZ44v7LCXVaVMhX1sNaxQC+qhBiOfhX6bEAxa4NJFuezR4Np8OCT18Gx1kFtpFhifc/SjVm6ny8ckY3UtkdK1GdWeQlW1okabfTIxMnnfYmu+kfONRbbKoM+IfD9/yT9qmRGEbmWJdFxUpP8wvP1XVUymHkWwXKx567TANZ2SaceovXgQUeOuRLVw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR04MB4555.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(376005)(366007)(1800799015)(52116005)(7416005)(38350700005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2PpFBexIawHFxUzBz3vi1utcGY2MMSnEtIJUO7r3iUl6a57iY08PMSCFYDYQkk2+W6VSIF+NZLVJ+66zsdK6xSpsDlangPNk8YdNbrdWMYGnPoXukjZ5o660QciWoEUx8ROggeeq7+Hx/S+iGFxOqBWJmnuQ5ovRViXHcCaKHtgSrIjmwA/Z73PfObKzNYECDkx5BHFC6yBc66gLIDZNksQnIueHi33F+hd1+Ub2gcW14ICVrP9R/w4P50hSh3lbJ/QK/TUkGWI+0u5cPUyyboITcnJ32tpRSuRYJqE1AM3o/kAM5GcH+c/mFgb41LwDZul5PG8K7wsSi2RxpD+gwMEblk+w9EhG+4Pwy7j+7cahC7DYHnV9jBOFVz3j+KvW8u4P+2ULB56G5KWMb7IoFbAeQdxV7exL/6A/UivKXm471Fygv4KY7a6Njum4H0eAWJ2kggH2m6Rw6wxP9MHg5oeSWIGItfAx3xF/FF/1bnmJGRoFyWwLpQymnCuottqBTnrCywdWsRP6T5khkiaSmSnvwUC1bzwEa9B+FB5YDHCI988taixQhjeR2vsNDQTq3tKYnuOa2blnBQRGrnfZ6FZewi7MDKDg7x5EOggMVlL6fjZPvKigI1Ysppu5/qEO9tjSkI/m2bNSvM3CmYowGmX8dDU/twoUrStuxp5tOr/61ySEUnZK8Yx7IXKiC82gacKTkSsFBYGHkvvuBPdiwvobDn13aW4TlfuombhTZSlHmJD7xn/823ZLuD4NmyBmGCyJFo0MMMOxuoPnvJUa5J46Nmg6kU/sSn/ZMo+Jq4SmpjZkoKFh1T9ToafJ2hyTkihGq85sZWhQR+Al2bRaq0POAuj2ni8WXu3w/sumjs9E6YvyjKVjyKut+CJaflEL0Txxh4clKjwkFM0olqJTjWC3FUKJzonDcpdvwwTSQKGqrNFqI1Xjc6TTiy/TKMrIvukD2UNL8TbqIswduMWdVQBkq2U2DjQ+kAnaVg+/N1ClBNenXca94Grmb/G+XDSIj9gAz0TF+rOzA897usbWK8pWQTifX+adVKOhgvAQ8SOR2V5vllk06BWFcyavrDTThdVN5x86kI6s2QcjvKdu4N6ewGWJmPEZU0MpLoMhfRNiVAmqVAD6TmWhxQf1Df8KAHS0swzarTelvqOQJ0cdbBlEXQKTP9PgSytPtlHCJQt5l2jOQRW1KsB750uPaiDFPtlOMDHGltApcloQHMTKBROBHOY4KGQxt1+Q29FgTp8zfX/nqo538ld6PpBi+bpLJLFwVhfg/I/us8YmxFP9YVmdCEIVZBz8iGrMq8yNSc6gXXbgDLe0TJN0hbK9brqFB0qL0K4l1Lkk9rn5Hf7k3OCWfGv1LAL/oPsv3O0+ruDSTlgLtv57oqzY2h3BV84uHstccmNyw+KKK9pZm4Fq2RCNLRqfkQSzEuv35cJr3ZVWNHv4RxBf1J3PlLk+mMYHtVOY7zicCCeEZ4A885xxxFBRZwqjwvLu0697vpoOzYXykrqPeMgnxQZ60m0gsN0oO5G3yCIia6P5cu+Dk9YPnC0yGrrhvHhtVhVIJ04CFdQUsDol3nQ0guL/evDq80Zc/y9cg4SFbHQXJZlwZXmNhQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 29239629-6871-42cf-f9bd-08dc7e634dae X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4555.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2024 15:40:15.1331 (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: Z8znRZN03UL75sRLG54AQvi4ioUq9ctsl2+5bvzW16iRV2i5y3rZtUI4XPSDy+RmBa8wP45nj3mF6xg7mgklFg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9961 It is possible for syzbot to side-step the restriction imposed by the blamed commit in the Fixes: tag, because the taprio UAPI permits a cycle-time different from (and potentially shorter than) the sum of entry intervals. We need one more restriction, which is that the cycle time itself must be larger than N * ETH_ZLEN bit times, where N is the number of schedule entries. This restriction needs to apply regardless of whether the cycle time came from the user or was the implicit, auto-calculated value, so we move the existing "cycle == 0" check outside the "if "(!new->cycle_time)" branch. This way covers both conditions and scenarios. Add a selftest which illustrates the issue triggered by syzbot. Fixes: b5b73b26b3ca ("taprio: Fix allowing too small intervals") Reported-by: syzbot+a7d2b1d5d1af83035567@syzkaller.appspotmail.com Closes: https://lore.kernel.org/netdev/0000000000007d66bc06196e7c66@google.com/ Signed-off-by: Vladimir Oltean --- net/sched/sch_taprio.c | 10 ++++----- .../tc-testing/tc-tests/qdiscs/taprio.json | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c index 118915055360..937a0c513c17 100644 --- a/net/sched/sch_taprio.c +++ b/net/sched/sch_taprio.c @@ -1151,11 +1151,6 @@ static int parse_taprio_schedule(struct taprio_sched *q, struct nlattr **tb, list_for_each_entry(entry, &new->entries, list) cycle = ktime_add_ns(cycle, entry->interval); - if (!cycle) { - NL_SET_ERR_MSG(extack, "'cycle_time' can never be 0"); - return -EINVAL; - } - if (cycle < 0 || cycle > INT_MAX) { NL_SET_ERR_MSG(extack, "'cycle_time' is too big"); return -EINVAL; @@ -1164,6 +1159,11 @@ static int parse_taprio_schedule(struct taprio_sched *q, struct nlattr **tb, new->cycle_time = cycle; } + if (new->cycle_time < new->num_entries * length_to_duration(q, ETH_ZLEN)) { + NL_SET_ERR_MSG(extack, "'cycle_time' is too small"); + return -EINVAL; + } + taprio_calculate_gate_durations(q, new); return 0; 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 8f12f00a4f57..557fb074acf0 100644 --- a/tools/testing/selftests/tc-testing/tc-tests/qdiscs/taprio.json +++ b/tools/testing/selftests/tc-testing/tc-tests/qdiscs/taprio.json @@ -154,6 +154,28 @@ "echo \"1\" > /sys/bus/netdevsim/del_device" ] }, + { + "id": "831f", + "name": "Add taprio Qdisc with too short cycle-time", + "category": [ + "qdisc", + "taprio" + ], + "plugins": { + "requires": "nsPlugin" + }, + "setup": [ + "echo \"1 1 8\" > /sys/bus/netdevsim/new_device" + ], + "cmdUnderTest": "$TC qdisc add dev $ETH root handle 1: taprio num_tc 2 queues 1@0 1@1 sched-entry S 01 200000 sched-entry S 02 200000 cycle-time 100 clockid CLOCK_TAI", + "expExitCode": "2", + "verifyCmd": "$TC qdisc show dev $ETH", + "matchPattern": "qdisc taprio 1: root refcnt", + "matchCount": "0", + "teardown": [ + "echo \"1\" > /sys/bus/netdevsim/del_device" + ] + }, { "id": "3e1e", "name": "Add taprio Qdisc with an invalid cycle-time",