Skip to contentSkip to conversation

QMP event missed during startup

Qemu-devel Ross Lagerwall 3 participants 4 messages Oct 30, 2017 – Nov 10, 2017

lore
Share & tools
lore
#0 lore raw

Hi,

I have found an issue where QEMU emits the RESUME event during startup when it starts VM execution, but it is not possible to receive this event.

To repro this, run:
qemu-system-i386 -m 256 -trace enable=monitor_protocol_event_emit,file=/tmp/out -qmp unix:/tmp/qmp,server,wait

QEMU will not start execution of the VM until something connects to the QMP socket (e.g. qmp-shell). Once connected, no event is received on the QMP connection but the tracepoint is hit indicating that an event has been emitted. I suspect that the event is emitted while the QMP client is doing the initial negotiation.

The reason I want to receive this event is that QEMU currently uses xenstore to communicate this information to the Xen toolstack (see xen-common.c:xen_change_state_handler) but we want to move to using QMP rather than xenstore for this kind of thing.

Is this a known issue or just a bug that should be fixed?

Thanks,

Signature · 1 line
Ross Lagerwall
#1 lore raw
Quoted 16 lines · * Ross Lagerwall ([email protected]) wrote:

Hi,

I have found an issue where QEMU emits the RESUME event during startup when it starts VM execution, but it is not possible to receive this event.

To repro this, run:
qemu-system-i386 -m 256 -trace enable=monitor_protocol_event_emit,file=/tmp/out -qmp unix:/tmp/qmp,server,wait

QEMU will not start execution of the VM until something connects to the QMP socket (e.g. qmp-shell). Once connected, no event is received on the QMP connection but the tracepoint is hit indicating that an event has been emitted. I suspect that the event is emitted while the QMP client is doing the initial negotiation.

Quoted 6 lines

The reason I want to receive this event is that QEMU currently uses xenstore to communicate this information to the Xen toolstack (see xen-common.c:xen_change_state_handler) but we want to move to using QMP rather than xenstore for this kind of thing.

Is this a known issue or just a bug that should be fixed?

I'll leave it to Markus to say if it's a bug or not, but can't you work around this by starting qemu with -S which leaves the guest paused, and then continuing the guest when you have your QMP ?

Dave

Quoted 4 lines

Thanks,

Signature · 1 line
Ross Lagerwall

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#2 lore raw
Quoted 22 lines · Dr. David Alan Gilbert
Quoted 21 lines · * Ross Lagerwall ([email protected]) wrote:

Hi,

I have found an issue where QEMU emits the RESUME event during startup when it starts VM execution, but it is not possible to receive this event.

To repro this, run:
qemu-system-i386 -m 256 -trace enable=monitor_protocol_event_emit,file=/tmp/out -qmp unix:/tmp/qmp,server,wait

QEMU will not start execution of the VM until something connects to the QMP socket (e.g. qmp-shell). Once connected, no event is received on the QMP connection but the tracepoint is hit indicating that an event has been emitted. I suspect that the event is emitted while the QMP client is doing the initial negotiation.

The reason I want to receive this event is that QEMU currently uses xenstore to communicate this information to the Xen toolstack (see xen-common.c:xen_change_state_handler) but we want to move to using QMP rather than xenstore for this kind of thing.

Quoted 5 lines
Quoted 1 line

Is this a known issue or just a bug that should be fixed?

I'll leave it to Markus to say if it's a bug or not, but can't you work around this by starting qemu with -S which leaves the guest paused, and then continuing the guest when you have your QMP ?

You can:

<-- {"QMP": {"version": {"qemu": {"micro": 50, "minor": 10, "major": 2}, "package": " (v2.10.0-613-g10656079e1-dirty)"}, "capabilities": []}} --> { "execute": "qmp_capabilities" }
<-- {"return": {}}
--> { "execute": "cont" }
<-- {"timestamp": {"seconds": 1510235984, "microseconds": 108550}, "event": "RESUME"}
<-- {"return": {}}

RESUME is sent in vm_prepare_start(), called from main() via vm_start(), but only if @autostart, i.e. no -S.

The "wait" in the argument of -qmp makes QEMU wait for a QMP client to connect to the QMP socket, long before vm_start() gets called. However, having connected is not sufficient for receiving events, you also have to exit capabilities negotiation mode. Not possible until QEMU is running the main loop, which runs after the vm_start() quoted above.

If QMP monitors became usable before entering main_loop(), we'd have a race condition instead. The only reliable way to get the RESUME event is -S.

This adds one minor item to the long list of reasons why management software should pass -S.

All clear now?

#3 lore raw
Quoted 48 lines · Markus Armbruster
Quoted 22 lines · Dr. David Alan Gilbert
Quoted 21 lines · * Ross Lagerwall ([email protected]) wrote:

Hi,

I have found an issue where QEMU emits the RESUME event during startup when it starts VM execution, but it is not possible to receive this event.

To repro this, run:
qemu-system-i386 -m 256 -trace enable=monitor_protocol_event_emit,file=/tmp/out -qmp unix:/tmp/qmp,server,wait

QEMU will not start execution of the VM until something connects to the QMP socket (e.g. qmp-shell). Once connected, no event is received on the QMP connection but the tracepoint is hit indicating that an event has been emitted. I suspect that the event is emitted while the QMP client is doing the initial negotiation.

The reason I want to receive this event is that QEMU currently uses xenstore to communicate this information to the Xen toolstack (see xen-common.c:xen_change_state_handler) but we want to move to using QMP rather than xenstore for this kind of thing.

Quoted 5 lines
Quoted 1 line

Is this a known issue or just a bug that should be fixed?

I'll leave it to Markus to say if it's a bug or not, but can't you work around this by starting qemu with -S which leaves the guest paused, and then continuing the guest when you have your QMP ?

You can:

<-- {"QMP": {"version": {"qemu": {"micro": 50, "minor": 10, "major": 2}, "package": " (v2.10.0-613-g10656079e1-dirty)"}, "capabilities": []}} --> { "execute": "qmp_capabilities" }
<-- {"return": {}}
--> { "execute": "cont" }
<-- {"timestamp": {"seconds": 1510235984, "microseconds": 108550}, "event": "RESUME"}
<-- {"return": {}}

RESUME is sent in vm_prepare_start(), called from main() via vm_start(), but only if @autostart, i.e. no -S.

The "wait" in the argument of -qmp makes QEMU wait for a QMP client to connect to the QMP socket, long before vm_start() gets called. However, having connected is not sufficient for receiving events, you also have to exit capabilities negotiation mode. Not possible until QEMU is running the main loop, which runs after the vm_start() quoted above.

Quoted 9 lines

If QMP monitors became usable before entering main_loop(), we'd have a race condition instead. The only reliable way to get the RESUME event is -S.

This adds one minor item to the long list of reasons why management software should pass -S.

All clear now?

Yeah that makes sense thanks. I've now tested with -S and it works fine.

Cheers,

Signature · 1 line
Ross Lagerwall