Re: [PATCH] locking/atomic: scripts: Fix type error in macro try_cmpxchg
From: Uros Bizjak
Date: Fri Jul 19 2024 - 06:15:50 EST
On Fri, Jul 19, 2024 at 4:40 AM Bibo Mao <maobibo@xxxxxxxxxxx> wrote:
>
> When porting pv spinlock function on LoongArch system, there is
> compiling error such as:
> from linux/include/linux/smp.h:13,
> from linux/kernel/locking/qspinlock.c:16:
> linux/kernel/locking/qspinlock_paravirt.h: In function 'pv_kick_node':
> linux/include/linux/atomic/atomic-arch-fallback.h:242:34: error: initialization of 'u8 *' {aka 'unsigned char *'} from incompatible pointer type 'enum vcpu_state *' [-Wincompatible-pointer-types]
> 242 | typeof(*(_ptr)) *___op = (_oldp), ___o = *___op, ___r; \
> | ^
> linux/atomic/atomic-instrumented.h:4908:9: note: in expansion of macro 'raw_try_cmpxchg_relaxed'
> 4908 | raw_try_cmpxchg_relaxed(__ai_ptr, __ai_oldp, __VA_ARGS__); \
> | ^~~~~~~~~~~~~~~~~~~~~~~
> linux/kernel/locking/qspinlock_paravirt.h:377:14: note: in expansion of macro 'try_cmpxchg_relaxed'
> 377 | if (!try_cmpxchg_relaxed(&pn->state, &old, vcpu_hashed))
This points to the mismatch between "pn->state" and "old" variable.
The correct fix is:
--cut here--
diff --git a/kernel/locking/qspinlock_paravirt.h
b/kernel/locking/qspinlock_paravirt.h
index f5a36e67b593..ac2e22502741 100644
--- a/kernel/locking/qspinlock_paravirt.h
+++ b/kernel/locking/qspinlock_paravirt.h
@@ -357,7 +357,7 @@ static void pv_wait_node(struct mcs_spinlock
*node, struct mcs_spinlock *prev)
static void pv_kick_node(struct qspinlock *lock, struct mcs_spinlock *node)
{
struct pv_node *pn = (struct pv_node *)node;
- enum vcpu_state old = vcpu_halted;
+ u8 old = vcpu_halted;
/*
* If the vCPU is indeed halted, advance its state to match that of
* pv_wait_node(). If OTOH this fails, the vCPU was running and will
--cut here--
Uros.