* [PATCH 0/12] Get rid of kernel memory allocation
@ 2008-09-08 19:30 Glauber Costa
2008-09-08 19:30 ` [PATCH] start removing kernel memory functions Glauber Costa
` (14 more replies)
0 siblings, 15 replies; 33+ messages in thread
From: Glauber Costa @ 2008-09-08 19:30 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori
Hey guys,
Some eons before the dinosaurs went extinct, we used to support
a method of memory allocation different than the one advertised by
KVM_CAP_USER_MEMORY.
This series of patches attempt on removing the support for it in kvm-userspace
entirely. It will make the job of integrating kvm and qemu much easier. As
a matter of fact, platforms other than x86 (and ia64, because it seems to
borrow a great deal of code from x86) don't even support that method.
I remind you that for those who still want to run userspaces old enough for Hypervisors
that lack user memory capability, you always have the option of running an
old enough userspace, so to match.
This patch series leaves one test for this capability in place, at machine
initialization: KVM will refuse to run if it's not in there. Later on,
if we deprecate the capability altogether from the kernel, we may do it through
an ABI check. But for now, I think this is enough.
series stat:
Glauber Costa (12):
start removing kernel memory functions
remove tests of user memory from vl.c
coalesce memory allocation
remove KVM_CAP_USER_MEMORY reference from qemu-kvm.c
remove KVM_CAP_USER_MEMORY from libkvm.c.
remove create_kernel_phys_mem
get rid of kvm_create_userspace_phys_mem
remove user_alloc field from slot representation
merge destroy phys mem functions
rename kvm_register_userspace_phys_mem
remove kernel memory code from hw/pc.c
remove kernel memory allocation code from ipf.c
libkvm/kvm-common.h | 8 +--
libkvm/libkvm-ia64.c | 31 ----------
libkvm/libkvm-powerpc.c | 21 -------
libkvm/libkvm-s390.c | 21 -------
libkvm/libkvm-x86.c | 124 ----------------------------------------
libkvm/libkvm.c | 146 ++++++++++++++---------------------------------
libkvm/libkvm.h | 2 +-
qemu/hw/ipf.c | 25 ++-------
qemu/hw/pc.c | 19 +------
qemu/qemu-kvm.c | 52 +++++++----------
qemu/vl.c | 26 ++------
11 files changed, 79 insertions(+), 396 deletions(-)
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH] start removing kernel memory functions
2008-09-08 19:30 [PATCH 0/12] Get rid of kernel memory allocation Glauber Costa
@ 2008-09-08 19:30 ` Glauber Costa
2008-09-08 19:30 ` [PATCH] remove tests of user memory from vl.c Glauber Costa
2008-09-09 14:25 ` [PATCH 0/12] Get rid of kernel memory allocation Avi Kivity
` (13 subsequent siblings)
14 siblings, 1 reply; 33+ messages in thread
From: Glauber Costa @ 2008-09-08 19:30 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
kvm_arch_create_default_phys_mem and kvm_alloc_kernel_memory
are legacy. Remove them, and their callers. The whole removal
will be split for bisectability. These ones goes first because they are
only called at initialization
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
libkvm/kvm-common.h | 3 --
libkvm/libkvm-ia64.c | 25 -------------
libkvm/libkvm-powerpc.c | 14 -------
libkvm/libkvm-s390.c | 14 -------
libkvm/libkvm-x86.c | 91 -----------------------------------------------
libkvm/libkvm.c | 19 +++-------
6 files changed, 5 insertions(+), 161 deletions(-)
diff --git a/libkvm/kvm-common.h b/libkvm/kvm-common.h
index 7092085..93cea1b 100644
--- a/libkvm/kvm-common.h
+++ b/libkvm/kvm-common.h
@@ -78,9 +78,6 @@ void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
void **vm_mem);
-int kvm_arch_create_default_phys_mem(kvm_context_t kvm,
- unsigned long phys_mem_bytes,
- void **vm_mem);
int kvm_arch_run(struct kvm_run *run, kvm_context_t kvm, int vcpu);
diff --git a/libkvm/libkvm-ia64.c b/libkvm/libkvm-ia64.c
index f35a16c..152d8fd 100644
--- a/libkvm/libkvm-ia64.c
+++ b/libkvm/libkvm-ia64.c
@@ -33,31 +33,6 @@
#include <fcntl.h>
#include <stdlib.h>
-int kvm_arch_create_default_phys_mem(kvm_context_t kvm,
- unsigned long phys_mem_bytes,
- void **vm_mem)
-{
- int zfd;
-
- zfd = open("/dev/zero", O_RDONLY);
- if (zfd == -1) {
- perror("open /dev/zero");
- return -1;
- }
- mmap(*vm_mem + 0xa8000, 0x8000, PROT_READ|PROT_WRITE,
- MAP_PRIVATE|MAP_FIXED, zfd, 0);
- close(zfd);
-
- return 0;
-}
-
-
-int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory,
- void **vm_mem)
-{
- return 0;
-}
-
void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
unsigned long len, int log, int writable)
{
diff --git a/libkvm/libkvm-powerpc.c b/libkvm/libkvm-powerpc.c
index 376aca4..c523f26 100644
--- a/libkvm/libkvm-powerpc.c
+++ b/libkvm/libkvm-powerpc.c
@@ -43,13 +43,6 @@ int handle_dcr(struct kvm_run *run, kvm_context_t kvm, int vcpu)
return ret;
}
-int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory,
- void **vm_mem)
-{
- fprintf(stderr, "%s: Operation not supported\n", __FUNCTION__);
- return -1;
-}
-
void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
unsigned long len, int log, int writable)
{
@@ -102,13 +95,6 @@ int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
return 0;
}
-int kvm_arch_create_default_phys_mem(kvm_context_t kvm,
- unsigned long phys_mem_bytes,
- void **vm_mem)
-{
- return 0;
-}
-
int kvm_arch_run(struct kvm_run *run, kvm_context_t kvm, int vcpu)
{
int ret = 0;
diff --git a/libkvm/libkvm-s390.c b/libkvm/libkvm-s390.c
index b3e4e92..59c534f 100644
--- a/libkvm/libkvm-s390.c
+++ b/libkvm/libkvm-s390.c
@@ -22,13 +22,6 @@
#include <stdio.h>
#include <inttypes.h>
-int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory,
- void **vm_mem)
-{
- fprintf(stderr, "%s: Operation not supported\n", __FUNCTION__);
- return -1;
-}
-
void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
unsigned long len, int log, int writable)
{
@@ -87,13 +80,6 @@ int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
return 0;
}
-int kvm_arch_create_default_phys_mem(kvm_context_t kvm,
- unsigned long phys_mem_bytes,
- void **vm_mem)
-{
- return 0;
-}
-
int kvm_arch_run(struct kvm_run *run, kvm_context_t kvm, int vcpu)
{
int ret = 0;
diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c
index ea97bdd..4ca3d7b 100644
--- a/libkvm/libkvm-x86.c
+++ b/libkvm/libkvm-x86.c
@@ -13,79 +13,6 @@
#include <fcntl.h>
#include <stdlib.h>
-int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory,
- void **vm_mem)
-{
- unsigned long dosmem = 0xa0000;
- unsigned long exmem = 0xc0000;
- unsigned long pcimem = 0xe0000000;
- 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 = 0x100000000ULL,
- };
-
-#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,
- low_memory.memory_size, 0, 0, 0);
-
-
- 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,
- extended_memory.memory_size, 0, 0, 0);
- }
-
- 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,
- above_4g_memory.memory_size, 0, 0, 0);
- }
-
- *vm_mem = mmap(NULL, memory, PROT_READ|PROT_WRITE, MAP_SHARED, kvm->vm_fd, 0);
-
- return 0;
-}
-
int kvm_set_tss_addr(kvm_context_t kvm, unsigned long addr)
{
#ifdef KVM_CAP_SET_TSS_ADDR
@@ -126,24 +53,6 @@ static int kvm_init_tss(kvm_context_t kvm)
return 0;
}
-int kvm_arch_create_default_phys_mem(kvm_context_t kvm,
- unsigned long phys_mem_bytes,
- void **vm_mem)
-{
- int zfd;
-
- zfd = open("/dev/zero", O_RDONLY);
- if (zfd == -1) {
- perror("open /dev/zero");
- return -1;
- }
- mmap(*vm_mem + 0xa8000, 0x8000, PROT_READ|PROT_WRITE,
- MAP_PRIVATE|MAP_FIXED, zfd, 0);
- close(zfd);
-
- return 0;
-}
-
int kvm_create_pit(kvm_context_t kvm)
{
#ifdef KVM_CAP_PIT
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
index 029e7b1..bacd29d 100644
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -328,24 +328,15 @@ static 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 r;
-
#ifdef KVM_CAP_USER_MEMORY
- r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY);
+ int r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY);
if (r > 0)
return 0;
- else
+ fprintf(stderr, "Hypervisor too old: KVM_CAP_USER_MEMORY extension not supported\n");
+#else
+#error Hypervisor too old: KVM_CAP_USER_MEMORY extension not supported
#endif
- r = kvm_alloc_kernel_memory(kvm, memory, vm_mem);
- if (r < 0)
- return r;
-
- r = kvm_arch_create_default_phys_mem(kvm, phys_mem_bytes, vm_mem);
- if (r < 0)
- return r;
-
- return 0;
+ return -1;
}
int kvm_check_extension(kvm_context_t kvm, int ext)
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH] remove tests of user memory from vl.c
2008-09-08 19:30 ` [PATCH] start removing kernel memory functions Glauber Costa
@ 2008-09-08 19:30 ` Glauber Costa
2008-09-08 19:30 ` [PATCH] coalesce memory allocation Glauber Costa
0 siblings, 1 reply; 33+ messages in thread
From: Glauber Costa @ 2008-09-08 19:30 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
kvm_qemu_create_context() will fail if we don't have
userspace memory capability, so no need to check it here.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
qemu/vl.c | 18 +++++-------------
1 files changed, 5 insertions(+), 13 deletions(-)
diff --git a/qemu/vl.c b/qemu/vl.c
index b34a114..25a1ee9 100644
--- a/qemu/vl.c
+++ b/qemu/vl.c
@@ -9934,20 +9934,12 @@ int main(int argc, char **argv)
fprintf(stderr, "Could not create KVM context\n");
exit(1);
}
-#ifdef KVM_CAP_USER_MEMORY
-{
- int ret;
- ret = kvm_qemu_check_extension(KVM_CAP_USER_MEMORY);
- if (ret) {
- phys_ram_base = qemu_alloc_physram(phys_ram_size);
- if (!phys_ram_base) {
- fprintf(stderr, "Could not allocate physical memory\n");
- exit(1);
- }
- }
-}
-#endif
+ phys_ram_base = qemu_alloc_physram(phys_ram_size);
+ if (!phys_ram_base) {
+ fprintf(stderr, "Could not allocate physical memory\n");
+ exit(1);
+ }
} else {
phys_ram_base = qemu_vmalloc(phys_ram_size);
if (!phys_ram_base) {
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH] coalesce memory allocation
2008-09-08 19:30 ` [PATCH] remove tests of user memory from vl.c Glauber Costa
@ 2008-09-08 19:30 ` Glauber Costa
2008-09-08 19:30 ` [PATCH] remove KVM_CAP_USER_MEMORY reference from qemu-kvm.c Glauber Costa
0 siblings, 1 reply; 33+ messages in thread
From: Glauber Costa @ 2008-09-08 19:30 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
Put all memory allocation under qemu_alloc_physram().
Protect the mem_area code with #ifdef USE_KVM. Although it
is not really needed, it help us keep track of the fact that
this is a kvm-only feature to the moment.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
qemu/vl.c | 18 +++++++-----------
1 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/qemu/vl.c b/qemu/vl.c
index 25a1ee9..022b3b8 100644
--- a/qemu/vl.c
+++ b/qemu/vl.c
@@ -9019,8 +9019,10 @@ void *qemu_alloc_physram(unsigned long memory)
void *area = NULL;
unsigned long map_len = memory;
+#ifdef USE_KVM
if (mem_path)
area = alloc_mem_area(memory, &map_len, mem_path);
+#endif
if (!area)
area = qemu_vmalloc(memory);
#ifdef USE_KVM
@@ -9934,18 +9936,12 @@ int main(int argc, char **argv)
fprintf(stderr, "Could not create KVM context\n");
exit(1);
}
+ }
- phys_ram_base = qemu_alloc_physram(phys_ram_size);
- if (!phys_ram_base) {
- fprintf(stderr, "Could not allocate physical memory\n");
- exit(1);
- }
- } else {
- phys_ram_base = qemu_vmalloc(phys_ram_size);
- if (!phys_ram_base) {
- fprintf(stderr, "Could not allocate physical memory\n");
- exit(1);
- }
+ phys_ram_base = qemu_alloc_physram(phys_ram_size);
+ if (!phys_ram_base) {
+ fprintf(stderr, "Could not allocate physical memory\n");
+ exit(1);
}
/* init the dynamic translator */
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH] remove KVM_CAP_USER_MEMORY reference from qemu-kvm.c
2008-09-08 19:30 ` [PATCH] coalesce memory allocation Glauber Costa
@ 2008-09-08 19:30 ` Glauber Costa
2008-09-08 19:30 ` [PATCH] remove KVM_CAP_USER_MEMORY from libkvm.c Glauber Costa
2008-09-10 19:23 ` [PATCH] remove KVM_CAP_USER_MEMORY reference from qemu-kvm.c Jan Kiszka
0 siblings, 2 replies; 33+ messages in thread
From: Glauber Costa @ 2008-09-08 19:30 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
kvm_cpu_register_physical_memory() is its only user. Remove it.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
qemu/qemu-kvm.c | 52 +++++++++++++++++++++-------------------------------
1 files changed, 21 insertions(+), 31 deletions(-)
diff --git a/qemu/qemu-kvm.c b/qemu/qemu-kvm.c
index 8d366e5..f0ef21e 100644
--- a/qemu/qemu-kvm.c
+++ b/qemu/qemu-kvm.c
@@ -775,42 +775,32 @@ void kvm_cpu_register_physical_memory(target_phys_addr_t start_addr,
unsigned long size,
unsigned long phys_offset)
{
-#ifdef KVM_CAP_USER_MEMORY
int r = 0;
-
- r = kvm_check_extension(kvm_context, KVM_CAP_USER_MEMORY);
- if (r) {
- if (!(phys_offset & ~TARGET_PAGE_MASK)) {
- r = kvm_is_allocated_mem(kvm_context, start_addr, size);
- if (r)
- return;
- r = kvm_is_intersecting_mem(kvm_context, start_addr);
- if (r)
- kvm_create_mem_hole(kvm_context, start_addr, size);
- r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
- phys_ram_base + phys_offset,
- size, 0);
- }
- if (phys_offset & IO_MEM_ROM) {
- phys_offset &= ~IO_MEM_ROM;
- r = kvm_is_intersecting_mem(kvm_context, start_addr);
- if (r)
- kvm_create_mem_hole(kvm_context, start_addr, size);
- r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
- phys_ram_base + phys_offset,
- size, 0);
- }
- if (r < 0) {
- printf("kvm_cpu_register_physical_memory: failed\n");
- exit(1);
- }
- return;
+ if (!(phys_offset & ~TARGET_PAGE_MASK)) {
+ r = kvm_is_allocated_mem(kvm_context, start_addr, size);
+ if (r)
+ return;
+ r = kvm_is_intersecting_mem(kvm_context, start_addr);
+ if (r)
+ kvm_create_mem_hole(kvm_context, start_addr, size);
+ r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
+ phys_ram_base + phys_offset,
+ size, 0);
}
-#endif
if (phys_offset & IO_MEM_ROM) {
phys_offset &= ~IO_MEM_ROM;
- memcpy(phys_ram_base + start_addr, phys_ram_base + phys_offset, size);
+ r = kvm_is_intersecting_mem(kvm_context, start_addr);
+ if (r)
+ kvm_create_mem_hole(kvm_context, start_addr, size);
+ r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
+ phys_ram_base + phys_offset,
+ size, 0);
+ }
+ if (r < 0) {
+ printf("kvm_cpu_register_physical_memory: failed\n");
+ exit(1);
}
+ return;
}
int kvm_setup_guest_memory(void *area, unsigned long size)
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH] remove KVM_CAP_USER_MEMORY from libkvm.c.
2008-09-08 19:30 ` [PATCH] remove KVM_CAP_USER_MEMORY reference from qemu-kvm.c Glauber Costa
@ 2008-09-08 19:30 ` Glauber Costa
2008-09-08 19:30 ` [PATCH] remove create_kernel_phys_mem Glauber Costa
2008-09-10 19:23 ` [PATCH] remove KVM_CAP_USER_MEMORY reference from qemu-kvm.c Jan Kiszka
1 sibling, 1 reply; 33+ messages in thread
From: Glauber Costa @ 2008-09-08 19:30 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
One of them is left, which is the initial check.
Code that does ioctl checking is left to be removed
in a future commit.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
libkvm/libkvm.c | 18 ------------------
1 files changed, 0 insertions(+), 18 deletions(-)
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
index bacd29d..cfb1195 100644
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -153,7 +153,6 @@ static int kvm_dirty_pages_log_change(kvm_context_t kvm, unsigned long phys_addr
return 1;
}
flag |= slots[slot].flags;
-#ifdef KVM_CAP_USER_MEMORY
if (slots[slot].user_alloc) {
struct kvm_userspace_memory_region mem = {
.slot = slot,
@@ -164,7 +163,6 @@ static int kvm_dirty_pages_log_change(kvm_context_t kvm, unsigned long phys_addr
};
r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &mem);
}
-#endif
if (!slots[slot].user_alloc) {
struct kvm_memory_region mem = {
.slot = slot,
@@ -388,8 +386,6 @@ int kvm_create(kvm_context_t kvm, unsigned long phys_mem_bytes, void **vm_mem)
}
-#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)
{
@@ -457,20 +453,14 @@ void kvm_destroy_userspace_phys_mem(kvm_context_t kvm,
free_slot(memory.slot);
}
-#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);
}
@@ -496,7 +486,6 @@ int kvm_is_allocated_mem(kvm_context_t kvm, unsigned long phys_start,
int kvm_create_mem_hole(kvm_context_t kvm, unsigned long phys_start,
unsigned long len)
{
-#ifdef KVM_CAP_USER_MEMORY
int slot;
int r;
struct kvm_userspace_memory_region rmslot;
@@ -556,7 +545,6 @@ int kvm_create_mem_hole(kvm_context_t kvm, unsigned long phys_start,
register_slot(newslot2.slot, newslot2.guest_phys_addr,
newslot2.memory_size, 1, newslot2.userspace_addr,
newslot2.flags);
-#endif
return 0;
}
@@ -565,7 +553,6 @@ int kvm_register_userspace_phys_mem(kvm_context_t kvm,
unsigned long len, int log)
{
-#ifdef KVM_CAP_USER_MEMORY
struct kvm_userspace_memory_region memory = {
.memory_size = len,
.guest_phys_addr = phys_start,
@@ -583,9 +570,6 @@ int kvm_register_userspace_phys_mem(kvm_context_t kvm,
register_slot(memory.slot, memory.guest_phys_addr, memory.memory_size,
1, memory.userspace_addr, memory.flags);
return 0;
-#else
- return -ENOSYS;
-#endif
}
@@ -611,11 +595,9 @@ void kvm_destroy_phys_mem(kvm_context_t kvm, unsigned long phys_start,
phys_start = slots[slot].phys_addr;
}
-#ifdef KVM_CAP_USER_MEMORY
if (ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY) > 0)
kvm_destroy_userspace_phys_mem(kvm, phys_start);
else
-#endif
kvm_create_kernel_phys_mem(kvm, phys_start, 0, 0, 0);
}
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH] remove create_kernel_phys_mem
2008-09-08 19:30 ` [PATCH] remove KVM_CAP_USER_MEMORY from libkvm.c Glauber Costa
@ 2008-09-08 19:30 ` Glauber Costa
2008-09-08 19:30 ` [PATCH] get rid of kvm_create_userspace_phys_mem Glauber Costa
0 siblings, 1 reply; 33+ messages in thread
From: Glauber Costa @ 2008-09-08 19:30 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
Wipe out create_kernel_phys_mem(), and all of its users.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
libkvm/kvm-common.h | 3 ---
libkvm/libkvm-ia64.c | 6 ------
libkvm/libkvm-powerpc.c | 7 -------
libkvm/libkvm-s390.c | 7 -------
libkvm/libkvm-x86.c | 33 ---------------------------------
libkvm/libkvm.c | 14 +++-----------
6 files changed, 3 insertions(+), 67 deletions(-)
diff --git a/libkvm/kvm-common.h b/libkvm/kvm-common.h
index 93cea1b..0c04cbc 100644
--- a/libkvm/kvm-common.h
+++ b/libkvm/kvm-common.h
@@ -72,9 +72,6 @@ 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);
-void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
- unsigned long len, int log, int writable);
-
int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
void **vm_mem);
diff --git a/libkvm/libkvm-ia64.c b/libkvm/libkvm-ia64.c
index 152d8fd..f3afc56 100644
--- a/libkvm/libkvm-ia64.c
+++ b/libkvm/libkvm-ia64.c
@@ -33,12 +33,6 @@
#include <fcntl.h>
#include <stdlib.h>
-void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
- unsigned long len, int log, int writable)
-{
- return NULL;
-}
-
int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
void **vm_mem)
{
diff --git a/libkvm/libkvm-powerpc.c b/libkvm/libkvm-powerpc.c
index c523f26..aaebfef 100644
--- a/libkvm/libkvm-powerpc.c
+++ b/libkvm/libkvm-powerpc.c
@@ -43,13 +43,6 @@ int handle_dcr(struct kvm_run *run, kvm_context_t kvm, int vcpu)
return ret;
}
-void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
- unsigned long len, int log, int writable)
-{
- fprintf(stderr, "%s: Operation not supported\n", __FUNCTION__);
- return NULL;
-}
-
void kvm_show_code(kvm_context_t kvm, int vcpu)
{
fprintf(stderr, "%s: Operation not supported\n", __FUNCTION__);
diff --git a/libkvm/libkvm-s390.c b/libkvm/libkvm-s390.c
index 59c534f..041c0ce 100644
--- a/libkvm/libkvm-s390.c
+++ b/libkvm/libkvm-s390.c
@@ -22,13 +22,6 @@
#include <stdio.h>
#include <inttypes.h>
-void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
- unsigned long len, int log, int writable)
-{
- fprintf(stderr, "%s: Operation not supported\n", __FUNCTION__);
- return NULL;
-}
-
void kvm_show_code(kvm_context_t kvm, int vcpu)
{
fprintf(stderr, "%s: Operation not supported\n", __FUNCTION__);
diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c
index 4ca3d7b..a8cca15 100644
--- a/libkvm/libkvm-x86.c
+++ b/libkvm/libkvm-x86.c
@@ -145,39 +145,6 @@ int kvm_arch_run(struct kvm_run *run,kvm_context_t kvm, int vcpu)
return r;
}
-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, memory.memory_size,
- 0, 0, memory.flags);
-
- 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;
-}
-
#define MAX_ALIAS_SLOTS 4
static struct {
uint64_t start;
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
index cfb1195..5b48240 100644
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -456,13 +456,8 @@ void kvm_destroy_userspace_phys_mem(kvm_context_t kvm,
void *kvm_create_phys_mem(kvm_context_t kvm, unsigned long phys_start,
unsigned long len, int log, int writable)
{
- 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
- return kvm_create_kernel_phys_mem(kvm, phys_start, len,
- log, writable);
+ return kvm_create_userspace_phys_mem(kvm, phys_start, len,
+ log, writable);
}
int kvm_is_intersecting_mem(kvm_context_t kvm, unsigned long phys_start)
@@ -595,10 +590,7 @@ void kvm_destroy_phys_mem(kvm_context_t kvm, unsigned long phys_start,
phys_start = slots[slot].phys_addr;
}
- if (ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY) > 0)
- kvm_destroy_userspace_phys_mem(kvm, phys_start);
- else
- kvm_create_kernel_phys_mem(kvm, phys_start, 0, 0, 0);
+ kvm_destroy_userspace_phys_mem(kvm, phys_start);
}
static int kvm_get_map(kvm_context_t kvm, int ioctl_num, int slot, void *buf)
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH] get rid of kvm_create_userspace_phys_mem
2008-09-08 19:30 ` [PATCH] remove create_kernel_phys_mem Glauber Costa
@ 2008-09-08 19:30 ` Glauber Costa
2008-09-08 19:30 ` [PATCH] remove user_alloc field from slot representation Glauber Costa
0 siblings, 1 reply; 33+ messages in thread
From: Glauber Costa @ 2008-09-08 19:30 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
It is just kvm_create_phys_mem() right now.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
libkvm/libkvm.c | 15 ++++-----------
1 files changed, 4 insertions(+), 11 deletions(-)
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
index 5b48240..5d42b43 100644
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -386,8 +386,8 @@ int kvm_create(kvm_context_t kvm, unsigned long phys_mem_bytes, void **vm_mem)
}
-void *kvm_create_userspace_phys_mem(kvm_context_t kvm, unsigned long phys_start,
- unsigned long len, int log, int writable)
+void *kvm_create_phys_mem(kvm_context_t kvm, unsigned long phys_start,
+ unsigned long len, int log, int writable)
{
int r;
int prot = PROT_READ;
@@ -408,7 +408,7 @@ void *kvm_create_userspace_phys_mem(kvm_context_t kvm, unsigned long phys_start,
MAP_FIXED | MAP_SHARED | MAP_ANONYMOUS, -1, 0);
#endif
if (ptr == MAP_FAILED) {
- fprintf(stderr, "create_userspace_phys_mem: %s", strerror(errno));
+ fprintf(stderr, "%s: %s", __func__, strerror(errno));
return 0;
}
@@ -418,7 +418,7 @@ void *kvm_create_userspace_phys_mem(kvm_context_t kvm, unsigned long phys_start,
memory.slot = get_free_slot(kvm);
r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &memory);
if (r == -1) {
- fprintf(stderr, "create_userspace_phys_mem: %s", strerror(errno));
+ fprintf(stderr, "%s: %s", __func__, strerror(errno));
return 0;
}
register_slot(memory.slot, memory.guest_phys_addr, memory.memory_size,
@@ -453,13 +453,6 @@ void kvm_destroy_userspace_phys_mem(kvm_context_t kvm,
free_slot(memory.slot);
}
-void *kvm_create_phys_mem(kvm_context_t kvm, unsigned long phys_start,
- unsigned long len, int log, int writable)
-{
- return kvm_create_userspace_phys_mem(kvm, phys_start, len,
- log, writable);
-}
-
int kvm_is_intersecting_mem(kvm_context_t kvm, unsigned long phys_start)
{
return get_intersecting_slot(phys_start) != -1;
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH] remove user_alloc field from slot representation
2008-09-08 19:30 ` [PATCH] get rid of kvm_create_userspace_phys_mem Glauber Costa
@ 2008-09-08 19:30 ` Glauber Costa
2008-09-08 19:30 ` [PATCH] merge destroy phys mem functions Glauber Costa
0 siblings, 1 reply; 33+ messages in thread
From: Glauber Costa @ 2008-09-08 19:30 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
All allocations are "user" now. So we don't need this field
anymore.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
libkvm/kvm-common.h | 2 +-
libkvm/libkvm.c | 39 +++++++++++++++------------------------
2 files changed, 16 insertions(+), 25 deletions(-)
diff --git a/libkvm/kvm-common.h b/libkvm/kvm-common.h
index 0c04cbc..d22556b 100644
--- a/libkvm/kvm-common.h
+++ b/libkvm/kvm-common.h
@@ -63,7 +63,7 @@ struct kvm_context {
void init_slots(void);
int get_free_slot(kvm_context_t kvm);
void register_slot(int slot, unsigned long phys_addr, unsigned long len,
- int user_alloc, unsigned long userspace_addr, unsigned flags);
+ unsigned long userspace_addr, unsigned flags);
void free_slot(int slot);
int get_slot(unsigned long phys_addr);
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
index 5d42b43..560b1bd 100644
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -58,7 +58,6 @@ int kvm_page_size;
struct slot_info {
unsigned long phys_addr;
unsigned long len;
- int user_alloc;
unsigned long userspace_addr;
unsigned flags;
};
@@ -101,11 +100,10 @@ int get_free_slot(kvm_context_t kvm)
}
void register_slot(int slot, unsigned long phys_addr, unsigned long len,
- int user_alloc, unsigned long userspace_addr, unsigned flags)
+ unsigned long userspace_addr, unsigned flags)
{
slots[slot].phys_addr = phys_addr;
slots[slot].len = len;
- slots[slot].user_alloc = user_alloc;
slots[slot].userspace_addr = userspace_addr;
slots[slot].flags = flags;
}
@@ -144,36 +142,29 @@ int get_intersecting_slot(unsigned long phys_addr)
static int kvm_dirty_pages_log_change(kvm_context_t kvm, unsigned long phys_addr
, __u32 flag)
{
- int r;
- int slot;
-
- slot = get_slot(phys_addr);
+ int r = -1;
+ int slot = get_slot(phys_addr);
if (slot == -1) {
fprintf(stderr, "BUG: %s: invalid parameters\n", __FUNCTION__);
return 1;
}
+
flag |= slots[slot].flags;
- if (slots[slot].user_alloc) {
+
+ {
struct kvm_userspace_memory_region mem = {
- .slot = slot,
.memory_size = slots[slot].len,
.guest_phys_addr = slots[slot].phys_addr,
.userspace_addr = slots[slot].userspace_addr,
.flags = flag,
};
+
+
+
r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &mem);
+ if (r == -1)
+ fprintf(stderr, "%s: %m\n", __FUNCTION__);
}
- if (!slots[slot].user_alloc) {
- struct kvm_memory_region mem = {
- .slot = slot,
- .memory_size = slots[slot].len,
- .guest_phys_addr = slots[slot].phys_addr,
- .flags = flag,
- };
- r = ioctl(kvm->vm_fd, KVM_SET_MEMORY_REGION, &mem);
- }
- if (r == -1)
- fprintf(stderr, "%s: %m\n", __FUNCTION__);
return r;
}
@@ -422,7 +413,7 @@ void *kvm_create_phys_mem(kvm_context_t kvm, unsigned long phys_start,
return 0;
}
register_slot(memory.slot, memory.guest_phys_addr, memory.memory_size,
- 1, memory.userspace_addr, memory.flags);
+ memory.userspace_addr, memory.flags);
return ptr;
}
@@ -522,7 +513,7 @@ int kvm_create_mem_hole(kvm_context_t kvm, unsigned long phys_start,
return -1;
}
register_slot(newslot1.slot, newslot1.guest_phys_addr,
- newslot1.memory_size, 1, newslot1.userspace_addr,
+ newslot1.memory_size, newslot1.userspace_addr,
newslot1.flags);
r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &newslot2);
@@ -531,7 +522,7 @@ int kvm_create_mem_hole(kvm_context_t kvm, unsigned long phys_start,
return -1;
}
register_slot(newslot2.slot, newslot2.guest_phys_addr,
- newslot2.memory_size, 1, newslot2.userspace_addr,
+ newslot2.memory_size, newslot2.userspace_addr,
newslot2.flags);
return 0;
}
@@ -556,7 +547,7 @@ int kvm_register_userspace_phys_mem(kvm_context_t kvm,
return -1;
}
register_slot(memory.slot, memory.guest_phys_addr, memory.memory_size,
- 1, memory.userspace_addr, memory.flags);
+ memory.userspace_addr, memory.flags);
return 0;
}
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH] merge destroy phys mem functions
2008-09-08 19:30 ` [PATCH] remove user_alloc field from slot representation Glauber Costa
@ 2008-09-08 19:30 ` Glauber Costa
2008-09-08 19:30 ` [PATCH] rename kvm_register_userspace_phys_mem Glauber Costa
0 siblings, 1 reply; 33+ messages in thread
From: Glauber Costa @ 2008-09-08 19:30 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
kvm_destroy_userspace_phys_mem() and kvm_destroy_phys_mem()
can be merged into a single function, now that kernel allocation
is no more.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
libkvm/libkvm.c | 45 +++++++++++++++++----------------------------
1 files changed, 17 insertions(+), 28 deletions(-)
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
index 560b1bd..32481e5 100644
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -418,32 +418,6 @@ void *kvm_create_phys_mem(kvm_context_t kvm, unsigned long phys_start,
return ptr;
}
-void kvm_destroy_userspace_phys_mem(kvm_context_t kvm,
- unsigned long phys_start)
-{
- int r;
- struct kvm_userspace_memory_region memory = {
- .memory_size = 0,
- .guest_phys_addr = phys_start,
- .flags = 0,
- };
-
- memory.userspace_addr = 0;
- memory.slot = get_slot(phys_start);
-
- if (memory.slot == -1)
- return;
-
- r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &memory);
- if (r == -1) {
- fprintf(stderr, "destroy_userspace_phys_mem: %s",
- strerror(errno));
- return;
- }
-
- free_slot(memory.slot);
-}
-
int kvm_is_intersecting_mem(kvm_context_t kvm, unsigned long phys_start)
{
return get_intersecting_slot(phys_start) != -1;
@@ -559,10 +533,17 @@ void kvm_destroy_phys_mem(kvm_context_t kvm, unsigned long phys_start,
unsigned long len)
{
int slot;
+ int r;
+ struct kvm_userspace_memory_region memory = {
+ .memory_size = 0,
+ .guest_phys_addr = phys_start,
+ .userspace_addr = 0,
+ .flags = 0,
+ };
slot = get_slot(phys_start);
- if (slot >= KVM_MAX_NUM_MEM_REGIONS) {
+ if ((slot >= KVM_MAX_NUM_MEM_REGIONS) || (slot == -1)) {
fprintf(stderr, "BUG: %s: invalid parameters (slot=%d)\n",
__FUNCTION__, slot);
return;
@@ -574,7 +555,15 @@ void kvm_destroy_phys_mem(kvm_context_t kvm, unsigned long phys_start,
phys_start = slots[slot].phys_addr;
}
- kvm_destroy_userspace_phys_mem(kvm, phys_start);
+ memory.slot = slot;
+ r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &memory);
+ if (r == -1) {
+ fprintf(stderr, "destroy_userspace_phys_mem: %s",
+ strerror(errno));
+ return;
+ }
+
+ free_slot(memory.slot);
}
static int kvm_get_map(kvm_context_t kvm, int ioctl_num, int slot, void *buf)
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH] rename kvm_register_userspace_phys_mem
2008-09-08 19:30 ` [PATCH] merge destroy phys mem functions Glauber Costa
@ 2008-09-08 19:30 ` Glauber Costa
2008-09-08 19:30 ` [PATCH] remove kernel memory code from hw/pc.c Glauber Costa
0 siblings, 1 reply; 33+ messages in thread
From: Glauber Costa @ 2008-09-08 19:30 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
Change its name to kvm_register_phys_mem().
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
libkvm/libkvm.c | 2 +-
libkvm/libkvm.h | 2 +-
qemu/qemu-kvm.c | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
index 32481e5..f5df5c3 100644
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -501,7 +501,7 @@ int kvm_create_mem_hole(kvm_context_t kvm, unsigned long phys_start,
return 0;
}
-int kvm_register_userspace_phys_mem(kvm_context_t kvm,
+int kvm_register_phys_mem(kvm_context_t kvm,
unsigned long phys_start, void *userspace_addr,
unsigned long len, int log)
{
diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h
index 346eedf..79dd769 100644
--- a/libkvm/libkvm.h
+++ b/libkvm/libkvm.h
@@ -459,7 +459,7 @@ int kvm_is_allocated_mem(kvm_context_t kvm, unsigned long phys_start,
unsigned long len);
int kvm_create_mem_hole(kvm_context_t kvm, unsigned long phys_start,
unsigned long len);
-int kvm_register_userspace_phys_mem(kvm_context_t kvm,
+int kvm_register_phys_mem(kvm_context_t kvm,
unsigned long phys_start, void *userspace_addr,
unsigned long len, int log);
int kvm_get_dirty_pages(kvm_context_t, unsigned long phys_addr, void *buf);
diff --git a/qemu/qemu-kvm.c b/qemu/qemu-kvm.c
index f0ef21e..c522a28 100644
--- a/qemu/qemu-kvm.c
+++ b/qemu/qemu-kvm.c
@@ -783,7 +783,7 @@ void kvm_cpu_register_physical_memory(target_phys_addr_t start_addr,
r = kvm_is_intersecting_mem(kvm_context, start_addr);
if (r)
kvm_create_mem_hole(kvm_context, start_addr, size);
- r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
+ r = kvm_register_phys_mem(kvm_context, start_addr,
phys_ram_base + phys_offset,
size, 0);
}
@@ -792,7 +792,7 @@ void kvm_cpu_register_physical_memory(target_phys_addr_t start_addr,
r = kvm_is_intersecting_mem(kvm_context, start_addr);
if (r)
kvm_create_mem_hole(kvm_context, start_addr, size);
- r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
+ r = kvm_register_phys_mem(kvm_context, start_addr,
phys_ram_base + phys_offset,
size, 0);
}
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH] remove kernel memory code from hw/pc.c
2008-09-08 19:30 ` [PATCH] rename kvm_register_userspace_phys_mem Glauber Costa
@ 2008-09-08 19:30 ` Glauber Costa
2008-09-08 19:30 ` [PATCH] remove kernel memory allocation code from ipf.c Glauber Costa
0 siblings, 1 reply; 33+ messages in thread
From: Glauber Costa @ 2008-09-08 19:30 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
qemu/hw/pc.c | 19 ++-----------------
1 files changed, 2 insertions(+), 17 deletions(-)
diff --git a/qemu/hw/pc.c b/qemu/hw/pc.c
index 026e96d..8a50096 100644
--- a/qemu/hw/pc.c
+++ b/qemu/hw/pc.c
@@ -842,8 +842,7 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size,
vmport_init();
/* allocate RAM */
-#ifdef KVM_CAP_USER_MEMORY
- if (kvm_enabled() && kvm_qemu_check_extension(KVM_CAP_USER_MEMORY)) {
+ if (kvm_enabled()) {
ram_addr = qemu_ram_alloc(0xa0000);
cpu_register_physical_memory(0, 0xa0000, ram_addr);
kvm_cpu_register_physical_memory(0, 0xa0000, ram_addr);
@@ -876,7 +875,6 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size,
ram_addr);
}
} else
-#endif
{
ram_addr = qemu_ram_alloc(ram_size);
cpu_register_physical_memory(0, below_4g_mem_size, ram_addr);
@@ -965,21 +963,8 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size,
cpu_register_physical_memory((uint32_t)(-bios_size),
bios_size, bios_offset | IO_MEM_ROM);
if (kvm_enabled()) {
- int r;
-#ifdef KVM_CAP_USER_MEMORY
- r = kvm_qemu_check_extension(KVM_CAP_USER_MEMORY);
- if (r)
- kvm_cpu_register_physical_memory((uint32_t)(-bios_size),
+ kvm_cpu_register_physical_memory((uint32_t)(-bios_size),
bios_size, bios_offset | IO_MEM_ROM);
- else
-#endif
- {
- bios_mem = kvm_cpu_create_phys_mem((uint32_t)(-bios_size),
- bios_size, 0, 1);
- if (!bios_mem)
- exit(1);
- memcpy(bios_mem, phys_ram_base + bios_offset, bios_size);
- }
}
bochs_bios_init();
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH] remove kernel memory allocation code from ipf.c
2008-09-08 19:30 ` [PATCH] remove kernel memory code from hw/pc.c Glauber Costa
@ 2008-09-08 19:30 ` Glauber Costa
0 siblings, 0 replies; 33+ messages in thread
From: Glauber Costa @ 2008-09-08 19:30 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
qemu/hw/ipf.c | 25 +++++--------------------
1 files changed, 5 insertions(+), 20 deletions(-)
diff --git a/qemu/hw/ipf.c b/qemu/hw/ipf.c
index 2f7054c..d979d4d 100644
--- a/qemu/hw/ipf.c
+++ b/qemu/hw/ipf.c
@@ -417,8 +417,7 @@ static void ipf_init1(ram_addr_t ram_size, int vga_ram_size,
}
/* allocate RAM */
-#ifdef KVM_CAP_USER_MEMORY
- if (kvm_enabled() && kvm_qemu_check_extension(KVM_CAP_USER_MEMORY)) {
+ if (kvm_enabled()) {
ram_addr = qemu_ram_alloc(0xa0000);
cpu_register_physical_memory(0, 0xa0000, ram_addr);
kvm_cpu_register_physical_memory(0, 0xa0000, ram_addr);
@@ -434,7 +433,6 @@ static void ipf_init1(ram_addr_t ram_size, int vga_ram_size,
kvm_cpu_register_physical_memory(0x100000, ram_size - 0x100000,
ram_addr);
} else
-#endif
{
ram_addr = qemu_ram_alloc(ram_size);
cpu_register_physical_memory(0, ram_size, ram_addr);
@@ -469,23 +467,10 @@ static void ipf_init1(ram_addr_t ram_size, int vga_ram_size,
}
fw_image_start = fw_start + GFW_SIZE - image_size;
-#ifdef KVM_CAP_USER_MEMORY
- r = kvm_qemu_check_extension(KVM_CAP_USER_MEMORY);
- if (r) {
- cpu_register_physical_memory(GFW_START, GFW_SIZE, fw_offset);
- kvm_cpu_register_physical_memory(GFW_START,GFW_SIZE, fw_offset);
- memcpy(fw_image_start, image, image_size);
- }
- else
-#endif
- {
- fw_start = kvm_create_phys_mem(kvm_context, (uint32_t)(-image_size),
- image_size, 0, 1);
- if (!fw_start)
- exit(1);
- fw_image_start = fw_start + GFW_SIZE - image_size;
- memcpy(fw_image_start, image, image_size);
- }
+ cpu_register_physical_memory(GFW_START, GFW_SIZE, fw_offset);
+ kvm_cpu_register_physical_memory(GFW_START,GFW_SIZE, fw_offset);
+ memcpy(fw_image_start, image, image_size);
+
free(image);
flush_icache_range((unsigned long)fw_image_start,
(unsigned long)fw_image_start + image_size);
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* Re: [PATCH 0/12] Get rid of kernel memory allocation
2008-09-08 19:30 [PATCH 0/12] Get rid of kernel memory allocation Glauber Costa
2008-09-08 19:30 ` [PATCH] start removing kernel memory functions Glauber Costa
@ 2008-09-09 14:25 ` Avi Kivity
2008-09-09 14:57 ` Glauber Costa
2008-09-10 19:20 ` [PATCH 0/12] get rid of kernel memory registration Glauber Costa
` (12 subsequent siblings)
14 siblings, 1 reply; 33+ messages in thread
From: Avi Kivity @ 2008-09-09 14:25 UTC (permalink / raw)
To: Glauber Costa; +Cc: kvm, aliguori
Glauber Costa wrote:
> Hey guys,
>
> Some eons before the dinosaurs went extinct, we used to support
> a method of memory allocation different than the one advertised by
> KVM_CAP_USER_MEMORY.
>
> This series of patches attempt on removing the support for it in kvm-userspace
> entirely. It will make the job of integrating kvm and qemu much easier. As
> a matter of fact, platforms other than x86 (and ia64, because it seems to
> borrow a great deal of code from x86) don't even support that method.
>
> I remind you that for those who still want to run userspaces old enough for Hypervisors
> that lack user memory capability, you always have the option of running an
> old enough userspace, so to match.
>
> This patch series leaves one test for this capability in place, at machine
> initialization: KVM will refuse to run if it's not in there. Later on,
> if we deprecate the capability altogether from the kernel, we may do it through
> an ABI check. But for now, I think this is enough.
>
> series stat:
>
Looks good. Two comments that are simultaneously critical and minor:
- use git send-email -n to number patches so I they are lexically sorted
for git am (oh and --no-chain-reply-to also helps)
- qemu code is formatted with 4-space indents, no tabs. your patches
seem to have 4-position tabs (which could only have been created by the
recently-opened LHC, as they don't occur naturally). please talk to
your editor.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH 0/12] Get rid of kernel memory allocation
2008-09-09 14:25 ` [PATCH 0/12] Get rid of kernel memory allocation Avi Kivity
@ 2008-09-09 14:57 ` Glauber Costa
2008-09-09 15:01 ` Avi Kivity
0 siblings, 1 reply; 33+ messages in thread
From: Glauber Costa @ 2008-09-09 14:57 UTC (permalink / raw)
To: Avi Kivity; +Cc: Glauber Costa, kvm, aliguori
On Tue, Sep 09, 2008 at 05:25:09PM +0300, Avi Kivity wrote:
> Glauber Costa wrote:
>> Hey guys,
>>
>> Some eons before the dinosaurs went extinct, we used to support
>> a method of memory allocation different than the one advertised by
>> KVM_CAP_USER_MEMORY.
>>
>> This series of patches attempt on removing the support for it in kvm-userspace
>> entirely. It will make the job of integrating kvm and qemu much easier. As
>> a matter of fact, platforms other than x86 (and ia64, because it seems to
>> borrow a great deal of code from x86) don't even support that method.
>>
>> I remind you that for those who still want to run userspaces old enough for Hypervisors
>> that lack user memory capability, you always have the option of running an
>> old enough userspace, so to match.
>>
>> This patch series leaves one test for this capability in place, at machine
>> initialization: KVM will refuse to run if it's not in there. Later on,
>> if we deprecate the capability altogether from the kernel, we may do it through
>> an ABI check. But for now, I think this is enough.
>>
>> series stat:
>>
>
> Looks good. Two comments that are simultaneously critical and minor:
>
> - use git send-email -n to number patches so I they are lexically sorted
> for git am (oh and --no-chain-reply-to also helps)
gee. I use this regularly, but this time I forgot ;-(
Sorry master.
> - qemu code is formatted with 4-space indents, no tabs. your patches
> seem to have 4-position tabs (which could only have been created by the
> recently-opened LHC, as they don't occur naturally). please talk to
> your editor.
Part of them. Of course one of them might have been a screw up, but mostly,
I'm using 4 spaces for code under qemu/, and tabs for code in libkvm, which seems
to be the standard. Should I use spaces for libkvm too?
>
> --
> error compiling committee.c: too many arguments to function
>
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH 0/12] Get rid of kernel memory allocation
2008-09-09 14:57 ` Glauber Costa
@ 2008-09-09 15:01 ` Avi Kivity
0 siblings, 0 replies; 33+ messages in thread
From: Avi Kivity @ 2008-09-09 15:01 UTC (permalink / raw)
To: Glauber Costa; +Cc: Glauber Costa, kvm, aliguori
Glauber Costa wrote:
>> - qemu code is formatted with 4-space indents, no tabs. your patches
>> seem to have 4-position tabs (which could only have been created by the
>> recently-opened LHC, as they don't occur naturally). please talk to
>> your editor.
>>
> Part of them. Of course one of them might have been a screw up, but mostly,
> I'm using 4 spaces for code under qemu/, and tabs for code in libkvm, which seems
> to be the standard. Should I use spaces for libkvm too?
>
No, libkvm uses those tabs. Early design error.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 0/12] get rid of kernel memory registration
2008-09-08 19:30 [PATCH 0/12] Get rid of kernel memory allocation Glauber Costa
2008-09-08 19:30 ` [PATCH] start removing kernel memory functions Glauber Costa
2008-09-09 14:25 ` [PATCH 0/12] Get rid of kernel memory allocation Avi Kivity
@ 2008-09-10 19:20 ` Glauber Costa
2008-09-11 8:59 ` Avi Kivity
2008-09-10 19:20 ` [PATCH 01/12] start removing kernel memory functions Glauber Costa
` (11 subsequent siblings)
14 siblings, 1 reply; 33+ messages in thread
From: Glauber Costa @ 2008-09-10 19:20 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori
Avi,
I hope it is better now.
For libkvm code, I'm still using tabs. For qemu, spaces.
However, I'm not fixing places that were already using it. There are a lot
of patches in flight right now, anthony's integration effort being the most
significant ones, and simple whitespace fixes could break them. We can do
a later pass that removes all the tabs.
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH 01/12] start removing kernel memory functions
2008-09-08 19:30 [PATCH 0/12] Get rid of kernel memory allocation Glauber Costa
` (2 preceding siblings ...)
2008-09-10 19:20 ` [PATCH 0/12] get rid of kernel memory registration Glauber Costa
@ 2008-09-10 19:20 ` Glauber Costa
2008-09-10 19:20 ` [PATCH 02/12] remove tests of user memory from vl.c Glauber Costa
` (10 subsequent siblings)
14 siblings, 0 replies; 33+ messages in thread
From: Glauber Costa @ 2008-09-10 19:20 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
kvm_arch_create_default_phys_mem and kvm_alloc_kernel_memory
are legacy. Remove them, and their callers. The whole removal
will be split for bisectability. These ones goes first because they are
only called at initialization
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
libkvm/kvm-common.h | 3 --
libkvm/libkvm-ia64.c | 25 -------------
libkvm/libkvm-powerpc.c | 14 -------
libkvm/libkvm-s390.c | 14 -------
libkvm/libkvm-x86.c | 91 -----------------------------------------------
libkvm/libkvm.c | 19 +++-------
6 files changed, 5 insertions(+), 161 deletions(-)
diff --git a/libkvm/kvm-common.h b/libkvm/kvm-common.h
index 7092085..93cea1b 100644
--- a/libkvm/kvm-common.h
+++ b/libkvm/kvm-common.h
@@ -78,9 +78,6 @@ void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
void **vm_mem);
-int kvm_arch_create_default_phys_mem(kvm_context_t kvm,
- unsigned long phys_mem_bytes,
- void **vm_mem);
int kvm_arch_run(struct kvm_run *run, kvm_context_t kvm, int vcpu);
diff --git a/libkvm/libkvm-ia64.c b/libkvm/libkvm-ia64.c
index f35a16c..152d8fd 100644
--- a/libkvm/libkvm-ia64.c
+++ b/libkvm/libkvm-ia64.c
@@ -33,31 +33,6 @@
#include <fcntl.h>
#include <stdlib.h>
-int kvm_arch_create_default_phys_mem(kvm_context_t kvm,
- unsigned long phys_mem_bytes,
- void **vm_mem)
-{
- int zfd;
-
- zfd = open("/dev/zero", O_RDONLY);
- if (zfd == -1) {
- perror("open /dev/zero");
- return -1;
- }
- mmap(*vm_mem + 0xa8000, 0x8000, PROT_READ|PROT_WRITE,
- MAP_PRIVATE|MAP_FIXED, zfd, 0);
- close(zfd);
-
- return 0;
-}
-
-
-int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory,
- void **vm_mem)
-{
- return 0;
-}
-
void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
unsigned long len, int log, int writable)
{
diff --git a/libkvm/libkvm-powerpc.c b/libkvm/libkvm-powerpc.c
index 376aca4..c523f26 100644
--- a/libkvm/libkvm-powerpc.c
+++ b/libkvm/libkvm-powerpc.c
@@ -43,13 +43,6 @@ int handle_dcr(struct kvm_run *run, kvm_context_t kvm, int vcpu)
return ret;
}
-int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory,
- void **vm_mem)
-{
- fprintf(stderr, "%s: Operation not supported\n", __FUNCTION__);
- return -1;
-}
-
void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
unsigned long len, int log, int writable)
{
@@ -102,13 +95,6 @@ int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
return 0;
}
-int kvm_arch_create_default_phys_mem(kvm_context_t kvm,
- unsigned long phys_mem_bytes,
- void **vm_mem)
-{
- return 0;
-}
-
int kvm_arch_run(struct kvm_run *run, kvm_context_t kvm, int vcpu)
{
int ret = 0;
diff --git a/libkvm/libkvm-s390.c b/libkvm/libkvm-s390.c
index b3e4e92..59c534f 100644
--- a/libkvm/libkvm-s390.c
+++ b/libkvm/libkvm-s390.c
@@ -22,13 +22,6 @@
#include <stdio.h>
#include <inttypes.h>
-int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory,
- void **vm_mem)
-{
- fprintf(stderr, "%s: Operation not supported\n", __FUNCTION__);
- return -1;
-}
-
void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
unsigned long len, int log, int writable)
{
@@ -87,13 +80,6 @@ int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
return 0;
}
-int kvm_arch_create_default_phys_mem(kvm_context_t kvm,
- unsigned long phys_mem_bytes,
- void **vm_mem)
-{
- return 0;
-}
-
int kvm_arch_run(struct kvm_run *run, kvm_context_t kvm, int vcpu)
{
int ret = 0;
diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c
index ea97bdd..4ca3d7b 100644
--- a/libkvm/libkvm-x86.c
+++ b/libkvm/libkvm-x86.c
@@ -13,79 +13,6 @@
#include <fcntl.h>
#include <stdlib.h>
-int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory,
- void **vm_mem)
-{
- unsigned long dosmem = 0xa0000;
- unsigned long exmem = 0xc0000;
- unsigned long pcimem = 0xe0000000;
- 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 = 0x100000000ULL,
- };
-
-#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,
- low_memory.memory_size, 0, 0, 0);
-
-
- 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,
- extended_memory.memory_size, 0, 0, 0);
- }
-
- 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,
- above_4g_memory.memory_size, 0, 0, 0);
- }
-
- *vm_mem = mmap(NULL, memory, PROT_READ|PROT_WRITE, MAP_SHARED, kvm->vm_fd, 0);
-
- return 0;
-}
-
int kvm_set_tss_addr(kvm_context_t kvm, unsigned long addr)
{
#ifdef KVM_CAP_SET_TSS_ADDR
@@ -126,24 +53,6 @@ static int kvm_init_tss(kvm_context_t kvm)
return 0;
}
-int kvm_arch_create_default_phys_mem(kvm_context_t kvm,
- unsigned long phys_mem_bytes,
- void **vm_mem)
-{
- int zfd;
-
- zfd = open("/dev/zero", O_RDONLY);
- if (zfd == -1) {
- perror("open /dev/zero");
- return -1;
- }
- mmap(*vm_mem + 0xa8000, 0x8000, PROT_READ|PROT_WRITE,
- MAP_PRIVATE|MAP_FIXED, zfd, 0);
- close(zfd);
-
- return 0;
-}
-
int kvm_create_pit(kvm_context_t kvm)
{
#ifdef KVM_CAP_PIT
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
index 029e7b1..bacd29d 100644
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -328,24 +328,15 @@ static 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 r;
-
#ifdef KVM_CAP_USER_MEMORY
- r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY);
+ int r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY);
if (r > 0)
return 0;
- else
+ fprintf(stderr, "Hypervisor too old: KVM_CAP_USER_MEMORY extension not supported\n");
+#else
+#error Hypervisor too old: KVM_CAP_USER_MEMORY extension not supported
#endif
- r = kvm_alloc_kernel_memory(kvm, memory, vm_mem);
- if (r < 0)
- return r;
-
- r = kvm_arch_create_default_phys_mem(kvm, phys_mem_bytes, vm_mem);
- if (r < 0)
- return r;
-
- return 0;
+ return -1;
}
int kvm_check_extension(kvm_context_t kvm, int ext)
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH 02/12] remove tests of user memory from vl.c
2008-09-08 19:30 [PATCH 0/12] Get rid of kernel memory allocation Glauber Costa
` (3 preceding siblings ...)
2008-09-10 19:20 ` [PATCH 01/12] start removing kernel memory functions Glauber Costa
@ 2008-09-10 19:20 ` Glauber Costa
2008-09-10 19:20 ` [PATCH 03/12] coalesce memory allocation Glauber Costa
` (9 subsequent siblings)
14 siblings, 0 replies; 33+ messages in thread
From: Glauber Costa @ 2008-09-10 19:20 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
kvm_qemu_create_context() will fail if we don't have
userspace memory capability, so no need to check it here.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
qemu/vl.c | 19 +++++--------------
1 files changed, 5 insertions(+), 14 deletions(-)
diff --git a/qemu/vl.c b/qemu/vl.c
index b34a114..0484a3b 100644
--- a/qemu/vl.c
+++ b/qemu/vl.c
@@ -9934,20 +9934,11 @@ int main(int argc, char **argv)
fprintf(stderr, "Could not create KVM context\n");
exit(1);
}
-#ifdef KVM_CAP_USER_MEMORY
-{
- int ret;
-
- ret = kvm_qemu_check_extension(KVM_CAP_USER_MEMORY);
- if (ret) {
- phys_ram_base = qemu_alloc_physram(phys_ram_size);
- if (!phys_ram_base) {
- fprintf(stderr, "Could not allocate physical memory\n");
- exit(1);
- }
- }
-}
-#endif
+ phys_ram_base = qemu_alloc_physram(phys_ram_size);
+ if (!phys_ram_base) {
+ fprintf(stderr, "Could not allocate physical memory\n");
+ exit(1);
+ }
} else {
phys_ram_base = qemu_vmalloc(phys_ram_size);
if (!phys_ram_base) {
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH 03/12] coalesce memory allocation
2008-09-08 19:30 [PATCH 0/12] Get rid of kernel memory allocation Glauber Costa
` (4 preceding siblings ...)
2008-09-10 19:20 ` [PATCH 02/12] remove tests of user memory from vl.c Glauber Costa
@ 2008-09-10 19:20 ` Glauber Costa
2008-09-10 19:20 ` [PATCH 04/12] remove KVM_CAP_USER_MEMORY reference from qemu-kvm.c Glauber Costa
` (8 subsequent siblings)
14 siblings, 0 replies; 33+ messages in thread
From: Glauber Costa @ 2008-09-10 19:20 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
Put all memory allocation under qemu_alloc_physram().
Protect the mem_area code with #ifdef USE_KVM. Although it
is not really needed, it help us keep track of the fact that
this is a kvm-only feature to the moment.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
qemu/vl.c | 19 ++++++++-----------
1 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/qemu/vl.c b/qemu/vl.c
index 0484a3b..022b3b8 100644
--- a/qemu/vl.c
+++ b/qemu/vl.c
@@ -9019,8 +9019,10 @@ void *qemu_alloc_physram(unsigned long memory)
void *area = NULL;
unsigned long map_len = memory;
+#ifdef USE_KVM
if (mem_path)
area = alloc_mem_area(memory, &map_len, mem_path);
+#endif
if (!area)
area = qemu_vmalloc(memory);
#ifdef USE_KVM
@@ -9934,17 +9936,12 @@ int main(int argc, char **argv)
fprintf(stderr, "Could not create KVM context\n");
exit(1);
}
- phys_ram_base = qemu_alloc_physram(phys_ram_size);
- if (!phys_ram_base) {
- fprintf(stderr, "Could not allocate physical memory\n");
- exit(1);
- }
- } else {
- phys_ram_base = qemu_vmalloc(phys_ram_size);
- if (!phys_ram_base) {
- fprintf(stderr, "Could not allocate physical memory\n");
- exit(1);
- }
+ }
+
+ phys_ram_base = qemu_alloc_physram(phys_ram_size);
+ if (!phys_ram_base) {
+ fprintf(stderr, "Could not allocate physical memory\n");
+ exit(1);
}
/* init the dynamic translator */
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH 04/12] remove KVM_CAP_USER_MEMORY reference from qemu-kvm.c
2008-09-08 19:30 [PATCH 0/12] Get rid of kernel memory allocation Glauber Costa
` (5 preceding siblings ...)
2008-09-10 19:20 ` [PATCH 03/12] coalesce memory allocation Glauber Costa
@ 2008-09-10 19:20 ` Glauber Costa
2008-09-10 19:20 ` [PATCH 05/12] remove KVM_CAP_USER_MEMORY from libkvm.c Glauber Costa
` (7 subsequent siblings)
14 siblings, 0 replies; 33+ messages in thread
From: Glauber Costa @ 2008-09-10 19:20 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
kvm_cpu_register_physical_memory() is its only user. Remove it.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
qemu/qemu-kvm.c | 52 +++++++++++++++++++++-------------------------------
1 files changed, 21 insertions(+), 31 deletions(-)
diff --git a/qemu/qemu-kvm.c b/qemu/qemu-kvm.c
index 8d366e5..f0ef21e 100644
--- a/qemu/qemu-kvm.c
+++ b/qemu/qemu-kvm.c
@@ -775,42 +775,32 @@ void kvm_cpu_register_physical_memory(target_phys_addr_t start_addr,
unsigned long size,
unsigned long phys_offset)
{
-#ifdef KVM_CAP_USER_MEMORY
int r = 0;
-
- r = kvm_check_extension(kvm_context, KVM_CAP_USER_MEMORY);
- if (r) {
- if (!(phys_offset & ~TARGET_PAGE_MASK)) {
- r = kvm_is_allocated_mem(kvm_context, start_addr, size);
- if (r)
- return;
- r = kvm_is_intersecting_mem(kvm_context, start_addr);
- if (r)
- kvm_create_mem_hole(kvm_context, start_addr, size);
- r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
- phys_ram_base + phys_offset,
- size, 0);
- }
- if (phys_offset & IO_MEM_ROM) {
- phys_offset &= ~IO_MEM_ROM;
- r = kvm_is_intersecting_mem(kvm_context, start_addr);
- if (r)
- kvm_create_mem_hole(kvm_context, start_addr, size);
- r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
- phys_ram_base + phys_offset,
- size, 0);
- }
- if (r < 0) {
- printf("kvm_cpu_register_physical_memory: failed\n");
- exit(1);
- }
- return;
+ if (!(phys_offset & ~TARGET_PAGE_MASK)) {
+ r = kvm_is_allocated_mem(kvm_context, start_addr, size);
+ if (r)
+ return;
+ r = kvm_is_intersecting_mem(kvm_context, start_addr);
+ if (r)
+ kvm_create_mem_hole(kvm_context, start_addr, size);
+ r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
+ phys_ram_base + phys_offset,
+ size, 0);
}
-#endif
if (phys_offset & IO_MEM_ROM) {
phys_offset &= ~IO_MEM_ROM;
- memcpy(phys_ram_base + start_addr, phys_ram_base + phys_offset, size);
+ r = kvm_is_intersecting_mem(kvm_context, start_addr);
+ if (r)
+ kvm_create_mem_hole(kvm_context, start_addr, size);
+ r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
+ phys_ram_base + phys_offset,
+ size, 0);
+ }
+ if (r < 0) {
+ printf("kvm_cpu_register_physical_memory: failed\n");
+ exit(1);
}
+ return;
}
int kvm_setup_guest_memory(void *area, unsigned long size)
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH 05/12] remove KVM_CAP_USER_MEMORY from libkvm.c.
2008-09-08 19:30 [PATCH 0/12] Get rid of kernel memory allocation Glauber Costa
` (6 preceding siblings ...)
2008-09-10 19:20 ` [PATCH 04/12] remove KVM_CAP_USER_MEMORY reference from qemu-kvm.c Glauber Costa
@ 2008-09-10 19:20 ` Glauber Costa
2008-09-10 19:21 ` [PATCH 06/12] remove create_kernel_phys_mem Glauber Costa
` (6 subsequent siblings)
14 siblings, 0 replies; 33+ messages in thread
From: Glauber Costa @ 2008-09-10 19:20 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
One of them is left, which is the initial check.
Code that does ioctl checking is left to be removed
in a future commit.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
libkvm/libkvm.c | 18 ------------------
1 files changed, 0 insertions(+), 18 deletions(-)
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
index bacd29d..cfb1195 100644
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -153,7 +153,6 @@ static int kvm_dirty_pages_log_change(kvm_context_t kvm, unsigned long phys_addr
return 1;
}
flag |= slots[slot].flags;
-#ifdef KVM_CAP_USER_MEMORY
if (slots[slot].user_alloc) {
struct kvm_userspace_memory_region mem = {
.slot = slot,
@@ -164,7 +163,6 @@ static int kvm_dirty_pages_log_change(kvm_context_t kvm, unsigned long phys_addr
};
r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &mem);
}
-#endif
if (!slots[slot].user_alloc) {
struct kvm_memory_region mem = {
.slot = slot,
@@ -388,8 +386,6 @@ int kvm_create(kvm_context_t kvm, unsigned long phys_mem_bytes, void **vm_mem)
}
-#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)
{
@@ -457,20 +453,14 @@ void kvm_destroy_userspace_phys_mem(kvm_context_t kvm,
free_slot(memory.slot);
}
-#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);
}
@@ -496,7 +486,6 @@ int kvm_is_allocated_mem(kvm_context_t kvm, unsigned long phys_start,
int kvm_create_mem_hole(kvm_context_t kvm, unsigned long phys_start,
unsigned long len)
{
-#ifdef KVM_CAP_USER_MEMORY
int slot;
int r;
struct kvm_userspace_memory_region rmslot;
@@ -556,7 +545,6 @@ int kvm_create_mem_hole(kvm_context_t kvm, unsigned long phys_start,
register_slot(newslot2.slot, newslot2.guest_phys_addr,
newslot2.memory_size, 1, newslot2.userspace_addr,
newslot2.flags);
-#endif
return 0;
}
@@ -565,7 +553,6 @@ int kvm_register_userspace_phys_mem(kvm_context_t kvm,
unsigned long len, int log)
{
-#ifdef KVM_CAP_USER_MEMORY
struct kvm_userspace_memory_region memory = {
.memory_size = len,
.guest_phys_addr = phys_start,
@@ -583,9 +570,6 @@ int kvm_register_userspace_phys_mem(kvm_context_t kvm,
register_slot(memory.slot, memory.guest_phys_addr, memory.memory_size,
1, memory.userspace_addr, memory.flags);
return 0;
-#else
- return -ENOSYS;
-#endif
}
@@ -611,11 +595,9 @@ void kvm_destroy_phys_mem(kvm_context_t kvm, unsigned long phys_start,
phys_start = slots[slot].phys_addr;
}
-#ifdef KVM_CAP_USER_MEMORY
if (ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY) > 0)
kvm_destroy_userspace_phys_mem(kvm, phys_start);
else
-#endif
kvm_create_kernel_phys_mem(kvm, phys_start, 0, 0, 0);
}
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH 06/12] remove create_kernel_phys_mem
2008-09-08 19:30 [PATCH 0/12] Get rid of kernel memory allocation Glauber Costa
` (7 preceding siblings ...)
2008-09-10 19:20 ` [PATCH 05/12] remove KVM_CAP_USER_MEMORY from libkvm.c Glauber Costa
@ 2008-09-10 19:21 ` Glauber Costa
2008-09-10 19:21 ` [PATCH 07/12] get rid of kvm_create_userspace_phys_mem Glauber Costa
` (5 subsequent siblings)
14 siblings, 0 replies; 33+ messages in thread
From: Glauber Costa @ 2008-09-10 19:21 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
Wipe out create_kernel_phys_mem(), and all of its users.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
libkvm/kvm-common.h | 3 ---
libkvm/libkvm-ia64.c | 6 ------
libkvm/libkvm-powerpc.c | 7 -------
libkvm/libkvm-s390.c | 7 -------
libkvm/libkvm-x86.c | 33 ---------------------------------
libkvm/libkvm.c | 14 +++-----------
6 files changed, 3 insertions(+), 67 deletions(-)
diff --git a/libkvm/kvm-common.h b/libkvm/kvm-common.h
index 93cea1b..0c04cbc 100644
--- a/libkvm/kvm-common.h
+++ b/libkvm/kvm-common.h
@@ -72,9 +72,6 @@ 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);
-void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
- unsigned long len, int log, int writable);
-
int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
void **vm_mem);
diff --git a/libkvm/libkvm-ia64.c b/libkvm/libkvm-ia64.c
index 152d8fd..f3afc56 100644
--- a/libkvm/libkvm-ia64.c
+++ b/libkvm/libkvm-ia64.c
@@ -33,12 +33,6 @@
#include <fcntl.h>
#include <stdlib.h>
-void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
- unsigned long len, int log, int writable)
-{
- return NULL;
-}
-
int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
void **vm_mem)
{
diff --git a/libkvm/libkvm-powerpc.c b/libkvm/libkvm-powerpc.c
index c523f26..aaebfef 100644
--- a/libkvm/libkvm-powerpc.c
+++ b/libkvm/libkvm-powerpc.c
@@ -43,13 +43,6 @@ int handle_dcr(struct kvm_run *run, kvm_context_t kvm, int vcpu)
return ret;
}
-void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
- unsigned long len, int log, int writable)
-{
- fprintf(stderr, "%s: Operation not supported\n", __FUNCTION__);
- return NULL;
-}
-
void kvm_show_code(kvm_context_t kvm, int vcpu)
{
fprintf(stderr, "%s: Operation not supported\n", __FUNCTION__);
diff --git a/libkvm/libkvm-s390.c b/libkvm/libkvm-s390.c
index 59c534f..041c0ce 100644
--- a/libkvm/libkvm-s390.c
+++ b/libkvm/libkvm-s390.c
@@ -22,13 +22,6 @@
#include <stdio.h>
#include <inttypes.h>
-void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start,
- unsigned long len, int log, int writable)
-{
- fprintf(stderr, "%s: Operation not supported\n", __FUNCTION__);
- return NULL;
-}
-
void kvm_show_code(kvm_context_t kvm, int vcpu)
{
fprintf(stderr, "%s: Operation not supported\n", __FUNCTION__);
diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c
index 4ca3d7b..a8cca15 100644
--- a/libkvm/libkvm-x86.c
+++ b/libkvm/libkvm-x86.c
@@ -145,39 +145,6 @@ int kvm_arch_run(struct kvm_run *run,kvm_context_t kvm, int vcpu)
return r;
}
-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, memory.memory_size,
- 0, 0, memory.flags);
-
- 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;
-}
-
#define MAX_ALIAS_SLOTS 4
static struct {
uint64_t start;
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
index cfb1195..5b48240 100644
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -456,13 +456,8 @@ void kvm_destroy_userspace_phys_mem(kvm_context_t kvm,
void *kvm_create_phys_mem(kvm_context_t kvm, unsigned long phys_start,
unsigned long len, int log, int writable)
{
- 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
- return kvm_create_kernel_phys_mem(kvm, phys_start, len,
- log, writable);
+ return kvm_create_userspace_phys_mem(kvm, phys_start, len,
+ log, writable);
}
int kvm_is_intersecting_mem(kvm_context_t kvm, unsigned long phys_start)
@@ -595,10 +590,7 @@ void kvm_destroy_phys_mem(kvm_context_t kvm, unsigned long phys_start,
phys_start = slots[slot].phys_addr;
}
- if (ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY) > 0)
- kvm_destroy_userspace_phys_mem(kvm, phys_start);
- else
- kvm_create_kernel_phys_mem(kvm, phys_start, 0, 0, 0);
+ kvm_destroy_userspace_phys_mem(kvm, phys_start);
}
static int kvm_get_map(kvm_context_t kvm, int ioctl_num, int slot, void *buf)
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH 07/12] get rid of kvm_create_userspace_phys_mem
2008-09-08 19:30 [PATCH 0/12] Get rid of kernel memory allocation Glauber Costa
` (8 preceding siblings ...)
2008-09-10 19:21 ` [PATCH 06/12] remove create_kernel_phys_mem Glauber Costa
@ 2008-09-10 19:21 ` Glauber Costa
2008-09-10 19:21 ` [PATCH 08/12] remove user_alloc field from slot representation Glauber Costa
` (4 subsequent siblings)
14 siblings, 0 replies; 33+ messages in thread
From: Glauber Costa @ 2008-09-10 19:21 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
It is just kvm_create_phys_mem() right now.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
libkvm/libkvm.c | 15 ++++-----------
1 files changed, 4 insertions(+), 11 deletions(-)
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
index 5b48240..5d42b43 100644
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -386,8 +386,8 @@ int kvm_create(kvm_context_t kvm, unsigned long phys_mem_bytes, void **vm_mem)
}
-void *kvm_create_userspace_phys_mem(kvm_context_t kvm, unsigned long phys_start,
- unsigned long len, int log, int writable)
+void *kvm_create_phys_mem(kvm_context_t kvm, unsigned long phys_start,
+ unsigned long len, int log, int writable)
{
int r;
int prot = PROT_READ;
@@ -408,7 +408,7 @@ void *kvm_create_userspace_phys_mem(kvm_context_t kvm, unsigned long phys_start,
MAP_FIXED | MAP_SHARED | MAP_ANONYMOUS, -1, 0);
#endif
if (ptr == MAP_FAILED) {
- fprintf(stderr, "create_userspace_phys_mem: %s", strerror(errno));
+ fprintf(stderr, "%s: %s", __func__, strerror(errno));
return 0;
}
@@ -418,7 +418,7 @@ void *kvm_create_userspace_phys_mem(kvm_context_t kvm, unsigned long phys_start,
memory.slot = get_free_slot(kvm);
r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &memory);
if (r == -1) {
- fprintf(stderr, "create_userspace_phys_mem: %s", strerror(errno));
+ fprintf(stderr, "%s: %s", __func__, strerror(errno));
return 0;
}
register_slot(memory.slot, memory.guest_phys_addr, memory.memory_size,
@@ -453,13 +453,6 @@ void kvm_destroy_userspace_phys_mem(kvm_context_t kvm,
free_slot(memory.slot);
}
-void *kvm_create_phys_mem(kvm_context_t kvm, unsigned long phys_start,
- unsigned long len, int log, int writable)
-{
- return kvm_create_userspace_phys_mem(kvm, phys_start, len,
- log, writable);
-}
-
int kvm_is_intersecting_mem(kvm_context_t kvm, unsigned long phys_start)
{
return get_intersecting_slot(phys_start) != -1;
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH 08/12] remove user_alloc field from slot representation
2008-09-08 19:30 [PATCH 0/12] Get rid of kernel memory allocation Glauber Costa
` (9 preceding siblings ...)
2008-09-10 19:21 ` [PATCH 07/12] get rid of kvm_create_userspace_phys_mem Glauber Costa
@ 2008-09-10 19:21 ` Glauber Costa
2008-09-10 19:21 ` [PATCH 09/12] merge destroy phys mem functions Glauber Costa
` (3 subsequent siblings)
14 siblings, 0 replies; 33+ messages in thread
From: Glauber Costa @ 2008-09-10 19:21 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
All allocations are "user" now. So we don't need this field
anymore.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
libkvm/kvm-common.h | 2 +-
libkvm/libkvm.c | 39 +++++++++++++++------------------------
2 files changed, 16 insertions(+), 25 deletions(-)
diff --git a/libkvm/kvm-common.h b/libkvm/kvm-common.h
index 0c04cbc..d22556b 100644
--- a/libkvm/kvm-common.h
+++ b/libkvm/kvm-common.h
@@ -63,7 +63,7 @@ struct kvm_context {
void init_slots(void);
int get_free_slot(kvm_context_t kvm);
void register_slot(int slot, unsigned long phys_addr, unsigned long len,
- int user_alloc, unsigned long userspace_addr, unsigned flags);
+ unsigned long userspace_addr, unsigned flags);
void free_slot(int slot);
int get_slot(unsigned long phys_addr);
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
index 5d42b43..560b1bd 100644
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -58,7 +58,6 @@ int kvm_page_size;
struct slot_info {
unsigned long phys_addr;
unsigned long len;
- int user_alloc;
unsigned long userspace_addr;
unsigned flags;
};
@@ -101,11 +100,10 @@ int get_free_slot(kvm_context_t kvm)
}
void register_slot(int slot, unsigned long phys_addr, unsigned long len,
- int user_alloc, unsigned long userspace_addr, unsigned flags)
+ unsigned long userspace_addr, unsigned flags)
{
slots[slot].phys_addr = phys_addr;
slots[slot].len = len;
- slots[slot].user_alloc = user_alloc;
slots[slot].userspace_addr = userspace_addr;
slots[slot].flags = flags;
}
@@ -144,36 +142,29 @@ int get_intersecting_slot(unsigned long phys_addr)
static int kvm_dirty_pages_log_change(kvm_context_t kvm, unsigned long phys_addr
, __u32 flag)
{
- int r;
- int slot;
-
- slot = get_slot(phys_addr);
+ int r = -1;
+ int slot = get_slot(phys_addr);
if (slot == -1) {
fprintf(stderr, "BUG: %s: invalid parameters\n", __FUNCTION__);
return 1;
}
+
flag |= slots[slot].flags;
- if (slots[slot].user_alloc) {
+
+ {
struct kvm_userspace_memory_region mem = {
- .slot = slot,
.memory_size = slots[slot].len,
.guest_phys_addr = slots[slot].phys_addr,
.userspace_addr = slots[slot].userspace_addr,
.flags = flag,
};
+
+
+
r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &mem);
+ if (r == -1)
+ fprintf(stderr, "%s: %m\n", __FUNCTION__);
}
- if (!slots[slot].user_alloc) {
- struct kvm_memory_region mem = {
- .slot = slot,
- .memory_size = slots[slot].len,
- .guest_phys_addr = slots[slot].phys_addr,
- .flags = flag,
- };
- r = ioctl(kvm->vm_fd, KVM_SET_MEMORY_REGION, &mem);
- }
- if (r == -1)
- fprintf(stderr, "%s: %m\n", __FUNCTION__);
return r;
}
@@ -422,7 +413,7 @@ void *kvm_create_phys_mem(kvm_context_t kvm, unsigned long phys_start,
return 0;
}
register_slot(memory.slot, memory.guest_phys_addr, memory.memory_size,
- 1, memory.userspace_addr, memory.flags);
+ memory.userspace_addr, memory.flags);
return ptr;
}
@@ -522,7 +513,7 @@ int kvm_create_mem_hole(kvm_context_t kvm, unsigned long phys_start,
return -1;
}
register_slot(newslot1.slot, newslot1.guest_phys_addr,
- newslot1.memory_size, 1, newslot1.userspace_addr,
+ newslot1.memory_size, newslot1.userspace_addr,
newslot1.flags);
r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &newslot2);
@@ -531,7 +522,7 @@ int kvm_create_mem_hole(kvm_context_t kvm, unsigned long phys_start,
return -1;
}
register_slot(newslot2.slot, newslot2.guest_phys_addr,
- newslot2.memory_size, 1, newslot2.userspace_addr,
+ newslot2.memory_size, newslot2.userspace_addr,
newslot2.flags);
return 0;
}
@@ -556,7 +547,7 @@ int kvm_register_userspace_phys_mem(kvm_context_t kvm,
return -1;
}
register_slot(memory.slot, memory.guest_phys_addr, memory.memory_size,
- 1, memory.userspace_addr, memory.flags);
+ memory.userspace_addr, memory.flags);
return 0;
}
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH 09/12] merge destroy phys mem functions
2008-09-08 19:30 [PATCH 0/12] Get rid of kernel memory allocation Glauber Costa
` (10 preceding siblings ...)
2008-09-10 19:21 ` [PATCH 08/12] remove user_alloc field from slot representation Glauber Costa
@ 2008-09-10 19:21 ` Glauber Costa
2008-09-10 19:21 ` [PATCH 10/12] rename kvm_register_userspace_phys_mem Glauber Costa
` (2 subsequent siblings)
14 siblings, 0 replies; 33+ messages in thread
From: Glauber Costa @ 2008-09-10 19:21 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
kvm_destroy_userspace_phys_mem() and kvm_destroy_phys_mem()
can be merged into a single function, now that kernel allocation
is no more.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
libkvm/libkvm.c | 45 +++++++++++++++++----------------------------
1 files changed, 17 insertions(+), 28 deletions(-)
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
index 560b1bd..32481e5 100644
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -418,32 +418,6 @@ void *kvm_create_phys_mem(kvm_context_t kvm, unsigned long phys_start,
return ptr;
}
-void kvm_destroy_userspace_phys_mem(kvm_context_t kvm,
- unsigned long phys_start)
-{
- int r;
- struct kvm_userspace_memory_region memory = {
- .memory_size = 0,
- .guest_phys_addr = phys_start,
- .flags = 0,
- };
-
- memory.userspace_addr = 0;
- memory.slot = get_slot(phys_start);
-
- if (memory.slot == -1)
- return;
-
- r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &memory);
- if (r == -1) {
- fprintf(stderr, "destroy_userspace_phys_mem: %s",
- strerror(errno));
- return;
- }
-
- free_slot(memory.slot);
-}
-
int kvm_is_intersecting_mem(kvm_context_t kvm, unsigned long phys_start)
{
return get_intersecting_slot(phys_start) != -1;
@@ -559,10 +533,17 @@ void kvm_destroy_phys_mem(kvm_context_t kvm, unsigned long phys_start,
unsigned long len)
{
int slot;
+ int r;
+ struct kvm_userspace_memory_region memory = {
+ .memory_size = 0,
+ .guest_phys_addr = phys_start,
+ .userspace_addr = 0,
+ .flags = 0,
+ };
slot = get_slot(phys_start);
- if (slot >= KVM_MAX_NUM_MEM_REGIONS) {
+ if ((slot >= KVM_MAX_NUM_MEM_REGIONS) || (slot == -1)) {
fprintf(stderr, "BUG: %s: invalid parameters (slot=%d)\n",
__FUNCTION__, slot);
return;
@@ -574,7 +555,15 @@ void kvm_destroy_phys_mem(kvm_context_t kvm, unsigned long phys_start,
phys_start = slots[slot].phys_addr;
}
- kvm_destroy_userspace_phys_mem(kvm, phys_start);
+ memory.slot = slot;
+ r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &memory);
+ if (r == -1) {
+ fprintf(stderr, "destroy_userspace_phys_mem: %s",
+ strerror(errno));
+ return;
+ }
+
+ free_slot(memory.slot);
}
static int kvm_get_map(kvm_context_t kvm, int ioctl_num, int slot, void *buf)
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH 10/12] rename kvm_register_userspace_phys_mem
2008-09-08 19:30 [PATCH 0/12] Get rid of kernel memory allocation Glauber Costa
` (11 preceding siblings ...)
2008-09-10 19:21 ` [PATCH 09/12] merge destroy phys mem functions Glauber Costa
@ 2008-09-10 19:21 ` Glauber Costa
2008-09-10 19:21 ` [PATCH 11/12] remove kernel memory code from hw/pc.c Glauber Costa
2008-09-10 19:21 ` [PATCH 12/12] remove kernel memory allocation code from ipf.c Glauber Costa
14 siblings, 0 replies; 33+ messages in thread
From: Glauber Costa @ 2008-09-10 19:21 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
Change its name to kvm_register_phys_mem().
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
libkvm/libkvm.c | 2 +-
libkvm/libkvm.h | 2 +-
qemu/qemu-kvm.c | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
index 32481e5..f5df5c3 100644
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -501,7 +501,7 @@ int kvm_create_mem_hole(kvm_context_t kvm, unsigned long phys_start,
return 0;
}
-int kvm_register_userspace_phys_mem(kvm_context_t kvm,
+int kvm_register_phys_mem(kvm_context_t kvm,
unsigned long phys_start, void *userspace_addr,
unsigned long len, int log)
{
diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h
index 346eedf..79dd769 100644
--- a/libkvm/libkvm.h
+++ b/libkvm/libkvm.h
@@ -459,7 +459,7 @@ int kvm_is_allocated_mem(kvm_context_t kvm, unsigned long phys_start,
unsigned long len);
int kvm_create_mem_hole(kvm_context_t kvm, unsigned long phys_start,
unsigned long len);
-int kvm_register_userspace_phys_mem(kvm_context_t kvm,
+int kvm_register_phys_mem(kvm_context_t kvm,
unsigned long phys_start, void *userspace_addr,
unsigned long len, int log);
int kvm_get_dirty_pages(kvm_context_t, unsigned long phys_addr, void *buf);
diff --git a/qemu/qemu-kvm.c b/qemu/qemu-kvm.c
index f0ef21e..c522a28 100644
--- a/qemu/qemu-kvm.c
+++ b/qemu/qemu-kvm.c
@@ -783,7 +783,7 @@ void kvm_cpu_register_physical_memory(target_phys_addr_t start_addr,
r = kvm_is_intersecting_mem(kvm_context, start_addr);
if (r)
kvm_create_mem_hole(kvm_context, start_addr, size);
- r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
+ r = kvm_register_phys_mem(kvm_context, start_addr,
phys_ram_base + phys_offset,
size, 0);
}
@@ -792,7 +792,7 @@ void kvm_cpu_register_physical_memory(target_phys_addr_t start_addr,
r = kvm_is_intersecting_mem(kvm_context, start_addr);
if (r)
kvm_create_mem_hole(kvm_context, start_addr, size);
- r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
+ r = kvm_register_phys_mem(kvm_context, start_addr,
phys_ram_base + phys_offset,
size, 0);
}
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH 11/12] remove kernel memory code from hw/pc.c
2008-09-08 19:30 [PATCH 0/12] Get rid of kernel memory allocation Glauber Costa
` (12 preceding siblings ...)
2008-09-10 19:21 ` [PATCH 10/12] rename kvm_register_userspace_phys_mem Glauber Costa
@ 2008-09-10 19:21 ` Glauber Costa
2008-09-10 19:21 ` [PATCH 12/12] remove kernel memory allocation code from ipf.c Glauber Costa
14 siblings, 0 replies; 33+ messages in thread
From: Glauber Costa @ 2008-09-10 19:21 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
qemu/hw/pc.c | 19 ++-----------------
1 files changed, 2 insertions(+), 17 deletions(-)
diff --git a/qemu/hw/pc.c b/qemu/hw/pc.c
index 026e96d..8a50096 100644
--- a/qemu/hw/pc.c
+++ b/qemu/hw/pc.c
@@ -842,8 +842,7 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size,
vmport_init();
/* allocate RAM */
-#ifdef KVM_CAP_USER_MEMORY
- if (kvm_enabled() && kvm_qemu_check_extension(KVM_CAP_USER_MEMORY)) {
+ if (kvm_enabled()) {
ram_addr = qemu_ram_alloc(0xa0000);
cpu_register_physical_memory(0, 0xa0000, ram_addr);
kvm_cpu_register_physical_memory(0, 0xa0000, ram_addr);
@@ -876,7 +875,6 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size,
ram_addr);
}
} else
-#endif
{
ram_addr = qemu_ram_alloc(ram_size);
cpu_register_physical_memory(0, below_4g_mem_size, ram_addr);
@@ -965,21 +963,8 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size,
cpu_register_physical_memory((uint32_t)(-bios_size),
bios_size, bios_offset | IO_MEM_ROM);
if (kvm_enabled()) {
- int r;
-#ifdef KVM_CAP_USER_MEMORY
- r = kvm_qemu_check_extension(KVM_CAP_USER_MEMORY);
- if (r)
- kvm_cpu_register_physical_memory((uint32_t)(-bios_size),
+ kvm_cpu_register_physical_memory((uint32_t)(-bios_size),
bios_size, bios_offset | IO_MEM_ROM);
- else
-#endif
- {
- bios_mem = kvm_cpu_create_phys_mem((uint32_t)(-bios_size),
- bios_size, 0, 1);
- if (!bios_mem)
- exit(1);
- memcpy(bios_mem, phys_ram_base + bios_offset, bios_size);
- }
}
bochs_bios_init();
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH 12/12] remove kernel memory allocation code from ipf.c
2008-09-08 19:30 [PATCH 0/12] Get rid of kernel memory allocation Glauber Costa
` (13 preceding siblings ...)
2008-09-10 19:21 ` [PATCH 11/12] remove kernel memory code from hw/pc.c Glauber Costa
@ 2008-09-10 19:21 ` Glauber Costa
14 siblings, 0 replies; 33+ messages in thread
From: Glauber Costa @ 2008-09-10 19:21 UTC (permalink / raw)
To: kvm; +Cc: avi, aliguori, Glauber Costa
From: Glauber Costa <glommer@redhat.com>
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
qemu/hw/ipf.c | 27 ++++++---------------------
1 files changed, 6 insertions(+), 21 deletions(-)
diff --git a/qemu/hw/ipf.c b/qemu/hw/ipf.c
index 2f7054c..d70af90 100644
--- a/qemu/hw/ipf.c
+++ b/qemu/hw/ipf.c
@@ -416,9 +416,8 @@ static void ipf_init1(ram_addr_t ram_size, int vga_ram_size,
qemu_register_reset(main_cpu_reset, env);
}
- /* allocate RAM */
-#ifdef KVM_CAP_USER_MEMORY
- if (kvm_enabled() && kvm_qemu_check_extension(KVM_CAP_USER_MEMORY)) {
+ /* allocate RAM */
+ if (kvm_enabled()) {
ram_addr = qemu_ram_alloc(0xa0000);
cpu_register_physical_memory(0, 0xa0000, ram_addr);
kvm_cpu_register_physical_memory(0, 0xa0000, ram_addr);
@@ -434,7 +433,6 @@ static void ipf_init1(ram_addr_t ram_size, int vga_ram_size,
kvm_cpu_register_physical_memory(0x100000, ram_size - 0x100000,
ram_addr);
} else
-#endif
{
ram_addr = qemu_ram_alloc(ram_size);
cpu_register_physical_memory(0, ram_size, ram_addr);
@@ -469,23 +467,10 @@ static void ipf_init1(ram_addr_t ram_size, int vga_ram_size,
}
fw_image_start = fw_start + GFW_SIZE - image_size;
-#ifdef KVM_CAP_USER_MEMORY
- r = kvm_qemu_check_extension(KVM_CAP_USER_MEMORY);
- if (r) {
- cpu_register_physical_memory(GFW_START, GFW_SIZE, fw_offset);
- kvm_cpu_register_physical_memory(GFW_START,GFW_SIZE, fw_offset);
- memcpy(fw_image_start, image, image_size);
- }
- else
-#endif
- {
- fw_start = kvm_create_phys_mem(kvm_context, (uint32_t)(-image_size),
- image_size, 0, 1);
- if (!fw_start)
- exit(1);
- fw_image_start = fw_start + GFW_SIZE - image_size;
- memcpy(fw_image_start, image, image_size);
- }
+ cpu_register_physical_memory(GFW_START, GFW_SIZE, fw_offset);
+ kvm_cpu_register_physical_memory(GFW_START,GFW_SIZE, fw_offset);
+ memcpy(fw_image_start, image, image_size);
+
free(image);
flush_icache_range((unsigned long)fw_image_start,
(unsigned long)fw_image_start + image_size);
--
1.5.5.1
^ permalink raw reply related [flat|nested] 33+ messages in thread
* Re: [PATCH] remove KVM_CAP_USER_MEMORY reference from qemu-kvm.c
2008-09-08 19:30 ` [PATCH] remove KVM_CAP_USER_MEMORY reference from qemu-kvm.c Glauber Costa
2008-09-08 19:30 ` [PATCH] remove KVM_CAP_USER_MEMORY from libkvm.c Glauber Costa
@ 2008-09-10 19:23 ` Jan Kiszka
2008-09-10 19:37 ` Glauber Costa
1 sibling, 1 reply; 33+ messages in thread
From: Jan Kiszka @ 2008-09-10 19:23 UTC (permalink / raw)
To: Glauber Costa; +Cc: kvm, avi, aliguori, Glauber Costa
[-- Attachment #1: Type: text/plain, Size: 3414 bytes --]
Glauber Costa wrote:
> From: Glauber Costa <glommer@redhat.com>
>
> kvm_cpu_register_physical_memory() is its only user. Remove it.
>
> Signed-off-by: Glauber Costa <glommer@redhat.com>
> ---
> qemu/qemu-kvm.c | 52 +++++++++++++++++++++-------------------------------
> 1 files changed, 21 insertions(+), 31 deletions(-)
>
> diff --git a/qemu/qemu-kvm.c b/qemu/qemu-kvm.c
> index 8d366e5..f0ef21e 100644
> --- a/qemu/qemu-kvm.c
> +++ b/qemu/qemu-kvm.c
> @@ -775,42 +775,32 @@ void kvm_cpu_register_physical_memory(target_phys_addr_t start_addr,
> unsigned long size,
> unsigned long phys_offset)
> {
> -#ifdef KVM_CAP_USER_MEMORY
> int r = 0;
> -
> - r = kvm_check_extension(kvm_context, KVM_CAP_USER_MEMORY);
> - if (r) {
> - if (!(phys_offset & ~TARGET_PAGE_MASK)) {
> - r = kvm_is_allocated_mem(kvm_context, start_addr, size);
> - if (r)
> - return;
> - r = kvm_is_intersecting_mem(kvm_context, start_addr);
> - if (r)
> - kvm_create_mem_hole(kvm_context, start_addr, size);
> - r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
> - phys_ram_base + phys_offset,
> - size, 0);
> - }
> - if (phys_offset & IO_MEM_ROM) {
> - phys_offset &= ~IO_MEM_ROM;
> - r = kvm_is_intersecting_mem(kvm_context, start_addr);
> - if (r)
> - kvm_create_mem_hole(kvm_context, start_addr, size);
> - r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
> - phys_ram_base + phys_offset,
> - size, 0);
> - }
> - if (r < 0) {
> - printf("kvm_cpu_register_physical_memory: failed\n");
> - exit(1);
> - }
> - return;
> + if (!(phys_offset & ~TARGET_PAGE_MASK)) {
> + r = kvm_is_allocated_mem(kvm_context, start_addr, size);
> + if (r)
> + return;
> + r = kvm_is_intersecting_mem(kvm_context, start_addr);
> + if (r)
> + kvm_create_mem_hole(kvm_context, start_addr, size);
> + r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
> + phys_ram_base + phys_offset,
> + size, 0);
> }
> -#endif
> if (phys_offset & IO_MEM_ROM) {
At this chance: Shouldn't this become 'else if'?
> phys_offset &= ~IO_MEM_ROM;
> - memcpy(phys_ram_base + start_addr, phys_ram_base + phys_offset, size);
> + r = kvm_is_intersecting_mem(kvm_context, start_addr);
> + if (r)
> + kvm_create_mem_hole(kvm_context, start_addr, size);
> + r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
> + phys_ram_base + phys_offset,
> + size, 0);
> + }
> + if (r < 0) {
> + printf("kvm_cpu_register_physical_memory: failed\n");
> + exit(1);
> }
> + return;
> }
>
> int kvm_setup_guest_memory(void *area, unsigned long size)
Jan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 257 bytes --]
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH] remove KVM_CAP_USER_MEMORY reference from qemu-kvm.c
2008-09-10 19:23 ` [PATCH] remove KVM_CAP_USER_MEMORY reference from qemu-kvm.c Jan Kiszka
@ 2008-09-10 19:37 ` Glauber Costa
2008-09-10 19:59 ` Jan Kiszka
0 siblings, 1 reply; 33+ messages in thread
From: Glauber Costa @ 2008-09-10 19:37 UTC (permalink / raw)
To: Jan Kiszka; +Cc: Glauber Costa, kvm, avi, aliguori
On Wed, Sep 10, 2008 at 09:23:18PM +0200, Jan Kiszka wrote:
> Glauber Costa wrote:
> > From: Glauber Costa <glommer@redhat.com>
> >
> > kvm_cpu_register_physical_memory() is its only user. Remove it.
> >
> > Signed-off-by: Glauber Costa <glommer@redhat.com>
> > ---
> > qemu/qemu-kvm.c | 52 +++++++++++++++++++++-------------------------------
> > 1 files changed, 21 insertions(+), 31 deletions(-)
> >
> > diff --git a/qemu/qemu-kvm.c b/qemu/qemu-kvm.c
> > index 8d366e5..f0ef21e 100644
> > --- a/qemu/qemu-kvm.c
> > +++ b/qemu/qemu-kvm.c
> > @@ -775,42 +775,32 @@ void kvm_cpu_register_physical_memory(target_phys_addr_t start_addr,
> > unsigned long size,
> > unsigned long phys_offset)
> > {
> > -#ifdef KVM_CAP_USER_MEMORY
> > int r = 0;
> > -
> > - r = kvm_check_extension(kvm_context, KVM_CAP_USER_MEMORY);
> > - if (r) {
> > - if (!(phys_offset & ~TARGET_PAGE_MASK)) {
> > - r = kvm_is_allocated_mem(kvm_context, start_addr, size);
> > - if (r)
> > - return;
> > - r = kvm_is_intersecting_mem(kvm_context, start_addr);
> > - if (r)
> > - kvm_create_mem_hole(kvm_context, start_addr, size);
> > - r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
> > - phys_ram_base + phys_offset,
> > - size, 0);
> > - }
> > - if (phys_offset & IO_MEM_ROM) {
> > - phys_offset &= ~IO_MEM_ROM;
> > - r = kvm_is_intersecting_mem(kvm_context, start_addr);
> > - if (r)
> > - kvm_create_mem_hole(kvm_context, start_addr, size);
> > - r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
> > - phys_ram_base + phys_offset,
> > - size, 0);
> > - }
> > - if (r < 0) {
> > - printf("kvm_cpu_register_physical_memory: failed\n");
> > - exit(1);
> > - }
> > - return;
> > + if (!(phys_offset & ~TARGET_PAGE_MASK)) {
> > + r = kvm_is_allocated_mem(kvm_context, start_addr, size);
> > + if (r)
> > + return;
> > + r = kvm_is_intersecting_mem(kvm_context, start_addr);
> > + if (r)
> > + kvm_create_mem_hole(kvm_context, start_addr, size);
> > + r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
> > + phys_ram_base + phys_offset,
> > + size, 0);
> > }
> > -#endif
> > if (phys_offset & IO_MEM_ROM) {
>
> At this chance: Shouldn't this become 'else if'?
fyi: just sent out a new series, this time with numbers and no tabs in qemu ;-)
As a coding style practice, yes. But they are mutually exclusive anyway, so it shouldn't
matter. We could definitely try to make it better, but they way to go is to have only one case
instead of two: look at how close they are to each other! I have a later series that do that,
so I'm just trying to set up the ground here.
>
> > phys_offset &= ~IO_MEM_ROM;
> > - memcpy(phys_ram_base + start_addr, phys_ram_base + phys_offset, size);
> > + r = kvm_is_intersecting_mem(kvm_context, start_addr);
> > + if (r)
> > + kvm_create_mem_hole(kvm_context, start_addr, size);
> > + r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
> > + phys_ram_base + phys_offset,
> > + size, 0);
> > + }
> > + if (r < 0) {
> > + printf("kvm_cpu_register_physical_memory: failed\n");
> > + exit(1);
> > }
> > + return;
> > }
> >
> > int kvm_setup_guest_memory(void *area, unsigned long size)
>
> Jan
>
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH] remove KVM_CAP_USER_MEMORY reference from qemu-kvm.c
2008-09-10 19:37 ` Glauber Costa
@ 2008-09-10 19:59 ` Jan Kiszka
0 siblings, 0 replies; 33+ messages in thread
From: Jan Kiszka @ 2008-09-10 19:59 UTC (permalink / raw)
To: Glauber Costa; +Cc: Glauber Costa, kvm, avi, aliguori
[-- Attachment #1: Type: text/plain, Size: 3658 bytes --]
Glauber Costa wrote:
> On Wed, Sep 10, 2008 at 09:23:18PM +0200, Jan Kiszka wrote:
>> Glauber Costa wrote:
>>> From: Glauber Costa <glommer@redhat.com>
>>>
>>> kvm_cpu_register_physical_memory() is its only user. Remove it.
>>>
>>> Signed-off-by: Glauber Costa <glommer@redhat.com>
>>> ---
>>> qemu/qemu-kvm.c | 52 +++++++++++++++++++++-------------------------------
>>> 1 files changed, 21 insertions(+), 31 deletions(-)
>>>
>>> diff --git a/qemu/qemu-kvm.c b/qemu/qemu-kvm.c
>>> index 8d366e5..f0ef21e 100644
>>> --- a/qemu/qemu-kvm.c
>>> +++ b/qemu/qemu-kvm.c
>>> @@ -775,42 +775,32 @@ void kvm_cpu_register_physical_memory(target_phys_addr_t start_addr,
>>> unsigned long size,
>>> unsigned long phys_offset)
>>> {
>>> -#ifdef KVM_CAP_USER_MEMORY
>>> int r = 0;
>>> -
>>> - r = kvm_check_extension(kvm_context, KVM_CAP_USER_MEMORY);
>>> - if (r) {
>>> - if (!(phys_offset & ~TARGET_PAGE_MASK)) {
>>> - r = kvm_is_allocated_mem(kvm_context, start_addr, size);
>>> - if (r)
>>> - return;
>>> - r = kvm_is_intersecting_mem(kvm_context, start_addr);
>>> - if (r)
>>> - kvm_create_mem_hole(kvm_context, start_addr, size);
>>> - r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
>>> - phys_ram_base + phys_offset,
>>> - size, 0);
>>> - }
>>> - if (phys_offset & IO_MEM_ROM) {
>>> - phys_offset &= ~IO_MEM_ROM;
>>> - r = kvm_is_intersecting_mem(kvm_context, start_addr);
>>> - if (r)
>>> - kvm_create_mem_hole(kvm_context, start_addr, size);
>>> - r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
>>> - phys_ram_base + phys_offset,
>>> - size, 0);
>>> - }
>>> - if (r < 0) {
>>> - printf("kvm_cpu_register_physical_memory: failed\n");
>>> - exit(1);
>>> - }
>>> - return;
>>> + if (!(phys_offset & ~TARGET_PAGE_MASK)) {
>>> + r = kvm_is_allocated_mem(kvm_context, start_addr, size);
>>> + if (r)
>>> + return;
>>> + r = kvm_is_intersecting_mem(kvm_context, start_addr);
>>> + if (r)
>>> + kvm_create_mem_hole(kvm_context, start_addr, size);
>>> + r = kvm_register_userspace_phys_mem(kvm_context, start_addr,
>>> + phys_ram_base + phys_offset,
>>> + size, 0);
>>> }
>>> -#endif
>>> if (phys_offset & IO_MEM_ROM) {
>> At this chance: Shouldn't this become 'else if'?
>
> fyi: just sent out a new series, this time with numbers and no tabs in qemu ;-)
Yeah, much better. :)
>
> As a coding style practice, yes. But they are mutually exclusive anyway, so it shouldn't
> matter. We could definitely try to make it better, but they way to go is to have only one case
> instead of two: look at how close they are to each other! I have a later series that do that,
> so I'm just trying to set up the ground here.
Well, they are close partly because the IO_MEM_ROM part is incomplete
(it ignores the 'read-only' property).
However, I just stumbled over it while trying to understand how this
function works. Without the 'else', I had to check twice that the cases
are exclusive in practice...
Jan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 257 bytes --]
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH 0/12] get rid of kernel memory registration
2008-09-10 19:20 ` [PATCH 0/12] get rid of kernel memory registration Glauber Costa
@ 2008-09-11 8:59 ` Avi Kivity
0 siblings, 0 replies; 33+ messages in thread
From: Avi Kivity @ 2008-09-11 8:59 UTC (permalink / raw)
To: Glauber Costa; +Cc: kvm, aliguori
Glauber Costa wrote:
> Avi,
>
> I hope it is better now.
> For libkvm code, I'm still using tabs. For qemu, spaces.
> However, I'm not fixing places that were already using it. There are a lot
> of patches in flight right now, anthony's integration effort being the most
> significant ones, and simple whitespace fixes could break them.
Definitely the right approach.
> We can do
> a later pass that removes all the tabs.
>
Or wait for the natural churn to fix it.
Who invented tabs, and what did he think he was doing?
Anyway applied the lot, thanks.
--
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
^ permalink raw reply [flat|nested] 33+ messages in thread
end of thread, other threads:[~2008-09-11 9:01 UTC | newest]
Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-08 19:30 [PATCH 0/12] Get rid of kernel memory allocation Glauber Costa
2008-09-08 19:30 ` [PATCH] start removing kernel memory functions Glauber Costa
2008-09-08 19:30 ` [PATCH] remove tests of user memory from vl.c Glauber Costa
2008-09-08 19:30 ` [PATCH] coalesce memory allocation Glauber Costa
2008-09-08 19:30 ` [PATCH] remove KVM_CAP_USER_MEMORY reference from qemu-kvm.c Glauber Costa
2008-09-08 19:30 ` [PATCH] remove KVM_CAP_USER_MEMORY from libkvm.c Glauber Costa
2008-09-08 19:30 ` [PATCH] remove create_kernel_phys_mem Glauber Costa
2008-09-08 19:30 ` [PATCH] get rid of kvm_create_userspace_phys_mem Glauber Costa
2008-09-08 19:30 ` [PATCH] remove user_alloc field from slot representation Glauber Costa
2008-09-08 19:30 ` [PATCH] merge destroy phys mem functions Glauber Costa
2008-09-08 19:30 ` [PATCH] rename kvm_register_userspace_phys_mem Glauber Costa
2008-09-08 19:30 ` [PATCH] remove kernel memory code from hw/pc.c Glauber Costa
2008-09-08 19:30 ` [PATCH] remove kernel memory allocation code from ipf.c Glauber Costa
2008-09-10 19:23 ` [PATCH] remove KVM_CAP_USER_MEMORY reference from qemu-kvm.c Jan Kiszka
2008-09-10 19:37 ` Glauber Costa
2008-09-10 19:59 ` Jan Kiszka
2008-09-09 14:25 ` [PATCH 0/12] Get rid of kernel memory allocation Avi Kivity
2008-09-09 14:57 ` Glauber Costa
2008-09-09 15:01 ` Avi Kivity
2008-09-10 19:20 ` [PATCH 0/12] get rid of kernel memory registration Glauber Costa
2008-09-11 8:59 ` Avi Kivity
2008-09-10 19:20 ` [PATCH 01/12] start removing kernel memory functions Glauber Costa
2008-09-10 19:20 ` [PATCH 02/12] remove tests of user memory from vl.c Glauber Costa
2008-09-10 19:20 ` [PATCH 03/12] coalesce memory allocation Glauber Costa
2008-09-10 19:20 ` [PATCH 04/12] remove KVM_CAP_USER_MEMORY reference from qemu-kvm.c Glauber Costa
2008-09-10 19:20 ` [PATCH 05/12] remove KVM_CAP_USER_MEMORY from libkvm.c Glauber Costa
2008-09-10 19:21 ` [PATCH 06/12] remove create_kernel_phys_mem Glauber Costa
2008-09-10 19:21 ` [PATCH 07/12] get rid of kvm_create_userspace_phys_mem Glauber Costa
2008-09-10 19:21 ` [PATCH 08/12] remove user_alloc field from slot representation Glauber Costa
2008-09-10 19:21 ` [PATCH 09/12] merge destroy phys mem functions Glauber Costa
2008-09-10 19:21 ` [PATCH 10/12] rename kvm_register_userspace_phys_mem Glauber Costa
2008-09-10 19:21 ` [PATCH 11/12] remove kernel memory code from hw/pc.c Glauber Costa
2008-09-10 19:21 ` [PATCH 12/12] remove kernel memory allocation code from ipf.c Glauber Costa
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox