From: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
To: Davide Libenzi <davidel-AhlLAIvw+VEjIGhXcJzhZg@public.gmane.org>
Cc: Christoph Hellwig <hch-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: Re: [PATCH 5/9] KVM: Adds ability to signal userspace using a file-descriptor
Date: Sun, 20 May 2007 10:20:37 +0300 [thread overview]
Message-ID: <464FF6C5.10207@qumranet.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0705171010570.31677-GPJ85BhbkB8RepQJljzAVbITYcZ0+W3JAL8bYrjMMd8@public.gmane.org>
Davide Libenzi wrote:
> On Thu, 17 May 2007, Avi Kivity wrote:
>
>
>> Davide Libenzi wrote:
>>
>>> On Wed, 16 May 2007, Avi Kivity wrote:
>>>
>>>
>>>
>>>> IMO doing eventfd_fget() asap is best. I much prefer refcounted pointers
>>>> to
>>>> handles in the kernel: it's easier to see what things point to, and there
>>>> is
>>>> to context needed for dereferencing.
>>>>
>>>>
>>> There are concerns (from Al and Christoph) about file lifetime tracking of
>>> an fd passed down to the kernel.
>>>
>>>
>> What concerns are these?
>>
>> I have my own concerns about bare fds, which can change their backing file,
>> and which are dependent on the context. The kernel appears to be moving away
>> from handles to pointers, as seen by the pid -> task_struck/struct pid
>> conversion.
>>
>
> The concern is that by keeping a reference to the file* you may end up
> with a file that has no more userspace links. Although the file_count()==1
> will tell you that you've the only reference left, this relies on you
> doing the check. I really don't know how this will be used in KVM, so I
> can't really say how well these concerns applies.
>
>
That's perfectly fine for kvm (and as far as I can see, any other
application: the user losing their eventfd reference is equivalent to
the user ignoring any events, which should be survivable by the kernel).
>
>
>
>>> Avi, how about you go the other way around? I expose you something like:
>>>
>>> long eventfd_create(unsigned int count, void (*release)(void *),
>>> void *priv);
>>>
>>> This returns you an eventfd (or error), and lets you install a callback to
>>> be used when the file_operations->release is called (basically, userspace
>>> closed the last file instance).
>>> Can KVM pass back an fd to userspace instead of the other way around?
>>>
>>>
>> That was my original thought, but when I saw your proposal I preferred that as
>> more flexible.
>>
>> If we go this way, I prefer to have a struct file * and do away with the
>> callback, but that brings us back to the file lifetime concerns.
>>
>
> Doing the above requires some care too. Access to your copy of the file*
> must be protected by a lock (you can sleep from inside the callback, so a
> mutex is fine too). I'll sketch you some code:
>
>
> /* Defined in linux/eventfd.h */
> struct eventfd_relcb {
> struct list_head lnk;
> void (*proc)(struct eventfd_relcb *);
> };
>
> /* Your context data */
> struct your_ctx {
> whatever_lock your_lock;
> ...
> struct eventfd_relcb rcb;
> struct file *evfile;
> };
>
> /* Your eventfd release callback */
> void rcb_callback(struct eventfd_relcb *rcb) {
> struct your_ctx *c = container_of(rcb, struct your_ctx, rcb);
>
> whatever_lock_lock(&c->your_lock);
> ...
> c->evfile = NULL;
> whatever_lock_unlock(&c->your_lock);
> }
>
> /* Your notify userspace function */
> void notify_userspace(struct your_ctx *c) {
>
> whatever_lock_lock(&c->your_lock);
> if (c->evfile != NULL)
> eventfd_signal(c->evfile, 1);
> whatever_lock_unlock(&c->your_lock);
> }
>
> /* Your eventfd create/setup function (modulo error checks) */
> void setup_eventfd(struct your_ctx *c) {
> int fd;
>
> c->rcb.proc = rcb_callback;
> fd = eventfd_create(0, &c->rcb);
> c->evfile = eventfd_fget(fd);
> /* Then return fd to userspace in some way */
> ...
> }
>
>
>
> If, by any chance, you need to detach yourself from the eventfd:
>
> void detach_eventfd(struct your_ctx *c) {
>
> whatever_lock_lock(&c->your_lock);
> if (c->evfile != NULL) {
> eventfd_del_release_cb(c->evfile, &c->rcb);
> /* And, optionally ... */
> eventfd_set_shutdown(c->evfile);
> }
> whatever_lock_unlock(&c->your_lock);
> }
>
>
> The eventfd_set_shutdown() function will make a POLLIN signaled to
> userspace, and a read(2) on the eventfd will return 0 (like peer
> disconnected sockets). Then userspace will know that no more eventfs will
> show up in there.
> Tentative patch below (builds, not tested yet).
>
>
>
Looks like a lot of code for what was supposed to be a code reduction...
I think I'll look at Gregory's notification-free suggestion instead.
--
error compiling committee.c: too many arguments to function
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
next prev parent reply other threads:[~2007-05-20 7:20 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-15 3:15 [PATCH 0/9] in-kernel APIC v4 (kernel side) Gregory Haskins
[not found] ` <20070515031217.9382.44999.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>
2007-05-15 3:15 ` [PATCH 1/9] KVM: Adds support for in-kernel mmio handlers Gregory Haskins
2007-05-15 3:15 ` [PATCH 2/9] KVM: VMX - fix interrupt checking on light-exit Gregory Haskins
2007-05-15 3:15 ` [PATCH 3/9] KVM: Add irqdevice object Gregory Haskins
2007-05-15 3:15 ` [PATCH 4/9] KVM: Adds ability to preempt an executing VCPU Gregory Haskins
2007-05-15 3:15 ` [PATCH 5/9] KVM: Adds ability to signal userspace using a file-descriptor Gregory Haskins
[not found] ` <20070515031536.9382.16826.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>
2007-05-15 7:45 ` Avi Kivity
[not found] ` <4649650E.2070102-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-15 12:02 ` Gregory Haskins
[not found] ` <464968D6.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-05-15 15:40 ` Davide Libenzi
[not found] ` <Pine.LNX.4.64.0705150832130.30085-GPJ85BhbkB8RepQJljzAVbITYcZ0+W3JAL8bYrjMMd8@public.gmane.org>
2007-05-15 16:18 ` Gregory Haskins
[not found] ` <4649A4E1.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-05-15 16:22 ` Christoph Hellwig
[not found] ` <20070515162249.GA19238-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2007-05-15 16:29 ` Gregory Haskins
2007-05-15 17:16 ` Davide Libenzi
[not found] ` <Pine.LNX.4.64.0705151008400.30345-GPJ85BhbkB8RepQJljzAVbITYcZ0+W3JAL8bYrjMMd8@public.gmane.org>
2007-05-16 12:00 ` Avi Kivity
[not found] ` <464AF269.7030402-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-16 19:59 ` Davide Libenzi
[not found] ` <Pine.LNX.4.64.0705161201410.12427-GPJ85BhbkB8RepQJljzAVbITYcZ0+W3JAL8bYrjMMd8@public.gmane.org>
2007-05-17 11:33 ` Avi Kivity
[not found] ` <464C3D93.5090605-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-17 19:11 ` Davide Libenzi
[not found] ` <Pine.LNX.4.64.0705171010570.31677-GPJ85BhbkB8RepQJljzAVbITYcZ0+W3JAL8bYrjMMd8@public.gmane.org>
2007-05-17 21:57 ` Davide Libenzi
2007-05-20 7:20 ` Avi Kivity [this message]
2007-05-16 10:09 ` Avi Kivity
2007-05-16 10:07 ` Avi Kivity
2007-05-15 3:15 ` [PATCH 6/9] KVM: Add support for in-kernel LAPIC model Gregory Haskins
2007-05-15 3:15 ` [PATCH 7/9] KVM: Adds support for real NMI injection on VMX processors Gregory Haskins
2007-05-15 3:15 ` [PATCH 8/9] KVM: Adds basic plumbing to support TPR shadow features Gregory Haskins
2007-05-15 3:15 ` [PATCH 9/9] KVM: Add statistics from interrupt subsystem Gregory Haskins
-- strict thread matches above, loose matches on Subject: below --
2007-05-15 14:57 [PATCH 0/9] in-kernel APIC v5 (kernel side) Gregory Haskins
[not found] ` <20070515145404.15609.61552.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>
2007-05-15 14:57 ` [PATCH 5/9] KVM: Adds ability to signal userspace using a file-descriptor Gregory Haskins
[not found] ` <20070515145759.15609.34720.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>
2007-05-15 16:39 ` Anthony Liguori
[not found] ` <4649E22F.3090308-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-05-15 16:55 ` Gregory Haskins
[not found] ` <4649AD87.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-05-15 18:44 ` Anthony Liguori
[not found] ` <4649FF7B.10107-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-05-16 11:56 ` Avi Kivity
2007-05-09 15:18 [PATCH 0/9] in-kernel APIC v2 Gregory Haskins
[not found] ` <20070509151238.8673.4818.stgit-sLgBBP33vUGnsjUZhwzVf9HuzzzSOjJt@public.gmane.org>
2007-05-09 15:19 ` [PATCH 5/9] KVM: Adds ability to signal userspace using a file-descriptor Gregory Haskins
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=464FF6C5.10207@qumranet.com \
--to=avi-atkuwr5tajbwk0htik3j/w@public.gmane.org \
--cc=davidel-AhlLAIvw+VEjIGhXcJzhZg@public.gmane.org \
--cc=hch-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
/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