From patchwork Wed Apr 10 10:33:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Olaf Hering X-Patchwork-Id: 10893575 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CCEF213B5 for ; Wed, 10 Apr 2019 10:35:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7A88289D8 for ; Wed, 10 Apr 2019 10:35:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AB7D8289DD; Wed, 10 Apr 2019 10:35:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5DD1D289DA for ; Wed, 10 Apr 2019 10:35:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hEAYH-0001Vz-4s; Wed, 10 Apr 2019 10:33:57 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hEAYE-0001Vn-PE for xen-devel@lists.xenproject.org; Wed, 10 Apr 2019 10:33:55 +0000 X-Inumbo-ID: 221b97ce-5b7c-11e9-92d7-bc764e045a96 Received: from mo6-p01-ob.smtp.rzone.de (unknown [2a01:238:20a:202:5301::5]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 221b97ce-5b7c-11e9-92d7-bc764e045a96; Wed, 10 Apr 2019 10:33:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1554892431; 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=xOKCXwocWtIHAq+uHv/YMpH2hjDHKJX5LsGsPBztemw=; b=H9Dp33DvC1HzRnjwxkMKFj6FvMmCyErijMPyA4U/lO+AHYjo0IsZQhbZG+KQIS37Jj f5llcUTJuKlrKHZrHxAjlcsz0Aga8eSWHcQhY8EBf0g2qV9Bk0W61AHporxkNykXA+aF mFUJTas+WR6NhXSKvmieZF2O2NvNmHJnkWn0HaqsIFIzD039qPEUIonLTyG/IjG5Dc1B 6DnPQwAib9lLCDXDf3EI3BypMVi8mtOzVtoptBx6deFMxJtiGqXk9J5APYhYxTdX6efk EovJ1k/baov5hUH7VhT5aFyfIEhwdzLkeShO/zmu66savaxCkAfTEW7Yd+q2oB30TRG0 +9Ug== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuznKRsvz7yq3NXHy7eI5Iw==" X-RZG-CLASS-ID: mo00 Received: from sender by smtp.strato.de (RZmta 44.18 DYNA|AUTH) with ESMTPSA id 60a847v3AAXk4x4 (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); Wed, 10 Apr 2019 12:33:46 +0200 (CEST) From: Olaf Hering To: xen-devel@lists.xenproject.org Date: Wed, 10 Apr 2019 12:33:38 +0200 Message-Id: <20190410103338.5456-1-olaf@aepfle.de> X-Mailer: git-send-email 2.16.4 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v1] 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_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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. 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 that assumption, 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 any device_model has to be spawned. This function can not be used as is, just to fill b_info->device_model_version, because store_libxl_entry() was already called earlier. Update this function to receive a domid to work with, instead of reading xenstore. Rearrange the code and initialize b_info->device_model_version in libxl__domain_build_info_setdefault() per DOMAIN_TYPE. Update initiate_domain_create() to set b_info->device_model_version if it was not set earlier, using the updated libxl__need_xenpv_qemu(). Introduce LIBXL_DEVICE_MODEL_VERSION_NONE_REQUIRED for PV and PVH that have no need for a device_model. Update existing users of libxl__need_xenpv_qemu() to use b_info->device_model_version for their check if a device_model is needed. Signed-off-by: Olaf Hering Cc: Roger Pau Monné Cc: Anthony PERARD --- tools/libxl/libxl_create.c | 37 ++++++++++++++++++++++++++++++------- tools/libxl/libxl_dm.c | 38 ++++++++++++++++++++++---------------- tools/libxl/libxl_dom_suspend.c | 8 ++++++-- tools/libxl/libxl_internal.h | 3 ++- tools/libxl/libxl_types.idl | 1 + 5 files changed, 61 insertions(+), 26 deletions(-) diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 89fe80fc9c..778417f386 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -87,16 +87,20 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc, b_info->device_model_ssidref = SECINITSID_DOMDM; if (!b_info->device_model_version) { - if (b_info->type == LIBXL_DOMAIN_TYPE_HVM) { + switch (b_info->type) { + case LIBXL_DOMAIN_TYPE_HVM: if (libxl_defbool_val(b_info->device_model_stubdomain)) { b_info->device_model_version = LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL; } else { b_info->device_model_version = libxl__default_device_model(gc); } - } else { - b_info->device_model_version = - LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN; + break; + case LIBXL_DOMAIN_TYPE_PV: + case LIBXL_DOMAIN_TYPE_PVH: + default: + /* will be set later */ + break; } if (b_info->device_model_version == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) { @@ -978,6 +982,17 @@ static void initiate_domain_create(libxl__egc *egc, goto error_out; } + if (d_config->b_info.device_model_version + == LIBXL_DEVICE_MODEL_VERSION_UNKNOWN) { + ret = libxl__need_xenpv_qemu(gc, d_config, domid); + if (ret) + d_config->b_info.device_model_version = + LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN; + else + d_config->b_info.device_model_version = + LIBXL_DEVICE_MODEL_VERSION_NONE_REQUIRED; + } + dcs->guest_domid = domid; dcs->sdss.dm.guest_domid = 0; /* means we haven't spawned */ @@ -1312,6 +1327,7 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev, libxl__domain_create_state *dcs = CONTAINER_OF(multidev, *dcs, multidev); STATE_AO_GC(dcs->ao); int i; + bool need_qemu; /* convenience aliases */ const uint32_t domid = dcs->guest_domid; @@ -1464,10 +1480,17 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev, libxl__device_console_add(gc, domid, &console, state, &device); libxl__device_console_dispose(&console); - ret = libxl__need_xenpv_qemu(gc, d_config); - if (ret < 0) + switch (d_config->b_info.device_model_version) { + case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: + case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: + need_qemu = true; + break; + default: + need_qemu = false; + break; + } goto error_out; - if (ret) { + if (need_qemu) { dcs->sdss.dm.guest_domid = domid; libxl__spawn_local_dm(egc, &dcs->sdss.dm); return; diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 2f19786bdd..5e861a8111 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -2268,7 +2268,7 @@ static void spawn_stub_launch_dm(libxl__egc *egc, libxl__domain_build_state *const d_state = sdss->dm.build_state; libxl__domain_build_state *const stubdom_state = &sdss->dm_state; uint32_t dm_domid = sdss->pvqemu.guest_domid; - int need_qemu; + bool need_qemu; if (ret) { LOGD(ERROR, guest_domid, "error connecting disk devices"); @@ -2337,7 +2337,15 @@ static void spawn_stub_launch_dm(libxl__egc *egc, } } - need_qemu = libxl__need_xenpv_qemu(gc, dm_config); + switch (dm_config->b_info.device_model_version) { + case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: + case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: + need_qemu = true; + break; + default: + need_qemu = false; + break; + } for (i = 0; i < num_console; i++) { libxl__device device; @@ -3175,18 +3183,11 @@ static void kill_device_model_uid_cb(libxl__egc *egc, } /* Return 0 if no dm needed, 1 if needed and <0 if error. */ -int libxl__need_xenpv_qemu(libxl__gc *gc, libxl_domain_config *d_config) +int libxl__need_xenpv_qemu(libxl__gc *gc, libxl_domain_config *d_config, uint32_t domid) { int idx, i, ret, num; - uint32_t domid; const struct libxl_device_type *dt; - ret = libxl__get_domid(gc, &domid); - if (ret) { - LOG(ERROR, "unable to get domain id"); - goto out; - } - if (d_config->num_vfbs > 0 || d_config->num_p9s > 0) { ret = 1; goto out; @@ -3238,21 +3239,26 @@ int libxl__dm_check_start(libxl__gc *gc, libxl_domain_config *d_config, uint32_t domid) { int rc; + bool need_qemu; if (libxl__dm_active(gc, domid)) return 0; - rc = libxl__need_xenpv_qemu(gc, d_config); - if (rc < 0) - goto out; - - if (!rc) + switch (d_config->b_info.device_model_version) { + case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: + case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: + need_qemu = true; + break; + default: + need_qemu = false; + break; + } + if (need_qemu == false) return 0; LOGD(ERROR, domid, "device model required but not running"); rc = ERROR_FAIL; -out: return rc; } diff --git a/tools/libxl/libxl_dom_suspend.c b/tools/libxl/libxl_dom_suspend.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); - if (dsps->type == LIBXL_DOMAIN_TYPE_HVM) { + if (dsps->type == LIBXL_DOMAIN_TYPE_HVM || + libxl__device_model_version_running(gc, dsps->domid) == + LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) { dsps->callback_device_model_done = 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; } - if (type == LIBXL_DOMAIN_TYPE_HVM) { + if (type == LIBXL_DOMAIN_TYPE_HVM || + libxl__device_model_version_running(gc, domid) == + LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) { rc = 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..9eb4211d85 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1817,7 +1817,8 @@ _hidden int libxl__domain_build(libxl__gc *gc, _hidden const char *libxl__domain_device_model(libxl__gc *gc, const libxl_domain_build_info *info); _hidden int libxl__need_xenpv_qemu(libxl__gc *gc, - libxl_domain_config *d_config); + libxl_domain_config *d_config, + uint32_t domid); _hidden bool libxl__query_qemu_backend(libxl__gc *gc, uint32_t domid, uint32_t backend_id, 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 = Enumeration("device_model_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"), ]) libxl_console_type = Enumeration("console_type", [