From patchwork Thu May 5 10:27:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 110689 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DB6B9A04FF; Thu, 5 May 2022 12:27:45 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E392342824; Thu, 5 May 2022 12:27:40 +0200 (CEST) Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [170.10.133.74]) by mails.dpdk.org (Postfix) with ESMTP id D042741145 for ; Thu, 5 May 2022 12:27:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651746459; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rh2zB6pRrTYo8o2Lq4En6df9y4dAV4GhMxUibYGVDJg=; b=dnGPbKq6r+NkUCMMlO+RD/m6vS6iB8sdnCAoU5/PYJK+SXE1H5snLmPqK4pSplIeKLJiaM l2FC6Udix/CuCPmIQdkAll9czeJZOfFwk0Y1VyTS3gPFHaRuwW1/V6Mmqorbs7n5ov9ngT 4/a8pc3NwsU0I475dFQ57C3UOENFJ6Q= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-668-D0gN9mMaN4ybyADtqy0yxA-1; Thu, 05 May 2022 06:27:36 -0400 X-MC-Unique: D0gN9mMaN4ybyADtqy0yxA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 014AE1C08969; Thu, 5 May 2022 10:27:36 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id B618E415F2E; Thu, 5 May 2022 10:27:34 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, jasowang@redhat.com, chenbo.xia@intel.com, david.marchand@redhat.com, olivier.matz@6wind.com Cc: stable@dpdk.org, Maxime Coquelin Subject: [PATCH 1/6] Revert "app/testpmd: modify mac in csum forwarding" Date: Thu, 5 May 2022 12:27:24 +0200 Message-Id: <20220505102729.821075-2-maxime.coquelin@redhat.com> In-Reply-To: <20220505102729.821075-1-maxime.coquelin@redhat.com> References: <20220505102729.821075-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patch reverts commit 10f4620f02e1 ("app/testpmd: modify mac in csum forwarding"), as the checksum forwarding is expected to only perform checksum and not also overwritte the source and destination MAC addresses. Doing so, we can test checksum offloading with real traffic without breaking broadcast packets. Fixes: 10f4620f02e1 ("app/testpmd: modify mac in csum forwarding") Cc: stable@dpdk.org Signed-off-by: Maxime Coquelin Acked-by: Chenbo Xia --- app/test-pmd/csumonly.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c index cdb1920763..8b6665d6f3 100644 --- a/app/test-pmd/csumonly.c +++ b/app/test-pmd/csumonly.c @@ -894,10 +894,6 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) * and inner headers */ eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *); - rte_ether_addr_copy(&peer_eth_addrs[fs->peer_addr], - ð_hdr->dst_addr); - rte_ether_addr_copy(&ports[fs->tx_port].eth_addr, - ð_hdr->src_addr); parse_ethernet(eth_hdr, &info); l3_hdr = (char *)eth_hdr + info.l2_len; From patchwork Thu May 5 10:27:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 110690 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A6774A04FF; Thu, 5 May 2022 12:27:52 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E441342832; Thu, 5 May 2022 12:27:41 +0200 (CEST) Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [170.10.133.74]) by mails.dpdk.org (Postfix) with ESMTP id 3F45642829 for ; Thu, 5 May 2022 12:27:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651746460; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m5j5dHl6TxdzjKKNwasf/xt1TQlTYT6Hhiso+7Q5xck=; b=YStujCKcfTqmYLL2G13Mps/Lpyx3sXHH+LLunbneG1JnZ/dqrqryRU21Q1EC3GAoq2WksY DeZ6Hpu4NjFtSsoe1ONS/WKE6npdDW7IrEI8EqokZ8qT1YUUyDW6aBhjCxiMc8xqiFnVir xXKXukm4vxwM7JinQDSWyPPO7TeOVQ4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-622-5W8OLU0hMiOf_S0qkGlwmg-1; Thu, 05 May 2022 06:27:37 -0400 X-MC-Unique: 5W8OLU0hMiOf_S0qkGlwmg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 88A323C0D186; Thu, 5 May 2022 10:27:37 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 463F9416157; Thu, 5 May 2022 10:27:36 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, jasowang@redhat.com, chenbo.xia@intel.com, david.marchand@redhat.com, olivier.matz@6wind.com Cc: stable@dpdk.org, Maxime Coquelin Subject: [PATCH 2/6] vhost: fix missing enqueue pseudo-header calculation Date: Thu, 5 May 2022 12:27:25 +0200 Message-Id: <20220505102729.821075-3-maxime.coquelin@redhat.com> In-Reply-To: <20220505102729.821075-1-maxime.coquelin@redhat.com> References: <20220505102729.821075-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The Virtio specification requires that in case of checksum offloading, the pseudo-header checksum must be set in the L4 header. When received from another Vhost-user port, the packet checksum might already contain the pseudo-header checksum but we have no way to know it. So we have no other choice than doing the pseudo-header checksum systematically. This patch handles this using the rte_net_intel_cksum_prepare() helper. Fixes: 859b480d5afd ("vhost: add guest offload setting") Cc: stable@dpdk.org Signed-off-by: Maxime Coquelin Reviewed-by: Chenbo Xia --- lib/vhost/virtio_net.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index 5f432b0d77..c0ff3357a8 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -548,6 +548,16 @@ virtio_enqueue_offload(struct rte_mbuf *m_buf, struct virtio_net_hdr *net_hdr) csum_l4 |= RTE_MBUF_F_TX_TCP_CKSUM; if (csum_l4) { + /* + * Pseudo-header checksum must be set as per Virtio spec. + * + * Note: We don't propagate rte_net_intel_cksum_prepare() + * errors, as it would have an impact on performance, and an + * error would mean the packet is dropped by the guest instead + * of being dropped here. + */ + rte_net_intel_cksum_prepare(m_buf); + net_hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM; net_hdr->csum_start = m_buf->l2_len + m_buf->l3_len; From patchwork Thu May 5 10:27:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 110691 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CD38BA04FF; Thu, 5 May 2022 12:27:58 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DBAC942820; Thu, 5 May 2022 12:27:43 +0200 (CEST) Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [170.10.129.74]) by mails.dpdk.org (Postfix) with ESMTP id CF32042837 for ; Thu, 5 May 2022 12:27:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651746462; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eJfPMPP7g0kdrT1xP42yckeDoqZw/NkGadDIN4XmT8o=; b=avBDWwskqrpklCXAUykZ666EELp2KWr6IqqwodEiT1Q+wPaFd7lQGRd6v4PRuljmRZYpqD gckJvqpUN/3iQlX9ONRrXnilPic2E7TnzEv5GZ63rJ61iBIi4wTfU/qRYWM6APmhkYBz9/ 2fDwAucTq+7aVDT2nYacXbBSv7WpO/8= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-561-kR3rGa7UNpyQGhONk9kQJQ-1; Thu, 05 May 2022 06:27:39 -0400 X-MC-Unique: kR3rGa7UNpyQGhONk9kQJQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1D533299E743; Thu, 5 May 2022 10:27:39 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF6FF416157; Thu, 5 May 2022 10:27:37 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, jasowang@redhat.com, chenbo.xia@intel.com, david.marchand@redhat.com, olivier.matz@6wind.com Cc: stable@dpdk.org, Maxime Coquelin Subject: [PATCH 3/6] net/vhost: enable compliant offloading mode Date: Thu, 5 May 2022 12:27:26 +0200 Message-Id: <20220505102729.821075-4-maxime.coquelin@redhat.com> In-Reply-To: <20220505102729.821075-1-maxime.coquelin@redhat.com> References: <20220505102729.821075-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patch enables the compliant offloading flags mode by default, which prevents the Rx path to set Tx offload flags, which is illegal. A new legacy-ol-flags devarg is introduced to enable the legacy behaviour. Signed-off-by: Maxime Coquelin Reviewed-by: Chenbo Xia --- doc/guides/nics/vhost.rst | 6 ++++++ drivers/net/vhost/rte_eth_vhost.c | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/doc/guides/nics/vhost.rst b/doc/guides/nics/vhost.rst index ee802ec4a8..d7c0e2ade8 100644 --- a/doc/guides/nics/vhost.rst +++ b/doc/guides/nics/vhost.rst @@ -64,6 +64,12 @@ The user can specify below arguments in `--vdev` option. It is used to enable external buffer support in vhost library. (Default: 0 (disabled)) +#. ``legacy-ol-flags``: + + It is used to restore legacy behavior for offloading that was not + compliant with offloading API. + (Default: 0 (disabled)) + Vhost PMD event handling ------------------------ diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c index 070f0e6dfd..0a2e8d9b29 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -31,9 +31,10 @@ enum {VIRTIO_RXQ, VIRTIO_TXQ, VIRTIO_QNUM}; #define ETH_VHOST_CLIENT_ARG "client" #define ETH_VHOST_IOMMU_SUPPORT "iommu-support" #define ETH_VHOST_POSTCOPY_SUPPORT "postcopy-support" -#define ETH_VHOST_VIRTIO_NET_F_HOST_TSO "tso" -#define ETH_VHOST_LINEAR_BUF "linear-buffer" -#define ETH_VHOST_EXT_BUF "ext-buffer" +#define ETH_VHOST_VIRTIO_NET_F_HOST_TSO "tso" +#define ETH_VHOST_LINEAR_BUF "linear-buffer" +#define ETH_VHOST_EXT_BUF "ext-buffer" +#define ETH_VHOST_LEGACY_OL_FLAGS "legacy-ol-flags" #define VHOST_MAX_PKT_BURST 32 static const char *valid_arguments[] = { @@ -1563,6 +1564,7 @@ rte_pmd_vhost_probe(struct rte_vdev_device *dev) int tso = 0; int linear_buf = 0; int ext_buf = 0; + int legacy_ol_flags = 0; struct rte_eth_dev *eth_dev; const char *name = rte_vdev_device_name(dev); @@ -1672,6 +1674,17 @@ rte_pmd_vhost_probe(struct rte_vdev_device *dev) flags |= RTE_VHOST_USER_EXTBUF_SUPPORT; } + if (rte_kvargs_count(kvlist, ETH_VHOST_LEGACY_OL_FLAGS) == 1) { + ret = rte_kvargs_process(kvlist, + ETH_VHOST_LEGACY_OL_FLAGS, + &open_int, &legacy_ol_flags); + if (ret < 0) + goto out_free; + } + + if (legacy_ol_flags == 0) + flags |= RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS; + if (dev->device.numa_node == SOCKET_ID_ANY) dev->device.numa_node = rte_socket_id(); From patchwork Thu May 5 10:27:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 110693 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 52B34A04FF; Thu, 5 May 2022 12:28:12 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1F14F42841; Thu, 5 May 2022 12:27:49 +0200 (CEST) Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [170.10.129.74]) by mails.dpdk.org (Postfix) with ESMTP id 6F1BA4281E for ; Thu, 5 May 2022 12:27:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651746468; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4uRasHln5WR8DlBnbCVXjXG6TOB25YmRkeRDD83tuUI=; b=icda6xUafUZ1zRHxTOrmxd7l+h0tF5GpShQQbx0g9OnIMmXV+9hDsZXx+zywsVM0OSTrbu bb5voaSiHLFYzZykhHnfbL4b6MGsfMoi9wuvhCgYOR/avMWZCAjpXLFxYe8oS4Fc59k6Mm pJ2wsq7z2XPaxdtLNjohQ0z03DcJaR4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-313-ux5Rn-aAPQ6AcWyILzsrYw-1; Thu, 05 May 2022 06:27:41 -0400 X-MC-Unique: ux5Rn-aAPQ6AcWyILzsrYw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 986A01C08965; Thu, 5 May 2022 10:27:40 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61725416157; Thu, 5 May 2022 10:27:39 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, jasowang@redhat.com, chenbo.xia@intel.com, david.marchand@redhat.com, olivier.matz@6wind.com Cc: stable@dpdk.org, Maxime Coquelin Subject: [PATCH 4/6] net/vhost: make VLAN stripping flag a boolean Date: Thu, 5 May 2022 12:27:27 +0200 Message-Id: <20220505102729.821075-5-maxime.coquelin@redhat.com> In-Reply-To: <20220505102729.821075-1-maxime.coquelin@redhat.com> References: <20220505102729.821075-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This trivial patch makes the vlan_strip field of the pmd_internal struct a boolean, since it is handled as such. Signed-off-by: Maxime Coquelin Reviewed-by: Chenbo Xia --- drivers/net/vhost/rte_eth_vhost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c index 0a2e8d9b29..baa973ad6d 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -110,7 +110,7 @@ struct pmd_internal { uint16_t max_queues; int vid; rte_atomic32_t started; - uint8_t vlan_strip; + bool vlan_strip; }; struct internal_list { From patchwork Thu May 5 10:27:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 110692 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D0819A04FF; Thu, 5 May 2022 12:28:04 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D9D164283D; Thu, 5 May 2022 12:27:44 +0200 (CEST) Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [170.10.133.74]) by mails.dpdk.org (Postfix) with ESMTP id E4E2442829 for ; Thu, 5 May 2022 12:27:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651746463; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w8w5EzFQgJDW+ds2CormPz3WlzGWCW3rQ3AnTlsawys=; b=dEU+8Khk1Tv4xMDK8dNydsvhGQlTXw67N0f5pqMS82WFrNVeIb3U7/juphuQgkQre+u4Ti ZpHpn+4YT6C0Kvp+S69JLd3FJKb4La9CYoiygPygNv/SLa7oUdiZ+WlNutJofjBvZ62ykV JXppIeZN6DgDbpMB3y5zoFVGYq1JP08= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-116-oNJLhKyMMzOGH66ekVeukA-1; Thu, 05 May 2022 06:27:42 -0400 X-MC-Unique: oNJLhKyMMzOGH66ekVeukA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2F17B86B8AB; Thu, 5 May 2022 10:27:42 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id DFD4C415F2E; Thu, 5 May 2022 10:27:40 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, jasowang@redhat.com, chenbo.xia@intel.com, david.marchand@redhat.com, olivier.matz@6wind.com Cc: stable@dpdk.org, Maxime Coquelin Subject: [PATCH 5/6] net/vhost: perform SW checksum in Rx path Date: Thu, 5 May 2022 12:27:28 +0200 Message-Id: <20220505102729.821075-6-maxime.coquelin@redhat.com> In-Reply-To: <20220505102729.821075-1-maxime.coquelin@redhat.com> References: <20220505102729.821075-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Virtio specification supports host checksum offloading for L4, which is enabled with VIRTIO_NET_F_CSUM feature negotiation. However, the Vhost PMD does not advertise Rx checksum offload capabilities, so we can end-up with the VIRTIO_NET_F_CSUM feature being negociated, implying the Vhost library returns packets with checksum being offloaded while the application did not request for it. Advertising these offload capabilities at the ethdev level is not enough, because we could still end-up with the application not enabling these offloads while the guest still negotiate them. This patch advertizes the Rx checksum offload capabilities, and introduces a compatibility layer to cover the case VIRTIO_NET_F_CSUM has been negotiated but the application does not configure the Rx checksum offloads. This function performis the L4 Rx checksum in SW for UDP and TCP. Note that it is not needed to calculate the pseudo-header checksum, because the Virtio specification requires that the driver do it. This patch does not advertize SCTP checksum offloading capability for now, but it could be handled later if the need arises. Reported-by: Jason Wang Signed-off-by: Maxime Coquelin --- doc/guides/nics/features/vhost.ini | 1 + drivers/net/vhost/rte_eth_vhost.c | 83 ++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/doc/guides/nics/features/vhost.ini b/doc/guides/nics/features/vhost.ini index ef81abb439..15f4dfe5e8 100644 --- a/doc/guides/nics/features/vhost.ini +++ b/doc/guides/nics/features/vhost.ini @@ -7,6 +7,7 @@ Link status = Y Free Tx mbuf on demand = Y Queue status event = Y +L4 checksum offload = P Basic stats = Y Extended stats = Y x86-32 = Y diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c index baa973ad6d..d5303f7368 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -107,10 +108,12 @@ struct pmd_internal { char *iface_name; uint64_t flags; uint64_t disable_flags; + uint64_t features; uint16_t max_queues; int vid; rte_atomic32_t started; bool vlan_strip; + bool rx_sw_csum; }; struct internal_list { @@ -362,6 +365,70 @@ vhost_update_single_packet_xstats(struct vhost_queue *vq, struct rte_mbuf *buf) vhost_count_xcast_packets(vq, buf); } +static void +vhost_dev_csum_configure(struct rte_eth_dev *eth_dev) +{ + struct pmd_internal *internal = eth_dev->data->dev_private; + const struct rte_eth_rxmode *rxmode = ð_dev->data->dev_conf.rxmode; + + internal->rx_sw_csum = false; + + /* SW checksum is not compatible with legacy mode */ + if (!(internal->flags & RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS)) + return; + + if (internal->features & (1ULL << VIRTIO_NET_F_CSUM)) { + if (!(rxmode->offloads & + (RTE_ETH_RX_OFFLOAD_UDP_CKSUM | RTE_ETH_RX_OFFLOAD_TCP_CKSUM))) { + VHOST_LOG(NOTICE, "Rx csum will be done in SW, may impact performance."); + internal->rx_sw_csum = true; + } + } +} + +static void +vhost_dev_rx_sw_csum(struct rte_mbuf *mbuf) +{ + struct rte_net_hdr_lens hdr_lens; + uint32_t ptype, hdr_len; + uint16_t csum = 0, csum_offset; + + /* Return early if the L4 checksum was not offloaded */ + if ((mbuf->ol_flags & RTE_MBUF_F_RX_L4_CKSUM_MASK) != RTE_MBUF_F_RX_L4_CKSUM_NONE) + return; + + ptype = rte_net_get_ptype(mbuf, &hdr_lens, RTE_PTYPE_ALL_MASK); + + hdr_len = hdr_lens.l2_len + hdr_lens.l3_len; + + switch (ptype & RTE_PTYPE_L4_MASK) { + case RTE_PTYPE_L4_TCP: + csum_offset = offsetof(struct rte_tcp_hdr, cksum) + hdr_len; + break; + case RTE_PTYPE_L4_UDP: + csum_offset = offsetof(struct rte_udp_hdr, dgram_cksum) + hdr_len; + break; + default: + /* Unsupported packet type */ + return; + } + + /* The pseudo-header checksum is already performed, as per Virtio spec */ + if (rte_raw_cksum_mbuf(mbuf, hdr_len, rte_pktmbuf_pkt_len(mbuf) - hdr_len, &csum) < 0) + return; + + csum = ~csum; + /* See RFC768 */ + if (unlikely((ptype & RTE_PTYPE_L4_UDP) && csum == 0)) + csum = 0xffff; + + if (rte_pktmbuf_data_len(mbuf) >= csum_offset + 1) + *rte_pktmbuf_mtod_offset(mbuf, uint16_t *, csum_offset) = csum; + + mbuf->ol_flags &= ~RTE_MBUF_F_RX_L4_CKSUM_MASK; + mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD; +} + static uint16_t eth_vhost_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) { @@ -402,6 +469,9 @@ eth_vhost_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) if (r->internal->vlan_strip) rte_vlan_strip(bufs[i]); + if (r->internal->rx_sw_csum) + vhost_dev_rx_sw_csum(bufs[i]); + r->stats.bytes += bufs[i]->pkt_len; r->stats.xstats[VHOST_BYTE] += bufs[i]->pkt_len; @@ -805,6 +875,11 @@ new_device(int vid) eth_dev->data->numa_node = newnode; #endif + if (rte_vhost_get_negotiated_features(vid, &internal->features)) { + VHOST_LOG(ERR, "Failed to get device features\n"); + return -1; + } + internal->vid = vid; if (rte_atomic32_read(&internal->started) == 1) { queue_setup(eth_dev, internal); @@ -827,6 +902,8 @@ new_device(int vid) eth_dev->data->dev_link.link_status = RTE_ETH_LINK_UP; + vhost_dev_csum_configure(eth_dev); + rte_atomic32_set(&internal->dev_attached, 1); update_queuing_status(eth_dev); @@ -1131,6 +1208,8 @@ eth_dev_configure(struct rte_eth_dev *dev) internal->vlan_strip = !!(rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP); + vhost_dev_csum_configure(dev); + return 0; } @@ -1281,6 +1360,10 @@ eth_dev_info(struct rte_eth_dev *dev, dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS | RTE_ETH_TX_OFFLOAD_VLAN_INSERT; dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP; + if (internal->flags & RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS) { + dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_UDP_CKSUM | + RTE_ETH_RX_OFFLOAD_TCP_CKSUM; + } return 0; } From patchwork Thu May 5 10:27:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 110694 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EB4D8A04FF; Thu, 5 May 2022 12:28:19 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7CDC04283F; Thu, 5 May 2022 12:27:54 +0200 (CEST) Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [170.10.129.74]) by mails.dpdk.org (Postfix) with ESMTP id 506234069F for ; Thu, 5 May 2022 12:27:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651746472; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+VSCWAsWs1Wtex/UdC1DCDn5c9HooEfhdBaMGzpHPVA=; b=GOV4hmjCvETDgdtPyQ82LJkGYyyw40AM7WrrGafkk53u5gPpkIcfn0K3G8YX8eFv0DNAez mRaCdzEwLBy9jfPEq8gxD/GkTpKEr6kVXBgzxhs0POMcMb00Nq/BQz3cnw6D6oOBVbklWT p4LV935lEXNlR3Moj5GuL72xGlx3q98= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-523-X9F1FDn2N2CR44T1ZuVhhQ-1; Thu, 05 May 2022 06:27:44 -0400 X-MC-Unique: X9F1FDn2N2CR44T1ZuVhhQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AAE5E833961; Thu, 5 May 2022 10:27:43 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73563416157; Thu, 5 May 2022 10:27:42 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, jasowang@redhat.com, chenbo.xia@intel.com, david.marchand@redhat.com, olivier.matz@6wind.com Cc: stable@dpdk.org, Maxime Coquelin Subject: [PATCH 6/6] net/vhost: perform SW checksum in Tx path Date: Thu, 5 May 2022 12:27:29 +0200 Message-Id: <20220505102729.821075-7-maxime.coquelin@redhat.com> In-Reply-To: <20220505102729.821075-1-maxime.coquelin@redhat.com> References: <20220505102729.821075-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Virtio specification supports guest checksum offloading for L4, which is enabled with VIRTIO_NET_F_GUEST_CSUM feature negotiation. However, the Vhost PMD does not advertise Tx checksum offload capabilities. Advertising these offload capabilities at the ethdev level is not enough, because we could still end-up with the application enabling these offloads while the guest not negotiating it. This patch advertizes the Tx checksum offload capabilities, and introduces a compatibility layer to cover the case VIRTIO_NET_F_GUEST_CSUM has not been negotiated but the application does configure the Tx checksum offloads. This function performs the L4 Tx checksum in SW for UDP and TCP. Compared to Rx SW checksum, the Tx SW checksum function needs to compute the pseudo-header checksum, as we cannot knwo whether it was done before. This patch does not advertize SCTP checksum offloading capability for now, but it could be handled later if the need arises. Reported-by: Jason Wang Signed-off-by: Maxime Coquelin --- drivers/net/vhost/rte_eth_vhost.c | 62 +++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c index d5303f7368..52a802de05 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -114,6 +114,7 @@ struct pmd_internal { rte_atomic32_t started; bool vlan_strip; bool rx_sw_csum; + bool tx_sw_csum; }; struct internal_list { @@ -370,8 +371,10 @@ vhost_dev_csum_configure(struct rte_eth_dev *eth_dev) { struct pmd_internal *internal = eth_dev->data->dev_private; const struct rte_eth_rxmode *rxmode = ð_dev->data->dev_conf.rxmode; + const struct rte_eth_txmode *txmode = ð_dev->data->dev_conf.txmode; internal->rx_sw_csum = false; + internal->tx_sw_csum = false; /* SW checksum is not compatible with legacy mode */ if (!(internal->flags & RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS)) @@ -384,6 +387,56 @@ vhost_dev_csum_configure(struct rte_eth_dev *eth_dev) internal->rx_sw_csum = true; } } + + if (!(internal->features & (1ULL << VIRTIO_NET_F_GUEST_CSUM))) { + if (txmode->offloads & + (RTE_ETH_TX_OFFLOAD_UDP_CKSUM | RTE_ETH_TX_OFFLOAD_TCP_CKSUM)) { + VHOST_LOG(NOTICE, "Tx csum will be done in SW, may impact performance."); + internal->tx_sw_csum = true; + } + } +} + +static void +vhost_dev_tx_sw_csum(struct rte_mbuf *mbuf) +{ + uint32_t hdr_len; + uint16_t csum = 0, csum_offset; + + switch (mbuf->ol_flags & RTE_MBUF_F_TX_L4_MASK) { + case RTE_MBUF_F_TX_L4_NO_CKSUM: + return; + case RTE_MBUF_F_TX_TCP_CKSUM: + csum_offset = offsetof(struct rte_tcp_hdr, cksum); + break; + case RTE_MBUF_F_TX_UDP_CKSUM: + csum_offset = offsetof(struct rte_udp_hdr, dgram_cksum); + break; + default: + /* Unsupported packet type. */ + return; + } + + hdr_len = mbuf->l2_len + mbuf->l3_len; + csum_offset += hdr_len; + + /* Prepare the pseudo-header checksum */ + if (rte_net_intel_cksum_prepare(mbuf) < 0) + return; + + if (rte_raw_cksum_mbuf(mbuf, hdr_len, rte_pktmbuf_pkt_len(mbuf) - hdr_len, &csum) < 0) + return; + + csum = ~csum; + /* See RFC768 */ + if (unlikely((mbuf->packet_type & RTE_PTYPE_L4_UDP) && csum == 0)) + csum = 0xffff; + + if (rte_pktmbuf_data_len(mbuf) >= csum_offset + 1) + *rte_pktmbuf_mtod_offset(mbuf, uint16_t *, csum_offset) = csum; + + mbuf->ol_flags &= ~RTE_MBUF_F_TX_L4_MASK; + mbuf->ol_flags |= RTE_MBUF_F_TX_L4_NO_CKSUM; } static void @@ -513,6 +566,10 @@ eth_vhost_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) } } + if (r->internal->tx_sw_csum) + vhost_dev_tx_sw_csum(m); + + bufs[nb_send] = m; ++nb_send; } @@ -1359,6 +1416,11 @@ eth_dev_info(struct rte_eth_dev *dev, dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS | RTE_ETH_TX_OFFLOAD_VLAN_INSERT; + if (internal->flags & RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS) { + dev_info->tx_offload_capa |= RTE_ETH_TX_OFFLOAD_UDP_CKSUM | + RTE_ETH_TX_OFFLOAD_TCP_CKSUM; + } + dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP; if (internal->flags & RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS) { dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_UDP_CKSUM |