From patchwork Thu Sep 26 09:45:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11162079 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 C707F13BD for ; Thu, 26 Sep 2019 09:49:22 +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 A1C48222C0 for ; Thu, 26 Sep 2019 09:49:22 +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="IlM/KF4q" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A1C48222C0 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 1iDQO0-0004eB-EV; Thu, 26 Sep 2019 09:48:32 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDQNy-0004bU-O5 for xen-devel@lists.xenproject.org; Thu, 26 Sep 2019 09:48:30 +0000 X-Inumbo-ID: c6a914e0-e042-11e9-964c-12813bfff9fa Received: from smtp-fw-4101.amazon.com (unknown [72.21.198.25]) by localhost (Halon) with ESMTPS id c6a914e0-e042-11e9-964c-12813bfff9fa; Thu, 26 Sep 2019 09:48:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1569491301; x=1601027301; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=HOlQh5k1oNPRVyL9EqE56c5arborDHenMa3MWF/9pfs=; b=IlM/KF4qOHtiHobdIhoy4X9IQKrT7Z/OOlTfJ6iGL3z10hBx4FYvTdTs 6dvfDM/kb539B7sKCllwfWiawVSFIPMfU+QULXjtvj9A4X9gVWYxyhJFB Zhv0+joeWcrUveDuNYEo6EEG1TZbRZbnoF3uOFQ+hkLb+BE1fjn55D5BK M=; X-IronPort-AV: E=Sophos;i="5.64,551,1559520000"; d="scan'208";a="787535108" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1d-38ae4ad2.us-east-1.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 26 Sep 2019 09:48:21 +0000 Received: from EX13MTAUWA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1d-38ae4ad2.us-east-1.amazon.com (Postfix) with ESMTPS id 53C5DA299F; Thu, 26 Sep 2019 09:48:19 +0000 (UTC) Received: from EX13D18UWA004.ant.amazon.com (10.43.160.45) by EX13MTAUWA001.ant.amazon.com (10.43.160.58) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 26 Sep 2019 09:47:53 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX13D18UWA004.ant.amazon.com (10.43.160.45) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 26 Sep 2019 09:47:52 +0000 Received: from u9d785c4ba99158.ant.amazon.com (10.125.106.58) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Thu, 26 Sep 2019 09:47:51 +0000 From: To: Date: Thu, 26 Sep 2019 10:45:56 +0100 Message-ID: <8f0acf3643328ce680cb9aac0eccb7d724fd1b40.1569489002.git.hongyax@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [RFC PATCH 33/84] efi: switch EFI L4 table to use new APIs 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: Andrew Cooper , Wei Liu , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_?= =?utf-8?q?Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Wei Liu This requires storing the MFN instead of linear address of the L4 table. Adjust code accordingly. Signed-off-by: Wei Liu --- xen/arch/x86/efi/runtime.h | 12 +++++++++--- xen/common/efi/boot.c | 8 ++++++-- xen/common/efi/efi.h | 3 ++- xen/common/efi/runtime.c | 8 ++++---- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/xen/arch/x86/efi/runtime.h b/xen/arch/x86/efi/runtime.h index d9eb8f5c27..277d237953 100644 --- a/xen/arch/x86/efi/runtime.h +++ b/xen/arch/x86/efi/runtime.h @@ -2,11 +2,17 @@ #include #ifndef COMPAT -l4_pgentry_t *__read_mostly efi_l4_pgtable; +mfn_t __read_mostly efi_l4_mfn = INVALID_MFN_INITIALIZER; void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e) { - if ( efi_l4_pgtable ) - l4e_write(efi_l4_pgtable + l4idx, l4e); + if ( !mfn_eq(efi_l4_mfn, INVALID_MFN) ) + { + l4_pgentry_t *l4t; + + l4t = map_xen_pagetable_new(efi_l4_mfn); + l4e_write(l4t + l4idx, l4e); + UNMAP_XEN_PAGETABLE_NEW(l4t); + } } #endif diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 3868293d06..f55d6a6d76 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -1488,6 +1488,7 @@ void __init efi_init_memory(void) unsigned int prot; } *extra, *extra_head = NULL; #endif + l4_pgentry_t *efi_l4_pgtable; free_ebmalloc_unused_mem(); @@ -1603,8 +1604,9 @@ void __init efi_init_memory(void) mdesc_ver, efi_memmap); #else /* Set up 1:1 page tables to do runtime calls in "physical" mode. */ - efi_l4_pgtable = alloc_xen_pagetable(); - BUG_ON(!efi_l4_pgtable); + efi_l4_mfn = alloc_xen_pagetable_new(); + BUG_ON(mfn_eq(efi_l4_mfn, INVALID_MFN)); + efi_l4_pgtable = map_xen_pagetable_new(efi_l4_mfn); clear_page(efi_l4_pgtable); copy_mapping(efi_l4_pgtable, 0, max_page, ram_range_valid); @@ -1703,6 +1705,8 @@ void __init efi_init_memory(void) i < l4_table_offset(DIRECTMAP_VIRT_END); ++i ) efi_l4_pgtable[i] = idle_pg_table[i]; #endif + + UNMAP_XEN_PAGETABLE_NEW(efi_l4_pgtable); } #endif diff --git a/xen/common/efi/efi.h b/xen/common/efi/efi.h index 6b9c56ead1..139b660ed7 100644 --- a/xen/common/efi/efi.h +++ b/xen/common/efi/efi.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -29,7 +30,7 @@ extern UINTN efi_memmap_size, efi_mdesc_size; extern void *efi_memmap; #ifdef CONFIG_X86 -extern l4_pgentry_t *efi_l4_pgtable; +extern mfn_t efi_l4_mfn; #endif extern const struct efi_pci_rom *efi_pci_roms; diff --git a/xen/common/efi/runtime.c b/xen/common/efi/runtime.c index ab53ebcc55..d4b04a04f4 100644 --- a/xen/common/efi/runtime.c +++ b/xen/common/efi/runtime.c @@ -85,7 +85,7 @@ struct efi_rs_state efi_rs_enter(void) static const u32 mxcsr = MXCSR_DEFAULT; struct efi_rs_state state = { .cr3 = 0 }; - if ( !efi_l4_pgtable ) + if ( mfn_eq(efi_l4_mfn, INVALID_MFN) ) return state; state.cr3 = read_cr3(); @@ -111,7 +111,7 @@ struct efi_rs_state efi_rs_enter(void) lgdt(&gdt_desc); } - switch_cr3_cr4(virt_to_maddr(efi_l4_pgtable), read_cr4()); + switch_cr3_cr4(mfn_to_maddr(efi_l4_mfn), read_cr4()); return state; } @@ -140,9 +140,9 @@ void efi_rs_leave(struct efi_rs_state *state) bool efi_rs_using_pgtables(void) { - return efi_l4_pgtable && + return !mfn_eq(efi_l4_mfn, INVALID_MFN) && (smp_processor_id() == efi_rs_on_cpu) && - (read_cr3() == virt_to_maddr(efi_l4_pgtable)); + (read_cr3() == mfn_to_maddr(efi_l4_mfn)); } unsigned long efi_get_time(void)