Karthik_S
Karthik_S

Reputation: 23

Implementing a custom hypercall in kvm

I am very new to Virtualization and of late I have been trying to familiarize myself with the way VMMs operate and how hypercalls are made.

Talking about which I plan to implement a new hypercall in KVM which is installed on my Ubuntu desktop, and in turn can be callable from the guest environment.With this hypercall I plan to just return a string saying "Hello World". At this point,I am clueless about how to make it happen.It would be really helpful if you could please guide me as to how do I go about implementing such a hypercall.Thank you!

Upvotes: 1

Views: 4366

Answers (1)

Yogi
Yogi

Reputation: 476

You can use vmcall instruction in the user program to make a hypercall in KVM. You need to write a handler for this VMCALL in the kvm. If you run a code in guest;

#define VMCALL_ID 100
do_vmcall ()
{
   asm volatile ("vmcall" : "eax"(VMCALL_ID));
}

it will result a trap in the KVM. The kvm will call handle_vmcall function. In the handle_vmcall function you need to write a handler corresponding to this.

int handle_vmcall(struct kvm_vcpu *vcpu)
{
    unsigned eax = kvm_read_register(vcpu, VCPU_REGS_RAX);

    switch (eax) {
        case VMCALL_ID:
            BLAH; break;
        default: BLAH; BLAH;
    }
    return 0;
}

Upvotes: 2

Related Questions