From: Will Deacon <will@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Ard Biesheuvel <ardb@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Ryan Roberts <ryan.roberts@arm.com>,
Mark Rutland <mark.rutland@arm.com>,
Oliver Upton <oliver.upton@linux.dev>,
Marc Zyngier <maz@kernel.org>
Subject: Re: [PATCH 10/10] arm64: mm: Re-implement the __flush_tlb_range_op macro in C
Date: Sun, 13 Jul 2025 14:35:40 +0100 [thread overview]
Message-ID: <aHO2LAoDpciZftP_@willie-the-truck> (raw)
In-Reply-To: <CAHk-=wijmAO=-dWc8HUMdUbkdGqgNtiO6mntAcTekWc5qN3YjQ@mail.gmail.com>
On Fri, Jul 11, 2025 at 11:16:32AM -0700, Linus Torvalds wrote:
> On Fri, 11 Jul 2025 at 09:18, Will Deacon <will@kernel.org> wrote:
> >
> > The __flush_tlb_range_op() macro is horrible and has been a previous
> > source of bugs thanks to multiple expansions of its arguments (see
> > commit f7edb07ad7c6 ("Fix mmu notifiers for range-based invalidates")).
> >
> > Rewrite the thing in C.
>
> So I do think this is better than the old case, but I think you could
> go one step further...
>
> > +static __always_inline void __flush_tlb_range_op(const enum tlbi_op op,
> > + u64 start, size_t pages,
> > + u64 stride, u16 asid,
> > + u32 level, bool lpa2)
>
> If you replaced that "enum tlbi_op op" with two function pointers
> instead (for "the invalidate range" and "invalidate one" cases
> respectively), I think you could make this code much more obvious.
>
> And exactly like how you depend on that 'op' value being
> constant-folded because all the different levels are inline functions,
> the same thing ends up happening with function pointers where inlining
> will result in a constant function pointer becoming just a static call
> (and in turn inlined as well).
So I don't _strictly_ rely on the constant-folding and replacing that
BUILD_BUG_ON() with a BUG_ON() would still give functionally correct
code if inlining didn't occur. I just much preferred catching a wonky
TLBI op at compile-time, which is why I ended up with this but I hadn't
considered that this would allow us to inline indirect function calls.
> And then the actual *callers* would use the "look up op" thing, but I
> suspect that in many cases those could then be in turn also simplified
> to not use that op-number at all, but just end up using the op-name.
Right, I think we'd drop the enum entirely if we went down this route.
> I didn't try to actually create that series - and I think you'd want
> to do it in multiple steps just to make each individual step small and
> obvious - but I think it would end up looking nicer.
I'll have a play...
Will
next prev parent reply other threads:[~2025-07-13 13:40 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-11 16:17 [PATCH 00/10] arm64: Replace TLB invalidation preprocessor macros with C functions Will Deacon
2025-07-11 16:17 ` [PATCH 01/10] arm64: mm: Introduce a C wrapper for by-level TLB invalidation helpers Will Deacon
2025-07-14 8:38 ` Ryan Roberts
2025-07-11 16:17 ` [PATCH 02/10] arm64: mm: Introduce a C wrapper for by-range " Will Deacon
2025-07-14 8:26 ` Ryan Roberts
2025-07-11 16:17 ` [PATCH 03/10] arm64: mm: Implicitly invalidate user ASID based on TLBI operation Will Deacon
2025-07-14 8:44 ` Ryan Roberts
2025-07-14 9:46 ` Ryan Roberts
2025-07-11 16:17 ` [PATCH 04/10] arm64: mm: Remove unused 'tlbi_user' argument from __flush_tlb_range_op() Will Deacon
2025-07-11 16:17 ` [PATCH 05/10] arm64: mm: Re-implement the __tlbi_level macro in C Will Deacon
2025-07-14 9:02 ` Ryan Roberts
2025-07-11 16:17 ` [PATCH 06/10] arm64: mm: Simplify __TLBI_RANGE_NUM() macro Will Deacon
2025-07-14 9:06 ` Ryan Roberts
2025-07-15 5:13 ` Dev Jain
2025-07-11 16:17 ` [PATCH 07/10] arm64: mm: Push __TLBI_VADDR() into __tlbi_level() Will Deacon
2025-07-11 16:17 ` [PATCH 08/10] arm64: mm: Inline __TLBI_VADDR_RANGE() into __tlbi_range() Will Deacon
2025-07-14 9:17 ` Ryan Roberts
2025-07-11 16:17 ` [PATCH 09/10] arm64: mm: Simplify __flush_tlb_range_limit_excess() Will Deacon
2025-07-14 9:30 ` Ryan Roberts
2025-07-15 5:38 ` Dev Jain
2025-07-11 16:17 ` [PATCH 10/10] arm64: mm: Re-implement the __flush_tlb_range_op macro in C Will Deacon
2025-07-11 18:16 ` Linus Torvalds
2025-07-13 13:35 ` Will Deacon [this message]
2025-07-14 9:44 ` Ryan Roberts
2025-12-10 12:29 ` [PATCH 00/10] arm64: Replace TLB invalidation preprocessor macros with C functions Ryan Roberts
2025-12-12 12:12 ` Ryan Roberts
2025-12-12 20:13 ` Will Deacon
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=aHO2LAoDpciZftP_@willie-the-truck \
--to=will@kernel.org \
--cc=ardb@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=ryan.roberts@arm.com \
--cc=torvalds@linux-foundation.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