From patchwork Wed Jul 17 19:33:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamas K Lengyel X-Patchwork-Id: 11048189 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3B5846C5 for ; Wed, 17 Jul 2019 19:36:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A092204FB for ; Wed, 17 Jul 2019 19:36:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D7D0285D6; Wed, 17 Jul 2019 19:36:01 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 19F95204FB for ; Wed, 17 Jul 2019 19:36:00 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hnpgh-0000IV-13; Wed, 17 Jul 2019 19:34:03 +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 1hnpgg-0000IL-3M for xen-devel@lists.xenproject.org; Wed, 17 Jul 2019 19:34:02 +0000 X-Inumbo-ID: d2f84668-a8c9-11e9-b34d-ef1fc16ccd93 Received: from mail-io1-f66.google.com (unknown [209.85.166.66]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d2f84668-a8c9-11e9-b34d-ef1fc16ccd93; Wed, 17 Jul 2019 19:33:59 +0000 (UTC) Received: by mail-io1-f66.google.com with SMTP id o9so47686592iom.3 for ; Wed, 17 Jul 2019 12:33:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bhWcJS8ddgdUot0n7cOWsB1nWNTTcu28PhAqbt9unzE=; b=rce9aksren0NUfpFpaHvSv5PuZS+YsziuobuSK+M36Qj5BJrEbILpuadtSAql1CuMQ M+qmg8y0mo8iZnKbRhM63PicD1dseSt/MLElvotlNyr4dwYuaeKZMzTJtZbOedAbGlHS yOK57++MAZgCKwhPIyKsPyWfUq8SBw6tpifHnx1Kq5KjNLwB8L5gMXltz6zVMNtH6lY0 vktqKeQD5TphJrGz61MCR58Doq/csFneYlOiDZoVpX3/RATuwyhIBmgD5ktJemvRmGt9 hToHHNxUyub5nFtpe1KDd5Bk5vE/l53swImeY7JTXkkId31kXjcrshJVJi0jFC0ciusv XVWA== X-Gm-Message-State: APjAAAUaoEJV2naFtcbiF3rYYgdDBxmDvqxqud7weV5kYdUbahHvxad6 1eCsk+618EyM6Kx1UONHqNFAHVn8hTQ= X-Google-Smtp-Source: APXvYqzrM8D7/bpoymNk7/JIn6lgsbg1TXAklNJxkyfJnaG4sM7EImy+PUeVAPjyK7Hwmcn2ZiWtGQ== X-Received: by 2002:a5d:8794:: with SMTP id f20mr37851018ion.128.1563392038669; Wed, 17 Jul 2019 12:33:58 -0700 (PDT) Received: from l1.lan (c-71-205-12-124.hsd1.co.comcast.net. [71.205.12.124]) by smtp.gmail.com with ESMTPSA id v13sm21743421ioq.13.2019.07.17.12.33.56 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 17 Jul 2019 12:33:57 -0700 (PDT) From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 17 Jul 2019 13:33:34 -0600 Message-Id: <20190717193335.11991-5-tamas@tklengyel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190717193335.11991-1-tamas@tklengyel.com> References: <20190717193335.11991-1-tamas@tklengyel.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v6 4/5] x86/mem_sharing: compile mem_sharing subsystem only when kconfig is enabled 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 , Wei Liu , Razvan Cojocaru , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Stefano Stabellini , Jan Beulich , Daniel De Graaf , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Disable it by default as it is only an experimental subsystem. Signed-off-by: Tamas K Lengyel Acked-by: Daniel De Graaf Acked-by: Razvan Cojocaru Acked-by: Jan Beulich Cc: Andrew Cooper Cc: Wei Liu Cc: Roger Pau Monne Cc: George Dunlap Cc: Ian Jackson Cc: Julien Grall Cc: Konrad Rzeszutek Wilk Cc: Stefano Stabellini Cc: Tim Deegan Cc: George Dunlap ---- v6: rebase on staging --- xen/arch/x86/Kconfig | 6 +++++- xen/arch/x86/domain.c | 2 ++ xen/arch/x86/domctl.c | 2 ++ xen/arch/x86/mm/Makefile | 2 +- xen/arch/x86/x86_64/compat/mm.c | 2 ++ xen/arch/x86/x86_64/mm.c | 2 ++ xen/common/Kconfig | 3 --- xen/common/domain.c | 6 +++--- xen/common/grant_table.c | 2 +- xen/common/memory.c | 2 +- xen/common/vm_event.c | 6 +++--- xen/include/asm-x86/mem_sharing.h | 28 ++++++++++++++++++++++++++++ xen/include/asm-x86/mm.h | 3 +++ xen/include/xen/mm.h | 2 +- xen/include/xen/sched.h | 2 +- xen/include/xsm/dummy.h | 2 +- xen/include/xsm/xsm.h | 4 ++-- xen/xsm/dummy.c | 2 +- xen/xsm/flask/hooks.c | 4 ++-- 19 files changed, 61 insertions(+), 21 deletions(-) diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index f502d765ba..288dc6c042 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -18,7 +18,6 @@ config X86 select HAS_KEXEC select MEM_ACCESS_ALWAYS_ON select HAS_MEM_PAGING - select HAS_MEM_SHARING select HAS_NS16550 select HAS_PASSTHROUGH select HAS_PCI @@ -199,6 +198,11 @@ config PV_SHIM_EXCLUSIVE firmware, and will not function correctly in other scenarios. If unsure, say N. + +config MEM_SHARING + bool "Xen memory sharing support" if EXPERT = "y" + depends on HVM + endmenu source "common/Kconfig" diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index e791d86892..ea55160887 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -2095,6 +2095,7 @@ int domain_relinquish_resources(struct domain *d) d->arch.auto_unmask = 0; } +#ifdef CONFIG_MEM_SHARING PROGRESS(shared): if ( is_hvm_domain(d) ) @@ -2105,6 +2106,7 @@ int domain_relinquish_resources(struct domain *d) if ( ret ) return ret; } +#endif spin_lock(&d->page_alloc_lock); page_list_splice(&d->arch.relmem_list, &d->page_list); diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index c827790202..2d45e5b8a8 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -1236,9 +1236,11 @@ long arch_do_domctl( break; } +#ifdef CONFIG_MEM_SHARING case XEN_DOMCTL_mem_sharing_op: ret = mem_sharing_domctl(d, &domctl->u.mem_sharing_op); break; +#endif #if P2M_AUDIT && defined(CONFIG_HVM) case XEN_DOMCTL_audit_p2m: diff --git a/xen/arch/x86/mm/Makefile b/xen/arch/x86/mm/Makefile index 5a17646f98..5010a29d6c 100644 --- a/xen/arch/x86/mm/Makefile +++ b/xen/arch/x86/mm/Makefile @@ -6,7 +6,7 @@ obj-$(CONFIG_HVM) += guest_walk_2.o guest_walk_3.o guest_walk_4.o obj-$(CONFIG_SHADOW_PAGING) += guest_walk_2.o guest_walk_3.o guest_walk_4.o obj-$(CONFIG_MEM_ACCESS) += mem_access.o obj-y += mem_paging.o -obj-y += mem_sharing.o +obj-$(CONFIG_MEM_SHARING) += mem_sharing.o obj-y += p2m.o p2m-pt.o obj-$(CONFIG_HVM) += p2m-ept.o p2m-pod.o obj-y += paging.o diff --git a/xen/arch/x86/x86_64/compat/mm.c b/xen/arch/x86/x86_64/compat/mm.c index 32410ed273..d4c6be3032 100644 --- a/xen/arch/x86/x86_64/compat/mm.c +++ b/xen/arch/x86/x86_64/compat/mm.c @@ -152,8 +152,10 @@ int compat_arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) case XENMEM_paging_op: return mem_paging_memop(guest_handle_cast(arg, xen_mem_paging_op_t)); +#ifdef CONFIG_MEM_SHARING case XENMEM_sharing_op: return mem_sharing_memop(guest_handle_cast(arg, xen_mem_sharing_op_t)); +#endif default: rc = -ENOSYS; diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index 899b883b2d..1919cae18b 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -993,8 +993,10 @@ long subarch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) case XENMEM_paging_op: return mem_paging_memop(guest_handle_cast(arg, xen_mem_paging_op_t)); +#ifdef CONFIG_MEM_SHARING case XENMEM_sharing_op: return mem_sharing_memop(guest_handle_cast(arg, xen_mem_sharing_op_t)); +#endif default: rc = -ENOSYS; diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 912630a4fb..16829f6274 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -48,9 +48,6 @@ config MEM_ACCESS config HAS_MEM_PAGING bool -config HAS_MEM_SHARING - bool - config HAS_PDX bool diff --git a/xen/common/domain.c b/xen/common/domain.c index 8a5fa8662b..55aa759b75 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -74,7 +74,7 @@ integer_param("hardware_dom", hardware_domid); /* Private domain structs for DOMID_XEN, DOMID_IO, etc. */ struct domain *__read_mostly dom_xen; struct domain *__read_mostly dom_io; -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING struct domain *__read_mostly dom_cow; #endif @@ -549,7 +549,7 @@ void __init setup_system_domains(void) if ( IS_ERR(dom_io) ) panic("Failed to create d[IO]: %ld\n", PTR_ERR(dom_io)); -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING /* * Initialise our COW domain. * This domain owns sharable pages. @@ -966,7 +966,7 @@ static void complete_domain_destroy(struct rcu_head *head) xfree(d->vm_event_paging); #endif xfree(d->vm_event_monitor); -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING xfree(d->vm_event_share); #endif diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index b6b45c21e1..97695a221a 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -3798,7 +3798,7 @@ void grant_table_init_vcpu(struct vcpu *v) v->maptrack_tail = MAPTRACK_TAIL; } -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING int mem_sharing_gref_to_gfn(struct grant_table *gt, grant_ref_t ref, gfn_t *gfn, uint16_t *status) { diff --git a/xen/common/memory.c b/xen/common/memory.c index 30d210fc08..d9b35a608c 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -1676,7 +1676,7 @@ int check_get_page_from_gfn(struct domain *d, gfn_t gfn, bool readonly, return -EAGAIN; } #endif -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING if ( (q & P2M_UNSHARE) && p2m_is_shared(p2mt) ) { if ( page ) diff --git a/xen/common/vm_event.c b/xen/common/vm_event.c index e8726805e7..2a1c87e44b 100644 --- a/xen/common/vm_event.c +++ b/xen/common/vm_event.c @@ -531,7 +531,7 @@ static void monitor_notification(struct vcpu *v, unsigned int port) vm_event_resume(v->domain, v->domain->vm_event_monitor); } -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING /* Registered with Xen-bound event channel for incoming notifications. */ static void mem_sharing_notification(struct vcpu *v, unsigned int port) { @@ -561,7 +561,7 @@ void vm_event_cleanup(struct domain *d) destroy_waitqueue_head(&d->vm_event_monitor->wq); (void)vm_event_disable(d, &d->vm_event_monitor); } -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING if ( vm_event_check_ring(d->vm_event_share) ) { destroy_waitqueue_head(&d->vm_event_share->wq); @@ -703,7 +703,7 @@ int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec) } break; -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING case XEN_DOMCTL_VM_EVENT_OP_SHARING: { rc = -EINVAL; diff --git a/xen/include/asm-x86/mem_sharing.h b/xen/include/asm-x86/mem_sharing.h index afd0c17292..db22468744 100644 --- a/xen/include/asm-x86/mem_sharing.h +++ b/xen/include/asm-x86/mem_sharing.h @@ -24,6 +24,8 @@ #include #include +#ifdef CONFIG_MEM_SHARING + /* Auditing of memory sharing code? */ #ifndef NDEBUG #define MEM_SHARING_AUDIT 1 @@ -99,4 +101,30 @@ int mem_sharing_domctl(struct domain *d, */ int relinquish_shared_pages(struct domain *d); +#else + +static inline unsigned int mem_sharing_get_nr_saved_mfns(void) +{ + return 0; +} +static inline unsigned int mem_sharing_get_nr_shared_mfns(void) +{ + return 0; +} +static inline int mem_sharing_unshare_page(struct domain *d, + unsigned long gfn, + uint16_t flags) +{ + ASSERT_UNREACHABLE(); + return -EOPNOTSUPP; +} +static inline int mem_sharing_notify_enomem(struct domain *d, unsigned long gfn, + bool allow_sleep) +{ + ASSERT_UNREACHABLE(); + return -EOPNOTSUPP; +} + +#endif + #endif /* __MEM_SHARING_H__ */ diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index 087ad97351..35c2527265 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -127,6 +127,8 @@ struct page_info /* For non-pinnable single-page shadows, a higher entry that points * at us. */ paddr_t up; + +#ifdef CONFIG_MEM_SHARING /* For shared/sharable pages, we use a doubly-linked list * of all the {pfn,domain} pairs that map this page. We also include * an opaque handle, which is effectively a version, so that clients @@ -134,6 +136,7 @@ struct page_info * This list is allocated and freed when a page is shared/unshared. */ struct page_sharing_info *sharing; +#endif }; /* Reference count and various PGC_xxx flags and fields. */ diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 47c8412b3a..977e45aae7 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -275,7 +275,7 @@ struct npfec { /* Private domain structs for DOMID_XEN, DOMID_IO, etc. */ extern struct domain *dom_xen, *dom_io; -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING extern struct domain *dom_cow; #else # define dom_cow NULL diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 97a3ab55aa..b40c8fd138 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -459,7 +459,7 @@ struct domain /* Various vm_events */ /* Memory sharing support */ -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING struct vm_event_domain *vm_event_share; #endif /* Memory paging support */ diff --git a/xen/include/xsm/dummy.h b/xen/include/xsm/dummy.h index 01d2814fed..ef52bb1764 100644 --- a/xen/include/xsm/dummy.h +++ b/xen/include/xsm/dummy.h @@ -597,7 +597,7 @@ static XSM_INLINE int xsm_mem_paging(XSM_DEFAULT_ARG struct domain *d) } #endif -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING static XSM_INLINE int xsm_mem_sharing(XSM_DEFAULT_ARG struct domain *d) { XSM_ASSERT_ACTION(XSM_DM_PRIV); diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h index b6141f6ab1..e22d6160b5 100644 --- a/xen/include/xsm/xsm.h +++ b/xen/include/xsm/xsm.h @@ -150,7 +150,7 @@ struct xsm_operations { int (*mem_paging) (struct domain *d); #endif -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING int (*mem_sharing) (struct domain *d); #endif @@ -597,7 +597,7 @@ static inline int xsm_mem_paging (xsm_default_t def, struct domain *d) } #endif -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING static inline int xsm_mem_sharing (xsm_default_t def, struct domain *d) { return xsm_ops->mem_sharing(d); diff --git a/xen/xsm/dummy.c b/xen/xsm/dummy.c index c9a566f2b5..5705e52791 100644 --- a/xen/xsm/dummy.c +++ b/xen/xsm/dummy.c @@ -128,7 +128,7 @@ void __init xsm_fixup_ops (struct xsm_operations *ops) set_to_dummy_if_null(ops, mem_paging); #endif -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING set_to_dummy_if_null(ops, mem_sharing); #endif diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index a7d690ac3c..791c1f66af 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -1262,7 +1262,7 @@ static int flask_mem_paging(struct domain *d) } #endif -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING static int flask_mem_sharing(struct domain *d) { return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__MEM_SHARING); @@ -1829,7 +1829,7 @@ static struct xsm_operations flask_ops = { .mem_paging = flask_mem_paging, #endif -#ifdef CONFIG_HAS_MEM_SHARING +#ifdef CONFIG_MEM_SHARING .mem_sharing = flask_mem_sharing, #endif