qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] MSI: Fix release of resources
@ 2011-05-02  9:13 Jan Kiszka
  2011-05-02 18:00 ` [Qemu-devel] [PATCH v2] MSI: Robust resource release Jan Kiszka
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Kiszka @ 2011-05-02  9:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alexander Graf, Gerd Hoffmann

msi_init may fail, so the users should check msi_present before calling
msi_uninit.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 hw/ide/ich.c   |    2 +-
 hw/intel-hda.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/ide/ich.c b/hw/ide/ich.c
index a3d475c..35e1de7 100644
--- a/hw/ide/ich.c
+++ b/hw/ide/ich.c
@@ -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);
     }
 
diff --git a/hw/intel-hda.c b/hw/intel-hda.c
index b0b1d12..ff99348 100644
--- a/hw/intel-hda.c
+++ b/hw/intel-hda.c
@@ -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);
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH v2] MSI: Robust resource release
  2011-05-02  9:13 [Qemu-devel] [PATCH] MSI: Fix release of resources Jan Kiszka
@ 2011-05-02 18:00 ` Jan Kiszka
  2011-05-03 10:16   ` Alexander Graf
  2011-05-05 13:10   ` Michael S. Tsirkin
  0 siblings, 2 replies; 4+ messages in thread
From: Jan Kiszka @ 2011-05-02 18:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael S. Tsirkin, Alexander Graf, Gerd Hoffmann

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.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 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.

diff --git a/hw/ide/ich.c b/hw/ide/ich.c
index a3d475c..8c1ff6c 100644
--- a/hw/ide/ich.c
+++ b/hw/ide/ich.c
@@ -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);
 
diff --git a/hw/intel-hda.c b/hw/intel-hda.c
index b0b1d12..093c4b9 100644
--- a/hw/intel-hda.c
+++ b/hw/intel-hda.c
@@ -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;
 }
diff --git a/hw/msi.c b/hw/msi.c
index 0cbf89f..3141804 100644
--- a/hw/msi.c
+++ b/hw/msi.c
@@ -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");
 }
 
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH v2] MSI: Robust resource release
  2011-05-02 18:00 ` [Qemu-devel] [PATCH v2] MSI: Robust resource release Jan Kiszka
@ 2011-05-03 10:16   ` Alexander Graf
  2011-05-05 13:10   ` Michael S. Tsirkin
  1 sibling, 0 replies; 4+ messages in thread
From: Alexander Graf @ 2011-05-03 10:16 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: Michael S. Tsirkin, qemu-devel, Gerd Hoffmann


On 02.05.2011, at 20:00, Jan Kiszka wrote:

> 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.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>

Looks good to me.

Acked-by: Alexander Graf <agraf@suse.de>


Alex

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH v2] MSI: Robust resource release
  2011-05-02 18:00 ` [Qemu-devel] [PATCH v2] MSI: Robust resource release Jan Kiszka
  2011-05-03 10:16   ` Alexander Graf
@ 2011-05-05 13:10   ` Michael S. Tsirkin
  1 sibling, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2011-05-05 13:10 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: Gerd Hoffmann, qemu-devel, Alexander Graf

On Mon, May 02, 2011 at 08:00:47PM +0200, Jan Kiszka wrote:
> 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.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>

Applied, thanks!

> ---
>  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.
> 
> diff --git a/hw/ide/ich.c b/hw/ide/ich.c
> index a3d475c..8c1ff6c 100644
> --- a/hw/ide/ich.c
> +++ b/hw/ide/ich.c
> @@ -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);
>  
> diff --git a/hw/intel-hda.c b/hw/intel-hda.c
> index b0b1d12..093c4b9 100644
> --- a/hw/intel-hda.c
> +++ b/hw/intel-hda.c
> @@ -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;
>  }
> diff --git a/hw/msi.c b/hw/msi.c
> index 0cbf89f..3141804 100644
> --- a/hw/msi.c
> +++ b/hw/msi.c
> @@ -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");
>  }
>  
> -- 
> 1.7.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-05-05 13:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-02  9:13 [Qemu-devel] [PATCH] MSI: Fix release of resources Jan Kiszka
2011-05-02 18:00 ` [Qemu-devel] [PATCH v2] MSI: Robust resource release Jan Kiszka
2011-05-03 10:16   ` Alexander Graf
2011-05-05 13:10   ` Michael S. Tsirkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).