diff mbox series

KVM: x86: fix sending PV IPI

Message ID 1646814944-51801-1-git-send-email-lirongqing@baidu.com (mailing list archive)
State New, archived
Headers show
Series KVM: x86: fix sending PV IPI | expand

Commit Message

Li RongQing March 9, 2022, 8:35 a.m. UTC
if apic_id is less than min, and (max - apic_id) is greater than
KVM_IPI_CLUSTER_SIZE, then third check condition is satisfied,

but it should enter last branch, send IPI directly

Fixes: aaffcfd1e82 ("KVM: X86: Implement PV IPIs in linux guest")
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 arch/x86/kernel/kvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Paolo Bonzini March 9, 2022, 9:38 a.m. UTC | #1
On 3/9/22 09:35, Li RongQing wrote:
> if apic_id is less than min, and (max - apic_id) is greater than
> KVM_IPI_CLUSTER_SIZE, then third check condition is satisfied,
> 
> but it should enter last branch, send IPI directly
> 
> Fixes: aaffcfd1e82 ("KVM: X86: Implement PV IPIs in linux guest")
> Signed-off-by: Li RongQing <lirongqing@baidu.com>

So an example is

    apic_id on first iteration = 1
    apic_id on second iteration = KVM_IPI_CLUSTER_SIZE
    apic_id on third iteration = 0

Thanks, this looks good.

Paolo

> ---
>   arch/x86/kernel/kvm.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> index 959f919..8915c93 100644
> --- a/arch/x86/kernel/kvm.c
> +++ b/arch/x86/kernel/kvm.c
> @@ -517,7 +517,7 @@ static void __send_ipi_mask(const struct cpumask *mask, int vector)
>   		} else if (apic_id < min && max - apic_id < KVM_IPI_CLUSTER_SIZE) {
>   			ipi_bitmap <<= min - apic_id;
>   			min = apic_id;
> -		} else if (apic_id < min + KVM_IPI_CLUSTER_SIZE) {
> +		} else if (apic_id > min && apic_id < min + KVM_IPI_CLUSTER_SIZE) {
>   			max = apic_id < max ? max : apic_id;
>   		} else {
>   			ret = kvm_hypercall4(KVM_HC_SEND_IPI, (unsigned long)ipi_bitmap,
Li RongQing April 1, 2022, 8:59 a.m. UTC | #2
> > if apic_id is less than min, and (max - apic_id) is greater than
> > KVM_IPI_CLUSTER_SIZE, then third check condition is satisfied,
> >
> > but it should enter last branch, send IPI directly
> >
> > Fixes: aaffcfd1e82 ("KVM: X86: Implement PV IPIs in linux guest")
> > Signed-off-by: Li RongQing <lirongqing@baidu.com>
> 
> So an example is
> 
>     apic_id on first iteration = 1
>     apic_id on second iteration = KVM_IPI_CLUSTER_SIZE
>     apic_id on third iteration = 0
> 
> Thanks, this looks good.
> 
> Paolo


Ping

thanks

-Li
diff mbox series

Patch

diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index 959f919..8915c93 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -517,7 +517,7 @@  static void __send_ipi_mask(const struct cpumask *mask, int vector)
 		} else if (apic_id < min && max - apic_id < KVM_IPI_CLUSTER_SIZE) {
 			ipi_bitmap <<= min - apic_id;
 			min = apic_id;
-		} else if (apic_id < min + KVM_IPI_CLUSTER_SIZE) {
+		} else if (apic_id > min && apic_id < min + KVM_IPI_CLUSTER_SIZE) {
 			max = apic_id < max ? max : apic_id;
 		} else {
 			ret = kvm_hypercall4(KVM_HC_SEND_IPI, (unsigned long)ipi_bitmap,