From nobody Thu May 2 16:09:47 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=1588005414; cv=none; d=zohomail.com; s=zohoarc; b=UThR+WHm4FI5tbn4pVd0bbY+gcPdyKhOvSL7LBZQqY4G3AHqHeLnMNJF2AcgEPqgqegmNUnXR/Mg1hn+cjGHr/MGHZVy7+3C4XujzGw9eV+Oevf2vM6A3Vjjf1Ny4Qdl7Ve04eo2XGtnPRbwoCKXQS6CwP2BED8C8ynsfcrop88= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588005414; 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=OUvgbPvY0dzi34n/A48XyrcAGl9m3VoDU7Swy6s1QVI=; b=Lm3IYxTYMvj9jtHQFpxl4yDJi8NQW+gLXzaLFddU0VOOrxsgGrKnOTMK4/LeRgP0/s3uq7Ex4ewsy1Pc9ZjiLeWf6Zal8y4vWDwcOO9XpaaCCxvloFm8JEiuSedHwnB62VZNmPDvOnwRTSSYmaGvv9F4xfVlQ4q6PW20l92TyWQ= 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 1588005414521971.9950611910259; Mon, 27 Apr 2020 09:36:54 -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 1jT6k0-0005Bw-CF; Mon, 27 Apr 2020 16:36:20 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jT6jz-0005Br-HO for xen-devel@lists.xenproject.org; Mon, 27 Apr 2020 16:36:19 +0000 Received: from mga12.intel.com (unknown [192.55.52.136]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 370f49d8-88a5-11ea-b9cf-bc764e2007e4; Mon, 27 Apr 2020 16:36:16 +0000 (UTC) Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2020 09:36:15 -0700 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.135.4.141]) by fmsmga007.fm.intel.com with ESMTP; 27 Apr 2020 09:36:14 -0700 X-Inumbo-ID: 370f49d8-88a5-11ea-b9cf-bc764e2007e4 IronPort-SDR: 6aKooz1thBqvXDvwqwubCtsRfPA4ZJdjTh2JQkaKZZGZKF3Q80cPJEwg3x0mrJ1wi839j+W7pn SKWy4e45k6pA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False IronPort-SDR: fIxKDoxW3NEB5x0T+1W2eUbk66JHIjak0g21kHPa7AFHzxGqpCiPR93bd1TRSH7U+PAEforAfx MAAfaMbbD5lA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,324,1583222400"; d="scan'208";a="247457283" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Subject: [PATCH] mem_sharing: map shared_info page to same gfn during fork Date: Mon, 27 Apr 2020 09:36:05 -0700 Message-Id: <08d022bbca06c59624817ac9e23ddcb288121763.1588004969.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 --- xen/arch/x86/mm/mem_sharing.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index 344a5bfb3d..acbf21b22c 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 old_gfn; struct p2m_domain *p2m =3D p2m_get_hostp2m(cd); static const unsigned int params[] =3D { @@ -1701,6 +1702,34 @@ 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))); + + if ( !gfn_eq(old_gfn, INVALID_GFN) ) + { + /* let's make sure shared_info is mapped to the same gfn */ + gfn_t new_gfn =3D _gfn(get_gpfn_from_mfn(mfn_x(new_mfn))); + + if ( !gfn_eq(new_gfn, INVALID_GFN) && !gfn_eq(old_gfn, new_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; + + new_gfn =3D INVALID_GFN; + } + + if ( gfn_eq(new_gfn, INVALID_GFN) ) + { + /* if shared info is not currently mapped then map it */ + 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