From patchwork Wed Jan 22 14:44:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11345857 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BCF7E13A4 for ; Wed, 22 Jan 2020 14:46:05 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 89F6F21835 for ; Wed, 22 Jan 2020 14:46:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="jXsvkla+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 89F6F21835 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuHFa-0000WS-Ah; Wed, 22 Jan 2020 14:44:58 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuHFZ-0000WD-WC for xen-devel@lists.xenproject.org; Wed, 22 Jan 2020 14:44:58 +0000 X-Inumbo-ID: c27fac9a-3d25-11ea-9fd7-bc764e2007e4 Received: from smtp-fw-4101.amazon.com (unknown [72.21.198.25]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c27fac9a-3d25-11ea-9fd7-bc764e2007e4; Wed, 22 Jan 2020 14:44:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1579704298; x=1611240298; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NTN+nLYL47FZLMKXa+HZsaN7UTNai8NyDI/R0TbYg4M=; b=jXsvkla+eukSFVXBAd6Q++drFtltH8mfb1XZpk3oNqRr82aODE+rcufI RZHFNduvX0CoMvwqOTUDFk8kpaz3h9F6w049yoJetGCsHZD7KY8QOvqau Ir3axA1d/NWmTPULZLsXuHX/QlIKbatar+N9CLLQ4DHHWsIRUFlBJXD9M I=; IronPort-SDR: 66kLv12nUO1vb8vWAoguNOf8VoH0xevBDLpmwuj3Q0WwWerKMYa8cjVPN2pI9m44eMIMv8pUaD OXRjZES8nltg== X-IronPort-AV: E=Sophos;i="5.70,350,1574121600"; d="scan'208";a="13614851" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1d-98acfc19.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 22 Jan 2020 14:44:56 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1d-98acfc19.us-east-1.amazon.com (Postfix) with ESMTPS id 5155FA28ED; Wed, 22 Jan 2020 14:44:53 +0000 (UTC) Received: from EX13D32EUB001.ant.amazon.com (10.43.166.125) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Wed, 22 Jan 2020 14:44:53 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D32EUB001.ant.amazon.com (10.43.166.125) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 22 Jan 2020 14:44:52 +0000 Received: from u2f063a87eabd5f.cbg10.amazon.com (10.125.106.135) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Wed, 22 Jan 2020 14:44:50 +0000 From: Paul Durrant To: Date: Wed, 22 Jan 2020 14:44:41 +0000 Message-ID: <20200122144446.919-3-pdurrant@amazon.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200122144446.919-1-pdurrant@amazon.com> References: <20200122144446.919-1-pdurrant@amazon.com> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH v4 2/7] libxl_create: make 'soft reset' explicit X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , Paul Durrant , Ian Jackson , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The 'soft reset' code path in libxl__domain_make() is currently taken if a valid domid is passed into the function. A subsequent patch will enable higher levels of the toolstack to determine the domid of newly created or restored domains and therefore this criteria for choosing 'soft reset' will no longer be usable. This patch adds an extra boolean option to libxl__domain_make() to specify whether it is being invoked in soft reset context and appropriately modifies callers to choose the right value. To facilitate this, a new 'soft_reset' boolean field is added to struct libxl__domain_create_state and the 'domid_soft_reset' field is renamed to 'domid' in anticipation of its wider remit. For the moment do_domain_create() will always set domid to INVALID_DOMID and hence we can add an assertion into libxl__domain_create() that, if it is not called in soft reset context, the passed in domid is exactly that value. Whilst in the neighbourhood, some checks of 'restore_fd > -1' have been replaced by 'restore_fd >= 0' to be more conventional and consistent with checks of 'restore_fd < 0'. Signed-off-by: Paul Durrant Acked-by: Ian Jackson --- Cc: Wei Liu Cc: Anthony PERARD --- tools/libxl/libxl_create.c | 56 ++++++++++++++++++++++-------------- tools/libxl/libxl_dm.c | 2 +- tools/libxl/libxl_internal.h | 5 ++-- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 8a1bff6cd3..73a2883357 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -538,7 +538,7 @@ out: int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config, libxl__domain_build_state *state, - uint32_t *domid) + uint32_t *domid, bool soft_reset) { libxl_ctx *ctx = libxl__gc_owner(gc); int ret, rc, nb_vm; @@ -555,14 +555,15 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config, libxl_domain_create_info *info = &d_config->c_info; libxl_domain_build_info *b_info = &d_config->b_info; + assert(soft_reset || *domid == INVALID_DOMID); + uuid_string = libxl__uuid2string(gc, info->uuid); if (!uuid_string) { rc = ERROR_NOMEM; goto out; } - /* Valid domid here means we're soft resetting. */ - if (!libxl_domid_valid_guest(*domid)) { + if (!soft_reset) { struct xen_domctl_createdomain create = { .ssidref = info->ssidref, .max_vcpus = b_info->max_vcpus, @@ -611,6 +612,14 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config, goto out; } + /* + * If soft_reset is set the the domid will have been valid on entry. + * If it was not set then xc_domain_create() should have assigned a + * valid value. Either way, if we reach this point, domid should be + * valid. + */ + assert(libxl_domid_valid_guest(*domid)); + ret = xc_cpupool_movedomain(ctx->xch, info->poolid, *domid); if (ret < 0) { LOGED(ERROR, *domid, "domain move fail"); @@ -1091,13 +1100,14 @@ static void initiate_domain_create(libxl__egc *egc, libxl_domain_config *const d_config = dcs->guest_config; const int restore_fd = dcs->restore_fd; - domid = dcs->domid_soft_reset; + domid = dcs->domid; libxl__domain_build_state_init(&dcs->build_state); ret = libxl__domain_config_setdefault(gc,d_config,domid); if (ret) goto error_out; - ret = libxl__domain_make(gc, d_config, &dcs->build_state, &domid); + ret = libxl__domain_make(gc, d_config, &dcs->build_state, &domid, + dcs->soft_reset); if (ret) { LOGD(ERROR, domid, "cannot make domain: %d", ret); dcs->guest_domid = domid; @@ -1141,7 +1151,7 @@ static void initiate_domain_create(libxl__egc *egc, if (ret) goto error_out; - if (restore_fd >= 0 || dcs->domid_soft_reset != INVALID_DOMID) { + if (restore_fd >= 0 || dcs->soft_reset) { LOGD(DEBUG, domid, "restoring, not running bootloader"); domcreate_bootloader_done(egc, &dcs->bl, 0); } else { @@ -1217,7 +1227,7 @@ static void domcreate_bootloader_done(libxl__egc *egc, dcs->sdss.dm.callback = domcreate_devmodel_started; dcs->sdss.callback = domcreate_devmodel_started; - if (restore_fd < 0 && dcs->domid_soft_reset == INVALID_DOMID) { + if (restore_fd < 0 && !dcs->soft_reset) { rc = libxl__domain_build(gc, domid, dcs); domcreate_rebuild_done(egc, dcs, rc); return; @@ -1827,7 +1837,7 @@ static int do_domain_create(libxl_ctx *ctx, libxl_domain_config *d_config, libxl_domain_config_copy(ctx, &cdcs->dcs.guest_config_saved, d_config); cdcs->dcs.restore_fd = cdcs->dcs.libxc_fd = restore_fd; cdcs->dcs.send_back_fd = send_back_fd; - if (restore_fd > -1) { + if (restore_fd >= 0) { cdcs->dcs.restore_params = *params; rc = libxl__fd_flags_modify_save(gc, cdcs->dcs.restore_fd, ~(O_NONBLOCK|O_NDELAY), 0, @@ -1835,7 +1845,8 @@ static int do_domain_create(libxl_ctx *ctx, libxl_domain_config *d_config, if (rc < 0) goto out_err; } cdcs->dcs.callback = domain_create_cb; - cdcs->dcs.domid_soft_reset = INVALID_DOMID; + cdcs->dcs.domid = INVALID_DOMID; + cdcs->dcs.soft_reset = false; if (cdcs->dcs.restore_params.checkpointed_stream == LIBXL_CHECKPOINTED_STREAM_COLO) { @@ -1905,7 +1916,7 @@ static void soft_reset_dm_suspended(libxl__egc *egc, int rc); static int do_domain_soft_reset(libxl_ctx *ctx, libxl_domain_config *d_config, - uint32_t domid_soft_reset, + uint32_t domid, const libxl_asyncop_how *ao_how, const libxl_asyncprogress_how *aop_console_how) @@ -1933,15 +1944,16 @@ static int do_domain_soft_reset(libxl_ctx *ctx, libxl_domain_config_copy(ctx, &srs->cdcs.dcs.guest_config_saved, d_config); cdcs->dcs.restore_fd = -1; - cdcs->dcs.domid_soft_reset = domid_soft_reset; + cdcs->dcs.domid = domid; + cdcs->dcs.soft_reset = true; cdcs->dcs.callback = domain_create_cb; libxl__ao_progress_gethow(&srs->cdcs.dcs.aop_console_how, aop_console_how); cdcs->domid_out = &domid_out; - dom_path = libxl__xs_get_dompath(gc, domid_soft_reset); + dom_path = libxl__xs_get_dompath(gc, domid); if (!dom_path) { - LOGD(ERROR, domid_soft_reset, "failed to read domain path"); + LOGD(ERROR, domid, "failed to read domain path"); rc = ERROR_FAIL; goto out; } @@ -1950,7 +1962,7 @@ static int do_domain_soft_reset(libxl_ctx *ctx, GCSPRINTF("%s/store/ring-ref", dom_path), &xs_store_mfn); if (rc) { - LOGD(ERROR, domid_soft_reset, "failed to read store/ring-ref."); + LOGD(ERROR, domid, "failed to read store/ring-ref."); goto out; } state->store_mfn = xs_store_mfn ? atol(xs_store_mfn): 0; @@ -1959,7 +1971,7 @@ static int do_domain_soft_reset(libxl_ctx *ctx, GCSPRINTF("%s/console/ring-ref", dom_path), &xs_console_mfn); if (rc) { - LOGD(ERROR, domid_soft_reset, "failed to read console/ring-ref."); + LOGD(ERROR, domid, "failed to read console/ring-ref."); goto out; } state->console_mfn = xs_console_mfn ? atol(xs_console_mfn): 0; @@ -1968,20 +1980,20 @@ static int do_domain_soft_reset(libxl_ctx *ctx, GCSPRINTF("%s/console/tty", dom_path), &console_tty); if (rc) { - LOGD(ERROR, domid_soft_reset, "failed to read console/tty."); + LOGD(ERROR, domid, "failed to read console/tty."); goto out; } state->console_tty = libxl__strdup(gc, console_tty); dss->ao = ao; - dss->domid = dss->dsps.domid = domid_soft_reset; + dss->domid = dss->dsps.domid = domid; dss->dsps.dm_savefile = GCSPRINTF(LIBXL_DEVICE_MODEL_SAVE_FILE".%d", - domid_soft_reset); + domid); rc = libxl__save_emulator_xenstore_data(dss, &srs->toolstack_buf, &srs->toolstack_len); if (rc) { - LOGD(ERROR, domid_soft_reset, "failed to save toolstack record."); + LOGD(ERROR, domid, "failed to save toolstack record."); goto out; } @@ -2010,10 +2022,10 @@ static void soft_reset_dm_suspended(libxl__egc *egc, * xenstore again with probably different store/console/... * channels. */ - xs_release_domain(CTX->xsh, cdcs->dcs.domid_soft_reset); + xs_release_domain(CTX->xsh, cdcs->dcs.domid); srs->dds.ao = ao; - srs->dds.domid = cdcs->dcs.domid_soft_reset; + srs->dds.domid = cdcs->dcs.domid; srs->dds.callback = domain_soft_reset_cb; srs->dds.soft_reset = true; libxl__domain_destroy(egc, &srs->dds); @@ -2029,7 +2041,7 @@ static void domain_create_cb(libxl__egc *egc, *cdcs->domid_out = domid; - if (dcs->restore_fd > -1) { + if (dcs->restore_fd >= 0) { flrc = libxl__fd_flags_restore(gc, dcs->restore_fd, dcs->restore_fdfl); /* diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 3f08ccad1b..2bd92fb1df 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -2194,7 +2194,7 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__domain_create_state *dcs) /* fixme: this function can leak the stubdom if it fails */ ret = libxl__domain_make(gc, dm_config, stubdom_state, - &sdss->pvqemu.guest_domid); + &sdss->pvqemu.guest_domid, false); if (ret) goto out; uint32_t dm_domid = sdss->pvqemu.guest_domid; diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index f2f753c72b..3a00bdb8b4 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1956,7 +1956,7 @@ _hidden void libxl__exec(libxl__gc *gc, int stdinfd, int stdoutfd, _hidden int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config, libxl__domain_build_state *state, - uint32_t *domid); + uint32_t *domid, bool soft_reset); _hidden int libxl__domain_build(libxl__gc *gc, uint32_t domid, libxl__domain_create_state *dcs); @@ -4131,7 +4131,8 @@ struct libxl__domain_create_state { int restore_fdfl; /* original flags of restore_fd */ int send_back_fd; libxl_domain_restore_params restore_params; - uint32_t domid_soft_reset; + uint32_t domid; + bool soft_reset; libxl__domain_create_cb *callback; libxl_asyncprogress_how aop_console_how; /* private to domain_create */