address violations of MISRA C:2012 Directive 4.10
PATCH 7/13 x86/asm: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinAdd or move inclusion guards to address violations of MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Inclusion guards must appear at the beginning of the headers (comments are permitted anywhere).
The text of the beggining comment of cpufeatures.h has been changed to match the deviation in automation/eclair_analysis/ECLAIR/deviations.ecl, moreover this new formulation is already used in other files.
Mechanical change.
--- xen/arch/x86/include/asm/compat.h | 5 +++++ xen/arch/x86/include/asm/cpufeatures.h | 4 +--- xen/arch/x86/include/asm/efibind.h | 5 +++++ xen/arch/x86/include/asm/hypercall.h | 6 +++--- 4 files changed, 14 insertions(+), 6 deletions(-)
xen/arch/x86/include/asm/compat.h +5 -0
@@ -2,6 +2,9 @@* compat.h */ +#ifndef __ASM_X86_COMPAT_H__ +#define __ASM_X86_COMPAT_H__ +#ifdef CONFIG_COMPAT #define COMPAT_BITS_PER_LONG 32
@@ -18,3 +21,5 @@ int switch_compat(struct domain *);#include <xen/errno.h> static inline int switch_compat (struct domain *d) {return -EOPNOTSUPP ; }#endif + +#endif /* __ASM_X86_COMPAT_H__ */
xen/arch/x86/include/asm/cpufeatures.h +1 -3
@@ -1,6 +1,4 @@ -/* -* Explicitly intended for multiple inclusion. -*/ +/* This file is legitimately included multiple times */ #include <xen/lib/x86/cpuid-autogen.h>
xen/arch/x86/include/asm/efibind.h +5 -0
@@ -1,2 +1,7 @@ +#ifndef __ASM_X86_EFIBIND_H__ +#define __ASM_X86_EFIBIND_H__ +#include <xen/types.h> #include <asm/x86_64/efibind.h> + +#endif /* __ASM_X86_EFIBIND_H__ */
xen/arch/x86/include/asm/hypercall.h +3 -3
@@ -2,13 +2,13 @@* asm-x86/hypercall.h */ +#ifndef __ASM_X86_HYPERCALL_H__ +#define __ASM_X86_HYPERCALL_H__ +#ifndef __XEN_HYPERCALL_H__#error "asm/hypercall.h should not be included directly - include xen/hypercall.h instead"#endif -#ifndef __ASM_X86_HYPERCALL_H__ -#define __ASM_X86_HYPERCALL_H__ -#include <xen/types.h> #include <public/physdev.h> #include <public/event_channel.h>
Signature · 1 line
2.34.1
PATCH 10/13 xen/efi: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinAdd inclusion guards to address violations of
MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Also C files, if included somewhere, need to comply with the guideline.
Mechanical change.
--- xen/common/efi/efi.h | 5 +++++ xen/common/efi/runtime.c | 6 ++++++ 2 files changed, 11 insertions(+)
xen/common/efi/efi.h +5 -0
@@ -1,3 +1,6 @@ +#ifndef __COMMON_EFI_EFI_H__ +#define __COMMON_EFI_EFI_H__ +#include <asm/efibind.h> #include <efi/efidef.h> #include <efi/efierr.h>
@@ -51,3 +54,5 @@ void free_ebmalloc_unused_mem(void);const void *pe_find_section (const void *image,const UINTN image_size,const CHAR16 *section_name,UINTN *size_out); + +#endif /* __COMMON_EFI_EFI_H__ */
xen/common/efi/runtime.c +6 -0
@@ -6,6 +6,10 @@#include <xen/irq.h> #include <xen/time.h> +#ifndef __COMMON_EFI_RUNTIME_C__ +#define __COMMON_EFI_RUNTIME_C__ + +DEFINE_XEN_GUEST_HANDLE (CHAR16 ); struct efi_rs_state {
@@ -704,3 +708,5 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *op)return rc; }#endif + +#endif /* __COMMON_EFI_RUNTIME_C__ */
Signature · 1 line
2.34.1
cover address violations of MISRA C:2012 Directive 4.10
Add or move inclusion guards to address violations of MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Inclusion guards must appear at the beginning of the headers (comments are permitted anywhere) and the #if directive cannot be used for other checks.
C files, if included somewhere, need to comply with the guideline.
Simone Ballarin (13):
misra: add deviation for headers that explicitly avoid guards automation/eclair: add text-based deviation for empty headers xen/arm: address violations of MISRA C:2012 Directive 4.10 xen/x86: address violations of MISRA C:2012 Directive 4.10 automation/eclair: add deviation for usercopy.c x86/EFI: address violations of MISRA C:2012 Directive 4.10 x86/asm: address violations of MISRA C:2012 Directive 4.10 x86/mm: address violations of MISRA C:2012 Directive 4.10 xen/common: address violations of MISRA C:2012 Directive 4.10 xen/efi: address violations of MISRA C:2012 Directive 4.10 xen/sched: address violations of MISRA C:2012 Directive 4.10
xen: address violations of MISRA C:2012 Directive 4.10 x86/asm: address violations of MISRA C:2012 Directive 4.10
automation/eclair_analysis/ECLAIR/deviations.ecl | 9 +++++++++ docs/misra/rules.rst | 5 ++++- xen/arch/arm/efi/efi-boot.h | 6 ++++++ xen/arch/arm/include/asm/hypercall.h | 6 +++--- xen/arch/arm/include/asm/iocap.h | 6 +++--- xen/arch/x86/Makefile | 8 ++++---- xen/arch/x86/cpu/cpu.h | 5 +++++ xen/arch/x86/efi/efi-boot.h | 6 ++++++ xen/arch/x86/efi/runtime.h | 5 +++++ xen/arch/x86/include/asm/compat.h | 5 +++++ xen/arch/x86/include/asm/cpufeatures.h | 4 +--- xen/arch/x86/include/asm/efibind.h | 5 +++++ xen/arch/x86/include/asm/hypercall.h | 6 +++--- xen/arch/x86/mm/guest_walk.c | 5 +++++ xen/arch/x86/mm/hap/guest_walk.c | 4 ++++ xen/arch/x86/physdev.c | 4 ++++ xen/arch/x86/platform_hypercall.c | 5 +++++ xen/arch/x86/x86_64/compat/mm.c | 5 +++++ xen/arch/x86/x86_64/mmconfig.h | 5 +++++ xen/arch/x86/x86_emulate/private.h | 5 +++++ xen/arch/x86/x86_emulate/x86_emulate.c | 5 +++++ xen/common/compat/grant_table.c | 7 +++++++ xen/common/coverage/gcc_4_7.c | 5 +++++ xen/common/decompress.h | 5 +++++ xen/common/efi/efi.h | 5 +++++ xen/common/efi/runtime.c | 6 ++++++ xen/common/event_channel.h | 5 +++++ xen/common/multicall.c | 5 +++++ xen/common/sched/compat.c | 6 ++++++ xen/include/xen/err.h | 4 +++- xen/include/xen/pci_ids.h | 5 +++++ xen/include/xen/softirq.h | 4 +++- xen/include/xen/unaligned.h | 7 ++++--- xen/include/xen/vmap.h | 4 +++- xen/tools/compat-xlat-header.py | 2 ++ 35 files changed, 161 insertions(+), 23 deletions(-)
Signature · 1 line
2.34.1
PATCH 13/13 x86/asm: address violations of MISRA C:2012 Directive 4.10
Amend generation script to address a violation of
MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
This patch adds a special comment to the beginning of the header to make it explicit that the file is generated automatically.
The comment is recognized by ECLAIR and will cause the deviation of the violation.
--- xen/tools/compat-xlat-header.py | 2 ++ 1 file changed, 2 insertions(+)
xen/tools/compat-xlat-header.py +2 -0
@@ -406,6 +406,8 @@ def main(): line = line.strip() header_tokens += re_tokenazier.split(line) + print("/* Generated file, do not edit! */") + with open(sys.argv[2]) as compat_list: for line in compat_list: words = re_tokenazier.split(line, maxsplit=1)
Signature · 1 line
2.34.1
PATCH 9/13 xen/common: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinAdd inclusion guards to address violations of
MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Also C files, if included somewhere, need to comply with the guideline.
Mechanical change.
--- xen/common/compat/grant_table.c | 7 +++++++ xen/common/coverage/gcc_4_7.c | 5 +++++ xen/common/decompress.h | 5 +++++ xen/common/event_channel.h | 5 +++++ xen/common/multicall.c | 5 +++++ 5 files changed, 27 insertions(+)
xen/common/compat/grant_table.c +7 -0
@@ -3,6 +3,10 @@* */ + +#ifndef __COMMON_COMPAT_GRANT_TABLE_C__ +#define __COMMON_COMPAT_GRANT_TABLE_C__ +#include <xen/hypercall.h> #include <compat/grant_table.h>
@@ -331,6 +335,9 @@ int compat_grant_table_op( return rc; } + +#endif /* __COMMON_COMPAT_GRANT_TABLE_C__ */ +/* * Local variables: * mode: C
xen/common/coverage/gcc_4_7.c +5 -0
@@ -14,6 +14,9 @@* Wei Liu <[email protected]> */ +#ifndef __COMMON_COVERAGE_GCC_4_7_C__ +#define __COMMON_COVERAGE_GCC_4_7_C__ +#include <xen/string.h> #include "gcov.h"
@@ -193,6 +196,8 @@ size_t gcov_info_to_gcda(char *buffer, const struct gcov_info *info) return pos; } +#endif /* __COMMON_COVERAGE_GCC_4_7_C__ */ +/* * Local variables: * mode: C
xen/common/decompress.h +5 -0
@@ -1,3 +1,6 @@ +#ifndef __COMMON_DECOMPRESS_H__ +#define __COMMON_DECOMPRESS_H__ +#ifdef __XEN__#include <xen/cache.h>
@@ -23,3 +26,5 @@#define large_free free#endif + +#endif /* __COMMON_DECOMPRESS_H__ */
xen/common/event_channel.h +5 -0
@@ -1,5 +1,8 @@/* Event channel handling private header. */ +#ifndef __COMMON_EVENT_CHANNEL_H__ +#define __COMMON_EVENT_CHANNEL_H__ +#include <xen/event.h> static inline unsigned int max_evtchns (const struct domain *d)
@@ -52,6 +55,8 @@ int evtchn_fifo_init_control(struct evtchn_init_control *init_control);int evtchn_fifo_expand_array (const struct evtchn_expand_array *expand_array);void evtchn_fifo_destroy (struct domain *d); +#endif /* __COMMON_EVENT_CHANNEL_H__ */ +/* * Local variables: * mode: C
xen/common/multicall.c +5 -0
@@ -2,6 +2,9 @@* multicall.c */ +#ifndef __COMMON_MULTICALL_C__ +#define __COMMON_MULTICALL_C__ +#include <xen/types.h> #include <xen/lib.h> #include <xen/mm.h>
@@ -124,6 +127,8 @@ ret_t do_multicall( __HYPERVISOR_multicall, "hi", call_list, nr_calls-i); } +#endif /* __COMMON_MULTICALL_C__ */ +/* * Local variables: * mode: C
Signature · 1 line
2.34.1
PATCH 11/13 xen/sched: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinAdd inclusion guards to address violations of
MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Mechanical change.
--- xen/common/sched/compat.c | 6 ++++++ 1 file changed, 6 insertions(+)
xen/common/sched/compat.c +6 -0
@@ -3,6 +3,10 @@* */ +#ifndef __COMMON_SCHED_COMPAT_C__ +#define __COMMON_SCHED_COMPAT_C__ + +#include <compat/sched.h> #define COMPAT
@@ -44,6 +48,8 @@ int compat_set_timer_op(uint32_t lo, int32_t hi) return do_set_timer_op(((s64)hi << 32) | lo); } +#endif /* __COMMON_SCHED_COMPAT_C__ */ +/* * Local variables: * mode: C
Signature · 1 line
2.34.1
PATCH 6/13 x86/EFI: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinAdd inclusion guards to address violations of
MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Mechanical change.
--- xen/arch/x86/efi/efi-boot.h | 6 ++++++ xen/arch/x86/efi/runtime.h | 5 +++++ 2 files changed, 11 insertions(+)
xen/arch/x86/efi/efi-boot.h +6 -0
@@ -3,6 +3,10 @@* is intended to be included by common/efi/boot.c _only_, and * therefore can define arch specific global variables. */ + +#ifndef __X86_EFI_EFI_BOOT_H__ +#define __X86_EFI_EFI_BOOT_H__ +#include <xen/vga.h> #include <asm/e820.h> #include <asm/edd.h>
@@ -913,6 +917,8 @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable efi_exit_boot(ImageHandle, SystemTable); } +#endif /* __X86_EFI_EFI_BOOT_H__ */ +/* * Local variables: * mode: C
xen/arch/x86/efi/runtime.h +5 -0
@@ -1,3 +1,6 @@ +#ifndef __X86_EFI_RUNTIME_H__ +#define __X86_EFI_RUNTIME_H__ +#include <xen/domain_page.h> #include <xen/mm.h> #include <asm/atomic.h>
@@ -17,3 +20,5 @@ void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e) } }#endif + +#endif /* __X86_EFI_RUNTIME_H__ */
Signature · 1 line
2.34.1
PATCH 5/13 automation/eclair: add deviation for usercopy.c
In reply to Simone Ballarinxen/arch/x86/usercopy.c includes itself, so it is not supposed to comply with Directive 4.10:
"Precautions shall be taken in order to prevent the contents of a header file being included more than once"
This patch adds a deviation for the file.
--- automation/eclair_analysis/ECLAIR/deviations.ecl | 4 ++++ docs/misra/rules.rst | 2 ++ 2 files changed, 6 insertions(+)
automation/eclair_analysis/ECLAIR/deviations.ecl +4 -0
@@ -96,6 +96,10 @@ conform to the directive." -config=MC3R1.D4.10,reports+={safe, "first_area(text(^ \\* In this case, no inclusion guards apply and the caller is responsible.*\\*/$, begin-1))"} -doc_end +-doc_begin="xen/arch/x86/usercopy.c includes itself: it is not supposed to comply with the directive" +-config=MC3R1.D4.10,reports+={deliberate, "all_area(all_loc(file("^xen/arch/x86/usercopy\\.c$")))"} +-doc_end + # # Series 5. #
docs/misra/rules.rst +2 -0
@@ -62,6 +62,8 @@ maintainers if you want to suggest a change. - Files that are intended to be included more than once do not need to conform to the directive. Files that explicitly avoid inclusion guards under specific circumstances do not need to conform the directive. + xen/arch/x86/usercopy.c includes itself: it is not supposed to comply + with the directive. * - `Dir 4.11 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/D_04_11.c>`_ - Required
Signature · 1 line
2.34.1
PATCH 3/13 xen/arm: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinAdd or move inclusion guards to address violations of MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Inclusion guards must appear at the beginning of the headers (comments are permitted anywhere).
Mechanical change.
--- xen/arch/arm/efi/efi-boot.h | 6 ++++++ xen/arch/arm/include/asm/hypercall.h | 6 +++--- xen/arch/arm/include/asm/iocap.h | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-)
xen/arch/arm/efi/efi-boot.h +6 -0
@@ -3,6 +3,10 @@* is intended to be included by common/efi/boot.c _only_, and * therefore can define arch specific global variables. */ + +#ifndef __ARM_EFI_EFI_BOOT_H__ +#define __ARM_EFI_EFI_BOOT_H__ +#include <xen/device_tree.h> #include <xen/libfdt/libfdt.h> #include <asm/setup.h>
@@ -1003,6 +1007,8 @@ static void __init efi_arch_flush_dcache_area(const void *vaddr, UINTN size) __flush_dcache_area(vaddr, size); } +#endif /* __ARM_EFI_EFI_BOOT_H__*/ +/* * Local variables: * mode: C
xen/arch/arm/include/asm/hypercall.h +3 -3
@@ -1,10 +1,10 @@ +#ifndef __ASM_ARM_HYPERCALL_H__ +#define __ASM_ARM_HYPERCALL_H__ +#ifndef __XEN_HYPERCALL_H__#error "asm/hypercall.h should not be included directly - include xen/hypercall.h instead"#endif -#ifndef __ASM_ARM_HYPERCALL_H__ -#define __ASM_ARM_HYPERCALL_H__ -#include <public/domctl.h> /* for arch_do_domctl */ long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d,
xen/arch/arm/include/asm/iocap.h +3 -3
@@ -1,10 +1,10 @@ -#ifndef __X86_IOCAP_H__ -#define __X86_IOCAP_H__ +#ifndef __ASM_ARM_IOCAP_H__ +#define __ASM_ARM_IOCAP_H__#define cache_flush_permitted (d) \ (!rangeset_is_empty((d)->iomem_caps)) -#endif +#endif /* __ASM_ARM_IOCAP_H__ */ /* * Local variables:
Signature · 1 line
2.34.1
PATCH 1/13 misra: add deviation for headers that explicitly avoid guards
In reply to Simone BallarinSome headers, under specific circumstances (documented in a comment at the beginning of the file), explicitly avoid inclusion guards: the caller is responsible for including them correctly.
These files are not supposed to comply with Directive 4.10:
"Precautions shall be taken in order to prevent the contents of a header file being included more than once"
This patch adds a deviation for all headers that contain the following in a comment text:
"In this case, no inclusion guards apply and the caller is responsible"
--- automation/eclair_analysis/ECLAIR/deviations.ecl | 4 ++++ docs/misra/rules.rst | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-)
automation/eclair_analysis/ECLAIR/deviations.ecl +4 -0
@@ -91,6 +91,10 @@ conform to the directive." -config=MC3R1.D4.10,reports+={safe, "first_area(text(^/\\* Generated file, do not edit! \\*/$, begin-3))"} -doc_end +-doc_begin="Some headers, under specific circumstances, explicitly avoid inclusion guards." +-config=MC3R1.D4.10,reports+={safe, "first_area(text(^ \\* In this case, no inclusion guards apply and the caller is responsible.*\\*/$, begin-1))"} +-doc_end + # # Series 5. #
docs/misra/rules.rst +2 -1
@@ -60,7 +60,8 @@ maintainers if you want to suggest a change. - Precautions shall be taken in order to prevent the contents of a header file being included more than once - Files that are intended to be included more than once do not need to - conform to the directive + conform to the directive. Files that explicitly avoid inclusion guards + under specific circumstances do not need to conform the directive. * - `Dir 4.11 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/D_04_11.c>`_ - Required
Signature · 1 line
2.34.1
PATCH 12/13 xen: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinMove or amended inclusion guards to address violations of MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Inclusion guards must appear at the beginning of the headers (comments are permitted anywhere) and the #if directive cannot be used for other checks.
Mechanical change.
--- xen/include/xen/err.h | 4 +++- xen/include/xen/pci_ids.h | 5 +++++ xen/include/xen/softirq.h | 4 +++- xen/include/xen/unaligned.h | 7 ++++--- xen/include/xen/vmap.h | 4 +++- 5 files changed, 18 insertions(+), 6 deletions(-)
xen/include/xen/err.h +3 -1
@@ -1,5 +1,6 @@ -#if !defined(__XEN_ERR_H__) && !defined(__ASSEMBLY__) +#if !defined(__XEN_ERR_H__)#define __XEN_ERR_H__ +#if !defined(__ASSEMBLY__)#include <xen/compiler.h> #include <xen/errno.h>
@@ -54,4 +55,5 @@ static inline int __must_check PTR_RET(const void *ptr)return IS_ERR (ptr) ?PTR_ERR (ptr) :0 ; } +#endif /* __ASSEMBLY__ */ #endif /* __XEN_ERR_H__ */
xen/include/xen/pci_ids.h +5 -0
@@ -1,3 +1,6 @@ +#ifndef __XEN_PCI_IDS_H__ +#define __XEN_PCI_IDS_H__ +#define PCI_VENDOR_ID_AMD 0x1022#define PCI_VENDOR_ID_NVIDIA 0x10de
@@ -11,3 +14,5 @@#define PCI_VENDOR_ID_BROADCOM 0x14e4#define PCI_VENDOR_ID_INTEL 0x8086 + +#endif /* __XEN_PCI_IDS_H__ */
xen/include/xen/softirq.h +3 -1
@@ -1,5 +1,6 @@ -#if !defined(__XEN_SOFTIRQ_H__) && !defined(__ASSEMBLY__) +#if !defined(__XEN_SOFTIRQ_H__)#define __XEN_SOFTIRQ_H__ +#if !defined(__ASSEMBLY__)/* Low-latency softirqs come first in the following list. */ enum {
@@ -40,4 +41,5 @@ void cpu_raise_softirq_batch_finish(void);*/ void process_pending_softirqs (void ); +#endif /* __ASSEMBLY__ */ #endif /* __XEN_SOFTIRQ_H__ */
xen/include/xen/unaligned.h +4 -3
@@ -3,13 +3,14 @@* without faulting, and at least reasonably efficiently. Other architectures * will need to have a custom asm/unaligned.h. */ -#ifndef __ASM_UNALIGNED_H__ -#error "xen/unaligned.h should not be included directly - include asm/unaligned.h instead" -#endif #ifndef __XEN_UNALIGNED_H__#define __XEN_UNALIGNED_H__ +#ifndef __ASM_UNALIGNED_H__ +#error "xen/unaligned.h should not be included directly - include asm/unaligned.h instead" +#endif +#ifdef __XEN__#include <xen/types.h> #include <asm/byteorder.h>
xen/include/xen/vmap.h +3 -1
@@ -1,5 +1,6 @@ -#if !defined(__XEN_VMAP_H__) && defined(VMAP_VIRT_START ) +#if !defined(__XEN_VMAP_H__)#define __XEN_VMAP_H__ +#if defined(VMAP_VIRT_START )#include <xen/mm-frame.h> #include <xen/page-size.h>
@@ -38,4 +39,5 @@ static inline void vm_init(void)vm_init_type (VMAP_DEFAULT , (void *)VMAP_VIRT_START ,arch_vmap_virt_end ()); } +#endif /* VMAP_VIRT_START */ #endif /* __XEN_VMAP_H__ */
Signature · 1 line
2.34.1
PATCH 2/13 automation/eclair: add text-based deviation for empty headers
In reply to Simone BallarinThis patch adds a text-based deviation for Directive 4.10:
"Precautions shall be taken in order to prevent the contents of a header file being included more than once"
Headers starting with the following comment are not supposed to comply with the directive:
"/* empty */"
These headers should be empty, therefore they pose no risk if included more than once.
--- automation/eclair_analysis/ECLAIR/deviations.ecl | 1 + 1 file changed, 1 insertion(+)
automation/eclair_analysis/ECLAIR/deviations.ecl +1 -0
@@ -80,6 +80,7 @@ inline functions." -doc_begin="This header file is autogenerated or empty, therefore it poses no risk if included more than once." +-config=MC3R1.D4.10,reports+={safe, "first_area(text(^/\\* empty \\*/$, begin-1))"} -file_tag+={empty_header, "^xen/arch/arm/efi/runtime\\.h$"} -file_tag+={autogen_headers, "^xen/include/xen/compile\\.h$||^xen/include/generated/autoconf.h$||^xen/include/xen/hypercall-defs.h$"} -config=MC3R1.D4.10,reports+={safe, "all_area(all_loc(file(empty_header||autogen_headers)))"}
Signature · 1 line
2.34.1
PATCH 4/13 xen/x86: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinAdd or move inclusion guards to address violations of MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Inclusion guards must appear at the beginning of the headers (comments are permitted anywhere).
Also C files, if included somewhere, need to comply with the guideline.
Mechanical change.
--- xen/arch/x86/Makefile | 8 ++++---- xen/arch/x86/cpu/cpu.h | 5 +++++ xen/arch/x86/physdev.c | 4 ++++ xen/arch/x86/platform_hypercall.c | 5 +++++ xen/arch/x86/x86_64/compat/mm.c | 5 +++++ xen/arch/x86/x86_64/mmconfig.h | 5 +++++ xen/arch/x86/x86_emulate/private.h | 5 +++++ xen/arch/x86/x86_emulate/x86_emulate.c | 5 +++++ 8 files changed, 38 insertions(+), 4 deletions(-)
xen/arch/x86/Makefile +4 -4
@@ -259,17 +259,17 @@ $(objtree)/arch/x86/include/asm/asm-macros.h: $(obj)/asm-macros.i $(src)/Makefil $(call filechk,asm-macros.h) define filechk_asm-macros.h + echo '#ifndef __ASM_MACROS_H__'; \ + echo '#define __ASM_MACROS_H__'; \ echo '#if 0'; \ echo '.if 0'; \ echo '#endif'; \ - echo '#ifndef __ASM_MACROS_H__'; \ - echo '#define __ASM_MACROS_H__'; \ echo 'asm ( ".include \"$@\"" );'; \ - echo '#endif /* __ASM_MACROS_H__ */'; \ echo '#if 0'; \ echo '.endif'; \ cat $<; \ - echo '#endif' + echo '#endif'; \ + echo '#endif /* __ASM_MACROS_H__ */' endef $(obj)/efi.lds: AFLAGS-y += -DEFI
xen/arch/x86/cpu/cpu.h +5 -0
@@ -1,3 +1,6 @@ +#ifndef __X86_CPU_CPU_H__ +#define __X86_CPU_CPU_H__ + /* attempt to consolidate cpu attributes */ struct cpu_dev { void (*c_early_init)(struct cpuinfo_x86 *c);
@@ -24,3 +27,5 @@ void amd_init_lfence(struct cpuinfo_x86 *c);void amd_init_ssbd (const struct cpuinfo_x86 *c);void amd_init_spectral_chicken (void );void detect_zen2_null_seg_behaviour (void ); + +#endif /* __X86_CPU_CPU_H__ */
xen/arch/x86/physdev.c +4 -0
@@ -1,3 +1,5 @@ +#ifndef __X86_PHYSDEV_C__ +#define __X86_PHYSDEV_C__#include <xen/init.h> #include <xen/lib.h>
@@ -623,6 +625,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) return ret; } +#endif /* __X86_PHYSDEV_C__ */ +/* * Local variables: * mode: C
xen/arch/x86/platform_hypercall.c +5 -0
@@ -6,6 +6,9 @@* Copyright (c) 2002-2006, K Fraser */ +#ifndef __X86_PLATFORM_HYPERCALL_C__ +#define __X86_PLATFORM_HYPERCALL_C__ +#include <xen/types.h> #include <xen/lib.h> #include <xen/mm.h>
@@ -899,6 +902,8 @@ ret_t do_platform_op( return ret; } +#endif /* __X86_PLATFORM_HYPERCALL_C__ */ +/* * Local variables: * mode: C
xen/arch/x86/x86_64/compat/mm.c +5 -0
@@ -1,3 +1,6 @@ +#ifndef __X86_X86_64_COMPAT_MM_C__ +#define __X86_X86_64_COMPAT_MM_C__ +#include <xen/event.h> #include <xen/hypercall.h> #include <xen/mem_access.h>
@@ -326,6 +329,8 @@ int compat_mmuext_op( }#endif /* CONFIG_PV */ +#endif /* __X86_X86_64_COMPAT_MM_C__ */ +/* * Local variables: * mode: C
xen/arch/x86/x86_64/mmconfig.h +5 -0
@@ -5,6 +5,9 @@* Author: Allen Kay <[email protected]> - adapted from linux */ +#ifndef __X86_X86_64_MMCONFIG_H__ +#define __X86_X86_64_MMCONFIG_H__ +#define PCI_DEVICE_ID_INTEL_E7520_MCH 0x3590#define PCI_DEVICE_ID_INTEL_82945G_HB 0x2770
@@ -72,3 +75,5 @@ int pci_mmcfg_reserved(uint64_t address, unsigned int segment,int pci_mmcfg_arch_init (void );int pci_mmcfg_arch_enable (unsigned int );void pci_mmcfg_arch_disable (unsigned int ); + +#endif /* __X86_X86_64_MMCONFIG_H__ */
xen/arch/x86/x86_emulate/private.h +5 -0
@@ -6,6 +6,9 @@* Copyright (c) 2005-2007 XenSource Inc. */ +#ifndef __X86_X86_EMULATE_PRIVATE_H__ +#define __X86_X86_EMULATE_PRIVATE_H__ +#ifdef __XEN__# include <xen/kernel.h>
@@ -831,3 +834,5 @@ static inline int read_ulong(enum x86_segment seg, *val =0 ; return ops->read(seg, offset, val, bytes, ctxt); } + +#endif /* __X86_X86_EMULATE_PRIVATE_H__ */
xen/arch/x86/x86_emulate/x86_emulate.c +5 -0
@@ -8,6 +8,9 @@* Copyright (c) 2005-2007 XenSource Inc. */ +#ifndef __X86_X86_EMULATE_EMULATE_C__ +#define __X86_X86_EMULATE_EMULATE_C__ +#include "private.h" /*
@@ -8678,3 +8681,5 @@ int x86_emulate_wrapper(return rc; }#endif + +#endif /* __X86_X86_EMULATE_EMULATE_C__ */
Signature · 1 line
2.34.1
PATCH 8/13 x86/mm: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinAdd inclusion guards to address violations of
MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
C files, if included somewhere, need to comply with the guideline.
Mechanical change.
--- xen/arch/x86/mm/guest_walk.c | 5 +++++ xen/arch/x86/mm/hap/guest_walk.c | 4 ++++ 2 files changed, 9 insertions(+)
xen/arch/x86/mm/guest_walk.c +5 -0
@@ -9,6 +9,9 @@* Parts based on earlier work by Michael A Fetterman, Ian Pratt et al. */ +#ifndef __X86_MM_GUEST_WALK_C__ +#define __X86_MM_GUEST_WALK_C__ +#include <xen/types.h> #include <xen/mm.h> #include <xen/paging.h>
@@ -576,6 +579,8 @@ void *map_domain_gfn(struct p2m_domain *p2m, gfn_t gfn, mfn_t *mfn, }#endif +#endif /* __X86_MM_GUEST_WALK_C__ */ +/* * Local variables: * mode: C
xen/arch/x86/mm/hap/guest_walk.c +4 -0
@@ -7,6 +7,9 @@* Copyright (c) 2007, XenSource Inc. */ +#ifndef __X86_MM_HAP_GUEST_WALK_C__ +#define __X86_MM_HAP_GUEST_WALK_C__ +#include <xen/domain_page.h> #include <xen/paging.h> #include <xen/sched.h>
@@ -124,6 +127,7 @@ unsigned long cf_check hap_p2m_ga_to_gfn(GUEST_PAGING_LEVELS)( return gfn_x(INVALID_GFN); } +#endif /* __X86_MM_HAP_GUEST_WALK_C__ */ /* * Local variables:
Signature · 1 line
2.34.1
Re: [XEN PATCH 01/13] misra: add deviation for headers that explicitly avoid guards
In reply to Simone BallarinQuoted 8 lines · Simone Ballarin
Some headers, under specific circumstances (documented in a comment at the beginning of the file), explicitly avoid inclusion guards: the caller is responsible for including them correctly.
These files are not supposed to comply with Directive 4.10:
"Precautions shall be taken in order to prevent the contents of a header file being included more than once"
Quoted 5 lines
This patch adds a deviation for all headers that contain the following in a comment text:
"In this case, no inclusion guards apply and the caller is responsible"Signed-off-by Simone Ballarin <[email protected]>
Quoted 37 lines
--- automation/eclair_analysis/ECLAIR/deviations.ecl | 4 ++++ docs/misra/rules.rst | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-)automation/eclair_analysis/ECLAIR/deviations.ecl +4
-0@@ -91,6 +91,10 @@ conform to the directive." -config=MC3R1.D4.10,reports+={safe, "first_area(text(^/\\* Generated file, do not edit! \\*/$, begin-3))"} -doc_end +-doc_begin="Some headers, under specific circumstances, explicitly avoid inclusion guards." +-config=MC3R1.D4.10,reports+={safe, "first_area(text(^ \\* In this case, no inclusion guards apply and the caller is responsible.*\\*/$, begin-1))"} +-doc_end + # # Series 5. #docs/misra/rules.rst +2
-1@@ -60,7 +60,8 @@ maintainers if you want to suggest a change. - Precautions shall be taken in order to prevent the contents of a header file being included more than once - Files that are intended to be included more than once do not need to - conform to the directive + conform to the directive. Files that explicitly avoid inclusion guards + under specific circumstances do not need to conform the directive. * - `Dir 4.11 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/D_04_11.c>`_ - RequiredSignature · 1 line
2.34.1
Re: [XEN PATCH 02/13] automation/eclair: add text-based deviation for empty headers
In reply to Simone BallarinQuoted 4 lines · Simone Ballarin
This patch adds a text-based deviation for Directive 4.10:
"Precautions shall be taken in order to prevent the contents of a header file being included more than once"
Quoted 8 lines
Headers starting with the following comment are not supposed to comply with the directive:
"/* empty */"These headers should be empty, therefore they pose no risk if included more than once.
Signed-off-by Simone Ballarin <[email protected]>
However I think we should also update rules.rst and/or update docs/misra/safe.json
Quoted 19 lines
--- automation/eclair_analysis/ECLAIR/deviations.ecl | 1 + 1 file changed, 1 insertion(+)automation/eclair_analysis/ECLAIR/deviations.ecl +1
-0@@ -80,6 +80,7 @@ inline functions." -doc_begin="This header file is autogenerated or empty, therefore it poses no risk if included more than once." +-config=MC3R1.D4.10,reports+={safe, "first_area(text(^/\\* empty \\*/$, begin-1))"} -file_tag+={empty_header, "^xen/arch/arm/efi/runtime\\.h$"} -file_tag+={autogen_headers, "^xen/include/xen/compile\\.h$||^xen/include/generated/autoconf.h$||^xen/include/xen/hypercall-defs.h$"} -config=MC3R1.D4.10,reports+={safe, "all_area(all_loc(file(empty_header||autogen_headers)))"}Signature · 1 line
2.34.1
Re: [XEN PATCH 03/13] xen/arm: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinQuoted 11 lines · Simone Ballarin
Add or move inclusion guards to address violations of MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Inclusion guards must appear at the beginning of the headers (comments are permitted anywhere).
Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>
Quoted 69 lines
--- xen/arch/arm/efi/efi-boot.h | 6 ++++++ xen/arch/arm/include/asm/hypercall.h | 6 +++--- xen/arch/arm/include/asm/iocap.h | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-)xen/arch/arm/efi/efi-boot.h +6
-0@@ -3,6 +3,10 @@* is intended to be included by common/efi/boot.c _only_, and * therefore can define arch specific global variables. */ + +#ifndef __ARM_EFI_EFI_BOOT_H__ +#define __ARM_EFI_EFI_BOOT_H__ +#include <xen/device_tree.h> #include <xen/libfdt/libfdt.h> #include <asm/setup.h> @@ -1003,6 +1007,8 @@ static void __init efi_arch_flush_dcache_area(const void *vaddr, UINTN size) __flush_dcache_area(vaddr, size); } +#endif /* __ARM_EFI_EFI_BOOT_H__*/ +/* * Local variables: * mode: C xen/arch/arm/include/asm/hypercall.h +3
-3@@ -1,10 +1,10 @@ +#ifndef __ASM_ARM_HYPERCALL_H__ +#define __ASM_ARM_HYPERCALL_H__ +#ifndef __XEN_HYPERCALL_H__#error "asm/hypercall.h should not be included directly - include xen/hypercall.h instead"#endif -#ifndef __ASM_ARM_HYPERCALL_H__ -#define __ASM_ARM_HYPERCALL_H__ -#include <public/domctl.h> /* for arch_do_domctl */ long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d,xen/arch/arm/include/asm/iocap.h +3
-3@@ -1,10 +1,10 @@ -#ifndef __X86_IOCAP_H__ -#define __X86_IOCAP_H__ +#ifndef __ASM_ARM_IOCAP_H__ +#define __ASM_ARM_IOCAP_H__#define cache_flush_permitted (d) \ (!rangeset_is_empty((d)->iomem_caps)) -#endif +#endif /* __ASM_ARM_IOCAP_H__ */ /* * Local variables: Signature · 1 line
2.34.1
Re: [XEN PATCH 03/13] xen/arm: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinHi,
Quoted 56 lines · Simone Ballarin
Add or move inclusion guards to address violations of MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Inclusion guards must appear at the beginning of the headers (comments are permitted anywhere).
Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>--- xen/arch/arm/efi/efi-boot.h | 6 ++++++ xen/arch/arm/include/asm/hypercall.h | 6 +++--- xen/arch/arm/include/asm/iocap.h | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-)xen/arch/arm/efi/efi-boot.h +6
-0@@ -3,6 +3,10 @@* is intended to be included by common/efi/boot.c _only_, and * therefore can define arch specific global variables. */ + +#ifndef __ARM_EFI_EFI_BOOT_H__ +#define __ARM_EFI_EFI_BOOT_H__ +#include <xen/device_tree.h> #include <xen/libfdt/libfdt.h> #include <asm/setup.h> @@ -1003,6 +1007,8 @@ static void __init efi_arch_flush_dcache_area(const void *vaddr, UINTN size) __flush_dcache_area(vaddr, size); } +#endif /* __ARM_EFI_EFI_BOOT_H__*/ +/* * Local variables: * mode: C
xen/arch/arm/include/asm/hypercall.h +3
-0@@ -1,10 +1,10 @@ +#ifndef __ASM_ARM_HYPERCALL_H__ +#define __ASM_ARM_HYPERCALL_H__ +#ifndef __XEN_HYPERCALL_H__#error "asm/hypercall.h should not be included directly - include
xen/hypercall.hinstead"
#endif
xen/arch/arm/include/asm/hypercall.h line 7
Quoted 3 lines
xen/arch/arm/include/asm/hypercall.h +0
-3-#ifndef __ASM_ARM_HYPERCALL_H__ -#define __ASM_ARM_HYPERCALL_H__ -
I understand that you are trying to fix a misra violation. However, this feels like it was done on purpose.
With the new change, you would not always check that the file were included at the correct place. I am not against this change but this ought to be explained.
Quoted 9 lines
#include <
public/domctl.h> /* forarch_do_domctl*/long subarch_do_domctl(struct
xen_domctl*domctl, struct domain *d,xen/arch/arm/include/asm/iocap.h +0
-0
xen/arch/arm/include/asm/iocap.h line 7
Quoted 10 lines
xen/arch/arm/include/asm/iocap.h +3
-3@@ -1,10 +1,10 @@ -#ifndef __X86_IOCAP_H__ -#define __X86_IOCAP_H__ +#ifndef __ASM_ARM_IOCAP_H__ +#define __ASM_ARM_IOCAP_H__#define cache_flush_permitted (d) \ (!rangeset_is_empty((d)->iomem_caps)) -#endif +#endif /* __ASM_ARM_IOCAP_H__ */
I don’t understand how this is related to the rest of the patch. You wrote that inclusion must appear first and this is the case here.
However the name is technically not correct. Is this really related to directive 4.10? If so, this should be clarified in the commit message. If not, then I think this should be in a separate commit.
Cheers,
Quoted 7 lines
xen/arch/arm/include/asm/iocap.h +0
-1/* * Local variables: -- 2.34.1
Re: [XEN PATCH 04/13] xen/x86: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinQuoted 38 lines · Simone Ballarin
Add or move inclusion guards to address violations of MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Inclusion guards must appear at the beginning of the headers (comments are permitted anywhere).
Also C files, if included somewhere, need to comply with the guideline.
Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>--- xen/arch/x86/Makefile | 8 ++++---- xen/arch/x86/cpu/cpu.h | 5 +++++ xen/arch/x86/physdev.c | 4 ++++ xen/arch/x86/platform_hypercall.c | 5 +++++ xen/arch/x86/x86_64/compat/mm.c | 5 +++++ xen/arch/x86/x86_64/mmconfig.h | 5 +++++ xen/arch/x86/x86_emulate/private.h | 5 +++++ xen/arch/x86/x86_emulate/x86_emulate.c | 5 +++++ 8 files changed, 38 insertions(+), 4 deletions(-)xen/arch/x86/Makefile +2
-1@@ -259,17 +259,17 @@ $(objtree)/arch/x86/include/asm/asm-macros.h: $(obj)/asm-macros.i $(src)/Makefil $(call filechk,asm-macros.h) define filechk_asm-macros.h + echo '#ifndef __ASM_MACROS_H__'; \ + echo '#define __ASM_MACROS_H__'; \ echo '#if 0'; \ echo '.if 0'; \ echo '#endif'; \ - echo '#ifndef __ASM_MACROS_H__'; \
xen/arch/x86/Makefile $(objtree)/arch/x86/include/asm/asm-macros.h: $(obj)/asm-macros.i $(src)/Makefil · line 273
Quoted 10 lines
xen/arch/x86/Makefile +2
-3- echo '#define __ASM_MACROS_H__'; \ echo 'asm ( ".include \"$@\"" );'; \ - echo '#endif /* __ASM_MACROS_H__ */'; \ echo '#if 0'; \ echo '.endif'; \ cat $<; \ - echo '#endif' + echo '#endif'; \ + echo '#endif /* __ASM_MACROS_H__ */' endef
This looks OK but it needs to be reviewed by an x86 maintainer
Quoted 23 lines
xen/arch/x86/Makefile +0
-0$(obj)/efi.lds: AFLAGS-y += -DEFIxen/arch/x86/cpu/cpu.h +5
-0@@ -1,3 +1,6 @@ +#ifndef __X86_CPU_CPU_H__ +#define __X86_CPU_CPU_H__ + /* attempt to consolidate cpu attributes */ struct cpu_dev { void (*c_early_init)(struct cpuinfo_x86 *c);@@ -24,3 +27,5 @@ void amd_init_lfence(struct cpuinfo_x86 *c);void amd_init_ssbd (const struct cpuinfo_x86 *c);void amd_init_spectral_chicken (void );void detect_zen2_null_seg_behaviour (void ); + +#endif /* __X86_CPU_CPU_H__ */ xen/arch/x86/physdev.c +0
-0
xen/arch/x86/physdev.c line 2
Quoted 2 lines
xen/arch/x86/physdev.c +2
-0@@ -1,3 +1,5 @@ +#ifndef __X86_PHYSDEV_C__ +#define __X86_PHYSDEV_C__
NIT: double " "
everything else looks OK
Quoted 117 lines
xen/arch/x86/physdev.c +2
-0#include <xen/init.h> #include <xen/lib.h> @@ -623,6 +625,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) return ret; } +#endif /* __X86_PHYSDEV_C__ */ +/* * Local variables: * mode: C xen/arch/x86/platform_hypercall.c +5
-0@@ -6,6 +6,9 @@* Copyright (c) 2002-2006, K Fraser */ +#ifndef __X86_PLATFORM_HYPERCALL_C__ +#define __X86_PLATFORM_HYPERCALL_C__ +#include <xen/types.h> #include <xen/lib.h> #include <xen/mm.h> @@ -899,6 +902,8 @@ ret_t do_platform_op( return ret; } +#endif /* __X86_PLATFORM_HYPERCALL_C__ */ +/* * Local variables: * mode: C xen/arch/x86/x86_64/compat/mm.c +5
-0@@ -1,3 +1,6 @@ +#ifndef __X86_X86_64_COMPAT_MM_C__ +#define __X86_X86_64_COMPAT_MM_C__ +#include <xen/event.h> #include <xen/hypercall.h> #include <xen/mem_access.h> @@ -326,6 +329,8 @@ int compat_mmuext_op( }#endif /* CONFIG_PV */ +#endif /* __X86_X86_64_COMPAT_MM_C__ */ +/* * Local variables: * mode: C xen/arch/x86/x86_64/mmconfig.h +5
-0@@ -5,6 +5,9 @@* Author: Allen Kay <[email protected]> - adapted from linux */ +#ifndef __X86_X86_64_MMCONFIG_H__ +#define __X86_X86_64_MMCONFIG_H__ +#define PCI_DEVICE_ID_INTEL_E7520_MCH 0x3590#define PCI_DEVICE_ID_INTEL_82945G_HB 0x2770@@ -72,3 +75,5 @@ int pci_mmcfg_reserved(uint64_t address, unsigned int segment,int pci_mmcfg_arch_init (void );int pci_mmcfg_arch_enable (unsigned int );void pci_mmcfg_arch_disable (unsigned int ); + +#endif /* __X86_X86_64_MMCONFIG_H__ */ xen/arch/x86/x86_emulate/private.h +5
-0@@ -6,6 +6,9 @@* Copyright (c) 2005-2007 XenSource Inc. */ +#ifndef __X86_X86_EMULATE_PRIVATE_H__ +#define __X86_X86_EMULATE_PRIVATE_H__ +#ifdef __XEN__# include <xen/kernel.h> @@ -831,3 +834,5 @@ static inline int read_ulong(enum x86_segment seg, *val =0 ; return ops->read(seg, offset, val, bytes, ctxt); } + +#endif /* __X86_X86_EMULATE_PRIVATE_H__ */ xen/arch/x86/x86_emulate/x86_emulate.c +5
-0@@ -8,6 +8,9 @@* Copyright (c) 2005-2007 XenSource Inc. */ +#ifndef __X86_X86_EMULATE_EMULATE_C__ +#define __X86_X86_EMULATE_EMULATE_C__ +#include "private.h" /* @@ -8678,3 +8681,5 @@ int x86_emulate_wrapper(return rc; }#endif + +#endif /* __X86_X86_EMULATE_EMULATE_C__ */ Signature · 1 line
2.34.1
Re: [XEN PATCH 05/13] automation/eclair: add deviation for usercopy.c
In reply to Simone Ballarin+Nicola, Luca
Quoted 34 lines · Simone Ballarin
xen/arch/x86/usercopy.cincludes itself, so it is not supposed to comply with Directive 4.10:
"Precautions shall be taken in order to prevent the contents of a header file being included more than once"This patch adds a deviation for the file.
Signed-off-by Simone Ballarin <[email protected]>--- automation/eclair_analysis/ECLAIR/deviations.ecl | 4 ++++ docs/misra/rules.rst | 2 ++ 2 files changed, 6 insertions(+)automation/eclair_analysis/ECLAIR/deviations.ecl +4
-0@@ -96,6 +96,10 @@ conform to the directive." -config=MC3R1.D4.10,reports+={safe, "first_area(text(^ \\* In this case, no inclusion guards apply and the caller is responsible.*\\*/$, begin-1))"} -doc_end +-doc_begin="xen/arch/x86/usercopy.c includes itself: it is not supposed to comply with the directive" +-config=MC3R1.D4.10,reports+={deliberate, "all_area(all_loc(file("^xen/arch/x86/usercopy\\.c$")))"} +-doc_end + # # Series 5. #docs/misra/rules.rst +0
-0
docs/misra/rules.rst maintainers if you want to suggest a change. · line 66
Quoted 5 lines
docs/misra/rules.rst +2
-0@@ -62,6 +62,8 @@ maintainers if you want to suggest a change. - Files that are intended to be included more than once do not need to conform to the directive. Files that explicitly avoid inclusion guards under specific circumstances do not need to conform the directive. + xen/arch/x86/usercopy.c includes itself: it is not supposed to comply + with the directive.
We need to find a consistent way to document this kind of deviations in a non-ECLAIR specific way, without adding the complete list of deviations to rules.rst.
Can we use safe.json and add an in-code comment at the top of usercopy.c? E.g.:
xen/arch/x86/usercopy.c +1 -0
@@ -1,3 +1,4 @@ +/* SAF-1-safe */ /* * User address space access functions. *
Otherwise, maybe we should extend safe.json to also have an extra field with a list of paths. For instance see "files" below:
{
"version": "1.0",
"content": [
{
"id": "SAF-0-safe",
"analyser": {
"eclair": "MC3R1.R8.6",
"coverity": "misra_c_2012_rule_8_6_violation"
},
"name": "Rule 8.6: linker script defined symbols",
"text": "It is safe to declare this symbol because it is defined in the linker script."
},
{
"id": "SAF-1-safe",
"analyser": {
"eclair": "MC3R1.D4.10"
},
"name": "Dir 4.10: files that include themselves",
"text": "Files purposely written to include themselves are not supposed to comply with D4.10.",
"files": ["xen/arch/x86/usercopy.c"]
},
{
"id": "SAF-2-safe",
"analyser": {},
"name": "Sentinel",
"text": "Next ID to be used"
}
]
}Re: [XEN PATCH 06/13] x86/EFI: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinQuoted 8 lines · Simone Ballarin
Add inclusion guards to address violations of
MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>
Quoted 49 lines
--- xen/arch/x86/efi/efi-boot.h | 6 ++++++ xen/arch/x86/efi/runtime.h | 5 +++++ 2 files changed, 11 insertions(+)xen/arch/x86/efi/efi-boot.h +6
-0@@ -3,6 +3,10 @@* is intended to be included by common/efi/boot.c _only_, and * therefore can define arch specific global variables. */ + +#ifndef __X86_EFI_EFI_BOOT_H__ +#define __X86_EFI_EFI_BOOT_H__ +#include <xen/vga.h> #include <asm/e820.h> #include <asm/edd.h> @@ -913,6 +917,8 @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable efi_exit_boot(ImageHandle, SystemTable); } +#endif /* __X86_EFI_EFI_BOOT_H__ */ +/* * Local variables: * mode: C xen/arch/x86/efi/runtime.h +5
-0@@ -1,3 +1,6 @@ +#ifndef __X86_EFI_RUNTIME_H__ +#define __X86_EFI_RUNTIME_H__ +#include <xen/domain_page.h> #include <xen/mm.h> #include <asm/atomic.h> @@ -17,3 +20,5 @@ void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e) } }#endif + +#endif /* __X86_EFI_RUNTIME_H__ */ Signature · 1 line
2.34.1
Re: [XEN PATCH 07/13] x86/asm: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinQuoted 11 lines · Simone Ballarin
Add or move inclusion guards to address violations of MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Inclusion guards must appear at the beginning of the headers (comments are permitted anywhere).
The text of the beggining comment of
cpufeatures.hhas been changed to match the deviation in automation/eclair_analysis/ECLAIR/deviations.ecl, moreover this new formulation is already used in other files.
I don't think it is a good idea to do this kind of textual matching. Instead we should use the format introduced by safe.json, e.g. SAF-1-safe
Quoted 78 lines
Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>--- xen/arch/x86/include/asm/compat.h | 5 +++++ xen/arch/x86/include/asm/cpufeatures.h | 4 +--- xen/arch/x86/include/asm/efibind.h | 5 +++++ xen/arch/x86/include/asm/hypercall.h | 6 +++--- 4 files changed, 14 insertions(+), 6 deletions(-)xen/arch/x86/include/asm/compat.h +5
-0@@ -2,6 +2,9 @@* compat.h */ +#ifndef __ASM_X86_COMPAT_H__ +#define __ASM_X86_COMPAT_H__ +#ifdef CONFIG_COMPAT #define COMPAT_BITS_PER_LONG 32@@ -18,3 +21,5 @@ int switch_compat(struct domain *);#include <xen/errno.h> static inline int switch_compat (struct domain *d) {return -EOPNOTSUPP ; }#endif + +#endif /* __ASM_X86_COMPAT_H__ */ xen/arch/x86/include/asm/cpufeatures.h +1
-3@@ -1,6 +1,4 @@ -/* -* Explicitly intended for multiple inclusion. -*/ +/* This file is legitimately included multiple times */ #include <xen/lib/x86/cpuid-autogen.h> xen/arch/x86/include/asm/efibind.h +5
-0@@ -1,2 +1,7 @@ +#ifndef __ASM_X86_EFIBIND_H__ +#define __ASM_X86_EFIBIND_H__ +#include <xen/types.h> #include <asm/x86_64/efibind.h> + +#endif /* __ASM_X86_EFIBIND_H__ */ xen/arch/x86/include/asm/hypercall.h +3
-3@@ -2,13 +2,13 @@* asm-x86/hypercall.h */ +#ifndef __ASM_X86_HYPERCALL_H__ +#define __ASM_X86_HYPERCALL_H__ +#ifndef __XEN_HYPERCALL_H__#error "asm/hypercall.h should not be included directly - include xen/hypercall.h instead"#endif -#ifndef __ASM_X86_HYPERCALL_H__ -#define __ASM_X86_HYPERCALL_H__ -#include <xen/types.h> #include <public/physdev.h> #include <public/event_channel.h> Signature · 1 line
2.34.1
Re: [XEN PATCH 01/13] misra: add deviation for headers that explicitly avoid guards
In reply to Stefano StabelliniQuoted 9 lines · Stefano Stabellini
Quoted 8 lines · Simone Ballarin
Some headers, under specific circumstances (documented in a comment at the beginning of the file), explicitly avoid inclusion guards: the caller is responsible for including them correctly.
These files are not supposed to comply with Directive 4.10:
"Precautions shall be taken in order to prevent the contents of a header file being included more than once"
Quoted 7 lines
Quoted 5 lines
This patch adds a deviation for all headers that contain the following in a comment text:
"In this case, no inclusion guards apply and the caller is responsible"Signed-off-by Simone Ballarin <[email protected]>
Actually one question
Quoted 13 lines
Quoted 13 lines
--- automation/eclair_analysis/ECLAIR/deviations.ecl | 4 ++++ docs/misra/rules.rst | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-)automation/eclair_analysis/ECLAIR/deviations.ecl +0
-0@@ -91,6 +91,10 @@ conform to the directive." -config=MC3R1.D4.10,reports+={safe, "first_area(text(^/\\* Generated file, do not edit! \\*/$, begin-3))"} -doc_end
Quoted 3 lines
automation/eclair_analysis/ECLAIR/deviations.ecl conform to the directive." · line 96
Quoted 3 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +3
-0+-doc_begin="Some headers, under specific circumstances, explicitly avoid inclusion guards." +-config=MC3R1.D4.10,reports+={safe, "first_area(text(^ \\* In this case, no inclusion guards apply and the caller is responsible.*\\*/$, begin-1))"} +-doc_end
Is this supposed to match with any files starting with "In this case, no inclusion..." ?
We should use the format introduced by safe.json instead
Re: [XEN PATCH 08/13] x86/mm: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinQuoted 10 lines · Simone Ballarin
Add inclusion guards to address violations of
MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").C files, if included somewhere, need to comply with the guideline.
Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>
Quoted 53 lines
--- xen/arch/x86/mm/guest_walk.c | 5 +++++ xen/arch/x86/mm/hap/guest_walk.c | 4 ++++ 2 files changed, 9 insertions(+)xen/arch/x86/mm/guest_walk.c +5
-0@@ -9,6 +9,9 @@* Parts based on earlier work by Michael A Fetterman, Ian Pratt et al. */ +#ifndef __X86_MM_GUEST_WALK_C__ +#define __X86_MM_GUEST_WALK_C__ +#include <xen/types.h> #include <xen/mm.h> #include <xen/paging.h> @@ -576,6 +579,8 @@ void *map_domain_gfn(struct p2m_domain *p2m, gfn_t gfn, mfn_t *mfn, }#endif +#endif /* __X86_MM_GUEST_WALK_C__ */ +/* * Local variables: * mode: C xen/arch/x86/mm/hap/guest_walk.c +4
-0@@ -7,6 +7,9 @@* Copyright (c) 2007, XenSource Inc. */ +#ifndef __X86_MM_HAP_GUEST_WALK_C__ +#define __X86_MM_HAP_GUEST_WALK_C__ +#include <xen/domain_page.h> #include <xen/paging.h> #include <xen/sched.h> @@ -124,6 +127,7 @@ unsigned long cf_check hap_p2m_ga_to_gfn(GUEST_PAGING_LEVELS)( return gfn_x(INVALID_GFN); } +#endif /* __X86_MM_HAP_GUEST_WALK_C__ */ /* * Local variables: Signature · 1 line
2.34.1
Re: [XEN PATCH 09/13] xen/common: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinQuoted 10 lines · Simone Ballarin
Add inclusion guards to address violations of
MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").Also C files, if included somewhere, need to comply with the guideline.
Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>
Quoted 121 lines
--- xen/common/compat/grant_table.c | 7 +++++++ xen/common/coverage/gcc_4_7.c | 5 +++++ xen/common/decompress.h | 5 +++++ xen/common/event_channel.h | 5 +++++ xen/common/multicall.c | 5 +++++ 5 files changed, 27 insertions(+)xen/common/compat/grant_table.c +7
-0@@ -3,6 +3,10 @@* */ + +#ifndef __COMMON_COMPAT_GRANT_TABLE_C__ +#define __COMMON_COMPAT_GRANT_TABLE_C__ +#include <xen/hypercall.h> #include <compat/grant_table.h> @@ -331,6 +335,9 @@ int compat_grant_table_op( return rc; } + +#endif /* __COMMON_COMPAT_GRANT_TABLE_C__ */ +/* * Local variables: * mode: C xen/common/coverage/gcc_4_7.c +5
-0@@ -14,6 +14,9 @@* Wei Liu <[email protected]> */ +#ifndef __COMMON_COVERAGE_GCC_4_7_C__ +#define __COMMON_COVERAGE_GCC_4_7_C__ +#include <xen/string.h> #include "gcov.h" @@ -193,6 +196,8 @@ size_t gcov_info_to_gcda(char *buffer, const struct gcov_info *info) return pos; } +#endif /* __COMMON_COVERAGE_GCC_4_7_C__ */ +/* * Local variables: * mode: C xen/common/decompress.h +5
-0@@ -1,3 +1,6 @@ +#ifndef __COMMON_DECOMPRESS_H__ +#define __COMMON_DECOMPRESS_H__ +#ifdef __XEN__#include <xen/cache.h> @@ -23,3 +26,5 @@#define large_free free#endif + +#endif /* __COMMON_DECOMPRESS_H__ */ xen/common/event_channel.h +5
-0@@ -1,5 +1,8 @@/* Event channel handling private header. */ +#ifndef __COMMON_EVENT_CHANNEL_H__ +#define __COMMON_EVENT_CHANNEL_H__ +#include <xen/event.h> static inline unsigned int max_evtchns (const struct domain *d)@@ -52,6 +55,8 @@ int evtchn_fifo_init_control(struct evtchn_init_control *init_control);int evtchn_fifo_expand_array (const struct evtchn_expand_array *expand_array);void evtchn_fifo_destroy (struct domain *d); +#endif /* __COMMON_EVENT_CHANNEL_H__ */ +/* * Local variables: * mode: C xen/common/multicall.c +5
-0@@ -2,6 +2,9 @@* multicall.c */ +#ifndef __COMMON_MULTICALL_C__ +#define __COMMON_MULTICALL_C__ +#include <xen/types.h> #include <xen/lib.h> #include <xen/mm.h> @@ -124,6 +127,8 @@ ret_t do_multicall( __HYPERVISOR_multicall, "hi", call_list, nr_calls-i); } +#endif /* __COMMON_MULTICALL_C__ */ +/* * Local variables: * mode: C Signature · 1 line
2.34.1
Re: [XEN PATCH 10/13] xen/efi: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinQuoted 37 lines · Simone Ballarin
Add inclusion guards to address violations of
MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").Also C files, if included somewhere, need to comply with the guideline.
Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>--- xen/common/efi/efi.h | 5 +++++ xen/common/efi/runtime.c | 6 ++++++ 2 files changed, 11 insertions(+)xen/common/efi/efi.h +5
-0@@ -1,3 +1,6 @@ +#ifndef __COMMON_EFI_EFI_H__ +#define __COMMON_EFI_EFI_H__ +#include <asm/efibind.h> #include <efi/efidef.h> #include <efi/efierr.h> @@ -51,3 +54,5 @@ void free_ebmalloc_unused_mem(void);const void *pe_find_section (const void *image,const UINTN image_size,const CHAR16 *section_name,UINTN *size_out); + +#endif /* __COMMON_EFI_EFI_H__ */ xen/common/efi/runtime.c +0
-0
xen/common/efi/runtime.c line 10
Quoted 5 lines
xen/common/efi/runtime.c +2
-0@@ -6,6 +6,10 @@#include <xen/irq.h> #include <xen/time.h> +#ifndef __COMMON_EFI_RUNTIME_C__ +#define __COMMON_EFI_RUNTIME_C__
Shouldn't this be at the top of the file?
Quoted 12 lines
xen/common/efi/runtime.c +2
-0DEFINE_XEN_GUEST_HANDLE (CHAR16 );struct efi_rs_state {@@ -704,3 +708,5 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *op)return rc; }#endif + +#endif /* __COMMON_EFI_RUNTIME_C__ */ Signature · 1 line
2.34.1
Re: [XEN PATCH 11/13] xen/sched: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinQuoted 8 lines · Simone Ballarin
Add inclusion guards to address violations of
MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>
Quoted 31 lines
--- xen/common/sched/compat.c | 6 ++++++ 1 file changed, 6 insertions(+)xen/common/sched/compat.c +6
-0@@ -3,6 +3,10 @@* */ +#ifndef __COMMON_SCHED_COMPAT_C__ +#define __COMMON_SCHED_COMPAT_C__ + +#include <compat/sched.h> #define COMPAT @@ -44,6 +48,8 @@ int compat_set_timer_op(uint32_t lo, int32_t hi) return do_set_timer_op(((s64)hi << 32) | lo); } +#endif /* __COMMON_SCHED_COMPAT_C__ */ +/* * Local variables: * mode: C Signature · 1 line
2.34.1
Re: [XEN PATCH 13/13] x86/asm: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinQuoted 21 lines · Simone Ballarin
Amend generation script to address a violation of
MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").This patch adds a special comment to the beginning of the header to make it explicit that the file is generated automatically.
The comment is recognized by ECLAIR and will cause the deviation of the violation.
Signed-off-by Simone Ballarin <[email protected]>--- xen/tools/compat-xlat-header.py | 2 ++ 1 file changed, 2 insertions(+)xen/tools/compat-xlat-header.py +0
-0
xen/tools/compat-xlat-header.py def main(): · line 409
Quoted 4 lines
xen/tools/compat-xlat-header.py +1
-0@@ -406,6 +406,8 @@ def main(): line = line.strip() header_tokens += re_tokenazier.split(line) + print("/* Generated file, do not edit! */")
I think it might be a good idea regardless of MISRA compliance to add this comment.
However for MISRA compliance I think we should document somewhere other than ECLAIR config file that "Generated file, do not edit!" is being used as a MISRA C deviation marker.
I think we should add a special note to safe.json, or alternatively also add the safe.json tag to the comment:
print("/* SAF-1-safe Generated file, do not edit! */")
Quoted 3 lines
xen/tools/compat-xlat-header.py +0
-0with open(sys.argv[2]) as compat_list: for line in compat_list: words = re_tokenazier.split(line, maxsplit=1)
Re: [XEN PATCH 12/13] xen: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinQuoted 25 lines · Simone Ballarin
Move or amended inclusion guards to address violations of MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Inclusion guards must appear at the beginning of the headers (comments are permitted anywhere) and the #if directive cannot be used for other checks.
Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>--- xen/include/xen/err.h | 4 +++- xen/include/xen/pci_ids.h | 5 +++++ xen/include/xen/softirq.h | 4 +++- xen/include/xen/unaligned.h | 7 ++++--- xen/include/xen/vmap.h | 4 +++- 5 files changed, 18 insertions(+), 6 deletions(-)xen/include/xen/err.h +0
-0
xen/include/xen/err.h line 3
Quoted 4 lines
xen/include/xen/err.h +2
-1@@ -1,5 +1,6 @@ -#if !defined(__XEN_ERR_H__) && !defined(__ASSEMBLY__) +#if !defined(__XEN_ERR_H__)#define __XEN_ERR_H__ +#if !defined(__ASSEMBLY__)
The original pattern was also guarding the header file sufficiently, protecting it from double-inclusion. In fact, it is posing stricter restrictions than usual (not laxer). This change is unnecessary?
Quoted 30 lines
xen/include/xen/err.h +1
-0#include <xen/compiler.h> #include <xen/errno.h> @@ -54,4 +55,5 @@ static inline int __must_check PTR_RET(const void *ptr)return IS_ERR (ptr) ?PTR_ERR (ptr) :0 ; } +#endif /* __ASSEMBLY__ */ #endif /* __XEN_ERR_H__ */ xen/include/xen/pci_ids.h +5
-0@@ -1,3 +1,6 @@ +#ifndef __XEN_PCI_IDS_H__ +#define __XEN_PCI_IDS_H__ +#define PCI_VENDOR_ID_AMD 0x1022#define PCI_VENDOR_ID_NVIDIA 0x10de@@ -11,3 +14,5 @@#define PCI_VENDOR_ID_BROADCOM 0x14e4#define PCI_VENDOR_ID_INTEL 0x8086 + +#endif /* __XEN_PCI_IDS_H__ */ xen/include/xen/softirq.h +0
-0
xen/include/xen/softirq.h line 3
Quoted 4 lines
xen/include/xen/softirq.h +2
-1@@ -1,5 +1,6 @@ -#if !defined(__XEN_SOFTIRQ_H__) && !defined(__ASSEMBLY__) +#if !defined(__XEN_SOFTIRQ_H__)#define __XEN_SOFTIRQ_H__ +#if !defined(__ASSEMBLY__)
same here
Quoted 35 lines
xen/include/xen/softirq.h +1
-0/* Low-latency softirqs come first in the following list. */ enum {@@ -40,4 +41,5 @@ void cpu_raise_softirq_batch_finish(void);*/ void process_pending_softirqs (void ); +#endif /* __ASSEMBLY__ */ #endif /* __XEN_SOFTIRQ_H__ */ xen/include/xen/unaligned.h +4
-3@@ -3,13 +3,14 @@* without faulting, and at least reasonably efficiently. Other architectures * will need to have a custom asm/unaligned.h. */ -#ifndef __ASM_UNALIGNED_H__ -#error "xen/unaligned.h should not be included directly - include asm/unaligned.h instead" -#endif #ifndef __XEN_UNALIGNED_H__#define __XEN_UNALIGNED_H__ +#ifndef __ASM_UNALIGNED_H__ +#error "xen/unaligned.h should not be included directly - include asm/unaligned.h instead" +#endif +#ifdef __XEN__#include <xen/types.h> #include <asm/byteorder.h> xen/include/xen/vmap.h +0
-0
xen/include/xen/vmap.h line 3
Quoted 4 lines
xen/include/xen/vmap.h +2
-1@@ -1,5 +1,6 @@ -#if !defined(__XEN_VMAP_H__) && defined(VMAP_VIRT_START ) +#if !defined(__XEN_VMAP_H__)#define __XEN_VMAP_H__ +#if defined(VMAP_VIRT_START )
same here
Quoted 11 lines
xen/include/xen/vmap.h +1
-0#include <xen/mm-frame.h> #include <xen/page-size.h> @@ -38,4 +39,5 @@ static inline void vm_init(void)vm_init_type (VMAP_DEFAULT , (void *)VMAP_VIRT_START ,arch_vmap_virt_end ()); } +#endif /* VMAP_VIRT_START */ #endif /* __XEN_VMAP_H__ */ Signature · 1 line
2.34.1
Re: [XEN PATCH 01/13] misra: add deviation for headers that explicitly avoid guards
In reply to Simone Ballarindocs/misra/rules.rst maintainers if you want to suggest a change. · line 64
Quoted 9 lines · Simone Ballarin
docs/misra/rules.rst +2
-1@@ -60,7 +60,8 @@ maintainers if you want to suggest a change. - Precautions shall be taken in order to prevent the contents of a header file being included more than once - Files that are intended to be included more than once do not need to - conform to the directive + conform to the directive. Files that explicitly avoid inclusion guards + under specific circumstances do not need to conform the directive.
Nit: There's a "to" missing near the end of the added sentence. Can likely be taken care of while committing, since Stefano has already ack-ed this, but I'd like to still raise the question of the utility of this statement:
How is one to know whether omission of guards is intentional?
Jan
Re: [XEN PATCH 02/13] automation/eclair: add text-based deviation for empty headers
In reply to Simone Ballarinautomation/eclair_analysis/ECLAIR/deviations.ecl inline functions." · line 82
Quoted 6 lines · Simone Ballarin
automation/eclair_analysis/ECLAIR/deviations.ecl +0
-0@@ -80,6 +80,7 @@ inline functions." -doc_begin="This header file is autogenerated or empty, therefore it poses no risk if included more than once."
While unrelated to, the change at hand, I still have a question on this:
How come it is deemed universally safe to multi-include generated headers. I would have said that whether that's safe depends on the nature of the generated code in the header. Only truly empty ones are uniformly safe to include any number of times.
Jan
Quoted 4 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +1
-0+-config=MC3R1.D4.10,reports+={safe, "first_area(text(^/\\* empty \\*/$, begin-1))"} -file_tag+={empty_header, "^xen/arch/arm/efi/runtime\\.h$"} -file_tag+={autogen_headers, "^xen/include/xen/compile\\.h$||^xen/include/generated/autoconf.h$||^xen/include/xen/hypercall-defs.h$"} -config=MC3R1.D4.10,reports+={safe, "all_area(all_loc(file(empty_header||autogen_headers)))"}
Re: [XEN PATCH 05/13] automation/eclair: add deviation for usercopy.c
In reply to Stefano StabelliniQuoted 21 lines · Stefano Stabellini
Quoted 20 lines · Simone Ballarin
automation/eclair_analysis/ECLAIR/deviations.ecl +4
-0@@ -96,6 +96,10 @@ conform to the directive." -config=MC3R1.D4.10,reports+={safe, "first_area(text(^ \\* In this case, no inclusion guards apply and the caller is responsible.*\\*/$, begin-1))"} -doc_end +-doc_begin="xen/arch/x86/usercopy.c includes itself: it is not supposed to comply with the directive" +-config=MC3R1.D4.10,reports+={deliberate, "all_area(all_loc(file("^xen/arch/x86/usercopy\\.c$")))"} +-doc_end + # # Series 5. #docs/misra/rules.rst +0
-0@@ -62,6 +62,8 @@ maintainers if you want to suggest a change. - Files that are intended to be included more than once do not need to conform to the directive. Files that explicitly avoid inclusion guards
Quoted 8 lines
docs/misra/rules.rst maintainers if you want to suggest a change. · line 66
Quoted 3 lines
docs/misra/rules.rst +2
-0under specific circumstances do not need to conform the directive. + xen/arch/x86/usercopy.c includes itself: it is not supposed to comply + with the directive.We need to find a consistent way to document this kind of deviations in a non-ECLAIR specific way, without adding the complete list of deviations to
rules.rst.
+1
Especially rules.rst should not be modified to add mention of individual exceptions. That's simply not the purpose of the file, at least the way I understand it.
Quoted 2 lines
Can we use safe.json and add an in-code comment at the top of
usercopy.c? E.g.:
Right, this ought to be the was to go. Question is whether ...
xen/arch/x86/usercopy.c line 1
Quoted 6 lines
xen/arch/x86/usercopy.c +1
-0@@ -1,3 +1,4 @@ +/* SAF-1-safe */
... this (or any other) placement of the comment will actually do (not just for Eclair).
Jan
Quoted 36 lines
xen/arch/x86/usercopy.c +0
-0/* * User address space access functions. * Otherwise, maybe we should extend safe.json to also have an extra field with a list of paths. For instance see "files" below:
{ "version": "1.0", "content": [ { "id": "SAF-0-safe", "analyser": { "eclair": "MC3R1.R8.6", "coverity": "misra_c_2012_rule_8_6_violation" }, "name": "Rule 8.6: linker script defined symbols", "text": "It is safe to declare this symbol because it is defined in the linker script." }, { "id": "SAF-1-safe", "analyser": { "eclair": "MC3R1.D4.10" }, "name": "Dir 4.10: files that include themselves", "text": "Files purposely written to include themselves are not supposed to comply with D4.10.", "files": ["xen/arch/x86/usercopy.c"] }, { "id": "SAF-2-safe", "analyser": {}, "name": "Sentinel", "text": "Next ID to be used" } ] }
Re: [XEN PATCH 07/13] x86/asm: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinQuoted 9 lines · Simone Ballarin
xen/arch/x86/include/asm/hypercall.h +3
-0@@ -2,13 +2,13 @@* asm-x86/hypercall.h */ +#ifndef __ASM_X86_HYPERCALL_H__ +#define __ASM_X86_HYPERCALL_H__ +
xen/arch/x86/include/asm/hypercall.h line 14
Quoted 10 lines
xen/arch/x86/include/asm/hypercall.h +0
-3#ifndef __XEN_HYPERCALL_H__#error "asm/hypercall.h should not be included directly - include xen/hypercall.h instead"#endif -#ifndef __ASM_X86_HYPERCALL_H__ -#define __ASM_X86_HYPERCALL_H__ -#include <xen/types.h> #include <public/physdev.h> #include <public/event_channel.h>
See Julien's comment on the similar Arm change.
Jan
Re: [XEN PATCH 10/13] xen/efi: address violations of MISRA C:2012 Directive 4.10
In reply to Stefano StabelliniQuoted 11 lines · Stefano Stabellini
xen/common/efi/runtime.c line 10
Quoted 8 lines · Simone Ballarin
xen/common/efi/runtime.c +2
-0@@ -6,6 +6,10 @@#include <xen/irq.h> #include <xen/time.h> +#ifndef __COMMON_EFI_RUNTIME_C__ +#define __COMMON_EFI_RUNTIME_C__Shouldn't this be at the top of the file?
Imo .c files shouldn't gain guards in the first place.
Jan
Re: [XEN PATCH 09/13] xen/common: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinQuoted 9 lines · Simone Ballarin
Add inclusion guards to address violations of
MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").Also C files, if included somewhere, need to comply with the guideline.
Mechanical change.
Quoted 8 lines
Signed-off-by Simone Ballarin <[email protected]>--- xen/common/compat/grant_table.c | 7 +++++++ xen/common/coverage/gcc_4_7.c | 5 +++++ xen/common/decompress.h | 5 +++++ xen/common/event_channel.h | 5 +++++ xen/common/multicall.c | 5 +++++ 5 files changed, 27 insertions(+)
As already said in reply to another patch, imo .c files shouldn't gain such guards. These are commonly referred to as "header guards" for a reason.
xen/common/compat/grant_table.c line 6
Quoted 7 lines
xen/common/compat/grant_table.c +1
-0@@ -3,6 +3,10 @@* */ +
Nit: No double blank lines please.
xen/common/compat/grant_table.c int compat_grant_table_op( · line 338
Quoted 11 lines
xen/common/compat/grant_table.c +4
-0+#ifndef __COMMON_COMPAT_GRANT_TABLE_C__ +#define __COMMON_COMPAT_GRANT_TABLE_C__ +#include <xen/hypercall.h> #include <compat/grant_table.h> @@ -331,6 +335,9 @@ int compat_grant_table_op(return rc; } +
Again here (at least).
Jan
Re: [XEN PATCH 12/13] xen: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinQuoted 6 lines · Simone Ballarin
xen/include/xen/unaligned.h +0
-0@@ -3,13 +3,14 @@* without faulting, and at least reasonably efficiently. Other architectures * will need to have a custom asm/unaligned.h. */
xen/include/xen/unaligned.h line 12
Quoted 10 lines
xen/include/xen/unaligned.h +3
-3-#ifndef __ASM_UNALIGNED_H__ -#error "xen/unaligned.h should not be included directly - include asm/unaligned.h instead" -#endif #ifndef __XEN_UNALIGNED_H__#define __XEN_UNALIGNED_H__ +#ifndef __ASM_UNALIGNED_H__ +#error "xen/unaligned.h should not be included directly - include asm/unaligned.h instead" +#endif
In addition to what Stefano said, this repositioning also is questionable (as per comments elsewhere). Overall it looks like the entire patch wants dropping? Or wait, no, the pci_ids.h change would remain.
Jan
Re: [XEN PATCH 04/13] xen/x86: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinQuoted 13 lines · Simone Ballarin
Add or move inclusion guards to address violations of MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Inclusion guards must appear at the beginning of the headers (comments are permitted anywhere).
Also C files, if included somewhere, need to comply with the guideline.
Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>
Quoted 10 lines
--- xen/arch/x86/Makefile | 8 ++++---- xen/arch/x86/cpu/cpu.h | 5 +++++ xen/arch/x86/physdev.c | 4 ++++ xen/arch/x86/platform_hypercall.c | 5 +++++ xen/arch/x86/x86_64/compat/mm.c | 5 +++++ xen/arch/x86/x86_64/mmconfig.h | 5 +++++ xen/arch/x86/x86_emulate/private.h | 5 +++++ xen/arch/x86/x86_emulate/x86_emulate.c | 5 +++++ 8 files changed, 38 insertions(+), 4 deletions(-)
Considering that the description talks of header files alone, there's a lot of non-header-file churn here.
Quoted 12 lines
xen/arch/x86/Makefile +2
-1@@ -259,17 +259,17 @@ $(objtree)/arch/x86/include/asm/asm-macros.h: $(obj)/asm-macros.i $(src)/Makefil $(call filechk,asm-macros.h) define filechk_asm-macros.h + echo '#ifndef __ASM_MACROS_H__'; \ + echo '#define __ASM_MACROS_H__'; \ echo '#if 0'; \ echo '.if 0'; \ echo '#endif'; \ - echo '#ifndef __ASM_MACROS_H__'; \
xen/arch/x86/Makefile $(objtree)/arch/x86/include/asm/asm-macros.h: $(obj)/asm-macros.i $(src)/Makefil · line 273
Quoted 10 lines
xen/arch/x86/Makefile +2
-3- echo '#define __ASM_MACROS_H__'; \ echo 'asm ( ".include \"$@\"" );'; \ - echo '#endif /* __ASM_MACROS_H__ */'; \ echo '#if 0'; \ echo '.endif'; \ cat $<; \ - echo '#endif' + echo '#endif'; \ + echo '#endif /* __ASM_MACROS_H__ */' endef
Can you please explain why this needs adjustment? While I think things are going to be okay with the adjustment, this dual C and assembler construct would imo better be left alone. Plus as per context found in patch 2, aren't generated headers excluded anyway?
Jan
Re: [XEN PATCH 06/13] x86/EFI: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinQuoted 18 lines · Simone Ballarin
Add inclusion guards to address violations of
MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>--- xen/arch/x86/efi/efi-boot.h | 6 ++++++ xen/arch/x86/efi/runtime.h | 5 +++++ 2 files changed, 11 insertions(+)xen/arch/x86/efi/efi-boot.h +0
-0
xen/arch/x86/efi/efi-boot.h line 8
Quoted 6 lines
xen/arch/x86/efi/efi-boot.h +3
-0@@ -3,6 +3,10 @@* is intended to be included by common/efi/boot.c _only_, and * therefore can define arch specific global variables. */ + +#ifndef __X86_EFI_EFI_BOOT_H__ +#define __X86_EFI_EFI_BOOT_H__
Considering the comment, I find the need for a guard here quite "interesting", to be honest.
Jan
Re: [XEN PATCH 01/13] misra: add deviation for headers that explicitly avoid guards
In reply to Jan BeulichQuoted 15 lines · Jan Beulich
docs/misra/rules.rst maintainers if you want to suggest a change. · line 64
Quoted 9 lines · Simone Ballarin
docs/misra/rules.rst +2
-1@@ -60,7 +60,8 @@ maintainers if you want to suggest a change. - Precautions shall be taken in order to prevent the contents of a header file being included more than once - Files that are intended to be included more than once do not need to - conform to the directive + conform to the directive. Files that explicitly avoid inclusion guards + under specific circumstances do not need to conform the directive.Nit: There's a "to" missing near the end of the added sentence. Can likely be taken care of while committing, since Stefano has already ack-ed this, but I'd like to still raise the question of the utility of this statement:
How is one to know whether omission of guards is intentional?
As suggested by Stefano, this kind of deviation should be done using
the format specified in safe.json, and I will follow his suggestion in the next submission. The statement will disappear.
Quoted 5 lines
Jan
Signature · 3 lines
Simone Ballarin, M.Sc. Field Application Engineer, BUGSENG (https://bugseng.com)
Re: [XEN PATCH 01/13] misra: add deviation for headers that explicitly avoid guards
In reply to Stefano StabelliniQuoted 34 lines · Stefano Stabellini
Quoted 9 lines · Stefano Stabellini
Quoted 8 lines · Simone Ballarin
Some headers, under specific circumstances (documented in a comment at the beginning of the file), explicitly avoid inclusion guards: the caller is responsible for including them correctly.
These files are not supposed to comply with Directive 4.10:
"Precautions shall be taken in order to prevent the contents of a header file being included more than once"Quoted 7 lines
Quoted 5 lines
This patch adds a deviation for all headers that contain the following in a comment text:
"In this case, no inclusion guards apply and the caller is responsible"Signed-off-by Simone Ballarin <[email protected]>Actually one question
Quoted 13 lines
Quoted 13 lines
--- automation/eclair_analysis/ECLAIR/deviations.ecl | 4 ++++ docs/misra/rules.rst | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-)automation/eclair_analysis/ECLAIR/deviations.ecl +0
-0@@ -91,6 +91,10 @@ conform to the directive." -config=MC3R1.D4.10,reports+={safe, "first_area(text(^/\\* Generated file, do not edit! \\*/$, begin-3))"} -doc_end
Quoted 9 lines
Quoted 3 lines
automation/eclair_analysis/ECLAIR/deviations.ecl conform to the directive." · line 96
Quoted 3 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +3
-0+-doc_begin="Some headers, under specific circumstances, explicitly avoid inclusion guards." +-config=MC3R1.D4.10,reports+={safe, "first_area(text(^ \\* In this case, no inclusion guards apply and the caller is responsible.*\\*/$, begin-1))"} +-doc_endIs this supposed to match with any files starting with "In this case, no inclusion..." ?
We should use the format introduced by safe.json instead
I agree, I will do it in the next submission.
Signature · 3 lines
Simone Ballarin, M.Sc. Field Application Engineer, BUGSENG (https://bugseng.com)
Re: [XEN PATCH 02/13] automation/eclair: add text-based deviation for empty headers
In reply to Stefano StabelliniQuoted 12 lines · Stefano Stabellini
Quoted 11 lines · Simone Ballarin
This patch adds a text-based deviation for Directive 4.10:
"Precautions shall be taken in order to prevent the contents of a header file being included more than once"Headers starting with the following comment are not supposed to comply with the directive:
"/* empty */"These headers should be empty, therefore they pose no risk if included more than once.
Quoted 6 lines
Quoted 1 line
Signed-off-by Simone Ballarin <[email protected]>However I think we should also update
rules.rstand/or updatedocs/misra/safe.json
I will do it in the next submission.
Quoted 22 lines
Quoted 21 lines
--- automation/eclair_analysis/ECLAIR/deviations.ecl | 1 + 1 file changed, 1 insertion(+)automation/eclair_analysis/ECLAIR/deviations.ecl +1
-0@@ -80,6 +80,7 @@ inline functions." -doc_begin="This header file is autogenerated or empty, therefore it poses no risk if included more than once." +-config=MC3R1.D4.10,reports+={safe, "first_area(text(^/\\* empty \\*/$, begin-1))"} -file_tag+={empty_header, "^xen/arch/arm/efi/runtime\\.h$"} -file_tag+={autogen_headers, "^xen/include/xen/compile\\.h$||^xen/include/generated/autoconf.h$||^xen/include/xen/hypercall-defs.h$"} -config=MC3R1.D4.10,reports+={safe, "all_area(all_loc(file(empty_header||autogen_headers)))"}Signature · 1 line
2.34.1
Signature · 3 lines
Simone Ballarin, M.Sc. Field Application Engineer, BUGSENG (https://bugseng.com)
Re: [XEN PATCH 02/13] automation/eclair: add text-based deviation for empty headers
In reply to Jan BeulichQuoted 5 lines · Jan Beulich
Quoted 4 lines · Simone Ballarin
automation/eclair_analysis/ECLAIR/deviations.ecl +0
-0@@ -80,6 +80,7 @@ inline functions."
Quoted 8 lines
automation/eclair_analysis/ECLAIR/deviations.ecl inline functions." · line 82
Quoted 2 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +0
-0-doc_begin="This header file is autogenerated or empty, therefore it poses no risk if included more than once."While unrelated to, the change at hand, I still have a question on this:
How come it is deemed universally safe to multi-include generated headers. I would have said that whether that's safe depends on the nature of the generated code in the header. Only truly empty ones are uniformly safe to include any number of times.
Yes, I agree with you. The mere fact that a file is auto-generated does not imply anything, moreover, this deviation is not even reported in rule.rst. In the next series, I'll drop it.
Quoted 8 lines
Jan
Quoted 4 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +1
-0+-config=MC3R1.D4.10,reports+={safe, "first_area(text(^/\\* empty \\*/$, begin-1))"} -file_tag+={empty_header, "^xen/arch/arm/efi/runtime\\.h$"} -file_tag+={autogen_headers, "^xen/include/xen/compile\\.h$||^xen/include/generated/autoconf.h$||^xen/include/xen/hypercall-defs.h$"} -config=MC3R1.D4.10,reports+={safe, "all_area(all_loc(file(empty_header||autogen_headers)))"}
Signature · 3 lines
Simone Ballarin, M.Sc. Field Application Engineer, BUGSENG (https://bugseng.com)
Re: [XEN PATCH 03/13] xen/arm: address violations of MISRA C:2012 Directive 4.10
In reply to Julien GrallQuoted 69 lines · Julien Grall
Hi,
Quoted 56 lines · Simone Ballarin
Add or move inclusion guards to address violations of MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Inclusion guards must appear at the beginning of the headers (comments are permitted anywhere).
Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>--- xen/arch/arm/efi/efi-boot.h | 6 ++++++ xen/arch/arm/include/asm/hypercall.h | 6 +++--- xen/arch/arm/include/asm/iocap.h | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-)xen/arch/arm/efi/efi-boot.h +6
-0@@ -3,6 +3,10 @@* is intended to be included by common/efi/boot.c _only_, and * therefore can define arch specific global variables. */ + +#ifndef __ARM_EFI_EFI_BOOT_H__ +#define __ARM_EFI_EFI_BOOT_H__ +#include <xen/device_tree.h> #include <xen/libfdt/libfdt.h> #include <asm/setup.h> @@ -1003,6 +1007,8 @@ static void __init efi_arch_flush_dcache_area(const void *vaddr, UINTN size) __flush_dcache_area(vaddr, size); } +#endif /* __ARM_EFI_EFI_BOOT_H__*/ +/* * Local variables: * mode: C
xen/arch/arm/include/asm/hypercall.h +3
-0@@ -1,10 +1,10 @@ +#ifndef __ASM_ARM_HYPERCALL_H__ +#define __ASM_ARM_HYPERCALL_H__ +#ifndef __XEN_HYPERCALL_H__#error "asm/hypercall.h should not be included directly - include
xen/hypercall.hinstead"
#endifxen/arch/arm/include/asm/hypercall.h line 7
Quoted 3 lines
xen/arch/arm/include/asm/hypercall.h +0
-3-#ifndef __ASM_ARM_HYPERCALL_H__ -#define __ASM_ARM_HYPERCALL_H__ -I understand that you are trying to fix a misra violation. However, this feels like it was done on purpose.
Quoted 3 lines
With the new change, you would not always check that the file were included at the correct place. I am not against this change but this ought to be explained.
I don't think the semantics have changed. Please correct me if I'm wrong.
With this change, the only situation where the check is not performed is when __ASM_ARM_HYPERCALL_H__ is defined (i.e. the file has already been successfully included). This implies that if __ASM_ARM_HYPERCALL_H__ is defined, then __XEN_HYPERCALL_H__ is also defined, so the check would be useless.
The same thing happened with the code before the change: if I include the file after xen/hypercall.h, the check will always succeed.
Quoted 26 lines
Quoted 11 lines
#include <public/domctl.h> /* for arch_do_domctl */long subarch_do_domctl(struct
xen_domctl*domctl, struct domain *d,xen/arch/arm/include/asm/iocap.h +0
-0xen/arch/arm/include/asm/iocap.h line 7
Quoted 10 lines
xen/arch/arm/include/asm/iocap.h +3
-3@@ -1,10 +1,10 @@ -#ifndef __X86_IOCAP_H__ -#define __X86_IOCAP_H__ +#ifndef __ASM_ARM_IOCAP_H__ +#define __ASM_ARM_IOCAP_H__#define cache_flush_permitted (d) \ (!rangeset_is_empty((d)->iomem_caps)) -#endif +#endif /* __ASM_ARM_IOCAP_H__ */ I don’t understand how this is related to the rest of the patch. You wrote that inclusion must appear first and this is the case here.
Quoted 4 lines
However the name is technically not correct. Is this really related to directive 4.10? If so, this should be clarified in the commit message. If not, then I think this should be in a separate commit.
Yes, you are right. This is not correlated to this series. I will put it on a separate commit.
Quoted 11 lines
Cheers,
Quoted 7 lines
xen/arch/arm/include/asm/iocap.h +0
-1/* * Local variables: -- 2.34.1
Signature · 3 lines
Simone Ballarin, M.Sc. Field Application Engineer, BUGSENG (https://bugseng.com)
Re: [XEN PATCH 03/13] xen/arm: address violations of MISRA C:2012 Directive 4.10
Quoted 27 lines · Simone Ballarin
Quoted 21 lines · Julien Grall
Quoted 11 lines · Simone Ballarin
xen/arch/arm/include/asm/hypercall.h +3
-0@@ -1,10 +1,10 @@ +#ifndef __ASM_ARM_HYPERCALL_H__ +#define __ASM_ARM_HYPERCALL_H__ +#ifndef __XEN_HYPERCALL_H__#error "asm/hypercall.h should not be included directly - include
xen/hypercall.hinstead"
#endifxen/arch/arm/include/asm/hypercall.h line 7
Quoted 3 lines
xen/arch/arm/include/asm/hypercall.h +0
-3-#ifndef __ASM_ARM_HYPERCALL_H__ -#define __ASM_ARM_HYPERCALL_H__ -I understand that you are trying to fix a misra violation. However, this feels like it was done on purpose.
Quoted 3 lines
With the new change, you would not always check that the file were included at the correct place. I am not against this change but this ought to be explained.
I don't think the semantics have changed. Please correct me if I'm wrong.
Quoted 8 lines
With this change, the only situation where the check is not performed is when
__ASM_ARM_HYPERCALL_H__is defined (i.e. the file has already been successfully included). This implies that if__ASM_ARM_HYPERCALL_H__is defined, then__XEN_HYPERCALL_H__is also defined, so the check would be useless.The same thing happened with the code before the change: if I include the file after
xen/hypercall.h, the check will always succeed.
Hmm, I think you're right, but I draw a different conclusion: The check fails to work as intended. And this can only be repaired without your adjustment.
Jan
Re: [XEN PATCH 03/13] xen/arm: address violations of MISRA C:2012 Directive 4.10
Quoted 34 lines · Jan Beulich
Quoted 33 lines · Simone Ballarin
Quoted 21 lines · Julien Grall
Quoted 11 lines · Simone Ballarin
xen/arch/arm/include/asm/hypercall.h +3
-0@@ -1,10 +1,10 @@ +#ifndef __ASM_ARM_HYPERCALL_H__ +#define __ASM_ARM_HYPERCALL_H__ +#ifndef __XEN_HYPERCALL_H__#error "asm/hypercall.h should not be included directly - include
xen/hypercall.hinstead"
#endifxen/arch/arm/include/asm/hypercall.h line 7
Quoted 3 lines
xen/arch/arm/include/asm/hypercall.h +0
-3-#ifndef __ASM_ARM_HYPERCALL_H__ -#define __ASM_ARM_HYPERCALL_H__ -I understand that you are trying to fix a misra violation. However, this feels like it was done on purpose.
Quoted 3 lines
With the new change, you would not always check that the file were included at the correct place. I am not against this change but this ought to be explained.
I don't think the semantics have changed. Please correct me if I'm wrong.
With this change, the only situation where the check is not performed is when
__ASM_ARM_HYPERCALL_H__is defined (i.e. the file has already been successfully included). This implies that if__ASM_ARM_HYPERCALL_H__is defined, then__XEN_HYPERCALL_H__is also defined, so the check would be useless.
Quoted 7 lines
Quoted 2 lines
The same thing happened with the code before the change: if I include the file after
xen/hypercall.h, the check will always succeed.Hmm, I think you're right, but I draw a different conclusion: The check fails to work as intended. And this can only be repaired without your adjustment.
Ok, I will just deviate these cases.
Quoted 1 line
Jan
Signature · 3 lines
Simone Ballarin, M.Sc. Field Application Engineer, BUGSENG (https://bugseng.com)
Re: [XEN PATCH 05/13] automation/eclair: add deviation for usercopy.c
In reply to Stefano StabelliniQuoted 83 lines · Stefano Stabellini
+Nicola, Luca
Quoted 34 lines · Simone Ballarin
xen/arch/x86/usercopy.cincludes itself, so it is not supposed to comply with Directive 4.10:
"Precautions shall be taken in order to prevent the contents of a header file being included more than once"This patch adds a deviation for the file.
Signed-off-by Simone Ballarin <[email protected]>--- automation/eclair_analysis/ECLAIR/deviations.ecl | 4 ++++ docs/misra/rules.rst | 2 ++ 2 files changed, 6 insertions(+)automation/eclair_analysis/ECLAIR/deviations.ecl +4
-0@@ -96,6 +96,10 @@ conform to the directive." -config=MC3R1.D4.10,reports+={safe, "first_area(text(^ \\* In this case, no inclusion guards apply and the caller is responsible.*\\*/$, begin-1))"} -doc_end +-doc_begin="xen/arch/x86/usercopy.c includes itself: it is not supposed to comply with the directive" +-config=MC3R1.D4.10,reports+={deliberate, "all_area(all_loc(file("^xen/arch/x86/usercopy\\.c$")))"} +-doc_end + # # Series 5. #docs/misra/rules.rst +0
-0docs/misra/rules.rst maintainers if you want to suggest a change. · line 66
Quoted 5 lines
docs/misra/rules.rst +2
-0@@ -62,6 +62,8 @@ maintainers if you want to suggest a change. - Files that are intended to be included more than once do not need to conform to the directive. Files that explicitly avoid inclusion guards under specific circumstances do not need to conform the directive. + xen/arch/x86/usercopy.c includes itself: it is not supposed to comply + with the directive.We need to find a consistent way to document this kind of deviations in a non-ECLAIR specific way, without adding the complete list of deviations to
rules.rst.Can we use safe.json and add an in-code comment at the top of
usercopy.c? E.g.:xen/arch/x86/usercopy.c +1
-0@@ -1,3 +1,4 @@ +/* SAF-1-safe */ /* * User address space access functions. * Quoted 1 line
Otherwise, maybe we should extend safe.json to also have an extra field
with a list of paths. For instance see "files" below >
{ "version": "1.0", "content": [ { "id": "SAF-0-safe", "analyser": { "eclair": "MC3R1.R8.6", "coverity": "misra_c_2012_rule_8_6_violation" }, "name": "Rule 8.6: linker script defined symbols", "text": "It is safe to declare this symbol because it is defined in the linker script." }, { "id": "SAF-1-safe", "analyser": { "eclair": "MC3R1.D4.10" }, "name": "Dir 4.10: files that include themselves", "text": "Files purposely written to include themselves are not supposed to comply with D4.10.", "files": ["xen/arch/x86/usercopy.c"] },
Quoted 9 lines
{
"id": "SAF-2-safe",
"analyser": {},
"name": "Sentinel",
"text": "Next ID to be used"
}
]
}In general, I prefer the first option for such ad hoc deviation (the comment at the beginning of the file): this way, anyone who touches the file will immediately see the comment and think as its changes will affect the deviation (is it still safe? is it still necessary?).
To help the developer more, I think it is better to also add the "name" in the comment, this is my proposal:
/* SAF-4-safe Dir 4.10: files that include themselves*/ /*
* User address space access functions.
*
* Copyright 1997 Andi Kleen <[email protected]>
* Copyright 1997 Linus Torvalds
* Copyright 2002 Andi Kleen <[email protected]>
*/
Signature · 3 lines
Simone Ballarin, M.Sc. Field Application Engineer, BUGSENG (https://bugseng.com)
Re: [XEN PATCH 11/13] xen/sched: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinQuoted 9 lines · Simone Ballarin
Add inclusion guards to address violations of
MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>
Re: [XEN PATCH 06/13] x86/EFI: address violations of MISRA C:2012 Directive 4.10
In reply to Jan BeulichQuoted 29 lines · Jan Beulich
Quoted 18 lines · Simone Ballarin
Add inclusion guards to address violations of
MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>--- xen/arch/x86/efi/efi-boot.h | 6 ++++++ xen/arch/x86/efi/runtime.h | 5 +++++ 2 files changed, 11 insertions(+)xen/arch/x86/efi/efi-boot.h +0
-0xen/arch/x86/efi/efi-boot.h line 8
Quoted 6 lines
xen/arch/x86/efi/efi-boot.h +3
-0@@ -3,6 +3,10 @@* is intended to be included by common/efi/boot.c _only_, and * therefore can define arch specific global variables. */ + +#ifndef __X86_EFI_EFI_BOOT_H__ +#define __X86_EFI_EFI_BOOT_H__Considering the comment, I find the need for a guard here quite "interesting", to be honest.
Quoted 1 line
Jan
I don't think a simple comment is enough to say that "precautions have been taken". For the moment, I will drop this change to keep this patch going.
Signature · 3 lines
Simone Ballarin, M.Sc. Field Application Engineer, BUGSENG (https://bugseng.com)
Re: [XEN PATCH 07/13] x86/asm: address violations of MISRA C:2012 Directive 4.10
In reply to Stefano StabelliniQuoted 9 lines · Stefano Stabellini
Quoted 8 lines · Simone Ballarin
Add or move inclusion guards to address violations of MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Inclusion guards must appear at the beginning of the headers (comments are permitted anywhere).
Quoted 8 lines
Quoted 3 lines
The text of the beggining comment of
cpufeatures.hhas been changed to match the deviation in automation/eclair_analysis/ECLAIR/deviations.ecl, moreover this new formulation is already used in other files.I don't think it is a good idea to do this kind of textual matching. Instead we should use the format introduced by safe.json, e.g. SAF-1-safe
I agree. I will use a comment-based deviation.
Quoted 79 lines
Quoted 79 lines
Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>--- xen/arch/x86/include/asm/compat.h | 5 +++++ xen/arch/x86/include/asm/cpufeatures.h | 4 +--- xen/arch/x86/include/asm/efibind.h | 5 +++++ xen/arch/x86/include/asm/hypercall.h | 6 +++--- 4 files changed, 14 insertions(+), 6 deletions(-)xen/arch/x86/include/asm/compat.h +5
-0@@ -2,6 +2,9 @@* compat.h */ +#ifndef __ASM_X86_COMPAT_H__ +#define __ASM_X86_COMPAT_H__ +#ifdef CONFIG_COMPAT #define COMPAT_BITS_PER_LONG 32@@ -18,3 +21,5 @@ int switch_compat(struct domain *);#include <xen/errno.h> static inline int switch_compat (struct domain *d) {return -EOPNOTSUPP ; }#endif + +#endif /* __ASM_X86_COMPAT_H__ */ xen/arch/x86/include/asm/cpufeatures.h +1
-3@@ -1,6 +1,4 @@ -/* -* Explicitly intended for multiple inclusion. -*/ +/* This file is legitimately included multiple times */ #include <xen/lib/x86/cpuid-autogen.h> xen/arch/x86/include/asm/efibind.h +5
-0@@ -1,2 +1,7 @@ +#ifndef __ASM_X86_EFIBIND_H__ +#define __ASM_X86_EFIBIND_H__ +#include <xen/types.h> #include <asm/x86_64/efibind.h> + +#endif /* __ASM_X86_EFIBIND_H__ */ xen/arch/x86/include/asm/hypercall.h +3
-3@@ -2,13 +2,13 @@* asm-x86/hypercall.h */ +#ifndef __ASM_X86_HYPERCALL_H__ +#define __ASM_X86_HYPERCALL_H__ +#ifndef __XEN_HYPERCALL_H__#error "asm/hypercall.h should not be included directly - include xen/hypercall.h instead"#endif -#ifndef __ASM_X86_HYPERCALL_H__ -#define __ASM_X86_HYPERCALL_H__ -#include <xen/types.h> #include <public/physdev.h> #include <public/event_channel.h> Signature · 1 line
2.34.1
Signature · 3 lines
Simone Ballarin, M.Sc. Field Application Engineer, BUGSENG (https://bugseng.com)
Re: [XEN PATCH 05/13] automation/eclair: add deviation for usercopy.c
In reply to Simone BallarinQuoted 108 lines · Simone Ballarin
Quoted 93 lines · Stefano Stabellini
+Nicola, Luca
Quoted 39 lines · Simone Ballarin
xen/arch/x86/usercopy.cincludes itself, so it is not supposed to comply with Directive 4.10:
"Precautions shall be taken in order to prevent the contents of a header file being included more than once"This patch adds a deviation for the file.
Signed-off-by Simone Ballarin <[email protected]>--- automation/eclair_analysis/ECLAIR/deviations.ecl | 4 ++++ docs/misra/rules.rst | 2 ++ 2 files changed, 6 insertions(+)automation/eclair_analysis/ECLAIR/deviations.ecl +0
-0@@ -96,6 +96,10 @@ conform to the directive." -config=MC3R1.D4.10,reports+={safe, "first_area(text(^ \\* In this case, no inclusion guards apply and the caller is responsible.*\\*/$, begin-1))"} -doc_end +-doc_begin="xen/arch/x86/usercopy.c includes itself: it is not supposedto comply with the directive" +-config=MC3R1.D4.10,reports+={deliberate, "all_area(all_loc(file("^xen/arch/x86/usercopy\\.c$")))"} +-doc_end
automation/eclair_analysis/ECLAIR/deviations.ecl +1
-0+ # # Series 5. #docs/misra/rules.rst +0
-0@@ -62,6 +62,8 @@ maintainers if you want to suggest a change. - Files that are intended to be included more than once do not needQuoted 8 lines
to
conform to the directive. Files that explicitly avoid inclusion
guards
under specific circumstances do not need to conform the
directive.
+xen/arch/x86/usercopy.cincludes itself: it is not supposed to
comply
+ with the directive.We need to find a consistent way to document this kind of deviations in a non-ECLAIR specific way, without adding the complete list of deviations to
rules.rst.Can we use safe.json and add an in-code comment at the top of
usercopy.c? E.g.:xen/arch/x86/usercopy.c +1
-0@@ -1,3 +1,4 @@ +/* SAF-1-safe */ /* * User address space access functions. * Quoted 1 line
Otherwise, maybe we should extend safe.json to also have an extra field
with a list of paths. For instance see "files" below >
{ "version": "1.0", "content": [ { "id": "SAF-0-safe", "analyser": { "eclair": "MC3R1.R8.6", "coverity": "misra_c_2012_rule_8_6_violation" }, "name": "Rule 8.6: linker script defined symbols", "text": "It is safe to declare this symbol because it is defined in the linker script." }, { "id": "SAF-1-safe", "analyser": { "eclair": "MC3R1.D4.10" }, "name": "Dir 4.10: files that include themselves", "text": "Files purposely written to include themselves are not supposed to comply with D4.10.", "files": ["xen/arch/x86/usercopy.c"] },Quoted 9 lines
{ "id": "SAF-2-safe", "analyser": {}, "name": "Sentinel", "text": "Next ID to be used" } ] }In general, I prefer the first option for such ad hoc deviation (the comment at the beginning of the file): this way, anyone who touches the file will immediately see the comment and think as its changes will affect the deviation (is it still safe? is it still necessary?).
Quoted 4 lines
To help the developer more, I think it is better to also add the "name" in the comment, this is my proposal:
/* SAF-4-safe Dir 4.10: files that include themselves*/
Yes, this is fine, it was always intended to be possible to add the name of the deviation or a short comment in the in-code comment
Quoted 13 lines
/*
* User address space access functions.
*
* Copyright 1997 Andi Kleen <[email protected]>
* Copyright 1997 Linus Torvalds
* Copyright 2002 Andi Kleen <[email protected]>
*/Signature · 3 lines
Simone Ballarin, M.Sc. Field Application Engineer, BUGSENG (https://bugseng.com)
Re: [XEN PATCH 05/13] automation/eclair: add deviation for usercopy.c
Quoted 49 lines · Stefano Stabellini
Quoted 48 lines · Simone Ballarin
Quoted 33 lines · Stefano Stabellini
On Mon, 28 Aug 2023, Simone Ballarin wrote:
xen/arch/x86/usercopy.c +1
-0@@ -1,3 +1,4 @@ +/* SAF-1-safe */ /* * User address space access functions. * Quoted 1 line
Otherwise, maybe we should extend safe.json to also have an extra field
with a list of paths. For instance see "files" below >
{ "version": "1.0", "content": [ { "id": "SAF-0-safe", "analyser": { "eclair": "MC3R1.R8.6", "coverity": "misra_c_2012_rule_8_6_violation" }, "name": "Rule 8.6: linker script defined symbols", "text": "It is safe to declare this symbol because it is defined in the linker script." }, { "id": "SAF-1-safe", "analyser": { "eclair": "MC3R1.D4.10" }, "name": "Dir 4.10: files that include themselves", "text": "Files purposely written to include themselves are not supposed to comply with D4.10.", "files": ["xen/arch/x86/usercopy.c"] },Quoted 9 lines
{ "id": "SAF-2-safe", "analyser": {}, "name": "Sentinel", "text": "Next ID to be used" } ] }In general, I prefer the first option for such ad hoc deviation (the comment at the beginning of the file): this way, anyone who touches the file will immediately see the comment and think as its changes will affect the deviation (is it still safe? is it still necessary?).
Quoted 7 lines
Quoted 4 lines
To help the developer more, I think it is better to also add the "name" in the comment, this is my proposal:
/* SAF-4-safe Dir 4.10: files that include themselves*/
Yes, this is fine, it was always intended to be possible to add the name of the deviation or a short comment in the in-code comment
But then either the directive number wants omitting, or the Misra version needs to also be stated.
Jan
Re: [XEN PATCH 09/13] xen/common: address violations of MISRA C:2012 Directive 4.10
In reply to Jan BeulichQuoted 19 lines · Jan Beulich
Quoted 9 lines · Simone Ballarin
Add inclusion guards to address violations of
MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").Also C files, if included somewhere, need to comply with the guideline.
Mechanical change.
Quoted 8 lines
Signed-off-by Simone Ballarin <[email protected]>--- xen/common/compat/grant_table.c | 7 +++++++ xen/common/coverage/gcc_4_7.c | 5 +++++ xen/common/decompress.h | 5 +++++ xen/common/event_channel.h | 5 +++++ xen/common/multicall.c | 5 +++++ 5 files changed, 27 insertions(+)
Quoted 3 lines
As already said in reply to another patch, imo .c files shouldn't gain such guards. These are commonly referred to as "header guards" for a reason.
This is the MISRA's definition of "header file" (MISRA C:2012 Revision 1, Appendix J):
"A header file is any file that is the subject of a #include
directive.
Note: the filename extension is not significant."
So, the guards are required if we want to comply with the directive, otherwise we can raise a deviation.
The danger of multi-inclusion also exists for .c files, why do you want to avoid guards for them?
Quoted 25 lines
xen/common/compat/grant_table.c line 6
Quoted 7 lines
xen/common/compat/grant_table.c +1
-0@@ -3,6 +3,10 @@* */ +Nit: No double blank lines please.
xen/common/compat/grant_table.c int compat_grant_table_op( · line 338
Quoted 11 lines
xen/common/compat/grant_table.c +4
-0+#ifndef __COMMON_COMPAT_GRANT_TABLE_C__ +#define __COMMON_COMPAT_GRANT_TABLE_C__ +#include <xen/hypercall.h> #include <compat/grant_table.h> @@ -331,6 +335,9 @@ int compat_grant_table_op(return rc; } +Again here (at least).
Jan
Signature · 3 lines
Simone Ballarin, M.Sc. Field Application Engineer, BUGSENG (https://bugseng.com)
Re: [XEN PATCH 09/13] xen/common: address violations of MISRA C:2012 Directive 4.10
Quoted 24 lines · Simone Ballarin
Quoted 19 lines · Jan Beulich
Quoted 9 lines · Simone Ballarin
Add inclusion guards to address violations of
MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").Also C files, if included somewhere, need to comply with the guideline.
Mechanical change.
Quoted 8 lines
Signed-off-by Simone Ballarin <[email protected]>--- xen/common/compat/grant_table.c | 7 +++++++ xen/common/coverage/gcc_4_7.c | 5 +++++ xen/common/decompress.h | 5 +++++ xen/common/event_channel.h | 5 +++++ xen/common/multicall.c | 5 +++++ 5 files changed, 27 insertions(+)Quoted 3 lines
As already said in reply to another patch, imo .c files shouldn't gain such guards. These are commonly referred to as "header guards" for a reason.
Quoted 6 lines
This is the MISRA's definition of "header file" (MISRA C:2012 Revision 1, Appendix J):
"A header file is any file that is the subject of a #include
directive.
Note: the filename extension is not significant."
That's completely misleading terminology then.
Quoted 5 lines
So, the guards are required if we want to comply with the directive, otherwise we can raise a deviation.
The danger of multi-inclusion also exists for .c files, why do you want to avoid guards for them?
Counter question: Why only add guards to some of them? (My personal answer is "Because it's extra clutter.")
Jan
Re: [XEN PATCH 12/13] xen: address violations of MISRA C:2012 Directive 4.10
In reply to Stefano StabelliniQuoted 21 lines · Stefano Stabellini
Quoted 20 lines · Simone Ballarin
Move or amended inclusion guards to address violations of MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Inclusion guards must appear at the beginning of the headers (comments are permitted anywhere) and the #if directive cannot be used for other checks.
Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>--- xen/include/xen/err.h | 4 +++- xen/include/xen/pci_ids.h | 5 +++++ xen/include/xen/softirq.h | 4 +++- xen/include/xen/unaligned.h | 7 ++++--- xen/include/xen/vmap.h | 4 +++- 5 files changed, 18 insertions(+), 6 deletions(-)
Quoted 13 lines
xen/include/xen/err.h line 3
Quoted 9 lines
xen/include/xen/err.h +2
-1@@ -1,5 +1,6 @@ -#if !defined(__XEN_ERR_H__) && !defined(__ASSEMBLY__) +#if !defined(__XEN_ERR_H__)#define __XEN_ERR_H__ +#if !defined(__ASSEMBLY__)The original pattern was also guarding the header file sufficiently, protecting it from double-inclusion. In fact, it is posing stricter restrictions than usual (not laxer). This change is unnecessary?
The MISRA directive asks to use one of the two following forms:
<start-of-file>
#if !defined ( identifier )
#define identifier
/* Contents of file */
#endif
<end-of-file>
<start-of-file>
#ifndef identifier
#define identifier
/* Contents of file */
#endif
<end-of-file>
I do not see any reason for deviating, but if you ask that, I can do it.
Quoted 95 lines
Quoted 32 lines
xen/include/xen/err.h +1
-0#include <xen/compiler.h> #include <xen/errno.h> @@ -54,4 +55,5 @@ static inline int __must_check PTR_RET(const void *ptr)return IS_ERR (ptr) ?PTR_ERR (ptr) :0 ; } +#endif /* __ASSEMBLY__ */ #endif /* __XEN_ERR_H__ */ xen/include/xen/pci_ids.h +5
-0@@ -1,3 +1,6 @@ +#ifndef __XEN_PCI_IDS_H__ +#define __XEN_PCI_IDS_H__ +#define PCI_VENDOR_ID_AMD 0x1022#define PCI_VENDOR_ID_NVIDIA 0x10de@@ -11,3 +14,5 @@#define PCI_VENDOR_ID_BROADCOM 0x14e4#define PCI_VENDOR_ID_INTEL 0x8086 + +#endif /* __XEN_PCI_IDS_H__ */ xen/include/xen/softirq.h +0
-0xen/include/xen/softirq.h line 3
Quoted 4 lines
xen/include/xen/softirq.h +2
-1@@ -1,5 +1,6 @@ -#if !defined(__XEN_SOFTIRQ_H__) && !defined(__ASSEMBLY__) +#if !defined(__XEN_SOFTIRQ_H__)#define __XEN_SOFTIRQ_H__ +#if !defined(__ASSEMBLY__)same here
Quoted 35 lines
xen/include/xen/softirq.h +1
-0/* Low-latency softirqs come first in the following list. */ enum {@@ -40,4 +41,5 @@ void cpu_raise_softirq_batch_finish(void);*/ void process_pending_softirqs (void ); +#endif /* __ASSEMBLY__ */ #endif /* __XEN_SOFTIRQ_H__ */ xen/include/xen/unaligned.h +4
-3@@ -3,13 +3,14 @@* without faulting, and at least reasonably efficiently. Other architectures * will need to have a custom asm/unaligned.h. */ -#ifndef __ASM_UNALIGNED_H__ -#error "xen/unaligned.h should not be included directly - include asm/unaligned.h instead" -#endif #ifndef __XEN_UNALIGNED_H__#define __XEN_UNALIGNED_H__ +#ifndef __ASM_UNALIGNED_H__ +#error "xen/unaligned.h should not be included directly - include asm/unaligned.h instead" +#endif +#ifdef __XEN__#include <xen/types.h> #include <asm/byteorder.h> xen/include/xen/vmap.h +0
-0xen/include/xen/vmap.h line 3
Quoted 4 lines
xen/include/xen/vmap.h +2
-1@@ -1,5 +1,6 @@ -#if !defined(__XEN_VMAP_H__) && defined(VMAP_VIRT_START ) +#if !defined(__XEN_VMAP_H__)#define __XEN_VMAP_H__ +#if defined(VMAP_VIRT_START )same here
Quoted 11 lines
xen/include/xen/vmap.h +1
-0#include <xen/mm-frame.h> #include <xen/page-size.h> @@ -38,4 +39,5 @@ static inline void vm_init(void)vm_init_type (VMAP_DEFAULT , (void *)VMAP_VIRT_START ,arch_vmap_virt_end ()); } +#endif /* VMAP_VIRT_START */ #endif /* __XEN_VMAP_H__ */ Signature · 1 line
2.34.1
Signature · 3 lines
Simone Ballarin, M.Sc. Field Application Engineer, BUGSENG (https://bugseng.com)
Re: [XEN PATCH 12/13] xen: address violations of MISRA C:2012 Directive 4.10
Quoted 45 lines · Simone Ballarin
Quoted 21 lines · Stefano Stabellini
Quoted 20 lines · Simone Ballarin
Move or amended inclusion guards to address violations of MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Inclusion guards must appear at the beginning of the headers (comments are permitted anywhere) and the #if directive cannot be used for other checks.
Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>--- xen/include/xen/err.h | 4 +++- xen/include/xen/pci_ids.h | 5 +++++ xen/include/xen/softirq.h | 4 +++- xen/include/xen/unaligned.h | 7 ++++--- xen/include/xen/vmap.h | 4 +++- 5 files changed, 18 insertions(+), 6 deletions(-)Quoted 13 lines
xen/include/xen/err.h line 3
Quoted 9 lines
xen/include/xen/err.h +2
-1@@ -1,5 +1,6 @@ -#if !defined(__XEN_ERR_H__) && !defined(__ASSEMBLY__) +#if !defined(__XEN_ERR_H__)#define __XEN_ERR_H__ +#if !defined(__ASSEMBLY__)The original pattern was also guarding the header file sufficiently, protecting it from double-inclusion. In fact, it is posing stricter restrictions than usual (not laxer). This change is unnecessary?
The MISRA directive asks to use one of the two following forms:
<start-of-file>
#if !defined ( identifier )
#define identifier
/* Contents of file */
#endif
<end-of-file>
Quoted 8 lines
<start-of-file>
#ifndef identifier
#define identifier
/* Contents of file */
#endif
<end-of-file>I do not see any reason for deviating, but if you ask that, I can do it.
I do not see a reason why a deviation would be needed here. Misra shouldn't be more pedantic / restrictive than necessary to achieve its goals. Looking at the flood of changes we've already seen, pointless changes really shouldn't be asked for.
Jan
Re: [XEN PATCH 09/13] xen/common: address violations of MISRA C:2012 Directive 4.10
In reply to Jan BeulichQuoted 25 lines · Jan Beulich
Quoted 24 lines · Simone Ballarin
Quoted 22 lines · Jan Beulich
Quoted 9 lines · Simone Ballarin
Add inclusion guards to address violations of
MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").Also C files, if included somewhere, need to comply with the guideline.
Mechanical change.
Quoted 8 lines
Signed-off-by Simone Ballarin <[email protected]>--- xen/common/compat/grant_table.c | 7 +++++++ xen/common/coverage/gcc_4_7.c | 5 +++++ xen/common/decompress.h | 5 +++++ xen/common/event_channel.h | 5 +++++ xen/common/multicall.c | 5 +++++ 5 files changed, 27 insertions(+)As already said in reply to another patch, imo .c files shouldn't gain such guards. These are commonly referred to as "header guards" for a reason.
Quoted 9 lines
Quoted 6 lines
This is the MISRA's definition of "header file" (MISRA C:2012 Revision 1, Appendix J):
"A header file is any file that is the subject of a #include
directive.
Note: the filename extension is not significant."That's completely misleading terminology then.
I might agree with you on this, but either way this is the definition to apply when reading the guideline. IMHO here, the best would be to use a separate extension for "C files intended to be included" (but that's not the point).
Quoted 11 lines
Quoted 5 lines
So, the guards are required if we want to comply with the directive, otherwise we can raise a deviation.
The danger of multi-inclusion also exists for .c files, why do you want to avoid guards for them?
Counter question: Why only add guards to some of them? (My personal answer is "Because it's extra clutter.")
Jan
It's not "some of them", it's exactly the ones used in an #include directive, so I'm not getting your objection.
By the way, if the community agrees, I can deviate all C files and drop the changes.
Signature · 3 lines
Simone Ballarin, M.Sc. Field Application Engineer, BUGSENG (https://bugseng.com)
Re: [XEN PATCH 09/13] xen/common: address violations of MISRA C:2012 Directive 4.10
Quoted 10 lines · Simone Ballarin
Quoted 6 lines · Jan Beulich
Quoted 2 lines · Simone Ballarin
The danger of multi-inclusion also exists for .c files, why do you want to avoid guards for them?
Counter question: Why only add guards to some of them? (My personal answer is "Because it's extra clutter.")
It's not "some of them", it's exactly the ones used in an #include directive, so I'm not getting your objection.
My point is that by adding guards only for files we presently use in some #include directive, we set us up for introducing new violations as soon as another .c file becomes the subject of an #include. The more that it is unusual to add guards in .c files, i.e. it is to be expected that people wouldn't think about this extra Misra requirement.
Jan
Re: [XEN PATCH 09/13] xen/common: address violations of MISRA C:2012 Directive 4.10
Quoted 12 lines · Jan Beulich
Quoted 10 lines · Simone Ballarin
Quoted 6 lines · Jan Beulich
Quoted 2 lines · Simone Ballarin
The danger of multi-inclusion also exists for .c files, why do you want to avoid guards for them?
Counter question: Why only add guards to some of them? (My personal answer is "Because it's extra clutter.")
It's not "some of them", it's exactly the ones used in an #include directive, so I'm not getting your objection.
Quoted 7 lines
My point is that by adding guards only for files we presently use in some #include directive, we set us up for introducing new violations as soon as another .c file becomes the subject of an #include.The more that it is unusual to add guards in .c files, i.e. it is to be expected that people wouldn't think about this extra Misra requirement.
Jan
I can agree to partially adopt the directive: I will add a deviation for C files in rules.txt.
Signature · 3 lines
Simone Ballarin, M.Sc. Field Application Engineer, BUGSENG (https://bugseng.com)
Re: [XEN PATCH 05/13] automation/eclair: add deviation for usercopy.c
In reply to Stefano StabelliniQuoted 80 lines · Stefano Stabellini
+Nicola, Luca
Quoted 34 lines · Simone Ballarin
xen/arch/x86/usercopy.cincludes itself, so it is not supposed to comply with Directive 4.10:
"Precautions shall be taken in order to prevent the contents of a header file being included more than once"This patch adds a deviation for the file.
Signed-off-by Simone Ballarin <[email protected]>---
automation/eclair_analysis/ECLAIR/deviations.ecl | 4 ++++docs/misra/rules.rst| 2 ++2 files changed, 6 insertions(+)automation/eclair_analysis/ECLAIR/deviations.ecl +4
-2@@ -96,6 +96,10 @@ conform to the directive." -config=MC3R1.D4.10,reports+={safe, "first_area(text(^ \\* In this case, no inclusion guards apply and the caller is responsible.*\\*/$, begin-1))"} -doc_end +-doc_begin="xen/arch/x86/usercopy.c includes itself: it is not supposed to comply with the directive" +-config=MC3R1.D4.10,reports+={deliberate, "all_area(all_loc(file("^xen/arch/x86/usercopy\\.c$")))"} +-doc_end + # # Series 5. #docs/misra/rules.rst +0
-0docs/misra/rules.rst maintainers if you want to suggest a change. · line 66
Quoted 5 lines
docs/misra/rules.rst +2
-0@@ -62,6 +62,8 @@ maintainers if you want to suggest a change. - Files that are intended to be included more than once do not need to conform to the directive. Files that explicitly avoid inclusion guards under specific circumstances do not need to conform the directive. + xen/arch/x86/usercopy.c includes itself: it is not supposed to comply + with the directive.We need to find a consistent way to document this kind of deviations in a non-ECLAIR specific way, without adding the complete list of deviations to
rules.rst.Can we use safe.json and add an in-code comment at the top of
usercopy.c? E.g.:xen/arch/x86/usercopy.c +1
-0@@ -1,3 +1,4 @@ +/* SAF-1-safe */ /* * User address space access functions. * Otherwise, maybe we should extend safe.json to also have an extra field with a list of paths. For instance see "files" below:
{ "version": "1.0", "content": [ { "id": "SAF-0-safe", "analyser": { "eclair": "MC3R1.R8.6", "coverity": "misra_c_2012_rule_8_6_violation" }, "name": "Rule 8.6: linker script defined symbols", "text": "It is safe to declare this symbol because it is defined in the linker script." },
Quoted 8 lines
{
"id": "SAF-1-safe",
"analyser": {
"eclair": "MC3R1.D4.10"
},
"name": "Dir 4.10: files that include themselves",
"text": "Files purposely written to include themselves are not supposed to comply with D4.10.",
"files": ["xen/arch/x86/usercopy.c"]Why couldn’t we do it without the “files” field? The presence of the tag in the file and the justification (I think) are enough.
Quoted 9 lines
}, { "id": "SAF-2-safe", "analyser": {}, "name": "Sentinel", "text": "Next ID to be used" }]
}
Re: [XEN PATCH 09/13] xen/common: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinQuoted 20 lines · Simone Ballarin
Quoted 19 lines · Jan Beulich
Quoted 11 lines · Simone Ballarin
Quoted 7 lines · Jan Beulich
Quoted 3 lines · Simone Ballarin
The danger of multi-inclusion also exists for .c files, why do you want
to avoid guards for them?Counter question: Why only add guards to some of them? (My personal answer is "Because it's extra clutter.")
It's not "some of them", it's exactly the ones used in an #include directive, so I'm not getting your objection.
My point is that by adding guards only for files we presently use in some #include directive, we set us up for introducing new violations as soon as another .c file becomes the subject of an #include.The more that it is unusual to add guards in .c files, i.e. it is to be expected that people wouldn't think about this extra Misra requirement.
Quoted 4 lines
Quoted 1 line
Jan
I can agree to partially adopt the directive: I will add a deviation for C files in rules.txt.
Sorry for the late reply as I was OOO. Please hold on before adding a deviation for C files.
In general, I think including .c files is not common behavior, and should be restricted to special cases. We could say that exactly because they are special, they follow different rules so we can skip the guards. Or we could say that they are still at risk of double-inclusion, hence we should be consistent and protect them too. I think we should discuss the topic during the next MISRA C meeting.
Re: [XEN PATCH 12/13] xen: address violations of MISRA C:2012 Directive 4.10
In reply to Simone BallarinQuoted 45 lines · Simone Ballarin
Quoted 21 lines · Stefano Stabellini
Quoted 20 lines · Simone Ballarin
Move or amended inclusion guards to address violations of MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Inclusion guards must appear at the beginning of the headers (comments are permitted anywhere) and the #if directive cannot be used for other checks.
Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>--- xen/include/xen/err.h | 4 +++- xen/include/xen/pci_ids.h | 5 +++++ xen/include/xen/softirq.h | 4 +++- xen/include/xen/unaligned.h | 7 ++++--- xen/include/xen/vmap.h | 4 +++- 5 files changed, 18 insertions(+), 6 deletions(-)Quoted 13 lines
xen/include/xen/err.h line 3
Quoted 9 lines
xen/include/xen/err.h +2
-1@@ -1,5 +1,6 @@ -#if !defined(__XEN_ERR_H__) && !defined(__ASSEMBLY__) +#if !defined(__XEN_ERR_H__)#define __XEN_ERR_H__ +#if !defined(__ASSEMBLY__)The original pattern was also guarding the header file sufficiently, protecting it from double-inclusion. In fact, it is posing stricter restrictions than usual (not laxer). This change is unnecessary?
The MISRA directive asks to use one of the two following forms:
<start-of-file>
#if !defined ( identifier )
#define identifier
/* Contents of file */
#endif
<end-of-file>
Quoted 8 lines
<start-of-file>
#ifndef identifier
#define identifier
/* Contents of file */
#endif
<end-of-file>I do not see any reason for deviating, but if you ask that, I can do it.
Let's follow MISRA's form.
Re: [XEN PATCH 09/13] xen/common: address violations of MISRA C:2012 Directive 4.10
In reply to Stefano StabelliniQuoted 27 lines · Stefano Stabellini
Quoted 14 lines · Simone Ballarin
Quoted 13 lines · Jan Beulich
Quoted 11 lines · Simone Ballarin
Quoted 7 lines · Jan Beulich
Quoted 3 lines · Simone Ballarin
The danger of multi-inclusion also exists for .c files, why do you want
to avoid guards for them?Counter question: Why only add guards to some of them? (My personal answer is "Because it's extra clutter.")
It's not "some of them", it's exactly the ones used in an #include directive, so I'm not getting your objection.
Quoted 8 lines
Quoted 5 lines
My point is that by adding guards only for files we presently use in some #include directive, we set us up for introducing new violations as soon as another .c file becomes the subject of an #include.The more that it is unusual to add guards in .c files, i.e. it is to be expected that people wouldn't think about this extra Misra requirement.
I can agree to partially adopt the directive: I will add a deviation for C files in rules.txt.
Sorry for the late reply as I was OOO. Please hold on before adding a deviation for C files.
Quoted 6 lines
In general, I think including .c files is not common behavior, and should be restricted to special cases. We could say that exactly because they are special, they follow different rules so we can skip the guards. Or we could say that they are still at risk of double-inclusion, hence we should be consistent and protect them too. I think we should discuss the topic during the next MISRA C meeting.
Just one further remark right here: While including a header file a 2nd time stands a fair chance of working (i.e. the compiler not spitting out errors), that would be very unusual for a .c file: Every function or data item it defines would (in the common case) be already defined.
Jan
Re: [XEN PATCH 12/13] xen: address violations of MISRA C:2012 Directive 4.10
In reply to Stefano StabelliniQuoted 53 lines · Stefano Stabellini
Quoted 52 lines · Simone Ballarin
Quoted 21 lines · Stefano Stabellini
Quoted 20 lines · Simone Ballarin
Move or amended inclusion guards to address violations of MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Inclusion guards must appear at the beginning of the headers (comments are permitted anywhere) and the #if directive cannot be used for other checks.
Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>--- xen/include/xen/err.h | 4 +++- xen/include/xen/pci_ids.h | 5 +++++ xen/include/xen/softirq.h | 4 +++- xen/include/xen/unaligned.h | 7 ++++--- xen/include/xen/vmap.h | 4 +++- 5 files changed, 18 insertions(+), 6 deletions(-)Quoted 13 lines
xen/include/xen/err.h line 3
Quoted 9 lines
xen/include/xen/err.h +2
-1@@ -1,5 +1,6 @@ -#if !defined(__XEN_ERR_H__) && !defined(__ASSEMBLY__) +#if !defined(__XEN_ERR_H__)#define __XEN_ERR_H__ +#if !defined(__ASSEMBLY__)The original pattern was also guarding the header file sufficiently, protecting it from double-inclusion. In fact, it is posing stricter restrictions than usual (not laxer). This change is unnecessary?
The MISRA directive asks to use one of the two following forms:
<start-of-file>
#if !defined ( identifier )
#define identifier
/* Contents of file */
#endif
<end-of-file><start-of-file>
#ifndef identifier
#define identifier
/* Contents of file */
#endif
<end-of-file>
Quoted 3 lines
Quoted 1 line
I do not see any reason for deviating, but if you ask that, I can do it.
Let's follow MISRA's form.
This is what I strongly dislike: They could be less restrictive on the exact patterns permitted without impacting the goal intended to be reached. But it's all as simple as possible, not as flexible as possible.
In any event, if a transformation like what can still be seen in context is to be made, then please #ifdef / #ifndef instead of defined(...) whenever possible.
Jan
Re: [XEN PATCH 09/13] xen/common: address violations of MISRA C:2012 Directive 4.10
In reply to Stefano StabelliniQuoted 29 lines · Stefano Stabellini
Quoted 20 lines · Simone Ballarin
Quoted 19 lines · Jan Beulich
Quoted 11 lines · Simone Ballarin
Quoted 7 lines · Jan Beulich
Quoted 3 lines · Simone Ballarin
The danger of multi-inclusion also exists for .c files, why do you want
to avoid guards for them?Counter question: Why only add guards to some of them? (My personal answer is "Because it's extra clutter.")
It's not "some of them", it's exactly the ones used in an #include directive, so I'm not getting your objection.
My point is that by adding guards only for files we presently use in some #include directive, we set us up for introducing new violations as soon as another .c file becomes the subject of an #include.The more that it is unusual to add guards in .c files, i.e. it is to be expected that people wouldn't think about this extra Misra requirement.
Quoted 4 lines
Quoted 1 line
Jan
I can agree to partially adopt the directive: I will add a deviation for C files in rules.txt.
Sorry for the late reply as I was OOO. Please hold on before adding a deviation for C files.
Quoted 7 lines
In general, I think including .c files is not common behavior, and should be restricted to special cases. We could say that exactly because they are special, they follow different rules so we can skip the guards. Or we could say that they are still at risk of double-inclusion, hence we should be consistent and protect them too. I think we should discuss the topic during the next MISRA C meeting.
Ok, I will drop changes in C files without adding the deviation.
Signature · 3 lines
Simone Ballarin, M.Sc. Field Application Engineer, BUGSENG (https://bugseng.com)
Re: [XEN PATCH 12/13] xen: address violations of MISRA C:2012 Directive 4.10
In reply to Jan BeulichQuoted 58 lines · Jan Beulich
Quoted 53 lines · Stefano Stabellini
Quoted 52 lines · Simone Ballarin
Quoted 21 lines · Stefano Stabellini
Quoted 20 lines · Simone Ballarin
Move or amended inclusion guards to address violations of MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order to prevent the contents of a header file being included more than once").
Inclusion guards must appear at the beginning of the headers (comments are permitted anywhere) and the #if directive cannot be used for other checks.
Mechanical change.
Signed-off-by Simone Ballarin <[email protected]>--- xen/include/xen/err.h | 4 +++- xen/include/xen/pci_ids.h | 5 +++++ xen/include/xen/softirq.h | 4 +++- xen/include/xen/unaligned.h | 7 ++++--- xen/include/xen/vmap.h | 4 +++- 5 files changed, 18 insertions(+), 6 deletions(-)Quoted 13 lines
xen/include/xen/err.h line 3
Quoted 9 lines
xen/include/xen/err.h +2
-1@@ -1,5 +1,6 @@ -#if !defined(__XEN_ERR_H__) && !defined(__ASSEMBLY__) +#if !defined(__XEN_ERR_H__)#define __XEN_ERR_H__ +#if !defined(__ASSEMBLY__)The original pattern was also guarding the header file sufficiently, protecting it from double-inclusion. In fact, it is posing stricter restrictions than usual (not laxer). This change is unnecessary?
The MISRA directive asks to use one of the two following forms:
<start-of-file>
#if !defined ( identifier )
#define identifier
/* Contents of file */
#endif
<end-of-file><start-of-file>
#ifndef identifier
#define identifier
/* Contents of file */
#endif
<end-of-file>Quoted 3 lines
Quoted 1 line
I do not see any reason for deviating, but if you ask that, I can do it.
Let's follow MISRA's form.
Quoted 7 lines
This is what I strongly dislike: They could be less restrictive on the exact patterns permitted without impacting the goal intended to be reached. But it's all as simple as possible, not as flexible as possible.
In any event, if a transformation like what can still be seen in context is to be made, then please #ifdef / #ifndef instead of defined(...) whenever possible.
In all fairness I dislike this too. However the rule is clear that to make it easier to implement MISRA C checkers MISRA only supports 2 specific patterns. And I can see they have a point there in making it easier to automatically check for correctness.
So I would go ahead with the change.