From nobody Fri Mar 29 15:32:20 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1557501759; cv=none; d=zoho.com; s=zohoarc; b=e+FCvLFwRu1sRTOmdaZTljT0KWfpBc5pufA8XkK24zrpKEMJiikNlPwv2A7O6dNRzQMQK0BaN7WCASldORGPWvou5HBKSEpiK4FjE+I8lP3bgfm+yCM54EOHNXxoRCgyfsgNv02t55BNTIHOnjY3wcP04XsCW4FIRIu5UENnOvE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557501759; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=BSXW0q1/43hQdZosb05uZ3+78xRFPXpHocx3Edb8SbI=; b=j8UPP3BiMn0bVRT2TOD4hNZNzupLIpPigk0+wcwx5sydceZytHlub6cshya+LGWCKfxJLPRQ3znlny3bP5b9iHWewule9H5gIfly1swfw72j/s3JvkMxTCBqxF4dn5copghhdl0DRK9CCBNGumQMOhljPzmQrc0AeZ69jPwEJB0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1557501758290387.61909996959935; Fri, 10 May 2019 08:22:38 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hP7Kk-0007w4-E1; Fri, 10 May 2019 15:21:14 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hP7Ki-0007vn-6O for xen-devel@lists.xenproject.org; Fri, 10 May 2019 15:21:13 +0000 Received: from mo6-p00-ob.smtp.rzone.de (unknown [2a01:238:20a:202:5300::6]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 3c782971-7337-11e9-8980-bc764e045a96; Fri, 10 May 2019 15:21:09 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 44.18 SBL|AUTH) with ESMTPSA id 60a847v4AFKp2jD (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Fri, 10 May 2019 17:20:51 +0200 (CEST) X-Inumbo-ID: 3c782971-7337-11e9-8980-bc764e045a96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1557501668; s=strato-dkim-0002; d=aepfle.de; h=Message-Id:Date:Subject:Cc:To:From:X-RZG-CLASS-ID:X-RZG-AUTH:From: Subject:Sender; bh=qxOPC38YksBeE2l6b7tznHCxKJ7pnDIaW9xjlPzfywQ=; b=GJmkMzY7BughIL1okh15VqdguBVdnjC7WKy1hSuk7wPHPj8Q2Zv/XFZPd+cNoyXfIM K8Hd2198PV9qsoXp03oPCn1/Mlp7ecTLs436zAYm9F4QZtU9iTtYcYSiOvFrMTn6AXGT KORF5RtHodGLcvhmmueEqKRJL3gjQfQBIF8IpkDfsUAtyE+58S++K1r9DN+cvUF4pk/J TGJTSf5soxjaB4H7WjQYD+tOBMA0lfLp8BgnbsTLtAVfeI961o0iVI8HYRs0GKuhbmKF jbhfUBZQSFNcdN1TKvYtVnApY7PRrxzXRrjApRISorNooRLxlD4NW6vJJEn1MyoY8KC9 7TzQ== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS329Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Date: Fri, 10 May 2019 17:20:47 +0200 Message-Id: <20190510152047.17299-1-olaf@aepfle.de> X-Mailer: git-send-email 2.16.4 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4] libxl: fix migration of PV and PVH domUs with and without qemu X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , Wei Liu , Olaf Hering , Ian Jackson , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) If a domU has a qemu-xen instance attached, it is required to call qemus "xen-save-devices-state" method. Without it, the receiving side of a PV or PVH migration may be unable to lock the image: xen be: qdisk-51712: xen be: qdisk-51712: error: Failed to get "write" lock error: Failed to get "write" lock xen be: qdisk-51712: xen be: qdisk-51712: initialise() failed initialise() failed To fix this bug, libxl__domain_suspend_device_model() and libxl__domain_resume_device_model() have to be called not only for HVM, but also if the active device_model is QEMU_XEN. Unfortunately, libxl__domain_build_info_setdefault() hardcodes b_info->device_model_version to QEMU_XEN if it does not know it any better. As a result libxl__device_model_version_running() will return incorrect values. This breaks domUs without a device_model. libxl__qmp_stop() would wait 10 seconds in qmp_open() for a qemu that will never appear. During this long timeframe the domU remains in state paused on the sending side. As a result network connections may be dropped. Once this bug is fixed as well, by just removing the assumption that every domU has a QEMU_XEN, there is no code to actually initialise b_info->device_model_version. There is a helper function libxl__need_xenpv_qemu(), which is used in various places to decide if a device_model has to be spawned. This function can not be used as is, just to fill device_model_version, because store_libxl_entry() was already called earlier. Create a new function to set device_model_version. Move existing code from libxl__domain_build_info_setdefault() to cover the HVM case. Add new code to cover non-HVM case, use libxl__need_xenpv_qemu() to set device_model_version. Move also initialization for device_model_stubdomain to the new function. Update libxl__spawn_stub_dm() and initiate_domain_create() to call the new function prior libxl__domain_build_info_setdefault() because device_mode_version is expected to be initialzed. libxl_domain_need_memory() needs no update because it does not have a d_config available anyway, and the callers provide a populated b_info. Introduce LIBXL_DEVICE_MODEL_VERSION_NONE_REQUIRED for PV and PVH that have no need for a device_model to make the state explicit. v03: - rearrange code to make sure device_model_version is initialized before store_libxl_entry() is called v02: - update wording in a comment - remove stale goto in domcreate_launch_dm - initialize ret in libxl__need_xenpv_qemu Signed-off-by: Olaf Hering Cc: Roger Pau Monn=C3=A9 Cc: Anthony PERARD Reviewed-by: Roger Pau Monn=C3=A9 --- tools/libxl/libxl_create.c | 99 ++++++++++++++++++++++++++-----------= ---- tools/libxl/libxl_dm.c | 2 + tools/libxl/libxl_dom_suspend.c | 8 +++- tools/libxl/libxl_internal.h | 2 + tools/libxl/libxl_types.idl | 1 + 5 files changed, 75 insertions(+), 37 deletions(-) diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 89fe80fc9c..bc4613a296 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -27,6 +27,64 @@ =20 #include =20 +int libxl__domain_set_device_model(libxl__gc *gc, libxl_domain_config *d_c= onfig) +{ + libxl_domain_build_info *b_info =3D &d_config->b_info; + int ret; + + libxl_defbool_setdefault(&b_info->device_model_stubdomain, false); + + if (b_info->device_model_version) + return 0; + + switch (b_info->type) { + case LIBXL_DOMAIN_TYPE_HVM: + if (libxl_defbool_val(b_info->device_model_stubdomain)) { + b_info->device_model_version =3D + LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL; + } else { + b_info->device_model_version =3D libxl__default_device_model(g= c); + } + break; + default: + ret =3D libxl__need_xenpv_qemu(gc, d_config); + switch (ret) { + case 1: + d_config->b_info.device_model_version =3D + LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN; + break; + case 0: + d_config->b_info.device_model_version =3D + LIBXL_DEVICE_MODEL_VERSION_NONE_REQUIRED; + break; + default: + LOGE(ERROR, "Unable to determine QEMU requisite"); + return ERROR_FAIL; + } + } + + if (b_info->device_model_version =3D=3D LIBXL_DEVICE_MODEL_VERSION_QEM= U_XEN) { + const char *dm; + + dm =3D libxl__domain_device_model(gc, b_info); + ret =3D access(dm, X_OK); + if (ret < 0) { + /* qemu-xen unavailable, use qemu-xen-traditional */ + if (errno =3D=3D ENOENT) { + LOGE(INFO, "qemu-xen is unavailable" + ", using qemu-xen-traditional instead"); + b_info->device_model_version =3D + LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL; + } else { + LOGE(ERROR, "qemu-xen access error"); + return ERROR_FAIL; + } + } + } + + return 0; +} + int libxl__domain_create_info_setdefault(libxl__gc *gc, libxl_domain_create_info *c_info) { @@ -80,45 +138,10 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc, return rc; } =20 - libxl_defbool_setdefault(&b_info->device_model_stubdomain, false); - if (libxl_defbool_val(b_info->device_model_stubdomain) && !b_info->device_model_ssidref) b_info->device_model_ssidref =3D SECINITSID_DOMDM; =20 - if (!b_info->device_model_version) { - if (b_info->type =3D=3D LIBXL_DOMAIN_TYPE_HVM) { - if (libxl_defbool_val(b_info->device_model_stubdomain)) { - b_info->device_model_version =3D - LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL; - } else { - b_info->device_model_version =3D libxl__default_device_mod= el(gc); - } - } else { - b_info->device_model_version =3D - LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN; - } - if (b_info->device_model_version - =3D=3D LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) { - const char *dm; - - dm =3D libxl__domain_device_model(gc, b_info); - rc =3D access(dm, X_OK); - if (rc < 0) { - /* qemu-xen unavailable, use qemu-xen-traditional */ - if (errno =3D=3D ENOENT) { - LOGE(INFO, "qemu-xen is unavailable" - ", using qemu-xen-traditional instead"); - b_info->device_model_version =3D - LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL; - } else { - LOGE(ERROR, "qemu-xen access error"); - return ERROR_FAIL; - } - } - } - } - if (b_info->blkdev_start =3D=3D NULL) b_info->blkdev_start =3D libxl__strdup(NOGC, "xvda"); =20 @@ -938,6 +961,12 @@ static void initiate_domain_create(libxl__egc *egc, goto error_out; } =20 + ret =3D libxl__domain_set_device_model(gc, d_config); + if (ret) { + LOGD(ERROR, domid, "Unable to set domain device model"); + goto error_out; + } + ret =3D libxl__domain_create_info_setdefault(gc, &d_config->c_info); if (ret) { LOGD(ERROR, domid, "Unable to set domain create info defaults"); diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 2f19786bdd..086e566311 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -2168,6 +2168,8 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stu= b_dm_spawn_state *sdss) dm_config->c_info.run_hotplug_scripts =3D guest_config->c_info.run_hotplug_scripts; =20 + ret =3D libxl__domain_set_device_model(gc, dm_config); + if (ret) goto out; ret =3D libxl__domain_create_info_setdefault(gc, &dm_config->c_info); if (ret) goto out; ret =3D libxl__domain_build_info_setdefault(gc, &dm_config->b_info); diff --git a/tools/libxl/libxl_dom_suspend.c b/tools/libxl/libxl_dom_suspen= d.c index d1af3a6573..c492fe5dd1 100644 --- a/tools/libxl/libxl_dom_suspend.c +++ b/tools/libxl/libxl_dom_suspend.c @@ -379,7 +379,9 @@ static void domain_suspend_common_guest_suspended(libxl= __egc *egc, libxl__ev_xswatch_deregister(gc, &dsps->guest_watch); libxl__ev_time_deregister(gc, &dsps->guest_timeout); =20 - if (dsps->type =3D=3D LIBXL_DOMAIN_TYPE_HVM) { + if (dsps->type =3D=3D LIBXL_DOMAIN_TYPE_HVM || + libxl__device_model_version_running(gc, dsps->domid) =3D=3D + LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) { dsps->callback_device_model_done =3D domain_suspend_common_done; libxl__domain_suspend_device_model(egc, dsps); /* must be last */ return; @@ -459,7 +461,9 @@ int libxl__domain_resume(libxl__gc *gc, uint32_t domid,= int suspend_cancel) goto out; } =20 - if (type =3D=3D LIBXL_DOMAIN_TYPE_HVM) { + if (type =3D=3D LIBXL_DOMAIN_TYPE_HVM || + libxl__device_model_version_running(gc, domid) =3D=3D + LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) { rc =3D libxl__domain_resume_device_model(gc, domid); if (rc) { LOGD(ERROR, domid, "failed to resume device model:%d", rc); diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 44e0221284..25f113404b 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1374,6 +1374,8 @@ _hidden int libxl__device_nextid(libxl__gc *gc, uint3= 2_t domid, _hidden int libxl__resolve_domid(libxl__gc *gc, const char *name, uint32_t *domid); =20 +_hidden int libxl__domain_set_device_model(libxl__gc *gc, + libxl_domain_config *d_config); /* * For each aggregate type which can be used as an input we provide: * diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index cb4702fd7a..7d75bd3850 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -106,6 +106,7 @@ libxl_device_model_version =3D Enumeration("device_mode= l_version", [ (0, "UNKNOWN"), (1, "QEMU_XEN_TRADITIONAL"), # Historical qemu-xen device model (qemu-= dm) (2, "QEMU_XEN"), # Upstream based qemu-xen device model + (3, "NONE_REQUIRED"), ]) =20 libxl_console_type =3D Enumeration("console_type", [ _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel