All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] domain_page: handle NULL within unmap_domain_page() itself
@ 2020-05-13 15:43 Hongyan Xia
  2020-05-14 10:01 ` Wei Liu
  2020-05-15 18:06 ` Julien Grall
  0 siblings, 2 replies; 4+ messages in thread
From: Hongyan Xia @ 2020-05-13 15:43 UTC (permalink / raw)
  To: xen-devel
  Cc: Stefano Stabellini, Julien Grall, Wei Liu, Andrew Cooper,
	Ian Jackson, George Dunlap, Jan Beulich, Volodymyr Babchuk,
	Roger Pau Monné

From: Hongyan Xia <hongyxia@amazon.com>

The macro version UNMAP_DOMAIN_PAGE() does both NULL checking and
variable clearing. Move NULL checking into the function itself so that
the semantics is consistent with other similar constructs like XFREE().
This also eases the use unmap_domain_page() in error handling paths,
where we only care about NULL checking but not about variable clearing.

Signed-off-by: Hongyan Xia <hongyxia@amazon.com>
---
 xen/arch/arm/mm.c             | 3 +++
 xen/arch/x86/domain_page.c    | 2 +-
 xen/include/xen/domain_page.h | 7 ++-----
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index 727107eefa..1b14f49345 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -498,6 +498,9 @@ void unmap_domain_page(const void *va)
     lpae_t *map = this_cpu(xen_dommap);
     int slot = ((unsigned long) va - DOMHEAP_VIRT_START) >> SECOND_SHIFT;
 
+    if ( !va )
+        return;
+
     local_irq_save(flags);
 
     ASSERT(slot >= 0 && slot < DOMHEAP_ENTRIES);
diff --git a/xen/arch/x86/domain_page.c b/xen/arch/x86/domain_page.c
index dd32712d2f..b03728e18e 100644
--- a/xen/arch/x86/domain_page.c
+++ b/xen/arch/x86/domain_page.c
@@ -181,7 +181,7 @@ void unmap_domain_page(const void *ptr)
     unsigned long va = (unsigned long)ptr, mfn, flags;
     struct vcpu_maphash_entry *hashent;
 
-    if ( va >= DIRECTMAP_VIRT_START )
+    if ( !va || va >= DIRECTMAP_VIRT_START )
         return;
 
     ASSERT(va >= MAPCACHE_VIRT_START && va < MAPCACHE_VIRT_END);
diff --git a/xen/include/xen/domain_page.h b/xen/include/xen/domain_page.h
index ab2be7b719..a182d33b67 100644
--- a/xen/include/xen/domain_page.h
+++ b/xen/include/xen/domain_page.h
@@ -73,11 +73,8 @@ static inline void unmap_domain_page_global(const void *va) {};
 #endif /* !CONFIG_DOMAIN_PAGE */
 
 #define UNMAP_DOMAIN_PAGE(p) do {   \
-    if ( p )                        \
-    {                               \
-        unmap_domain_page(p);       \
-        (p) = NULL;                 \
-    }                               \
+    unmap_domain_page(p);           \
+    (p) = NULL;                     \
 } while ( false )
 
 #endif /* __XEN_DOMAIN_PAGE_H__ */
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] domain_page: handle NULL within unmap_domain_page() itself
  2020-05-13 15:43 [PATCH] domain_page: handle NULL within unmap_domain_page() itself Hongyan Xia
@ 2020-05-14 10:01 ` Wei Liu
  2020-05-14 13:11   ` Jan Beulich
  2020-05-15 18:06 ` Julien Grall
  1 sibling, 1 reply; 4+ messages in thread
From: Wei Liu @ 2020-05-14 10:01 UTC (permalink / raw)
  To: Hongyan Xia
  Cc: Stefano Stabellini, Julien Grall, Wei Liu, Andrew Cooper,
	Ian Jackson, George Dunlap, Jan Beulich, xen-devel,
	Volodymyr Babchuk, Roger Pau Monné

On Wed, May 13, 2020 at 04:43:33PM +0100, Hongyan Xia wrote:
> From: Hongyan Xia <hongyxia@amazon.com>
> 
> The macro version UNMAP_DOMAIN_PAGE() does both NULL checking and
> variable clearing. Move NULL checking into the function itself so that
> the semantics is consistent with other similar constructs like XFREE().
> This also eases the use unmap_domain_page() in error handling paths,
> where we only care about NULL checking but not about variable clearing.
> 
> Signed-off-by: Hongyan Xia <hongyxia@amazon.com>

Reviewed-by: Wei Liu <wl@xen.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] domain_page: handle NULL within unmap_domain_page() itself
  2020-05-14 10:01 ` Wei Liu
@ 2020-05-14 13:11   ` Jan Beulich
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Beulich @ 2020-05-14 13:11 UTC (permalink / raw)
  To: Hongyan Xia
  Cc: Stefano Stabellini, Julien Grall, Wei Liu, Andrew Cooper,
	Ian Jackson, George Dunlap, xen-devel, Volodymyr Babchuk,
	Roger Pau Monné

On 14.05.2020 12:01, Wei Liu wrote:
> On Wed, May 13, 2020 at 04:43:33PM +0100, Hongyan Xia wrote:
>> From: Hongyan Xia <hongyxia@amazon.com>
>>
>> The macro version UNMAP_DOMAIN_PAGE() does both NULL checking and
>> variable clearing. Move NULL checking into the function itself so that
>> the semantics is consistent with other similar constructs like XFREE().
>> This also eases the use unmap_domain_page() in error handling paths,
>> where we only care about NULL checking but not about variable clearing.
>>
>> Signed-off-by: Hongyan Xia <hongyxia@amazon.com>
> 
> Reviewed-by: Wei Liu <wl@xen.org>

Acked-by: Jan Beulich <jbeulich@suse.com>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] domain_page: handle NULL within unmap_domain_page() itself
  2020-05-13 15:43 [PATCH] domain_page: handle NULL within unmap_domain_page() itself Hongyan Xia
  2020-05-14 10:01 ` Wei Liu
@ 2020-05-15 18:06 ` Julien Grall
  1 sibling, 0 replies; 4+ messages in thread
From: Julien Grall @ 2020-05-15 18:06 UTC (permalink / raw)
  To: Hongyan Xia, xen-devel
  Cc: Stefano Stabellini, Wei Liu, Andrew Cooper, Ian Jackson,
	George Dunlap, Jan Beulich, Volodymyr Babchuk,
	Roger Pau Monné

Hi,

On 13/05/2020 16:43, Hongyan Xia wrote:
> From: Hongyan Xia <hongyxia@amazon.com>
> 
> The macro version UNMAP_DOMAIN_PAGE() does both NULL checking and
> variable clearing. Move NULL checking into the function itself so that
> the semantics is consistent with other similar constructs like XFREE().
> This also eases the use unmap_domain_page() in error handling paths,
> where we only care about NULL checking but not about variable clearing.
> 
> Signed-off-by: Hongyan Xia <hongyxia@amazon.com>

Acked-by: Julien Grall <jgrall@amazon.com>

Cheers,

> ---
>   xen/arch/arm/mm.c             | 3 +++
>   xen/arch/x86/domain_page.c    | 2 +-
>   xen/include/xen/domain_page.h | 7 ++-----
>   3 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
> index 727107eefa..1b14f49345 100644
> --- a/xen/arch/arm/mm.c
> +++ b/xen/arch/arm/mm.c
> @@ -498,6 +498,9 @@ void unmap_domain_page(const void *va)
>       lpae_t *map = this_cpu(xen_dommap);
>       int slot = ((unsigned long) va - DOMHEAP_VIRT_START) >> SECOND_SHIFT;
>   
> +    if ( !va )
> +        return;
> +
>       local_irq_save(flags);
>   
>       ASSERT(slot >= 0 && slot < DOMHEAP_ENTRIES);
> diff --git a/xen/arch/x86/domain_page.c b/xen/arch/x86/domain_page.c
> index dd32712d2f..b03728e18e 100644
> --- a/xen/arch/x86/domain_page.c
> +++ b/xen/arch/x86/domain_page.c
> @@ -181,7 +181,7 @@ void unmap_domain_page(const void *ptr)
>       unsigned long va = (unsigned long)ptr, mfn, flags;
>       struct vcpu_maphash_entry *hashent;
>   
> -    if ( va >= DIRECTMAP_VIRT_START )
> +    if ( !va || va >= DIRECTMAP_VIRT_START )
>           return;
>   
>       ASSERT(va >= MAPCACHE_VIRT_START && va < MAPCACHE_VIRT_END);
> diff --git a/xen/include/xen/domain_page.h b/xen/include/xen/domain_page.h
> index ab2be7b719..a182d33b67 100644
> --- a/xen/include/xen/domain_page.h
> +++ b/xen/include/xen/domain_page.h
> @@ -73,11 +73,8 @@ static inline void unmap_domain_page_global(const void *va) {};
>   #endif /* !CONFIG_DOMAIN_PAGE */
>   
>   #define UNMAP_DOMAIN_PAGE(p) do {   \
> -    if ( p )                        \
> -    {                               \
> -        unmap_domain_page(p);       \
> -        (p) = NULL;                 \
> -    }                               \
> +    unmap_domain_page(p);           \
> +    (p) = NULL;                     \
>   } while ( false )
>   
>   #endif /* __XEN_DOMAIN_PAGE_H__ */
> 

-- 
Julien Grall


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-05-15 18:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-13 15:43 [PATCH] domain_page: handle NULL within unmap_domain_page() itself Hongyan Xia
2020-05-14 10:01 ` Wei Liu
2020-05-14 13:11   ` Jan Beulich
2020-05-15 18:06 ` Julien Grall

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.