Re: [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size
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 > >Reviewed-by: David Gibson > >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
Re: [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size
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 >> --- >> 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 >Tested-by: Yuval Shaia 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. >> @@
Re: [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size
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 > --- > 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 Tested-by: Yuval Shaia > 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 =
Re: [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size
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~
Re: [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size
On Mon, Oct 14, 2019 at 10:15:02AM +0100, Dr. David Alan Gilbert wrote: >* Wei Yang (richardw.y...@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 >> --- >> 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
Re: [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size
* Wei Yang (richardw.y...@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 > --- > 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 =
Re: [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size
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 > --- Reviewed-by: Richard Henderson r~
Re: [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size
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 Reviewed-by: David Gibson 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 signature.asc Description: PGP signature
Re: [PATCH 2/2] core: replace getpagesize() with qemu_real_host_page_size
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 Reviewed-by: Michael S. Tsirkin > --- > 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 * >