[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2] misra: deviate MISRA C Rule 18.3 for is_kernel*() macros


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>
  • Date: Fri, 4 Dec 2026 08:44:03 +0000
  • Accept-language: en-US, uk-UA, ru-RU
  • 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
  • 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=rx8UXZArrU8pxaSi56+rX2ZIpM+tVJbE2gnTap1beeI=; b=C6cSQZyIMHd9mqkWfJZp0bv30v3Ck1yRo+M5N+4CQ3HUOPFx8d531rdseu3hGMeuVcwKwNBzIsaced8+At8Kh7skwEdhU6zWvuZjOLfpvotH+Xor9AYuOQ1xBPWjlY2Mdo3yRvnz1uBWUXRZB10/EZZ1BDI/4aghWCk44ehYOXCWS3SA1xw6Sn1qWxqmWtArYRHK0RMdQre5fvjb1d+ml1nDXZZ29n+ioPFemcVrHQMSZj89bA1GiDJQatNn+4RUrljHqfBQV193uicJxKJhKM949tLqCiowHepFmogW+ZO6RQ4lvBsCe8owaJt/M8OtcRr8+35wjDKjogTzyK3hMA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RxCmG+apATTBjZxY5juKKWzH6GZCPvCR8Csj1ly5QDSWy1XITLt52RMpiBFDzMzdtaPT5zoJcnXd8h0IqGshgJXPqubevmHjX9nJ9IWddy1rS1H5s88M3NYioJn6lYzuEVHbulq4sBsRZfBh7Zj/i9dJv6188O2XkTe4iHlQLSQ2u9rJCgYcPoYlf9d9x1sHWOntHvYtWL+lIQ5oH+06g/6+d1jXjv/jVRN14ZeelAAJ138s1tKKjftU8NVyRYtesxp/VvlGM5kGh+RNuI3dC5ouMcmjjV6V5vhEpda5oICd7JUxnczBl/NwdTOF0oflaIZc2m9ClwRXxnDFl47pAQ==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:x-ms-exchange-senderadcheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>, Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>, Doug Goldstein <cardoe@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>
  • Delivery-date: Fri, 04 Dec 2026 08:44:17 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHdg8udmMcSDSVaK0O75PtHYVXs/g==
  • Thread-topic: [PATCH v2] misra: deviate MISRA C Rule 18.3 for is_kernel*() macros

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.

Deviate the rule for comparisons encapsulated by these macros.

Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
---
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
-- 
2.43.0

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.