From patchwork Wed Jun 21 10:25:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 9801457 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 57CF160329 for ; Wed, 21 Jun 2017 10:28:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E6A42858E for ; Wed, 21 Jun 2017 10:27:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6322628593; Wed, 21 Jun 2017 10:27:57 +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 E99102858E for ; Wed, 21 Jun 2017 10:27:56 +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 1dNcp7-0005wP-2w; Wed, 21 Jun 2017 10:25:21 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dNcp5-0005wG-Gi for xen-devel@lists.xenproject.org; Wed, 21 Jun 2017 10:25:19 +0000 Received: from [85.158.143.35] by server-4.bemta-6.messagelabs.com id 30/B7-02956-E894A495; Wed, 21 Jun 2017 10:25:18 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrNIsWRWlGSWpSXmKPExsXS6fjDS7fX0yv S4H+DrcX3LZOZHBg9Dn+4whLAGMWamZeUX5HAmrFqWTtbwUaDiolftrI0MB5V6WLk5BASyJP4 9m0LC4jNK2An0XnyNZgtIWAocXrhTTCbRUBVov/fbjYQm01AXaLt2XbWLkYODhEBA4lzR5NAT GaBeImr6+xBTGEBc4kN/a4Qw4skzpzbBjaEU8BeYsfvt8wgJbwCghJ/dwiDhJmBdl4//Ix1Ai PPLITMLCQZCFtL4uGvWywQtrbEsoWvmWeBrZWWWP6PAyJsJXHr+Ck2VCUgtqtEy9OrTAsYOVY xahSnFpWlFukaWuolFWWmZ5TkJmbm6BoamOnlphYXJ6an5iQmFesl5+duYgQGKgMQ7GD8sSzg EKMkB5OSKO8FWa9IIb6k/JTKjMTijPii0pzU4kOMMhwcShK8Lh5AOcGi1PTUirTMHGDMwKQlO HiURHjXuAKleYsLEnOLM9MhUqcYFaXEeUNA+gRAEhmleXBtsDi9xCgrJczLCHSIEE9BalFuZg mq/CtGcQ5GJWHe0yBTeDLzSuCmvwJazAS0+MURD5DFJYkIKakGxoVHDqUKyHx/NXNFy7w7mR5 79+/uz/v5ycdeOZPrRs9/9ePOPZqXd8fKL6+plE3fd9M96seiWcma3+zeCfboL3wa+Cj3pYDR lE+lQXMkHf2CuQ8XFsT9uaiy9fmTGTwbt3PwVLVMikuLT02R/zfhbvDX01sWG0a5b3Pp2BC8M /aZ2/Iy/0/mH5RYijMSDbWYi4oTAWP0gFPOAgAA X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-13.tower-21.messagelabs.com!1498040716!69068694!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 65126 invoked from network); 21 Jun 2017 10:25:17 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-13.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 21 Jun 2017 10:25:17 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Wed, 21 Jun 2017 04:25:15 -0600 Message-Id: <594A65AB02000078001651EE@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.2 Date: Wed, 21 Jun 2017 04:25:15 -0600 From: "Jan Beulich" To: "xen-devel" References: <594A63F602000078001651C6@prv-mh.provo.novell.com> <594A63F602000078001651C6@prv-mh.provo.novell.com> In-Reply-To: <594A63F602000078001651C6@prv-mh.provo.novell.com> Mime-Version: 1.0 Cc: George Dunlap , Andrew Cooper Subject: [Xen-devel] [PATCH 1/2] x86/p2m: simplify p2m_next_level() 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 Calculate entry PFN and flags just once, making the respective variables (and also pg) function wide. Take the opportunity and also make the induction variable unsigned. Signed-off-by: Jan Beulich x86/p2m-pt: simplify p2m_next_level() Calculate entry PFN and flags just once, making the respective variables (and also pg) function wide. Take the opportunity and also make the induction variable unsigned. Signed-off-by: Jan Beulich --- a/xen/arch/x86/mm/p2m-pt.c +++ b/xen/arch/x86/mm/p2m-pt.c @@ -195,7 +195,9 @@ p2m_next_level(struct p2m_domain *p2m, v l1_pgentry_t *p2m_entry; l1_pgentry_t new_entry; void *next; - int i; + struct page_info *pg; + unsigned int i, flags; + unsigned long pfn; if ( !(p2m_entry = p2m_find_entry(*table, gfn_remainder, gfn, shift, max)) ) @@ -204,8 +206,6 @@ p2m_next_level(struct p2m_domain *p2m, v /* PoD/paging: Not present doesn't imply empty. */ if ( !l1e_get_flags(*p2m_entry) ) { - struct page_info *pg; - pg = p2m_alloc_ptp(p2m, type); if ( pg == NULL ) return -ENOMEM; @@ -232,21 +232,17 @@ p2m_next_level(struct p2m_domain *p2m, v } } - ASSERT(l1e_get_flags(*p2m_entry) & (_PAGE_PRESENT|_PAGE_PSE)); + flags = l1e_get_flags(*p2m_entry); + pfn = l1e_get_pfn(*p2m_entry); + ASSERT(flags & (_PAGE_PRESENT|_PAGE_PSE)); /* split 1GB pages into 2MB pages */ - if ( type == PGT_l2_page_table && (l1e_get_flags(*p2m_entry) & _PAGE_PSE) ) + if ( type == PGT_l2_page_table && (flags & _PAGE_PSE) ) { - unsigned long flags, pfn; - struct page_info *pg; - pg = p2m_alloc_ptp(p2m, PGT_l2_page_table); if ( pg == NULL ) return -ENOMEM; - flags = l1e_get_flags(*p2m_entry); - pfn = l1e_get_pfn(*p2m_entry); - l1_entry = __map_domain_page(pg); for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ ) { @@ -263,19 +259,14 @@ p2m_next_level(struct p2m_domain *p2m, v /* split single 2MB large page into 4KB page in P2M table */ - if ( type == PGT_l1_page_table && (l1e_get_flags(*p2m_entry) & _PAGE_PSE) ) + if ( type == PGT_l1_page_table && (flags & _PAGE_PSE) ) { - unsigned long flags, pfn; - struct page_info *pg; - pg = p2m_alloc_ptp(p2m, PGT_l1_page_table); if ( pg == NULL ) return -ENOMEM; /* New splintered mappings inherit the flags of the old superpage, * with a little reorganisation for the _PAGE_PSE_PAT bit. */ - flags = l1e_get_flags(*p2m_entry); - pfn = l1e_get_pfn(*p2m_entry); if ( pfn & 1 ) /* ==> _PAGE_PSE_PAT was set */ pfn -= 1; /* Clear it; _PAGE_PSE becomes _PAGE_PAT */ else --- a/xen/arch/x86/mm/p2m-pt.c +++ b/xen/arch/x86/mm/p2m-pt.c @@ -195,7 +195,9 @@ p2m_next_level(struct p2m_domain *p2m, v l1_pgentry_t *p2m_entry; l1_pgentry_t new_entry; void *next; - int i; + struct page_info *pg; + unsigned int i, flags; + unsigned long pfn; if ( !(p2m_entry = p2m_find_entry(*table, gfn_remainder, gfn, shift, max)) ) @@ -204,8 +206,6 @@ p2m_next_level(struct p2m_domain *p2m, v /* PoD/paging: Not present doesn't imply empty. */ if ( !l1e_get_flags(*p2m_entry) ) { - struct page_info *pg; - pg = p2m_alloc_ptp(p2m, type); if ( pg == NULL ) return -ENOMEM; @@ -232,21 +232,17 @@ p2m_next_level(struct p2m_domain *p2m, v } } - ASSERT(l1e_get_flags(*p2m_entry) & (_PAGE_PRESENT|_PAGE_PSE)); + flags = l1e_get_flags(*p2m_entry); + pfn = l1e_get_pfn(*p2m_entry); + ASSERT(flags & (_PAGE_PRESENT|_PAGE_PSE)); /* split 1GB pages into 2MB pages */ - if ( type == PGT_l2_page_table && (l1e_get_flags(*p2m_entry) & _PAGE_PSE) ) + if ( type == PGT_l2_page_table && (flags & _PAGE_PSE) ) { - unsigned long flags, pfn; - struct page_info *pg; - pg = p2m_alloc_ptp(p2m, PGT_l2_page_table); if ( pg == NULL ) return -ENOMEM; - flags = l1e_get_flags(*p2m_entry); - pfn = l1e_get_pfn(*p2m_entry); - l1_entry = __map_domain_page(pg); for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ ) { @@ -263,19 +259,14 @@ p2m_next_level(struct p2m_domain *p2m, v /* split single 2MB large page into 4KB page in P2M table */ - if ( type == PGT_l1_page_table && (l1e_get_flags(*p2m_entry) & _PAGE_PSE) ) + if ( type == PGT_l1_page_table && (flags & _PAGE_PSE) ) { - unsigned long flags, pfn; - struct page_info *pg; - pg = p2m_alloc_ptp(p2m, PGT_l1_page_table); if ( pg == NULL ) return -ENOMEM; /* New splintered mappings inherit the flags of the old superpage, * with a little reorganisation for the _PAGE_PSE_PAT bit. */ - flags = l1e_get_flags(*p2m_entry); - pfn = l1e_get_pfn(*p2m_entry); if ( pfn & 1 ) /* ==> _PAGE_PSE_PAT was set */ pfn -= 1; /* Clear it; _PAGE_PSE becomes _PAGE_PAT */ else