linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Wanpeng Li <kernellwp@gmail.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: "Radim Krčmář" <rkrcmar@redhat.com>,
	"Vitaly Kuznetsov" <vkuznets@redhat.com>
Subject: Re: [PATCH v5 3/6] KVM: X86: Fallback to original apic hooks when bad happens
Date: Thu, 2 Aug 2018 15:01:44 +0200	[thread overview]
Message-ID: <1059c3b2-3c4a-4218-eee2-d6fc748b99db@redhat.com> (raw)
In-Reply-To: <1532327996-17619-4-git-send-email-wanpengli@tencent.com>

On 23/07/2018 08:39, Wanpeng Li wrote:
> From: Wanpeng Li <wanpengli@tencent.com>
> 
> Fallback to original apic hooks when unlikely kvm fails to add the
> pending IRQ to lapic.
> 
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> ---
>  arch/x86/kernel/kvm.c | 20 +++++++++++++-------
>  1 file changed, 13 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> index eed6046..57eb4a2 100644
> --- a/arch/x86/kernel/kvm.c
> +++ b/arch/x86/kernel/kvm.c
> @@ -47,6 +47,7 @@
>  #include <asm/hypervisor.h>
>  #include <asm/kvm_guest.h>
>  
> +static struct apic orig_apic;
>  static int kvmapf = 1;
>  
>  static int __init parse_no_kvmapf(char *arg)
> @@ -454,10 +455,10 @@ static void __init sev_map_percpu_data(void)
>  }
>  
>  #ifdef CONFIG_SMP
> -static void __send_ipi_mask(const struct cpumask *mask, int vector)
> +static int __send_ipi_mask(const struct cpumask *mask, int vector)
>  {
>  	unsigned long flags;
> -	int cpu, apic_id, min = 0, max = 0;
> +	int cpu, apic_id, min = 0, max = 0, ret = 0;
>  #ifdef CONFIG_X86_64
>  	__uint128_t ipi_bitmap = 0;
>  	int cluster_size = 128;
> @@ -467,7 +468,7 @@ static void __send_ipi_mask(const struct cpumask *mask, int vector)
>  #endif
>  
>  	if (cpumask_empty(mask))
> -		return;
> +		return 0;
>  
>  	local_irq_save(flags);
>  
> @@ -481,7 +482,7 @@ static void __send_ipi_mask(const struct cpumask *mask, int vector)
>  		} else if (apic_id < min + cluster_size) {
>  			max = apic_id < max ? max : apic_id;
>  		} else {
> -			kvm_hypercall4(KVM_HC_SEND_IPI, (unsigned long)ipi_bitmap,
> +			ret = kvm_hypercall4(KVM_HC_SEND_IPI, (unsigned long)ipi_bitmap,
>  				(unsigned long)(ipi_bitmap >> BITS_PER_LONG), min, vector);
>  			min = max = apic_id;
>  			ipi_bitmap = 0;
> @@ -490,11 +491,12 @@ static void __send_ipi_mask(const struct cpumask *mask, int vector)
>  	}
>  
>  	if (ipi_bitmap) {
> -		kvm_hypercall4(KVM_HC_SEND_IPI, (unsigned long)ipi_bitmap,
> +		ret = kvm_hypercall4(KVM_HC_SEND_IPI, (unsigned long)ipi_bitmap,
>  			(unsigned long)(ipi_bitmap >> BITS_PER_LONG), min, vector);
>  	}
>  
>  	local_irq_restore(flags);
> +	return ret;
>  }
>  
>  static void kvm_send_ipi_mask(const struct cpumask *mask, int vector)
> @@ -511,7 +513,8 @@ static void kvm_send_ipi_mask_allbutself(const struct cpumask *mask, int vector)
>  	cpumask_copy(&new_mask, mask);
>  	cpumask_clear_cpu(this_cpu, &new_mask);
>  	local_mask = &new_mask;
> -	__send_ipi_mask(local_mask, vector);
> +	if (__send_ipi_mask(local_mask, vector))
> +		orig_apic.send_IPI_mask_allbutself(mask, vector);
>  }
>  
>  static void kvm_send_ipi_allbutself(int vector)
> @@ -521,7 +524,8 @@ static void kvm_send_ipi_allbutself(int vector)
>  
>  static void kvm_send_ipi_all(int vector)
>  {
> -	__send_ipi_mask(cpu_online_mask, vector);
> +	if (__send_ipi_mask(cpu_online_mask, vector))
> +		orig_apic.send_IPI_all(vector);
>  }
>  
>  /*
> @@ -529,6 +533,8 @@ static void kvm_send_ipi_all(int vector)
>   */
>  static void kvm_setup_pv_ipi(void)
>  {
> +	orig_apic = *apic;
> +
>  	apic->send_IPI_mask = kvm_send_ipi_mask;
>  	apic->send_IPI_mask_allbutself = kvm_send_ipi_mask_allbutself;
>  	apic->send_IPI_allbutself = kvm_send_ipi_allbutself;
> 

Is this actually needed?

Paolo

  reply	other threads:[~2018-08-02 13:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-23  6:39 [PATCH v5 0/6] KVM: X86: Implement Exit-less IPIs support Wanpeng Li
2018-07-23  6:39 ` [PATCH v5 1/6] KVM: X86: Add kvm hypervisor init time platform setup callback Wanpeng Li
2018-07-23  6:39 ` [PATCH v5 2/6] KVM: X86: Implement PV IPIs in linux guest Wanpeng Li
2018-07-23  6:39 ` [PATCH v5 3/6] KVM: X86: Fallback to original apic hooks when bad happens Wanpeng Li
2018-08-02 13:01   ` Paolo Bonzini [this message]
2018-07-23  6:39 ` [PATCH v5 4/6] KVM: X86: Implement PV IPIs send hypercall Wanpeng Li
2018-08-02 13:04   ` Paolo Bonzini
2018-08-03  4:09     ` Wanpeng Li
2018-07-23  6:39 ` [PATCH v5 5/6] KVM: X86: Add NMI support to PV IPIs Wanpeng Li
2018-07-23  6:39 ` [PATCH v5 6/6] KVM: X86: Expose PV_SEND_IPI CPUID feature bit to guest Wanpeng Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1059c3b2-3c4a-4218-eee2-d6fc748b99db@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kernellwp@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rkrcmar@redhat.com \
    --cc=vkuznets@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).