Message ID | 20220412173221.13315-1-varad.gautam@suse.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [01/10] x86: Move ap_init() to smp.c | expand |
Please discard this series, I've resent it with a cover letter here [1]. Sorry for the noise. [1] https://lore.kernel.org/kvm/20220412173407.13637-1-varad.gautam@suse.com/ On 4/12/22 7:32 PM, Varad Gautam wrote: > ap_init() copies the SIPI vector to lowmem, sends INIT/SIPI to APs > and waits on the APs to come up. > > Port this routine to C from asm and move it to smp.c to allow sharing > this functionality between the EFI (-fPIC) and non-EFI builds. > > Call ap_init() from the EFI setup path to reset the APs to a known > location. > > Signed-off-by: Varad Gautam <varad.gautam@suse.com> > --- > lib/x86/setup.c | 1 + > lib/x86/smp.c | 28 ++++++++++++++++++++++++++-- > lib/x86/smp.h | 1 + > x86/cstart64.S | 20 ++------------------ > x86/efi/efistart64.S | 9 +++++++++ > 5 files changed, 39 insertions(+), 20 deletions(-) > > diff --git a/lib/x86/setup.c b/lib/x86/setup.c > index 2d63a44..86ba6de 100644 > --- a/lib/x86/setup.c > +++ b/lib/x86/setup.c > @@ -323,6 +323,7 @@ efi_status_t setup_efi(efi_bootinfo_t *efi_bootinfo) > load_idt(); > mask_pic_interrupts(); > enable_apic(); > + ap_init(); > enable_x2apic(); > smp_init(); > setup_page_table(); > diff --git a/lib/x86/smp.c b/lib/x86/smp.c > index 683b25d..d7f5aba 100644 > --- a/lib/x86/smp.c > +++ b/lib/x86/smp.c > @@ -18,6 +18,9 @@ static volatile int ipi_done; > static volatile bool ipi_wait; > static int _cpu_count; > static atomic_t active_cpus; > +extern u8 sipi_entry; > +extern u8 sipi_end; > +volatile unsigned cpu_online_count = 1; > > static __attribute__((used)) void ipi(void) > { > @@ -114,8 +117,6 @@ void smp_init(void) > int i; > void ipi_entry(void); > > - _cpu_count = fwcfg_get_nb_cpus(); > - > setup_idt(); > init_apic_map(); > set_idt_entry(IPI_VECTOR, ipi_entry, 0); > @@ -142,3 +143,26 @@ void smp_reset_apic(void) > > atomic_inc(&active_cpus); > } > + > +void ap_init(void) > +{ > + u8 *dst_addr = 0; > + size_t sipi_sz = (&sipi_end - &sipi_entry) + 1; > + > + asm volatile("cld"); > + > + /* Relocate SIPI vector to dst_addr so it can run in 16-bit mode. */ > + memcpy(dst_addr, &sipi_entry, sipi_sz); > + > + /* INIT */ > + apic_icr_write(APIC_DEST_ALLBUT | APIC_DEST_PHYSICAL | APIC_DM_INIT | APIC_INT_ASSERT, 0); > + > + /* SIPI */ > + apic_icr_write(APIC_DEST_ALLBUT | APIC_DEST_PHYSICAL | APIC_DM_STARTUP, 0); > + > + _cpu_count = fwcfg_get_nb_cpus(); > + > + while (_cpu_count != cpu_online_count) { > + ; > + } > +} > diff --git a/lib/x86/smp.h b/lib/x86/smp.h > index bd303c2..9c92853 100644 > --- a/lib/x86/smp.h > +++ b/lib/x86/smp.h > @@ -78,5 +78,6 @@ void on_cpu(int cpu, void (*function)(void *data), void *data); > void on_cpu_async(int cpu, void (*function)(void *data), void *data); > void on_cpus(void (*function)(void *data), void *data); > void smp_reset_apic(void); > +void ap_init(void); > > #endif > diff --git a/x86/cstart64.S b/x86/cstart64.S > index 7272452..f371d06 100644 > --- a/x86/cstart64.S > +++ b/x86/cstart64.S > @@ -157,6 +157,7 @@ gdt32: > gdt32_end: > > .code16 > +.globl sipi_entry > sipi_entry: > mov %cr0, %eax > or $1, %eax > @@ -168,6 +169,7 @@ gdt32_descr: > .word gdt32_end - gdt32 - 1 > .long gdt32 > > +.globl sipi_end > sipi_end: > > .code32 > @@ -240,21 +242,3 @@ lvl5: > > online_cpus: > .fill (max_cpus + 7) / 8, 1, 0 > - > -ap_init: > - cld > - lea sipi_entry, %rsi > - xor %rdi, %rdi > - mov $(sipi_end - sipi_entry), %rcx > - rep movsb > - mov $APIC_DEFAULT_PHYS_BASE, %eax > - movl $(APIC_DEST_ALLBUT | APIC_DEST_PHYSICAL | APIC_DM_INIT | APIC_INT_ASSERT), APIC_ICR(%rax) > - movl $(APIC_DEST_ALLBUT | APIC_DEST_PHYSICAL | APIC_DM_STARTUP), APIC_ICR(%rax) > - call fwcfg_get_nb_cpus > -1: pause > - cmpw %ax, cpu_online_count > - jne 1b > - ret > - > -.align 2 > -cpu_online_count: .word 1 > diff --git a/x86/efi/efistart64.S b/x86/efi/efistart64.S > index 017abba..0425153 100644 > --- a/x86/efi/efistart64.S > +++ b/x86/efi/efistart64.S > @@ -57,3 +57,12 @@ load_gdt_tss: > pushq $0x08 /* 2nd entry in gdt64: 64-bit code segment */ > pushq %rdi > lretq > + > +.code16 > + > +.globl sipi_entry > +sipi_entry: > + jmp sipi_entry > + > +.globl sipi_end > +sipi_end: >
diff --git a/lib/x86/setup.c b/lib/x86/setup.c index 2d63a44..86ba6de 100644 --- a/lib/x86/setup.c +++ b/lib/x86/setup.c @@ -323,6 +323,7 @@ efi_status_t setup_efi(efi_bootinfo_t *efi_bootinfo) load_idt(); mask_pic_interrupts(); enable_apic(); + ap_init(); enable_x2apic(); smp_init(); setup_page_table(); diff --git a/lib/x86/smp.c b/lib/x86/smp.c index 683b25d..d7f5aba 100644 --- a/lib/x86/smp.c +++ b/lib/x86/smp.c @@ -18,6 +18,9 @@ static volatile int ipi_done; static volatile bool ipi_wait; static int _cpu_count; static atomic_t active_cpus; +extern u8 sipi_entry; +extern u8 sipi_end; +volatile unsigned cpu_online_count = 1; static __attribute__((used)) void ipi(void) { @@ -114,8 +117,6 @@ void smp_init(void) int i; void ipi_entry(void); - _cpu_count = fwcfg_get_nb_cpus(); - setup_idt(); init_apic_map(); set_idt_entry(IPI_VECTOR, ipi_entry, 0); @@ -142,3 +143,26 @@ void smp_reset_apic(void) atomic_inc(&active_cpus); } + +void ap_init(void) +{ + u8 *dst_addr = 0; + size_t sipi_sz = (&sipi_end - &sipi_entry) + 1; + + asm volatile("cld"); + + /* Relocate SIPI vector to dst_addr so it can run in 16-bit mode. */ + memcpy(dst_addr, &sipi_entry, sipi_sz); + + /* INIT */ + apic_icr_write(APIC_DEST_ALLBUT | APIC_DEST_PHYSICAL | APIC_DM_INIT | APIC_INT_ASSERT, 0); + + /* SIPI */ + apic_icr_write(APIC_DEST_ALLBUT | APIC_DEST_PHYSICAL | APIC_DM_STARTUP, 0); + + _cpu_count = fwcfg_get_nb_cpus(); + + while (_cpu_count != cpu_online_count) { + ; + } +} diff --git a/lib/x86/smp.h b/lib/x86/smp.h index bd303c2..9c92853 100644 --- a/lib/x86/smp.h +++ b/lib/x86/smp.h @@ -78,5 +78,6 @@ void on_cpu(int cpu, void (*function)(void *data), void *data); void on_cpu_async(int cpu, void (*function)(void *data), void *data); void on_cpus(void (*function)(void *data), void *data); void smp_reset_apic(void); +void ap_init(void); #endif diff --git a/x86/cstart64.S b/x86/cstart64.S index 7272452..f371d06 100644 --- a/x86/cstart64.S +++ b/x86/cstart64.S @@ -157,6 +157,7 @@ gdt32: gdt32_end: .code16 +.globl sipi_entry sipi_entry: mov %cr0, %eax or $1, %eax @@ -168,6 +169,7 @@ gdt32_descr: .word gdt32_end - gdt32 - 1 .long gdt32 +.globl sipi_end sipi_end: .code32 @@ -240,21 +242,3 @@ lvl5: online_cpus: .fill (max_cpus + 7) / 8, 1, 0 - -ap_init: - cld - lea sipi_entry, %rsi - xor %rdi, %rdi - mov $(sipi_end - sipi_entry), %rcx - rep movsb - mov $APIC_DEFAULT_PHYS_BASE, %eax - movl $(APIC_DEST_ALLBUT | APIC_DEST_PHYSICAL | APIC_DM_INIT | APIC_INT_ASSERT), APIC_ICR(%rax) - movl $(APIC_DEST_ALLBUT | APIC_DEST_PHYSICAL | APIC_DM_STARTUP), APIC_ICR(%rax) - call fwcfg_get_nb_cpus -1: pause - cmpw %ax, cpu_online_count - jne 1b - ret - -.align 2 -cpu_online_count: .word 1 diff --git a/x86/efi/efistart64.S b/x86/efi/efistart64.S index 017abba..0425153 100644 --- a/x86/efi/efistart64.S +++ b/x86/efi/efistart64.S @@ -57,3 +57,12 @@ load_gdt_tss: pushq $0x08 /* 2nd entry in gdt64: 64-bit code segment */ pushq %rdi lretq + +.code16 + +.globl sipi_entry +sipi_entry: + jmp sipi_entry + +.globl sipi_end +sipi_end:
ap_init() copies the SIPI vector to lowmem, sends INIT/SIPI to APs and waits on the APs to come up. Port this routine to C from asm and move it to smp.c to allow sharing this functionality between the EFI (-fPIC) and non-EFI builds. Call ap_init() from the EFI setup path to reset the APs to a known location. Signed-off-by: Varad Gautam <varad.gautam@suse.com> --- lib/x86/setup.c | 1 + lib/x86/smp.c | 28 ++++++++++++++++++++++++++-- lib/x86/smp.h | 1 + x86/cstart64.S | 20 ++------------------ x86/efi/efistart64.S | 9 +++++++++ 5 files changed, 39 insertions(+), 20 deletions(-)