patches for DPDK stable branches
 help / color / mirror / Atom feed
* [PATCH v21.11.6 1/2] net/virtio: fix descriptor addresses in 32-bit build
@ 2023-11-23 10:11 Maxime Coquelin
  2023-11-23 10:11 ` [PATCH v21.11.6 2/2] vhost: fix missing lock protection in power monitor API Maxime Coquelin
  2023-11-23 10:52 ` [PATCH v21.11.6 1/2] net/virtio: fix descriptor addresses in 32-bit build Kevin Traynor
  0 siblings, 2 replies; 4+ messages in thread
From: Maxime Coquelin @ 2023-11-23 10:11 UTC (permalink / raw)
  To: ktraynor, stable; +Cc: Maxime Coquelin, Sampath Peechu, David Marchand

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 <speechu@cisco.com>
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
(cherry picked from commit 8c41645be010ec7fa0df4f6c3790b167945154b4)
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 .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 <salems@nvidia.com>
 Sameh Gobriel <sameh.gobriel@intel.com>
 Sam Grove <sam.grove@sifive.com>
 Samik Gupta <samik.gupta@broadcom.com>
+Sampath Peechu <speechu@cisco.com>
 Samuel Gauthier <samuel.gauthier@6wind.com>
 Sangjin Han <sangjin@eecs.berkeley.edu>
 Sankar Chokkalingam <sankarx.chokkalingam@intel.com>
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v21.11.6 2/2] vhost: fix missing lock protection in power monitor API
  2023-11-23 10:11 [PATCH v21.11.6 1/2] net/virtio: fix descriptor addresses in 32-bit build Maxime Coquelin
@ 2023-11-23 10:11 ` Maxime Coquelin
  2023-11-23 10:52   ` Kevin Traynor
  2023-11-23 10:52 ` [PATCH v21.11.6 1/2] net/virtio: fix descriptor addresses in 32-bit build Kevin Traynor
  1 sibling, 1 reply; 4+ messages in thread
From: Maxime Coquelin @ 2023-11-23 10:11 UTC (permalink / raw)
  To: ktraynor, stable; +Cc: Maxime Coquelin, David Marchand

The power monitor get API is missing both access lock
protection and access status check.

Fixes: 34fd4373ce76 ("vhost: add power monitor API")
Cc: stable@dpdk.org

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Acked-by: David Marchand <david.marchand@redhat.com>
(cherry picked from commit b4c4e5675c85a9b471c252305811d15f6a6d2aa6)
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 lib/vhost/vhost.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
index 19c7b92c32..a544839de3 100644
--- a/lib/vhost/vhost.c
+++ b/lib/vhost/vhost.c
@@ -2014,6 +2014,7 @@ rte_vhost_get_monitor_addr(int vid, uint16_t queue_id,
 {
 	struct virtio_net *dev = get_device(vid);
 	struct vhost_virtqueue *vq;
+	int ret = 0;
 
 	if (dev == NULL)
 		return -1;
@@ -2024,6 +2025,13 @@ rte_vhost_get_monitor_addr(int vid, uint16_t queue_id,
 	if (vq == NULL)
 		return -1;
 
+	rte_spinlock_lock(&vq->access_lock);
+
+	if (unlikely(!vq->access_ok)) {
+		ret = -1;
+		goto out_unlock;
+	}
+
 	if (vq_is_packed(dev)) {
 		struct vring_packed_desc *desc;
 		desc = vq->desc_packed;
@@ -2043,7 +2051,10 @@ rte_vhost_get_monitor_addr(int vid, uint16_t queue_id,
 		pmc->match = 0;
 	}
 
-	return 0;
+out_unlock:
+	rte_spinlock_unlock(&vq->access_lock);
+
+	return ret;
 }
 
 
-- 
2.42.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v21.11.6 1/2] net/virtio: fix descriptor addresses in 32-bit build
  2023-11-23 10:11 [PATCH v21.11.6 1/2] net/virtio: fix descriptor addresses in 32-bit build Maxime Coquelin
  2023-11-23 10:11 ` [PATCH v21.11.6 2/2] vhost: fix missing lock protection in power monitor API Maxime Coquelin
@ 2023-11-23 10:52 ` Kevin Traynor
  1 sibling, 0 replies; 4+ messages in thread
From: Kevin Traynor @ 2023-11-23 10:52 UTC (permalink / raw)
  To: Maxime Coquelin, stable; +Cc: Sampath Peechu, David Marchand

On 23/11/2023 10:11, Maxime Coquelin wrote:
> 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<speechu@cisco.com>
> Signed-off-by: Maxime Coquelin<maxime.coquelin@redhat.com>
> Reviewed-by: David Marchand<david.marchand@redhat.com>
> (cherry picked from commit 8c41645be010ec7fa0df4f6c3790b167945154b4)
> Signed-off-by: Maxime Coquelin<maxime.coquelin@redhat.com>
> ---
>   .mailmap                           |  1 +
>   drivers/net/virtio/virtio_ethdev.c |  7 +++++--
>   drivers/net/virtio/virtqueue.h     | 18 ++++++++++++++----
>   3 files changed, 20 insertions(+), 6 deletions(-)

Applied to 21.11 branch. Thanks for backporting.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v21.11.6 2/2] vhost: fix missing lock protection in power monitor API
  2023-11-23 10:11 ` [PATCH v21.11.6 2/2] vhost: fix missing lock protection in power monitor API Maxime Coquelin
@ 2023-11-23 10:52   ` Kevin Traynor
  0 siblings, 0 replies; 4+ messages in thread
From: Kevin Traynor @ 2023-11-23 10:52 UTC (permalink / raw)
  To: Maxime Coquelin, stable; +Cc: David Marchand

On 23/11/2023 10:11, Maxime Coquelin wrote:
> The power monitor get API is missing both access lock
> protection and access status check.
> 
> Fixes: 34fd4373ce76 ("vhost: add power monitor API")
> Cc:stable@dpdk.org
> 
> Signed-off-by: Maxime Coquelin<maxime.coquelin@redhat.com>
> Acked-by: David Marchand<david.marchand@redhat.com>
> (cherry picked from commit b4c4e5675c85a9b471c252305811d15f6a6d2aa6)
> Signed-off-by: Maxime Coquelin<maxime.coquelin@redhat.com>
> ---
>   lib/vhost/vhost.c | 13 ++++++++++++-
>   1 file changed, 12 insertions(+), 1 deletion(-)

Applied to 21.11 branch. Thanks for backporting.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-11-23 10:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-23 10:11 [PATCH v21.11.6 1/2] net/virtio: fix descriptor addresses in 32-bit build Maxime Coquelin
2023-11-23 10:11 ` [PATCH v21.11.6 2/2] vhost: fix missing lock protection in power monitor API Maxime Coquelin
2023-11-23 10:52   ` Kevin Traynor
2023-11-23 10:52 ` [PATCH v21.11.6 1/2] net/virtio: fix descriptor addresses in 32-bit build Kevin Traynor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).