On Tue, 2015-06-09 at 11:37 +0800, Chen Fan wrote: > Signed-off-by: Chen Fan <chen.fan.f...@cn.fujitsu.com> > --- > hw/vfio/common.c | 12 ++++++++++++ > include/hw/vfio/vfio-common.h | 1 + > 2 files changed, 13 insertions(+) > > diff --git a/hw/vfio/common.c b/hw/vfio/common.c > index 4230f83..eff1930 100644 > --- a/hw/vfio/common.c > +++ b/hw/vfio/common.c > @@ -832,6 +832,7 @@ VFIOGroup *vfio_get_group(int groupid, AddressSpace *as) > goto close_fd_exit; > } > > + group->ref = 0; > group->groupid = groupid; > QLIST_INIT(&group->device_list); > > @@ -865,6 +866,15 @@ void vfio_put_group(VFIOGroup *group) > return; > } > > + if (group->ref) { > + if (QLIST_EMPTY(&group->device_list)) { > + if (group->container) { > + vfio_disconnect_container(group); > + } > + } > + return; > + }
Once we disconnect the container, our file descriptor for the group isn't sufficient for a bus reset. > + > vfio_kvm_device_del_group(group); > if (group->container) { > vfio_disconnect_container(group); > @@ -901,6 +911,7 @@ int vfio_get_device(VFIOGroup *group, const char *name, > return ret; > } > > + group->ref++; > vbasedev->fd = fd; > vbasedev->group = group; > QLIST_INSERT_HEAD(&group->device_list, vbasedev, next); > @@ -921,6 +932,7 @@ void vfio_put_base_device(VFIODevice *vbasedev) > if (!vbasedev->group) { > return; > } > + vbasedev->group->ref--; > QLIST_REMOVE(vbasedev, next); > vbasedev->group = NULL; > trace_vfio_put_base_device(vbasedev->fd); > diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h > index 0d1fb80..3eb042e 100644 > --- a/include/hw/vfio/vfio-common.h > +++ b/include/hw/vfio/vfio-common.h > @@ -117,6 +117,7 @@ struct VFIODeviceOps { > typedef struct VFIOGroup { > int fd; > int groupid; > + int ref; > VFIOContainer *container; > QLIST_HEAD(, VFIODevice) device_list; > QLIST_ENTRY(VFIOGroup) next;