Re: [patch] kvmctl.c: allow custom memory setup.

Gerd Hoffmann
2007-10-18T15:29:19Z

[-- Attachment #1: Type: text/plain, Size: 341 bytes --]

Avi Kivity wrote:
> Gerd Hoffmann wrote:
>> No, I'm hacking up one more user ;)
>
> Nice. What will it do?

Run xenified guest kernels without Xen.

>> Should I send an updated patch or do you just drop these lines when
>> merging?
>
> Please send a rebased and retested patch.

Oh, -47 is there. Updated patch attached.

cheers,
Gerd

[-- Attachment #2: kvm.diff --]
[-- Type: text/x-patch, Size: 3659 bytes --]

diff -up ./kvmctl.h.upstream ./kvmctl.h
--- ./kvmctl.h.upstream 2007-10-18 17:09:06.000000000 +0200
+++ ./kvmctl.h 2007-10-18 17:09:11.000000000 +0200
@@ -146,6 +146,9 @@ int kvm_get_shadow_pages(kvm_context_t k
int kvm_create(kvm_context_t kvm,
unsigned long phys_mem_bytes,
void **phys_mem);
+int kvm_create_vm(kvm_context_t kvm);
+void kvm_create_irqchip(kvm_context_t kvm);
+
/*!
* \brief Create a new virtual cpu
*
@@ -413,6 +416,9 @@ void *kvm_create_phys_mem(kvm_context_t,
unsigned long len, int slot, int log, int writable);
void kvm_destroy_phys_mem(kvm_context_t, unsigned long phys_start,
unsigned long len, int slot);
+int kvm_register_userspace_phys_mem(kvm_context_t kvm,
+ unsigned long phys_start, void *userspace_addr,
+ unsigned long len, int slot, int log);
int kvm_get_dirty_pages(kvm_context_t, int slot, void *buf);

diff -up ./kvmctl.c.upstream ./kvmctl.c
--- ./kvmctl.c.upstream 2007-10-18 17:08:57.000000000 +0200
+++ ./kvmctl.c 2007-10-18 17:18:53.000000000 +0200
@@ -436,12 +436,9 @@ int kvm_alloc_userspace_memory(kvm_conte

#endif

-int kvm_create(kvm_context_t kvm, unsigned long phys_mem_bytes, void **vm_mem)
+int kvm_create_vm(kvm_context_t kvm)
{
- unsigned long memory = (phys_mem_bytes + PAGE_SIZE - 1) & PAGE_MASK;
int fd = kvm->fd;
- int zfd;
- int r;

kvm->vcpu_fd[0] = -1;

@@ -451,6 +448,15 @@ int kvm_create(kvm_context_t kvm, unsign
return -1;
}
kvm->vm_fd = fd;
+ return 0;
+}
+
+int kvm_create_default_phys_mem(kvm_context_t kvm, unsigned long phys_mem_bytes,
+ void **vm_mem)
+{
+ unsigned long memory = (phys_mem_bytes + PAGE_SIZE - 1) & PAGE_MASK;
+ int zfd;
+ int r;

#ifdef KVM_CAP_USER_MEMORY
r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY);
@@ -468,13 +474,19 @@ int kvm_create(kvm_context_t kvm, unsign
close(zfd);

kvm->physical_memory = *vm_mem;
+ return 0;
+}
+
+void kvm_create_irqchip(kvm_context_t kvm)
+{
+ int r;

kvm->irqchip_in_kernel = 0;
#ifdef KVM_CAP_IRQCHIP
if (!kvm->no_irqchip_creation) {
r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_IRQCHIP);
if (r > 0) { /* kernel irqchip supported */
- r = ioctl(fd, KVM_CREATE_IRQCHIP);
+ r = ioctl(kvm->vm_fd, KVM_CREATE_IRQCHIP);
if (r >= 0)
kvm->irqchip_in_kernel = 1;
else
@@ -482,6 +494,19 @@ int kvm_create(kvm_context_t kvm, unsign
}
}
#endif
+}
+
+int kvm_create(kvm_context_t kvm, unsigned long phys_mem_bytes, void **vm_mem)
+{
+ int r;
+
+ r = kvm_create_vm(kvm);
+ if (r < 0)
+ return r;
+ r = kvm_create_default_phys_mem(kvm, phys_mem_bytes, vm_mem);
+ if (r < 0)
+ return r;
+ kvm_create_irqchip(kvm);
r = kvm_create_vcpu(kvm, 0);
if (r < 0)
return r;
@@ -577,6 +602,32 @@ void *kvm_create_phys_mem(kvm_context_t
log, writable);
}

+int kvm_register_userspace_phys_mem(kvm_context_t kvm,
+ unsigned long phys_start, void *userspace_addr,
+ unsigned long len, int slot, int log)
+{
+ struct kvm_userspace_memory_region memory = {
+ .slot = slot,
+ .memory_size = len,
+ .guest_phys_addr = phys_start,
+ .userspace_addr = (intptr_t)userspace_addr,
+ .flags = log ? KVM_MEM_LOG_DIRTY_PAGES : 0,
+ };
+ int r;
+
+ if (!kvm->physical_memory)
+ kvm->physical_memory = userspace_addr - phys_start;
+
+ r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &memory);
+ if (r == -1) {
+ fprintf(stderr, "create_userspace_phys_mem: %s\n", strerror(errno));
+ return -1;
+ }
+
+ kvm_userspace_memory_region_save_params(kvm, &memory);
+ return 0;
+}
+
/* destroy/free a whole slot.
* phys_start, len and slot are the params passed to kvm_create_phys_mem()
*/

[-- Attachment #3: Type: text/plain, Size: 314 bytes --]

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

[-- Attachment #4: Type: text/plain, Size: 186 bytes --]

_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org