From nobody Sat May 4 18:36:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1571910161; cv=none; d=zoho.com; s=zohoarc; b=cXjpLvm8RsNjTfB0UJ/nWiJRNs8FSMbGJ4LaCohc7Fy80z2Ef8GVvHi/H3gJYh6xvsGTelj8SURyLTgHfE7X/iN4ZfU4FpRL8qOxpcprj2CCuyw/aqtAzE+99UGZ5hIdVrMuu0BeqlhFLQPxbQyR8zHxpvsisI0zprWc7pt1O/0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571910161; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=Di6K+RUsl62t+qzjH3vbfsieyL2Q5lQu4/UhiQBsWA4=; b=fWwxOc1v5uVDMbDPHM+qaCfP6gKlcX7i9qMGD36hs6BingGX8812ptcnbk9i+1hhCbdz+IWY9rfd9p6IdLJBYAfdNAU5kuvgfgPt6Dl2e6+CsM5VMkZGKCia0WTz5zxDIPXcqx7PKQfMWueLHjqqvoQoZpGnp0y1B679Gm7kQaY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571910161149475.30536172357677; Thu, 24 Oct 2019 02:42:41 -0700 (PDT) Received: from localhost ([::1]:35312 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNYob-00077g-HS for importer@patchew.org; Thu, 24 Oct 2019 04:49:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37480) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNYOC-0004SO-8D for qemu-devel@nongnu.org; Thu, 24 Oct 2019 04:22:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNYOA-0000lE-U9 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 04:22:35 -0400 Received: from proxmox-new.maurer-it.com ([212.186.127.180]:3405) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNYOA-0000jC-Mq; Thu, 24 Oct 2019 04:22:34 -0400 Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id AE566407FB; Thu, 24 Oct 2019 10:12:32 +0200 (CEST) From: Wolfgang Bumiller To: qemu-devel@nongnu.org Subject: [PATCH v2] monitor/qmp: resume monitor when clearing its queue Date: Thu, 24 Oct 2019 10:12:31 +0200 Message-Id: <20191024081231.19087-1-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.186.127.180 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann , Markus Armbruster , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" When a monitor's queue is filled up in handle_qmp_command() it gets suspended. It's the dispatcher bh's job currently to resume the monitor, which it does after processing an event from the queue. However, it is possible for a CHR_EVENT_CLOSED event to be processed before before the bh is scheduled, which will clear the queue without resuming the monitor, thereby preventing the dispatcher from reaching the resume() call. Any new connections to the qmp socket will be accept()ed and show the greeting, but will not respond to any messages sent afterwards (as they will not be read from the still-suspended socket). Fix this by resuming the monitor when clearing a queue which was filled up. Signed-off-by: Wolfgang Bumiller --- Changes to v1: * Update commit message to include the resulting symptoms. * Moved the resume code from `monitor_qmp_cleanup_req_queue_locked` to `monitor_qmp_cleanup_queues` to avoid an unnecessary resume when destroying the monitor (as the `_locked` version is also used by `monitor_data_destroy()`. * Renamed `monitor_qmp_cleanup_queues` to `monitor_qmp_cleanup_queues_and_resume` to reflect the change and be verbose about it for potential future users of the function. Currently the only user is `monitor_qmp_event()` in the `CHR_EVENT_CLOSED` case, which is exactly the problematic case currentl= y. Sorry for the deleay :| monitor/qmp.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/monitor/qmp.c b/monitor/qmp.c index 9d9e5d8b27..df689aa95e 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -75,10 +75,30 @@ static void monitor_qmp_cleanup_req_queue_locked(Monito= rQMP *mon) } } =20 -static void monitor_qmp_cleanup_queues(MonitorQMP *mon) +static void monitor_qmp_cleanup_queues_and_resume(MonitorQMP *mon) { qemu_mutex_lock(&mon->qmp_queue_lock); + + /* + * Same condition as in monitor_qmp_bh_dispatcher(), but before removi= ng an + * element from the queue (hence no `- 1`), also, the queue should not= be + * empty either, otherwise the monitor hasn't been suspended yet (or w= as + * already resumed). + */ + bool need_resume =3D (!qmp_oob_enabled(mon) && mon->qmp_requests->leng= th > 0) + || mon->qmp_requests->length =3D=3D QMP_REQ_QUEUE_LEN_MAX; + monitor_qmp_cleanup_req_queue_locked(mon); + + if (need_resume) { + /* + * Pairs with the monitor_suspend() in handle_qmp_command() in cas= e the + * queue gets cleared from a CH_EVENT_CLOSED event before the disp= atch + * bh got scheduled. + */ + monitor_resume(&mon->common); + } + qemu_mutex_unlock(&mon->qmp_queue_lock); } =20 @@ -332,7 +352,7 @@ static void monitor_qmp_event(void *opaque, int event) * stdio, it's possible that stdout is still open when stdin * is closed. */ - monitor_qmp_cleanup_queues(mon); + monitor_qmp_cleanup_queues_and_resume(mon); json_message_parser_destroy(&mon->parser); json_message_parser_init(&mon->parser, handle_qmp_command, mon, NULL); --=20 2.20.1