qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

qdev: Reject drive property override

qdev_prop_set_drive() screws up when the property already has a
non-null value: it neglects to release the old value. Both the old
and the new backend become attached to the same device.

Example (taken from iotest 172): -fda ... -drive if=none,... -global
floppy.drive=none0.

Special case: attempting to use the same backend both times fails.
Example (also from iotest 172): -fda ... -global floppy.drive=floppy0.

Yet another example: -device with multiple drive=... (but not
device_add, which silently drops all but the last duplicate property).

Perhaps drive property override could be made to work. Perhaps it
should. I can't afford the time to figure this out now. What I can
do is reject usage that leaves backends in unhealthy states. For what
it's worth, we've long done the same for netdev properties.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200622094227.1271650-12-armbru@redhat.com>

+11 -85
+8
hw/core/qdev-properties-system.c
··· 98 98 return; 99 99 } 100 100 101 + /* 102 + * TODO Should this really be an error? If no, the old value 103 + * needs to be released before we store the new one. 104 + */ 105 + if (!check_prop_still_unset(dev, name, *ptr, str, errp)) { 106 + return; 107 + } 108 + 101 109 if (!*str) { 102 110 g_free(str); 103 111 *ptr = NULL;
+3 -85
tests/qemu-iotests/172.out
··· 795 795 QEMU_PROG: Floppy unit 1 is in use 796 796 797 797 Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global floppy.drive=none0 798 - 799 - dev: isa-fdc, id "" 800 - iobase = 1008 (0x3f0) 801 - irq = 6 (0x6) 802 - dma = 2 (0x2) 803 - driveA = "" 804 - driveB = "" 805 - check_media_rate = true 806 - fdtypeA = "auto" 807 - fdtypeB = "auto" 808 - fallback = "288" 809 - isa irq 6 810 - bus: floppy-bus.0 811 - type floppy-bus 812 - dev: floppy, id "" 813 - unit = 0 (0x0) 814 - drive = "floppy0" 815 - logical_block_size = 512 (512 B) 816 - physical_block_size = 512 (512 B) 817 - min_io_size = 0 (0 B) 818 - opt_io_size = 0 (0 B) 819 - discard_granularity = 4294967295 (4 GiB) 820 - write-cache = "auto" 821 - share-rw = false 822 - drive-type = "144" 823 - floppy0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) 824 - Attached to: /machine/unattached/device[15] 825 - Removable device: not locked, tray closed 826 - Cache mode: writeback 827 - 828 - none0 (NODE_NAME): TEST_DIR/t.qcow2.2 (qcow2) 829 - Attached to: /machine/unattached/device[15] 830 - Cache mode: writeback 831 - 832 - ide1-cd0: [not inserted] 833 - Attached to: /machine/unattached/device[22] 834 - Removable device: not locked, tray closed 835 - 836 - sd0: [not inserted] 837 - Removable device: not locked, tray closed 838 - (qemu) quit 839 - 798 + QEMU_PROG: -global floppy.drive=... conflicts with drive=floppy0 840 799 841 800 842 801 === Mixing -fdX and -device === ··· 1475 1434 QEMU_PROG: -device floppy,drive=none1,unit=1: Floppy unit 1 is in use 1476 1435 1477 1436 Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global floppy.drive=none0 -device floppy,drive=none1,unit=0 1478 - 1479 - dev: isa-fdc, id "" 1480 - iobase = 1008 (0x3f0) 1481 - irq = 6 (0x6) 1482 - dma = 2 (0x2) 1483 - driveA = "" 1484 - driveB = "" 1485 - check_media_rate = true 1486 - fdtypeA = "auto" 1487 - fdtypeB = "auto" 1488 - fallback = "288" 1489 - isa irq 6 1490 - bus: floppy-bus.0 1491 - type floppy-bus 1492 - dev: floppy, id "" 1493 - unit = 0 (0x0) 1494 - drive = "none1" 1495 - logical_block_size = 512 (512 B) 1496 - physical_block_size = 512 (512 B) 1497 - min_io_size = 0 (0 B) 1498 - opt_io_size = 0 (0 B) 1499 - discard_granularity = 4294967295 (4 GiB) 1500 - write-cache = "auto" 1501 - share-rw = false 1502 - drive-type = "144" 1503 - none0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) 1504 - Attached to: /machine/peripheral-anon/device[0] 1505 - Cache mode: writeback 1506 - 1507 - none1 (NODE_NAME): TEST_DIR/t.qcow2.2 (qcow2) 1508 - Attached to: /machine/peripheral-anon/device[0] 1509 - Removable device: not locked, tray closed 1510 - Cache mode: writeback 1511 - 1512 - ide1-cd0: [not inserted] 1513 - Attached to: /machine/unattached/device[21] 1514 - Removable device: not locked, tray closed 1515 - 1516 - sd0: [not inserted] 1517 - Removable device: not locked, tray closed 1518 - (qemu) quit 1519 - 1437 + QEMU_PROG: -device floppy,drive=none1,unit=0: -global floppy.drive=... conflicts with drive=none1 1520 1438 1521 1439 1522 1440 === Attempt to use drive twice === ··· 1531 1449 QEMU_PROG: -device floppy,drive=floppy0: Drive 'floppy0' is already in use because it has been automatically connected to another device (did you need 'if=none' in the drive options?) 1532 1450 1533 1451 Testing: -fda -global floppy.drive=floppy0 1534 - QEMU_PROG: Drive 'floppy0' is already in use because it has been automatically connected to another device (did you need 'if=none' in the drive options?) 1452 + QEMU_PROG: -global floppy.drive=... conflicts with drive=floppy0 1535 1453 1536 1454 Testing: -device floppy,drive=floppy0 1537 1455 QEMU_PROG: -device floppy,drive=floppy0: Property 'floppy.drive' can't find value 'floppy0'