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=1796386474; b=eeB8JnEXWE9q493V+zAtsJJQepouCvOU4xr1wCJE8DO0Ku5QNVFUN0rQxN47pWBnI8If hJ2U+ccutCjgqry285SgyxpYdU95amXa+Z2EiTt0BdHeBV/+AzRIcZILv+SY0rw8HauQD MevzSF37BQ4lWo4/z7DtlQNIIx8+wWRRFctrEDAqn5lDkio4dbOx30vLIp8GbAi70vEME 8srwdcBTUfq9oRkIp0WMW3xfddi1KgZouz1hb0reW5+5RQW8Vfvwoec90U1u7LgWNDHMT ElYmB57kDP7J5VXI/xi0vDf7Uq/iDzaRBQdBif0U3D5vb3irVYdjMjJuG48Lu8VvikA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386474; 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=or2Ac1hKVZLBUSau0sebzfTAmlRIWlHMQtDFt0/8x5U=; b=CFYxfFUStRkXTURlCm/3zStaUILiwYrmekiAxY+qlEnu/RmbyQKYkQx//vnEtlYKLznb eG35fnmVT3i7jOr40DNW8EPNJE5tDCsJD0LX05P3kd3e0HcQMYGmcaD6BJhxSE178dDbt kd+uTTDN9mKdRx+LffvbsFibexdNWEjYanfRHz5czTQnUAHzGQ5eHqb4kqi7Rp1SGLTyu 7FHLHyt9R5ozG/8PFeVkHnNva/ZRdK8sGcjOqWznKokxVarCIZwFF/7TSJpRlD0DDLtUj 5BxEc1mECF7AA2KdJvBUWrSoL6iFn4MFiZHV4LNPDOx8XQvJcMya0A1wEEJbEmhViaw== 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=lbAo9ep0; 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 09398606A322; Fri, 4 Dec 2026 12:14:34 +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=lbAo9ep0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7AC6E1F00935; Fri, 4 Dec 2026 12:14:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386473; bh=or2Ac1hKVZLBUSau0sebzfTAmlRIWlHMQtDFt0/8x5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lbAo9ep0sau7te18Y2rg2mbhhayl2+VWpYcz/t9je5Kp6CUhIlskwuBmF0WJgSp7A rP0fyoXyT41GPOWNLYbR+Hj3VoPPVI5mkKo+YaHH8CLwMC8Gs6e7GlSpw2JjGDEZJR YDBpzOJYabDzW59qzg1GDGwXAMM9y2eV5yE/Jsdk= 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.6 0976/1167] net: dpaa2-eth: fix objtool warning and logic bug Date: Fri, 4 Dec 2026 19:06:43 +0900 Message-ID: <20261204100727.619973443@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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.6-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 d77c22d1030a9..8064776366845 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