* [PATCH] KVM: SVM: allocate AVIC data structures based on kvm_amd moduleparameter
@ 2020-02-25 7:54 Paolo Bonzini
2020-02-25 13:45 ` Vitaly Kuznetsov
0 siblings, 1 reply; 4+ messages in thread
From: Paolo Bonzini @ 2020-02-25 7:54 UTC (permalink / raw)
To: linux-kernel, kvm; +Cc: rmuncrief
Even if APICv is disabled at startup, the backing page and ir_list need
to be initialized in case they are needed later. The only case in
which this can be skipped is for userspace irqchip, and that must be
done because avic_init_backing_page dereferences vcpu->arch.apic
(which is NULL for userspace irqchip).
Tested-by: rmuncrief@humanavance.com
Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=206579
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
arch/x86/kvm/svm.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index ad3f5b178a03..bd02526300ab 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -2194,8 +2194,9 @@ static void svm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
static int avic_init_vcpu(struct vcpu_svm *svm)
{
int ret;
+ struct kvm_vcpu *vcpu = &svm->vcpu;
- if (!kvm_vcpu_apicv_active(&svm->vcpu))
+ if (!avic || !irqchip_in_kernel(vcpu->kvm))
return 0;
ret = avic_init_backing_page(&svm->vcpu);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] KVM: SVM: allocate AVIC data structures based on kvm_amd moduleparameter
@ 2020-02-25 9:26 linmiaohe
0 siblings, 0 replies; 4+ messages in thread
From: linmiaohe @ 2020-02-25 9:26 UTC (permalink / raw)
To: Paolo Bonzini
Cc: rmuncrief@humanavance.com, linux-kernel@vger.kernel.org,
kvm@vger.kernel.org
Paolo Bonzini <pbonzini@redhat.com> writes:
>Even if APICv is disabled at startup, the backing page and ir_list need to be initialized in case they are needed later. The only case in which this can be skipped is for userspace irqchip, and that must be done because avic_init_backing_page dereferences vcpu->arch.apic (which is NULL for userspace irqchip).
>
>Tested-by: rmuncrief@humanavance.com
>Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=206579
>Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>---
> arch/x86/kvm/svm.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
>diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index ad3f5b178a03..bd02526300ab 100644
>--- a/arch/x86/kvm/svm.c
>+++ b/arch/x86/kvm/svm.c
>@@ -2194,8 +2194,9 @@ static void svm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) static int avic_init_vcpu(struct vcpu_svm *svm) {
> int ret;
>+ struct kvm_vcpu *vcpu = &svm->vcpu;
>
>- if (!kvm_vcpu_apicv_active(&svm->vcpu))
>+ if (!avic || !irqchip_in_kernel(vcpu->kvm))
> return 0;
>
> ret = avic_init_backing_page(&svm->vcpu);
>--
>1.8.3.1
>
Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] KVM: SVM: allocate AVIC data structures based on kvm_amd moduleparameter
2020-02-25 7:54 [PATCH] KVM: SVM: allocate AVIC data structures based on kvm_amd moduleparameter Paolo Bonzini
@ 2020-02-25 13:45 ` Vitaly Kuznetsov
2020-02-25 14:01 ` Paolo Bonzini
0 siblings, 1 reply; 4+ messages in thread
From: Vitaly Kuznetsov @ 2020-02-25 13:45 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: rmuncrief, linux-kernel, kvm
Paolo Bonzini <pbonzini@redhat.com> writes:
> Even if APICv is disabled at startup, the backing page and ir_list need
> to be initialized in case they are needed later. The only case in
> which this can be skipped is for userspace irqchip, and that must be
> done because avic_init_backing_page dereferences vcpu->arch.apic
> (which is NULL for userspace irqchip).
>
> Tested-by: rmuncrief@humanavance.com
> Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=206579
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> arch/x86/kvm/svm.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index ad3f5b178a03..bd02526300ab 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -2194,8 +2194,9 @@ static void svm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
> static int avic_init_vcpu(struct vcpu_svm *svm)
> {
> int ret;
> + struct kvm_vcpu *vcpu = &svm->vcpu;
>
> - if (!kvm_vcpu_apicv_active(&svm->vcpu))
> + if (!avic || !irqchip_in_kernel(vcpu->kvm))
> return 0;
>
> ret = avic_init_backing_page(&svm->vcpu);
Out of pure curiosity,
when irqchip_in_kernel() is false, can we still get to .update_pi_irte()
(svm_update_pi_irte()) -> get_pi_vcpu_info() -> "vcpu_info->pi_desc_addr
= __sme_set(page_to_phys((*svm)->avic_backing_page));" -> crash! or is
there anything which make this impossible?
The patch is an improvement anyway, so
Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
--
Vitaly
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] KVM: SVM: allocate AVIC data structures based on kvm_amd moduleparameter
2020-02-25 13:45 ` Vitaly Kuznetsov
@ 2020-02-25 14:01 ` Paolo Bonzini
0 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2020-02-25 14:01 UTC (permalink / raw)
To: Vitaly Kuznetsov; +Cc: rmuncrief, linux-kernel, kvm
On 25/02/20 14:45, Vitaly Kuznetsov wrote:
>> int ret;
>> + struct kvm_vcpu *vcpu = &svm->vcpu;
>>
>> - if (!kvm_vcpu_apicv_active(&svm->vcpu))
>> + if (!avic || !irqchip_in_kernel(vcpu->kvm))
>> return 0;
>>
>> ret = avic_init_backing_page(&svm->vcpu);
> Out of pure curiosity,
>
> when irqchip_in_kernel() is false, can we still get to .update_pi_irte()
> (svm_update_pi_irte()) -> get_pi_vcpu_info() -> "vcpu_info->pi_desc_addr
> = __sme_set(page_to_phys((*svm)->avic_backing_page));" -> crash! or is
> there anything which make this impossible?
No, because kvm_arch_irqfd_allowed returns false so you cannot create
any irqfd (svm_update_pi_irte is called when virt/lib/irqbypass.c finds
a match between two eventfds in KVM and VFIO).
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-02-25 14:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-25 7:54 [PATCH] KVM: SVM: allocate AVIC data structures based on kvm_amd moduleparameter Paolo Bonzini
2020-02-25 13:45 ` Vitaly Kuznetsov
2020-02-25 14:01 ` Paolo Bonzini
-- strict thread matches above, loose matches on Subject: below --
2020-02-25 9:26 linmiaohe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox