From patchwork Wed Oct 2 17:16:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11171691 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 04EF5112B for ; Wed, 2 Oct 2019 17:18:34 +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 D44D721D81 for ; Wed, 2 Oct 2019 17:18:33 +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="Kcouyx2j" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D44D721D81 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 1iFiFV-0008EV-3E; Wed, 02 Oct 2019 17:17:13 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iFiFT-0008E9-Sm for xen-devel@lists.xenproject.org; Wed, 02 Oct 2019 17:17:11 +0000 X-Inumbo-ID: 7365c29c-e538-11e9-bf31-bc764e2007e4 Received: from smtp-fw-6001.amazon.com (unknown [52.95.48.154]) by localhost (Halon) with ESMTPS id 7365c29c-e538-11e9-bf31-bc764e2007e4; Wed, 02 Oct 2019 17:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1570036622; x=1601572622; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=5Q2XE0XvYzUty69qqRlTGEEguqCrML7ftDS0JmcjKEo=; b=Kcouyx2jS7CKL6bC/JuXZmCbf4z2k8w7K0VcCo8eX4jX4U+GdaJybvni 4W4MsU+YVxiUBP8eBRCVzbrqDuB/0WuSUX6vrB0Hl/Sqv4mimZ1nlyOmG o1ZXpekVVAhHe/hJ6DqhnWNa277spLuDXbHhj/f8eIByEAOIV87a3TXp7 8=; X-IronPort-AV: E=Sophos;i="5.67,249,1566864000"; d="scan'208";a="419366605" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-69849ee2.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 02 Oct 2019 17:16:58 +0000 Received: from EX13MTAUEA001.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 9BDEBA1C90; Wed, 2 Oct 2019 17:16:57 +0000 (UTC) Received: from EX13D15UEE001.ant.amazon.com (10.43.62.86) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 2 Oct 2019 17:16:57 +0000 Received: from EX13MTAUEE001.ant.amazon.com (10.43.62.200) by EX13D15UEE001.ant.amazon.com (10.43.62.86) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 2 Oct 2019 17:16:56 +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; Wed, 2 Oct 2019 17:16:56 +0000 From: Hongyan Xia To: Date: Wed, 2 Oct 2019 18:16:46 +0100 Message-ID: <136f8a63b7e381af7a6134721ab6c63dac4e4654.1570034362.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] [PATCH v3 1/9] 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: Andrew Cooper , Wei Liu , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_?= =?utf-8?q?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 --- 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 3863e4ce57..2800106327 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -630,4 +630,9 @@ int arch_acquire_resource(struct domain *d, unsigned int type, unsigned int id, unsigned long frame, unsigned int nr_frames, xen_pfn_t mfn_list[]); +/* 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); + #endif /* __ASM_X86_MM_H__ */ 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 Wed Oct 2 17:16:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11171707 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 460D6112B for ; Wed, 2 Oct 2019 17:20:51 +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 226D921848 for ; Wed, 2 Oct 2019 17:20:51 +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="ClC9h2Ms" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 226D921848 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 1iFiHj-0000Rd-5D; Wed, 02 Oct 2019 17:19:31 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iFiHh-0000RP-Fv for xen-devel@lists.xenproject.org; Wed, 02 Oct 2019 17:19:29 +0000 X-Inumbo-ID: ca23a3ec-e538-11e9-bf31-bc764e2007e4 Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by localhost (Halon) with ESMTPS id ca23a3ec-e538-11e9-bf31-bc764e2007e4; Wed, 02 Oct 2019 17:19:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1570036769; x=1601572769; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=Dlve+Wyb9tqo/66ImCfcUmRynkVkhYK/y9vCkHe0JZE=; b=ClC9h2Msdw6qF5iJ959bZ5E6KcBL/+KkRDZ9qj8OUaw/0BsNVeSJ4izv N9XYWas06/EnoiW4H3ZJ95VnAYR3NPrbUV48F9R85x0kUyXvDtZ4C1tJF mUwv3AU7HBthhcQK8mpT6YkvGutLMuGFBneCKDsKlWRM/NLuFWvuuItCk 0=; X-IronPort-AV: E=Sophos;i="5.67,249,1566864000"; d="scan'208";a="706204314" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2c-4e7c8266.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 02 Oct 2019 17:17:26 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2c-4e7c8266.us-west-2.amazon.com (Postfix) with ESMTPS id 8C493A062E; Wed, 2 Oct 2019 17:16:58 +0000 (UTC) Received: from EX13D23UEE002.ant.amazon.com (10.43.62.97) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 2 Oct 2019 17:16:58 +0000 Received: from EX13MTAUEE001.ant.amazon.com (10.43.62.200) by EX13D23UEE002.ant.amazon.com (10.43.62.97) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 2 Oct 2019 17:16:58 +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; Wed, 2 Oct 2019 17:16:57 +0000 From: Hongyan Xia To: Date: Wed, 2 Oct 2019 18:16:47 +0100 Message-ID: <177843fa29560291b8af90db5daffe4852ea96b7.1570034362.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] [PATCH v3 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 , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_?= =?utf-8?q?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 --- 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 99816fc67c..88a15ecdf2 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -119,6 +119,7 @@ #include #include #include +#include #include #include #include @@ -4847,22 +4848,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(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 2800106327..80173eb4c3 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -633,6 +633,17 @@ int arch_acquire_resource(struct domain *d, unsigned int type, /* 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(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); #endif /* __ASM_X86_MM_H__ */ From patchwork Wed Oct 2 17:16:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11171701 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 AC19F14DB for ; Wed, 2 Oct 2019 17:18:37 +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 7D12021D81 for ; Wed, 2 Oct 2019 17:18:37 +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="l3n6Vk/u" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7D12021D81 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 1iFiFP-0008D6-KG; Wed, 02 Oct 2019 17:17:07 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iFiFO-0008D1-SO for xen-devel@lists.xenproject.org; Wed, 02 Oct 2019 17:17:06 +0000 X-Inumbo-ID: 730dd424-e538-11e9-bf31-bc764e2007e4 Received: from smtp-fw-4101.amazon.com (unknown [72.21.198.25]) by localhost (Halon) with ESMTPS id 730dd424-e538-11e9-bf31-bc764e2007e4; Wed, 02 Oct 2019 17:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1570036622; x=1601572622; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=nPtaka/gXfugAqPQq4HcFHXTvUe4DdTjNQEPXGjd+9c=; b=l3n6Vk/uRuif2X5agAEVXNZnWOKiL9ZaCmJk9+m2U6qQDqGcZf/uKZmc 3S2Rp5NDHzCjf8/0sEMEWsQRdwV2alSDLH3W3BCAvALDwsOcIFM7UCvtP WqSOJjCWUMou2dMPXi9Ci7Qs7/u0LFEwwuHZwvBLHXvp/FR6GOMnzZyS2 4=; X-IronPort-AV: E=Sophos;i="5.67,249,1566864000"; d="scan'208";a="789153766" 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-4101.iad4.amazon.com with ESMTP; 02 Oct 2019 17:17:00 +0000 Received: from EX13MTAUEA001.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 8A3FBA1E0F; Wed, 2 Oct 2019 17:16:59 +0000 (UTC) Received: from EX13D06UEE004.ant.amazon.com (10.43.62.44) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 2 Oct 2019 17:16:59 +0000 Received: from EX13MTAUEE001.ant.amazon.com (10.43.62.200) by EX13D06UEE004.ant.amazon.com (10.43.62.44) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 2 Oct 2019 17:16:58 +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; Wed, 2 Oct 2019 17:16:58 +0000 From: Hongyan Xia To: Date: Wed, 2 Oct 2019 18:16:48 +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 v3 3/9] 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: Andrew Cooper , Wei Liu , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_?= =?utf-8?q?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 | 75 ++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 88a15ecdf2..23066c492e 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5061,10 +5061,12 @@ int map_pages_to_xen( } else { - pl2e = l3e_to_l2e(ol3e); + l2_pgentry_t *l2t; + + 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 ) @@ -5072,21 +5074,22 @@ int map_pages_to_xen( else { unsigned int j; + l1_pgentry_t *l1t; - pl1e = l2e_to_l1e(ol2e); + l1t = 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); } } @@ -5102,6 +5105,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 * @@ -5123,12 +5127,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))); @@ -5141,15 +5145,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); @@ -5177,11 +5181,13 @@ int map_pages_to_xen( } else { - pl1e = l2e_to_l1e(ol2e); + l1_pgentry_t *l1t; + + 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); } } @@ -5203,6 +5209,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)) + @@ -5222,12 +5229,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)))); @@ -5239,15 +5246,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); @@ -5272,6 +5279,7 @@ int map_pages_to_xen( ((1u << PAGETABLE_ORDER) - 1)) == 0)) ) { unsigned long base_mfn; + l1_pgentry_t *l1t; if ( locking ) spin_lock(&map_pgdir_lock); @@ -5295,11 +5303,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 ) { @@ -5325,6 +5333,7 @@ int map_pages_to_xen( ((1UL << (L3_PAGETABLE_SHIFT - PAGE_SHIFT)) - 1))) ) { unsigned long base_mfn; + l2_pgentry_t *l2t; if ( locking ) spin_lock(&map_pgdir_lock); @@ -5342,13 +5351,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 Wed Oct 2 17:16:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11171693 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 4950F14DB for ; Wed, 2 Oct 2019 17:18:34 +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 250E2222BE for ; Wed, 2 Oct 2019 17:18:34 +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="XVK66bcX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 250E2222BE 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 1iFiFZ-0008G5-E4; Wed, 02 Oct 2019 17:17:17 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iFiFY-0008Fs-S0 for xen-devel@lists.xenproject.org; Wed, 02 Oct 2019 17:17:16 +0000 X-Inumbo-ID: 788cd242-e538-11e9-8628-bc764e2007e4 Received: from smtp-fw-6001.amazon.com (unknown [52.95.48.154]) by localhost (Halon) with ESMTPS id 788cd242-e538-11e9-8628-bc764e2007e4; Wed, 02 Oct 2019 17:17:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1570036631; x=1601572631; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=tH0b4W+UWpzdh9E5CsarCcvHj0VbyzZplIDQB4UfEXA=; b=XVK66bcXYxzwTWx02BEab3p3G0j/dKbZ1x0+CMCsEd5F/MJVQHsTptFS 7EhHo4XM4qC1Cd8xWX7aFrdqtraG1mxx8yqmBde2Az4Hoc6DedZBhvHlQ 9RYAXSw1PL25k49+Ww411qc4Df1h4n7cdFuvZVslUx4TSrHcIJEPFoJxi g=; X-IronPort-AV: E=Sophos;i="5.67,249,1566864000"; d="scan'208";a="419366681" 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-6001.iad6.amazon.com with ESMTP; 02 Oct 2019 17:17:10 +0000 Received: from EX13MTAUEA001.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 102CCA1EF0; Wed, 2 Oct 2019 17:17:10 +0000 (UTC) Received: from EX13D10UEE001.ant.amazon.com (10.43.62.201) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 2 Oct 2019 17:17:00 +0000 Received: from EX13MTAUEE001.ant.amazon.com (10.43.62.200) by EX13D10UEE001.ant.amazon.com (10.43.62.201) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 2 Oct 2019 17:16:59 +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; Wed, 2 Oct 2019 17:16:59 +0000 From: Hongyan Xia To: Date: Wed, 2 Oct 2019 18:16:49 +0100 Message-ID: <11d0e9d423772a7ddbd7d239a5029952d8b0c132.1570034362.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] [PATCH v3 4/9] 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: Andrew Cooper , Wei Liu , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_?= =?utf-8?q?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 23066c492e..2b8e192e26 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5428,6 +5428,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)) ) @@ -5443,11 +5445,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))); @@ -5456,14 +5458,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); } /* @@ -5497,12 +5499,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 ) @@ -5510,19 +5514,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 @@ -5569,9 +5573,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 ) { @@ -5580,7 +5584,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); @@ -5609,21 +5613,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 Wed Oct 2 17:16:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11171709 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 780DD112B for ; Wed, 2 Oct 2019 17:21:30 +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 5415221848 for ; Wed, 2 Oct 2019 17:21: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="lFvDBUjt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5415221848 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 1iFiIG-0000ql-Fm; Wed, 02 Oct 2019 17:20:04 +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 1iFiIE-0000cC-Fg for xen-devel@lists.xenproject.org; Wed, 02 Oct 2019 17:20:02 +0000 X-Inumbo-ID: dd963854-e538-11e9-971c-12813bfff9fa Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by localhost (Halon) with ESMTPS id dd963854-e538-11e9-971c-12813bfff9fa; Wed, 02 Oct 2019 17:20:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1570036801; x=1601572801; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=nlNmX6oFMATrz1mrFcpu7UP42RxsFpSgYon4ulWCf4k=; b=lFvDBUjt7Or8n9uNLg+yTmeeqhXYAqO8HR0eltHvBSveYaBKu5VzpTT9 Es84st6w32R7EMr0fmMxZzIdECZ0ZC0I1e1sR7eHBzgF1WNvwrQ75EjEM uD7w9OKP5jGcBq0BduWpK+jsID73M77njlmc0r3pqmGTxj5EJNWad6kZV g=; X-IronPort-AV: E=Sophos;i="5.67,249,1566864000"; d="scan'208";a="706204429" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2c-6f38efd9.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 02 Oct 2019 17:17:56 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2c-6f38efd9.us-west-2.amazon.com (Postfix) with ESMTPS id 82251A0561; Wed, 2 Oct 2019 17:17:10 +0000 (UTC) Received: from EX13D18UEE002.ant.amazon.com (10.43.62.65) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 2 Oct 2019 17:17:01 +0000 Received: from EX13MTAUEE001.ant.amazon.com (10.43.62.200) by EX13D18UEE002.ant.amazon.com (10.43.62.65) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 2 Oct 2019 17:17:00 +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; Wed, 2 Oct 2019 17:17:00 +0000 From: Hongyan Xia To: Date: Wed, 2 Oct 2019 18:16:50 +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 v3 5/9] x86/mm: map_pages_to_xen should 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: Andrew Cooper , Wei Liu , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_?= =?utf-8?q?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 --- xen/arch/x86/mm.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 2b8e192e26..26fcb2709b 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5014,9 +5014,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); \ @@ -5034,10 +5036,13 @@ 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; + { + ASSERT(rc == -ENOMEM); + goto out; + } ol3e = *pl3e; if ( cpu_has_page1gb && @@ -5129,7 +5134,10 @@ int map_pages_to_xen( l2t = alloc_xen_pagetable(); if ( l2t == NULL ) - return -ENOMEM; + { + ASSERT(rc == -ENOMEM); + goto out; + } for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ ) l2e_write(l2t + i, @@ -5158,7 +5166,10 @@ int map_pages_to_xen( pl2e = virt_to_xen_l2e(virt); if ( !pl2e ) - return -ENOMEM; + { + ASSERT(rc == -ENOMEM); + goto out; + } if ( ((((virt >> PAGE_SHIFT) | mfn_x(mfn)) & ((1u << PAGETABLE_ORDER) - 1)) == 0) && @@ -5203,7 +5214,10 @@ int map_pages_to_xen( { pl1e = virt_to_xen_l1e(virt); if ( pl1e == NULL ) - return -ENOMEM; + { + ASSERT(rc == -ENOMEM); + goto out; + } } else if ( l2e_get_flags(*pl2e) & _PAGE_PSE ) { @@ -5231,7 +5245,10 @@ int map_pages_to_xen( l1t = alloc_xen_pagetable(); if ( l1t == NULL ) - return -ENOMEM; + { + ASSERT(rc == -ENOMEM); + goto out; + } for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) l1e_write(&l1t[i], @@ -5377,7 +5394,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 Wed Oct 2 17:16:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11171699 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 A62F113B1 for ; Wed, 2 Oct 2019 17:18:37 +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 82C30222BE for ; Wed, 2 Oct 2019 17:18:37 +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="Bkg3G6Lh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 82C30222BE 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 1iFiFf-0008JK-4D; Wed, 02 Oct 2019 17:17:23 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iFiFd-0008Im-Sh for xen-devel@lists.xenproject.org; Wed, 02 Oct 2019 17:17:21 +0000 X-Inumbo-ID: 7a18aae6-e538-11e9-8628-bc764e2007e4 Received: from smtp-fw-6002.amazon.com (unknown [52.95.49.90]) by localhost (Halon) with ESMTPS id 7a18aae6-e538-11e9-8628-bc764e2007e4; Wed, 02 Oct 2019 17:17: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=1570036633; x=1601572633; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=fV/9brbO4gWoje4rTTbmECdy77LcIRpQMwVCOUOHLvY=; b=Bkg3G6Lhx50Jw30+PFrnAspScmFPM6lNOc5gMJ2WpLnPuD8mgI9vvhx6 IXbryp5tu+dpSInjPovNIxiNpMBi3ngJaobQTNZv07zNTT2oG6u3Nm3Wn IUOn+Z/oT5DeTmBg4x+yyY37L64Us8ky30iXNzyss7TMOHr9HGwjPtAAQ Q=; X-IronPort-AV: E=Sophos;i="5.67,249,1566864000"; d="scan'208";a="425367849" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-e7be2041.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 02 Oct 2019 17:17:11 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-e7be2041.us-west-2.amazon.com (Postfix) with ESMTPS id 9DDC2A226F; Wed, 2 Oct 2019 17:17:11 +0000 (UTC) Received: from EX13D10UEE002.ant.amazon.com (10.43.62.136) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 2 Oct 2019 17:17:02 +0000 Received: from EX13MTAUEE001.ant.amazon.com (10.43.62.200) by EX13D10UEE002.ant.amazon.com (10.43.62.136) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 2 Oct 2019 17:17:02 +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; Wed, 2 Oct 2019 17:17:01 +0000 From: Hongyan Xia To: Date: Wed, 2 Oct 2019 18:16:51 +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 v3 6/9] x86/mm: add an end_of_loop label in 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: Andrew Cooper , Wei Liu , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_?= =?utf-8?q?Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Wei Liu We will soon need to clean up mappings whenever the out most loop is ended. Add a new label and turn relevant continue's into goto's. No functional change. Signed-off-by: Wei Liu --- xen/arch/x86/mm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 26fcb2709b..5a5f0685cc 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5102,7 +5102,7 @@ int map_pages_to_xen( if ( !mfn_eq(mfn, INVALID_MFN) ) mfn = mfn_add(mfn, 1UL << (L3_PAGETABLE_SHIFT - PAGE_SHIFT)); nr_mfns -= 1UL << (L3_PAGETABLE_SHIFT - PAGE_SHIFT); - continue; + goto end_of_loop; } if ( (l3e_get_flags(ol3e) & _PAGE_PRESENT) && @@ -5129,7 +5129,7 @@ int map_pages_to_xen( if ( !mfn_eq(mfn, INVALID_MFN) ) mfn = mfn_add(mfn, i); nr_mfns -= i; - continue; + goto end_of_loop; } l2t = alloc_xen_pagetable(); @@ -5310,7 +5310,7 @@ int map_pages_to_xen( { if ( locking ) spin_unlock(&map_pgdir_lock); - continue; + goto end_of_loop; } if ( l2e_get_flags(ol2e) & _PAGE_PSE ) @@ -5365,7 +5365,7 @@ int map_pages_to_xen( { if ( locking ) spin_unlock(&map_pgdir_lock); - continue; + goto end_of_loop; } l2t = l3e_to_l2e(ol3e); @@ -5390,6 +5390,7 @@ int map_pages_to_xen( else if ( locking ) spin_unlock(&map_pgdir_lock); } + end_of_loop:; } #undef flush_flags From patchwork Wed Oct 2 17:16:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11171705 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 0C09913BD for ; Wed, 2 Oct 2019 17:18:42 +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 DBAC921D81 for ; Wed, 2 Oct 2019 17:18:41 +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="OsmxR+Fx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DBAC921D81 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 1iFiFk-0008MP-Fe; Wed, 02 Oct 2019 17:17:28 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iFiFi-0008Lb-SA for xen-devel@lists.xenproject.org; Wed, 02 Oct 2019 17:17:26 +0000 X-Inumbo-ID: 7ae19ee2-e538-11e9-8628-bc764e2007e4 Received: from smtp-fw-6001.amazon.com (unknown [52.95.48.154]) by localhost (Halon) with ESMTPS id 7ae19ee2-e538-11e9-8628-bc764e2007e4; Wed, 02 Oct 2019 17:17: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=1570036635; x=1601572635; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=tjeKGCbuAqsatSmRBJDdSqvisBAGgtdMPQqc19l9ulA=; b=OsmxR+Fxm/qVzxUY6ePWK+9NTuaOXLReRAu/rCFBqUN3h42DXkfSbPRz WY+vxwGVT4saXkjJDbrburaY537YuQSko5zM4474BNg2Th+wgXIRkSQ6u DvZ+GTaOzMMSX6OVZTa+DjIXI6KbzVoBTSsVZ/pwfKaaJmT5DGpQB3wqF I=; X-IronPort-AV: E=Sophos;i="5.67,249,1566864000"; d="scan'208";a="419366689" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2b-c7131dcf.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 02 Oct 2019 17:17:14 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-c7131dcf.us-west-2.amazon.com (Postfix) with ESMTPS id C79C5A2325; Wed, 2 Oct 2019 17:17:13 +0000 (UTC) Received: from EX13D08UEE002.ant.amazon.com (10.43.62.92) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 2 Oct 2019 17:17:03 +0000 Received: from EX13MTAUEE001.ant.amazon.com (10.43.62.200) by EX13D08UEE002.ant.amazon.com (10.43.62.92) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 2 Oct 2019 17:17:02 +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; Wed, 2 Oct 2019 17:17:02 +0000 From: Hongyan Xia To: Date: Wed, 2 Oct 2019 18:16:52 +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 v3 7/9] 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: Andrew Cooper , Wei Liu , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_?= =?utf-8?q?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 --- xen/arch/x86/mm.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 5a5f0685cc..3838343b87 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5425,6 +5425,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) @@ -5468,7 +5469,11 @@ 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; + { + ASSERT(rc == -ENOMEM); + goto out; + } + for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ ) l2e_write(l2t + i, l2e_from_pfn(l3e_get_pfn(*pl3e) + @@ -5525,7 +5530,11 @@ 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; + { + ASSERT(rc == -ENOMEM); + goto out; + } + for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) l1e_write(&l1t[i], l1e_from_pfn(l2e_get_pfn(*pl2e) + i, @@ -5658,7 +5667,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 Wed Oct 2 17:16:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11171711 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 0441213BD for ; Wed, 2 Oct 2019 17:21:32 +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 D473321848 for ; Wed, 2 Oct 2019 17:21: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="ppt9pW6G" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D473321848 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 1iFiIO-00018s-Qe; Wed, 02 Oct 2019 17:20:12 +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 1iFiIN-00018a-IK for xen-devel@lists.xenproject.org; Wed, 02 Oct 2019 17:20:11 +0000 X-Inumbo-ID: e3409574-e538-11e9-971c-12813bfff9fa Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by localhost (Halon) with ESMTPS id e3409574-e538-11e9-971c-12813bfff9fa; Wed, 02 Oct 2019 17:20:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1570036811; x=1601572811; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=UjuKLyVt5NcnOe8Xrtb78RB4wfI3B0cRksZlB3VQq9Q=; b=ppt9pW6GWN3kSu5pmScQxuhMwthm6MepR24bZ5iuhdvgNojyy7QlLtyA 8aeCN+XJ38SbbOg1Wy8iKZYTeZLQVggO1wN2tqo1M6QNwxz69N44Wu5VR 74wAb82i6yhYnjmeLQynjaYsnXDxQJ+uVUG4GHlpktGdLqSCMbEfrx5g2 o=; X-IronPort-AV: E=Sophos;i="5.67,249,1566864000"; d="scan'208";a="706204485" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2a-8549039f.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 02 Oct 2019 17:18:08 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-8549039f.us-west-2.amazon.com (Postfix) with ESMTPS id 04807A1C11; Wed, 2 Oct 2019 17:17:14 +0000 (UTC) Received: from EX13D14UEE004.ant.amazon.com (10.43.62.145) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 2 Oct 2019 17:17:04 +0000 Received: from EX13MTAUEE001.ant.amazon.com (10.43.62.200) by EX13D14UEE004.ant.amazon.com (10.43.62.145) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 2 Oct 2019 17:17:03 +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; Wed, 2 Oct 2019 17:17:03 +0000 From: Hongyan Xia To: Date: Wed, 2 Oct 2019 18:16:53 +0100 Message-ID: <8bd69059eeda992d55ba29dd5946903cb55620fd.1570034362.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] [PATCH v3 8/9] x86/mm: add an end_of_loop label in 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: Andrew Cooper , Wei Liu , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_?= =?utf-8?q?Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Wei Liu We will soon need to clean up mappings whenever the out most loop is ended. Add a new label and turn relevant continue's into goto's. No functional change. Signed-off-by: Wei Liu --- xen/arch/x86/mm.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 3838343b87..d7eb804f06 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5445,7 +5445,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) v += 1UL << L3_PAGETABLE_SHIFT; v &= ~((1UL << L3_PAGETABLE_SHIFT) - 1); - continue; + goto end_of_loop; } if ( l3e_get_flags(*pl3e) & _PAGE_PSE ) @@ -5463,7 +5463,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) l3e_write_atomic(pl3e, nl3e); v += 1UL << L3_PAGETABLE_SHIFT; - continue; + goto end_of_loop; } /* PAGE1GB: shatter the superpage and fall through. */ @@ -5507,7 +5507,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) v += 1UL << L2_PAGETABLE_SHIFT; v &= ~((1UL << L2_PAGETABLE_SHIFT) - 1); - continue; + goto end_of_loop; } if ( l2e_get_flags(*pl2e) & _PAGE_PSE ) @@ -5581,7 +5581,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) * skip the empty&free check. */ if ( (nf & _PAGE_PRESENT) || ((v != e) && (l1_table_offset(v) != 0)) ) - continue; + goto end_of_loop; if ( locking ) spin_lock(&map_pgdir_lock); @@ -5600,7 +5600,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) { if ( locking ) spin_unlock(&map_pgdir_lock); - continue; + goto end_of_loop; } l1t = l2e_to_l1e(*pl2e); @@ -5627,7 +5627,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) */ if ( (nf & _PAGE_PRESENT) || ((v != e) && (l2_table_offset(v) + l1_table_offset(v) != 0)) ) - continue; + goto end_of_loop; if ( locking ) spin_lock(&map_pgdir_lock); @@ -5640,7 +5640,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) { if ( locking ) spin_unlock(&map_pgdir_lock); - continue; + goto end_of_loop; } { @@ -5662,6 +5662,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) else if ( locking ) spin_unlock(&map_pgdir_lock); } + end_of_loop:; } flush_area(NULL, FLUSH_TLB_GLOBAL); From patchwork Wed Oct 2 17:16: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: 11171703 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 B655B112B for ; Wed, 2 Oct 2019 17:18:37 +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 9260C222C0 for ; Wed, 2 Oct 2019 17:18:37 +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="MfuDNpkR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9260C222C0 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 1iFiFb-0008HM-QM; Wed, 02 Oct 2019 17:17:19 +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 1iFiFa-0008Gi-HY for xen-devel@lists.xenproject.org; Wed, 02 Oct 2019 17:17:18 +0000 X-Inumbo-ID: 7c88dc4c-e538-11e9-971c-12813bfff9fa Received: from smtp-fw-2101.amazon.com (unknown [72.21.196.25]) by localhost (Halon) with ESMTPS id 7c88dc4c-e538-11e9-971c-12813bfff9fa; Wed, 02 Oct 2019 17:17:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1570036638; x=1601572638; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=mGoiEalAlkkotdrI6fYCm5yWWMR/P1p/JssBzZjs3OE=; b=MfuDNpkR6IPa3OycjRAZL+SKFhil/pcKXGNV/PBbL76BwZ5iETcsnU7d xeXjx7+WRTKwXr5I3CVa7nCXUlD9u3MqCkEGL6b3Igo3AUNhUoPMnIIIm i9V+p2e+X2cPa3TnG9XmEtkFl/irgSy61ZF5JCfzZy8uUJKrGjGLvLzkZ A=; X-IronPort-AV: E=Sophos;i="5.67,249,1566864000"; d="scan'208";a="754987328" Received: from iad6-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2a-53356bf6.us-west-2.amazon.com) ([10.124.125.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 02 Oct 2019 17:17:17 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-53356bf6.us-west-2.amazon.com (Postfix) with ESMTPS id D7FD1A2630; Wed, 2 Oct 2019 17:17:16 +0000 (UTC) Received: from EX13D10UEE004.ant.amazon.com (10.43.62.185) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 2 Oct 2019 17:17:05 +0000 Received: from EX13MTAUEE001.ant.amazon.com (10.43.62.200) by EX13D10UEE004.ant.amazon.com (10.43.62.185) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 2 Oct 2019 17:17:04 +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; Wed, 2 Oct 2019 17:17:04 +0000 From: Hongyan Xia To: Date: Wed, 2 Oct 2019 18:16:54 +0100 Message-ID: <55b6fbdac35d5c5b299a6c19315f462308ed6f3a.1570034362.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] [PATCH v3 9/9] 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: Andrew Cooper , Wei Liu , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_?= =?utf-8?q?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 d7eb804f06..79c65b15d5 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4904,25 +4904,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); @@ -4939,22 +4939,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); @@ -4972,22 +4972,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);