ACPI type safety cleanup
cover ACPI type safety cleanup
Small cleanup to make the ACPI callback functions harder to misuse.
Eduardo Habkost (2):
acpi: Improve acpi_send_event() type safety
acpi: Decouple ACPI hotplug callbacks from HotplugHandler
include/hw/acpi/acpi_dev_interface.h | 2 +- include/hw/acpi/cpu.h | 5 ++--- include/hw/acpi/cpu_hotplug.h | 2 +- include/hw/acpi/memory_hotplug.h | 4 ++-- include/hw/acpi/pcihp.h | 4 ++-- include/hw/mem/nvdimm.h | 3 ++- hw/acpi/acpi_interface.c | 5 ++--- hw/acpi/cpu.c | 8 ++++---- hw/acpi/cpu_hotplug.c | 4 ++-- hw/acpi/ich9.c | 14 ++++++++------ hw/acpi/memory_hotplug.c | 8 ++++---- hw/acpi/nvdimm.c | 4 ++-- hw/acpi/pcihp.c | 8 ++++---- hw/acpi/piix4.c | 18 ++++++++++-------- hw/acpi/vmgenid.c | 2 +- 15 files changed, 47 insertions(+), 44 deletions(-)
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
PATCH 1/2 acpi: Improve acpi_send_event() type safety
acpi_send_event() requires an object that implements TYPE_ACPI_DEVICE_IF. Indicate that in the function prototype.
--- include/hw/acpi/acpi_dev_interface.h | 2 +- hw/acpi/acpi_interface.c | 5 ++--- hw/acpi/cpu.c | 4 ++-- hw/acpi/cpu_hotplug.c | 2 +- hw/acpi/memory_hotplug.c | 4 ++-- hw/acpi/nvdimm.c | 2 +- hw/acpi/pcihp.c | 4 ++-- hw/acpi/vmgenid.c | 2 +- 8 files changed, 12 insertions(+), 13 deletions(-)
include/hw/acpi/acpi_dev_interface.h +1 -1
@@ -31,7 +31,7 @@ typedef struct AcpiDeviceIf {Object Parent; } AcpiDeviceIf; -void acpi_send_event (DeviceState *dev,AcpiEventStatusBits event); +void acpi_send_event (AcpiDeviceIf *dev,AcpiEventStatusBits event);/** * AcpiDeviceIfClass:
hw/acpi/acpi_interface.c +2 -3
@@ -2,12 +2,11 @@#include "hw/acpi/acpi_dev_interface.h" #include "qemu/module.h" -void acpi_send_event (DeviceState *dev,AcpiEventStatusBits event) +void acpi_send_event (AcpiDeviceIf *dev,AcpiEventStatusBits event) {AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (dev);if (adevc->send_event) { -AcpiDeviceIf *adev =ACPI_DEVICE_IF (dev); - adevc->send_event (adev, event); + adevc->send_event (dev, event); } }
hw/acpi/cpu.c +2 -2
@@ -233,7 +233,7 @@ void acpi_cpu_plug_cb(HotplugHandler *hotplug_dev, cdev->cpu =CPU (dev);if (dev->hotplugged) { cdev->is_inserting = true; -acpi_send_event (DEVICE (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS ); +acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS ); } }
@@ -249,7 +249,7 @@ void acpi_cpu_unplug_request_cb(HotplugHandler *hotplug_dev, } cdev->is_removing = true; -acpi_send_event (DEVICE (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS ); +acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS ); } void acpi_cpu_unplug_cb(CPUHotplugState *cpu_st,
hw/acpi/cpu_hotplug.c +1 -1
@@ -79,7 +79,7 @@ void legacy_acpi_cpu_plug_cb(HotplugHandler *hotplug_dev,if (*errp !=NULL ) {return ; } -acpi_send_event (DEVICE (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS ); +acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS ); } void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
hw/acpi/memory_hotplug.c +2 -2
@@ -280,7 +280,7 @@ void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st, mdev->is_enabled = true;if (dev->hotplugged) { mdev->is_inserting = true; -acpi_send_event (DEVICE (hotplug_dev),ACPI_MEMORY_HOTPLUG_STATUS ); +acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_MEMORY_HOTPLUG_STATUS ); } }
@@ -296,7 +296,7 @@ void acpi_memory_unplug_request_cb(HotplugHandler *hotplug_dev, } mdev->is_removing = true; -acpi_send_event (DEVICE (hotplug_dev),ACPI_MEMORY_HOTPLUG_STATUS ); +acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_MEMORY_HOTPLUG_STATUS ); } void acpi_memory_unplug_cb(MemHotplugState *mem_st,
hw/acpi/nvdimm.c +1 -1
@@ -921,7 +921,7 @@ static const MemoryRegionOps nvdimm_dsm_ops = {void nvdimm_acpi_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev) {if (dev->hotplugged) { -acpi_send_event (DEVICE (hotplug_dev),ACPI_NVDIMM_HOTPLUG_STATUS ); +acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_NVDIMM_HOTPLUG_STATUS ); } }
hw/acpi/pcihp.c +2 -2
@@ -237,7 +237,7 @@ void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s, } s->acpi_pcihp_pci_status[bsel].up |= (1U << slot); -acpi_send_event (DEVICE (hotplug_dev),ACPI_PCI_HOTPLUG_STATUS ); +acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_PCI_HOTPLUG_STATUS ); } void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
@@ -253,7 +253,7 @@ void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s, } s->acpi_pcihp_pci_status[bsel].down |= (1U << slot); -acpi_send_event (DEVICE (hotplug_dev),ACPI_PCI_HOTPLUG_STATUS ); +acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_PCI_HOTPLUG_STATUS ); }static uint64_t pci_read (void *opaque,hwaddr addr,unsigned int size)
hw/acpi/vmgenid.c +1 -1
@@ -158,7 +158,7 @@ static void vmgenid_update_guest(VmGenIdState *vms)cpu_physical_memory_write (vmgenid_addr, guid_le.data,sizeof (guid_le.data));/* Send _GPE.E05 event */ -acpi_send_event (DEVICE (obj),ACPI_VMGENID_CHANGE_STATUS ); +acpi_send_event (ACPI_DEVICE_IF (obj),ACPI_VMGENID_CHANGE_STATUS ); } } }
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
PATCH 2/2 acpi: Decouple ACPI hotplug callbacks from HotplugHandler
In reply to Eduardo HabkostThe ACPI hotplug callbacks get a HotplugHandler object as argument. This has two problems:
1) The functions require a TYPE_ACPI_DEVICE_IF object, but the function prototype doesn't indicate that. It's possible to pass an object that would make the function crash.
2) The function does not require the object to implement TYPE_HOTPLUG_HANDLER at all, but the function prototype imposes that for no reason.
Change the argument type to AcpiDeviceIf instead of HotplugHandler.
--- include/hw/acpi/cpu.h | 5 ++--- include/hw/acpi/cpu_hotplug.h | 2 +- include/hw/acpi/memory_hotplug.h | 4 ++-- include/hw/acpi/pcihp.h | 4 ++-- include/hw/mem/nvdimm.h | 3 ++- hw/acpi/cpu.c | 8 ++++---- hw/acpi/cpu_hotplug.c | 4 ++-- hw/acpi/ich9.c | 14 ++++++++------ hw/acpi/memory_hotplug.c | 8 ++++---- hw/acpi/nvdimm.c | 4 ++-- hw/acpi/pcihp.c | 8 ++++---- hw/acpi/piix4.c | 18 ++++++++++-------- 12 files changed, 43 insertions(+), 39 deletions(-)
include/hw/acpi/cpu.h +2 -3
@@ -15,7 +15,6 @@#include "hw/qdev-core.h" #include "hw/acpi/acpi.h" #include "hw/acpi/aml-build.h" -#include "hw/hotplug.h" typedef struct AcpiCpuStatus { struct CPUState *cpu;
@@ -34,10 +33,10 @@ typedef struct CPUHotplugState {AcpiCpuStatus *devs; } CPUHotplugState; -void acpi_cpu_plug_cb (HotplugHandler *hotplug_dev, +void acpi_cpu_plug_cb (AcpiDeviceIf *acpi_dev,CPUHotplugState *cpu_st,DeviceState *dev,Error **errp); -void acpi_cpu_unplug_request_cb (HotplugHandler *hotplug_dev, +void acpi_cpu_unplug_request_cb (AcpiDeviceIf *acpi_dev,CPUHotplugState *cpu_st,DeviceState *dev,Error **errp);
include/hw/acpi/cpu_hotplug.h +1 -1
@@ -25,7 +25,7 @@ typedef struct AcpiCpuHotplug {uint8_t sts[ACPI_GPE_PROC_LEN ]; } AcpiCpuHotplug; -void legacy_acpi_cpu_plug_cb (HotplugHandler *hotplug_dev, +void legacy_acpi_cpu_plug_cb (AcpiDeviceIf *acpi_dev,AcpiCpuHotplug *g,DeviceState *dev,Error **errp); void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
include/hw/acpi/memory_hotplug.h +2 -2
@@ -31,9 +31,9 @@ typedef struct MemHotplugState {void acpi_memory_hotplug_init (MemoryRegion *as,Object *owner,MemHotplugState *state,uint16_t io_base); -void acpi_memory_plug_cb (HotplugHandler *hotplug_dev,MemHotplugState *mem_st, +void acpi_memory_plug_cb (AcpiDeviceIf *acpi_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp); -void acpi_memory_unplug_request_cb (HotplugHandler *hotplug_dev, +void acpi_memory_unplug_request_cb (AcpiDeviceIf *acpi_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp); void acpi_memory_unplug_cb(MemHotplugState *mem_st,
include/hw/acpi/pcihp.h +2 -2
@@ -56,9 +56,9 @@ typedef struct AcpiPciHpState {void acpi_pcihp_init (Object *owner,AcpiPciHpState *,PCIBus *root,MemoryRegion *address_space_io,bool bridges_enabled); -void acpi_pcihp_device_plug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s, +void acpi_pcihp_device_plug_cb (AcpiDeviceIf *acpi_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp); -void acpi_pcihp_device_unplug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s, +void acpi_pcihp_device_unplug_cb (AcpiDeviceIf *acpi_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp);/* Called on reset */
include/hw/mem/nvdimm.h +2 -1
@@ -25,6 +25,7 @@#include "hw/mem/pc-dimm.h" #include "hw/acpi/bios-linker-loader.h" +#include "hw/acpi/acpi_dev_interface.h" #define NVDIMM_DEBUG 0#define nvdimm_debug (fmt, ...) \
@@ -149,5 +150,5 @@ void nvdimm_build_acpi(GArray *table_offsets, GArray *table_data, BIOSLinker *linker, AcpiNVDIMMState *state, uint32_t ram_slots);void nvdimm_plug (AcpiNVDIMMState *state); -void nvdimm_acpi_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev); +void nvdimm_acpi_plug_cb (AcpiDeviceIf *acpi_dev,DeviceState *dev);#endif
hw/acpi/cpu.c +4 -4
@@ -220,7 +220,7 @@ static AcpiCpuStatus *get_cpu_status(CPUHotplugState *cpu_st, DeviceState *dev)return NULL ; } -void acpi_cpu_plug_cb (HotplugHandler *hotplug_dev, +void acpi_cpu_plug_cb (AcpiDeviceIf *acpi_dev,CPUHotplugState *cpu_st,DeviceState *dev,Error **errp) {AcpiCpuStatus *cdev;
@@ -233,11 +233,11 @@ void acpi_cpu_plug_cb(HotplugHandler *hotplug_dev, cdev->cpu =CPU (dev);if (dev->hotplugged) { cdev->is_inserting = true; -acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS ); +acpi_send_event (acpi_dev,ACPI_CPU_HOTPLUG_STATUS ); } } -void acpi_cpu_unplug_request_cb (HotplugHandler *hotplug_dev, +void acpi_cpu_unplug_request_cb (AcpiDeviceIf *acpi_dev,CPUHotplugState *cpu_st,DeviceState *dev,Error **errp) {
@@ -249,7 +249,7 @@ void acpi_cpu_unplug_request_cb(HotplugHandler *hotplug_dev, } cdev->is_removing = true; -acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS ); +acpi_send_event (acpi_dev,ACPI_CPU_HOTPLUG_STATUS ); } void acpi_cpu_unplug_cb(CPUHotplugState *cpu_st,
hw/acpi/cpu_hotplug.c +2 -2
@@ -72,14 +72,14 @@ static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu, g->sts[cpu_id /8 ] |= (1 << (cpu_id %8 )); } -void legacy_acpi_cpu_plug_cb (HotplugHandler *hotplug_dev, +void legacy_acpi_cpu_plug_cb (AcpiDeviceIf *acpi_dev,AcpiCpuHotplug *g,DeviceState *dev,Error **errp) {acpi_set_cpu_present_bit (g,CPU (dev), errp);if (*errp !=NULL ) {return ; } -acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS ); +acpi_send_event (acpi_dev,ACPI_CPU_HOTPLUG_STATUS ); } void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
hw/acpi/ich9.c +8 -6
@@ -487,20 +487,21 @@ void ich9_pm_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); +AcpiDeviceIf *acpi_dev =ACPI_DEVICE_IF (hotplug_dev);if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {if (object_dynamic_cast (OBJECT (dev),TYPE_NVDIMM )) { -nvdimm_acpi_plug_cb (hotplug_dev, dev); +nvdimm_acpi_plug_cb (acpi_dev, dev); }else { -acpi_memory_plug_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, +acpi_memory_plug_cb (acpi_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); } }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) {if (lpc->pm.cpu_hotplug_legacy) { -legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.gpe_cpu, dev, errp); +legacy_acpi_cpu_plug_cb (acpi_dev, &lpc->pm.gpe_cpu, dev, errp); }else { -acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.cpuhp_state, dev, errp); +acpi_cpu_plug_cb (acpi_dev, &lpc->pm.cpuhp_state, dev, errp); } }else { error_setg(errp, "acpi: device plug request for not supported device"
@@ -512,15 +513,16 @@ void ich9_pm_device_unplug_request_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); +AcpiDeviceIf *acpi_dev =ACPI_DEVICE_IF (hotplug_dev);if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_unplug_request_cb (hotplug_dev, +acpi_memory_unplug_request_cb (acpi_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && !lpc->pm.cpu_hotplug_legacy) { -acpi_cpu_unplug_request_cb (hotplug_dev, &lpc->pm.cpuhp_state, +acpi_cpu_unplug_request_cb (acpi_dev, &lpc->pm.cpuhp_state, dev, errp); }else { error_setg(errp, "acpi: device unplug request for not supported device"
hw/acpi/memory_hotplug.c +4 -4
@@ -261,7 +261,7 @@ acpi_memory_slot_status(MemHotplugState *mem_st,return &mem_st->devs[slot]; } -void acpi_memory_plug_cb (HotplugHandler *hotplug_dev,MemHotplugState *mem_st, +void acpi_memory_plug_cb (AcpiDeviceIf *acpi_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp) {MemStatus *mdev;
@@ -280,11 +280,11 @@ void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st, mdev->is_enabled = true;if (dev->hotplugged) { mdev->is_inserting = true; -acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_MEMORY_HOTPLUG_STATUS ); +acpi_send_event (acpi_dev,ACPI_MEMORY_HOTPLUG_STATUS ); } } -void acpi_memory_unplug_request_cb (HotplugHandler *hotplug_dev, +void acpi_memory_unplug_request_cb (AcpiDeviceIf *acpi_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp) {
@@ -296,7 +296,7 @@ void acpi_memory_unplug_request_cb(HotplugHandler *hotplug_dev, } mdev->is_removing = true; -acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_MEMORY_HOTPLUG_STATUS ); +acpi_send_event (acpi_dev,ACPI_MEMORY_HOTPLUG_STATUS ); } void acpi_memory_unplug_cb(MemHotplugState *mem_st,
hw/acpi/nvdimm.c +2 -2
@@ -918,10 +918,10 @@ static const MemoryRegionOps nvdimm_dsm_ops = { }, }; -void nvdimm_acpi_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev) +void nvdimm_acpi_plug_cb (AcpiDeviceIf *acpi_dev,DeviceState *dev) {if (dev->hotplugged) { -acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_NVDIMM_HOTPLUG_STATUS ); +acpi_send_event (acpi_dev,ACPI_NVDIMM_HOTPLUG_STATUS ); } }
hw/acpi/pcihp.c +4 -4
@@ -217,7 +217,7 @@ void acpi_pcihp_reset(AcpiPciHpState *s)acpi_pcihp_update (s); } -void acpi_pcihp_device_plug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s, +void acpi_pcihp_device_plug_cb (AcpiDeviceIf *acpi_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp) {PCIDevice *pdev =PCI_DEVICE (dev);
@@ -237,10 +237,10 @@ void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s, } s->acpi_pcihp_pci_status[bsel].up |= (1U << slot); -acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_PCI_HOTPLUG_STATUS ); +acpi_send_event (acpi_dev,ACPI_PCI_HOTPLUG_STATUS ); } -void acpi_pcihp_device_unplug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s, +void acpi_pcihp_device_unplug_cb (AcpiDeviceIf *acpi_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp) {PCIDevice *pdev =PCI_DEVICE (dev);
@@ -253,7 +253,7 @@ void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s, } s->acpi_pcihp_pci_status[bsel].down |= (1U << slot); -acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_PCI_HOTPLUG_STATUS ); +acpi_send_event (acpi_dev,ACPI_PCI_HOTPLUG_STATUS ); }static uint64_t pci_read (void *opaque,hwaddr addr,unsigned int size)
hw/acpi/piix4.c +10 -8
@@ -374,22 +374,23 @@ static void piix4_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {PIIX4PMState *s =PIIX4_PM (hotplug_dev); +AcpiDeviceIf *acpi_dev =ACPI_DEVICE_IF (hotplug_dev);if (s->acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {if (object_dynamic_cast (OBJECT (dev),TYPE_NVDIMM )) { -nvdimm_acpi_plug_cb (hotplug_dev, dev); +nvdimm_acpi_plug_cb (acpi_dev, dev); }else { -acpi_memory_plug_cb (hotplug_dev, &s->acpi_memory_hotplug, +acpi_memory_plug_cb (acpi_dev, &s->acpi_memory_hotplug, dev, errp); } }else if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) { -acpi_pcihp_device_plug_cb (hotplug_dev, &s->acpi_pci_hotplug, dev, errp); +acpi_pcihp_device_plug_cb (acpi_dev, &s->acpi_pci_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) {if (s->cpu_hotplug_legacy) { -legacy_acpi_cpu_plug_cb (hotplug_dev, &s->gpe_cpu, dev, errp); +legacy_acpi_cpu_plug_cb (acpi_dev, &s->gpe_cpu, dev, errp); }else { -acpi_cpu_plug_cb (hotplug_dev, &s->cpuhp_state, dev, errp); +acpi_cpu_plug_cb (acpi_dev, &s->cpuhp_state, dev, errp); } }else { error_setg(errp, "acpi: device plug request for not supported device"
@@ -401,17 +402,18 @@ static void piix4_device_unplug_request_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {PIIX4PMState *s =PIIX4_PM (hotplug_dev); +AcpiDeviceIf *acpi_dev =ACPI_DEVICE_IF (hotplug_dev);if (s->acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_unplug_request_cb (hotplug_dev, &s->acpi_memory_hotplug, +acpi_memory_unplug_request_cb (acpi_dev, &s->acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) { -acpi_pcihp_device_unplug_cb (hotplug_dev, &s->acpi_pci_hotplug, dev, +acpi_pcihp_device_unplug_cb (acpi_dev, &s->acpi_pci_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && !s->cpu_hotplug_legacy) { -acpi_cpu_unplug_request_cb (hotplug_dev, &s->cpuhp_state, dev, errp); +acpi_cpu_unplug_request_cb (acpi_dev, &s->cpuhp_state, dev, errp); }else {error_setg (errp,"acpi: device unplug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
Re: [Qemu-devel] [PATCH for-3.1 1/2] acpi: Improve acpi_send_event() type safety
In reply to Eduardo HabkostQuoted 4 lines · On Mon, 23 Jul 2018 16:31:44 -0300 Eduardo Habkost <[email protected]> wrote:
acpi_send_event()requires an object that implementsTYPE_ACPI_DEVICE_IF. Indicate that in the function prototype.Signed-off-by Eduardo Habkost <[email protected]>
It's not like acpi_send_event would ever need access to more than AcpiDeviceIf, so it's fine to make it more strict.
PS:
checkpatch is not happy with this patch
Quoted 148 lines
--- include/hw/acpi/acpi_dev_interface.h | 2 +- hw/acpi/acpi_interface.c | 5 ++--- hw/acpi/cpu.c | 4 ++-- hw/acpi/cpu_hotplug.c | 2 +- hw/acpi/memory_hotplug.c | 4 ++-- hw/acpi/nvdimm.c | 2 +- hw/acpi/pcihp.c | 4 ++-- hw/acpi/vmgenid.c | 2 +- 8 files changed, 12 insertions(+), 13 deletions(-)include/hw/acpi/acpi_dev_interface.h +1
-1@@ -31,7 +31,7 @@ typedef struct AcpiDeviceIf {Object Parent; } AcpiDeviceIf; -void acpi_send_event (DeviceState *dev,AcpiEventStatusBits event); +void acpi_send_event (AcpiDeviceIf *dev,AcpiEventStatusBits event);/** * AcpiDeviceIfClass: hw/acpi/acpi_interface.c +2
-3@@ -2,12 +2,11 @@#include "hw/acpi/acpi_dev_interface.h" #include "qemu/module.h" -void acpi_send_event (DeviceState *dev,AcpiEventStatusBits event) +void acpi_send_event (AcpiDeviceIf *dev,AcpiEventStatusBits event) {AcpiDeviceIfClass *adevc =ACPI_DEVICE_IF_GET_CLASS (dev);if (adevc->send_event) { -AcpiDeviceIf *adev =ACPI_DEVICE_IF (dev); - adevc->send_event (adev, event); + adevc->send_event (dev, event); } }hw/acpi/cpu.c +2
-2@@ -233,7 +233,7 @@ void acpi_cpu_plug_cb(HotplugHandler *hotplug_dev, cdev->cpu =CPU (dev);if (dev->hotplugged) { cdev->is_inserting = true; -acpi_send_event (DEVICE (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS ); +acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS ); } }@@ -249,7 +249,7 @@ void acpi_cpu_unplug_request_cb(HotplugHandler *hotplug_dev, } cdev->is_removing = true; -acpi_send_event (DEVICE (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS ); +acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS ); } void acpi_cpu_unplug_cb(CPUHotplugState *cpu_st,hw/acpi/cpu_hotplug.c +1
-1@@ -79,7 +79,7 @@ void legacy_acpi_cpu_plug_cb(HotplugHandler *hotplug_dev,if (*errp !=NULL ) {return ; } -acpi_send_event (DEVICE (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS ); +acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS ); } void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,hw/acpi/memory_hotplug.c +2
-2@@ -280,7 +280,7 @@ void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st, mdev->is_enabled = true;if (dev->hotplugged) { mdev->is_inserting = true; -acpi_send_event (DEVICE (hotplug_dev),ACPI_MEMORY_HOTPLUG_STATUS ); +acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_MEMORY_HOTPLUG_STATUS ); } }@@ -296,7 +296,7 @@ void acpi_memory_unplug_request_cb(HotplugHandler *hotplug_dev, } mdev->is_removing = true; -acpi_send_event (DEVICE (hotplug_dev),ACPI_MEMORY_HOTPLUG_STATUS ); +acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_MEMORY_HOTPLUG_STATUS ); } void acpi_memory_unplug_cb(MemHotplugState *mem_st,hw/acpi/nvdimm.c +1
-1@@ -921,7 +921,7 @@ static const MemoryRegionOps nvdimm_dsm_ops = {void nvdimm_acpi_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev) {if (dev->hotplugged) { -acpi_send_event (DEVICE (hotplug_dev),ACPI_NVDIMM_HOTPLUG_STATUS ); +acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_NVDIMM_HOTPLUG_STATUS ); } }hw/acpi/pcihp.c +2
-2@@ -237,7 +237,7 @@ void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s, } s->acpi_pcihp_pci_status[bsel].up |= (1U << slot); -acpi_send_event (DEVICE (hotplug_dev),ACPI_PCI_HOTPLUG_STATUS ); +acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_PCI_HOTPLUG_STATUS ); } void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,@@ -253,7 +253,7 @@ void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s, } s->acpi_pcihp_pci_status[bsel].down |= (1U << slot); -acpi_send_event (DEVICE (hotplug_dev),ACPI_PCI_HOTPLUG_STATUS ); +acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_PCI_HOTPLUG_STATUS ); }static uint64_t pci_read (void *opaque,hwaddr addr,unsigned int size)hw/acpi/vmgenid.c +1
-1@@ -158,7 +158,7 @@ static void vmgenid_update_guest(VmGenIdState *vms)cpu_physical_memory_write (vmgenid_addr, guid_le.data,sizeof (guid_le.data));/* Send _GPE.E05 event */ -acpi_send_event (DEVICE (obj),ACPI_VMGENID_CHANGE_STATUS ); +acpi_send_event (ACPI_DEVICE_IF (obj),ACPI_VMGENID_CHANGE_STATUS ); } } }
Re: [Qemu-devel] [PATCH for-3.1 2/2] acpi: Decouple ACPI hotplug callbacks from HotplugHandler
In reply to Eduardo HabkostQuoted 10 lines · On Mon, 23 Jul 2018 16:31:45 -0300 Eduardo Habkost <[email protected]> wrote:
The ACPI hotplug callbacks get a HotplugHandler object as argument. This has two problems:
1) The functions require a
TYPE_ACPI_DEVICE_IFobject, but the function prototype doesn't indicate that. It's possible to pass an object that would make the function crash.
2) The function does not require the object to implementTYPE_HOTPLUG_HANDLERat all, but the function prototype imposes that for no reason.
Quoted 2 lines
Change the argument type to AcpiDeviceIf instead of HotplugHandler.
What is the motivation for this patch,
do you actually get crashes?
Quoted 354 lines
Signed-off-by Eduardo Habkost <[email protected]>--- include/hw/acpi/cpu.h | 5 ++--- include/hw/acpi/cpu_hotplug.h | 2 +- include/hw/acpi/memory_hotplug.h | 4 ++-- include/hw/acpi/pcihp.h | 4 ++-- include/hw/mem/nvdimm.h | 3 ++- hw/acpi/cpu.c | 8 ++++---- hw/acpi/cpu_hotplug.c | 4 ++-- hw/acpi/ich9.c | 14 ++++++++------ hw/acpi/memory_hotplug.c | 8 ++++---- hw/acpi/nvdimm.c | 4 ++-- hw/acpi/pcihp.c | 8 ++++---- hw/acpi/piix4.c | 18 ++++++++++-------- 12 files changed, 43 insertions(+), 39 deletions(-)include/hw/acpi/cpu.h +2
-3@@ -15,7 +15,6 @@#include "hw/qdev-core.h" #include "hw/acpi/acpi.h" #include "hw/acpi/aml-build.h" -#include "hw/hotplug.h" typedef struct AcpiCpuStatus { struct CPUState *cpu;@@ -34,10 +33,10 @@ typedef struct CPUHotplugState {AcpiCpuStatus *devs; } CPUHotplugState; -void acpi_cpu_plug_cb (HotplugHandler *hotplug_dev, +void acpi_cpu_plug_cb (AcpiDeviceIf *acpi_dev,CPUHotplugState *cpu_st,DeviceState *dev,Error **errp); -void acpi_cpu_unplug_request_cb (HotplugHandler *hotplug_dev, +void acpi_cpu_unplug_request_cb (AcpiDeviceIf *acpi_dev,CPUHotplugState *cpu_st,DeviceState *dev,Error **errp);include/hw/acpi/cpu_hotplug.h +1
-1@@ -25,7 +25,7 @@ typedef struct AcpiCpuHotplug {uint8_t sts[ACPI_GPE_PROC_LEN ]; } AcpiCpuHotplug; -void legacy_acpi_cpu_plug_cb (HotplugHandler *hotplug_dev, +void legacy_acpi_cpu_plug_cb (AcpiDeviceIf *acpi_dev,AcpiCpuHotplug *g,DeviceState *dev,Error **errp); void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,include/hw/acpi/memory_hotplug.h +2
-2@@ -31,9 +31,9 @@ typedef struct MemHotplugState {void acpi_memory_hotplug_init (MemoryRegion *as,Object *owner,MemHotplugState *state,uint16_t io_base); -void acpi_memory_plug_cb (HotplugHandler *hotplug_dev,MemHotplugState *mem_st, +void acpi_memory_plug_cb (AcpiDeviceIf *acpi_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp); -void acpi_memory_unplug_request_cb (HotplugHandler *hotplug_dev, +void acpi_memory_unplug_request_cb (AcpiDeviceIf *acpi_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp); void acpi_memory_unplug_cb(MemHotplugState *mem_st,include/hw/acpi/pcihp.h +2
-2@@ -56,9 +56,9 @@ typedef struct AcpiPciHpState {void acpi_pcihp_init (Object *owner,AcpiPciHpState *,PCIBus *root,MemoryRegion *address_space_io,bool bridges_enabled); -void acpi_pcihp_device_plug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s, +void acpi_pcihp_device_plug_cb (AcpiDeviceIf *acpi_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp); -void acpi_pcihp_device_unplug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s, +void acpi_pcihp_device_unplug_cb (AcpiDeviceIf *acpi_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp);/* Called on reset */ include/hw/mem/nvdimm.h +2
-1@@ -25,6 +25,7 @@#include "hw/mem/pc-dimm.h" #include "hw/acpi/bios-linker-loader.h" +#include "hw/acpi/acpi_dev_interface.h" #define NVDIMM_DEBUG 0#define nvdimm_debug (fmt, ...) \@@ -149,5 +150,5 @@ void nvdimm_build_acpi(GArray *table_offsets, GArray *table_data, BIOSLinker *linker, AcpiNVDIMMState *state, uint32_t ram_slots);void nvdimm_plug (AcpiNVDIMMState *state); -void nvdimm_acpi_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev); +void nvdimm_acpi_plug_cb (AcpiDeviceIf *acpi_dev,DeviceState *dev);#endif hw/acpi/cpu.c +4
-4@@ -220,7 +220,7 @@ static AcpiCpuStatus *get_cpu_status(CPUHotplugState *cpu_st, DeviceState *dev)return NULL ; } -void acpi_cpu_plug_cb (HotplugHandler *hotplug_dev, +void acpi_cpu_plug_cb (AcpiDeviceIf *acpi_dev,CPUHotplugState *cpu_st,DeviceState *dev,Error **errp) {AcpiCpuStatus *cdev;@@ -233,11 +233,11 @@ void acpi_cpu_plug_cb(HotplugHandler *hotplug_dev, cdev->cpu =CPU (dev);if (dev->hotplugged) { cdev->is_inserting = true; -acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS ); +acpi_send_event (acpi_dev,ACPI_CPU_HOTPLUG_STATUS ); } } -void acpi_cpu_unplug_request_cb (HotplugHandler *hotplug_dev, +void acpi_cpu_unplug_request_cb (AcpiDeviceIf *acpi_dev,CPUHotplugState *cpu_st,DeviceState *dev,Error **errp) {@@ -249,7 +249,7 @@ void acpi_cpu_unplug_request_cb(HotplugHandler *hotplug_dev, } cdev->is_removing = true; -acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS ); +acpi_send_event (acpi_dev,ACPI_CPU_HOTPLUG_STATUS ); } void acpi_cpu_unplug_cb(CPUHotplugState *cpu_st,hw/acpi/cpu_hotplug.c +2
-2@@ -72,14 +72,14 @@ static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu, g->sts[cpu_id /8 ] |= (1 << (cpu_id %8 )); } -void legacy_acpi_cpu_plug_cb (HotplugHandler *hotplug_dev, +void legacy_acpi_cpu_plug_cb (AcpiDeviceIf *acpi_dev,AcpiCpuHotplug *g,DeviceState *dev,Error **errp) {acpi_set_cpu_present_bit (g,CPU (dev), errp);if (*errp !=NULL ) {return ; } -acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_CPU_HOTPLUG_STATUS ); +acpi_send_event (acpi_dev,ACPI_CPU_HOTPLUG_STATUS ); } void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,hw/acpi/ich9.c +8
-6@@ -487,20 +487,21 @@ void ich9_pm_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); +AcpiDeviceIf *acpi_dev =ACPI_DEVICE_IF (hotplug_dev);if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {if (object_dynamic_cast (OBJECT (dev),TYPE_NVDIMM )) { -nvdimm_acpi_plug_cb (hotplug_dev, dev); +nvdimm_acpi_plug_cb (acpi_dev, dev); }else { -acpi_memory_plug_cb (hotplug_dev, &lpc->pm.acpi_memory_hotplug, +acpi_memory_plug_cb (acpi_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); } }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) {if (lpc->pm.cpu_hotplug_legacy) { -legacy_acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.gpe_cpu, dev, errp); +legacy_acpi_cpu_plug_cb (acpi_dev, &lpc->pm.gpe_cpu, dev, errp); }else { -acpi_cpu_plug_cb (hotplug_dev, &lpc->pm.cpuhp_state, dev, errp); +acpi_cpu_plug_cb (acpi_dev, &lpc->pm.cpuhp_state, dev, errp); } }else { error_setg(errp, "acpi: device plug request for not supported device"@@ -512,15 +513,16 @@ void ich9_pm_device_unplug_request_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {ICH9LPCState *lpc =ICH9_LPC_DEVICE (hotplug_dev); +AcpiDeviceIf *acpi_dev =ACPI_DEVICE_IF (hotplug_dev);if (lpc->pm.acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_unplug_request_cb (hotplug_dev, +acpi_memory_unplug_request_cb (acpi_dev, &lpc->pm.acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && !lpc->pm.cpu_hotplug_legacy) { -acpi_cpu_unplug_request_cb (hotplug_dev, &lpc->pm.cpuhp_state, +acpi_cpu_unplug_request_cb (acpi_dev, &lpc->pm.cpuhp_state, dev, errp); }else { error_setg(errp, "acpi: device unplug request for not supported device"hw/acpi/memory_hotplug.c +4
-4@@ -261,7 +261,7 @@ acpi_memory_slot_status(MemHotplugState *mem_st,return &mem_st->devs[slot]; } -void acpi_memory_plug_cb (HotplugHandler *hotplug_dev,MemHotplugState *mem_st, +void acpi_memory_plug_cb (AcpiDeviceIf *acpi_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp) {MemStatus *mdev;@@ -280,11 +280,11 @@ void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st, mdev->is_enabled = true;if (dev->hotplugged) { mdev->is_inserting = true; -acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_MEMORY_HOTPLUG_STATUS ); +acpi_send_event (acpi_dev,ACPI_MEMORY_HOTPLUG_STATUS ); } } -void acpi_memory_unplug_request_cb (HotplugHandler *hotplug_dev, +void acpi_memory_unplug_request_cb (AcpiDeviceIf *acpi_dev,MemHotplugState *mem_st,DeviceState *dev,Error **errp) {@@ -296,7 +296,7 @@ void acpi_memory_unplug_request_cb(HotplugHandler *hotplug_dev, } mdev->is_removing = true; -acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_MEMORY_HOTPLUG_STATUS ); +acpi_send_event (acpi_dev,ACPI_MEMORY_HOTPLUG_STATUS ); } void acpi_memory_unplug_cb(MemHotplugState *mem_st,hw/acpi/nvdimm.c +2
-2@@ -918,10 +918,10 @@ static const MemoryRegionOps nvdimm_dsm_ops = { }, }; -void nvdimm_acpi_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev) +void nvdimm_acpi_plug_cb (AcpiDeviceIf *acpi_dev,DeviceState *dev) {if (dev->hotplugged) { -acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_NVDIMM_HOTPLUG_STATUS ); +acpi_send_event (acpi_dev,ACPI_NVDIMM_HOTPLUG_STATUS ); } }hw/acpi/pcihp.c +4
-4@@ -217,7 +217,7 @@ void acpi_pcihp_reset(AcpiPciHpState *s)acpi_pcihp_update (s); } -void acpi_pcihp_device_plug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s, +void acpi_pcihp_device_plug_cb (AcpiDeviceIf *acpi_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp) {PCIDevice *pdev =PCI_DEVICE (dev);@@ -237,10 +237,10 @@ void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s, } s->acpi_pcihp_pci_status[bsel].up |= (1U << slot); -acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_PCI_HOTPLUG_STATUS ); +acpi_send_event (acpi_dev,ACPI_PCI_HOTPLUG_STATUS ); } -void acpi_pcihp_device_unplug_cb (HotplugHandler *hotplug_dev,AcpiPciHpState *s, +void acpi_pcihp_device_unplug_cb (AcpiDeviceIf *acpi_dev,AcpiPciHpState *s,DeviceState *dev,Error **errp) {PCIDevice *pdev =PCI_DEVICE (dev);@@ -253,7 +253,7 @@ void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s, } s->acpi_pcihp_pci_status[bsel].down |= (1U << slot); -acpi_send_event (ACPI_DEVICE_IF (hotplug_dev),ACPI_PCI_HOTPLUG_STATUS ); +acpi_send_event (acpi_dev,ACPI_PCI_HOTPLUG_STATUS ); }static uint64_t pci_read (void *opaque,hwaddr addr,unsigned int size)hw/acpi/piix4.c +10
-8@@ -374,22 +374,23 @@ static void piix4_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {PIIX4PMState *s =PIIX4_PM (hotplug_dev); +AcpiDeviceIf *acpi_dev =ACPI_DEVICE_IF (hotplug_dev);if (s->acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {if (object_dynamic_cast (OBJECT (dev),TYPE_NVDIMM )) { -nvdimm_acpi_plug_cb (hotplug_dev, dev); +nvdimm_acpi_plug_cb (acpi_dev, dev); }else { -acpi_memory_plug_cb (hotplug_dev, &s->acpi_memory_hotplug, +acpi_memory_plug_cb (acpi_dev, &s->acpi_memory_hotplug, dev, errp); } }else if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) { -acpi_pcihp_device_plug_cb (hotplug_dev, &s->acpi_pci_hotplug, dev, errp); +acpi_pcihp_device_plug_cb (acpi_dev, &s->acpi_pci_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) {if (s->cpu_hotplug_legacy) { -legacy_acpi_cpu_plug_cb (hotplug_dev, &s->gpe_cpu, dev, errp); +legacy_acpi_cpu_plug_cb (acpi_dev, &s->gpe_cpu, dev, errp); }else { -acpi_cpu_plug_cb (hotplug_dev, &s->cpuhp_state, dev, errp); +acpi_cpu_plug_cb (acpi_dev, &s->cpuhp_state, dev, errp); } }else { error_setg(errp, "acpi: device plug request for not supported device"@@ -401,17 +402,18 @@ static void piix4_device_unplug_request_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {PIIX4PMState *s =PIIX4_PM (hotplug_dev); +AcpiDeviceIf *acpi_dev =ACPI_DEVICE_IF (hotplug_dev);if (s->acpi_memory_hotplug.is_enabled &&object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -acpi_memory_unplug_request_cb (hotplug_dev, &s->acpi_memory_hotplug, +acpi_memory_unplug_request_cb (acpi_dev, &s->acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) { -acpi_pcihp_device_unplug_cb (hotplug_dev, &s->acpi_pci_hotplug, dev, +acpi_pcihp_device_unplug_cb (acpi_dev, &s->acpi_pci_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && !s->cpu_hotplug_legacy) { -acpi_cpu_unplug_request_cb (hotplug_dev, &s->cpuhp_state, dev, errp); +acpi_cpu_unplug_request_cb (acpi_dev, &s->cpuhp_state, dev, errp); }else {error_setg (errp,"acpi: device unplug request for not supported device" " type: %s" ,object_get_typename (OBJECT (dev)));
Re: [Qemu-devel] [PATCH for-3.1 2/2] acpi: Decouple ACPI hotplug callbacks from HotplugHandler
Quoted 13 lines · Igor Mammedov
Quoted 10 lines · On Mon, 23 Jul 2018 16:31:45 -0300 Eduardo Habkost <[email protected]> wrote:
The ACPI hotplug callbacks get a HotplugHandler object as argument. This has two problems:
1) The functions require a
TYPE_ACPI_DEVICE_IFobject, but the function prototype doesn't indicate that. It's possible to pass an object that would make the function crash.
2) The function does not require the object to implementTYPE_HOTPLUG_HANDLERat all, but the function prototype imposes that for no reason.
Quoted 4 lines
Quoted 2 lines
Change the argument type to AcpiDeviceIf instead of HotplugHandler.
What is the motivation for this patch,
do you actually get crashes?
I didn't get crashes, but the idea for the change came when Michael asked me how to get the HotplugHandler object. I was going to suggest current_machine (which is also a hotplug handler), when I noticed he actually needed an AcpiDeviceIf object.
The main motivation, however, is to simply make the function prototypes make sense. Is there a single reason to make the ACPI functions get a HotplugHandler argument instead of AcpiDeviceIf?
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH for-3.1 2/2] acpi: Decouple ACPI hotplug callbacks from HotplugHandler
Quoted 25 lines · On Tue, 24 Jul 2018 09:39:16 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 13 lines · Igor Mammedov
Quoted 10 lines · On Mon, 23 Jul 2018 16:31:45 -0300 Eduardo Habkost <[email protected]> wrote:
The ACPI hotplug callbacks get a HotplugHandler object as argument. This has two problems:
1) The functions require a
TYPE_ACPI_DEVICE_IFobject, but the function prototype doesn't indicate that. It's possible to pass an object that would make the function crash.
2) The function does not require the object to implementTYPE_HOTPLUG_HANDLERat all, but the function prototype imposes that for no reason.Quoted 4 lines
Quoted 2 lines
Change the argument type to AcpiDeviceIf instead of HotplugHandler.
What is the motivation for this patch,
do you actually get crashes?I didn't get crashes, but the idea for the change came when Michael asked me how to get the HotplugHandler object. I was going to suggest
current_machine(which is also a hotplug handler), when I noticed he actually needed an AcpiDeviceIf object.
Quoted 3 lines
The main motivation, however, is to simply make the function prototypes make sense. Is there a single reason to make the ACPI functions get a HotplugHandler argument instead of AcpiDeviceIf?
I'd rather to keep current *_cb() functions as is,
as we might actually need access to hotplug handler there and in that case keeping more generic hotplug handler would be better and it also sort of documents better what is being passed in.
Also we won't have to rewrite it back from AcpiDeviceIf to HotplugHandler again if it's needed.
Re: [Qemu-devel] [PATCH for-3.1 2/2] acpi: Decouple ACPI hotplug callbacks from HotplugHandler
Quoted 28 lines · Igor Mammedov
Quoted 25 lines · On Tue, 24 Jul 2018 09:39:16 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 13 lines · Igor Mammedov
Quoted 10 lines · On Mon, 23 Jul 2018 16:31:45 -0300 Eduardo Habkost <[email protected]> wrote:
The ACPI hotplug callbacks get a HotplugHandler object as argument. This has two problems:
1) The functions require a
TYPE_ACPI_DEVICE_IFobject, but the function prototype doesn't indicate that. It's possible to pass an object that would make the function crash.
2) The function does not require the object to implementTYPE_HOTPLUG_HANDLERat all, but the function prototype imposes that for no reason.Quoted 4 lines
Quoted 2 lines
Change the argument type to AcpiDeviceIf instead of HotplugHandler.
What is the motivation for this patch,
do you actually get crashes?I didn't get crashes, but the idea for the change came when Michael asked me how to get the HotplugHandler object. I was going to suggest
current_machine(which is also a hotplug handler), when I noticed he actually needed an AcpiDeviceIf object.
Quoted 7 lines
Quoted 3 lines
The main motivation, however, is to simply make the function prototypes make sense. Is there a single reason to make the ACPI functions get a HotplugHandler argument instead of AcpiDeviceIf?
I'd rather to keep current
*_cb()functions as is,
as we might actually need access to hotplug handler there and in that case keeping more generic hotplug handler would be better and it also sort of documents better what is being passed in.
I think it doesn't document what is being passed in at all. The function looks like it requires only a HotplugHandler object, but it actually requires an AcpiDeviceIf object.
Quoted 4 lines
Also we won't have to rewrite it back from AcpiDeviceIf to HotplugHandler again if it's needed.
My main problem is: today there's a hard requirement that HotplugHandler and AcpiDeviceIf must be the same object, but it's not documented anywhere.
The proposal in this patch is to remove that requirement, and make the callbacks just require an AcpiDeviceIf object.
If you plan to keep that requirement, that may be OK, but the requirement needs to be documented somehow. How do you think the requirement can be enforced and/or documented?
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH for-3.1 2/2] acpi: Decouple ACPI hotplug callbacks from HotplugHandler
In reply to Igor MammedovQuoted 31 lines · Igor Mammedov
Quoted 25 lines · On Tue, 24 Jul 2018 09:39:16 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 13 lines · Igor Mammedov
Quoted 10 lines · On Mon, 23 Jul 2018 16:31:45 -0300 Eduardo Habkost <[email protected]> wrote:
The ACPI hotplug callbacks get a HotplugHandler object as argument. This has two problems:
1) The functions require a
TYPE_ACPI_DEVICE_IFobject, but the function prototype doesn't indicate that. It's possible to pass an object that would make the function crash.
2) The function does not require the object to implementTYPE_HOTPLUG_HANDLERat all, but the function prototype imposes that for no reason.Quoted 4 lines
Quoted 2 lines
Change the argument type to AcpiDeviceIf instead of HotplugHandler.
What is the motivation for this patch,
do you actually get crashes?I didn't get crashes, but the idea for the change came when Michael asked me how to get the HotplugHandler object. I was going to suggest
current_machine(which is also a hotplug handler), when I noticed he actually needed an AcpiDeviceIf object.Quoted 3 lines
The main motivation, however, is to simply make the function prototypes make sense. Is there a single reason to make the ACPI functions get a HotplugHandler argument instead of AcpiDeviceIf?
Quoted 7 lines
I'd rather to keep current
*_cb()functions as is,
as we might actually need access to hotplug handler there and in that case keeping more generic hotplug handler would be better and it also sort of documents better what is being passed in.Also we won't have to rewrite it back from AcpiDeviceIf to HotplugHandler again if it's needed.
Personally I think type-safety is important, changing APIs isn't such a big deal. So I'd rather take Eduardo's patch unless the patches that would need to change it back are just round the corner. what's the status there?
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH for-3.1 2/2] acpi: Decouple ACPI hotplug callbacks from HotplugHandler
Quoted 37 lines · On Tue, 24 Jul 2018 21:14:48 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 36 lines · Igor Mammedov
Quoted 25 lines · On Tue, 24 Jul 2018 09:39:16 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 13 lines · Igor Mammedov
Quoted 10 lines · On Mon, 23 Jul 2018 16:31:45 -0300 Eduardo Habkost <[email protected]> wrote:
The ACPI hotplug callbacks get a HotplugHandler object as argument. This has two problems:
1) The functions require a
TYPE_ACPI_DEVICE_IFobject, but the function prototype doesn't indicate that. It's possible to pass an object that would make the function crash.
2) The function does not require the object to implementTYPE_HOTPLUG_HANDLERat all, but the function prototype imposes that for no reason.Quoted 4 lines
Quoted 2 lines
Change the argument type to AcpiDeviceIf instead of HotplugHandler.
What is the motivation for this patch,
do you actually get crashes?I didn't get crashes, but the idea for the change came when Michael asked me how to get the HotplugHandler object. I was going to suggest
current_machine(which is also a hotplug handler), when I noticed he actually needed an AcpiDeviceIf object.Quoted 3 lines
The main motivation, however, is to simply make the function prototypes make sense. Is there a single reason to make the ACPI functions get a HotplugHandler argument instead of AcpiDeviceIf?
I'd rather to keep current
*_cb()functions as is,
as we might actually need access to hotplug handler there and in that case keeping more generic hotplug handler would be better and it also sort of documents better what is being passed in.
Quoted 7 lines
Quoted 2 lines
Also we won't have to rewrite it back from AcpiDeviceIf to HotplugHandler again if it's needed.
Personally I think type-safety is important, changing APIs isn't such a big deal. So I'd rather take Eduardo's patch unless the patches that would need to change it back are just round the corner. what's the status there?
I don't have any patches for this part nor any plan to work on it. Ok, let's go ahead with Eduardo's patches. We can always change it back if need arises.
Re: [Qemu-devel] [PATCH for-3.1 2/2] acpi: Decouple ACPI hotplug callbacks from HotplugHandler
Quoted 43 lines · Igor Mammedov
Quoted 40 lines · On Tue, 24 Jul 2018 21:14:48 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 38 lines · Igor Mammedov
Quoted 25 lines · On Tue, 24 Jul 2018 09:39:16 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 13 lines · Igor Mammedov
Quoted 10 lines · On Mon, 23 Jul 2018 16:31:45 -0300 Eduardo Habkost <[email protected]> wrote:
The ACPI hotplug callbacks get a HotplugHandler object as argument. This has two problems:
1) The functions require a
TYPE_ACPI_DEVICE_IFobject, but the function prototype doesn't indicate that. It's possible to pass an object that would make the function crash.
2) The function does not require the object to implementTYPE_HOTPLUG_HANDLERat all, but the function prototype imposes that for no reason.Quoted 4 lines
Quoted 2 lines
Change the argument type to AcpiDeviceIf instead of HotplugHandler.
What is the motivation for this patch,
do you actually get crashes?I didn't get crashes, but the idea for the change came when Michael asked me how to get the HotplugHandler object. I was going to suggest
current_machine(which is also a hotplug handler), when I noticed he actually needed an AcpiDeviceIf object.Quoted 3 lines
The main motivation, however, is to simply make the function prototypes make sense. Is there a single reason to make the ACPI functions get a HotplugHandler argument instead of AcpiDeviceIf?
I'd rather to keep current
*_cb()functions as is,
as we might actually need access to hotplug handler there and in that case keeping more generic hotplug handler would be better and it also sort of documents better what is being passed in.Also we won't have to rewrite it back from AcpiDeviceIf to HotplugHandler again if it's needed.
Quoted 7 lines
Quoted 4 lines
Personally I think type-safety is important, changing APIs isn't such a big deal. So I'd rather take Eduardo's patch unless the patches that would need to change it back are just round the corner. what's the status there?
I don't have any patches for this part nor any plan to work on it. Ok, let's go ahead with Eduardo's patches. We can always change it back if need arises.
OK - it's for-3.1 anyway, Eduardo pls remember to repost after the release, if that's still the case I'll merge.
Signature · 1 line
MST