diff mbox series

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

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

Commit Message

Julien Grall Dec. 20, 2018, 7:23 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.

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>

---
    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(-)

Comments

Stefano Stabellini Dec. 20, 2018, 10:53 p.m. UTC | #1
On Thu, 20 Dec 2018, Julien Grall 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.
> 
> 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>

Acked-by: Stefano Stabellini <sstabellini@kernel.org>

> ---
>     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 <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)
> @@ -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);
> -- 
> 2.11.0
>
Andrew Cooper Dec. 20, 2018, 10:59 p.m. UTC | #2
On 20/12/2018 22:53, Stefano Stabellini wrote:
>
>> 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
>> @@ -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;

Newline.

>> +    case DOMID_XEN:
>> +        pg_owner = rcu_lock_domain(dom_xen);
>> +        break;

Newline.

>> +    default:
>> +        if ( (pg_owner = rcu_lock_domain_by_id(domid)) == NULL )
>> +        {
>> +            gdprintk(XENLOG_WARNING, "Unknown domain d%d\n", domid);
>> +            break;
>> +        }
>> +        break;

if ( (pg_owner = rcu_lock_domain_by_id(domid)) == NULL )
    gdprintk(XENLOG_WARNING, "Unknown domain d%d\n", domid);

break;

All trivial, so Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
and please fix on commit.

~Andrew
Jan Beulich Dec. 21, 2018, 9:12 a.m. UTC | #3
>>> On 20.12.18 at 20:23, <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.
> 
> Signed-off-by: Benjamin Sanda <ben.sanda@dornerworks.com>
> [julien: Rework commit title / turn put_pg_owner to a macro]

Nit: It's an inline function now.

Jan
Julien Grall Dec. 21, 2018, 10:53 a.m. UTC | #4
Hi,

On 20/12/2018 22:59, Andrew Cooper wrote:
> On 20/12/2018 22:53, Stefano Stabellini wrote:
>>
>>> 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
>>> @@ -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;
> 
> Newline.
> 
>>> +    case DOMID_XEN:
>>> +        pg_owner = rcu_lock_domain(dom_xen);
>>> +        break;
> 
> Newline.
> 
>>> +    default:
>>> +        if ( (pg_owner = rcu_lock_domain_by_id(domid)) == NULL )
>>> +        {
>>> +            gdprintk(XENLOG_WARNING, "Unknown domain d%d\n", domid);
>>> +            break;
>>> +        }
>>> +        break;
> 
> if ( (pg_owner = rcu_lock_domain_by_id(domid)) == NULL )
>      gdprintk(XENLOG_WARNING, "Unknown domain d%d\n", domid);
> 
> break;
> 
> All trivial, so Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
> and please fix on commit.

Thank you! I have now committed this patch.

Cheers,
diff mbox series

Patch

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 <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)
@@ -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);