From patchwork Thu Aug 17 14:44:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9906481 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 168F56038C for ; Thu, 17 Aug 2017 14:47:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 082D628B29 for ; Thu, 17 Aug 2017 14:47:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F165A28B2D; Thu, 17 Aug 2017 14:47:33 +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 6FA9C28B29 for ; Thu, 17 Aug 2017 14:47:33 +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 1diM2l-0000ye-EP; Thu, 17 Aug 2017 14:45:07 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1diM2k-0000yG-48 for xen-devel@lists.xenproject.org; Thu, 17 Aug 2017 14:45:06 +0000 Received: from [85.158.137.68] by server-11.bemta-3.messagelabs.com id 14/EA-01724-1FBA5995; Thu, 17 Aug 2017 14:45:05 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprOIsWRWlGSWpSXmKPExsXitHRDpO771VM jDX49UrP4vmUykwOjx+EPV1gCGKNYM/OS8isSWDMeTHjKUnDbouLbnHdsDYxtul2MnBwSAv4S U15OYgGx2QSUJX529rKB2CICehJNB54zdjFycTALzGGUmDq3C8jh4BAW8JLYfTEIpIZFQFXi0 IQlzCA2r4CFxLkvPxghZspL7Gq7yApicwpYShyatBisRgioZvaHdnYIW0GiY/oxJoheQYmTM5 +A3cAsICFx8MUL5gmMvLOQpGYhSS1gZFrFqFGcWlSWWqRrbKCXVJSZnlGSm5iZo2toYKyXm1p cnJiempOYVKyXnJ+7iREYPPUMDIw7GDtP+B1ilORgUhLl/T1rSqQQX1J+SmVGYnFGfFFpTmrx IUYZDg4lCV73VVMjhQSLUtNTK9Iyc4BhDJOW4OBREuFtBUnzFhck5hZnpkOkTjEacyzo2fCFi ePVhP/fmIRY8vLzUqXEee+BlAqAlGaU5sENgsXXJUZZKWFeRgYGBiGegtSi3MwSVPlXjOIcjE rCvDNApvBk5pXA7XsFdAoT0ClX2ieBnFKSiJCSamA0K56Wv1fd4c9TqY+vJ90sZj/KyiVjtPW pB5fMd34hjZotJZuC6wL92ZMCFvSmTPSazZlkcd5sW7K3zs4PnstmKWUWr9adr7xugXX7KYnb h/WebtZvrpqbc0Co/nPOId+YBR/WXU/6Y/uRdTNfuhWn2s7/Z1rupJm9u75S0M9GJ7xdeXdpP acSS3FGoqEWc1FxIgCkIsDKqgIAAA== X-Env-Sender: prvs=395e6b081=wei.liu2@citrix.com X-Msg-Ref: server-14.tower-31.messagelabs.com!1502981098!110297526!4 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.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 64486 invoked from network); 17 Aug 2017 14:45:03 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-14.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 17 Aug 2017 14:45:03 -0000 X-IronPort-AV: E=Sophos;i="5.41,388,1498521600"; d="scan'208";a="435893166" From: Wei Liu To: Xen-devel Date: Thu, 17 Aug 2017 15:44:32 +0100 Message-ID: <20170817144456.18989-8-wei.liu2@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170817144456.18989-1-wei.liu2@citrix.com> References: <20170817144456.18989-1-wei.liu2@citrix.com> MIME-Version: 1.0 Cc: George Dunlap , Andrew Cooper , Wei Liu , Jan Beulich Subject: [Xen-devel] [PATCH v4 07/31] x86/mm: move and rename guest_get_eff{, kern}_l1e 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 them to pv/mm.c and rename them to pv_get_guest_eff_{,kern}_l1e. Export them via pv/mm.h. They will be used later in emulation handlers. Signed-off-by: Wei Liu --- xen/arch/x86/mm.c | 38 +++---------------------- xen/arch/x86/pv/Makefile | 1 + xen/arch/x86/pv/mm.c | 67 +++++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/pv/mm.h | 53 +++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 34 deletions(-) create mode 100644 xen/arch/x86/pv/mm.c create mode 100644 xen/include/asm-x86/pv/mm.h diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index e0e655ac31..7eb80ecaa3 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -125,6 +125,7 @@ #include #include +#include #include "pv/emulate.h" @@ -554,37 +555,6 @@ static inline void guest_unmap_l1e(void *p) unmap_domain_page(p); } -/* Read a PV guest's l1e that maps this virtual address. */ -static inline void guest_get_eff_l1e(unsigned long addr, l1_pgentry_t *eff_l1e) -{ - ASSERT(!paging_mode_translate(current->domain)); - ASSERT(!paging_mode_external(current->domain)); - - if ( unlikely(!__addr_ok(addr)) || - __copy_from_user(eff_l1e, - &__linear_l1_table[l1_linear_offset(addr)], - sizeof(l1_pgentry_t)) ) - *eff_l1e = l1e_empty(); -} - -/* - * Read the guest's l1e that maps this address, from the kernel-mode - * page tables. - */ -static inline void guest_get_eff_kern_l1e(struct vcpu *v, unsigned long addr, - void *eff_l1e) -{ - const bool user_mode = !(v->arch.flags & TF_kernel_mode); - - if ( user_mode ) - toggle_guest_mode(v); - - guest_get_eff_l1e(addr, eff_l1e); - - if ( user_mode ) - toggle_guest_mode(v); -} - static inline void page_set_tlbflush_timestamp(struct page_info *page) { /* @@ -669,7 +639,7 @@ int map_ldt_shadow_page(unsigned int off) if ( is_pv_32bit_domain(d) ) gva = (u32)gva; - guest_get_eff_kern_l1e(v, gva, &l1e); + pv_get_guest_eff_kern_l1e(v, gva, &l1e); if ( unlikely(!(l1e_get_flags(l1e) & _PAGE_PRESENT)) ) return 0; @@ -5168,7 +5138,7 @@ int ptwr_do_page_fault(struct vcpu *v, unsigned long addr, int rc; /* Attempt to read the PTE that maps the VA being accessed. */ - guest_get_eff_l1e(addr, &pte); + pv_get_guest_eff_l1e(addr, &pte); /* We are looking only for read-only mappings of p.t. pages. */ if ( ((l1e_get_flags(pte) & (_PAGE_PRESENT|_PAGE_RW)) != _PAGE_PRESENT) || @@ -5323,7 +5293,7 @@ int mmio_ro_do_page_fault(struct vcpu *v, unsigned long addr, int rc; /* Attempt to read the PTE that maps the VA being accessed. */ - guest_get_eff_l1e(addr, &pte); + pv_get_guest_eff_l1e(addr, &pte); /* We are looking only for read-only mappings of MMIO pages. */ if ( ((l1e_get_flags(pte) & (_PAGE_PRESENT|_PAGE_RW)) != _PAGE_PRESENT) ) diff --git a/xen/arch/x86/pv/Makefile b/xen/arch/x86/pv/Makefile index 4e15484471..c83aed493b 100644 --- a/xen/arch/x86/pv/Makefile +++ b/xen/arch/x86/pv/Makefile @@ -7,6 +7,7 @@ obj-y += emul-priv-op.o obj-y += hypercall.o obj-y += iret.o obj-y += misc-hypercalls.o +obj-y += mm.o obj-y += traps.o obj-bin-y += dom0_build.init.o diff --git a/xen/arch/x86/pv/mm.c b/xen/arch/x86/pv/mm.c new file mode 100644 index 0000000000..aa2ce34145 --- /dev/null +++ b/xen/arch/x86/pv/mm.c @@ -0,0 +1,67 @@ +/****************************************************************************** + * arch/x86/pv/mm.c + * + * Memory management code for PV guests + * + * Copyright (c) 2002-2005 K A Fraser + * Copyright (c) 2004 Christian Limpach + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; If not, see . + */ + +#include + +#include + + +/* Read a PV guest's l1e that maps this virtual address. */ +void pv_get_guest_eff_l1e(unsigned long addr, l1_pgentry_t *eff_l1e) +{ + ASSERT(!paging_mode_translate(current->domain)); + ASSERT(!paging_mode_external(current->domain)); + + if ( unlikely(!__addr_ok(addr)) || + __copy_from_user(eff_l1e, + &__linear_l1_table[l1_linear_offset(addr)], + sizeof(l1_pgentry_t)) ) + *eff_l1e = l1e_empty(); +} + +/* + * Read the guest's l1e that maps this address, from the kernel-mode + * page tables. + */ +void pv_get_guest_eff_kern_l1e(struct vcpu *v, unsigned long addr, + void *eff_l1e) +{ + const bool user_mode = !(v->arch.flags & TF_kernel_mode); + + if ( user_mode ) + toggle_guest_mode(v); + + pv_get_guest_eff_l1e(addr, eff_l1e); + + if ( user_mode ) + toggle_guest_mode(v); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/asm-x86/pv/mm.h b/xen/include/asm-x86/pv/mm.h new file mode 100644 index 0000000000..19dbc3b66c --- /dev/null +++ b/xen/include/asm-x86/pv/mm.h @@ -0,0 +1,53 @@ +/* + * asm-x86/pv/mm.h + * + * Memory management interfaces for PV guests + * + * Copyright (C) 2017 Wei Liu + * + * This program is free software; you can redistribute it and/or + * modify it under the terms and conditions of the GNU General Public + * License, version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; If not, see . + */ + +#ifndef __X86_PV_MM_H__ +#define __X86_PV_MM_H__ + +#ifdef CONFIG_PV + +void pv_get_guest_eff_l1e(unsigned long addr, l1_pgentry_t *eff_l1e); + +void pv_get_guest_eff_kern_l1e(struct vcpu *v, unsigned long addr, + void *eff_l1e); + +#else + +static inline void pv_get_guest_eff_l1e(unsigned long addr, + l1_pgentry_t *eff_l1e) +{} + +static inline void pv_get_guest_eff_kern_l1e(struct vcpu *v, unsigned long addr, + void *eff_l1e) +{} + +#endif + +#endif /* __X86_PV_MM_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */