From: Mark Rutland <mark.rutland@arm.com>
To: Kees Cook <keescook@chromium.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Nick Desaulniers <ndesaulniers@google.com>,
linux-kernel@vger.kernel.org, Will Deacon <will.deacon@arm.com>,
Yury Norov <ynorov@caviumnetworks.com>,
Sami Tolvanen <samitolvanen@google.com>,
Alex Matveev <alxmtvv@gmail.com>,
Matthias Kaehlcke <mka@chromium.org>,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v3] arm64: sysreg: make mrs_s and msr_s macros work with Clang and LTO
Date: Mon, 15 Apr 2019 18:06:08 +0100 [thread overview]
Message-ID: <20190415170604.GA44415@lakrids.cambridge.arm.com> (raw)
In-Reply-To: <20190415143821.GA46880@beast>
On Mon, Apr 15, 2019 at 07:38:21AM -0700, Kees Cook wrote:
> From: Alex Matveev <alxmtvv@gmail.com>
>
> Clang's integrated assembler does not allow assembly macros defined
> in one inline asm block using the .macro directive to be used across
> separate asm blocks. LLVM developers consider this a feature and not a
> bug, recommending code refactoring:
>
> https://bugs.llvm.org/show_bug.cgi?id=19749
>
> As binutils doesn't allow macros to be redefined, this change uses
> UNDEFINE_MRS_S and UNDEFINE_MSR_S to define corresponding macros
> in-place and workaround gcc and clang limitations on redefining macros
> across different assembler blocks.
>
> Specifically, the current state after preprocessing looks like this:
>
> asm volatile(".macro mXX_s ... .endm");
> void f()
> {
> asm volatile("mXX_s a, b");
> }
>
> With GCC, it gives macro redefinition error because sysreg.h is included
> in multiple source files, and assembler code for all of them is later
> combined for LTO (I've seen an intermediate file with hundreds of
> identical definitions).
>
> With clang, it gives macro undefined error because clang doesn't allow
> sharing macros between inline asm statements.
>
> I also seem to remember catching another sort of undefined error with
> GCC due to reordering of macro definition asm statement and generated
> asm code for function that uses the macro.
>
> The solution with defining and undefining for each use, while certainly
> not elegant, satisfies both GCC and clang, LTO and non-LTO.
>
> Signed-off-by: Alex Matveev <alxmtvv@gmail.com>
> Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
> Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> v3: split out patch as stand-alone, added more uses in irqflags,
> updated commit log, based on discussion in
> https://lore.kernel.org/patchwork/patch/851580/
> ---
> arch/arm64/include/asm/irqflags.h | 12 +++++--
> arch/arm64/include/asm/kvm_hyp.h | 8 +++--
> arch/arm64/include/asm/sysreg.h | 55 +++++++++++++++++++++----------
> 3 files changed, 53 insertions(+), 22 deletions(-)
>
> diff --git a/arch/arm64/include/asm/irqflags.h b/arch/arm64/include/asm/irqflags.h
> index 43d8366c1e87..06d3987d1546 100644
> --- a/arch/arm64/include/asm/irqflags.h
> +++ b/arch/arm64/include/asm/irqflags.h
> @@ -43,7 +43,9 @@ static inline void arch_local_irq_enable(void)
> asm volatile(ALTERNATIVE(
> "msr daifclr, #2 // arch_local_irq_enable\n"
> "nop",
> + DEFINE_MSR_S
> "msr_s " __stringify(SYS_ICC_PMR_EL1) ",%0\n"
> + UNDEFINE_MSR_S
If we do need this, can we wrap this in a larger CPP macro that does the
whole sequence of defining, using, and undefining the asm macros?
It would be nice if we could simply rely on a more recent binutils these
days, which supports the generic S<op0>_<op1>_<cn>_<Cm>_<op2> sysreg
definition. That would mean we could get rid of the whole msr_s/mrs_s
hack by turning that into a CPP macro which built that name.
It looks like binutils has been able to do that since September 2014...
Are folk using toolchains older than that to compile kernels?
Thanks,
Mark.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-04-15 17:06 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-15 14:38 [PATCH v3] arm64: sysreg: make mrs_s and msr_s macros work with Clang and LTO Kees Cook
2019-04-15 17:06 ` Mark Rutland [this message]
2019-04-15 17:22 ` Nick Desaulniers
2019-04-16 17:08 ` Mark Rutland
2019-04-16 17:34 ` Nick Desaulniers
2019-04-17 4:02 ` Kees Cook
2019-04-22 17:44 ` Nick Desaulniers
2019-04-23 14:12 ` Mark Rutland
2019-04-23 18:15 ` Nick Desaulniers
2019-04-23 18:24 ` Kees Cook
2019-04-23 18:39 ` Arnd Bergmann
2019-04-16 17:18 ` Mark Rutland
2019-04-23 22:55 ` Kees Cook
2019-04-23 22:57 ` Ard Biesheuvel
2019-04-23 22:59 ` Nick Desaulniers
2019-04-23 23:09 ` Kees Cook
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=20190415170604.GA44415@lakrids.cambridge.arm.com \
--to=mark.rutland@arm.com \
--cc=alxmtvv@gmail.com \
--cc=ard.biesheuvel@linaro.org \
--cc=catalin.marinas@arm.com \
--cc=keescook@chromium.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mka@chromium.org \
--cc=ndesaulniers@google.com \
--cc=samitolvanen@google.com \
--cc=will.deacon@arm.com \
--cc=ynorov@caviumnetworks.com \
/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).