All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
To: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Cc: KVM <kvm@vger.kernel.org>, Jan Kiszka <jan.kiszka@siemens.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	qemu-devel@nongnu.org, Kevin O'Connor <kevin@koconnor.net>,
	Avi Kivity <avi@redhat.com>,
	Anthony Liguori <anthony@codemonkey.ws>,
	Liu Sheng <liusheng@linux.vnet.ibm.com>
Subject: [PATCH v2 4/5] Qemu: implement readonly memory
Date: Thu, 25 Oct 2012 17:22:48 +0800	[thread overview]
Message-ID: <508904E8.3010809@linux.vnet.ibm.com> (raw)
In-Reply-To: <50890462.5010307@linux.vnet.ibm.com>

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 <xiaoguangrong@linux.vnet.ibm.com>
---
 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

  parent reply	other threads:[~2012-10-25  9:22 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-25  9:20 [PATCH v2 0/5] Qemu: implement readonly memory Xiao Guangrong
2012-10-25  9:21 ` [PATCH v2 1/5] KVM: define KVM_CAP_READONLY_MEM unconditionally Xiao Guangrong
2012-10-25 12:14   ` Jan Kiszka
2012-10-25  9:21 ` [PATCH v2 2/5] Qemu: update header files Xiao Guangrong
2012-10-25 11:03   ` [Qemu-devel] " Peter Maydell
2012-10-25  9:22 ` [PATCH v2 3/5] Qemu: do not mark bios readonly Xiao Guangrong
2012-10-26 10:35   ` Jan Kiszka
2012-10-29  7:09     ` Xiao Guangrong
2012-10-29  7:44       ` Jan Kiszka
2012-10-29  8:31         ` Xiao Guangrong
2012-10-31  6:03           ` Jan Kiszka
2012-10-31  6:35             ` Xiao Guangrong
2012-10-31  6:46               ` Jan Kiszka
2012-10-31  7:01                 ` Xiao Guangrong
2012-10-31  7:21                   ` Jan Kiszka
2012-10-25  9:22 ` Xiao Guangrong [this message]
2012-10-25  9:23 ` [PATCH v2 5/5] Qemu: mark pci rom readonly Xiao Guangrong

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=508904E8.3010809@linux.vnet.ibm.com \
    --to=xiaoguangrong@linux.vnet.ibm.com \
    --cc=anthony@codemonkey.ws \
    --cc=avi@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=kevin@koconnor.net \
    --cc=kvm@vger.kernel.org \
    --cc=liusheng@linux.vnet.ibm.com \
    --cc=mtosatti@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

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

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