Replaced locks with lock guard macros
PATCH v4 1/2 lockable: fix __COUNTER__ macro to be referenced properly
In reply to [email protected]From: Daniel Brodsky <[email protected]>
- __COUNTER__ doesn't work with ## concat
- replaced ## with glue() macro so __COUNTER__ is evaluated
--- include/qemu/lockable.h | 4 ++-- include/qemu/rcu.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
include/qemu/lockable.h +2 -2
@@ -152,7 +152,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuLockable, qemu_lockable_auto_unlock)* } */ #define WITH_QEMU_LOCK_GUARD (x) \ - WITH_QEMU_LOCK_GUARD_((x), qemu_lockable_auto##__COUNTER__) + WITH_QEMU_LOCK_GUARD_((x), glue(qemu_lockable_auto, __COUNTER__))/** * QEMU_LOCK_GUARD - Lock an object until the end of the scope
@@ -170,7 +170,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuLockable, qemu_lockable_auto_unlock)* } */ #define QEMU_LOCK_GUARD (x) \ - g_autoptr(QemuLockable) qemu_lockable_auto##__COUNTER__ = \ + g_autoptr(QemuLockable) glue(qemu_lockable_auto, __COUNTER__) = \ qemu_lockable_auto_lock(QEMU_MAKE_LOCKABLE((x)))#endif
include/qemu/rcu.h +1 -1
@@ -170,7 +170,7 @@ static inline void rcu_read_auto_unlock(RCUReadAuto *r) G_DEFINE_AUTOPTR_CLEANUP_FUNC(RCUReadAuto, rcu_read_auto_unlock)#define WITH_RCU_READ_LOCK_GUARD () \ - WITH_RCU_READ_LOCK_GUARD_(_rcu_read_auto##__COUNTER__) + WITH_RCU_READ_LOCK_GUARD_(glue(_rcu_read_auto, __COUNTER__))#define WITH_RCU_READ_LOCK_GUARD_ (var) \ for (g_autoptr(RCUReadAuto) var = rcu_read_auto_lock(); \
Signature · 1 line
2.25.1
v4 cover Replaced locks with lock guard macros
From: Daniel Brodsky <[email protected]>
This patch set adds:
- a fix for lock guard macros so they can be used multiple times in the same function
- replacement of locks with lock guards where appropriate
v3 -> v4:
- removed unneeded unlocks from areas where lock guards are now used
- dropped change to lock guard in iscsi.c as it changed old functionality
v2 -> v3:
- added __COUNTER__ fix for additional lock guard macro
- added missing include header in platform.c
v1 -> v2:
- fixed whitespace churn
- added cover letter so patch set referenced correctly
Daniel Brodsky (2):
lockable: fix __COUNTER__ macro to be referenced properly
lockable: replaced locks with lock guard macros where appropriate
block/iscsi.c | 7 ++---- block/nfs.c | 51 +++++++++++++++++++---------------------- cpus-common.c | 14 ++++------- hw/display/qxl.c | 43 ++++++++++++++++------------------ hw/vfio/platform.c | 5 ++-- include/qemu/lockable.h | 4 ++-- include/qemu/rcu.h | 2 +- migration/migration.c | 3 +-- migration/multifd.c | 8 +++---- migration/ram.c | 3 +-- monitor/misc.c | 4 +--- ui/spice-display.c | 14 +++++------ util/log.c | 4 ++-- util/qemu-timer.c | 17 +++++++------- util/rcu.c | 8 +++---- util/thread-pool.c | 3 +-- util/vfio-helpers.c | 5 ++-- 17 files changed, 86 insertions(+), 109 deletions(-)
Signature · 1 line
2.25.1
PATCH v4 2/2 lockable: replaced locks with lock guard macros where appropriate
From: Daniel Brodsky <[email protected]>
- ran regexp "qemu_mutex_lock\(.*\).*\n.*if" to find targets
- replaced result with QEMU_LOCK_GUARD if all unlocks at function end
- replaced result with WITH_QEMU_LOCK_GUARD if unlock not at end
--- block/iscsi.c | 7 ++---- block/nfs.c | 51 ++++++++++++++++++++----------------------- cpus-common.c | 14 +++++------- hw/display/qxl.c | 43 +++++++++++++++++------------------- hw/vfio/platform.c | 5 ++--- migration/migration.c | 3 +-- migration/multifd.c | 8 +++---- migration/ram.c | 3 +-- monitor/misc.c | 4 +--- ui/spice-display.c | 14 ++++++------ util/log.c | 4 ++-- util/qemu-timer.c | 17 +++++++-------- util/rcu.c | 8 +++---- util/thread-pool.c | 3 +-- util/vfio-helpers.c | 5 ++--- 15 files changed, 83 insertions(+), 106 deletions(-)
block/iscsi.c +2 -5
@@ -1395,20 +1395,17 @@ static void iscsi_nop_timed_event(void *opaque) {IscsiLun *iscsilun = opaque; -qemu_mutex_lock (&iscsilun->mutex); +QEMU_LOCK_GUARD (&iscsilun->mutex);if (iscsi_get_nops_in_flight (iscsilun->iscsi) >=MAX_NOP_FAILURES ) {error_report ("iSCSI: NOP timeout. Reconnecting..." ); iscsilun->request_timed_out = true; }else if (iscsi_nop_out_async (iscsilun->iscsi,NULL ,NULL ,0 ,NULL ) !=0 ) {error_report ("iSCSI: failed to sent NOP-Out. Disabling NOP messages." ); - goto out; +return ; }timer_mod (iscsilun->nop_timer,qemu_clock_get_ms (QEMU_CLOCK_REALTIME ) +NOP_INTERVAL );iscsi_set_events (iscsilun); - -out: -qemu_mutex_unlock (&iscsilun->mutex); }static void iscsi_readcapacity_sync (IscsiLun *iscsilun,Error **errp)
block/nfs.c +24 -27
73 lines not on this page · raw message
cpus-common.c +5 -9
@@ -22,6 +22,7 @@#include "exec/cpu-common.h" #include "hw/core/cpu.h" #include "sysemu/cpus.h" +#include "qemu/lockable.h" static QemuMutex qemu_cpu_list_lock;static QemuCond exclusive_cond;
@@ -71,7 +72,7 @@ static int cpu_get_free_index(void)void cpu_list_add (CPUState *cpu) { -qemu_mutex_lock (&qemu_cpu_list_lock); +QEMU_LOCK_GUARD (&qemu_cpu_list_lock);if (cpu->cpu_index ==UNASSIGNED_CPU_INDEX ) { cpu->cpu_index =cpu_get_free_index ();assert (cpu->cpu_index !=UNASSIGNED_CPU_INDEX );
@@ -79,15 +80,13 @@ void cpu_list_add(CPUState *cpu)assert (!cpu_index_auto_assigned); }QTAILQ_INSERT_TAIL_RCU (&cpus, cpu, node); -qemu_mutex_unlock (&qemu_cpu_list_lock); }void cpu_list_remove (CPUState *cpu) { -qemu_mutex_lock (&qemu_cpu_list_lock); +QEMU_LOCK_GUARD (&qemu_cpu_list_lock);if (!QTAILQ_IN_USE (cpu, node)) {/* there is nothing to undo since cpu_exec_init() hasn't been called */ -qemu_mutex_unlock (&qemu_cpu_list_lock);return ; }
@@ -95,7 +94,6 @@ void cpu_list_remove(CPUState *cpu)QTAILQ_REMOVE_RCU (&cpus, cpu, node); cpu->cpu_index =UNASSIGNED_CPU_INDEX ; -qemu_mutex_unlock (&qemu_cpu_list_lock); }struct qemu_work_item {
@@ -237,7 +235,7 @@ void cpu_exec_start(CPUState *cpu)* see cpu->running == true, and it will kick the CPU. */ if (unlikely (atomic_read (&pending_cpus))) { -qemu_mutex_lock (&qemu_cpu_list_lock); +QEMU_LOCK_GUARD (&qemu_cpu_list_lock);if (!cpu->has_waiter) {/* Not counted in pending_cpus, let the exclusive item * run. Since we have the lock, just set cpu->running to true
@@ -252,7 +250,6 @@ void cpu_exec_start(CPUState *cpu)* waiter at cpu_exec_end. */ } -qemu_mutex_unlock (&qemu_cpu_list_lock); } }
@@ -280,7 +277,7 @@ void cpu_exec_end(CPUState *cpu)* next cpu_exec_start. */ if (unlikely (atomic_read (&pending_cpus))) { -qemu_mutex_lock (&qemu_cpu_list_lock); +QEMU_LOCK_GUARD (&qemu_cpu_list_lock);if (cpu->has_waiter) { cpu->has_waiter = false;atomic_set (&pending_cpus, pending_cpus -1 );
@@ -288,7 +285,6 @@ void cpu_exec_end(CPUState *cpu)qemu_cond_signal (&exclusive_cond); } } -qemu_mutex_unlock (&qemu_cpu_list_lock); } }
hw/display/qxl.c +20 -23
77 lines not on this page · raw message
hw/vfio/platform.c +2 -3
@@ -22,6 +22,7 @@#include "hw/vfio/vfio-platform.h" #include "migration/vmstate.h" #include "qemu/error-report.h" +#include "qemu/lockable.h" #include "qemu/main-loop.h" #include "qemu/module.h" #include "qemu/range.h"
@@ -216,7 +217,7 @@ static void vfio_intp_interrupt(VFIOINTp *intp)VFIOPlatformDevice *vdev = intp->vdev;bool delay_handling = false; -qemu_mutex_lock (&vdev->intp_mutex); +QEMU_LOCK_GUARD (&vdev->intp_mutex);if (intp->state ==VFIO_IRQ_INACTIVE ) { QLIST_FOREACH(tmp, &vdev->intp_list, next) { if (tmp->state == VFIO_IRQ_ACTIVE ||
@@ -236,7 +237,6 @@ static void vfio_intp_interrupt(VFIOINTp *intp)QSIMPLEQ_INSERT_TAIL (&vdev->pending_intp_queue, intp, pqnext); ret =event_notifier_test_and_clear (intp->interrupt); -qemu_mutex_unlock (&vdev->intp_mutex);return ; }
@@ -266,7 +266,6 @@ static void vfio_intp_interrupt(VFIOINTp *intp)qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL ) + vdev->mmap_timeout); } -qemu_mutex_unlock (&vdev->intp_mutex); }/**
migration/migration.c +1 -2
@@ -1652,11 +1652,10 @@ static void migrate_fd_cleanup_bh(void *opaque)void migrate_set_error (MigrationState *s,const Error *error) { -qemu_mutex_lock (&s->error_mutex); +QEMU_LOCK_GUARD (&s->error_mutex);if (!s->error) { s->error =error_copy (error); } -qemu_mutex_unlock (&s->error_mutex); }void migrate_fd_error (MigrationState *s,const Error *error)
migration/multifd.c +4 -4
@@ -894,11 +894,11 @@ void multifd_recv_sync_main(void)for (i =0 ; i <migrate_multifd_channels (); i++) {MultiFDRecvParams *p = &multifd_recv_state->params[i]; -qemu_mutex_lock (&p->mutex); -if (multifd_recv_state->packet_num < p->packet_num) { - multifd_recv_state->packet_num = p->packet_num; + WITH_QEMU_LOCK_GUARD(&p->mutex) { +if (multifd_recv_state->packet_num < p->packet_num) { + multifd_recv_state->packet_num = p->packet_num; + } } -qemu_mutex_unlock (&p->mutex);trace_multifd_recv_sync_main_signal (p->id);qemu_sem_post (&p->sem_sync); }
migration/ram.c +1 -2
@@ -1368,7 +1368,7 @@ static RAMBlock *unqueue_page(RAMState *rs, ram_addr_t *offset)return NULL ; } -qemu_mutex_lock (&rs->src_page_req_mutex); +QEMU_LOCK_GUARD (&rs->src_page_req_mutex);if (!QSIMPLEQ_EMPTY (&rs->src_page_requests)) {struct RAMSrcPageRequest *entry =QSIMPLEQ_FIRST (&rs->src_page_requests);
@@ -1385,7 +1385,6 @@ static RAMBlock *unqueue_page(RAMState *rs, ram_addr_t *offset)migration_consume_urgent_request (); } } -qemu_mutex_unlock (&rs->src_page_req_mutex);return block; }
monitor/misc.c +1 -3
@@ -1473,7 +1473,7 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,MonFdsetFd *mon_fdset_fd;AddfdInfo *fdinfo; -qemu_mutex_lock (&mon_fdsets_lock); +QEMU_LOCK_GUARD (&mon_fdsets_lock);if (has_fdset_id) { QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {/* Break if match found or match impossible due to ordering by ID */
@@ -1494,7 +1494,6 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,if (fdset_id <0 ) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"fdset-id" ,"a non-negative value" ); -qemu_mutex_unlock (&mon_fdsets_lock);return NULL ; }/* Use specified fdset ID */
@@ -1545,7 +1544,6 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id, fdinfo->fdset_id = mon_fdset->id; fdinfo->fd = mon_fdset_fd->fd; -qemu_mutex_unlock (&mon_fdsets_lock);return fdinfo; }
ui/spice-display.c +7 -7
@@ -18,6 +18,7 @@#include "qemu/osdep.h" #include "ui/qemu-spice.h" #include "qemu/timer.h" +#include "qemu/lockable.h" #include "qemu/main-loop.h" #include "qemu/option.h" #include "qemu/queue.h"
@@ -483,12 +484,12 @@ void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd) {graphic_hw_update (ssd->dcl.con); -qemu_mutex_lock (&ssd->lock); -if (QTAILQ_EMPTY (&ssd->updates) && ssd->ds) { -qemu_spice_create_update (ssd); - ssd->notify++; + WITH_QEMU_LOCK_GUARD(&ssd->lock) { +if (QTAILQ_EMPTY (&ssd->updates) && ssd->ds) { +qemu_spice_create_update (ssd); + ssd->notify++; + } } -qemu_mutex_unlock (&ssd->lock);trace_qemu_spice_display_refresh (ssd->qxl.id, ssd->notify);if (ssd->notify) {
@@ -580,7 +581,7 @@ static int interface_get_cursor_command(QXLInstance *sin, QXLCommandExt *ext)SimpleSpiceDisplay *ssd =container_of (sin, SimpleSpiceDisplay, qxl);int ret; -qemu_mutex_lock (&ssd->lock); +QEMU_LOCK_GUARD (&ssd->lock);if (ssd->ptr_define) { *ext = ssd->ptr_define->ext; ssd->ptr_define =NULL ;
@@ -592,7 +593,6 @@ static int interface_get_cursor_command(QXLInstance *sin, QXLCommandExt *ext) }else { ret = false; } -qemu_mutex_unlock (&ssd->lock);return ret; }
util/log.c +2 -2
@@ -25,6 +25,7 @@#include "qemu/cutils.h" #include "trace/control.h" #include "qemu/thread.h" +#include "qemu/lockable.h" static char *logfilename;static QemuMutex qemu_logfile_mutex;
@@ -94,7 +95,7 @@ void qemu_set_log(int log_flags)if (qemu_loglevel && (!is_daemonized () || logfilename)) { need_to_open_file = true; } -qemu_mutex_lock (&qemu_logfile_mutex); +QEMU_LOCK_GUARD (&qemu_logfile_mutex);if (qemu_logfile && !need_to_open_file) { logfile = qemu_logfile;atomic_rcu_set (&qemu_logfile,NULL );
@@ -136,7 +137,6 @@ void qemu_set_log(int log_flags) }atomic_rcu_set (&qemu_logfile, logfile); } -qemu_mutex_unlock (&qemu_logfile_mutex); }void qemu_log_needs_buffers (void )
util/qemu-timer.c +8 -9
@@ -459,17 +459,16 @@ void timer_mod_anticipate_ns(QEMUTimer *ts, int64_t expire_time)QEMUTimerList *timer_list = ts->timer_list;bool rearm; -qemu_mutex_lock (&timer_list->active_timers_lock); -if (ts->expire_time ==-1 || ts->expire_time > expire_time) { -if (ts->expire_time !=-1 ) { -timer_del_locked (timer_list, ts); + WITH_QEMU_LOCK_GUARD(&timer_list->active_timers_lock) { +if (ts->expire_time ==-1 || ts->expire_time > expire_time) { +if (ts->expire_time !=-1 ) { +timer_del_locked (timer_list, ts); + } + rearm =timer_mod_ns_locked (timer_list, ts, expire_time); + }else { + rearm = false; } - rearm =timer_mod_ns_locked (timer_list, ts, expire_time); - }else { - rearm = false; } -qemu_mutex_unlock (&timer_list->active_timers_lock); -if (rearm) {timerlist_rearm (timer_list); }
util/rcu.c +3 -5
@@ -31,6 +31,7 @@#include "qemu/atomic.h" #include "qemu/thread.h" #include "qemu/main-loop.h" +#include "qemu/lockable.h" #if defined(CONFIG_MALLOC_TRIM )#include <malloc.h> #endif
@@ -141,14 +142,14 @@ static void wait_for_readers(void)void synchronize_rcu (void ) { -qemu_mutex_lock (&rcu_sync_lock); +QEMU_LOCK_GUARD (&rcu_sync_lock);/* Write RCU-protected pointers before reading p_rcu_reader->ctr. * Pairs with smp_mb_placeholder() in rcu_read_lock(). */ smp_mb_global (); -qemu_mutex_lock (&rcu_registry_lock); +QEMU_LOCK_GUARD (&rcu_registry_lock);if (!QLIST_EMPTY (®istry)) {/* In either case, the atomic_mb_set below blocks stores that free * old RCU-protected pointers.
@@ -169,9 +170,6 @@ void synchronize_rcu(void)wait_for_readers (); } - -qemu_mutex_unlock (&rcu_registry_lock); -qemu_mutex_unlock (&rcu_sync_lock); }
util/thread-pool.c +1 -2
@@ -210,7 +210,7 @@ static void thread_pool_cancel(BlockAIOCB *acb)trace_thread_pool_cancel (elem, elem->common.opaque); -qemu_mutex_lock (&pool->lock); +QEMU_LOCK_GUARD (&pool->lock); if (elem->state == THREAD_QUEUED &&/* No thread has yet started working on elem. we can try to "steal" * the item from the worker if we can get a signal from the
@@ -225,7 +225,6 @@ static void thread_pool_cancel(BlockAIOCB *acb) elem->ret = -ECANCELED ; } -qemu_mutex_unlock (&pool->lock); }static AioContext *thread_pool_get_aio_context (BlockAIOCB *acb)
util/vfio-helpers.c +2 -3
@@ -21,6 +21,7 @@#include "standard-headers/linux/pci_regs.h" #include "qemu/event_notifier.h" #include "qemu/vfio-helpers.h" +#include "qemu/lockable.h" #include "trace.h" #define QEMU_VFIO_DEBUG 0
@@ -667,14 +668,12 @@ int qemu_vfio_dma_reset_temporary(QEMUVFIOState *s) .size = QEMU_VFIO_IOVA_MAX - s->high_water_mark, };trace_qemu_vfio_dma_reset_temporary (s); -qemu_mutex_lock (&s->lock); +QEMU_LOCK_GUARD (&s->lock);if (ioctl (s->container,VFIO_IOMMU_UNMAP_DMA , &unmap)) {error_report ("VFIO_UNMAP_DMA failed: %s" ,strerror (errno)); -qemu_mutex_unlock (&s->lock);return -errno; } s->high_water_mark =QEMU_VFIO_IOVA_MAX ; -qemu_mutex_unlock (&s->lock);return 0 ; }
Signature · 1 line
2.25.1
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series failed the asan build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.
=== TEST SCRIPT BEGIN ===
#!/bin/bash
export ARCH=x86_64
make docker-image-fedora V=1 NETWORK=1
time make docker-test-debug@fedora TARGET_LIST=x86_64-softmmu J=14 NETWORK=1 === TEST SCRIPT END ===
CC util/module.o
CC util/host-utils.o
CC util/bitmap.o
/tmp/qemu-test/src/util/thread-pool.c:213:5: error: unused variable 'qemu_lockable_auto1' [-Werror,-Wunused-variable]
QEMU_LOCK_GUARD(&pool->lock);
^/tmp/qemu-test/src/include/qemu/lockable.h:173:29: note: expanded from macro 'QEMU_LOCK_GUARD'
---qemu_lockable_auto1
^
1 error generated.
make: *** [/tmp/qemu-test/src/rules.mak:69: util/thread-pool.o] Error 1
make: *** Waiting for unfinished jobs....
Traceback (most recent call last):
File "./tests/docker/docker.py", line 664, in <module>
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=83384554d5524a41b38a2f80c48c2f30', '-u', '1003', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=x86_64-softmmu', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew2/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-zoq4pqgi/src/docker-src.2020-03-20-09.39.56.20282:/var/tmp/qemu:z,ro', 'qemu:fedora', '/var/tmp/qemu/run', 'test-debug']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=83384554d5524a41b38a2f80c48c2f30
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-zoq4pqgi/src'
make: *** [docker-run-test-debug@fedora] Error 2
real 3m26.893s
user 0m8.375s
The full log is available at
http://patchew.org/logs/[email protected]/testing.asan/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Quoted 4 lines · On Fri, Mar 20, 2020 at 06:43:23AM -0700, [email protected] wrote:
/tmp/qemu-test/src/util/thread-pool.c:213:5: error: unused variable 'qemu_lockable_auto1' [-Werror,-Wunused-variable]QEMU_LOCK_GUARD(&pool->lock); ^
/tmp/qemu-test/src/include/qemu/lockable.h:173:29: note: expanded from macro 'QEMU_LOCK_GUARD'
Apparently gcc suppresses "unused variable" warnings with g_autoptr() so we didn't see this warning before.
clang does report them so let's silence the warning manually. Please add G_GNUC_UNUSED onto the g_autoptr variable definition in the QEMU_LOCK_GUARD() macro:
#define QEMU_LOCK_GUARD(x) \
g_autoptr(QemuLockable) qemu_lockable_auto##__COUNTER__ G_GNUC_UNUSED = \
qemu_lockable_auto_lock(QEMU_MAKE_LOCKABLE((x)))The WITH_*_LOCK_GUARD() macros should not require changes because the variable is both read and written.
You can test locally by building with clang (llvm) instead of gcc:
./configure --cc=clang
Re: [PATCH v4 1/2] lockable: fix __COUNTER__ macro to be referenced properly
In reply to [email protected]Quoted 5 lines · On Fri, Mar 20, 2020 at 05:31:36AM -0700, [email protected] wrote:
From: Daniel Brodsky <[email protected]>
-
__COUNTER__doesn't work with ## concat
- replaced ## withglue()macro so__COUNTER__is evaluated
Quoted 7 lines
Fixes 3284c3ddc4Signed-off-by Daniel Brodsky <[email protected]>--- include/qemu/lockable.h | 4 ++-- include/qemu/rcu.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
Please see my comment on the Patchew CI error message in this email thread.
Stefan
Re: [PATCH v4 2/2] lockable: replaced locks with lock guard macros where appropriate
In reply to [email protected]Quoted 16 lines · On Fri, Mar 20, 2020 at 05:31:37AM -0700, [email protected] wrote:
From: Daniel Brodsky <[email protected]>
- ran regexp "qemu_mutex_lock\(.*\).*\n.*if" to find targets
- replaced result withQEMU_LOCK_GUARDif all unlocks at function end
- replaced result withWITH_QEMU_LOCK_GUARDif unlock not at endSigned-off-by Daniel Brodsky <[email protected]>--- block/iscsi.c | 7 ++---- block/nfs.c | 51 ++++++++++++++++++++----------------------- cpus-common.c | 14 +++++------- hw/display/qxl.c | 43 +++++++++++++++++------------------- hw/vfio/platform.c | 5 ++--- migration/migration.c | 3 +-- migration/multifd.c | 8 +++---- migration/ram.c | 3 +--
Quoted 8 lines
monitor/misc.c | 4 +--- ui/spice-display.c | 14 ++++++------ util/log.c | 4 ++-- util/qemu-timer.c | 17 +++++++-------- util/rcu.c | 8 +++---- util/thread-pool.c | 3 +-- util/vfio-helpers.c | 5 ++--- 15 files changed, 83 insertions(+), 106 deletions(-)
Quoted 18 lines · Stefan Hajnoczi
Quoted 4 lines · On Fri, Mar 20, 2020 at 06:43:23AM -0700, [email protected] wrote:
/tmp/qemu-test/src/util/thread-pool.c:213:5: error: unused variable 'qemu_lockable_auto1' [-Werror,-Wunused-variable]QEMU_LOCK_GUARD(&pool->lock); ^
/tmp/qemu-test/src/include/qemu/lockable.h:173:29: note: expanded from macro 'QEMU_LOCK_GUARD'Apparently gcc suppresses "unused variable" warnings with
g_autoptr()so we didn't see this warning before.clang does report them so let's silence the warning manually. Please add
G_GNUC_UNUSEDonto theg_autoptrvariable definition in theQEMU_LOCK_GUARD()macro:#define QEMU_LOCK_GUARD(x) \ g_autoptr(QemuLockable) qemu_lockable_auto##__COUNTER__ G_GNUC_UNUSED = \ qemu_lockable_auto_lock(QEMU_MAKE_LOCKABLE((x)))
Quoted 6 lines
The WITH_*_LOCK_GUARD() macros should not require changes because the variable is both read and written.
You can test locally by building with clang (llvm) instead of gcc:
./configure --cc=clang
Using --cc=clang is causing the following error in several different places:qemu/target/ppc/translate.c:1894:18: error: result of comparison 'target_ulong' (aka 'unsigned int') <= 4294967295
is always true [-Werror,-Wtautological-type-limit-compare]
if (mask <= 0xffffffffu) {
~~~~ ^ ~~~~~~~~~~~these errors don't come up when building with gcc. Any idea how to fix this? Or should I just suppress it?
Quoted 30 lines · Daniel Brodsky
Quoted 18 lines · Stefan Hajnoczi
Quoted 4 lines · On Fri, Mar 20, 2020 at 06:43:23AM -0700, [email protected] wrote:
/tmp/qemu-test/src/util/thread-pool.c:213:5: error: unused variable 'qemu_lockable_auto1' [-Werror,-Wunused-variable]QEMU_LOCK_GUARD(&pool->lock); ^
/tmp/qemu-test/src/include/qemu/lockable.h:173:29: note: expanded from macro 'QEMU_LOCK_GUARD'Apparently gcc suppresses "unused variable" warnings with
g_autoptr()so we didn't see this warning before.clang does report them so let's silence the warning manually. Please add
G_GNUC_UNUSEDonto theg_autoptrvariable definition in theQEMU_LOCK_GUARD()macro:#define QEMU_LOCK_GUARD(x) \ g_autoptr(QemuLockable) qemu_lockable_auto##__COUNTER__ G_GNUC_UNUSED = \ qemu_lockable_auto_lock(QEMU_MAKE_LOCKABLE((x)))Quoted 6 lines
The WITH_*_LOCK_GUARD() macros should not require changes because the variable is both read and written.
You can test locally by building with clang (llvm) instead of gcc:
./configure --cc=clangUsing --cc=clang is causing the following error in several different places:
qemu/target/ppc/translate.c:1894:18: error: result of comparison 'target_ulong' (aka 'unsigned int') <= 4294967295
is always true [-Werror,-Wtautological-type-limit-compare]
Quoted 5 lines
if (mask <= 0xffffffffu) { ~~~~ ^ ~~~~~~~~~~~these errors don't come up when building with gcc. Any idea how to fix this? Or should I just suppress it?
I'm of the opinion that it should be suppressed.
This is the *correct* test for ppc64, and the warning for ppc32 is simply because target_ulong == uint32_t. True is the correct result for ppc32.
We simply want the compiler to DTRT: simplify this test and remove the else as unreachable.
r~
Quoted 15 lines
Quoted 9 lines
Quoted 4 lines
You can test locally by building with clang (llvm) instead of gcc:
./configure --cc=clangUsing --cc=clang is causing the following error in several different places:
qemu/target/ppc/translate.c:1894:18: error: result of comparison 'target_ulong' (aka 'unsigned int') <= 4294967295
is always true [-Werror,-Wtautological-type-limit-compare]Quoted 5 lines
if (mask <= 0xffffffffu) { ~~~~ ^ ~~~~~~~~~~~these errors don't come up when building with gcc. Any idea how to fix this? Or should I just suppress it?
Quoted 7 lines
I'm of the opinion that it should be suppressed.
This is the *correct* test for ppc64, and the warning for ppc32 is simply because
target_ulong==uint32_t. True is the correct result for ppc32.We simply want the compiler to DTRT: simplify this test and remove the else as unreachable.
There may be ways to rewrite that expression to avoid triggering the warning on a 32-bit platform. Untested, but does this help:
if (sizeof(mask) > 4 && mask <= 0xffffffffu) {
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Quoted 11 lines
There may be ways to rewrite that expression to avoid triggering the warning on a 32-bit platform. Untested, but does this help:
if (sizeof(mask) > 4 && mask <=
0xffffffffu) {--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
Unfortunately, the compiler still catches that the statement is always true for 32-bit.
An alternative might be to convert cases like this to a macro instead, which doesn't
cause any errors.
Quoted 10 lines · Daniel Brodsky
Quoted 10 lines
There may be ways to rewrite that expression to avoid triggering the warning on a 32-bit platform. Untested, but does this help:
if (sizeof(mask) > 4 && mask <=
0xffffffffu) {--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
Quoted 5 lines
Unfortunately, the compiler still catches that the statement is always true for 32-bit.
An alternative might be to convert cases like this to a macro instead, which doesn't
cause any errors.
My preference is to add -Wno-tautological-type-limit-compare in configure, so we don't have to work around this same issue elsewhere in the code base.
r~
Quoted 6 lines · Richard Henderson
My preference is to add -Wno-tautological-type-limit-compare in configure, so we don't have to work around this same issue elsewhere in the code base.
r~
What do you think would be the best way to add this? I could change all additions of the -m32 flag to instead use -m32 -Wno-tautological-type-limit-compare or add the flag if qemu is being compiled with clang and -m32 already enabled.
Daniel
Quoted 7 lines · Daniel Brodsky
Quoted 5 lines · Richard Henderson
My preference is to add -Wno-tautological-type-limit-compare in configure, so we don't have to work around this same issue elsewhere in the code base.
Quoted 6 lines
Quoted 1 line
r~
What do you think would be the best way to add this? I could change all additions of the
-m32flag to instead use-m32 -Wno-tautological-type-limit-compareor add the flag if qemu is being compiled with clang and-m32already enabled.
I was going to add it unconditionally, with all of the other warning flags.
Except that it doesn't work -- clang-9 *still* warns. Clearly a clang bug, but there doesn't seem to be any workaround at all except --disable-werror.
r~
Quoted 16 lines · Richard Henderson
Quoted 7 lines · Daniel Brodsky
Quoted 5 lines · Richard Henderson
My preference is to add -Wno-tautological-type-limit-compare in configure, so we don't have to work around this same issue elsewhere in the code base.
Quoted 6 lines
Quoted 1 line
r~
What do you think would be the best way to add this? I could change all additions of the
-m32flag to instead use-m32 -Wno-tautological-type-limit-compareor add the flag if qemu is being compiled with clang and-m32already enabled.
Quoted 7 lines
I was going to add it unconditionally, with all of the other warning flags.
Except that it doesn't work -- clang-9 *still* warns. Clearly a clang bug, but there doesn't seem to be any workaround at all except --disable-werror.
r~
Using #pragma clang diagnostic ignored "-Wtautological-type-limit-compare" suppresses the errors (on Clang 9). I could go and drop that in for the problem areas? There's only a few so it wouldn't be a major change. I'm thinking of adding a macro like this:
#define PRAGMA(x) _Pragma(stringify(x))
#define IF_IGNORE_TYPE_LIMIT(statement) \
PRAGMA(clang diagnostic push) \
PRAGMA(clang diagnostic ignored "-Wtautological-type-limit-compare") \
if (statement) \
PRAGMA(clang diagnostic pop)and replacing the problem conditionals with it.
Daniel
Quoted 11 lines · Daniel Brodsky
Using
#pragma clang diagnostic ignored "-Wtautological-type-limit-compare"suppresses the errors (on Clang 9). I could go and drop that in for the problem areas? There's only a few so it wouldn't be a major change. I'm thinking of adding a macro like this:
#define PRAGMA(x) _Pragma(stringify(x))#define IF_IGNORE_TYPE_LIMIT(statement) \ PRAGMA(clang diagnostic push) \ PRAGMA(clang diagnostic ignored "-Wtautological-type-limit-compare") \ if (statement) \ PRAGMA(clang diagnostic pop)
This is not an in-principle objection, but we have found in the past that various gcc/clang implementations of _Pragma() are simply buggy when used inside macros; see the comments on this patch attempt:
https://patchwork.kernel.org/patch/10620079/
(one of which has a link to half a dozen gcc bug reports involving _Pragma and three clang bugs). For that particular case the approach we eventually took was to only use the _Pragma() stuff on clang because gcc mishandled it and luckily the spurious warning was clang-only. It's a shame, because the whole point of _Pragma() is to let you do this kind of thing in a macro, but the actual implementations in compilers are clearly just not fit-for-purpose.
So if you do go down this path please make sure you test it on a wide variety of different clang and gcc versions.
thanks
-- PMM