From patchwork Wed Aug 9 12:49:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1819304 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=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=PYLv5D9f; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (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 4RLVJL5R1Mz1yfl for ; Wed, 9 Aug 2023 22:49:54 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qTidH-00047s-Hy; Wed, 09 Aug 2023 12:49:47 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qTidF-00047T-9k for kernel-team@lists.ubuntu.com; Wed, 09 Aug 2023 12:49:45 +0000 Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) (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 135964449A for ; Wed, 9 Aug 2023 12:49:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1691585385; bh=JMDfdILjs+YYDczuXr3IqEqZN+CyHIs9XDtP7oAmSxU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PYLv5D9f98m+JfdIDBVB4ECPOiFCf/nB2vuOfLpR/oTEl94IqL8kqQlSo4XsCLHOP zRjl5JsEP7FEcjTE5PeMG/rCjgnOlGnL0eYc0Pa0TSmMI6oPOU9Rexxek7XWMOx4bw RKPNmlRabd0O8SYB0PzGE8ezTBkNye2tJq1SDZr9u9rVTi1Qrpk+iyH7p86zvEQxau xbk9igpqwhb4+SA2phwkasXDpAkjCBEF4tzfUUZwXcQK6YPC6i7veou2PL2k8ev+z7 dNSUyM96FNHfdtRZNtLOC//IEof7EhJ5sBHtOU3xLNr1KWtaHdvjdTXH/JvgbK+tqC +Odqxrk+L/q2g== Received: by mail-io1-f72.google.com with SMTP id ca18e2360f4ac-7868ec37aa7so661222239f.0 for ; Wed, 09 Aug 2023 05:49:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691585383; x=1692190183; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JMDfdILjs+YYDczuXr3IqEqZN+CyHIs9XDtP7oAmSxU=; b=VUw8lSAPMyZleynHH6kz4GBATTt+GX9H8ccMLUsusJM02Iv6OyAFksYAtFbvYyeJk3 2QijjdE1R5CHgImnS1nfT1Suv6eD9qHmHyY8z6QKxij44trDL8938GIQ6ouIBxJ7XV6D DwvO5MxZYP4mz3AwjzwxY+sYbh64ccYVcNqrejINrctpc9nJC5fa079esrPVZqkTqwqQ t+dE4bEXL4+2TZ71WuFnFnq07XSMH9qgOJUHiLLVS4fri660jMzqrtbiWK3kXRGsvviA +RGygCa/jxHQxcsiBOly53OhuUZn50MIuHsmnA+FU4aLyxjZTTLapnQS3Ek/2M9NYb4Z Y1Hg== X-Gm-Message-State: AOJu0YypEBniSBFPFA3r51xyg8tx890h0/F0QDrjvrqCtz3GVldcfQHA TkZbVij7p4vAwHH3cjaiwdb2M8pkgIk5js7bvg7FNcb/g05VppQ2VfVERnnTnN4rjBtFjBieXw2 +MtNYV5lDkjZ+JYlrntWuFGkryvb289c+OJlnzDCTxN+NkXI41w== X-Received: by 2002:a5d:9551:0:b0:791:3172:711c with SMTP id a17-20020a5d9551000000b007913172711cmr2944191ios.21.1691585383537; Wed, 09 Aug 2023 05:49:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGGIQs/HZE7GUz7QhcHfDgmd771lFYE/RajY5822ujvjdlcEwFqIv4Q76Gu5gUC6sgs9YgGVg== X-Received: by 2002:a5d:9551:0:b0:791:3172:711c with SMTP id a17-20020a5d9551000000b007913172711cmr2944170ios.21.1691585383276; Wed, 09 Aug 2023 05:49:43 -0700 (PDT) Received: from smtp.gmail.com (174-045-099-030.res.spectrum.com. [174.45.99.30]) by smtp.gmail.com with ESMTPSA id dy6-20020a0566381d4600b0042bb1c9b59csm3903264jab.126.2023.08.09.05.49.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Aug 2023 05:49:42 -0700 (PDT) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH] hv_netvsc: add support for vlans in AF_PACKET mode Date: Wed, 9 Aug 2023 06:49:38 -0600 Message-Id: <20230809124938.92604-2-tim.gardner@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230809124938.92604-1-tim.gardner@canonical.com> References: <20230809124938.92604-1-tim.gardner@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: Sriram Krishnan BugLink: https://bugs.launchpad.net/bugs/2030872 Vlan tagged packets are getting dropped when used with DPDK that uses the AF_PACKET interface on a hyperV guest. The packet layer uses the tpacket interface to communicate the vlans information to the upper layers. On Rx path, these drivers can read the vlan info from the tpacket header but on the Tx path, this information is still within the packet frame and requires the paravirtual drivers to push this back into the NDIS header which is then used by the host OS to form the packet. This transition from the packet frame to NDIS header is currently missing hence causing the host OS to drop the all vlan tagged packets sent by the drivers that use AF_PACKET (ETH_P_ALL) such as DPDK. Here is an overview of the changes in the vlan header in the packet path: The RX path (userspace handles everything): 1. RX VLAN packet is stripped by HOST OS and placed in NDIS header 2. Guest Kernel RX hv_netvsc packets and moves VLAN info from NDIS header into kernel SKB 3. Kernel shares packets with user space application with PACKET_MMAP. The SKB VLAN info is copied to tpacket layer and indication set TP_STATUS_VLAN_VALID. 4. The user space application will re-insert the VLAN info into the frame The TX path: 1. The user space application has the VLAN info in the frame. 2. Guest kernel gets packets from the application with PACKET_MMAP. 3. The kernel later sends the frame to the hv_netvsc driver. The only way to send VLANs is when the SKB is setup & the VLAN is stripped from the frame. 4. TX VLAN is re-inserted by HOST OS based on the NDIS header. If it sees a VLAN in the frame the packet is dropped. Cc: xe-linux-external@cisco.com Cc: Sriram Krishnan Signed-off-by: Sriram Krishnan Reviewed-by: Haiyang Zhang Signed-off-by: David S. Miller (cherry picked from commit fdd8fac47ce67bae17feed9b74b3505e432fe561) Signed-off-by: Tim Gardner --- drivers/net/hyperv/hyperv_net.h | 1 + drivers/net/hyperv/netvsc_drv.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h index a5dd563ea6dc..2e1daa5cb71a 100644 --- a/drivers/net/hyperv/hyperv_net.h +++ b/drivers/net/hyperv/hyperv_net.h @@ -900,6 +900,7 @@ struct netvsc_ethtool_stats { unsigned long rx_no_memory; unsigned long stop_queue; unsigned long wake_queue; + unsigned long vlan_error; }; struct netvsc_ethtool_pcpu_stats { diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c index b628c776fd03..875e82f78f37 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -606,6 +606,29 @@ static int netvsc_xmit(struct sk_buff *skb, struct net_device *net, bool xdp_tx) *hash_info = hash; } + /* When using AF_PACKET we need to drop VLAN header from + * the frame and update the SKB to allow the HOST OS + * to transmit the 802.1Q packet + */ + if (skb->protocol == htons(ETH_P_8021Q)) { + u16 vlan_tci; + + skb_reset_mac_header(skb); + if (eth_type_vlan(eth_hdr(skb)->h_proto)) { + if (unlikely(__skb_vlan_pop(skb, &vlan_tci) != 0)) { + ++net_device_ctx->eth_stats.vlan_error; + goto drop; + } + + __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan_tci); + /* Update the NDIS header pkt lengths */ + packet->total_data_buflen -= VLAN_HLEN; + packet->total_bytes -= VLAN_HLEN; + rndis_msg->msg_len = packet->total_data_buflen; + rndis_msg->msg.pkt.data_len = packet->total_data_buflen; + } + } + if (skb_vlan_tag_present(skb)) { struct ndis_pkt_8021q_info *vlan; @@ -1441,6 +1464,7 @@ static const struct { { "rx_no_memory", offsetof(struct netvsc_ethtool_stats, rx_no_memory) }, { "stop_queue", offsetof(struct netvsc_ethtool_stats, stop_queue) }, { "wake_queue", offsetof(struct netvsc_ethtool_stats, wake_queue) }, + { "vlan_error", offsetof(struct netvsc_ethtool_stats, vlan_error) }, }, pcpu_stats[] = { { "cpu%u_rx_packets", offsetof(struct netvsc_ethtool_pcpu_stats, rx_packets) },