From patchwork Thu Aug 22 13:54:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magali Lemes X-Patchwork-Id: 1975518 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 4WqPpZ6bR2z1yf6 for ; Thu, 22 Aug 2024 23:55:02 +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 1sh8HC-0003qh-2h; Thu, 22 Aug 2024 13:54:58 +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 1sh8HA-0003q7-P6 for kernel-team@lists.ubuntu.com; Thu, 22 Aug 2024 13:54:56 +0000 Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) (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 98DCE3F6B5 for ; Thu, 22 Aug 2024 13:54:56 +0000 (UTC) Received: by mail-pg1-f199.google.com with SMTP id 41be03b00d2f7-7c6b4dcb60aso353683a12.0 for ; Thu, 22 Aug 2024 06:54:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724334894; x=1724939694; 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=BS3sWOTJLug2siA6b/GCzWyg8iFEMohqJTkN5ce+UWo=; b=ccDIiGXh7aBCFjRHVzghBRCA3Y7q/HNOGCpkNo403RAC+pVXSOEHaVgaJ9+DceG/vH fvMTCaxrBL9jKBz95jwRXy5KuODSWV0gzz4zWm1BFGr0VqW9c3nVS0DKthNtRRK4dq/l zv1aslnLeg7ORbV3qpEuIBtQd8kGV/SAJGKSNpX5qixEUjHxfZ/kPDbNjjWciQXKNRUl afdplOaTnGHySUMbLafVv6EDyxyvUs8hSKU98ij5m/kyYQuBdwo/zo0NkOQF9gQQfT8S qf3oBBBfP5WGMH9bWnhmNS4JV1mRfLON2giKm8CLDeNoN4HMoIfoNE0LGmGVyQSEO5CD nZqA== X-Gm-Message-State: AOJu0YyXAIa4WQDRBcS3tDbm+YZE85qHBL8wwmHW1vAL2THilAR9aKTX wWX0OPfuznGXPHtOSJTOPN38TJ1PnACGt4iB4p6xwNJlgMNdzB8Aiqy03mHj3avSYcwQKO9+CbG 6tqblkNKvdm55lpYihtRKPHG6gPurr8U1styYOU8EPkdXMCgtNzj8pb+Kq2vinermaDemTEDO+Q kSpmtw+xJKIw== X-Received: by 2002:a17:902:c950:b0:201:f9c1:f543 with SMTP id d9443c01a7336-2038820c6f5mr19968005ad.18.1724334894634; Thu, 22 Aug 2024 06:54:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwCGJbz5ZfsYUs0m2hntkBjijr7vQxOjNkP+yQ4uPP0gbLaLYvWfpwz5qZp05FB4Ed20o9Jw== X-Received: by 2002:a17:902:c950:b0:201:f9c1:f543 with SMTP id d9443c01a7336-2038820c6f5mr19967795ad.18.1724334894232; Thu, 22 Aug 2024 06:54:54 -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.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 06:54:53 -0700 (PDT) From: Magali Lemes To: kernel-team@lists.ubuntu.com Subject: [SRU][jammy:linux-gcp][PATCH 1/2] gve: ignore nonrelevant GSO type bits when processing TSO headers Date: Thu, 22 Aug 2024 10:54:28 -0300 Message-Id: <20240822135429.1873646-2-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: Joshua Washington BugLink: https://bugs.launchpad.net/bugs/2077571 TSO currently fails when the skb's gso_type field has more than one bit set. TSO packets can be passed from userspace using PF_PACKET, TUNTAP and a few others, using virtio_net_hdr (e.g., PACKET_VNET_HDR). This includes virtualization, such as QEMU, a real use-case. The gso_type and gso_size fields as passed from userspace in virtio_net_hdr are not trusted blindly by the kernel. It adds gso_type |= SKB_GSO_DODGY to force the packet to enter the software GSO stack for verification. This issue might similarly come up when the CWR bit is set in the TCP header for congestion control, causing the SKB_GSO_TCP_ECN gso_type bit to be set. Fixes: a57e5de476be ("gve: DQO: Add TX path") Signed-off-by: Joshua Washington Reviewed-by: Praveen Kaligineedi Reviewed-by: Harshitha Ramamurthy Reviewed-by: Willem de Bruijn Suggested-by: Eric Dumazet Acked-by: Andrei Vagin v2 - Remove unnecessary comments, remove line break between fixes tag and signoffs. v3 - Add back unrelated empty line removal. Link: https://lore.kernel.org/r/20240610225729.2985343-1-joshwash@google.com Signed-off-by: Jakub Kicinski (backported from commit 1b9f756344416e02b41439bf2324b26aa25e141c) [magalilemes: missing upstream commit 504148fedb85 ("net: add skb_[inner_]tcp_all_headers helpers") causes a context conflict, which is safe to ignore. Accept incoming changes and replace the call to the skb_tcp_all_headers() helper with its implementation.] Signed-off-by: Magali Lemes --- drivers/net/ethernet/google/gve/gve_tx_dqo.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve_tx_dqo.c b/drivers/net/ethernet/google/gve/gve_tx_dqo.c index d36d68e281073..0abdc258f7815 100644 --- a/drivers/net/ethernet/google/gve/gve_tx_dqo.c +++ b/drivers/net/ethernet/google/gve/gve_tx_dqo.c @@ -502,28 +502,18 @@ static int gve_prep_tso(struct sk_buff *skb) if (unlikely(skb_shinfo(skb)->gso_size < GVE_TX_MIN_TSO_MSS_DQO)) return -1; + if (!(skb_shinfo(skb)->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6))) + return -EINVAL; + /* Needed because we will modify header. */ err = skb_cow_head(skb, 0); if (err < 0) return err; tcp = tcp_hdr(skb); - - /* Remove payload length from checksum. */ paylen = skb->len - skb_transport_offset(skb); - - switch (skb_shinfo(skb)->gso_type) { - case SKB_GSO_TCPV4: - case SKB_GSO_TCPV6: - csum_replace_by_diff(&tcp->check, - (__force __wsum)htonl(paylen)); - - /* Compute length of segmentation header. */ - header_len = skb_transport_offset(skb) + tcp_hdrlen(skb); - break; - default: - return -EINVAL; - } + csum_replace_by_diff(&tcp->check, (__force __wsum)htonl(paylen)); + header_len = skb_transport_offset(skb) + tcp_hdrlen(skb); if (unlikely(header_len > GVE_TX_MAX_HDR_SIZE_DQO)) return -EINVAL; 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;