Re: [PATCH 1/5] virtio-ring: move queue_index to vring_virtqueue

2012-09-05 Thread Rusty Russell
Paolo Bonzini  writes:

> From: Jason Wang 
>
> Instead of storing the queue index in transport-specific virtio structs,
> this patch moves them to vring_virtqueue and introduces an helper to get
> the value.  This lets drivers simplify their management and tracing of
> virtqueues.
>
> Signed-off-by: Jason Wang 
> Signed-off-by: Paolo Bonzini 

Sorry for the delay, I was at Kernel Summit and am only now actually
reading (vs skimming) my backlog.

Putting it in vring_virtqueue rather than virtqueue seems weird, though.
But I've applied as-is, we can clean up that later if we want (probably
by merging the two structures, I'll have to think harder on that).

Acked-by: Rusty Russell 

Cheers,
Rusty.
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/5] virtio-ring: move queue_index to vring_virtqueue

2012-08-29 Thread Jason Wang

On 08/28/2012 07:54 PM, Paolo Bonzini wrote:

From: Jason Wang

Instead of storing the queue index in transport-specific virtio structs,
this patch moves them to vring_virtqueue and introduces an helper to get
the value.  This lets drivers simplify their management and tracing of
virtqueues.

Signed-off-by: Jason Wang
Signed-off-by: Paolo Bonzini
---
I fixed the problems in Jason's v5 (posted at
http://permalink.gmane.org/gmane.linux.kernel.virtualization/15910)
and switched from virtio_set_queue_index to a new argument of
vring_new_virtqueue.  This breaks at compile-time any virtio
transport that is not updated.


Thanks Paolo. I'm fine with this patch.


  drivers/lguest/lguest_device.c |2 +-
  drivers/remoteproc/remoteproc_virtio.c |2 +-
  drivers/s390/kvm/kvm_virtio.c  |2 +-
  drivers/virtio/virtio_mmio.c   |   12 
  drivers/virtio/virtio_pci.c|   13 +
  drivers/virtio/virtio_ring.c   |   14 +-
  include/linux/virtio.h |2 ++
  include/linux/virtio_ring.h|3 ++-
  8 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/drivers/lguest/lguest_device.c b/drivers/lguest/lguest_device.c
index 9e8388e..ccb7dfb 100644
--- a/drivers/lguest/lguest_device.c
+++ b/drivers/lguest/lguest_device.c
@@ -296,7 +296,7 @@ static struct virtqueue *lg_find_vq(struct virtio_device 
*vdev,
 * to 'true': the host just a(nother) SMP CPU, so we only need inter-cpu
 * barriers.
 */
-   vq = vring_new_virtqueue(lvq->config.num, LGUEST_VRING_ALIGN, vdev,
+   vq = vring_new_virtqueue(index, lvq->config.num, LGUEST_VRING_ALIGN, 
vdev,
 true, lvq->pages, lg_notify, callback, name);
if (!vq) {
err = -ENOMEM;
diff --git a/drivers/remoteproc/remoteproc_virtio.c 
b/drivers/remoteproc/remoteproc_virtio.c
index 3541b44..343c194 100644
--- a/drivers/remoteproc/remoteproc_virtio.c
+++ b/drivers/remoteproc/remoteproc_virtio.c
@@ -103,7 +103,7 @@ static struct virtqueue *rp_find_vq(struct virtio_device 
*vdev,
 * Create the new vq, and tell virtio we're not interested in
 * the 'weak' smp barriers, since we're talking with a real device.
 */
-   vq = vring_new_virtqueue(len, rvring->align, vdev, false, addr,
+   vq = vring_new_virtqueue(id, len, rvring->align, vdev, false, addr,
rproc_virtio_notify, callback, name);
if (!vq) {
dev_err(dev, "vring_new_virtqueue %s failed\n", name);
diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c
index 47cccd5..5565af2 100644
--- a/drivers/s390/kvm/kvm_virtio.c
+++ b/drivers/s390/kvm/kvm_virtio.c
@@ -198,7 +198,7 @@ static struct virtqueue *kvm_find_vq(struct virtio_device 
*vdev,
if (err)
goto out;

-   vq = vring_new_virtqueue(config->num, KVM_S390_VIRTIO_RING_ALIGN,
+   vq = vring_new_virtqueue(index, config->num, KVM_S390_VIRTIO_RING_ALIGN,
 vdev, true, (void *) config->address,
 kvm_notify, callback, name);
if (!vq) {
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index 453db0c..008bf58 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -131,9 +131,6 @@ struct virtio_mmio_vq_info {
/* the number of entries in the queue */
unsigned int num;

-   /* the index of the queue */
-   int queue_index;
-
/* the virtual address of the ring queue */
void *queue;

@@ -225,11 +222,10 @@ static void vm_reset(struct virtio_device *vdev)
  static void vm_notify(struct virtqueue *vq)
  {
struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vq->vdev);
-   struct virtio_mmio_vq_info *info = vq->priv;

/* We write the queue's selector into the notification register to
 * signal the other end */
-   writel(info->queue_index, vm_dev->base + VIRTIO_MMIO_QUEUE_NOTIFY);
+   writel(virtqueue_get_queue_index(vq), vm_dev->base + 
VIRTIO_MMIO_QUEUE_NOTIFY);
  }

  /* Notify all virtqueues on an interrupt. */
@@ -270,6 +266,7 @@ static void vm_del_vq(struct virtqueue *vq)
struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vq->vdev);
struct virtio_mmio_vq_info *info = vq->priv;
unsigned long flags, size;
+   unsigned int index = virtqueue_get_queue_index(vq);

spin_lock_irqsave(&vm_dev->lock, flags);
list_del(&info->node);
@@ -278,7 +275,7 @@ static void vm_del_vq(struct virtqueue *vq)
vring_del_virtqueue(vq);

/* Select and deactivate the queue */
-   writel(info->queue_index, vm_dev->base + VIRTIO_MMIO_QUEUE_SEL);
+   writel(index, vm_dev->base + VIRTIO_MMIO_QUEUE_SEL);
writel(0, vm_dev->base + VIRTIO_MMIO_QUEUE_PFN);

size = PAGE_

[PATCH 1/5] virtio-ring: move queue_index to vring_virtqueue

2012-08-28 Thread Paolo Bonzini
From: Jason Wang 

Instead of storing the queue index in transport-specific virtio structs,
this patch moves them to vring_virtqueue and introduces an helper to get
the value.  This lets drivers simplify their management and tracing of
virtqueues.

Signed-off-by: Jason Wang 
Signed-off-by: Paolo Bonzini 
---
I fixed the problems in Jason's v5 (posted at
http://permalink.gmane.org/gmane.linux.kernel.virtualization/15910)
and switched from virtio_set_queue_index to a new argument of
vring_new_virtqueue.  This breaks at compile-time any virtio
transport that is not updated.

 drivers/lguest/lguest_device.c |2 +-
 drivers/remoteproc/remoteproc_virtio.c |2 +-
 drivers/s390/kvm/kvm_virtio.c  |2 +-
 drivers/virtio/virtio_mmio.c   |   12 
 drivers/virtio/virtio_pci.c|   13 +
 drivers/virtio/virtio_ring.c   |   14 +-
 include/linux/virtio.h |2 ++
 include/linux/virtio_ring.h|3 ++-
 8 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/drivers/lguest/lguest_device.c b/drivers/lguest/lguest_device.c
index 9e8388e..ccb7dfb 100644
--- a/drivers/lguest/lguest_device.c
+++ b/drivers/lguest/lguest_device.c
@@ -296,7 +296,7 @@ static struct virtqueue *lg_find_vq(struct virtio_device 
*vdev,
 * to 'true': the host just a(nother) SMP CPU, so we only need inter-cpu
 * barriers.
 */
-   vq = vring_new_virtqueue(lvq->config.num, LGUEST_VRING_ALIGN, vdev,
+   vq = vring_new_virtqueue(index, lvq->config.num, LGUEST_VRING_ALIGN, 
vdev,
 true, lvq->pages, lg_notify, callback, name);
if (!vq) {
err = -ENOMEM;
diff --git a/drivers/remoteproc/remoteproc_virtio.c 
b/drivers/remoteproc/remoteproc_virtio.c
index 3541b44..343c194 100644
--- a/drivers/remoteproc/remoteproc_virtio.c
+++ b/drivers/remoteproc/remoteproc_virtio.c
@@ -103,7 +103,7 @@ static struct virtqueue *rp_find_vq(struct virtio_device 
*vdev,
 * Create the new vq, and tell virtio we're not interested in
 * the 'weak' smp barriers, since we're talking with a real device.
 */
-   vq = vring_new_virtqueue(len, rvring->align, vdev, false, addr,
+   vq = vring_new_virtqueue(id, len, rvring->align, vdev, false, addr,
rproc_virtio_notify, callback, name);
if (!vq) {
dev_err(dev, "vring_new_virtqueue %s failed\n", name);
diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c
index 47cccd5..5565af2 100644
--- a/drivers/s390/kvm/kvm_virtio.c
+++ b/drivers/s390/kvm/kvm_virtio.c
@@ -198,7 +198,7 @@ static struct virtqueue *kvm_find_vq(struct virtio_device 
*vdev,
if (err)
goto out;
 
-   vq = vring_new_virtqueue(config->num, KVM_S390_VIRTIO_RING_ALIGN,
+   vq = vring_new_virtqueue(index, config->num, KVM_S390_VIRTIO_RING_ALIGN,
 vdev, true, (void *) config->address,
 kvm_notify, callback, name);
if (!vq) {
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index 453db0c..008bf58 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -131,9 +131,6 @@ struct virtio_mmio_vq_info {
/* the number of entries in the queue */
unsigned int num;
 
-   /* the index of the queue */
-   int queue_index;
-
/* the virtual address of the ring queue */
void *queue;
 
@@ -225,11 +222,10 @@ static void vm_reset(struct virtio_device *vdev)
 static void vm_notify(struct virtqueue *vq)
 {
struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vq->vdev);
-   struct virtio_mmio_vq_info *info = vq->priv;
 
/* We write the queue's selector into the notification register to
 * signal the other end */
-   writel(info->queue_index, vm_dev->base + VIRTIO_MMIO_QUEUE_NOTIFY);
+   writel(virtqueue_get_queue_index(vq), vm_dev->base + 
VIRTIO_MMIO_QUEUE_NOTIFY);
 }
 
 /* Notify all virtqueues on an interrupt. */
@@ -270,6 +266,7 @@ static void vm_del_vq(struct virtqueue *vq)
struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vq->vdev);
struct virtio_mmio_vq_info *info = vq->priv;
unsigned long flags, size;
+   unsigned int index = virtqueue_get_queue_index(vq);
 
spin_lock_irqsave(&vm_dev->lock, flags);
list_del(&info->node);
@@ -278,7 +275,7 @@ static void vm_del_vq(struct virtqueue *vq)
vring_del_virtqueue(vq);
 
/* Select and deactivate the queue */
-   writel(info->queue_index, vm_dev->base + VIRTIO_MMIO_QUEUE_SEL);
+   writel(index, vm_dev->base + VIRTIO_MMIO_QUEUE_SEL);
writel(0, vm_dev->base + VIRTIO_MMIO_QUEUE_PFN);
 
size = PAGE_ALIGN(vring_size(info->num, VIRTIO_MMIO_VRING_ALIGN));
@@ -324,7 +321,6 @@ static struct vir