All of lore.kernel.org
 help / color / mirror / Atom feed
* [XEN PATCH] xen: fixed violations of MISRA C:2012 Rule 3.1
@ 2023-06-13  7:42 ` Nicola Vetrini
  0 siblings, 0 replies; 10+ messages in thread
From: nicola.vetrini @ 2023-06-12 16:10 UTC (permalink / raw)
  To: xen-devel; +Cc: Nicola Vetrini

From: Nicola Vetrini <nicola.vetrini@bugseng.com>

The xen sources contain several violations of Rule 3.1 from MISRA C:2012,
whose headline states:
"The character sequences '/*' and '//' shall not be used within a comment".

Most of the violations are due to the presence of links to webpages within
C-style comment blocks, such as:

xen/arch/arm/include/asm/smccc.h:37.1-41.3
/*
 * This file provides common defines for ARM SMC Calling Convention as
 * specified in
 * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html
 */

In this case, we propose to deviate all of these occurrences with a
project deviation to be captured by a tool configuration.

There are, however, a few other violations that do not fall under this
category, namely:

1. in file "xen/arch/arm/include/asm/arm64/flushtlb.h" we propose to
avoid the usage of a nested comment;
2. in file "xen/common/xmalloc_tlsf.c" we propose to substitute the
commented-out if statement with a "#if 0 .. #endif;
3. in file "xen/include/xen/atomic.h" and
"xen/drivers/passthrough/arm/smmu-v3.c" we propose to split the C-style
comment containing the nested comment into two doxygen comments, clearly
identifying the second as a code sample. This can then be captured with a
project deviation by a tool configuration.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
 xen/arch/arm/include/asm/arm64/flushtlb.h | 8 ++++----
 xen/common/xmalloc_tlsf.c                 | 7 ++++---
 xen/drivers/passthrough/arm/smmu-v3.c     | 9 ++++++---
 xen/include/xen/atomic.h                  | 5 ++++-
 4 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/xen/arch/arm/include/asm/arm64/flushtlb.h b/xen/arch/arm/include/asm/arm64/flushtlb.h
index 3a9092b814..90ac3f9809 100644
--- a/xen/arch/arm/include/asm/arm64/flushtlb.h
+++ b/xen/arch/arm/include/asm/arm64/flushtlb.h
@@ -4,10 +4,10 @@
 /*
  * Every invalidation operation use the following patterns:
  *
- * DSB ISHST        // Ensure prior page-tables updates have completed
- * TLBI...          // Invalidate the TLB
- * DSB ISH          // Ensure the TLB invalidation has completed
- * ISB              // See explanation below
+ * DSB ISHST        Ensure prior page-tables updates have completed
+ * TLBI...          Invalidate the TLB
+ * DSB ISH          Ensure the TLB invalidation has completed
+ * ISB              See explanation below
  *
  * ARM64_WORKAROUND_REPEAT_TLBI:
  * Modification of the translation table for a virtual address might lead to
diff --git a/xen/common/xmalloc_tlsf.c b/xen/common/xmalloc_tlsf.c
index 75bdf18c4e..ea6ec47a59 100644
--- a/xen/common/xmalloc_tlsf.c
+++ b/xen/common/xmalloc_tlsf.c
@@ -140,9 +140,10 @@ static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl)
         *fl = flsl(*r) - 1;
         *sl = (*r >> (*fl - MAX_LOG2_SLI)) - MAX_SLI;
         *fl -= FLI_OFFSET;
-        /*if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
-         *fl = *sl = 0;
-         */
+#if 0
+        if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
+        fl = *sl = 0;
+#endif
         *r &= ~t;
     }
 }
diff --git a/xen/drivers/passthrough/arm/smmu-v3.c b/xen/drivers/passthrough/arm/smmu-v3.c
index 720aa69ff2..b1c536e7d9 100644
--- a/xen/drivers/passthrough/arm/smmu-v3.c
+++ b/xen/drivers/passthrough/arm/smmu-v3.c
@@ -1045,15 +1045,18 @@ static int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain,
 	/*
 	 * Ensure that we've completed prior invalidation of the main TLBs
 	 * before we read 'nr_ats_masters' in case of a concurrent call to
-	 * arm_smmu_enable_ats():
+	 * arm_smmu_enable_ats().
+	 */
+	/**
+	 * Code sample: Ensures that we always see the incremented
+	 * 'nr_ats_masters' count if ATS was enabled at the PCI device before
+	 * completion of the TLBI.
 	 *
 	 *	// unmap()			// arm_smmu_enable_ats()
 	 *	TLBI+SYNC			atomic_inc(&nr_ats_masters);
 	 *	smp_mb();			[...]
 	 *	atomic_read(&nr_ats_masters);	pci_enable_ats() // writel()
 	 *
-	 * Ensures that we always see the incremented 'nr_ats_masters' count if
-	 * ATS was enabled at the PCI device before completion of the TLBI.
 	 */
 	smp_mb();
 	if (!atomic_read(&smmu_domain->nr_ats_masters))
diff --git a/xen/include/xen/atomic.h b/xen/include/xen/atomic.h
index 529213ebbb..829646dda0 100644
--- a/xen/include/xen/atomic.h
+++ b/xen/include/xen/atomic.h
@@ -71,7 +71,10 @@ static inline void _atomic_set(atomic_t *v, int i);
  * Returns the initial value in @v, hence succeeds when the return value
  * matches that of @old.
  *
- * Sample (tries atomic increment of v until the operation succeeds):
+ */
+/**
+ *
+ * Code sample: Tries atomic increment of v until the operation succeeds.
  *
  *  while(1)
  *  {
-- 
2.34.1



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

* Re: [XEN PATCH] xen: fixed violations of MISRA C:2012 Rule 3.1
  2023-06-13  7:42 ` Nicola Vetrini
  (?)
@ 2023-06-13  7:17 ` Jan Beulich
  -1 siblings, 0 replies; 10+ messages in thread
From: Jan Beulich @ 2023-06-13  7:17 UTC (permalink / raw)
  To: nicola.vetrini; +Cc: xen-devel

On 12.06.2023 18:10, nicola.vetrini@bugseng.com wrote:
> From: Nicola Vetrini <nicola.vetrini@bugseng.com>
> 
> The xen sources contain several violations of Rule 3.1 from MISRA C:2012,
> whose headline states:
> "The character sequences '/*' and '//' shall not be used within a comment".
> 
> Most of the violations are due to the presence of links to webpages within
> C-style comment blocks, such as:
> 
> xen/arch/arm/include/asm/smccc.h:37.1-41.3
> /*
>  * This file provides common defines for ARM SMC Calling Convention as
>  * specified in
>  * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html
>  */
> 
> In this case, we propose to deviate all of these occurrences with a
> project deviation to be captured by a tool configuration.

Here "propose" is appropriate in the description, as this is something
the patch does not do. Further down, however, you mean to describe what
the patch does, not what an eventual patch might do.

Somewhat similarly you don't want to use past tense in the title, as
that wants to describe what is being done, rather than describing a
patch that has already landed.

> There are, however, a few other violations that do not fall under this
> category, namely:
> 
> 1. in file "xen/arch/arm/include/asm/arm64/flushtlb.h" we propose to
> avoid the usage of a nested comment;
> 2. in file "xen/common/xmalloc_tlsf.c" we propose to substitute the
> commented-out if statement with a "#if 0 .. #endif;
> 3. in file "xen/include/xen/atomic.h" and
> "xen/drivers/passthrough/arm/smmu-v3.c" we propose to split the C-style
> comment containing the nested comment into two doxygen comments, clearly
> identifying the second as a code sample. This can then be captured with a
> project deviation by a tool configuration.

Finally I find the use of "we" somewhat suspicious. Who besides you is
it that you're talking about?

Also please don't forget to Cc relevant maintainers.

> --- a/xen/drivers/passthrough/arm/smmu-v3.c
> +++ b/xen/drivers/passthrough/arm/smmu-v3.c
> @@ -1045,15 +1045,18 @@ static int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain,
>  	/*
>  	 * Ensure that we've completed prior invalidation of the main TLBs
>  	 * before we read 'nr_ats_masters' in case of a concurrent call to
> -	 * arm_smmu_enable_ats():
> +	 * arm_smmu_enable_ats().
> +	 */
> +	/**
> +	 * Code sample: Ensures that we always see the incremented
> +	 * 'nr_ats_masters' count if ATS was enabled at the PCI device before
> +	 * completion of the TLBI.
>  	 *
>  	 *	// unmap()			// arm_smmu_enable_ats()
>  	 *	TLBI+SYNC			atomic_inc(&nr_ats_masters);
>  	 *	smp_mb();			[...]
>  	 *	atomic_read(&nr_ats_masters);	pci_enable_ats() // writel()
>  	 *
> -	 * Ensures that we always see the incremented 'nr_ats_masters' count if
> -	 * ATS was enabled at the PCI device before completion of the TLBI.
>  	 */
>  	smp_mb();
>  	if (!atomic_read(&smmu_domain->nr_ats_masters))

I don't really know this code, but the use of inner comments looks
unnecessary to me here. The same could e.g. be achieved by

	 *	unmap():			arm_smmu_enable_ats():
	 *	TLBI+SYNC			atomic_inc(&nr_ats_masters);
	 *	smp_mb();			[...]
	 *	atomic_read(&nr_ats_masters);	pci_enable_ats(); (i.e. writel())


and it would avoid the somewhat odd splitting of adjacent comments
(which then is at risk of someone later coming forward with a patch
re-combining them).

> --- a/xen/include/xen/atomic.h
> +++ b/xen/include/xen/atomic.h
> @@ -71,7 +71,10 @@ static inline void _atomic_set(atomic_t *v, int i);
>   * Returns the initial value in @v, hence succeeds when the return value
>   * matches that of @old.
>   *
> - * Sample (tries atomic increment of v until the operation succeeds):
> + */
> +/**
> + *
> + * Code sample: Tries atomic increment of v until the operation succeeds.
>   *
>   *  while(1)
>   *  {

Somewhat similarly here: I don't think the inner comment provides
much value, and could hence be dropped instead of splitting the comment.

Jan


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

* [XEN PATCH] xen: fixed violations of MISRA C:2012 Rule 3.1
@ 2023-06-13  7:42 ` Nicola Vetrini
  0 siblings, 0 replies; 10+ messages in thread
From: Nicola Vetrini @ 2023-06-13  7:42 UTC (permalink / raw)
  To: xen-devel
  Cc: consulting, Nicola Vetrini, Stefano Stabellini, Julien Grall,
	Bertrand Marquis, Volodymyr Babchuk, Andrew Cooper,
	George Dunlap, Jan Beulich, Wei Liu, Rahul Singh

The xen sources contain several violations of Rule 3.1 from MISRA C:2012,
whose headline states:
"The character sequences '/*' and '//' shall not be used within a comment".

Most of the violations are due to the presence of links to webpages within
C-style comment blocks, such as:

xen/arch/arm/include/asm/smccc.h:37.1-41.3
/*
 * This file provides common defines for ARM SMC Calling Convention as
 * specified in
 * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html
 */

In this case, we propose to deviate all of these occurrences with a
project deviation to be captured by a tool configuration.

There are, however, a few other violations that do not fall under this
category, namely:

1. in file "xen/arch/arm/include/asm/arm64/flushtlb.h" we propose to
avoid the usage of a nested comment;
2. in file "xen/common/xmalloc_tlsf.c" we propose to substitute the
commented-out if statement with a "#if 0 .. #endif;
3. in file "xen/include/xen/atomic.h" and
"xen/drivers/passthrough/arm/smmu-v3.c" we propose to split the C-style
comment containing the nested comment into two doxygen comments, clearly
identifying the second as a code sample. This can then be captured with a
project deviation by a tool configuration.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
Changes:
- Resending the patch with the right maintainers in CC.
---
 xen/arch/arm/include/asm/arm64/flushtlb.h | 8 ++++----
 xen/common/xmalloc_tlsf.c                 | 7 ++++---
 xen/drivers/passthrough/arm/smmu-v3.c     | 9 ++++++---
 xen/include/xen/atomic.h                  | 5 ++++-
 4 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/xen/arch/arm/include/asm/arm64/flushtlb.h b/xen/arch/arm/include/asm/arm64/flushtlb.h
index 3a9092b814..90ac3f9809 100644
--- a/xen/arch/arm/include/asm/arm64/flushtlb.h
+++ b/xen/arch/arm/include/asm/arm64/flushtlb.h
@@ -4,10 +4,10 @@
 /*
  * Every invalidation operation use the following patterns:
  *
- * DSB ISHST        // Ensure prior page-tables updates have completed
- * TLBI...          // Invalidate the TLB
- * DSB ISH          // Ensure the TLB invalidation has completed
- * ISB              // See explanation below
+ * DSB ISHST        Ensure prior page-tables updates have completed
+ * TLBI...          Invalidate the TLB
+ * DSB ISH          Ensure the TLB invalidation has completed
+ * ISB              See explanation below
  *
  * ARM64_WORKAROUND_REPEAT_TLBI:
  * Modification of the translation table for a virtual address might lead to
diff --git a/xen/common/xmalloc_tlsf.c b/xen/common/xmalloc_tlsf.c
index 75bdf18c4e..ea6ec47a59 100644
--- a/xen/common/xmalloc_tlsf.c
+++ b/xen/common/xmalloc_tlsf.c
@@ -140,9 +140,10 @@ static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl)
         *fl = flsl(*r) - 1;
         *sl = (*r >> (*fl - MAX_LOG2_SLI)) - MAX_SLI;
         *fl -= FLI_OFFSET;
-        /*if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
-         *fl = *sl = 0;
-         */
+#if 0
+        if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
+        fl = *sl = 0;
+#endif
         *r &= ~t;
     }
 }
diff --git a/xen/drivers/passthrough/arm/smmu-v3.c b/xen/drivers/passthrough/arm/smmu-v3.c
index 720aa69ff2..b1c536e7d9 100644
--- a/xen/drivers/passthrough/arm/smmu-v3.c
+++ b/xen/drivers/passthrough/arm/smmu-v3.c
@@ -1045,15 +1045,18 @@ static int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain,
 	/*
 	 * Ensure that we've completed prior invalidation of the main TLBs
 	 * before we read 'nr_ats_masters' in case of a concurrent call to
-	 * arm_smmu_enable_ats():
+	 * arm_smmu_enable_ats().
+	 */
+	/**
+	 * Code sample: Ensures that we always see the incremented
+	 * 'nr_ats_masters' count if ATS was enabled at the PCI device before
+	 * completion of the TLBI.
 	 *
 	 *	// unmap()			// arm_smmu_enable_ats()
 	 *	TLBI+SYNC			atomic_inc(&nr_ats_masters);
 	 *	smp_mb();			[...]
 	 *	atomic_read(&nr_ats_masters);	pci_enable_ats() // writel()
 	 *
-	 * Ensures that we always see the incremented 'nr_ats_masters' count if
-	 * ATS was enabled at the PCI device before completion of the TLBI.
 	 */
 	smp_mb();
 	if (!atomic_read(&smmu_domain->nr_ats_masters))
diff --git a/xen/include/xen/atomic.h b/xen/include/xen/atomic.h
index 529213ebbb..829646dda0 100644
--- a/xen/include/xen/atomic.h
+++ b/xen/include/xen/atomic.h
@@ -71,7 +71,10 @@ static inline void _atomic_set(atomic_t *v, int i);
  * Returns the initial value in @v, hence succeeds when the return value
  * matches that of @old.
  *
- * Sample (tries atomic increment of v until the operation succeeds):
+ */
+/**
+ *
+ * Code sample: Tries atomic increment of v until the operation succeeds.
  *
  *  while(1)
  *  {
-- 
2.34.1



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

* Re: [XEN PATCH] xen: fixed violations of MISRA C:2012 Rule 3.1
  2023-06-13  7:42 ` Nicola Vetrini
  (?)
  (?)
@ 2023-06-13  8:27 ` Jan Beulich
  2023-06-13  9:44   ` Julien Grall
  2023-06-13  9:56   ` nicola
  -1 siblings, 2 replies; 10+ messages in thread
From: Jan Beulich @ 2023-06-13  8:27 UTC (permalink / raw)
  To: Nicola Vetrini
  Cc: consulting, Stefano Stabellini, Julien Grall, Bertrand Marquis,
	Volodymyr Babchuk, Andrew Cooper, George Dunlap, Wei Liu,
	Rahul Singh, xen-devel

On 13.06.2023 09:42, Nicola Vetrini wrote:
> The xen sources contain several violations of Rule 3.1 from MISRA C:2012,
> whose headline states:
> "The character sequences '/*' and '//' shall not be used within a comment".
> 
> Most of the violations are due to the presence of links to webpages within
> C-style comment blocks, such as:
> 
> xen/arch/arm/include/asm/smccc.h:37.1-41.3
> /*
>  * This file provides common defines for ARM SMC Calling Convention as
>  * specified in
>  * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html
>  */
> 
> In this case, we propose to deviate all of these occurrences with a
> project deviation to be captured by a tool configuration.
> 
> There are, however, a few other violations that do not fall under this
> category, namely:
> 
> 1. in file "xen/arch/arm/include/asm/arm64/flushtlb.h" we propose to
> avoid the usage of a nested comment;
> 2. in file "xen/common/xmalloc_tlsf.c" we propose to substitute the
> commented-out if statement with a "#if 0 .. #endif;
> 3. in file "xen/include/xen/atomic.h" and
> "xen/drivers/passthrough/arm/smmu-v3.c" we propose to split the C-style
> comment containing the nested comment into two doxygen comments, clearly
> identifying the second as a code sample. This can then be captured with a
> project deviation by a tool configuration.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
> ---
> Changes:
> - Resending the patch with the right maintainers in CC.

But without otherwise addressing comments already given, afaics. One more
remark:

> --- a/xen/common/xmalloc_tlsf.c
> +++ b/xen/common/xmalloc_tlsf.c
> @@ -140,9 +140,10 @@ static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl)
>          *fl = flsl(*r) - 1;
>          *sl = (*r >> (*fl - MAX_LOG2_SLI)) - MAX_SLI;
>          *fl -= FLI_OFFSET;
> -        /*if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
> -         *fl = *sl = 0;
> -         */
> +#if 0
> +        if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
> +        fl = *sl = 0;

You want to get indentation right here, and you don't want to lose
the indirection on fl.

> +#endif
>          *r &= ~t;
>      }
>  }

If you split this to 4 patches, leaving the URL proposal in just
the cover letter, then I think this one change (with the adjustments)
could go in right away. Similarly I expect the arm64/flushtlb.h
change could be ack-ed right away by an Arm maintainer.

Jan


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

* Re: [XEN PATCH] xen: fixed violations of MISRA C:2012 Rule 3.1
  2023-06-13  8:27 ` Jan Beulich
@ 2023-06-13  9:44   ` Julien Grall
  2023-06-14 13:20     ` nicola
  2023-06-13  9:56   ` nicola
  1 sibling, 1 reply; 10+ messages in thread
From: Julien Grall @ 2023-06-13  9:44 UTC (permalink / raw)
  To: Jan Beulich, Nicola Vetrini
  Cc: consulting, Stefano Stabellini, Bertrand Marquis,
	Volodymyr Babchuk, Andrew Cooper, George Dunlap, Wei Liu,
	Rahul Singh, xen-devel

Hi,

On 13/06/2023 09:27, Jan Beulich wrote:
> On 13.06.2023 09:42, Nicola Vetrini wrote:
>> The xen sources contain several violations of Rule 3.1 from MISRA C:2012,
>> whose headline states:
>> "The character sequences '/*' and '//' shall not be used within a comment".
>>
>> Most of the violations are due to the presence of links to webpages within
>> C-style comment blocks, such as:
>>
>> xen/arch/arm/include/asm/smccc.h:37.1-41.3
>> /*
>>   * This file provides common defines for ARM SMC Calling Convention as
>>   * specified in
>>   * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html
>>   */
>>
>> In this case, we propose to deviate all of these occurrences with a
>> project deviation to be captured by a tool configuration.
>>
>> There are, however, a few other violations that do not fall under this
>> category, namely:
>>
>> 1. in file "xen/arch/arm/include/asm/arm64/flushtlb.h" we propose to
>> avoid the usage of a nested comment;
>> 2. in file "xen/common/xmalloc_tlsf.c" we propose to substitute the
>> commented-out if statement with a "#if 0 .. #endif;
>> 3. in file "xen/include/xen/atomic.h" and
>> "xen/drivers/passthrough/arm/smmu-v3.c" we propose to split the C-style
>> comment containing the nested comment into two doxygen comments, clearly
>> identifying the second as a code sample. This can then be captured with a
>> project deviation by a tool configuration.
>>
>> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
>> ---
>> Changes:
>> - Resending the patch with the right maintainers in CC.
> 
> But without otherwise addressing comments already given, afaics. One more
> remark:
> 
>> --- a/xen/common/xmalloc_tlsf.c
>> +++ b/xen/common/xmalloc_tlsf.c
>> @@ -140,9 +140,10 @@ static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl)
>>           *fl = flsl(*r) - 1;
>>           *sl = (*r >> (*fl - MAX_LOG2_SLI)) - MAX_SLI;
>>           *fl -= FLI_OFFSET;
>> -        /*if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
>> -         *fl = *sl = 0;
>> -         */
>> +#if 0
>> +        if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
>> +        fl = *sl = 0;
> 
> You want to get indentation right here, and you don't want to lose
> the indirection on fl.
> 
>> +#endif
>>           *r &= ~t;
>>       }
>>   }
> 
> If you split this to 4 patches, leaving the URL proposal in just
> the cover letter, then I think this one change (with the adjustments)
> could go in right away. Similarly I expect the arm64/flushtlb.h
> change could be ack-ed right away by an Arm maintainer.

I actually dislike the proposal. In this case, the code is meant to look 
like assembly code. I would replace the // with ;. Also, I would like to 
keep the comment style in sync in arm32/flushtlb.h. So can this be 
updated as well?

Cheers,

-- 
Julien Grall


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

* Re: [XEN PATCH] xen: fixed violations of MISRA C:2012 Rule 3.1
  2023-06-13  8:27 ` Jan Beulich
  2023-06-13  9:44   ` Julien Grall
@ 2023-06-13  9:56   ` nicola
  2023-06-13 10:06     ` Jan Beulich
  1 sibling, 1 reply; 10+ messages in thread
From: nicola @ 2023-06-13  9:56 UTC (permalink / raw)
  To: xen-devel

[-- Attachment #1: Type: text/plain, Size: 3189 bytes --]


On 13/06/23 10:27, Jan Beulich wrote:

> On 13.06.2023 09:42, Nicola Vetrini wrote:
>> --- a/xen/common/xmalloc_tlsf.c
>> +++ b/xen/common/xmalloc_tlsf.c
>> @@ -140,9 +140,10 @@ static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl)
>>           *fl = flsl(*r) - 1;
>>           *sl = (*r >> (*fl - MAX_LOG2_SLI)) - MAX_SLI;
>>           *fl -= FLI_OFFSET;
>> -        /*if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
>> -         *fl = *sl = 0;
>> -         */
>> +#if 0
>> +        if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
>> +        fl = *sl = 0;
> You want to get indentation right here, and you don't want to lose
> the indirection on fl.

Understood.


>> +#endif
>>           *r &= ~t;
>>       }
>>   }
> If you split this to 4 patches, leaving the URL proposal in just
> the cover letter, then I think this one change (with the adjustments)
> could go in right away. Similarly I expect the arm64/flushtlb.h
> change could be ack-ed right away by an Arm maintainer.
Ok. I do not understand what you mean by "leaving the URL proposal in 
just the cover letter". Which URL?



I'm sorry, I didn't notice your previous reply. I'm going to address 
your observations now:

> Here "propose" is appropriate in the description, as this is something 
> the patch does not do. Further down, however, you mean to describe 
> what the patch does, not what an eventual patch might do.
>
To my knowledge, there is not a standard format to define a project 
deviation for a certain MISRA rule in Xen right now (this can also be 
discussed in a separate thread). To clarify, I meant to describe why I 
wasn't addressing these violations in the patch (they are the vast 
majority, but they do not have any implication w.r.t. functional safety 
and can therefore be safely deviated with an appropriate written 
justification).


> Somewhat similarly you don't want to use past tense in the title, as
> that wants to describe what is being done, rather than describing a
> patch that has already landed.

Understood.


> and it would avoid the somewhat odd splitting of adjacent comments
> (which then is at risk of someone later coming forward with a patch
> re-combining them).
>
> >/--- a/xen/include/xen/atomic.h/
> >/+++ b/xen/include/xen/atomic.h/
> >/@@ -71,7 +71,10 @@ static inline void _atomic_set(atomic_t *v, int i);/
> >/* Returns the initial value in @v, hence succeeds when the return value/
> >/* matches that of @old./
> >/*/
> >/- * Sample (tries atomic increment of v until the operation succeeds):/
> >/+ *//
> >/+/**/
> >/+ */
> >/+ * Code sample: Tries atomic increment of v until the operation 
> succeeds./
> >/*/
> >/* while(1)/
> >/* {/
>
> Somewhat similarly here: I don't think the inner comment provides
> much value, and could hence be dropped instead of splitting the comment.

The rationale behind these modifications was to separate clearly 
comments and code samples, so that the latter can be easily deviated by 
tool configurations. I'm ok with the suggestion of removing the nested 
comments, and otherwise leave the code as is, but i'll probably do this 
by splitting the patch as you suggested above.

Regards,

   Nicola

[-- Attachment #2: Type: text/html, Size: 4505 bytes --]

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

* Re: [XEN PATCH] xen: fixed violations of MISRA C:2012 Rule 3.1
  2023-06-13  9:56   ` nicola
@ 2023-06-13 10:06     ` Jan Beulich
  0 siblings, 0 replies; 10+ messages in thread
From: Jan Beulich @ 2023-06-13 10:06 UTC (permalink / raw)
  To: nicola; +Cc: xen-devel

First of all - please don't drop Cc-s when replying, unless you have a
specific reason to.

On 13.06.2023 11:56, nicola wrote:
> On 13/06/23 10:27, Jan Beulich wrote:
>> If you split this to 4 patches, leaving the URL proposal in just
>> the cover letter, then I think this one change (with the adjustments)
>> could go in right away. Similarly I expect the arm64/flushtlb.h
>> change could be ack-ed right away by an Arm maintainer.
> Ok. I do not understand what you mean by "leaving the URL proposal in 
> just the cover letter". Which URL?

In your description you had a proposal to deviate the // occurring
in URLs. The latest when splitting the patch, this doesn't belong
into any of the patches anymore, but just in the cover letter.

>> Here "propose" is appropriate in the description, as this is something 
>> the patch does not do. Further down, however, you mean to describe 
>> what the patch does, not what an eventual patch might do.
>>
> To my knowledge, there is not a standard format to define a project 
> deviation for a certain MISRA rule in Xen right now (this can also be 
> discussed in a separate thread). To clarify, I meant to describe why I 
> wasn't addressing these violations in the patch (they are the vast 
> majority, but they do not have any implication w.r.t. functional safety 
> and can therefore be safely deviated with an appropriate written 
> justification).

And as said, for what you're not doing in the patch, using "propose"
is quite fine (as per above, whether that actually belongs in the
description is another question). I view the word as inapplicable
though when you describe what you're actually doing in a patch. But
I'm not a native speaker, so I may be wrong here.

Jan


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

* Re: [XEN PATCH] xen: fixed violations of MISRA C:2012 Rule 3.1
  2023-06-13  9:44   ` Julien Grall
@ 2023-06-14 13:20     ` nicola
  0 siblings, 0 replies; 10+ messages in thread
From: nicola @ 2023-06-14 13:20 UTC (permalink / raw)
  To: Julien Grall, Jan Beulich
  Cc: consulting, Stefano Stabellini, Bertrand Marquis,
	Volodymyr Babchuk, Andrew Cooper, George Dunlap, Wei Liu,
	Rahul Singh, xen-devel


On 13/06/23 11:44, Julien Grall wrote:
> Hi,
>
> On 13/06/2023 09:27, Jan Beulich wrote:
>> On 13.06.2023 09:42, Nicola Vetrini wrote:
>>> The xen sources contain several violations of Rule 3.1 from MISRA 
>>> C:2012,
>>> whose headline states:
>>> "The character sequences '/*' and '//' shall not be used within a 
>>> comment".
>>>
>>> Most of the violations are due to the presence of links to webpages 
>>> within
>>> C-style comment blocks, such as:
>>>
>>> xen/arch/arm/include/asm/smccc.h:37.1-41.3
>>> /*
>>>   * This file provides common defines for ARM SMC Calling Convention as
>>>   * specified in
>>>   * 
>>> http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html
>>>   */
>>>
>>> In this case, we propose to deviate all of these occurrences with a
>>> project deviation to be captured by a tool configuration.
>>>
>>> There are, however, a few other violations that do not fall under this
>>> category, namely:
>>>
>>> 1. in file "xen/arch/arm/include/asm/arm64/flushtlb.h" we propose to
>>> avoid the usage of a nested comment;
>>> 2. in file "xen/common/xmalloc_tlsf.c" we propose to substitute the
>>> commented-out if statement with a "#if 0 .. #endif;
>>> 3. in file "xen/include/xen/atomic.h" and
>>> "xen/drivers/passthrough/arm/smmu-v3.c" we propose to split the C-style
>>> comment containing the nested comment into two doxygen comments, 
>>> clearly
>>> identifying the second as a code sample. This can then be captured 
>>> with a
>>> project deviation by a tool configuration.
>>>
>>> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
>>> ---
>>> Changes:
>>> - Resending the patch with the right maintainers in CC.
>>
>> But without otherwise addressing comments already given, afaics. One 
>> more
>> remark:
>>
>>> --- a/xen/common/xmalloc_tlsf.c
>>> +++ b/xen/common/xmalloc_tlsf.c
>>> @@ -140,9 +140,10 @@ static inline void MAPPING_SEARCH(unsigned long 
>>> *r, int *fl, int *sl)
>>>           *fl = flsl(*r) - 1;
>>>           *sl = (*r >> (*fl - MAX_LOG2_SLI)) - MAX_SLI;
>>>           *fl -= FLI_OFFSET;
>>> -        /*if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
>>> -         *fl = *sl = 0;
>>> -         */
>>> +#if 0
>>> +        if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
>>> +        fl = *sl = 0;
>>
>> You want to get indentation right here, and you don't want to lose
>> the indirection on fl.
>>
>>> +#endif
>>>           *r &= ~t;
>>>       }
>>>   }
>>
>> If you split this to 4 patches, leaving the URL proposal in just
>> the cover letter, then I think this one change (with the adjustments)
>> could go in right away. Similarly I expect the arm64/flushtlb.h
>> change could be ack-ed right away by an Arm maintainer.
>
> I actually dislike the proposal. In this case, the code is meant to 
> look like assembly code. I would replace the // with ;. Also, I would 
> like to keep the comment style in sync in arm32/flushtlb.h. So can 
> this be updated as well?
>
> Cheers,
>
Hi, Julien.

I'm not authorized to send patches about files in the arm32 tree, but 
surely the patch can be easily replicated in any place where it makes 
sense for consistency.

Regards,

   Nicola



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

* Re: [XEN PATCH] xen: fixed violations of MISRA C:2012 Rule 3.1
  2023-06-13  7:42 ` Nicola Vetrini
                   ` (2 preceding siblings ...)
  (?)
@ 2023-06-14 14:28 ` Andrew Cooper
  2023-06-14 15:05   ` Jan Beulich
  -1 siblings, 1 reply; 10+ messages in thread
From: Andrew Cooper @ 2023-06-14 14:28 UTC (permalink / raw)
  To: Nicola Vetrini, xen-devel
  Cc: consulting, Stefano Stabellini, Julien Grall, Bertrand Marquis,
	Volodymyr Babchuk, George Dunlap, Jan Beulich, Wei Liu,
	Rahul Singh

On 13/06/2023 8:42 am, Nicola Vetrini wrote:
> diff --git a/xen/common/xmalloc_tlsf.c b/xen/common/xmalloc_tlsf.c
> index 75bdf18c4e..ea6ec47a59 100644
> --- a/xen/common/xmalloc_tlsf.c
> +++ b/xen/common/xmalloc_tlsf.c
> @@ -140,9 +140,10 @@ static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl)
>          *fl = flsl(*r) - 1;
>          *sl = (*r >> (*fl - MAX_LOG2_SLI)) - MAX_SLI;
>          *fl -= FLI_OFFSET;
> -        /*if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
> -         *fl = *sl = 0;
> -         */
> +#if 0
> +        if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
> +        fl = *sl = 0;
> +#endif
>          *r &= ~t;
>      }
>  }

This logic has been commented out right from it's introduction in c/s
9736b76d829b2d in 2008, and never touched since.

I think it can safely be deleted, and not placed inside an #if 0.

~Andrew


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

* Re: [XEN PATCH] xen: fixed violations of MISRA C:2012 Rule 3.1
  2023-06-14 14:28 ` Andrew Cooper
@ 2023-06-14 15:05   ` Jan Beulich
  0 siblings, 0 replies; 10+ messages in thread
From: Jan Beulich @ 2023-06-14 15:05 UTC (permalink / raw)
  To: Andrew Cooper
  Cc: consulting, Stefano Stabellini, Julien Grall, Bertrand Marquis,
	Volodymyr Babchuk, George Dunlap, Wei Liu, Rahul Singh,
	xen-devel, Nicola Vetrini

On 14.06.2023 16:28, Andrew Cooper wrote:
> On 13/06/2023 8:42 am, Nicola Vetrini wrote:
>> diff --git a/xen/common/xmalloc_tlsf.c b/xen/common/xmalloc_tlsf.c
>> index 75bdf18c4e..ea6ec47a59 100644
>> --- a/xen/common/xmalloc_tlsf.c
>> +++ b/xen/common/xmalloc_tlsf.c
>> @@ -140,9 +140,10 @@ static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl)
>>          *fl = flsl(*r) - 1;
>>          *sl = (*r >> (*fl - MAX_LOG2_SLI)) - MAX_SLI;
>>          *fl -= FLI_OFFSET;
>> -        /*if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
>> -         *fl = *sl = 0;
>> -         */
>> +#if 0
>> +        if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
>> +        fl = *sl = 0;
>> +#endif
>>          *r &= ~t;
>>      }
>>  }
> 
> This logic has been commented out right from it's introduction in c/s
> 9736b76d829b2d in 2008, and never touched since.
> 
> I think it can safely be deleted, and not placed inside an #if 0.

I have to admit that I wouldn't be happy with deleting without any
replacement. Instead of the commented out code, how about instead
having ASSERT(*fl >= 0)? (What isn't clear to me is whether the
commented out code is actually meant to replace the earlier line,
rather than (optionally) be there in addition - at least it very
much looks like so. With such an uncertainty I'd be further
inclined to not remove what's there.)

Jan


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

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

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-12 16:10 [XEN PATCH] xen: fixed violations of MISRA C:2012 Rule 3.1 nicola.vetrini
2023-06-13  7:42 ` Nicola Vetrini
2023-06-13  7:17 ` Jan Beulich
2023-06-13  8:27 ` Jan Beulich
2023-06-13  9:44   ` Julien Grall
2023-06-14 13:20     ` nicola
2023-06-13  9:56   ` nicola
2023-06-13 10:06     ` Jan Beulich
2023-06-14 14:28 ` Andrew Cooper
2023-06-14 15:05   ` Jan Beulich

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.