arch/x86: Provide the CPU number in the wakeup AP callback
Subsystems (5)
PATCH v2 1/1 arch/x86: Provide the CPU number in the wakeup AP callback
When starting APs, confidential guests and paravisor guests need to know the CPU number, and the pattern of using the linear search has emerged in several places. With N processors that leads to the O(N^2) time complexity.
Provide the CPU number in the AP wake up callback so that one can get the CPU number in constant time.
---
The diff in ivm.c might catch your eye but that code mixes up the APIC ID and the CPU number anyway. That is fixed in another patch:
https://lore.kernel.org/linux-hyperv/[email protected]/
independently of this one (being an optimization).
I separated the two as this one might be more disputatious due to the change in the API (although it is a tiny one and comes with the benefits).
[V2]
- Remove the struct used in v1 in favor of passing the CPU number directly to the callback not to increase complexity.
** Thank you, Michael! **
[V1]
https://lore.kernel.org/linux-hyperv/[email protected]/ --- arch/x86/coco/sev/core.c | 13 ++----------- arch/x86/hyperv/hv_vtl.c | 12 ++---------- arch/x86/hyperv/ivm.c | 2 +- arch/x86/include/asm/apic.h | 8 ++++---- arch/x86/include/asm/mshyperv.h | 4 ++-- arch/x86/kernel/acpi/madt_wakeup.c | 2 +- arch/x86/kernel/apic/apic_noop.c | 2 +- arch/x86/kernel/apic/x2apic_uv_x.c | 2 +- arch/x86/kernel/smpboot.c | 8 ++++---- 9 files changed, 18 insertions(+), 35 deletions(-)
arch/x86/coco/sev/core.c +2 -11
@@ -1179,7 +1179,7 @@ static void snp_cleanup_vmsa(struct sev_es_save_area *vmsa, int apic_id)free_page ((unsigned long )vmsa); } -static int wakeup_cpu_via_vmgexit (u32 apic_id,unsigned long start_ip) +static int wakeup_cpu_via_vmgexit (u32 apic_id,unsigned long start_ip,int cpu) {struct sev_es_save_area *cur_vmsa, *vmsa;struct ghcb_state state;
@@ -1187,7 +1187,7 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip)unsigned long flags;struct ghcb *ghcb;u8 sipi_vector; -int cpu, ret; +int ret;u64 cr4;/*
@@ -1208,15 +1208,6 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip)/* Override start_ip with known protected guest start IP */ start_ip = real_mode_header->sev_es_trampoline_start; - -/* Find the logical CPU for the APIC ID */ -for_each_present_cpu (cpu) { -if (arch_match_cpu_phys_id (cpu, apic_id)) -break ; - } -if (cpu >= nr_cpu_ids) -return -EINVAL ; - cur_vmsa =per_cpu (sev_vmsa, cpu);/*
arch/x86/hyperv/hv_vtl.c +2 -10
@@ -237,17 +237,9 @@ static int hv_vtl_apicid_to_vp_id(u32 apic_id)return ret; } -static int hv_vtl_wakeup_secondary_cpu (u32 apicid,unsigned long start_eip) +static int hv_vtl_wakeup_secondary_cpu (u32 apicid,unsigned long start_eip,int cpu) { -int vp_id, cpu; - -/* Find the logical CPU for the APIC ID */ -for_each_present_cpu (cpu) { -if (arch_match_cpu_phys_id (cpu, apicid)) -break ; - } -if (cpu >= nr_cpu_ids) -return -EINVAL ; +int vp_id;pr_debug ("Bringing up CPU with APIC ID %d in VTL2...\n" , apicid); vp_id =hv_vtl_apicid_to_vp_id (apicid);
arch/x86/hyperv/ivm.c +1 -1
@@ -288,7 +288,7 @@ static void snp_cleanup_vmsa(struct sev_es_save_area *vmsa)free_page ((unsigned long )vmsa); } -int hv_snp_boot_ap (u32 cpu,unsigned long start_ip) +int hv_snp_boot_ap (u32 apic_id,unsigned long start_ip,int cpu) {struct sev_es_save_area *vmsa = (struct sev_es_save_area *)__get_free_page (GFP_KERNEL | __GFP_ZERO);
arch/x86/include/asm/apic.h +4 -4
@@ -313,9 +313,9 @@ struct apic {u32 (*get_apic_id)(u32 id);/* wakeup_secondary_cpu */ -int (*wakeup_secondary_cpu)(u32 apicid,unsigned long start_eip); +int (*wakeup_secondary_cpu)(u32 apicid,unsigned long start_eip,int cpu);/* wakeup secondary CPU using 64-bit wakeup point */ -int (*wakeup_secondary_cpu_64)(u32 apicid,unsigned long start_eip); +int (*wakeup_secondary_cpu_64)(u32 apicid,unsigned long start_eip,int cpu);char *name; };
@@ -333,8 +333,8 @@ struct apic_override {void (*send_IPI_self)(int vector);u64 (*icr_read)(void);void (*icr_write)(u32 low,u32 high); -int (*wakeup_secondary_cpu)(u32 apicid,unsigned long start_eip); -int (*wakeup_secondary_cpu_64)(u32 apicid,unsigned long start_eip); +int (*wakeup_secondary_cpu)(u32 apicid,unsigned long start_eip,int cpu); +int (*wakeup_secondary_cpu_64)(u32 apicid,unsigned long start_eip,int cpu); };/*
arch/x86/include/asm/mshyperv.h +2 -2
@@ -268,11 +268,11 @@ int hv_unmap_ioapic_interrupt(int ioapic_id, struct hv_interrupt_entry *entry);#ifdef CONFIG_AMD_MEM_ENCRYPT bool hv_ghcb_negotiate_protocol (void );void __noreturn hv_ghcb_terminate (unsigned int set,unsigned int reason); -int hv_snp_boot_ap (u32 cpu,unsigned long start_ip); +int hv_snp_boot_ap (u32 apic_id,unsigned long start_ip,int cpu);#else static inline bool hv_ghcb_negotiate_protocol (void ) {return false; }static inline void hv_ghcb_terminate (unsigned int set,unsigned int reason) {} -static inline int hv_snp_boot_ap (u32 cpu,unsigned long start_ip) {return 0 ; } +static inline int hv_snp_boot_ap (u32 apic_id,unsigned long start_ip,int cpu) {return 0 ; }#endif #if defined(CONFIG_AMD_MEM_ENCRYPT ) || defined(CONFIG_INTEL_TDX_GUEST )
arch/x86/kernel/acpi/madt_wakeup.c +1 -1
@@ -169,7 +169,7 @@ static int __init acpi_mp_setup_reset(u64 reset_vector)return 0 ; } -static int acpi_wakeup_cpu (u32 apicid,unsigned long start_ip) +static int acpi_wakeup_cpu (u32 apicid,unsigned long start_ip,int cpu) {if (!acpi_mp_wake_mailbox_paddr) {pr_warn_once ("No MADT mailbox: cannot bringup secondary CPUs. Booting with kexec?\n" );
arch/x86/kernel/apic/apic_noop.c +1 -1
@@ -27,7 +27,7 @@ static void noop_send_IPI_allbutself(int vector) { }static void noop_send_IPI_all (int vector) { }static void noop_send_IPI_self (int vector) { }static void noop_apic_icr_write (u32 low,u32 id) { } -static int noop_wakeup_secondary_cpu (u32 apicid,unsigned long start_eip) {return -1 ; } +static int noop_wakeup_secondary_cpu (u32 apicid,unsigned long start_eip,int cpu) {return -1 ; }static u64 noop_apic_icr_read (void ) {return 0 ; }static u32 noop_get_apic_id (u32 apicid) {return 0 ; }static void noop_apic_eoi (void ) { }
arch/x86/kernel/apic/x2apic_uv_x.c +1 -1
@@ -667,7 +667,7 @@ static __init void build_uv_gr_table(void) } } -static int uv_wakeup_secondary (u32 phys_apicid,unsigned long start_rip) +static int uv_wakeup_secondary (u32 phys_apicid,unsigned long start_rip,int cpu) {unsigned long val;int pnode;
arch/x86/kernel/smpboot.c +4 -4
@@ -715,7 +715,7 @@ static void send_init_sequence(u32 phys_apicid)/* * Wake up AP by INIT, INIT, STARTUP sequence. */ -static int wakeup_secondary_cpu_via_init (u32 phys_apicid,unsigned long start_eip) +static int wakeup_secondary_cpu_via_init (u32 phys_apicid,unsigned long start_eip,int cpu) {unsigned long send_status =0 , accept_status =0 ;int num_starts, j, maxlvt;
@@ -916,11 +916,11 @@ static int do_boot_cpu(u32 apicid, int cpu, struct task_struct *idle)* - Use an INIT boot APIC message */ if (apic->wakeup_secondary_cpu_64) - ret = apic->wakeup_secondary_cpu_64 (apicid, start_ip); + ret = apic->wakeup_secondary_cpu_64 (apicid, start_ip, cpu);else if (apic->wakeup_secondary_cpu) - ret = apic->wakeup_secondary_cpu (apicid, start_ip); + ret = apic->wakeup_secondary_cpu (apicid, start_ip, cpu);else - ret =wakeup_secondary_cpu_via_init (apicid, start_ip); + ret =wakeup_secondary_cpu_via_init (apicid, start_ip, cpu);/* If the wakeup mechanism failed, cleanup the warm reset vector */ if (ret)
base-commit: 628cc040b3a2980df6032766e8ef0688e981ab95
Signature · 1 line
2.43.0
Quoted 24 lines · Roman Kisel
When starting APs, confidential guests and paravisor guests need to know the CPU number, and the pattern of using the linear search has emerged in several places. With N processors that leads to the O(N^2) time complexity.
Provide the CPU number in the AP wake up callback so that one can get the CPU number in constant time.
Suggested-by Michael Kelley <[email protected]>Signed-off-by Roman Kisel <[email protected]>---
The diff inivm.cmight catch your eye but that code mixes up the APIC ID and the CPU number anyway. That is fixed in another patch:
https://lore.kernel.org/linux-hyperv/[email protected]/
independently of this one (being an optimization).
I separated the two as this one might be more disputatious due to the change in the API (although it is a tiny one and comes with the benefits).[V2]
- Remove the struct used in v1 in favor of passing the CPU number directly to the callback not to increase complexity.
** Thank you, Michael! **
[V1]
Quoted 13 lines
https://lore.kernel.org/linux-hyperv/[email protected]/ --- arch/x86/coco/sev/core.c | 13 ++----------- arch/x86/hyperv/hv_vtl.c | 12 ++---------- arch/x86/hyperv/ivm.c | 2 +- arch/x86/include/asm/apic.h | 8 ++++---- arch/x86/include/asm/mshyperv.h | 4 ++-- arch/x86/kernel/acpi/madt_wakeup.c | 2 +- arch/x86/kernel/apic/apic_noop.c | 2 +- arch/x86/kernel/apic/x2apic_uv_x.c | 2 +- arch/x86/kernel/smpboot.c | 8 ++++---- 9 files changed, 18 insertions(+), 35 deletions(-)
The change to wakeup_secondary_cpu_via_init() isn't needed but does provide consistency. I'll leave that to the maintainers to decide if that function should remain as is.
Otherwise,
Quoted 189 lines
arch/x86/coco/sev/core.c +2
-11@@ -1179,7 +1179,7 @@ static void snp_cleanup_vmsa(struct sev_es_save_area *vmsa, int apic_id)free_page ((unsigned long )vmsa); } -static int wakeup_cpu_via_vmgexit (u32 apic_id,unsigned long start_ip) +static int wakeup_cpu_via_vmgexit (u32 apic_id,unsigned long start_ip,int cpu) {struct sev_es_save_area *cur_vmsa, *vmsa;struct ghcb_state state;@@ -1187,7 +1187,7 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip)unsigned long flags;struct ghcb *ghcb;u8 sipi_vector; -int cpu, ret; +int ret;u64 cr4;/* @@ -1208,15 +1208,6 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip)/* Override start_ip with known protected guest start IP */ start_ip = real_mode_header->sev_es_trampoline_start; - -/* Find the logical CPU for the APIC ID */ -for_each_present_cpu (cpu) { -if (arch_match_cpu_phys_id (cpu, apic_id)) -break ; - } -if (cpu >= nr_cpu_ids) -return -EINVAL ; - cur_vmsa =per_cpu (sev_vmsa, cpu);/* arch/x86/hyperv/hv_vtl.c +2
-10@@ -237,17 +237,9 @@ static int hv_vtl_apicid_to_vp_id(u32 apic_id)return ret; } -static int hv_vtl_wakeup_secondary_cpu (u32 apicid,unsigned long start_eip) +static int hv_vtl_wakeup_secondary_cpu (u32 apicid,unsigned long start_eip,int cpu) { -int vp_id, cpu; - -/* Find the logical CPU for the APIC ID */ -for_each_present_cpu (cpu) { -if (arch_match_cpu_phys_id (cpu, apicid)) -break ; - } -if (cpu >= nr_cpu_ids) -return -EINVAL ; +int vp_id;pr_debug ("Bringing up CPU with APIC ID %d in VTL2...\n" , apicid); vp_id =hv_vtl_apicid_to_vp_id (apicid);arch/x86/hyperv/ivm.c +1
-1@@ -288,7 +288,7 @@ static void snp_cleanup_vmsa(struct sev_es_save_area *vmsa)free_page ((unsigned long )vmsa); } -int hv_snp_boot_ap (u32 cpu,unsigned long start_ip) +int hv_snp_boot_ap (u32 apic_id,unsigned long start_ip,int cpu) {struct sev_es_save_area *vmsa = (struct sev_es_save_area *)__get_free_page (GFP_KERNEL | __GFP_ZERO);arch/x86/include/asm/apic.h +4
-4@@ -313,9 +313,9 @@ struct apic {u32 (*get_apic_id)(u32 id);/* wakeup_secondary_cpu */ -int (*wakeup_secondary_cpu)(u32 apicid,unsigned long start_eip); +int (*wakeup_secondary_cpu)(u32 apicid,unsigned long start_eip,int cpu);/* wakeup secondary CPU using 64-bit wakeup point */ -int (*wakeup_secondary_cpu_64)(u32 apicid,unsigned long start_eip); +int (*wakeup_secondary_cpu_64)(u32 apicid,unsigned long start_eip,int cpu);char *name; };@@ -333,8 +333,8 @@ struct apic_override {void (*send_IPI_self)(int vector);u64 (*icr_read)(void);void (*icr_write)(u32 low,u32 high); -int (*wakeup_secondary_cpu)(u32 apicid,unsigned long start_eip); -int (*wakeup_secondary_cpu_64)(u32 apicid,unsigned long start_eip); +int (*wakeup_secondary_cpu)(u32 apicid,unsigned long start_eip,int cpu); +int (*wakeup_secondary_cpu_64)(u32 apicid,unsigned long start_eip,int cpu); };/* arch/x86/include/asm/mshyperv.h +2
-2@@ -268,11 +268,11 @@ int hv_unmap_ioapic_interrupt(int ioapic_id, struct hv_interrupt_entry *entry);#ifdef CONFIG_AMD_MEM_ENCRYPT bool hv_ghcb_negotiate_protocol (void );void __noreturn hv_ghcb_terminate (unsigned int set,unsigned int reason); -int hv_snp_boot_ap (u32 cpu,unsigned long start_ip); +int hv_snp_boot_ap (u32 apic_id,unsigned long start_ip,int cpu);#else static inline bool hv_ghcb_negotiate_protocol (void ) {return false; }static inline void hv_ghcb_terminate (unsigned int set,unsigned int reason) {} -static inline int hv_snp_boot_ap (u32 cpu,unsigned long start_ip) {return 0 ; } +static inline int hv_snp_boot_ap (u32 apic_id,unsigned long start_ip,int cpu) {return 0 ; }#endif #if defined(CONFIG_AMD_MEM_ENCRYPT ) || defined(CONFIG_INTEL_TDX_GUEST )arch/x86/kernel/acpi/madt_wakeup.c +1
-1@@ -169,7 +169,7 @@ static int __init acpi_mp_setup_reset(u64 reset_vector)return 0 ; } -static int acpi_wakeup_cpu (u32 apicid,unsigned long start_ip) +static int acpi_wakeup_cpu (u32 apicid,unsigned long start_ip,int cpu) {if (!acpi_mp_wake_mailbox_paddr) {pr_warn_once ("No MADT mailbox: cannot bringup secondary CPUs. Booting with kexec?\n" );arch/x86/kernel/apic/apic_noop.c +1
-1@@ -27,7 +27,7 @@ static void noop_send_IPI_allbutself(int vector) { }static void noop_send_IPI_all (int vector) { }static void noop_send_IPI_self (int vector) { }static void noop_apic_icr_write (u32 low,u32 id) { } -static int noop_wakeup_secondary_cpu (u32 apicid,unsigned long start_eip) {return -1 ; } +static int noop_wakeup_secondary_cpu (u32 apicid,unsigned long start_eip,int cpu) {return -1 ; }static u64 noop_apic_icr_read (void ) {return 0 ; }static u32 noop_get_apic_id (u32 apicid) {return 0 ; }static void noop_apic_eoi (void ) { }arch/x86/kernel/apic/x2apic_uv_x.c +1
-1@@ -667,7 +667,7 @@ static __init void build_uv_gr_table(void) } } -static int uv_wakeup_secondary (u32 phys_apicid,unsigned long start_rip) +static int uv_wakeup_secondary (u32 phys_apicid,unsigned long start_rip,int cpu) {unsigned long val;int pnode;arch/x86/kernel/smpboot.c +4
-4@@ -715,7 +715,7 @@ static void send_init_sequence(u32 phys_apicid)/* * Wake up AP by INIT, INIT, STARTUP sequence. */ -static int wakeup_secondary_cpu_via_init (u32 phys_apicid,unsigned long start_eip) +static int wakeup_secondary_cpu_via_init (u32 phys_apicid,unsigned long start_eip,int cpu) {unsigned long send_status =0 , accept_status =0 ;int num_starts, j, maxlvt;@@ -916,11 +916,11 @@ static int do_boot_cpu(u32 apicid, int cpu, struct task_struct *idle)* - Use an INIT boot APIC message */ if (apic->wakeup_secondary_cpu_64) - ret = apic->wakeup_secondary_cpu_64 (apicid, start_ip); + ret = apic->wakeup_secondary_cpu_64 (apicid, start_ip, cpu);else if (apic->wakeup_secondary_cpu) - ret = apic->wakeup_secondary_cpu (apicid, start_ip); + ret = apic->wakeup_secondary_cpu (apicid, start_ip, cpu);else - ret =wakeup_secondary_cpu_via_init (apicid, start_ip); + ret =wakeup_secondary_cpu_via_init (apicid, start_ip, cpu);/* If the wakeup mechanism failed, cleanup the warm reset vector */ if (ret)base-commit:
628cc040b3a2980df6032766e8ef0688e981ab95
Quoted 39 lines · Tom Lendacky
Quoted 24 lines · Roman Kisel
When starting APs, confidential guests and paravisor guests need to know the CPU number, and the pattern of using the linear search has emerged in several places. With N processors that leads to the O(N^2) time complexity.
Provide the CPU number in the AP wake up callback so that one can get the CPU number in constant time.
Suggested-by Michael Kelley <[email protected]>Signed-off-by Roman Kisel <[email protected]>---
The diff inivm.cmight catch your eye but that code mixes up the APIC ID and the CPU number anyway. That is fixed in another patch:
https://lore.kernel.org/linux-hyperv/[email protected]/
independently of this one (being an optimization).
I separated the two as this one might be more disputatious due to the change in the API (although it is a tiny one and comes with the benefits).[V2]
- Remove the struct used in v1 in favor of passing the CPU number directly to the callback not to increase complexity.
** Thank you, Michael! **
[V1]Quoted 13 lines
https://lore.kernel.org/linux-hyperv/[email protected]/ --- arch/x86/coco/sev/core.c | 13 ++----------- arch/x86/hyperv/hv_vtl.c | 12 ++---------- arch/x86/hyperv/ivm.c | 2 +- arch/x86/include/asm/apic.h | 8 ++++---- arch/x86/include/asm/mshyperv.h | 4 ++-- arch/x86/kernel/acpi/madt_wakeup.c | 2 +- arch/x86/kernel/apic/apic_noop.c | 2 +- arch/x86/kernel/apic/x2apic_uv_x.c | 2 +- arch/x86/kernel/smpboot.c | 8 ++++---- 9 files changed, 18 insertions(+), 35 deletions(-)
Quoted 7 lines
The change to
wakeup_secondary_cpu_via_init()isn't needed but does provide consistency. I'll leave that to the maintainers to decide if that function should remain as is.Otherwise,
Reviewed-by Tom Lendacky <[email protected]>
Tom,
appreciate takling the time to review, thank you!
Quoted 190 lines
Quoted 190 lines
arch/x86/coco/sev/core.c +2
-11@@ -1179,7 +1179,7 @@ static void snp_cleanup_vmsa(struct sev_es_save_area *vmsa, int apic_id)free_page ((unsigned long )vmsa); } -static int wakeup_cpu_via_vmgexit (u32 apic_id,unsigned long start_ip) +static int wakeup_cpu_via_vmgexit (u32 apic_id,unsigned long start_ip,int cpu) {struct sev_es_save_area *cur_vmsa, *vmsa;struct ghcb_state state;@@ -1187,7 +1187,7 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip)unsigned long flags;struct ghcb *ghcb;u8 sipi_vector; -int cpu, ret; +int ret;u64 cr4;/* @@ -1208,15 +1208,6 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip)/* Override start_ip with known protected guest start IP */ start_ip = real_mode_header->sev_es_trampoline_start; - -/* Find the logical CPU for the APIC ID */ -for_each_present_cpu (cpu) { -if (arch_match_cpu_phys_id (cpu, apic_id)) -break ; - } -if (cpu >= nr_cpu_ids) -return -EINVAL ; - cur_vmsa =per_cpu (sev_vmsa, cpu);/* arch/x86/hyperv/hv_vtl.c +2
-10@@ -237,17 +237,9 @@ static int hv_vtl_apicid_to_vp_id(u32 apic_id)return ret; } -static int hv_vtl_wakeup_secondary_cpu (u32 apicid,unsigned long start_eip) +static int hv_vtl_wakeup_secondary_cpu (u32 apicid,unsigned long start_eip,int cpu) { -int vp_id, cpu; - -/* Find the logical CPU for the APIC ID */ -for_each_present_cpu (cpu) { -if (arch_match_cpu_phys_id (cpu, apicid)) -break ; - } -if (cpu >= nr_cpu_ids) -return -EINVAL ; +int vp_id;pr_debug ("Bringing up CPU with APIC ID %d in VTL2...\n" , apicid); vp_id =hv_vtl_apicid_to_vp_id (apicid);arch/x86/hyperv/ivm.c +1
-1@@ -288,7 +288,7 @@ static void snp_cleanup_vmsa(struct sev_es_save_area *vmsa)free_page ((unsigned long )vmsa); } -int hv_snp_boot_ap (u32 cpu,unsigned long start_ip) +int hv_snp_boot_ap (u32 apic_id,unsigned long start_ip,int cpu) {struct sev_es_save_area *vmsa = (struct sev_es_save_area *)__get_free_page (GFP_KERNEL | __GFP_ZERO);arch/x86/include/asm/apic.h +4
-4@@ -313,9 +313,9 @@ struct apic {u32 (*get_apic_id)(u32 id);/* wakeup_secondary_cpu */ -int (*wakeup_secondary_cpu)(u32 apicid,unsigned long start_eip); +int (*wakeup_secondary_cpu)(u32 apicid,unsigned long start_eip,int cpu);/* wakeup secondary CPU using 64-bit wakeup point */ -int (*wakeup_secondary_cpu_64)(u32 apicid,unsigned long start_eip); +int (*wakeup_secondary_cpu_64)(u32 apicid,unsigned long start_eip,int cpu);char *name; };@@ -333,8 +333,8 @@ struct apic_override {void (*send_IPI_self)(int vector);u64 (*icr_read)(void);void (*icr_write)(u32 low,u32 high); -int (*wakeup_secondary_cpu)(u32 apicid,unsigned long start_eip); -int (*wakeup_secondary_cpu_64)(u32 apicid,unsigned long start_eip); +int (*wakeup_secondary_cpu)(u32 apicid,unsigned long start_eip,int cpu); +int (*wakeup_secondary_cpu_64)(u32 apicid,unsigned long start_eip,int cpu); };/* arch/x86/include/asm/mshyperv.h +2
-2@@ -268,11 +268,11 @@ int hv_unmap_ioapic_interrupt(int ioapic_id, struct hv_interrupt_entry *entry);#ifdef CONFIG_AMD_MEM_ENCRYPT bool hv_ghcb_negotiate_protocol (void );void __noreturn hv_ghcb_terminate (unsigned int set,unsigned int reason); -int hv_snp_boot_ap (u32 cpu,unsigned long start_ip); +int hv_snp_boot_ap (u32 apic_id,unsigned long start_ip,int cpu);#else static inline bool hv_ghcb_negotiate_protocol (void ) {return false; }static inline void hv_ghcb_terminate (unsigned int set,unsigned int reason) {} -static inline int hv_snp_boot_ap (u32 cpu,unsigned long start_ip) {return 0 ; } +static inline int hv_snp_boot_ap (u32 apic_id,unsigned long start_ip,int cpu) {return 0 ; }#endif #if defined(CONFIG_AMD_MEM_ENCRYPT ) || defined(CONFIG_INTEL_TDX_GUEST )arch/x86/kernel/acpi/madt_wakeup.c +1
-1@@ -169,7 +169,7 @@ static int __init acpi_mp_setup_reset(u64 reset_vector)return 0 ; } -static int acpi_wakeup_cpu (u32 apicid,unsigned long start_ip) +static int acpi_wakeup_cpu (u32 apicid,unsigned long start_ip,int cpu) {if (!acpi_mp_wake_mailbox_paddr) {pr_warn_once ("No MADT mailbox: cannot bringup secondary CPUs. Booting with kexec?\n" );arch/x86/kernel/apic/apic_noop.c +1
-1@@ -27,7 +27,7 @@ static void noop_send_IPI_allbutself(int vector) { }static void noop_send_IPI_all (int vector) { }static void noop_send_IPI_self (int vector) { }static void noop_apic_icr_write (u32 low,u32 id) { } -static int noop_wakeup_secondary_cpu (u32 apicid,unsigned long start_eip) {return -1 ; } +static int noop_wakeup_secondary_cpu (u32 apicid,unsigned long start_eip,int cpu) {return -1 ; }static u64 noop_apic_icr_read (void ) {return 0 ; }static u32 noop_get_apic_id (u32 apicid) {return 0 ; }static void noop_apic_eoi (void ) { }arch/x86/kernel/apic/x2apic_uv_x.c +1
-1@@ -667,7 +667,7 @@ static __init void build_uv_gr_table(void) } } -static int uv_wakeup_secondary (u32 phys_apicid,unsigned long start_rip) +static int uv_wakeup_secondary (u32 phys_apicid,unsigned long start_rip,int cpu) {unsigned long val;int pnode;arch/x86/kernel/smpboot.c +4
-4@@ -715,7 +715,7 @@ static void send_init_sequence(u32 phys_apicid)/* * Wake up AP by INIT, INIT, STARTUP sequence. */ -static int wakeup_secondary_cpu_via_init (u32 phys_apicid,unsigned long start_eip) +static int wakeup_secondary_cpu_via_init (u32 phys_apicid,unsigned long start_eip,int cpu) {unsigned long send_status =0 , accept_status =0 ;int num_starts, j, maxlvt;@@ -916,11 +916,11 @@ static int do_boot_cpu(u32 apicid, int cpu, struct task_struct *idle)* - Use an INIT boot APIC message */ if (apic->wakeup_secondary_cpu_64) - ret = apic->wakeup_secondary_cpu_64 (apicid, start_ip); + ret = apic->wakeup_secondary_cpu_64 (apicid, start_ip, cpu);else if (apic->wakeup_secondary_cpu) - ret = apic->wakeup_secondary_cpu (apicid, start_ip); + ret = apic->wakeup_secondary_cpu (apicid, start_ip, cpu);else - ret =wakeup_secondary_cpu_via_init (apicid, start_ip); + ret =wakeup_secondary_cpu_via_init (apicid, start_ip, cpu);/* If the wakeup mechanism failed, cleanup the warm reset vector */ if (ret)base-commit:
628cc040b3a2980df6032766e8ef0688e981ab95
Signature · 2 lines
Thank you, Roman
arch/x86/coco/sev/core.c static void snp_cleanup_vmsa(struct sev_es_save_area *vmsa, int apic_id) · line 1182
Quoted 2 lines · Roman Kisel
arch/x86/coco/sev/core.c +1
-1-static int wakeup_cpu_via_vmgexit (u32 apic_id,unsigned long start_ip) +static int wakeup_cpu_via_vmgexit (u32 apic_id,unsigned long start_ip,int cpu)
unsigned int cpu please. There are no negative CPU numbers yet :)
Quoted 15 lines
{
arch/x86/coco/sev/core.c +1
-1struct sev_es_save_area *cur_vmsa, *vmsa;struct ghcb_state state;@@ -1187,7 +1187,7 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip)unsigned long flags;struct ghcb *ghcb;u8 sipi_vector; -int cpu, ret; +int ret;u64 cr4;/* @@ -1208,15 +1208,6 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip)/* Override start_ip with known protected guest start IP */
arch/x86/coco/sev/core.c static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip) · line 1219
Quoted 10 lines
arch/x86/coco/sev/core.c +0
-9start_ip = real_mode_header->sev_es_trampoline_start; - -/* Find the logical CPU for the APIC ID */ -for_each_present_cpu (cpu) { -if (arch_match_cpu_phys_id (cpu, apic_id)) -break ; - } -if (cpu >= nr_cpu_ids) -return -EINVAL ; -
I just looked what arch_match_cpu_phys_id() actually does and I couldn't help myself to get a fit of laughter. x86 uses the weak default function in drivers/of/cpu.c:
bool __weak arch_match_cpu_phys_id(int cpu, u64 phys_id)
{
return (u32)phys_id == cpu;
}So this loop is the most convoluted way to write:
cpu = apic_id;
which is valid because the to be started CPU must be present, no?
I'm not opposed against the CPU number argument per se, but the justification for it is dubious at best.
Thanks,
tglx
Quoted 36 lines · Thomas Gleixner
arch/x86/coco/sev/core.c static void snp_cleanup_vmsa(struct sev_es_save_area *vmsa, int apic_id) · line 1182
Quoted 2 lines · Roman Kisel
arch/x86/coco/sev/core.c +1
-1-static int wakeup_cpu_via_vmgexit (u32 apic_id,unsigned long start_ip) +static int wakeup_cpu_via_vmgexit (u32 apic_id,unsigned long start_ip,int cpu)unsigned int cpu please. There are no negative CPU numbers yet :)
Quoted 15 lines
{
arch/x86/coco/sev/core.c +1
-1struct sev_es_save_area *cur_vmsa, *vmsa;struct ghcb_state state;@@ -1187,7 +1187,7 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip)unsigned long flags;struct ghcb *ghcb;u8 sipi_vector; -int cpu, ret; +int ret;u64 cr4;/* @@ -1208,15 +1208,6 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip)/* Override start_ip with known protected guest start IP */ arch/x86/coco/sev/core.c static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip) · line 1219
Quoted 10 lines
arch/x86/coco/sev/core.c +0
-9start_ip = real_mode_header->sev_es_trampoline_start; - -/* Find the logical CPU for the APIC ID */ -for_each_present_cpu (cpu) { -if (arch_match_cpu_phys_id (cpu, apic_id)) -break ; - } -if (cpu >= nr_cpu_ids) -return -EINVAL ; -I just looked what
arch_match_cpu_phys_id()actually does and I couldn't help myself to get a fit of laughter. x86 uses the weak default function indrivers/of/cpu.c:
Quoted 4 lines
bool
__weakarch_match_cpu_phys_id(int cpu, u64 phys_id){ return (u32)phys_id == cpu; }
There is an x86 version of this function in arch/x86/kernel/cpu/topology.c that overrides the __weak definition and does:
bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
{
return phys_id == (u64)cpuid_to_apicid[cpu];
}Thanks,
Tom
Quoted 13 lines
So this loop is the most convoluted way to write:
cpu = apic_id;which is valid because the to be started CPU must be present, no?
I'm not opposed against the CPU number argument per se, but the justification for it is dubious at best.
Thanks,
tglx
Quoted 6 lines · Tom Lendacky
Quoted 4 lines · Thomas Gleixner
bool
__weakarch_match_cpu_phys_id(int cpu, u64 phys_id){ return (u32)phys_id == cpu; }
Quoted 7 lines
There is an x86 version of this function in
arch/x86/kernel/cpu/topology.cthat overrides the__weakdefinition and does:bool
arch_match_cpu_phys_id(int cpu, u64 phys_id){ return phys_id == (u64)cpuid_to_apicid[cpu]; }
Oops. I missed that somehow. So yes, aside of the signed/unsigned thing this looks fine.
Thanks,
tglx
Quoted 10 lines · Thomas Gleixner
Quoted 9 lines · Tom Lendacky
Quoted 4 lines · Thomas Gleixner
bool
__weakarch_match_cpu_phys_id(int cpu, u64 phys_id){ return (u32)phys_id == cpu; }There is an x86 version of this function in
arch/x86/kernel/cpu/topology.cthat overrides the__weakdefinition and does:
Quoted 8 lines
Quoted 4 lines
bool
arch_match_cpu_phys_id(int cpu, u64 phys_id){ return phys_id == (u64)cpuid_to_apicid[cpu]; }Oops. I missed that somehow. So yes, aside of the signed/unsigned thing this looks fine.
Thomas,
Thanks a lot for the review! Will fix that in the next version.
Quoted 4 lines
Thanks,
tglx
Signature · 2 lines
Thank you, Roman