From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3821F433A7 for ; Thu, 23 Nov 2023 11:11:44 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2F1E3402A6; Thu, 23 Nov 2023 11:11:44 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id A00B14026B for ; Thu, 23 Nov 2023 11:11:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700734302; 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; bh=tkWhz7bC9BBjLziL6yowHRtUtHkXhJEX2ilOPSQXerg=; b=GSTlE0xLBXauy4Kqs7evy3tDYjgBulVRS/1lieDOnE7PHxahXLs8cum2KtC2UwD/8UKGSh 0nc/FCXu6SAqpJAKgo+lrQ4Ysm9H19nRdnPWSxiO4o4lWcEcwUhlf0Ff1cRPMw7fkgff3v Zy3kS+y+lxQN5aY3LEbPIWrvpVYtX4I= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-442-mCzrnWPfO_GJP_1Z2t8-Rg-1; Thu, 23 Nov 2023 05:11:40 -0500 X-MC-Unique: mCzrnWPfO_GJP_1Z2t8-Rg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9C91E3C027E3; Thu, 23 Nov 2023 10:11:40 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6EDCF1C060B0; Thu, 23 Nov 2023 10:11:39 +0000 (UTC) From: Maxime Coquelin To: ktraynor@redhat.com, stable@dpdk.org Cc: Maxime Coquelin , Sampath Peechu , David Marchand Subject: [PATCH v21.11.6 1/2] net/virtio: fix descriptor addresses in 32-bit build Date: Thu, 23 Nov 2023 11:11:30 +0100 Message-ID: <20231123101131.98389-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org With Virtio-user, the Virtio descriptor buffer address is the virtual address of the mbuf's buffer. On 32-bit builds, it is expected to be 32 bits. With Virtio-PCI, the Virtio descriptor buffer address is the physical address of the mbuf's buffer. On 32-bit builds running on 64-bit kernel, it is expected to be up to 64 bits. This patch introduces a new mask field in virtqueue's struct to filter our the upper 4 bytes of the address only when necessary. An optimization is introduced for 64-bit builds to remove the masking, as the address is always 64 bits wide. Fixes: ba55c94a7ebc ("net/virtio: revert forcing IOVA as VA mode for virtio-user") Cc: stable@dpdk.org Reported-by: Sampath Peechu Signed-off-by: Maxime Coquelin Reviewed-by: David Marchand (cherry picked from commit 8c41645be010ec7fa0df4f6c3790b167945154b4) Signed-off-by: Maxime Coquelin --- .mailmap | 1 + drivers/net/virtio/virtio_ethdev.c | 7 +++++-- drivers/net/virtio/virtqueue.h | 18 ++++++++++++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.mailmap b/.mailmap index 83b960753a..bb240b92ba 100644 --- a/.mailmap +++ b/.mailmap @@ -1179,6 +1179,7 @@ Salem Sol Sameh Gobriel Sam Grove Samik Gupta +Sampath Peechu Samuel Gauthier Sangjin Han Sankar Chokkalingam diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 11b9a4bc72..6e8c55e699 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -639,10 +639,13 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t queue_idx) hw->cvq = cvq; } - if (hw->use_va) + if (hw->use_va) { vq->mbuf_addr_offset = offsetof(struct rte_mbuf, buf_addr); - else + vq->mbuf_addr_mask = UINTPTR_MAX; + } else { vq->mbuf_addr_offset = offsetof(struct rte_mbuf, buf_iova); + vq->mbuf_addr_mask = UINT64_MAX; + } if (queue_type == VTNET_TQ) { struct virtio_tx_region *txr; diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h index f5d8b40cad..6c58e56555 100644 --- a/drivers/net/virtio/virtqueue.h +++ b/drivers/net/virtio/virtqueue.h @@ -113,17 +113,26 @@ virtqueue_store_flags_packed(struct vring_packed_desc *dp, #define VIRTQUEUE_MAX_NAME_SZ 32 +#ifdef RTE_ARCH_32 +#define VIRTIO_MBUF_ADDR_MASK(vq) ((vq)->mbuf_addr_mask) +#else +#define VIRTIO_MBUF_ADDR_MASK(vq) UINT64_MAX +#endif + /** * Return the IOVA (or virtual address in case of virtio-user) of mbuf * data buffer. * * The address is firstly casted to the word size (sizeof(uintptr_t)) - * before casting it to uint64_t. This is to make it work with different - * combination of word size (64 bit and 32 bit) and virtio device - * (virtio-pci and virtio-user). + * before casting it to uint64_t. It is then masked with the expected + * address length (64 bits for virtio-pci, word size for virtio-user). + * + * This is to make it work with different combination of word size (64 + * bit and 32 bit) and virtio device (virtio-pci and virtio-user). */ #define VIRTIO_MBUF_ADDR(mb, vq) \ - ((uint64_t)(*(uintptr_t *)((uintptr_t)(mb) + (vq)->mbuf_addr_offset))) + ((*(uint64_t *)((uintptr_t)(mb) + (vq)->mbuf_addr_offset)) & \ + VIRTIO_MBUF_ADDR_MASK(vq)) /** * Return the physical address (or virtual address in case of @@ -297,6 +306,7 @@ struct virtqueue { void *vq_ring_virt_mem; /**< linear address of vring*/ unsigned int vq_ring_size; uint16_t mbuf_addr_offset; + uint64_t mbuf_addr_mask; union { struct virtnet_rx rxq; -- 2.42.0