From patchwork Tue Aug 27 20:28:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magali Lemes X-Patchwork-Id: 1977466 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 4WtfKW3K1Vz1yfn for ; Wed, 28 Aug 2024 06:29:35 +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 1sj2og-0007Kh-AY; Tue, 27 Aug 2024 20:29:26 +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 1sj2of-0007IA-2U for kernel-team@lists.ubuntu.com; Tue, 27 Aug 2024 20:29:25 +0000 Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (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 D7EE53F183 for ; Tue, 27 Aug 2024 20:29:24 +0000 (UTC) Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-71454420f65so3381934b3a.1 for ; Tue, 27 Aug 2024 13:29:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724790562; x=1725395362; 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=8/YCzNLbgWmrSeo7XtL1wI5UE7Dxmo0IWDPSanaW1tI=; b=FvRL4rLDct1+eMjCvny3/N1g/7mvxU8pe8INMAoeVaoI/zjHJNZb4z9tAEkLO1EfNi KaI93V+7IH/5S8EUXeTL9E0DaJUNKCuQFQ4ohwIV2B/evvSOsQDksGPMpT65aFSPljJS VSvVQa/tJqRlSkJDOcMBI5DodmKs/oRvVKG1ApLeCrFIjeK0dDIPPcRGmrxKGFuG19mA ooXzdjdFFDy7Th9vlTAx06W/VAp/EVs9ZQ+FA7Gk0rsh5vuceLI7Y3lRUu/0d0v2eqzM QXfou1v4yvCB8+0h/S74YSqTi6xpZw+8PP+e/SPKfqbWsyMRlpii8ti/kUarHDo24arq O5AA== X-Gm-Message-State: AOJu0Yz4X497FsINL9JiXSGHnoRjG84pbAWeCRIKYNS7DlsBG9BC4h2f Jh5+bvw73vKFUVfJW51B1u0aoNGciF2P56akI3zoGa1C6S2TyfkdhquIuVcC7akKhkkdiY1YVE1 fugZFMMLGnzHYXEZk9F0VMxMWDCFXbddiumEPBz5AiVi9kN62sG5zDe/xE3LWH3XU1Ezr/4rq4j lEuCI6s004UQ== X-Received: by 2002:a05:6a00:66d1:b0:714:186a:ae0b with SMTP id d2e1a72fcca58-71445e77f21mr13960338b3a.24.1724790562565; Tue, 27 Aug 2024 13:29:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEcfvDdcgqZRNtlJWifGZx2UR+NyMBiVtQ1pPC7cSjydv46VcowUzJny8p/d19KsgOB+TuOCQ== X-Received: by 2002:a05:6a00:66d1:b0:714:186a:ae0b with SMTP id d2e1a72fcca58-71445e77f21mr13960323b3a.24.1724790562106; Tue, 27 Aug 2024 13:29:22 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:14a:8141:7d63:49a5:3ea2:be5d]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71434316102sm9253698b3a.175.2024.08.27.13.29.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 13:29:20 -0700 (PDT) From: Magali Lemes To: kernel-team@lists.ubuntu.com Subject: [SRU][jammy:linux-gke/linux-gkeop][PATCH 1/2] gve: ignore nonrelevant GSO type bits when processing TSO headers Date: Tue, 27 Aug 2024 17:28:52 -0300 Message-Id: <20240827202853.94286-2-magali.lemes@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240827202853.94286-1-magali.lemes@canonical.com> References: <20240827202853.94286-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 94e3b74a10f22..3120a82672e40 100644 --- a/drivers/net/ethernet/google/gve/gve_tx_dqo.c +++ b/drivers/net/ethernet/google/gve/gve_tx_dqo.c @@ -370,28 +370,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 Tue Aug 27 20:28:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magali Lemes X-Patchwork-Id: 1977467 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 4WtfKc3dyDz1yfn for ; Wed, 28 Aug 2024 06:29:40 +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 1sj2ol-0007OW-Es; Tue, 27 Aug 2024 20:29:31 +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 1sj2oj-0007Lp-9C for kernel-team@lists.ubuntu.com; Tue, 27 Aug 2024 20:29:29 +0000 Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.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-1.canonical.com (Postfix) with ESMTPS id DFE413F287 for ; Tue, 27 Aug 2024 20:29:26 +0000 (UTC) Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-714203541e1so5392083b3a.0 for ; Tue, 27 Aug 2024 13:29:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724790565; x=1725395365; 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=OQjS329UKjnpYr4JKj78bGFRu1kTwhHO7ePrpmtEWCk=; b=Ha3GDFDAa6ISn3izCLvgHBTIr1lzqTXDsMTz11GgLpFPJko/7wgV1pJ0sIrVD1y1J+ 1DzhID7h2bJ8tdJGn1/lHHvHytz0yDJnwaXdGdHAjKRH3Y+7xSb+xe8mv5v7Gc6yF1P9 zStBs7arGiNHUT2WIpakEGNdjm0YAUjCQbYh2ycroLK1z9ufYJe9LVMxbY0aRchbOq/R mh8HZ8uUDiB8e0OkRXjaQthETxIeOMIouGwDdQKbb4Ww/d/ep7sfyay6s2BY0PPLZZS0 6MgjhR2XbyX/yyjKoVLVUd5Q5c5PD6Raeb7wTra8/HOv3kAoepZU627KOjWQ9b+07cv8 ZNvw== X-Gm-Message-State: AOJu0YwL6tbDETo55q89mYouvu41+XI+dmiWIVZgNNJ3dLbhiEkOLVhD RedaiqjZJw+QWOLG3988OSf5aGJM3CI91jZSMhIGypCoszVCWBd+wW+7hE+ij4oWNP4l/IuCeBv 1jtEwqa3YwnMZg3k8oXNuOEv9V3bVMZjMrLI9t2WV0hKGvoENFhxreBaX1+pUrd9Xzf8DP8drEH P+cmV+i5Fytw== X-Received: by 2002:a05:6a00:1415:b0:710:4d3a:2d92 with SMTP id d2e1a72fcca58-7144573e05cmr17472312b3a.4.1724790564824; Tue, 27 Aug 2024 13:29:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFGjGmrfqxq/oQBwFGS6Pi9+KpFOkFqD/dnh4ZdZT+51a6nnDwEULpqibEeJGydigg6WeTfPw== X-Received: by 2002:a05:6a00:1415:b0:710:4d3a:2d92 with SMTP id d2e1a72fcca58-7144573e05cmr17472293b3a.4.1724790564370; Tue, 27 Aug 2024 13:29:24 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:14a:8141:7d63:49a5:3ea2:be5d]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71434316102sm9253698b3a.175.2024.08.27.13.29.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 13:29:23 -0700 (PDT) From: Magali Lemes To: kernel-team@lists.ubuntu.com Subject: [SRU][jammy:linux-gke/linux-gkeop][PATCH 2/2] gve: Fix an edge case for TSO skb validity check Date: Tue, 27 Aug 2024 17:28:53 -0300 Message-Id: <20240827202853.94286-3-magali.lemes@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240827202853.94286-1-magali.lemes@canonical.com> References: <20240827202853.94286-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 3120a82672e40..2dcb73e1c8572 100644 --- a/drivers/net/ethernet/google/gve/gve_tx_dqo.c +++ b/drivers/net/ethernet/google/gve/gve_tx_dqo.c @@ -596,22 +596,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;