Skip to content

Commit 93ea484

Browse files
committed
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging
virtio,pci: bugfixes Minor bugfixes all over the places, including one CVE. Additionally, a fix for an ancient bug in migration - one has to wonder how come no one noticed. The fix is also non-trivial since we dare not break all existing machine types with pci - we have a work around in the works, for now we just skip the work-around for old machine types. Great job by Hogan Wang noticing, debugging and fixing it, and thanks to Dr. David Alan Gilbert for reviewing the patches. Signed-off-by: Michael S. Tsirkin <[email protected]> # gpg: Signature made Mon 27 Jul 2020 16:34:58 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: fix virtio_pci_queue_enabled() MAINTAINERS: Cover the firmware JSON schema vhost-vdpa :Fix Coverity CID 1430270 / CID 1420267 libvhost-user: Report descriptor index on panic Fix vhost-user buffer over-read on ram hot-unplug hw/pci-host: save/restore pci host config register virtio-mem-pci: force virtio version 1 Signed-off-by: Peter Maydell <[email protected]>
2 parents 9303ecb + 0c9753e commit 93ea484

File tree

12 files changed

+60
-10
lines changed

12 files changed

+60
-10
lines changed

MAINTAINERS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2667,6 +2667,14 @@ F: include/hw/i2c/smbus_master.h
26672667
F: include/hw/i2c/smbus_slave.h
26682668
F: include/hw/i2c/smbus_eeprom.h
26692669

2670+
Firmware schema specifications
2671+
M: Laszlo Ersek <[email protected]>
2672+
M: Philippe Mathieu-Daudé <[email protected]>
2673+
R: Daniel P. Berrange <[email protected]>
2674+
R: Kashyap Chamarthy <[email protected]>
2675+
S: Maintained
2676+
F: docs/interop/firmware.json
2677+
26702678
EDK2 Firmware
26712679
M: Laszlo Ersek <[email protected]>
26722680
M: Philippe Mathieu-Daudé <[email protected]>

contrib/libvhost-user/libvhost-user.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,7 +2074,7 @@ virtqueue_get_head(VuDev *dev, VuVirtq *vq,
20742074

20752075
/* If their number is silly, that's a fatal mistake. */
20762076
if (*head >= vq->vring.num) {
2077-
vu_panic(dev, "Guest says index %u is available", head);
2077+
vu_panic(dev, "Guest says index %u is available", *head);
20782078
return false;
20792079
}
20802080

@@ -2133,7 +2133,7 @@ virtqueue_read_next_desc(VuDev *dev, struct vring_desc *desc,
21332133
smp_wmb();
21342134

21352135
if (*next >= max) {
2136-
vu_panic(dev, "Desc next is %u", next);
2136+
vu_panic(dev, "Desc next is %u", *next);
21372137
return VIRTQUEUE_READ_DESC_ERROR;
21382138
}
21392139

hw/core/machine.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "migration/vmstate.h"
3030

3131
GlobalProperty hw_compat_5_0[] = {
32+
{ "pci-host-bridge", "x-config-reg-migration-enabled", "off" },
3233
{ "virtio-balloon-device", "page-poison", "false" },
3334
{ "vmport", "x-read-set-eax", "off" },
3435
{ "vmport", "x-signal-unsupported-cmd", "off" },

hw/i386/pc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@
9797
#include "fw_cfg.h"
9898
#include "trace.h"
9999

100-
GlobalProperty pc_compat_5_0[] = {};
100+
GlobalProperty pc_compat_5_0[] = {
101+
};
101102
const size_t pc_compat_5_0_len = G_N_ELEMENTS(pc_compat_5_0);
102103

103104
GlobalProperty pc_compat_4_2[] = {

hw/pci/pci_host.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
#include "hw/pci/pci.h"
2323
#include "hw/pci/pci_bridge.h"
2424
#include "hw/pci/pci_host.h"
25+
#include "hw/qdev-properties.h"
2526
#include "qemu/module.h"
2627
#include "hw/pci/pci_bus.h"
28+
#include "migration/vmstate.h"
2729
#include "trace.h"
2830

2931
/* debug PCI */
@@ -200,12 +202,43 @@ const MemoryRegionOps pci_host_data_be_ops = {
200202
.endianness = DEVICE_BIG_ENDIAN,
201203
};
202204

205+
static bool pci_host_needed(void *opaque)
206+
{
207+
PCIHostState *s = opaque;
208+
return s->mig_enabled;
209+
}
210+
211+
const VMStateDescription vmstate_pcihost = {
212+
.name = "PCIHost",
213+
.needed = pci_host_needed,
214+
.version_id = 1,
215+
.minimum_version_id = 1,
216+
.fields = (VMStateField[]) {
217+
VMSTATE_UINT32(config_reg, PCIHostState),
218+
VMSTATE_END_OF_LIST()
219+
}
220+
};
221+
222+
static Property pci_host_properties_common[] = {
223+
DEFINE_PROP_BOOL("x-config-reg-migration-enabled", PCIHostState,
224+
mig_enabled, true),
225+
DEFINE_PROP_END_OF_LIST(),
226+
};
227+
228+
static void pci_host_class_init(ObjectClass *klass, void *data)
229+
{
230+
DeviceClass *dc = DEVICE_CLASS(klass);
231+
device_class_set_props(dc, pci_host_properties_common);
232+
dc->vmsd = &vmstate_pcihost;
233+
}
234+
203235
static const TypeInfo pci_host_type_info = {
204236
.name = TYPE_PCI_HOST_BRIDGE,
205237
.parent = TYPE_SYS_BUS_DEVICE,
206238
.abstract = true,
207239
.class_size = sizeof(PCIHostBridgeClass),
208240
.instance_size = sizeof(PCIHostState),
241+
.class_init = pci_host_class_init,
209242
};
210243

211244
static void pci_host_register_types(void)

hw/virtio/vhost-user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ static int send_remove_regions(struct vhost_dev *dev,
672672
memmove(&u->shadow_regions[shadow_reg_idx],
673673
&u->shadow_regions[shadow_reg_idx + 1],
674674
sizeof(struct vhost_memory_region) *
675-
(u->num_shadow_regions - shadow_reg_idx));
675+
(u->num_shadow_regions - shadow_reg_idx - 1));
676676
u->num_shadow_regions--;
677677
}
678678

hw/virtio/vhost-vdpa.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static bool vhost_vdpa_listener_skipped_section(MemoryRegionSection *section)
3737
static int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size,
3838
void *vaddr, bool readonly)
3939
{
40-
struct vhost_msg_v2 msg;
40+
struct vhost_msg_v2 msg = {};
4141
int fd = v->device_fd;
4242
int ret = 0;
4343

@@ -60,7 +60,7 @@ static int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size,
6060
static int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova,
6161
hwaddr size)
6262
{
63-
struct vhost_msg_v2 msg;
63+
struct vhost_msg_v2 msg = {};
6464
int fd = v->device_fd;
6565
int ret = 0;
6666

hw/virtio/virtio-mem-pci.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ static void virtio_mem_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
2121
VirtIOMEMPCI *mem_pci = VIRTIO_MEM_PCI(vpci_dev);
2222
DeviceState *vdev = DEVICE(&mem_pci->vdev);
2323

24-
qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
25-
object_property_set_bool(OBJECT(vdev), "realized", true, errp);
24+
virtio_pci_force_virtio_1(vpci_dev);
25+
qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
2626
}
2727

2828
static void virtio_mem_pci_set_addr(MemoryDeviceState *md, uint64_t addr,

hw/virtio/virtio-pci.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ static bool virtio_pci_queue_enabled(DeviceState *d, int n)
11161116
return proxy->vqs[vdev->queue_sel].enabled;
11171117
}
11181118

1119-
return virtio_queue_enabled(vdev, n);
1119+
return virtio_queue_enabled_legacy(vdev, n);
11201120
}
11211121

11221122
static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy,

hw/virtio/virtio.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3309,6 +3309,11 @@ hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n)
33093309
return vdev->vq[n].vring.desc;
33103310
}
33113311

3312+
bool virtio_queue_enabled_legacy(VirtIODevice *vdev, int n)
3313+
{
3314+
return virtio_queue_get_desc_addr(vdev, n) != 0;
3315+
}
3316+
33123317
bool virtio_queue_enabled(VirtIODevice *vdev, int n)
33133318
{
33143319
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
@@ -3317,7 +3322,7 @@ bool virtio_queue_enabled(VirtIODevice *vdev, int n)
33173322
if (k->queue_enabled) {
33183323
return k->queue_enabled(qbus->parent, n);
33193324
}
3320-
return virtio_queue_get_desc_addr(vdev, n) != 0;
3325+
return virtio_queue_enabled_legacy(vdev, n);
33213326
}
33223327

33233328
hwaddr virtio_queue_get_avail_addr(VirtIODevice *vdev, int n)

0 commit comments

Comments
 (0)