All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Izik Eidus <izike-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
Cc: kvm-devel
	<kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>,
	Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
Subject: [patch] kvmctl.c: allow custom memory setup.
Date: Wed, 17 Oct 2007 12:07:56 +0200	[thread overview]
Message-ID: <4715DEFC.8010507@redhat.com> (raw)
In-Reply-To: <47135284.1060106-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

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

Gerd Hoffmann wrote:
> I've made kvm_create() optionally skip the memory setup, so I can create
> my own later on.  That doesn't work though because creating the vcpu
> fails then.

Ugh, vmx grabs last 4 pages from slot 0 (looks like for real mode
emulation).  Thus memory must exist before creating the vcpu.  Which
makes fitting filemap-backed memory into the current libkvm init
procedure a bit difficuilt.

I've decided to split the kvm_create() into a bunch of pieces which can
be called as needed, so I can first create the vm, then do my custom
memory setup, then create the vcpu without making vmx unhappy ...

cheers,
  Gerd


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

* split kvm_create() into smaller pieces which can be individually
  called if needed.
* add kvm_register_userspace_phys_mem() function.
---
 user/kvmctl.c |   61 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 user/kvmctl.h |    8 +++++++
 2 files changed, 64 insertions(+), 5 deletions(-)

Index: kvm-46/user/kvmctl.c
===================================================================
--- kvm-46.orig/user/kvmctl.c
+++ kvm-46/user/kvmctl.c
@@ -427,12 +427,9 @@ int kvm_alloc_userspace_memory(kvm_conte
 	return 0;
 }
 
-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;
 
@@ -442,6 +439,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;
 
 	r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY);
 	if (r > 0)
@@ -457,18 +463,37 @@ 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;
 	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
 				printf("Create kernel PIC irqchip failed\n");
 		}
 	}
+}
+
+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;
@@ -558,6 +583,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", 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()
  */
Index: kvm-46/user/kvmctl.h
===================================================================
--- kvm-46.orig/user/kvmctl.h
+++ kvm-46/user/kvmctl.h
@@ -137,6 +137,11 @@ 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);
+int kvm_create_default_phys_mem(kvm_context_t kvm, unsigned long phys_mem_bytes,
+				void **vm_mem);
+void kvm_create_irqchip(kvm_context_t kvm);
+
 /*!
  * \brief Create a new virtual cpu
  *
@@ -404,6 +409,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);
 
 

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

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

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

_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel

  parent reply	other threads:[~2007-10-17 10:07 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-10  8:28 [ANNOUNCE] kvm-46 release Avi Kivity
     [not found] ` <470C8D28.2060408-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-10-10  8:39   ` Jun Koi
     [not found]     ` <fdaac4d50710100139v204e0e1du21efc51df95f77e7-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-10-10  8:41       ` Avi Kivity
     [not found]         ` <470C9034.2000206-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-10-10  9:04           ` Jun Koi
     [not found]             ` <fdaac4d50710100204n23a3486bk3012fa995b14455d-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-10-10  9:07               ` Avi Kivity
     [not found]                 ` <470C9660.8090700-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-10-11  1:02                   ` Jun Koi
     [not found]                     ` <fdaac4d50710101802u27013e48l8c88641a904f6ef8-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-10-11  1:13                       ` Anthony Liguori
2007-10-10  9:52   ` Farkas Levente
     [not found]     ` <470CA0DB.8020303-lWVWdrzSO4GHXe+LvDLADg@public.gmane.org>
2007-10-10 10:08       ` Avi Kivity
     [not found]         ` <470CA4AA.6020909-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-10-10 10:18           ` Farkas Levente
2007-10-10 10:16       ` Farkas Levente
2007-10-10 11:24   ` Farkas Levente
     [not found]     ` <470CB672.4070209-lWVWdrzSO4GHXe+LvDLADg@public.gmane.org>
2007-10-10 11:28       ` Avi Kivity
     [not found]         ` <470CB75E.4000404-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-10-10 11:35           ` Farkas Levente
     [not found]             ` <470CB91A.1020508-lWVWdrzSO4GHXe+LvDLADg@public.gmane.org>
2007-10-10 11:58               ` Avi Kivity
     [not found]                 ` <470CBE58.3040807-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-10-10 12:49                   ` Farkas Levente
     [not found]                     ` <470CCA61.3080007-lWVWdrzSO4GHXe+LvDLADg@public.gmane.org>
2007-10-13  7:18                       ` Avi Kivity
     [not found]                         ` <47107150.3000106-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-10-15 14:22                           ` Farkas Levente
2007-10-10 13:39   ` Daniel P. Berrange
     [not found]     ` <20071010133912.GB1894-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-10-10 13:39       ` Avi Kivity
     [not found]         ` <470CD61A.4090103-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-10-10 13:49           ` Haydn Solomon
     [not found]             ` <b75785ba0710100649y3903f0ccma8c687d033fffec7-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-10-10 14:59               ` Dor Laor
     [not found]                 ` <470CE8E7.7010001-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-10-10 15:22                   ` Haydn Solomon
2007-10-12  7:53   ` Gerd Hoffmann
     [not found]     ` <470F2806.8090902-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-10-13  7:13       ` Avi Kivity
     [not found]         ` <4710701C.2040200-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-10-15 10:44           ` Gerd Hoffmann
     [not found]             ` <47134476.1050609-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-10-15 11:00               ` Gerd Hoffmann
     [not found]                 ` <47134857.9030102-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-10-15 11:06                   ` Izik Eidus
     [not found]                     ` <1192446374.6578.0.camel-siXIhNkUrCXckEVJwWePHtCfPAL7FxvL@public.gmane.org>
2007-10-15 11:15                       ` Gerd Hoffmann
     [not found]                         ` <47134BC0.1000008-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-10-15 11:24                           ` Izik Eidus
     [not found]                             ` <1192447442.6911.5.camel-siXIhNkUrCXckEVJwWePHtCfPAL7FxvL@public.gmane.org>
2007-10-15 11:44                               ` Gerd Hoffmann
     [not found]                                 ` <47135284.1060106-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-10-17 10:07                                   ` Gerd Hoffmann [this message]
     [not found]                                     ` <4715DEFC.8010507-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-10-17 22:46                                       ` [patch] kvmctl.c: allow custom memory setup Izik Eidus
     [not found]                                         ` <471690D2.2060204-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-10-17 22:56                                           ` Izik Eidus
2007-10-18  7:39                                           ` Gerd Hoffmann
     [not found]                                             ` <47170D95.1050603-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-10-18  8:10                                               ` Dor Laor
     [not found]                                                 ` <471714FC.6050703-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-10-18 10:18                                                   ` Gerd Hoffmann
     [not found]                                                     ` <47173300.70907-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-10-18 10:30                                                       ` Izik Eidus
     [not found]                                                         ` <1192703432.3175.18.camel-siXIhNkUrCXckEVJwWePHtCfPAL7FxvL@public.gmane.org>
2007-10-18 10:39                                                           ` Avi Kivity
     [not found]                                                             ` <471737E8.6000708-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-10-18 11:06                                                               ` Gerd Hoffmann
     [not found]                                                                 ` <47173E21.3010502-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-10-18 11:21                                                                   ` Avi Kivity
     [not found]                                                                     ` <471741D1.7000500-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-10-18 12:24                                                                       ` Gerd Hoffmann
     [not found]                                                                         ` <47175088.7000507-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-10-18 12:34                                                                           ` Avi Kivity
     [not found]                                                                             ` <471752BC.90600-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-10-18 15:29                                                                               ` Gerd Hoffmann
     [not found]                                                                                 ` <47177BCF.7010309-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-10-18 16:43                                                                                   ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4715DEFC.8010507@redhat.com \
    --to=kraxel-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
    --cc=izike-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.