Re: [PATCH v9 12/22] KVM: VMX: Virtualize FRED event_data
From: Chao Gao
Date: Tue Nov 18 2025 - 22:24:22 EST
>diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
>index 4a74c9f64f90..0b5d04c863a8 100644
>--- a/arch/x86/kvm/vmx/vmx.c
>+++ b/arch/x86/kvm/vmx/vmx.c
>@@ -1860,6 +1860,9 @@ void vmx_inject_exception(struct kvm_vcpu *vcpu)
>
> vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, intr_info);
>
>+ if (is_fred_enabled(vcpu))
>+ vmcs_write64(INJECTED_EVENT_DATA, ex->event_data);
I think event_data should be reset to 0 in kvm_clear_exception_queue().
Otherwise, ex->event_data may be stale here, i.e., the event_data from the
previous event may be injected along with the next event.
<snip>
>+
> vmx_clear_hlt(vcpu);
> }
>
> /*
>@@ -950,6 +963,7 @@ void kvm_requeue_exception(struct kvm_vcpu *vcpu, unsigned int nr,
> vcpu->arch.exception.error_code = error_code;
> vcpu->arch.exception.has_payload = false;
> vcpu->arch.exception.payload = 0;
>+ vcpu->arch.exception.event_data = event_data;
If userspace saves guest events (via kvm_vcpu_ioctl_x86_get_vcpu_events())
right after an event is requeued, event_data will be lost (as that uAPI only
saves the payload and KVM doesn't convert the event_data back to a payload
there). So this event will be delivered with incorrect event_data if the
event is restored on another system after migration.
> }
> EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_requeue_exception);
>
>--
>2.51.0
>