From: Alex Williamson <alex.williamson@redhat.com>
To: Vijay Mohan Pandarathil <vijaymohan.pandarathil@hp.com>
Cc: gleb@redhat.com, bhelgaas@google.com, blauwirbel@gmail.com,
lance.oritz@hp.com, kvm@vger.kernel.org, qemu-devel@nongnu.org,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 1/3] VFIO: Wrapper for getting reference to vfio_device from device
Date: Mon, 25 Feb 2013 08:33:43 -0700 [thread overview]
Message-ID: <1361806423.2532.26.camel@bling.home> (raw)
In-Reply-To: <1361683516-31946-2-git-send-email-vijaymohan.pandarathil@hp.com>
On Sat, 2013-02-23 at 23:25 -0600, Vijay Mohan Pandarathil wrote:
> - Added vfio_device_get_from_dev() as wrapper to get
> reference to vfio_device from struct device.
>
> - Added vfio_device_data() as a wrapper to get device_data from
> vfio_device.
>
> Signed-off-by: Vijay Mohan Pandarathil <vijaymohan.pandarathil@hp.com>
> ---
> drivers/vfio/vfio.c | 47 ++++++++++++++++++++++++++++++++++-------------
> include/linux/vfio.h | 3 +++
> 2 files changed, 37 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
> index 12c264d..863d1d3 100644
> --- a/drivers/vfio/vfio.c
> +++ b/drivers/vfio/vfio.c
> @@ -407,12 +407,13 @@ static void vfio_device_release(struct kref *kref)
> }
>
> /* Device reference always implies a group reference */
> -static void vfio_device_put(struct vfio_device *device)
> +void vfio_device_put(struct vfio_device *device)
> {
> struct vfio_group *group = device->group;
> kref_put_mutex(&device->kref, vfio_device_release, &group->device_lock);
> vfio_group_put(group);
> }
> +EXPORT_SYMBOL_GPL(vfio_device_put);
>
> static void vfio_device_get(struct vfio_device *device)
> {
> @@ -642,8 +643,12 @@ int vfio_add_group_dev(struct device *dev,
> }
> EXPORT_SYMBOL_GPL(vfio_add_group_dev);
>
> -/* Test whether a struct device is present in our tracking */
> -static bool vfio_dev_present(struct device *dev)
> +/**
> + * This does a get on the vfio_device from device.
> + * Callers of this function will have to call vfio_put_device() to
> + * remove the reference.
> + */
> +struct vfio_device *vfio_device_get_from_dev(struct device *dev)
> {
I cc'd you on a patch that changes vfio_dev_present to fix a bug where
the device to iommu group lookup has been shutdown. Using it for this
purpose probably has the same bug. That code is in my next branch and
in the most reset pull request to Linus.
I think instead the code becomes much more simple. We're registering a
callback for a struct device for which vfio-pci is the driver. During
driver release we disable that callback for the device. Thus during the
callback, we know the device is owned by vfio-pci, which means that the
drvdata has what we need. So I think vfio_device_get_from_dev() simply
becomes:
struct vfio_device *vfio_get_device_from_dev(struct device *dev)
{
struct vfio_device *device = dev_get_drvdata(dev);
vfio_device_get(device);
return device;
}
EXPORT_SYMBOL_GPL(vfio_get_device_from_dev);
Thanks,
Alex
> struct iommu_group *iommu_group;
> struct vfio_group *group;
> @@ -651,25 +656,41 @@ static bool vfio_dev_present(struct device *dev)
>
> iommu_group = iommu_group_get(dev);
> if (!iommu_group)
> - return false;
> + return NULL;
>
> group = vfio_group_get_from_iommu(iommu_group);
> if (!group) {
> iommu_group_put(iommu_group);
> - return false;
> + return NULL;
> }
>
> device = vfio_group_get_device(group, dev);
> - if (!device) {
> - vfio_group_put(group);
> - iommu_group_put(iommu_group);
> - return false;
> - }
> -
> - vfio_device_put(device);
> vfio_group_put(group);
> iommu_group_put(iommu_group);
> - return true;
> + return device;
> +}
> +EXPORT_SYMBOL_GPL(vfio_device_get_from_dev);
> +
> +/*
> + * Caller must hold a reference to the vfio_device
> + */
> +void *vfio_device_data(struct vfio_device *device)
> +{
> + return device->device_data;
> +}
> +EXPORT_SYMBOL_GPL(vfio_device_data);
> +
> +/* Test whether a struct device is present in our tracking */
> +static bool vfio_dev_present(struct device *dev)
> +{
> + struct vfio_device *device;
> +
> + device = vfio_device_get_from_dev(dev);
> + if (device) {
> + vfio_device_put(device);
> + return true;
> + } else
> + return false;
> }
>
> /*
> diff --git a/include/linux/vfio.h b/include/linux/vfio.h
> index ab9e862..ac8d488 100644
> --- a/include/linux/vfio.h
> +++ b/include/linux/vfio.h
> @@ -45,6 +45,9 @@ extern int vfio_add_group_dev(struct device *dev,
> void *device_data);
>
> extern void *vfio_del_group_dev(struct device *dev);
> +extern struct vfio_device *vfio_device_get_from_dev(struct device *dev);
> +extern void vfio_device_put(struct vfio_device *device);
> +extern void *vfio_device_data(struct vfio_device *device);
>
> /**
> * struct vfio_iommu_driver_ops - VFIO IOMMU driver callbacks
next prev parent reply other threads:[~2013-02-25 15:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-24 5:25 [PATCH v5 0/3] AER-KVM: Error containment of VFIO devices assigned to KVM guests Vijay Mohan Pandarathil
2013-02-24 5:25 ` [PATCH v5 1/3] VFIO: Wrapper for getting reference to vfio_device from device Vijay Mohan Pandarathil
2013-02-25 15:33 ` Alex Williamson [this message]
2013-02-24 5:25 ` [PATCH v5 2/3] VFIO-AER: Vfio-pci driver changes for supporting AER Vijay Mohan Pandarathil
2013-02-24 5:25 ` [PATCH v5 3/3] QEMU-AER: Qemu changes to support AER for VFIO-PCI devices Vijay Mohan Pandarathil
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=1361806423.2532.26.camel@bling.home \
--to=alex.williamson@redhat.com \
--cc=bhelgaas@google.com \
--cc=blauwirbel@gmail.com \
--cc=gleb@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=lance.oritz@hp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
--cc=vijaymohan.pandarathil@hp.com \
/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;
as well as URLs for NNTP newsgroup(s).