From nobody Thu Oct 30 15:32:00 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass(p=quarantine dis=none) header.from=epam.com ARC-Seal: i=2; a=rsa-sha256; t=1761591154; cv=pass; d=zohomail.com; s=zohoarc; b=A/YzkrNbKatCYjNXxMf5QOkGXSdgJFTLycmFR1i8dzV8xXk+dYymy2B1tUIGnZBINu3bsGLwZO/d0Jp8ZyVN0EVFSWSAqMATKqKUOhHW598iX6Ypym0IMYZYsU5TPq3NzmEBg0zbh523GtjPBRVp8OBXweraVCYw7QEKAX08/GM= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761591154; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Awc8EWaFBCYfnRzVdONL9wuE5SU3NIVJ63vA+l3SDD0=; b=CPYgcaLsqSsTvFQ/kLkb94+IKNj/5nes0soQB3RrDGAafG53Qmom2Fh7uJzZajQyZEadcJrupdJD+6zp3C4nGFa7NdedAQtTYV3Vp/Tr4qaHodkUFqsdg1aLRey05+x8sy+Vmd/F9mIJbOYv96g6X06bBJEdVaB6zY97i27tKxI= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=epam.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1761591154773938.6299529584772; Mon, 27 Oct 2025 11:52:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1151734.1482270 (Exim 4.92) (envelope-from ) id 1vDSJv-0006IG-Rj; Mon, 27 Oct 2025 18:51:55 +0000 Received: by outflank-mailman (output) from mailman id 1151734.1482270; Mon, 27 Oct 2025 18:51:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vDSJv-0006I9-OL; Mon, 27 Oct 2025 18:51:55 +0000 Received: by outflank-mailman (input) for mailman id 1151734; Mon, 27 Oct 2025 18:51:54 +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 1vDSJu-0006I1-40 for xen-devel@lists.xenproject.org; Mon, 27 Oct 2025 18:51:54 +0000 Received: from OSPPR02CU001.outbound.protection.outlook.com (mail-norwayeastazlp170130007.outbound.protection.outlook.com [2a01:111:f403:c20f::7]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ff960cf5-b365-11f0-9d16-b5c5bf9af7f9; Mon, 27 Oct 2025 19:51:52 +0100 (CET) Received: from DB7PR03MB4140.eurprd03.prod.outlook.com (2603:10a6:5:34::10) by PR3PR03MB6650.eurprd03.prod.outlook.com (2603:10a6:102:7d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9253.18; Mon, 27 Oct 2025 18:51:48 +0000 Received: from DB7PR03MB4140.eurprd03.prod.outlook.com ([fe80::e16e:b655:974f:43f3]) by DB7PR03MB4140.eurprd03.prod.outlook.com ([fe80::e16e:b655:974f:43f3%4]) with mapi id 15.20.9253.017; Mon, 27 Oct 2025 18:51:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: ff960cf5-b365-11f0-9d16-b5c5bf9af7f9 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=isIxUWHXJUGe0VuRwEDh9ahLeOPb+CuyMLYBPkKUrJIBB3aPdFCjRnq/r64+t3yqI3G/5HvLqpqQc2HylN8ihXMgnUahYyb4ic8YwQ4lPW8JA9oYFw1qlo5TxIPa7VNXBe+5MqI8l0ogIYTyTO8XwX/ww2h66o7epY1JMCT4ok1AARp7NQivABprPILtJ7S8MRGFXoLLjM2pbpkw2a5A3oncTdI2hiAnND959gChwE74Efr3qTeLYj2f58MnuGfQ818TEY6dYhDTRJAw+AQ+R515DH3slSJjGFvxCl/yyPzyw1mXWPp0+BBcAkb5hVijg6xj30cKlXcOeqFUFBleog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Awc8EWaFBCYfnRzVdONL9wuE5SU3NIVJ63vA+l3SDD0=; b=bxmZtm9NFsTfOfbc4pqb20w3tQ9guF+qPtyhwhQeBbzyMkXawGAwX0YS94XtdGnzsJdM55zr/ihr68O5lnIXMbMXr0ZtA2JE9NDBV1EcghvERPppVw5MrnN+yXfkNNuvbSmEcvyVHAFBCAYQ/2HEdx/baCAmrYfX4CrH8FI+Rzrsovj0U3HXt7XPDl2OvUNyIAslByInSvazEGomC0bD8DYyf/eXpww4viIEG6HXB8wRqahYqhH+oHa7/0xsQ/nSRXND0nH5t9S8Pz65FlbttkbagD1m4LVNm7kbb7elNPuUWicp7YX/SLK0HbvBkpc1pkgZ+ArsB5TyWV0skhOaRg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Awc8EWaFBCYfnRzVdONL9wuE5SU3NIVJ63vA+l3SDD0=; b=nzUz1BHF3DhkRLjtEemhsuvyeMyM13XgeCfe+i8YHufcot7E1RfXgVBJmMnbhuYDDDOtiEJq1V7cL6GGCIfW8naimMT4yPYIxouLNFUXmhBKJmiBqAmril3DhA5Ot0JGJyGmV1Crfat4bcOfT7tpqeeLshoprqhQkkeexG7ji/gKtwOxtfPejigBFaSVd0zxbHaqC7Md12HUcyrn5CCxXI/3s1AOk1m24/Y08+tqh8CIN0mINUwm1h2sryzTYvLyhs0pfIsVaUCXLSZLU51QaF5LlHfHjKoYnjU8NciiRO3yz6JtHRV6HTi5oEM1+OE4lSHbb2El7KGgtWjV8r0RiA== From: Dmytro Prokopchuk1 To: "xen-devel@lists.xenproject.org" CC: Dmytro Prokopchuk1 , Nicola Vetrini , Doug Goldstein , Stefano Stabellini , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?iso-8859-1?Q?Roger_Pau_Monn=E9?= Subject: [PATCH v4] misra: consider conversion from UL or (void*) to function pointer as safe Thread-Topic: [PATCH v4] misra: consider conversion from UL or (void*) to function pointer as safe Thread-Index: AQHcR3K/aTBeUCgm+E66rbTSUIb8rQ== Date: Mon, 27 Oct 2025 18:51:47 +0000 Message-ID: Accept-Language: en-US, uk-UA, ru-RU Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DB7PR03MB4140:EE_|PR3PR03MB6650:EE_ x-ms-office365-filtering-correlation-id: b16d4d93-b6ad-4bab-b984-08de1589e1cd x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0;ARA:13230040|42112799006|7416014|376014|1800799024|366016|38070700021; x-microsoft-antispam-message-info: =?iso-8859-1?Q?9G1bqlMPtSwZGkonbLcSnXXhj9tocTBNioSEGZdeZYSDqN58Md/kRonKCp?= =?iso-8859-1?Q?eLeZN5lVlhhCR61vS3nj3mEsOhvqv94rIDVD4zKauN1GpuhFY1A8/pL14R?= =?iso-8859-1?Q?rSBZzK24bpE5vE7FZso5g6yR9cH0nhnqz9PtB/oZGYP9FQaEHJiTiKQnHQ?= =?iso-8859-1?Q?nRBh5HfbxwZYuEbfTh4GDlnpdgtFJIVoDokuIPHCqFDRLaAIzNGrE2aZkb?= =?iso-8859-1?Q?TnQV6eyKdjGJJz9OOHsU+m0W3vfCz+2kUv37o2UrM7sPc5NsTLTAfhJjLK?= =?iso-8859-1?Q?tEpu+tSUqdmDcLCXC/c+PY0emImwFlURkmPlCQ2GVJ00n6s2dZekjC6pBn?= =?iso-8859-1?Q?Q0PIBqZ82HerC2pxrloSL7fLrBNx5F2NaOuNstTdhnt5Xgy1i68/TeGtVa?= =?iso-8859-1?Q?kCAXXMM9At57Nt9dVX/t0YLzvfzOSeGDQftdPkPPkspJTtHRNgh5gZgbYV?= =?iso-8859-1?Q?RqE4+yH760jpOXdP9x3uCj3GAP95hgBH8Y4DzmQF5n74AVHPLkziBtV1tx?= =?iso-8859-1?Q?vU1Wkq7wKTV6X1AqmSmEAcc/QlJ4uJ1H6pHOFxwIO9ZJmVmfXHbphtMqk9?= =?iso-8859-1?Q?kLlRNZb12w42UFfmsOI+dE4bbfY6ZmNHYTCWFJvQUSROes/dQSsW32LdU9?= =?iso-8859-1?Q?46DCMwWC8KCPSnlZ5M2scK4vWvNytauRTeaS4otPBVs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CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB7PR03MB4140.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(42112799006)(7416014)(376014)(1800799024)(366016)(38070700021);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?Q?Rmzx6VvZH9XPSBcLZoa/cDBOBSgUV0s/Qd8hBk6Vbjg23UTFJ7PuAhckeg?= =?iso-8859-1?Q?eHICLoAXalXRECrF+WA/F8hLKgiROeF/QyDjmBsgB0wL79u7750S3J2t8G?= =?iso-8859-1?Q?+7puqAxpyrNpBmRyP9SXFbwtdIs5orNYxktuZBhNq2iNzQtkBsQZSArrU0?= =?iso-8859-1?Q?tt8AY86ub3q8LAC3DGAg3StLmy7xjM22iMCkCnC+WDrv70SIfGnxCLlu89?= =?iso-8859-1?Q?DucxE11A8RhIiqgNxmN+ljpROaCQg8Bdl0dG6h+pTED7FMSyrYM9Tr6QhS?= =?iso-8859-1?Q?eBOtldfatKWek7liPxN8OaeaW09SzO4HGZQTsynNPe4cHJNW2iYgxyZNQc?= =?iso-8859-1?Q?x4V9oKJf26AqCeEwSmSoBqzxw0H4N4D1Ftc72KgjCdF/cAvLtjKhZ1C0Bf?= =?iso-8859-1?Q?t6vjoHQ2evB1bqJrEobvSVoBWu5tjB9xU4xCPC5NLZFzHpoHJYbokuZfTo?= =?iso-8859-1?Q?GjPGd97nV1Yq+HLos+hU2SpELxDNMayR0zBla73XUNnSxgeQdzaXMIyv7f?= =?iso-8859-1?Q?I+F4J49OT1wPr5W8fWYyojfRMHdR6rkIseKaYm7Y+M0OfDIdy6ARQTofGk?= =?iso-8859-1?Q?ivEB+1RYNmyx4wxf9ZtR69QvqX+HZqbtqEmU77+o0cPJOdYblUQ0DWZQMO?= =?iso-8859-1?Q?pgvbm82RwupyFie9PhQcBhdtMkI7PdyQmJ5se40Jgs9N7qhh9eZ/ZG/Yt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KGi4b/ksIXd9RIkknxHnbR8Q1rL7?= =?iso-8859-1?Q?UVIG4uoVEsbobHHTR2GJmLOPKPxlOFIABOb/deNtqcC0lZpQCW3m5zQg?= =?iso-8859-1?Q?=3D=3D?= Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4140.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b16d4d93-b6ad-4bab-b984-08de1589e1cd X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Oct 2025 18:51:47.5704 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: LgGiaRGLFg/IRwvKsJcu/d0WxnWZZdR5AJvic/LBjW3Z62/4AJt02SXWaEh6AYfPKP6cFjqbrry0HvkR+mp82qwYbe8KYdnAuBbf70cgq2s= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR03MB6650 X-ZohoMail-DKIM: pass (identity @epam.com) X-ZM-MESSAGEID: 1761591157394158500 Content-Type: text/plain; charset="utf-8" Rule 11.1 states as following: "Conversions shall not be performed between a pointer to a function and any other type." This deviation from Rule 11.1 relies on both ABI definitions and compiler implementations supported by Xen. The System V x86_64 ABI and the AArch64 ELF ABI define consistent and compatible representations (i.e., having the same size and memory layout) for (void *), unsigned long, and function pointers, enabling safe conversions between these types without data loss or corruption. Additionally, GCC and Clang, faithfully implement the ABI specifications, ensuring that the generated machine code conforms to these guarantees. Developers must note that this behavior is not universal and depends on platform-specific ABIs and compiler implementations. Configure Eclair to avoid reporting violations for conversions from unsigned long or (void *) to a function pointer. Add a compile-time assertion into the file 'xen/common/version.c' to confirm this conversion compatibility across X86 and ARM platforms (assuming this file is common for them). References: - System V x86_64 ABI: https://gitlab.com/x86-psABIs/x86-64-ABI/-/jobs/arti= facts/master/raw/x86-64-ABI/abi.pdf?job=3Dbuild - AArch64 ELF ABI: https://github.com/ARM-software/abi-aa/releases - GCC: https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html - Clang: https://clang.llvm.org/docs/CrossCompilation.html Signed-off-by: Dmytro Prokopchuk Reviewed-by: Nicola Vetrini --- Changes in v4: - the build assertions for the X86 and ARM are enabled by default (uncondit= ionally) - re-wrote description for the build_assertions() function - excluded PowerPC architecture (not in scope of certification) from the ch= eck and wrote apropriate explanation Link to v3: https://patchew.org/Xen/0e72c83102668dfa6f14c4e8f9839b4a73d30b3d.1760458094= .git.dmytro._5Fprokopchuk1@epam.com/ --- .../eclair_analysis/ECLAIR/deviations.ecl | 8 ++++++ docs/misra/deviations.rst | 8 +++++- docs/misra/rules.rst | 7 +++++- xen/common/version.c | 25 +++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl b/automation/= eclair_analysis/ECLAIR/deviations.ecl index 7f3fd35a33..219ba6993b 100644 --- a/automation/eclair_analysis/ECLAIR/deviations.ecl +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl @@ -375,6 +375,14 @@ constant expressions are required.\"" } -doc_end =20 +-doc_begin=3D"Conversion from unsigned long or (void *) to a function poin= ter can restore full information, provided that the source type has enough = bits to restore it." +-config=3DMC3A2.R11.1,casts+=3D{safe, + "from(type(canonical(builtin(unsigned long)||pointer(builtin(void))))) + &&to(type(canonical(__function_pointer_types))) + &&relation(definitely_preserves_value)" +} +-doc_end + -doc_begin=3D"The conversion from a function pointer to a boolean has a we= ll-known semantics that do not lead to unexpected behaviour." -config=3DMC3A2.R11.1,casts+=3D{safe, "from(type(canonical(__function_pointer_types))) diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst index 3271317206..b3431ef24e 100644 --- a/docs/misra/deviations.rst +++ b/docs/misra/deviations.rst @@ -366,11 +366,17 @@ Deviations related to MISRA C:2012 Rules: - Tagged as `safe` for ECLAIR. =20 * - R11.1 - - The conversion from a function pointer to unsigned long or (void \*= ) does + - The conversion from a function pointer to unsigned long or '(void *= )' does not lose any information, provided that the target type has enough = bits to store it. - Tagged as `safe` for ECLAIR. =20 + * - R11.1 + - Conversion from unsigned long or '(void *)' to a function pointer c= an + restore full information, provided that the source type has enough = bits + to restore it. + - Tagged as `safe` for ECLAIR. + * - R11.1 - The conversion from a function pointer to a boolean has a well-known semantics that do not lead to unexpected behaviour. diff --git a/docs/misra/rules.rst b/docs/misra/rules.rst index 4388010ec9..4e94251887 100644 --- a/docs/misra/rules.rst +++ b/docs/misra/rules.rst @@ -431,7 +431,12 @@ maintainers if you want to suggest a change. - All conversions to integer types are permitted if the destination type has enough bits to hold the entire value. Conversions to bool and void* are permitted. Conversions from 'void noreturn (*)(...)' - to 'void (*)(...)' are permitted. + to 'void (*)(...)' are permitted. Conversions from unsigned long or + '(void *)' to a function pointer are permitted. + Example:: + + unsigned long func_addr =3D (unsigned long)&some_function; + void (*restored_func)(void) =3D (void (*)(void))func_addr; =20 * - `Rule 11.2 `_ - Required diff --git a/xen/common/version.c b/xen/common/version.c index 553b97ba9b..674bd72b31 100644 --- a/xen/common/version.c +++ b/xen/common/version.c @@ -217,6 +217,31 @@ void __init xen_build_init(void) #endif /* CONFIG_X86 */ } #endif /* BUILD_ID */ + +/* + * This assertion checks compatibility between 'unsigned long', 'void *', + * and function pointers. This is true for most supported architectures, + * including X86 (x86_64) and ARM (arm, aarch64). + * + * For more context on architecture-specific preprocessor guards, see + * docs/misc/C-language-toolchain.rst. + * + * If porting Xen to a new architecture where this compatibility does not = hold, + * exclude that architecture from these checks and provide suitable commen= tary + * and/or alternative checks as appropriate. + */ +static void __init __maybe_unused build_assertions(void) +{ + /* + * Exclude architectures where function pointers are larger than data = pointers: + * - PowerPC: uses function descriptors (code address + TOC pointer). + */ +#if !defined(__powerpc__) + BUILD_BUG_ON(sizeof(unsigned long) !=3D sizeof(void (*)(void))); + BUILD_BUG_ON(sizeof(void *) !=3D sizeof(void (*)(void))); +#endif +} + /* * Local variables: * mode: C --=20 2.43.0