From f0b74016d1542dac6c9ffe779b21584c902857a8 Mon Sep 17 00:00:00 2001 From: Yin Fengwei Date: Fri, 30 Mar 2018 12:16:26 +0800 Subject: [PATCH] DM: release mmio data structure for pci bar We didn't release mmio/io data structure related with PCI bar of pci dev. Which could trigger memory leak when reboot UOS. With the new patch, we release the mmio/io data structure when pci core tries to deinit pci device. Signed-off-by: Yin Fengwei Acked-by: Eddie Dong --- devicemodel/hw/pci/core.c | 16 ++++++++++++++++ devicemodel/include/pci_core.h | 1 + 2 files changed, 17 insertions(+) diff --git a/devicemodel/hw/pci/core.c b/devicemodel/hw/pci/core.c index cffcc580e..b28b00088 100644 --- a/devicemodel/hw/pci/core.c +++ b/devicemodel/hw/pci/core.c @@ -665,6 +665,20 @@ pci_emul_alloc_pbar(struct pci_vdev *pdi, int idx, uint64_t hostbase, return 0; } +void +pci_emul_free_bars(struct pci_vdev *pdi) +{ + int i; + + for (i = 0; i < PCI_BARMAX; i++) { + if ((pdi->bar[i].type != PCIBAR_NONE) && + (pdi->bar[i].type != PCIBAR_MEMHI64)){ + unregister_bar(pdi, i); + pdi->bar[i].type = PCIBAR_NONE; + } + } +} + #define CAP_START_OFFSET 0x40 int pci_emul_add_capability(struct pci_vdev *dev, u_char *capdata, int caplen) @@ -772,6 +786,8 @@ pci_emul_deinit(struct vmctx *ctx, struct pci_vdev_ops *ops, int bus, int slot, (*ops->vdev_deinit)(ctx, fi->fi_devi, fi->fi_param); if (fi->fi_param) free(fi->fi_param); + + pci_emul_free_bars(fi->fi_devi); if (fi->fi_devi) free(fi->fi_devi); } diff --git a/devicemodel/include/pci_core.h b/devicemodel/include/pci_core.h index 3a02d203a..3d8088e16 100644 --- a/devicemodel/include/pci_core.h +++ b/devicemodel/include/pci_core.h @@ -230,6 +230,7 @@ int pci_emul_alloc_bar(struct pci_vdev *pdi, int idx, int pci_emul_alloc_pbar(struct pci_vdev *pdi, int idx, uint64_t hostbase, enum pcibar_type type, uint64_t size); +void pci_emul_free_bars(struct pci_vdev *pdi); int pci_emul_add_capability(struct pci_vdev *dev, u_char *capdata, int caplen); int pci_emul_add_msicap(struct pci_vdev *pi, int msgnum);