* [Qemu-devel] [PATCH v3 1/1] virtio: serial: expose a 'guest_writable' callback for users
@ 2014-10-28 14:51 Amit Shah
2014-10-28 15:18 ` Marc-André Lureau
2014-11-13 14:47 ` Gerd Hoffmann
0 siblings, 2 replies; 6+ messages in thread
From: Amit Shah @ 2014-10-28 14:51 UTC (permalink / raw)
To: qemu list
Cc: Peter Maydell, Markus Armbruster, Gerd Hoffmann, Amit Shah,
marcandre.lureau, Amos Kong
Users of virtio-serial may want to know when a port becomes writable. A
port can stop accepting writes if the guest port is open but not being
read from. In this case, data gets queued up in the virtqueue, and
after the vq is full, writes to the port do not succeed.
When the guest reads off a vq element, and adds a new one for the host
to put data in, we can tell users the port is available for more writes,
via the new ->guest_writable() callback.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
v3: document the semantics of the callback (Peter Maydell, Markus)
v2: check for port != NULL (Peter Maydell)
---
hw/char/virtio-serial-bus.c | 31 +++++++++++++++++++++++++++++++
include/hw/virtio/virtio-serial.h | 11 +++++++++++
2 files changed, 42 insertions(+)
diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index c6870f1..bea7a17 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -465,6 +465,37 @@ static void handle_output(VirtIODevice *vdev, VirtQueue *vq)
static void handle_input(VirtIODevice *vdev, VirtQueue *vq)
{
+ /*
+ * Users of virtio-serial would like to know when guest becomes
+ * writable again -- i.e. if a vq had stuff queued up and the
+ * guest wasn't reading at all, the host would not be able to
+ * write to the vq anymore. Once the guest reads off something,
+ * we can start queueing things up again. However, this call is
+ * made for each buffer addition by the guest -- even though free
+ * buffers existed prior to the current buffer addition. This is
+ * done so as not to maintain previous state, which will need
+ * additional live-migration-related changes.
+ */
+ VirtIOSerial *vser;
+ VirtIOSerialPort *port;
+ VirtIOSerialPortClass *vsc;
+
+ vser = VIRTIO_SERIAL(vdev);
+ port = find_port_by_vq(vser, vq);
+
+ if (!port) {
+ return;
+ }
+ vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port);
+
+ /*
+ * If guest_connected is false, this call is being made by the
+ * early-boot queueing up of descriptors, which is just noise for
+ * the host apps -- don't disturb them in that case.
+ */
+ if (port->guest_connected && port->host_connected && vsc->guest_writable) {
+ vsc->guest_writable(port);
+ }
}
static uint32_t get_features(VirtIODevice *vdev, uint32_t features)
diff --git a/include/hw/virtio/virtio-serial.h b/include/hw/virtio/virtio-serial.h
index a679e54..fe6e696 100644
--- a/include/hw/virtio/virtio-serial.h
+++ b/include/hw/virtio/virtio-serial.h
@@ -98,6 +98,17 @@ typedef struct VirtIOSerialPortClass {
/* Guest is now ready to accept data (virtqueues set up). */
void (*guest_ready)(VirtIOSerialPort *port);
+ /*
+ * Guest has enqueued a buffer for the host to write into.
+ * Called each time a buffer is enqueued by the guest;
+ * irrespective of whether there already were free buffers the
+ * host could have consumed.
+ *
+ * This is dependent on both, the guest and host ends being
+ * connected.
+ */
+ void (*guest_writable)(VirtIOSerialPort *port);
+
/*
* Guest wrote some data to the port. This data is handed over to
* the app via this callback. The app can return a size less than
--
1.9.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v3 1/1] virtio: serial: expose a 'guest_writable' callback for users
2014-10-28 14:51 [Qemu-devel] [PATCH v3 1/1] virtio: serial: expose a 'guest_writable' callback for users Amit Shah
@ 2014-10-28 15:18 ` Marc-André Lureau
2014-11-13 14:47 ` Gerd Hoffmann
1 sibling, 0 replies; 6+ messages in thread
From: Marc-André Lureau @ 2014-10-28 15:18 UTC (permalink / raw)
To: Amit Shah
Cc: Peter Maydell, qemu list, Markus Armbruster, Gerd Hoffmann,
marcandre lureau, Amos Kong
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
I have a somewhat related question, that perhaps someone may help me with:
Why isn't the qemu char driver/device interface based (for most devices)
on socketpair (and equivalent bi-directional pipe on other OS).
It looks to me like it could simplify API and event handling on both fe/be
sides, although it may cost a few more open fds and additional copy.
----- Mail original -----
> Users of virtio-serial may want to know when a port becomes writable. A
> port can stop accepting writes if the guest port is open but not being
> read from. In this case, data gets queued up in the virtqueue, and
> after the vq is full, writes to the port do not succeed.
>
> When the guest reads off a vq element, and adds a new one for the host
> to put data in, we can tell users the port is available for more writes,
> via the new ->guest_writable() callback.
>
> Signed-off-by: Amit Shah <amit.shah@redhat.com>
>
> ---
> v3: document the semantics of the callback (Peter Maydell, Markus)
> v2: check for port != NULL (Peter Maydell)
> ---
> hw/char/virtio-serial-bus.c | 31 +++++++++++++++++++++++++++++++
> include/hw/virtio/virtio-serial.h | 11 +++++++++++
> 2 files changed, 42 insertions(+)
>
> diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
> index c6870f1..bea7a17 100644
> --- a/hw/char/virtio-serial-bus.c
> +++ b/hw/char/virtio-serial-bus.c
> @@ -465,6 +465,37 @@ static void handle_output(VirtIODevice *vdev, VirtQueue
> *vq)
>
> static void handle_input(VirtIODevice *vdev, VirtQueue *vq)
> {
> + /*
> + * Users of virtio-serial would like to know when guest becomes
> + * writable again -- i.e. if a vq had stuff queued up and the
> + * guest wasn't reading at all, the host would not be able to
> + * write to the vq anymore. Once the guest reads off something,
> + * we can start queueing things up again. However, this call is
> + * made for each buffer addition by the guest -- even though free
> + * buffers existed prior to the current buffer addition. This is
> + * done so as not to maintain previous state, which will need
> + * additional live-migration-related changes.
> + */
> + VirtIOSerial *vser;
> + VirtIOSerialPort *port;
> + VirtIOSerialPortClass *vsc;
> +
> + vser = VIRTIO_SERIAL(vdev);
> + port = find_port_by_vq(vser, vq);
> +
> + if (!port) {
> + return;
> + }
> + vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port);
> +
> + /*
> + * If guest_connected is false, this call is being made by the
> + * early-boot queueing up of descriptors, which is just noise for
> + * the host apps -- don't disturb them in that case.
> + */
> + if (port->guest_connected && port->host_connected &&
> vsc->guest_writable) {
> + vsc->guest_writable(port);
> + }
> }
>
> static uint32_t get_features(VirtIODevice *vdev, uint32_t features)
> diff --git a/include/hw/virtio/virtio-serial.h
> b/include/hw/virtio/virtio-serial.h
> index a679e54..fe6e696 100644
> --- a/include/hw/virtio/virtio-serial.h
> +++ b/include/hw/virtio/virtio-serial.h
> @@ -98,6 +98,17 @@ typedef struct VirtIOSerialPortClass {
> /* Guest is now ready to accept data (virtqueues set up). */
> void (*guest_ready)(VirtIOSerialPort *port);
>
> + /*
> + * Guest has enqueued a buffer for the host to write into.
> + * Called each time a buffer is enqueued by the guest;
> + * irrespective of whether there already were free buffers the
> + * host could have consumed.
> + *
> + * This is dependent on both, the guest and host ends being
> + * connected.
> + */
> + void (*guest_writable)(VirtIOSerialPort *port);
> +
> /*
> * Guest wrote some data to the port. This data is handed over to
> * the app via this callback. The app can return a size less than
> --
> 1.9.3
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v3 1/1] virtio: serial: expose a 'guest_writable' callback for users
2014-10-28 14:51 [Qemu-devel] [PATCH v3 1/1] virtio: serial: expose a 'guest_writable' callback for users Amit Shah
2014-10-28 15:18 ` Marc-André Lureau
@ 2014-11-13 14:47 ` Gerd Hoffmann
2014-11-13 14:52 ` Peter Maydell
2014-11-14 1:48 ` Amit Shah
1 sibling, 2 replies; 6+ messages in thread
From: Gerd Hoffmann @ 2014-11-13 14:47 UTC (permalink / raw)
To: Amit Shah
Cc: Peter Maydell, Amos Kong, qemu list, marcandre.lureau,
Markus Armbruster
On Di, 2014-10-28 at 20:21 +0530, Amit Shah wrote:
> Users of virtio-serial may want to know when a port becomes writable. A
> port can stop accepting writes if the guest port is open but not being
> read from. In this case, data gets queued up in the virtqueue, and
> after the vq is full, writes to the port do not succeed.
>
> When the guest reads off a vq element, and adds a new one for the host
> to put data in, we can tell users the port is available for more writes,
> via the new ->guest_writable() callback.
>
> Signed-off-by: Amit Shah <amit.shah@redhat.com>
What is the plan with that one? I have some spice patches sitting in a
branch depending on this one. Should it go through virtio queue? With
some ack from virtio I can also take it through the spice queue,
together with the other patches depending on this one.
It fails checkpatch btw:
=== checkpatch complains ===
ERROR: code indent should never use tabs
#53: FILE: include/hw/virtio/virtio-serial.h:102:
+^I * Guest has enqueued a buffer for the host to write into.$
[ ... more of these snipped ... ]
cheers,
Gerd
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v3 1/1] virtio: serial: expose a 'guest_writable' callback for users
2014-11-13 14:47 ` Gerd Hoffmann
@ 2014-11-13 14:52 ` Peter Maydell
2014-11-13 14:56 ` Gerd Hoffmann
2014-11-14 1:48 ` Amit Shah
1 sibling, 1 reply; 6+ messages in thread
From: Peter Maydell @ 2014-11-13 14:52 UTC (permalink / raw)
To: Gerd Hoffmann
Cc: Amit Shah, Marc-André Lureau, Amos Kong, qemu list,
Markus Armbruster
On 13 November 2014 14:47, Gerd Hoffmann <kraxel@redhat.com> wrote:
> On Di, 2014-10-28 at 20:21 +0530, Amit Shah wrote:
>> Users of virtio-serial may want to know when a port becomes writable. A
>> port can stop accepting writes if the guest port is open but not being
>> read from. In this case, data gets queued up in the virtqueue, and
>> after the vq is full, writes to the port do not succeed.
>>
>> When the guest reads off a vq element, and adds a new one for the host
>> to put data in, we can tell users the port is available for more writes,
>> via the new ->guest_writable() callback.
>>
>> Signed-off-by: Amit Shah <amit.shah@redhat.com>
>
> What is the plan with that one?
It missed the hardfreeze deadline and is heading for 2.3 instead.
thanks
-- PMM
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v3 1/1] virtio: serial: expose a 'guest_writable' callback for users
2014-11-13 14:52 ` Peter Maydell
@ 2014-11-13 14:56 ` Gerd Hoffmann
0 siblings, 0 replies; 6+ messages in thread
From: Gerd Hoffmann @ 2014-11-13 14:56 UTC (permalink / raw)
To: Peter Maydell
Cc: Amit Shah, Marc-André Lureau, Amos Kong, qemu list,
Markus Armbruster
On Do, 2014-11-13 at 14:52 +0000, Peter Maydell wrote:
> On 13 November 2014 14:47, Gerd Hoffmann <kraxel@redhat.com> wrote:
> > On Di, 2014-10-28 at 20:21 +0530, Amit Shah wrote:
> >> Users of virtio-serial may want to know when a port becomes writable. A
> >> port can stop accepting writes if the guest port is open but not being
> >> read from. In this case, data gets queued up in the virtqueue, and
> >> after the vq is full, writes to the port do not succeed.
> >>
> >> When the guest reads off a vq element, and adds a new one for the host
> >> to put data in, we can tell users the port is available for more writes,
> >> via the new ->guest_writable() callback.
> >>
> >> Signed-off-by: Amit Shah <amit.shah@redhat.com>
> >
> > What is the plan with that one?
>
> It missed the hardfreeze deadline and is heading for 2.3 instead.
Sure, I didn't plan to squeeze it into 2.2, but the question remains
valid even when targeting 2.3 ;)
cheers,
Gerd
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v3 1/1] virtio: serial: expose a 'guest_writable' callback for users
2014-11-13 14:47 ` Gerd Hoffmann
2014-11-13 14:52 ` Peter Maydell
@ 2014-11-14 1:48 ` Amit Shah
1 sibling, 0 replies; 6+ messages in thread
From: Amit Shah @ 2014-11-14 1:48 UTC (permalink / raw)
To: Gerd Hoffmann
Cc: Peter Maydell, Amos Kong, qemu list, marcandre.lureau,
Markus Armbruster
On (Thu) 13 Nov 2014 [15:47:12], Gerd Hoffmann wrote:
> On Di, 2014-10-28 at 20:21 +0530, Amit Shah wrote:
> > Users of virtio-serial may want to know when a port becomes writable. A
> > port can stop accepting writes if the guest port is open but not being
> > read from. In this case, data gets queued up in the virtqueue, and
> > after the vq is full, writes to the port do not succeed.
> >
> > When the guest reads off a vq element, and adds a new one for the host
> > to put data in, we can tell users the port is available for more writes,
> > via the new ->guest_writable() callback.
> >
> > Signed-off-by: Amit Shah <amit.shah@redhat.com>
>
> What is the plan with that one? I have some spice patches sitting in a
> branch depending on this one. Should it go through virtio queue? With
> some ack from virtio I can also take it through the spice queue,
> together with the other patches depending on this one.
I will push it through my tree when 2.3 opens.
> It fails checkpatch btw:
Yes, v4 (in the pull req) corrected this.
Thanks,
Amit
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-11-14 1:48 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-28 14:51 [Qemu-devel] [PATCH v3 1/1] virtio: serial: expose a 'guest_writable' callback for users Amit Shah
2014-10-28 15:18 ` Marc-André Lureau
2014-11-13 14:47 ` Gerd Hoffmann
2014-11-13 14:52 ` Peter Maydell
2014-11-13 14:56 ` Gerd Hoffmann
2014-11-14 1:48 ` Amit Shah
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).