Re: [Qemu-devel] [RFC v2 1/2] docs: vhost-user: add in-band kick/call messages

2019-09-17 Thread Johannes Berg
On Mon, 2019-09-16 at 11:30 -0400, Michael S. Tsirkin wrote:
> 
> So first we really need to fix up Starting and stopping section,
> explaining that if the FD is invalid, this means ring
> is immediately started, right?

It actually does say that, and ... I even changed it already to say the
ring is also started when receiving the new VHOST_USER_VRING_KICK
message:

   Client must start ring upon receiving a kick (that is, detecting that
   file descriptor is readable) on the descriptor specified by
   ``VHOST_USER_SET_VRING_KICK`` (or receiving the in-band message
   ``VHOST_USER_VRING_KICK`` if negotiated) and stop ring upon receiving
   ``VHOST_USER_GET_VRING_BASE``.


> If we want to keep it simple, my proposal is this, if
> VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS is set then
> VHOST_USER_SET_VRING_CALL and VHOST_USER_SET_VRING_KICK are not valid.
> Starting/stopping ring needs to be updated, teaching it
> that ring is started after it gets a kick.

Makes sense, mostly I just need to actually *implement* that.

johannes




Re: [Qemu-devel] [RFC v2 1/2] docs: vhost-user: add in-band kick/call messages

2019-09-16 Thread Michael S. Tsirkin
On Mon, Sep 16, 2019 at 01:40:35PM +0200, Johannes Berg wrote:
> Hi Michael,
> 
> I had just wanted to prepare a resend, but
> 
> > > Hmm I don't like this. I propose that with 
> > > VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS
> > > we just don't allow VHOST_USER_SET_VRING_CALL (if you think it's
> > > important to allow them, we can say that we do not require them).
> > 
> > You can't actually skip SET_VRING_CALL, it's necessary to start a vring,
> > so libvhost-user for example calls dev->iface->queue_set_started() only
> > in this case. The docs in the "Starting and stopping rings" section also
> > explain this.
> 
> [...]
> 
> > See above. But I guess we could put a flag into bit 9 indicating that
> > you want to use messages instead of polling or a file descriptor, if you
> > prefer.
> 
> Personally, I don't think it matters since right now I can see the in-
> band notification as being really necessary/useful only for simulation
> work, and in that case no polling will be doable.
> 
> If you do think it's important to not make the two mutually exclusive,
> how would you prefer to have this handled? With a new flag, e.g. in bit
> 9, indicating "use inband signalling instead of polling or eventfd"?
> 
> Thanks,
> johannes


So first we really need to fix up Starting and stopping section,
explaining that if the FD is invalid, this means ring
is immediately started, right?

If we want to keep it simple, my proposal is this, if
VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS is set then
VHOST_USER_SET_VRING_CALL and VHOST_USER_SET_VRING_KICK are not valid.
Starting/stopping ring needs to be updated, teaching it
that ring is started after it gets a kick.


-- 
MST




Re: [Qemu-devel] [RFC v2 1/2] docs: vhost-user: add in-band kick/call messages

2019-09-16 Thread Johannes Berg
Hi Michael,

I had just wanted to prepare a resend, but

> > Hmm I don't like this. I propose that with 
> > VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS
> > we just don't allow VHOST_USER_SET_VRING_CALL (if you think it's
> > important to allow them, we can say that we do not require them).
> 
> You can't actually skip SET_VRING_CALL, it's necessary to start a vring,
> so libvhost-user for example calls dev->iface->queue_set_started() only
> in this case. The docs in the "Starting and stopping rings" section also
> explain this.

[...]

> See above. But I guess we could put a flag into bit 9 indicating that
> you want to use messages instead of polling or a file descriptor, if you
> prefer.

Personally, I don't think it matters since right now I can see the in-
band notification as being really necessary/useful only for simulation
work, and in that case no polling will be doable.

If you do think it's important to not make the two mutually exclusive,
how would you prefer to have this handled? With a new flag, e.g. in bit
9, indicating "use inband signalling instead of polling or eventfd"?

Thanks,
johannes




Re: [Qemu-devel] [RFC v2 1/2] docs: vhost-user: add in-band kick/call messages

2019-09-12 Thread Johannes Berg
On Thu, 2019-09-12 at 09:09 +0100, Dr. David Alan Gilbert wrote:
> 
> You're actually using the same trick of using
> REPLY_ACK/need_reply  to make it synchronous that set_mem_table does;

I don't think it's really the same - though arguably I could have
spec'ed the inband signal to *require* an ACK. The way I did it relies
on the REPLY_ACK extension.

SET_MEM_TABLE actually specifies a 3-way handshake, qemu->device,
device->qemu, qemu->device.

> that makes sense - but then new calls are getting it to actually process
> some data/commands on the ring itself?

No, the calls (or more specifically the REPLY_ACK to them) are really in
simulation to only acknowledge the interrupt (kick/call) signal has been
received and accounted for on the simulation calendar, the actual
processing happens when the calendar event is scheduled.

johannes




Re: [Qemu-devel] [RFC v2 1/2] docs: vhost-user: add in-band kick/call messages

2019-09-12 Thread Dr. David Alan Gilbert
* Johannes Berg (johan...@sipsolutions.net) wrote:
> On Wed, 2019-09-11 at 20:15 +0100, Dr. David Alan Gilbert wrote:
> 
> > > Extend the protocol slightly, so that a message can be used for kick
> > > and call instead, if VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS is
> > > negotiated. This in itself doesn't guarantee synchronisation, but both
> > > sides can also negotiate VHOST_USER_PROTOCOL_F_REPLY_ACK and thus get
> > > a reply to this message by setting the need_reply flag, and ensure
> > > synchronisation this way.
> > 
> > I'm confused; if you've already got REPLY_ACK, why do we need anything
> > else?  We already require the reply on set_mem_table as part of
> > postcopy.
> 
> Hmm? How's this related to set_mem_table?
> 
> For simulation purposes, I need the kick and call (and error perhaps
> though it's not really used by anyone now it seems) to be synchronous
> messages instead of asynchronous event FD pushes.
> 
> But I think enough words have been expended on explaining it already, if
> I may kindly ask you to read the discussions with Stefan and Michael
> here:
> 
> https://lore.kernel.org/qemu-devel/20190902121233.13382-1-johan...@sipsolutions.net/

Ah OK.

You're actually using the same trick of using
REPLY_ACK/need_reply  to make it synchronous that set_mem_table does;
that makes sense - but then new calls are getting it to actually process
some data/commands on the ring itself?

Dave

> Thanks,
> johannes
> 
--
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK



Re: [Qemu-devel] [RFC v2 1/2] docs: vhost-user: add in-band kick/call messages

2019-09-11 Thread Johannes Berg
On Wed, 2019-09-11 at 20:15 +0100, Dr. David Alan Gilbert wrote:

> > Extend the protocol slightly, so that a message can be used for kick
> > and call instead, if VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS is
> > negotiated. This in itself doesn't guarantee synchronisation, but both
> > sides can also negotiate VHOST_USER_PROTOCOL_F_REPLY_ACK and thus get
> > a reply to this message by setting the need_reply flag, and ensure
> > synchronisation this way.
> 
> I'm confused; if you've already got REPLY_ACK, why do we need anything
> else?  We already require the reply on set_mem_table as part of
> postcopy.

Hmm? How's this related to set_mem_table?

For simulation purposes, I need the kick and call (and error perhaps
though it's not really used by anyone now it seems) to be synchronous
messages instead of asynchronous event FD pushes.

But I think enough words have been expended on explaining it already, if
I may kindly ask you to read the discussions with Stefan and Michael
here:

https://lore.kernel.org/qemu-devel/20190902121233.13382-1-johan...@sipsolutions.net/

Thanks,
johannes




Re: [Qemu-devel] [RFC v2 1/2] docs: vhost-user: add in-band kick/call messages

2019-09-11 Thread Dr. David Alan Gilbert
* Johannes Berg (johan...@sipsolutions.net) wrote:
> From: Johannes Berg 
> 
> For good reason, vhost-user is currently built asynchronously, that
> way better performance can be obtained. However, for certain use
> cases such as simulation, this is problematic.
> 
> Consider an event-based simulation in which both the device and CPU
> have scheduled according to a simulation "calendar". Now, consider
> the CPU sending I/O to the device, over a vring in the vhost-user
> protocol. In this case, the CPU must wait for the vring interrupt
> to have been processed by the device, so that the device is able to
> put an entry onto the simulation calendar to obtain time to handle
> the interrupt. Note that this doesn't mean the I/O is actually done
> at this time, it just means that the handling of it is scheduled
> before the CPU can continue running.
> 
> This cannot be done with the asynchronous eventfd based vring kick
> and call design.
> 
> Extend the protocol slightly, so that a message can be used for kick
> and call instead, if VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS is
> negotiated. This in itself doesn't guarantee synchronisation, but both
> sides can also negotiate VHOST_USER_PROTOCOL_F_REPLY_ACK and thus get
> a reply to this message by setting the need_reply flag, and ensure
> synchronisation this way.

I'm confused; if you've already got REPLY_ACK, why do we need anything
else?  We already require the reply on set_mem_table as part of
postcopy.

Dave

> To really use it in both directions, VHOST_USER_PROTOCOL_F_SLAVE_REQ
> is also needed.
> 
> Since it is used for simulation purposes and too many messages on
> the socket can lock up the virtual machine, document that this should
> only be used together with the mentioned features.
> 
> Signed-off-by: Johannes Berg 
> ---
>  docs/interop/vhost-user.rst | 113 ++--
>  1 file changed, 96 insertions(+), 17 deletions(-)
> 
> diff --git a/docs/interop/vhost-user.rst b/docs/interop/vhost-user.rst
> index 7827b710aa0a..c4396eabf9e9 100644
> --- a/docs/interop/vhost-user.rst
> +++ b/docs/interop/vhost-user.rst
> @@ -2,6 +2,7 @@
>  Vhost-user Protocol
>  ===
>  :Copyright: 2014 Virtual Open Systems Sarl.
> +:Copyright: 2019 Intel Corporation
>  :Licence: This work is licensed under the terms of the GNU GPL,
>version 2 or later. See the COPYING file in the top-level
>directory.
> @@ -279,6 +280,9 @@ If *master* is unable to send the full message or 
> receives a wrong
>  reply it will close the connection. An optional reconnection mechanism
>  can be implemented.
>  
> +If *slave* detects some error such as incompatible features, it may also
> +close the connection. This should only happen in exceptional circumstances.
> +
>  Any protocol extensions are gated by protocol feature bits, which
>  allows full backwards compatibility on both master and slave.  As
>  older slaves don't support negotiating protocol features, a feature
> @@ -315,7 +319,8 @@ it until ring is started, or after it has been stopped.
>  
>  Client must start ring upon receiving a kick (that is, detecting that
>  file descriptor is readable) on the descriptor specified by
> -``VHOST_USER_SET_VRING_KICK``, and stop ring upon receiving
> +``VHOST_USER_SET_VRING_KICK`` (or receiving the in-band message
> +``VHOST_USER_VRING_KICK`` if negotiated) and stop ring upon receiving
>  ``VHOST_USER_GET_VRING_BASE``.
>  
>  While processing the rings (whether they are enabled or not), client
> @@ -767,24 +772,48 @@ When reconnecting:
>  #. Resubmit inflight ``DescStatePacked`` entries in order of their
> counter value
>  
> +In-band notifications
> +-
> +
> +In some limited situations (e.g. for simulation) it is desirable to
> +have the kick, call and error (if used) signals done via in-band
> +messages instead of asynchronous eventfd notifications. This can be
> +done by negotiating the ``VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS``
> +protocol feature.
> +
> +Note that due to the fact that too many messages on the sockets can
> +cause the sending application(s) to block, it is not advised to use
> +this feature unless absolutely necessary. It is also considered an
> +error to negotiate this feature without also negotiating
> +``VHOST_USER_PROTOCOL_F_SLAVE_REQ`` and ``VHOST_USER_PROTOCOL_F_REPLY_ACK``,
> +the former is necessary for getting a message channel from the slave
> +to the master, while the latter needs to be used with the in-band
> +notification messages to block until they are processed, both to avoid
> +blocking later and for proper processing (at least in the simulation
> +use case.) As it has no other way of signalling this error, the slave
> +should close the connection as a response to a
> +``VHOST_USER_SET_PROTOCOL_FEATURES`` message that sets the in-band
> +notifications feature flag without the other two.
> +
>  Protocol features
>  -
>  
>  .. code:: c
>  
> -  #define

Re: [Qemu-devel] [RFC v2 1/2] docs: vhost-user: add in-band kick/call messages

2019-09-11 Thread Johannes Berg
On Wed, 2019-09-11 at 10:07 -0400, Michael S. Tsirkin wrote:
> 
> > +  #define VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD12
> > +  #define VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS 13
> 
> INFLIGHT so INBAND?

*shrug*, sure

> > +  instead of waiting for the call; however, if the protocol feature
> > +  ``VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS`` has been negotiated
> > +  it instead means the updates should be done using the messages.
> 
> Hmm I don't like this. I propose that with 
> VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS
> we just don't allow VHOST_USER_SET_VRING_CALL (if you think it's
> important to allow them, we can say that we do not require them).

You can't actually skip SET_VRING_CALL, it's necessary to start a vring,
so libvhost-user for example calls dev->iface->queue_set_started() only
in this case. The docs in the "Starting and stopping rings" section also
explain this.

> But it's important for performance to be able to enable polling.

I don't think if you enable this you care about performance, after all
the whole point of it is to get REPLY_ACK for the in-band message.

> > +  When the ``VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS`` protocol
> > +  feature has been successfully negotiated, this message may be
> > +  submitted by the master to indicate that a buffer was added to
> > +  the vring instead of signalling it using the vring's event FD or
> 
> event -> kick?
> fd -> file descriptor

Sure.

> > +  having the slave rely on polling.
> 
> i think polling is a separate option and should be there with inband
> kicks.

See above. But I guess we could put a flag into bit 9 indicating that
you want to use messages instead of polling or a file descriptor, if you
prefer.

> > +``VHOST_USER_SLAVE_VRING_CALL``
> > +  :id: 4
> > +  :equivalent ioctl: N/A
> > +  :slave payload: vring state description
> > +  :master payload: N/A
> > +
> > +  When the ``VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS`` protocol
> > +  feature has been successfully negotiated, this message may be
> > +  submitted by the slave to indicate that a buffer was used from
> > +  the vring instead of signalling this using the vring's kick FD or
> > +  having the master relying on polling.
> 
> call FD?

I confused this far too many times and thought I got it right finally,
but yes, you're right.

johannes




Re: [Qemu-devel] [RFC v2 1/2] docs: vhost-user: add in-band kick/call messages

2019-09-11 Thread Michael S. Tsirkin
On Wed, Sep 11, 2019 at 03:45:38PM +0200, Johannes Berg wrote:
> From: Johannes Berg 
> 
> For good reason, vhost-user is currently built asynchronously, that
> way better performance can be obtained. However, for certain use
> cases such as simulation, this is problematic.
> 
> Consider an event-based simulation in which both the device and CPU
> have scheduled according to a simulation "calendar". Now, consider
> the CPU sending I/O to the device, over a vring in the vhost-user
> protocol. In this case, the CPU must wait for the vring interrupt
> to have been processed by the device, so that the device is able to
> put an entry onto the simulation calendar to obtain time to handle
> the interrupt. Note that this doesn't mean the I/O is actually done
> at this time, it just means that the handling of it is scheduled
> before the CPU can continue running.
> 
> This cannot be done with the asynchronous eventfd based vring kick
> and call design.
> 
> Extend the protocol slightly, so that a message can be used for kick
> and call instead, if VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS is
> negotiated. This in itself doesn't guarantee synchronisation, but both
> sides can also negotiate VHOST_USER_PROTOCOL_F_REPLY_ACK and thus get
> a reply to this message by setting the need_reply flag, and ensure
> synchronisation this way.
> 
> To really use it in both directions, VHOST_USER_PROTOCOL_F_SLAVE_REQ
> is also needed.
> 
> Since it is used for simulation purposes and too many messages on
> the socket can lock up the virtual machine, document that this should
> only be used together with the mentioned features.
> 
> Signed-off-by: Johannes Berg 
> ---
>  docs/interop/vhost-user.rst | 113 ++--
>  1 file changed, 96 insertions(+), 17 deletions(-)
> 
> diff --git a/docs/interop/vhost-user.rst b/docs/interop/vhost-user.rst
> index 7827b710aa0a..c4396eabf9e9 100644
> --- a/docs/interop/vhost-user.rst
> +++ b/docs/interop/vhost-user.rst
> @@ -2,6 +2,7 @@
>  Vhost-user Protocol
>  ===
>  :Copyright: 2014 Virtual Open Systems Sarl.
> +:Copyright: 2019 Intel Corporation
>  :Licence: This work is licensed under the terms of the GNU GPL,
>version 2 or later. See the COPYING file in the top-level
>directory.
> @@ -279,6 +280,9 @@ If *master* is unable to send the full message or 
> receives a wrong
>  reply it will close the connection. An optional reconnection mechanism
>  can be implemented.
>  
> +If *slave* detects some error such as incompatible features, it may also
> +close the connection. This should only happen in exceptional circumstances.
> +
>  Any protocol extensions are gated by protocol feature bits, which
>  allows full backwards compatibility on both master and slave.  As
>  older slaves don't support negotiating protocol features, a feature
> @@ -315,7 +319,8 @@ it until ring is started, or after it has been stopped.
>  
>  Client must start ring upon receiving a kick (that is, detecting that
>  file descriptor is readable) on the descriptor specified by
> -``VHOST_USER_SET_VRING_KICK``, and stop ring upon receiving
> +``VHOST_USER_SET_VRING_KICK`` (or receiving the in-band message
> +``VHOST_USER_VRING_KICK`` if negotiated) and stop ring upon receiving
>  ``VHOST_USER_GET_VRING_BASE``.
>  
>  While processing the rings (whether they are enabled or not), client
> @@ -767,24 +772,48 @@ When reconnecting:
>  #. Resubmit inflight ``DescStatePacked`` entries in order of their
> counter value
>  
> +In-band notifications
> +-
> +
> +In some limited situations (e.g. for simulation) it is desirable to
> +have the kick, call and error (if used) signals done via in-band
> +messages instead of asynchronous eventfd notifications. This can be
> +done by negotiating the ``VHOST_USER_PROTOCOL_F_IN_BAND_NOTIFICATIONS``
> +protocol feature.
> +
> +Note that due to the fact that too many messages on the sockets can
> +cause the sending application(s) to block, it is not advised to use
> +this feature unless absolutely necessary. It is also considered an
> +error to negotiate this feature without also negotiating
> +``VHOST_USER_PROTOCOL_F_SLAVE_REQ`` and ``VHOST_USER_PROTOCOL_F_REPLY_ACK``,
> +the former is necessary for getting a message channel from the slave
> +to the master, while the latter needs to be used with the in-band
> +notification messages to block until they are processed, both to avoid
> +blocking later and for proper processing (at least in the simulation
> +use case.) As it has no other way of signalling this error, the slave
> +should close the connection as a response to a
> +``VHOST_USER_SET_PROTOCOL_FEATURES`` message that sets the in-band
> +notifications feature flag without the other two.
> +
>  Protocol features
>  -
>  
>  .. code:: c
>  
> -  #define VHOST_USER_PROTOCOL_F_MQ 0
> -  #define VHOST_USER_PROTOCOL_F_LOG_SHMFD  1
> -  #define VHOST_USER_PROTOCOL_F_RARP