Skip to contentSkip to conversation

virtio: feature bit fixup

PATCH In review Cornelia Huck 4 participants 7 messages Dec 12, 2014 – Jan 21, 2015

lore
Share & tools
lore
#0 lore raw

cover virtio: feature bit fixup

When reviewing my feature bit changes for 1.0, Thomas noticed that I accidentally fixed a bug :) There are two further places with the same problem that Thomas noticed as well.

I wonder why we didn't see problems before...

Cornelia Huck (1):
virtio: fix feature bit checks

 hw/scsi/virtio-scsi.c       | 2 +-
 hw/virtio/dataplane/vring.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
1.8.5.5
#1 lore raw

PATCH 1/1 virtio: fix feature bit checks

Several places check against the feature bit number instead of against the feature bit. Fix them.

---
 hw/scsi/virtio-scsi.c       | 2 +-
 hw/virtio/dataplane/vring.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
hw/scsi/virtio-scsi.c +1 -1
index ef48550..a44c410 100644
@@ -144,7 +144,7 @@ static int virtio_scsi_parse_req(VirtIOSCSIReq *req,
      *
      * TODO: always disable this workaround for virtio 1.0 devices.
      */
-    if ((vdev->guest_features & VIRTIO_F_ANY_LAYOUT) == 0) {
+    if ((vdev->guest_features & (1 << VIRTIO_F_ANY_LAYOUT)) == 0) {
         req_size = req->elem.out_sg[0].iov_len;
         resp_size = req->elem.in_sg[0].iov_len;
     }
hw/virtio/dataplane/vring.c +2 -2
index 61f6d83..78c6f45 100644
@@ -133,12 +133,12 @@ bool vring_should_notify(VirtIODevice *vdev, Vring *vring)
      * interrupts. */
     smp_mb();
 
-    if ((vdev->guest_features & VIRTIO_F_NOTIFY_ON_EMPTY) &&
+    if ((vdev->guest_features & (1 << VIRTIO_F_NOTIFY_ON_EMPTY)) &&
         unlikely(vring->vr.avail->idx == vring->last_avail_idx)) {
         return true;
     }
 
-    if (!(vdev->guest_features & VIRTIO_RING_F_EVENT_IDX)) {
+    if (!(vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX))) {
         return !(vring->vr.avail->flags & VRING_AVAIL_F_NO_INTERRUPT);
     }
     old = vring->signalled_used;
Signature · 1 line
1.8.5.5
#2 lore raw

Re: [Qemu-devel] [PATCH 1/1] virtio: fix feature bit checks

Quoted 5 lines · Cornelia Huck

Several places check against the feature bit number instead of against the feature bit. Fix them.

Cc stable?
Quoted 39 lines
---
 hw/scsi/virtio-scsi.c       | 2 +-
 hw/virtio/dataplane/vring.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
hw/scsi/virtio-scsi.c +1 -1
index ef48550..a44c410 100644
@@ -144,7 +144,7 @@ static int virtio_scsi_parse_req(VirtIOSCSIReq *req,
      *
      * TODO: always disable this workaround for virtio 1.0 devices.
      */
-    if ((vdev->guest_features & VIRTIO_F_ANY_LAYOUT) == 0) {
+    if ((vdev->guest_features & (1 << VIRTIO_F_ANY_LAYOUT)) == 0) {
         req_size = req->elem.out_sg[0].iov_len;
         resp_size = req->elem.in_sg[0].iov_len;
     }
hw/virtio/dataplane/vring.c +2 -2
index 61f6d83..78c6f45 100644
@@ -133,12 +133,12 @@ bool vring_should_notify(VirtIODevice *vdev, Vring *vring)
      * interrupts. */
     smp_mb();
 
-    if ((vdev->guest_features & VIRTIO_F_NOTIFY_ON_EMPTY) &&
+    if ((vdev->guest_features & (1 << VIRTIO_F_NOTIFY_ON_EMPTY)) &&
         unlikely(vring->vr.avail->idx == vring->last_avail_idx)) {
         return true;
     }
 
-    if (!(vdev->guest_features & VIRTIO_RING_F_EVENT_IDX)) {
+    if (!(vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX))) {
         return !(vring->vr.avail->flags & VRING_AVAIL_F_NO_INTERRUPT);
     }
     old = vring->signalled_used;
Signature · 1 line
1.8.5.5
#3 lore raw

Re: [Qemu-devel] [PATCH 1/1] virtio: fix feature bit checks

Quoted 8 lines · On Fri, 12 Dec 2014 11:08:21 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 5 lines · Cornelia Huck

Several places check against the feature bit number instead of against the feature bit. Fix them.

Cc stable?

Hm, yeah. Can you add it?

Quoted 5 lines
Quoted 5 lines
---
 hw/scsi/virtio-scsi.c       | 2 +-
 hw/virtio/dataplane/vring.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
#4 lore raw

Re: [Qemu-devel] [PATCH 1/1] virtio: fix feature bit checks

Quoted 7 lines · Cornelia Huck
Quoted 4 lines · On Fri, 12 Dec 2014 11:08:21 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 3 lines · Cornelia Huck

Several places check against the feature bit number instead of against the feature bit. Fix them.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Cc stable?

Hm, yeah. Can you add it?

Ccing [email protected]

Fam

#5 lore raw

Re: [Qemu-devel] [PATCH 1/1] virtio: fix feature bit checks

In reply to Cornelia Huck
Quoted 32 lines · On Fri, 12 Dec 2014 10:01:46 +0100 Cornelia Huck <[email protected]>…

Several places check against the feature bit number instead of against the feature bit. Fix them.

---
 hw/scsi/virtio-scsi.c       | 2 +-
 hw/virtio/dataplane/vring.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
hw/scsi/virtio-scsi.c +1 -1
index ef48550..a44c410 100644
@@ -144,7 +144,7 @@ static int virtio_scsi_parse_req(VirtIOSCSIReq *req,
      *
      * TODO: always disable this workaround for virtio 1.0 devices.
      */
-    if ((vdev->guest_features & VIRTIO_F_ANY_LAYOUT) == 0) {
+    if ((vdev->guest_features & (1 << VIRTIO_F_ANY_LAYOUT)) == 0) {
         req_size = req->elem.out_sg[0].iov_len;
         resp_size = req->elem.in_sg[0].iov_len;
     }
hw/virtio/dataplane/vring.c +0 -1
index 61f6d83..78c6f45 100644
@@ -133,12 +133,12 @@ bool vring_should_notify(VirtIODevice *vdev, Vring *vring)
      * interrupts. */
     smp_mb();
 
-    if ((vdev->guest_features & VIRTIO_F_NOTIFY_ON_EMPTY) &&

hw/virtio/dataplane/vring.c bool vring_should_notify(VirtIODevice *vdev, Vring *vring) · line 144

Quoted 10 lines
hw/virtio/dataplane/vring.c +2 -1
+    if ((vdev->guest_features & (1 << VIRTIO_F_NOTIFY_ON_EMPTY)) &&
         unlikely(vring->vr.avail->idx == vring->last_avail_idx)) {
         return true;
     }
 
-    if (!(vdev->guest_features & VIRTIO_RING_F_EVENT_IDX)) {
+    if (!(vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX))) {
         return !(vring->vr.avail->flags & VRING_AVAIL_F_NO_INTERRUPT);
     }
     old = vring->signalled_used;

Ping ... somebody taking care of this? It's a bug fix for current code, so IMHO this patch should not wait for the inclusion of the other virtio-1 stuff...

Thomas

#6 lore raw

Re: [Qemu-devel] [PATCH 1/1] virtio: fix feature bit checks

Quoted 50 lines · Thomas Huth
Quoted 32 lines · On Fri, 12 Dec 2014 10:01:46 +0100 Cornelia Huck <[email protected]>…

Several places check against the feature bit number instead of against the feature bit. Fix them.

---
 hw/scsi/virtio-scsi.c       | 2 +-
 hw/virtio/dataplane/vring.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
hw/scsi/virtio-scsi.c +1 -1
index ef48550..a44c410 100644
@@ -144,7 +144,7 @@ static int virtio_scsi_parse_req(VirtIOSCSIReq *req,
      *
      * TODO: always disable this workaround for virtio 1.0 devices.
      */
-    if ((vdev->guest_features & VIRTIO_F_ANY_LAYOUT) == 0) {
+    if ((vdev->guest_features & (1 << VIRTIO_F_ANY_LAYOUT)) == 0) {
         req_size = req->elem.out_sg[0].iov_len;
         resp_size = req->elem.in_sg[0].iov_len;
     }
hw/virtio/dataplane/vring.c +0 -1
index 61f6d83..78c6f45 100644
@@ -133,12 +133,12 @@ bool vring_should_notify(VirtIODevice *vdev, Vring *vring)
      * interrupts. */
     smp_mb();
 
-    if ((vdev->guest_features & VIRTIO_F_NOTIFY_ON_EMPTY) &&

hw/virtio/dataplane/vring.c bool vring_should_notify(VirtIODevice *vdev, Vring *vring) · line 144

Quoted 10 lines
hw/virtio/dataplane/vring.c +2 -1
+    if ((vdev->guest_features & (1 << VIRTIO_F_NOTIFY_ON_EMPTY)) &&
         unlikely(vring->vr.avail->idx == vring->last_avail_idx)) {
         return true;
     }
 
-    if (!(vdev->guest_features & VIRTIO_RING_F_EVENT_IDX)) {
+    if (!(vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX))) {
         return !(vring->vr.avail->flags & VRING_AVAIL_F_NO_INTERRUPT);
     }
     old = vring->signalled_used;

Ping ... somebody taking care of this? It's a bug fix for current code, so IMHO this patch should not wait for the inclusion of the other virtio-1 stuff...

Quoted 1 line

Thomas

It's in my queue.