diff mbox

[1/8] virtio: add request_vqs/free_vqs operations

Message ID 20090427123153.GA1156@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Michael S. Tsirkin April 27, 2009, 12:31 p.m. UTC
This adds 2 new optional virtio operations: request_vqs/free_vqs. They will be
used for MSI support, because MSI needs to know the total number of vectors
upfront.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/linux/virtio_config.h |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)

Comments

Rusty Russell May 4, 2009, 11:32 a.m. UTC | #1
On Mon, 27 Apr 2009 10:01:53 pm Michael S. Tsirkin wrote:
> This adds 2 new optional virtio operations: request_vqs/free_vqs. They will be
> used for MSI support, because MSI needs to know the total number of vectors
> upfront.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

Hi Michael,

  Thanks for this work!  But this interface is horrible.  Either probe for the
number of vqs in virtio_pci, or change find_vq to

	int (*find_vqs)(struct virtio_device *, unsigned max,
						     struct virtqueue *vqs[]);

Thanks,
Rusty.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Michael S. Tsirkin May 4, 2009, 11:51 a.m. UTC | #2
On Mon, May 04, 2009 at 09:02:20PM +0930, Rusty Russell wrote:
> On Mon, 27 Apr 2009 10:01:53 pm Michael S. Tsirkin wrote:
> > This adds 2 new optional virtio operations: request_vqs/free_vqs. They will be
> > used for MSI support, because MSI needs to know the total number of vectors
> > upfront.
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> 
> Hi Michael,

Hi Rusty,

>   Thanks for this work!  But this interface is horrible.  Either probe for the
> number of vqs in virtio_pci, or change find_vq to
> 
> 	int (*find_vqs)(struct virtio_device *, unsigned max,
> 						     struct virtqueue *vqs[]);

I'm happier with the later option: it's easy for a host to expose
support for a very large number of vqs, and I don't want them to
waste resources if guest does not use them.

Thanks for the feedback!

> Thanks,
> Rusty.
diff mbox

Patch

diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index bf8ec28..e935670 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -49,6 +49,15 @@ 
  * @set_status: write the status byte
  *	vdev: the virtio_device
  *	status: the new status byte
+ * @request_vqs: request the specified number of virtqueues
+ *	vdev: the virtio_device
+ *	max_vqs: the max number of virtqueues we want
+ *      If supplied, must call before any virtqueues are instantiated.
+ *      To modify the max number of virtqueues after request_vqs has been
+ *      called, call free_vqs and then request_vqs with a new value.
+ * @free_vqs: cleanup resources allocated by request_vqs
+ *	vdev: the virtio_device
+ *      If supplied, must call after all virtqueues have been deleted.
  * @reset: reset the device
  *	vdev: the virtio device
  *	After this, status and feature negotiation must be done again
@@ -75,6 +84,8 @@  struct virtio_config_ops
 	u8 (*get_status)(struct virtio_device *vdev);
 	void (*set_status)(struct virtio_device *vdev, u8 status);
 	void (*reset)(struct virtio_device *vdev);
+	int (*request_vqs)(struct virtio_device *vdev, unsigned max_vqs);
+	void (*free_vqs)(struct virtio_device *vdev);
 	struct virtqueue *(*find_vq)(struct virtio_device *vdev,
 				     unsigned index,
 				     void (*callback)(struct virtqueue *));
@@ -126,5 +137,29 @@  static inline int virtio_config_buf(struct virtio_device *vdev,
 	vdev->config->get(vdev, offset, buf, len);
 	return 0;
 }
+
+/**
+ * virtio_request_vqs: request the specified number of virtqueues
+ * @vdev: the virtio_device
+ * @max_vqs: the max number of virtqueues we want
+ *
+ * For details, see documentation for request_vqs above. */
+static inline int virtio_request_vqs(struct virtio_device *vdev,
+				     unsigned max_vqs)
+{
+	return vdev->config->request_vqs ?
+		vdev->config->request_vqs(vdev, max_vqs) : 0;
+}
+
+/**
+ * free_vqs: cleanup resources allocated by virtio_request_vqs
+ * @vdev: the virtio_device
+ *
+ * For details, see documentation for free_vqs above. */
+static inline void virtio_free_vqs(struct virtio_device *vdev)
+{
+	if (vdev->config->free_vqs)
+		vdev->config->free_vqs(vdev);
+}
 #endif /* __KERNEL__ */
 #endif /* _LINUX_VIRTIO_CONFIG_H */