[PATCH] KVM: SVM: Update destination when updating pi irte

From: dengqiao.joey
Date: Tue May 16 2023 - 08:22:33 EST


Destination of irte will be cleard by IOMMU driver when updating irte.
It will only be set correctly in vcpu_load. IOMMU will deliver the
doorbell message to the wrong physical cpu before vcpu_load is executed.
That means vcpu can not recognize interrupt delivery during the time of
non-root mode.

Signed-off-by: dengqiao.joey <dengqiao.joey@xxxxxxxxxxxxx>
---
arch/x86/kvm/svm/avic.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c
index cfc8ab773025..16fe41429123 100644
--- a/arch/x86/kvm/svm/avic.c
+++ b/arch/x86/kvm/svm/avic.c
@@ -933,8 +933,11 @@ int avic_pi_update_irte(struct kvm *kvm, unsigned int host_irq,
* we can reference to them directly when we update vcpu
* scheduling information in IOMMU irte.
*/
- if (!ret && pi.is_guest_mode)
+ if (!ret && pi.is_guest_mode) {
+ amd_iommu_update_ga(kvm_cpu_get_apicid(svm->vcpu.cpu),
+ true, pi.ir_data);
svm_ir_list_add(svm, &pi);
+ }
} else {
/* Use legacy mode in IRTE */
struct amd_iommu_pi_data pi;
--
2.11.0