Skip to contentSkip to conversation

xen/arm: ioremap_attr: return NULL is __vmap failed

PATCH Superseded Julien Grall 4 participants 10 messages Nov 15, 2013 – Nov 19, 2013

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: ioremap_attr: return NULL is __vmap failed

Most of ioremap_* caller check if ioremap returns NULL. Actually, if the physical address is non-aligned, Xen will return the pointer given by __vmap plus the offset in the page. So if ioremap_* fails, the caller will retrieve an non-NULL address and continue as if there was no error.

---
 xen/arch/arm/mm.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
xen/arch/arm/mm.c +6 -1
index 26c6768..5137668 100644
@@ -742,8 +742,13 @@ void *ioremap_attr(paddr_t pa, size_t len, unsigned int attributes)
     unsigned long pfn = PFN_DOWN(pa);
     unsigned int offs = pa & (PAGE_SIZE - 1);
     unsigned int nr = PFN_UP(offs + len);
+    void *ptr;
 
-    return (__vmap(&pfn, nr, 1, 1, attributes) + offs);
+    ptr = __vmap(&pfn, nr, 1, 1, attributes);
+    if ( ptr == NULL )
+        return NULL;
+
+    return (ptr + offs);
 }
 
 void *ioremap(paddr_t pa, size_t len)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 xen/arm: Panic if platform initialization failed

Actually, if an error occurs, Xen will silently ignore it and continue. Convert platform_init to a void function and panic if we fail to correctly initialize the platform.

---
 xen/arch/arm/platform.c        | 5 +++--
 xen/include/asm-arm/platform.h | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)
xen/arch/arm/platform.c +3 -2
index db135f8..0fbbdc7 100644
@@ -54,7 +54,7 @@ static void dump_platform_table(void)
         printk("    - %s\n", p->name);
 }
 
-int __init platform_init(void)
+void __init platform_init(void)
 {
     int res = 0;
 
@@ -82,7 +82,8 @@ int __init platform_init(void)
     if ( platform && platform->init )
         res = platform->init();
 
-    return res;
+    if ( res )
+        panic("Unable to initialize the platform\n");
 }
 
 int __init platform_init_time(void)
xen/include/asm-arm/platform.h +1 -1
index 43afebb..c282b30 100644
@@ -45,7 +45,7 @@ struct platform_desc {
  */
 #define PLATFORM_QUIRK_DOM0_MAPPING_11 (1 << 0)
 
-int __init platform_init(void);
+void __init platform_init(void);
 int __init platform_init_time(void);
 int __init platform_specific_mapping(struct domain *d);
 #ifdef CONFIG_ARM_32
Signature · 1 line
1.8.3.1
Acked-by on v1 1/1
#2 lore raw

Re: [PATCH] xen/arm: Panic if platform initialization failed

Quoted 5 lines · Julien Grall

Actually, if an error occurs, Xen will silently ignore it and continue. Convert platform_init to a void function and panic if we fail to correctly initialize the platform.

Quoted 43 lines
 xen/arch/arm/platform.c        | 5 +++--
 xen/include/asm-arm/platform.h | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)
xen/arch/arm/platform.c +3 -2
index db135f8..0fbbdc7 100644
@@ -54,7 +54,7 @@ static void dump_platform_table(void)
         printk("    - %s\n", p->name);
 }
 
-int __init platform_init(void)
+void __init platform_init(void)
 {
     int res = 0;
 
@@ -82,7 +82,8 @@ int __init platform_init(void)
     if ( platform && platform->init )
         res = platform->init();
 
-    return res;
+    if ( res )
+        panic("Unable to initialize the platform\n");
 }
 
 int __init platform_init_time(void)
xen/include/asm-arm/platform.h +1 -1
index 43afebb..c282b30 100644
@@ -45,7 +45,7 @@ struct platform_desc {
  */
 #define PLATFORM_QUIRK_DOM0_MAPPING_11 (1 << 0)
 
-int __init platform_init(void);
+void __init platform_init(void);
 int __init platform_init_time(void);
 int __init platform_specific_mapping(struct domain *d);
 #ifdef CONFIG_ARM_32
Signature · 1 line
1.8.3.1
Acked-by
#3 lore raw

Re: [PATCH] xen/arm: Panic if platform initialization failed

Quoted 8 lines · Stefano Stabellini
Quoted 5 lines · Julien Grall

Actually, if an error occurs, Xen will silently ignore it and continue. Convert platform_init to a void function and panic if we fail to correctly initialize the platform.

/insert similar wanderings about pushing the panic down the stack.

#4 lore raw

PATCH 1/1 xen/arm: Panic if we are unable to initialize platform timer

In reply to Julien Grall

The caller of xen_init_time, start_xen, doesn't check the return value of the function. Xen will silently ignore the error and continue.

---
 xen/arch/arm/time.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/time.c +1 -1
index a30d422..938995d 100644
@@ -132,7 +132,7 @@ int __init init_xen_time(void)
 
     res = platform_init_time();
     if ( res )
-        return res;
+        panic("Timer: Cannot initialize platform timer\n");
 
     /* Check that this CPU supports the Generic Timer interface */
     if ( !cpu_has_gentimer )
Signature · 1 line
1.8.3.1
Acked-by on v1 1/1
#5 lore raw

Re: [PATCH] xen/arm: Panic if we are unable to initialize platform timer

Quoted 4 lines · Julien Grall

The caller of xen_init_time, start_xen, doesn't check the return value of the function. Xen will silently ignore the error and continue.

Quoted 19 lines
 xen/arch/arm/time.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/time.c +1 -1
index a30d422..938995d 100644
@@ -132,7 +132,7 @@ int __init init_xen_time(void)
 
     res = platform_init_time();
     if ( res )
-        return res;
+        panic("Timer: Cannot initialize platform timer\n");
 
     /* Check that this CPU supports the Generic Timer interface */
     if ( !cpu_has_gentimer )
Signature · 1 line
1.8.3.1
Acked-by
#6 lore raw

Re: [PATCH] xen/arm: Panic if we are unable to initialize platform timer

Quoted 7 lines · Stefano Stabellini
Quoted 4 lines · Julien Grall

The caller of xen_init_time, start_xen, doesn't check the return value of the function. Xen will silently ignore the error and continue.

I did wonder if it might be worth pushing the panic down into platform_time_init, so that the message could be more specific. But that seems like it relies on platform code to be more aware of when to panic and to use consistent wording etc. So all in all I think it is better here.

Quoted 21 lines
Quoted 21 lines

 xen/arch/arm/time.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/time.c +1 -1
index a30d422..938995d 100644
@@ -132,7 +132,7 @@ int __init init_xen_time(void)
 
     res = platform_init_time();
     if ( res )
-        return res;
+        panic("Timer: Cannot initialize platform timer\n");
 
     /* Check that this CPU supports the Generic Timer interface */
     if ( !cpu_has_gentimer )
Signature · 1 line
1.8.3.1
#7 lore raw

Re: [PATCH] xen/arm: Panic if we are unable to initialize platform timer

Quoted 9 lines · Ian Campbell
Quoted 7 lines · Stefano Stabellini
Quoted 4 lines · Julien Grall

The caller of xen_init_time, start_xen, doesn't check the return value of the function. Xen will silently ignore the error and continue.

Quoted 7 lines

I did wonder if it might be worth pushing the panic down into platform_time_init, so that the message could be more specific. But that seems like it relies on platform code to be more aware of when to panic and to use consistent wording etc. So all in all I think it is better here.

I thought about this solution. I didn't find good argument for one of these solutions. So, by default, I choose to panic in init_xen_time.

Signature · 1 line
Julien Grall
#8 lore raw
In reply to Julien Grall
Quoted 15 lines · Julien Grall

Most of ioremap_* caller check if ioremap returns NULL. Actually, if the physical address is non-aligned, Xen will return the pointer given by __vmap plus the offset in the page. So if ioremap_* fails, the caller will retrieve an non-NULL address and continue as if there was no error.

---
 xen/arch/arm/mm.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
xen/arch/arm/mm.c +0 -0
index 26c6768..5137668 100644

xen/arch/arm/mm.c void *ioremap_attr(paddr_t pa, size_t len, unsigned int attributes) · line 747

Quoted 7 lines
xen/arch/arm/mm.c +2 -1
@@ -742,8 +742,13 @@ void *ioremap_attr(paddr_t pa, size_t len, unsigned int attributes)
     unsigned long pfn = PFN_DOWN(pa);
     unsigned int offs = pa & (PAGE_SIZE - 1);
     unsigned int nr = PFN_UP(offs + len);
+    void *ptr;
 
-    return (__vmap(&pfn, nr, 1, 1, attributes) + offs);
+    ptr = __vmap(&pfn, nr, 1, 1, attributes);

No need to split the declaration of void *ptr and its initialisation.

~Andrew

Quoted 7 lines
xen/arch/arm/mm.c +4 -0
+    if ( ptr == NULL )
+        return NULL;
+
+    return (ptr + offs);
 }
 
 void *ioremap(paddr_t pa, size_t len)
Acked-by on v1 1/1
#9 lore raw
In reply to Julien Grall
Quoted 16 lines · Julien Grall

Most of ioremap_* caller check if ioremap returns NULL. Actually, if the physical address is non-aligned, Xen will return the pointer given by __vmap plus the offset in the page. So if ioremap_* fails, the caller will retrieve an non-NULL address and continue as if there was no error.

---
 xen/arch/arm/mm.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
xen/arch/arm/mm.c +0 -0
index 26c6768..5137668 100644
@@ -742,8 +742,13 @@ void *ioremap_attr(paddr_t pa, size_t len, unsigned int attributes)
     unsigned long pfn = PFN_DOWN(pa);

xen/arch/arm/mm.c void *ioremap_attr(paddr_t pa, size_t len, unsigned int attributes) · line 751

Quoted 10 lines
xen/arch/arm/mm.c +6 -1
     unsigned int offs = pa & (PAGE_SIZE - 1);
     unsigned int nr = PFN_UP(offs + len);
+    void *ptr;
 
-    return (__vmap(&pfn, nr, 1, 1, attributes) + offs);
+    ptr = __vmap(&pfn, nr, 1, 1, attributes);
+    if ( ptr == NULL )
+        return NULL;
+
+    return (ptr + offs);

No need for brackets here.

In any case