Message ID | 20220216090300.9424-3-roger.pau@citrix.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | retpoline: add clang support + Kconfig selectable | expand |
On 16.02.2022 10:02, Roger Pau Monne wrote: > Detect whether the compiler supports clang retpoline option and enable > by default if available, just like it's done for gcc. > > Note clang already disables jump tables when retpoline is enabled, so > there's no need to also pass the fno-jump-tables parameter. That's one of the secondary gcc side arrangements. What about the other (-mindirect-branch-register)? > Reported-by: Jan Beulich <JBeulich@suse.com> That's Andrew, not me? Jan > Signed-off-by: Roger Pau Monné <roger.pau@citrix.com> > --- > xen/arch/x86/Kconfig | 5 ++++- > xen/arch/x86/arch.mk | 3 +++ > 2 files changed, 7 insertions(+), 1 deletion(-) > > diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig > index 2cd713724f..fe00b4598b 100644 > --- a/xen/arch/x86/Kconfig > +++ b/xen/arch/x86/Kconfig > @@ -35,8 +35,11 @@ config ARCH_DEFCONFIG > config GCC_INDIRECT_THUNK > def_bool $(cc-option,-mindirect-branch-register) > > +config CLANG_INDIRECT_THUNK > + def_bool $(cc-option,-mretpoline-external-thunk) > + > config INDIRECT_THUNK > - depends on GCC_INDIRECT_THUNK > + depends on GCC_INDIRECT_THUNK || CLANG_INDIRECT_THUNK > def_bool y > > config HAS_AS_CET_SS > diff --git a/xen/arch/x86/arch.mk b/xen/arch/x86/arch.mk > index 2da4bdb1ed..f2aa2a515f 100644 > --- a/xen/arch/x86/arch.mk > +++ b/xen/arch/x86/arch.mk > @@ -47,6 +47,9 @@ CFLAGS-$(CONFIG_GCC_INDIRECT_THUNK) += -mindirect-branch=thunk-extern > CFLAGS-$(CONFIG_GCC_INDIRECT_THUNK) += -mindirect-branch-register > CFLAGS-$(CONFIG_GCC_INDIRECT_THUNK) += -fno-jump-tables > > +# Enable clang retpoline support if available. > +CFLAGS-$(CONFIG_CLANG_INDIRECT_THUNK) += -mretpoline-external-thunk > + > # If supported by the compiler, reduce stack alignment to 8 bytes. But allow > # this to be overridden elsewhere. > $(call cc-option-add,CFLAGS_stack_boundary,CC,-mpreferred-stack-boundary=3)
On Wed, Feb 16, 2022 at 10:47:52AM +0100, Jan Beulich wrote: > On 16.02.2022 10:02, Roger Pau Monne wrote: > > Detect whether the compiler supports clang retpoline option and enable > > by default if available, just like it's done for gcc. > > > > Note clang already disables jump tables when retpoline is enabled, so > > there's no need to also pass the fno-jump-tables parameter. > > That's one of the secondary gcc side arrangements. What about the other > (-mindirect-branch-register)? clang already passes the return address on a register always on amd64 so that's not needed either. I can add a comment like I've done for no-jump-tables. > > Reported-by: Jan Beulich <JBeulich@suse.com> > > That's Andrew, not me? Ops, sorry, I got that mixed up then. Thanks, Roger.
On 16.02.2022 12:26, Roger Pau Monné wrote: > On Wed, Feb 16, 2022 at 10:47:52AM +0100, Jan Beulich wrote: >> On 16.02.2022 10:02, Roger Pau Monne wrote: >>> Detect whether the compiler supports clang retpoline option and enable >>> by default if available, just like it's done for gcc. >>> >>> Note clang already disables jump tables when retpoline is enabled, so >>> there's no need to also pass the fno-jump-tables parameter. >> >> That's one of the secondary gcc side arrangements. What about the other >> (-mindirect-branch-register)? > > clang already passes the return address on a register always on amd64 > so that's not needed either. I can add a comment like I've done for > no-jump-tables. > >>> Reported-by: Jan Beulich <JBeulich@suse.com> >> >> That's Andrew, not me? > > Ops, sorry, I got that mixed up then. With the adjustments then Reviewed-by: Jan Beulich <jbeulich@suse.com>
diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 2cd713724f..fe00b4598b 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -35,8 +35,11 @@ config ARCH_DEFCONFIG config GCC_INDIRECT_THUNK def_bool $(cc-option,-mindirect-branch-register) +config CLANG_INDIRECT_THUNK + def_bool $(cc-option,-mretpoline-external-thunk) + config INDIRECT_THUNK - depends on GCC_INDIRECT_THUNK + depends on GCC_INDIRECT_THUNK || CLANG_INDIRECT_THUNK def_bool y config HAS_AS_CET_SS diff --git a/xen/arch/x86/arch.mk b/xen/arch/x86/arch.mk index 2da4bdb1ed..f2aa2a515f 100644 --- a/xen/arch/x86/arch.mk +++ b/xen/arch/x86/arch.mk @@ -47,6 +47,9 @@ CFLAGS-$(CONFIG_GCC_INDIRECT_THUNK) += -mindirect-branch=thunk-extern CFLAGS-$(CONFIG_GCC_INDIRECT_THUNK) += -mindirect-branch-register CFLAGS-$(CONFIG_GCC_INDIRECT_THUNK) += -fno-jump-tables +# Enable clang retpoline support if available. +CFLAGS-$(CONFIG_CLANG_INDIRECT_THUNK) += -mretpoline-external-thunk + # If supported by the compiler, reduce stack alignment to 8 bytes. But allow # this to be overridden elsewhere. $(call cc-option-add,CFLAGS_stack_boundary,CC,-mpreferred-stack-boundary=3)
Detect whether the compiler supports clang retpoline option and enable by default if available, just like it's done for gcc. Note clang already disables jump tables when retpoline is enabled, so there's no need to also pass the fno-jump-tables parameter. Reported-by: Jan Beulich <JBeulich@suse.com> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com> --- xen/arch/x86/Kconfig | 5 ++++- xen/arch/x86/arch.mk | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-)