From patchwork Tue Nov 6 19:14:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 150347 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4274063ljp; Tue, 6 Nov 2018 11:17:23 -0800 (PST) X-Google-Smtp-Source: AJdET5ehG9DbtMLiWbcGXqcBJIivALbo2Jsy2AkojthbE5ahpUhi+pvds/5KQyUq/PShS39dziK7 X-Received: by 2002:a81:2156:: with SMTP id h83-v6mr6435535ywh.9.1541531843250; Tue, 06 Nov 2018 11:17:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541531843; cv=none; d=google.com; s=arc-20160816; b=nc0LevNL19kBJMYhaaBWgnutXPBcXKVbZTvyfBqz1b5adCwfm64ETygGsgE/lMEUaF eT/RDol6zbLQeriAEfk4pE9VP17EIPl40OabXXcm+W5Azjg4tPegbI2nfgxfc5k99A6f djew9TnTZU/++E2nO6L0TitpoxeQ/lqjtXhOGvnx0CpE2hqWKpfudZeh46gcwR95x2Fi nLQYIzagUrWsgMesm7XB51m7+XVtR1uFoFf/01yUIMsR8k5UHYLBv4EAxYz7cGdfltXe I7J+GwzvoGqTavwoa47mc3MsltnKLVAVb9JxhMn6fAue75qTbckE2L8+ch3c43RnIZAq eoZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=8e4iTU1+5oTWBMUdWKQNQBTRkQ9xWyAy/unG3YCog40=; b=vql660/tT036FAYaHlxpWg6hIpCKly2Ayj3f/sIU9moiuEps+BFYtmqll+KzQ/E9OZ rXXATcYyO8ijAnna5px523xmJcNez4AIDHiSVs7AmWlt5yA2byUqltVHH6ftIyl9NG9u Mp5YWacW6DfZOjSc08KlKYssVjEhlCQFfOxIde4TutBH7gpw+vBtRCzOKN2MG+BY3YwX k33CZo/7JFl8VD+fnRWFFFheY69nxT6HVt3V5eZivgRVmNkSMK6mtkb/w9MCdMdO/BNA vRAo/hbZVVzTfvb1fi/3RpcWWvyUbh0mlBOcOcUjesi+RVDjqLhZQaVZr8YaRoDSv+Xu fR5Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id g16-v6si21108365ybh.28.2018.11.06.11.17.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Nov 2018 11:17:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1gK6oe-0003bq-91; Tue, 06 Nov 2018 19:15:08 +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 1gK6oc-0003bb-SC for xen-devel@lists.xenproject.org; Tue, 06 Nov 2018 19:15:06 +0000 X-Inumbo-ID: 44f1f0aa-e1f8-11e8-9fee-12d6303a7972 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 44f1f0aa-e1f8-11e8-9fee-12d6303a7972; Tue, 06 Nov 2018 19:15:06 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8B4911596; Tue, 6 Nov 2018 11:15:05 -0800 (PST) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9D7813F718; Tue, 6 Nov 2018 11:15:03 -0800 (PST) From: Julien Grall To: sstabellini@kernel.org, xen-devel@lists.xenproject.org Date: Tue, 6 Nov 2018 19:14:47 +0000 Message-Id: <20181106191454.22143-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181106191454.22143-1-julien.grall@arm.com> References: <20181106191454.22143-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 1/8] xen/page_alloc: Move get_pg_owner()/put_pg_owner() from x86 to common code 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: Wei Liu , Benjamin Sanda , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Benjamin Sanda get_pg_owner() and put_pg_owner() will be necessary in a follow-up commit to support xentrace on Arm. So move the helper to common code. Note that put_pg_owner() has been turned to a macro rather than static inline because of inter-dependency between includes. Signed-off-by: Benjamin Sanda [julien: Rework commit title / turn put_pg_owner to a macro] Signed-off-by: Julien Grall --- xen/arch/x86/mm.c | 42 ------------------------------------------ xen/common/page_alloc.c | 38 ++++++++++++++++++++++++++++++++++++++ xen/include/xen/mm.h | 3 +++ 3 files changed, 41 insertions(+), 42 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index f043e43ac7..9363e9bd96 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -3100,48 +3100,6 @@ static int vcpumask_to_pcpumask( } } -static struct domain *get_pg_owner(domid_t domid) -{ - struct domain *pg_owner = NULL, *curr = current->domain; - - if ( likely(domid == DOMID_SELF) ) - { - pg_owner = rcu_lock_current_domain(); - goto out; - } - - if ( unlikely(domid == curr->domain_id) ) - { - gdprintk(XENLOG_WARNING, "Cannot specify itself as foreign domain\n"); - goto out; - } - - switch ( domid ) - { - case DOMID_IO: - pg_owner = rcu_lock_domain(dom_io); - break; - case DOMID_XEN: - pg_owner = rcu_lock_domain(dom_xen); - break; - default: - if ( (pg_owner = rcu_lock_domain_by_id(domid)) == NULL ) - { - gdprintk(XENLOG_WARNING, "Unknown domain d%d\n", domid); - break; - } - break; - } - - out: - return pg_owner; -} - -static void put_pg_owner(struct domain *pg_owner) -{ - rcu_unlock_domain(pg_owner); -} - long do_mmuext_op( XEN_GUEST_HANDLE_PARAM(mmuext_op_t) uops, unsigned int count, diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 16e1b0c357..ef1b4f596a 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -146,6 +146,7 @@ #include #include #include /* for highmem_start only */ +#include #else #define p2m_pod_offline_or_broken_hit(pg) 0 #define p2m_pod_offline_or_broken_replace(pg) BUG_ON(pg != NULL) @@ -2447,6 +2448,43 @@ static __init int register_heap_trigger(void) } __initcall(register_heap_trigger); +struct domain *get_pg_owner(domid_t domid) +{ + struct domain *pg_owner = NULL, *curr = current->domain; + + if ( likely(domid == DOMID_SELF) ) + { + pg_owner = rcu_lock_current_domain(); + goto out; + } + + if ( unlikely(domid == curr->domain_id) ) + { + gdprintk(XENLOG_WARNING, "Cannot specify itself as foreign domain\n"); + goto out; + } + + switch ( domid ) + { + case DOMID_IO: + pg_owner = rcu_lock_domain(dom_io); + break; + case DOMID_XEN: + pg_owner = rcu_lock_domain(dom_xen); + break; + default: + if ( (pg_owner = rcu_lock_domain_by_id(domid)) == NULL ) + { + gdprintk(XENLOG_WARNING, "Unknown domain d%d\n", domid); + break; + } + break; + } + + out: + return pg_owner; +} + /* * Local variables: * mode: C diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 054d02e6c0..dd4d990ae3 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -589,6 +589,9 @@ int xenmem_add_to_physmap_one(struct domain *d, unsigned int space, int xenmem_add_to_physmap(struct domain *d, struct xen_add_to_physmap *xatp, unsigned int start); +struct domain *get_pg_owner(domid_t domid); +#define put_pg_owner(pg_owner) rcu_unlock_domain(pg_owner) + /* Return 0 on success, or negative on error. */ int __must_check guest_remove_page(struct domain *d, unsigned long gmfn); int __must_check steal_page(struct domain *d, struct page_info *page,