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

Re: [PATCH] misra: fix Rule 11.3 violation in 'vcpu_mark_events_pending'


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>
  • Date: Fri, 22 Aug 2025 13:29:39 +0000
  • Accept-language: en-US, uk-UA, ru-RU
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=tfvnJewfW0iD06SEd1Fx9eRySUqTLCrVpsrNlqTHbJ4=; b=MfI+W7IMUEy32H2zLvR2Sqzjx8G/RBnnJD+WLRgbKXUc5ig/SxreA9g51FEOQiMDwOFaDCDwKAWjsLXD8dIaxzOEuY/uBbzvTOgLNOcfAXNv5SdOkSCxzAQcQmLR1HG9ORQlfraBFDV3K/VnXB7c4B82euFeJm8bla79x/Xbh55pd2pvV7YWNEKA8aRXCq3x2v2TvJZKsOGeEtd666VdCUXgM4S+La7JtnK5eOG0ixx2AvWtTr140wisVLzv3iYImamUpNJjjEsNwcEcGlwGa5m8c1URycM0uyOkw3F1HWwspXOuvJW8+t72f4usoaJ6PAc1MTjfUMcBZKUm9JRKig==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oRAbOMRlFPZ/0TpqG4fBKiCeJFHm+gKs6Cbs8Fp8O6y3zNJWht8AZx2t4H4wZU3pwePTK7ph9vEX+eWsEHMczzHMhmah8j2JaxvPf1EpnqR5Q5Rw0yB16mFBY9/UBzsDQhPQGh0xfZw6mSLL2orWo62Wf3WNh+hzGEfieUdMPb5bdTp8/0LG2NNW+F/PxBWESeB9KVt3WMPBypwCxMVkaMn960jiqgj0BoOC5HxP02M0u6tRXUj8j4V/aEmczoXDP8xSjlpU6Ycc8Su1VS+S2ADg4WW9OFzRnqS94ldTfih6nUatl9r0cvtBxanWdC+caZYgfHVlCqj6AHbWBfnupQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Fri, 22 Aug 2025 13:30:00 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHcEahzo6Ns4M/vpkyFl3Gc8+EN0rRs2qIAgAHTq4A=
  • Thread-topic: [PATCH] misra: fix Rule 11.3 violation in 'vcpu_mark_events_pending'


On 8/21/25 12:35, Jan Beulich wrote:
> On 20.08.2025 10:00, Dmytro Prokopchuk1 wrote:
>> MISRA C:2012 Rule 11.3 states: "A cast shall not be performed between
>> a pointer to object type and a pointer to a different object type."
>>
>> The function 'vcpu_mark_events_pending' contains a non-compliant cast
>> to (unsigned long*). Remove the explicit cast and pass the compatible
>> pointer type to the 'guest_test_and_set_bit' macro.
>
> No-where up to here (incl the subject) it is said that this is an Arm-
> only issue. Hence why I ended up looking in the first place.
>
>> Fixes: c626aa1a5a (arm: implement event injection, 2012-06-01)
>> Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
>> ---
>> Test CI pipeline:
>> https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/1993054203
>> ---
>>   xen/arch/arm/domain.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
>> index 310c578909..6371e68cc7 100644
>> --- a/xen/arch/arm/domain.c
>> +++ b/xen/arch/arm/domain.c
>> @@ -1166,7 +1166,7 @@ void arch_dump_vcpu_info(struct vcpu *v)
>>   void vcpu_mark_events_pending(struct vcpu *v)
>>   {
>>       bool already_pending = guest_test_and_set_bit(v->domain,
>> -        0, (unsigned long *)&vcpu_info(v, evtchn_upcall_pending));
>> +        0, &vcpu_info(v, evtchn_upcall_pending));
>
> It'll be Arm maintainers to judge, but my take is that the previously
> questionable construct better wouldn't be made yet more questionable.
> What's missing, at least for Arm32 aiui, is a (build-time) check that
> the field actually lives at a 32-bit boundary and that read-modify-
> write operations carried out on it at 32-bit width (this is true even
> for Arm64) won't have an impact on what follows (this may be possible
> to cover by just a comment, as you can't really check for the absence
> of struct fields).
>
> Jan

The build-time assert could be placed there:

BUILD_BUG_ON(offsetof(struct vcpu_info, evtchn_upcall_pending) % 4 != 0);

but member 'evtchn_upcall_pending' is the first in the struct
'vcpu_info', and offsetof() will always return zero.
Currently this assert is useless. Probably it can protect us in the
future when somebody will decide to move 'evtchn_upcall_pending' or add
new member in front of it.

Dmytro.

 


Rackspace

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