Skip to contentSkip to conversation

VirtIO: Fix QEMU crash during Windows PNP tests

PATCH In review Yan Vugenfirer 4 participants 7 messages Sep 14, 2009 – Mar 2, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 VirtIO: Fix QEMU crash during Windows PNP tests

---
 hw/virtio-pci.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
hw/virtio-pci.c +12 -2
index f812ab7..a0a22c4 100644
@@ -364,8 +364,17 @@ static void virtio_map(PCIDevice *pci_dev, int region_num,
 static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
                                 uint32_t val, int len)
 {
+    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+
+    if (PCI_COMMAND == address) {
+        if (!(val & PCI_COMMAND_MASTER)) {
+            proxy->vdev->status &= ~VIRTIO_CONFIG_S_DRIVER_OK;
+        }
+    }
+
     pci_default_write_config(pci_dev, address, val, len);
-    msix_write_config(pci_dev, address, val, len);
+    if(proxy->vdev->nvectors)
+        msix_write_config(pci_dev, address, val, len);
 }
 
 static const VirtIOBindings virtio_pci_bindings = {
@@ -407,11 +416,12 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,
                          msix_bar_size(&proxy->pci_dev),
                          PCI_ADDRESS_SPACE_MEM,
                          msix_mmio_map);
-        proxy->pci_dev.config_write = virtio_write_config;
         proxy->pci_dev.unregister = msix_uninit;
     } else
         vdev->nvectors = 0;
 
+    proxy->pci_dev.config_write = virtio_write_config;
+
     size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev) + vdev->config_len;
     if (size & (size-1))
         size = 1 << qemu_fls(size);
Signature · 1 line
1.5.5.6
#1 lore raw
Quoted 11 lines · Yan Vugenfirer

---
hw/virtio-pci.c | 14 ++++++++++++--

1 files changed, 12 insertions(+), 2 deletions(-)
hw/virtio-pci.c +0 -0
index f812ab7..a0a22c4 100644

hw/virtio-pci.c static void virtio_map(PCIDevice *pci_dev, int region_num, · line 371

Quoted 8 lines
hw/virtio-pci.c +5 -0
@@ -364,8 +364,17 @@ static void virtio_map(PCIDevice *pci_dev, int region_num,
 static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
                                uint32_t val, int len)
 {
+    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+
+    if (PCI_COMMAND == address) {
+        if (!(val & PCI_COMMAND_MASTER)) {
+            proxy->vdev->status &= ~VIRTIO_CONFIG_S_DRIVER_OK;

This part breaks PCI hotplug with Linux guests.

What happens is the following:

(qemu) pci_add auto nic model=virtio,vlan=0
- Virtio dev 1 -> write config (0)
- Virtio dev 1 -> write config (0x3)
- Virtio dev 1 -> set status explicitly to OK

(qemu) pci_add auto storage file=/tmp/image.raw,if=virtio
- Virtio dev 1 -> write config (0x3)
-> Unset DRIVER_OK bit
-> network device becomes unresponsive
- Virtio dev 2 -> write config (0)
- Virtio dev 2 -> write config (0x3)
- Virtio dev 2 -> set status explicitly to OK

Please either revert this patch or provide a proper fix.

Alex

#2 lore raw
Quoted 25 lines · Alexander Graf
Quoted 11 lines · Yan Vugenfirer

---
hw/virtio-pci.c | 14 ++++++++++++--

1 files changed, 12 insertions(+), 2 deletions(-)
hw/virtio-pci.c +0 -0
index f812ab7..a0a22c4 100644

hw/virtio-pci.c static void virtio_map(PCIDevice *pci_dev, int region_num, · line 371

Quoted 8 lines
hw/virtio-pci.c +5 -0
@@ -364,8 +364,17 @@ static void virtio_map(PCIDevice *pci_dev, int region_num,
 static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
                                uint32_t val, int len)
 {
+    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+
+    if (PCI_COMMAND == address) {
+        if (!(val & PCI_COMMAND_MASTER)) {
+            proxy->vdev->status &= ~VIRTIO_CONFIG_S_DRIVER_OK;

This part breaks PCI hotplug with Linux guests.

Quoted 1 line

What happens is the following:

Looks like something is broken even without this patch.

Quoted 5 lines

(qemu) pci_add auto nic model=virtio,vlan=0
- Virtio dev 1 -> write config (0)
- Virtio dev 1 -> write config (0x3)
- Virtio dev 1 -> set status explicitly to OK

Why Linux doesn't enable bus mastering on this device?

Quoted 3 lines

(qemu) pci_add auto storage file=/tmp/image.raw,if=virtio
- Virtio dev 1 -> write config (0x3)

Why Linux touches unrelated device's config space?

Quoted 10 lines

-> Unset DRIVER_OK bit
-> network device becomes unresponsive
- Virtio dev 2 -> write config (0)
- Virtio dev 2 -> write config (0x3)
- Virtio dev 2 -> set status explicitly to OK

Please either revert this patch or provide a proper fix.

Alex

--
Gleb.

#3 lore raw
Quoted 27 lines · Gleb Natapov
Quoted 25 lines · Alexander Graf
Quoted 11 lines · Yan Vugenfirer

---
hw/virtio-pci.c | 14 ++++++++++++--

1 files changed, 12 insertions(+), 2 deletions(-)
hw/virtio-pci.c +0 -0
index f812ab7..a0a22c4 100644

hw/virtio-pci.c static void virtio_map(PCIDevice *pci_dev, int region_num, · line 371

Quoted 8 lines
hw/virtio-pci.c +5 -0
@@ -364,8 +364,17 @@ static void virtio_map(PCIDevice *pci_dev, int region_num,
 static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
                                uint32_t val, int len)
 {
+    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+
+    if (PCI_COMMAND == address) {
+        if (!(val & PCI_COMMAND_MASTER)) {
+            proxy->vdev->status &= ~VIRTIO_CONFIG_S_DRIVER_OK;

This part breaks PCI hotplug with Linux guests.

Quoted 1 line

What happens is the following:

Quoted 8 lines

Looks like something is broken even without this patch.

Quoted 5 lines

(qemu) pci_add auto nic model=virtio,vlan=0
- Virtio dev 1 -> write config (0)
- Virtio dev 1 -> write config (0x3)
- Virtio dev 1 -> set status explicitly to OK

Why Linux doesn't enable bus mastering on this device?

I fixed this, and Rusty said he has applied the patch, but it seems the patch got lost later:

http://lkml.org/lkml/2009/11/29/73

Alexander, could you please check whether applying this patch fixes hotplug for you?
If yes I will queue it up for 2.6.34.

Quoted 18 lines
Quoted 3 lines

(qemu) pci_add auto storage file=/tmp/image.raw,if=virtio
- Virtio dev 1 -> write config (0x3)

Why Linux touches unrelated device's config space?

Quoted 10 lines

-> Unset DRIVER_OK bit
-> network device becomes unresponsive
- Virtio dev 2 -> write config (0)
- Virtio dev 2 -> write config (0x3)
- Virtio dev 2 -> set status explicitly to OK

Please either revert this patch or provide a proper fix.

Alex

--
Gleb.

#4 lore raw
Quoted 37 lines · Michael S. Tsirkin
Quoted 27 lines · Gleb Natapov
Quoted 25 lines · Alexander Graf
Quoted 11 lines · Yan Vugenfirer

---
hw/virtio-pci.c | 14 ++++++++++++--

1 files changed, 12 insertions(+), 2 deletions(-)
hw/virtio-pci.c +0 -0
index f812ab7..a0a22c4 100644

hw/virtio-pci.c static void virtio_map(PCIDevice *pci_dev, int region_num, · line 371

Quoted 8 lines
hw/virtio-pci.c +5 -0
@@ -364,8 +364,17 @@ static void virtio_map(PCIDevice *pci_dev, int region_num,
 static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
                               uint32_t val, int len)
 {
+    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+
+    if (PCI_COMMAND == address) {
+        if (!(val & PCI_COMMAND_MASTER)) {
+            proxy->vdev->status &= ~VIRTIO_CONFIG_S_DRIVER_OK;

This part breaks PCI hotplug with Linux guests.

Quoted 1 line

What happens is the following:

Quoted 8 lines

Looks like something is broken even without this patch.

Quoted 5 lines

(qemu) pci_add auto nic model=virtio,vlan=0
- Virtio dev 1 -> write config (0)
- Virtio dev 1 -> write config (0x3)
- Virtio dev 1 -> set status explicitly to OK

Why Linux doesn't enable bus mastering on this device?

Quoted 8 lines

I fixed this, and Rusty said he has applied the patch, but it seems the patch got lost later:

http://lkml.org/lkml/2009/11/29/73

Alexander, could you please check whether applying this patch fixes hotplug for you?
If yes I will queue it up for 2.6.34.

So we're looking at a guest bug?

It's still a qemu regression then. This configuration used to work with 0.10. There should at least be a feature bit from the guest saying "I'm good with bus mastering", so we can enable the check only for those.

Alex

#5 lore raw
Quoted 43 lines · Alexander Graf
Quoted 40 lines · Michael S. Tsirkin
Quoted 27 lines · Gleb Natapov
Quoted 25 lines · Alexander Graf
Quoted 11 lines · Yan Vugenfirer

---
hw/virtio-pci.c | 14 ++++++++++++--

1 files changed, 12 insertions(+), 2 deletions(-)
hw/virtio-pci.c +0 -0
index f812ab7..a0a22c4 100644

hw/virtio-pci.c static void virtio_map(PCIDevice *pci_dev, int region_num, · line 371

Quoted 8 lines
hw/virtio-pci.c +5 -0
@@ -364,8 +364,17 @@ static void virtio_map(PCIDevice *pci_dev, int region_num,
 static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
                               uint32_t val, int len)
 {
+    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+
+    if (PCI_COMMAND == address) {
+        if (!(val & PCI_COMMAND_MASTER)) {
+            proxy->vdev->status &= ~VIRTIO_CONFIG_S_DRIVER_OK;

This part breaks PCI hotplug with Linux guests.

Quoted 1 line

What happens is the following:

Quoted 8 lines

Looks like something is broken even without this patch.

Quoted 5 lines

(qemu) pci_add auto nic model=virtio,vlan=0
- Virtio dev 1 -> write config (0)
- Virtio dev 1 -> write config (0x3)
- Virtio dev 1 -> set status explicitly to OK

Why Linux doesn't enable bus mastering on this device?

I fixed this, and Rusty said he has applied the patch, but it seems the patch got lost later:

Quoted 7 lines
Quoted 5 lines

http://lkml.org/lkml/2009/11/29/73

Alexander, could you please check whether applying this patch fixes hotplug for you?
If yes I will queue it up for 2.6.34.

So we're looking at a guest bug?

Donnu. Does it work with the patch applied?

Quoted 5 lines

It's still a qemu regression then. This configuration used to work with 0.10. There should at least be a feature bit from the guest saying "I'm good with bus mastering", so we can enable the check only for those.
Alex

#6 lore raw
Quoted 46 lines · Michael S. Tsirkin
Quoted 45 lines · Alexander Graf
Quoted 42 lines · Michael S. Tsirkin
Quoted 27 lines · Gleb Natapov
Quoted 25 lines · Alexander Graf
Quoted 11 lines · Yan Vugenfirer

---
hw/virtio-pci.c | 14 ++++++++++++--

1 files changed, 12 insertions(+), 2 deletions(-)
hw/virtio-pci.c +0 -0
index f812ab7..a0a22c4 100644

hw/virtio-pci.c static void virtio_map(PCIDevice *pci_dev, int region_num, · line 371

Quoted 8 lines
hw/virtio-pci.c +5 -0
@@ -364,8 +364,17 @@ static void virtio_map(PCIDevice *pci_dev, int region_num,
 static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
                              uint32_t val, int len)
 {
+    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+
+    if (PCI_COMMAND == address) {
+        if (!(val & PCI_COMMAND_MASTER)) {
+            proxy->vdev->status &= ~VIRTIO_CONFIG_S_DRIVER_OK;

This part breaks PCI hotplug with Linux guests.

Quoted 1 line

What happens is the following:

Quoted 8 lines

Looks like something is broken even without this patch.

Quoted 5 lines

(qemu) pci_add auto nic model=virtio,vlan=0
- Virtio dev 1 -> write config (0)
- Virtio dev 1 -> write config (0x3)
- Virtio dev 1 -> set status explicitly to OK

Why Linux doesn't enable bus mastering on this device?

I fixed this, and Rusty said he has applied the patch, but it seems the patch got lost later:

http://lkml.org/lkml/2009/11/29/73

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Alexander, could you please check whether applying this patch fixes hotplug for you?
If yes I will queue it up for 2.6.34.

So we're looking at a guest bug?

Donnu. Does it work with the patch applied?

Yes, it works with the patch applied. It's still missing a capability though :-).

Alex