From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 30DDD2E7391 for ; Thu, 16 Jul 2026 06:34:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784183692; cv=none; b=q/5W1tOP0FSkxKKPPtOSL8qWYVolKNq+v6vKwiSpOayyXct0s/FViZCiUTue9azkYHFsrJNVydCH890x7EeIUpseicv02AjTuEm2lBxlD9Y13bK0QedAgaz4K2ptl5qTewqGgtNjawR6u/4w28UGIgPkXndLlnKWumDgUN/3fsc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784183692; c=relaxed/simple; bh=vwtzLaUn7wHgUAalpp5RyegEj5VMiUcE2KwC9OxQpoA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hn6ffTNMERwgO0zJo9c5F6bRdY7QhueeFNCpF2sSPefIVpcH+rTGmhflfm1fZG/GNoM58nV4mfLwJzrnLzp/QM2iOawoDSGhEr3OpqbywgHyExxaYPXSpjflNFg5Njote9ns5ekgtIohA4vU08XQSo6PX+xTJYHrtH3mpcsEHVw= 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=nbdkXmL4; arc=none smtp.client-ip=209.85.210.170 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="nbdkXmL4" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-848761b5897so3275443b3a.3 for ; Wed, 15 Jul 2026 23:34:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784183690; x=1784788490; 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=GwXxw7O4TWZvXWtuVAmXlGrveb0Tk1fsMJGJIBcnjmk=; b=nbdkXmL46zpBls7LPE4Ql/QjaIyicnvx7h+gpaWtq3xr+D49YtGTfMvoF0Wj4uGAgx IeNBy539JJ7tVL8y4404MTz1EPGHVfjErPqJV5/djiMTKfnxGx2Be5popFww8VFrqMkL PimpZsiM1XkvuJIdmMWklR8LWbihstK2pAGz0Tqvk+ziy8QB3yp4vqea5LwU5IuL9CmN lSx6lnDruyqGMUvXrabbmVBw0qBye0h0YYwWxKDmSCx/HB0cIhTyFvVLRSAuN3PWBJDY 6RWKnsJqbCRbqacMqpkyWpxflE+DrrRyZANgeYFR2arCRk2wbyn5/h4oLdjJ57yz3Znr UbsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784183690; x=1784788490; 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=GwXxw7O4TWZvXWtuVAmXlGrveb0Tk1fsMJGJIBcnjmk=; b=RxVCEjSLHAhzoZfK1TWSRhBOkRDB6fPKZl/YFSL59LqqO397PQHF0MVoNJGOrCFLVb ckv2aTAMSWkR/F4xOmfpfbEo9jrAHS4W7rn0S7/pjalb3hpjlusTZdTN8fuk/Aio7P+l Pem1JkQmywAgIhsbN66nXTkcziExhPqmHkUHWfbOxF/OtYntzARDglPETTRyQ8T3Xy8y +gvjNk0rToQN2Vj+LTj96gDPaoYJAfAPCno1uErMsqrILBeCaB7WTz2x6uURdC49UOnR 3JmmvKXGqRrLu4ltAnC7oNmigSOG3N7S40jFPj5jth2cEZ6/kcJK+hd00nwmoIC9MRNH TZyQ== X-Forwarded-Encrypted: i=1; AHgh+Rps4FEqjFyGtnlOxG+Op5Bc8JXxK6p6FSPlctTUzqJIOccVnNSnTJ1TYsepSMXXw7sqMDe79DE37P4mViI=@vger.kernel.org X-Gm-Message-State: AOJu0YxsEoL/KprkT99Lm151ikA1D/lfgRYURq32AZdyst4SSQ4fgefw 8GxhnriuZFW9BuSJUc2EearHfp/IDQ57hLbUpKlKtZAM2PDA8XfL37NL X-Gm-Gg: AfdE7cnJdmVwzWZnYTuqjanxGknHt5J87aPgMxarwvsvOcsVHyglqjh6L/9yz2dMzSr W4PQ6a0rFcuXACyqUim9ktPj06/mOGFGt5dXwLVUikrgbyIdsgCjjF9Yy6iob+m4cIY0PZMFOMq M0QRdte4JMEUJneUxd6LLZV50cx/C85NXac758Mpn5ck004pkSz7Z6nLE8KEy2KZpdFppy1IFVN 7KI1RGYrr7r0cPfz4qw6JXz/V4FsqkMy+lXakzVkHVD0hjbiZMmerFLBEBz1aUBPFQNfQ/J+9xu qIDZyO9dZe2YwNbbkt0jyLBsW9fBj9cEs8s1w6ML0O3+1EAGCdpXZXyjsm5VQR2VV7XNEfaseSm U3zEz63FLQCKgDCRTlOh+S1p/ALns4KMKqa2/oZ/830kuKdoVFv9wEvUjvwlonrw4QtBdCqmsL8 AR0iKQvPXZHOPiHU8NeFZsFIWAzVcGVUEluNV99Q== X-Received: by 2002:a05:6a00:2da4:b0:845:e41f:9696 with SMTP id d2e1a72fcca58-84a5574252bmr8683937b3a.25.1784183690556; Wed, 15 Jul 2026 23:34:50 -0700 (PDT) Received: from csl-conti-dell7858.ntu.edu.sg ([155.69.195.57]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84a4f7dadcfsm4242172b3a.48.2026.07.15.23.34.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jul 2026 23:34:50 -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 , Simon Horman , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net v5 3/3] octeon_ep_vf: fix skb frags overflow in the RX path Date: Thu, 16 Jul 2026 14:34:32 +0800 Message-Id: <20260716063432.2908100-4-maoyixie.tju@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260716063432.2908100-1-maoyixie.tju@gmail.com> References: <20260716063432.2908100-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 | 52 ++++++++++++------- 1 file changed, 33 insertions(+), 19 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..138e779f7e 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) +{ + u32 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. * @@ -430,29 +455,18 @@ static int __octep_vf_oq_process_rx(struct octep_vf_device *oct, read_idx = octep_vf_oq_next_idx(oq, read_idx); } else { struct skb_shared_info *shinfo; - u16 data_len; + u32 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