From nobody Mon May 6 13:47:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503471259339332.19086663750386; Tue, 22 Aug 2017 23:54:19 -0700 (PDT) Received: from localhost ([::1]:42141 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkPYP-0003n2-KL for importer@patchew.org; Wed, 23 Aug 2017 02:54:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49713) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkPVi-0001wA-Dx for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:51:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkPVh-0007Ma-OM for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:51:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51062) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkPVh-0007MD-IL for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:51:29 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 827C7821C3; Wed, 23 Aug 2017 06:51:28 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-14-103.nay.redhat.com [10.66.14.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36C6A78363; Wed, 23 Aug 2017 06:51:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 827C7821C3 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 23 Aug 2017 14:51:04 +0800 Message-Id: <1503471071-2233-2-git-send-email-peterx@redhat.com> In-Reply-To: <1503471071-2233-1-git-send-email-peterx@redhat.com> References: <1503471071-2233-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 23 Aug 2017 06:51:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v2 1/8] monitor: move skip_flush into monitor_data_init X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Fam Zheng , Juan Quintela , Markus Armbruster , peterx@redhat.com, mdroth@linux.vnet.ibm.com, Paolo Bonzini , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It's part of the data init. Collect it. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- monitor.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/monitor.c b/monitor.c index e0f8801..7c90df7 100644 --- a/monitor.c +++ b/monitor.c @@ -568,13 +568,14 @@ static void monitor_qapi_event_init(void) =20 static void handle_hmp_command(Monitor *mon, const char *cmdline); =20 -static void monitor_data_init(Monitor *mon) +static void monitor_data_init(Monitor *mon, bool skip_flush) { memset(mon, 0, sizeof(Monitor)); qemu_mutex_init(&mon->out_lock); mon->outbuf =3D qstring_new(); /* Use *mon_cmds by default. */ mon->cmd_table =3D mon_cmds; + mon->skip_flush =3D skip_flush; } =20 static void monitor_data_destroy(Monitor *mon) @@ -594,8 +595,7 @@ char *qmp_human_monitor_command(const char *command_lin= e, bool has_cpu_index, char *output =3D NULL; Monitor *old_mon, hmp; =20 - monitor_data_init(&hmp); - hmp.skip_flush =3D true; + monitor_data_init(&hmp, true); =20 old_mon =3D cur_mon; cur_mon =3D &hmp; @@ -4098,7 +4098,7 @@ void monitor_init(Chardev *chr, int flags) } =20 mon =3D g_malloc(sizeof(*mon)); - monitor_data_init(mon); + monitor_data_init(mon, false); =20 qemu_chr_fe_init(&mon->chr, chr, &error_abort); mon->flags =3D flags; --=20 2.7.4 From nobody Mon May 6 13:47:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503471196352235.37815045896264; Tue, 22 Aug 2017 23:53:16 -0700 (PDT) Received: from localhost ([::1]:42140 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkPXP-0002zf-6s for importer@patchew.org; Wed, 23 Aug 2017 02:53:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkPVn-00020P-BJ for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:51:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkPVl-0007PD-RU for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:51:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39010) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkPVl-0007Om-Hs for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:51:33 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C0FE37EEC; Wed, 23 Aug 2017 06:51:32 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-14-103.nay.redhat.com [10.66.14.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC71784FCD; Wed, 23 Aug 2017 06:51:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7C0FE37EEC Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 23 Aug 2017 14:51:05 +0800 Message-Id: <1503471071-2233-3-git-send-email-peterx@redhat.com> In-Reply-To: <1503471071-2233-1-git-send-email-peterx@redhat.com> References: <1503471071-2233-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 23 Aug 2017 06:51:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v2 2/8] monitor: allow monitor to create thread to poll X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Fam Zheng , Juan Quintela , Markus Armbruster , peterx@redhat.com, mdroth@linux.vnet.ibm.com, Paolo Bonzini , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Firstly, introduce Monitor.use_thread, and set it for monitors that are using non-mux typed backend chardev. We only do this for monitors, so mux-typed chardevs are not suitable (when it connects to, e.g., serials and the monitor together). When use_thread is set, we create standalone thread to poll the monitor events, isolated from the main loop thread. Here we still need to take the BQL before dispatching the tasks since some of the monitor commands are not allowed to execute without the protection of BQL. Then this gives us the chance to avoid taking the BQL for some monitor commands in the future. * Why this change? We need these per-monitor threads to make sure we can have at least one monitor that will never stuck (that can receive further monitor commands). * So when will monitors stuck? And, how do they stuck? After we have postcopy and remote page faults, it's simple to achieve a stuck in the monitor (which is also a stuck in main loop thread): (1) Monitor deadlock on BQL As we may know, when postcopy is running on destination VM, the vcpu threads can stuck merely any time as long as it tries to access an uncopied guest page. Meanwhile, when the stuck happens, it is possible that the vcpu thread is holding the BQL. If the page fault is not handled quickly, you'll find that monitors stop working, which is trying to take the BQL. If the page fault cannot be handled correctly (one case is a paused postcopy, when network is temporarily down), monitors will hang forever. Without current patch, that means the main loop hanged. We'll never find a way to talk to VM again. (2) Monitor tries to run codes page-faulted vcpus The HMP command "info cpus" is one of the good example - it tries to kick all the vcpus and sync status from them. However, if there is any vcpu that stuck at an unhandled page fault, it can never achieve the sync, then the HMP hangs. Again, it hangs the main loop thread as well. After either (1) or (2), we can see the deadlock problem: - On one hand, if monitor hangs, we cannot do the postcopy recovery, because postcopy recovery needs user to specify new listening port on destination monitor. - On the other hand, if we cannot recover the paused postcopy, then page faults cannot be serviced, and the monitors will possibly hang forever then. * How this patch helps? - Firstly, we'll have our own thread for each dedicated monitor (or say, the backend chardev is only used for monitor), so even main loop thread hangs (it is always possible), this monitor thread may still survive. - Not all monitor commands need the BQL. We can selectively take the BQL (depends on which command we are running) to avoid waiting on a page-faulted vcpu thread that has taken the BQL (this will be done in following up patches). Signed-off-by: Peter Xu --- monitor.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++= ---- qapi/qmp-dispatch.c | 15 +++++++++++ 2 files changed, 85 insertions(+), 5 deletions(-) diff --git a/monitor.c b/monitor.c index 7c90df7..3d4ecff 100644 --- a/monitor.c +++ b/monitor.c @@ -36,6 +36,8 @@ #include "net/net.h" #include "net/slirp.h" #include "chardev/char-fe.h" +#include "chardev/char-mux.h" +#include "chardev/char-io.h" #include "ui/qemu-spice.h" #include "sysemu/numa.h" #include "monitor/monitor.h" @@ -190,6 +192,8 @@ struct Monitor { int flags; int suspend_cnt; bool skip_flush; + /* Whether the monitor wants to be polled in standalone thread */ + bool use_thread; =20 QemuMutex out_lock; QString *outbuf; @@ -206,6 +210,11 @@ struct Monitor { mon_cmd_t *cmd_table; QLIST_HEAD(,mon_fd_t) fds; QLIST_ENTRY(Monitor) entry; + + /* Only used when "use_thread" is used */ + QemuThread mon_thread; + GMainContext *mon_context; + GMainLoop *mon_loop; }; =20 /* QMP checker flags */ @@ -568,7 +577,7 @@ static void monitor_qapi_event_init(void) =20 static void handle_hmp_command(Monitor *mon, const char *cmdline); =20 -static void monitor_data_init(Monitor *mon, bool skip_flush) +static void monitor_data_init(Monitor *mon, bool skip_flush, bool use_thre= ad) { memset(mon, 0, sizeof(Monitor)); qemu_mutex_init(&mon->out_lock); @@ -576,10 +585,34 @@ static void monitor_data_init(Monitor *mon, bool skip= _flush) /* Use *mon_cmds by default. */ mon->cmd_table =3D mon_cmds; mon->skip_flush =3D skip_flush; + mon->use_thread =3D use_thread; + if (use_thread) { + /* + * For monitors that use isolated threads, they'll need their + * own GMainContext and GMainLoop. Otherwise, these pointers + * will be NULL, which means the default context will be used. + */ + mon->mon_context =3D g_main_context_new(); + mon->mon_loop =3D g_main_loop_new(mon->mon_context, TRUE); + } } =20 static void monitor_data_destroy(Monitor *mon) { + /* Destroy the thread first if there is */ + if (mon->use_thread) { + /* Notify the per-monitor thread to quit. */ + g_main_loop_quit(mon->mon_loop); + /* + * Make sure the context will get the quit message since it's + * in another thread. Without this, it may not be able to + * respond to the quit message immediately. + */ + g_main_context_wakeup(mon->mon_context); + qemu_thread_join(&mon->mon_thread); + g_main_loop_unref(mon->mon_loop); + g_main_context_unref(mon->mon_context); + } qemu_chr_fe_deinit(&mon->chr, false); if (monitor_is_qmp(mon)) { json_message_parser_destroy(&mon->qmp.parser); @@ -595,7 +628,7 @@ char *qmp_human_monitor_command(const char *command_lin= e, bool has_cpu_index, char *output =3D NULL; Monitor *old_mon, hmp; =20 - monitor_data_init(&hmp, true); + monitor_data_init(&hmp, true, false); =20 old_mon =3D cur_mon; cur_mon =3D &hmp; @@ -3101,6 +3134,11 @@ static void handle_hmp_command(Monitor *mon, const c= har *cmdline) { QDict *qdict; const mon_cmd_t *cmd; + /* + * If we haven't take the BQL (when called by per-monitor + * threads), we need to take care of the BQL on our own. + */ + bool take_bql =3D !qemu_mutex_iothread_locked(); =20 trace_handle_hmp_command(mon, cmdline); =20 @@ -3116,7 +3154,16 @@ static void handle_hmp_command(Monitor *mon, const c= har *cmdline) return; } =20 + if (take_bql) { + qemu_mutex_lock_iothread(); + } + cmd->cmd(mon, qdict); + + if (take_bql) { + qemu_mutex_unlock_iothread(); + } + QDECREF(qdict); } =20 @@ -4086,6 +4133,15 @@ static void __attribute__((constructor)) monitor_loc= k_init(void) qemu_mutex_init(&monitor_lock); } =20 +static void *monitor_thread(void *data) +{ + Monitor *mon =3D data; + + g_main_loop_run(mon->mon_loop); + + return NULL; +} + void monitor_init(Chardev *chr, int flags) { static int is_first_init =3D 1; @@ -4098,7 +4154,9 @@ void monitor_init(Chardev *chr, int flags) } =20 mon =3D g_malloc(sizeof(*mon)); - monitor_data_init(mon, false); + + /* For non-mux typed monitors, we create dedicated threads. */ + monitor_data_init(mon, false, !CHARDEV_IS_MUX(chr)); =20 qemu_chr_fe_init(&mon->chr, chr, &error_abort); mon->flags =3D flags; @@ -4112,12 +4170,19 @@ void monitor_init(Chardev *chr, int flags) =20 if (monitor_is_qmp(mon)) { qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_qmp_= read, - monitor_qmp_event, NULL, mon, NULL, true); + monitor_qmp_event, NULL, mon, + mon->mon_context, true); qemu_chr_fe_set_echo(&mon->chr, true); json_message_parser_init(&mon->qmp.parser, handle_qmp_command); } else { qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_read, - monitor_event, NULL, mon, NULL, true); + monitor_event, NULL, mon, + mon->mon_context, true); + } + + if (mon->use_thread) { + qemu_thread_create(&mon->mon_thread, chr->label, monitor_thread, + mon, QEMU_THREAD_JOINABLE); } =20 qemu_mutex_lock(&monitor_lock); diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 5ad36f8..3b6b224 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -19,6 +19,7 @@ #include "qapi/qmp/qjson.h" #include "qapi-types.h" #include "qapi/qmp/qerror.h" +#include "qemu/main-loop.h" =20 static QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp) { @@ -75,6 +76,11 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, QO= bject *request, QDict *args, *dict; QmpCommand *cmd; QObject *ret =3D NULL; + /* + * If we haven't take the BQL (when called by per-monitor + * threads), we need to take care of the BQL on our own. + */ + bool take_bql =3D !qemu_mutex_iothread_locked(); =20 dict =3D qmp_dispatch_check_obj(request, errp); if (!dict) { @@ -101,7 +107,16 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, = QObject *request, QINCREF(args); } =20 + if (take_bql) { + qemu_mutex_lock_iothread(); + } + cmd->fn(args, &ret, &local_err); + + if (take_bql) { + qemu_mutex_unlock_iothread(); + } + if (local_err) { error_propagate(errp, local_err); } else if (cmd->options & QCO_NO_SUCCESS_RESP) { --=20 2.7.4 From nobody Mon May 6 13:47:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15034713337621022.6069465205283; Tue, 22 Aug 2017 23:55:33 -0700 (PDT) Received: from localhost ([::1]:42152 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkPZc-0004qC-Em for importer@patchew.org; Wed, 23 Aug 2017 02:55:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49771) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkPVt-00024W-9p for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:51:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkPVp-0007QR-Dd for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:51:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37084) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkPVp-0007QF-7W for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:51:37 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 310924A6F4; Wed, 23 Aug 2017 06:51:36 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-14-103.nay.redhat.com [10.66.14.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5715828DA; Wed, 23 Aug 2017 06:51:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 310924A6F4 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 23 Aug 2017 14:51:06 +0800 Message-Id: <1503471071-2233-4-git-send-email-peterx@redhat.com> In-Reply-To: <1503471071-2233-1-git-send-email-peterx@redhat.com> References: <1503471071-2233-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 23 Aug 2017 06:51:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v2 3/8] char-io: fix possible risk on IOWatchPoll X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Fam Zheng , Juan Quintela , Markus Armbruster , peterx@redhat.com, mdroth@linux.vnet.ibm.com, Paolo Bonzini , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is not a problem if we are only having one single loop thread like before. However, after per-monitor thread is introduced, this is not true any more, and the risk can happen. The risk can be triggered with "make check -j8" sometimes: qemu-system-x86_64: /root/git/qemu/chardev/char-io.c:91: io_watch_poll_finalize: Assertion `iwp->src =3D=3D NULL' failed. This patch keeps the reference for the watch object when creating in io_add_watch_poll(), so that the object will never be released in the context main loop, especially when the context loop is running in another standalone thread. Meanwhile, when we want to remove the watch object, we always first detach the watch object from its owner context, then we continue with the cleanup. Without this patch, calling io_remove_watch_poll() in main loop thread is not thread-safe, since the other per-monitor thread may be modifying the watch object at the same time. Signed-off-by: Peter Xu Reviewed-by: Marc-Andr=C3=A9 Lureau --- chardev/char-io.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/chardev/char-io.c b/chardev/char-io.c index f810524..5c52c40 100644 --- a/chardev/char-io.c +++ b/chardev/char-io.c @@ -122,7 +122,6 @@ GSource *io_add_watch_poll(Chardev *chr, g_free(name); =20 g_source_attach(&iwp->parent, context); - g_source_unref(&iwp->parent); return (GSource *)iwp; } =20 @@ -131,12 +130,24 @@ static void io_remove_watch_poll(GSource *source) IOWatchPoll *iwp; =20 iwp =3D io_watch_poll_from_source(source); + + /* + * Here the order of destruction really matters. We need to first + * detach the IOWatchPoll object from the context (which may still + * be running in another loop thread), only after that could we + * continue to operate on iwp->src, or there may be risk condition + * between current thread and the context loop thread. + * + * Let's blame the glib bug mentioned in commit 2b3167 (again) for + * this extra complexity. + */ + g_source_destroy(&iwp->parent); if (iwp->src) { g_source_destroy(iwp->src); g_source_unref(iwp->src); iwp->src =3D NULL; } - g_source_destroy(&iwp->parent); + g_source_unref(&iwp->parent); } =20 void remove_fd_in_watch(Chardev *chr) --=20 2.7.4 From nobody Mon May 6 13:47:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503471490288351.9263014435827; Tue, 22 Aug 2017 23:58:10 -0700 (PDT) Received: from localhost ([::1]:42161 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkPc6-00079c-W1 for importer@patchew.org; Wed, 23 Aug 2017 02:58:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkPW0-0002CQ-Bc for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:51:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkPVy-0007UB-Ns for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:51:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35714) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkPVy-0007Tv-EQ for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:51:46 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6074681E19; Wed, 23 Aug 2017 06:51:45 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-14-103.nay.redhat.com [10.66.14.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9843678363; Wed, 23 Aug 2017 06:51:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6074681E19 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 23 Aug 2017 14:51:07 +0800 Message-Id: <1503471071-2233-5-git-send-email-peterx@redhat.com> In-Reply-To: <1503471071-2233-1-git-send-email-peterx@redhat.com> References: <1503471071-2233-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 23 Aug 2017 06:51:45 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v2 4/8] QAPI: new QMP command option "without-bql" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Fam Zheng , Juan Quintela , Markus Armbruster , peterx@redhat.com, mdroth@linux.vnet.ibm.com, Paolo Bonzini , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Introducing this new parameter for QMP commands in general to mark out when the command does not need BQL. Normally QMP command executions are done with the protection of BQL in QEMU. However the truth is that not all the QMP commands require the BQL. This new parameter provides a way to allow QMP commands to run in parallel when possible, without the contention on the BQL. Since the default value of "without-bql" is still false, so now all QMP commands are still protected by BQL still. Signed-off-by: Peter Xu --- docs/devel/qapi-code-gen.txt | 10 +++++++++- include/qapi/qmp/dispatch.h | 1 + qapi/qmp-dispatch.c | 11 +++++++++++ scripts/qapi-commands.py | 18 +++++++++++++----- scripts/qapi-introspect.py | 2 +- scripts/qapi.py | 15 ++++++++++----- scripts/qapi2texi.py | 2 +- tests/qapi-schema/test-qapi.py | 2 +- 8 files changed, 47 insertions(+), 14 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 9903ac4..4960d00 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -556,7 +556,8 @@ following example objects: =20 Usage: { 'command': STRING, '*data': COMPLEX-TYPE-NAME-OR-DICT, '*returns': TYPE-NAME, '*boxed': true, - '*gen': false, '*success-response': false } + '*gen': false, '*success-response': false, + '*without-bql': false } =20 Commands are defined by using a dictionary containing several members, where three members are most common. The 'command' member is a @@ -636,6 +637,13 @@ possible, the command expression should include the op= tional key 'success-response' with boolean value false. So far, only QGA makes use of this member. =20 +Most of the commands require the Big QEMU Lock (BQL) be held during +execution. However, there is a small subset of the commands that may +not really need BQL at all. To mark out this kind of commands, we can +specify "without-bql" to "true". This parameter is only a hint for +internal QMP implementation to provide possiblility to allow commands +be run in parallel, or reduce the contention of the lock. Users of QMP +should not really be aware of such information. =20 =3D=3D=3D Events =3D=3D=3D =20 diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index 20578dc..ec5c620 100644 --- a/include/qapi/qmp/dispatch.h +++ b/include/qapi/qmp/dispatch.h @@ -23,6 +23,7 @@ typedef enum QmpCommandOptions { QCO_NO_OPTIONS =3D 0x0, QCO_NO_SUCCESS_RESP =3D 0x1, + QCO_WITHOUT_BQL =3D 0x2, } QmpCommandOptions; =20 typedef struct QmpCommand diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 3b6b224..b7fba5e 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -107,6 +107,17 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, = QObject *request, QINCREF(args); } =20 + if (cmd->options & QCO_WITHOUT_BQL) { + /* + * If this command can live without BQL, then we don't take + * it. One thing to mention: we may have already taken the + * BQL before reaching here. If so, we just keep it. So + * generally speaking we are trying our best on reducing the + * contention of BQL. + */ + take_bql =3D false; + } + if (take_bql) { qemu_mutex_lock_iothread(); } diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index 974d0a4..155a0a4 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -192,10 +192,17 @@ out: return ret =20 =20 -def gen_register_command(name, success_response): - options =3D 'QCO_NO_OPTIONS' +def gen_register_command(name, success_response, without_bql): + options =3D [] + if not success_response: - options =3D 'QCO_NO_SUCCESS_RESP' + options +=3D ['QCO_NO_SUCCESS_RESP'] + if without_bql: + options +=3D ['QCO_WITHOUT_BQL'] + + if not options: + options =3D ['QCO_NO_OPTIONS'] + options =3D " | ".join(options) =20 ret =3D mcgen(''' qmp_register_command(cmds, "%(name)s", @@ -241,7 +248,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor): self._visited_ret_types =3D None =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, without_bql): if not gen: return self.decl +=3D gen_command_decl(name, arg_type, boxed, ret_type) @@ -250,7 +257,8 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor): self.defn +=3D gen_marshal_output(ret_type) self.decl +=3D gen_marshal_decl(name) self.defn +=3D gen_marshal(name, arg_type, boxed, ret_type) - self._regy +=3D gen_register_command(name, success_response) + self._regy +=3D gen_register_command(name, success_response, + without_bql) =20 =20 (input_file, output_dir, do_c, do_h, prefix, opts) =3D parse_command_line() diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py index 032bcea..a523544 100644 --- a/scripts/qapi-introspect.py +++ b/scripts/qapi-introspect.py @@ -154,7 +154,7 @@ const char %(c_name)s[] =3D %(c_string)s; for m in variants.variants]}) =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, without_bql): arg_type =3D arg_type or self._schema.the_empty_object_type ret_type =3D ret_type or self._schema.the_empty_object_type self._gen_json(name, 'command', diff --git a/scripts/qapi.py b/scripts/qapi.py index 8aa2775..3951143 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -920,7 +920,8 @@ def check_exprs(exprs): elif 'command' in expr: meta =3D 'command' check_keys(expr_elem, 'command', [], - ['data', 'returns', 'gen', 'success-response', 'box= ed']) + ['data', 'returns', 'gen', 'success-response', + 'boxed', 'without-bql']) elif 'event' in expr: meta =3D 'event' check_keys(expr_elem, 'event', [], ['data', 'boxed']) @@ -1031,7 +1032,7 @@ class QAPISchemaVisitor(object): pass =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, without_bql): pass =20 def visit_event(self, name, info, arg_type, boxed): @@ -1398,7 +1399,7 @@ class QAPISchemaAlternateType(QAPISchemaType): =20 class QAPISchemaCommand(QAPISchemaEntity): def __init__(self, name, info, doc, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, without_bql): QAPISchemaEntity.__init__(self, name, info, doc) assert not arg_type or isinstance(arg_type, str) assert not ret_type or isinstance(ret_type, str) @@ -1408,6 +1409,7 @@ class QAPISchemaCommand(QAPISchemaEntity): self.ret_type =3D None self.gen =3D gen self.success_response =3D success_response + self.without_bql =3D without_bql self.boxed =3D boxed =20 def check(self, schema): @@ -1432,7 +1434,8 @@ class QAPISchemaCommand(QAPISchemaEntity): def visit(self, visitor): visitor.visit_command(self.name, self.info, self.arg_type, self.ret_type, - self.gen, self.success_response, self.boxed) + self.gen, self.success_response, + self.boxed, self.without_bql) =20 =20 class QAPISchemaEvent(QAPISchemaEntity): @@ -1639,6 +1642,7 @@ class QAPISchema(object): rets =3D expr.get('returns') gen =3D expr.get('gen', True) success_response =3D expr.get('success-response', True) + without_bql =3D expr.get('without-bql', False) boxed =3D expr.get('boxed', False) if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( @@ -1647,7 +1651,8 @@ class QAPISchema(object): assert len(rets) =3D=3D 1 rets =3D self._make_array_type(rets[0], info) self._def_entity(QAPISchemaCommand(name, info, doc, data, rets, - gen, success_response, boxed)) + gen, success_response, + boxed, without_bql)) =20 def _def_event(self, expr, info, doc): name =3D expr['event'] diff --git a/scripts/qapi2texi.py b/scripts/qapi2texi.py index a317526..659bd83 100755 --- a/scripts/qapi2texi.py +++ b/scripts/qapi2texi.py @@ -236,7 +236,7 @@ class QAPISchemaGenDocVisitor(qapi.QAPISchemaVisitor): body=3Dtexi_entity(doc, 'Members')) =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, without_bql): doc =3D self.cur_doc if self.out: self.out +=3D '\n' diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index c7724d3..15aff29 100644 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -36,7 +36,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): self._print_variants(variants) =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, without_bql): print 'command %s %s -> %s' % \ (name, arg_type and arg_type.name, ret_type and ret_type.name) print ' gen=3D%s success_response=3D%s boxed=3D%s' % \ --=20 2.7.4 From nobody Mon May 6 13:47:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503471403103713.9452450007772; Tue, 22 Aug 2017 23:56:43 -0700 (PDT) Received: from localhost ([::1]:42154 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkPai-0005pF-HL for importer@patchew.org; Wed, 23 Aug 2017 02:56:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49812) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkPW4-0002Ds-T0 for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:51:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkPW4-0007We-7a for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:51:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36026) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkPW4-0007WM-1C for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:51:52 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F33698124A; Wed, 23 Aug 2017 06:51:50 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-14-103.nay.redhat.com [10.66.14.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 62AE584FD8; Wed, 23 Aug 2017 06:51:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F33698124A Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 23 Aug 2017 14:51:08 +0800 Message-Id: <1503471071-2233-6-git-send-email-peterx@redhat.com> In-Reply-To: <1503471071-2233-1-git-send-email-peterx@redhat.com> References: <1503471071-2233-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 23 Aug 2017 06:51:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v2 5/8] hmp: support "without_bql" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Fam Zheng , Juan Quintela , Markus Armbruster , peterx@redhat.com, mdroth@linux.vnet.ibm.com, Paolo Bonzini , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Introducing new option "without_bql" for HMP commands. It works just like QMP "without-bql", but for HMP commands. Signed-off-by: Peter Xu --- monitor.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/monitor.c b/monitor.c index 3d4ecff..c26c797 100644 --- a/monitor.c +++ b/monitor.c @@ -125,6 +125,8 @@ typedef struct mon_cmd_t { const char *args_type; const char *params; const char *help; + /* Whether this command can be run without taking BQL? */ + bool without_bql; void (*cmd)(Monitor *mon, const QDict *qdict); /* @sub_table is a list of 2nd level of commands. If it does not exist, * cmd should be used. If it exists, sub_table[?].cmd should be @@ -3154,6 +3156,14 @@ static void handle_hmp_command(Monitor *mon, const c= har *cmdline) return; } =20 + if (cmd->without_bql) { + /* + * This is similar to QMP's "without-bql". See comments in + * do_qmp_dispatch(). + */ + take_bql =3D false; + } + if (take_bql) { qemu_mutex_lock_iothread(); } --=20 2.7.4 From nobody Mon May 6 13:47:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503471604420279.18395534227136; Wed, 23 Aug 2017 00:00:04 -0700 (PDT) Received: from localhost ([::1]:42172 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkPdz-0000Xm-9S for importer@patchew.org; Wed, 23 Aug 2017 03:00:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49834) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkPW9-0002IH-E7 for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:51:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkPW8-0007Yd-Nt for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:51:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33446) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkPW8-0007Y6-HA for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:51:56 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 71A2F7E451; Wed, 23 Aug 2017 06:51:55 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-14-103.nay.redhat.com [10.66.14.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 686C878363; Wed, 23 Aug 2017 06:51:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 71A2F7E451 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 23 Aug 2017 14:51:09 +0800 Message-Id: <1503471071-2233-7-git-send-email-peterx@redhat.com> In-Reply-To: <1503471071-2233-1-git-send-email-peterx@redhat.com> References: <1503471071-2233-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 23 Aug 2017 06:51:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v2 6/8] migration: qmp: migrate_incoming don't need BQL X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Fam Zheng , Juan Quintela , Markus Armbruster , peterx@redhat.com, mdroth@linux.vnet.ibm.com, Paolo Bonzini , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Let "migrate-incoming" command be run without BQL. Then even if any thread hanged with BQL held, we can still run this command. Signed-off-by: Peter Xu --- qapi-schema.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qapi-schema.json b/qapi-schema.json index 802ea53..b55e73b 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3259,7 +3259,8 @@ # <- { "return": {} } # ## -{ 'command': 'migrate-incoming', 'data': {'uri': 'str' } } +{ 'command': 'migrate-incoming', 'data': {'uri': 'str' }, + 'without-bql': 'true' } =20 ## # @xen-save-devices-state: --=20 2.7.4 From nobody Mon May 6 13:47:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503471542875267.0577322156995; Tue, 22 Aug 2017 23:59:02 -0700 (PDT) Received: from localhost ([::1]:42166 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkPcz-00086K-Mp for importer@patchew.org; Wed, 23 Aug 2017 02:59:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49892) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkPWO-0002TP-5A for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:52:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkPWK-0007cL-8D for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:52:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39694) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkPWK-0007c0-1u for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:52:08 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ED6FCC047B6B; Wed, 23 Aug 2017 06:52:06 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-14-103.nay.redhat.com [10.66.14.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB4E178363; Wed, 23 Aug 2017 06:51:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ED6FCC047B6B Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 23 Aug 2017 14:51:10 +0800 Message-Id: <1503471071-2233-8-git-send-email-peterx@redhat.com> In-Reply-To: <1503471071-2233-1-git-send-email-peterx@redhat.com> References: <1503471071-2233-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 23 Aug 2017 06:52:07 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v2 7/8] migration: hmp: migrate_incoming don't need BQL X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Fam Zheng , Juan Quintela , Markus Armbruster , peterx@redhat.com, mdroth@linux.vnet.ibm.com, Paolo Bonzini , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Allow this command to run without BQL held. Signed-off-by: Peter Xu --- hmp-commands.hx | 1 + 1 file changed, 1 insertion(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index 1941e19..e8d8812 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -968,6 +968,7 @@ ETEXI .params =3D "uri", .help =3D "Continue an incoming migration from an -incoming = defer", .cmd =3D hmp_migrate_incoming, + .without_bql =3D true, }, =20 STEXI --=20 2.7.4 From nobody Mon May 6 13:47:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503471329720173.39268782482816; Tue, 22 Aug 2017 23:55:29 -0700 (PDT) Received: from localhost ([::1]:42147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkPZY-0004l9-HM for importer@patchew.org; Wed, 23 Aug 2017 02:55:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49903) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkPWO-0002U3-TQ for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:52:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkPWO-0007dX-56 for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:52:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34672) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkPWN-0007dH-VP for qemu-devel@nongnu.org; Wed, 23 Aug 2017 02:52:12 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DDDC383F42; Wed, 23 Aug 2017 06:52:10 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-14-103.nay.redhat.com [10.66.14.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F6C478363; Wed, 23 Aug 2017 06:52:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DDDC383F42 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 23 Aug 2017 14:51:11 +0800 Message-Id: <1503471071-2233-9-git-send-email-peterx@redhat.com> In-Reply-To: <1503471071-2233-1-git-send-email-peterx@redhat.com> References: <1503471071-2233-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 23 Aug 2017 06:52:11 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v2 8/8] migration: add incoming mgmt lock X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Fam Zheng , Juan Quintela , Markus Armbruster , peterx@redhat.com, mdroth@linux.vnet.ibm.com, Paolo Bonzini , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Now at least migrate_incoming can be run in parallel. Let's provide a migration lock to protect it. Signed-off-by: Peter Xu --- migration/migration.c | 6 ++++++ migration/migration.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index c3fe0ed..32058f7 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -145,6 +145,7 @@ MigrationIncomingState *migration_incoming_get_current(= void) mis_current.state =3D MIGRATION_STATUS_NONE; memset(&mis_current, 0, sizeof(MigrationIncomingState)); qemu_mutex_init(&mis_current.rp_mutex); + qemu_mutex_init(&mis_current.mgmt_mutex); qemu_event_init(&mis_current.main_thread_load_event, false); once =3D true; } @@ -1171,6 +1172,7 @@ void qmp_migrate_incoming(const char *uri, Error **er= rp) { Error *local_err =3D NULL; static bool once =3D true; + MigrationIncomingState *mis =3D migration_incoming_get_current(); =20 if (!deferred_incoming) { error_setg(errp, "For use with '-incoming defer'"); @@ -1180,8 +1182,12 @@ void qmp_migrate_incoming(const char *uri, Error **e= rrp) error_setg(errp, "The incoming migration has already been started"= ); } =20 + qemu_mutex_lock(&mis->mgmt_mutex); + qemu_start_incoming_migration(uri, &local_err); =20 + qemu_mutex_unlock(&mis->mgmt_mutex); + if (local_err) { error_propagate(errp, local_err); return; diff --git a/migration/migration.h b/migration/migration.h index 148c9fa..95f077b 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -58,6 +58,9 @@ struct MigrationIncomingState { /* The coroutine we should enter (back) after failover */ Coroutine *migration_incoming_co; QemuSemaphore colo_incoming_sem; + + /* Migration incoming management lock */ + QemuMutex mgmt_mutex; }; =20 MigrationIncomingState *migration_incoming_get_current(void); --=20 2.7.4