pcie: Add hotplug detect state register to w1cmask
PATCH 1/1 pcie: Add hotplug detect state register to w1cmask
When trying to migrate a machine type pc-q35-6.0 or lower, with this cmdline options:
-device driver=pcie-root-port,port=18,chassis=19,id=pcie-root-port18,bus=pcie.0,addr=0x12 \
-device driver=nec-usb-xhci,p2=4,p3=4,id=nex-usb-xhci0,bus=pcie-root-port18,addr=0x12.0x1
the following bug happens after all ram pages were sent:
qemu-kvm: get_pci_config_device: Bad config data: i=0x6e read: 0 device: 40 cmask: ff wmask: 0 w1cmask:19
qemu-kvm: Failed to load PCIDevice:config
qemu-kvm: Failed to load pcie-root-port:parent_obj.parent_obj.parent_obj
qemu-kvm: error while loading state for instance 0x0 of device '0000:00:12.0/pcie-root-port'
qemu-kvm: load of migration failed: Invalid argument
This happens on pc-q35-6.0 or lower because of:
{ "ICH9-LPC", ACPI_PM_PROP_ACPI_PCIHP_BRIDGE, "off" }
In this scenario, hotplug_handler_plug() calls pcie_cap_slot_plug_cb(), which sets the bus dev->config byte 0x6e with bit PCI_EXP_SLTSTA_PDS to signal PCI hotplug for the guest. After a while the guest will deal with this hotplug and qemu will clear the above bit.
Then, during migration, get_pci_config_device() will compare the configs of both the freshly created device and the one that is being received via migration, which will differ due to the PCI_EXP_SLTSTA_PDS bit and cause the bug to reproduce.
To avoid this fake incompatibility, there are two fields in PCIDevice that can help:
.wmask: Used to implement R/W bytes, and .w1cmask: Used to implement RW1C(Write 1 to Clear) bytes
According to pcie_cap_slot_init() the slot status register (PCI_EXP_SLTSTA), in which PCI_EXP_SLTSTA_PDS is a flag, seems to fall under w1cmask field, with makes sense due to the way signaling the hotplug works.
So, add PCI_EXP_SLTSTA_PDS bit to w1cmask, so the fake incompatibility on get_pci_config_device() does not abort the migration.
--- hw/pci/pcie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci/pcie.c +1 -1
@@ -657,7 +657,7 @@ void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s) PCI_EXP_SLTCTL_EIC);pci_word_test_and_set_mask (dev->w1cmask + pos +PCI_EXP_SLTSTA , -PCI_EXP_HP_EV_SUPPORTED ); +PCI_EXP_HP_EV_SUPPORTED |PCI_EXP_SLTSTA_PDS ); dev->exp.hpev_notified = false;
Signature · 1 line
2.41.0
Hi, Leo,
Thanks for figuring this out. Let me copy a few more potential reviewers from commit 17858a1695 ("hw/acpi/ich9: Set ACPI PCI hot-plug as default on Q35").
Quoted 27 lines · Leonardo Bras
When trying to migrate a machine type pc-q35-6.0 or lower, with this cmdline options:
(quoted diff) +0
-2-device driver=pcie-root-port,port=18,chassis=19,id=pcie-root-port18,bus=pcie.0,addr=0x12 \ -device driver=nec-usb-xhci,p2=4,p3=4,id=nex-usb-xhci0,bus=pcie-root-port18,addr=0x12.0x1the following bug happens after all ram pages were sent:
qemu-kvm:
get_pci_config_device: Bad config data: i=0x6e read: 0 device: 40 cmask: ff wmask: 0 w1cmask:19
qemu-kvm: Failed to load PCIDevice:config
qemu-kvm: Failed to load pcie-root-port:parent_obj.parent_obj.parent_obj
qemu-kvm: error while loading state for instance0x0of device '0000:00:12.0/pcie-root-port'
qemu-kvm: load of migration failed: Invalid argumentThis happens on pc-q35-6.0 or lower because of:
{ "ICH9-LPC",ACPI_PM_PROP_ACPI_PCIHP_BRIDGE, "off" }In this scenario,
hotplug_handler_plug()callspcie_cap_slot_plug_cb(), which sets the busdev->configbyte0x6ewith bitPCI_EXP_SLTSTA_PDSto signal PCI hotplug for the guest. After a while the guest will deal with this hotplug and qemu will clear the above bit.Then, during migration,
get_pci_config_device()will compare the configs of both the freshly created device and the one that is being received via migration, which will differ due to thePCI_EXP_SLTSTA_PDSbit and cause the bug to reproduce.
Quoted 5 lines
To avoid this fake incompatibility, there are two fields in PCIDevice that can help:
.wmask: Used to implement R/W bytes, and .w1cmask: Used to implement RW1C(Write 1 to Clear) bytes
Is there one more option to clear the bit in cmask?
IIUC w1cmask means the guest can now write to this bit, but afaiu from the pcie spec it's RO.
Quoted 11 lines
According to
pcie_cap_slot_init()the slot status register (PCI_EXP_SLTSTA), in whichPCI_EXP_SLTSTA_PDSis a flag, seems to fall under w1cmask field, with makes sense due to the way signaling the hotplug works.So, add
PCI_EXP_SLTSTA_PDSbit to w1cmask, so the fake incompatibility onget_pci_config_device()does not abort the migration.Signed-off-by Leonardo Bras <[email protected]>
Do we need a Fixes: and also the need to copy stable?
Quoted 20 lines
--- hw/pci/pcie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/pci/pcie.c +1
-1@@ -657,7 +657,7 @@ void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s) PCI_EXP_SLTCTL_EIC);pci_word_test_and_set_mask (dev->w1cmask + pos +PCI_EXP_SLTSTA , -PCI_EXP_HP_EV_SUPPORTED ); +PCI_EXP_HP_EV_SUPPORTED |PCI_EXP_SLTSTA_PDS ); dev->exp.hpev_notified = false;Signature · 1 line
2.41.0
Signature · 1 line
Peter Xu
Quoted 21 lines · Peter Xu
Hi, Leo,
Thanks for figuring this out. Let me copy a few more potential reviewers from commit
17858a1695("hw/acpi/ich9: Set ACPI PCI hot-plug as default on Q35").Quoted 14 lines · Leonardo Bras
When trying to migrate a machine type pc-q35-6.0 or lower, with this cmdline options:
(quoted diff) +0
-2-device driver=pcie-root-port,port=18,chassis=19,id=pcie-root-port18,bus=pcie.0,addr=0x12 \ -device driver=nec-usb-xhci,p2=4,p3=4,id=nex-usb-xhci0,bus=pcie-root-port18,addr=0x12.0x1the following bug happens after all ram pages were sent:
qemu-kvm:
get_pci_config_device: Bad config data: i=0x6e read: 0 device: 40 cmask: ff wmask: 0 w1cmask:19
qemu-kvm: Failed to load PCIDevice:config
qemu-kvm: Failed to load pcie-root-port:parent_obj.parent_obj.parent_obj
qemu-kvm: error while loading state for instance0x0of device '0000:00:12.0/pcie-root-port'
qemu-kvm: load of migration failed: Invalid argument
Quoted 7 lines
Quoted 7 lines
This happens on pc-q35-6.0 or lower because of:
{ "ICH9-LPC",ACPI_PM_PROP_ACPI_PCIHP_BRIDGE, "off" }In this scenario,
hotplug_handler_plug()callspcie_cap_slot_plug_cb(), which sets the busdev->configbyte0x6ewith bitPCI_EXP_SLTSTA_PDSto signal PCI hotplug for the guest. After a while the guest will deal with this hotplug and qemu will clear the above bit.
Presence Detect State – This bit indicates the presence of an adapter in the slot, reflected by the logical “OR” of the Physical Layer in-band presence detect mechanism and, if present, any out-of-band presence detect mechanism defined for the slot’s corresponding form factor. Note that the in-band presence detect mechanism requires that power be applied to an adapter for its presence to be detected. Consequently, form factors that require a power controller for hot-plug must implement a physical pin presence detect mechanism.
RO
Defined encodings are:
0b Slot Empty
1b Card Present in slot
This bit must be implemented on all Downstream Ports that implement slots. For Downstream Ports not connected to slots (where the Slot Implemented bit of the PCI Express Capabilities register is 0b), this bit must be hardwired to 1b.
And this seems to match what QEMU is doing: it clears on unplug not after guest deals with hotplug.
Quoted 4 lines
Quoted 4 lines
Then, during migration,
get_pci_config_device()will compare the configs of both the freshly created device and the one that is being received via migration, which will differ due to thePCI_EXP_SLTSTA_PDSbit and cause the bug to reproduce.
So bit is set on source.
But why is the bit cleared on destination? This is the part I don't get.
Quoted 10 lines
Quoted 5 lines
To avoid this fake incompatibility, there are two fields in PCIDevice that can help:
.wmask: Used to implement R/W bytes, and .w1cmask: Used to implement RW1C(Write 1 to Clear) bytes
Is there one more option to clear the bit in cmask?
IIUC w1cmask means the guest can now write to this bit, but afaiu from the pcie spec it's RO.
Yes this bit must be RO.
Quoted 37 lines
Quoted 11 lines
According to
pcie_cap_slot_init()the slot status register (PCI_EXP_SLTSTA), in whichPCI_EXP_SLTSTA_PDSis a flag, seems to fall under w1cmask field, with makes sense due to the way signaling the hotplug works.So, add
PCI_EXP_SLTSTA_PDSbit to w1cmask, so the fake incompatibility onget_pci_config_device()does not abort the migration.Signed-off-by Leonardo Bras <[email protected]>Do we need a Fixes: and also the need to copy stable?
Quoted 20 lines
--- hw/pci/pcie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/pci/pcie.c +1
-1@@ -657,7 +657,7 @@ void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s) PCI_EXP_SLTCTL_EIC);pci_word_test_and_set_mask (dev->w1cmask + pos +PCI_EXP_SLTSTA , -PCI_EXP_HP_EV_SUPPORTED ); +PCI_EXP_HP_EV_SUPPORTED |PCI_EXP_SLTSTA_PDS ); dev->exp.hpev_notified = false;Signature · 1 line
2.41.0Signature · 1 line
Peter Xu
Quoted 53 lines · Michael S. Tsirkin
Quoted 21 lines · Peter Xu
Hi, Leo,
Thanks for figuring this out. Let me copy a few more potential reviewers from commit
17858a1695("hw/acpi/ich9: Set ACPI PCI hot-plug as default on Q35").Quoted 14 lines · Leonardo Bras
When trying to migrate a machine type pc-q35-6.0 or lower, with this cmdline options:
(quoted diff) +0
-2-device driver=pcie-root-port,port=18,chassis=19,id=pcie-root-port18,bus=pcie.0,addr=0x12 \ -device driver=nec-usb-xhci,p2=4,p3=4,id=nex-usb-xhci0,bus=pcie-root-port18,addr=0x12.0x1the following bug happens after all ram pages were sent:
qemu-kvm:
get_pci_config_device: Bad config data: i=0x6e read: 0 device: 40 cmask: ff wmask: 0 w1cmask:19
qemu-kvm: Failed to load PCIDevice:config
qemu-kvm: Failed to load pcie-root-port:parent_obj.parent_obj.parent_obj
qemu-kvm: error while loading state for instance0x0of device '0000:00:12.0/pcie-root-port'
qemu-kvm: load of migration failed: Invalid argumentQuoted 7 lines
Quoted 7 lines
This happens on pc-q35-6.0 or lower because of:
{ "ICH9-LPC",ACPI_PM_PROP_ACPI_PCIHP_BRIDGE, "off" }In this scenario,
hotplug_handler_plug()callspcie_cap_slot_plug_cb(), which sets the busdev->configbyte0x6ewith bitPCI_EXP_SLTSTA_PDSto signal PCI hotplug for the guest. After a while the guest will deal with this hotplug and qemu will clear the above bit.Presence Detect State – This bit indicates the presence of an adapter in the slot, reflected by the logical “OR” of the Physical Layer in-band presence detect mechanism and, if present, any out-of-band presence detect mechanism defined for the slot’s corresponding form factor. Note that the in-band presence detect mechanism requires that power be applied to an adapter for its presence to be detected. Consequently, form factors that require a power controller for hot-plug must implement a physical pin presence detect mechanism.
RO
Defined encodings are:
0b Slot Empty
1b Card Present in slot
This bit must be implemented on all Downstream Ports that implement slots. For Downstream Ports not connected to slots (where the Slot Implemented bit of the PCI Express Capabilities register is 0b), this bit must be hardwired to 1b.And this seems to match what QEMU is doing: it clears on unplug not after guest deals with hotplug.
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Then, during migration,
get_pci_config_device()will compare the configs of both the freshly created device and the one that is being received via migration, which will differ due to thePCI_EXP_SLTSTA_PDSbit and cause the bug to reproduce.So bit is set on source.
But why is the bit cleared on destination? This is the part I don't get.
My understanding is that when ACPI_PM_PROP_ACPI_PCIHP_BRIDGE is off for the device, we just won't ever PCI_EXP_SLTSTA_PDS bit?
Quoted 53 lines
Quoted 5 lines
Quoted 5 lines
To avoid this fake incompatibility, there are two fields in PCIDevice that can help:
Quoted 7 lines
Quoted 2 lines
.wmask: Used to implement R/W bytes, and .w1cmask: Used to implement RW1C(Write 1 to Clear) bytes
Is there one more option to clear the bit in cmask?
IIUC w1cmask means the guest can now write to this bit, but afaiu from the pcie spec it's RO.
Yes this bit must be RO.
Quoted 37 lines
Quoted 11 lines
According to
pcie_cap_slot_init()the slot status register (PCI_EXP_SLTSTA), in whichPCI_EXP_SLTSTA_PDSis a flag, seems to fall under w1cmask field, with makes sense due to the way signaling the hotplug works.So, add
PCI_EXP_SLTSTA_PDSbit to w1cmask, so the fake incompatibility onget_pci_config_device()does not abort the migration.Signed-off-by Leonardo Bras <[email protected]>Do we need a Fixes: and also the need to copy stable?
Quoted 20 lines
--- hw/pci/pcie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/pci/pcie.c +1
-1@@ -657,7 +657,7 @@ void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s) PCI_EXP_SLTCTL_EIC);pci_word_test_and_set_mask (dev->w1cmask + pos +PCI_EXP_SLTSTA , -PCI_EXP_HP_EV_SUPPORTED ); +PCI_EXP_HP_EV_SUPPORTED |PCI_EXP_SLTSTA_PDS ); dev->exp.hpev_notified = false;Signature · 1 line
2.41.0Signature · 1 line
Peter Xu
Signature · 1 line
Peter Xu
Quoted 59 lines · Peter Xu
Quoted 58 lines · Michael S. Tsirkin
Quoted 21 lines · Peter Xu
Hi, Leo,
Thanks for figuring this out. Let me copy a few more potential reviewers from commit
17858a1695("hw/acpi/ich9: Set ACPI PCI hot-plug as default on Q35").Quoted 14 lines · Leonardo Bras
When trying to migrate a machine type pc-q35-6.0 or lower, with this cmdline options:
(quoted diff) +0
-2-device driver=pcie-root-port,port=18,chassis=19,id=pcie-root-port18,bus=pcie.0,addr=0x12 \ -device driver=nec-usb-xhci,p2=4,p3=4,id=nex-usb-xhci0,bus=pcie-root-port18,addr=0x12.0x1the following bug happens after all ram pages were sent:
qemu-kvm:
get_pci_config_device: Bad config data: i=0x6e read: 0 device: 40 cmask: ff wmask: 0 w1cmask:19
qemu-kvm: Failed to load PCIDevice:config
qemu-kvm: Failed to load pcie-root-port:parent_obj.parent_obj.parent_obj
qemu-kvm: error while loading state for instance0x0of device '0000:00:12.0/pcie-root-port'
qemu-kvm: load of migration failed: Invalid argumentQuoted 7 lines
Quoted 7 lines
This happens on pc-q35-6.0 or lower because of:
{ "ICH9-LPC",ACPI_PM_PROP_ACPI_PCIHP_BRIDGE, "off" }In this scenario,
hotplug_handler_plug()callspcie_cap_slot_plug_cb(), which sets the busdev->configbyte0x6ewith bitPCI_EXP_SLTSTA_PDSto signal PCI hotplug for the guest. After a while the guest will deal with this hotplug and qemu will clear the above bit.Presence Detect State – This bit indicates the presence of an adapter in the slot, reflected by the logical “OR” of the Physical Layer in-band presence detect mechanism and, if present, any out-of-band presence detect mechanism defined for the slot’s corresponding form factor. Note that the in-band presence detect mechanism requires that power be applied to an adapter for its presence to be detected. Consequently, form factors that require a power controller for hot-plug must implement a physical pin presence detect mechanism.
RO
Defined encodings are:
0b Slot Empty
1b Card Present in slot
This bit must be implemented on all Downstream Ports that implement slots. For Downstream Ports not connected to slots (where the Slot Implemented bit of the PCI Express Capabilities register is 0b), this bit must be hardwired to 1b.And this seems to match what QEMU is doing: it clears on unplug not after guest deals with hotplug.
Quoted 4 lines
Quoted 4 lines
Then, during migration,
get_pci_config_device()will compare the configs of both the freshly created device and the one that is being received via migration, which will differ due to thePCI_EXP_SLTSTA_PDSbit and cause the bug to reproduce.
Quoted 5 lines
Quoted 2 lines
So bit is set on source.
But why is the bit cleared on destination? This is the part I don't get.My understanding is that when
ACPI_PM_PROP_ACPI_PCIHP_BRIDGEis off for the device, we just won't everPCI_EXP_SLTSTA_PDSbit?
Why?
Quoted 56 lines
Quoted 53 lines
Quoted 5 lines
Quoted 5 lines
To avoid this fake incompatibility, there are two fields in PCIDevice that can help:
Quoted 7 lines
Quoted 2 lines
.wmask: Used to implement R/W bytes, and .w1cmask: Used to implement RW1C(Write 1 to Clear) bytes
Is there one more option to clear the bit in cmask?
IIUC w1cmask means the guest can now write to this bit, but afaiu from the pcie spec it's RO.
Yes this bit must be RO.
Quoted 37 lines
Quoted 11 lines
According to
pcie_cap_slot_init()the slot status register (PCI_EXP_SLTSTA), in whichPCI_EXP_SLTSTA_PDSis a flag, seems to fall under w1cmask field, with makes sense due to the way signaling the hotplug works.So, add
PCI_EXP_SLTSTA_PDSbit to w1cmask, so the fake incompatibility onget_pci_config_device()does not abort the migration.Signed-off-by Leonardo Bras <[email protected]>Do we need a Fixes: and also the need to copy stable?
Quoted 20 lines
--- hw/pci/pcie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/pci/pcie.c +1
-1@@ -657,7 +657,7 @@ void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s) PCI_EXP_SLTCTL_EIC);pci_word_test_and_set_mask (dev->w1cmask + pos +PCI_EXP_SLTSTA , -PCI_EXP_HP_EV_SUPPORTED ); +PCI_EXP_HP_EV_SUPPORTED |PCI_EXP_SLTSTA_PDS ); dev->exp.hpev_notified = false;Signature · 1 line
2.41.0Signature · 1 line
Peter XuSignature · 1 line
Peter Xu
Quoted 60 lines · Michael S. Tsirkin
Quoted 59 lines · Peter Xu
Quoted 58 lines · Michael S. Tsirkin
Quoted 21 lines · Peter Xu
Hi, Leo,
Thanks for figuring this out. Let me copy a few more potential reviewers from commit
17858a1695("hw/acpi/ich9: Set ACPI PCI hot-plug as default on Q35").Quoted 14 lines · Leonardo Bras
When trying to migrate a machine type pc-q35-6.0 or lower, with this cmdline options:
(quoted diff) +0
-2-device driver=pcie-root-port,port=18,chassis=19,id=pcie-root-port18,bus=pcie.0,addr=0x12 \ -device driver=nec-usb-xhci,p2=4,p3=4,id=nex-usb-xhci0,bus=pcie-root-port18,addr=0x12.0x1the following bug happens after all ram pages were sent:
qemu-kvm:
get_pci_config_device: Bad config data: i=0x6e read: 0 device: 40 cmask: ff wmask: 0 w1cmask:19
qemu-kvm: Failed to load PCIDevice:config
qemu-kvm: Failed to load pcie-root-port:parent_obj.parent_obj.parent_obj
qemu-kvm: error while loading state for instance0x0of device '0000:00:12.0/pcie-root-port'
qemu-kvm: load of migration failed: Invalid argumentQuoted 7 lines
Quoted 7 lines
This happens on pc-q35-6.0 or lower because of:
{ "ICH9-LPC",ACPI_PM_PROP_ACPI_PCIHP_BRIDGE, "off" }In this scenario,
hotplug_handler_plug()callspcie_cap_slot_plug_cb(), which sets the busdev->configbyte0x6ewith bitPCI_EXP_SLTSTA_PDSto signal PCI hotplug for the guest. After a while the guest will deal with this hotplug and qemu will clear the above bit.Presence Detect State – This bit indicates the presence of an adapter in the slot, reflected by the logical “OR” of the Physical Layer in-band presence detect mechanism and, if present, any out-of-band presence detect mechanism defined for the slot’s corresponding form factor. Note that the in-band presence detect mechanism requires that power be applied to an adapter for its presence to be detected. Consequently, form factors that require a power controller for hot-plug must implement a physical pin presence detect mechanism.
RO
Defined encodings are:
0b Slot Empty
1b Card Present in slot
This bit must be implemented on all Downstream Ports that implement slots. For Downstream Ports not connected to slots (where the Slot Implemented bit of the PCI Express Capabilities register is 0b), this bit must be hardwired to 1b.And this seems to match what QEMU is doing: it clears on unplug not after guest deals with hotplug.
Quoted 4 lines
Quoted 4 lines
Then, during migration,
get_pci_config_device()will compare the configs of both the freshly created device and the one that is being received via migration, which will differ due to thePCI_EXP_SLTSTA_PDSbit and cause the bug to reproduce.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
So bit is set on source.
But why is the bit cleared on destination? This is the part I don't get.My understanding is that when
ACPI_PM_PROP_ACPI_PCIHP_BRIDGEis off for the device, we just won't everPCI_EXP_SLTSTA_PDSbit?Why?
Never mind, spoke too soon, sorry. :(
I thought pcie_cap_slot_plug_cb() can skip the set, but then I just found that dev->hotplugged is not what I imagined there.
Leo should know better.
Quoted 59 lines
Quoted 58 lines
Quoted 55 lines
Quoted 7 lines
Quoted 7 lines
To avoid this fake incompatibility, there are two fields in PCIDevice that can help:
Quoted 7 lines
Quoted 2 lines
.wmask: Used to implement R/W bytes, and .w1cmask: Used to implement RW1C(Write 1 to Clear) bytes
Is there one more option to clear the bit in cmask?
IIUC w1cmask means the guest can now write to this bit, but afaiu from the pcie spec it's RO.
Yes this bit must be RO.
Quoted 37 lines
Quoted 11 lines
According to
pcie_cap_slot_init()the slot status register (PCI_EXP_SLTSTA), in whichPCI_EXP_SLTSTA_PDSis a flag, seems to fall under w1cmask field, with makes sense due to the way signaling the hotplug works.So, add
PCI_EXP_SLTSTA_PDSbit to w1cmask, so the fake incompatibility onget_pci_config_device()does not abort the migration.Signed-off-by Leonardo Bras <[email protected]>Do we need a Fixes: and also the need to copy stable?
Quoted 20 lines
--- hw/pci/pcie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/pci/pcie.c +1
-1@@ -657,7 +657,7 @@ void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s) PCI_EXP_SLTCTL_EIC);pci_word_test_and_set_mask (dev->w1cmask + pos +PCI_EXP_SLTSTA , -PCI_EXP_HP_EV_SUPPORTED ); +PCI_EXP_HP_EV_SUPPORTED |PCI_EXP_SLTSTA_PDS ); dev->exp.hpev_notified = false;Signature · 1 line
2.41.0Signature · 1 line
Peter XuSignature · 1 line
Peter Xu
Signature · 1 line
Peter Xu
Hello Peter and Michael, thanks for reviewing!
Quoted 42 lines · Peter Xu
Quoted 41 lines · Michael S. Tsirkin
Quoted 40 lines · Peter Xu
Quoted 39 lines · Michael S. Tsirkin
Quoted 21 lines · Peter Xu
Hi, Leo,
Thanks for figuring this out. Let me copy a few more potential reviewers from commit
17858a1695("hw/acpi/ich9: Set ACPI PCI hot-plug as default on Q35").Quoted 14 lines · Leonardo Bras
When trying to migrate a machine type pc-q35-6.0 or lower, with this cmdline options:
(quoted diff) +0
-2-device driver=pcie-root-port,port=18,chassis=19,id=pcie-root-port18,bus=pcie.0,addr=0x12 \ -device driver=nec-usb-xhci,p2=4,p3=4,id=nex-usb-xhci0,bus=pcie-root-port18,addr=0x12.0x1the following bug happens after all ram pages were sent:
qemu-kvm:
get_pci_config_device: Bad config data: i=0x6e read: 0 device: 40 cmask: ff wmask: 0 w1cmask:19
qemu-kvm: Failed to load PCIDevice:config
qemu-kvm: Failed to load pcie-root-port:parent_obj.parent_obj.parent_obj
qemu-kvm: error while loading state for instance0x0of device '0000:00:12.0/pcie-root-port'
qemu-kvm: load of migration failed: Invalid argumentQuoted 7 lines
Quoted 7 lines
This happens on pc-q35-6.0 or lower because of:
{ "ICH9-LPC",ACPI_PM_PROP_ACPI_PCIHP_BRIDGE, "off" }In this scenario,
hotplug_handler_plug()callspcie_cap_slot_plug_cb(), which sets the busdev->configbyte0x6ewith bitPCI_EXP_SLTSTA_PDSto signal PCI hotplug for the guest. After a while the guest will deal with this hotplug and qemu will clear the above bit.Presence Detect State – This bit indicates the presence of an adapter in the slot, reflected by the logical “OR” of the Physical Layer in-band presence detect mechanism and, if present, any out-of-band presence detect mechanism defined for the slot’s corresponding form factor. Note that the in-band presence detect mechanism requires that power be applied to an adapter for its presence to be detected. Consequently, form factors that require a power controller for hot-plug must implement a physical pin presence detect mechanism.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
RO
Defined encodings are:
0b Slot Empty
1b Card Present in slot
This bit must be implemented on all Downstream Ports that implement slots. For Downstream Ports not connected to slots (where the Slot Implemented bit of the PCI Express Capabilities register is 0b), this bit must be hardwired to 1b.
Thank you for providing this doc!
I am new to PCI stuff, could you please point this doc?
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
And this seems to match what QEMU is doing: it clears on unplug not after guest deals with hotplug.
Oh, that's weird.
It should not unplug the device, so IIUC it should not clear the bit. Maybe something weird is happening in the guest, I will take a look.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
Then, during migration,
get_pci_config_device()will compare the configs of both the freshly created device and the one that is being received via migration, which will differ due to thePCI_EXP_SLTSTA_PDSbit and cause the bug to reproduce.So bit is set on source.
But why is the bit cleared on destination? This is the part I don't get.
No, bit is set when the device is created by qemu.
After some time running (boot process completion) the bit is cleared.
The receiving end of migration will then create the device with the bit set, and then wait for migration. After the source device is received, the compare fails due to those bits being different.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
My understanding is that when
ACPI_PM_PROP_ACPI_PCIHP_BRIDGEis off for the device, we just won't everPCI_EXP_SLTSTA_PDSbit?
Quoted 8 lines
Quoted 1 line
Why?
Never mind, spoke too soon, sorry. :(
I thought
pcie_cap_slot_plug_cb()can skip the set, but then I just found thatdev->hotpluggedis not what I imagined there.Leo should know better.
There is a difference of which hotplug function is called based on the ACPI_PM_PROP_ACPI_PCIHP_BRIDGE option:
When ACPI_PM_PROP_ACPI_PCIHP_BRIDGE=="off", hotplug_handler_plug() calls pcie_cap_slot_plug_cb() which sets the bus dev->config byte 0x6e with bit PCI_EXP_SLTSTA_PDS.
When ACPI_PM_PROP_ACPI_PCIHP_BRIDGE=="on", hotplug_handler_plug() calls ich9_pm_device_plug_cb(), which does not set this bit.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
To avoid this fake incompatibility, there are two fields in PCIDevice that can help:
.wmask: Used to implement R/W bytes, and .w1cmask: Used to implement RW1C(Write 1 to Clear) bytes
Is there one more option to clear the bit in cmask?
We could clear the bit for .cmask . I suggested w1cmask because I previously understood that bit was guest-writeable.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
IIUC w1cmask means the guest can now write to this bit, but afaiu from the pcie spec it's RO.
Yes this bit must be RO.
My bad, I assumed behavior based on how the guest was working, and this gone wrong. With above documentation provided, I would suggest clearing the .config mask related bit so qemu skips checking this one.
What is your opinion on that?
Quoted 44 lines
Quoted 43 lines
Quoted 42 lines
Quoted 39 lines
Quoted 38 lines
Quoted 7 lines
According to
pcie_cap_slot_init()the slot status register (PCI_EXP_SLTSTA), in whichPCI_EXP_SLTSTA_PDSis a flag, seems to fall under w1cmask field, with makes sense due to the way signaling the hotplug works.Quoted 5 lines
So, add
PCI_EXP_SLTSTA_PDSbit to w1cmask, so the fake incompatibility onget_pci_config_device()does not abort the migration.Signed-off-by Leonardo Bras <[email protected]>Do we need a Fixes: and also the need to copy stable?
Quoted 20 lines
--- hw/pci/pcie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/pci/pcie.c +1
-1@@ -657,7 +657,7 @@ void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s) PCI_EXP_SLTCTL_EIC);pci_word_test_and_set_mask (dev->w1cmask + pos +PCI_EXP_SLTSTA , -PCI_EXP_HP_EV_SUPPORTED ); +PCI_EXP_HP_EV_SUPPORTED |PCI_EXP_SLTSTA_PDS ); dev->exp.hpev_notified = false;Signature · 1 line
2.41.0Signature · 1 line
Peter XuSignature · 1 line
Peter Xu
Hello Peter and Michael, I have a few updates on this:
Quoted 55 lines · Leonardo Brás
Hello Peter and Michael, thanks for reviewing!
Quoted 42 lines · Peter Xu
Quoted 41 lines · Michael S. Tsirkin
Quoted 40 lines · Peter Xu
Quoted 39 lines · Michael S. Tsirkin
Quoted 21 lines · Peter Xu
Hi, Leo,
Thanks for figuring this out. Let me copy a few more potential reviewers from commit
17858a1695("hw/acpi/ich9: Set ACPI PCI hot-plug as default on Q35").Quoted 14 lines · Leonardo Bras
When trying to migrate a machine type pc-q35-6.0 or lower, with this cmdline options:
(quoted diff) +0
-2-device driver=pcie-root-port,port=18,chassis=19,id=pcie-root-port18,bus=pcie.0,addr=0x12 \ -device driver=nec-usb-xhci,p2=4,p3=4,id=nex-usb-xhci0,bus=pcie-root-port18,addr=0x12.0x1the following bug happens after all ram pages were sent:
qemu-kvm:
get_pci_config_device: Bad config data: i=0x6e read: 0 device: 40 cmask: ff wmask: 0 w1cmask:19
qemu-kvm: Failed to load PCIDevice:config
qemu-kvm: Failed to load pcie-root-port:parent_obj.parent_obj.parent_obj
qemu-kvm: error while loading state for instance0x0of device '0000:00:12.0/pcie-root-port'
qemu-kvm: load of migration failed: Invalid argumentQuoted 7 lines
Quoted 7 lines
This happens on pc-q35-6.0 or lower because of:
{ "ICH9-LPC",ACPI_PM_PROP_ACPI_PCIHP_BRIDGE, "off" }In this scenario,
hotplug_handler_plug()callspcie_cap_slot_plug_cb(), which sets the busdev->configbyte0x6ewith bitPCI_EXP_SLTSTA_PDSto signal PCI hotplug for the guest. After a while the guest will deal with this hotplug and qemu will clear the above bit.Presence Detect State – This bit indicates the presence of an adapter in the slot, reflected by the logical “OR” of the Physical Layer in-band presence detect mechanism and, if present, any out-of-band presence detect mechanism defined for the slot’s corresponding form factor. Note that the in-band presence detect mechanism requires that power be applied to an adapter for its presence to be detected. Consequently, form factors that require a power controller for hot-plug must implement a physical pin presence detect mechanism.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
RO
Defined encodings are:
0b Slot Empty
1b Card Present in slot
This bit must be implemented on all Downstream Ports that implement slots. For Downstream Ports not connected to slots (where the Slot Implemented bit of the PCI Express Capabilities register is 0b), this bit must be hardwired to 1b.
Quoted 2 lines
Thank you for providing this doc!
I am new to PCI stuff, could you please point this doc?
(I mean, the link to the documentation)
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
And this seems to match what QEMU is doing: it clears on unplug not after guest deals with hotplug.
Oh, that's weird.
It should not unplug the device, so IIUC it should not clear the bit. Maybe something weird is happening in the guest, I will take a look.
Updates on this:
You are right! For some reason the guest is hot-unplugging the device under some conditions, so there is another bug on this for me to look after.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Then, during migration,
get_pci_config_device()will compare the configs of both the freshly created device and the one that is being received via migration, which will differ due to thePCI_EXP_SLTSTA_PDSbit and cause the bug to reproduce.
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
So bit is set on source.
But why is the bit cleared on destination? This is the part I don't get.No, bit is set when the device is created by qemu.
After some time running (boot process completion) the bit is cleared.
The 'after some time' here is about the guest hot-unplugging the device.
Quoted 5 lines
The receiving end of migration will then create the device with the bit set, and then wait for migration. After the source device is received, the compare fails due to those bits being different.
But anyway, there is some chance the device will be hot-unplugged by the guest OS for any reason, so we need to cover this scenario so it does not break migration.
Quoted 33 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
My understanding is that when
ACPI_PM_PROP_ACPI_PCIHP_BRIDGEis off for the device, we just won't everPCI_EXP_SLTSTA_PDSbit?Quoted 8 lines
Quoted 1 line
Why?
Never mind, spoke too soon, sorry. :(
I thought
pcie_cap_slot_plug_cb()can skip the set, but then I just found thatdev->hotpluggedis not what I imagined there.Leo should know better.
There is a difference of which hotplug function is called based on the
ACPI_PM_PROP_ACPI_PCIHP_BRIDGEoption:When ACPI_PM_PROP_ACPI_PCIHP_BRIDGE=="off",
hotplug_handler_plug()callspcie_cap_slot_plug_cb()which sets the busdev->configbyte0x6ewith bitPCI_EXP_SLTSTA_PDS.When ACPI_PM_PROP_ACPI_PCIHP_BRIDGE=="on",
hotplug_handler_plug()callsich9_pm_device_plug_cb(), which does not set this bit.Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
To avoid this fake incompatibility, there are two fields in PCIDevice that can help:
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
.wmask: Used to implement R/W bytes, and .w1cmask: Used to implement RW1C(Write 1 to Clear) bytes
Is there one more option to clear the bit in cmask?
We could clear the bit for .cmask . I suggested w1cmask because I previously understood that bit was guest-writeable.
IIUC, the bit is guest-writeable, so we should use .wmask instead of .cmask . Is this correct?
Quoted 58 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
IIUC w1cmask means the guest can now write to this bit, but afaiu from the pcie spec it's RO.
Yes this bit must be RO.
My bad, I assumed behavior based on how the guest was working, and this gone wrong. With above documentation provided, I would suggest clearing the .config mask related bit so qemu skips checking this one.
What is your opinion on that?
Quoted 44 lines
Quoted 43 lines
Quoted 42 lines
Quoted 39 lines
Quoted 38 lines
Quoted 7 lines
According to
pcie_cap_slot_init()the slot status register (PCI_EXP_SLTSTA), in whichPCI_EXP_SLTSTA_PDSis a flag, seems to fall under w1cmask field, with makes sense due to the way signaling the hotplug works.Quoted 5 lines
So, add
PCI_EXP_SLTSTA_PDSbit to w1cmask, so the fake incompatibility onget_pci_config_device()does not abort the migration.Signed-off-by Leonardo Bras <[email protected]>Do we need a Fixes: and also the need to copy stable?
Quoted 20 lines
--- hw/pci/pcie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/pci/pcie.c +1
-1@@ -657,7 +657,7 @@ void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s) PCI_EXP_SLTCTL_EIC);pci_word_test_and_set_mask (dev->w1cmask + pos +PCI_EXP_SLTSTA , -PCI_EXP_HP_EV_SUPPORTED ); +PCI_EXP_HP_EV_SUPPORTED |PCI_EXP_SLTSTA_PDS ); dev->exp.hpev_notified = false;Signature · 1 line
2.41.0Signature · 1 line
Peter XuSignature · 1 line
Peter Xu
Quoted 58 lines · Leonardo Brás
Hello Peter and Michael, I have a few updates on this:
Quoted 55 lines · Leonardo Brás
Hello Peter and Michael, thanks for reviewing!
Quoted 50 lines · Peter Xu
Quoted 49 lines · Michael S. Tsirkin
Quoted 48 lines · Peter Xu
Quoted 47 lines · Michael S. Tsirkin
Quoted 21 lines · Peter Xu
Hi, Leo,
Thanks for figuring this out. Let me copy a few more potential reviewers from commit
17858a1695("hw/acpi/ich9: Set ACPI PCI hot-plug as default on Q35").Quoted 14 lines · Leonardo Bras
When trying to migrate a machine type pc-q35-6.0 or lower, with this cmdline options:
(quoted diff) +0
-2-device driver=pcie-root-port,port=18,chassis=19,id=pcie-root-port18,bus=pcie.0,addr=0x12 \ -device driver=nec-usb-xhci,p2=4,p3=4,id=nex-usb-xhci0,bus=pcie-root-port18,addr=0x12.0x1the following bug happens after all ram pages were sent:
qemu-kvm:
get_pci_config_device: Bad config data: i=0x6e read: 0 device: 40 cmask: ff wmask: 0 w1cmask:19
qemu-kvm: Failed to load PCIDevice:config
qemu-kvm: Failed to load pcie-root-port:parent_obj.parent_obj.parent_obj
qemu-kvm: error while loading state for instance0x0of device '0000:00:12.0/pcie-root-port'
qemu-kvm: load of migration failed: Invalid argumentQuoted 7 lines
Quoted 7 lines
This happens on pc-q35-6.0 or lower because of:
{ "ICH9-LPC",ACPI_PM_PROP_ACPI_PCIHP_BRIDGE, "off" }In this scenario,
hotplug_handler_plug()callspcie_cap_slot_plug_cb(), which sets the busdev->configbyte0x6ewith bitPCI_EXP_SLTSTA_PDSto signal PCI hotplug for the guest. After a while the guest will deal with this hotplug and qemu will clear the above bit.Presence Detect State – This bit indicates the presence of an adapter in the slot, reflected by the logical “OR” of the Physical Layer in-band presence detect mechanism and, if present, any out-of-band presence detect mechanism defined for the slot’s corresponding form factor. Note that the in-band presence detect mechanism requires that power be applied to an adapter for its presence to be detected. Consequently, form factors that require a power controller for hot-plug must implement a physical pin presence detect mechanism.
RO
Defined encodings are:
0b Slot Empty
1b Card Present in slot
This bit must be implemented on all Downstream Ports that implement slots. For Downstream Ports not connected to slots (where the Slot Implemented bit of the PCI Express Capabilities register is 0b), this bit must be hardwired to 1b.
Quoted 4 lines
Quoted 2 lines
Thank you for providing this doc!
I am new to PCI stuff, could you please point this doc?(I mean, the link to the documentation)
The pci specs are all here: https://pcisig.com/
Red Hat is a member so just register, it's free.
I'd get the 5.0 version of pci express base:
https://members.pcisig.com/wg/PCI-SIG/document/13005
6.0 is out but they did something to make it take years to open, and it shouldn't matter for this.
Quoted 142 lines
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
And this seems to match what QEMU is doing: it clears on unplug not after guest deals with hotplug.
Oh, that's weird.
It should not unplug the device, so IIUC it should not clear the bit. Maybe something weird is happening in the guest, I will take a look.Updates on this:
You are right! For some reason the guest is hot-unplugging the device under some conditions, so there is another bug on this for me to look after.Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Then, during migration,
get_pci_config_device()will compare the configs of both the freshly created device and the one that is being received via migration, which will differ due to thePCI_EXP_SLTSTA_PDSbit and cause the bug to reproduce.Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
So bit is set on source.
But why is the bit cleared on destination? This is the part I don't get.No, bit is set when the device is created by qemu.
After some time running (boot process completion) the bit is cleared.The 'after some time' here is about the guest hot-unplugging the device.
Quoted 5 lines
The receiving end of migration will then create the device with the bit set, and then wait for migration. After the source device is received, the compare fails due to those bits being different.
But anyway, there is some chance the device will be hot-unplugged by the guest OS for any reason, so we need to cover this scenario so it does not break migration.
Quoted 33 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
My understanding is that when
ACPI_PM_PROP_ACPI_PCIHP_BRIDGEis off for the device, we just won't everPCI_EXP_SLTSTA_PDSbit?Quoted 8 lines
Quoted 1 line
Why?
Never mind, spoke too soon, sorry. :(
I thought
pcie_cap_slot_plug_cb()can skip the set, but then I just found thatdev->hotpluggedis not what I imagined there.Leo should know better.
There is a difference of which hotplug function is called based on the
ACPI_PM_PROP_ACPI_PCIHP_BRIDGEoption:When ACPI_PM_PROP_ACPI_PCIHP_BRIDGE=="off",
hotplug_handler_plug()callspcie_cap_slot_plug_cb()which sets the busdev->configbyte0x6ewith bitPCI_EXP_SLTSTA_PDS.When ACPI_PM_PROP_ACPI_PCIHP_BRIDGE=="on",
hotplug_handler_plug()callsich9_pm_device_plug_cb(), which does not set this bit.Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
To avoid this fake incompatibility, there are two fields in PCIDevice that can help:
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
.wmask: Used to implement R/W bytes, and .w1cmask: Used to implement RW1C(Write 1 to Clear) bytes
Is there one more option to clear the bit in cmask?
We could clear the bit for .cmask . I suggested w1cmask because I previously understood that bit was guest-writeable.
IIUC, the bit is guest-writeable, so we should use .wmask instead of .cmask . Is this correct?
Quoted 58 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
IIUC w1cmask means the guest can now write to this bit, but afaiu from the pcie spec it's RO.
Yes this bit must be RO.
My bad, I assumed behavior based on how the guest was working, and this gone wrong. With above documentation provided, I would suggest clearing the .config mask related bit so qemu skips checking this one.
What is your opinion on that?
Quoted 44 lines
Quoted 43 lines
Quoted 42 lines
Quoted 39 lines
Quoted 38 lines
Quoted 7 lines
According to
pcie_cap_slot_init()the slot status register (PCI_EXP_SLTSTA), in whichPCI_EXP_SLTSTA_PDSis a flag, seems to fall under w1cmask field, with makes sense due to the way signaling the hotplug works.Quoted 5 lines
So, add
PCI_EXP_SLTSTA_PDSbit to w1cmask, so the fake incompatibility onget_pci_config_device()does not abort the migration.Signed-off-by Leonardo Bras <[email protected]>Do we need a Fixes: and also the need to copy stable?
Quoted 20 lines
--- hw/pci/pcie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/pci/pcie.c +1
-1@@ -657,7 +657,7 @@ void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s) PCI_EXP_SLTCTL_EIC);pci_word_test_and_set_mask (dev->w1cmask + pos +PCI_EXP_SLTSTA , -PCI_EXP_HP_EV_SUPPORTED ); +PCI_EXP_HP_EV_SUPPORTED |PCI_EXP_SLTSTA_PDS ); dev->exp.hpev_notified = false;Signature · 1 line
2.41.0Signature · 1 line
Peter XuSignature · 1 line
Peter Xu
Quoted 65 lines · Michael S. Tsirkin
Quoted 58 lines · Leonardo Brás
Hello Peter and Michael, I have a few updates on this:
Quoted 55 lines · Leonardo Brás
Hello Peter and Michael, thanks for reviewing!
Quoted 50 lines · Peter Xu
Quoted 49 lines · Michael S. Tsirkin
Quoted 48 lines · Peter Xu
Quoted 47 lines · Michael S. Tsirkin
Quoted 21 lines · Peter Xu
Hi, Leo,
Thanks for figuring this out. Let me copy a few more potential reviewers from commit
17858a1695("hw/acpi/ich9: Set ACPI PCI hot-plug as default on Q35").Quoted 14 lines · Leonardo Bras
When trying to migrate a machine type pc-q35-6.0 or lower, with this cmdline options:
(quoted diff) +0
-2-device driver=pcie-root-port,port=18,chassis=19,id=pcie-root-port18,bus=pcie.0,addr=0x12 \ -device driver=nec-usb-xhci,p2=4,p3=4,id=nex-usb-xhci0,bus=pcie-root-port18,addr=0x12.0x1the following bug happens after all ram pages were sent:
qemu-kvm:
get_pci_config_device: Bad config data: i=0x6e read: 0 device: 40 cmask: ff wmask: 0 w1cmask:19
qemu-kvm: Failed to load PCIDevice:config
qemu-kvm: Failed to load pcie-root-port:parent_obj.parent_obj.parent_obj
qemu-kvm: error while loading state for instance0x0of device '0000:00:12.0/pcie-root-port'
qemu-kvm: load of migration failed: Invalid argumentQuoted 7 lines
Quoted 7 lines
This happens on pc-q35-6.0 or lower because of:
{ "ICH9-LPC",ACPI_PM_PROP_ACPI_PCIHP_BRIDGE, "off" }In this scenario,
hotplug_handler_plug()callspcie_cap_slot_plug_cb(), which sets the busdev->configbyte0x6ewith bitPCI_EXP_SLTSTA_PDSto signal PCI hotplug for the guest. After a while the guest will deal with this hotplug and qemu will clear the above bit.Presence Detect State – This bit indicates the presence of an adapter in the slot, reflected by the logical “OR” of the Physical Layer in-band presence detect mechanism and, if present, any out-of-band presence detect mechanism defined for the slot’s corresponding form factor. Note that the in-band presence detect mechanism requires that power be applied to an adapter for its presence to be detected. Consequently, form factors that require a power controller for hot-plug must implement a physical pin presence detect mechanism.
RO
Defined encodings are:
0b Slot Empty
1b Card Present in slot
This bit must be implemented on all Downstream Ports that implement slots. For Downstream Ports not connected to slots (where the Slot Implemented bit of the PCI Express Capabilities register is 0b), this bit must be hardwired to 1b.Quoted 4 lines
Quoted 2 lines
Thank you for providing this doc!
I am new to PCI stuff, could you please point this doc?(I mean, the link to the documentation)
Quoted 8 lines
The pci specs are all here: https://pcisig.com/
Red Hat is a member so just register, it's free.I'd get the 5.0 version of pci express base:
https://members.pcisig.com/wg/PCI-SIG/document/130056.0 is out but they did something to make it take years to open, and it shouldn't matter for this.
This is great! Thanks for sharing!
Quoted 77 lines
Quoted 77 lines
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
And this seems to match what QEMU is doing: it clears on unplug not after guest deals with hotplug.
Oh, that's weird.
It should not unplug the device, so IIUC it should not clear the bit. Maybe something weird is happening in the guest, I will take a look.Updates on this:
You are right! For some reason the guest is hot-unplugging the device under some conditions, so there is another bug on this for me to look after.Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Then, during migration,
get_pci_config_device()will compare the configs of both the freshly created device and the one that is being received via migration, which will differ due to thePCI_EXP_SLTSTA_PDSbit and cause the bug to reproduce.Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
So bit is set on source.
But why is the bit cleared on destination? This is the part I don't get.No, bit is set when the device is created by qemu.
After some time running (boot process completion) the bit is cleared.The 'after some time' here is about the guest hot-unplugging the device.
Quoted 5 lines
The receiving end of migration will then create the device with the bit set, and then wait for migration. After the source device is received, the compare fails due to those bits being different.
But anyway, there is some chance the device will be hot-unplugged by the guest OS for any reason, so we need to cover this scenario so it does not break migration.
Quoted 36 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
My understanding is that when
ACPI_PM_PROP_ACPI_PCIHP_BRIDGEis off for the device, we just won't everPCI_EXP_SLTSTA_PDSbit?Quoted 8 lines
Quoted 1 line
Why?
Never mind, spoke too soon, sorry. :(
I thought
pcie_cap_slot_plug_cb()can skip the set, but then I just found thatdev->hotpluggedis not what I imagined there.Leo should know better.
There is a difference of which hotplug function is called based on the
ACPI_PM_PROP_ACPI_PCIHP_BRIDGEoption:When ACPI_PM_PROP_ACPI_PCIHP_BRIDGE=="off",
hotplug_handler_plug()callspcie_cap_slot_plug_cb()which sets the busdev->configbyte0x6ewith bitPCI_EXP_SLTSTA_PDS.When ACPI_PM_PROP_ACPI_PCIHP_BRIDGE=="on",
hotplug_handler_plug()callsich9_pm_device_plug_cb(), which does not set this bit.Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
To avoid this fake incompatibility, there are two fields in PCIDevice that can help:
.wmask: Used to implement R/W bytes, and .w1cmask: Used to implement RW1C(Write 1 to Clear) bytes
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Is there one more option to clear the bit in cmask?
We could clear the bit for .cmask . I suggested w1cmask because I previously understood that bit was guest-writeable.
IIUC, the bit is guest-writeable, so we should use .wmask instead of .cmask . Is this correct?
It was incorrect :/
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
IIUC w1cmask means the guest can now write to this bit, but afaiu from the pcie spec it's RO.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Yes this bit must be RO.
My bad, I assumed behavior based on how the guest was working, and this gone wrong. With above documentation provided, I would suggest clearing the .config mask related bit so qemu skips checking this one.
What is your opinion on that?
Michael,
Is the above fine?
If so, I will send a v2 on this.
Any other suggestions?
Quoted 47 lines
Quoted 46 lines
Quoted 46 lines
Quoted 45 lines
Quoted 44 lines
Quoted 43 lines
Quoted 31 lines
Quoted 31 lines
Quoted 8 lines
According to
pcie_cap_slot_init()the slot status register (PCI_EXP_SLTSTA), in whichPCI_EXP_SLTSTA_PDSis a flag, seems to fall under w1cmask field, with makes sense due to the way signaling the hotplug works.Quoted 5 lines
So, add
PCI_EXP_SLTSTA_PDSbit to w1cmask, so the fake incompatibility onget_pci_config_device()does not abort the migration.Signed-off-by Leonardo Bras <[email protected]>Do we need a Fixes: and also the need to copy stable?
Quoted 15 lines
--- hw/pci/pcie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/pci/pcie.c +1
-1@@ -657,7 +657,7 @@ void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s) PCI_EXP_SLTCTL_EIC);pci_word_test_and_set_mask (dev->w1cmask + pos +PCI_EXP_SLTSTA , -PCI_EXP_HP_EV_SUPPORTED ); +PCI_EXP_HP_EV_SUPPORTED |PCI_EXP_SLTSTA_PDS );Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
hw/pci/pcie.c +0
-1dev->exp.hpev_notified = false; --2.41.0
--
Peter Xu--
Peter Xu
Quoted 157 lines · Leonardo Bras Soares Passos
Quoted 65 lines · Michael S. Tsirkin
Quoted 58 lines · Leonardo Brás
Hello Peter and Michael, I have a few updates on this:
Quoted 55 lines · Leonardo Brás
Hello Peter and Michael, thanks for reviewing!
Quoted 50 lines · Peter Xu
Quoted 49 lines · Michael S. Tsirkin
Quoted 48 lines · Peter Xu
Quoted 47 lines · Michael S. Tsirkin
Quoted 21 lines · Peter Xu
Hi, Leo,
Thanks for figuring this out. Let me copy a few more potential reviewers from commit
17858a1695("hw/acpi/ich9: Set ACPI PCI hot-plug as default on Q35").Quoted 14 lines · Leonardo Bras
When trying to migrate a machine type pc-q35-6.0 or lower, with this cmdline options:
(quoted diff) +0
-2-device driver=pcie-root-port,port=18,chassis=19,id=pcie-root-port18,bus=pcie.0,addr=0x12 \ -device driver=nec-usb-xhci,p2=4,p3=4,id=nex-usb-xhci0,bus=pcie-root-port18,addr=0x12.0x1the following bug happens after all ram pages were sent:
qemu-kvm:
get_pci_config_device: Bad config data: i=0x6e read: 0 device: 40 cmask: ff wmask: 0 w1cmask:19
qemu-kvm: Failed to load PCIDevice:config
qemu-kvm: Failed to load pcie-root-port:parent_obj.parent_obj.parent_obj
qemu-kvm: error while loading state for instance0x0of device '0000:00:12.0/pcie-root-port'
qemu-kvm: load of migration failed: Invalid argumentQuoted 7 lines
Quoted 7 lines
This happens on pc-q35-6.0 or lower because of:
{ "ICH9-LPC",ACPI_PM_PROP_ACPI_PCIHP_BRIDGE, "off" }In this scenario,
hotplug_handler_plug()callspcie_cap_slot_plug_cb(), which sets the busdev->configbyte0x6ewith bitPCI_EXP_SLTSTA_PDSto signal PCI hotplug for the guest. After a while the guest will deal with this hotplug and qemu will clear the above bit.Presence Detect State – This bit indicates the presence of an adapter in the slot, reflected by the logical “OR” of the Physical Layer in-band presence detect mechanism and, if present, any out-of-band presence detect mechanism defined for the slot’s corresponding form factor. Note that the in-band presence detect mechanism requires that power be applied to an adapter for its presence to be detected. Consequently, form factors that require a power controller for hot-plug must implement a physical pin presence detect mechanism.
RO
Defined encodings are:
0b Slot Empty
1b Card Present in slot
This bit must be implemented on all Downstream Ports that implement slots. For Downstream Ports not connected to slots (where the Slot Implemented bit of the PCI Express Capabilities register is 0b), this bit must be hardwired to 1b.Quoted 4 lines
Quoted 2 lines
Thank you for providing this doc!
I am new to PCI stuff, could you please point this doc?(I mean, the link to the documentation)
Quoted 8 lines
The pci specs are all here: https://pcisig.com/
Red Hat is a member so just register, it's free.I'd get the 5.0 version of pci express base:
https://members.pcisig.com/wg/PCI-SIG/document/130056.0 is out but they did something to make it take years to open, and it shouldn't matter for this.
This is great! Thanks for sharing!
Quoted 79 lines
Quoted 79 lines
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
And this seems to match what QEMU is doing: it clears on unplug not after guest deals with hotplug.
Oh, that's weird.
It should not unplug the device, so IIUC it should not clear the bit. Maybe something weird is happening in the guest, I will take a look.Updates on this:
You are right! For some reason the guest is hot-unplugging the device under some conditions, so there is another bug on this for me to look after.Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Then, during migration,
get_pci_config_device()will compare the configs of both the freshly created device and the one that is being received via migration, which will differ due to thePCI_EXP_SLTSTA_PDSbit and cause the bug to reproduce.Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
So bit is set on source.
But why is the bit cleared on destination? This is the part I don't get.No, bit is set when the device is created by qemu.
After some time running (boot process completion) the bit is cleared.The 'after some time' here is about the guest hot-unplugging the device.
Quoted 5 lines
The receiving end of migration will then create the device with the bit set, and then wait for migration. After the source device is received, the compare fails due to those bits being different.
But anyway, there is some chance the device will be hot-unplugged by the guest OS for any reason, so we need to cover this scenario so it does not break migration.
Quoted 38 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
My understanding is that when
ACPI_PM_PROP_ACPI_PCIHP_BRIDGEis off for the device, we just won't everPCI_EXP_SLTSTA_PDSbit?Quoted 8 lines
Quoted 1 line
Why?
Never mind, spoke too soon, sorry. :(
I thought
pcie_cap_slot_plug_cb()can skip the set, but then I just found thatdev->hotpluggedis not what I imagined there.Leo should know better.
There is a difference of which hotplug function is called based on the
ACPI_PM_PROP_ACPI_PCIHP_BRIDGEoption:When ACPI_PM_PROP_ACPI_PCIHP_BRIDGE=="off",
hotplug_handler_plug()callspcie_cap_slot_plug_cb()which sets the busdev->configbyte0x6ewith bitPCI_EXP_SLTSTA_PDS.When ACPI_PM_PROP_ACPI_PCIHP_BRIDGE=="on",
hotplug_handler_plug()callsich9_pm_device_plug_cb(), which does not set this bit.Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 10 lines
To avoid this fake incompatibility, there are two fields in PCIDevice that can help:
.wmask: Used to implement R/W bytes, and .w1cmask: Used to implement RW1C(Write 1 to Clear) bytes
Is there one more option to clear the bit in cmask?
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
We could clear the bit for .cmask . I suggested w1cmask because I previously understood that bit was guest-writeable.
IIUC, the bit is guest-writeable, so we should use .wmask instead of .cmask . Is this correct?
It was incorrect :/
I was under the impression the guest was writing to this value, but in fact it was writing to SLTCTL (RW), and qemu was the one detecting power on -> power off for the device and writing 0 to SLTSTA-> Presence Detect State.
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
IIUC w1cmask means the guest can now write to this bit, but afaiu from the pcie spec it's RO.
Yes this bit must be RO.
My bad, I assumed behavior based on how the guest was working, and this gone wrong. With above documentation provided, I would suggest clearing the .config mask related bit so qemu skips checking this one.
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
What is your opinion on that?
Michael,
Is the above fine?If so, I will send a v2 on this.
Any other suggestions?
This v2 is mostly ready, so I will send it, and in any case it's not the best solution, we can improve that on a possible v3.
Quoted 47 lines
Quoted 47 lines
Quoted 46 lines
Quoted 46 lines
Quoted 45 lines
Quoted 44 lines
Quoted 43 lines
Quoted 31 lines
Quoted 31 lines
Quoted 8 lines
According to
pcie_cap_slot_init()the slot status register (PCI_EXP_SLTSTA), in whichPCI_EXP_SLTSTA_PDSis a flag, seems to fall under w1cmask field, with makes sense due to the way signaling the hotplug works.Quoted 5 lines
So, add
PCI_EXP_SLTSTA_PDSbit to w1cmask, so the fake incompatibility onget_pci_config_device()does not abort the migration.Signed-off-by Leonardo Bras <[email protected]>Do we need a Fixes: and also the need to copy stable?
Quoted 15 lines
--- hw/pci/pcie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/pci/pcie.c +1
-1@@ -657,7 +657,7 @@ void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s) PCI_EXP_SLTCTL_EIC);pci_word_test_and_set_mask (dev->w1cmask + pos +PCI_EXP_SLTSTA , -PCI_EXP_HP_EV_SUPPORTED ); +PCI_EXP_HP_EV_SUPPORTED |PCI_EXP_SLTSTA_PDS );Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
hw/pci/pcie.c +0
-1dev->exp.hpev_notified = false; --2.41.0
--
Peter Xu--
Peter Xu