Skip to contentSkip to conversation

exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic

PATCH In review Philippe Mathieu-Daudé 6 participants 30 messages May 7, 2020 – May 11, 2020

lore
Share & tools
lore
#0 lore raw

cover exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic

Stefan suggested to make qemu_ram_writeback() target agnostic, Paolo to add memory_region_msync(), and Peter to remove "exec/ram_addr.h" [*].

I let a single function in this file, cpu_physical_memory_sync_dirty_bitmap(), to let the maintainer have the pleasure to remove this header definitively himself :)

Based-on: <[email protected]> "Move Xen accelerator code under accel/xen/"
https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg01722.html

[*] https://www.mail-archive.com/[email protected]/msg66242.html

Philippe Mathieu-Daudé (10):
exec: Rename qemu_ram_writeback() as qemu_ram_msync() exec/ramblock: Add missing 'qemu/rcu.h' include
exec: Move tb_invalidate_phys_range() to 'exec/exec-all.h' exec/memory-internal: Check CONFIG_SOFTMMU instead of CONFIG_USER_ONLY
exec: Move qemu_minrampagesize/qemu_maxrampagesize to 'qemu-common.h'
exec: Move ramblock_recv_bitmap_offset() to migration/ram.c
exec: Move all RAMBlock functions to 'exec/ramblock.h' hw/block: Let the NVMe emulated device be target-agnostic
exec: Update coding style to make checkpatch.pl happy
exec: Move cpu_physical_memory_* functions to 'exec/memory-internal.h'

 include/exec/cpu-common.h      |  24 --
 include/exec/exec-all.h        |  14 +-
 include/exec/memory-internal.h | 307 +++++++++++++++++++++++-
 include/exec/ram_addr.h        | 415 +--------------------------------
 include/exec/ramblock.h        | 135 +++++++++++
 include/qemu-common.h          |  10 +
 migration/migration.h          |   1 +
 accel/tcg/cputlb.c             |   1 -
 accel/tcg/translate-all.c      |   2 -
 exec.c                         |   2 +-
 hw/block/nvme.c                |   5 +-
 hw/ppc/spapr.c                 |   1 -
 hw/ppc/spapr_caps.c            |   2 +-
 hw/ppc/spapr_pci.c             |   1 -
 hw/s390x/s390-stattrib-kvm.c   |   1 -
 hw/s390x/s390-stattrib.c       |   1 -
 hw/s390x/s390-virtio-ccw.c     |   2 +-
 hw/vfio/spapr.c                |   2 +-
 hw/virtio/vhost-user.c         |   1 +
 hw/virtio/vhost.c              |   1 +
 hw/virtio/virtio-balloon.c     |   1 +
 memory.c                       |   4 +-
 migration/migration.c          |   1 +
 migration/postcopy-ram.c       |   1 +
 migration/ram.c                |   8 +
 migration/savevm.c             |   1 +
 stubs/ram-block.c              |   2 +-
 target/ppc/kvm.c               |   1 -
 target/s390x/kvm.c             |   1 -
 util/vfio-helpers.c            |   2 +-
 hw/block/Makefile.objs         |   2 +-
 31 files changed, 485 insertions(+), 467 deletions(-)
Signature · 1 line
2.21.3
#1 lore raw

PATCH 1/10 exec: Rename qemu_ram_writeback() as qemu_ram_msync()

Rename qemu_ram_writeback() as qemu_ram_msync() to better match what it does.

---
 include/exec/ram_addr.h | 4 ++--
 exec.c                  | 2 +-
 hw/block/nvme.c         | 3 +--
 memory.c                | 2 +-
 4 files changed, 5 insertions(+), 6 deletions(-)
include/exec/ram_addr.h +2 -2
index 4e05292f91..7b5c24e928 100644
@@ -136,12 +136,12 @@ void qemu_ram_free(RAMBlock *block);
 
 int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp);
 
-void qemu_ram_writeback(RAMBlock *block, ram_addr_t start, ram_addr_t length);
+void qemu_ram_msync(RAMBlock *block, ram_addr_t start, ram_addr_t length);
 
 /* Clear whole block of mem */
 static inline void qemu_ram_block_writeback(RAMBlock *block)
 {
-    qemu_ram_writeback(block, 0, block->used_length);
+    qemu_ram_msync(block, 0, block->used_length);
 }
 
 #define DIRTY_CLIENTS_ALL     ((1 << DIRTY_MEMORY_NUM) - 1)
exec.c +1 -1
index 2874bb5088..f5a8cdf370 100644
@@ -2127,7 +2127,7 @@ int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp)
  * Otherwise no-op.
  * @Note: this is supposed to be a synchronous op.
  */
-void qemu_ram_writeback(RAMBlock *block, ram_addr_t start, ram_addr_t length)
+void qemu_ram_msync(RAMBlock *block, ram_addr_t start, ram_addr_t length)
 {
     /* The requested range should fit in within the block range */
     g_assert((start + length) <= block->used_length);
hw/block/nvme.c +1 -2
index 9b453423cf..21a199e53b 100644
@@ -1207,8 +1207,7 @@ static uint64_t nvme_mmio_read(void *opaque, hwaddr addr, unsigned size)
          */
         if (addr == 0xE08 &&
             (NVME_PMRCAP_PMRWBM(n->bar.pmrcap) & 0x02)) {
-            qemu_ram_writeback(n->pmrdev->mr.ram_block,
-                               0, n->pmrdev->size);
+            qemu_ram_msync(n->pmrdev->mr.ram_block, 0, n->pmrdev->size);
         }
         memcpy(&val, ptr + addr, size);
     } else {
memory.c +1 -1
index 601b749906..3e65e33ac4 100644
@@ -2205,7 +2205,7 @@ void memory_region_do_writeback(MemoryRegion *mr, hwaddr addr, hwaddr size)
      * different types of memory regions
      */
     if (mr->ram_block && mr->dirty_log_mask) {
-        qemu_ram_writeback(mr->ram_block, addr, size);
+        qemu_ram_msync(mr->ram_block, addr, size);
     }
 }
 
Signature · 1 line
2.21.3
#3 lore raw

PATCH 2/10 exec/ramblock: Add missing 'qemu/rcu.h' include

In reply to Philippe Mathieu-Daudé

The first field of RAMBlock is a rcu_head structure. We need to include the "qemu/rcu.h" to avoid errors when including "exec/ramblock.h" without "qemu/rcu.h":

include/exec/ramblock.h:27:21: error: field ‘rcu’ has incomplete type

     27 |     struct rcu_head rcu;
        |                     ^~~
  include/exec/ramblock.h:39:5: error: expected specifier-qualifier-list before ‘QLIST_ENTRY’
     39 |     QLIST_ENTRY(RAMBlock) next;
        |     ^~~~~~~~~~~
---
 include/exec/ramblock.h | 1 +
 1 file changed, 1 insertion(+)
include/exec/ramblock.h +1 -0
index 07d50864d8..6ac0aa7a89 100644
@@ -21,6 +21,7 @@
 
 #ifndef CONFIG_USER_ONLY
 #include "cpu-common.h"
+#include "qemu/rcu.h"
 
 struct RAMBlock {
     struct rcu_head rcu;
Signature · 1 line
2.21.3
Reviewed-by on v1 2/10
#4 lore raw

Re: [PATCH 02/10] exec/ramblock: Add missing 'qemu/rcu.h' include

Quoted 5 lines · Philippe Mathieu-Daudé

The first field of RAMBlock is a rcu_head structure. We need to include the "qemu/rcu.h" to avoid errors when including "exec/ramblock.h" without "qemu/rcu.h":

include/exec/ramblock.h:27:21: error: field ‘rcu’ has incomplete type

Quoted 8 lines
     27 |     struct rcu_head rcu;
        |                     ^~~
  include/exec/ramblock.h:39:5: error: expected
specifier-qualifier-list before ‘QLIST_ENTRY’
     39 |     QLIST_ENTRY(RAMBlock) next;
        |     ^~~~~~~~~~~
#5 lore raw

PATCH 3/10 exec: Move tb_invalidate_phys_range() to 'exec/exec-all.h'

In reply to Philippe Mathieu-Daudé

Move tb_invalidate_phys_range() to "exec/exec-all.h" with the other TranslationBlock invalidate functions. Move all these functions altogether. Check for the CONFIG_SOFTMMU definition which is more explicit than CONFIG_USER_ONLY.

---
 include/exec/exec-all.h | 14 ++++++++------
 include/exec/ram_addr.h |  2 --
 2 files changed, 8 insertions(+), 8 deletions(-)
include/exec/exec-all.h +8 -6
index 350c4b451b..f1a9b8a576 100644
@@ -454,12 +454,15 @@ static inline uint32_t curr_cflags(void)
 }
 
 /* TranslationBlock invalidate API */
-#if defined(CONFIG_USER_ONLY)
+#ifdef CONFIG_SOFTMMU
+void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs);
+void tb_invalidate_phys_range(ram_addr_t start, ram_addr_t end);
+void tb_flush_jmp_cache(CPUState *cpu, target_ulong addr);
+#else
 void tb_invalidate_phys_addr(target_ulong addr);
 void tb_invalidate_phys_range(target_ulong start, target_ulong end);
-#else
-void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs);
-#endif
+#endif /* CONFIG_SOFTMMU */
+
 void tb_flush(CPUState *cpu);
 void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr);
 TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc,
@@ -583,7 +586,6 @@ void tlb_reset_dirty(CPUState *cpu, ram_addr_t start1, ram_addr_t length);
 void tlb_set_dirty(CPUState *cpu, target_ulong vaddr);
 
 /* exec.c */
-void tb_flush_jmp_cache(CPUState *cpu, target_ulong addr);
 
 MemoryRegionSection *
 address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr addr,
@@ -591,7 +593,7 @@ address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr addr,
                                   MemTxAttrs attrs, int *prot);
 hwaddr memory_region_section_get_iotlb(CPUState *cpu,
                                        MemoryRegionSection *section);
-#endif
+#endif /* CONFIG_USER_ONLY */
 
 /* vl.c */
 extern int singlestep;
include/exec/ram_addr.h +0 -2
index 7b5c24e928..06096e8c6a 100644
@@ -147,8 +147,6 @@ static inline void qemu_ram_block_writeback(RAMBlock *block)
 #define DIRTY_CLIENTS_ALL     ((1 << DIRTY_MEMORY_NUM) - 1)
 #define DIRTY_CLIENTS_NOCODE  (DIRTY_CLIENTS_ALL & ~(1 << DIRTY_MEMORY_CODE))
 
-void tb_invalidate_phys_range(ram_addr_t start, ram_addr_t end);
-
 static inline bool cpu_physical_memory_get_dirty(ram_addr_t start,
                                                  ram_addr_t length,
                                                  unsigned client)
Signature · 1 line
2.21.3
#6 lore raw

PATCH 4/10 exec/memory-internal: Check CONFIG_SOFTMMU instead of CONFIG_USER_ONLY

In reply to Philippe Mathieu-Daudé

The CONFIG_SOFTMMU definition is poisoned in "exec/poison.h". As this header is internal, check for poisoned CONFIG_SOFTMMU instead of CONFIG_USER_ONLY to make this include harder to use.

---
 include/exec/memory-internal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/exec/memory-internal.h +1 -1
index 9fcc2af25c..b2b7c1e78a 100644
@@ -22,7 +22,7 @@
 
 #include "cpu.h"
 
-#ifndef CONFIG_USER_ONLY
+#ifdef CONFIG_SOFTMMU
 static inline AddressSpaceDispatch *flatview_to_dispatch(FlatView *fv)
 {
     return fv->dispatch;
Signature · 1 line
2.21.3
#8 lore raw

PATCH 5/10 exec: Move qemu_minrampagesize/qemu_maxrampagesize to 'qemu-common.h'

In reply to Philippe Mathieu-Daudé

Move these generic functions to a more common place, with other functions related to host page size. Document a little.

---
 include/exec/ram_addr.h    |  3 ---
 include/qemu-common.h      | 10 ++++++++++
 hw/ppc/spapr_caps.c        |  2 +-
 hw/s390x/s390-virtio-ccw.c |  1 +
 hw/vfio/spapr.c            |  2 +-
 5 files changed, 13 insertions(+), 5 deletions(-)
include/exec/ram_addr.h +0 -3
index 06096e8c6a..195b67d3c8 100644
@@ -93,9 +93,6 @@ static inline unsigned long int ramblock_recv_bitmap_offset(void *host_addr,
 
 bool ramblock_is_pmem(RAMBlock *rb);
 
-long qemu_minrampagesize(void);
-long qemu_maxrampagesize(void);
-
 /**
  * qemu_ram_alloc_from_file,
  * qemu_ram_alloc_from_fd:  Allocate a ram block from the specified backing
include/qemu-common.h +10 -0
index d0142f29ac..2821a6ef76 100644
@@ -80,6 +80,16 @@ bool set_preferred_target_page_bits(int bits);
  */
 void finalize_target_page_bits(void);
 
+/**
+ * qemu_minrampagesize:
+ * qemu_maxrampagesize:
+ *
+ * If backed via -memdev, return the device page size,
+ * else return the host kernel page size.
+ */
+long qemu_minrampagesize(void);
+long qemu_maxrampagesize(void);
+
 /**
  * Sends a (part of) iovec down a socket, yielding when the socket is full, or
  * Receives data into a (part of) iovec from a socket,
hw/ppc/spapr_caps.c +1 -1
index eb54f94227..33a802a103 100644
@@ -23,11 +23,11 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu-common.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "qapi/visitor.h"
 #include "sysemu/hw_accel.h"
-#include "exec/ram_addr.h"
 #include "target/ppc/cpu.h"
 #include "target/ppc/mmu-hash64.h"
 #include "cpu-models.h"
hw/s390x/s390-virtio-ccw.c +1 -0
index f660070d22..c009384505 100644
@@ -12,6 +12,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu-common.h"
 #include "qapi/error.h"
 #include "cpu.h"
 #include "hw/boards.h"
hw/vfio/spapr.c +1 -1
index 2900bd1941..c64db940a7 100644
@@ -9,13 +9,13 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu-common.h"
 #include "cpu.h"
 #include <sys/ioctl.h>
 #include <linux/vfio.h>
 
 #include "hw/vfio/vfio-common.h"
 #include "hw/hw.h"
-#include "exec/ram_addr.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "trace.h"
Signature · 1 line
2.21.3
Acked-by on v1 5/10
#10 lore raw

Re: [PATCH 05/10] exec: Move qemu_minrampagesize/qemu_maxrampagesize to 'qemu-common.h'

In reply to Philippe Mathieu-Daudé
Quoted 5 lines · On Thu, 7 May 2020 19:39:53 +0200 Philippe Mathieu-Daudé <[email protected]>…

Move these generic functions to a more common place, with other functions related to host page size. Document a little.

Quoted 7 lines
---
 include/exec/ram_addr.h    |  3 ---
 include/qemu-common.h      | 10 ++++++++++
 hw/ppc/spapr_caps.c        |  2 +-
 hw/s390x/s390-virtio-ccw.c |  1 +
 hw/vfio/spapr.c            |  2 +-
 5 files changed, 13 insertions(+), 5 deletions(-)
Acked-by on v1 5/10
#11 lore raw

Re: [PATCH 05/10] exec: Move qemu_minrampagesize/qemu_maxrampagesize to 'qemu-common.h'

In reply to Philippe Mathieu-Daudé
Quoted 5 lines · Philippe Mathieu-Daudé

Move these generic functions to a more common place, with other functions related to host page size. Document a little.

ppc parts

Quoted 91 lines
---
 include/exec/ram_addr.h    |  3 ---
 include/qemu-common.h      | 10 ++++++++++
 hw/ppc/spapr_caps.c        |  2 +-
 hw/s390x/s390-virtio-ccw.c |  1 +
 hw/vfio/spapr.c            |  2 +-
 5 files changed, 13 insertions(+), 5 deletions(-)
include/exec/ram_addr.h +0 -3
index 06096e8c6a..195b67d3c8 100644
@@ -93,9 +93,6 @@ static inline unsigned long int ramblock_recv_bitmap_offset(void *host_addr,
 
 bool ramblock_is_pmem(RAMBlock *rb);
 
-long qemu_minrampagesize(void);
-long qemu_maxrampagesize(void);
-
 /**
  * qemu_ram_alloc_from_file,
  * qemu_ram_alloc_from_fd:  Allocate a ram block from the specified backing
include/qemu-common.h +10 -0
index d0142f29ac..2821a6ef76 100644
@@ -80,6 +80,16 @@ bool set_preferred_target_page_bits(int bits);
  */
 void finalize_target_page_bits(void);
 
+/**
+ * qemu_minrampagesize:
+ * qemu_maxrampagesize:
+ *
+ * If backed via -memdev, return the device page size,
+ * else return the host kernel page size.
+ */
+long qemu_minrampagesize(void);
+long qemu_maxrampagesize(void);
+
 /**
  * Sends a (part of) iovec down a socket, yielding when the socket is full, or
  * Receives data into a (part of) iovec from a socket,
hw/ppc/spapr_caps.c +1 -1
index eb54f94227..33a802a103 100644
@@ -23,11 +23,11 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu-common.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "qapi/visitor.h"
 #include "sysemu/hw_accel.h"
-#include "exec/ram_addr.h"
 #include "target/ppc/cpu.h"
 #include "target/ppc/mmu-hash64.h"
 #include "cpu-models.h"
hw/s390x/s390-virtio-ccw.c +1 -0
index f660070d22..c009384505 100644
@@ -12,6 +12,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu-common.h"
 #include "qapi/error.h"
 #include "cpu.h"
 #include "hw/boards.h"
hw/vfio/spapr.c +1 -1
index 2900bd1941..c64db940a7 100644
@@ -9,13 +9,13 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu-common.h"
 #include "cpu.h"
 #include <sys/ioctl.h>
 #include <linux/vfio.h>
 
 #include "hw/vfio/vfio-common.h"
 #include "hw/hw.h"
-#include "exec/ram_addr.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "trace.h"
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#12 lore raw

PATCH 6/10 exec: Move ramblock_recv_bitmap_offset() to migration/ram.c

In reply to Philippe Mathieu-Daudé

The ramblock_recv_bitmap_offset() function is only used once in migration/ram.c, move it there.

---
 include/exec/ram_addr.h | 8 --------
 migration/ram.c         | 8 ++++++++
 2 files changed, 8 insertions(+), 8 deletions(-)
include/exec/ram_addr.h +0 -8
index 195b67d3c8..c61d5188f7 100644
@@ -83,14 +83,6 @@ static inline void *ramblock_ptr(RAMBlock *block, ram_addr_t offset)
     return (char *)block->host + offset;
 }
 
-static inline unsigned long int ramblock_recv_bitmap_offset(void *host_addr,
-                                                            RAMBlock *rb)
-{
-    uint64_t host_addr_offset =
-            (uint64_t)(uintptr_t)(host_addr - (void *)rb->host);
-    return host_addr_offset >> TARGET_PAGE_BITS;
-}
-
 bool ramblock_is_pmem(RAMBlock *rb);
 
 /**
migration/ram.c +8 -0
index 53166fc279..0cd16d0519 100644
@@ -190,6 +190,14 @@ int foreach_not_ignored_block(RAMBlockIterFunc func, void *opaque)
     return ret;
 }
 
+static inline unsigned long int ramblock_recv_bitmap_offset(void *host_addr,
+                                                            RAMBlock *rb)
+{
+    uint64_t host_addr_offset =
+            (uint64_t)(uintptr_t)(host_addr - (void *)rb->host);
+    return host_addr_offset >> TARGET_PAGE_BITS;
+}
+
 static void ramblock_recv_map_init(void)
 {
     RAMBlock *rb;
Signature · 1 line
2.21.3
Reviewed-by on v1 6/10
#13 lore raw

Re: [PATCH 06/10] exec: Move ramblock_recv_bitmap_offset() to migration/ram.c

Quoted 4 lines · Philippe Mathieu-Daudé

The ramblock_recv_bitmap_offset() function is only used once in migration/ram.c, move it there.

But, if you are in the mood:

migration/ram.c int foreach_not_ignored_block(RAMBlockIterFunc func, void *opaque) · line 198

Quoted 8 lines

}

migration/ram.c +6 -0
+static inline unsigned long int ramblock_recv_bitmap_offset(void *host_addr,
+                                                            RAMBlock *rb)
+{
+    uint64_t host_addr_offset =
+            (uint64_t)(uintptr_t)(host_addr - (void *)rb->host);
+    return host_addr_offset >> TARGET_PAGE_BITS;
                                  ^^^^^^^^^^^^^^^^

That should be qemu_target_page_bits().

We are trying (not there yet) that migration code is target independent, this TARGET constant are one of the problems (not the only one, thought).

And yes, I know that this file has both the function and the constant, sniff.

Later, Juan.

#14 lore raw

Re: [PATCH 06/10] exec: Move ramblock_recv_bitmap_offset() to migration/ram.c

Quoted 20 lines · Juan Quintela
Quoted 4 lines · Philippe Mathieu-Daudé

The ramblock_recv_bitmap_offset() function is only used once in migration/ram.c, move it there.

But, if you are in the mood:

migration/ram.c int foreach_not_ignored_block(RAMBlockIterFunc func, void *opaque) · line 198

Quoted 8 lines
  }
migration/ram.c +6 -0
+static inline unsigned long int ramblock_recv_bitmap_offset(void *host_addr,
+                                                            RAMBlock *rb)
+{
+    uint64_t host_addr_offset =
+            (uint64_t)(uintptr_t)(host_addr - (void *)rb->host);
+    return host_addr_offset >> TARGET_PAGE_BITS;
                                   ^^^^^^^^^^^^^^^^
Quoted 1 line

That should be qemu_target_page_bits().

Ah! I've been looking for this function :)

Quoted 4 lines

We are trying (not there yet) that migration code is target independent, this TARGET constant are one of the problems (not the only one, thought).

Good.

Quoted 6 lines

And yes, I know that this file has both the function and the constant, sniff.

Later, Juan.

#15 lore raw

PATCH 7/10 exec: Move all RAMBlock functions to 'exec/ramblock.h'

In reply to Philippe Mathieu-Daudé

The RAMBlock API was dispersed in 3 different headers. One of these headers, "exec/ram_addr.h", is restricted to target dependent code. However these functions are not target specific. Move all functions into a single place. Now all these functions can be accessed by target-agnostic code.

---
 include/exec/cpu-common.h    |  24 -------
 include/exec/ram_addr.h      | 105 ---------------------------
 include/exec/ramblock.h      | 134 +++++++++++++++++++++++++++++++++++
 migration/migration.h        |   1 +
 accel/tcg/translate-all.c    |   2 -
 hw/block/nvme.c              |   2 +-
 hw/s390x/s390-stattrib-kvm.c |   1 -
 hw/s390x/s390-stattrib.c     |   1 -
 hw/s390x/s390-virtio-ccw.c   |   1 -
 hw/virtio/vhost-user.c       |   1 +
 hw/virtio/vhost.c            |   1 +
 hw/virtio/virtio-balloon.c   |   1 +
 memory.c                     |   1 +
 migration/migration.c        |   1 +
 migration/postcopy-ram.c     |   1 +
 migration/savevm.c           |   1 +
 stubs/ram-block.c            |   2 +-
 target/ppc/kvm.c             |   1 -
 target/s390x/kvm.c           |   1 -
 util/vfio-helpers.c          |   2 +-
 20 files changed, 145 insertions(+), 139 deletions(-)
include/exec/cpu-common.h +0 -24
index b47e5630e7..347ceb603b 100644
@@ -49,25 +49,6 @@ typedef uint32_t CPUReadMemoryFunc(void *opaque, hwaddr addr);
 void qemu_ram_remap(ram_addr_t addr, ram_addr_t length);
 /* This should not be used by devices.  */
 ram_addr_t qemu_ram_addr_from_host(void *ptr);
-RAMBlock *qemu_ram_block_by_name(const char *name);
-RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,
-                                   ram_addr_t *offset);
-ram_addr_t qemu_ram_block_host_offset(RAMBlock *rb, void *host);
-void qemu_ram_set_idstr(RAMBlock *block, const char *name, DeviceState *dev);
-void qemu_ram_unset_idstr(RAMBlock *block);
-const char *qemu_ram_get_idstr(RAMBlock *rb);
-void *qemu_ram_get_host_addr(RAMBlock *rb);
-ram_addr_t qemu_ram_get_offset(RAMBlock *rb);
-ram_addr_t qemu_ram_get_used_length(RAMBlock *rb);
-bool qemu_ram_is_shared(RAMBlock *rb);
-bool qemu_ram_is_uf_zeroable(RAMBlock *rb);
-void qemu_ram_set_uf_zeroable(RAMBlock *rb);
-bool qemu_ram_is_migratable(RAMBlock *rb);
-void qemu_ram_set_migratable(RAMBlock *rb);
-void qemu_ram_unset_migratable(RAMBlock *rb);
-
-size_t qemu_ram_pagesize(RAMBlock *block);
-size_t qemu_ram_pagesize_largest(void);
 
 void cpu_physical_memory_rw(hwaddr addr, void *buf,
                             hwaddr len, bool is_write);
@@ -100,11 +81,6 @@ void qemu_flush_coalesced_mmio_buffer(void);
 
 void cpu_flush_icache_range(hwaddr start, hwaddr len);
 
-typedef int (RAMBlockIterFunc)(RAMBlock *rb, void *opaque);
-
-int qemu_ram_foreach_block(RAMBlockIterFunc func, void *opaque);
-int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length);
-
 #endif
 
 #endif /* CPU_COMMON_H */
include/exec/ram_addr.h +0 -105

112 lines not on this page · raw message

include/exec/ramblock.h +134 -0

145 lines not on this page · raw message

migration/migration.h +1 -0
index 507284e563..73eb210ef5 100644
@@ -21,6 +21,7 @@
 #include "qemu/coroutine_int.h"
 #include "io/channel.h"
 #include "net/announce.h"
+#include "exec/ramblock.h"
 
 struct PostcopyBlocktimeContext;
 
accel/tcg/translate-all.c +0 -2
index 9924e66d1f..15c8ee9110 100644
@@ -43,8 +43,6 @@
 #include <libutil.h>
 #endif
 #endif
-#else
-#include "exec/ram_addr.h"
 #endif
 
 #include "exec/cputlb.h"
hw/block/nvme.c +1 -1
index 21a199e53b..8d8dd7ce80 100644
@@ -46,7 +46,7 @@
 #include "qapi/visitor.h"
 #include "sysemu/hostmem.h"
 #include "sysemu/block-backend.h"
-#include "exec/ram_addr.h"
+#include "exec/ramblock.h"
 
 #include "qemu/log.h"
 #include "qemu/module.h"
hw/s390x/s390-stattrib-kvm.c +0 -1
index f89d8d9d16..46ca7e7d1f 100644
@@ -15,7 +15,6 @@
 #include "hw/s390x/storage-attributes.h"
 #include "qemu/error-report.h"
 #include "sysemu/kvm.h"
-#include "exec/ram_addr.h"
 #include "cpu.h"
 #include "kvm_s390x.h"
 
hw/s390x/s390-stattrib.c +0 -1
index 58121b9f68..9785d51577 100644
@@ -16,7 +16,6 @@
 #include "migration/register.h"
 #include "hw/s390x/storage-attributes.h"
 #include "qemu/error-report.h"
-#include "exec/ram_addr.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
 
hw/s390x/s390-virtio-ccw.c +0 -1
index c009384505..ade36eda5e 100644
@@ -17,7 +17,6 @@
 #include "cpu.h"
 #include "hw/boards.h"
 #include "exec/address-spaces.h"
-#include "exec/ram_addr.h"
 #include "hw/s390x/s390-virtio-hcall.h"
 #include "hw/s390x/sclp.h"
 #include "hw/s390x/s390_flic.h"
hw/virtio/vhost-user.c +1 -0
index ec21e8fbe8..12764d6254 100644
@@ -23,6 +23,7 @@
 #include "sysemu/cryptodev.h"
 #include "migration/migration.h"
 #include "migration/postcopy-ram.h"
+#include "exec/ramblock.h"
 #include "trace.h"
 
 #include <sys/ioctl.h>
hw/virtio/vhost.c +1 -0
index aff98a0ede..7da8d95a43 100644
@@ -22,6 +22,7 @@
 #include "qemu/memfd.h"
 #include "standard-headers/linux/vhost_types.h"
 #include "exec/address-spaces.h"
+#include "exec/ramblock.h"
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-access.h"
 #include "migration/blocker.h"
hw/virtio/virtio-balloon.c +1 -0
index a4729f7fc9..ea112e9403 100644
@@ -23,6 +23,7 @@
 #include "sysemu/balloon.h"
 #include "hw/virtio/virtio-balloon.h"
 #include "exec/address-spaces.h"
+#include "exec/ramblock.h"
 #include "qapi/error.h"
 #include "qapi/qapi-events-misc.h"
 #include "qapi/visitor.h"
memory.c +1 -0
index 3e65e33ac4..e8e7bcd6c7 100644
@@ -28,6 +28,7 @@
 
 #include "exec/memory-internal.h"
 #include "exec/ram_addr.h"
+#include "exec/ramblock.h"
 #include "sysemu/kvm.h"
 #include "sysemu/runstate.h"
 #include "sysemu/tcg.h"
migration/migration.c +1 -0
index 177cce9e95..8c7ed8cc79 100644
@@ -46,6 +46,7 @@
 #include "qemu/thread.h"
 #include "trace.h"
 #include "exec/target_page.h"
+#include "exec/ramblock.h"
 #include "io/channel-buffer.h"
 #include "migration/colo.h"
 #include "hw/boards.h"
migration/postcopy-ram.c +1 -0
index a36402722b..78646abf7a 100644
@@ -18,6 +18,7 @@
 
 #include "qemu/osdep.h"
 #include "exec/target_page.h"
+#include "exec/ramblock.h"
 #include "migration.h"
 #include "qemu-file.h"
 #include "savevm.h"
migration/savevm.c +1 -0
index b979ea6e7f..714b5b4591 100644
@@ -48,6 +48,7 @@
 #include "sysemu/cpus.h"
 #include "exec/memory.h"
 #include "exec/target_page.h"
+#include "exec/ramblock.h"
 #include "trace.h"
 #include "qemu/iov.h"
 #include "qemu/main-loop.h"
stubs/ram-block.c +1 -1
index 73c0a3ee08..9e73543598 100644
@@ -1,6 +1,6 @@
 #include "qemu/osdep.h"
 #include "exec/ramlist.h"
-#include "exec/cpu-common.h"
+#include "exec/ramblock.h"
 
 void *qemu_ram_get_host_addr(RAMBlock *rb)
 {
target/ppc/kvm.c +0 -1
index 2692f76130..1f3db517db 100644
@@ -43,7 +43,6 @@
 #include "trace.h"
 #include "exec/gdbstub.h"
 #include "exec/memattrs.h"
-#include "exec/ram_addr.h"
 #include "sysemu/hostmem.h"
 #include "qemu/cutils.h"
 #include "qemu/main-loop.h"
target/s390x/kvm.c +0 -1
index 69881a0da0..42657bc0a5 100644
@@ -41,7 +41,6 @@
 #include "sysemu/runstate.h"
 #include "sysemu/device_tree.h"
 #include "exec/gdbstub.h"
-#include "exec/ram_addr.h"
 #include "trace.h"
 #include "hw/s390x/s390-pci-inst.h"
 #include "hw/s390x/s390-pci-bus.h"
util/vfio-helpers.c +1 -1
index e399e330e2..2ee169da58 100644
@@ -15,7 +15,7 @@
 #include <linux/vfio.h>
 #include "qapi/error.h"
 #include "exec/ramlist.h"
-#include "exec/cpu-common.h"
+#include "exec/ramblock.h"
 #include "trace.h"
 #include "qemu/error-report.h"
 #include "standard-headers/linux/pci_regs.h"
Signature · 1 line
2.21.3
Reviewed-by on v1 7/10
#16 lore raw

Re: [PATCH 07/10] exec: Move all RAMBlock functions to 'exec/ramblock.h'

Quoted 8 lines · Philippe Mathieu-Daudé

The RAMBlock API was dispersed in 3 different headers. One of these headers, "exec/ram_addr.h", is restricted to target dependent code. However these functions are not target specific. Move all functions into a single place. Now all these functions can be accessed by target-agnostic code.

Very nice of you doing this, Thanks.

Acked-by on v1 7/10
#17 lore raw

Re: [PATCH 07/10] exec: Move all RAMBlock functions to 'exec/ramblock.h'

In reply to Philippe Mathieu-Daudé
Quoted 22 lines · On Thu, 7 May 2020 19:39:55 +0200 Philippe Mathieu-Daudé <[email protected]>…

The RAMBlock API was dispersed in 3 different headers. One of these headers, "exec/ram_addr.h", is restricted to target dependent code. However these functions are not target specific. Move all functions into a single place. Now all these functions can be accessed by target-agnostic code.

---
 include/exec/cpu-common.h    |  24 -------
 include/exec/ram_addr.h      | 105 ---------------------------
 include/exec/ramblock.h      | 134 +++++++++++++++++++++++++++++++++++
 migration/migration.h        |   1 +
 accel/tcg/translate-all.c    |   2 -
 hw/block/nvme.c              |   2 +-
 hw/s390x/s390-stattrib-kvm.c |   1 -
 hw/s390x/s390-stattrib.c     |   1 -
 hw/s390x/s390-virtio-ccw.c   |   1 -
 hw/virtio/vhost-user.c       |   1 +
 hw/virtio/vhost.c            |   1 +
 hw/virtio/virtio-balloon.c   |   1 +
 memory.c                     |   1 +
Quoted 8 lines
 migration/migration.c        |   1 +
 migration/postcopy-ram.c     |   1 +
 migration/savevm.c           |   1 +
 stubs/ram-block.c            |   2 +-
 target/ppc/kvm.c             |   1 -
 target/s390x/kvm.c           |   1 -
 util/vfio-helpers.c          |   2 +-
 20 files changed, 145 insertions(+), 139 deletions(-)
Acked-by on v1 7/10
#18 lore raw

Re: [PATCH 07/10] exec: Move all RAMBlock functions to 'exec/ramblock.h'

In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

The RAMBlock API was dispersed in 3 different headers. One of these headers, "exec/ram_addr.h", is restricted to target dependent code. However these functions are not target specific. Move all functions into a single place. Now all these functions can be accessed by target-agnostic code.

ppc parts

Quoted 540 lines
---
 include/exec/cpu-common.h    |  24 -------
 include/exec/ram_addr.h      | 105 ---------------------------
 include/exec/ramblock.h      | 134 +++++++++++++++++++++++++++++++++++
 migration/migration.h        |   1 +
 accel/tcg/translate-all.c    |   2 -
 hw/block/nvme.c              |   2 +-
 hw/s390x/s390-stattrib-kvm.c |   1 -
 hw/s390x/s390-stattrib.c     |   1 -
 hw/s390x/s390-virtio-ccw.c   |   1 -
 hw/virtio/vhost-user.c       |   1 +
 hw/virtio/vhost.c            |   1 +
 hw/virtio/virtio-balloon.c   |   1 +
 memory.c                     |   1 +
 migration/migration.c        |   1 +
 migration/postcopy-ram.c     |   1 +
 migration/savevm.c           |   1 +
 stubs/ram-block.c            |   2 +-
 target/ppc/kvm.c             |   1 -
 target/s390x/kvm.c           |   1 -
 util/vfio-helpers.c          |   2 +-
 20 files changed, 145 insertions(+), 139 deletions(-)
include/exec/cpu-common.h +0 -24
index b47e5630e7..347ceb603b 100644
@@ -49,25 +49,6 @@ typedef uint32_t CPUReadMemoryFunc(void *opaque, hwaddr addr);
 void qemu_ram_remap(ram_addr_t addr, ram_addr_t length);
 /* This should not be used by devices.  */
 ram_addr_t qemu_ram_addr_from_host(void *ptr);
-RAMBlock *qemu_ram_block_by_name(const char *name);
-RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,
-                                   ram_addr_t *offset);
-ram_addr_t qemu_ram_block_host_offset(RAMBlock *rb, void *host);
-void qemu_ram_set_idstr(RAMBlock *block, const char *name, DeviceState *dev);
-void qemu_ram_unset_idstr(RAMBlock *block);
-const char *qemu_ram_get_idstr(RAMBlock *rb);
-void *qemu_ram_get_host_addr(RAMBlock *rb);
-ram_addr_t qemu_ram_get_offset(RAMBlock *rb);
-ram_addr_t qemu_ram_get_used_length(RAMBlock *rb);
-bool qemu_ram_is_shared(RAMBlock *rb);
-bool qemu_ram_is_uf_zeroable(RAMBlock *rb);
-void qemu_ram_set_uf_zeroable(RAMBlock *rb);
-bool qemu_ram_is_migratable(RAMBlock *rb);
-void qemu_ram_set_migratable(RAMBlock *rb);
-void qemu_ram_unset_migratable(RAMBlock *rb);
-
-size_t qemu_ram_pagesize(RAMBlock *block);
-size_t qemu_ram_pagesize_largest(void);
 
 void cpu_physical_memory_rw(hwaddr addr, void *buf,
                             hwaddr len, bool is_write);
@@ -100,11 +81,6 @@ void qemu_flush_coalesced_mmio_buffer(void);
 
 void cpu_flush_icache_range(hwaddr start, hwaddr len);
 
-typedef int (RAMBlockIterFunc)(RAMBlock *rb, void *opaque);
-
-int qemu_ram_foreach_block(RAMBlockIterFunc func, void *opaque);
-int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length);
-
 #endif
 
 #endif /* CPU_COMMON_H */
include/exec/ram_addr.h +0 -105
index c61d5188f7..0deffad66f 100644
@@ -26,112 +26,7 @@
 #include "exec/ramlist.h"
 #include "exec/ramblock.h"
 
-/**
- * clear_bmap_size: calculate clear bitmap size
- *
- * @pages: number of guest pages
- * @shift: guest page number shift
- *
- * Returns: number of bits for the clear bitmap
- */
-static inline long clear_bmap_size(uint64_t pages, uint8_t shift)
-{
-    return DIV_ROUND_UP(pages, 1UL << shift);
-}
 
-/**
- * clear_bmap_set: set clear bitmap for the page range
- *
- * @rb: the ramblock to operate on
- * @start: the start page number
- * @size: number of pages to set in the bitmap
- *
- * Returns: None
- */
-static inline void clear_bmap_set(RAMBlock *rb, uint64_t start,
-                                  uint64_t npages)
-{
-    uint8_t shift = rb->clear_bmap_shift;
-
-    bitmap_set_atomic(rb->clear_bmap, start >> shift,
-                      clear_bmap_size(npages, shift));
-}
-
-/**
- * clear_bmap_test_and_clear: test clear bitmap for the page, clear if set
- *
- * @rb: the ramblock to operate on
- * @page: the page number to check
- *
- * Returns: true if the bit was set, false otherwise
- */
-static inline bool clear_bmap_test_and_clear(RAMBlock *rb, uint64_t page)
-{
-    uint8_t shift = rb->clear_bmap_shift;
-
-    return bitmap_test_and_clear_atomic(rb->clear_bmap, page >> shift, 1);
-}
-
-static inline bool offset_in_ramblock(RAMBlock *b, ram_addr_t offset)
-{
-    return (b && b->host && offset < b->used_length) ? true : false;
-}
-
-static inline void *ramblock_ptr(RAMBlock *block, ram_addr_t offset)
-{
-    assert(offset_in_ramblock(block, offset));
-    return (char *)block->host + offset;
-}
-
-bool ramblock_is_pmem(RAMBlock *rb);
-
-/**
- * qemu_ram_alloc_from_file,
- * qemu_ram_alloc_from_fd:  Allocate a ram block from the specified backing
- *                          file or device
- *
- * Parameters:
- *  @size: the size in bytes of the ram block
- *  @mr: the memory region where the ram block is
- *  @ram_flags: specify the properties of the ram block, which can be one
- *              or bit-or of following values
- *              - RAM_SHARED: mmap the backing file or device with MAP_SHARED
- *              - RAM_PMEM: the backend @mem_path or @fd is persistent memory
- *              Other bits are ignored.
- *  @mem_path or @fd: specify the backing file or device
- *  @errp: pointer to Error*, to store an error if it happens
- *
- * Return:
- *  On success, return a pointer to the ram block.
- *  On failure, return NULL.
- */
-RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
-                                   uint32_t ram_flags, const char *mem_path,
-                                   Error **errp);
-RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
-                                 uint32_t ram_flags, int fd,
-                                 Error **errp);
-
-RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
-                                  MemoryRegion *mr, Error **errp);
-RAMBlock *qemu_ram_alloc(ram_addr_t size, bool share, MemoryRegion *mr,
-                         Error **errp);
-RAMBlock *qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t max_size,
-                                    void (*resized)(const char*,
-                                                    uint64_t length,
-                                                    void *host),
-                                    MemoryRegion *mr, Error **errp);
-void qemu_ram_free(RAMBlock *block);
-
-int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp);
-
-void qemu_ram_msync(RAMBlock *block, ram_addr_t start, ram_addr_t length);
-
-/* Clear whole block of mem */
-static inline void qemu_ram_block_writeback(RAMBlock *block)
-{
-    qemu_ram_msync(block, 0, block->used_length);
-}
 
 #define DIRTY_CLIENTS_ALL     ((1 << DIRTY_MEMORY_NUM) - 1)
 #define DIRTY_CLIENTS_NOCODE  (DIRTY_CLIENTS_ALL & ~(1 << DIRTY_MEMORY_CODE))
include/exec/ramblock.h +134 -0
index 6ac0aa7a89..b6b34141fc 100644
@@ -22,6 +22,7 @@
 #ifndef CONFIG_USER_ONLY
 #include "cpu-common.h"
 #include "qemu/rcu.h"
+#include "qemu/bitmap.h"
 
 struct RAMBlock {
     struct rcu_head rcu;
@@ -61,5 +62,138 @@ struct RAMBlock {
     unsigned long *clear_bmap;
     uint8_t clear_bmap_shift;
 };
+
+RAMBlock *qemu_ram_block_by_name(const char *name);
+RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,
+                                   ram_addr_t *offset);
+ram_addr_t qemu_ram_block_host_offset(RAMBlock *rb, void *host);
+void qemu_ram_set_idstr(RAMBlock *block, const char *name, DeviceState *dev);
+void qemu_ram_unset_idstr(RAMBlock *block);
+const char *qemu_ram_get_idstr(RAMBlock *rb);
+void *qemu_ram_get_host_addr(RAMBlock *rb);
+ram_addr_t qemu_ram_get_offset(RAMBlock *rb);
+ram_addr_t qemu_ram_get_used_length(RAMBlock *rb);
+bool qemu_ram_is_shared(RAMBlock *rb);
+bool qemu_ram_is_uf_zeroable(RAMBlock *rb);
+void qemu_ram_set_uf_zeroable(RAMBlock *rb);
+bool qemu_ram_is_migratable(RAMBlock *rb);
+void qemu_ram_set_migratable(RAMBlock *rb);
+void qemu_ram_unset_migratable(RAMBlock *rb);
+
+size_t qemu_ram_pagesize(RAMBlock *block);
+size_t qemu_ram_pagesize_largest(void);
+
+/**
+ * clear_bmap_size: calculate clear bitmap size
+ *
+ * @pages: number of guest pages
+ * @shift: guest page number shift
+ *
+ * Returns: number of bits for the clear bitmap
+ */
+static inline long clear_bmap_size(uint64_t pages, uint8_t shift)
+{
+    return DIV_ROUND_UP(pages, 1UL << shift);
+}
+
+/**
+ * clear_bmap_set: set clear bitmap for the page range
+ *
+ * @rb: the ramblock to operate on
+ * @start: the start page number
+ * @size: number of pages to set in the bitmap
+ *
+ * Returns: None
+ */
+static inline void clear_bmap_set(RAMBlock *rb, uint64_t start,
+                                  uint64_t npages)
+{
+    uint8_t shift = rb->clear_bmap_shift;
+
+    bitmap_set_atomic(rb->clear_bmap, start >> shift,
+                      clear_bmap_size(npages, shift));
+}
+
+/**
+ * clear_bmap_test_and_clear: test clear bitmap for the page, clear if set
+ *
+ * @rb: the ramblock to operate on
+ * @page: the page number to check
+ *
+ * Returns: true if the bit was set, false otherwise
+ */
+static inline bool clear_bmap_test_and_clear(RAMBlock *rb, uint64_t page)
+{
+    uint8_t shift = rb->clear_bmap_shift;
+
+    return bitmap_test_and_clear_atomic(rb->clear_bmap, page >> shift, 1);
+}
+
+static inline bool offset_in_ramblock(RAMBlock *b, ram_addr_t offset)
+{
+    return (b && b->host && offset < b->used_length) ? true : false;
+}
+
+static inline void *ramblock_ptr(RAMBlock *block, ram_addr_t offset)
+{
+    assert(offset_in_ramblock(block, offset));
+    return (char *)block->host + offset;
+}
+
+bool ramblock_is_pmem(RAMBlock *rb);
+
+/**
+ * qemu_ram_alloc_from_file,
+ * qemu_ram_alloc_from_fd:  Allocate a ram block from the specified backing
+ *                          file or device
+ *
+ * Parameters:
+ *  @size: the size in bytes of the ram block
+ *  @mr: the memory region where the ram block is
+ *  @ram_flags: specify the properties of the ram block, which can be one
+ *              or bit-or of following values
+ *              - RAM_SHARED: mmap the backing file or device with MAP_SHARED
+ *              - RAM_PMEM: the backend @mem_path or @fd is persistent memory
+ *              Other bits are ignored.
+ *  @mem_path or @fd: specify the backing file or device
+ *  @errp: pointer to Error*, to store an error if it happens
+ *
+ * Return:
+ *  On success, return a pointer to the ram block.
+ *  On failure, return NULL.
+ */
+RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
+                                   uint32_t ram_flags, const char *mem_path,
+                                   Error **errp);
+RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
+                                 uint32_t ram_flags, int fd,
+                                 Error **errp);
+
+RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
+                                  MemoryRegion *mr, Error **errp);
+RAMBlock *qemu_ram_alloc(ram_addr_t size, bool share, MemoryRegion *mr,
+                         Error **errp);
+RAMBlock *qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t max_size,
+                                    void (*resized)(const char*,
+                                                    uint64_t length,
+                                                    void *host),
+                                    MemoryRegion *mr, Error **errp);
+void qemu_ram_free(RAMBlock *block);
+
+int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp);
+
+void qemu_ram_msync(RAMBlock *block, ram_addr_t start, ram_addr_t length);
+
+/* Clear whole block of mem */
+static inline void qemu_ram_block_writeback(RAMBlock *block)
+{
+    qemu_ram_msync(block, 0, block->used_length);
+}
+
+typedef int (RAMBlockIterFunc)(RAMBlock *rb, void *opaque);
+
+int qemu_ram_foreach_block(RAMBlockIterFunc func, void *opaque);
+int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length);
+
 #endif
 #endif
migration/migration.h +1 -0
index 507284e563..73eb210ef5 100644
@@ -21,6 +21,7 @@
 #include "qemu/coroutine_int.h"
 #include "io/channel.h"
 #include "net/announce.h"
+#include "exec/ramblock.h"
 
 struct PostcopyBlocktimeContext;
 
accel/tcg/translate-all.c +0 -2
index 9924e66d1f..15c8ee9110 100644
@@ -43,8 +43,6 @@
 #include <libutil.h>
 #endif
 #endif
-#else
-#include "exec/ram_addr.h"
 #endif
 
 #include "exec/cputlb.h"
hw/block/nvme.c +1 -1
index 21a199e53b..8d8dd7ce80 100644
@@ -46,7 +46,7 @@
 #include "qapi/visitor.h"
 #include "sysemu/hostmem.h"
 #include "sysemu/block-backend.h"
-#include "exec/ram_addr.h"
+#include "exec/ramblock.h"
 
 #include "qemu/log.h"
 #include "qemu/module.h"
hw/s390x/s390-stattrib-kvm.c +0 -1
index f89d8d9d16..46ca7e7d1f 100644
@@ -15,7 +15,6 @@
 #include "hw/s390x/storage-attributes.h"
 #include "qemu/error-report.h"
 #include "sysemu/kvm.h"
-#include "exec/ram_addr.h"
 #include "cpu.h"
 #include "kvm_s390x.h"
 
hw/s390x/s390-stattrib.c +0 -1
index 58121b9f68..9785d51577 100644
@@ -16,7 +16,6 @@
 #include "migration/register.h"
 #include "hw/s390x/storage-attributes.h"
 #include "qemu/error-report.h"
-#include "exec/ram_addr.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
 
hw/s390x/s390-virtio-ccw.c +0 -1
index c009384505..ade36eda5e 100644
@@ -17,7 +17,6 @@
 #include "cpu.h"
 #include "hw/boards.h"
 #include "exec/address-spaces.h"
-#include "exec/ram_addr.h"
 #include "hw/s390x/s390-virtio-hcall.h"
 #include "hw/s390x/sclp.h"
 #include "hw/s390x/s390_flic.h"
hw/virtio/vhost-user.c +1 -0
index ec21e8fbe8..12764d6254 100644
@@ -23,6 +23,7 @@
 #include "sysemu/cryptodev.h"
 #include "migration/migration.h"
 #include "migration/postcopy-ram.h"
+#include "exec/ramblock.h"
 #include "trace.h"
 
 #include <sys/ioctl.h>
hw/virtio/vhost.c +1 -0
index aff98a0ede..7da8d95a43 100644
@@ -22,6 +22,7 @@
 #include "qemu/memfd.h"
 #include "standard-headers/linux/vhost_types.h"
 #include "exec/address-spaces.h"
+#include "exec/ramblock.h"
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-access.h"
 #include "migration/blocker.h"
hw/virtio/virtio-balloon.c +1 -0
index a4729f7fc9..ea112e9403 100644
@@ -23,6 +23,7 @@
 #include "sysemu/balloon.h"
 #include "hw/virtio/virtio-balloon.h"
 #include "exec/address-spaces.h"
+#include "exec/ramblock.h"
 #include "qapi/error.h"
 #include "qapi/qapi-events-misc.h"
 #include "qapi/visitor.h"
memory.c +1 -0
index 3e65e33ac4..e8e7bcd6c7 100644
@@ -28,6 +28,7 @@
 
 #include "exec/memory-internal.h"
 #include "exec/ram_addr.h"
+#include "exec/ramblock.h"
 #include "sysemu/kvm.h"
 #include "sysemu/runstate.h"
 #include "sysemu/tcg.h"
migration/migration.c +1 -0
index 177cce9e95..8c7ed8cc79 100644
@@ -46,6 +46,7 @@
 #include "qemu/thread.h"
 #include "trace.h"
 #include "exec/target_page.h"
+#include "exec/ramblock.h"
 #include "io/channel-buffer.h"
 #include "migration/colo.h"
 #include "hw/boards.h"
migration/postcopy-ram.c +1 -0
index a36402722b..78646abf7a 100644
@@ -18,6 +18,7 @@
 
 #include "qemu/osdep.h"
 #include "exec/target_page.h"
+#include "exec/ramblock.h"
 #include "migration.h"
 #include "qemu-file.h"
 #include "savevm.h"
migration/savevm.c +1 -0
index b979ea6e7f..714b5b4591 100644
@@ -48,6 +48,7 @@
 #include "sysemu/cpus.h"
 #include "exec/memory.h"
 #include "exec/target_page.h"
+#include "exec/ramblock.h"
 #include "trace.h"
 #include "qemu/iov.h"
 #include "qemu/main-loop.h"
stubs/ram-block.c +1 -1
index 73c0a3ee08..9e73543598 100644
@@ -1,6 +1,6 @@
 #include "qemu/osdep.h"
 #include "exec/ramlist.h"
-#include "exec/cpu-common.h"
+#include "exec/ramblock.h"
 
 void *qemu_ram_get_host_addr(RAMBlock *rb)
 {
target/ppc/kvm.c +0 -1
index 2692f76130..1f3db517db 100644
@@ -43,7 +43,6 @@
 #include "trace.h"
 #include "exec/gdbstub.h"
 #include "exec/memattrs.h"
-#include "exec/ram_addr.h"
 #include "sysemu/hostmem.h"
 #include "qemu/cutils.h"
 #include "qemu/main-loop.h"
target/s390x/kvm.c +0 -1
index 69881a0da0..42657bc0a5 100644
@@ -41,7 +41,6 @@
 #include "sysemu/runstate.h"
 #include "sysemu/device_tree.h"
 #include "exec/gdbstub.h"
-#include "exec/ram_addr.h"
 #include "trace.h"
 #include "hw/s390x/s390-pci-inst.h"
 #include "hw/s390x/s390-pci-bus.h"
util/vfio-helpers.c +1 -1
index e399e330e2..2ee169da58 100644
@@ -15,7 +15,7 @@
 #include <linux/vfio.h>
 #include "qapi/error.h"
 #include "exec/ramlist.h"
-#include "exec/cpu-common.h"
+#include "exec/ramblock.h"
 #include "trace.h"
 #include "qemu/error-report.h"
 #include "standard-headers/linux/pci_regs.h"
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#19 lore raw

PATCH 8/10 hw/block: Let the NVMe emulated device be target-agnostic

In reply to Philippe Mathieu-Daudé

Now than qemu_ram_msync() has been ...

---
 hw/block/Makefile.objs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/Makefile.objs +1 -1
index 47960b5f0d..8855c22656 100644
@@ -13,6 +13,6 @@ common-obj-$(CONFIG_SH4) += tc58128.o
 
 obj-$(CONFIG_VIRTIO_BLK) += virtio-blk.o
 obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk.o
-obj-$(CONFIG_NVME_PCI) += nvme.o
+common-obj-$(CONFIG_NVME_PCI) += nvme.o
 
 obj-y += dataplane/
Signature · 1 line
2.21.3
#20 lore raw

Re: [PATCH 08/10] hw/block: Let the NVMe emulated device be target-agnostic

Quoted 1 line · Philippe Mathieu-Daudé

Now than qemu_ram_msync() has been ...

Oops =)

"Now than qemu_ram_msync() is no more target-specific, we can make this device-generic."

Quoted 19 lines
---
  hw/block/Makefile.objs | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/Makefile.objs +1 -1
index 47960b5f0d..8855c22656 100644
@@ -13,6 +13,6 @@ common-obj-$(CONFIG_SH4) += tc58128.o
 
  obj-$(CONFIG_VIRTIO_BLK) += virtio-blk.o
  obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk.o
-obj-$(CONFIG_NVME_PCI) += nvme.o
+common-obj-$(CONFIG_NVME_PCI) += nvme.o
 
  obj-y += dataplane/
#22 lore raw

PATCH 9/10 exec: Update coding style to make checkpatch.pl happy

In reply to Philippe Mathieu-Daudé

We will move this code in the next commit. Clean it up first to avoid checkpatch.pl errors.

---
 include/exec/ram_addr.h | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
include/exec/ram_addr.h +15 -9
index 0deffad66f..6acde47a0f 100644
@@ -95,7 +95,8 @@ static inline bool cpu_physical_memory_all_dirty(ram_addr_t start,
     while (page < end) {
         unsigned long next = MIN(end, base + DIRTY_MEMORY_BLOCK_SIZE);
         unsigned long num = next - base;
-        unsigned long found = find_next_zero_bit(blocks->blocks[idx], num, offset);
+        unsigned long found = find_next_zero_bit(blocks->blocks[idx],
+                                                 num, offset);
         if (found < num) {
             dirty = false;
             break;
@@ -120,14 +121,14 @@ static inline bool cpu_physical_memory_is_clean(ram_addr_t addr)
 {
     bool vga = cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_VGA);
     bool code = cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_CODE);
-    bool migration =
-        cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_MIGRATION);
+    bool migration = cpu_physical_memory_get_dirty_flag(addr,
+                                                        DIRTY_MEMORY_MIGRATION);
     return !(vga && code && migration);
 }
 
 static inline uint8_t cpu_physical_memory_range_includes_clean(ram_addr_t start,
-                                                               ram_addr_t length,
-                                                               uint8_t mask)
+                                                            ram_addr_t length,
+                                                            uint8_t mask)
 {
     uint8_t ret = 0;
 
@@ -272,7 +273,8 @@ static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
 
         xen_hvm_modified_memory(start, pages << TARGET_PAGE_BITS);
     } else {
-        uint8_t clients = tcg_enabled() ? DIRTY_CLIENTS_ALL : DIRTY_CLIENTS_NOCODE;
+        uint8_t clients = tcg_enabled()
+                          ? DIRTY_CLIENTS_ALL : DIRTY_CLIENTS_NOCODE;
 
         if (!global_dirty_log) {
             clients &= ~(1 << DIRTY_MEMORY_MIGRATION);
@@ -304,8 +306,11 @@ bool cpu_physical_memory_test_and_clear_dirty(ram_addr_t start,
                                               ram_addr_t length,
                                               unsigned client);
 
-DirtyBitmapSnapshot *cpu_physical_memory_snapshot_and_clear_dirty
-    (MemoryRegion *mr, hwaddr offset, hwaddr length, unsigned client);
+DirtyBitmapSnapshot *cpu_physical_memory_snapshot_and_clear_dirty(
+                                                            MemoryRegion *mr,
+                                                            hwaddr offset,
+                                                            hwaddr length,
+                                                            unsigned client);
 
 bool cpu_physical_memory_snapshot_get_dirty(DirtyBitmapSnapshot *snap,
                                             ram_addr_t start,
@@ -314,7 +319,8 @@ bool cpu_physical_memory_snapshot_get_dirty(DirtyBitmapSnapshot *snap,
 static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start,
                                                          ram_addr_t length)
 {
-    cpu_physical_memory_test_and_clear_dirty(start, length, DIRTY_MEMORY_MIGRATION);
+    cpu_physical_memory_test_and_clear_dirty(start, length,
+                                             DIRTY_MEMORY_MIGRATION);
     cpu_physical_memory_test_and_clear_dirty(start, length, DIRTY_MEMORY_VGA);
     cpu_physical_memory_test_and_clear_dirty(start, length, DIRTY_MEMORY_CODE);
 }
Signature · 1 line
2.21.3
#24 lore raw

PATCH 10/10 exec: Move cpu_physical_memory_* functions to 'exec/memory-internal.h'

In reply to Philippe Mathieu-Daudé
---
 include/exec/memory-internal.h | 305 ++++++++++++++++++++++++++++++++-
 include/exec/ram_addr.h        | 303 +-------------------------------
 accel/tcg/cputlb.c             |   1 -
 hw/ppc/spapr.c                 |   1 -
 hw/ppc/spapr_pci.c             |   1 -
 memory.c                       |   1 -
 6 files changed, 305 insertions(+), 307 deletions(-)
include/exec/memory-internal.h +304 -1
index b2b7c1e78a..4abb3bbd85 100644
@@ -21,8 +21,13 @@
 #define MEMORY_INTERNAL_H
 
 #include "cpu.h"
+#include "sysemu/tcg.h"
+#include "sysemu/xen.h"
+#include "exec/ramlist.h"
+#include "exec/ramblock.h"
 
 #ifdef CONFIG_SOFTMMU
+
 static inline AddressSpaceDispatch *flatview_to_dispatch(FlatView *fv)
 {
     return fv->dispatch;
@@ -49,5 +54,303 @@ void address_space_dispatch_free(AddressSpaceDispatch *d);
 
 void mtree_print_dispatch(struct AddressSpaceDispatch *d,
                           MemoryRegion *root);
-#endif
+
+#define DIRTY_CLIENTS_ALL     ((1 << DIRTY_MEMORY_NUM) - 1)
+#define DIRTY_CLIENTS_NOCODE  (DIRTY_CLIENTS_ALL & ~(1 << DIRTY_MEMORY_CODE))
+
+static inline bool cpu_physical_memory_get_dirty(ram_addr_t start,
+                                                 ram_addr_t length,
+                                                 unsigned client)
+{
+    DirtyMemoryBlocks *blocks;
+    unsigned long end, page;
+    unsigned long idx, offset, base;
+    bool dirty = false;
+
+    assert(client < DIRTY_MEMORY_NUM);
+
+    end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
+    page = start >> TARGET_PAGE_BITS;
+
+    WITH_RCU_READ_LOCK_GUARD() {
+        blocks = atomic_rcu_read(&ram_list.dirty_memory[client]);
+
+        idx = page / DIRTY_MEMORY_BLOCK_SIZE;
+        offset = page % DIRTY_MEMORY_BLOCK_SIZE;
+        base = page - offset;
+        while (page < end) {
+            unsigned long next = MIN(end, base + DIRTY_MEMORY_BLOCK_SIZE);
+            unsigned long num = next - base;
+            unsigned long found = find_next_bit(blocks->blocks[idx],
+                                                num, offset);
+            if (found < num) {
+                dirty = true;
+                break;
+            }
+
+            page = next;
+            idx++;
+            offset = 0;
+            base += DIRTY_MEMORY_BLOCK_SIZE;
+        }
+    }
+
+    return dirty;
+}
+
+static inline bool cpu_physical_memory_all_dirty(ram_addr_t start,
+                                                 ram_addr_t length,
+                                                 unsigned client)
+{
+    DirtyMemoryBlocks *blocks;
+    unsigned long end, page;
+    unsigned long idx, offset, base;
+    bool dirty = true;
+
+    assert(client < DIRTY_MEMORY_NUM);
+
+    end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
+    page = start >> TARGET_PAGE_BITS;
+
+    RCU_READ_LOCK_GUARD();
+
+    blocks = atomic_rcu_read(&ram_list.dirty_memory[client]);
+
+    idx = page / DIRTY_MEMORY_BLOCK_SIZE;
+    offset = page % DIRTY_MEMORY_BLOCK_SIZE;
+    base = page - offset;
+    while (page < end) {
+        unsigned long next = MIN(end, base + DIRTY_MEMORY_BLOCK_SIZE);
+        unsigned long num = next - base;
+        unsigned long found = find_next_zero_bit(blocks->blocks[idx],
+                                                 num, offset);
+        if (found < num) {
+            dirty = false;
+            break;
+        }
+
+        page = next;
+        idx++;
+        offset = 0;
+        base += DIRTY_MEMORY_BLOCK_SIZE;
+    }
+
+    return dirty;
+}
+
+static inline bool cpu_physical_memory_get_dirty_flag(ram_addr_t addr,
+                                                      unsigned client)
+{
+    return cpu_physical_memory_get_dirty(addr, 1, client);
+}
+
+static inline bool cpu_physical_memory_is_clean(ram_addr_t addr)
+{
+    bool vga = cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_VGA);
+    bool code = cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_CODE);
+    bool migration = cpu_physical_memory_get_dirty_flag(addr,
+                                                        DIRTY_MEMORY_MIGRATION);
+    return !(vga && code && migration);
+}
+
+static inline uint8_t cpu_physical_memory_range_includes_clean(ram_addr_t start,
+                                                            ram_addr_t length,
+                                                            uint8_t mask)
+{
+    uint8_t ret = 0;
+
+    if (mask & (1 << DIRTY_MEMORY_VGA) &&
+        !cpu_physical_memory_all_dirty(start, length, DIRTY_MEMORY_VGA)) {
+        ret |= (1 << DIRTY_MEMORY_VGA);
+    }
+    if (mask & (1 << DIRTY_MEMORY_CODE) &&
+        !cpu_physical_memory_all_dirty(start, length, DIRTY_MEMORY_CODE)) {
+        ret |= (1 << DIRTY_MEMORY_CODE);
+    }
+    if (mask & (1 << DIRTY_MEMORY_MIGRATION) &&
+        !cpu_physical_memory_all_dirty(start, length, DIRTY_MEMORY_MIGRATION)) {
+        ret |= (1 << DIRTY_MEMORY_MIGRATION);
+    }
+    return ret;
+}
+
+static inline void cpu_physical_memory_set_dirty_flag(ram_addr_t addr,
+                                                      unsigned client)
+{
+    unsigned long page, idx, offset;
+    DirtyMemoryBlocks *blocks;
+
+    assert(client < DIRTY_MEMORY_NUM);
+
+    page = addr >> TARGET_PAGE_BITS;
+    idx = page / DIRTY_MEMORY_BLOCK_SIZE;
+    offset = page % DIRTY_MEMORY_BLOCK_SIZE;
+
+    RCU_READ_LOCK_GUARD();
+
+    blocks = atomic_rcu_read(&ram_list.dirty_memory[client]);
+
+    set_bit_atomic(offset, blocks->blocks[idx]);
+}
+
+static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start,
+                                                       ram_addr_t length,
+                                                       uint8_t mask)
+{
+    DirtyMemoryBlocks *blocks[DIRTY_MEMORY_NUM];
+    unsigned long end, page;
+    unsigned long idx, offset, base;
+    int i;
+
+    if (!mask && !xen_enabled()) {
+        return;
+    }
+
+    end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
+    page = start >> TARGET_PAGE_BITS;
+
+    WITH_RCU_READ_LOCK_GUARD() {
+        for (i = 0; i < DIRTY_MEMORY_NUM; i++) {
+            blocks[i] = atomic_rcu_read(&ram_list.dirty_memory[i]);
+        }
+
+        idx = page / DIRTY_MEMORY_BLOCK_SIZE;
+        offset = page % DIRTY_MEMORY_BLOCK_SIZE;
+        base = page - offset;
+        while (page < end) {
+            unsigned long next = MIN(end, base + DIRTY_MEMORY_BLOCK_SIZE);
+
+            if (likely(mask & (1 << DIRTY_MEMORY_MIGRATION))) {
+                bitmap_set_atomic(blocks[DIRTY_MEMORY_MIGRATION]->blocks[idx],
+                                  offset, next - page);
+            }
+            if (unlikely(mask & (1 << DIRTY_MEMORY_VGA))) {
+                bitmap_set_atomic(blocks[DIRTY_MEMORY_VGA]->blocks[idx],
+                                  offset, next - page);
+            }
+            if (unlikely(mask & (1 << DIRTY_MEMORY_CODE))) {
+                bitmap_set_atomic(blocks[DIRTY_MEMORY_CODE]->blocks[idx],
+                                  offset, next - page);
+            }
+
+            page = next;
+            idx++;
+            offset = 0;
+            base += DIRTY_MEMORY_BLOCK_SIZE;
+        }
+    }
+
+    xen_hvm_modified_memory(start, length);
+}
+
+#if !defined(_WIN32)
+static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
+                                                          ram_addr_t start,
+                                                          ram_addr_t pages)
+{
+    unsigned long i, j;
+    unsigned long page_number, c;
+    hwaddr addr;
+    ram_addr_t ram_addr;
+    unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
+    unsigned long hpratio = qemu_real_host_page_size / TARGET_PAGE_SIZE;
+    unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS);
+
+    /* start address is aligned at the start of a word? */
+    if ((((page * BITS_PER_LONG) << TARGET_PAGE_BITS) == start) &&
+        (hpratio == 1)) {
+        unsigned long **blocks[DIRTY_MEMORY_NUM];
+        unsigned long idx;
+        unsigned long offset;
+        long k;
+        long nr = BITS_TO_LONGS(pages);
+
+        idx = (start >> TARGET_PAGE_BITS) / DIRTY_MEMORY_BLOCK_SIZE;
+        offset = BIT_WORD((start >> TARGET_PAGE_BITS) %
+                          DIRTY_MEMORY_BLOCK_SIZE);
+
+        WITH_RCU_READ_LOCK_GUARD() {
+            for (i = 0; i < DIRTY_MEMORY_NUM; i++) {
+                blocks[i] = atomic_rcu_read(&ram_list.dirty_memory[i])->blocks;
+            }
+
+            for (k = 0; k < nr; k++) {
+                if (bitmap[k]) {
+                    unsigned long temp = leul_to_cpu(bitmap[k]);
+
+                    atomic_or(&blocks[DIRTY_MEMORY_VGA][idx][offset], temp);
+
+                    if (global_dirty_log) {
+                        atomic_or(&blocks[DIRTY_MEMORY_MIGRATION][idx][offset],
+                                  temp);
+                    }
+
+                    if (tcg_enabled()) {
+                        atomic_or(&blocks[DIRTY_MEMORY_CODE][idx][offset],
+                                  temp);
+                    }
+                }
+
+                if (++offset >= BITS_TO_LONGS(DIRTY_MEMORY_BLOCK_SIZE)) {
+                    offset = 0;
+                    idx++;
+                }
+            }
+        }
+
+        xen_hvm_modified_memory(start, pages << TARGET_PAGE_BITS);
+    } else {
+        uint8_t clients = tcg_enabled() ? DIRTY_CLIENTS_ALL
+                                        : DIRTY_CLIENTS_NOCODE;
+
+        if (!global_dirty_log) {
+            clients &= ~(1 << DIRTY_MEMORY_MIGRATION);
+        }
+
+        /*
+         * bitmap-traveling is faster than memory-traveling (for addr...)
+         * especially when most of the memory is not dirty.
+         */
+        for (i = 0; i < len; i++) {
+            if (bitmap[i] != 0) {
+                c = leul_to_cpu(bitmap[i]);
+                do {
+                    j = ctzl(c);
+                    c &= ~(1ul << j);
+                    page_number = (i * HOST_LONG_BITS + j) * hpratio;
+                    addr = page_number * TARGET_PAGE_SIZE;
+                    ram_addr = start + addr;
+                    cpu_physical_memory_set_dirty_range(ram_addr,
+                                       TARGET_PAGE_SIZE * hpratio, clients);
+                } while (c != 0);
+            }
+        }
+    }
+}
+#endif /* not _WIN32 */
+
+bool cpu_physical_memory_test_and_clear_dirty(ram_addr_t start,
+                                              ram_addr_t length,
+                                              unsigned client);
+
+DirtyBitmapSnapshot *cpu_physical_memory_snapshot_and_clear_dirty(
+                                                            MemoryRegion *mr,
+                                                            hwaddr offset,
+                                                            hwaddr length,
+                                                            unsigned client);
+
+bool cpu_physical_memory_snapshot_get_dirty(DirtyBitmapSnapshot *snap,
+                                            ram_addr_t start,
+                                            ram_addr_t length);
+
+static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start,
+                                                         ram_addr_t length)
+{
+    cpu_physical_memory_test_and_clear_dirty(start, length,
+                                             DIRTY_MEMORY_MIGRATION);
+    cpu_physical_memory_test_and_clear_dirty(start, length, DIRTY_MEMORY_VGA);
+    cpu_physical_memory_test_and_clear_dirty(start, length, DIRTY_MEMORY_CODE);
+}
+
+#endif /* CONFIG_SOFTMMU */
 #endif
include/exec/ram_addr.h +1 -302

311 lines not on this page · raw message

accel/tcg/cputlb.c +0 -1
index e3b5750c3b..922671f246 100644
@@ -26,7 +26,6 @@
 #include "exec/cpu_ldst.h"
 #include "exec/cputlb.h"
 #include "exec/memory-internal.h"
-#include "exec/ram_addr.h"
 #include "tcg/tcg.h"
 #include "qemu/error-report.h"
 #include "exec/log.h"
hw/ppc/spapr.c +0 -1
index c18eab0a23..d7c3bf3932 100644
@@ -69,7 +69,6 @@
 #include "hw/virtio/vhost-scsi-common.h"
 
 #include "exec/address-spaces.h"
-#include "exec/ram_addr.h"
 #include "hw/usb.h"
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
hw/ppc/spapr_pci.c +0 -1
index 61b84a392d..8d9aeba6e6 100644
@@ -36,7 +36,6 @@
 #include "hw/ppc/spapr.h"
 #include "hw/pci-host/spapr.h"
 #include "exec/address-spaces.h"
-#include "exec/ram_addr.h"
 #include <libfdt.h>
 #include "trace.h"
 #include "qemu/error-report.h"
memory.c +0 -1
index e8e7bcd6c7..4e1d19c5fc 100644
@@ -27,7 +27,6 @@
 #include "trace-root.h"
 
 #include "exec/memory-internal.h"
-#include "exec/ram_addr.h"
 #include "exec/ramblock.h"
 #include "sysemu/kvm.h"
 #include "sysemu/runstate.h"
Signature · 1 line
2.21.3
#25 lore raw

Re: [PATCH 10/10] exec: Move cpu_physical_memory_* functions to 'exec/memory-internal.h'

Quoted 1 line · Philippe Mathieu-Daudé

Once here, can someone give a test that meassures if it makes sense that this functions are inline?
They are relatively big, and I would preffer them to be in a .c file, but I have no clue about how performance critical they are.

Again, this include was another of the reasons that migration/ram.c can't be make target agnostic.

Later, Juan.

Acked-by on v1 10/10
#26 lore raw

Re: [PATCH 10/10] exec: Move cpu_physical_memory_* functions to 'exec/memory-internal.h'

In reply to Philippe Mathieu-Daudé
Quoted 1 line · Philippe Mathieu-Daudé

ppc parts

Quoted 696 lines
---
 include/exec/memory-internal.h | 305 ++++++++++++++++++++++++++++++++-
 include/exec/ram_addr.h        | 303 +-------------------------------
 accel/tcg/cputlb.c             |   1 -
 hw/ppc/spapr.c                 |   1 -
 hw/ppc/spapr_pci.c             |   1 -
 memory.c                       |   1 -
 6 files changed, 305 insertions(+), 307 deletions(-)
include/exec/memory-internal.h +304 -1
index b2b7c1e78a..4abb3bbd85 100644
@@ -21,8 +21,13 @@
 #define MEMORY_INTERNAL_H
 
 #include "cpu.h"
+#include "sysemu/tcg.h"
+#include "sysemu/xen.h"
+#include "exec/ramlist.h"
+#include "exec/ramblock.h"
 
 #ifdef CONFIG_SOFTMMU
+
 static inline AddressSpaceDispatch *flatview_to_dispatch(FlatView *fv)
 {
     return fv->dispatch;
@@ -49,5 +54,303 @@ void address_space_dispatch_free(AddressSpaceDispatch *d);
 
 void mtree_print_dispatch(struct AddressSpaceDispatch *d,
                           MemoryRegion *root);
-#endif
+
+#define DIRTY_CLIENTS_ALL     ((1 << DIRTY_MEMORY_NUM) - 1)
+#define DIRTY_CLIENTS_NOCODE  (DIRTY_CLIENTS_ALL & ~(1 << DIRTY_MEMORY_CODE))
+
+static inline bool cpu_physical_memory_get_dirty(ram_addr_t start,
+                                                 ram_addr_t length,
+                                                 unsigned client)
+{
+    DirtyMemoryBlocks *blocks;
+    unsigned long end, page;
+    unsigned long idx, offset, base;
+    bool dirty = false;
+
+    assert(client < DIRTY_MEMORY_NUM);
+
+    end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
+    page = start >> TARGET_PAGE_BITS;
+
+    WITH_RCU_READ_LOCK_GUARD() {
+        blocks = atomic_rcu_read(&ram_list.dirty_memory[client]);
+
+        idx = page / DIRTY_MEMORY_BLOCK_SIZE;
+        offset = page % DIRTY_MEMORY_BLOCK_SIZE;
+        base = page - offset;
+        while (page < end) {
+            unsigned long next = MIN(end, base + DIRTY_MEMORY_BLOCK_SIZE);
+            unsigned long num = next - base;
+            unsigned long found = find_next_bit(blocks->blocks[idx],
+                                                num, offset);
+            if (found < num) {
+                dirty = true;
+                break;
+            }
+
+            page = next;
+            idx++;
+            offset = 0;
+            base += DIRTY_MEMORY_BLOCK_SIZE;
+        }
+    }
+
+    return dirty;
+}
+
+static inline bool cpu_physical_memory_all_dirty(ram_addr_t start,
+                                                 ram_addr_t length,
+                                                 unsigned client)
+{
+    DirtyMemoryBlocks *blocks;
+    unsigned long end, page;
+    unsigned long idx, offset, base;
+    bool dirty = true;
+
+    assert(client < DIRTY_MEMORY_NUM);
+
+    end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
+    page = start >> TARGET_PAGE_BITS;
+
+    RCU_READ_LOCK_GUARD();
+
+    blocks = atomic_rcu_read(&ram_list.dirty_memory[client]);
+
+    idx = page / DIRTY_MEMORY_BLOCK_SIZE;
+    offset = page % DIRTY_MEMORY_BLOCK_SIZE;
+    base = page - offset;
+    while (page < end) {
+        unsigned long next = MIN(end, base + DIRTY_MEMORY_BLOCK_SIZE);
+        unsigned long num = next - base;
+        unsigned long found = find_next_zero_bit(blocks->blocks[idx],
+                                                 num, offset);
+        if (found < num) {
+            dirty = false;
+            break;
+        }
+
+        page = next;
+        idx++;
+        offset = 0;
+        base += DIRTY_MEMORY_BLOCK_SIZE;
+    }
+
+    return dirty;
+}
+
+static inline bool cpu_physical_memory_get_dirty_flag(ram_addr_t addr,
+                                                      unsigned client)
+{
+    return cpu_physical_memory_get_dirty(addr, 1, client);
+}
+
+static inline bool cpu_physical_memory_is_clean(ram_addr_t addr)
+{
+    bool vga = cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_VGA);
+    bool code = cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_CODE);
+    bool migration = cpu_physical_memory_get_dirty_flag(addr,
+                                                        DIRTY_MEMORY_MIGRATION);
+    return !(vga && code && migration);
+}
+
+static inline uint8_t cpu_physical_memory_range_includes_clean(ram_addr_t start,
+                                                            ram_addr_t length,
+                                                            uint8_t mask)
+{
+    uint8_t ret = 0;
+
+    if (mask & (1 << DIRTY_MEMORY_VGA) &&
+        !cpu_physical_memory_all_dirty(start, length, DIRTY_MEMORY_VGA)) {
+        ret |= (1 << DIRTY_MEMORY_VGA);
+    }
+    if (mask & (1 << DIRTY_MEMORY_CODE) &&
+        !cpu_physical_memory_all_dirty(start, length, DIRTY_MEMORY_CODE)) {
+        ret |= (1 << DIRTY_MEMORY_CODE);
+    }
+    if (mask & (1 << DIRTY_MEMORY_MIGRATION) &&
+        !cpu_physical_memory_all_dirty(start, length, DIRTY_MEMORY_MIGRATION)) {
+        ret |= (1 << DIRTY_MEMORY_MIGRATION);
+    }
+    return ret;
+}
+
+static inline void cpu_physical_memory_set_dirty_flag(ram_addr_t addr,
+                                                      unsigned client)
+{
+    unsigned long page, idx, offset;
+    DirtyMemoryBlocks *blocks;
+
+    assert(client < DIRTY_MEMORY_NUM);
+
+    page = addr >> TARGET_PAGE_BITS;
+    idx = page / DIRTY_MEMORY_BLOCK_SIZE;
+    offset = page % DIRTY_MEMORY_BLOCK_SIZE;
+
+    RCU_READ_LOCK_GUARD();
+
+    blocks = atomic_rcu_read(&ram_list.dirty_memory[client]);
+
+    set_bit_atomic(offset, blocks->blocks[idx]);
+}
+
+static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start,
+                                                       ram_addr_t length,
+                                                       uint8_t mask)
+{
+    DirtyMemoryBlocks *blocks[DIRTY_MEMORY_NUM];
+    unsigned long end, page;
+    unsigned long idx, offset, base;
+    int i;
+
+    if (!mask && !xen_enabled()) {
+        return;
+    }
+
+    end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
+    page = start >> TARGET_PAGE_BITS;
+
+    WITH_RCU_READ_LOCK_GUARD() {
+        for (i = 0; i < DIRTY_MEMORY_NUM; i++) {
+            blocks[i] = atomic_rcu_read(&ram_list.dirty_memory[i]);
+        }
+
+        idx = page / DIRTY_MEMORY_BLOCK_SIZE;
+        offset = page % DIRTY_MEMORY_BLOCK_SIZE;
+        base = page - offset;
+        while (page < end) {
+            unsigned long next = MIN(end, base + DIRTY_MEMORY_BLOCK_SIZE);
+
+            if (likely(mask & (1 << DIRTY_MEMORY_MIGRATION))) {
+                bitmap_set_atomic(blocks[DIRTY_MEMORY_MIGRATION]->blocks[idx],
+                                  offset, next - page);
+            }
+            if (unlikely(mask & (1 << DIRTY_MEMORY_VGA))) {
+                bitmap_set_atomic(blocks[DIRTY_MEMORY_VGA]->blocks[idx],
+                                  offset, next - page);
+            }
+            if (unlikely(mask & (1 << DIRTY_MEMORY_CODE))) {
+                bitmap_set_atomic(blocks[DIRTY_MEMORY_CODE]->blocks[idx],
+                                  offset, next - page);
+            }
+
+            page = next;
+            idx++;
+            offset = 0;
+            base += DIRTY_MEMORY_BLOCK_SIZE;
+        }
+    }
+
+    xen_hvm_modified_memory(start, length);
+}
+
+#if !defined(_WIN32)
+static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
+                                                          ram_addr_t start,
+                                                          ram_addr_t pages)
+{
+    unsigned long i, j;
+    unsigned long page_number, c;
+    hwaddr addr;
+    ram_addr_t ram_addr;
+    unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
+    unsigned long hpratio = qemu_real_host_page_size / TARGET_PAGE_SIZE;
+    unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS);
+
+    /* start address is aligned at the start of a word? */
+    if ((((page * BITS_PER_LONG) << TARGET_PAGE_BITS) == start) &&
+        (hpratio == 1)) {
+        unsigned long **blocks[DIRTY_MEMORY_NUM];
+        unsigned long idx;
+        unsigned long offset;
+        long k;
+        long nr = BITS_TO_LONGS(pages);
+
+        idx = (start >> TARGET_PAGE_BITS) / DIRTY_MEMORY_BLOCK_SIZE;
+        offset = BIT_WORD((start >> TARGET_PAGE_BITS) %
+                          DIRTY_MEMORY_BLOCK_SIZE);
+
+        WITH_RCU_READ_LOCK_GUARD() {
+            for (i = 0; i < DIRTY_MEMORY_NUM; i++) {
+                blocks[i] = atomic_rcu_read(&ram_list.dirty_memory[i])->blocks;
+            }
+
+            for (k = 0; k < nr; k++) {
+                if (bitmap[k]) {
+                    unsigned long temp = leul_to_cpu(bitmap[k]);
+
+                    atomic_or(&blocks[DIRTY_MEMORY_VGA][idx][offset], temp);
+
+                    if (global_dirty_log) {
+                        atomic_or(&blocks[DIRTY_MEMORY_MIGRATION][idx][offset],
+                                  temp);
+                    }
+
+                    if (tcg_enabled()) {
+                        atomic_or(&blocks[DIRTY_MEMORY_CODE][idx][offset],
+                                  temp);
+                    }
+                }
+
+                if (++offset >= BITS_TO_LONGS(DIRTY_MEMORY_BLOCK_SIZE)) {
+                    offset = 0;
+                    idx++;
+                }
+            }
+        }
+
+        xen_hvm_modified_memory(start, pages << TARGET_PAGE_BITS);
+    } else {
+        uint8_t clients = tcg_enabled() ? DIRTY_CLIENTS_ALL
+                                        : DIRTY_CLIENTS_NOCODE;
+
+        if (!global_dirty_log) {
+            clients &= ~(1 << DIRTY_MEMORY_MIGRATION);
+        }
+
+        /*
+         * bitmap-traveling is faster than memory-traveling (for addr...)
+         * especially when most of the memory is not dirty.
+         */
+        for (i = 0; i < len; i++) {
+            if (bitmap[i] != 0) {
+                c = leul_to_cpu(bitmap[i]);
+                do {
+                    j = ctzl(c);
+                    c &= ~(1ul << j);
+                    page_number = (i * HOST_LONG_BITS + j) * hpratio;
+                    addr = page_number * TARGET_PAGE_SIZE;
+                    ram_addr = start + addr;
+                    cpu_physical_memory_set_dirty_range(ram_addr,
+                                       TARGET_PAGE_SIZE * hpratio, clients);
+                } while (c != 0);
+            }
+        }
+    }
+}
+#endif /* not _WIN32 */
+
+bool cpu_physical_memory_test_and_clear_dirty(ram_addr_t start,
+                                              ram_addr_t length,
+                                              unsigned client);
+
+DirtyBitmapSnapshot *cpu_physical_memory_snapshot_and_clear_dirty(
+                                                            MemoryRegion *mr,
+                                                            hwaddr offset,
+                                                            hwaddr length,
+                                                            unsigned client);
+
+bool cpu_physical_memory_snapshot_get_dirty(DirtyBitmapSnapshot *snap,
+                                            ram_addr_t start,
+                                            ram_addr_t length);
+
+static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start,
+                                                         ram_addr_t length)
+{
+    cpu_physical_memory_test_and_clear_dirty(start, length,
+                                             DIRTY_MEMORY_MIGRATION);
+    cpu_physical_memory_test_and_clear_dirty(start, length, DIRTY_MEMORY_VGA);
+    cpu_physical_memory_test_and_clear_dirty(start, length, DIRTY_MEMORY_CODE);
+}
+
+#endif /* CONFIG_SOFTMMU */
 #endif
include/exec/ram_addr.h +1 -302
index 6acde47a0f..64bf28a332 100644
@@ -21,310 +21,9 @@
 
 #ifndef CONFIG_USER_ONLY
 #include "cpu.h"
-#include "sysemu/xen.h"
-#include "sysemu/tcg.h"
 #include "exec/ramlist.h"
 #include "exec/ramblock.h"
-
-
-
-#define DIRTY_CLIENTS_ALL     ((1 << DIRTY_MEMORY_NUM) - 1)
-#define DIRTY_CLIENTS_NOCODE  (DIRTY_CLIENTS_ALL & ~(1 << DIRTY_MEMORY_CODE))
-
-static inline bool cpu_physical_memory_get_dirty(ram_addr_t start,
-                                                 ram_addr_t length,
-                                                 unsigned client)
-{
-    DirtyMemoryBlocks *blocks;
-    unsigned long end, page;
-    unsigned long idx, offset, base;
-    bool dirty = false;
-
-    assert(client < DIRTY_MEMORY_NUM);
-
-    end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
-    page = start >> TARGET_PAGE_BITS;
-
-    WITH_RCU_READ_LOCK_GUARD() {
-        blocks = atomic_rcu_read(&ram_list.dirty_memory[client]);
-
-        idx = page / DIRTY_MEMORY_BLOCK_SIZE;
-        offset = page % DIRTY_MEMORY_BLOCK_SIZE;
-        base = page - offset;
-        while (page < end) {
-            unsigned long next = MIN(end, base + DIRTY_MEMORY_BLOCK_SIZE);
-            unsigned long num = next - base;
-            unsigned long found = find_next_bit(blocks->blocks[idx],
-                                                num, offset);
-            if (found < num) {
-                dirty = true;
-                break;
-            }
-
-            page = next;
-            idx++;
-            offset = 0;
-            base += DIRTY_MEMORY_BLOCK_SIZE;
-        }
-    }
-
-    return dirty;
-}
-
-static inline bool cpu_physical_memory_all_dirty(ram_addr_t start,
-                                                 ram_addr_t length,
-                                                 unsigned client)
-{
-    DirtyMemoryBlocks *blocks;
-    unsigned long end, page;
-    unsigned long idx, offset, base;
-    bool dirty = true;
-
-    assert(client < DIRTY_MEMORY_NUM);
-
-    end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
-    page = start >> TARGET_PAGE_BITS;
-
-    RCU_READ_LOCK_GUARD();
-
-    blocks = atomic_rcu_read(&ram_list.dirty_memory[client]);
-
-    idx = page / DIRTY_MEMORY_BLOCK_SIZE;
-    offset = page % DIRTY_MEMORY_BLOCK_SIZE;
-    base = page - offset;
-    while (page < end) {
-        unsigned long next = MIN(end, base + DIRTY_MEMORY_BLOCK_SIZE);
-        unsigned long num = next - base;
-        unsigned long found = find_next_zero_bit(blocks->blocks[idx],
-                                                 num, offset);
-        if (found < num) {
-            dirty = false;
-            break;
-        }
-
-        page = next;
-        idx++;
-        offset = 0;
-        base += DIRTY_MEMORY_BLOCK_SIZE;
-    }
-
-    return dirty;
-}
-
-static inline bool cpu_physical_memory_get_dirty_flag(ram_addr_t addr,
-                                                      unsigned client)
-{
-    return cpu_physical_memory_get_dirty(addr, 1, client);
-}
-
-static inline bool cpu_physical_memory_is_clean(ram_addr_t addr)
-{
-    bool vga = cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_VGA);
-    bool code = cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_CODE);
-    bool migration = cpu_physical_memory_get_dirty_flag(addr,
-                                                        DIRTY_MEMORY_MIGRATION);
-    return !(vga && code && migration);
-}
-
-static inline uint8_t cpu_physical_memory_range_includes_clean(ram_addr_t start,
-                                                            ram_addr_t length,
-                                                            uint8_t mask)
-{
-    uint8_t ret = 0;
-
-    if (mask & (1 << DIRTY_MEMORY_VGA) &&
-        !cpu_physical_memory_all_dirty(start, length, DIRTY_MEMORY_VGA)) {
-        ret |= (1 << DIRTY_MEMORY_VGA);
-    }
-    if (mask & (1 << DIRTY_MEMORY_CODE) &&
-        !cpu_physical_memory_all_dirty(start, length, DIRTY_MEMORY_CODE)) {
-        ret |= (1 << DIRTY_MEMORY_CODE);
-    }
-    if (mask & (1 << DIRTY_MEMORY_MIGRATION) &&
-        !cpu_physical_memory_all_dirty(start, length, DIRTY_MEMORY_MIGRATION)) {
-        ret |= (1 << DIRTY_MEMORY_MIGRATION);
-    }
-    return ret;
-}
-
-static inline void cpu_physical_memory_set_dirty_flag(ram_addr_t addr,
-                                                      unsigned client)
-{
-    unsigned long page, idx, offset;
-    DirtyMemoryBlocks *blocks;
-
-    assert(client < DIRTY_MEMORY_NUM);
-
-    page = addr >> TARGET_PAGE_BITS;
-    idx = page / DIRTY_MEMORY_BLOCK_SIZE;
-    offset = page % DIRTY_MEMORY_BLOCK_SIZE;
-
-    RCU_READ_LOCK_GUARD();
-
-    blocks = atomic_rcu_read(&ram_list.dirty_memory[client]);
-
-    set_bit_atomic(offset, blocks->blocks[idx]);
-}
-
-static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start,
-                                                       ram_addr_t length,
-                                                       uint8_t mask)
-{
-    DirtyMemoryBlocks *blocks[DIRTY_MEMORY_NUM];
-    unsigned long end, page;
-    unsigned long idx, offset, base;
-    int i;
-
-    if (!mask && !xen_enabled()) {
-        return;
-    }
-
-    end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
-    page = start >> TARGET_PAGE_BITS;
-
-    WITH_RCU_READ_LOCK_GUARD() {
-        for (i = 0; i < DIRTY_MEMORY_NUM; i++) {
-            blocks[i] = atomic_rcu_read(&ram_list.dirty_memory[i]);
-        }
-
-        idx = page / DIRTY_MEMORY_BLOCK_SIZE;
-        offset = page % DIRTY_MEMORY_BLOCK_SIZE;
-        base = page - offset;
-        while (page < end) {
-            unsigned long next = MIN(end, base + DIRTY_MEMORY_BLOCK_SIZE);
-
-            if (likely(mask & (1 << DIRTY_MEMORY_MIGRATION))) {
-                bitmap_set_atomic(blocks[DIRTY_MEMORY_MIGRATION]->blocks[idx],
-                                  offset, next - page);
-            }
-            if (unlikely(mask & (1 << DIRTY_MEMORY_VGA))) {
-                bitmap_set_atomic(blocks[DIRTY_MEMORY_VGA]->blocks[idx],
-                                  offset, next - page);
-            }
-            if (unlikely(mask & (1 << DIRTY_MEMORY_CODE))) {
-                bitmap_set_atomic(blocks[DIRTY_MEMORY_CODE]->blocks[idx],
-                                  offset, next - page);
-            }
-
-            page = next;
-            idx++;
-            offset = 0;
-            base += DIRTY_MEMORY_BLOCK_SIZE;
-        }
-    }
-
-    xen_hvm_modified_memory(start, length);
-}
-
-#if !defined(_WIN32)
-static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
-                                                          ram_addr_t start,
-                                                          ram_addr_t pages)
-{
-    unsigned long i, j;
-    unsigned long page_number, c;
-    hwaddr addr;
-    ram_addr_t ram_addr;
-    unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
-    unsigned long hpratio = qemu_real_host_page_size / TARGET_PAGE_SIZE;
-    unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS);
-
-    /* start address is aligned at the start of a word? */
-    if ((((page * BITS_PER_LONG) << TARGET_PAGE_BITS) == start) &&
-        (hpratio == 1)) {
-        unsigned long **blocks[DIRTY_MEMORY_NUM];
-        unsigned long idx;
-        unsigned long offset;
-        long k;
-        long nr = BITS_TO_LONGS(pages);
-
-        idx = (start >> TARGET_PAGE_BITS) / DIRTY_MEMORY_BLOCK_SIZE;
-        offset = BIT_WORD((start >> TARGET_PAGE_BITS) %
-                          DIRTY_MEMORY_BLOCK_SIZE);
-
-        WITH_RCU_READ_LOCK_GUARD() {
-            for (i = 0; i < DIRTY_MEMORY_NUM; i++) {
-                blocks[i] = atomic_rcu_read(&ram_list.dirty_memory[i])->blocks;
-            }
-
-            for (k = 0; k < nr; k++) {
-                if (bitmap[k]) {
-                    unsigned long temp = leul_to_cpu(bitmap[k]);
-
-                    atomic_or(&blocks[DIRTY_MEMORY_VGA][idx][offset], temp);
-
-                    if (global_dirty_log) {
-                        atomic_or(&blocks[DIRTY_MEMORY_MIGRATION][idx][offset],
-                                  temp);
-                    }
-
-                    if (tcg_enabled()) {
-                        atomic_or(&blocks[DIRTY_MEMORY_CODE][idx][offset],
-                                  temp);
-                    }
-                }
-
-                if (++offset >= BITS_TO_LONGS(DIRTY_MEMORY_BLOCK_SIZE)) {
-                    offset = 0;
-                    idx++;
-                }
-            }
-        }
-
-        xen_hvm_modified_memory(start, pages << TARGET_PAGE_BITS);
-    } else {
-        uint8_t clients = tcg_enabled()
-                          ? DIRTY_CLIENTS_ALL : DIRTY_CLIENTS_NOCODE;
-
-        if (!global_dirty_log) {
-            clients &= ~(1 << DIRTY_MEMORY_MIGRATION);
-        }
-
-        /*
-         * bitmap-traveling is faster than memory-traveling (for addr...)
-         * especially when most of the memory is not dirty.
-         */
-        for (i = 0; i < len; i++) {
-            if (bitmap[i] != 0) {
-                c = leul_to_cpu(bitmap[i]);
-                do {
-                    j = ctzl(c);
-                    c &= ~(1ul << j);
-                    page_number = (i * HOST_LONG_BITS + j) * hpratio;
-                    addr = page_number * TARGET_PAGE_SIZE;
-                    ram_addr = start + addr;
-                    cpu_physical_memory_set_dirty_range(ram_addr,
-                                       TARGET_PAGE_SIZE * hpratio, clients);
-                } while (c != 0);
-            }
-        }
-    }
-}
-#endif /* not _WIN32 */
-
-bool cpu_physical_memory_test_and_clear_dirty(ram_addr_t start,
-                                              ram_addr_t length,
-                                              unsigned client);
-
-DirtyBitmapSnapshot *cpu_physical_memory_snapshot_and_clear_dirty(
-                                                            MemoryRegion *mr,
-                                                            hwaddr offset,
-                                                            hwaddr length,
-                                                            unsigned client);
-
-bool cpu_physical_memory_snapshot_get_dirty(DirtyBitmapSnapshot *snap,
-                                            ram_addr_t start,
-                                            ram_addr_t length);
-
-static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start,
-                                                         ram_addr_t length)
-{
-    cpu_physical_memory_test_and_clear_dirty(start, length,
-                                             DIRTY_MEMORY_MIGRATION);
-    cpu_physical_memory_test_and_clear_dirty(start, length, DIRTY_MEMORY_VGA);
-    cpu_physical_memory_test_and_clear_dirty(start, length, DIRTY_MEMORY_CODE);
-}
-
+#include "exec/memory-internal.h"
 
 /* Called with RCU critical section */
 static inline
accel/tcg/cputlb.c +0 -1
index e3b5750c3b..922671f246 100644
@@ -26,7 +26,6 @@
 #include "exec/cpu_ldst.h"
 #include "exec/cputlb.h"
 #include "exec/memory-internal.h"
-#include "exec/ram_addr.h"
 #include "tcg/tcg.h"
 #include "qemu/error-report.h"
 #include "exec/log.h"
hw/ppc/spapr.c +0 -1
index c18eab0a23..d7c3bf3932 100644
@@ -69,7 +69,6 @@
 #include "hw/virtio/vhost-scsi-common.h"
 
 #include "exec/address-spaces.h"
-#include "exec/ram_addr.h"
 #include "hw/usb.h"
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
hw/ppc/spapr_pci.c +0 -1
index 61b84a392d..8d9aeba6e6 100644
@@ -36,7 +36,6 @@
 #include "hw/ppc/spapr.h"
 #include "hw/pci-host/spapr.h"
 #include "exec/address-spaces.h"
-#include "exec/ram_addr.h"
 #include <libfdt.h>
 #include "trace.h"
 #include "qemu/error-report.h"
memory.c +0 -1
index e8e7bcd6c7..4e1d19c5fc 100644
@@ -27,7 +27,6 @@
 #include "trace-root.h"
 
 #include "exec/memory-internal.h"
-#include "exec/ram_addr.h"
 #include "exec/ramblock.h"
 #include "sysemu/kvm.h"
 #include "sysemu/runstate.h"
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#27 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

Stefan suggested to make qemu_ram_writeback() target agnostic, Paolo to add memory_region_msync(), and Peter to remove "exec/ram_addr.h" [*].

I let a single function in this file, cpu_physical_memory_sync_dirty_bitmap(), to let the maintainer have the pleasure to remove this header definitively himself :)

I don't think this is a good idea. :)

"exec/ram_addr.h" is a good place for functions that work on ram-addr_t and/or RAMBlock data. There should very few of these, since these are mostly an internal concept that should only be used for live migration.
You could:

- figure out which files actually need to include exec/ram_addr.h. There's already very few of them.

- move the large functions to a new .c file, ramblock.c. Figure out which can be static, move the declarations for the others to ramblock.h

- kill ram_addr.h and include ramblock.h instead.

Not coincidentially, qemu_ram_writeback() takes a RAMBlock*, and it ends up in ramblock.h.

Also, this is orthogonal to adding the wrapper memory_region_msync.

Thanks,

Paolo

#28 lore raw
Quoted 11 lines · Paolo Bonzini
Quoted 7 lines · Philippe Mathieu-Daudé

Stefan suggested to make qemu_ram_writeback() target agnostic, Paolo to add memory_region_msync(), and Peter to remove "exec/ram_addr.h" [*].

I let a single function in this file, cpu_physical_memory_sync_dirty_bitmap(), to let the maintainer have the pleasure to remove this header definitively himself :)

I don't think this is a good idea. :)

Quoted 7 lines

"exec/ram_addr.h" is a good place for functions that work on ram-addr_t and/or RAMBlock data. There should very few of these, since these are mostly an internal concept that should only be used for live migration.
You could:

- figure out which files actually need to include exec/ram_addr.h. There's already very few of them.

ram_addr.h looks really "not dangerous", I think that I preffer the memory-internal.h or whatever name that implies that you should think twice before using that file.

My main problem with that include are:

- cpu_physical_memory_set_dirty_lebitmap()
- cpu_physical_memory_sync_dirty_bitmap()

Both are long, both are complex, and if one changes them, it is very probably that you end breaking some random architecture in TCG (being there, done that).

As you said, that functions are used only in a couple of places. I haven't meassured the impact of moving it to a .c file, but I would preffer it if performance don't suffer.

Quoted 3 lines

- move the large functions to a new .c file, ramblock.c. Figure out which can be static, move the declarations for the others to ramblock.h

Ok, it appears that we kind of agree.

Quoted 1 line

- kill ram_addr.h and include ramblock.h instead.

I created ramblock.h initially (/me checks) because if you just need to walk a ramblock (that is clearly target independent code), you needed to become target dependent, due to the definitions that are there inside.

I don't care one way or another, just that we don't create the old dependency.

Quoted 2 lines

Not coincidentially, qemu_ram_writeback() takes a RAMBlock*, and it ends up in ramblock.h.

Thanks, Juan.

#29 lore raw
In reply to Philippe Mathieu-Daudé
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series failed the docker-quick@centos7 build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-centos7 V=1 NETWORK=1
time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1 === TEST SCRIPT END ===

TEST check-qtest-aarch64: tests/qtest/arm-cpu-features
Broken pipe
/tmp/qemu-test/src/tests/qtest/libqtest.c:175: kill_qemu() detected QEMU death from signal 6 (Aborted) (core dumped)
ERROR - too few tests run (expected 5, got 0)
make: *** [check-qtest-aarch64] Error 1
make: *** Waiting for unfinished jobs....
TEST check-unit: tests/check-block-qdict
TEST check-unit: tests/test-char
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=aa05160ac8ef4a8aabb028db62e978dc', '-u', '1001', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=1', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-sj3y_tsg/src/docker-src.2020-05-08-02.05.43.23802:/var/tmp/qemu:z,ro', 'qemu:centos7', '/var/tmp/qemu/run', 'test-quick']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=aa05160ac8ef4a8aabb028db62e978dc
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-sj3y_tsg/src'
make: *** [docker-run-test-quick@centos7] Error 2

real 14m12.181s
user 0m9.451s

The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-quick@centos7/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]