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 8F6954562D for ; Tue, 16 Jul 2024 23:39:44 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8944440E50; Tue, 16 Jul 2024 23:39:44 +0200 (CEST) Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com [209.85.219.179]) by mails.dpdk.org (Postfix) with ESMTP id 8C0574065B for ; Tue, 16 Jul 2024 23:39:43 +0200 (CEST) Received: by mail-yb1-f179.google.com with SMTP id 3f1490d57ef6-dfe43dca3bfso6254777276.0 for ; Tue, 16 Jul 2024 14:39:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atomicrules-com.20230601.gappssmtp.com; s=20230601; t=1721165983; x=1721770783; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xZLzWCaClq9RrhCWTV+EnhXMvHjLUSMNtbDHazGGMFQ=; b=VsdbsO5Q2CQroBgE5nJbZ5uaGpWmQozBcOr1Uv7fFakvj7jgEFNMvC8vPMRjcOUtvt eCfHF/lkLQBByCRi5/daFvNPZTjtSTme5nMIUil0IW8c/DajRBhIxBZnVHmx8B8u7wjy xOivBOGEm1uIU5pCljJT1eIONJIDgfeOI5AJG3GYf21iODmKbWgvTuTm435Z9d8iQucH g6bbCkNv4RBL5be1vrWgpRV9fkoBKIYDExFlTEHYEwAMQ+2rgdOTEofJ2QqZAx3GJrBj bcZJzWAc0tn211fHBG1b66NiB4YbmLB+l2RunRosASyjb2rH4apgq6EbsvpDIDZXcSYy xT1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721165983; x=1721770783; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xZLzWCaClq9RrhCWTV+EnhXMvHjLUSMNtbDHazGGMFQ=; b=nupo5UmccnU/PIWFpFs+PeSZa9Q4BLnquHxBFyGsejgTo4Eecas+wGhc5GTiSZ2pas bG0PzA12Ls7BJZHrryY/byOzr5ZtqjlSegt80T8iEVKml/4qyOHxIP9V2tJUagtPNhEx SwDZYreSOYQPm7zppY46WCyN6whl4qKTJ8rwMr+kkKDAbvv697RyEatTjUnBzChWl4NY FZXbnlGLD61ieDjXOjCoG3T30j26oDVHzvPlp2/ESJou5pXxCKRsQk11t7vGq3CUIKHj jOGyTTspBjNIDfxlnvYMdpFMlDj3J1aA9QOwrUgTRqjonw8tJw0LOp2QVVkP+E8/VRhg J+jQ== X-Gm-Message-State: AOJu0YyVw4exZxrwDFSn7K4rDcRkedftz3rcTnzAjmTlNROKR4DQ1EUY Tm5U9K7SI0INS5NNHnKpdVEX1YCkHG7ZH3RUBR092ICNpbDgzDdmFBNlN9XnmQ== X-Google-Smtp-Source: AGHT+IF++K2hXnUSigfez/vLKcabdbZyDoWQbmHz2163o6IFMhQK8ZMN/OOVkuwYKX7NpuRfvrpIhQ== X-Received: by 2002:a05:6902:2b8e:b0:dff:1a17:dcbc with SMTP id 3f1490d57ef6-e05d5d58edbmr3759605276.2.1721165982755; Tue, 16 Jul 2024 14:39:42 -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-6b76194f417sm34830676d6.23.2024.07.16.14.39.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jul 2024 14:39:42 -0700 (PDT) From: Ed Czeck To: dev@dpdk.org, ferruh.yigit@amd.com Cc: stable@dpdk.org, Shepard Siegel , John Miller Subject: [PATCH v2] net/ark: fix index arithmetic optimization bug Date: Tue, 16 Jul 2024 17:39:39 -0400 Message-Id: <20240716213939.2561065-1-ed.czeck@atomicrules.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240716210631.2557642-1-ed.czeck@atomicrules.com> References: <20240716210631.2557642-1-ed.czeck@atomicrules.com> 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 --- v2: * update patch to apply to dpdk-next-net --- 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 9c89c85f50..30130b08de 100644 --- a/drivers/net/ark/ark_ethdev_tx.c +++ b/drivers/net/ark/ark_ethdev_tx.c @@ -39,8 +39,8 @@ struct __rte_cache_aligned 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 __rte_cache_aligned ark_tx_queue { /* next cache line - fields written by device */ alignas(RTE_CACHE_LINE_MIN_SIZE) RTE_MARKER cacheline1; - volatile int32_t cons_index; /* hw is done, can be freed */ + volatile uint32_t cons_index; /* hw is done, can be freed */ }; /* 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