From: Nicholas Piggin <npiggin@gmail.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: Nicholas Piggin <npiggin@gmail.com>
Subject: [PATCH 8/9] powerpc/64s: Permit d-form memops in asm when building with prefix on clang
Date: Wed, 26 Apr 2023 15:58:46 +1000 [thread overview]
Message-ID: <20230426055848.402993-10-npiggin@gmail.com> (raw)
In-Reply-To: <20230426055848.402993-1-npiggin@gmail.com>
GCC appears to have a bug where it generates immediate offsets beyond
the 16-bit range of d-form memory operations in extended inline asm
when prefix instructions are enabled. So simpler fallback asm is
implemented for CONFIG_PPC_KERNEL_PREFIXED builds for now.
Clang does not have this bug, so this hack can be restricted to GCC.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
arch/powerpc/Kconfig | 7 +++++++
arch/powerpc/include/asm/atomic.h | 8 ++++----
arch/powerpc/include/asm/io.h | 2 +-
arch/powerpc/include/asm/uaccess.h | 4 ++--
4 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 261e9453b43c..39cd8d3ff846 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -7,6 +7,13 @@ config CC_HAS_ELFV2
config CC_HAS_PREFIXED
def_bool PPC64 && $(cc-option, -mcpu=power10 -mprefixed)
+config CC_HAS_BROKEN_DFORM_MEMOP_ASM
+ # GCC has a bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108239)
+ # when compiling with prefixed instructions that causes it to generate
+ # out-of-range offsets for d-form loads and stores from memory
+ # operands.
+ def_bool CC_HAS_PREFIXED && CC_IS_GCC
+
config CC_HAS_PCREL
# Clang has a bug (https://github.com/llvm/llvm-project/issues/62372)
# where pcrel code is not generated if -msoft-float, -mno-altivec, or
diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
index 47228b177478..f15c9e54e261 100644
--- a/arch/powerpc/include/asm/atomic.h
+++ b/arch/powerpc/include/asm/atomic.h
@@ -28,7 +28,7 @@ static __inline__ int arch_atomic_read(const atomic_t *v)
int t;
/* -mprefixed can generate offsets beyond range, fall back hack */
- if (IS_ENABLED(CONFIG_PPC_KERNEL_PREFIXED))
+ if (IS_ENABLED(CONFIG_CC_HAS_BROKEN_DFORM_MEMOP_ASM))
__asm__ __volatile__("lwz %0,0(%1)" : "=r"(t) : "b"(&v->counter));
else
__asm__ __volatile__("lwz%U1%X1 %0,%1" : "=r"(t) : "m<>"(v->counter));
@@ -39,7 +39,7 @@ static __inline__ int arch_atomic_read(const atomic_t *v)
static __inline__ void arch_atomic_set(atomic_t *v, int i)
{
/* -mprefixed can generate offsets beyond range, fall back hack */
- if (IS_ENABLED(CONFIG_PPC_KERNEL_PREFIXED))
+ if (IS_ENABLED(CONFIG_CC_HAS_BROKEN_DFORM_MEMOP_ASM))
__asm__ __volatile__("stw %1,0(%2)" : "=m"(v->counter) : "r"(i), "b"(&v->counter));
else
__asm__ __volatile__("stw%U0%X0 %1,%0" : "=m<>"(v->counter) : "r"(i));
@@ -206,7 +206,7 @@ static __inline__ s64 arch_atomic64_read(const atomic64_t *v)
s64 t;
/* -mprefixed can generate offsets beyond range, fall back hack */
- if (IS_ENABLED(CONFIG_PPC_KERNEL_PREFIXED))
+ if (IS_ENABLED(CONFIG_CC_HAS_BROKEN_DFORM_MEMOP_ASM))
__asm__ __volatile__("ld %0,0(%1)" : "=r"(t) : "b"(&v->counter));
else
__asm__ __volatile__("ld%U1%X1 %0,%1" : "=r"(t) : "m<>"(v->counter));
@@ -217,7 +217,7 @@ static __inline__ s64 arch_atomic64_read(const atomic64_t *v)
static __inline__ void arch_atomic64_set(atomic64_t *v, s64 i)
{
/* -mprefixed can generate offsets beyond range, fall back hack */
- if (IS_ENABLED(CONFIG_PPC_KERNEL_PREFIXED))
+ if (IS_ENABLED(CONFIG_CC_HAS_BROKEN_DFORM_MEMOP_ASM))
__asm__ __volatile__("std %1,0(%2)" : "=m"(v->counter) : "r"(i), "b"(&v->counter));
else
__asm__ __volatile__("std%U0%X0 %1,%0" : "=m<>"(v->counter) : "r"(i));
diff --git a/arch/powerpc/include/asm/io.h b/arch/powerpc/include/asm/io.h
index f1e657c9bbe8..2e6061f26c09 100644
--- a/arch/powerpc/include/asm/io.h
+++ b/arch/powerpc/include/asm/io.h
@@ -98,7 +98,7 @@ extern bool isa_io_special;
*/
/* -mprefixed can generate offsets beyond range, fall back hack */
-#ifdef CONFIG_PPC_KERNEL_PREFIXED
+#ifdef CONFIG_CC_HAS_BROKEN_DFORM_MEMOP_ASM
#define DEF_MMIO_IN_X(name, size, insn) \
static inline u##size name(const volatile u##size __iomem *addr) \
{ \
diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
index a2d255aa9627..6fdca4cddcf3 100644
--- a/arch/powerpc/include/asm/uaccess.h
+++ b/arch/powerpc/include/asm/uaccess.h
@@ -72,7 +72,7 @@ __pu_failed: \
* are no aliasing issues.
*/
/* -mprefixed can generate offsets beyond range, fall back hack */
-#ifdef CONFIG_PPC_KERNEL_PREFIXED
+#ifdef CONFIG_CC_HAS_BROKEN_DFORM_MEMOP_ASM
#define __put_user_asm_goto(x, addr, label, op) \
asm_volatile_goto( \
"1: " op " %0,0(%1) # put_user\n" \
@@ -144,7 +144,7 @@ do { \
#ifdef CONFIG_CC_HAS_ASM_GOTO_OUTPUT
/* -mprefixed can generate offsets beyond range, fall back hack */
-#ifdef CONFIG_PPC_KERNEL_PREFIXED
+#ifdef CONFIG_CC_HAS_BROKEN_DFORM_MEMOP_ASM
#define __get_user_asm_goto(x, addr, label, op) \
asm_volatile_goto( \
"1: "op" %0,0(%1) # get_user\n" \
--
2.40.0
next prev parent reply other threads:[~2023-04-26 6:07 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-26 5:58 [PATCH 0/9] powerpc: Build fixes Nicholas Piggin
2023-04-26 5:58 ` [PATCH 1/9] powerpc: Fix merge conflict between pcrel and copy_thread changes Nicholas Piggin
2023-04-26 5:58 ` [PATCH 2/9] powerpc/64s: Disable pcrel code model on Clang Nicholas Piggin
2023-04-26 5:58 ` [PATCH 3/9] powerpc/boot: Seperate target flags from BOOTCFLAGS Nicholas Piggin
2023-04-26 5:58 ` [PATCH 4/9] powerpc/boot: Seperate CPP " Nicholas Piggin
2023-04-26 5:58 ` [PATCH 5/9] powerpc/boot: Separate BOOTCFLAGS from BOOTASFLAGS Nicholas Piggin
2023-04-26 15:11 ` Linus Torvalds
2023-04-26 5:58 ` [PATCH 6/9] powerpc/boot: Clean up Makefile after cflags and asflags separation Nicholas Piggin
2023-04-26 5:58 ` [PATCH 6/9] powerpc/boot: clean up Makefile flags Nicholas Piggin
2023-04-26 5:58 ` [PATCH 7/9] powerpc/build: Remove -pipe from compilation flags Nicholas Piggin
2023-04-26 5:58 ` Nicholas Piggin [this message]
2023-04-26 5:58 ` [PATCH 9/9] powerpc/64s: Work around llvm-as not recognising pla Nicholas Piggin
2023-04-26 12:01 ` (subset) [PATCH 0/9] powerpc: Build fixes Michael Ellerman
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=20230426055848.402993-10-npiggin@gmail.com \
--to=npiggin@gmail.com \
--cc=linuxppc-dev@lists.ozlabs.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;
as well as URLs for NNTP newsgroup(s).