Skip to content

Commit 8115857

Browse files
chejianjwenlingz
authored andcommitted
dm: pci: unregister bars which are still enabled in pci_emul_free_bars
Guest OS for example Windows will disable bars before shutdown. Bars are unregistered when they are disabled. Trying to unregister a bar which has been unregistered causes a assertion. In pci_emul_free_bars only those enabled bars should be unregistered. Tracked-On: #2962 Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com> Acked-by: Yin Fengwei <fengwei.yin@intel.com>
1 parent fd389cb commit 8115857

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

devicemodel/hw/pci/core.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,12 +703,23 @@ pci_emul_alloc_pbar(struct pci_vdev *pdi, int idx, uint64_t hostbase,
703703
void
704704
pci_emul_free_bars(struct pci_vdev *pdi)
705705
{
706-
int i;
706+
int i, enabled;
707707

708708
for (i = 0; i < PCI_BARMAX; i++) {
709709
if ((pdi->bar[i].type != PCIBAR_NONE) &&
710710
(pdi->bar[i].type != PCIBAR_MEMHI64)){
711-
unregister_bar(pdi, i);
711+
/*
712+
* Check whether the bar is enabled or not,
713+
* if it is disabled then it should have been
714+
* unregistered in pci_emul_cmdsts_write.
715+
*/
716+
if (pdi->bar[i].type == PCIBAR_IO)
717+
enabled = porten(pdi);
718+
else
719+
enabled = memen(pdi);
720+
721+
if (enabled)
722+
unregister_bar(pdi, i);
712723
pdi->bar[i].type = PCIBAR_NONE;
713724
}
714725
}

0 commit comments

Comments
 (0)