From patchwork Thu Jul 20 16:04:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9855329 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 89B18600F5 for ; Thu, 20 Jul 2017 16:18:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79EC7286DE for ; Thu, 20 Jul 2017 16:18:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6EDEF2870D; Thu, 20 Jul 2017 16:18:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E196628721 for ; Thu, 20 Jul 2017 16:18:38 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dYE7y-00030g-1M; Thu, 20 Jul 2017 16:16:38 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dYE7w-0002yY-Bk for xen-devel@lists.xenproject.org; Thu, 20 Jul 2017 16:16:36 +0000 Received: from [85.158.143.35] by server-7.bemta-6.messagelabs.com id 7A/48-03557-367D0795; Thu, 20 Jul 2017 16:16:35 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprGIsWRWlGSWpSXmKPExsXitHRDpG7S9YJ Ig5+LrSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1ox1S26xFTw2qJg79QBTA+Na9S5GTg4JAX+J 9ydesoLYbALKEj87e9lAbBEBPYmmA88Zuxi5OJgF5jBKTJ3bBeRwcAgLuEqcWJoJUsMioCrR+ vsgO4jNK2AhMXPzCnaImfISu9ougs3kBIqv+fWVCcQWEjCX2Lx/PguErSDRMf0YE0SvoMTJmU /A4swCEhIHX7xgnsDIOwtJahaS1AJGplWM6sWpRWWpRbpmeklFmekZJbmJmTm6hgZmermpxcW J6ak5iUnFesn5uZsYgaHDAAQ7GOed8D/EKMnBpCTKyxJYECnEl5SfUpmRWJwRX1Sak1p8iFGG g0NJgpfhGlBOsCg1PbUiLTMHGMQwaQkOHiURXkGQNG9xQWJucWY6ROoUozFHx4yf35g4Xk34/ 41JiCUvPy9VSpzXBqRUAKQ0ozQPbhAsui4xykoJ8zICnSbEU5BalJtZgir/ilGcg1FJmHfdVa ApPJl5JXD7XgGdwgR0yiM3sFNKEhFSUg2M2RI3Jmu48v2qF5mnKvTXkLm43GfdjxDHU3K2Uma Kgb/f5U/Z1eG44VsXZ78ti+bjbatU3e6smfLvxddj4SmlJ1o/Fb12VctpuGh/dovsrN9VqzXm LxZyFgvuq7foOmfIEr9mP7vQKcX4wCNalSsq/52cwTh7YUdSe/nujwabtqZPsVh77vwfJZbij ERDLeai4kQAp5SWP6kCAAA= X-Env-Sender: prvs=3674d857a=wei.liu2@citrix.com X-Msg-Ref: server-10.tower-21.messagelabs.com!1500567380!67573675!6 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 49569 invoked from network); 20 Jul 2017 16:16:34 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-10.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 20 Jul 2017 16:16:34 -0000 X-IronPort-AV: E=Sophos;i="5.40,384,1496102400"; d="scan'208";a="432310750" From: Wei Liu To: Xen-devel Date: Thu, 20 Jul 2017 17:04:23 +0100 Message-ID: <20170720160426.2343-19-wei.liu2@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170720160426.2343-1-wei.liu2@citrix.com> References: <20170720160426.2343-1-wei.liu2@citrix.com> MIME-Version: 1.0 Cc: George Dunlap , Andrew Cooper , Wei Liu , Jan Beulich Subject: [Xen-devel] [PATCH v3 18/21] x86/mm: move and rename map_ldt_shadow_page X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Take the chance to change v to curr and d to currd in code. Also change the return type to bool. Fix up all the call sites. Signed-off-by: Wei Liu --- xen/arch/x86/mm.c | 42 ------------------------------------- xen/arch/x86/pv/descriptor-tables.c | 42 +++++++++++++++++++++++++++++++++++++ xen/arch/x86/traps.c | 5 +++-- xen/include/asm-x86/mm.h | 2 -- xen/include/asm-x86/pv/processor.h | 2 ++ 5 files changed, 47 insertions(+), 46 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 1a9517fda8..109a109155 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -604,48 +604,6 @@ static int alloc_segdesc_page(struct page_info *page) } -/* Map shadow page at offset @off. */ -int map_ldt_shadow_page(unsigned int off) -{ - struct vcpu *v = current; - struct domain *d = v->domain; - unsigned long gmfn; - struct page_info *page; - l1_pgentry_t l1e, nl1e; - unsigned long gva = v->arch.pv_vcpu.ldt_base + (off << PAGE_SHIFT); - int okay; - - BUG_ON(unlikely(in_irq())); - - if ( is_pv_32bit_domain(d) ) - gva = (u32)gva; - pv_get_guest_eff_kern_l1e(v, gva, &l1e); - if ( unlikely(!(l1e_get_flags(l1e) & _PAGE_PRESENT)) ) - return 0; - - gmfn = l1e_get_pfn(l1e); - page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC); - if ( unlikely(!page) ) - return 0; - - okay = get_page_type(page, PGT_seg_desc_page); - if ( unlikely(!okay) ) - { - put_page(page); - return 0; - } - - nl1e = l1e_from_pfn(page_to_mfn(page), l1e_get_flags(l1e) | _PAGE_RW); - - spin_lock(&v->arch.pv_vcpu.shadow_ldt_lock); - l1e_write(&gdt_ldt_ptes(d, v)[off + 16], nl1e); - v->arch.pv_vcpu.shadow_ldt_mapcnt++; - spin_unlock(&v->arch.pv_vcpu.shadow_ldt_lock); - - return 1; -} - - int get_page_from_pagenr(unsigned long page_nr, struct domain *d) { struct page_info *page = mfn_to_page(page_nr); diff --git a/xen/arch/x86/pv/descriptor-tables.c b/xen/arch/x86/pv/descriptor-tables.c index a302812774..6ac5c736cf 100644 --- a/xen/arch/x86/pv/descriptor-tables.c +++ b/xen/arch/x86/pv/descriptor-tables.c @@ -24,6 +24,7 @@ #include #include +#include #include /************************* @@ -217,6 +218,47 @@ int compat_update_descriptor(u32 pa_lo, u32 pa_hi, u32 desc_lo, u32 desc_hi) desc_lo | ((u64)desc_hi << 32)); } +/* Map shadow page at offset @off. */ +bool pv_map_ldt_shadow_page(unsigned int off) +{ + struct vcpu *curr = current; + struct domain *currd = curr->domain; + unsigned long gmfn; + struct page_info *page; + l1_pgentry_t l1e, nl1e; + unsigned long gva = curr->arch.pv_vcpu.ldt_base + (off << PAGE_SHIFT); + int okay; + + BUG_ON(unlikely(in_irq())); + + if ( is_pv_32bit_domain(currd) ) + gva = (u32)gva; + pv_get_guest_eff_kern_l1e(curr, gva, &l1e); + if ( unlikely(!(l1e_get_flags(l1e) & _PAGE_PRESENT)) ) + return false; + + gmfn = l1e_get_pfn(l1e); + page = get_page_from_gfn(currd, gmfn, NULL, P2M_ALLOC); + if ( unlikely(!page) ) + return false; + + okay = get_page_type(page, PGT_seg_desc_page); + if ( unlikely(!okay) ) + { + put_page(page); + return false; + } + + nl1e = l1e_from_pfn(page_to_mfn(page), l1e_get_flags(l1e) | _PAGE_RW); + + spin_lock(&curr->arch.pv_vcpu.shadow_ldt_lock); + l1e_write(&gdt_ldt_ptes(currd, curr)[off + 16], nl1e); + curr->arch.pv_vcpu.shadow_ldt_mapcnt++; + spin_unlock(&curr->arch.pv_vcpu.shadow_ldt_lock); + + return true; +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index b93b3d1317..dbdcdf62a6 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -77,6 +77,7 @@ #include #include #include +#include #include /* @@ -1100,7 +1101,7 @@ static int handle_gdt_ldt_mapping_fault(unsigned long offset, /* * If the fault is in another vcpu's area, it cannot be due to * a GDT/LDT descriptor load. Thus we can reasonably exit immediately, and - * indeed we have to since map_ldt_shadow_page() works correctly only on + * indeed we have to since pv_map_ldt_shadow_page() works correctly only on * accesses to a vcpu's own area. */ if ( vcpu_area != curr->vcpu_id ) @@ -1112,7 +1113,7 @@ static int handle_gdt_ldt_mapping_fault(unsigned long offset, if ( likely(is_ldt_area) ) { /* LDT fault: Copy a mapping from the guest's LDT, if it is valid. */ - if ( likely(map_ldt_shadow_page(offset >> PAGE_SHIFT)) ) + if ( likely(pv_map_ldt_shadow_page(offset >> PAGE_SHIFT)) ) { if ( guest_mode(regs) ) trace_trap_two_addr(TRC_PV_GDT_LDT_MAPPING_FAULT, diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index 6fc1e7d5ca..07287d97ca 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -550,8 +550,6 @@ long subarch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg); int compat_arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void)); int compat_subarch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void)); -int map_ldt_shadow_page(unsigned int); - #define NIL(type) ((type *)-sizeof(type)) #define IS_NIL(ptr) (!((uintptr_t)(ptr) + sizeof(*(ptr)))) diff --git a/xen/include/asm-x86/pv/processor.h b/xen/include/asm-x86/pv/processor.h index 8ab5773871..6f9e1afe8a 100644 --- a/xen/include/asm-x86/pv/processor.h +++ b/xen/include/asm-x86/pv/processor.h @@ -25,6 +25,7 @@ void pv_destroy_gdt(struct vcpu *d); long pv_set_gdt(struct vcpu *d, unsigned long *frames, unsigned int entries); +bool pv_map_ldt_shadow_page(unsigned int); #else @@ -34,6 +35,7 @@ static inline void pv_destroy_gdt(struct vcpu *d) {} static inline long pv_set_gdt(struct vcpu *d, unsigned long *frames, unsigned int entries) { return -EINVAL; } +static inline bool pv_map_ldt_shadow_page(unsigned int) { return false; } #endif