aboutsummaryrefslogtreecommitdiff
path: root/hw/virtio/virtio.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2023-01-09 10:07:11 +0000
committerPeter Maydell <peter.maydell@linaro.org>2023-01-09 10:07:12 +0000
commitd6271b657286de80260413684a1f2a63f44ea17b (patch)
tree0e604002563e1e75a3b114ccb7dbdf30c1690df6 /hw/virtio/virtio.c
parent3d83b78285d6e96636130f7d449fd02e2d4deee0 (diff)
parentaba0d042b1c1be38818cec16af3f34e9e9e2aed2 (diff)
Merge tag 'for_upstream' of https://git.kernel.org/pub/scm/virt/kvm/mst/qemu into staging
virtio,pc,pci: features, cleanups, fixes mostly vhost-vdpa: guest announce feature emulation when using shadow virtqueue support for configure interrupt startup speed ups an acpi change to only generate cluster node in PPTT when specified for arm misc fixes, cleanups Signed-off-by: Michael S. Tsirkin <mst@redhat.com> # gpg: Signature made Sun 08 Jan 2023 08:01:39 GMT # gpg: using RSA key 5D09FD0871C8F85B94CA8A0D281F0DB8D28D5469 # gpg: issuer "mst@redhat.com" # gpg: Good signature from "Michael S. Tsirkin <mst@kernel.org>" [full] # gpg: aka "Michael S. Tsirkin <mst@redhat.com>" [full] # Primary key fingerprint: 0270 606B 6F3C DF3D 0B17 0970 C350 3912 AFBE 8E67 # Subkey fingerprint: 5D09 FD08 71C8 F85B 94CA 8A0D 281F 0DB8 D28D 5469 * tag 'for_upstream' of https://git.kernel.org/pub/scm/virt/kvm/mst/qemu: (50 commits) vhost-scsi: fix memleak of vsc->inflight acpi: cpuhp: fix guest-visible maximum access size to the legacy reg block tests: acpi: aarch64: Add *.topology tables tests: acpi: aarch64: Add topology test for aarch64 tests: acpi: Add and whitelist *.topology blobs tests: virt: Update expected ACPI tables for virt test hw/acpi/aml-build: Only generate cluster node in PPTT when specified tests: virt: Allow changes to PPTT test table virtio-pci: fix proxy->vector_irqfd leak in virtio_pci_set_guest_notifiers vdpa: commit all host notifier MRs in a single MR transaction vhost: configure all host notifiers in a single MR transaction vhost: simplify vhost_dev_enable_notifiers vdpa: harden the error path if get_iova_range failed vdpa-dev: get iova range explicitly docs/devel: Rules on #include in headers include: Include headers where needed include/hw/virtio: Break inclusion loop include/hw/cxl: Break inclusion loop cxl_pci.h and cxl_cdat_h include/hw/pci: Include hw/pci/pci.h where needed include/hw/pci: Split pci_device.h off pci.h ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/virtio/virtio.c')
-rw-r--r--hw/virtio/virtio.c225
1 files changed, 33 insertions, 192 deletions
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 289eb71045..f35178f5fc 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -13,10 +13,7 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
-#include "qapi/qmp/qdict.h"
#include "qapi/qapi-commands-virtio.h"
-#include "qapi/qapi-commands-qom.h"
-#include "qapi/qmp/qjson.h"
#include "trace.h"
#include "qemu/error-report.h"
#include "qemu/log.h"
@@ -25,6 +22,7 @@
#include "qom/object_interfaces.h"
#include "hw/core/cpu.h"
#include "hw/virtio/virtio.h"
+#include "hw/virtio/vhost.h"
#include "migration/qemu-file-types.h"
#include "qemu/atomic.h"
#include "hw/virtio/virtio-bus.h"
@@ -47,8 +45,7 @@
#include "standard-headers/linux/virtio_mem.h"
#include "standard-headers/linux/virtio_vsock.h"
-/* QAPI list of realized VirtIODevices */
-static QTAILQ_HEAD(, VirtIODevice) virtio_list;
+QmpVirtIODeviceList virtio_list;
/*
* Maximum size of virtio device config space
@@ -3417,7 +3414,14 @@ static void virtio_queue_guest_notifier_read(EventNotifier *n)
virtio_irq(vq);
}
}
+static void virtio_config_guest_notifier_read(EventNotifier *n)
+{
+ VirtIODevice *vdev = container_of(n, VirtIODevice, config_notifier);
+ if (event_notifier_test_and_clear(n)) {
+ virtio_notify_config(vdev);
+ }
+}
void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign,
bool with_irqfd)
{
@@ -3434,6 +3438,23 @@ void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign,
}
}
+void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev,
+ bool assign, bool with_irqfd)
+{
+ EventNotifier *n;
+ n = &vdev->config_notifier;
+ if (assign && !with_irqfd) {
+ event_notifier_set_handler(n, virtio_config_guest_notifier_read);
+ } else {
+ event_notifier_set_handler(n, NULL);
+ }
+ if (!assign) {
+ /* Test and clear notifier before closing it,*/
+ /* in case poll callback didn't have time to run. */
+ virtio_config_guest_notifier_read(n);
+ }
+}
+
EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq)
{
return &vq->guest_notifier;
@@ -3514,6 +3535,11 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq)
return &vq->host_notifier;
}
+EventNotifier *virtio_config_get_guest_notifier(VirtIODevice *vdev)
+{
+ return &vdev->config_notifier;
+}
+
void virtio_queue_set_host_notifier_enabled(VirtQueue *vq, bool enabled)
{
vq->host_notifier_enabled = enabled;
@@ -3795,191 +3821,6 @@ bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
return virtio_bus_ioeventfd_enabled(vbus);
}
-VirtioInfoList *qmp_x_query_virtio(Error **errp)
-{
- VirtioInfoList *list = NULL;
- VirtioInfoList *node;
- VirtIODevice *vdev;
-
- QTAILQ_FOREACH(vdev, &virtio_list, next) {
- DeviceState *dev = DEVICE(vdev);
- Error *err = NULL;
- QObject *obj = qmp_qom_get(dev->canonical_path, "realized", &err);
-
- if (err == NULL) {
- GString *is_realized = qobject_to_json_pretty(obj, true);
- /* virtio device is NOT realized, remove it from list */
- if (!strncmp(is_realized->str, "false", 4)) {
- QTAILQ_REMOVE(&virtio_list, vdev, next);
- } else {
- node = g_new0(VirtioInfoList, 1);
- node->value = g_new(VirtioInfo, 1);
- node->value->path = g_strdup(dev->canonical_path);
- node->value->name = g_strdup(vdev->name);
- QAPI_LIST_PREPEND(list, node->value);
- }
- g_string_free(is_realized, true);
- }
- qobject_unref(obj);
- }
-
- return list;
-}
-
-static VirtIODevice *virtio_device_find(const char *path)
-{
- VirtIODevice *vdev;
-
- QTAILQ_FOREACH(vdev, &virtio_list, next) {
- DeviceState *dev = DEVICE(vdev);
-
- if (strcmp(dev->canonical_path, path) != 0) {
- continue;
- }
-
- Error *err = NULL;
- QObject *obj = qmp_qom_get(dev->canonical_path, "realized", &err);
- if (err == NULL) {
- GString *is_realized = qobject_to_json_pretty(obj, true);
- /* virtio device is NOT realized, remove it from list */
- if (!strncmp(is_realized->str, "false", 4)) {
- g_string_free(is_realized, true);
- qobject_unref(obj);
- QTAILQ_REMOVE(&virtio_list, vdev, next);
- return NULL;
- }
- g_string_free(is_realized, true);
- } else {
- /* virtio device doesn't exist in QOM tree */
- QTAILQ_REMOVE(&virtio_list, vdev, next);
- qobject_unref(obj);
- return NULL;
- }
- /* device exists in QOM tree & is realized */
- qobject_unref(obj);
- return vdev;
- }
- return NULL;
-}
-
-VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
-{
- VirtIODevice *vdev;
- VirtioStatus *status;
-
- vdev = virtio_device_find(path);
- if (vdev == NULL) {
- error_setg(errp, "Path %s is not a VirtIODevice", path);
- return NULL;
- }
-
- status = g_new0(VirtioStatus, 1);
- status->name = g_strdup(vdev->name);
- status->device_id = vdev->device_id;
- status->vhost_started = vdev->vhost_started;
- status->guest_features = qmp_decode_features(vdev->device_id,
- vdev->guest_features);
- status->host_features = qmp_decode_features(vdev->device_id,
- vdev->host_features);
- status->backend_features = qmp_decode_features(vdev->device_id,
- vdev->backend_features);
-
- switch (vdev->device_endian) {
- case VIRTIO_DEVICE_ENDIAN_LITTLE:
- status->device_endian = g_strdup("little");
- break;
- case VIRTIO_DEVICE_ENDIAN_BIG:
- status->device_endian = g_strdup("big");
- break;
- default:
- status->device_endian = g_strdup("unknown");
- break;
- }
-
- status->num_vqs = virtio_get_num_queues(vdev);
- status->status = qmp_decode_status(vdev->status);
- status->isr = vdev->isr;
- status->queue_sel = vdev->queue_sel;
- status->vm_running = vdev->vm_running;
- status->broken = vdev->broken;
- status->disabled = vdev->disabled;
- status->use_started = vdev->use_started;
- status->started = vdev->started;
- status->start_on_kick = vdev->start_on_kick;
- status->disable_legacy_check = vdev->disable_legacy_check;
- status->bus_name = g_strdup(vdev->bus_name);
- status->use_guest_notifier_mask = vdev->use_guest_notifier_mask;
-
- if (vdev->vhost_started) {
- VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
- struct vhost_dev *hdev = vdc->get_vhost(vdev);
-
- status->vhost_dev = g_new0(VhostStatus, 1);
- status->vhost_dev->n_mem_sections = hdev->n_mem_sections;
- status->vhost_dev->n_tmp_sections = hdev->n_tmp_sections;
- status->vhost_dev->nvqs = hdev->nvqs;
- status->vhost_dev->vq_index = hdev->vq_index;
- status->vhost_dev->features =
- qmp_decode_features(vdev->device_id, hdev->features);
- status->vhost_dev->acked_features =
- qmp_decode_features(vdev->device_id, hdev->acked_features);
- status->vhost_dev->backend_features =
- qmp_decode_features(vdev->device_id, hdev->backend_features);
- status->vhost_dev->protocol_features =
- qmp_decode_protocols(hdev->protocol_features);
- status->vhost_dev->max_queues = hdev->max_queues;
- status->vhost_dev->backend_cap = hdev->backend_cap;
- status->vhost_dev->log_enabled = hdev->log_enabled;
- status->vhost_dev->log_size = hdev->log_size;
- }
-
- return status;
-}
-
-VirtVhostQueueStatus *qmp_x_query_virtio_vhost_queue_status(const char *path,
- uint16_t queue,
- Error **errp)
-{
- VirtIODevice *vdev;
- VirtVhostQueueStatus *status;
-
- vdev = virtio_device_find(path);
- if (vdev == NULL) {
- error_setg(errp, "Path %s is not a VirtIODevice", path);
- return NULL;
- }
-
- if (!vdev->vhost_started) {
- error_setg(errp, "Error: vhost device has not started yet");
- return NULL;
- }
-
- VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
- struct vhost_dev *hdev = vdc->get_vhost(vdev);
-
- if (queue < hdev->vq_index || queue >= hdev->vq_index + hdev->nvqs) {
- error_setg(errp, "Invalid vhost virtqueue number %d", queue);
- return NULL;
- }
-
- status = g_new0(VirtVhostQueueStatus, 1);
- status->name = g_strdup(vdev->name);
- status->kick = hdev->vqs[queue].kick;
- status->call = hdev->vqs[queue].call;
- status->desc = (uintptr_t)hdev->vqs[queue].desc;
- status->avail = (uintptr_t)hdev->vqs[queue].avail;
- status->used = (uintptr_t)hdev->vqs[queue].used;
- status->num = hdev->vqs[queue].num;
- status->desc_phys = hdev->vqs[queue].desc_phys;
- status->desc_size = hdev->vqs[queue].desc_size;
- status->avail_phys = hdev->vqs[queue].avail_phys;
- status->avail_size = hdev->vqs[queue].avail_size;
- status->used_phys = hdev->vqs[queue].used_phys;
- status->used_size = hdev->vqs[queue].used_size;
-
- return status;
-}
-
VirtQueueStatus *qmp_x_query_virtio_queue_status(const char *path,
uint16_t queue,
Error **errp)
@@ -3987,7 +3828,7 @@ VirtQueueStatus *qmp_x_query_virtio_queue_status(const char *path,
VirtIODevice *vdev;
VirtQueueStatus *status;
- vdev = virtio_device_find(path);
+ vdev = qmp_find_virtio_device(path);
if (vdev == NULL) {
error_setg(errp, "Path %s is not a VirtIODevice", path);
return NULL;
@@ -4080,7 +3921,7 @@ VirtioQueueElement *qmp_x_query_virtio_queue_element(const char *path,
VirtQueue *vq;
VirtioQueueElement *element = NULL;
- vdev = virtio_device_find(path);
+ vdev = qmp_find_virtio_device(path);
if (vdev == NULL) {
error_setg(errp, "Path %s is not a VirtIO device", path);
return NULL;