[PATCH] domain_page: handle NULL within unmap_domain_page() itself

Hongyan Xia posted 1 patch 23 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/xen tags/patchew/a3ddf0c755227a3c742f6b93783c576135a86874.1589384602.git.hongyxia@amazon.com
Maintainers: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>, Wei Liu <wl@xen.org>, Julien Grall <julien@xen.org>, Ian Jackson <ian.jackson@eu.citrix.com>, Jan Beulich <jbeulich@suse.com>, Stefano Stabellini <sstabellini@kernel.org>, Andrew Cooper <andrew.cooper3@citrix.com>, "Roger Pau Monné" <roger.pau@citrix.com>, George Dunlap <george.dunlap@citrix.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(-)

[PATCH] domain_page: handle NULL within unmap_domain_page() itself

Posted by Hongyan Xia 23 weeks ago
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


Re: [PATCH] domain_page: handle NULL within unmap_domain_page() itself

Posted by Julien Grall 22 weeks ago
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

Re: [PATCH] domain_page: handle NULL within unmap_domain_page() itself

Posted by Wei Liu 23 weeks ago
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>

Re: [PATCH] domain_page: handle NULL within unmap_domain_page() itself

Posted by Jan Beulich 23 weeks ago
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>