All of lore.kernel.org
 help / color / mirror / Atom feed
* [PULL] Urgent memory fix for kvm with unaligned memory slots
@ 2012-03-01 13:40 ` Avi Kivity
  0 siblings, 0 replies; 13+ messages in thread
From: Avi Kivity @ 2012-03-01 13:40 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: qemu-devel, KVM list

The memory core may generate RAM memory regions that are not page
aligned, but the kvm code is not prepared to handle them well and will
abort under certain conditions.  This patch fixes the problem.

Please pull from:

  git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git memory/urgent

----------------------------------------------------------------
Avi Kivity (1):
      kvm: fix unaligned slots

 kvm-all.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index c4babda..4b7a4ae 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -541,17 +541,26 @@ static void kvm_set_phys_mem(MemoryRegionSection
*section, bool add)
     target_phys_addr_t start_addr = section->offset_within_address_space;
     ram_addr_t size = section->size;
     void *ram = NULL;
+    unsigned delta;
 
     /* kvm works in page size chunks, but the function may be called
        with sub-page size and unaligned start address. */
-    size = TARGET_PAGE_ALIGN(size);
-    start_addr = TARGET_PAGE_ALIGN(start_addr);
+    delta = TARGET_PAGE_ALIGN(size) - size;
+    if (delta > size) {
+        return;
+    }
+    start_addr += delta;
+    size -= delta;
+    size &= TARGET_PAGE_MASK;
+    if (!size || (start_addr & ~TARGET_PAGE_MASK)) {
+        return;
+    }
 
     if (!memory_region_is_ram(mr)) {
         return;
     }
 
-    ram = memory_region_get_ram_ptr(mr) + section->offset_within_region;
+    ram = memory_region_get_ram_ptr(mr) + section->offset_within_region
+ delta;
 
     while (1) {
         mem = kvm_lookup_overlapping_slot(s, start_addr, start_addr +
size);

-- 
error compiling committee.c: too many arguments to function


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2012-03-02 13:23 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-01 13:40 [PULL] Urgent memory fix for kvm with unaligned memory slots Avi Kivity
2012-03-01 13:40 ` [Qemu-devel] " Avi Kivity
2012-03-01 16:51 ` Bobby Powers
2012-03-01 16:51   ` [Qemu-devel] " Bobby Powers
2012-03-01 17:03   ` Avi Kivity
2012-03-01 17:03     ` [Qemu-devel] " Avi Kivity
2012-03-01 17:08     ` Eric Blake
2012-03-01 17:08       ` Eric Blake
2012-03-01 17:11       ` Bobby Powers
2012-03-01 17:11         ` Bobby Powers
2012-03-01 17:13       ` Avi Kivity
2012-03-01 17:13         ` Avi Kivity
2012-03-02 13:23 ` Anthony Liguori

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.