From patchwork Mon Oct 17 19:12:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13009296 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 68CA6C433FE for ; Mon, 17 Oct 2022 19:13:16 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.424560.672078 (Exim 4.92) (envelope-from ) id 1okVXp-0002L5-Nq; Mon, 17 Oct 2022 19:13:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 424560.672078; Mon, 17 Oct 2022 19:13:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1okVXp-0002Ks-Ii; Mon, 17 Oct 2022 19:13:01 +0000 Received: by outflank-mailman (input) for mailman id 424560; Mon, 17 Oct 2022 19:13:00 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1okVXo-0002HD-Ho for xen-devel@lists.xenproject.org; Mon, 17 Oct 2022 19:13:00 +0000 Received: from esa2.hc3370-68.iphmx.com (esa2.hc3370-68.iphmx.com [216.71.145.153]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b4fe2e1e-4e4f-11ed-8fd0-01056ac49cbb; Mon, 17 Oct 2022 21:12:58 +0200 (CEST) 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: b4fe2e1e-4e4f-11ed-8fd0-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1666033977; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=3xz6EapRYQ8Fq100GycK8t7tBLACDmNaRcneaz+jMYU=; b=WcFgxBqMVFotnGy+6pgnZFuwpAXUUgK7MZB9MnbBhshm6qyaYQU22BHU rV8YpJxD1RQsqMSnnl/Y6x5nHqzyfyKgi5xBYN20Gqw82xWrAwxil21Du PaRCeBICPxKsSXJh7Mzsmu6Wp7mHrcuzuFw50NH6HqRwFp9OnSJyNlCT2 c=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 5.1 X-MesageID: 82941464 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:SbhN46gKFI9U3uHyKlbXEaNMX17brhtdUexiu6ucsGfUl6mq9fgcCa95VXk6Z2cg+JsCT87dIK/hR2lo1aTMpqcRdC0qbbba9ML8jXdDsEdh0got7YTDm+eGxa96EqShD8hztsQ/Qs6ClDEHlkbm7waH7WG8GD/sfEhyUH/qkf4XmNGi54QvZhV9d5/T3i7rKkFnYMtekEl+kHxUpPyWbWFSNWBatcRp5sI0y+7nXA2X2W26sNl3O+Hy0Ws6jrqgd+NMm95ZRW9rDiPWRoOmI2VnAtMKlDE0aCcQT08n1SHPghHCSouinHd4hOQH6eVhpH/CTxbS0oIdu1fXFAizDVWXqwkerL28YlGpz0cRuKy9056ksWy40m6r8qECH5JjbHCHVJ1DCqIMGP5h+I+uJuU64SZFM3c+XX44IRTBgVwH7rxW0CXv82reKfUo4rlyUtsG1hRmMawlIKS7HWBvu8eYBiqbow0zN6WEB/mRK3uLF8YbG4HwiOXdyyz7xl22Q2Pq+Ro7dZYr0U4CgssW2SdzfIrFWH/cSXc/XBdW26Jyr3quf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JY7nZ1bveYjnHyuKHtTB+PxqpnJpASC2AqGElLDjvS2YxeVumhL0N+Ru19fbkE5hBZbSDxQvJjI19y/owmkxCM1w6yNl3b6f+xaKstx9y5Y2bwIpjFz05paFybmPwdy/IzfPwSt/E7vXdCT/g2yvh0o59A6tcs27Ig76ZhyXd4K5tUMpKtBp0hrEG4DA9Bbop1usC1MfuLfzu+O4KgXwKz5D/WiB7MUXmvT34p7VFoN0w== X-IronPort-AV: E=Sophos;i="5.95,192,1661832000"; d="scan'208";a="82941464" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis , Henry Wang Subject: [PATCH 1/2] arm/p2m: Rework p2m_init() Date: Mon, 17 Oct 2022 20:12:36 +0100 Message-ID: <20221017191237.11079-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20221017191237.11079-1-andrew.cooper3@citrix.com> References: <20221017191237.11079-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 p2m_init() is mostly trivial initialisation, but has two failable operations which are on either side of the backpointer trigger for teardown to take actions. p2m_free_vmid() is idempotent with a failed p2m_alloc_vmid(), so rearrange p2m_init() to perform all trivial setup, then set the backpointer, then perform all failable setup. This will simplify a future bugfix which needs to add a third failabile operation. No practical change. Signed-off-by: Andrew Cooper Reviewed-by: Julien Grall Reviewed-by: Bertrand Marquis --- CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Henry Wang --- xen/arch/arm/p2m.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index f17500ddf3a3..6826f6315080 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -1754,7 +1754,7 @@ void p2m_final_teardown(struct domain *d) int p2m_init(struct domain *d) { struct p2m_domain *p2m = p2m_get_hostp2m(d); - int rc = 0; + int rc; unsigned int cpu; rwlock_init(&p2m->lock); @@ -1763,11 +1763,6 @@ int p2m_init(struct domain *d) INIT_PAGE_LIST_HEAD(&d->arch.paging.p2m_freelist); p2m->vmid = INVALID_VMID; - - rc = p2m_alloc_vmid(d); - if ( rc != 0 ) - return rc; - p2m->max_mapped_gfn = _gfn(0); p2m->lowest_mapped_gfn = _gfn(ULONG_MAX); @@ -1783,8 +1778,6 @@ int p2m_init(struct domain *d) p2m->clean_pte = is_iommu_enabled(d) && !iommu_has_feature(d, IOMMU_FEAT_COHERENT_WALK); - rc = p2m_alloc_table(d); - /* * Make sure that the type chosen to is able to store the an vCPU ID * between 0 and the maximum of virtual CPUS supported as long as @@ -1797,13 +1790,20 @@ int p2m_init(struct domain *d) p2m->last_vcpu_ran[cpu] = INVALID_VCPU_ID; /* - * Besides getting a domain when we only have the p2m in hand, - * the back pointer to domain is also used in p2m_teardown() - * as an end-of-initialization indicator. + * "Trivial" initialisation is now complete. Set the backpointer so + * p2m_teardown() and friends know to do something. */ p2m->domain = d; - return rc; + rc = p2m_alloc_vmid(d); + if ( rc ) + return rc; + + rc = p2m_alloc_table(d); + if ( rc ) + return rc; + + return 0; } /*