Commit f2784eed authored by Daniel P. Berrangé's avatar Daniel P. Berrangé Committed by Michael S. Tsirkin
Browse files

hw: report invalid disable-legacy|modern usage for virtio-1-only devs



A number of virtio devices (gpu, crypto, mouse, keyboard, tablet) only
support the virtio-1 (aka modern) mode. Currently if the user launches
QEMU, setting those devices to enable legacy mode, QEMU will silently
create them in modern mode, ignoring the user's (mistaken) request.

This patch introduces proper data validation so that an attempt to
configure a virtio-1-only devices in legacy mode gets reported as an
error to the user.

Checking this required introduction of a new field to explicitly track
what operating model is to be used for a device, separately from the
disable_modern and disable_legacy fields that record the user's
requested configuration.

Signed-off-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
Message-Id: <20190215103239.28640-2-berrange@redhat.com>
Reviewed-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent 2259637b
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -102,9 +102,26 @@ const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7);

GlobalProperty hw_compat_2_6[] = {
    { "virtio-mmio", "format_transport_address", "off" },
    /* Optional because not all virtio-pci devices support legacy mode */
    { "virtio-pci", "disable-modern", "on",  .optional = true },
    { "virtio-pci", "disable-legacy", "off", .optional = true },
    /*
     * don't include devices which are modern-only
     * ie keyboard, mouse, tablet, gpu, vga & crypto
     */
    { "virtio-9p-pci", "disable-modern", "on" },
    { "virtio-9p-pci", "disable-legacy", "off" },
    { "virtio-balloon-pci", "disable-modern", "on" },
    { "virtio-balloon-pci", "disable-legacy", "off" },
    { "virtio-blk-pci", "disable-modern", "on" },
    { "virtio-blk-pci", "disable-legacy", "off" },
    { "virtio-input-host-pci", "disable-modern", "on" },
    { "virtio-input-host-pci", "disable-legacy", "off" },
    { "virtio-net-pci", "disable-modern", "on" },
    { "virtio-net-pci", "disable-legacy", "off" },
    { "virtio-rng-pci", "disable-modern", "on" },
    { "virtio-rng-pci", "disable-legacy", "off" },
    { "virtio-scsi-pci", "disable-modern", "on" },
    { "virtio-scsi-pci", "disable-legacy", "off" },
    { "virtio-serial-pci", "disable-modern", "on" },
    { "virtio-serial-pci", "disable-legacy", "off" },
};
const size_t hw_compat_2_6_len = G_N_ELEMENTS(hw_compat_2_6);

+3 −1
Original line number Diff line number Diff line
@@ -47,7 +47,9 @@ static void virtio_gpu_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
    Error *local_error = NULL;

    qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
    virtio_pci_force_virtio_1(vpci_dev);
    if (!virtio_pci_force_virtio_1(vpci_dev, errp)) {
        return;
    }
    object_property_set_bool(OBJECT(vdev), true, "realized", &local_error);

    if (local_error) {
+3 −1
Original line number Diff line number Diff line
@@ -154,7 +154,9 @@ static void virtio_vga_realize(VirtIOPCIProxy *vpci_dev, Error **errp)

    /* init virtio bits */
    qdev_set_parent_bus(DEVICE(g), BUS(&vpci_dev->bus));
    virtio_pci_force_virtio_1(vpci_dev);
    if (!virtio_pci_force_virtio_1(vpci_dev, errp)) {
        return;
    }
    object_property_set_bool(OBJECT(g), true, "realized", &err);
    if (err) {
        error_propagate(errp, err);
+3 −1
Original line number Diff line number Diff line
@@ -51,7 +51,9 @@ static void virtio_crypto_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
    }

    qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
    virtio_pci_force_virtio_1(vpci_dev);
    if (!virtio_pci_force_virtio_1(vpci_dev, errp)) {
        return;
    }
    object_property_set_bool(OBJECT(vdev), true, "realized", errp);
    object_property_set_link(OBJECT(vcrypto),
                 OBJECT(vcrypto->vdev.conf.cryptodev), "cryptodev",
+3 −1
Original line number Diff line number Diff line
@@ -48,7 +48,9 @@ static void virtio_input_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
    DeviceState *vdev = DEVICE(&vinput->vdev);

    qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
    virtio_pci_force_virtio_1(vpci_dev);
    if (!virtio_pci_force_virtio_1(vpci_dev, errp)) {
        return;
    }
    object_property_set_bool(OBJECT(vdev), true, "realized", errp);
}

Loading