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

Re: [PATCH 3/4] xen/arm: domain: Fix MISRA C 2012 Rule 8.7 violation


  • To: Xenia Ragiadakou <burzalodowa@xxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 7 Jul 2022 09:55:17 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vDoXUJYE2L1MXgeg5Vl21Hb74gqxgy51xSJU7VJ02sw=; b=hDTFAUhI/jirQgCyOZF9WS1sMeBwbkujoxX+dA9Tm/wZDh+RpaexWz+PzxsgWz6nck3DBSy11E+3tDbfCbWQ8kI3w56LW50LpkOtpiWdCvu5pr8NsF6dOKn4UioCsrvg7dzzogYzkNZo0hlvSbkQp0aAD0J+juMYkdfNovz1v5YTMWxiy/lG/iJo8JXFpWAMkRWxwEMQ4ZVdZmQHmdToWs4+A0rF8Cr7HBhwTnPVaVlMy4rZeILf6xYoIlssCuPYTbWFW9/Xlp8A997orGdzm/ic3D87EBcQ4AMK3lr2HBGrKbUaHfbgw9LIK/kkf1FaZmyi4JrBbivvQJAIRU/jBA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cct7mlQ+fmofmRKmzqcl2c/8V04kDu6xrEXlaakl+Il1NzS6OS360UQRt5qtzF4Z7eIKLtpUJF2wtEKNhEmQZWhDflIK6fcmFKTUqOhYIv4DWnPlzasTbKBRJoBc8+oG5Y6VrmuNhBrFgkHuPM9L9a4qFpyHpKDZD0NAR45CTiUqB+QM0J9iSni34S3bXZCgybl+Q91hnWZpw2F80J63KQj/U06oGTNF0gibxnv70zdg1RoMAVAs53l24q5zPfp9My/5JSm6ohdc28YbqhTvXHrzXRel/n54CRPWotVPBtTeWRm3KiGkPgJk3tpwU5NnA1CdMhpt1scL4ATFGTBtDw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Thu, 07 Jul 2022 07:55:30 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 07.07.2022 09:27, Xenia Ragiadakou wrote:
> On 7/6/22 11:51, Jan Beulich wrote:
>> On 06.07.2022 10:43, Xenia Ragiadakou wrote:
>>> On 7/6/22 10:10, Jan Beulich wrote:
>>>> On 05.07.2022 23:02, Xenia Ragiadakou wrote:
>>>>> The function idle_loop() is referenced only in domain.c.
>>>>> Change its linkage from external to internal by adding the storage-class
>>>>> specifier static to its definitions.
>>>>>
>>>>> Since idle_loop() is referenced only in inline assembly, add the 'used'
>>>>> attribute to suppress unused-function compiler warning.
>>>>
>>>> While I see that Julien has already acked the patch, I'd like to point
>>>> out that using __used here is somewhat bogus. Imo the better approach
>>>> is to properly make visible to the compiler that the symbol is used by
>>>> the asm(), by adding a fake(?) input.
>>>
>>> I 'm afraid I do not understand what do you mean by "adding a fake(?)
>>> input". Can you please elaborate a little on your suggestion?
>>
>> Once the asm() in question takes the function as an input, the compiler
>> will know that the function has a user (unless, of course, it finds a
>> way to elide the asm() itself). The "fake(?)" was because I'm not deeply
>> enough into Arm inline assembly to know whether the input could then
>> also be used as an instruction operand (which imo would be preferable) -
>> if it can't (e.g. because there's no suitable constraint or operand
>> modifier), it still can be an input just to inform the compiler.
> 
> According to the following statement, your approach is the recommended one:
> "To prevent the compiler from removing global data or functions which 
> are referenced from inline assembly statements, you can:
> -use __attribute__((used)) with the global data or functions.
> -pass the reference to global data or functions as operands to inline 
> assembly statements.
> Arm recommends passing the reference to global data or functions as 
> operands to inline assembly statements so that if the final image does 
> not require the inline assembly statements and the referenced global 
> data or function, then they can be removed."
> 
> IIUC, you are suggesting to change
> asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack) : "memory" )
> into
> asm volatile ("mov sp,%0; b %1" : : "r" (stack), "S" (fn) : "memory" );

Yes, except that I can't judge about the "S" constraint.

> This gives, respectively:
> reset_stack_and_jump(idle_loop);
> 
>       460:    9100001f        mov     sp, x0
> 
>       464:    14000007        b       480 <idle_loop>
> 
> 
> reset_stack_and_jump(idle_loop);
> 
>       460:    9100001f        mov     sp, x0
> 
>       464:    14000000        b       600 <idle_loop>
> 
> 
> With this change, the functions return_to_new_vcpu32 and 
> return_to_new_vcpu64, implemented in assembly and called in the same way 
> as idle_loop(), need to be declared.

Which imo is a good thing - these probably shouldn't have lived entirely
behind the back of the compiler.

Jan



 


Rackspace

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