xen/MISRA: Remove nonstandard inline keywords
cover xen/MISRA: Remove nonstandard inline keywords
Along with two minor pieces of cleanup in x86/apic found while doing this work.
Gitlab CI:
https://gitlab.com/xen-project/people/andyhhp/xen/-/pipelines/1081682400
Andrew Cooper (3):
x86/apic: Drop atomic accessors
x86/apic: Drop the APIC_MSR_BASE constant
xen/MISRA: Remove nonstandard inline keywords
.../eclair_analysis/ECLAIR/toolchain.ecl | 6 +-- docs/misra/C-language-toolchain.rst | 2 +- xen/arch/x86/include/asm/apic.h | 37 ++++++------------- xen/arch/x86/include/asm/apicdef.h | 3 -- xen/include/acpi/cpufreq/cpufreq.h | 4 +- xen/include/xen/bitops.h | 4 +- xen/include/xen/compiler.h | 7 ++-- 7 files changed, 23 insertions(+), 40 deletions(-)
base-commit: c22fe7213c9b1f99cbc64c33e391afa223f9cd08
Signature · 1 line
2.30.2
PATCH 1/3 x86/apic: Drop atomic accessors
The last users were dropped in commit 413e92e9bf13 ("x86/apic: Drop workarounds for Pentium/82489DX erratum").
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
--- xen/arch/x86/include/asm/apic.h | 13 ------------- 1 file changed, 13 deletions(-)
xen/arch/x86/include/asm/apic.h +0 -13
@@ -54,11 +54,6 @@ static __inline void apic_mem_write(unsigned long reg, u32 v) *((volatile u32 *)(APIC_BASE +reg)) = v; } -static __inlinevoid apic_mem_write_atomic (unsigned long reg,u32 v) -{ - (void )xchg ((volatile u32 *)(APIC_BASE +reg), v); -} -static __inlineu32 apic_mem_read (unsigned long reg) {return *((volatile u32 *)(APIC_BASE +reg));
@@ -97,14 +92,6 @@ static __inline void apic_write(unsigned long reg, u32 v)apic_mem_write (reg, v); } -static __inlinevoid apic_write_atomic (unsigned long reg,u32 v) -{ -if ( x2apic_enabled ) -apic_wrmsr (reg, v); -else -apic_mem_write_atomic (reg, v); -} -static __inlineu32 apic_read (unsigned long reg) {if ( x2apic_enabled )
Signature · 1 line
2.30.2
Re: [PATCH 1/3] x86/apic: Drop atomic accessors
Quoted 4 lines · Andrew Cooper
The last users were dropped in commit
413e92e9bf13("x86/apic: Drop workarounds for Pentium/82489DX erratum").Signed-off-by Andrew Cooper <[email protected]>
Quoted 43 lines
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>--- xen/arch/x86/include/asm/apic.h | 13 ------------- 1 file changed, 13 deletions(-)xen/arch/x86/include/asm/apic.h +0
-13@@ -54,11 +54,6 @@ static __inline void apic_mem_write(unsigned long reg, u32 v) *((volatile u32 *)(APIC_BASE +reg)) = v; } -static __inlinevoid apic_mem_write_atomic (unsigned long reg,u32 v) -{ - (void )xchg ((volatile u32 *)(APIC_BASE +reg), v); -} -static __inlineu32 apic_mem_read (unsigned long reg) {return *((volatile u32 *)(APIC_BASE +reg));@@ -97,14 +92,6 @@ static __inline void apic_write(unsigned long reg, u32 v)apic_mem_write (reg, v); } -static __inlinevoid apic_write_atomic (unsigned long reg,u32 v) -{ -if ( x2apic_enabled ) -apic_wrmsr (reg, v); -else -apic_mem_write_atomic (reg, v); -} -static __inlineu32 apic_read (unsigned long reg) {if ( x2apic_enabled )Signature · 1 line
2.30.2
PATCH 2/3 x86/apic: Drop the APIC_MSR_BASE constant
In reply to Andrew CooperUse MSR_X2APIC_FIRST from msr-index.h instead.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
--- xen/arch/x86/include/asm/apic.h | 4 ++-- xen/arch/x86/include/asm/apicdef.h | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-)
xen/arch/x86/include/asm/apic.h +2 -2
@@ -69,7 +69,7 @@ static __inline void apic_wrmsr(unsigned long reg, uint64_t msr_content) reg == APIC_LVR)return ; -wrmsrl (APIC_MSR_BASE + (reg >>4 ), msr_content); +wrmsrl (MSR_X2APIC_FIRST + (reg >>4 ), msr_content); }static __inlineuint64_t apic_rdmsr (unsigned long reg)
@@ -79,7 +79,7 @@ static __inline uint64_t apic_rdmsr(unsigned long reg)if (reg ==APIC_DFR )return -1u ; -rdmsrl (APIC_MSR_BASE + (reg >>4 ), msr_content); +rdmsrl (MSR_X2APIC_FIRST + (reg >>4 ), msr_content);return msr_content; }
xen/arch/x86/include/asm/apicdef.h +0 -3
@@ -124,9 +124,6 @@#define APIC_BASE __fix_to_virt(FIX_APIC_BASE) -/* It's only used in x2APIC mode of an x2APIC unit. */ -#define APIC_MSR_BASE 0x800 -#define MAX_IO_APICS 128extern bool x2apic_enabled;
Signature · 1 line
2.30.2
Re: [PATCH 2/3] x86/apic: Drop the APIC_MSR_BASE constant
Quoted 3 lines · Andrew Cooper
Use
MSR_X2APIC_FIRSTfrommsr-index.hinstead.Signed-off-by Andrew Cooper <[email protected]>
PATCH 3/3 xen/MISRA: Remove nonstandard inline keywords
In reply to Andrew CooperThe differences between inline, __inline and __inline__ keywords are a vestigial remnant of older C standards, and in Xen we use inline almost exclusively.
Replace __inline and __inline__ with regular inline, and remove their exceptions from the MISRA configuration.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Roberto Bagnara <[email protected]>
CC: Nicola Vetrini <[email protected]>
CC: Simone Ballarin <[email protected]>
I'm entirely guessing at the Eclair configuration.
--- .../eclair_analysis/ECLAIR/toolchain.ecl | 6 +++--- docs/misra/C-language-toolchain.rst | 2 +- xen/arch/x86/include/asm/apic.h | 20 +++++++++---------- xen/include/acpi/cpufreq/cpufreq.h | 4 ++-- xen/include/xen/bitops.h | 4 ++-- xen/include/xen/compiler.h | 7 +++---- 6 files changed, 21 insertions(+), 22 deletions(-)
automation/eclair_analysis/ECLAIR/toolchain.ecl +3 -3
@@ -15,7 +15,7 @@ _Static_assert: see Section \"2.1 C Language\" of "GCC_MANUAL". asm, __asm__: see Sections \"6.48 Alternate Keywords\" and \"6.47 How to Use Inline Assembly Language in C Code\" of "GCC_MANUAL". __volatile__: see Sections \"6.48 Alternate Keywords\" and \"6.47.2.1 Volatile\" of "GCC_MANUAL". - __const__, __inline__, __inline: see Section \"6.48 Alternate Keywords\" of "GCC_MANUAL". + __const__ : see Section \"6.48 Alternate Keywords\" of "GCC_MANUAL". typeof, __typeof__: see Section \"6.7 Referring to a Type with typeof\" of "GCC_MANUAL". __alignof__, __alignof: see Sections \"6.48 Alternate Keywords\" and \"6.44 Determining the Alignment of Functions, Types or Variables\" of "GCC_MANUAL". __attribute__: see Section \"6.39 Attribute Syntax\" of "GCC_MANUAL".
@@ -23,8 +23,8 @@ __builtin_va_arg: non-documented GCC extension. __builtin_offsetof: see Section \"6.53 Support for offsetof\" of "GCC_MANUAL". " --config=STD.tokenext,behavior+={c99, GCC_ARM64, "^(_Static_assert|asm|__asm__|__volatile__|__const__|__inline__|typeof|__typeof__|__alignof__|__attribute__|__builtin_types_compatible_p|__builtin_va_arg|__builtin_offsetof)$"} --config=STD.tokenext,behavior+={c99, GCC_X86_64, "^(_Static_assert|asm|__asm__|__volatile__|__const__|__inline__|__inline|typeof|__typeof__|__alignof__|__alignof|__attribute__|__builtin_types_compatible_p|__builtin_va_arg|__builtin_offsetof)$"} +-config=STD.tokenext,behavior+={c99, GCC_ARM64, "^(_Static_assert|asm|__asm__|__volatile__|__const__|typeof|__typeof__|__alignof__|__attribute__|__builtin_types_compatible_p|__builtin_va_arg|__builtin_offsetof)$"} +-config=STD.tokenext,behavior+={c99, GCC_X86_64, "^(_Static_assert|asm|__asm__|__volatile__|__const__|typeof|__typeof__|__alignof__|__alignof|__attribute__|__builtin_types_compatible_p|__builtin_va_arg|__builtin_offsetof)$"} -doc_end -doc_begin="Non-documented GCC extension."
docs/misra/C-language-toolchain.rst +1 -1
@@ -84,7 +84,7 @@ The table columns are as follows: see Sections "6.48 Alternate Keywords" and "6.47 How to Use Inline Assembly Language in C Code" of GCC_MANUAL. __volatile__: see Sections "6.48 Alternate Keywords" and "6.47.2.1 Volatile" of GCC_MANUAL. - __const__, __inline__, __inline: + __const__: see Section "6.48 Alternate Keywords" of GCC_MANUAL. typeof, __typeof__: see Section "6.7 Referring to a Type with typeof" of GCC_MANUAL.
xen/arch/x86/include/asm/apic.h +10 -10
@@ -49,12 +49,12 @@ const struct genapic *apic_x2apic_probe(void);* Basic functions accessing APICs. */ -static __inlinevoid apic_mem_write (unsigned long reg,u32 v) +static inline void apic_mem_write (unsigned long reg,u32 v) { *((volatile u32 *)(APIC_BASE +reg)) = v; } -static __inlineu32 apic_mem_read (unsigned long reg) +static inline u32 apic_mem_read (unsigned long reg) {return *((volatile u32 *)(APIC_BASE +reg)); }
@@ -63,7 +63,7 @@ static __inline u32 apic_mem_read(unsigned long reg)* access the 64-bit ICR register. */ -static __inlinevoid apic_wrmsr (unsigned long reg,uint64_t msr_content) +static inline void apic_wrmsr (unsigned long reg,uint64_t msr_content) {if (reg ==APIC_DFR || reg ==APIC_ID || reg ==APIC_LDR || reg ==APIC_LVR )
@@ -72,7 +72,7 @@ static __inline void apic_wrmsr(unsigned long reg, uint64_t msr_content)wrmsrl (MSR_X2APIC_FIRST + (reg >>4 ), msr_content); } -static __inlineuint64_t apic_rdmsr (unsigned long reg) +static inline uint64_t apic_rdmsr (unsigned long reg) {uint64_t msr_content;
@@ -83,7 +83,7 @@ static __inline uint64_t apic_rdmsr(unsigned long reg)return msr_content; } -static __inlinevoid apic_write (unsigned long reg,u32 v) +static inline void apic_write (unsigned long reg,u32 v) {if ( x2apic_enabled )
@@ -92,7 +92,7 @@ static __inline void apic_write(unsigned long reg, u32 v)apic_mem_write (reg, v); } -static __inlineu32 apic_read (unsigned long reg) +static inline u32 apic_read (unsigned long reg) {if ( x2apic_enabled )return apic_rdmsr (reg);
@@ -100,7 +100,7 @@ static __inline u32 apic_read(unsigned long reg)return apic_mem_read (reg); } -static __inlineu64 apic_icr_read (void ) +static inline u64 apic_icr_read (void ) {u32 lo, hi;
@@ -115,7 +115,7 @@ static __inline u64 apic_icr_read(void)return ((u64 )lo) | (((u64 )hi) <<32 ); } -static __inlinevoid apic_icr_write (u32 low,u32 dest) +static inline void apic_icr_write (u32 low,u32 dest) {if ( x2apic_enabled )apic_wrmsr (APIC_ICR , low | ((uint64_t )dest <<32 ));
@@ -126,13 +126,13 @@ static __inline void apic_icr_write(u32 low, u32 dest) } } -static __inlinebool apic_isr_read (uint8_t vector) +static inline bool apic_isr_read (uint8_t vector) {return (apic_read (APIC_ISR + ((vector & ~0x1f ) >>1 )) >> (vector &0x1f )) &1 ; } -static __inlineu32 get_apic_id (void )/* Get the physical APIC id */ +static inline u32 get_apic_id (void ) {u32 id =apic_read (APIC_ID );return x2apic_enabled ? id :GET_xAPIC_ID (id);
xen/include/acpi/cpufreq/cpufreq.h +2 -2
@@ -148,7 +148,7 @@ extern int cpufreq_driver_getavg(unsigned int cpu, unsigned int flag);extern int cpufreq_update_turbo (int cpuid,int new_state);extern int cpufreq_get_turbo_status (int cpuid); -static __inline__int +static inline int __cpufreq_governor (struct cpufreq_policy *policy,unsigned int event) {return policy->governor->governor (policy, event);
@@ -179,7 +179,7 @@ extern struct cpufreq_driver cpufreq_driver;int cpufreq_register_driver (const struct cpufreq_driver *); -static __inline__ +static inline void cpufreq_verify_within_limits (struct cpufreq_policy *policy,unsigned int min,unsigned int max) {
xen/include/xen/bitops.h +2 -2
@@ -127,7 +127,7 @@ static inline int generic_fls64(__u64 x)# endif #endif -static __inline__int get_bitmask_order (unsigned int count) +static inline int get_bitmask_order (unsigned int count) {int order;
@@ -135,7 +135,7 @@ static __inline__ int get_bitmask_order(unsigned int count)return order;/* We could be slightly more clever with -1 here... */ } -static __inline__int get_count_order (unsigned int count) +static inline int get_count_order (unsigned int count) {int order;
xen/include/xen/compiler.h +3 -4
@@ -20,9 +20,8 @@#define likely (x) __builtin_expect(!!(x),1)#define unlikely (x) __builtin_expect(!!(x),0) -#define inline __inline__ -#define always_inline __inline__ __attribute__ ((__always_inline__)) -#define gnu_inline __inline__ __attribute__ ((__gnu_inline__)) +#define always_inline inline __attribute__((__always_inline__)) +#define gnu_inline inline __attribute__((__gnu_inline__))#define noinline __attribute__((__noinline__))#define noreturn __attribute__((__noreturn__))
@@ -83,7 +82,7 @@* inline functions not expanded inline get placed in .init.text. */ #include <xen/init.h> -#define __inline__ __inline__ __init +#define inline inline __init#endif #define __attribute_pure__ __attribute__((__pure__))
Signature · 1 line
2.30.2
Quoted 17 lines · Andrew Cooper
The differences between inline,
__inlineand__inline__keywords are a vestigial remnant of older C standards, and in Xen we use inline almost exclusively.Replace
__inlineand__inline__with regular inline, and remove their exceptions from the MISRA configuration.Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Roberto Bagnara <[email protected]>
CC: Nicola Vetrini <[email protected]>
CC: Simone Ballarin <[email protected]>
Quoted 1 line
I'm entirely guessing at the Eclair configuration.
https://gitlab.com/xen-project/people/andyhhp/xen/-/jobs/5596360097 is Eclair running on this change, and it came back green
But I'll have to defer to bugsend to judge whether it was correctly configured.
~Andrew
Quoted 17 lines · Andrew Cooper
The differences between inline,
__inlineand__inline__keywords are a vestigial remnant of older C standards, and in Xen we use inline almost exclusively.Replace
__inlineand__inline__with regular inline, and remove their exceptions from the MISRA configuration.Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Roberto Bagnara <[email protected]>
CC: Nicola Vetrini <[email protected]>
CC: Simone Ballarin <[email protected]>
Quoted 2 lines
I'm entirely guessing at the Eclair configuration.
---
The configuration changes are ok. One observation below.
Quoted 78 lines
.../eclair_analysis/ECLAIR/toolchain.ecl | 6 +++--- docs/misra/C-language-toolchain.rst | 2 +- xen/arch/x86/include/asm/apic.h | 20 +++++++++---------- xen/include/acpi/cpufreq/cpufreq.h | 4 ++-- xen/include/xen/bitops.h | 4 ++-- xen/include/xen/compiler.h | 7 +++---- 6 files changed, 21 insertions(+), 22 deletions(-)automation/eclair_analysis/ECLAIR/toolchain.ecl +0
-0@@ -15,7 +15,7 @@ _Static_assert: see Section \"2.1 C Language\" of "GCC_MANUAL". asm, __asm__: see Sections \"6.48 Alternate Keywords\" and \"6.47How to Use Inline Assembly Language in C Code\" of "
GCC_MANUAL".
__volatile__: see Sections \"6.48 Alternate Keywords\" and
\"6.47.2.1 Volatile\" of "GCC_MANUAL".
-__const__,__inline__,__inline: see Section \"6.48 Alternate
Keywords\" of "GCC_MANUAL".
+__const__: see Section \"6.48 Alternate Keywords\" of
"GCC_MANUAL".
typeof,__typeof__: see Section \"6.7 Referring to a Type with
typeof\" of "GCC_MANUAL".
__alignof__,__alignof: see Sections \"6.48 Alternate Keywords\"
and \"6.44 Determining the Alignment of Functions, Types or Variables\" of "GCC_MANUAL".
__attribute__: see Section \"6.39 Attribute Syntax\" of
"GCC_MANUAL".automation/eclair_analysis/ECLAIR/toolchain.ecl +0
-0@@ -23,8 +23,8 @@ __builtin_va_arg: non-documented GCC extension. __builtin_offsetof: see Section \"6.53 Support for offsetof\" of"
GCC_MANUAL".
"
--config=STD.tokenext,behavior+={c99,GCC_ARM64, "^(_Static_assert|asm|__asm__|__volatile__|__const__|__inline__|typeof|__typeof__|__alignof__|__attribute__|__builtin_types_compatible_p|__builtin_va_arg|__builtin_offsetof)$"} --config=STD.tokenext,behavior+={c99,GCC_X86_64, "^(_Static_assert|asm|__asm__|__volatile__|__const__|__inline__|__inline|typeof|__typeof__|__alignof__|__alignof|__attribute__|__builtin_types_compatible_p|__builtin_va_arg|__builtin_offsetof)$"}+-config=STD.tokenext,behavior+={c99, GCC_ARM64, "^(_Static_assert|asm|__asm__|__volatile__|__const__|typeof|__typeof__|__alignof__|__attribute__|__builtin_types_compatible_p|__builtin_va_arg|__builtin_offsetof)$"} +-config=STD.tokenext,behavior+={c99, GCC_X86_64, "^(_Static_assert|asm|__asm__|__volatile__|__const__|typeof|__typeof__|__alignof__|__alignof|__attribute__|__builtin_types_compatible_p|__builtin_va_arg|__builtin_offsetof)$"}-doc_end
-doc_begin="Non-documented GCC extension."
docs/misra/C-language-toolchain.rst +0
-0@@ -84,7 +84,7 @@ The table columns are as follows: see Sections "6.48 Alternate Keywords" and "6.47 How to UseInline Assembly Language in C Code" of
GCC_MANUAL.__volatile__: see Sections "6.48 Alternate Keywords" and "6.47.2.1Volatile" of
GCC_MANUAL.docs/misra/C-language-toolchain.rst +1
-1- __const__, __inline__, __inline: + __const__: see Section "6.48 Alternate Keywords" of GCC_MANUAL. typeof, __typeof__: see Section "6.7 Referring to a Type with typeof" of
GCC_MANUAL.xen/include/xen/compiler.h +2
-3@@ -20,9 +20,8 @@#define likely (x) __builtin_expect(!!(x),1)#define unlikely (x) __builtin_expect(!!(x),0) -#define inline __inline__ -#define always_inline __inline__ __attribute__ ((__always_inline__)) -#define gnu_inline __inline__ __attribute__ ((__gnu_inline__)) +#define always_inline inline __attribute__((__always_inline__)) +#define gnu_inline inline __attribute__((__gnu_inline__))#define noinline __attribute__((__noinline__))#define noreturn __attribute__((__noreturn__))
xen/include/xen/compiler.h line 85
Quoted 5 lines
xen/include/xen/compiler.h +1
-1@@ -83,7 +82,7 @@* inline functions not expanded inline get placed in .init.text. */ #include <xen/init.h> -#define __inline__ __inline__ __init +#define inline inline __init
The violation of Rule 20.4 (A macro shall not be defined with the same name as a keyword) is still present due to this macro.
Quoted 3 lines
xen/include/xen/compiler.h +0
-0#endif #define __attribute_pure__ __attribute__((__pure__))
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Quoted 18 lines · Nicola Vetrini
Quoted 17 lines · Andrew Cooper
The differences between inline,
__inlineand__inline__keywords are a vestigial remnant of older C standards, and in Xen we use inline almost exclusively.Replace
__inlineand__inline__with regular inline, and remove their exceptions from the MISRA configuration.Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Roberto Bagnara <[email protected]>
CC: Nicola Vetrini <[email protected]>
CC: Simone Ballarin <[email protected]>
Quoted 4 lines
Quoted 2 lines
I'm entirely guessing at the Eclair configuration.
---The configuration changes are ok. One observation below.
Thanks. Can I take that as an Ack/Reviewed-by ?
Quoted 5 lines
Quoted 5 lines
xen/include/xen/compiler.h +0
-0@@ -83,7 +82,7 @@
Quoted 8 lines
xen/include/xen/compiler.h line 85
Quoted 5 lines
xen/include/xen/compiler.h +1
-1* inline functions not expanded inline get placed in .init.text. */ #include <xen/init.h> -#define __inline__ __inline__ __init +#define inline inline __initThe violation of Rule 20.4 (A macro shall not be defined with the same name as a keyword) is still present due to this macro.
I was expecting this to come up.
There's a comment half out of context above, but to expand on it, we have a feature in the build system where if you say obj-y += foo.init.o then it gets compiled as normal and then all symbols checked for being in the relevant .init sections. It's a safeguard around init-only code ending up in the runtime image (which is good for other goals of safety).
This particular define is necessary to cause out-of-lined static inlines to end up in the right section, without having to invent a new __inline_or_init macro and rewriting half the header files in the project.
I think it's going to need a local deviation. It's deliberate, and all we're doing is using the inline keyword to hook in an extra __section() attribute.
~Andrew
Quoted 19 lines · Andrew Cooper
Quoted 18 lines · Nicola Vetrini
Quoted 17 lines · Andrew Cooper
The differences between inline,
__inlineand__inline__keywords are a vestigial remnant of older C standards, and in Xen we use inline almost exclusively.Replace
__inlineand__inline__with regular inline, and remove their exceptions from the MISRA configuration.Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Roberto Bagnara <[email protected]>
CC: Nicola Vetrini <[email protected]>
CC: Simone Ballarin <[email protected]>
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
I'm entirely guessing at the Eclair configuration.
---The configuration changes are ok. One observation below.
Thanks. Can I take that as an Ack/Reviewed-by ?
I see that Simone already gave one; that should suffice.
Quoted 26 lines
Quoted 5 lines
Quoted 5 lines
xen/include/xen/compiler.h +0
-0@@ -83,7 +82,7 @@Quoted 8 lines
xen/include/xen/compiler.h line 85
Quoted 5 lines
xen/include/xen/compiler.h +1
-1* inline functions not expanded inline get placed in .init.text. */ #include <xen/init.h> -#define __inline__ __inline__ __init +#define inline inline __initThe violation of Rule 20.4 (A macro shall not be defined with the same name as a keyword) is still present due to this macro.
I was expecting this to come up.
There's a comment half out of context above, but to expand on it, we have a feature in the build system where if you say obj-y += foo.init.o then it gets compiled as normal and then all symbols checked for being in the relevant .init sections. It's a safeguard around init-only code ending up in the runtime image (which is good for other goals of safety).
This particular define is necessary to cause out-of-lined static inlines to end up in the right section, without having to invent a new
__inline_or_initmacro and rewriting half the header files in the project.
Quoted 5 lines
I think it's going to need a local deviation. It's deliberate, and all we're doing is using the inline keyword to hook in an extra
__section()attribute.~Andrew
That's fair. I also agree that an exception for this use of inline can be made.
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Quoted 213 lines · Andrew Cooper
The differences between inline,
__inlineand__inline__keywords are a vestigial remnant of older C standards, and in Xen we use inline almost exclusively.Replace
__inlineand__inline__with regular inline, and remove their exceptions from the MISRA configuration.Signed-off-by Andrew Cooper <[email protected]>--- > CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Roberto Bagnara <[email protected]>
CC: Nicola Vetrini <[email protected]>
CC: Simone Ballarin <[email protected]>I'm entirely guessing at the Eclair configuration.
--- .../eclair_analysis/ECLAIR/toolchain.ecl | 6 +++--- docs/misra/C-language-toolchain.rst | 2 +- xen/arch/x86/include/asm/apic.h | 20 +++++++++---------- xen/include/acpi/cpufreq/cpufreq.h | 4 ++-- xen/include/xen/bitops.h | 4 ++-- xen/include/xen/compiler.h | 7 +++---- 6 files changed, 21 insertions(+), 22 deletions(-)automation/eclair_analysis/ECLAIR/toolchain.ecl +3
-3@@ -15,7 +15,7 @@ _Static_assert: see Section \"2.1 C Language\" of "GCC_MANUAL". asm, __asm__: see Sections \"6.48 Alternate Keywords\" and \"6.47 How to Use Inline Assembly Language in C Code\" of "GCC_MANUAL". __volatile__: see Sections \"6.48 Alternate Keywords\" and \"6.47.2.1 Volatile\" of "GCC_MANUAL". - __const__, __inline__, __inline: see Section \"6.48 Alternate Keywords\" of "GCC_MANUAL". + __const__ : see Section \"6.48 Alternate Keywords\" of "GCC_MANUAL". typeof, __typeof__: see Section \"6.7 Referring to a Type with typeof\" of "GCC_MANUAL". __alignof__, __alignof: see Sections \"6.48 Alternate Keywords\" and \"6.44 Determining the Alignment of Functions, Types or Variables\" of "GCC_MANUAL". __attribute__: see Section \"6.39 Attribute Syntax\" of "GCC_MANUAL".@@ -23,8 +23,8 @@ __builtin_va_arg: non-documented GCC extension. __builtin_offsetof: see Section \"6.53 Support for offsetof\" of "GCC_MANUAL". " --config=STD.tokenext,behavior+={c99, GCC_ARM64, "^(_Static_assert|asm|__asm__|__volatile__|__const__|__inline__|typeof|__typeof__|__alignof__|__attribute__|__builtin_types_compatible_p|__builtin_va_arg|__builtin_offsetof)$"} --config=STD.tokenext,behavior+={c99, GCC_X86_64, "^(_Static_assert|asm|__asm__|__volatile__|__const__|__inline__|__inline|typeof|__typeof__|__alignof__|__alignof|__attribute__|__builtin_types_compatible_p|__builtin_va_arg|__builtin_offsetof)$"} +-config=STD.tokenext,behavior+={c99, GCC_ARM64, "^(_Static_assert|asm|__asm__|__volatile__|__const__|typeof|__typeof__|__alignof__|__attribute__|__builtin_types_compatible_p|__builtin_va_arg|__builtin_offsetof)$"} +-config=STD.tokenext,behavior+={c99, GCC_X86_64, "^(_Static_assert|asm|__asm__|__volatile__|__const__|typeof|__typeof__|__alignof__|__alignof|__attribute__|__builtin_types_compatible_p|__builtin_va_arg|__builtin_offsetof)$"} -doc_end -doc_begin="Non-documented GCC extension."docs/misra/C-language-toolchain.rst +1
-1@@ -84,7 +84,7 @@ The table columns are as follows: see Sections "6.48 Alternate Keywords" and "6.47 How to Use Inline Assembly Language in C Code" of GCC_MANUAL. __volatile__: see Sections "6.48 Alternate Keywords" and "6.47.2.1 Volatile" of GCC_MANUAL. - __const__, __inline__, __inline: + __const__: see Section "6.48 Alternate Keywords" of GCC_MANUAL. typeof, __typeof__: see Section "6.7 Referring to a Type with typeof" of GCC_MANUAL.xen/arch/x86/include/asm/apic.h +10
-10@@ -49,12 +49,12 @@ const struct genapic *apic_x2apic_probe(void);* Basic functions accessing APICs. */ -static __inlinevoid apic_mem_write (unsigned long reg,u32 v) +static inline void apic_mem_write (unsigned long reg,u32 v) { *((volatile u32 *)(APIC_BASE +reg)) = v; } -static __inlineu32 apic_mem_read (unsigned long reg) +static inline u32 apic_mem_read (unsigned long reg) {return *((volatile u32 *)(APIC_BASE +reg)); }@@ -63,7 +63,7 @@ static __inline u32 apic_mem_read(unsigned long reg)* access the 64-bit ICR register. */ -static __inlinevoid apic_wrmsr (unsigned long reg,uint64_t msr_content) +static inline void apic_wrmsr (unsigned long reg,uint64_t msr_content) {if (reg ==APIC_DFR || reg ==APIC_ID || reg ==APIC_LDR || reg ==APIC_LVR )@@ -72,7 +72,7 @@ static __inline void apic_wrmsr(unsigned long reg, uint64_t msr_content)wrmsrl (MSR_X2APIC_FIRST + (reg >>4 ), msr_content); } -static __inlineuint64_t apic_rdmsr (unsigned long reg) +static inline uint64_t apic_rdmsr (unsigned long reg) {uint64_t msr_content;@@ -83,7 +83,7 @@ static __inline uint64_t apic_rdmsr(unsigned long reg)return msr_content; } -static __inlinevoid apic_write (unsigned long reg,u32 v) +static inline void apic_write (unsigned long reg,u32 v) {if ( x2apic_enabled )@@ -92,7 +92,7 @@ static __inline void apic_write(unsigned long reg, u32 v)apic_mem_write (reg, v); } -static __inlineu32 apic_read (unsigned long reg) +static inline u32 apic_read (unsigned long reg) {if ( x2apic_enabled )return apic_rdmsr (reg);@@ -100,7 +100,7 @@ static __inline u32 apic_read(unsigned long reg)return apic_mem_read (reg); } -static __inlineu64 apic_icr_read (void ) +static inline u64 apic_icr_read (void ) {u32 lo, hi;@@ -115,7 +115,7 @@ static __inline u64 apic_icr_read(void)return ((u64 )lo) | (((u64 )hi) <<32 ); } -static __inlinevoid apic_icr_write (u32 low,u32 dest) +static inline void apic_icr_write (u32 low,u32 dest) {if ( x2apic_enabled )apic_wrmsr (APIC_ICR , low | ((uint64_t )dest <<32 ));@@ -126,13 +126,13 @@ static __inline void apic_icr_write(u32 low, u32 dest) } } -static __inlinebool apic_isr_read (uint8_t vector) +static inline bool apic_isr_read (uint8_t vector) {return (apic_read (APIC_ISR + ((vector & ~0x1f ) >>1 )) >> (vector &0x1f )) &1 ; } -static __inlineu32 get_apic_id (void )/* Get the physical APIC id */ +static inline u32 get_apic_id (void ) {u32 id =apic_read (APIC_ID );return x2apic_enabled ? id :GET_xAPIC_ID (id);xen/include/acpi/cpufreq/cpufreq.h +2
-2@@ -148,7 +148,7 @@ extern int cpufreq_driver_getavg(unsigned int cpu, unsigned int flag);extern int cpufreq_update_turbo (int cpuid,int new_state);extern int cpufreq_get_turbo_status (int cpuid); -static __inline__int +static inline int __cpufreq_governor (struct cpufreq_policy *policy,unsigned int event) {return policy->governor->governor (policy, event);@@ -179,7 +179,7 @@ extern struct cpufreq_driver cpufreq_driver;int cpufreq_register_driver (const struct cpufreq_driver *); -static __inline__ +static inline void cpufreq_verify_within_limits (struct cpufreq_policy *policy,unsigned int min,unsigned int max) {xen/include/xen/bitops.h +2
-2@@ -127,7 +127,7 @@ static inline int generic_fls64(__u64 x)# endif #endif -static __inline__int get_bitmask_order (unsigned int count) +static inline int get_bitmask_order (unsigned int count) {int order;@@ -135,7 +135,7 @@ static __inline__ int get_bitmask_order(unsigned int count)return order;/* We could be slightly more clever with -1 here... */ } -static __inline__int get_count_order (unsigned int count) +static inline int get_count_order (unsigned int count) {int order;xen/include/xen/compiler.h +2
-3@@ -20,9 +20,8 @@#define likely (x) __builtin_expect(!!(x),1)#define unlikely (x) __builtin_expect(!!(x),0) -#define inline __inline__ -#define always_inline __inline__ __attribute__ ((__always_inline__)) -#define gnu_inline __inline__ __attribute__ ((__gnu_inline__)) +#define always_inline inline __attribute__((__always_inline__)) +#define gnu_inline inline __attribute__((__gnu_inline__))#define noinline __attribute__((__noinline__))#define noreturn __attribute__((__noreturn__))
xen/include/xen/compiler.h line 88
Quoted 8 lines
xen/include/xen/compiler.h +1
-1@@ -83,7 +82,7 @@* inline functions not expanded inline get placed in .init.text. */ #include <xen/init.h> -#define __inline__ __inline__ __init +#define inline inline __init#endif #define __attribute_pure__ __attribute__((__pure__))
Signature · 3 lines
Simone Ballarin, M.Sc. Field Application Engineer, BUGSENG (https://bugseng.com)
Quoted 14 lines · Andrew Cooper
The differences between inline,
__inlineand__inline__keywords are a vestigial remnant of older C standards, and in Xen we use inline almost exclusively.Replace
__inlineand__inline__with regular inline, and remove their exceptions from the MISRA configuration.Signed-off-by Andrew Cooper <[email protected]>docs/misra/C-language-toolchain.rst +0
-0
docs/misra/C-language-toolchain.rst The table columns are as follows: · line 90
Quoted 8 lines
docs/misra/C-language-toolchain.rst +1
-1@@ -84,7 +84,7 @@ The table columns are as follows: see Sections "6.48 Alternate Keywords" and "6.47 How to Use Inline Assembly Language in C Code" of GCC_MANUAL. __volatile__: see Sections "6.48 Alternate Keywords" and "6.47.2.1 Volatile" of GCC_MANUAL. - __const__, __inline__, __inline: + __const__: see Section "6.48 Alternate Keywords" of GCC_MANUAL. typeof, __typeof__: see Section "6.7 Referring to a Type with typeof" of GCC_MANUAL.
Asking the Bugseng guys as well, do we need to add to C-language-toolchain.rst:
inline __attribute__((__always_inline__)) inline __attribute__((__gnu_inline__))
Given that the problem was also present before this patch:
Quoted 6 lines
xen/include/xen/compiler.h +0
-0@@ -20,9 +20,8 @@#define likely (x) __builtin_expect(!!(x),1)
xen/include/xen/compiler.h line 27
Quoted 10 lines
xen/include/xen/compiler.h +2
-3#define unlikely (x) __builtin_expect(!!(x),0) -#define inline __inline__ -#define always_inline __inline__ __attribute__ ((__always_inline__)) -#define gnu_inline __inline__ __attribute__ ((__gnu_inline__)) +#define always_inline inline __attribute__((__always_inline__)) +#define gnu_inline inline __attribute__((__gnu_inline__))#define noinline __attribute__((__noinline__))#define noreturn __attribute__((__noreturn__))
This is where they are used.
Quoted 13 lines
xen/include/xen/compiler.h +1
-1@@ -83,7 +82,7 @@* inline functions not expanded inline get placed in .init.text. */ #include <xen/init.h> -#define __inline__ __inline__ __init +#define inline inline __init#endif #define __attribute_pure__ __attribute__((__pure__))Signature · 1 line
2.30.2
Quoted 19 lines · Stefano Stabellini
Quoted 18 lines · Andrew Cooper
The differences between inline,
__inlineand__inline__keywords are a vestigial remnant of older C standards, and in Xen we use inline almost exclusively.Replace
__inlineand__inline__with regular inline, and remove their exceptions from the MISRA configuration.Signed-off-by Andrew Cooper <[email protected]>docs/misra/C-language-toolchain.rst +0
-1@@ -84,7 +84,7 @@ The table columns are as follows: see Sections "6.48 Alternate Keywords" and "6.47 How to Use Inline Assembly Language in C Code" of GCC_MANUAL. __volatile__: see Sections "6.48 Alternate Keywords" and "6.47.2.1 Volatile" of GCC_MANUAL. - __const__, __inline__, __inline:
Quoted 8 lines
docs/misra/C-language-toolchain.rst The table columns are as follows: · line 90
Quoted 4 lines
docs/misra/C-language-toolchain.rst +1
-0+ __const__: see Section "6.48 Alternate Keywords" of GCC_MANUAL. typeof, __typeof__: see Section "6.7 Referring to a Type with typeof" of GCC_MANUAL.Asking the Bugseng guys as well, do we need to add to
C-language-toolchain.rst:
inline __attribute__((__always_inline__)) inline __attribute__((__gnu_inline__))
__attribute__ itself is in the list of permitted non-standard tokens, in both files.
However, neither file has anything concerning the parameter(s) to the __attribute__, and we do use an awful lot of them.
If they want discussing, then that's going to be a lot of work.
Quoted 3 lines
Given that the problem was also present before this patch:
Reviewed-by Stefano Stabellini <[email protected]>
Thanks.
Quoted 32 lines · Andrew Cooper
Quoted 22 lines · Stefano Stabellini
Quoted 21 lines · Andrew Cooper
The differences between inline,
__inlineand__inline__keywords are a vestigial remnant of older C standards, and in Xen we use inline almost exclusively.Replace
__inlineand__inline__with regular inline, and remove their exceptions from the MISRA configuration.Signed-off-by Andrew Cooper <[email protected]>docs/misra/C-language-toolchain.rst +0
-0@@ -84,7 +84,7 @@ The table columns are as follows: see Sections "6.48 Alternate Keywords" and "6.47 How toUse Inline Assembly Language in C Code" of
GCC_MANUAL.__volatile__: see Sections "6.48 Alternate Keywords" and "6.47.2.1Volatile" of
GCC_MANUAL.docs/misra/C-language-toolchain.rst +1
-1- __const__, __inline__, __inline: + __const__:Quoted 8 lines
Quoted 4 lines
see Section "6.48 Alternate Keywords" of
GCC_MANUAL.
typeof,__typeof__:
see Section "6.7 Referring to a Type with typeof" ofGCC_MANUAL.Asking the Bugseng guys as well, do we need to add to
C-language-toolchain.rst:
inline __attribute__((__always_inline__)) inline __attribute__((__gnu_inline__))
Quoted 8 lines
__attribute__itself is in the list of permitted non-standard tokens, in both files.However, neither file has anything concerning the parameter(s) to the
__attribute__, and we do use an awful lot of them.If they want discussing, then that's going to be a lot of work.
Just __attribute__ is fine, since we point to
Section "6.39 Attribute Syntax" of GCC_MANUAL.
which describes the syntax for the token and gives pointers to other relevant sections of the manual.
Quoted 5 lines
Quoted 3 lines
Given that the problem was also present before this patch:
Reviewed-by Stefano Stabellini <[email protected]>Thanks.
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)