From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B90E641D8D for ; Mon, 27 Feb 2023 08:10:14 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B222A40A84; Mon, 27 Feb 2023 08:10:14 +0100 (CET) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2072.outbound.protection.outlook.com [40.107.220.72]) by mails.dpdk.org (Postfix) with ESMTP id AB8B940A84 for ; Mon, 27 Feb 2023 08:10:12 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VGtynMN7/O4J/G7VcKcaopY4D0UEkEhYubhgJKwcaAeBLX+1X0rXdKrcdbihqGnFgQ45PFxrAos/Ds3dMOBUE98aPKHHqmiq3U1RSEULKVXWpfgVt9GXDt5iXobYFSQ4MbJI14LmKLQQq3ooo5hJBBSe6uES5ZEr6MRdN/sEGaNzPpvzl6SBPHa0662zgT5A9ZAJqVL4kt9sfcl0r0qGcLbGjN8vVCcxJ60sF3b4j3YdY3YLT45suRz7VX7nEOkTARklb9aKx2HNSkLi9M4qompNOjHvcHRtrSZ77omBNXriuv9xMBv0wxAiK4wqvIpvLlRB/xTi4G0vm/C3FcHvlg== 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=5sjZhZ3u5hydzxaTsij3NmUDVCAUOvzPD7AH9ul3tI8=; b=YA5RP4Q59Xncpn9WZIR05OTmiMZfKKM1+Glq80uHlmkUfEswDg/xgD+XqRnqGAwZSyKgtorOqaSEdICAJP9GYaj5NywJOsGb9FGEmYMs4mM9CVfRJ+0FUw0ZaZQ+2tm4b3xGXkvCcWC2S1KXLJqo5fbaOB5GcljMOKR/WWn6ksVyOIgIvxWMge87dibpB8QnzIDyjT4FkBoZNWZPN9vU/zWROMprfuQoIpkeV7KKHF0x6v+KNjS/WC4VwKhv2j2bTAIknGeIl01JkcjUxbAUvfwbJIQ5jv+HEqNr08QZ0aXkZ4voPsmm0URl6Pqe4WHi5lo7TswuPze/Lh+d6rxJsQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=intel.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=5sjZhZ3u5hydzxaTsij3NmUDVCAUOvzPD7AH9ul3tI8=; b=juIpavvH5E+KFUpjpy2baHVUKdcGmZZN4pn2AG06LEWuY5qlgGQqlRjtKudex6+jCxlSslRwQ5vjpdKEMAsUvd6gFCAaowL15Mh5grpDRKZw8D/p5PPvUx8nTvWnV81U0VIbyotSRuWwNl3YpFVSMh1MepyWLMVem9pYsdHdcyt0zxhUbBuoRZshOXtY1NzMZUCG5xiLmGXRAFG/jRz2dP4eLf4yOTCjWvg4UwsR+WDWQ5z4INEqosZxgGkLv+enlyCOhLY2gR17J3FyFwX+0sQsw0zSgicEAPZZo3ruEPzSfEhQ7iT5hO1IHzAeM6FgRMXK0cq/k/W6NJlMtwropw== Received: from DM6PR14CA0037.namprd14.prod.outlook.com (2603:10b6:5:18f::14) by CO6PR12MB5428.namprd12.prod.outlook.com (2603:10b6:5:35c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.28; Mon, 27 Feb 2023 07:10:09 +0000 Received: from DM6NAM11FT082.eop-nam11.prod.protection.outlook.com (2603:10b6:5:18f:cafe::bf) by DM6PR14CA0037.outlook.office365.com (2603:10b6:5:18f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.28 via Frontend Transport; Mon, 27 Feb 2023 07:10:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by DM6NAM11FT082.mail.protection.outlook.com (10.13.173.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.16 via Frontend Transport; Mon, 27 Feb 2023 07:10:08 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Sun, 26 Feb 2023 23:10:00 -0800 Received: from nvidia.com (10.126.230.37) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Sun, 26 Feb 2023 23:09:58 -0800 From: Xueming Li To: Erik Gabriel Carrillo CC: dpdk stable Subject: patch 'eventdev/timer: fix overflow' has been queued to stable release 22.11.2 Date: Mon, 27 Feb 2023 14:59:50 +0800 Message-ID: <20230227070107.15664-82-xuemingl@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230227070107.15664-1-xuemingl@nvidia.com> References: <20230227062349.13764-1-xuemingl@nvidia.com> <20230227070107.15664-1-xuemingl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.230.37] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT082:EE_|CO6PR12MB5428:EE_ X-MS-Office365-Filtering-Correlation-Id: fcee2abe-4634-4694-22e4-08db1891a901 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nJelgmMR2ubKZqnpabY9qTBxhATsV+u3Ep+JNzCpZYf0yto/L1oRgD6rzeXgoLvjB9jwSaCTkbie0naGzLZ1bLfSMvQB6Qh6cT+LmGs9dnRcJ0XtHgcXwFsLlSmy1l3F+FusSFiHqP7sYriLzvwD+EAPwh+Az6L+pfpuBa9qIj9cHuRNRy8piw9LtTQRE1nJclxtQqG/yjVtSWbnut8erj5OL3m36bCKJ7VI7E3ZnCOkqtc5gJdEfsqWCUs5VCsXVhMppFbSP4hu1bDyp6/c4qfEWLDpvwE5+xp2MaOMzxPfEzTGT5P/CNuo2CYa0G0dhZivjGZKBoOOGdJ3nakWRjJzSwivN6ht0jfWBJ8YADxwa/G2ExBboSMzikiFEd59cHtydmMqrszdRKXFWQAHLrG6n2fBBFhvth76Gq5IeZIUqPxXp6AS39yk7g0jWDoEmLpK59gKNeGna/HmqPPKyjEpAWO+/G3QR54S9nb3KMImNnGRk0joZIfe8Xf2fJczdNW4MKFI0I+x64LR31ZmoWr6vnvamOOoAiZ1n6yh9aJaolo/crMc0p2thYl41xA8X+sBlkFjzsspyr8fWcEfYwQCGXmTEj9NO+uyID2QVkA+HpUSMkeAa98nFz21N0IMltoQtqPwVeS6tXuSouJDiPE6NnDCg/TTMdOt03UAdEHtSllLf6DwfvffvF1PLRwc7A95KfztZN4Tc0XDhlxUyBVy2iyNmZb+s6SrDHGxFCvw7X1wb3+zVNxdgxPnPSkcyYcVdzQ5LdO/KU+hpujtDGyy8YRNGD0ds6e/RDgBlaS9hRPAKbNT5XTtQHokkDx+ X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230025)(4636009)(39860400002)(136003)(396003)(376002)(346002)(451199018)(46966006)(40470700004)(36840700001)(40460700003)(6286002)(16526019)(186003)(7636003)(82740400003)(83380400001)(356005)(6916009)(8936002)(4326008)(70586007)(70206006)(41300700001)(2906002)(8676002)(36860700001)(5660300002)(34020700004)(7696005)(55016003)(40480700001)(47076005)(478600001)(1076003)(426003)(26005)(336012)(6666004)(53546011)(966005)(2616005)(316002)(40140700001)(36756003)(82310400005)(86362001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Feb 2023 07:10:08.6243 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fcee2abe-4634-4694-22e4-08db1891a901 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT082.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR12MB5428 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Hi, FYI, your patch has been queued to stable release 22.11.2 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 03/01/23. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://git.dpdk.org/dpdk-stable/log/?h=22.11-staging This queued commit can be viewed at: https://git.dpdk.org/dpdk-stable/commit/?h=22.11-staging&id=f7825956c03a7e1b86cc07a26fc6f24dfb1d0275 Thanks. Xueming Li --- >From f7825956c03a7e1b86cc07a26fc6f24dfb1d0275 Mon Sep 17 00:00:00 2001 From: Erik Gabriel Carrillo Date: Thu, 9 Feb 2023 09:13:49 -0600 Subject: [PATCH] eventdev/timer: fix overflow Cc: Xueming Li [ upstream commit 13aba5f88d2e1bd8644a2d52fd6b1e4fc73fc3ca ] The software timer adapter converts event timer timeout ticks to a number of TSC cycles at which an rte_timer should expire. The computation uses an integer multiplication that can result in overflow. If necessary, reduce the timeout_nsecs value by the number of whole seconds it contains to keep the value of the multiplier within a range that will not result in overflow. Add the saved value back later to get the final result. Also, move the logic that checks the timeout range into the function that performs the above computation. Fixes: 6750b21bd6af ("eventdev: add default software timer adapter") Signed-off-by: Erik Gabriel Carrillo --- lib/eventdev/rte_event_timer_adapter.c | 97 ++++++++++++++++---------- 1 file changed, 59 insertions(+), 38 deletions(-) diff --git a/lib/eventdev/rte_event_timer_adapter.c b/lib/eventdev/rte_event_timer_adapter.c index a0f14bf861..b07b3837d5 100644 --- a/lib/eventdev/rte_event_timer_adapter.c +++ b/lib/eventdev/rte_event_timer_adapter.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "event_timer_adapter_pmd.h" #include "eventdev_pmd.h" @@ -699,13 +700,51 @@ swtim_callback(struct rte_timer *tim) } } -static __rte_always_inline uint64_t +static __rte_always_inline int get_timeout_cycles(struct rte_event_timer *evtim, - const struct rte_event_timer_adapter *adapter) + const struct rte_event_timer_adapter *adapter, + uint64_t *timeout_cycles) { - struct swtim *sw = swtim_pmd_priv(adapter); - uint64_t timeout_ns = evtim->timeout_ticks * sw->timer_tick_ns; - return timeout_ns * rte_get_timer_hz() / NSECPERSEC; + static struct rte_reciprocal_u64 nsecpersec_inverse; + static uint64_t timer_hz; + uint64_t rem_cycles, secs_cycles = 0; + uint64_t secs, timeout_nsecs; + uint64_t nsecpersec; + struct swtim *sw; + + sw = swtim_pmd_priv(adapter); + nsecpersec = (uint64_t)NSECPERSEC; + + timeout_nsecs = evtim->timeout_ticks * sw->timer_tick_ns; + if (timeout_nsecs > sw->max_tmo_ns) + return -1; + if (timeout_nsecs < sw->timer_tick_ns) + return -2; + + /* Set these values in the first invocation */ + if (!timer_hz) { + timer_hz = rte_get_timer_hz(); + nsecpersec_inverse = rte_reciprocal_value_u64(nsecpersec); + } + + /* If timeout_nsecs > nsecpersec, decrease timeout_nsecs by the number + * of whole seconds it contains and convert that value to a number + * of cycles. This keeps timeout_nsecs in the interval [0..nsecpersec) + * in order to avoid overflow when we later multiply by timer_hz. + */ + if (timeout_nsecs > nsecpersec) { + secs = rte_reciprocal_divide_u64(timeout_nsecs, + &nsecpersec_inverse); + secs_cycles = secs * timer_hz; + timeout_nsecs -= secs * nsecpersec; + } + + rem_cycles = rte_reciprocal_divide_u64(timeout_nsecs * timer_hz, + &nsecpersec_inverse); + + *timeout_cycles = secs_cycles + rem_cycles; + + return 0; } /* This function returns true if one or more (adapter) ticks have occurred since @@ -739,23 +778,6 @@ swtim_did_tick(struct swtim *sw) return false; } -/* Check that event timer timeout value is in range */ -static __rte_always_inline int -check_timeout(struct rte_event_timer *evtim, - const struct rte_event_timer_adapter *adapter) -{ - uint64_t tmo_nsec; - struct swtim *sw = swtim_pmd_priv(adapter); - - tmo_nsec = evtim->timeout_ticks * sw->timer_tick_ns; - if (tmo_nsec > sw->max_tmo_ns) - return -1; - if (tmo_nsec < sw->timer_tick_ns) - return -2; - - return 0; -} - /* Check that event timer event queue sched type matches destination event queue * sched type */ @@ -1140,21 +1162,6 @@ __swtim_arm_burst(const struct rte_event_timer_adapter *adapter, break; } - ret = check_timeout(evtims[i], adapter); - if (unlikely(ret == -1)) { - __atomic_store_n(&evtims[i]->state, - RTE_EVENT_TIMER_ERROR_TOOLATE, - __ATOMIC_RELAXED); - rte_errno = EINVAL; - break; - } else if (unlikely(ret == -2)) { - __atomic_store_n(&evtims[i]->state, - RTE_EVENT_TIMER_ERROR_TOOEARLY, - __ATOMIC_RELAXED); - rte_errno = EINVAL; - break; - } - if (unlikely(check_destination_event_queue(evtims[i], adapter) < 0)) { __atomic_store_n(&evtims[i]->state, @@ -1170,7 +1177,21 @@ __swtim_arm_burst(const struct rte_event_timer_adapter *adapter, evtims[i]->impl_opaque[0] = (uintptr_t)tim; evtims[i]->impl_opaque[1] = (uintptr_t)adapter; - cycles = get_timeout_cycles(evtims[i], adapter); + ret = get_timeout_cycles(evtims[i], adapter, &cycles); + if (unlikely(ret == -1)) { + __atomic_store_n(&evtims[i]->state, + RTE_EVENT_TIMER_ERROR_TOOLATE, + __ATOMIC_RELAXED); + rte_errno = EINVAL; + break; + } else if (unlikely(ret == -2)) { + __atomic_store_n(&evtims[i]->state, + RTE_EVENT_TIMER_ERROR_TOOEARLY, + __ATOMIC_RELAXED); + rte_errno = EINVAL; + break; + } + ret = rte_timer_alt_reset(sw->timer_data_id, tim, cycles, type, lcore_id, NULL, evtims[i]); if (ret < 0) { -- 2.25.1 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2023-02-27 14:08:43.560124200 +0800 +++ 0083-eventdev-timer-fix-overflow.patch 2023-02-27 14:08:40.809237000 +0800 @@ -1 +1 @@ -From 13aba5f88d2e1bd8644a2d52fd6b1e4fc73fc3ca Mon Sep 17 00:00:00 2001 +From f7825956c03a7e1b86cc07a26fc6f24dfb1d0275 Mon Sep 17 00:00:00 2001 @@ -4,0 +5,3 @@ +Cc: Xueming Li + +[ upstream commit 13aba5f88d2e1bd8644a2d52fd6b1e4fc73fc3ca ] @@ -17 +19,0 @@ -Cc: stable@dpdk.org @@ -25 +27 @@ -index 7f4f347369..23eb1d4a7d 100644 +index a0f14bf861..b07b3837d5 100644 @@ -28 +30 @@ -@@ -18,6 +18,7 @@ +@@ -17,6 +17,7 @@ @@ -36 +38 @@ -@@ -734,13 +735,51 @@ swtim_callback(struct rte_timer *tim) +@@ -699,13 +700,51 @@ swtim_callback(struct rte_timer *tim) @@ -93 +95 @@ -@@ -774,23 +813,6 @@ swtim_did_tick(struct swtim *sw) +@@ -739,23 +778,6 @@ swtim_did_tick(struct swtim *sw) @@ -117 +119 @@ -@@ -1210,21 +1232,6 @@ __swtim_arm_burst(const struct rte_event_timer_adapter *adapter, +@@ -1140,21 +1162,6 @@ __swtim_arm_burst(const struct rte_event_timer_adapter *adapter, @@ -139 +141 @@ -@@ -1240,7 +1247,21 @@ __swtim_arm_burst(const struct rte_event_timer_adapter *adapter, +@@ -1170,7 +1177,21 @@ __swtim_arm_burst(const struct rte_event_timer_adapter *adapter,