Skip to content

Commit 8ffa52c

Browse files
committed
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging
acpi,virtio,pc: bugfixes Fix bug in ACPI which were tripping up guests. Fix a use-after-free with hotplug of virtio devices. Block ability to create legacy devices which shouldn't have been there in the first place. Fix migration error handling with balloon. Drop some dead code in virtio. vtd emulation fixup. Signed-off-by: Michael S. Tsirkin <[email protected]> # gpg: Signature made Wed 22 Jul 2020 13:07:26 BST # 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 * remotes/mst/tags/for_upstream: virtio-pci: Changed vdev to proxy for VirtIO PCI BAR callbacks. intel_iommu: Use correct shift for 256 bits qi descriptor virtio: verify that legacy support is not accidentally on virtio: list legacy-capable devices virtio-balloon: Replace free page hinting references to 'report' with 'hint' virtio-balloon: Add locking to prevent possible race when starting hinting virtio-balloon: Prevent guest from starting a report when we didn't request one virtio: Drop broken and superfluous object_property_set_link() acpi: accept byte and word access to core ACPI registers Signed-off-by: Peter Maydell <[email protected]>
2 parents 53ce7b4 + ccec7e9 commit 8ffa52c

File tree

13 files changed

+127
-73
lines changed

13 files changed

+127
-73
lines changed

hw/acpi/core.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,8 @@ static void acpi_pm_evt_write(void *opaque, hwaddr addr, uint64_t val,
458458
static const MemoryRegionOps acpi_pm_evt_ops = {
459459
.read = acpi_pm_evt_read,
460460
.write = acpi_pm_evt_write,
461-
.valid.min_access_size = 2,
461+
.impl.min_access_size = 2,
462+
.valid.min_access_size = 1,
462463
.valid.max_access_size = 2,
463464
.endianness = DEVICE_LITTLE_ENDIAN,
464465
};
@@ -527,7 +528,8 @@ static void acpi_pm_tmr_write(void *opaque, hwaddr addr, uint64_t val,
527528
static const MemoryRegionOps acpi_pm_tmr_ops = {
528529
.read = acpi_pm_tmr_read,
529530
.write = acpi_pm_tmr_write,
530-
.valid.min_access_size = 4,
531+
.impl.min_access_size = 4,
532+
.valid.min_access_size = 1,
531533
.valid.max_access_size = 4,
532534
.endianness = DEVICE_LITTLE_ENDIAN,
533535
};
@@ -599,7 +601,8 @@ static void acpi_pm_cnt_write(void *opaque, hwaddr addr, uint64_t val,
599601
static const MemoryRegionOps acpi_pm_cnt_ops = {
600602
.read = acpi_pm_cnt_read,
601603
.write = acpi_pm_cnt_write,
602-
.valid.min_access_size = 2,
604+
.impl.min_access_size = 2,
605+
.valid.min_access_size = 1,
603606
.valid.max_access_size = 2,
604607
.endianness = DEVICE_LITTLE_ENDIAN,
605608
};

hw/i386/intel_iommu.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2549,6 +2549,11 @@ static bool vtd_process_inv_desc(IntelIOMMUState *s)
25492549
/* Try to fetch and process more Invalidation Descriptors */
25502550
static void vtd_fetch_inv_desc(IntelIOMMUState *s)
25512551
{
2552+
int qi_shift;
2553+
2554+
/* Refer to 10.4.23 of VT-d spec 3.0 */
2555+
qi_shift = s->iq_dw ? VTD_IQH_QH_SHIFT_5 : VTD_IQH_QH_SHIFT_4;
2556+
25522557
trace_vtd_inv_qi_fetch();
25532558

25542559
if (s->iq_tail >= s->iq_size) {
@@ -2567,7 +2572,7 @@ static void vtd_fetch_inv_desc(IntelIOMMUState *s)
25672572
}
25682573
/* Must update the IQH_REG in time */
25692574
vtd_set_quad_raw(s, DMAR_IQH_REG,
2570-
(((uint64_t)(s->iq_head)) << VTD_IQH_QH_SHIFT) &
2575+
(((uint64_t)(s->iq_head)) << qi_shift) &
25712576
VTD_IQH_QH_MASK);
25722577
}
25732578
}

hw/i386/intel_iommu_internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@
230230
#define VTD_IQA_DW_MASK 0x800
231231

232232
/* IQH_REG */
233-
#define VTD_IQH_QH_SHIFT 4
233+
#define VTD_IQH_QH_SHIFT_4 4
234+
#define VTD_IQH_QH_SHIFT_5 5
234235
#define VTD_IQH_QH_MASK 0x7fff0ULL
235236

236237
/* ICS_REG */

hw/s390x/virtio-ccw-crypto.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ static void virtio_ccw_crypto_realize(VirtioCcwDevice *ccw_dev, Error **errp)
2323
if (!qdev_realize(vdev, BUS(&ccw_dev->bus), errp)) {
2424
return;
2525
}
26-
27-
object_property_set_link(OBJECT(vdev), "cryptodev",
28-
OBJECT(dev->vdev.conf.cryptodev), NULL);
2926
}
3027

3128
static void virtio_ccw_crypto_instance_init(Object *obj)

hw/s390x/virtio-ccw-rng.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ static void virtio_ccw_rng_realize(VirtioCcwDevice *ccw_dev, Error **errp)
2424
if (!qdev_realize(vdev, BUS(&ccw_dev->bus), errp)) {
2525
return;
2626
}
27-
28-
object_property_set_link(OBJECT(dev), "rng", OBJECT(dev->vdev.conf.rng),
29-
NULL);
3027
}
3128

3229
static void virtio_ccw_rng_instance_init(Object *obj)

hw/s390x/virtio-ccw.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,12 @@ static void virtio_ccw_device_plugged(DeviceState *d, Error **errp)
11211121
dev->max_rev = 0;
11221122
}
11231123

1124+
if (!virtio_ccw_rev_max(dev) && !virtio_legacy_allowed(vdev)) {
1125+
error_setg(errp, "Invalid value of property max_rev "
1126+
"(is %d expected >= 1)", virtio_ccw_rev_max(dev));
1127+
return;
1128+
}
1129+
11241130
if (virtio_get_num_queues(vdev) > VIRTIO_QUEUE_MAX) {
11251131
error_setg(errp, "The number of virtqueues %d "
11261132
"exceeds virtio limit %d", n,

hw/virtio/virtio-balloon.c

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -526,21 +526,22 @@ static bool get_free_page_hints(VirtIOBalloon *dev)
526526
ret = false;
527527
goto out;
528528
}
529-
if (id == dev->free_page_report_cmd_id) {
530-
dev->free_page_report_status = FREE_PAGE_REPORT_S_START;
529+
if (dev->free_page_hint_status == FREE_PAGE_HINT_S_REQUESTED &&
530+
id == dev->free_page_hint_cmd_id) {
531+
dev->free_page_hint_status = FREE_PAGE_HINT_S_START;
531532
} else {
532533
/*
533534
* Stop the optimization only when it has started. This
534535
* avoids a stale stop sign for the previous command.
535536
*/
536-
if (dev->free_page_report_status == FREE_PAGE_REPORT_S_START) {
537-
dev->free_page_report_status = FREE_PAGE_REPORT_S_STOP;
537+
if (dev->free_page_hint_status == FREE_PAGE_HINT_S_START) {
538+
dev->free_page_hint_status = FREE_PAGE_HINT_S_STOP;
538539
}
539540
}
540541
}
541542

542543
if (elem->in_num) {
543-
if (dev->free_page_report_status == FREE_PAGE_REPORT_S_START) {
544+
if (dev->free_page_hint_status == FREE_PAGE_HINT_S_START) {
544545
qemu_guest_free_page_hint(elem->in_sg[0].iov_base,
545546
elem->in_sg[0].iov_len);
546547
}
@@ -566,11 +567,11 @@ static void virtio_ballloon_get_free_page_hints(void *opaque)
566567
qemu_mutex_unlock(&dev->free_page_lock);
567568
virtio_notify(vdev, vq);
568569
/*
569-
* Start to poll the vq once the reporting started. Otherwise, continue
570+
* Start to poll the vq once the hinting started. Otherwise, continue
570571
* only when there are entries on the vq, which need to be given back.
571572
*/
572573
} while (continue_to_get_hints ||
573-
dev->free_page_report_status == FREE_PAGE_REPORT_S_START);
574+
dev->free_page_hint_status == FREE_PAGE_HINT_S_START);
574575
virtio_queue_set_notification(vq, 1);
575576
}
576577

@@ -591,33 +592,37 @@ static void virtio_balloon_free_page_start(VirtIOBalloon *s)
591592
return;
592593
}
593594

594-
if (s->free_page_report_cmd_id == UINT_MAX) {
595-
s->free_page_report_cmd_id =
596-
VIRTIO_BALLOON_FREE_PAGE_REPORT_CMD_ID_MIN;
595+
qemu_mutex_lock(&s->free_page_lock);
596+
597+
if (s->free_page_hint_cmd_id == UINT_MAX) {
598+
s->free_page_hint_cmd_id =
599+
VIRTIO_BALLOON_FREE_PAGE_HINT_CMD_ID_MIN;
597600
} else {
598-
s->free_page_report_cmd_id++;
601+
s->free_page_hint_cmd_id++;
599602
}
600603

601-
s->free_page_report_status = FREE_PAGE_REPORT_S_REQUESTED;
604+
s->free_page_hint_status = FREE_PAGE_HINT_S_REQUESTED;
605+
qemu_mutex_unlock(&s->free_page_lock);
606+
602607
virtio_notify_config(vdev);
603608
}
604609

605610
static void virtio_balloon_free_page_stop(VirtIOBalloon *s)
606611
{
607612
VirtIODevice *vdev = VIRTIO_DEVICE(s);
608613

609-
if (s->free_page_report_status != FREE_PAGE_REPORT_S_STOP) {
614+
if (s->free_page_hint_status != FREE_PAGE_HINT_S_STOP) {
610615
/*
611616
* The lock also guarantees us that the
612617
* virtio_ballloon_get_free_page_hints exits after the
613-
* free_page_report_status is set to S_STOP.
618+
* free_page_hint_status is set to S_STOP.
614619
*/
615620
qemu_mutex_lock(&s->free_page_lock);
616621
/*
617-
* The guest hasn't done the reporting, so host sends a notification
618-
* to the guest to actively stop the reporting.
622+
* The guest isn't done hinting, so send a notification
623+
* to the guest to actively stop the hinting.
619624
*/
620-
s->free_page_report_status = FREE_PAGE_REPORT_S_STOP;
625+
s->free_page_hint_status = FREE_PAGE_HINT_S_STOP;
621626
qemu_mutex_unlock(&s->free_page_lock);
622627
virtio_notify_config(vdev);
623628
}
@@ -627,20 +632,20 @@ static void virtio_balloon_free_page_done(VirtIOBalloon *s)
627632
{
628633
VirtIODevice *vdev = VIRTIO_DEVICE(s);
629634

630-
if (s->free_page_report_status != FREE_PAGE_REPORT_S_DONE) {
635+
if (s->free_page_hint_status != FREE_PAGE_HINT_S_DONE) {
631636
/* See virtio_balloon_free_page_stop() */
632637
qemu_mutex_lock(&s->free_page_lock);
633-
s->free_page_report_status = FREE_PAGE_REPORT_S_DONE;
638+
s->free_page_hint_status = FREE_PAGE_HINT_S_DONE;
634639
qemu_mutex_unlock(&s->free_page_lock);
635640
virtio_notify_config(vdev);
636641
}
637642
}
638643

639644
static int
640-
virtio_balloon_free_page_report_notify(NotifierWithReturn *n, void *data)
645+
virtio_balloon_free_page_hint_notify(NotifierWithReturn *n, void *data)
641646
{
642647
VirtIOBalloon *dev = container_of(n, VirtIOBalloon,
643-
free_page_report_notify);
648+
free_page_hint_notify);
644649
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
645650
PrecopyNotifyData *pnd = data;
646651

@@ -698,7 +703,7 @@ static size_t virtio_balloon_config_size(VirtIOBalloon *s)
698703
if (virtio_has_feature(features, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) {
699704
return offsetof(struct virtio_balloon_config, poison_val);
700705
}
701-
return offsetof(struct virtio_balloon_config, free_page_report_cmd_id);
706+
return offsetof(struct virtio_balloon_config, free_page_hint_cmd_id);
702707
}
703708

704709
static void virtio_balloon_get_config(VirtIODevice *vdev, uint8_t *config_data)
@@ -710,14 +715,14 @@ static void virtio_balloon_get_config(VirtIODevice *vdev, uint8_t *config_data)
710715
config.actual = cpu_to_le32(dev->actual);
711716
config.poison_val = cpu_to_le32(dev->poison_val);
712717

713-
if (dev->free_page_report_status == FREE_PAGE_REPORT_S_REQUESTED) {
714-
config.free_page_report_cmd_id =
715-
cpu_to_le32(dev->free_page_report_cmd_id);
716-
} else if (dev->free_page_report_status == FREE_PAGE_REPORT_S_STOP) {
717-
config.free_page_report_cmd_id =
718+
if (dev->free_page_hint_status == FREE_PAGE_HINT_S_REQUESTED) {
719+
config.free_page_hint_cmd_id =
720+
cpu_to_le32(dev->free_page_hint_cmd_id);
721+
} else if (dev->free_page_hint_status == FREE_PAGE_HINT_S_STOP) {
722+
config.free_page_hint_cmd_id =
718723
cpu_to_le32(VIRTIO_BALLOON_CMD_ID_STOP);
719-
} else if (dev->free_page_report_status == FREE_PAGE_REPORT_S_DONE) {
720-
config.free_page_report_cmd_id =
724+
} else if (dev->free_page_hint_status == FREE_PAGE_HINT_S_DONE) {
725+
config.free_page_hint_cmd_id =
721726
cpu_to_le32(VIRTIO_BALLOON_CMD_ID_DONE);
722727
}
723728

@@ -830,14 +835,14 @@ static int virtio_balloon_post_load_device(void *opaque, int version_id)
830835
return 0;
831836
}
832837

833-
static const VMStateDescription vmstate_virtio_balloon_free_page_report = {
838+
static const VMStateDescription vmstate_virtio_balloon_free_page_hint = {
834839
.name = "virtio-balloon-device/free-page-report",
835840
.version_id = 1,
836841
.minimum_version_id = 1,
837842
.needed = virtio_balloon_free_page_support,
838843
.fields = (VMStateField[]) {
839-
VMSTATE_UINT32(free_page_report_cmd_id, VirtIOBalloon),
840-
VMSTATE_UINT32(free_page_report_status, VirtIOBalloon),
844+
VMSTATE_UINT32(free_page_hint_cmd_id, VirtIOBalloon),
845+
VMSTATE_UINT32(free_page_hint_status, VirtIOBalloon),
841846
VMSTATE_END_OF_LIST()
842847
}
843848
};
@@ -864,7 +869,7 @@ static const VMStateDescription vmstate_virtio_balloon_device = {
864869
VMSTATE_END_OF_LIST()
865870
},
866871
.subsections = (const VMStateDescription * []) {
867-
&vmstate_virtio_balloon_free_page_report,
872+
&vmstate_virtio_balloon_free_page_hint,
868873
&vmstate_virtio_balloon_page_poison,
869874
NULL
870875
}
@@ -903,7 +908,7 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp)
903908
VIRTIO_BALLOON_F_FREE_PAGE_HINT)) {
904909
s->free_page_vq = virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE,
905910
virtio_balloon_handle_free_page_vq);
906-
precopy_add_notifier(&s->free_page_report_notify);
911+
precopy_add_notifier(&s->free_page_hint_notify);
907912

908913
object_ref(OBJECT(s->iothread));
909914
s->free_page_bh = aio_bh_new(iothread_get_aio_context(s->iothread),
@@ -927,7 +932,7 @@ static void virtio_balloon_device_unrealize(DeviceState *dev)
927932
qemu_bh_delete(s->free_page_bh);
928933
object_unref(OBJECT(s->iothread));
929934
virtio_balloon_free_page_stop(s);
930-
precopy_remove_notifier(&s->free_page_report_notify);
935+
precopy_remove_notifier(&s->free_page_hint_notify);
931936
}
932937
balloon_stats_destroy_timer(s);
933938
qemu_remove_balloon_handler(s);
@@ -999,8 +1004,8 @@ static void virtio_balloon_instance_init(Object *obj)
9991004

10001005
qemu_mutex_init(&s->free_page_lock);
10011006
qemu_cond_init(&s->free_page_cond);
1002-
s->free_page_report_cmd_id = VIRTIO_BALLOON_FREE_PAGE_REPORT_CMD_ID_MIN;
1003-
s->free_page_report_notify.notify = virtio_balloon_free_page_report_notify;
1007+
s->free_page_hint_cmd_id = VIRTIO_BALLOON_FREE_PAGE_HINT_CMD_ID_MIN;
1008+
s->free_page_hint_notify.notify = virtio_balloon_free_page_hint_notify;
10041009

10051010
object_property_add(obj, "guest-stats", "guest statistics",
10061011
balloon_stats_get_all, NULL, NULL, s);

hw/virtio/virtio-crypto-pci.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ static void virtio_crypto_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
5757
if (!qdev_realize(vdev, BUS(&vpci_dev->bus), errp)) {
5858
return;
5959
}
60-
object_property_set_link(OBJECT(vcrypto), "cryptodev",
61-
OBJECT(vcrypto->vdev.conf.cryptodev), NULL);
6260
}
6361

6462
static void virtio_crypto_pci_class_init(ObjectClass *klass, void *data)

0 commit comments

Comments
 (0)