[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: Roberto Bagnara <roberto.bagnara@xxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
- From: Jan Beulich <jbeulich@xxxxxxxx>
- Date: Tue, 8 Oct 2024 07:59:08 +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: 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: Tue, 08 Oct 2024 05:59:16 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 02.10.2024 08:54, Roberto Bagnara wrote:
> On 2024-10-02 08:09, Jan Beulich wrote:
>> 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.
>
> You can do two things to obtain a second opinion:
>
> 1) Use the MISRA forum (here is the link to the forum
> section devoted to the side-effect rules of MISRA C:2012
> and MISRA C:2023 (https://forum.misra.org.uk/forumdisplay.php?fid=168).
> The MISRA C Working Group will, in due course, provide
> you with an official answer to your questions about what,
> for the interpretation of Rule 13.6, has to be considered
> a side effect.
>
> 2) Reach out to your ISO National Body and try to obtain
> an official answer from ISO/IEC JTC1/SC22/WG14 (the
> international standardization working group for the
> programming language C) to your questions about what the
> C Standard considers to be side effects.
I took the latter route, and to my (positive) surprise I got back an answer
the same day. There was a request for someone to confirm, but so far I didn't
see further replies. Since this is a German institution I raised the question
in German and got back an answer in German (attached); I've tried my best to
translate this without falsifying anything, but I've omitted non-technical
parts:
"Initialization of an object is never a side effect of the initialization
by itself. Of course expressions used for initialization can themselves have
side effects on other objects.
@Andreas: Do you agree? C after all has a far simpler object model than C++.
The (potential) change in object representation (i.e. the bytes underlying
the object) is not a side effect of object initialization, but its primary
purpose."
Further for Misra she added a reference to a Swiss person, but I think with
Bugseng we have sufficient expertise there.
Jan --- Begin Message ---
- To: Wellhöfer, Johannes <Johannes.Wellhoefer@xxxxxx>, "jbeulich@xxxxxxxx" <jbeulich@xxxxxxxx>
- From: Daniela Engert <dani@xxxxxxx>
- Date: Wed, 2 Oct 2024 15:31:12 +0200 (CEST)
- Arc-authentication-results: i=2; mx.google.com; dkim=pass header.i=@ngrt.de header.s=strato-dkim-0002 header.b=Av+BfH85; dkim=neutral (no key) header.i=@ngrt.de header.s=strato-dkim-0003; arc=pass (i=1); spf=pass (google.com: domain of dani@xxxxxxx designates 85.215.255.24 as permitted sender) smtp.mailfrom=dani@xxxxxxx
- Arc-authentication-results: i=1; strato.com; arc=none; dkim=none
- Arc-message-signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=importance:content-transfer-encoding:mime-version:subject :references:in-reply-to:message-id:cc:to:from:date:dkim-signature :dkim-signature; bh=gqLzixRFcExxmwgQxITcEHF+zRUaT8QWyXD37Sf7WF4=; fh=wjE6VCDYDgSWmMpPztkPEeR7njgHslLn8MmGM3lclnI=; b=NfDr9hJCAEEloGqHJW5XvsxJuXCTuNe1wvcmSUlm19mdO+L1wlAYUVWvVsYeki56DW i60MNPV3tEY5lksIWxJqHMhzdF78NNtm97DWr8bTkzzqJbtaVEpfqfGlhUpcqe2/eOBf p1qRpSlD+kec+zyy8Y2w/9hCy27TkJWQTLc3mnVH1XDdr3V9v8alQ59/3mIMNlGLjb6b ybuRFPCm9HSSfwq2R3u6Qvls4XsIMpb4F+ftIPM5cBn1Z26HxqM5fSUpwXKSP7It6g5r xFpemWpu3cro+1osIt3d1FLhtTYfuGmdNB45TvCLvnCvfvb1a6jN7C7f5vH2OLxXN56m /rSw==; dara=google.com
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1727875873; s=strato-dkim-0002; d=strato.com; h=Subject:References:In-Reply-To:Message-ID:Cc:To:From:Date:Cc:Date: From:Subject:Sender; bh=gqLzixRFcExxmwgQxITcEHF+zRUaT8QWyXD37Sf7WF4=; b=Q6XWALr3hfdXMnqQIn14d+NatToraGG7HjA+ToS4UJnpVVhWJsG8qBlpaLvfKi2Lup Qlm4yTf4DNp67XkjDA9cYEwYtQbudIer1MShNaMXtc6z9bxsGXL/Oh6kCGqpsDZMJMcE dQ9+bxry2PVfYO6BIuenMt3aZI0pXIySzB3QpSkfDKbaSnSPDmlSmrNsiImU9h/hRzhk LyCx2iyrQWADTgx0EW+XrTitYSIfoCB0XZUI4Dhe9ne9J0h80OCH+4XiFYx6xNzLKaUS dkBc8oYdBFigoDwv9POQmOF2w7FuUqMtKd70EgaFKNTtnxyrKJlxFxlpO0QJo7CS4VcM rU6w==
- Arc-seal: i=2; a=rsa-sha256; t=1727875873; cv=pass; d=google.com; s=arc-20240605; b=Ccsmv0tSonPNOmraBzwBXS3zs8xzOLjV8jSifYGhBVO2J0O/1+ul+u+ly3WtnqRR70 GRKB7a+0GGpnFST969+Syw6GOwi4Rqq61CYguA8Kaisc5kZxaVWAmnfXTNnFDmnZt5lo dnle60GSE3eLKBsmo9Gufw9fD4EVvc1HlXqdLNggfjxitEDYEFcqfvOkClAMKsQLGR3N KTY1uuZkOD2O+6P+qHI5m54C+1aUeHkUzMPHRd9H+SR3r6WMCG8F84RhR+Vw+u9p+xR+ EYRLbZr2ffVhkM/Ewok4mbW+QibOrtfXoURvdLlgoP3mVqUBTU8jTfWyQGHa8YVX3jIw yVmg==
- Arc-seal: i=1; a=rsa-sha256; t=1727875873; cv=none; d=strato.com; s=strato-dkim-0002; b=Abrj5yW+HdijCFE1QHmPhJ02h0qBgoyX/e5PcMv+3s2FoJkI4t+NPpVKqr0POW4ECa Xgk5eujrEcBsdWp/T2bIFfAD1R6xKeE3h4qwR/uHOc8ISLSUGVqVLsw3Iet55evVqJvF bIOv1GhgjGa+PWZt2Jrm9cNxfNFrgndjk8ocLZ3NclYudDn0XSg20Xy4zyxaubLCCx51 GfCGk4TSmvrtYVZWGSZHswYQNXJzq8zcu3vuacSbL4WOjgQbmLu/5UDpfZmSHxmzegYL IPXZ89Kom/KFepabWl/WMOXuG4AzCXKlHZOR04WMd4jZvjlOv63VzpGJAKLTqFvc+fN/ uTgw==
- Authentication-results: mx.google.com; dkim=pass header.i=@ngrt.de header.s=strato-dkim-0002 header.b=Av+BfH85; dkim=neutral (no key) header.i=@ngrt.de header.s=strato-dkim-0003; arc=pass (i=1); spf=pass (google.com: domain of dani@xxxxxxx designates 85.215.255.24 as permitted sender) smtp.mailfrom=dani@xxxxxxx
- Cc: Andreas Weis <der_ghulbus@xxxxxxxxxxxxxx>
- Delivered-to: jbeulich@xxxxxxxx
- Importance: Normal
Hallo zusammen,
bitte nicht wundern, aber sobald ich "Ingenieur" rieche, bin ich sofort beim
"Du" (bin ja selber eine).
Mein Hauptfokus liegt zwar auf C++, und C ist für mich ein "Seiteneffekt", aber
diese Frage kann ich vermutlich ebenfalls beantworten:
Die Initialisierung eines Objekts ist niemals ein Seiteneffekt der
Initialisierung von sich selbst. In den Expressions, welche zur Initialisierung
evaluiert werden, können jedoch sehr wohl Seiteneffekte in anderen Objekten
auftreten.
@Andreas: kannst du dem zustimmen? C hat ja ein sehr viel einfacheres
Objektmodell als C++. Die (potentielle) Änderung der Objektrepräsentation (d.h.
die Bytes, welche das Objekt hinterlegen) ist ja kein Seiteneffekt der
Objektinitialisierung, sondern sein primärer Zweck.
Wenn es um MISRA geht, wäre sicherlich P. Sommerlad der richtige
Ansprechpartner (https://sommerlad.ch/). Ansonsten tagt das WG14 Komittee
gerade, große Teile der WG14 Tafelrunde sind versammelt, Robert Seacord ist
sein Chair.
lG Daniela
> Wellhöfer, Johannes <johannes.wellhoefer@xxxxxx> hat am 02.10.2024 15:02 CEST
> geschrieben:
>
>
> Danke Manuela, fürs weiterleiten.
>
> Sehr geehrter Herr Beulich,
>
> vielen Dank für Ihre Anfrage. Ich habe Frau Engert hier mit in den
> Emailverlauf genommen. Sie arbeitet als deutsche Expertin in der
> JTC1/SC22/WG14 mit.
>
> @Daniela Engert können Sie Herrn Beulich mit seiner Frage (unten im Verlauf
> gelb markiert) weiterhelfen?
>
> Mit freundlichen Grüßen
>
> Johannes Wellhöfer
> Er/Sein
> Projektmanager
> DIN-Normenausschuss Informationstechnik und Anwendungen (NIA)
> DIN Deutsches Institut für Normung e. V. – Industrie und Informationstechnik
> (DIN – NuS IIT IuA)
>
> LinkedIn (https://www.linkedin.com/in/johannes-wellhoefer/) | T +49 30
> 2601-2455 | F +49 30 2601-4-2455 | M +49 174 2007820
> LinkedIn-Kanal des Normenausschusses für Informationstechnik und Anwendungen
> (https://www.linkedin.com/showcase/din-nia/)
>
>
>
>
> Ab sofort kostenlos: Der Normungs-Monitor
> (https://www.din.de/de/din-und-seine-partner/presse/mitteilungen/ab-januar-kostenlos-der-normungs-monitor-983794)
> Unkompliziert zu Normungsprojekten Ihrer Branche auf dem Laufenden bleiben
>
>
> Folgen Sie uns auf https://twitter.com/DIN_Norm
> https://www.linkedin.com/company/din-ev
> https://www.youtube.com/user/DINBerlin
>
> DIN Deutsches Institut für Normung e. V., Am DIN-Platz, Burggrafenstraße 6,
> 10787 Berlin; www.din.de (http://www.din.de/)} Registergericht: AG
> Berlin-Charlottenburg, VR 288 B; Präsident: Ulrich B. Stoll; Vorstand:
> Christoph Winterhalter (Vorsitzender), Daniel Schmidt;
> Der Inhalt dieser E-Mail (einschließlich Anhängen) ist vertraulich. Falls Sie
> diese E-Mail versehentlich erhalten haben, löschen Sie sie bitte und
> informieren den Absender. The contents of this e-mail (including attachments)
> are confidential. If you received this e-mail in error, please delete it and
> notify the sender.
> -----Ursprüngliche Nachricht-----
> Von: Tillack-Lübke, Manuela <Manuela.Tillack-luebke@xxxxxx>
> Gesendet: Mittwoch, 2. Oktober 2024 12:09
> An: Wellhöfer, Johannes <Johannes.Wellhoefer@xxxxxx>
> Betreff: WG: Klarstellung zu ISO/IEC JTC1/SC22/WG14
>
> Lieber Johannes,
>
> zuständigkeitshalber bitte ich Dich um Beantwortung der unten angefügten
> Anfrage. Vielen Dank.
>
>
> Mit besten Grüßen
>
> Manuela
> AP A. 634
> - 2419
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: info@xxxxxx <info@xxxxxx>
> Gesendet: Mittwoch, 2. Oktober 2024 10:17
> An: DIN Info <DIN-Info@xxxxxx>
> Betreff: Klarstellung zu ISO/IEC JTC1/SC22/WG14
>
> Guten Tag,
>
> folgende Nachricht wurde auf https://www.din.de/de an Sie geschickt.
>
> Guten Tag,
>
> im Zusammenhang mit Misra C:2012 ist eine Interpretationsfrage zum C99
> Standard (ISO/IEC 9899:TC3) aufgetaucht. Zur Klärung wurde ich an den ISO
> National Body verwiesen, der - soweit ich feststellen kann - Sie sind.
>
> Die eigentliche Frage betrifft "side effects": Fällt die Initialisierung
> eines Objekts auch darunter?
>
> In der Hoffnung, dass Sie uns bei der Klärung behilflich sein können,
> möglicherweise auch durch Verweis an eine andere geeignete Stelle, vielen
> Dank im Voraus,
> Jan Beulich
>
> Herr Jan Beulich
> jbeulich@xxxxxxxx
--- End Message ---
|