[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 04/91] virtio/virtio-pci: Handle extra notification data
From: |
Michael S. Tsirkin |
Subject: |
[PULL v2 04/91] virtio/virtio-pci: Handle extra notification data |
Date: |
Tue, 2 Jul 2024 16:13:50 -0400 |
From: Jonah Palmer <jonah.palmer@oracle.com>
Add support to virtio-pci devices for handling the extra data sent
from the driver to the device when the VIRTIO_F_NOTIFICATION_DATA
transport feature has been negotiated.
The extra data that's passed to the virtio-pci device when this
feature is enabled varies depending on the device's virtqueue
layout.
In a split virtqueue layout, this data includes:
- upper 16 bits: shadow_avail_idx
- lower 16 bits: virtqueue index
In a packed virtqueue layout, this data includes:
- upper 16 bits: 1-bit wrap counter & 15-bit shadow_avail_idx
- lower 16 bits: virtqueue index
Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
Message-Id: <20240315165557.26942-2-jonah.palmer@oracle.com>
Reviewed-by: Eugenio PĂ©rez <eperezma@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/virtio/virtio.h | 2 ++
hw/virtio/virtio-pci.c | 12 +++++++++---
hw/virtio/virtio.c | 18 ++++++++++++++++++
3 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 7d5ffdc145..1451926a13 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -307,6 +307,8 @@ int virtio_queue_ready(VirtQueue *vq);
int virtio_queue_empty(VirtQueue *vq);
+void virtio_queue_set_shadow_avail_idx(VirtQueue *vq, uint16_t idx);
+
/* Host binding interface. */
uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr);
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index b1d02f4b3d..cffc7efcae 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -384,7 +384,7 @@ static void virtio_ioport_write(void *opaque, uint32_t
addr, uint32_t val)
{
VirtIOPCIProxy *proxy = opaque;
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
- uint16_t vector;
+ uint16_t vector, vq_idx;
hwaddr pa;
switch (addr) {
@@ -408,8 +408,14 @@ static void virtio_ioport_write(void *opaque, uint32_t
addr, uint32_t val)
vdev->queue_sel = val;
break;
case VIRTIO_PCI_QUEUE_NOTIFY:
- if (val < VIRTIO_QUEUE_MAX) {
- virtio_queue_notify(vdev, val);
+ vq_idx = val;
+ if (vq_idx < VIRTIO_QUEUE_MAX && virtio_queue_get_num(vdev, vq_idx)) {
+ if (virtio_vdev_has_feature(vdev, VIRTIO_F_NOTIFICATION_DATA)) {
+ VirtQueue *vq = virtio_get_queue(vdev, vq_idx);
+
+ virtio_queue_set_shadow_avail_idx(vq, val >> 16);
+ }
+ virtio_queue_notify(vdev, vq_idx);
}
break;
case VIRTIO_PCI_STATUS:
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 893a072c9d..f7c99e3a96 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -2264,6 +2264,24 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n,
int align)
}
}
+void virtio_queue_set_shadow_avail_idx(VirtQueue *vq, uint16_t
shadow_avail_idx)
+{
+ if (!vq->vring.desc) {
+ return;
+ }
+
+ /*
+ * 16-bit data for packed VQs include 1-bit wrap counter and
+ * 15-bit shadow_avail_idx.
+ */
+ if (virtio_vdev_has_feature(vq->vdev, VIRTIO_F_RING_PACKED)) {
+ vq->shadow_avail_wrap_counter = (shadow_avail_idx >> 15) & 0x1;
+ vq->shadow_avail_idx = shadow_avail_idx & 0x7FFF;
+ } else {
+ vq->shadow_avail_idx = shadow_avail_idx;
+ }
+}
+
static void virtio_queue_notify_vq(VirtQueue *vq)
{
if (vq->vring.desc && vq->handle_output) {
--
MST
- [PULL v2 00/91] virtio: features,fixes, Michael S. Tsirkin, 2024/07/02
- [PULL v2 01/91] vhost: dirty log should be per backend type, Michael S. Tsirkin, 2024/07/02
- [PULL v2 02/91] vhost: Perform memory section dirty scans once per iteration, Michael S. Tsirkin, 2024/07/02
- [PULL v2 03/91] vhost-vdpa: check vhost_vdpa_set_vring_ready() return value, Michael S. Tsirkin, 2024/07/02
- [PULL v2 04/91] virtio/virtio-pci: Handle extra notification data,
Michael S. Tsirkin <=
- [PULL v2 05/91] virtio: Prevent creation of device using notification-data with ioeventfd, Michael S. Tsirkin, 2024/07/02
- [PULL v2 06/91] virtio-mmio: Handle extra notification data, Michael S. Tsirkin, 2024/07/02
- [PULL v2 07/91] virtio-ccw: Handle extra notification data, Michael S. Tsirkin, 2024/07/02
- [PULL v2 08/91] vhost/vhost-user: Add VIRTIO_F_NOTIFICATION_DATA to vhost feature bits, Michael S. Tsirkin, 2024/07/02
- [PULL v2 09/91] Fix vhost user assertion when sending more than one fd, Michael S. Tsirkin, 2024/07/02
- [PULL v2 10/91] vhost-vsock: add VIRTIO_F_RING_PACKED to feature_bits, Michael S. Tsirkin, 2024/07/02
- [PULL v2 11/91] hw/virtio: Fix obtain the buffer id from the last descriptor, Michael S. Tsirkin, 2024/07/02
- [PULL v2 12/91] virtio-pci: only reset pm state during resetting, Michael S. Tsirkin, 2024/07/02
- [PULL v2 13/91] vhost-user-gpu: fix import of DMABUF, Michael S. Tsirkin, 2024/07/02
- [PULL v2 14/91] Revert "vhost-user: fix lost reconnect", Michael S. Tsirkin, 2024/07/02