mirror of
https://github.com/clearlinux/kvmtool.git
synced 2026-09-06 21:51:49 +00:00
Initialize KVM some more
This patch adds some more KVM initialization code. Doesn't work yet, though. Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
This commit is contained in:
committed by
Will Deacon
parent
4076b0411d
commit
2b0e334253
@@ -8,6 +8,7 @@
|
||||
struct kvm {
|
||||
int fd; /* /dev/kvm */
|
||||
int vmfd;
|
||||
int vcpu_fd;
|
||||
};
|
||||
|
||||
static void die(const char *s)
|
||||
@@ -50,6 +51,7 @@ static struct kvm *kvm__new(void)
|
||||
|
||||
static struct kvm *kvm__init(void)
|
||||
{
|
||||
struct kvm_userspace_memory_region mem;
|
||||
struct kvm *self;
|
||||
int ret;
|
||||
|
||||
@@ -70,9 +72,32 @@ static struct kvm *kvm__init(void)
|
||||
if (!kvm__supports_extension(self, KVM_CAP_USER_MEMORY))
|
||||
die("KVM_CAP_USER_MEMORY");
|
||||
|
||||
mem = (struct kvm_userspace_memory_region) {
|
||||
.slot = 0,
|
||||
.guest_phys_addr = 0x0UL,
|
||||
.memory_size = 64UL * 1024UL * 1024UL,
|
||||
};
|
||||
|
||||
ret = ioctl(self->vmfd, KVM_SET_USER_MEMORY_REGION, &mem, 1);
|
||||
if (ret < 0)
|
||||
die("ioctl(KVM_SET_USER_MEMORY_REGION)");
|
||||
|
||||
self->vcpu_fd = ioctl(self->vmfd, KVM_CREATE_VCPU, 0);
|
||||
if (self->vcpu_fd < 0)
|
||||
die("ioctl(KVM_CREATE_VCPU)");
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
static void kvm__run(struct kvm *self)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = ioctl(self->vcpu_fd, KVM_RUN, 0);
|
||||
if (ret < 0)
|
||||
die("KVM_RUN");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct cpu *cpu;
|
||||
@@ -85,5 +110,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
cpu__reset(cpu);
|
||||
|
||||
kvm__run(kvm);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user