From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 103EE606A322 for ; Fri, 4 Dec 2026 09:25:05 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1513951.1705333 (Exim 4.92) (envelope-from ) id 1xZPX7-0003Y4-VZ; Fri, 04 Dec 2026 09:24:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1513951.1705333; Fri, 04 Dec 2026 09:24:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xZPX7-0003Xv-Sl; Fri, 04 Dec 2026 09:24:49 +0000 Received: by outflank-mailman (input) for mailman id 1513951; Fri, 04 Dec 2026 09:24:48 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xZPX6-0003Xk-JJ for xen-devel@lists.xenproject.org; Fri, 04 Dec 2026 09:24:48 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xZPX5-007EW2-W9 for xen-devel@lists.xenproject.org; Fri, 04 Dec 2026 10:24:48 +0100 Received: from [10.42.69.2] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6b1286d9-e002-0a2a0a5209dd-0a2a4502a350-22 for ; Fri, 04 Dec 2026 10:24:47 +0100 Received: from [162.55.131.47] (helo=support.bugseng.com) by tlsNG-720697.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6b1286df-4900-0a2a45020019-a237832f8b7c-3 for ; Fri, 04 Dec 2026 10:24:47 +0100 Received: from support.bugseng.com (support.bugseng.com [162.55.131.47]) (Authenticated sender: nicola) by support.bugseng.com (Postfix) with ESMTPA id 8C9A24EE0296; Fri, 4 Dec 2026 10:24:47 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Post: List-Help: List-Subscribe: , Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; none Authentication-Results: bugseng.com; arc=none smtp.remote-ip=162.55.131.47 ARC-Seal: i=1; d=bugseng.com; s=openarc; a=rsa-sha256; cv=none; t=1796376287; b=rUKCujGW5d0BROql4ljht3wFXlIOFbEdrtQOVYuKCFrO7kdKzAdIODtyq0qPspNM00Hu 6/dsJmK5/vK5YpniVT37WhybkiTsQJplkhiiSrYh+Ees1slI927rqGS8bhBivgCHTL76F ruQ0h9hMFS4cmo7dMyMFvNtEwaQ3N/57FMVvxRYY/HHjsEqja0QowhLXJvOT5ak6skMWz v+zRRg/54Lb1vQC6IKrXxS+h8HumeWmn2bbKFxmKaeol5QLzJqEb4OaoWmGIMIDjS1FK0 LQ4clBkbbkCQynRwX/HkN1RWnyTmKehjnJW7o6PS9wYx0qnsk5vp40dF5b0vbvEwSXKF4 l88BIqc1FtiZ+gE2mJcgM4ciBxnBYXiqGnhJZf8ZdBq0hZCk1/ZgZdZ27lAk3c7GxmhGz UyNYrYKdzLELZAfvXNwcQspMJu27oibjk6TW52d+3YxySxBMJIcGJBJZGYbUksN+lBttg STYdQczd2/dFk7a6E5g2GeAUyna/mRsQ+Xpkmu9qBj2a7y25TzK2wRnawIVJ8RLO7B530 2fbjje2dfxjuuGbSpXmz3UsDICVQUHx01bYaV+0hr4l+h98cdy+O0FNp/Ohs8tDwMSTfJ mDOTa3LpXwcY6wex08mIWWH6gGdL9aNGkdgvswycctTA98NCxGSBYcTIUg2ElLo= ARC-Message-Signature: i=1; d=bugseng.com; s=openarc; a=rsa-sha256; c=relaxed/relaxed; t=1796376287; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:X-Sender:Organization:Content-Type: Content-Transfer-Encoding; bh=8Mf83oeH5YAUHJpyNS7m+F6N3Oh29eczM9a+Y10Id7k=; b=tn7XrlXvmTRblZokZRVi/gXBcy1OmolLX+uMosq9cWShAY6ps28sBOsM2SZPtR1O90OL BRdt2rFQXwy+LnbF3RMA7VbyShJD+d0p29Q5hJmVDMFqvbauHpiml9KfDCam+owkrI90Z iS09L6JAhPZ6WizpF4mdVTnAz7aFGjixfhnULH6d8S3/qoYYna/DEMlBq/yoLhf1K5FpM zszLZ5aLGcSZBZs2/2YQVmfVONuS/ueNHdPd3lMxXP5GRU28n2XyVYeuD6mG+bJIDzgN7 dYvIowYoy8KQtqil/wbxBRz8E0/hPrZJbnHmlLyAg7T47pXlvw4SgJC3/8pu/PxFJhqAL OaFy2NuPB6OSqzm73LjqBNfY/YB89kQz11KoIYO4VXcioPyG2202sLNeOcNk692PT+bNC rxzIoSgWM6fu6gXy+h8gBjMubHAp0MQDvIC0PK6FBHGZNJNv4c/OPKIKUjR/GiGjmavmW p4/sQ92gG+nmnSGA3n8oGZWhprLXgOcHfR5eTt0Agjx/DQkrSJjd3D2Dx9S0repGLInZm O0E+kyMnLELoggF4jAsnZmyAqT3uoOrWHXeJ8tuMx4xDJGYWZRI3wx9qOUzmwIyg9UrbR /sZ7OnXZQUXElEsEFCZS1njF1E4fSgSh4cwSsUf3eTS4j4h8iNdy5C+TsylPcUo= ARC-Authentication-Results: i=1; bugseng.com; arc=none smtp.remote-ip=162.55.131.47 X-Archived-By: MIME-Version: 1.0 Date: Fri, 04 Dec 2026 10:24:47 +0100 From: Nicola Vetrini To: Dmytro Prokopchuk1 Cc: xen-devel@lists.xenproject.org, Doug Goldstein , Stefano Stabellini , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= Subject: Re: [PATCH v2] misra: deviate MISRA C Rule 18.3 for is_kernel*() macros In-Reply-To: <9a5e6e8a05ff6f0d5975ca71f25e6311cd092044.1796372428.git.dmytro_prokopchuk1@epam.com> References: <9a5e6e8a05ff6f0d5975ca71f25e6311cd092044.1796372428.git.dmytro_prokopchuk1@epam.com> Message-ID: <742eb6fe2f24abc084b97e163ffcc66e@bugseng.com> X-Sender: nicola.vetrini@bugseng.com Organization: BUGSENG s.r.l. Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-purgate-ID: tlsNG-720697/1796376287-3359C6C6-AEB2A68C/0/0 X-purgate-type: clean X-purgate-size: 4243 X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_PASS,SPF_PASS, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On 2026-12-04 09:44, Dmytro Prokopchuk1 wrote: > MISRA C Rule 18.3 states: "The relational operators >, >=, < and <= > shall > not be applied to objects of pointer type except where they point into > the same object". > > The is_kernel(), is_kernel_text(), is_kernel_rodata() and > is_kernel_inittext() macros check whether an arbitrary address lies > within a section of the Xen image by comparing it against > linker-defined > section boundaries. A pointer outside the section is a legitimate input > for them and simply yields false, hence such comparisons are safe. > Why would this matter? The standard only guarantees defined behavior if you compare pointers inside the same array, no matter that the compiler doesn't take advantage of it (probably due to the cast on p). To me, it looks like a more reasonable approach would be to do the comparison in unsigned long and then rely on the assumption that no information is lost in the char* -> unsigned long conversion. e.g. extern char _stext[], _etext[]; #define is_kernel_text(p) ({ \ unsigned long __p = (unsigned long)(p); \ (__p >= (unsigned long)_stext) && (__p < (unsigned long)_etext); \ }) in this way you avoid the violation at the root. > Deviate the rule for comparisons encapsulated by these macros. > > Signed-off-by: Dmytro Prokopchuk > --- > Changes in v2: > - restrict the deviation to the is_kernel*() macros instead of covering > comparisons against all linker symbols > - update the commit subject, message and deviations.rst accordingly > > With v2 applied the remaining R18.3 violations (ARM64 and x86_64) are > all > unrelated to linker symbols. > > Test CI pipeline: > https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/3152444935 > --- > automation/eclair_analysis/ECLAIR/deviations.ecl | 5 +++++ > docs/misra/deviations.rst | 7 +++++++ > 2 files changed, 12 insertions(+) > > diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl > b/automation/eclair_analysis/ECLAIR/deviations.ecl > index cdcdb4622c..b7a7fb2a52 100644 > --- a/automation/eclair_analysis/ECLAIR/deviations.ecl > +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl > @@ -630,6 +630,11 @@ C99 Undefined Behaviour 45: Pointers that do not > point into, or just beyond, the > -config=MC3A2.R18.2,reports+={safe, > "any_area(any_loc(any_exp(macro(^page_to_mfn$))))"} > -doc_end > > +-doc_begin="The following macros check whether an arbitrary address > lies within a section of the Xen image by comparing it > +against linker-defined section boundaries. A pointer outside the > section is a legitimate input and simply yields false." > +-config=MC3A2.R18.3,reports+={safe, > "any_area(any_loc(any_exp(macro(^is_kernel(_text|_rodata|_inittext)?$))))"} > +-doc_end > + > -doc_begin="Flexible array members are deliberately used and XEN > developers are aware of the dangers related to them: > unexpected result when the structure is given as argument to a > sizeof() operator and the truncation in assignment between structures." > -config=MC3A2.R18.7,reports+={deliberate, "any()"} > diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst > index eb5817f88b..df77f8c3cd 100644 > --- a/docs/misra/deviations.rst > +++ b/docs/misra/deviations.rst > @@ -644,6 +644,13 @@ Deviations related to MISRA C:2012 Rules: > are safe. > - Tagged as `safe` for ECLAIR. > > + * - R18.3 > + - Relational comparisons between pointers encapsulated by macros > + is_kernel(), is_kernel_text(), is_kernel_rodata(), > is_kernel_inittext() > + are safe, as they check whether an arbitrary address lies > within a > + section of the Xen image. > + - Tagged as `safe` for ECLAIR. > + > * - R20.4 > - The override of the keyword \"inline\" in xen/compiler.h is > present so > that section contents checks pass when the compiler chooses not > to -- Nicola Vetrini, B.Sc. Software Engineer BUGSENG (https://bugseng.com) LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253