From patchwork Thu Sep 26 09:46:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11162191 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 0990813BD for ; Thu, 26 Sep 2019 09:51:31 +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 D9F832053B for ; Thu, 26 Sep 2019 09:51:30 +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="NDAiXiSK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D9F832053B 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 1iDQQ5-0000qI-Mq; Thu, 26 Sep 2019 09:50:41 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDQQ2-0000jT-LP for xen-devel@lists.xenproject.org; Thu, 26 Sep 2019 09:50:38 +0000 X-Inumbo-ID: 0e7fd56a-e043-11e9-b588-bc764e2007e4 Received: from smtp-fw-2101.amazon.com (unknown [72.21.196.25]) by localhost (Halon) with ESMTPS id 0e7fd56a-e043-11e9-b588-bc764e2007e4; Thu, 26 Sep 2019 09:50:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1569491422; x=1601027422; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=+1jLygSDyv4GFQENO5qpV0Y2nFg1v//DHVeDCSUFn/g=; b=NDAiXiSKfqZTaxKhvvItUUqMB+IQIPWe80Mu1q1v7CsMQEyU/cp35Neb C8tMCcH6B5frX7M0j89HFshFN5Az/OwQBPgVFdCJXwIwXAI9Q+IkpS8fB 0kZwGh1APQqNXZbtlkh+Nk0cjFNdYaPfiCOkMIBc02hlIAdAEsqKku2r4 4=; X-IronPort-AV: E=Sophos;i="5.64,551,1559520000"; d="scan'208";a="753354491" Received: from iad6-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1a-af6a10df.us-east-1.amazon.com) ([10.124.125.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 26 Sep 2019 09:50:22 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1a-af6a10df.us-east-1.amazon.com (Postfix) with ESMTPS id 8FB9BA0702; Thu, 26 Sep 2019 09:50:20 +0000 (UTC) Received: from EX13D28EUC003.ant.amazon.com (10.43.164.43) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 26 Sep 2019 09:49:54 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX13D28EUC003.ant.amazon.com (10.43.164.43) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 26 Sep 2019 09:49: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:49:50 +0000 From: To: Date: Thu, 26 Sep 2019 10:46:40 +0100 Message-ID: <450fcebd6ad4cbf0b078070149b9287260bdc0a3.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 77/84] x86: properly (un)map pages in restore_all_guests. 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 , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= , Wei Liu , Jan Beulich , Hongyan Xia Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Hongyan Xia Before, it assumed both cr3 could be accessed via a direct map. This is no longer true. Also, this means we can remove a xenheap mapping hack we introduced earlier when building the cr3 of dom0. Signed-off-by: Hongyan Xia --- xen/arch/x86/pv/dom0_build.c | 11 +++++------ xen/arch/x86/x86_64/entry.S | 32 +++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index 0ec30988b8..202edcaa17 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -623,9 +623,7 @@ int __init dom0_construct_pv(struct domain *d, if ( !is_pv_32bit_domain(d) ) { maddr_to_page(mpt_alloc)->u.inuse.type_info = PGT_l4_page_table; - l4start = l4tab = __va(mpt_alloc); - map_pages_to_xen((unsigned long)l4start, maddr_to_mfn(mpt_alloc), 1, - PAGE_HYPERVISOR); + l4start = l4tab = map_xen_pagetable(maddr_to_mfn(mpt_alloc)); mpt_alloc += PAGE_SIZE; clear_page(l4tab); init_xen_l4_slots(l4tab, _mfn(virt_to_mfn(l4start)), @@ -635,9 +633,8 @@ int __init dom0_construct_pv(struct domain *d, else { /* Monitor table already created by switch_compat(). */ - l4start = l4tab = __va(pagetable_get_paddr(v->arch.guest_table)); - map_pages_to_xen((unsigned long)l4start, - pagetable_get_mfn(v->arch.guest_table), 1, PAGE_HYPERVISOR); + l4start = l4tab = + map_xen_pagetable(pagetable_get_mfn(v->arch.guest_table)); /* See public/xen.h on why the following is needed. */ maddr_to_page(mpt_alloc)->u.inuse.type_info = PGT_l3_page_table; l3start = map_xen_pagetable(maddr_to_mfn(mpt_alloc)); @@ -907,6 +904,8 @@ int __init dom0_construct_pv(struct domain *d, pv_shim_setup_dom(d, l4start, v_start, vxenstore_start, vconsole_start, vphysmap_start, si); + UNMAP_XEN_PAGETABLE(l4start); + if ( is_pv_32bit_domain(d) ) xlat_start_info(si, pv_shim ? XLAT_start_info_console_domU : XLAT_start_info_console_dom0); diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S index 11385857fa..8ca9a8e0ea 100644 --- a/xen/arch/x86/x86_64/entry.S +++ b/xen/arch/x86/x86_64/entry.S @@ -150,11 +150,27 @@ restore_all_guest: je .Lrag_copy_done movb $0, STACK_CPUINFO_FIELD(root_pgt_changed)(%rdx) movabs $PADDR_MASK & PAGE_MASK, %rsi - movabs $DIRECTMAP_VIRT_START, %rcx and %rsi, %rdi and %r9, %rsi - add %rcx, %rdi - add %rcx, %rsi + + /* Without a direct map, we have to map pages first before copying. */ + /* FIXME: optimisations may be needed. */ + pushq %r9 + pushq %rdx + pushq %rax + pushq %rsi + shr $PAGE_SHIFT, %rdi + callq map_xen_pagetable + popq %rdi + pushq %rax + shr $PAGE_SHIFT, %rdi + callq map_xen_pagetable + mov %rax, %rsi + mov 0(%rsp), %rdi + + /* %rsi and %rdi are on top the stack for unmapping. */ + pushq %rsi + mov $ROOT_PAGETABLE_FIRST_XEN_SLOT, %ecx mov root_table_offset(SH_LINEAR_PT_VIRT_START)*8(%rsi), %r8 mov %r8, root_table_offset(SH_LINEAR_PT_VIRT_START)*8(%rdi) @@ -166,6 +182,16 @@ restore_all_guest: sub $(ROOT_PAGETABLE_FIRST_XEN_SLOT - \ ROOT_PAGETABLE_LAST_XEN_SLOT - 1) * 8, %rdi rep movsq + + /* Unmap the two pages. */ + popq %rdi + callq unmap_xen_pagetable + popq %rdi + callq unmap_xen_pagetable + popq %rax + popq %rdx + popq %r9 + .Lrag_copy_done: mov %r9, STACK_CPUINFO_FIELD(xen_cr3)(%rdx) movb $1, STACK_CPUINFO_FIELD(use_pv_cr3)(%rdx)