From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796382230; b=3KqBaZ+JYZ4Dw8S2lX7XWkNm+5edj8noRBJutvmUCnc02XDsqY5cGOibkRLpg+7LNPQX sF1qdIhmzRamWLBicu82HiDj85V41WVmWvxDR/7n91w448P/DT/Krsjcp1cdmofdJGqa1 MVcJOdCRJSaYNimqPzxk7z+HHOIQzw7QCMztP8z5YDAIgEEmkBcz1AQeJoO44hgvB3m2c eYg3aDycy6qESuYtJmbplT57t58wl38ebA7CMAurrPHLtidchTMM8FtXXM/iWmeFstEj+ oNSZCtw9PSCc/i0ud9jneObv9S/yvPKP+VVZ62X6tiY/FRU4Q40HGCLAZij+mV2Dvfw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382230; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=VhSKx8ofjnVHKuvFux0cxdHajE5/ajMidLTnLlLLRLw=; b=p2tARwSrPYNUJTxOTsVKaZd9vg6YFzt6RjHNI2QPpdlCNVqyRHTYp2ZCsJc3HO0wlmhN Gz+q2+29b2j6XIrqrKSJPTB4k1Ar9wxk3uRiRdjnvkqaWMylTikrUapoH3j+UXWkOpoaA m/I9xywsgKtvM09XdLU8bD/Dl/Kb7qYpdEPII70784mENmwnKY+/Xn1rAqxXghxiU1BYm jQ6Mu+ZlypMg4RaYhefVSaX1D+EQ9YYoFU+q9/SWwZOIxW0ZKLqdristgXKf2MN9R45Ae xqt1o6KSUFNFiyXu2OlpM07j72mMmKy30TRvfYJnRt5I7vcB4QN0d0UpGBCFb0WlWBg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=skLSFNnF; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 347A2606A32C; Fri, 4 Dec 2026 11:03:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=skLSFNnF Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4B531F000C2; Fri, 4 Dec 2026 11:03:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382230; bh=VhSKx8ofjnVHKuvFux0cxdHajE5/ajMidLTnLlLLRLw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=skLSFNnFi0hQonVr6S4sMlViVB0RGBsLMp9J0TxsxRizzybCG3jG4At9YF2pxhPN2 k8xegxar65lqWJ6rl/tllSYKCKNLWcVn8wvzX4xBWoE9BB+pza547NRMi0w5Egdk8Q R88A2KWugMx8FlEdy7pNWHRpzoMnDLmo6/36v4qk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Robert-Ionut Alexa , Ioana Ciornei , "David S. Miller" , Andrew Lunn , Jakub Kicinski , Paolo Abeni , Linus Torvalds , Sasha Levin Subject: [PATCH 6.18 323/703] net: dpaa2-eth: fix objtool warning and logic bug Date: Fri, 4 Dec 2026 19:03:42 +0900 Message-ID: <20261204100636.368717640@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Linus Torvalds [ Upstream commit 25faec9ce61c01fb45abf812a222c5b43c3cd5c5 ] This commit came about because I locally had a build with COMPILE_TEST and various runtime hardening features (that don't make sense for a pure build test anyway) disabled - and objtool complained about some of the code as a result: drivers/net/ethernet/freescale/dpaa2/fsl-dpaa2-eth.o: warning: objtool: dpaa2_eth_add_bufs+0x3f8: stack state mismatch: reg1[15]=-1+0 reg2[15]=-2-208 The reason seems to be that without the hardening features, objtool notices that gcc is doing really odd things with the 'page' variable, which is uninitialized in the path where 'ch->xsk_zc' is true. Now, this seems to be just objtool becoming confused about some ugly code, but that code is _also_ actively buggy in a different way, so let's just fix this all. What confuses objtool seems to be the stack slot for the uninitialized 'page' variable - for the case where that variable isn't actually used. There is some shared error handling code that frees the previously allocated page or xsk buffers depending on previous state. That code is ugly and worth fixing: just free the page or buffers in the context where they are actually allocated, not at some common point where you have to wonder "which one is it I'm supposed to free again?". That gets rid of the objtool warning, because now gcc doesn't take messy and incomprehensible source code and turn it into messy and even more incomprehensible object code any more. No more questionable stack frames with CFI information that blows objtool's little mind. But fixing that then makes a real bug more obvious: the freeing of the xsk buffers is buggy. It frees the buffers that never got mapped: for (; i < batch; i++) xsk_buff_free(xdp_buffs[i]); and that looks sane enough: iterate over the unused part of the batch. But it's horrendously wrong, because it updates 'i'. And 'i' isn't some harmless little local loop counter. It's the variable that is supposed to contain how many buffers have been successfully mapped. So now that 'free the buffers we didn't map' loop ends up updating that counter, and after the loop 'i' will be the whole batch we allocated. So that loop first freed the buffers that failed to map, and then as a side effect said "all these buffers I just freed were successfully mapped" and they would be released to hardware. So objtool didn't actually find a real bug. It just found code that was so ugly that it triggered a false positive. And as is often the case with ugly code: people hadn't understood it either, and it was buggy. It's worth noting that the code is still ugly. A variable name like 'i' is perfectly fine for some random anonymous loop iterator that is just that. But when it has serious meaning outside the loop, you should give it a serious name that makes sense non-locally. This does not fix that kind of ugliness. This is just the minimal fix for the objtool warning and the entirely incidental bug it then uncovered. They had nothing in common except for the obfuscated C code contest entry. Fixes: 48276c08cf5d ("net: dpaa2-eth: AF_XDP RX zero copy support") Cc: Robert-Ionut Alexa Cc: Ioana Ciornei Cc: David S. Miller Cc: Andrew Lunn Cc: Jakub Kicinski Cc: Paolo Abeni Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- .../net/ethernet/freescale/dpaa2/dpaa2-eth.c | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c index 6fd478572ef8f..964ec0fcf739d 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c @@ -1679,11 +1679,9 @@ static int dpaa2_eth_add_bufs(struct dpaa2_eth_priv *priv, struct device *dev = priv->net_dev->dev.parent; u64 buf_array[DPAA2_ETH_BUFS_PER_CMD]; struct dpaa2_eth_swa *swa; - struct page *page; dma_addr_t addr; int retries = 0; int i = 0, err; - u32 batch; /* Allocate buffers visible to WRIOP */ if (!ch->xsk_zc) { @@ -1693,14 +1691,16 @@ static int dpaa2_eth_add_bufs(struct dpaa2_eth_priv *priv, * the entire page except for a tailroom reserved for * skb shared info */ - page = dev_alloc_pages(0); + struct page *page = dev_alloc_pages(0); if (!page) goto err_alloc; addr = dma_map_page(dev, page, 0, priv->rx_buf_size, DMA_BIDIRECTIONAL); - if (unlikely(dma_mapping_error(dev, addr))) - goto err_map; + if (unlikely(dma_mapping_error(dev, addr))) { + __free_pages(page, 0); + goto err_alloc; + } buf_array[i] = addr; @@ -1716,8 +1716,8 @@ static int dpaa2_eth_add_bufs(struct dpaa2_eth_priv *priv, * of DPAA2_ETH_BUFS_PER_CMD. Bail out if the UMEM cannot * provide enough buffers at the moment */ - batch = xsk_buff_alloc_batch(ch->xsk_pool, xdp_buffs, - DPAA2_ETH_BUFS_PER_CMD); + u32 batch = xsk_buff_alloc_batch(ch->xsk_pool, xdp_buffs, + DPAA2_ETH_BUFS_PER_CMD); if (!batch) goto err_alloc; @@ -1727,8 +1727,11 @@ static int dpaa2_eth_add_bufs(struct dpaa2_eth_priv *priv, swa->xsk.xdp_buff = xdp_buffs[i]; addr = xsk_buff_xdp_get_frame_dma(xdp_buffs[i]); - if (unlikely(dma_mapping_error(dev, addr))) - goto err_map; + if (unlikely(dma_mapping_error(dev, addr))) { + for (int j = i; j < batch; j++) + xsk_buff_free(xdp_buffs[j]); + goto err_alloc; + } buf_array[i] = addr; @@ -1759,13 +1762,6 @@ static int dpaa2_eth_add_bufs(struct dpaa2_eth_priv *priv, return i; -err_map: - if (!ch->xsk_zc) { - __free_pages(page, 0); - } else { - for (; i < batch; i++) - xsk_buff_free(xdp_buffs[i]); - } err_alloc: /* If we managed to allocate at least some buffers, * release them to hardware -- 2.53.0