From: Sasha Levin <levinsasha928@gmail.com>
To: Avi Kivity <avi@redhat.com>
Cc: kvm@vger.kernel.org, Ingo Molnar <mingo@elte.hu>,
Marcelo Tosatti <mtosatti@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Pekka Enberg <penberg@kernel.org>
Subject: Re: [PATCH 5/5] ioeventfd: Introduce KVM_IOEVENTFD_FLAG_SOCKET
Date: Wed, 06 Jul 2011 15:58:54 +0300 [thread overview]
Message-ID: <1309957134.15123.10.camel@sasha> (raw)
In-Reply-To: <4E145783.2000605@redhat.com>
On Wed, 2011-07-06 at 15:39 +0300, Avi Kivity wrote:
> On 07/06/2011 07:37 AM, Sasha Levin wrote:
> > The new flag allows passing a connected socket instead of an
> > eventfd to be notified of writes or reads to the specified memory region.
> >
> > Instead of signaling an event, On write - the value written to the memory
> > region is written to the pipe.
> > On read - a notification of the read is sent to the host, and a response
> > is expected with the value to be 'read'.
> >
> > Using a socket instead of an eventfd is usefull when any value can be
> > written to the memory region but we're interested in recieving the
> > actual value instead of just a notification.
> >
> > A simple example for practical use is the serial port. we are not
> > interested in an exit every time a char is written to the port, but
> > we do need to know what was written so we could handle it on the guest.
> >
> >
> >
> > @@ -534,6 +607,7 @@ ioeventfd_read(struct kvm_io_device *this, gpa_t addr, int len,
> > void *val)
> > {
> > struct _ioeventfd *p = to_ioeventfd(this);
> > + struct kvm_ioeventfd_data data;
> >
> > /* Exit if signaling on reads isn't requested */
> > if (!p->track_reads)
> > @@ -542,7 +616,21 @@ ioeventfd_read(struct kvm_io_device *this, gpa_t addr, int len,
> > if (!ioeventfd_in_range(p, addr, len, val))
> > return -EOPNOTSUPP;
> >
> > - eventfd_signal(p->eventfd, 1);
> > + data = (struct kvm_ioeventfd_data) {
> > + .addr = addr,
> > + .len = len,
> > + .is_write = 0,
> > + };
> > +
> > + if (p->sock) {
> > + socket_write(p->sock,&data, sizeof(data));
> > + socket_read(p->sock,&data, sizeof(data));
> > + set_val(val, len, data.data);
> > + } else {
> > + set_val(val, len, p->datamatch);
> > + eventfd_signal(p->eventfd, 1);
> > + }
> > +
> > return 0;
> > }
>
> If there are two reads on the same ioeventfd range, then the responses
> can mix up. Need to make sure we get the right response.
>
> Note that a mutex on the ioeventfd structure is insufficient, since the
> same socket may be used for multiple ranges.
>
> One way out is to require that sockets not be shared among vcpus (there
> can be only one outstanding read per vcpu). It seems heavy handed though.
>
What about something as follows:
This requires an addition of a mutex to struct ioeventfd.
1. When adding a new ioeventfd, scan exiting ioeventfds (we already do
it anyway) and check whether another ioeventfd is using the socket
already.
2. If the existing ioeventfd doesn't have a mutex assigned, create a new
mutex and assign it to both ioeventfds.
3. If the existing ioeventfd already has a mutex assigned, copy it to
the new ioeventfd.
4. When removing an ioeventfd, do everything the other way around :)
This mutex can be used to lock the write/read pair.
--
Sasha.
next prev parent reply other threads:[~2011-07-06 12:58 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-06 4:37 [PATCH 1/5] ioeventfd: Remove natural sized length limitation Sasha Levin
2011-07-06 4:37 ` [PATCH 2/5] ioeventfd: Add helper functions for reading and writing Sasha Levin
2011-07-06 4:37 ` [PATCH 3/5] ioeventfd: Introduce KVM_IOEVENTFD_FLAG_READ Sasha Levin
2011-07-06 4:37 ` [PATCH 4/5] ioeventfd: Introduce KVM_IOEVENTFD_FLAG_NOWRITE Sasha Levin
2011-07-06 4:37 ` [PATCH 5/5] ioeventfd: Introduce KVM_IOEVENTFD_FLAG_SOCKET Sasha Levin
2011-07-06 11:42 ` Michael S. Tsirkin
2011-07-06 15:01 ` Sasha Levin
2011-07-06 17:58 ` Michael S. Tsirkin
2011-07-10 5:34 ` Sasha Levin
2011-07-10 8:05 ` Michael S. Tsirkin
2011-07-12 11:23 ` Sasha Levin
2011-07-12 11:26 ` Avi Kivity
2011-07-13 6:37 ` Pekka Enberg
2011-07-13 6:45 ` Pekka Enberg
2011-07-13 7:07 ` Avi Kivity
2011-07-13 8:02 ` Pekka Enberg
2011-07-13 12:57 ` Avi Kivity
2011-07-13 13:00 ` Pekka Enberg
2011-07-13 13:32 ` Avi Kivity
2011-07-14 7:26 ` Pekka Enberg
2011-07-14 8:07 ` Sasha Levin
2011-07-14 8:09 ` Avi Kivity
2011-07-14 8:14 ` Pekka Enberg
2011-07-14 8:28 ` Avi Kivity
2011-07-14 8:59 ` Pekka Enberg
2011-07-14 9:48 ` Avi Kivity
[not found] ` <CAOJsxLHSeRuTOoiJssyrELRx-eXok3WinLr_+_G4dB+yHNBKdg@mail.gmai! l.com>
2011-07-14 10:30 ` Pekka Enberg
2011-07-14 11:54 ` Avi Kivity
2011-07-14 12:32 ` Sasha Levin
2011-07-14 12:46 ` Avi Kivity
2011-07-14 13:00 ` Sasha Levin
2011-07-14 13:05 ` Avi Kivity
2011-07-14 13:17 ` Pekka Enberg
2011-07-14 13:23 ` Avi Kivity
2011-07-20 2:52 ` Anthony Liguori
2011-07-20 6:16 ` Sasha Levin
2011-07-20 9:42 ` Pekka Enberg
2011-07-14 12:37 ` Pekka Enberg
2011-07-14 12:48 ` Avi Kivity
2011-07-14 12:52 ` Pekka Enberg
2011-07-14 12:54 ` Avi Kivity
2011-07-14 8:19 ` Gleb Natapov
2011-07-14 8:25 ` Michael S. Tsirkin
2011-07-14 8:29 ` Avi Kivity
2011-07-20 2:49 ` Anthony Liguori
2011-07-20 9:44 ` Pekka Enberg
2011-07-20 21:10 ` Anthony Liguori
2011-07-25 12:10 ` Sasha Levin
2011-07-25 12:16 ` Avi Kivity
2011-07-25 12:26 ` Sasha Levin
2011-07-25 13:04 ` Avi Kivity
2011-07-13 7:51 ` Pekka Enberg
2011-07-13 10:04 ` Pekka Enberg
2011-07-13 10:26 ` Sasha Levin
2011-07-13 10:56 ` Pekka Enberg
2011-07-13 11:14 ` Pekka Enberg
2011-07-06 12:39 ` Avi Kivity
2011-07-06 12:58 ` Sasha Levin [this message]
2011-07-06 13:04 ` Avi Kivity
2011-07-06 13:00 ` Avi Kivity
2011-07-20 2:42 ` Anthony Liguori
2011-07-20 8:19 ` Avi Kivity
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=1309957134.15123.10.camel@sasha \
--to=levinsasha928@gmail.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mst@redhat.com \
--cc=mtosatti@redhat.com \
--cc=penberg@kernel.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