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 9D9C645BD2; Fri, 25 Oct 2024 09:39:45 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 26AF540264; Fri, 25 Oct 2024 09:39:45 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 47905400D5 for ; Fri, 25 Oct 2024 09:39:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729841982; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vSN4dNaELc/nezkYAwtrNBCkxdkMGPUJHwn8gSH6e8Y=; b=avPo+EQ5qCS7oqmFAyn/jglYWryxBjFSMf03EhBgTa4K2tS+9d9ZnDt9NZrnmJwtXsLVhV XiZQ6jVeVkfy4gd+cuEqmLlqGOoQ5xZUrpfcTABBZhmN41mYyMmotcC0jKKLxUtIWhsbL4 Rooj+rvtQYn0KoZHQqA9J0YQA3KW/lw= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-602-gX2BBK-2O-CirmmF7zGnfQ-1; Fri, 25 Oct 2024 03:39:41 -0400 X-MC-Unique: gX2BBK-2O-CirmmF7zGnfQ-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BC2AE1955F41; Fri, 25 Oct 2024 07:39:39 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.224.57]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DA14419560A2; Fri, 25 Oct 2024 07:39:34 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: Jack Bond-Preston , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= , =?UTF-8?q?Morten=20Br=C3=B8rup?= , Tyler Retzlaff Subject: [PATCH v2] test/bitops: check worker lcore availability Date: Fri, 25 Oct 2024 09:39:26 +0200 Message-ID: <20241025073926.43621-1-david.marchand@redhat.com> In-Reply-To: <20241011152533.3189097-1-david.marchand@redhat.com> References: <20241011152533.3189097-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 Coverity is not able to understand that having 2 lcores means that rte_get_next_lcore(-1, 0, 1) can't return RTE_MAX_LCORE. Add a check. Coverity issue: 445382, 445383, 445384, 445387, 445389, 445391 Fixes: 35326b61aecb ("bitops: add atomic bit operations in new API") Signed-off-by: David Marchand --- Changes since v2: - added a helper, - prefer RTE_VERIFY(), Note: - a better fix would be to check lcore id validity in the EAL launch API, but it requires inspecting all functions and it could result in some API change, so sending this as a simple fix for now, --- app/test/test_bitops.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/test/test_bitops.c b/app/test/test_bitops.c index 681e984037..78a7df6bb1 100644 --- a/app/test/test_bitops.c +++ b/app/test/test_bitops.c @@ -13,6 +13,17 @@ #include #include "test.h" +static unsigned int +get_worker_lcore(void) +{ + unsigned int lcore_id = rte_get_next_lcore(-1, 1, 0); + + /* avoid checkers (like Coverity) false positives */ + RTE_VERIFY(lcore_id < RTE_MAX_LCORE); + + return lcore_id; +} + #define GEN_TEST_BIT_ACCESS(test_name, set_fun, clear_fun, assign_fun, flip_fun, test_fun, size, \ mod) \ static int \ @@ -158,7 +169,7 @@ test_bit_atomic_parallel_assign ## size(void) \ printf("Need multiple cores to run parallel test.\n"); \ return TEST_SKIPPED; \ } \ - worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \ + worker_lcore_id = get_worker_lcore(); \ lmain.bit = rte_rand_max(size); \ do { \ lworker.bit = rte_rand_max(size); \ @@ -217,7 +228,7 @@ test_bit_atomic_parallel_test_and_modify ## size(void) \ printf("Need multiple cores to run parallel test.\n"); \ return TEST_SKIPPED; \ } \ - worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \ + worker_lcore_id = get_worker_lcore(); \ int rc = rte_eal_remote_launch(run_parallel_test_and_modify ## size, &lworker, \ worker_lcore_id); \ TEST_ASSERT(rc == 0, "Worker thread launch failed"); \ @@ -266,7 +277,7 @@ test_bit_atomic_parallel_flip ## size(void) \ printf("Need multiple cores to run parallel test.\n"); \ return TEST_SKIPPED; \ } \ - worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \ + worker_lcore_id = get_worker_lcore(); \ int rc = rte_eal_remote_launch(run_parallel_flip ## size, &lworker, worker_lcore_id); \ TEST_ASSERT(rc == 0, "Worker thread launch failed"); \ run_parallel_flip ## size(&lmain); \ -- 2.46.2