monitor: protect qemu_chr_fe_accept_input with monitor lock

The monitor_accept_input API is called from a bottom half, and will
invoke qemu_chr_fe_accept_input().

When a following patch introduces the ability to delete monitors, it
will be neccesary to delete the bottom half. Protecting the call to
qemu_chr_fe_accept_input with the monitor lock will allow for
synchronization with the deletion process.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
[DB: extracted from a larger commit and refactored to apply
     to the new monitor class structure]
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Tested-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Message-ID: <20260706135824.2623960-27-berrange@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
Christian Brauner
2026-07-06 14:58:14 +01:00
committed by Markus Armbruster
parent 4575407b93
commit a0248548ca
3 changed files with 12 additions and 5 deletions

View File

@@ -116,9 +116,11 @@ static void monitor_hmp_accept_input(Monitor *mon)
MonitorHMP *hmp = MONITOR_HMP(mon);
assert(hmp->rs);
readline_restart(hmp->rs);
qemu_chr_fe_accept_input(&mon->chr);
qemu_mutex_unlock(&mon->mon_lock);
readline_show_prompt(hmp->rs);
} else {
qemu_chr_fe_accept_input(&mon->chr);
qemu_mutex_unlock(&mon->mon_lock);
}
}

View File

@@ -562,11 +562,7 @@ static void monitor_accept_input(void *opaque)
Monitor *mon = opaque;
MonitorClass *cls = MONITOR_GET_CLASS(mon);
if (cls->accept_input) {
cls->accept_input(mon);
}
qemu_chr_fe_accept_input(&mon->chr);
cls->accept_input(mon);
}
void monitor_resume(Monitor *mon)

View File

@@ -107,6 +107,7 @@ static void monitor_qmp_emit_event(Monitor *mon, QAPIEvent event, QDict *qdict);
static bool monitor_qmp_requires_iothread(const Monitor *mon);
static void monitor_qmp_complete(UserCreatable *uc, Error **errp);
static bool monitor_qmp_prepare_delete(UserCreatable *uc, Error **errp);
static void monitor_qmp_accept_input(Monitor *mon);
static void monitor_qmp_class_init(ObjectClass *cls, const void *data)
{
@@ -119,6 +120,7 @@ static void monitor_qmp_class_init(ObjectClass *cls, const void *data)
moncls->emit_event = monitor_qmp_emit_event;
moncls->requires_iothread = monitor_qmp_requires_iothread;
moncls->accept_input = monitor_qmp_accept_input;
ucc->complete = monitor_qmp_complete;
ucc->prepare_delete = monitor_qmp_prepare_delete;
@@ -665,3 +667,10 @@ static bool monitor_qmp_prepare_delete(UserCreatable *uc, Error **errp)
error_setg(errp, "Deleting QMP monitors is not supported");
return false;
}
static void monitor_qmp_accept_input(Monitor *mon)
{
WITH_QEMU_LOCK_GUARD(&mon->mon_lock) {
qemu_chr_fe_accept_input(&mon->chr);
}
}