Skip to content

Commit a8bf2fc

Browse files
brooniewilldeacon
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 32d495b commit a8bf2fc

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

arch/arm64/include/asm/mmu_context.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <asm/cacheflush.h>
2020
#include <asm/cpufeature.h>
21+
#include <asm/daifflags.h>
2122
#include <asm/proc-fns.h>
2223
#include <asm-generic/mm_hooks.h>
2324
#include <asm/cputype.h>
@@ -152,6 +153,7 @@ static inline void cpu_replace_ttbr1(pgd_t *pgdp, pgd_t *idmap)
152153
typedef void (ttbr_replace_func)(phys_addr_t);
153154
extern ttbr_replace_func idmap_cpu_replace_ttbr1;
154155
ttbr_replace_func *replace_phys;
156+
unsigned long daif;
155157

156158
/* phys_to_ttbr() zeros lower 2 bits of ttbr with 52-bit PA */
157159
phys_addr_t ttbr1 = phys_to_ttbr(virt_to_phys(pgdp));
@@ -171,7 +173,15 @@ static inline void cpu_replace_ttbr1(pgd_t *pgdp, pgd_t *idmap)
171173
replace_phys = (void *)__pa_symbol(idmap_cpu_replace_ttbr1);
172174

173175
__cpu_install_idmap(idmap);
176+
177+
/*
178+
* We really don't want to take *any* exceptions while TTBR1 is
179+
* in the process of being replaced so mask everything.
180+
*/
181+
daif = local_daif_save();
174182
replace_phys(ttbr1);
183+
local_daif_restore(daif);
184+
175185
cpu_uninstall_idmap();
176186
}
177187

arch/arm64/mm/proc.S

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,12 @@ SYM_FUNC_END(cpu_do_resume)
189189
* called by anything else. It can only be executed from a TTBR0 mapping.
190190
*/
191191
SYM_TYPED_FUNC_START(idmap_cpu_replace_ttbr1)
192-
save_and_disable_daif flags=x2
193-
194192
__idmap_cpu_set_reserved_ttbr1 x1, x3
195193

196194
offset_ttbr1 x0, x3
197195
msr ttbr1_el1, x0
198196
isb
199197

200-
restore_daif x2
201-
202198
ret
203199
SYM_FUNC_END(idmap_cpu_replace_ttbr1)
204200
.popsection

0 commit comments

Comments
 (0)