From patchwork Sun Jul 30 15:43:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9870551 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 97ADE60353 for ; Sun, 30 Jul 2017 15:46:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86E6B28462 for ; Sun, 30 Jul 2017 15:46:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 79BB428599; Sun, 30 Jul 2017 15:46:58 +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 DFF4428462 for ; Sun, 30 Jul 2017 15:46:57 +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 1dbqNc-0006MT-N8; Sun, 30 Jul 2017 15:43:44 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dbqNa-0006LH-Kd for xen-devel@lists.xenproject.org; Sun, 30 Jul 2017 15:43:42 +0000 Received: from [85.158.137.68] by server-5.bemta-3.messagelabs.com id 47/86-02181-DAEFD795; Sun, 30 Jul 2017 15:43:41 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprIIsWRWlGSWpSXmKPExsXitHSDve7af7W RBtc+i1h83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBl3N/9jKpioXnFm5V2mBsYWuS5GDg4JAX+J WY80uxg5OdgElCV+dvaygdgiAnoSTQeeM3YxcnEwC8xhlJg6t4sRJCEsECGxtuUFM4jNIqAqc ff5VyYQm1fAQqLx1U92EFtCQF5iV9tFVhCbU8BSYtOSLrAaIYFUiTPHVrBD2AoSHdOPQfUKSp yc+YQFxGYWkJA4+OIF8wRG3llIUrOQpBYwMq1i1ChOLSpLLdI1MtNLKspMzyjJTczM0TU0MNb LTS0uTkxPzUlMKtZLzs/dxAgMnnoGBsYdjA17/Q4xSnIwKYnyruOujRTiS8pPqcxILM6ILyrN SS0+xCjDwaEkwfvhL1BOsCg1PbUiLTMHGMYwaQkOHiURXh5gKAvxFhck5hZnpkOkTjHqcrya8 P8bkxBLXn5eqpQ47y+QGQIgRRmleXAjYDF1iVFWSpiXkYGBQYinILUoN7MEVf4VozgHo5Iw7y KQKTyZeSVwm14BHcEEdIRkKdgRJYkIKakGxop5Vkr5Wnw7W9OXtDL47W8ImB0T+t3L3Inntsz sqzyipdEvnf8ek2l/X9h6bWXI6t0FdTxeTgsfB8z78cwhRUFk7n5O6xsbYpg0Dy85dmX27ZNm 7P4Hew0nua53TTvGM7uTqUL/4B7z4AiPNbcemz+/85DLS2itmbfc0RbG6i8PVh9YaP8/U4mlO CPRUIu5qDgRANnTbAKkAgAA X-Env-Sender: prvs=37723ee83=wei.liu2@citrix.com X-Msg-Ref: server-13.tower-31.messagelabs.com!1501429419!103196474!2 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 48059 invoked from network); 30 Jul 2017 15:43:41 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-13.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 30 Jul 2017 15:43:41 -0000 X-IronPort-AV: E=Sophos;i="5.40,437,1496102400"; d="scan'208";a="441941022" From: Wei Liu To: Xen-devel Date: Sun, 30 Jul 2017 16:43:30 +0100 Message-ID: <20170730154335.24313-7-wei.liu2@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170730154335.24313-1-wei.liu2@citrix.com> References: <20170720160426.2343-1-wei.liu2@citrix.com> <20170730154335.24313-1-wei.liu2@citrix.com> MIME-Version: 1.0 Cc: George Dunlap , Andrew Cooper , Wei Liu , Jan Beulich Subject: [Xen-devel] [PATCH v3 extra 06/11] x86/mm: move and add pv_ prefix to invalidate_shadow_ldt 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 Move the code to pv/mm.c and export it via pv/mm.h. Use bool for flush. Signed-off-by: Wei Liu --- xen/arch/x86/mm.c | 44 ++++---------------------------------------- xen/arch/x86/pv/mm.c | 35 +++++++++++++++++++++++++++++++++++ xen/include/asm-x86/pv/mm.h | 4 ++++ 3 files changed, 43 insertions(+), 40 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index ac0e0ba346..76ce5aef68 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -478,42 +478,6 @@ static inline void page_set_tlbflush_timestamp(struct page_info *page) const char __section(".bss.page_aligned.const") __aligned(PAGE_SIZE) zero_page[PAGE_SIZE]; -static void invalidate_shadow_ldt(struct vcpu *v, int flush) -{ - l1_pgentry_t *pl1e; - unsigned int i; - struct page_info *page; - - BUG_ON(unlikely(in_irq())); - - spin_lock(&v->arch.pv_vcpu.shadow_ldt_lock); - - if ( v->arch.pv_vcpu.shadow_ldt_mapcnt == 0 ) - goto out; - - v->arch.pv_vcpu.shadow_ldt_mapcnt = 0; - pl1e = gdt_ldt_ptes(v->domain, v); - - for ( i = 16; i < 32; i++ ) - { - if ( !(l1e_get_flags(pl1e[i]) & _PAGE_PRESENT) ) - continue; - page = l1e_get_page(pl1e[i]); - l1e_write(&pl1e[i], l1e_empty()); - ASSERT_PAGE_IS_TYPE(page, PGT_seg_desc_page); - ASSERT_PAGE_IS_DOMAIN(page, v->domain); - put_page_and_type(page); - } - - /* Rid TLBs of stale mappings (guest mappings and shadow mappings). */ - if ( flush ) - flush_tlb_mask(v->vcpu_dirty_cpumask); - - out: - spin_unlock(&v->arch.pv_vcpu.shadow_ldt_lock); -} - - bool get_page_from_mfn(mfn_t mfn, struct domain *d) { struct page_info *page = mfn_to_page(mfn_x(mfn)); @@ -1059,7 +1023,7 @@ void put_page_from_l1e(l1_pgentry_t l1e, struct domain *l1e_owner) (l1e_owner == pg_owner) ) { for_each_vcpu ( pg_owner, v ) - invalidate_shadow_ldt(v, 1); + pv_invalidate_shadow_ldt(v, true); } put_page(page); } @@ -1958,7 +1922,7 @@ int pv_new_guest_cr3(unsigned long mfn) return rc; } - invalidate_shadow_ldt(curr, 0); + pv_invalidate_shadow_ldt(curr, false); write_ptbase(curr); return 0; @@ -1996,7 +1960,7 @@ int pv_new_guest_cr3(unsigned long mfn) return rc; } - invalidate_shadow_ldt(curr, 0); + pv_invalidate_shadow_ldt(curr, false); if ( !VM_ASSIST(currd, m2p_strict) && !paging_mode_refcounts(currd) ) fill_ro_mpt(mfn); @@ -2496,7 +2460,7 @@ long do_mmuext_op( else if ( (curr->arch.pv_vcpu.ldt_ents != ents) || (curr->arch.pv_vcpu.ldt_base != ptr) ) { - invalidate_shadow_ldt(curr, 0); + pv_invalidate_shadow_ldt(curr, false); flush_tlb_local(); curr->arch.pv_vcpu.ldt_base = ptr; curr->arch.pv_vcpu.ldt_ents = ents; diff --git a/xen/arch/x86/pv/mm.c b/xen/arch/x86/pv/mm.c index f0393b9e3c..19b2ae588e 100644 --- a/xen/arch/x86/pv/mm.c +++ b/xen/arch/x86/pv/mm.c @@ -742,6 +742,41 @@ int pv_free_page_type(struct page_info *page, unsigned long type, return rc; } +void pv_invalidate_shadow_ldt(struct vcpu *v, bool flush) +{ + l1_pgentry_t *pl1e; + unsigned int i; + struct page_info *page; + + BUG_ON(unlikely(in_irq())); + + spin_lock(&v->arch.pv_vcpu.shadow_ldt_lock); + + if ( v->arch.pv_vcpu.shadow_ldt_mapcnt == 0 ) + goto out; + + v->arch.pv_vcpu.shadow_ldt_mapcnt = 0; + pl1e = gdt_ldt_ptes(v->domain, v); + + for ( i = 16; i < 32; i++ ) + { + if ( !(l1e_get_flags(pl1e[i]) & _PAGE_PRESENT) ) + continue; + page = l1e_get_page(pl1e[i]); + l1e_write(&pl1e[i], l1e_empty()); + ASSERT_PAGE_IS_TYPE(page, PGT_seg_desc_page); + ASSERT_PAGE_IS_DOMAIN(page, v->domain); + put_page_and_type(page); + } + + /* Rid TLBs of stale mappings (guest mappings and shadow mappings). */ + if ( flush ) + flush_tlb_mask(v->vcpu_dirty_cpumask); + + out: + spin_unlock(&v->arch.pv_vcpu.shadow_ldt_lock); +} + /* * Local variables: * mode: C diff --git a/xen/include/asm-x86/pv/mm.h b/xen/include/asm-x86/pv/mm.h index 841666e7a0..664d7c3868 100644 --- a/xen/include/asm-x86/pv/mm.h +++ b/xen/include/asm-x86/pv/mm.h @@ -101,6 +101,8 @@ int pv_alloc_page_type(struct page_info *page, unsigned long type, int pv_free_page_type(struct page_info *page, unsigned long type, bool preemptible); +void pv_invalidate_shadow_ldt(struct vcpu *v, bool flush); + #else #include @@ -138,6 +140,8 @@ static inline int pv_free_page_type(struct page_info *page, unsigned long type, bool preemptible) { return -EINVAL; } +static inline void pv_invalidate_shadow_ldt(struct vcpu *v, bool flush) {} + #endif #endif /* __X86_PV_MM_H__ */