diff mbox series

[Xen-devel,1/8] xen/page_alloc: Move get_pg_owner()/put_pg_owner() from x86 to common code

Message ID 20181106191454.22143-2-julien.grall@arm.com
State New
Headers show
Series xen/arm: Add xentrace support | expand

Commit Message

Julien Grall Nov. 6, 2018, 7:14 p.m. UTC
From: Benjamin Sanda <ben.sanda@dornerworks.com>

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 <ben.sanda@dornerworks.com>
[julien: Rework commit title / turn put_pg_owner to a macro]
Signed-off-by: Julien Grall <julien.grall@arm.com>
---
 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(-)

Comments

Jan Beulich Nov. 7, 2018, 9:28 a.m. UTC | #1
>>> On 06.11.18 at 20:14, <julien.grall@arm.com> wrote:
> From: Benjamin Sanda <ben.sanda@dornerworks.com>
> 
> 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.

Could this be avoided by placing both in a different header,
e.g. sched.h? Mid-term we should probably try to split out
type (structure) declarations from sched.h, to make it easier
to have full types available without having to respect other
include dependencies.

Jan
Julien Grall Nov. 9, 2018, 6:06 p.m. UTC | #2
Hi Jan,

On 07/11/2018 09:28, Jan Beulich wrote:
>>>> On 06.11.18 at 20:14, <julien.grall@arm.com> wrote:
>> From: Benjamin Sanda <ben.sanda@dornerworks.com>
>>
>> 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.
> 
> Could this be avoided by placing both in a different header,
> e.g. sched.h?
This seems to work. I will use that in the next version.

> Mid-term we should probably try to split out
> type (structure) declarations from sched.h, to make it easier
> to have full types available without having to respect other
> include dependencies.

The include dependencies on Xen is a bit of a nightmare. I have started to clean 
it up on Arm and I will support any changes in the common headers.

Cheers,
diff mbox series

Patch

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 <asm/guest.h>
 #include <asm/p2m.h>
 #include <asm/setup.h> /* for highmem_start only */
+#include <asm/paging.h>
 #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,