From patchwork Thu May 9 13:42:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 10937171 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AB4A1912 for ; Thu, 9 May 2019 13:43:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9149228B0D for ; Thu, 9 May 2019 13:43:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 855E828B14; Thu, 9 May 2019 13:43:50 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 20D8328B0D for ; Thu, 9 May 2019 13:43:50 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hOjJV-00063N-Bd; Thu, 09 May 2019 13:42:21 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hOjJU-00063H-GO for xen-devel@lists.xenproject.org; Thu, 09 May 2019 13:42:20 +0000 X-Inumbo-ID: 423b4ce6-7260-11e9-830c-830beb5e8ab4 Received: from prv1-mh.provo.novell.com (unknown [137.65.248.33]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 423b4ce6-7260-11e9-830c-830beb5e8ab4; Thu, 09 May 2019 13:42:17 +0000 (UTC) Received: from INET-PRV1-MTA by prv1-mh.provo.novell.com with Novell_GroupWise; Thu, 09 May 2019 07:42:16 -0600 Message-Id: <5CD42E37020000780022D32F@prv1-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 18.1.0 Date: Thu, 09 May 2019 07:42:15 -0600 From: "Jan Beulich" To: "xen-devel" References: <5CD42DCB020000780022D317@prv1-mh.provo.novell.com> In-Reply-To: <5CD42DCB020000780022D317@prv1-mh.provo.novell.com> Mime-Version: 1.0 Content-Disposition: inline Subject: [Xen-devel] [PATCH v2 1/3] x86/mm: short-circuit HVM-only mode flags when !HVM X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: George Dunlap , Andrew Cooper , Wei Liu , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP #define-ing them to zero allows better code generation in this case, and paves the way for more DCE, allowing to leave certain functions just declared, but not defined. Signed-off-by: Jan Beulich Reviewed-by: Wei Liu Reviewed-by: George Dunlap --- v2: New. --- a/xen/arch/x86/mm/paging.c +++ b/xen/arch/x86/mm/paging.c @@ -837,7 +837,9 @@ int paging_enable(struct domain *d, u32 switch ( mode & (PG_external | PG_translate | PG_refcounts) ) { case 0: +#if PG_external | PG_translate | PG_refcounts case PG_external | PG_translate | PG_refcounts: +#endif break; default: return -EINVAL; --- a/xen/include/asm-x86/paging.h +++ b/xen/include/asm-x86/paging.h @@ -46,19 +46,29 @@ #define PG_SH_enable 0 #define PG_SH_forced 0 #endif +#ifdef CONFIG_HVM #define PG_HAP_enable (1U << PG_HAP_shift) +#else +#define PG_HAP_enable 0 +#endif /* common paging mode bits */ #define PG_mode_shift 10 +#ifdef CONFIG_HVM /* Refcounts based on shadow tables instead of guest tables */ #define PG_refcounts (XEN_DOMCTL_SHADOW_ENABLE_REFCOUNT << PG_mode_shift) -/* Enable log dirty mode */ -#define PG_log_dirty (XEN_DOMCTL_SHADOW_ENABLE_LOG_DIRTY << PG_mode_shift) /* Xen does p2m translation, not guest */ #define PG_translate (XEN_DOMCTL_SHADOW_ENABLE_TRANSLATE << PG_mode_shift) /* Xen does not steal address space from the domain for its own booking; * requires VT or similar mechanisms */ #define PG_external (XEN_DOMCTL_SHADOW_ENABLE_EXTERNAL << PG_mode_shift) +#else +#define PG_refcounts 0 +#define PG_translate 0 +#define PG_external 0 +#endif +/* Enable log dirty mode */ +#define PG_log_dirty (XEN_DOMCTL_SHADOW_ENABLE_LOG_DIRTY << PG_mode_shift) /* All paging modes. */ #define PG_MASK (PG_refcounts | PG_log_dirty | PG_translate | PG_external) From patchwork Thu May 9 13:44:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 10937173 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A1F776 for ; Thu, 9 May 2019 13:46:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55E8728B12 for ; Thu, 9 May 2019 13:46:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48C5D28B15; Thu, 9 May 2019 13:46:25 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A6E8228B12 for ; Thu, 9 May 2019 13:46:24 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hOjLa-0006IZ-4F; Thu, 09 May 2019 13:44:30 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hOjLY-0006IT-Jf for xen-devel@lists.xenproject.org; Thu, 09 May 2019 13:44:28 +0000 X-Inumbo-ID: 8fe1173f-7260-11e9-8980-bc764e045a96 Received: from prv1-mh.provo.novell.com (unknown [137.65.248.33]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 8fe1173f-7260-11e9-8980-bc764e045a96; Thu, 09 May 2019 13:44:27 +0000 (UTC) Received: from INET-PRV1-MTA by prv1-mh.provo.novell.com with Novell_GroupWise; Thu, 09 May 2019 07:44:26 -0600 Message-Id: <5CD42EB9020000780022D332@prv1-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 18.1.0 Date: Thu, 09 May 2019 07:44:25 -0600 From: "Jan Beulich" To: "xen-devel" References: <5CD42DCB020000780022D317@prv1-mh.provo.novell.com> In-Reply-To: <5CD42DCB020000780022D317@prv1-mh.provo.novell.com> Mime-Version: 1.0 Content-Disposition: inline Subject: [Xen-devel] [PATCH v2 2/3] x86/mm: make guest_physmap_add_entry() HVM-only X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: George Dunlap , Andrew Cooper , Wei Liu , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Lift its !paging_mode_translate() part into guest_physmap_add_page() (which is what common code calls), eliminating the dummy use of a (HVM-only really) P2M type in the PV case. Suggested-by: George Dunlap Signed-off-by: Jan Beulich Reviewed-by: Wei Liu Reviewed-by: George Dunlap --- v2: New. --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -813,22 +813,14 @@ guest_physmap_remove_page(struct domain } int -guest_physmap_add_entry(struct domain *d, gfn_t gfn, mfn_t mfn, - unsigned int page_order, p2m_type_t t) +guest_physmap_add_page(struct domain *d, gfn_t gfn, mfn_t mfn, + unsigned int page_order) { - struct p2m_domain *p2m = p2m_get_hostp2m(d); - unsigned long i; - gfn_t ogfn; - p2m_type_t ot; - p2m_access_t a; - mfn_t omfn; - int pod_count = 0; - int rc = 0; - /* IOMMU for PV guests is handled in get_page_type() and put_page(). */ if ( !paging_mode_translate(d) ) { struct page_info *page = mfn_to_page(mfn); + unsigned long i; /* * Our interface for PV guests wrt IOMMU entries hasn't been very @@ -841,7 +833,7 @@ guest_physmap_add_entry(struct domain *d * any guest-requested type changes succeed and remove the IOMMU * entry). */ - if ( !need_iommu_pt_sync(d) || t != p2m_ram_rw ) + if ( !need_iommu_pt_sync(d) ) return 0; for ( i = 0; i < (1UL << page_order); ++i, ++page ) @@ -855,6 +847,29 @@ guest_physmap_add_entry(struct domain *d return 0; } + return guest_physmap_add_entry(d, gfn, mfn, page_order, p2m_ram_rw); +} + +#ifdef CONFIG_HVM +int +guest_physmap_add_entry(struct domain *d, gfn_t gfn, mfn_t mfn, + unsigned int page_order, p2m_type_t t) +{ + struct p2m_domain *p2m = p2m_get_hostp2m(d); + unsigned long i; + gfn_t ogfn; + p2m_type_t ot; + p2m_access_t a; + mfn_t omfn; + int pod_count = 0; + int rc = 0; + + if ( !paging_mode_translate(d) ) + { + ASSERT_UNREACHABLE(); + return -EPERM; + } + /* foreign pages are added thru p2m_add_foreign */ if ( p2m_is_foreign(t) ) return -EINVAL; @@ -978,7 +993,6 @@ guest_physmap_add_entry(struct domain *d gfn_x(gfn), mfn_x(mfn)); rc = p2m_set_entry(p2m, gfn, INVALID_MFN, page_order, p2m_invalid, p2m->default_access); -#ifdef CONFIG_HVM if ( rc == 0 ) { pod_lock(p2m); @@ -986,7 +1000,6 @@ guest_physmap_add_entry(struct domain *d BUG_ON(p2m->pod.entry_count < 0); pod_unlock(p2m); } -#endif } out: @@ -994,7 +1007,7 @@ out: return rc; } - +#endif /* * Modify the p2m type of a single gfn from ot to nt. --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -587,14 +587,9 @@ int guest_physmap_add_entry(struct domai mfn_t mfn, unsigned int page_order, p2m_type_t t); -/* Untyped version for RAM only, for compatibility */ -static inline int guest_physmap_add_page(struct domain *d, - gfn_t gfn, - mfn_t mfn, - unsigned int page_order) -{ - return guest_physmap_add_entry(d, gfn, mfn, page_order, p2m_ram_rw); -} +/* Untyped version for RAM only, for compatibility and PV. */ +int guest_physmap_add_page(struct domain *d, gfn_t gfn, mfn_t mfn, + unsigned int page_order); /* Set a p2m range as populate-on-demand */ int guest_physmap_mark_populate_on_demand(struct domain *d, unsigned long gfn, From patchwork Thu May 9 13:45:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 10937175 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8523976 for ; Thu, 9 May 2019 13:47:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F53C28B12 for ; Thu, 9 May 2019 13:47:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6076B28B15; Thu, 9 May 2019 13:47:06 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EF4C128B12 for ; Thu, 9 May 2019 13:47:05 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hOjMk-0006Oq-Fb; Thu, 09 May 2019 13:45:42 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hOjMk-0006Ok-3O for xen-devel@lists.xenproject.org; Thu, 09 May 2019 13:45:42 +0000 X-Inumbo-ID: ba397754-7260-11e9-9740-0f0c7ea2df55 Received: from prv1-mh.provo.novell.com (unknown [137.65.248.33]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id ba397754-7260-11e9-9740-0f0c7ea2df55; Thu, 09 May 2019 13:45:38 +0000 (UTC) Received: from INET-PRV1-MTA by prv1-mh.provo.novell.com with Novell_GroupWise; Thu, 09 May 2019 07:45:37 -0600 Message-Id: <5CD42EFC020000780022D335@prv1-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 18.1.0 Date: Thu, 09 May 2019 07:45:32 -0600 From: "Jan Beulich" To: "xen-devel" References: <5CD42DCB020000780022D317@prv1-mh.provo.novell.com> In-Reply-To: <5CD42DCB020000780022D317@prv1-mh.provo.novell.com> Mime-Version: 1.0 Content-Disposition: inline Subject: [Xen-devel] [PATCH v2 3/3] x86/mm: subsume set_gpfn_from_mfn() into guest_physmap_add_page() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP The two callers in common/memory.c currently call set_gpfn_from_mfn() themselves, so moving the call into guest_physmap_add_page() helps tidy their code. The two callers in common/grant_table.c fail to make that call alongside the one to guest_physmap_add_page(), so will actually get fixed by the change. Other (x86) callers are HVM only and are hence unaffected by a change to the function's !paging_mode_translate() part. Sadly this isn't enough yet to drop Arm's dummy macro, as there's one more use in page_alloc.c. Signed-off-by: Jan Beulich Acked-by: Julien Grall Reviewed-by: George Dunlap --- v2: Re-base over added earlier patch. Re-write description. --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -833,15 +833,16 @@ guest_physmap_add_page(struct domain *d, * any guest-requested type changes succeed and remove the IOMMU * entry). */ - if ( !need_iommu_pt_sync(d) ) - return 0; - for ( i = 0; i < (1UL << page_order); ++i, ++page ) { - if ( get_page_and_type(page, d, PGT_writable_page) ) + if ( !need_iommu_pt_sync(d) ) + /* nothing */; + else if ( get_page_and_type(page, d, PGT_writable_page) ) put_page_and_type(page); else return -EINVAL; + + set_gpfn_from_mfn(mfn_x(mfn) + i, gfn_x(gfn) + i); } return 0; --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -270,16 +270,10 @@ static void populate_physmap(struct memo guest_physmap_add_page(d, _gfn(gpfn), mfn, a->extent_order); - if ( !paging_mode_translate(d) ) - { - for ( j = 0; j < (1U << a->extent_order); j++ ) - set_gpfn_from_mfn(mfn_x(mfn_add(mfn, j)), gpfn + j); - - /* Inform the domain of the new page's machine address. */ - if ( unlikely(__copy_mfn_to_guest_offset(a->extent_list, i, - mfn)) ) - goto out; - } + if ( !paging_mode_translate(d) && + /* Inform the domain of the new page's machine address. */ + unlikely(__copy_mfn_to_guest_offset(a->extent_list, i, mfn)) ) + goto out; } } @@ -755,15 +749,11 @@ static long memory_exchange(XEN_GUEST_HA guest_physmap_add_page(d, _gfn(gpfn), mfn, exch.out.extent_order); - if ( !paging_mode_translate(d) ) - { - for ( k = 0; k < (1UL << exch.out.extent_order); k++ ) - set_gpfn_from_mfn(mfn_x(mfn_add(mfn, k)), gpfn + k); - if ( __copy_mfn_to_guest_offset(exch.out.extent_start, - (i << out_chunk_order) + j, - mfn) ) - rc = -EFAULT; - } + if ( !paging_mode_translate(d) && + __copy_mfn_to_guest_offset(exch.out.extent_start, + (i << out_chunk_order) + j, + mfn) ) + rc = -EFAULT; } BUG_ON( !(d->is_dying) && (j != (1UL << out_chunk_order)) );