From patchwork Wed Dec 4 17:10:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11273319 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 7540B13B6 for ; Wed, 4 Dec 2019 17:12:35 +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 5092A2081B for ; Wed, 4 Dec 2019 17:12:35 +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="cMM9KTSJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5092A2081B 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 1icYBC-0003Zv-Pu; Wed, 04 Dec 2019 17:11:10 +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 1icYBB-0003Zq-Fo for xen-devel@lists.xenproject.org; Wed, 04 Dec 2019 17:11:09 +0000 X-Inumbo-ID: 105d1328-16b9-11ea-8206-12813bfff9fa Received: from smtp-fw-6002.amazon.com (unknown [52.95.49.90]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 105d1328-16b9-11ea-8206-12813bfff9fa; Wed, 04 Dec 2019 17:11:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1575479468; x=1607015468; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=eTYMfNKFGd1QO/1jhYdMM6duQPKa4/DHgiQ8LFUbFwk=; b=cMM9KTSJc1I8V8k/T/39X7Mp1TlENFKJExZv9+czt++GairNRGvBi+tB +NQSUrFOpB9rL02KPVqzJ/6aNifgakxTqxVFWLqlzw4dr5z6Im7e7a3O7 n+JNkm+NvXuobdT7eLS+u9Y2UpeoKDLpoJXxwiP6i+FLtOTWD/aGG45C3 s=; IronPort-SDR: aead8iyIb2sTM4HMIC4juFd75F0Cy+XK3yd6XTi1/GmAZ9iiBCOgAw4LNPr326bR5uSoZDYz4v CNHOHVg9Dt/Q== X-IronPort-AV: E=Sophos;i="5.69,278,1571702400"; d="scan'208";a="6210793" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-1c1b5cdd.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 04 Dec 2019 17:11:07 +0000 Received: from EX13MTAUWA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-1c1b5cdd.us-west-2.amazon.com (Postfix) with ESMTPS id C26CDA235B; Wed, 4 Dec 2019 17:11:06 +0000 (UTC) Received: from EX13D19UWA001.ant.amazon.com (10.43.160.169) by EX13MTAUWA001.ant.amazon.com (10.43.160.118) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 4 Dec 2019 17:11:06 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX13D19UWA001.ant.amazon.com (10.43.160.169) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 4 Dec 2019 17:11:05 +0000 Received: from u60d575063b1f53.ant.amazon.com (10.125.106.64) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Wed, 4 Dec 2019 17:11:05 +0000 From: Hongyan Xia To: Date: Wed, 4 Dec 2019 17:10:54 +0000 Message-ID: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH v4 2/9] 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: 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 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 --- Changed since v3: - const qualify unmap_xen_pagetable_new(). - remove redundant parentheses. --- xen/arch/x86/mm.c | 39 ++++++++++++++++++++++++++++++++++----- xen/include/asm-x86/mm.h | 11 +++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 7d4dd80a85..ca362ad638 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -119,6 +119,7 @@ #include #include #include +#include #include #include #include @@ -5020,22 +5021,50 @@ int mmcfg_intercept_write( } void *alloc_xen_pagetable(void) +{ + mfn_t mfn; + + mfn = alloc_xen_pagetable_new(); + ASSERT(!mfn_eq(mfn, INVALID_MFN)); + + return map_xen_pagetable_new(mfn); +} + +void free_xen_pagetable(void *v) +{ + if ( system_state != SYS_STATE_early_boot ) + free_xen_pagetable_new(virt_to_mfn(v)); +} + +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 virt_to_mfn(ptr); } - 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_new(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_new(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 9d2b833579..76593fe9e7 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_new(mfn_t mfn); +void unmap_xen_pagetable_new(const void *v); +void free_xen_pagetable_new(mfn_t mfn); + +#define UNMAP_XEN_PAGETABLE_NEW(ptr) \ + do { \ + unmap_xen_pagetable_new(ptr); \ + (ptr) = NULL; \ + } while (0) + l1_pgentry_t *virt_to_xen_l1e(unsigned long v); int __sync_local_execstate(void);