RE: [PATCH 7/8] kvm: qemu: deassign device from guest

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Marcelo Tosatti wrote:
> Weidong,
> 
> Does this set fix
> 
> http://sourceforge.net/tracker2/?func=detail&aid=2432316&group_id=180599&atid=893831
> 

I found above bug was already gone even without my patch. I guess it's fixed by Mark:

commit: 02874f4272b6787ff94ee7256ef083257b9d1eb1
Author: Mark McLoughlin <markmc@xxxxxxxxxx>
Date:   Fri Nov 28 17:10:47 2008 +0000

    kvm: qemu: device-assignment: free device if hotplug fails
    
    Signed-off-by: Mark McLoughlin <markmc@xxxxxxxxxx>
    Signed-off-by: Avi Kivity <avi@xxxxxxxxxx>


Actually, my patch just moves free_assigned_device into init_assigned_device, no functional change. But I updated the patch to also call free_assigned_device when pci_register_device fails in init_assigned_device, because adev is allocated by qemu_mallocz in add_assigned_device.

>From ce48b0d6c636d8f49bc5977d1d144fa047273846 Mon Sep 17 00:00:00 2001
From: Weidong Han <weidong.han@xxxxxxxxx>
Date: Thu, 19 Feb 2009 10:49:30 +0800
Subject: [PATCH] kvm: qemu: free device on error in init_assigned_device

make init_assigned_device call free_assigned_device on error,
and then make free_assigned_device is static because it's only
invoked in device-assigned.c.

Acked-by: Mark McLoughlin <markmc@xxxxxxxxxx>
Signed-off-by: Weidong Han <weidong.han@xxxxxxxxx>
---
 qemu/hw/device-assignment.c |   14 +++++++++-----
 qemu/hw/device-assignment.h |    1 -
 qemu/hw/pci-hotplug.c       |    1 -
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/qemu/hw/device-assignment.c b/qemu/hw/device-assignment.c
index e6d2352..0b96ee4 100644
--- a/qemu/hw/device-assignment.c
+++ b/qemu/hw/device-assignment.c
@@ -443,7 +443,7 @@ again:
 
 static LIST_HEAD(, AssignedDevInfo) adev_head;
 
-void free_assigned_device(AssignedDevInfo *adev)
+static void free_assigned_device(AssignedDevInfo *adev)
 {
     AssignedDevice *dev = adev->assigned_dev;
 
@@ -550,7 +550,7 @@ struct PCIDevice *init_assigned_device(AssignedDevInfo *adev, PCIBus *bus)
     if (NULL == dev) {
         fprintf(stderr, "%s: Error: Couldn't register real device %s\n",
                 __func__, adev->name);
-        return NULL;
+        goto out;
     }
 
     adev->assigned_dev = dev;
@@ -558,14 +558,14 @@ struct PCIDevice *init_assigned_device(AssignedDevInfo *adev, PCIBus *bus)
     if (get_real_device(dev, adev->bus, adev->dev, adev->func)) {
         fprintf(stderr, "%s: Error: Couldn't get real device (%s)!\n",
                 __func__, adev->name);
-        return NULL;
+        goto out;
     }
 
     /* handle real device's MMIO/PIO BARs */
     if (assigned_dev_register_regions(dev->real_device.regions,
                                       dev->real_device.region_number,
                                       dev))
-        return NULL;
+        goto out;
 
     /* handle interrupt routing */
     e_device = (dev->dev.devfn >> 3) & 0x1f;
@@ -595,10 +595,14 @@ struct PCIDevice *init_assigned_device(AssignedDevInfo *adev, PCIBus *bus)
     if (r < 0) {
 	fprintf(stderr, "Failed to assign device \"%s\" : %s\n",
                 adev->name, strerror(-r));
-	return NULL;
+	goto out;
     }
 
     return &dev->dev;
+
+out:
+    free_assigned_device(adev);
+    return NULL;
 }
 
 /*
diff --git a/qemu/hw/device-assignment.h b/qemu/hw/device-assignment.h
index f216bb0..6a9b9fa 100644
--- a/qemu/hw/device-assignment.h
+++ b/qemu/hw/device-assignment.h
@@ -94,7 +94,6 @@ struct AssignedDevInfo {
     int disable_iommu;
 };
 
-void free_assigned_device(AssignedDevInfo *adev);
 PCIDevice *init_assigned_device(AssignedDevInfo *adev, PCIBus *bus);
 AssignedDevInfo *add_assigned_device(const char *arg);
 void add_assigned_devices(PCIBus *bus, const char **devices, int n_devices);
diff --git a/qemu/hw/pci-hotplug.c b/qemu/hw/pci-hotplug.c
index 8c76453..65fafd1 100644
--- a/qemu/hw/pci-hotplug.c
+++ b/qemu/hw/pci-hotplug.c
@@ -143,7 +143,6 @@ static PCIDevice *qemu_pci_hot_assign_device(PCIBus *pci_bus, const char *opts)
     ret = init_assigned_device(adev, pci_bus);
     if (ret == NULL) {
         term_printf("Failed to assign device\n");
-        free_assigned_device(adev);
         return NULL;
     }
 
-- 
1.6.0.4



> 
> On Wed, Feb 18, 2009 at 03:13:05PM +0800, Han, Weidong wrote:
>> free_assigned_device just frees device from qemu, it should also
>> deassign the device from guest when guest exits or hot remove
>> assigned device. 
>> 
>> Acked-by: Mark McLoughlin <markmc@xxxxxxxxxx>
>> Signed-off-by: Weidong Han <weidong.han@xxxxxxxxx>
>> ---
>>  qemu/hw/device-assignment.c |   28 ++++++++++++++++++++++++++--
>>  qemu/hw/device-assignment.h |    1 +
>>  2 files changed, 27 insertions(+), 2 deletions(-)

Attachment: 0003-kvm-qemu-free-device-on-error-in-init_assigned_dev-v2.patch
Description: 0003-kvm-qemu-free-device-on-error-in-init_assigned_dev-v2.patch


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux