All of lore.kernel.org
 help / color / mirror / Atom feed
* The necessity of injecting a hardware exception reported in VMX IDT vectoring information
@ 2023-04-05  9:34 Li, Xin3
  2023-04-05 12:30 ` Paolo Bonzini
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Li, Xin3 @ 2023-04-05  9:34 UTC (permalink / raw)
  To: kvm@vger.kernel.org
  Cc: Christopherson,, Sean, Paolo Bonzini, Li, Xiaoyao, Yao, Yuan,
	Dong, Eddie, Tian, Kevin, Nakajima, Jun, H.Peter Anvin,
	Mallick, Asit K

The VMCS IDT vectoring information field is used to report basic information
associated with the event that was being delivered when a VM exit occurred.
such an event itself doesn't trigger a VM exit, however, a condition to deliver
the event is not met, e.g., EPT violation.

When the IDT vectoring information field reports a maskable external interrupt,
KVM reinjects this external interrupt after handling the VM exit. Otherwise,
the external interrupt is lost.

KVM handles a hardware exception reported in the IDT vectoring information
field in the same way, which makes nothing wrong. This piece of code is in
__vmx_complete_interrupts():

        case INTR_TYPE_SOFT_EXCEPTION:
                vcpu->arch.event_exit_inst_len = vmcs_read32(instr_len_field);
                fallthrough;
        case INTR_TYPE_HARD_EXCEPTION:
                if (idt_vectoring_info & VECTORING_INFO_DELIVER_CODE_MASK) {
                        u32 err = vmcs_read32(error_code_field);
                        kvm_requeue_exception_e(vcpu, vector, err);
                } else
                        kvm_requeue_exception(vcpu, vector);
                break;

But if KVM just ignores any hardware exception in such a case, the CPU will
re-generate it once it resumes guest execution, which looks cleaner.

The question is, must KVM inject a hardware exception from the IDT vectoring
information field? Is there any correctness issue if KVM does not?

If no correctness issue, it's better to not do it, because the injected event
from IDT vectoring could trigger another exception, i.e., a nested exception,
and after the nested exception is handled, the CPU resumes to re-trigger the
original event, which makes not much sense to inject it.

In addition, the benefits of not doing so are:
1) Less code.
2) Faster execution. Calling kvm_requeue_exception_e()/kvm_requeue_exception()
   consumes a few hundred cycles at least, although it's a rare case with EPT,
   but a lot with shadow (who cares?). And vmx_inject_exception() also has a
   cost.
3) An IDT vectoring could trigger more than one VM exit, e.g., the first is an
   EPT violation, and the second a PML full, KVM needs to reinject it twice
   (extremely rare).

Thanks!
  Xin

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-04-07 20:16 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-05  9:34 The necessity of injecting a hardware exception reported in VMX IDT vectoring information Li, Xin3
2023-04-05 12:30 ` Paolo Bonzini
2023-04-05 18:03   ` Li, Xin3
2023-04-06  7:34     ` Paolo Bonzini
2023-04-07  5:59       ` Li, Xin3
2023-04-06  1:33 ` Sean Christopherson
     [not found]   ` <BYAPR11MB37173810AE3328B5E28A18D795919@BYAPR11MB3717.namprd11.prod.outlook.com>
2023-04-06  7:33     ` Paolo Bonzini
2023-04-06 10:31       ` Yao, Yuan
2023-04-07  6:31       ` Li, Xin3
2023-04-07  7:15   ` Li, Xin3
2023-04-07  7:49 ` Xiaoyao Li
2023-04-07 20:16   ` Sean Christopherson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.