[Qemu-devel] [RFC PATCH] pci: deassert intx when pci device unrealize

Herongguang (Stephen) posted 1 patch 6 years, 11 months ago
Failed in applying to current master (apply log)
hw/pci/pci.c | 1 +
1 file changed, 1 insertion(+)
[Qemu-devel] [RFC PATCH] pci: deassert intx when pci device unrealize
Posted by Herongguang (Stephen) 6 years, 11 months ago
If a pci device is not reset by VM (by writing into config space)
and unplugged by VM, after that when VM reboots, qemu may assert:
pcibus_reset: Assertion `bus->irq_count[i] == 0' failed

Signed-off-by: herongguang <herongguang.he@huawei.com>
---

Is there need to call pci_do_device_reset()?

---
  hw/pci/pci.c | 1 +
  1 file changed, 1 insertion(+)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 259483b..afe6397 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -1078,6 +1078,7 @@ static void pci_qdev_unrealize(DeviceState *dev, Error **errp)

      pci_unregister_io_regions(pci_dev);
      pci_del_option_rom(pci_dev);
+    pci_device_deassert_intx(pci_dev);

      if (pc->exit) {
          pc->exit(pci_dev);
--
1.7.12.4

Re: [Qemu-devel] [RFC PATCH] pci: deassert intx when pci device unrealize
Posted by Michael S. Tsirkin 6 years, 11 months ago
On Mon, Apr 24, 2017 at 09:12:29PM +0800, Herongguang (Stephen) wrote:
> If a pci device is not reset by VM (by writing into config space)
> and unplugged by VM, after that when VM reboots, qemu may assert:
> pcibus_reset: Assertion `bus->irq_count[i] == 0' failed
> 
> Signed-off-by: herongguang <herongguang.he@huawei.com>

Good grief, I can't believe we have had this bug for so long.
Thanks a lot for finding this.

Pls Cc stable on this patch.

> ---
> 
> Is there need to call pci_do_device_reset()?

I don't think so, why?

> ---
>  hw/pci/pci.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index 259483b..afe6397 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -1078,6 +1078,7 @@ static void pci_qdev_unrealize(DeviceState *dev, Error **errp)
> 
>      pci_unregister_io_regions(pci_dev);
>      pci_del_option_rom(pci_dev);
> +    pci_device_deassert_intx(pci_dev);

I think the right place to call this is after class exit
when we know no one will try to assert the interrupt.

> 
>      if (pc->exit) {
>          pc->exit(pci_dev);
> --
> 1.7.12.4

Re: [Qemu-devel] [RFC PATCH] pci: deassert intx when pci device unrealize
Posted by Herongguang (Stephen) 6 years, 11 months ago

On 2017/4/25 7:45, Michael S. Tsirkin wrote:
> On Mon, Apr 24, 2017 at 09:12:29PM +0800, Herongguang (Stephen) wrote:
>> If a pci device is not reset by VM (by writing into config space)
>> and unplugged by VM, after that when VM reboots, qemu may assert:
>> pcibus_reset: Assertion `bus->irq_count[i] == 0' failed
>>
>> Signed-off-by: herongguang <herongguang.he@huawei.com>
>
> Good grief, I can't believe we have had this bug for so long.
> Thanks a lot for finding this.
>
> Pls Cc stable on this patch.
>
>> ---
>>
>> Is there need to call pci_do_device_reset()?
>
> I don't think so, why?
>
>> ---
>>   hw/pci/pci.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
>> index 259483b..afe6397 100644
>> --- a/hw/pci/pci.c
>> +++ b/hw/pci/pci.c
>> @@ -1078,6 +1078,7 @@ static void pci_qdev_unrealize(DeviceState *dev, Error **errp)
>>
>>       pci_unregister_io_regions(pci_dev);
>>       pci_del_option_rom(pci_dev);
>> +    pci_device_deassert_intx(pci_dev);
>
> I think the right place to call this is after class exit
> when we know no one will try to assert the interrupt.

OK, it's safer, will resend a new patch.

>
>>
>>       if (pc->exit) {
>>           pc->exit(pci_dev);
>> --
>> 1.7.12.4
> .
>