Skip to content

Commit 82ca151

Browse files
ardbiesheuvelctmarinas
authored andcommitted
arm64: mmu: Make __cpu_replace_ttbr1() out of line
__cpu_replace_ttbr1() is a static inline, and so it gets instantiated wherever it is used. This is not really necessary, as it is never called on a hot path. It also has the unfortunate side effect that the symbol idmap_cpu_replace_ttbr1 may never be referenced from kCFI enabled C code, and this means the type id symbol may not exist either. This will result in a build error once we start referring to this symbol from asm code as well. (Note that this problem only occurs when CnP, KAsan and suspend/resume are all disabled in the Kconfig but that is a valid config, if unusual). So let's just move it out of line so all callers will share the same implementation, which will reference idmap_cpu_replace_ttbr1 unconditionally. Signed-off-by: Ard Biesheuvel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 293d865 commit 82ca151

File tree

2 files changed

+33
-31
lines changed

2 files changed

+33
-31
lines changed

arch/arm64/include/asm/mmu_context.h

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -148,37 +148,7 @@ static inline void cpu_install_ttbr0(phys_addr_t ttbr0, unsigned long t0sz)
148148
isb();
149149
}
150150

151-
/*
152-
* Atomically replaces the active TTBR1_EL1 PGD with a new VA-compatible PGD,
153-
* avoiding the possibility of conflicting TLB entries being allocated.
154-
*/
155-
static inline void __cpu_replace_ttbr1(pgd_t *pgdp, pgd_t *idmap, bool cnp)
156-
{
157-
typedef void (ttbr_replace_func)(phys_addr_t);
158-
extern ttbr_replace_func idmap_cpu_replace_ttbr1;
159-
ttbr_replace_func *replace_phys;
160-
unsigned long daif;
161-
162-
/* phys_to_ttbr() zeros lower 2 bits of ttbr with 52-bit PA */
163-
phys_addr_t ttbr1 = phys_to_ttbr(virt_to_phys(pgdp));
164-
165-
if (cnp)
166-
ttbr1 |= TTBR_CNP_BIT;
167-
168-
replace_phys = (void *)__pa_symbol(idmap_cpu_replace_ttbr1);
169-
170-
__cpu_install_idmap(idmap);
171-
172-
/*
173-
* We really don't want to take *any* exceptions while TTBR1 is
174-
* in the process of being replaced so mask everything.
175-
*/
176-
daif = local_daif_save();
177-
replace_phys(ttbr1);
178-
local_daif_restore(daif);
179-
180-
cpu_uninstall_idmap();
181-
}
151+
void __cpu_replace_ttbr1(pgd_t *pgdp, pgd_t *idmap, bool cnp);
182152

183153
static inline void cpu_enable_swapper_cnp(void)
184154
{

arch/arm64/mm/mmu.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,3 +1486,35 @@ void ptep_modify_prot_commit(struct vm_area_struct *vma, unsigned long addr, pte
14861486
{
14871487
set_pte_at(vma->vm_mm, addr, ptep, pte);
14881488
}
1489+
1490+
/*
1491+
* Atomically replaces the active TTBR1_EL1 PGD with a new VA-compatible PGD,
1492+
* avoiding the possibility of conflicting TLB entries being allocated.
1493+
*/
1494+
void __cpu_replace_ttbr1(pgd_t *pgdp, pgd_t *idmap, bool cnp)
1495+
{
1496+
typedef void (ttbr_replace_func)(phys_addr_t);
1497+
extern ttbr_replace_func idmap_cpu_replace_ttbr1;
1498+
ttbr_replace_func *replace_phys;
1499+
unsigned long daif;
1500+
1501+
/* phys_to_ttbr() zeros lower 2 bits of ttbr with 52-bit PA */
1502+
phys_addr_t ttbr1 = phys_to_ttbr(virt_to_phys(pgdp));
1503+
1504+
if (cnp)
1505+
ttbr1 |= TTBR_CNP_BIT;
1506+
1507+
replace_phys = (void *)__pa_symbol(idmap_cpu_replace_ttbr1);
1508+
1509+
__cpu_install_idmap(idmap);
1510+
1511+
/*
1512+
* We really don't want to take *any* exceptions while TTBR1 is
1513+
* in the process of being replaced so mask everything.
1514+
*/
1515+
daif = local_daif_save();
1516+
replace_phys(ttbr1);
1517+
local_daif_restore(daif);
1518+
1519+
cpu_uninstall_idmap();
1520+
}

0 commit comments

Comments
 (0)