kvmarm.lists.cs.columbia.edu archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64: Work around broken GCC 4.9 handling of "S" constraint
@ 2020-12-17 11:11 Marc Zyngier
  2020-12-17 11:13 ` Ard Biesheuvel
  2020-12-17 14:13 ` Catalin Marinas
  0 siblings, 2 replies; 3+ messages in thread
From: Marc Zyngier @ 2020-12-17 11:11 UTC (permalink / raw)
  To: linux-arm-kernel, kvmarm
  Cc: Catalin Marinas, Will Deacon, Ard Biesheuvel, kernel-team

GCC 4.9 seems to have a problem with the "S" asm constraint
when the symbol lives in the same compilation unit, and pretends
the constraint is impossible:

$ cat x.c
void *foo(void)
{
	static int x;
	int *addr;
	asm("adrp %0, %1" : "=r" (addr) : "S" (&x));
	return addr;
}

$ ~/Work/gcc-linaro-aarch64-linux-gnu-4.9-2014.09_linux/bin/aarch64-linux-gnu-gcc -S -x c -O2 x.c
x.c: In function ‘foo’:
x.c:5:2: error: impossible constraint in ‘asm’
  asm("adrp %0, %1" : "=r" (addr) : "S" (&x));
  ^

Boo. Following revisions of the compiler work just fine, though.

We can fallback to the "i" constraint for GCC version prior to 5.0,
which *seems* to do the right thing. Hopefully we will be able to
remove this at some point, but in the meantime this gets us going.

Signed-off-by: Marc Zyngier <maz@kernel.org>
---
* From v1: Dropped the detection hack and rely on GCC_VERSION

 arch/arm64/include/asm/kvm_asm.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h
index 7ccf770c53d9..8a33d83ea843 100644
--- a/arch/arm64/include/asm/kvm_asm.h
+++ b/arch/arm64/include/asm/kvm_asm.h
@@ -199,6 +199,12 @@ extern void __vgic_v3_init_lrs(void);
 
 extern u32 __kvm_get_mdcr_el2(void);
 
+#if defined(GCC_VERSION) && GCC_VERSION < 50000
+#define SYM_CONSTRAINT	"i"
+#else
+#define SYM_CONSTRAINT	"S"
+#endif
+
 /*
  * Obtain the PC-relative address of a kernel symbol
  * s: symbol
@@ -215,7 +221,7 @@ extern u32 __kvm_get_mdcr_el2(void);
 		typeof(s) *addr;					\
 		asm("adrp	%0, %1\n"				\
 		    "add	%0, %0, :lo12:%1\n"			\
-		    : "=r" (addr) : "S" (&s));				\
+		    : "=r" (addr) : SYM_CONSTRAINT (&s));		\
 		addr;							\
 	})
 
-- 
2.29.2

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] arm64: Work around broken GCC 4.9 handling of "S" constraint
  2020-12-17 11:11 [PATCH] arm64: Work around broken GCC 4.9 handling of "S" constraint Marc Zyngier
@ 2020-12-17 11:13 ` Ard Biesheuvel
  2020-12-17 14:13 ` Catalin Marinas
  1 sibling, 0 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2020-12-17 11:13 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: Android Kernel Team, Catalin Marinas, Will Deacon, kvmarm, Linux ARM

On Thu, 17 Dec 2020 at 12:11, Marc Zyngier <maz@kernel.org> wrote:
>
> GCC 4.9 seems to have a problem with the "S" asm constraint
> when the symbol lives in the same compilation unit, and pretends
> the constraint is impossible:
>
> $ cat x.c
> void *foo(void)
> {
>         static int x;
>         int *addr;
>         asm("adrp %0, %1" : "=r" (addr) : "S" (&x));
>         return addr;
> }
>
> $ ~/Work/gcc-linaro-aarch64-linux-gnu-4.9-2014.09_linux/bin/aarch64-linux-gnu-gcc -S -x c -O2 x.c
> x.c: In function ‘foo’:
> x.c:5:2: error: impossible constraint in ‘asm’
>   asm("adrp %0, %1" : "=r" (addr) : "S" (&x));
>   ^
>
> Boo. Following revisions of the compiler work just fine, though.
>
> We can fallback to the "i" constraint for GCC version prior to 5.0,
> which *seems* to do the right thing. Hopefully we will be able to
> remove this at some point, but in the meantime this gets us going.
>
> Signed-off-by: Marc Zyngier <maz@kernel.org>

Acked-by: Ard Biesheuvel <ardb@kernel.org>

> ---
> * From v1: Dropped the detection hack and rely on GCC_VERSION
>
>  arch/arm64/include/asm/kvm_asm.h | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h
> index 7ccf770c53d9..8a33d83ea843 100644
> --- a/arch/arm64/include/asm/kvm_asm.h
> +++ b/arch/arm64/include/asm/kvm_asm.h
> @@ -199,6 +199,12 @@ extern void __vgic_v3_init_lrs(void);
>
>  extern u32 __kvm_get_mdcr_el2(void);
>
> +#if defined(GCC_VERSION) && GCC_VERSION < 50000
> +#define SYM_CONSTRAINT "i"
> +#else
> +#define SYM_CONSTRAINT "S"
> +#endif
> +
>  /*
>   * Obtain the PC-relative address of a kernel symbol
>   * s: symbol
> @@ -215,7 +221,7 @@ extern u32 __kvm_get_mdcr_el2(void);
>                 typeof(s) *addr;                                        \
>                 asm("adrp       %0, %1\n"                               \
>                     "add        %0, %0, :lo12:%1\n"                     \
> -                   : "=r" (addr) : "S" (&s));                          \
> +                   : "=r" (addr) : SYM_CONSTRAINT (&s));               \
>                 addr;                                                   \
>         })
>
> --
> 2.29.2
>
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] arm64: Work around broken GCC 4.9 handling of "S" constraint
  2020-12-17 11:11 [PATCH] arm64: Work around broken GCC 4.9 handling of "S" constraint Marc Zyngier
  2020-12-17 11:13 ` Ard Biesheuvel
@ 2020-12-17 14:13 ` Catalin Marinas
  1 sibling, 0 replies; 3+ messages in thread
From: Catalin Marinas @ 2020-12-17 14:13 UTC (permalink / raw)
  To: Marc Zyngier, kvmarm, linux-arm-kernel
  Cc: kernel-team, Will Deacon, Ard Biesheuvel

On Thu, 17 Dec 2020 11:11:35 +0000, Marc Zyngier wrote:
> GCC 4.9 seems to have a problem with the "S" asm constraint
> when the symbol lives in the same compilation unit, and pretends
> the constraint is impossible:
> 
> $ cat x.c
> void *foo(void)
> {
> 	static int x;
> 	int *addr;
> 	asm("adrp %0, %1" : "=r" (addr) : "S" (&x));
> 	return addr;
> }
> 
> [...]

Applied to arm64 (for-next/fixes), thanks!

[1/1] arm64: Work around broken GCC 4.9 handling of "S" constraint
      https://git.kernel.org/arm64/c/9fd339a45be5

-- 
Catalin

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-17 14:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-17 11:11 [PATCH] arm64: Work around broken GCC 4.9 handling of "S" constraint Marc Zyngier
2020-12-17 11:13 ` Ard Biesheuvel
2020-12-17 14:13 ` Catalin Marinas

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