qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v2 4/5] Qemu: implement readonly memory


From: Xiao Guangrong
Subject: [Qemu-devel] [PATCH v2 4/5] Qemu: implement readonly memory
Date: Thu, 25 Oct 2012 17:22:48 +0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120911 Thunderbird/15.0.1

As readonly memory is support in kvm, this patch supports this feature
in qemu, mainly pluging the memory region with KVM_MEM_READONLY flag
to kvm

Signed-off-by: Xiao Guangrong <address@hidden>
---
 kvm-all.c |   24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 92a7137..6b9395a 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -101,6 +101,7 @@ struct KVMState
     QTAILQ_HEAD(msi_hashtab, KVMMSIRoute) msi_hashtab[KVM_MSI_HASHTAB_SIZE];
     bool direct_msi;
 #endif
+    bool readonly_mem;
 };

 KVMState *kvm_state;
@@ -265,9 +266,16 @@ err:
  * dirty pages logging control
  */

-static int kvm_mem_flags(KVMState *s, bool log_dirty)
+static int kvm_mem_flags(KVMState *s, MemoryRegion *mr)
 {
-    return log_dirty ? KVM_MEM_LOG_DIRTY_PAGES : 0;
+    int flags;
+
+    flags = memory_region_is_logging(mr) ? KVM_MEM_LOG_DIRTY_PAGES : 0;
+
+    if (s->readonly_mem && mr->readonly) {
+        flags |= KVM_MEM_READONLY;
+    }
+    return flags;
 }

 static int kvm_slot_dirty_pages_log_change(KVMSlot *mem, bool log_dirty)
@@ -278,7 +286,7 @@ static int kvm_slot_dirty_pages_log_change(KVMSlot *mem, 
bool log_dirty)

     old_flags = mem->flags;

-    flags = (mem->flags & ~mask) | kvm_mem_flags(s, log_dirty);
+    flags = (mem->flags & ~mask) | (log_dirty ? mask : 0);
     mem->flags = flags;

     /* If nothing changed effectively, no need to issue ioctl */
@@ -626,7 +634,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, 
bool add)
             mem->memory_size = old.memory_size;
             mem->start_addr = old.start_addr;
             mem->ram = old.ram;
-            mem->flags = kvm_mem_flags(s, log_dirty);
+            mem->flags = kvm_mem_flags(s, mr);

             err = kvm_set_user_memory_region(s, mem);
             if (err) {
@@ -647,7 +655,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, 
bool add)
             mem->memory_size = start_addr - old.start_addr;
             mem->start_addr = old.start_addr;
             mem->ram = old.ram;
-            mem->flags =  kvm_mem_flags(s, log_dirty);
+            mem->flags =  kvm_mem_flags(s, mr);

             err = kvm_set_user_memory_region(s, mem);
             if (err) {
@@ -671,7 +679,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, 
bool add)
             size_delta = mem->start_addr - old.start_addr;
             mem->memory_size = old.memory_size - size_delta;
             mem->ram = old.ram + size_delta;
-            mem->flags = kvm_mem_flags(s, log_dirty);
+            mem->flags = kvm_mem_flags(s, mr);

             err = kvm_set_user_memory_region(s, mem);
             if (err) {
@@ -693,7 +701,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, 
bool add)
     mem->memory_size = size;
     mem->start_addr = start_addr;
     mem->ram = ram;
-    mem->flags = kvm_mem_flags(s, log_dirty);
+    mem->flags = kvm_mem_flags(s, mr);

     err = kvm_set_user_memory_region(s, mem);
     if (err) {
@@ -1390,6 +1398,8 @@ int kvm_init(void)
         s->irq_set_ioctl = KVM_IRQ_LINE_STATUS;
     }

+    s->readonly_mem = kvm_check_extension(s, KVM_CAP_READONLY_MEM);
+
     ret = kvm_arch_init(s);
     if (ret < 0) {
         goto err;
-- 
1.7.7.6




reply via email to

[Prev in Thread] Current Thread [Next in Thread]