Skip to content

Commit

Permalink
Merge tag 'for_upstream' of https://git.kernel.org/pub/scm/virt/kvm/m…
Browse files Browse the repository at this point in the history
…st/qemu into staging

virtio,pc,pci: features, cleanups, fixes

vhost-scsi support for worker ioctls

fixes, cleanups all over the place.

Signed-off-by: Michael S. Tsirkin <[email protected]>

# -----BEGIN PGP SIGNATURE-----
#
# iQFDBAABCAAtFiEEXQn9CHHI+FuUyooNKB8NuNKNVGkFAmWKohIPHG1zdEByZWRo
# YXQuY29tAAoJECgfDbjSjVRpG2YH/1rJGV8TQm4V8kcGP9wOknPAMFADnEFdFmrB
# V+JEDnyKrdcEZLPRh0b846peWRJhC13iL7Ks3VNjeVsfE9TyzNyNDpUzCJPfYFjR
# 3m8ChLDvE9tKBA5/hXMIcgDXaYcPIrPvHyl4HG8EQn7oaeMpS2uecKqDpDDvNXGq
# oNamNvqimFSqA+3ChzA+0Qt07Ts7xFEw4OEXSwfRXlsam/dhQG0SI+crRheHuvFb
# HR8EwmNydA1D/M51AuBNuvX36u3SnPWm7Anp5711SZ1b59unshI0ztIqIJnGkvYe
# qpUJSmxR6ulwWe4nQfb+GhBsuJ2j2ORC7YfXyAT7mw8rds8loaI=
# =cNy2
# -----END PGP SIGNATURE-----
# gpg: Signature made Tue 26 Dec 2023 04:51:14 EST
# gpg:                using RSA key 5D09FD0871C8F85B94CA8A0D281F0DB8D28D5469
# gpg:                issuer "[email protected]"
# gpg: Good signature from "Michael S. Tsirkin <[email protected]>" [full]
# gpg:                 aka "Michael S. Tsirkin <[email protected]>" [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: (21 commits)
  vdpa: move memory listener to vhost_vdpa_shared
  vdpa: use dev_shared in vdpa_iommu
  vdpa: use VhostVDPAShared in vdpa_dma_map and unmap
  vdpa: move iommu_list to vhost_vdpa_shared
  vdpa: remove msg type of vhost_vdpa
  vdpa: move backend_cap to vhost_vdpa_shared
  vdpa: move iotlb_batch_begin_sent to vhost_vdpa_shared
  vdpa: move file descriptor to vhost_vdpa_shared
  vdpa: use vdpa shared for tracing
  vdpa: move shadow_data to vhost_vdpa_shared
  vdpa: move iova_range to vhost_vdpa_shared
  vdpa: move iova tree to the shared struct
  vdpa: add VhostVDPAShared
  vdpa: do not set virtio status bits if unneeded
  Fix bugs when VM shutdown with virtio-gpu unplugged
  vhost-scsi: fix usage of error_reportf_err()
  hw/acpi: propagate vcpu hotplug after switch to modern interface
  vhost-scsi: Add support for a worker thread per virtqueue
  vhost: Add worker backend callouts
  tests: bios-tables-test: Rename smbios type 4 related test functions
  ...

Signed-off-by: Stefan Hajnoczi <[email protected]>
  • Loading branch information
stefanhaRH committed Dec 26, 2023
2 parents b0839e8 + f6fe3e3 commit 455f444
Show file tree
Hide file tree
Showing 14 changed files with 332 additions and 177 deletions.
20 changes: 16 additions & 4 deletions hw/acpi/cpu_hotplug.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = {
},
};

static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu)
static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu,
bool *swtchd_to_modern)
{
CPUClass *k = CPU_GET_CLASS(cpu);
int64_t cpu_id;
Expand All @@ -68,31 +69,42 @@ static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu)
if ((cpu_id / 8) >= ACPI_GPE_PROC_LEN) {
object_property_set_bool(g->device, "cpu-hotplug-legacy", false,
&error_abort);
*swtchd_to_modern = true;
return;
}

*swtchd_to_modern = false;
g->sts[cpu_id / 8] |= (1 << (cpu_id % 8));
}

void legacy_acpi_cpu_plug_cb(HotplugHandler *hotplug_dev,
AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
{
acpi_set_cpu_present_bit(g, CPU(dev));
acpi_send_event(DEVICE(hotplug_dev), ACPI_CPU_HOTPLUG_STATUS);
bool swtchd_to_modern;
Error *local_err = NULL;

acpi_set_cpu_present_bit(g, CPU(dev), &swtchd_to_modern);
if (swtchd_to_modern) {
/* propagate the hotplug to the modern interface */
hotplug_handler_plug(hotplug_dev, dev, &local_err);
} else {
acpi_send_event(DEVICE(hotplug_dev), ACPI_CPU_HOTPLUG_STATUS);
}
}

void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
AcpiCpuHotplug *gpe_cpu, uint16_t base)
{
CPUState *cpu;
bool swtchd_to_modern;

memory_region_init_io(&gpe_cpu->io, owner, &AcpiCpuHotplug_ops,
gpe_cpu, "acpi-cpu-hotplug", ACPI_GPE_PROC_LEN);
memory_region_add_subregion(parent, base, &gpe_cpu->io);
gpe_cpu->device = owner;

CPU_FOREACH(cpu) {
acpi_set_cpu_present_bit(gpe_cpu, cpu);
acpi_set_cpu_present_bit(gpe_cpu, cpu, &swtchd_to_modern);
}
}

Expand Down
4 changes: 4 additions & 0 deletions hw/display/virtio-gpu-base.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ void
virtio_gpu_base_device_unrealize(DeviceState *qdev)
{
VirtIOGPUBase *g = VIRTIO_GPU_BASE(qdev);
VirtIODevice *vdev = VIRTIO_DEVICE(qdev);

virtio_del_queue(vdev, 0);
virtio_del_queue(vdev, 1);
virtio_cleanup(vdev);
migrate_del_blocker(&g->migration_blocker);
}

Expand Down
66 changes: 64 additions & 2 deletions hw/scsi/vhost-scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ static int vhost_scsi_start(VHostSCSI *s)

ret = vhost_scsi_common_start(vsc, &local_err);
if (ret < 0) {
error_reportf_err(local_err, "Error starting vhost-scsi");
error_reportf_err(local_err, "Error starting vhost-scsi: ");
return ret;
}

ret = vhost_scsi_set_endpoint(s);
if (ret < 0) {
error_reportf_err(local_err, "Error setting vhost-scsi endpoint");
error_report("Error setting vhost-scsi endpoint");
vhost_scsi_common_stop(vsc);
}

Expand Down Expand Up @@ -165,6 +165,59 @@ static const VMStateDescription vmstate_virtio_vhost_scsi = {
.pre_save = vhost_scsi_pre_save,
};

static int vhost_scsi_set_workers(VHostSCSICommon *vsc, bool per_virtqueue)
{
struct vhost_dev *dev = &vsc->dev;
struct vhost_vring_worker vq_worker;
struct vhost_worker_state worker;
int i, ret;

/* Use default worker */
if (!per_virtqueue || dev->nvqs == VHOST_SCSI_VQ_NUM_FIXED + 1) {
return 0;
}

/*
* ctl/evt share the first worker since it will be rare for them
* to send cmds while IO is running.
*/
for (i = VHOST_SCSI_VQ_NUM_FIXED + 1; i < dev->nvqs; i++) {
memset(&worker, 0, sizeof(worker));

ret = dev->vhost_ops->vhost_new_worker(dev, &worker);
if (ret == -ENOTTY) {
/*
* worker ioctls are not implemented so just ignore and
* and continue device setup.
*/
warn_report("vhost-scsi: Backend supports a single worker. "
"Ignoring worker_per_virtqueue=true setting.");
ret = 0;
break;
} else if (ret) {
break;
}

memset(&vq_worker, 0, sizeof(vq_worker));
vq_worker.worker_id = worker.worker_id;
vq_worker.index = i;

ret = dev->vhost_ops->vhost_attach_vring_worker(dev, &vq_worker);
if (ret == -ENOTTY) {
/*
* It's a bug for the kernel to have supported the worker creation
* ioctl but not attach.
*/
dev->vhost_ops->vhost_free_worker(dev, &worker);
break;
} else if (ret) {
break;
}
}

return ret;
}

static void vhost_scsi_realize(DeviceState *dev, Error **errp)
{
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev);
Expand Down Expand Up @@ -232,6 +285,13 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp)
goto free_vqs;
}

ret = vhost_scsi_set_workers(vsc, vs->conf.worker_per_virtqueue);
if (ret < 0) {
error_setg(errp, "vhost-scsi: vhost worker setup failed: %s",
strerror(-ret));
goto free_vqs;
}

/* At present, channel and lun both are 0 for bootable vhost-scsi disk */
vsc->channel = 0;
vsc->lun = 0;
Expand Down Expand Up @@ -297,6 +357,8 @@ static Property vhost_scsi_properties[] = {
VIRTIO_SCSI_F_T10_PI,
false),
DEFINE_PROP_BOOL("migratable", VHostSCSICommon, migratable, false),
DEFINE_PROP_BOOL("worker_per_virtqueue", VirtIOSCSICommon,
conf.worker_per_virtqueue, false),
DEFINE_PROP_END_OF_LIST(),
};

Expand Down
3 changes: 2 additions & 1 deletion hw/scsi/vhost-user-scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ static void vhost_user_scsi_set_status(VirtIODevice *vdev, uint8_t status)
if (should_start) {
ret = vhost_user_scsi_start(s, &local_err);
if (ret < 0) {
error_reportf_err(local_err, "unable to start vhost-user-scsi: %s",
error_reportf_err(local_err,
"unable to start vhost-user-scsi: %s: ",
strerror(-ret));
qemu_chr_fe_disconnect(&vs->conf.chardev);
}
Expand Down
14 changes: 7 additions & 7 deletions hw/virtio/trace-events
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ vhost_user_write(uint32_t req, uint32_t flags) "req:%d flags:0x%"PRIx32""
vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p"

# vhost-vdpa.c
vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8
vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8
vhost_vdpa_listener_begin_batch(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8
vhost_vdpa_listener_commit(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8
vhost_vdpa_listener_region_add_unaligned(void *v, const char *name, uint64_t offset_as, uint64_t offset_page) "vdpa: %p region %s offset_within_address_space %"PRIu64" offset_within_region %"PRIu64
vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8
vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8
vhost_vdpa_listener_begin_batch(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8
vhost_vdpa_listener_commit(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8
vhost_vdpa_listener_region_add_unaligned(void *v, const char *name, uint64_t offset_as, uint64_t offset_page) "vdpa_shared: %p region %s offset_within_address_space %"PRIu64" offset_within_region %"PRIu64
vhost_vdpa_listener_region_add(void *vdpa, uint64_t iova, uint64_t llend, void *vaddr, bool readonly) "vdpa: %p iova 0x%"PRIx64" llend 0x%"PRIx64" vaddr: %p read-only: %d"
vhost_vdpa_listener_region_del_unaligned(void *v, const char *name, uint64_t offset_as, uint64_t offset_page) "vdpa: %p region %s offset_within_address_space %"PRIu64" offset_within_region %"PRIu64
vhost_vdpa_listener_region_del_unaligned(void *v, const char *name, uint64_t offset_as, uint64_t offset_page) "vdpa_shared: %p region %s offset_within_address_space %"PRIu64" offset_within_region %"PRIu64
vhost_vdpa_listener_region_del(void *vdpa, uint64_t iova, uint64_t llend) "vdpa: %p iova 0x%"PRIx64" llend 0x%"PRIx64
vhost_vdpa_add_status(void *dev, uint8_t status) "dev: %p status: 0x%"PRIx8
vhost_vdpa_init(void *dev, void *vdpa) "dev: %p vdpa: %p"
vhost_vdpa_init(void *dev, void *s, void *vdpa) "dev: %p, common dev: %p vdpa: %p"
vhost_vdpa_cleanup(void *dev, void *vdpa) "dev: %p vdpa: %p"
vhost_vdpa_memslots_limit(void *dev, int ret) "dev: %p = 0x%x"
vhost_vdpa_set_mem_table(void *dev, uint32_t nregions, uint32_t padding) "dev: %p nregions: %"PRIu32" padding: 0x%"PRIx32
Expand Down
7 changes: 5 additions & 2 deletions hw/virtio/vdpa-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ static void vhost_vdpa_device_realize(DeviceState *dev, Error **errp)
if (*errp) {
return;
}
v->vdpa.device_fd = v->vhostfd;

v->vdev_id = vhost_vdpa_device_get_u32(v->vhostfd,
VHOST_VDPA_GET_DEVICE_ID, errp);
Expand Down Expand Up @@ -114,7 +113,9 @@ static void vhost_vdpa_device_realize(DeviceState *dev, Error **errp)
strerror(-ret));
goto free_vqs;
}
v->vdpa.iova_range = iova_range;
v->vdpa.shared = g_new0(VhostVDPAShared, 1);
v->vdpa.shared->device_fd = v->vhostfd;
v->vdpa.shared->iova_range = iova_range;

ret = vhost_dev_init(&v->dev, &v->vdpa, VHOST_BACKEND_TYPE_VDPA, 0, NULL);
if (ret < 0) {
Expand Down Expand Up @@ -162,6 +163,7 @@ static void vhost_vdpa_device_realize(DeviceState *dev, Error **errp)
vhost_dev_cleanup(&v->dev);
free_vqs:
g_free(vqs);
g_free(v->vdpa.shared);
out:
qemu_close(v->vhostfd);
v->vhostfd = -1;
Expand All @@ -184,6 +186,7 @@ static void vhost_vdpa_device_unrealize(DeviceState *dev)
g_free(s->config);
g_free(s->dev.vqs);
vhost_dev_cleanup(&s->dev);
g_free(s->vdpa.shared);
qemu_close(s->vhostfd);
s->vhostfd = -1;
}
Expand Down
28 changes: 28 additions & 0 deletions hw/virtio/vhost-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,30 @@ static int vhost_kernel_set_vring_busyloop_timeout(struct vhost_dev *dev,
return vhost_kernel_call(dev, VHOST_SET_VRING_BUSYLOOP_TIMEOUT, s);
}

static int vhost_kernel_new_worker(struct vhost_dev *dev,
struct vhost_worker_state *worker)
{
return vhost_kernel_call(dev, VHOST_NEW_WORKER, worker);
}

static int vhost_kernel_free_worker(struct vhost_dev *dev,
struct vhost_worker_state *worker)
{
return vhost_kernel_call(dev, VHOST_FREE_WORKER, worker);
}

static int vhost_kernel_attach_vring_worker(struct vhost_dev *dev,
struct vhost_vring_worker *worker)
{
return vhost_kernel_call(dev, VHOST_ATTACH_VRING_WORKER, worker);
}

static int vhost_kernel_get_vring_worker(struct vhost_dev *dev,
struct vhost_vring_worker *worker)
{
return vhost_kernel_call(dev, VHOST_GET_VRING_WORKER, worker);
}

static int vhost_kernel_set_features(struct vhost_dev *dev,
uint64_t features)
{
Expand Down Expand Up @@ -313,6 +337,10 @@ const VhostOps kernel_ops = {
.vhost_set_vring_err = vhost_kernel_set_vring_err,
.vhost_set_vring_busyloop_timeout =
vhost_kernel_set_vring_busyloop_timeout,
.vhost_get_vring_worker = vhost_kernel_get_vring_worker,
.vhost_attach_vring_worker = vhost_kernel_attach_vring_worker,
.vhost_new_worker = vhost_kernel_new_worker,
.vhost_free_worker = vhost_kernel_free_worker,
.vhost_set_features = vhost_kernel_set_features,
.vhost_get_features = vhost_kernel_get_features,
.vhost_set_backend_cap = vhost_kernel_set_backend_cap,
Expand Down
16 changes: 16 additions & 0 deletions hw/virtio/vhost-user-rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,29 @@ static void vu_rng_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask)
{
VHostUserRNG *rng = VHOST_USER_RNG(vdev);

/*
* We don't support interrupts, return early if index is set to
* VIRTIO_CONFIG_IRQ_IDX.
*/
if (idx == VIRTIO_CONFIG_IRQ_IDX) {
return;
}

vhost_virtqueue_mask(&rng->vhost_dev, vdev, idx, mask);
}

static bool vu_rng_guest_notifier_pending(VirtIODevice *vdev, int idx)
{
VHostUserRNG *rng = VHOST_USER_RNG(vdev);

/*
* We don't support interrupts, return early if index is set to
* VIRTIO_CONFIG_IRQ_IDX.
*/
if (idx == VIRTIO_CONFIG_IRQ_IDX) {
return false;
}

return vhost_virtqueue_pending(&rng->vhost_dev, idx);
}

Expand Down
Loading

0 comments on commit 455f444

Please sign in to comment.