This patch refactors the current hypercall infrastructure to better support live
migration and SMP. It eliminates the hypercall page by trapping the UD
exception that would occur if you used the wrong hypercall instruction for the
underlying architecture and replacing it with the right one lazily.
It also introduces the infrastructure to probe for hypercall available via
CPUID leaves 0x40000002 and 0x40000003.
A fall-out of this patch is that the unhandled hypercalls no longer trap to
userspace. There is very little reason though to use a hypercall to communicate
with userspace as PIO or MMIO can be used. There is no code in tree that uses
userspace hypercalls.
void kvm_emulate_cpuid(struct kvm_vcpu *vcpu)
{
int i;
@@ -1632,6 +1575,12 @@ void kvm_emulate_cpuid(struct kvm_vcpu *vcpu)
vcpu->regs[VCPU_REGS_RBX] = 0;
vcpu->regs[VCPU_REGS_RCX] = 0;
vcpu->regs[VCPU_REGS_RDX] = 0;
+
+ if ((function & 0xFFFF0000) == 0x40000000) {
+ emulate_paravirt_cpuid(vcpu, function);
+ goto out;
+ }
+
+static int ud_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
+{
+ int er;
+
+ er = emulate_instruction(&svm->vcpu, kvm_run, 0, 0);
+
+ /* we should only succeed here in the case of hypercalls which
+ cannot generate an MMIO event. MMIO means that the emulator
+ is mistakenly allowing an instruction that should generate
+ a UD fault so it's a bug. */
+ BUG_ON(er == EMULATE_DO_MMIO);
+
+#define KVM_ENOSYS ENOSYS