From patchwork Thu Sep 14 12:58:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9953011 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 D4E6C602C9 for ; Thu, 14 Sep 2017 13:01:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A19BF290D4 for ; Thu, 14 Sep 2017 13:01:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 95BC7290D7; Thu, 14 Sep 2017 13:01:37 +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 07C13290BB for ; Thu, 14 Sep 2017 13:01:37 +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 1dsTjR-0004KZ-8X; Thu, 14 Sep 2017 12:59:01 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dsTjP-0004Jn-OL for xen-devel@lists.xenproject.org; Thu, 14 Sep 2017 12:58:59 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id 8B/E3-03093-21D7AB95; Thu, 14 Sep 2017 12:58:58 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprBIsWRWlGSWpSXmKPExsXitHRDpK5Q7a5 Ig7uzJC2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oybS64xFxxRqXh+5gZTA+M52S5GTg4JAX+J 11t/M4HYbALKEj87e9lAbBEBPYmmA88Zuxi5OJgF5jBKTJ3bxQiSEBawl2ib/ROsgUVAVeJ17 wOwOK+AhcS2+xPZIIbKS+xqu8gKYnMKWEp0fXgJVi8EVNN7aT87hK0g0TH9GBNEr6DEyZlPWE BsZgEJiYMvXjBPYOSdhSQ1C0lqASPTKkaN4tSistQiXSNjvaSizPSMktzEzBxdQwMzvdzU4uL E9NScxKRiveT83E2MwPBhAIIdjH/mBx5ilORgUhLl3au7M1KILyk/pTIjsTgjvqg0J7X4EKMM B4eSBG9Z9a5IIcGi1PTUirTMHGAgw6QlOHiURHgvg6R5iwsSc4sz0yFSpxiNOQ5MuPKHiaPj5 t0/TEIsefl5qVLivDdASgVASjNK8+AGwSLsEqOslDAvI9BpQjwFqUW5mSWo8q8YxTkYlYR594 NM4cnMK4Hb9wroFCagU86c3gFySkkiQkqqgbFvx8x49kC9B0+u6fZ17b37gaXw76E5N+ITfuX 2Gv6azGb18Y/rwo2RafyuyasZ2Ld+PLF8FvPUXdbPfz7p0Pgy7Yt23V3LuJ3iPJOXStV6b6xY r9yh/GxOjIeZZwtbsP7M1+ucGJdwbHmeJVounx4VVuajNzfcQsr/0jyuqr2LGQ53OTt/XajEU pyRaKjFXFScCACzozHPqwIAAA== X-Env-Sender: prvs=423b67c62=wei.liu2@citrix.com X-Msg-Ref: server-14.tower-21.messagelabs.com!1505393936!76188754!1 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 1776 invoked from network); 14 Sep 2017 12:58:58 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-14.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 14 Sep 2017 12:58:58 -0000 X-IronPort-AV: E=Sophos;i="5.42,393,1500940800"; d="scan'208";a="439751161" From: Wei Liu To: Xen-devel Date: Thu, 14 Sep 2017 13:58:36 +0100 Message-ID: <20170914125852.22129-8-wei.liu2@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170914125852.22129-1-wei.liu2@citrix.com> References: <20170914125852.22129-1-wei.liu2@citrix.com> MIME-Version: 1.0 Cc: George Dunlap , Andrew Cooper , Wei Liu , Jan Beulich Subject: [Xen-devel] [PATCH v5 07/23] x86/mm: move map_guest_l1e to pv/mm.c 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 And export the function via pv/mm.h. Signed-off-by: Wei Liu Acked-by: Jan Beulich --- xen/arch/x86/mm.c | 29 -------------------- xen/arch/x86/pv/Makefile | 1 + xen/arch/x86/pv/mm.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/pv/mm.h | 2 ++ 4 files changed, 72 insertions(+), 29 deletions(-) create mode 100644 xen/arch/x86/pv/mm.c diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index e77abb015b..29d8e18819 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -526,35 +526,6 @@ void update_cr3(struct vcpu *v) make_cr3(v, cr3_mfn); } -/* - * Get a mapping of a PV guest's l1e for this linear address. The return - * pointer should be unmapped using unmap_domain_page(). - */ -static l1_pgentry_t *map_guest_l1e(unsigned long linear, mfn_t *gl1mfn) -{ - l2_pgentry_t l2e; - - ASSERT(!paging_mode_translate(current->domain)); - ASSERT(!paging_mode_external(current->domain)); - - if ( unlikely(!__addr_ok(linear)) ) - return NULL; - - /* Find this l1e and its enclosing l1mfn in the linear map. */ - if ( __copy_from_user(&l2e, - &__linear_l2_table[l2_linear_offset(linear)], - sizeof(l2_pgentry_t)) ) - return NULL; - - /* Check flags that it will be safe to read the l1e. */ - if ( (l2e_get_flags(l2e) & (_PAGE_PRESENT | _PAGE_PSE)) != _PAGE_PRESENT ) - return NULL; - - *gl1mfn = l2e_get_mfn(l2e); - - return (l1_pgentry_t *)map_domain_page(*gl1mfn) + l1_table_offset(linear); -} - /* * Read the guest's l1e that maps this address, from the kernel-mode * page tables. diff --git a/xen/arch/x86/pv/Makefile b/xen/arch/x86/pv/Makefile index 24af0b550e..d4fcc2ab94 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 += ro-page-fault.o obj-y += traps.o diff --git a/xen/arch/x86/pv/mm.c b/xen/arch/x86/pv/mm.c new file mode 100644 index 0000000000..4bfa322788 --- /dev/null +++ b/xen/arch/x86/pv/mm.c @@ -0,0 +1,69 @@ +/* + * pv/mm.c + * + * Memory managment 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 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 . + */ + +#include + +#include + +/* Override macros from asm/page.h to make them work with mfn_t */ +#undef mfn_to_page +#define mfn_to_page(mfn) __mfn_to_page(mfn_x(mfn)) +#undef page_to_mfn +#define page_to_mfn(pg) _mfn(__page_to_mfn(pg)) + +/* + * Get a mapping of a PV guest's l1e for this linear address. The return + * pointer should be unmapped using unmap_domain_page(). + */ +l1_pgentry_t *map_guest_l1e(unsigned long linear, mfn_t *gl1mfn) +{ + l2_pgentry_t l2e; + + ASSERT(!paging_mode_translate(current->domain)); + ASSERT(!paging_mode_external(current->domain)); + + if ( unlikely(!__addr_ok(linear)) ) + return NULL; + + /* Find this l1e and its enclosing l1mfn in the linear map. */ + if ( __copy_from_user(&l2e, + &__linear_l2_table[l2_linear_offset(linear)], + sizeof(l2_pgentry_t)) ) + return NULL; + + /* Check flags that it will be safe to read the l1e. */ + if ( (l2e_get_flags(l2e) & (_PAGE_PRESENT | _PAGE_PSE)) != _PAGE_PRESENT ) + return NULL; + + *gl1mfn = l2e_get_mfn(l2e); + + return (l1_pgentry_t *)map_domain_page(*gl1mfn) + l1_table_offset(linear); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/x86/pv/mm.h b/xen/arch/x86/pv/mm.h index 6602e6ce07..acef061acf 100644 --- a/xen/arch/x86/pv/mm.h +++ b/xen/arch/x86/pv/mm.h @@ -1,6 +1,8 @@ #ifndef __PV_MM_H__ #define __PV_MM_H__ +l1_pgentry_t *map_guest_l1e(unsigned long linear, mfn_t *gl1mfn); + /* Read a PV guest's l1e that maps this linear address. */ static inline l1_pgentry_t guest_get_eff_l1e(unsigned long linear) {