@samitouri / QOSamiQemu / commits / a0248548ca

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>

Christian Brauner committed Jul 6, 2026 at 14:58 UTC a0248548ca784ef14a6d3bc01e95d5e8a4bdc559
3 files changed +12 -5
monitor/hmp.c
+2
@@ -116,9 +116,11 @@ static void monitor_hmp_accept_input(Monitor *mon)
116 MonitorHMP *hmp = MONITOR_HMP(mon);
117 assert(hmp->rs);
118 readline_restart(hmp->rs);
119 + qemu_chr_fe_accept_input(&mon->chr);
120 qemu_mutex_unlock(&mon->mon_lock);
121 readline_show_prompt(hmp->rs);
122 } else {
123 + qemu_chr_fe_accept_input(&mon->chr);
124 qemu_mutex_unlock(&mon->mon_lock);
125 }
126 }
monitor/monitor.c
+1 -5
@@ -562,11 +562,7 @@ static void monitor_accept_input(void *opaque)
562 Monitor *mon = opaque;
563 MonitorClass *cls = MONITOR_GET_CLASS(mon);
564
565 - if (cls->accept_input) {
566 - cls->accept_input(mon);
567 - }
568 -
569 - qemu_chr_fe_accept_input(&mon->chr);
565 + cls->accept_input(mon);
566 }
567
568 void monitor_resume(Monitor *mon)
monitor/qmp.c
+9
@@ -107,6 +107,7 @@ static void monitor_qmp_emit_event(Monitor *mon, QAPIEvent event, QDict *qdict);
107 static bool monitor_qmp_requires_iothread(const Monitor *mon);
108 static void monitor_qmp_complete(UserCreatable *uc, Error **errp);
109 static bool monitor_qmp_prepare_delete(UserCreatable *uc, Error **errp);
110 +static void monitor_qmp_accept_input(Monitor *mon);
111
112 static void monitor_qmp_class_init(ObjectClass *cls, const void *data)
113 {
@@ -119,6 +120,7 @@ static void monitor_qmp_class_init(ObjectClass *cls, const void *data)
120
121 moncls->emit_event = monitor_qmp_emit_event;
122 moncls->requires_iothread = monitor_qmp_requires_iothread;
123 + moncls->accept_input = monitor_qmp_accept_input;
124
125 ucc->complete = monitor_qmp_complete;
126 ucc->prepare_delete = monitor_qmp_prepare_delete;
@@ -665,3 +667,10 @@ static bool monitor_qmp_prepare_delete(UserCreatable *uc, Error **errp)
667 error_setg(errp, "Deleting QMP monitors is not supported");
668 return false;
669 }
670 +
671 +static void monitor_qmp_accept_input(Monitor *mon)
672 +{
673 + WITH_QEMU_LOCK_GUARD(&mon->mon_lock) {
674 + qemu_chr_fe_accept_input(&mon->chr);
675 + }
676 +}