From: Xi Ruoyao <xry111@xry111.site>
To: guoren@kernel.org, chenhuacai@kernel.or, kernel@xen0n.name,
arnd@arndb.de, andi.shyti@linux.intel.com, wangrui@loongson.cn,
andrzej.hajda@intel.com, peterz@infradead.org, will@kernel.org,
boqun.feng@gmail.com, mark.rutland@arm.com
Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org,
Guo Ren <guoren@linux.alibaba.com>
Subject: Re: [PATCH] LoongArch: Fixup cmpxchg sematic for memory barrier
Date: Tue, 01 Aug 2023 11:10:55 +0800 [thread overview]
Message-ID: <8573346a40ff1490cdc15d5e11d982a06e98d3bb.camel@xry111.site> (raw)
In-Reply-To: <20230801011554.3950435-1-guoren@kernel.org>
On Mon, 2023-07-31 at 21:15 -0400, guoren@kernel.org wrote:
> From: Guo Ren <guoren@linux.alibaba.com>
>
> When cmpxchg failed, no memory barrier was needed to take. Only
> when cmpxchg success and the new value is written, then the memory
> barriers needed.
>
> - cmpxchg_asm: Unnecessary __WEAK_LLSC_WB for the fail path would
> reduce the performance of the cmpxchg loop trying.
I'm not an expert in memory models, but in practice this barrier is
really needed or cmpxchg will be "not atomic". See
https://lore.kernel.org/linux-mips/1d49da11-51d5-e148-cb02-9bd0ee57fae6@flygoat.com/.
> - cmpxchg_small: Miss an necessary __WEAK_LLSC_WB when sc succeeds.
> It's a bug because there is no memory synchronization
> when sc succeeds.
>
> Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
> Signed-off-by: Guo Ren <guoren@kernel.org>
> ---
> arch/loongarch/include/asm/cmpxchg.h | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/arch/loongarch/include/asm/cmpxchg.h b/arch/loongarch/include/asm/cmpxchg.h
> index 979fde61bba8..6a05b92814b6 100644
> --- a/arch/loongarch/include/asm/cmpxchg.h
> +++ b/arch/loongarch/include/asm/cmpxchg.h
> @@ -102,8 +102,8 @@ __arch_xchg(volatile void *ptr, unsigned long x, int size)
> " move $t0, %z4 \n" \
> " " st " $t0, %1 \n" \
> " beqz $t0, 1b \n" \
> - "2: \n" \
> __WEAK_LLSC_MB \
> + "2: \n" \
> : "=&r" (__ret), "=ZB"(*m) \
> : "ZB"(*m), "Jr" (old), "Jr" (new) \
> : "t0", "memory"); \
> @@ -148,10 +148,8 @@ static inline unsigned int __cmpxchg_small(volatile void *ptr, unsigned int old,
> " or %1, %1, %z6 \n"
> " sc.w %1, %2 \n"
> " beqz %1, 1b \n"
> - " b 3f \n"
> - "2: \n"
> __WEAK_LLSC_MB
> - "3: \n"
> + "2: \n"
> : "=&r" (old32), "=&r" (temp), "=ZC" (*ptr32)
> : "ZC" (*ptr32), "Jr" (mask), "Jr" (old), "Jr" (new)
> : "memory");
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
prev parent reply other threads:[~2023-08-01 3:11 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-01 1:15 guoren
2023-08-01 2:29 ` WANG Rui
2023-08-01 8:32 ` Will Deacon
2023-08-01 9:30 ` WANG Rui
2023-08-01 9:02 ` Guo Ren
2023-08-01 9:05 ` Guo Ren
2023-08-01 9:31 ` WANG Rui
2023-08-01 10:49 ` Guo Ren
2023-08-01 11:23 ` Xi Ruoyao
2023-08-01 11:28 ` Xi Ruoyao
2023-08-01 16:36 ` WANG Rui
2023-08-01 23:17 ` Guo Ren
2023-08-02 2:23 ` WANG Rui
2023-08-01 3:10 ` Xi Ruoyao [this message]
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=8573346a40ff1490cdc15d5e11d982a06e98d3bb.camel@xry111.site \
--to=xry111@xry111.site \
--cc=andi.shyti@linux.intel.com \
--cc=andrzej.hajda@intel.com \
--cc=arnd@arndb.de \
--cc=boqun.feng@gmail.com \
--cc=chenhuacai@kernel.or \
--cc=guoren@kernel.org \
--cc=guoren@linux.alibaba.com \
--cc=kernel@xen0n.name \
--cc=linux-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=mark.rutland@arm.com \
--cc=peterz@infradead.org \
--cc=wangrui@loongson.cn \
--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®