MSI: Fix release of resources
PATCH 1/1 MSI: Fix release of resources
msi_init may fail, so the users should check msi_present before calling msi_uninit.
--- hw/ide/ich.c | 2 +- hw/intel-hda.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
hw/ide/ich.c +1 -1
@@ -110,7 +110,7 @@ static int pci_ich9_uninit(PCIDevice *dev)struct AHCIPCIState *d; d = DO_UPCAST(struct AHCIPCIState, card, dev); -if (msi_enabled (dev)) { +if (msi_present (dev)) {msi_uninit (dev); }
hw/intel-hda.c +1 -1
@@ -1174,7 +1174,7 @@ static int intel_hda_exit(PCIDevice *pci) {IntelHDAState *d =DO_UPCAST (IntelHDAState, pci, pci); -if (d->msi) { +if (msi_present (pci)) {msi_uninit (&d->pci); }cpu_unregister_io_memory (d->mmio_addr);
Signature · 1 line
1.7.1
PATCH v2 1/1 MSI: Robust resource release
msi_init may fail, so we need to check on uninit if the cap was actually installed. This also avoids that the users need to check.
--- hw/ide/ich.c | 5 +---- hw/intel-hda.c | 4 +--- hw/msi.c | 12 ++++++++++-- 3 files changed, 12 insertions(+), 9 deletions(-)
v2: Push cap check into msi_uninit (just like msix), remove check from
users.
hw/ide/ich.c +1 -4
@@ -110,10 +110,7 @@ static int pci_ich9_uninit(PCIDevice *dev)struct AHCIPCIState *d; d = DO_UPCAST(struct AHCIPCIState, card, dev); -if (msi_enabled (dev)) { -msi_uninit (dev); - } - +msi_uninit (dev);qemu_unregister_reset (ahci_reset, d);ahci_uninit (&d->ahci);
hw/intel-hda.c +1 -3
@@ -1174,9 +1174,7 @@ static int intel_hda_exit(PCIDevice *pci) {IntelHDAState *d =DO_UPCAST (IntelHDAState, pci, pci); -if (d->msi) { -msi_uninit (&d->pci); - } +msi_uninit (&d->pci);cpu_unregister_io_memory (d->mmio_addr);return 0 ; }
hw/msi.c +10 -2
@@ -183,9 +183,17 @@ int msi_init(struct PCIDevice *dev, uint8_t offset,void msi_uninit (struct PCIDevice *dev) { -uint16_t flags =pci_get_word (dev->config +msi_flags_off (dev)); -uint8_t cap_size =msi_cap_sizeof (flags); +uint16_t flags; +uint8_t cap_size; + +if (!(dev->cap_present &QEMU_PCI_CAP_MSI )) { +return ; + } + flags =pci_get_word (dev->config +msi_flags_off (dev)); + cap_size =msi_cap_sizeof (flags);pci_del_capability (dev,PCI_CAP_ID_MSIX , cap_size); + dev->cap_present &= ~QEMU_PCI_CAP_MSI ; +MSI_DEV_PRINTF (dev,"uninit\n" ); }
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH v2] MSI: Robust resource release
Quoted 4 lines · Jan Kiszka
msi_initmay fail, so we need to check on uninit if the cap was actually installed. This also avoids that the users need to check.Signed-off-by Jan Kiszka <[email protected]>
Looks good to me.
Alex
Michael S. Tsirkin
AppliedRe: [Qemu-devel] [PATCH v2] MSI: Robust resource release
In reply to Jan KiszkaQuoted 4 lines · Jan Kiszka
msi_initmay fail, so we need to check on uninit if the cap was actually installed. This also avoids that the users need to check.Signed-off-by Jan Kiszka <[email protected]>
Applied, thanks!
Quoted 66 lines
--- hw/ide/ich.c | 5 +---- hw/intel-hda.c | 4 +--- hw/msi.c | 12 ++++++++++-- 3 files changed, 12 insertions(+), 9 deletions(-)v2: Push cap check into
msi_uninit(just like msix), remove check from
users.hw/ide/ich.c +1
-4@@ -110,10 +110,7 @@ static int pci_ich9_uninit(PCIDevice *dev)struct AHCIPCIState *d; d = DO_UPCAST(struct AHCIPCIState, card, dev); -if (msi_enabled (dev)) { -msi_uninit (dev); - } - +msi_uninit (dev);qemu_unregister_reset (ahci_reset, d);ahci_uninit (&d->ahci);hw/intel-hda.c +1
-3@@ -1174,9 +1174,7 @@ static int intel_hda_exit(PCIDevice *pci) {IntelHDAState *d =DO_UPCAST (IntelHDAState, pci, pci); -if (d->msi) { -msi_uninit (&d->pci); - } +msi_uninit (&d->pci);cpu_unregister_io_memory (d->mmio_addr);return 0 ; }hw/msi.c +10
-2@@ -183,9 +183,17 @@ int msi_init(struct PCIDevice *dev, uint8_t offset,void msi_uninit (struct PCIDevice *dev) { -uint16_t flags =pci_get_word (dev->config +msi_flags_off (dev)); -uint8_t cap_size =msi_cap_sizeof (flags); +uint16_t flags; +uint8_t cap_size; + +if (!(dev->cap_present &QEMU_PCI_CAP_MSI )) { +return ; + } + flags =pci_get_word (dev->config +msi_flags_off (dev)); + cap_size =msi_cap_sizeof (flags);pci_del_capability (dev,PCI_CAP_ID_MSIX , cap_size); + dev->cap_present &= ~QEMU_PCI_CAP_MSI ; +MSI_DEV_PRINTF (dev,"uninit\n" ); }Signature · 1 line
1.7.1