piix: fix up/down races
PATCH v4 1/1 piix: fix up/down races
piix acpi interface suffers from the following 2 issues:
1.
- delete device a
- quickly add device b in another slot
if we do this before guest reads the down register, the down event is discarded and device will never be deleted.
2.
- delete device a
- quickly reset before guest can respond
interrupt is reset and guest will never eject the device.
To fix this, we implement three changes:
1. Do not clear up/down registers on each hotplug event. this ensures we don't lose events.
2. Make existing up/down registers write 1 to clear; bios will now write back to these the value it read.
3. on reset, remove all devices which have DOWN bit set
For compatibility with old guests, we also clear
the DOWN bit on write to EJ0 for a device.
This patch also extends the documentation for the
ACPI interface, to make the semantics explicit.
Compatibility notes: migrating guests across qemu versions can cause bios from one qemu realease running on another qemu release. The following documents the behaviour in this case:
A. new bios running on old qemu
A bios implementing the change mentioned above will if running on an old qemu introduce a race: the registers were writeable there, so if a register changes between read and write, we'll clobber the new bits losing events. As that version tends to lose events anyway, and as the better than complicating the interface. If someone cares enough, the fix can go on the stable branch.
B. old bios running on new qemu
Down bits will get cleared on eject because of 3 above.
Up bits only get cleared on reset.
This will cause unnecessary notifications and bus rescans, but they are harmless.
---
Changes from v3:
- Documentation/comment tweaks suggested by Alex and Igor
- assert that DOWN is clear before adding a device Changes from v2:
- Use existing register instead of adding a new one, and update documentation
Changes from v1:
- tweaked a comment about clearing down register on reset
- documentation update
docs/specs/acpi_pci_hotplug.txt | 60 ++++++++++++++++++++++++++++++++----- hw/acpi_piix4.c | 63 +++++++++++++++++++++++++++++---------- 2 files changed, 99 insertions(+), 24 deletions(-)
docs/specs/acpi_pci_hotplug.txt +52 -8
@@ -7,31 +7,75 @@ describes the interface between QEMU and the ACPI BIOS. ACPI GPE block (IO ports 0xafe0-0xafe3, byte access): ----------------------------------------- -Generic ACPI GPE block. Bit 1 (GPE.1) used to notify PCI hotplug/eject +Generic ACPI GPE block. Bit 1 (GPE.1) is used to notify PCI hotplug/hotunplug event to ACPI BIOS, via SCI interrupt. -PCI slot injection notification pending (IO port 0xae00-0xae03, 4-byte access): +Semantics: this event occurs each time a bit in either Pending PCI slot +injection notification or Pending PCI slot removal notification registers +changes status from 0 to 1. + +Pending PCI slot injection notification (IO port 0xae00-0xae03, 4-byte access): --------------------------------------------------------------- -Slot injection notification pending. One bit per slot. +Slot injection notification is pending. One bit per slot. +When written by Guest, this register implements write one to clear behaviour. Read by ACPI BIOS GPE.1 handler to notify OS of injection events. +Written to by ACPI BIOS GPE.1 handler after reading +and before notifying OS of injection events. + +Semantics: after a slot is populated by hotplug, it is immediately enabled +and a bit in this register is set. +Writes into this register are used to acknowledge the injection notification, +clearing the injection notification events in specified slots, +and do not affect the slot status. +Reset value: 0 -PCI slot removal notification (IO port 0xae04-0xae07, 4-byte access): +Pending PCI slot removal notification (IO port 0xae04-0xae07, 4-byte access): ----------------------------------------------------- -Slot removal notification pending. One bit per slot. +Slot removal notification is pending. One bit per slot. +When written by Guest, this register implements write one to clear behaviour: Read by ACPI BIOS GPE.1 handler to notify OS of removal events. +Written to by ACPI BIOS GPE.1 handler after reading +and before notifying OS of removal events. + +Note: if both slot removal and slot injection notification have a specific bit +set, ACPI BIOS notifies OS of injection event followed by removal event. + +Semantics: upon hotunplug request, a bit in this register is set +and the OSPM is notified about hotunplug request, but a slot remains enabled +until eject. +Writes into this register are used to acknowledge the hotunplug request, +clearing the removal notification events in specified slots, +and do not affect the slot status. +Reset value: 0 + PCI device eject (IO port 0xae08-0xae0b, 4-byte access): ---------------------------------------- Used by ACPI BIOS _EJ0 method to request device removal. One bit per slot. -Reads return 0. +Guests should not read this register. In practice reads return 0. +guests should write values with exactly one bit set, selecting +the slot to eject. +In practice all bits except the lowest bit that is set are discarded. Also in +practice writing the value 0 into this register has no effect. + +Semantics: selected hotunpluggable slot is disabled and powered off. +Has no effect on non-hotunpluggable slots. + +For compatibility with old BIOS, writes to this register +clear bits in pending slot injection notification register. PCI removability status (IO port 0xae0c-0xae0f, 4-byte access): ----------------------------------------------- -Used by ACPI BIOS _RMV method to indicate removability status to OS. One -bit per slot. +Used by ACPI BIOS _RMV method to detect removability status +and report to OS. One bit per slot. +Guests should not write this register, in practice the value +written is discarded. + +Semantics: selected slots support hotplug. Contents of this register +do not change while guest is running.
hw/acpi_piix4.c +47 -16
116 lines not on this page · raw message
Signature · 1 line
1.7.9.111.gf3fb0