Skip to contentSkip to conversation

virtio: virtio_config_ops documentation

PATCH In review Cornelia Huck 4 participants 20 messages Jan 3, 2019 – Jan 15, 2019 virtio core

lore
Share & tools
lore
#0 lore raw

cover virtio: virtio_config_ops documentation

After the latest virtio-balloon changes, it became clear that it is not obvious that some of the virtio operations (e.g. reading or writing the config space) cannot be done from an atomic context for all transports.

At least try to document that, and also fix some inconsistencies I noticed along the way.

Cornelia Huck (2):
virtio: fix virtio_config_ops description
virtio: document virtio_config_ops restrictions

 include/linux/virtio_config.h | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
Signature · 6 lines
2.17.2


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
#1 lore raw

PATCH 1/2 virtio: fix virtio_config_ops description

- get_features has returned 64 bits since commit d025477368792 ("virtio: add support for 64 bit features.")
- properly mark all optional callbacks

---
 include/linux/virtio_config.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/virtio_config.h +4 -4
index 32baf8e26735..7087ef946ba7 100644
@@ -22,7 +22,7 @@ struct irq_affinity;
  *	offset: the offset of the configuration field
  *	buf: the buffer to read the field value from.
  *	len: the length of the buffer
- * @generation: config generation counter
+ * @generation: config generation counter (optional)
  *	vdev: the virtio_device
  *	Returns the config generation counter
  * @get_status: read the status byte
@@ -48,17 +48,17 @@ struct irq_affinity;
  * @del_vqs: free virtqueues found by find_vqs().
  * @get_features: get the array of feature bits for this device.
  *	vdev: the virtio_device
- *	Returns the first 32 feature bits (all we currently need).
+ *	Returns the first 64 feature bits (all we currently need).
  * @finalize_features: confirm what device features we'll be using.
  *	vdev: the virtio_device
  *	This gives the final feature bits for the device: it can change
  *	the dev->feature bits if it wants.
  *	Returns 0 on success or error status
- * @bus_name: return the bus name associated with the device
+ * @bus_name: return the bus name associated with the device (optional)
  *	vdev: the virtio_device
  *      This returns a pointer to the bus name a la pci_name from which
  *      the caller can then copy.
- * @set_vq_affinity: set the affinity for a virtqueue.
+ * @set_vq_affinity: set the affinity for a virtqueue (optional).
  * @get_vq_affinity: get the affinity for a virtqueue (optional).
  */
 typedef void vq_callback_t(struct virtqueue *);
Signature · 1 line
2.17.2
#2 lore raw

PATCH 1/2 virtio: fix virtio_config_ops description

In reply to Cornelia Huck

- get_features has returned 64 bits since commit d025477368792 ("virtio: add support for 64 bit features.")
- properly mark all optional callbacks

---
 include/linux/virtio_config.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/virtio_config.h +4 -4
index 32baf8e26735..7087ef946ba7 100644
@@ -22,7 +22,7 @@ struct irq_affinity;
  *	offset: the offset of the configuration field
  *	buf: the buffer to read the field value from.
  *	len: the length of the buffer
- * @generation: config generation counter
+ * @generation: config generation counter (optional)
  *	vdev: the virtio_device
  *	Returns the config generation counter
  * @get_status: read the status byte
@@ -48,17 +48,17 @@ struct irq_affinity;
  * @del_vqs: free virtqueues found by find_vqs().
  * @get_features: get the array of feature bits for this device.
  *	vdev: the virtio_device
- *	Returns the first 32 feature bits (all we currently need).
+ *	Returns the first 64 feature bits (all we currently need).
  * @finalize_features: confirm what device features we'll be using.
  *	vdev: the virtio_device
  *	This gives the final feature bits for the device: it can change
  *	the dev->feature bits if it wants.
  *	Returns 0 on success or error status
- * @bus_name: return the bus name associated with the device
+ * @bus_name: return the bus name associated with the device (optional)
  *	vdev: the virtio_device
  *      This returns a pointer to the bus name a la pci_name from which
  *      the caller can then copy.
- * @set_vq_affinity: set the affinity for a virtqueue.
+ * @set_vq_affinity: set the affinity for a virtqueue (optional).
  * @get_vq_affinity: get the affinity for a virtqueue (optional).
  */
 typedef void vq_callback_t(struct virtqueue *);
Signature · 6 lines
2.17.2


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
#3 lore raw

Re: [PATCH 1/2] virtio: fix virtio_config_ops description

Quoted 33 lines · On Thu, 3 Jan 2019 17:08:03 +0100 Cornelia Huck <[email protected]> wrote:

- get_features has returned 64 bits since commit d025477368792 ("virtio: add support for 64 bit features.")
- properly mark all optional callbacks

---
 include/linux/virtio_config.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/virtio_config.h +2 -2
index 32baf8e26735..7087ef946ba7 100644
@@ -22,7 +22,7 @@ struct irq_affinity;
  *	offset: the offset of the configuration field
  *	buf: the buffer to read the field value from.
  *	len: the length of the buffer
- * @generation: config generation counter
+ * @generation: config generation counter (optional)
  *	vdev: the virtio_device
  *	Returns the config generation counter
  * @get_status: read the status byte
@@ -48,17 +48,17 @@ struct irq_affinity;
  * @del_vqs: free virtqueues found by find_vqs().
  * @get_features: get the array of feature bits for this device.
  *	vdev: the virtio_device
- *	Returns the first 32 feature bits (all we currently need).
+ *	Returns the first 64 feature bits (all we currently need).
  * @finalize_features: confirm what device features we'll be using.
  *	vdev: the virtio_device
  *	This gives the final feature bits for the device: it can change
  *	the dev->feature bits if it wants.
  *	Returns 0 on success or error status

include/linux/virtio_config.h struct irq_affinity; · line 64

Quoted 10 lines
include/linux/virtio_config.h +2 -2
- * @bus_name: return the bus name associated with the device
+ * @bus_name: return the bus name associated with the device (optional)
  *	vdev: the virtio_device
  *      This returns a pointer to the bus name a la pci_name from which
  *      the caller can then copy.
- * @set_vq_affinity: set the affinity for a virtqueue.
+ * @set_vq_affinity: set the affinity for a virtqueue (optional).
  * @get_vq_affinity: get the affinity for a virtqueue (optional).
  */
 typedef void vq_callback_t(struct virtqueue *);

Ping. Any feedback on that patch?

#4 lore raw

Re: [PATCH 1/2] virtio: fix virtio_config_ops description

In reply to Cornelia Huck
Quoted 33 lines · On Thu, 3 Jan 2019 17:08:03 +0100 Cornelia Huck <[email protected]> wrote:

- get_features has returned 64 bits since commit d025477368792 ("virtio: add support for 64 bit features.")
- properly mark all optional callbacks

---
 include/linux/virtio_config.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/virtio_config.h +2 -2
index 32baf8e26735..7087ef946ba7 100644
@@ -22,7 +22,7 @@ struct irq_affinity;
  *	offset: the offset of the configuration field
  *	buf: the buffer to read the field value from.
  *	len: the length of the buffer
- * @generation: config generation counter
+ * @generation: config generation counter (optional)
  *	vdev: the virtio_device
  *	Returns the config generation counter
  * @get_status: read the status byte
@@ -48,17 +48,17 @@ struct irq_affinity;
  * @del_vqs: free virtqueues found by find_vqs().
  * @get_features: get the array of feature bits for this device.
  *	vdev: the virtio_device
- *	Returns the first 32 feature bits (all we currently need).
+ *	Returns the first 64 feature bits (all we currently need).
  * @finalize_features: confirm what device features we'll be using.
  *	vdev: the virtio_device
  *	This gives the final feature bits for the device: it can change
  *	the dev->feature bits if it wants.
  *	Returns 0 on success or error status

include/linux/virtio_config.h struct irq_affinity; · line 64

Quoted 10 lines
include/linux/virtio_config.h +2 -2
- * @bus_name: return the bus name associated with the device
+ * @bus_name: return the bus name associated with the device (optional)
  *	vdev: the virtio_device
  *      This returns a pointer to the bus name a la pci_name from which
  *      the caller can then copy.
- * @set_vq_affinity: set the affinity for a virtqueue.
+ * @set_vq_affinity: set the affinity for a virtqueue (optional).
  * @get_vq_affinity: get the affinity for a virtqueue (optional).
  */
 typedef void vq_callback_t(struct virtqueue *);

Ping. Any feedback on that patch?

Reviewed-by
#5 lore raw

Re: [virtio-dev] Re: [PATCH 1/2] virtio: fix virtio_config_ops description

Quoted 8 lines · On Mon, 14 Jan 2019 15:09:58 +0100 Cornelia Huck <[email protected]> wrote:
Quoted 5 lines · On Thu, 3 Jan 2019 17:08:03 +0100 Cornelia Huck <[email protected]> wrote:

- get_features has returned 64 bits since commit d025477368792 ("virtio: add support for 64 bit features.")
- properly mark all optional callbacks

Quoted 41 lines
Quoted 28 lines
---
 include/linux/virtio_config.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/virtio_config.h +2 -2
index 32baf8e26735..7087ef946ba7 100644
@@ -22,7 +22,7 @@ struct irq_affinity;
  *	offset: the offset of the configuration field
  *	buf: the buffer to read the field value from.
  *	len: the length of the buffer
- * @generation: config generation counter
+ * @generation: config generation counter (optional)
  *	vdev: the virtio_device
  *	Returns the config generation counter
  * @get_status: read the status byte
@@ -48,17 +48,17 @@ struct irq_affinity;
  * @del_vqs: free virtqueues found by find_vqs().
  * @get_features: get the array of feature bits for this device.
  *	vdev: the virtio_device
- *	Returns the first 32 feature bits (all we currently need).
+ *	Returns the first 64 feature bits (all we currently need).
  * @finalize_features: confirm what device features we'll be using.
  *	vdev: the virtio_device
  *	This gives the final feature bits for the device: it can change
  *	the dev->feature bits if it wants.
  *	Returns 0 on success or error status

include/linux/virtio_config.h struct irq_affinity; · line 64

Quoted 10 lines
include/linux/virtio_config.h +2 -2
- * @bus_name: return the bus name associated with the device
+ * @bus_name: return the bus name associated with the device (optional)
  *	vdev: the virtio_device
  *      This returns a pointer to the bus name a la pci_name from which
  *      the caller can then copy.
- * @set_vq_affinity: set the affinity for a virtqueue.
+ * @set_vq_affinity: set the affinity for a virtqueue (optional).
  * @get_vq_affinity: get the affinity for a virtqueue (optional).
  */
 typedef void vq_callback_t(struct virtqueue *);

Ping. Any feedback on that patch?

Quoted 4 lines

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

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

Reviewed-by
#6 lore raw

Re: [PATCH 1/2] virtio: fix virtio_config_ops description

In reply to Cornelia Huck
Quoted 39 lines · Cornelia Huck
Quoted 36 lines · On Thu, 3 Jan 2019 17:08:03 +0100 Cornelia Huck <[email protected]> wrote:

- get_features has returned 64 bits since commit d025477368792 ("virtio: add support for 64 bit features.")
- properly mark all optional callbacks

---
  include/linux/virtio_config.h | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/virtio_config.h +3 -3
index 32baf8e26735..7087ef946ba7 100644
@@ -22,7 +22,7 @@ struct irq_affinity;
   *	offset: the offset of the configuration field
   *	buf: the buffer to read the field value from.
   *	len: the length of the buffer
- * @generation: config generation counter
+ * @generation: config generation counter (optional)
   *	vdev: the virtio_device
   *	Returns the config generation counter
   * @get_status: read the status byte
@@ -48,17 +48,17 @@ struct irq_affinity;
   * @del_vqs: free virtqueues found by find_vqs().
   * @get_features: get the array of feature bits for this device.
   *	vdev: the virtio_device
- *	Returns the first 32 feature bits (all we currently need).
+ *	Returns the first 64 feature bits (all we currently need).
   * @finalize_features: confirm what device features we'll be using.
   *	vdev: the virtio_device
   *	This gives the final feature bits for the device: it can change
   *	the dev->feature bits if it wants.
   *	Returns 0 on success or error status
- * @bus_name: return the bus name associated with the device
+ * @bus_name: return the bus name associated with the device (optional)
   *	vdev: the virtio_device
Quoted 8 lines

include/linux/virtio_config.h struct irq_affinity; · line 64

Quoted 7 lines
include/linux/virtio_config.h +1 -1
   *      This returns a pointer to the bus name a la pci_name from which
   *      the caller can then copy.
- * @set_vq_affinity: set the affinity for a virtqueue.
+ * @set_vq_affinity: set the affinity for a virtqueue (optional).
   * @get_vq_affinity: get the affinity for a virtqueue (optional).
   */
  typedef void vq_callback_t(struct virtqueue *);

Ping. Any feedback on that patch?

Best,
Wei

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

#7 lore raw

Re: [PATCH 1/2] virtio: fix virtio_config_ops description

Quoted 49 lines · Wei Wang
Quoted 39 lines · Cornelia Huck
Quoted 36 lines · On Thu, 3 Jan 2019 17:08:03 +0100 Cornelia Huck <[email protected]> wrote:

- get_features has returned 64 bits since commit d025477368792 ("virtio: add support for 64 bit features.")
- properly mark all optional callbacks

---
  include/linux/virtio_config.h | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/virtio_config.h +3 -3
index 32baf8e26735..7087ef946ba7 100644
@@ -22,7 +22,7 @@ struct irq_affinity;
   *	offset: the offset of the configuration field
   *	buf: the buffer to read the field value from.
   *	len: the length of the buffer
- * @generation: config generation counter
+ * @generation: config generation counter (optional)
   *	vdev: the virtio_device
   *	Returns the config generation counter
   * @get_status: read the status byte
@@ -48,17 +48,17 @@ struct irq_affinity;
   * @del_vqs: free virtqueues found by find_vqs().
   * @get_features: get the array of feature bits for this device.
   *	vdev: the virtio_device
- *	Returns the first 32 feature bits (all we currently need).
+ *	Returns the first 64 feature bits (all we currently need).
   * @finalize_features: confirm what device features we'll be using.
   *	vdev: the virtio_device
   *	This gives the final feature bits for the device: it can change
   *	the dev->feature bits if it wants.
   *	Returns 0 on success or error status
- * @bus_name: return the bus name associated with the device
+ * @bus_name: return the bus name associated with the device (optional)
   *	vdev: the virtio_device
Quoted 8 lines

include/linux/virtio_config.h struct irq_affinity; · line 64

Quoted 7 lines
include/linux/virtio_config.h +1 -1
   *      This returns a pointer to the bus name a la pci_name from which
   *      the caller can then copy.
- * @set_vq_affinity: set the affinity for a virtqueue.
+ * @set_vq_affinity: set the affinity for a virtqueue (optional).
   * @get_vq_affinity: get the affinity for a virtqueue (optional).
   */
  typedef void vq_callback_t(struct virtqueue *);

Ping. Any feedback on that patch?

Quoted 4 lines

Best,
Wei

Pushed already, can't add tags.
Sorry about that.

Signature · 1 line
MST
#8 lore raw

Re: [PATCH 1/2] virtio: fix virtio_config_ops description

In reply to Wei Wang
Quoted 49 lines · Wei Wang
Quoted 39 lines · Cornelia Huck
Quoted 36 lines · On Thu, 3 Jan 2019 17:08:03 +0100 Cornelia Huck <[email protected]> wrote:

- get_features has returned 64 bits since commit d025477368792 ("virtio: add support for 64 bit features.")
- properly mark all optional callbacks

---
  include/linux/virtio_config.h | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/virtio_config.h +3 -3
index 32baf8e26735..7087ef946ba7 100644
@@ -22,7 +22,7 @@ struct irq_affinity;
   *	offset: the offset of the configuration field
   *	buf: the buffer to read the field value from.
   *	len: the length of the buffer
- * @generation: config generation counter
+ * @generation: config generation counter (optional)
   *	vdev: the virtio_device
   *	Returns the config generation counter
   * @get_status: read the status byte
@@ -48,17 +48,17 @@ struct irq_affinity;
   * @del_vqs: free virtqueues found by find_vqs().
   * @get_features: get the array of feature bits for this device.
   *	vdev: the virtio_device
- *	Returns the first 32 feature bits (all we currently need).
+ *	Returns the first 64 feature bits (all we currently need).
   * @finalize_features: confirm what device features we'll be using.
   *	vdev: the virtio_device
   *	This gives the final feature bits for the device: it can change
   *	the dev->feature bits if it wants.
   *	Returns 0 on success or error status
- * @bus_name: return the bus name associated with the device
+ * @bus_name: return the bus name associated with the device (optional)
   *	vdev: the virtio_device
Quoted 8 lines

include/linux/virtio_config.h struct irq_affinity; · line 64

Quoted 7 lines
include/linux/virtio_config.h +1 -1
   *      This returns a pointer to the bus name a la pci_name from which
   *      the caller can then copy.
- * @set_vq_affinity: set the affinity for a virtqueue.
+ * @set_vq_affinity: set the affinity for a virtqueue (optional).
   * @get_vq_affinity: get the affinity for a virtqueue (optional).
   */
  typedef void vq_callback_t(struct virtqueue *);

Ping. Any feedback on that patch?

Quoted 4 lines

Best,
Wei

Pushed already, can't add tags.
Sorry about that.

Signature · 1 line
MST
Reviewed-by
#9 lore raw

Re: [PATCH 1/2] virtio: fix virtio_config_ops description

In reply to Cornelia Huck
Quoted 39 lines · Cornelia Huck
Quoted 36 lines · On Thu, 3 Jan 2019 17:08:03 +0100 Cornelia Huck <[email protected]> wrote:

- get_features has returned 64 bits since commit d025477368792 ("virtio: add support for 64 bit features.")
- properly mark all optional callbacks

---
  include/linux/virtio_config.h | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/virtio_config.h +3 -3
index 32baf8e26735..7087ef946ba7 100644
@@ -22,7 +22,7 @@ struct irq_affinity;
   *	offset: the offset of the configuration field
   *	buf: the buffer to read the field value from.
   *	len: the length of the buffer
- * @generation: config generation counter
+ * @generation: config generation counter (optional)
   *	vdev: the virtio_device
   *	Returns the config generation counter
   * @get_status: read the status byte
@@ -48,17 +48,17 @@ struct irq_affinity;
   * @del_vqs: free virtqueues found by find_vqs().
   * @get_features: get the array of feature bits for this device.
   *	vdev: the virtio_device
- *	Returns the first 32 feature bits (all we currently need).
+ *	Returns the first 64 feature bits (all we currently need).
   * @finalize_features: confirm what device features we'll be using.
   *	vdev: the virtio_device
   *	This gives the final feature bits for the device: it can change
   *	the dev->feature bits if it wants.
   *	Returns 0 on success or error status
- * @bus_name: return the bus name associated with the device
+ * @bus_name: return the bus name associated with the device (optional)
   *	vdev: the virtio_device
Quoted 8 lines

include/linux/virtio_config.h struct irq_affinity; · line 64

Quoted 7 lines
include/linux/virtio_config.h +1 -1
   *      This returns a pointer to the bus name a la pci_name from which
   *      the caller can then copy.
- * @set_vq_affinity: set the affinity for a virtqueue.
+ * @set_vq_affinity: set the affinity for a virtqueue (optional).
   * @get_vq_affinity: get the affinity for a virtqueue (optional).
   */
  typedef void vq_callback_t(struct virtqueue *);

Ping. Any feedback on that patch?

Best,
Wei

#10 lore raw

PATCH 2/2 virtio: document virtio_config_ops restrictions

In reply to Cornelia Huck

Some transports (e.g. virtio-ccw) implement virtio operations that seem to be a simple read/write as something more involved that cannot be done from an atomic context.

Give at least a hint about that.

---
 include/linux/virtio_config.h | 5 +++++
 1 file changed, 5 insertions(+)
include/linux/virtio_config.h +5 -0
index 7087ef946ba7..987b6491b946 100644
@@ -12,6 +12,11 @@ struct irq_affinity;
 
 /**
  * virtio_config_ops - operations for configuring a virtio device
+ * Note: Do not assume that a transport implements all of the operations
+ *       getting/setting a value as a simple read/write! Generally speaking,
+ *       any of @get/@set, @get_status/@set_status, or @get_features/
+ *       @finalize_features are NOT safe to be called from an atomic
+ *       context.
  * @get: read the value of a configuration field
  *	vdev: the virtio_device
  *	offset: the offset of the configuration field
Signature · 1 line
2.17.2
#11 lore raw

PATCH 2/2 virtio: document virtio_config_ops restrictions

In reply to Cornelia Huck

Some transports (e.g. virtio-ccw) implement virtio operations that seem to be a simple read/write as something more involved that cannot be done from an atomic context.

Give at least a hint about that.

---
 include/linux/virtio_config.h | 5 +++++
 1 file changed, 5 insertions(+)
include/linux/virtio_config.h +5 -0
index 7087ef946ba7..987b6491b946 100644
@@ -12,6 +12,11 @@ struct irq_affinity;
 
 /**
  * virtio_config_ops - operations for configuring a virtio device
+ * Note: Do not assume that a transport implements all of the operations
+ *       getting/setting a value as a simple read/write! Generally speaking,
+ *       any of @get/@set, @get_status/@set_status, or @get_features/
+ *       @finalize_features are NOT safe to be called from an atomic
+ *       context.
  * @get: read the value of a configuration field
  *	vdev: the virtio_device
  *	offset: the offset of the configuration field
Signature · 6 lines
2.17.2


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
#12 lore raw

Re: [PATCH 2/2] virtio: document virtio_config_ops restrictions

Quoted 17 lines · Cornelia Huck

Some transports (e.g. virtio-ccw) implement virtio operations that seem to be a simple read/write as something more involved that cannot be done from an atomic context.

Give at least a hint about that.

---
 include/linux/virtio_config.h | 5 +++++
 1 file changed, 5 insertions(+)
include/linux/virtio_config.h +0 -0
index 7087ef946ba7..987b6491b946 100644
@@ -12,6 +12,11 @@ struct irq_affinity;
 

include/linux/virtio_config.h struct irq_affinity; · line 22

Quoted 10 lines
include/linux/virtio_config.h +5 -0
 /**
  * virtio_config_ops - operations for configuring a virtio device
+ * Note: Do not assume that a transport implements all of the operations
+ *       getting/setting a value as a simple read/write! Generally speaking,
+ *       any of @get/@set, @get_status/@set_status, or @get_features/
+ *       @finalize_features are NOT safe to be called from an atomic
+ *       context.
  * @get: read the value of a configuration field
  *	vdev: the virtio_device
  *	offset: the offset of the configuration field

Then might_sleep in virtio_cread/virtio_cwrite and friends would be appropriate? I guess we'll need to fix balloon first.

Quoted 2 lines
Signature · 1 line
2.17.2
#13 lore raw

Re: [PATCH 2/2] virtio: document virtio_config_ops restrictions

In reply to Cornelia Huck
Quoted 17 lines · Cornelia Huck

Some transports (e.g. virtio-ccw) implement virtio operations that seem to be a simple read/write as something more involved that cannot be done from an atomic context.

Give at least a hint about that.

---
 include/linux/virtio_config.h | 5 +++++
 1 file changed, 5 insertions(+)
include/linux/virtio_config.h +0 -0
index 7087ef946ba7..987b6491b946 100644
@@ -12,6 +12,11 @@ struct irq_affinity;
 

include/linux/virtio_config.h struct irq_affinity; · line 22

Quoted 10 lines
include/linux/virtio_config.h +5 -0
 /**
  * virtio_config_ops - operations for configuring a virtio device
+ * Note: Do not assume that a transport implements all of the operations
+ *       getting/setting a value as a simple read/write! Generally speaking,
+ *       any of @get/@set, @get_status/@set_status, or @get_features/
+ *       @finalize_features are NOT safe to be called from an atomic
+ *       context.
  * @get: read the value of a configuration field
  *	vdev: the virtio_device
  *	offset: the offset of the configuration field

Then might_sleep in virtio_cread/virtio_cwrite and friends would be appropriate? I guess we'll need to fix balloon first.

Quoted 2 lines
Signature · 1 line
2.17.2

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

#14 lore raw

Re: [PATCH 2/2] virtio: document virtio_config_ops restrictions

Quoted 18 lines · On Thu, 3 Jan 2019 11:28:28 -0500 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 17 lines · Cornelia Huck

Some transports (e.g. virtio-ccw) implement virtio operations that seem to be a simple read/write as something more involved that cannot be done from an atomic context.

Give at least a hint about that.

---
 include/linux/virtio_config.h | 5 +++++
 1 file changed, 5 insertions(+)
include/linux/virtio_config.h +0 -0
index 7087ef946ba7..987b6491b946 100644
@@ -12,6 +12,11 @@ struct irq_affinity;
 
Quoted 14 lines

include/linux/virtio_config.h struct irq_affinity; · line 22

Quoted 10 lines
include/linux/virtio_config.h +5 -0
 /**
  * virtio_config_ops - operations for configuring a virtio device
+ * Note: Do not assume that a transport implements all of the operations
+ *       getting/setting a value as a simple read/write! Generally speaking,
+ *       any of @get/@set, @get_status/@set_status, or @get_features/
+ *       @finalize_features are NOT safe to be called from an atomic
+ *       context.
  * @get: read the value of a configuration field
  *	vdev: the virtio_device
  *	offset: the offset of the configuration field  

Then might_sleep in virtio_cread/virtio_cwrite and friends would be appropriate? I guess we'll need to fix balloon first.

Yes, it makes sense to go over the code and add might_sleep to functions where it makes sense after the balloon changes have been merged.

#15 lore raw

Re: [PATCH 2/2] virtio: document virtio_config_ops restrictions

In reply to Michael S. Tsirkin
Quoted 18 lines · On Thu, 3 Jan 2019 11:28:28 -0500 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 17 lines · Cornelia Huck

Some transports (e.g. virtio-ccw) implement virtio operations that seem to be a simple read/write as something more involved that cannot be done from an atomic context.

Give at least a hint about that.

---
 include/linux/virtio_config.h | 5 +++++
 1 file changed, 5 insertions(+)
include/linux/virtio_config.h +0 -0
index 7087ef946ba7..987b6491b946 100644
@@ -12,6 +12,11 @@ struct irq_affinity;
 
Quoted 14 lines

include/linux/virtio_config.h struct irq_affinity; · line 22

Quoted 10 lines
include/linux/virtio_config.h +5 -0
 /**
  * virtio_config_ops - operations for configuring a virtio device
+ * Note: Do not assume that a transport implements all of the operations
+ *       getting/setting a value as a simple read/write! Generally speaking,
+ *       any of @get/@set, @get_status/@set_status, or @get_features/
+ *       @finalize_features are NOT safe to be called from an atomic
+ *       context.
  * @get: read the value of a configuration field
  *	vdev: the virtio_device
  *	offset: the offset of the configuration field  

Then might_sleep in virtio_cread/virtio_cwrite and friends would be appropriate? I guess we'll need to fix balloon first.

Yes, it makes sense to go over the code and add might_sleep to functions where it makes sense after the balloon changes have been merged.

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

#16 lore raw

Re: [PATCH 2/2] virtio: document virtio_config_ops restrictions

In reply to Cornelia Huck
Quoted 16 lines · On Thu, 3 Jan 2019 17:08:04 +0100 Cornelia Huck <[email protected]> wrote:

Some transports (e.g. virtio-ccw) implement virtio operations that seem to be a simple read/write as something more involved that cannot be done from an atomic context.

Give at least a hint about that.

---
 include/linux/virtio_config.h | 5 +++++
 1 file changed, 5 insertions(+)
include/linux/virtio_config.h +0 -0
index 7087ef946ba7..987b6491b946 100644

include/linux/virtio_config.h struct irq_affinity; · line 19

Quoted 8 lines
include/linux/virtio_config.h +5 -0
@@ -12,6 +12,11 @@ struct irq_affinity;
 
 /**
  * virtio_config_ops - operations for configuring a virtio device
+ * Note: Do not assume that a transport implements all of the operations
+ *       getting/setting a value as a simple read/write! Generally speaking,
+ *       any of @get/@set, @get_status/@set_status, or @get_features/
+ *       @finalize_features are NOT safe to be called from an atomic
+ *       context.

I think the only exception is @bus_name (and maybe @generation, I don't know) because it does not have to 'speak' with the hypervisor. If a transport operation has to 'speak' with the hypervisor, we do it by making it interpret a channel program. That means not safe to be called form atomic context. Or am I missing something?

Regards,
Halil

include/linux/virtio_config.h struct irq_affinity; · line 22

Quoted 3 lines
include/linux/virtio_config.h +0 -0
  * @get: read the value of a configuration field
  *	vdev: the virtio_device
  *	offset: the offset of the configuration field

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

#17 lore raw

Re: [PATCH 2/2] virtio: document virtio_config_ops restrictions

Quoted 20 lines · On Thu, 3 Jan 2019 18:28:49 +0100 Halil Pasic <[email protected]> wrote:
Quoted 17 lines · On Thu, 3 Jan 2019 17:08:04 +0100 Cornelia Huck <[email protected]> wrote:

Some transports (e.g. virtio-ccw) implement virtio operations that seem to be a simple read/write as something more involved that cannot be done from an atomic context.

Give at least a hint about that.

---
 include/linux/virtio_config.h | 5 +++++
 1 file changed, 5 insertions(+)
include/linux/virtio_config.h +0 -0
index 7087ef946ba7..987b6491b946 100644
@@ -12,6 +12,11 @@ struct irq_affinity;
 
Quoted 13 lines

include/linux/virtio_config.h struct irq_affinity; · line 19

Quoted 7 lines
include/linux/virtio_config.h +5 -0
 /**
  * virtio_config_ops - operations for configuring a virtio device
+ * Note: Do not assume that a transport implements all of the operations
+ *       getting/setting a value as a simple read/write! Generally speaking,
+ *       any of @get/@set, @get_status/@set_status, or @get_features/
+ *       @finalize_features are NOT safe to be called from an atomic
+ *       context.  

I think the only exception is @bus_name (and maybe @generation, I don't know) because it does not have to 'speak' with the hypervisor. If a transport operation has to 'speak' with the hypervisor, we do it by making it interpret a channel program. That means not safe to be called form atomic context. Or am I missing something?

I explicitly singled out the listed callbacks because they read/write a value and there might be more to them than meets the eye. I would assume that nobody expects calling e.g. find_vqs (allocating queues) from an atomic context to be a good idea :) Maybe I should do s/Generally speaking/In particular/ ?

That said, it's only a hint; we should add might_sleep as well to interfaces where it makes sense.

Reviewed-by on v1 2/2
#18 lore raw

Re: [virtio-dev] [PATCH 2/2] virtio: document virtio_config_ops restrictions

In reply to Cornelia Huck
Quoted 17 lines · Cornelia Huck

Some transports (e.g. virtio-ccw) implement virtio operations that seem to be a simple read/write as something more involved that cannot be done from an atomic context.

Give at least a hint about that.

---
  include/linux/virtio_config.h | 5 +++++
  1 file changed, 5 insertions(+)
include/linux/virtio_config.h +0 -0
index 7087ef946ba7..987b6491b946 100644
@@ -12,6 +12,11 @@ struct irq_affinity;
 

include/linux/virtio_config.h struct irq_affinity; · line 22

Quoted 10 lines
include/linux/virtio_config.h +5 -0
  /**
   * virtio_config_ops - operations for configuring a virtio device
+ * Note: Do not assume that a transport implements all of the operations
+ *       getting/setting a value as a simple read/write! Generally speaking,
+ *       any of @get/@set, @get_status/@set_status, or @get_features/
+ *       @finalize_features are NOT safe to be called from an atomic
+ *       context.
   * @get: read the value of a configuration field
   *	vdev: the virtio_device
   *	offset: the offset of the configuration field

Best,
Wei

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

Reviewed-by on v1 2/2
#19 lore raw

Re: [virtio-dev] [PATCH 2/2] virtio: document virtio_config_ops restrictions

In reply to Cornelia Huck
Quoted 17 lines · Cornelia Huck

Some transports (e.g. virtio-ccw) implement virtio operations that seem to be a simple read/write as something more involved that cannot be done from an atomic context.

Give at least a hint about that.

---
  include/linux/virtio_config.h | 5 +++++
  1 file changed, 5 insertions(+)
include/linux/virtio_config.h +0 -0
index 7087ef946ba7..987b6491b946 100644
@@ -12,6 +12,11 @@ struct irq_affinity;
 

include/linux/virtio_config.h struct irq_affinity; · line 22

Quoted 10 lines
include/linux/virtio_config.h +5 -0
  /**
   * virtio_config_ops - operations for configuring a virtio device
+ * Note: Do not assume that a transport implements all of the operations
+ *       getting/setting a value as a simple read/write! Generally speaking,
+ *       any of @get/@set, @get_status/@set_status, or @get_features/
+ *       @finalize_features are NOT safe to be called from an atomic
+ *       context.
   * @get: read the value of a configuration field
   *	vdev: the virtio_device
   *	offset: the offset of the configuration field

Best,
Wei