Fix the segment fault when calling yank_register_instance
PATCH 1/2 Fix the segment fault when calling yank_register_instance
From: Li Zhang <[email protected]>
When executing the QMP commands "chardev-change" to change the backend device to socket, it will cause a segment fault because it assumes chr->label as non-NULL in function yank_register_instance. The function qmp_chardev_change calls chardev_new, which label is NULL when creating a new chardev. The label will be passed to yank_register_instance which causes a segment fault. The callchain is as the following:
chardev_new ->
qemu_char_open ->
cc->open ->
qmp_chardev_open_socket ->
yank_register_instance--- chardev/char-socket.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
chardev/char-socket.c +5 -3
@@ -1421,10 +1421,12 @@ static void qmp_chardev_open_socket(Chardev *chr,qemu_chr_set_feature (chr,QEMU_CHAR_FEATURE_FD_PASS ); } -if (!yank_register_instance (CHARDEV_YANK_INSTANCE (chr->label), errp)) { -return ; +if (chr->label) { +if (!yank_register_instance (CHARDEV_YANK_INSTANCE (chr->label), errp)) { +return ; + } + s->registered_yank = true; } - s->registered_yank = true;/* be isn't opened until we get a connection */ *be_opened = false;
Signature · 1 line
2.25.1
PATCH 2/2 Support monitor chardev hotswap with QMP
From: Li Zhang <[email protected]>
For some scenarios, it needs to hot-add a monitor device. But QEMU doesn't support hotplug yet. It also works by adding a monitor with null backend by default and then change its backend to socket by QMP command "chardev-change".
So this patch is to support monitor chardev hotswap with QMP.
--- monitor/monitor-internal.h | 3 +++ monitor/monitor.c | 2 +- monitor/qmp.c | 42 +++++++++++++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 4 deletions(-)
monitor/monitor-internal.h +3 -0
@@ -186,4 +186,7 @@ int hmp_compare_cmd(const char *name, const char *list);void qmp_query_qmp_schema (QDict *qdict,QObject **ret_data,Error **errp); +gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond, +void *opaque); +#endif
monitor/monitor.c +1 -1
@@ -157,7 +157,7 @@ static inline bool monitor_is_hmp_non_interactive(const Monitor *mon)static void monitor_flush_locked (Monitor *mon); -static gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond, +gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond,void *opaque) {Monitor *mon = opaque;
monitor/qmp.c +39 -3
66 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH 2/2] Support monitor chardev hotswap with QMP
Hi,
Any comments about this patch?
Thanks
Li
Quoted 127 lines · Li Zhang
From: Li Zhang <[email protected]>
For some scenarios, it needs to hot-add a monitor device. But QEMU doesn't support hotplug yet. It also works by adding a monitor with null backend by default and then change its backend to socket by QMP command "chardev-change".
So this patch is to support monitor chardev hotswap with QMP.
Signed-off-by Li Zhang <[email protected]>--- monitor/monitor-internal.h | 3 +++ monitor/monitor.c | 2 +- monitor/qmp.c | 42 +++++++++++++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 4 deletions(-)monitor/monitor-internal.h +3
-0@@ -186,4 +186,7 @@ int hmp_compare_cmd(const char *name, const char *list);void qmp_query_qmp_schema (QDict *qdict,QObject **ret_data,Error **errp); +gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond, +void *opaque); +#endif
monitor/monitor.c +1
-1@@ -157,7 +157,7 @@ static inline bool monitor_is_hmp_non_interactive(const Monitor *mon) static void monitor_flush_locked(Monitor *mon); -static gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond, +gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond,void *opaque) {Monitor *mon = opaque;monitor/qmp.c +30
-1@@ -44,6 +44,7 @@ struct QMPRequest {Error *err; };typedef struct QMPRequest QMPRequest ; +static void monitor_qmp_set_handlers_bh (void *opaque);QmpCommandList qmp_commands, qmp_cap_negotiation_commands;@@ -480,7 +481,35 @@ void monitor_data_destroy_qmp(MonitorQMP *mon)g_queue_free (mon->qmp_requests); } -static void monitor_qmp_setup_handlers_bh (void *opaque) +static int monitor_qmp_change (void *opaque) +{ +MonitorQMP *mon = opaque; + + mon->common.use_io_thread = +qemu_chr_has_feature (mon->common.chr.chr,QEMU_CHAR_FEATURE_GCONTEXT ); + +if (mon->common.use_io_thread) { +aio_bh_schedule_oneshot (iothread_get_aio_context (mon_iothread), + monitor_qmp_set_handlers_bh, mon); + }else { +qemu_chr_fe_set_handlers (&mon->common.chr, monitor_can_read, + monitor_qmp_read, monitor_qmp_event, + monitor_qmp_change, &mon->common,NULL , true); + } + +if (mon->common.out_watch) { +g_source_remove (mon->common.out_watch); +qemu_mutex_lock (&mon->common.mon_lock); + mon->common.out_watch = +qemu_chr_fe_add_watch (&mon->common.chr,G_IO_OUT |G_IO_HUP , + monitor_unblocked, &mon->common); +qemu_mutex_unlock (&mon->common.mon_lock); + } + +return 0 ; +} + +static void monitor_qmp_set_handlers_bh (void *opaque) {MonitorQMP *mon = opaque; GMainContext *context;monitor/qmp.c +8
-1@@ -490,7 +519,14 @@ static void monitor_qmp_setup_handlers_bh(void *opaque)assert (context);qemu_chr_fe_set_handlers (&mon->common.chr, monitor_can_read, monitor_qmp_read, monitor_qmp_event, -NULL , &mon->common, context, true); + monitor_qmp_change, &mon->common, context, true); + +} + +static void monitor_qmp_setup_handlers_bh (void *opaque) +{ +MonitorQMP *mon = opaque; +monitor_qmp_set_handlers_bh (mon);monitor_list_append (&mon->common);}
monitor/qmp.c +1
-1@@ -531,7 +567,7 @@ void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) }else {qemu_chr_fe_set_handlers (&mon->common.chr, monitor_can_read, monitor_qmp_read, monitor_qmp_event, -NULL , &mon->common,NULL , true); + monitor_qmp_change, &mon->common,NULL , true);monitor_list_append (&mon->common);}}
--
2.25.1
Re: [PATCH 2/2] Support monitor chardev hotswap with QMP
Quoted 3 lines · Li Zhang
Hi,
Any comments about this patch?
I wanted to review this before my Easter break, but I'm out of time :(
When I'm back (April 6), I'll check whether it still needs review, but I do hope somebody else can look at it sooner.
Re: [PATCH 2/2] Support monitor chardev hotswap with QMP
Quoted 12 lines · Markus Armbruster
Quoted 3 lines · Li Zhang
Hi,
Any comments about this patch?
I wanted to review this before my Easter break, but I'm out of time :(
When I'm back (April 6), I'll check whether it still needs review, but I do hope somebody else can look at it sooner.
Thanks anyway. This patch is better to work with Lukas' patches together.
Re: [PATCH 2/2] Support monitor chardev hotswap with QMP
In reply to Markus ArmbrusterHi Markus,
Any suggestions on this patch?
Thanks
Li
Quoted 12 lines · Markus Armbruster
Quoted 3 lines · Li Zhang
Hi,
Any comments about this patch?
I wanted to review this before my Easter break, but I'm out of time :(
When I'm back (April 6), I'll check whether it still needs review, but I do hope somebody else can look at it sooner.
Re: [PATCH 2/2] Support monitor chardev hotswap with QMP
Quoted 3 lines · Li Zhang
Hi Markus,
Any suggestions on this patch?
I understand PATCH 1/2 got superseded by Lukas's "[PATCH v8 0/4] yank:
Add chardev tests and fixes". I trust Marc-André will take care of it in due time.
Before I look at the actual patch: does this patch depend on Lukas's fix or your "[PATCH 1/2] Fix the segment fault when calling yank_register_instance"?
Re: [PATCH 2/2] Support monitor chardev hotswap with QMP
Hi Markus,
[PATCH 1/2] Fix the segment fault when calling yank_register_instance is reworked by Lukas.
And his patches have been merged to master branch of qemu. [PATCH 2/2] Support monitor chardev hotswap with QMP is to change monitor backend with chardev-change. It is not implemented yet.
Quoted 15 lines · Markus Armbruster
Quoted 3 lines · Li Zhang
Hi Markus,
Any suggestions on this patch?
I understand PATCH 1/2 got superseded by Lukas's "[PATCH v8 0/4] yank:
Add chardev tests and fixes". I trust Marc-André will take care of it in due time.Before I look at the actual patch: does this patch depend on Lukas's fix or your "[PATCH 1/2] Fix the segment fault when calling
yank_register_instance"?
Re: [PATCH 2/2] Support monitor chardev hotswap with QMP
In reply to Li ZhangHi Li,
Quoted 65 lines
For some scenarios, it needs to hot-add a monitor device. But QEMU doesn't support hotplug yet. It also works by adding a monitor with null backend by default and then change its backend to socket by QMP command "chardev-change".
So this patch is to support monitor chardev hotswap with QMP.
Signed-off-by Li Zhang <[email protected]>--- monitor/monitor-internal.h | 3 +++ monitor/monitor.c | 2 +- monitor/qmp.c | 42 +++++++++++++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 4 deletions(-)monitor/monitor-internal.h +3
-0@@ -186,4 +186,7 @@ int hmp_compare_cmd(const char *name, const char *list);void qmp_query_qmp_schema (QDict *qdict,QObject **ret_data,Error **errp); +gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond, +void *opaque); +#endif monitor/monitor.c +1
-1@@ -157,7 +157,7 @@ static inline bool monitor_is_hmp_non_interactive(const Monitor *mon)static void monitor_flush_locked (Monitor *mon); -static gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond, +gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond,void *opaque) {Monitor *mon = opaque;monitor/qmp.c +10
-1@@ -44,6 +44,7 @@ struct QMPRequest {Error *err; };typedef struct QMPRequest QMPRequest ; +static void monitor_qmp_set_handlers_bh (void *opaque);QmpCommandList qmp_commands, qmp_cap_negotiation_commands;@@ -480,7 +481,35 @@ void monitor_data_destroy_qmp(MonitorQMP *mon)g_queue_free (mon->qmp_requests); } -static void monitor_qmp_setup_handlers_bh (void *opaque) +static int monitor_qmp_change (void *opaque) +{ +MonitorQMP *mon = opaque; + + mon->common.use_io_thread = +qemu_chr_has_feature (mon->common.chr.chr,QEMU_CHAR_FEATURE_GCONTEXT ); + +if (mon->common.use_io_thread) { + aio_bh_schedule_oneshot(iothread_get_aio_context(mon_iothread),
monitor/qmp.c void monitor_data_destroy_qmp(MonitorQMP *mon) · line 502
Quoted 10 lines
monitor/qmp.c +10
-0+ monitor_qmp_set_handlers_bh, mon); + }else { +qemu_chr_fe_set_handlers (&mon->common.chr, monitor_can_read, + monitor_qmp_read, monitor_qmp_event, + monitor_qmp_change, &mon->common,NULL , true); + } + +if (mon->common.out_watch) { +g_source_remove (mon->common.out_watch); +qemu_mutex_lock (&mon->common.mon_lock);
Not very sure if mutex is must here, but still its protecting "out_watch" for simultaneous updating.
Quoted 30 lines
monitor/qmp.c +18
-1+ mon->common.out_watch = +qemu_chr_fe_add_watch (&mon->common.chr,G_IO_OUT |G_IO_HUP , + monitor_unblocked, &mon->common); +qemu_mutex_unlock (&mon->common.mon_lock); + } + +return 0 ; +} + +static void monitor_qmp_set_handlers_bh (void *opaque) {MonitorQMP *mon = opaque;GMainContext *context;@@ -490,7 +519,14 @@ static void monitor_qmp_setup_handlers_bh(void *opaque)assert (context);qemu_chr_fe_set_handlers (&mon->common.chr, monitor_can_read, monitor_qmp_read, monitor_qmp_event, -NULL , &mon->common, context, true); + monitor_qmp_change, &mon->common, context, true); + +} + +static void monitor_qmp_setup_handlers_bh (void *opaque) +{ +MonitorQMP *mon = opaque; +monitor_qmp_set_handlers_bh (mon);monitor_list_append (&mon->common); }
monitor/qmp.c void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) · line 573
Quoted 8 lines
monitor/qmp.c +1
-1@@ -531,7 +567,7 @@ void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) }else {qemu_chr_fe_set_handlers (&mon->common.chr, monitor_can_read, monitor_qmp_read, monitor_qmp_event, -NULL , &mon->common,NULL , true); + monitor_qmp_change, &mon->common,NULL , true);monitor_list_append (&mon->common); } }
Overall patch looks good to me.
Re: [PATCH 2/2] Support monitor chardev hotswap with QMP
In reply to Li ZhangQuoted 10 lines · Li Zhang
From: Li Zhang <[email protected]>
For some scenarios, it needs to hot-add a monitor device. But QEMU doesn't support hotplug yet. It also works by adding a monitor with null backend by default and then change its backend to socket by QMP command "chardev-change".
So this patch is to support monitor chardev hotswap with QMP.
Signed-off-by Li Zhang <[email protected]>
I think what what you're trying to say is that chardev-change does not work when the character device changes is used by a QMP monitor. Correct?
If yes, how exactly does it misbehave?
Does it work with an HMP monitor?
Quoted 56 lines
--- monitor/monitor-internal.h | 3 +++ monitor/monitor.c | 2 +- monitor/qmp.c | 42 +++++++++++++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 4 deletions(-)monitor/monitor-internal.h +3
-0@@ -186,4 +186,7 @@ int hmp_compare_cmd(const char *name, const char *list);void qmp_query_qmp_schema (QDict *qdict,QObject **ret_data,Error **errp); +gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond, +void *opaque); +#endif monitor/monitor.c +1
-1@@ -157,7 +157,7 @@ static inline bool monitor_is_hmp_non_interactive(const Monitor *mon)static void monitor_flush_locked (Monitor *mon); -static gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond, +gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond,void *opaque) {Monitor *mon = opaque;monitor/qmp.c +9
-1@@ -44,6 +44,7 @@ struct QMPRequest {Error *err; };typedef struct QMPRequest QMPRequest ; +static void monitor_qmp_set_handlers_bh (void *opaque);QmpCommandList qmp_commands, qmp_cap_negotiation_commands;@@ -480,7 +481,35 @@ void monitor_data_destroy_qmp(MonitorQMP *mon)g_queue_free (mon->qmp_requests); } -static void monitor_qmp_setup_handlers_bh (void *opaque) +static int monitor_qmp_change (void *opaque) +{ +MonitorQMP *mon = opaque; + + mon->common.use_io_thread = +qemu_chr_has_feature (mon->common.chr.chr,QEMU_CHAR_FEATURE_GCONTEXT ); + +if (mon->common.use_io_thread) {
monitor/qmp.c void monitor_data_destroy_qmp(MonitorQMP *mon) · line 501
Quoted 10 lines
monitor/qmp.c +10
-0+aio_bh_schedule_oneshot (iothread_get_aio_context (mon_iothread), + monitor_qmp_set_handlers_bh, mon); + }else { +qemu_chr_fe_set_handlers (&mon->common.chr, monitor_can_read, + monitor_qmp_read, monitor_qmp_event, + monitor_qmp_change, &mon->common,NULL , true); + } + +if (mon->common.out_watch) { +g_source_remove (mon->common.out_watch);
All other updates of @out_watch are under @mon_lock. Why not this one?
I have no idea whether g_source_remove() is the right function to call. Its documentation says "You must use g_source_destroy() for sources added to a non-default main context." The qemu_chr_fe_set_handlers() contract is of no help.
Documentation of g_source_destroy() confuses some more: "This does not unref the GSource: if you still hold a reference, use g_source_unref() to drop it.
Marc-André, can you help?
monitor/qmp.c void monitor_data_destroy_qmp(MonitorQMP *mon) · line 505
Quoted 4 lines
monitor/qmp.c +4
-0+qemu_mutex_lock (&mon->common.mon_lock); + mon->common.out_watch = +qemu_chr_fe_add_watch (&mon->common.chr,G_IO_OUT |G_IO_HUP , + monitor_unblocked, &mon->common);
Bad indentation. Better:
mon->common.out_watch =
qemu_chr_fe_add_watch(&mon->common.chr, G_IO_OUT | G_IO_HUP,
monitor_unblocked, &mon->common);or
mon->common.out_watch = qemu_chr_fe_add_watch(&mon->common.chr,
G_IO_OUT | G_IO_HUP,
monitor_unblocked,
&mon->common);or
mon->common.out_watch = qemu_chr_fe_add_watch(&mon->common.chr,
G_IO_OUT | G_IO_HUP,
monitor_unblocked, &mon->common);monitor/qmp.c void monitor_data_destroy_qmp(MonitorQMP *mon) · line 510
Quoted 5 lines
monitor/qmp.c +5
-0+qemu_mutex_unlock (&mon->common.mon_lock); + } + +return 0 ; +}
This function copies from monitor_data_init(), monitor_init_qmp(), and monitor_flush_locked(). Feels like a refactoring would be in order. Possibly on top.
Quoted 30 lines
monitor/qmp.c +11
-2+ +static void monitor_qmp_set_handlers_bh (void *opaque) {MonitorQMP *mon = opaque;GMainContext *context;@@ -490,7 +519,14 @@ static void monitor_qmp_setup_handlers_bh(void *opaque)assert (context);qemu_chr_fe_set_handlers (&mon->common.chr, monitor_can_read, monitor_qmp_read, monitor_qmp_event, -NULL , &mon->common, context, true); + monitor_qmp_change, &mon->common, context, true); + +} + +static void monitor_qmp_setup_handlers_bh (void *opaque) +{ +MonitorQMP *mon = opaque; +monitor_qmp_set_handlers_bh (mon);monitor_list_append (&mon->common); }@@ -531,7 +567,7 @@ void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) }else {qemu_chr_fe_set_handlers (&mon->common.chr, monitor_can_read, monitor_qmp_read, monitor_qmp_event, -NULL , &mon->common,NULL , true); + monitor_qmp_change, &mon->common,NULL , true);monitor_list_append (&mon->common); } }
Re: [PATCH 2/2] Support monitor chardev hotswap with QMP
Quoted 10 lines · Markus Armbruster
Quoted 7 lines · Li Zhang
From: Li Zhang <[email protected]>
For some scenarios, it needs to hot-add a monitor device. But QEMU doesn't support hotplug yet. It also works by adding a monitor with null backend by default and then change its backend to socket by QMP command "chardev-change".
Quoted 8 lines
Quoted 3 lines
So this patch is to support monitor chardev hotswap with QMP.
Signed-off-by Li Zhang <[email protected]>I think what what you're trying to say is that chardev-change does not work when the character device changes is used by a QMP monitor. Correct?
I mean that when the character device is a monitor device, it doesn't work with a QMP monitor.
For example, I add 2 QMP monitors and change one of the monitor's backends from socket to a null device.
It doesn't work because it needs the monitor device to support chardev-change.
Quoted 1 line
If yes, how exactly does it misbehave?
This command chardev-change needs specific device's change callback function.
Quoted 2 lines
Does it work with an HMP monitor?
No, it doesn't work.
Quoted 61 lines
Quoted 61 lines
--- monitor/monitor-internal.h | 3 +++ monitor/monitor.c | 2 +- monitor/qmp.c | 42 +++++++++++++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 4 deletions(-)monitor/monitor-internal.h +3
-0@@ -186,4 +186,7 @@ int hmp_compare_cmd(const char *name, const char *list);void qmp_query_qmp_schema (QDict *qdict,QObject **ret_data,Error **errp); +gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond, +void *opaque); +#endif monitor/monitor.c +1
-1@@ -157,7 +157,7 @@ static inline bool monitor_is_hmp_non_interactive(const Monitor *mon)static void monitor_flush_locked (Monitor *mon); -static gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond, +gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond,void *opaque) {Monitor *mon = opaque;monitor/qmp.c +13
-1@@ -44,6 +44,7 @@ struct QMPRequest {Error *err; };typedef struct QMPRequest QMPRequest ; +static void monitor_qmp_set_handlers_bh (void *opaque);QmpCommandList qmp_commands, qmp_cap_negotiation_commands;@@ -480,7 +481,35 @@ void monitor_data_destroy_qmp(MonitorQMP *mon)g_queue_free (mon->qmp_requests); } -static void monitor_qmp_setup_handlers_bh (void *opaque) +static int monitor_qmp_change (void *opaque) +{ +MonitorQMP *mon = opaque; + + mon->common.use_io_thread = +qemu_chr_has_feature (mon->common.chr.chr,QEMU_CHAR_FEATURE_GCONTEXT ); + +if (mon->common.use_io_thread) { +aio_bh_schedule_oneshot (iothread_get_aio_context (mon_iothread), + monitor_qmp_set_handlers_bh, mon); + }else { + qemu_chr_fe_set_handlers(&mon->common.chr, monitor_can_read,
Quoted 8 lines
monitor/qmp.c void monitor_data_destroy_qmp(MonitorQMP *mon) · line 501
Quoted 6 lines
monitor/qmp.c +6
-0+ monitor_qmp_read, monitor_qmp_event, + monitor_qmp_change, &mon->common, NULL, true); + } + +if (mon->common.out_watch) { +g_source_remove (mon->common.out_watch);All other updates of @out_watch are under @mon_lock. Why not this one?
Sorry, I missed it. I will correct it.
Quoted 36 lines
I have no idea whether
g_source_remove()is the right function to call. Its documentation says "You must useg_source_destroy()for sources added to a non-default main context." Theqemu_chr_fe_set_handlers()contract is of no help.Documentation of
g_source_destroy()confuses some more: "This does not unref the GSource: if you still hold a reference, useg_source_unref()to drop it.Marc-André, can you help?
monitor/qmp.c void monitor_data_destroy_qmp(MonitorQMP *mon) · line 505
Quoted 4 lines
monitor/qmp.c +4
-0+qemu_mutex_lock (&mon->common.mon_lock); + mon->common.out_watch = +qemu_chr_fe_add_watch (&mon->common.chr,G_IO_OUT |G_IO_HUP , + monitor_unblocked, &mon->common);Bad indentation. Better:
mon->common.out_watch = qemu_chr_fe_add_watch(&mon->common.chr, G_IO_OUT | G_IO_HUP, monitor_unblocked, &mon->common);or
mon->common.out_watch = qemu_chr_fe_add_watch(&mon->common.chr, G_IO_OUT | G_IO_HUP, monitor_unblocked, &mon->common);or
mon->common.out_watch = qemu_chr_fe_add_watch(&mon->common.chr, G_IO_OUT | G_IO_HUP, monitor_unblocked, &mon->common);
Quoted 6 lines
monitor/qmp.c void monitor_data_destroy_qmp(MonitorQMP *mon) · line 510
Quoted 5 lines
monitor/qmp.c +5
-0+qemu_mutex_unlock (&mon->common.mon_lock); + } + +return 0 ; +}
I will correct it. Thanks.
Quoted 4 lines
This function copies from
monitor_data_init(),monitor_init_qmp(), andmonitor_flush_locked(). Feels like a refactoring would be in order. Possibly on top.
OK, I am considering it to avoid duplicated code.
Quoted 21 lines
Quoted 21 lines
monitor/qmp.c +10
-1+ +static void monitor_qmp_set_handlers_bh (void *opaque) {MonitorQMP *mon = opaque;GMainContext *context;@@ -490,7 +519,14 @@ static void monitor_qmp_setup_handlers_bh(void *opaque)assert (context);qemu_chr_fe_set_handlers (&mon->common.chr, monitor_can_read, monitor_qmp_read, monitor_qmp_event, -NULL , &mon->common, context, true); + monitor_qmp_change, &mon->common, context, true); + +} + +static void monitor_qmp_setup_handlers_bh (void *opaque) +{ +MonitorQMP *mon = opaque; +monitor_qmp_set_handlers_bh (mon);monitor_list_append (&mon->common); }
Quoted 10 lines
monitor/qmp.c void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) · line 573
Quoted 9 lines
monitor/qmp.c +1
-1@@ -531,7 +567,7 @@ void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) }else {qemu_chr_fe_set_handlers (&mon->common.chr, monitor_can_read, monitor_qmp_read, monitor_qmp_event, -NULL , &mon->common,NULL , true); + monitor_qmp_change, &mon->common,NULL , true);monitor_list_append (&mon->common); } }
--
Best Regards
-Li
Re: [PATCH 2/2] Support monitor chardev hotswap with QMP
Quoted 19 lines · Li Zhang
Quoted 10 lines · Markus Armbruster
Quoted 7 lines · Li Zhang
From: Li Zhang <[email protected]>
For some scenarios, it needs to hot-add a monitor device. But QEMU doesn't support hotplug yet. It also works by adding a monitor with null backend by default and then change its backend to socket by QMP command "chardev-change".
Quoted 8 lines
Quoted 3 lines
So this patch is to support monitor chardev hotswap with QMP.
Signed-off-by Li Zhang <[email protected]>I think what what you're trying to say is that chardev-change does not work when the character device changes is used by a QMP monitor. Correct?
Quoted 8 lines
I mean that when the character device is a monitor device, it doesn't work with a QMP monitor.
For example, I add 2 QMP monitors and change one of the monitor's backends from socket to a null device.
It doesn't work because it needs the monitor device to support chardev-change.Quoted 1 line
If yes, how exactly does it misbehave?
This command chardev-change needs specific device's change callback function.
Yes, but what happens if you try anyway? I'm asking, because I'd like the answer to be worked into the commit message.
Quoted 2 lines
Quoted 1 line
Does it work with an HMP monitor?
No, it doesn't work.
Re: [PATCH 2/2] Support monitor chardev hotswap with QMP
When I tried chardev-change, it reports this error:
{
"error": {
"class": "GenericError",
"desc": "Chardev user does not support chardev hotswap"
}
}Quoted 37 lines · Markus Armbruster
Quoted 19 lines · Li Zhang
Quoted 10 lines · Markus Armbruster
Quoted 7 lines · Li Zhang
From: Li Zhang <[email protected]>
For some scenarios, it needs to hot-add a monitor device. But QEMU doesn't support hotplug yet. It also works by adding a monitor with null backend by default and then change its backend to socket by QMP command "chardev-change".
Quoted 8 lines
Quoted 3 lines
So this patch is to support monitor chardev hotswap with QMP.
Signed-off-by Li Zhang <[email protected]>I think what what you're trying to say is that chardev-change does not work when the character device changes is used by a QMP monitor. Correct?
Quoted 8 lines
I mean that when the character device is a monitor device, it doesn't work with a QMP monitor.
For example, I add 2 QMP monitors and change one of the monitor's backends from socket to a null device.
It doesn't work because it needs the monitor device to support chardev-change.Quoted 1 line
If yes, how exactly does it misbehave?
This command chardev-change needs specific device's change callback function.
Yes, but what happens if you try anyway? I'm asking, because I'd like the answer to be worked into the commit message.
Quoted 2 lines
Quoted 1 line
Does it work with an HMP monitor?
No, it doesn't work.
Signature · 2 lines
Best Regards -Li
Re: [PATCH 2/2] Support monitor chardev hotswap with QMP
In reply to Markus ArmbrusterQuoted 8 lines · Markus Armbruster
Quoted 6 lines · Li Zhang
From: Li Zhang <[email protected]>
For some scenarios, it needs to hot-add a monitor device. But QEMU doesn't support hotplug yet. It also works by adding a monitor with null backend by default and then change its backend to socket by QMP command "chardev-change".
If you need ability to hot-add monitor instances, why not just implement that feature directly, instead of pre-creating monitors with null backends and then later changing the backend ?
Quoted 148 lines
Quoted 4 lines
So this patch is to support monitor chardev hotswap with QMP.
Signed-off-by Li Zhang <[email protected]>I think what what you're trying to say is that chardev-change does not work when the character device changes is used by a QMP monitor. Correct?
If yes, how exactly does it misbehave?
Does it work with an HMP monitor?
Quoted 56 lines
--- monitor/monitor-internal.h | 3 +++ monitor/monitor.c | 2 +- monitor/qmp.c | 42 +++++++++++++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 4 deletions(-)monitor/monitor-internal.h +3
-0@@ -186,4 +186,7 @@ int hmp_compare_cmd(const char *name, const char *list);void qmp_query_qmp_schema (QDict *qdict,QObject **ret_data,Error **errp); +gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond, +void *opaque); +#endif monitor/monitor.c +1
-1@@ -157,7 +157,7 @@ static inline bool monitor_is_hmp_non_interactive(const Monitor *mon)static void monitor_flush_locked (Monitor *mon); -static gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond, +gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond,void *opaque) {Monitor *mon = opaque;monitor/qmp.c +9
-1@@ -44,6 +44,7 @@ struct QMPRequest {Error *err; };typedef struct QMPRequest QMPRequest ; +static void monitor_qmp_set_handlers_bh (void *opaque);QmpCommandList qmp_commands, qmp_cap_negotiation_commands;@@ -480,7 +481,35 @@ void monitor_data_destroy_qmp(MonitorQMP *mon)g_queue_free (mon->qmp_requests); } -static void monitor_qmp_setup_handlers_bh (void *opaque) +static int monitor_qmp_change (void *opaque) +{ +MonitorQMP *mon = opaque; + + mon->common.use_io_thread = +qemu_chr_has_feature (mon->common.chr.chr,QEMU_CHAR_FEATURE_GCONTEXT ); + +if (mon->common.use_io_thread) {monitor/qmp.c void monitor_data_destroy_qmp(MonitorQMP *mon) · line 501
Quoted 10 lines
monitor/qmp.c +10
-0+aio_bh_schedule_oneshot (iothread_get_aio_context (mon_iothread), + monitor_qmp_set_handlers_bh, mon); + }else { +qemu_chr_fe_set_handlers (&mon->common.chr, monitor_can_read, + monitor_qmp_read, monitor_qmp_event, + monitor_qmp_change, &mon->common,NULL , true); + } + +if (mon->common.out_watch) { +g_source_remove (mon->common.out_watch);All other updates of @out_watch are under @mon_lock. Why not this one?
I have no idea whether
g_source_remove()is the right function to call. Its documentation says "You must useg_source_destroy()for sources added to a non-default main context." Theqemu_chr_fe_set_handlers()contract is of no help.Documentation of
g_source_destroy()confuses some more: "This does not unref the GSource: if you still hold a reference, useg_source_unref()to drop it.Marc-André, can you help?
monitor/qmp.c void monitor_data_destroy_qmp(MonitorQMP *mon) · line 505
Quoted 4 lines
monitor/qmp.c +4
-0+qemu_mutex_lock (&mon->common.mon_lock); + mon->common.out_watch = +qemu_chr_fe_add_watch (&mon->common.chr,G_IO_OUT |G_IO_HUP , + monitor_unblocked, &mon->common);Bad indentation. Better:
mon->common.out_watch = qemu_chr_fe_add_watch(&mon->common.chr, G_IO_OUT | G_IO_HUP, monitor_unblocked, &mon->common);or
mon->common.out_watch = qemu_chr_fe_add_watch(&mon->common.chr, G_IO_OUT | G_IO_HUP, monitor_unblocked, &mon->common);or
mon->common.out_watch = qemu_chr_fe_add_watch(&mon->common.chr, G_IO_OUT | G_IO_HUP, monitor_unblocked, &mon->common);monitor/qmp.c void monitor_data_destroy_qmp(MonitorQMP *mon) · line 510
Quoted 5 lines
monitor/qmp.c +5
-0+qemu_mutex_unlock (&mon->common.mon_lock); + } + +return 0 ; +}This function copies from
monitor_data_init(),monitor_init_qmp(), andmonitor_flush_locked(). Feels like a refactoring would be in order. Possibly on top.Quoted 21 lines
monitor/qmp.c +10
-1+ +static void monitor_qmp_set_handlers_bh (void *opaque) {MonitorQMP *mon = opaque;GMainContext *context;@@ -490,7 +519,14 @@ static void monitor_qmp_setup_handlers_bh(void *opaque)assert (context);qemu_chr_fe_set_handlers (&mon->common.chr, monitor_can_read, monitor_qmp_read, monitor_qmp_event, -NULL , &mon->common, context, true); + monitor_qmp_change, &mon->common, context, true); + +} + +static void monitor_qmp_setup_handlers_bh (void *opaque) +{ +MonitorQMP *mon = opaque; +monitor_qmp_set_handlers_bh (mon);monitor_list_append (&mon->common); }
Quoted 11 lines
monitor/qmp.c void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) · line 573
Quoted 9 lines
monitor/qmp.c +1
-1@@ -531,7 +567,7 @@ void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) }else {qemu_chr_fe_set_handlers (&mon->common.chr, monitor_can_read, monitor_qmp_read, monitor_qmp_event, -NULL , &mon->common,NULL , true); + monitor_qmp_change, &mon->common,NULL , true);monitor_list_append (&mon->common); } }
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 :|
Re: [PATCH 2/2] Support monitor chardev hotswap with QMP
Quoted 6 lines · Daniel P. Berrangé
Quoted 4 lines · Markus Armbruster
Quoted 2 lines · Li Zhang
From: Li Zhang <[email protected]>
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
For some scenarios, it needs to hot-add a monitor device. But QEMU doesn't support hotplug yet. It also works by adding a monitor with null backend by default and then change its backend to socket by QMP command "chardev-change".
If you need ability to hot-add monitor instances, why not just implement that feature directly, instead of pre-creating monitors with null backends and then later changing the backend ?
Hi Daniel,
I would like to use this solution first because we'd like to use it as soon as possible.
It's the best solution to implement the hot-add feature and it may need more effort to do it.
I will consider it.
Quoted 167 lines
Quoted 148 lines
Quoted 4 lines
So this patch is to support monitor chardev hotswap with QMP.
Signed-off-by Li Zhang <[email protected]>I think what what you're trying to say is that chardev-change does not work when the character device changes is used by a QMP monitor. Correct?
If yes, how exactly does it misbehave?
Does it work with an HMP monitor?
Quoted 56 lines
--- monitor/monitor-internal.h | 3 +++ monitor/monitor.c | 2 +- monitor/qmp.c | 42 +++++++++++++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 4 deletions(-)monitor/monitor-internal.h +3
-0@@ -186,4 +186,7 @@ int hmp_compare_cmd(const char *name, const char *list);void qmp_query_qmp_schema (QDict *qdict,QObject **ret_data,Error **errp); +gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond, +void *opaque); +#endif monitor/monitor.c +1
-1@@ -157,7 +157,7 @@ static inline bool monitor_is_hmp_non_interactive(const Monitor *mon)static void monitor_flush_locked (Monitor *mon); -static gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond, +gboolean monitor_unblocked (GIOChannel *chan,GIOCondition cond,void *opaque) {Monitor *mon = opaque;monitor/qmp.c +9
-1@@ -44,6 +44,7 @@ struct QMPRequest {Error *err; };typedef struct QMPRequest QMPRequest ; +static void monitor_qmp_set_handlers_bh (void *opaque);QmpCommandList qmp_commands, qmp_cap_negotiation_commands;@@ -480,7 +481,35 @@ void monitor_data_destroy_qmp(MonitorQMP *mon)g_queue_free (mon->qmp_requests); } -static void monitor_qmp_setup_handlers_bh (void *opaque) +static int monitor_qmp_change (void *opaque) +{ +MonitorQMP *mon = opaque; + + mon->common.use_io_thread = +qemu_chr_has_feature (mon->common.chr.chr,QEMU_CHAR_FEATURE_GCONTEXT ); + +if (mon->common.use_io_thread) {monitor/qmp.c void monitor_data_destroy_qmp(MonitorQMP *mon) · line 501
Quoted 10 lines
monitor/qmp.c +10
-0+aio_bh_schedule_oneshot (iothread_get_aio_context (mon_iothread), + monitor_qmp_set_handlers_bh, mon); + }else { +qemu_chr_fe_set_handlers (&mon->common.chr, monitor_can_read, + monitor_qmp_read, monitor_qmp_event, + monitor_qmp_change, &mon->common,NULL , true); + } + +if (mon->common.out_watch) { +g_source_remove (mon->common.out_watch);All other updates of @out_watch are under @mon_lock. Why not this one?
I have no idea whether
g_source_remove()is the right function to call. Its documentation says "You must useg_source_destroy()for sources added to a non-default main context." Theqemu_chr_fe_set_handlers()contract is of no help.Documentation of
g_source_destroy()confuses some more: "This does not unref the GSource: if you still hold a reference, useg_source_unref()to drop it.Marc-André, can you help?
monitor/qmp.c void monitor_data_destroy_qmp(MonitorQMP *mon) · line 505
Quoted 4 lines
monitor/qmp.c +4
-0+qemu_mutex_lock (&mon->common.mon_lock); + mon->common.out_watch = +qemu_chr_fe_add_watch (&mon->common.chr,G_IO_OUT |G_IO_HUP , + monitor_unblocked, &mon->common);Bad indentation. Better:
mon->common.out_watch = qemu_chr_fe_add_watch(&mon->common.chr, G_IO_OUT | G_IO_HUP, monitor_unblocked, &mon->common);or
mon->common.out_watch = qemu_chr_fe_add_watch(&mon->common.chr, G_IO_OUT | G_IO_HUP, monitor_unblocked, &mon->common);or
mon->common.out_watch = qemu_chr_fe_add_watch(&mon->common.chr, G_IO_OUT | G_IO_HUP, monitor_unblocked, &mon->common);monitor/qmp.c void monitor_data_destroy_qmp(MonitorQMP *mon) · line 510
Quoted 5 lines
monitor/qmp.c +5
-0+qemu_mutex_unlock (&mon->common.mon_lock); + } + +return 0 ; +}This function copies from
monitor_data_init(),monitor_init_qmp(), andmonitor_flush_locked(). Feels like a refactoring would be in order. Possibly on top.Quoted 21 lines
monitor/qmp.c +10
-1+ +static void monitor_qmp_set_handlers_bh (void *opaque) {MonitorQMP *mon = opaque;GMainContext *context;@@ -490,7 +519,14 @@ static void monitor_qmp_setup_handlers_bh(void *opaque)assert (context);qemu_chr_fe_set_handlers (&mon->common.chr, monitor_can_read, monitor_qmp_read, monitor_qmp_event, -NULL , &mon->common, context, true); + monitor_qmp_change, &mon->common, context, true); + +} + +static void monitor_qmp_setup_handlers_bh (void *opaque) +{ +MonitorQMP *mon = opaque; +monitor_qmp_set_handlers_bh (mon);monitor_list_append (&mon->common); }Quoted 11 lines
monitor/qmp.c void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) · line 573
Quoted 9 lines
monitor/qmp.c +1
-1@@ -531,7 +567,7 @@ void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) }else {qemu_chr_fe_set_handlers (&mon->common.chr, monitor_can_read, monitor_qmp_read, monitor_qmp_event, -NULL , &mon->common,NULL , true); + monitor_qmp_change, &mon->common,NULL , true);monitor_list_append (&mon->common); } }Regards,
Daniel
--|: 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 · 2 lines
Best Regards -Li
Hi
Quoted 40 lines · Li Zhang
From: Li Zhang <[email protected]>
When executing the QMP commands "chardev-change" to change the backend device to socket, it will cause a segment fault because it assumes
chr->labelas non-NULL in functionyank_register_instance. The functionqmp_chardev_changecallschardev_new, which label is NULL when creating a new chardev. The label will be passed toyank_register_instancewhich causes a segment fault. The callchain is as the following:chardev_new -> qemu_char_open -> cc->open -> qmp_chardev_open_socket -> yank_register_instanceSigned-off-by Li Zhang <[email protected]>--- chardev/char-socket.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)chardev/char-socket.c +5
-3@@ -1421,10 +1421,12 @@ static void qmp_chardev_open_socket(Chardev *chr,qemu_chr_set_feature (chr,QEMU_CHAR_FEATURE_FD_PASS ); } -if (!yank_register_instance (CHARDEV_YANK_INSTANCE (chr->label), errp)) { -return ; +if (chr->label) { +if (!yank_register_instance (CHARDEV_YANK_INSTANCE (chr->label), errp)) { +return ; + } + s->registered_yank = true; } - s->registered_yank = true;
Quoted 3 lines
/* be isn't opened until we get a connection */
*be_opened= false
Looks wrong to me, the new chardev will get the same label, and it should still be possible to call the yank functions then. The registration logic needs to be reworked during chardev-change.
Signature · 1 line
Marc-André Lureau
Hi Marc-André,
The new chardev can get the same label. It is assigned after the function
ChardevReturn *qmp_chardev_change(const char *id, ChardevBackend *backend,
Error **errp)
{
.....
chr_new = chardev_new(NULL, object_class_get_name(OBJECT_CLASS(cc)),
backend, chr->gcontext, errp);
if (!chr_new) {
return NULL;
}
chr_new->label = g_strdup(id);
if (chr->be_open && !chr_new->be_open) {
qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
closed_sent = true;
}
chr->be = NULL;
qemu_chr_fe_init(be, chr_new, &error_abort);
.....
}It passes parameter NULL in chardev_new, I think it may be because the old chardev isn't released yet.
It will cause duplicated problems. I need to consider this logic to see if it can be changed.
Thanks
Li
Quoted 55 lines · Marc-André Lureau
Hi
Quoted 40 lines · Li Zhang
From: Li Zhang <[email protected]>
When executing the QMP commands "chardev-change" to change the backend device to socket, it will cause a segment fault because it assumes
chr->labelas non-NULL in functionyank_register_instance. The functionqmp_chardev_changecallschardev_new, which label is NULL when creating a new chardev. The label will be passed toyank_register_instancewhich causes a segment fault. The callchain is as the following:chardev_new -> qemu_char_open -> cc->open -> qmp_chardev_open_socket -> yank_register_instanceSigned-off-by Li Zhang <[email protected]>--- chardev/char-socket.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)chardev/char-socket.c +5
-3@@ -1421,10 +1421,12 @@ static void qmp_chardev_open_socket(Chardev *chr,qemu_chr_set_feature (chr,QEMU_CHAR_FEATURE_FD_PASS ); } -if (!yank_register_instance (CHARDEV_YANK_INSTANCE (chr->label), errp)) { -return ; +if (chr->label) { +if (!yank_register_instance (CHARDEV_YANK_INSTANCE (chr->label), errp)) { +return ; + } + s->registered_yank = true; } - s->registered_yank = true;Quoted 3 lines
/* be isn't opened until we get a connection */
*be_opened= falseLooks wrong to me, the new chardev will get the same label, and it should still be possible to call the yank functions then. The registration logic needs to be reworked during chardev-change.
--
Marc-André Lureau
Hi Marc-André,
By looking into chardev and yank_register_function logic, this old chardev is registered according to the chardev label.
So it's been in yank_instance_list. yank instance only has a chardev label, and the new chardev's label is the same as the old chardev.
So it doesn't need to register it again when changing the chardev backend. Otherwise, it will report duplicated yank instances.
I think the chardev logic has no problems. And it works with yank functions.
Thanks
Li
Quoted 55 lines · Marc-André Lureau
Hi
Quoted 40 lines · Li Zhang
From: Li Zhang <[email protected]>
When executing the QMP commands "chardev-change" to change the backend device to socket, it will cause a segment fault because it assumes
chr->labelas non-NULL in functionyank_register_instance. The functionqmp_chardev_changecallschardev_new, which label is NULL when creating a new chardev. The label will be passed toyank_register_instancewhich causes a segment fault. The callchain is as the following:chardev_new -> qemu_char_open -> cc->open -> qmp_chardev_open_socket -> yank_register_instanceSigned-off-by Li Zhang <[email protected]>--- chardev/char-socket.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)chardev/char-socket.c +5
-3@@ -1421,10 +1421,12 @@ static void qmp_chardev_open_socket(Chardev *chr,qemu_chr_set_feature (chr,QEMU_CHAR_FEATURE_FD_PASS ); } -if (!yank_register_instance (CHARDEV_YANK_INSTANCE (chr->label), errp)) { -return ; +if (chr->label) { +if (!yank_register_instance (CHARDEV_YANK_INSTANCE (chr->label), errp)) { +return ; + } + s->registered_yank = true; } - s->registered_yank = true;Quoted 3 lines
/* be isn't opened until we get a connection */
*be_opened= falseLooks wrong to me, the new chardev will get the same label, and it should still be possible to call the yank functions then. The registration logic needs to be reworked during chardev-change.
--
Marc-André Lureau
Hi
Quoted 12 lines · Li Zhang
Hi Marc-André,
By looking into chardev and
yank_register_functionlogic, this old chardev is registered according to the chardev label.
So it's been inyank_instance_list. yank instance only has a chardev label, and the new chardev's label is the same as the old chardev. So it doesn't need to register it again when changing the chardev backend. Otherwise, it will report duplicated yank instances.
I think the chardev logic has no problems. And it works with yank functions.
The previous instance is being removed with yank_unregister_instance() during object_unparent(). The new instance is not registered.
That scenario deserves tests. (it's a shame there are no tests for yank ...)
Quoted 62 lines
Thanks
LiQuoted 55 lines · Marc-André Lureau
Hi
Quoted 40 lines · Li Zhang
From: Li Zhang <[email protected]>
When executing the QMP commands "chardev-change" to change the backend device to socket, it will cause a segment fault because it assumes
chr->labelas non-NULL in functionyank_register_instance. The functionqmp_chardev_changecallschardev_new, which label is NULL when creating a new chardev. The label will be passed toyank_register_instancewhich causes a segment fault. The callchain is as the following:chardev_new -> qemu_char_open -> cc->open -> qmp_chardev_open_socket -> yank_register_instanceSigned-off-by Li Zhang <[email protected]>--- chardev/char-socket.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)chardev/char-socket.c +5
-3@@ -1421,10 +1421,12 @@ static void qmp_chardev_open_socket(Chardev *chr,qemu_chr_set_feature (chr,QEMU_CHAR_FEATURE_FD_PASS ); } -if (!yank_register_instance (CHARDEV_YANK_INSTANCE (chr->label), errp)) { -return ; +if (chr->label) { +if (!yank_register_instance (CHARDEV_YANK_INSTANCE (chr->label), errp)) { +return ; + } + s->registered_yank = true; } - s->registered_yank = true;Quoted 3 lines
/* be isn't opened until we get a connection */
*be_opened= falseLooks wrong to me, the new chardev will get the same label, and it should still be possible to call the yank functions then. The registration logic needs to be reworked during chardev-change.
--
Marc-André Lureau
Signature · 1 line
Marc-André Lureau
Hi Marc-André,
Hi Marc-André,
Ah, you are right. For some scenarios, it is not registered and registered for some scenarios.
If the previous chardev is not socket, it won't be registered either. There are still problems.
Quoted 91 lines · Marc-André Lureau
Hi
Quoted 12 lines · Li Zhang
Hi Marc-André,
By looking into chardev and
yank_register_functionlogic, this old chardev is registered according to the chardev label.
So it's been inyank_instance_list. yank instance only has a chardev label, and the new chardev's label is the same as the old chardev. So it doesn't need to register it again when changing the chardev backend. Otherwise, it will report duplicated yank instances. I think the chardev logic has no problems. And it works with yank functions.The previous instance is being removed with
yank_unregister_instance()duringobject_unparent(). The new instance is not registered.That scenario deserves tests. (it's a shame there are no tests for yank ...)
Quoted 63 lines
Thanks
LiQuoted 56 lines · Marc-André Lureau
Hi
Quoted 41 lines · Li Zhang
From: Li Zhang <[email protected]>
When executing the QMP commands "chardev-change" to change the backend device to socket, it will cause a segment fault because it assumes
chr->labelas non-NULL in functionyank_register_instance. The functionqmp_chardev_changecallschardev_new, which label is NULL when creating a new chardev. The label will be passed toyank_register_instancewhich causes a segment fault. The callchain is as the following:chardev_new -> qemu_char_open -> cc->open -> qmp_chardev_open_socket -> yank_register_instanceSigned-off-by Li Zhang <[email protected]>--- chardev/char-socket.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)chardev/char-socket.c +5
-3@@ -1421,10 +1421,12 @@ static void qmp_chardev_open_socket(Chardev *chr,qemu_chr_set_feature (chr,QEMU_CHAR_FEATURE_FD_PASS ); } -if (!yank_register_instance (CHARDEV_YANK_INSTANCE (chr->label), errp)) { -return ; +if (chr->label) { +if (!yank_register_instance (CHARDEV_YANK_INSTANCE (chr->label), errp)) { +return ; + } + s->registered_yank = true; } - s->registered_yank = true;Quoted 3 lines
/* be isn't opened until we get a connection */
*be_opened= falseLooks wrong to me, the new chardev will get the same label, and it should still be possible to call the yank functions then. The registration logic needs to be reworked during chardev-change.
--
Marc-André Lureau--
Marc-André Lureau
Quoted 9 lines · On Mon, 15 Mar 2021 18:06:35 +0100 Li Zhang <[email protected]> wrote:
From: Li Zhang <[email protected]>
When executing the QMP commands "chardev-change" to change the backend device to socket, it will cause a segment fault because it assumes
chr->labelas non-NULL in functionyank_register_instance. The functionqmp_chardev_changecallschardev_new, which label is NULL when creating a new chardev. The label will be passed toyank_register_instancewhich causes a segment fault. The callchain is as the following:
Quoted 5 lines
chardev_new ->
qemu_char_open ->
cc->open ->
qmp_chardev_open_socket ->
yank_register_instanceOh, I didn't consider the chardev-change case. I'll look into it.
Regards,
Lukas Straub
Looks like a bug fix. Lukas, can you take care of it in time for 6.0?
Quoted 40 lines · Li Zhang
From: Li Zhang <[email protected]>
When executing the QMP commands "chardev-change" to change the backend device to socket, it will cause a segment fault because it assumes
chr->labelas non-NULL in functionyank_register_instance. The functionqmp_chardev_changecallschardev_new, which label is NULL when creating a new chardev. The label will be passed toyank_register_instancewhich causes a segment fault. The callchain is as the following:chardev_new -> qemu_char_open -> cc->open -> qmp_chardev_open_socket -> yank_register_instanceSigned-off-by Li Zhang <[email protected]>--- chardev/char-socket.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)chardev/char-socket.c +5
-3@@ -1421,10 +1421,12 @@ static void qmp_chardev_open_socket(Chardev *chr,qemu_chr_set_feature (chr,QEMU_CHAR_FEATURE_FD_PASS ); } -if (!yank_register_instance (CHARDEV_YANK_INSTANCE (chr->label), errp)) { -return ; +if (chr->label) { +if (!yank_register_instance (CHARDEV_YANK_INSTANCE (chr->label), errp)) { +return ; + } + s->registered_yank = true; } - s->registered_yank = true;/* be isn't opened until we get a connection */ *be_opened = false;
Quoted 2 lines · On Fri, 26 Mar 2021 15:41:11 +0100 Markus Armbruster <[email protected]> wrote:
Looks like a bug fix. Lukas, can you take care of it in time for 6.0?
Yeah, this patch only fixes a symptom, but not the core cause of the bug. I have already written patches that fix the bugs inclusive test-cases:
https://lore.kernel.org/qemu-devel/[email protected]/
Regards,
Lukas Straub
Quoted 9 lines · Lukas Straub
Quoted 2 lines · On Fri, 26 Mar 2021 15:41:11 +0100 Markus Armbruster <[email protected]> wrote:
Looks like a bug fix. Lukas, can you take care of it in time for 6.0?
Yeah, this patch only fixes a symptom, but not the core cause of the bug. I have already written patches that fix the bugs inclusive test-cases:
https://lore.kernel.org/qemu-devel/[email protected]/
Awesome! I didn't make the connection. I trust you'll take care of getting the fixes merged :)