MIPS: Build uasm-generated code only once to avoid CPU Hotplug problem
RFC PATCH 1/1 MIPS: Build uasm-generated code only once to avoid CPU Hotplug problem
Currently, clear_page()/copy_page() are generated by Micro-assembler dynamically. But they are unavailable until uasm_resolve_relocs() has finished because jump labels are illegal before that. Since these functions are shared by every CPU, we only call build_clear_page()/ build_copy_page() on CPU#0 at boot time. Without this patch, programs will get random memory corruption (segmentation fault, bus error, etc.) while CPU Hotplug (e.g. one CPU is using clear_page() while another is generating it in cpu_cache_init()).
For similar reasons we modify build_tlb_refill_handler()'s invocation.
--- arch/mips/mm/c-octeon.c | 6 ++++-- arch/mips/mm/c-r3k.c | 6 ++++-- arch/mips/mm/c-r4k.c | 6 ++++-- arch/mips/mm/c-tx39.c | 6 ++++-- arch/mips/mm/tlb-r3k.c | 3 ++- arch/mips/mm/tlb-r4k.c | 3 ++- arch/mips/mm/tlb-r8k.c | 3 ++- arch/mips/sgi-ip27/ip27-init.c | 3 ++- 8 files changed, 24 insertions(+), 12 deletions(-)
arch/mips/mm/c-octeon.c +4 -2
@@ -280,8 +280,10 @@ void __cpuinit octeon_cache_init(void) __flush_kernel_vmap_range = octeon_flush_kernel_vmap_range; -build_clear_page (); -build_copy_page (); +if (smp_processor_id () ==0 ) { +build_clear_page (); +build_copy_page (); + } board_cache_error_setup = octeon_cache_error_setup; }
arch/mips/mm/c-r3k.c +4 -2
@@ -342,6 +342,8 @@ void __cpuinit r3k_cache_init(void)printk ("Primary data cache %ldkB, linesize %ld bytes.\n" , dcache_size >>10 , dcache_lsize); -build_clear_page (); -build_copy_page (); +if (smp_processor_id () ==0 ) { +build_clear_page (); +build_copy_page (); + } }
arch/mips/mm/c-r4k.c +4 -2
@@ -1548,8 +1548,10 @@ void __cpuinit r4k_cache_init(void) }#endif -build_clear_page (); -build_copy_page (); +if (smp_processor_id () ==0 ) { +build_clear_page (); +build_copy_page (); + }#if !defined(CONFIG_MIPS_CMP )local_r4k___flush_cache_all (NULL );#endif
arch/mips/mm/c-tx39.c +4 -2
@@ -434,7 +434,9 @@ void __cpuinit tx39_cache_init(void)printk ("Primary data cache %ldkB, linesize %d bytes\n" , dcache_size >>10 , current_cpu_data.dcache.linesz); -build_clear_page (); -build_copy_page (); +if (smp_processor_id () ==0 ) { +build_clear_page (); +build_copy_page (); + }tx39h_flush_icache_all (); }
arch/mips/mm/tlb-r3k.c +2 -1
@@ -280,5 +280,6 @@ void __cpuinit tlb_init(void) {local_flush_tlb_all (); -build_tlb_refill_handler (); +if (smp_processor_id () ==0 ) +build_tlb_refill_handler (); }
arch/mips/mm/tlb-r4k.c +2 -1
@@ -439,5 +439,6 @@ void __cpuinit tlb_init(void)printk ("Ignoring invalid argument ntlb=%d\n" , ntlb); } -build_tlb_refill_handler (); +if (smp_processor_id () ==0 ) +build_tlb_refill_handler (); }
arch/mips/mm/tlb-r8k.c +2 -1
@@ -244,5 +244,6 @@ void __cpuinit tlb_init(void)local_flush_tlb_all (); -build_tlb_refill_handler (); +if (smp_processor_id () ==0 ) +build_tlb_refill_handler (); }
arch/mips/sgi-ip27/ip27-init.c +2 -1
@@ -84,7 +84,8 @@ static void __cpuinit per_hub_init(cnodeid_t cnode)memcpy ((void *)(CKSEG0 +0x100 ), &except_vec2_generic,0x80 );memcpy ((void *)(CKSEG0 +0x180 ), &except_vec3_generic,0x80 ); -build_tlb_refill_handler (); +if (smp_processor_id () ==0 ) +build_tlb_refill_handler ();memcpy ((void *)(CKSEG0 +0x100 ), (void *)CKSEG0 ,0x80 );memcpy ((void *)(CKSEG0 +0x180 ), &except_vec3_generic,0x100 );__flush_cache_all ();
Signature · 1 line
1.7.7.3
Quoted 11 lines · Huacai Chen
Currently, clear_page()/copy_page() are generated by Micro-assembler dynamically. But they are unavailable until
uasm_resolve_relocs()has finished because jump labels are illegal before that. Since these functions are shared by every CPU, we only call build_clear_page()/build_copy_page()on CPU#0 at boot time. Without this patch, programs will get random memory corruption (segmentation fault, bus error, etc.) while CPU Hotplug (e.g. one CPU is usingclear_page()while another is generating it incpu_cache_init()).For similar reasons we modify build_tlb_refill_handler()'s invocation.
I like the general idea behind the patch. But would prefer to move the test to the functions that are generating the code. That way if more call sites are added, we don't have to copy the boiler-plate testing code.
Also can we change the test to something like:
static atomic_t execute_once;
.
.
.
if (!atomic_xchg(&execute_once, 1)) {
/* Generate the code */
}
.
.
.That way if we take CPU-0 on and off line, the code will not be regenerated.
Thanks,
David Daney
Quoted 129 lines
Signed-off-by Huacai Chen <[email protected]>Signed-off-by Hongbing Hu <[email protected]>--- arch/mips/mm/c-octeon.c | 6 ++++-- arch/mips/mm/c-r3k.c | 6 ++++-- arch/mips/mm/c-r4k.c | 6 ++++-- arch/mips/mm/c-tx39.c | 6 ++++-- arch/mips/mm/tlb-r3k.c | 3 ++- arch/mips/mm/tlb-r4k.c | 3 ++- arch/mips/mm/tlb-r8k.c | 3 ++- arch/mips/sgi-ip27/ip27-init.c | 3 ++- 8 files changed, 24 insertions(+), 12 deletions(-)arch/mips/mm/c-octeon.c +4
-2@@ -280,8 +280,10 @@ void __cpuinit octeon_cache_init(void) __flush_kernel_vmap_range = octeon_flush_kernel_vmap_range; -build_clear_page (); -build_copy_page (); +if (smp_processor_id () ==0 ) { +build_clear_page (); +build_copy_page (); + } board_cache_error_setup = octeon_cache_error_setup; }arch/mips/mm/c-r3k.c +4
-2@@ -342,6 +342,8 @@ void __cpuinit r3k_cache_init(void)printk ("Primary data cache %ldkB, linesize %ld bytes.\n" , dcache_size >>10 , dcache_lsize); -build_clear_page (); -build_copy_page (); +if (smp_processor_id () ==0 ) { +build_clear_page (); +build_copy_page (); + } }arch/mips/mm/c-r4k.c +4
-2@@ -1548,8 +1548,10 @@ void __cpuinit r4k_cache_init(void) }#endif -build_clear_page (); -build_copy_page (); +if (smp_processor_id () ==0 ) { +build_clear_page (); +build_copy_page (); + }#if !defined(CONFIG_MIPS_CMP )local_r4k___flush_cache_all (NULL );#endif arch/mips/mm/c-tx39.c +4
-2@@ -434,7 +434,9 @@ void __cpuinit tx39_cache_init(void)printk ("Primary data cache %ldkB, linesize %d bytes\n" , dcache_size >>10 , current_cpu_data.dcache.linesz); -build_clear_page (); -build_copy_page (); +if (smp_processor_id () ==0 ) { +build_clear_page (); +build_copy_page (); + }tx39h_flush_icache_all (); }arch/mips/mm/tlb-r3k.c +2
-1@@ -280,5 +280,6 @@ void __cpuinit tlb_init(void) {local_flush_tlb_all (); -build_tlb_refill_handler (); +if (smp_processor_id () ==0 ) +build_tlb_refill_handler (); }arch/mips/mm/tlb-r4k.c +2
-1@@ -439,5 +439,6 @@ void __cpuinit tlb_init(void)printk ("Ignoring invalid argument ntlb=%d\n" , ntlb); } -build_tlb_refill_handler (); +if (smp_processor_id () ==0 ) +build_tlb_refill_handler (); }arch/mips/mm/tlb-r8k.c +2
-1@@ -244,5 +244,6 @@ void __cpuinit tlb_init(void)local_flush_tlb_all (); -build_tlb_refill_handler (); +if (smp_processor_id () ==0 ) +build_tlb_refill_handler (); }arch/mips/sgi-ip27/ip27-init.c +2
-1@@ -84,7 +84,8 @@ static void __cpuinit per_hub_init(cnodeid_t cnode)memcpy ((void *)(CKSEG0 +0x100 ), &except_vec2_generic,0x80 );memcpy ((void *)(CKSEG0 +0x180 ), &except_vec3_generic,0x80 ); -build_tlb_refill_handler (); +if (smp_processor_id () ==0 ) +build_tlb_refill_handler ();memcpy ((void *)(CKSEG0 +0x100 ), (void *)CKSEG0 ,0x80 );memcpy ((void *)(CKSEG0 +0x180 ), &except_vec3_generic,0x100 );__flush_cache_all ();
OK, I'm reworking...
Quoted 174 lines · David Daney
Quoted 10 lines · Huacai Chen
Currently, clear_page()/copy_page() are generated by Micro-assembler dynamically. But they are unavailable until
uasm_resolve_relocs()has finished because jump labels are illegal before that. Since these functions are shared by every CPU, we only call build_clear_page()/build_copy_page()on CPU#0 at boot time. Without this patch, programs will get random memory corruption (segmentation fault, bus error, etc.) while CPU Hotplug (e.g. one CPU is usingclear_page()while another is generating it incpu_cache_init()).Quoted 2 lines
For similar reasons we modify build_tlb_refill_handler()'s invocation.
I like the general idea behind the patch. But would prefer to move the test to the functions that are generating the code. That way if more call sites are added, we don't have to copy the boiler-plate testing code.
Also can we change the test to something like:
static atomic_t execute_once; . . . if (!atomic_xchg(&execute_once, 1)) { /* Generate the code */ } . . .That way if we take CPU-0 on and off line, the code will not be regenerated.
Thanks,
David DaneyQuoted 134 lines
Signed-off-by Huacai Chen <[email protected]>Signed-off-by Hongbing Hu <[email protected]>--- arch/mips/mm/c-octeon.c | 6 ++++-- arch/mips/mm/c-r3k.c | 6 ++++-- arch/mips/mm/c-r4k.c | 6 ++++-- arch/mips/mm/c-tx39.c | 6 ++++-- arch/mips/mm/tlb-r3k.c | 3 ++- arch/mips/mm/tlb-r4k.c | 3 ++- arch/mips/mm/tlb-r8k.c | 3 ++- arch/mips/sgi-ip27/ip27-init.c | 3 ++- 8 files changed, 24 insertions(+), 12 deletions(-)arch/mips/mm/c-octeon.c +4
-2@@ -280,8 +280,10 @@ void __cpuinit octeon_cache_init(void) __flush_kernel_vmap_range = octeon_flush_kernel_vmap_range; -build_clear_page (); -build_copy_page (); +if (smp_processor_id () ==0 ) { +build_clear_page (); +build_copy_page (); + } board_cache_error_setup = octeon_cache_error_setup; }arch/mips/mm/c-r3k.c +4
-2@@ -342,6 +342,8 @@ void __cpuinit r3k_cache_init(void)printk ("Primary data cache %ldkB, linesize %ld bytes.\n" , dcache_size >>10 , dcache_lsize); -build_clear_page (); -build_copy_page (); +if (smp_processor_id () ==0 ) { +build_clear_page (); +build_copy_page (); + } }arch/mips/mm/c-r4k.c +4
-2@@ -1548,8 +1548,10 @@ void __cpuinit r4k_cache_init(void) }#endif -build_clear_page (); -build_copy_page (); +if (smp_processor_id () ==0 ) { +build_clear_page (); +build_copy_page (); + }#if !defined(CONFIG_MIPS_CMP )local_r4k___flush_cache_all (NULL );#endif arch/mips/mm/c-tx39.c +4
-2@@ -434,7 +434,9 @@ void __cpuinit tx39_cache_init(void)printk ("Primary data cache %ldkB, linesize %d bytes\n" , dcache_size >>10 , current_cpu_data.dcache.linesz); -build_clear_page (); -build_copy_page (); +if (smp_processor_id () ==0 ) { +build_clear_page (); +build_copy_page (); + }tx39h_flush_icache_all (); }arch/mips/mm/tlb-r3k.c +2
-1@@ -280,5 +280,6 @@ void __cpuinit tlb_init(void) {local_flush_tlb_all (); -build_tlb_refill_handler (); +if (smp_processor_id () ==0 ) +build_tlb_refill_handler (); }arch/mips/mm/tlb-r4k.c +2
-1@@ -439,5 +439,6 @@ void __cpuinit tlb_init(void)printk ("Ignoring invalid argument ntlb=%d\n" , ntlb); } -build_tlb_refill_handler (); +if (smp_processor_id () ==0 ) +build_tlb_refill_handler ();}arch/mips/mm/tlb-r8k.c +2
-1@@ -244,5 +244,6 @@ void __cpuinit tlb_init(void)local_flush_tlb_all (); -build_tlb_refill_handler (); +if (smp_processor_id () ==0 ) +build_tlb_refill_handler (); }arch/mips/sgi-ip27/ip27-init.c +2
-1@@ -84,7 +84,8 @@ static void __cpuinit per_hub_init(cnodeid_t cnode)memcpy ((void *)(CKSEG0 +0x100 ), &except_vec2_generic,0x80 );memcpy ((void *)(CKSEG0 +0x180 ), &except_vec3_generic,0x80 ); -build_tlb_refill_handler (); +if (smp_processor_id () ==0 ) +build_tlb_refill_handler ();memcpy ((void *)(CKSEG0 +0x100 ), (void *)CKSEG0 ,0x80 );memcpy((void *)(CKSEG0 + 0x180), &except_vec3_generic, 0x100); __flush_cache_all();
I'm sorry, this is the only patch, please ignore [01/14].
Quoted 142 lines · Huacai Chen
Currently, clear_page()/copy_page() are generated by Micro-assembler dynamically. But they are unavailable until
uasm_resolve_relocs()has finished because jump labels are illegal before that. Since these functions are shared by every CPU, we only call build_clear_page()/build_copy_page()on CPU#0 at boot time. Without this patch, programs will get random memory corruption (segmentation fault, bus error, etc.) while CPU Hotplug (e.g. one CPU is usingclear_page()while another is generating it incpu_cache_init()).For similar reasons we modify build_tlb_refill_handler()'s invocation.
Signed-off-by Huacai Chen <[email protected]>Signed-off-by Hongbing Hu <[email protected]>--- arch/mips/mm/c-octeon.c | 6 ++++-- arch/mips/mm/c-r3k.c | 6 ++++-- arch/mips/mm/c-r4k.c | 6 ++++-- arch/mips/mm/c-tx39.c | 6 ++++-- arch/mips/mm/tlb-r3k.c | 3 ++- arch/mips/mm/tlb-r4k.c | 3 ++- arch/mips/mm/tlb-r8k.c | 3 ++- arch/mips/sgi-ip27/ip27-init.c | 3 ++- 8 files changed, 24 insertions(+), 12 deletions(-)arch/mips/mm/c-octeon.c +4
-2@@ -280,8 +280,10 @@ void __cpuinit octeon_cache_init(void) __flush_kernel_vmap_range = octeon_flush_kernel_vmap_range; -build_clear_page (); -build_copy_page (); +if (smp_processor_id () ==0 ) { +build_clear_page (); +build_copy_page (); + } board_cache_error_setup = octeon_cache_error_setup; }arch/mips/mm/c-r3k.c +4
-2@@ -342,6 +342,8 @@ void __cpuinit r3k_cache_init(void)printk ("Primary data cache %ldkB, linesize %ld bytes.\n" , dcache_size >>10 , dcache_lsize); -build_clear_page (); -build_copy_page (); +if (smp_processor_id () ==0 ) { +build_clear_page (); +build_copy_page (); + } }arch/mips/mm/c-r4k.c +4
-2@@ -1548,8 +1548,10 @@ void __cpuinit r4k_cache_init(void) }#endif -build_clear_page (); -build_copy_page (); +if (smp_processor_id () ==0 ) { +build_clear_page (); +build_copy_page (); + }#if !defined(CONFIG_MIPS_CMP )local_r4k___flush_cache_all (NULL );#endif arch/mips/mm/c-tx39.c +4
-2@@ -434,7 +434,9 @@ void __cpuinit tx39_cache_init(void)printk ("Primary data cache %ldkB, linesize %d bytes\n" , dcache_size >>10 , current_cpu_data.dcache.linesz); -build_clear_page (); -build_copy_page (); +if (smp_processor_id () ==0 ) { +build_clear_page (); +build_copy_page (); + }tx39h_flush_icache_all (); }arch/mips/mm/tlb-r3k.c +2
-1@@ -280,5 +280,6 @@ void __cpuinit tlb_init(void) {local_flush_tlb_all (); -build_tlb_refill_handler (); +if (smp_processor_id () ==0 ) +build_tlb_refill_handler (); }arch/mips/mm/tlb-r4k.c +2
-1@@ -439,5 +439,6 @@ void __cpuinit tlb_init(void)printk ("Ignoring invalid argument ntlb=%d\n" , ntlb); } -build_tlb_refill_handler (); +if (smp_processor_id () ==0 ) +build_tlb_refill_handler (); }arch/mips/mm/tlb-r8k.c +2
-1@@ -244,5 +244,6 @@ void __cpuinit tlb_init(void)local_flush_tlb_all (); -build_tlb_refill_handler (); +if (smp_processor_id () ==0 ) +build_tlb_refill_handler (); }arch/mips/sgi-ip27/ip27-init.c +2
-2@@ -84,7 +84,8 @@ static void __cpuinit per_hub_init(cnodeid_t cnode)memcpy ((void *)(CKSEG0 +0x100 ), &except_vec2_generic,0x80 );memcpy ((void *)(CKSEG0 +0x180 ), &except_vec3_generic,0x80 ); -build_tlb_refill_handler (); +if (smp_processor_id () ==0 ) +build_tlb_refill_handler ();memcpy ((void *)(CKSEG0 +0x100 ), (void *)CKSEG0 ,0x80 );memcpy ((void *)(CKSEG0 +0x180 ), &except_vec3_generic,0x100 );__flush_cache_all (); --1.7.7.3