From patchwork Mon Apr 27 16:36:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamas K Lengyel X-Patchwork-Id: 11512987 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BB724912 for ; Mon, 27 Apr 2020 16:37:02 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id A2BAD20663 for ; Mon, 27 Apr 2020 16:37:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A2BAD20663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Inumbo-ID: 370f49d8-88a5-11ea-b9cf-bc764e2007e4 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) IronPort-SDR: 6aKooz1thBqvXDvwqwubCtsRfPA4ZJdjTh2JQkaKZZGZKF3Q80cPJEwg3x0mrJ1wi839j+W7pn SKWy4e45k6pA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False 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 IronPort-SDR: fIxKDoxW3NEB5x0T+1W2eUbk66JHIjak0g21kHPa7AFHzxGqpCiPR93bd1TRSH7U+PAEforAfx MAAfaMbbD5lA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,324,1583222400"; d="scan'208";a="247457283" 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 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 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_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" During a VM fork we copy the shared_info page; however, we also need to ensure 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 = p2m_get_hostp2m(cd); static const unsigned int params[] = { @@ -1701,6 +1702,34 @@ static int copy_special_pages(struct domain *cd, struct domain *d) new_mfn = _mfn(virt_to_mfn(cd->shared_info)); copy_domain_page(new_mfn, old_mfn); + old_gfn = _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 = _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 = p2m->set_entry(p2m, new_gfn, INVALID_MFN, PAGE_ORDER_4K, + p2m_invalid, p2m->default_access, -1); + if ( rc ) + return rc; + + new_gfn = INVALID_GFN; + } + + if ( gfn_eq(new_gfn, INVALID_GFN) ) + { + /* if shared info is not currently mapped then map it */ + rc = p2m->set_entry(p2m, old_gfn, new_mfn, PAGE_ORDER_4K, + p2m_ram_rw, p2m->default_access, -1); + if ( rc ) + return rc; + } + } + return 0; }