On 12/15/2021 1:05 AM, Gerd Hoffmann wrote:
On Tue, Dec 14, 2021 at 09:53:12PM +0000, Annie Li wrote:
After the PCIe device is hot-plugged, the device's power state is
initialized as ON. However, the device isn't powered on yet, i.e.
the PCI_EXP_SYSCTL_PCC bit isn't set to PCI_EXP_SLTCTL_PWR_ON.
Later on, its power state will set back to OFF due to the non
PCI_EXP_SLTCTL_PWR_ON state. The device is invisible until
PCI_EXP_SLTCTL_PWR_ON is set.
This may be appropriate for general PCIe hot-plug cases. However,
if the device is hot-plugged when the VM is in VM_STATE_PRELAUNCH
state, especially the system disk device, the firmware will fail
to find the system disk. As a result, the guest fails to boot.
Maybe we should just not set DeviceState->hotplugged = true for devices
added in VM_STATE_PRELAUNCH? It's not actual hotplug (i.e. device added
while the system is running) after all ...
Simply not setting "DeviceState->hotplugged" doesn't work. Devices
created in
PHASE_MACHINE_READY phase are treated as hot-plugged devices. So I just
tried
following change for the quick test, the device is still invisible to
the firmware with
this change.
static void device_initfn(Object *obj)
{
...snip...
- if (phase_check(PHASE_MACHINE_READY)) {
+ if (phase_check(PHASE_MACHINE_READY) &&
!runstate_check(RUN_STATE_PRELAUNCH)) {
dev->hotplugged = 1;
qdev_hot_added = true;
}
...snip...
}
Thanks
Annie
There are lots of places checking DeviceState->hotplugged, and I suspect
we have similar issues elsewhere.
take care,
Gerd