ring: Forbid using descriptors in two chains at once
RFC PATCH 1/1 ring: Forbid using descriptors in two chains at once
Using the same descriptor in multiple chains at once creates difficulties. If the descriptor is device-writeable, this is begging for data corruption due to conflicting writes from the device. Even if the descriptor is device-readable, the mere possibility requires devices to use more sophisticated internal data structures.
Require descriptors to be used in at most one chain at any given time. Indirect descriptors can be used if support for huge batches is needed.
---
I have not checked whether this will break existing drivers, so I'm marking this as RFC for now.
--- packed-ring.tex | 6 ++++++ split-ring.tex | 6 ++++++ 2 files changed, 12 insertions(+)
packed-ring.tex +6 -0
@@ -473,6 +473,12 @@ \subsection{Event Suppression Structure Format}\label{sec:Basic This implies that loops in the descriptor list are forbidden! +Drivers MUST NOT include a descriptor in a chain if the +descriptor is already part of a previous chain whose processing +has not completed. This implies that the total number of +descriptors submitted to the device, but not yet processed, is +limited by the queue size. + The driver MUST place any device-writable descriptor elements after any device-readable descriptor elements.
split-ring.tex +6 -0
@@ -223,6 +223,12 @@ \subsection{The Virtqueue Descriptor Table}\label{sec:Basic Facilities of a Virt Drivers MUST NOT add a descriptor chain longer than $2^{32}$ bytes in total; this implies that loops in the descriptor chain are forbidden! +Drivers MUST NOT include a descriptor in a chain if the +descriptor is already part of a previous chain whose processing +has not completed. This implies that the total number of +descriptors submitted to the device, but not yet processed, is +limited by the queue size. + If VIRTIO_F_IN_ORDER has been negotiated, and when making a descriptor with VRING_DESC_F_NEXT set in \field{flags} at offset $x$ in the table available to the device, driver MUST set
Signature · 1 line
2.54.0
Quoted 5 lines · Demi Marie Obenour
Using the same descriptor in multiple chains at once creates difficulties. If the descriptor is device-writeable, this is begging for data corruption due to conflicting writes from the device. Even if the descriptor is device-readable, the mere possibility requires devices to use more sophisticated internal data structures.
The natural way to index requests is by using the avail ring head, not descriptors, though? I suspect it's about device memory being limited, etc. But pls make it more explicit.
Quoted 2 lines
Require descriptors to be used in at most one chain at any given time. Indirect descriptors can be used if support for huge batches is needed.
does this imply indirect are exempt from this rule? the text you propose makes no such exemptions.
Quoted 15 lines
Signed-off-by Demi Marie Obenour <[email protected]>---
I have not checked whether this will break existing drivers, so I'm marking this as RFC for now.--- packed-ring.tex | 6 ++++++ split-ring.tex | 6 ++++++ 2 files changed, 12 insertions(+)packed-ring.tex +0
-0
packed-ring.tex \subsection{Event Suppression Structure Format}\label{sec:Basic · line 480
Quoted 8 lines
packed-ring.tex +5
-0@@ -473,6 +473,12 @@ \subsection{Event Suppression Structure Format}\label{sec:Basic This implies that loops in the descriptor list are forbidden! +Drivers MUST NOT include a descriptor in a chain if the +descriptor is already part of a previous chain whose processing +has not completed. This implies that the total number of +descriptors submitted to the device, but not yet processed, is +limited by the queue size.
I do not understand what is this trying to say for the packed ring. How do you include a descriptor in a chain twice - the ring has to wrap around, no?
For that matter, I do not think "This implies that loops in the descriptor list are forbidden!" makes sense for packed either - I think we copied it from split by mistake.
Quoted 9 lines
packed-ring.tex +1
-0+ The driver MUST place any device-writable descriptor elements after any device-readable descriptor elements.split-ring.tex +0
-0
split-ring.tex \subsection{The Virtqueue Descriptor Table}\label{sec:Basic Facilities of a Virt · line 228
Quoted 6 lines
split-ring.tex +3
-0@@ -223,6 +223,12 @@ \subsection{The Virtqueue Descriptor Table}\label{sec:Basic Facilities of a Virt Drivers MUST NOT add a descriptor chain longer than $2^{32}$ bytes in total; this implies that loops in the descriptor chain are forbidden! +Drivers MUST NOT include a descriptor in a chain if the +descriptor is already part of a previous chain whose processing +has not completed.
what specifically is "include a descriptor in a chain"? something to do with making a head available? and what is "whose processing has not completed"? something to do with a head not used?
Quoted 7 lines
split-ring.tex +3
-0This implies that the total number of +descriptors submitted to the device, but not yet processed, is +limited by the queue size. + If VIRTIO_F_IN_ORDER has been negotiated, and when making a descriptor with VRING_DESC_F_NEXT set in \field{flags} at offset$x$ in the table available to the device, driver MUST set
We can't really introduce new mandatory requirements without a feature bit.
Quoted 3 lines
Signature · 1 line
2.54.0
Quoted 10 lines · Michael S. Tsirkin
Quoted 5 lines · Demi Marie Obenour
Using the same descriptor in multiple chains at once creates difficulties. If the descriptor is device-writeable, this is begging for data corruption due to conflicting writes from the device. Even if the descriptor is device-readable, the mere possibility requires devices to use more sophisticated internal data structures.
The natural way to index requests is by using the avail ring head, not descriptors, though? I suspect it's about device memory being limited, etc. But pls make it more explicit.
It's about being able to *not* use scatter-gather I/O, and instead use a single I/O request for each descriptor. io_uring makes this very cheap. However, it requires that the lookup key be (avail ring head, descriptor index) rather than just (avail ring head).
The latter has sufficiently few possibilities one can just use a bitmap. The former isn't. This means using a memory pool, heap allocation, or associative container.
Quoted 5 lines
Quoted 2 lines
Require descriptors to be used in at most one chain at any given time. Indirect descriptors can be used if support for huge batches is needed.
does this imply indirect are exempt from this rule? the text you propose makes no such exemptions.
It means that indirect descriptors can point to huge numbers of descriptors, rather than just what fits in the descriptor ring.
Quoted 17 lines
Quoted 17 lines
Signed-off-by Demi Marie Obenour <[email protected]>---
I have not checked whether this will break existing drivers, so I'm marking this as RFC for now.--- packed-ring.tex | 6 ++++++ split-ring.tex | 6 ++++++ 2 files changed, 12 insertions(+)packed-ring.tex +0
-0@@ -473,6 +473,12 @@ \subsection{Event Suppression Structure Format}\label{sec:Basic This implies that loops in the descriptor list are forbidden!
Quoted 9 lines
packed-ring.tex \subsection{Event Suppression Structure Format}\label{sec:Basic · line 480
Quoted 5 lines
packed-ring.tex +5
-0+Drivers MUST NOT include a descriptor in a chain if the +descriptor is already part of a previous chain whose processing +has not completed. This implies that the total number of +descriptors submitted to the device, but not yet processed, is +limited by the queue size.I do not understand what is this trying to say for the packed ring. How do you include a descriptor in a chain twice - the ring has to wrap around, no?
I don't think you can.
Quoted 3 lines
For that matter, I do not think "This implies that loops in the descriptor list are forbidden!" makes sense for packed either - I think we copied it from split by mistake.
Fair.
Quoted 20 lines
Quoted 9 lines
packed-ring.tex +1
-0+ The driver MUST place any device-writable descriptor elements after any device-readable descriptor elements.split-ring.tex +0
-0split-ring.tex \subsection{The Virtqueue Descriptor Table}\label{sec:Basic Facilities of a Virt · line 228
Quoted 6 lines
split-ring.tex +3
-0@@ -223,6 +223,12 @@ \subsection{The Virtqueue Descriptor Table}\label{sec:Basic Facilities of a Virt Drivers MUST NOT add a descriptor chain longer than $2^{32}$ bytes in total; this implies that loops in the descriptor chain are forbidden! +Drivers MUST NOT include a descriptor in a chain if the +descriptor is already part of a previous chain whose processing +has not completed.what specifically is "include a descriptor in a chain"? something to do with making a head available? and what is "whose processing has not completed"? something to do with a head not used?
Quoted 10 lines
Quoted 7 lines
split-ring.tex +3
-0This implies that the total number of +descriptors submitted to the device, but not yet processed, is +limited by the queue size. + If VIRTIO_F_IN_ORDER has been negotiated, and when making a descriptor with VRING_DESC_F_NEXT set in \field{flags} at offset$x$ in the table available to the device, driver MUST set
We can't really introduce new mandatory requirements without a feature bit.
I'm making the assumption that no existing driver actually violates this rule. That said, another option would be to force any driver that does violate it onto a slow path, perhaps by serializing the I/O operations.
As an aside, this is why the spec I am working on for the vhost-user device backend has seemingly arbitrary restrictions around MSI-X interrupts. It makes life easier for device authors.
Finally, I understand if this isn't viable. It can be worked around in devices without *too* much complexity.
Signature · 2 lines
Sincerely, Demi Marie Obenour (she/her/hers)
Quoted 21 lines · Demi Marie Obenour
Quoted 10 lines · Michael S. Tsirkin
Quoted 5 lines · Demi Marie Obenour
Using the same descriptor in multiple chains at once creates difficulties. If the descriptor is device-writeable, this is begging for data corruption due to conflicting writes from the device. Even if the descriptor is device-readable, the mere possibility requires devices to use more sophisticated internal data structures.
The natural way to index requests is by using the avail ring head, not descriptors, though? I suspect it's about device memory being limited, etc. But pls make it more explicit.
It's about being able to *not* use scatter-gather I/O, and instead use a single I/O request for each descriptor.
io_uringmakes this very cheap. However, it requires that the lookup key be (avail ring head, descriptor index) rather than just (avail ring head).The latter has sufficiently few possibilities one can just use a bitmap. The former isn't. This means using a memory pool, heap allocation, or associative container.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Require descriptors to be used in at most one chain at any given time. Indirect descriptors can be used if support for huge batches is needed.
does this imply indirect are exempt from this rule? the text you propose makes no such exemptions.
It means that indirect descriptors can point to huge numbers of descriptors, rather than just what fits in the descriptor ring.
Nope, the spec limits the chain size to ring size.
Quoted 71 lines
Quoted 17 lines
Quoted 17 lines
Signed-off-by Demi Marie Obenour <[email protected]>---
I have not checked whether this will break existing drivers, so I'm marking this as RFC for now.--- packed-ring.tex | 6 ++++++ split-ring.tex | 6 ++++++ 2 files changed, 12 insertions(+)packed-ring.tex +0
-0@@ -473,6 +473,12 @@ \subsection{Event Suppression Structure Format}\label{sec:Basic This implies that loops in the descriptor list are forbidden!Quoted 9 lines
packed-ring.tex \subsection{Event Suppression Structure Format}\label{sec:Basic · line 480
Quoted 5 lines
packed-ring.tex +5
-0+Drivers MUST NOT include a descriptor in a chain if the +descriptor is already part of a previous chain whose processing +has not completed. This implies that the total number of +descriptors submitted to the device, but not yet processed, is +limited by the queue size.I do not understand what is this trying to say for the packed ring. How do you include a descriptor in a chain twice - the ring has to wrap around, no?
I don't think you can.
Quoted 3 lines
For that matter, I do not think "This implies that loops in the descriptor list are forbidden!" makes sense for packed either - I think we copied it from split by mistake.
Fair.
Quoted 20 lines
Quoted 9 lines
packed-ring.tex +1
-0+ The driver MUST place any device-writable descriptor elements after any device-readable descriptor elements.split-ring.tex +0
-0split-ring.tex \subsection{The Virtqueue Descriptor Table}\label{sec:Basic Facilities of a Virt · line 228
Quoted 6 lines
split-ring.tex +3
-0@@ -223,6 +223,12 @@ \subsection{The Virtqueue Descriptor Table}\label{sec:Basic Facilities of a Virt Drivers MUST NOT add a descriptor chain longer than $2^{32}$ bytes in total; this implies that loops in the descriptor chain are forbidden! +Drivers MUST NOT include a descriptor in a chain if the +descriptor is already part of a previous chain whose processing +has not completed.what specifically is "include a descriptor in a chain"? something to do with making a head available? and what is "whose processing has not completed"? something to do with a head not used?
Quoted 10 lines
Quoted 7 lines
split-ring.tex +3
-0This implies that the total number of +descriptors submitted to the device, but not yet processed, is +limited by the queue size. + If VIRTIO_F_IN_ORDER has been negotiated, and when making a descriptor with VRING_DESC_F_NEXT set in \field{flags} at offset$x$ in the table available to the device, driver MUST set
We can't really introduce new mandatory requirements without a feature bit.
I'm making the assumption that no existing driver actually violates this rule. That said, another option would be to force any driver that does violate it onto a slow path, perhaps by serializing the I/O operations.
Quoted 9 lines
As an aside, this is why the spec I am working on for the vhost-user device backend has seemingly arbitrary restrictions around MSI-X interrupts. It makes life easier for device authors.
Finally, I understand if this isn't viable. It can be worked around in devices without *too* much complexity.
Signature · 2 lines
Sincerely, Demi Marie Obenour (she/her/hers)
We have two options:
- a new feature bit + if negotiated, driver MUST.
device can decide if it wants to support drivers without a feature bit
- a recommendation (driver SHOULD)
Signature · 1 line
MST
Quoted 25 lines · Michael S. Tsirkin
Quoted 24 lines · Demi Marie Obenour
Quoted 10 lines · Michael S. Tsirkin
Quoted 5 lines · Demi Marie Obenour
Using the same descriptor in multiple chains at once creates difficulties. If the descriptor is device-writeable, this is begging for data corruption due to conflicting writes from the device. Even if the descriptor is device-readable, the mere possibility requires devices to use more sophisticated internal data structures.
The natural way to index requests is by using the avail ring head, not descriptors, though? I suspect it's about device memory being limited, etc. But pls make it more explicit.
It's about being able to *not* use scatter-gather I/O, and instead use a single I/O request for each descriptor.
io_uringmakes this very cheap. However, it requires that the lookup key be (avail ring head, descriptor index) rather than just (avail ring head).The latter has sufficiently few possibilities one can just use a bitmap. The former isn't. This means using a memory pool, heap allocation, or associative container.
Quoted 3 lines
Quoted 2 lines
Require descriptors to be used in at most one chain at any given time. Indirect descriptors can be used if support for huge batches is needed.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
does this imply indirect are exempt from this rule? the text you propose makes no such exemptions.
It means that indirect descriptors can point to huge numbers of descriptors, rather than just what fits in the descriptor ring.
Nope, the spec limits the chain size to ring size.
Oh, I see.
Quoted 81 lines
Quoted 71 lines
Quoted 17 lines
Quoted 17 lines
Signed-off-by Demi Marie Obenour <[email protected]>---
I have not checked whether this will break existing drivers, so I'm marking this as RFC for now.--- packed-ring.tex | 6 ++++++ split-ring.tex | 6 ++++++ 2 files changed, 12 insertions(+)packed-ring.tex +0
-0@@ -473,6 +473,12 @@ \subsection{Event Suppression Structure Format}\label{sec:Basic This implies that loops in the descriptor list are forbidden!Quoted 9 lines
packed-ring.tex \subsection{Event Suppression Structure Format}\label{sec:Basic · line 480
Quoted 5 lines
packed-ring.tex +5
-0+Drivers MUST NOT include a descriptor in a chain if the +descriptor is already part of a previous chain whose processing +has not completed. This implies that the total number of +descriptors submitted to the device, but not yet processed, is +limited by the queue size.I do not understand what is this trying to say for the packed ring. How do you include a descriptor in a chain twice - the ring has to wrap around, no?
I don't think you can.
Quoted 3 lines
For that matter, I do not think "This implies that loops in the descriptor list are forbidden!" makes sense for packed either - I think we copied it from split by mistake.
Fair.
Quoted 20 lines
Quoted 9 lines
packed-ring.tex +1
-0+ The driver MUST place any device-writable descriptor elements after any device-readable descriptor elements.split-ring.tex +0
-0split-ring.tex \subsection{The Virtqueue Descriptor Table}\label{sec:Basic Facilities of a Virt · line 228
Quoted 6 lines
split-ring.tex +3
-0@@ -223,6 +223,12 @@ \subsection{The Virtqueue Descriptor Table}\label{sec:Basic Facilities of a Virt Drivers MUST NOT add a descriptor chain longer than $2^{32}$ bytes in total; this implies that loops in the descriptor chain are forbidden! +Drivers MUST NOT include a descriptor in a chain if the +descriptor is already part of a previous chain whose processing +has not completed.what specifically is "include a descriptor in a chain"? something to do with making a head available? and what is "whose processing has not completed"? something to do with a head not used?
Quoted 10 lines
Quoted 7 lines
split-ring.tex +3
-0This implies that the total number of +descriptors submitted to the device, but not yet processed, is +limited by the queue size. + If VIRTIO_F_IN_ORDER has been negotiated, and when making a descriptor with VRING_DESC_F_NEXT set in \field{flags} at offset$x$ in the table available to the device, driver MUST set
We can't really introduce new mandatory requirements without a feature bit.
I'm making the assumption that no existing driver actually violates this rule. That said, another option would be to force any driver that does violate it onto a slow path, perhaps by serializing the I/O operations.
Quoted 9 lines
As an aside, this is why the spec I am working on for the vhost-user device backend has seemingly arbitrary restrictions around MSI-X interrupts. It makes life easier for device authors.
Finally, I understand if this isn't viable. It can be worked around in devices without *too* much complexity.
Signature · 2 lines
Sincerely, Demi Marie Obenour (she/her/hers)
Quoted 4 lines
We have two options:
- a new feature bit + if negotiated, driver MUST.
device can decide if it wants to support drivers without a feature bit
- a recommendation (driver SHOULD)
I'm going to drop this. Neither removes any complexity from device implementations that need to work with existing drivers.
My hope was that no existing driver actually relied on being able to use a descriptor in two chains at once. If that is true, disallowing it would not break any code in the wild.
However, that only works if one can enumerate the existing drivers that are out there. There might be proprietary drivers deployed in closed environments that never see the light of day. So this reasoning doesn't work.
This leaves otherwise-unfixable security holes as the only justification I can think of for this kind of change.
Signature · 2 lines
Sincerely, Demi Marie Obenour (she/her/hers)