Re: [kvm-devel] [PATCH 00 of 27] Refactor libkvm code Phase 1
Hmm, The problem here is in the case of kvm_create_phys_mem kvm_create_default_phys_mem, most archs from now on should always be allocating guest memory from userspace (at least I think this correct). Now if this is not the case then really adding an architecture hook function to kvm_create_default_phys_mem would also solve this problem. As There is a mmap call that maps memory for video(?), which is something that is just for x86. With the size of these functions being very small, I think it's best to move them for now. Then if someone else does need them they can easily create there own and then we can figure out how to make a common function in this case. Anyone disagree? On Fri, 2007-11-02 at 13:26 +0800, Zhang, Xiantao wrote: Hi Young, Quick hand! For patch 07/27, 09/27, i have some concerns about them. In these two patches you moved the functions kvm_create_kernel_phys_mem, kvm_create_default_phys_mem to x86 arch. But I think it should work well for most archs. As somebody said, S390 may have a very different memory allocation mechanism, but we can't move them directly to x86 arch, because other archs may also need them. We should find another approach to handle them, and make s390 and other archs all happy ! What about your ideas?:) thanks Xiantao -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jerone Young Sent: 2007年11月1日 1:05 To: kvm-devel@lists.sourceforge.net Cc: [EMAIL PROTECTED] Subject: [kvm-devel] [PATCH 00 of 27] Refactor libkvm code Phase 1 Kaniciwa! I am here to once again bring great honorable patches to refactor libkvm x86 code. Patches that I sent in the past for this really took the wrong approach, and also many variables that I was splitting out actually could be shared amongst many architectures. This is the first phase as much of the code is tightly written for x86 but can be reused by other archs, it's just a matter of an agreed upon method. Also since there are about 27 of these lets get through these before moving through more. Signed-off-by: Jerone Young [EMAIL PROTECTED] - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 08 of 20] Move kvm_destroy_phys_mem to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193998499 18000 # Node ID baaa6c2233371bba2d1d67a839747576c013bbe4 # Parent 9ac9f734ec73ca1b5f156250c69741ee2a642718 Move kvm_destroy_phys_mem to libkvm-x86.c Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -323,3 +323,29 @@ void *kvm_create_phys_mem(kvm_context_t log, writable); } +/* destroy/free a whole slot. + * phys_start, len and slot are the params passed to kvm_create_phys_mem() + */ +void kvm_destroy_phys_mem(kvm_context_t kvm, unsigned long phys_start, + unsigned long len) +{ + int slot; + struct kvm_memory_region *mem; + + slot = get_slot(phys_start); + + if (slot = KVM_MAX_NUM_MEM_REGIONS) { + fprintf(stderr, BUG: %s: invalid parameters (slot=%d)\n, + __FUNCTION__, slot); + return; + } + mem = kvm-mem_regions[slot]; + if (phys_start != mem-guest_phys_addr) { + fprintf(stderr, + WARNING: %s: phys_start is 0x%lx expecting 0x%llx\n, + __FUNCTION__, phys_start, mem-guest_phys_addr); + phys_start = mem-guest_phys_addr; + } + kvm_create_phys_mem(kvm, phys_start, 0, 0, 0); +} + diff --git a/libkvm/libkvm-x86.h b/libkvm/libkvm-x86.h new file mode 100644 --- /dev/null +++ b/libkvm/libkvm-x86.h @@ -0,0 +1,14 @@ +/* This header is for x86 functions variables that will be exposed to users. + * DO NOT PLACE FUNCTIONS OR VARIABLES HERE THAT ARE NOT GOING TO EXPOSED TO + * USERS. + */ +#ifndef LIBKVM_X86_H +#define LIBKVM_X86_H + +void *kvm_create_phys_mem(kvm_context_t, unsigned long phys_start, + unsigned long len, int log, int writable); + +void kvm_destroy_phys_mem(kvm_context_t, unsigned long phys_start, + unsigned long len); + +#endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -447,33 +447,6 @@ int kvm_register_userspace_phys_mem(kvm_ #else return -ENOSYS; #endif -} - - -/* destroy/free a whole slot. - * phys_start, len and slot are the params passed to kvm_create_phys_mem() - */ -void kvm_destroy_phys_mem(kvm_context_t kvm, unsigned long phys_start, - unsigned long len) -{ - int slot; - struct kvm_memory_region *mem; - - slot = get_slot(phys_start); - - if (slot = KVM_MAX_NUM_MEM_REGIONS) { - fprintf(stderr, BUG: %s: invalid parameters (slot=%d)\n, - __FUNCTION__, slot); - return; - } - mem = kvm-mem_regions[slot]; - if (phys_start != mem-guest_phys_addr) { - fprintf(stderr, - WARNING: %s: phys_start is 0x%lx expecting 0x%llx\n, - __FUNCTION__, phys_start, mem-guest_phys_addr); - phys_start = mem-guest_phys_addr; - } - kvm_create_phys_mem(kvm, phys_start, 0, 0, 0); } int kvm_create_memory_alias(kvm_context_t kvm, - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 16 of 20] Move kvm_get_apic to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193999289 18000 # Node ID 203ba0a9217f489a3ed43f13fffd3bbe128e5635 # Parent 3bc39db4c42e55ffae1fb2890c0983a518a5990d Move kvm_get_apic to libkvm-x86.c Moves apic function since it is x86 only. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -717,4 +717,12 @@ void kvm_show_regs(kvm_context_t kvm, in sregs.efer); } - +uint64_t kvm_get_apic_base(kvm_context_t kvm, int vcpu) +{ + struct kvm_run *run = kvm-run[vcpu]; + + if (kvm_abi == 10) + return ((struct kvm_run_abi10 *)run)-apic_base; + return run-apic_base; +} + diff --git a/libkvm/libkvm-x86.h b/libkvm/libkvm-x86.h --- a/libkvm/libkvm-x86.h +++ b/libkvm/libkvm-x86.h @@ -70,4 +70,16 @@ void kvm_show_regs(kvm_context_t kvm, in void kvm_show_regs(kvm_context_t kvm, int vcpu); +/*! + * \brief Get the value of the APIC_BASE msr as of last exit to userspace + * + * This gets the APIC_BASE msr as it was on the last exit to userspace. + * + * \param kvm Pointer to the current kvm_context + * \param vcpu Which virtual CPU should get dumped + * \return APIC_BASE msr contents + */ +uint64_t kvm_get_apic_base(kvm_context_t kvm, int vcpu); + + #endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -759,15 +759,6 @@ int kvm_get_interrupt_flag(kvm_context_t return run-if_flag; } -uint64_t kvm_get_apic_base(kvm_context_t kvm, int vcpu) -{ - struct kvm_run *run = kvm-run[vcpu]; - - if (kvm_abi == 10) - return ((struct kvm_run_abi10 *)run)-apic_base; - return run-apic_base; -} - int kvm_is_ready_for_interrupt_injection(kvm_context_t kvm, int vcpu) { struct kvm_run *run = kvm-run[vcpu]; diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -204,17 +204,6 @@ int kvm_get_interrupt_flag(kvm_context_t int kvm_get_interrupt_flag(kvm_context_t kvm, int vcpu); /*! - * \brief Get the value of the APIC_BASE msr as of last exit to userspace - * - * This gets the APIC_BASE msr as it was on the last exit to userspace. - * - * \param kvm Pointer to the current kvm_context - * \param vcpu Which virtual CPU should get dumped - * \return APIC_BASE msr contents - */ -uint64_t kvm_get_apic_base(kvm_context_t kvm, int vcpu); - -/*! * \brief Check if a vcpu is ready for interrupt injection * * This checks if vcpu interrupts are not masked by mov ss or sti. - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 12 of 20] Move abi 10 functions to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193999194 18000 # Node ID a2a901203454cc13f623627f6a38da9f47e386cf # Parent 1a317a4b44a4553f43eeb1165e543396a198fac4 Move abi 10 functions to libkvm-x86.c Move handle_io_abi_10 to libkvm-x86.c Move handle_mmio_abi10 to libkvm-x86.c Move kvm_run_abi10 to libkvm-x86.c WARNING: You will get compile warning libkvm-x86.c:561: warning: implicit declaration of function âkvm_show_codeâ Until you apply the kvm_show_code patch. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h --- a/libkvm/kvm-x86.h +++ b/libkvm/kvm-x86.h @@ -41,4 +41,6 @@ void *kvm_create_kernel_phys_mem(kvm_con void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start, unsigned long len, int log, int writable); +int kvm_run_abi10(kvm_context_t kvm, int vcpu); + #endif diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -1,6 +1,7 @@ #include libkvm.h #include kvm-x86.h #include kvm-context.h +#include kvm-abi-10.h #include errno.h #include sys/ioctl.h #include string.h @@ -12,6 +13,7 @@ #include sys/types.h #include sys/stat.h #include fcntl.h +#include stdlib.h int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory, void **vm_mem) @@ -408,4 +410,185 @@ int kvm_set_lapic(kvm_context_t kvm, int #endif - +static int handle_io_abi10(kvm_context_t kvm, struct kvm_run_abi10 *run, + int vcpu) +{ + uint16_t addr = run-io.port; + int r; + int i; + void *p = (void *)run + run-io.data_offset; + + for (i = 0; i run-io.count; ++i) { + switch (run-io.direction) { + case KVM_EXIT_IO_IN: + switch (run-io.size) { + case 1: + r = kvm-callbacks-inb(kvm-opaque, addr, p); + break; + case 2: + r = kvm-callbacks-inw(kvm-opaque, addr, p); + break; + case 4: + r = kvm-callbacks-inl(kvm-opaque, addr, p); + break; + default: + fprintf(stderr, bad I/O size %d\n, run-io.size); + return -EMSGSIZE; + } + break; + case KVM_EXIT_IO_OUT: + switch (run-io.size) { + case 1: + r = kvm-callbacks-outb(kvm-opaque, addr, +*(uint8_t *)p); + break; + case 2: + r = kvm-callbacks-outw(kvm-opaque, addr, +*(uint16_t *)p); + break; + case 4: + r = kvm-callbacks-outl(kvm-opaque, addr, +*(uint32_t *)p); + break; + default: + fprintf(stderr, bad I/O size %d\n, run-io.size); + return -EMSGSIZE; + } + break; + default: + fprintf(stderr, bad I/O direction %d\n, run-io.direction); + return -EPROTO; + } + + p += run-io.size; + } + run-io_completed = 1; + + return 0; +} + +static int handle_mmio_abi10(kvm_context_t kvm, struct kvm_run_abi10 *kvm_run) +{ + unsigned long addr = kvm_run-mmio.phys_addr; + void *data = kvm_run-mmio.data; + int r = -1; + + if (kvm_run-mmio.is_write) { + switch (kvm_run-mmio.len) { + case 1: + r = kvm-callbacks-writeb(kvm-opaque, addr, + *(uint8_t *)data); + break; + case 2: + r = kvm-callbacks-writew(kvm-opaque, addr, + *(uint16_t *)data); + break; + case 4: + r = kvm-callbacks-writel(kvm-opaque, addr, + *(uint32_t *)data); + break; + case 8: + r = kvm-callbacks-writeq(kvm-opaque, addr, + *(uint64_t *)data); + break; + } + } else { + switch (kvm_run-mmio.len) { + case 1: + r =
[kvm-devel] [PATCH 20 of 20] Remove unsued inclusion of linux/kvm_parah.h in userspace libkvm.h
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193999598 18000 # Node ID 86353de2387cb0d94f403f8af798d0814d2e176c # Parent 4b9058a7e809c1f463256f47bd499e9a9d990ca8 Remove unsued inclusion of linux/kvm_parah.h in userspace libkvm.h This remove unused code from libkvm.h. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -12,14 +12,6 @@ #endif #include linux/kvm.h - -#define u32 uint32_t /* older kvm_para.h had a u32 exposed */ -#define u64 uint32_t /* older kvm_para.h had a u32 exposed */ -#define PAGE_SIZE 4096 -#include linux/kvm_para.h -#undef u32 -#undef u64 -#undef PAGE_SIZE #include signal.h - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 07 of 20] Move kvm_create_phys_mem to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193998369 18000 # Node ID 9ac9f734ec73ca1b5f156250c69741ee2a642718 # Parent c66785783d56c9aa034de01a3519cf7f42a0f383 Move kvm_create_phys_mem to libkvm-x86.c This patch moves kvm_create_phys_mem to libkvm-x86.c Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -307,3 +307,19 @@ void *kvm_create_kernel_phys_mem(kvm_con return ptr; } +void *kvm_create_phys_mem(kvm_context_t kvm, unsigned long phys_start, + unsigned long len, int log, int writable) +{ +#ifdef KVM_CAP_USER_MEMORY + int r; + + r = ioctl(kvm-fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY); + if (r 0) + return kvm_create_userspace_phys_mem(kvm, phys_start, len, + log, writable); + else +#endif + return kvm_create_kernel_phys_mem(kvm, phys_start, len, + log, writable); +} + diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -417,21 +417,6 @@ void *kvm_create_userspace_phys_mem(kvm_ #endif -void *kvm_create_phys_mem(kvm_context_t kvm, unsigned long phys_start, - unsigned long len, int log, int writable) -{ -#ifdef KVM_CAP_USER_MEMORY - int r; - - r = ioctl(kvm-fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY); - if (r 0) - return kvm_create_userspace_phys_mem(kvm, phys_start, len, - log, writable); - else -#endif - return kvm_create_kernel_phys_mem(kvm, phys_start, len, - log, writable); -} int kvm_register_userspace_phys_mem(kvm_context_t kvm, unsigned long phys_start, void *userspace_addr, diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -26,6 +26,11 @@ struct kvm_context; struct kvm_context; typedef struct kvm_context *kvm_context_t; + +#if defined(__x86_64__) || defined(__i386__) +#include libkvm-x86.h +#endif + /*! * \brief KVM callbacks structure @@ -413,8 +418,6 @@ void kvm_show_regs(kvm_context_t kvm, in void kvm_show_regs(kvm_context_t kvm, int vcpu); -void *kvm_create_phys_mem(kvm_context_t, unsigned long phys_start, - unsigned long len, int log, int writable); void kvm_destroy_phys_mem(kvm_context_t, unsigned long phys_start, unsigned long len); int kvm_register_userspace_phys_mem(kvm_context_t kvm, - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 01 of 20] Move kvm_context to kvmctl.h
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193996153 18000 # Node ID 5900e2b0ebdee721ae651070fcd325363691e25a # Parent 6ce27ddeb45df182e923060ae3abe699ce704ca3 Move kvm_context to kvmctl.h This patch moves kvm_context from libkvm.c to kvm-context.h. This is so other files are able to see members of kvm_context. Also you should allways declare stuff like this in a header anyway. Also moved are delcrations MAX_VCPU, KVM_MAX_NUM_MEM_REGIONS, PAGE_SIZE PAGE_MASK to kvm-x86.h. The idea here is kvm-$(ARCH).h will be headers for interal use by libkvm. Headers name libkvm-$(ARCH) will be functions that are arch specific that will be exposed to a user. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/config-i386.mak b/libkvm/config-i386.mak --- a/libkvm/config-i386.mak +++ b/libkvm/config-i386.mak @@ -1,2 +1,4 @@ LIBDIR := /lib +CFLAGS += -m32 +CFLAGS += -D__i386__ diff --git a/libkvm/config-x86_64.mak b/libkvm/config-x86_64.mak --- a/libkvm/config-x86_64.mak +++ b/libkvm/config-x86_64.mak @@ -1,2 +1,5 @@ LIBDIR := /lib64 +CFLAGS += -m64 +CFLAGS += -D__x86_64__ + diff --git a/libkvm/kvm-context.h b/libkvm/kvm-context.h new file mode 100644 --- /dev/null +++ b/libkvm/kvm-context.h @@ -0,0 +1,31 @@ +#ifndef KVM_CONTEXT_H +#define KVM_CONTEXT_H + +/** + * \brief The KVM context + * + * The verbose KVM context + */ + +struct kvm_context { + /// Filedescriptor to /dev/kvm + int fd; + int vm_fd; + int vcpu_fd[MAX_VCPUS]; + struct kvm_run *run[MAX_VCPUS]; + /// Callbacks that KVM uses to emulate various unvirtualizable functionality + struct kvm_callbacks *callbacks; + void *opaque; + /// A pointer to the memory used as the physical memory for the guest + void *physical_memory; + /// is dirty pages logging enabled for all regions or not + int dirty_pages_log_all; + /// memory regions parameters + struct kvm_memory_region mem_regions[KVM_MAX_NUM_MEM_REGIONS]; + /// do not create in-kernel irqchip if set + int no_irqchip_creation; + /// in-kernel irqchip status + int irqchip_in_kernel; +}; + +#endif diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h new file mode 100644 --- /dev/null +++ b/libkvm/kvm-x86.h @@ -0,0 +1,17 @@ +/* This header is for functions variables that will ONLY be + * used inside libkvm for x86. + * THESE ARE NOT EXPOSED TO THE USER AND ARE ONLY FOR USE + * WITHIN LIBKVM. + */ +#ifndef KVM_X86_H +#define KVM_X86_H + +/* FIXME: share this number with kvm */ +/* FIXME: or dynamically alloc/realloc regions */ +#define KVM_MAX_NUM_MEM_REGIONS 8u +#define MAX_VCPUS 4 + +#define PAGE_SIZE 4096ul +#define PAGE_MASK (~(PAGE_SIZE - 1)) + +#endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -37,43 +37,16 @@ #include libkvm.h #include kvm-abi-10.h +#if defined(__x86_64__) || defined(__i386__) +#include kvm-x86.h +#endif + +#include kvm-context.h + static int kvm_abi = EXPECTED_KVM_API_VERSION; -#define PAGE_SIZE 4096ul -#define PAGE_MASK (~(PAGE_SIZE - 1)) - -/* FIXME: share this number with kvm */ -/* FIXME: or dynamically alloc/realloc regions */ -#define KVM_MAX_NUM_MEM_REGIONS 8u int free_slots[KVM_MAX_NUM_MEM_REGIONS]; unsigned long phys_addr_slots[KVM_MAX_NUM_MEM_REGIONS]; -#define MAX_VCPUS 4 - -/** - * \brief The KVM context - * - * The verbose KVM context - */ -struct kvm_context { - /// Filedescriptor to /dev/kvm - int fd; - int vm_fd; - int vcpu_fd[MAX_VCPUS]; - struct kvm_run *run[MAX_VCPUS]; - /// Callbacks that KVM uses to emulate various unvirtualizable functionality - struct kvm_callbacks *callbacks; - void *opaque; - /// A pointer to the memory used as the physical memory for the guest - void *physical_memory; - /// is dirty pages logging enabled for all regions or not - int dirty_pages_log_all; - /// memory regions parameters - struct kvm_memory_region mem_regions[KVM_MAX_NUM_MEM_REGIONS]; - /// do not create in-kernel irqchip if set - int no_irqchip_creation; - /// in-kernel irqchip status - int irqchip_in_kernel; -}; static void init_slots() { diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -1,4 +1,4 @@ -/** \file kvmctl.h +/** \file libkvm.h * libkvm API */ - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 17 of 20] Move cr8 functions to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193999336 18000 # Node ID ff04bb3d78f2a6163d08448ee15af35fcf8910d4 # Parent 203ba0a9217f489a3ed43f13fffd3bbe128e5635 Move cr8 functions to libkvm-x86.c This patch moves functions: kvm_set_cr8 kvm_get_cr8 cr8 is an x86 only register. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -726,3 +726,19 @@ uint64_t kvm_get_apic_base(kvm_context_t return run-apic_base; } +void kvm_set_cr8(kvm_context_t kvm, int vcpu, uint64_t cr8) +{ + struct kvm_run *run = kvm-run[vcpu]; + + if (kvm_abi == 10) { + ((struct kvm_run_abi10 *)run)-cr8 = cr8; + return; + } + run-cr8 = cr8; +} + +__u64 kvm_get_cr8(kvm_context_t kvm, int vcpu) +{ + return kvm-run[vcpu]-cr8; +} + diff --git a/libkvm/libkvm-x86.h b/libkvm/libkvm-x86.h --- a/libkvm/libkvm-x86.h +++ b/libkvm/libkvm-x86.h @@ -81,5 +81,27 @@ void kvm_show_regs(kvm_context_t kvm, in */ uint64_t kvm_get_apic_base(kvm_context_t kvm, int vcpu); +/*! + * \brief Set up cr8 for next time the vcpu is executed + * + * This is a fast setter for cr8, which will be applied when the + * vcpu next enters guest mode. + * + * \param kvm Pointer to the current kvm_context + * \param vcpu Which virtual CPU should get dumped + * \param cr8 next cr8 value + */ +void kvm_set_cr8(kvm_context_t kvm, int vcpu, uint64_t cr8); + +/*! + * \brief Get cr8 for sync tpr in qemu apic emulation + * + * This is a getter for cr8, which used to sync with the tpr in qemu + * apic emualtion. + * + * \param kvm Pointer to the current kvm_context + * \param vcpu Which virtual CPU should get dumped + */ +__u64 kvm_get_cr8(kvm_context_t kvm, int vcpu); #endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -768,22 +768,6 @@ int kvm_is_ready_for_interrupt_injection return run-ready_for_interrupt_injection; } -void kvm_set_cr8(kvm_context_t kvm, int vcpu, uint64_t cr8) -{ - struct kvm_run *run = kvm-run[vcpu]; - - if (kvm_abi == 10) { - ((struct kvm_run_abi10 *)run)-cr8 = cr8; - return; - } - run-cr8 = cr8; -} - -__u64 kvm_get_cr8(kvm_context_t kvm, int vcpu) -{ - return kvm-run[vcpu]-cr8; -} - int kvm_run(kvm_context_t kvm, int vcpu) { int r; diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -215,29 +215,6 @@ int kvm_is_ready_for_interrupt_injection int kvm_is_ready_for_interrupt_injection(kvm_context_t kvm, int vcpu); /*! - * \brief Set up cr8 for next time the vcpu is executed - * - * This is a fast setter for cr8, which will be applied when the - * vcpu next enters guest mode. - * - * \param kvm Pointer to the current kvm_context - * \param vcpu Which virtual CPU should get dumped - * \param cr8 next cr8 value - */ -void kvm_set_cr8(kvm_context_t kvm, int vcpu, uint64_t cr8); - -/*! - * \brief Get cr8 for sync tpr in qemu apic emulation - * - * This is a getter for cr8, which used to sync with the tpr in qemu - * apic emualtion. - * - * \param kvm Pointer to the current kvm_context - * \param vcpu Which virtual CPU should get dumped - */ -__u64 kvm_get_cr8(kvm_context_t kvm, int vcpu); - -/*! * \brief Read VCPU registers * * This gets the GP registers from the VCPU and outputs them - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 13 of 20] Move msrs functions to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193999237 18000 # Node ID c2350eacb65b258bae26d5dc1888ac4b9917f59f # Parent a2a901203454cc13f623627f6a38da9f47e386cf Move msrs functions to libkvm-x86.c This patch moves functions: kvm_msr_list move kvm_get_msrs move kvm_set_msrs Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h --- a/libkvm/kvm-x86.h +++ b/libkvm/kvm-x86.h @@ -43,4 +43,8 @@ void *kvm_create_kernel_phys_mem(kvm_con int kvm_run_abi10(kvm_context_t kvm, int vcpu); +struct kvm_msr_list *kvm_get_msr_list(kvm_context_t); +int kvm_get_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n); +int kvm_set_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n); + #endif diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -591,4 +591,70 @@ more: return r; } - +/* + * Returns available msr list. User must free. + */ +struct kvm_msr_list *kvm_get_msr_list(kvm_context_t kvm) +{ + struct kvm_msr_list sizer, *msrs; + int r, e; + + sizer.nmsrs = 0; + r = ioctl(kvm-fd, KVM_GET_MSR_INDEX_LIST, sizer); + if (r == -1 errno != E2BIG) + return NULL; + msrs = malloc(sizeof *msrs + sizer.nmsrs * sizeof *msrs-indices); + if (!msrs) { + errno = ENOMEM; + return NULL; + } + msrs-nmsrs = sizer.nmsrs; + r = ioctl(kvm-fd, KVM_GET_MSR_INDEX_LIST, msrs); + if (r == -1) { + e = errno; + free(msrs); + errno = e; + return NULL; + } + return msrs; +} + +int kvm_get_msrs(kvm_context_t kvm, int vcpu, struct kvm_msr_entry *msrs, +int n) +{ +struct kvm_msrs *kmsrs = malloc(sizeof *kmsrs + n * sizeof *msrs); +int r, e; + +if (!kmsrs) { + errno = ENOMEM; + return -1; +} +kmsrs-nmsrs = n; +memcpy(kmsrs-entries, msrs, n * sizeof *msrs); +r = ioctl(kvm-vcpu_fd[vcpu], KVM_GET_MSRS, kmsrs); +e = errno; +memcpy(msrs, kmsrs-entries, n * sizeof *msrs); +free(kmsrs); +errno = e; +return r; +} + +int kvm_set_msrs(kvm_context_t kvm, int vcpu, struct kvm_msr_entry *msrs, +int n) +{ +struct kvm_msrs *kmsrs = malloc(sizeof *kmsrs + n * sizeof *msrs); +int r, e; + +if (!kmsrs) { + errno = ENOMEM; + return -1; +} +kmsrs-nmsrs = n; +memcpy(kmsrs-entries, msrs, n * sizeof *msrs); +r = ioctl(kvm-vcpu_fd[vcpu], KVM_SET_MSRS, kmsrs); +e = errno; +free(kmsrs); +errno = e; +return r; +} + diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -637,73 +637,6 @@ int kvm_set_sregs(kvm_context_t kvm, int return ioctl(kvm-vcpu_fd[vcpu], KVM_SET_SREGS, sregs); } -/* - * Returns available msr list. User must free. - */ -struct kvm_msr_list *kvm_get_msr_list(kvm_context_t kvm) -{ - struct kvm_msr_list sizer, *msrs; - int r, e; - - sizer.nmsrs = 0; - r = ioctl(kvm-fd, KVM_GET_MSR_INDEX_LIST, sizer); - if (r == -1 errno != E2BIG) - return NULL; - msrs = malloc(sizeof *msrs + sizer.nmsrs * sizeof *msrs-indices); - if (!msrs) { - errno = ENOMEM; - return NULL; - } - msrs-nmsrs = sizer.nmsrs; - r = ioctl(kvm-fd, KVM_GET_MSR_INDEX_LIST, msrs); - if (r == -1) { - e = errno; - free(msrs); - errno = e; - return NULL; - } - return msrs; -} - -int kvm_get_msrs(kvm_context_t kvm, int vcpu, struct kvm_msr_entry *msrs, -int n) -{ -struct kvm_msrs *kmsrs = malloc(sizeof *kmsrs + n * sizeof *msrs); -int r, e; - -if (!kmsrs) { - errno = ENOMEM; - return -1; -} -kmsrs-nmsrs = n; -memcpy(kmsrs-entries, msrs, n * sizeof *msrs); -r = ioctl(kvm-vcpu_fd[vcpu], KVM_GET_MSRS, kmsrs); -e = errno; -memcpy(msrs, kmsrs-entries, n * sizeof *msrs); -free(kmsrs); -errno = e; -return r; -} - -int kvm_set_msrs(kvm_context_t kvm, int vcpu, struct kvm_msr_entry *msrs, -int n) -{ -struct kvm_msrs *kmsrs = malloc(sizeof *kmsrs + n * sizeof *msrs); -int r, e; - -if (!kmsrs) { - errno = ENOMEM; - return -1; -} -kmsrs-nmsrs = n; -memcpy(kmsrs-entries, msrs, n * sizeof *msrs); -r = ioctl(kvm-vcpu_fd[vcpu], KVM_SET_MSRS, kmsrs); -e = errno; -free(kmsrs); -errno = e; -return r; -} - static void print_seg(FILE *file, const char *name, struct kvm_segment *seg) { fprintf(stderr, diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -340,10 +340,6 @@ int kvm_get_sregs(kvm_context_t kvm, int */ int kvm_set_sregs(kvm_context_t kvm, int vcpu, struct kvm_sregs *regs); -struct kvm_msr_list
[kvm-devel] [PATCH 06 of 20] Move kvm_create_kernel_phys_mem to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193998359 18000 # Node ID c66785783d56c9aa034de01a3519cf7f42a0f383 # Parent e3def9892f39527f216acbde2de4dad0e8501183 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 [EMAIL PROTECTED] diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h --- a/libkvm/kvm-x86.h +++ b/libkvm/kvm-x86.h @@ -5,6 +5,8 @@ */ #ifndef KVM_X86_H #define KVM_X86_H + +#include kvm-common.h /* FIXME: share this number with kvm */ /* FIXME: or dynamically alloc/realloc regions */ @@ -36,4 +38,7 @@ int kvm_arch_create(kvm_context_t kvm, u int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes, void **vm_mem); +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 @@ -274,4 +274,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 @@ -375,38 +375,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 - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 02 of 20] Make static slot kvm_memory region funcions public
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193996153 18000 # Node ID dfe10a389c131e9cfdfd20765ec1a29cd403aeaf # Parent 5900e2b0ebdee721ae651070fcd325363691e25a Make static slot kvm_memory region funcions public This patch changes static functions for manipulation of memory slots and regions public in kvmctl.c. This also makes a decleration for these functions in kvmctl.h. This allow for breaking out code into other files and still keep this functionality. These functions can later be broken up some to move there x86 specific stuff (ex. TSS). Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h --- a/libkvm/kvm-x86.h +++ b/libkvm/kvm-x86.h @@ -14,4 +14,14 @@ #define PAGE_SIZE 4096ul #define PAGE_MASK (~(PAGE_SIZE - 1)) +void init_slots(); +int get_free_slot(kvm_context_t kvm); +void register_slot(int slot, unsigned long phys_addr); +int get_slot(unsigned long phys_addr); +void kvm_memory_region_save_params(kvm_context_t kvm, + struct kvm_memory_region *mem); +void kvm_userspace_memory_region_save_params(kvm_context_t kvm, + struct kvm_userspace_memory_region *mem); +void kvm_memory_region_clear_params(kvm_context_t kvm, int regnum); + #endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -48,7 +48,7 @@ int free_slots[KVM_MAX_NUM_MEM_REGIONS]; int free_slots[KVM_MAX_NUM_MEM_REGIONS]; unsigned long phys_addr_slots[KVM_MAX_NUM_MEM_REGIONS]; -static void init_slots() +void init_slots() { int i; @@ -56,7 +56,7 @@ static void init_slots() free_slots[i] = 0; } -static int get_free_slot(kvm_context_t kvm) +int get_free_slot(kvm_context_t kvm) { int i; int tss_ext; @@ -83,13 +83,13 @@ static int get_free_slot(kvm_context_t k return -1; } -static void register_slot(int slot, unsigned long phys_addr) +void register_slot(int slot, unsigned long phys_addr) { free_slots[slot] = 1; phys_addr_slots[slot] = phys_addr; } -static int get_slot(unsigned long phys_addr) +int get_slot(unsigned long phys_addr) { int i; @@ -102,7 +102,7 @@ static int get_slot(unsigned long phys_a /* * memory regions parameters */ -static void kvm_memory_region_save_params(kvm_context_t kvm, +void kvm_memory_region_save_params(kvm_context_t kvm, struct kvm_memory_region *mem) { if (!mem || (mem-slot = KVM_MAX_NUM_MEM_REGIONS)) { @@ -114,7 +114,7 @@ static void kvm_memory_region_save_param #ifdef KVM_CAP_USER_MEMORY -static void kvm_userspace_memory_region_save_params(kvm_context_t kvm, +void kvm_userspace_memory_region_save_params(kvm_context_t kvm, struct kvm_userspace_memory_region *mem) { struct kvm_memory_region kvm_mem; @@ -128,7 +128,7 @@ static void kvm_userspace_memory_region_ #endif -static void kvm_memory_region_clear_params(kvm_context_t kvm, int regnum) +void kvm_memory_region_clear_params(kvm_context_t kvm, int regnum) { if (regnum = KVM_MAX_NUM_MEM_REGIONS) { fprintf(stderr, BUG: %s: invalid parameters\n, __FUNCTION__); - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] Spanish soldier goes nude on magazine
Spanish soldier goes nude on magazine cover http://www.maoker.com/n832c57.aspx College girl students graduate to 'body studies' http://www.maoker.com/n835c57.aspx Aniston shares nude scene with Vince http://www.maoker.com/n463c56.aspx Britney Spears plans to commission a nude portrait http://www.maoker.com/n457c57.aspx Sadie Frost's nud e PETA shoot http://www.maoker.com/n454c67.aspx - 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/___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 11 of 20] Make functions in libkvm.c nonstatic
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193998622 18000 # Node ID 1a317a4b44a4553f43eeb1165e543396a198fac4 # Parent ad3abdfa2584ffe4f316987df65ee2130f23551c Make functions in libkvm.c nonstatic. This patch makes the following functions nonstatic. These functions are potentially reusable by other archs, but are need by arch specific code in libkvm-x86.c. These functions include: handle_halt handle_shutdown post_kvm_run pre_kvm_run handle_io_window handle_debug Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/kvm-common.h b/libkvm/kvm-common.h new file mode 100644 --- /dev/null +++ b/libkvm/kvm-common.h @@ -0,0 +1,20 @@ +/* This header is for functions variables that will ONLY be + * used inside libkvm. + * THESE ARE NOT EXPOSED TO THE USER AND ARE ONLY FOR USE + * WITHIN LIBKVM. + */ +#ifndef KVM_COMMON_H +#define KVM_COMMON_H + +void *kvm_create_userspace_phys_mem(kvm_context_t kvm, unsigned long phys_start, + unsigned long len, int log, int writable); + +int handle_halt(kvm_context_t kvm, int vcpu); +int handle_shutdown(kvm_context_t kvm, int vcpu); +void post_kvm_run(kvm_context_t kvm, int vcpu); +int pre_kvm_run(kvm_context_t kvm, int vcpu); +int handle_io_window(kvm_context_t kvm); +int handle_debug(kvm_context_t kvm, int vcpu); +int try_push_interrupts(kvm_context_t kvm); + +#endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -659,7 +659,7 @@ static int handle_io(kvm_context_t kvm, return 0; } -static int handle_debug(kvm_context_t kvm, int vcpu) +int handle_debug(kvm_context_t kvm, int vcpu) { return kvm-callbacks-debug(kvm-opaque, vcpu); } @@ -944,17 +944,17 @@ static int handle_mmio(kvm_context_t kvm return r; } -static int handle_io_window(kvm_context_t kvm) +int handle_io_window(kvm_context_t kvm) { return kvm-callbacks-io_window(kvm-opaque); } -static int handle_halt(kvm_context_t kvm, int vcpu) +int handle_halt(kvm_context_t kvm, int vcpu) { return kvm-callbacks-halt(kvm-opaque, vcpu); } -static int handle_shutdown(kvm_context_t kvm, int vcpu) +int handle_shutdown(kvm_context_t kvm, int vcpu) { return kvm-callbacks-shutdown(kvm-opaque, vcpu); } @@ -964,12 +964,12 @@ int try_push_interrupts(kvm_context_t kv return kvm-callbacks-try_push_interrupts(kvm-opaque); } -static void post_kvm_run(kvm_context_t kvm, int vcpu) +void post_kvm_run(kvm_context_t kvm, int vcpu) { kvm-callbacks-post_kvm_run(kvm-opaque, vcpu); } -static int pre_kvm_run(kvm_context_t kvm, int vcpu) +int pre_kvm_run(kvm_context_t kvm, int vcpu) { return kvm-callbacks-pre_kvm_run(kvm-opaque, vcpu); } - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
Re: [kvm-devel] [BUG] 2.6.23.1 host freezes when running kvm
* Avi Kivity [EMAIL PROTECTED] [071023 10:21]: Thanks, that will be most helpful. If userspace won't compile against some intermediate version, let me know the commit hash and I'll add a fixup. A bisect didn't find anything between 2.6.22 and 2.6.23. Which made me very confused. I think, I must have used the Debian userland tools... which is still bad and I will double check that with 2.6.23. -Bart - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
Re: [kvm-devel] [kvm-ppc-devel] [PATCH 01 of 20] Move kvm_context to kvmctl.h
On Fri, 2007-11-02 at 05:36 -0500, Jerone Young wrote: # HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193996153 18000 # Node ID 5900e2b0ebdee721ae651070fcd325363691e25a # Parent 6ce27ddeb45df182e923060ae3abe699ce704ca3 Move kvm_context to kvmctl.h This patch moves kvm_context from libkvm.c to kvm-context.h. This is so other files are able to see members of kvm_context. Also you should allways declare stuff like this in a header anyway. Also moved are delcrations MAX_VCPU, KVM_MAX_NUM_MEM_REGIONS, PAGE_SIZE PAGE_MASK to kvm-x86.h. The idea here is kvm-$(ARCH).h will be headers for interal use by libkvm. Headers name libkvm-$(ARCH) will be functions that are arch specific that will be exposed to a user. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/config-i386.mak b/libkvm/config-i386.mak --- a/libkvm/config-i386.mak +++ b/libkvm/config-i386.mak @@ -1,2 +1,4 @@ LIBDIR := /lib +CFLAGS += -m32 +CFLAGS += -D__i386__ diff --git a/libkvm/config-x86_64.mak b/libkvm/config-x86_64.mak --- a/libkvm/config-x86_64.mak +++ b/libkvm/config-x86_64.mak @@ -1,2 +1,5 @@ LIBDIR := /lib64 +CFLAGS += -m64 +CFLAGS += -D__x86_64__ These shouldn't be needed since libkvm/Makefile is now including ../user/config.mak . (Questionable IMHO, but that's already committed. :) diff --git a/libkvm/kvm-context.h b/libkvm/kvm-context.h new file mode 100644 --- /dev/null +++ b/libkvm/kvm-context.h @@ -0,0 +1,31 @@ +#ifndef KVM_CONTEXT_H +#define KVM_CONTEXT_H + +/** + * \brief The KVM context + * + * The verbose KVM context + */ + +struct kvm_context { + /// Filedescriptor to /dev/kvm + int fd; + int vm_fd; + int vcpu_fd[MAX_VCPUS]; + struct kvm_run *run[MAX_VCPUS]; + /// Callbacks that KVM uses to emulate various unvirtualizable functionality + struct kvm_callbacks *callbacks; + void *opaque; + /// A pointer to the memory used as the physical memory for the guest + void *physical_memory; + /// is dirty pages logging enabled for all regions or not + int dirty_pages_log_all; + /// memory regions parameters + struct kvm_memory_region mem_regions[KVM_MAX_NUM_MEM_REGIONS]; + /// do not create in-kernel irqchip if set + int no_irqchip_creation; + /// in-kernel irqchip status + int irqchip_in_kernel; +}; + +#endif This doesn't work because kvm_memory_region, MAX_VCPUS, and KVM_MAX_NUM_MEM_REGIONS are undefined here. I don't think kvm_context needs its own header anyways, and combining it into the non-exported kvm-common.h will simplify things. diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h new file mode 100644 --- /dev/null +++ b/libkvm/kvm-x86.h @@ -0,0 +1,17 @@ +/* This header is for functions variables that will ONLY be + * used inside libkvm for x86. + * THESE ARE NOT EXPOSED TO THE USER AND ARE ONLY FOR USE + * WITHIN LIBKVM. + */ +#ifndef KVM_X86_H +#define KVM_X86_H + +/* FIXME: share this number with kvm */ +/* FIXME: or dynamically alloc/realloc regions */ +#define KVM_MAX_NUM_MEM_REGIONS 8u +#define MAX_VCPUS 4 These should be common until proven otherwise, so move into kvm-common.h. +#define PAGE_SIZE 4096ul +#define PAGE_MASK (~(PAGE_SIZE - 1)) + +#endif Userspace should never do this, and should always use getpagesize(2) instead. (I know it's not your fault.) Once you change those two things, kvm-x86.h disappears (unless you need to create it later in the series). -- Hollis Blanchard IBM Linux Technology Center - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
Re: [kvm-devel] [kvm-ppc-devel] [PATCH 01 of 20] Move kvm_context to kvmctl.h
On Fri, 2007-11-02 at 12:28 -0500, Hollis Blanchard wrote: On Fri, 2007-11-02 at 05:36 -0500, Jerone Young wrote: # HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193996153 18000 # Node ID 5900e2b0ebdee721ae651070fcd325363691e25a # Parent 6ce27ddeb45df182e923060ae3abe699ce704ca3 Move kvm_context to kvmctl.h This patch moves kvm_context from libkvm.c to kvm-context.h. This is so other files are able to see members of kvm_context. Also you should allways declare stuff like this in a header anyway. Also moved are delcrations MAX_VCPU, KVM_MAX_NUM_MEM_REGIONS, PAGE_SIZE PAGE_MASK to kvm-x86.h. The idea here is kvm-$(ARCH).h will be headers for interal use by libkvm. Headers name libkvm-$(ARCH) will be functions that are arch specific that will be exposed to a user. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/config-i386.mak b/libkvm/config-i386.mak --- a/libkvm/config-i386.mak +++ b/libkvm/config-i386.mak @@ -1,2 +1,4 @@ LIBDIR := /lib +CFLAGS += -m32 +CFLAGS += -D__i386__ diff --git a/libkvm/config-x86_64.mak b/libkvm/config-x86_64.mak --- a/libkvm/config-x86_64.mak +++ b/libkvm/config-x86_64.mak @@ -1,2 +1,5 @@ LIBDIR := /lib64 +CFLAGS += -m64 +CFLAGS += -D__x86_64__ These shouldn't be needed since libkvm/Makefile is now including ../user/config.mak . (Questionable IMHO, but that's already committed. :) diff --git a/libkvm/kvm-context.h b/libkvm/kvm-context.h new file mode 100644 --- /dev/null +++ b/libkvm/kvm-context.h @@ -0,0 +1,31 @@ +#ifndef KVM_CONTEXT_H +#define KVM_CONTEXT_H + +/** + * \brief The KVM context + * + * The verbose KVM context + */ + +struct kvm_context { + /// Filedescriptor to /dev/kvm + int fd; + int vm_fd; + int vcpu_fd[MAX_VCPUS]; + struct kvm_run *run[MAX_VCPUS]; + /// Callbacks that KVM uses to emulate various unvirtualizable functionality + struct kvm_callbacks *callbacks; + void *opaque; + /// A pointer to the memory used as the physical memory for the guest + void *physical_memory; + /// is dirty pages logging enabled for all regions or not + int dirty_pages_log_all; + /// memory regions parameters + struct kvm_memory_region mem_regions[KVM_MAX_NUM_MEM_REGIONS]; + /// do not create in-kernel irqchip if set + int no_irqchip_creation; + /// in-kernel irqchip status + int irqchip_in_kernel; +}; + +#endif This doesn't work because kvm_memory_region, MAX_VCPUS, and KVM_MAX_NUM_MEM_REGIONS are undefined here. I don't think kvm_context needs its own header anyways, and combining it into the non-exported kvm-common.h will simplify things. Well in libkvm.h the arch header is included before. But since these values may work for everyone for now I can move them and kvm-context to the kvm-common header. diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h new file mode 100644 --- /dev/null +++ b/libkvm/kvm-x86.h @@ -0,0 +1,17 @@ +/* This header is for functions variables that will ONLY be + * used inside libkvm for x86. + * THESE ARE NOT EXPOSED TO THE USER AND ARE ONLY FOR USE + * WITHIN LIBKVM. + */ +#ifndef KVM_X86_H +#define KVM_X86_H + +/* FIXME: share this number with kvm */ +/* FIXME: or dynamically alloc/realloc regions */ +#define KVM_MAX_NUM_MEM_REGIONS 8u +#define MAX_VCPUS 4 These should be common until proven otherwise, so move into kvm-common.h. +#define PAGE_SIZE 4096ul +#define PAGE_MASK (~(PAGE_SIZE - 1)) + +#endif Userspace should never do this, and should always use getpagesize(2) instead. (I know it's not your fault.) Once you change those two things, kvm-x86.h disappears (unless you need to create it later in the series). I'll change this in a patch outside of these patches. - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 09 of 20] Move kvm_create_memory_alias kvm_destroy_memory_alias to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193998505 18000 # Node ID c58b3979cf946fb9c82ddd7d2f480d4d65064b00 # Parent baaa6c2233371bba2d1d67a839747576c013bbe4 Move kvm_create_memory_alias kvm_destroy_memory_alias to libkvm-x86.c Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -349,3 +349,32 @@ void kvm_destroy_phys_mem(kvm_context_t kvm_create_phys_mem(kvm, phys_start, 0, 0, 0); } +int kvm_create_memory_alias(kvm_context_t kvm, + uint64_t phys_addr, + uint64_t phys_start, + uint64_t len, + uint64_t target_phys) +{ + struct kvm_memory_alias alias = { + .flags = 0, + .guest_phys_addr = phys_start, + .memory_size = len, + .target_phys_addr = target_phys, + }; + int fd = kvm-vm_fd; + int r; + + alias.slot = get_slot(phys_addr); + + r = ioctl(fd, KVM_SET_MEMORY_ALIAS, alias); + if (r == -1) + return -errno; + + return 0; +} + +int kvm_destroy_memory_alias(kvm_context_t kvm, uint64_t phys_addr) +{ + return kvm_create_memory_alias(kvm, phys_addr, 0, 0, 0); +} + diff --git a/libkvm/libkvm-x86.h b/libkvm/libkvm-x86.h --- a/libkvm/libkvm-x86.h +++ b/libkvm/libkvm-x86.h @@ -11,4 +11,23 @@ void kvm_destroy_phys_mem(kvm_context_t, void kvm_destroy_phys_mem(kvm_context_t, unsigned long phys_start, unsigned long len); +/*! + * \brief Create a memory alias + * + * Aliases a portion of physical memory to another portion. If the guest + * accesses the alias region, it will behave exactly as if it accessed + * the target memory. + */ +int kvm_create_memory_alias(kvm_context_t, uint64_t phys_addr, + uint64_t phys_start, uint64_t len, + uint64_t target_phys); + +/*! + * \brief Destroy a memory alias + * + * Removes an alias created with kvm_create_memory_alias(). + */ +int kvm_destroy_memory_alias(kvm_context_t, uint64_t phys_addr); + + #endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -447,35 +447,6 @@ int kvm_register_userspace_phys_mem(kvm_ #else return -ENOSYS; #endif -} - -int kvm_create_memory_alias(kvm_context_t kvm, - uint64_t phys_addr, - uint64_t phys_start, - uint64_t len, - uint64_t target_phys) -{ - struct kvm_memory_alias alias = { - .flags = 0, - .guest_phys_addr = phys_start, - .memory_size = len, - .target_phys_addr = target_phys, - }; - int fd = kvm-vm_fd; - int r; - - alias.slot = get_slot(phys_addr); - - r = ioctl(fd, KVM_SET_MEMORY_ALIAS, alias); - if (r == -1) - return -errno; - - return 0; -} - -int kvm_destroy_memory_alias(kvm_context_t kvm, uint64_t phys_addr) -{ - return kvm_create_memory_alias(kvm, phys_addr, 0, 0, 0); } static int kvm_get_map(kvm_context_t kvm, int ioctl_num, int slot, void *buf) diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -427,24 +427,6 @@ int kvm_get_dirty_pages(kvm_context_t, u /*! - * \brief Create a memory alias - * - * Aliases a portion of physical memory to another portion. If the guest - * accesses the alias region, it will behave exactly as if it accessed - * the target memory. - */ -int kvm_create_memory_alias(kvm_context_t, uint64_t phys_addr, - uint64_t phys_start, uint64_t len, - uint64_t target_phys); - -/*! - * \brief Destroy a memory alias - * - * Removes an alias created with kvm_create_memory_alias(). - */ -int kvm_destroy_memory_alias(kvm_context_t, uint64_t phys_addr); - -/*! * \brief Get a bitmap of guest ram pages which are allocated to the guest. * * \param kvm Pointer to the current kvm_context - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 10 of 20] Move kvm_get kmv_set_lapci functions to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193998515 18000 # Node ID ad3abdfa2584ffe4f316987df65ee2130f23551c # Parent c58b3979cf946fb9c82ddd7d2f480d4d65064b00 Move kvm_get kmv_set_lapci functions to libkvm-x86.c Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -378,3 +378,34 @@ int kvm_destroy_memory_alias(kvm_context return kvm_create_memory_alias(kvm, phys_addr, 0, 0, 0); } +#ifdef KVM_CAP_IRQCHIP + +int kvm_get_lapic(kvm_context_t kvm, int vcpu, struct kvm_lapic_state *s) +{ + int r; + if (!kvm-irqchip_in_kernel) + return 0; + r = ioctl(kvm-vcpu_fd[vcpu], KVM_GET_LAPIC, s); + if (r == -1) { + r = -errno; + perror(kvm_get_lapic); + } + return r; +} + +int kvm_set_lapic(kvm_context_t kvm, int vcpu, struct kvm_lapic_state *s) +{ + int r; + if (!kvm-irqchip_in_kernel) + return 0; + r = ioctl(kvm-vcpu_fd[vcpu], KVM_SET_LAPIC, s); + if (r == -1) { + r = -errno; + perror(kvm_set_lapic); + } + return r; +} + +#endif + + diff --git a/libkvm/libkvm-x86.h b/libkvm/libkvm-x86.h --- a/libkvm/libkvm-x86.h +++ b/libkvm/libkvm-x86.h @@ -29,5 +29,30 @@ int kvm_create_memory_alias(kvm_context_ */ int kvm_destroy_memory_alias(kvm_context_t, uint64_t phys_addr); +#ifdef KVM_CAP_IRQCHIP + +/*! + * \brief Get in kernel local APIC for vcpu + * + * Save the local apic state including the timer of a virtual CPU + * + * \param kvm Pointer to the current kvm_context + * \param vcpu Which virtual CPU should be accessed + * \param s Local apic state of the specific virtual CPU + */ +int kvm_get_lapic(kvm_context_t kvm, int vcpu, struct kvm_lapic_state *s); + +/*! + * \brief Set in kernel local APIC for vcpu + * + * Restore the local apic state including the timer of a virtual CPU + * + * \param kvm Pointer to the current kvm_context + * \param vcpu Which virtual CPU should be accessed + * \param s Local apic state of the specific virtual CPU + */ +int kvm_set_lapic(kvm_context_t kvm, int vcpu, struct kvm_lapic_state *s); #endif + +#endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -541,32 +541,6 @@ int kvm_set_irqchip(kvm_context_t kvm, s if (r == -1) { r = -errno; perror(kvm_set_irqchip\n); - } - return r; -} - -int kvm_get_lapic(kvm_context_t kvm, int vcpu, struct kvm_lapic_state *s) -{ - int r; - if (!kvm-irqchip_in_kernel) - return 0; - r = ioctl(kvm-vcpu_fd[vcpu], KVM_GET_LAPIC, s); - if (r == -1) { - r = -errno; - perror(kvm_get_lapic); - } - return r; -} - -int kvm_set_lapic(kvm_context_t kvm, int vcpu, struct kvm_lapic_state *s) -{ - int r; - if (!kvm-irqchip_in_kernel) - return 0; - r = ioctl(kvm-vcpu_fd[vcpu], KVM_SET_LAPIC, s); - if (r == -1) { - r = -errno; - perror(kvm_set_lapic); } return r; } diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -484,27 +484,6 @@ int kvm_get_irqchip(kvm_context_t kvm, s */ int kvm_set_irqchip(kvm_context_t kvm, struct kvm_irqchip *chip); -/*! - * \brief Get in kernel local APIC for vcpu - * - * Save the local apic state including the timer of a virtual CPU - * - * \param kvm Pointer to the current kvm_context - * \param vcpu Which virtual CPU should be accessed - * \param s Local apic state of the specific virtual CPU - */ -int kvm_get_lapic(kvm_context_t kvm, int vcpu, struct kvm_lapic_state *s); - -/*! - * \brief Set in kernel local APIC for vcpu - * - * Restore the local apic state including the timer of a virtual CPU - * - * \param kvm Pointer to the current kvm_context - * \param vcpu Which virtual CPU should be accessed - * \param s Local apic state of the specific virtual CPU - */ -int kvm_set_lapic(kvm_context_t kvm, int vcpu, struct kvm_lapic_state *s); #endif - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 15 of 20] Declare kvm_abi as a global variable in libkvm.h
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193999281 18000 # Node ID 3bc39db4c42e55ffae1fb2890c0983a518a5990d # Parent af69cb5dc23f7cc272678b8e32e80a0bb368822b Declare kvm_abi as a global variable in libkvm.h Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -43,7 +43,7 @@ #include kvm-context.h -static int kvm_abi = EXPECTED_KVM_API_VERSION; +int kvm_abi = EXPECTED_KVM_API_VERSION; int free_slots[KVM_MAX_NUM_MEM_REGIONS]; unsigned long phys_addr_slots[KVM_MAX_NUM_MEM_REGIONS]; diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -30,6 +30,9 @@ typedef struct kvm_context *kvm_context_ #if defined(__x86_64__) || defined(__i386__) #include libkvm-x86.h #endif + +/* kvm abi verison variable */ +extern int kvm_abi; /*! - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 19 of 20] Move kvm_show_code to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193999513 18000 # Node ID 4b9058a7e809c1f463256f47bd499e9a9d990ca8 # Parent 1eeb2919a59229d76aa856e782ebb622aacf5013 Move kvm_show_code to libkvm-x86.c Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h --- a/libkvm/kvm-x86.h +++ b/libkvm/kvm-x86.h @@ -47,4 +47,6 @@ int kvm_get_msrs(kvm_context_t, int vcpu int kvm_get_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n); int kvm_set_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n); +void kvm_show_code(kvm_context_t kvm, int vcpu); + #endif diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -760,3 +760,42 @@ int kvm_setup_cpuid(kvm_context_t kvm, i return r; } +void kvm_show_code(kvm_context_t kvm, int vcpu) +{ +#define CR0_PE_MASK(1ULL0) + int fd = kvm-vcpu_fd[vcpu]; + struct kvm_regs regs; + struct kvm_sregs sregs; + int r; + unsigned char code[50]; + int back_offset; + char code_str[sizeof(code) * 3 + 1]; + unsigned long rip; + + r = ioctl(fd, KVM_GET_SREGS, sregs); + if (r == -1) { + perror(KVM_GET_SREGS); + return; + } + if (sregs.cr0 CR0_PE_MASK) + return; + + r = ioctl(fd, KVM_GET_REGS, regs); + if (r == -1) { + perror(KVM_GET_REGS); + return; + } + rip = sregs.cs.base + regs.rip; + back_offset = regs.rip; + if (back_offset 20) + back_offset = 20; + memcpy(code, kvm-physical_memory + rip - back_offset, sizeof code); + *code_str = 0; + for (r = 0; r sizeof code; ++r) { + if (r == back_offset) + strcat(code_str, --); + sprintf(code_str + strlen(code_str), %02x, code[r]); + } + fprintf(stderr, code:%s\n, code_str); +} + diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -637,45 +637,6 @@ int kvm_set_sregs(kvm_context_t kvm, int return ioctl(kvm-vcpu_fd[vcpu], KVM_SET_SREGS, sregs); } -static void kvm_show_code(kvm_context_t kvm, int vcpu) -{ -#define CR0_PE_MASK(1ULL0) - int fd = kvm-vcpu_fd[vcpu]; - struct kvm_regs regs; - struct kvm_sregs sregs; - int r; - unsigned char code[50]; - int back_offset; - char code_str[sizeof(code) * 3 + 1]; - unsigned long rip; - - r = ioctl(fd, KVM_GET_SREGS, sregs); - if (r == -1) { - perror(KVM_GET_SREGS); - return; - } - if (sregs.cr0 CR0_PE_MASK) - return; - - r = ioctl(fd, KVM_GET_REGS, regs); - if (r == -1) { - perror(KVM_GET_REGS); - return; - } - rip = sregs.cs.base + regs.rip; - back_offset = regs.rip; - if (back_offset 20) - back_offset = 20; - memcpy(code, kvm-physical_memory + rip - back_offset, sizeof code); - *code_str = 0; - for (r = 0; r sizeof code; ++r) { - if (r == back_offset) - strcat(code_str, --); - sprintf(code_str + strlen(code_str), %02x, code[r]); - } - fprintf(stderr, code:%s\n, code_str); -} - static int handle_mmio(kvm_context_t kvm, struct kvm_run *kvm_run) { unsigned long addr = kvm_run-mmio.phys_addr; - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 14 of 20] Move print_seg Move kvm_show_regs to kvmctl-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193999254 18000 # Node ID af69cb5dc23f7cc272678b8e32e80a0bb368822b # Parent c2350eacb65b258bae26d5dc1888ac4b9917f59f Move print_seg Move kvm_show_regs to kvmctl-x86.c This patch moves functions print_seg, kvm_show_regs, print_dt to libkvm-x86.c. Since kvm_show_regs really has little to no shared code (besides an ioctl call and variable declarations), it is best that this be moved into arch specific code. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -658,3 +658,63 @@ int kvm_set_msrs(kvm_context_t kvm, int return r; } +static void print_seg(FILE *file, const char *name, struct kvm_segment *seg) +{ + fprintf(stderr, + %s %04x (%08llx/%08x p %d dpl %d db %d s %d type %x l %d +g %d avl %d)\n, + name, seg-selector, seg-base, seg-limit, seg-present, + seg-dpl, seg-db, seg-s, seg-type, seg-l, seg-g, + seg-avl); +} + +static void print_dt(FILE *file, const char *name, struct kvm_dtable *dt) +{ + fprintf(stderr, %s %llx/%x\n, name, dt-base, dt-limit); +} + +void kvm_show_regs(kvm_context_t kvm, int vcpu) +{ + int fd = kvm-vcpu_fd[vcpu]; + struct kvm_regs regs; + struct kvm_sregs sregs; + int r; + + r = ioctl(fd, KVM_GET_REGS, regs); + if (r == -1) { + perror(KVM_GET_REGS); + return; + } + fprintf(stderr, + rax %016llx rbx %016llx rcx %016llx rdx %016llx\n + rsi %016llx rdi %016llx rsp %016llx rbp %016llx\n + r8 %016llx r9 %016llx r10 %016llx r11 %016llx\n + r12 %016llx r13 %016llx r14 %016llx r15 %016llx\n + rip %016llx rflags %08llx\n, + regs.rax, regs.rbx, regs.rcx, regs.rdx, + regs.rsi, regs.rdi, regs.rsp, regs.rbp, + regs.r8, regs.r9, regs.r10, regs.r11, + regs.r12, regs.r13, regs.r14, regs.r15, + regs.rip, regs.rflags); + r = ioctl(fd, KVM_GET_SREGS, sregs); + if (r == -1) { + perror(KVM_GET_SREGS); + return; + } + print_seg(stderr, cs, sregs.cs); + print_seg(stderr, ds, sregs.ds); + print_seg(stderr, es, sregs.es); + print_seg(stderr, ss, sregs.ss); + print_seg(stderr, fs, sregs.fs); + print_seg(stderr, gs, sregs.gs); + print_seg(stderr, tr, sregs.tr); + print_seg(stderr, ldt, sregs.ldt); + print_dt(stderr, gdt, sregs.gdt); + print_dt(stderr, idt, sregs.idt); + fprintf(stderr, cr0 %llx cr2 %llx cr3 %llx cr4 %llx cr8 %llx +efer %llx\n, + sregs.cr0, sregs.cr2, sregs.cr3, sregs.cr4, sregs.cr8, + sregs.efer); +} + + diff --git a/libkvm/libkvm-x86.h b/libkvm/libkvm-x86.h --- a/libkvm/libkvm-x86.h +++ b/libkvm/libkvm-x86.h @@ -55,4 +55,19 @@ int kvm_set_lapic(kvm_context_t kvm, int #endif +/*! + * \brief Dump VCPU registers + * + * This dumps some of the information that KVM has about a virtual CPU, namely: + * - GP Registers + * + * A much more verbose version of this is available as kvm_dump_vcpu() + * + * \param kvm Pointer to the current kvm_context + * \param vcpu Which virtual CPU should get dumped + * \return 0 on success + */ +void kvm_show_regs(kvm_context_t kvm, int vcpu); + + #endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -637,65 +637,6 @@ int kvm_set_sregs(kvm_context_t kvm, int return ioctl(kvm-vcpu_fd[vcpu], KVM_SET_SREGS, sregs); } -static void print_seg(FILE *file, const char *name, struct kvm_segment *seg) -{ - fprintf(stderr, - %s %04x (%08llx/%08x p %d dpl %d db %d s %d type %x l %d -g %d avl %d)\n, - name, seg-selector, seg-base, seg-limit, seg-present, - seg-dpl, seg-db, seg-s, seg-type, seg-l, seg-g, - seg-avl); -} - -static void print_dt(FILE *file, const char *name, struct kvm_dtable *dt) -{ - fprintf(stderr, %s %llx/%x\n, name, dt-base, dt-limit); -} - -void kvm_show_regs(kvm_context_t kvm, int vcpu) -{ - int fd = kvm-vcpu_fd[vcpu]; - struct kvm_regs regs; - struct kvm_sregs sregs; - int r; - - r = ioctl(fd, KVM_GET_REGS, regs); - if (r == -1) { - perror(KVM_GET_REGS); - return; - } - fprintf(stderr, - rax %016llx rbx %016llx rcx %016llx rdx %016llx\n - rsi %016llx rdi %016llx rsp %016llx rbp %016llx\n - r8 %016llx r9 %016llx r10 %016llx r11 %016llx\n - r12 %016llx r13 %016llx r14 %016llx r15 %016llx\n - rip %016llx rflags %08llx\n, - regs.rax, regs.rbx, regs.rcx, regs.rdx, - regs.rsi, regs.rdi, regs.rsp, regs.rbp, -
[kvm-devel] [PATCH 18 of 20] Move kvm_setup_cpuid to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193999487 18000 # Node ID 1eeb2919a59229d76aa856e782ebb622aacf5013 # Parent ff04bb3d78f2a6163d08448ee15af35fcf8910d4 Move kvm_setup_cpuid to libkvm-x86.c cpuid is an x86 instruction, so needs to go in the approriate place. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -742,3 +742,21 @@ __u64 kvm_get_cr8(kvm_context_t kvm, int return kvm-run[vcpu]-cr8; } +int kvm_setup_cpuid(kvm_context_t kvm, int vcpu, int nent, + struct kvm_cpuid_entry *entries) +{ + struct kvm_cpuid *cpuid; + int r; + + cpuid = malloc(sizeof(*cpuid) + nent * sizeof(*entries)); + if (!cpuid) + return -ENOMEM; + + cpuid-nent = nent; + memcpy(cpuid-entries, entries, nent * sizeof(*entries)); + r = ioctl(kvm-vcpu_fd[vcpu], KVM_SET_CPUID, cpuid); + + free(cpuid); + return r; +} + diff --git a/libkvm/libkvm-x86.h b/libkvm/libkvm-x86.h --- a/libkvm/libkvm-x86.h +++ b/libkvm/libkvm-x86.h @@ -104,4 +104,19 @@ void kvm_set_cr8(kvm_context_t kvm, int */ __u64 kvm_get_cr8(kvm_context_t kvm, int vcpu); +/*! + * \brief Setup a vcpu's cpuid instruction emulation + * + * Set up a table of cpuid function to cpuid outputs.\n + * + * \param kvm Pointer to the current kvm_context + * \param vcpu Which virtual CPU should be initialized + * \param nent number of entries to be installed + * \param entries cpuid function entries table + * \return 0 on success, or -errno on error + */ +int kvm_setup_cpuid(kvm_context_t kvm, int vcpu, int nent, + struct kvm_cpuid_entry *entries); + + #endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -863,24 +863,6 @@ int kvm_guest_debug(kvm_context_t kvm, i return ioctl(kvm-vcpu_fd[vcpu], KVM_DEBUG_GUEST, dbg); } -int kvm_setup_cpuid(kvm_context_t kvm, int vcpu, int nent, - struct kvm_cpuid_entry *entries) -{ - struct kvm_cpuid *cpuid; - int r; - - cpuid = malloc(sizeof(*cpuid) + nent * sizeof(*entries)); - if (!cpuid) - return -ENOMEM; - - cpuid-nent = nent; - memcpy(cpuid-entries, entries, nent * sizeof(*entries)); - r = ioctl(kvm-vcpu_fd[vcpu], KVM_SET_CPUID, cpuid); - - free(cpuid); - return r; -} - int kvm_set_signal_mask(kvm_context_t kvm, int vcpu, const sigset_t *sigset) { struct kvm_signal_mask *sigmask; diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -324,20 +324,6 @@ int kvm_guest_debug(kvm_context_t, int v int kvm_guest_debug(kvm_context_t, int vcpu, struct kvm_debug_guest *dbg); /*! - * \brief Setup a vcpu's cpuid instruction emulation - * - * Set up a table of cpuid function to cpuid outputs.\n - * - * \param kvm Pointer to the current kvm_context - * \param vcpu Which virtual CPU should be initialized - * \param nent number of entries to be installed - * \param entries cpuid function entries table - * \return 0 on success, or -errno on error - */ -int kvm_setup_cpuid(kvm_context_t kvm, int vcpu, int nent, - struct kvm_cpuid_entry *entries); - -/*! * \brief Set a vcpu's signal mask for guest mode * * A vcpu can have different signals blocked in guest mode and user mode. - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 03 of 20] Move fuction kvm_alloc_kernel_memory to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193996847 18000 # Node ID dcf5d603165aad6e5276e3fdda81e1be2a6595ae # Parent dfe10a389c131e9cfdfd20765ec1a29cd403aeaf Move fuction kvm_alloc_kernel_memory to libkvm-x86.c Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/Makefile b/libkvm/Makefile --- a/libkvm/Makefile +++ b/libkvm/Makefile @@ -21,7 +21,7 @@ autodepend-flags = -MMD -MF $(dir $*).$( all: libkvm.a -libkvm.a: libkvm.o +libkvm.a: libkvm.o $(libkvm-$(ARCH)-objs) $(AR) rcs $@ $^ install: diff --git a/libkvm/config-i386.mak b/libkvm/config-i386.mak --- a/libkvm/config-i386.mak +++ b/libkvm/config-i386.mak @@ -2,3 +2,5 @@ LIBDIR := /lib LIBDIR := /lib CFLAGS += -m32 CFLAGS += -D__i386__ + +libkvm-$(ARCH)-objs := libkvm-x86.o diff --git a/libkvm/config-x86_64.mak b/libkvm/config-x86_64.mak --- a/libkvm/config-x86_64.mak +++ b/libkvm/config-x86_64.mak @@ -3,3 +3,4 @@ CFLAGS += -m64 CFLAGS += -m64 CFLAGS += -D__x86_64__ +libkvm-$(ARCH)-objs := libkvm-x86.o diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h --- a/libkvm/kvm-x86.h +++ b/libkvm/kvm-x86.h @@ -24,4 +24,8 @@ void kvm_userspace_memory_region_save_pa struct kvm_userspace_memory_region *mem); void kvm_memory_region_clear_params(kvm_context_t kvm, int regnum); + +int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory, + void **vm_mem); + #endif diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c new file mode 100644 --- /dev/null +++ b/libkvm/libkvm-x86.c @@ -0,0 +1,82 @@ +#include libkvm.h +#include kvm-x86.h +#include kvm-context.h +#include unistd.h +#include stropts.h +#include sys/mman.h +#include stdio.h + +int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory, + void **vm_mem) +{ + unsigned long dosmem = 0xa; + unsigned long exmem = 0xc; + unsigned long pcimem = 0xe000; + int r; + int tss_ext; + struct kvm_memory_region low_memory = { + .memory_size = memory dosmem ? memory : dosmem, + .guest_phys_addr = 0, + }; + struct kvm_memory_region extended_memory = { + .memory_size = memory exmem ? 0 : memory - exmem, + .guest_phys_addr = exmem, + }; + struct kvm_memory_region above_4g_memory = { + .memory_size = memory pcimem ? 0 : memory - pcimem, + .guest_phys_addr = 0x1ULL, + }; + +#ifdef KVM_CAP_SET_TSS_ADDR + tss_ext = ioctl(kvm-fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR); +#else + tss_ext = 0; +#endif + + if (memory = pcimem) + extended_memory.memory_size = pcimem - exmem; + + /* 640K should be enough. */ + low_memory.slot = get_free_slot(kvm); + r = ioctl(kvm-vm_fd, KVM_SET_MEMORY_REGION, low_memory); + if (r == -1) { + fprintf(stderr, kvm_create_memory_region: %m\n); + return -1; + } + register_slot(low_memory.slot, low_memory.guest_phys_addr); + + if (extended_memory.memory_size) { + if (tss_ext 0) + extended_memory.slot = get_free_slot(kvm); + else + extended_memory.slot = 0; + r = ioctl(kvm-vm_fd, KVM_SET_MEMORY_REGION, extended_memory); + if (r == -1) { + fprintf(stderr, kvm_create_memory_region: %m\n); + return -1; + } + register_slot(extended_memory.slot, + extended_memory.guest_phys_addr); + } + + if (above_4g_memory.memory_size) { + above_4g_memory.slot = get_free_slot(kvm); + r = ioctl(kvm-vm_fd, KVM_SET_MEMORY_REGION, above_4g_memory); + if (r == -1) { + fprintf(stderr, kvm_create_memory_region: %m\n); + return -1; + } + register_slot(above_4g_memory.slot, + above_4g_memory.guest_phys_addr); + } + + kvm_memory_region_save_params(kvm, low_memory); + kvm_memory_region_save_params(kvm, extended_memory); + kvm_memory_region_save_params(kvm, above_4g_memory); + if (above_4g_memory.memory_size) + kvm_memory_region_save_params(kvm, above_4g_memory); + + *vm_mem = mmap(NULL, memory, PROT_READ|PROT_WRITE, MAP_SHARED, kvm-vm_fd, 0); + + return 0; +} diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -319,79 +319,6 @@ int kvm_get_shadow_pages(kvm_context_t k return -1; } -int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory, - void **vm_mem) -{ - unsigned long dosmem = 0xa; -
[kvm-devel] [PATCH 00 of 20] [RESEND] Refactor libkvm code Phase 1
Ohayo! Patches have been reworked with everybodys suggestions. Now all none user exposed function are now in file kvm-$ARCH.h , while user exposed funcitons are in libkvm-$ARCH.h. All patches have been tested and now will compile on there own (well those after the abi-10 patches will give you warning until you apply the kvm_show_code patch, but they compile). This is the first phase as much of the code is tightly written for x86 but can be reused by other archs, it's just a matter of an agreed upon method. Also since there are about 27 of these lets get through these before moving through more. Signed-off-by: Jerone Young [EMAIL PROTECTED] - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [ kvm-Bugs-1824525 ] Fails to restore saved guests
Bugs item #1824525, was opened at 2007-11-02 17:13 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=893831aid=1824525group_id=180599 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: yunfeng (yunfeng) Assigned to: Nobody/Anonymous (nobody) Summary: Fails to restore saved guests Initial Comment: The guests can be saved. But it will hang when restoring from the disk. The commits kernel, a9acc2800d8676d8a9a91aeaedd16ae4f75c05df userspace, 179c05cc201592d8d48254133cc0075271a69e23 -- You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=893831aid=1824525group_id=180599 - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] Spanish soldier goes nude on magazine
Spanish soldier goes nude on magazine cover http://www.maoker.com/n832c57.aspx College girl students graduate to 'body studies' http://www.maoker.com/n835c57.aspx Aniston shares nude scene with Vince http://www.maoker.com/n463c56.aspx Britney Spears plans to commission a nude portrait http://www.maoker.com/n457c57.aspx Sadie Frost's nud e PETA shoot http://www.maoker.com/n454c67.aspx - 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/___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 05 of 20] Modify out arch specific code from kvm_create function
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193997379 18000 # Node ID e3def9892f39527f216acbde2de4dad0e8501183 # Parent 5ad14643e8eccb6aec15a5b7779f9a026dd2d204 Modify out arch specific code from kvm_create function This function removes all x86 specific code and creates a hook function kv_arch_create to accomidate for this code. This patch also moves the following funcitons to libkvm-x86.c: kvm_set_tss_addr kvm_set_init_tss kvm_create_default_phys_mem This patch moves function kvm_create_default_phys_mem to libkvm-x86. This function is arch specific to x86 and also today no one allocates guest memory in the kernel. To remove confusion the function has been renameed kvm_x86_create_default_phys_mem Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h --- a/libkvm/kvm-x86.h +++ b/libkvm/kvm-x86.h @@ -31,4 +31,9 @@ int kvm_alloc_userspace_memory(kvm_conte int kvm_alloc_userspace_memory(kvm_context_t kvm, unsigned long memory, void **vm_mem); +int kvm_set_tss_addr(kvm_context_t kvm, unsigned long addr); + +int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes, + void **vm_mem); + #endif diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -8,6 +8,10 @@ #include stropts.h #include sys/mman.h #include stdio.h +#include errno.h +#include sys/types.h +#include sys/stat.h +#include fcntl.h int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory, void **vm_mem) @@ -187,3 +191,87 @@ int kvm_alloc_userspace_memory(kvm_conte #endif +int kvm_set_tss_addr(kvm_context_t kvm, unsigned long addr) +{ +#ifdef KVM_CAP_SET_TSS_ADDR + int r; + + r = ioctl(kvm-fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR); + if (r 0) { + r = ioctl(kvm-vm_fd, KVM_SET_TSS_ADDR, addr); + if (r == -1) { + fprintf(stderr, kvm_set_tss_addr: %m\n); + return -errno; + } + return 0; + } +#endif + return -ENOSYS; +} + +static int kvm_init_tss(kvm_context_t kvm) +{ +#ifdef KVM_CAP_SET_TSS_ADDR + int r; + + r = ioctl(kvm-fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR); + if (r 0) { + /* +* this address is 3 pages before the bios, and the bios should present +* as unavaible memory +*/ + r = kvm_set_tss_addr(kvm, 0xfffbd000); + if (r 0) { + printf(kvm_init_tss: unable to set tss addr\n); + return r; + } + + } +#endif + return 0; +} + +static int kvm_x86_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); + if (r 0) + r = kvm_alloc_userspace_memory(kvm, memory, vm_mem); + else +#endif + r = kvm_alloc_kernel_memory(kvm, memory, vm_mem); + if (r 0) + return r; + +zfd = open(/dev/zero, O_RDONLY); +mmap(*vm_mem + 0xa8000, 0x8000, PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_FIXED, zfd, 0); +close(zfd); + + kvm-physical_memory = *vm_mem; + return 0; +} + + +int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes, + void **vm_mem) +{ + int r = 0; + + r = kvm_init_tss(kvm); + if (r 0) + return r; + r = kvm_x86_create_default_phys_mem(kvm, phys_mem_bytes, vm_mem); + if (r 0) + return r; + + return 0; +} + + diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -335,72 +335,7 @@ int kvm_create_vm(kvm_context_t kvm) return 0; } -int kvm_set_tss_addr(kvm_context_t kvm, unsigned long addr) -{ -#ifdef KVM_CAP_SET_TSS_ADDR - int r; - - r = ioctl(kvm-fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR); - if (r 0) { - r = ioctl(kvm-vm_fd, KVM_SET_TSS_ADDR, addr); - if (r == -1) { - fprintf(stderr, kvm_set_tss_addr: %m\n); - return -errno; - } - return 0; - } -#endif - return -ENOSYS; -} - -static int kvm_init_tss(kvm_context_t kvm) -{ -#ifdef KVM_CAP_SET_TSS_ADDR - int r; - - r = ioctl(kvm-fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR); - if (r 0) { - /* -* this address is 3 pages before the
[kvm-devel] [PATCH 04 of 20] Move kvm_alloc_userspace_memory to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1193997182 18000 # Node ID 5ad14643e8eccb6aec15a5b7779f9a026dd2d204 # Parent dcf5d603165aad6e5276e3fdda81e1be2a6595ae Move kvm_alloc_userspace_memory to libkvm-x86.c This moves x86 specific function kvm_alloc_userspace_memory() out of libkvm.c into libkvm-x86.c. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h --- a/libkvm/kvm-x86.h +++ b/libkvm/kvm-x86.h @@ -28,4 +28,7 @@ int kvm_alloc_kernel_memory(kvm_context_ int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory, void **vm_mem); +int kvm_alloc_userspace_memory(kvm_context_t kvm, unsigned long memory, + void **vm_mem); + #endif diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -1,6 +1,9 @@ #include libkvm.h #include kvm-x86.h #include kvm-context.h +#include errno.h +#include sys/ioctl.h +#include string.h #include unistd.h #include stropts.h #include sys/mman.h @@ -80,3 +83,107 @@ int kvm_alloc_kernel_memory(kvm_context_ return 0; } + + +#ifdef KVM_CAP_USER_MEMORY + +int kvm_alloc_userspace_memory(kvm_context_t kvm, unsigned long memory, + void **vm_mem) +{ + unsigned long dosmem = 0xa; + unsigned long exmem = 0xc; + unsigned long pcimem = 0xe000; + int r; + int tss_ext; + struct kvm_userspace_memory_region low_memory = { + .memory_size = memory dosmem ? memory : dosmem, + .guest_phys_addr = 0, + }; + struct kvm_userspace_memory_region extended_memory = { + .memory_size = memory exmem ? 0 : memory - exmem, + .guest_phys_addr = exmem, + }; + struct kvm_userspace_memory_region above_4g_memory = { + .memory_size = memory pcimem ? 0 : memory - pcimem, + .guest_phys_addr = 0x1ULL, + }; + +#ifdef KVM_CAP_SET_TSS_ADDR + tss_ext = ioctl(kvm-fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR); +#else + tss_ext = 0; +#endif + + if (memory = pcimem) { + extended_memory.memory_size = pcimem - exmem; + *vm_mem = mmap(NULL, memory + 0x1ULL - pcimem, + PROT_READ|PROT_WRITE, MAP_ANONYMOUS | + MAP_SHARED, -1, 0); + } + else + *vm_mem = mmap(NULL, memory, PROT_READ|PROT_WRITE, MAP_ANONYMOUS + | MAP_SHARED, -1, 0); + if (*vm_mem == MAP_FAILED) { + fprintf(stderr, kvm_alloc_userspace_memory: %s, strerror(errno)); + return -1; + } + + low_memory.userspace_addr = (unsigned long)*vm_mem; + low_memory.slot = get_free_slot(kvm); + /* 640K should be enough. */ + r = ioctl(kvm-vm_fd, KVM_SET_USER_MEMORY_REGION, low_memory); + if (r == -1) { + fprintf(stderr, kvm_create_memory_region: %m\n); + return -1; + } + register_slot(low_memory.slot, low_memory.guest_phys_addr); + + if (extended_memory.memory_size) { + r = munmap(*vm_mem + dosmem, exmem - dosmem); + if (r == -1) { + fprintf(stderr, kvm_alloc_userspace_memory: %s, + strerror(errno)); + return -1; + } + extended_memory.userspace_addr = (unsigned long)(*vm_mem + exmem); + if (tss_ext 0) + extended_memory.slot = get_free_slot(kvm); + else + extended_memory.slot = 0; + r = ioctl(kvm-vm_fd, KVM_SET_USER_MEMORY_REGION, extended_memory); + if (r == -1) { + fprintf(stderr, kvm_create_memory_region: %m\n); + return -1; + } + register_slot(extended_memory.slot, + extended_memory.guest_phys_addr); + } + + if (above_4g_memory.memory_size) { + r = munmap(*vm_mem + pcimem, 0x1ULL - pcimem); + if (r == -1) { + fprintf(stderr, kvm_alloc_userspace_memory: %s, + strerror(errno)); + return -1; + } + above_4g_memory.userspace_addr = (unsigned long)(*vm_mem + 0x1ULL); + above_4g_memory.slot = get_free_slot(kvm); + r = ioctl(kvm-vm_fd, KVM_SET_USER_MEMORY_REGION, above_4g_memory); + if (r == -1) { + fprintf(stderr, kvm_create_memory_region: %m\n); +
[kvm-devel] [PATCH 15 of 19] Declare kvm_abi as a global variable in libkvm.h
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027873 18000 # Node ID df89e9282fd9f491579b42624565bac580f7db8e # Parent 68585a137682a876dd438782147445f4484146ce Declare kvm_abi as a global variable in libkvm.h Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -41,7 +41,7 @@ #include kvm-x86.h #endif -static int kvm_abi = EXPECTED_KVM_API_VERSION; +int kvm_abi = EXPECTED_KVM_API_VERSION; int free_slots[KVM_MAX_NUM_MEM_REGIONS]; unsigned long phys_addr_slots[KVM_MAX_NUM_MEM_REGIONS]; diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -30,6 +30,9 @@ typedef struct kvm_context *kvm_context_ #if defined(__x86_64__) || defined(__i386__) #include libkvm-x86.h #endif + +/* kvm abi verison variable */ +extern int kvm_abi; /*! - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 08 of 19] Move kvm_destroy_phys_mem to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027873 18000 # Node ID 098efe35de4493a3eda631cb2f9fd958ae303897 # Parent 8e77064ea82d0b7fbd8bb77429bbfd62f99c00f6 Move kvm_destroy_phys_mem to libkvm-x86.c Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -322,3 +322,29 @@ void *kvm_create_phys_mem(kvm_context_t log, writable); } +/* destroy/free a whole slot. + * phys_start, len and slot are the params passed to kvm_create_phys_mem() + */ +void kvm_destroy_phys_mem(kvm_context_t kvm, unsigned long phys_start, + unsigned long len) +{ + int slot; + struct kvm_memory_region *mem; + + slot = get_slot(phys_start); + + if (slot = KVM_MAX_NUM_MEM_REGIONS) { + fprintf(stderr, BUG: %s: invalid parameters (slot=%d)\n, + __FUNCTION__, slot); + return; + } + mem = kvm-mem_regions[slot]; + if (phys_start != mem-guest_phys_addr) { + fprintf(stderr, + WARNING: %s: phys_start is 0x%lx expecting 0x%llx\n, + __FUNCTION__, phys_start, mem-guest_phys_addr); + phys_start = mem-guest_phys_addr; + } + kvm_create_phys_mem(kvm, phys_start, 0, 0, 0); +} + diff --git a/libkvm/libkvm-x86.h b/libkvm/libkvm-x86.h --- a/libkvm/libkvm-x86.h +++ b/libkvm/libkvm-x86.h @@ -8,4 +8,7 @@ void *kvm_create_phys_mem(kvm_context_t, void *kvm_create_phys_mem(kvm_context_t, unsigned long phys_start, unsigned long len, int log, int writable); +void kvm_destroy_phys_mem(kvm_context_t, unsigned long phys_start, + unsigned long len); + #endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -445,33 +445,6 @@ int kvm_register_userspace_phys_mem(kvm_ #else return -ENOSYS; #endif -} - - -/* destroy/free a whole slot. - * phys_start, len and slot are the params passed to kvm_create_phys_mem() - */ -void kvm_destroy_phys_mem(kvm_context_t kvm, unsigned long phys_start, - unsigned long len) -{ - int slot; - struct kvm_memory_region *mem; - - slot = get_slot(phys_start); - - if (slot = KVM_MAX_NUM_MEM_REGIONS) { - fprintf(stderr, BUG: %s: invalid parameters (slot=%d)\n, - __FUNCTION__, slot); - return; - } - mem = kvm-mem_regions[slot]; - if (phys_start != mem-guest_phys_addr) { - fprintf(stderr, - WARNING: %s: phys_start is 0x%lx expecting 0x%llx\n, - __FUNCTION__, phys_start, mem-guest_phys_addr); - phys_start = mem-guest_phys_addr; - } - kvm_create_phys_mem(kvm, phys_start, 0, 0, 0); } int kvm_create_memory_alias(kvm_context_t kvm, - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 12 of 19] Move abi 10 functions to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027873 18000 # Node ID 0ade452df6c708a2b44696a23e733d59c8906aea # Parent 01b86b564fb9e751295ff8eddf5f38cfb24e1e34 Move abi 10 functions to libkvm-x86.c Move handle_io_abi_10 to libkvm-x86.c Move handle_mmio_abi10 to libkvm-x86.c Move kvm_run_abi10 to libkvm-x86.c Move kvm_show_code to libkvm-x86.c Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h --- a/libkvm/kvm-x86.h +++ b/libkvm/kvm-x86.h @@ -38,4 +38,8 @@ void *kvm_create_kernel_phys_mem(kvm_con void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start, unsigned long len, int log, int writable); +int kvm_run_abi10(kvm_context_t kvm, int vcpu); + +void kvm_show_code(kvm_context_t kvm, int vcpu); + #endif diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -1,5 +1,6 @@ #include libkvm.h #include kvm-x86.h +#include kvm-abi-10.h #include errno.h #include sys/ioctl.h #include string.h @@ -11,6 +12,7 @@ #include sys/types.h #include sys/stat.h #include fcntl.h +#include stdlib.h int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory, void **vm_mem) @@ -407,4 +409,224 @@ int kvm_set_lapic(kvm_context_t kvm, int #endif - +static int handle_io_abi10(kvm_context_t kvm, struct kvm_run_abi10 *run, + int vcpu) +{ + uint16_t addr = run-io.port; + int r; + int i; + void *p = (void *)run + run-io.data_offset; + + for (i = 0; i run-io.count; ++i) { + switch (run-io.direction) { + case KVM_EXIT_IO_IN: + switch (run-io.size) { + case 1: + r = kvm-callbacks-inb(kvm-opaque, addr, p); + break; + case 2: + r = kvm-callbacks-inw(kvm-opaque, addr, p); + break; + case 4: + r = kvm-callbacks-inl(kvm-opaque, addr, p); + break; + default: + fprintf(stderr, bad I/O size %d\n, run-io.size); + return -EMSGSIZE; + } + break; + case KVM_EXIT_IO_OUT: + switch (run-io.size) { + case 1: + r = kvm-callbacks-outb(kvm-opaque, addr, +*(uint8_t *)p); + break; + case 2: + r = kvm-callbacks-outw(kvm-opaque, addr, +*(uint16_t *)p); + break; + case 4: + r = kvm-callbacks-outl(kvm-opaque, addr, +*(uint32_t *)p); + break; + default: + fprintf(stderr, bad I/O size %d\n, run-io.size); + return -EMSGSIZE; + } + break; + default: + fprintf(stderr, bad I/O direction %d\n, run-io.direction); + return -EPROTO; + } + + p += run-io.size; + } + run-io_completed = 1; + + return 0; +} + +static int handle_mmio_abi10(kvm_context_t kvm, struct kvm_run_abi10 *kvm_run) +{ + unsigned long addr = kvm_run-mmio.phys_addr; + void *data = kvm_run-mmio.data; + int r = -1; + + if (kvm_run-mmio.is_write) { + switch (kvm_run-mmio.len) { + case 1: + r = kvm-callbacks-writeb(kvm-opaque, addr, + *(uint8_t *)data); + break; + case 2: + r = kvm-callbacks-writew(kvm-opaque, addr, + *(uint16_t *)data); + break; + case 4: + r = kvm-callbacks-writel(kvm-opaque, addr, + *(uint32_t *)data); + break; + case 8: + r = kvm-callbacks-writeq(kvm-opaque, addr, + *(uint64_t *)data); + break; + } + } else { + switch (kvm_run-mmio.len) { + case 1: + r = kvm-callbacks-readb(kvm-opaque, addr, + (uint8_t
[kvm-devel] [PATCH 17 of 19] Move cr8 functions to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027873 18000 # Node ID ab3e5d875c37bf36db4e73331fd3234523598c6e # Parent 7e750325679dd770206ec6da84f00a4dc4be1b2c Move cr8 functions to libkvm-x86.c This patch moves functions: kvm_set_cr8 kvm_get_cr8 cr8 is an x86 only register. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -766,3 +766,19 @@ uint64_t kvm_get_apic_base(kvm_context_t return run-apic_base; } +void kvm_set_cr8(kvm_context_t kvm, int vcpu, uint64_t cr8) +{ + struct kvm_run *run = kvm-run[vcpu]; + + if (kvm_abi == 10) { + ((struct kvm_run_abi10 *)run)-cr8 = cr8; + return; + } + run-cr8 = cr8; +} + +__u64 kvm_get_cr8(kvm_context_t kvm, int vcpu) +{ + return kvm-run[vcpu]-cr8; +} + diff --git a/libkvm/libkvm-x86.h b/libkvm/libkvm-x86.h --- a/libkvm/libkvm-x86.h +++ b/libkvm/libkvm-x86.h @@ -81,5 +81,27 @@ void kvm_show_regs(kvm_context_t kvm, in */ uint64_t kvm_get_apic_base(kvm_context_t kvm, int vcpu); +/*! + * \brief Set up cr8 for next time the vcpu is executed + * + * This is a fast setter for cr8, which will be applied when the + * vcpu next enters guest mode. + * + * \param kvm Pointer to the current kvm_context + * \param vcpu Which virtual CPU should get dumped + * \param cr8 next cr8 value + */ +void kvm_set_cr8(kvm_context_t kvm, int vcpu, uint64_t cr8); + +/*! + * \brief Get cr8 for sync tpr in qemu apic emulation + * + * This is a getter for cr8, which used to sync with the tpr in qemu + * apic emualtion. + * + * \param kvm Pointer to the current kvm_context + * \param vcpu Which virtual CPU should get dumped + */ +__u64 kvm_get_cr8(kvm_context_t kvm, int vcpu); #endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -727,22 +727,6 @@ int kvm_is_ready_for_interrupt_injection return run-ready_for_interrupt_injection; } -void kvm_set_cr8(kvm_context_t kvm, int vcpu, uint64_t cr8) -{ - struct kvm_run *run = kvm-run[vcpu]; - - if (kvm_abi == 10) { - ((struct kvm_run_abi10 *)run)-cr8 = cr8; - return; - } - run-cr8 = cr8; -} - -__u64 kvm_get_cr8(kvm_context_t kvm, int vcpu) -{ - return kvm-run[vcpu]-cr8; -} - int kvm_run(kvm_context_t kvm, int vcpu) { int r; diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -215,29 +215,6 @@ int kvm_is_ready_for_interrupt_injection int kvm_is_ready_for_interrupt_injection(kvm_context_t kvm, int vcpu); /*! - * \brief Set up cr8 for next time the vcpu is executed - * - * This is a fast setter for cr8, which will be applied when the - * vcpu next enters guest mode. - * - * \param kvm Pointer to the current kvm_context - * \param vcpu Which virtual CPU should get dumped - * \param cr8 next cr8 value - */ -void kvm_set_cr8(kvm_context_t kvm, int vcpu, uint64_t cr8); - -/*! - * \brief Get cr8 for sync tpr in qemu apic emulation - * - * This is a getter for cr8, which used to sync with the tpr in qemu - * apic emualtion. - * - * \param kvm Pointer to the current kvm_context - * \param vcpu Which virtual CPU should get dumped - */ -__u64 kvm_get_cr8(kvm_context_t kvm, int vcpu); - -/*! * \brief Read VCPU registers * * This gets the GP registers from the VCPU and outputs them - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 09 of 19] Move kvm_create_memory_alias kvm_destroy_memory_alias to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027873 18000 # Node ID 76218015a52046be4d77069c3e999b6ca60d0528 # Parent 098efe35de4493a3eda631cb2f9fd958ae303897 Move kvm_create_memory_alias kvm_destroy_memory_alias to libkvm-x86.c Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -348,3 +348,32 @@ void kvm_destroy_phys_mem(kvm_context_t kvm_create_phys_mem(kvm, phys_start, 0, 0, 0); } +int kvm_create_memory_alias(kvm_context_t kvm, + uint64_t phys_addr, + uint64_t phys_start, + uint64_t len, + uint64_t target_phys) +{ + struct kvm_memory_alias alias = { + .flags = 0, + .guest_phys_addr = phys_start, + .memory_size = len, + .target_phys_addr = target_phys, + }; + int fd = kvm-vm_fd; + int r; + + alias.slot = get_slot(phys_addr); + + r = ioctl(fd, KVM_SET_MEMORY_ALIAS, alias); + if (r == -1) + return -errno; + + return 0; +} + +int kvm_destroy_memory_alias(kvm_context_t kvm, uint64_t phys_addr) +{ + return kvm_create_memory_alias(kvm, phys_addr, 0, 0, 0); +} + diff --git a/libkvm/libkvm-x86.h b/libkvm/libkvm-x86.h --- a/libkvm/libkvm-x86.h +++ b/libkvm/libkvm-x86.h @@ -11,4 +11,23 @@ void kvm_destroy_phys_mem(kvm_context_t, void kvm_destroy_phys_mem(kvm_context_t, unsigned long phys_start, unsigned long len); +/*! + * \brief Create a memory alias + * + * Aliases a portion of physical memory to another portion. If the guest + * accesses the alias region, it will behave exactly as if it accessed + * the target memory. + */ +int kvm_create_memory_alias(kvm_context_t, uint64_t phys_addr, + uint64_t phys_start, uint64_t len, + uint64_t target_phys); + +/*! + * \brief Destroy a memory alias + * + * Removes an alias created with kvm_create_memory_alias(). + */ +int kvm_destroy_memory_alias(kvm_context_t, uint64_t phys_addr); + + #endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -445,35 +445,6 @@ int kvm_register_userspace_phys_mem(kvm_ #else return -ENOSYS; #endif -} - -int kvm_create_memory_alias(kvm_context_t kvm, - uint64_t phys_addr, - uint64_t phys_start, - uint64_t len, - uint64_t target_phys) -{ - struct kvm_memory_alias alias = { - .flags = 0, - .guest_phys_addr = phys_start, - .memory_size = len, - .target_phys_addr = target_phys, - }; - int fd = kvm-vm_fd; - int r; - - alias.slot = get_slot(phys_addr); - - r = ioctl(fd, KVM_SET_MEMORY_ALIAS, alias); - if (r == -1) - return -errno; - - return 0; -} - -int kvm_destroy_memory_alias(kvm_context_t kvm, uint64_t phys_addr) -{ - return kvm_create_memory_alias(kvm, phys_addr, 0, 0, 0); } static int kvm_get_map(kvm_context_t kvm, int ioctl_num, int slot, void *buf) diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -427,24 +427,6 @@ int kvm_get_dirty_pages(kvm_context_t, u /*! - * \brief Create a memory alias - * - * Aliases a portion of physical memory to another portion. If the guest - * accesses the alias region, it will behave exactly as if it accessed - * the target memory. - */ -int kvm_create_memory_alias(kvm_context_t, uint64_t phys_addr, - uint64_t phys_start, uint64_t len, - uint64_t target_phys); - -/*! - * \brief Destroy a memory alias - * - * Removes an alias created with kvm_create_memory_alias(). - */ -int kvm_destroy_memory_alias(kvm_context_t, uint64_t phys_addr); - -/*! * \brief Get a bitmap of guest ram pages which are allocated to the guest. * * \param kvm Pointer to the current kvm_context - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 02 of 19] Make static slot kvm_memory region funcions public
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027872 18000 # Node ID 17bf778405bb2aea7eab2e4625f913941efeab1c # Parent 72c2d9f9786aea122419208189291808d56b8053 Make static slot kvm_memory region funcions public This patch changes static functions for manipulation of memory slots and regions public in kvmctl.c. This also makes a decleration for these functions in kvmctl.h. This allow for breaking out code into other files and still keep this functionality. These functions can later be broken up some to move there x86 specific stuff (ex. TSS). Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h --- a/libkvm/kvm-x86.h +++ b/libkvm/kvm-x86.h @@ -11,4 +11,14 @@ #define PAGE_SIZE 4096ul #define PAGE_MASK (~(PAGE_SIZE - 1)) +void init_slots(); +int get_free_slot(kvm_context_t kvm); +void register_slot(int slot, unsigned long phys_addr); +int get_slot(unsigned long phys_addr); +void kvm_memory_region_save_params(kvm_context_t kvm, + struct kvm_memory_region *mem); +void kvm_userspace_memory_region_save_params(kvm_context_t kvm, + struct kvm_userspace_memory_region *mem); +void kvm_memory_region_clear_params(kvm_context_t kvm, int regnum); + #endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -46,7 +46,7 @@ int free_slots[KVM_MAX_NUM_MEM_REGIONS]; int free_slots[KVM_MAX_NUM_MEM_REGIONS]; unsigned long phys_addr_slots[KVM_MAX_NUM_MEM_REGIONS]; -static void init_slots() +void init_slots() { int i; @@ -54,7 +54,7 @@ static void init_slots() free_slots[i] = 0; } -static int get_free_slot(kvm_context_t kvm) +int get_free_slot(kvm_context_t kvm) { int i; int tss_ext; @@ -81,13 +81,13 @@ static int get_free_slot(kvm_context_t k return -1; } -static void register_slot(int slot, unsigned long phys_addr) +void register_slot(int slot, unsigned long phys_addr) { free_slots[slot] = 1; phys_addr_slots[slot] = phys_addr; } -static int get_slot(unsigned long phys_addr) +int get_slot(unsigned long phys_addr) { int i; @@ -100,7 +100,7 @@ static int get_slot(unsigned long phys_a /* * memory regions parameters */ -static void kvm_memory_region_save_params(kvm_context_t kvm, +void kvm_memory_region_save_params(kvm_context_t kvm, struct kvm_memory_region *mem) { if (!mem || (mem-slot = KVM_MAX_NUM_MEM_REGIONS)) { @@ -112,7 +112,7 @@ static void kvm_memory_region_save_param #ifdef KVM_CAP_USER_MEMORY -static void kvm_userspace_memory_region_save_params(kvm_context_t kvm, +void kvm_userspace_memory_region_save_params(kvm_context_t kvm, struct kvm_userspace_memory_region *mem) { struct kvm_memory_region kvm_mem; @@ -126,7 +126,7 @@ static void kvm_userspace_memory_region_ #endif -static void kvm_memory_region_clear_params(kvm_context_t kvm, int regnum) +void kvm_memory_region_clear_params(kvm_context_t kvm, int regnum) { if (regnum = KVM_MAX_NUM_MEM_REGIONS) { fprintf(stderr, BUG: %s: invalid parameters\n, __FUNCTION__); - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 14 of 19] Move print_seg Move kvm_show_regs to kvmctl-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027873 18000 # Node ID 68585a137682a876dd438782147445f4484146ce # Parent 5bb5ef1b7faa8c11677b73fedbe089d0926ca4e9 Move print_seg Move kvm_show_regs to kvmctl-x86.c This patch moves functions print_seg, kvm_show_regs, print_dt to libkvm-x86.c. Since kvm_show_regs really has little to no shared code (besides an ioctl call and variable declarations), it is best that this be moved into arch specific code. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -698,3 +698,63 @@ int kvm_set_msrs(kvm_context_t kvm, int return r; } +static void print_seg(FILE *file, const char *name, struct kvm_segment *seg) +{ + fprintf(stderr, + %s %04x (%08llx/%08x p %d dpl %d db %d s %d type %x l %d +g %d avl %d)\n, + name, seg-selector, seg-base, seg-limit, seg-present, + seg-dpl, seg-db, seg-s, seg-type, seg-l, seg-g, + seg-avl); +} + +static void print_dt(FILE *file, const char *name, struct kvm_dtable *dt) +{ + fprintf(stderr, %s %llx/%x\n, name, dt-base, dt-limit); +} + +void kvm_show_regs(kvm_context_t kvm, int vcpu) +{ + int fd = kvm-vcpu_fd[vcpu]; + struct kvm_regs regs; + struct kvm_sregs sregs; + int r; + + r = ioctl(fd, KVM_GET_REGS, regs); + if (r == -1) { + perror(KVM_GET_REGS); + return; + } + fprintf(stderr, + rax %016llx rbx %016llx rcx %016llx rdx %016llx\n + rsi %016llx rdi %016llx rsp %016llx rbp %016llx\n + r8 %016llx r9 %016llx r10 %016llx r11 %016llx\n + r12 %016llx r13 %016llx r14 %016llx r15 %016llx\n + rip %016llx rflags %08llx\n, + regs.rax, regs.rbx, regs.rcx, regs.rdx, + regs.rsi, regs.rdi, regs.rsp, regs.rbp, + regs.r8, regs.r9, regs.r10, regs.r11, + regs.r12, regs.r13, regs.r14, regs.r15, + regs.rip, regs.rflags); + r = ioctl(fd, KVM_GET_SREGS, sregs); + if (r == -1) { + perror(KVM_GET_SREGS); + return; + } + print_seg(stderr, cs, sregs.cs); + print_seg(stderr, ds, sregs.ds); + print_seg(stderr, es, sregs.es); + print_seg(stderr, ss, sregs.ss); + print_seg(stderr, fs, sregs.fs); + print_seg(stderr, gs, sregs.gs); + print_seg(stderr, tr, sregs.tr); + print_seg(stderr, ldt, sregs.ldt); + print_dt(stderr, gdt, sregs.gdt); + print_dt(stderr, idt, sregs.idt); + fprintf(stderr, cr0 %llx cr2 %llx cr3 %llx cr4 %llx cr8 %llx +efer %llx\n, + sregs.cr0, sregs.cr2, sregs.cr3, sregs.cr4, sregs.cr8, + sregs.efer); +} + + diff --git a/libkvm/libkvm-x86.h b/libkvm/libkvm-x86.h --- a/libkvm/libkvm-x86.h +++ b/libkvm/libkvm-x86.h @@ -55,4 +55,19 @@ int kvm_set_lapic(kvm_context_t kvm, int #endif +/*! + * \brief Dump VCPU registers + * + * This dumps some of the information that KVM has about a virtual CPU, namely: + * - GP Registers + * + * A much more verbose version of this is available as kvm_dump_vcpu() + * + * \param kvm Pointer to the current kvm_context + * \param vcpu Which virtual CPU should get dumped + * \return 0 on success + */ +void kvm_show_regs(kvm_context_t kvm, int vcpu); + + #endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -635,65 +635,6 @@ int kvm_set_sregs(kvm_context_t kvm, int return ioctl(kvm-vcpu_fd[vcpu], KVM_SET_SREGS, sregs); } -static void print_seg(FILE *file, const char *name, struct kvm_segment *seg) -{ - fprintf(stderr, - %s %04x (%08llx/%08x p %d dpl %d db %d s %d type %x l %d -g %d avl %d)\n, - name, seg-selector, seg-base, seg-limit, seg-present, - seg-dpl, seg-db, seg-s, seg-type, seg-l, seg-g, - seg-avl); -} - -static void print_dt(FILE *file, const char *name, struct kvm_dtable *dt) -{ - fprintf(stderr, %s %llx/%x\n, name, dt-base, dt-limit); -} - -void kvm_show_regs(kvm_context_t kvm, int vcpu) -{ - int fd = kvm-vcpu_fd[vcpu]; - struct kvm_regs regs; - struct kvm_sregs sregs; - int r; - - r = ioctl(fd, KVM_GET_REGS, regs); - if (r == -1) { - perror(KVM_GET_REGS); - return; - } - fprintf(stderr, - rax %016llx rbx %016llx rcx %016llx rdx %016llx\n - rsi %016llx rdi %016llx rsp %016llx rbp %016llx\n - r8 %016llx r9 %016llx r10 %016llx r11 %016llx\n - r12 %016llx r13 %016llx r14 %016llx r15 %016llx\n - rip %016llx rflags %08llx\n, - regs.rax, regs.rbx, regs.rcx, regs.rdx, - regs.rsi, regs.rdi, regs.rsp, regs.rbp, -
[kvm-devel] [PATCH 04 of 19] Move kvm_alloc_userspace_memory to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027872 18000 # Node ID 486d6818fcf62f9fda006e9e090bf1eba40e0e14 # Parent d92515231c6345b7a4b5388089a5edb4c323a392 Move kvm_alloc_userspace_memory to libkvm-x86.c This moves x86 specific function kvm_alloc_userspace_memory() out of libkvm.c into libkvm-x86.c. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h --- a/libkvm/kvm-x86.h +++ b/libkvm/kvm-x86.h @@ -25,4 +25,7 @@ int kvm_alloc_kernel_memory(kvm_context_ int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory, void **vm_mem); +int kvm_alloc_userspace_memory(kvm_context_t kvm, unsigned long memory, + void **vm_mem); + #endif diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -1,5 +1,8 @@ #include libkvm.h #include kvm-x86.h +#include errno.h +#include sys/ioctl.h +#include string.h #include unistd.h #include stropts.h #include sys/mman.h @@ -79,3 +82,107 @@ int kvm_alloc_kernel_memory(kvm_context_ return 0; } + + +#ifdef KVM_CAP_USER_MEMORY + +int kvm_alloc_userspace_memory(kvm_context_t kvm, unsigned long memory, + void **vm_mem) +{ + unsigned long dosmem = 0xa; + unsigned long exmem = 0xc; + unsigned long pcimem = 0xe000; + int r; + int tss_ext; + struct kvm_userspace_memory_region low_memory = { + .memory_size = memory dosmem ? memory : dosmem, + .guest_phys_addr = 0, + }; + struct kvm_userspace_memory_region extended_memory = { + .memory_size = memory exmem ? 0 : memory - exmem, + .guest_phys_addr = exmem, + }; + struct kvm_userspace_memory_region above_4g_memory = { + .memory_size = memory pcimem ? 0 : memory - pcimem, + .guest_phys_addr = 0x1ULL, + }; + +#ifdef KVM_CAP_SET_TSS_ADDR + tss_ext = ioctl(kvm-fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR); +#else + tss_ext = 0; +#endif + + if (memory = pcimem) { + extended_memory.memory_size = pcimem - exmem; + *vm_mem = mmap(NULL, memory + 0x1ULL - pcimem, + PROT_READ|PROT_WRITE, MAP_ANONYMOUS | + MAP_SHARED, -1, 0); + } + else + *vm_mem = mmap(NULL, memory, PROT_READ|PROT_WRITE, MAP_ANONYMOUS + | MAP_SHARED, -1, 0); + if (*vm_mem == MAP_FAILED) { + fprintf(stderr, kvm_alloc_userspace_memory: %s, strerror(errno)); + return -1; + } + + low_memory.userspace_addr = (unsigned long)*vm_mem; + low_memory.slot = get_free_slot(kvm); + /* 640K should be enough. */ + r = ioctl(kvm-vm_fd, KVM_SET_USER_MEMORY_REGION, low_memory); + if (r == -1) { + fprintf(stderr, kvm_create_memory_region: %m\n); + return -1; + } + register_slot(low_memory.slot, low_memory.guest_phys_addr); + + if (extended_memory.memory_size) { + r = munmap(*vm_mem + dosmem, exmem - dosmem); + if (r == -1) { + fprintf(stderr, kvm_alloc_userspace_memory: %s, + strerror(errno)); + return -1; + } + extended_memory.userspace_addr = (unsigned long)(*vm_mem + exmem); + if (tss_ext 0) + extended_memory.slot = get_free_slot(kvm); + else + extended_memory.slot = 0; + r = ioctl(kvm-vm_fd, KVM_SET_USER_MEMORY_REGION, extended_memory); + if (r == -1) { + fprintf(stderr, kvm_create_memory_region: %m\n); + return -1; + } + register_slot(extended_memory.slot, + extended_memory.guest_phys_addr); + } + + if (above_4g_memory.memory_size) { + r = munmap(*vm_mem + pcimem, 0x1ULL - pcimem); + if (r == -1) { + fprintf(stderr, kvm_alloc_userspace_memory: %s, + strerror(errno)); + return -1; + } + above_4g_memory.userspace_addr = (unsigned long)(*vm_mem + 0x1ULL); + above_4g_memory.slot = get_free_slot(kvm); + r = ioctl(kvm-vm_fd, KVM_SET_USER_MEMORY_REGION, above_4g_memory); + if (r == -1) { + fprintf(stderr, kvm_create_memory_region: %m\n); + return -1; +
[kvm-devel] [PATCH 16 of 19] Move kvm_get_apic to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027873 18000 # Node ID 7e750325679dd770206ec6da84f00a4dc4be1b2c # Parent df89e9282fd9f491579b42624565bac580f7db8e Move kvm_get_apic to libkvm-x86.c Moves apic function since it is x86 only. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -757,4 +757,12 @@ void kvm_show_regs(kvm_context_t kvm, in sregs.efer); } - +uint64_t kvm_get_apic_base(kvm_context_t kvm, int vcpu) +{ + struct kvm_run *run = kvm-run[vcpu]; + + if (kvm_abi == 10) + return ((struct kvm_run_abi10 *)run)-apic_base; + return run-apic_base; +} + diff --git a/libkvm/libkvm-x86.h b/libkvm/libkvm-x86.h --- a/libkvm/libkvm-x86.h +++ b/libkvm/libkvm-x86.h @@ -70,4 +70,16 @@ void kvm_show_regs(kvm_context_t kvm, in void kvm_show_regs(kvm_context_t kvm, int vcpu); +/*! + * \brief Get the value of the APIC_BASE msr as of last exit to userspace + * + * This gets the APIC_BASE msr as it was on the last exit to userspace. + * + * \param kvm Pointer to the current kvm_context + * \param vcpu Which virtual CPU should get dumped + * \return APIC_BASE msr contents + */ +uint64_t kvm_get_apic_base(kvm_context_t kvm, int vcpu); + + #endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -718,15 +718,6 @@ int kvm_get_interrupt_flag(kvm_context_t return run-if_flag; } -uint64_t kvm_get_apic_base(kvm_context_t kvm, int vcpu) -{ - struct kvm_run *run = kvm-run[vcpu]; - - if (kvm_abi == 10) - return ((struct kvm_run_abi10 *)run)-apic_base; - return run-apic_base; -} - int kvm_is_ready_for_interrupt_injection(kvm_context_t kvm, int vcpu) { struct kvm_run *run = kvm-run[vcpu]; diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -204,17 +204,6 @@ int kvm_get_interrupt_flag(kvm_context_t int kvm_get_interrupt_flag(kvm_context_t kvm, int vcpu); /*! - * \brief Get the value of the APIC_BASE msr as of last exit to userspace - * - * This gets the APIC_BASE msr as it was on the last exit to userspace. - * - * \param kvm Pointer to the current kvm_context - * \param vcpu Which virtual CPU should get dumped - * \return APIC_BASE msr contents - */ -uint64_t kvm_get_apic_base(kvm_context_t kvm, int vcpu); - -/*! * \brief Check if a vcpu is ready for interrupt injection * * This checks if vcpu interrupts are not masked by mov ss or sti. - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 03 of 19] Move fuction kvm_alloc_kernel_memory to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027872 18000 # Node ID d92515231c6345b7a4b5388089a5edb4c323a392 # Parent 17bf778405bb2aea7eab2e4625f913941efeab1c Move fuction kvm_alloc_kernel_memory to libkvm-x86.c Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/Makefile b/libkvm/Makefile --- a/libkvm/Makefile +++ b/libkvm/Makefile @@ -21,7 +21,7 @@ autodepend-flags = -MMD -MF $(dir $*).$( all: libkvm.a -libkvm.a: libkvm.o +libkvm.a: libkvm.o $(libkvm-$(ARCH)-objs) $(AR) rcs $@ $^ install: diff --git a/libkvm/config-i386.mak b/libkvm/config-i386.mak --- a/libkvm/config-i386.mak +++ b/libkvm/config-i386.mak @@ -2,3 +2,5 @@ LIBDIR := /lib LIBDIR := /lib CFLAGS += -m32 CFLAGS += -D__i386__ + +libkvm-$(ARCH)-objs := libkvm-x86.o diff --git a/libkvm/config-x86_64.mak b/libkvm/config-x86_64.mak --- a/libkvm/config-x86_64.mak +++ b/libkvm/config-x86_64.mak @@ -2,3 +2,5 @@ LIBDIR := /lib64 LIBDIR := /lib64 CFLAGS += -m64 CFLAGS += -D__x86_64__ + +libkvm-$(ARCH)-objs := libkvm-x86.o diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h --- a/libkvm/kvm-x86.h +++ b/libkvm/kvm-x86.h @@ -21,4 +21,8 @@ void kvm_userspace_memory_region_save_pa struct kvm_userspace_memory_region *mem); void kvm_memory_region_clear_params(kvm_context_t kvm, int regnum); + +int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory, + void **vm_mem); + #endif diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c new file mode 100644 --- /dev/null +++ b/libkvm/libkvm-x86.c @@ -0,0 +1,81 @@ +#include libkvm.h +#include kvm-x86.h +#include unistd.h +#include stropts.h +#include sys/mman.h +#include stdio.h + +int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory, + void **vm_mem) +{ + unsigned long dosmem = 0xa; + unsigned long exmem = 0xc; + unsigned long pcimem = 0xe000; + int r; + int tss_ext; + struct kvm_memory_region low_memory = { + .memory_size = memory dosmem ? memory : dosmem, + .guest_phys_addr = 0, + }; + struct kvm_memory_region extended_memory = { + .memory_size = memory exmem ? 0 : memory - exmem, + .guest_phys_addr = exmem, + }; + struct kvm_memory_region above_4g_memory = { + .memory_size = memory pcimem ? 0 : memory - pcimem, + .guest_phys_addr = 0x1ULL, + }; + +#ifdef KVM_CAP_SET_TSS_ADDR + tss_ext = ioctl(kvm-fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR); +#else + tss_ext = 0; +#endif + + if (memory = pcimem) + extended_memory.memory_size = pcimem - exmem; + + /* 640K should be enough. */ + low_memory.slot = get_free_slot(kvm); + r = ioctl(kvm-vm_fd, KVM_SET_MEMORY_REGION, low_memory); + if (r == -1) { + fprintf(stderr, kvm_create_memory_region: %m\n); + return -1; + } + register_slot(low_memory.slot, low_memory.guest_phys_addr); + + if (extended_memory.memory_size) { + if (tss_ext 0) + extended_memory.slot = get_free_slot(kvm); + else + extended_memory.slot = 0; + r = ioctl(kvm-vm_fd, KVM_SET_MEMORY_REGION, extended_memory); + if (r == -1) { + fprintf(stderr, kvm_create_memory_region: %m\n); + return -1; + } + register_slot(extended_memory.slot, + extended_memory.guest_phys_addr); + } + + if (above_4g_memory.memory_size) { + above_4g_memory.slot = get_free_slot(kvm); + r = ioctl(kvm-vm_fd, KVM_SET_MEMORY_REGION, above_4g_memory); + if (r == -1) { + fprintf(stderr, kvm_create_memory_region: %m\n); + return -1; + } + register_slot(above_4g_memory.slot, + above_4g_memory.guest_phys_addr); + } + + kvm_memory_region_save_params(kvm, low_memory); + kvm_memory_region_save_params(kvm, extended_memory); + kvm_memory_region_save_params(kvm, above_4g_memory); + if (above_4g_memory.memory_size) + kvm_memory_region_save_params(kvm, above_4g_memory); + + *vm_mem = mmap(NULL, memory, PROT_READ|PROT_WRITE, MAP_SHARED, kvm-vm_fd, 0); + + return 0; +} diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -317,79 +317,6 @@ int kvm_get_shadow_pages(kvm_context_t k return -1; } -int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory, - void **vm_mem) -{ - unsigned long dosmem = 0xa; -
[kvm-devel] [PATCH 05 of 19] Modify out arch specific code from kvm_create function
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027872 18000 # Node ID 7f802db02478d5d5ec63348e126b54e85681c66f # Parent 486d6818fcf62f9fda006e9e090bf1eba40e0e14 Modify out arch specific code from kvm_create function This function removes all x86 specific code and creates a hook function kv_arch_create to accomidate for this code. This patch also moves the following funcitons to libkvm-x86.c: kvm_set_tss_addr kvm_set_init_tss kvm_create_default_phys_mem This patch moves function kvm_create_default_phys_mem to libkvm-x86. This function is arch specific to x86 and also today no one allocates guest memory in the kernel. To remove confusion the function has been renameed kvm_x86_create_default_phys_mem Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h --- a/libkvm/kvm-x86.h +++ b/libkvm/kvm-x86.h @@ -28,4 +28,9 @@ int kvm_alloc_userspace_memory(kvm_conte int kvm_alloc_userspace_memory(kvm_context_t kvm, unsigned long memory, void **vm_mem); +int kvm_set_tss_addr(kvm_context_t kvm, unsigned long addr); + +int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes, + void **vm_mem); + #endif diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -7,6 +7,10 @@ #include stropts.h #include sys/mman.h #include stdio.h +#include errno.h +#include sys/types.h +#include sys/stat.h +#include fcntl.h int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory, void **vm_mem) @@ -186,3 +190,87 @@ int kvm_alloc_userspace_memory(kvm_conte #endif +int kvm_set_tss_addr(kvm_context_t kvm, unsigned long addr) +{ +#ifdef KVM_CAP_SET_TSS_ADDR + int r; + + r = ioctl(kvm-fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR); + if (r 0) { + r = ioctl(kvm-vm_fd, KVM_SET_TSS_ADDR, addr); + if (r == -1) { + fprintf(stderr, kvm_set_tss_addr: %m\n); + return -errno; + } + return 0; + } +#endif + return -ENOSYS; +} + +static int kvm_init_tss(kvm_context_t kvm) +{ +#ifdef KVM_CAP_SET_TSS_ADDR + int r; + + r = ioctl(kvm-fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR); + if (r 0) { + /* +* this address is 3 pages before the bios, and the bios should present +* as unavaible memory +*/ + r = kvm_set_tss_addr(kvm, 0xfffbd000); + if (r 0) { + printf(kvm_init_tss: unable to set tss addr\n); + return r; + } + + } +#endif + return 0; +} + +static int kvm_x86_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); + if (r 0) + r = kvm_alloc_userspace_memory(kvm, memory, vm_mem); + else +#endif + r = kvm_alloc_kernel_memory(kvm, memory, vm_mem); + if (r 0) + return r; + +zfd = open(/dev/zero, O_RDONLY); +mmap(*vm_mem + 0xa8000, 0x8000, PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_FIXED, zfd, 0); +close(zfd); + + kvm-physical_memory = *vm_mem; + return 0; +} + + +int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes, + void **vm_mem) +{ + int r = 0; + + r = kvm_init_tss(kvm); + if (r 0) + return r; + r = kvm_x86_create_default_phys_mem(kvm, phys_mem_bytes, vm_mem); + if (r 0) + return r; + + return 0; +} + + diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -333,72 +333,7 @@ int kvm_create_vm(kvm_context_t kvm) return 0; } -int kvm_set_tss_addr(kvm_context_t kvm, unsigned long addr) -{ -#ifdef KVM_CAP_SET_TSS_ADDR - int r; - - r = ioctl(kvm-fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR); - if (r 0) { - r = ioctl(kvm-vm_fd, KVM_SET_TSS_ADDR, addr); - if (r == -1) { - fprintf(stderr, kvm_set_tss_addr: %m\n); - return -errno; - } - return 0; - } -#endif - return -ENOSYS; -} - -static int kvm_init_tss(kvm_context_t kvm) -{ -#ifdef KVM_CAP_SET_TSS_ADDR - int r; - - r = ioctl(kvm-fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR); - if (r 0) { - /* -* this address is 3 pages before the
[kvm-devel] [PATCH 00 of 19] [v3] Refactor libkvm
Some more fixing this time around. Taking the suggestion by Hollis blancard I have combilned kvm_context into kvm-common.h. Also in this set of patches I have consolidated some of the later patches to avoid compiler warnings between patches. This is the first phase as much of the code is tightly written for x86 but can be reused by other archs, it's just a matter of an agreed upon method. - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 07 of 19] Move kvm_create_phys_mem to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027872 18000 # Node ID 8e77064ea82d0b7fbd8bb77429bbfd62f99c00f6 # Parent 02f38e54018070bafd501df846147f4ae7661109 Move kvm_create_phys_mem to libkvm-x86.c This patch moves kvm_create_phys_mem to libkvm-x86.c Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/kvm-common.h b/libkvm/kvm-common.h --- a/libkvm/kvm-common.h +++ b/libkvm/kvm-common.h @@ -34,4 +34,8 @@ struct kvm_context { int irqchip_in_kernel; }; +#ifdef KVM_CAP_USER_MEMORY +void *kvm_create_userspace_phys_mem(kvm_context_t kvm, unsigned long phys_start, + unsigned long len, int log, int writable); #endif +#endif diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -306,3 +306,19 @@ void *kvm_create_kernel_phys_mem(kvm_con return ptr; } +void *kvm_create_phys_mem(kvm_context_t kvm, unsigned long phys_start, + unsigned long len, int log, int writable) +{ +#ifdef KVM_CAP_USER_MEMORY + int r; + + r = ioctl(kvm-fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY); + if (r 0) + return kvm_create_userspace_phys_mem(kvm, phys_start, len, + log, writable); + else +#endif + return kvm_create_kernel_phys_mem(kvm, phys_start, len, + log, writable); +} + diff --git a/libkvm/libkvm-x86.h b/libkvm/libkvm-x86.h new file mode 100644 --- /dev/null +++ b/libkvm/libkvm-x86.h @@ -0,0 +1,11 @@ +/* This header is for x86 functions variables that will be exposed to users. + * DO NOT PLACE FUNCTIONS OR VARIABLES HERE THAT ARE NOT GOING TO EXPOSED TO + * USERS. + */ +#ifndef LIBKVM_X86_H +#define LIBKVM_X86_H + +void *kvm_create_phys_mem(kvm_context_t, unsigned long phys_start, + unsigned long len, int log, int writable); + +#endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -415,21 +415,6 @@ void *kvm_create_userspace_phys_mem(kvm_ #endif -void *kvm_create_phys_mem(kvm_context_t kvm, unsigned long phys_start, - unsigned long len, int log, int writable) -{ -#ifdef KVM_CAP_USER_MEMORY - int r; - - r = ioctl(kvm-fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY); - if (r 0) - return kvm_create_userspace_phys_mem(kvm, phys_start, len, - log, writable); - else -#endif - return kvm_create_kernel_phys_mem(kvm, phys_start, len, - log, writable); -} int kvm_register_userspace_phys_mem(kvm_context_t kvm, unsigned long phys_start, void *userspace_addr, diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -26,6 +26,11 @@ struct kvm_context; struct kvm_context; typedef struct kvm_context *kvm_context_t; + +#if defined(__x86_64__) || defined(__i386__) +#include libkvm-x86.h +#endif + /*! * \brief KVM callbacks structure @@ -413,8 +418,6 @@ void kvm_show_regs(kvm_context_t kvm, in void kvm_show_regs(kvm_context_t kvm, int vcpu); -void *kvm_create_phys_mem(kvm_context_t, unsigned long phys_start, - unsigned long len, int log, int writable); void kvm_destroy_phys_mem(kvm_context_t, unsigned long phys_start, unsigned long len); int kvm_register_userspace_phys_mem(kvm_context_t kvm, - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 19 of 19] Remove unsued inclusion of linux/kvm_parah.h in userspace libkvm.h
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027874 18000 # Node ID b8aa16dc574d2b6033bd847aff83f5aed3285310 # Parent 7e15060d3192c2ad951cb7b8295737b84b3b46b9 Remove unsued inclusion of linux/kvm_parah.h in userspace libkvm.h This remove unused code from libkvm.h. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -12,14 +12,6 @@ #endif #include linux/kvm.h - -#define u32 uint32_t /* older kvm_para.h had a u32 exposed */ -#define u64 uint32_t /* older kvm_para.h had a u32 exposed */ -#define PAGE_SIZE 4096 -#include linux/kvm_para.h -#undef u32 -#undef u64 -#undef PAGE_SIZE #include signal.h - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 18 of 19] Move kvm_setup_cpuid to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027874 18000 # Node ID 7e15060d3192c2ad951cb7b8295737b84b3b46b9 # Parent ab3e5d875c37bf36db4e73331fd3234523598c6e Move kvm_setup_cpuid to libkvm-x86.c cpuid is an x86 instruction, so needs to go in the approriate place. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -782,3 +782,21 @@ __u64 kvm_get_cr8(kvm_context_t kvm, int return kvm-run[vcpu]-cr8; } +int kvm_setup_cpuid(kvm_context_t kvm, int vcpu, int nent, + struct kvm_cpuid_entry *entries) +{ + struct kvm_cpuid *cpuid; + int r; + + cpuid = malloc(sizeof(*cpuid) + nent * sizeof(*entries)); + if (!cpuid) + return -ENOMEM; + + cpuid-nent = nent; + memcpy(cpuid-entries, entries, nent * sizeof(*entries)); + r = ioctl(kvm-vcpu_fd[vcpu], KVM_SET_CPUID, cpuid); + + free(cpuid); + return r; +} + diff --git a/libkvm/libkvm-x86.h b/libkvm/libkvm-x86.h --- a/libkvm/libkvm-x86.h +++ b/libkvm/libkvm-x86.h @@ -104,4 +104,19 @@ void kvm_set_cr8(kvm_context_t kvm, int */ __u64 kvm_get_cr8(kvm_context_t kvm, int vcpu); +/*! + * \brief Setup a vcpu's cpuid instruction emulation + * + * Set up a table of cpuid function to cpuid outputs.\n + * + * \param kvm Pointer to the current kvm_context + * \param vcpu Which virtual CPU should be initialized + * \param nent number of entries to be installed + * \param entries cpuid function entries table + * \return 0 on success, or -errno on error + */ +int kvm_setup_cpuid(kvm_context_t kvm, int vcpu, int nent, + struct kvm_cpuid_entry *entries); + + #endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -822,24 +822,6 @@ int kvm_guest_debug(kvm_context_t kvm, i return ioctl(kvm-vcpu_fd[vcpu], KVM_DEBUG_GUEST, dbg); } -int kvm_setup_cpuid(kvm_context_t kvm, int vcpu, int nent, - struct kvm_cpuid_entry *entries) -{ - struct kvm_cpuid *cpuid; - int r; - - cpuid = malloc(sizeof(*cpuid) + nent * sizeof(*entries)); - if (!cpuid) - return -ENOMEM; - - cpuid-nent = nent; - memcpy(cpuid-entries, entries, nent * sizeof(*entries)); - r = ioctl(kvm-vcpu_fd[vcpu], KVM_SET_CPUID, cpuid); - - free(cpuid); - return r; -} - int kvm_set_signal_mask(kvm_context_t kvm, int vcpu, const sigset_t *sigset) { struct kvm_signal_mask *sigmask; diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -324,20 +324,6 @@ int kvm_guest_debug(kvm_context_t, int v int kvm_guest_debug(kvm_context_t, int vcpu, struct kvm_debug_guest *dbg); /*! - * \brief Setup a vcpu's cpuid instruction emulation - * - * Set up a table of cpuid function to cpuid outputs.\n - * - * \param kvm Pointer to the current kvm_context - * \param vcpu Which virtual CPU should be initialized - * \param nent number of entries to be installed - * \param entries cpuid function entries table - * \return 0 on success, or -errno on error - */ -int kvm_setup_cpuid(kvm_context_t kvm, int vcpu, int nent, - struct kvm_cpuid_entry *entries); - -/*! * \brief Set a vcpu's signal mask for guest mode * * A vcpu can have different signals blocked in guest mode and user mode. - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 06 of 19] Move kvm_create_kernel_phys_mem to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027872 18000 # Node ID 02f38e54018070bafd501df846147f4ae7661109 # Parent 7f802db02478d5d5ec63348e126b54e85681c66f 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 [EMAIL PROTECTED] diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h --- a/libkvm/kvm-x86.h +++ b/libkvm/kvm-x86.h @@ -5,6 +5,8 @@ */ #ifndef KVM_X86_H #define KVM_X86_H + +#include kvm-common.h #include kvm-common.h @@ -33,4 +35,7 @@ int kvm_arch_create(kvm_context_t kvm, u int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes, void **vm_mem); +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 @@ -273,4 +273,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 @@ -373,38 +373,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 - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 10 of 19] Move kvm_get kmv_set_lapci functions to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027873 18000 # Node ID 8dad7519cc92eabd7d66ea3ea20c983dade61243 # Parent 76218015a52046be4d77069c3e999b6ca60d0528 Move kvm_get kmv_set_lapci functions to libkvm-x86.c Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -377,3 +377,34 @@ int kvm_destroy_memory_alias(kvm_context return kvm_create_memory_alias(kvm, phys_addr, 0, 0, 0); } +#ifdef KVM_CAP_IRQCHIP + +int kvm_get_lapic(kvm_context_t kvm, int vcpu, struct kvm_lapic_state *s) +{ + int r; + if (!kvm-irqchip_in_kernel) + return 0; + r = ioctl(kvm-vcpu_fd[vcpu], KVM_GET_LAPIC, s); + if (r == -1) { + r = -errno; + perror(kvm_get_lapic); + } + return r; +} + +int kvm_set_lapic(kvm_context_t kvm, int vcpu, struct kvm_lapic_state *s) +{ + int r; + if (!kvm-irqchip_in_kernel) + return 0; + r = ioctl(kvm-vcpu_fd[vcpu], KVM_SET_LAPIC, s); + if (r == -1) { + r = -errno; + perror(kvm_set_lapic); + } + return r; +} + +#endif + + diff --git a/libkvm/libkvm-x86.h b/libkvm/libkvm-x86.h --- a/libkvm/libkvm-x86.h +++ b/libkvm/libkvm-x86.h @@ -29,5 +29,30 @@ int kvm_create_memory_alias(kvm_context_ */ int kvm_destroy_memory_alias(kvm_context_t, uint64_t phys_addr); +#ifdef KVM_CAP_IRQCHIP + +/*! + * \brief Get in kernel local APIC for vcpu + * + * Save the local apic state including the timer of a virtual CPU + * + * \param kvm Pointer to the current kvm_context + * \param vcpu Which virtual CPU should be accessed + * \param s Local apic state of the specific virtual CPU + */ +int kvm_get_lapic(kvm_context_t kvm, int vcpu, struct kvm_lapic_state *s); + +/*! + * \brief Set in kernel local APIC for vcpu + * + * Restore the local apic state including the timer of a virtual CPU + * + * \param kvm Pointer to the current kvm_context + * \param vcpu Which virtual CPU should be accessed + * \param s Local apic state of the specific virtual CPU + */ +int kvm_set_lapic(kvm_context_t kvm, int vcpu, struct kvm_lapic_state *s); #endif + +#endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -539,32 +539,6 @@ int kvm_set_irqchip(kvm_context_t kvm, s if (r == -1) { r = -errno; perror(kvm_set_irqchip\n); - } - return r; -} - -int kvm_get_lapic(kvm_context_t kvm, int vcpu, struct kvm_lapic_state *s) -{ - int r; - if (!kvm-irqchip_in_kernel) - return 0; - r = ioctl(kvm-vcpu_fd[vcpu], KVM_GET_LAPIC, s); - if (r == -1) { - r = -errno; - perror(kvm_get_lapic); - } - return r; -} - -int kvm_set_lapic(kvm_context_t kvm, int vcpu, struct kvm_lapic_state *s) -{ - int r; - if (!kvm-irqchip_in_kernel) - return 0; - r = ioctl(kvm-vcpu_fd[vcpu], KVM_SET_LAPIC, s); - if (r == -1) { - r = -errno; - perror(kvm_set_lapic); } return r; } diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -484,27 +484,6 @@ int kvm_get_irqchip(kvm_context_t kvm, s */ int kvm_set_irqchip(kvm_context_t kvm, struct kvm_irqchip *chip); -/*! - * \brief Get in kernel local APIC for vcpu - * - * Save the local apic state including the timer of a virtual CPU - * - * \param kvm Pointer to the current kvm_context - * \param vcpu Which virtual CPU should be accessed - * \param s Local apic state of the specific virtual CPU - */ -int kvm_get_lapic(kvm_context_t kvm, int vcpu, struct kvm_lapic_state *s); - -/*! - * \brief Set in kernel local APIC for vcpu - * - * Restore the local apic state including the timer of a virtual CPU - * - * \param kvm Pointer to the current kvm_context - * \param vcpu Which virtual CPU should be accessed - * \param s Local apic state of the specific virtual CPU - */ -int kvm_set_lapic(kvm_context_t kvm, int vcpu, struct kvm_lapic_state *s); #endif - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 11 of 19] Make functions in libkvm.c nonstatic
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027873 18000 # Node ID 01b86b564fb9e751295ff8eddf5f38cfb24e1e34 # Parent 8dad7519cc92eabd7d66ea3ea20c983dade61243 Make functions in libkvm.c nonstatic. This patch makes the following functions nonstatic. These functions are potentially reusable by other archs, but are need by arch specific code in libkvm-x86.c. These functions include: handle_halt handle_shutdown post_kvm_run pre_kvm_run handle_io_window handle_debug Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/kvm-common.h b/libkvm/kvm-common.h --- a/libkvm/kvm-common.h +++ b/libkvm/kvm-common.h @@ -38,4 +38,13 @@ void *kvm_create_userspace_phys_mem(kvm_ void *kvm_create_userspace_phys_mem(kvm_context_t kvm, unsigned long phys_start, unsigned long len, int log, int writable); #endif + +int handle_halt(kvm_context_t kvm, int vcpu); +int handle_shutdown(kvm_context_t kvm, int vcpu); +void post_kvm_run(kvm_context_t kvm, int vcpu); +int pre_kvm_run(kvm_context_t kvm, int vcpu); +int handle_io_window(kvm_context_t kvm); +int handle_debug(kvm_context_t kvm, int vcpu); +int try_push_interrupts(kvm_context_t kvm); + #endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -657,7 +657,7 @@ static int handle_io(kvm_context_t kvm, return 0; } -static int handle_debug(kvm_context_t kvm, int vcpu) +int handle_debug(kvm_context_t kvm, int vcpu) { return kvm-callbacks-debug(kvm-opaque, vcpu); } @@ -942,17 +942,17 @@ static int handle_mmio(kvm_context_t kvm return r; } -static int handle_io_window(kvm_context_t kvm) +int handle_io_window(kvm_context_t kvm) { return kvm-callbacks-io_window(kvm-opaque); } -static int handle_halt(kvm_context_t kvm, int vcpu) +int handle_halt(kvm_context_t kvm, int vcpu) { return kvm-callbacks-halt(kvm-opaque, vcpu); } -static int handle_shutdown(kvm_context_t kvm, int vcpu) +int handle_shutdown(kvm_context_t kvm, int vcpu) { return kvm-callbacks-shutdown(kvm-opaque, vcpu); } @@ -962,12 +962,12 @@ int try_push_interrupts(kvm_context_t kv return kvm-callbacks-try_push_interrupts(kvm-opaque); } -static void post_kvm_run(kvm_context_t kvm, int vcpu) +void post_kvm_run(kvm_context_t kvm, int vcpu) { kvm-callbacks-post_kvm_run(kvm-opaque, vcpu); } -static int pre_kvm_run(kvm_context_t kvm, int vcpu) +int pre_kvm_run(kvm_context_t kvm, int vcpu) { return kvm-callbacks-pre_kvm_run(kvm-opaque, vcpu); } - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 01 of 19] Move kvm_context to kvmctl.h
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027872 18000 # Node ID 72c2d9f9786aea122419208189291808d56b8053 # Parent 6ce27ddeb45df182e923060ae3abe699ce704ca3 Move kvm_context to kvmctl.h This patch moves kvm_context from libkvm.c to kvm-context.h. This is so other files are able to see members of kvm_context. Also you should allways declare stuff like this in a header anyway. Also moved are delcrations MAX_VCPU, KVM_MAX_NUM_MEM_REGIONS, PAGE_SIZE PAGE_MASK to kvm-x86.h. The idea here is kvm-$(ARCH).h will be headers for interal use by libkvm. Headers name libkvm-$(ARCH) will be functions that are arch specific that will be exposed to a user. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/config-i386.mak b/libkvm/config-i386.mak --- a/libkvm/config-i386.mak +++ b/libkvm/config-i386.mak @@ -1,2 +1,4 @@ LIBDIR := /lib +CFLAGS += -m32 +CFLAGS += -D__i386__ diff --git a/libkvm/config-x86_64.mak b/libkvm/config-x86_64.mak --- a/libkvm/config-x86_64.mak +++ b/libkvm/config-x86_64.mak @@ -1,2 +1,4 @@ LIBDIR := /lib64 +CFLAGS += -m64 +CFLAGS += -D__x86_64__ diff --git a/libkvm/kvm-common.h b/libkvm/kvm-common.h new file mode 100644 --- /dev/null +++ b/libkvm/kvm-common.h @@ -0,0 +1,37 @@ +#ifndef KVM_COMMON_H +#define KVM_COMMON_H + +/* FIXME: share this number with kvm */ +/* FIXME: or dynamically alloc/realloc regions */ +#define KVM_MAX_NUM_MEM_REGIONS 8u +#define MAX_VCPUS 4 + + +/** + * \brief The KVM context + * + * The verbose KVM context + */ + +struct kvm_context { + /// Filedescriptor to /dev/kvm + int fd; + int vm_fd; + int vcpu_fd[MAX_VCPUS]; + struct kvm_run *run[MAX_VCPUS]; + /// Callbacks that KVM uses to emulate various unvirtualizable functionality + struct kvm_callbacks *callbacks; + void *opaque; + /// A pointer to the memory used as the physical memory for the guest + void *physical_memory; + /// is dirty pages logging enabled for all regions or not + int dirty_pages_log_all; + /// memory regions parameters + struct kvm_memory_region mem_regions[KVM_MAX_NUM_MEM_REGIONS]; + /// do not create in-kernel irqchip if set + int no_irqchip_creation; + /// in-kernel irqchip status + int irqchip_in_kernel; +}; + +#endif diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h new file mode 100644 --- /dev/null +++ b/libkvm/kvm-x86.h @@ -0,0 +1,14 @@ +/* This header is for functions variables that will ONLY be + * used inside libkvm for x86. + * THESE ARE NOT EXPOSED TO THE USER AND ARE ONLY FOR USE + * WITHIN LIBKVM. + */ +#ifndef KVM_X86_H +#define KVM_X86_H + +#include kvm-common.h + +#define PAGE_SIZE 4096ul +#define PAGE_MASK (~(PAGE_SIZE - 1)) + +#endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -37,43 +37,14 @@ #include libkvm.h #include kvm-abi-10.h +#if defined(__x86_64__) || defined(__i386__) +#include kvm-x86.h +#endif + static int kvm_abi = EXPECTED_KVM_API_VERSION; -#define PAGE_SIZE 4096ul -#define PAGE_MASK (~(PAGE_SIZE - 1)) - -/* FIXME: share this number with kvm */ -/* FIXME: or dynamically alloc/realloc regions */ -#define KVM_MAX_NUM_MEM_REGIONS 8u int free_slots[KVM_MAX_NUM_MEM_REGIONS]; unsigned long phys_addr_slots[KVM_MAX_NUM_MEM_REGIONS]; -#define MAX_VCPUS 4 - -/** - * \brief The KVM context - * - * The verbose KVM context - */ -struct kvm_context { - /// Filedescriptor to /dev/kvm - int fd; - int vm_fd; - int vcpu_fd[MAX_VCPUS]; - struct kvm_run *run[MAX_VCPUS]; - /// Callbacks that KVM uses to emulate various unvirtualizable functionality - struct kvm_callbacks *callbacks; - void *opaque; - /// A pointer to the memory used as the physical memory for the guest - void *physical_memory; - /// is dirty pages logging enabled for all regions or not - int dirty_pages_log_all; - /// memory regions parameters - struct kvm_memory_region mem_regions[KVM_MAX_NUM_MEM_REGIONS]; - /// do not create in-kernel irqchip if set - int no_irqchip_creation; - /// in-kernel irqchip status - int irqchip_in_kernel; -}; static void init_slots() { diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -1,4 +1,4 @@ -/** \file kvmctl.h +/** \file libkvm.h * libkvm API */ - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
[kvm-devel] [PATCH 13 of 19] Move msrs functions to libkvm-x86.c
# HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027873 18000 # Node ID 5bb5ef1b7faa8c11677b73fedbe089d0926ca4e9 # Parent 0ade452df6c708a2b44696a23e733d59c8906aea Move msrs functions to libkvm-x86.c This patch moves functions: kvm_msr_list move kvm_get_msrs move kvm_set_msrs Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h --- a/libkvm/kvm-x86.h +++ b/libkvm/kvm-x86.h @@ -42,4 +42,8 @@ int kvm_run_abi10(kvm_context_t kvm, int void kvm_show_code(kvm_context_t kvm, int vcpu); +struct kvm_msr_list *kvm_get_msr_list(kvm_context_t); +int kvm_get_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n); +int kvm_set_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n); + #endif diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -630,3 +630,71 @@ void kvm_show_code(kvm_context_t kvm, in fprintf(stderr, code:%s\n, code_str); } + +/* + * Returns available msr list. User must free. + */ +struct kvm_msr_list *kvm_get_msr_list(kvm_context_t kvm) +{ + struct kvm_msr_list sizer, *msrs; + int r, e; + + sizer.nmsrs = 0; + r = ioctl(kvm-fd, KVM_GET_MSR_INDEX_LIST, sizer); + if (r == -1 errno != E2BIG) + return NULL; + msrs = malloc(sizeof *msrs + sizer.nmsrs * sizeof *msrs-indices); + if (!msrs) { + errno = ENOMEM; + return NULL; + } + msrs-nmsrs = sizer.nmsrs; + r = ioctl(kvm-fd, KVM_GET_MSR_INDEX_LIST, msrs); + if (r == -1) { + e = errno; + free(msrs); + errno = e; + return NULL; + } + return msrs; +} + +int kvm_get_msrs(kvm_context_t kvm, int vcpu, struct kvm_msr_entry *msrs, +int n) +{ +struct kvm_msrs *kmsrs = malloc(sizeof *kmsrs + n * sizeof *msrs); +int r, e; + +if (!kmsrs) { + errno = ENOMEM; + return -1; +} +kmsrs-nmsrs = n; +memcpy(kmsrs-entries, msrs, n * sizeof *msrs); +r = ioctl(kvm-vcpu_fd[vcpu], KVM_GET_MSRS, kmsrs); +e = errno; +memcpy(msrs, kmsrs-entries, n * sizeof *msrs); +free(kmsrs); +errno = e; +return r; +} + +int kvm_set_msrs(kvm_context_t kvm, int vcpu, struct kvm_msr_entry *msrs, +int n) +{ +struct kvm_msrs *kmsrs = malloc(sizeof *kmsrs + n * sizeof *msrs); +int r, e; + +if (!kmsrs) { + errno = ENOMEM; + return -1; +} +kmsrs-nmsrs = n; +memcpy(kmsrs-entries, msrs, n * sizeof *msrs); +r = ioctl(kvm-vcpu_fd[vcpu], KVM_SET_MSRS, kmsrs); +e = errno; +free(kmsrs); +errno = e; +return r; +} + diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -635,73 +635,6 @@ int kvm_set_sregs(kvm_context_t kvm, int return ioctl(kvm-vcpu_fd[vcpu], KVM_SET_SREGS, sregs); } -/* - * Returns available msr list. User must free. - */ -struct kvm_msr_list *kvm_get_msr_list(kvm_context_t kvm) -{ - struct kvm_msr_list sizer, *msrs; - int r, e; - - sizer.nmsrs = 0; - r = ioctl(kvm-fd, KVM_GET_MSR_INDEX_LIST, sizer); - if (r == -1 errno != E2BIG) - return NULL; - msrs = malloc(sizeof *msrs + sizer.nmsrs * sizeof *msrs-indices); - if (!msrs) { - errno = ENOMEM; - return NULL; - } - msrs-nmsrs = sizer.nmsrs; - r = ioctl(kvm-fd, KVM_GET_MSR_INDEX_LIST, msrs); - if (r == -1) { - e = errno; - free(msrs); - errno = e; - return NULL; - } - return msrs; -} - -int kvm_get_msrs(kvm_context_t kvm, int vcpu, struct kvm_msr_entry *msrs, -int n) -{ -struct kvm_msrs *kmsrs = malloc(sizeof *kmsrs + n * sizeof *msrs); -int r, e; - -if (!kmsrs) { - errno = ENOMEM; - return -1; -} -kmsrs-nmsrs = n; -memcpy(kmsrs-entries, msrs, n * sizeof *msrs); -r = ioctl(kvm-vcpu_fd[vcpu], KVM_GET_MSRS, kmsrs); -e = errno; -memcpy(msrs, kmsrs-entries, n * sizeof *msrs); -free(kmsrs); -errno = e; -return r; -} - -int kvm_set_msrs(kvm_context_t kvm, int vcpu, struct kvm_msr_entry *msrs, -int n) -{ -struct kvm_msrs *kmsrs = malloc(sizeof *kmsrs + n * sizeof *msrs); -int r, e; - -if (!kmsrs) { - errno = ENOMEM; - return -1; -} -kmsrs-nmsrs = n; -memcpy(kmsrs-entries, msrs, n * sizeof *msrs); -r = ioctl(kvm-vcpu_fd[vcpu], KVM_SET_MSRS, kmsrs); -e = errno; -free(kmsrs); -errno = e; -return r; -} - static void print_seg(FILE *file, const char *name, struct kvm_segment *seg) { fprintf(stderr, diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -340,10 +340,6 @@ int kvm_get_sregs(kvm_context_t kvm, int */ int kvm_set_sregs(kvm_context_t
Re: [kvm-devel] [kvm-ppc-devel] [PATCH 01 of 19] Move kvm_context to kvmctl.h
* Remove the config-*.mak changes * Update the patch description * Supply a copyright notice in all new files -- Hollis Blanchard IBM Linux Technology Center On Fri, 2007-11-02 at 13:24 -0500, Jerone Young wrote: # HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027872 18000 # Node ID 72c2d9f9786aea122419208189291808d56b8053 # Parent 6ce27ddeb45df182e923060ae3abe699ce704ca3 Move kvm_context to kvmctl.h This patch moves kvm_context from libkvm.c to kvm-context.h. This is so other files are able to see members of kvm_context. Also you should allways declare stuff like this in a header anyway. Also moved are delcrations MAX_VCPU, KVM_MAX_NUM_MEM_REGIONS, PAGE_SIZE PAGE_MASK to kvm-x86.h. The idea here is kvm-$(ARCH).h will be headers for interal use by libkvm. Headers name libkvm-$(ARCH) will be functions that are arch specific that will be exposed to a user. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/config-i386.mak b/libkvm/config-i386.mak --- a/libkvm/config-i386.mak +++ b/libkvm/config-i386.mak @@ -1,2 +1,4 @@ LIBDIR := /lib +CFLAGS += -m32 +CFLAGS += -D__i386__ diff --git a/libkvm/config-x86_64.mak b/libkvm/config-x86_64.mak --- a/libkvm/config-x86_64.mak +++ b/libkvm/config-x86_64.mak @@ -1,2 +1,4 @@ LIBDIR := /lib64 +CFLAGS += -m64 +CFLAGS += -D__x86_64__ diff --git a/libkvm/kvm-common.h b/libkvm/kvm-common.h new file mode 100644 --- /dev/null +++ b/libkvm/kvm-common.h @@ -0,0 +1,37 @@ +#ifndef KVM_COMMON_H +#define KVM_COMMON_H + +/* FIXME: share this number with kvm */ +/* FIXME: or dynamically alloc/realloc regions */ +#define KVM_MAX_NUM_MEM_REGIONS 8u +#define MAX_VCPUS 4 + + +/** + * \brief The KVM context + * + * The verbose KVM context + */ + +struct kvm_context { + /// Filedescriptor to /dev/kvm + int fd; + int vm_fd; + int vcpu_fd[MAX_VCPUS]; + struct kvm_run *run[MAX_VCPUS]; + /// Callbacks that KVM uses to emulate various unvirtualizable functionality + struct kvm_callbacks *callbacks; + void *opaque; + /// A pointer to the memory used as the physical memory for the guest + void *physical_memory; + /// is dirty pages logging enabled for all regions or not + int dirty_pages_log_all; + /// memory regions parameters + struct kvm_memory_region mem_regions[KVM_MAX_NUM_MEM_REGIONS]; + /// do not create in-kernel irqchip if set + int no_irqchip_creation; + /// in-kernel irqchip status + int irqchip_in_kernel; +}; + +#endif diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h new file mode 100644 --- /dev/null +++ b/libkvm/kvm-x86.h @@ -0,0 +1,14 @@ +/* This header is for functions variables that will ONLY be + * used inside libkvm for x86. + * THESE ARE NOT EXPOSED TO THE USER AND ARE ONLY FOR USE + * WITHIN LIBKVM. + */ +#ifndef KVM_X86_H +#define KVM_X86_H + +#include kvm-common.h + +#define PAGE_SIZE 4096ul +#define PAGE_MASK (~(PAGE_SIZE - 1)) + +#endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -37,43 +37,14 @@ #include libkvm.h #include kvm-abi-10.h +#if defined(__x86_64__) || defined(__i386__) +#include kvm-x86.h +#endif + static int kvm_abi = EXPECTED_KVM_API_VERSION; -#define PAGE_SIZE 4096ul -#define PAGE_MASK (~(PAGE_SIZE - 1)) - -/* FIXME: share this number with kvm */ -/* FIXME: or dynamically alloc/realloc regions */ -#define KVM_MAX_NUM_MEM_REGIONS 8u int free_slots[KVM_MAX_NUM_MEM_REGIONS]; unsigned long phys_addr_slots[KVM_MAX_NUM_MEM_REGIONS]; -#define MAX_VCPUS 4 - -/** - * \brief The KVM context - * - * The verbose KVM context - */ -struct kvm_context { - /// Filedescriptor to /dev/kvm - int fd; - int vm_fd; - int vcpu_fd[MAX_VCPUS]; - struct kvm_run *run[MAX_VCPUS]; - /// Callbacks that KVM uses to emulate various unvirtualizable functionality - struct kvm_callbacks *callbacks; - void *opaque; - /// A pointer to the memory used as the physical memory for the guest - void *physical_memory; - /// is dirty pages logging enabled for all regions or not - int dirty_pages_log_all; - /// memory regions parameters - struct kvm_memory_region mem_regions[KVM_MAX_NUM_MEM_REGIONS]; - /// do not create in-kernel irqchip if set - int no_irqchip_creation; - /// in-kernel irqchip status - int irqchip_in_kernel; -}; static void init_slots() { diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -1,4 +1,4 @@ -/** \file kvmctl.h +/** \file libkvm.h * libkvm API */ - 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.
Re: [kvm-devel] [kvm-ppc-devel] [PATCH 02 of 19] Make static slot kvm_memory region funcions public
On Fri, 2007-11-02 at 13:24 -0500, Jerone Young wrote: diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -46,7 +46,7 @@ int free_slots[KVM_MAX_NUM_MEM_REGIONS]; int free_slots[KVM_MAX_NUM_MEM_REGIONS]; unsigned long phys_addr_slots[KVM_MAX_NUM_MEM_REGIONS]; -static void init_slots() +void init_slots() { int i; As long as you're here could you please add a void? That bugs me every time I see it. -- Hollis Blanchard IBM Linux Technology Center - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
Re: [kvm-devel] [kvm-ppc-devel] [PATCH 00 of 27] Refactor libkvm code Phase 1
Yes, everybody should be doing userspace memory allocation now, and we just need to support kernel allocation for compatibility on x86. -- Hollis Blanchard IBM Linux Technology Center On Fri, 2007-11-02 at 02:49 -0500, Jerone Young wrote: Hmm, The problem here is in the case of kvm_create_phys_mem kvm_create_default_phys_mem, most archs from now on should always be allocating guest memory from userspace (at least I think this correct). Now if this is not the case then really adding an architecture hook function to kvm_create_default_phys_mem would also solve this problem. As There is a mmap call that maps memory for video(?), which is something that is just for x86. With the size of these functions being very small, I think it's best to move them for now. Then if someone else does need them they can easily create there own and then we can figure out how to make a common function in this case. Anyone disagree? On Fri, 2007-11-02 at 13:26 +0800, Zhang, Xiantao wrote: Hi Young, Quick hand! For patch 07/27, 09/27, i have some concerns about them. In these two patches you moved the functions kvm_create_kernel_phys_mem, kvm_create_default_phys_mem to x86 arch. But I think it should work well for most archs. As somebody said, S390 may have a very different memory allocation mechanism, but we can't move them directly to x86 arch, because other archs may also need them. We should find another approach to handle them, and make s390 and other archs all happy ! What about your ideas?:) thanks Xiantao -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jerone Young Sent: 2007年11月1日 1:05 To: kvm-devel@lists.sourceforge.net Cc: [EMAIL PROTECTED] Subject: [kvm-devel] [PATCH 00 of 27] Refactor libkvm code Phase 1 Kaniciwa! I am here to once again bring great honorable patches to refactor libkvm x86 code. Patches that I sent in the past for this really took the wrong approach, and also many variables that I was splitting out actually could be shared amongst many architectures. This is the first phase as much of the code is tightly written for x86 but can be reused by other archs, it's just a matter of an agreed upon method. Also since there are about 27 of these lets get through these before moving through more. Signed-off-by: Jerone Young [EMAIL PROTECTED] - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel - 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/ ___ kvm-ppc-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/kvm-ppc-devel - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
Re: [kvm-devel] [kvm-ppc-devel] [PATCH 17 of 19] Move cr8 functions to libkvm-x86.c
These are exported functions, right? So their prototypes should remain in libkvm.h. (This is OK even on other architectures, because you'll only get build error if somebody actually calls them.) The alternative is to make many exported headers: libkvm.h, libkvm-x86.h, etc. I think a combined libkvm.h is simpler and therefore better. -- Hollis Blanchard IBM Linux Technology Center On Fri, 2007-11-02 at 13:25 -0500, Jerone Young wrote: # HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027873 18000 # Node ID ab3e5d875c37bf36db4e73331fd3234523598c6e # Parent 7e750325679dd770206ec6da84f00a4dc4be1b2c Move cr8 functions to libkvm-x86.c This patch moves functions: kvm_set_cr8 kvm_get_cr8 cr8 is an x86 only register. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -766,3 +766,19 @@ uint64_t kvm_get_apic_base(kvm_context_t return run-apic_base; } +void kvm_set_cr8(kvm_context_t kvm, int vcpu, uint64_t cr8) +{ + struct kvm_run *run = kvm-run[vcpu]; + + if (kvm_abi == 10) { + ((struct kvm_run_abi10 *)run)-cr8 = cr8; + return; + } + run-cr8 = cr8; +} + +__u64 kvm_get_cr8(kvm_context_t kvm, int vcpu) +{ + return kvm-run[vcpu]-cr8; +} + diff --git a/libkvm/libkvm-x86.h b/libkvm/libkvm-x86.h --- a/libkvm/libkvm-x86.h +++ b/libkvm/libkvm-x86.h @@ -81,5 +81,27 @@ void kvm_show_regs(kvm_context_t kvm, in */ uint64_t kvm_get_apic_base(kvm_context_t kvm, int vcpu); +/*! + * \brief Set up cr8 for next time the vcpu is executed + * + * This is a fast setter for cr8, which will be applied when the + * vcpu next enters guest mode. + * + * \param kvm Pointer to the current kvm_context + * \param vcpu Which virtual CPU should get dumped + * \param cr8 next cr8 value + */ +void kvm_set_cr8(kvm_context_t kvm, int vcpu, uint64_t cr8); + +/*! + * \brief Get cr8 for sync tpr in qemu apic emulation + * + * This is a getter for cr8, which used to sync with the tpr in qemu + * apic emualtion. + * + * \param kvm Pointer to the current kvm_context + * \param vcpu Which virtual CPU should get dumped + */ +__u64 kvm_get_cr8(kvm_context_t kvm, int vcpu); #endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -727,22 +727,6 @@ int kvm_is_ready_for_interrupt_injection return run-ready_for_interrupt_injection; } -void kvm_set_cr8(kvm_context_t kvm, int vcpu, uint64_t cr8) -{ - struct kvm_run *run = kvm-run[vcpu]; - - if (kvm_abi == 10) { - ((struct kvm_run_abi10 *)run)-cr8 = cr8; - return; - } - run-cr8 = cr8; -} - -__u64 kvm_get_cr8(kvm_context_t kvm, int vcpu) -{ - return kvm-run[vcpu]-cr8; -} - int kvm_run(kvm_context_t kvm, int vcpu) { int r; diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -215,29 +215,6 @@ int kvm_is_ready_for_interrupt_injection int kvm_is_ready_for_interrupt_injection(kvm_context_t kvm, int vcpu); /*! - * \brief Set up cr8 for next time the vcpu is executed - * - * This is a fast setter for cr8, which will be applied when the - * vcpu next enters guest mode. - * - * \param kvm Pointer to the current kvm_context - * \param vcpu Which virtual CPU should get dumped - * \param cr8 next cr8 value - */ -void kvm_set_cr8(kvm_context_t kvm, int vcpu, uint64_t cr8); - -/*! - * \brief Get cr8 for sync tpr in qemu apic emulation - * - * This is a getter for cr8, which used to sync with the tpr in qemu - * apic emualtion. - * - * \param kvm Pointer to the current kvm_context - * \param vcpu Which virtual CPU should get dumped - */ -__u64 kvm_get_cr8(kvm_context_t kvm, int vcpu); - -/*! * \brief Read VCPU registers * * This gets the GP registers from the VCPU and outputs them - 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/ ___ kvm-ppc-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/kvm-ppc-devel - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
Re: [kvm-devel] [kvm-ppc-devel] [PATCH 18 of 19] Move kvm_setup_cpuid to libkvm-x86.c
Again, exported function - keep declarations in libkvm.h. (Please check your other patches for this issue.) -- Hollis Blanchard IBM Linux Technology Center On Fri, 2007-11-02 at 13:25 -0500, Jerone Young wrote: # HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027874 18000 # Node ID 7e15060d3192c2ad951cb7b8295737b84b3b46b9 # Parent ab3e5d875c37bf36db4e73331fd3234523598c6e Move kvm_setup_cpuid to libkvm-x86.c cpuid is an x86 instruction, so needs to go in the approriate place. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -782,3 +782,21 @@ __u64 kvm_get_cr8(kvm_context_t kvm, int return kvm-run[vcpu]-cr8; } +int kvm_setup_cpuid(kvm_context_t kvm, int vcpu, int nent, + struct kvm_cpuid_entry *entries) +{ + struct kvm_cpuid *cpuid; + int r; + + cpuid = malloc(sizeof(*cpuid) + nent * sizeof(*entries)); + if (!cpuid) + return -ENOMEM; + + cpuid-nent = nent; + memcpy(cpuid-entries, entries, nent * sizeof(*entries)); + r = ioctl(kvm-vcpu_fd[vcpu], KVM_SET_CPUID, cpuid); + + free(cpuid); + return r; +} + diff --git a/libkvm/libkvm-x86.h b/libkvm/libkvm-x86.h --- a/libkvm/libkvm-x86.h +++ b/libkvm/libkvm-x86.h @@ -104,4 +104,19 @@ void kvm_set_cr8(kvm_context_t kvm, int */ __u64 kvm_get_cr8(kvm_context_t kvm, int vcpu); +/*! + * \brief Setup a vcpu's cpuid instruction emulation + * + * Set up a table of cpuid function to cpuid outputs.\n + * + * \param kvm Pointer to the current kvm_context + * \param vcpu Which virtual CPU should be initialized + * \param nent number of entries to be installed + * \param entries cpuid function entries table + * \return 0 on success, or -errno on error + */ +int kvm_setup_cpuid(kvm_context_t kvm, int vcpu, int nent, + struct kvm_cpuid_entry *entries); + + #endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -822,24 +822,6 @@ int kvm_guest_debug(kvm_context_t kvm, i return ioctl(kvm-vcpu_fd[vcpu], KVM_DEBUG_GUEST, dbg); } -int kvm_setup_cpuid(kvm_context_t kvm, int vcpu, int nent, - struct kvm_cpuid_entry *entries) -{ - struct kvm_cpuid *cpuid; - int r; - - cpuid = malloc(sizeof(*cpuid) + nent * sizeof(*entries)); - if (!cpuid) - return -ENOMEM; - - cpuid-nent = nent; - memcpy(cpuid-entries, entries, nent * sizeof(*entries)); - r = ioctl(kvm-vcpu_fd[vcpu], KVM_SET_CPUID, cpuid); - - free(cpuid); - return r; -} - int kvm_set_signal_mask(kvm_context_t kvm, int vcpu, const sigset_t *sigset) { struct kvm_signal_mask *sigmask; diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -324,20 +324,6 @@ int kvm_guest_debug(kvm_context_t, int v int kvm_guest_debug(kvm_context_t, int vcpu, struct kvm_debug_guest *dbg); /*! - * \brief Setup a vcpu's cpuid instruction emulation - * - * Set up a table of cpuid function to cpuid outputs.\n - * - * \param kvm Pointer to the current kvm_context - * \param vcpu Which virtual CPU should be initialized - * \param nent number of entries to be installed - * \param entries cpuid function entries table - * \return 0 on success, or -errno on error - */ -int kvm_setup_cpuid(kvm_context_t kvm, int vcpu, int nent, - struct kvm_cpuid_entry *entries); - -/*! * \brief Set a vcpu's signal mask for guest mode * * A vcpu can have different signals blocked in guest mode and user mode. - 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/ ___ kvm-ppc-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/kvm-ppc-devel - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
Re: [kvm-devel] [kvm-ppc-devel] [PATCH 01 of 19] Move kvm_context to kvmctl.h
I'll wait awhile before sending another super patch bomb to the list. Perhaps I can add these changes afterward if need be. Actually do need the conf-*.mak changes. Otherwise if you compile libkvm on it's own you don't get the CFLAGS. Now the way it really should be is that those config-*.mak files shouldn't be there and the ones used should be those in the user directory. I was planning to send a patch for this after these patches got in. On Fri, 2007-11-02 at 14:34 -0500, Hollis Blanchard wrote: * Remove the config-*.mak changes * Update the patch description * Supply a copyright notice in all new files -- Hollis Blanchard IBM Linux Technology Center On Fri, 2007-11-02 at 13:24 -0500, Jerone Young wrote: # HG changeset patch # User Jerone Young [EMAIL PROTECTED] # Date 1194027872 18000 # Node ID 72c2d9f9786aea122419208189291808d56b8053 # Parent 6ce27ddeb45df182e923060ae3abe699ce704ca3 Move kvm_context to kvmctl.h This patch moves kvm_context from libkvm.c to kvm-context.h. This is so other files are able to see members of kvm_context. Also you should allways declare stuff like this in a header anyway. Also moved are delcrations MAX_VCPU, KVM_MAX_NUM_MEM_REGIONS, PAGE_SIZE PAGE_MASK to kvm-x86.h. The idea here is kvm-$(ARCH).h will be headers for interal use by libkvm. Headers name libkvm-$(ARCH) will be functions that are arch specific that will be exposed to a user. Signed-off-by: Jerone Young [EMAIL PROTECTED] diff --git a/libkvm/config-i386.mak b/libkvm/config-i386.mak --- a/libkvm/config-i386.mak +++ b/libkvm/config-i386.mak @@ -1,2 +1,4 @@ LIBDIR := /lib +CFLAGS += -m32 +CFLAGS += -D__i386__ diff --git a/libkvm/config-x86_64.mak b/libkvm/config-x86_64.mak --- a/libkvm/config-x86_64.mak +++ b/libkvm/config-x86_64.mak @@ -1,2 +1,4 @@ LIBDIR := /lib64 +CFLAGS += -m64 +CFLAGS += -D__x86_64__ diff --git a/libkvm/kvm-common.h b/libkvm/kvm-common.h new file mode 100644 --- /dev/null +++ b/libkvm/kvm-common.h @@ -0,0 +1,37 @@ +#ifndef KVM_COMMON_H +#define KVM_COMMON_H + +/* FIXME: share this number with kvm */ +/* FIXME: or dynamically alloc/realloc regions */ +#define KVM_MAX_NUM_MEM_REGIONS 8u +#define MAX_VCPUS 4 + + +/** + * \brief The KVM context + * + * The verbose KVM context + */ + +struct kvm_context { + /// Filedescriptor to /dev/kvm + int fd; + int vm_fd; + int vcpu_fd[MAX_VCPUS]; + struct kvm_run *run[MAX_VCPUS]; + /// Callbacks that KVM uses to emulate various unvirtualizable functionality + struct kvm_callbacks *callbacks; + void *opaque; + /// A pointer to the memory used as the physical memory for the guest + void *physical_memory; + /// is dirty pages logging enabled for all regions or not + int dirty_pages_log_all; + /// memory regions parameters + struct kvm_memory_region mem_regions[KVM_MAX_NUM_MEM_REGIONS]; + /// do not create in-kernel irqchip if set + int no_irqchip_creation; + /// in-kernel irqchip status + int irqchip_in_kernel; +}; + +#endif diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h new file mode 100644 --- /dev/null +++ b/libkvm/kvm-x86.h @@ -0,0 +1,14 @@ +/* This header is for functions variables that will ONLY be + * used inside libkvm for x86. + * THESE ARE NOT EXPOSED TO THE USER AND ARE ONLY FOR USE + * WITHIN LIBKVM. + */ +#ifndef KVM_X86_H +#define KVM_X86_H + +#include kvm-common.h + +#define PAGE_SIZE 4096ul +#define PAGE_MASK (~(PAGE_SIZE - 1)) + +#endif diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -37,43 +37,14 @@ #include libkvm.h #include kvm-abi-10.h +#if defined(__x86_64__) || defined(__i386__) +#include kvm-x86.h +#endif + static int kvm_abi = EXPECTED_KVM_API_VERSION; -#define PAGE_SIZE 4096ul -#define PAGE_MASK (~(PAGE_SIZE - 1)) - -/* FIXME: share this number with kvm */ -/* FIXME: or dynamically alloc/realloc regions */ -#define KVM_MAX_NUM_MEM_REGIONS 8u int free_slots[KVM_MAX_NUM_MEM_REGIONS]; unsigned long phys_addr_slots[KVM_MAX_NUM_MEM_REGIONS]; -#define MAX_VCPUS 4 - -/** - * \brief The KVM context - * - * The verbose KVM context - */ -struct kvm_context { - /// Filedescriptor to /dev/kvm - int fd; - int vm_fd; - int vcpu_fd[MAX_VCPUS]; - struct kvm_run *run[MAX_VCPUS]; - /// Callbacks that KVM uses to emulate various unvirtualizable functionality - struct kvm_callbacks *callbacks; - void *opaque; - /// A pointer to the memory used as the physical memory for the guest - void *physical_memory; - /// is dirty pages logging enabled for all regions or not - int dirty_pages_log_all; - /// memory regions parameters - struct kvm_memory_region mem_regions[KVM_MAX_NUM_MEM_REGIONS]; - /// do not create in-kernel
[kvm-devel] [PATCH] KVM: is_long_mode should check for EFER_LMA
From bfed574c93b36a19e2976ddcaae7939dd6c6fc41 Mon Sep 17 00:00:00 2001 From: Amit Shah [EMAIL PROTECTED] Date: Sat, 3 Nov 2007 02:38:00 +0530 Subject: [PATCH] KVM: is_long_mode should check for EFER_LMA is_long_mode currently checks the LongModeEnable bit in EFER instead of the LongModeActive bit. This should work for most cases, but for some broken implementations that set the LME bit before enabling PAE in CR4 to enter long mode. This is noticed on a solaris guest on an AMD host (but might not be specific to AMD). Signed-off-by: Amit Shah [EMAIL PROTECTED] --- drivers/kvm/x86.h |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/drivers/kvm/x86.h b/drivers/kvm/x86.h index 663b822..5c10761 100644 --- a/drivers/kvm/x86.h +++ b/drivers/kvm/x86.h @@ -104,7 +104,7 @@ static inline int kvm_mmu_reload(struct kvm_vcpu *vcpu) static inline int is_long_mode(struct kvm_vcpu *vcpu) { #ifdef CONFIG_X86_64 - return vcpu-shadow_efer EFER_LME; + return vcpu-shadow_efer EFER_LMA; #else return 0; #endif -- 1.4.4.2 - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel
Re: [kvm-devel] Starting a VM reboots my machine
Dor Laor wrote: Cam Macdonell wrote: Hi, I'm running an AMD vendor_id : AuthenticAMD cpu family : 15 model : 75 model name : AMD Athlon(tm) 64 X2 Dual Core Processor 4600+ with 4GB of RAM and Scientific Linux 5.0. I've compiled kvm-48 on it and the compile works and loading the modules works fine, the only dmesg line referring to kvm is SELinux: initialized (dev kvm_anon_inodefs, type kvm_anon_inodefs), not configured for labeling. However, when I boot any KVM, the machine reboots. It works fine with the no-kvm flag. Has anyone else seen this behaviour? We have some instabilities with AMD. These issues are under debug these days. Can you please supply netconsole debug messages from the host. This can be very helpful. Hi Dor, I tried to hunt on my own, but I can't find much on netconsole set up. Do you have any tips or links for setting up netconsole? I'm running Scientific Linux (a RHEL5 clone). Thanks very much, Cam - 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/ ___ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel