From: David Laight <david.laight.linux@gmail.com>
To: Andreas Schwab <schwab@suse.de>
Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] riscv/atomic: Do proper sign extension also for unsigned in arch_cmpxchg
Date: Thu, 30 Jan 2025 21:35:04 +0000 [thread overview]
Message-ID: <20250130213504.285b4675@pumpkin> (raw)
In-Reply-To: <mvmed0k4prh.fsf@suse.de>
On Thu, 30 Jan 2025 10:25:38 +0100
Andreas Schwab <schwab@suse.de> wrote:
> Sign extend also an unsigned compare value to match what lr.w is doing.
> Otherwise try_cmpxchg may spuriously return true when used on a u32 value
> that has the sign bit set, as it happens often in inode_set_ctime_current.
>
> Do this in three conversion steps. The first conversion to long is needed
> to avoid a -Wpointer-to-int-cast warning when arch_cmpxchg is used with a
> pointer type.
Doesn't that break things by discarding the high bits of a pointer value?
David
> Then convert to int and back to long to always sign extend
> the 32-bit value to 64-bit.
>
> Fixes: 6c58f25e6938 ("riscv/atomic: Fix sign extension for RV64I")
> Signed-off-by: Andreas Schwab <schwab@suse.de>
> ---
> arch/riscv/include/asm/cmpxchg.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h
> index 4cadc56220fe..427c41dde643 100644
> --- a/arch/riscv/include/asm/cmpxchg.h
> +++ b/arch/riscv/include/asm/cmpxchg.h
> @@ -231,7 +231,7 @@
> __arch_cmpxchg(".w", ".w" sc_sfx, ".w" cas_sfx, \
> sc_prepend, sc_append, \
> cas_prepend, cas_append, \
> - __ret, __ptr, (long), __old, __new); \
> + __ret, __ptr, (long)(int)(long), __old, __new); \
> break; \
> case 8: \
> __arch_cmpxchg(".d", ".d" sc_sfx, ".d" cas_sfx, \
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
WARNING: multiple messages have this Message-ID (diff)
From: David Laight <david.laight.linux@gmail.com>
To: Andreas Schwab <schwab@suse.de>
Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] riscv/atomic: Do proper sign extension also for unsigned in arch_cmpxchg
Date: Thu, 30 Jan 2025 21:35:04 +0000 [thread overview]
Message-ID: <20250130213504.285b4675@pumpkin> (raw)
In-Reply-To: <mvmed0k4prh.fsf@suse.de>
On Thu, 30 Jan 2025 10:25:38 +0100
Andreas Schwab <schwab@suse.de> wrote:
> Sign extend also an unsigned compare value to match what lr.w is doing.
> Otherwise try_cmpxchg may spuriously return true when used on a u32 value
> that has the sign bit set, as it happens often in inode_set_ctime_current.
>
> Do this in three conversion steps. The first conversion to long is needed
> to avoid a -Wpointer-to-int-cast warning when arch_cmpxchg is used with a
> pointer type.
Doesn't that break things by discarding the high bits of a pointer value?
David
> Then convert to int and back to long to always sign extend
> the 32-bit value to 64-bit.
>
> Fixes: 6c58f25e6938 ("riscv/atomic: Fix sign extension for RV64I")
> Signed-off-by: Andreas Schwab <schwab@suse.de>
> ---
> arch/riscv/include/asm/cmpxchg.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h
> index 4cadc56220fe..427c41dde643 100644
> --- a/arch/riscv/include/asm/cmpxchg.h
> +++ b/arch/riscv/include/asm/cmpxchg.h
> @@ -231,7 +231,7 @@
> __arch_cmpxchg(".w", ".w" sc_sfx, ".w" cas_sfx, \
> sc_prepend, sc_append, \
> cas_prepend, cas_append, \
> - __ret, __ptr, (long), __old, __new); \
> + __ret, __ptr, (long)(int)(long), __old, __new); \
> break; \
> case 8: \
> __arch_cmpxchg(".d", ".d" sc_sfx, ".d" cas_sfx, \
next prev parent reply other threads:[~2025-01-30 21:35 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-30 9:25 [PATCH] riscv/atomic: Do proper sign extension also for unsigned in arch_cmpxchg Andreas Schwab
2025-01-30 9:25 ` Andreas Schwab
2025-01-30 14:18 ` Alexandre Ghiti
2025-01-30 14:18 ` Alexandre Ghiti
2025-01-30 14:52 ` Andreas Schwab
2025-01-30 14:52 ` Andreas Schwab
2025-01-30 15:23 ` Alexandre Ghiti
2025-01-30 15:23 ` Alexandre Ghiti
2025-01-30 15:53 ` Andreas Schwab
2025-01-30 15:53 ` Andreas Schwab
2025-01-30 17:21 ` Jessica Clarke
2025-01-30 17:21 ` Jessica Clarke
2025-02-03 8:42 ` Andreas Schwab
2025-02-03 8:42 ` Andreas Schwab
2025-02-03 13:57 ` Maciej W. Rozycki
2025-02-03 13:57 ` Maciej W. Rozycki
2025-02-03 21:22 ` Jessica Clarke
2025-02-03 21:22 ` Jessica Clarke
2025-02-04 16:44 ` Maciej W. Rozycki
2025-02-04 16:44 ` Maciej W. Rozycki
2025-01-30 14:40 ` Andrew Jones
2025-01-30 14:40 ` Andrew Jones
2025-01-30 21:35 ` David Laight [this message]
2025-01-30 21:35 ` David Laight
2025-02-03 8:42 ` Andreas Schwab
2025-02-03 8:42 ` Andreas Schwab
2025-02-01 12:17 ` Xi Ruoyao
2025-02-01 12:17 ` Xi Ruoyao
2025-02-04 8:33 ` Alexandre Ghiti
2025-02-04 8:33 ` Alexandre Ghiti
2025-02-13 18:30 ` patchwork-bot+linux-riscv
2025-02-13 18:30 ` patchwork-bot+linux-riscv
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=20250130213504.285b4675@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=schwab@suse.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.