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

[PATCH] misra: address Rule 11.3 in spin_unlock_common()


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>
  • Date: Mon, 3 Nov 2025 10:11:09 +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=NEBXxe5Boj0saBa99VfCm7OJSQT//pjU4KKrjePIzjk=; b=NWs6Ojaidi8HPnoGdrQeEDP1u2wracFG1u7oIc58P2QqEY7nUyh36oOGa5q6g+k0/+PwPn1VCx92Jku8H7UuzleEsPAVKfz69I2i6w2j8M8ap+AFjLLfHpeB6xSncJvmzsomr7ILzqyYtR0zGbBYvVEa3AyxKPHc5kPzNNPXbWMNxkRFd7KPTA5mdl5XpETQvtFeAQ8W9YQKLWoXv9FkqNuSR4orT9ktQaiOZCm7Ss2VIeHL2p7o8coZrimCcLJSFjGlDD32fRzBrYmGK2v0ueOAOdkreNnaRnmCFh614DTCbc9Kq/KlAJhknBtRBwgoLCv2NYKk1Kkd255ykJSuew==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UP8QXwtNsrJJOA2AMs7tgu7YP5Lg9/VS0duCbfti/U3KHZQtAwWGhN0p+BKDvCBX6R+FsFXalMYe6sjXSPqm8cevFEEyxfuA4EP+r7ojOW62xrWEROEUPA+YBt2Noa/x1Mj+o+0Ac/JwSyG4Kwqc/qT8ryhI9jzrD+WmhSCJqKqrx/D+9yLkgm8dhsZoVwSA6E+wJtkmGz6TAJazA+9lfwDmvpq6dKdRysGjUIgFnrwA6LGHPhWr28BT4WAMI8dW4dD78YV07BmvKLPwUoir6CeePr/RKId1/PEVe5jWc8k6kxu0tlf6LGUnF5+z13NNnfjcnEe7puNqJfNXdCEn3g==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>, Alistair Francis <alistair.francis@xxxxxxx>, Bob Eshleman <bobbyeshleman@xxxxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>, Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Mon, 03 Nov 2025 10:11:26 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHcTKotzXBEqxBVDUKBYcHGEivA9g==
  • Thread-topic: [PATCH] misra: address Rule 11.3 in spin_unlock_common()

The generic 'add_sized()' macro performs type-based pointer casts, which
violate MISRA C Rule 11.3 (cast between pointer to object type and pointer
to a different object type).
Replace the use of 'add_sized(&t->head, 1)' with the type-specific
'add_u16_sized(&t->head, 1)' in the 'spin_unlock_common()' function.

A BUILD_BUG_ON(sizeof(t->head) != sizeof(uint16_t)); check is added to
ensure the field size matches expectations at build time.

On RISC-V, the atomic addition function for 16-bit values was missing,
causing build failures when called 'add_u16_sized()'. Generate a static
inline implementation of 'add_u16_sized()' for uint16_t.

Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
---
Test CI pipeline:
https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/2136333330
---
 xen/arch/riscv/include/asm/atomic.h | 10 ++++++++++
 xen/common/spinlock.c               |  3 ++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/xen/arch/riscv/include/asm/atomic.h 
b/xen/arch/riscv/include/asm/atomic.h
index 8e0425cea0..2676061725 100644
--- a/xen/arch/riscv/include/asm/atomic.h
+++ b/xen/arch/riscv/include/asm/atomic.h
@@ -111,6 +111,16 @@ static always_inline void _add_sized(volatile void *p,
     }
 }
 
+#define build_add_sized(name, type)                                     \
+static inline void name(volatile type *addr, unsigned long val)         \
+{                                                                       \
+    volatile type *ptr = addr;                                          \
+    write_atomic(ptr, read_atomic(ptr) + val);                          \
+}
+
+build_add_sized(add_u16_sized, uint16_t)
+#undef build_add_sized
+
 #define add_sized(p, x)                                 \
 ({                                                      \
     typeof(*(p)) x_ = (x);                              \
diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c
index 0389293b09..d9dc9998e6 100644
--- a/xen/common/spinlock.c
+++ b/xen/common/spinlock.c
@@ -367,7 +367,8 @@ static void always_inline 
spin_unlock_common(spinlock_tickets_t *t,
     LOCK_PROFILE_REL;
     rel_lock(debug);
     arch_lock_release_barrier();
-    add_sized(&t->head, 1);
+    BUILD_BUG_ON(sizeof(t->head) != sizeof(uint16_t));
+    add_u16_sized(&t->head, 1);
     arch_lock_signal();
     preempt_enable();
 }
-- 
2.43.0



 


Rackspace

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