Commit Graph

10 Commits

Author SHA1 Message Date
Gerd Hoffmann 59a5b0f7bf virtio-pci: alloc only resources actually used.
Move resource allocation from common code to legacy and modern code.
Only request resources actually used, i.e. bar0 in legacy mode and
the bar(s) specified by capabilities in modern mode.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2015-06-24 08:15:09 +02:00
Michael S. Tsirkin ff31d2e285 virtio_pci: move probe/remove code to common
Most of initialization is device-independent.
Let's move it to common.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-01-21 16:28:51 +10:30
Sasha Levin 2bd56afd44 virtio_pci: drop useless del_vqs call
Device VQs were getting freed twice: once in every device's removal
functions, and then again in virtio_pci_legacy_remove().  The ones in
devices are called first, so drop the useless second call.

Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-01-21 16:28:50 +10:30
Michael S. Tsirkin a1eb03f546 virtio_pci: document why we defer kfree
The reason we defer kfree until release function is because it's a
general rule for kobjects: kfree of the reference counter itself is only
legal in the release function.

Previous patch didn't make this clear, document this in code.

Cc: stable@vger.kernel.org
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2015-01-06 16:35:36 +02:00
Sasha Levin 63bd62a08c virtio_pci: defer kfree until release callback
A struct device which has just been unregistered can live on past the
point at which a driver decides to drop it's initial reference to the
kobject gained on allocation.

This implies that 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().

Unfortunately, this is exactly what virtio pci does:
it has an empty release callback, and frees memory immediately
after unregistering the device.

This causes an easy to reproduce crash if CONFIG_DEBUG_KOBJECT_RELEASE
it enabled.

To fix, free the memory only once we know the device is gone in the release
callback.

Cc: stable@vger.kernel.org
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2015-01-06 16:35:36 +02:00
Michael S. Tsirkin 945399a8c7 virtio_pci: device-specific release callback
It turns out we need to add device-specific code
in release callback. Move it to virtio_pci_legacy.c.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2015-01-06 16:35:36 +02:00
Michael S. Tsirkin 9a4253db0c virtio_pci: move probe to common file
It turns out this make everything easier.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2014-12-14 15:10:30 +02:00
Michael S. Tsirkin 5f4c976089 virtio_pci: rename virtio_pci -> virtio_pci_common
kbuild does not seem to like it when we name source
files same as the module.
Let's rename virtio_pci -> virtio_pci_common,
and get rid of #include-ing c files.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2014-12-09 21:42:05 +02:00
Michael S. Tsirkin a90fdce9dc virtio_pci: update file descriptions and copyright
There's been a lot of changes since 2007.
List main authors, add Red Hat copyright.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2014-12-09 21:42:05 +02:00
Michael S. Tsirkin 38eb4a29a7 virtio_pci: split out legacy device support
Move everything dealing with legacy devices out to virtio_pci_legacy.c.
Expose common code APIs in virtio_pci.h

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2014-12-09 21:42:04 +02:00