From: Alex Williamson <alex.williamson@redhat.com>
To: Jike Song <jike.song@intel.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: [v4 1/3] vfio: add vfio_group_notify support
Date: Tue, 15 Nov 2016 16:11:20 -0700 [thread overview]
Message-ID: <20161115161120.43d1aef8@t450s.home> (raw)
In-Reply-To: <1479209747-5564-2-git-send-email-jike.song@intel.com>
On Tue, 15 Nov 2016 19:35:45 +0800
Jike Song <jike.song@intel.com> wrote:
> A vfio_group may be or may not be attached to a KVM instance,
> if it is, the user of vfio_group might also want to know which
> KVM instance it is attached to, and when it will detach. In VFIO
> there are already external APIs for KVM to get/put vfio_group,
> by providing a similar vfio_group_notify, KVM can notify the
> vfio_group about attaching events.
>
> Cc: Xiao Guangrong <guangrong.xiao@linux.intel.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Alex Williamson <alex.williamson@redhat.com>
> Signed-off-by: Jike Song <jike.song@intel.com>
> ---
> drivers/vfio/vfio.c | 30 ++++++++++++++++++++++++++++++
> include/linux/vfio.h | 4 ++++
> 2 files changed, 34 insertions(+)
>
> diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
> index 0afb58e..b149ced 100644
> --- a/drivers/vfio/vfio.c
> +++ b/drivers/vfio/vfio.c
> @@ -86,6 +86,8 @@ struct vfio_group {
> struct mutex unbound_lock;
> atomic_t opened;
> bool noiommu;
> + struct kvm *kvm;
> + struct blocking_notifier_head notifier;
> };
>
> struct vfio_device {
> @@ -1015,6 +1017,34 @@ static long vfio_ioctl_check_extension(struct vfio_container *container,
> return ret;
> }
>
> +void vfio_group_notify(struct vfio_group *group, struct kvm *kvm)
> +{
> + group->kvm = kvm;
> + blocking_notifier_call_chain(&group->notifier,
> + VFIO_GROUP_NOTIFY_SET_KVM, kvm);
> +}
> +EXPORT_SYMBOL_GPL(vfio_group_notify);
This shouldn't be called vfio_group_notify() if it's specific to kvm.
vfio_group_set_kvm() perhaps.
> +
> +static void vfio_group_register_notifier(struct vfio_group *group,
> + struct notifier_block *nb)
> +{
> + blocking_notifier_chain_register(&group->notifier, nb);
> +
> + /*
> + * The attaching of kvm and vfio_group might already happen, so
> + * here we replay once on registration.
> + */
> + if (group->kvm)
> + blocking_notifier_call_chain(&group->notifier,
> + VFIO_GROUP_NOTIFY_SET_KVM, group->kvm);
> +}
> +
> +static void vfio_group_unregister_notifier(struct vfio_group *group,
> + struct notifier_block *nb)
> +{
> + blocking_notifier_chain_unregister(&group->notifier, nb);
> +}
> +
> /* hold write lock on container->group_lock */
> static int __vfio_container_attach_groups(struct vfio_container *container,
> struct vfio_iommu_driver *driver,
> diff --git a/include/linux/vfio.h b/include/linux/vfio.h
> index d4ce14d..ec9f74f 100644
> --- a/include/linux/vfio.h
> +++ b/include/linux/vfio.h
> @@ -100,6 +100,9 @@ extern void vfio_unregister_iommu_driver(
> extern long vfio_external_check_extension(struct vfio_group *group,
> unsigned long arg);
>
> +struct kvm;
> +extern void vfio_group_notify(struct vfio_group *group, struct kvm *kvm);
> +
> /*
> * Sub-module helpers
> */
> @@ -149,6 +152,7 @@ extern int vfio_unpin_pages(struct device *dev, unsigned long *user_pfn,
> int npage);
>
> #define VFIO_IOMMU_NOTIFY_DMA_UNMAP 1
> +#define VFIO_GROUP_NOTIFY_SET_KVM 2
>
> extern int vfio_register_notifier(struct device *dev,
> struct notifier_block *nb);
next prev parent reply other threads:[~2016-11-15 23:11 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-15 11:35 [v4 0/3] plumb kvm/vfio to notify kvm:group attaching/detaching Jike Song
2016-11-15 11:35 ` [v4 1/3] vfio: add vfio_group_notify support Jike Song
2016-11-15 23:11 ` Alex Williamson [this message]
2016-11-16 3:02 ` Jike Song
2016-11-15 11:35 ` [v4 2/3] vfio_register_notifier: also register on the group notifier Jike Song
2016-11-15 23:11 ` Alex Williamson
2016-11-16 3:01 ` Jike Song
2016-11-16 3:43 ` Alex Williamson
2016-11-16 9:14 ` Kirti Wankhede
2016-11-16 9:37 ` Jike Song
2016-11-16 10:44 ` Kirti Wankhede
2016-11-16 17:48 ` Alex Williamson
2016-11-16 19:12 ` Kirti Wankhede
2016-11-16 19:45 ` Alex Williamson
2016-11-17 5:24 ` Jike Song
2016-11-17 6:03 ` Alex Williamson
2016-11-17 6:27 ` Jike Song
2016-11-17 12:31 ` Jike Song
2016-11-17 16:22 ` Alex Williamson
2016-11-18 10:39 ` Jike Song
2016-11-15 11:35 ` [v4 3/3] kvm: notify vfio on attaching and detaching 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=20161115161120.43d1aef8@t450s.home \
--to=alex.williamson@redhat.com \
--cc=cjia@nvidia.com \
--cc=guangrong.xiao@linux.intel.com \
--cc=jike.song@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 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).