Skip to contentSkip to conversation

Fix MISRA C 2012 violations

PATCH Superseded Xenia Ragiadakou 4 participants 32 messages Jul 5, 2022 – Jul 28, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Fix MISRA C 2012 violations

Resolve MISRA C 2012 Rule 8.4 violation warnings.

Xenia Ragiadakou (4):
xen/arm: traps: Fix MISRA C 2012 Rule 8.4 violations xen/common: time: Fix MISRA C 2012 Rule 8.7 violation xen/arm: domain: Fix MISRA C 2012 Rule 8.7 violation xen/char: pv_console: Fix MISRA C 2012 Rule 8.4 violation

 xen/arch/arm/domain.c                |  2 +-
 xen/arch/arm/include/asm/processor.h | 14 ++++++++++++++
 xen/common/time.c                    |  2 +-
 xen/include/xen/pv_console.h         |  2 +-
 4 files changed, 17 insertions(+), 3 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/4 xen/arm: traps: Fix MISRA C 2012 Rule 8.4 violations

Add the function prototypes of the functions below in <asm/processor.h> header file so that they are visible before the function definitions in traps.c. enter_hypervisor_from_guest_preirq() enter_hypervisor_from_guest()
do_trap_hyp_sync()
do_trap_guest_sync()
do_trap_irq()
do_trap_fiq()
leave_hypervisor_to_guest()

---
 xen/arch/arm/include/asm/processor.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
xen/arch/arm/include/asm/processor.h +14 -0
index c021160412..74cc07028f 100644
@@ -576,10 +576,24 @@ void vcpu_regs_hyp_to_user(const struct vcpu *vcpu,
 void vcpu_regs_user_to_hyp(struct vcpu *vcpu,
                            const struct vcpu_guest_core_regs *regs);
 
+void enter_hypervisor_from_guest_preirq(void);
+
+void enter_hypervisor_from_guest(void);
+
+void do_trap_hyp_sync(struct cpu_user_regs *regs);
+
+void do_trap_guest_sync(struct cpu_user_regs *regs);
+
 void do_trap_hyp_serror(struct cpu_user_regs *regs);
 
 void do_trap_guest_serror(struct cpu_user_regs *regs);
 
+void do_trap_irq(struct cpu_user_regs *regs);
+
+void do_trap_fiq(struct cpu_user_regs *regs);
+
+void leave_hypervisor_to_guest(void);
+
 register_t get_default_hcr_flags(void);
 
 /*
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/4] xen/arm: traps: Fix MISRA C 2012 Rule 8.4 violations

Hi Xenia,

Quoted 9 lines · Xenia Ragiadakou

Add the function prototypes of the functions below in <asm/processor.h> header file so that they are visible before the function definitions in traps.c. enter_hypervisor_from_guest_preirq() enter_hypervisor_from_guest()
do_trap_hyp_sync()
do_trap_guest_sync()
do_trap_irq()
do_trap_fiq()
leave_hypervisor_to_guest()

I have actually came across those missing prototypes in the past and I have refrained to add them because they are not meant to be called from C.

While I agree this is a violation of Misra C, I am still not convinced they should be added (there is no need to verify the prototype).

So IMHO, they should be marked as deviation.

Cheers,

Signature · 1 line
Julien Grall
#3 lore raw

Re: [PATCH 1/4] xen/arm: traps: Fix MISRA C 2012 Rule 8.4 violations

Hi Julien,

Quoted 13 lines · Julien Grall

Hi Xenia,

Quoted 9 lines · Xenia Ragiadakou

Add the function prototypes of the functions below in <asm/processor.h> header file so that they are visible before the function definitions in traps.c. enter_hypervisor_from_guest_preirq() enter_hypervisor_from_guest()
do_trap_hyp_sync()
do_trap_guest_sync()
do_trap_irq()
do_trap_fiq()
leave_hypervisor_to_guest()

Quoted 3 lines

I have actually came across those missing prototypes in the past and I have refrained to add them because they are not meant to be called from C.

While I agree this is a violation of Misra C, I am still not convinced they should be added (there is no need to verify the prototype).

Yes, there is no need. Here, I decided to follow the example of do_trap_hyp_serror() and do_trap_guest_serror() for consistency.

Quoted 5 lines

So IMHO, they should be marked as deviation.

Cheers,

Signature · 1 line
Xenia
#4 lore raw

Re: [PATCH 1/4] xen/arm: traps: Fix MISRA C 2012 Rule 8.4 violations

Hi Xenia,

Quoted 14 lines · Xenia Ragiadakou
Quoted 13 lines · Julien Grall

Hi Xenia,

Quoted 9 lines · Xenia Ragiadakou

Add the function prototypes of the functions below in <asm/processor.h> header file so that they are visible before the function definitions in traps.c. enter_hypervisor_from_guest_preirq() enter_hypervisor_from_guest()
do_trap_hyp_sync()
do_trap_guest_sync()
do_trap_irq()
do_trap_fiq()
leave_hypervisor_to_guest()

Quoted 5 lines
Quoted 3 lines

I have actually came across those missing prototypes in the past and I have refrained to add them because they are not meant to be called from C.

While I agree this is a violation of Misra C, I am still not convinced they should be added (there is no need to verify the prototype).

Yes, there is no need. Here, I decided to follow the example of do_trap_hyp_serror() and do_trap_guest_serror() for consistency.

do_trap_guest_serror() is called from C code (see arch/arm32/traps.c).

do_trap_hyp_serror() is called only from assembly. I would argue that if you want consistency, then you should drop the prototype rather than modifying 90% of the other examples.

Otherwise, this is not really consistency but more a design choice (you want to be fully compliant with MISRA).

Cheers,

Signature · 1 line
Julien Grall
#5 lore raw

Re: [PATCH 1/4] xen/arm: traps: Fix MISRA C 2012 Rule 8.4 violations

Quoted 28 lines · Julien Grall

Hi Xenia,

Quoted 16 lines · Xenia Ragiadakou
Quoted 15 lines · Julien Grall

Hi Xenia,

Quoted 11 lines · Xenia Ragiadakou

Add the function prototypes of the functions below in <asm/processor.h> header
file so that they are visible before the function definitions in traps.c.
enter_hypervisor_from_guest_preirq() enter_hypervisor_from_guest()
do_trap_hyp_sync()
do_trap_guest_sync()
do_trap_irq()
do_trap_fiq()
leave_hypervisor_to_guest()

Quoted 8 lines
Quoted 5 lines

I have actually came across those missing prototypes in the past and I have refrained to add them because they are not meant to be called from C.

While I agree this is a violation of Misra C, I am still not convinced they should be added (there is no need to verify the prototype).

Yes, there is no need. Here, I decided to follow the example of do_trap_hyp_serror() and do_trap_guest_serror() for consistency.

Quoted 8 lines

do_trap_guest_serror() is called from C code (see arch/arm32/traps.c).

do_trap_hyp_serror() is called only from assembly. I would argue that if you want consistency, then you should drop the prototype rather than modifying 90% of the other examples.

Otherwise, this is not really consistency but more a design choice (you want to be fully compliant with MISRA).

Actually I am not sure that MISRA requires prototypes for assembly functions only meant to be called from assembly. I think MISRA requires detailed docs for anything assembly, but I don't think it requires C prototypes for all assembly functions.

So I think we could skip them for now. At some point we'll discuss what we need to do for the assembly code but we haven't tackled that yet.

#6 lore raw

Re: [PATCH 1/4] xen/arm: traps: Fix MISRA C 2012 Rule 8.4 violations

In reply to Julien Grall

Hi Julien,

Quoted 15 lines · Julien Grall
Quoted 14 lines · Xenia Ragiadakou
Quoted 13 lines · Julien Grall

Hi Xenia,

Quoted 9 lines · Xenia Ragiadakou

Add the function prototypes of the functions below in <asm/processor.h> header file so that they are visible before the function definitions in traps.c. enter_hypervisor_from_guest_preirq() enter_hypervisor_from_guest()
do_trap_hyp_sync()
do_trap_guest_sync()
do_trap_irq()
do_trap_fiq()
leave_hypervisor_to_guest()

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

I have actually came across those missing prototypes in the past and I have refrained to add them because they are not meant to be called from C.

While I agree this is a violation of Misra C, I am still not convinced they should be added (there is no need to verify the prototype).

Yes, there is no need. Here, I decided to follow the example of do_trap_hyp_serror() and do_trap_guest_serror() for consistency.

do_trap_guest_serror() is called from C code (see arch/arm32/traps.c).

You are right, my mistake.

Quoted 4 lines

do_trap_hyp_serror() is called only from assembly. I would argue that if you want consistency, then you should drop the prototype rather than modifying 90% of the other examples.

Otherwise, this is not really consistency but more a design choice (you want to be fully compliant with MISRA).

I agree with you that there is no need to declare the variables and functions that are called only from assembly, prior to their definitions. So, this kind of violations could be grouped together and provide a formal deviation. This seems to me reasonable.

Signature · 1 line
Xenia
#7 lore raw

PATCH 2/4 xen/common: time: Fix MISRA C 2012 Rule 8.7 violation

In reply to Xenia Ragiadakou

The variable __mon_lengths is referenced only in time.c. Change its linkage from external to internal by adding the storage-class specifier static to its definitions.

Also, this patch resolves indirectly a MISRA C 2012 Rule 8.4 violation warning.

---
 xen/common/time.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/time.c +1 -1
index 22379f4ae2..92f7b72464 100644
@@ -28,7 +28,7 @@
   ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
 
 /* How many days are in each month.  */
-const unsigned short int __mon_lengths[2][12] = {
+static const unsigned short int __mon_lengths[2][12] = {
     /* Normal years.  */
     {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
     /* Leap years.  */
Signature · 1 line
2.34.1
Acked-by on v1 2/4
#8 lore raw

Re: [PATCH 2/4] xen/common: time: Fix MISRA C 2012 Rule 8.7 violation

Hi Xenia,

Quoted 7 lines · Xenia Ragiadakou

The variable __mon_lengths is referenced only in time.c. Change its linkage from external to internal by adding the storage-class specifier static to its definitions.

Also, this patch resolves indirectly a MISRA C 2012 Rule 8.4 violation warning.

Cheers,

Quoted 17 lines
---
  xen/common/time.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/time.c +1 -1
index 22379f4ae2..92f7b72464 100644
@@ -28,7 +28,7 @@
    ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
 
  /* How many days are in each month.  */
-const unsigned short int __mon_lengths[2][12] = {
+static const unsigned short int __mon_lengths[2][12] = {
      /* Normal years.  */
      {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
      /* Leap years.  */
Signature · 1 line
Julien Grall
#9 lore raw

PATCH 3/4 xen/arm: domain: Fix MISRA C 2012 Rule 8.7 violation

In reply to Xenia Ragiadakou

The function idle_loop() is referenced only in domain.c. Change its linkage from external to internal by adding the storage-class specifier static to its definitions.

Since idle_loop() is referenced only in inline assembly, add the 'used' attribute to suppress unused-function compiler warning.

Also, this patch resolves indirectly a MISRA C 2012 Rule 8.4 violation warning.

---
 xen/arch/arm/domain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/domain.c +1 -1
index 2f8eaab7b5..2fa67266d0 100644
@@ -63,7 +63,7 @@ static void do_idle(void)
     rcu_idle_exit(cpu);
 }
 
-void idle_loop(void)
+static __used void idle_loop(void)
 {
     unsigned int cpu = smp_processor_id();
 
Signature · 1 line
2.34.1
Acked-by on v1 3/4
#10 lore raw

Re: [PATCH 3/4] xen/arm: domain: Fix MISRA C 2012 Rule 8.7 violation

Hi Xenia,

Quoted 10 lines · Xenia Ragiadakou

The function idle_loop() is referenced only in domain.c. Change its linkage from external to internal by adding the storage-class specifier static to its definitions.

Since idle_loop() is referenced only in inline assembly, add the 'used' attribute to suppress unused-function compiler warning.

Also, this patch resolves indirectly a MISRA C 2012 Rule 8.4 violation warning.

Cheers,

Quoted 17 lines
---
  xen/arch/arm/domain.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/domain.c +1 -1
index 2f8eaab7b5..2fa67266d0 100644
@@ -63,7 +63,7 @@ static void do_idle(void)
      rcu_idle_exit(cpu);
  }
 
-void idle_loop(void)
+static __used void idle_loop(void)
  {
      unsigned int cpu = smp_processor_id();
 
Signature · 1 line
Julien Grall
#11 lore raw

Re: [PATCH 3/4] xen/arm: domain: Fix MISRA C 2012 Rule 8.7 violation

In reply to Xenia Ragiadakou
Quoted 6 lines · Xenia Ragiadakou

The function idle_loop() is referenced only in domain.c. Change its linkage from external to internal by adding the storage-class specifier static to its definitions.

Since idle_loop() is referenced only in inline assembly, add the 'used' attribute to suppress unused-function compiler warning.

While I see that Julien has already acked the patch, I'd like to point out that using __used here is somewhat bogus. Imo the better approach is to properly make visible to the compiler that the symbol is used by the asm(), by adding a fake(?) input.

Jan

#12 lore raw

Re: [PATCH 3/4] xen/arm: domain: Fix MISRA C 2012 Rule 8.7 violation

Hi Jan,

Quoted 5 lines · Jan Beulich
Quoted 4 lines · Xenia Ragiadakou

The function idle_loop() is referenced only in domain.c. Change its linkage from external to internal by adding the storage-class specifier static to its definitions.

Quoted 7 lines
Quoted 2 lines

Since idle_loop() is referenced only in inline assembly, add the 'used' attribute to suppress unused-function compiler warning.

While I see that Julien has already acked the patch, I'd like to point out that using __used here is somewhat bogus. Imo the better approach is to properly make visible to the compiler that the symbol is used by the asm(), by adding a fake(?) input.

I 'm afraid I do not understand what do you mean by "adding a fake(?) input". Can you please elaborate a little on your suggestion?

Signature · 1 line
Xenia
#13 lore raw

Re: [PATCH 3/4] xen/arm: domain: Fix MISRA C 2012 Rule 8.7 violation

Quoted 9 lines · Xenia Ragiadakou
Quoted 8 lines · Jan Beulich
Quoted 6 lines · Xenia Ragiadakou

The function idle_loop() is referenced only in domain.c. Change its linkage from external to internal by adding the storage-class specifier static to its definitions.

Since idle_loop() is referenced only in inline assembly, add the 'used' attribute to suppress unused-function compiler warning.

Quoted 7 lines
Quoted 4 lines

While I see that Julien has already acked the patch, I'd like to point out that using __used here is somewhat bogus. Imo the better approach is to properly make visible to the compiler that the symbol is used by the asm(), by adding a fake(?) input.

I 'm afraid I do not understand what do you mean by "adding a fake(?) input". Can you please elaborate a little on your suggestion?

Once the asm() in question takes the function as an input, the compiler will know that the function has a user (unless, of course, it finds a way to elide the asm() itself). The "fake(?)" was because I'm not deeply enough into Arm inline assembly to know whether the input could then also be used as an instruction operand (which imo would be preferable) - if it can't (e.g. because there's no suitable constraint or operand modifier), it still can be an input just to inform the compiler.

Jan

#14 lore raw

Re: [PATCH 3/4] xen/arm: domain: Fix MISRA C 2012 Rule 8.7 violation

Hi Jan,

Quoted 18 lines · Jan Beulich
Quoted 9 lines · Xenia Ragiadakou
Quoted 8 lines · Jan Beulich
Quoted 6 lines · Xenia Ragiadakou

The function idle_loop() is referenced only in domain.c. Change its linkage from external to internal by adding the storage-class specifier static to its definitions.

Since idle_loop() is referenced only in inline assembly, add the 'used' attribute to suppress unused-function compiler warning.

Quoted 7 lines
Quoted 4 lines

While I see that Julien has already acked the patch, I'd like to point out that using __used here is somewhat bogus. Imo the better approach is to properly make visible to the compiler that the symbol is used by the asm(), by adding a fake(?) input.

I 'm afraid I do not understand what do you mean by "adding a fake(?) input". Can you please elaborate a little on your suggestion?

Quoted 7 lines

Once the asm() in question takes the function as an input, the compiler will know that the function has a user (unless, of course, it finds a way to elide the asm() itself). The "fake(?)" was because I'm not deeply enough into Arm inline assembly to know whether the input could then also be used as an instruction operand (which imo would be preferable) - if it can't (e.g. because there's no suitable constraint or operand modifier), it still can be an input just to inform the compiler.

According to the following statement, your approach is the recommended one:
"To prevent the compiler from removing global data or functions which are referenced from inline assembly statements, you can:
-use __attribute__((used)) with the global data or functions.
-pass the reference to global data or functions as operands to inline assembly statements.
Arm recommends passing the reference to global data or functions as operands to inline assembly statements so that if the final image does not require the inline assembly statements and the referenced global data or function, then they can be removed."

IIUC, you are suggesting to change
asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack) : "memory" ) into
asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) : "memory" );

This gives, respectively:
reset_stack_and_jump(idle_loop);

     460:	9100001f 	mov	sp, x0

     464:	14000007 	b	480 <idle_loop>

reset_stack_and_jump(idle_loop);

     460:	9100001f 	mov	sp, x0

     464:	14000000 	b	600 <idle_loop>

With this change, the functions return_to_new_vcpu32 and return_to_new_vcpu64, implemented in assembly and called in the same way as idle_loop(), need to be declared.

Signature · 1 line
Xenia
#15 lore raw

Re: [PATCH 3/4] xen/arm: domain: Fix MISRA C 2012 Rule 8.7 violation

Quoted 38 lines · Xenia Ragiadakou
Quoted 18 lines · Jan Beulich
Quoted 9 lines · Xenia Ragiadakou
Quoted 8 lines · Jan Beulich
Quoted 6 lines · Xenia Ragiadakou

The function idle_loop() is referenced only in domain.c. Change its linkage from external to internal by adding the storage-class specifier static to its definitions.

Since idle_loop() is referenced only in inline assembly, add the 'used' attribute to suppress unused-function compiler warning.

Quoted 7 lines
Quoted 4 lines

While I see that Julien has already acked the patch, I'd like to point out that using __used here is somewhat bogus. Imo the better approach is to properly make visible to the compiler that the symbol is used by the asm(), by adding a fake(?) input.

I 'm afraid I do not understand what do you mean by "adding a fake(?) input". Can you please elaborate a little on your suggestion?

Quoted 7 lines

Once the asm() in question takes the function as an input, the compiler will know that the function has a user (unless, of course, it finds a way to elide the asm() itself). The "fake(?)" was because I'm not deeply enough into Arm inline assembly to know whether the input could then also be used as an instruction operand (which imo would be preferable) - if it can't (e.g. because there's no suitable constraint or operand modifier), it still can be an input just to inform the compiler.

According to the following statement, your approach is the recommended one:
"To prevent the compiler from removing global data or functions which are referenced from inline assembly statements, you can:

(quoted diff) +0 -2
-use __attribute__((used)) with the global data or functions.
-pass the reference to global data or functions as operands to inline 

assembly statements.
Arm recommends passing the reference to global data or functions as operands to inline assembly statements so that if the final image does not require the inline assembly statements and the referenced global data or function, then they can be removed."

Quoted 4 lines

IIUC, you are suggesting to change
asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack) : "memory" ) into
asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) : "memory" );

Yes, except that I can't judge about the "S" constraint.

Quoted 10 lines

This gives, respectively:
reset_stack_and_jump(idle_loop);

      460:	9100001f 	mov	sp, x0

      464:	14000007 	b	480 <idle_loop>

reset_stack_and_jump(idle_loop);

Quoted 8 lines
      460:	9100001f 	mov	sp, x0

      464:	14000000 	b	600 <idle_loop>

With this change, the functions return_to_new_vcpu32 and return_to_new_vcpu64, implemented in assembly and called in the same way as idle_loop(), need to be declared.

Which imo is a good thing - these probably shouldn't have lived entirely behind the back of the compiler.

Jan

#16 lore raw

Re: [PATCH 3/4] xen/arm: domain: Fix MISRA C 2012 Rule 8.7 violation

Quoted 39 lines · Jan Beulich
Quoted 38 lines · Xenia Ragiadakou
Quoted 18 lines · Jan Beulich
Quoted 9 lines · Xenia Ragiadakou
Quoted 8 lines · Jan Beulich
Quoted 6 lines · Xenia Ragiadakou

The function idle_loop() is referenced only in domain.c. Change its linkage from external to internal by adding the storage-class specifier static to its definitions.

Since idle_loop() is referenced only in inline assembly, add the 'used' attribute to suppress unused-function compiler warning.

Quoted 7 lines
Quoted 4 lines

While I see that Julien has already acked the patch, I'd like to point out that using __used here is somewhat bogus. Imo the better approach is to properly make visible to the compiler that the symbol is used by the asm(), by adding a fake(?) input.

I 'm afraid I do not understand what do you mean by "adding a fake(?) input". Can you please elaborate a little on your suggestion?

Quoted 7 lines

Once the asm() in question takes the function as an input, the compiler will know that the function has a user (unless, of course, it finds a way to elide the asm() itself). The "fake(?)" was because I'm not deeply enough into Arm inline assembly to know whether the input could then also be used as an instruction operand (which imo would be preferable) - if it can't (e.g. because there's no suitable constraint or operand modifier), it still can be an input just to inform the compiler.

According to the following statement, your approach is the recommended one:
"To prevent the compiler from removing global data or functions which are referenced from inline assembly statements, you can:

(quoted diff) +0 -2
-use __attribute__((used)) with the global data or functions.
-pass the reference to global data or functions as operands to inline

assembly statements.
Arm recommends passing the reference to global data or functions as operands to inline assembly statements so that if the final image does not require the inline assembly statements and the referenced global data or function, then they can be removed."

Quoted 7 lines
Quoted 4 lines

IIUC, you are suggesting to change
asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack) : "memory" ) into
asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) : "memory" );

Yes, except that I can't judge about the "S" constraint.

This constraint does not work for arm32. Any other thoughts?

Another way, as Jan suggested, is to pass the function as a 'fake' (unused) input. I 'm suspecting something like the following could work
asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn) : "memory") What do you think?

Quoted 23 lines
Quoted 10 lines

This gives, respectively:
reset_stack_and_jump(idle_loop);

       460:	9100001f 	mov	sp, x0

       464:	14000007 	b	480 <idle_loop>

reset_stack_and_jump(idle_loop);

Quoted 8 lines
       460:	9100001f 	mov	sp, x0

       464:	14000000 	b	600 <idle_loop>

With this change, the functions return_to_new_vcpu32 and return_to_new_vcpu64, implemented in assembly and called in the same way as idle_loop(), need to be declared.

Which imo is a good thing - these probably shouldn't have lived entirely behind the back of the compiler.

Jan

Signature · 1 line
Xenia
#17 lore raw

Re: [PATCH 3/4] xen/arm: domain: Fix MISRA C 2012 Rule 8.7 violation

Quoted 48 lines · Xenia Ragiadakou
Quoted 39 lines · Jan Beulich
Quoted 38 lines · Xenia Ragiadakou
Quoted 18 lines · Jan Beulich
Quoted 9 lines · Xenia Ragiadakou
Quoted 8 lines · Jan Beulich
Quoted 6 lines · Xenia Ragiadakou

The function idle_loop() is referenced only in domain.c. Change its linkage from external to internal by adding the storage-class specifier static to its definitions.

Since idle_loop() is referenced only in inline assembly, add the 'used' attribute to suppress unused-function compiler warning.

Quoted 7 lines
Quoted 4 lines

While I see that Julien has already acked the patch, I'd like to point out that using __used here is somewhat bogus. Imo the better approach is to properly make visible to the compiler that the symbol is used by the asm(), by adding a fake(?) input.

I 'm afraid I do not understand what do you mean by "adding a fake(?) input". Can you please elaborate a little on your suggestion?

Quoted 7 lines

Once the asm() in question takes the function as an input, the compiler will know that the function has a user (unless, of course, it finds a way to elide the asm() itself). The "fake(?)" was because I'm not deeply enough into Arm inline assembly to know whether the input could then also be used as an instruction operand (which imo would be preferable) - if it can't (e.g. because there's no suitable constraint or operand modifier), it still can be an input just to inform the compiler.

According to the following statement, your approach is the recommended one:
"To prevent the compiler from removing global data or functions which are referenced from inline assembly statements, you can:

(quoted diff) +0 -2
-use __attribute__((used)) with the global data or functions.
-pass the reference to global data or functions as operands to inline

assembly statements.
Arm recommends passing the reference to global data or functions as operands to inline assembly statements so that if the final image does not require the inline assembly statements and the referenced global data or function, then they can be removed."

Quoted 7 lines
Quoted 4 lines

IIUC, you are suggesting to change
asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack) : "memory" ) into
asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) : "memory" );

Yes, except that I can't judge about the "S" constraint.

Quoted 7 lines

This constraint does not work for arm32. Any other thoughts?

Another way, as Jan suggested, is to pass the function as a 'fake' (unused) input.
I 'm suspecting something like the following could work
asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn) : "memory") What do you think?

Well, yes, X should always be a fallback option. But I said already when you suggested S that I can't judge about its use, so I guess I'm the wrong one to ask. Even more so that you only say "does not work", without any details ...

Jan

#18 lore raw

Re: [PATCH 3/4] xen/arm: domain: Fix MISRA C 2012 Rule 8.7 violation

Quoted 57 lines · Jan Beulich
Quoted 48 lines · Xenia Ragiadakou
Quoted 39 lines · Jan Beulich
Quoted 38 lines · Xenia Ragiadakou
Quoted 18 lines · Jan Beulich
Quoted 9 lines · Xenia Ragiadakou
Quoted 8 lines · Jan Beulich
Quoted 6 lines · Xenia Ragiadakou

The function idle_loop() is referenced only in domain.c. Change its linkage from external to internal by adding the storage-class specifier static to its definitions.

Since idle_loop() is referenced only in inline assembly, add the 'used' attribute to suppress unused-function compiler warning.

Quoted 7 lines
Quoted 4 lines

While I see that Julien has already acked the patch, I'd like to point out that using __used here is somewhat bogus. Imo the better approach is to properly make visible to the compiler that the symbol is used by the asm(), by adding a fake(?) input.

I 'm afraid I do not understand what do you mean by "adding a fake(?) input". Can you please elaborate a little on your suggestion?

Quoted 7 lines

Once the asm() in question takes the function as an input, the compiler will know that the function has a user (unless, of course, it finds a way to elide the asm() itself). The "fake(?)" was because I'm not deeply enough into Arm inline assembly to know whether the input could then also be used as an instruction operand (which imo would be preferable) - if it can't (e.g. because there's no suitable constraint or operand modifier), it still can be an input just to inform the compiler.

According to the following statement, your approach is the recommended one:
"To prevent the compiler from removing global data or functions which are referenced from inline assembly statements, you can:

(quoted diff) +0 -2
-use __attribute__((used)) with the global data or functions.
-pass the reference to global data or functions as operands to inline

assembly statements.
Arm recommends passing the reference to global data or functions as operands to inline assembly statements so that if the final image does not require the inline assembly statements and the referenced global data or function, then they can be removed."

Quoted 7 lines
Quoted 4 lines

IIUC, you are suggesting to change
asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack) : "memory" ) into
asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) : "memory" );

Yes, except that I can't judge about the "S" constraint.

Quoted 7 lines

This constraint does not work for arm32. Any other thoughts?

Another way, as Jan suggested, is to pass the function as a 'fake' (unused) input.
I 'm suspecting something like the following could work
asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn) : "memory") What do you think?

Quoted 5 lines

Well, yes, X should always be a fallback option. But I said already when you suggested S that I can't judge about its use, so I guess I'm the wrong one to ask. Even more so that you only say "does not work", without any details ...

The question is addressed to anyone familiar with arm inline assembly.
I added the arm maintainers as primary recipients to this email to make this perfectly clear.

When cross-compiling Xen on x86 for arm32 with
asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) : "memory" ); compilation fails with the error: impossible constraint in ‘asm'

Signature · 1 line
Xenia
#19 lore raw

Re: [PATCH 3/4] xen/arm: domain: Fix MISRA C 2012 Rule 8.7 violation

Quoted 77 lines · Xenia Ragiadakou
Quoted 70 lines · Jan Beulich
Quoted 60 lines · Xenia Ragiadakou
Quoted 50 lines · Jan Beulich
Quoted 49 lines · Xenia Ragiadakou
Quoted 24 lines · Jan Beulich
Quoted 19 lines · Xenia Ragiadakou
Quoted 10 lines · Jan Beulich
Quoted 8 lines · Xenia Ragiadakou

The function idle_loop() is referenced only in domain.c. Change its linkage from external to internal by adding the storage-class
specifier static to its definitions.

Since idle_loop() is referenced only in inline assembly, add the 'used'
attribute to suppress unused-function compiler warning.

Quoted 7 lines

While I see that Julien has already acked the patch, I'd like to point
out that using __used here is somewhat bogus. Imo the better approach
is to properly make visible to the compiler that the symbol is used by
the asm(), by adding a fake(?) input.

Quoted 3 lines

I 'm afraid I do not understand what do you mean by "adding a fake(?)
input". Can you please elaborate a little on your suggestion?

Quoted 11 lines

Once the asm() in question takes the function as an input, the compiler
will know that the function has a user (unless, of course, it finds a
way to elide the asm() itself). The "fake(?)" was because I'm not deeply
enough into Arm inline assembly to know whether the input could then also be used as an instruction operand (which imo would be preferable) -
if it can't (e.g. because there's no suitable constraint or operand modifier), it still can be an input just to inform the compiler.

According to the following statement, your approach is the recommended one:
"To prevent the compiler from removing global data or functions which are referenced from inline assembly statements, you can:

(quoted diff) +0 -2
-use __attribute__((used)) with the global data or functions.
-pass the reference to global data or functions as operands to inline

assembly statements.
Arm recommends passing the reference to global data or functions as operands to inline assembly statements so that if the final image does not require the inline assembly statements and the referenced global data or function, then they can be removed."

Quoted 8 lines
Quoted 5 lines

IIUC, you are suggesting to change
asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack) : "memory" ) into
asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) : "memory" );

Yes, except that I can't judge about the "S" constraint.

Quoted 8 lines

This constraint does not work for arm32. Any other thoughts?

Another way, as Jan suggested, is to pass the function as a 'fake' (unused) input.
I 'm suspecting something like the following could work asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn) :
"memory")
What do you think?

Quoted 5 lines

Well, yes, X should always be a fallback option. But I said already when you suggested S that I can't judge about its use, so I guess I'm the wrong one to ask. Even more so that you only say "does not work", without any details ...

Quoted 7 lines

The question is addressed to anyone familiar with arm inline assembly. I added the arm maintainers as primary recipients to this email to make this perfectly clear.

When cross-compiling Xen on x86 for arm32 with
asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) : "memory" ); compilation fails with the error: impossible constraint in ‘asm'

Unfortunately looking at the GCC manual pages [1], it doesn't seem to be possible. The problem is that the definition of "S" changes between aarch64 and arm (the 32-bit version).

For aarch64:

S An absolute symbolic address or a label reference

This is what we want. For arm instead:

S A symbol in the text segment of the current file

This is not useful for what we need to do here. As far as I can tell, there is no other way in GCC assembly inline for arm to do this.

So we have 2 choices: we use the __used keyword as Xenia did in this patch. Or we move the implementation of switch_stack_and_jump in assembly. I attempted a prototype of the latter to see how it would come out, see below.

I don't like it very much. I prefer the version with __used that Xenia had in this patch. But I am OK either way.

xen/arch/arm/arm32/entry.S +4 -0
index 38826142ad..4d28f7e9f7 100644
@@ -442,6 +442,10 @@ ENTRY(__context_switch)
         add     r4, r1, #VCPU_arch_saved_context
         ldmia   r4, {r4 - sl, fp, sp, pc}       /* Load registers and return */
 
+ENTRY(__switch_stack_and_jump)
+        mov sp, r0
+        bx r1
+
 /*
  * Local variables:
  * mode: ASM
xen/arch/arm/arm64/entry.S +4 -0
index 95f1a92684..5d5d713f80 100644
@@ -618,6 +618,10 @@ ENTRY(__context_switch)
         mov     sp, x9
         ret
 
+ENTRY(__switch_stack_and_jump)
+        mov sp, x0
+        br x1
+
 /*
  * Local variables:
  * mode: ASM
xen/arch/arm/include/asm/current.h +5 -1
index 73e81458e5..7696440a57 100644
@@ -44,8 +44,12 @@ static inline struct cpu_info *get_cpu_info(void)
 
 #define guest_cpu_user_regs() (&get_cpu_info()->guest_cpu_user_regs)
 
+void return_to_new_vcpu32(void);
+void return_to_new_vcpu64(void);
+void __switch_stack_and_jump(void *p, void *f);
+
 #define switch_stack_and_jump(stack, fn) do {                           \
-    asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack) : "memory" ); \
+    __switch_stack_and_jump(stack, fn);                                 \
     unreachable();                                                      \
 } while ( false )
 

[1] https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html

#20 lore raw

Re: [PATCH 3/4] xen/arm: domain: Fix MISRA C 2012 Rule 8.7 violation

Quoted 101 lines · Stefano Stabellini
Quoted 77 lines · Xenia Ragiadakou
Quoted 70 lines · Jan Beulich
Quoted 60 lines · Xenia Ragiadakou
Quoted 50 lines · Jan Beulich
Quoted 49 lines · Xenia Ragiadakou
Quoted 24 lines · Jan Beulich
Quoted 19 lines · Xenia Ragiadakou
Quoted 10 lines · Jan Beulich
Quoted 8 lines · Xenia Ragiadakou

The function idle_loop() is referenced only in domain.c. Change its linkage from external to internal by adding the storage-class
specifier static to its definitions.

Since idle_loop() is referenced only in inline assembly, add the 'used'
attribute to suppress unused-function compiler warning.

Quoted 7 lines

While I see that Julien has already acked the patch, I'd like to point
out that using __used here is somewhat bogus. Imo the better approach
is to properly make visible to the compiler that the symbol is used by
the asm(), by adding a fake(?) input.

Quoted 3 lines

I 'm afraid I do not understand what do you mean by "adding a fake(?)
input". Can you please elaborate a little on your suggestion?

Quoted 11 lines

Once the asm() in question takes the function as an input, the compiler
will know that the function has a user (unless, of course, it finds a
way to elide the asm() itself). The "fake(?)" was because I'm not deeply
enough into Arm inline assembly to know whether the input could then also be used as an instruction operand (which imo would be preferable) -
if it can't (e.g. because there's no suitable constraint or operand modifier), it still can be an input just to inform the compiler.

According to the following statement, your approach is the recommended one:
"To prevent the compiler from removing global data or functions which are referenced from inline assembly statements, you can:

(quoted diff) +0 -2
-use __attribute__((used)) with the global data or functions.
-pass the reference to global data or functions as operands to inline

assembly statements.
Arm recommends passing the reference to global data or functions as operands to inline assembly statements so that if the final image does not require the inline assembly statements and the referenced global data or function, then they can be removed."

Quoted 8 lines
Quoted 5 lines

IIUC, you are suggesting to change
asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack) : "memory" ) into
asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) : "memory" );

Yes, except that I can't judge about the "S" constraint.

Quoted 8 lines

This constraint does not work for arm32. Any other thoughts?

Another way, as Jan suggested, is to pass the function as a 'fake' (unused) input.
I 'm suspecting something like the following could work asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn) :
"memory")
What do you think?

Quoted 5 lines

Well, yes, X should always be a fallback option. But I said already when you suggested S that I can't judge about its use, so I guess I'm the wrong one to ask. Even more so that you only say "does not work", without any details ...

Quoted 7 lines

The question is addressed to anyone familiar with arm inline assembly. I added the arm maintainers as primary recipients to this email to make this perfectly clear.

When cross-compiling Xen on x86 for arm32 with
asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) : "memory" ); compilation fails with the error: impossible constraint in ‘asm'

Unfortunately looking at the GCC manual pages [1], it doesn't seem to be possible. The problem is that the definition of "S" changes between aarch64 and arm (the 32-bit version).

For aarch64:

S An absolute symbolic address or a label reference

This is what we want. For arm instead:

S A symbol in the text segment of the current file

This is not useful for what we need to do here. As far as I can tell, there is no other way in GCC assembly inline for arm to do this.

Quoted 7 lines

So we have 2 choices: we use the __used keyword as Xenia did in this patch. Or we move the implementation of switch_stack_and_jump in assembly. I attempted a prototype of the latter to see how it would come out, see below.

I don't like it very much. I prefer the version with __used that Xenia had in this patch. But I am OK either way.

You forgot the imo better intermediate option of using the "X" constraint.

Jan

#21 lore raw

Re: [PATCH 3/4] xen/arm: domain: Fix MISRA C 2012 Rule 8.7 violation

Quoted 107 lines · Jan Beulich
Quoted 106 lines · Stefano Stabellini
Quoted 77 lines · Xenia Ragiadakou
Quoted 70 lines · Jan Beulich
Quoted 60 lines · Xenia Ragiadakou
Quoted 50 lines · Jan Beulich
Quoted 49 lines · Xenia Ragiadakou
Quoted 24 lines · Jan Beulich
Quoted 19 lines · Xenia Ragiadakou
Quoted 10 lines · Jan Beulich
Quoted 8 lines · Xenia Ragiadakou

The function idle_loop() is referenced only in domain.c. Change its linkage from external to internal by adding the storage-class
specifier static to its definitions.

Since idle_loop() is referenced only in inline assembly, add the 'used'
attribute to suppress unused-function compiler warning.

Quoted 7 lines

While I see that Julien has already acked the patch, I'd like to point
out that using __used here is somewhat bogus. Imo the better approach
is to properly make visible to the compiler that the symbol is used by
the asm(), by adding a fake(?) input.

Quoted 3 lines

I 'm afraid I do not understand what do you mean by "adding a fake(?)
input". Can you please elaborate a little on your suggestion?

Quoted 11 lines

Once the asm() in question takes the function as an input, the compiler
will know that the function has a user (unless, of course, it finds a
way to elide the asm() itself). The "fake(?)" was because I'm not deeply
enough into Arm inline assembly to know whether the input could then also be used as an instruction operand (which imo would be preferable) -
if it can't (e.g. because there's no suitable constraint or operand modifier), it still can be an input just to inform the compiler.

According to the following statement, your approach is the recommended one:
"To prevent the compiler from removing global data or functions which are referenced from inline assembly statements, you can:

(quoted diff) +0 -2
-use __attribute__((used)) with the global data or functions.
-pass the reference to global data or functions as operands to inline

assembly statements.
Arm recommends passing the reference to global data or functions as operands to inline assembly statements so that if the final image does not require the inline assembly statements and the referenced global data or function, then they can be removed."

Quoted 8 lines
Quoted 5 lines

IIUC, you are suggesting to change
asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack) : "memory" ) into
asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) : "memory" );

Yes, except that I can't judge about the "S" constraint.

Quoted 8 lines

This constraint does not work for arm32. Any other thoughts?

Another way, as Jan suggested, is to pass the function as a 'fake' (unused) input.
I 'm suspecting something like the following could work asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn) :
"memory")
What do you think?

Quoted 5 lines

Well, yes, X should always be a fallback option. But I said already when you suggested S that I can't judge about its use, so I guess I'm the wrong one to ask. Even more so that you only say "does not work", without any details ...

Quoted 7 lines

The question is addressed to anyone familiar with arm inline assembly. I added the arm maintainers as primary recipients to this email to make this perfectly clear.

When cross-compiling Xen on x86 for arm32 with
asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) : "memory" ); compilation fails with the error: impossible constraint in ‘asm'

Unfortunately looking at the GCC manual pages [1], it doesn't seem to be possible. The problem is that the definition of "S" changes between aarch64 and arm (the 32-bit version).

For aarch64:

S An absolute symbolic address or a label reference

This is what we want. For arm instead:

S A symbol in the text segment of the current file

This is not useful for what we need to do here. As far as I can tell, there is no other way in GCC assembly inline for arm to do this.

So we have 2 choices: we use the __used keyword as Xenia did in this patch. Or we move the implementation of switch_stack_and_jump in assembly. I attempted a prototype of the latter to see how it would come out, see below.

Quoted 4 lines
Quoted 2 lines

I don't like it very much. I prefer the version with __used that Xenia had in this patch. But I am OK either way.

You forgot the imo better intermediate option of using the "X" constraint.

I couldn't get "X" to compile in any way (not even for arm64). Do you have a concrete example that you think should work using "X" as constraint?

#22 lore raw

Re: [PATCH 3/4] xen/arm: domain: Fix MISRA C 2012 Rule 8.7 violation

Quoted 108 lines · Stefano Stabellini
Quoted 107 lines · Jan Beulich
Quoted 106 lines · Stefano Stabellini
Quoted 77 lines · Xenia Ragiadakou
Quoted 70 lines · Jan Beulich
Quoted 60 lines · Xenia Ragiadakou
Quoted 50 lines · Jan Beulich
Quoted 49 lines · Xenia Ragiadakou
Quoted 24 lines · Jan Beulich
Quoted 19 lines · Xenia Ragiadakou
Quoted 10 lines · Jan Beulich
Quoted 8 lines · Xenia Ragiadakou

The function idle_loop() is referenced only in domain.c. Change its linkage from external to internal by adding the storage-class
specifier static to its definitions.

Since idle_loop() is referenced only in inline assembly, add the 'used'
attribute to suppress unused-function compiler warning.

Quoted 7 lines

While I see that Julien has already acked the patch, I'd like to point
out that using __used here is somewhat bogus. Imo the better approach
is to properly make visible to the compiler that the symbol is used by
the asm(), by adding a fake(?) input.

Quoted 3 lines

I 'm afraid I do not understand what do you mean by "adding a fake(?)
input". Can you please elaborate a little on your suggestion?

Quoted 11 lines

Once the asm() in question takes the function as an input, the compiler
will know that the function has a user (unless, of course, it finds a
way to elide the asm() itself). The "fake(?)" was because I'm not deeply
enough into Arm inline assembly to know whether the input could then also be used as an instruction operand (which imo would be preferable) -
if it can't (e.g. because there's no suitable constraint or operand modifier), it still can be an input just to inform the compiler.

According to the following statement, your approach is the recommended one:
"To prevent the compiler from removing global data or functions which are referenced from inline assembly statements, you can:

(quoted diff) +0 -2
-use __attribute__((used)) with the global data or functions.
-pass the reference to global data or functions as operands to inline

assembly statements.
Arm recommends passing the reference to global data or functions as operands to inline assembly statements so that if the final image does not require the inline assembly statements and the referenced global data or function, then they can be removed."

Quoted 8 lines
Quoted 5 lines

IIUC, you are suggesting to change
asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack) : "memory" ) into
asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) : "memory" );

Yes, except that I can't judge about the "S" constraint.

Quoted 8 lines

This constraint does not work for arm32. Any other thoughts?

Another way, as Jan suggested, is to pass the function as a 'fake' (unused) input.
I 'm suspecting something like the following could work asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn) :
"memory")
What do you think?

Quoted 5 lines

Well, yes, X should always be a fallback option. But I said already when you suggested S that I can't judge about its use, so I guess I'm the wrong one to ask. Even more so that you only say "does not work", without any details ...

Quoted 7 lines

The question is addressed to anyone familiar with arm inline assembly. I added the arm maintainers as primary recipients to this email to make this perfectly clear.

When cross-compiling Xen on x86 for arm32 with
asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) : "memory" ); compilation fails with the error: impossible constraint in ‘asm'

Unfortunately looking at the GCC manual pages [1], it doesn't seem to be possible. The problem is that the definition of "S" changes between aarch64 and arm (the 32-bit version).

For aarch64:

S An absolute symbolic address or a label reference

This is what we want. For arm instead:

S A symbol in the text segment of the current file

This is not useful for what we need to do here. As far as I can tell, there is no other way in GCC assembly inline for arm to do this.

So we have 2 choices: we use the __used keyword as Xenia did in this patch. Or we move the implementation of switch_stack_and_jump in assembly. I attempted a prototype of the latter to see how it would come out, see below.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

I don't like it very much. I prefer the version with __used that Xenia had in this patch. But I am OK either way.

You forgot the imo better intermediate option of using the "X" constraint.

I couldn't get "X" to compile in any way (not even for arm64). Do you have a concrete example that you think should work using "X" as constraint?

I proposed the X constraint for the case that the function is used as a fake (unused) input operand to the inline asm. For instance, in the example below, the function is listed in the input operands but there is not corresponding reference to it.

asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn) : "memory" );

Signature · 1 line
Xenia
#23 lore raw

Re: [PATCH 3/4] xen/arm: domain: Fix MISRA C 2012 Rule 8.7 violation

Quoted 145 lines · Xenia Ragiadakou
Quoted 135 lines · Stefano Stabellini
Quoted 134 lines · Jan Beulich
Quoted 133 lines · Stefano Stabellini
Quoted 107 lines · Xenia Ragiadakou
Quoted 93 lines · Jan Beulich
Quoted 83 lines · Xenia Ragiadakou
Quoted 71 lines · Jan Beulich
Quoted 70 lines · Xenia Ragiadakou
Quoted 42 lines · Jan Beulich
Quoted 26 lines · Xenia Ragiadakou
Quoted 14 lines · Jan Beulich
Quoted 12 lines · Xenia Ragiadakou

The function idle_loop() is referenced only in
domain.c.
Change its linkage from external to internal by adding
the
storage-class
specifier static to its definitions.

Since idle_loop() is referenced only in inline
assembly, add
the 'used'
attribute to suppress unused-function compiler
warning.

Quoted 10 lines

While I see that Julien has already acked the patch, I'd like to
point
out that using __used here is somewhat bogus. Imo the better
approach
is to properly make visible to the compiler that the symbol is
used by
the asm(), by adding a fake(?) input.

Quoted 5 lines

I 'm afraid I do not understand what do you mean by "adding a
fake(?)
input". Can you please elaborate a little on your suggestion?

Once the asm() in question takes the function as an input, the
compiler
will know that the function has a user (unless, of course, it finds
a
way to elide the asm() itself). The "fake(?)" was because I'm not
deeply

Quoted 8 lines

enough into Arm inline assembly to know whether the input could then
also be used as an instruction operand (which imo would be preferable) -
if it can't (e.g. because there's no suitable constraint or operand
modifier), it still can be an input just to inform the compiler.

According to the following statement, your approach is the recommended
one:
"To prevent the compiler from removing global data or functions which
are referenced from inline assembly statements, you can:

(quoted diff) +0 -2
-use __attribute__((used)) with the global data or functions.
-pass the reference to global data or functions as operands to

inline
assembly statements.
Arm recommends passing the reference to global data or functions as
operands to inline assembly statements so that if the final image does
not require the inline assembly statements and the referenced global
data or function, then they can be removed."

Quoted 10 lines
Quoted 7 lines

IIUC, you are suggesting to change
asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack) :
"memory" )
into
asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) :
"memory"
);

Yes, except that I can't judge about the "S" constraint.

Quoted 8 lines

This constraint does not work for arm32. Any other thoughts?

Another way, as Jan suggested, is to pass the function as a 'fake' (unused) input.
I 'm suspecting something like the following could work asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn) :
"memory")
What do you think?

Quoted 7 lines

Well, yes, X should always be a fallback option. But I said already when
you suggested S that I can't judge about its use, so I guess I'm the wrong one to ask. Even more so that you only say "does not work", without
any details ...

The question is addressed to anyone familiar with arm inline assembly. I added the arm maintainers as primary recipients to this email to make this
perfectly clear.

Quoted 4 lines

When cross-compiling Xen on x86 for arm32 with
asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) : "memory" );
compilation fails with the error: impossible constraint in ‘asm'

Unfortunately looking at the GCC manual pages [1], it doesn't seem to be possible. The problem is that the definition of "S" changes between aarch64 and arm (the 32-bit version).

For aarch64:

S An absolute symbolic address or a label reference

This is what we want. For arm instead:

S A symbol in the text segment of the current file

This is not useful for what we need to do here. As far as I can tell, there is no other way in GCC assembly inline for arm to do this.

So we have 2 choices: we use the __used keyword as Xenia did in this patch. Or we move the implementation of switch_stack_and_jump in assembly. I attempted a prototype of the latter to see how it would come out, see below.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

I don't like it very much. I prefer the version with __used that Xenia had in this patch. But I am OK either way.

You forgot the imo better intermediate option of using the "X" constraint.

I couldn't get "X" to compile in any way (not even for arm64). Do you have a concrete example that you think should work using "X" as constraint?

Quoted 6 lines

I proposed the X constraint for the case that the function is used as a fake (unused) input operand to the inline asm.
For instance, in the example below, the function is listed in the input operands but there is not corresponding reference to it.

asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn) : "memory" );

Also replying to Jan, yes, this doesn't build for me, not even for arm64. The error is below.

arch/arm/domain.c: In function ‘continue_new_vcpu’:
arch/arm/domain.c:345:30: error: ‘return_to_new_vcpu32’ undeclared (first use in this function)

  345 |         reset_stack_and_jump(return_to_new_vcpu32);
      |                              ^~~~~~~~~~~~~~~~~~~~

./arch/arm/include/asm/current.h:48:65: note: in definition of macro ‘switch_stack_and_jump’
48 | asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn) : "memory" ); \
| ^~
arch/arm/domain.c:345:9: note: in expansion of macro ‘reset_stack_and_jump’

  345 |         reset_stack_and_jump(return_to_new_vcpu32);
      |         ^~~~~~~~~~~~~~~~~~~~
arch/arm/domain.c:345:30: note: each undeclared identifier is reported only once for each function it appears in
  345 |         reset_stack_and_jump(return_to_new_vcpu32);
      |                              ^~~~~~~~~~~~~~~~~~~~

./arch/arm/include/asm/current.h:48:65: note: in definition of macro ‘switch_stack_and_jump’
48 | asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn) : "memory" ); \
| ^~
arch/arm/domain.c:345:9: note: in expansion of macro ‘reset_stack_and_jump’

  345 |         reset_stack_and_jump(return_to_new_vcpu32);
      |         ^~~~~~~~~~~~~~~~~~~~
  CC      arch/arm/domain_build.o
arch/arm/domain.c:348:30: error: ‘return_to_new_vcpu64’ undeclared (first use in this function)
  348 |         reset_stack_and_jump(return_to_new_vcpu64);
      |                              ^~~~~~~~~~~~~~~~~~~~

./arch/arm/include/asm/current.h:48:65: note: in definition of macro ‘switch_stack_and_jump’
48 | asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn) : "memory" ); \
| ^~
arch/arm/domain.c:348:9: note: in expansion of macro ‘reset_stack_and_jump’

  348 |         reset_stack_and_jump(return_to_new_vcpu64);
      |         ^~~~~~~~~~~~~~~~~~~~

make[2]: *** [Rules.mk:246: arch/arm/domain.o] Error 1

#24 lore raw

Re: [PATCH 3/4] xen/arm: domain: Fix MISRA C 2012 Rule 8.7 violation

Hi Stefano,

Quoted 187 lines · Stefano Stabellini
Quoted 145 lines · Xenia Ragiadakou
Quoted 135 lines · Stefano Stabellini
Quoted 134 lines · Jan Beulich
Quoted 133 lines · Stefano Stabellini
Quoted 107 lines · Xenia Ragiadakou
Quoted 93 lines · Jan Beulich
Quoted 83 lines · Xenia Ragiadakou
Quoted 71 lines · Jan Beulich
Quoted 70 lines · Xenia Ragiadakou
Quoted 42 lines · Jan Beulich
Quoted 26 lines · Xenia Ragiadakou
Quoted 24 lines · Jan Beulich

On 05.07.2022 23:02, Xenia Ragiadakou wrote:
The function idle_loop() is referenced only in
domain.c.
Change its linkage from external to internal by adding
the
storage-class
specifier static to its definitions.

Since idle_loop() is referenced only in inline
assembly, add
the 'used'
attribute to suppress unused-function compiler
warning.

While I see that Julien has already acked the patch, I'd
like to
point
out that using __used here is somewhat bogus. Imo the
better
approach
is to properly make visible to the compiler that the
symbol is
used by
the asm(), by adding a fake(?) input.

Quoted 5 lines

I 'm afraid I do not understand what do you mean by "adding a
fake(?)
input". Can you please elaborate a little on your suggestion?

Once the asm() in question takes the function as an input, the
compiler
will know that the function has a user (unless, of course, it finds
a
way to elide the asm() itself). The "fake(?)" was because I'm not
deeply

Quoted 8 lines

enough into Arm inline assembly to know whether the input could then
also be used as an instruction operand (which imo would be preferable) -
if it can't (e.g. because there's no suitable constraint or operand
modifier), it still can be an input just to inform the compiler.

According to the following statement, your approach is the recommended
one:
"To prevent the compiler from removing global data or functions which
are referenced from inline assembly statements, you can:

(quoted diff) +0 -2
-use __attribute__((used)) with the global data or functions.
-pass the reference to global data or functions as operands to

inline
assembly statements.
Arm recommends passing the reference to global data or functions as
operands to inline assembly statements so that if the final image does
not require the inline assembly statements and the referenced global
data or function, then they can be removed."

Quoted 10 lines
Quoted 7 lines

IIUC, you are suggesting to change
asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack) :
"memory" )
into
asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) :
"memory"
);

Yes, except that I can't judge about the "S" constraint.

Quoted 8 lines

This constraint does not work for arm32. Any other thoughts?

Another way, as Jan suggested, is to pass the function as a 'fake' (unused) input.
I 'm suspecting something like the following could work asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn) :
"memory")
What do you think?

Quoted 7 lines

Well, yes, X should always be a fallback option. But I said already when
you suggested S that I can't judge about its use, so I guess I'm the wrong one to ask. Even more so that you only say "does not work", without
any details ...

The question is addressed to anyone familiar with arm inline assembly. I added the arm maintainers as primary recipients to this email to make this
perfectly clear.

Quoted 4 lines

When cross-compiling Xen on x86 for arm32 with
asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) : "memory" );
compilation fails with the error: impossible constraint in ‘asm'

Unfortunately looking at the GCC manual pages [1], it doesn't seem to be possible. The problem is that the definition of "S" changes between aarch64 and arm (the 32-bit version).

For aarch64:

S An absolute symbolic address or a label reference

This is what we want. For arm instead:

S A symbol in the text segment of the current file

This is not useful for what we need to do here. As far as I can tell, there is no other way in GCC assembly inline for arm to do this.

So we have 2 choices: we use the __used keyword as Xenia did in this patch. Or we move the implementation of switch_stack_and_jump in assembly. I attempted a prototype of the latter to see how it would come out, see below.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

I don't like it very much. I prefer the version with __used that Xenia had in this patch. But I am OK either way.

You forgot the imo better intermediate option of using the "X" constraint.

I couldn't get "X" to compile in any way (not even for arm64). Do you have a concrete example that you think should work using "X" as constraint?

Quoted 6 lines

I proposed the X constraint for the case that the function is used as a fake (unused) input operand to the inline asm.
For instance, in the example below, the function is listed in the input operands but there is not corresponding reference to it.

asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn) : "memory" );

Also replying to Jan, yes, this doesn't build for me, not even for arm64. The error is below.

arch/arm/domain.c: In function ‘continue_new_vcpu’:
arch/arm/domain.c:345:30: error: ‘return_to_new_vcpu32’ undeclared (first use in this function)

   345 |         reset_stack_and_jump(return_to_new_vcpu32);
       |                              ^~~~~~~~~~~~~~~~~~~~
./arch/arm/include/asm/current.h:48:65: note: in definition of macro ‘switch_stack_and_jump’
    48 |     asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn) : "memory" ); \
       |                                                                 ^~
arch/arm/domain.c:345:9: note: in expansion of macro ‘reset_stack_and_jump’
   345 |         reset_stack_and_jump(return_to_new_vcpu32);
       |         ^~~~~~~~~~~~~~~~~~~~
arch/arm/domain.c:345:30: note: each undeclared identifier is reported only once for each function it appears in
   345 |         reset_stack_and_jump(return_to_new_vcpu32);
       |                              ^~~~~~~~~~~~~~~~~~~~
./arch/arm/include/asm/current.h:48:65: note: in definition of macro ‘switch_stack_and_jump’
    48 |     asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn) : "memory" ); \
       |                                                                 ^~
arch/arm/domain.c:345:9: note: in expansion of macro ‘reset_stack_and_jump’
   345 |         reset_stack_and_jump(return_to_new_vcpu32);
       |         ^~~~~~~~~~~~~~~~~~~~
   CC      arch/arm/domain_build.o
arch/arm/domain.c:348:30: error: ‘return_to_new_vcpu64’ undeclared (first use in this function)
   348 |         reset_stack_and_jump(return_to_new_vcpu64);
       |                              ^~~~~~~~~~~~~~~~~~~~
./arch/arm/include/asm/current.h:48:65: note: in definition of macro ‘switch_stack_and_jump’
    48 |     asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn) : "memory" ); \
       |                                                                 ^~
arch/arm/domain.c:348:9: note: in expansion of macro ‘reset_stack_and_jump’
   348 |         reset_stack_and_jump(return_to_new_vcpu64);
       |         ^~~~~~~~~~~~~~~~~~~~
Quoted 1 line

make[2]: *** [Rules.mk:246: arch/arm/domain.o] Error 1

With this change, the compiler becomes aware that the functions idle_loop, return_to_new_vcpu32 and return_to_new_vcpu64 are used by the inline assembly. For idle loop, there is a previous declaration but for the other two there is not and when the compiler encounters their references complains. So, for this to compile, it is also required to declare
return_to_new_vcpu32 and return_to_new_vcpu64.

Signature · 1 line
Xenia
#25 lore raw

Re: [PATCH 3/4] xen/arm: domain: Fix MISRA C 2012 Rule 8.7 violation

Quoted 229 lines · Xenia Ragiadakou

Hi Stefano,

Quoted 224 lines · Stefano Stabellini
Quoted 171 lines · Xenia Ragiadakou
Quoted 163 lines · Stefano Stabellini
Quoted 162 lines · Jan Beulich
Quoted 160 lines · Stefano Stabellini
Quoted 127 lines · Xenia Ragiadakou
Quoted 109 lines · Jan Beulich
Quoted 99 lines · Xenia Ragiadakou
Quoted 84 lines · Jan Beulich
Quoted 83 lines · Xenia Ragiadakou
Quoted 51 lines · Jan Beulich
Quoted 34 lines · Xenia Ragiadakou

On 7/6/22 10:10, Jan Beulich wrote:
On 05.07.2022 23:02, Xenia Ragiadakou wrote:
The function idle_loop() is referenced only in
domain.c.
Change its linkage from external to internal by
adding
the
storage-class
specifier static to its definitions.

Since idle_loop() is referenced only in inline
assembly, add
the 'used'
attribute to suppress unused-function compiler
warning.

While I see that Julien has already acked the patch,
I'd
like to
point
out that using __used here is somewhat bogus. Imo
the
better
approach
is to properly make visible to the compiler that the
symbol is
used by
the asm(), by adding a fake(?) input.

I 'm afraid I do not understand what do you mean by
"adding a
fake(?)
input". Can you please elaborate a little on your
suggestion?

Once the asm() in question takes the function as an input,
the
compiler
will know that the function has a user (unless, of course,
it finds
a
way to elide the asm() itself). The "fake(?)" was because
I'm not
deeply
enough into Arm inline assembly to know whether the input
could then

Quoted 8 lines

also be used as an instruction operand (which imo would be
preferable) -
if it can't (e.g. because there's no suitable constraint or
operand
modifier), it still can be an input just to inform the compiler.

According to the following statement, your approach is the recommended
one:
"To prevent the compiler from removing global data or functions which
are referenced from inline assembly statements, you can:
-use __attribute__((used)) with the global data or functions.
-pass the reference to global data or functions as operands to
inline
assembly statements.
Arm recommends passing the reference to global data or functions as
operands to inline assembly statements so that if the final
image does
not require the inline assembly statements and the referenced
global
data or function, then they can be removed."

Quoted 11 lines
Quoted 8 lines

IIUC, you are suggesting to change
asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack) :
"memory" )
into
asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) :
"memory"
);

Yes, except that I can't judge about the "S" constraint.

This constraint does not work for arm32. Any other thoughts?

Quoted 8 lines

Another way, as Jan suggested, is to pass the function as a 'fake'
(unused) input.
I 'm suspecting something like the following could work asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn) :
"memory")
What do you think?

Quoted 10 lines

Well, yes, X should always be a fallback option. But I said already
when
you suggested S that I can't judge about its use, so I guess I'm the
wrong one to ask. Even more so that you only say "does not work",
without
any details ...

The question is addressed to anyone familiar with arm inline assembly.
I added the arm maintainers as primary recipients to this email to make this
perfectly clear.

Quoted 5 lines

When cross-compiling Xen on x86 for arm32 with
asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) :
"memory"
);
compilation fails with the error: impossible constraint in ‘asm'

Unfortunately looking at the GCC manual pages [1], it doesn't seem to be
possible. The problem is that the definition of "S" changes between aarch64 and arm (the 32-bit version).

For aarch64:

S An absolute symbolic address or a label reference

This is what we want. For arm instead:

S A symbol in the text segment of the current file

This is not useful for what we need to do here. As far as I can tell,
there is no other way in GCC assembly inline for arm to do this.

So we have 2 choices: we use the __used keyword as Xenia did in this patch. Or we move the implementation of switch_stack_and_jump in assembly. I attempted a prototype of the latter to see how it would come
out, see below.

I don't like it very much. I prefer the version with __used that Xenia
had in this patch. But I am OK either way.

Quoted 6 lines
Quoted 2 lines

You forgot the imo better intermediate option of using the "X" constraint.

I couldn't get "X" to compile in any way (not even for arm64). Do you have a concrete example that you think should work using "X" as constraint?

Quoted 8 lines

I proposed the X constraint for the case that the function is used as a fake
(unused) input operand to the inline asm.
For instance, in the example below, the function is listed in the input operands but there is not corresponding reference to it.

asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn) : "memory" );

Also replying to Jan, yes, this doesn't build for me, not even for arm64. The error is below.

arch/arm/domain.c: In function ‘continue_new_vcpu’:
arch/arm/domain.c:345:30: error: ‘return_to_new_vcpu32’ undeclared (first use in this function)

   345 |         reset_stack_and_jump(return_to_new_vcpu32);
       |                              ^~~~~~~~~~~~~~~~~~~~
./arch/arm/include/asm/current.h:48:65: note: in definition of macro
‘switch_stack_and_jump’
    48 |     asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn)
: "memory" ); \
       |                                                                 ^~
arch/arm/domain.c:345:9: note: in expansion of macro ‘reset_stack_and_jump’
   345 |         reset_stack_and_jump(return_to_new_vcpu32);
       |         ^~~~~~~~~~~~~~~~~~~~
arch/arm/domain.c:345:30: note: each undeclared identifier is reported only
once for each function it appears in
   345 |         reset_stack_and_jump(return_to_new_vcpu32);
       |                              ^~~~~~~~~~~~~~~~~~~~
./arch/arm/include/asm/current.h:48:65: note: in definition of macro
‘switch_stack_and_jump’
    48 |     asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn)
: "memory" ); \
       |                                                                 ^~
arch/arm/domain.c:345:9: note: in expansion of macro ‘reset_stack_and_jump’
   345 |         reset_stack_and_jump(return_to_new_vcpu32);
       |         ^~~~~~~~~~~~~~~~~~~~
   CC      arch/arm/domain_build.o
arch/arm/domain.c:348:30: error: ‘return_to_new_vcpu64’ undeclared (first
use in this function)
   348 |         reset_stack_and_jump(return_to_new_vcpu64);
       |                              ^~~~~~~~~~~~~~~~~~~~
./arch/arm/include/asm/current.h:48:65: note: in definition of macro
‘switch_stack_and_jump’
    48 |     asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack), "X" (fn)
: "memory" ); \
       |                                                                 ^~
arch/arm/domain.c:348:9: note: in expansion of macro ‘reset_stack_and_jump’
   348 |         reset_stack_and_jump(return_to_new_vcpu64);
       |         ^~~~~~~~~~~~~~~~~~~~
Quoted 1 line

make[2]: *** [Rules.mk:246: arch/arm/domain.o] Error 1

Quoted 6 lines

With this change, the compiler becomes aware that the functions idle_loop, return_to_new_vcpu32 and return_to_new_vcpu64 are used by the inline assembly. For idle loop, there is a previous declaration but for the other two there is not and when the compiler encounters their references complains. So, for this to compile, it is also required to declare return_to_new_vcpu32 and return_to_new_vcpu64.

Ah, right! I didn't read close enough the error message. I can see now that it builds just fine on both arm32 and arm64. I am fine with this.

#26 lore raw

Re: [PATCH 3/4] xen/arm: domain: Fix MISRA C 2012 Rule 8.7 violation

In reply to Stefano Stabellini
Quoted 6 lines · Stefano Stabellini
Quoted 1 line · Jan Beulich

You forgot the imo better intermediate option of using the "X" constraint.

I couldn't get "X" to compile in any way (not even for arm64). Do you have a concrete example that you think should work using "X" as constraint?

Perhaps you tried to use the respective input then as an operand to the insn? That won't work afaik - as Xenia says, it can be used only as a "fake" operand (i.e. one that tells the compiler something, but having no direct meaning for the insn).

Actually I thought we had uses of "X" already somewhere in Xen and/or XTF, but now that I looked I can't find any. (Anymore?)

Jan

#27 lore raw

PATCH 4/4 xen/char: pv_console: Fix MISRA C 2012 Rule 8.4 violation

In reply to Xenia Ragiadakou

The function pv_console_evtchn() is defined in the header <xen/pv_console.h>. If the header happens to be included by multiple files, this can result in linker errors due to multiple definitions,
So, it is more appropriate to resolve this MISRA C 2012 Rule 8.4 violation warning by making pv_console_evtchn() inline with internal linkage.

---
 xen/include/xen/pv_console.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/include/xen/pv_console.h +1 -1
index 4745f46f2d..a96a6368b1 100644
@@ -19,7 +19,7 @@ static inline void pv_console_set_rx_handler(serial_rx_fn fn) { }
 static inline void pv_console_init_postirq(void) { }
 static inline void pv_console_puts(const char *buf, size_t nr) { }
 static inline size_t pv_console_rx(struct cpu_user_regs *regs) { return 0; }
-evtchn_port_t pv_console_evtchn(void)
+static inline evtchn_port_t pv_console_evtchn(void)
 {
     ASSERT_UNREACHABLE();
     return 0;
Signature · 1 line
2.34.1
#28 lore raw

Re: [PATCH 4/4] xen/char: pv_console: Fix MISRA C 2012 Rule 8.4 violation

Hi Xenia,

Quoted 5 lines · Xenia Ragiadakou

The function pv_console_evtchn() is defined in the header <xen/pv_console.h>. If the header happens to be included by multiple files, this can result in linker errors due to multiple definitions,
So, it is more appropriate to resolve this MISRA C 2012 Rule 8.4 violation warning by making pv_console_evtchn() inline with internal linkage.

There are multiple version of pv_console_evtchn(). The version below is only used when !CONFIG_XEN_GUEST.

The header is also included multiple time within Xen. So I am a bit puzzled why we haven't seen this error before. Maybe this is unused when !CONFIG_XEN_GUEST?

If yes, I would remove the call. If no, then I think the commit message should be clarified.

Cheers,

Signature · 1 line
Julien Grall
#29 lore raw

Re: [PATCH 4/4] xen/char: pv_console: Fix MISRA C 2012 Rule 8.4 violation

Hi Julien,

Quoted 9 lines · Julien Grall

Hi Xenia,

Quoted 5 lines · Xenia Ragiadakou

The function pv_console_evtchn() is defined in the header <xen/pv_console.h>. If the header happens to be included by multiple files, this can result in linker errors due to multiple definitions,
So, it is more appropriate to resolve this MISRA C 2012 Rule 8.4 violation warning by making pv_console_evtchn() inline with internal linkage.

Quoted 5 lines

There are multiple version of pv_console_evtchn(). The version below is only used when !CONFIG_XEN_GUEST.

The header is also included multiple time within Xen. So I am a bit puzzled why we haven't seen this error before. Maybe this is unused when !CONFIG_XEN_GUEST?

If yes, I would remove the call. If no, then I think the commit message should be clarified.

You are right. I had to clarify that this holds when !CONFIG_XEN_GUEST.
So when !CONFIG_XEN_GUEST, the function pv_console_evtchn() is defined inside the header file and the header is included only by a single file. This is why the error has not been triggered.

Quoted 3 lines

Cheers,

Signature · 1 line
Xenia
#30 lore raw

Re: [PATCH 4/4] xen/char: pv_console: Fix MISRA C 2012 Rule 8.4 violation

Quoted 22 lines · Xenia Ragiadakou

Hi Julien,

Quoted 19 lines · Julien Grall

Hi Xenia,

Quoted 8 lines · Xenia Ragiadakou

The function pv_console_evtchn() is defined in the header <xen/pv_console.h>.
If the header happens to be included by multiple files, this can result in
linker errors due to multiple definitions,
So, it is more appropriate to resolve this MISRA C 2012 Rule 8.4 violation
warning by making pv_console_evtchn() inline with internal linkage.

There are multiple version of pv_console_evtchn(). The version below is only used when !CONFIG_XEN_GUEST.

The header is also included multiple time within Xen. So I am a bit puzzled why we haven't seen this error before. Maybe this is unused when !CONFIG_XEN_GUEST?

Quoted 7 lines
Quoted 2 lines

If yes, I would remove the call. If no, then I think the commit message should be clarified.

You are right. I had to clarify that this holds when !CONFIG_XEN_GUEST. So when !CONFIG_XEN_GUEST, the function pv_console_evtchn() is defined inside the header file and the header is included only by a single file. This is why the error has not been triggered.

Irrespective of that it is as Julien suspects: The function is only ever referenced when XEN_GUEST. Hence the better course of action indeed looks to be to ditch the unused stub; we don't even need DCE here for there to not be any references.

Jan

#31 lore raw

Re: [PATCH 4/4] xen/char: pv_console: Fix MISRA C 2012 Rule 8.4 violation

Quoted 31 lines · Jan Beulich
Quoted 22 lines · Xenia Ragiadakou

Hi Julien,

Quoted 19 lines · Julien Grall

Hi Xenia,

Quoted 8 lines · Xenia Ragiadakou

The function pv_console_evtchn() is defined in the header <xen/pv_console.h>.
If the header happens to be included by multiple files, this can result in
linker errors due to multiple definitions,
So, it is more appropriate to resolve this MISRA C 2012 Rule 8.4 violation
warning by making pv_console_evtchn() inline with internal linkage.

There are multiple version of pv_console_evtchn(). The version below is only used when !CONFIG_XEN_GUEST.

The header is also included multiple time within Xen. So I am a bit puzzled why we haven't seen this error before. Maybe this is unused when !CONFIG_XEN_GUEST?

Quoted 7 lines
Quoted 2 lines

If yes, I would remove the call. If no, then I think the commit message should be clarified.

You are right. I had to clarify that this holds when !CONFIG_XEN_GUEST. So when !CONFIG_XEN_GUEST, the function pv_console_evtchn() is defined inside the header file and the header is included only by a single file. This is why the error has not been triggered.

Quoted 4 lines

Irrespective of that it is as Julien suspects: The function is only ever referenced when XEN_GUEST. Hence the better course of action indeed looks to be to ditch the unused stub; we don't even need DCE here for there to not be any references.

Yes, if the function is not used at all when XEN_GUEST, then I think its definition is considered unreachable code (Rule 2.1) and needs to be removed.

Signature · 1 line
Xenia