From patchwork Wed Jun 8 12:49:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 112572 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 C506CA04FD; Wed, 8 Jun 2022 14:50:38 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0472742BB6; Wed, 8 Jun 2022 14:50:14 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 337E542BAC for ; Wed, 8 Jun 2022 14:50:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654692612; 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=r7nHR9aMi9Ul0CSXeuq/nRGM+gHzUZgGN6kaVZiRmQg=; b=f2l0nWxiXPTipfdRzgWqoE+nktnTfESl0kSHR3GZDpWPQ9pqhytoDUnOHw/ygVZUPwW95D GZtoz4ud5CJA+si7paLmWuU97xyrj7d/Xc0tGq3spmhwvGuCMpZsiXgwwWlC5gWNX3O+bH C7FPEGJ0OdkrXT6iCl2lfvWbMIKV0mU= 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-189-wFQ3hGmpP5GoxYnf-kNZyg-1; Wed, 08 Jun 2022 08:50:08 -0400 X-MC-Unique: wFQ3hGmpP5GoxYnf-kNZyg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6090238173CD; Wed, 8 Jun 2022 12:50:08 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89E9040CFD0B; Wed, 8 Jun 2022 12:50:06 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, jasowang@redhat.com, chenbo.xia@intel.com, david.marchand@redhat.com, olivier.matz@6wind.com, wenwux.ma@intel.com, yuying.zhang@intel.com, aman.deep.singh@intel.com Cc: Maxime Coquelin Subject: [PATCH v2 6/6] net/vhost: perform SW checksum in Tx path Date: Wed, 8 Jun 2022 14:49:46 +0200 Message-Id: <20220608124946.102623-7-maxime.coquelin@redhat.com> In-Reply-To: <20220608124946.102623-1-maxime.coquelin@redhat.com> References: <20220608124946.102623-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 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 advertises 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 know whether it was done before. This patch does not advertise 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 Reviewed-by: Chenbo Xia Reviewed-by: Cheng Jiang --- 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 42f0d52ebc..d75d256040 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -92,6 +92,7 @@ struct pmd_internal { rte_atomic32_t started; bool vlan_strip; bool rx_sw_csum; + bool tx_sw_csum; }; struct internal_list { @@ -283,8 +284,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)) @@ -297,6 +300,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 @@ -423,6 +476,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; } @@ -1267,6 +1324,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 |