Add debug interface to kick/call on purpose
cover Add debug interface to kick/call on purpose
The virtio device/driver (e.g., vhost-scsi and indeed any device including e1000e) may hang due to the lost of IRQ or the lost of doorbell register kick, e.g.,
https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg01711.html
The virtio-net was in trouble in above link because the 'kick' was not taking effect (missed).
This RFC adds a new debug interface 'DeviceEvent' to DeviceClass to help narrow down if the issue is due to lost of irq/kick. So far the new interface handles only two events: 'call' and 'kick'. Any device (e.g., e1000e or vhost-scsi) may implement (e.g., via eventfd, MSI-X or legacy IRQ).
The 'call' is to inject irq on purpose by admin for a specific device (e.g., vhost-scsi) from QEMU/host to VM, while the 'kick' is to kick the doorbell on purpose by admin at QEMU/host side for a specific device.
This device can also be used as a workaround if call/kick is lost due to virtualization software (e.g., kernel or QEMU) issue.
Below is from live crash analysis. Initially, the queue=3 has count=30 for 'kick' eventfd_ctx. Suppose there is data in vring avail while there is no used available. We suspect this is because vhost-scsi was not notified by VM. In order to narrow down and analyze the issue, we use live crash to dump the current counter of eventfd for queue=3.
crash> eventfd_ctx ffffa10392537ac0
struct eventfd_ctx {
kref = {
refcount = {
refs = {
counter = 4
}
}
},
wqh = {
lock = {
{
rlock = {
raw_lock = {
{
val = {
counter = 0
},
{
locked = 0 '\000',
pending = 0 '\000'
},
{
locked_pending = 0,
tail = 0
}
}
}
}
}
},
head = {
next = 0xffffa104ae40d360,
prev = 0xffffa104ae40d360
} },
count = 30, -----> eventfd is 30 !!!
flags = 526336,
id = 26
}
Now we kick the doorbell for vhost-scsi queue=3 on purpose for diagnostic with this interface.
{ "execute": "x-debug-device-event", "arguments": { "dev": "/machine/peripheral/vscsi0", "event": "kick", "queue": 3 } }
The counter increased to 31. Suppose the hang issue is addressed, it indicates something bad is in software that the 'kick' is lost.
crash> eventfd_ctx ffffa10392537ac0
struct eventfd_ctx {
kref = {
refcount = {
refs = {
counter = 4
}
}
},
wqh = {
lock = {
{
rlock = {
raw_lock = {
{
val = {
counter = 0
},
{
locked = 0 '\000',
pending = 0 '\000'
},
{
locked_pending = 0,
tail = 0
}
}
}
}
}
},
head = {
next = 0xffffa104ae40d360,
prev = 0xffffa104ae40d360
} },
count = 31, -----> eventfd incremented to 31 !!! flags = 526336,
id = 26
}
Only the interface for vhost-scsi is implemented since this is RFC. I will implement for other types (e.g., eventfd or MSI-X) if the RFC is reasonable.
Thank you very much!
Dongli Zhang
RFC PATCH 1/2 qdev: add debug interface to kick/call eventfd
The virtio device/driver (e.g., vhost-scsi) may hang due to the lost of IRQ or the lost of doorbell register kick, e.g.,
https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg01711.html
This patch adds a new debug interface 'DeviceEvent' to DeviceClass to help narrow down if the issue is due to lost of irq/kick. So far the new interface handles only two events: 'call' and 'kick'. Any device (e.g., e1000e or vhost-scsi) may implement (e.g., via eventfd, MSI-X or legacy IRQ).
The 'call' is to inject irq on purpose by admin for a specific device (e.g., vhost-scsi) from QEMU/host to VM, while the 'kick' is to kick the doorbell on purpose by admin at QEMU/host side for a specific device.
--- hmp-commands.hx | 14 ++++++++++++++ include/hw/qdev-core.h | 6 ++++++ include/monitor/hmp.h | 1 + qapi/qdev.json | 30 ++++++++++++++++++++++++++++++ softmmu/qdev-monitor.c | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 92 insertions(+)
hmp-commands.hx +14 -0
@@ -1867,3 +1867,17 @@ ERST .flags = "p", }, + { + .name = "x-debug-device-event", + .args_type = "dev:s,event:s,queue:l", + .params = "dev event queue", + .help = "generate device event for a specific device queue", + .cmd = hmp_x_debug_device_event, + .flags = "p", + }, + +SRST +``x-debug-device-event`` *dev* *event* *queue* + Generate device event *event* for specific *queue* of *dev* +ERST +
include/hw/qdev-core.h +6 -0
@@ -29,9 +29,14 @@ typedef enum DeviceCategory { DEVICE_CATEGORY_MAX } DeviceCategory; +#define DEVICE_EVENT_CALL 1 +#define DEVICE_EVENT_KICK 2 +typedef void (*DeviceRealize )(DeviceState *dev,Error **errp);typedef void (*DeviceUnrealize )(DeviceState *dev);typedef void (*DeviceReset )(DeviceState *dev); +typedef void (*DeviceEvent )(DeviceState *dev,int event,int queue, +Error **errp);typedef void (*BusRealize )(BusState *bus,Error **errp);typedef void (*BusUnrealize )(BusState *bus);
@@ -132,6 +137,7 @@ struct DeviceClass {DeviceReset reset;DeviceRealize realize;DeviceUnrealize unrealize; +DeviceEvent event;/* device state */ const VMStateDescription *vmsd;
include/monitor/hmp.h +1 -0
@@ -133,5 +133,6 @@ void hmp_info_replay(Monitor *mon, const QDict *qdict);void hmp_replay_break (Monitor *mon,const QDict *qdict);void hmp_replay_delete_break (Monitor *mon,const QDict *qdict);void hmp_replay_seek (Monitor *mon,const QDict *qdict); +void hmp_x_debug_device_event (Monitor *mon,const QDict *qdict);#endif
qapi/qdev.json +30 -0
@@ -124,3 +124,33 @@ ## { 'event': 'DEVICE_DELETED', 'data': { '*device': 'str', 'path': 'str' } } + +## +# @x-debug-device-event: +# +# Generate device event for a specific device queue +# +# @dev: device path +# +# @event: event (e.g., kick or call) to trigger +# +# @queue: queue id +# +# Returns: Nothing on success +# +# Since: 5.3 +# +# Notes: This is used to debug VM driver hang issue. The 'kick' event is to +# send notification to QEMU/vhost while the 'call' event is to +# interrupt VM on purpose. +# +# Example: +# +# -> { "execute": "x-debug-device_event", +# "arguments": { "dev": "/machine/peripheral/vscsi0", "event": "kick", +# "queue": "1" } } +# <- { "return": {} } +# +## +{ 'command': 'x-debug-device-event', + 'data': {'dev': 'str', 'event': 'str', 'queue': 'int'} }
softmmu/qdev-monitor.c +41 -0
47 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH RFC 1/2] qdev: add debug interface to kick/call eventfd
Quoted 1 line · Dongli Zhang
The virtio device/driver (e.g., vhost-scsi) may hang due to the lost of IRQ
s/lost/loss/
Quoted 1 line
or the lost of doorbell register kick, e.g.,
and again
Quoted 5 lines
https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg01711.html
This patch adds a new debug interface 'DeviceEvent' to DeviceClass to help narrow down if the issue is due to lost of irq/kick. So far the new
and again
Quoted 21 lines
interface handles only two events: 'call' and 'kick'. Any device (e.g., e1000e or vhost-scsi) may implement (e.g., via eventfd, MSI-X or legacy IRQ).
The 'call' is to inject irq on purpose by admin for a specific device (e.g., vhost-scsi) from QEMU/host to VM, while the 'kick' is to kick the doorbell on purpose by admin at QEMU/host side for a specific device.
Signed-off-by Dongli Zhang <[email protected]>---
+++
b/qapi/qdev.jsonqapi/qdev.json +5
-0@@ -124,3 +124,33 @@ ## { 'event': 'DEVICE_DELETED', 'data': { '*device': 'str', 'path': 'str' } } + +## +# @x-debug-device-event: +# +# Generate device event for a specific device queue
qapi/qdev.json line 141
Quoted 10 lines
qapi/qdev.json +10
-0+# +# @dev: device path +# +# @event: event (e.g., kick or call) to trigger +# +# @queue: queue id +# +# Returns: Nothing on success +# +# Since: 5.3
The next release is named 6.0, not 5.3.
qapi/qdev.json line 151
Quoted 10 lines
qapi/qdev.json +10
-0+# +# Notes: This is used to debug VM driver hang issue. The 'kick' event is to +# send notification to QEMU/vhost while the 'call' event is to +# interrupt VM on purpose. +# +# Example: +# +# -> { "execute": "x-debug-device_event", +# "arguments": { "dev": "/machine/peripheral/vscsi0", "event": "kick", +# "queue": "1" } }
Your example has queue typed as a string...
qapi/qdev.json line 156
Quoted 5 lines
qapi/qdev.json +5
-0+# <- { "return": {} } +# +## +{ 'command': 'x-debug-device-event', + 'data': {'dev': 'str', 'event': 'str', 'queue': 'int'} }
...which does not match its actual type as an integer.
event should be an enum type (the finite choice of 'kick' or 'call', and introspectible if we add new choices in the future) rather than an open-coded str.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
RFC PATCH 2/2 vhost-scsi: implement DeviceEvent
In reply to Dongli ZhangThis patch implements DeviceEvent for vhost-scsi. As RFC, this patch only considers the case of eventfd and only for vhost-scsi.
Below are example for HMP and QAPI.
(qemu) device_event /machine/peripheral/vscsi0 kick 1
{ "execute": "x-debug-device-event",
"arguments": { "dev": "/machine/peripheral/vscsi0",
"event": "kick",
"queue": 1 } }--- hw/virtio/vhost-scsi-pci.c | 10 ++++++++++ hw/virtio/virtio.c | 19 +++++++++++++++++++ include/hw/virtio/virtio.h | 3 +++ 3 files changed, 32 insertions(+)
hw/virtio/vhost-scsi-pci.c +10 -0
@@ -62,12 +62,22 @@ static void vhost_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)qdev_realize (vdev,BUS (&vpci_dev->bus), errp); } +static void vhost_scsi_pci_event (DeviceState *dev,int event,int queue, +Error **errp) +{ +VHostSCSIPCI *vscsi =VHOST_SCSI_PCI (dev); +DeviceState *vdev =DEVICE (&vscsi->vdev); + +virtio_device_event_eventfd (vdev, event, queue, errp); +} +static void vhost_scsi_pci_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);VirtioPCIClass *k =VIRTIO_PCI_CLASS (klass);PCIDeviceClass *pcidev_k =PCI_DEVICE_CLASS (klass); k->realize = vhost_scsi_pci_realize; + dc->event = vhost_scsi_pci_event;set_bit (DEVICE_CATEGORY_STORAGE , dc->categories);device_class_set_props (dc, vhost_scsi_pci_properties); pcidev_k->vendor_id =PCI_VENDOR_ID_REDHAT_QUMRANET ;
hw/virtio/virtio.c +19 -0
@@ -3690,6 +3690,25 @@ static void virtio_device_unrealize(DeviceState *dev) vdev->bus_name =NULL ; } +void virtio_device_event_eventfd (DeviceState *dev,int event,int queue, +Error **errp) +{ +struct VirtIODevice *vdev =VIRTIO_DEVICE (dev); +int num =virtio_get_num_queues (vdev); + +if (queue <0 || queue >= num) { +error_setg (errp,"Invalid queue %d" , queue); +return ; + } + +VirtQueue *vq = &vdev->vq[queue]; + +if (event ==DEVICE_EVENT_CALL ) +event_notifier_set (&vq->guest_notifier); +else if (event ==DEVICE_EVENT_KICK ) +event_notifier_set (&vq->host_notifier); +} +static void virtio_device_free_virtqueues (VirtIODevice *vdev) {int i;
include/hw/virtio/virtio.h +3 -0
@@ -397,4 +397,7 @@ static inline bool virtio_device_disabled(VirtIODevice *vdev)bool virtio_legacy_allowed (VirtIODevice *vdev);bool virtio_legacy_check_disabled (VirtIODevice *vdev); +void virtio_device_event_eventfd (DeviceState *dev,int event,int queue, +Error **errp); +#endif
Signature · 1 line
2.17.1
Quoted 15 lines · Dongli Zhang
The virtio device/driver (e.g., vhost-scsi and indeed any device including e1000e) may hang due to the lost of IRQ or the lost of doorbell register kick, e.g.,
https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg01711.html
The virtio-net was in trouble in above link because the 'kick' was not taking effect (missed).
This RFC adds a new debug interface 'DeviceEvent' to DeviceClass to help narrow down if the issue is due to lost of irq/kick. So far the new interface handles only two events: 'call' and 'kick'. Any device (e.g., e1000e or vhost-scsi) may implement (e.g., via eventfd, MSI-X or legacy IRQ).
Quoted 3 lines
The 'call' is to inject irq on purpose by admin for a specific device (e.g., vhost-scsi) from QEMU/host to VM, while the 'kick' is to kick the doorbell on purpose by admin at QEMU/host side for a specific device.
I'm really not convinced that we want to give admins the direct ability to poke at internals of devices in a running QEMU. It feels like there is way too much potential for the admin to make a situation far worse by doing the wrong thing here, and people dealing with support tickets will have no idea that the admin has been poking internals of the device and broken it by doing something wrong.
You pointed to bug that hit where this could conceivably be useful, but that's a one time issue and should not a common occurrance that justifies making an official public API to poke at devices forever more IMHO.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 16 lines · * Daniel P. Berrangé ([email protected]) wrote:
Quoted 15 lines · Dongli Zhang
The virtio device/driver (e.g., vhost-scsi and indeed any device including e1000e) may hang due to the lost of IRQ or the lost of doorbell register kick, e.g.,
https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg01711.html
The virtio-net was in trouble in above link because the 'kick' was not taking effect (missed).
This RFC adds a new debug interface 'DeviceEvent' to DeviceClass to help narrow down if the issue is due to lost of irq/kick. So far the new interface handles only two events: 'call' and 'kick'. Any device (e.g., e1000e or vhost-scsi) may implement (e.g., via eventfd, MSI-X or legacy IRQ).
Quoted 8 lines
Quoted 3 lines
The 'call' is to inject irq on purpose by admin for a specific device (e.g., vhost-scsi) from QEMU/host to VM, while the 'kick' is to kick the doorbell on purpose by admin at QEMU/host side for a specific device.
I'm really not convinced that we want to give admins the direct ability to poke at internals of devices in a running QEMU. It feels like there is way too much potential for the admin to make a situation far worse by doing the wrong thing here,
We already do have commands to write to an iport, and to inject MCEs for example; is this that much different?
Quoted 3 lines
and people dealing with support tickets will have
no idea that the admin has been poking internals of the device and broken it by doing something wrong.
You could add a one time log entry to say that this mischeivous command had been used.
Quoted 3 lines
You pointed to bug that hit where this could conceivably be useful, but that's a one time issue and should not a common occurrance that justifies making an official public API to poke at devices forever more IMHO.
I think where it might be practically useful is if you were debugging a hung customers VM and need to find a way to get it to move again. THat's something I'm not familiar with on the virtio side; mst - is this useful from a virtio side?
Dave
Quoted 6 lines
Regards,
DanielSignature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 36 lines · Dr. David Alan Gilbert
Quoted 16 lines · * Daniel P. Berrangé ([email protected]) wrote:
Quoted 15 lines · Dongli Zhang
The virtio device/driver (e.g., vhost-scsi and indeed any device including e1000e) may hang due to the lost of IRQ or the lost of doorbell register kick, e.g.,
The virtio-net was in trouble in above link because the 'kick' was not taking effect (missed).
This RFC adds a new debug interface 'DeviceEvent' to DeviceClass to help narrow down if the issue is due to lost of irq/kick. So far the new interface handles only two events: 'call' and 'kick'. Any device (e.g., e1000e or vhost-scsi) may implement (e.g., via eventfd, MSI-X or legacy IRQ).
Quoted 8 lines
Quoted 3 lines
The 'call' is to inject irq on purpose by admin for a specific device (e.g., vhost-scsi) from QEMU/host to VM, while the 'kick' is to kick the doorbell on purpose by admin at QEMU/host side for a specific device.
I'm really not convinced that we want to give admins the direct ability to poke at internals of devices in a running QEMU. It feels like there is way too much potential for the admin to make a situation far worse by doing the wrong thing here,
We already do have commands to write to an iport, and to inject MCEs for example; is this that much different?
Quoted 3 lines
and people dealing with support tickets will have
no idea that the admin has been poking internals of the device and broken it by doing something wrong.You could add a one time log entry to say that this mischeivous command had been used.
Quoted 8 lines
Quoted 3 lines
You pointed to bug that hit where this could conceivably be useful, but that's a one time issue and should not a common occurrance that justifies making an official public API to poke at devices forever more IMHO.
I think where it might be practically useful is if you were debugging a hung customers VM and need to find a way to get it to move again. THat's something I'm not familiar with on the virtio side; mst - is this useful from a virtio side?
BTW, the linux kernel blk-mq has similar idea/interface. To run the below will be able to 'run' the block IO queue on purpose.
echo "kick" > /sys/kernel/debug/block/sda/state
It is helpful for diagnostic if we assume the IO stall is due to an unknown race that a 'run' of queue is missing.
Dongli Zhang
Quoted 6 lines
Dave
Quoted 3 lines
Regards,
Daniel