From patchwork Tue Jan 7 12:06:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11320819 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 9EAF8930 for ; Tue, 7 Jan 2020 12:08:15 +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 7B313206F0 for ; Tue, 7 Jan 2020 12:08:15 +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="QOPt5pTZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7B313206F0 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 1iondq-00050G-FJ; Tue, 07 Jan 2020 12:07:22 +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 1iondo-0004zO-Kt for xen-devel@lists.xenproject.org; Tue, 07 Jan 2020 12:07:20 +0000 X-Inumbo-ID: 3d172c30-3146-11ea-abea-12813bfff9fa Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 3d172c30-3146-11ea-abea-12813bfff9fa; Tue, 07 Jan 2020 12:07:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1578398833; x=1609934833; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=U3mwHbcFdCe6JbFMFdiwFqByzpljucm+6vyznbEIxNA=; b=QOPt5pTZAD4ajyoPoVXfaK1lq+OcbpVvlACkG5leLVgqfVj9M1puvUOe GQ0JV8XB1YxScc0oDff5Q5wZUU+G9KG4nbYA7Dwocvqgt9pjvDPN7pTLF J0zSNmXP/FSIDbsblrQmNC9FPXu1g2c2mxr+Vf35OOlO4Ia8GICd+GV9x A=; IronPort-SDR: FmaljOdqBog0xHdR+wgVkeh5NmYRhrHEFLXQiMGOf9xM2IRUWIt4kkZzZDB3vDDi5dkU7IYyeo CaQptbVupt7A== X-IronPort-AV: E=Sophos;i="5.69,406,1571702400"; d="scan'208";a="17196813" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1e-62350142.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 07 Jan 2020 12:07:02 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1e-62350142.us-east-1.amazon.com (Postfix) with ESMTPS id 783D9A2384; Tue, 7 Jan 2020 12:07:00 +0000 (UTC) Received: from EX13D37EUB003.ant.amazon.com (10.43.166.251) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 7 Jan 2020 12:06:59 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D37EUB003.ant.amazon.com (10.43.166.251) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 7 Jan 2020 12:06:58 +0000 Received: from u0b3720fa96e858.ant.amazon.com (10.125.106.133) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 7 Jan 2020 12:06:55 +0000 From: Hongyan Xia To: Date: Tue, 7 Jan 2020 12:06:44 +0000 Message-ID: <5f64321c4cceccd057e3b3e7fadea696793a7966.1578397252.git.hongyxia@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH v5 2/7] x86: introduce a new set of APIs to manage Xen page tables 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: Wei Liu , Wei Liu , Andrew Cooper , jgrall@amazon.com, Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Wei Liu We are going to switch to using domheap page for page tables. A new set of APIs is introduced to allocate, map, unmap and free pages for page tables. The allocation and deallocation work on mfn_t but not page_info, because they are required to work even before frame table is set up. Implement the old functions with the new ones. We will rewrite, site by site, other mm functions that manipulate page tables to use the new APIs. Note these new APIs still use xenheap page underneath and no actual map and unmap is done so that we don't break xen half way. They will be switched to use domheap and dynamic mappings when usage of old APIs is eliminated. No functional change intended in this patch. Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia Reviewed-by: Julien Grall --- Changed since v4: - properly handle INVALID_MFN. - remove the _new suffix for map/unmap_xen_pagetable because they do not have old alternatives. Changed since v3: - const qualify unmap_xen_pagetable_new(). - remove redundant parentheses. --- xen/arch/x86/mm.c | 44 +++++++++++++++++++++++++++++++++++++++----- xen/include/asm-x86/mm.h | 11 +++++++++++ 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index cc0d71996c..22b55390f1 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -119,6 +119,7 @@ #include #include #include +#include #include #include #include @@ -4992,22 +4993,55 @@ int mmcfg_intercept_write( } void *alloc_xen_pagetable(void) +{ + mfn_t mfn = alloc_xen_pagetable_new(); + + return mfn_eq(mfn, INVALID_MFN) ? NULL : mfn_to_virt(mfn_x(mfn)); +} + +void free_xen_pagetable(void *v) +{ + mfn_t mfn = v ? virt_to_mfn(v) : INVALID_MFN; + + if ( system_state != SYS_STATE_early_boot ) + free_xen_pagetable_new(mfn); +} + +/* + * For these PTE APIs, the caller must follow the alloc-map-unmap-free + * lifecycle, which means explicitly mapping the PTE pages before accessing + * them. The caller must check whether the allocation has succeeded, and only + * pass valid MFNs to map_xen_pagetable(). + */ +mfn_t alloc_xen_pagetable_new(void) { if ( system_state != SYS_STATE_early_boot ) { void *ptr = alloc_xenheap_page(); BUG_ON(!hardware_domain && !ptr); - return ptr; + return ptr ? virt_to_mfn(ptr) : INVALID_MFN; } - return mfn_to_virt(mfn_x(alloc_boot_pages(1, 1))); + return alloc_boot_pages(1, 1); } -void free_xen_pagetable(void *v) +void *map_xen_pagetable(mfn_t mfn) { - if ( system_state != SYS_STATE_early_boot ) - free_xenheap_page(v); + return mfn_to_virt(mfn_x(mfn)); +} + +/* v can point to an entry within a table or be NULL */ +void unmap_xen_pagetable(const void *v) +{ + /* XXX still using xenheap page, no need to do anything. */ +} + +/* mfn can be INVALID_MFN */ +void free_xen_pagetable_new(mfn_t mfn) +{ + if ( system_state != SYS_STATE_early_boot && !mfn_eq(mfn, INVALID_MFN) ) + free_xenheap_page(mfn_to_virt(mfn_x(mfn))); } static DEFINE_SPINLOCK(map_pgdir_lock); diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index 2ca8882ad0..861edba34e 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -582,6 +582,17 @@ void *do_page_walk(struct vcpu *v, unsigned long addr); /* Allocator functions for Xen pagetables. */ void *alloc_xen_pagetable(void); void free_xen_pagetable(void *v); +mfn_t alloc_xen_pagetable_new(void); +void *map_xen_pagetable(mfn_t mfn); +void unmap_xen_pagetable(const void *v); +void free_xen_pagetable_new(mfn_t mfn); + +#define UNMAP_XEN_PAGETABLE(ptr) \ + do { \ + unmap_xen_pagetable(ptr); \ + (ptr) = NULL; \ + } while (0) + l1_pgentry_t *virt_to_xen_l1e(unsigned long v); int __sync_local_execstate(void);