From nobody Sun May 5 19:06:07 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; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1588087783; cv=none; d=zohomail.com; s=zohoarc; b=ZEkzr2n/DilaFOm/GnV9gNZ+oeCEABBqDJorV4Sf9l0tTQPM34NyNZ7TzmjxEihOTxydnDdxDFMmA0tuMN4XnmxYpu1VzHfEKYm0bLoViba2dN3fwWAGGU2g6fSNm3t3DKrCtYgKwHSCrylhow7O50hUwFDDQAUsoSPDho6RNjw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588087783; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=E77G68AZA19hc44tTdtib/RQxxVsHT44iLI3dIwPQTk=; b=NW22MaqfGhsgc8cxHchjOGdErnxsvtD1Ce8gSGfXYnXQzYlT1PO7TpV7AQ4SvIQ0K9OAJ+ZgScahRhiecX+bzu++LU88k/bgN6MoE+ruK8ob+/uyzcmBuQ1/r4pyeIgtIZzTzOFLlxtJ4+38Lq6rV7+TV4C0tAv/pP8pVeh8QAk= ARC-Authentication-Results: i=1; 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; dmarc=fail header.from= (p=none 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 1588087783491315.381024967485; Tue, 28 Apr 2020 08:29:43 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jTSAd-0004e4-Pb; Tue, 28 Apr 2020 15:29:15 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jTSAc-0004dz-JO for xen-devel@lists.xenproject.org; Tue, 28 Apr 2020 15:29:14 +0000 Received: from mga06.intel.com (unknown [134.134.136.31]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 026b3d0c-8965-11ea-b9cf-bc764e2007e4; Tue, 28 Apr 2020 15:29:11 +0000 (UTC) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2020 08:29:10 -0700 Received: from saborios-mobl3.amr.corp.intel.com (HELO localhost.localdomain) ([10.213.167.78]) by FMSMGA003.fm.intel.com with ESMTP; 28 Apr 2020 08:29:09 -0700 X-Inumbo-ID: 026b3d0c-8965-11ea-b9cf-bc764e2007e4 IronPort-SDR: EdMYaLnUHsftwJTNCVwDNzKpjjKDqJs94bQxQDIwTiV6JPJhyhJYeKTBU9tnwkngHNDZhoIUvd Q1aPO5MyoqHw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False IronPort-SDR: xj0EbWvHko3qZ+zrB/VnZT14E9RwkXTMaOZtUZ539XzXawhJoh+nXipBTLHQHjab549XZxzWQG srL6R4Yhue6w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,328,1583222400"; d="scan'208";a="302736438" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Subject: [PATCH v2] mem_sharing: map shared_info page to same gfn during fork Date: Tue, 28 Apr 2020 08:29:00 -0700 Message-Id: <6497e71a791bbc17b1ace3f5f260bd61275b76ba.1588087596.git.tamas.lengyel@intel.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Tamas K Lengyel , Tamas K Lengyel , Wei Liu , Andrew Cooper , George Dunlap , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Type: text/plain; charset="utf-8" During a VM fork we copy the shared_info page; however, we also need to ens= ure that the page is mapped into the same GFN in the fork as its in the parent. Signed-off-by: Tamas K Lengyel Suggested-by: Roger Pau Monne Reviewed-by: Roger Pau Monn=C3=A9 --- xen/arch/x86/mm/mem_sharing.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index 344a5bfb3d..a1dea8fedb 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -1656,6 +1656,7 @@ static void copy_tsc(struct domain *cd, struct domain= *d) static int copy_special_pages(struct domain *cd, struct domain *d) { mfn_t new_mfn, old_mfn; + gfn_t new_gfn, old_gfn; struct p2m_domain *p2m =3D p2m_get_hostp2m(cd); static const unsigned int params[] =3D { @@ -1701,6 +1702,30 @@ static int copy_special_pages(struct domain *cd, str= uct domain *d) new_mfn =3D _mfn(virt_to_mfn(cd->shared_info)); copy_domain_page(new_mfn, old_mfn); =20 + old_gfn =3D _gfn(get_gpfn_from_mfn(mfn_x(old_mfn))); + new_gfn =3D _gfn(get_gpfn_from_mfn(mfn_x(new_mfn))); + + if ( !gfn_eq(old_gfn, new_gfn) ) + { + if ( !gfn_eq(new_gfn, INVALID_GFN) ) + { + /* if shared_info is mapped to a different gfn just remove it = */ + rc =3D p2m->set_entry(p2m, new_gfn, INVALID_MFN, PAGE_ORDER_4K, + p2m_invalid, p2m->default_access, -1); + if ( rc ) + return rc; + } + + if ( !gfn_eq(old_gfn, INVALID_GFN) ) + { + /* now map it to the same gfn as the parent */ + rc =3D p2m->set_entry(p2m, old_gfn, new_mfn, PAGE_ORDER_4K, + p2m_ram_rw, p2m->default_access, -1); + if ( rc ) + return rc; + } + } + return 0; } =20 --=20 2.20.1