Skip to contentSkip to conversation

fix missing headers and static storage duration

PATCH In review Nicola Vetrini 2 participants 11 messages Aug 10, 2023

lore
Share & tools
lore
#0 lore raw

v2 cover fix missing headers and static storage duration

The files touched by this series contain function or variable definitions with no prior declaration visible, because it's inside an header that is not included or it's not present anywhere. This is a risk in itself, but also violates MISRA C:2012 Rule 8.4, which states the following:
"A compatible declaration shall be visible when an object or function with external linkage is defined".

The resolution strategies are as follows:

1. make the functions/variables static
2. include the header that contains the compatible declaration, or add one in the header if that's not the case.

No functional change.

Additional notes:
- other cases, such as functions/variables used only in asm code will be possibly dealt with in future patches.
- functions in 'gcov_base.c' are deviated, since they are called only from code generated by gcc in a particular non-release build configuration;
- variables in 'xen/include/acpi/acglobal.h' are deviated temporarily, since it's uncertain whether modifying the include pattern to be compliant with the rule would introduce subtle bugs.

---
Changes in v2:
- Modified commit messages, with additional "Fixed" tags and mention that these are bugfixes
- Split patch 4/8 of the previous version
- Drop patch 7/8 of the previous version, because it's already addressed by this patch [1]

[1] https://lists.xen.org/archives/html/xen-devel/2023-05/msg00896.html

Nicola Vetrini (7):
xen/memory: make 'ioreq_server_max_frames' static
xen: make 'saved_cmdline' static
xen/include: make a declaration of 'get_sec' visible where needed xen/arm: make declarations visible before function definitions
x86: make some functions and variables static rather than extern xen/arm: mm: add missing extern variable declaration x86/nmi: include missing header with declarations for 'watchdog_*'

 xen/arch/arm/include/asm/mm.h     | 3 +++
 xen/arch/arm/setup.c              | 1 +
 xen/arch/arm/time.c               | 1 +
 xen/arch/x86/cpu/mcheck/mce.c     | 2 +-
 xen/arch/x86/cpu/mcheck/mce_amd.c | 2 +-
 xen/arch/x86/cpu/microcode/core.c | 2 +-
 xen/arch/x86/nmi.c                | 3 ++-
 xen/arch/x86/spec_ctrl.c          | 4 ++--
 xen/common/kernel.c               | 2 +-
 xen/common/memory.c               | 2 +-
 xen/include/xen/cper.h            | 3 +--
 xen/include/xen/time.h            | 1 +
 12 files changed, 16 insertions(+), 10 deletions(-)

--
2.34.1

#1 lore raw

PATCH v2 1/7 xen/memory: make 'ioreq_server_max_frames' static

The function 'ioreq_server_max_frames' can be defined static, as its only uses are within the same file. This in turn avoids violating Rule 8.4 because no declaration is present.

No functional change.

Fixes 9244528955de ("xen/memory: Fix acquire_resource size semantics”)

---
Changes in v2:
- Revised commit message

---
 xen/common/memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/memory.c +1 -1
index c206fa48087d..b1dcbaf551e6 100644
@@ -1120,7 +1120,7 @@ static long xatp_permission_check(struct domain *d, unsigned int space)
     return xsm_add_to_physmap(XSM_TARGET, current->domain, d);
 }
 
-unsigned int ioreq_server_max_frames(const struct domain *d)
+static unsigned int ioreq_server_max_frames(const struct domain *d)
 {
     unsigned int nr = 0;
 
Signature · 1 line
2.34.1
#2 lore raw

Re: [XEN PATCH v2 1/7] xen/memory: make 'ioreq_server_max_frames' static

Quoted 3 lines · Nicola Vetrini

The function 'ioreq_server_max_frames' can be defined static, as its only uses are within the same file. This in turn avoids violating Rule 8.4 because no declaration is present.

Here and presumably in subsequent patches (I only looked at patch 2 for now) you're now missing the word Misra (ahead of Rule). I'm happy for that to be added while committing.

Jan

#3 lore raw

PATCH v2 2/7 xen: make 'saved_cmdline' static

In reply to Nicola Vetrini

The variable 'saved_cmdline' can be defined static, as its only uses are within the same file. This in turn avoids violating Rule 8.4 because no declaration is present.

Fixes e6ee01ad24b6 ("xen/version: Drop compat/kernel.c")

---
Changes in v2:
- Revised commit message

---
 xen/common/kernel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/kernel.c +1 -1
index fb919f3d9c38..52aa28762782 100644
@@ -28,7 +28,7 @@ CHECK_feature_info;
 
 enum system_state system_state = SYS_STATE_early_boot;
 
-xen_commandline_t saved_cmdline;
+static xen_commandline_t saved_cmdline;
 static const char __initconst opt_builtin_cmdline[] = CONFIG_CMDLINE;
 
 static int assign_integer_param(const struct kernel_param *param, uint64_t val)
Signature · 1 line
2.34.1
#4 lore raw

PATCH v2 3/7 xen/include: make a declaration of 'get_sec' visible where needed

In reply to Nicola Vetrini

A declaration for 'get_sec' is added in 'xen/include/xen/time.h' to be available for every call site (in particular 'cper.h'). This also resolves a violation of MISRA C:2012 Rule 8.4.

Fixes c8cb30cfc87a ("mce: Provide ERST interface")

---
Changes in v2:
- Revised commit message
- Split patch

---
 xen/include/xen/cper.h | 3 +--
 xen/include/xen/time.h | 1 +
 2 files changed, 2 insertions(+), 2 deletions(-)
xen/include/xen/cper.h +1 -2
index 7c6a4c45ce32..de8f385bdd5c 100644
@@ -23,8 +23,7 @@
 
 #include <xen/types.h>
 #include <xen/string.h>
-
-extern unsigned long get_sec(void);
+#include <xen/time.h>
 
 typedef struct {
 	uint8_t b[16];
xen/include/xen/time.h +1 -0
index 5aafdda4f392..67c586b7369c 100644
@@ -36,6 +36,7 @@ s_time_t get_s_time_fixed(u64 at_tick);
 s_time_t get_s_time(void);
 unsigned long get_localtime(struct domain *d);
 uint64_t get_localtime_us(struct domain *d);
+unsigned long get_sec(void);
 
 struct tm {
     int     tm_sec;         /* seconds */
Signature · 1 line
2.34.1
Reviewed-by on v2 3/7
#5 lore raw

Re: [XEN PATCH v2 3/7] xen/include: make a declaration of 'get_sec' visible where needed

Quoted 6 lines · Nicola Vetrini

A declaration for 'get_sec' is added in 'xen/include/xen/time.h' to be available for every call site (in particular 'cper.h'). This also resolves a violation of MISRA C:2012 Rule 8.4.

Fixes c8cb30cfc87a ("mce: Provide ERST interface")
#6 lore raw

PATCH v2 4/7 xen/arm: make declarations visible before function definitions

In reply to Nicola Vetrini

'xen/hypercall.h' is included in 'xen/arch/arm/setup.c' to allow the declaration of 'arch_get_xen_caps' to be visible when defining the function.

The header 'xen/delay.h' is included in 'xen/arch/arm/time.c' to allow the declaration of 'udelay' to be visible.

Fixes 7cfc339cbc2f ("arm: Implement arch_get_xen_caps")
Fixes 335ba242c55c ("arm: implement udelay()")

---
Changes in v2:
- Revised commit message
- Split patch

---
 xen/arch/arm/setup.c | 1 +
 xen/arch/arm/time.c  | 1 +
 2 files changed, 2 insertions(+)
xen/arch/arm/setup.c +1 -0
index bbf72b69aae6..44ccea03ca14 100644
@@ -32,6 +32,7 @@
 #include <xen/libfdt/libfdt-xen.h>
 #include <xen/acpi.h>
 #include <xen/warning.h>
+#include <xen/hypercall.h>
 #include <asm/alternative.h>
 #include <asm/page.h>
 #include <asm/current.h>
xen/arch/arm/time.c +1 -0
index 0b482d7db30c..3535bd8ac7c7 100644
@@ -17,6 +17,7 @@
 #include <xen/softirq.h>
 #include <xen/sched.h>
 #include <xen/time.h>
+#include <xen/delay.h>
 #include <xen/sched.h>
 #include <xen/event.h>
 #include <xen/acpi.h>
Signature · 1 line
2.34.1
#7 lore raw

PATCH v2 5/7 x86: make some functions and variables static rather than extern

In reply to Nicola Vetrini

The functions and variables touched by this commit can be static, as they are only used within the same unit. This in turn addresses the absence of declarations that violates Rule 8.4.

Fixes 741367e77d6c ("mce: Clean-up mcheck_init handler")
Fixes 45f57813f646 ("x86/MCE: implement recoverscan for AMD")
Fixes 155587481e39 ("x86/microcode: Scan the initramfs payload for microcode blob")
Fixes af50dd63cf8d ("Pull nmi/traps changes from Linux 2.6.14.")
Fixes fef244b179c0 ("x86/spec-ctrl: Knobs for STIBP and PSFD, and follow hardware STIBP hint")

---
Changes in v2:
- Revised commit message

I'm a bit uncertain about af50dd63cf8d, because it was done long ago and it's not clear whether the variable could have been static since then.

---
 xen/arch/x86/cpu/mcheck/mce.c     | 2 +-
 xen/arch/x86/cpu/mcheck/mce_amd.c | 2 +-
 xen/arch/x86/cpu/microcode/core.c | 2 +-
 xen/arch/x86/nmi.c                | 2 +-
 xen/arch/x86/spec_ctrl.c          | 4 ++--
 5 files changed, 6 insertions(+), 6 deletions(-)
xen/arch/x86/cpu/mcheck/mce.c +1 -1
index 57e1eb221e6b..6141b7eb9cf1 100644
@@ -599,7 +599,7 @@ unsigned int mce_firstbank(struct cpuinfo_x86 *c)
            c->x86_vendor == X86_VENDOR_INTEL && c->x86_model < 0x1a;
 }
 
-int show_mca_info(int inited, struct cpuinfo_x86 *c)
+static int show_mca_info(int inited, struct cpuinfo_x86 *c)
 {
     static enum mcheck_type g_type = mcheck_unset;
 
xen/arch/x86/cpu/mcheck/mce_amd.c +1 -1
index adc36522cc27..72f3feeaeed8 100644
@@ -87,7 +87,7 @@ enum mc_ec_type {
     MC_EC_BUS_TYPE = 0x0800,
 };
 
-enum mc_ec_type
+static enum mc_ec_type
 mc_ec2type(uint16_t errorcode)
 {
     if ( errorcode & MC_EC_BUS_TYPE )
xen/arch/x86/cpu/microcode/core.c +1 -1
index bec8b55db256..9fcb9c1c3a90 100644
@@ -149,7 +149,7 @@ static int __init cf_check parse_ucode(const char *s)
 }
 custom_param("ucode", parse_ucode);
 
-void __init microcode_scan_module(
+static void __init microcode_scan_module(
     unsigned long *module_map,
     const multiboot_info_t *mbi)
 {
xen/arch/x86/nmi.c +1 -1
index c5c28300b04d..104e366bd310 100644
@@ -108,7 +108,7 @@ static unsigned int lapic_nmi_owner;
  *     be enabled
  * -1: the lapic NMI watchdog is disabled, but can be enabled
  */
-int nmi_active;
+static int nmi_active;
 
 #define K7_EVNTSEL_ENABLE	(1 << 22)
 #define K7_EVNTSEL_INT		(1 << 20)
xen/arch/x86/spec_ctrl.c +2 -2
index ebe56a96cdca..9b8fdb5303ad 100644
@@ -43,9 +43,9 @@ static enum ind_thunk {
 } opt_thunk __initdata = THUNK_DEFAULT;
 
 static int8_t __initdata opt_ibrs = -1;
-int8_t __initdata opt_stibp = -1;
+static int8_t __initdata opt_stibp = -1;
 bool __ro_after_init opt_ssbd;
-int8_t __initdata opt_psfd = -1;
+static int8_t __initdata opt_psfd = -1;
 
 int8_t __ro_after_init opt_ibpb_ctxt_switch = -1;
 int8_t __read_mostly opt_eager_fpu = -1;
Signature · 1 line
2.34.1
Reviewed-by on v2 5/7
#8 lore raw

Re: [XEN PATCH v2 5/7] x86: make some functions and variables static rather than extern

Quoted 10 lines · Nicola Vetrini

The functions and variables touched by this commit can be static, as they are only used within the same unit. This in turn addresses the absence of declarations that violates Rule 8.4.

Fixes 741367e77d6c ("mce: Clean-up mcheck_init handler")
Fixes 45f57813f646 ("x86/MCE: implement recoverscan for AMD")
Fixes 155587481e39 ("x86/microcode: Scan the initramfs payload for microcode blob")
Fixes af50dd63cf8d ("Pull nmi/traps changes from Linux 2.6.14.")
Fixes fef244b179c0 ("x86/spec-ctrl: Knobs for STIBP and PSFD, and follow hardware STIBP hint")
#9 lore raw

PATCH v2 6/7 xen/arm: mm: add missing extern variable declaration

In reply to Nicola Vetrini

Add a declaration for the variable 'init_ttbr' to resolve the violation of Rule 8.4 present the relative source file 'mm.c'.

No functional changes.

Fixes 4557c2292854 ("xen: arm: rewrite start of day page table and cpu bring up")

---
Changes in v2:
- Revised commit message

---
 xen/arch/arm/include/asm/mm.h | 3 +++
 1 file changed, 3 insertions(+)
xen/arch/arm/include/asm/mm.h +3 -0
index 2db8535a4ca8..aaacba3f044b 100644
@@ -165,6 +165,9 @@ struct page_info
 #define _PGC_need_scrub   _PGC_allocated
 #define PGC_need_scrub    PGC_allocated
 
+/* Non-boot CPUs use this to find the correct pagetables. */
+extern uint64_t init_ttbr;
+
 extern mfn_t directmap_mfn_start, directmap_mfn_end;
 extern vaddr_t directmap_virt_end;
 #ifdef CONFIG_ARM_64
Signature · 1 line
2.34.1
#10 lore raw

PATCH v2 7/7 x86/nmi: include missing header with declarations for 'watchdog_*'

In reply to Nicola Vetrini

Include an additional header to make the declarations for functions 'watchdog_*' visible prior to their definition in the file, thereby resolving the violations of Rule 8.4.

No functional change.

Fixes c8177e691f0f ("watchdog: Move watchdog from being x86 specific to common code")

---
Changes in v2:
- Revised commit message

---
 xen/arch/x86/nmi.c | 1 +
 1 file changed, 1 insertion(+)
xen/arch/x86/nmi.c +1 -0
index 104e366bd310..dc79c25e3ffd 100644
@@ -24,6 +24,7 @@
 #include <xen/console.h>
 #include <xen/smp.h>
 #include <xen/keyhandler.h>
+#include <xen/watchdog.h>
 #include <xen/cpu.h>
 #include <asm/current.h>
 #include <asm/mc146818rtc.h>
Signature · 1 line
2.34.1