All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicola Vetrini <nicola.vetrini@bugseng.com>
To: Dmytro Prokopchuk1 <dmytro_prokopchuk1@epam.com>
Cc: xen-devel@lists.xenproject.org, sstabellini@kernel.org,
	consulting@bugseng.com, andrew.cooper3@citrix.com,
	jbeulich@suse.com, Doug Goldstein <cardoe@cardoe.com>
Subject: Re: [XEN PATCH 2/2] Address violation of MISRA C Rule 13.1 involving asm side effects.
Date: Wed, 13 Aug 2025 09:46:15 +0200	[thread overview]
Message-ID: <c03ea3bcf950d6fb0d04d0f67790d03f@bugseng.com> (raw)
In-Reply-To: <175d7b47-32bb-4b5d-a16b-7402bd823b15@epam.com>

On 2025-08-13 09:41, Dmytro Prokopchuk1 wrote:
> On 8/9/25 00:40, Nicola Vetrini wrote:
>> The rule states: "Initializer lists shall not contain persistent side 
>> effects".
>> The specific way in which the 'mrs' instruction is used does not lead 
>> to
>> visible side effects for the surrounding code.
>> 
>> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
>> ---
>> Not yet tested on the Xen ECLAIR runner, as the syntax used in the 
>> deviation
>> is only supported after updating the runner.
>> 
>> What the tool is reporting is that due to the '=r' constraint and the
>> semantics of the instruction, there is the side effect of writing to 
>> '_r',
>> but this is not observable outside the stmt expr. The deviation ends 
>> up being
>> a bit too general for my taste, but the restriction on the actual 
>> istruction
>> should be enough to limit applicability to cases that are arguably 
>> safe in
>> practice.
>> 
>> An alternative approach would be represented by stating that side 
>> effects in
>> 'READ_SYSREG64' are safe, but this is not true in general.
>> ---
>>   automation/eclair_analysis/ECLAIR/deviations.ecl | 4 ++++
>>   1 file changed, 4 insertions(+)
>> 
>> diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl 
>> b/automation/eclair_analysis/ECLAIR/deviations.ecl
>> index ec0cac797e5f..6b492e38505d 100644
>> --- a/automation/eclair_analysis/ECLAIR/deviations.ecl
>> +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
>> @@ -437,6 +437,10 @@ write or not"
>>   # Series 13
>>   #
>> 
>> +-doc_begin="Consider the asm instruction to read an Arm system 
>> register to have no side effects."
>> +-asm_properties+={"asm(any())&&child(text, 
>> ast_field(value,^mrs\\s+%0.*$))", {no_side_effect}}
>> +-doc_end
>> +
>>   -doc_begin="All developers and reviewers can be safely assumed to be 
>> well aware
>>   of the short-circuit evaluation strategy of such logical operators."
>>   -config=MC3A2.R13.5,reports+={disapplied,"any()"}
> 
> I think it's worth to add example of macro expansion in the commit
> description or asm_properties doc:
> 
> uint64_t _r; asm volatile("mrs  %0, ""TPIDR_EL2" : "=r" (_r));
> 
> This uses the 'mrs' instruction to read from the TPIDR_EL2 register.
> While this read operation accesses a system register, reading itself
> doesn't cause any persistent side effects, as no program state is 
> modified.
> 

Definitely not in the -doc_begin, perhaps in deviations.rst, though in 
reality it is a single case this currently applies to. Reading the 
register is not the reason why this deviation was requested, but the 
write with the "=r" constraint on "_r", as that is the side effect the 
tool is pointing at.

-- 
Nicola Vetrini, B.Sc.
Software Engineer
BUGSENG (https://bugseng.com)
LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253


  reply	other threads:[~2025-08-13  7:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-08 21:40 [XEN PATCH 1/2] automation/eclair: ECLAIR configuration changes due to GitLab runner update Nicola Vetrini
2025-08-08 21:40 ` [XEN PATCH 2/2] Address violation of MISRA C Rule 13.1 involving asm side effects Nicola Vetrini
2025-08-13  7:41   ` Dmytro Prokopchuk1
2025-08-13  7:46     ` Nicola Vetrini [this message]
2025-08-14  7:36   ` Jan Beulich
2025-08-14 17:49     ` Nicola Vetrini
2025-08-15 19:51   ` Stefano Stabellini
2025-08-08 21:43 ` [XEN PATCH 1/2] automation/eclair: ECLAIR configuration changes due to GitLab runner update Andrew Cooper
2025-08-08 21:48 ` 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=c03ea3bcf950d6fb0d04d0f67790d03f@bugseng.com \
    --to=nicola.vetrini@bugseng.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=cardoe@cardoe.com \
    --cc=consulting@bugseng.com \
    --cc=dmytro_prokopchuk1@epam.com \
    --cc=jbeulich@suse.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.