From patchwork Wed Aug 2 08:57:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13337888 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EAC46C001DF for ; Wed, 2 Aug 2023 08:58:40 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.574808.900392 (Exim 4.92) (envelope-from ) id 1qR7gU-0002xe-6C; Wed, 02 Aug 2023 08:58:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 574808.900392; Wed, 02 Aug 2023 08:58:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qR7gU-0002xX-3Z; Wed, 02 Aug 2023 08:58:22 +0000 Received: by outflank-mailman (input) for mailman id 574808; Wed, 02 Aug 2023 08:58:21 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qR7gT-0002xR-Hr for xen-devel@lists.xenproject.org; Wed, 02 Aug 2023 08:58:21 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ba0df38c-3112-11ee-b25e-6b7b168915f2; Wed, 02 Aug 2023 10:58:19 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id A030B4EE0737; Wed, 2 Aug 2023 10:58:17 +0200 (CEST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ba0df38c-3112-11ee-b25e-6b7b168915f2 From: Nicola Vetrini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, michal.orzel@amd.com, xenia.ragiadakou@amd.com, ayan.kumar.halder@amd.com, consulting@bugseng.com, Nicola Vetrini , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Wei Liu , =?utf-8?q?Roger_Pau_Mo?= =?utf-8?q?nn=C3=A9?= Subject: [XEN PATCH v2] x86/cpu-policy: justify a violation of MISRA C:2012 Rule 1.3 Date: Wed, 2 Aug 2023 10:57:59 +0200 Message-Id: <30fdada8b08b2060c6f1ccc2ecb06d418efd97b0.1690966632.git.nicola.vetrini@bugseng.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 The empty feature set 'str_7c1' in 'tools/misc/xen-cpuid.c' causes the struct declaration to have no named members, hence violating Rule 1.3: "There shall be no occurrence of undefined or critical unspecified behaviour" because it is forbidden by ISO/IEC 9899:1999(E), Section 6.7.2.1.7: "If the struct-declaration-list contains no named members, the behavior is undefined." Given that Xen is using an undocumented GCC extension that specifies the behaviour upon defining a struct with no named member, this construct is well-defined and thus it is marked as safe. No functional changes. Signed-off-by: Nicola Vetrini --- Changes in v2: - Added a comment mentioning the use of a GCC extension. Note for v1: As agreed during the MISRA C group meetings, this violation is dealt with by means of a comment deviation, as future changes may eliminate the root cause, which is the empty feature set. My justification for the claim and the commit message may need some adjusting. Note for v2: Note that GCC does not document the particular usage of non-empty structs with no named members, but it works as expected nonetheless. --- docs/misra/safe.json | 9 +++++++++ xen/include/xen/lib/x86/cpu-policy.h | 1 + 2 files changed, 10 insertions(+) diff --git a/docs/misra/safe.json b/docs/misra/safe.json index e3c8a1d8eb..ec2bd58777 100644 --- a/docs/misra/safe.json +++ b/docs/misra/safe.json @@ -12,6 +12,15 @@ }, { "id": "SAF-1-safe", + "analyser": { + "eclair": "MC3R1.R1.3", + "text": "The following declaration of a struct with no named members is deliberate and the use of an undocumented GCC extension ensures that the behaviour is fully defined for that compiler." + }, + "name": "Sentinel", + "text": "Next ID to be used" + }, + { + "id": "SAF-2-safe", "analyser": {}, "name": "Sentinel", "text": "Next ID to be used" diff --git a/xen/include/xen/lib/x86/cpu-policy.h b/xen/include/xen/lib/x86/cpu-policy.h index bab3eecda6..6b52f080c9 100644 --- a/xen/include/xen/lib/x86/cpu-policy.h +++ b/xen/include/xen/lib/x86/cpu-policy.h @@ -203,6 +203,7 @@ struct cpu_policy }; union { uint32_t _7c1; + /* SAF-1-safe */ struct { DECL_BITFIELD(7c1); }; }; union {