First batch of misc changes for 2.5 (2015-09-09)
Subsystems (3)
The following changes since commit 090d0bfd948343d522cd20bc634105b5cfe2483b:
s390: fix softmmu compilation (2015-08-28 16:05:24 +0100)
are available in the git repository at:
git://github.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to 9fd1a94888cd6a559f95c3596ec1ac28b74838c1:
cpu-exec: fix lock hierarchy for user-mode emulation (2015-09-09 15:34:56 +0200)
----------------------------------------------------------------
* Support for jemalloc
* qemu_mutex_lock_iothread "No such process" fix
* cutils: qemu_strto* wrappers
* iohandler.c simplification
* Many other fixes and misc patches.
And some MTTCG work (with Emilio's fixes squashed):
* Signal-free TCG kick
* Removing spinlock in favor of QemuMutex
* User-mode emulation multi-threading fixes/docs
----------------------------------------------------------------
Alexandre Derumier (1):
configure: Add support for jemalloc
Andrey Smetanin (1):
Added generic panic handler qemu_system_guest_panicked()
Aníbal Limón (1):
cpus.c: qemu_mutex_lock_iothread fix race condition at cpu thread init
Carlos L. Torres (5):
cutils: Add qemu_strtol() wrapper
cutils: Add qemu_strtoul() wrapper
cutils: Add qemu_strtoll() wrapper
cutils: Add qemu_strtoull() wrapper
qmp: Add example usage of strto*l() qemu wrapper
Dr. David Alan Gilbert (1):
Move RAMBlock and ram_list to ram_addr.h
Emilio G. Cota (7):
qemu-thread: handle spurious futex_wait wakeups
seqlock: add missing 'inline' to seqlock_read_retry
seqlock: read sequence number atomically
rcu: init rcu_registry_lock after fork
rcu: fix comment with s/rcu_gp_lock/rcu_registry_lock/
linux-user: call rcu_(un)register_thread on pthread_(exit|create)
translate-all: remove obsolete comment about l1_map
Fam Zheng (1):
iohandler: Use aio API
Gonglei (1):
vhost-scsi: fix wrong vhost-scsi firmware path
KONRAD Frederic (3):
cpus: remove tcg_halt_cond and tcg_cpu_thread globals replace spinlock by QemuMutex.
remove unused spinlock.
Michael Marineau (1):
Makefile.target: include top level build dir in vpath
Michael S. Tsirkin (1):
scripts/dump-guest-memory.py: fix after RAMBlock change
Paolo Bonzini (18):
i8257: rewrite DMA_schedule to avoid hooking into the CPU loop
i8257: remove cpu_request_exit irq
tcg: introduce tcg_current_cpu
remove qemu/tls.h
tcg: assign cpu->current_tb in a simpler place
tcg: synchronize cpu->exit_request and cpu->tcg_exit_req accesses
tcg: synchronize exit_request and tcg_current_cpu accesses use qemu_cpu_kick instead of cpu_exit or qemu_cpu_kick_thread
tcg: signal-free qemu_cpu_kick
CODING_STYLE: update mixed declaration rules
checkpatch: adapt some tests to QEMU
checkpatch: remove tests that are not relevant outside the kernel add macro file for coccinelle
cpus: protect work list with work_mutex
tcg: add memory barriers in page_find_alloc accesses
tcg: comment on which functions have to be called with mmap_lock held
exec: make mmap_lock/mmap_unlock globally available
cpu-exec: fix lock hierarchy for user-mode emulation
Peter Crosthwaite (1):
configure: factor out adding disas configure
Peter Lieven (1):
block/iscsi: validate block size returned from target
CODING_STYLE | 13 +- Makefile.target | 2 +- block/iscsi.c | 4 + bsd-user/qemu.h | 2 - configure | 93 +-- cpu-exec.c | 119 ++-- cpus.c | 130 ++--- exec.c | 2 +- gdbstub.c | 2 +- hw/block/fdc.c | 2 +- hw/dma/i82374.c | 5 +- hw/dma/i8257.c | 31 +- hw/i386/pc.c | 13 +- hw/isa/i82378.c | 3 +- hw/mips/mips_fulong2e.c | 13 +- hw/mips/mips_jazz.c | 13 +- hw/mips/mips_malta.c | 13 +- hw/misc/pvpanic.c | 3 +- hw/ppc/prep.c | 11 - hw/ppc/spapr_rtas.c | 2 +- hw/scsi/vhost-scsi.c | 2 +- hw/sparc/sun4m.c | 4 +- hw/sparc64/sun4u.c | 4 +- include/exec/cpu-all.h | 41 -- include/exec/exec-all.h | 15 +- include/exec/ram_addr.h | 40 ++ include/exec/spinlock.h | 49 -- include/hw/isa/isa.h | 4 +- include/qemu-common.h | 8 + include/qemu/main-loop.h | 3 +- include/qemu/rcu.h | 2 +- include/qemu/seqlock.h | 8 +- include/qemu/tls.h | 52 -- include/qom/cpu.h | 14 +- include/sysemu/sysemu.h | 1 + iohandler.c | 111 +--- linux-user/main.c | 6 +- linux-user/qemu.h | 2 - linux-user/syscall.c | 2 + main-loop.c | 5 +- qmp.c | 14 +- qom/cpu.c | 3 + scripts/checkpatch.pl | 540 +++--------------- scripts/cocci-macro-file.h | 119 ++++ scripts/dump-guest-memory.py | 2 +- target-i386/cpu.h | 3 + target-i386/mem_helper.c | 25 +- target-i386/translate.c | 2 + target-s390x/kvm.c | 11 +- tcg/tcg.h | 4 + tests/test-cutils.c | 1280 ++++++++++++++++++++++++++++++++++++++++++ translate-all.c | 85 ++- util/cutils.c | 136 +++++ util/qemu-thread-posix.c | 11 +- util/rcu.c | 7 +- vl.c | 6 + 56 files changed, 2057 insertions(+), 1040 deletions(-) delete mode 100644 include/exec/spinlock.h delete mode 100644 include/qemu/tls.h create mode 100644 scripts/cocci-macro-file.h
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 02/43] seqlock: add missing 'inline' to seqlock_read_retry
From: "Emilio G. Cota" <[email protected]>
Message-Id: <[email protected]>
--- include/qemu/seqlock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/qemu/seqlock.h +1 -1
@@ -62,7 +62,7 @@ static inline unsigned seqlock_read_begin(QemuSeqLock *sl)return ret; } -static int seqlock_read_retry (const QemuSeqLock *sl,unsigned start) +static inline int seqlock_read_retry (const QemuSeqLock *sl,unsigned start) {/* Read other fields before reading final sequence. */ smp_rmb ();
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 01/43] qemu-thread: handle spurious futex_wait wakeups
In reply to Paolo BonziniFrom: "Emilio G. Cota" <[email protected]>
Message-Id: <[email protected]>
--- util/qemu-thread-posix.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
util/qemu-thread-posix.c +10 -1
@@ -298,7 +298,16 @@ static inline void futex_wake(QemuEvent *ev, int n)static inline void futex_wait (QemuEvent *ev,unsigned val) { -futex (ev,FUTEX_WAIT , (int ) val,NULL ,NULL ,0 ); +while (futex (ev,FUTEX_WAIT , (int ) val,NULL ,NULL ,0 )) { +switch (errno) { +case EWOULDBLOCK : +return ; +case EINTR : +break ;/* get out of switch and retry */ +default : +abort (); + } + } }#else static inline void futex_wake (QemuEvent *ev,int n)
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 03/43] seqlock: read sequence number atomically
In reply to Paolo BonziniFrom: "Emilio G. Cota" <[email protected]>
With this change we make sure that the compiler will not optimise the read of the sequence number in any way.
Message-Id: <[email protected]>
--- include/qemu/seqlock.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
include/qemu/seqlock.h +3 -3
@@ -55,18 +55,18 @@ static inline void seqlock_write_unlock(QemuSeqLock *sl)static inline unsigned seqlock_read_begin (QemuSeqLock *sl) {/* Always fail if a write is in progress. */ -unsigned ret = sl->sequence & ~1 ; +unsigned ret =atomic_read (&sl->sequence);/* Read sequence before reading other fields. */ smp_rmb (); -return ret; +return ret & ~1 ; }static inline int seqlock_read_retry (const QemuSeqLock *sl,unsigned start) {/* Read other fields before reading final sequence. */ smp_rmb (); -return unlikely (sl->sequence != start); +return unlikely (atomic_read (&sl->sequence) != start); }#endif
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 04/43] cpus.c: qemu_mutex_lock_iothread fix race condition at cpu thread init
In reply to Paolo BonziniFrom: Aníbal Limón <[email protected]>
When QEMU starts the RCU thread executes qemu_mutex_lock_thread causing error "qemu:qemu_cpu_kick_thread: No such process" and exits.
This isn't occur frequently but in glibc the thread id can exist and this not guarantee that the thread is on active/running state. If is inserted a sleep(1) after newthread assignment [1] the issue appears.
So not make assumption that thread exist if first_cpu->thread is set then change the validation of cpu to created that is set into cpu threads (kvm, tcg, dummy).
Message-Id: <[email protected]>
--- cpus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
cpus.c +1 -1
@@ -1166,7 +1166,7 @@ void qemu_mutex_lock_iothread(void)* TCG code execution. */ if (!tcg_enabled () ||qemu_in_vcpu_thread () || - !first_cpu || !first_cpu->thread) { + !first_cpu || !first_cpu->created) {qemu_mutex_lock (&qemu_global_mutex);atomic_dec (&iothread_requesting_mutex); }else {
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 05/43] iohandler: Use aio API
In reply to Paolo BonziniFrom: Fam Zheng <[email protected]>
iohandler.c shares the same interface with aio, but with duplicated code. It's better to rebase iohandler, also because that aio is a more friendly interface to multi-threads.
Create a global AioContext instance and let its GSource handle the iohandler events.
Message-Id: <[email protected]>
--- include/qemu/main-loop.h | 3 +- iohandler.c | 111 +++++++---------------------------------------- main-loop.c | 5 ++- 3 files changed, 19 insertions(+), 100 deletions(-)
include/qemu/main-loop.h +1 -2
@@ -203,6 +203,7 @@ void qemu_set_fd_handler(int fd, IOHandler *fd_write, void *opaque); +GSource *iohandler_get_g_source (void );#ifdef CONFIG_POSIX /** * qemu_add_child_watch: Register a child process for reaping.
@@ -265,8 +266,6 @@ void qemu_mutex_unlock_iothread(void);/* internal interfaces */ void qemu_fd_register (int fd); -void qemu_iohandler_fill (GArray *pollfds); -void qemu_iohandler_poll (GArray *pollfds,int rc);QEMUBH *qemu_bh_new (QEMUBHFunc *cb,void *opaque);void qemu_bh_schedule_idle (QEMUBH *bh);
iohandler.c +15 -96
126 lines not on this page · raw message
main-loop.c +3 -2
@@ -161,6 +161,9 @@ int qemu_init_main_loop(Error **errp) src =aio_get_g_source (qemu_aio_context);g_source_attach (src,NULL );g_source_unref (src); + src =iohandler_get_g_source (); +g_source_attach (src,NULL ); +g_source_unref (src);return 0 ; }
@@ -487,7 +490,6 @@ int main_loop_wait(int nonblocking)#ifdef CONFIG_SLIRP slirp_pollfds_fill (gpollfds, &timeout);#endif -qemu_iohandler_fill (gpollfds);if (timeout ==UINT32_MAX ) { timeout_ns =-1 ;
@@ -500,7 +502,6 @@ int main_loop_wait(int nonblocking) &main_loop_tlg)); ret =os_host_main_loop_wait (timeout_ns); -qemu_iohandler_poll (gpollfds, ret);#ifdef CONFIG_SLIRP slirp_pollfds_poll (gpollfds, (ret <0 ));#endif
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 08/43] i8257: rewrite DMA_schedule to avoid hooking into the CPU loop
In reply to Paolo BonziniThe i8257 DMA controller uses an idle bottom half, which by default does not cause the main loop to exit. Therefore, the DMA_schedule function is there to ensure that the CPU relinquishes the iothread mutex to the iothread.
However, this is not enough since the iothread will call aio_compute_timeout() and go to sleep again. In the iothread world, forcing execution of the idle bottom half is much simpler, and only requires a call to qemu_notify_event(). Do it, removing the need for the "cpu_request_exit" pseudo-irq. The next patch will remove it.
--- hw/block/fdc.c | 2 +- hw/dma/i8257.c | 18 ++++++++++++------ hw/sparc/sun4m.c | 2 +- hw/sparc64/sun4u.c | 2 +- include/hw/isa/isa.h | 2 +- 5 files changed, 16 insertions(+), 10 deletions(-)
hw/block/fdc.c +1 -1
@@ -1417,7 +1417,7 @@ static void fdctrl_start_transfer(FDCtrl *fdctrl, int direction)* recall us... */ DMA_hold_DREQ (fdctrl->dma_chann); -DMA_schedule (fdctrl->dma_chann); +DMA_schedule (); }else {/* Start transfer */ fdctrl_transfer_handler(fdctrl, fdctrl->dma_chann, 0,
hw/dma/i8257.c +12 -6
@@ -358,6 +358,7 @@ static void channel_run (int ncont, int ichan) }static QEMUBH *dma_bh; +static bool dma_bh_scheduled;static void DMA_run (void ) {
@@ -390,12 +391,15 @@ static void DMA_run (void) running =0 ; out: -if (rearm) +if (rearm) {qemu_bh_schedule_idle (dma_bh); + dma_bh_scheduled = true; + } }static void DMA_run_bh (void *unused) { + dma_bh_scheduled = false;DMA_run (); }
@@ -458,12 +462,14 @@ int DMA_write_memory (int nchan, void *buf, int pos, int len)return len; } -/* request the emulator to transfer a new DMA memory block ASAP */ -void DMA_schedule (int nchan) +/* request the emulator to transfer a new DMA memory block ASAP (even +* if the idle bottom half would not have exited the iothread yet). +*/ +void DMA_schedule (void ) { -struct dma_cont *d = &dma_controllers[nchan >3 ]; - -qemu_irq_pulse (*d->cpu_request_exit); +if (dma_bh_scheduled) { +qemu_notify_event (); + } }static void dma_reset (void *opaque)
hw/sparc/sun4m.c +1 -1
@@ -109,7 +109,7 @@ int DMA_write_memory (int nchan, void *buf, int pos, int size) }void DMA_hold_DREQ (int nchan) {}void DMA_release_DREQ (int nchan) {} -void DMA_schedule (int nchan) {} +void DMA_schedule (void ) {}void DMA_init (int high_page_enable,qemu_irq *cpu_request_exit) {
hw/sparc64/sun4u.c +1 -1
@@ -112,7 +112,7 @@ int DMA_write_memory (int nchan, void *buf, int pos, int size) }void DMA_hold_DREQ (int nchan) {}void DMA_release_DREQ (int nchan) {} -void DMA_schedule (int nchan) {} +void DMA_schedule (void ) {}void DMA_init (int high_page_enable,qemu_irq *cpu_request_exit) {
include/hw/isa/isa.h +1 -1
@@ -112,7 +112,7 @@ int DMA_read_memory (int nchan, void *buf, int pos, int size);int DMA_write_memory (int nchan,void *buf,int pos,int size);void DMA_hold_DREQ (int nchan);void DMA_release_DREQ (int nchan); -void DMA_schedule (int nchan); +void DMA_schedule (void );void DMA_init (int high_page_enable,qemu_irq *cpu_request_exit); void DMA_register_channel (int nchan, DMA_transfer_handler transfer_handler,
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 06/43] block/iscsi: validate block size returned from target
In reply to Paolo BonziniFrom: Peter Lieven <[email protected]>
It has been reported that at least tgtd returns a block size of 0 for LUN 0. To avoid running into divide by zero later on and protect against other problematic block sizes validate the block size right at connection time.
Message-Id: <[email protected]>
--- block/iscsi.c | 4 ++++ 1 file changed, 4 insertions(+)
block/iscsi.c +4 -0
@@ -1214,6 +1214,10 @@ static void iscsi_readcapacity_sync(IscsiLun *iscsilun, Error **errp)if (task ==NULL || task->status !=SCSI_STATUS_GOOD ) {error_setg (errp,"iSCSI: failed to send readcapacity10 command." ); + }else if (!iscsilun->block_size || + iscsilun->block_size %BDRV_SECTOR_SIZE ) { +error_setg (errp,"iSCSI: the target returned an invalid " +"block size of %d." , iscsilun->block_size); }if (task) {scsi_free_scsi_task (task);
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 10/43] tcg: introduce tcg_current_cpu
In reply to Paolo BonziniThis is already useful on Windows in order to remove tls.h, because accesses to current_cpu are done from a different thread on that platform. It will be used on POSIX platforms as soon TCG stops using signals to interrupt the execution of translated code.
--- cpu-exec.c | 14 +++++--------- cpus.c | 5 +++-- include/exec/exec-all.h | 1 + 3 files changed, 9 insertions(+), 11 deletions(-)
cpu-exec.c +5 -9
@@ -342,6 +342,7 @@ static void cpu_handle_debug_exception(CPUState *cpu)/* main execution loop */ volatile sig_atomic_t exit_request; +CPUState *tcg_current_cpu;int cpu_exec (CPUState *cpu) {
@@ -368,15 +369,7 @@ int cpu_exec(CPUState *cpu) } current_cpu = cpu; - -/* As long as current_cpu is null, up to the assignment just above, -* requests by other threads to exit the execution loop are expected to -* be issued using the exit_request global. We must make sure that our -* evaluation of the global value is performed past the current_cpu -* value transition point, which requires a memory barrier as well as -* an instruction scheduling constraint on modern architectures. */ -smp_mb (); - +atomic_mb_set (&tcg_current_cpu, cpu);rcu_read_lock ();if (unlikely (exit_request)) {
@@ -579,5 +572,8 @@ int cpu_exec(CPUState *cpu)/* fail safe : never use current_cpu outside cpu_exec() */ current_cpu =NULL ; + +/* Does not need atomic_mb_set because a spurious wakeup is okay. */ +atomic_set (&tcg_current_cpu,NULL );return ret; }
cpus.c +3 -2
@@ -663,8 +663,9 @@ static void cpu_handle_guest_debug(CPUState *cpu)static void cpu_signal (int sig) { -if (current_cpu) { -cpu_exit (current_cpu); +CPUState *cpu =atomic_mb_read (&tcg_current_cpu); +if (cpu) { +cpu_exit (cpu); } exit_request =1 ; }
include/exec/exec-all.h +1 -0
@@ -387,6 +387,7 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong addr);extern int singlestep;/* cpu-exec.c */ +extern CPUState *tcg_current_cpu;extern volatile sig_atomic_t exit_request;#if !defined(CONFIG_USER_ONLY )
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 07/43] Added generic panic handler qemu_system_guest_panicked()
In reply to Paolo BonziniFrom: Andrey Smetanin <[email protected]>
There are pieces of guest panic handling code that can be shared in one generic function. These code replaced by call qemu_system_guest_panicked().
Message-Id: <[email protected]>
--- hw/misc/pvpanic.c | 3 +-- include/sysemu/sysemu.h | 1 + target-s390x/kvm.c | 11 ++--------- vl.c | 6 ++++++ 4 files changed, 10 insertions(+), 11 deletions(-)
hw/misc/pvpanic.c +1 -2
@@ -41,8 +41,7 @@ static void handle_event(int event) }if (event &PVPANIC_PANICKED ) { -qapi_event_send_guest_panicked (GUEST_PANIC_ACTION_PAUSE , &error_abort); -vm_stop (RUN_STATE_GUEST_PANICKED ); +qemu_system_guest_panicked ();return ; } }
include/sysemu/sysemu.h +1 -0
@@ -69,6 +69,7 @@ int qemu_reset_requested_get(void);void qemu_system_killed (int signal,pid_t pid);void qemu_devices_reset (void );void qemu_system_reset (bool report); +void qemu_system_guest_panicked (void );void qemu_add_exit_notifier (Notifier *notify);void qemu_remove_exit_notifier (Notifier *notify);
target-s390x/kvm.c +2 -9
@@ -1796,13 +1796,6 @@ static bool is_special_wait_psw(CPUState *cs)return cs->kvm_run->psw_addr ==0xfffUL ; } -static void guest_panicked (void ) -{ -qapi_event_send_guest_panicked (GUEST_PANIC_ACTION_PAUSE , - &error_abort); -vm_stop (RUN_STATE_GUEST_PANICKED ); -} -static void unmanageable_intercept (S390CPU *cpu,const char *str,int pswoffset) {CPUState *cs =CPU (cpu);
@@ -1811,7 +1804,7 @@ static void unmanageable_intercept(S390CPU *cpu, const char *str, int pswoffset) str, cs->cpu_index,ldq_phys (cs->as, cpu->env.psa + pswoffset), ldq_phys(cs->as, cpu->env.psa + pswoffset + 8));s390_cpu_halt (cpu); -guest_panicked (); +qemu_system_guest_panicked (); }static int handle_intercept (S390CPU *cpu)
@@ -1844,7 +1837,7 @@ static int handle_intercept(S390CPU *cpu)if (is_special_wait_psw (cs)) {qemu_system_shutdown_request (); }else { -guest_panicked (); +qemu_system_guest_panicked (); } } r =EXCP_HALTED ;
vl.c +6 -0
@@ -1740,6 +1740,12 @@ void qemu_system_reset(bool report)cpu_synchronize_all_post_reset (); } +void qemu_system_guest_panicked (void ) +{ +qapi_event_send_guest_panicked (GUEST_PANIC_ACTION_PAUSE , &error_abort); +vm_stop (RUN_STATE_GUEST_PANICKED ); +} +void qemu_system_reset_request (void ) {if (no_reboot) {
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 09/43] i8257: remove cpu_request_exit irq
In reply to Paolo BonziniThis is unused. cpu_exit now is almost exclusively an internal function to the CPU execution loop. In a few patches, we'll change the remaining occurrences to qemu_cpu_kick, making it truly internal.
--- hw/dma/i82374.c | 5 +---- hw/dma/i8257.c | 13 ++++--------- hw/i386/pc.c | 13 +------------ hw/isa/i82378.c | 3 +-- hw/mips/mips_fulong2e.c | 13 +------------ hw/mips/mips_jazz.c | 13 +------------ hw/mips/mips_malta.c | 13 +------------ hw/ppc/prep.c | 11 ----------- hw/sparc/sun4m.c | 2 +- hw/sparc64/sun4u.c | 2 +- include/hw/isa/isa.h | 2 +- 11 files changed, 13 insertions(+), 77 deletions(-)
hw/dma/i82374.c +1 -4
@@ -38,7 +38,6 @@ do { fprintf(stderr, "i82374 ERROR: " fmt , ## __VA_ARGS__); } while (0)typedef struct I82374State {uint8_t commands[8 ]; -qemu_irq out;PortioList port_list; }I82374State ;
@@ -101,7 +100,7 @@ static uint32_t i82374_read_descriptor(void *opaque, uint32_t nport)static void i82374_realize (I82374State *s,Error **errp) { -DMA_init (1 , &s->out); +DMA_init (1 );memset (s->commands,0 ,sizeof (s->commands)); }
@@ -145,8 +144,6 @@ static void i82374_isa_realize(DeviceState *dev, Error **errp) isa->iobase);i82374_realize (s, errp); - -qdev_init_gpio_out (dev, &s->out,1 ); }static Property i82374_properties[] = {
hw/dma/i8257.c +4 -9
@@ -59,7 +59,6 @@ static struct dma_cont {uint8_t flip_flop;int dshift;struct dma_regs regs[4 ]; -qemu_irq *cpu_request_exit;MemoryRegion channel_io;MemoryRegion cont_io; } dma_controllers[2 ];
@@ -521,13 +520,11 @@ static const MemoryRegionOps cont_io_ops = {/* dshift = 0: 8 bit DMA, 1 = 16 bit DMA */ static void dma_init2 (struct dma_cont *d,int base,int dshift, -int page_base,int pageh_base, -qemu_irq *cpu_request_exit) +int page_base,int pageh_base) {int i; d->dshift = dshift; - d->cpu_request_exit = cpu_request_exit;memory_region_init_io (&d->channel_io,NULL , &channel_io_ops, d,"dma-chan" ,8 << d->dshift);
@@ -591,12 +588,10 @@ static const VMStateDescription vmstate_dma = { } }; -void DMA_init (int high_page_enable,qemu_irq *cpu_request_exit) +void DMA_init (int high_page_enable) { -dma_init2 (&dma_controllers[0 ],0x00 ,0 ,0x80 , - high_page_enable ?0x480 :-1 , cpu_request_exit); -dma_init2 (&dma_controllers[1 ],0xc0 ,1 ,0x88 , - high_page_enable ?0x488 :-1 , cpu_request_exit); +dma_init2 (&dma_controllers[0 ],0x00 ,0 ,0x80 , high_page_enable ?0x480 :-1 ); +dma_init2 (&dma_controllers[1 ],0xc0 ,1 ,0x88 , high_page_enable ?0x488 :-1 );vmstate_register (NULL ,0 , &vmstate_dma, &dma_controllers[0 ]);vmstate_register (NULL ,1 , &vmstate_dma, &dma_controllers[1 ]);
hw/i386/pc.c +1 -12
@@ -1446,15 +1446,6 @@ DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus)return dev; } -static void cpu_request_exit (void *opaque,int irq,int level) -{ -CPUState *cpu = current_cpu; - -if (cpu && level) { -cpu_exit (cpu); - } -} -static const MemoryRegionOps ioport80_io_ops = { .write = ioport80_write, .read = ioport80_read,
@@ -1489,7 +1480,6 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,qemu_irq rtc_irq =NULL ;qemu_irq *a20_line;ISADevice *i8042, *port92, *vmmouse, *pit =NULL ; -qemu_irq *cpu_exit_irq;MemoryRegion *ioport80_io =g_new (MemoryRegion,1 );MemoryRegion *ioportF0_io =g_new (MemoryRegion,1 );
@@ -1566,8 +1556,7 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi, port92 =isa_create_simple (isa_bus,"port92" );port92_init (port92, &a20_line[1 ]); - cpu_exit_irq =qemu_allocate_irqs (cpu_request_exit,NULL ,1 ); -DMA_init (0 , cpu_exit_irq); +DMA_init (0 );for (i =0 ; i <MAX_FD ; i++) { fd[i] =drive_get (IF_FLOPPY ,0 , i);
hw/isa/i82378.c +1 -2
@@ -100,7 +100,6 @@ static void i82378_realize(PCIDevice *pci, Error **errp)/* 2 82C37 (dma) */ isa =isa_create_simple (isabus,"i82374" ); -qdev_connect_gpio_out (DEVICE (isa),0 , s->out[1 ]);/* timer */ isa_create_simple (isabus,"mc146818rtc" );
@@ -111,7 +110,7 @@ static void i82378_init(Object *obj)DeviceState *dev =DEVICE (obj);I82378State *s =I82378 (obj); -qdev_init_gpio_out (dev, s->out,2 ); +qdev_init_gpio_out (dev, s->out,1 );qdev_init_gpio_in (dev, i82378_request_pic_irq,16 ); }
hw/mips/mips_fulong2e.c +1 -12
@@ -251,15 +251,6 @@ static void network_init (PCIBus *pci_bus) } } -static void cpu_request_exit (void *opaque,int irq,int level) -{ -CPUState *cpu = current_cpu; - -if (cpu && level) { -cpu_exit (cpu); - } -} -static void mips_fulong2e_init (MachineState *machine) {ram_addr_t ram_size = machine->ram_size;
@@ -274,7 +265,6 @@ static void mips_fulong2e_init(MachineState *machine)long bios_size;int64_t kernel_entry;qemu_irq *i8259; -qemu_irq *cpu_exit_irq;PCIBus *pci_bus;ISABus *isa_bus;I2CBus *smbus;
@@ -375,8 +365,7 @@ static void mips_fulong2e_init(MachineState *machine)/* init other devices */ pit =pit_init (isa_bus,0x40 ,0 ,NULL ); - cpu_exit_irq =qemu_allocate_irqs (cpu_request_exit,NULL ,1 ); -DMA_init (0 , cpu_exit_irq); +DMA_init (0 );/* Super I/O */ isa_create_simple (isa_bus,"i8042" );
hw/mips/mips_jazz.c +1 -12
@@ -104,15 +104,6 @@ static const MemoryRegionOps dma_dummy_ops = {#define MAGNUM_BIOS_SIZE_MAX 0x7e000#define MAGNUM_BIOS_SIZE (BIOS_SIZE < MAGNUM_BIOS_SIZE_MAX ? BIOS_SIZE : MAGNUM_BIOS_SIZE_MAX) -static void cpu_request_exit (void *opaque,int irq,int level) -{ -CPUState *cpu = current_cpu; - -if (cpu && level) { -cpu_exit (cpu); - } -} -static CPUUnassignedAccess real_do_unassigned_access; static void mips_jazz_do_unassigned_access(CPUState *cpu, hwaddr addr, bool is_write, bool is_exec,
@@ -150,7 +141,6 @@ static void mips_jazz_init(MachineState *machine,ISADevice *pit;DriveInfo *fds[MAX_FD ];qemu_irq esp_reset, dma_enable; -qemu_irq *cpu_exit_irq;MemoryRegion *ram =g_new (MemoryRegion,1 );MemoryRegion *bios =g_new (MemoryRegion,1 );MemoryRegion *bios2 =g_new (MemoryRegion,1 );
@@ -234,8 +224,7 @@ static void mips_jazz_init(MachineState *machine,/* ISA devices */ i8259 =i8259_init (isa_bus, env->irq[4 ]);isa_bus_irqs (isa_bus, i8259); - cpu_exit_irq =qemu_allocate_irqs (cpu_request_exit,NULL ,1 ); -DMA_init (0 , cpu_exit_irq); +DMA_init (0 ); pit =pit_init (isa_bus,0x40 ,0 ,NULL );pcspk_init (isa_bus, pit);
hw/mips/mips_malta.c +1 -12
@@ -905,15 +905,6 @@ static void main_cpu_reset(void *opaque) } } -static void cpu_request_exit (void *opaque,int irq,int level) -{ -CPUState *cpu = current_cpu; - -if (cpu && level) { -cpu_exit (cpu); - } -} -static void mips_malta_init (MachineState *machine) {
@@ -939,7 +930,6 @@ void mips_malta_init(MachineState *machine)MIPSCPU *cpu;CPUMIPSState *env;qemu_irq *isa_irq; -qemu_irq *cpu_exit_irq;int piix4_devfn;I2CBus *smbus;int i;
@@ -1175,8 +1165,7 @@ void mips_malta_init(MachineState *machine)smbus_eeprom_init (smbus,8 , smbus_eeprom_buf, smbus_eeprom_size);g_free (smbus_eeprom_buf); pit =pit_init (isa_bus,0x40 ,0 ,NULL ); - cpu_exit_irq =qemu_allocate_irqs (cpu_request_exit,NULL ,1 ); -DMA_init (0 , cpu_exit_irq); +DMA_init (0 );/* Super I/O */ isa_create_simple (isa_bus,"i8042" );
hw/ppc/prep.c +0 -11
@@ -336,15 +336,6 @@ static uint32_t PREP_io_800_readb (void *opaque, uint32_t addr)#define NVRAM_SIZE 0x2000 -static void cpu_request_exit (void *opaque,int irq,int level) -{ -CPUState *cpu = current_cpu; - -if (cpu && level) { -cpu_exit (cpu); - } -} -static void ppc_prep_reset (void *opaque) {PowerPCCPU *cpu = opaque;
@@ -626,8 +617,6 @@ static void ppc_prep_init(MachineState *machine) cpu =POWERPC_CPU (first_cpu);qdev_connect_gpio_out (&pci->qdev,0 , cpu->env.irq_inputs[PPC6xx_INPUT_INT]); -qdev_connect_gpio_out (&pci->qdev,1 , -qemu_allocate_irq (cpu_request_exit,NULL ,0 ));sysbus_connect_irq (&pcihost->busdev,0 ,qdev_get_gpio_in (&pci->qdev,9 ));sysbus_connect_irq (&pcihost->busdev,1 ,qdev_get_gpio_in (&pci->qdev,11 ));sysbus_connect_irq (&pcihost->busdev,2 ,qdev_get_gpio_in (&pci->qdev,9 ));
hw/sparc/sun4m.c +1 -1
@@ -111,7 +111,7 @@ void DMA_hold_DREQ (int nchan) {}void DMA_release_DREQ (int nchan) {}void DMA_schedule (void ) {} -void DMA_init (int high_page_enable,qemu_irq *cpu_request_exit) +void DMA_init (int high_page_enable) { }
hw/sparc64/sun4u.c +1 -1
@@ -114,7 +114,7 @@ void DMA_hold_DREQ (int nchan) {}void DMA_release_DREQ (int nchan) {}void DMA_schedule (void ) {} -void DMA_init (int high_page_enable,qemu_irq *cpu_request_exit) +void DMA_init (int high_page_enable) { }
include/hw/isa/isa.h +1 -1
@@ -113,7 +113,7 @@ int DMA_write_memory (int nchan, void *buf, int pos, int size);void DMA_hold_DREQ (int nchan);void DMA_release_DREQ (int nchan);void DMA_schedule (void ); -void DMA_init (int high_page_enable,qemu_irq *cpu_request_exit); +void DMA_init (int high_page_enable);void DMA_register_channel (int nchan,DMA_transfer_handler transfer_handler,void *opaque);
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 14/43] tcg: synchronize exit_request and tcg_current_cpu accesses
In reply to Paolo BonziniSynchronize the remaining pair of accesses in cpu_signal. These should be necessary on Windows as well, at least in theory. Probably SuspendProcess and ResumeProcess introduce some implicit memory barrier.
--- cpu-exec.c | 2 +- cpus.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-)
cpu-exec.c +1 -1
@@ -372,7 +372,7 @@ int cpu_exec(CPUState *cpu)atomic_mb_set (&tcg_current_cpu, cpu);rcu_read_lock (); -if (unlikely (exit_request)) { +if (unlikely (atomic_mb_read (&exit_request))) { cpu->exit_request =1 ; }
cpus.c +10 -4
@@ -663,11 +663,15 @@ static void cpu_handle_guest_debug(CPUState *cpu)static void cpu_signal (int sig) { -CPUState *cpu =atomic_mb_read (&tcg_current_cpu); +CPUState *cpu; +/* Ensure whatever caused the exit has reached the CPU threads before +* writing exit_request. +*/ +atomic_mb_set (&exit_request,1 ); + cpu =atomic_mb_read (&tcg_current_cpu);if (cpu) {cpu_exit (cpu); } - exit_request =1 ; }#ifdef CONFIG_LINUX
@@ -1063,7 +1067,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) }/* process any pending work */ - exit_request =1 ; +atomic_mb_set (&exit_request,1 );while (1 ) {tcg_exec_all ();
@@ -1441,7 +1445,9 @@ static void tcg_exec_all(void)break ; } } - exit_request =0 ; + +/* Pairs with smp_wmb in qemu_cpu_kick. */ +atomic_mb_set (&exit_request,0 ); }void list_cpus (FILE *f,fprintf_function cpu_fprintf,const char *optarg)
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 15/43] use qemu_cpu_kick instead of cpu_exit or qemu_cpu_kick_thread
In reply to Paolo BonziniUse the same API to trigger interruption of a CPU, no matter if under TCG or KVM. There is no difference: these calls come from the CPU thread, so the qemu_cpu_kick calls will send a signal to the running thread and it will be processed synchronously, just like a call to cpu_exit. The only difference is in the overhead, but neither call to cpu_exit (now qemu_cpu_kick) is in a hot path.
--- cpus.c | 17 ++++++++--------- gdbstub.c | 2 +- hw/ppc/spapr_rtas.c | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-)
cpus.c +8 -9
@@ -1090,6 +1090,12 @@ static void qemu_cpu_kick_thread(CPUState *cpu)#ifndef _WIN32int err; +if (!tcg_enabled ()) { +if (cpu->thread_kicked) { +return ; + } + cpu->thread_kicked = true; + } err =pthread_kill (cpu->thread->thread,SIG_IPI );if (err) {fprintf (stderr,"qemu:%s: %s" , __func__,strerror (err));
@@ -1127,21 +1133,14 @@ static void qemu_cpu_kick_thread(CPUState *cpu)void qemu_cpu_kick (CPUState *cpu) {qemu_cond_broadcast (cpu->halt_cond); -if (!tcg_enabled () && !cpu->thread_kicked) { -qemu_cpu_kick_thread (cpu); - cpu->thread_kicked = true; - } +qemu_cpu_kick_thread (cpu); }void qemu_cpu_kick_self (void ) {#ifndef _WIN32assert (current_cpu); - -if (!current_cpu->thread_kicked) { -qemu_cpu_kick_thread (current_cpu); - current_cpu->thread_kicked = true; - } +qemu_cpu_kick_thread (current_cpu);#else abort ();#endif
gdbstub.c +1 -1
@@ -1362,7 +1362,7 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...)is still in the running state, which can cause packets to be dropped and state transition 'T' packets to be sent while the syscall is still being processed. */ -cpu_exit (s->c_cpu); +qemu_cpu_kick (s->c_cpu);#endif }
hw/ppc/spapr_rtas.c +1 -1
@@ -214,7 +214,7 @@ static void rtas_stop_self(PowerPCCPU *cpu, sPAPRMachineState *spapr,CPUPPCState *env = &cpu->env; cs->halted =1 ; -cpu_exit (cs); +qemu_cpu_kick (cs);/* * While stopping a CPU, the guest calls H_CPPR which * effectively disables interrupts on XICS level.
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 11/43] remove qemu/tls.h
In reply to Paolo BonziniTLS is now required on all platforms, so DECLARE_TLS/DEFINE_TLS is not needed anymore. Removing it does not break Windows because of the previous patch.
--- exec.c | 2 +- include/qemu/tls.h | 52 ---------------------------------------------------- include/qom/cpu.h | 4 +--- 3 files changed, 2 insertions(+), 56 deletions(-) delete mode 100644 include/qemu/tls.h
exec.c +1 -1
@@ -90,7 +90,7 @@ static MemoryRegion io_mem_unassigned;struct CPUTailQ cpus =QTAILQ_HEAD_INITIALIZER (cpus);/* current CPU in the current thread. It is only valid inside cpu_exec() */ -DEFINE_TLS(CPUState *, current_cpu); +__threadCPUState *current_cpu;/* 0 = Do not count executed instructions. 1 = Precise instruction counting. 2 = Adaptive rate instruction counting. */
include/qemu/tls.h deleted +0 -52
52 lines not on this page · raw message
include/qom/cpu.h +1 -3
@@ -28,7 +28,6 @@#include "exec/memattrs.h" #include "qemu/queue.h" #include "qemu/thread.h" -#include "qemu/tls.h" #include "qemu/typedefs.h" typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size,
@@ -333,8 +332,7 @@ extern struct CPUTailQ cpus; QTAILQ_FOREACH_REVERSE(cpu, &cpus, CPUTailQ, node)#define first_cpu QTAILQ_FIRST(&cpus) -DECLARE_TLS(CPUState *, current_cpu); -#define current_cpu tls_var(current_cpu) +extern __threadCPUState *current_cpu;/** * cpu_paging_enabled:
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 13/43] tcg: synchronize cpu->exit_request and cpu->tcg_exit_req accesses
In reply to Paolo Bonzini--- cpu-exec.c | 6 +++++- qom/cpu.c | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-)
cpu-exec.c +5 -1
@@ -507,8 +507,12 @@ int cpu_exec(CPUState *cpu)* loop. Whatever requested the exit will also * have set something else (eg exit_request or * interrupt_request) which we will handle -* next time around the loop. +* next time around the loop. But we need to +* ensure the tcg_exit_req read in generated code +* comes before the next read of cpu->exit_request +* or cpu->interrupt_request. */ +smp_rmb (); next_tb =0 ;break ;case TB_EXIT_ICOUNT_EXPIRED :
qom/cpu.c +2 -0
@@ -114,6 +114,8 @@ void cpu_reset_interrupt(CPUState *cpu, int mask)void cpu_exit (CPUState *cpu) { cpu->exit_request =1 ; +/* Ensure cpu_exec will see the exit request after TCG has exited. */ +smp_wmb (); cpu->tcg_exit_req =1 ; }
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 16/43] tcg: signal-free qemu_cpu_kick
In reply to Paolo BonziniSignals are slow and do not exist on Win32. The previous patches have done most of the legwork to introduce memory barriers (some of them were even there already for the sake of Windows!) and we can now set the flags directly in the iothread.
qemu_cpu_kick_thread is not used anymore on TCG, since the TCG thread is never outside usermode while the CPU is running (not halted). Instead run the content of the signal handler (now in qemu_cpu_kick_no_halt) directly. qemu_cpu_kick_no_halt is also used in qemu_mutex_lock_iothread to avoid the overhead of qemu_cond_broadcast.
--- cpu-exec.c | 2 +- cpus.c | 89 ++++++++++++------------------------------------- include/exec/exec-all.h | 4 +-- include/qom/cpu.h | 4 +-- 4 files changed, 27 insertions(+), 72 deletions(-)
cpu-exec.c +1 -1
@@ -341,7 +341,7 @@ static void cpu_handle_debug_exception(CPUState *cpu)/* main execution loop */ -volatile sig_atomic_t exit_request; +bool exit_request;CPUState *tcg_current_cpu;int cpu_exec (CPUState *cpu)
cpus.c +22 -67
144 lines not on this page · raw message
include/exec/exec-all.h +2 -2
@@ -386,9 +386,9 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong addr);/* vl.c */ extern int singlestep; -/* cpu-exec.c */ +/* cpu-exec.c, accessed with atomic_mb_read/atomic_mb_set */ extern CPUState *tcg_current_cpu; -extern volatile sig_atomic_t exit_request; +extern bool exit_request;#if !defined(CONFIG_USER_ONLY )void migration_bitmap_extend (ram_addr_t old,ram_addr_t new);
include/qom/cpu.h +2 -2
@@ -268,7 +268,7 @@ struct CPUState {bool created;bool stop;bool stopped; -volatile sig_atomic_t exit_request; +bool exit_request;uint32_t interrupt_request;int singlestep_enabled;int64_t icount_extra;
@@ -319,7 +319,7 @@ struct CPUState {offset from AREG0. Leave this field at the end so as to make the (absolute value) offset as small as possible. This reduces code size, especially for hosts without large memory offsets. */ -volatile sig_atomic_t tcg_exit_req; +uint32_t tcg_exit_req; };QTAILQ_HEAD (CPUTailQ, CPUState);
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 12/43] tcg: assign cpu->current_tb in a simpler place
In reply to Paolo BonziniTCG has not been reading cpu->current_tb from signal handlers for years. The code that synchronized cpu_exec with the signal handler is not needed anymore.
--- cpu-exec.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
cpu-exec.c +2 -8
@@ -493,18 +493,13 @@ int cpu_exec(CPUState *cpu) } have_tb_lock = false;spin_unlock (&tcg_ctx.tb_ctx.tb_lock); - -/* cpu_interrupt might be called while translating the -TB, but before it is linked into a potentially -infinite loop and becomes env->current_tb. Avoid -starting execution if there is a pending interrupt. */ - cpu->current_tb = tb; -barrier ();if (likely (!cpu->exit_request)) {trace_exec_tb (tb, tb->pc); tc_ptr = tb->tc_ptr;/* execute the generated code */ + cpu->current_tb = tb; next_tb =cpu_tb_exec (cpu, tc_ptr); + cpu->current_tb =NULL ;switch (next_tb &TB_EXIT_MASK ) {case TB_EXIT_REQUESTED :/* Something asked us to stop executing
@@ -543,7 +538,6 @@ int cpu_exec(CPUState *cpu)break ; } } - cpu->current_tb =NULL ;/* Try to align the host and virtual clocks if the guest is in advance */ align_clocks (&sc, cpu);
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 18/43] Makefile.target: include top level build dir in vpath
In reply to Paolo BonziniFrom: Michael Marineau <[email protected]>
Using ccache with CCACHE_BASEDIR set to $(SRC_PATH) or a parent will rewrite all absolute paths to relative paths. This interacts poorly with QEMU's two-level build directory scheme. For example, lets say BUILD_DIR=$(SRC_PATH)/build so build/blockdev.d will contain:
blockdev.o: ../blockdev.c ../include/sysemu/block-backend.h \
Now the target build under build/x86_64-softmmu or similar will depend on ../blockdev.o which in turn will get make to source ../blockdev.d to check its dependencies. Since make always considers paths relative to the current working directory rather than the makefile the path appeared in the relative path to ../blockdev.c is useless.
This change simply adds the top level build directory to vpath so paths relative to the source directory, top build directory, and target build directory all work just fine.
Message-Id: <[email protected]>
--- Makefile.target | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile.target +1 -1
@@ -7,7 +7,7 @@ include config-target.mak include config-devices.mak include $(SRC_PATH)/rules.mak -$(call set-vpath, $(SRC_PATH)) +$(call set-vpath, $(SRC_PATH):$(BUILD_DIR)) ifdef CONFIG_LINUX QEMU_CFLAGS += -I../linux-headers endif
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 17/43] Move RAMBlock and ram_list to ram_addr.h
In reply to Paolo BonziniFrom: "Dr. David Alan Gilbert" <[email protected]>
Message-Id: <[email protected]>
--- include/exec/cpu-all.h | 41 ----------------------------------------- include/exec/ram_addr.h | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 41 deletions(-)
include/exec/cpu-all.h +0 -41
@@ -266,44 +266,6 @@ CPUArchState *cpu_copy(CPUArchState *env);#if !defined(CONFIG_USER_ONLY ) -/* memory API */ - -typedef struct RAMBlock RAMBlock ; - -struct RAMBlock { -struct rcu_head rcu; -struct MemoryRegion *mr; -uint8_t *host; -ram_addr_t offset; -ram_addr_t used_length; -ram_addr_t max_length; -void (*resized)(const char *,uint64_t length,void *host); -uint32_t flags; -/* Protected by iothread lock. */ -char idstr[256 ]; -/* RCU-enabled, writes protected by the ramlist lock */ -QLIST_ENTRY (RAMBlock) next; -int fd; -}; - -static inline void *ramblock_ptr (RAMBlock *block,ram_addr_t offset) -{ -assert (offset < block->used_length); -assert (block->host); -return (char *)block->host + offset; -} - -typedef struct RAMList { -QemuMutex mutex; -/* Protected by the iothread lock. */ -unsigned long *dirty_memory[DIRTY_MEMORY_NUM ]; -RAMBlock *mru_block; -/* RCU-enabled, writes protected by the ramlist lock. */ - QLIST_HEAD(, RAMBlock) blocks; -uint32_t version; -}RAMList ; -extern RAMList ram_list; -/* Flags stored in the low bits of the TLB virtual address. These are defined so that fast path ram access is all zeros. */ /* Zero if TLB entry is valid. */
@@ -316,9 +278,6 @@ extern RAMList ram_list;void dump_exec_info (FILE *f,fprintf_function cpu_fprintf);void dump_opcount_info (FILE *f,fprintf_function cpu_fprintf); -ram_addr_t last_ram_offset (void ); -void qemu_mutex_lock_ramlist (void ); -void qemu_mutex_unlock_ramlist (void );#endif /* !CONFIG_USER_ONLY */ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
include/exec/ram_addr.h +40 -0
@@ -22,6 +22,46 @@#ifndef CONFIG_USER_ONLY #include "hw/xen/xen.h" +typedef struct RAMBlock RAMBlock ; + +struct RAMBlock { +struct rcu_head rcu; +struct MemoryRegion *mr; +uint8_t *host; +ram_addr_t offset; +ram_addr_t used_length; +ram_addr_t max_length; +void (*resized)(const char *,uint64_t length,void *host); +uint32_t flags; +/* Protected by iothread lock. */ +char idstr[256 ]; +/* RCU-enabled, writes protected by the ramlist lock */ +QLIST_ENTRY (RAMBlock) next; +int fd; +}; + +static inline void *ramblock_ptr (RAMBlock *block,ram_addr_t offset) +{ +assert (offset < block->used_length); +assert (block->host); +return (char *)block->host + offset; +} + +typedef struct RAMList { +QemuMutex mutex; +/* Protected by the iothread lock. */ +unsigned long *dirty_memory[DIRTY_MEMORY_NUM ]; +RAMBlock *mru_block; +/* RCU-enabled, writes protected by the ramlist lock. */ + QLIST_HEAD(, RAMBlock) blocks; +uint32_t version; +}RAMList ; +extern RAMList ram_list; + +ram_addr_t last_ram_offset (void ); +void qemu_mutex_lock_ramlist (void ); +void qemu_mutex_unlock_ramlist (void ); +ram_addr_t qemu_ram_alloc_from_file (ram_addr_t size,MemoryRegion *mr,bool share,const char *mem_path,Error **errp);
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 20/43] rcu: fix comment with s/rcu_gp_lock/rcu_registry_lock/
In reply to Paolo BonziniFrom: "Emilio G. Cota" <[email protected]>
Message-Id: <[email protected]>
--- include/qemu/rcu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/qemu/rcu.h +1 -1
@@ -71,7 +71,7 @@ struct rcu_reader_data {/* Data used by reader only */ unsigned depth; -/* Data used for registry, protected by rcu_gp_lock */ +/* Data used for registry, protected by rcu_registry_lock */ QLIST_ENTRY (rcu_reader_data) node; };
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 22/43] translate-all: remove obsolete comment about l1_map
In reply to Paolo BonziniFrom: "Emilio G. Cota" <[email protected]>
l1_map is based on physical addresses in full-system mode, as pointed out in an earlier comment. Said comment also mentions that virtual addresses are only used in l1_map in user-only mode.
Message-Id: <[email protected]>
--- translate-all.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
translate-all.c +1 -2
@@ -122,8 +122,7 @@ uintptr_t qemu_real_host_page_mask;uintptr_t qemu_host_page_size;uintptr_t qemu_host_page_mask; -/* This is a multi-level map on the virtual address space. -The bottom level has pointers to PageDesc. */ +/* The bottom level has pointers to PageDesc */ static void *l1_map[V_L1_SIZE ];/* code generation context */
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 21/43] linux-user: call rcu_(un)register_thread on pthread_(exit|create)
In reply to Paolo BonziniFrom: "Emilio G. Cota" <[email protected]>
Message-Id: <[email protected]>
--- linux-user/syscall.c | 2 ++ 1 file changed, 2 insertions(+)
linux-user/syscall.c +2 -0
@@ -4513,6 +4513,7 @@ static void *clone_func(void *arg)CPUState *cpu;TaskState *ts; +rcu_register_thread (); env = info->env; cpu =ENV_GET_CPU (env); thread_cpu = cpu;
@@ -5614,6 +5615,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, thread_cpu =NULL ;object_unref (OBJECT (cpu));g_free (ts); +rcu_unregister_thread ();pthread_exit (NULL ); }#ifdef TARGET_GPROF
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 19/43] rcu: init rcu_registry_lock after fork
In reply to Paolo BonziniFrom: "Emilio G. Cota" <[email protected]>
We were unlocking this lock after fork, which is wrong since only the thread that holds a mutex is allowed to unlock it.
Message-Id: <[email protected]>
--- util/rcu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
util/rcu.c +6 -1
@@ -335,6 +335,11 @@ static void rcu_init_unlock(void)qemu_mutex_unlock (&rcu_registry_lock); qemu_mutex_unlock(&rcu_sync_lock); } + +static void rcu_init_child (void ) +{ +qemu_mutex_init (&rcu_registry_lock); +}#endif void rcu_after_fork (void )
@@ -346,7 +351,7 @@ void rcu_after_fork(void)static void __attribute__((__constructor__))rcu_init (void ) {#ifdef CONFIG_POSIX -pthread_atfork (rcu_init_lock, rcu_init_unlock, rcu_init_unlock); +pthread_atfork (rcu_init_lock, rcu_init_unlock, rcu_init_child);#endif rcu_init_complete (); }
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PULL 19/43] rcu: init rcu_registry_lock after fork
Quoted 4 lines · Paolo Bonzini
From: "Emilio G. Cota" <[email protected]>
We were unlocking this lock after fork, which is wrong since only the thread that holds a mutex is allowed to unlock it.
This breaks libvirt capability probing. I see qemu running:
/home/kraxel/projects/qemu/build-default/x86_64-softmmu/qemu-system-x86_64 -S -no-user-config -nodefaults -nographic -M none -qmp unix:/var/lib/libvirt/qemu/capabilities.monitor.sock,server,nowait -pidfile /var/lib/libvirt/qemu/capabilities.pidfile -daemonize
and libvirt is stuck until I kill qemu.
cheers,
Gerd
Re: [Qemu-devel] [PULL 19/43] rcu: init rcu_registry_lock after fork
Quoted 10 lines · Gerd Hoffmann
Quoted 4 lines · Paolo Bonzini
Quoted 4 lines
From: "Emilio G. Cota" <[email protected]>
We were unlocking this lock after fork, which is wrong since only the thread that holds a mutex is allowed to unlock it.
This breaks libvirt capability probing. I see qemu running:
/home/kraxel/projects/qemu/build-default/x86_64-softmmu/qemu-system-x86_64-S -no-user-config -nodefaults -nographic -M none -qmp unix:/var/lib/libvirt/qemu/capabilities.monitor.sock,server,nowait -pidfile/var/lib/libvirt/qemu/capabilities.pidfile-daemonizeand libvirt is stuck until I kill qemu.
Yes, Laszlo reported this already. The patch was included by mistake and I've already sent a revert.
Paolo
[Qemu-devel] [PULL 23/43] cutils: Add qemu_strtol() wrapper
In reply to Paolo BonziniFrom: "Carlos L. Torres" <[email protected]>
Add wrapper for strtol() function. Include unit tests.
Message-Id: <07199f1c0ff3892790c6322123aee1e92f580550.1437346779.git.carlos.torres@rackspace.com>
--- include/qemu-common.h | 2 + tests/test-cutils.c | 319 ++++++++++++++++++++++++++++++++++++++++++++++++++ util/cutils.c | 58 +++++++++ 3 files changed, 379 insertions(+)
include/qemu-common.h +2 -0
@@ -203,6 +203,8 @@ int qemu_fls(int i);int qemu_fdatasync (int fd);int fcntl_setfl (int fd,int flag);int qemu_parse_fd (const char *param); +int qemu_strtol (const char *nptr,const char **endptr,int base, +long *result);int parse_uint (const char *s,unsigned long long *value,char **endptr,int base);
tests/test-cutils.c +319 -0
330 lines not on this page · raw message
util/cutils.c +58 -0
64 lines not on this page · raw message
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 28/43] CODING_STYLE: update mixed declaration rules
In reply to Paolo BonziniMixed declarations do come in handy at the top of #ifdef blocks. Reluctantly allow this particular usage and suggest an alternative.
--- CODING_STYLE | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
CODING_STYLE +9 -4
@@ -87,10 +87,15 @@ Furthermore, it is the QEMU coding style. 5. Declarations -Mixed declarations (interleaving statements and declarations within blocks) -are not allowed; declarations should be at the beginning of blocks. In other -words, the code should not generate warnings if using GCC's --Wdeclaration-after-statement option. +Mixed declarations (interleaving statements and declarations within +blocks) are generally not allowed; declarations should be at the beginning +of blocks. + +Every now and then, an exception is made for declarations inside a +#ifdef or #ifndef block: if the code looks nicer, such declarations can +be placed at the top of the block even if there are statements above. +On the other hand, however, it's often best to move that #ifdef/#ifndef +block to a separate function altogether. 6. Conditional statements
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 24/43] cutils: Add qemu_strtoul() wrapper
In reply to Paolo BonziniFrom: "Carlos L. Torres" <[email protected]>
Add wrapper for strtoul() function. Include unit tests.
Message-Id: <9621b4ae8e35fded31c715c2ae2a98f904f07ad0.1437346779.git.carlos.torres@rackspace.com>
--- include/qemu-common.h | 2 + tests/test-cutils.c | 318 ++++++++++++++++++++++++++++++++++++++++++++++++++ util/cutils.c | 32 +++++ 3 files changed, 352 insertions(+)
include/qemu-common.h +2 -0
@@ -205,6 +205,8 @@ int fcntl_setfl(int fd, int flag);int qemu_parse_fd (const char *param);int qemu_strtol (const char *nptr,const char **endptr,int base,long *result); +int qemu_strtoul (const char *nptr,const char **endptr,int base, +unsigned long *result);int parse_uint (const char *s,unsigned long long *value,char **endptr,int base);
tests/test-cutils.c +318 -0
329 lines not on this page · raw message
util/cutils.c +32 -0
@@ -416,6 +416,38 @@ int qemu_strtol(const char *nptr, const char **endptr, int base, }return err; } + +/** +* Converts ASCII string to an unsigned long integer. +* +* If string contains a negative number, value will be converted to +* the unsigned representation of the signed value, unless the original +* (nonnegated) value would overflow, in this case, it will set @result +* to ULONG_MAX, and return ERANGE. +* +* The same behavior holds, for qemu_strtoull() but sets @result to +* ULLONG_MAX instead of ULONG_MAX. +* +* See qemu_strtol() documentation for more info. +*/ +int qemu_strtoul (const char *nptr,const char **endptr,int base, +unsigned long *result) +{ +char *p; +int err =0 ; +if (!nptr) { +if (endptr) { + *endptr = nptr; + } + err = -EINVAL ; + }else { + errno =0 ; + *result =strtoul (nptr, &p, base); + err =check_strtox_error (endptr, p, errno); + } +return err; +} +/** * parse_uint: *
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 26/43] cutils: Add qemu_strtoull() wrapper
In reply to Paolo BonziniFrom: "Carlos L. Torres" <[email protected]>
Add wrapper for strtoull() function. Include unit tests.
Message-Id: <e0f0f611c9a81f3c29f451d0b17d755dfab1e90a.1437346779.git.carlos.torres@rackspace.com>
--- include/qemu-common.h | 2 + tests/test-cutils.c | 323 ++++++++++++++++++++++++++++++++++++++++++++++++++ util/cutils.c | 23 ++++ 3 files changed, 348 insertions(+)
include/qemu-common.h +2 -0
@@ -209,6 +209,8 @@ int qemu_strtoul(const char *nptr, const char **endptr, int base, unsigned long *result);int qemu_strtoll (const char *nptr,const char **endptr,int base,int64_t *result); +int qemu_strtoull (const char *nptr,const char **endptr,int base, +uint64_t *result);int parse_uint (const char *s,unsigned long long *value,char **endptr,int base);
tests/test-cutils.c +323 -0
334 lines not on this page · raw message
util/cutils.c +23 -0
@@ -472,6 +472,29 @@ int qemu_strtoll(const char *nptr, const char **endptr, int base, }/** +* Converts ASCII string to an unsigned long long integer. +* +* See qemu_strtol() documentation for more info. +*/ +int qemu_strtoull (const char *nptr,const char **endptr,int base, +uint64_t *result) +{ +char *p; +int err =0 ; +if (!nptr) { +if (endptr) { + *endptr = nptr; + } + err = -EINVAL ; + }else { + errno =0 ; + *result =strtoull (nptr, &p, base); + err =check_strtox_error (endptr, p, errno); + } +return err; +} + +/** * parse_uint: * * @s: String to parse
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 27/43] qmp: Add example usage of strto*l() qemu wrapper
In reply to Paolo BonziniFrom: "Carlos L. Torres" <[email protected]>
Message-Id: <11ac63e95d88551f1c2c9b1216b15d3cb8ba4468.1437346779.git.carlos.torres@rackspace.com>
--- qmp.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
qmp.c +10 -4
@@ -49,14 +49,20 @@ VersionInfo *qmp_query_version(Error **errp) {VersionInfo *info =g_new0 (VersionInfo,1 );const char *version =QEMU_VERSION ; -char *tmp; +const char *tmp; +int err; info->qemu =g_new0 (VersionTriple,1 ); - info->qemu->major =strtol (version, &tmp,10 ); + err =qemu_strtoll (version, &tmp,10 , &info->qemu->major); +assert (err ==0 ); tmp++; - info->qemu->minor =strtol (tmp, &tmp,10 ); + + err =qemu_strtoll (tmp, &tmp,10 , &info->qemu->minor); +assert (err ==0 ); tmp++; - info->qemu->micro =strtol (tmp, &tmp,10 ); + + err =qemu_strtoll (tmp, &tmp,10 , &info->qemu->micro); +assert (err ==0 ); info->package =g_strdup (QEMU_PKGVERSION );return info;
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 25/43] cutils: Add qemu_strtoll() wrapper
In reply to Paolo BonziniFrom: "Carlos L. Torres" <[email protected]>
Add wrapper for strtoll() function. Include unit tests.
Message-Id: <7454a6bb9ec03b629e8beb4f109dd30dc2c9804c.1437346779.git.carlos.torres@rackspace.com>
--- include/qemu-common.h | 2 + tests/test-cutils.c | 320 ++++++++++++++++++++++++++++++++++++++++++++++++++ util/cutils.c | 23 ++++ 3 files changed, 345 insertions(+)
include/qemu-common.h +2 -0
@@ -207,6 +207,8 @@ int qemu_strtol(const char *nptr, const char **endptr, int base, long *result);int qemu_strtoul (const char *nptr,const char **endptr,int base,unsigned long *result); +int qemu_strtoll (const char *nptr,const char **endptr,int base, +int64_t *result);int parse_uint (const char *s,unsigned long long *value,char **endptr,int base);
tests/test-cutils.c +320 -0
331 lines not on this page · raw message
util/cutils.c +23 -0
@@ -449,6 +449,29 @@ int qemu_strtoul(const char *nptr, const char **endptr, int base, }/** +* Converts ASCII string to a long long integer. +* +* See qemu_strtol() documentation for more info. +*/ +int qemu_strtoll (const char *nptr,const char **endptr,int base, +int64_t *result) +{ +char *p; +int err =0 ; +if (!nptr) { +if (endptr) { + *endptr = nptr; + } + err = -EINVAL ; + }else { + errno =0 ; + *result =strtoll (nptr, &p, base); + err =check_strtox_error (endptr, p, errno); + } +return err; +} + +/** * parse_uint: * * @s: String to parse
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 29/43] checkpatch: adapt some tests to QEMU
In reply to Paolo BonziniMostly change severity levels, but some tests can also be adjusted to refer to QEMU APIs or data structures.
--- scripts/checkpatch.pl | 141 +++++++++++++++++++++----------------------------- 1 file changed, 60 insertions(+), 81 deletions(-)
scripts/checkpatch.pl +60 -81
@@ -152,33 +152,18 @@ our $Sparse = qr{ }x; # Notes to $Attribute: -# We need \b after 'init' otherwise 'initconst' will cause a false positive in a check our $Attribute = qr{ const| - __percpu| - __nocast| - __safe| - __bitwise__| - __packed__| - __packed2__| - __naked| - __maybe_unused| - __always_unused| - __noreturn| - __used| - __cold| - __noclone| - __deprecated| - __read_mostly| - __kprobes| - __(?:mem|cpu|dev|)(?:initdata|initconst|init\b)| - ____cacheline_aligned| - ____cacheline_aligned_in_smp| - ____cacheline_internodealigned_in_smp| - __weak + volatile| + QEMU_NORETURN| + QEMU_WARN_UNUSED_RESULT| + QEMU_SENTINEL| + QEMU_ARTIFICIAL| + QEMU_PACKED| + GCC_FMT_ATTR }x; our $Modifier; -our $Inline = qr{inline|__always_inline|noinline}; +our $Inline = qr{inline}; our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]}; our $Lval = qr{$Ident(?:$Member)*};
@@ -1367,7 +1352,7 @@ sub process { # Check for incorrect file permissions if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) { my $permhere = $here . "FILE: $realfile\n"; - if ($realfile =~ /(Makefile|Kconfig|\.c|\.cpp|\.h|\.S|\.tmpl)$/) { + if ($realfile =~ /(\bMakefile(?:\.objs)?|\.c|\.cc|\.cpp|\.h|\.mak|\.[sS])$/) { ERROR("do not set execute permissions for source files\n" . $permhere); } }
@@ -1947,9 +1932,14 @@ sub process { ERROR("open brace '{' following $1 go on the same line\n" . $hereprev); } +# ... however, open braces on typedef lines should be avoided. + if ($line =~ /^.\s*typedef\s+(enum|union|struct)(?:\s+$Ident\b)?.*[^;]$/) { + ERROR("typedefs should be separate from struct declaration\n" . $herecurr); + } + # missing space after union, struct or enum definition if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?(?:\s+$Ident)?[=\{]/) { - WARN("missing space after $1 definition\n" . $herecurr); + ERROR("missing space after $1 definition\n" . $herecurr); } # check for spacing round square brackets; allowed:
@@ -2267,7 +2257,7 @@ sub process { if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) { my $name = $1; if ($name ne 'EOF' && $name ne 'ERROR') { - CHK("return of an errno should typically be -ve (return -$1)\n" . $herecurr); + WARN("return of an errno should typically be -ve (return -$1)\n" . $herecurr); } }
@@ -2671,15 +2661,15 @@ sub process { # warn about #if 0 if ($line =~ /^.\s*\#\s*if\s+0\b/) { - CHK("if this code is redundant consider removing it\n" . + WARN("if this code is redundant consider removing it\n" . $herecurr); } -# check for needless kfree() checks +# check for needless g_free() checks if ($prevline =~ /\bif\s*\(([^\)]*)\)/) { my $expr = $1; - if ($line =~ /\bkfree\(\Q$expr\E\);/) { - WARN("kfree(NULL) is safe this check is probably not required\n" . $hereprev); + if ($line =~ /\bg_free\(\Q$expr\E\);/) { + WARN("g_free(NULL) is safe this check is probably not required\n" . $hereprev); } } # check for needless usb_free_urb() checks
@@ -2726,14 +2716,16 @@ sub process { } } # check for memory barriers without a comment. - if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) { + if ($line =~ /\b(smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) { if (!ctx_has_comment($first_line, $linenr)) { - CHK("memory barrier without comment\n" . $herecurr); + WARN("memory barrier without comment\n" . $herecurr); } } # check of hardware specific defines - if ($line =~ m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) { - CHK("architecture specific defines should be avoided\n" . $herecurr); +# we have e.g. CONFIG_LINUX and CONFIG_WIN32 for common cases +# where they might be necessary. + if ($line =~ m@^.\s*\#\s*if.*\b__@) { + WARN("architecture specific defines should be avoided\n" . $herecurr); } # Check that the storage class is at the beginning of a declaration
@@ -2794,9 +2786,13 @@ sub process { } } -# check for pointless casting of kmalloc return - if ($line =~ /\*\s*\)\s*k[czm]alloc\b/) { - WARN("unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr); +# check for pointless casting of g_malloc return + if ($line =~ /\*\s*\)\s*g_(try)?(m|re)alloc(0?)(_n)?\b/) { + if ($2 == 'm') { + WARN("unnecessary cast may hide bugs, use g_$1new$3 instead\n" . $herecurr); + } else { + WARN("unnecessary cast may hide bugs, use g_$1renew$3 instead\n" . $herecurr); + } } # check for gcc specific __FUNCTION__
@@ -2813,54 +2809,37 @@ sub process { WARN("consider using a completion\n" . $herecurr); } -# recommend strict_strto* over simple_strto* - if ($line =~ /\bsimple_(strto.*?)\s*\(/) { - WARN("consider using strict_$1 in preference to simple_$1\n" . $herecurr); +# recommend qemu_strto* over strto* + if ($line =~ /\b(strto.*?)\s*\(/) { + WARN("consider using qemu_$1 in preference to $1\n" . $herecurr); } -# check for __initcall(), use device_initcall() explicitly please - if ($line =~ /^.\s*__initcall\s*\(/) { - WARN("please use device_initcall() instead of __initcall()\n" . $herecurr); +# check for module_init(), use category-specific init macros explicitly please + if ($line =~ /^module_init\s*\(/) { + WARN("please use block_init(), type_init() etc. instead of module_init()\n" . $herecurr); } # check for various ops structs, ensure they are const. - my $struct_ops = qr{acpi_dock_ops| - address_space_operations| - backlight_ops| - block_device_operations| - dentry_operations| - dev_pm_ops| - dma_map_ops| - extent_io_ops| - file_lock_operations| - file_operations| - hv_ops| - ide_dma_ops| - intel_dvo_dev_ops| - item_operations| - iwl_ops| - kgdb_arch| - kgdb_io| - kset_uevent_ops| - lock_manager_operations| - microcode_ops| - mtrr_ops| - neigh_ops| - nlmsvc_binding| - pci_raw_ops| - pipe_buf_operations| - platform_hibernation_ops| - platform_suspend_ops| - proto_ops| - rpc_pipe_ops| - seq_operations| - snd_ac97_build_ops| - soc_pcmcia_socket_ops| - stacktrace_ops| - sysfs_ops| - tty_operations| - usb_mon_operations| - wd_ops}x; + my $struct_ops = qr{AIOCBInfo| + BdrvActionOps| + BlockDevOps| + BlockJobDriver| + DisplayChangeListenerOps| + GraphicHwOps| + IDEDMAOps| + KVMCapabilityInfo| + MemoryRegionIOMMUOps| + MemoryRegionOps| + MemoryRegionPortio| + QEMUFileOps| + SCSIBusInfo| + SCSIReqOps| + Spice[A-Z][a-zA-Z0-9]*Interface| + TPMDriverOps| + USBDesc[A-Z][a-zA-Z0-9]*| + VhostOps| + VMStateDescription| + VMStateInfo}x; if ($line !~ /\bconst\b/ && - $line =~ /\bstruct\s+($struct_ops)\b/) { + $line =~ /\b($struct_ops)\b/) { WARN("struct $1 should normally be const\n" . $herecurr); }
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 30/43] checkpatch: remove tests that are not relevant outside the kernel
In reply to Paolo BonziniFully removing Sparse support requires more invasive changes. Only remove the really kernel-specific parts such as address space names.
--- scripts/checkpatch.pl | 401 ++------------------------------------------------ 1 file changed, 12 insertions(+), 389 deletions(-)
scripts/checkpatch.pl +12 -389
@@ -141,14 +141,7 @@ our $Ident = qr{ }x; our $Storage = qr{extern|static|asmlinkage}; our $Sparse = qr{ - __user| - __kernel| - __force| - __iomem| - __must_check| - __init_refok| - __kprobes| - __ref + __force }x; # Notes to $Attribute:
@@ -200,14 +193,6 @@ our $typeTypedefs = qr{(?x: | QEMUBH # all uppercase )}; -our $logFunctions = qr{(?x: - printk| - pr_(debug|dbg|vdbg|devel|info|warning|err|notice|alert|crit|emerg|cont)| - (dev|netdev|netif)_(printk|dbg|vdbg|info|warn|err|notice|alert|crit|emerg|WARN)| - WARN| - panic -)}; - our @typeList = ( qr{void}, qr{(?:unsigned\s+)?char},
@@ -228,20 +213,20 @@ our @typeList = ( qr{${Ident}_handler}, qr{${Ident}_handler_fn}, ); + +# This can be modified by sub possible. Since it can be empty, be careful +# about regexes that always match, because they can cause infinite loops. our @modifierList = ( - qr{fastcall}, ); -our $allowed_asm_includes = qr{(?x: - irq| - memory -)}; -# memory.h: ARM has a custom one - sub build_types { - my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)"; - $Modifier = qr{(?:$Attribute|$Sparse|$mods)}; + if (@modifierList > 0) { + my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; + $Modifier = qr{(?:$Attribute|$Sparse|$mods)}; + } else { + $Modifier = qr{(?:$Attribute|$Sparse)}; + } $NonptrType = qr{ (?:$Modifier\s+|const\s+)* (?:
@@ -262,27 +247,6 @@ build_types(); $chk_signoff = 0 if ($file); -my @dep_includes = (); -my @dep_functions = (); -my $removal = "Documentation/feature-removal-schedule.txt"; -if ($tree && -f "$root/$removal") { - open(my $REMOVE, '<', "$root/$removal") || - die "$P: $removal: open failed - $!\n"; - while (<$REMOVE>) { - if (/^Check:\s+(.*\S)/) { - for my $entry (split(/[, ]+/, $1)) { - if ($entry =~ m@include/(.*)@) { - push(@dep_includes, $1); - - } elsif ($entry !~ m@/@) { - push(@dep_functions, $entry); - } - } - } - } - close($REMOVE); -} - my @rawlines = (); my @lines = (); my $vname;
@@ -1112,33 +1076,6 @@ sub CHK { } } -sub check_absolute_file { - my ($absolute, $herecurr) = @_; - my $file = $absolute; - - ##print "absolute<$absolute>\n"; - - # See if any suffix of this path is a path within the tree. - while ($file =~ s@^[^/]*/@@) { - if (-f "$root/$file") { - ##print "file<$file>\n"; - last; - } - } - if (! -f _) { - return 0; - } - - # It is, so see if the prefix is acceptable. - my $prefix = $absolute; - substr($prefix, -length($file)) = ''; - - ##print "prefix<$prefix>\n"; - if ($prefix ne ".../") { - WARN("use relative pathname instead of absolute in changelog text\n" . $herecurr); - } -} - sub process { my $filename = shift;
@@ -1181,10 +1118,6 @@ sub process { my %suppress_export; # Pre-scan the patch sanitizing the lines. - # Pre-scan the patch looking for any __setup documentation. - # - my @setup_docs = (); - my $setup_docs = 0; sanitise_line_reset(); my $line;
@@ -1192,13 +1125,6 @@ sub process { $linenr++; $line = $rawline; - if ($rawline=~/^\+\+\+\s+(\S+)/) { - $setup_docs = 0; - if ($1 =~ m@Documentation/kernel-parameters.txt$@) { - $setup_docs = 1; - } - #next; - } if ($rawline=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) { $realline=$1-1; if (defined $2) {
@@ -1257,10 +1183,6 @@ sub process { #print "==>$rawline\n"; #print "-->$line\n"; - - if ($setup_docs && $line =~ /^\+/) { - push(@setup_docs, $line); - } } $prefix = '';
@@ -1335,9 +1257,6 @@ sub process { WARN("patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n"); } - if ($realfile =~ m@^include/asm/@) { - ERROR("do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n"); - } next; }
@@ -1377,20 +1296,6 @@ sub process { $herecurr) if (!$emitted_corrupt++); } -# Check for absolute kernel paths. - if ($tree) { - while ($line =~ m{(?:^|\s)(/\S*)}g) { - my $file = $1; - - if ($file =~ m{^(.*?)(?::\d+)+:?$} && - check_absolute_file($1, $herecurr)) { - # - } else { - check_absolute_file($file, $herecurr); - } - } - } - # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php if (($realfile =~ /^$/ || $line =~ /^\+/) && $rawline !~ m/^$UTF8*$/) {
@@ -1417,45 +1322,12 @@ sub process { $rpt_cleaners = 1; } -# check for Kconfig help text having a real description -# Only applies when adding the entry originally, after that we do not have -# sufficient context to determine whether it is indeed long enough. - if ($realfile =~ /Kconfig/ && - $line =~ /\+\s*(?:---)?help(?:---)?$/) { - my $length = 0; - my $cnt = $realcnt; - my $ln = $linenr + 1; - my $f; - my $is_end = 0; - while ($cnt > 0 && defined $lines[$ln - 1]) { - $f = $lines[$ln - 1]; - $cnt-- if ($lines[$ln - 1] !~ /^-/); - $is_end = $lines[$ln - 1] =~ /^\+/; - $ln++; - - next if ($f =~ /^-/); - $f =~ s/^.//; - $f =~ s/#.*//; - $f =~ s/^\s+//; - next if ($f =~ /^$/); - if ($f =~ /^\s*config\s/) { - $is_end = 1; - last; - } - $length++; - } - WARN("please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($is_end && $length < 4); - #print "is_end<$is_end> length<$length>\n"; - } - # check we are in a valid source file if not then ignore this hunk next if ($realfile !~ /\.(h|c|cpp|s|S|pl|sh)$/); #80 column limit - if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && - $rawline !~ /^.\s*\*\s*\@$Ident\s/ && - !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:,|\)\s*;)\s*$/ || - $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) && + if ($line =~ /^\+/ && + !($line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) && $length > 80) { WARN("line over 80 characters\n" . $herecurr);
@@ -1471,18 +1343,6 @@ sub process { WARN("adding a line without newline at end of file\n" . $herecurr); } -# Blackfin: use hi/lo macros - if ($realfile =~ m@arch/blackfin/.*\.S$@) { - if ($line =~ /\.[lL][[:space:]]*=.*&[[:space:]]*0x[fF][fF][fF][fF]/) { - my $herevet = "$here\n" . cat_vet($line) . "\n"; - ERROR("use the LO() macro, not (... & 0xFFFF)\n" . $herevet); - } - if ($line =~ /\.[hH][[:space:]]*=.*>>[[:space:]]*16/) { - my $herevet = "$here\n" . cat_vet($line) . "\n"; - ERROR("use the HI() macro, not (... >> 16)\n" . $herevet); - } - } - # check we are in a valid source file C or perl if not then ignore this hunk next if ($realfile !~ /\.(h|c|cpp|pl)$/);
@@ -1501,16 +1361,6 @@ sub process { WARN("CVS style keyword markers, these will _not_ be updated\n". $herecurr); } -# Blackfin: don't use __builtin_bfin_[cs]sync - if ($line =~ /__builtin_bfin_csync/) { - my $herevet = "$here\n" . cat_vet($line) . "\n"; - ERROR("use the CSYNC() macro in asm/blackfin.h\n" . $herevet); - } - if ($line =~ /__builtin_bfin_ssync/) { - my $herevet = "$here\n" . cat_vet($line) . "\n"; - ERROR("use the SSYNC() macro in asm/blackfin.h\n" . $herevet); - } - # Check for potential 'bare' types my ($stat, $cond, $line_nr_next, $remain_next, $off_next, $realline_next);
@@ -1794,50 +1644,6 @@ sub process { $line =~ s@//.*@@; $opline =~ s@//.*@@; -# EXPORT_SYMBOL should immediately follow the thing it is exporting, consider -# the whole statement. -#print "APW <$lines[$realline_next - 1]>\n"; - if (defined $realline_next && - exists $lines[$realline_next - 1] && - !defined $suppress_export{$realline_next} && - ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ || - $lines[$realline_next - 1] =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) { - # Handle definitions which produce identifiers with - # a prefix: - # XXX(foo); - # EXPORT_SYMBOL(something_foo); - my $name = $1; - if ($stat =~ /^.([A-Z_]+)\s*\(\s*($Ident)/ && - $name =~ /^${Ident}_$2/) { -#print "FOO C name<$name>\n"; - $suppress_export{$realline_next} = 1; - - } elsif ($stat !~ /(?: - \n.}\s*$| - ^.DEFINE_$Ident\(\Q$name\E\)| - ^.DECLARE_$Ident\(\Q$name\E\)| - ^.LIST_HEAD\(\Q$name\E\)| - ^.(?:$Storage\s+)?$Type\s*\(\s*\*\s*\Q$name\E\s*\)\s*\(| - \b\Q$name\E(?:\s+$Attribute)*\s*(?:;|=|\[|\() - )/x) { -#print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n"; - $suppress_export{$realline_next} = 2; - } else { - $suppress_export{$realline_next} = 1; - } - } - if (!defined $suppress_export{$linenr} && - $prevline =~ /^.\s*$/ && - ($line =~ /EXPORT_SYMBOL.*\((.*)\)/ || - $line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) { -#print "FOO B <$lines[$linenr - 1]>\n"; - $suppress_export{$linenr} = 2; - } - if (defined $suppress_export{$linenr} && - $suppress_export{$linenr} == 2) { - WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr); - } - # check for global initialisers. if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) { ERROR("do not initialise globals to 0 or NULL\n" .
@@ -1885,40 +1691,6 @@ sub process { } } -# # no BUG() or BUG_ON() -# if ($line =~ /\b(BUG|BUG_ON)\b/) { -# print "Try to use WARN_ON & Recovery code rather than BUG() or BUG_ON()\n"; -# print "$herecurr"; -# $clean = 0; -# } - - if ($line =~ /\bLINUX_VERSION_CODE\b/) { - WARN("LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr); - } - -# printk should use KERN_* levels. Note that follow on printk's on the -# same line do not need a level, so we use the current block context -# to try and find and validate the current printk. In summary the current -# printk includes all preceding printk's which have no newline on the end. -# we assume the first bad printk is the one to report. - if ($line =~ /\bprintk\((?!KERN_)\s*"/) { - my $ok = 0; - for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) { - #print "CHECK<$lines[$ln - 1]\n"; - # we have a preceding printk if it ends - # with "\n" ignore it, else it is to blame - if ($lines[$ln - 1] =~ m{\bprintk\(}) { - if ($rawlines[$ln - 1] !~ m{\\n"}) { - $ok = 1; - } - last; - } - } - if ($ok == 0) { - WARN("printk() should include KERN_ facility level\n" . $herecurr); - } - } - # function brace can't be on same line, except for #defines of do while, # or if closed on same line if (($line=~/$Type\s*$Ident\(.*\).*\s{/) and
@@ -2180,26 +1952,6 @@ sub process { } } -# check for multiple assignments - if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) { - CHK("multiple assignments should be avoided\n" . $herecurr); - } - -## # check for multiple declarations, allowing for a function declaration -## # continuation. -## if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ && -## $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) { -## -## # Remove any bracketed sections to ensure we do not -## # falsly report the parameters of functions. -## my $ln = $line; -## while ($ln =~ s/\([^\(\)]*\)//g) { -## } -## if ($ln =~ /,/) { -## WARN("declaring multiple variables together should be avoided\n" . $herecurr); -## } -## } - #need space before brace following if, while, etc if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) || $line =~ /do{/) {
@@ -2388,22 +2140,6 @@ sub process { WARN("Whitepspace after \\ makes next lines useless\n" . $herecurr); } -#warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line) - if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\<asm\/(.*)\.h\>}) { - my $file = "$1.h"; - my $checkfile = "include/linux/$file"; - if (-f "$root/$checkfile" && - $realfile ne $checkfile && - $1 !~ /$allowed_asm_includes/) - { - if ($realfile =~ m{^arch/}) { - CHK("Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr); - } else { - WARN("Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr); - } - } - } - # multi-statement macros should be enclosed in a do while loop, grab the # first statement and ensure its the whole macro if its not enclosed # in a known good container
@@ -2498,15 +2234,6 @@ sub process { } } -# make sure symbols are always wrapped with VMLINUX_SYMBOL() ... -# all assignments may have only one of the following with an assignment: -# . -# ALIGN(...) -# VMLINUX_SYMBOL(...) - if ($realfile eq 'vmlinux.lds.h' && $line =~ /(?:(?:^|\s)$Ident\s*=|=\s*$Ident(?:\s|$))/) { - WARN("vmlinux.lds.h needs VMLINUX_SYMBOL() around C-visible symbols\n" . $herecurr); - } - # check for missing bracing round if etc if ($line =~ /(^.*)\bif\b/ && $line !~ /\#\s*if/) { my ($level, $endln, @chunks) =
@@ -2634,31 +2361,12 @@ sub process { } } -# don't include deprecated include files (uses RAW line) - for my $inc (@dep_includes) { - if ($rawline =~ m@^.\s*\#\s*include\s*\<$inc>@) { - ERROR("Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n" . $herecurr); - } - } - -# don't use deprecated functions - for my $func (@dep_functions) { - if ($line =~ /\b$func\b/) { - ERROR("Don't use $func(): see Documentation/feature-removal-schedule.txt\n" . $herecurr); - } - } - # no volatiles please my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b}; if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) { WARN("Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr); } -# SPIN_LOCK_UNLOCKED & RW_LOCK_UNLOCKED are deprecated - if ($line =~ /\b(SPIN_LOCK_UNLOCKED|RW_LOCK_UNLOCKED)/) { - ERROR("Use of $1 is deprecated: see Documentation/spinlocks.txt\n" . $herecurr); - } - # warn about #if 0 if ($line =~ /^.\s*\#\s*if\s+0\b/) { WARN("if this code is redundant consider removing it\n" .
@@ -2672,28 +2380,6 @@ sub process { WARN("g_free(NULL) is safe this check is probably not required\n" . $hereprev); } } -# check for needless usb_free_urb() checks - if ($prevline =~ /\bif\s*\(([^\)]*)\)/) { - my $expr = $1; - if ($line =~ /\busb_free_urb\(\Q$expr\E\);/) { - WARN("usb_free_urb(NULL) is safe this check is probably not required\n" . $hereprev); - } - } - -# prefer usleep_range over udelay - if ($line =~ /\budelay\s*\(\s*(\w+)\s*\)/) { - # ignore udelay's < 10, however - if (! (($1 =~ /(\d+)/) && ($1 < 10)) ) { - CHK("usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $line); - } - } - -# warn about unexpectedly long msleep's - if ($line =~ /\bmsleep\s*\((\d+)\);/) { - if ($1 < 20) { - WARN("msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $line); - } - } # warn about #ifdefs in C files # if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
@@ -2706,15 +2392,6 @@ sub process { if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) { ERROR("exactly one space required after that #$1\n" . $herecurr); } - -# check for spinlock_t definitions without a comment. - if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/ || - $line =~ /^.\s*(DEFINE_MUTEX)\s*\(/) { - my $which = $1; - if (!ctx_has_comment($first_line, $linenr)) { - CHK("$1 definition without comment\n" . $herecurr); - } - } # check for memory barriers without a comment. if ($line =~ /\b(smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) { if (!ctx_has_comment($first_line, $linenr)) {
@@ -2740,11 +2417,6 @@ sub process { ERROR("inline keyword should sit between storage class and type\n" . $herecurr); } -# Check for __inline__ and __inline, prefer inline - if ($line =~ /\b(__inline__|__inline)\b/) { - WARN("plain inline is preferred over $1\n" . $herecurr); - } - # check for sizeof(&) if ($line =~ /\bsizeof\s*\(\s*\&/) { WARN("sizeof(& should be avoided\n" . $herecurr);
@@ -2777,15 +2449,6 @@ sub process { WARN("externs should be avoided in .c files\n" . $herecurr); } -# checks for new __setup's - if ($rawline =~ /\b__setup\("([^"]*)"/) { - my $name = $1; - - if (!grep(/$name/, @setup_docs)) { - CHK("__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr); - } - } - # check for pointless casting of g_malloc return if ($line =~ /\*\s*\)\s*g_(try)?(m|re)alloc(0?)(_n)?\b/) { if ($2 == 'm') {
@@ -2800,15 +2463,6 @@ sub process { WARN("__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr); } -# check for semaphores used as mutexes - if ($line =~ /^.\s*(DECLARE_MUTEX|init_MUTEX)\s*\(/) { - WARN("mutexes are preferred for single holder semaphores\n" . $herecurr); - } -# check for semaphores used as mutexes - if ($line =~ /^.\s*init_MUTEX_LOCKED\s*\(/) { - WARN("consider using a completion\n" . $herecurr); - - } # recommend qemu_strto* over strto* if ($line =~ /\b(strto.*?)\s*\(/) { WARN("consider using qemu_$1 in preference to $1\n" . $herecurr);
@@ -2844,18 +2498,6 @@ sub process { $herecurr); } -# use of NR_CPUS is usually wrong -# ignore definitions of NR_CPUS and usage to define arrays as likely right - if ($line =~ /\bNR_CPUS\b/ && - $line !~ /^.\s*\s*#\s*if\b.*\bNR_CPUS\b/ && - $line !~ /^.\s*\s*#\s*define\b.*\bNR_CPUS\b/ && - $line !~ /^.\s*$Declare\s.*\[[^\]]*NR_CPUS[^\]]*\]/ && - $line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ && - $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/) - { - WARN("usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr); - } - # check for %L{u,d,i} in strings my $string; while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) {
@@ -2867,25 +2509,6 @@ sub process { } } -# whine mightly about in_atomic - if ($line =~ /\bin_atomic\s*\(/) { - if ($realfile =~ m@^drivers/@) { - ERROR("do not use in_atomic in drivers\n" . $herecurr); - } elsif ($realfile !~ m@^kernel/@) { - WARN("use of in_atomic() is incorrect outside core kernel code\n" . $herecurr); - } - } - -# check for lockdep_set_novalidate_class - if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ || - $line =~ /__lockdep_no_validate__\s*\)/ ) { - if ($realfile !~ m@^kernel/lockdep@ && - $realfile !~ m@^include/linux/lockdep@ && - $realfile !~ m@^drivers/base/core@) { - ERROR("lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr); - } - } - # QEMU specific tests if ($rawline =~ /\b(?:Qemu|QEmu)\b/) { WARN("use QEMU instead of Qemu or QEmu\n" . $herecurr);
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 31/43] vhost-scsi: fix wrong vhost-scsi firmware path
In reply to Paolo BonziniFrom: Gonglei <[email protected]>
vhost-scsi bootindex does't work because Qemu passes wrong fireware path to seabios.
before:
/pci@i0cf8/scsi@7channel@0/vhost-scsi@0,0
after applying the patch:
/pci@i0cf8/scsi@7/channel@0/vhost-scsi@0,0
Message-Id: <[email protected]>
--- hw/scsi/vhost-scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/scsi/vhost-scsi.c +1 -1
@@ -292,7 +292,7 @@ static char *vhost_scsi_get_fw_dev_path(FWPathProvider *p, BusState *bus, {VHostSCSI *s =VHOST_SCSI (dev);/* format: channel@channel/vhost-scsi@target,lun */ -return g_strdup_printf ("channel@%x/%s@%x,%x" , s->channel, +return g_strdup_printf ("/channel@%x/%s@%x,%x" , s->channel,qdev_fw_name (dev), s->target, s->lun); }
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 32/43] configure: factor out adding disas configure
In reply to Paolo BonziniFrom: Peter Crosthwaite <[email protected]>
Every arch adds its disas configury to both its own config as well config_disas_all. Make a small function do to both at once.
Message-Id: <[email protected]>
--- configure | 65 ++++++++++++++++++++++++--------------------------------------- 1 file changed, 25 insertions(+), 40 deletions(-)
configure +25 -40
@@ -5483,91 +5483,76 @@ fi cflags="" ldflags="" +disas_config() { + echo "CONFIG_${1}_DIS=y" >> $config_target_mak + echo "CONFIG_${1}_DIS=y" >> config-all-disas.mak +} + for i in $ARCH $TARGET_BASE_ARCH ; do case "$i" in alpha) - echo "CONFIG_ALPHA_DIS=y" >> $config_target_mak - echo "CONFIG_ALPHA_DIS=y" >> config-all-disas.mak + disas_config "ALPHA" ;; aarch64) if test -n "${cxx}"; then - echo "CONFIG_ARM_A64_DIS=y" >> $config_target_mak - echo "CONFIG_ARM_A64_DIS=y" >> config-all-disas.mak + disas_config "ARM_A64" fi ;; arm) - echo "CONFIG_ARM_DIS=y" >> $config_target_mak - echo "CONFIG_ARM_DIS=y" >> config-all-disas.mak + disas_config "ARM" if test -n "${cxx}"; then - echo "CONFIG_ARM_A64_DIS=y" >> $config_target_mak - echo "CONFIG_ARM_A64_DIS=y" >> config-all-disas.mak + disas_config "ARM_A64" fi ;; cris) - echo "CONFIG_CRIS_DIS=y" >> $config_target_mak - echo "CONFIG_CRIS_DIS=y" >> config-all-disas.mak + disas_config "CRIS" ;; hppa) - echo "CONFIG_HPPA_DIS=y" >> $config_target_mak - echo "CONFIG_HPPA_DIS=y" >> config-all-disas.mak + disas_config "HPPA" ;; i386|x86_64|x32) - echo "CONFIG_I386_DIS=y" >> $config_target_mak - echo "CONFIG_I386_DIS=y" >> config-all-disas.mak + disas_config "I386" ;; ia64*) - echo "CONFIG_IA64_DIS=y" >> $config_target_mak - echo "CONFIG_IA64_DIS=y" >> config-all-disas.mak + disas_config "IA64" ;; lm32) - echo "CONFIG_LM32_DIS=y" >> $config_target_mak - echo "CONFIG_LM32_DIS=y" >> config-all-disas.mak + disas_config "LM32" ;; m68k) - echo "CONFIG_M68K_DIS=y" >> $config_target_mak - echo "CONFIG_M68K_DIS=y" >> config-all-disas.mak + disas_config "M68K" ;; microblaze*) - echo "CONFIG_MICROBLAZE_DIS=y" >> $config_target_mak - echo "CONFIG_MICROBLAZE_DIS=y" >> config-all-disas.mak + disas_config "MICROBLAZE" ;; mips*) - echo "CONFIG_MIPS_DIS=y" >> $config_target_mak - echo "CONFIG_MIPS_DIS=y" >> config-all-disas.mak + disas_config "MIPS" ;; moxie*) - echo "CONFIG_MOXIE_DIS=y" >> $config_target_mak - echo "CONFIG_MOXIE_DIS=y" >> config-all-disas.mak + disas_config "MOXIE" ;; or32) - echo "CONFIG_OPENRISC_DIS=y" >> $config_target_mak - echo "CONFIG_OPENRISC_DIS=y" >> config-all-disas.mak + disas_config "OPENRISC" ;; ppc*) - echo "CONFIG_PPC_DIS=y" >> $config_target_mak - echo "CONFIG_PPC_DIS=y" >> config-all-disas.mak + disas_config "PPC" ;; s390*) - echo "CONFIG_S390_DIS=y" >> $config_target_mak - echo "CONFIG_S390_DIS=y" >> config-all-disas.mak + disas_config "S390" ;; sh4) - echo "CONFIG_SH4_DIS=y" >> $config_target_mak - echo "CONFIG_SH4_DIS=y" >> config-all-disas.mak + disas_config "SH4" ;; sparc*) - echo "CONFIG_SPARC_DIS=y" >> $config_target_mak - echo "CONFIG_SPARC_DIS=y" >> config-all-disas.mak + disas_config "SPARC" ;; xtensa*) - echo "CONFIG_XTENSA_DIS=y" >> $config_target_mak - echo "CONFIG_XTENSA_DIS=y" >> config-all-disas.mak + disas_config "XTENSA" ;; esac done if test "$tcg_interpreter" = "yes" ; then - echo "CONFIG_TCI_DIS=y" >> $config_target_mak - echo "CONFIG_TCI_DIS=y" >> config-all-disas.mak + disas_config "TCI" fi case "$ARCH" in
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 34/43] configure: Add support for jemalloc
In reply to Paolo BonziniFrom: Alexandre Derumier <[email protected]>
This adds "--enable-jemalloc" and "--disable-jemalloc" to allow linking to jemalloc memory allocator.
We have already tcmalloc support,
but it seem to not working well with a lot of iothreads/disks.
The main problem is that tcmalloc use a shared thread cache of 16MB by default.
With more threads, this cache is shared, and some bad garbage collections can occur if the cache is too low.
It's possible to tcmalloc cache increase it with a env var:
TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES=256MB
With default 16MB, performances are really bad with more than 2 disks. Increasing to 256MB, it's helping but still have problem with 16 disks/iothreads.
Jemalloc don't have performance problem with default configuration.
Here the benchmark results in iops of 1 qemu vm randread 4K iodepth=32, with rbd block backend (librbd is doing a lot of memory allocation), 1 iothread by disk
glibc malloc
------------
1 disk 29052 2 disks 55878 4 disks 127899 8 disks 240566 15 disks 269976
jemalloc
--------
1 disk 41278 2 disks 75781 4 disks 195351 8 disks 294241 15 disks 298199
tcmalloc 2.2.1 default 16M cache
--------------------------------
1 disk 37911 2 disks 67698 4 disks 41076 8 disks 43312
15 disks 37569
tcmalloc : 256M cache
---------------------------
1 disk 33914 2 disks 58839 4 disks 148205 8 disks 213298 15 disks 218383
Message-Id: <[email protected]>
--- configure | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
configure +28 -0
@@ -337,6 +337,7 @@ libssh2="" vhdx="" numa="" tcmalloc="no" +jemalloc="no" # parse CC options first for opt do
@@ -1143,6 +1144,10 @@ for opt do ;; --enable-tcmalloc) tcmalloc="yes" ;; + --disable-jemalloc) jemalloc="no" + ;; + --enable-jemalloc) jemalloc="yes" + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information"
@@ -1367,6 +1372,7 @@ disabled with --disable-FEATURE, default is enabled if available: vhdx support for the Microsoft VHDX image format numa libnuma support tcmalloc tcmalloc support + jemalloc jemalloc support NOTE: The object files are built at the place where configure is launched EOF
@@ -3367,6 +3373,11 @@ EOF fi fi +if test "$tcmalloc" = "yes" && test "$jemalloc" = "yes" ; then + echo "ERROR: tcmalloc && jemalloc can't be used at the same time" + exit 1 +fi + ########################################## # tcmalloc probe
@@ -3384,6 +3395,22 @@ EOF fi ########################################## +# jemalloc probe + +if test "$jemalloc" = "yes" ; then + cat > $TMPC << EOF +#include <stdlib.h> +int main(void) { malloc(1); return 0; } +EOF + + if compile_prog "" "-ljemalloc" ; then + LIBS="-ljemalloc $LIBS" + else + feature_not_found "jemalloc" "install jemalloc devel" + fi +fi + +########################################## # signalfd probe signalfd="no" cat > $TMPC << EOF
@@ -4594,6 +4621,7 @@ echo "snappy support $snappy" echo "bzip2 support $bzip2" echo "NUMA host support $numa" echo "tcmalloc support $tcmalloc" +echo "jemalloc support $jemalloc" if test "$sdl_too_old" = "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support"
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 35/43] scripts/dump-guest-memory.py: fix after RAMBlock change
In reply to Paolo BonziniFrom: "Michael S. Tsirkin" <[email protected]>
commit 9b8424d5735278ca382f11adc7c63072b632ab83
"exec: split length -> used_length/max_length"
changed field names in struct RAMBlock
It turns out that scripts/dump-guest-memory.py was poking at this field, update it accordingly.
Message-Id: <[email protected]>
--- scripts/dump-guest-memory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/dump-guest-memory.py +1 -1
@@ -118,7 +118,7 @@ shape and this command should mostly work.""" def qemu_get_ram_block(self, ram_addr): ram_blocks = gdb.parse_and_eval("ram_list.blocks") for block in self.qlist_foreach(ram_blocks, "next"): - if (ram_addr - block["offset"] < block["length"]): + if (ram_addr - block["offset"] < block["used_length"]): return block raise gdb.GdbError("Bad ram offset %x" % ram_addr)
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 33/43] add macro file for coccinelle
In reply to Paolo BonziniCoccinelle chokes on some idioms from compiler.h and queue.h. Extract those in a macro file, to be used with "--macro-file scripts/cocci-macro-file.h".
--- scripts/cocci-macro-file.h | 119 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 scripts/cocci-macro-file.h
scripts/cocci-macro-file.h new file +119 -0
@@ -0,0 +1,119 @@ +/* Macro file for Coccinelle +* +* Copyright (C) 2015 Red Hat, Inc. +* +* Authors: +* Paolo Bonzini <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or, at your +* option, any later version. See the COPYING file in the top-level directory. +*/ + +/* Coccinelle only does limited parsing of headers, and chokes on some idioms +* defined in compiler.h and queue.h. Macros that Coccinelle must know about +* in order to parse .c files must be in a separate macro file---which is +* exactly what you're staring at now. +* +* To use this file, add the "--macro-file scripts/cocci-macro-file.h" to the +* Coccinelle command line. +*/ + +/* From qemu/compiler.h */ +#define QEMU_GNUC_PREREQ (maj, min) 1 +#define QEMU_NORETURN __attribute__ ((__noreturn__)) +#define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) +#define QEMU_SENTINEL __attribute__((sentinel)) +#define QEMU_ARTIFICIAL __attribute__((always_inline, artificial)) +#define QEMU_PACKED __attribute__((gcc_struct, packed)) + +#define cat (x,y) x ## y +#define cat2 (x,y) cat(x,y) +#define QEMU_BUILD_BUG_ON (x) \ + typedef char cat2(qemu_build_bug_on__,__LINE__)[(x)?-1:1] __attribute__((unused)); + +#define GCC_FMT_ATTR (n, m) __attribute__((format(gnu_printf, n, m))) + +#define xglue (x, y) x ## y +#define glue (x, y) xglue(x, y) +#define stringify (s) tostring(s) +#define tostring (s) #s + +#define typeof_field (type, field) typeof(((type *)0)->field) +#define type_check (t1,t2) ((t1*)0 - (t2*)0) + +/* From qemu/queue.h */ + +#define QLIST_HEAD (name, type) \ +struct name { \ + struct type *lh_first;/* first element */ \ +} + +#define QLIST_HEAD_INITIALIZER (head) \ + { NULL } + +#define QLIST_ENTRY (type) \ +struct { \ + struct type *le_next;/* next element */ \ +struct type **le_prev;/* address of previous next element */ \ +} + +/* +* Singly-linked List definitions. +*/ +#define QSLIST_HEAD(name, type) \ +struct name { \ + struct type *slh_first; /* first element */ \ +} + +#define QSLIST_HEAD_INITIALIZER (head) \ + { NULL } + +#define QSLIST_ENTRY(type) \ +struct { \ + struct type *sle_next; /* next element */ \ +} + +/* +* Simple queue definitions. +*/ +#define QSIMPLEQ_HEAD (name, type) \ +struct name { \ + struct type *sqh_first;/* first element */ \ +struct type **sqh_last;/* addr of last next element */ \ +} + +#define QSIMPLEQ_HEAD_INITIALIZER (head) \ + { NULL, &(head).sqh_first } + +#define QSIMPLEQ_ENTRY(type) \ +struct { \ + struct type *sqe_next; /* next element */ \ +} + +/* +* Tail queue definitions. +*/ +#define Q_TAILQ_HEAD(name, type, qual) \ +struct name { \ + qual type *tqh_first; /* first element */ \ + qual type *qual *tqh_last; /* addr of last next element */ \ +} +#define QTAILQ_HEAD(name, type) \ +struct name { \ + type *tqh_first; /* first element */ \ + type **tqh_last; /* addr of last next element */ \ +} + +#define QTAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).tqh_first } + +#define Q_TAILQ_ENTRY(type, qual) \ +struct { \ + qual type *tqe_next; /* next element */ \ + qual type *qual *tqe_prev; /* address of previous next element */\ +} +#define QTAILQ_ENTRY(type) \ +struct { \ + type *tqe_next; /* next element */ \ + type **tqe_prev; /* address of previous next element */ \ +}
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 36/43] cpus: protect work list with work_mutex
In reply to Paolo BonziniProtect the list of queued work items with something other than the BQL, as a preparation for running the work items outside it.
--- cpus.c | 22 ++++++++++++++++++---- include/qom/cpu.h | 6 +++++- qom/cpu.c | 1 + 3 files changed, 24 insertions(+), 5 deletions(-)
cpus.c +18 -4
@@ -819,6 +819,8 @@ void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data) wi.func = func; wi.data = data; wi.free = false; + +qemu_mutex_lock (&cpu->work_mutex);if (cpu->queued_work_first ==NULL ) { cpu->queued_work_first = &wi; }else {
@@ -827,9 +829,10 @@ void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data) cpu->queued_work_last = &wi; wi.next =NULL ; wi.done = false; +qemu_mutex_unlock (&cpu->work_mutex);qemu_cpu_kick (cpu); -while (!wi.done) { +while (!atomic_mb_read (&wi.done)) {CPUState *self_cpu = current_cpu;qemu_cond_wait (&qemu_work_cond, &qemu_global_mutex);
@@ -850,6 +853,8 @@ void async_run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data) wi->func = func; wi->data = data; wi->free = true; + +qemu_mutex_lock (&cpu->work_mutex);if (cpu->queued_work_first ==NULL ) { cpu->queued_work_first = wi; }else {
@@ -858,6 +863,7 @@ void async_run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data) cpu->queued_work_last = wi; wi->next =NULL ; wi->done = false; +qemu_mutex_unlock (&cpu->work_mutex);qemu_cpu_kick (cpu); }
@@ -870,15 +876,23 @@ static void flush_queued_work(CPUState *cpu)return ; } -while ((wi = cpu->queued_work_first)) { +qemu_mutex_lock (&cpu->work_mutex); +while (cpu->queued_work_first !=NULL ) { + wi = cpu->queued_work_first; cpu->queued_work_first = wi->next; +if (!cpu->queued_work_first) { + cpu->queued_work_last =NULL ; + } +qemu_mutex_unlock (&cpu->work_mutex); wi->func (wi->data); - wi->done = true; +qemu_mutex_lock (&cpu->work_mutex);if (wi->free) {g_free (wi); + }else { +atomic_mb_set (&wi->done, true); } } - cpu->queued_work_last =NULL ; +qemu_mutex_unlock (&cpu->work_mutex);qemu_cond_broadcast (&qemu_work_cond); }
include/qom/cpu.h +5 -1
@@ -243,6 +243,8 @@ struct kvm_run;* @mem_io_pc: Host Program Counter at which the memory was accessed. * @mem_io_vaddr: Target virtual address at which the memory was accessed. * @kvm_fd: vCPU file descriptor for KVM. +* @work_mutex: Lock to prevent multiple access to queued_work_*. +* @queued_work_first: First asynchronous work pending. * * State of one CPU core or thread. */
@@ -263,7 +265,6 @@ struct CPUState {uint32_t host_tid;bool running;struct QemuCond *halt_cond; -struct qemu_work_item *queued_work_first, *queued_work_last;bool thread_kicked;bool created;bool stop;
@@ -274,6 +275,9 @@ struct CPUState {int64_t icount_extra;sigjmp_buf jmp_env; +QemuMutex work_mutex; +struct qemu_work_item *queued_work_first, *queued_work_last; +AddressSpace *as;struct AddressSpaceDispatch *memory_dispatch;MemoryListener *tcg_as_listener;
qom/cpu.c +1 -0
@@ -316,6 +316,7 @@ static void cpu_common_initfn(Object *obj) cpu->cpu_index =-1 ; cpu->gdb_num_regs = cpu->gdb_num_g_regs = cc->gdb_num_core_regs; +qemu_mutex_init (&cpu->work_mutex);QTAILQ_INIT (&cpu->breakpoints);QTAILQ_INIT (&cpu->watchpoints); }
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 37/43] cpus: remove tcg_halt_cond and tcg_cpu_thread globals
In reply to Paolo BonziniFrom: KONRAD Frederic <[email protected]>
This hides the tcg_halt_cond and tcg_cpu_thread global variables inside qemu_tcg_init_vcpu. Multi-threaded TCG will need one QemuCond and one QemuThread per virtual cpu, so it's preferrable to use cpu->halt_cond and cpu->thread.
Message-Id: <[email protected]>
--- cpus.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
cpus.c +6 -9
@@ -786,9 +786,6 @@ static unsigned iothread_requesting_mutex;static QemuThread io_thread; -static QemuThread *tcg_cpu_thread; -static QemuCond *tcg_halt_cond; -/* cpu creation */ static QemuCond qemu_cpu_cond;/* system init */
@@ -907,15 +904,13 @@ static void qemu_wait_io_event_common(CPUState *cpu) cpu->thread_kicked = false; } -static void qemu_tcg_wait_io_event (void ) +static void qemu_tcg_wait_io_event (CPUState *cpu) { -CPUState *cpu; -while (all_cpu_threads_idle ()) {/* Start accounting real time to the virtual clock if the CPUs are idle. */ qemu_clock_warp (QEMU_CLOCK_VIRTUAL ); -qemu_cond_wait (tcg_halt_cond, &qemu_global_mutex); +qemu_cond_wait (cpu->halt_cond, &qemu_global_mutex); }while (iothread_requesting_mutex) {
@@ -1040,7 +1035,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)/* wait for initial kick-off after machine start */ while (first_cpu->stopped) { -qemu_cond_wait (tcg_halt_cond, &qemu_global_mutex); +qemu_cond_wait (first_cpu->halt_cond, &qemu_global_mutex);/* process any pending work */ CPU_FOREACH (cpu) {
@@ -1061,7 +1056,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)qemu_clock_notify (QEMU_CLOCK_VIRTUAL ); } } -qemu_tcg_wait_io_event (); +qemu_tcg_wait_io_event (QTAILQ_FIRST (&cpus)); }return NULL ;
@@ -1224,6 +1219,8 @@ void resume_all_vcpus(void)static void qemu_tcg_init_vcpu (CPUState *cpu) {char thread_name[VCPU_THREAD_NAME_SIZE ]; +static QemuCond *tcg_halt_cond; +static QemuThread *tcg_cpu_thread;tcg_cpu_address_space_init (cpu, cpu->as);
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 39/43] remove unused spinlock.
In reply to Paolo BonziniFrom: KONRAD Frederic <[email protected]>
This just removes spinlock as it is not used anymore.
Message-Id: <[email protected]>
--- include/exec/spinlock.h | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 include/exec/spinlock.h
include/exec/spinlock.h deleted +0 -49
@@ -1,49 +0,0 @@ -/* -* Copyright (c) 2003 Fabrice Bellard -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU Lesser General Public -* License as published by the Free Software Foundation; either -* version 2 of the License, or (at your option) any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public -* License along with this library; if not, see <http://www.gnu.org/licenses/> -*/ - -/* configure guarantees us that we have pthreads on any host except -* mingw32, which doesn't support any of the user-only targets. -* So we can simply assume we have pthread mutexes here. -*/ -#if defined(CONFIG_USER_ONLY ) - -#include <pthread.h> -#define spin_lock pthread_mutex_lock -#define spin_unlock pthread_mutex_unlock -#define spinlock_t pthread_mutex_t -#define SPIN_LOCK_UNLOCKED PTHREAD_MUTEX_INITIALIZER - -#else - -/* Empty implementations, on the theory that system mode emulation -* is single-threaded. This means that these functions should only -* be used from code run in the TCG cpu thread, and cannot protect -* data structures which might also be accessed from the IO thread -* or from signal handlers. -*/ -typedef int spinlock_t ; -#define SPIN_LOCK_UNLOCKED 0 - -static inline void spin_lock (spinlock_t *lock) -{ -} - -static inline void spin_unlock (spinlock_t *lock) -{ -} - -#endif
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 41/43] tcg: comment on which functions have to be called with mmap_lock held
In reply to Paolo Bonzini--- translate-all.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)
translate-all.c +22 -7
@@ -171,11 +171,13 @@ void cpu_gen_init(void) }/* return non zero if the very first instruction is invalid so that -the virtual CPU can trigger an exception. - -'*gen_code_size_ptr' contains the size of the generated code (host -code). -*/ +* the virtual CPU can trigger an exception. +* +* '*gen_code_size_ptr' contains the size of the generated code (host +* code). +* +* Called with mmap_lock held for user-mode emulation. +*/ int cpu_gen_code (CPUArchState *env,TranslationBlock *tb,int *gen_code_size_ptr) {TCGContext *s = &tcg_ctx;
@@ -420,6 +422,9 @@ static void page_init(void)#endif } +/* If alloc=1: +* Called with mmap_lock held for user-mode emulation. +*/ static PageDesc *page_find_alloc (tb_page_addr_t index,int alloc) {PageDesc *pd;
@@ -1029,6 +1034,7 @@ static void build_page_bitmap(PageDesc *p) } } +/* Called with mmap_lock held for user mode emulation. */ TranslationBlock *tb_gen_code (CPUState *cpu,target_ulong pc,target_ulong cs_base,int flags,int cflags)
@@ -1076,6 +1082,8 @@ TranslationBlock *tb_gen_code(CPUState *cpu,* 'is_cpu_write_access' should be true if called from a real cpu write * access: the virtual CPU will exit the current TB if code is modified inside * this TB. +* +* Called with mmap_lock held for user-mode emulation */ void tb_invalidate_phys_range (tb_page_addr_t start,tb_page_addr_t end) {
@@ -1092,6 +1100,8 @@ void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end)* 'is_cpu_write_access' should be true if called from a real cpu write * access: the virtual CPU will exit the current TB if code is modified inside * this TB. +* +* Called with mmap_lock held for user-mode emulation */ void tb_invalidate_phys_page_range (tb_page_addr_t start,tb_page_addr_t end,int is_cpu_write_access)
@@ -1240,6 +1250,7 @@ void tb_invalidate_phys_page_fast(tb_page_addr_t start, int len) }#if !defined(CONFIG_SOFTMMU ) +/* Called with mmap_lock held. */ static void tb_invalidate_phys_page (tb_page_addr_t addr,uintptr_t pc,void *puc,bool locked)
@@ -1309,7 +1320,10 @@ static void tb_invalidate_phys_page(tb_page_addr_t addr, }#endif -/* add the tb in the target page and protect it if necessary */ +/* add the tb in the target page and protect it if necessary +* +* Called with mmap_lock held for user-mode emulation. +*/ static inline void tb_alloc_page (TranslationBlock *tb,unsigned int n,tb_page_addr_t page_addr) {
@@ -1365,7 +1379,8 @@ static inline void tb_alloc_page(TranslationBlock *tb, }/* add a new TB and link it to the physical page tables. phys_page2 is -(-1) to indicate that only one page contains the TB. */ +* (-1) to indicate that only one page contains the TB. +*/ static void tb_link_page (TranslationBlock *tb,tb_page_addr_t phys_pc,tb_page_addr_t phys_page2) {
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 38/43] replace spinlock by QemuMutex.
In reply to Paolo BonziniFrom: KONRAD Frederic <[email protected]>
spinlock is only used in two cases:
* cpu-exec.c: to protect TranslationBlock
* mem_helper.c: for lock helper in target-i386 (which seems broken).
It's a pthread_mutex_t in user-mode, so we can use QemuMutex directly, with an #ifdef. The #ifdef will be removed when multithreaded TCG will need the mutex as well.
Message-Id: <[email protected]>
--- cpu-exec.c | 14 +++----------- include/exec/exec-all.h | 4 ++-- linux-user/main.c | 6 +++--- target-i386/cpu.h | 3 +++ target-i386/mem_helper.c | 25 ++++++++++++++++++++++--- target-i386/translate.c | 2 ++ tcg/tcg.h | 4 ++++ translate-all.c | 34 ++++++++++++++++++++++++++++++++++ 8 files changed, 73 insertions(+), 19 deletions(-)
cpu-exec.c +3 -11
@@ -357,9 +357,6 @@ int cpu_exec(CPUState *cpu)uintptr_t next_tb;SyncClocks sc; -/* This must be volatile so it is not trashed by longjmp() */ -volatile bool have_tb_lock = false; -if (cpu->halted) {if (!cpu_has_work (cpu)) {return EXCP_HALTED ;
@@ -468,8 +465,7 @@ int cpu_exec(CPUState *cpu) cpu->exception_index =EXCP_INTERRUPT ;cpu_loop_exit (cpu); } -spin_lock (&tcg_ctx.tb_ctx.tb_lock); - have_tb_lock = true; +tb_lock (); tb =tb_find_fast (cpu);/* Note: we do it here to avoid a gcc bug on Mac OS X when doing it in tb_find_slow */
@@ -491,8 +487,7 @@ int cpu_exec(CPUState *cpu)tb_add_jump ((TranslationBlock *)(next_tb & ~TB_EXIT_MASK ), next_tb &TB_EXIT_MASK , tb); } - have_tb_lock = false; -spin_unlock (&tcg_ctx.tb_ctx.tb_lock); +tb_unlock ();if (likely (!cpu->exit_request)) {trace_exec_tb (tb, tb->pc); tc_ptr = tb->tc_ptr;
@@ -558,10 +553,7 @@ int cpu_exec(CPUState *cpu) x86_cpu =X86_CPU (cpu); env = &x86_cpu->env;#endif -if (have_tb_lock) { -spin_unlock (&tcg_ctx.tb_ctx.tb_lock); - have_tb_lock = false; - } +tb_lock_reset (); } }/* for(;;) */
include/exec/exec-all.h +2 -2
@@ -225,7 +225,7 @@ struct TranslationBlock {struct TranslationBlock *jmp_first; }; -#include "exec/spinlock.h" +#include "qemu/thread.h" typedef struct TBContext TBContext ;
@@ -235,7 +235,7 @@ struct TBContext {TranslationBlock *tb_phys_hash[CODE_GEN_PHYS_HASH_SIZE ];int nb_tbs;/* any access to the tbs or the page table must use this lock */ -spinlock_t tb_lock; +QemuMutex tb_lock;/* statistics */ int tb_flush_count;
linux-user/main.c +3 -3
@@ -105,7 +105,7 @@ static int pending_cpus;/* Make sure everything is in a consistent state for calling fork(). */ void fork_start (void ) { -pthread_mutex_lock (&tcg_ctx.tb_ctx.tb_lock); +qemu_mutex_lock (&tcg_ctx.tb_ctx.tb_lock);pthread_mutex_lock (&exclusive_lock);mmap_fork_start (); }
@@ -127,11 +127,11 @@ void fork_end(int child)pthread_mutex_init (&cpu_list_mutex,NULL );pthread_cond_init (&exclusive_cond,NULL );pthread_cond_init (&exclusive_resume,NULL ); -pthread_mutex_init (&tcg_ctx.tb_ctx.tb_lock,NULL ); +qemu_mutex_init (&tcg_ctx.tb_ctx.tb_lock);gdbserver_fork (thread_cpu); }else {pthread_mutex_unlock (&exclusive_lock); -pthread_mutex_unlock (&tcg_ctx.tb_ctx.tb_lock); +qemu_mutex_unlock (&tcg_ctx.tb_ctx.tb_lock); } }
target-i386/cpu.h +3 -0
@@ -1318,6 +1318,9 @@ static inline MemTxAttrs cpu_get_mem_attrs(CPUX86State *env)void cpu_set_mxcsr (CPUX86State *env,uint32_t val);void cpu_set_fpuc (CPUX86State *env,uint16_t val); +/* mem_helper.c */ +void helper_lock_init (void ); +/* svm_helper.c */ void cpu_svm_check_intercept_param (CPUX86State *env1,uint32_t type,uint64_t param);
target-i386/mem_helper.c +22 -3
@@ -23,18 +23,37 @@/* broken thread support */ -static spinlock_t global_cpu_lock =SPIN_LOCK_UNLOCKED ; +#if defined(CONFIG_USER_ONLY ) +QemuMutex global_cpu_lock;void helper_lock (void ) { -spin_lock (&global_cpu_lock); +qemu_mutex_lock (&global_cpu_lock); }void helper_unlock (void ) { -spin_unlock (&global_cpu_lock); +qemu_mutex_unlock (&global_cpu_lock); } +void helper_lock_init (void ) +{ +qemu_mutex_init (&global_cpu_lock); +} +#else +void helper_lock (void ) +{ +} + +void helper_unlock (void ) +{ +} + +void helper_lock_init (void ) +{ +} +#endif +void helper_cmpxchg8b (CPUX86State *env,target_ulong a0) {uint64_t d;
target-i386/translate.c +2 -0
@@ -7899,6 +7899,8 @@ void optimize_flags_init(void) offsetof(CPUX86State, regs[i]), reg_names[i]); } + +helper_lock_init (); }/* generate intermediate code in gen_opc_buf and gen_opparam_buf for
tcg/tcg.h +4 -0
@@ -595,6 +595,10 @@ void *tcg_malloc_internal(TCGContext *s, int size);void tcg_pool_reset (TCGContext *s);void tcg_pool_delete (TCGContext *s); +void tb_lock (void ); +void tb_unlock (void ); +void tb_lock_reset (void ); +static inline void *tcg_malloc (int size) {TCGContext *s = &tcg_ctx;
translate-all.c +34 -0
@@ -128,6 +128,39 @@ static void *l1_map[V_L1_SIZE];/* code generation context */ TCGContext tcg_ctx; +/* translation block context */ +#ifdef CONFIG_USER_ONLY +__threadint have_tb_lock; +#endif + +void tb_lock (void ) +{ +#ifdef CONFIG_USER_ONLY +assert (!have_tb_lock); +qemu_mutex_lock (&tcg_ctx.tb_ctx.tb_lock); + have_tb_lock++; +#endif +} + +void tb_unlock (void ) +{ +#ifdef CONFIG_USER_ONLY +assert (have_tb_lock); + have_tb_lock--; +qemu_mutex_unlock (&tcg_ctx.tb_ctx.tb_lock); +#endif +} + +void tb_lock_reset (void ) +{ +#ifdef CONFIG_USER_ONLY +if (have_tb_lock) { +qemu_mutex_unlock (&tcg_ctx.tb_ctx.tb_lock); + have_tb_lock =0 ; + } +#endif +} +static void tb_link_page (TranslationBlock *tb,tb_page_addr_t phys_pc,tb_page_addr_t phys_page2);static TranslationBlock *tb_find_pc (uintptr_t tc_ptr);
@@ -675,6 +708,7 @@ static inline void code_gen_alloc(size_t tb_size)CODE_GEN_AVG_BLOCK_SIZE ; tcg_ctx.tb_ctx.tbs =g_malloc (tcg_ctx.code_gen_max_blocks *sizeof (TranslationBlock)); +qemu_mutex_init (&tcg_ctx.tb_ctx.tb_lock); }/* Must be called before using the QEMU cpus. 'tb_size' is the size
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 40/43] tcg: add memory barriers in page_find_alloc accesses
In reply to Paolo Bonzinipage_find is reading the radix tree outside all locks, so it has to use the RCU primitives. It does not need RCU critical sections because the PageDescs are never removed, so there is never a need to wait for the end of code sections that use a PageDesc.
--- translate-all.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
translate-all.c +4 -4
@@ -431,26 +431,26 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)/* Level 2..N-1. */ for (i =V_L1_SHIFT /V_L2_BITS -1 ; i >0 ; i--) { -void **p = *lp; +void **p =atomic_rcu_read (lp);if (p ==NULL ) {if (!alloc) {return NULL ; } p = g_new0(void *, V_L2_SIZE); - *lp = p; +atomic_rcu_set (lp, p); } lp = p + ((index >> (i *V_L2_BITS )) & (V_L2_SIZE -1 )); } - pd = *lp; + pd =atomic_rcu_read (lp);if (pd ==NULL ) {if (!alloc) {return NULL ; } pd =g_new0 (PageDesc,V_L2_SIZE ); - *lp = pd; +atomic_rcu_set (lp, pd); }return pd + (index & (V_L2_SIZE -1 ));
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 42/43] exec: make mmap_lock/mmap_unlock globally available
In reply to Paolo BonziniThere is some iffy lock hierarchy going on in translate-all.c. To fix it, we need to take the mmap_lock in cpu-exec.c. Make the functions globally available.
--- bsd-user/qemu.h | 2 -- include/exec/exec-all.h | 6 ++++++ linux-user/qemu.h | 2 -- translate-all.c | 5 ----- 4 files changed, 6 insertions(+), 9 deletions(-)
bsd-user/qemu.h +0 -2
@@ -211,8 +211,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, abi_ulong new_addr);int target_msync (abi_ulong start,abi_ulong len,int flags);extern unsigned long last_brk; -void mmap_lock (void ); -void mmap_unlock (void );void cpu_list_lock (void );void cpu_list_unlock (void );#if defined(CONFIG_USE_NPTL )
include/exec/exec-all.h +6 -0
@@ -374,11 +374,17 @@ void tlb_fill(CPUState *cpu, target_ulong addr, int is_write, int mmu_idx,#endif #if defined(CONFIG_USER_ONLY ) +void mmap_lock (void ); +void mmap_unlock (void ); +static inline tb_page_addr_t get_page_addr_code (CPUArchState *env1,target_ulong addr) {return addr; }#else +static inline void mmap_lock (void ) {} +static inline void mmap_unlock (void ) {} +/* cputlb.c */ tb_page_addr_t get_page_addr_code (CPUArchState *env1,target_ulong addr);#endif
linux-user/qemu.h +0 -2
@@ -261,8 +261,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,int target_msync (abi_ulong start,abi_ulong len,int flags);extern unsigned long last_brk;extern abi_ulong mmap_next_start; -void mmap_lock (void ); -void mmap_unlock (void );abi_ulong mmap_find_vma (abi_ulong ,abi_ulong );void cpu_list_lock (void );void cpu_list_unlock (void );
translate-all.c +0 -5
@@ -466,11 +466,6 @@ static inline PageDesc *page_find(tb_page_addr_t index)return page_find_alloc (index,0 ); } -#if !defined(CONFIG_USER_ONLY ) -#define mmap_lock () do { } while (0) -#define mmap_unlock () do { } while (0) -#endif -#if defined(CONFIG_USER_ONLY )/* Currently it is not recommended to allocate big chunks of data in user mode. It will change when a dedicated libc will be used. */
Signature · 1 line
2.4.3
[Qemu-devel] [PULL 43/43] cpu-exec: fix lock hierarchy for user-mode emulation
In reply to Paolo Bonzinitb_lock has to be taken inside the mmap_lock (example:tb_invalidate_phys_range is called by target_mmap), but tb_link_page is taking the mmap_lock and it is called with the tb_lock held.
To fix this, take the mmap_lock in tb_find_slow, not in tb_link_page.
--- cpu-exec.c | 71 ++++++++++++++++++++++++++++++++++++++++++--------------- translate-all.c | 6 ++--- 2 files changed, 55 insertions(+), 22 deletions(-)
cpu-exec.c +53 -18
@@ -249,10 +249,10 @@ static void cpu_exec_nocache(CPUState *cpu, int max_cycles,tb_free (tb); } -static TranslationBlock *tb_find_slow (CPUState *cpu, -target_ulong pc, -target_ulong cs_base, -uint64_t flags) +static TranslationBlock *tb_find_physical (CPUState *cpu, +target_ulong pc, +target_ulong cs_base, +uint64_t flags) {CPUArchState *env = (CPUArchState *)cpu->env_ptr;TranslationBlock *tb, **ptb1;
@@ -269,8 +269,9 @@ static TranslationBlock *tb_find_slow(CPUState *cpu, ptb1 = &tcg_ctx.tb_ctx.tb_phys_hash[h];for (;;) { tb = *ptb1; -if (!tb) - goto not_found; +if (!tb) { +return NULL ; + } if (tb->pc == pc && tb->page_addr[0] == phys_page1 && tb->cs_base == cs_base &&
@@ -282,25 +283,59 @@ static TranslationBlock *tb_find_slow(CPUState *cpu, virt_page2 = (pc &TARGET_PAGE_MASK ) +TARGET_PAGE_SIZE ; phys_page2 =get_page_addr_code (env, virt_page2); -if (tb->page_addr[1 ] == phys_page2) - goto found; +if (tb->page_addr[1 ] == phys_page2) { +break ; + } }else { - goto found; +break ; } } ptb1 = &tb->phys_hash_next; } - not_found: -/* if no translated code available, then translate it now */ - tb =tb_gen_code (cpu, pc, cs_base, flags,0 ); - found: -/* Move the last found TB to the head of the list */ -if (likely (*ptb1)) { - *ptb1 = tb->phys_hash_next; - tb->phys_hash_next = tcg_ctx.tb_ctx.tb_phys_hash[h]; - tcg_ctx.tb_ctx.tb_phys_hash[h] = tb; +/* Move the TB to the head of the list */ + *ptb1 = tb->phys_hash_next; + tb->phys_hash_next = tcg_ctx.tb_ctx.tb_phys_hash[h]; + tcg_ctx.tb_ctx.tb_phys_hash[h] = tb; +return tb; +} + +static TranslationBlock *tb_find_slow (CPUState *cpu, +target_ulong pc, +target_ulong cs_base, +uint64_t flags) +{ +TranslationBlock *tb; + + tb =tb_find_physical (cpu, pc, cs_base, flags); +if (tb) { + goto found; + } + +#ifdef CONFIG_USER_ONLY +/* mmap_lock is needed by tb_gen_code, and mmap_lock must be +* taken outside tb_lock. Since we're momentarily dropping +* tb_lock, there's a chance that our desired tb has been +* translated. +*/ +tb_unlock (); +mmap_lock (); +tb_lock (); + tb =tb_find_physical (cpu, pc, cs_base, flags); +if (tb) { +mmap_unlock (); + goto found; } +#endif + +/* if no translated code available, then translate it now */ + tb =tb_gen_code (cpu, pc, cs_base, flags,0 ); + +#ifdef CONFIG_USER_ONLY +mmap_unlock (); +#endif + +found:/* we add the TB in the virtual pc hash table */ cpu->tb_jmp_cache[tb_jmp_cache_hash_func (pc)] = tb;return tb;
translate-all.c +2 -4
@@ -1375,6 +1375,8 @@ static inline void tb_alloc_page(TranslationBlock *tb,/* add a new TB and link it to the physical page tables. phys_page2 is * (-1) to indicate that only one page contains the TB. +* +* Called with mmap_lock held for user-mode emulation. */ static void tb_link_page (TranslationBlock *tb,tb_page_addr_t phys_pc,tb_page_addr_t phys_page2)
@@ -1382,9 +1384,6 @@ static void tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc,unsigned int h;TranslationBlock **ptb; -/* Grab the mmap lock to stop another thread invalidating this TB -before we are done. */ -mmap_lock ();/* add in the physical hash table */ h =tb_phys_hash_func (phys_pc); ptb = &tcg_ctx.tb_ctx.tb_phys_hash[h];
@@ -1414,7 +1413,6 @@ static void tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc,#ifdef DEBUG_TB_CHECK tb_page_check ();#endif -mmap_unlock (); }/* find the TB 'tb' such that tb[0].tc_ptr <= tc_ptr <
Signature · 1 line
2.4.3
Quoted 19 lines · Paolo Bonzini
The following changes since commit
090d0bfd948343d522cd20bc634105b5cfe2483b:s390: fix softmmu compilation (2015-08-28 16:05:24 +0100)
are available in the git repository at:
git://github.com/bonzini/qemu.gittags/for-upstreamfor you to fetch changes up to
9fd1a94888cd6a559f95c3596ec1ac28b74838c1:cpu-exec: fix lock hierarchy for user-mode emulation (2015-09-09 15:34:56 +0200)
----------------------------------------------------------------
* Support for jemalloc
*qemu_mutex_lock_iothread"No such process" fix
* cutils: qemu_strto* wrappers
*iohandler.csimplification
* Many other fixes and misc patches.
Quoted 6 lines
And some MTTCG work (with Emilio's fixes squashed):
* Signal-free TCG kick
* Removing spinlock in favor of QemuMutex
* User-mode emulation multi-threading fixes/docs----------------------------------------------------------------
Hi. I'm afraid 'make check' fails on OSX:
GTESTER tests/test-cutils
**
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:267:void test_qemu_strtol_empty(): assertion failed (err == 0): (-22 == 0)
GTester: last random seed: R02Sab816860e6f76841220ea943985e84ad **
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:282:void test_qemu_strtol_whitespace(): assertion failed (err == 0): (-22 == 0)
GTester: last random seed: R02Sf54276ef91a62d445403b86533fd5107 **
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:297:void test_qemu_strtol_invalid(): assertion failed (err == 0): (-22 == 0)
GTester: last random seed: R02Sc7bdef393984a4b2f2d4e4f27abeb15d **
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:481:void test_qemu_strtol_full_empty(): assertion failed (err == 0): (-22 == 0)
GTester: last random seed: R02S4997e0b4ab30ebccffa73bc1781328b2 **
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:558:void test_qemu_strtoul_empty(): assertion failed (err == 0): (-22 == 0)
GTester: last random seed: R02S698648c46f24ad5a964b9d17af6bc4e8 **
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:573:void test_qemu_strtoul_whitespace(): assertion failed (err == 0): (-22 ==
0)
GTester: last random seed: R02S1104b6fe236e206ba8fcf92362809c51 **
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:588:void test_qemu_strtoul_invalid(): assertion failed (err == 0): (-22 == 0)
GTester: last random seed: R02S174ff5853966067468f62d748943c2b7 **
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:768:void test_qemu_strtoul_full_empty(): assertion failed (err == 0): (-22 ==
0)
GTester: last random seed: R02S3ce87fc2cc5682c83e1e1d52621b4da5 **
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:843:void test_qemu_strtoll_empty(): assertion failed (err == 0): (-22 == 0)
GTester: last random seed: R02S63bf7c10814c2a2bd2d17434e0aa02cf **
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:858:void test_qemu_strtoll_whitespace(): assertion failed (err == 0): (-22 ==
0)
GTester: last random seed: R02S99d2c928c55415df4469f03edce5f1b3 **
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:873:void test_qemu_strtoll_invalid(): assertion failed (err == 0): (-22 == 0)
GTester: last random seed: R02S6c849584fb36a603f2261d0c215691bc ** ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:1053:void test_qemu_strtoll_full_empty(): assertion failed (err == 0): (-22 ==
0)
GTester: last random seed: R02S8685bb488d3e6869e053fe9bbf7e99d0 ** ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:1131:void test_qemu_strtoull_empty(): assertion failed (err == 0): (-22 == 0)
GTester: last random seed: R02Sd7cef3a007a563c9ffa77f7ed3a60ab6 ** ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:1146:void test_qemu_strtoull_whitespace(): assertion failed (err == 0): (-22 ==
0)
GTester: last random seed: R02Sad8be510623b0ddc095987c6bd300454 ** ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:1161:void test_qemu_strtoull_invalid(): assertion failed (err == 0): (-22 == 0)
GTester: last random seed: R02Sc012647d52c18c0917f45222650e10b0 ** ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:1341:void test_qemu_strtoull_full_empty(): assertion failed (err == 0): (-22 ==
0)
GTester: last random seed: R02Scf2405f86a11f03b0ec039a0af727ebd
make: *** [check-tests/test-cutils] Error 1
(errno 22 on OSX is EINVAL.)
These tests appear to be testing the behaviour of the system strtol on invalid sequences (for instance the first one is using the empty string ""). POSIX says
http://pubs.opengroup.org/onlinepubs/9699919799/functions/strtol.html
"If the subject sequence is empty or does not have the expected
form, no conversion is performed; the value of str shall be stored in the object pointed to by endptr, provided that endptr is not a null pointer."
and later
"These functions may fail if:
[EINVAL] No conversion could be performed."
That is, it's implementation defined whether this kind of failing conversion sets errno to EINVAL or leaves it alone, and it looks like the test cases are assuming the latter behaviour. I imagine they won't work on the BSDs either, though I haven't tested.
thanks
-- PMM
I will add a patch to detect the invalid sequences, as the OS X behavior seems preferable. Something like returning -EINVAL if result == 0 && (endptr == p || endptr[-1] != '0'). Nice to have the testcases.
And I thought I had tested this pull request really a lot. :-)
Paolo
-----Original Message-----
From: Peter Maydell [[email protected]]
Received: mercoledì, 09 set 2015, 20:42
To: Paolo Bonzini [[email protected]]
CC: QEMU Developers [[email protected]]
Subject: Re: [Qemu-devel] [PULL 00/43] First batch of misc changes for 2.5 (2015-09-09)
Quoted 19 lines · Paolo Bonzini
The following changes since commit
090d0bfd948343d522cd20bc634105b5cfe2483b:s390: fix softmmu compilation (2015-08-28 16:05:24 +0100)
are available in the git repository at:
git://github.com/bonzini/qemu.gittags/for-upstreamfor you to fetch changes up to
9fd1a94888cd6a559f95c3596ec1ac28b74838c1:cpu-exec: fix lock hierarchy for user-mode emulation (2015-09-09 15:34:56 +0200)
----------------------------------------------------------------
* Support for jemalloc
*qemu_mutex_lock_iothread"No such process" fix
* cutils: qemu_strto* wrappers
*iohandler.csimplification
* Many other fixes and misc patches.
Quoted 6 lines
And some MTTCG work (with Emilio's fixes squashed):
* Signal-free TCG kick
* Removing spinlock in favor of QemuMutex
* User-mode emulation multi-threading fixes/docs----------------------------------------------------------------
Hi. I'm afraid 'make check' fails on OSX:
GTESTER tests/test-cutils
**
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:267:void test_qemu_strtol_empty(): assertion failed (err == 0): (-22 == 0)
GTester: last random seed: R02Sab816860e6f76841220ea943985e84ad **
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:282:void test_qemu_strtol_whitespace(): assertion failed (err == 0): (-22 == 0)
GTester: last random seed: R02Sf54276ef91a62d445403b86533fd5107 **
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:297:void test_qemu_strtol_invalid(): assertion failed (err == 0): (-22 == 0)
GTester: last random seed: R02Sc7bdef393984a4b2f2d4e4f27abeb15d **
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:481:void test_qemu_strtol_full_empty(): assertion failed (err == 0): (-22 == 0)
GTester: last random seed: R02S4997e0b4ab30ebccffa73bc1781328b2 **
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:558:void test_qemu_strtoul_empty(): assertion failed (err == 0): (-22 == 0)
GTester: last random seed: R02S698648c46f24ad5a964b9d17af6bc4e8 **
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:573:void test_qemu_strtoul_whitespace(): assertion failed (err == 0): (-22 ==
0)
GTester: last random seed: R02S1104b6fe236e206ba8fcf92362809c51 **
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:588:void test_qemu_strtoul_invalid(): assertion failed (err == 0): (-22 == 0)
GTester: last random seed: R02S174ff5853966067468f62d748943c2b7 **
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:768:void test_qemu_strtoul_full_empty(): assertion failed (err == 0): (-22 ==
0)
GTester: last random seed: R02S3ce87fc2cc5682c83e1e1d52621b4da5 **
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:843:void test_qemu_strtoll_empty(): assertion failed (err == 0): (-22 == 0)
GTester: last random seed: R02S63bf7c10814c2a2bd2d17434e0aa02cf **
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:858:void test_qemu_strtoll_whitespace(): assertion failed (err == 0): (-22 ==
0)
GTester: last random seed: R02S99d2c928c55415df4469f03edce5f1b3 **
ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:873:void test_qemu_strtoll_invalid(): assertion failed (err == 0): (-22 == 0)
GTester: last random seed: R02S6c849584fb36a603f2261d0c215691bc ** ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:1053:void test_qemu_strtoll_full_empty(): assertion failed (err == 0): (-22 ==
0)
GTester: last random seed: R02S8685bb488d3e6869e053fe9bbf7e99d0 ** ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:1131:void test_qemu_strtoull_empty(): assertion failed (err == 0): (-22 == 0)
GTester: last random seed: R02Sd7cef3a007a563c9ffa77f7ed3a60ab6 ** ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:1146:void test_qemu_strtoull_whitespace(): assertion failed (err == 0): (-22 ==
0)
GTester: last random seed: R02Sad8be510623b0ddc095987c6bd300454 ** ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:1161:void test_qemu_strtoull_invalid(): assertion failed (err == 0): (-22 == 0)
GTester: last random seed: R02Sc012647d52c18c0917f45222650e10b0 ** ERROR:/Users/pm215/src/qemu/tests/test-cutils.c:1341:void test_qemu_strtoull_full_empty(): assertion failed (err == 0): (-22 ==
0)
GTester: last random seed: R02Scf2405f86a11f03b0ec039a0af727ebd
make: *** [check-tests/test-cutils] Error 1
(errno 22 on OSX is EINVAL.)
These tests appear to be testing the behaviour of the system strtol on invalid sequences (for instance the first one is using the empty string ""). POSIX says
http://pubs.opengroup.org/onlinepubs/9699919799/functions/strtol.html
"If the subject sequence is empty or does not have the expected
form, no conversion is performed; the value of str shall be stored in the object pointed to by endptr, provided that endptr is not a null pointer."
and later
"These functions may fail if:
[EINVAL] No conversion could be performed."
That is, it's implementation defined whether this kind of failing conversion sets errno to EINVAL or leaves it alone, and it looks like the test cases are assuming the latter behaviour. I imagine they won't work on the BSDs either, though I haven't tested.
thanks
-- PMM