Skip to contentSkip to conversation

virtio-scsi: fix object check failure

PATCH In review Ming Lei 4 participants 10 messages Jun 18, 2014 – Jul 26, 2014

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 virtio-scsi: fix object check failure

In case of vhost-scsi, the object type of VirtIODevice isn't VirtIOSCSI, so use the cast trick to fix the problem like in virtio_scsi_handle_cmd()

Cc Anthony Liguori <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Paolo Bonzini <[email protected]>
---
 hw/scsi/virtio-scsi.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/scsi/virtio-scsi.c +1 -1
index b0d7517..13700f5 100644
@@ -538,7 +538,7 @@ static void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev,
 
 static void virtio_scsi_handle_event(VirtIODevice *vdev, VirtQueue *vq)
 {
-    VirtIOSCSI *s = VIRTIO_SCSI(vdev);
+    VirtIOSCSI *s = (VirtIOSCSI *)vdev;
 
     if (s->events_dropped) {
         virtio_scsi_push_event(s, NULL, VIRTIO_SCSI_T_NO_EVENT, 0);
Signature · 1 line
1.7.9.5
#1 lore raw

Il 18/06/2014 14:13, Ming Lei ha scritto:

Quoted 19 lines

In case of vhost-scsi, the object type of VirtIODevice isn't VirtIOSCSI, so use the cast trick to fix the problem like in virtio_scsi_handle_cmd()

Cc Anthony Liguori <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Paolo Bonzini <[email protected]>
---
 hw/scsi/virtio-scsi.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/scsi/virtio-scsi.c +0 -0
index b0d7517..13700f5 100644

hw/scsi/virtio-scsi.c static void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev, · line 544

Quoted 8 lines
hw/scsi/virtio-scsi.c +1 -1
@@ -538,7 +538,7 @@ static void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev,
 
 static void virtio_scsi_handle_event(VirtIODevice *vdev, VirtQueue *vq)
 {
-    VirtIOSCSI *s = VIRTIO_SCSI(vdev);
+    VirtIOSCSI *s = (VirtIOSCSI *)vdev;
 
     if (s->events_dropped) {
         virtio_scsi_push_event(s, NULL, VIRTIO_SCSI_T_NO_EVENT, 0);

This should never be triggered by vhost-scsi. Perhaps a bug in the kernel?

Paolo

author
#2 lore raw
Quoted 27 lines · Paolo Bonzini

Il 18/06/2014 14:13, Ming Lei ha scritto:

Quoted 25 lines

In case of vhost-scsi, the object type of VirtIODevice isn't VirtIOSCSI, so use the cast trick to fix the problem like in virtio_scsi_handle_cmd()

Cc Anthony Liguori <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Paolo Bonzini <[email protected]>
---
 hw/scsi/virtio-scsi.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/scsi/virtio-scsi.c +1 -1
index b0d7517..13700f5 100644
@@ -538,7 +538,7 @@ static void virtio_scsi_push_event(VirtIOSCSI *s,
 SCSIDevice *dev,
 
 static void virtio_scsi_handle_event(VirtIODevice *vdev, VirtQueue *vq)
 {
-    VirtIOSCSI *s = VIRTIO_SCSI(vdev);
+    VirtIOSCSI *s = (VirtIOSCSI *)vdev;
 
Quoted 5 lines
Quoted 3 lines
hw/scsi/virtio-scsi.c +0 -0
     if (s->events_dropped) {
         virtio_scsi_push_event(s, NULL, VIRTIO_SCSI_T_NO_EVENT, 0);

This should never be triggered by vhost-scsi. Perhaps a bug in the kernel?

It can be triggered with rmmod, system suspend, reboot...

Thanks,
--
Ming Lei

#3 lore raw

Il 18/06/2014 16:18, Ming Lei ha scritto:

Quoted 2 lines
Quoted 1 line
Quoted 1 line

This should never be triggered by vhost-scsi. Perhaps a bug in the kernel?

It can be triggered with rmmod, system suspend, reboot...

Yes, but it should not.

What happens if you change VHOST_SCSI_VQ_NUM_FIXED from 2 to 3?

Paolo

#4 lore raw

Il 18/06/2014 17:02, Paolo Bonzini ha scritto:

Quoted 8 lines

Il 18/06/2014 16:18, Ming Lei ha scritto:

Quoted 3 lines
Quoted 2 lines
Quoted 1 line

This should never be triggered by vhost-scsi. Perhaps a bug in the

kernel?

It can be triggered with rmmod, system suspend, reboot...

Yes, but it should not.

What happens if you change VHOST_SCSI_VQ_NUM_FIXED from 2 to 3?

Sorry, brain fart here. The number of interrupts in virtio-scsi is queues+3 because of the configuration interrupt. This does not apply here.

Anyway, vhost-scsi passes the number of virtqueues correctly to the kernel.

QEMU might be triggering this because, when vhost is stopped, the queue is still not empty (as expected, since it's a receive queue).

Can you check that this is the case?

If so, patching QEMU is correct, but you need to change VIRTIO_SCSI(vdev) to VIRTIO_SCSI_COMMON(vdev), and move events_dropped from VirtIOSCSI to VirtIOSCSICommon.

Paolo

author
#5 lore raw
Quoted 18 lines · Paolo Bonzini

Il 18/06/2014 17:02, Paolo Bonzini ha scritto:

Quoted 11 lines

Il 18/06/2014 16:18, Ming Lei ha scritto:

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

This should never be triggered by vhost-scsi. Perhaps a bug in the

kernel?

It can be triggered with rmmod, system suspend, reboot...

Yes, but it should not.

What happens if you change VHOST_SCSI_VQ_NUM_FIXED from 2 to 3?

Sorry, brain fart here. The number of interrupts in virtio-scsi is queues+3 because of the configuration interrupt. This does not apply here.

Quoted 6 lines

Anyway, vhost-scsi passes the number of virtqueues correctly to the kernel.

QEMU might be triggering this because, when vhost is stopped, the queue is still not empty (as expected, since it's a receive queue).

Can you check that this is the case?

Yes, that is the case.

Quoted 4 lines

If so, patching QEMU is correct, but you need to change VIRTIO_SCSI(vdev) to VIRTIO_SCSI_COMMON(vdev), and move events_dropped from VirtIOSCSI to VirtIOSCSICommon.

This approach should be better.

Thanks,
--
Ming Lei

#6 lore raw

Hi Ming & Paolo,

Quoted 26 lines · Ming Lei
Quoted 18 lines · Paolo Bonzini

Il 18/06/2014 17:02, Paolo Bonzini ha scritto:

Quoted 11 lines

Il 18/06/2014 16:18, Ming Lei ha scritto:

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

This should never be triggered by vhost-scsi. Perhaps a bug in the

kernel?

It can be triggered with rmmod, system suspend, reboot...

Yes, but it should not.

What happens if you change VHOST_SCSI_VQ_NUM_FIXED from 2 to 3?

Sorry, brain fart here. The number of interrupts in virtio-scsi is queues+3 because of the configuration interrupt. This does not apply here.

Quoted 6 lines

Anyway, vhost-scsi passes the number of virtqueues correctly to the kernel.

QEMU might be triggering this because, when vhost is stopped, the queue is still not empty (as expected, since it's a receive queue).

Can you check that this is the case?

Quoted 8 lines

Yes, that is the case.

Quoted 4 lines

If so, patching QEMU is correct, but you need to change VIRTIO_SCSI(vdev) to VIRTIO_SCSI_COMMON(vdev), and move events_dropped from VirtIOSCSI to VirtIOSCSICommon.

This approach should be better.

Just curious if this patch was picked up by upstream yet, and if it needs to be CC'd to stable for vhost-scsi code in >= v1.5.y ..?

Thanks,

--nab

author
#7 lore raw
Quoted 32 lines · Nicholas A. Bellinger

Hi Ming & Paolo,

Quoted 29 lines · Ming Lei
Quoted 18 lines · Paolo Bonzini

Il 18/06/2014 17:02, Paolo Bonzini ha scritto:

Quoted 11 lines

Il 18/06/2014 16:18, Ming Lei ha scritto:

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

This should never be triggered by vhost-scsi. Perhaps a bug in the

kernel?

It can be triggered with rmmod, system suspend, reboot...

Yes, but it should not.

What happens if you change VHOST_SCSI_VQ_NUM_FIXED from 2 to 3?

Sorry, brain fart here. The number of interrupts in virtio-scsi is queues+3 because of the configuration interrupt. This does not apply here.

Quoted 6 lines

Anyway, vhost-scsi passes the number of virtqueues correctly to the kernel.

QEMU might be triggering this because, when vhost is stopped, the queue is still not empty (as expected, since it's a receive queue).

Can you check that this is the case?

Yes, that is the case.

Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

If so, patching QEMU is correct, but you need to change VIRTIO_SCSI(vdev) to VIRTIO_SCSI_COMMON(vdev), and move events_dropped from VirtIOSCSI to VirtIOSCSICommon.

This approach should be better.

Just curious if this patch was picked up by upstream yet, and if it needs to be CC'd to stable for vhost-scsi code in >= v1.5.y ..?

Below is the merged version which has been marked as stable:

http://git.qemu.org/?p=qemu.git;a=commit;h=91d670fbf9945ca4ecbd123affb36889e7fe8a5d

Thanks,

#8 lore raw
In reply to Ming Lei

Am 18.06.2014 14:13, schrieb Ming Lei:

Quoted 18 lines

In case of vhost-scsi, the object type of VirtIODevice isn't VirtIOSCSI, so use the cast trick to fix the problem like in virtio_scsi_handle_cmd()

Cc Anthony Liguori <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Paolo Bonzini <[email protected]>
---
 hw/scsi/virtio-scsi.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/scsi/virtio-scsi.c +0 -0
index b0d7517..13700f5 100644

hw/scsi/virtio-scsi.c static void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev, · line 543

Quoted 7 lines
hw/scsi/virtio-scsi.c +1 -1
@@ -538,7 +538,7 @@ static void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev,
 
 static void virtio_scsi_handle_event(VirtIODevice *vdev, VirtQueue *vq)
 {
-    VirtIOSCSI *s = VIRTIO_SCSI(vdev);
+    VirtIOSCSI *s = (VirtIOSCSI *)vdev;
 
     if (s->events_dropped) {

If s is not of type VirtIOSCSI as you indicate, then you shouldn't be accessing its fields here either. You're basically disabling the safety mechanism to avoid just that.

If you see a direct cast used elsewhere, it is most likely for performance reasons, not for correctness.

Regards,
Andreas

Quoted 2 lines
hw/scsi/virtio-scsi.c +0 -0
         virtio_scsi_push_event(s, NULL, VIRTIO_SCSI_T_NO_EVENT, 0);
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
author
#9 lore raw
Quoted 25 lines · Andreas Färber

Am 18.06.2014 14:13, schrieb Ming Lei:

Quoted 24 lines

In case of vhost-scsi, the object type of VirtIODevice isn't VirtIOSCSI, so use the cast trick to fix the problem like in virtio_scsi_handle_cmd()

Cc Anthony Liguori <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Paolo Bonzini <[email protected]>
---
 hw/scsi/virtio-scsi.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/scsi/virtio-scsi.c +1 -1
index b0d7517..13700f5 100644
@@ -538,7 +538,7 @@ static void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev,
 
 static void virtio_scsi_handle_event(VirtIODevice *vdev, VirtQueue *vq)
 {
-    VirtIOSCSI *s = VIRTIO_SCSI(vdev);
+    VirtIOSCSI *s = (VirtIOSCSI *)vdev;
 
Quoted 5 lines

hw/scsi/virtio-scsi.c static void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev, · line 543

Quoted 1 line
hw/scsi/virtio-scsi.c +0 -0
     if (s->events_dropped) {

If s is not of type VirtIOSCSI as you indicate, then you shouldn't be accessing its fields here either. You're basically disabling the safety mechanism to avoid just that.

Yes, you are right, and the correct approach should let VirtIOSCSI as parent of VHostSCSI, so how about attached patch?

Quoted 3 lines

If you see a direct cast used elsewhere, it is most likely for performance reasons, not for correctness.

The other two places aren't for performance reason, and it is designed as so.

Thanks,
--
Ming Lei

From b1e09246ee961a67a301dd0591a2919cd9b5bab3 Mon Sep 17 00:00:00 2001
From: Ming Lei <[email protected]>
Date: Wed, 18 Jun 2014 20:06:55 +0800
Subject: [PATCH] virtio-scsi: fix object check failure

In case of vhost-scsi, the object type of VirtIODevice isn't VirtIOSCSI, so use the cast trick to fix the problem like in virtio_scsi_handle_cmd()

Cc Anthony Liguori <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Paolo Bonzini <[email protected]>
---
 hw/scsi/vhost-scsi.c           |    2 +-
 hw/scsi/virtio-scsi.c          |    2 +-
 hw/virtio/virtio-pci.c         |    2 +-
 include/hw/virtio/vhost-scsi.h |    2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
hw/scsi/vhost-scsi.c +1 -1
index 3983a5b..76985a7 100644
@@ -257,7 +257,7 @@ static void vhost_scsi_unrealize(DeviceState *dev, Error **errp)
 }
 
 static Property vhost_scsi_properties[] = {
-    DEFINE_VHOST_SCSI_PROPERTIES(VHostSCSI, parent_obj.conf),
+    DEFINE_VHOST_SCSI_PROPERTIES(VHostSCSI, parent.parent_obj.conf),
     DEFINE_PROP_END_OF_LIST(),
 };
 
hw/scsi/virtio-scsi.c +1 -1
index b0d7517..13700f5 100644
@@ -538,7 +538,7 @@ static void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev,
 
 static void virtio_scsi_handle_event(VirtIODevice *vdev, VirtQueue *vq)
 {
-    VirtIOSCSI *s = VIRTIO_SCSI(vdev);
+    VirtIOSCSI *s = (VirtIOSCSI *)vdev;
 
     if (s->events_dropped) {
         virtio_scsi_push_event(s, NULL, VIRTIO_SCSI_T_NO_EVENT, 0);
hw/virtio/virtio-pci.c +1 -1
index af2e1c3..b428898 100644
@@ -1199,7 +1199,7 @@ static const TypeInfo virtio_scsi_pci_info = {
 static Property vhost_scsi_pci_properties[] = {
     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
                        DEV_NVECTORS_UNSPECIFIED),
-    DEFINE_VHOST_SCSI_PROPERTIES(VHostSCSIPCI, vdev.parent_obj.conf),
+    DEFINE_VHOST_SCSI_PROPERTIES(VHostSCSIPCI, vdev.parent.parent_obj.conf),
     DEFINE_PROP_END_OF_LIST(),
 };
 
include/hw/virtio/vhost-scsi.h +1 -1
index 85cc031..62fc820 100644
@@ -55,7 +55,7 @@ enum vhost_scsi_vq_list {
         OBJECT_CHECK(VHostSCSI, (obj), TYPE_VHOST_SCSI)
 
 typedef struct VHostSCSI {
-    VirtIOSCSICommon parent_obj;
+    VirtIOSCSI parent;
 
     Error *migration_blocker;
 
Signature · 1 line
1.7.9.5