From: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: xen-devel@lists.xenproject.org,
"Doug Goldstein" <cardoe@cardoe.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Anthony PERARD" <anthony.perard@vates.tech>,
"Michal Orzel" <michal.orzel@amd.com>,
"Julien Grall" <julien@xen.org>,
"Roger Pau Monné" <roger@xenproject.org>,
"Nicola Vetrini" <nicola.vetrini@bugseng.com>
Subject: Re: [PATCH v2] misra: deviate MISRA C Rule 18.3 for is_kernel*() macros
Date: Fri, 4 Dec 2026 13:40:46 +0200 [thread overview]
Message-ID: <6900ce41-e34c-4d26-a25d-2a014705591c@epam.com> (raw)
In-Reply-To: <e99dc029-f116-434c-acf1-17acc5fe69b5@suse.com>
On 12/4/26 13:17, Jan Beulich wrote:
> On 04.12.2026 12:15, Dmytro Prokopchuk wrote:
>>
>>
>> On 12/4/26 11:24, Nicola Vetrini wrote:
>>> 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.
>>
>> Looks like Xen has this deviation established already:
>>
>> -doc_begin="Conversions from and to integral types are safe, in the
>> assumption that the target type has enough bits to store the value.
>> See also Section \"4.7 Arrays and Pointers\" of \"GCC_MANUAL\""
>> -config=MC3A2.R11.6,casts+={safe, ...
>>
>>>
>>> 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.
>>
>> And we can update macros without new violations.
>> And all four macros should be updated: is_kernel, is_kernel_text,
>> is_kernel_rodata, is_kernel_inittext, to be aligned.
>>
>> Well, let's wait someone else review.
>
> I certainly agree with Nicola: Why add a deviation when we can easily get
> away without.
I agree. ( actually BUGSENG youtube videos say the same :) )
So, I will prepare V3.
>
> Jan
prev parent reply other threads:[~2026-12-04 11:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 8:44 [PATCH v2] misra: deviate MISRA C Rule 18.3 for is_kernel*() macros Dmytro Prokopchuk1
2026-12-04 9:24 ` Nicola Vetrini
2026-12-04 11:15 ` Dmytro Prokopchuk
2026-12-04 11:17 ` Jan Beulich
2026-12-04 11:40 ` Dmytro Prokopchuk [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6900ce41-e34c-4d26-a25d-2a014705591c@epam.com \
--to=dmytro_prokopchuk1@epam.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=cardoe@cardoe.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=nicola.vetrini@bugseng.com \
--cc=roger@xenproject.org \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.