All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic
@ 2020-05-07 17:39 Philippe Mathieu-Daudé
  2020-05-07 17:39 ` [PATCH 01/10] exec: Rename qemu_ram_writeback() as qemu_ram_msync() Philippe Mathieu-Daudé
                   ` (11 more replies)
  0 siblings, 12 replies; 30+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-05-07 17:39 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Kevin Wolf, Cornelia Huck, Alex Williamson, Michael S. Tsirkin,
	qemu-block, David Hildenbrand, Juan Quintela,
	Dr. David Alan Gilbert, Max Reitz, Halil Pasic,
	Christian Borntraeger, qemu-s390x, qemu-ppc, Keith Busch,
	Richard Henderson, Philippe Mathieu-Daudé,
	David Gibson

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: <20200507155813.16169-1-philmd@redhat.com>
"Move Xen accelerator code under accel/xen/"
https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg01722.html

[*] https://www.mail-archive.com/qemu-block@nongnu.org/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(-)

-- 
2.21.3



^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 01/10] exec: Rename qemu_ram_writeback() as qemu_ram_msync()
  2020-05-07 17:39 [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic Philippe Mathieu-Daudé
@ 2020-05-07 17:39 ` Philippe Mathieu-Daudé
  2020-05-08  7:59   ` Juan Quintela
  2020-05-07 17:39 ` [PATCH 02/10] exec/ramblock: Add missing 'qemu/rcu.h' include Philippe Mathieu-Daudé
                   ` (10 subsequent siblings)
  11 siblings, 1 reply; 30+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-05-07 17:39 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Kevin Wolf, Cornelia Huck, Alex Williamson, Michael S. Tsirkin,
	qemu-block, David Hildenbrand, Juan Quintela,
	Dr. David Alan Gilbert, Max Reitz, Halil Pasic,
	Christian Borntraeger, qemu-s390x, qemu-ppc, Stefan Hajnoczi,
	Keith Busch, Richard Henderson, Philippe Mathieu-Daudé,
	David Gibson

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

Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 include/exec/ram_addr.h | 4 ++--
 exec.c                  | 2 +-
 hw/block/nvme.c         | 3 +--
 memory.c                | 2 +-
 4 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index 4e05292f91..7b5c24e928 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -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)
diff --git a/exec.c b/exec.c
index 2874bb5088..f5a8cdf370 100644
--- a/exec.c
+++ b/exec.c
@@ -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);
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 9b453423cf..21a199e53b 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -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 {
diff --git a/memory.c b/memory.c
index 601b749906..3e65e33ac4 100644
--- a/memory.c
+++ b/memory.c
@@ -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);
     }
 }
 
-- 
2.21.3



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 02/10] exec/ramblock: Add missing 'qemu/rcu.h' include
  2020-05-07 17:39 [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic Philippe Mathieu-Daudé
  2020-05-07 17:39 ` [PATCH 01/10] exec: Rename qemu_ram_writeback() as qemu_ram_msync() Philippe Mathieu-Daudé
@ 2020-05-07 17:39 ` Philippe Mathieu-Daudé
  2020-05-08  7:59   ` Juan Quintela
  2020-05-07 17:39 ` [PATCH 03/10] exec: Move tb_invalidate_phys_range() to 'exec/exec-all.h' Philippe Mathieu-Daudé
                   ` (9 subsequent siblings)
  11 siblings, 1 reply; 30+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-05-07 17:39 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Kevin Wolf, Cornelia Huck, Alex Williamson, Michael S. Tsirkin,
	qemu-block, David Hildenbrand, Juan Quintela,
	Dr. David Alan Gilbert, Max Reitz, Halil Pasic,
	Christian Borntraeger, qemu-s390x, qemu-ppc, Keith Busch,
	Richard Henderson, Philippe Mathieu-Daudé,
	David Gibson

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;
        |     ^~~~~~~~~~~

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 include/exec/ramblock.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/exec/ramblock.h b/include/exec/ramblock.h
index 07d50864d8..6ac0aa7a89 100644
--- a/include/exec/ramblock.h
+++ b/include/exec/ramblock.h
@@ -21,6 +21,7 @@
 
 #ifndef CONFIG_USER_ONLY
 #include "cpu-common.h"
+#include "qemu/rcu.h"
 
 struct RAMBlock {
     struct rcu_head rcu;
-- 
2.21.3



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 03/10] exec: Move tb_invalidate_phys_range() to 'exec/exec-all.h'
  2020-05-07 17:39 [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic Philippe Mathieu-Daudé
  2020-05-07 17:39 ` [PATCH 01/10] exec: Rename qemu_ram_writeback() as qemu_ram_msync() Philippe Mathieu-Daudé
  2020-05-07 17:39 ` [PATCH 02/10] exec/ramblock: Add missing 'qemu/rcu.h' include Philippe Mathieu-Daudé
@ 2020-05-07 17:39 ` Philippe Mathieu-Daudé
  2020-05-07 17:39 ` [PATCH 04/10] exec/memory-internal: Check CONFIG_SOFTMMU instead of CONFIG_USER_ONLY Philippe Mathieu-Daudé
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 30+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-05-07 17:39 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Kevin Wolf, Cornelia Huck, Alex Williamson, Michael S. Tsirkin,
	qemu-block, David Hildenbrand, Juan Quintela,
	Dr. David Alan Gilbert, Max Reitz, Halil Pasic,
	Christian Borntraeger, qemu-s390x, qemu-ppc, Keith Busch,
	Richard Henderson, Philippe Mathieu-Daudé,
	David Gibson

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.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 include/exec/exec-all.h | 14 ++++++++------
 include/exec/ram_addr.h |  2 --
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index 350c4b451b..f1a9b8a576 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -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;
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index 7b5c24e928..06096e8c6a 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -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)
-- 
2.21.3



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 04/10] exec/memory-internal: Check CONFIG_SOFTMMU instead of CONFIG_USER_ONLY
  2020-05-07 17:39 [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic Philippe Mathieu-Daudé
                   ` (2 preceding siblings ...)
  2020-05-07 17:39 ` [PATCH 03/10] exec: Move tb_invalidate_phys_range() to 'exec/exec-all.h' Philippe Mathieu-Daudé
@ 2020-05-07 17:39 ` Philippe Mathieu-Daudé
  2020-05-08  8:01   ` Juan Quintela
  2020-05-07 17:39 ` [PATCH 05/10] exec: Move qemu_minrampagesize/qemu_maxrampagesize to 'qemu-common.h' Philippe Mathieu-Daudé
                   ` (7 subsequent siblings)
  11 siblings, 1 reply; 30+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-05-07 17:39 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Kevin Wolf, Cornelia Huck, Alex Williamson, Michael S. Tsirkin,
	qemu-block, David Hildenbrand, Juan Quintela,
	Dr. David Alan Gilbert, Max Reitz, Halil Pasic,
	Christian Borntraeger, qemu-s390x, qemu-ppc, Keith Busch,
	Richard Henderson, Philippe Mathieu-Daudé,
	David Gibson

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.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 include/exec/memory-internal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h
index 9fcc2af25c..b2b7c1e78a 100644
--- a/include/exec/memory-internal.h
+++ b/include/exec/memory-internal.h
@@ -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;
-- 
2.21.3



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 05/10] exec: Move qemu_minrampagesize/qemu_maxrampagesize to 'qemu-common.h'
  2020-05-07 17:39 [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic Philippe Mathieu-Daudé
                   ` (3 preceding siblings ...)
  2020-05-07 17:39 ` [PATCH 04/10] exec/memory-internal: Check CONFIG_SOFTMMU instead of CONFIG_USER_ONLY Philippe Mathieu-Daudé
@ 2020-05-07 17:39 ` Philippe Mathieu-Daudé
  2020-05-08  8:03   ` Juan Quintela
                     ` (2 more replies)
  2020-05-07 17:39 ` [PATCH 06/10] exec: Move ramblock_recv_bitmap_offset() to migration/ram.c Philippe Mathieu-Daudé
                   ` (6 subsequent siblings)
  11 siblings, 3 replies; 30+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-05-07 17:39 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Kevin Wolf, Cornelia Huck, Alex Williamson, Michael S. Tsirkin,
	qemu-block, David Hildenbrand, Alexey Kardashevskiy,
	Juan Quintela, Dr. David Alan Gilbert, Max Reitz, Halil Pasic,
	Christian Borntraeger, qemu-s390x, qemu-ppc, Keith Busch,
	Richard Henderson, Philippe Mathieu-Daudé,
	David Gibson

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

Cc: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 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(-)

diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index 06096e8c6a..195b67d3c8 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -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
diff --git a/include/qemu-common.h b/include/qemu-common.h
index d0142f29ac..2821a6ef76 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -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,
diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
index eb54f94227..33a802a103 100644
--- a/hw/ppc/spapr_caps.c
+++ b/hw/ppc/spapr_caps.c
@@ -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"
diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index f660070d22..c009384505 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -12,6 +12,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu-common.h"
 #include "qapi/error.h"
 #include "cpu.h"
 #include "hw/boards.h"
diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
index 2900bd1941..c64db940a7 100644
--- a/hw/vfio/spapr.c
+++ b/hw/vfio/spapr.c
@@ -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"
-- 
2.21.3



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 06/10] exec: Move ramblock_recv_bitmap_offset() to migration/ram.c
  2020-05-07 17:39 [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic Philippe Mathieu-Daudé
                   ` (4 preceding siblings ...)
  2020-05-07 17:39 ` [PATCH 05/10] exec: Move qemu_minrampagesize/qemu_maxrampagesize to 'qemu-common.h' Philippe Mathieu-Daudé
@ 2020-05-07 17:39 ` Philippe Mathieu-Daudé
  2020-05-08  8:07   ` Juan Quintela
  2020-05-07 17:39 ` [PATCH 07/10] exec: Move all RAMBlock functions to 'exec/ramblock.h' Philippe Mathieu-Daudé
                   ` (5 subsequent siblings)
  11 siblings, 1 reply; 30+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-05-07 17:39 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Kevin Wolf, Cornelia Huck, Alex Williamson, Michael S. Tsirkin,
	qemu-block, David Hildenbrand, Juan Quintela,
	Dr. David Alan Gilbert, Max Reitz, Halil Pasic,
	Christian Borntraeger, qemu-s390x, qemu-ppc, Keith Busch,
	Richard Henderson, Philippe Mathieu-Daudé,
	David Gibson

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

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 include/exec/ram_addr.h | 8 --------
 migration/ram.c         | 8 ++++++++
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index 195b67d3c8..c61d5188f7 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -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);
 
 /**
diff --git a/migration/ram.c b/migration/ram.c
index 53166fc279..0cd16d0519 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -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;
-- 
2.21.3



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 07/10] exec: Move all RAMBlock functions to 'exec/ramblock.h'
  2020-05-07 17:39 [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic Philippe Mathieu-Daudé
                   ` (5 preceding siblings ...)
  2020-05-07 17:39 ` [PATCH 06/10] exec: Move ramblock_recv_bitmap_offset() to migration/ram.c Philippe Mathieu-Daudé
@ 2020-05-07 17:39 ` Philippe Mathieu-Daudé
  2020-05-08  8:08   ` Juan Quintela
                     ` (2 more replies)
  2020-05-07 17:39 ` [PATCH 08/10] hw/block: Let the NVMe emulated device be target-agnostic Philippe Mathieu-Daudé
                   ` (4 subsequent siblings)
  11 siblings, 3 replies; 30+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-05-07 17:39 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Kevin Wolf, Cornelia Huck, Alex Williamson, Michael S. Tsirkin,
	qemu-block, David Hildenbrand, Juan Quintela,
	Dr. David Alan Gilbert, Max Reitz, Halil Pasic,
	Christian Borntraeger, qemu-s390x, qemu-ppc, Keith Busch,
	Richard Henderson, Philippe Mathieu-Daudé,
	David Gibson

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.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 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(-)

diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index b47e5630e7..347ceb603b 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -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 */
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index c61d5188f7..0deffad66f 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -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))
diff --git a/include/exec/ramblock.h b/include/exec/ramblock.h
index 6ac0aa7a89..b6b34141fc 100644
--- a/include/exec/ramblock.h
+++ b/include/exec/ramblock.h
@@ -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
diff --git a/migration/migration.h b/migration/migration.h
index 507284e563..73eb210ef5 100644
--- a/migration/migration.h
+++ b/migration/migration.h
@@ -21,6 +21,7 @@
 #include "qemu/coroutine_int.h"
 #include "io/channel.h"
 #include "net/announce.h"
+#include "exec/ramblock.h"
 
 struct PostcopyBlocktimeContext;
 
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index 9924e66d1f..15c8ee9110 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -43,8 +43,6 @@
 #include <libutil.h>
 #endif
 #endif
-#else
-#include "exec/ram_addr.h"
 #endif
 
 #include "exec/cputlb.h"
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 21a199e53b..8d8dd7ce80 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -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"
diff --git a/hw/s390x/s390-stattrib-kvm.c b/hw/s390x/s390-stattrib-kvm.c
index f89d8d9d16..46ca7e7d1f 100644
--- a/hw/s390x/s390-stattrib-kvm.c
+++ b/hw/s390x/s390-stattrib-kvm.c
@@ -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"
 
diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c
index 58121b9f68..9785d51577 100644
--- a/hw/s390x/s390-stattrib.c
+++ b/hw/s390x/s390-stattrib.c
@@ -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"
 
diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index c009384505..ade36eda5e 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -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"
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index ec21e8fbe8..12764d6254 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -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>
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index aff98a0ede..7da8d95a43 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -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"
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index a4729f7fc9..ea112e9403 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -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"
diff --git a/memory.c b/memory.c
index 3e65e33ac4..e8e7bcd6c7 100644
--- a/memory.c
+++ b/memory.c
@@ -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"
diff --git a/migration/migration.c b/migration/migration.c
index 177cce9e95..8c7ed8cc79 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -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"
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index a36402722b..78646abf7a 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -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"
diff --git a/migration/savevm.c b/migration/savevm.c
index b979ea6e7f..714b5b4591 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -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"
diff --git a/stubs/ram-block.c b/stubs/ram-block.c
index 73c0a3ee08..9e73543598 100644
--- a/stubs/ram-block.c
+++ b/stubs/ram-block.c
@@ -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)
 {
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
index 2692f76130..1f3db517db 100644
--- a/target/ppc/kvm.c
+++ b/target/ppc/kvm.c
@@ -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"
diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
index 69881a0da0..42657bc0a5 100644
--- a/target/s390x/kvm.c
+++ b/target/s390x/kvm.c
@@ -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"
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
index e399e330e2..2ee169da58 100644
--- a/util/vfio-helpers.c
+++ b/util/vfio-helpers.c
@@ -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"
-- 
2.21.3



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 08/10] hw/block: Let the NVMe emulated device be target-agnostic
  2020-05-07 17:39 [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic Philippe Mathieu-Daudé
                   ` (6 preceding siblings ...)
  2020-05-07 17:39 ` [PATCH 07/10] exec: Move all RAMBlock functions to 'exec/ramblock.h' Philippe Mathieu-Daudé
@ 2020-05-07 17:39 ` Philippe Mathieu-Daudé
  2020-05-07 17:42   ` Philippe Mathieu-Daudé
  2020-05-08  8:09   ` Juan Quintela
  2020-05-07 17:39 ` [PATCH 09/10] exec: Update coding style to make checkpatch.pl happy Philippe Mathieu-Daudé
                   ` (3 subsequent siblings)
  11 siblings, 2 replies; 30+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-05-07 17:39 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Kevin Wolf, Cornelia Huck, Alex Williamson, Michael S. Tsirkin,
	qemu-block, David Hildenbrand, Juan Quintela,
	Dr. David Alan Gilbert, Max Reitz, Halil Pasic,
	Christian Borntraeger, qemu-s390x, qemu-ppc, Keith Busch,
	Richard Henderson, Philippe Mathieu-Daudé,
	David Gibson

Now than qemu_ram_msync() has been ...

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/block/Makefile.objs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/block/Makefile.objs b/hw/block/Makefile.objs
index 47960b5f0d..8855c22656 100644
--- a/hw/block/Makefile.objs
+++ b/hw/block/Makefile.objs
@@ -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/
-- 
2.21.3



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 09/10] exec: Update coding style to make checkpatch.pl happy
  2020-05-07 17:39 [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic Philippe Mathieu-Daudé
                   ` (7 preceding siblings ...)
  2020-05-07 17:39 ` [PATCH 08/10] hw/block: Let the NVMe emulated device be target-agnostic Philippe Mathieu-Daudé
@ 2020-05-07 17:39 ` Philippe Mathieu-Daudé
  2020-05-08  9:05   ` Juan Quintela
  2020-05-07 17:39 ` [PATCH 10/10] exec: Move cpu_physical_memory_* functions to 'exec/memory-internal.h' Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  11 siblings, 1 reply; 30+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-05-07 17:39 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Kevin Wolf, Cornelia Huck, Alex Williamson, Michael S. Tsirkin,
	qemu-block, David Hildenbrand, Juan Quintela,
	Dr. David Alan Gilbert, Max Reitz, Halil Pasic,
	Christian Borntraeger, qemu-s390x, qemu-ppc, Keith Busch,
	Richard Henderson, Philippe Mathieu-Daudé,
	David Gibson

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

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 include/exec/ram_addr.h | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index 0deffad66f..6acde47a0f 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -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);
 }
-- 
2.21.3



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 10/10] exec: Move cpu_physical_memory_* functions to 'exec/memory-internal.h'
  2020-05-07 17:39 [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic Philippe Mathieu-Daudé
                   ` (8 preceding siblings ...)
  2020-05-07 17:39 ` [PATCH 09/10] exec: Update coding style to make checkpatch.pl happy Philippe Mathieu-Daudé
@ 2020-05-07 17:39 ` Philippe Mathieu-Daudé
  2020-05-08  8:12   ` Juan Quintela
  2020-05-11  1:35   ` David Gibson
  2020-05-07 22:15 ` [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic Paolo Bonzini
  2020-05-08  6:19 ` no-reply
  11 siblings, 2 replies; 30+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-05-07 17:39 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Kevin Wolf, Cornelia Huck, Alex Williamson, Michael S. Tsirkin,
	qemu-block, David Hildenbrand, Juan Quintela,
	Dr. David Alan Gilbert, Max Reitz, Halil Pasic,
	Christian Borntraeger, qemu-s390x, qemu-ppc, Keith Busch,
	Richard Henderson, Philippe Mathieu-Daudé,
	David Gibson

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 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(-)

diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h
index b2b7c1e78a..4abb3bbd85 100644
--- a/include/exec/memory-internal.h
+++ b/include/exec/memory-internal.h
@@ -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
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index 6acde47a0f..64bf28a332 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -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
diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c
index e3b5750c3b..922671f246 100644
--- a/accel/tcg/cputlb.c
+++ b/accel/tcg/cputlb.c
@@ -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"
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index c18eab0a23..d7c3bf3932 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -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"
diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
index 61b84a392d..8d9aeba6e6 100644
--- a/hw/ppc/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -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"
diff --git a/memory.c b/memory.c
index e8e7bcd6c7..4e1d19c5fc 100644
--- a/memory.c
+++ b/memory.c
@@ -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"
-- 
2.21.3



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* Re: [PATCH 08/10] hw/block: Let the NVMe emulated device be target-agnostic
  2020-05-07 17:39 ` [PATCH 08/10] hw/block: Let the NVMe emulated device be target-agnostic Philippe Mathieu-Daudé
@ 2020-05-07 17:42   ` Philippe Mathieu-Daudé
  2020-05-08  8:09   ` Juan Quintela
  1 sibling, 0 replies; 30+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-05-07 17:42 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Kevin Wolf, Cornelia Huck, Alex Williamson, Michael S. Tsirkin,
	qemu-block, David Hildenbrand, Juan Quintela,
	Dr. David Alan Gilbert, Max Reitz, Halil Pasic,
	Christian Borntraeger, qemu-s390x, qemu-ppc, Keith Busch,
	Richard Henderson, David Gibson

On 5/7/20 7:39 PM, Philippe Mathieu-Daudé wrote:
> Now than qemu_ram_msync() has been ...

Oops =)

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

> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>   hw/block/Makefile.objs | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/block/Makefile.objs b/hw/block/Makefile.objs
> index 47960b5f0d..8855c22656 100644
> --- a/hw/block/Makefile.objs
> +++ b/hw/block/Makefile.objs
> @@ -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/
> 



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic
  2020-05-07 17:39 [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic Philippe Mathieu-Daudé
                   ` (9 preceding siblings ...)
  2020-05-07 17:39 ` [PATCH 10/10] exec: Move cpu_physical_memory_* functions to 'exec/memory-internal.h' Philippe Mathieu-Daudé
@ 2020-05-07 22:15 ` Paolo Bonzini
  2020-05-08  8:21   ` Juan Quintela
  2020-05-08  6:19 ` no-reply
  11 siblings, 1 reply; 30+ messages in thread
From: Paolo Bonzini @ 2020-05-07 22:15 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, Peter Maydell, qemu-devel
  Cc: Kevin Wolf, Cornelia Huck, Alex Williamson, Michael S. Tsirkin,
	qemu-block, David Hildenbrand, Juan Quintela,
	Dr. David Alan Gilbert, Max Reitz, Halil Pasic,
	Christian Borntraeger, qemu-s390x, qemu-ppc, Keith Busch,
	Richard Henderson, David Gibson

On 07/05/20 19:39, Philippe Mathieu-Daudé wrote:
> 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



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic
  2020-05-07 17:39 [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic Philippe Mathieu-Daudé
                   ` (10 preceding siblings ...)
  2020-05-07 22:15 ` [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic Paolo Bonzini
@ 2020-05-08  6:19 ` no-reply
  11 siblings, 0 replies; 30+ messages in thread
From: no-reply @ 2020-05-08  6:19 UTC (permalink / raw)
  To: philmd
  Cc: kwolf, peter.maydell, qemu-block, mst, qemu-s390x, cohuck, david,
	qemu-devel, dgilbert, pasic, quintela, alex.williamson, qemu-ppc,
	david, kbusch, pbonzini, mreitz, philmd, borntraeger, rth

Patchew URL: https://patchew.org/QEMU/20200507173958.25894-1-philmd@redhat.com/



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/20200507173958.25894-1-philmd@redhat.com/testing.docker-quick@centos7/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 01/10] exec: Rename qemu_ram_writeback() as qemu_ram_msync()
  2020-05-07 17:39 ` [PATCH 01/10] exec: Rename qemu_ram_writeback() as qemu_ram_msync() Philippe Mathieu-Daudé
@ 2020-05-08  7:59   ` Juan Quintela
  0 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2020-05-08  7:59 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Peter Maydell, Cornelia Huck, Alex Williamson,
	qemu-block, David Hildenbrand, Michael S. Tsirkin, qemu-devel,
	Max Reitz, Halil Pasic, Christian Borntraeger, qemu-s390x,
	qemu-ppc, Stefan Hajnoczi, Keith Busch, Paolo Bonzini,
	Richard Henderson, Dr. David Alan Gilbert, David Gibson

Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
> Rename qemu_ram_writeback() as qemu_ram_msync() to better
> match what it does.
>
> Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>

if block people preffers that name, who I am to complain.



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 02/10] exec/ramblock: Add missing 'qemu/rcu.h' include
  2020-05-07 17:39 ` [PATCH 02/10] exec/ramblock: Add missing 'qemu/rcu.h' include Philippe Mathieu-Daudé
@ 2020-05-08  7:59   ` Juan Quintela
  0 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2020-05-08  7:59 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Peter Maydell, Cornelia Huck, Alex Williamson,
	qemu-block, David Hildenbrand, Michael S. Tsirkin, qemu-devel,
	Max Reitz, Halil Pasic, Christian Borntraeger, qemu-s390x,
	qemu-ppc, Keith Busch, Paolo Bonzini, Richard Henderson,
	Dr. David Alan Gilbert, David Gibson

Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
> 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;
>         |     ^~~~~~~~~~~
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 04/10] exec/memory-internal: Check CONFIG_SOFTMMU instead of CONFIG_USER_ONLY
  2020-05-07 17:39 ` [PATCH 04/10] exec/memory-internal: Check CONFIG_SOFTMMU instead of CONFIG_USER_ONLY Philippe Mathieu-Daudé
@ 2020-05-08  8:01   ` Juan Quintela
  0 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2020-05-08  8:01 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Peter Maydell, Cornelia Huck, Alex Williamson,
	qemu-block, David Hildenbrand, Michael S. Tsirkin, qemu-devel,
	Max Reitz, Halil Pasic, Christian Borntraeger, qemu-s390x,
	qemu-ppc, Keith Busch, Paolo Bonzini, Richard Henderson,
	Dr. David Alan Gilbert, David Gibson

Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
> 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.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>>

Reviewed-by: Juan Quintela <quintela@redhat.com>



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 05/10] exec: Move qemu_minrampagesize/qemu_maxrampagesize to 'qemu-common.h'
  2020-05-07 17:39 ` [PATCH 05/10] exec: Move qemu_minrampagesize/qemu_maxrampagesize to 'qemu-common.h' Philippe Mathieu-Daudé
@ 2020-05-08  8:03   ` Juan Quintela
  2020-05-08  9:09   ` Cornelia Huck
  2020-05-11  1:32   ` David Gibson
  2 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2020-05-08  8:03 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Peter Maydell, Cornelia Huck, Alex Williamson,
	qemu-block, David Hildenbrand, Alexey Kardashevskiy,
	Michael S. Tsirkin, qemu-devel, Max Reitz, Halil Pasic,
	Christian Borntraeger, qemu-s390x, qemu-ppc, Keith Busch,
	Paolo Bonzini, Richard Henderson, Dr. David Alan Gilbert,
	David Gibson

Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
> Move these generic functions to a more common place, with other
> functions related to host page size. Document a little.
>
> Cc: Alexey Kardashevskiy <aik@ozlabs.ru>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 06/10] exec: Move ramblock_recv_bitmap_offset() to migration/ram.c
  2020-05-07 17:39 ` [PATCH 06/10] exec: Move ramblock_recv_bitmap_offset() to migration/ram.c Philippe Mathieu-Daudé
@ 2020-05-08  8:07   ` Juan Quintela
  2020-05-08  9:27     ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 30+ messages in thread
From: Juan Quintela @ 2020-05-08  8:07 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Peter Maydell, Cornelia Huck, Alex Williamson,
	qemu-block, David Hildenbrand, Michael S. Tsirkin, qemu-devel,
	Max Reitz, Halil Pasic, Christian Borntraeger, qemu-s390x,
	qemu-ppc, Keith Busch, Paolo Bonzini, Richard Henderson,
	Dr. David Alan Gilbert, David Gibson

Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
> The ramblock_recv_bitmap_offset() function is only used once
> in migration/ram.c, move it there.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>

But, if you are in the mood:

>  }
>  
> +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.



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 07/10] exec: Move all RAMBlock functions to 'exec/ramblock.h'
  2020-05-07 17:39 ` [PATCH 07/10] exec: Move all RAMBlock functions to 'exec/ramblock.h' Philippe Mathieu-Daudé
@ 2020-05-08  8:08   ` Juan Quintela
  2020-05-08  9:32   ` Cornelia Huck
  2020-05-11  1:33   ` David Gibson
  2 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2020-05-08  8:08 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Peter Maydell, Cornelia Huck, Alex Williamson,
	qemu-block, David Hildenbrand, Michael S. Tsirkin, qemu-devel,
	Max Reitz, Halil Pasic, Christian Borntraeger, qemu-s390x,
	qemu-ppc, Keith Busch, Paolo Bonzini, Richard Henderson,
	Dr. David Alan Gilbert, David Gibson

Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
> 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.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>

Very nice of you doing this, Thanks.



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 08/10] hw/block: Let the NVMe emulated device be target-agnostic
  2020-05-07 17:39 ` [PATCH 08/10] hw/block: Let the NVMe emulated device be target-agnostic Philippe Mathieu-Daudé
  2020-05-07 17:42   ` Philippe Mathieu-Daudé
@ 2020-05-08  8:09   ` Juan Quintela
  1 sibling, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2020-05-08  8:09 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Peter Maydell, Cornelia Huck, Alex Williamson,
	qemu-block, David Hildenbrand, Michael S. Tsirkin, qemu-devel,
	Max Reitz, Halil Pasic, Christian Borntraeger, qemu-s390x,
	qemu-ppc, Keith Busch, Paolo Bonzini, Richard Henderson,
	Dr. David Alan Gilbert, David Gibson

Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
> Now than qemu_ram_msync() has been ...
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 10/10] exec: Move cpu_physical_memory_* functions to 'exec/memory-internal.h'
  2020-05-07 17:39 ` [PATCH 10/10] exec: Move cpu_physical_memory_* functions to 'exec/memory-internal.h' Philippe Mathieu-Daudé
@ 2020-05-08  8:12   ` Juan Quintela
  2020-05-11  1:35   ` David Gibson
  1 sibling, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2020-05-08  8:12 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Peter Maydell, Cornelia Huck, Alex Williamson,
	qemu-block, David Hildenbrand, Michael S. Tsirkin, qemu-devel,
	Max Reitz, Halil Pasic, Christian Borntraeger, qemu-s390x,
	qemu-ppc, Keith Busch, Paolo Bonzini, Richard Henderson,
	Dr. David Alan Gilbert, David Gibson

Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

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.



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic
  2020-05-07 22:15 ` [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic Paolo Bonzini
@ 2020-05-08  8:21   ` Juan Quintela
  0 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2020-05-08  8:21 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Kevin Wolf, Peter Maydell, Cornelia Huck, Alex Williamson,
	qemu-block, David Hildenbrand, Michael S. Tsirkin, qemu-devel,
	Max Reitz, Halil Pasic, Christian Borntraeger, qemu-s390x,
	qemu-ppc, Keith Busch, Richard Henderson,
	Philippe Mathieu-Daudé,
	Dr. David Alan Gilbert, David Gibson

Paolo Bonzini <pbonzini@redhat.com> wrote:
> On 07/05/20 19:39, Philippe Mathieu-Daudé wrote:
>> 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.

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.

>
> - 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.

> - 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.

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

Thanks, Juan.



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 09/10] exec: Update coding style to make checkpatch.pl happy
  2020-05-07 17:39 ` [PATCH 09/10] exec: Update coding style to make checkpatch.pl happy Philippe Mathieu-Daudé
@ 2020-05-08  9:05   ` Juan Quintela
  0 siblings, 0 replies; 30+ messages in thread
From: Juan Quintela @ 2020-05-08  9:05 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Peter Maydell, Cornelia Huck, Alex Williamson,
	qemu-block, David Hildenbrand, Michael S. Tsirkin, qemu-devel,
	Max Reitz, Halil Pasic, Christian Borntraeger, qemu-s390x,
	qemu-ppc, Keith Busch, Paolo Bonzini, Richard Henderson,
	Dr. David Alan Gilbert, David Gibson

Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
> We will move this code in the next commit. Clean it up
> first to avoid checkpatch.pl errors.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 05/10] exec: Move qemu_minrampagesize/qemu_maxrampagesize to 'qemu-common.h'
  2020-05-07 17:39 ` [PATCH 05/10] exec: Move qemu_minrampagesize/qemu_maxrampagesize to 'qemu-common.h' Philippe Mathieu-Daudé
  2020-05-08  8:03   ` Juan Quintela
@ 2020-05-08  9:09   ` Cornelia Huck
  2020-05-11  1:32   ` David Gibson
  2 siblings, 0 replies; 30+ messages in thread
From: Cornelia Huck @ 2020-05-08  9:09 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Peter Maydell, Alex Williamson, Michael S. Tsirkin,
	qemu-block, David Hildenbrand, Alexey Kardashevskiy,
	Juan Quintela, qemu-devel, Max Reitz, Halil Pasic,
	Christian Borntraeger, qemu-s390x, qemu-ppc, Keith Busch,
	Paolo Bonzini, Richard Henderson, Dr. David Alan Gilbert,
	David Gibson

On Thu,  7 May 2020 19:39:53 +0200
Philippe Mathieu-Daudé <philmd@redhat.com> wrote:

> Move these generic functions to a more common place, with other
> functions related to host page size. Document a little.
> 
> Cc: Alexey Kardashevskiy <aik@ozlabs.ru>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  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: Cornelia Huck <cohuck@redhat.com>



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 06/10] exec: Move ramblock_recv_bitmap_offset() to migration/ram.c
  2020-05-08  8:07   ` Juan Quintela
@ 2020-05-08  9:27     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 30+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-05-08  9:27 UTC (permalink / raw)
  To: quintela
  Cc: Kevin Wolf, Peter Maydell, Cornelia Huck, Alex Williamson,
	qemu-block, David Hildenbrand, Michael S. Tsirkin, qemu-devel,
	Max Reitz, Halil Pasic, Christian Borntraeger, qemu-s390x,
	qemu-ppc, Keith Busch, Paolo Bonzini, Richard Henderson,
	Dr. David Alan Gilbert, David Gibson

On 5/8/20 10:07 AM, Juan Quintela wrote:
> Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>> The ramblock_recv_bitmap_offset() function is only used once
>> in migration/ram.c, move it there.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> 
> Reviewed-by: Juan Quintela <quintela@redhat.com>
> 
> But, if you are in the mood:
> 
>>   }
>>   
>> +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().

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

> 
> 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.

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



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 07/10] exec: Move all RAMBlock functions to 'exec/ramblock.h'
  2020-05-07 17:39 ` [PATCH 07/10] exec: Move all RAMBlock functions to 'exec/ramblock.h' Philippe Mathieu-Daudé
  2020-05-08  8:08   ` Juan Quintela
@ 2020-05-08  9:32   ` Cornelia Huck
  2020-05-11  1:33   ` David Gibson
  2 siblings, 0 replies; 30+ messages in thread
From: Cornelia Huck @ 2020-05-08  9:32 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Peter Maydell, Alex Williamson, Michael S. Tsirkin,
	qemu-block, David Hildenbrand, Juan Quintela, qemu-devel,
	Max Reitz, Halil Pasic, Christian Borntraeger, qemu-s390x,
	qemu-ppc, Keith Busch, Paolo Bonzini, Richard Henderson,
	Dr. David Alan Gilbert, David Gibson

On Thu,  7 May 2020 19:39:55 +0200
Philippe Mathieu-Daudé <philmd@redhat.com> wrote:

> 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.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  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(-)

Acked-by: Cornelia Huck <cohuck@redhat.com>



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 05/10] exec: Move qemu_minrampagesize/qemu_maxrampagesize to 'qemu-common.h'
  2020-05-07 17:39 ` [PATCH 05/10] exec: Move qemu_minrampagesize/qemu_maxrampagesize to 'qemu-common.h' Philippe Mathieu-Daudé
  2020-05-08  8:03   ` Juan Quintela
  2020-05-08  9:09   ` Cornelia Huck
@ 2020-05-11  1:32   ` David Gibson
  2 siblings, 0 replies; 30+ messages in thread
From: David Gibson @ 2020-05-11  1:32 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Peter Maydell, Cornelia Huck, Alex Williamson,
	Michael S. Tsirkin, qemu-block, David Hildenbrand,
	Alexey Kardashevskiy, Juan Quintela, qemu-devel, Max Reitz,
	Halil Pasic, Christian Borntraeger, qemu-s390x, qemu-ppc,
	Keith Busch, Paolo Bonzini, Dr. David Alan Gilbert,
	Richard Henderson

[-- Attachment #1: Type: text/plain, Size: 3399 bytes --]

On Thu, May 07, 2020 at 07:39:53PM +0200, Philippe Mathieu-Daudé wrote:
> Move these generic functions to a more common place, with other
> functions related to host page size. Document a little.
> 
> Cc: Alexey Kardashevskiy <aik@ozlabs.ru>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

ppc parts
Acked-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  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(-)
> 
> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
> index 06096e8c6a..195b67d3c8 100644
> --- a/include/exec/ram_addr.h
> +++ b/include/exec/ram_addr.h
> @@ -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
> diff --git a/include/qemu-common.h b/include/qemu-common.h
> index d0142f29ac..2821a6ef76 100644
> --- a/include/qemu-common.h
> +++ b/include/qemu-common.h
> @@ -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,
> diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
> index eb54f94227..33a802a103 100644
> --- a/hw/ppc/spapr_caps.c
> +++ b/hw/ppc/spapr_caps.c
> @@ -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"
> diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
> index f660070d22..c009384505 100644
> --- a/hw/s390x/s390-virtio-ccw.c
> +++ b/hw/s390x/s390-virtio-ccw.c
> @@ -12,6 +12,7 @@
>   */
>  
>  #include "qemu/osdep.h"
> +#include "qemu-common.h"
>  #include "qapi/error.h"
>  #include "cpu.h"
>  #include "hw/boards.h"
> diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
> index 2900bd1941..c64db940a7 100644
> --- a/hw/vfio/spapr.c
> +++ b/hw/vfio/spapr.c
> @@ -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"

-- 
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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 07/10] exec: Move all RAMBlock functions to 'exec/ramblock.h'
  2020-05-07 17:39 ` [PATCH 07/10] exec: Move all RAMBlock functions to 'exec/ramblock.h' Philippe Mathieu-Daudé
  2020-05-08  8:08   ` Juan Quintela
  2020-05-08  9:32   ` Cornelia Huck
@ 2020-05-11  1:33   ` David Gibson
  2 siblings, 0 replies; 30+ messages in thread
From: David Gibson @ 2020-05-11  1:33 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Peter Maydell, Cornelia Huck, Alex Williamson,
	Michael S. Tsirkin, qemu-block, David Hildenbrand, Juan Quintela,
	qemu-devel, Max Reitz, Halil Pasic, Christian Borntraeger,
	qemu-s390x, qemu-ppc, Keith Busch, Paolo Bonzini,
	Dr. David Alan Gilbert, Richard Henderson

[-- Attachment #1: Type: text/plain, Size: 20368 bytes --]

On Thu, May 07, 2020 at 07:39:55PM +0200, Philippe Mathieu-Daudé wrote:
> 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.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

ppc parts
Acked-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  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(-)
> 
> diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
> index b47e5630e7..347ceb603b 100644
> --- a/include/exec/cpu-common.h
> +++ b/include/exec/cpu-common.h
> @@ -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 */
> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
> index c61d5188f7..0deffad66f 100644
> --- a/include/exec/ram_addr.h
> +++ b/include/exec/ram_addr.h
> @@ -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))
> diff --git a/include/exec/ramblock.h b/include/exec/ramblock.h
> index 6ac0aa7a89..b6b34141fc 100644
> --- a/include/exec/ramblock.h
> +++ b/include/exec/ramblock.h
> @@ -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
> diff --git a/migration/migration.h b/migration/migration.h
> index 507284e563..73eb210ef5 100644
> --- a/migration/migration.h
> +++ b/migration/migration.h
> @@ -21,6 +21,7 @@
>  #include "qemu/coroutine_int.h"
>  #include "io/channel.h"
>  #include "net/announce.h"
> +#include "exec/ramblock.h"
>  
>  struct PostcopyBlocktimeContext;
>  
> diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
> index 9924e66d1f..15c8ee9110 100644
> --- a/accel/tcg/translate-all.c
> +++ b/accel/tcg/translate-all.c
> @@ -43,8 +43,6 @@
>  #include <libutil.h>
>  #endif
>  #endif
> -#else
> -#include "exec/ram_addr.h"
>  #endif
>  
>  #include "exec/cputlb.h"
> diff --git a/hw/block/nvme.c b/hw/block/nvme.c
> index 21a199e53b..8d8dd7ce80 100644
> --- a/hw/block/nvme.c
> +++ b/hw/block/nvme.c
> @@ -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"
> diff --git a/hw/s390x/s390-stattrib-kvm.c b/hw/s390x/s390-stattrib-kvm.c
> index f89d8d9d16..46ca7e7d1f 100644
> --- a/hw/s390x/s390-stattrib-kvm.c
> +++ b/hw/s390x/s390-stattrib-kvm.c
> @@ -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"
>  
> diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c
> index 58121b9f68..9785d51577 100644
> --- a/hw/s390x/s390-stattrib.c
> +++ b/hw/s390x/s390-stattrib.c
> @@ -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"
>  
> diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
> index c009384505..ade36eda5e 100644
> --- a/hw/s390x/s390-virtio-ccw.c
> +++ b/hw/s390x/s390-virtio-ccw.c
> @@ -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"
> diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
> index ec21e8fbe8..12764d6254 100644
> --- a/hw/virtio/vhost-user.c
> +++ b/hw/virtio/vhost-user.c
> @@ -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>
> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> index aff98a0ede..7da8d95a43 100644
> --- a/hw/virtio/vhost.c
> +++ b/hw/virtio/vhost.c
> @@ -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"
> diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
> index a4729f7fc9..ea112e9403 100644
> --- a/hw/virtio/virtio-balloon.c
> +++ b/hw/virtio/virtio-balloon.c
> @@ -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"
> diff --git a/memory.c b/memory.c
> index 3e65e33ac4..e8e7bcd6c7 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -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"
> diff --git a/migration/migration.c b/migration/migration.c
> index 177cce9e95..8c7ed8cc79 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -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"
> diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
> index a36402722b..78646abf7a 100644
> --- a/migration/postcopy-ram.c
> +++ b/migration/postcopy-ram.c
> @@ -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"
> diff --git a/migration/savevm.c b/migration/savevm.c
> index b979ea6e7f..714b5b4591 100644
> --- a/migration/savevm.c
> +++ b/migration/savevm.c
> @@ -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"
> diff --git a/stubs/ram-block.c b/stubs/ram-block.c
> index 73c0a3ee08..9e73543598 100644
> --- a/stubs/ram-block.c
> +++ b/stubs/ram-block.c
> @@ -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)
>  {
> diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
> index 2692f76130..1f3db517db 100644
> --- a/target/ppc/kvm.c
> +++ b/target/ppc/kvm.c
> @@ -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"
> diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
> index 69881a0da0..42657bc0a5 100644
> --- a/target/s390x/kvm.c
> +++ b/target/s390x/kvm.c
> @@ -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"
> diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
> index e399e330e2..2ee169da58 100644
> --- a/util/vfio-helpers.c
> +++ b/util/vfio-helpers.c
> @@ -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"

-- 
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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 10/10] exec: Move cpu_physical_memory_* functions to 'exec/memory-internal.h'
  2020-05-07 17:39 ` [PATCH 10/10] exec: Move cpu_physical_memory_* functions to 'exec/memory-internal.h' Philippe Mathieu-Daudé
  2020-05-08  8:12   ` Juan Quintela
@ 2020-05-11  1:35   ` David Gibson
  1 sibling, 0 replies; 30+ messages in thread
From: David Gibson @ 2020-05-11  1:35 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Peter Maydell, Cornelia Huck, Alex Williamson,
	Michael S. Tsirkin, qemu-block, David Hildenbrand, Juan Quintela,
	qemu-devel, Max Reitz, Halil Pasic, Christian Borntraeger,
	qemu-s390x, qemu-ppc, Keith Busch, Paolo Bonzini,
	Dr. David Alan Gilbert, Richard Henderson

[-- Attachment #1: Type: text/plain, Size: 26773 bytes --]

On Thu, May 07, 2020 at 07:39:58PM +0200, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

ppc parts
Acked-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  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(-)
> 
> diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h
> index b2b7c1e78a..4abb3bbd85 100644
> --- a/include/exec/memory-internal.h
> +++ b/include/exec/memory-internal.h
> @@ -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
> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
> index 6acde47a0f..64bf28a332 100644
> --- a/include/exec/ram_addr.h
> +++ b/include/exec/ram_addr.h
> @@ -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
> diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c
> index e3b5750c3b..922671f246 100644
> --- a/accel/tcg/cputlb.c
> +++ b/accel/tcg/cputlb.c
> @@ -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"
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index c18eab0a23..d7c3bf3932 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -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"
> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> index 61b84a392d..8d9aeba6e6 100644
> --- a/hw/ppc/spapr_pci.c
> +++ b/hw/ppc/spapr_pci.c
> @@ -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"
> diff --git a/memory.c b/memory.c
> index e8e7bcd6c7..4e1d19c5fc 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -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"

-- 
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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2020-05-11  1:48 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-07 17:39 [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic Philippe Mathieu-Daudé
2020-05-07 17:39 ` [PATCH 01/10] exec: Rename qemu_ram_writeback() as qemu_ram_msync() Philippe Mathieu-Daudé
2020-05-08  7:59   ` Juan Quintela
2020-05-07 17:39 ` [PATCH 02/10] exec/ramblock: Add missing 'qemu/rcu.h' include Philippe Mathieu-Daudé
2020-05-08  7:59   ` Juan Quintela
2020-05-07 17:39 ` [PATCH 03/10] exec: Move tb_invalidate_phys_range() to 'exec/exec-all.h' Philippe Mathieu-Daudé
2020-05-07 17:39 ` [PATCH 04/10] exec/memory-internal: Check CONFIG_SOFTMMU instead of CONFIG_USER_ONLY Philippe Mathieu-Daudé
2020-05-08  8:01   ` Juan Quintela
2020-05-07 17:39 ` [PATCH 05/10] exec: Move qemu_minrampagesize/qemu_maxrampagesize to 'qemu-common.h' Philippe Mathieu-Daudé
2020-05-08  8:03   ` Juan Quintela
2020-05-08  9:09   ` Cornelia Huck
2020-05-11  1:32   ` David Gibson
2020-05-07 17:39 ` [PATCH 06/10] exec: Move ramblock_recv_bitmap_offset() to migration/ram.c Philippe Mathieu-Daudé
2020-05-08  8:07   ` Juan Quintela
2020-05-08  9:27     ` Philippe Mathieu-Daudé
2020-05-07 17:39 ` [PATCH 07/10] exec: Move all RAMBlock functions to 'exec/ramblock.h' Philippe Mathieu-Daudé
2020-05-08  8:08   ` Juan Quintela
2020-05-08  9:32   ` Cornelia Huck
2020-05-11  1:33   ` David Gibson
2020-05-07 17:39 ` [PATCH 08/10] hw/block: Let the NVMe emulated device be target-agnostic Philippe Mathieu-Daudé
2020-05-07 17:42   ` Philippe Mathieu-Daudé
2020-05-08  8:09   ` Juan Quintela
2020-05-07 17:39 ` [PATCH 09/10] exec: Update coding style to make checkpatch.pl happy Philippe Mathieu-Daudé
2020-05-08  9:05   ` Juan Quintela
2020-05-07 17:39 ` [PATCH 10/10] exec: Move cpu_physical_memory_* functions to 'exec/memory-internal.h' Philippe Mathieu-Daudé
2020-05-08  8:12   ` Juan Quintela
2020-05-11  1:35   ` David Gibson
2020-05-07 22:15 ` [PATCH 00/10] exec: Shear 'exec/ram_addr.h' and make NVMe device target-agnostic Paolo Bonzini
2020-05-08  8:21   ` Juan Quintela
2020-05-08  6:19 ` no-reply

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.