diff mbox

[1/3] virtio: introduce virtqueue_unmap_sg()

Message ID 1442563270-11615-1-git-send-email-jasowang@redhat.com
State New
Headers show

Commit Message

Jason Wang Sept. 18, 2015, 8:01 a.m. UTC
Factor out sg unmapping logic. This will be reused by the patch that
can discard descriptor.

Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 hw/virtio/virtio.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

Comments

Andrew James Sept. 24, 2015, 2:51 p.m. UTC | #1
On 09/18/2015 02:01 AM, Jason Wang wrote:
> Factor out sg unmapping logic. This will be reused by the patch that
> can discard descriptor.
> 
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
>  hw/virtio/virtio.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 0832db9..eb8d5ca 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -243,15 +243,12 @@ int virtio_queue_empty(VirtQueue *vq)
>      return vring_avail_idx(vq) == vq->last_avail_idx;
>  }
>  
> -void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
> -                    unsigned int len, unsigned int idx)
> +static void virtqueue_unmap_sg(VirtQueue *vq, const VirtQueueElement *elem,
> +                               unsigned int len)
>  {
>      unsigned int offset;
>      int i;
>  
> -    trace_virtqueue_fill(vq, elem, len, idx);
> -
> -    offset = 0;
>      for (i = 0; i < elem->in_num; i++) {
>          size_t size = MIN(len - offset, elem->in_sg[i].iov_len);
>  

Should the "offset = 0" really be dropped here? Seems like it ends
up uninitialized. GCC thinks it might too.

> @@ -266,6 +263,14 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
>          cpu_physical_memory_unmap(elem->out_sg[i].iov_base,
>                                    elem->out_sg[i].iov_len,
>                                    0, elem->out_sg[i].iov_len);
> +}
> +
> +void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
> +                    unsigned int len, unsigned int idx)
> +{
> +    trace_virtqueue_fill(vq, elem, len, idx);
> +
> +    virtqueue_unmap_sg(vq, elem, len);
>  
>      idx = (idx + vring_used_idx(vq)) % vq->vring.num;
>  
> 

Thanks,
Andrew James Sept. 24, 2015, 4:19 p.m. UTC | #2
On 09/18/2015 02:01 AM, Jason Wang wrote:
> Factor out sg unmapping logic. This will be reused by the patch that
> can discard descriptor.
> 
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
>  hw/virtio/virtio.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 0832db9..eb8d5ca 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -243,15 +243,12 @@ int virtio_queue_empty(VirtQueue *vq)
>      return vring_avail_idx(vq) == vq->last_avail_idx;
>  }
>  
> -void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
> -                    unsigned int len, unsigned int idx)
> +static void virtqueue_unmap_sg(VirtQueue *vq, const VirtQueueElement *elem,
> +                               unsigned int len)
>  {
>      unsigned int offset;
>      int i;
>  
> -    trace_virtqueue_fill(vq, elem, len, idx);
> -
> -    offset = 0;
>      for (i = 0; i < elem->in_num; i++) {
>          size_t size = MIN(len - offset, elem->in_sg[i].iov_len);
>  

Should the "offset = 0" really be dropped here? Seems like it ends
up uninitialized. GCC thinks it might too.

> @@ -266,6 +263,14 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
>          cpu_physical_memory_unmap(elem->out_sg[i].iov_base,
>                                    elem->out_sg[i].iov_len,
>                                    0, elem->out_sg[i].iov_len);
> +}
> +
> +void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
> +                    unsigned int len, unsigned int idx)
> +{
> +    trace_virtqueue_fill(vq, elem, len, idx);
> +
> +    virtqueue_unmap_sg(vq, elem, len);
>  
>      idx = (idx + vring_used_idx(vq)) % vq->vring.num;
>  
> 

Thanks,
Jason Wang Sept. 25, 2015, 3:27 a.m. UTC | #3
On 09/25/2015 12:19 AM, Andrew James wrote:
> On 09/18/2015 02:01 AM, Jason Wang wrote:
>> > Factor out sg unmapping logic. This will be reused by the patch that
>> > can discard descriptor.
>> > 
>> > Cc: Michael S. Tsirkin <mst@redhat.com>
>> > Signed-off-by: Jason Wang <jasowang@redhat.com>
>> > ---
>> >  hw/virtio/virtio.c | 15 ++++++++++-----
>> >  1 file changed, 10 insertions(+), 5 deletions(-)
>> > 
>> > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
>> > index 0832db9..eb8d5ca 100644
>> > --- a/hw/virtio/virtio.c
>> > +++ b/hw/virtio/virtio.c
>> > @@ -243,15 +243,12 @@ int virtio_queue_empty(VirtQueue *vq)
>> >      return vring_avail_idx(vq) == vq->last_avail_idx;
>> >  }
>> >  
>> > -void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
>> > -                    unsigned int len, unsigned int idx)
>> > +static void virtqueue_unmap_sg(VirtQueue *vq, const VirtQueueElement *elem,
>> > +                               unsigned int len)
>> >  {
>> >      unsigned int offset;
>> >      int i;
>> >  
>> > -    trace_virtqueue_fill(vq, elem, len, idx);
>> > -
>> > -    offset = 0;
>> >      for (i = 0; i < elem->in_num; i++) {
>> >          size_t size = MIN(len - offset, elem->in_sg[i].iov_len);
>> >  
> Should the "offset = 0" really be dropped here? 

Probably not.

> Seems like it ends
> up uninitialized. GCC thinks it might too.
>

Yes, will keep the offset initialization in V2.

Thanks
diff mbox

Patch

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 0832db9..eb8d5ca 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -243,15 +243,12 @@  int virtio_queue_empty(VirtQueue *vq)
     return vring_avail_idx(vq) == vq->last_avail_idx;
 }
 
-void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
-                    unsigned int len, unsigned int idx)
+static void virtqueue_unmap_sg(VirtQueue *vq, const VirtQueueElement *elem,
+                               unsigned int len)
 {
     unsigned int offset;
     int i;
 
-    trace_virtqueue_fill(vq, elem, len, idx);
-
-    offset = 0;
     for (i = 0; i < elem->in_num; i++) {
         size_t size = MIN(len - offset, elem->in_sg[i].iov_len);
 
@@ -266,6 +263,14 @@  void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
         cpu_physical_memory_unmap(elem->out_sg[i].iov_base,
                                   elem->out_sg[i].iov_len,
                                   0, elem->out_sg[i].iov_len);
+}
+
+void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
+                    unsigned int len, unsigned int idx)
+{
+    trace_virtqueue_fill(vq, elem, len, idx);
+
+    virtqueue_unmap_sg(vq, elem, len);
 
     idx = (idx + vring_used_idx(vq)) % vq->vring.num;