Skip to contentSkip to conversation

content: document console vq detach buffer

PATCH In review Pankaj Gupta 3 participants 6 messages Aug 13, 2019 – Aug 19, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 content: document console vq detach buffer

This patch documents console special case where vq buffers are deleted at port hotunplug time. This behavior is different in other devices where vq buffers are deleted at device unplug time.

---
 content.tex | 2 ++
 1 file changed, 2 insertions(+)
content.tex +2 -0
index ee0d7c9..33e8ccc 100644
@@ -497,6 +497,8 @@ \section{Device Cleanup}\label{sec:General Initialization And Device Operation /
 of a live virtqueue.
 
 Thus a driver MUST ensure a virtqueue isn't live (by device reset) before removing exposed buffers.
+Console has a special property that when port is detached virtqueue is considered stopped, device
+must not use any buffers, and it is legal to take buffers out of the device.
 
 \chapter{Virtio Transport Options}\label{sec:Virtio Transport Options}
 
Signature · 6 lines
2.21.0


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
#1 lore raw
Quoted 14 lines · Pankaj Gupta

This patch documents console special case where vq buffers are deleted at port hotunplug time. This behavior is different in other devices where vq buffers are deleted at device unplug time.

---
 content.tex | 2 ++
 1 file changed, 2 insertions(+)
content.tex +0 -0
index ee0d7c9..33e8ccc 100644

content.tex \section{Device Cleanup}\label{sec:General Initialization And Device Operation / · line 501

Quoted 5 lines
content.tex +2 -0
@@ -497,6 +497,8 @@ \section{Device Cleanup}\label{sec:General Initialization And Device Operation /
 of a live virtqueue.
 
 Thus a driver MUST ensure a virtqueue isn't live (by device reset) before removing exposed buffers.
+Console has a special property that when port is detached virtqueue is considered stopped, device
+must not use any buffers, and it is legal to take buffers out of the device.

The word "detach" is not defined or used in the spec, so it's unclear what this is supposed to mean. Is this related to a control message (VIRTIO_CONSOLE_PORT_OPEN)?

How about:

The device MUST NOT use buffers after it has sent VIRTIO_CONSOLE_PORT_OPEN with value=0 for a port.

I'm not sure what you mean by "take buffers out of the device"? I guess you mean the driver can modify the vring because the device isn't looking.

#2 lore raw
Quoted 20 lines · Pankaj Gupta
Quoted 17 lines

This patch documents console special case where vq buffers are deleted at port hotunplug time. This behavior is different in other devices where vq buffers are deleted at device unplug time.

---
 content.tex | 2 ++
 1 file changed, 2 insertions(+)
content.tex +0 -0
index ee0d7c9..33e8ccc 100644
@@ -497,6 +497,8 @@ \section{Device Cleanup}\label{sec:General

Initialization And Device Operation /
of a live virtqueue.

Quoted 10 lines
Quoted 6 lines

Thus a driver MUST ensure a virtqueue isn't live (by device reset) before removing exposed buffers.
+Console has a special property that when port is detached virtqueue is considered stopped, device
+must not use any buffers, and it is legal to take buffers out of the device.

The word "detach" is not defined or used in the spec, so it's unclear what this is supposed to mean. Is this related to a control message (VIRTIO_CONSOLE_PORT_OPEN)?

By detach here we mean "unplug".

Quoted 9 lines

How about:

The device MUST NOT use buffers after it has sent VIRTIO_CONSOLE_PORT_OPEN with value=0 for a port.

I'm not sure what you mean by "take buffers out of the device"? I guess you mean the driver can modify the vring because the device isn't looking.

"take buffers out of the device" means "remove the unused buffers from the virt queue".

How about the below text:

Console has a special property that when port is unplugged virtqueue is considered stopped, device must not use any buffers, and it is legal to remove the unused buffers from the device.

Thanks,
Pankaj

Quoted 1 line

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#3 lore raw
Quoted 29 lines · Pankaj Gupta
Quoted 18 lines · Pankaj Gupta
Quoted 17 lines

This patch documents console special case where vq buffers are deleted at port hotunplug time. This behavior is different in other devices where vq buffers are deleted at device unplug time.

---
 content.tex | 2 ++
 1 file changed, 2 insertions(+)
content.tex +0 -0
index ee0d7c9..33e8ccc 100644
@@ -497,6 +497,8 @@ \section{Device Cleanup}\label{sec:General

Initialization And Device Operation /
of a live virtqueue.

Quoted 10 lines
Quoted 6 lines

Thus a driver MUST ensure a virtqueue isn't live (by device reset) before removing exposed buffers.
+Console has a special property that when port is detached virtqueue is considered stopped, device
+must not use any buffers, and it is legal to take buffers out of the device.

The word "detach" is not defined or used in the spec, so it's unclear what this is supposed to mean. Is this related to a control message (VIRTIO_CONSOLE_PORT_OPEN)?

Quoted 1 line

By detach here we mean "unplug".

"unplug" also has no meaning defined in the spec. Please explain things in terms of the actual device interface (control messages, config space fields, etc) so that the spec is clear. Which event or operation are you talking about?

Quoted 11 lines
Quoted 9 lines

How about:

The device MUST NOT use buffers after it has sent VIRTIO_CONSOLE_PORT_OPEN with value=0 for a port.

I'm not sure what you mean by "take buffers out of the device"? I guess you mean the driver can modify the vring because the device isn't looking.

"take buffers out of the device" means "remove the unused buffers from the virt queue".

What does "remove the unused buffers from the virt queue" mean? Decreasing the avail index (for split-ring virtqueue layouts) so that previously available buffers are no longer available?

Stefan

#4 lore raw
In reply to Pankaj Gupta
Quoted 14 lines · Pankaj Gupta

This patch documents console special case where vq buffers are deleted at port hotunplug time. This behavior is different in other devices where vq buffers are deleted at device unplug time.

---
 content.tex | 2 ++
 1 file changed, 2 insertions(+)
content.tex +0 -0
index ee0d7c9..33e8ccc 100644

content.tex \section{Device Cleanup}\label{sec:General Initialization And Device Operation / · line 503

Quoted 7 lines
content.tex +2 -0
@@ -497,6 +497,8 @@ \section{Device Cleanup}\label{sec:General Initialization And Device Operation /
 of a live virtqueue.
 
 Thus a driver MUST ensure a virtqueue isn't live (by device reset) before removing exposed buffers.
+Console has a special property that when port is detached virtqueue is considered stopped, device
+must not use any buffers, and it is legal to take buffers out of the device.
 
 \chapter{Virtio Transport Options}\label{sec:Virtio Transport Options}

I don't think that's enough, or a good way to do it.

The assumption that once exposed buffers stay exposed until used
is spread out in lots of places in the spec.
E.g.
2.6.6.1
Driver Requirements: The Virtqueue Available Ring
A driver MUST NOT decrement the available idx on a virtqueue (ie. there is no way to “unexpose” buffers).

And in the packed ring part, e.g.

A device MUST NOT use a descriptor unless it observes the VIRTQ_DESC_F_AVAIL bit in its flags being changed (e.g. as compared to the initial zero value). A device MUST NOT change a descriptor after changing it’s the VIRTQ_DESC_F_USED bit in its flags.
2.7.16
Driver Requirements: The Virtqueue Descriptor Table
A driver MUST NOT change a descriptor unless it observes the VIRTQ_DESC_F_USED bit in its flags being changed. A driver MUST NOT change a descriptor after changing the VIRTQ_DESC_F_AVAIL bit in its flags.

So we need to document how exactly to revert added buffers in all these places. I propose adding special sections, explaining that some devices allow taking back available buffers.

We need to see how this interacts with other places in the spec:
e.g. if we do allow taking back buffers, what happens with notifications such as when using event index? Are they resent when buffer is re-added?

I also worry that since the spec said this can't happen, some hypervisors might implement a policy that will crash if the guest violates this rule. Seems unlikely since Linux violated the rule for a while, but I'd suggest that you take a look at least at some open-source hypervisors to see what is going on. An alternative is a feature flag - if we do that I would actually advocate for a generic feature that allows stopping queues at any time, then restarting it. I think it would be handy generally for things like enabling/disabling XDP.

Quoted 2 lines
Signature · 1 line
2.21.0

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#5 lore raw
Quoted 27 lines · Pankaj Gupta
Quoted 24 lines

This patch documents console special case where vq buffers are deleted at port hotunplug time. This behavior is different in other devices where vq buffers are deleted at device unplug time.

---
 content.tex | 2 ++
 1 file changed, 2 insertions(+)
content.tex +0 -0
index ee0d7c9..33e8ccc 100644
@@ -497,6 +497,8 @@ \section{Device Cleanup}\label{sec:General

Initialization And Device Operation /
of a live virtqueue.

Thus a driver MUST ensure a virtqueue isn't live (by device reset) before removing exposed buffers.
+Console has a special property that when port is detached virtqueue is considered stopped, device
+must not use any buffers, and it is legal to take buffers out of the device.

Quoted 6 lines
Quoted 1 line

\chapter{Virtio Transport Options}\label{sec:Virtio Transport Options}

I don't think that's enough, or a good way to do it.

The assumption that once exposed buffers stay exposed until used is spread out in lots of places in the spec.

oh... I did not notice the other places.

Quoted 20 lines

E.g.
2.6.6.1
Driver Requirements: The Virtqueue Available Ring
A driver MUST NOT decrement the available idx on a virtqueue (ie. there is no way to “unexpose” buffers).

And in the packed ring part, e.g.

A device MUST NOT use a descriptor unless it observes the VIRTQ_DESC_F_AVAIL bit in its flags
being changed (e.g. as compared to the initial zero value). A device MUST NOT change a descriptor after
changing it’s the VIRTQ_DESC_F_USED bit in its flags.
2.7.16
Driver Requirements: The Virtqueue Descriptor Table
A driver MUST NOT change a descriptor unless it observes the VIRTQ_DESC_F_USED bit in its flags being
changed. A driver MUST NOT change a descriptor after changing the VIRTQ_DESC_F_AVAIL bit in its flags.

Quoted 3 lines

So we need to document how exactly to revert added buffers in all these places. I propose adding special sections, explaining that some devices allow taking back available buffers.

Sure.

Quoted 5 lines

We need to see how this interacts with other places in the spec:
e.g. if we do allow taking back buffers, what happens with notifications such as when using event index? Are they resent when buffer is re-added?

o.k. Will check this.

Quoted 7 lines

I also worry that since the spec said this can't happen, some hypervisors might implement a policy that will crash if the guest violates this rule. Seems unlikely since Linux violated the rule for a while, but I'd suggest that you take a look at least at some open-source hypervisors to see what is going on.

Good point. I will check.

An alternative is a feature flag -

Quoted 3 lines

if we do that I would actually advocate for a generic feature that allows stopping queues at any time, then restarting it. I think it would be handy generally for things like enabling/disabling XDP.

o.k. Good idea. Generic queue stopping will require additional work e.g draining the queue and might require certain device specific operation. Will look at this.

Thank you for the suggestions.

Best regards,
Pankaj

Quoted 6 lines
Quoted 5 lines

--
2.21.0

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]