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

vmgenid: replace x-write-pointer-available hack

This compat property sole function is to prevent the device from being
instantiated. Instead of requiring an extra compat property, check if
fw_cfg has DMA enabled.

fw_cfg is a built-in device that is initialized very early by the
machine init code. We have at least one other device that also
assumes fw_cfg_find() can be safely used on realize: pvpanic.

This has the additional benefit of handling other cases properly, like:

$ qemu-system-x86_64 -device vmgenid -machine none
qemu-system-x86_64: -device vmgenid: vmgenid requires DMA write support in fw_cfg, which this machine type does not provide
$ qemu-system-x86_64 -device vmgenid -machine pc-i440fx-2.9 -global fw_cfg.dma_enabled=off
qemu-system-x86_64: -device vmgenid: vmgenid requires DMA write support in fw_cfg, which this machine type does not provide
$ qemu-system-x86_64 -device vmgenid -machine pc-i440fx-2.6 -global fw_cfg.dma_enabled=on
[boots normally]

Suggested-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Ben Warren <ben@skyportsystems.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

authored by

Marc-André Lureau and committed by
Michael S. Tsirkin
c8389550 672339f7

+13 -13
+10
hw/acpi/bios-linker-loader.c
··· 169 169 } 170 170 171 171 /* 172 + * board code must realize fw_cfg first, as a fixed device, before 173 + * another device realize function call bios_linker_loader_can_write_pointer() 174 + */ 175 + bool bios_linker_loader_can_write_pointer(void) 176 + { 177 + FWCfgState *fw_cfg = fw_cfg_find(); 178 + return fw_cfg && fw_cfg_dma_enabled(fw_cfg); 179 + } 180 + 181 + /* 172 182 * bios_linker_loader_alloc: ask guest to load file into guest memory. 173 183 * 174 184 * @linker: linker object instance
+1 -8
hw/acpi/vmgenid.c
··· 205 205 memset(vms->vmgenid_addr_le, 0, ARRAY_SIZE(vms->vmgenid_addr_le)); 206 206 } 207 207 208 - static Property vmgenid_properties[] = { 209 - DEFINE_PROP_BOOL("x-write-pointer-available", VmGenIdState, 210 - write_pointer_available, true), 211 - DEFINE_PROP_END_OF_LIST(), 212 - }; 213 - 214 208 static void vmgenid_realize(DeviceState *dev, Error **errp) 215 209 { 216 210 VmGenIdState *vms = VMGENID(dev); 217 211 218 - if (!vms->write_pointer_available) { 212 + if (!bios_linker_loader_can_write_pointer()) { 219 213 error_setg(errp, "%s requires DMA write support in fw_cfg, " 220 214 "which this machine type does not provide", VMGENID_DEVICE); 221 215 return; ··· 239 233 dc->vmsd = &vmstate_vmgenid; 240 234 dc->realize = vmgenid_realize; 241 235 dc->hotpluggable = false; 242 - dc->props = vmgenid_properties; 243 236 set_bit(DEVICE_CATEGORY_MISC, dc->categories); 244 237 245 238 object_class_property_add_str(klass, VMGENID_GUID, NULL,
+2
include/hw/acpi/bios-linker-loader.h
··· 7 7 GArray *file_list; 8 8 } BIOSLinker; 9 9 10 + bool bios_linker_loader_can_write_pointer(void); 11 + 10 12 BIOSLinker *bios_linker_loader_init(void); 11 13 12 14 void bios_linker_loader_alloc(BIOSLinker *linker,
-1
include/hw/acpi/vmgenid.h
··· 21 21 DeviceClass parent_obj; 22 22 QemuUUID guid; /* The 128-bit GUID seen by the guest */ 23 23 uint8_t vmgenid_addr_le[8]; /* Address of the GUID (little-endian) */ 24 - bool write_pointer_available; 25 24 } VmGenIdState; 26 25 27 26 /* returns NULL unless there is exactly one device */
-4
include/hw/compat.h
··· 153 153 .driver = "fw_cfg_io",\ 154 154 .property = "dma_enabled",\ 155 155 .value = "off",\ 156 - },{\ 157 - .driver = "vmgenid",\ 158 - .property = "x-write-pointer-available",\ 159 - .value = "off",\ 160 156 }, 161 157 162 158 #define HW_COMPAT_2_3 \