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

Re: [PATCH 1/3] xen/keyhandler: add missing noreturn attribute


  • To: Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Fri, 6 Jun 2025 08:47:50 +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: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>, victorm.lira@xxxxxxx, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Federico Serafini <federico.serafini@xxxxxxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Fri, 06 Jun 2025 06:48:12 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 06.06.2025 02:09, Stefano Stabellini wrote:
> On Thu, 5 Jun 2025, Jan Beulich wrote:
>> On 05.06.2025 14:26, Nicola Vetrini wrote:
>>> On 2025-06-05 14:22, Nicola Vetrini wrote:
>>>> On 2025-06-05 09:17, Jan Beulich wrote:
>>>>> On 05.06.2025 01:49, victorm.lira@xxxxxxx wrote:
>>>>>> From: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
>>>>>>
>>>>>> Function `reboot_machine' does not return, but lacks the `noreturn' 
>>>>>> attribute,
>>>>>> therefore causing a violation of MISRA C Rule 2.1: "A project shall 
>>>>>> not contain
>>>>>> unreachable code".
>>>>>
>>>>> Is this (uniformly) true? Looking at ...
>>>>>
>>>>>> --- a/xen/common/keyhandler.c
>>>>>> +++ b/xen/common/keyhandler.c
>>>>>> @@ -251,7 +251,7 @@ static void cf_check 
>>>>>> dump_hwdom_registers(unsigned char key)
>>>>>>      }
>>>>>>  }
>>>>>>
>>>>>> -static void cf_check reboot_machine(unsigned char key, bool unused)
>>>>>> +static void noreturn cf_check reboot_machine(unsigned char key, bool 
>>>>>> unused)
>>>>>>  {
>>>>>>      printk("'%c' pressed -> rebooting machine\n", key);
>>>>>>      machine_restart(0);
>>>>>
>>>>> ... generated code here, I can see that the compiler is perfectly able 
>>>>> to
>>>>> leverage the noreturn that machine_restart() has, resulting in no
>>>>> unreachable code to be generated. That is - neither in source nor in
>>>>> binary there is any unreachable code. Therefore I'm having a hard time
>>>>> seeing what the violation is here.
>>>>>
>>>>> That said, I certainly don't mind the addition of the (seemingly) 
>>>>> missing
>>>>> attribute. Otoh I wonder whether an attribute the removal of which has 
>>>>> no
>>>>> effect wouldn't count as "dead code" or alike, violating some other 
>>>>> rule.
>>>>>
>>>>
>>>> Inlining does not play a role in this case. Here reboot_machine() is 
>>>> marked as a violation because machine_restart() is noreturn and there 
>>>> is no other path upon which reboot_machine() may return, hence any 
>>>> function calling reboot_machine() could have portions that are 
>>>> inadvertently unreachable (as in never executed due to divergence) by 
>>>> not having the annotation.
>>
>> Just that there's not going to be a 2nd caller, considering the purpose
>> of the function.
>>
>>>> That said, in such trivial cases compilers 
>>>> are typically able to derive the property automatically, but they are 
>>>> not obliged to and, more importantly, the behavior may even differ with 
>>>> the same compiler using different optimization levels.
>>>
>>> Just a note: in later revisions of MISRA C this has become a rule of its 
>>> own [1], which helps reduce confusion, but up to MISRA C:2012 Amendment 
>>> 2 (currently used by Xen), this is part of Rule 2.1.
>>>
>>> [1] Rule 17.11: "A function that never returns should be declared with a 
>>> _Noreturn function specifier"
>>
>> Oh, that's indeed quite a bit more explicit.
> 
> Does it mean you would ack the patch? :-)

With an improved description I may at least no longer object to it.

Jan



 


Rackspace

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