Skip to contentSkip to conversation

virtio-pci: error out when both legacy and modern modes are disabled

PATCH Superseded Greg Kurz 3 participants 9 messages Jul 21, 2016 – Jul 22, 2016

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Greg Kurz

author
#0 lore raw

PATCH v4 1/1 virtio-pci: error out when both legacy and modern modes are disabled

From: Greg Kurz <[email protected]>

Without presuming if we got there because of a user mistake or some more subtle bug in the tooling, it really does not make sense to implement a non-functional device.

---
v4: - rephrased error message and provide a hint to the user
- split string literals to stay below 80 characters
- added Marcel's R-b tag

---
 hw/virtio/virtio-pci.c |    8 ++++++++
 1 file changed, 8 insertions(+)
hw/virtio/virtio-pci.c +8 -0
index 755f9218b77d..72c4b392ffda 100644
@@ -1842,6 +1842,14 @@ static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp)
     VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);
     PCIDevice *pci_dev = &proxy->pci_dev;
 
+    if (!(virtio_pci_modern(proxy) || virtio_pci_legacy(proxy))) {
+        error_setg(errp, "device cannot work when both modern and legacy modes"
+                   " are disabled");
+        error_append_hint(errp, "Set either disable-modern or disable-legacy"
+                          " to off\n");
+        return;
+    }
+
     if (!(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_PCIE) &&
         virtio_pci_modern(proxy)) {
         pci_dev->cap_present |= QEMU_PCI_CAP_EXPRESS;
author
#1 lore raw
Quoted 6 lines · On Thu, 21 Jul 2016 23:21:16 +0200 Greg Kurz <[email protected]> wrote:

From: Greg Kurz <[email protected]>

Without presuming if we got there because of a user mistake or some more subtle bug in the tooling, it really does not make sense to implement a non-functional device.

Quoted 8 lines

---
v4: - rephrased error message and provide a hint to the user
- split string literals to stay below 80 characters
- added Marcel's R-b tag
---

Marcel,

I see that Michael has comments on your patch. If you feel this patch is valuable for 2.7, please consider carrying and pushing it, as I'm about to take a 1-month leave.

Thanks.

--
Greg

Quoted 24 lines
 hw/virtio/virtio-pci.c |    8 ++++++++
 1 file changed, 8 insertions(+)
hw/virtio/virtio-pci.c +8 -0
index 755f9218b77d..72c4b392ffda 100644
@@ -1842,6 +1842,14 @@ static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp)
     VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);
     PCIDevice *pci_dev = &proxy->pci_dev;
 
+    if (!(virtio_pci_modern(proxy) || virtio_pci_legacy(proxy))) {
+        error_setg(errp, "device cannot work when both modern and legacy modes"
+                   " are disabled");
+        error_append_hint(errp, "Set either disable-modern or disable-legacy"
+                          " to off\n");
+        return;
+    }
+
     if (!(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_PCIE) &&
         virtio_pci_modern(proxy)) {
         pci_dev->cap_present |= QEMU_PCI_CAP_EXPRESS;
#2 lore raw
Quoted 18 lines · Greg Kurz
Quoted 6 lines · On Thu, 21 Jul 2016 23:21:16 +0200 Greg Kurz <[email protected]> wrote:

From: Greg Kurz <[email protected]>

Without presuming if we got there because of a user mistake or some more subtle bug in the tooling, it really does not make sense to implement a non-functional device.

Quoted 8 lines

---
v4: - rephrased error message and provide a hint to the user
- split string literals to stay below 80 characters
- added Marcel's R-b tag
---

Quoted 6 lines

Marcel,

I see that Michael has comments on your patch. If you feel this patch is valuable for 2.7, please consider carrying and pushing it, as I'm about to take a 1-month leave.

I'll be sure to take it form here, thanks for the help! Marcel

Quoted 30 lines

Thanks.

--
Greg

Quoted 24 lines
  hw/virtio/virtio-pci.c |    8 ++++++++
  1 file changed, 8 insertions(+)
hw/virtio/virtio-pci.c +8 -0
index 755f9218b77d..72c4b392ffda 100644
@@ -1842,6 +1842,14 @@ static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp)
      VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);
      PCIDevice *pci_dev = &proxy->pci_dev;
 
+    if (!(virtio_pci_modern(proxy) || virtio_pci_legacy(proxy))) {
+        error_setg(errp, "device cannot work when both modern and legacy modes"
+                   " are disabled");
+        error_append_hint(errp, "Set either disable-modern or disable-legacy"
+                          " to off\n");
+        return;
+    }
+
      if (!(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_PCIE) &&
          virtio_pci_modern(proxy)) {
          pci_dev->cap_present |= QEMU_PCI_CAP_EXPRESS;
#3 lore raw
In reply to Greg Kurz
Quoted 22 lines · On Thu, 21 Jul 2016 23:21:16 +0200 Greg Kurz <[email protected]> wrote:

From: Greg Kurz <[email protected]>

Without presuming if we got there because of a user mistake or some more subtle bug in the tooling, it really does not make sense to implement a non-functional device.

---
v4: - rephrased error message and provide a hint to the user
- split string literals to stay below 80 characters
- added Marcel's R-b tag

---
 hw/virtio/virtio-pci.c |    8 ++++++++
 1 file changed, 8 insertions(+)
hw/virtio/virtio-pci.c +0 -0
index 755f9218b77d..72c4b392ffda 100644

hw/virtio/virtio-pci.c static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp) · line 1845

Quoted 4 lines
hw/virtio/virtio-pci.c +1 -0
@@ -1842,6 +1842,14 @@ static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp)
     VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);
     PCIDevice *pci_dev = &proxy->pci_dev;
 
+    if (!(virtio_pci_modern(proxy) || virtio_pci_legacy(proxy))) {

I'm not sure that I didn't mess up the sequence of the realize callbacks, but could disable_legacy still be AUTO here? In that case, we'd fail for disable-modern=on and disable-legacy unset (i.e., AUTO), which would be ok for pcie but not for !pcie.

Quoted 11 lines
hw/virtio/virtio-pci.c +7 -0
+        error_setg(errp, "device cannot work when both modern and legacy modes"
+                   " are disabled");
+        error_append_hint(errp, "Set either disable-modern or disable-legacy"
+                          " to off\n");
+        return;
+    }
+
     if (!(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_PCIE) &&
         virtio_pci_modern(proxy)) {
         pci_dev->cap_present |= QEMU_PCI_CAP_EXPRESS;
author
#4 lore raw
Quoted 28 lines · On Fri, 22 Jul 2016 10:04:35 +0200 Cornelia Huck <[email protected]>…
Quoted 25 lines · On Thu, 21 Jul 2016 23:21:16 +0200 Greg Kurz <[email protected]> wrote:

From: Greg Kurz <[email protected]>

Without presuming if we got there because of a user mistake or some more subtle bug in the tooling, it really does not make sense to implement a non-functional device.

---
v4: - rephrased error message and provide a hint to the user
- split string literals to stay below 80 characters
- added Marcel's R-b tag

---
 hw/virtio/virtio-pci.c |    8 ++++++++
 1 file changed, 8 insertions(+)
hw/virtio/virtio-pci.c +0 -0
index 755f9218b77d..72c4b392ffda 100644
@@ -1842,6 +1842,14 @@ static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp)
     VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);
     PCIDevice *pci_dev = &proxy->pci_dev;
 
Quoted 7 lines

hw/virtio/virtio-pci.c static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp) · line 1845

Quoted 1 line
hw/virtio/virtio-pci.c +1 -0
+    if (!(virtio_pci_modern(proxy) || virtio_pci_legacy(proxy))) {  

I'm not sure that I didn't mess up the sequence of the realize callbacks, but could disable_legacy still be AUTO here? In that case, we'd fail for disable-modern=on and disable-legacy unset (i.e., AUTO), which would be ok for pcie but not for !pcie.

Marcel made the same comment in:

https://lists.gnu.org/archive/html/qemu-devel/2016-07/msg05225.html

If the user explicitly disables modern, she shouldn't rely on QEMU implicitly enabling legacy, hence the suggestion in error_append_hint().

Quoted 12 lines
Quoted 11 lines
hw/virtio/virtio-pci.c +7 -0
+        error_setg(errp, "device cannot work when both modern and legacy modes"
+                   " are disabled");
+        error_append_hint(errp, "Set either disable-modern or disable-legacy"
+                          " to off\n");
+        return;
+    }
+
     if (!(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_PCIE) &&
         virtio_pci_modern(proxy)) {
         pci_dev->cap_present |= QEMU_PCI_CAP_EXPRESS;
#5 lore raw
Quoted 39 lines · On Fri, 22 Jul 2016 12:11:11 +0200 Greg Kurz <[email protected]> wrote:
Quoted 28 lines · On Fri, 22 Jul 2016 10:04:35 +0200 Cornelia Huck <[email protected]>…
Quoted 25 lines · On Thu, 21 Jul 2016 23:21:16 +0200 Greg Kurz <[email protected]> wrote:

From: Greg Kurz <[email protected]>

Without presuming if we got there because of a user mistake or some more subtle bug in the tooling, it really does not make sense to implement a non-functional device.

---
v4: - rephrased error message and provide a hint to the user
- split string literals to stay below 80 characters
- added Marcel's R-b tag

---
 hw/virtio/virtio-pci.c |    8 ++++++++
 1 file changed, 8 insertions(+)
hw/virtio/virtio-pci.c +0 -0
index 755f9218b77d..72c4b392ffda 100644
@@ -1842,6 +1842,14 @@ static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp)
     VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);
     PCIDevice *pci_dev = &proxy->pci_dev;
 
Quoted 7 lines

hw/virtio/virtio-pci.c static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp) · line 1845

Quoted 1 line
hw/virtio/virtio-pci.c +1 -0
+    if (!(virtio_pci_modern(proxy) || virtio_pci_legacy(proxy))) {  

I'm not sure that I didn't mess up the sequence of the realize callbacks, but could disable_legacy still be AUTO here? In that case, we'd fail for disable-modern=on and disable-legacy unset (i.e., AUTO), which would be ok for pcie but not for !pcie.

Quoted 6 lines

Marcel made the same comment in:

https://lists.gnu.org/archive/html/qemu-devel/2016-07/msg05225.html

If the user explicitly disables modern, she shouldn't rely on QEMU implicitly enabling legacy, hence the suggestion in error_append_hint().

I don't know, I'd find that a bit surprising, especially as I would end up with a legacy-capable device if I did not specify anything in the !pcie case.

Quoted 3 lines
Quoted 3 lines

hw/virtio/virtio-pci.c static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp) · line 1847

Quoted 3 lines
hw/virtio/virtio-pci.c +2 -0
+        error_setg(errp, "device cannot work when both modern and legacy modes"
+                   " are disabled");

Suggest to change this wording to:

"device cannot work as neither modern nor legacy mode is enabled"

as this more accurately reflects what happened (the user did not actively disable legacy in the case above).

Quoted 2 lines
Quoted 2 lines

hw/virtio/virtio-pci.c static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp) · line 1849

Quoted 2 lines
hw/virtio/virtio-pci.c +2 -0
+        error_append_hint(errp, "Set either disable-modern or disable-legacy"
+                          " to off\n");

The hint looks fine to me :)

Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
hw/virtio/virtio-pci.c +3 -0
+        return;
+    }
+
     if (!(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_PCIE) &&
         virtio_pci_modern(proxy)) {
         pci_dev->cap_present |= QEMU_PCI_CAP_EXPRESS;
author
#6 lore raw
Quoted 44 lines · On Fri, 22 Jul 2016 12:32:24 +0200 Cornelia Huck <[email protected]>…
Quoted 41 lines · On Fri, 22 Jul 2016 12:11:11 +0200 Greg Kurz <[email protected]> wrote:
Quoted 28 lines · On Fri, 22 Jul 2016 10:04:35 +0200 Cornelia Huck <[email protected]>…
Quoted 25 lines · On Thu, 21 Jul 2016 23:21:16 +0200 Greg Kurz <[email protected]> wrote:

From: Greg Kurz <[email protected]>

Without presuming if we got there because of a user mistake or some more subtle bug in the tooling, it really does not make sense to implement a non-functional device.

---
v4: - rephrased error message and provide a hint to the user
- split string literals to stay below 80 characters
- added Marcel's R-b tag

---
 hw/virtio/virtio-pci.c |    8 ++++++++
 1 file changed, 8 insertions(+)
hw/virtio/virtio-pci.c +0 -0
index 755f9218b77d..72c4b392ffda 100644
@@ -1842,6 +1842,14 @@ static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp)
     VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);
     PCIDevice *pci_dev = &proxy->pci_dev;
 
Quoted 7 lines

hw/virtio/virtio-pci.c static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp) · line 1845

Quoted 1 line
hw/virtio/virtio-pci.c +1 -0
+    if (!(virtio_pci_modern(proxy) || virtio_pci_legacy(proxy))) {    

I'm not sure that I didn't mess up the sequence of the realize callbacks, but could disable_legacy still be AUTO here? In that case, we'd fail for disable-modern=on and disable-legacy unset (i.e., AUTO), which would be ok for pcie but not for !pcie.

Marcel made the same comment in:

Quoted 9 lines
Quoted 4 lines

https://lists.gnu.org/archive/html/qemu-devel/2016-07/msg05225.html

If the user explicitly disables modern, she shouldn't rely on QEMU implicitly enabling legacy, hence the suggestion in error_append_hint().

I don't know, I'd find that a bit surprising, especially as I would end up with a legacy-capable device if I did not specify anything in the !pcie case.

Isn't it already what happens with legacy being the default in pre-2.7 QEMU ?

Do you think we should have separate checks for pcie and !pcie ?

Quoted 11 lines
Quoted 3 lines
Quoted 3 lines

hw/virtio/virtio-pci.c static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp) · line 1847

Quoted 3 lines
hw/virtio/virtio-pci.c +2 -0
+        error_setg(errp, "device cannot work when both modern and legacy modes"
+                   " are disabled");  

Suggest to change this wording to:

"device cannot work as neither modern nor legacy mode is enabled"

as this more accurately reflects what happened (the user did not actively disable legacy in the case above).

Thanks ! This is THE wording I was looking for :)

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

hw/virtio/virtio-pci.c static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp) · line 1849

Quoted 2 lines
hw/virtio/virtio-pci.c +2 -0
+        error_append_hint(errp, "Set either disable-modern or disable-legacy"
+                          " to off\n");  

The hint looks fine to me :)

It was the easy part :)

Quoted 11 lines
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
hw/virtio/virtio-pci.c +3 -0
+        return;
+    }
+
     if (!(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_PCIE) &&
         virtio_pci_modern(proxy)) {
         pci_dev->cap_present |= QEMU_PCI_CAP_EXPRESS;
Reviewed-by
#7 lore raw
Quoted 52 lines · On Fri, 22 Jul 2016 15:23:19 +0200 Greg Kurz <[email protected]> wrote:
Quoted 49 lines · On Fri, 22 Jul 2016 12:32:24 +0200 Cornelia Huck <[email protected]>…
Quoted 45 lines · On Fri, 22 Jul 2016 12:11:11 +0200 Greg Kurz <[email protected]> wrote:
Quoted 28 lines · On Fri, 22 Jul 2016 10:04:35 +0200 Cornelia Huck <[email protected]>…
Quoted 25 lines · On Thu, 21 Jul 2016 23:21:16 +0200 Greg Kurz <[email protected]> wrote:

From: Greg Kurz <[email protected]>

Without presuming if we got there because of a user mistake or some more subtle bug in the tooling, it really does not make sense to implement a non-functional device.

---
v4: - rephrased error message and provide a hint to the user
- split string literals to stay below 80 characters
- added Marcel's R-b tag

---
 hw/virtio/virtio-pci.c |    8 ++++++++
 1 file changed, 8 insertions(+)
hw/virtio/virtio-pci.c +0 -0
index 755f9218b77d..72c4b392ffda 100644
@@ -1842,6 +1842,14 @@ static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp)
     VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);
     PCIDevice *pci_dev = &proxy->pci_dev;
 
Quoted 7 lines

hw/virtio/virtio-pci.c static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp) · line 1845

Quoted 1 line
hw/virtio/virtio-pci.c +1 -0
+    if (!(virtio_pci_modern(proxy) || virtio_pci_legacy(proxy))) {    

I'm not sure that I didn't mess up the sequence of the realize callbacks, but could disable_legacy still be AUTO here? In that case, we'd fail for disable-modern=on and disable-legacy unset (i.e., AUTO), which would be ok for pcie but not for !pcie.

Marcel made the same comment in:

https://lists.gnu.org/archive/html/qemu-devel/2016-07/msg05225.html

If the user explicitly disables modern, she shouldn't rely on QEMU implicitly enabling legacy, hence the suggestion in error_append_hint().

Quoted 6 lines
Quoted 4 lines

I don't know, I'd find that a bit surprising, especially as I would end up with a legacy-capable device if I did not specify anything in the !pcie case.

Isn't it already what happens with legacy being the default in pre-2.7 QEMU ?

Well, that is exactly my point; users may be surprised.

Quoted 2 lines

Do you think we should have separate checks for pcie and !pcie ?

I don't think we should overengineer this.

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

hw/virtio/virtio-pci.c static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp) · line 1847

Quoted 4 lines
hw/virtio/virtio-pci.c +2 -0
+        error_setg(errp, "device cannot work when both modern and legacy modes"
+                   " are disabled");  

Suggest to change this wording to:

Quoted 7 lines
Quoted 5 lines

"device cannot work as neither modern nor legacy mode is enabled"

as this more accurately reflects what happened (the user did not actively disable legacy in the case above).

Thanks ! This is THE wording I was looking for :)

:)

I'm fine with the patch with the changed wording, as it less confusing for the user.

<I'll be offline next week so please just attach my

if the only thing you change is the message>

author
#8 lore raw
Quoted 44 lines · On Fri, 22 Jul 2016 15:42:48 +0200 Cornelia Huck <[email protected]>…

[...]

Quoted 43 lines
Quoted 43 lines
Quoted 42 lines
Quoted 28 lines
Quoted 25 lines · On Thu, 21 Jul 2016 23:21:16 +0200 Greg Kurz <[email protected]> wrote:

From: Greg Kurz <[email protected]>

Without presuming if we got there because of a user mistake or some more subtle bug in the tooling, it really does not make sense to implement a non-functional device.

---
v4: - rephrased error message and provide a hint to the user
- split string literals to stay below 80 characters
- added Marcel's R-b tag

---
 hw/virtio/virtio-pci.c |    8 ++++++++
 1 file changed, 8 insertions(+)
hw/virtio/virtio-pci.c +0 -0
index 755f9218b77d..72c4b392ffda 100644
@@ -1842,6 +1842,14 @@ static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp)
     VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);
     PCIDevice *pci_dev = &proxy->pci_dev;
 
Quoted 7 lines

hw/virtio/virtio-pci.c static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp) · line 1845

Quoted 1 line
hw/virtio/virtio-pci.c +1 -0
+    if (!(virtio_pci_modern(proxy) || virtio_pci_legacy(proxy))) {      

I'm not sure that I didn't mess up the sequence of the realize callbacks, but could disable_legacy still be AUTO here? In that case, we'd fail for disable-modern=on and disable-legacy unset (i.e., AUTO), which would be ok for pcie but not for !pcie.

Marcel made the same comment in:

https://lists.gnu.org/archive/html/qemu-devel/2016-07/msg05225.html

If the user explicitly disables modern, she shouldn't rely on QEMU implicitly enabling legacy, hence the suggestion in error_append_hint().

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

I don't know, I'd find that a bit surprising, especially as I would end up with a legacy-capable device if I did not specify anything in the !pcie case.

Isn't it already what happens with legacy being the default in pre-2.7 QEMU ?

Well, that is exactly my point; users may be surprised.

One day legacy will be hopefully buried :)

Quoted 5 lines
Quoted 2 lines

Do you think we should have separate checks for pcie and !pcie ?

I don't think we should overengineer this.

Agreed.

Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

hw/virtio/virtio-pci.c static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp) · line 1847

Quoted 4 lines
hw/virtio/virtio-pci.c +2 -0
+        error_setg(errp, "device cannot work when both modern and legacy modes"
+                   " are disabled");    

Suggest to change this wording to:

Quoted 7 lines
Quoted 5 lines

"device cannot work as neither modern nor legacy mode is enabled"

as this more accurately reflects what happened (the user did not actively disable legacy in the case above).

Thanks ! This is THE wording I was looking for :)

:)

Quoted 9 lines

I'm fine with the patch with the changed wording, as it less confusing for the user.

<I'll be offline next week so please just attach my

if the only thing you change is the message>

I'll do this right away as I'll be offline for 1 month starting... just after I post v5 :)

Cheers.

--
Greg