[PATCH 06 of 17] Move kvm_create_kernel_phys_mem to libkvm-x86.c

Jerone Young
2007-11-06T16:48:47Z

# Date 1194367649 21600
# Node ID 7ea01f673a05fe66cb0d9c514b5a43ddcd72c07f
# Parent 4bab1bb82930ade04b5a796ca79e75e392265ba7
Move kvm_create_kernel_phys_mem to libkvm-x86.c

This patch moves kvm_create_kernel_phys_mem to x86 as this is
the only arch that will be allocating memory for guest in the
kernel (at least for older kvm versions).

Signed-off-by: Jerone Young <jeroney-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h
--- a/libkvm/kvm-x86.h
+++ b/libkvm/kvm-x86.h
@@ -20,6 +20,8 @@

#include "kvm-common.h"

+#include "kvm-common.h"
+
#define PAGE_SIZE 4096ul
#define PAGE_MASK (~(PAGE_SIZE - 1))

@@ -33,4 +35,7 @@ int kvm_set_tss_addr(kvm_context_t kvm,
int kvm_set_tss_addr(kvm_context_t kvm, unsigned long addr);

+void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
+ unsigned long len, int log, int writable);
+
#endif
diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c
--- a/libkvm/libkvm-x86.c
+++ b/libkvm/libkvm-x86.c
@@ -261,4 +261,36 @@ int kvm_arch_create(kvm_context_t kvm, u
return 0;
}

-
+void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
+ unsigned long len, int log, int writable)
+{
+ int r;
+ int prot = PROT_READ;
+ void *ptr;
+ struct kvm_memory_region memory = {
+ .memory_size = len,
+ .guest_phys_addr = phys_start,
+ .flags = log ? KVM_MEM_LOG_DIRTY_PAGES : 0,
+ };
+
+ memory.slot = get_free_slot(kvm);
+ r = ioctl(kvm->vm_fd, KVM_SET_MEMORY_REGION, &memory);
+ if (r == -1) {
+ fprintf(stderr, "create_kernel_phys_mem: %s", strerror(errno));
+ return 0;
+ }
+ register_slot(memory.slot, memory.guest_phys_addr);
+ kvm_memory_region_save_params(kvm, &memory);
+
+ if (writable)
+ prot |= PROT_WRITE;
+
+ ptr = mmap(NULL, len, prot, MAP_SHARED, kvm->vm_fd, phys_start);
+ if (ptr == MAP_FAILED) {
+ fprintf(stderr, "create_kernel_phys_mem: %s", strerror(errno));
+ return 0;
+ }
+
+ return ptr;
+}
+
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -399,38 +399,6 @@ int kvm_create(kvm_context_t kvm, unsign
return 0;
}

-void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
- unsigned long len, int log, int writable)
-{
- int r;
- int prot = PROT_READ;
- void *ptr;
- struct kvm_memory_region memory = {
- .memory_size = len,
- .guest_phys_addr = phys_start,
- .flags = log ? KVM_MEM_LOG_DIRTY_PAGES : 0,
- };
-
- memory.slot = get_free_slot(kvm);
- r = ioctl(kvm->vm_fd, KVM_SET_MEMORY_REGION, &memory);
- if (r == -1) {
- fprintf(stderr, "create_kernel_phys_mem: %s", strerror(errno));
- return 0;
- }
- register_slot(memory.slot, memory.guest_phys_addr);
- kvm_memory_region_save_params(kvm, &memory);
-
- if (writable)
- prot |= PROT_WRITE;
-
- ptr = mmap(NULL, len, prot, MAP_SHARED, kvm->vm_fd, phys_start);
- if (ptr == MAP_FAILED) {
- fprintf(stderr, "create_kernel_phys_mem: %s", strerror(errno));
- return 0;
- }
-
- return ptr;
-}

#ifdef KVM_CAP_USER_MEMORY