qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Andrew Jones <drjones@redhat.com>, lersek@redhat.com, mst@redhat.com
Subject: [Qemu-devel] [PATCH 03/12] kvm-all: put kvm_mem_flags to more work
Date: Thu, 18 Jun 2015 18:28:43 +0200	[thread overview]
Message-ID: <1434644932-90017-3-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1434644648-89776-1-git-send-email-pbonzini@redhat.com>

From: Andrew Jones <drjones@redhat.com>

Currently kvm_mem_flags just translates bools to bits, let's
make it also determine the bools first. This avoids its parameter
list growing each time we add a flag.

Signed-off-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 kvm-all.c | 42 ++++++++++++++++++++----------------------
 1 file changed, 20 insertions(+), 22 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 53e01d4..195886d 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -291,45 +291,47 @@ err:
  * dirty pages logging control
  */
 
-static int kvm_mem_flags(KVMState *s, bool log_dirty, bool readonly)
+static int kvm_mem_flags(MemoryRegion *mr)
 {
+    bool readonly = mr->readonly || memory_region_is_romd(mr);
     int flags = 0;
-    flags = log_dirty ? KVM_MEM_LOG_DIRTY_PAGES : 0;
+
+    if (memory_region_get_dirty_log_mask(mr) != 0) {
+        flags |= KVM_MEM_LOG_DIRTY_PAGES;
+    }
     if (readonly && kvm_readonly_mem_allowed) {
         flags |= KVM_MEM_READONLY;
     }
     return flags;
 }
 
-static int kvm_slot_dirty_pages_log_change(KVMSlot *mem, bool log_dirty)
+static int kvm_slot_update_flags(KVMSlot *mem, MemoryRegion *mr)
 {
     KVMState *s = kvm_state;
-    int flags, mask = KVM_MEM_LOG_DIRTY_PAGES;
     int old_flags;
 
     old_flags = mem->flags;
-
-    flags = (mem->flags & ~mask) | kvm_mem_flags(s, log_dirty, false);
-    mem->flags = flags;
+    mem->flags = kvm_mem_flags(mr);
 
     /* If nothing changed effectively, no need to issue ioctl */
-    if (flags == old_flags) {
+    if (mem->flags == old_flags) {
         return 0;
     }
 
     return kvm_set_user_memory_region(s, mem);
 }
 
-static int kvm_dirty_pages_log_change(hwaddr phys_addr,
-                                      ram_addr_t size, bool log_dirty)
+static int kvm_section_update_flags(MemoryRegionSection *section)
 {
     KVMState *s = kvm_state;
+    hwaddr phys_addr = section->offset_within_address_space;
+    ram_addr_t size = int128_get64(section->size);
     KVMSlot *mem = kvm_lookup_matching_slot(s, phys_addr, phys_addr + size);
 
     if (mem == NULL)  {
         return 0;
     } else {
-        return kvm_slot_dirty_pages_log_change(mem, log_dirty);
+        return kvm_slot_update_flags(mem, section->mr);
     }
 }
 
@@ -343,8 +345,7 @@ static void kvm_log_start(MemoryListener *listener,
         return;
     }
 
-    r = kvm_dirty_pages_log_change(section->offset_within_address_space,
-                                   int128_get64(section->size), true);
+    r = kvm_section_update_flags(section);
     if (r < 0) {
         abort();
     }
@@ -360,8 +361,7 @@ static void kvm_log_stop(MemoryListener *listener,
         return;
     }
 
-    r = kvm_dirty_pages_log_change(section->offset_within_address_space,
-                                   int128_get64(section->size), false);
+    r = kvm_section_update_flags(section);
     if (r < 0) {
         abort();
     }
@@ -638,9 +638,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, bool add)
     KVMSlot *mem, old;
     int err;
     MemoryRegion *mr = section->mr;
-    bool log_dirty = memory_region_get_dirty_log_mask(mr) != 0;
     bool writeable = !mr->readonly && !mr->rom_device;
-    bool readonly_flag = mr->readonly || memory_region_is_romd(mr);
     hwaddr start_addr = section->offset_within_address_space;
     ram_addr_t size = int128_get64(section->size);
     void *ram = NULL;
@@ -684,7 +682,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, bool add)
             (ram - start_addr == mem->ram - mem->start_addr)) {
             /* The new slot fits into the existing one and comes with
              * identical parameters - update flags and done. */
-            kvm_slot_dirty_pages_log_change(mem, log_dirty);
+            kvm_slot_update_flags(mem, mr);
             return;
         }
 
@@ -717,7 +715,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, readonly_flag);
+            mem->flags = kvm_mem_flags(mr);
 
             err = kvm_set_user_memory_region(s, mem);
             if (err) {
@@ -738,7 +736,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, readonly_flag);
+            mem->flags =  kvm_mem_flags(mr);
 
             err = kvm_set_user_memory_region(s, mem);
             if (err) {
@@ -762,7 +760,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, readonly_flag);
+            mem->flags = kvm_mem_flags(mr);
 
             err = kvm_set_user_memory_region(s, mem);
             if (err) {
@@ -784,7 +782,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, readonly_flag);
+    mem->flags = kvm_mem_flags(mr);
 
     err = kvm_set_user_memory_region(s, mem);
     if (err) {
-- 
1.8.3.1

  parent reply	other threads:[~2015-06-18 16:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-18 16:23 [Qemu-devel] [PATCH for-2.4 00/12] pc: KVM support for SMRAM Paolo Bonzini
2015-06-18 16:28 ` [Qemu-devel] [PATCH 01/12] piix4/ich9: do not raise SMI on ACPI enable/disable commands Paolo Bonzini
2015-06-18 16:28 ` [Qemu-devel] [PATCH 02/12] target-i386: add support for SMBASE MSR and SMIs Paolo Bonzini
2015-06-18 16:28 ` Paolo Bonzini [this message]
2015-06-18 16:28 ` [Qemu-devel] [PATCH 04/12] kvm-all: remove useless typedef Paolo Bonzini
2015-06-18 16:28 ` [Qemu-devel] [PATCH 05/12] kvm-all: move internal types to kvm_int.h Paolo Bonzini
2015-06-18 16:30 ` [Qemu-devel] [PATCH 06/12] kvm-all: make KVM's memory listener more generic Paolo Bonzini
2015-06-18 16:30 ` [Qemu-devel] [PATCH 07/12] kvm-all: add support for multiple address spaces Paolo Bonzini
2015-06-18 16:30 ` [Qemu-devel] [PATCH 08/12] kvm-all: kvm_irqchip_create is not expected to fail Paolo Bonzini
2015-06-18 16:30 ` [Qemu-devel] [PATCH 09/12] target-i386: register a separate KVM address space including SMRAM regions Paolo Bonzini
2015-06-18 16:30 ` [Qemu-devel] [PATCH 10/12] pc_piix: rename kvm_enabled to smm_enabled Paolo Bonzini
2015-06-18 16:30 ` [Qemu-devel] [PATCH 11/12] ich9: add smm_enabled field and arguments Paolo Bonzini
2015-06-18 16:30 ` [Qemu-devel] [PATCH 12/12] pc: add SMM property Paolo Bonzini
  -- strict thread matches above, loose matches on Subject: below --
2015-06-05 14:31 [Qemu-devel] [PATCH 00/12] SMM part 2: KVM and -machine enablement Paolo Bonzini
2015-06-05 14:31 ` [Qemu-devel] [PATCH 03/12] kvm-all: put kvm_mem_flags to more work Paolo Bonzini

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=1434644932-90017-3-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=drjones@redhat.com \
    --cc=lersek@redhat.com \
    --cc=mst@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 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).