From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 3/5] arm64: Create and use __tlbi_dsb() macros
Date: Thu, 12 Jan 2017 16:58:52 +0000 [thread overview]
Message-ID: <20170112165852.GH13843@arm.com> (raw)
In-Reply-To: <20170111144118.17062-3-cov@codeaurora.org>
Hi Christopher,
On Wed, Jan 11, 2017 at 09:41:16AM -0500, Christopher Covington wrote:
> This refactoring will allow an errata workaround that repeats tlbi dsb
> sequences to only change one location. This is not intended to change the
> generated assembly and comparison of before and after preprocessor output
> of arch/arm64/mm/mmu.c and vmlinux objdump shows no functional changes.
>
> Signed-off-by: Christopher Covington <cov@codeaurora.org>
> ---
> arch/arm64/include/asm/tlbflush.h | 104 +++++++++++++++++++++++++-------------
> 1 file changed, 69 insertions(+), 35 deletions(-)
>
> diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h
> index deab523..f28813c 100644
> --- a/arch/arm64/include/asm/tlbflush.h
> +++ b/arch/arm64/include/asm/tlbflush.h
> @@ -25,22 +25,69 @@
> #include <asm/cputype.h>
>
> /*
> - * Raw TLBI operations.
> + * Raw TLBI, DSB operations
> *
> - * Where necessary, use the __tlbi() macro to avoid asm()
> - * boilerplate. Drivers and most kernel code should use the TLB
> - * management routines in preference to the macro below.
> + * Where necessary, use __tlbi_*dsb() macros to avoid asm() boilerplate.
> + * Drivers and most kernel code should use the TLB management routines in
> + * preference to the macros below.
> *
> - * The macro can be used as __tlbi(op) or __tlbi(op, arg), depending
> - * on whether a particular TLBI operation takes an argument or
> - * not. The macros handles invoking the asm with or without the
> - * register argument as appropriate.
> + * The __tlbi_dsb() macro handles invoking the asm without any register
> + * argument, with a single register argument, and with start (included)
> + * and end (excluded) range of register arguments. For example:
> + *
> + * __tlbi_dsb(op, attr)
> + *
> + * tlbi op
> + * dsb attr
> + *
> + * __tlbi_dsb(op, attr, addr)
> + *
> + * mov %[addr], =addr
> + * tlbi op, %[addr]
> + * dsb attr
> + *
> + * __tlbi_range_dsb(op, attr, start, end)
> + *
> + * mov %[arg], =start
> + * mov %[end], =end
> + * for:
> + * tlbi op, %[addr]
> + * add %[addr], %[addr], #(1 << (PAGE_SHIFT - 12))
> + * cmp %[addr], %[end]
> + * b.ne for
> + * dsb attr
> */
> -#define __TLBI_0(op, arg) asm ("tlbi " #op)
> -#define __TLBI_1(op, arg) asm ("tlbi " #op ", %0" : : "r" (arg))
> -#define __TLBI_N(op, arg, n, ...) __TLBI_##n(op, arg)
>
> -#define __tlbi(op, ...) __TLBI_N(op, ##__VA_ARGS__, 1, 0)
> +#define __TLBI_FOR_0(ig0, ig1, ig2)
> +#define __TLBI_INSTR_0(op, ig1, ig2) "tlbi " #op
> +#define __TLBI_IO_0(ig0, ig1, ig2) : :
> +
> +#define __TLBI_FOR_1(ig0, ig1, ig2)
> +#define __TLBI_INSTR_1(op, ig0, ig1) "tlbi " #op ", %0"
> +#define __TLBI_IO_1(ig0, arg, ig1) : : "r" (arg)
> +
> +#define __TLBI_FOR_2(ig0, start, ig1) unsigned long addr; \
> + for (addr = start; addr < end; \
> + addr += 1 << (PAGE_SHIFT - 12))
> +#define __TLBI_INSTR_2(op, ig0, ig1) "tlbi " #op ", %0"
> +#define __TLBI_IO_2(ig0, ig1, ig2) : : "r" (addr)
> +
> +#define __TLBI_FOR_N(op, a1, a2, n, ...) __TLBI_FOR_##n(op, a1, a2)
> +#define __TLBI_INSTR_N(op, a1, a2, n, ...) __TLBI_INSTR_##n(op, a1, a2)
> +#define __TLBI_IO_N(op, a1, a2, n, ...) __TLBI_IO_##n(op, a1, a2)
> +
> +#define __TLBI_FOR(op, ...) __TLBI_FOR_N(op, ##__VA_ARGS__, 2, 1, 0)
> +#define __TLBI_INSTR(op, ...) __TLBI_INSTR_N(op, ##__VA_ARGS__, 2, 1, 0)
> +#define __TLBI_IO(op, ...) __TLBI_IO_N(op, ##__VA_ARGS__, 2, 1, 0)
> +
> +#define __tlbi_asm_dsb(as, op, attr, ...) do { \
> + __TLBI_FOR(op, ##__VA_ARGS__) \
> + asm (__TLBI_INSTR(op, ##__VA_ARGS__) \
> + __TLBI_IO(op, ##__VA_ARGS__)); \
> + asm volatile ( as "\ndsb " #attr "\n" \
> + : : : "memory"); } while (0)
> +
> +#define __tlbi_dsb(...) __tlbi_asm_dsb("", ##__VA_ARGS__)
I can't deny that this is cool, but ultimately it's completely unreadable.
What I was thinking you'd do would be make __tlbi expand to:
tlbi
dsb
tlbi
dsb
for Falkor, and:
tlbi
nop
nop
nop
for everybody else.
Wouldn't that localise this change sufficiently that you wouldn't need
to change all the callers and encode the looping in your cpp macros?
I realise you get an extra dsb in some places with that change, but I'd
like to see numbers for the impact of that on top of the workaround. If
it's an issue, then an alternative sequence would be:
tlbi
dsb
tlbi
and you'd rely on the existing dsb to complete that.
Having said that, I don't understand how your current loop code works
when the workaround is applied. AFAICT, you end up emitting something
like:
dsb ishst
for i in 0 to n
tlbi va+i
dsb
tlbi va+n
dsb
which looks wrong to me. Am I misreading something here?
Will
next prev parent reply other threads:[~2017-01-12 16:58 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-11 14:41 [PATCH v3 1/5] arm64: Define Falkor v1 CPU Christopher Covington
2017-01-11 14:41 ` [PATCH v3 2/5] arm64: Work around Falkor erratum 1003 Christopher Covington
2017-01-11 18:06 ` Catalin Marinas
2017-01-11 18:22 ` Marc Zyngier
2017-01-11 18:40 ` Mark Rutland
2017-01-12 15:45 ` Catalin Marinas
2017-01-12 16:12 ` Mark Rutland
2017-01-24 14:27 ` Christopher Covington
2017-01-12 15:55 ` Catalin Marinas
2017-01-12 16:07 ` Will Deacon
2017-01-11 18:33 ` Mark Rutland
2017-01-11 18:35 ` Timur Tabi
2017-01-11 18:37 ` Mark Rutland
2017-01-11 18:40 ` Timur Tabi
2017-01-11 18:45 ` Mark Rutland
2017-01-16 14:26 ` Christopher Covington
2017-01-11 18:50 ` Marc Zyngier
2017-01-12 9:59 ` Catalin Marinas
2017-01-24 14:54 ` Christopher Covington
2017-01-11 14:41 ` [PATCH v3 3/5] arm64: Create and use __tlbi_dsb() macros Christopher Covington
2017-01-12 16:58 ` Will Deacon [this message]
2017-01-13 15:12 ` Christopher Covington
2017-01-13 16:12 ` Will Deacon
2017-01-24 22:03 ` Christopher Covington
2017-01-11 14:41 ` [PATCH v3 4/5] arm64: Use __tlbi_dsb() macros in KVM code Christopher Covington
2017-01-11 14:41 ` [PATCH v3 5/5] arm64: Work around Falkor erratum 1009 Christopher Covington
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=20170112165852.GH13843@arm.com \
--to=will.deacon@arm.com \
--cc=linux-arm-kernel@lists.infradead.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).