From patchwork Fri Feb 21 10:42:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11396121 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 92F4A930 for ; Fri, 21 Feb 2020 10:43:20 +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 6F29520722 for ; Fri, 21 Feb 2020 10:43:20 +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="Hk6ES/Al" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6F29520722 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 1j55lA-00018z-T2; Fri, 21 Feb 2020 10:42:16 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j55l9-00018u-Q1 for xen-devel@lists.xenproject.org; Fri, 21 Feb 2020 10:42:15 +0000 X-Inumbo-ID: d2a3498c-5496-11ea-ade5-bc764e2007e4 Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d2a3498c-5496-11ea-ade5-bc764e2007e4; Fri, 21 Feb 2020 10:42:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1582281735; x=1613817735; h=from:to:cc:subject:date:message-id:mime-version; bh=oVvCqE3UBYAoNn/m2KoZp9FaTfLcLb8rPOOd+6lsbms=; b=Hk6ES/AlRaXVBBeqKzqgNJoMSn40IUoX2XEOOf6M7WsxyzNEz1LbEJQH +7/LAdRsLaAWO5rW/+N9rZCZwe1HEyN7A0RHnTl1Nc0MkBPbztJpKKZMM xUQ+Y1Er669umT7dDUorh+xmNp9yiEHS4xhe/gJ/gJ7KysP2w6YrjnRFX o=; IronPort-SDR: hbxdbPRVhftFDX7CtMYMPqDtyeXgnHE4THSf0jJgLxAw5fJf8/fqQZjYiHAvZQzyf/h+jzoORl AKwXklKSb7fg== X-IronPort-AV: E=Sophos;i="5.70,467,1574121600"; d="scan'208";a="28043467" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2c-4e7c8266.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 21 Feb 2020 10:42:13 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2c-4e7c8266.us-west-2.amazon.com (Postfix) with ESMTPS id 3CBC7A1E1F; Fri, 21 Feb 2020 10:42:12 +0000 (UTC) Received: from EX13D37EUB003.ant.amazon.com (10.43.166.251) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Fri, 21 Feb 2020 10:42:12 +0000 Received: from EX13MTAUEA001.ant.amazon.com (10.43.61.82) by EX13D37EUB003.ant.amazon.com (10.43.166.251) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 21 Feb 2020 10:42:10 +0000 Received: from u0b3720fa96e858.ant.amazon.com (10.125.106.133) by mail-relay.amazon.com (10.43.61.243) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Fri, 21 Feb 2020 10:42:08 +0000 From: Hongyan Xia To: Date: Fri, 21 Feb 2020 10:42:03 +0000 Message-ID: <27c7736ec643dd0dd3cf469e6dc57f9d36379dcb.1582281718.git.hongyxia@amazon.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH] 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 , George Dunlap , Andrew Cooper , Ian Jackson , 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 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 in unmap_domain_page. Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia --- xen/arch/x86/domain_page.c | 2 +- xen/arch/x86/mm.c | 14 ++++++++------ xen/include/xen/domain_page.h | 5 +++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/domain_page.c b/xen/arch/x86/domain_page.c index dd32712d2f..b03728e18e 100644 --- a/xen/arch/x86/domain_page.c +++ b/xen/arch/x86/domain_page.c @@ -181,7 +181,7 @@ void unmap_domain_page(const void *ptr) unsigned long va = (unsigned long)ptr, mfn, flags; struct vcpu_maphash_entry *hashent; - if ( va >= DIRECTMAP_VIRT_START ) + if ( !va || va >= DIRECTMAP_VIRT_START ) return; ASSERT(va >= MAPCACHE_VIRT_START && va < MAPCACHE_VIRT_END); 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..a182d33b67 100644 --- a/xen/include/xen/domain_page.h +++ b/xen/include/xen/domain_page.h @@ -72,4 +72,9 @@ static inline void unmap_domain_page_global(const void *va) {}; #endif /* !CONFIG_DOMAIN_PAGE */ +#define UNMAP_DOMAIN_PAGE(p) do { \ + unmap_domain_page(p); \ + (p) = NULL; \ +} while ( false ) + #endif /* __XEN_DOMAIN_PAGE_H__ */