QEMU-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/2] cleanup on page size
@ 2019-10-13  2:11 Wei Yang
  2019-10-13  2:11 ` [PATCH 1/2] cpu: use ROUND_UP() to define xxx_PAGE_ALIGN Wei Yang
                   ` (3 more replies)
  0 siblings, 4 replies; 23+ messages in thread
From: Wei Yang @ 2019-10-13  2:11 UTC (permalink / raw)
  To: pbonzini, ehabkost, imammedo, kwolf, mreitz, stefanha, fam, den,
	marcandre.lureau, kraxel, mst, rth, cohuck, pasic, borntraeger,
	mark.cave-ayland, david, yuval.shaia, marcel.apfelbaum,
	alex.williamson, quintela, dgilbert, armbru, sw
  Cc: qemu-s390x, qemu-ppc, qemu-devel, qemu-block, Wei Yang

Patch 1 simplify the definition of xxx_PAGE_ALIGN.
Patch 2 replaces getpagesize() with qemu_real_host_page_size. This one touch a
volume of code. If some point is not correct, I'd appreciate your
notification.

Wei Yang (2):
  cpu: use ROUND_UP() to define xxx_PAGE_ALIGN
  core: replace getpagesize() with qemu_real_host_page_size

 accel/kvm/kvm-all.c            |  6 +++---
 backends/hostmem.c             |  2 +-
 block.c                        |  4 ++--
 block/file-posix.c             |  9 +++++----
 block/io.c                     |  2 +-
 block/parallels.c              |  2 +-
 block/qcow2-cache.c            |  2 +-
 contrib/vhost-user-gpu/vugbm.c |  2 +-
 exec.c                         |  6 +++---
 hw/intc/s390_flic_kvm.c        |  2 +-
 hw/ppc/mac_newworld.c          |  2 +-
 hw/ppc/spapr_pci.c             |  2 +-
 hw/rdma/vmw/pvrdma_main.c      |  2 +-
 hw/vfio/spapr.c                |  7 ++++---
 include/exec/cpu-all.h         |  7 +++----
 include/exec/ram_addr.h        |  2 +-
 include/qemu/osdep.h           |  4 ++--
 migration/migration.c          |  2 +-
 migration/postcopy-ram.c       |  4 ++--
 monitor/misc.c                 |  2 +-
 target/ppc/kvm.c               |  2 +-
 tests/vhost-user-bridge.c      |  8 ++++----
 util/mmap-alloc.c              | 10 +++++-----
 util/oslib-posix.c             |  4 ++--
 util/oslib-win32.c             |  2 +-
 util/vfio-helpers.c            | 12 ++++++------
 26 files changed, 55 insertions(+), 54 deletions(-)

-- 
2.17.1



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

* [PATCH 1/2] cpu: use ROUND_UP() to define xxx_PAGE_ALIGN
  2019-10-13  2:11 [PATCH 0/2] cleanup on page size Wei Yang
@ 2019-10-13  2:11 ` Wei Yang
  2019-10-13  6:34   ` Michael S. Tsirkin
                     ` (3 more replies)
  2019-10-13  2:11 ` [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size Wei Yang
                   ` (2 subsequent siblings)
  3 siblings, 4 replies; 23+ messages in thread
From: Wei Yang @ 2019-10-13  2:11 UTC (permalink / raw)
  To: pbonzini, ehabkost, imammedo, kwolf, mreitz, stefanha, fam, den,
	marcandre.lureau, kraxel, mst, rth, cohuck, pasic, borntraeger,
	mark.cave-ayland, david, yuval.shaia, marcel.apfelbaum,
	alex.williamson, quintela, dgilbert, armbru, sw
  Cc: qemu-s390x, qemu-ppc, qemu-devel, qemu-block, Wei Yang

Use ROUND_UP() to define, which is a little bit easy to read.

Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
---
 include/exec/cpu-all.h | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index ad9ab85eb3..255bb186ac 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -220,7 +220,7 @@ extern int target_page_bits;
 
 #define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS)
 #define TARGET_PAGE_MASK ~(TARGET_PAGE_SIZE - 1)
-#define TARGET_PAGE_ALIGN(addr) (((addr) + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK)
+#define TARGET_PAGE_ALIGN(addr) ROUND_UP((addr), TARGET_PAGE_SIZE)
 
 /* Using intptr_t ensures that qemu_*_page_mask is sign-extended even
  * when intptr_t is 32-bit and we are aligning a long long.
@@ -228,9 +228,8 @@ extern int target_page_bits;
 extern uintptr_t qemu_host_page_size;
 extern intptr_t qemu_host_page_mask;
 
-#define HOST_PAGE_ALIGN(addr) (((addr) + qemu_host_page_size - 1) & qemu_host_page_mask)
-#define REAL_HOST_PAGE_ALIGN(addr) (((addr) + qemu_real_host_page_size - 1) & \
-                                    qemu_real_host_page_mask)
+#define HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_host_page_size)
+#define REAL_HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_real_host_page_size)
 
 /* same as PROT_xxx */
 #define PAGE_READ      0x0001
-- 
2.17.1



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

* [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size
  2019-10-13  2:11 [PATCH 0/2] cleanup on page size Wei Yang
  2019-10-13  2:11 ` [PATCH 1/2] cpu: use ROUND_UP() to define xxx_PAGE_ALIGN Wei Yang
@ 2019-10-13  2:11 ` Wei Yang
  2019-10-13  6:35   ` Michael S. Tsirkin
                     ` (5 more replies)
  2019-10-13  6:36 ` [PATCH 0/2] cleanup on page size Michael S. Tsirkin
  2019-10-14 21:59 ` Wei Yang
  3 siblings, 6 replies; 23+ messages in thread
From: Wei Yang @ 2019-10-13  2:11 UTC (permalink / raw)
  To: pbonzini, ehabkost, imammedo, kwolf, mreitz, stefanha, fam, den,
	marcandre.lureau, kraxel, mst, rth, cohuck, pasic, borntraeger,
	mark.cave-ayland, david, yuval.shaia, marcel.apfelbaum,
	alex.williamson, quintela, dgilbert, armbru, sw
  Cc: qemu-s390x, qemu-ppc, qemu-devel, qemu-block, Wei Yang

There are three page size in qemu:

  real host page size
  host page size
  target page size

All of them have dedicate variable to represent. For the last two, we
use the same form in the whole qemu project, while for the first one we
use two forms: qemu_real_host_page_size and getpagesize().

qemu_real_host_page_size is defined to be a replacement of
getpagesize(), so let it serve the role.

[Note] Not fully tested for some arch or device.

Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
---
 accel/kvm/kvm-all.c            |  6 +++---
 backends/hostmem.c             |  2 +-
 block.c                        |  4 ++--
 block/file-posix.c             |  9 +++++----
 block/io.c                     |  2 +-
 block/parallels.c              |  2 +-
 block/qcow2-cache.c            |  2 +-
 contrib/vhost-user-gpu/vugbm.c |  2 +-
 exec.c                         |  6 +++---
 hw/intc/s390_flic_kvm.c        |  2 +-
 hw/ppc/mac_newworld.c          |  2 +-
 hw/ppc/spapr_pci.c             |  2 +-
 hw/rdma/vmw/pvrdma_main.c      |  2 +-
 hw/vfio/spapr.c                |  7 ++++---
 include/exec/ram_addr.h        |  2 +-
 include/qemu/osdep.h           |  4 ++--
 migration/migration.c          |  2 +-
 migration/postcopy-ram.c       |  4 ++--
 monitor/misc.c                 |  2 +-
 target/ppc/kvm.c               |  2 +-
 tests/vhost-user-bridge.c      |  8 ++++----
 util/mmap-alloc.c              | 10 +++++-----
 util/oslib-posix.c             |  4 ++--
 util/oslib-win32.c             |  2 +-
 util/vfio-helpers.c            | 12 ++++++------
 25 files changed, 52 insertions(+), 50 deletions(-)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index d2d96d73e8..140b0bd8f6 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -52,7 +52,7 @@
 /* KVM uses PAGE_SIZE in its definition of KVM_COALESCED_MMIO_MAX. We
  * need to use the real host PAGE_SIZE, as that's what KVM will use.
  */
-#define PAGE_SIZE getpagesize()
+#define PAGE_SIZE qemu_real_host_page_size
 
 //#define DEBUG_KVM
 
@@ -507,7 +507,7 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section,
 {
     ram_addr_t start = section->offset_within_region +
                        memory_region_get_ram_addr(section->mr);
-    ram_addr_t pages = int128_get64(section->size) / getpagesize();
+    ram_addr_t pages = int128_get64(section->size) / qemu_real_host_page_size;
 
     cpu_physical_memory_set_dirty_lebitmap(bitmap, start, pages);
     return 0;
@@ -1841,7 +1841,7 @@ static int kvm_init(MachineState *ms)
      * even with KVM.  TARGET_PAGE_SIZE is assumed to be the minimum
      * page size for the system though.
      */
-    assert(TARGET_PAGE_SIZE <= getpagesize());
+    assert(TARGET_PAGE_SIZE <= qemu_real_host_page_size);
 
     s->sigmask_len = 8;
 
diff --git a/backends/hostmem.c b/backends/hostmem.c
index 6d333dc23c..e773bdfa6e 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -304,7 +304,7 @@ size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
 #else
 size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
 {
-    return getpagesize();
+    return qemu_real_host_page_size;
 }
 #endif
 
diff --git a/block.c b/block.c
index 5944124845..98f47e2902 100644
--- a/block.c
+++ b/block.c
@@ -106,7 +106,7 @@ size_t bdrv_opt_mem_align(BlockDriverState *bs)
 {
     if (!bs || !bs->drv) {
         /* page size or 4k (hdd sector size) should be on the safe side */
-        return MAX(4096, getpagesize());
+        return MAX(4096, qemu_real_host_page_size);
     }
 
     return bs->bl.opt_mem_alignment;
@@ -116,7 +116,7 @@ size_t bdrv_min_mem_align(BlockDriverState *bs)
 {
     if (!bs || !bs->drv) {
         /* page size or 4k (hdd sector size) should be on the safe side */
-        return MAX(4096, getpagesize());
+        return MAX(4096, qemu_real_host_page_size);
     }
 
     return bs->bl.min_mem_alignment;
diff --git a/block/file-posix.c b/block/file-posix.c
index f12c06de2d..f60ac3f93f 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -322,7 +322,7 @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp)
 {
     BDRVRawState *s = bs->opaque;
     char *buf;
-    size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize());
+    size_t max_align = MAX(MAX_BLOCKSIZE, qemu_real_host_page_size);
     size_t alignments[] = {1, 512, 1024, 2048, 4096};
 
     /* For SCSI generic devices the alignment is not really used.
@@ -1131,13 +1131,14 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
 
         ret = sg_get_max_segments(s->fd);
         if (ret > 0) {
-            bs->bl.max_transfer = MIN(bs->bl.max_transfer, ret * getpagesize());
+            bs->bl.max_transfer = MIN(bs->bl.max_transfer,
+                                      ret * qemu_real_host_page_size);
         }
     }
 
     raw_probe_alignment(bs, s->fd, errp);
     bs->bl.min_mem_alignment = s->buf_align;
-    bs->bl.opt_mem_alignment = MAX(s->buf_align, getpagesize());
+    bs->bl.opt_mem_alignment = MAX(s->buf_align, qemu_real_host_page_size);
 }
 
 static int check_for_dasd(int fd)
@@ -1700,7 +1701,7 @@ static int allocate_first_block(int fd, size_t max_size)
     size_t write_size = (max_size < MAX_BLOCKSIZE)
         ? BDRV_SECTOR_SIZE
         : MAX_BLOCKSIZE;
-    size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize());
+    size_t max_align = MAX(MAX_BLOCKSIZE, qemu_real_host_page_size);
     void *buf;
     ssize_t n;
     int ret;
diff --git a/block/io.c b/block/io.c
index 4f9ee97c2b..a201c8721a 100644
--- a/block/io.c
+++ b/block/io.c
@@ -159,7 +159,7 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error **errp)
         bdrv_merge_limits(&bs->bl, &bs->file->bs->bl);
     } else {
         bs->bl.min_mem_alignment = 512;
-        bs->bl.opt_mem_alignment = getpagesize();
+        bs->bl.opt_mem_alignment = qemu_real_host_page_size;
 
         /* Safe default since most protocols use readv()/writev()/etc */
         bs->bl.max_iov = IOV_MAX;
diff --git a/block/parallels.c b/block/parallels.c
index 7cd2714b69..f1dfb03eef 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -847,7 +847,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
         }
     }
 
-    s->bat_dirty_block = 4 * getpagesize();
+    s->bat_dirty_block = 4 * qemu_real_host_page_size;
     s->bat_dirty_bmap =
         bitmap_new(DIV_ROUND_UP(s->header_size, s->bat_dirty_block));
 
diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
index d29b038a67..7444b9c4ab 100644
--- a/block/qcow2-cache.c
+++ b/block/qcow2-cache.c
@@ -74,7 +74,7 @@ static void qcow2_cache_table_release(Qcow2Cache *c, int i, int num_tables)
 /* Using MADV_DONTNEED to discard memory is a Linux-specific feature */
 #ifdef CONFIG_LINUX
     void *t = qcow2_cache_get_table_addr(c, i);
-    int align = getpagesize();
+    int align = qemu_real_host_page_size;
     size_t mem_size = (size_t) c->table_size * num_tables;
     size_t offset = QEMU_ALIGN_UP((uintptr_t) t, align) - (uintptr_t) t;
     size_t length = QEMU_ALIGN_DOWN(mem_size - offset, align);
diff --git a/contrib/vhost-user-gpu/vugbm.c b/contrib/vhost-user-gpu/vugbm.c
index d3bb82ff0e..9c357b6399 100644
--- a/contrib/vhost-user-gpu/vugbm.c
+++ b/contrib/vhost-user-gpu/vugbm.c
@@ -52,7 +52,7 @@ struct udmabuf_create {
 static size_t
 udmabuf_get_size(struct vugbm_buffer *buf)
 {
-    return ROUND_UP(buf->width * buf->height * 4, getpagesize());
+    return ROUND_UP(buf->width * buf->height * 4, qemu_real_host_page_size);
 }
 
 static bool
diff --git a/exec.c b/exec.c
index bdcfcdff3f..27ef36769d 100644
--- a/exec.c
+++ b/exec.c
@@ -1762,11 +1762,11 @@ long qemu_maxrampagesize(void)
 #else
 long qemu_minrampagesize(void)
 {
-    return getpagesize();
+    return qemu_real_host_page_size;
 }
 long qemu_maxrampagesize(void)
 {
-    return getpagesize();
+    return qemu_real_host_page_size;
 }
 #endif
 
@@ -2425,7 +2425,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
     new_block->max_length = max_size;
     assert(max_size >= size);
     new_block->fd = -1;
-    new_block->page_size = getpagesize();
+    new_block->page_size = qemu_real_host_page_size;
     new_block->host = host;
     if (host) {
         new_block->flags |= RAM_PREALLOC;
diff --git a/hw/intc/s390_flic_kvm.c b/hw/intc/s390_flic_kvm.c
index cedccba8a9..c9ee80eaae 100644
--- a/hw/intc/s390_flic_kvm.c
+++ b/hw/intc/s390_flic_kvm.c
@@ -25,7 +25,7 @@
 #include "migration/qemu-file-types.h"
 #include "trace.h"
 
-#define FLIC_SAVE_INITIAL_SIZE getpagesize()
+#define FLIC_SAVE_INITIAL_SIZE qemu_real_host_page_size
 #define FLIC_FAILED (-1UL)
 #define FLIC_SAVEVM_VERSION 1
 
diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
index c5bbcc7433..3594517f0c 100644
--- a/hw/ppc/mac_newworld.c
+++ b/hw/ppc/mac_newworld.c
@@ -439,7 +439,7 @@ static void ppc_core99_init(MachineState *machine)
     }
 
     /* The NewWorld NVRAM is not located in the MacIO device */
-    if (kvm_enabled() && getpagesize() > 4096) {
+    if (kvm_enabled() && qemu_real_host_page_size > 4096) {
         /* We can't combine read-write and read-only in a single page, so
            move the NVRAM out of ROM again for KVM */
         nvram_addr = 0xFFE00000;
diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
index 01ff41d4c4..191b295412 100644
--- a/hw/ppc/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -1942,7 +1942,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
      * our memory slot is of page size granularity.
      */
     if (kvm_enabled()) {
-        msi_window_size = getpagesize();
+        msi_window_size = qemu_real_host_page_size;
     }
 
     memory_region_init_io(&sphb->msiwindow, OBJECT(sphb), &spapr_msi_ops, spapr,
diff --git a/hw/rdma/vmw/pvrdma_main.c b/hw/rdma/vmw/pvrdma_main.c
index 3e36e13013..3722d9e772 100644
--- a/hw/rdma/vmw/pvrdma_main.c
+++ b/hw/rdma/vmw/pvrdma_main.c
@@ -601,7 +601,7 @@ static void pvrdma_realize(PCIDevice *pdev, Error **errp)
     rdma_info_report("Initializing device %s %x.%x", pdev->name,
                      PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
 
-    if (TARGET_PAGE_SIZE != getpagesize()) {
+    if (TARGET_PAGE_SIZE != qemu_real_host_page_size) {
         error_setg(errp, "Target page size must be the same as host page size");
         return;
     }
diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
index e853eebe11..33692fc86f 100644
--- a/hw/vfio/spapr.c
+++ b/hw/vfio/spapr.c
@@ -196,14 +196,15 @@ int vfio_spapr_create_window(VFIOContainer *container,
      * bits_per_level is a safe guess of how much we can allocate per level:
      * 8 is the current minimum for CONFIG_FORCE_MAX_ZONEORDER and MAX_ORDER
      * is usually bigger than that.
-     * Below we look at getpagesize() as TCEs are allocated from system pages.
+     * Below we look at qemu_real_host_page_size as TCEs are allocated from
+     * system pages.
      */
-    bits_per_level = ctz64(getpagesize()) + 8;
+    bits_per_level = ctz64(qemu_real_host_page_size) + 8;
     create.levels = bits_total / bits_per_level;
     if (bits_total % bits_per_level) {
         ++create.levels;
     }
-    max_levels = (64 - create.page_shift) / ctz64(getpagesize());
+    max_levels = (64 - create.page_shift) / ctz64(qemu_real_host_page_size);
     for ( ; create.levels <= max_levels; ++create.levels) {
         ret = ioctl(container->fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &create);
         if (!ret) {
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index e96e621de5..d638941272 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -380,7 +380,7 @@ static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
     hwaddr addr;
     ram_addr_t ram_addr;
     unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
-    unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE;
+    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? */
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index c7d242f476..0f97d68586 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -423,9 +423,9 @@ void qemu_anon_ram_free(void *ptr, size_t size);
 #  define QEMU_VMALLOC_ALIGN (256 * 4096)
 #elif defined(__linux__) && defined(__sparc__)
 #include <sys/shm.h>
-#  define QEMU_VMALLOC_ALIGN MAX(getpagesize(), SHMLBA)
+#  define QEMU_VMALLOC_ALIGN MAX(qemu_real_host_page_size, SHMLBA)
 #else
-#  define QEMU_VMALLOC_ALIGN getpagesize()
+#  define QEMU_VMALLOC_ALIGN qemu_real_host_page_size
 #endif
 
 #ifdef CONFIG_POSIX
diff --git a/migration/migration.c b/migration/migration.c
index ff9504cf28..264da3c88a 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -2288,7 +2288,7 @@ static struct rp_cmd_args {
 static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname,
                                        ram_addr_t start, size_t len)
 {
-    long our_host_ps = getpagesize();
+    long our_host_ps = qemu_real_host_page_size;
 
     trace_migrate_handle_rp_req_pages(rbname, start, len);
 
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index 1f63e65ed7..5f6eec1276 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -308,7 +308,7 @@ static bool ufd_check_and_apply(int ufd, MigrationIncomingState *mis)
         return false;
     }
 
-    if (getpagesize() != ram_pagesize_summary()) {
+    if (qemu_real_host_page_size != ram_pagesize_summary()) {
         bool have_hp = false;
         /* We've got a huge page */
 #ifdef UFFD_FEATURE_MISSING_HUGETLBFS
@@ -346,7 +346,7 @@ static int test_ramblock_postcopiable(RAMBlock *rb, void *opaque)
  */
 bool postcopy_ram_supported_by_host(MigrationIncomingState *mis)
 {
-    long pagesize = getpagesize();
+    long pagesize = qemu_real_host_page_size;
     int ufd = -1;
     bool ret = false; /* Error unless we change it */
     void *testarea = NULL;
diff --git a/monitor/misc.c b/monitor/misc.c
index aef16f6cfb..3baa15f3bf 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -862,7 +862,7 @@ static uint64_t vtop(void *ptr, Error **errp)
     uint64_t pinfo;
     uint64_t ret = -1;
     uintptr_t addr = (uintptr_t) ptr;
-    uintptr_t pagesize = getpagesize();
+    uintptr_t pagesize = qemu_real_host_page_size;
     off_t offset = addr / pagesize * sizeof(pinfo);
     int fd;
 
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
index 820724cc7d..7d2e8969ac 100644
--- a/target/ppc/kvm.c
+++ b/target/ppc/kvm.c
@@ -411,7 +411,7 @@ void kvm_check_mmu(PowerPCCPU *cpu, Error **errp)
          * will be a normal mapping, not a special hugepage one used
          * for RAM.
          */
-        if (getpagesize() < 0x10000) {
+        if (qemu_real_host_page_size < 0x10000) {
             error_setg(errp,
                        "KVM can't supply 64kiB CI pages, which guest expects");
         }
diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
index c4e350e1f5..6c3d490611 100644
--- a/tests/vhost-user-bridge.c
+++ b/tests/vhost-user-bridge.c
@@ -468,8 +468,8 @@ vubr_queue_set_started(VuDev *dev, int qidx, bool started)
 
     if (started && vubr->notifier.fd >= 0) {
         vu_set_queue_host_notifier(dev, vq, vubr->notifier.fd,
-                                   getpagesize(),
-                                   qidx * getpagesize());
+                                   qemu_real_host_page_size,
+                                   qidx * qemu_real_host_page_size);
     }
 
     if (qidx % 2 == 1) {
@@ -594,7 +594,7 @@ static void *notifier_thread(void *arg)
 {
     VuDev *dev = (VuDev *)arg;
     VubrDev *vubr = container_of(dev, VubrDev, vudev);
-    int pagesize = getpagesize();
+    int pagesize = qemu_real_host_page_size;
     int qidx;
 
     while (true) {
@@ -630,7 +630,7 @@ vubr_host_notifier_setup(VubrDev *dev)
     void *addr;
     int fd;
 
-    length = getpagesize() * VHOST_USER_BRIDGE_MAX_QUEUES;
+    length = qemu_real_host_page_size * VHOST_USER_BRIDGE_MAX_QUEUES;
 
     fd = mkstemp(template);
     if (fd < 0) {
diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
index f7f177d0ea..27dcccd8ec 100644
--- a/util/mmap-alloc.c
+++ b/util/mmap-alloc.c
@@ -48,7 +48,7 @@ size_t qemu_fd_getpagesize(int fd)
 #endif
 #endif
 
-    return getpagesize();
+    return qemu_real_host_page_size;
 }
 
 size_t qemu_mempath_getpagesize(const char *mem_path)
@@ -79,7 +79,7 @@ size_t qemu_mempath_getpagesize(const char *mem_path)
 #endif
 #endif
 
-    return getpagesize();
+    return qemu_real_host_page_size;
 }
 
 void *qemu_ram_mmap(int fd,
@@ -114,7 +114,7 @@ void *qemu_ram_mmap(int fd,
      */
     flags = MAP_PRIVATE;
     pagesize = qemu_fd_getpagesize(fd);
-    if (fd == -1 || pagesize == getpagesize()) {
+    if (fd == -1 || pagesize == qemu_real_host_page_size) {
         guardfd = -1;
         flags |= MAP_ANONYMOUS;
     } else {
@@ -123,7 +123,7 @@ void *qemu_ram_mmap(int fd,
     }
 #else
     guardfd = -1;
-    pagesize = getpagesize();
+    pagesize = qemu_real_host_page_size;
     flags = MAP_PRIVATE | MAP_ANONYMOUS;
 #endif
 
@@ -205,7 +205,7 @@ void qemu_ram_munmap(int fd, void *ptr, size_t size)
 #if defined(__powerpc64__) && defined(__linux__)
         pagesize = qemu_fd_getpagesize(fd);
 #else
-        pagesize = getpagesize();
+        pagesize = qemu_real_host_page_size;
 #endif
         munmap(ptr, size + pagesize);
     }
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index f8693384fc..5a291cc982 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -617,7 +617,7 @@ void *qemu_alloc_stack(size_t *sz)
 #ifdef CONFIG_DEBUG_STACK_USAGE
     void *ptr2;
 #endif
-    size_t pagesz = getpagesize();
+    size_t pagesz = qemu_real_host_page_size;
 #ifdef _SC_THREAD_STACK_MIN
     /* avoid stacks smaller than _SC_THREAD_STACK_MIN */
     long min_stack_sz = sysconf(_SC_THREAD_STACK_MIN);
@@ -679,7 +679,7 @@ void qemu_free_stack(void *stack, size_t sz)
     unsigned int usage;
     void *ptr;
 
-    for (ptr = stack + getpagesize(); ptr < stack + sz;
+    for (ptr = stack + qemu_real_host_page_size; ptr < stack + sz;
          ptr += sizeof(uint32_t)) {
         if (*(uint32_t *)ptr != 0xdeadbeaf) {
             break;
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index 886e400d6a..e9b14ab178 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -554,7 +554,7 @@ void os_mem_prealloc(int fd, char *area, size_t memory, int smp_cpus,
                      Error **errp)
 {
     int i;
-    size_t pagesize = getpagesize();
+    size_t pagesize = qemu_real_host_page_size;
 
     memory = (memory + pagesize - 1) & -pagesize;
     for (i = 0; i < memory / pagesize; i++) {
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
index 26ffd0d6b5..813f7ec564 100644
--- a/util/vfio-helpers.c
+++ b/util/vfio-helpers.c
@@ -514,9 +514,9 @@ static IOVAMapping *qemu_vfio_add_mapping(QEMUVFIOState *s,
     IOVAMapping m = {.host = host, .size = size, .iova = iova};
     IOVAMapping *insert;
 
-    assert(QEMU_IS_ALIGNED(size, getpagesize()));
-    assert(QEMU_IS_ALIGNED(s->low_water_mark, getpagesize()));
-    assert(QEMU_IS_ALIGNED(s->high_water_mark, getpagesize()));
+    assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size));
+    assert(QEMU_IS_ALIGNED(s->low_water_mark, qemu_real_host_page_size));
+    assert(QEMU_IS_ALIGNED(s->high_water_mark, qemu_real_host_page_size));
     trace_qemu_vfio_new_mapping(s, host, size, index, iova);
 
     assert(index >= 0);
@@ -567,7 +567,7 @@ static void qemu_vfio_undo_mapping(QEMUVFIOState *s, IOVAMapping *mapping,
 
     index = mapping - s->mappings;
     assert(mapping->size > 0);
-    assert(QEMU_IS_ALIGNED(mapping->size, getpagesize()));
+    assert(QEMU_IS_ALIGNED(mapping->size, qemu_real_host_page_size));
     assert(index >= 0 && index < s->nr_mappings);
     if (ioctl(s->container, VFIO_IOMMU_UNMAP_DMA, &unmap)) {
         error_setg(errp, "VFIO_UNMAP_DMA failed: %d", -errno);
@@ -613,8 +613,8 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
     IOVAMapping *mapping;
     uint64_t iova0;
 
-    assert(QEMU_PTR_IS_ALIGNED(host, getpagesize()));
-    assert(QEMU_IS_ALIGNED(size, getpagesize()));
+    assert(QEMU_PTR_IS_ALIGNED(host, qemu_real_host_page_size));
+    assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size));
     trace_qemu_vfio_dma_map(s, host, size, temporary, iova);
     qemu_mutex_lock(&s->lock);
     mapping = qemu_vfio_find_mapping(s, host, &index);
-- 
2.17.1



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

* Re: [PATCH 1/2] cpu: use ROUND_UP() to define xxx_PAGE_ALIGN
  2019-10-13  2:11 ` [PATCH 1/2] cpu: use ROUND_UP() to define xxx_PAGE_ALIGN Wei Yang
@ 2019-10-13  6:34   ` Michael S. Tsirkin
  2019-10-13  9:27   ` David Gibson
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 23+ messages in thread
From: Michael S. Tsirkin @ 2019-10-13  6:34 UTC (permalink / raw)
  To: Wei Yang
  Cc: fam, mark.cave-ayland, qemu-devel, kraxel, den, qemu-block,
	quintela, armbru, pasic, borntraeger, marcandre.lureau, rth,
	ehabkost, sw, dgilbert, yuval.shaia, alex.williamson, stefanha,
	pbonzini, david, kwolf, cohuck, qemu-s390x, mreitz, qemu-ppc,
	imammedo

On Sun, Oct 13, 2019 at 10:11:44AM +0800, Wei Yang wrote:
> Use ROUND_UP() to define, which is a little bit easy to read.
> 
> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>

Reviewed-by: Michael S. Tsirkin <mst@redhat.com>

> ---
>  include/exec/cpu-all.h | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
> index ad9ab85eb3..255bb186ac 100644
> --- a/include/exec/cpu-all.h
> +++ b/include/exec/cpu-all.h
> @@ -220,7 +220,7 @@ extern int target_page_bits;
>  
>  #define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS)
>  #define TARGET_PAGE_MASK ~(TARGET_PAGE_SIZE - 1)
> -#define TARGET_PAGE_ALIGN(addr) (((addr) + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK)
> +#define TARGET_PAGE_ALIGN(addr) ROUND_UP((addr), TARGET_PAGE_SIZE)
>  
>  /* Using intptr_t ensures that qemu_*_page_mask is sign-extended even
>   * when intptr_t is 32-bit and we are aligning a long long.
> @@ -228,9 +228,8 @@ extern int target_page_bits;
>  extern uintptr_t qemu_host_page_size;
>  extern intptr_t qemu_host_page_mask;
>  
> -#define HOST_PAGE_ALIGN(addr) (((addr) + qemu_host_page_size - 1) & qemu_host_page_mask)
> -#define REAL_HOST_PAGE_ALIGN(addr) (((addr) + qemu_real_host_page_size - 1) & \
> -                                    qemu_real_host_page_mask)
> +#define HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_host_page_size)
> +#define REAL_HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_real_host_page_size)
>  
>  /* same as PROT_xxx */
>  #define PAGE_READ      0x0001
> -- 
> 2.17.1


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

* Re: [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size
  2019-10-13  2:11 ` [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size Wei Yang
@ 2019-10-13  6:35   ` Michael S. Tsirkin
  2019-10-13  9:28   ` David Gibson
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 23+ messages in thread
From: Michael S. Tsirkin @ 2019-10-13  6:35 UTC (permalink / raw)
  To: Wei Yang
  Cc: fam, mark.cave-ayland, qemu-devel, kraxel, den, qemu-block,
	quintela, armbru, pasic, borntraeger, marcandre.lureau, rth,
	ehabkost, sw, dgilbert, yuval.shaia, alex.williamson, stefanha,
	pbonzini, david, kwolf, cohuck, qemu-s390x, mreitz, qemu-ppc,
	imammedo

On Sun, Oct 13, 2019 at 10:11:45AM +0800, Wei Yang wrote:
> There are three page size in qemu:
> 
>   real host page size
>   host page size
>   target page size
> 
> All of them have dedicate variable to represent. For the last two, we
> use the same form in the whole qemu project, while for the first one we
> use two forms: qemu_real_host_page_size and getpagesize().
> 
> qemu_real_host_page_size is defined to be a replacement of
> getpagesize(), so let it serve the role.
> 
> [Note] Not fully tested for some arch or device.
> 
> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>

Reviewed-by: Michael S. Tsirkin <mst@redhat.com>

> ---
>  accel/kvm/kvm-all.c            |  6 +++---
>  backends/hostmem.c             |  2 +-
>  block.c                        |  4 ++--
>  block/file-posix.c             |  9 +++++----
>  block/io.c                     |  2 +-
>  block/parallels.c              |  2 +-
>  block/qcow2-cache.c            |  2 +-
>  contrib/vhost-user-gpu/vugbm.c |  2 +-
>  exec.c                         |  6 +++---
>  hw/intc/s390_flic_kvm.c        |  2 +-
>  hw/ppc/mac_newworld.c          |  2 +-
>  hw/ppc/spapr_pci.c             |  2 +-
>  hw/rdma/vmw/pvrdma_main.c      |  2 +-
>  hw/vfio/spapr.c                |  7 ++++---
>  include/exec/ram_addr.h        |  2 +-
>  include/qemu/osdep.h           |  4 ++--
>  migration/migration.c          |  2 +-
>  migration/postcopy-ram.c       |  4 ++--
>  monitor/misc.c                 |  2 +-
>  target/ppc/kvm.c               |  2 +-
>  tests/vhost-user-bridge.c      |  8 ++++----
>  util/mmap-alloc.c              | 10 +++++-----
>  util/oslib-posix.c             |  4 ++--
>  util/oslib-win32.c             |  2 +-
>  util/vfio-helpers.c            | 12 ++++++------
>  25 files changed, 52 insertions(+), 50 deletions(-)
> 
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index d2d96d73e8..140b0bd8f6 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -52,7 +52,7 @@
>  /* KVM uses PAGE_SIZE in its definition of KVM_COALESCED_MMIO_MAX. We
>   * need to use the real host PAGE_SIZE, as that's what KVM will use.
>   */
> -#define PAGE_SIZE getpagesize()
> +#define PAGE_SIZE qemu_real_host_page_size
>  
>  //#define DEBUG_KVM
>  
> @@ -507,7 +507,7 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section,
>  {
>      ram_addr_t start = section->offset_within_region +
>                         memory_region_get_ram_addr(section->mr);
> -    ram_addr_t pages = int128_get64(section->size) / getpagesize();
> +    ram_addr_t pages = int128_get64(section->size) / qemu_real_host_page_size;
>  
>      cpu_physical_memory_set_dirty_lebitmap(bitmap, start, pages);
>      return 0;
> @@ -1841,7 +1841,7 @@ static int kvm_init(MachineState *ms)
>       * even with KVM.  TARGET_PAGE_SIZE is assumed to be the minimum
>       * page size for the system though.
>       */
> -    assert(TARGET_PAGE_SIZE <= getpagesize());
> +    assert(TARGET_PAGE_SIZE <= qemu_real_host_page_size);
>  
>      s->sigmask_len = 8;
>  
> diff --git a/backends/hostmem.c b/backends/hostmem.c
> index 6d333dc23c..e773bdfa6e 100644
> --- a/backends/hostmem.c
> +++ b/backends/hostmem.c
> @@ -304,7 +304,7 @@ size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
>  #else
>  size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
>  {
> -    return getpagesize();
> +    return qemu_real_host_page_size;
>  }
>  #endif
>  
> diff --git a/block.c b/block.c
> index 5944124845..98f47e2902 100644
> --- a/block.c
> +++ b/block.c
> @@ -106,7 +106,7 @@ size_t bdrv_opt_mem_align(BlockDriverState *bs)
>  {
>      if (!bs || !bs->drv) {
>          /* page size or 4k (hdd sector size) should be on the safe side */
> -        return MAX(4096, getpagesize());
> +        return MAX(4096, qemu_real_host_page_size);
>      }
>  
>      return bs->bl.opt_mem_alignment;
> @@ -116,7 +116,7 @@ size_t bdrv_min_mem_align(BlockDriverState *bs)
>  {
>      if (!bs || !bs->drv) {
>          /* page size or 4k (hdd sector size) should be on the safe side */
> -        return MAX(4096, getpagesize());
> +        return MAX(4096, qemu_real_host_page_size);
>      }
>  
>      return bs->bl.min_mem_alignment;
> diff --git a/block/file-posix.c b/block/file-posix.c
> index f12c06de2d..f60ac3f93f 100644
> --- a/block/file-posix.c
> +++ b/block/file-posix.c
> @@ -322,7 +322,7 @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp)
>  {
>      BDRVRawState *s = bs->opaque;
>      char *buf;
> -    size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize());
> +    size_t max_align = MAX(MAX_BLOCKSIZE, qemu_real_host_page_size);
>      size_t alignments[] = {1, 512, 1024, 2048, 4096};
>  
>      /* For SCSI generic devices the alignment is not really used.
> @@ -1131,13 +1131,14 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
>  
>          ret = sg_get_max_segments(s->fd);
>          if (ret > 0) {
> -            bs->bl.max_transfer = MIN(bs->bl.max_transfer, ret * getpagesize());
> +            bs->bl.max_transfer = MIN(bs->bl.max_transfer,
> +                                      ret * qemu_real_host_page_size);
>          }
>      }
>  
>      raw_probe_alignment(bs, s->fd, errp);
>      bs->bl.min_mem_alignment = s->buf_align;
> -    bs->bl.opt_mem_alignment = MAX(s->buf_align, getpagesize());
> +    bs->bl.opt_mem_alignment = MAX(s->buf_align, qemu_real_host_page_size);
>  }
>  
>  static int check_for_dasd(int fd)
> @@ -1700,7 +1701,7 @@ static int allocate_first_block(int fd, size_t max_size)
>      size_t write_size = (max_size < MAX_BLOCKSIZE)
>          ? BDRV_SECTOR_SIZE
>          : MAX_BLOCKSIZE;
> -    size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize());
> +    size_t max_align = MAX(MAX_BLOCKSIZE, qemu_real_host_page_size);
>      void *buf;
>      ssize_t n;
>      int ret;
> diff --git a/block/io.c b/block/io.c
> index 4f9ee97c2b..a201c8721a 100644
> --- a/block/io.c
> +++ b/block/io.c
> @@ -159,7 +159,7 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error **errp)
>          bdrv_merge_limits(&bs->bl, &bs->file->bs->bl);
>      } else {
>          bs->bl.min_mem_alignment = 512;
> -        bs->bl.opt_mem_alignment = getpagesize();
> +        bs->bl.opt_mem_alignment = qemu_real_host_page_size;
>  
>          /* Safe default since most protocols use readv()/writev()/etc */
>          bs->bl.max_iov = IOV_MAX;
> diff --git a/block/parallels.c b/block/parallels.c
> index 7cd2714b69..f1dfb03eef 100644
> --- a/block/parallels.c
> +++ b/block/parallels.c
> @@ -847,7 +847,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
>          }
>      }
>  
> -    s->bat_dirty_block = 4 * getpagesize();
> +    s->bat_dirty_block = 4 * qemu_real_host_page_size;
>      s->bat_dirty_bmap =
>          bitmap_new(DIV_ROUND_UP(s->header_size, s->bat_dirty_block));
>  
> diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
> index d29b038a67..7444b9c4ab 100644
> --- a/block/qcow2-cache.c
> +++ b/block/qcow2-cache.c
> @@ -74,7 +74,7 @@ static void qcow2_cache_table_release(Qcow2Cache *c, int i, int num_tables)
>  /* Using MADV_DONTNEED to discard memory is a Linux-specific feature */
>  #ifdef CONFIG_LINUX
>      void *t = qcow2_cache_get_table_addr(c, i);
> -    int align = getpagesize();
> +    int align = qemu_real_host_page_size;
>      size_t mem_size = (size_t) c->table_size * num_tables;
>      size_t offset = QEMU_ALIGN_UP((uintptr_t) t, align) - (uintptr_t) t;
>      size_t length = QEMU_ALIGN_DOWN(mem_size - offset, align);
> diff --git a/contrib/vhost-user-gpu/vugbm.c b/contrib/vhost-user-gpu/vugbm.c
> index d3bb82ff0e..9c357b6399 100644
> --- a/contrib/vhost-user-gpu/vugbm.c
> +++ b/contrib/vhost-user-gpu/vugbm.c
> @@ -52,7 +52,7 @@ struct udmabuf_create {
>  static size_t
>  udmabuf_get_size(struct vugbm_buffer *buf)
>  {
> -    return ROUND_UP(buf->width * buf->height * 4, getpagesize());
> +    return ROUND_UP(buf->width * buf->height * 4, qemu_real_host_page_size);
>  }
>  
>  static bool
> diff --git a/exec.c b/exec.c
> index bdcfcdff3f..27ef36769d 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1762,11 +1762,11 @@ long qemu_maxrampagesize(void)
>  #else
>  long qemu_minrampagesize(void)
>  {
> -    return getpagesize();
> +    return qemu_real_host_page_size;
>  }
>  long qemu_maxrampagesize(void)
>  {
> -    return getpagesize();
> +    return qemu_real_host_page_size;
>  }
>  #endif
>  
> @@ -2425,7 +2425,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
>      new_block->max_length = max_size;
>      assert(max_size >= size);
>      new_block->fd = -1;
> -    new_block->page_size = getpagesize();
> +    new_block->page_size = qemu_real_host_page_size;
>      new_block->host = host;
>      if (host) {
>          new_block->flags |= RAM_PREALLOC;
> diff --git a/hw/intc/s390_flic_kvm.c b/hw/intc/s390_flic_kvm.c
> index cedccba8a9..c9ee80eaae 100644
> --- a/hw/intc/s390_flic_kvm.c
> +++ b/hw/intc/s390_flic_kvm.c
> @@ -25,7 +25,7 @@
>  #include "migration/qemu-file-types.h"
>  #include "trace.h"
>  
> -#define FLIC_SAVE_INITIAL_SIZE getpagesize()
> +#define FLIC_SAVE_INITIAL_SIZE qemu_real_host_page_size
>  #define FLIC_FAILED (-1UL)
>  #define FLIC_SAVEVM_VERSION 1
>  
> diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
> index c5bbcc7433..3594517f0c 100644
> --- a/hw/ppc/mac_newworld.c
> +++ b/hw/ppc/mac_newworld.c
> @@ -439,7 +439,7 @@ static void ppc_core99_init(MachineState *machine)
>      }
>  
>      /* The NewWorld NVRAM is not located in the MacIO device */
> -    if (kvm_enabled() && getpagesize() > 4096) {
> +    if (kvm_enabled() && qemu_real_host_page_size > 4096) {
>          /* We can't combine read-write and read-only in a single page, so
>             move the NVRAM out of ROM again for KVM */
>          nvram_addr = 0xFFE00000;
> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> index 01ff41d4c4..191b295412 100644
> --- a/hw/ppc/spapr_pci.c
> +++ b/hw/ppc/spapr_pci.c
> @@ -1942,7 +1942,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
>       * our memory slot is of page size granularity.
>       */
>      if (kvm_enabled()) {
> -        msi_window_size = getpagesize();
> +        msi_window_size = qemu_real_host_page_size;
>      }
>  
>      memory_region_init_io(&sphb->msiwindow, OBJECT(sphb), &spapr_msi_ops, spapr,
> diff --git a/hw/rdma/vmw/pvrdma_main.c b/hw/rdma/vmw/pvrdma_main.c
> index 3e36e13013..3722d9e772 100644
> --- a/hw/rdma/vmw/pvrdma_main.c
> +++ b/hw/rdma/vmw/pvrdma_main.c
> @@ -601,7 +601,7 @@ static void pvrdma_realize(PCIDevice *pdev, Error **errp)
>      rdma_info_report("Initializing device %s %x.%x", pdev->name,
>                       PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
>  
> -    if (TARGET_PAGE_SIZE != getpagesize()) {
> +    if (TARGET_PAGE_SIZE != qemu_real_host_page_size) {
>          error_setg(errp, "Target page size must be the same as host page size");
>          return;
>      }
> diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
> index e853eebe11..33692fc86f 100644
> --- a/hw/vfio/spapr.c
> +++ b/hw/vfio/spapr.c
> @@ -196,14 +196,15 @@ int vfio_spapr_create_window(VFIOContainer *container,
>       * bits_per_level is a safe guess of how much we can allocate per level:
>       * 8 is the current minimum for CONFIG_FORCE_MAX_ZONEORDER and MAX_ORDER
>       * is usually bigger than that.
> -     * Below we look at getpagesize() as TCEs are allocated from system pages.
> +     * Below we look at qemu_real_host_page_size as TCEs are allocated from
> +     * system pages.
>       */
> -    bits_per_level = ctz64(getpagesize()) + 8;
> +    bits_per_level = ctz64(qemu_real_host_page_size) + 8;
>      create.levels = bits_total / bits_per_level;
>      if (bits_total % bits_per_level) {
>          ++create.levels;
>      }
> -    max_levels = (64 - create.page_shift) / ctz64(getpagesize());
> +    max_levels = (64 - create.page_shift) / ctz64(qemu_real_host_page_size);
>      for ( ; create.levels <= max_levels; ++create.levels) {
>          ret = ioctl(container->fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &create);
>          if (!ret) {
> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
> index e96e621de5..d638941272 100644
> --- a/include/exec/ram_addr.h
> +++ b/include/exec/ram_addr.h
> @@ -380,7 +380,7 @@ static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
>      hwaddr addr;
>      ram_addr_t ram_addr;
>      unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
> -    unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE;
> +    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? */
> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> index c7d242f476..0f97d68586 100644
> --- a/include/qemu/osdep.h
> +++ b/include/qemu/osdep.h
> @@ -423,9 +423,9 @@ void qemu_anon_ram_free(void *ptr, size_t size);
>  #  define QEMU_VMALLOC_ALIGN (256 * 4096)
>  #elif defined(__linux__) && defined(__sparc__)
>  #include <sys/shm.h>
> -#  define QEMU_VMALLOC_ALIGN MAX(getpagesize(), SHMLBA)
> +#  define QEMU_VMALLOC_ALIGN MAX(qemu_real_host_page_size, SHMLBA)
>  #else
> -#  define QEMU_VMALLOC_ALIGN getpagesize()
> +#  define QEMU_VMALLOC_ALIGN qemu_real_host_page_size
>  #endif
>  
>  #ifdef CONFIG_POSIX
> diff --git a/migration/migration.c b/migration/migration.c
> index ff9504cf28..264da3c88a 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -2288,7 +2288,7 @@ static struct rp_cmd_args {
>  static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname,
>                                         ram_addr_t start, size_t len)
>  {
> -    long our_host_ps = getpagesize();
> +    long our_host_ps = qemu_real_host_page_size;
>  
>      trace_migrate_handle_rp_req_pages(rbname, start, len);
>  
> diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
> index 1f63e65ed7..5f6eec1276 100644
> --- a/migration/postcopy-ram.c
> +++ b/migration/postcopy-ram.c
> @@ -308,7 +308,7 @@ static bool ufd_check_and_apply(int ufd, MigrationIncomingState *mis)
>          return false;
>      }
>  
> -    if (getpagesize() != ram_pagesize_summary()) {
> +    if (qemu_real_host_page_size != ram_pagesize_summary()) {
>          bool have_hp = false;
>          /* We've got a huge page */
>  #ifdef UFFD_FEATURE_MISSING_HUGETLBFS
> @@ -346,7 +346,7 @@ static int test_ramblock_postcopiable(RAMBlock *rb, void *opaque)
>   */
>  bool postcopy_ram_supported_by_host(MigrationIncomingState *mis)
>  {
> -    long pagesize = getpagesize();
> +    long pagesize = qemu_real_host_page_size;
>      int ufd = -1;
>      bool ret = false; /* Error unless we change it */
>      void *testarea = NULL;
> diff --git a/monitor/misc.c b/monitor/misc.c
> index aef16f6cfb..3baa15f3bf 100644
> --- a/monitor/misc.c
> +++ b/monitor/misc.c
> @@ -862,7 +862,7 @@ static uint64_t vtop(void *ptr, Error **errp)
>      uint64_t pinfo;
>      uint64_t ret = -1;
>      uintptr_t addr = (uintptr_t) ptr;
> -    uintptr_t pagesize = getpagesize();
> +    uintptr_t pagesize = qemu_real_host_page_size;
>      off_t offset = addr / pagesize * sizeof(pinfo);
>      int fd;
>  
> diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
> index 820724cc7d..7d2e8969ac 100644
> --- a/target/ppc/kvm.c
> +++ b/target/ppc/kvm.c
> @@ -411,7 +411,7 @@ void kvm_check_mmu(PowerPCCPU *cpu, Error **errp)
>           * will be a normal mapping, not a special hugepage one used
>           * for RAM.
>           */
> -        if (getpagesize() < 0x10000) {
> +        if (qemu_real_host_page_size < 0x10000) {
>              error_setg(errp,
>                         "KVM can't supply 64kiB CI pages, which guest expects");
>          }
> diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
> index c4e350e1f5..6c3d490611 100644
> --- a/tests/vhost-user-bridge.c
> +++ b/tests/vhost-user-bridge.c
> @@ -468,8 +468,8 @@ vubr_queue_set_started(VuDev *dev, int qidx, bool started)
>  
>      if (started && vubr->notifier.fd >= 0) {
>          vu_set_queue_host_notifier(dev, vq, vubr->notifier.fd,
> -                                   getpagesize(),
> -                                   qidx * getpagesize());
> +                                   qemu_real_host_page_size,
> +                                   qidx * qemu_real_host_page_size);
>      }
>  
>      if (qidx % 2 == 1) {
> @@ -594,7 +594,7 @@ static void *notifier_thread(void *arg)
>  {
>      VuDev *dev = (VuDev *)arg;
>      VubrDev *vubr = container_of(dev, VubrDev, vudev);
> -    int pagesize = getpagesize();
> +    int pagesize = qemu_real_host_page_size;
>      int qidx;
>  
>      while (true) {
> @@ -630,7 +630,7 @@ vubr_host_notifier_setup(VubrDev *dev)
>      void *addr;
>      int fd;
>  
> -    length = getpagesize() * VHOST_USER_BRIDGE_MAX_QUEUES;
> +    length = qemu_real_host_page_size * VHOST_USER_BRIDGE_MAX_QUEUES;
>  
>      fd = mkstemp(template);
>      if (fd < 0) {
> diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
> index f7f177d0ea..27dcccd8ec 100644
> --- a/util/mmap-alloc.c
> +++ b/util/mmap-alloc.c
> @@ -48,7 +48,7 @@ size_t qemu_fd_getpagesize(int fd)
>  #endif
>  #endif
>  
> -    return getpagesize();
> +    return qemu_real_host_page_size;
>  }
>  
>  size_t qemu_mempath_getpagesize(const char *mem_path)
> @@ -79,7 +79,7 @@ size_t qemu_mempath_getpagesize(const char *mem_path)
>  #endif
>  #endif
>  
> -    return getpagesize();
> +    return qemu_real_host_page_size;
>  }
>  
>  void *qemu_ram_mmap(int fd,
> @@ -114,7 +114,7 @@ void *qemu_ram_mmap(int fd,
>       */
>      flags = MAP_PRIVATE;
>      pagesize = qemu_fd_getpagesize(fd);
> -    if (fd == -1 || pagesize == getpagesize()) {
> +    if (fd == -1 || pagesize == qemu_real_host_page_size) {
>          guardfd = -1;
>          flags |= MAP_ANONYMOUS;
>      } else {
> @@ -123,7 +123,7 @@ void *qemu_ram_mmap(int fd,
>      }
>  #else
>      guardfd = -1;
> -    pagesize = getpagesize();
> +    pagesize = qemu_real_host_page_size;
>      flags = MAP_PRIVATE | MAP_ANONYMOUS;
>  #endif
>  
> @@ -205,7 +205,7 @@ void qemu_ram_munmap(int fd, void *ptr, size_t size)
>  #if defined(__powerpc64__) && defined(__linux__)
>          pagesize = qemu_fd_getpagesize(fd);
>  #else
> -        pagesize = getpagesize();
> +        pagesize = qemu_real_host_page_size;
>  #endif
>          munmap(ptr, size + pagesize);
>      }
> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
> index f8693384fc..5a291cc982 100644
> --- a/util/oslib-posix.c
> +++ b/util/oslib-posix.c
> @@ -617,7 +617,7 @@ void *qemu_alloc_stack(size_t *sz)
>  #ifdef CONFIG_DEBUG_STACK_USAGE
>      void *ptr2;
>  #endif
> -    size_t pagesz = getpagesize();
> +    size_t pagesz = qemu_real_host_page_size;
>  #ifdef _SC_THREAD_STACK_MIN
>      /* avoid stacks smaller than _SC_THREAD_STACK_MIN */
>      long min_stack_sz = sysconf(_SC_THREAD_STACK_MIN);
> @@ -679,7 +679,7 @@ void qemu_free_stack(void *stack, size_t sz)
>      unsigned int usage;
>      void *ptr;
>  
> -    for (ptr = stack + getpagesize(); ptr < stack + sz;
> +    for (ptr = stack + qemu_real_host_page_size; ptr < stack + sz;
>           ptr += sizeof(uint32_t)) {
>          if (*(uint32_t *)ptr != 0xdeadbeaf) {
>              break;
> diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> index 886e400d6a..e9b14ab178 100644
> --- a/util/oslib-win32.c
> +++ b/util/oslib-win32.c
> @@ -554,7 +554,7 @@ void os_mem_prealloc(int fd, char *area, size_t memory, int smp_cpus,
>                       Error **errp)
>  {
>      int i;
> -    size_t pagesize = getpagesize();
> +    size_t pagesize = qemu_real_host_page_size;
>  
>      memory = (memory + pagesize - 1) & -pagesize;
>      for (i = 0; i < memory / pagesize; i++) {
> diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
> index 26ffd0d6b5..813f7ec564 100644
> --- a/util/vfio-helpers.c
> +++ b/util/vfio-helpers.c
> @@ -514,9 +514,9 @@ static IOVAMapping *qemu_vfio_add_mapping(QEMUVFIOState *s,
>      IOVAMapping m = {.host = host, .size = size, .iova = iova};
>      IOVAMapping *insert;
>  
> -    assert(QEMU_IS_ALIGNED(size, getpagesize()));
> -    assert(QEMU_IS_ALIGNED(s->low_water_mark, getpagesize()));
> -    assert(QEMU_IS_ALIGNED(s->high_water_mark, getpagesize()));
> +    assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size));
> +    assert(QEMU_IS_ALIGNED(s->low_water_mark, qemu_real_host_page_size));
> +    assert(QEMU_IS_ALIGNED(s->high_water_mark, qemu_real_host_page_size));
>      trace_qemu_vfio_new_mapping(s, host, size, index, iova);
>  
>      assert(index >= 0);
> @@ -567,7 +567,7 @@ static void qemu_vfio_undo_mapping(QEMUVFIOState *s, IOVAMapping *mapping,
>  
>      index = mapping - s->mappings;
>      assert(mapping->size > 0);
> -    assert(QEMU_IS_ALIGNED(mapping->size, getpagesize()));
> +    assert(QEMU_IS_ALIGNED(mapping->size, qemu_real_host_page_size));
>      assert(index >= 0 && index < s->nr_mappings);
>      if (ioctl(s->container, VFIO_IOMMU_UNMAP_DMA, &unmap)) {
>          error_setg(errp, "VFIO_UNMAP_DMA failed: %d", -errno);
> @@ -613,8 +613,8 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
>      IOVAMapping *mapping;
>      uint64_t iova0;
>  
> -    assert(QEMU_PTR_IS_ALIGNED(host, getpagesize()));
> -    assert(QEMU_IS_ALIGNED(size, getpagesize()));
> +    assert(QEMU_PTR_IS_ALIGNED(host, qemu_real_host_page_size));
> +    assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size));
>      trace_qemu_vfio_dma_map(s, host, size, temporary, iova);
>      qemu_mutex_lock(&s->lock);
>      mapping = qemu_vfio_find_mapping(s, host, &index);
> -- 
> 2.17.1


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

* Re: [PATCH 0/2] cleanup on page size
  2019-10-13  2:11 [PATCH 0/2] cleanup on page size Wei Yang
  2019-10-13  2:11 ` [PATCH 1/2] cpu: use ROUND_UP() to define xxx_PAGE_ALIGN Wei Yang
  2019-10-13  2:11 ` [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size Wei Yang
@ 2019-10-13  6:36 ` Michael S. Tsirkin
  2019-10-14 21:59 ` Wei Yang
  3 siblings, 0 replies; 23+ messages in thread
From: Michael S. Tsirkin @ 2019-10-13  6:36 UTC (permalink / raw)
  To: Wei Yang
  Cc: fam, mark.cave-ayland, qemu-devel, kraxel, den, qemu-block,
	quintela, armbru, pasic, borntraeger, marcandre.lureau, rth,
	ehabkost, sw, dgilbert, yuval.shaia, alex.williamson, stefanha,
	pbonzini, david, kwolf, cohuck, qemu-s390x, mreitz, qemu-ppc,
	imammedo

On Sun, Oct 13, 2019 at 10:11:43AM +0800, Wei Yang wrote:
> Patch 1 simplify the definition of xxx_PAGE_ALIGN.
> Patch 2 replaces getpagesize() with qemu_real_host_page_size. This one touch a
> volume of code. If some point is not correct, I'd appreciate your
> notification.


Pls queue at the trivial branch.

> Wei Yang (2):
>   cpu: use ROUND_UP() to define xxx_PAGE_ALIGN
>   core: replace getpagesize() with qemu_real_host_page_size
> 
>  accel/kvm/kvm-all.c            |  6 +++---
>  backends/hostmem.c             |  2 +-
>  block.c                        |  4 ++--
>  block/file-posix.c             |  9 +++++----
>  block/io.c                     |  2 +-
>  block/parallels.c              |  2 +-
>  block/qcow2-cache.c            |  2 +-
>  contrib/vhost-user-gpu/vugbm.c |  2 +-
>  exec.c                         |  6 +++---
>  hw/intc/s390_flic_kvm.c        |  2 +-
>  hw/ppc/mac_newworld.c          |  2 +-
>  hw/ppc/spapr_pci.c             |  2 +-
>  hw/rdma/vmw/pvrdma_main.c      |  2 +-
>  hw/vfio/spapr.c                |  7 ++++---
>  include/exec/cpu-all.h         |  7 +++----
>  include/exec/ram_addr.h        |  2 +-
>  include/qemu/osdep.h           |  4 ++--
>  migration/migration.c          |  2 +-
>  migration/postcopy-ram.c       |  4 ++--
>  monitor/misc.c                 |  2 +-
>  target/ppc/kvm.c               |  2 +-
>  tests/vhost-user-bridge.c      |  8 ++++----
>  util/mmap-alloc.c              | 10 +++++-----
>  util/oslib-posix.c             |  4 ++--
>  util/oslib-win32.c             |  2 +-
>  util/vfio-helpers.c            | 12 ++++++------
>  26 files changed, 55 insertions(+), 54 deletions(-)
> 
> -- 
> 2.17.1


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

* Re: [PATCH 1/2] cpu: use ROUND_UP() to define xxx_PAGE_ALIGN
  2019-10-13  2:11 ` [PATCH 1/2] cpu: use ROUND_UP() to define xxx_PAGE_ALIGN Wei Yang
  2019-10-13  6:34   ` Michael S. Tsirkin
@ 2019-10-13  9:27   ` David Gibson
  2019-10-13 15:56   ` Richard Henderson
  2019-10-14 16:25   ` Juan Quintela
  3 siblings, 0 replies; 23+ messages in thread
From: David Gibson @ 2019-10-13  9:27 UTC (permalink / raw)
  To: Wei Yang
  Cc: fam, mst, mark.cave-ayland, qemu-devel, kraxel, den, qemu-block,
	quintela, armbru, pasic, borntraeger, marcandre.lureau, ehabkost,
	sw, dgilbert, yuval.shaia, alex.williamson, stefanha, pbonzini,
	rth, kwolf, cohuck, qemu-s390x, mreitz, qemu-ppc, imammedo

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

On Sun, Oct 13, 2019 at 10:11:44AM +0800, Wei Yang wrote:
> Use ROUND_UP() to define, which is a little bit easy to read.
> 
> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  include/exec/cpu-all.h | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
> index ad9ab85eb3..255bb186ac 100644
> --- a/include/exec/cpu-all.h
> +++ b/include/exec/cpu-all.h
> @@ -220,7 +220,7 @@ extern int target_page_bits;
>  
>  #define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS)
>  #define TARGET_PAGE_MASK ~(TARGET_PAGE_SIZE - 1)
> -#define TARGET_PAGE_ALIGN(addr) (((addr) + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK)
> +#define TARGET_PAGE_ALIGN(addr) ROUND_UP((addr), TARGET_PAGE_SIZE)
>  
>  /* Using intptr_t ensures that qemu_*_page_mask is sign-extended even
>   * when intptr_t is 32-bit and we are aligning a long long.
> @@ -228,9 +228,8 @@ extern int target_page_bits;
>  extern uintptr_t qemu_host_page_size;
>  extern intptr_t qemu_host_page_mask;
>  
> -#define HOST_PAGE_ALIGN(addr) (((addr) + qemu_host_page_size - 1) & qemu_host_page_mask)
> -#define REAL_HOST_PAGE_ALIGN(addr) (((addr) + qemu_real_host_page_size - 1) & \
> -                                    qemu_real_host_page_mask)
> +#define HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_host_page_size)
> +#define REAL_HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_real_host_page_size)
>  
>  /* same as PROT_xxx */
>  #define PAGE_READ      0x0001

-- 
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] 23+ messages in thread

* Re: [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size
  2019-10-13  2:11 ` [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size Wei Yang
  2019-10-13  6:35   ` Michael S. Tsirkin
@ 2019-10-13  9:28   ` David Gibson
  2019-10-16  1:25     ` Wei Yang
  2019-10-13 16:03   ` Richard Henderson
                     ` (3 subsequent siblings)
  5 siblings, 1 reply; 23+ messages in thread
From: David Gibson @ 2019-10-13  9:28 UTC (permalink / raw)
  To: Wei Yang
  Cc: fam, mst, mark.cave-ayland, qemu-devel, kraxel, den, qemu-block,
	quintela, armbru, pasic, borntraeger, marcandre.lureau, ehabkost,
	sw, dgilbert, yuval.shaia, alex.williamson, stefanha, pbonzini,
	rth, kwolf, cohuck, qemu-s390x, mreitz, qemu-ppc, imammedo

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

On Sun, Oct 13, 2019 at 10:11:45AM +0800, Wei Yang wrote:
> There are three page size in qemu:
> 
>   real host page size
>   host page size
>   target page size
> 
> All of them have dedicate variable to represent. For the last two, we
> use the same form in the whole qemu project, while for the first one we
> use two forms: qemu_real_host_page_size and getpagesize().
> 
> qemu_real_host_page_size is defined to be a replacement of
> getpagesize(), so let it serve the role.
> 
> [Note] Not fully tested for some arch or device.
> 
> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

Although the chances of someone messing this up again are almost 100%.

-- 
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] 23+ messages in thread

* Re: [PATCH 1/2] cpu: use ROUND_UP() to define xxx_PAGE_ALIGN
  2019-10-13  2:11 ` [PATCH 1/2] cpu: use ROUND_UP() to define xxx_PAGE_ALIGN Wei Yang
  2019-10-13  6:34   ` Michael S. Tsirkin
  2019-10-13  9:27   ` David Gibson
@ 2019-10-13 15:56   ` Richard Henderson
  2019-10-13 23:36     ` David Gibson
  2019-10-14  1:01     ` Wei Yang
  2019-10-14 16:25   ` Juan Quintela
  3 siblings, 2 replies; 23+ messages in thread
From: Richard Henderson @ 2019-10-13 15:56 UTC (permalink / raw)
  To: Wei Yang, pbonzini, ehabkost, imammedo, kwolf, mreitz, stefanha,
	fam, den, marcandre.lureau, kraxel, mst, cohuck, pasic,
	borntraeger, mark.cave-ayland, david, yuval.shaia,
	marcel.apfelbaum, alex.williamson, quintela, dgilbert, armbru,
	sw
  Cc: qemu-s390x, qemu-ppc, qemu-devel, qemu-block

On 10/12/19 10:11 PM, Wei Yang wrote:
> Use ROUND_UP() to define, which is a little bit easy to read.
> 
> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
> ---
>  include/exec/cpu-all.h | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
> index ad9ab85eb3..255bb186ac 100644
> --- a/include/exec/cpu-all.h
> +++ b/include/exec/cpu-all.h
> @@ -220,7 +220,7 @@ extern int target_page_bits;
>  
>  #define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS)
>  #define TARGET_PAGE_MASK ~(TARGET_PAGE_SIZE - 1)
> -#define TARGET_PAGE_ALIGN(addr) (((addr) + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK)
> +#define TARGET_PAGE_ALIGN(addr) ROUND_UP((addr), TARGET_PAGE_SIZE)
>  
>  /* Using intptr_t ensures that qemu_*_page_mask is sign-extended even
>   * when intptr_t is 32-bit and we are aligning a long long.
> @@ -228,9 +228,8 @@ extern int target_page_bits;
>  extern uintptr_t qemu_host_page_size;
>  extern intptr_t qemu_host_page_mask;
>  
> -#define HOST_PAGE_ALIGN(addr) (((addr) + qemu_host_page_size - 1) & qemu_host_page_mask)
> -#define REAL_HOST_PAGE_ALIGN(addr) (((addr) + qemu_real_host_page_size - 1) & \
> -                                    qemu_real_host_page_mask)
> +#define HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_host_page_size)
> +#define REAL_HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_real_host_page_size)


No, please.

(1) The compiler does not know that qemu_*host_page_size is a power of 2, and
will generate a real division at runtime.  The same is true for
TARGET_PAGE_SIZE when TARGET_PAGE_BITS_VARY.

(2) The first hunk conflicts with an in-flight patch of mine:

https://lists.gnu.org/archive/html/qemu-devel/2019-09/msg04526.html


r~


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

* Re: [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size
  2019-10-13  2:11 ` [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size Wei Yang
  2019-10-13  6:35   ` Michael S. Tsirkin
  2019-10-13  9:28   ` David Gibson
@ 2019-10-13 16:03   ` Richard Henderson
  2019-10-14  9:15   ` Dr. David Alan Gilbert
                     ` (2 subsequent siblings)
  5 siblings, 0 replies; 23+ messages in thread
From: Richard Henderson @ 2019-10-13 16:03 UTC (permalink / raw)
  To: Wei Yang, pbonzini, ehabkost, imammedo, kwolf, mreitz, stefanha,
	fam, den, marcandre.lureau, kraxel, mst, rth, cohuck, pasic,
	borntraeger, mark.cave-ayland, david, yuval.shaia,
	marcel.apfelbaum, alex.williamson, quintela, dgilbert, armbru,
	sw
  Cc: qemu-s390x, qemu-ppc, qemu-devel, qemu-block

On 10/12/19 10:11 PM, Wei Yang wrote:
> There are three page size in qemu:
> 
>   real host page size
>   host page size
>   target page size
> 
> All of them have dedicate variable to represent. For the last two, we
> use the same form in the whole qemu project, while for the first one we
> use two forms: qemu_real_host_page_size and getpagesize().
> 
> qemu_real_host_page_size is defined to be a replacement of
> getpagesize(), so let it serve the role.
> 
> [Note] Not fully tested for some arch or device.
> 
> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
> ---

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~


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

* Re: [PATCH 1/2] cpu: use ROUND_UP() to define xxx_PAGE_ALIGN
  2019-10-13 15:56   ` Richard Henderson
@ 2019-10-13 23:36     ` David Gibson
  2019-10-14  1:01     ` Wei Yang
  1 sibling, 0 replies; 23+ messages in thread
From: David Gibson @ 2019-10-13 23:36 UTC (permalink / raw)
  To: Richard Henderson
  Cc: fam, mst, mark.cave-ayland, qemu-devel, kraxel, den, qemu-block,
	quintela, armbru, pasic, borntraeger, marcandre.lureau, ehabkost,
	sw, dgilbert, yuval.shaia, alex.williamson, stefanha, pbonzini,
	kwolf, cohuck, qemu-s390x, mreitz, qemu-ppc, Wei Yang, imammedo

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

On Sun, Oct 13, 2019 at 11:56:35AM -0400, Richard Henderson wrote:
> On 10/12/19 10:11 PM, Wei Yang wrote:
> > Use ROUND_UP() to define, which is a little bit easy to read.
> > 
> > Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
> > ---
> >  include/exec/cpu-all.h | 7 +++----
> >  1 file changed, 3 insertions(+), 4 deletions(-)
> > 
> > diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
> > index ad9ab85eb3..255bb186ac 100644
> > --- a/include/exec/cpu-all.h
> > +++ b/include/exec/cpu-all.h
> > @@ -220,7 +220,7 @@ extern int target_page_bits;
> >  
> >  #define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS)
> >  #define TARGET_PAGE_MASK ~(TARGET_PAGE_SIZE - 1)
> > -#define TARGET_PAGE_ALIGN(addr) (((addr) + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK)
> > +#define TARGET_PAGE_ALIGN(addr) ROUND_UP((addr), TARGET_PAGE_SIZE)
> >  
> >  /* Using intptr_t ensures that qemu_*_page_mask is sign-extended even
> >   * when intptr_t is 32-bit and we are aligning a long long.
> > @@ -228,9 +228,8 @@ extern int target_page_bits;
> >  extern uintptr_t qemu_host_page_size;
> >  extern intptr_t qemu_host_page_mask;
> >  
> > -#define HOST_PAGE_ALIGN(addr) (((addr) + qemu_host_page_size - 1) & qemu_host_page_mask)
> > -#define REAL_HOST_PAGE_ALIGN(addr) (((addr) + qemu_real_host_page_size - 1) & \
> > -                                    qemu_real_host_page_mask)
> > +#define HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_host_page_size)
> > +#define REAL_HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_real_host_page_size)
> 
> 
> No, please.
> 
> (1) The compiler does not know that qemu_*host_page_size is a power of 2, and
> will generate a real division at runtime.  The same is true for
> TARGET_PAGE_SIZE when TARGET_PAGE_BITS_VARY.

Ouch, good point, I didn't think of that when I gave an R-b.

> (2) The first hunk conflicts with an in-flight patch of mine:
> 
> https://lists.gnu.org/archive/html/qemu-devel/2019-09/msg04526.html
> 
> 
> r~
> 

-- 
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] 23+ messages in thread

* Re: [PATCH 1/2] cpu: use ROUND_UP() to define xxx_PAGE_ALIGN
  2019-10-13 15:56   ` Richard Henderson
  2019-10-13 23:36     ` David Gibson
@ 2019-10-14  1:01     ` Wei Yang
  2019-10-14  2:38       ` Richard Henderson
  1 sibling, 1 reply; 23+ messages in thread
From: Wei Yang @ 2019-10-14  1:01 UTC (permalink / raw)
  To: Richard Henderson
  Cc: fam, mst, mark.cave-ayland, qemu-devel, kraxel, den, qemu-block,
	quintela, armbru, pasic, borntraeger, marcandre.lureau, ehabkost,
	sw, dgilbert, yuval.shaia, alex.williamson, stefanha, pbonzini,
	david, kwolf, cohuck, qemu-s390x, mreitz, qemu-ppc, Wei Yang,
	imammedo

On Sun, Oct 13, 2019 at 11:56:35AM -0400, Richard Henderson wrote:
>On 10/12/19 10:11 PM, Wei Yang wrote:
>> Use ROUND_UP() to define, which is a little bit easy to read.
>> 
>> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
>> ---
>>  include/exec/cpu-all.h | 7 +++----
>>  1 file changed, 3 insertions(+), 4 deletions(-)
>> 
>> diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
>> index ad9ab85eb3..255bb186ac 100644
>> --- a/include/exec/cpu-all.h
>> +++ b/include/exec/cpu-all.h
>> @@ -220,7 +220,7 @@ extern int target_page_bits;
>>  
>>  #define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS)
>>  #define TARGET_PAGE_MASK ~(TARGET_PAGE_SIZE - 1)
>> -#define TARGET_PAGE_ALIGN(addr) (((addr) + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK)
>> +#define TARGET_PAGE_ALIGN(addr) ROUND_UP((addr), TARGET_PAGE_SIZE)
>>  
>>  /* Using intptr_t ensures that qemu_*_page_mask is sign-extended even
>>   * when intptr_t is 32-bit and we are aligning a long long.
>> @@ -228,9 +228,8 @@ extern int target_page_bits;
>>  extern uintptr_t qemu_host_page_size;
>>  extern intptr_t qemu_host_page_mask;
>>  
>> -#define HOST_PAGE_ALIGN(addr) (((addr) + qemu_host_page_size - 1) & qemu_host_page_mask)
>> -#define REAL_HOST_PAGE_ALIGN(addr) (((addr) + qemu_real_host_page_size - 1) & \
>> -                                    qemu_real_host_page_mask)
>> +#define HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_host_page_size)
>> +#define REAL_HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_real_host_page_size)
>
>
>No, please.
>
>(1) The compiler does not know that qemu_*host_page_size is a power of 2, and
>will generate a real division at runtime.  The same is true for
>TARGET_PAGE_SIZE when TARGET_PAGE_BITS_VARY.
>

Confused

The definition of ROUND_UP is:

#define ROUND_UP(n, d) (((n) + (d) - 1) & -(0 ? (n) : (d)))

Why it will do division? This will be expanded to the same form as the
original code, if my understanding is correct. Would you mind telling me more?

>(2) The first hunk conflicts with an in-flight patch of mine:
>
>https://lists.gnu.org/archive/html/qemu-devel/2019-09/msg04526.html
>
>
>r~

-- 
Wei Yang
Help you, Help me


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

* Re: [PATCH 1/2] cpu: use ROUND_UP() to define xxx_PAGE_ALIGN
  2019-10-14  1:01     ` Wei Yang
@ 2019-10-14  2:38       ` Richard Henderson
  2019-10-14  3:19         ` Wei Yang
  0 siblings, 1 reply; 23+ messages in thread
From: Richard Henderson @ 2019-10-14  2:38 UTC (permalink / raw)
  To: Wei Yang
  Cc: fam, mst, mark.cave-ayland, qemu-devel, kraxel, den, qemu-block,
	quintela, armbru, pasic, borntraeger, marcandre.lureau, ehabkost,
	sw, dgilbert, yuval.shaia, alex.williamson, stefanha, pbonzini,
	david, kwolf, cohuck, qemu-s390x, mreitz, qemu-ppc, imammedo

On 10/13/19 6:01 PM, Wei Yang wrote:
>> No, please.
>>
>> (1) The compiler does not know that qemu_*host_page_size is a power of 2, and
>> will generate a real division at runtime.  The same is true for
>> TARGET_PAGE_SIZE when TARGET_PAGE_BITS_VARY.
>>
> 
> Confused
> 
> The definition of ROUND_UP is:
> 
> #define ROUND_UP(n, d) (((n) + (d) - 1) & -(0 ? (n) : (d)))

Ah, my bad, I did confuse this with QEMU_ALIGN_UP.

Hmm.

	lea	-1(n, size), t
	neg	size
	and	size, t

vs

	mov	mask, t
	not	t
	add	n, t
	and	mask, t

which is what I proposed here

>> https://lists.gnu.org/archive/html/qemu-devel/2019-09/msg04526.html

I'm ok with your version.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~



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

* Re: [PATCH 1/2] cpu: use ROUND_UP() to define xxx_PAGE_ALIGN
  2019-10-14  2:38       ` Richard Henderson
@ 2019-10-14  3:19         ` Wei Yang
  0 siblings, 0 replies; 23+ messages in thread
From: Wei Yang @ 2019-10-14  3:19 UTC (permalink / raw)
  To: Richard Henderson
  Cc: fam, mst, mark.cave-ayland, qemu-devel, kraxel, den, qemu-block,
	quintela, armbru, pasic, borntraeger, marcandre.lureau, ehabkost,
	sw, dgilbert, yuval.shaia, alex.williamson, stefanha, imammedo,
	david, kwolf, cohuck, qemu-s390x, mreitz, qemu-ppc, Wei Yang,
	pbonzini

On Sun, Oct 13, 2019 at 07:38:04PM -0700, Richard Henderson wrote:
>On 10/13/19 6:01 PM, Wei Yang wrote:
>>> No, please.
>>>
>>> (1) The compiler does not know that qemu_*host_page_size is a power of 2, and
>>> will generate a real division at runtime.  The same is true for
>>> TARGET_PAGE_SIZE when TARGET_PAGE_BITS_VARY.
>>>
>> 
>> Confused
>> 
>> The definition of ROUND_UP is:
>> 
>> #define ROUND_UP(n, d) (((n) + (d) - 1) & -(0 ? (n) : (d)))
>
>Ah, my bad, I did confuse this with QEMU_ALIGN_UP.
>
>Hmm.
>
>	lea	-1(n, size), t
>	neg	size
>	and	size, t
>
>vs
>
>	mov	mask, t
>	not	t
>	add	n, t
>	and	mask, t
>
>which is what I proposed here
>
>>> https://lists.gnu.org/archive/html/qemu-devel/2019-09/msg04526.html
>
>I'm ok with your version.
>
>Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>

Thanks for your clarification.

Have a nice day

>
>r~
>

-- 
Wei Yang
Help you, Help me


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

* Re: [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size
  2019-10-13  2:11 ` [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size Wei Yang
                     ` (2 preceding siblings ...)
  2019-10-13 16:03   ` Richard Henderson
@ 2019-10-14  9:15   ` Dr. David Alan Gilbert
  2019-10-14 21:36     ` Wei Yang
  2019-10-15 11:45   ` Yuval Shaia
  2019-10-23  9:19   ` Paolo Bonzini
  5 siblings, 1 reply; 23+ messages in thread
From: Dr. David Alan Gilbert @ 2019-10-14  9:15 UTC (permalink / raw)
  To: Wei Yang
  Cc: fam, mst, mark.cave-ayland, qemu-devel, kraxel, den, qemu-block,
	quintela, armbru, pasic, borntraeger, marcandre.lureau, rth,
	ehabkost, sw, yuval.shaia, alex.williamson, stefanha, pbonzini,
	david, kwolf, cohuck, qemu-s390x, mreitz, qemu-ppc, imammedo

* Wei Yang (richardw.yang@linux.intel.com) wrote:
> There are three page size in qemu:
> 
>   real host page size
>   host page size
>   target page size
> 
> All of them have dedicate variable to represent. For the last two, we
> use the same form in the whole qemu project, while for the first one we
> use two forms: qemu_real_host_page_size and getpagesize().
> 
> qemu_real_host_page_size is defined to be a replacement of
> getpagesize(), so let it serve the role.

We also use sysconf(_SC_PAGESIZE) in a few places.

Dave

> 
> [Note] Not fully tested for some arch or device.
> 
> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
> ---
>  accel/kvm/kvm-all.c            |  6 +++---
>  backends/hostmem.c             |  2 +-
>  block.c                        |  4 ++--
>  block/file-posix.c             |  9 +++++----
>  block/io.c                     |  2 +-
>  block/parallels.c              |  2 +-
>  block/qcow2-cache.c            |  2 +-
>  contrib/vhost-user-gpu/vugbm.c |  2 +-
>  exec.c                         |  6 +++---
>  hw/intc/s390_flic_kvm.c        |  2 +-
>  hw/ppc/mac_newworld.c          |  2 +-
>  hw/ppc/spapr_pci.c             |  2 +-
>  hw/rdma/vmw/pvrdma_main.c      |  2 +-
>  hw/vfio/spapr.c                |  7 ++++---
>  include/exec/ram_addr.h        |  2 +-
>  include/qemu/osdep.h           |  4 ++--
>  migration/migration.c          |  2 +-
>  migration/postcopy-ram.c       |  4 ++--
>  monitor/misc.c                 |  2 +-
>  target/ppc/kvm.c               |  2 +-
>  tests/vhost-user-bridge.c      |  8 ++++----
>  util/mmap-alloc.c              | 10 +++++-----
>  util/oslib-posix.c             |  4 ++--
>  util/oslib-win32.c             |  2 +-
>  util/vfio-helpers.c            | 12 ++++++------
>  25 files changed, 52 insertions(+), 50 deletions(-)
> 
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index d2d96d73e8..140b0bd8f6 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -52,7 +52,7 @@
>  /* KVM uses PAGE_SIZE in its definition of KVM_COALESCED_MMIO_MAX. We
>   * need to use the real host PAGE_SIZE, as that's what KVM will use.
>   */
> -#define PAGE_SIZE getpagesize()
> +#define PAGE_SIZE qemu_real_host_page_size
>  
>  //#define DEBUG_KVM
>  
> @@ -507,7 +507,7 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section,
>  {
>      ram_addr_t start = section->offset_within_region +
>                         memory_region_get_ram_addr(section->mr);
> -    ram_addr_t pages = int128_get64(section->size) / getpagesize();
> +    ram_addr_t pages = int128_get64(section->size) / qemu_real_host_page_size;
>  
>      cpu_physical_memory_set_dirty_lebitmap(bitmap, start, pages);
>      return 0;
> @@ -1841,7 +1841,7 @@ static int kvm_init(MachineState *ms)
>       * even with KVM.  TARGET_PAGE_SIZE is assumed to be the minimum
>       * page size for the system though.
>       */
> -    assert(TARGET_PAGE_SIZE <= getpagesize());
> +    assert(TARGET_PAGE_SIZE <= qemu_real_host_page_size);
>  
>      s->sigmask_len = 8;
>  
> diff --git a/backends/hostmem.c b/backends/hostmem.c
> index 6d333dc23c..e773bdfa6e 100644
> --- a/backends/hostmem.c
> +++ b/backends/hostmem.c
> @@ -304,7 +304,7 @@ size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
>  #else
>  size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
>  {
> -    return getpagesize();
> +    return qemu_real_host_page_size;
>  }
>  #endif
>  
> diff --git a/block.c b/block.c
> index 5944124845..98f47e2902 100644
> --- a/block.c
> +++ b/block.c
> @@ -106,7 +106,7 @@ size_t bdrv_opt_mem_align(BlockDriverState *bs)
>  {
>      if (!bs || !bs->drv) {
>          /* page size or 4k (hdd sector size) should be on the safe side */
> -        return MAX(4096, getpagesize());
> +        return MAX(4096, qemu_real_host_page_size);
>      }
>  
>      return bs->bl.opt_mem_alignment;
> @@ -116,7 +116,7 @@ size_t bdrv_min_mem_align(BlockDriverState *bs)
>  {
>      if (!bs || !bs->drv) {
>          /* page size or 4k (hdd sector size) should be on the safe side */
> -        return MAX(4096, getpagesize());
> +        return MAX(4096, qemu_real_host_page_size);
>      }
>  
>      return bs->bl.min_mem_alignment;
> diff --git a/block/file-posix.c b/block/file-posix.c
> index f12c06de2d..f60ac3f93f 100644
> --- a/block/file-posix.c
> +++ b/block/file-posix.c
> @@ -322,7 +322,7 @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp)
>  {
>      BDRVRawState *s = bs->opaque;
>      char *buf;
> -    size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize());
> +    size_t max_align = MAX(MAX_BLOCKSIZE, qemu_real_host_page_size);
>      size_t alignments[] = {1, 512, 1024, 2048, 4096};
>  
>      /* For SCSI generic devices the alignment is not really used.
> @@ -1131,13 +1131,14 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
>  
>          ret = sg_get_max_segments(s->fd);
>          if (ret > 0) {
> -            bs->bl.max_transfer = MIN(bs->bl.max_transfer, ret * getpagesize());
> +            bs->bl.max_transfer = MIN(bs->bl.max_transfer,
> +                                      ret * qemu_real_host_page_size);
>          }
>      }
>  
>      raw_probe_alignment(bs, s->fd, errp);
>      bs->bl.min_mem_alignment = s->buf_align;
> -    bs->bl.opt_mem_alignment = MAX(s->buf_align, getpagesize());
> +    bs->bl.opt_mem_alignment = MAX(s->buf_align, qemu_real_host_page_size);
>  }
>  
>  static int check_for_dasd(int fd)
> @@ -1700,7 +1701,7 @@ static int allocate_first_block(int fd, size_t max_size)
>      size_t write_size = (max_size < MAX_BLOCKSIZE)
>          ? BDRV_SECTOR_SIZE
>          : MAX_BLOCKSIZE;
> -    size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize());
> +    size_t max_align = MAX(MAX_BLOCKSIZE, qemu_real_host_page_size);
>      void *buf;
>      ssize_t n;
>      int ret;
> diff --git a/block/io.c b/block/io.c
> index 4f9ee97c2b..a201c8721a 100644
> --- a/block/io.c
> +++ b/block/io.c
> @@ -159,7 +159,7 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error **errp)
>          bdrv_merge_limits(&bs->bl, &bs->file->bs->bl);
>      } else {
>          bs->bl.min_mem_alignment = 512;
> -        bs->bl.opt_mem_alignment = getpagesize();
> +        bs->bl.opt_mem_alignment = qemu_real_host_page_size;
>  
>          /* Safe default since most protocols use readv()/writev()/etc */
>          bs->bl.max_iov = IOV_MAX;
> diff --git a/block/parallels.c b/block/parallels.c
> index 7cd2714b69..f1dfb03eef 100644
> --- a/block/parallels.c
> +++ b/block/parallels.c
> @@ -847,7 +847,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
>          }
>      }
>  
> -    s->bat_dirty_block = 4 * getpagesize();
> +    s->bat_dirty_block = 4 * qemu_real_host_page_size;
>      s->bat_dirty_bmap =
>          bitmap_new(DIV_ROUND_UP(s->header_size, s->bat_dirty_block));
>  
> diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
> index d29b038a67..7444b9c4ab 100644
> --- a/block/qcow2-cache.c
> +++ b/block/qcow2-cache.c
> @@ -74,7 +74,7 @@ static void qcow2_cache_table_release(Qcow2Cache *c, int i, int num_tables)
>  /* Using MADV_DONTNEED to discard memory is a Linux-specific feature */
>  #ifdef CONFIG_LINUX
>      void *t = qcow2_cache_get_table_addr(c, i);
> -    int align = getpagesize();
> +    int align = qemu_real_host_page_size;
>      size_t mem_size = (size_t) c->table_size * num_tables;
>      size_t offset = QEMU_ALIGN_UP((uintptr_t) t, align) - (uintptr_t) t;
>      size_t length = QEMU_ALIGN_DOWN(mem_size - offset, align);
> diff --git a/contrib/vhost-user-gpu/vugbm.c b/contrib/vhost-user-gpu/vugbm.c
> index d3bb82ff0e..9c357b6399 100644
> --- a/contrib/vhost-user-gpu/vugbm.c
> +++ b/contrib/vhost-user-gpu/vugbm.c
> @@ -52,7 +52,7 @@ struct udmabuf_create {
>  static size_t
>  udmabuf_get_size(struct vugbm_buffer *buf)
>  {
> -    return ROUND_UP(buf->width * buf->height * 4, getpagesize());
> +    return ROUND_UP(buf->width * buf->height * 4, qemu_real_host_page_size);
>  }
>  
>  static bool
> diff --git a/exec.c b/exec.c
> index bdcfcdff3f..27ef36769d 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1762,11 +1762,11 @@ long qemu_maxrampagesize(void)
>  #else
>  long qemu_minrampagesize(void)
>  {
> -    return getpagesize();
> +    return qemu_real_host_page_size;
>  }
>  long qemu_maxrampagesize(void)
>  {
> -    return getpagesize();
> +    return qemu_real_host_page_size;
>  }
>  #endif
>  
> @@ -2425,7 +2425,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
>      new_block->max_length = max_size;
>      assert(max_size >= size);
>      new_block->fd = -1;
> -    new_block->page_size = getpagesize();
> +    new_block->page_size = qemu_real_host_page_size;
>      new_block->host = host;
>      if (host) {
>          new_block->flags |= RAM_PREALLOC;
> diff --git a/hw/intc/s390_flic_kvm.c b/hw/intc/s390_flic_kvm.c
> index cedccba8a9..c9ee80eaae 100644
> --- a/hw/intc/s390_flic_kvm.c
> +++ b/hw/intc/s390_flic_kvm.c
> @@ -25,7 +25,7 @@
>  #include "migration/qemu-file-types.h"
>  #include "trace.h"
>  
> -#define FLIC_SAVE_INITIAL_SIZE getpagesize()
> +#define FLIC_SAVE_INITIAL_SIZE qemu_real_host_page_size
>  #define FLIC_FAILED (-1UL)
>  #define FLIC_SAVEVM_VERSION 1
>  
> diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
> index c5bbcc7433..3594517f0c 100644
> --- a/hw/ppc/mac_newworld.c
> +++ b/hw/ppc/mac_newworld.c
> @@ -439,7 +439,7 @@ static void ppc_core99_init(MachineState *machine)
>      }
>  
>      /* The NewWorld NVRAM is not located in the MacIO device */
> -    if (kvm_enabled() && getpagesize() > 4096) {
> +    if (kvm_enabled() && qemu_real_host_page_size > 4096) {
>          /* We can't combine read-write and read-only in a single page, so
>             move the NVRAM out of ROM again for KVM */
>          nvram_addr = 0xFFE00000;
> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> index 01ff41d4c4..191b295412 100644
> --- a/hw/ppc/spapr_pci.c
> +++ b/hw/ppc/spapr_pci.c
> @@ -1942,7 +1942,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
>       * our memory slot is of page size granularity.
>       */
>      if (kvm_enabled()) {
> -        msi_window_size = getpagesize();
> +        msi_window_size = qemu_real_host_page_size;
>      }
>  
>      memory_region_init_io(&sphb->msiwindow, OBJECT(sphb), &spapr_msi_ops, spapr,
> diff --git a/hw/rdma/vmw/pvrdma_main.c b/hw/rdma/vmw/pvrdma_main.c
> index 3e36e13013..3722d9e772 100644
> --- a/hw/rdma/vmw/pvrdma_main.c
> +++ b/hw/rdma/vmw/pvrdma_main.c
> @@ -601,7 +601,7 @@ static void pvrdma_realize(PCIDevice *pdev, Error **errp)
>      rdma_info_report("Initializing device %s %x.%x", pdev->name,
>                       PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
>  
> -    if (TARGET_PAGE_SIZE != getpagesize()) {
> +    if (TARGET_PAGE_SIZE != qemu_real_host_page_size) {
>          error_setg(errp, "Target page size must be the same as host page size");
>          return;
>      }
> diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
> index e853eebe11..33692fc86f 100644
> --- a/hw/vfio/spapr.c
> +++ b/hw/vfio/spapr.c
> @@ -196,14 +196,15 @@ int vfio_spapr_create_window(VFIOContainer *container,
>       * bits_per_level is a safe guess of how much we can allocate per level:
>       * 8 is the current minimum for CONFIG_FORCE_MAX_ZONEORDER and MAX_ORDER
>       * is usually bigger than that.
> -     * Below we look at getpagesize() as TCEs are allocated from system pages.
> +     * Below we look at qemu_real_host_page_size as TCEs are allocated from
> +     * system pages.
>       */
> -    bits_per_level = ctz64(getpagesize()) + 8;
> +    bits_per_level = ctz64(qemu_real_host_page_size) + 8;
>      create.levels = bits_total / bits_per_level;
>      if (bits_total % bits_per_level) {
>          ++create.levels;
>      }
> -    max_levels = (64 - create.page_shift) / ctz64(getpagesize());
> +    max_levels = (64 - create.page_shift) / ctz64(qemu_real_host_page_size);
>      for ( ; create.levels <= max_levels; ++create.levels) {
>          ret = ioctl(container->fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &create);
>          if (!ret) {
> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
> index e96e621de5..d638941272 100644
> --- a/include/exec/ram_addr.h
> +++ b/include/exec/ram_addr.h
> @@ -380,7 +380,7 @@ static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
>      hwaddr addr;
>      ram_addr_t ram_addr;
>      unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
> -    unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE;
> +    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? */
> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> index c7d242f476..0f97d68586 100644
> --- a/include/qemu/osdep.h
> +++ b/include/qemu/osdep.h
> @@ -423,9 +423,9 @@ void qemu_anon_ram_free(void *ptr, size_t size);
>  #  define QEMU_VMALLOC_ALIGN (256 * 4096)
>  #elif defined(__linux__) && defined(__sparc__)
>  #include <sys/shm.h>
> -#  define QEMU_VMALLOC_ALIGN MAX(getpagesize(), SHMLBA)
> +#  define QEMU_VMALLOC_ALIGN MAX(qemu_real_host_page_size, SHMLBA)
>  #else
> -#  define QEMU_VMALLOC_ALIGN getpagesize()
> +#  define QEMU_VMALLOC_ALIGN qemu_real_host_page_size
>  #endif
>  
>  #ifdef CONFIG_POSIX
> diff --git a/migration/migration.c b/migration/migration.c
> index ff9504cf28..264da3c88a 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -2288,7 +2288,7 @@ static struct rp_cmd_args {
>  static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname,
>                                         ram_addr_t start, size_t len)
>  {
> -    long our_host_ps = getpagesize();
> +    long our_host_ps = qemu_real_host_page_size;
>  
>      trace_migrate_handle_rp_req_pages(rbname, start, len);
>  
> diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
> index 1f63e65ed7..5f6eec1276 100644
> --- a/migration/postcopy-ram.c
> +++ b/migration/postcopy-ram.c
> @@ -308,7 +308,7 @@ static bool ufd_check_and_apply(int ufd, MigrationIncomingState *mis)
>          return false;
>      }
>  
> -    if (getpagesize() != ram_pagesize_summary()) {
> +    if (qemu_real_host_page_size != ram_pagesize_summary()) {
>          bool have_hp = false;
>          /* We've got a huge page */
>  #ifdef UFFD_FEATURE_MISSING_HUGETLBFS
> @@ -346,7 +346,7 @@ static int test_ramblock_postcopiable(RAMBlock *rb, void *opaque)
>   */
>  bool postcopy_ram_supported_by_host(MigrationIncomingState *mis)
>  {
> -    long pagesize = getpagesize();
> +    long pagesize = qemu_real_host_page_size;
>      int ufd = -1;
>      bool ret = false; /* Error unless we change it */
>      void *testarea = NULL;
> diff --git a/monitor/misc.c b/monitor/misc.c
> index aef16f6cfb..3baa15f3bf 100644
> --- a/monitor/misc.c
> +++ b/monitor/misc.c
> @@ -862,7 +862,7 @@ static uint64_t vtop(void *ptr, Error **errp)
>      uint64_t pinfo;
>      uint64_t ret = -1;
>      uintptr_t addr = (uintptr_t) ptr;
> -    uintptr_t pagesize = getpagesize();
> +    uintptr_t pagesize = qemu_real_host_page_size;
>      off_t offset = addr / pagesize * sizeof(pinfo);
>      int fd;
>  
> diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
> index 820724cc7d..7d2e8969ac 100644
> --- a/target/ppc/kvm.c
> +++ b/target/ppc/kvm.c
> @@ -411,7 +411,7 @@ void kvm_check_mmu(PowerPCCPU *cpu, Error **errp)
>           * will be a normal mapping, not a special hugepage one used
>           * for RAM.
>           */
> -        if (getpagesize() < 0x10000) {
> +        if (qemu_real_host_page_size < 0x10000) {
>              error_setg(errp,
>                         "KVM can't supply 64kiB CI pages, which guest expects");
>          }
> diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
> index c4e350e1f5..6c3d490611 100644
> --- a/tests/vhost-user-bridge.c
> +++ b/tests/vhost-user-bridge.c
> @@ -468,8 +468,8 @@ vubr_queue_set_started(VuDev *dev, int qidx, bool started)
>  
>      if (started && vubr->notifier.fd >= 0) {
>          vu_set_queue_host_notifier(dev, vq, vubr->notifier.fd,
> -                                   getpagesize(),
> -                                   qidx * getpagesize());
> +                                   qemu_real_host_page_size,
> +                                   qidx * qemu_real_host_page_size);
>      }
>  
>      if (qidx % 2 == 1) {
> @@ -594,7 +594,7 @@ static void *notifier_thread(void *arg)
>  {
>      VuDev *dev = (VuDev *)arg;
>      VubrDev *vubr = container_of(dev, VubrDev, vudev);
> -    int pagesize = getpagesize();
> +    int pagesize = qemu_real_host_page_size;
>      int qidx;
>  
>      while (true) {
> @@ -630,7 +630,7 @@ vubr_host_notifier_setup(VubrDev *dev)
>      void *addr;
>      int fd;
>  
> -    length = getpagesize() * VHOST_USER_BRIDGE_MAX_QUEUES;
> +    length = qemu_real_host_page_size * VHOST_USER_BRIDGE_MAX_QUEUES;
>  
>      fd = mkstemp(template);
>      if (fd < 0) {
> diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
> index f7f177d0ea..27dcccd8ec 100644
> --- a/util/mmap-alloc.c
> +++ b/util/mmap-alloc.c
> @@ -48,7 +48,7 @@ size_t qemu_fd_getpagesize(int fd)
>  #endif
>  #endif
>  
> -    return getpagesize();
> +    return qemu_real_host_page_size;
>  }
>  
>  size_t qemu_mempath_getpagesize(const char *mem_path)
> @@ -79,7 +79,7 @@ size_t qemu_mempath_getpagesize(const char *mem_path)
>  #endif
>  #endif
>  
> -    return getpagesize();
> +    return qemu_real_host_page_size;
>  }
>  
>  void *qemu_ram_mmap(int fd,
> @@ -114,7 +114,7 @@ void *qemu_ram_mmap(int fd,
>       */
>      flags = MAP_PRIVATE;
>      pagesize = qemu_fd_getpagesize(fd);
> -    if (fd == -1 || pagesize == getpagesize()) {
> +    if (fd == -1 || pagesize == qemu_real_host_page_size) {
>          guardfd = -1;
>          flags |= MAP_ANONYMOUS;
>      } else {
> @@ -123,7 +123,7 @@ void *qemu_ram_mmap(int fd,
>      }
>  #else
>      guardfd = -1;
> -    pagesize = getpagesize();
> +    pagesize = qemu_real_host_page_size;
>      flags = MAP_PRIVATE | MAP_ANONYMOUS;
>  #endif
>  
> @@ -205,7 +205,7 @@ void qemu_ram_munmap(int fd, void *ptr, size_t size)
>  #if defined(__powerpc64__) && defined(__linux__)
>          pagesize = qemu_fd_getpagesize(fd);
>  #else
> -        pagesize = getpagesize();
> +        pagesize = qemu_real_host_page_size;
>  #endif
>          munmap(ptr, size + pagesize);
>      }
> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
> index f8693384fc..5a291cc982 100644
> --- a/util/oslib-posix.c
> +++ b/util/oslib-posix.c
> @@ -617,7 +617,7 @@ void *qemu_alloc_stack(size_t *sz)
>  #ifdef CONFIG_DEBUG_STACK_USAGE
>      void *ptr2;
>  #endif
> -    size_t pagesz = getpagesize();
> +    size_t pagesz = qemu_real_host_page_size;
>  #ifdef _SC_THREAD_STACK_MIN
>      /* avoid stacks smaller than _SC_THREAD_STACK_MIN */
>      long min_stack_sz = sysconf(_SC_THREAD_STACK_MIN);
> @@ -679,7 +679,7 @@ void qemu_free_stack(void *stack, size_t sz)
>      unsigned int usage;
>      void *ptr;
>  
> -    for (ptr = stack + getpagesize(); ptr < stack + sz;
> +    for (ptr = stack + qemu_real_host_page_size; ptr < stack + sz;
>           ptr += sizeof(uint32_t)) {
>          if (*(uint32_t *)ptr != 0xdeadbeaf) {
>              break;
> diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> index 886e400d6a..e9b14ab178 100644
> --- a/util/oslib-win32.c
> +++ b/util/oslib-win32.c
> @@ -554,7 +554,7 @@ void os_mem_prealloc(int fd, char *area, size_t memory, int smp_cpus,
>                       Error **errp)
>  {
>      int i;
> -    size_t pagesize = getpagesize();
> +    size_t pagesize = qemu_real_host_page_size;
>  
>      memory = (memory + pagesize - 1) & -pagesize;
>      for (i = 0; i < memory / pagesize; i++) {
> diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
> index 26ffd0d6b5..813f7ec564 100644
> --- a/util/vfio-helpers.c
> +++ b/util/vfio-helpers.c
> @@ -514,9 +514,9 @@ static IOVAMapping *qemu_vfio_add_mapping(QEMUVFIOState *s,
>      IOVAMapping m = {.host = host, .size = size, .iova = iova};
>      IOVAMapping *insert;
>  
> -    assert(QEMU_IS_ALIGNED(size, getpagesize()));
> -    assert(QEMU_IS_ALIGNED(s->low_water_mark, getpagesize()));
> -    assert(QEMU_IS_ALIGNED(s->high_water_mark, getpagesize()));
> +    assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size));
> +    assert(QEMU_IS_ALIGNED(s->low_water_mark, qemu_real_host_page_size));
> +    assert(QEMU_IS_ALIGNED(s->high_water_mark, qemu_real_host_page_size));
>      trace_qemu_vfio_new_mapping(s, host, size, index, iova);
>  
>      assert(index >= 0);
> @@ -567,7 +567,7 @@ static void qemu_vfio_undo_mapping(QEMUVFIOState *s, IOVAMapping *mapping,
>  
>      index = mapping - s->mappings;
>      assert(mapping->size > 0);
> -    assert(QEMU_IS_ALIGNED(mapping->size, getpagesize()));
> +    assert(QEMU_IS_ALIGNED(mapping->size, qemu_real_host_page_size));
>      assert(index >= 0 && index < s->nr_mappings);
>      if (ioctl(s->container, VFIO_IOMMU_UNMAP_DMA, &unmap)) {
>          error_setg(errp, "VFIO_UNMAP_DMA failed: %d", -errno);
> @@ -613,8 +613,8 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
>      IOVAMapping *mapping;
>      uint64_t iova0;
>  
> -    assert(QEMU_PTR_IS_ALIGNED(host, getpagesize()));
> -    assert(QEMU_IS_ALIGNED(size, getpagesize()));
> +    assert(QEMU_PTR_IS_ALIGNED(host, qemu_real_host_page_size));
> +    assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size));
>      trace_qemu_vfio_dma_map(s, host, size, temporary, iova);
>      qemu_mutex_lock(&s->lock);
>      mapping = qemu_vfio_find_mapping(s, host, &index);
> -- 
> 2.17.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK


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

* Re: [PATCH 1/2] cpu: use ROUND_UP() to define xxx_PAGE_ALIGN
  2019-10-13  2:11 ` [PATCH 1/2] cpu: use ROUND_UP() to define xxx_PAGE_ALIGN Wei Yang
                     ` (2 preceding siblings ...)
  2019-10-13 15:56   ` Richard Henderson
@ 2019-10-14 16:25   ` Juan Quintela
  3 siblings, 0 replies; 23+ messages in thread
From: Juan Quintela @ 2019-10-14 16:25 UTC (permalink / raw)
  To: Wei Yang
  Cc: fam, mst, mark.cave-ayland, qemu-devel, kraxel, den, qemu-block,
	armbru, pasic, borntraeger, marcandre.lureau, rth, ehabkost, sw,
	dgilbert, yuval.shaia, alex.williamson, stefanha, pbonzini,
	david, kwolf, cohuck, qemu-s390x, mreitz, qemu-ppc, imammedo

Wei Yang <richardw.yang@linux.intel.com> wrote:
> Use ROUND_UP() to define, which is a little bit easy to read.
>
> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>

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


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

* Re: [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size
  2019-10-14  9:15   ` Dr. David Alan Gilbert
@ 2019-10-14 21:36     ` Wei Yang
  2019-10-14 23:12       ` Richard Henderson
  0 siblings, 1 reply; 23+ messages in thread
From: Wei Yang @ 2019-10-14 21:36 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: fam, mst, mark.cave-ayland, qemu-devel, kraxel, den, qemu-block,
	quintela, armbru, pasic, borntraeger, marcandre.lureau, rth,
	ehabkost, sw, yuval.shaia, alex.williamson, stefanha, pbonzini,
	david, kwolf, cohuck, qemu-s390x, mreitz, qemu-ppc, Wei Yang,
	imammedo

On Mon, Oct 14, 2019 at 10:15:02AM +0100, Dr. David Alan Gilbert wrote:
>* Wei Yang (richardw.yang@linux.intel.com) wrote:
>> There are three page size in qemu:
>> 
>>   real host page size
>>   host page size
>>   target page size
>> 
>> All of them have dedicate variable to represent. For the last two, we
>> use the same form in the whole qemu project, while for the first one we
>> use two forms: qemu_real_host_page_size and getpagesize().
>> 
>> qemu_real_host_page_size is defined to be a replacement of
>> getpagesize(), so let it serve the role.
>
>We also use sysconf(_SC_PAGESIZE) in a few places.

You mean need to replace them too?

>
>Dave
>
>> 
>> [Note] Not fully tested for some arch or device.
>> 
>> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
>> ---
>>  accel/kvm/kvm-all.c            |  6 +++---
>>  backends/hostmem.c             |  2 +-
>>  block.c                        |  4 ++--
>>  block/file-posix.c             |  9 +++++----
>>  block/io.c                     |  2 +-
>>  block/parallels.c              |  2 +-
>>  block/qcow2-cache.c            |  2 +-
>>  contrib/vhost-user-gpu/vugbm.c |  2 +-
>>  exec.c                         |  6 +++---
>>  hw/intc/s390_flic_kvm.c        |  2 +-
>>  hw/ppc/mac_newworld.c          |  2 +-
>>  hw/ppc/spapr_pci.c             |  2 +-
>>  hw/rdma/vmw/pvrdma_main.c      |  2 +-
>>  hw/vfio/spapr.c                |  7 ++++---
>>  include/exec/ram_addr.h        |  2 +-
>>  include/qemu/osdep.h           |  4 ++--
>>  migration/migration.c          |  2 +-
>>  migration/postcopy-ram.c       |  4 ++--
>>  monitor/misc.c                 |  2 +-
>>  target/ppc/kvm.c               |  2 +-
>>  tests/vhost-user-bridge.c      |  8 ++++----
>>  util/mmap-alloc.c              | 10 +++++-----
>>  util/oslib-posix.c             |  4 ++--
>>  util/oslib-win32.c             |  2 +-
>>  util/vfio-helpers.c            | 12 ++++++------
>>  25 files changed, 52 insertions(+), 50 deletions(-)
>> 
>> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
>> index d2d96d73e8..140b0bd8f6 100644
>> --- a/accel/kvm/kvm-all.c
>> +++ b/accel/kvm/kvm-all.c
>> @@ -52,7 +52,7 @@
>>  /* KVM uses PAGE_SIZE in its definition of KVM_COALESCED_MMIO_MAX. We
>>   * need to use the real host PAGE_SIZE, as that's what KVM will use.
>>   */
>> -#define PAGE_SIZE getpagesize()
>> +#define PAGE_SIZE qemu_real_host_page_size
>>  
>>  //#define DEBUG_KVM
>>  
>> @@ -507,7 +507,7 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section,
>>  {
>>      ram_addr_t start = section->offset_within_region +
>>                         memory_region_get_ram_addr(section->mr);
>> -    ram_addr_t pages = int128_get64(section->size) / getpagesize();
>> +    ram_addr_t pages = int128_get64(section->size) / qemu_real_host_page_size;
>>  
>>      cpu_physical_memory_set_dirty_lebitmap(bitmap, start, pages);
>>      return 0;
>> @@ -1841,7 +1841,7 @@ static int kvm_init(MachineState *ms)
>>       * even with KVM.  TARGET_PAGE_SIZE is assumed to be the minimum
>>       * page size for the system though.
>>       */
>> -    assert(TARGET_PAGE_SIZE <= getpagesize());
>> +    assert(TARGET_PAGE_SIZE <= qemu_real_host_page_size);
>>  
>>      s->sigmask_len = 8;
>>  
>> diff --git a/backends/hostmem.c b/backends/hostmem.c
>> index 6d333dc23c..e773bdfa6e 100644
>> --- a/backends/hostmem.c
>> +++ b/backends/hostmem.c
>> @@ -304,7 +304,7 @@ size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
>>  #else
>>  size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
>>  {
>> -    return getpagesize();
>> +    return qemu_real_host_page_size;
>>  }
>>  #endif
>>  
>> diff --git a/block.c b/block.c
>> index 5944124845..98f47e2902 100644
>> --- a/block.c
>> +++ b/block.c
>> @@ -106,7 +106,7 @@ size_t bdrv_opt_mem_align(BlockDriverState *bs)
>>  {
>>      if (!bs || !bs->drv) {
>>          /* page size or 4k (hdd sector size) should be on the safe side */
>> -        return MAX(4096, getpagesize());
>> +        return MAX(4096, qemu_real_host_page_size);
>>      }
>>  
>>      return bs->bl.opt_mem_alignment;
>> @@ -116,7 +116,7 @@ size_t bdrv_min_mem_align(BlockDriverState *bs)
>>  {
>>      if (!bs || !bs->drv) {
>>          /* page size or 4k (hdd sector size) should be on the safe side */
>> -        return MAX(4096, getpagesize());
>> +        return MAX(4096, qemu_real_host_page_size);
>>      }
>>  
>>      return bs->bl.min_mem_alignment;
>> diff --git a/block/file-posix.c b/block/file-posix.c
>> index f12c06de2d..f60ac3f93f 100644
>> --- a/block/file-posix.c
>> +++ b/block/file-posix.c
>> @@ -322,7 +322,7 @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp)
>>  {
>>      BDRVRawState *s = bs->opaque;
>>      char *buf;
>> -    size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize());
>> +    size_t max_align = MAX(MAX_BLOCKSIZE, qemu_real_host_page_size);
>>      size_t alignments[] = {1, 512, 1024, 2048, 4096};
>>  
>>      /* For SCSI generic devices the alignment is not really used.
>> @@ -1131,13 +1131,14 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
>>  
>>          ret = sg_get_max_segments(s->fd);
>>          if (ret > 0) {
>> -            bs->bl.max_transfer = MIN(bs->bl.max_transfer, ret * getpagesize());
>> +            bs->bl.max_transfer = MIN(bs->bl.max_transfer,
>> +                                      ret * qemu_real_host_page_size);
>>          }
>>      }
>>  
>>      raw_probe_alignment(bs, s->fd, errp);
>>      bs->bl.min_mem_alignment = s->buf_align;
>> -    bs->bl.opt_mem_alignment = MAX(s->buf_align, getpagesize());
>> +    bs->bl.opt_mem_alignment = MAX(s->buf_align, qemu_real_host_page_size);
>>  }
>>  
>>  static int check_for_dasd(int fd)
>> @@ -1700,7 +1701,7 @@ static int allocate_first_block(int fd, size_t max_size)
>>      size_t write_size = (max_size < MAX_BLOCKSIZE)
>>          ? BDRV_SECTOR_SIZE
>>          : MAX_BLOCKSIZE;
>> -    size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize());
>> +    size_t max_align = MAX(MAX_BLOCKSIZE, qemu_real_host_page_size);
>>      void *buf;
>>      ssize_t n;
>>      int ret;
>> diff --git a/block/io.c b/block/io.c
>> index 4f9ee97c2b..a201c8721a 100644
>> --- a/block/io.c
>> +++ b/block/io.c
>> @@ -159,7 +159,7 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error **errp)
>>          bdrv_merge_limits(&bs->bl, &bs->file->bs->bl);
>>      } else {
>>          bs->bl.min_mem_alignment = 512;
>> -        bs->bl.opt_mem_alignment = getpagesize();
>> +        bs->bl.opt_mem_alignment = qemu_real_host_page_size;
>>  
>>          /* Safe default since most protocols use readv()/writev()/etc */
>>          bs->bl.max_iov = IOV_MAX;
>> diff --git a/block/parallels.c b/block/parallels.c
>> index 7cd2714b69..f1dfb03eef 100644
>> --- a/block/parallels.c
>> +++ b/block/parallels.c
>> @@ -847,7 +847,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
>>          }
>>      }
>>  
>> -    s->bat_dirty_block = 4 * getpagesize();
>> +    s->bat_dirty_block = 4 * qemu_real_host_page_size;
>>      s->bat_dirty_bmap =
>>          bitmap_new(DIV_ROUND_UP(s->header_size, s->bat_dirty_block));
>>  
>> diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
>> index d29b038a67..7444b9c4ab 100644
>> --- a/block/qcow2-cache.c
>> +++ b/block/qcow2-cache.c
>> @@ -74,7 +74,7 @@ static void qcow2_cache_table_release(Qcow2Cache *c, int i, int num_tables)
>>  /* Using MADV_DONTNEED to discard memory is a Linux-specific feature */
>>  #ifdef CONFIG_LINUX
>>      void *t = qcow2_cache_get_table_addr(c, i);
>> -    int align = getpagesize();
>> +    int align = qemu_real_host_page_size;
>>      size_t mem_size = (size_t) c->table_size * num_tables;
>>      size_t offset = QEMU_ALIGN_UP((uintptr_t) t, align) - (uintptr_t) t;
>>      size_t length = QEMU_ALIGN_DOWN(mem_size - offset, align);
>> diff --git a/contrib/vhost-user-gpu/vugbm.c b/contrib/vhost-user-gpu/vugbm.c
>> index d3bb82ff0e..9c357b6399 100644
>> --- a/contrib/vhost-user-gpu/vugbm.c
>> +++ b/contrib/vhost-user-gpu/vugbm.c
>> @@ -52,7 +52,7 @@ struct udmabuf_create {
>>  static size_t
>>  udmabuf_get_size(struct vugbm_buffer *buf)
>>  {
>> -    return ROUND_UP(buf->width * buf->height * 4, getpagesize());
>> +    return ROUND_UP(buf->width * buf->height * 4, qemu_real_host_page_size);
>>  }
>>  
>>  static bool
>> diff --git a/exec.c b/exec.c
>> index bdcfcdff3f..27ef36769d 100644
>> --- a/exec.c
>> +++ b/exec.c
>> @@ -1762,11 +1762,11 @@ long qemu_maxrampagesize(void)
>>  #else
>>  long qemu_minrampagesize(void)
>>  {
>> -    return getpagesize();
>> +    return qemu_real_host_page_size;
>>  }
>>  long qemu_maxrampagesize(void)
>>  {
>> -    return getpagesize();
>> +    return qemu_real_host_page_size;
>>  }
>>  #endif
>>  
>> @@ -2425,7 +2425,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
>>      new_block->max_length = max_size;
>>      assert(max_size >= size);
>>      new_block->fd = -1;
>> -    new_block->page_size = getpagesize();
>> +    new_block->page_size = qemu_real_host_page_size;
>>      new_block->host = host;
>>      if (host) {
>>          new_block->flags |= RAM_PREALLOC;
>> diff --git a/hw/intc/s390_flic_kvm.c b/hw/intc/s390_flic_kvm.c
>> index cedccba8a9..c9ee80eaae 100644
>> --- a/hw/intc/s390_flic_kvm.c
>> +++ b/hw/intc/s390_flic_kvm.c
>> @@ -25,7 +25,7 @@
>>  #include "migration/qemu-file-types.h"
>>  #include "trace.h"
>>  
>> -#define FLIC_SAVE_INITIAL_SIZE getpagesize()
>> +#define FLIC_SAVE_INITIAL_SIZE qemu_real_host_page_size
>>  #define FLIC_FAILED (-1UL)
>>  #define FLIC_SAVEVM_VERSION 1
>>  
>> diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
>> index c5bbcc7433..3594517f0c 100644
>> --- a/hw/ppc/mac_newworld.c
>> +++ b/hw/ppc/mac_newworld.c
>> @@ -439,7 +439,7 @@ static void ppc_core99_init(MachineState *machine)
>>      }
>>  
>>      /* The NewWorld NVRAM is not located in the MacIO device */
>> -    if (kvm_enabled() && getpagesize() > 4096) {
>> +    if (kvm_enabled() && qemu_real_host_page_size > 4096) {
>>          /* We can't combine read-write and read-only in a single page, so
>>             move the NVRAM out of ROM again for KVM */
>>          nvram_addr = 0xFFE00000;
>> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
>> index 01ff41d4c4..191b295412 100644
>> --- a/hw/ppc/spapr_pci.c
>> +++ b/hw/ppc/spapr_pci.c
>> @@ -1942,7 +1942,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
>>       * our memory slot is of page size granularity.
>>       */
>>      if (kvm_enabled()) {
>> -        msi_window_size = getpagesize();
>> +        msi_window_size = qemu_real_host_page_size;
>>      }
>>  
>>      memory_region_init_io(&sphb->msiwindow, OBJECT(sphb), &spapr_msi_ops, spapr,
>> diff --git a/hw/rdma/vmw/pvrdma_main.c b/hw/rdma/vmw/pvrdma_main.c
>> index 3e36e13013..3722d9e772 100644
>> --- a/hw/rdma/vmw/pvrdma_main.c
>> +++ b/hw/rdma/vmw/pvrdma_main.c
>> @@ -601,7 +601,7 @@ static void pvrdma_realize(PCIDevice *pdev, Error **errp)
>>      rdma_info_report("Initializing device %s %x.%x", pdev->name,
>>                       PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
>>  
>> -    if (TARGET_PAGE_SIZE != getpagesize()) {
>> +    if (TARGET_PAGE_SIZE != qemu_real_host_page_size) {
>>          error_setg(errp, "Target page size must be the same as host page size");
>>          return;
>>      }
>> diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
>> index e853eebe11..33692fc86f 100644
>> --- a/hw/vfio/spapr.c
>> +++ b/hw/vfio/spapr.c
>> @@ -196,14 +196,15 @@ int vfio_spapr_create_window(VFIOContainer *container,
>>       * bits_per_level is a safe guess of how much we can allocate per level:
>>       * 8 is the current minimum for CONFIG_FORCE_MAX_ZONEORDER and MAX_ORDER
>>       * is usually bigger than that.
>> -     * Below we look at getpagesize() as TCEs are allocated from system pages.
>> +     * Below we look at qemu_real_host_page_size as TCEs are allocated from
>> +     * system pages.
>>       */
>> -    bits_per_level = ctz64(getpagesize()) + 8;
>> +    bits_per_level = ctz64(qemu_real_host_page_size) + 8;
>>      create.levels = bits_total / bits_per_level;
>>      if (bits_total % bits_per_level) {
>>          ++create.levels;
>>      }
>> -    max_levels = (64 - create.page_shift) / ctz64(getpagesize());
>> +    max_levels = (64 - create.page_shift) / ctz64(qemu_real_host_page_size);
>>      for ( ; create.levels <= max_levels; ++create.levels) {
>>          ret = ioctl(container->fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &create);
>>          if (!ret) {
>> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
>> index e96e621de5..d638941272 100644
>> --- a/include/exec/ram_addr.h
>> +++ b/include/exec/ram_addr.h
>> @@ -380,7 +380,7 @@ static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
>>      hwaddr addr;
>>      ram_addr_t ram_addr;
>>      unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
>> -    unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE;
>> +    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? */
>> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
>> index c7d242f476..0f97d68586 100644
>> --- a/include/qemu/osdep.h
>> +++ b/include/qemu/osdep.h
>> @@ -423,9 +423,9 @@ void qemu_anon_ram_free(void *ptr, size_t size);
>>  #  define QEMU_VMALLOC_ALIGN (256 * 4096)
>>  #elif defined(__linux__) && defined(__sparc__)
>>  #include <sys/shm.h>
>> -#  define QEMU_VMALLOC_ALIGN MAX(getpagesize(), SHMLBA)
>> +#  define QEMU_VMALLOC_ALIGN MAX(qemu_real_host_page_size, SHMLBA)
>>  #else
>> -#  define QEMU_VMALLOC_ALIGN getpagesize()
>> +#  define QEMU_VMALLOC_ALIGN qemu_real_host_page_size
>>  #endif
>>  
>>  #ifdef CONFIG_POSIX
>> diff --git a/migration/migration.c b/migration/migration.c
>> index ff9504cf28..264da3c88a 100644
>> --- a/migration/migration.c
>> +++ b/migration/migration.c
>> @@ -2288,7 +2288,7 @@ static struct rp_cmd_args {
>>  static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname,
>>                                         ram_addr_t start, size_t len)
>>  {
>> -    long our_host_ps = getpagesize();
>> +    long our_host_ps = qemu_real_host_page_size;
>>  
>>      trace_migrate_handle_rp_req_pages(rbname, start, len);
>>  
>> diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
>> index 1f63e65ed7..5f6eec1276 100644
>> --- a/migration/postcopy-ram.c
>> +++ b/migration/postcopy-ram.c
>> @@ -308,7 +308,7 @@ static bool ufd_check_and_apply(int ufd, MigrationIncomingState *mis)
>>          return false;
>>      }
>>  
>> -    if (getpagesize() != ram_pagesize_summary()) {
>> +    if (qemu_real_host_page_size != ram_pagesize_summary()) {
>>          bool have_hp = false;
>>          /* We've got a huge page */
>>  #ifdef UFFD_FEATURE_MISSING_HUGETLBFS
>> @@ -346,7 +346,7 @@ static int test_ramblock_postcopiable(RAMBlock *rb, void *opaque)
>>   */
>>  bool postcopy_ram_supported_by_host(MigrationIncomingState *mis)
>>  {
>> -    long pagesize = getpagesize();
>> +    long pagesize = qemu_real_host_page_size;
>>      int ufd = -1;
>>      bool ret = false; /* Error unless we change it */
>>      void *testarea = NULL;
>> diff --git a/monitor/misc.c b/monitor/misc.c
>> index aef16f6cfb..3baa15f3bf 100644
>> --- a/monitor/misc.c
>> +++ b/monitor/misc.c
>> @@ -862,7 +862,7 @@ static uint64_t vtop(void *ptr, Error **errp)
>>      uint64_t pinfo;
>>      uint64_t ret = -1;
>>      uintptr_t addr = (uintptr_t) ptr;
>> -    uintptr_t pagesize = getpagesize();
>> +    uintptr_t pagesize = qemu_real_host_page_size;
>>      off_t offset = addr / pagesize * sizeof(pinfo);
>>      int fd;
>>  
>> diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
>> index 820724cc7d..7d2e8969ac 100644
>> --- a/target/ppc/kvm.c
>> +++ b/target/ppc/kvm.c
>> @@ -411,7 +411,7 @@ void kvm_check_mmu(PowerPCCPU *cpu, Error **errp)
>>           * will be a normal mapping, not a special hugepage one used
>>           * for RAM.
>>           */
>> -        if (getpagesize() < 0x10000) {
>> +        if (qemu_real_host_page_size < 0x10000) {
>>              error_setg(errp,
>>                         "KVM can't supply 64kiB CI pages, which guest expects");
>>          }
>> diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
>> index c4e350e1f5..6c3d490611 100644
>> --- a/tests/vhost-user-bridge.c
>> +++ b/tests/vhost-user-bridge.c
>> @@ -468,8 +468,8 @@ vubr_queue_set_started(VuDev *dev, int qidx, bool started)
>>  
>>      if (started && vubr->notifier.fd >= 0) {
>>          vu_set_queue_host_notifier(dev, vq, vubr->notifier.fd,
>> -                                   getpagesize(),
>> -                                   qidx * getpagesize());
>> +                                   qemu_real_host_page_size,
>> +                                   qidx * qemu_real_host_page_size);
>>      }
>>  
>>      if (qidx % 2 == 1) {
>> @@ -594,7 +594,7 @@ static void *notifier_thread(void *arg)
>>  {
>>      VuDev *dev = (VuDev *)arg;
>>      VubrDev *vubr = container_of(dev, VubrDev, vudev);
>> -    int pagesize = getpagesize();
>> +    int pagesize = qemu_real_host_page_size;
>>      int qidx;
>>  
>>      while (true) {
>> @@ -630,7 +630,7 @@ vubr_host_notifier_setup(VubrDev *dev)
>>      void *addr;
>>      int fd;
>>  
>> -    length = getpagesize() * VHOST_USER_BRIDGE_MAX_QUEUES;
>> +    length = qemu_real_host_page_size * VHOST_USER_BRIDGE_MAX_QUEUES;
>>  
>>      fd = mkstemp(template);
>>      if (fd < 0) {
>> diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
>> index f7f177d0ea..27dcccd8ec 100644
>> --- a/util/mmap-alloc.c
>> +++ b/util/mmap-alloc.c
>> @@ -48,7 +48,7 @@ size_t qemu_fd_getpagesize(int fd)
>>  #endif
>>  #endif
>>  
>> -    return getpagesize();
>> +    return qemu_real_host_page_size;
>>  }
>>  
>>  size_t qemu_mempath_getpagesize(const char *mem_path)
>> @@ -79,7 +79,7 @@ size_t qemu_mempath_getpagesize(const char *mem_path)
>>  #endif
>>  #endif
>>  
>> -    return getpagesize();
>> +    return qemu_real_host_page_size;
>>  }
>>  
>>  void *qemu_ram_mmap(int fd,
>> @@ -114,7 +114,7 @@ void *qemu_ram_mmap(int fd,
>>       */
>>      flags = MAP_PRIVATE;
>>      pagesize = qemu_fd_getpagesize(fd);
>> -    if (fd == -1 || pagesize == getpagesize()) {
>> +    if (fd == -1 || pagesize == qemu_real_host_page_size) {
>>          guardfd = -1;
>>          flags |= MAP_ANONYMOUS;
>>      } else {
>> @@ -123,7 +123,7 @@ void *qemu_ram_mmap(int fd,
>>      }
>>  #else
>>      guardfd = -1;
>> -    pagesize = getpagesize();
>> +    pagesize = qemu_real_host_page_size;
>>      flags = MAP_PRIVATE | MAP_ANONYMOUS;
>>  #endif
>>  
>> @@ -205,7 +205,7 @@ void qemu_ram_munmap(int fd, void *ptr, size_t size)
>>  #if defined(__powerpc64__) && defined(__linux__)
>>          pagesize = qemu_fd_getpagesize(fd);
>>  #else
>> -        pagesize = getpagesize();
>> +        pagesize = qemu_real_host_page_size;
>>  #endif
>>          munmap(ptr, size + pagesize);
>>      }
>> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
>> index f8693384fc..5a291cc982 100644
>> --- a/util/oslib-posix.c
>> +++ b/util/oslib-posix.c
>> @@ -617,7 +617,7 @@ void *qemu_alloc_stack(size_t *sz)
>>  #ifdef CONFIG_DEBUG_STACK_USAGE
>>      void *ptr2;
>>  #endif
>> -    size_t pagesz = getpagesize();
>> +    size_t pagesz = qemu_real_host_page_size;
>>  #ifdef _SC_THREAD_STACK_MIN
>>      /* avoid stacks smaller than _SC_THREAD_STACK_MIN */
>>      long min_stack_sz = sysconf(_SC_THREAD_STACK_MIN);
>> @@ -679,7 +679,7 @@ void qemu_free_stack(void *stack, size_t sz)
>>      unsigned int usage;
>>      void *ptr;
>>  
>> -    for (ptr = stack + getpagesize(); ptr < stack + sz;
>> +    for (ptr = stack + qemu_real_host_page_size; ptr < stack + sz;
>>           ptr += sizeof(uint32_t)) {
>>          if (*(uint32_t *)ptr != 0xdeadbeaf) {
>>              break;
>> diff --git a/util/oslib-win32.c b/util/oslib-win32.c
>> index 886e400d6a..e9b14ab178 100644
>> --- a/util/oslib-win32.c
>> +++ b/util/oslib-win32.c
>> @@ -554,7 +554,7 @@ void os_mem_prealloc(int fd, char *area, size_t memory, int smp_cpus,
>>                       Error **errp)
>>  {
>>      int i;
>> -    size_t pagesize = getpagesize();
>> +    size_t pagesize = qemu_real_host_page_size;
>>  
>>      memory = (memory + pagesize - 1) & -pagesize;
>>      for (i = 0; i < memory / pagesize; i++) {
>> diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
>> index 26ffd0d6b5..813f7ec564 100644
>> --- a/util/vfio-helpers.c
>> +++ b/util/vfio-helpers.c
>> @@ -514,9 +514,9 @@ static IOVAMapping *qemu_vfio_add_mapping(QEMUVFIOState *s,
>>      IOVAMapping m = {.host = host, .size = size, .iova = iova};
>>      IOVAMapping *insert;
>>  
>> -    assert(QEMU_IS_ALIGNED(size, getpagesize()));
>> -    assert(QEMU_IS_ALIGNED(s->low_water_mark, getpagesize()));
>> -    assert(QEMU_IS_ALIGNED(s->high_water_mark, getpagesize()));
>> +    assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size));
>> +    assert(QEMU_IS_ALIGNED(s->low_water_mark, qemu_real_host_page_size));
>> +    assert(QEMU_IS_ALIGNED(s->high_water_mark, qemu_real_host_page_size));
>>      trace_qemu_vfio_new_mapping(s, host, size, index, iova);
>>  
>>      assert(index >= 0);
>> @@ -567,7 +567,7 @@ static void qemu_vfio_undo_mapping(QEMUVFIOState *s, IOVAMapping *mapping,
>>  
>>      index = mapping - s->mappings;
>>      assert(mapping->size > 0);
>> -    assert(QEMU_IS_ALIGNED(mapping->size, getpagesize()));
>> +    assert(QEMU_IS_ALIGNED(mapping->size, qemu_real_host_page_size));
>>      assert(index >= 0 && index < s->nr_mappings);
>>      if (ioctl(s->container, VFIO_IOMMU_UNMAP_DMA, &unmap)) {
>>          error_setg(errp, "VFIO_UNMAP_DMA failed: %d", -errno);
>> @@ -613,8 +613,8 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
>>      IOVAMapping *mapping;
>>      uint64_t iova0;
>>  
>> -    assert(QEMU_PTR_IS_ALIGNED(host, getpagesize()));
>> -    assert(QEMU_IS_ALIGNED(size, getpagesize()));
>> +    assert(QEMU_PTR_IS_ALIGNED(host, qemu_real_host_page_size));
>> +    assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size));
>>      trace_qemu_vfio_dma_map(s, host, size, temporary, iova);
>>      qemu_mutex_lock(&s->lock);
>>      mapping = qemu_vfio_find_mapping(s, host, &index);
>> -- 
>> 2.17.1
>> 
>--
>Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

-- 
Wei Yang
Help you, Help me


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

* Re: [PATCH 0/2] cleanup on page size
  2019-10-13  2:11 [PATCH 0/2] cleanup on page size Wei Yang
                   ` (2 preceding siblings ...)
  2019-10-13  6:36 ` [PATCH 0/2] cleanup on page size Michael S. Tsirkin
@ 2019-10-14 21:59 ` Wei Yang
  3 siblings, 0 replies; 23+ messages in thread
From: Wei Yang @ 2019-10-14 21:59 UTC (permalink / raw)
  To: Wei Yang
  Cc: fam, mst, mark.cave-ayland, qemu-devel, kraxel, den, qemu-block,
	quintela, armbru, pasic, borntraeger, marcandre.lureau, rth,
	ehabkost, sw, dgilbert, yuval.shaia, alex.williamson, stefanha,
	pbonzini, david, kwolf, cohuck, qemu-s390x, mreitz, qemu-ppc,
	imammedo

Hi, All,

I got one page size related question, hope to get some hint.

There is one comment in page_size_init().

    /* NOTE: we can always suppose that qemu_host_page_size >=
       TARGET_PAGE_SIZE */

The final result is true, since we compare qemu_host_page_size with
TARGET_PAGE_SIZE and if not qemu_host_page_size will be assigned to
TARGET_PAGE_SIZE.

Generally, there is no problem, but one corner case for migration.

In function ram_save_host_page(), it tries to save a whole host page. Or to be
specific, it tries to save a whole REAL host page.

The potential problem is when qemu_real_host_page_size < TARGET_PAGE_SIZE,
this whole host page would be a wrong range.

So I am wondering why we have the assumption written in page_size_init()?

I tried to dig out who and why we have this comment, but found the first
commit is

    commit 54936004fddc52c321cb3f9a9a51140e782bed5d
    Author: bellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>
    Date:   Tue May 13 00:25:15 2003 +0000
    
        mmap emulation
    
    
        git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@158 c046a42c-6fe2-441c-8c8c-71466251a162

There is no reason logged.

On Sun, Oct 13, 2019 at 10:11:43AM +0800, Wei Yang wrote:
>Patch 1 simplify the definition of xxx_PAGE_ALIGN.
>Patch 2 replaces getpagesize() with qemu_real_host_page_size. This one touch a
>volume of code. If some point is not correct, I'd appreciate your
>notification.
>
>Wei Yang (2):
>  cpu: use ROUND_UP() to define xxx_PAGE_ALIGN
>  core: replace getpagesize() with qemu_real_host_page_size
>
> accel/kvm/kvm-all.c            |  6 +++---
> backends/hostmem.c             |  2 +-
> block.c                        |  4 ++--
> block/file-posix.c             |  9 +++++----
> block/io.c                     |  2 +-
> block/parallels.c              |  2 +-
> block/qcow2-cache.c            |  2 +-
> contrib/vhost-user-gpu/vugbm.c |  2 +-
> exec.c                         |  6 +++---
> hw/intc/s390_flic_kvm.c        |  2 +-
> hw/ppc/mac_newworld.c          |  2 +-
> hw/ppc/spapr_pci.c             |  2 +-
> hw/rdma/vmw/pvrdma_main.c      |  2 +-
> hw/vfio/spapr.c                |  7 ++++---
> include/exec/cpu-all.h         |  7 +++----
> include/exec/ram_addr.h        |  2 +-
> include/qemu/osdep.h           |  4 ++--
> migration/migration.c          |  2 +-
> migration/postcopy-ram.c       |  4 ++--
> monitor/misc.c                 |  2 +-
> target/ppc/kvm.c               |  2 +-
> tests/vhost-user-bridge.c      |  8 ++++----
> util/mmap-alloc.c              | 10 +++++-----
> util/oslib-posix.c             |  4 ++--
> util/oslib-win32.c             |  2 +-
> util/vfio-helpers.c            | 12 ++++++------
> 26 files changed, 55 insertions(+), 54 deletions(-)
>
>-- 
>2.17.1

-- 
Wei Yang
Help you, Help me


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

* Re: [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size
  2019-10-14 21:36     ` Wei Yang
@ 2019-10-14 23:12       ` Richard Henderson
  0 siblings, 0 replies; 23+ messages in thread
From: Richard Henderson @ 2019-10-14 23:12 UTC (permalink / raw)
  To: Wei Yang, Dr. David Alan Gilbert
  Cc: fam, mst, mark.cave-ayland, qemu-devel, kraxel, den, qemu-block,
	quintela, armbru, pasic, borntraeger, marcandre.lureau, rth,
	ehabkost, sw, yuval.shaia, alex.williamson, stefanha, imammedo,
	david, kwolf, cohuck, qemu-s390x, mreitz, qemu-ppc, pbonzini

On 10/14/19 2:36 PM, Wei Yang wrote:
> On Mon, Oct 14, 2019 at 10:15:02AM +0100, Dr. David Alan Gilbert wrote:
>> We also use sysconf(_SC_PAGESIZE) in a few places.
> 
> You mean need to replace them too?

I would say so, as a separate patch.


r~


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

* Re: [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size
  2019-10-13  2:11 ` [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size Wei Yang
                     ` (3 preceding siblings ...)
  2019-10-14  9:15   ` Dr. David Alan Gilbert
@ 2019-10-15 11:45   ` Yuval Shaia
  2019-10-16  1:07     ` Wei Yang
  2019-10-23  9:19   ` Paolo Bonzini
  5 siblings, 1 reply; 23+ messages in thread
From: Yuval Shaia @ 2019-10-15 11:45 UTC (permalink / raw)
  To: Wei Yang
  Cc: fam, mst, mark.cave-ayland, qemu-devel, kraxel, den, qemu-block,
	quintela, armbru, pasic, borntraeger, marcandre.lureau, rth,
	ehabkost, sw, dgilbert, alex.williamson, stefanha, pbonzini,
	david, kwolf, cohuck, qemu-s390x, mreitz, qemu-ppc, imammedo

On Sun, Oct 13, 2019 at 10:11:45AM +0800, Wei Yang wrote:
> There are three page size in qemu:
> 
>   real host page size
>   host page size
>   target page size
> 
> All of them have dedicate variable to represent. For the last two, we
> use the same form in the whole qemu project, while for the first one we
> use two forms: qemu_real_host_page_size and getpagesize().
> 
> qemu_real_host_page_size is defined to be a replacement of
> getpagesize(), so let it serve the role.
> 
> [Note] Not fully tested for some arch or device.
> 
> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
> ---
>  accel/kvm/kvm-all.c            |  6 +++---
>  backends/hostmem.c             |  2 +-
>  block.c                        |  4 ++--
>  block/file-posix.c             |  9 +++++----
>  block/io.c                     |  2 +-
>  block/parallels.c              |  2 +-
>  block/qcow2-cache.c            |  2 +-
>  contrib/vhost-user-gpu/vugbm.c |  2 +-
>  exec.c                         |  6 +++---
>  hw/intc/s390_flic_kvm.c        |  2 +-
>  hw/ppc/mac_newworld.c          |  2 +-
>  hw/ppc/spapr_pci.c             |  2 +-
>  hw/rdma/vmw/pvrdma_main.c      |  2 +-

for pvrdma stuff:

Reviewed-by: Yuval Shaia <yuval.shaia@oracle.com>
Tested-by: Yuval Shaia <yuval.shaia@oracle.com>

>  hw/vfio/spapr.c                |  7 ++++---
>  include/exec/ram_addr.h        |  2 +-
>  include/qemu/osdep.h           |  4 ++--
>  migration/migration.c          |  2 +-
>  migration/postcopy-ram.c       |  4 ++--
>  monitor/misc.c                 |  2 +-
>  target/ppc/kvm.c               |  2 +-
>  tests/vhost-user-bridge.c      |  8 ++++----
>  util/mmap-alloc.c              | 10 +++++-----
>  util/oslib-posix.c             |  4 ++--
>  util/oslib-win32.c             |  2 +-
>  util/vfio-helpers.c            | 12 ++++++------
>  25 files changed, 52 insertions(+), 50 deletions(-)
> 
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index d2d96d73e8..140b0bd8f6 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -52,7 +52,7 @@
>  /* KVM uses PAGE_SIZE in its definition of KVM_COALESCED_MMIO_MAX. We
>   * need to use the real host PAGE_SIZE, as that's what KVM will use.
>   */
> -#define PAGE_SIZE getpagesize()
> +#define PAGE_SIZE qemu_real_host_page_size
>  
>  //#define DEBUG_KVM
>  
> @@ -507,7 +507,7 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section,
>  {
>      ram_addr_t start = section->offset_within_region +
>                         memory_region_get_ram_addr(section->mr);
> -    ram_addr_t pages = int128_get64(section->size) / getpagesize();
> +    ram_addr_t pages = int128_get64(section->size) / qemu_real_host_page_size;
>  
>      cpu_physical_memory_set_dirty_lebitmap(bitmap, start, pages);
>      return 0;
> @@ -1841,7 +1841,7 @@ static int kvm_init(MachineState *ms)
>       * even with KVM.  TARGET_PAGE_SIZE is assumed to be the minimum
>       * page size for the system though.
>       */
> -    assert(TARGET_PAGE_SIZE <= getpagesize());
> +    assert(TARGET_PAGE_SIZE <= qemu_real_host_page_size);
>  
>      s->sigmask_len = 8;
>  
> diff --git a/backends/hostmem.c b/backends/hostmem.c
> index 6d333dc23c..e773bdfa6e 100644
> --- a/backends/hostmem.c
> +++ b/backends/hostmem.c
> @@ -304,7 +304,7 @@ size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
>  #else
>  size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
>  {
> -    return getpagesize();
> +    return qemu_real_host_page_size;
>  }
>  #endif
>  
> diff --git a/block.c b/block.c
> index 5944124845..98f47e2902 100644
> --- a/block.c
> +++ b/block.c
> @@ -106,7 +106,7 @@ size_t bdrv_opt_mem_align(BlockDriverState *bs)
>  {
>      if (!bs || !bs->drv) {
>          /* page size or 4k (hdd sector size) should be on the safe side */
> -        return MAX(4096, getpagesize());
> +        return MAX(4096, qemu_real_host_page_size);
>      }
>  
>      return bs->bl.opt_mem_alignment;
> @@ -116,7 +116,7 @@ size_t bdrv_min_mem_align(BlockDriverState *bs)
>  {
>      if (!bs || !bs->drv) {
>          /* page size or 4k (hdd sector size) should be on the safe side */
> -        return MAX(4096, getpagesize());
> +        return MAX(4096, qemu_real_host_page_size);
>      }
>  
>      return bs->bl.min_mem_alignment;
> diff --git a/block/file-posix.c b/block/file-posix.c
> index f12c06de2d..f60ac3f93f 100644
> --- a/block/file-posix.c
> +++ b/block/file-posix.c
> @@ -322,7 +322,7 @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp)
>  {
>      BDRVRawState *s = bs->opaque;
>      char *buf;
> -    size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize());
> +    size_t max_align = MAX(MAX_BLOCKSIZE, qemu_real_host_page_size);
>      size_t alignments[] = {1, 512, 1024, 2048, 4096};
>  
>      /* For SCSI generic devices the alignment is not really used.
> @@ -1131,13 +1131,14 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
>  
>          ret = sg_get_max_segments(s->fd);
>          if (ret > 0) {
> -            bs->bl.max_transfer = MIN(bs->bl.max_transfer, ret * getpagesize());
> +            bs->bl.max_transfer = MIN(bs->bl.max_transfer,
> +                                      ret * qemu_real_host_page_size);
>          }
>      }
>  
>      raw_probe_alignment(bs, s->fd, errp);
>      bs->bl.min_mem_alignment = s->buf_align;
> -    bs->bl.opt_mem_alignment = MAX(s->buf_align, getpagesize());
> +    bs->bl.opt_mem_alignment = MAX(s->buf_align, qemu_real_host_page_size);
>  }
>  
>  static int check_for_dasd(int fd)
> @@ -1700,7 +1701,7 @@ static int allocate_first_block(int fd, size_t max_size)
>      size_t write_size = (max_size < MAX_BLOCKSIZE)
>          ? BDRV_SECTOR_SIZE
>          : MAX_BLOCKSIZE;
> -    size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize());
> +    size_t max_align = MAX(MAX_BLOCKSIZE, qemu_real_host_page_size);
>      void *buf;
>      ssize_t n;
>      int ret;
> diff --git a/block/io.c b/block/io.c
> index 4f9ee97c2b..a201c8721a 100644
> --- a/block/io.c
> +++ b/block/io.c
> @@ -159,7 +159,7 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error **errp)
>          bdrv_merge_limits(&bs->bl, &bs->file->bs->bl);
>      } else {
>          bs->bl.min_mem_alignment = 512;
> -        bs->bl.opt_mem_alignment = getpagesize();
> +        bs->bl.opt_mem_alignment = qemu_real_host_page_size;
>  
>          /* Safe default since most protocols use readv()/writev()/etc */
>          bs->bl.max_iov = IOV_MAX;
> diff --git a/block/parallels.c b/block/parallels.c
> index 7cd2714b69..f1dfb03eef 100644
> --- a/block/parallels.c
> +++ b/block/parallels.c
> @@ -847,7 +847,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
>          }
>      }
>  
> -    s->bat_dirty_block = 4 * getpagesize();
> +    s->bat_dirty_block = 4 * qemu_real_host_page_size;
>      s->bat_dirty_bmap =
>          bitmap_new(DIV_ROUND_UP(s->header_size, s->bat_dirty_block));
>  
> diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
> index d29b038a67..7444b9c4ab 100644
> --- a/block/qcow2-cache.c
> +++ b/block/qcow2-cache.c
> @@ -74,7 +74,7 @@ static void qcow2_cache_table_release(Qcow2Cache *c, int i, int num_tables)
>  /* Using MADV_DONTNEED to discard memory is a Linux-specific feature */
>  #ifdef CONFIG_LINUX
>      void *t = qcow2_cache_get_table_addr(c, i);
> -    int align = getpagesize();
> +    int align = qemu_real_host_page_size;
>      size_t mem_size = (size_t) c->table_size * num_tables;
>      size_t offset = QEMU_ALIGN_UP((uintptr_t) t, align) - (uintptr_t) t;
>      size_t length = QEMU_ALIGN_DOWN(mem_size - offset, align);
> diff --git a/contrib/vhost-user-gpu/vugbm.c b/contrib/vhost-user-gpu/vugbm.c
> index d3bb82ff0e..9c357b6399 100644
> --- a/contrib/vhost-user-gpu/vugbm.c
> +++ b/contrib/vhost-user-gpu/vugbm.c
> @@ -52,7 +52,7 @@ struct udmabuf_create {
>  static size_t
>  udmabuf_get_size(struct vugbm_buffer *buf)
>  {
> -    return ROUND_UP(buf->width * buf->height * 4, getpagesize());
> +    return ROUND_UP(buf->width * buf->height * 4, qemu_real_host_page_size);
>  }
>  
>  static bool
> diff --git a/exec.c b/exec.c
> index bdcfcdff3f..27ef36769d 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1762,11 +1762,11 @@ long qemu_maxrampagesize(void)
>  #else
>  long qemu_minrampagesize(void)
>  {
> -    return getpagesize();
> +    return qemu_real_host_page_size;
>  }
>  long qemu_maxrampagesize(void)
>  {
> -    return getpagesize();
> +    return qemu_real_host_page_size;
>  }
>  #endif
>  
> @@ -2425,7 +2425,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
>      new_block->max_length = max_size;
>      assert(max_size >= size);
>      new_block->fd = -1;
> -    new_block->page_size = getpagesize();
> +    new_block->page_size = qemu_real_host_page_size;
>      new_block->host = host;
>      if (host) {
>          new_block->flags |= RAM_PREALLOC;
> diff --git a/hw/intc/s390_flic_kvm.c b/hw/intc/s390_flic_kvm.c
> index cedccba8a9..c9ee80eaae 100644
> --- a/hw/intc/s390_flic_kvm.c
> +++ b/hw/intc/s390_flic_kvm.c
> @@ -25,7 +25,7 @@
>  #include "migration/qemu-file-types.h"
>  #include "trace.h"
>  
> -#define FLIC_SAVE_INITIAL_SIZE getpagesize()
> +#define FLIC_SAVE_INITIAL_SIZE qemu_real_host_page_size
>  #define FLIC_FAILED (-1UL)
>  #define FLIC_SAVEVM_VERSION 1
>  
> diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
> index c5bbcc7433..3594517f0c 100644
> --- a/hw/ppc/mac_newworld.c
> +++ b/hw/ppc/mac_newworld.c
> @@ -439,7 +439,7 @@ static void ppc_core99_init(MachineState *machine)
>      }
>  
>      /* The NewWorld NVRAM is not located in the MacIO device */
> -    if (kvm_enabled() && getpagesize() > 4096) {
> +    if (kvm_enabled() && qemu_real_host_page_size > 4096) {
>          /* We can't combine read-write and read-only in a single page, so
>             move the NVRAM out of ROM again for KVM */
>          nvram_addr = 0xFFE00000;
> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> index 01ff41d4c4..191b295412 100644
> --- a/hw/ppc/spapr_pci.c
> +++ b/hw/ppc/spapr_pci.c
> @@ -1942,7 +1942,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
>       * our memory slot is of page size granularity.
>       */
>      if (kvm_enabled()) {
> -        msi_window_size = getpagesize();
> +        msi_window_size = qemu_real_host_page_size;
>      }
>  
>      memory_region_init_io(&sphb->msiwindow, OBJECT(sphb), &spapr_msi_ops, spapr,
> diff --git a/hw/rdma/vmw/pvrdma_main.c b/hw/rdma/vmw/pvrdma_main.c
> index 3e36e13013..3722d9e772 100644
> --- a/hw/rdma/vmw/pvrdma_main.c
> +++ b/hw/rdma/vmw/pvrdma_main.c
> @@ -601,7 +601,7 @@ static void pvrdma_realize(PCIDevice *pdev, Error **errp)
>      rdma_info_report("Initializing device %s %x.%x", pdev->name,
>                       PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
>  
> -    if (TARGET_PAGE_SIZE != getpagesize()) {
> +    if (TARGET_PAGE_SIZE != qemu_real_host_page_size) {
>          error_setg(errp, "Target page size must be the same as host page size");
>          return;
>      }
> diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
> index e853eebe11..33692fc86f 100644
> --- a/hw/vfio/spapr.c
> +++ b/hw/vfio/spapr.c
> @@ -196,14 +196,15 @@ int vfio_spapr_create_window(VFIOContainer *container,
>       * bits_per_level is a safe guess of how much we can allocate per level:
>       * 8 is the current minimum for CONFIG_FORCE_MAX_ZONEORDER and MAX_ORDER
>       * is usually bigger than that.
> -     * Below we look at getpagesize() as TCEs are allocated from system pages.
> +     * Below we look at qemu_real_host_page_size as TCEs are allocated from
> +     * system pages.
>       */
> -    bits_per_level = ctz64(getpagesize()) + 8;
> +    bits_per_level = ctz64(qemu_real_host_page_size) + 8;
>      create.levels = bits_total / bits_per_level;
>      if (bits_total % bits_per_level) {
>          ++create.levels;
>      }
> -    max_levels = (64 - create.page_shift) / ctz64(getpagesize());
> +    max_levels = (64 - create.page_shift) / ctz64(qemu_real_host_page_size);
>      for ( ; create.levels <= max_levels; ++create.levels) {
>          ret = ioctl(container->fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &create);
>          if (!ret) {
> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
> index e96e621de5..d638941272 100644
> --- a/include/exec/ram_addr.h
> +++ b/include/exec/ram_addr.h
> @@ -380,7 +380,7 @@ static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
>      hwaddr addr;
>      ram_addr_t ram_addr;
>      unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
> -    unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE;
> +    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? */
> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> index c7d242f476..0f97d68586 100644
> --- a/include/qemu/osdep.h
> +++ b/include/qemu/osdep.h
> @@ -423,9 +423,9 @@ void qemu_anon_ram_free(void *ptr, size_t size);
>  #  define QEMU_VMALLOC_ALIGN (256 * 4096)
>  #elif defined(__linux__) && defined(__sparc__)
>  #include <sys/shm.h>
> -#  define QEMU_VMALLOC_ALIGN MAX(getpagesize(), SHMLBA)
> +#  define QEMU_VMALLOC_ALIGN MAX(qemu_real_host_page_size, SHMLBA)
>  #else
> -#  define QEMU_VMALLOC_ALIGN getpagesize()
> +#  define QEMU_VMALLOC_ALIGN qemu_real_host_page_size
>  #endif
>  
>  #ifdef CONFIG_POSIX
> diff --git a/migration/migration.c b/migration/migration.c
> index ff9504cf28..264da3c88a 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -2288,7 +2288,7 @@ static struct rp_cmd_args {
>  static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname,
>                                         ram_addr_t start, size_t len)
>  {
> -    long our_host_ps = getpagesize();
> +    long our_host_ps = qemu_real_host_page_size;
>  
>      trace_migrate_handle_rp_req_pages(rbname, start, len);
>  
> diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
> index 1f63e65ed7..5f6eec1276 100644
> --- a/migration/postcopy-ram.c
> +++ b/migration/postcopy-ram.c
> @@ -308,7 +308,7 @@ static bool ufd_check_and_apply(int ufd, MigrationIncomingState *mis)
>          return false;
>      }
>  
> -    if (getpagesize() != ram_pagesize_summary()) {
> +    if (qemu_real_host_page_size != ram_pagesize_summary()) {
>          bool have_hp = false;
>          /* We've got a huge page */
>  #ifdef UFFD_FEATURE_MISSING_HUGETLBFS
> @@ -346,7 +346,7 @@ static int test_ramblock_postcopiable(RAMBlock *rb, void *opaque)
>   */
>  bool postcopy_ram_supported_by_host(MigrationIncomingState *mis)
>  {
> -    long pagesize = getpagesize();
> +    long pagesize = qemu_real_host_page_size;
>      int ufd = -1;
>      bool ret = false; /* Error unless we change it */
>      void *testarea = NULL;
> diff --git a/monitor/misc.c b/monitor/misc.c
> index aef16f6cfb..3baa15f3bf 100644
> --- a/monitor/misc.c
> +++ b/monitor/misc.c
> @@ -862,7 +862,7 @@ static uint64_t vtop(void *ptr, Error **errp)
>      uint64_t pinfo;
>      uint64_t ret = -1;
>      uintptr_t addr = (uintptr_t) ptr;
> -    uintptr_t pagesize = getpagesize();
> +    uintptr_t pagesize = qemu_real_host_page_size;
>      off_t offset = addr / pagesize * sizeof(pinfo);
>      int fd;
>  
> diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
> index 820724cc7d..7d2e8969ac 100644
> --- a/target/ppc/kvm.c
> +++ b/target/ppc/kvm.c
> @@ -411,7 +411,7 @@ void kvm_check_mmu(PowerPCCPU *cpu, Error **errp)
>           * will be a normal mapping, not a special hugepage one used
>           * for RAM.
>           */
> -        if (getpagesize() < 0x10000) {
> +        if (qemu_real_host_page_size < 0x10000) {
>              error_setg(errp,
>                         "KVM can't supply 64kiB CI pages, which guest expects");
>          }
> diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
> index c4e350e1f5..6c3d490611 100644
> --- a/tests/vhost-user-bridge.c
> +++ b/tests/vhost-user-bridge.c
> @@ -468,8 +468,8 @@ vubr_queue_set_started(VuDev *dev, int qidx, bool started)
>  
>      if (started && vubr->notifier.fd >= 0) {
>          vu_set_queue_host_notifier(dev, vq, vubr->notifier.fd,
> -                                   getpagesize(),
> -                                   qidx * getpagesize());
> +                                   qemu_real_host_page_size,
> +                                   qidx * qemu_real_host_page_size);
>      }
>  
>      if (qidx % 2 == 1) {
> @@ -594,7 +594,7 @@ static void *notifier_thread(void *arg)
>  {
>      VuDev *dev = (VuDev *)arg;
>      VubrDev *vubr = container_of(dev, VubrDev, vudev);
> -    int pagesize = getpagesize();
> +    int pagesize = qemu_real_host_page_size;
>      int qidx;
>  
>      while (true) {
> @@ -630,7 +630,7 @@ vubr_host_notifier_setup(VubrDev *dev)
>      void *addr;
>      int fd;
>  
> -    length = getpagesize() * VHOST_USER_BRIDGE_MAX_QUEUES;
> +    length = qemu_real_host_page_size * VHOST_USER_BRIDGE_MAX_QUEUES;
>  
>      fd = mkstemp(template);
>      if (fd < 0) {
> diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
> index f7f177d0ea..27dcccd8ec 100644
> --- a/util/mmap-alloc.c
> +++ b/util/mmap-alloc.c
> @@ -48,7 +48,7 @@ size_t qemu_fd_getpagesize(int fd)
>  #endif
>  #endif
>  
> -    return getpagesize();
> +    return qemu_real_host_page_size;
>  }
>  
>  size_t qemu_mempath_getpagesize(const char *mem_path)
> @@ -79,7 +79,7 @@ size_t qemu_mempath_getpagesize(const char *mem_path)
>  #endif
>  #endif
>  
> -    return getpagesize();
> +    return qemu_real_host_page_size;
>  }
>  
>  void *qemu_ram_mmap(int fd,
> @@ -114,7 +114,7 @@ void *qemu_ram_mmap(int fd,
>       */
>      flags = MAP_PRIVATE;
>      pagesize = qemu_fd_getpagesize(fd);
> -    if (fd == -1 || pagesize == getpagesize()) {
> +    if (fd == -1 || pagesize == qemu_real_host_page_size) {
>          guardfd = -1;
>          flags |= MAP_ANONYMOUS;
>      } else {
> @@ -123,7 +123,7 @@ void *qemu_ram_mmap(int fd,
>      }
>  #else
>      guardfd = -1;
> -    pagesize = getpagesize();
> +    pagesize = qemu_real_host_page_size;
>      flags = MAP_PRIVATE | MAP_ANONYMOUS;
>  #endif
>  
> @@ -205,7 +205,7 @@ void qemu_ram_munmap(int fd, void *ptr, size_t size)
>  #if defined(__powerpc64__) && defined(__linux__)
>          pagesize = qemu_fd_getpagesize(fd);
>  #else
> -        pagesize = getpagesize();
> +        pagesize = qemu_real_host_page_size;
>  #endif
>          munmap(ptr, size + pagesize);
>      }
> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
> index f8693384fc..5a291cc982 100644
> --- a/util/oslib-posix.c
> +++ b/util/oslib-posix.c
> @@ -617,7 +617,7 @@ void *qemu_alloc_stack(size_t *sz)
>  #ifdef CONFIG_DEBUG_STACK_USAGE
>      void *ptr2;
>  #endif
> -    size_t pagesz = getpagesize();
> +    size_t pagesz = qemu_real_host_page_size;
>  #ifdef _SC_THREAD_STACK_MIN
>      /* avoid stacks smaller than _SC_THREAD_STACK_MIN */
>      long min_stack_sz = sysconf(_SC_THREAD_STACK_MIN);
> @@ -679,7 +679,7 @@ void qemu_free_stack(void *stack, size_t sz)
>      unsigned int usage;
>      void *ptr;
>  
> -    for (ptr = stack + getpagesize(); ptr < stack + sz;
> +    for (ptr = stack + qemu_real_host_page_size; ptr < stack + sz;
>           ptr += sizeof(uint32_t)) {
>          if (*(uint32_t *)ptr != 0xdeadbeaf) {
>              break;
> diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> index 886e400d6a..e9b14ab178 100644
> --- a/util/oslib-win32.c
> +++ b/util/oslib-win32.c
> @@ -554,7 +554,7 @@ void os_mem_prealloc(int fd, char *area, size_t memory, int smp_cpus,
>                       Error **errp)
>  {
>      int i;
> -    size_t pagesize = getpagesize();
> +    size_t pagesize = qemu_real_host_page_size;
>  
>      memory = (memory + pagesize - 1) & -pagesize;
>      for (i = 0; i < memory / pagesize; i++) {
> diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
> index 26ffd0d6b5..813f7ec564 100644
> --- a/util/vfio-helpers.c
> +++ b/util/vfio-helpers.c
> @@ -514,9 +514,9 @@ static IOVAMapping *qemu_vfio_add_mapping(QEMUVFIOState *s,
>      IOVAMapping m = {.host = host, .size = size, .iova = iova};
>      IOVAMapping *insert;
>  
> -    assert(QEMU_IS_ALIGNED(size, getpagesize()));
> -    assert(QEMU_IS_ALIGNED(s->low_water_mark, getpagesize()));
> -    assert(QEMU_IS_ALIGNED(s->high_water_mark, getpagesize()));
> +    assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size));
> +    assert(QEMU_IS_ALIGNED(s->low_water_mark, qemu_real_host_page_size));
> +    assert(QEMU_IS_ALIGNED(s->high_water_mark, qemu_real_host_page_size));
>      trace_qemu_vfio_new_mapping(s, host, size, index, iova);
>  
>      assert(index >= 0);
> @@ -567,7 +567,7 @@ static void qemu_vfio_undo_mapping(QEMUVFIOState *s, IOVAMapping *mapping,
>  
>      index = mapping - s->mappings;
>      assert(mapping->size > 0);
> -    assert(QEMU_IS_ALIGNED(mapping->size, getpagesize()));
> +    assert(QEMU_IS_ALIGNED(mapping->size, qemu_real_host_page_size));
>      assert(index >= 0 && index < s->nr_mappings);
>      if (ioctl(s->container, VFIO_IOMMU_UNMAP_DMA, &unmap)) {
>          error_setg(errp, "VFIO_UNMAP_DMA failed: %d", -errno);
> @@ -613,8 +613,8 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
>      IOVAMapping *mapping;
>      uint64_t iova0;
>  
> -    assert(QEMU_PTR_IS_ALIGNED(host, getpagesize()));
> -    assert(QEMU_IS_ALIGNED(size, getpagesize()));
> +    assert(QEMU_PTR_IS_ALIGNED(host, qemu_real_host_page_size));
> +    assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size));
>      trace_qemu_vfio_dma_map(s, host, size, temporary, iova);
>      qemu_mutex_lock(&s->lock);
>      mapping = qemu_vfio_find_mapping(s, host, &index);
> -- 
> 2.17.1
> 


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

* Re: [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size
  2019-10-15 11:45   ` Yuval Shaia
@ 2019-10-16  1:07     ` Wei Yang
  0 siblings, 0 replies; 23+ messages in thread
From: Wei Yang @ 2019-10-16  1:07 UTC (permalink / raw)
  To: Yuval Shaia
  Cc: fam, mst, mark.cave-ayland, qemu-devel, kraxel, den, qemu-block,
	quintela, armbru, pasic, borntraeger, marcandre.lureau, rth,
	ehabkost, sw, dgilbert, alex.williamson, stefanha, pbonzini,
	david, kwolf, cohuck, qemu-s390x, mreitz, qemu-ppc, Wei Yang,
	imammedo

On Tue, Oct 15, 2019 at 02:45:15PM +0300, Yuval Shaia wrote:
>On Sun, Oct 13, 2019 at 10:11:45AM +0800, Wei Yang wrote:
>> There are three page size in qemu:
>> 
>>   real host page size
>>   host page size
>>   target page size
>> 
>> All of them have dedicate variable to represent. For the last two, we
>> use the same form in the whole qemu project, while for the first one we
>> use two forms: qemu_real_host_page_size and getpagesize().
>> 
>> qemu_real_host_page_size is defined to be a replacement of
>> getpagesize(), so let it serve the role.
>> 
>> [Note] Not fully tested for some arch or device.
>> 
>> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
>> ---
>>  accel/kvm/kvm-all.c            |  6 +++---
>>  backends/hostmem.c             |  2 +-
>>  block.c                        |  4 ++--
>>  block/file-posix.c             |  9 +++++----
>>  block/io.c                     |  2 +-
>>  block/parallels.c              |  2 +-
>>  block/qcow2-cache.c            |  2 +-
>>  contrib/vhost-user-gpu/vugbm.c |  2 +-
>>  exec.c                         |  6 +++---
>>  hw/intc/s390_flic_kvm.c        |  2 +-
>>  hw/ppc/mac_newworld.c          |  2 +-
>>  hw/ppc/spapr_pci.c             |  2 +-
>>  hw/rdma/vmw/pvrdma_main.c      |  2 +-
>
>for pvrdma stuff:
>
>Reviewed-by: Yuval Shaia <yuval.shaia@oracle.com>
>Tested-by: Yuval Shaia <yuval.shaia@oracle.com>

Thanks

>
>>  hw/vfio/spapr.c                |  7 ++++---
>>  include/exec/ram_addr.h        |  2 +-
>>  include/qemu/osdep.h           |  4 ++--
>>  migration/migration.c          |  2 +-
>>  migration/postcopy-ram.c       |  4 ++--
>>  monitor/misc.c                 |  2 +-
>>  target/ppc/kvm.c               |  2 +-
>>  tests/vhost-user-bridge.c      |  8 ++++----
>>  util/mmap-alloc.c              | 10 +++++-----
>>  util/oslib-posix.c             |  4 ++--
>>  util/oslib-win32.c             |  2 +-
>>  util/vfio-helpers.c            | 12 ++++++------
>>  25 files changed, 52 insertions(+), 50 deletions(-)
>> 
>> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
>> index d2d96d73e8..140b0bd8f6 100644
>> --- a/accel/kvm/kvm-all.c
>> +++ b/accel/kvm/kvm-all.c
>> @@ -52,7 +52,7 @@
>>  /* KVM uses PAGE_SIZE in its definition of KVM_COALESCED_MMIO_MAX. We
>>   * need to use the real host PAGE_SIZE, as that's what KVM will use.
>>   */
>> -#define PAGE_SIZE getpagesize()
>> +#define PAGE_SIZE qemu_real_host_page_size
>>  
>>  //#define DEBUG_KVM
>>  
>> @@ -507,7 +507,7 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section,
>>  {
>>      ram_addr_t start = section->offset_within_region +
>>                         memory_region_get_ram_addr(section->mr);
>> -    ram_addr_t pages = int128_get64(section->size) / getpagesize();
>> +    ram_addr_t pages = int128_get64(section->size) / qemu_real_host_page_size;
>>  
>>      cpu_physical_memory_set_dirty_lebitmap(bitmap, start, pages);
>>      return 0;
>> @@ -1841,7 +1841,7 @@ static int kvm_init(MachineState *ms)
>>       * even with KVM.  TARGET_PAGE_SIZE is assumed to be the minimum
>>       * page size for the system though.
>>       */
>> -    assert(TARGET_PAGE_SIZE <= getpagesize());
>> +    assert(TARGET_PAGE_SIZE <= qemu_real_host_page_size);
>>  
>>      s->sigmask_len = 8;
>>  
>> diff --git a/backends/hostmem.c b/backends/hostmem.c
>> index 6d333dc23c..e773bdfa6e 100644
>> --- a/backends/hostmem.c
>> +++ b/backends/hostmem.c
>> @@ -304,7 +304,7 @@ size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
>>  #else
>>  size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
>>  {
>> -    return getpagesize();
>> +    return qemu_real_host_page_size;
>>  }
>>  #endif
>>  
>> diff --git a/block.c b/block.c
>> index 5944124845..98f47e2902 100644
>> --- a/block.c
>> +++ b/block.c
>> @@ -106,7 +106,7 @@ size_t bdrv_opt_mem_align(BlockDriverState *bs)
>>  {
>>      if (!bs || !bs->drv) {
>>          /* page size or 4k (hdd sector size) should be on the safe side */
>> -        return MAX(4096, getpagesize());
>> +        return MAX(4096, qemu_real_host_page_size);
>>      }
>>  
>>      return bs->bl.opt_mem_alignment;
>> @@ -116,7 +116,7 @@ size_t bdrv_min_mem_align(BlockDriverState *bs)
>>  {
>>      if (!bs || !bs->drv) {
>>          /* page size or 4k (hdd sector size) should be on the safe side */
>> -        return MAX(4096, getpagesize());
>> +        return MAX(4096, qemu_real_host_page_size);
>>      }
>>  
>>      return bs->bl.min_mem_alignment;
>> diff --git a/block/file-posix.c b/block/file-posix.c
>> index f12c06de2d..f60ac3f93f 100644
>> --- a/block/file-posix.c
>> +++ b/block/file-posix.c
>> @@ -322,7 +322,7 @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp)
>>  {
>>      BDRVRawState *s = bs->opaque;
>>      char *buf;
>> -    size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize());
>> +    size_t max_align = MAX(MAX_BLOCKSIZE, qemu_real_host_page_size);
>>      size_t alignments[] = {1, 512, 1024, 2048, 4096};
>>  
>>      /* For SCSI generic devices the alignment is not really used.
>> @@ -1131,13 +1131,14 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
>>  
>>          ret = sg_get_max_segments(s->fd);
>>          if (ret > 0) {
>> -            bs->bl.max_transfer = MIN(bs->bl.max_transfer, ret * getpagesize());
>> +            bs->bl.max_transfer = MIN(bs->bl.max_transfer,
>> +                                      ret * qemu_real_host_page_size);
>>          }
>>      }
>>  
>>      raw_probe_alignment(bs, s->fd, errp);
>>      bs->bl.min_mem_alignment = s->buf_align;
>> -    bs->bl.opt_mem_alignment = MAX(s->buf_align, getpagesize());
>> +    bs->bl.opt_mem_alignment = MAX(s->buf_align, qemu_real_host_page_size);
>>  }
>>  
>>  static int check_for_dasd(int fd)
>> @@ -1700,7 +1701,7 @@ static int allocate_first_block(int fd, size_t max_size)
>>      size_t write_size = (max_size < MAX_BLOCKSIZE)
>>          ? BDRV_SECTOR_SIZE
>>          : MAX_BLOCKSIZE;
>> -    size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize());
>> +    size_t max_align = MAX(MAX_BLOCKSIZE, qemu_real_host_page_size);
>>      void *buf;
>>      ssize_t n;
>>      int ret;
>> diff --git a/block/io.c b/block/io.c
>> index 4f9ee97c2b..a201c8721a 100644
>> --- a/block/io.c
>> +++ b/block/io.c
>> @@ -159,7 +159,7 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error **errp)
>>          bdrv_merge_limits(&bs->bl, &bs->file->bs->bl);
>>      } else {
>>          bs->bl.min_mem_alignment = 512;
>> -        bs->bl.opt_mem_alignment = getpagesize();
>> +        bs->bl.opt_mem_alignment = qemu_real_host_page_size;
>>  
>>          /* Safe default since most protocols use readv()/writev()/etc */
>>          bs->bl.max_iov = IOV_MAX;
>> diff --git a/block/parallels.c b/block/parallels.c
>> index 7cd2714b69..f1dfb03eef 100644
>> --- a/block/parallels.c
>> +++ b/block/parallels.c
>> @@ -847,7 +847,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
>>          }
>>      }
>>  
>> -    s->bat_dirty_block = 4 * getpagesize();
>> +    s->bat_dirty_block = 4 * qemu_real_host_page_size;
>>      s->bat_dirty_bmap =
>>          bitmap_new(DIV_ROUND_UP(s->header_size, s->bat_dirty_block));
>>  
>> diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
>> index d29b038a67..7444b9c4ab 100644
>> --- a/block/qcow2-cache.c
>> +++ b/block/qcow2-cache.c
>> @@ -74,7 +74,7 @@ static void qcow2_cache_table_release(Qcow2Cache *c, int i, int num_tables)
>>  /* Using MADV_DONTNEED to discard memory is a Linux-specific feature */
>>  #ifdef CONFIG_LINUX
>>      void *t = qcow2_cache_get_table_addr(c, i);
>> -    int align = getpagesize();
>> +    int align = qemu_real_host_page_size;
>>      size_t mem_size = (size_t) c->table_size * num_tables;
>>      size_t offset = QEMU_ALIGN_UP((uintptr_t) t, align) - (uintptr_t) t;
>>      size_t length = QEMU_ALIGN_DOWN(mem_size - offset, align);
>> diff --git a/contrib/vhost-user-gpu/vugbm.c b/contrib/vhost-user-gpu/vugbm.c
>> index d3bb82ff0e..9c357b6399 100644
>> --- a/contrib/vhost-user-gpu/vugbm.c
>> +++ b/contrib/vhost-user-gpu/vugbm.c
>> @@ -52,7 +52,7 @@ struct udmabuf_create {
>>  static size_t
>>  udmabuf_get_size(struct vugbm_buffer *buf)
>>  {
>> -    return ROUND_UP(buf->width * buf->height * 4, getpagesize());
>> +    return ROUND_UP(buf->width * buf->height * 4, qemu_real_host_page_size);
>>  }
>>  
>>  static bool
>> diff --git a/exec.c b/exec.c
>> index bdcfcdff3f..27ef36769d 100644
>> --- a/exec.c
>> +++ b/exec.c
>> @@ -1762,11 +1762,11 @@ long qemu_maxrampagesize(void)
>>  #else
>>  long qemu_minrampagesize(void)
>>  {
>> -    return getpagesize();
>> +    return qemu_real_host_page_size;
>>  }
>>  long qemu_maxrampagesize(void)
>>  {
>> -    return getpagesize();
>> +    return qemu_real_host_page_size;
>>  }
>>  #endif
>>  
>> @@ -2425,7 +2425,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
>>      new_block->max_length = max_size;
>>      assert(max_size >= size);
>>      new_block->fd = -1;
>> -    new_block->page_size = getpagesize();
>> +    new_block->page_size = qemu_real_host_page_size;
>>      new_block->host = host;
>>      if (host) {
>>          new_block->flags |= RAM_PREALLOC;
>> diff --git a/hw/intc/s390_flic_kvm.c b/hw/intc/s390_flic_kvm.c
>> index cedccba8a9..c9ee80eaae 100644
>> --- a/hw/intc/s390_flic_kvm.c
>> +++ b/hw/intc/s390_flic_kvm.c
>> @@ -25,7 +25,7 @@
>>  #include "migration/qemu-file-types.h"
>>  #include "trace.h"
>>  
>> -#define FLIC_SAVE_INITIAL_SIZE getpagesize()
>> +#define FLIC_SAVE_INITIAL_SIZE qemu_real_host_page_size
>>  #define FLIC_FAILED (-1UL)
>>  #define FLIC_SAVEVM_VERSION 1
>>  
>> diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
>> index c5bbcc7433..3594517f0c 100644
>> --- a/hw/ppc/mac_newworld.c
>> +++ b/hw/ppc/mac_newworld.c
>> @@ -439,7 +439,7 @@ static void ppc_core99_init(MachineState *machine)
>>      }
>>  
>>      /* The NewWorld NVRAM is not located in the MacIO device */
>> -    if (kvm_enabled() && getpagesize() > 4096) {
>> +    if (kvm_enabled() && qemu_real_host_page_size > 4096) {
>>          /* We can't combine read-write and read-only in a single page, so
>>             move the NVRAM out of ROM again for KVM */
>>          nvram_addr = 0xFFE00000;
>> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
>> index 01ff41d4c4..191b295412 100644
>> --- a/hw/ppc/spapr_pci.c
>> +++ b/hw/ppc/spapr_pci.c
>> @@ -1942,7 +1942,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
>>       * our memory slot is of page size granularity.
>>       */
>>      if (kvm_enabled()) {
>> -        msi_window_size = getpagesize();
>> +        msi_window_size = qemu_real_host_page_size;
>>      }
>>  
>>      memory_region_init_io(&sphb->msiwindow, OBJECT(sphb), &spapr_msi_ops, spapr,
>> diff --git a/hw/rdma/vmw/pvrdma_main.c b/hw/rdma/vmw/pvrdma_main.c
>> index 3e36e13013..3722d9e772 100644
>> --- a/hw/rdma/vmw/pvrdma_main.c
>> +++ b/hw/rdma/vmw/pvrdma_main.c
>> @@ -601,7 +601,7 @@ static void pvrdma_realize(PCIDevice *pdev, Error **errp)
>>      rdma_info_report("Initializing device %s %x.%x", pdev->name,
>>                       PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
>>  
>> -    if (TARGET_PAGE_SIZE != getpagesize()) {
>> +    if (TARGET_PAGE_SIZE != qemu_real_host_page_size) {
>>          error_setg(errp, "Target page size must be the same as host page size");
>>          return;
>>      }
>> diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
>> index e853eebe11..33692fc86f 100644
>> --- a/hw/vfio/spapr.c
>> +++ b/hw/vfio/spapr.c
>> @@ -196,14 +196,15 @@ int vfio_spapr_create_window(VFIOContainer *container,
>>       * bits_per_level is a safe guess of how much we can allocate per level:
>>       * 8 is the current minimum for CONFIG_FORCE_MAX_ZONEORDER and MAX_ORDER
>>       * is usually bigger than that.
>> -     * Below we look at getpagesize() as TCEs are allocated from system pages.
>> +     * Below we look at qemu_real_host_page_size as TCEs are allocated from
>> +     * system pages.
>>       */
>> -    bits_per_level = ctz64(getpagesize()) + 8;
>> +    bits_per_level = ctz64(qemu_real_host_page_size) + 8;
>>      create.levels = bits_total / bits_per_level;
>>      if (bits_total % bits_per_level) {
>>          ++create.levels;
>>      }
>> -    max_levels = (64 - create.page_shift) / ctz64(getpagesize());
>> +    max_levels = (64 - create.page_shift) / ctz64(qemu_real_host_page_size);
>>      for ( ; create.levels <= max_levels; ++create.levels) {
>>          ret = ioctl(container->fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &create);
>>          if (!ret) {
>> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
>> index e96e621de5..d638941272 100644
>> --- a/include/exec/ram_addr.h
>> +++ b/include/exec/ram_addr.h
>> @@ -380,7 +380,7 @@ static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
>>      hwaddr addr;
>>      ram_addr_t ram_addr;
>>      unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
>> -    unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE;
>> +    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? */
>> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
>> index c7d242f476..0f97d68586 100644
>> --- a/include/qemu/osdep.h
>> +++ b/include/qemu/osdep.h
>> @@ -423,9 +423,9 @@ void qemu_anon_ram_free(void *ptr, size_t size);
>>  #  define QEMU_VMALLOC_ALIGN (256 * 4096)
>>  #elif defined(__linux__) && defined(__sparc__)
>>  #include <sys/shm.h>
>> -#  define QEMU_VMALLOC_ALIGN MAX(getpagesize(), SHMLBA)
>> +#  define QEMU_VMALLOC_ALIGN MAX(qemu_real_host_page_size, SHMLBA)
>>  #else
>> -#  define QEMU_VMALLOC_ALIGN getpagesize()
>> +#  define QEMU_VMALLOC_ALIGN qemu_real_host_page_size
>>  #endif
>>  
>>  #ifdef CONFIG_POSIX
>> diff --git a/migration/migration.c b/migration/migration.c
>> index ff9504cf28..264da3c88a 100644
>> --- a/migration/migration.c
>> +++ b/migration/migration.c
>> @@ -2288,7 +2288,7 @@ static struct rp_cmd_args {
>>  static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname,
>>                                         ram_addr_t start, size_t len)
>>  {
>> -    long our_host_ps = getpagesize();
>> +    long our_host_ps = qemu_real_host_page_size;
>>  
>>      trace_migrate_handle_rp_req_pages(rbname, start, len);
>>  
>> diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
>> index 1f63e65ed7..5f6eec1276 100644
>> --- a/migration/postcopy-ram.c
>> +++ b/migration/postcopy-ram.c
>> @@ -308,7 +308,7 @@ static bool ufd_check_and_apply(int ufd, MigrationIncomingState *mis)
>>          return false;
>>      }
>>  
>> -    if (getpagesize() != ram_pagesize_summary()) {
>> +    if (qemu_real_host_page_size != ram_pagesize_summary()) {
>>          bool have_hp = false;
>>          /* We've got a huge page */
>>  #ifdef UFFD_FEATURE_MISSING_HUGETLBFS
>> @@ -346,7 +346,7 @@ static int test_ramblock_postcopiable(RAMBlock *rb, void *opaque)
>>   */
>>  bool postcopy_ram_supported_by_host(MigrationIncomingState *mis)
>>  {
>> -    long pagesize = getpagesize();
>> +    long pagesize = qemu_real_host_page_size;
>>      int ufd = -1;
>>      bool ret = false; /* Error unless we change it */
>>      void *testarea = NULL;
>> diff --git a/monitor/misc.c b/monitor/misc.c
>> index aef16f6cfb..3baa15f3bf 100644
>> --- a/monitor/misc.c
>> +++ b/monitor/misc.c
>> @@ -862,7 +862,7 @@ static uint64_t vtop(void *ptr, Error **errp)
>>      uint64_t pinfo;
>>      uint64_t ret = -1;
>>      uintptr_t addr = (uintptr_t) ptr;
>> -    uintptr_t pagesize = getpagesize();
>> +    uintptr_t pagesize = qemu_real_host_page_size;
>>      off_t offset = addr / pagesize * sizeof(pinfo);
>>      int fd;
>>  
>> diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
>> index 820724cc7d..7d2e8969ac 100644
>> --- a/target/ppc/kvm.c
>> +++ b/target/ppc/kvm.c
>> @@ -411,7 +411,7 @@ void kvm_check_mmu(PowerPCCPU *cpu, Error **errp)
>>           * will be a normal mapping, not a special hugepage one used
>>           * for RAM.
>>           */
>> -        if (getpagesize() < 0x10000) {
>> +        if (qemu_real_host_page_size < 0x10000) {
>>              error_setg(errp,
>>                         "KVM can't supply 64kiB CI pages, which guest expects");
>>          }
>> diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
>> index c4e350e1f5..6c3d490611 100644
>> --- a/tests/vhost-user-bridge.c
>> +++ b/tests/vhost-user-bridge.c
>> @@ -468,8 +468,8 @@ vubr_queue_set_started(VuDev *dev, int qidx, bool started)
>>  
>>      if (started && vubr->notifier.fd >= 0) {
>>          vu_set_queue_host_notifier(dev, vq, vubr->notifier.fd,
>> -                                   getpagesize(),
>> -                                   qidx * getpagesize());
>> +                                   qemu_real_host_page_size,
>> +                                   qidx * qemu_real_host_page_size);
>>      }
>>  
>>      if (qidx % 2 == 1) {
>> @@ -594,7 +594,7 @@ static void *notifier_thread(void *arg)
>>  {
>>      VuDev *dev = (VuDev *)arg;
>>      VubrDev *vubr = container_of(dev, VubrDev, vudev);
>> -    int pagesize = getpagesize();
>> +    int pagesize = qemu_real_host_page_size;
>>      int qidx;
>>  
>>      while (true) {
>> @@ -630,7 +630,7 @@ vubr_host_notifier_setup(VubrDev *dev)
>>      void *addr;
>>      int fd;
>>  
>> -    length = getpagesize() * VHOST_USER_BRIDGE_MAX_QUEUES;
>> +    length = qemu_real_host_page_size * VHOST_USER_BRIDGE_MAX_QUEUES;
>>  
>>      fd = mkstemp(template);
>>      if (fd < 0) {
>> diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
>> index f7f177d0ea..27dcccd8ec 100644
>> --- a/util/mmap-alloc.c
>> +++ b/util/mmap-alloc.c
>> @@ -48,7 +48,7 @@ size_t qemu_fd_getpagesize(int fd)
>>  #endif
>>  #endif
>>  
>> -    return getpagesize();
>> +    return qemu_real_host_page_size;
>>  }
>>  
>>  size_t qemu_mempath_getpagesize(const char *mem_path)
>> @@ -79,7 +79,7 @@ size_t qemu_mempath_getpagesize(const char *mem_path)
>>  #endif
>>  #endif
>>  
>> -    return getpagesize();
>> +    return qemu_real_host_page_size;
>>  }
>>  
>>  void *qemu_ram_mmap(int fd,
>> @@ -114,7 +114,7 @@ void *qemu_ram_mmap(int fd,
>>       */
>>      flags = MAP_PRIVATE;
>>      pagesize = qemu_fd_getpagesize(fd);
>> -    if (fd == -1 || pagesize == getpagesize()) {
>> +    if (fd == -1 || pagesize == qemu_real_host_page_size) {
>>          guardfd = -1;
>>          flags |= MAP_ANONYMOUS;
>>      } else {
>> @@ -123,7 +123,7 @@ void *qemu_ram_mmap(int fd,
>>      }
>>  #else
>>      guardfd = -1;
>> -    pagesize = getpagesize();
>> +    pagesize = qemu_real_host_page_size;
>>      flags = MAP_PRIVATE | MAP_ANONYMOUS;
>>  #endif
>>  
>> @@ -205,7 +205,7 @@ void qemu_ram_munmap(int fd, void *ptr, size_t size)
>>  #if defined(__powerpc64__) && defined(__linux__)
>>          pagesize = qemu_fd_getpagesize(fd);
>>  #else
>> -        pagesize = getpagesize();
>> +        pagesize = qemu_real_host_page_size;
>>  #endif
>>          munmap(ptr, size + pagesize);
>>      }
>> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
>> index f8693384fc..5a291cc982 100644
>> --- a/util/oslib-posix.c
>> +++ b/util/oslib-posix.c
>> @@ -617,7 +617,7 @@ void *qemu_alloc_stack(size_t *sz)
>>  #ifdef CONFIG_DEBUG_STACK_USAGE
>>      void *ptr2;
>>  #endif
>> -    size_t pagesz = getpagesize();
>> +    size_t pagesz = qemu_real_host_page_size;
>>  #ifdef _SC_THREAD_STACK_MIN
>>      /* avoid stacks smaller than _SC_THREAD_STACK_MIN */
>>      long min_stack_sz = sysconf(_SC_THREAD_STACK_MIN);
>> @@ -679,7 +679,7 @@ void qemu_free_stack(void *stack, size_t sz)
>>      unsigned int usage;
>>      void *ptr;
>>  
>> -    for (ptr = stack + getpagesize(); ptr < stack + sz;
>> +    for (ptr = stack + qemu_real_host_page_size; ptr < stack + sz;
>>           ptr += sizeof(uint32_t)) {
>>          if (*(uint32_t *)ptr != 0xdeadbeaf) {
>>              break;
>> diff --git a/util/oslib-win32.c b/util/oslib-win32.c
>> index 886e400d6a..e9b14ab178 100644
>> --- a/util/oslib-win32.c
>> +++ b/util/oslib-win32.c
>> @@ -554,7 +554,7 @@ void os_mem_prealloc(int fd, char *area, size_t memory, int smp_cpus,
>>                       Error **errp)
>>  {
>>      int i;
>> -    size_t pagesize = getpagesize();
>> +    size_t pagesize = qemu_real_host_page_size;
>>  
>>      memory = (memory + pagesize - 1) & -pagesize;
>>      for (i = 0; i < memory / pagesize; i++) {
>> diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
>> index 26ffd0d6b5..813f7ec564 100644
>> --- a/util/vfio-helpers.c
>> +++ b/util/vfio-helpers.c
>> @@ -514,9 +514,9 @@ static IOVAMapping *qemu_vfio_add_mapping(QEMUVFIOState *s,
>>      IOVAMapping m = {.host = host, .size = size, .iova = iova};
>>      IOVAMapping *insert;
>>  
>> -    assert(QEMU_IS_ALIGNED(size, getpagesize()));
>> -    assert(QEMU_IS_ALIGNED(s->low_water_mark, getpagesize()));
>> -    assert(QEMU_IS_ALIGNED(s->high_water_mark, getpagesize()));
>> +    assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size));
>> +    assert(QEMU_IS_ALIGNED(s->low_water_mark, qemu_real_host_page_size));
>> +    assert(QEMU_IS_ALIGNED(s->high_water_mark, qemu_real_host_page_size));
>>      trace_qemu_vfio_new_mapping(s, host, size, index, iova);
>>  
>>      assert(index >= 0);
>> @@ -567,7 +567,7 @@ static void qemu_vfio_undo_mapping(QEMUVFIOState *s, IOVAMapping *mapping,
>>  
>>      index = mapping - s->mappings;
>>      assert(mapping->size > 0);
>> -    assert(QEMU_IS_ALIGNED(mapping->size, getpagesize()));
>> +    assert(QEMU_IS_ALIGNED(mapping->size, qemu_real_host_page_size));
>>      assert(index >= 0 && index < s->nr_mappings);
>>      if (ioctl(s->container, VFIO_IOMMU_UNMAP_DMA, &unmap)) {
>>          error_setg(errp, "VFIO_UNMAP_DMA failed: %d", -errno);
>> @@ -613,8 +613,8 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
>>      IOVAMapping *mapping;
>>      uint64_t iova0;
>>  
>> -    assert(QEMU_PTR_IS_ALIGNED(host, getpagesize()));
>> -    assert(QEMU_IS_ALIGNED(size, getpagesize()));
>> +    assert(QEMU_PTR_IS_ALIGNED(host, qemu_real_host_page_size));
>> +    assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size));
>>      trace_qemu_vfio_dma_map(s, host, size, temporary, iova);
>>      qemu_mutex_lock(&s->lock);
>>      mapping = qemu_vfio_find_mapping(s, host, &index);
>> -- 
>> 2.17.1
>> 

-- 
Wei Yang
Help you, Help me


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

* Re: [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size
  2019-10-13  9:28   ` David Gibson
@ 2019-10-16  1:25     ` Wei Yang
  0 siblings, 0 replies; 23+ messages in thread
From: Wei Yang @ 2019-10-16  1:25 UTC (permalink / raw)
  To: David Gibson
  Cc: fam, mst, mark.cave-ayland, qemu-devel, kraxel, den, qemu-block,
	quintela, armbru, pasic, borntraeger, marcandre.lureau, ehabkost,
	sw, dgilbert, yuval.shaia, alex.williamson, stefanha, pbonzini,
	rth, kwolf, cohuck, qemu-s390x, mreitz, qemu-ppc, Wei Yang,
	imammedo

On Sun, Oct 13, 2019 at 08:28:41PM +1100, David Gibson wrote:
>On Sun, Oct 13, 2019 at 10:11:45AM +0800, Wei Yang wrote:
>> There are three page size in qemu:
>> 
>>   real host page size
>>   host page size
>>   target page size
>> 
>> All of them have dedicate variable to represent. For the last two, we
>> use the same form in the whole qemu project, while for the first one we
>> use two forms: qemu_real_host_page_size and getpagesize().
>> 
>> qemu_real_host_page_size is defined to be a replacement of
>> getpagesize(), so let it serve the role.
>> 
>> [Note] Not fully tested for some arch or device.
>> 
>> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
>
>Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
>
>Although the chances of someone messing this up again are almost 100%.
>

Hi, David

I found put a check in checkpatch.pl may be a good way to prevent it.

Just draft a patch, hope you would like it.

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



-- 
Wei Yang
Help you, Help me


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

* Re: [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size
  2019-10-13  2:11 ` [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size Wei Yang
                     ` (4 preceding siblings ...)
  2019-10-15 11:45   ` Yuval Shaia
@ 2019-10-23  9:19   ` Paolo Bonzini
  5 siblings, 0 replies; 23+ messages in thread
From: Paolo Bonzini @ 2019-10-23  9:19 UTC (permalink / raw)
  To: Wei Yang, ehabkost, imammedo, kwolf, mreitz, stefanha, fam, den,
	marcandre.lureau, kraxel, mst, rth, cohuck, pasic, borntraeger,
	mark.cave-ayland, david, yuval.shaia, marcel.apfelbaum,
	alex.williamson, quintela, dgilbert, armbru, sw
  Cc: qemu-s390x, qemu-ppc, qemu-devel, qemu-block

On 13/10/19 04:11, Wei Yang wrote:
> There are three page size in qemu:
> 
>   real host page size
>   host page size
>   target page size
> 
> All of them have dedicate variable to represent. For the last two, we
> use the same form in the whole qemu project, while for the first one we
> use two forms: qemu_real_host_page_size and getpagesize().
> 
> qemu_real_host_page_size is defined to be a replacement of
> getpagesize(), so let it serve the role.
> 
> [Note] Not fully tested for some arch or device.
> 
> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
> ---
>  accel/kvm/kvm-all.c            |  6 +++---
>  backends/hostmem.c             |  2 +-
>  block.c                        |  4 ++--
>  block/file-posix.c             |  9 +++++----
>  block/io.c                     |  2 +-
>  block/parallels.c              |  2 +-
>  block/qcow2-cache.c            |  2 +-
>  contrib/vhost-user-gpu/vugbm.c |  2 +-
>  exec.c                         |  6 +++---
>  hw/intc/s390_flic_kvm.c        |  2 +-
>  hw/ppc/mac_newworld.c          |  2 +-
>  hw/ppc/spapr_pci.c             |  2 +-
>  hw/rdma/vmw/pvrdma_main.c      |  2 +-
>  hw/vfio/spapr.c                |  7 ++++---
>  include/exec/ram_addr.h        |  2 +-
>  include/qemu/osdep.h           |  4 ++--
>  migration/migration.c          |  2 +-
>  migration/postcopy-ram.c       |  4 ++--
>  monitor/misc.c                 |  2 +-
>  target/ppc/kvm.c               |  2 +-
>  tests/vhost-user-bridge.c      |  8 ++++----
>  util/mmap-alloc.c              | 10 +++++-----
>  util/oslib-posix.c             |  4 ++--
>  util/oslib-win32.c             |  2 +-
>  util/vfio-helpers.c            | 12 ++++++------
>  25 files changed, 52 insertions(+), 50 deletions(-)
> 
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index d2d96d73e8..140b0bd8f6 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -52,7 +52,7 @@
>  /* KVM uses PAGE_SIZE in its definition of KVM_COALESCED_MMIO_MAX. We
>   * need to use the real host PAGE_SIZE, as that's what KVM will use.
>   */
> -#define PAGE_SIZE getpagesize()
> +#define PAGE_SIZE qemu_real_host_page_size
>  
>  //#define DEBUG_KVM
>  
> @@ -507,7 +507,7 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section,
>  {
>      ram_addr_t start = section->offset_within_region +
>                         memory_region_get_ram_addr(section->mr);
> -    ram_addr_t pages = int128_get64(section->size) / getpagesize();
> +    ram_addr_t pages = int128_get64(section->size) / qemu_real_host_page_size;
>  
>      cpu_physical_memory_set_dirty_lebitmap(bitmap, start, pages);
>      return 0;
> @@ -1841,7 +1841,7 @@ static int kvm_init(MachineState *ms)
>       * even with KVM.  TARGET_PAGE_SIZE is assumed to be the minimum
>       * page size for the system though.
>       */
> -    assert(TARGET_PAGE_SIZE <= getpagesize());
> +    assert(TARGET_PAGE_SIZE <= qemu_real_host_page_size);
>  
>      s->sigmask_len = 8;
>  
> diff --git a/backends/hostmem.c b/backends/hostmem.c
> index 6d333dc23c..e773bdfa6e 100644
> --- a/backends/hostmem.c
> +++ b/backends/hostmem.c
> @@ -304,7 +304,7 @@ size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
>  #else
>  size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
>  {
> -    return getpagesize();
> +    return qemu_real_host_page_size;
>  }
>  #endif
>  
> diff --git a/block.c b/block.c
> index 5944124845..98f47e2902 100644
> --- a/block.c
> +++ b/block.c
> @@ -106,7 +106,7 @@ size_t bdrv_opt_mem_align(BlockDriverState *bs)
>  {
>      if (!bs || !bs->drv) {
>          /* page size or 4k (hdd sector size) should be on the safe side */
> -        return MAX(4096, getpagesize());
> +        return MAX(4096, qemu_real_host_page_size);
>      }
>  
>      return bs->bl.opt_mem_alignment;
> @@ -116,7 +116,7 @@ size_t bdrv_min_mem_align(BlockDriverState *bs)
>  {
>      if (!bs || !bs->drv) {
>          /* page size or 4k (hdd sector size) should be on the safe side */
> -        return MAX(4096, getpagesize());
> +        return MAX(4096, qemu_real_host_page_size);
>      }
>  
>      return bs->bl.min_mem_alignment;
> diff --git a/block/file-posix.c b/block/file-posix.c
> index f12c06de2d..f60ac3f93f 100644
> --- a/block/file-posix.c
> +++ b/block/file-posix.c
> @@ -322,7 +322,7 @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp)
>  {
>      BDRVRawState *s = bs->opaque;
>      char *buf;
> -    size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize());
> +    size_t max_align = MAX(MAX_BLOCKSIZE, qemu_real_host_page_size);
>      size_t alignments[] = {1, 512, 1024, 2048, 4096};
>  
>      /* For SCSI generic devices the alignment is not really used.
> @@ -1131,13 +1131,14 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
>  
>          ret = sg_get_max_segments(s->fd);
>          if (ret > 0) {
> -            bs->bl.max_transfer = MIN(bs->bl.max_transfer, ret * getpagesize());
> +            bs->bl.max_transfer = MIN(bs->bl.max_transfer,
> +                                      ret * qemu_real_host_page_size);
>          }
>      }
>  
>      raw_probe_alignment(bs, s->fd, errp);
>      bs->bl.min_mem_alignment = s->buf_align;
> -    bs->bl.opt_mem_alignment = MAX(s->buf_align, getpagesize());
> +    bs->bl.opt_mem_alignment = MAX(s->buf_align, qemu_real_host_page_size);
>  }
>  
>  static int check_for_dasd(int fd)
> @@ -1700,7 +1701,7 @@ static int allocate_first_block(int fd, size_t max_size)
>      size_t write_size = (max_size < MAX_BLOCKSIZE)
>          ? BDRV_SECTOR_SIZE
>          : MAX_BLOCKSIZE;
> -    size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize());
> +    size_t max_align = MAX(MAX_BLOCKSIZE, qemu_real_host_page_size);
>      void *buf;
>      ssize_t n;
>      int ret;
> diff --git a/block/io.c b/block/io.c
> index 4f9ee97c2b..a201c8721a 100644
> --- a/block/io.c
> +++ b/block/io.c
> @@ -159,7 +159,7 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error **errp)
>          bdrv_merge_limits(&bs->bl, &bs->file->bs->bl);
>      } else {
>          bs->bl.min_mem_alignment = 512;
> -        bs->bl.opt_mem_alignment = getpagesize();
> +        bs->bl.opt_mem_alignment = qemu_real_host_page_size;
>  
>          /* Safe default since most protocols use readv()/writev()/etc */
>          bs->bl.max_iov = IOV_MAX;
> diff --git a/block/parallels.c b/block/parallels.c
> index 7cd2714b69..f1dfb03eef 100644
> --- a/block/parallels.c
> +++ b/block/parallels.c
> @@ -847,7 +847,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
>          }
>      }
>  
> -    s->bat_dirty_block = 4 * getpagesize();
> +    s->bat_dirty_block = 4 * qemu_real_host_page_size;
>      s->bat_dirty_bmap =
>          bitmap_new(DIV_ROUND_UP(s->header_size, s->bat_dirty_block));
>  
> diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
> index d29b038a67..7444b9c4ab 100644
> --- a/block/qcow2-cache.c
> +++ b/block/qcow2-cache.c
> @@ -74,7 +74,7 @@ static void qcow2_cache_table_release(Qcow2Cache *c, int i, int num_tables)
>  /* Using MADV_DONTNEED to discard memory is a Linux-specific feature */
>  #ifdef CONFIG_LINUX
>      void *t = qcow2_cache_get_table_addr(c, i);
> -    int align = getpagesize();
> +    int align = qemu_real_host_page_size;
>      size_t mem_size = (size_t) c->table_size * num_tables;
>      size_t offset = QEMU_ALIGN_UP((uintptr_t) t, align) - (uintptr_t) t;
>      size_t length = QEMU_ALIGN_DOWN(mem_size - offset, align);
> diff --git a/contrib/vhost-user-gpu/vugbm.c b/contrib/vhost-user-gpu/vugbm.c
> index d3bb82ff0e..9c357b6399 100644
> --- a/contrib/vhost-user-gpu/vugbm.c
> +++ b/contrib/vhost-user-gpu/vugbm.c
> @@ -52,7 +52,7 @@ struct udmabuf_create {
>  static size_t
>  udmabuf_get_size(struct vugbm_buffer *buf)
>  {
> -    return ROUND_UP(buf->width * buf->height * 4, getpagesize());
> +    return ROUND_UP(buf->width * buf->height * 4, qemu_real_host_page_size);
>  }
>  
>  static bool
> diff --git a/exec.c b/exec.c
> index bdcfcdff3f..27ef36769d 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1762,11 +1762,11 @@ long qemu_maxrampagesize(void)
>  #else
>  long qemu_minrampagesize(void)
>  {
> -    return getpagesize();
> +    return qemu_real_host_page_size;
>  }
>  long qemu_maxrampagesize(void)
>  {
> -    return getpagesize();
> +    return qemu_real_host_page_size;
>  }
>  #endif
>  
> @@ -2425,7 +2425,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
>      new_block->max_length = max_size;
>      assert(max_size >= size);
>      new_block->fd = -1;
> -    new_block->page_size = getpagesize();
> +    new_block->page_size = qemu_real_host_page_size;
>      new_block->host = host;
>      if (host) {
>          new_block->flags |= RAM_PREALLOC;
> diff --git a/hw/intc/s390_flic_kvm.c b/hw/intc/s390_flic_kvm.c
> index cedccba8a9..c9ee80eaae 100644
> --- a/hw/intc/s390_flic_kvm.c
> +++ b/hw/intc/s390_flic_kvm.c
> @@ -25,7 +25,7 @@
>  #include "migration/qemu-file-types.h"
>  #include "trace.h"
>  
> -#define FLIC_SAVE_INITIAL_SIZE getpagesize()
> +#define FLIC_SAVE_INITIAL_SIZE qemu_real_host_page_size
>  #define FLIC_FAILED (-1UL)
>  #define FLIC_SAVEVM_VERSION 1
>  
> diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
> index c5bbcc7433..3594517f0c 100644
> --- a/hw/ppc/mac_newworld.c
> +++ b/hw/ppc/mac_newworld.c
> @@ -439,7 +439,7 @@ static void ppc_core99_init(MachineState *machine)
>      }
>  
>      /* The NewWorld NVRAM is not located in the MacIO device */
> -    if (kvm_enabled() && getpagesize() > 4096) {
> +    if (kvm_enabled() && qemu_real_host_page_size > 4096) {
>          /* We can't combine read-write and read-only in a single page, so
>             move the NVRAM out of ROM again for KVM */
>          nvram_addr = 0xFFE00000;
> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> index 01ff41d4c4..191b295412 100644
> --- a/hw/ppc/spapr_pci.c
> +++ b/hw/ppc/spapr_pci.c
> @@ -1942,7 +1942,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
>       * our memory slot is of page size granularity.
>       */
>      if (kvm_enabled()) {
> -        msi_window_size = getpagesize();
> +        msi_window_size = qemu_real_host_page_size;
>      }
>  
>      memory_region_init_io(&sphb->msiwindow, OBJECT(sphb), &spapr_msi_ops, spapr,
> diff --git a/hw/rdma/vmw/pvrdma_main.c b/hw/rdma/vmw/pvrdma_main.c
> index 3e36e13013..3722d9e772 100644
> --- a/hw/rdma/vmw/pvrdma_main.c
> +++ b/hw/rdma/vmw/pvrdma_main.c
> @@ -601,7 +601,7 @@ static void pvrdma_realize(PCIDevice *pdev, Error **errp)
>      rdma_info_report("Initializing device %s %x.%x", pdev->name,
>                       PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
>  
> -    if (TARGET_PAGE_SIZE != getpagesize()) {
> +    if (TARGET_PAGE_SIZE != qemu_real_host_page_size) {
>          error_setg(errp, "Target page size must be the same as host page size");
>          return;
>      }
> diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
> index e853eebe11..33692fc86f 100644
> --- a/hw/vfio/spapr.c
> +++ b/hw/vfio/spapr.c
> @@ -196,14 +196,15 @@ int vfio_spapr_create_window(VFIOContainer *container,
>       * bits_per_level is a safe guess of how much we can allocate per level:
>       * 8 is the current minimum for CONFIG_FORCE_MAX_ZONEORDER and MAX_ORDER
>       * is usually bigger than that.
> -     * Below we look at getpagesize() as TCEs are allocated from system pages.
> +     * Below we look at qemu_real_host_page_size as TCEs are allocated from
> +     * system pages.
>       */
> -    bits_per_level = ctz64(getpagesize()) + 8;
> +    bits_per_level = ctz64(qemu_real_host_page_size) + 8;
>      create.levels = bits_total / bits_per_level;
>      if (bits_total % bits_per_level) {
>          ++create.levels;
>      }
> -    max_levels = (64 - create.page_shift) / ctz64(getpagesize());
> +    max_levels = (64 - create.page_shift) / ctz64(qemu_real_host_page_size);
>      for ( ; create.levels <= max_levels; ++create.levels) {
>          ret = ioctl(container->fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &create);
>          if (!ret) {
> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
> index e96e621de5..d638941272 100644
> --- a/include/exec/ram_addr.h
> +++ b/include/exec/ram_addr.h
> @@ -380,7 +380,7 @@ static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
>      hwaddr addr;
>      ram_addr_t ram_addr;
>      unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
> -    unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE;
> +    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? */
> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> index c7d242f476..0f97d68586 100644
> --- a/include/qemu/osdep.h
> +++ b/include/qemu/osdep.h
> @@ -423,9 +423,9 @@ void qemu_anon_ram_free(void *ptr, size_t size);
>  #  define QEMU_VMALLOC_ALIGN (256 * 4096)
>  #elif defined(__linux__) && defined(__sparc__)
>  #include <sys/shm.h>
> -#  define QEMU_VMALLOC_ALIGN MAX(getpagesize(), SHMLBA)
> +#  define QEMU_VMALLOC_ALIGN MAX(qemu_real_host_page_size, SHMLBA)
>  #else
> -#  define QEMU_VMALLOC_ALIGN getpagesize()
> +#  define QEMU_VMALLOC_ALIGN qemu_real_host_page_size
>  #endif
>  
>  #ifdef CONFIG_POSIX
> diff --git a/migration/migration.c b/migration/migration.c
> index ff9504cf28..264da3c88a 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -2288,7 +2288,7 @@ static struct rp_cmd_args {
>  static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname,
>                                         ram_addr_t start, size_t len)
>  {
> -    long our_host_ps = getpagesize();
> +    long our_host_ps = qemu_real_host_page_size;
>  
>      trace_migrate_handle_rp_req_pages(rbname, start, len);
>  
> diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
> index 1f63e65ed7..5f6eec1276 100644
> --- a/migration/postcopy-ram.c
> +++ b/migration/postcopy-ram.c
> @@ -308,7 +308,7 @@ static bool ufd_check_and_apply(int ufd, MigrationIncomingState *mis)
>          return false;
>      }
>  
> -    if (getpagesize() != ram_pagesize_summary()) {
> +    if (qemu_real_host_page_size != ram_pagesize_summary()) {
>          bool have_hp = false;
>          /* We've got a huge page */
>  #ifdef UFFD_FEATURE_MISSING_HUGETLBFS
> @@ -346,7 +346,7 @@ static int test_ramblock_postcopiable(RAMBlock *rb, void *opaque)
>   */
>  bool postcopy_ram_supported_by_host(MigrationIncomingState *mis)
>  {
> -    long pagesize = getpagesize();
> +    long pagesize = qemu_real_host_page_size;
>      int ufd = -1;
>      bool ret = false; /* Error unless we change it */
>      void *testarea = NULL;
> diff --git a/monitor/misc.c b/monitor/misc.c
> index aef16f6cfb..3baa15f3bf 100644
> --- a/monitor/misc.c
> +++ b/monitor/misc.c
> @@ -862,7 +862,7 @@ static uint64_t vtop(void *ptr, Error **errp)
>      uint64_t pinfo;
>      uint64_t ret = -1;
>      uintptr_t addr = (uintptr_t) ptr;
> -    uintptr_t pagesize = getpagesize();
> +    uintptr_t pagesize = qemu_real_host_page_size;
>      off_t offset = addr / pagesize * sizeof(pinfo);
>      int fd;
>  
> diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
> index 820724cc7d..7d2e8969ac 100644
> --- a/target/ppc/kvm.c
> +++ b/target/ppc/kvm.c
> @@ -411,7 +411,7 @@ void kvm_check_mmu(PowerPCCPU *cpu, Error **errp)
>           * will be a normal mapping, not a special hugepage one used
>           * for RAM.
>           */
> -        if (getpagesize() < 0x10000) {
> +        if (qemu_real_host_page_size < 0x10000) {
>              error_setg(errp,
>                         "KVM can't supply 64kiB CI pages, which guest expects");
>          }
> diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
> index c4e350e1f5..6c3d490611 100644
> --- a/tests/vhost-user-bridge.c
> +++ b/tests/vhost-user-bridge.c
> @@ -468,8 +468,8 @@ vubr_queue_set_started(VuDev *dev, int qidx, bool started)
>  
>      if (started && vubr->notifier.fd >= 0) {
>          vu_set_queue_host_notifier(dev, vq, vubr->notifier.fd,
> -                                   getpagesize(),
> -                                   qidx * getpagesize());
> +                                   qemu_real_host_page_size,
> +                                   qidx * qemu_real_host_page_size);
>      }
>  
>      if (qidx % 2 == 1) {
> @@ -594,7 +594,7 @@ static void *notifier_thread(void *arg)
>  {
>      VuDev *dev = (VuDev *)arg;
>      VubrDev *vubr = container_of(dev, VubrDev, vudev);
> -    int pagesize = getpagesize();
> +    int pagesize = qemu_real_host_page_size;
>      int qidx;
>  
>      while (true) {
> @@ -630,7 +630,7 @@ vubr_host_notifier_setup(VubrDev *dev)
>      void *addr;
>      int fd;
>  
> -    length = getpagesize() * VHOST_USER_BRIDGE_MAX_QUEUES;
> +    length = qemu_real_host_page_size * VHOST_USER_BRIDGE_MAX_QUEUES;
>  
>      fd = mkstemp(template);
>      if (fd < 0) {
> diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
> index f7f177d0ea..27dcccd8ec 100644
> --- a/util/mmap-alloc.c
> +++ b/util/mmap-alloc.c
> @@ -48,7 +48,7 @@ size_t qemu_fd_getpagesize(int fd)
>  #endif
>  #endif
>  
> -    return getpagesize();
> +    return qemu_real_host_page_size;
>  }
>  
>  size_t qemu_mempath_getpagesize(const char *mem_path)
> @@ -79,7 +79,7 @@ size_t qemu_mempath_getpagesize(const char *mem_path)
>  #endif
>  #endif
>  
> -    return getpagesize();
> +    return qemu_real_host_page_size;
>  }
>  
>  void *qemu_ram_mmap(int fd,
> @@ -114,7 +114,7 @@ void *qemu_ram_mmap(int fd,
>       */
>      flags = MAP_PRIVATE;
>      pagesize = qemu_fd_getpagesize(fd);
> -    if (fd == -1 || pagesize == getpagesize()) {
> +    if (fd == -1 || pagesize == qemu_real_host_page_size) {
>          guardfd = -1;
>          flags |= MAP_ANONYMOUS;
>      } else {
> @@ -123,7 +123,7 @@ void *qemu_ram_mmap(int fd,
>      }
>  #else
>      guardfd = -1;
> -    pagesize = getpagesize();
> +    pagesize = qemu_real_host_page_size;
>      flags = MAP_PRIVATE | MAP_ANONYMOUS;
>  #endif
>  
> @@ -205,7 +205,7 @@ void qemu_ram_munmap(int fd, void *ptr, size_t size)
>  #if defined(__powerpc64__) && defined(__linux__)
>          pagesize = qemu_fd_getpagesize(fd);
>  #else
> -        pagesize = getpagesize();
> +        pagesize = qemu_real_host_page_size;
>  #endif
>          munmap(ptr, size + pagesize);
>      }
> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
> index f8693384fc..5a291cc982 100644
> --- a/util/oslib-posix.c
> +++ b/util/oslib-posix.c
> @@ -617,7 +617,7 @@ void *qemu_alloc_stack(size_t *sz)
>  #ifdef CONFIG_DEBUG_STACK_USAGE
>      void *ptr2;
>  #endif
> -    size_t pagesz = getpagesize();
> +    size_t pagesz = qemu_real_host_page_size;
>  #ifdef _SC_THREAD_STACK_MIN
>      /* avoid stacks smaller than _SC_THREAD_STACK_MIN */
>      long min_stack_sz = sysconf(_SC_THREAD_STACK_MIN);
> @@ -679,7 +679,7 @@ void qemu_free_stack(void *stack, size_t sz)
>      unsigned int usage;
>      void *ptr;
>  
> -    for (ptr = stack + getpagesize(); ptr < stack + sz;
> +    for (ptr = stack + qemu_real_host_page_size; ptr < stack + sz;
>           ptr += sizeof(uint32_t)) {
>          if (*(uint32_t *)ptr != 0xdeadbeaf) {
>              break;
> diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> index 886e400d6a..e9b14ab178 100644
> --- a/util/oslib-win32.c
> +++ b/util/oslib-win32.c
> @@ -554,7 +554,7 @@ void os_mem_prealloc(int fd, char *area, size_t memory, int smp_cpus,
>                       Error **errp)
>  {
>      int i;
> -    size_t pagesize = getpagesize();
> +    size_t pagesize = qemu_real_host_page_size;
>  
>      memory = (memory + pagesize - 1) & -pagesize;
>      for (i = 0; i < memory / pagesize; i++) {
> diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
> index 26ffd0d6b5..813f7ec564 100644
> --- a/util/vfio-helpers.c
> +++ b/util/vfio-helpers.c
> @@ -514,9 +514,9 @@ static IOVAMapping *qemu_vfio_add_mapping(QEMUVFIOState *s,
>      IOVAMapping m = {.host = host, .size = size, .iova = iova};
>      IOVAMapping *insert;
>  
> -    assert(QEMU_IS_ALIGNED(size, getpagesize()));
> -    assert(QEMU_IS_ALIGNED(s->low_water_mark, getpagesize()));
> -    assert(QEMU_IS_ALIGNED(s->high_water_mark, getpagesize()));
> +    assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size));
> +    assert(QEMU_IS_ALIGNED(s->low_water_mark, qemu_real_host_page_size));
> +    assert(QEMU_IS_ALIGNED(s->high_water_mark, qemu_real_host_page_size));
>      trace_qemu_vfio_new_mapping(s, host, size, index, iova);
>  
>      assert(index >= 0);
> @@ -567,7 +567,7 @@ static void qemu_vfio_undo_mapping(QEMUVFIOState *s, IOVAMapping *mapping,
>  
>      index = mapping - s->mappings;
>      assert(mapping->size > 0);
> -    assert(QEMU_IS_ALIGNED(mapping->size, getpagesize()));
> +    assert(QEMU_IS_ALIGNED(mapping->size, qemu_real_host_page_size));
>      assert(index >= 0 && index < s->nr_mappings);
>      if (ioctl(s->container, VFIO_IOMMU_UNMAP_DMA, &unmap)) {
>          error_setg(errp, "VFIO_UNMAP_DMA failed: %d", -errno);
> @@ -613,8 +613,8 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
>      IOVAMapping *mapping;
>      uint64_t iova0;
>  
> -    assert(QEMU_PTR_IS_ALIGNED(host, getpagesize()));
> -    assert(QEMU_IS_ALIGNED(size, getpagesize()));
> +    assert(QEMU_PTR_IS_ALIGNED(host, qemu_real_host_page_size));
> +    assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size));
>      trace_qemu_vfio_dma_map(s, host, size, temporary, iova);
>      qemu_mutex_lock(&s->lock);
>      mapping = qemu_vfio_find_mapping(s, host, &index);
> 

Queued this one, thanks.

Paolo


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

end of thread, back to index

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-13  2:11 [PATCH 0/2] cleanup on page size Wei Yang
2019-10-13  2:11 ` [PATCH 1/2] cpu: use ROUND_UP() to define xxx_PAGE_ALIGN Wei Yang
2019-10-13  6:34   ` Michael S. Tsirkin
2019-10-13  9:27   ` David Gibson
2019-10-13 15:56   ` Richard Henderson
2019-10-13 23:36     ` David Gibson
2019-10-14  1:01     ` Wei Yang
2019-10-14  2:38       ` Richard Henderson
2019-10-14  3:19         ` Wei Yang
2019-10-14 16:25   ` Juan Quintela
2019-10-13  2:11 ` [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size Wei Yang
2019-10-13  6:35   ` Michael S. Tsirkin
2019-10-13  9:28   ` David Gibson
2019-10-16  1:25     ` Wei Yang
2019-10-13 16:03   ` Richard Henderson
2019-10-14  9:15   ` Dr. David Alan Gilbert
2019-10-14 21:36     ` Wei Yang
2019-10-14 23:12       ` Richard Henderson
2019-10-15 11:45   ` Yuval Shaia
2019-10-16  1:07     ` Wei Yang
2019-10-23  9:19   ` Paolo Bonzini
2019-10-13  6:36 ` [PATCH 0/2] cleanup on page size Michael S. Tsirkin
2019-10-14 21:59 ` Wei Yang

QEMU-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/qemu-devel/0 qemu-devel/git/0.git
	git clone --mirror https://lore.kernel.org/qemu-devel/1 qemu-devel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 qemu-devel qemu-devel/ https://lore.kernel.org/qemu-devel \
		qemu-devel@nongnu.org
	public-inbox-index qemu-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.nongnu.qemu-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git