From patchwork Sun Jul 30 15:43:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9870539 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 3D7B8603B4 for ; Sun, 30 Jul 2017 15:46:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EDAD2856D for ; Sun, 30 Jul 2017 15:46:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 23A1128599; Sun, 30 Jul 2017 15:46:30 +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 9A5642859F for ; Sun, 30 Jul 2017 15:46:29 +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-0006Lp-2L; Sun, 30 Jul 2017 15:43:44 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dbqNa-0006LF-7Z for xen-devel@lists.xenproject.org; Sun, 30 Jul 2017 15:43:42 +0000 Received: from [193.109.254.147] by server-6.bemta-6.messagelabs.com id 59/46-03937-DAEFD795; Sun, 30 Jul 2017 15:43:41 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprAIsWRWlGSWpSXmKPExsXitHRDpO6af7W RBouX6Vp83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBkLXn1nLOjRqLi3+wtzA+M8+S5GDg4JAX+J Jz9Euhg5OdgElCV+dvaygdgiAnoSTQeeM3YxcnEwC8xhlJg6t4sRJCEsECXR1neDEaSXRUBV4 uaSWJAwr4CFxIKDi8B6JQTkJXa1XWQFsTkFLCU2LeliArGFBFIlzhxbwQ5hK0h0TD/GBNErKH Fy5hMWEJtZQELi4IsXzBMYeWchSc1CklrAyLSKUaM4tagstUjX2FAvqSgzPaMkNzEzR9fQwEw vN7W4ODE9NScxqVgvOT93EyMwdBiAYAdj06LAQ4ySHExKorzruGsjhfiS8lMqMxKLM+KLSnNS iw8xynBwKEnwFv4FygkWpaanVqRl5gCDGCYtwcGjJMI7DSTNW1yQmFucmQ6ROsWoy/Fqwv9vT EIsefl5qVLivA0gRQIgRRmleXAjYBF1iVFWSpiXEegoIZ6C1KLczBJU+VeM4hyMSsK8ySBTeD LzSuA2vQI6ggnoCMlSsCNKEhFSUg2M/awsJ7cVxXJ/NOieycx0O272ibKrXFOMdr22PFX3qbk kMKk4/ZWNpOWsG43iJQtz2sr4OuxEe60fq8Y1zDvmvIKpo9M68l+qlfF86w0BvTOrj64xnbc/ MMFo55nHiUWbzN6FzLx1eYt6zf/lqvzRK493Tj5z8WBAcefaO7wGTvONVkbMiL+txFKckWiox VxUnAgAi3wlB6MCAAA= X-Env-Sender: prvs=37723ee83=wei.liu2@citrix.com X-Msg-Ref: server-3.tower-27.messagelabs.com!1501429419!109213908!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.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 17555 invoked from network); 30 Jul 2017 15:43:40 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-3.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 30 Jul 2017 15:43:40 -0000 X-IronPort-AV: E=Sophos;i="5.40,437,1496102400"; d="scan'208";a="433622810" From: Wei Liu To: Xen-devel Date: Sun, 30 Jul 2017 16:43:27 +0100 Message-ID: <20170730154335.24313-4-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 03/11] x86/mm: move and add pv_ prefix to create_pae_xen_mappings 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 it via a local header because it is going to be used by several PV specific files. Take the chance to change its return type to bool. Signed-off-by: Wei Liu --- xen/arch/x86/mm.c | 46 ++++------------------------------------------ xen/arch/x86/pv/mm.c | 40 ++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/pv/mm.h | 6 ++++++ 3 files changed, 50 insertions(+), 42 deletions(-) create mode 100644 xen/arch/x86/pv/mm.h diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 40f9ad9c98..0c6a6de1a9 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -127,6 +127,8 @@ #include #include +#include "pv/mm.h" + /* Mapping of the fixmap space needed early. */ l1_pgentry_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) l1_fixmap[L1_PAGETABLE_ENTRIES]; @@ -1223,46 +1225,6 @@ static int alloc_l1_table(struct page_info *page) return ret; } -static int create_pae_xen_mappings(struct domain *d, l3_pgentry_t *pl3e) -{ - struct page_info *page; - l3_pgentry_t l3e3; - - if ( !is_pv_32bit_domain(d) ) - return 1; - - pl3e = (l3_pgentry_t *)((unsigned long)pl3e & PAGE_MASK); - - /* 3rd L3 slot contains L2 with Xen-private mappings. It *must* exist. */ - l3e3 = pl3e[3]; - if ( !(l3e_get_flags(l3e3) & _PAGE_PRESENT) ) - { - gdprintk(XENLOG_WARNING, "PAE L3 3rd slot is empty\n"); - return 0; - } - - /* - * The Xen-private mappings include linear mappings. The L2 thus cannot - * be shared by multiple L3 tables. The test here is adequate because: - * 1. Cannot appear in slots != 3 because get_page_type() checks the - * PGT_pae_xen_l2 flag, which is asserted iff the L2 appears in slot 3 - * 2. Cannot appear in another page table's L3: - * a. alloc_l3_table() calls this function and this check will fail - * b. mod_l3_entry() disallows updates to slot 3 in an existing table - */ - page = l3e_get_page(l3e3); - BUG_ON(page->u.inuse.type_info & PGT_pinned); - BUG_ON((page->u.inuse.type_info & PGT_count_mask) == 0); - BUG_ON(!(page->u.inuse.type_info & PGT_pae_xen_l2)); - if ( (page->u.inuse.type_info & PGT_count_mask) != 1 ) - { - gdprintk(XENLOG_WARNING, "PAE L3 3rd slot is shared\n"); - return 0; - } - - return 1; -} - static int alloc_l2_table(struct page_info *page, unsigned long type, int preemptible) { @@ -1367,7 +1329,7 @@ static int alloc_l3_table(struct page_info *page) adjust_guest_l3e(pl3e[i], d); } - if ( rc >= 0 && !create_pae_xen_mappings(d, pl3e) ) + if ( rc >= 0 && !pv_create_pae_xen_mappings(d, pl3e) ) rc = -EINVAL; if ( rc < 0 && rc != -ERESTART && rc != -EINTR ) { @@ -1839,7 +1801,7 @@ static int mod_l3_entry(l3_pgentry_t *pl3e, } if ( likely(rc == 0) ) - if ( !create_pae_xen_mappings(d, pl3e) ) + if ( !pv_create_pae_xen_mappings(d, pl3e) ) BUG(); put_page_from_l3e(ol3e, pfn, 0, 1); diff --git a/xen/arch/x86/pv/mm.c b/xen/arch/x86/pv/mm.c index 0f4303cef2..46e1fcf4e5 100644 --- a/xen/arch/x86/pv/mm.c +++ b/xen/arch/x86/pv/mm.c @@ -211,6 +211,46 @@ bool pv_update_intpte(intpte_t *p, intpte_t old, intpte_t new, return rv; } +bool pv_create_pae_xen_mappings(struct domain *d, l3_pgentry_t *pl3e) +{ + struct page_info *page; + l3_pgentry_t l3e3; + + if ( !is_pv_32bit_domain(d) ) + return true; + + pl3e = (l3_pgentry_t *)((unsigned long)pl3e & PAGE_MASK); + + /* 3rd L3 slot contains L2 with Xen-private mappings. It *must* exist. */ + l3e3 = pl3e[3]; + if ( !(l3e_get_flags(l3e3) & _PAGE_PRESENT) ) + { + gdprintk(XENLOG_WARNING, "PAE L3 3rd slot is empty\n"); + return false; + } + + /* + * The Xen-private mappings include linear mappings. The L2 thus cannot + * be shared by multiple L3 tables. The test here is adequate because: + * 1. Cannot appear in slots != 3 because get_page_type() checks the + * PGT_pae_xen_l2 flag, which is asserted iff the L2 appears in slot 3 + * 2. Cannot appear in another page table's L3: + * a. alloc_l3_table() calls this function and this check will fail + * b. mod_l3_entry() disallows updates to slot 3 in an existing table + */ + page = l3e_get_page(l3e3); + BUG_ON(page->u.inuse.type_info & PGT_pinned); + BUG_ON((page->u.inuse.type_info & PGT_count_mask) == 0); + BUG_ON(!(page->u.inuse.type_info & PGT_pae_xen_l2)); + if ( (page->u.inuse.type_info & PGT_count_mask) != 1 ) + { + gdprintk(XENLOG_WARNING, "PAE L3 3rd slot is shared\n"); + return false; + } + + return true; +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/pv/mm.h b/xen/arch/x86/pv/mm.h new file mode 100644 index 0000000000..bafc2b6116 --- /dev/null +++ b/xen/arch/x86/pv/mm.h @@ -0,0 +1,6 @@ +#ifndef __PV_MM_H__ +#define __PV_MM_H__ + +bool pv_create_pae_xen_mappings(struct domain *d, l3_pgentry_t *pl3e); + +#endif /* __PV_MM_H__ */