From patchwork Wed Jan 8 17:14:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamas K Lengyel X-Patchwork-Id: 11324123 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1501F13A0 for ; Wed, 8 Jan 2020 17:15:44 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F01402067D for ; Wed, 8 Jan 2020 17:15:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F01402067D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ipEuv-0000ZD-DJ; Wed, 08 Jan 2020 17:14:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ipEut-0000Y1-K7 for xen-devel@lists.xenproject.org; Wed, 08 Jan 2020 17:14:47 +0000 X-Inumbo-ID: 59dcc8bc-323a-11ea-8599-bc764e2007e4 Received: from mga14.intel.com (unknown [192.55.52.115]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 59dcc8bc-323a-11ea-8599-bc764e2007e4; Wed, 08 Jan 2020 17:14:38 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Jan 2020 09:14:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,410,1571727600"; d="scan'208";a="395806093" Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.251.132.23]) by orsmga005.jf.intel.com with ESMTP; 08 Jan 2020 09:14:36 -0800 From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 8 Jan 2020 09:14:03 -0800 Message-Id: <3f8ab6b4cf686e814d91961b564fede6d0c64030.1578503483.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 v4 06/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_Pau_Monn=C3=A9?= 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 --- 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 | 16 ++++++++++++++++ xen/include/asm-x86/p2m.h | 4 ---- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index f6187403a0..3aa61c30e6 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; } -#define mem_sharing_enabled(d) \ - (is_hvm_domain(d) && (d)->arch.hvm.mem_sharing_enabled) - static atomic_t nr_saved_mfns = ATOMIC_INIT(0); static atomic_t nr_shared_mfns = ATOMIC_INIT(0); @@ -1309,6 +1306,7 @@ int __mem_sharing_unshare_page(struct domain *d, int relinquish_shared_pages(struct domain *d) { int rc = 0; + struct mem_sharing_domain *msd = &d->arch.hvm.mem_sharing; struct p2m_domain *p2m = p2m_get_hostp2m(d); unsigned long gfn, count = 0; @@ -1316,7 +1314,7 @@ int relinquish_shared_pages(struct domain *d) return 0; p2m_lock(p2m); - for ( gfn = p2m->next_shared_gfn_to_relinquish; + for ( gfn = msd->next_shared_gfn_to_relinquish; gfn <= p2m->max_mapped_pfn; gfn++ ) { p2m_access_t a; @@ -1351,7 +1349,7 @@ int relinquish_shared_pages(struct domain *d) { if ( hypercall_preempt_check() ) { - p2m->next_shared_gfn_to_relinquish = gfn + 1; + msd->next_shared_gfn_to_relinquish = gfn + 1; rc = -ERESTART; break; } @@ -1437,7 +1435,7 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) /* Only HAP is supported */ rc = -ENODEV; - if ( !hap_enabled(d) || !d->arch.hvm.mem_sharing_enabled ) + if ( !mem_sharing_enabled(d) ) goto out; 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, u8 bus, u8 devfn, u32 flag) /* Prevent device assign if mem paging or mem sharing have been * enabled for this domain */ if ( d != 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/domain.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 { struct viridian_domain *viridian; - bool_t mem_sharing_enabled; bool_t qemu_mapcache_invalidate; bool_t is_s3_suspended; @@ -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 }; #endif /* __ASM_X86_HVM_DOMAIN_H__ */ diff --git a/xen/include/asm-x86/mem_sharing.h b/xen/include/asm-x86/mem_sharing.h index cf7848709f..13114b6346 100644 --- a/xen/include/asm-x86/mem_sharing.h +++ b/xen/include/asm-x86/mem_sharing.h @@ -26,6 +26,20 @@ #ifdef CONFIG_MEM_SHARING +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 @@ -104,6 +118,8 @@ int relinquish_shared_pages(struct domain *d); #else +#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; - /* 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