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"		\
