From patchwork Thu Aug 22 13:20:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magali Lemes X-Patchwork-Id: 1975488 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WqP3v75hkz1yXY for ; Thu, 22 Aug 2024 23:21:31 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1sh7kj-0007lC-RF; Thu, 22 Aug 2024 13:21:25 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1sh7kh-0007kX-NE for kernel-team@lists.ubuntu.com; Thu, 22 Aug 2024 13:21:23 +0000 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 635913F6B5 for ; Thu, 22 Aug 2024 13:21:23 +0000 (UTC) Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-20206086d92so7990945ad.2 for ; Thu, 22 Aug 2024 06:21:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724332881; x=1724937681; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RWcWPj22G2kPiObi1L76Qvrzf3Dwyl3YeqTlIobpeSs=; b=kMIdtl8taIMd/JmfdEPG7CS9VEHfME13EKLSpEv72dAsDaVsAqcru5ma24vZu4I/5n kKQ0Fpemqkj/1j9Za0tvWINovhoBHELGmumVxVLbQprlpkx2M2N6md2udD7NkNF2+6MW dtk6RxOyCxJu6D1dPsfEoDCCH7DCGgnjlX8w7to8wjYWf0CjCPSZz1Q8YfNEpHUOeqWj VB6aGZTLrYhrKYbcKTcceLNQv0kU1bf8+g/tOrY6TDwrzBaATueLmFkENBnRC74WQ5mE TTqUt+7imK4Tuh9b8H8UjLXfz7NXiCUurzyHJpnY8jMebcwZfTYgixcrWuGcOJE7uhms NLZQ== X-Gm-Message-State: AOJu0YxWNGwhSy2cr4ERe+I1Zszc1h63+UzBQgw7x4De3YhB2D8osPKO YBjp3NpmndylzXHVCtlnSXetCc3GMDJzD4sJmAMBIj7d3E+TKNoRwOX6ojX9prNp1Xn9SGxdgRM GqIthEHN3YRrChIHZrWN5LiGaaUdTgVeO6JvLyMOQZbQcLcytgoWvdDkgpUldlBwXv1agqOodjM pW5YUp3LDoFw== X-Received: by 2002:a17:902:ecca:b0:201:fcc1:9ea7 with SMTP id d9443c01a7336-203681c935cmr57776195ad.64.1724332881390; Thu, 22 Aug 2024 06:21:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHuRd9cl429zBwNh0UuEO8DZEpzoCMPgPtmqWnXDXDtNhru3TsCjX9drj70ULCowSXaxBk9AQ== X-Received: by 2002:a17:902:ecca:b0:201:fcc1:9ea7 with SMTP id d9443c01a7336-203681c935cmr57775895ad.64.1724332880870; Thu, 22 Aug 2024 06:21:20 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:14a:8141:b038:b36d:34d:98fa]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2038560e4f6sm12344675ad.193.2024.08.22.06.21.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 06:21:20 -0700 (PDT) From: Magali Lemes To: kernel-team@lists.ubuntu.com Subject: [SRU][noble:linux-gcp][PATCH 1/1] gve: Fix an edge case for TSO skb validity check Date: Thu, 22 Aug 2024 10:20:56 -0300 Message-Id: <20240822132056.1862811-2-magali.lemes@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240822132056.1862811-1-magali.lemes@canonical.com> References: <20240822132056.1862811-1-magali.lemes@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Bailey Forrest BugLink: https://bugs.launchpad.net/bugs/2077571 The NIC requires each TSO segment to not span more than 10 descriptors. NIC further requires each descriptor to not exceed 16KB - 1 (GVE_TX_MAX_BUF_SIZE_DQO). The descriptors for an skb are generated by gve_tx_add_skb_no_copy_dqo() for DQO RDA queue format. gve_tx_add_skb_no_copy_dqo() loops through each skb frag and generates a descriptor for the entire frag if the frag size is not greater than GVE_TX_MAX_BUF_SIZE_DQO. If the frag size is greater than GVE_TX_MAX_BUF_SIZE_DQO, it is split into descriptor(s) of size GVE_TX_MAX_BUF_SIZE_DQO and a descriptor is generated for the remainder (frag size % GVE_TX_MAX_BUF_SIZE_DQO). gve_can_send_tso() checks if the descriptors thus generated for an skb would meet the requirement that each TSO-segment not span more than 10 descriptors. However, the current code misses an edge case when a TSO segment spans multiple descriptors within a large frag. This change fixes the edge case. gve_can_send_tso() relies on the assumption that max gso size (9728) is less than GVE_TX_MAX_BUF_SIZE_DQO and therefore within an skb fragment a TSO segment can never span more than 2 descriptors. Fixes: a57e5de476be ("gve: DQO: Add TX path") Signed-off-by: Praveen Kaligineedi Signed-off-by: Bailey Forrest Reviewed-by: Jeroen de Borst Cc: stable@vger.kernel.org Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20240724143431.3343722-1-pkaligineedi@google.com Signed-off-by: Jakub Kicinski (cherry picked from commit 36e3b949e35964e22b9a57f960660fc599038dd4) Signed-off-by: Magali Lemes --- drivers/net/ethernet/google/gve/gve_tx_dqo.c | 22 +++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/google/gve/gve_tx_dqo.c b/drivers/net/ethernet/google/gve/gve_tx_dqo.c index c40a7bb749bb..66fb75b8cbfe 100644 --- a/drivers/net/ethernet/google/gve/gve_tx_dqo.c +++ b/drivers/net/ethernet/google/gve/gve_tx_dqo.c @@ -812,22 +812,42 @@ static bool gve_can_send_tso(const struct sk_buff *skb) const int header_len = skb_tcp_all_headers(skb); const int gso_size = shinfo->gso_size; int cur_seg_num_bufs; + int prev_frag_size; int cur_seg_size; int i; cur_seg_size = skb_headlen(skb) - header_len; + prev_frag_size = skb_headlen(skb); cur_seg_num_bufs = cur_seg_size > 0; for (i = 0; i < shinfo->nr_frags; i++) { if (cur_seg_size >= gso_size) { cur_seg_size %= gso_size; cur_seg_num_bufs = cur_seg_size > 0; + + if (prev_frag_size > GVE_TX_MAX_BUF_SIZE_DQO) { + int prev_frag_remain = prev_frag_size % + GVE_TX_MAX_BUF_SIZE_DQO; + + /* If the last descriptor of the previous frag + * is less than cur_seg_size, the segment will + * span two descriptors in the previous frag. + * Since max gso size (9728) is less than + * GVE_TX_MAX_BUF_SIZE_DQO, it is impossible + * for the segment to span more than two + * descriptors. + */ + if (prev_frag_remain && + cur_seg_size > prev_frag_remain) + cur_seg_num_bufs++; + } } if (unlikely(++cur_seg_num_bufs > max_bufs_per_seg)) return false; - cur_seg_size += skb_frag_size(&shinfo->frags[i]); + prev_frag_size = skb_frag_size(&shinfo->frags[i]); + cur_seg_size += prev_frag_size; } return true;