From: Jike Song <jike.song@intel.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: pbonzini@redhat.com, guangrong.xiao@linux.intel.com,
kwankhede@nvidia.com, cjia@nvidia.com, kevin.tian@intel.com,
kvm@vger.kernel.org
Subject: Re: [v8 1/3] vfio: vfio_register_notifier: classify iommu notifier
Date: Fri, 02 Dec 2016 10:07:13 +0800 [thread overview]
Message-ID: <5840D751.7050908@intel.com> (raw)
In-Reply-To: <20161201104529.0c1f8381@t450s.home>
On 12/02/2016 01:45 AM, Alex Williamson wrote:
> On Thu, 1 Dec 2016 09:22:33 -0700
> Alex Williamson <alex.williamson@redhat.com> wrote:
>
>> On Thu, 1 Dec 2016 09:21:22 -0700
>> Alex Williamson <alex.williamson@redhat.com> wrote:
>>
>>> On Thu, 1 Dec 2016 13:20:05 +0800
>>> Jike Song <jike.song@intel.com> wrote:
>>>
>>>> Currently vfio_register_notifier assumes that there is only one
>>>> notifier chain, which is in vfio_iommu. However, the user might
>>>> also be interested in events other than vfio_iommu, for example,
>>>> vfio_group. Refactor vfio_{un}register_notifier implementation
>>>> to make it feasible.
>>>>
>>>> Cc: Alex Williamson <alex.williamson@redhat.com>
>>>> Cc: Paolo Bonzini <pbonzini@redhat.com>
>>>> Cc: Xiao Guangrong <guangrong.xiao@linux.intel.com>
>>>> Reviewed-by: Kirti Wankhede <kwankhede@nvidia.com>
>>>> Signed-off-by: Jike Song <jike.song@intel.com>
>>>> ---
>>>> drivers/vfio/vfio.c | 85 +++++++++++++++++++++++++++++------------
>>>> drivers/vfio/vfio_iommu_type1.c | 8 ++++
>>>> include/linux/vfio.h | 17 +++++++--
>>>> 3 files changed, 82 insertions(+), 28 deletions(-)
>>>
>>> I'm making the following fixup to merge this with Christophe's patch
>>> found here https://lkml.org/lkml/2016/11/30/57
>>
>> Whoops, somehow that got sent before I added the changes:
>
> checkpatch.pl also complains about adding new typedefs, so perhaps
> vfio_notify_type_t is not way to go. This is the patch as I have it
> now, I've also updated 2/3 to remove the typedef there. If there are
> no objections, this is what I'll go with. Thanks,
Thanks for the fixup! I actually saw the checkpatch.pl warning about
new typedef but scrupled to remove it :-)
--
Thanks,
Jike
>
> commit 22195cbd3451a75abaf30651a61cf85c89061327
> Author: Jike Song <jike.song@intel.com>
> Date: Thu Dec 1 13:20:05 2016 +0800
>
> vfio: vfio_register_notifier: classify iommu notifier
>
> Currently vfio_register_notifier assumes that there is only one
> notifier chain, which is in vfio_iommu. However, the user might
> also be interested in events other than vfio_iommu, for example,
> vfio_group. Refactor vfio_{un}register_notifier implementation
> to make it feasible.
>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Xiao Guangrong <guangrong.xiao@linux.intel.com>
> Reviewed-by: Kirti Wankhede <kwankhede@nvidia.com>
> Signed-off-by: Jike Song <jike.song@intel.com>
> [aw: merge with commit 816ca69ea9c7 ("vfio: Fix handling of error returned by 'vfio_group_get_from_dev()'"), remove typedef]
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
>
> diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
> index 7b39313..6cc2a9f 100644
> --- a/drivers/vfio/vfio.c
> +++ b/drivers/vfio/vfio.c
> @@ -2008,59 +2008,44 @@ int vfio_unpin_pages(struct device *dev, unsigned long *user_pfn, int npage)
> }
> EXPORT_SYMBOL(vfio_unpin_pages);
>
> -int vfio_register_notifier(struct device *dev, struct notifier_block *nb)
> +static int vfio_register_iommu_notifier(struct vfio_group *group,
> + unsigned long *events,
> + struct notifier_block *nb)
> {
> struct vfio_container *container;
> - struct vfio_group *group;
> struct vfio_iommu_driver *driver;
> int ret;
>
> - if (!dev || !nb)
> - return -EINVAL;
> -
> - group = vfio_group_get_from_dev(dev);
> - if (!group)
> - return -ENODEV;
> -
> ret = vfio_group_add_container_user(group);
> if (ret)
> - goto err_register_nb;
> + return -EINVAL;
>
> container = group->container;
> down_read(&container->group_lock);
>
> driver = container->iommu_driver;
> if (likely(driver && driver->ops->register_notifier))
> - ret = driver->ops->register_notifier(container->iommu_data, nb);
> + ret = driver->ops->register_notifier(container->iommu_data,
> + events, nb);
> else
> ret = -ENOTTY;
>
> up_read(&container->group_lock);
> vfio_group_try_dissolve_container(group);
>
> -err_register_nb:
> - vfio_group_put(group);
> return ret;
> }
> -EXPORT_SYMBOL(vfio_register_notifier);
>
> -int vfio_unregister_notifier(struct device *dev, struct notifier_block *nb)
> +static int vfio_unregister_iommu_notifier(struct vfio_group *group,
> + struct notifier_block *nb)
> {
> struct vfio_container *container;
> - struct vfio_group *group;
> struct vfio_iommu_driver *driver;
> int ret;
>
> - if (!dev || !nb)
> - return -EINVAL;
> -
> - group = vfio_group_get_from_dev(dev);
> - if (!group)
> - return -ENODEV;
> -
> ret = vfio_group_add_container_user(group);
> if (ret)
> - goto err_unregister_nb;
> + return -EINVAL;
>
> container = group->container;
> down_read(&container->group_lock);
> @@ -2075,7 +2060,56 @@ int vfio_unregister_notifier(struct device *dev, struct notifier_block *nb)
> up_read(&container->group_lock);
> vfio_group_try_dissolve_container(group);
>
> -err_unregister_nb:
> + return ret;
> +}
> +
> +int vfio_register_notifier(struct device *dev, enum vfio_notify_type type,
> + unsigned long *events, struct notifier_block *nb)
> +{
> + struct vfio_group *group;
> + int ret;
> +
> + if (!dev || !nb || !events || (*events == 0))
> + return -EINVAL;
> +
> + group = vfio_group_get_from_dev(dev);
> + if (!group)
> + return -ENODEV;
> +
> + switch (type) {
> + case VFIO_IOMMU_NOTIFY:
> + ret = vfio_register_iommu_notifier(group, events, nb);
> + break;
> + default:
> + ret = -EINVAL;
> + }
> +
> + vfio_group_put(group);
> + return ret;
> +}
> +EXPORT_SYMBOL(vfio_register_notifier);
> +
> +int vfio_unregister_notifier(struct device *dev, enum vfio_notify_type type,
> + struct notifier_block *nb)
> +{
> + struct vfio_group *group;
> + int ret;
> +
> + if (!dev || !nb)
> + return -EINVAL;
> +
> + group = vfio_group_get_from_dev(dev);
> + if (!group)
> + return -ENODEV;
> +
> + switch (type) {
> + case VFIO_IOMMU_NOTIFY:
> + ret = vfio_unregister_iommu_notifier(group, nb);
> + break;
> + default:
> + ret = -EINVAL;
> + }
> +
> vfio_group_put(group);
> return ret;
> }
> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
> index 51810a9..b88ad1e 100644
> --- a/drivers/vfio/vfio_iommu_type1.c
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -1584,10 +1584,18 @@ static long vfio_iommu_type1_ioctl(void *iommu_data,
> }
>
> static int vfio_iommu_type1_register_notifier(void *iommu_data,
> + unsigned long *events,
> struct notifier_block *nb)
> {
> struct vfio_iommu *iommu = iommu_data;
>
> + /* clear known events */
> + *events &= ~VFIO_IOMMU_NOTIFY_DMA_UNMAP;
> +
> + /* refuse to register if still events remaining */
> + if (*events)
> + return -EINVAL;
> +
> return blocking_notifier_chain_register(&iommu->notifier, nb);
> }
>
> diff --git a/include/linux/vfio.h b/include/linux/vfio.h
> index 15ff042..0e5201f 100644
> --- a/include/linux/vfio.h
> +++ b/include/linux/vfio.h
> @@ -81,6 +81,7 @@ struct vfio_iommu_driver_ops {
> int (*unpin_pages)(void *iommu_data,
> unsigned long *user_pfn, int npage);
> int (*register_notifier)(void *iommu_data,
> + unsigned long *events,
> struct notifier_block *nb);
> int (*unregister_notifier)(void *iommu_data,
> struct notifier_block *nb);
> @@ -107,12 +108,20 @@ extern int vfio_pin_pages(struct device *dev, unsigned long *user_pfn,
> extern int vfio_unpin_pages(struct device *dev, unsigned long *user_pfn,
> int npage);
>
> -#define VFIO_IOMMU_NOTIFY_DMA_UNMAP (1)
> +/* each type has independent events */
> +enum vfio_notify_type {
> + VFIO_IOMMU_NOTIFY = 0,
> +};
> +
> +/* events for VFIO_IOMMU_NOTIFY */
> +#define VFIO_IOMMU_NOTIFY_DMA_UNMAP BIT(0)
>
> extern int vfio_register_notifier(struct device *dev,
> + enum vfio_notify_type type,
> + unsigned long *required_events,
> struct notifier_block *nb);
> -
> extern int vfio_unregister_notifier(struct device *dev,
> + enum vfio_notify_type type,
> struct notifier_block *nb);
>
> /*
>
next prev parent reply other threads:[~2016-12-02 2:07 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-01 5:20 [v8 0/3] plumb kvm/vfio to notify kvm:group attach/detach Jike Song
2016-12-01 5:20 ` [v8 1/3] vfio: vfio_register_notifier: classify iommu notifier Jike Song
2016-12-01 16:21 ` Alex Williamson
2016-12-01 16:22 ` Alex Williamson
2016-12-01 17:45 ` Alex Williamson
2016-12-02 2:07 ` Jike Song [this message]
2016-12-01 5:20 ` [v8 2/3] vfio: support notifier chain in vfio_group Jike Song
2016-12-01 5:20 ` [v8 3/3] kvm: set/clear kvm to/from vfio_group when group add/delete Jike Song
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=5840D751.7050908@intel.com \
--to=jike.song@intel.com \
--cc=alex.williamson@redhat.com \
--cc=cjia@nvidia.com \
--cc=guangrong.xiao@linux.intel.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=kwankhede@nvidia.com \
--cc=pbonzini@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.