From patchwork Tue Aug 27 20:27:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magali Lemes X-Patchwork-Id: 1977464 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 4WtfJd4NSGz1yfy for ; Wed, 28 Aug 2024 06:28:48 +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 1sj2np-0006wT-PF; Tue, 27 Aug 2024 20:28:33 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1sj2no-0006vz-Ot for kernel-team@lists.ubuntu.com; Tue, 27 Aug 2024 20:28:32 +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-1.canonical.com (Postfix) with ESMTPS id 810D23F287 for ; Tue, 27 Aug 2024 20:28:32 +0000 (UTC) Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-201e7b422ffso50192335ad.2 for ; Tue, 27 Aug 2024 13:28:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724790510; x=1725395310; 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=RXW5X4bvAPVdfz0USlvoJEQUsdfIfDuPDNFr54JyVj/chVA188dgCt5TujaNpLln3B CK68frx/BKJ9xPCGv5qZpLbT7r2vVMotvD6HOW36gF4jHy+ncmOpd4aUEUfYdA+23rj3 txXhqHBlXDzlTl1vzqV4Wt1+v2bSf1rHf+ntK+IXW93BrfNDski5InJehes6LKdIOPVe GUc41JYCpD1HdeVyOkqD/sQkMZrGex8GjB2rzVDI71acSe41+7qrOfnOOimJLWXgwp5k 7Yippb1SqxeUPTAhwj3kSOn+ghWIs69A+xo08skkGtjdZLDqEY0Xz8Hq955FHHQODkti cnIQ== X-Gm-Message-State: AOJu0YwCpGQoi5nSfn5JSje5riOWMlUOegxf84Tlzboj7vkAh0P78v8V 0YWfAiYDIu8W906irX1UntQ7WBeQjvdKVl8kOoQX0oI8J/FZAtWbT16kPswenf9GH6KkUXUrBbV pUnwwP1SIwIUFEtZF7Nva1jdLa7pF+sD8+8W0OR9uW6Oj7jDRV+ugeq3s3GB2CjDCCXpqdCyA/5 2Psw44mHTE/A== X-Received: by 2002:a17:902:ced0:b0:202:e83:eb11 with SMTP id d9443c01a7336-2039e49513emr148561555ad.29.1724790510487; Tue, 27 Aug 2024 13:28:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE7MKEg/aNEkCsj6Qpz7ufnrLrF1av9XUcym2finPBYs6Fk/Q8ob++jyZwd81cwFek3zKbQRQ== X-Received: by 2002:a17:902:ced0:b0:202:e83:eb11 with SMTP id d9443c01a7336-2039e49513emr148561375ad.29.1724790510015; Tue, 27 Aug 2024 13:28:30 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:14a:8141:7d63:49a5:3ea2:be5d]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20385ae4fddsm86501955ad.255.2024.08.27.13.28.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 13:28:29 -0700 (PDT) From: Magali Lemes To: kernel-team@lists.ubuntu.com Subject: [SRU][noble:linux-gke][PATCH 1/1] gve: Fix an edge case for TSO skb validity check Date: Tue, 27 Aug 2024 17:27:58 -0300 Message-Id: <20240827202758.94037-2-magali.lemes@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240827202758.94037-1-magali.lemes@canonical.com> References: <20240827202758.94037-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;