From patchwork Fri Oct 14 07:54:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Theil X-Patchwork-Id: 118196 X-Patchwork-Delegate: thomas@monjalon.net 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 9332CA00C2; Fri, 14 Oct 2022 09:54:26 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4D689410F2; Fri, 14 Oct 2022 09:54:26 +0200 (CEST) Received: from smail.rz.tu-ilmenau.de (smail.rz.tu-ilmenau.de [141.24.186.67]) by mails.dpdk.org (Postfix) with ESMTP id 301C1410F1 for ; Fri, 14 Oct 2022 09:54:25 +0200 (CEST) Received: from isengard.fritz.box (p54aef542.dip0.t-ipconnect.de [84.174.245.66]) by smail.rz.tu-ilmenau.de (Postfix) with ESMTPA id F0B72580098; Fri, 14 Oct 2022 09:54:24 +0200 (CEST) From: Markus Theil To: dev@dpdk.org Cc: Michael Pfeiffer Subject: [PATCH v2 1/2] eal: expose lcore pthread id Date: Fri, 14 Oct 2022 09:54:20 +0200 Message-Id: <20221014075421.10300-1-markus.theil@tu-ilmenau.de> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221014062100.5761-1-markus.theil@tu-ilmenau.de> References: <20221014062100.5761-1-markus.theil@tu-ilmenau.de> MIME-Version: 1.0 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 From: Michael Pfeiffer Also expose the pthread id of each lcore, in order to allow modification of pthread attributes, for example use rte_thread_setname without executing pthread_self() on the maybe already running lcore. The rte_lcore_to_thread_id function is added to API. Signed-off-by: Michael Pfeiffer --- lib/eal/common/eal_common_lcore.c | 10 ++++++++++ lib/eal/include/rte_lcore.h | 14 ++++++++++++++ lib/eal/version.map | 1 + 3 files changed, 25 insertions(+) diff --git a/lib/eal/common/eal_common_lcore.c b/lib/eal/common/eal_common_lcore.c index 06c594b022..812e62bcb3 100644 --- a/lib/eal/common/eal_common_lcore.c +++ b/lib/eal/common/eal_common_lcore.c @@ -114,6 +114,16 @@ rte_lcore_to_socket_id(unsigned int lcore_id) return lcore_config[lcore_id].socket_id; } +int +rte_lcore_to_thread_id(int lcore_id, pthread_t *thread_id) +{ + if (unlikely(lcore_id < 0 || lcore_id >= RTE_MAX_LCORE)) + return -1; + + *thread_id = lcore_config[lcore_id].thread_id; + return 0; +} + static int socket_id_cmp(const void *a, const void *b) { diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h index 4d3978512c..3ccd0a73b9 100644 --- a/lib/eal/include/rte_lcore.h +++ b/lib/eal/include/rte_lcore.h @@ -171,6 +171,20 @@ rte_lcore_to_socket_id(unsigned int lcore_id); */ int rte_lcore_to_cpu_id(int lcore_id); +/** + * Get the ID of the thread of the specified lcore + * + * @param lcore_id + * the targeted lcore, which MUST be between 0 and RTE_MAX_LCORE-1. + * @param thread_id + * the thread id is returned in this argument if lcore_id is in range + * @return + * 0 on success, or -1 if out of range + */ +__rte_experimental +int +rte_lcore_to_thread_id(int lcore_id, pthread_t *thread_id); + #ifdef RTE_HAS_CPUSET /** diff --git a/lib/eal/version.map b/lib/eal/version.map index 2d64a2592e..2e57242920 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -440,6 +440,7 @@ EXPERIMENTAL { rte_thread_detach; rte_thread_equal; rte_thread_join; + rte_lcore_to_thread_id; }; INTERNAL { From patchwork Fri Oct 14 07:54:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Theil X-Patchwork-Id: 118197 X-Patchwork-Delegate: thomas@monjalon.net 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 82484A00C2; Fri, 14 Oct 2022 09:54:30 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5B13742CA2; Fri, 14 Oct 2022 09:54:27 +0200 (CEST) Received: from smail.rz.tu-ilmenau.de (smail.rz.tu-ilmenau.de [141.24.186.67]) by mails.dpdk.org (Postfix) with ESMTP id 703AF410F1 for ; Fri, 14 Oct 2022 09:54:25 +0200 (CEST) Received: from isengard.fritz.box (p54aef542.dip0.t-ipconnect.de [84.174.245.66]) by smail.rz.tu-ilmenau.de (Postfix) with ESMTPA id 2D61C580099; Fri, 14 Oct 2022 09:54:25 +0200 (CEST) From: Markus Theil To: dev@dpdk.org Cc: Markus Theil Subject: [PATCH v2 2/2] eal: prevent OOB read in rte_lcore_to_socket_id Date: Fri, 14 Oct 2022 09:54:21 +0200 Message-Id: <20221014075421.10300-2-markus.theil@tu-ilmenau.de> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221014075421.10300-1-markus.theil@tu-ilmenau.de> References: <20221014062100.5761-1-markus.theil@tu-ilmenau.de> <20221014075421.10300-1-markus.theil@tu-ilmenau.de> MIME-Version: 1.0 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 rte_lcore_to_socket_id did not check the lcore_id range before accessing an array with RTE_MAX_LCORE elements. Signed-off-by: Markus Theil --- lib/eal/common/eal_common_lcore.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/eal/common/eal_common_lcore.c b/lib/eal/common/eal_common_lcore.c index 812e62bcb3..af53efcc24 100644 --- a/lib/eal/common/eal_common_lcore.c +++ b/lib/eal/common/eal_common_lcore.c @@ -111,6 +111,9 @@ unsigned int rte_get_next_lcore(unsigned int i, int skip_main, int wrap) unsigned int rte_lcore_to_socket_id(unsigned int lcore_id) { + if (unlikely(lcore_id >= RTE_MAX_LCORE)) + return -1; + return lcore_config[lcore_id].socket_id; }