From: Sasha Levin <sasha.levin@oracle.com>
To: linux-kernel@vger.kernel.org
Cc: Sasha Levin <sasha.levin@oracle.com>,
Rusty Russell <rusty@rustcorp.com.au>,
"Michael S. Tsirkin" <mst@redhat.com>,
virtualization@lists.linux-foundation.org (open list:VIRTIO CORE,
NET...)
Subject: [PATCH 2/2] virtio: don't free memory until the underlying struct device has been released
Date: Fri, 2 Jan 2015 14:47:40 -0500 [thread overview]
Message-ID: <1420228060-18721-2-git-send-email-sasha.levin@oracle.com> (raw)
In-Reply-To: <1420228060-18721-1-git-send-email-sasha.levin@oracle.com>
When releasing a virtio device, We can't free a struct virtio_device until the
underlying struct device has been released, which might not happen immediately
on device_unregister() even if that was the device's last reference.
Instead, free the memory only once we know the device is gone in the release
callback.
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
---
drivers/virtio/virtio_pci_common.c | 9 ++++-----
drivers/virtio/virtio_pci_legacy.c | 1 -
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
index 59d3685..caa483d 100644
--- a/drivers/virtio/virtio_pci_common.c
+++ b/drivers/virtio/virtio_pci_common.c
@@ -423,11 +423,10 @@ int vp_set_vq_affinity(struct virtqueue *vq, int cpu)
void virtio_pci_release_dev(struct device *_d)
{
- /*
- * No need for a release method as we allocate/free
- * all devices together with the pci devices.
- * Provide an empty one to avoid getting a warning from core.
- */
+ struct virtio_device *vdev = dev_to_virtio(_d);
+ struct virtio_pci_device *vp_dev = to_vp_device(vdev);
+
+ kfree(vp_dev);
}
#ifdef CONFIG_PM_SLEEP
diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
index 913ca23..15e6e6d 100644
--- a/drivers/virtio/virtio_pci_legacy.c
+++ b/drivers/virtio/virtio_pci_legacy.c
@@ -301,5 +301,4 @@ void virtio_pci_legacy_remove(struct pci_dev *pci_dev)
pci_iounmap(pci_dev, vp_dev->ioaddr);
pci_release_regions(pci_dev);
pci_disable_device(pci_dev);
- kfree(vp_dev);
}
--
1.7.10.4
next prev parent reply other threads:[~2015-01-02 19:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-02 19:47 [PATCH 1/2] virtio_pci: double free and invalid memory access of device vqs Sasha Levin
2015-01-02 19:47 ` Sasha Levin [this message]
2015-01-04 11:26 ` [PATCH 2/2] virtio: don't free memory until the underlying struct device has been released Michael S. Tsirkin
2015-01-04 15:03 ` Sasha Levin
2015-01-04 15:40 ` Michael S. Tsirkin
2015-01-04 11:12 ` [PATCH 1/2] virtio_pci: double free and invalid memory access of device vqs Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1420228060-18721-2-git-send-email-sasha.levin@oracle.com \
--to=sasha.levin@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=rusty@rustcorp.com.au \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®