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

Re: [XEN PATCH v2 1/3] EFI: address a violation of MISRA C Rule 13.6


  • To: Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 2 Oct 2024 08:09:15 +0200
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Roberto Bagnara <roberto.bagnara@xxxxxxxxxxx>, Federico Serafini <federico.serafini@xxxxxxxxxxx>, consulting@xxxxxxxxxxx, "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>, Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Wed, 02 Oct 2024 06:09:25 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 01.10.2024 23:36, Stefano Stabellini wrote:
> On Tue, 1 Oct 2024, Jan Beulich wrote:
>> On 01.10.2024 07:25, Roberto Bagnara wrote:
>>> On 2024-09-30 15:07, Jan Beulich wrote:
>>>> On 30.09.2024 14:49, Federico Serafini wrote:
>>>>> guest_handle_ok()'s expansion contains a sizeof() involving its
>>>>> first argument which is guest_handle_cast().
>>>>> The expansion of the latter, in turn, contains a variable
>>>>> initialization.
>>>>>
>>>>> Since MISRA considers the initialization (even of a local variable)
>>>>> a side effect, the chain of expansions mentioned above violates
>>>>> MISRA C:2012 Rule 13.6 (The operand of the `sizeof' operator shall not
>>>>> contain any expression which has potential side effect).
>>>>
>>>> I'm afraid I need to ask for clarification of terminology and alike here.
>>>> While the Misra doc has a section on Persistent Side Effects in its
>>>> Glossary appendix, what constitutes a side effect from its pov isn't
>>>> really spelled out anywhere. Which in turn raises the question whether it
>>>> is indeed Misra (and not just Eclair) which deems initialization a side
>>>> effect. This is even more so relevant as 13.6 talks of only expressions,
>>>> yet initializers fall under declarations (in turn involving an expression
>>>> on the rhs of the equal sign).
>>>>
>>>> All the same of course affects patch 2 then, too.
>>>
>>> MISRA C leaves the definition of "side effect" to the C Standard.
>>> E.g., C18 5.1.2.3p2:
>>>
>>>    Accessing a volatile object, modifying an object, modifying a file,
>>>    or calling a function that does any of those operations are all
>>>    side effects,[omitted irrelevant footnote reference] which are
>>>    changes in the state of the execution environment.
>>>
>>> The MISRA C:2012/2023 Glossary entry for "Persistent side effect"
>>> indirectly confirms that initialization is always a side effect.
>>
>> Hmm, that's interesting: There's indeed an example with an initializer
>> there. Yet to me the text you quote from the C standard does not say
>> that initialization is a side effect - it would be "modifying an
>> object" aiui, yet ahead of initialization being complete the object
>> doesn't "exist" imo, and hence can be "modified" only afterwards.
> 
> I feel it's becoming a bit too philosophical. Since there's some room
> for interpretation and only two violations left to address, I believe
> it's best to stick with the stricter interpretation of the definition.
> Therefore, I'd proceed with this series in its current form.

Proceeding with the series in its current form may be okay (as you say,
you view the changes as readability improvements anyway), but imo the
interpretation needs settling on no matter what. In fact even for these
two patches it may affect what their descriptions ought to say (would
be nice imo to avoid permanently recording potentially misleading
information by committing as is). And of course clarity would help
dealing with future instances that might appear. I take it you realize
that if someone had submitted a patch adding code similar to the
original forms of what's being altered here, it would be relatively
unlikely for a reviewer to spot the issue. IOW here we're making
ourselves heavily dependent upon Eclair spotting (supposed) issues,
adding extra work and delays for such changes to go in.

Jan



 


Rackspace

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