From: Nicola Vetrini <nicola.vetrini@bugseng.com>
To: Dmytro Prokopchuk1 <dmytro_prokopchuk1@epam.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Jan Beulich <jbeulich@suse.com>,
Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>,
Bertrand Marquis <bertrand.marquis@arm.com>,
Michal Orzel <michal.orzel@amd.com>,
Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>,
Dario Faggioli <dfaggioli@suse.com>,
Juergen Gross <jgross@suse.com>,
George Dunlap <gwd@xenproject.org>,
xen-devel@lists.xenproject.org
Subject: Re: [PATCH] misra: fix violations in macros GVA_INFO, TRACE_TIME
Date: Tue, 05 Aug 2025 15:22:23 +0200 [thread overview]
Message-ID: <1a59e6d831fd7119df1e2bd0cdbe262b@bugseng.com> (raw)
In-Reply-To: <91d2a8ec-8a8e-404a-85ac-1038317e937b@epam.com>
On 2025-08-05 13:49, Dmytro Prokopchuk1 wrote:
> On 7/31/25 19:09, Nicola Vetrini wrote:
>> On 2025-07-31 18:05, Andrew Cooper wrote:
>>> On 31/07/2025 4:58 pm, Jan Beulich wrote:
>>>> On 31.07.2025 17:37, Andrew Cooper wrote:
>>>>> On 31/07/2025 4:16 pm, Dmytro Prokopchuk1 wrote:
>>>>>> MISRA Rule 13.1: Initializer lists shall not contain persistent
>>>>>> side
>>>>>> effects.
>>>>>>
>>>>>> The violations occur because both the `GVA_INFO` and `TRACE_TIME`
>>>>>> macro
>>>>>> expansions include expressions with persistent side effects
>>>>>> introduced
>>>>>> via inline assembly.
>>>>>>
>>>>>> In the case of `GVA_INFO`, the issue stems from the initializer
>>>>>> list
>>>>>> containing a direct call to `current`, which evaluates to
>>>>>> `this_cpu(curr_vcpu)` and involves persistent side effects via the
>>>>>> `asm` statement. To resolve this, the side-effect-producing
>>>>>> expression
>>>>>> is computed in a separate statement prior to the macro
>>>>>> initialization:
>>>>>>
>>>>>> struct vcpu *current_vcpu = current;
>>>>>>
>>>>>> The computed value is passed into the `GVA_INFO(current_vcpu)`
>>>>>> macro,
>>>>>> ensuring that the initializer is clean and free of such side
>>>>>> effects.
>>>>>>
>>>>>> Similarly, the `TRACE_TIME` macro violates this rule when
>>>>>> accessing
>>>>>> expressions like `current->vcpu_id` and
>>>>>> `current->domain->domain_id`,
>>>>>> which also depend on `current` and inline assembly. To fix this,
>>>>>> the
>>>>>> value of `current` is assigned to a temporary variable:
>>>>>>
>>>>>> struct vcpu *v = current;
>>>>>>
>>>>>> This temporary variable is then used to access `domain_id` and
>>>>>> `vcpu_id`.
>>>>>> This ensures that the arguments passed to the `TRACE_TIME` macro
>>>>>> are
>>>>>> simple expressions free of persistent side effects.
>>>>>>
>>>>>> Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
>>>>> The macro `current` specifically does not (and must not) have side
>>>>> effects. It is expected to behave like a plain `struct vcpu
>>>>> *current;`
>>>>> variable, and what Eclair is noticing is the thread-local machinery
>>>>> under this_cpu() (or in x86's case, get_current()).
>>>>>
>>>>> In ARM's case, it's literally reading the hardware thread pointer
>>>>> register. Can anything be done to tell Eclair that `this_cpu()`
>>>>> specifically does not have side effects?
>>>>>
>>>>> The only reason that GVA_INFO() and TRACE_TIME() are picked out is
>>>>> because they both contain embedded structure initialisation, and
>>>>> this is
>>>>> is actually an example where trying to comply with MISRA interferes
>>>>> with
>>>>> what is otherwise a standard pattern in Xen.
>>>> Irrespective of what you say, some of the changes here were
>>>> eliminating
>>>> multiple adjacent uses of current, which - iirc - often the compiler
>>>> can't fold via CSE.
>>>
>>> Where we have mixed usage, sure. (I'm sure I've got a branch
>>> somewhere
>>> trying to add some more pure/const around to try and help out here,
>>> but
>>> I can't find it, and don't recall it being a major improvement
>>> either.)
>>>
>>> The real problem here is that there are a *very few* number of
>>> contexts
>>> where Eclair refuses to tolerate the use of `current` citing side
>>> effects, despite there being no side effects.
>>>
>>> That is the thing that breaks the principle of least surprise, and we
>>> ought to fix it by making Eclair happy with `current` everywhere,
>>> rather
>>> than force people to learn that 2 macros can't have a `current` in
>>> their
>>> parameter list.
>>>
>>
>> I'll take a look. Likely yes, by adding a handful of properties. There
>> are subtleties, though.
>>
>
> Hi, Nicola.
>
> Did you have a chance to try configure Eclair to ignore this macro
> `this_cpu()`?
>
Hi Dmytro,
I'm on it, I needed to handle other tasks first.
> Thanks.
> Dmytro
--
Nicola Vetrini, B.Sc.
Software Engineer
BUGSENG (https://bugseng.com)
LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
next prev parent reply other threads:[~2025-08-05 13:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-31 15:16 [PATCH] misra: fix violations in macros GVA_INFO, TRACE_TIME Dmytro Prokopchuk1
2025-07-31 15:32 ` Jan Beulich
2025-08-01 5:26 ` Jürgen Groß
2025-07-31 15:37 ` Andrew Cooper
2025-07-31 15:58 ` Jan Beulich
2025-07-31 16:05 ` Andrew Cooper
2025-07-31 16:09 ` Nicola Vetrini
2025-08-05 11:49 ` Dmytro Prokopchuk1
2025-08-05 13:22 ` Nicola Vetrini [this message]
2025-08-06 9:27 ` Nicola Vetrini
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=1a59e6d831fd7119df1e2bd0cdbe262b@bugseng.com \
--to=nicola.vetrini@bugseng.com \
--cc=Volodymyr_Babchuk@epam.com \
--cc=andrew.cooper3@citrix.com \
--cc=bertrand.marquis@arm.com \
--cc=dfaggioli@suse.com \
--cc=dmytro_prokopchuk1@epam.com \
--cc=gwd@xenproject.org \
--cc=jbeulich@suse.com \
--cc=jgross@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--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.