From patchwork Thu Aug 22 13:54:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magali Lemes X-Patchwork-Id: 1975519 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 4WqPpd0jQ8z1yXY for ; Thu, 22 Aug 2024 23:55:05 +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 1sh8HE-0003sF-79; Thu, 22 Aug 2024 13:55:00 +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 1sh8HC-0003rI-Qa for kernel-team@lists.ubuntu.com; Thu, 22 Aug 2024 13:54:58 +0000 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.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 8C9163F6B5 for ; Thu, 22 Aug 2024 13:54:58 +0000 (UTC) Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-7cd98f27becso882996a12.3 for ; Thu, 22 Aug 2024 06:54:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724334896; x=1724939696; 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=jynhbV18Td2Rpw0SRHLwZ1ukn0V3tjQ5i7FQsjyGSsk=; b=Jm4piiDOWMNmb+0rDqZFkPo6kgIPfIXX+icmdRnxChtYQOF/HFK51N8a5WZaFqDqWp iAxWQR7TbRAehgMpLBOjmbLeX75ZjUzIR9vZtBMol37KoRBhoreq1UHR2DuTqh9eZRY8 Y3gEbDJPlpbRiH6UMzsskSlsoWyHCGS6HgKj04gFXJlWxCGjQ8HTBM9cBuGrvDT8dusc PTTp3tJkqPv/bcJ6k+VpI/0e2iKsqGjQZQzmmPxOLacoz7wkaNu+XIhbnGLiHOqdN6Yt u+Bcve+8rJdDnFtMVaCEVVzLShYf1uHfrPGTyePV0rjDtKPD0fDyFwktwIBiqPPmYCPq oAOw== X-Gm-Message-State: AOJu0YxLh4ACcMFrn3IYd0hcIZDRafpyYREiy/K1ObPPHMCiykr8tC9W G4/SmmLWotorJoRgs8lSH4PD7ZQpo4hE7dTMlmxfwHZCW099qvOAMhqljPRNlnhuIc/aSYunFbJ m5GI7Kh86ooMbJ0IRueA1RlzKe8m1y33GQgqHhjh6F393eWwo0TMMmaI0b7KPK61dVz5CCbbVPO e1vRS0IA/h3g== X-Received: by 2002:a17:902:e809:b0:202:3dcf:8c38 with SMTP id d9443c01a7336-2036808f87bmr68256085ad.44.1724334896558; Thu, 22 Aug 2024 06:54:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHBZxYSGPdTVPoOqzhGGxryZrGWNekcXTy4tzFqymB/ZfZBE0ETxm98oScDGCqGejYl+yh1OA== X-Received: by 2002:a17:902:e809:b0:202:3dcf:8c38 with SMTP id d9443c01a7336-2036808f87bmr68255855ad.44.1724334896129; Thu, 22 Aug 2024 06:54:56 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:14a:8141:b038:b36d:34d:98fa]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20385581b4csm12902965ad.111.2024.08.22.06.54.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 06:54:55 -0700 (PDT) From: Magali Lemes To: kernel-team@lists.ubuntu.com Subject: [SRU][jammy:linux-gcp][PATCH 2/2] gve: Fix an edge case for TSO skb validity check Date: Thu, 22 Aug 2024 10:54:29 -0300 Message-Id: <20240822135429.1873646-3-magali.lemes@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240822135429.1873646-1-magali.lemes@canonical.com> References: <20240822135429.1873646-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 0abdc258f7815..9e7949b8fc73d 100644 --- a/drivers/net/ethernet/google/gve/gve_tx_dqo.c +++ b/drivers/net/ethernet/google/gve/gve_tx_dqo.c @@ -813,22 +813,42 @@ static bool gve_can_send_tso(const struct sk_buff *skb) const struct skb_shared_info *shinfo = skb_shinfo(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;