util/pagesize: Make qemu_real_host_page_size of type size_t
Subsystems (2)
v2 cover util/pagesize: Make qemu_real_host_page_size of type size_t
Since v1:
Make QEMU_VMALLOC_ALIGN unsigned in a previous patch
Philippe Mathieu-Daudé (2):
qemu/osdep: Make QEMU_VMALLOC_ALIGN unsigned long util/pagesize: Make qemu_real_host_page_size of type size_t
include/exec/ram_addr.h | 4 ++-- include/qemu/osdep.h | 6 +++--- accel/kvm/kvm-all.c | 3 ++- block/qcow2-cache.c | 2 +- exec.c | 8 ++++---- hw/ppc/spapr_pci.c | 2 +- hw/virtio/virtio-mem.c | 2 +- migration/migration.c | 2 +- migration/postcopy-ram.c | 2 +- monitor/misc.c | 2 +- util/pagesize.c | 2 +- 11 files changed, 18 insertions(+), 17 deletions(-)
Signature · 1 line
2.21.3
PATCH v2 1/2 qemu/osdep: Make QEMU_VMALLOC_ALIGN unsigned long
QEMU_VMALLOC_ALIGN is sometimes expanded to signed type, other times to unsigned. Unify using unsigned.
--- include/qemu/osdep.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/qemu/osdep.h +2 -2
@@ -454,10 +454,10 @@ void qemu_anon_ram_free(void *ptr, size_t size);/* Use 2 MiB alignment so transparent hugepages can be used by KVM. Valgrind does not support alignments larger than 1 MiB, therefore we need special code which handles running on Valgrind. */ -# define QEMU_VMALLOC_ALIGN (512 * 4096) +# define QEMU_VMALLOC_ALIGN (512 * 4096UL)#elif defined(__linux__) && defined(__s390x__)/* Use 1 MiB (segment size) alignment so gmap can be used by KVM. */ -# define QEMU_VMALLOC_ALIGN (256 * 4096) +# define QEMU_VMALLOC_ALIGN (256 * 4096UL)#elif defined(__linux__) && defined(__sparc__)#include <sys/shm.h> # define QEMU_VMALLOC_ALIGN MAX(qemu_real_host_page_size, SHMLBA)
Signature · 1 line
2.21.3
Re: [PATCH-for-5.1? v2 1/2] qemu/osdep: Make QEMU_VMALLOC_ALIGN unsigned long
Quoted 4 lines · Philippe Mathieu-Daudé
QEMU_VMALLOC_ALIGNis sometimes expanded to signed type, other times to unsigned. Unify using unsigned.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 21 lines
--- include/qemu/osdep.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)include/qemu/osdep.h +2
-2@@ -454,10 +454,10 @@ void qemu_anon_ram_free(void *ptr, size_t size);/* Use 2 MiB alignment so transparent hugepages can be used by KVM. Valgrind does not support alignments larger than 1 MiB, therefore we need special code which handles running on Valgrind. */ -# define QEMU_VMALLOC_ALIGN (512 * 4096) +# define QEMU_VMALLOC_ALIGN (512 * 4096UL)#elif defined(__linux__) && defined(__s390x__)/* Use 1 MiB (segment size) alignment so gmap can be used by KVM. */ -# define QEMU_VMALLOC_ALIGN (256 * 4096) +# define QEMU_VMALLOC_ALIGN (256 * 4096UL)#elif defined(__linux__) && defined(__sparc__)#include <sys/shm.h> # define QEMU_VMALLOC_ALIGN MAX(qemu_real_host_page_size, SHMLBA)
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH v2 2/2 util/pagesize: Make qemu_real_host_page_size of type size_t
In reply to Philippe Mathieu-DaudéWe use different types to hold 'qemu_real_host_page_size'. Unify picking 'size_t' which seems the best candidate.
Doing so fix a format string issue in hw/virtio/virtio-mem.c reported when building with GCC 4.9.4:
hw/virtio/virtio-mem.c: In function ‘virtio_mem_set_block_size’:
hw/virtio/virtio-mem.c:756:9: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 7 has type ‘uintptr_t’ [-Werror=format=]
error_setg(errp, "'%s' property has to be at least 0x%" PRIx32, name,
^--- include/exec/ram_addr.h | 4 ++-- include/qemu/osdep.h | 2 +- accel/kvm/kvm-all.c | 3 ++- block/qcow2-cache.c | 2 +- exec.c | 8 ++++---- hw/ppc/spapr_pci.c | 2 +- hw/virtio/virtio-mem.c | 2 +- migration/migration.c | 2 +- migration/postcopy-ram.c | 2 +- monitor/misc.c | 2 +- util/pagesize.c | 2 +- 11 files changed, 16 insertions(+), 15 deletions(-)
include/exec/ram_addr.h +2 -2
@@ -93,8 +93,8 @@ static inline unsigned long int ramblock_recv_bitmap_offset(void *host_addr,bool ramblock_is_pmem (RAMBlock *rb); -long qemu_minrampagesize (void ); -long qemu_maxrampagesize (void ); +size_t qemu_minrampagesize (void ); +size_t qemu_maxrampagesize (void );/** * qemu_ram_alloc_from_file,
include/qemu/osdep.h +1 -1
@@ -635,10 +635,10 @@ char *qemu_get_pid_name(pid_t pid);*/ pid_t qemu_fork (Error **errp); +extern size_t qemu_real_host_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. */ -extern uintptr_t qemu_real_host_page_size;extern intptr_t qemu_real_host_page_mask;extern int qemu_icache_linesize;
accel/kvm/kvm-all.c +2 -1
@@ -674,7 +674,8 @@ static int kvm_log_clear_one_slot(KVMSlot *mem, int as_id, uint64_t start,KVMState *s = kvm_state;uint64_t end, bmap_start, start_delta, bmap_npages;struct kvm_clear_dirty_log d; -unsigned long *bmap_clear =NULL , psize = qemu_real_host_page_size; +unsigned long *bmap_clear =NULL ; +size_t psize = qemu_real_host_page_size;int ret;/*
block/qcow2-cache.c +1 -1
@@ -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 = qemu_real_host_page_size; +size_t 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);
exec.c +4 -4
@@ -1657,7 +1657,7 @@ static int find_max_backend_pagesize(Object *obj, void *opaque)* TODO: We assume right now that all mapped host memory backends are * used as RAM, however some might be used for different purposes. */ -long qemu_minrampagesize (void ) +size_t qemu_minrampagesize (void ) {long hpsize =LONG_MAX ;Object *memdev_root =object_resolve_path ("/objects" ,NULL );
@@ -1666,7 +1666,7 @@ long qemu_minrampagesize(void)return hpsize; } -long qemu_maxrampagesize (void ) +size_t qemu_maxrampagesize (void ) {long pagesize =0 ;Object *memdev_root =object_resolve_path ("/objects" ,NULL );
@@ -1675,11 +1675,11 @@ long qemu_maxrampagesize(void) return pagesize; }#else -long qemu_minrampagesize (void ) +size_t qemu_minrampagesize (void ) {return qemu_real_host_page_size; } -long qemu_maxrampagesize (void ) +size_t qemu_maxrampagesize (void ) {return qemu_real_host_page_size; }
hw/ppc/spapr_pci.c +1 -1
@@ -1810,7 +1810,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)char *namebuf;int i;PCIBus *bus; -uint64_t msi_window_size =4096 ; +size_t msi_window_size =4096 ;SpaprTceTable *tcet;const unsigned windows_supported =spapr_phb_windows_supported (sphb);Error *local_err =NULL ;
hw/virtio/virtio-mem.c +1 -1
@@ -753,7 +753,7 @@ static void virtio_mem_set_block_size(Object *obj, Visitor *v, const char *name, }if (value <VIRTIO_MEM_MIN_BLOCK_SIZE ) { -error_setg (errp,"'%s' property has to be at least 0x%" PRIx32, name, +error_setg (errp,"'%s' property has to be at least 0x%zx" , name,VIRTIO_MEM_MIN_BLOCK_SIZE );return ; }else if (!is_power_of_2 (value)) {
migration/migration.c +1 -1
@@ -2433,7 +2433,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 = qemu_real_host_page_size; +size_t our_host_ps = qemu_real_host_page_size;trace_migrate_handle_rp_req_pages (rbname, start, len);
migration/postcopy-ram.c +1 -1
@@ -345,7 +345,7 @@ static int test_ramblock_postcopiable(RAMBlock *rb, void *opaque)*/ bool postcopy_ram_supported_by_host (MigrationIncomingState *mis) { -long pagesize = qemu_real_host_page_size; +size_t pagesize = qemu_real_host_page_size;int ufd =-1 ;bool ret = false;/* Error unless we change it */ void *testarea =NULL ;
monitor/misc.c +1 -1
@@ -740,7 +740,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 = qemu_real_host_page_size; +size_t pagesize = qemu_real_host_page_size;off_t offset = addr / pagesize *sizeof (pinfo);int fd;
util/pagesize.c +1 -1
@@ -8,7 +8,7 @@#include "qemu/osdep.h" -uintptr_t qemu_real_host_page_size; +size_t qemu_real_host_page_size;intptr_t qemu_real_host_page_mask;static void __attribute__((constructor))init_real_host_page_size (void )
Signature · 1 line
2.21.3
Quoted 6 lines · Philippe Mathieu-Daudé
We use different types to hold '
qemu_real_host_page_size'. Unify picking 'size_t' which seems the best candidate.Doing so fix a format string issue in
hw/virtio/virtio-mem.creported when building with GCC 4.9.4:
Quoted 8 lines
hw/virtio/virtio-mem.c: In function ‘virtio_mem_set_block_size’:
hw/virtio/virtio-mem.c:756:9: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 7 has type ‘uintptr_t’ [-Werror=format=]error_setg(errp, "'%s' property has to be at least 0x%" PRIx32, name, ^Fixes 910b25766b ("virtio-mem: Paravirtualized memory hot(un)plug")Reported-by Bruce Rogers <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
and ppc parts
Quoted 186 lines
--- include/exec/ram_addr.h | 4 ++-- include/qemu/osdep.h | 2 +- accel/kvm/kvm-all.c | 3 ++- block/qcow2-cache.c | 2 +- exec.c | 8 ++++---- hw/ppc/spapr_pci.c | 2 +- hw/virtio/virtio-mem.c | 2 +- migration/migration.c | 2 +- migration/postcopy-ram.c | 2 +- monitor/misc.c | 2 +- util/pagesize.c | 2 +- 11 files changed, 16 insertions(+), 15 deletions(-)include/exec/ram_addr.h +2
-2@@ -93,8 +93,8 @@ static inline unsigned long int ramblock_recv_bitmap_offset(void *host_addr,bool ramblock_is_pmem (RAMBlock *rb); -long qemu_minrampagesize (void ); -long qemu_maxrampagesize (void ); +size_t qemu_minrampagesize (void ); +size_t qemu_maxrampagesize (void );/** * qemu_ram_alloc_from_file, include/qemu/osdep.h +1
-1@@ -635,10 +635,10 @@ char *qemu_get_pid_name(pid_t pid);*/ pid_t qemu_fork (Error **errp); +extern size_t qemu_real_host_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. */ -extern uintptr_t qemu_real_host_page_size;extern intptr_t qemu_real_host_page_mask;extern int qemu_icache_linesize;accel/kvm/kvm-all.c +2
-1@@ -674,7 +674,8 @@ static int kvm_log_clear_one_slot(KVMSlot *mem, int as_id, uint64_t start,KVMState *s = kvm_state;uint64_t end, bmap_start, start_delta, bmap_npages;struct kvm_clear_dirty_log d; -unsigned long *bmap_clear =NULL , psize = qemu_real_host_page_size; +unsigned long *bmap_clear =NULL ; +size_t psize = qemu_real_host_page_size;int ret;/* block/qcow2-cache.c +1
-1@@ -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 = qemu_real_host_page_size; +size_t 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);exec.c +4
-4@@ -1657,7 +1657,7 @@ static int find_max_backend_pagesize(Object *obj, void *opaque)* TODO: We assume right now that all mapped host memory backends are * used as RAM, however some might be used for different purposes. */ -long qemu_minrampagesize (void ) +size_t qemu_minrampagesize (void ) {long hpsize =LONG_MAX ;Object *memdev_root =object_resolve_path ("/objects" ,NULL );@@ -1666,7 +1666,7 @@ long qemu_minrampagesize(void)return hpsize; } -long qemu_maxrampagesize (void ) +size_t qemu_maxrampagesize (void ) {long pagesize =0 ;Object *memdev_root =object_resolve_path ("/objects" ,NULL );@@ -1675,11 +1675,11 @@ long qemu_maxrampagesize(void) return pagesize; }#else -long qemu_minrampagesize (void ) +size_t qemu_minrampagesize (void ) {return qemu_real_host_page_size; } -long qemu_maxrampagesize (void ) +size_t qemu_maxrampagesize (void ) {return qemu_real_host_page_size; }hw/ppc/spapr_pci.c +1
-1@@ -1810,7 +1810,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)char *namebuf;int i;PCIBus *bus; -uint64_t msi_window_size =4096 ; +size_t msi_window_size =4096 ;SpaprTceTable *tcet;const unsigned windows_supported =spapr_phb_windows_supported (sphb);Error *local_err =NULL ;hw/virtio/virtio-mem.c +1
-1@@ -753,7 +753,7 @@ static void virtio_mem_set_block_size(Object *obj, Visitor *v, const char *name, }if (value <VIRTIO_MEM_MIN_BLOCK_SIZE ) { -error_setg (errp,"'%s' property has to be at least 0x%" PRIx32, name, +error_setg (errp,"'%s' property has to be at least 0x%zx" , name,VIRTIO_MEM_MIN_BLOCK_SIZE );return ; }else if (!is_power_of_2 (value)) {migration/migration.c +1
-1@@ -2433,7 +2433,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 = qemu_real_host_page_size; +size_t our_host_ps = qemu_real_host_page_size;trace_migrate_handle_rp_req_pages (rbname, start, len);migration/postcopy-ram.c +1
-1@@ -345,7 +345,7 @@ static int test_ramblock_postcopiable(RAMBlock *rb, void *opaque)*/ bool postcopy_ram_supported_by_host (MigrationIncomingState *mis) { -long pagesize = qemu_real_host_page_size; +size_t pagesize = qemu_real_host_page_size;int ufd =-1 ;bool ret = false;/* Error unless we change it */ void *testarea =NULL ;monitor/misc.c +1
-1@@ -740,7 +740,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 = qemu_real_host_page_size; +size_t pagesize = qemu_real_host_page_size;off_t offset = addr / pagesize *sizeof (pinfo);int fd;util/pagesize.c +1
-1@@ -8,7 +8,7 @@#include "qemu/osdep.h" -uintptr_t qemu_real_host_page_size; +size_t qemu_real_host_page_size;intptr_t qemu_real_host_page_mask;static void __attribute__((constructor))init_real_host_page_size (void )
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 2 lines · * Philippe Mathieu-Daudé ([email protected]) wrote:
Since v1:
MakeQEMU_VMALLOC_ALIGNunsigned in a previous patch
Nah, not for 5.1 - it feels like the type of thing that might on a really bad day create a really subtle bug.
Dave
Quoted 4 lines
Philippe Mathieu-Daudé (2):
qemu/osdep: MakeQEMU_VMALLOC_ALIGNunsigned long util/pagesize: Makeqemu_real_host_page_sizeof typesize_t
Quoted 16 lines
include/exec/ram_addr.h | 4 ++-- include/qemu/osdep.h | 6 +++--- accel/kvm/kvm-all.c | 3 ++- block/qcow2-cache.c | 2 +- exec.c | 8 ++++---- hw/ppc/spapr_pci.c | 2 +- hw/virtio/virtio-mem.c | 2 +- migration/migration.c | 2 +- migration/postcopy-ram.c | 2 +- monitor/misc.c | 2 +- util/pagesize.c | 2 +- 11 files changed, 18 insertions(+), 17 deletions(-)Signature · 1 line
2.21.3
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 6 lines · Dr. David Alan Gilbert
Quoted 2 lines · * Philippe Mathieu-Daudé ([email protected]) wrote:
Since v1:
MakeQEMU_VMALLOC_ALIGNunsigned in a previous patchNah, not for 5.1 - it feels like the type of thing that might on a really bad day create a really subtle bug.
Ack :)