From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gerd Hoffmann Subject: Re: [patch] kvmctl.c: allow custom memory setup. Date: Thu, 18 Oct 2007 17:29:19 +0200 Message-ID: <47177BCF.7010309@redhat.com> References: <470C8D28.2060408@qumranet.com> <470F2806.8090902@redhat.com> <4710701C.2040200@qumranet.com> <47134476.1050609@redhat.com> <47134857.9030102@redhat.com> <1192446374.6578.0.camel@izike-woof.qumranet.com> <47134BC0.1000008@redhat.com> <1192447442.6911.5.camel@izike-woof.qumranet.com> <47135284.1060106@redhat.com> <4715DEFC.8010507@redhat.com> <471690D2.2060204@qumranet.com> <47170D95.1050603@redhat.com> <471714FC.6050703@qumranet.com> <47173300.70907@redhat.com> <1192703432.3175.18.camel@izike-woof.qumranet.com> <471737E8.6000708@qumranet.com> <47173E21.3010502@redhat.com> <471741D1.7000500@qumranet.com> <47175088.7000507@redhat.com> <471752BC.90600@qumranet.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------060709020203020607030108" Cc: kvm-devel To: Avi Kivity Return-path: In-Reply-To: <471752BC.90600-atKUWr5tajBWk0Htik3J/w@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Errors-To: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: kvm.vger.kernel.org This is a multi-part message in MIME format. --------------060709020203020607030108 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Avi Kivity wrote: > Gerd Hoffmann wrote: >> No, I'm hacking up one more user ;) > > Nice. What will it do? Run xenified guest kernels without Xen. >> Should I send an updated patch or do you just drop these lines when >> merging? > > Please send a rebased and retested patch. Oh, -47 is there. Updated patch attached. cheers, Gerd --------------060709020203020607030108 Content-Type: text/x-patch; name="kvm.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="kvm.diff" diff -up ./kvmctl.h.upstream ./kvmctl.h --- ./kvmctl.h.upstream 2007-10-18 17:09:06.000000000 +0200 +++ ./kvmctl.h 2007-10-18 17:09:11.000000000 +0200 @@ -146,6 +146,9 @@ int kvm_get_shadow_pages(kvm_context_t k int kvm_create(kvm_context_t kvm, unsigned long phys_mem_bytes, void **phys_mem); +int kvm_create_vm(kvm_context_t kvm); +void kvm_create_irqchip(kvm_context_t kvm); + /*! * \brief Create a new virtual cpu * @@ -413,6 +416,9 @@ void *kvm_create_phys_mem(kvm_context_t, unsigned long len, int slot, int log, int writable); void kvm_destroy_phys_mem(kvm_context_t, unsigned long phys_start, unsigned long len, int slot); +int kvm_register_userspace_phys_mem(kvm_context_t kvm, + unsigned long phys_start, void *userspace_addr, + unsigned long len, int slot, int log); int kvm_get_dirty_pages(kvm_context_t, int slot, void *buf); diff -up ./kvmctl.c.upstream ./kvmctl.c --- ./kvmctl.c.upstream 2007-10-18 17:08:57.000000000 +0200 +++ ./kvmctl.c 2007-10-18 17:18:53.000000000 +0200 @@ -436,12 +436,9 @@ int kvm_alloc_userspace_memory(kvm_conte #endif -int kvm_create(kvm_context_t kvm, unsigned long phys_mem_bytes, void **vm_mem) +int kvm_create_vm(kvm_context_t kvm) { - unsigned long memory = (phys_mem_bytes + PAGE_SIZE - 1) & PAGE_MASK; int fd = kvm->fd; - int zfd; - int r; kvm->vcpu_fd[0] = -1; @@ -451,6 +448,15 @@ int kvm_create(kvm_context_t kvm, unsign return -1; } kvm->vm_fd = fd; + return 0; +} + +int kvm_create_default_phys_mem(kvm_context_t kvm, unsigned long phys_mem_bytes, + void **vm_mem) +{ + unsigned long memory = (phys_mem_bytes + PAGE_SIZE - 1) & PAGE_MASK; + int zfd; + int r; #ifdef KVM_CAP_USER_MEMORY r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY); @@ -468,13 +474,19 @@ int kvm_create(kvm_context_t kvm, unsign close(zfd); kvm->physical_memory = *vm_mem; + return 0; +} + +void kvm_create_irqchip(kvm_context_t kvm) +{ + int r; kvm->irqchip_in_kernel = 0; #ifdef KVM_CAP_IRQCHIP if (!kvm->no_irqchip_creation) { r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_IRQCHIP); if (r > 0) { /* kernel irqchip supported */ - r = ioctl(fd, KVM_CREATE_IRQCHIP); + r = ioctl(kvm->vm_fd, KVM_CREATE_IRQCHIP); if (r >= 0) kvm->irqchip_in_kernel = 1; else @@ -482,6 +494,19 @@ int kvm_create(kvm_context_t kvm, unsign } } #endif +} + +int kvm_create(kvm_context_t kvm, unsigned long phys_mem_bytes, void **vm_mem) +{ + int r; + + r = kvm_create_vm(kvm); + if (r < 0) + return r; + r = kvm_create_default_phys_mem(kvm, phys_mem_bytes, vm_mem); + if (r < 0) + return r; + kvm_create_irqchip(kvm); r = kvm_create_vcpu(kvm, 0); if (r < 0) return r; @@ -577,6 +602,32 @@ void *kvm_create_phys_mem(kvm_context_t log, writable); } +int kvm_register_userspace_phys_mem(kvm_context_t kvm, + unsigned long phys_start, void *userspace_addr, + unsigned long len, int slot, int log) +{ + struct kvm_userspace_memory_region memory = { + .slot = slot, + .memory_size = len, + .guest_phys_addr = phys_start, + .userspace_addr = (intptr_t)userspace_addr, + .flags = log ? KVM_MEM_LOG_DIRTY_PAGES : 0, + }; + int r; + + if (!kvm->physical_memory) + kvm->physical_memory = userspace_addr - phys_start; + + r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &memory); + if (r == -1) { + fprintf(stderr, "create_userspace_phys_mem: %s\n", strerror(errno)); + return -1; + } + + kvm_userspace_memory_region_save_params(kvm, &memory); + return 0; +} + /* destroy/free a whole slot. * phys_start, len and slot are the params passed to kvm_create_phys_mem() */ --------------060709020203020607030108 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- 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/ --------------060709020203020607030108 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ kvm-devel mailing list kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/kvm-devel --------------060709020203020607030108--