From patchwork Tue Jan 7 12:06:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11320813 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 BE8D214BD for ; Tue, 7 Jan 2020 12:07:59 +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 9A8FD206F0 for ; Tue, 7 Jan 2020 12:07:59 +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="MhcGEegg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9A8FD206F0 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 1iondV-0004rt-2e; Tue, 07 Jan 2020 12:07:01 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iondT-0004rk-Mr for xen-devel@lists.xenproject.org; Tue, 07 Jan 2020 12:06:59 +0000 X-Inumbo-ID: 35023b34-3146-11ea-bf56-bc764e2007e4 Received: from smtp-fw-4101.amazon.com (unknown [72.21.198.25]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 35023b34-3146-11ea-bf56-bc764e2007e4; Tue, 07 Jan 2020 12:06:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1578398819; x=1609934819; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=vzVo7Pkr115VO+uvn/aEK7YoYU1WoiSKCmOi6chFnk0=; b=MhcGEegg4tzLSFp2dGBQ08A74742HBaiX3HbP45fEd4JLk6vjXPgxT5C GDoA2yGLiIH5ldFv7lbhgNOeYp/gSTR5o2FZ8eO364bAoKjRkMn/RSsqs LB1RvN5yYC8/gQeS5qCRLylsELG52OhoCFuNWNL+aB8+9s1YJEQ63vkSS g=; IronPort-SDR: ATeL8JZmdWP11cueDdpP047DUpkXCkgw3dM8Ni9yTZGFsTArhm976+dOJMW26/ylL1vCF1OwVj kWWs9XpTv09g== X-IronPort-AV: E=Sophos;i="5.69,406,1571702400"; d="scan'208";a="11237503" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1d-9ec21598.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 07 Jan 2020 12:06:59 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1d-9ec21598.us-east-1.amazon.com (Postfix) with ESMTPS id 3A1D5A1BEA; Tue, 7 Jan 2020 12:06:56 +0000 (UTC) Received: from EX13D37EUA002.ant.amazon.com (10.43.165.200) 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:56 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D37EUA002.ant.amazon.com (10.43.165.200) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 7 Jan 2020 12:06:55 +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:52 +0000 From: Hongyan Xia To: Date: Tue, 7 Jan 2020 12:06:43 +0000 Message-ID: <3b373c553a15dfdcd26c21e4f39c30404c7c2fa9.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 1/7] x86: move some xen mm function declarations 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 They were put into page.h but mm.h is more appropriate. The real reason is that I will be adding some new functions which takes mfn_t. It turns out it is a bit difficult to do in page.h. No functional change. Signed-off-by: Wei Liu Acked-by: Jan Beulich --- Changed since v3: - move Xen PTE API declarations next to do_page_walk(). --- xen/include/asm-x86/mm.h | 5 +++++ xen/include/asm-x86/page.h | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index 1479ba6703..2ca8882ad0 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -579,6 +579,11 @@ void update_cr3(struct vcpu *v); int vcpu_destroy_pagetables(struct vcpu *); 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); +l1_pgentry_t *virt_to_xen_l1e(unsigned long v); + int __sync_local_execstate(void); /* Arch-specific portion of memory_op hypercall. */ diff --git a/xen/include/asm-x86/page.h b/xen/include/asm-x86/page.h index c1e92937c0..05a8b1efa6 100644 --- a/xen/include/asm-x86/page.h +++ b/xen/include/asm-x86/page.h @@ -345,11 +345,6 @@ void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t); #ifndef __ASSEMBLY__ -/* Allocator functions for Xen pagetables. */ -void *alloc_xen_pagetable(void); -void free_xen_pagetable(void *v); -l1_pgentry_t *virt_to_xen_l1e(unsigned long v); - /* Convert between PAT/PCD/PWT embedded in PTE flags and 3-bit cacheattr. */ static inline unsigned int pte_flags_to_cacheattr(unsigned int flags) { 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); From patchwork Tue Jan 7 12:06:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11320823 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 5DF371580 for ; Tue, 7 Jan 2020 12:08:29 +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 2F20B206F0 for ; Tue, 7 Jan 2020 12:08:29 +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="eT36SmCq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2F20B206F0 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 1iondu-000530-Pe; Tue, 07 Jan 2020 12:07:26 +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 1iondt-00052S-L0 for xen-devel@lists.xenproject.org; Tue, 07 Jan 2020 12:07:25 +0000 X-Inumbo-ID: 3dab60f8-3146-11ea-abea-12813bfff9fa Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 3dab60f8-3146-11ea-abea-12813bfff9fa; Tue, 07 Jan 2020 12:07:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1578398834; x=1609934834; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=9luuwXGD9ICtZdH8eBFGPL/X+PZYoevKi/JrBwcT7oo=; b=eT36SmCqrHzQcQRSNpRuWfzyB5G2cYoHwLiIJa1/ucs6Y5L82Y2jWW76 QNCx3474f4dTJ+Ol4GcNIsoy9XkEW9auq0dPr7EpHwodBkcmLIkmskHJf B/PKa3A4wpx9UzkrpP3qJHqtM2mNvy9BTOliMTZfTmPmr6GCDe6/0JPtI g=; IronPort-SDR: oOGHtDkyvgelS000JY1OjQPP9khn/QzfUt/EVylICQZjD315Tlmdt7EITdowHsRdKYnO7ITYd0 gRQXRFTl4oZQ== X-IronPort-AV: E=Sophos;i="5.69,406,1571702400"; d="scan'208";a="18566714" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-69849ee2.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 07 Jan 2020 12:07:03 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-69849ee2.us-west-2.amazon.com (Postfix) with ESMTPS id 43F7CA1DA0; Tue, 7 Jan 2020 12:07:03 +0000 (UTC) Received: from EX13D37EUA002.ant.amazon.com (10.43.165.200) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 7 Jan 2020 12:07:02 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D37EUA002.ant.amazon.com (10.43.165.200) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 7 Jan 2020 12:07:01 +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:59 +0000 From: Hongyan Xia To: Date: Tue, 7 Jan 2020 12:06:45 +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 v5 3/7] x86/mm: introduce l{1, 2}t local variables to map_pages_to_xen 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 The pl2e and pl1e variables are heavily (ab)used in that function. It is fine at the moment because all page tables are always mapped so there is no need to track the life time of each variable. We will soon have the requirement to map and unmap page tables. We need to track the life time of each variable to avoid leakage. Introduce some l{1,2}t variables with limited scope so that we can track life time of pointers to xen page tables more easily. No functional change. Signed-off-by: Wei Liu Reviewed-by: Jan Beulich --- Changed since v4: - style fixes. - const qualify introduced variables. --- xen/arch/x86/mm.c | 72 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 22b55390f1..699aa6bbdf 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5211,10 +5211,11 @@ int map_pages_to_xen( } else { - pl2e = l3e_to_l2e(ol3e); + l2_pgentry_t *l2t = l3e_to_l2e(ol3e); + for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ ) { - ol2e = pl2e[i]; + ol2e = l2t[i]; if ( !(l2e_get_flags(ol2e) & _PAGE_PRESENT) ) continue; if ( l2e_get_flags(ol2e) & _PAGE_PSE ) @@ -5222,21 +5223,21 @@ int map_pages_to_xen( else { unsigned int j; + const l1_pgentry_t *l1t = l2e_to_l1e(ol2e); - pl1e = l2e_to_l1e(ol2e); for ( j = 0; j < L1_PAGETABLE_ENTRIES; j++ ) - flush_flags(l1e_get_flags(pl1e[j])); + flush_flags(l1e_get_flags(l1t[j])); } } flush_area(virt, flush_flags); for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ ) { - ol2e = pl2e[i]; + ol2e = l2t[i]; if ( (l2e_get_flags(ol2e) & _PAGE_PRESENT) && !(l2e_get_flags(ol2e) & _PAGE_PSE) ) free_xen_pagetable(l2e_to_l1e(ol2e)); } - free_xen_pagetable(pl2e); + free_xen_pagetable(l2t); } } @@ -5252,6 +5253,7 @@ int map_pages_to_xen( { unsigned int flush_flags = FLUSH_TLB | FLUSH_ORDER(2 * PAGETABLE_ORDER); + l2_pgentry_t *l2t; /* Skip this PTE if there is no change. */ if ( ((l3e_get_pfn(ol3e) & ~(L2_PAGETABLE_ENTRIES * @@ -5273,12 +5275,12 @@ int map_pages_to_xen( continue; } - pl2e = alloc_xen_pagetable(); - if ( pl2e == NULL ) + l2t = alloc_xen_pagetable(); + if ( l2t == NULL ) return -ENOMEM; for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ ) - l2e_write(pl2e + i, + l2e_write(l2t + i, l2e_from_pfn(l3e_get_pfn(ol3e) + (i << PAGETABLE_ORDER), l3e_get_flags(ol3e))); @@ -5291,15 +5293,15 @@ int map_pages_to_xen( if ( (l3e_get_flags(*pl3e) & _PAGE_PRESENT) && (l3e_get_flags(*pl3e) & _PAGE_PSE) ) { - l3e_write_atomic(pl3e, l3e_from_mfn(virt_to_mfn(pl2e), + l3e_write_atomic(pl3e, l3e_from_mfn(virt_to_mfn(l2t), __PAGE_HYPERVISOR)); - pl2e = NULL; + l2t = NULL; } if ( locking ) spin_unlock(&map_pgdir_lock); flush_area(virt, flush_flags); - if ( pl2e ) - free_xen_pagetable(pl2e); + if ( l2t ) + free_xen_pagetable(l2t); } pl2e = virt_to_xen_l2e(virt); @@ -5327,11 +5329,12 @@ int map_pages_to_xen( } else { - pl1e = l2e_to_l1e(ol2e); + l1_pgentry_t *l1t = l2e_to_l1e(ol2e); + for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) - flush_flags(l1e_get_flags(pl1e[i])); + flush_flags(l1e_get_flags(l1t[i])); flush_area(virt, flush_flags); - free_xen_pagetable(pl1e); + free_xen_pagetable(l1t); } } @@ -5353,6 +5356,7 @@ int map_pages_to_xen( { unsigned int flush_flags = FLUSH_TLB | FLUSH_ORDER(PAGETABLE_ORDER); + l1_pgentry_t *l1t; /* Skip this PTE if there is no change. */ if ( (((l2e_get_pfn(*pl2e) & ~(L1_PAGETABLE_ENTRIES - 1)) + @@ -5372,12 +5376,12 @@ int map_pages_to_xen( goto check_l3; } - pl1e = alloc_xen_pagetable(); - if ( pl1e == NULL ) + l1t = alloc_xen_pagetable(); + if ( l1t == NULL ) return -ENOMEM; for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) - l1e_write(&pl1e[i], + l1e_write(&l1t[i], l1e_from_pfn(l2e_get_pfn(*pl2e) + i, lNf_to_l1f(l2e_get_flags(*pl2e)))); @@ -5389,15 +5393,15 @@ int map_pages_to_xen( if ( (l2e_get_flags(*pl2e) & _PAGE_PRESENT) && (l2e_get_flags(*pl2e) & _PAGE_PSE) ) { - l2e_write_atomic(pl2e, l2e_from_mfn(virt_to_mfn(pl1e), + l2e_write_atomic(pl2e, l2e_from_mfn(virt_to_mfn(l1t), __PAGE_HYPERVISOR)); - pl1e = NULL; + l1t = NULL; } if ( locking ) spin_unlock(&map_pgdir_lock); flush_area(virt, flush_flags); - if ( pl1e ) - free_xen_pagetable(pl1e); + if ( l1t ) + free_xen_pagetable(l1t); } pl1e = l2e_to_l1e(*pl2e) + l1_table_offset(virt); @@ -5422,6 +5426,7 @@ int map_pages_to_xen( ((1u << PAGETABLE_ORDER) - 1)) == 0)) ) { unsigned long base_mfn; + const l1_pgentry_t *l1t; if ( locking ) spin_lock(&map_pgdir_lock); @@ -5445,11 +5450,11 @@ int map_pages_to_xen( goto check_l3; } - pl1e = l2e_to_l1e(ol2e); - base_mfn = l1e_get_pfn(*pl1e) & ~(L1_PAGETABLE_ENTRIES - 1); - for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++, pl1e++ ) - if ( (l1e_get_pfn(*pl1e) != (base_mfn + i)) || - (l1e_get_flags(*pl1e) != flags) ) + l1t = l2e_to_l1e(ol2e); + base_mfn = l1e_get_pfn(l1t[0]) & ~(L1_PAGETABLE_ENTRIES - 1); + for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) + if ( (l1e_get_pfn(l1t[i]) != (base_mfn + i)) || + (l1e_get_flags(l1t[i]) != flags) ) break; if ( i == L1_PAGETABLE_ENTRIES ) { @@ -5475,6 +5480,7 @@ int map_pages_to_xen( ((1UL << (L3_PAGETABLE_SHIFT - PAGE_SHIFT)) - 1))) ) { unsigned long base_mfn; + const l2_pgentry_t *l2t; if ( locking ) spin_lock(&map_pgdir_lock); @@ -5492,13 +5498,13 @@ int map_pages_to_xen( continue; } - pl2e = l3e_to_l2e(ol3e); - base_mfn = l2e_get_pfn(*pl2e) & ~(L2_PAGETABLE_ENTRIES * + l2t = l3e_to_l2e(ol3e); + base_mfn = l2e_get_pfn(l2t[0]) & ~(L2_PAGETABLE_ENTRIES * L1_PAGETABLE_ENTRIES - 1); - for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ ) - if ( (l2e_get_pfn(*pl2e) != + for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ ) + if ( (l2e_get_pfn(l2t[i]) != (base_mfn + (i << PAGETABLE_ORDER))) || - (l2e_get_flags(*pl2e) != l1f_to_lNf(flags)) ) + (l2e_get_flags(l2t[i]) != l1f_to_lNf(flags)) ) break; if ( i == L2_PAGETABLE_ENTRIES ) { From patchwork Tue Jan 7 12:06:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11320821 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 33686930 for ; Tue, 7 Jan 2020 12:08:17 +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 103E7206F0 for ; Tue, 7 Jan 2020 12:08:16 +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="ASjzOJS9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 103E7206F0 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 1iondf-0004vH-MD; Tue, 07 Jan 2020 12:07:11 +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 1ionde-0004ut-Kt for xen-devel@lists.xenproject.org; Tue, 07 Jan 2020 12:07:10 +0000 X-Inumbo-ID: 3a4b5878-3146-11ea-abea-12813bfff9fa Received: from smtp-fw-6002.amazon.com (unknown [52.95.49.90]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 3a4b5878-3146-11ea-abea-12813bfff9fa; Tue, 07 Jan 2020 12:07: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=1578398828; x=1609934828; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=+zVQP4wvGmxUJMXWIxCOYEmPNTxv3X5lBU4BlGgepwY=; b=ASjzOJS9dVbjneQaL9wMhNuLoZ+ZuJfjN55fsMG3qPMRu0mXvKOIagMn cBcPZhehGS0FkNAdEXns+HwoUkg3fjc4XFNc0FQ54gJK7XgmmpB32uA+j 1xQLrGQ4FsRqAfrU+HJ4jHjn9zCTGZp+83B25xab4vXNFZbc28Zs0uAQZ M=; IronPort-SDR: vaOeRBeSB5BFjpVEYyPXEgfBVpZzqtv6YVbB6ZOg4GBRoGhEXc3ICJsYfgz17GFA0y5btvbON4 idk4iNhA2xJQ== X-IronPort-AV: E=Sophos;i="5.69,406,1571702400"; d="scan'208";a="10390311" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-90c42d1d.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 07 Jan 2020 12:07:07 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2a-90c42d1d.us-west-2.amazon.com (Postfix) with ESMTPS id 6AC49A1E63; Tue, 7 Jan 2020 12:07:06 +0000 (UTC) Received: from EX13D37EUA003.ant.amazon.com (10.43.165.7) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 7 Jan 2020 12:07:05 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D37EUA003.ant.amazon.com (10.43.165.7) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 7 Jan 2020 12:07:05 +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:07:02 +0000 From: Hongyan Xia To: Date: Tue, 7 Jan 2020 12:06:46 +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 v5 4/7] x86/mm: introduce l{1, 2}t local variables to modify_xen_mappings 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 The pl2e and pl1e variables are heavily (ab)used in that function. It is fine at the moment because all page tables are always mapped so there is no need to track the life time of each variable. We will soon have the requirement to map and unmap page tables. We need to track the life time of each variable to avoid leakage. Introduce some l{1,2}t variables with limited scope so that we can track life time of pointers to xen page tables more easily. No functional change. Signed-off-by: Wei Liu Reviewed-by: Jan Beulich --- xen/arch/x86/mm.c | 68 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 699aa6bbdf..7160ddcb67 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5575,6 +5575,8 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) if ( l3e_get_flags(*pl3e) & _PAGE_PSE ) { + l2_pgentry_t *l2t; + if ( l2_table_offset(v) == 0 && l1_table_offset(v) == 0 && ((e - v) >= (1UL << L3_PAGETABLE_SHIFT)) ) @@ -5590,11 +5592,11 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) } /* PAGE1GB: shatter the superpage and fall through. */ - pl2e = alloc_xen_pagetable(); - if ( !pl2e ) + l2t = alloc_xen_pagetable(); + if ( !l2t ) return -ENOMEM; for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ ) - l2e_write(pl2e + i, + l2e_write(l2t + i, l2e_from_pfn(l3e_get_pfn(*pl3e) + (i << PAGETABLE_ORDER), l3e_get_flags(*pl3e))); @@ -5603,14 +5605,14 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) if ( (l3e_get_flags(*pl3e) & _PAGE_PRESENT) && (l3e_get_flags(*pl3e) & _PAGE_PSE) ) { - l3e_write_atomic(pl3e, l3e_from_mfn(virt_to_mfn(pl2e), + l3e_write_atomic(pl3e, l3e_from_mfn(virt_to_mfn(l2t), __PAGE_HYPERVISOR)); - pl2e = NULL; + l2t = NULL; } if ( locking ) spin_unlock(&map_pgdir_lock); - if ( pl2e ) - free_xen_pagetable(pl2e); + if ( l2t ) + free_xen_pagetable(l2t); } /* @@ -5644,12 +5646,14 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) } else { + l1_pgentry_t *l1t; + /* PSE: shatter the superpage and try again. */ - pl1e = alloc_xen_pagetable(); - if ( !pl1e ) + l1t = alloc_xen_pagetable(); + if ( !l1t ) return -ENOMEM; for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) - l1e_write(&pl1e[i], + l1e_write(&l1t[i], l1e_from_pfn(l2e_get_pfn(*pl2e) + i, l2e_get_flags(*pl2e) & ~_PAGE_PSE)); if ( locking ) @@ -5657,19 +5661,19 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) if ( (l2e_get_flags(*pl2e) & _PAGE_PRESENT) && (l2e_get_flags(*pl2e) & _PAGE_PSE) ) { - l2e_write_atomic(pl2e, l2e_from_mfn(virt_to_mfn(pl1e), + l2e_write_atomic(pl2e, l2e_from_mfn(virt_to_mfn(l1t), __PAGE_HYPERVISOR)); - pl1e = NULL; + l1t = NULL; } if ( locking ) spin_unlock(&map_pgdir_lock); - if ( pl1e ) - free_xen_pagetable(pl1e); + if ( l1t ) + free_xen_pagetable(l1t); } } else { - l1_pgentry_t nl1e; + l1_pgentry_t nl1e, *l1t; /* * Ordinary 4kB mapping: The L2 entry has been verified to be @@ -5716,9 +5720,9 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) continue; } - pl1e = l2e_to_l1e(*pl2e); + l1t = l2e_to_l1e(*pl2e); for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) - if ( l1e_get_intpte(pl1e[i]) != 0 ) + if ( l1e_get_intpte(l1t[i]) != 0 ) break; if ( i == L1_PAGETABLE_ENTRIES ) { @@ -5727,7 +5731,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) if ( locking ) spin_unlock(&map_pgdir_lock); flush_area(NULL, FLUSH_TLB_GLOBAL); /* flush before free */ - free_xen_pagetable(pl1e); + free_xen_pagetable(l1t); } else if ( locking ) spin_unlock(&map_pgdir_lock); @@ -5756,21 +5760,25 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) continue; } - pl2e = l3e_to_l2e(*pl3e); - for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ ) - if ( l2e_get_intpte(pl2e[i]) != 0 ) - break; - if ( i == L2_PAGETABLE_ENTRIES ) { - /* Empty: zap the L3E and free the L2 page. */ - l3e_write_atomic(pl3e, l3e_empty()); - if ( locking ) + l2_pgentry_t *l2t; + + l2t = l3e_to_l2e(*pl3e); + for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ ) + if ( l2e_get_intpte(l2t[i]) != 0 ) + break; + if ( i == L2_PAGETABLE_ENTRIES ) + { + /* Empty: zap the L3E and free the L2 page. */ + l3e_write_atomic(pl3e, l3e_empty()); + if ( locking ) + spin_unlock(&map_pgdir_lock); + flush_area(NULL, FLUSH_TLB_GLOBAL); /* flush before free */ + free_xen_pagetable(l2t); + } + else if ( locking ) spin_unlock(&map_pgdir_lock); - flush_area(NULL, FLUSH_TLB_GLOBAL); /* flush before free */ - free_xen_pagetable(pl2e); } - else if ( locking ) - spin_unlock(&map_pgdir_lock); } flush_area(NULL, FLUSH_TLB_GLOBAL); From patchwork Tue Jan 7 12:06:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11320817 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 4235B930 for ; Tue, 7 Jan 2020 12:08:14 +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 1E71D206F0 for ; Tue, 7 Jan 2020 12:08:14 +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="LIOQwXmk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1E71D206F0 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 1iondl-0004xM-0I; Tue, 07 Jan 2020 12:07:17 +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 1iondj-0004wu-Kw for xen-devel@lists.xenproject.org; Tue, 07 Jan 2020 12:07:15 +0000 X-Inumbo-ID: 3c4feddd-3146-11ea-abea-12813bfff9fa Received: from smtp-fw-2101.amazon.com (unknown [72.21.196.25]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 3c4feddd-3146-11ea-abea-12813bfff9fa; Tue, 07 Jan 2020 12:07:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1578398832; x=1609934832; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=JmnKc1RvQ63Kc9IxskD8nxU0+SIuQ6WCnZXK7dk0U+4=; b=LIOQwXmkWc6j0c48DcMQTrOa7IcyXXwjumGgpirtI/QKfGfLrXelE3S6 ojpm4kQRwBUMyXEiX+NZPdPfUavHHeBB2eEjOKxn7NIgMRUBdcbnugN6y LWKnvvgRL3SdaYNRMgoPahqJTUnlCKplG08eEFnvT4/nb9usLdJ0e8Sqb E=; IronPort-SDR: Ti+YQF7GAmnfvLPAxX0xTwRSicrW+bHUO0/kmZnwrWdcErRcIAW24ecgf/8fGiRV7QK5685U3A 3eikrGXEHI2Q== X-IronPort-AV: E=Sophos;i="5.69,406,1571702400"; d="scan'208";a="11310538" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1d-474bcd9f.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 07 Jan 2020 12:07:12 +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-474bcd9f.us-east-1.amazon.com (Postfix) with ESMTPS id 01962A1FD7; Tue, 7 Jan 2020 12:07:09 +0000 (UTC) Received: from EX13D37EUB001.ant.amazon.com (10.43.166.31) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 7 Jan 2020 12:07:09 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D37EUB001.ant.amazon.com (10.43.166.31) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 7 Jan 2020 12:07:07 +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:07:05 +0000 From: Hongyan Xia To: Date: Tue, 7 Jan 2020 12:06:47 +0000 Message-ID: <512c9e69ab0699062ac972efc4551b3b872f336b.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 5/7] x86/mm: map_pages_to_xen would better have one exit path 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 will soon rewrite the function to handle dynamically mapping and unmapping of page tables. No functional change. Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia --- Changed since v4: - drop the end_of_loop goto label since this function may be refactored in the future and there are options to do things without the goto. Changed since v3: - remove asserts on rc since rc never gets changed to anything else. - reword commit message. --- xen/arch/x86/mm.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 7160ddcb67..71e9c4b19e 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5164,9 +5164,11 @@ int map_pages_to_xen( unsigned int flags) { bool locking = system_state > SYS_STATE_boot; + l3_pgentry_t *pl3e, ol3e; l2_pgentry_t *pl2e, ol2e; l1_pgentry_t *pl1e, ol1e; unsigned int i; + int rc = -ENOMEM; #define flush_flags(oldf) do { \ unsigned int o_ = (oldf); \ @@ -5184,10 +5186,11 @@ int map_pages_to_xen( while ( nr_mfns != 0 ) { - l3_pgentry_t ol3e, *pl3e = virt_to_xen_l3e(virt); + pl3e = virt_to_xen_l3e(virt); if ( !pl3e ) - return -ENOMEM; + goto out; + ol3e = *pl3e; if ( cpu_has_page1gb && @@ -5277,7 +5280,7 @@ int map_pages_to_xen( l2t = alloc_xen_pagetable(); if ( l2t == NULL ) - return -ENOMEM; + goto out; for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ ) l2e_write(l2t + i, @@ -5306,7 +5309,7 @@ int map_pages_to_xen( pl2e = virt_to_xen_l2e(virt); if ( !pl2e ) - return -ENOMEM; + goto out; if ( ((((virt >> PAGE_SHIFT) | mfn_x(mfn)) & ((1u << PAGETABLE_ORDER) - 1)) == 0) && @@ -5350,7 +5353,7 @@ int map_pages_to_xen( { pl1e = virt_to_xen_l1e(virt); if ( pl1e == NULL ) - return -ENOMEM; + goto out; } else if ( l2e_get_flags(*pl2e) & _PAGE_PSE ) { @@ -5378,7 +5381,7 @@ int map_pages_to_xen( l1t = alloc_xen_pagetable(); if ( l1t == NULL ) - return -ENOMEM; + goto out; for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) l1e_write(&l1t[i], @@ -5524,7 +5527,10 @@ int map_pages_to_xen( #undef flush_flags - return 0; + rc = 0; + + out: + return rc; } int populate_pt_range(unsigned long virt, unsigned long nr_mfns) From patchwork Tue Jan 7 12:06:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11320827 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 9BCA614BD for ; Tue, 7 Jan 2020 12:08: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 78317206F0 for ; Tue, 7 Jan 2020 12:08:31 +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="G0ff7odx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 78317206F0 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 1ione0-00056Q-5v; Tue, 07 Jan 2020 12:07: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 1iondy-00055g-LH for xen-devel@lists.xenproject.org; Tue, 07 Jan 2020 12:07:30 +0000 X-Inumbo-ID: 3dab60f9-3146-11ea-abea-12813bfff9fa Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 3dab60f9-3146-11ea-abea-12813bfff9fa; Tue, 07 Jan 2020 12:07:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1578398835; x=1609934835; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=itKH+BLxlqdCAm2+43IZOto6nSnXfTrkF2Xaud+RgFA=; b=G0ff7odxvwnpdRAwFghJL7fAyXLegpKZ9SIWGlE9BBlcEWnid4rvEoHn ZuqDZYVIJrGuywWyWSHn+C53tgyN558Iy9I3b00cvgjsu2P0T8Sy26UOT cbW2afI20Qm4FiPwEbufyazvhWeDSCJWILdHShTS+uBtm30qmFni+6X9n U=; IronPort-SDR: 8hrNrjKmBI/OWVh0/p5gtqiIqyGIFqWnq5MGV90oWAOOAMuauPUzywexY9hITtituKRUy19DuH ZSk81tOeXE6g== X-IronPort-AV: E=Sophos;i="5.69,406,1571702400"; d="scan'208";a="18566730" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-538b0bfb.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 07 Jan 2020 12:07:13 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2a-538b0bfb.us-west-2.amazon.com (Postfix) with ESMTPS id A7129A1DF1; Tue, 7 Jan 2020 12:07:12 +0000 (UTC) Received: from EX13D37EUB003.ant.amazon.com (10.43.166.251) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 7 Jan 2020 12:07:12 +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:07:11 +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:07:08 +0000 From: Hongyan Xia To: Date: Tue, 7 Jan 2020 12:06:48 +0000 Message-ID: <7c072f70f8fa9a7b3c431a8fa3fa37d0d64e530b.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 6/7] x86/mm: make sure there is one exit path for modify_xen_mappings 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 will soon need to handle dynamically mapping / unmapping page tables in the said function. No functional change. Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia --- Changed since v4: - drop the end_of_loop goto label since this function may be refactored in the future and there are options to do things without the goto. Changed since v3: - remove asserts on rc since it never gets changed to anything else. --- xen/arch/x86/mm.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 71e9c4b19e..6b589762b1 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5557,6 +5557,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) l1_pgentry_t *pl1e; unsigned int i; unsigned long v = s; + int rc = -ENOMEM; /* Set of valid PTE bits which may be altered. */ #define FLAGS_MASK (_PAGE_NX|_PAGE_RW|_PAGE_PRESENT) @@ -5600,7 +5601,8 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) /* PAGE1GB: shatter the superpage and fall through. */ l2t = alloc_xen_pagetable(); if ( !l2t ) - return -ENOMEM; + goto out; + for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ ) l2e_write(l2t + i, l2e_from_pfn(l3e_get_pfn(*pl3e) + @@ -5657,7 +5659,8 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) /* PSE: shatter the superpage and try again. */ l1t = alloc_xen_pagetable(); if ( !l1t ) - return -ENOMEM; + goto out; + for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) l1e_write(&l1t[i], l1e_from_pfn(l2e_get_pfn(*pl2e) + i, @@ -5790,7 +5793,10 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) flush_area(NULL, FLUSH_TLB_GLOBAL); #undef FLAGS_MASK - return 0; + rc = 0; + + out: + return rc; } #undef flush_area From patchwork Tue Jan 7 12:06:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11320825 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 8A309930 for ; Tue, 7 Jan 2020 12:08:29 +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 66FF4206F0 for ; Tue, 7 Jan 2020 12:08:29 +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="Y4w4pzRP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 66FF4206F0 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 1ione5-0005AC-G4; Tue, 07 Jan 2020 12:07:37 +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 1ione3-000591-Lb for xen-devel@lists.xenproject.org; Tue, 07 Jan 2020 12:07:35 +0000 X-Inumbo-ID: 44682f3f-3146-11ea-abea-12813bfff9fa Received: from smtp-fw-4101.amazon.com (unknown [72.21.198.25]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 44682f3f-3146-11ea-abea-12813bfff9fa; Tue, 07 Jan 2020 12:07:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1578398847; x=1609934847; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=k9ao28sjxycjJJ0sKPbc+jDcJKXPxqdYKANLUQawgsg=; b=Y4w4pzRPb6YwAW3sCTsFENbdLfsATjot1whK4xGoMB0uhReWXUPCzygs v6iChHVfP9bLwomrClj0vFvgwfppkUmqPxKF8qREVXSFLv5SS+YKn+Pwv mKhQLw2YxHA7Edlwr7CXLnVc9zgHMSeUtTSYcQdPwHOkRLf5OGrxaMvVD Q=; IronPort-SDR: RXHC8QyoI91/DwlBhQyMM3o6YE501Ntq1IjrBXKWqLKWELxCSpw/fEMLf35cID3BBMY2bcu0mo cKU2blFvpjKQ== X-IronPort-AV: E=Sophos;i="5.69,406,1571702400"; d="scan'208";a="11237542" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1a-821c648d.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 07 Jan 2020 12:07:26 +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-821c648d.us-east-1.amazon.com (Postfix) with ESMTPS id E38D0A1C3D; Tue, 7 Jan 2020 12:07:24 +0000 (UTC) Received: from EX13D37EUA004.ant.amazon.com (10.43.165.124) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 7 Jan 2020 12:07:15 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D37EUA004.ant.amazon.com (10.43.165.124) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 7 Jan 2020 12:07:14 +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:07:11 +0000 From: Hongyan Xia To: Date: Tue, 7 Jan 2020 12:06:49 +0000 Message-ID: <3f256df7ddae79efa66ceead096315593cb3901e.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 7/7] x86/mm: change pl*e to l*t in virt_to_xen_l*e 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 will need to have a variable named pl*e when we rewrite virt_to_xen_l*e. Change pl*e to l*t to reflect better its purpose. This will make reviewing later patch easier. No functional change. Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia Reviewed-by: Jan Beulich --- xen/arch/x86/mm.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 6b589762b1..d594d6abfb 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5054,25 +5054,25 @@ static l3_pgentry_t *virt_to_xen_l3e(unsigned long v) if ( !(l4e_get_flags(*pl4e) & _PAGE_PRESENT) ) { bool locking = system_state > SYS_STATE_boot; - l3_pgentry_t *pl3e = alloc_xen_pagetable(); + l3_pgentry_t *l3t = alloc_xen_pagetable(); - if ( !pl3e ) + if ( !l3t ) return NULL; - clear_page(pl3e); + clear_page(l3t); if ( locking ) spin_lock(&map_pgdir_lock); if ( !(l4e_get_flags(*pl4e) & _PAGE_PRESENT) ) { - l4_pgentry_t l4e = l4e_from_paddr(__pa(pl3e), __PAGE_HYPERVISOR); + l4_pgentry_t l4e = l4e_from_paddr(__pa(l3t), __PAGE_HYPERVISOR); l4e_write(pl4e, l4e); efi_update_l4_pgtable(l4_table_offset(v), l4e); - pl3e = NULL; + l3t = NULL; } if ( locking ) spin_unlock(&map_pgdir_lock); - if ( pl3e ) - free_xen_pagetable(pl3e); + if ( l3t ) + free_xen_pagetable(l3t); } return l4e_to_l3e(*pl4e) + l3_table_offset(v); @@ -5089,22 +5089,22 @@ static l2_pgentry_t *virt_to_xen_l2e(unsigned long v) if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ) { bool locking = system_state > SYS_STATE_boot; - l2_pgentry_t *pl2e = alloc_xen_pagetable(); + l2_pgentry_t *l2t = alloc_xen_pagetable(); - if ( !pl2e ) + if ( !l2t ) return NULL; - clear_page(pl2e); + clear_page(l2t); if ( locking ) spin_lock(&map_pgdir_lock); if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ) { - l3e_write(pl3e, l3e_from_paddr(__pa(pl2e), __PAGE_HYPERVISOR)); - pl2e = NULL; + l3e_write(pl3e, l3e_from_paddr(__pa(l2t), __PAGE_HYPERVISOR)); + l2t = NULL; } if ( locking ) spin_unlock(&map_pgdir_lock); - if ( pl2e ) - free_xen_pagetable(pl2e); + if ( l2t ) + free_xen_pagetable(l2t); } BUG_ON(l3e_get_flags(*pl3e) & _PAGE_PSE); @@ -5122,22 +5122,22 @@ l1_pgentry_t *virt_to_xen_l1e(unsigned long v) if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ) { bool locking = system_state > SYS_STATE_boot; - l1_pgentry_t *pl1e = alloc_xen_pagetable(); + l1_pgentry_t *l1t = alloc_xen_pagetable(); - if ( !pl1e ) + if ( !l1t ) return NULL; - clear_page(pl1e); + clear_page(l1t); if ( locking ) spin_lock(&map_pgdir_lock); if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ) { - l2e_write(pl2e, l2e_from_paddr(__pa(pl1e), __PAGE_HYPERVISOR)); - pl1e = NULL; + l2e_write(pl2e, l2e_from_paddr(__pa(l1t), __PAGE_HYPERVISOR)); + l1t = NULL; } if ( locking ) spin_unlock(&map_pgdir_lock); - if ( pl1e ) - free_xen_pagetable(pl1e); + if ( l1t ) + free_xen_pagetable(l1t); } BUG_ON(l2e_get_flags(*pl2e) & _PAGE_PSE);