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=1796383642; b=ZTf1ndxbAcochWKsQJOS2HhCz3ZPG3jdZepty3ccqnNGpNzI2i7sFd760NdFQbB2HE3J J4sBcZA4LFKIyUIYuvxUQENJeYfTYiahEqmP2+7gcGNKJmOcWyjxW6UOnH9Tr9dcnoi9k uzBnTu6VvXMb1zdn0zEsCfkxY8Mc679z2SaooauKdiMnhy2r2Whwd2ZmoxIF5Uo2S779x FOB1PXV3ISDANxI32KYOKT7ykmKHU14QchdMBeTlupn4klUEvKq168hguauPYzw5crqmX 1sz04lwEl06biOSPm+japm+xmsQK5gqIwEXXc6641/BK31ImCmzpYrRfaIqK8WDGxsg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383642; 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=aaoQXiIYO1RDVqab7o56sX5mlkOeV33z/xsAFUlE0cw=; b=B4f3eH+/diOpdckEQqTzb30WQYr1kFKG+Aw2SfeY0HK075xNwGd1ux3qhBslaqgH+Ls8 F6B/pA0J0DwN1YlbCYX9t8nTB+KuAxKCoaj+zs05FrI3+zbqgvLY7qA1q17SFfJR8I2gG M3wEteMmxQhqxn1lNtJzLodUhrz0i2sXWzt9YMneifWcFfjhAcgs7ekVSw5LrBogRt6N2 mW78Ukw7OVx0ot0MtP9BLkzjYA7fSBI/mH6gyeIIrwbJSgm1YZ5kOa2RNiaQAgm91IYZc a9gbVlFDs3ypAjxhm9JPdlMMBSher5ExI09z+ybTtReo/B9ak0XjcMDQRlilv/qkzNQ== 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=C2OeSiYP; 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 A1887606A322; Fri, 4 Dec 2026 11:27:22 +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=C2OeSiYP Received: by smtp.kernel.org (Postfix) with ESMTPSA id C17571F000CE; Fri, 4 Dec 2026 11:27:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383642; bh=aaoQXiIYO1RDVqab7o56sX5mlkOeV33z/xsAFUlE0cw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=C2OeSiYPkZuuNwLEYZ3CYcR20caLHHQA9qzwZM1ROOFJi+QYw6lXnwVFpTypeXCdt 8kmGTeJbYUC6jb8Js/o+6L1OGP/okWaUGkJ6Tz/kPSIu9tLkQ1KLmXVEslrvrqsye9 b0oFVnaTci8pJjDjA17GrTzQg6DnRDOpxofiItYY= 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.12 309/555] net: dpaa2-eth: fix objtool warning and logic bug Date: Fri, 4 Dec 2026 19:05:52 +0900 Message-ID: <20261204100621.208500921@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@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.12-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 047a09e9e6da2..462af416ee49f 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