From nobody Sun May 12 02:34:06 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; 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1676480928497976.2299415151059; Wed, 15 Feb 2023 09:08:48 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.496156.766742 (Exim 4.92) (envelope-from ) id 1pSLGV-0002y7-AA; Wed, 15 Feb 2023 17:08:19 +0000 Received: by outflank-mailman (output) from mailman id 496156.766742; Wed, 15 Feb 2023 17:08:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pSLGV-0002y0-7e; Wed, 15 Feb 2023 17:08:19 +0000 Received: by outflank-mailman (input) for mailman id 496156; Wed, 15 Feb 2023 17:08:17 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pSLGT-0002xu-RS for xen-devel@lists.xenproject.org; Wed, 15 Feb 2023 17:08:17 +0000 Received: from MTA-08-3.privateemail.com (mta-08-3.privateemail.com [198.54.127.61]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 55e72334-ad53-11ed-933c-83870f6b2ba8; Wed, 15 Feb 2023 18:08:16 +0100 (CET) Received: from mta-08.privateemail.com (localhost [127.0.0.1]) by mta-08.privateemail.com (Postfix) with ESMTP id 7108818000A1; Wed, 15 Feb 2023 12:08:14 -0500 (EST) Received: from localhost.localdomain (c-73-126-95-14.hsd1.ma.comcast.net [73.126.95.14]) by mta-08.privateemail.com (Postfix) with ESMTPA id 041A918000A0; Wed, 15 Feb 2023 12:08:06 -0500 (EST) 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: 55e72334-ad53-11ed-933c-83870f6b2ba8 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=tklengyel.com; s=default; t=1676480894; bh=w68mtRdRllSdCaMn2vsvCBnT6Q4zJSnE9BFgcS4DrkY=; h=From:To:Cc:Subject:Date:From; b=lYfHmOk+bF1+8+b/5OEVqlCveopUzDzCDj4WdrwgpHxg11wLRMRYZSkNMxUBMm/DR ha1Cq6ucFTcUDi/pPDqnl3ueSjYIbonuPLqju0pqRxmJTENX/NCEenJlSWQ38d24E8 OfeomqOU6/tg/Nrt1EOiiXmTEb8IGkwyTbMya4UI9JTC/zSSH81i1PyCwGk7kXJij1 vKOzrJwQrIHtthcXLFkmqCLutOqAh+Al4Rc8lTe8hBiVjuBEMsqe4qGvjJHG/AvQSH khJlwkHVzRj6csFsbVfIM62CRNENApEA13XZn+iVv8IfvJZ4/iMLCRzgbALWgxhCdL rM1dDL79SkZSw== From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Cc: Tamas K Lengyel , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v2] x86: Perform mem_sharing teardown before paging teardown Date: Wed, 15 Feb 2023 12:07:58 -0500 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: ClamAV using ClamSMTP X-ZM-MESSAGEID: 1676480929084100001 Content-Type: text/plain; charset="utf-8" An assert failure has been observed in p2m_teardown when performing vm forking and then destroying the forked VM (p2m-basic.c:173). The assert checks whether the domain's shared pages counter is 0. According to the patch that originally added the assert (7bedbbb5c31) the p2m_teardown should only happen after mem_sharing already relinquished all shared pages. In this patch we flip the order in which relinquish ops are called to avoid tripping the assert. Signed-off-by: Tamas K Lengyel Fixes: e7aa55c0aab3 ("x86/p2m: free the paging memory pool preemptively") --- v2: comsetic fixes --- xen/arch/x86/domain.c | 56 ++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index db3ebf062d..a42f03e8e5 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -2289,9 +2289,9 @@ int domain_relinquish_resources(struct domain *d) =20 enum { PROG_iommu_pagetables =3D 1, + PROG_shared, PROG_paging, PROG_vcpu_pagetables, - PROG_shared, PROG_xen, PROG_l4, PROG_l3, @@ -2310,6 +2310,34 @@ int domain_relinquish_resources(struct domain *d) if ( ret ) return ret; =20 +#ifdef CONFIG_MEM_SHARING + PROGRESS(shared): + + if ( is_hvm_domain(d) ) + { + /* + * If the domain has shared pages, relinquish them allowing + * for preemption. + */ + ret =3D relinquish_shared_pages(d); + if ( ret ) + return ret; + + /* + * If the domain is forked, decrement the parent's pause count + * and release the domain. + */ + if ( mem_sharing_is_fork(d) ) + { + struct domain *parent =3D d->parent; + + d->parent =3D NULL; + domain_unpause(parent); + put_domain(parent); + } + } +#endif + PROGRESS(paging): =20 /* Tear down paging-assistance stuff. */ @@ -2350,32 +2378,6 @@ int domain_relinquish_resources(struct domain *d) d->arch.auto_unmask =3D 0; } =20 -#ifdef CONFIG_MEM_SHARING - PROGRESS(shared): - - if ( is_hvm_domain(d) ) - { - /* If the domain has shared pages, relinquish them allowing - * for preemption. */ - ret =3D relinquish_shared_pages(d); - if ( ret ) - return ret; - - /* - * If the domain is forked, decrement the parent's pause count - * and release the domain. - */ - if ( mem_sharing_is_fork(d) ) - { - struct domain *parent =3D d->parent; - - d->parent =3D NULL; - domain_unpause(parent); - put_domain(parent); - } - } -#endif - spin_lock(&d->page_alloc_lock); page_list_splice(&d->arch.relmem_list, &d->page_list); INIT_PAGE_LIST_HEAD(&d->arch.relmem_list); --=20 2.34.1