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

Re: [XEN PATCH 4/4] xen: address violations of MISRA C:2012 Rule 13.1


  • To: Simone Ballarin <simone.ballarin@xxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 19 Oct 2023 13:19:49 +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=UJnRviuH5kVqzhbJRUDVKYJ0B7nGICAbdQehwGjRISk=; b=GfwHySPyZeG2mSi/I3LzzGHAuO5SK21aCXJ8UmHYhnvz5Dc4UgeUsKQKsnEbeZtXwnAOCNVyoGurqZfgwOQMi0Wu7rxMzNYgT5Z4xGEvMJZPjl3MQBoVnmXAmJp8+sS/jQz26ABBxdZrfyiW/uhFZpSWJwzpwksWnn+NrJI7NnJ5qTalKvSxMiL74ArGqr8acC6S5FfGkKbfGyyXDHbTGl9/3HPMko4JqJ14ER1syqKmQkdYzZc56WJJgg8Hk3LPe04xPERWcAEIXQMhzhY2ezolf2+lBOjSh/qbV7+YBUx38fHmTsIazkfJ9DjDKVSAEjcQvE0gXCD8h5JoMcGmtA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ATjgnNZuoVLxeUDmdH+WdVrjLmmt3ZDv56+Av3gSNRNNtGpuotLIQf5mlELfTuZYOUiAOdXsDLqUhcav1KaXtPkqCYnYMvFb2lHMhGbcfFJ3MMfqdDZsUaAEw7Xu4ntBlrFntdtiBkn84+60dZRrshk7IozyIY46squMho9cx2j2S2I/UjngKJ0vLHHmbKOFUNkllr45leyyUMyVUhP3KukxhHzls/j4djQb/Y8OFPsjVU/TM6cCEj67bb9bKChLR0jK2HLOi8+i+klNp2yJQiRv9NRH7ekTU/ujRxFi4YhWeYuEJCjoI09/8Nv/bxTsjHk8S2to28sbz/ikKRpl4w==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, consulting@xxxxxxxxxxx, George Dunlap <george.dunlap@xxxxxxxxxx>, Dario Faggioli <dfaggioli@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Wei Liu <wl@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Thu, 19 Oct 2023 11:20:03 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 19.10.2023 13:12, Simone Ballarin wrote:
> On 19/10/23 11:35, Jan Beulich wrote:
>> On 19.10.2023 03:06, Stefano Stabellini wrote:
>>> On Wed, 18 Oct 2023, Simone Ballarin wrote:
>>>> --- a/xen/common/sched/core.c
>>>> +++ b/xen/common/sched/core.c
>>>> @@ -1504,6 +1504,8 @@ long vcpu_yield(void)
>>>>   {
>>>>       struct vcpu * v=current;
>>>>       spinlock_t *lock;
>>>> +    domid_t domain_id;
>>>> +    int vcpu_id;
>>>>   
>>>>       rcu_read_lock(&sched_res_rculock);
>>>>   
>>>> @@ -1515,7 +1517,9 @@ long vcpu_yield(void)
>>>>   
>>>>       SCHED_STAT_CRANK(vcpu_yield);
>>>>   
>>>> -    TRACE_2D(TRC_SCHED_YIELD, current->domain->domain_id, 
>>>> current->vcpu_id);
>>>> +    domain_id = current->domain->domain_id;
>>>> +    vcpu_id = current->vcpu_id;
>>>> +    TRACE_2D(TRC_SCHED_YIELD, domain_id, vcpu_id);
>>>
>>> Also here it looks like accessing the current pointer is considered a
>>> side effect. Why? This is a just a global variable that is only accessed
>>> for reading.
>>
>> Not exactly. It's a per-CPU variable access on Arm, but involves a
>> function call on x86. Still that function call has no other side
>> effects, but I guess Misra wouldn't honor this.
>>
>> I'm afraid though that the suggested change violates rule 2.2, as
>> the two new assignments are dead code when !CONFIG_TRACEBUFFER.
> 
> I confirm that there is no problem in X86: I will simply propose a patch
> adding __attribute_pure__ to get_cpu_info.

I specifically did not suggest that, because I'm afraid the "pure" attribute
may not be used there. Besides this attribute typically being discarded for
inline functions in favor of the compiler's own judgement, it would allow
the compiler to squash multiple invocations. This might even be desirable in
most cases, but would break across a stack pointer change. (In this context
you also need to keep in mind late optimizations done by LTO.)

Jan



 


Rackspace

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