From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id AF846A0597; Wed, 8 Apr 2020 22:24:30 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id F1F811C1F2; Wed, 8 Apr 2020 22:24:29 +0200 (CEST) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by dpdk.org (Postfix) with ESMTP id D140B1C1B6 for ; Wed, 8 Apr 2020 22:24:28 +0200 (CEST) Received: by mail-pf1-f193.google.com with SMTP id q3so2946914pff.13 for ; Wed, 08 Apr 2020 13:24:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=sgp1AGBgoDzkPTRBli90XaZluk/p8eGGWWSpzbbxZKM=; b=H1+PyjppRjyODXNmbmfdWY2evnNG1G/zT5o36HT9ptNspe5iHynm5b6PQucizPp/ri Zj/jarITTsHB3tjezloSvy7nFPpNR9SVez1j9225w+/PnjIUc4Tgkxkdxcb8Jgjlirzu xEwvr6T7UZZZt+SNsUFFfRDBmU6FBmIzQBBTh0DcsFiJRVN86RhMyf053EUfsmLDDOQK cU0UvT1UtzAYlXQP9ZZEozH9l0jjpHO+4/H3xRnsCIqprmpyhOcWK+f3zw/eoP8Kv03u vRLyiUhWS6NpT/CLR6/LymvQ/dyQMuzW4lrPzo1rHAkHWcB4RKaih024y0sB+zW2xt53 FICg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=sgp1AGBgoDzkPTRBli90XaZluk/p8eGGWWSpzbbxZKM=; b=UazSTGvvQ7uh0xLHpxDc+RnuT15CW/KRzFjydHRcAiDBl7XJhdnbdqTjVUYcc7soR1 vQNxdiu7Xz1b/HpC4RIOep5MzqPkSK7S9RVQXIKsZY7isxAV+fsSHV3a5ha0w2iWfB46 oSTbzLem667szIKUSviQVtnUBB82+qkNgMpZgbsxXdSBrDz8IXTZkrYFVXpOCMDH5+Qb x/TknmMJbP0iMGU2GXvoKNY2okfEvmP/0LNKcJlAeIk0AuNnZCLA09kcffl0tkXDEsl6 T4qaRmD8n3NLqxx/1J5Yb8bgtCzMelbNXskELyV7JEMg3nrNujTREOm3Ipasu5e1h0Ix etxw== X-Gm-Message-State: AGi0PuYDsOkG8zdU1XwAt7nv0IQrL5iUBHQWzn4oIZp8UUWzbrHF1yGo tgmdGhEEt45NIW1TYmWKJmk6Q/WZU/AD3A== X-Google-Smtp-Source: APiQypKzzdrzquB+FebXtH/seYXyOlLxs/IS+aY4EDtt+6xPvtWA4zbiVJB6x6YB3cUxBtjta/63Ww== X-Received: by 2002:a62:fc07:: with SMTP id e7mr9753065pfh.299.1586377467318; Wed, 08 Apr 2020 13:24:27 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id iq23sm357006pjb.18.2020.04.08.13.24.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2020 13:24:26 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Wed, 8 Apr 2020 13:24:19 -0700 Message-Id: <20200408202419.16471-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] eal: return -1 if rte_lcore_index called from non-DPDK thread X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" If rte_lcore_index() is asked to give the index of the current lcore (argument -1) and is called from a non-DPDK thread then it would invalid result. The result would come lcore_config[-1].core_index which is some other data in the per-thread area. The resolution is to return -1 which is what rte_lcore_index() returns if handed an invalid lcore. Same issue existed with rte_lcore_to_cpu_id(). Bugzilla ID: 446 Signed-off-by: Stephen Hemminger --- lib/librte_eal/common/eal_common_lcore.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/common/eal_common_lcore.c b/lib/librte_eal/common/eal_common_lcore.c index 5404922a87d2..1d05234192ba 100644 --- a/lib/librte_eal/common/eal_common_lcore.c +++ b/lib/librte_eal/common/eal_common_lcore.c @@ -31,8 +31,12 @@ int rte_lcore_index(int lcore_id) if (unlikely(lcore_id >= RTE_MAX_LCORE)) return -1; - if (lcore_id < 0) + if (lcore_id < 0) { + if (rte_lcore_id() == LCORE_ID_ANY) + return -1; + lcore_id = (int)rte_lcore_id(); + } return lcore_config[lcore_id].core_index; } @@ -42,8 +46,12 @@ int rte_lcore_to_cpu_id(int lcore_id) if (unlikely(lcore_id >= RTE_MAX_LCORE)) return -1; - if (lcore_id < 0) + if (lcore_id < 0) { + if (rte_lcore_id() == LCORE_ID_ANY) + return -1; + lcore_id = (int)rte_lcore_id(); + } return lcore_config[lcore_id].core_id; } -- 2.20.1