arm64 kernel 6.14: why should set reserved_ttbr0 in cpu_do_switch_mm?

Hi all:

    cpu_do_switch_mm is used to change user address space in arm64. 

    According to the code in https://elixir.bootlin.com/linux/v6.14.6/source/arch/arm64/mm/context.c#L349, it does so in three major steps:

   (1) set ttbr0_el1 to reserved_ttbr0;

   (2) change ASID in ttbr1_el1;

   (3) set ttbr0_el1 to actual translation table base.

   So, what is the purpose of setting ttbr0_el1 to reserved_ttbr0?

   Thanks in advance!

Parents
  • I've asked an expert, and got this answer -

    Because we're using TCR.A1, we can't switch the ASID and TTBR0.BADDR atomically. reserved_ttbr0 contains no valid translations, so it doesn't matter if the CPU attempts to speculatively fetch anything from that with either ASID while we're updating TTBR1. Without that step, there would be the potential to cache a TLB entry from the old pagetable with the new ASID, or vice-versa.

Reply
  • I've asked an expert, and got this answer -

    Because we're using TCR.A1, we can't switch the ASID and TTBR0.BADDR atomically. reserved_ttbr0 contains no valid translations, so it doesn't matter if the CPU attempts to speculatively fetch anything from that with either ASID while we're updating TTBR1. Without that step, there would be the potential to cache a TLB entry from the old pagetable with the new ASID, or vice-versa.

Children
No data