Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arm64/kpti: Move DAIF masking to C code

We really don't want to take an exception while replacing TTBR1 so we mask
DAIF during the actual update. Currently this is done in the assembly
function idmap_cpu_replace_ttbr1() but it could equally be done in the only
caller of that function, cpu_replace_ttbr1(). This simplifies the assembly
code slightly and means that when working with the code around masking DAIF
flags there is one less piece of assembly code which needs to be considered.

While we're at it add a comment which makes explicit why we are masking
DAIF in this code.

There should be no functional effect.

Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20221123180209.634650-2-broonie@kernel.org
Signed-off-by: Will Deacon <will@kernel.org>

authored by

Mark Brown and committed by
Will Deacon
a8bf2fc4 32d495b0

+10 -4
+10
arch/arm64/include/asm/mmu_context.h
··· 18 18 19 19 #include <asm/cacheflush.h> 20 20 #include <asm/cpufeature.h> 21 + #include <asm/daifflags.h> 21 22 #include <asm/proc-fns.h> 22 23 #include <asm-generic/mm_hooks.h> 23 24 #include <asm/cputype.h> ··· 153 152 typedef void (ttbr_replace_func)(phys_addr_t); 154 153 extern ttbr_replace_func idmap_cpu_replace_ttbr1; 155 154 ttbr_replace_func *replace_phys; 155 + unsigned long daif; 156 156 157 157 /* phys_to_ttbr() zeros lower 2 bits of ttbr with 52-bit PA */ 158 158 phys_addr_t ttbr1 = phys_to_ttbr(virt_to_phys(pgdp)); ··· 173 171 replace_phys = (void *)__pa_symbol(idmap_cpu_replace_ttbr1); 174 172 175 173 __cpu_install_idmap(idmap); 174 + 175 + /* 176 + * We really don't want to take *any* exceptions while TTBR1 is 177 + * in the process of being replaced so mask everything. 178 + */ 179 + daif = local_daif_save(); 176 180 replace_phys(ttbr1); 181 + local_daif_restore(daif); 182 + 177 183 cpu_uninstall_idmap(); 178 184 } 179 185
-4
arch/arm64/mm/proc.S
··· 189 189 * called by anything else. It can only be executed from a TTBR0 mapping. 190 190 */ 191 191 SYM_TYPED_FUNC_START(idmap_cpu_replace_ttbr1) 192 - save_and_disable_daif flags=x2 193 - 194 192 __idmap_cpu_set_reserved_ttbr1 x1, x3 195 193 196 194 offset_ttbr1 x0, x3 197 195 msr ttbr1_el1, x0 198 196 isb 199 - 200 - restore_daif x2 201 197 202 198 ret 203 199 SYM_FUNC_END(idmap_cpu_replace_ttbr1)