@@ -70,7 +70,8 @@ static int table_usage(uint64_t *table, int adjustment)
70
70
int prev_count = xlat_use_count [i ];
71
71
int new_count = prev_count + adjustment ;
72
72
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 ) {
74
75
MMU_DEBUG ("table [%d]%p: usage %#x -> %#x\n" , i , table , prev_count , new_count );
75
76
}
76
77
@@ -191,6 +192,8 @@ static void debug_show_pte(uint64_t *pte, unsigned int level)
191
192
return ;
192
193
}
193
194
195
+ MMU_DEBUG ("0x%016llx " , * pte );
196
+
194
197
if (is_table_desc (* pte , level )) {
195
198
uint64_t * table = pte_desc_table (* pte );
196
199
@@ -396,7 +399,7 @@ static void del_mapping(uint64_t *table, uintptr_t virt, size_t size,
396
399
static uint64_t * dup_table (uint64_t * src_table , unsigned int level )
397
400
{
398
401
uint64_t * dst_table = new_table ();
399
- int i ;
402
+ int i , usage_count = 0 ;
400
403
401
404
if (!dst_table ) {
402
405
return NULL ;
@@ -423,9 +426,10 @@ static uint64_t *dup_table(uint64_t *src_table, unsigned int level)
423
426
inc_table_ref (pte_desc_table (dst_table [i ]));
424
427
}
425
428
if (!is_free_desc (dst_table [i ])) {
426
- table_usage ( dst_table , 1 ) ;
429
+ usage_count ++ ;
427
430
}
428
431
}
432
+ table_usage (dst_table , usage_count );
429
433
430
434
return dst_table ;
431
435
}
@@ -504,6 +508,7 @@ static int privatize_page_range(struct arm_mmu_ptables *dst_pt,
504
508
static void discard_table (uint64_t * table , unsigned int level )
505
509
{
506
510
unsigned int i ;
511
+ int free_count = 0 ;
507
512
508
513
for (i = 0U ; i < Ln_XLAT_NUM_ENTRIES ; i ++ ) {
509
514
if (is_table_desc (table [i ], level )) {
@@ -516,9 +521,10 @@ static void discard_table(uint64_t *table, unsigned int level)
516
521
}
517
522
if (!is_free_desc (table [i ])) {
518
523
table [i ] = 0U ;
519
- table_usage ( table , -1 ) ;
524
+ free_count ++ ;
520
525
}
521
526
}
527
+ table_usage (table , - free_count );
522
528
}
523
529
524
530
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)
978
984
enable_mmu_el1 (& kernel_ptables , flags );
979
985
}
980
986
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 )
982
988
{
983
989
#ifdef CONFIG_USERSPACE
984
990
sys_snode_t * node ;
@@ -992,7 +998,7 @@ static void sync_domains(uintptr_t virt, size_t size)
992
998
domain = CONTAINER_OF (node , struct arch_mem_domain , node );
993
999
domain_ptables = & domain -> ptables ;
994
1000
ret = globalize_page_range (domain_ptables , & kernel_ptables ,
995
- virt , size , "generic" );
1001
+ virt , size , name );
996
1002
if (ret ) {
997
1003
LOG_ERR ("globalize_page_range() returned %d" , ret );
998
1004
}
@@ -1074,7 +1080,7 @@ void arch_mem_map(void *virt, uintptr_t phys, size_t size, uint32_t flags)
1074
1080
} else {
1075
1081
uint32_t mem_flags = flags & K_MEM_CACHE_MASK ;
1076
1082
1077
- sync_domains ((uintptr_t )virt , size );
1083
+ sync_domains ((uintptr_t )virt , size , "mem_map" );
1078
1084
invalidate_tlb_all ();
1079
1085
1080
1086
switch (mem_flags ) {
@@ -1092,7 +1098,7 @@ void arch_mem_map(void *virt, uintptr_t phys, size_t size, uint32_t flags)
1092
1098
void arch_mem_unmap (void * addr , size_t size )
1093
1099
{
1094
1100
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" );
1096
1102
invalidate_tlb_all ();
1097
1103
}
1098
1104
@@ -1311,6 +1317,7 @@ static void z_arm64_swap_ptables(struct k_thread *incoming)
1311
1317
return ; /* Already the right tables */
1312
1318
}
1313
1319
1320
+ MMU_DEBUG ("TTBR0 switch from %#llx to %#llx\n" , curr_ttbr0 , new_ttbr0 );
1314
1321
z_arm64_set_ttbr0 (new_ttbr0 );
1315
1322
1316
1323
if (get_asid (curr_ttbr0 ) == get_asid (new_ttbr0 )) {
0 commit comments