Blame SOURCES/kvm-memory-cpu_physical_memory_mask_dirty_range-always-c.patch

0a122b
From e892037c3e5cf8ec5f0278dcbc97167831100a54 Mon Sep 17 00:00:00 2001
0a122b
From: Juan Quintela <quintela@redhat.com>
0a122b
Date: Tue, 14 Jan 2014 15:07:23 +0100
0a122b
Subject: [PATCH 12/40] memory: cpu_physical_memory_mask_dirty_range() always clears a single flag
0a122b
0a122b
RH-Author: Juan Quintela <quintela@redhat.com>
0a122b
Message-id: <1389712071-23303-13-git-send-email-quintela@redhat.com>
0a122b
Patchwork-id: 56667
0a122b
O-Subject: [RHEL7 qemu-kvm PATCH 12/40] memory: cpu_physical_memory_mask_dirty_range() always clears a single flag
0a122b
Bugzilla: 997559
0a122b
RH-Acked-by: Orit Wasserman <owasserm@redhat.com>
0a122b
RH-Acked-by: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
0a122b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
0a122b
Document it
0a122b
0a122b
Signed-off-by: Juan Quintela <quintela@redhat.com>
0a122b
Reviewed-by: Eric Blake <eblake@redhat.com>
0a122b
Reviewed-by: Orit Wasserman <owasserm@redhat.com>
0a122b
(cherry picked from commit 52159192919469b424b54c167312e53d5a62d233)
0a122b
Signed-off-by: Juan Quintela <quintela@trasno.org>
0a122b
---
0a122b
 cputlb.c                       |  4 ++--
0a122b
 exec.c                         | 19 ++++++++++---------
0a122b
 include/exec/memory-internal.h | 40 ++++++++++++++++++----------------------
0a122b
 include/exec/memory.h          |  3 ---
0a122b
 memory.c                       | 10 ++++------
0a122b
 5 files changed, 34 insertions(+), 42 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 cputlb.c                       |    4 ++--
0a122b
 exec.c                         |   19 ++++++++++---------
0a122b
 include/exec/memory-internal.h |   40 ++++++++++++++++++----------------------
0a122b
 include/exec/memory.h          |    3 ---
0a122b
 memory.c                       |   10 ++++------
0a122b
 5 files changed, 34 insertions(+), 42 deletions(-)
0a122b
0a122b
diff --git a/cputlb.c b/cputlb.c
0a122b
index 84e83e0..9c89c01 100644
0a122b
--- a/cputlb.c
0a122b
+++ b/cputlb.c
0a122b
@@ -129,7 +129,7 @@ void tlb_protect_code(ram_addr_t ram_addr)
0a122b
 {
0a122b
     cpu_physical_memory_reset_dirty(ram_addr,
0a122b
                                     ram_addr + TARGET_PAGE_SIZE,
0a122b
-                                    CODE_DIRTY_FLAG);
0a122b
+                                    DIRTY_MEMORY_CODE);
0a122b
 }
0a122b
 
0a122b
 /* update the TLB so that writes in physical page 'phys_addr' are no longer
0a122b
@@ -137,7 +137,7 @@ void tlb_protect_code(ram_addr_t ram_addr)
0a122b
 void tlb_unprotect_code_phys(CPUArchState *env, ram_addr_t ram_addr,
0a122b
                              target_ulong vaddr)
0a122b
 {
0a122b
-    cpu_physical_memory_set_dirty_flag(ram_addr, CODE_DIRTY_FLAG);
0a122b
+    cpu_physical_memory_set_dirty_flag(ram_addr, DIRTY_MEMORY_CODE);
0a122b
 }
0a122b
 
0a122b
 static bool tlb_is_dirty_ram(CPUTLBEntry *tlbe)
0a122b
diff --git a/exec.c b/exec.c
0a122b
index 069e082..8942d50 100644
0a122b
--- a/exec.c
0a122b
+++ b/exec.c
0a122b
@@ -596,7 +596,7 @@ static void tlb_reset_dirty_range_all(ram_addr_t start, ram_addr_t end,
0a122b
 
0a122b
 /* Note: start and end must be within the same ram block.  */
0a122b
 void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t end,
0a122b
-                                     int dirty_flags)
0a122b
+                                     unsigned client)
0a122b
 {
0a122b
     uintptr_t length;
0a122b
 
0a122b
@@ -606,7 +606,7 @@ void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t end,
0a122b
     length = end - start;
0a122b
     if (length == 0)
0a122b
         return;
0a122b
-    cpu_physical_memory_mask_dirty_range(start, length, dirty_flags);
0a122b
+    cpu_physical_memory_mask_dirty_range(start, length, client);
0a122b
 
0a122b
     if (tcg_enabled()) {
0a122b
         tlb_reset_dirty_range_all(start, end, length);
0a122b
@@ -1480,7 +1480,7 @@ static const MemoryRegionOps rom_mem_ops = {
0a122b
 static void notdirty_mem_write(void *opaque, hwaddr ram_addr,
0a122b
                                uint64_t val, unsigned size)
0a122b
 {
0a122b
-    if (!cpu_physical_memory_get_dirty_flag(ram_addr, CODE_DIRTY_FLAG)) {
0a122b
+    if (!cpu_physical_memory_get_dirty_flag(ram_addr, DIRTY_MEMORY_CODE)) {
0a122b
         tb_invalidate_phys_page_fast(ram_addr, size);
0a122b
     }
0a122b
     switch (size) {
0a122b
@@ -1496,8 +1496,8 @@ static void notdirty_mem_write(void *opaque, hwaddr ram_addr,
0a122b
     default:
0a122b
         abort();
0a122b
     }
0a122b
-    cpu_physical_memory_set_dirty_flag(ram_addr, MIGRATION_DIRTY_FLAG);
0a122b
-    cpu_physical_memory_set_dirty_flag(ram_addr, VGA_DIRTY_FLAG);
0a122b
+    cpu_physical_memory_set_dirty_flag(ram_addr, DIRTY_MEMORY_MIGRATION);
0a122b
+    cpu_physical_memory_set_dirty_flag(ram_addr, DIRTY_MEMORY_VGA);
0a122b
     /* we remove the notdirty callback only if the code has been
0a122b
        flushed */
0a122b
     if (cpu_physical_memory_is_dirty(ram_addr))
0a122b
@@ -1919,8 +1919,8 @@ static void invalidate_and_set_dirty(hwaddr addr,
0a122b
         /* invalidate code */
0a122b
         tb_invalidate_phys_page_range(addr, addr + length, 0);
0a122b
         /* set dirty bit */
0a122b
-        cpu_physical_memory_set_dirty_flag(addr, VGA_DIRTY_FLAG);
0a122b
-        cpu_physical_memory_set_dirty_flag(addr, MIGRATION_DIRTY_FLAG);
0a122b
+        cpu_physical_memory_set_dirty_flag(addr, DIRTY_MEMORY_VGA);
0a122b
+        cpu_physical_memory_set_dirty_flag(addr, DIRTY_MEMORY_MIGRATION);
0a122b
     }
0a122b
     xen_modified_memory(addr, length);
0a122b
 }
0a122b
@@ -2435,8 +2435,9 @@ void stl_phys_notdirty(hwaddr addr, uint32_t val)
0a122b
                 /* invalidate code */
0a122b
                 tb_invalidate_phys_page_range(addr1, addr1 + 4, 0);
0a122b
                 /* set dirty bit */
0a122b
-                cpu_physical_memory_set_dirty_flag(addr1, MIGRATION_DIRTY_FLAG);
0a122b
-                cpu_physical_memory_set_dirty_flag(addr1, VGA_DIRTY_FLAG);
0a122b
+                cpu_physical_memory_set_dirty_flag(addr1,
0a122b
+                                                   DIRTY_MEMORY_MIGRATION);
0a122b
+                cpu_physical_memory_set_dirty_flag(addr1, DIRTY_MEMORY_VGA);
0a122b
             }
0a122b
         }
0a122b
     }
0a122b
diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h
0a122b
index 794fabd..fbcd384 100644
0a122b
--- a/include/exec/memory-internal.h
0a122b
+++ b/include/exec/memory-internal.h
0a122b
@@ -49,29 +49,25 @@ ram_addr_t qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr);
0a122b
 void qemu_ram_free(ram_addr_t addr);
0a122b
 void qemu_ram_free_from_ptr(ram_addr_t addr);
0a122b
 
0a122b
-#define VGA_DIRTY_FLAG       0x01
0a122b
-#define CODE_DIRTY_FLAG      0x02
0a122b
-#define MIGRATION_DIRTY_FLAG 0x08
0a122b
-
0a122b
 static inline bool cpu_physical_memory_get_dirty_flag(ram_addr_t addr,
0a122b
-                                                      int dirty_flag)
0a122b
+                                                      unsigned client)
0a122b
 {
0a122b
-    return ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] & dirty_flag;
0a122b
+    return ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] & (1 << client);
0a122b
 }
0a122b
 
0a122b
 /* read dirty bit (return 0 or 1) */
0a122b
 static inline bool cpu_physical_memory_is_dirty(ram_addr_t addr)
0a122b
 {
0a122b
-    bool vga = cpu_physical_memory_get_dirty_flag(addr, VGA_DIRTY_FLAG);
0a122b
-    bool code = cpu_physical_memory_get_dirty_flag(addr, CODE_DIRTY_FLAG);
0a122b
+    bool vga = cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_VGA);
0a122b
+    bool code = cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_CODE);
0a122b
     bool migration =
0a122b
-        cpu_physical_memory_get_dirty_flag(addr, MIGRATION_DIRTY_FLAG);
0a122b
+        cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_MIGRATION);
0a122b
     return vga && code && migration;
0a122b
 }
0a122b
 
0a122b
 static inline int cpu_physical_memory_get_dirty(ram_addr_t start,
0a122b
                                                 ram_addr_t length,
0a122b
-                                                int dirty_flag)
0a122b
+                                                unsigned client)
0a122b
 {
0a122b
     int ret = 0;
0a122b
     ram_addr_t addr, end;
0a122b
@@ -79,28 +75,28 @@ static inline int cpu_physical_memory_get_dirty(ram_addr_t start,
0a122b
     end = TARGET_PAGE_ALIGN(start + length);
0a122b
     start &= TARGET_PAGE_MASK;
0a122b
     for (addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
0a122b
-        ret |= cpu_physical_memory_get_dirty_flag(addr, dirty_flag);
0a122b
+        ret |= cpu_physical_memory_get_dirty_flag(addr, client);
0a122b
     }
0a122b
     return ret;
0a122b
 }
0a122b
 
0a122b
 static inline void cpu_physical_memory_set_dirty_flag(ram_addr_t addr,
0a122b
-                                                      int dirty_flag)
0a122b
+                                                      unsigned client)
0a122b
 {
0a122b
-    ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] |= dirty_flag;
0a122b
+    ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] |= (1 << client);
0a122b
 }
0a122b
 
0a122b
 static inline void cpu_physical_memory_set_dirty(ram_addr_t addr)
0a122b
 {
0a122b
-    cpu_physical_memory_set_dirty_flag(addr, MIGRATION_DIRTY_FLAG);
0a122b
-    cpu_physical_memory_set_dirty_flag(addr, VGA_DIRTY_FLAG);
0a122b
-    cpu_physical_memory_set_dirty_flag(addr, CODE_DIRTY_FLAG);
0a122b
+    cpu_physical_memory_set_dirty_flag(addr, DIRTY_MEMORY_MIGRATION);
0a122b
+    cpu_physical_memory_set_dirty_flag(addr, DIRTY_MEMORY_VGA);
0a122b
+    cpu_physical_memory_set_dirty_flag(addr, DIRTY_MEMORY_CODE);
0a122b
 }
0a122b
 
0a122b
-static inline int cpu_physical_memory_clear_dirty_flags(ram_addr_t addr,
0a122b
-                                                        int dirty_flags)
0a122b
+static inline int cpu_physical_memory_clear_dirty_flag(ram_addr_t addr,
0a122b
+                                                       unsigned client)
0a122b
 {
0a122b
-    int mask = ~dirty_flags;
0a122b
+    int mask = ~(1 << client);
0a122b
 
0a122b
     return ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] &= mask;
0a122b
 }
0a122b
@@ -120,19 +116,19 @@ static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start,
0a122b
 
0a122b
 static inline void cpu_physical_memory_mask_dirty_range(ram_addr_t start,
0a122b
                                                         ram_addr_t length,
0a122b
-                                                        int dirty_flags)
0a122b
+                                                        unsigned client)
0a122b
 {
0a122b
     ram_addr_t addr, end;
0a122b
 
0a122b
     end = TARGET_PAGE_ALIGN(start + length);
0a122b
     start &= TARGET_PAGE_MASK;
0a122b
     for (addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
0a122b
-        cpu_physical_memory_clear_dirty_flags(addr, dirty_flags);
0a122b
+        cpu_physical_memory_clear_dirty_flag(addr, client);
0a122b
     }
0a122b
 }
0a122b
 
0a122b
 void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t end,
0a122b
-                                     int dirty_flags);
0a122b
+                                     unsigned client);
0a122b
 
0a122b
 extern const IORangeOps memory_region_iorange_ops;
0a122b
 
0a122b
diff --git a/include/exec/memory.h b/include/exec/memory.h
0a122b
index 9e88320..868fdb1 100644
0a122b
--- a/include/exec/memory.h
0a122b
+++ b/include/exec/memory.h
0a122b
@@ -30,9 +30,6 @@ typedef struct MemoryRegionOps MemoryRegionOps;
0a122b
 typedef struct MemoryRegionPortio MemoryRegionPortio;
0a122b
 typedef struct MemoryRegionMmio MemoryRegionMmio;
0a122b
 
0a122b
-/* Must match *_DIRTY_FLAGS in cpu-all.h.  To be replaced with dynamic
0a122b
- * registration.
0a122b
- */
0a122b
 #define DIRTY_MEMORY_VGA       0
0a122b
 #define DIRTY_MEMORY_CODE      1
0a122b
 #define DIRTY_MEMORY_MIGRATION 3
0a122b
diff --git a/memory.c b/memory.c
0a122b
index e7a454f..2883da5 100644
0a122b
--- a/memory.c
0a122b
+++ b/memory.c
0a122b
@@ -1070,8 +1070,7 @@ bool memory_region_get_dirty(MemoryRegion *mr, hwaddr addr,
0a122b
                              hwaddr size, unsigned client)
0a122b
 {
0a122b
     assert(mr->terminates);
0a122b
-    return cpu_physical_memory_get_dirty(mr->ram_addr + addr, size,
0a122b
-                                         1 << client);
0a122b
+    return cpu_physical_memory_get_dirty(mr->ram_addr + addr, size, client);
0a122b
 }
0a122b
 
0a122b
 void memory_region_set_dirty(MemoryRegion *mr, hwaddr addr,
0a122b
@@ -1086,12 +1085,11 @@ bool memory_region_test_and_clear_dirty(MemoryRegion *mr, hwaddr addr,
0a122b
 {
0a122b
     bool ret;
0a122b
     assert(mr->terminates);
0a122b
-    ret = cpu_physical_memory_get_dirty(mr->ram_addr + addr, size,
0a122b
-                                        1 << client);
0a122b
+    ret = cpu_physical_memory_get_dirty(mr->ram_addr + addr, size, client);
0a122b
     if (ret) {
0a122b
         cpu_physical_memory_reset_dirty(mr->ram_addr + addr,
0a122b
                                         mr->ram_addr + addr + size,
0a122b
-                                        1 << client);
0a122b
+                                        client);
0a122b
     }
0a122b
     return ret;
0a122b
 }
0a122b
@@ -1137,7 +1135,7 @@ void memory_region_reset_dirty(MemoryRegion *mr, hwaddr addr,
0a122b
     assert(mr->terminates);
0a122b
     cpu_physical_memory_reset_dirty(mr->ram_addr + addr,
0a122b
                                     mr->ram_addr + addr + size,
0a122b
-                                    1 << client);
0a122b
+                                    client);
0a122b
 }
0a122b
 
0a122b
 void *memory_region_get_ram_ptr(MemoryRegion *mr)
0a122b
-- 
0a122b
1.7.1
0a122b