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 D33AC4562D for ; Tue, 16 Jul 2024 22:52:22 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AF363402C8; Tue, 16 Jul 2024 22:52:22 +0200 (CEST) Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) by mails.dpdk.org (Postfix) with ESMTP id 40BAD40270 for ; Tue, 16 Jul 2024 22:52:21 +0200 (CEST) Received: by mail-yb1-f175.google.com with SMTP id 3f1490d57ef6-e03a17a50a9so6241021276.1 for ; Tue, 16 Jul 2024 13:52:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atomicrules-com.20230601.gappssmtp.com; s=20230601; t=1721163140; x=1721767940; darn=dpdk.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=KkqAfdjh2/UpYS9WxLYXO3TAJAkKkSi5kyD/8a6vS0o=; b=POK2FBb9EHOJNTL/n8C5bQkFFGQhNSP62uV371PSE1vfVMQoeUi7CMjLM9URZRezU4 i2PGzIG4TKnfK6TVc0nJzcknVXKRvb2WWPoPl8Zn1dN+EBhGMHfflRiYxBpxR121N5aB zwGbf4mdTRRPBTEvKEyy4jjMPpXWsBnyRbiCNebVZRylDWupiAF32if5NtLReq3SB6DK rszB18sa/mSLHNUG4p1WdtoZp5uo9gWdYFRa9MdurJRiBsi/+dxIWCvt6e4sZAbk/czm hIPfJ47EH1AwTf/xjddUT4WOaa6BAaonAz69AmSIW/ieZx2U/JVcaUWogJkYb8Q0Dvzm dBog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721163140; x=1721767940; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KkqAfdjh2/UpYS9WxLYXO3TAJAkKkSi5kyD/8a6vS0o=; b=isZqeMMByigzoxX9t4IuGa3uPewf/9Afp9X1WRbIK4/Bs8FaDEQ4P1BZ6ImICM7udj bvY9E1MbQSoGf7ybreTEoSgWNsvMSlfKFisxB+hrMMVC6xJkqsFo3eKt/0KXO42N9nUz XQKA0YD+idNsrw/mjMVYx2vHqj5M7kP4tmrf5nLMkU5AIJk4/RFQCZNwPtOktYpdLmic KbqcCzDOP6qEA6XbWpYDMJwTDRx+t9g3IBym7HmEvidK5tRXe6MvEvWgRPHhDKrwp3JI xmWmR+K6cp6nygveQ6zo9Ok2DHy+nxpX2Y6qUV4Ys2ncgdfZRF29POM91BElkv+nGiOX py4w== X-Gm-Message-State: AOJu0YzJ5W4jXpPiSBUsHRPy+oDDrwAHQWfS1OBWdGamRMEjfuUakUw1 g+R8Ngr7FZE5Ql9ukidjqash7ldWu8mxSLp4UrSBSLejgKaj0pCuVkAzEMX0lXLfPLSe9nNUU5H N2w== X-Google-Smtp-Source: AGHT+IHsWGk12JTOrm+RxD8yBQYzcyvNiu4L9+JE72vdu1RXbaFOhe+JBOnRPAZ7CsiRbIHezecFLQ== X-Received: by 2002:a05:6902:210d:b0:e03:4d43:658f with SMTP id 3f1490d57ef6-e05d5a3fe5bmr4570231276.53.1721163140479; Tue, 16 Jul 2024 13:52:20 -0700 (PDT) Received: from localhost.localdomain (pool-173-48-111-149.bstnma.fios.verizon.net. [173.48.111.149]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b761a0f7e2sm34280176d6.100.2024.07.16.13.52.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jul 2024 13:52:19 -0700 (PDT) From: Ed Czeck To: czeck@ieee.org Cc: stable@dpdk.org Subject: [PATCH] net/ark: fix index arithmetic optimization bug Date: Tue, 16 Jul 2024 16:52:06 -0400 Message-Id: <20240716205206.2556759-1-ed.czeck@atomicrules.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 fix for compiler optimizer error using int32_t. (a - b) > 0 can behave differently under optimization at values near max and min bounds. This patch replaces int32_t with uint32_t except for necessary casts. Fixes: 9ee9e0d3b85e ("net/ark: update to reflect FPGA updates") Cc: stable@dpdk.org Signed-off-by: Ed Czeck --- drivers/net/ark/ark_ethdev_tx.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/net/ark/ark_ethdev_tx.c b/drivers/net/ark/ark_ethdev_tx.c index d02a786ee0..b387dadf80 100644 --- a/drivers/net/ark/ark_ethdev_tx.c +++ b/drivers/net/ark/ark_ethdev_tx.c @@ -39,8 +39,8 @@ struct ark_tx_queue { uint32_t queue_mask; /* 3 indexes to the paired data rings. */ - int32_t prod_index; /* where to put the next one */ - int32_t free_index; /* mbuf has been freed */ + uint32_t prod_index; /* where to put the next one */ + uint32_t free_index; /* mbuf has been freed */ /* The queue Id is used to identify the HW Q */ uint16_t phys_qid; @@ -49,7 +49,7 @@ struct ark_tx_queue { /* next cache line - fields written by device */ RTE_MARKER cacheline1 __rte_cache_min_aligned; - volatile int32_t cons_index; /* hw is done, can be freed */ + volatile uint32_t cons_index; /* hw is done, can be freed */ } __rte_cache_aligned; /* Forward declarations */ @@ -108,7 +108,7 @@ eth_ark_xmit_pkts(void *vtxq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) uint32_t user_meta[5]; int stat; - int32_t prod_index_limit; + uint32_t prod_index_limit; uint16_t nb; uint8_t user_len = 0; const uint32_t min_pkt_len = ARK_MIN_TX_PKTLEN; @@ -124,7 +124,7 @@ eth_ark_xmit_pkts(void *vtxq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) prod_index_limit = queue->queue_size + queue->free_index - 4; for (nb = 0; - (nb < nb_pkts) && (prod_index_limit - queue->prod_index) > 0; + (nb < nb_pkts) && (int32_t)(prod_index_limit - queue->prod_index) > 0; ++nb) { mbuf = tx_pkts[nb]; @@ -194,13 +194,13 @@ eth_ark_tx_jumbo(struct ark_tx_queue *queue, struct rte_mbuf *mbuf, uint32_t *user_meta, uint8_t meta_cnt) { struct rte_mbuf *next; - int32_t free_queue_space; + uint32_t free_queue_space; uint8_t flags = ARK_DDM_SOP; free_queue_space = queue->queue_mask - (queue->prod_index - queue->free_index); /* We need up to 4 mbufs for first header and 2 for subsequent ones */ - if (unlikely(free_queue_space < (2 + (2 * mbuf->nb_segs)))) + if (unlikely(free_queue_space < (2U + (2U * mbuf->nb_segs)))) return -1; while (mbuf != NULL) { @@ -392,10 +392,11 @@ free_completed_tx(struct ark_tx_queue *queue) { struct rte_mbuf *mbuf; union ark_tx_meta *meta; - int32_t top_index; + uint32_t top_index; top_index = queue->cons_index; /* read once */ - while ((top_index - queue->free_index) > 0) { + + while ((int32_t)(top_index - queue->free_index) > 0) { meta = &queue->meta_q[queue->free_index & queue->queue_mask]; if (likely((meta->flags & ARK_DDM_SOP) != 0)) { mbuf = queue->bufs[queue->free_index & -- 2.34.1