Re: [PATCH v2 03/17] KVM: VMX: Move posted interrupt delivery code to common header
From: Chao Gao
Date: Thu Feb 13 2025 - 01:59:29 EST
>+/*
>+ * Send interrupt to vcpu via posted interrupt way.
>+ * 1. If target vcpu is running(non-root mode), send posted interrupt
>+ * notification to vcpu and hardware will sync PIR to vIRR atomically.
This comment primarily describes what kvm_vcpu_trigger_posted_interrupt() does.
And, it is not entirely accurate, as it is not necessarily the "hardware" that
syncs PIR to vIRR (see case 2 & 3 in the comment in
kvm_vcpu_trigger_posted_interrupt()).
How about:
/*
* Post an interrupt to a vCPU's PIR and trigger the vCPU to process the
* interrupt if necessary.
*/
Other than that, the patch looks good to me
Reviewed-by: Chao Gao <chao.gao@xxxxxxxxx>
>+ * 2. If target vcpu isn't running(root mode), kick it to pick up the
>+ * interrupt from PIR in next vmentry.
>+ */
>+static inline void __vmx_deliver_posted_interrupt(struct kvm_vcpu *vcpu,
>+ struct pi_desc *pi_desc, int vector)
>+{
>+ if (pi_test_and_set_pir(vector, pi_desc))
>+ return;
>+
>+ /* If a previous notification has sent the IPI, nothing to do. */
>+ if (pi_test_and_set_on(pi_desc))
>+ return;
>+
>+ /*
>+ * The implied barrier in pi_test_and_set_on() pairs with the smp_mb_*()
>+ * after setting vcpu->mode in vcpu_enter_guest(), thus the vCPU is
>+ * guaranteed to see PID.ON=1 and sync the PIR to IRR if triggering a
>+ * posted interrupt "fails" because vcpu->mode != IN_GUEST_MODE.
>+ */
>+ kvm_vcpu_trigger_posted_interrupt(vcpu, POSTED_INTR_VECTOR);
>+}
>+