Skip to content

Commit e0cc87f

Browse files
Wu Feiralfbaechle
authored andcommitted
MIPS: Shrink the size of tlb handler
By combining swapper_pg_dir and module_pg_dir, several if conditions can be eliminated from the tlb exception handler. The reason they can be combined is that, the effective virtual address of vmalloc returned is at the bottom, and of module_alloc returned is at the top. It also fixes the bug in vmalloc(), which happens when its return address is not covered by the first pgd. Signed-off-by: Wu Fei <at.wufei@gmail.com> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent a7bcb1a commit e0cc87f

4 files changed

Lines changed: 3 additions & 63 deletions

File tree

‎arch/mips/include/asm/pgtable-64.h‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@
109109

110110
#define VMALLOC_START MAP_BASE
111111
#define VMALLOC_END \
112-
(VMALLOC_START + PTRS_PER_PGD * PTRS_PER_PMD * PTRS_PER_PTE * PAGE_SIZE)
112+
(VMALLOC_START + \
113+
PTRS_PER_PGD * PTRS_PER_PMD * PTRS_PER_PTE * PAGE_SIZE - (1UL << 32))
113114
#if defined(CONFIG_MODULES) && defined(KBUILD_64BIT_SYM32) && \
114115
VMALLOC_START != CKSSEG
115116
/* Load modules into 32bit-compatible segment. */
116117
#define MODULE_START CKSSEG
117118
#define MODULE_END (FIXADDR_START-2*PAGE_SIZE)
118-
extern pgd_t module_pg_dir[PTRS_PER_PGD];
119119
#endif
120120

121121
#define pte_ERROR(e) \
@@ -188,12 +188,7 @@ static inline void pud_clear(pud_t *pudp)
188188
#define __pmd_offset(address) pmd_index(address)
189189

190190
/* to find an entry in a kernel page-table-directory */
191-
#ifdef MODULE_START
192-
#define pgd_offset_k(address) \
193-
((address) >= MODULE_START ? module_pg_dir : pgd_offset(&init_mm, 0UL))
194-
#else
195-
#define pgd_offset_k(address) pgd_offset(&init_mm, 0UL)
196-
#endif
191+
#define pgd_offset_k(address) pgd_offset(&init_mm, address)
197192

198193
#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
199194
#define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))

‎arch/mips/mm/init.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,6 @@ unsigned long pgd_current[NR_CPUS];
475475
*/
476476
pgd_t swapper_pg_dir[_PTRS_PER_PGD] __page_aligned(_PGD_ORDER);
477477
#ifdef CONFIG_64BIT
478-
#ifdef MODULE_START
479-
pgd_t module_pg_dir[PTRS_PER_PGD] __page_aligned(PGD_ORDER);
480-
#endif
481478
pmd_t invalid_pmd_table[PTRS_PER_PMD] __page_aligned(PMD_ORDER);
482479
#endif
483480
pte_t invalid_pte_table[PTRS_PER_PTE] __page_aligned(PTE_ORDER);

‎arch/mips/mm/pgtable-64.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ void __init pagetable_init(void)
5959

6060
/* Initialize the entire pgd. */
6161
pgd_init((unsigned long)swapper_pg_dir);
62-
#ifdef MODULE_START
63-
pgd_init((unsigned long)module_pg_dir);
64-
#endif
6562
pmd_init((unsigned long)invalid_pmd_table, (unsigned long)invalid_pte_table);
6663

6764
pgd_base = swapper_pg_dir;

‎arch/mips/mm/tlbex.c‎

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,7 @@ build_get_pmde64(u32 **p, struct uasm_label **l, struct uasm_reloc **r,
499499
* The vmalloc handling is not in the hotpath.
500500
*/
501501
uasm_i_dmfc0(p, tmp, C0_BADVADDR);
502-
#ifdef MODULE_START
503-
uasm_il_bltz(p, r, tmp, label_module_alloc);
504-
#else
505502
uasm_il_bltz(p, r, tmp, label_vmalloc);
506-
#endif
507503
/* No uasm_i_nop needed here, since the next insn doesn't touch TMP. */
508504

509505
#ifdef CONFIG_SMP
@@ -556,52 +552,7 @@ build_get_pgd_vmalloc64(u32 **p, struct uasm_label **l, struct uasm_reloc **r,
556552
{
557553
long swpd = (long)swapper_pg_dir;
558554

559-
#ifdef MODULE_START
560-
long modd = (long)module_pg_dir;
561-
562-
uasm_l_module_alloc(l, *p);
563-
/*
564-
* Assumption:
565-
* VMALLOC_START >= 0xc000000000000000UL
566-
* MODULE_START >= 0xe000000000000000UL
567-
*/
568-
UASM_i_SLL(p, ptr, bvaddr, 2);
569-
uasm_il_bgez(p, r, ptr, label_vmalloc);
570-
571-
if (uasm_in_compat_space_p(MODULE_START) &&
572-
!uasm_rel_lo(MODULE_START)) {
573-
uasm_i_lui(p, ptr, uasm_rel_hi(MODULE_START)); /* delay slot */
574-
} else {
575-
/* unlikely configuration */
576-
uasm_i_nop(p); /* delay slot */
577-
UASM_i_LA(p, ptr, MODULE_START);
578-
}
579-
uasm_i_dsubu(p, bvaddr, bvaddr, ptr);
580-
581-
if (uasm_in_compat_space_p(modd) && !uasm_rel_lo(modd)) {
582-
uasm_il_b(p, r, label_vmalloc_done);
583-
uasm_i_lui(p, ptr, uasm_rel_hi(modd));
584-
} else {
585-
UASM_i_LA_mostly(p, ptr, modd);
586-
uasm_il_b(p, r, label_vmalloc_done);
587-
if (uasm_in_compat_space_p(modd))
588-
uasm_i_addiu(p, ptr, ptr, uasm_rel_lo(modd));
589-
else
590-
uasm_i_daddiu(p, ptr, ptr, uasm_rel_lo(modd));
591-
}
592-
593555
uasm_l_vmalloc(l, *p);
594-
if (uasm_in_compat_space_p(MODULE_START) &&
595-
!uasm_rel_lo(MODULE_START) &&
596-
MODULE_START << 32 == VMALLOC_START)
597-
uasm_i_dsll32(p, ptr, ptr, 0); /* typical case */
598-
else
599-
UASM_i_LA(p, ptr, VMALLOC_START);
600-
#else
601-
uasm_l_vmalloc(l, *p);
602-
UASM_i_LA(p, ptr, VMALLOC_START);
603-
#endif
604-
uasm_i_dsubu(p, bvaddr, bvaddr, ptr);
605556

606557
if (uasm_in_compat_space_p(swpd) && !uasm_rel_lo(swpd)) {
607558
uasm_il_b(p, r, label_vmalloc_done);

0 commit comments

Comments
 (0)