x86/hyperv: Avoid erroneously sending IPI to 'self'
Subsystems (3)
PATCH 1/1 x86/hyperv: Avoid erroneously sending IPI to 'self'
__send_ipi_mask_ex() uses an optimization: when the target CPU mask is equal to 'cpu_present_mask' it uses 'HV_GENERIC_SET_ALL' format to avoid converting the specified cpumask to VP_SET. This case was overlooked when 'exclude_self' parameter was added. As the result, a spurious IPI to 'self' can be send.
--- arch/x86/hyperv/hv_apic.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
arch/x86/hyperv/hv_apic.c +15 -5
@@ -122,17 +122,27 @@ static bool __send_ipi_mask_ex(const struct cpumask *mask, int vector, ipi_arg->reserved =0 ; ipi_arg->vp_set.valid_bank_mask =0 ; -if (!cpumask_equal (mask, cpu_present_mask)) { +/* +* Use HV_GENERIC_SET_ALL and avoid converting cpumask to VP_SET +* when the IPI is sent to all currently present CPUs. +*/ +if (!cpumask_equal (mask, cpu_present_mask) || exclude_self) { ipi_arg->vp_set.format =HV_GENERIC_SET_SPARSE_4K ;if (exclude_self) nr_bank =cpumask_to_vpset_noself (&(ipi_arg->vp_set), mask);else nr_bank =cpumask_to_vpset (&(ipi_arg->vp_set), mask); - } -if (nr_bank <0 ) - goto ipi_mask_ex_done; -if (!nr_bank) + +/* +* 'nr_bank <= 0' means some CPUs in cpumask can't be +* represented in VP_SET. Return an error and fall back to +* native (architectural) method of sending IPIs. +*/ +if (nr_bank <=0 ) + goto ipi_mask_ex_done; + }else { ipi_arg->vp_set.format =HV_GENERIC_SET_ALL ; + } status =hv_do_rep_hypercall (HVCALL_SEND_IPI_EX ,0 , nr_bank, ipi_arg,NULL );
Signature · 1 line
2.31.1
From: Vitaly Kuznetsov <[email protected]> Sent: Wednesday, October 6, 2021 5:50 AM
Quoted 52 lines
__send_ipi_mask_ex()uses an optimization: when the target CPU mask is equal to 'cpu_present_mask' it uses 'HV_GENERIC_SET_ALL' format to avoid converting the specified cpumask toVP_SET. This case was overlooked when 'exclude_self' parameter was added. As the result, a spurious IPI to 'self' can be send.Reported-by Thomas Gleixner <[email protected]>Fixes dfb5c1e12c28 ("x86/hyperv: remove on-stack cpumask from hv_send_ipi_mask_allbutself")Signed-off-by Vitaly Kuznetsov <[email protected]>--- arch/x86/hyperv/hv_apic.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)arch/x86/hyperv/hv_apic.c +15
-6@@ -122,17 +122,27 @@ static bool __send_ipi_mask_ex(const struct cpumask *mask, int vector, ipi_arg->reserved =0 ; ipi_arg->vp_set.valid_bank_mask =0 ; -if (!cpumask_equal (mask, cpu_present_mask)) { +/* +* Use HV_GENERIC_SET_ALL and avoid converting cpumask to VP_SET +* when the IPI is sent to all currently present CPUs. +*/ +if (!cpumask_equal (mask, cpu_present_mask) || exclude_self) { ipi_arg->vp_set.format =HV_GENERIC_SET_SPARSE_4K ;if (exclude_self) nr_bank =cpumask_to_vpset_noself (&(ipi_arg->vp_set), mask);else nr_bank =cpumask_to_vpset (&(ipi_arg->vp_set), mask); - } -if (nr_bank <0 ) - goto ipi_mask_ex_done; -if (!nr_bank) + +/* +* 'nr_bank <= 0' means some CPUs in cpumask can't be +* represented in VP_SET. Return an error and fall back to +* native (architectural) method of sending IPIs. +*/ +if (nr_bank <=0 ) + goto ipi_mask_ex_done; + }else { ipi_arg->vp_set.format =HV_GENERIC_SET_ALL ; + } status =hv_do_rep_hypercall (HVCALL_SEND_IPI_EX ,0 , nr_bank, ipi_arg,NULL ); --
Quoted 1 line
2.31.1
Quoted 1 line · Michael Kelley
From: Vitaly Kuznetsov <[email protected]> Sent: Wednesday, October 6, 2021 5:50 AM
[...]
Quoted 4 lines
Quoted 2 lines
--
2.31.1Reviewed-by Michael Kelley <[email protected]>
LGTM.
Applied to hyperv-fixes. Thanks.
Wei.