Skip to content
  • Peter Xu's avatar
    d25836ca
    memory: do explicit cleanup when remove listeners · d25836ca
    Peter Xu authored
    When unregister memory listeners, we should call, e.g.,
    region_del() (and possibly other undo operations) on every existing
    memory region sections there, otherwise we may leak resources that are
    held during the region_add(). This patch undo the stuff for the
    listeners, which emulates the case when the address space is set from
    current to an empty state.
    
    I found this problem when debugging a refcount leak issue that leads to
    a device unplug event lost (please see the "Bug:" line below).  In that
    case, the leakage of resource is the PCI BAR memory region refcount.
    And since memory regions are not keeping their own refcount but onto
    their owners, so the vfio-pci device's (who is the owner of the PCI BAR
    memory regions) refcount is leaked, and event missing.
    
    We had encountered similar issues before and fixed in other
    way (ee4c1128, "vhost: Release memory references on cleanup"). This
    patch can be seen as a more high-level fix of similar problems that are
    caused by the resource leaks from memory listeners. So now we can remove
    the explicit unref of memory regions since that'll be done altogether
    during unregistering of listeners now.
    
    Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1531393
    
    
    Signed-off-by: default avatarPeter Xu <peterx@redhat.com>
    Message-Id: <20180122060244.29368-5-peterx@redhat.com>
    Reviewed-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    d25836ca
    memory: do explicit cleanup when remove listeners
    Peter Xu authored
    When unregister memory listeners, we should call, e.g.,
    region_del() (and possibly other undo operations) on every existing
    memory region sections there, otherwise we may leak resources that are
    held during the region_add(). This patch undo the stuff for the
    listeners, which emulates the case when the address space is set from
    current to an empty state.
    
    I found this problem when debugging a refcount leak issue that leads to
    a device unplug event lost (please see the "Bug:" line below).  In that
    case, the leakage of resource is the PCI BAR memory region refcount.
    And since memory regions are not keeping their own refcount but onto
    their owners, so the vfio-pci device's (who is the owner of the PCI BAR
    memory regions) refcount is leaked, and event missing.
    
    We had encountered similar issues before and fixed in other
    way (ee4c1128, "vhost: Release memory references on cleanup"). This
    patch can be seen as a more high-level fix of similar problems that are
    caused by the resource leaks from memory listeners. So now we can remove
    the explicit unref of memory regions since that'll be done altogether
    during unregistering of listeners now.
    
    Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1531393
    
    
    Signed-off-by: default avatarPeter Xu <peterx@redhat.com>
    Message-Id: <20180122060244.29368-5-peterx@redhat.com>
    Reviewed-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Loading