kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jike Song <jike.song@intel.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: Kirti Wankhede <kwankhede@nvidia.com>,
	pbonzini@redhat.com, guangrong.xiao@linux.intel.com,
	cjia@nvidia.com, kevin.tian@intel.com, kvm@vger.kernel.org
Subject: Re: [v4 2/3] vfio_register_notifier: also register on the group notifier
Date: Thu, 17 Nov 2016 20:31:07 +0800	[thread overview]
Message-ID: <582DA30B.6020301@intel.com> (raw)
In-Reply-To: <20161116230316.11f2cde8@t450s.home>

On 11/17/2016 02:03 PM, Alex Williamson wrote:
> On Thu, 17 Nov 2016 13:24:59 +0800
> Jike Song <jike.song@intel.com> wrote:
> 
>> On 11/17/2016 03:45 AM, Alex Williamson wrote:
>>> Perhaps calling it a filter is not correct, I was thinking that a
>>> vendor driver would register the notifier with a set of required
>>> events.  The driver would need to handle/ignore additional events
>>> outside of the required mask.  There are certainly some complications
>>> to this model though that I hadn't thought all the way through until
>>> now.  For instance what if we add event XYZ in the future and the
>>> vendor driver adds this to their required mask.  If we run that on an
>>> older kernel where the vfio infrastructure doesn't know about that
>>> event, the vendor driver needs to fail, or at least know that event is
>>> not supported and retry with a set of supported events.
>>>
>>> There's another problem with my proposal too, we can't put a single
>>> notifier_block on multiple notifier_block heads, that just doesn't
>>> work.  So we probably need to separate a group notifier from an iommu
>>> notifier, the vendor driver will need to register for each.
>>>
>>> Maybe we end up with something like:
>>>
>>> int vfio_register_notifier(struct device *dev,
>>> 			   vfio_notify_type_t type,
>>> 			   unsigned long *required_events,
>>> 			   struct notifier_block *nb);
>>>
>>> typedef unsigned short vfio_notify_type_t;
>>> enum vfio_notify_type {
>>> 	VFIO_IOMMU_NOTIFY = (__force vfio_notify_type_t)0,
>>> 	VFIO_GROUP_NOTIFY = (__force vfio_notify_type_t)1,
>>> };
>>>
>>> (stealing this from pci_dev_flags_t, hope it works)
>>>
>>> A VFIO_GROUP_NOTIFY would add the notifier_block to the vfio_group, a
>>> VFIO_IOMMU_NOTIFY would add it to vfio_iommu.  Each would have their
>>> own unique set of events and each would compare their supported events
>>> to the required events by the caller.  Supported events would be
>>> cleared from the callers required_events arg.  If required_events still
>>> has bits set, the notifier_block is not registered, an error is
>>> returned, and the caller can identify the unsupported events by the
>>> remaining bits in the required_events arg.  Can that work?  Thanks,  
>>
>> Let me summarize the discussion:
>>
>> - There should be 2 notifier heads, one in vfio_iommu another in vfio_group;
>> - vfio_{un}register_notifier() has the type specified in parameter
>> - In vfio_register_notifier, maybe:
>>
>> 	static vfio_iommu_register_notifier() {..}
>> 	static vfio_group_register_notifier() {..}
>> 	int vfio_register_notififer(type..
>> 	{
>> 		if (type == VFIO_IOMMU_NOTIFY)
>> 			return vfio_iommu_register_notifier();
>> 		if (type == VFIO_GROUP_NOTIFY)
>> 			return vfio_group_register_notifier();
>> 	}
>>
>>
>>
>> What's more, if we still want registration to be done in mdev framework,
>> we should change parent_ops:
>>
>> - rename 'notifier' to 'iommu_notifier'
>> - add "group_notifier"
>> - Add a group_events and a iommu_events to indicate what events vendor is
>>   interested in, respectively
>>
>> or otherwise don't touch it from mdev framework at all?
> 
> I think we should remove the notifier from the mdev framework and have
> the vendor drivers call vfio_{un}register_notifier() directly.  Note:
> 
>  - vfio_group_release() should be modified to remove any notifier
>    blocks remaining to prevent a stale call chain for the next user.

vfio_group_release calls vfio_group_unlock_and_free, which in turn calls 
kfree(group), so I guess a WARN_ON(group->notifier.head) before kfree
is enough?

>  - vfio_sanity_check_pfn_list() should be modified to WARN_ON remaining
>    notifier blocks on the vfio_iommu (ie. vendor drivers will need to
>    actively remove iommu notifiers since the vfio_iommu can persist
>    beyond the attachment of the mdev group, the WARN_ON will promote a
>    proactive approach to surfacing such issues).

I guess Kirti will prefer to pick up this? if not I also can do it :-)

> I'd like to get Kirti's current series in linux-next ASAP, so please
> submit a follow-on series to make these changes.  I hope we can get
> that finalized and added on top of Kirti's series before the v4.10
> merge window opens. Thanks,

Yes, I'll send out the follow-on series ASAP, since we also have KVMGT
depending on it to get notified by vfio...


--
Thanks,
Jike


  parent reply	other threads:[~2016-11-17 16:57 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
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 [this message]
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=582DA30B.6020301@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 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).