From nobody Mon Feb 9 07:25:25 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576698146; cv=none; d=zohomail.com; s=zohoarc; b=SCExZ2xSCdnqAjGhZ8fRjg6E0ajYeY5clEDSf92eP15RbcKpGEvlknP1vC+XkT/165YE2Eu5RasNHe7Wzdx0NRJdUezDjlMGYh2i6seqTKopn5LCPT03UzJ7hmVB/0a3cAH+kUSAbEdZ/7MVlT52ViW6wZSjQHP6bJEfNZHJ+80= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576698146; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GDQeWfOioFf963kHqcZEQUoX3YIGnsrTh4DvPe66fpY=; b=LdZz3FgTT4Gdq3ws0o/+rirjLtQhwQK2nAUkXxvXgVBVGzU0RwPiWTYQXpyPG1M5PhXLfiCCBUAMUUqjB/CV7qV+9RMtZSBuOZfh5cNjwbhxAa/9UZWUQM96+eApGn+u8GOB53+MCob4RLYmlFgx4P6K9AT961hPZYj8ouj70WM= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576698146793375.03121183287476; Wed, 18 Dec 2019 11:42:26 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihfCk-0007yk-Lt; Wed, 18 Dec 2019 19:41:54 +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 1ihfCj-0007xS-87 for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 19:41:53 +0000 Received: from mga03.intel.com (unknown [134.134.136.65]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5b028b0e-21ce-11ea-90f3-12813bfff9fa; Wed, 18 Dec 2019 19:41:16 +0000 (UTC) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 11:41:16 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.103.7]) by orsmga008.jf.intel.com with ESMTP; 18 Dec 2019 11:41:15 -0800 X-Inumbo-ID: 5b028b0e-21ce-11ea-90f3-12813bfff9fa X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="210196329" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 11:40:45 -0800 Message-Id: <11fd562f28132f950f4ed60e7a896b07da78f520.1576697796.git.tamas.lengyel@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 08/20] x86/mem_sharing: define mem_sharing_domain to hold some scattered variables 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: Tamas K Lengyel , Tamas K Lengyel , Wei Liu , George Dunlap , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Create struct mem_sharing_domain under hvm_domain and move mem sharing variables into it from p2m_domain and hvm_domain. Expose the mem_sharing_enabled macro to be used consistently across Xen. Remove some duplicate calls to mem_sharing_enabled in mem_sharing.c Signed-off-by: Tamas K Lengyel --- xen/arch/x86/mm/mem_sharing.c | 30 +++++------------------------- xen/drivers/passthrough/pci.c | 3 +-- xen/include/asm-x86/hvm/domain.h | 6 +++++- xen/include/asm-x86/mem_sharing.h | 16 ++++++++++++++++ xen/include/asm-x86/p2m.h | 4 ---- 5 files changed, 27 insertions(+), 32 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index c0e305ad71..5d81730315 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -197,9 +197,6 @@ static inline shr_handle_t get_next_handle(void) return x + 1; } =20 -#define mem_sharing_enabled(d) \ - (is_hvm_domain(d) && (d)->arch.hvm.mem_sharing_enabled) - static atomic_t nr_saved_mfns =3D ATOMIC_INIT(0); static atomic_t nr_shared_mfns =3D ATOMIC_INIT(0); =20 @@ -1300,6 +1297,7 @@ int __mem_sharing_unshare_page(struct domain *d, int relinquish_shared_pages(struct domain *d) { int rc =3D 0; + struct mem_sharing_domain *msd =3D &d->arch.hvm.mem_sharing; struct p2m_domain *p2m =3D p2m_get_hostp2m(d); unsigned long gfn, count =3D 0; =20 @@ -1307,7 +1305,7 @@ int relinquish_shared_pages(struct domain *d) return 0; =20 p2m_lock(p2m); - for ( gfn =3D p2m->next_shared_gfn_to_relinquish; + for ( gfn =3D msd->next_shared_gfn_to_relinquish; gfn <=3D p2m->max_mapped_pfn; gfn++ ) { p2m_access_t a; @@ -1342,7 +1340,7 @@ int relinquish_shared_pages(struct domain *d) { if ( hypercall_preempt_check() ) { - p2m->next_shared_gfn_to_relinquish =3D gfn + 1; + msd->next_shared_gfn_to_relinquish =3D gfn + 1; rc =3D -ERESTART; break; } @@ -1428,7 +1426,7 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_= sharing_op_t) arg) =20 /* Only HAP is supported */ rc =3D -ENODEV; - if ( !hap_enabled(d) || !d->arch.hvm.mem_sharing_enabled ) + if ( !mem_sharing_enabled(d) ) goto out; =20 switch ( mso.op ) @@ -1437,10 +1435,6 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem= _sharing_op_t) arg) { shr_handle_t handle; =20 - rc =3D -EINVAL; - if ( !mem_sharing_enabled(d) ) - goto out; - rc =3D nominate_page(d, _gfn(mso.u.nominate.u.gfn), 0, &handle= ); mso.u.nominate.handle =3D handle; } @@ -1452,9 +1446,6 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_= sharing_op_t) arg) gfn_t gfn; shr_handle_t handle; =20 - rc =3D -EINVAL; - if ( !mem_sharing_enabled(d) ) - goto out; rc =3D mem_sharing_gref_to_gfn(d->grant_table, gref, &gfn, NUL= L); if ( rc < 0 ) goto out; @@ -1470,10 +1461,6 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem= _sharing_op_t) arg) struct domain *cd; shr_handle_t sh, ch; =20 - rc =3D -EINVAL; - if ( !mem_sharing_enabled(d) ) - goto out; - rc =3D rcu_lock_live_remote_domain_by_id(mso.u.share.client_do= main, &cd); if ( rc ) @@ -1540,10 +1527,6 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem= _sharing_op_t) arg) struct domain *cd; shr_handle_t sh; =20 - rc =3D -EINVAL; - if ( !mem_sharing_enabled(d) ) - goto out; - rc =3D rcu_lock_live_remote_domain_by_id(mso.u.share.client_do= main, &cd); if ( rc ) @@ -1602,9 +1585,6 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_= sharing_op_t) arg) mso.u.range.opaque > mso.u.range.last_gfn) ) goto out; =20 - if ( !mem_sharing_enabled(d) ) - goto out; - rc =3D rcu_lock_live_remote_domain_by_id(mso.u.range.client_do= main, &cd); if ( rc ) @@ -1708,7 +1688,7 @@ int mem_sharing_domctl(struct domain *d, struct xen_d= omctl_mem_sharing_op *mec) if ( unlikely(is_iommu_enabled(d) && mec->u.enable) ) rc =3D -EXDEV; else - d->arch.hvm.mem_sharing_enabled =3D mec->u.enable; + d->arch.hvm.mem_sharing.enabled =3D mec->u.enable; } break; =20 diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index c07a63981a..65d1d457ff 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -1498,8 +1498,7 @@ static int assign_device(struct domain *d, u16 seg, u= 8 bus, u8 devfn, u32 flag) /* Prevent device assign if mem paging or mem sharing have been=20 * enabled for this domain */ if ( d !=3D dom_io && - unlikely((is_hvm_domain(d) && - d->arch.hvm.mem_sharing_enabled) || + unlikely(mem_sharing_enabled(d) || vm_event_check_ring(d->vm_event_paging) || p2m_get_hostp2m(d)->global_logdirty) ) return -EXDEV; diff --git a/xen/include/asm-x86/hvm/domain.h b/xen/include/asm-x86/hvm/dom= ain.h index bcc5621797..8f70ba2b1a 100644 --- a/xen/include/asm-x86/hvm/domain.h +++ b/xen/include/asm-x86/hvm/domain.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -156,7 +157,6 @@ struct hvm_domain { =20 struct viridian_domain *viridian; =20 - bool_t mem_sharing_enabled; bool_t qemu_mapcache_invalidate; bool_t is_s3_suspended; =20 @@ -192,6 +192,10 @@ struct hvm_domain { struct vmx_domain vmx; struct svm_domain svm; }; + +#ifdef CONFIG_MEM_SHARING + struct mem_sharing_domain mem_sharing; +#endif }; =20 #endif /* __ASM_X86_HVM_DOMAIN_H__ */ diff --git a/xen/include/asm-x86/mem_sharing.h b/xen/include/asm-x86/mem_sh= aring.h index 0a9192d0e2..89cdaccea0 100644 --- a/xen/include/asm-x86/mem_sharing.h +++ b/xen/include/asm-x86/mem_sharing.h @@ -26,6 +26,20 @@ =20 #ifdef CONFIG_MEM_SHARING =20 +struct mem_sharing_domain +{ + bool enabled; + + /* + * When releasing shared gfn's in a preemptible manner, recall where + * to resume the search. + */ + unsigned long next_shared_gfn_to_relinquish; +}; + +#define mem_sharing_enabled(d) \ + (hap_enabled(d) && (d)->arch.hvm.mem_sharing.enabled) + /* Auditing of memory sharing code? */ #ifndef NDEBUG #define MEM_SHARING_AUDIT 1 @@ -105,6 +119,8 @@ int relinquish_shared_pages(struct domain *d); =20 #else =20 +#define mem_sharing_enabled(d) false + static inline unsigned int mem_sharing_get_nr_saved_mfns(void) { return 0; diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 7399c4a897..8defa90306 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -305,10 +305,6 @@ struct p2m_domain { unsigned long min_remapped_gfn; unsigned long max_remapped_gfn; =20 - /* When releasing shared gfn's in a preemptible manner, recall where - * to resume the search */ - unsigned long next_shared_gfn_to_relinquish; - #ifdef CONFIG_HVM /* Populate-on-demand variables * All variables are protected with the pod lock. We cannot rely on --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel