mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Boqun Feng <boqun.feng@gmail.com>
To: Uros Bizjak <ubizjak@gmail.com>
Cc: Bibo Mao <maobibo@loongson.cn>, Will Deacon <will@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>,
	"Paul E . McKenney" <paulmck@kernel.org>,
	Carlos Llamas <cmllamas@google.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] locking/atomic: scripts: Fix type error in macro try_cmpxchg
Date: Fri, 19 Jul 2024 09:18:42 -0700	[thread overview]
Message-ID: <ZpqR4qkFUNgkJj0x@boqun-archlinux> (raw)
In-Reply-To: <CAFULd4bt5oiQq4_3jSDe+3P=1xtAhZ=34vLREqPVT9njjdWKSA@mail.gmail.com>

On Fri, Jul 19, 2024 at 12:15:28PM +0200, Uros Bizjak wrote:
> On Fri, Jul 19, 2024 at 4:40 AM Bibo Mao <maobibo@loongson.cn> 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;
>        /*

Looks reasonable to me, we should also add static_assert() for
try_cmpxhg_*() to make sure the old has the same size of the cmpxchged
field.

Regards,
Boqun

>         * 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.

  reply	other threads:[~2024-07-19 16:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-19  2:40 Bibo Mao
2024-07-19 10:15 ` Uros Bizjak
2024-07-19 16:18   ` Boqun Feng [this message]
2024-07-20  8:35     ` Uros Bizjak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZpqR4qkFUNgkJj0x@boqun-archlinux \
    --to=boqun.feng@gmail.com \
    --cc=cmllamas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maobibo@loongson.cn \
    --cc=mingo@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=ubizjak@gmail.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®