From patchwork Mon Sep 30 10:33:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11166403 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 E066613BD for ; Mon, 30 Sep 2019 10:35:52 +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 BC97321855 for ; Mon, 30 Sep 2019 10:35:52 +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="HY+nhe6I" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC97321855 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 1iEt1F-0007fx-JI; Mon, 30 Sep 2019 10:35:05 +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 1iEt1E-0007ex-Rq for xen-devel@lists.xenproject.org; Mon, 30 Sep 2019 10:35:04 +0000 X-Inumbo-ID: ee832c70-e36d-11e9-96cd-12813bfff9fa Received: from smtp-fw-2101.amazon.com (unknown [72.21.196.25]) by localhost (Halon) with ESMTPS id ee832c70-e36d-11e9-96cd-12813bfff9fa; Mon, 30 Sep 2019 10:34:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1569839690; x=1601375690; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=HOlQh5k1oNPRVyL9EqE56c5arborDHenMa3MWF/9pfs=; b=HY+nhe6Ib1orxn5CDGGEDstp8oZoYsU4k+VAuaeQgRdc36v3TmrhQA4x d5N8xfLLpT4G2W1nRTcTuZW0jAzrPFYZmic2o98gr3dHwt3lawHzsryTQ hVICG7pzDwz4HeqCDZjtCfiWPI+npGlaLSRcfwG1AKauR4Zh+4sreAam5 c=; X-IronPort-AV: E=Sophos;i="5.64,565,1559520000"; d="scan'208";a="754242253" Received: from iad6-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1d-37fd6b3d.us-east-1.amazon.com) ([10.124.125.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 30 Sep 2019 10:34:50 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1d-37fd6b3d.us-east-1.amazon.com (Postfix) with ESMTPS id CAAA8282413; Mon, 30 Sep 2019 10:34:48 +0000 (UTC) Received: from EX13D09UEE001.ant.amazon.com (10.43.62.205) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 30 Sep 2019 10:34:20 +0000 Received: from EX13MTAUEE001.ant.amazon.com (10.43.62.200) by EX13D09UEE001.ant.amazon.com (10.43.62.205) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 30 Sep 2019 10:34:20 +0000 Received: from u9d785c4ba99158.ant.amazon.com (10.125.106.78) by mail-relay.amazon.com (10.43.62.226) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Mon, 30 Sep 2019 10:34:19 +0000 From: Hongyan Xia To: Date: Mon, 30 Sep 2019 11:33:24 +0100 Message-ID: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH v2 32/55] 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 , Jan Beulich , =?utf-8?q?Roger_Pau_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)