From nobody Sun May 5 13:13:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1608574604; cv=none; d=zohomail.com; s=zohoarc; b=XMjCVFmlNwTe5j554ljI/1KpFhKuoAmemuELLrvdEKCbE90x2ApefTDehETmmOIMdSoEDzZGhO/gVDTNjE/lNQNM6rrJi0sdLw8a5I7rbkEGaSgNQoHbXwP3dN+ZuHAho972Tpl571jtDmjx7G9X4C5TvyVXmYXRw+Ug2Jz9UV8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608574604; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=V+uG/cNFA7yd9EuJ5E/MqM1pQh6Ig2k8BfWIJd3+vAM=; b=C40AVp2lEye89o7pN6XDIBlVHZKqatlPBmWBBJ1QB7yYiKfTmWGPwsz81WV0p9Fpa5i7N3fBKEf/0Ir70stSBy/Y7utnLl7Ye+7oXE+ATdTng5Aq+sMMIjPrKXZH5KzpGGQEf8Pwp02q0k/t+r8JsFRNxw3MteBkMpghuHD6EF0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1608574604605693.215955638985; Mon, 21 Dec 2020 10:16:44 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.57506.100659 (Exim 4.92) (envelope-from ) id 1krPjP-0000dZ-Eh; Mon, 21 Dec 2020 18:16:27 +0000 Received: by outflank-mailman (output) from mailman id 57506.100659; Mon, 21 Dec 2020 18:16:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1krPjP-0000dR-Ag; Mon, 21 Dec 2020 18:16:27 +0000 Received: by outflank-mailman (input) for mailman id 57506; Mon, 21 Dec 2020 18:16:26 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1krPjN-0000Ys-W1 for xen-devel@lists.xenproject.org; Mon, 21 Dec 2020 18:16:26 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ecc297fa-f5ea-407d-8910-2d35caea21ad; Mon, 21 Dec 2020 18:16:21 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ecc297fa-f5ea-407d-8910-2d35caea21ad DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1608574581; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hRzDOLHnk7AFo9Bf3bdweZ3XGJXNV7e3/ahLcdzLXdc=; b=PkeTYGYy5J+nu1yRvcPaFf1Eat/wOb5MuRUjuLPnlecyz8cWolXvkzue C0o6aubhD0qn4DMCYz88QJ/ekjSdrxJqw75vgbXQTYjp+JG2qfASGQtla A9w0txW93vt3ddhahEcN2cwNX9gx5lIFWO/RW5/4IcH991BptUfmu6vAH 8=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: eCvJ8vVJQ+h1Yvf02LFBLnaUX2zruNYyojZwmjDu86rPk3OsY1YAJpD8hf6UX9QXu7VM/LGXdw Mfq/e9i8vDhIMvhBLTTwKJPhvUGgz7+970pi2fg0mXdV+5s4Qgy/WR7kX1Qf7AVSFz1AkS53CQ KCfJUjFqhJsEh2izW+lDXB+pRJ9DfMX6ATET2w4pGiIbXho9dAff3jM9/1gNbbhUKq74ne7Yzo Sb0m3H6WQSCXKvppEvIg7wtDjbw1GRpCC0dtdeuVhNVpQi80rKMQ6z0E6ef/OQgUp85jOvyNqm Ebk= X-SBRS: 5.2 X-MesageID: 33707602 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.78,437,1599537600"; d="scan'208";a="33707602" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Stefano Stabellini , Julien Grall , Volodymyr Babchuk Subject: [PATCH 1/3] xen/domain: Reorder trivial initialisation in early domain_create() Date: Mon, 21 Dec 2020 18:14:44 +0000 Message-ID: <20201221181446.7791-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201221181446.7791-1-andrew.cooper3@citrix.com> References: <20201221181446.7791-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) This improves the robustness of the error paths. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk --- xen/common/domain.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index 5ec48c3e19..ce3667f1b4 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -391,25 +391,7 @@ struct domain *domain_create(domid_t domid, =20 TRACE_1D(TRC_DOM0_DOM_ADD, d->domain_id); =20 - /* - * Allocate d->vcpu[] and set ->max_vcpus up early. Various per-domain - * resources want to be sized based on max_vcpus. - */ - if ( !is_system_domain(d) ) - { - err =3D -ENOMEM; - d->vcpu =3D xzalloc_array(struct vcpu *, config->max_vcpus); - if ( !d->vcpu ) - goto fail; - - d->max_vcpus =3D config->max_vcpus; - } - - lock_profile_register_struct(LOCKPROF_TYPE_PERDOM, d, domid); - - if ( (err =3D xsm_alloc_security_domain(d)) !=3D 0 ) - goto fail; - + /* Trivial initialisation. */ atomic_set(&d->refcnt, 1); RCU_READ_LOCK_INIT(&d->rcu_lock); spin_lock_init_prof(d, domain_lock); @@ -434,6 +416,27 @@ struct domain *domain_create(domid_t domid, INIT_LIST_HEAD(&d->pdev_list); #endif =20 + /* All error paths can depend on the above setup. */ + + /* + * Allocate d->vcpu[] and set ->max_vcpus up early. Various per-domain + * resources want to be sized based on max_vcpus. + */ + if ( !is_system_domain(d) ) + { + err =3D -ENOMEM; + d->vcpu =3D xzalloc_array(struct vcpu *, config->max_vcpus); + if ( !d->vcpu ) + goto fail; + + d->max_vcpus =3D config->max_vcpus; + } + + lock_profile_register_struct(LOCKPROF_TYPE_PERDOM, d, domid); + + if ( (err =3D xsm_alloc_security_domain(d)) !=3D 0 ) + goto fail; + err =3D -ENOMEM; if ( !zalloc_cpumask_var(&d->dirty_cpumask) ) goto fail; --=20 2.11.0 From nobody Sun May 5 13:13:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1608574641; cv=none; d=zohomail.com; s=zohoarc; b=IEHVy26TQePSrOu8PMaYNgS3mJpedWHxxmcLazVUClqeeys+870yCQiHgAenAv//RMX0NIGiVnK5l+d+eI5Lys66WuUIGz3XxbZBM7Q2lUdISZT8PR7MWwu+X/ekqNMHqk4xiZGQBgQ3PpjRLogv8LLG9f+NxSx8AAjyI+m4Fos= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608574641; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YKwzBlivX8RdceltiSWBFaII5jDK6rdRdXSNpI0/ZUk=; b=MSx/T0/dS5yK0kssmRovQGO/Xb2y2ATPJZYXcUhLTIHwsVOa7/g4gSCIg9jEZUQevE0EAcEwOhN2jGkkldTA9c+ag+xX2S4IreqFgweIB5p2ugNSyBuCuPI46acGAXLjYNbHdexmqNvD8Jk+SnNSAB/4tfl1Hau5zOZ/SLqhbxA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1608574641742901.843862871701; Mon, 21 Dec 2020 10:17:21 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.57507.100664 (Exim 4.92) (envelope-from ) id 1krPjP-0000eJ-SM; Mon, 21 Dec 2020 18:16:27 +0000 Received: by outflank-mailman (output) from mailman id 57507.100664; Mon, 21 Dec 2020 18:16:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1krPjP-0000e8-Kt; Mon, 21 Dec 2020 18:16:27 +0000 Received: by outflank-mailman (input) for mailman id 57507; Mon, 21 Dec 2020 18:16:26 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1krPjO-0000Yt-1i for xen-devel@lists.xenproject.org; Mon, 21 Dec 2020 18:16:26 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c26f9d72-d98a-4135-ab13-a02dfca0b828; Mon, 21 Dec 2020 18:16:21 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c26f9d72-d98a-4135-ab13-a02dfca0b828 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1608574581; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=urlwgaA7ewlnkuu+TIgJoIZwJdSpHPYy7Pdzt1cR0Pw=; b=Ccjv2poHVOxQ2PteI7sEqDOvSXmNdrE1fFGGKY57SBV7qZ2nonQkIpS4 fgH1lo5gcNjB2ycw5QSocjnoMvH+J41sTDoRGBQdMyRFSxU2UugRMlZzh BuLoN5vFxaBN0YEL0MgLXh9ilBtngV8+Jli783VUYSfSMHk4QzfZ8NBi9 A=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: YM3is+7Zqq7V8NlCoaB8HckE19fpwhw6g/oSB9Nlw3U5Tvw3lNLeurhFXLG0q6HzmPtP1Vt6yd GDEVl5p1jIateQHhbHTGmRHS6KXmrnebYHDe1wWPcpOLvqZ8F4H+nVbgfF5Z5W10JiOsbtj5Qh m3HII8KswCQOiK4j0+m0fmUL319hk5NJ9MhnZAh9xPm5WMJ1GTaOetOZogH/kL5tUZdI6cdMeI wnErJIkn4lxsqG/04yvguXKumnXAV586kWuEVf2s/kkwFfOmjBvmgPMUws9E+L8WS2IoBuJXRr R/g= X-SBRS: 5.2 X-MesageID: 33707596 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.78,437,1599537600"; d="scan'208";a="33707596" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Stefano Stabellini , Julien Grall , Volodymyr Babchuk Subject: [PATCH 2/3] xen/domain: Introduce domain_teardown() Date: Mon, 21 Dec 2020 18:14:45 +0000 Message-ID: <20201221181446.7791-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201221181446.7791-1-andrew.cooper3@citrix.com> References: <20201221181446.7791-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) There is no common equivelent of domain_reliquish_resources(), which has caused various pieces of common cleanup to live in inappropriate places. Perhaps most obviously, evtchn_destroy() is called for every continuation of domain_reliquish_resources(), which can easily be thousands of times. Create domain_teardown() to be a new top level facility, and call it from t= he appropriate positions in domain_kill() and domain_create()'s error path. No change in behaviour yet. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk --- xen/common/domain.c | 59 +++++++++++++++++++++++++++++++++++++++++++++= ++++ xen/include/xen/sched.h | 8 +++++++ 2 files changed, 67 insertions(+) diff --git a/xen/common/domain.c b/xen/common/domain.c index ce3667f1b4..ef1987335b 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -273,6 +273,59 @@ static int __init parse_extra_guest_irqs(const char *s) custom_param("extra_guest_irqs", parse_extra_guest_irqs); =20 /* + * Release resources held by a domain. There may or may not be live + * references to the domain, and it may or may not be fully constructed. + * + * d->is_dying differing between DOMDYING_dying and DOMDYING_dead can be u= sed + * to determine if live references to the domain exist, and also whether + * continuations are permitted. + * + * If d->is_dying is DOMDYING_dead, this must not return non-zero. + */ +static int domain_teardown(struct domain *d) +{ + BUG_ON(!d->is_dying); + + /* + * This hypercall can take minutes of wallclock time to complete. This + * logic implements a co-routine, stashing state in struct domain acro= ss + * hypercall continuation boundaries. + */ + switch ( d->teardown.val ) + { + /* + * Record the current progress. Subsequent hypercall continuations + * will logically restart work from this point. + * + * PROGRESS() markers must not be in the middle of loops. The loop + * variable isn't preserved across a continuation. + * + * To avoid redundant work, there should be a marker before each + * function which may return -ERESTART. + */ +#define PROGRESS(x) \ + d->teardown.val =3D PROG_ ## x; \ + /* Fallthrough */ \ + case PROG_ ## x + + enum { + PROG_done =3D 1, + }; + + case 0: + PROGRESS(done): + break; + +#undef PROGRESS + + default: + BUG(); + } + + return 0; +} + +/* * Destroy a domain once all references to it have been dropped. Used eit= her * from the RCU path, or from the domain_create() error path before the do= main * is inserted into the domlist. @@ -553,6 +606,9 @@ struct domain *domain_create(domid_t domid, if ( init_status & INIT_watchdog ) watchdog_domain_destroy(d); =20 + /* Must not hit a continuation in this context. */ + ASSERT(domain_teardown(d) =3D=3D 0); + _domain_destroy(d); =20 return ERR_PTR(err); @@ -733,6 +789,9 @@ int domain_kill(struct domain *d) domain_set_outstanding_pages(d, 0); /* fallthrough */ case DOMDYING_dying: + rc =3D domain_teardown(d); + if ( rc ) + break; rc =3D evtchn_destroy(d); if ( rc ) break; diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index faf5fda36f..3f35c537b8 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -525,6 +525,14 @@ struct domain /* Argo interdomain communication support */ struct argo_domain *argo; #endif + + /* + * Continuation information for domain_teardown(). All fields entirely + * private. + */ + struct { + unsigned int val; + } teardown; }; =20 static inline struct page_list_head *page_to_list( --=20 2.11.0 From nobody Sun May 5 13:13:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1608574603; cv=none; d=zohomail.com; s=zohoarc; b=mnscYXF4JTQBL7VrKy9sE0HfOzEh97qCVWE34Ryr3vMG8KyZDsSEp5sjA+F3xVtUT6HGPf7CO11iPZdfKFZepjSwch+Saf2/43PG3Jf2O/52/D7nVmw+Zl08umw8WKhckRGTqNAjCUQFuXpqVqDy1cWFO+rsJsAk+RoTodTNsrM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608574603; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/uvdDze3226ePcfDryRYa3CMV2If4wKRcPQhuUZ4PaU=; b=BdK8cALOORVXRm+BCvcGhNgU6fAsJGxELNXPRScMfEpyfTsY4PBoG+cI0XoE8xQuH/d+Z09m63ph/Yuvjba/P3gHdTqx6rMrWgAMSvqZOH2Zo425YbUjm5Ahi4MYBACYnHEC0hgHew6flBSekTTmONW8taYwAWYGrZNo6xCIcac= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1608574603499351.31357141260287; Mon, 21 Dec 2020 10:16:43 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.57505.100641 (Exim 4.92) (envelope-from ) id 1krPjL-0000Zj-1C; Mon, 21 Dec 2020 18:16:23 +0000 Received: by outflank-mailman (output) from mailman id 57505.100641; Mon, 21 Dec 2020 18:16:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1krPjK-0000ZT-To; Mon, 21 Dec 2020 18:16:22 +0000 Received: by outflank-mailman (input) for mailman id 57505; Mon, 21 Dec 2020 18:16:21 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1krPjJ-0000Yt-4S for xen-devel@lists.xenproject.org; Mon, 21 Dec 2020 18:16:21 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 499db0c6-1c04-4f23-bcff-a7f45c660f51; Mon, 21 Dec 2020 18:16:19 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 499db0c6-1c04-4f23-bcff-a7f45c660f51 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1608574578; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=B/5dAlAFWaIIj98Nfhx+GTd6ypQExw4vEU95/xCjDHg=; b=RptR4pbhuiWfugIcYa2CFotfNAbTHwPPzNr3Ie/BxtvtLbKjVoVH2Suc hGwytbJmlDCwvhwTH8PqZoL4VOWEcuCUbggU3j5T0icOVGs06Je5VkPEM 1A1UT9Lf1LuzxkreIw60m1JM/fUUGcHD9MQnRLpgDLDA3+m5NIxyrsuiD Q=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: B2W5j/M1lFQ4AS9cDmR2qgWNTidmuOzn0n9z0yNDaw/6TLT//jKQLoaUzyjGxlQZX0ekB3tpRO QhE9YPWHljtcL3rJa6q43GOmj6C+EtPvZFNj5toDju/qNoArojSJ3JZLc0eapxNpVtF1Lg6AIc vHqUacirXXlhjWLDaRwXjiQFQFz7ckwCFUUuVWucuDvARBuLsf5qKrvZm6R8/W4wv7bx2/1BKJ VBuRPehHIlDgMFOILQXNBoQWXDJbaXFFouUz3l47EZg1HMQhZ5Gp1K5MG5KL6TsmeKN6jP+b7h nwc= X-SBRS: 5.2 X-MesageID: 33707581 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.78,437,1599537600"; d="scan'208";a="33707581" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Stefano Stabellini , Julien Grall , Volodymyr Babchuk Subject: [PATCH 3/3] xen/evtchn: Clean up teardown handling Date: Mon, 21 Dec 2020 18:14:46 +0000 Message-ID: <20201221181446.7791-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201221181446.7791-1-andrew.cooper3@citrix.com> References: <20201221181446.7791-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) First of all, rename the evtchn APIs: * evtchn_destroy =3D> evtchn_teardown * evtchn_destroy_final =3D> evtchn_destroy Move both calls into appropriate positions in domain_teardown() and _domain_destroy(), which avoids having different cleanup logic depending on the the cause of the cleanup. In particular, this avoids evtchn_teardown() (previously named evtchn_destroy()) being called redundantly thousands of times on a typical XEN_DOMCTL_destroydomain hypercall. No net change in behaviour. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk RFC. While testing this, I observed this, after faking up an -ENOMEM in dom0's construction: (XEN) [2020-12-21 16:31:20] NX (Execute Disable) protection active (XEN) [2020-12-21 16:33:04] (XEN) [2020-12-21 16:33:04] **************************************** (XEN) [2020-12-21 16:33:04] Panic on CPU 0: (XEN) [2020-12-21 16:33:04] Error creating domain 0 (XEN) [2020-12-21 16:33:04] **************************************** XSA-344 appears to have added nearly 2 minutes of wallclock time into the domain_create() error path, which isn't ok. Considering that event channels haven't even been initialised in this particular scenario, it ought to take ~0 time. Even if event channels have been initalised, none can be active as the domain isn't visible to the syst= em. --- xen/common/domain.c | 17 ++++++++--------- xen/common/event_channel.c | 8 ++++---- xen/include/xen/sched.h | 4 ++-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index ef1987335b..701747b9d9 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -284,6 +284,8 @@ custom_param("extra_guest_irqs", parse_extra_guest_irqs= ); */ static int domain_teardown(struct domain *d) { + int rc; + BUG_ON(!d->is_dying); =20 /* @@ -313,6 +315,10 @@ static int domain_teardown(struct domain *d) }; =20 case 0: + rc =3D evtchn_teardown(d); + if ( rc ) + return rc; + PROGRESS(done): break; =20 @@ -335,6 +341,8 @@ static void _domain_destroy(struct domain *d) BUG_ON(!d->is_dying); BUG_ON(atomic_read(&d->refcnt) !=3D DOMAIN_DESTROYED); =20 + evtchn_destroy(d); + xfree(d->pbuf); =20 argo_destroy(d); @@ -598,11 +606,7 @@ struct domain *domain_create(domid_t domid, if ( init_status & INIT_gnttab ) grant_table_destroy(d); if ( init_status & INIT_evtchn ) - { - evtchn_destroy(d); - evtchn_destroy_final(d); radix_tree_destroy(&d->pirq_tree, free_pirq_struct); - } if ( init_status & INIT_watchdog ) watchdog_domain_destroy(d); =20 @@ -792,9 +796,6 @@ int domain_kill(struct domain *d) rc =3D domain_teardown(d); if ( rc ) break; - rc =3D evtchn_destroy(d); - if ( rc ) - break; rc =3D domain_relinquish_resources(d); if ( rc !=3D 0 ) break; @@ -987,8 +988,6 @@ static void complete_domain_destroy(struct rcu_head *he= ad) if ( d->target !=3D NULL ) put_domain(d->target); =20 - evtchn_destroy_final(d); - radix_tree_destroy(&d->pirq_tree, free_pirq_struct); =20 xfree(d->vcpu); diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c index 4a48094356..c1af54eed5 100644 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -1401,7 +1401,7 @@ void free_xen_event_channel(struct domain *d, int por= t) { /* * Make sure ->is_dying is read /after/ ->valid_evtchns, pairing - * with the spin_barrier() and BUG_ON() in evtchn_destroy(). + * with the spin_barrier() and BUG_ON() in evtchn_teardown(). */ smp_rmb(); BUG_ON(!d->is_dying); @@ -1421,7 +1421,7 @@ void notify_via_xen_event_channel(struct domain *ld, = int lport) { /* * Make sure ->is_dying is read /after/ ->valid_evtchns, pairing - * with the spin_barrier() and BUG_ON() in evtchn_destroy(). + * with the spin_barrier() and BUG_ON() in evtchn_teardown(). */ smp_rmb(); ASSERT(ld->is_dying); @@ -1499,7 +1499,7 @@ int evtchn_init(struct domain *d, unsigned int max_po= rt) return 0; } =20 -int evtchn_destroy(struct domain *d) +int evtchn_teardown(struct domain *d) { unsigned int i; =20 @@ -1534,7 +1534,7 @@ int evtchn_destroy(struct domain *d) } =20 =20 -void evtchn_destroy_final(struct domain *d) +void evtchn_destroy(struct domain *d) { unsigned int i, j; =20 diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 3f35c537b8..bb22eeca38 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -142,8 +142,8 @@ struct evtchn } __attribute__((aligned(64))); =20 int evtchn_init(struct domain *d, unsigned int max_port); -int evtchn_destroy(struct domain *d); /* from domain_kill */ -void evtchn_destroy_final(struct domain *d); /* from complete_domain_destr= oy */ +int evtchn_teardown(struct domain *d); +void evtchn_destroy(struct domain *d); =20 struct waitqueue_vcpu; =20 --=20 2.11.0