Re: [PATCH v2 3/6] KVM: SVM: Inject #HV when restricted injection is active

From: Lai Jiangshan
Date: Sun Sep 22 2024 - 17:56:25 EST


Hello

On Tue, Sep 10, 2024 at 2:05 PM Melody Wang <huibo.wang@xxxxxxx> wrote:

> +static bool __sev_snp_inject(enum inject_type type, struct kvm_vcpu *vcpu)
> +{
> + struct vcpu_svm *svm = to_svm(vcpu);
> + struct kvm_host_map hvdb_map;
> + struct hvdb *hvdb;
> +
> + hvdb = map_hvdb(vcpu, &hvdb_map);
> + if (!hvdb)
> + return false;

old_vector = hvdb->events.vector;

> +
> + hvdb->events.vector = vcpu->arch.interrupt.nr;
> +
> + prepare_hv_injection(svm, hvdb);

The specification recommends saving an HV injection on the following condition:

if (!(type == INJECT_IRQ && old_vector))
prepare_hv_injection(svm, hvdb)

If PendingEvent.Vector was previously non-zero, because the guest has
not yet chosen to acknowledge the interrupt, the previous vector
number can be overwritten by the new vector number without sending
another #HV (regardless of the value of PendingEvent.NoFurtherSignal),
because the guest should already have been informed that a vector was
pending.


> +
> + unmap_hvdb(vcpu, &hvdb_map);
> +
> + return true;
> +}
> +