From nobody Tue Nov 11 08:31:25 2025 Delivered-To: importer@patchew.org Received-SPF: none (zoho.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 (zoho.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=1569426681; cv=none; d=zoho.com; s=zohoarc; b=SPp5de89Hk1xQWrV7BeOpPdcN1JtcHdQQI524DtEDKeHOZTCd2/mDwsA1EVcAr0l0utsskpb0/xiIlMriXRY+VrvTxKzT7BaBwmXy4PTRa5JLJ9pQpu45UUtwTlRZHq0txtIixwFPWjW7cLRvhxMr+SrhTjWxwkO7Lu8Rx+Z7e4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569426681; 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:ARC-Authentication-Results; bh=g9PqycUkO9C2TySatgv0/Kb/A8cC7e139nCfcbyT6w4=; b=iknotKX6YFigk1WSf6y0KzySAp79lXtXxDIevDkiJJNrnX6ynl1qw6XO6ZZmlGah8Q4+MvwWA9BMXaBaeDhr9bUFKHLPaV5IR9MMfMV6ilQnzRCOqrZNPUPzOk+0YJSOdg/3wL8g0G2xEaRLK8Y3UA6VFxPNfpspR8++Mouopjo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.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 1569426681114395.84479939804373; Wed, 25 Sep 2019 08:51:21 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iD9YN-0001h5-TG; Wed, 25 Sep 2019 15:50:07 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iD9YM-0001Yq-NH for xen-devel@lists.xenproject.org; Wed, 25 Sep 2019 15:50:06 +0000 Received: from mga12.intel.com (unknown [192.55.52.136]) by localhost (Halon) with ESMTPS id 12999768-dfac-11e9-bf31-bc764e2007e4; Wed, 25 Sep 2019 15:49:35 +0000 (UTC) Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Sep 2019 08:49:33 -0700 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.252.129.153]) by orsmga006.jf.intel.com with ESMTP; 25 Sep 2019 08:49:32 -0700 X-Inumbo-ID: 12999768-dfac-11e9-bf31-bc764e2007e4 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,548,1559545200"; d="scan'208";a="193812663" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 25 Sep 2019 08:48:46 -0700 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [RFC PATCH for-next 08/18] 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 | 2 +- xen/include/asm-x86/hvm/domain.h | 7 ++++++- xen/include/asm-x86/mem_sharing.h | 16 ++++++++++++++++ xen/include/asm-x86/p2m.h | 4 ---- 5 files changed, 28 insertions(+), 31 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index df308a75cd..d5ecb77679 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 @@ private_page_found: 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(has_iommu_pt(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 d28f17af75..12e24b58fd 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -1482,7 +1482,7 @@ static int assign_device(struct domain *d, u16 seg, u= 8 bus, u8 devfn, u32 flag) =20 /* Prevent device assign if mem paging or mem sharing have been=20 * enabled for this domain */ - if ( unlikely(d->arch.hvm.mem_sharing_enabled || + if ( 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..d54663b386 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,7 @@ struct hvm_domain { =20 struct viridian_domain *viridian; =20 - bool_t mem_sharing_enabled; + bool_t hap_enabled; bool_t qemu_mapcache_invalidate; bool_t is_s3_suspended; =20 @@ -192,6 +193,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 8deb0ceee5..57db72376b 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