From patchwork Wed Oct 4 10:54:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Mattias_R=C3=B6nnblom?= X-Patchwork-Id: 132299 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id F05C14266F; Wed, 4 Oct 2023 13:00:29 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BD12E40289; Wed, 4 Oct 2023 13:00:29 +0200 (CEST) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2049.outbound.protection.outlook.com [40.107.14.49]) by mails.dpdk.org (Postfix) with ESMTP id A65F84027C for ; Wed, 4 Oct 2023 13:00:28 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hGZeGjBqJI/TKlCvEb+DLJKqeOrzfmuabxGA996/6ALf2XzKcqYOlLKMQr4EpvSM6fX4m/dZNHO0IQMNPOtNaI204BNxEgqL+cZUdULqvEkTTb3QkarH47UUiCfoDmaipP5le7KvYymFK1cLRt/OhBz0n0JoJ2w61JTx7lc+PxfzB8jizinD0XzKCYVO4mjrzebq7HmlwuWy1vNq1lAQpyCgAjJlJpndGTWLHuuTPPgsWfbiJInze+Bz3pedATjdWAp6Zcp/qBmgCBLe281Y3PtDlZXKgCIMjzGP7kGTabhmzefVKG8NuISZyr39051F4HapWtZDN6bEzePilRaZOw== 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=XvhVgoiiO2WGhNmn8dmKizgs8N7hL5kthLZBK09PRjE=; b=f8NeTpkzXnwyRkqzB6zovZJL12LSix75bGfGrpQ8DIsrP+GncUGY8Ye0t5TKY0ZQqTkB+J/Nwtja+i/8H1rSYQR8sTK3F7xRteHPzBYHPlFZQhtvD40UlPjSjf40Z+6rJ+bvhCttOd4W0fSSX1M5b1sHbCMKjLxjhXmbsly4z9Mf417JhH/yAyB6QYns2mpFUA4u1blCLLUe6kgD9vLTHBaB8tr8Rym8fMSyPNMkZ19kSf+/MIxp1zhleR+jknaKc1r1PUa+K1v96+PANahOF8DGu78F4yJpN43nXQbsMuQexZQwwUoWRhS8KTlxPF68+C8rHQWWHVmEBZQE+BJGww== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 192.176.1.74) smtp.rcpttodomain=dpdk.org smtp.mailfrom=ericsson.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ericsson.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XvhVgoiiO2WGhNmn8dmKizgs8N7hL5kthLZBK09PRjE=; b=kQQ1JMYUkD8BvFzzBHvgBKsMiuwZ1c/drJGgxeNvFVG3OjObK24hpSiWA+vwI85upcLBg6TV6hJ7lLwkX0EgqZZMjUTarMFsg42eBy+h8kpkNtjRr6DenF246gsC5rNrEEeJr35NNALZofBTWCxCsadguGnbQdEEjz2UxQ0CjtI= Received: from DB7PR03CA0087.eurprd03.prod.outlook.com (2603:10a6:10:72::28) by PA4PR07MB8439.eurprd07.prod.outlook.com (2603:10a6:102:2a6::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.35; Wed, 4 Oct 2023 11:00:24 +0000 Received: from DU6PEPF0000B61E.eurprd02.prod.outlook.com (2603:10a6:10:72:cafe::a0) by DB7PR03CA0087.outlook.office365.com (2603:10a6:10:72::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.33 via Frontend Transport; Wed, 4 Oct 2023 11:00:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 192.176.1.74) smtp.mailfrom=ericsson.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ericsson.com; Received-SPF: Pass (protection.outlook.com: domain of ericsson.com designates 192.176.1.74 as permitted sender) receiver=protection.outlook.com; client-ip=192.176.1.74; helo=oa.msg.ericsson.com; pr=C Received: from oa.msg.ericsson.com (192.176.1.74) by DU6PEPF0000B61E.mail.protection.outlook.com (10.167.8.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.6838.14 via Frontend Transport; Wed, 4 Oct 2023 11:00:24 +0000 Received: from SESSMR604.ericsson.se (100.87.178.32) by ESESSMB505.ericsson.se (153.88.183.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.32; Wed, 4 Oct 2023 13:00:11 +0200 Received: from ESESBMB503.ericsson.se (153.88.183.58) by SESSMR604.ericsson.se (100.87.178.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.2.1118.26; Wed, 4 Oct 2023 13:00:11 +0200 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.183.153) by smtp.internal.ericsson.com (153.88.183.186) with Microsoft SMTP Server id 15.1.2507.32 via Frontend Transport; Wed, 4 Oct 2023 13:00:11 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 96F7D380061; Wed, 4 Oct 2023 13:00:11 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , Stephen Hemminger , , =?utf-8?q?Mattias_R=C3=B6nnblom?= Subject: [PATCH] random: clarify PRNG MT safety guarantees Date: Wed, 4 Oct 2023 12:54:49 +0200 Message-ID: <20231004105449.367667-1-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU6PEPF0000B61E:EE_|PA4PR07MB8439:EE_ X-MS-Office365-Filtering-Correlation-Id: 8700ad3d-dd6f-496b-02f1-08dbc4c91c4e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xFDNZtqYHgqlBXU8zcac6DUDijxECzRsGSsMun48d2bhYkfIfg+JFxXdd0B4OhMwvi1/0LYJEh17vooVgtR/UDh1Oo6NyiZDTT/5p2vgN+XSkjvsGvx2BBftBtcyoJyOoATc2tp9OQ1UNyIv4Z7ziIBp00FH73lT0d0mcU+e1nDDcSdFRwB5n+yAKg67W/ERvsqjiiSKqiwUtrOMsiYz4N1fK9W3YOwxQY7skJTiWISF7wV/R6V+9lmjI9iHDEpMPjNd2em910ZmR7Zj9SoeR31/NfNi3AGhcW4o/6R4yCLFQhZUgtFOYdLglpfs21+JkDa0o/vds5pF2/mjXcLbsFj+OSZSSX0jOWPsw1yJ/CRGx+qe4roZQveSiJHf3is5Q7OEUFOH6stq+vaptwmKZ4r2WznT8KzgeXCiIJ82HrnWY21ot3OCbLk33r85siahRoQcyO/lIsssm/Xrx/fzJYdvUeHA63dY5rWPZx6SFCvJTm+scxt5zN8QQdHRTl9tiCl/3WHEi9+lAPt1FtGgeDvXf51UUbg4y8zjzuyzpigJSHD5OPgK7XFFle1ez9TiyKgGSf0wX7Sp8SvCGcWINYiVI5HrIekXdXuVgPjwSUSTAbY9ysur2+psViDchV/Mu1hJdOJBqoJXhtfjKZqS0DHKEkYYz/6pLCqOId8mqXeItyIboPZFZBrqy6yXohqxIpUCdrJ8epTOrLq5yzv8eSmMntW062wRB+QuJYHrgvA+tcIaC5ic6n9UL9N/ivLscImpeOL4fRkNvLmZfgeY74fsUNcpvsJMR2JnruLUjeGcZteAyH6Bz1KSZJpaehUGb73C0L+RQWe6xiEaREKD5w== X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230031)(4636009)(376002)(136003)(396003)(346002)(39860400002)(230922051799003)(82310400011)(64100799003)(451199024)(186009)(1800799009)(46966006)(36840700001)(40470700004)(40460700003)(40480700001)(6266002)(478600001)(6666004)(47076005)(86362001)(36860700001)(82960400001)(356005)(7636003)(82740400003)(54906003)(2906002)(41300700001)(2616005)(336012)(83380400001)(1076003)(107886003)(26005)(36756003)(5660300002)(70586007)(316002)(70206006)(6916009)(8936002)(4326008)(8676002); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2023 11:00:24.4464 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8700ad3d-dd6f-496b-02f1-08dbc4c91c4e X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=92e84ceb-fbfd-47ab-be52-080c6b87953f; Ip=[192.176.1.74]; Helo=[oa.msg.ericsson.com] X-MS-Exchange-CrossTenant-AuthSource: DU6PEPF0000B61E.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR07MB8439 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Clarify MT safety guarantees for unregistered non-EAL threads calling PRNG functions in rte_random.h. Clarify that rte_srand() is not MT safe in regards to calls to rte_rand_max() and rte_drand(). Signed-off-by: Mattias Rönnblom Suggested-by: Stephen Hemminger Acked-by: Morten Brørup --- lib/eal/include/rte_random.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/eal/include/rte_random.h b/lib/eal/include/rte_random.h index 2edf5d210b..c12eb07ea8 100644 --- a/lib/eal/include/rte_random.h +++ b/lib/eal/include/rte_random.h @@ -27,8 +27,8 @@ extern "C" { * value. * * This function is not multi-thread safe in regards to other - * rte_srand() calls, nor is it in relation to concurrent rte_rand() - * calls. + * rte_srand() calls, nor is it in relation to concurrent rte_rand(), + * rte_rand_max() or rte_drand() calls. * * @param seedval * The value of the seed. @@ -41,8 +41,9 @@ rte_srand(uint64_t seedval); * * The generator is not cryptographically secure. * - * If called from EAL threads or registered non-EAL threads, this function - * is thread-safe. + * rte_rand(), rte_rand_max() and rte_drand() are multi-thread safe, + * with the exception that they may not be called by multiple + * _unregistered_ non-EAL threads in parallel. * * @return * A pseudo-random value between 0 and (1<<64)-1. @@ -56,8 +57,9 @@ rte_rand(void); * This function returns an uniformly distributed (unbiased) random * number less than a user-specified maximum value. * - * If called from EAL threads or registered non-EAL threads, this function - * is thread-safe. + * rte_rand(), rte_rand_max() and rte_drand() are multi-thread safe, + * with the exception that they may not be called by multiple + * _unregistered_ non-EAL threads in parallel. * * @param upper_bound * The upper bound of the generated number. @@ -78,8 +80,9 @@ rte_rand_max(uint64_t upper_bound); * * The generator is not cryptographically secure. * - * If called from EAL threads or registered non-EAL threads, this function - * is thread-safe. + * rte_rand(), rte_rand_max() and rte_drand() are multi-thread safe, + * with the exception that they may not be called by multiple + * _unregistered_ non-EAL threads in parallel. * * @return * A pseudo-random value between 0 and 1.0.