From: Jike Song <jike.song@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Xiao Guangrong <guangrong.xiao@linux.intel.com>,
Xiao Guangrong <guangrong.xiao@intel.com>,
Alex Williamson <alex.williamson@redhat.com>,
"Tian, Kevin" <kevin.tian@intel.com>, Neo Jia <cjia@nvidia.com>,
kvm@vger.kernel.org, qemu-devel <qemu-devel@nongnu.org>,
Xiaoguang Chen <xiaoguang.chen@intel.com>,
Kirti Wankhede <kwankhede@nvidia.com>
Subject: Re: [Qemu-devel] [PATCH 1/2] KVM: page track: add a new notifier type: track_flush_slot
Date: Sat, 29 Oct 2016 12:07:30 +0800 [thread overview]
Message-ID: <58142082.9080404@intel.com> (raw)
In-Reply-To: <5392281b-414e-13f0-e674-4ac2e9823ab8@redhat.com>
On 10/26/2016 10:45 PM, Paolo Bonzini wrote:
> On 26/10/2016 15:44, Jike Song wrote:
>> On 10/21/2016 01:06 AM, Paolo Bonzini wrote:
>>> On 20/10/2016 03:48, Xiao Guangrong wrote:
>>>> I understood that KVM side is safe, however, vfio side is independent with
>>>> kvm and the user of usrdata can fetch kvm struct at any time, consider
>>>> this scenario:
>>>>
>>>> CPU 0 CPU 1
>>>> KVM: VFIO/userdata user
>>>> kvm_ioctl_create_device
>>>> get_kvm()
>>>> vfio_group_get_usrdata(vfio_group)
>>>> kvm_device_release
>>>> put_kvm()
>>>> !!! kvm refcount has gone
>>>> use KVM struct
>>>>
>>>> Then, the user of userdata have fetched kvm struct but the refcount has
>>>> already gone.
>>>
>>> vfio_group_set_usrdata (actually) kvm_vfio_group_set_kvm has called
>>> kvm_get_kvm too, however. What you need is a mutex that is taken by
>>> vfio_group_set_usrdata and by the callers of vfio_group_get_usrdata.
>>
>> Hi Paolo & Guangrong,
>>
>> I walked the whole thread and became a little nervous: I don't want
>> to introduce a global mutex.
>>
>> The problem is, as I understand, vfio_group_get_usrdata() returns a
>> KVM pointer but it may be stale. To make the pointer always valid,
>> it can call kvm_get_kvm() *before* return the pointer.
>
> That doesn't work, you still have to protect get against concurrent set.
> But the mutex need not be global, it is specific to the vfio device.
> You probably have such a mutex anyway...
Thanks Paolo, I agree whatsoever a mutex is necessary. I cooked a patch
sent to you and Alex, please kindly have a look :-)
--
Thanks,
Jike
>> I would apologize in advance if this idea turns out totally
>> nonsense, but hey, please kindly help fix my whim :-)
>>
>>
>> [vfio.h]
>>
>> struct vfio_usrdata {
>> void *data;
>> void (*get)(void *data);
>> void (*put)(void *data)
>> };
>>
>> vfio_group {
>> ...
>> vfio_usrdata *usrdata;
>>
>> [kvm.ko]
>>
>> struvt vfio_usrdata kvmdata = {
>> .data = kvm,
>> .get = kvm_get_kvm,
>> .put = kvm_put_kvm,
>> };
>>
>> fn = symbol_get(vfio_group_set_usrdata)
>> fn(vfio_group, &kvmdata)
>>
>>
>> [vfio.ko]
>>
>> vfio_group_set_usrdata
>> lock
>> vfio_group->d = kvmdata
>> unlock
>>
>> void *vfio_group_get_usrdata
>> lock
>> struct vfio_usrdata *d = vfio_group->usrdata;
>> d->get(d->data);
>> unlock
>> return d->data;
>>
>> void vfio_group_put_usrdata
>> lock
>> struct vfio_usrdata *d = vfio_group->usrdata;
>> d->put(d->data)
>> unlock
>>
>> [kvmgt.ko]
>>
>> call vfio_group_get_usrdata to get kvm,
>> call vfio_group_put_usrdata to release it
>> *never* call kvm_get_kvm/kvm_put_kvm
next prev parent reply other threads:[~2016-10-29 4:10 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1475998904-13456-1-git-send-email-xiaoguang.chen@intel.com>
[not found] ` <1475998904-13456-2-git-send-email-xiaoguang.chen@intel.com>
[not found] ` <20161009083134.GA19090@nvidia.com>
[not found] ` <ad547eac-428c-751b-05c4-52002d78ecb4@redhat.com>
[not found] ` <20161010180140.GA27757@nvidia.com>
[not found] ` <c9d63f52-9b6f-5752-2111-773b33adc426@redhat.com>
[not found] ` <1259cdba-c137-c3da-abe2-ecf51aec6738@linux.intel.com>
[not found] ` <e992eb4e-0806-8f6e-851d-36eaf389a897@redhat.com>
[not found] ` <ea9dffe6-7afa-4862-e46f-6f780a309e46@linux.intel.com>
[not found] ` <523e1446-75f1-fe3a-d818-f7d238d57751@redhat.com>
2016-10-14 10:37 ` [Qemu-devel] [PATCH 1/2] KVM: page track: add a new notifier type: track_flush_slot Jike Song
2016-10-14 10:43 ` Paolo Bonzini
2016-10-14 12:26 ` Jike Song
2016-10-14 14:41 ` Alex Williamson
2016-10-14 14:46 ` Alex Williamson
2016-10-14 16:35 ` Neo Jia
2016-10-14 16:51 ` Alex Williamson
2016-10-14 22:19 ` Neo Jia
2016-10-17 16:02 ` Alex Williamson
2016-10-18 12:38 ` Jike Song
2016-10-18 14:59 ` Alex Williamson
2016-10-19 2:32 ` Jike Song
2016-10-19 5:45 ` Xiao Guangrong
2016-10-19 11:56 ` Paolo Bonzini
2016-10-19 13:39 ` Xiao Guangrong
2016-10-19 14:14 ` Paolo Bonzini
2016-10-20 1:48 ` Xiao Guangrong
2016-10-20 17:06 ` Paolo Bonzini
2016-10-20 17:19 ` Xiao, Guangrong
2016-10-21 2:47 ` Jike Song
2016-10-26 13:44 ` Jike Song
2016-10-26 14:45 ` Paolo Bonzini
2016-10-29 4:07 ` Jike Song [this message]
2016-10-19 13:56 ` Eric Blake
2016-10-24 6:32 ` 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=58142082.9080404@intel.com \
--to=jike.song@intel.com \
--cc=alex.williamson@redhat.com \
--cc=cjia@nvidia.com \
--cc=guangrong.xiao@intel.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 \
--cc=qemu-devel@nongnu.org \
--cc=xiaoguang.chen@intel.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).