[PATCH v2 1/2] arm64: Add support for FEAT_HAFT

Catalin Marinas catalin.marinas at arm.com
Thu Sep 19 11:58:42 PDT 2024


On Thu, Aug 29, 2024 at 02:29:41PM +0800, Yicong Yang wrote:
> On 2024/8/21 0:18, Will Deacon wrote:
> > On Wed, Aug 14, 2024 at 05:23:32PM +0800, Yicong Yang wrote:
> >> +static void cpu_enable_haft(struct arm64_cpu_capabilities const *cap)
> >> +{
> >> +	sysreg_clear_set_s(SYS_TCR2_EL1, 0, TCR2_EL1x_HAFT);
> >> +	isb();
> >> +	local_flush_tlb_all();
> >> +}
> > 
> > As this isn't a per-TTBR enable, should we be initialising the kernel
> > table entries in TTBR1 as YOUNG to avoid potential races with the
> > hardware update? It looks like the bit is ignored on CPUs without HAFT,
> > so we can just do this unconditionally.
> 
> I'm a bit uncertain about the race here, is it because of the access fault
> or the inconsistent observation of table entries' AF status when enable the
> HAFT? and...

Linux doesn't use this mechanism on kernel page tables. The hardware
update of the access bit is atomic and, while it could race with a
non-atomic entry update, it shouldn't matter since no-one checks this
bit. However, I'd still set the AF bit when creating the kernel page
table, it saves the hardware from having to update them at run-time.

> > At the very least, we should be able to enable HAFT in __cpu_setup(),
> > like we do for HA.
> > 
> 
> ...if we enable this in __cpu_setup() as suggested we should have no race problem,
> since this is enabled before MMU on?

I suspect Will was referring to the actual page tables. But it makes
sense to enable this in __cpu_setup(), it saves us from having to do the
TLBI.

> > It's a bit of a pity that we can't handle this mismatch. After all,
> > access flag data is imprecise (unlike the dirty bit) and so you could
> > envisage a mechanism for falling back to leaf-level AF at runtime rather
> > than refusing to online a CPU.
> 
> ok. I suppose enable this should be ok if no users. So it's possible to just
> try to enable this at each CPU's startup, but don't advertise this feature to
> the upper users if not all the CPUs in the system support this. This won't
> affect leaf-level AF since leaf-level AF has its own detection and enabling
> and doesn't depend on HAFT.

Yes, I think this should work as long as arch_has_hw_pte_young() returns
false if one of the CPUs doesn't support it. I had a quick grep through
the kernel and all (most?) cases where the non-leaf pmd is checked or
the AF bit cleared are conditional on should_clear_pmd_young().
Personally I'd have introduced pmd_nonleaf_young() etc. functions in the
core code to make it more explicit. I guess, if we really want, we could
add a VM_WARN_ON if pmd_young() or pmdp_test_and_clear_young() is called
on a non-leaf pmd and FEAT_HAFT is disabled.

-- 
Catalin



More information about the linux-arm-kernel mailing list