* [Qemu-devel] [5734] Make KVM slot management more robust
@ 2008-11-18 15:41 Anthony Liguori
0 siblings, 0 replies; only message in thread
From: Anthony Liguori @ 2008-11-18 15:41 UTC (permalink / raw)
To: qemu-devel
Revision: 5734
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5734
Author: aliguori
Date: 2008-11-18 15:41:18 +0000 (Tue, 18 Nov 2008)
Log Message:
-----------
Make KVM slot management more robust
KVM keeps track of physical memory based on slots in the kernel. The current
code that translates QEMU memory mappings to slots work but is not robust
in the fact of reregistering partial regions of memory.
This patch does the right thing for reregistering partial regions of memory. It
also prevents QEMU from using KVM private slots.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Modified Paths:
--------------
trunk/kvm-all.c
Modified: trunk/kvm-all.c
===================================================================
--- trunk/kvm-all.c 2008-11-18 09:32:01 UTC (rev 5733)
+++ trunk/kvm-all.c 2008-11-18 15:41:18 UTC (rev 5734)
@@ -50,6 +50,9 @@
int i;
for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
+ /* KVM private memory slots */
+ if (i >= 8 && i < 12)
+ continue;
if (s->slots[i].memory_size == 0)
return &s->slots[i];
}
@@ -327,10 +330,45 @@
kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, mem);
} else if (start_addr >= mem->guest_phys_addr &&
- (start_addr + size) <= (mem->guest_phys_addr + mem->memory_size))
+ (start_addr + size) <= (mem->guest_phys_addr +
+ mem->memory_size)) {
+ KVMSlot slot;
+ target_phys_addr_t mem_start;
+ ram_addr_t mem_size, mem_offset;
+
+ /* Not splitting */
+ if ((phys_offset - (start_addr - mem->guest_phys_addr)) ==
+ ((uint8_t *)mem->userspace_addr - phys_ram_base))
+ return;
+
+ /* unregister whole slot */
+ memcpy(&slot, mem, sizeof(slot));
+ mem->memory_size = 0;
+ kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, mem);
+
+ /* register prefix slot */
+ mem_start = slot.guest_phys_addr;
+ mem_size = start_addr - slot.guest_phys_addr;
+ mem_offset = (uint8_t *)slot.userspace_addr - phys_ram_base;
+ if (mem_size)
+ kvm_set_phys_mem(mem_start, mem_size, mem_offset);
+
+ /* register new slot */
+ kvm_set_phys_mem(start_addr, size, phys_offset);
+
+ /* register suffix slot */
+ mem_start = start_addr + size;
+ mem_offset += mem_size + size;
+ mem_size = slot.memory_size - mem_size - size;
+ if (mem_size)
+ kvm_set_phys_mem(mem_start, mem_size, mem_offset);
+
return;
+ } else {
+ printf("Registering overlapping slot\n");
+ abort();
+ }
}
-
/* KVM does not need to know about this memory */
if (flags >= IO_MEM_UNASSIGNED)
return;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-11-18 15:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-18 15:41 [Qemu-devel] [5734] Make KVM slot management more robust Anthony Liguori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).