From patchwork Thu Dec 20 19:23:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 154362 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp50610ljp; Thu, 20 Dec 2018 11:26:06 -0800 (PST) X-Google-Smtp-Source: AFSGD/WeELO67u6TchlbNNkxDPsDKno86tss2AOoP7KRRykF47VfH0zVmCsNoAGdIjpZqPcMmJHv X-Received: by 2002:a81:1d44:: with SMTP id d65mr28207577ywd.483.1545333965935; Thu, 20 Dec 2018 11:26:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545333965; cv=none; d=google.com; s=arc-20160816; b=dHG9lZsUtxFVzvJ1eaWClK9oYfTj/biYap1owJcwkNXytGmzYjPHcixTQhC62MfHjA taccToICqxh59uK64E0pJwb75PwCAFrdw1Zj5c0t7aUs6QmQULRqWD9+e+ZPUi9+M7vO fBBx7p7dDbe/8X1O67Ut/8muA3SPZG7L/ZjYB//a/PO46Lrz8Juq5X5YBRM9+/Be7sUK zG0vP/Z7UrtSst7GQWhRCJJfZN/7gpD+GgB5saFnMzukekGfanf99gl3K1Tq+wHOiYFk cSFbOrZl1gRC/s/P5Tw0YqIV635zgok1EE580lrIeeDnMqJJZKTVwEFISNdomvRUtueZ B3qw== 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=Ex6+yrLCZMnxUVwzckeRn1BPMRPvhFlZmWFLKbR7RTE=; b=ALmZW/PZHZFGBWAhHnKybLbuEAjsxAjB1hmzvYJYBbTb/R8k8iVv9eFHUImTCSrzLr G6CYCCYJCkA8rgZTTnvZNm06CMKZDkdDffjAiEu/crroZtktt1KniQ9DvltVB3YfkibB uqIc90zPm8tDzfuJ4w4SWyi4ybjxQ4ea2QuG4lltBo7E3b68oPBkzZGiCvsYzwWDx9ns f9xJVN+wow8SnfIz0EefFd0Qv7SLTeRdXPbLZKjd0WjnQxnJCDURFHbEOjbaJtINLoEg CtLVhAK3pnmFZ4Ckaql5u4mLjiRSvmbRGwlAp98TSYRBSwkK4fVdhtKkgbm1RWee+wAT c7Eg== 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 w131si13250330ywc.347.2018.12.20.11.26.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Dec 2018 11:26:05 -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 1ga3vE-0001wt-4Y; Thu, 20 Dec 2018 19:23:52 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ga3vC-0001wd-EY for xen-devel@lists.xenproject.org; Thu, 20 Dec 2018 19:23:50 +0000 X-Inumbo-ID: c71d97df-048c-11e9-8e1d-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id c71d97df-048c-11e9-8e1d-bc764e045a96; Thu, 20 Dec 2018 19:23:49 +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 32DF91596; Thu, 20 Dec 2018 11:23:49 -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 1D3443F575; Thu, 20 Dec 2018 11:23:46 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 20 Dec 2018 19:23:31 +0000 Message-Id: <20181220192338.17526-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181220192338.17526-1-julien.grall@arm.com> References: <20181220192338.17526-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH for-4.12 v2 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: sstabellini@kernel.org, Wei Liu , Benjamin Sanda , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= 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. Signed-off-by: Benjamin Sanda [julien: Rework commit title / turn put_pg_owner to a macro] Signed-off-by: Julien Grall Acked-by: Stefano Stabellini --- Changes in v2: - Move get_pg_owner()/put_pg_owner() in sched.h - Turn put_pg_owner() to a static inline --- xen/arch/x86/mm.c | 42 ------------------------------------------ xen/common/page_alloc.c | 38 ++++++++++++++++++++++++++++++++++++++ xen/include/xen/sched.h | 8 ++++++++ 3 files changed, 46 insertions(+), 42 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 1431f347f3..08f34722c2 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -3089,48 +3089,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 2c6509e3a0..edb93b8ada 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) @@ -2509,6 +2510,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/sched.h b/xen/include/xen/sched.h index 0309c1f2a0..4956a7716c 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -599,6 +599,14 @@ static inline struct domain *rcu_lock_current_domain(void) } struct domain *get_domain_by_id(domid_t dom); + +struct domain *get_pg_owner(domid_t domid); + +static inline void put_pg_owner(struct domain *pg_owner) +{ + rcu_unlock_domain(pg_owner); +} + void domain_destroy(struct domain *d); int domain_kill(struct domain *d); int domain_shutdown(struct domain *d, u8 reason);