From nobody Mon Feb 9 08:30:29 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=1579629068; cv=none; d=zohomail.com; s=zohoarc; b=MJOOzekusGlcfgmIo8+ESSJpLWoiZHQNqTRuOtjylZNVW9tHols/uLjyksFE3B2P7BTYSzyCl98Puek6yiI0M0L7cs4Lipm6APQiXZ4rTZGzbLw+1zWhXU+QctCPWp/PbQ+A9yqSUUsqnPCtoUszdxdfjqyQTn0qaa3l+L0lVjo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579629068; 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=nv3qtQZbGygJrJ0BcofSN7qAro7N9Ullk8wJxz9QscU=; b=cv0Tp6pCJIovFiQnpmbMExKCdLH/iCPEDwBCTuRIBAo1tqlBHDTQme85I0w+XKGzEMHMM/+kZEGw5szukl/TOsLozfQwVWpzqjETkvqyL6Gz/NUOTzIitW55UdUp/VX2913hAld2RgbwMe6ndX53yIdcjSVDrNHJBQFpAbh0x1o= 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 1579629068280507.13397226773907; Tue, 21 Jan 2020 09:51:08 -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 1itxfe-0004pb-PH; Tue, 21 Jan 2020 17:50:34 +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 1itxfd-0004o0-B3 for xen-devel@lists.xenproject.org; Tue, 21 Jan 2020 17:50:33 +0000 Received: from mga04.intel.com (unknown [192.55.52.120]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7856bad3-3c76-11ea-bb21-12813bfff9fa; Tue, 21 Jan 2020 17:50:11 +0000 (UTC) Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Jan 2020 09:50:03 -0800 Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.251.23.127]) by orsmga006.jf.intel.com with ESMTP; 21 Jan 2020 09:50:03 -0800 X-Inumbo-ID: 7856bad3-3c76-11ea-bb21-12813bfff9fa X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,346,1574150400"; d="scan'208";a="228929167" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Tue, 21 Jan 2020 09:49:40 -0800 Message-Id: <90ec3d762a17d81773e36dfa894d9b4bbd991389.1579628566.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 v5 07/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 , =?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 Acked-by: Jan Beulich Acked-by: George Dunlap --- v5: remove hap_enabled check() from mem_sharing_enabled as suggested by Jan --- xen/arch/x86/mm/mem_sharing.c | 10 ++++------ xen/drivers/passthrough/pci.c | 3 +-- xen/include/asm-x86/hvm/domain.h | 6 +++++- xen/include/asm-x86/mem_sharing.h | 15 +++++++++++++++ xen/include/asm-x86/p2m.h | 4 ---- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index 2a20e4958b..1846f97acc 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -197,9 +197,6 @@ static 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 @@ -1297,6 +1294,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 @@ -1304,7 +1302,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; @@ -1339,7 +1337,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; } @@ -1425,7 +1423,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 ) 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 cf7848709f..a10af9d570 100644 --- a/xen/include/asm-x86/mem_sharing.h +++ b/xen/include/asm-x86/mem_sharing.h @@ -26,6 +26,19 @@ =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) ((d)->arch.hvm.mem_sharing.enabled) + /* Auditing of memory sharing code? */ #ifndef NDEBUG #define MEM_SHARING_AUDIT 1 @@ -104,6 +117,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