From nobody Tue Apr 7 13:11:19 2026 Received: from mail115-100.sinamail.sina.com.cn (mail115-100.sinamail.sina.com.cn [218.30.115.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EC2420468E for ; Fri, 13 Mar 2026 03:20:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=218.30.115.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773372056; cv=none; b=gV7QRXWqSTMfyudrz7SVLVlmSgX2mN+CVoj1vB3+Zk0qQIywHH6zMCQy4yqzt8PRA8xVNe4uTgrxLog0bI8M9AnYM8qVHu//km4XkdzMlADLr8WPlzCGm8Cu7qCdtRkmkRmiRXLYChHDnLb8EkmYqccaCu7fM1k+YavmBw1/MaQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773372056; c=relaxed/simple; bh=y0Ah/CzvBkpqX7I7vu2xVBl2TW0EAIWYO7FzvuDd4mw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=uarOIonPtbaTyByCH9xqr39QmBs119g7UJwe0ATElmVdofGq69GMxRxmBMjdBBh4gEIZHGSk56EbPxut2TwlynZx1KckDZerJr+IO5CuufQMKIqVBeFLt41fkEoC5OagVU5I+tSHBoDaRLAGnKNvz4w9diJbDNTuGmdr1w6xVTE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sina.com; spf=pass smtp.mailfrom=sina.com; dkim=pass (1024-bit key) header.d=sina.com header.i=@sina.com header.b=GVKTxa/G; arc=none smtp.client-ip=218.30.115.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sina.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sina.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=sina.com header.i=@sina.com header.b="GVKTxa/G" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sina.com; s=201208; t=1773372052; bh=sSJYW5io/4MyT3pXpRddCt5uwN76i4vLd85t6YieSm4=; h=From:Subject:Date:Message-Id; b=GVKTxa/GNuJt9y+fjpH4ggvI6go1utBrv6n14+9FlIyRRoqAkrOI+Hcn1kM5o3CGz 4VkbjiJ1evzjcv8/yaaF29K4BFkTa+jZlxjisCsIXawuRIqtBAKhw7/nAUEebRGWug 3pW01WHJhQxb3lLI3AF84yM3tbT2J99w36sFl6uA= X-SMAIL-HELO: pek-lpg-core6.wrs.com Received: from unknown (HELO pek-lpg-core6.wrs.com)([60.247.85.88]) by sina.com (10.185.250.23) with ESMTP id 69B3826B0000382D; Fri, 13 Mar 2026 11:20:13 +0800 (CST) X-Sender: johnny_haocn@sina.com X-Auth-ID: johnny_haocn@sina.com Authentication-Results: sina.com; spf=none smtp.mailfrom=johnny_haocn@sina.com; dkim=none header.i=none; dmarc=none action=none header.from=johnny_haocn@sina.com X-SMAIL-MID: 3918558912958 X-SMAIL-UIID: 70AA6FCCB42040DE9AC27B7A05CF2B26-20260313-112013-1 From: Johnny Hao To: gregkh@linuxfoundation.org, stable@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kevin Groeneveld , Jacob Keller , Wei Fang , Jakub Kicinski , Johnny Hao Subject: [PATCH 6.1.y] net: fec: handle page_pool_dev_alloc_pages error Date: Fri, 13 Mar 2026 11:20:09 +0800 Message-Id: <20260313032009.2181924-1-johnny_haocn@sina.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Kevin Groeneveld [ Upstream commit 001ba0902046cb6c352494df610718c0763e77a5 ] The fec_enet_update_cbd function calls page_pool_dev_alloc_pages but did not handle the case when it returned NULL. There was a WARN_ON(!new_page) but it would still proceed to use the NULL pointer and then crash. This case does seem somewhat rare but when the system is under memory pressure it can happen. One case where I can duplicate this with some frequency is when writing over a smbd share to a SATA HDD attached to an imx6q. Setting /proc/sys/vm/min_free_kbytes to higher values also seems to solve the problem for my test case. But it still seems wrong that the fec driver ignores the memory allocation error and can crash. This commit handles the allocation error by dropping the current packet. Fixes: 95698ff6177b5 ("net: fec: using page pool to manage RX buffers") Signed-off-by: Kevin Groeneveld Reviewed-by: Jacob Keller Reviewed-by: Wei Fang Link: https://patch.msgid.link/20250113154846.1765414-1-kgroeneveld@lenbroo= k.com Signed-off-by: Jakub Kicinski [ The context change is due to the commit 6c8fae0caf5d (net: fec: simplify the code logic of quirks") in v6.2 which is irrelevant to the logic of this patch. ] Signed-off-by: Johnny Hao --- drivers/net/ethernet/freescale/fec_main.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethern= et/freescale/fec_main.c index c8f897afb30a..e9c4945d0c27 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -1595,19 +1595,22 @@ fec_enet_copybreak(struct net_device *ndev, struct = sk_buff **skb, return true; } =20 -static void fec_enet_update_cbd(struct fec_enet_priv_rx_q *rxq, +static int fec_enet_update_cbd(struct fec_enet_priv_rx_q *rxq, struct bufdesc *bdp, int index) { struct page *new_page; dma_addr_t phys_addr; =20 new_page =3D page_pool_dev_alloc_pages(rxq->page_pool); - WARN_ON(!new_page); - rxq->rx_skb_info[index].page =3D new_page; + if (unlikely(!new_page)) + return -ENOMEM; =20 + rxq->rx_skb_info[index].page =3D new_page; rxq->rx_skb_info[index].offset =3D FEC_ENET_XDP_HEADROOM; phys_addr =3D page_pool_get_dma_addr(new_page) + FEC_ENET_XDP_HEADROOM; bdp->cbd_bufaddr =3D cpu_to_fec32(phys_addr); + + return 0; } =20 /* During a receive, the bd_rx.cur points to the current incoming buffer. @@ -1632,6 +1635,7 @@ fec_enet_rx_queue(struct net_device *ndev, int budget= , u16 queue_id) int index =3D 0; bool need_swap =3D fep->quirks & FEC_QUIRK_SWAP_FRAME; struct page *page; + __fec32 cbd_bufaddr; =20 #ifdef CONFIG_M532x flush_cache_all(); @@ -1686,12 +1690,17 @@ fec_enet_rx_queue(struct net_device *ndev, int budg= et, u16 queue_id) =20 index =3D fec_enet_get_bd_index(bdp, &rxq->bd); page =3D rxq->rx_skb_info[index].page; + cbd_bufaddr =3D bdp->cbd_bufaddr; + if (fec_enet_update_cbd(rxq, bdp, index)) { + ndev->stats.rx_dropped++; + goto rx_processing_done; + } + dma_sync_single_for_cpu(&fep->pdev->dev, - fec32_to_cpu(bdp->cbd_bufaddr), + fec32_to_cpu(cbd_bufaddr), pkt_len, DMA_FROM_DEVICE); prefetch(page_address(page)); - fec_enet_update_cbd(rxq, bdp, index); =20 /* The packet length includes FCS, but we don't want to * include that when passing upstream as it messes up --=20 2.34.1