From nobody Tue Nov 18 10:36:02 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1609863714; cv=none; d=zohomail.com; s=zohoarc; b=YiHhwjxT2Q3PjKpcpvD3sVlKwifjPYqYXbDEd1hMmsTcHW8+H9L9EQQT1fj2DGxxKfkuELf63aNTXHgw6TcbBn8T1bGEjW3cFHISqACCFZM9YuSbdWItgXJ4Nj7G9HYxgs3oS3pjFOlgNmshRBIhwjmgllS25rAjWAYPeZAnlKM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609863714; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=P+c/iE7ZNt+1iAl9fEdT5Q4GJTbqiM/4QSgP4j+Xs+w=; b=gx2Btir5MTWb4ja4jVepJ9R8A0ahjWytEOHWyHH90849C6wz7W+MmULXk+dvukw23zshiMx9LrOBPfjBk1gKBHEaEGiuPIGbZ5U1hY/Bsv51gW4O12Kw6SiMEWS9KmTllSVqnmAQEIp30x336MmNa0AQYpH6u3USEHjkROSfkR8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160986371443418.318175997297544; Tue, 5 Jan 2021 08:21:54 -0800 (PST) Received: from localhost ([::1]:44808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kwp5j-0004QN-HU for importer@patchew.org; Tue, 05 Jan 2021 11:21:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kwote-00044s-Pc for qemu-devel@nongnu.org; Tue, 05 Jan 2021 11:09:23 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:34612) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kwotc-00043u-Lw for qemu-devel@nongnu.org; Tue, 05 Jan 2021 11:09:22 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 105FsjoM094290; Tue, 5 Jan 2021 16:09:17 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2130.oracle.com with ESMTP id 35tebasjwa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 05 Jan 2021 16:09:17 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 105FulaQ187551; Tue, 5 Jan 2021 16:09:16 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 35v1f8snr0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 05 Jan 2021 16:09:16 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 105G9GcG018678; Tue, 5 Jan 2021 16:09:16 GMT Received: from ca-dev63.us.oracle.com (/10.211.8.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 05 Jan 2021 08:09:15 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=P+c/iE7ZNt+1iAl9fEdT5Q4GJTbqiM/4QSgP4j+Xs+w=; b=LkRbSUKtIFevm639KIFdPjxdmSl36Eb5gX0Ajbf5WnXltm8GJSpfZCfkg7F8LjN9+FgV IaNe/auV+v72KXcDuS/3pXk1+H+cugkwZ4+/JWmrd37/3Wzux8yFKQ33TSG28qHWk3V3 96qiSa1DOOhpucPhnaooTaz07yWbyAU4f6NHmtTJhSnLWb/Q0VcBZNlT23TGURd0NsSM eNPl6D8wQkLrm06BIHAbb2B6UJf2a96qJmiQKvHvGciw80gZVQorubo5Ro2ofO7mgpVW awmQ8GIbavyQseJnOuAtg3dPiLM0r44vUzKX4QreDF2FHIIWz5rQQj0v14vgtj8knsa+ GA== From: Steve Sistare To: qemu-devel@nongnu.org Subject: [PATCH V2 19/22] monitor: cpr support Date: Tue, 5 Jan 2021 07:42:07 -0800 Message-Id: <1609861330-129855-20-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1609861330-129855-1-git-send-email-steven.sistare@oracle.com> References: <1609861330-129855-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9855 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 phishscore=0 suspectscore=0 spamscore=0 bulkscore=0 adultscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101050099 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9855 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 priorityscore=1501 spamscore=0 mlxscore=0 clxscore=1015 bulkscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101050099 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=141.146.126.79; envelope-from=steven.sistare@oracle.com; helo=aserp2130.oracle.com X-Spam_score_int: -46 X-Spam_score: -4.7 X-Spam_bar: ---- X-Spam_report: (-4.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.252, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: "Daniel P. Berrange" , "Michael S. Tsirkin" , Jason Zeng , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Juan Quintela , "Dr. David Alan Gilbert" , Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" A monitor socket requires special treatment. Save and restore the qmp negotiation status. Stop the monitor's iothread in cpsave. Otherwise, the thread will detect the close of the monitor socket and call unsetenv_fd= ,which modifies environ and races with execv which uses environ. Signed-off-by: Mark Kanda Signed-off-by: Steve Sistare --- include/monitor/monitor.h | 2 ++ migration/cpr.c | 2 ++ monitor/monitor.c | 5 +++++ monitor/qmp.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 1018d75..5456cff 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -22,6 +22,8 @@ void monitor_init_hmp(Chardev *chr, bool use_readline, Er= ror **errp); int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp); int monitor_init_opts(QemuOpts *opts, Error **errp); void monitor_cleanup(void); +void monitor_iothread_stop(void); +void monitor_cprsave(void); =20 int monitor_suspend(Monitor *mon); void monitor_resume(Monitor *mon); diff --git a/migration/cpr.c b/migration/cpr.c index de85d56..0f49c7d 100644 --- a/migration/cpr.c +++ b/migration/cpr.c @@ -137,9 +137,11 @@ void cprsave(const char *file, CprMode mode, Error **e= rrp) if (vfio_cprsave()) { goto err; } + monitor_iothread_stop(); walkenv(FD_PREFIX, preserve_fd, 0); vhost_dev_reset_all(); qemu_term_exit(); + monitor_cprsave(); setenv("QEMU_START_FREEZE", "", 1); qemu_system_exec_request(); } diff --git a/monitor/monitor.c b/monitor/monitor.c index b385a3d..1bda67c 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -591,6 +591,11 @@ void monitor_cleanup(void) } } =20 +void monitor_iothread_stop(void) +{ + iothread_stop(mon_iothread); +} + static void monitor_qapi_event_init(void) { monitor_qapi_event_state =3D g_hash_table_new(qapi_event_throttle_hash, diff --git a/monitor/qmp.c b/monitor/qmp.c index d433cea..d7eeab1 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -33,6 +33,7 @@ #include "qapi/qmp/qlist.h" #include "qapi/qmp/qstring.h" #include "trace.h" +#include "qemu/env.h" =20 struct QMPRequest { /* Owner of the request */ @@ -398,6 +399,21 @@ static void monitor_qmp_setup_handlers_bh(void *opaque) monitor_list_append(&mon->common); } =20 +static void setenv_qmp(const char *name, bool val) +{ + setenv_bool(name, val); +} + +static bool getenv_qmp(const char *name) +{ + bool ret =3D getenv_bool(name); + if (ret !=3D -1) { + unsetenv_bool(name); + return ret; + } + return false; +} + void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) { MonitorQMP *mon =3D g_new0(MonitorQMP, 1); @@ -438,4 +454,31 @@ void monitor_init_qmp(Chardev *chr, bool pretty, Error= **errp) NULL, &mon->common, NULL, true); monitor_list_append(&mon->common); } + + /* + * If a chr->label qmp env var is true, this is a restored qmp + * connection with capabilities negotiated. + */ + if (getenv_qmp(chr->label) =3D=3D true) { + mon->commands =3D &qmp_commands; + } +} + +/* Save the result of capability negotiation in the environment */ + +void monitor_cprsave(void) +{ + Monitor *mon; + MonitorQMP *qmp_mon; + + QTAILQ_FOREACH(mon, &mon_list, entry) { + if (!monitor_is_qmp(mon)) { + continue; + } + + qmp_mon =3D container_of(mon, MonitorQMP, common); + if (qmp_mon->commands =3D=3D &qmp_commands) { + setenv_qmp(mon->chr.chr->label, true); + } + } } --=20 1.8.3.1