From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21D6D35E940 for ; Mon, 6 Jul 2026 15:02:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783350156; cv=none; b=MhEWeO+w1+l6dTxNAXq3guoXBSdwNLmRp64+cavtoS6qs8aVTcqul0nUkRAz4KgzgSfgCE4JuaPBnIlJ3mPtCcoY+Sn8vCYXKcSsxlJ5Aj4z0NukZic2M9Pt/QGb2XKpwTU+QpcE4Ni8ePYbWjHkfAhli4fFRjjK5y+k86s7WiU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783350156; c=relaxed/simple; bh=JGzkXl8T4vjevVpJys/9S7aV2vwhdOJ0EE2T8w9o+ZA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P1pTF0gyKVmu7uZ+VjBG5Gw8bMIxZHv3SHf7dbGJCxkBuDePY0Z2eym5fw7i+NfBnP2pdtEHpHPy2cAOkwhEzgz9iXKGEIxPcvnDQWzRFA5vNXwg71E8Z/knXahxEKB5z+yoalWo0Sp9Hu5FhSyg3RxPUIxCg2M1bA20fcdXiNw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YbYEEjjf; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YbYEEjjf" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2cace7da66eso29283295ad.0 for ; Mon, 06 Jul 2026 08:02:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783350154; x=1783954954; darn=vger.kernel.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:content-type; bh=Bk3S36tC0GR663/gxEYgv45wCB/Ce7y/WSTL/b0Dlu4=; b=YbYEEjjfCVZMncjx0L2Jaf6DomVF0tSTUXjtgv4KfIjjpc3U8KO1jxiQ0dEYxVqKEV kP41AfxGQP7shiBnfXXk0oG0O+GEKHdRzhOPL8SBn6JywjW2xZRfSOPIYXRdBH7QQXdm ZfIlFdwohRoVG2N1zCUV7tyqVI6rYodzi5fmzGne0vKXTS5JbsIGr5JzKPyRs8ISQuTn wJBQpo8uUFPM/2ZDEvWooBiNucZx0CMIZXXM3xo+6iKMkCbf8uEvpzj5qBhxhHK5vD72 3UmJFdVwijKNFpePEWzPYj2e4jFIvXkQXk5/QwZF/cIv0zAc2oU5aprnyzlrbCThQagt cMEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783350154; x=1783954954; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Bk3S36tC0GR663/gxEYgv45wCB/Ce7y/WSTL/b0Dlu4=; b=Vqlfyee51EWwuPI8GztoreBuCs+W4B65Kc6CQoy6/WEitAH9ViFCyGgyc1ntJkrx+T nbU0d9Q8rZtesisC1tjQSrVU45XlBY3gGlR9mVAhfie9OiVPonN2ICurzJoAJjE6epuZ d8OkZOHpYWDBVYaR1RaSfTvNkbHhFhqM0OZSTOoDw0sIyQpIoZxLEwPTG5lnzUKQCfBD iGOJePUVAe+VkYL6UBLqmOl/i2MdTG1R+jhaS0pHjI6YJ1WkUsSk0nNwhElE87Xo1+XF 85VV0qwyc9Z4XEznGFdWZCAxzfyk4E9YHdl30C3wq8MkeHVpBKy1pNgZjsMPY9x/O2pg Xx7Q== X-Forwarded-Encrypted: i=1; AHgh+RrIkAcqeKUzfN//6sg4QvJzoA020uc+HtrLLuVrt2rsdwCzrcN7cSYeXwSTYJticxygumfrq6OjMCU8jds=@vger.kernel.org X-Gm-Message-State: AOJu0YzJ4dJ2SIrQzlRn+iEOPUtbqdje+e48AmWrDZdjq+fGra0Z/xMg 8OmtjhJujO0xON5POT1Ar1U2sOQ0Fw+YJNL2n5J24Ok/pesLkKxaT5r6 X-Gm-Gg: AfdE7cmIrdU5nUUtoyX+XTU+IHpyUDAZnmDMR/gszCBFGhfcmQQDgxZ3GxGLL+5veWy 8YLbPKFT53VXSk5F/3g0GiMK/NXn+owh6wUVx+aNTv8tMcYsv0T/8Z++lqhGY4c9iABbdUdCLUR HQ5B4SwXRCFQf0Abb2zxCMkJfE95nuK7VQFPwjvVYsDmesa+Cp6Sm9F7IPOtV4PJtQMSMsnPoAw Jb/Q8MewpUFh1Y7cDv9S+33cOLnSilWFihqbiqVmEGBiCh/pXVr7R1hbjijnjAy3FgOXHZ00Pjy j2cE1mqFlMFAU+AwYjcoOnZaXv2LMabgI3g568oRvtcTx2u1/7am6jkGGVbXKaVfEwwB7XSKH6U mZiLQ5b2m5CNJAGAhk/yUxwIYKmf+Jcbsm9gpGUzYUJbXAKRXTU6gKuuzqr9oXCPvwAoO1pdBgk PCnwCmzOjYShO7ZhzBg1Dp6iHf/+vlLfltxv02jw== X-Received: by 2002:a17:902:c404:b0:2c9:97a7:3278 with SMTP id d9443c01a7336-2ccbf1828b0mr10330665ad.41.1783350153050; Mon, 06 Jul 2026 08:02:33 -0700 (PDT) Received: from csl-conti-dell7858.ntu.edu.sg ([155.69.195.57]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cb3f5b7090sm41651765ad.26.2026.07.06.08.02.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 08:02:32 -0700 (PDT) From: Maoyi Xie To: Veerasenareddy Burru , Sathesh Edara , Satananda Burla , Shinas Rasheed Cc: Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maciej Fijalkowski , Guangshuo Li , David Carlier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net v4 3/3] octeon_ep_vf: fix skb frags overflow in the RX path Date: Mon, 6 Jul 2026 23:02:08 +0800 Message-Id: <20260706150208.2944898-4-maoyixie.tju@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260706150208.2944898-1-maoyixie.tju@gmail.com> References: <20260706150208.2944898-1-maoyixie.tju@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit __octep_vf_oq_process_rx() has the same unbounded fragment loop as the PF driver. buff_info->len comes from the device response header. The loop adds one fragment per buffer_size chunk with no check against MAX_SKB_FRAGS. A long packet yields about 18 fragments. That is one past the default MAX_SKB_FRAGS of 17. skb_add_rx_frag() then writes past shinfo->frags[]. The fragment count is now checked before napi_build_skb(). A packet that needs more fragments than the skb can hold is dropped. octep_vf_oq_drop_rx() drains those descriptors. It also frees the head page and every fragment page. The previous patch added those frees to the inline drop path. The napi_build_skb() failure path now uses the same helper. Fixes: 1cd3b407977c ("octeon_ep_vf: add Tx/Rx processing and interrupt support") Co-developed-by: Kaixuan Li Signed-off-by: Kaixuan Li Signed-off-by: Maoyi Xie --- .../marvell/octeon_ep_vf/octep_vf_rx.c | 50 ++++++++++++------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_rx.c b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_rx.c index 302559b16b..e7733b41a1 100644 --- a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_rx.c +++ b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_rx.c @@ -357,6 +357,31 @@ static inline u32 octep_vf_oq_next_idx(struct octep_vf_oq *oq, u32 idx) return (idx + 1 == oq->max_count) ? 0 : idx + 1; } +static void octep_vf_oq_drop_rx(struct octep_vf_oq *oq, + struct octep_vf_rx_buffer *buff_info, + void *resp_hw, u32 *read_idx, u32 *desc_used) +{ + u16 data_len = buff_info->len - oq->max_single_buffer_size; + + put_page(virt_to_page(resp_hw)); + (*desc_used)++; + *read_idx = octep_vf_oq_next_idx(oq, *read_idx); + while (data_len) { + dma_unmap_page(oq->dev, oq->desc_ring[*read_idx].buffer_ptr, + PAGE_SIZE, DMA_FROM_DEVICE); + buff_info = (struct octep_vf_rx_buffer *) + &oq->buff_info[*read_idx]; + put_page(buff_info->page); + buff_info->page = NULL; + if (data_len < oq->buffer_size) + data_len = 0; + else + data_len -= oq->buffer_size; + (*desc_used)++; + *read_idx = octep_vf_oq_next_idx(oq, *read_idx); + } +} + /** * __octep_vf_oq_process_rx() - Process hardware Rx queue and push to stack. * @@ -432,27 +457,16 @@ static int __octep_vf_oq_process_rx(struct octep_vf_device *oct, struct skb_shared_info *shinfo; u16 data_len; + data_len = buff_info->len - oq->max_single_buffer_size; + if (DIV_ROUND_UP(data_len, oq->buffer_size) > MAX_SKB_FRAGS) { + octep_vf_oq_drop_rx(oq, buff_info, resp_hw, &read_idx, &desc_used); + continue; + } + skb = napi_build_skb((void *)resp_hw, PAGE_SIZE); if (!skb) { oq->stats->alloc_failures++; - put_page(virt_to_page(resp_hw)); - desc_used++; - read_idx = octep_vf_oq_next_idx(oq, read_idx); - data_len = buff_info->len - oq->max_single_buffer_size; - while (data_len) { - dma_unmap_page(oq->dev, oq->desc_ring[read_idx].buffer_ptr, - PAGE_SIZE, DMA_FROM_DEVICE); - buff_info = (struct octep_vf_rx_buffer *) - &oq->buff_info[read_idx]; - put_page(buff_info->page); - buff_info->page = NULL; - if (data_len < oq->buffer_size) - data_len = 0; - else - data_len -= oq->buffer_size; - desc_used++; - read_idx = octep_vf_oq_next_idx(oq, read_idx); - } + octep_vf_oq_drop_rx(oq, buff_info, resp_hw, &read_idx, &desc_used); continue; } rx_bytes += buff_info->len; -- 2.34.1