From patchwork Thu Feb 27 10:27:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11408251 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 C0547924 for ; Thu, 27 Feb 2020 10:29:10 +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 9CBD324691 for ; Thu, 27 Feb 2020 10:29:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="TXQh0hau" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9CBD324691 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=none 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.89) (envelope-from ) id 1j7GOk-0003gB-VC; Thu, 27 Feb 2020 10:28:06 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j7GOj-0003g6-EA for xen-devel@lists.xenproject.org; Thu, 27 Feb 2020 10:28:05 +0000 X-Inumbo-ID: d6c5be5a-594b-11ea-9c17-bc764e2007e4 Received: from smtp-fw-6001.amazon.com (unknown [52.95.48.154]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d6c5be5a-594b-11ea-9c17-bc764e2007e4; Thu, 27 Feb 2020 10:28:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1582799286; x=1614335286; h=from:to:cc:subject:date:message-id:mime-version; bh=bozTLwurkM4j//NT4sbJrL0L1X5s2qdTkBGBFJ75zqc=; b=TXQh0hauM9A2qXwTvb8WbssIdaICcm1bL5LHEqkQ+2KjBUBUH1K4lock cNP46HEciHoFkxB44b5sYzDv5ZniDZ6B25JDR1+WIbiMEBf4yFA58yfS0 WqGzNGO5TUPk6FUwBgqdofzwcFb4CkBFzwXVDZ8YudhwaANzLIp1nb6hF w=; IronPort-SDR: xfbajrZ8pqhO85/jCyQjnN/8tu9U5T1bSxU/0XcJ1WA3DdX89XpflhS4lqQMRL0z260+0fyk9o I48zduIiP2ZQ== X-IronPort-AV: E=Sophos;i="5.70,491,1574121600"; d="scan'208";a="19927560" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-1968f9fa.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 27 Feb 2020 10:27:52 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2c-1968f9fa.us-west-2.amazon.com (Postfix) with ESMTPS id 6D9E0A2BD3; Thu, 27 Feb 2020 10:27:50 +0000 (UTC) Received: from EX13D37EUA003.ant.amazon.com (10.43.165.7) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Thu, 27 Feb 2020 10:27:50 +0000 Received: from EX13MTAUWC001.ant.amazon.com (10.43.162.135) by EX13D37EUA003.ant.amazon.com (10.43.165.7) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 27 Feb 2020 10:27:47 +0000 Received: from u0b3720fa96e858.ant.amazon.com (10.125.106.133) by mail-relay.amazon.com (10.43.162.232) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Thu, 27 Feb 2020 10:27:44 +0000 From: Hongyan Xia To: Date: Thu, 27 Feb 2020 10:27:39 +0000 Message-ID: X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH v2] x86/mm: switch to new APIs in arch_init_memory X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Konrad Rzeszutek Wilk , Andrew Cooper , Ian Jackson , George Dunlap , Hongyan Xia , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Wei Liu The function will map and unmap pages on demand. Since we now map and unmap Xen PTE pages, we would like to track the lifetime of mappings so that 1) we do not dereference memory through a variable after it is unmapped, 2) we do not unmap more than once. Therefore, we introduce the UNMAP_DOMAIN_PAGE macro to nullify the variable after unmapping, and ignore NULL. Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia Reviewed-by: Jan Beulich --- Changed in v2: - let UNMAP_DOMAIN_PAGE itself check whether the input is NULL to avoid adding the check in unmap_domain_page. - reword the commit message. --- xen/arch/x86/mm.c | 14 ++++++++------ xen/include/xen/domain_page.h | 7 +++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 70b87c4830..9fcdcde5b7 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -356,19 +356,21 @@ void __init arch_init_memory(void) ASSERT(root_pgt_pv_xen_slots < ROOT_PAGETABLE_PV_XEN_SLOTS); if ( l4_table_offset(split_va) == l4_table_offset(split_va - 1) ) { - l3_pgentry_t *l3tab = alloc_xen_pagetable(); + mfn_t l3mfn = alloc_xen_pagetable_new(); - if ( l3tab ) + if ( !mfn_eq(l3mfn, INVALID_MFN) ) { - const l3_pgentry_t *l3idle = - l4e_to_l3e(idle_pg_table[l4_table_offset(split_va)]); + l3_pgentry_t *l3idle = map_l3t_from_l4e( + idle_pg_table[l4_table_offset(split_va)]); + l3_pgentry_t *l3tab = map_domain_page(l3mfn); for ( i = 0; i < l3_table_offset(split_va); ++i ) l3tab[i] = l3idle[i]; for ( ; i < L3_PAGETABLE_ENTRIES; ++i ) l3tab[i] = l3e_empty(); - split_l4e = l4e_from_mfn(virt_to_mfn(l3tab), - __PAGE_HYPERVISOR_RW); + split_l4e = l4e_from_mfn(l3mfn, __PAGE_HYPERVISOR_RW); + UNMAP_DOMAIN_PAGE(l3idle); + UNMAP_DOMAIN_PAGE(l3tab); } else ++root_pgt_pv_xen_slots; diff --git a/xen/include/xen/domain_page.h b/xen/include/xen/domain_page.h index 32669a3339..bfc3bf6aeb 100644 --- a/xen/include/xen/domain_page.h +++ b/xen/include/xen/domain_page.h @@ -72,4 +72,11 @@ static inline void unmap_domain_page_global(const void *va) {}; #endif /* !CONFIG_DOMAIN_PAGE */ +#define UNMAP_DOMAIN_PAGE(p) do { \ + if ( p ) { \ + unmap_domain_page(p); \ + (p) = NULL; \ + } \ +} while ( false ) + #endif /* __XEN_DOMAIN_PAGE_H__ */