From mboxrd@z Thu Jan 1 00:00:00 1970 From: Amit Shah Subject: Re: [PATCH 0/2] Fix hot-unplug: device removal while port in use Date: Fri, 11 Mar 2011 16:46:28 +0530 Message-ID: <20110311111628.GC8908@amit-x200.redhat.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: virtualization-bounces@lists.linux-foundation.org Errors-To: virtualization-bounces@lists.linux-foundation.org To: Virtualization List Cc: markmc@redhat.com, "Michael S. Tsirkin" List-Id: virtualization@lists.linuxfoundation.org On (Wed) 02 Mar 2011 [13:53:06], Amit Shah wrote: > The second patch fixes a warning where the pci region is already > freed. I'm not sure what or how the region gets freed, any clues > there will be helpful. OK, so in the case where a virtio-console port is in use (opened by a program) and a virtio-console device is removed, the port is kept around but all the virtio-related state is assumed to be gone. When the port is finally released (close() called), we call device_destroy() on the port's device. This results in the parent device's structures to be freed as well. This includes the PCI regions for the virtio-console PCI device. Once this is done, however, virtio_pci_release_dev() kicks in, as the last ref to the virtio device is now gone, and attempts to do pci_iounmap(pci_dev, vp_dev->ioaddr); pci_release_regions(pci_dev); pci_disable_device(pci_dev); which results in the double-free warning. Ideally virtio_pci_release_dev() shouldn't be needed at all; all that work can be moved to virtio_pci_remove(). virtio_pci_release_dev() was added in 29f9f12e to curb a warning: virtio: add PCI device release() function Add a release() function for virtio_pci devices so as to avoid: Device 'virtio0' does not have a release() function, it is broken and must be fixed So we could have an empty release() function that does nothing, and all of the current functionality be moved to virtio_pci_remove(), as it was earlier. This should keep everyone happy. Is that fine? Amit