Skip to content

Commit b5be646

Browse files
Nicolas Pitrenashif
authored andcommitted
arch/arm64/mmu: improve debugging output
Rationalize the debug log to make it easier to use. Signed-off-by: Nicolas Pitre <[email protected]>
1 parent d7e9ea0 commit b5be646

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

arch/arm64/core/mmu.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ static int table_usage(uint64_t *table, int adjustment)
7070
int prev_count = xlat_use_count[i];
7171
int new_count = prev_count + adjustment;
7272

73-
if (IS_ENABLED(DUMP_PTE) || new_count == 0) {
73+
/* be reasonable not to always create a debug flood */
74+
if ((IS_ENABLED(DUMP_PTE) && adjustment != 0) || new_count == 0) {
7475
MMU_DEBUG("table [%d]%p: usage %#x -> %#x\n", i, table, prev_count, new_count);
7576
}
7677

@@ -191,6 +192,8 @@ static void debug_show_pte(uint64_t *pte, unsigned int level)
191192
return;
192193
}
193194

195+
MMU_DEBUG("0x%016llx ", *pte);
196+
194197
if (is_table_desc(*pte, level)) {
195198
uint64_t *table = pte_desc_table(*pte);
196199

@@ -396,7 +399,7 @@ static void del_mapping(uint64_t *table, uintptr_t virt, size_t size,
396399
static uint64_t *dup_table(uint64_t *src_table, unsigned int level)
397400
{
398401
uint64_t *dst_table = new_table();
399-
int i;
402+
int i, usage_count = 0;
400403

401404
if (!dst_table) {
402405
return NULL;
@@ -423,9 +426,10 @@ static uint64_t *dup_table(uint64_t *src_table, unsigned int level)
423426
inc_table_ref(pte_desc_table(dst_table[i]));
424427
}
425428
if (!is_free_desc(dst_table[i])) {
426-
table_usage(dst_table, 1);
429+
usage_count++;
427430
}
428431
}
432+
table_usage(dst_table, usage_count);
429433

430434
return dst_table;
431435
}
@@ -504,6 +508,7 @@ static int privatize_page_range(struct arm_mmu_ptables *dst_pt,
504508
static void discard_table(uint64_t *table, unsigned int level)
505509
{
506510
unsigned int i;
511+
int free_count = 0;
507512

508513
for (i = 0U; i < Ln_XLAT_NUM_ENTRIES; i++) {
509514
if (is_table_desc(table[i], level)) {
@@ -516,9 +521,10 @@ static void discard_table(uint64_t *table, unsigned int level)
516521
}
517522
if (!is_free_desc(table[i])) {
518523
table[i] = 0U;
519-
table_usage(table, -1);
524+
free_count++;
520525
}
521526
}
527+
table_usage(table, -free_count);
522528
}
523529

524530
static int globalize_table(uint64_t *dst_table, uint64_t *src_table,
@@ -978,7 +984,7 @@ void z_arm64_mm_init(bool is_primary_core)
978984
enable_mmu_el1(&kernel_ptables, flags);
979985
}
980986

981-
static void sync_domains(uintptr_t virt, size_t size)
987+
static void sync_domains(uintptr_t virt, size_t size, const char *name)
982988
{
983989
#ifdef CONFIG_USERSPACE
984990
sys_snode_t *node;
@@ -992,7 +998,7 @@ static void sync_domains(uintptr_t virt, size_t size)
992998
domain = CONTAINER_OF(node, struct arch_mem_domain, node);
993999
domain_ptables = &domain->ptables;
9941000
ret = globalize_page_range(domain_ptables, &kernel_ptables,
995-
virt, size, "generic");
1001+
virt, size, name);
9961002
if (ret) {
9971003
LOG_ERR("globalize_page_range() returned %d", ret);
9981004
}
@@ -1074,7 +1080,7 @@ void arch_mem_map(void *virt, uintptr_t phys, size_t size, uint32_t flags)
10741080
} else {
10751081
uint32_t mem_flags = flags & K_MEM_CACHE_MASK;
10761082

1077-
sync_domains((uintptr_t)virt, size);
1083+
sync_domains((uintptr_t)virt, size, "mem_map");
10781084
invalidate_tlb_all();
10791085

10801086
switch (mem_flags) {
@@ -1092,7 +1098,7 @@ void arch_mem_map(void *virt, uintptr_t phys, size_t size, uint32_t flags)
10921098
void arch_mem_unmap(void *addr, size_t size)
10931099
{
10941100
remove_map(&kernel_ptables, "generic", (uintptr_t)addr, size);
1095-
sync_domains((uintptr_t)addr, size);
1101+
sync_domains((uintptr_t)addr, size, "mem_unmap");
10961102
invalidate_tlb_all();
10971103
}
10981104

@@ -1311,6 +1317,7 @@ static void z_arm64_swap_ptables(struct k_thread *incoming)
13111317
return; /* Already the right tables */
13121318
}
13131319

1320+
MMU_DEBUG("TTBR0 switch from %#llx to %#llx\n", curr_ttbr0, new_ttbr0);
13141321
z_arm64_set_ttbr0(new_ttbr0);
13151322

13161323
if (get_asid(curr_ttbr0) == get_asid(new_ttbr0)) {

0 commit comments

Comments
 (0)