virtio: error report fixes in 9P and PCI
cover virtio: error report fixes in 9P and PCI
This series brings error reporting to virtio 9P in case a malformed element is returned by virtqueue_pop().
While here, I also re-post a patch for virtio PCI that fell through the cracks and missed the 2.7 merge window.
---
Greg Kurz (2):
virtio-9p: print error message and exit instead of BUG_ON()
virtio-pci: error out when both legacy and modern modes are disabled
hw/9pfs/virtio-9p-device.c | 20 ++++++++++++++++++-- hw/virtio/virtio-pci.c | 8 ++++++++ 2 files changed, 26 insertions(+), 2 deletions(-)
--
Greg
PATCH 1/2 virtio-9p: print error message and exit instead of BUG_ON()
Calling assert() really makes sense when hitting a genuine bug, which calls for a fix in QEMU. However, when something goes wrong because the guest sends a malformed message, it is better to write down a more meaningul error message and exit.
--- hw/9pfs/virtio-9p-device.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
hw/9pfs/virtio-9p-device.c +18 -2
@@ -19,6 +19,7 @@#include "coth.h" #include "hw/virtio/virtio-access.h" #include "qemu/iov.h" +#include "qemu/error-report.h" void virtio_9p_push_and_notify (V9fsPDU *pdu) {
@@ -35,6 +36,11 @@ void virtio_9p_push_and_notify(V9fsPDU *pdu)virtio_notify (VIRTIO_DEVICE (v), v->vq); } +static void virtio_9p_error (const char *msg) +{ +error_report ("The virtio-9p driver in the guest has an issue: %s" , msg); +} +static void handle_9p_output (VirtIODevice *vdev,VirtQueue *vq) {V9fsVirtioState *v = (V9fsVirtioState *)vdev;
@@ -56,13 +62,23 @@ static void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)break ; } -BUG_ON (elem->out_num ==0 || elem->in_num ==0 ); +if (elem->out_num ==0 ) { +virtio_9p_error ("missing VirtFS request's header" ); +exit (1 ); + } +if (elem->in_num ==0 ) { +virtio_9p_error ("missing VirtFS reply's header" ); +exit (1 ); + }QEMU_BUILD_BUG_ON (sizeof out !=7 ); v->elems[pdu->idx] = elem; len =iov_to_buf (elem->out_sg, elem->out_num,0 , &out,sizeof out); -BUG_ON (len !=sizeof out); +if (len !=sizeof out) { +virtio_9p_error ("malformed VirtFS request" ); +exit (1 ); + } pdu->size =le32_to_cpu (out.size_le);
Re: [Qemu-devel] [PATCH 1/2] virtio-9p: print error message and exit instead of BUG_ON()
Quoted 35 lines · Greg Kurz
Calling
assert()really makes sense when hitting a genuine bug, which calls for a fix in QEMU. However, when something goes wrong because the guest sends a malformed message, it is better to write down a more meaningul error message and exit.Signed-off-by Greg Kurz <[email protected]>--- hw/9pfs/virtio-9p-device.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)hw/9pfs/virtio-9p-device.c +6
-0@@ -19,6 +19,7 @@#include "coth.h" #include "hw/virtio/virtio-access.h" #include "qemu/iov.h" +#include "qemu/error-report.h" void virtio_9p_push_and_notify (V9fsPDU *pdu) {@@ -35,6 +36,11 @@ void virtio_9p_push_and_notify(V9fsPDU *pdu)virtio_notify (VIRTIO_DEVICE (v), v->vq); } +static void virtio_9p_error (const char *msg) +{ +error_report ("The virtio-9p driver in the guest has an issue: %s" , msg); +} +static void handle_9p_output (VirtIODevice *vdev,VirtQueue *vq) {V9fsVirtioState *v = (V9fsVirtioState *)vdev;
hw/9pfs/virtio-9p-device.c static void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq) · line 68
Quoted 8 lines
hw/9pfs/virtio-9p-device.c +4
-1@@ -56,13 +62,23 @@ static void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)break ; } -BUG_ON (elem->out_num ==0 || elem->in_num ==0 ); +if (elem->out_num ==0 ) { +virtio_9p_error ("missing VirtFS request's header" ); +exit (1 ); + }
Can the guest trigger this?
hw/9pfs/virtio-9p-device.c static void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq) · line 72
Quoted 4 lines
hw/9pfs/virtio-9p-device.c +4
-0+if (elem->in_num ==0 ) { +virtio_9p_error ("missing VirtFS reply's header" ); +exit (1 ); + }
Same question.
hw/9pfs/virtio-9p-device.c static void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq) · line 81
Quoted 10 lines
hw/9pfs/virtio-9p-device.c +4
-1QEMU_BUILD_BUG_ON (sizeof out !=7 ); v->elems[pdu->idx] = elem; len =iov_to_buf (elem->out_sg, elem->out_num,0 , &out,sizeof out); -BUG_ON (len !=sizeof out); +if (len !=sizeof out) { +virtio_9p_error ("malformed VirtFS request" ); +exit (1 ); + }
Same question.
Quoted 3 lines
hw/9pfs/virtio-9p-device.c +0
-0pdu->size =le32_to_cpu (out.size_le);
Re: [Qemu-devel] [PATCH 1/2] virtio-9p: print error message and exit instead of BUG_ON()
Quoted 40 lines · On Thu, 08 Sep 2016 09:14:05 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 38 lines · Greg Kurz
Calling
assert()really makes sense when hitting a genuine bug, which calls for a fix in QEMU. However, when something goes wrong because the guest sends a malformed message, it is better to write down a more meaningul error message and exit.Signed-off-by Greg Kurz <[email protected]>--- hw/9pfs/virtio-9p-device.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)hw/9pfs/virtio-9p-device.c +6
-0@@ -19,6 +19,7 @@#include "coth.h" #include "hw/virtio/virtio-access.h" #include "qemu/iov.h" +#include "qemu/error-report.h" void virtio_9p_push_and_notify (V9fsPDU *pdu) {@@ -35,6 +36,11 @@ void virtio_9p_push_and_notify(V9fsPDU *pdu)virtio_notify (VIRTIO_DEVICE (v), v->vq); } +static void virtio_9p_error (const char *msg) +{ +error_report ("The virtio-9p driver in the guest has an issue: %s" , msg); +} +static void handle_9p_output (VirtIODevice *vdev,VirtQueue *vq) {V9fsVirtioState *v = (V9fsVirtioState *)vdev;@@ -56,13 +62,23 @@ static void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)break ; }
Quoted 8 lines
hw/9pfs/virtio-9p-device.c static void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq) · line 68
Quoted 5 lines
hw/9pfs/virtio-9p-device.c +4
-1-BUG_ON (elem->out_num ==0 || elem->in_num ==0 ); +if (elem->out_num ==0 ) { +virtio_9p_error ("missing VirtFS request's header" ); +exit (1 ); + }Can the guest trigger this?
Yes it can in theory if it pushes an empty buffer... but this "recent" commit changed the outcome:
commit 1e7aed70144b4673fc26e73062064b6724795e5f
Author: Prasad J Pandit <[email protected]> Date: Wed Jul 27 21:07:56 2016 +0530
virtio: check vring descriptor buffer length
And now, the error is caught in virtqueue_map_desc():
if (!sz) {
error_report("virtio: zero sized buffers are not allowed");
exit(1);
}So I guess we should keep the BUG_ON() then.
BTW, there are similar checks in virtio-blk and virtio-net leading to a QEMU exit... which seem to be obsoleted by the above commit. I'll have a closer look.
Quoted 7 lines
hw/9pfs/virtio-9p-device.c static void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq) · line 72
Quoted 4 lines
hw/9pfs/virtio-9p-device.c +4
-0+if (elem->in_num ==0 ) { +virtio_9p_error ("missing VirtFS reply's header" ); +exit (1 ); + }Same question.
Same answer. :)
Quoted 11 lines
hw/9pfs/virtio-9p-device.c static void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq) · line 81
Quoted 10 lines
hw/9pfs/virtio-9p-device.c +4
-1QEMU_BUILD_BUG_ON (sizeof out !=7 ); v->elems[pdu->idx] = elem; len =iov_to_buf (elem->out_sg, elem->out_num,0 , &out,sizeof out); -BUG_ON (len !=sizeof out); +if (len !=sizeof out) { +virtio_9p_error ("malformed VirtFS request" ); +exit (1 ); + }
Quoted 2 lines
Same question.
Here this is different: the guest can put a bogus len in the vring_desc structure, and this doesn't get checked earlier.
Quoted 3 lines
hw/9pfs/virtio-9p-device.c static void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq) · line 84
Quoted 3 lines
hw/9pfs/virtio-9p-device.c +0
-0pdu->size =le32_to_cpu (out.size_le);
Cheers.
--
Greg
Re: [Qemu-devel] [PATCH 1/2] virtio-9p: print error message and exit instead of BUG_ON()
In reply to Greg KurzQuoted 9 lines · On Wed, 07 Sep 2016 19:19:24 +0200 Greg Kurz <[email protected]> wrote:
Calling
assert()really makes sense when hitting a genuine bug, which calls for a fix in QEMU. However, when something goes wrong because the guest sends a malformed message, it is better to write down a more meaningul error message and exit.Signed-off-by Greg Kurz <[email protected]>--- hw/9pfs/virtio-9p-device.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
While this is an improvement over the current state, I don't think the guest should be able to kill qemu just by doing something stupid.
The right way to go is to mark the virtio device as broken and stop doing any processing until the guest resets it. I think Stefan had a patch series doing that for some base virtio errors, but I'd have to search for it.
Re: [Qemu-devel] [PATCH 1/2] virtio-9p: print error message and exit instead of BUG_ON()
Quoted 8 lines · On Thu, 8 Sep 2016 10:59:26 +0200 Cornelia Huck <[email protected]>…
Quoted 5 lines · On Wed, 07 Sep 2016 19:19:24 +0200 Greg Kurz <[email protected]> wrote:
Calling
assert()really makes sense when hitting a genuine bug, which calls for a fix in QEMU. However, when something goes wrong because the guest sends a malformed message, it is better to write down a more meaningul error message and exit.
Quoted 8 lines
Quoted 4 lines
Signed-off-by Greg Kurz <[email protected]>--- hw/9pfs/virtio-9p-device.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)While this is an improvement over the current state, I don't think the guest should be able to kill qemu just by doing something stupid.
Hi Connie,
I'm glad you're pointing this out... this was also my impression, but since there are a bunch of sanity checks in the virtio code that cause QEMU to exit (even recently added like 1e7aed70144b), I did not dare stand up :)
Quoted 5 lines
The right way to go is to mark the virtio device as broken and stop doing any processing until the guest resets it. I think Stefan had a patch series doing that for some base virtio errors, but I'd have to search for it.
I'd be glad to have a look and try to address this issue.
Thanks !
--
Greg
Re: [Qemu-devel] [PATCH 1/2] virtio-9p: print error message and exit instead of BUG_ON()
Quoted 20 lines · Greg Kurz
Quoted 8 lines · On Thu, 8 Sep 2016 10:59:26 +0200 Cornelia Huck <[email protected]>…
Quoted 5 lines · On Wed, 07 Sep 2016 19:19:24 +0200 Greg Kurz <[email protected]> wrote:
Calling
assert()really makes sense when hitting a genuine bug, which calls for a fix in QEMU. However, when something goes wrong because the guest sends a malformed message, it is better to write down a more meaningul error message and exit.Quoted 8 lines
Quoted 4 lines
Signed-off-by Greg Kurz <[email protected]>--- hw/9pfs/virtio-9p-device.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)While this is an improvement over the current state, I don't think the guest should be able to kill qemu just by doing something stupid.
Quoted 6 lines
Hi Connie,
I'm glad you're pointing this out... this was also my impression, but since there are a bunch of sanity checks in the virtio code that cause QEMU to exit (even recently added like
1e7aed70144b), I did not dare stand up :)
It's true that it's broken in many places but we should just fix them all.
A separate question is how to log such hardware/guest bugs generally. People already complained about disk filling up because of us printing errors on each such bug. Maybe print each message only N times, and then set a flag to skip the log until management tells us to restart logging again.
Quoted 12 lines
Quoted 5 lines
The right way to go is to mark the virtio device as broken and stop doing any processing until the guest resets it. I think Stefan had a patch series doing that for some base virtio errors, but I'd have to search for it.
I'd be glad to have a look and try to address this issue.
Thanks !
--
Greg
Re: [Qemu-devel] [PATCH 1/2] virtio-9p: print error message and exit instead of BUG_ON()
Quoted 32 lines · On Thu, 8 Sep 2016 18:00:28 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 20 lines · Greg Kurz
Quoted 8 lines · On Thu, 8 Sep 2016 10:59:26 +0200 Cornelia Huck <[email protected]>…
Quoted 5 lines · On Wed, 07 Sep 2016 19:19:24 +0200 Greg Kurz <[email protected]> wrote:
Calling
assert()really makes sense when hitting a genuine bug, which calls for a fix in QEMU. However, when something goes wrong because the guest sends a malformed message, it is better to write down a more meaningul error message and exit.Quoted 8 lines
Quoted 4 lines
Signed-off-by Greg Kurz <[email protected]>--- hw/9pfs/virtio-9p-device.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)While this is an improvement over the current state, I don't think the guest should be able to kill qemu just by doing something stupid.
Quoted 6 lines
Hi Connie,
I'm glad you're pointing this out... this was also my impression, but since there are a bunch of sanity checks in the virtio code that cause QEMU to exit (even recently added like
1e7aed70144b), I did not dare stand up :)It's true that it's broken in many places but we should just fix them all.
Quoted 5 lines
A separate question is how to log such hardware/guest bugs generally. People already complained about disk filling up because of us printing errors on each such bug. Maybe print each message only N times, and then set a flag to skip the log until management tells us to restart logging again.
I'd expect to get the message just once per device if we set the device to broken (unless the guess continuously resets it again...) Do we have a generic print/log ratelimit infrastructure in qemu?
Re: [Qemu-devel] [PATCH 1/2] virtio-9p: print error message and exit instead of BUG_ON()
Quoted 35 lines · Cornelia Huck
Quoted 32 lines · On Thu, 8 Sep 2016 18:00:28 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 20 lines · Greg Kurz
Quoted 8 lines · On Thu, 8 Sep 2016 10:59:26 +0200 Cornelia Huck <[email protected]>…
Quoted 5 lines · On Wed, 07 Sep 2016 19:19:24 +0200 Greg Kurz <[email protected]> wrote:
Calling
assert()really makes sense when hitting a genuine bug, which calls for a fix in QEMU. However, when something goes wrong because the guest sends a malformed message, it is better to write down a more meaningul error message and exit.Quoted 8 lines
Quoted 4 lines
Signed-off-by Greg Kurz <[email protected]>--- hw/9pfs/virtio-9p-device.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)While this is an improvement over the current state, I don't think the guest should be able to kill qemu just by doing something stupid.
Quoted 6 lines
Hi Connie,
I'm glad you're pointing this out... this was also my impression, but since there are a bunch of sanity checks in the virtio code that cause QEMU to exit (even recently added like
1e7aed70144b), I did not dare stand up :)It's true that it's broken in many places but we should just fix them all.
Quoted 8 lines
Quoted 5 lines
A separate question is how to log such hardware/guest bugs generally. People already complained about disk filling up because of us printing errors on each such bug. Maybe print each message only N times, and then set a flag to skip the log until management tells us to restart logging again.
I'd expect to get the message just once per device if we set the device to broken (unless the guess continuously resets it again...)
Which it can do, so we should limit that anyway.
Quoted 2 lines
Do we have
a generic print/log ratelimit infrastructure in qemu?
There are actually two kinds of errors host side ones and ones triggered by guests.
We should distinguish between them API-wise, then we will be able to limit the logging of those that guest can trigger.
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH 1/2] virtio-9p: print error message and exit instead of BUG_ON()
Quoted 50 lines · On Thu, 8 Sep 2016 18:19:27 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 35 lines · Cornelia Huck
Quoted 32 lines · On Thu, 8 Sep 2016 18:00:28 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 20 lines · Greg Kurz
Quoted 8 lines · On Thu, 8 Sep 2016 10:59:26 +0200 Cornelia Huck <[email protected]>…
Quoted 5 lines · On Wed, 07 Sep 2016 19:19:24 +0200 Greg Kurz <[email protected]> wrote:
Calling
assert()really makes sense when hitting a genuine bug, which calls for a fix in QEMU. However, when something goes wrong because the guest sends a malformed message, it is better to write down a more meaningul error message and exit.Quoted 8 lines
Quoted 4 lines
Signed-off-by Greg Kurz <[email protected]>--- hw/9pfs/virtio-9p-device.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)While this is an improvement over the current state, I don't think the guest should be able to kill qemu just by doing something stupid.
Quoted 6 lines
Hi Connie,
I'm glad you're pointing this out... this was also my impression, but since there are a bunch of sanity checks in the virtio code that cause QEMU to exit (even recently added like
1e7aed70144b), I did not dare stand up :)It's true that it's broken in many places but we should just fix them all.
Quoted 8 lines
Quoted 5 lines
A separate question is how to log such hardware/guest bugs generally. People already complained about disk filling up because of us printing errors on each such bug. Maybe print each message only N times, and then set a flag to skip the log until management tells us to restart logging again.
I'd expect to get the message just once per device if we set the device to broken (unless the guess continuously resets it again...)
Which it can do, so we should limit that anyway.
Quoted 2 lines
Do we have
a generic print/log ratelimit infrastructure in qemu?
Quoted 7 lines
There are actually two kinds of errors host side ones and ones triggered by guests.
We should distinguish between them API-wise, then we will be able to limit the logging of those that guest can trigger.
FWIW it makes sense to use error_report() if QEMU exits. If it continues execution, this means we're expecting the guest or the host to do something to fix the error condition. This requires QEMU to emit an event of some sort, but not necessarily to log an error message in a file. I guess this depends if QEMU is run by some tooling, or by a human.
Re: [Qemu-devel] [PATCH 1/2] virtio-9p: print error message and exit instead of BUG_ON()
Quoted 56 lines · Greg Kurz
Quoted 53 lines · On Thu, 8 Sep 2016 18:19:27 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 35 lines · Cornelia Huck
Quoted 32 lines · On Thu, 8 Sep 2016 18:00:28 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 20 lines · Greg Kurz
Quoted 8 lines · On Thu, 8 Sep 2016 10:59:26 +0200 Cornelia Huck <[email protected]>…
Quoted 5 lines · On Wed, 07 Sep 2016 19:19:24 +0200 Greg Kurz <[email protected]> wrote:
Calling
assert()really makes sense when hitting a genuine bug, which calls for a fix in QEMU. However, when something goes wrong because the guest sends a malformed message, it is better to write down a more meaningul error message and exit.Quoted 8 lines
Quoted 4 lines
Signed-off-by Greg Kurz <[email protected]>--- hw/9pfs/virtio-9p-device.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)While this is an improvement over the current state, I don't think the guest should be able to kill qemu just by doing something stupid.
Quoted 6 lines
Hi Connie,
I'm glad you're pointing this out... this was also my impression, but since there are a bunch of sanity checks in the virtio code that cause QEMU to exit (even recently added like
1e7aed70144b), I did not dare stand up :)It's true that it's broken in many places but we should just fix them all.
Quoted 8 lines
Quoted 5 lines
A separate question is how to log such hardware/guest bugs generally. People already complained about disk filling up because of us printing errors on each such bug. Maybe print each message only N times, and then set a flag to skip the log until management tells us to restart logging again.
I'd expect to get the message just once per device if we set the device to broken (unless the guess continuously resets it again...)
Which it can do, so we should limit that anyway.
Quoted 2 lines
Do we have
a generic print/log ratelimit infrastructure in qemu?There are actually two kinds of errors host side ones and ones triggered by guests.
Quoted 6 lines
Quoted 4 lines
We should distinguish between them API-wise, then we will be able to limit the logging of those that guest can trigger.
FWIW it makes sense to use
error_report()if QEMU exits.
Not necessarily e.g. hotplug errors trigger error_report too. Generally it should be for host misconfiguration or similar management errors.
Quoted 5 lines
If it continues
execution, this means we're expecting the guest or the host to do something to fix the error condition. This requires QEMU to emit an event of some sort, but not necessarily to log an error message in a file. I guess this depends if QEMU is run by some tooling, or by a human.
I'm not sure we need an event if tools are not expected to do anything with it. If we limit # of times error is printed, tools will need to reset this counter, so we will need an event on overflow.
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH 1/2] virtio-9p: print error message and exit instead of BUG_ON()
Quoted 16 lines · On Thu, 8 Sep 2016 19:55:16 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 7 lines · Greg Kurz
Quoted 4 lines · On Thu, 8 Sep 2016 18:19:27 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 3 lines · Cornelia Huck
On Thu, 8 Sep 2016 18:00:28 +0300
"Michael S. Tsirkin" <[email protected]> wrote:Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · Greg Kurz
If it continues
execution, this means we're expecting the guest or the host to do something to fix the error condition. This requires QEMU to emit an event of some sort, but not necessarily to log an error message in a file. I guess this depends if QEMU is run by some tooling, or by a human.
Quoted 4 lines
I'm not sure we need an event if tools are not expected to do anything with it. If we limit # of times error is printed, tools will need to reset this counter, so we will need an event on overflow.
If the device goes into a broken state, it should be discoverable from outside. I'm not sure we need an actual event signalling this if this happens due to the guest doing something wrong: That would be a task for tools monitoring _inside_ the guest. For tools monitoring the health of the machine (from the host perspective), the discovery interface would probably be enough?
Re: [Qemu-devel] [PATCH 1/2] virtio-9p: print error message and exit instead of BUG_ON()
Quoted 24 lines · On Fri, 9 Sep 2016 10:30:53 +0200 Cornelia Huck <[email protected]>…
Quoted 16 lines · On Thu, 8 Sep 2016 19:55:16 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 7 lines · Greg Kurz
Quoted 4 lines · On Thu, 8 Sep 2016 18:19:27 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 3 lines · Cornelia Huck
On Thu, 8 Sep 2016 18:00:28 +0300
"Michael S. Tsirkin" <[email protected]> wrote:Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · Greg Kurz
If it continues
execution, this means we're expecting the guest or the host to do something to fix the error condition. This requires QEMU to emit an event of some sort, but not necessarily to log an error message in a file. I guess this depends if QEMU is run by some tooling, or by a human.Quoted 4 lines
I'm not sure we need an event if tools are not expected to do anything with it. If we limit # of times error is printed, tools will need to reset this counter, so we will need an event on overflow.
Quoted 4 lines
If the device goes into a broken state, it should be discoverable from outside. I'm not sure we need an actual event signalling this if this happens due to the guest doing something wrong: That would be a task for tools monitoring _inside_ the guest.
Well, in case of a virtio device being broken, section 2.1.2 in the spec suggests to set the status to DEVICE_NEEDS_RESET and to notify it to the guest (aka. event signalling). I'll send a patch shortly.
Quoted 4 lines
For tools monitoring the
health of the machine (from the host perspective), the discovery interface would probably be enough?
Yeah, probably.
Cheers.
--
Greg
Re: [Qemu-devel] [PATCH 1/2] virtio-9p: print error message and exit instead of BUG_ON()
Quoted 27 lines · On Fri, 9 Sep 2016 10:46:25 +0200 Greg Kurz <[email protected]> wrote:
Quoted 24 lines · On Fri, 9 Sep 2016 10:30:53 +0200 Cornelia Huck <[email protected]>…
Quoted 20 lines · On Thu, 8 Sep 2016 19:55:16 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 7 lines · Greg Kurz
Quoted 4 lines · On Thu, 8 Sep 2016 18:19:27 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 3 lines · Cornelia Huck
On Thu, 8 Sep 2016 18:00:28 +0300
"Michael S. Tsirkin" <[email protected]> wrote:Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · Greg Kurz
If it continues
execution, this means we're expecting the guest or the host to do something to fix the error condition. This requires QEMU to emit an event of some sort, but not necessarily to log an error message in a file. I guess this depends if QEMU is run by some tooling, or by a human.I'm not sure we need an event if tools are not expected to do anything with it. If we limit # of times error is printed, tools will need to reset this counter, so we will need an event on overflow.
Quoted 8 lines
Quoted 4 lines
If the device goes into a broken state, it should be discoverable from outside. I'm not sure we need an actual event signalling this if this happens due to the guest doing something wrong: That would be a task for tools monitoring _inside_ the guest.
Well, in case of a virtio device being broken, section 2.1.2 in the spec suggests to set the status to
DEVICE_NEEDS_RESETand to notify it to the guest (aka. event signalling). I'll send a patch shortly.
Stefan had already sent <[email protected]> ages ago, but it has not yet made it anywhere...
Anyhow, I was concerned with host signalling (sorry for being unclear), and I still do not think we need to alert host monitoring software to guest stupidity.
Quoted 13 lines
Quoted 5 lines
For tools monitoring the
health of the machine (from the host perspective), the discovery interface would probably be enough?Yeah, probably.
Cheers.
--
Greg
Re: [Qemu-devel] [PATCH 1/2] virtio-9p: print error message and exit instead of BUG_ON()
Quoted 35 lines · On Fri, 9 Sep 2016 10:53:05 +0200 Cornelia Huck <[email protected]>…
Quoted 32 lines · On Fri, 9 Sep 2016 10:46:25 +0200 Greg Kurz <[email protected]> wrote:
Quoted 28 lines · On Fri, 9 Sep 2016 10:30:53 +0200 Cornelia Huck <[email protected]>…
Quoted 16 lines · On Thu, 8 Sep 2016 19:55:16 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 7 lines · Greg Kurz
Quoted 4 lines · On Thu, 8 Sep 2016 18:19:27 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 3 lines · Cornelia Huck
On Thu, 8 Sep 2016 18:00:28 +0300
"Michael S. Tsirkin" <[email protected]> wrote:Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · Greg Kurz
If it continues
execution, this means we're expecting the guest or the host to do something to fix the error condition. This requires QEMU to emit an event of some sort, but not necessarily to log an error message in a file. I guess this depends if QEMU is run by some tooling, or by a human.Quoted 4 lines
I'm not sure we need an event if tools are not expected to do anything with it. If we limit # of times error is printed, tools will need to reset this counter, so we will need an event on overflow.
If the device goes into a broken state, it should be discoverable from outside. I'm not sure we need an actual event signalling this if this happens due to the guest doing something wrong: That would be a task for tools monitoring _inside_ the guest.
Quoted 8 lines
Quoted 3 lines
Well, in case of a virtio device being broken, section 2.1.2 in the spec suggests to set the status to
DEVICE_NEEDS_RESETand to notify it to the guest (aka. event signalling). I'll send a patch shortly.Stefan had already sent <[email protected]> ages ago, but it has not yet made it anywhere...
I don't know what to do with this message-id :\
Quoted 4 lines
Anyhow, I was concerned with host signalling (sorry for being unclear), and I still do not think we need to alert host monitoring software to guest stupidity.
I agree. Sorry if my poor wording made you (and others) think I was suggesting that :) My point was that if QEMU exits because of guest stupidity, you are forced to error_report() something to the host, but this is really suboptimal (even if BUG_ON is worse)... then there was that discussion about log files getting to big, but I don't even know how we came there, as it does not really make sense when QEMU exits.
Quoted 14 lines
Quoted 13 lines
Quoted 5 lines
For tools monitoring the
health of the machine (from the host perspective), the discovery interface would probably be enough?Yeah, probably.
Cheers.
--
Greg
Re: [Qemu-devel] [PATCH 1/2] virtio-9p: print error message and exit instead of BUG_ON()
Quoted 7 lines · On Fri, 9 Sep 2016 11:26:17 +0200 Greg Kurz <[email protected]> wrote:
Quoted 5 lines
Stefan had already sent <[email protected]> ages ago, but it has not yet made it anywhere...
I don't know what to do with this message-id :\
I finally found :)
+message-id:<[email protected]> in the search box at https://lists.nongnu.org/archive/html/qemu-devel/
Cheers.
--
Greg
Re: [Qemu-devel] [PATCH 1/2] virtio-9p: print error message and exit instead of BUG_ON()
In reply to Greg KurzQuoted 56 lines · Greg Kurz
Quoted 53 lines · On Thu, 8 Sep 2016 18:19:27 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 35 lines · Cornelia Huck
Quoted 32 lines · On Thu, 8 Sep 2016 18:00:28 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 20 lines · Greg Kurz
Quoted 8 lines · On Thu, 8 Sep 2016 10:59:26 +0200 Cornelia Huck <[email protected]>…
Quoted 5 lines · On Wed, 07 Sep 2016 19:19:24 +0200 Greg Kurz <[email protected]> wrote:
Calling
assert()really makes sense when hitting a genuine bug, which calls for a fix in QEMU. However, when something goes wrong because the guest sends a malformed message, it is better to write down a more meaningul error message and exit.Quoted 8 lines
Quoted 4 lines
Signed-off-by Greg Kurz <[email protected]>--- hw/9pfs/virtio-9p-device.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)While this is an improvement over the current state, I don't think the guest should be able to kill qemu just by doing something stupid.
Quoted 6 lines
Hi Connie,
I'm glad you're pointing this out... this was also my impression, but since there are a bunch of sanity checks in the virtio code that cause QEMU to exit (even recently added like
1e7aed70144b), I did not dare stand up :)It's true that it's broken in many places but we should just fix them all.
Quoted 8 lines
Quoted 5 lines
A separate question is how to log such hardware/guest bugs generally. People already complained about disk filling up because of us printing errors on each such bug. Maybe print each message only N times, and then set a flag to skip the log until management tells us to restart logging again.
I'd expect to get the message just once per device if we set the device to broken (unless the guess continuously resets it again...)
Which it can do, so we should limit that anyway.
Quoted 2 lines
Do we have
a generic print/log ratelimit infrastructure in qemu?There are actually two kinds of errors host side ones and ones triggered by guests.
Quoted 6 lines
Quoted 4 lines
We should distinguish between them API-wise, then we will be able to limit the logging of those that guest can trigger.
FWIW it makes sense to use
error_report()if QEMU exits.
exit(STATUS) with STATUS != 0 without printing a message is always wrong.
Quoted 5 lines
If it continues
execution, this means we're expecting the guest or the host to do something to fix the error condition. This requires QEMU to emit an event of some sort, but not necessarily to log an error message in a file. I guess this depends if QEMU is run by some tooling, or by a human.
error_report() normally goes to stderr. Tooling or humans can of course make it go to a file instead.
error_report() is indeed a sub-par way to send an "attention" signal to the host, because recognizing such a signal reliably is unnecessary hard for management applications. QMP events are much easier.
Both are useless when the signal needs to go to the guest. Signalling the guest is a device model job.
error_report() without exit() has its uses. Error conditions in need of fixing aren't the only reason to call error_report(). But when you add a call, ask yourself whether management application or guest would like to respond to it.
Re: [Qemu-devel] [PATCH 1/2] virtio-9p: print error message and exit instead of BUG_ON()
Quoted 63 lines · On Fri, 09 Sep 2016 08:38:13 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 61 lines · Greg Kurz
Quoted 57 lines · On Thu, 8 Sep 2016 18:19:27 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 35 lines · Cornelia Huck
Quoted 32 lines · On Thu, 8 Sep 2016 18:00:28 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 20 lines · Greg Kurz
Quoted 8 lines · On Thu, 8 Sep 2016 10:59:26 +0200 Cornelia Huck <[email protected]>…
Quoted 5 lines · On Wed, 07 Sep 2016 19:19:24 +0200 Greg Kurz <[email protected]> wrote:
Calling
assert()really makes sense when hitting a genuine bug, which calls for a fix in QEMU. However, when something goes wrong because the guest sends a malformed message, it is better to write down a more meaningul error message and exit.Quoted 8 lines
Quoted 4 lines
Signed-off-by Greg Kurz <[email protected]>--- hw/9pfs/virtio-9p-device.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)While this is an improvement over the current state, I don't think the guest should be able to kill qemu just by doing something stupid.
Quoted 6 lines
Hi Connie,
I'm glad you're pointing this out... this was also my impression, but since there are a bunch of sanity checks in the virtio code that cause QEMU to exit (even recently added like
1e7aed70144b), I did not dare stand up :)It's true that it's broken in many places but we should just fix them all.
Quoted 8 lines
Quoted 5 lines
A separate question is how to log such hardware/guest bugs generally. People already complained about disk filling up because of us printing errors on each such bug. Maybe print each message only N times, and then set a flag to skip the log until management tells us to restart logging again.
I'd expect to get the message just once per device if we set the device to broken (unless the guess continuously resets it again...)
Which it can do, so we should limit that anyway.
Quoted 2 lines
Do we have
a generic print/log ratelimit infrastructure in qemu?There are actually two kinds of errors host side ones and ones triggered by guests.
We should distinguish between them API-wise, then we will be able to limit the logging of those that guest can trigger.
Quoted 5 lines
Quoted 1 line
FWIW it makes sense to use
error_report()if QEMU exits.exit(STATUS) with STATUS != 0 without printing a message is always wrong.
I fully agree.
Quoted 6 lines
Quoted 5 lines
If it continues
execution, this means we're expecting the guest or the host to do something to fix the error condition. This requires QEMU to emit an event of some sort, but not necessarily to log an error message in a file. I guess this depends if QEMU is run by some tooling, or by a human.
Quoted 7 lines
error_report()normally goes to stderr. Tooling or humans can of course make it go to a file instead.
error_report()is indeed a sub-par way to send an "attention" signal to the host, because recognizing such a signal reliably is unnecessary hard for management applications. QMP events are much easier.
My wording was poor but yes, that was my point. :)
Quoted 3 lines
Both are useless when the signal needs to go to the guest. Signalling the guest is a device model job.
I also agree with that. In the case of virtio, this is explained in section 2.1.2 of the spec.
Quoted 4 lines
error_report()withoutexit()has its uses. Error conditions in need of fixing aren't the only reason to callerror_report(). But when you add a call, ask yourself whether management application or guest would like to respond to it.
In the case of the present patch, we currently have BUG_ON() which generates a cryptic and unusable message.
It turns out that the first one (elem->out_num == 0 || elem->in_num == 0) is correct since it is now [1] impossible to hit this according to the code (see virtqueue_pop() and virtqueue_map_desc()).
The second one (len != sizeof out) though matches a potential guest originated error. If I do as suggested by Connie, then the error_report() isn't needed anymore.
Cheers.
--
Greg
[1] sending an empty buffer was sufficient before commit 1e7aed70144b4 as said in my previous answer
Re: [Qemu-devel] [PATCH 1/2] virtio-9p: print error message and exit instead of BUG_ON()
Quoted 105 lines · Greg Kurz
Quoted 63 lines · On Fri, 09 Sep 2016 08:38:13 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 61 lines · Greg Kurz
Quoted 57 lines · On Thu, 8 Sep 2016 18:19:27 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 35 lines · Cornelia Huck
Quoted 32 lines · On Thu, 8 Sep 2016 18:00:28 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 20 lines · Greg Kurz
Quoted 8 lines · On Thu, 8 Sep 2016 10:59:26 +0200 Cornelia Huck <[email protected]>…
Quoted 5 lines · On Wed, 07 Sep 2016 19:19:24 +0200 Greg Kurz <[email protected]> wrote:
Calling
assert()really makes sense when hitting a genuine bug, which calls for a fix in QEMU. However, when something goes wrong because the guest sends a malformed message, it is better to write down a more meaningul error message and exit.Quoted 8 lines
Quoted 4 lines
Signed-off-by Greg Kurz <[email protected]>--- hw/9pfs/virtio-9p-device.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)While this is an improvement over the current state, I don't think the guest should be able to kill qemu just by doing something stupid.
Quoted 6 lines
Hi Connie,
I'm glad you're pointing this out... this was also my impression, but since there are a bunch of sanity checks in the virtio code that cause QEMU to exit (even recently added like
1e7aed70144b), I did not dare stand up :)It's true that it's broken in many places but we should just fix them all.
Quoted 8 lines
Quoted 5 lines
A separate question is how to log such hardware/guest bugs generally. People already complained about disk filling up because of us printing errors on each such bug. Maybe print each message only N times, and then set a flag to skip the log until management tells us to restart logging again.
I'd expect to get the message just once per device if we set the device to broken (unless the guess continuously resets it again...)
Which it can do, so we should limit that anyway.
Quoted 2 lines
Do we have
a generic print/log ratelimit infrastructure in qemu?There are actually two kinds of errors host side ones and ones triggered by guests.
We should distinguish between them API-wise, then we will be able to limit the logging of those that guest can trigger.
Quoted 5 lines
Quoted 1 line
FWIW it makes sense to use
error_report()if QEMU exits.exit(STATUS) with STATUS != 0 without printing a message is always wrong.
I fully agree.
Quoted 6 lines
Quoted 5 lines
If it continues
execution, this means we're expecting the guest or the host to do something to fix the error condition. This requires QEMU to emit an event of some sort, but not necessarily to log an error message in a file. I guess this depends if QEMU is run by some tooling, or by a human.Quoted 7 lines
error_report()normally goes to stderr. Tooling or humans can of course make it go to a file instead.
error_report()is indeed a sub-par way to send an "attention" signal to the host, because recognizing such a signal reliably is unnecessary hard for management applications. QMP events are much easier.My wording was poor but yes, that was my point. :)
Quoted 3 lines
Both are useless when the signal needs to go to the guest. Signalling the guest is a device model job.
I also agree with that. In the case of virtio, this is explained in section 2.1.2 of the spec.
Quoted 4 lines
error_report()withoutexit()has its uses. Error conditions in need of fixing aren't the only reason to callerror_report(). But when you add a call, ask yourself whether management application or guest would like to respond to it.In the case of the present patch, we currently have
BUG_ON()which generates a cryptic and unusable message.
Quoted 7 lines
It turns out that the first one (
elem->out_num== 0 ||elem->in_num== 0) is correct since it is now [1] impossible to hit this according to the code (seevirtqueue_pop()andvirtqueue_map_desc()).The second one (len != sizeof out) though matches a potential guest originated error. If I do as suggested by Connie, then the
error_report()isn't needed anymore.
I dive into the details of your analysis right now, only make high-level recommendations:
* Issues common to all virtio devices should be addressed in the virtio core. If that's not feasible, they should be addressed in all devices consistently.
* Guest misbehavior should put the device in a guest-observable error state. It should not crash QEMU, it should not spam stderr. Code handling it in other ways should be marked FIXME.
* Nobody expects you to get things perfectly right in one step. Just try to move towards the goal.
Quoted 8 lines
Cheers.
--
Greg[1] sending an empty buffer was sufficient before commit
1e7aed70144b4as said in my previous answer
Re: [Qemu-devel] [PATCH 1/2] virtio-9p: print error message and exit instead of BUG_ON()
Quoted 115 lines · On Fri, 09 Sep 2016 11:08:56 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 105 lines · Greg Kurz
Quoted 63 lines · On Fri, 09 Sep 2016 08:38:13 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 61 lines · Greg Kurz
Quoted 57 lines · On Thu, 8 Sep 2016 18:19:27 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 35 lines · Cornelia Huck
Quoted 32 lines · On Thu, 8 Sep 2016 18:00:28 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 20 lines · Greg Kurz
Quoted 8 lines · On Thu, 8 Sep 2016 10:59:26 +0200 Cornelia Huck <[email protected]>…
Quoted 5 lines · On Wed, 07 Sep 2016 19:19:24 +0200 Greg Kurz <[email protected]> wrote:
Calling
assert()really makes sense when hitting a genuine bug, which calls for a fix in QEMU. However, when something goes wrong because the guest sends a malformed message, it is better to write down a more meaningul error message and exit.Quoted 8 lines
Quoted 4 lines
Signed-off-by Greg Kurz <[email protected]>--- hw/9pfs/virtio-9p-device.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)While this is an improvement over the current state, I don't think the guest should be able to kill qemu just by doing something stupid.
Quoted 6 lines
Hi Connie,
I'm glad you're pointing this out... this was also my impression, but since there are a bunch of sanity checks in the virtio code that cause QEMU to exit (even recently added like
1e7aed70144b), I did not dare stand up :)It's true that it's broken in many places but we should just fix them all.
Quoted 8 lines
Quoted 5 lines
A separate question is how to log such hardware/guest bugs generally. People already complained about disk filling up because of us printing errors on each such bug. Maybe print each message only N times, and then set a flag to skip the log until management tells us to restart logging again.
I'd expect to get the message just once per device if we set the device to broken (unless the guess continuously resets it again...)
Which it can do, so we should limit that anyway.
Quoted 2 lines
Do we have
a generic print/log ratelimit infrastructure in qemu?There are actually two kinds of errors host side ones and ones triggered by guests.
We should distinguish between them API-wise, then we will be able to limit the logging of those that guest can trigger.
Quoted 5 lines
Quoted 1 line
FWIW it makes sense to use
error_report()if QEMU exits.exit(STATUS) with STATUS != 0 without printing a message is always wrong.
I fully agree.
Quoted 6 lines
Quoted 5 lines
If it continues
execution, this means we're expecting the guest or the host to do something to fix the error condition. This requires QEMU to emit an event of some sort, but not necessarily to log an error message in a file. I guess this depends if QEMU is run by some tooling, or by a human.Quoted 7 lines
error_report()normally goes to stderr. Tooling or humans can of course make it go to a file instead.
error_report()is indeed a sub-par way to send an "attention" signal to the host, because recognizing such a signal reliably is unnecessary hard for management applications. QMP events are much easier.My wording was poor but yes, that was my point. :)
Quoted 3 lines
Both are useless when the signal needs to go to the guest. Signalling the guest is a device model job.
I also agree with that. In the case of virtio, this is explained in section 2.1.2 of the spec.
Quoted 4 lines
error_report()withoutexit()has its uses. Error conditions in need of fixing aren't the only reason to callerror_report(). But when you add a call, ask yourself whether management application or guest would like to respond to it.In the case of the present patch, we currently have
BUG_ON()which generates a cryptic and unusable message.Quoted 7 lines
It turns out that the first one (
elem->out_num== 0 ||elem->in_num== 0) is correct since it is now [1] impossible to hit this according to the code (seevirtqueue_pop()andvirtqueue_map_desc()).The second one (len != sizeof out) though matches a potential guest originated error. If I do as suggested by Connie, then the
error_report()isn't needed anymore.
Quoted 7 lines
I dive into the details of your analysis right now, only make high-level recommendations:
* Issues common to all virtio devices should be addressed in the virtio core. If that's not feasible, they should be addressed in all devices consistently.
Agreed.
Quoted 4 lines
* Guest misbehavior should put the device in a guest-observable error state. It should not crash QEMU, it should not spam stderr. Code handling it in other ways should be marked FIXME.
Agreed. FWIW a bunch of FIXMEs are missing in the virtio code then :)
Quoted 3 lines
* Nobody expects you to get things perfectly right in one step. Just try to move towards the goal.
Sure ! I'm now reading through Stefan's series to address the issue:
https://lists.nongnu.org/archive/html/qemu-devel/2016-04/msg01978.html
Cheers.
--
Greg
Quoted 8 lines
Quoted 8 lines
Cheers.
--
Greg[1] sending an empty buffer was sufficient before commit
1e7aed70144b4as said in my previous answer
PATCH 2/2 virtio-pci: error out when both legacy and modern modes are disabled
In reply to Greg KurzFrom: 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.
--- hw/virtio/virtio-pci.c | 8 ++++++++ 1 file changed, 8 insertions(+)
hw/virtio/virtio-pci.c +8 -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))) { +error_setg (errp,"device cannot work as neither modern nor legacy mode" +" is enabled" ); +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 ;
Re: [Qemu-devel] [PATCH 2/2] virtio-pci: error out when both legacy and modern modes are disabled
Quoted 23 lines · Greg Kurz
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.
Signed-off-by Greg Kurz <[email protected]>Reviewed-by Marcel Apfelbaum <[email protected]>Reviewed-by Cornelia Huck <[email protected]>Signed-off-by Greg Kurz <[email protected]>--- hw/virtio/virtio-pci.c | 8 ++++++++ 1 file changed, 8 insertions(+)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))) {
hw/virtio/virtio-pci.c static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp) · line 1855
Quoted 10 lines
hw/virtio/virtio-pci.c +7
-0+error_setg (errp,"device cannot work as neither modern nor legacy mode" +" is enabled" ); +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 ;
Pardon my ignorance... is this a device-specific restriction, or is it the same for more (all?) virtio devices?
Re: [Qemu-devel] [PATCH 2/2] virtio-pci: error out when both legacy and modern modes are disabled
Quoted 24 lines · On Thu, 08 Sep 2016 09:15:28 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 22 lines · Greg Kurz
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.
Signed-off-by Greg Kurz <[email protected]>Reviewed-by Marcel Apfelbaum <[email protected]>Reviewed-by Cornelia Huck <[email protected]>Signed-off-by Greg Kurz <[email protected]>--- hw/virtio/virtio-pci.c | 8 ++++++++ 1 file changed, 8 insertions(+)hw/virtio/virtio-pci.c +0
-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;
Quoted 14 lines
hw/virtio/virtio-pci.c static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp) · line 1855
Quoted 11 lines
hw/virtio/virtio-pci.c +8
-0+if (!(virtio_pci_modern (proxy) ||virtio_pci_legacy (proxy))) { +error_setg (errp,"device cannot work as neither modern nor legacy mode" +" is enabled" ); +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 ;Pardon my ignorance... is this a device-specific restriction, or is it the same for more (all?) virtio devices?
Yes this for all virtio devices.
But wait, I now realize that the check isn't done in the right place because if we don't pass an explicit disable-legacy=on then proxy->disable_legacy gets its final value in virtio_pci_realize() which gets called after virtio_pci_dc_realize()...
I'll fix that.
Thanks !
--
Greg