[Xen-devel] [PATCH] arm/gic: Make sense of assertions

Andrii Anisov posted 1 patch 4 years, 6 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/xen tags/patchew/1571133668-5875-1-git-send-email-andrii.anisov@gmail.com
xen/arch/arm/gic.c        | 6 +++---
xen/include/asm-arm/gic.h | 2 ++
2 files changed, 5 insertions(+), 3 deletions(-)
[Xen-devel] [PATCH] arm/gic: Make sense of assertions
Posted by Andrii Anisov 4 years, 6 months ago
From: Andrii Anisov <andrii_anisov@epam.com>

ARM Compiler complains about assertion conditions being always true,
because sgi is of enum type what has all its values under 16.
In order to preserve those asserts, specify the available SGI number
right in the enum and use it for the assertions. This also eliminates
nasty hardcoded values.

Signed-off-by: Andrii Anisov <andrii_anisov@epam.com>
---
 xen/arch/arm/gic.c        | 6 +++---
 xen/include/asm-arm/gic.h | 2 ++
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c
index 113655a..bf373d7 100644
--- a/xen/arch/arm/gic.c
+++ b/xen/arch/arm/gic.c
@@ -294,7 +294,7 @@ void __init gic_init(void)
 
 void send_SGI_mask(const cpumask_t *cpumask, enum gic_sgi sgi)
 {
-    ASSERT(sgi < 16); /* There are only 16 SGIs */
+    ASSERT(sgi < NUMBER_OF_GIC_SGIS);
 
     gic_hw_ops->send_SGI(sgi, SGI_TARGET_LIST, cpumask);
 }
@@ -306,14 +306,14 @@ void send_SGI_one(unsigned int cpu, enum gic_sgi sgi)
 
 void send_SGI_self(enum gic_sgi sgi)
 {
-    ASSERT(sgi < 16); /* There are only 16 SGIs */
+    ASSERT(sgi < NUMBER_OF_GIC_SGIS);
 
     gic_hw_ops->send_SGI(sgi, SGI_TARGET_SELF, NULL);
 }
 
 void send_SGI_allbutself(enum gic_sgi sgi)
 {
-   ASSERT(sgi < 16); /* There are only 16 SGIs */
+   ASSERT(sgi < NUMBER_OF_GIC_SGIS);
 
    gic_hw_ops->send_SGI(sgi, SGI_TARGET_OTHERS, NULL);
 }
diff --git a/xen/include/asm-arm/gic.h b/xen/include/asm-arm/gic.h
index 793d324..5b72388 100644
--- a/xen/include/asm-arm/gic.h
+++ b/xen/include/asm-arm/gic.h
@@ -280,6 +280,8 @@ enum gic_sgi {
     GIC_SGI_EVENT_CHECK = 0,
     GIC_SGI_DUMP_STATE  = 1,
     GIC_SGI_CALL_FUNCTION = 2,
+    /* There are only 16 SGIs */
+    NUMBER_OF_GIC_SGIS = 16
 };
 
 /* SGI irq mode types */
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH] arm/gic: Make sense of assertions
Posted by Julien Grall 4 years, 6 months ago
Hi,

On 10/15/19 11:01 AM, Andrii Anisov wrote:
> From: Andrii Anisov <andrii_anisov@epam.com>
> 
> ARM Compiler complains about assertion conditions being always true,
> because sgi is of enum type what has all its values under 16.
> In order to preserve those asserts, specify the available SGI number
> right in the enum and use it for the assertions. This also eliminates
> nasty hardcoded values.

To be honest, those ASSERTIONs are pointless. If we are really worry of 
enum gic_sgi to have more than 16 values, then it would be best to use a 
BUILD_BUG_ON(). So you can get a build failure if that's every happening.

Something like:

static void __init __maybe_unused build_assertions(void)
{
       BUILD_BUG_ON(GIC_SGI_MAX > NR_GIC_SGI);
}

enum
{
      /* Use for sanity check on the size of the enum */
      GIC_MAX_SGI;
}

Cheers,

-- 
Julien Grall

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH] arm/gic: Make sense of assertions
Posted by Andrii Anisov 4 years, 6 months ago
Hello,

On 15.10.19 14:08, Julien Grall wrote:
> To be honest, those ASSERTIONs are pointless.

I'd prefer to drop them.

-- 
Sincerely,
Andrii Anisov.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel