From patchwork Wed Aug 23 15:58:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9917705 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 53AFE60327 for ; Wed, 23 Aug 2017 16:00:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 448962899C for ; Wed, 23 Aug 2017 16:00:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 380C8289DF; Wed, 23 Aug 2017 16:00:40 +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 857902899C for ; Wed, 23 Aug 2017 16:00:39 +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 1dkY34-0000AM-Q8; Wed, 23 Aug 2017 15:58:30 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dkY33-00009o-I8 for xen-devel@lists.xenproject.org; Wed, 23 Aug 2017 15:58:29 +0000 Received: from [193.109.254.147] by server-6.bemta-6.messagelabs.com id 99/F4-03937-426AD995; Wed, 23 Aug 2017 15:58:28 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42JxWrohUldl2dx Ig3U/+Sy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oxzU+4zFWxwrbg63aiB8YZJFyMnh4SAv8Sb T3+YQWw2AWWJn529bCC2iICeRNOB54xdjFwczALbGCWu7lzMApIQFnCS+N6+GKyBRUBV4vOHn ewgNq+AhcTp20vYIIbKS+xqu8gKYnMKWEpsap0GViMEVNNw5QeUrSDRMf0YE0SvoMTJmU/A5j MLSEgcfPGCeQIj7ywkqVlIUgsYmVYxahSnFpWlFukaG+klFWWmZ5TkJmbm6BoamOnlphYXJ6a n5iQmFesl5+duYgQGDwMQ7GA8vS7wEKMkB5OSKK+mztxIIb6k/JTKjMTijPii0pzU4kOMMhwc ShK8C5cA5QSLUtNTK9Iyc4BhDJOW4OBREuGNAknzFhck5hZnpkOkTjEqSonzaoIkBEASGaV5c G2w2LnEKCslzMsIdIgQT0FqUW5mCar8K0ZxDkYlYd4NIFN4MvNK4Ka/AlrMBLR40ok5IItLEh FSUg2M3DwdXILMuR9i7gVc1RR2eX42M1ZfkSf9fO6TQ4+kLtyeVJAgMnvPJI/T25Q0Tzzvilj 2vm3zf7kPSaq7lpqZlU67MUPmuuCMAwXzEh7kPEx++8z9vNtvxbKbpfUnGOfM45nHL6IULu9/ y0vz+K69bslvZh5ZsFIr7dzEONt49ee+HNOXPRJPUWIpzkg01GIuKk4EACt6HQuYAgAA X-Env-Sender: prvs=401f19e66=wei.liu2@citrix.com X-Msg-Ref: server-4.tower-27.messagelabs.com!1503503906!112317802!2 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 17111 invoked from network); 23 Aug 2017 15:58:28 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-4.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 23 Aug 2017 15:58:28 -0000 X-IronPort-AV: E=Sophos;i="5.41,417,1498521600"; d="scan'208";a="436591497" From: Wei Liu To: Xen-devel Date: Wed, 23 Aug 2017 16:58:24 +0100 Message-ID: <20170823155824.11144-3-wei.liu2@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170823155824.11144-1-wei.liu2@citrix.com> References: <20170823155824.11144-1-wei.liu2@citrix.com> MIME-Version: 1.0 Cc: George Dunlap , Tim Deegan , Wei Liu , Jan Beulich , Andrew Cooper Subject: [Xen-devel] [PATCH RFC 2/2] x86/mm: PG_translate implies PG_refcounts 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 After 404595352 ("x86/paging: Enforce PG_external == PG_translate == PG_refcounts"), PG_refcounts and PG_translate always need to be set together. Squash PG_refcounts to simplify code. All calls paging_mode_refcounts are replaced by calls to paging_mode_translate. Signed-off-by: Wei Liu Acked-by: Tim Deegan --- Cc: George Dunlap Cc: Tim Deegan Cc: Jan Beulich Cc: Andrew Cooper --- xen/arch/x86/domain.c | 6 ++---- xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/mm.c | 20 ++++++++++---------- xen/arch/x86/mm/paging.c | 8 +++----- xen/include/asm-x86/paging.h | 5 +---- xen/include/asm-x86/shadow.h | 2 +- 6 files changed, 18 insertions(+), 25 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 9b4b9596d8..bbe545b165 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1017,8 +1017,6 @@ int arch_set_info_guest( if ( !cr3_page ) rc = -EINVAL; - else if ( paging_mode_refcounts(d) ) - /* nothing */; else if ( cr3_page == v->arch.old_guest_table ) { v->arch.old_guest_table = NULL; @@ -1040,7 +1038,7 @@ int arch_set_info_guest( break; case 0: if ( !compat && !VM_ASSIST(d, m2p_strict) && - !paging_mode_refcounts(d) ) + !paging_mode_translate(d) ) fill_ro_mpt(cr3_gfn); break; default: @@ -1061,7 +1059,7 @@ int arch_set_info_guest( if ( !cr3_page ) rc = -EINVAL; - else if ( !paging_mode_refcounts(d) ) + else if ( !paging_mode_translate(d) ) { rc = get_page_type_preemptible(cr3_page, PGT_root_page_table); switch ( rc ) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 6cb903def5..eee0ff422e 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -589,7 +589,7 @@ int hvm_domain_initialise(struct domain *d, unsigned long domcr_flags, hvm_init_cacheattr_region_list(d); - rc = paging_enable(d, PG_refcounts|PG_translate|PG_external); + rc = paging_enable(d, PG_translate|PG_external); if ( rc != 0 ) goto fail0; diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index ed77270586..8adb7b6649 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -1925,7 +1925,7 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e, if ( unlikely(__copy_from_user(&ol1e, pl1e, sizeof(ol1e)) != 0) ) return -EFAULT; - ASSERT(!paging_mode_refcounts(pt_dom)); + ASSERT(!paging_mode_translate(pt_dom)); if ( l1e_get_flags(nl1e) & _PAGE_PRESENT ) { @@ -2257,7 +2257,7 @@ int get_page(struct page_info *page, struct domain *domain) if ( likely(owner == domain) ) return 1; - if ( !paging_mode_refcounts(domain) && !domain->is_dying ) + if ( !paging_mode_translate(domain) && !domain->is_dying ) gprintk(XENLOG_INFO, "Error mfn %"PRI_mfn": rd=%d od=%d caf=%08lx taf=%" PRtype_info "\n", mfn_x(page_to_mfn(page)), domain->domain_id, @@ -2719,7 +2719,7 @@ int vcpu_destroy_pagetables(struct vcpu *v) if ( mfn ) { page = mfn_to_page(_mfn(mfn)); - if ( paging_mode_refcounts(v->domain) ) + if ( paging_mode_translate(v->domain) ) put_page(page); else rc = put_page_and_type_preemptible(page); @@ -2740,7 +2740,7 @@ int vcpu_destroy_pagetables(struct vcpu *v) if ( mfn ) { page = mfn_to_page(_mfn(mfn)); - if ( paging_mode_refcounts(v->domain) ) + if ( paging_mode_translate(v->domain) ) put_page(page); else rc = put_page_and_type_preemptible(page); @@ -2811,7 +2811,7 @@ int new_guest_cr3(unsigned long mfn) return 0; } - rc = paging_mode_refcounts(d) + rc = paging_mode_translate(d) ? (get_page_from_mfn(_mfn(mfn), d) ? 0 : -EINVAL) : get_page_and_type_from_mfn(_mfn(mfn), PGT_root_page_table, d, 0, 1); switch ( rc ) @@ -2829,7 +2829,7 @@ int new_guest_cr3(unsigned long mfn) invalidate_shadow_ldt(curr, 0); - if ( !VM_ASSIST(d, m2p_strict) && !paging_mode_refcounts(d) ) + if ( !VM_ASSIST(d, m2p_strict) && !paging_mode_translate(d) ) fill_ro_mpt(mfn); curr->arch.guest_table = pagetable_from_pfn(mfn); update_cr3(curr); @@ -2840,7 +2840,7 @@ int new_guest_cr3(unsigned long mfn) { struct page_info *page = mfn_to_page(_mfn(old_base_mfn)); - if ( paging_mode_refcounts(d) ) + if ( paging_mode_translate(d) ) put_page(page); else switch ( rc = put_page_and_type_preemptible(page) ) @@ -3059,7 +3059,7 @@ long do_mmuext_op( if ( (op.cmd - MMUEXT_PIN_L1_TABLE) > (CONFIG_PAGING_LEVELS - 1) ) break; - if ( paging_mode_refcounts(pg_owner) ) + if ( paging_mode_translate(pg_owner) ) break; page = get_page_from_gfn(pg_owner, op.arg1.mfn, NULL, P2M_ALLOC); @@ -3121,7 +3121,7 @@ long do_mmuext_op( break; case MMUEXT_UNPIN_TABLE: - if ( paging_mode_refcounts(pg_owner) ) + if ( paging_mode_translate(pg_owner) ) break; page = get_page_from_gfn(pg_owner, op.arg1.mfn, NULL, P2M_ALLOC); @@ -3564,7 +3564,7 @@ long do_mmu_update( p2m_type_t p2mt; rc = -EOPNOTSUPP; - if ( unlikely(paging_mode_refcounts(pt_owner)) ) + if ( unlikely(paging_mode_translate(pt_owner)) ) break; xsm_needed |= XSM_MMU_NORMAL_UPDATE; diff --git a/xen/arch/x86/mm/paging.c b/xen/arch/x86/mm/paging.c index 75f5fc0024..354d96d4cc 100644 --- a/xen/arch/x86/mm/paging.c +++ b/xen/arch/x86/mm/paging.c @@ -839,11 +839,11 @@ int paging_enable(struct domain *d, u32 mode) if ( mode & ~PG_MASK ) return -EINVAL; - /* All of external|translate|refcounts, or none. */ - switch ( mode & (PG_external | PG_translate | PG_refcounts) ) + /* Both of external|translate, or none. */ + switch ( mode & (PG_external | PG_translate) ) { case 0: - case PG_external | PG_translate | PG_refcounts: + case PG_external | PG_translate: break; default: return -EINVAL; @@ -881,8 +881,6 @@ void paging_dump_domain_info(struct domain *d) printk("shadow "); if ( paging_mode_hap(d) ) printk("hap "); - if ( paging_mode_refcounts(d) ) - printk("refcounts "); if ( paging_mode_log_dirty(d) ) printk("log_dirty "); if ( paging_mode_translate(d) ) diff --git a/xen/include/asm-x86/paging.h b/xen/include/asm-x86/paging.h index 64bf2f968a..496a80a1ad 100644 --- a/xen/include/asm-x86/paging.h +++ b/xen/include/asm-x86/paging.h @@ -47,8 +47,6 @@ /* common paging mode bits */ #define PG_mode_shift 10 -/* 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 */ @@ -58,13 +56,12 @@ #define PG_external (XEN_DOMCTL_SHADOW_ENABLE_EXTERNAL << PG_mode_shift) /* All paging modes. */ -#define PG_MASK (PG_refcounts | PG_log_dirty | PG_translate | PG_external) +#define PG_MASK (PG_log_dirty | PG_translate | PG_external) #define paging_mode_enabled(_d) (!!(_d)->arch.paging.mode) #define paging_mode_shadow(_d) (!!((_d)->arch.paging.mode & PG_SH_enable)) #define paging_mode_hap(_d) (!!((_d)->arch.paging.mode & PG_HAP_enable)) -#define paging_mode_refcounts(_d) (!!((_d)->arch.paging.mode & PG_refcounts)) #define paging_mode_log_dirty(_d) (!!((_d)->arch.paging.mode & PG_log_dirty)) #define paging_mode_translate(_d) (!!((_d)->arch.paging.mode & PG_translate)) #define paging_mode_external(_d) (!!((_d)->arch.paging.mode & PG_external)) diff --git a/xen/include/asm-x86/shadow.h b/xen/include/asm-x86/shadow.h index 678b5d48bb..e0607b9620 100644 --- a/xen/include/asm-x86/shadow.h +++ b/xen/include/asm-x86/shadow.h @@ -35,7 +35,7 @@ #define shadow_mode_enabled(_d) paging_mode_shadow(_d) #define shadow_mode_refcounts(_d) (paging_mode_shadow(_d) && \ - paging_mode_refcounts(_d)) + paging_mode_translate(_d)) #define shadow_mode_log_dirty(_d) (paging_mode_shadow(_d) && \ paging_mode_log_dirty(_d)) #define shadow_mode_translate(_d) (paging_mode_shadow(_d) && \