Misc patches for 2017-01-12
Subsystems (6)
The following changes since commit 997eba28a3ed5400a80f754bf3a1c8044b75b9ff:
Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20180111' into staging (2018-01-11 14:34:41 +0000)
are available in the git repository at:
git://github.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to b1371ef477b9478454917a1804fcbaae147dc84f:
scripts/analyse-locks-simpletrace.py: script to analyse lock times (2018-01-12 12:23:51 +0100)
----------------------------------------------------------------
* QemuMutex tracing improvements (Alex)
* ram_addr_t optimization (David)
* SCSI fixes (Fam, Stefan, me)
* do {} while (0) fixes (Eric)
* KVM fix for PMU (Jan)
* memory leak fixes from ASAN (Marc-André)
* migration fix for HPET, icount, loadvm (Maria, Pavel)
* hflags fixes (me, Tao)
* block/iscsi uninitialized variable (Peter L.)
* full support for GMainContexts in character devices (Peter Xu)
* more boot-serial-test (Thomas)
* Memory leak fix (Zhecheng)
----------------------------------------------------------------
Alex Bennée (4):
scripts/qemu-gdb: add simple tcg lock status helper scripts/qemu-gdb/timers.py: new helper to dump timer state util/qemu-thread-*: add qemu_lock, locked and unlock trace events scripts/analyse-locks-simpletrace.py: script to analyse lock times
Dr. David Alan Gilbert (2):
find_ram_offset: Add comments and tracing
find_ram_offset: Align ram_addr_t allocation on long boundaries
Eric Blake (7):
net: Drop unusual use of do { } while (0);
mips: Tweak location of ';' in macros
chardev: Use goto/label instead of do/break/while(0)
chardev: Clean up previous patch indentation
tests: Avoid 'do/while(false); ' in vhost-user-bridge
maint: Fix macros with broken 'do/while(0); ' usage
checkpatch: Enforce proper do/while (0) style
Fam Zheng (1):
scsi-generic: Add share-rw option
Haozhong Zhang (1):
pc: fail memory hot-plug/unplug with -no-acpi and Q35 machine type
Jan Dakinevich (1):
i386/cpu/kvm: look at PMU's CPUID before setting MSRs
Marc-André Lureau (18):
build-sys: fix qemu-ga -pthread linking
build-sys: silence make by default or V=0
build-sys: add a rule to print a variable
build-sys: compile with -Og or -O1 when --enable-debug tests/docker: add some sanitizers to fedora dockerfile tests/docker: add test-debug
build-sys: add some sanitizers when --enable-debug if possible
tests: fix check-qobject leak
vl: fix direct firmware directories leak
readline: add a free function
tests: fix migration-test leak
crypto: fix stack-buffer-overflow error
qemu-config: fix leak in query-command-line-options
tests: fix qmp-test leak
ucontext: annotate coroutine stack for ASAN
tests: fix coroutine leak in /basic/entered
mips: fix potential fopen(NULL,...)
disas/s390: fix global-buffer-overflow
Maria Klimushenkova (1):
hpet: recover timer offset correctly
Paolo Bonzini (3):
scsi: fix scsi_convert_sense crash when in_buf == NULL && in_len == 0
target-i386: update hflags on Hypervisor.framework
cpus: unify qemu_*_wait_io_event
Pavel Dovgalyuk (2):
icount: fixed saving/restoring of icount warp timers
cpu: flush TB cache when loading VMState
Peter Lieven (1):
block/iscsi: fix initialization of iTask in iscsi_co_get_block_status
Peter Xu (3):
chardev: use backend chr context when watch for fe
chardev: let g_idle_add() be with chardev gcontext
chardev: introduce qemu_chr_timeout_add_ms()
Stefan Hajnoczi (1):
scsi-disk: release AioContext in unaligned WRITE SAME case
Tao Wu (3):
target/i386: move hflags update code to a function target/i386: hax: change to use x86_update_hflags target/i386: hax: Move x86_update_hflags.
Thomas Huth (3):
tests/boot-serial-test: Add tests for microblaze boards tests/boot-serial-test: Add a test for the moxiesim machine tests/boot-serial-test: Add support for the raspi2 machine
linzhecheng (1):
irq: fix memory leak
.travis.yml | 3 +- Makefile | 7 +- audio/paaudio.c | 4 +- block/iscsi.c | 3 +- chardev/char-fe.c | 2 +- chardev/char-pty.c | 64 ++++++++-------- chardev/char-serial.c | 75 +++++++++--------- chardev/char-socket.c | 28 ++++--- chardev/char.c | 18 +++++ configure | 38 +++++++++- cpus.c | 134 ++++++++++++++++++++------------- crypto/ivgen-essiv.c | 2 +- disas/s390.c | 16 ++-- docs/devel/build-system.txt | 13 ++++ exec.c | 40 ++++++++-- hw/adc/stm32f2xx_adc.c | 2 +- hw/block/m25p80.c | 2 +- hw/char/cadence_uart.c | 2 +- hw/char/stm32f2xx_usart.c | 2 +- hw/char/terminal3270.c | 28 ++++--- hw/display/cg3.c | 2 +- hw/display/dpcd.c | 2 +- hw/display/xlnx_dp.c | 2 +- hw/dma/pl330.c | 2 +- hw/dma/xlnx-zynq-devcfg.c | 2 +- hw/dma/xlnx_dpdma.c | 2 +- hw/i2c/i2c-ddc.c | 2 +- hw/i386/pc.c | 18 ++++- hw/misc/auxbus.c | 2 +- hw/misc/macio/mac_dbdma.c | 4 +- hw/misc/mmio_interface.c | 2 +- hw/misc/stm32f2xx_syscfg.c | 2 +- hw/misc/zynq_slcr.c | 2 +- hw/net/cadence_gem.c | 2 +- hw/net/pcnet.c | 20 ++--- hw/nvram/ds1225y.c | 4 +- hw/scsi/scsi-disk.c | 1 + hw/scsi/scsi-generic.c | 9 +++ hw/ssi/mss-spi.c | 2 +- hw/ssi/stm32f2xx_spi.c | 2 +- hw/ssi/xilinx_spi.c | 2 +- hw/ssi/xilinx_spips.c | 2 +- hw/timer/a9gtimer.c | 2 +- hw/timer/cadence_ttc.c | 2 +- hw/timer/hpet.c | 32 +++++++- hw/timer/mss-timer.c | 2 +- hw/timer/stm32f2xx_timer.c | 2 +- hw/tpm/tpm_passthrough.c | 2 +- hw/tpm/tpm_tis.c | 2 +- include/chardev/char.h | 3 + include/qemu/compiler.h | 4 + include/qemu/readline.h | 1 + include/qemu/thread.h | 39 +++++++++- migration/rdma.c | 2 +- monitor.c | 2 +- rules.mak | 2 + scripts/analyse-locks-simpletrace.py | 99 ++++++++++++++++++++++++ scripts/checkpatch.pl | 5 ++ scripts/qemu-gdb.py | 4 +- scripts/qemugdb/tcg.py | 46 +++++++++++ scripts/qemugdb/timers.py | 54 +++++++++++++ scsi/utils.c | 12 +-- target/arm/translate-a64.c | 2 +- target/i386/cpu.c | 42 +++++++++++ target/i386/cpu.h | 2 + target/i386/hax-all.c | 54 +------------ target/i386/hvf/x86hvf.c | 2 +- target/i386/kvm.c | 121 ++++++++++++----------------- target/mips/msa_helper.c | 34 +++++---- target/s390x/kvm.c | 2 +- tests/Makefile.include | 5 ++ tests/acpi-utils.h | 8 +- tests/boot-serial-test.c | 37 +++++++++ tests/check-qobject.c | 2 + tests/docker/dockerfiles/fedora.docker | 4 +- tests/docker/test-clang | 2 +- tests/docker/test-debug | 26 +++++++ tests/docker/test-mingw | 2 - tests/migration-test.c | 3 +- tests/qmp-test.c | 3 +- tests/tcg/test-mmap.c | 2 +- tests/test-coroutine.c | 1 - tests/vhost-user-bridge.c | 6 +- trace-events | 4 + ui/sdl_zoom_template.h | 8 +- util/coroutine-ucontext.c | 48 ++++++++++++ util/qemu-config.c | 3 +- util/qemu-thread-posix.c | 21 +++--- util/qemu-thread-win32.c | 20 ++--- util/readline.c | 18 ++++- util/trace-events | 7 +- vl.c | 9 ++- 92 files changed, 972 insertions(+), 414 deletions(-) create mode 100755 scripts/analyse-locks-simpletrace.py create mode 100644 scripts/qemugdb/tcg.py create mode 100644 scripts/qemugdb/timers.py create mode 100755 tests/docker/test-debug
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 01/52] scsi-generic: Add share-rw option
From: Fam Zheng <[email protected]>
Add the property to the device model, then parse it by calling blkconf_apply_backend_options().
In addition to blk_set_perm(), the called function also handles error options and wce. For error options we've already checked that the default values are used, for wce we don't have the option either so it is always the default (true). In other words there is no change of behavior in these regards.
Message-Id: <[email protected]>
--- hw/scsi/scsi-generic.c | 9 +++++++++ 1 file changed, 9 insertions(+)
hw/scsi/scsi-generic.c +9 -0
@@ -482,6 +482,7 @@ static void scsi_generic_realize(SCSIDevice *s, Error **errp)int rc;int sg_version;struct sg_scsi_id scsiid; +Error *local_err =NULL ;if (!s->conf.blk) {error_setg (errp,"drive property not set" );
@@ -515,6 +516,13 @@ static void scsi_generic_realize(SCSIDevice *s, Error **errp)error_setg (errp,"SG_GET_SCSI_ID ioctl failed" );return ; } +blkconf_apply_backend_options (&s->conf, +blk_is_read_only (s->conf.blk), + true, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + }/* define device state */ s->type = scsiid.scsi_type;
@@ -565,6 +573,7 @@ static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun,static Property scsi_generic_properties[] = {DEFINE_PROP_DRIVE ("drive" , SCSIDevice, conf.blk), +DEFINE_PROP_BOOL ("share-rw" , SCSIDevice, conf.share_rw, false),DEFINE_PROP_END_OF_LIST (), };
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 02/52] scsi: fix scsi_convert_sense crash when in_buf == NULL && in_len == 0
In reply to Paolo Bonziniscsi_disk_emulate_command passes in_buf == NULL when sent a REQUEST SENSE command. Check for in_len == 0 before dereferencing in_buf.
--- scsi/utils.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
scsi/utils.c +6 -6
@@ -322,18 +322,18 @@ int scsi_convert_sense(uint8_t *in_buf, int in_len,SCSISense sense;bool fixed_in; +if (in_len ==0 ) { +return scsi_build_sense_buf (buf, len,SENSE_CODE (NO_SENSE ), fixed); + } + fixed_in = (in_buf[0 ] &2 ) ==0 ; -if (in_len && fixed == fixed_in) { +if (fixed == fixed_in) {memcpy (buf, in_buf,MIN (len, in_len));return MIN (len, in_len); - } - -if (in_len ==0 ) { - sense =SENSE_CODE (NO_SENSE ); }else { sense =scsi_parse_sense_buf (in_buf, in_len); +return scsi_build_sense_buf (buf, len, sense, fixed); } -return scsi_build_sense_buf (buf, len, sense, fixed); }int scsi_sense_to_errno (int key,int asc,int ascq)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 03/52] pc: fail memory hot-plug/unplug with -no-acpi and Q35 machine type
In reply to Paolo BonziniFrom: Haozhong Zhang <[email protected]>
When -no-acpi option is used with Q35 machine type, no guest ACPI is built, but the ACPI device is still created, so only checking the presence of ACPI device before memory plug/unplug is not enough in such cases. Check whether ACPI is disabled globally in addition and fail memory plug/unplug if it's disabled.
Message-Id: <[email protected]>
--- hw/i386/pc.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
hw/i386/pc.c +14 -4
@@ -1695,9 +1695,14 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev, align =memory_region_get_alignment (mr); } -if (!pcms->acpi_dev) { +/* +* When -no-acpi is used with Q35 machine type, no ACPI is built, +* but pcms->acpi_dev is still created. Check !acpi_enabled in +* addition to cover this case. +*/ +if (!pcms->acpi_dev || !acpi_enabled) {error_setg (&local_err, -"memory hotplug is not enabled: missing acpi device" ); +"memory hotplug is not enabled: missing acpi device or acpi disabled" ); goto out; }
@@ -1729,9 +1734,14 @@ static void pc_dimm_unplug_request(HotplugHandler *hotplug_dev,Error *local_err =NULL ;PCMachineState *pcms =PC_MACHINE (hotplug_dev); -if (!pcms->acpi_dev) { +/* +* When -no-acpi is used with Q35 machine type, no ACPI is built, +* but pcms->acpi_dev is still created. Check !acpi_enabled in +* addition to cover this case. +*/ +if (!pcms->acpi_dev || !acpi_enabled) {error_setg (&local_err, -"memory hotplug is not enabled: missing acpi device" ); +"memory hotplug is not enabled: missing acpi device or acpi disabled" ); goto out; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 04/52] hpet: recover timer offset correctly
In reply to Paolo BonziniFrom: Maria Klimushenkova <[email protected]>
HPET saves its state by calculating the current time and recovers timer offset using this calculated value. But these calculations include divisions and multiplications. Therefore the timer state cannot be recovered precise enough.
This patch introduces saving of the original value of the offset to preserve the determinism of the timer.
Message-Id: <20171220100205.16625.84632.stgit@pasha-VirtualBox>
--- hw/timer/hpet.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)
hw/timer/hpet.c +30 -2
@@ -70,6 +70,7 @@ typedef struct HPETState {MemoryRegion iomem;uint64_t hpet_offset; +bool hpet_offset_loaded;qemu_irq irqs[HPET_NUM_IRQ_ROUTES ];uint32_t flags;uint8_t rtc_irq_level;
@@ -221,7 +222,9 @@ static int hpet_pre_save(void *opaque)HPETState *s = opaque;/* save current counter value */ - s->hpet_counter =hpet_get_ticks (s); +if (hpet_enabled (s)) { + s->hpet_counter =hpet_get_ticks (s); + }return 0 ; }
@@ -232,6 +235,8 @@ static int hpet_pre_load(void *opaque)/* version 1 only supports 3, later versions will load the actual value */ s->num_timers =HPET_MIN_TIMERS ; +/* for checking whether the hpet_offset section is loaded */ + s->hpet_offset_loaded = false;return 0 ; }
@@ -252,7 +257,10 @@ static int hpet_post_load(void *opaque, int version_id)HPETState *s = opaque;/* Recalculate the offset between the main counter and guest time */ - s->hpet_offset =ticks_to_ns (s->hpet_counter) -qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +if (!s->hpet_offset_loaded) { + s->hpet_offset =ticks_to_ns (s->hpet_counter) + -qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); + }/* Push number of timers into capability returned via HPET_ID */ s->capability &= ~HPET_ID_NUM_TIM_MASK ;
@@ -267,6 +275,14 @@ static int hpet_post_load(void *opaque, int version_id)return 0 ; } +static int hpet_offset_post_load (void *opaque,int version_id) +{ +HPETState *s = opaque; + + s->hpet_offset_loaded = true; +return 0 ; +} +static bool hpet_rtc_irq_level_needed (void *opaque) {HPETState *s = opaque;
@@ -285,6 +301,17 @@ static const VMStateDescription vmstate_hpet_rtc_irq_level = { } }; +static const VMStateDescription vmstate_hpet_offset = { + .name ="hpet/offset" , + .version_id =1 , + .minimum_version_id =1 , + .post_load = hpet_offset_post_load, + .fields = (VMStateField []) { +VMSTATE_UINT64 (hpet_offset, HPETState), +VMSTATE_END_OF_LIST () + } +}; +static const VMStateDescription vmstate_hpet_timer = { .name ="hpet_timer" , .version_id =1 ,
@@ -320,6 +347,7 @@ static const VMStateDescription vmstate_hpet = { }, .subsections = (const VMStateDescription*[]) { &vmstate_hpet_rtc_irq_level, + &vmstate_hpet_offset,NULL } };
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PULL 04/52] hpet: recover timer offset correctly
This revision is incorrect.
Here is the latest one: https://lists.gnu.org/archive/html/qemu-devel/2018-01/msg01751.html
Pavel Dovgalyuk
Quoted 112 lines
-----Original Message-----
From: Paolo Bonzini [mailto:[email protected]] On Behalf Of Paolo Bonzini
Sent: Friday, January 12, 2018 2:30 PM
To: [email protected]
Cc: Maria Klimushenkova; Pavel Dovgalyuk
Subject: [PULL 04/52] hpet: recover timer offset correctlyFrom: Maria Klimushenkova <[email protected]>
HPET saves its state by calculating the current time and recovers timer offset using this calculated value. But these calculations include divisions and multiplications. Therefore the timer state cannot be recovered precise enough.
This patch introduces saving of the original value of the offset to preserve the determinism of the timer.Signed-off-by Maria Klimushenkova <[email protected]>Signed-off-by Pavel Dovgalyuk <[email protected]>Message-Id: <20171220100205.16625.84632.stgit@pasha-VirtualBox>
Signed-off-by Paolo Bonzini <[email protected]>--- hw/timer/hpet.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)hw/timer/hpet.c +30
-3@@ -70,6 +70,7 @@ typedef struct HPETState {MemoryRegion iomem;uint64_t hpet_offset; +bool hpet_offset_loaded;qemu_irq irqs[HPET_NUM_IRQ_ROUTES ];uint32_t flags;uint8_t rtc_irq_level;@@ -221,7 +222,9 @@ static int hpet_pre_save(void *opaque)HPETState *s = opaque;/* save current counter value */ - s->hpet_counter =hpet_get_ticks (s); +if (hpet_enabled (s)) { + s->hpet_counter =hpet_get_ticks (s); + }return 0 ; }@@ -232,6 +235,8 @@ static int hpet_pre_load(void *opaque)/* version 1 only supports 3, later versions will load the actual value */ s->num_timers =HPET_MIN_TIMERS ; +/* for checking whether the hpet_offset section is loaded */ + s->hpet_offset_loaded = false;return 0 ; }@@ -252,7 +257,10 @@ static int hpet_post_load(void *opaque, int version_id)HPETState *s = opaque;/* Recalculate the offset between the main counter and guest time */ - s->hpet_offset =ticks_to_ns (s->hpet_counter) -qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +if (!s->hpet_offset_loaded) { + s->hpet_offset =ticks_to_ns (s->hpet_counter) + -qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); + }/* Push number of timers into capability returned via HPET_ID */ s->capability &= ~HPET_ID_NUM_TIM_MASK ;@@ -267,6 +275,14 @@ static int hpet_post_load(void *opaque, int version_id)return 0 ; } +static int hpet_offset_post_load (void *opaque,int version_id) +{ +HPETState *s = opaque; + + s->hpet_offset_loaded = true; +return 0 ; +} +static bool hpet_rtc_irq_level_needed (void *opaque) {HPETState *s = opaque;@@ -285,6 +301,17 @@ static const VMStateDescription vmstate_hpet_rtc_irq_level = { } }; +static const VMStateDescription vmstate_hpet_offset = { + .name ="hpet/offset" , + .version_id =1 , + .minimum_version_id =1 , + .post_load = hpet_offset_post_load, + .fields = (VMStateField []) { +VMSTATE_UINT64 (hpet_offset, HPETState), +VMSTATE_END_OF_LIST () + } +}; +static const VMStateDescription vmstate_hpet_timer = { .name ="hpet_timer" , .version_id =1 ,@@ -320,6 +347,7 @@ static const VMStateDescription vmstate_hpet = { }, .subsections = (const VMStateDescription*[]) { &vmstate_hpet_rtc_irq_level, + &vmstate_hpet_offset,NULL } }; --1.8.3.1
Re: [Qemu-devel] [PULL 04/52] hpet: recover timer offset correctly
Quoted 2 lines · Pavel Dovgalyuk
This revision is incorrect.
Here is the latest one: https://lists.gnu.org/archive/html/qemu-devel/2018-01/msg01751.html
_That_ version was posted on 10 Jan.
_This_ version was posted on 11 Jan. So this one is the latest one; the latest one is wrong too.
I wasted at least one hour this morning due to patches that didn't compile, please *please* be more careful, and send a follow-up for the problem with this version.
Paolo
Re: [Qemu-devel] [PULL 04/52] hpet: recover timer offset correctly
Quoted 9 lines
From: Paolo Bonzini [mailto:[email protected]]
Quoted 2 lines · Pavel Dovgalyuk
This revision is incorrect.
Here is the latest one: https://lists.gnu.org/archive/html/qemu-devel/2018-01/msg01751.html_That_ version was posted on 10 Jan.
_This_ version was posted on 11 Jan. So this one is the latest one; the latest one is wrong too.
That's strange.
I posted this version on 20 Dec: https://lists.gnu.org/archive/html/qemu-devel/2017-12/msg04172.html
Pavel Dovgalyuk
Re: [Qemu-devel] [PULL 04/52] hpet: recover timer offset correctly
Quoted 8 lines · Pavel Dovgalyuk
Quoted 6 lines
Quoted 2 lines
This revision is incorrect.
Here is the latest one: https://lists.gnu.org/archive/html/qemu-devel/2018-01/msg01751.html_That_ version was posted on 10 Jan.
_This_ version was posted on 11 Jan. So this one is the latest one; the latest one is wrong too.
That's strange.
I posted this version on 20 Dec: https://lists.gnu.org/archive/html/qemu-devel/2017-12/msg04172.html
Hmm, my mistake then...
Paolo
[Qemu-devel] [PULL 06/52] chardev: use backend chr context when watch for fe
In reply to Paolo BonziniFrom: Peter Xu <[email protected]>
In commit 6bbb6c0644 ("chardev: use per-dev context for io_add_watch_poll", 2017-09-22) all the chardev watches are converted to use per-chardev gcontext to support chardev to be run outside default main thread. However that's still missing one call from the frontend code. Touch that up.
Message-Id: <[email protected]>
--- chardev/char-fe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
chardev/char-fe.c +1 -1
@@ -356,7 +356,7 @@ guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition cond, }g_source_set_callback (src, (GSourceFunc )func, user_data,NULL ); - tag =g_source_attach (src,NULL ); + tag =g_source_attach (src, s->gcontext);g_source_unref (src);return tag;
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 05/52] i386/cpu/kvm: look at PMU's CPUID before setting MSRs
In reply to Paolo BonziniFrom: Jan Dakinevich <[email protected]>
Certain PMU-related MSRs are not supported for CPUs with PMU architecture below version 2. KVM rejects any access to them (see intel_is_valid_msr_idx routine in KVM), and QEMU fails on the following assertion:
kvm_put_msrs: Assertion `ret == cpu->kvm_msr_buf->nmsrs' failed.
QEMU also could fail if KVM exposes less fixed counters then 3. It could happen if host system run inside another hypervisor, which is tweaking PMU-related CPUID. To prevent possible fail, number of fixed counters now is obtained in the same way as number of GP counters.
Message-Id: <[email protected]>
--- target/i386/kvm.c | 80 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 32 deletions(-)
target/i386/kvm.c +48 -32
@@ -92,8 +92,9 @@ static bool has_msr_hv_stimer;static bool has_msr_hv_frequencies;static bool has_msr_xss; -static bool has_msr_architectural_pmu; -static uint32_t num_architectural_pmu_counters; +static uint32_t has_architectural_pmu_version; +static uint32_t num_architectural_pmu_gp_counters; +static uint32_t num_architectural_pmu_fixed_counters;static int has_xsave;static int has_xcrs;
@@ -872,19 +873,28 @@ int kvm_arch_init_vcpu(CPUState *cs) }if (limit >=0x0a ) { -uint32_t ver; +uint32_t eax, edx; -cpu_x86_cpuid (env,0x0a ,0 , &ver, &unused, &unused, &unused); -if ((ver &0xff ) >0 ) { - has_msr_architectural_pmu = true; - num_architectural_pmu_counters = (ver &0xff00 ) >>8 ; +cpu_x86_cpuid (env,0x0a ,0 , &eax, &unused, &unused, &edx); + + has_architectural_pmu_version = eax &0xff ; +if (has_architectural_pmu_version >0 ) { + num_architectural_pmu_gp_counters = (eax &0xff00 ) >>8 ;/* Shouldn't be more than 32, since that's the number of bits * available in EBX to tell us _which_ counters are available. * Play it safe. */ -if (num_architectural_pmu_counters >MAX_GP_COUNTERS ) { - num_architectural_pmu_counters =MAX_GP_COUNTERS ; +if (num_architectural_pmu_gp_counters >MAX_GP_COUNTERS ) { + num_architectural_pmu_gp_counters =MAX_GP_COUNTERS ; + } + +if (has_architectural_pmu_version >1 ) { + num_architectural_pmu_fixed_counters = edx &0x1f ; + +if (num_architectural_pmu_fixed_counters >MAX_FIXED_COUNTERS ) { + num_architectural_pmu_fixed_counters =MAX_FIXED_COUNTERS ; + } } } }
@@ -1650,32 +1660,36 @@ static int kvm_put_msrs(X86CPU *cpu, int level)if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_STEAL_TIME )) {kvm_msr_entry_add (cpu,MSR_KVM_STEAL_TIME , env->steal_time_msr); } -if (has_msr_architectural_pmu) { -/* Stop the counter. */ -kvm_msr_entry_add (cpu,MSR_CORE_PERF_FIXED_CTR_CTRL ,0 ); -kvm_msr_entry_add (cpu,MSR_CORE_PERF_GLOBAL_CTRL ,0 ); +if (has_architectural_pmu_version >0 ) { +if (has_architectural_pmu_version >1 ) { +/* Stop the counter. */ +kvm_msr_entry_add (cpu,MSR_CORE_PERF_FIXED_CTR_CTRL ,0 ); +kvm_msr_entry_add (cpu,MSR_CORE_PERF_GLOBAL_CTRL ,0 ); + }/* Set the counter values. */ -for (i =0 ; i <MAX_FIXED_COUNTERS ; i++) { +for (i =0 ; i < num_architectural_pmu_fixed_counters; i++) {kvm_msr_entry_add (cpu,MSR_CORE_PERF_FIXED_CTR0 + i, env->msr_fixed_counters[i]); } -for (i =0 ; i < num_architectural_pmu_counters; i++) { +for (i =0 ; i < num_architectural_pmu_gp_counters; i++) {kvm_msr_entry_add (cpu,MSR_P6_PERFCTR0 + i, env->msr_gp_counters[i]);kvm_msr_entry_add (cpu,MSR_P6_EVNTSEL0 + i, env->msr_gp_evtsel[i]); } -kvm_msr_entry_add (cpu,MSR_CORE_PERF_GLOBAL_STATUS , - env->msr_global_status); -kvm_msr_entry_add (cpu,MSR_CORE_PERF_GLOBAL_OVF_CTRL , - env->msr_global_ovf_ctrl); - -/* Now start the PMU. */ -kvm_msr_entry_add (cpu,MSR_CORE_PERF_FIXED_CTR_CTRL , - env->msr_fixed_ctr_ctrl); -kvm_msr_entry_add (cpu,MSR_CORE_PERF_GLOBAL_CTRL , - env->msr_global_ctrl); +if (has_architectural_pmu_version >1 ) { +kvm_msr_entry_add (cpu,MSR_CORE_PERF_GLOBAL_STATUS , + env->msr_global_status); +kvm_msr_entry_add (cpu,MSR_CORE_PERF_GLOBAL_OVF_CTRL , + env->msr_global_ovf_ctrl); + +/* Now start the PMU. */ +kvm_msr_entry_add (cpu,MSR_CORE_PERF_FIXED_CTR_CTRL , + env->msr_fixed_ctr_ctrl); +kvm_msr_entry_add (cpu,MSR_CORE_PERF_GLOBAL_CTRL , + env->msr_global_ctrl); + } }/* * Hyper-V partition-wide MSRs: to avoid clearing them on cpu hot-add,
@@ -2030,15 +2044,17 @@ static int kvm_get_msrs(X86CPU *cpu)if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_STEAL_TIME )) {kvm_msr_entry_add (cpu,MSR_KVM_STEAL_TIME ,0 ); } -if (has_msr_architectural_pmu) { -kvm_msr_entry_add (cpu,MSR_CORE_PERF_FIXED_CTR_CTRL ,0 ); -kvm_msr_entry_add (cpu,MSR_CORE_PERF_GLOBAL_CTRL ,0 ); -kvm_msr_entry_add (cpu,MSR_CORE_PERF_GLOBAL_STATUS ,0 ); -kvm_msr_entry_add (cpu,MSR_CORE_PERF_GLOBAL_OVF_CTRL ,0 ); -for (i =0 ; i <MAX_FIXED_COUNTERS ; i++) { +if (has_architectural_pmu_version >0 ) { +if (has_architectural_pmu_version >1 ) { +kvm_msr_entry_add (cpu,MSR_CORE_PERF_FIXED_CTR_CTRL ,0 ); +kvm_msr_entry_add (cpu,MSR_CORE_PERF_GLOBAL_CTRL ,0 ); +kvm_msr_entry_add (cpu,MSR_CORE_PERF_GLOBAL_STATUS ,0 ); +kvm_msr_entry_add (cpu,MSR_CORE_PERF_GLOBAL_OVF_CTRL ,0 ); + } +for (i =0 ; i < num_architectural_pmu_fixed_counters; i++) {kvm_msr_entry_add (cpu,MSR_CORE_PERF_FIXED_CTR0 + i,0 ); } -for (i =0 ; i < num_architectural_pmu_counters; i++) { +for (i =0 ; i < num_architectural_pmu_gp_counters; i++) {kvm_msr_entry_add (cpu,MSR_P6_PERFCTR0 + i,0 );kvm_msr_entry_add (cpu,MSR_P6_EVNTSEL0 + i,0 ); }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 07/52] chardev: let g_idle_add() be with chardev gcontext
In reply to Paolo BonziniFrom: Peter Xu <[email protected]>
The idle task will be attached to main gcontext even if the chardev backend is running in another gcontext. Fix the only caller by extending the g_idle_add() logic into the more powerful g_source_attach(). It's basically g_idle_add_full() implementation, but with the chardev's gcontext passed in.
Message-Id: <[email protected]>
--- chardev/char-pty.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
chardev/char-pty.c +13 -8
@@ -43,7 +43,7 @@ typedef struct {/* Protected by the Chardev chr_write_lock. */ int connected;guint timer_tag; -guint open_tag; +GSource *open_source; } PtyChardev;#define PTY_CHARDEV (obj) OBJECT_CHECK(PtyChardev, (obj), TYPE_CHARDEV_PTY)
@@ -58,7 +58,7 @@ static gboolean pty_chr_timer(gpointer opaque)qemu_mutex_lock (&chr->chr_write_lock); s->timer_tag =0 ; - s->open_tag =0 ; + s->open_source =NULL ;if (!s->connected) {/* Next poll ... */ pty_chr_update_read_handler_locked (chr);
@@ -183,7 +183,7 @@ static gboolean qemu_chr_be_generic_open_func(gpointer opaque)Chardev *chr =CHARDEV (opaque);PtyChardev *s =PTY_CHARDEV (opaque); - s->open_tag =0 ; + s->open_source =NULL ;qemu_chr_be_event (chr,CHR_EVENT_OPENED );return FALSE; }
@@ -194,9 +194,10 @@ static void pty_chr_state(Chardev *chr, int connected)PtyChardev *s =PTY_CHARDEV (chr);if (!connected) { -if (s->open_tag) { -g_source_remove (s->open_tag); - s->open_tag =0 ; +if (s->open_source) { +g_source_destroy (s->open_source); +g_source_unref (s->open_source); + s->open_source =NULL ; }remove_fd_in_watch (chr); s->connected =0 ;
@@ -210,9 +211,13 @@ static void pty_chr_state(Chardev *chr, int connected) s->timer_tag =0 ; }if (!s->connected) { -g_assert (s->open_tag ==0 ); +g_assert (s->open_source ==NULL ); + s->open_source =g_idle_source_new (); s->connected =1 ; - s->open_tag =g_idle_add (qemu_chr_be_generic_open_func, chr); +g_source_set_callback (s->open_source, + qemu_chr_be_generic_open_func, + chr,NULL ); +g_source_attach (s->open_source, chr->gcontext); }if (!chr->gsource) { chr->gsource = io_add_watch_poll(chr, s->ioc,
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 08/52] chardev: introduce qemu_chr_timeout_add_ms()
In reply to Paolo BonziniFrom: Peter Xu <[email protected]>
It's a replacement of g_timeout_add[_seconds]() for chardevs. Chardevs now can have dedicated gcontext, we should always bind chardev tasks onto those gcontext rather than the default main context. Since there are quite a few of g_timeout_add[_seconds]() callers, a new function qemu_chr_timeout_add_ms() is introduced.
One thing to mention is that, terminal3270 is still always running on main gcontext. However let's convert that as well since it's still part of chardev codes and in case one day we'll miss that when we move it out of main gcontext too.
Also, convert all the timers from GSource tags into GSource pointers. Gsource tag IDs and g_source_remove()s can only work with default gcontext, while now these GSources can logically be attached to other contexts. So let's use explicit g_source_destroy() plus another g_source_unref() to remove a timer.
Note: when in the timer handler, we don't need the g_source_destroy() any more since that'll be done automatically if the timer handler returns false (and that's what all the current handlers do).
Yet another note: in pty_chr_rearm_timer() we take special care for ms=1000. This patch merged the two cases into one.
Message-Id: <[email protected]>
--- chardev/char-pty.c | 43 +++++++++++++++++++------------------------ chardev/char-socket.c | 28 ++++++++++++++++++---------- chardev/char.c | 18 ++++++++++++++++++ hw/char/terminal3270.c | 28 ++++++++++++++++------------ include/chardev/char.h | 3 +++ 5 files changed, 74 insertions(+), 46 deletions(-)
chardev/char-pty.c +19 -24
@@ -42,7 +42,7 @@ typedef struct {/* Protected by the Chardev chr_write_lock. */ int connected; -guint timer_tag; +GSource *timer_src;GSource *open_source; } PtyChardev;
@@ -57,7 +57,8 @@ static gboolean pty_chr_timer(gpointer opaque)PtyChardev *s =PTY_CHARDEV (opaque);qemu_mutex_lock (&chr->chr_write_lock); - s->timer_tag =0 ; + s->timer_src =NULL ; +g_source_unref (s->open_source); s->open_source =NULL ;if (!s->connected) {/* Next poll ... */
@@ -67,25 +68,25 @@ static gboolean pty_chr_timer(gpointer opaque)return FALSE; } +static void pty_chr_timer_cancel (PtyChardev *s) +{ +if (s->timer_src) { +g_source_destroy (s->timer_src); +g_source_unref (s->timer_src); + s->timer_src =NULL ; + } +} +/* Called with chr_write_lock held. */ static void pty_chr_rearm_timer (Chardev *chr,int ms) {PtyChardev *s =PTY_CHARDEV (chr);char *name; -if (s->timer_tag) { -g_source_remove (s->timer_tag); - s->timer_tag =0 ; - } - -if (ms ==1000 ) { - name =g_strdup_printf ("pty-timer-secs-%s" , chr->label); - s->timer_tag =g_timeout_add_seconds (1 , pty_chr_timer, chr); - }else { - name =g_strdup_printf ("pty-timer-ms-%s" , chr->label); - s->timer_tag =g_timeout_add (ms, pty_chr_timer, chr); - } -g_source_set_name_by_id (s->timer_tag, name); +pty_chr_timer_cancel (s); + name =g_strdup_printf ("pty-timer-%s" , chr->label); + s->timer_src =qemu_chr_timeout_add_ms (chr, ms, pty_chr_timer, chr); +g_source_set_name (s->timer_src, name);g_free (name); }
@@ -206,10 +207,7 @@ static void pty_chr_state(Chardev *chr, int connected)* the virtual device linked to our pty. */ pty_chr_rearm_timer (chr,1000 ); }else { -if (s->timer_tag) { -g_source_remove (s->timer_tag); - s->timer_tag =0 ; - } +pty_chr_timer_cancel (s);if (!s->connected) {g_assert (s->open_source ==NULL ); s->open_source =g_idle_source_new ();
@@ -236,10 +234,7 @@ static void char_pty_finalize(Object *obj)qemu_mutex_lock (&chr->chr_write_lock);pty_chr_state (chr,0 );object_unref (OBJECT (s->ioc)); -if (s->timer_tag) { -g_source_remove (s->timer_tag); - s->timer_tag =0 ; - } +pty_chr_timer_cancel (s);qemu_mutex_unlock (&chr->chr_write_lock);qemu_chr_be_event (chr,CHR_EVENT_CLOSED ); }
@@ -272,7 +267,7 @@ static void char_pty_open(Chardev *chr, name =g_strdup_printf ("chardev-pty-%s" , chr->label);qio_channel_set_name (QIO_CHANNEL (s->ioc), name);g_free (name); - s->timer_tag =0 ; + s->timer_src =NULL ; *be_opened = false; }
chardev/char-socket.c +18 -10
@@ -57,7 +57,7 @@ typedef struct {bool is_telnet;bool is_tn3270; -guint reconnect_timer; +GSource *reconnect_timer;int64_t reconnect_time;bool connect_err_reported; } SocketChardev;
@@ -67,16 +67,27 @@ typedef struct {static gboolean socket_reconnect_timeout (gpointer opaque); +static void tcp_chr_reconn_timer_cancel (SocketChardev *s) +{ +if (s->reconnect_timer) { +g_source_destroy (s->reconnect_timer); +g_source_unref (s->reconnect_timer); + s->reconnect_timer =NULL ; + } +} +static void qemu_chr_socket_restart_timer (Chardev *chr) {SocketChardev *s =SOCKET_CHARDEV (chr);char *name;assert (s->connected ==0 ); - s->reconnect_timer =g_timeout_add_seconds (s->reconnect_time, - socket_reconnect_timeout, chr); name =g_strdup_printf ("chardev-socket-reconnect-%s" , chr->label); -g_source_set_name_by_id (s->reconnect_timer, name); + s->reconnect_timer =qemu_chr_timeout_add_ms (chr, + s->reconnect_time *1000 , + socket_reconnect_timeout, + chr); +g_source_set_name (s->reconnect_timer, name);g_free (name); }
@@ -781,11 +792,7 @@ static void char_socket_finalize(Object *obj)SocketChardev *s =SOCKET_CHARDEV (obj);tcp_chr_free_connection (chr); - -if (s->reconnect_timer) { -g_source_remove (s->reconnect_timer); - s->reconnect_timer =0 ; - } +tcp_chr_reconn_timer_cancel (s);qapi_free_SocketAddress (s->addr);if (s->listener) {qio_net_listener_set_client_func (s->listener,NULL ,NULL ,NULL );
@@ -824,7 +831,8 @@ static gboolean socket_reconnect_timeout(gpointer opaque)SocketChardev *s =SOCKET_CHARDEV (opaque);QIOChannelSocket *sioc; - s->reconnect_timer =0 ; +g_source_unref (s->reconnect_timer); + s->reconnect_timer =NULL ;if (chr->be_open) {return false;
chardev/char.c +18 -0
@@ -1084,6 +1084,24 @@ void qmp_chardev_send_break(const char *id, Error **errp)qemu_chr_be_event (chr,CHR_EVENT_BREAK ); } +/* +* Add a timeout callback for the chardev (in milliseconds), return +* the GSource object created. Please use this to add timeout hook for +* chardev instead of g_timeout_add() and g_timeout_add_seconds(), to +* make sure the gcontext that the task bound to is correct. +*/ +GSource *qemu_chr_timeout_add_ms (Chardev *chr,guint ms, +GSourceFunc func,void *private) +{ +GSource *source =g_timeout_source_new (ms); + +assert (func); +g_source_set_callback (source, func, private,NULL ); +g_source_attach (source, chr->gcontext); + +return source; +} +void qemu_chr_cleanup (void ) {object_unparent (get_chardevs_root ());
hw/char/terminal3270.c +16 -12
@@ -31,7 +31,7 @@ typedef struct Terminal3270 {uint8_t outv[OUTPUT_BUFFER_SIZE ];int in_len;bool handshake_done; -guint timer_tag; +GSource *timer_src; } Terminal3270;#define TYPE_TERMINAL_3270 "x-terminal3270"
@@ -45,6 +45,15 @@ static int terminal_can_read(void *opaque)return INPUT_BUFFER_SIZE - t->in_len; } +static void terminal_timer_cancel (Terminal3270 *t) +{ +if (t->timer_src) { +g_source_destroy (t->timer_src); +g_source_unref (t->timer_src); + t->timer_src =NULL ; + } +} +/* * Protocol handshake done, * signal guest by an unsolicited DE irq.
@@ -90,12 +99,9 @@ static void terminal_read(void *opaque, const uint8_t *buf, int size)assert (size <= (INPUT_BUFFER_SIZE - t->in_len)); -if (t->timer_tag) { -g_source_remove (t->timer_tag); - t->timer_tag =0 ; - } - t->timer_tag =g_timeout_add_seconds (600 , send_timing_mark_cb, t); - +terminal_timer_cancel (t); + t->timer_src =qemu_chr_timeout_add_ms (t->chr.chr,600 *1000 , + send_timing_mark_cb, t);memcpy (&t->inv[t->in_len], buf, size); t->in_len += size;if (t->in_len <2 ) {
@@ -145,10 +151,7 @@ static void chr_event(void *opaque, int event)/* Ensure the initial status correct, always reset them. */ t->in_len =0 ; t->handshake_done = false; -if (t->timer_tag) { -g_source_remove (t->timer_tag); - t->timer_tag =0 ; - } +terminal_timer_cancel (t);switch (event) {case CHR_EVENT_OPENED :
@@ -157,7 +160,8 @@ static void chr_event(void *opaque, int event)* char-socket.c. Once qemu receives the terminal-type of the * client, mark handshake done and trigger everything rolling again. */ - t->timer_tag =g_timeout_add_seconds (600 , send_timing_mark_cb, t); + t->timer_src =qemu_chr_timeout_add_ms (t->chr.chr,600 *1000 , + send_timing_mark_cb, t);break ;case CHR_EVENT_CLOSED : sch->curr_status.scsw.dstat =SCSW_DSTAT_DEVICE_END ;
include/chardev/char.h +3 -0
@@ -256,6 +256,9 @@ Chardev *qemu_chardev_new(const char *id, const char *typename,extern int term_escape_char; +GSource *qemu_chr_timeout_add_ms (Chardev *chr,guint ms, +GSourceFunc func,void *private); +/* console.c */ void qemu_chr_parse_vc (QemuOpts *opts,ChardevBackend *backend,Error **errp);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 09/52] build-sys: fix qemu-ga -pthread linking
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
When linking qemu-ga under some configuration (when gthread-2.0.pc doesn't have -pthread, as happening atm with meson build), you may have this linking issue:
/usr/bin/ld: libqemuutil.a(qemu-thread-posix.o): undefined reference to symbol 'pthread_setname_np@@GLIBC_2.12' /usr/lib64/libpthread.so.0: error adding symbols: DSO missing from command line
Make sure qemu-ga links with the pthread library, by adding correct flags to libs_qga.
This is really a QEMU bug, because it's QEMU code that's using pthread functions, and so we must explicitly link against pthreads. The bug was just masked by the fact that often some pkg-config or another for one of our dependencies will add -pthread to the link line anyway.
Message-Id: <[email protected]>
--- configure | 1 + 1 file changed, 1 insertion(+)
configure +1 -0
@@ -3464,6 +3464,7 @@ else done if test "$found" = "no"; then LIBS="$pthread_lib $LIBS" + libs_qga="$pthread_lib $libs_qga" fi PTHREAD_LIB="$pthread_lib" break
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 10/52] build-sys: silence make by default or V=0
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Move generic make flags in MAKEFLAGS (SUBDIR_MAKEFLAGS is more qemu specific).
Use --quiet to silence make 'is up to date' message.
Message-Id: <[email protected]>
--- Makefile | 2 +- rules.mak | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
Makefile +1 -1
@@ -277,7 +277,7 @@ else DOCS= endif -SUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory) BUILD_DIR=$(BUILD_DIR) +SUBDIR_MAKEFLAGS=BUILD_DIR=$(BUILD_DIR) SUBDIR_DEVICES_MAK=$(patsubst %, %/config-devices.mak, $(TARGET_DIRS)) SUBDIR_DEVICES_MAK_DEP=$(patsubst %, %-config-devices.mak.d, $(TARGET_DIRS))
rules.mak +2 -0
@@ -131,6 +131,8 @@ modules: # If called with only a single argument, will print nothing in quiet mode. quiet-command = $(if $(V),$1,$(if $(2),@printf " %-7s %s\n" $2 $3 && $1, @$1)) +MAKEFLAGS += $(if $(V),,--no-print-directory --quiet) + # cc-option # Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 11/52] build-sys: add a rule to print a variable
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
$ make print-CFLAGS CFLAGS=-fsanitize=address -Og -g
Trick from various sources:
https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
https://www.cmcrossroads.com/article/printing-value-makefile-variable
Message-Id: <[email protected]>
--- Makefile | 5 ++++- docs/devel/build-system.txt | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)
Makefile +4 -1
@@ -8,9 +8,12 @@ SRC_PATH=. UNCHECKED_GOALS := %clean TAGS cscope ctags dist \ html info pdf txt \ - help check-help \ + help check-help print-% \ docker docker-% vm-test vm-build-% +print-%: + @echo '$*=$($*)' + # All following code might depend on configuration variables ifneq ($(wildcard config-host.mak),) # Put the all: rule here so that config-host.mak can contain dependencies.
docs/devel/build-system.txt +13 -0
@@ -510,3 +510,16 @@ default-configs/$TARGET-NAME file as input. This is the entrypoint used when make recurses to build a single system or userspace emulator target. It is merely a symlink back to the Makefile.target in the top level. + + +Useful make targets +=================== + +- help + + Print a help message for the most common build targets. + +- print-VAR + + Print the value of the variable VAR. Useful for debugging the build + system.
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 12/52] build-sys: compile with -Og or -O1 when --enable-debug
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
When --enable-debug is turned on, configure doesn't set -O level, and uses default compiler -O0 level, which is slow.
Instead, use -Og if supported by the compiler (optimize debugging experience), or -O1 (keeps code somewhat debuggable and works around compiler bugs).
Unfortunately, gcc has many false-positive maybe-uninitialized errors with Og and O1 (f27 gcc 7.2.1 20170915):
/home/elmarco/src/qemu/hw/ipmi/isa_ipmi_kcs.c: In function ‘ipmi_kcs_ioport_read’:/home/elmarco/src/qemu/hw/ipmi/isa_ipmi_kcs.c:279:12: error: ‘ret’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
return ret;
^~~cc1: all warnings being treated as errors
make: *** [/home/elmarco/src/qemu/rules.mak:66: hw/ipmi/isa_ipmi_kcs.o] Error 1
make: *** Waiting for unfinished jobs..../home/elmarco/src/qemu/hw/ide/ahci.c: In function ‘ahci_populate_sglist’:/home/elmarco/src/qemu/hw/ide/ahci.c:903:58: error: ‘tbl_entry_size’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
if ((off_idx == -1) || (off_pos < 0) || (off_pos > tbl_entry_size)) {
~~~~~~~~~^~~~~~~~~~~~~~~~~cc1: all warnings being treated as errors
make: *** [/home/elmarco/src/qemu/rules.mak:66: hw/ide/ahci.o] Error 1/home/elmarco/src/qemu/hw/display/qxl.c: In function ‘qxl_add_memslot’:/home/elmarco/src/qemu/hw/display/qxl.c:1397:52: error: ‘pci_start’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
memslot.virt_end = virt_start + (guest_end - pci_start);
~~~~~~~~~~~~~^~~~~~~~~~~~
/home/elmarco/src/qemu/hw/display/qxl.c:1389:9: error: ‘pci_region’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
qxl_set_guest_bug(d, "%s: pci_region = %d", __func__, pci_region);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~cc1: all warnings being treated as errors
There seems to be a long list of related bugs in upstream GCC, some of them are being fixed very recently:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24639
For now, let's workaround it by using Wno-maybe-uninitialized (gcc-only).
Message-Id: <[email protected]>
--- configure | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
configure +13 -2
@@ -5194,8 +5194,19 @@ if test "$gcov" = "yes" ; then LDFLAGS="-fprofile-arcs -ftest-coverage $LDFLAGS" elif test "$fortify_source" = "yes" ; then CFLAGS="-O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $CFLAGS" -elif test "$debug" = "no"; then - CFLAGS="-O2 $CFLAGS" +elif test "$debug" = "yes"; then + if compile_prog "-Og" ""; then + CFLAGS="-Og $CFLAGS" + elif compile_prog "-O1" ""; then + CFLAGS="-O1 $CFLAGS" + fi + # Workaround GCC false-positive Wuninitialized bugs with Og or O1: + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24639 + if cc_has_warning_flag "-Wno-maybe-uninitialized"; then + CFLAGS="-Wno-maybe-uninitialized $CFLAGS" + fi +else + CFLAGS="-O2 $CFLAGS" fi ##########################################
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 13/52] tests/docker: add some sanitizers to fedora dockerfile
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Build fedora image with ASAN/UBSan support.
Message-Id: <[email protected]>
--- tests/docker/dockerfiles/fedora.docker | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tests/docker/dockerfiles/fedora.docker +2 -2
@@ -3,7 +3,7 @@ ENV PACKAGES \ ccache gettext git tar PyYAML sparse flex bison python2 bzip2 hostname \ glib2-devel pixman-devel zlib-devel SDL-devel libfdt-devel \ gcc gcc-c++ clang make perl which bc findutils libaio-devel \ - nettle-devel \ + nettle-devel libasan libubsan \ mingw32-pixman mingw32-glib2 mingw32-gmp mingw32-SDL mingw32-pkg-config \ mingw32-gtk2 mingw32-gtk3 mingw32-gnutls mingw32-nettle mingw32-libtasn1 \ mingw32-libjpeg-turbo mingw32-libpng mingw32-curl mingw32-libssh2 \
@@ -15,4 +15,4 @@ ENV PACKAGES \ RUN dnf install -y $PACKAGES RUN rpm -q $PACKAGES | sort > /packages.txt -ENV FEATURES mingw clang pyyaml +ENV FEATURES mingw clang pyyaml asan
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 14/52] tests/docker: add test-debug
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Add a new test with --enable-debug using clang/asan/ubsan, remove --enable-debug from test-clang & test-mingw.
Message-Id: <[email protected]>
--- tests/docker/test-clang | 2 +- tests/docker/test-debug | 26 ++++++++++++++++++++++++++ tests/docker/test-mingw | 2 -- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100755 tests/docker/test-debug
tests/docker/test-clang +1 -1
@@ -17,7 +17,7 @@ requires clang cd "$BUILD_DIR" -OPTS="--enable-debug --cxx=clang++ --cc=clang --host-cc=clang" +OPTS="--cxx=clang++ --cc=clang --host-cc=clang" # -fsanitize=undefined is broken on Fedora 23, skip it for now # See also: https://bugzilla.redhat.com/show_bug.cgi?id=1263834 #OPTS="$OPTS --extra-cflags=-fsanitize=undefined \
tests/docker/test-debug new file +26 -0
@@ -0,0 +1,26 @@ +#!/bin/bash -e +# +# Compile and check with clang & --enable-debug. +# +# Copyright (c) 2016-2018 Red Hat Inc. +# +# Authors: +# Fam Zheng <[email protected]> +# Marc-André Lureau <[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. + +. common.rc + +requires clang asan + +cd "$BUILD_DIR" + +OPTS="--cxx=clang++ --cc=clang --host-cc=clang" +OPTS="--enable-debug $OPTS" + +build_qemu $OPTS +make $MAKEFLAGS check +install_qemu
tests/docker/test-mingw +0 -2
@@ -22,7 +22,6 @@ for prefix in x86_64-w64-mingw32- i686-w64-mingw32-; do TARGET_LIST=${TARGET_LIST:-$DEF_TARGET_LIST} \ build_qemu --cross-prefix=$prefix \ --enable-trace-backends=simple \ - --enable-debug \ --enable-gnutls \ --enable-nettle \ --enable-curl \
@@ -35,4 +34,3 @@ for prefix in x86_64-w64-mingw32- i686-w64-mingw32-; do make clean done -
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 15/52] build-sys: add some sanitizers when --enable-debug if possible
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Enable ASAN/UBSan by default if the compiler supports it.
Typical slowdown introduced by AddressSanitizer is 2x. UBSan shouldn't have much impact on runtime cost.
Message-Id: <[email protected]>
--- configure | 7 +++++++ 1 file changed, 7 insertions(+)
configure +7 -0
@@ -5195,6 +5195,13 @@ if test "$gcov" = "yes" ; then elif test "$fortify_source" = "yes" ; then CFLAGS="-O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $CFLAGS" elif test "$debug" = "yes"; then + write_c_skeleton; + if compile_prog "-fsanitize=address" ""; then + CFLAGS="-fsanitize=address $CFLAGS" + fi + if compile_prog "-fsanitize=undefined" ""; then + CFLAGS="-fsanitize=undefined $CFLAGS" + fi if compile_prog "-Og" ""; then CFLAGS="-Og $CFLAGS" elif compile_prog "-O1" ""; then
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 16/52] tests: fix check-qobject leak
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
/public/qobject_is_equal_conversion: OK
=================================================================
==14396==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 56 byte(s) in 1 object(s) allocated from:
#0 0x7f07682c5850 in malloc (/lib64/libasan.so.4+0xde850)
#1 0x7f0767d12f0c in g_malloc ../glib/gmem.c:94
#2 0x7f0767d131cf in g_malloc_n ../glib/gmem.c:331
#3 0x562bd767371f in do_test_equality /home/elmarco/src/qq/tests/check-qobject.c:49
#4 0x562bd7674a35 in qobject_is_equal_dict_test /home/elmarco/src/qq/tests/check-qobject.c:267
#5 0x7f0767d37b04 in test_case_run ../glib/gtestutils.c:2237
#6 0x7f0767d37ec4 in g_test_run_suite_internal ../glib/gtestutils.c:2321
#7 0x7f0767d37f6d in g_test_run_suite_internal ../glib/gtestutils.c:2333
#8 0x7f0767d38184 in g_test_run_suite ../glib/gtestutils.c:2408
#9 0x7f0767d36e0d in g_test_run ../glib/gtestutils.c:1674
#10 0x562bd7674e75 in main /home/elmarco/src/qq/tests/check-qobject.c:327
#11 0x7f0766009039 in __libc_start_main (/lib64/libc.so.6+0x21039)Message-Id: <[email protected]>
--- tests/check-qobject.c | 2 ++ 1 file changed, 2 insertions(+)
tests/check-qobject.c +2 -0
@@ -59,6 +59,8 @@ static void do_test_equality(bool expected, int _, ...)g_assert (qobject_is_equal (args[i], args[j]) == expected); } } + +g_free (args); }#define check_equal (...) \
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 17/52] vl: fix direct firmware directories leak
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Note that data_dir[] will now point to allocated strings.
Fixes:
Direct leak of 16 byte(s) in 1 object(s) allocated from:
#0 0x7f1448181850 in malloc (/lib64/libasan.so.4+0xde850)
#1 0x7f1446ed8f0c in g_malloc ../glib/gmem.c:94
#2 0x7f1446ed91cf in g_malloc_n ../glib/gmem.c:331
#3 0x7f1446ef739a in g_strsplit ../glib/gstrfuncs.c:2364
#4 0x55cf276439d7 in main /home/elmarco/src/qq/vl.c:4311
#5 0x7f143dfad039 in __libc_start_main (/lib64/libc.so.6+0x21039)Message-Id: <[email protected]>
--- vl.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
vl.c +6 -3
@@ -2318,7 +2318,7 @@ static void qemu_add_data_dir(const char *path)return ;/* duplicate */ } } - data_dir[data_dir_idx++] = path; + data_dir[data_dir_idx++] =g_strdup (path); }static inline bool nonempty_str (const char *str)
@@ -3078,7 +3078,7 @@ int main(int argc, char **argv, char **envp)Error *main_loop_err =NULL ;Error *err =NULL ;bool list_data_dirs = false; -char **dirs; +char *dir, **dirs; typedef struct BlockdevOptions_queue { BlockdevOptions *bdo; Location loc;
@@ -4181,9 +4181,12 @@ int main(int argc, char **argv, char **envp)for (i =0 ; dirs[i] !=NULL ; i++) {qemu_add_data_dir (dirs[i]); } +g_strfreev (dirs);/* try to find datadir relative to the executable path */ -qemu_add_data_dir (os_find_datadir ()); + dir =os_find_datadir (); +qemu_add_data_dir (dir); +g_free (dir);/* add the datadir specified when building */ qemu_add_data_dir (CONFIG_QEMU_DATADIR );
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 18/52] readline: add a free function
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Fixes leaks such as:
Direct leak of 2 byte(s) in 1 object(s) allocated from:
#0 0x7eff58beb850 in malloc (/lib64/libasan.so.4+0xde850)
#1 0x7eff57942f0c in g_malloc ../glib/gmem.c:94
#2 0x7eff579431cf in g_malloc_n ../glib/gmem.c:331
#3 0x7eff5795f6eb in g_strdup ../glib/gstrfuncs.c:363
#4 0x55db720f1d46 in readline_hist_add /home/elmarco/src/qq/util/readline.c:258
#5 0x55db720f2d34 in readline_handle_byte /home/elmarco/src/qq/util/readline.c:387
#6 0x55db71539d00 in monitor_read /home/elmarco/src/qq/monitor.c:3896
#7 0x55db71f9be35 in qemu_chr_be_write_impl /home/elmarco/src/qq/chardev/char.c:167
#8 0x55db71f9bed3 in qemu_chr_be_write /home/elmarco/src/qq/chardev/char.c:179
#9 0x55db71fa013c in fd_chr_read /home/elmarco/src/qq/chardev/char-fd.c:66
#10 0x55db71fe18a8 in qio_channel_fd_source_dispatch /home/elmarco/src/qq/io/channel-watch.c:84
#11 0x7eff5793a90b in g_main_dispatch ../glib/gmain.c:3182
#12 0x7eff5793b7ac in g_main_context_dispatch ../glib/gmain.c:3847
#13 0x55db720af3bd in glib_pollfds_poll /home/elmarco/src/qq/util/main-loop.c:214
#14 0x55db720af505 in os_host_main_loop_wait /home/elmarco/src/qq/util/main-loop.c:261
#15 0x55db720af6d6 in main_loop_wait /home/elmarco/src/qq/util/main-loop.c:515
#16 0x55db7184e0de in main_loop /home/elmarco/src/qq/vl.c:1995
#17 0x55db7185e956 in main /home/elmarco/src/qq/vl.c:4914
#18 0x7eff4ea17039 in __libc_start_main (/lib64/libc.so.6+0x21039)(while at it, use g_new0(ReadLineState), it's a bit easier to read)
Message-Id: <[email protected]>
--- include/qemu/readline.h | 1 + monitor.c | 2 +- util/readline.c | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-)
include/qemu/readline.h +1 -0
@@ -59,5 +59,6 @@ ReadLineState *readline_init(ReadLinePrintfFunc *printf_func, ReadLineFlushFunc *flush_func, void *opaque, ReadLineCompletionFunc *completion_finder); +void readline_free (ReadLineState *rs);#endif /* READLINE_H */
monitor.c +1 -1
@@ -583,7 +583,7 @@ static void monitor_data_destroy(Monitor *mon)if (monitor_is_qmp (mon)) {json_message_parser_destroy (&mon->qmp.parser); } -g_free (mon->rs); +readline_free (mon->rs);QDECREF (mon->outbuf);qemu_mutex_destroy (&mon->out_lock); }
util/readline.c +17 -1
@@ -500,12 +500,28 @@ const char *readline_get_history(ReadLineState *rs, unsigned int index)return rs->history[index]; } +void readline_free (ReadLineState *rs) +{ +int i; + +if (!rs) { +return ; + } +for (i =0 ; i <READLINE_MAX_CMDS ; i++) { +g_free (rs->history[i]); + } +for (i =0 ; i <READLINE_MAX_COMPLETIONS ; i++) { +g_free (rs->completions[i]); + } +g_free (rs); +} +ReadLineState *readline_init (ReadLinePrintfFunc *printf_func,ReadLineFlushFunc *flush_func,void *opaque,ReadLineCompletionFunc *completion_finder) { -ReadLineState *rs =g_malloc0 (sizeof (*rs)); +ReadLineState *rs =g_new0 (ReadLineState,1 ); rs->hist_entry =-1 ; rs->opaque = opaque;
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 19/52] tests: fix migration-test leak
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Direct leak of 12 byte(s) in 2 object(s) allocated from:
#0 0x7f50d403c850 in malloc (/lib64/libasan.so.4+0xde850)
#1 0x7f50d1ddf98f in vasprintf (/lib64/libc.so.6+0x8098f)Message-Id: <[email protected]>
--- tests/migration-test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tests/migration-test.c +2 -1
@@ -358,13 +358,14 @@ static void migrate_check_parameter(QTestState *who, const char *parameter, const char *value) {QDict *rsp, *rsp_return; -const char *result; +char *result; rsp =wait_command (who,"{ 'execute': 'query-migrate-parameters' }" ); rsp_return =qdict_get_qdict (rsp,"return" ); result =g_strdup_printf ("%" PRId64,qdict_get_try_int (rsp_return, parameter,-1 )); g_assert_cmpstr(result, ==, value); +g_free (result);QDECREF (rsp); }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 20/52] crypto: fix stack-buffer-overflow error
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
ASAN complains about:
==8856==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffd8a1fe168 at pc 0x561136cb4451 bp 0x7ffd8a1fe130 sp 0x7ffd8a1fd8e0 READ of size 16 at 0x7ffd8a1fe168 thread T0
#0 0x561136cb4450 in __asan_memcpy (/home/elmarco/src/qq/build/tests/test-crypto-ivgen+0x110450)
#1 0x561136d2a6a7 in qcrypto_ivgen_essiv_calculate /home/elmarco/src/qq/crypto/ivgen-essiv.c:83:5
#2 0x561136d29af8 in qcrypto_ivgen_calculate /home/elmarco/src/qq/crypto/ivgen.c:72:12
#3 0x561136d07c8e in test_ivgen /home/elmarco/src/qq/tests/test-crypto-ivgen.c:148:5
#4 0x7f77772c3b04 in test_case_run /home/elmarco/src/gnome/glib/builddir/../glib/gtestutils.c:2237
#5 0x7f77772c3ec4 in g_test_run_suite_internal /home/elmarco/src/gnome/glib/builddir/../glib/gtestutils.c:2321
#6 0x7f77772c3f6d in g_test_run_suite_internal /home/elmarco/src/gnome/glib/builddir/../glib/gtestutils.c:2333
#7 0x7f77772c3f6d in g_test_run_suite_internal /home/elmarco/src/gnome/glib/builddir/../glib/gtestutils.c:2333
#8 0x7f77772c3f6d in g_test_run_suite_internal /home/elmarco/src/gnome/glib/builddir/../glib/gtestutils.c:2333
#9 0x7f77772c4184 in g_test_run_suite /home/elmarco/src/gnome/glib/builddir/../glib/gtestutils.c:2408
#10 0x7f77772c2e0d in g_test_run /home/elmarco/src/gnome/glib/builddir/../glib/gtestutils.c:1674
#11 0x561136d0799b in main /home/elmarco/src/qq/tests/test-crypto-ivgen.c:173:12
#12 0x7f77756e6039 in __libc_start_main (/lib64/libc.so.6+0x21039)
#13 0x561136c13d89 in _start (/home/elmarco/src/qq/build/tests/test-crypto-ivgen+0x6fd89)Address 0x7ffd8a1fe168 is located in stack of thread T0 at offset 40 in frame
#0 0x561136d2a40f in qcrypto_ivgen_essiv_calculate /home/elmarco/src/qq/crypto/ivgen-essiv.c:76
This frame has 1 object(s):
[32, 40) 'sector.addr' <== Memory access at offset 40 overflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow (/home/elmarco/src/qq/build/tests/test-crypto-ivgen+0x110450) in __asan_memcpy Shadow bytes around the buggy address:
0x100031437bd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x100031437be0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x100031437bf0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x100031437c00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x100031437c10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x100031437c20: 00 00 00 00 00 00 00 00 f1 f1 f1 f1 00[f3]f3 f3
0x100031437c30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x100031437c40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x100031437c50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x100031437c60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x100031437c70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb
It looks like the rest of the code copes with ndata being larger than sizeof(sector), so limit the memcpy() range.
Message-Id: <[email protected]>
--- crypto/ivgen-essiv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/ivgen-essiv.c +1 -1
@@ -79,7 +79,7 @@ static int qcrypto_ivgen_essiv_calculate(QCryptoIVGen *ivgen,uint8_t *data =g_new (uint8_t, ndata); sector =cpu_to_le64 (sector); -memcpy (data, (uint8_t *)§or, ndata); +memcpy (data, (uint8_t *)§or,MIN (sizeof (sector), ndata));if (sizeof (sector) < ndata) {memset (data +sizeof (sector),0 , ndata -sizeof (sector)); }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 21/52] qemu-config: fix leak in query-command-line-options
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Direct leak of 160 byte(s) in 4 object(s) allocated from:
#0 0x55ed7678cda8 in calloc (/home/elmarco/src/qq/build/x86_64-softmmu/qemu-system-x86_64+0x797da8)
#1 0x7f3f5e725f75 in g_malloc0 /home/elmarco/src/gnome/glib/builddir/../glib/gmem.c:124
#2 0x55ed778aa3a7 in query_option_descs /home/elmarco/src/qq/util/qemu-config.c:60:16
#3 0x55ed778aa307 in get_drive_infolist /home/elmarco/src/qq/util/qemu-config.c:140:19
#4 0x55ed778a9f40 in qmp_query_command_line_options /home/elmarco/src/qq/util/qemu-config.c:254:36
#5 0x55ed76d4868c in qmp_marshal_query_command_line_options /home/elmarco/src/qq/build/qmp-marshal.c:3078:14
#6 0x55ed77855dd5 in do_qmp_dispatch /home/elmarco/src/qq/qapi/qmp-dispatch.c:104:5
#7 0x55ed778558cc in qmp_dispatch /home/elmarco/src/qq/qapi/qmp-dispatch.c:131:11
#8 0x55ed768b592f in handle_qmp_command /home/elmarco/src/qq/monitor.c:3840:11
#9 0x55ed7786ccfe in json_message_process_token /home/elmarco/src/qq/qobject/json-streamer.c:105:5
#10 0x55ed778fe37c in json_lexer_feed_char /home/elmarco/src/qq/qobject/json-lexer.c:323:13
#11 0x55ed778fdde6 in json_lexer_feed /home/elmarco/src/qq/qobject/json-lexer.c:373:15
#12 0x55ed7786cd83 in json_message_parser_feed /home/elmarco/src/qq/qobject/json-streamer.c:124:12
#13 0x55ed768b559e in monitor_qmp_read /home/elmarco/src/qq/monitor.c:3882:5
#14 0x55ed77714f29 in qemu_chr_be_write_impl /home/elmarco/src/qq/chardev/char.c:167:9
#15 0x55ed77714fde in qemu_chr_be_write /home/elmarco/src/qq/chardev/char.c:179:9
#16 0x55ed7772ffad in tcp_chr_read /home/elmarco/src/qq/chardev/char-socket.c:440:13
#17 0x55ed7777113b in qio_channel_fd_source_dispatch /home/elmarco/src/qq/io/channel-watch.c:84:12
#18 0x7f3f5e71d90b in g_main_dispatch /home/elmarco/src/gnome/glib/builddir/../glib/gmain.c:3182
#19 0x7f3f5e71e7ac in g_main_context_dispatch /home/elmarco/src/gnome/glib/builddir/../glib/gmain.c:3847
#20 0x55ed77886ffc in glib_pollfds_poll /home/elmarco/src/qq/util/main-loop.c:214:9
#21 0x55ed778865fd in os_host_main_loop_wait /home/elmarco/src/qq/util/main-loop.c:261:5
#22 0x55ed77886222 in main_loop_wait /home/elmarco/src/qq/util/main-loop.c:515:11
#23 0x55ed76d2a4df in main_loop /home/elmarco/src/qq/vl.c:1995:9
#24 0x55ed76d1cb4a in main /home/elmarco/src/qq/vl.c:4914:5
#25 0x7f3f555f6039 in __libc_start_main (/lib64/libc.so.6+0x21039)Message-Id: <[email protected]>
--- util/qemu-config.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
util/qemu-config.c +2 -1
@@ -105,7 +105,8 @@ static void cleanup_infolist(CommandLineParameterInfoList *head)if (!strcmp (pre_entry->value->name, cur->next->value->name)) { del_entry = cur->next; cur->next = cur->next->next; -g_free (del_entry); + del_entry->next =NULL ; +qapi_free_CommandLineParameterInfoList (del_entry);break ; } pre_entry = pre_entry->next;
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 23/52] ucontext: annotate coroutine stack for ASAN
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
It helps ASAN to detect more leaks on coroutine stacks, as found in the following patch.
A similar work would need to be done for sigaltstack & windows fibers to have similar coverage. Since ucontext is preferred, I didn't bother checking the other coroutine implementations for now.
Message-Id: <[email protected]>
--- .travis.yml | 3 ++- configure | 15 +++++++++++++++ include/qemu/compiler.h | 4 ++++ util/coroutine-ucontext.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-)
.travis.yml +2 -1
@@ -13,12 +13,13 @@ addons: - libattr1-dev - libbrlapi-dev - libcap-ng-dev + - libgcc-6-dev - libgnutls-dev - libgtk-3-dev - libiscsi-dev - liblttng-ust-dev - - libnfs-dev - libncurses5-dev + - libnfs-dev - libnss3-dev - libpixman-1-dev - libpng12-dev
configure +15 -0
@@ -5186,6 +5186,13 @@ if compile_prog "" "" ; then fi ########################################## +# check for asan header +have_asan_iface_h=yes +if ! check_include "sanitizer/asan_interface.h" ; then + have_asan_iface_h=no +fi + +########################################## # End of CC checks # After here, no more $cc or $ld runs
@@ -5198,6 +5205,10 @@ elif test "$debug" = "yes"; then write_c_skeleton; if compile_prog "-fsanitize=address" ""; then CFLAGS="-fsanitize=address $CFLAGS" + if test "$have_asan_iface_h" = "no" ; then + print_error "ASAN build enabled, but ASAN header missing." \ + "Without code annotation, the report may be inferior." + fi fi if compile_prog "-fsanitize=undefined" ""; then CFLAGS="-fsanitize=undefined $CFLAGS"
@@ -6320,6 +6331,10 @@ if test "$have_utmpx" = "yes" ; then echo "HAVE_UTMPX=y" >> $config_host_mak fi +if test "$have_asan_iface_h" = "yes" ; then + echo "HAVE_ASAN_IFACE_H=y" >> $config_host_mak +fi + if test "$ivshmem" = "yes" ; then echo "CONFIG_IVSHMEM=y" >> $config_host_mak fi
include/qemu/compiler.h +4 -0
@@ -111,4 +111,8 @@#define GCC_FMT_ATTR (n, m)#endif +#ifndef __has_feature +#define __has_feature (x) 0/* compatibility with non-clang compilers */ +#endif +#endif /* COMPILER_H */
util/coroutine-ucontext.c +48 -0
101 lines not on this page · raw message
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 24/52] tests: fix coroutine leak in /basic/entered
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
The coroutine is not finished by the time the test ends, resulting in ASAN warning:
==7005==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 312 byte(s) in 1 object(s) allocated from:
#0 0x7fd35290fa38 in __interceptor_calloc (/lib64/libasan.so.4+0xdea38)
#1 0x7fd3506c5f75 in g_malloc0 ../glib/gmem.c:124
#2 0x55994af03e47 in qemu_coroutine_new /home/elmarco/src/qemu/util/coroutine-ucontext.c:144
#3 0x55994aefed99 in qemu_coroutine_create /home/elmarco/src/qemu/util/qemu-coroutine.c:76
#4 0x55994ac1eb50 in verify_entered_step_1 /home/elmarco/src/qemu/tests/test-coroutine.c:80
#5 0x55994af03c75 in coroutine_trampoline /home/elmarco/src/qemu/util/coroutine-ucontext.c:119
#6 0x7fd34ec02bef (/lib64/libc.so.6+0x50bef)Do not yield() to let the coroutine terminate.
Message-Id: <[email protected]>
--- tests/test-coroutine.c | 1 - 1 file changed, 1 deletion(-)
tests/test-coroutine.c +0 -1
@@ -67,7 +67,6 @@ static void coroutine_fn verify_entered_step_2(void *opaque)/* Once more to check it still works after yielding */ g_assert (qemu_coroutine_entered (caller));g_assert (qemu_coroutine_entered (qemu_coroutine_self ())); -qemu_coroutine_yield (); } static void coroutine_fn verify_entered_step_1(void *opaque)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 22/52] tests: fix qmp-test leak
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Direct leak of 913 byte(s) in 43 object(s) allocated from:
#0 0x55880a15df60 in __interceptor_malloc (/home/elmarco/src/qq/build/tests/qmp-test+0x110f60)
#1 0x7f3f20fd098f in _IO_vasprintf (/lib64/libc.so.6+0x8098f)Message-Id: <[email protected]>
--- tests/qmp-test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tests/qmp-test.c +2 -1
@@ -271,7 +271,7 @@ static void add_query_tests(QmpSchema *schema) {SchemaInfoList *tail;SchemaInfo *si, *arg_type, *ret_type; -const char *test_name; +char *test_name;/* Test the query-like commands */ for (tail = schema->list; tail; tail = tail->next) {
@@ -297,6 +297,7 @@ static void add_query_tests(QmpSchema *schema) test_name =g_strdup_printf ("qmp/%s" , si->name);qtest_add_data_func (test_name, si->name, test_query); +g_free (test_name); } }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 25/52] mips: fix potential fopen(NULL,...)
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Spotted thanks to ASAN.
Message-Id: <[email protected]>
--- hw/nvram/ds1225y.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/nvram/ds1225y.c +2 -2
@@ -80,7 +80,7 @@ static int nvram_post_load(void *opaque, int version_id) }/* Write back nvram contents */ - s->file =fopen (s->filename,"wb" ); + s->file = s->filename ?fopen (s->filename,"wb" ) :NULL ;if (s->file) {/* Write back contents, as 'wb' mode cleaned the file */ if (fwrite (s->contents, s->chip_size,1 , s->file) !=1 ) {
@@ -126,7 +126,7 @@ static int nvram_sysbus_initfn(SysBusDevice *dev)sysbus_init_mmio (dev, &s->iomem);/* Read current file */ - file =fopen (s->filename,"rb" ); + file = s->filename ?fopen (s->filename,"rb" ) :NULL ;if (file) {/* Read nvram contents */ if (fread (s->contents, s->chip_size,1 , file) !=1 ) {
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 26/52] disas/s390: fix global-buffer-overflow
In reply to Paolo BonziniFrom: Marc-André Lureau <[email protected]>
Spotted thanks to ASAN:
==25226==ERROR: AddressSanitizer: global-buffer-overflow on address 0x556715a1f120 at pc 0x556714b6f6b1 bp 0x7ffcdfac1360 sp 0x7ffcdfac1350 READ of size 1 at 0x556715a1f120 thread T0
#0 0x556714b6f6b0 in init_disasm /home/elmarco/src/qemu/disas/s390.c:219
#1 0x556714b6fa6a in print_insn_s390 /home/elmarco/src/qemu/disas/s390.c:294
#2 0x55671484d031 in monitor_disas /home/elmarco/src/qemu/disas.c:635
#3 0x556714862ec0 in memory_dump /home/elmarco/src/qemu/monitor.c:1324
#4 0x55671486342a in hmp_memory_dump /home/elmarco/src/qemu/monitor.c:1418
#5 0x5567148670be in handle_hmp_command /home/elmarco/src/qemu/monitor.c:3109
#6 0x5567148674ed in qmp_human_monitor_command /home/elmarco/src/qemu/monitor.c:613
#7 0x556714b00918 in qmp_marshal_human_monitor_command /home/elmarco/src/qemu/build/qmp-marshal.c:1704
#8 0x556715138a3e in do_qmp_dispatch /home/elmarco/src/qemu/qapi/qmp-dispatch.c:104
#9 0x556715138f83 in qmp_dispatch /home/elmarco/src/qemu/qapi/qmp-dispatch.c:131
#10 0x55671485cf88 in handle_qmp_command /home/elmarco/src/qemu/monitor.c:3839
#11 0x55671514e80b in json_message_process_token /home/elmarco/src/qemu/qobject/json-streamer.c:105
#12 0x5567151bf2dc in json_lexer_feed_char /home/elmarco/src/qemu/qobject/json-lexer.c:323
#13 0x5567151bf827 in json_lexer_feed /home/elmarco/src/qemu/qobject/json-lexer.c:373
#14 0x55671514ee62 in json_message_parser_feed /home/elmarco/src/qemu/qobject/json-streamer.c:124
#15 0x556714854b1f in monitor_qmp_read /home/elmarco/src/qemu/monitor.c:3881
#16 0x556715045440 in qemu_chr_be_write_impl /home/elmarco/src/qemu/chardev/char.c:172
#17 0x556715047184 in qemu_chr_be_write /home/elmarco/src/qemu/chardev/char.c:184
#18 0x55671505a8e6 in tcp_chr_read /home/elmarco/src/qemu/chardev/char-socket.c:440
#19 0x5567150943c3 in qio_channel_fd_source_dispatch /home/elmarco/src/qemu/io/channel-watch.c:84
#20 0x7fb90292b90b in g_main_dispatch ../glib/gmain.c:3182
#21 0x7fb90292c7ac in g_main_context_dispatch ../glib/gmain.c:3847
#22 0x556715162eca in glib_pollfds_poll /home/elmarco/src/qemu/util/main-loop.c:214
#23 0x556715163001 in os_host_main_loop_wait /home/elmarco/src/qemu/util/main-loop.c:261
#24 0x5567151631fa in main_loop_wait /home/elmarco/src/qemu/util/main-loop.c:515
#25 0x556714ad6d3b in main_loop /home/elmarco/src/qemu/vl.c:1950
#26 0x556714ade329 in main /home/elmarco/src/qemu/vl.c:4865
#27 0x7fb8fe5c9009 in __libc_start_main (/lib64/libc.so.6+0x21009)
#28 0x5567147af4d9 in _start (/home/elmarco/src/qemu/build/s390x-softmmu/qemu-system-s390x+0xf674d9)0x556715a1f120 is located 32 bytes to the left of global variable 'char_hci_type_info' defined in '/home/elmarco/src/qemu/hw/bt/hci-csr.c:493:23' (0x556715a1f140) of size 104 0x556715a1f120 is located 8 bytes to the right of global variable 's390_opcodes' defined in '/home/elmarco/src/qemu/disas/s390.c:860:33' (0x556715a15280) of size 40600
This fix is based on Andreas Arnez <[email protected]> upstream commit:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff;h=9ace48f3d7d80ce09c5df60cccb433470410b11b
2014-08-19 Andreas Arnez <[email protected]>
* s390-dis.c (init_disasm): Simplify initialization of
opc_index[]. This also fixes an access after the last element
of s390_opcodes[].Message-Id: <[email protected]>
--- disas/s390.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
disas/s390.c +6 -10
@@ -207,18 +207,14 @@ static int opc_index[256];static void init_disasm (struct disassemble_info *info) { -const struct s390_opcode *opcode; -const struct s390_opcode *opcode_end; +int i;memset (opc_index,0 ,sizeof (opc_index)); - opcode_end = s390_opcodes + s390_num_opcodes; -for (opcode = s390_opcodes; opcode < opcode_end; opcode++) - { - opc_index[(int ) opcode->opcode[0 ]] = opcode - s390_opcodes; -while ((opcode < opcode_end) && - (opcode[1 ].opcode[0 ] == opcode->opcode[0 ])) - opcode++; - } + +/* Reverse order, such that each opc_index ends up pointing to the +first matching entry instead of the last. */ +for (i = s390_num_opcodes; i--; ) + opc_index[s390_opcodes[i].opcode[0 ]] = i;#ifdef QEMU_DISABLE switch (info->mach)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 27/52] scsi-disk: release AioContext in unaligned WRITE SAME case
In reply to Paolo BonziniFrom: Stefan Hajnoczi <[email protected]>
scsi_write_same_complete() can retry the write if the request was unaligned. Make sure to release the AioContext when that code path is taken!
This patch fixes a hang when QEMU terminates after an unaligned WRITE SAME request has been processed with dataplane. The hang occurs because iothread_stop_all() cannot acquire the AioContext lock that was leaked by the IOThread in scsi_write_same_complete().
Message-Id: <[email protected]>
--- hw/scsi/scsi-disk.c | 1 + 1 file changed, 1 insertion(+)
hw/scsi/scsi-disk.c +1 -0
@@ -1755,6 +1755,7 @@ static void scsi_write_same_complete(void *opaque, int ret) data->sector <<BDRV_SECTOR_BITS , &data->qiov,0 , scsi_write_same_complete, data); +aio_context_release (blk_get_aio_context (s->qdev.conf.blk));return ; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 28/52] tests/boot-serial-test: Add tests for microblaze boards
In reply to Paolo BonziniFrom: Thomas Huth <[email protected]>
This adds two simple TCG + UART tests for the microblaze boards, one in big endian mode, and one in little endian mode.
Message-Id: <[email protected]>
--- tests/Makefile.include | 2 ++ tests/boot-serial-test.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+)
tests/Makefile.include +2 -0
@@ -300,6 +300,8 @@ check-qtest-alpha-y = tests/boot-serial-test$(EXESUF) check-qtest-m68k-y = tests/boot-serial-test$(EXESUF) +check-qtest-microblaze-y = tests/boot-serial-test$(EXESUF) + check-qtest-mips-y = tests/endianness-test$(EXESUF) check-qtest-mips64-y = tests/endianness-test$(EXESUF)
tests/boot-serial-test.c +20 -0
@@ -24,6 +24,22 @@ static const uint8_t kernel_mcf5208[] = {0x60 ,0xfa /* bra.s loop */ }; +static const uint8_t kernel_pls3adsp1800[] = { +0xb0 ,0x00 ,0x84 ,0x00 ,/* imm 0x8400 */ +0x30 ,0x60 ,0x00 ,0x04 ,/* addik r3,r0,4 */ +0x30 ,0x80 ,0x00 ,0x54 ,/* addik r4,r0,'T' */ +0xf0 ,0x83 ,0x00 ,0x00 ,/* sbi r4,r3,0 */ +0xb8 ,0x00 ,0xff ,0xfc /* bri -4 loop */ +}; + +static const uint8_t kernel_plml605[] = { +0xe0 ,0x83 ,0x00 ,0xb0 ,/* imm 0x83e0 */ +0x00 ,0x10 ,0x60 ,0x30 ,/* addik r3,r0,0x1000 */ +0x54 ,0x00 ,0x80 ,0x30 ,/* addik r4,r0,'T' */ +0x00 ,0x00 ,0x83 ,0xf0 ,/* sbi r4,r3,0 */ +0xfc ,0xff ,0x00 ,0xb8 /* bri -4 loop */ +}; + typedef struct testdef { const char *arch; /* Target architecture */ const char *machine; /* Name of the machine */
@@ -50,6 +66,10 @@ static testdef_t tests[] = { {"s390x" ,"s390-ccw-virtio" , "-nodefaults -device sclpconsole,chardev=serial0", "virtio device" }, { "m68k", "mcf5208evb", "", "TT", sizeof(kernel_mcf5208), kernel_mcf5208 }, + { "microblaze", "petalogix-s3adsp1800", "", "TT", + sizeof(kernel_pls3adsp1800), kernel_pls3adsp1800 }, + { "microblazeel", "petalogix-ml605", "", "TT", + sizeof(kernel_plml605), kernel_plml605 }, { NULL } };
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 29/52] tests/boot-serial-test: Add a test for the moxiesim machine
In reply to Paolo BonziniFrom: Thomas Huth <[email protected]>
Now that moxiesim supports the -bios parameter, we can check this machine in the boot-serial tester, too, by supplying a mini bios that only writes 'T' characters to the UART.
Message-Id: <[email protected]>
--- tests/Makefile.include | 2 ++ tests/boot-serial-test.c | 8 ++++++++ 2 files changed, 10 insertions(+)
tests/Makefile.include +2 -0
@@ -308,6 +308,8 @@ check-qtest-mips64-y = tests/endianness-test$(EXESUF) check-qtest-mips64el-y = tests/endianness-test$(EXESUF) +check-qtest-moxie-y = tests/boot-serial-test$(EXESUF) + check-qtest-ppc-y = tests/endianness-test$(EXESUF) check-qtest-ppc-y += tests/boot-order-test$(EXESUF) check-qtest-ppc-y += tests/prom-env-test$(EXESUF)
tests/boot-serial-test.c +8 -0
@@ -40,6 +40,13 @@ static const uint8_t kernel_plml605[] = {0xfc ,0xff ,0x00 ,0xb8 /* bri -4 loop */ }; +static const uint8_t bios_moxiesim[] = { +0x20 ,0x10 ,0x00 ,0x00 ,0x03 ,0xf8 ,/* ldi.s r1,0x3f8 */ +0x1b ,0x20 ,0x00 ,0x00 ,0x00 ,0x54 ,/* ldi.b r2,'T' */ +0x1e ,0x12 ,/* st.b r1,r2 */ +0x1a ,0x00 ,0x00 ,0x00 ,0x10 ,0x00 /* jmpa 0x1000 */ +}; + typedef struct testdef { const char *arch; /* Target architecture */ const char *machine; /* Name of the machine */
@@ -70,6 +77,7 @@ static testdef_t tests[] = { sizeof(kernel_pls3adsp1800), kernel_pls3adsp1800 }, {"microblazeel" ,"petalogix-ml605" ,"" ,"TT" , sizeof(kernel_plml605), kernel_plml605 }, + { "moxie", "moxiesim", "", "TT", sizeof(bios_moxiesim), 0, bios_moxiesim }, { NULL } };
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 30/52] tests/boot-serial-test: Add support for the raspi2 machine
In reply to Paolo BonziniFrom: Thomas Huth <[email protected]>
The raspi2 machine supports loading firmware images, so we can easily load a small test sequence as raw binary blob here to test the UART.
Message-Id: <[email protected]>
--- tests/Makefile.include | 1 + tests/boot-serial-test.c | 9 +++++++++ 2 files changed, 10 insertions(+)
tests/Makefile.include +1 -0
@@ -362,6 +362,7 @@ check-qtest-arm-y += tests/virtio-blk-test$(EXESUF) gcov-files-arm-y += arm-softmmu/hw/block/virtio-blk.c check-qtest-arm-y += tests/test-arm-mptimer$(EXESUF) gcov-files-arm-y += hw/timer/arm_mptimer.c +check-qtest-arm-y += tests/boot-serial-test$(EXESUF) check-qtest-aarch64-y = tests/numa-test$(EXESUF)
tests/boot-serial-test.c +9 -0
@@ -47,6 +47,14 @@ static const uint8_t bios_moxiesim[] = {0x1a ,0x00 ,0x00 ,0x00 ,0x10 ,0x00 /* jmpa 0x1000 */ }; +static const uint8_t bios_raspi2[] = { +0x08 ,0x30 ,0x9f ,0xe5 ,/* ldr r3,[pc,#8] Get base */ +0x54 ,0x20 ,0xa0 ,0xe3 ,/* mov r2,#'T' */ +0x00 ,0x20 ,0xc3 ,0xe5 ,/* strb r2,[r3] */ +0xfb ,0xff ,0xff ,0xea ,/* b loop */ +0x00 ,0x10 ,0x20 ,0x3f ,/* 0x3f201000 = UART0 base addr */ +}; + typedef struct testdef { const char *arch; /* Target architecture */ const char *machine; /* Name of the machine */
@@ -78,6 +86,7 @@ static testdef_t tests[] = { {"microblazeel" ,"petalogix-ml605" ,"" ,"TT" , sizeof(kernel_plml605), kernel_plml605 }, { "moxie", "moxiesim", "", "TT", sizeof(bios_moxiesim), 0, bios_moxiesim }, + { "arm", "raspi2", "", "TT", sizeof(bios_raspi2), 0, bios_raspi2 }, { NULL } };
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 31/52] target/i386: move hflags update code to a function
In reply to Paolo BonziniFrom: Tao Wu <[email protected]>
We will share the same code for hax/kvm.
Message-Id: <[email protected]>
--- target/i386/cpu.c | 42 ++++++++++++++++++++++++++++++++++++++++++ target/i386/cpu.h | 2 ++ target/i386/kvm.c | 40 +--------------------------------------- 3 files changed, 45 insertions(+), 39 deletions(-)
target/i386/cpu.c +42 -0
@@ -4147,6 +4147,48 @@ static void x86_disas_set_info(CPUState *cs, disassemble_info *info) info->cap_insn_split =8 ; } +void x86_update_hflags (CPUX86State *env) +{ +uint32_t hflags; +#define HFLAG_COPY_MASK \ + ~( HF_CPL_MASK | HF_PE_MASK | HF_MP_MASK | HF_EM_MASK | \ + HF_TS_MASK | HF_TF_MASK | HF_VM_MASK | HF_IOPL_MASK | \ + HF_OSFXSR_MASK | HF_LMA_MASK | HF_CS32_MASK | \ + HF_SS32_MASK | HF_CS64_MASK | HF_ADDSEG_MASK) + + hflags = env->hflags &HFLAG_COPY_MASK ; + hflags |= (env->segs[R_SS ].flags >>DESC_DPL_SHIFT ) &HF_CPL_MASK ; + hflags |= (env->cr[0 ] &CR0_PE_MASK ) << (HF_PE_SHIFT -CR0_PE_SHIFT ); + hflags |= (env->cr[0 ] << (HF_MP_SHIFT -CR0_MP_SHIFT )) & + (HF_MP_MASK |HF_EM_MASK |HF_TS_MASK ); + hflags |= (env->eflags & (HF_TF_MASK |HF_VM_MASK |HF_IOPL_MASK )); + +if (env->cr[4 ] &CR4_OSFXSR_MASK ) { + hflags |=HF_OSFXSR_MASK ; + } + +if (env->efer &MSR_EFER_LMA ) { + hflags |=HF_LMA_MASK ; + } + +if ((hflags &HF_LMA_MASK ) && (env->segs[R_CS ].flags &DESC_L_MASK )) { + hflags |=HF_CS32_MASK |HF_SS32_MASK |HF_CS64_MASK ; + }else { + hflags |= (env->segs[R_CS ].flags &DESC_B_MASK ) >> + (DESC_B_SHIFT -HF_CS32_SHIFT ); + hflags |= (env->segs[R_SS ].flags &DESC_B_MASK ) >> + (DESC_B_SHIFT -HF_SS32_SHIFT ); +if (!(env->cr[0 ] &CR0_PE_MASK ) || (env->eflags &VM_MASK ) || + !(hflags &HF_CS32_MASK )) { + hflags |=HF_ADDSEG_MASK ; + }else { + hflags |= ((env->segs[R_DS ].base | env->segs[R_ES ].base | + env->segs[R_SS ].base) !=0 ) <<HF_ADDSEG_SHIFT ; + } + } + env->hflags = hflags; +} +static Property x86_cpu_properties[] = { #ifdef CONFIG_USER_ONLY /* apic_id = 0 by default for *-user, see commit 9886e834 */
target/i386/cpu.h +2 -0
@@ -1778,4 +1778,6 @@ bool cpu_is_bsp(X86CPU *cpu);void x86_cpu_xrstor_all_areas (X86CPU *cpu,const X86XSaveArea *buf);void x86_cpu_xsave_all_areas (X86CPU *cpu,X86XSaveArea *buf); +void x86_update_hflags (CPUX86State * env); +#endif /* I386_CPU_H */
target/i386/kvm.c +1 -39
@@ -1891,7 +1891,6 @@ static int kvm_get_sregs(X86CPU *cpu) {CPUX86State *env = &cpu->env;struct kvm_sregs sregs; -uint32_t hflags;int bit, i, ret; ret =kvm_vcpu_ioctl (CPU (cpu),KVM_GET_SREGS , &sregs);
@@ -1933,44 +1932,7 @@ static int kvm_get_sregs(X86CPU *cpu) env->efer = sregs.efer;/* changes to apic base and cr8/tpr are read back via kvm_arch_post_run */ - -#define HFLAG_COPY_MASK \ - ~( HF_CPL_MASK | HF_PE_MASK | HF_MP_MASK | HF_EM_MASK | \ - HF_TS_MASK | HF_TF_MASK | HF_VM_MASK | HF_IOPL_MASK | \ - HF_OSFXSR_MASK | HF_LMA_MASK | HF_CS32_MASK | \ - HF_SS32_MASK | HF_CS64_MASK | HF_ADDSEG_MASK) - - hflags = env->hflags &HFLAG_COPY_MASK ; - hflags |= (env->segs[R_SS ].flags >>DESC_DPL_SHIFT ) &HF_CPL_MASK ; - hflags |= (env->cr[0 ] &CR0_PE_MASK ) << (HF_PE_SHIFT -CR0_PE_SHIFT ); - hflags |= (env->cr[0 ] << (HF_MP_SHIFT -CR0_MP_SHIFT )) & - (HF_MP_MASK |HF_EM_MASK |HF_TS_MASK ); - hflags |= (env->eflags & (HF_TF_MASK |HF_VM_MASK |HF_IOPL_MASK )); - -if (env->cr[4 ] &CR4_OSFXSR_MASK ) { - hflags |=HF_OSFXSR_MASK ; - } - -if (env->efer &MSR_EFER_LMA ) { - hflags |=HF_LMA_MASK ; - } - -if ((hflags &HF_LMA_MASK ) && (env->segs[R_CS ].flags &DESC_L_MASK )) { - hflags |=HF_CS32_MASK |HF_SS32_MASK |HF_CS64_MASK ; - }else { - hflags |= (env->segs[R_CS ].flags &DESC_B_MASK ) >> - (DESC_B_SHIFT -HF_CS32_SHIFT ); - hflags |= (env->segs[R_SS ].flags &DESC_B_MASK ) >> - (DESC_B_SHIFT -HF_SS32_SHIFT ); -if (!(env->cr[0 ] &CR0_PE_MASK ) || (env->eflags &VM_MASK ) || - !(hflags &HF_CS32_MASK )) { - hflags |=HF_ADDSEG_MASK ; - }else { - hflags |= ((env->segs[R_DS ].base | env->segs[R_ES ].base | - env->segs[R_SS ].base) !=0 ) <<HF_ADDSEG_SHIFT ; - } - } - env->hflags = hflags; +x86_update_hflags (env);return 0 ; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 32/52] target/i386: hax: change to use x86_update_hflags
In reply to Paolo BonziniFrom: Tao Wu <[email protected]>
Change to use x86_update_hflags instead of keeping another copy at hax side. This also fix bug like HF_CPL_MASK should be SS.DPL, not CS.DPL.
Message-Id: <[email protected]>
--- target/i386/hax-all.c | 52 +-------------------------------------------------- 1 file changed, 1 insertion(+), 51 deletions(-)
target/i386/hax-all.c +1 -51
@@ -782,56 +782,6 @@ static int hax_set_segments(CPUArchState *env, struct vcpu_state_t *sregs)return 0 ; } -/* -* After get the state from the kernel module, some -* qemu emulator state need be updated also -*/ -static int hax_setup_qemu_emulator (CPUArchState *env) -{ - -#define HFLAG_COPY_MASK (~( \ - HF_CPL_MASK | HF_PE_MASK | HF_MP_MASK | HF_EM_MASK | \ - HF_TS_MASK | HF_TF_MASK | HF_VM_MASK | HF_IOPL_MASK | \ - HF_OSFXSR_MASK | HF_LMA_MASK | HF_CS32_MASK | \ - HF_SS32_MASK | HF_CS64_MASK | HF_ADDSEG_MASK)) - -uint32_t hflags; - - hflags = (env->segs[R_CS ].flags >>DESC_DPL_SHIFT ) &HF_CPL_MASK ; - hflags |= (env->cr[0 ] &CR0_PE_MASK ) << (HF_PE_SHIFT -CR0_PE_SHIFT ); - hflags |= (env->cr[0 ] << (HF_MP_SHIFT -CR0_MP_SHIFT )) & - (HF_MP_MASK |HF_EM_MASK |HF_TS_MASK ); - hflags |= (env->eflags & (HF_TF_MASK |HF_VM_MASK |HF_IOPL_MASK )); - hflags |= (env->cr[4 ] &CR4_OSFXSR_MASK ) << - (HF_OSFXSR_SHIFT -CR4_OSFXSR_SHIFT ); - -if (env->efer &MSR_EFER_LMA ) { - hflags |=HF_LMA_MASK ; - } - -if ((hflags &HF_LMA_MASK ) && (env->segs[R_CS ].flags &DESC_L_MASK )) { - hflags |=HF_CS32_MASK |HF_SS32_MASK |HF_CS64_MASK ; - }else { - hflags |= (env->segs[R_CS ].flags &DESC_B_MASK ) >> - (DESC_B_SHIFT -HF_CS32_SHIFT ); - hflags |= (env->segs[R_SS ].flags &DESC_B_MASK ) >> - (DESC_B_SHIFT -HF_SS32_SHIFT ); -if (!(env->cr[0 ] &CR0_PE_MASK ) || - (env->eflags &VM_MASK ) || !(hflags &HF_CS32_MASK )) { - hflags |=HF_ADDSEG_MASK ; - }else { - hflags |= ((env->segs[R_DS ].base | - env->segs[R_ES ].base | - env->segs[R_SS ].base) !=0 ) <<HF_ADDSEG_SHIFT ; - } - } - - hflags &= ~HF_SMM_MASK ; - - env->hflags = (env->hflags &HFLAG_COPY_MASK ) | hflags; -return 0 ; -} -static int hax_sync_vcpu_register (CPUArchState *env,int set) {struct vcpu_state_t regs;
@@ -888,7 +838,7 @@ static int hax_sync_vcpu_register(CPUArchState *env, int set) } }if (!set) { -hax_setup_qemu_emulator (env); +x86_update_hflags (env); }return 0 ; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 33/52] target/i386: hax: Move x86_update_hflags.
In reply to Paolo BonziniFrom: Tao Wu <[email protected]>
x86_update_hflags reference env->efer which is updated in hax_get_msrs, so it has to be called after hax_get_msrs. This fix the bug that sometimes dump_state show 32 bits regs even in 64 bits mode.
Message-Id: <[email protected]>
--- target/i386/hax-all.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
target/i386/hax-all.c +1 -3
@@ -837,9 +837,6 @@ static int hax_sync_vcpu_register(CPUArchState *env, int set)return -1 ; } } -if (!set) { -x86_update_hflags (env); - }return 0 ; }
@@ -1020,6 +1017,7 @@ static int hax_arch_get_registers(CPUArchState *env)return ret; } +x86_update_hflags (env);return 0 ; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 34/52] target-i386: update hflags on Hypervisor.framework
In reply to Paolo BonziniThis ensures that x86_cpu_dump_state shows registers with the correct size.
--- target/i386/hvf/x86hvf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/hvf/x86hvf.c +1 -1
@@ -297,7 +297,6 @@ int hvf_get_registers(CPUState *cpu_state)X86CPU *x86cpu =X86_CPU (cpu_state);CPUX86State *env = &x86cpu->env; - env->regs[R_EAX ] =rreg (cpu_state->hvf_fd,HV_X86_RAX ); env->regs[R_EBX ] =rreg (cpu_state->hvf_fd,HV_X86_RBX ); env->regs[R_ECX ] =rreg (cpu_state->hvf_fd,HV_X86_RCX );
@@ -333,6 +332,7 @@ int hvf_get_registers(CPUState *cpu_state) env->dr[6 ] =rreg (cpu_state->hvf_fd,HV_X86_DR6 ); env->dr[7 ] =rreg (cpu_state->hvf_fd,HV_X86_DR7 ); +x86_update_hflags (env);return 0 ; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 35/52] scripts/qemu-gdb: add simple tcg lock status helper
In reply to Paolo BonziniFrom: Alex Bennée <[email protected]>
Add a simple helper to dump lock state.
--- scripts/qemu-gdb.py | 3 ++- scripts/qemugdb/tcg.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 scripts/qemugdb/tcg.py
scripts/qemu-gdb.py +2 -1
@@ -26,7 +26,7 @@ import os, sys sys.path.append(os.path.dirname(__file__)) -from qemugdb import aio, mtree, coroutine +from qemugdb import aio, mtree, coroutine, tcg class QemuCommand(gdb.Command): '''Prefix for QEMU debug support commands'''
@@ -38,6 +38,7 @@ QemuCommand() coroutine.CoroutineCommand() mtree.MtreeCommand() aio.HandlersCommand() +tcg.TCGLockStatusCommand() coroutine.CoroutineSPFunction() coroutine.CoroutinePCFunction()
scripts/qemugdb/tcg.py new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PULL 35/52] scripts/qemu-gdb: add simple tcg lock status helper
Quoted 1 line · Paolo Bonzini
From: Alex Bennée <[email protected]>
<snip>
scripts/qemugdb/tcg.py line 9
Quoted 12 lines
scripts/qemugdb/tcg.py new file +9
-0@@ -0,0 +1,46 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# GDB debugging support, TCG status +# +# Copyright 2016 Linaro Ltd +# +# Authors: +# Alex Bennée <[email protected]>
<snip>
Hmm some munging occurred somewhere.
--
Alex Bennée
[Qemu-devel] [PULL 36/52] scripts/qemu-gdb/timers.py: new helper to dump timer state
In reply to Paolo BonziniFrom: Alex Bennée <[email protected]>
This introduces the qemu-gdb command "qemu timers" which will dump the state of the main timers in the system.
--- scripts/qemu-gdb.py | 3 ++- scripts/qemugdb/timers.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 scripts/qemugdb/timers.py
scripts/qemu-gdb.py +2 -1
@@ -26,7 +26,7 @@ import os, sys sys.path.append(os.path.dirname(__file__)) -from qemugdb import aio, mtree, coroutine, tcg +from qemugdb import aio, mtree, coroutine, tcg, timers class QemuCommand(gdb.Command): '''Prefix for QEMU debug support commands'''
@@ -39,6 +39,7 @@ coroutine.CoroutineCommand() mtree.MtreeCommand() aio.HandlersCommand() tcg.TCGLockStatusCommand() +timers.TimersCommand() coroutine.CoroutineSPFunction() coroutine.CoroutinePCFunction()
scripts/qemugdb/timers.py new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 37/52] icount: fixed saving/restoring of icount warp timers
In reply to Paolo BonziniFrom: Pavel Dovgalyuk <[email protected]>
This patch adds saving and restoring of the icount warp timers in the vmstate.
It is needed because there timers affect the virtual clock value. Therefore determinism of the execution in icount record/replay mode depends on determinism of the timers.
--- cpus.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 19 deletions(-)
cpus.c +66 -19
@@ -120,16 +120,11 @@ static bool all_cpu_threads_idle(void)/* Protected by TimersState seqlock */ static bool icount_sleep = true; -static int64_t vm_clock_warp_start =-1 ;/* Conversion factor from emulated instructions to virtual clock ticks. */ static int icount_time_shift;/* Arbitrarily pick 1MIPS as the minimum allowable speed. */ #define MAX_ICOUNT_SHIFT 10 -static QEMUTimer *icount_rt_timer; -static QEMUTimer *icount_vm_timer; -static QEMUTimer *icount_warp_timer; - typedef struct TimersState { /* Protected by BQL. */ int64_t cpu_ticks_prev;
@@ -147,6 +142,11 @@ typedef struct TimersState {int64_t qemu_icount_bias;/* Only written by TCG thread */ int64_t qemu_icount; +/* for adjusting icount */ +int64_t vm_clock_warp_start; +QEMUTimer *icount_rt_timer; +QEMUTimer *icount_vm_timer; +QEMUTimer *icount_warp_timer; } TimersState;static TimersState timers_state;
@@ -432,14 +432,14 @@ static void icount_adjust(void)static void icount_adjust_rt (void *opaque) { -timer_mod (icount_rt_timer, +timer_mod (timers_state.icount_rt_timer,qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL_RT ) +1000 );icount_adjust (); }static void icount_adjust_vm (void *opaque) { -timer_mod (icount_vm_timer, +timer_mod (timers_state.icount_vm_timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +NANOSECONDS_PER_SECOND /10 );icount_adjust ();
@@ -460,7 +460,7 @@ static void icount_warp_rt(void)*/ do { seq =seqlock_read_begin (&timers_state.vm_clock_seqlock); - warp_start = vm_clock_warp_start; + warp_start = timers_state.vm_clock_warp_start; }while (seqlock_read_retry (&timers_state.vm_clock_seqlock, seq));if (warp_start ==-1 ) {
@@ -473,7 +473,7 @@ static void icount_warp_rt(void) cpu_get_clock_locked());int64_t warp_delta; - warp_delta = clock - vm_clock_warp_start; + warp_delta = clock - timers_state.vm_clock_warp_start;if (use_icount ==2 ) {/* * In adaptive mode, do not let QEMU_CLOCK_VIRTUAL run too
@@ -485,7 +485,7 @@ static void icount_warp_rt(void) } timers_state.qemu_icount_bias += warp_delta; } - vm_clock_warp_start =-1 ; + timers_state.vm_clock_warp_start =-1 ;seqlock_write_end (&timers_state.vm_clock_seqlock);if (qemu_clock_expired (QEMU_CLOCK_VIRTUAL )) {
@@ -594,11 +594,13 @@ void qemu_start_warp_timer(void)* every 100ms. */ seqlock_write_begin (&timers_state.vm_clock_seqlock); -if (vm_clock_warp_start ==-1 || vm_clock_warp_start > clock) { - vm_clock_warp_start = clock; +if (timers_state.vm_clock_warp_start ==-1 + || timers_state.vm_clock_warp_start > clock) { + timers_state.vm_clock_warp_start = clock; }seqlock_write_end (&timers_state.vm_clock_seqlock); -timer_mod_anticipate (icount_warp_timer, clock + deadline); +timer_mod_anticipate (timers_state.icount_warp_timer, + clock + deadline); } }else if (deadline ==0 ) {qemu_clock_notify (QEMU_CLOCK_VIRTUAL );
@@ -623,7 +625,7 @@ static void qemu_account_warp_timer(void)return ; } -timer_del (icount_warp_timer); +timer_del (timers_state.icount_warp_timer);icount_warp_rt (); }
@@ -632,6 +634,45 @@ static bool icount_state_needed(void *opaque)return use_icount; } +static bool warp_timer_state_needed (void *opaque) +{ +TimersState *s = opaque; +return s->icount_warp_timer !=NULL ; +} + +static bool adjust_timers_state_needed (void *opaque) +{ +TimersState *s = opaque; +return s->icount_rt_timer !=NULL ; +} + +/* +* Subsection for warp timer migration is optional, because may not be created +*/ +static const VMStateDescription icount_vmstate_warp_timer = { + .name ="timer/icount/warp_timer" , + .version_id =1 , + .minimum_version_id =1 , + .needed = warp_timer_state_needed, + .fields = (VMStateField []) { +VMSTATE_INT64 (vm_clock_warp_start, TimersState), +VMSTATE_TIMER_PTR (icount_warp_timer, TimersState), +VMSTATE_END_OF_LIST () + } +}; + +static const VMStateDescription icount_vmstate_adjust_timers = { + .name ="timer/icount/timers" , + .version_id =1 , + .minimum_version_id =1 , + .needed = adjust_timers_state_needed, + .fields = (VMStateField []) { +VMSTATE_TIMER_PTR (icount_rt_timer, TimersState), +VMSTATE_TIMER_PTR (icount_vm_timer, TimersState), +VMSTATE_END_OF_LIST () + } +}; +/* * This is a subsection for icount migration. */
@@ -644,6 +685,11 @@ static const VMStateDescription icount_vmstate_timers = { VMSTATE_INT64(qemu_icount_bias, TimersState), VMSTATE_INT64(qemu_icount, TimersState),VMSTATE_END_OF_LIST () + }, + .subsections = (const VMStateDescription *[]) { + &icount_vmstate_warp_timer, + &icount_vmstate_adjust_timers, +NULL } };
@@ -754,7 +800,7 @@ void configure_icount(QemuOpts *opts, Error **errp) icount_sleep =qemu_opt_get_bool (opts,"sleep" , true);if (icount_sleep) { - icount_warp_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL_RT , + timers_state.icount_warp_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL_RT , icount_timer_cb,NULL ); }
@@ -788,13 +834,14 @@ void configure_icount(QemuOpts *opts, Error **errp)the virtual time trigger catches emulated time passing too fast. Realtime triggers occur even when idle, so use them less frequently than VM triggers. */ - icount_rt_timer =timer_new_ms (QEMU_CLOCK_VIRTUAL_RT , + timers_state.vm_clock_warp_start =-1 ; + timers_state.icount_rt_timer =timer_new_ms (QEMU_CLOCK_VIRTUAL_RT , icount_adjust_rt,NULL ); -timer_mod (icount_rt_timer, +timer_mod (timers_state.icount_rt_timer,qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL_RT ) +1000 ); - icount_vm_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , + timers_state.icount_vm_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , icount_adjust_vm,NULL ); -timer_mod (icount_vm_timer, +timer_mod (timers_state.icount_vm_timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +NANOSECONDS_PER_SECOND /10 ); }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 38/52] cpus: unify qemu_*_wait_io_event
In reply to Paolo BonziniExcept for round-robin TCG, every other accelerator is using more or less the same code around qemu_wait_io_event_common. The exception is HAX, which also has to eat the dummy APC that is queued by qemu_cpu_kick_thread.
We can add the SleepEx call to qemu_wait_io_event under "if (!tcg_enabled())", since that is the condition that is used in qemu_cpu_kick_thread, and unify the function for KVM, HAX, HVF and multi-threaded TCG. Single-threaded TCG code can also be simplified since it is only used in the round-robin, sleep-if-all-CPUs-idle case.
--- cpus.c | 49 +++++++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 32 deletions(-)
cpus.c +17 -32
@@ -909,7 +909,8 @@ static void kick_tcg_thread(void *opaque)static void start_tcg_kick_timer (void ) { -if (!mttcg_enabled && !tcg_kick_vcpu_timer &&CPU_NEXT (first_cpu)) { +assert (!mttcg_enabled); +if (!tcg_kick_vcpu_timer &&CPU_NEXT (first_cpu)) { tcg_kick_vcpu_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , kick_tcg_thread,NULL );timer_mod (tcg_kick_vcpu_timer,qemu_tcg_next_kick ());
@@ -918,6 +919,7 @@ static void start_tcg_kick_timer(void)static void stop_tcg_kick_timer (void ) { +assert (!mttcg_enabled);if (tcg_kick_vcpu_timer) {timer_del (tcg_kick_vcpu_timer); tcg_kick_vcpu_timer =NULL ;
@@ -1137,18 +1139,9 @@ static void qemu_wait_io_event_common(CPUState *cpu)process_queued_cpu_work (cpu); } -static bool qemu_tcg_should_sleep (CPUState *cpu) +static void qemu_tcg_rr_wait_io_event (CPUState *cpu) { -if (mttcg_enabled) { -return cpu_thread_is_idle (cpu); - }else { -return all_cpu_threads_idle (); - } -} - -static void qemu_tcg_wait_io_event (CPUState *cpu) -{ -while (qemu_tcg_should_sleep (cpu)) { +while (all_cpu_threads_idle ()) {stop_tcg_kick_timer ();qemu_cond_wait (cpu->halt_cond, &qemu_global_mutex); }
@@ -1158,20 +1151,18 @@ static void qemu_tcg_wait_io_event(CPUState *cpu)qemu_wait_io_event_common (cpu); } -static void qemu_kvm_wait_io_event (CPUState *cpu) +static void qemu_wait_io_event (CPUState *cpu) {while (cpu_thread_is_idle (cpu)) {qemu_cond_wait (cpu->halt_cond, &qemu_global_mutex); } -qemu_wait_io_event_common (cpu); -} - -static void qemu_hvf_wait_io_event (CPUState *cpu) -{ -while (cpu_thread_is_idle (cpu)) { -qemu_cond_wait (cpu->halt_cond, &qemu_global_mutex); +#ifdef _WIN32 +/* Eat dummy APC queued by qemu_cpu_kick_thread. */ +if (!tcg_enabled ()) { +SleepEx (0 , TRUE); } +#endif qemu_wait_io_event_common (cpu); }
@@ -1207,7 +1198,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)cpu_handle_guest_debug (cpu); } } -qemu_kvm_wait_io_event (cpu); +qemu_wait_io_event (cpu); }while (!cpu->unplug ||cpu_can_run (cpu));qemu_kvm_destroy_vcpu (cpu);
@@ -1253,7 +1244,7 @@ static void *qemu_dummy_cpu_thread_fn(void *arg)exit (1 ); }qemu_mutex_lock_iothread (); -qemu_wait_io_event_common (cpu); +qemu_wait_io_event (cpu); }return NULL ;
@@ -1470,7 +1461,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg)atomic_mb_set (&cpu->exit_request,0 ); } -qemu_tcg_wait_io_event (cpu ? cpu :QTAILQ_FIRST (&cpus)); +qemu_tcg_rr_wait_io_event (cpu ? cpu :QTAILQ_FIRST (&cpus));deal_with_unplugged_cpus (); }
@@ -1501,13 +1492,7 @@ static void *qemu_hax_cpu_thread_fn(void *arg) } } -while (cpu_thread_is_idle (cpu)) { -qemu_cond_wait (cpu->halt_cond, &qemu_global_mutex); - } -#ifdef _WIN32 -SleepEx (0 , TRUE); -#endif -qemu_wait_io_event_common (cpu); +qemu_wait_io_event (cpu); }return NULL ; }
@@ -1544,7 +1529,7 @@ static void *qemu_hvf_cpu_thread_fn(void *arg)cpu_handle_guest_debug (cpu); } } -qemu_hvf_wait_io_event (cpu); +qemu_wait_io_event (cpu); }while (!cpu->unplug ||cpu_can_run (cpu));hvf_vcpu_destroy (cpu);
@@ -1623,7 +1608,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) }atomic_mb_set (&cpu->exit_request,0 ); -qemu_tcg_wait_io_event (cpu); +qemu_wait_io_event (cpu); }return NULL ;
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 41/52] mips: Tweak location of ';' in macros
In reply to Paolo BonziniFrom: Eric Blake <[email protected]>
It is more typical to provide the ';' by the caller of a macro than to embed it in the macro itself; this is because syntax highlight engines can get confused if a macro is called without a semicolon before the closing '}'.
Message-Id: <[email protected]>
--- target/mips/msa_helper.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-)
target/mips/msa_helper.c +18 -16
@@ -682,13 +682,13 @@ static inline int64_t msa_mod_u_df(uint32_t df, int64_t arg1, int64_t arg2)do { \ e =SIGNED_EVEN (a, df); \ o =SIGNED_ODD (a, df); \ - }while (0 ); + } while (0)#define UNSIGNED_EXTRACT (e, o, a, df) \ do { \ e = UNSIGNED_EVEN(a, df); \ o = UNSIGNED_ODD(a, df); \ - } while (0); + } while (0)static inline int64_t msa_dotp_s_df (uint32_t df,int64_t arg1,int64_t arg2) {
@@ -1120,9 +1120,11 @@ void helper_msa_splat_df(CPUMIPSState *env, uint32_t df, uint32_t wd,#define MSA_LOOP_COND_D MSA_LOOP_COND(DF_DOUBLE)#define MSA_LOOP (DF ) \ + do { \ for (i = 0; i < (MSA_LOOP_COND_ ## DF) ; i++) { \ - MSA_DO_ ## DF \ - } + MSA_DO_ ## DF; \ + } \ + } while (0)#define MSA_FN_DF (FUNC ) \ void helper_msa_##FUNC(CPUMIPSState *env, uint32_t df, uint32_t wd, \
@@ -1135,17 +1137,17 @@ void helper_msa_##FUNC(CPUMIPSState *env, uint32_t df, uint32_t wd, \uint32_t i; \switch (df) { \case DF_BYTE : \ -MSA_LOOP_B \ +MSA_LOOP_B ; \break ; \case DF_HALF : \ -MSA_LOOP_H \ +MSA_LOOP_H ; \break ; \case DF_WORD : \ -MSA_LOOP_W \ +MSA_LOOP_W ; \break ; \case DF_DOUBLE : \ -MSA_LOOP_D \ - break; \ +MSA_LOOP_D ; \ +break ; \default : \assert (0 ); \ } \
@@ -1168,7 +1170,7 @@ void helper_msa_##FUNC(CPUMIPSState *env, uint32_t df, uint32_t wd, \ do { \ R##DF(pwx, i) = pwt->DF[2*i]; \ L##DF(pwx, i) = pws->DF[2*i]; \ - } while (0); + } while (0) MSA_FN_DF(pckev_df) #undef MSA_DO
@@ -1176,7 +1178,7 @@ MSA_FN_DF(pckev_df) do { \ R##DF(pwx, i) = pwt->DF[2*i+1]; \ L##DF(pwx, i) = pws->DF[2*i+1]; \ - } while (0); + } while (0) MSA_FN_DF(pckod_df) #undef MSA_DO
@@ -1184,7 +1186,7 @@ MSA_FN_DF(pckod_df) do { \ pwx->DF[2*i] = L##DF(pwt, i); \ pwx->DF[2*i+1] = L##DF(pws, i); \ - } while (0); + } while (0) MSA_FN_DF(ilvl_df) #undef MSA_DO
@@ -1192,7 +1194,7 @@ MSA_FN_DF(ilvl_df) do { \ pwx->DF[2*i] = R##DF(pwt, i); \ pwx->DF[2*i+1] = R##DF(pws, i); \ - } while (0); + } while (0) MSA_FN_DF(ilvr_df) #undef MSA_DO
@@ -1200,7 +1202,7 @@ MSA_FN_DF(ilvr_df)do { \ pwx->DF[2 *i] = pwt->DF[2 *i]; \ pwx->DF[2 *i+1 ] = pws->DF[2 *i]; \ - }while (0 ); + } while (0)MSA_FN_DF (ilvev_df) #undef MSA_DO
@@ -1208,7 +1210,7 @@ MSA_FN_DF(ilvev_df)do { \ pwx->DF[2 *i] = pwt->DF[2 *i+1 ]; \ pwx->DF[2 *i+1 ] = pws->DF[2 *i+1 ]; \ - }while (0 ); + } while (0) MSA_FN_DF(ilvod_df)#undef MSA_DO#undef MSA_LOOP_COND
@@ -1222,7 +1224,7 @@ MSA_FN_DF(ilvod_df)uint32_t k = (pwd->DF[i] &0x3f ) % (2 * n); \ pwx->DF[i] = \ (pwd->DF[i] &0xc0 ) ?0 : k < n ? pwt->DF[k] : pws->DF[k - n]; \ - }while (0 ); + }while (0 ) MSA_FN_DF(vshf_df)#undef MSA_DO#undef MSA_LOOP_COND
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 42/52] chardev: Use goto/label instead of do/break/while(0)
In reply to Paolo BonziniFrom: Eric Blake <[email protected]>
Use of a do/while(0) control flow in order to permit an early break is an unusual paradigm, and triggers a false positive with a planned future syntax check against 'while (0);'. Rewrite the code to use a goto instead. This patch temporarily keeps an extra level of indentation to highlight the change; the next patch cleans it up.
Message-Id: <[email protected]>
--- chardev/char-serial.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
chardev/char-serial.c +10 -3
@@ -64,9 +64,14 @@ static void tty_serial_init(int fd, int speed,#endif tcgetattr (fd, &tty); -#define check_speed (val) if (speed <= val) { spd = B##val; break; } +#define check_speed (val) \ + if (speed <= val) { \ + spd = B##val; \ + goto done; \ + } + speed = speed *10 /11 ; - do { + {check_speed (50 );check_speed (75 );check_speed (110 );
@@ -125,8 +130,10 @@ static void tty_serial_init(int fd, int speed,check_speed (4000000 );#endif spd =B115200 ; - }while (0 ); + } +#undef check_speed + done:cfsetispeed (&tty, spd);cfsetospeed (&tty, spd);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 43/52] chardev: Clean up previous patch indentation
In reply to Paolo BonziniFrom: Eric Blake <[email protected]>
The previous patch left in an extra scope layer for ease of review; time to remove it. No semantic change.
Message-Id: <[email protected]>
--- chardev/char-serial.c | 66 +++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 34 deletions(-)
chardev/char-serial.c +32 -34
@@ -71,66 +71,64 @@ static void tty_serial_init(int fd, int speed, } speed = speed *10 /11 ; - { -check_speed (50 ); -check_speed (75 ); -check_speed (110 ); -check_speed (134 ); -check_speed (150 ); -check_speed (200 ); -check_speed (300 ); -check_speed (600 ); -check_speed (1200 ); -check_speed (1800 ); -check_speed (2400 ); -check_speed (4800 ); -check_speed (9600 ); -check_speed (19200 ); -check_speed (38400 ); -/* Non-Posix values follow. They may be unsupported on some systems. */ -check_speed (57600 ); -check_speed (115200 ); +check_speed (50 ); +check_speed (75 ); +check_speed (110 ); +check_speed (134 ); +check_speed (150 ); +check_speed (200 ); +check_speed (300 ); +check_speed (600 ); +check_speed (1200 ); +check_speed (1800 ); +check_speed (2400 ); +check_speed (4800 ); +check_speed (9600 ); +check_speed (19200 ); +check_speed (38400 ); +/* Non-Posix values follow. They may be unsupported on some systems. */ +check_speed (57600 ); +check_speed (115200 );#ifdef B230400 -check_speed (230400 ); +check_speed (230400 );#endif #ifdef B460800 -check_speed (460800 ); +check_speed (460800 );#endif #ifdef B500000 -check_speed (500000 ); +check_speed (500000 );#endif #ifdef B576000 -check_speed (576000 ); +check_speed (576000 );#endif #ifdef B921600 -check_speed (921600 ); +check_speed (921600 );#endif #ifdef B1000000 -check_speed (1000000 ); +check_speed (1000000 );#endif #ifdef B1152000 -check_speed (1152000 ); +check_speed (1152000 );#endif #ifdef B1500000 -check_speed (1500000 ); +check_speed (1500000 );#endif #ifdef B2000000 -check_speed (2000000 ); +check_speed (2000000 );#endif #ifdef B2500000 -check_speed (2500000 ); +check_speed (2500000 );#endif #ifdef B3000000 -check_speed (3000000 ); +check_speed (3000000 );#endif #ifdef B3500000 -check_speed (3500000 ); +check_speed (3500000 );#endif #ifdef B4000000 -check_speed (4000000 ); +check_speed (4000000 );#endif - spd =B115200 ; - } + spd =B115200 ;#undef check_speed done:
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 39/52] irq: fix memory leak
In reply to Paolo BonziniFrom: linzhecheng <[email protected]>
entry is moved from list but is not freed.
Message-Id: <[email protected]>
--- target/i386/kvm.c | 1 + 1 file changed, 1 insertion(+)
target/i386/kvm.c +1 -0
@@ -3470,6 +3470,7 @@ int kvm_arch_release_virq_post(int virq)if (entry->virq == virq) {trace_kvm_x86_remove_msi_route (virq);QLIST_REMOVE (entry, list); +g_free (entry);break ; } }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 44/52] tests: Avoid 'do/while(false); ' in vhost-user-bridge
In reply to Paolo BonziniFrom: Eric Blake <[email protected]>
Use of a do/while(0) loop as a way to allow break statements in the middle of execute-once code is unusual. More typical is the use of goto for early exits, with a label at the end of the execute-once code, rather than nesting code in a scope; however, the comment at the end of the existing code makes this alternative a bit unpractical.
So, to avoid false positives from a future syntax check about 'while (false);', and to keep the loop form (in case someone ever does add DONTWAIT support, where they can just as easily manipulate the initial loop condition or add an if around the final 'break'), I opted to use the form of a while(1) loop (the break as an early exit is more idiomatic there), coupled with a final break preserving the original comment.
Message-Id: <[email protected]>
--- tests/vhost-user-bridge.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tests/vhost-user-bridge.c +4 -2
@@ -283,7 +283,7 @@ vubr_backend_recv_cb(int sock, void *ctx)return ; } - do { +while (1 ) {struct iovec *sg;ssize_t ret, total =0 ;unsigned int num;
@@ -343,7 +343,9 @@ vubr_backend_recv_cb(int sock, void *ctx)free (elem); elem =NULL ; - }while (false);/* could loop if DONTWAIT worked? */ + +break ;/* could loop if DONTWAIT worked? */ + }if (mhdr_cnt) { mhdr.num_buffers = i;
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 40/52] net: Drop unusual use of do { } while (0);
In reply to Paolo BonziniFrom: Eric Blake <[email protected]>
For a couple of macros in pcnet.c, we have to provide a new scope to avoid compiler warnings about declarations in the middle of a switch statement that aren't in a sub-scope. But use of 'do { ... } while (0);' merely to provide that new scope is arcane overkill, compared to just using '{ ... }'.
Message-Id: <[email protected]>
--- hw/net/pcnet.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
hw/net/pcnet.c +10 -10
@@ -456,32 +456,32 @@ static inline void pcnet_rmd_store(PCNetState *s, struct pcnet_RMD *rmd,#define CHECK_RMD (ADDR ,RES ) do { \ switch (BCR_SWSTYLE(s)) { \ case 0x00: \ - do { \ + { \ uint16_t rda[4]; \ s->phys_mem_read(s->dma_opaque, (ADDR), \ (void *)&rda[0], sizeof(rda), 0); \ (RES) |= (rda[2] & 0xf000)!=0xf000; \ (RES) |= (rda[3] & 0xf000)!=0x0000; \ - } while (0); \ + } \ break; \ case 0x01: \ case 0x02: \ - do { \ + { \ uint32_t rda[4]; \ s->phys_mem_read(s->dma_opaque, (ADDR), \ (void *)&rda[0], sizeof(rda), 0); \ (RES) |= (rda[1] & 0x0000f000L)!=0x0000f000L; \ (RES) |= (rda[2] & 0x0000f000L)!=0x00000000L; \ - } while (0); \ + } \ break; \ case 0x03: \ - do { \ + { \ uint32_t rda[4]; \ s->phys_mem_read(s->dma_opaque, (ADDR), \ (void *)&rda[0], sizeof(rda), 0); \ (RES) |= (rda[0] & 0x0000f000L)!=0x00000000L; \ (RES) |= (rda[1] & 0x0000f000L)!=0x0000f000L; \ - } while (0); \ + } \ break; \ } \ } while (0)
@@ -489,22 +489,22 @@ static inline void pcnet_rmd_store(PCNetState *s, struct pcnet_RMD *rmd,#define CHECK_TMD (ADDR ,RES ) do { \ switch (BCR_SWSTYLE(s)) { \ case 0x00: \ - do { \ + { \ uint16_t xda[4]; \ s->phys_mem_read(s->dma_opaque, (ADDR), \ (void *)&xda[0], sizeof(xda), 0); \ (RES) |= (xda[2] & 0xf000)!=0xf000; \ - } while (0); \ + } \ break; \ case 0x01: \ case 0x02: \ case 0x03: \ - do { \ + { \ uint32_t xda[4]; \ s->phys_mem_read(s->dma_opaque, (ADDR), \ (void *)&xda[0], sizeof(xda), 0); \ (RES) |= (xda[1] & 0x0000f000L)!=0x0000f000L; \ - } while (0); \ + } \ break; \ } \ } while (0)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 46/52] checkpatch: Enforce proper do/while (0) style
In reply to Paolo BonziniFrom: Eric Blake <[email protected]>
Use of a loop construct for code that is not intended to repeat does not make much idiomatic sense, except in one place: it is a common usage in macros in order to wrap arbitrary code with single-statement semantics. But when used in a macro, it is more typical for the caller to supply the trailing ';' when calling the macro.
Although qemu coding style frowns on bare:
if (cond)
statement1;
else
statement2;where extra semicolons actually cause syntax errors, we still want our macro styles to be easily copied to other projects. Thus, declare it an error if we encounter any form of 'while (0)' with a semicolon in the same line.
Message-Id: <[email protected]>
--- scripts/checkpatch.pl | 5 +++++ 1 file changed, 5 insertions(+)
scripts/checkpatch.pl +5 -0
@@ -1622,6 +1622,11 @@ sub process { } } +# 'do ... while (0/false)' only makes sense in macros, without trailing ';' + if ($line =~ /while\s*\((0|false)\);/) { + ERROR("suspicious ; after while (0)\n" . $herecurr); + } + # Check relative indent for conditionals and blocks. if ($line =~ /\b(?:(?:if|while|for)\s*\(|do\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) { my ($s, $c) = ($stat, $cond);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 45/52] maint: Fix macros with broken 'do/while(0); ' usage
In reply to Paolo BonziniFrom: Eric Blake <[email protected]>
The point of writing a macro embedded in a 'do { ... } while (0)' loop (particularly if the macro has multiple statements or would otherwise end with an 'if' statement) is so that the macro can be used as a drop-in statement with the caller supplying the trailing ';'. Although our coding style frowns on brace-less 'if':
if (cond)
statement;
else
something else;that is the classic case where failure to use do/while(0) wrapping would cause the 'else' to pair with any embedded 'if' in the macro rather than the intended outer 'if'. But conversely, if the macro includes an embedded ';', then the same brace-less coding style would now have two statements, making the 'else' a syntax error rather than pairing with the outer 'if'. Thus, even though our coding style with required braces is not impacted, ending a macro with ';' makes our code harder to port to projects that use brace-less styles.
The change should have no semantic impact. I was not able to fully compile-test all of the changes (as some of them are examples of the ugly bit-rotting debug print statements that are completely elided by default, and I didn't want to recompile with the necessary -D witnesses - cleaning those up is left as a bite-sized task for another day); I did, however, audit that for all files touched, all callers of the changed macros DID supply a trailing ';' at the callsite, and did not appear to be used as part of a brace-less conditional.
Found mechanically via: $ git grep -B1 'while (0);' | grep -A1 \\\\
Message-Id: <[email protected]>
--- audio/paaudio.c | 4 ++-- hw/adc/stm32f2xx_adc.c | 2 +- hw/block/m25p80.c | 2 +- hw/char/cadence_uart.c | 2 +- hw/char/stm32f2xx_usart.c | 2 +- hw/display/cg3.c | 2 +- hw/display/dpcd.c | 2 +- hw/display/xlnx_dp.c | 2 +- hw/dma/pl330.c | 2 +- hw/dma/xlnx-zynq-devcfg.c | 2 +- hw/dma/xlnx_dpdma.c | 2 +- hw/i2c/i2c-ddc.c | 2 +- hw/misc/auxbus.c | 2 +- hw/misc/macio/mac_dbdma.c | 4 ++-- hw/misc/mmio_interface.c | 2 +- hw/misc/stm32f2xx_syscfg.c | 2 +- hw/misc/zynq_slcr.c | 2 +- hw/net/cadence_gem.c | 2 +- hw/ssi/mss-spi.c | 2 +- hw/ssi/stm32f2xx_spi.c | 2 +- hw/ssi/xilinx_spi.c | 2 +- hw/ssi/xilinx_spips.c | 2 +- hw/timer/a9gtimer.c | 2 +- hw/timer/cadence_ttc.c | 2 +- hw/timer/mss-timer.c | 2 +- hw/timer/stm32f2xx_timer.c | 2 +- hw/tpm/tpm_passthrough.c | 2 +- hw/tpm/tpm_tis.c | 2 +- migration/rdma.c | 2 +- target/arm/translate-a64.c | 2 +- target/s390x/kvm.c | 2 +- tests/acpi-utils.h | 8 ++++---- tests/tcg/test-mmap.c | 2 +- ui/sdl_zoom_template.h | 8 ++++---- 34 files changed, 42 insertions(+), 42 deletions(-)
audio/paaudio.c +2 -2
@@ -89,7 +89,7 @@ static inline int PA_STREAM_IS_GOOD(pa_stream_state_t x) } \ goto label; \ } \ - }while (0 ); + } while (0)#define CHECK_DEAD_GOTO (c, stream, rerror, label) \ do { \
@@ -107,7 +107,7 @@ static inline int PA_STREAM_IS_GOOD(pa_stream_state_t x) } \ goto label; \ } \ - }while (0 ); + }while (0 ) static int qpa_simple_read (PAVoiceIn *p, void *data, size_t length, int *rerror) {
hw/adc/stm32f2xx_adc.c +1 -1
@@ -37,7 +37,7 @@if (STM_ADC_ERR_DEBUG >= lvl) { \ qemu_log("%s: " fmt, __func__, ## args); \ } \ -}while (0 ); +}while (0 ) #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
hw/block/m25p80.c +1 -1
@@ -40,7 +40,7 @@fprintf (stderr,": %s: " , __func__); \ fprintf(stderr, ## __VA_ARGS__); \ } \ -}while (0 ); +}while (0 )/* Fields for FlashPartInfo->flags */
hw/char/cadence_uart.c +1 -1
@@ -33,7 +33,7 @@#define DB_PRINT (...) do { \ fprintf(stderr, ": %s: ", __func__); \ fprintf(stderr, ## __VA_ARGS__); \ - } while (0); + } while (0)#else #define DB_PRINT (...)#endif
hw/char/stm32f2xx_usart.c +1 -1
@@ -34,7 +34,7 @@if (STM_USART_ERR_DEBUG >= lvl) { \ qemu_log("%s: " fmt, __func__, ## args); \ } \ -}while (0 ); +}while (0 ) #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
hw/display/cg3.c +1 -1
@@ -63,7 +63,7 @@if (DEBUG_CG3 ) { \ printf("CG3: " fmt , ## __VA_ARGS__); \ } \ -}while (0 ); +} while (0)#define TYPE_CG3 "cgthree"#define CG3 (obj) OBJECT_CHECK(CG3State, (obj), TYPE_CG3)
hw/display/dpcd.c +1 -1
@@ -39,7 +39,7 @@if (DEBUG_DPCD ) { \ qemu_log("dpcd: " fmt, ## __VA_ARGS__); \ } \ -}while (0 ); +} while (0)#define DPCD_READABLE_AREA 0x600
hw/display/xlnx_dp.c +1 -1
@@ -34,7 +34,7 @@if (DEBUG_DP ) { \ qemu_log("xlnx_dp: " fmt , ## __VA_ARGS__); \ } \ -}while (0 ); +}while (0 )/* * Register offset for DP.
hw/dma/pl330.c +1 -1
@@ -29,7 +29,7 @@if (PL330_ERR_DEBUG >= lvl) {\ fprintf(stderr, "PL330: %s:" fmt, __func__, ## args);\ } \ -}while (0 ); +}while (0 ) #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
hw/dma/xlnx-zynq-devcfg.c +1 -1
@@ -43,7 +43,7 @@if (XLNX_ZYNQ_DEVCFG_ERR_DEBUG ) { \ qemu_log("%s: " fmt, __func__, ## args); \ } \ -}while (0 ); +}while (0 ) REG32(CTRL, 0x00)FIELD (CTRL ,FORCE_RST ,31 ,1 )/* Not supported, wr ignored */
hw/dma/xlnx_dpdma.c +1 -1
@@ -34,7 +34,7 @@if (DEBUG_DPDMA ) { \ qemu_log("xlnx_dpdma: " fmt , ## __VA_ARGS__); \ } \ -}while (0 ); +}while (0 )/* * Registers offset for DPDMA.
hw/i2c/i2c-ddc.c +1 -1
@@ -30,7 +30,7 @@if (DEBUG_I2CDDC ) { \ qemu_log("i2c-ddc: " fmt , ## __VA_ARGS__); \ } \ -}while (0 ); +}while (0 )/* Structure defining a monitor's characteristics in a * readable format: this should be passed to build_edid_blob()
hw/misc/auxbus.c +1 -1
@@ -40,7 +40,7 @@if (DEBUG_AUX ) { \ qemu_log("aux: " fmt , ## __VA_ARGS__); \ } \ -}while (0 ); +} while (0)#define TYPE_AUXTOI2C "aux-to-i2c-bridge"#define AUXTOI2C (obj) OBJECT_CHECK(AUXTOI2CState, (obj), TYPE_AUXTOI2C)
hw/misc/macio/mac_dbdma.c +2 -2
@@ -52,7 +52,7 @@if (DEBUG_DBDMA ) { \ printf("DBDMA: " fmt , ## __VA_ARGS__); \ } \ -}while (0 ); +} while (0)#define DBDMA_DPRINTFCH (ch, fmt, ...) do { \ if (DEBUG_DBDMA) { \
@@ -60,7 +60,7 @@ printf("DBDMA[%02x]: " fmt , (ch)->channel, ## __VA_ARGS__); \ } \ } \ -}while (0 ); +}while (0 )/* */
hw/misc/mmio_interface.c +1 -1
@@ -39,7 +39,7 @@ static uint64_t mmio_interface_counter;if (DEBUG_MMIO_INTERFACE ) { \ qemu_log("mmio_interface: 0x%" PRIX64 ": " fmt, s->id, ## __VA_ARGS__);\ } \ -}while (0 ); +}while (0 ) static void mmio_interface_init(Object *obj) {
hw/misc/stm32f2xx_syscfg.c +1 -1
@@ -34,7 +34,7 @@if (STM_SYSCFG_ERR_DEBUG >= lvl) { \ qemu_log("%s: " fmt, __func__, ## args); \ } \ -}while (0 ); +}while (0 ) #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
hw/misc/zynq_slcr.c +1 -1
@@ -30,7 +30,7 @@fprintf (stderr,": %s: " , __func__); \ fprintf(stderr, ## __VA_ARGS__); \ } \ - }while (0 ); + } while (0)#define XILINX_LOCK_KEY 0x767b#define XILINX_UNLOCK_KEY 0xdf0d
hw/net/cadence_gem.c +1 -1
@@ -34,7 +34,7 @@#define DB_PRINT (...) do { \ fprintf(stderr, ": %s: ", __func__); \ fprintf(stderr, ## __VA_ARGS__); \ - } while (0); + } while (0)#else #define DB_PRINT (...)#endif
hw/ssi/mss-spi.c +1 -1
@@ -35,7 +35,7 @@if (MSS_SPI_ERR_DEBUG >= lvl) { \ qemu_log("%s: " fmt "\n", __func__, ## args); \ } \ -}while (0 ); +}while (0 ) #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
hw/ssi/stm32f2xx_spi.c +1 -1
@@ -35,7 +35,7 @@if (STM_SPI_ERR_DEBUG >= lvl) { \ qemu_log("%s: " fmt, __func__, ## args); \ } \ -}while (0 ); +}while (0 ) #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
hw/ssi/xilinx_spi.c +1 -1
@@ -36,7 +36,7 @@#define DB_PRINT (...) do { \ fprintf(stderr, ": %s: ", __func__); \ fprintf(stderr, ## __VA_ARGS__); \ - } while (0); + } while (0)#else #define DB_PRINT (...)#endif
hw/ssi/xilinx_spips.c +1 -1
@@ -43,7 +43,7 @@fprintf (stderr,": %s: " , __func__); \ fprintf(stderr, ## __VA_ARGS__); \ } \ -}while (0 ); +}while (0 )/* config register */ #define R_CONFIG (0x00 / 4)
hw/timer/a9gtimer.c +1 -1
@@ -37,7 +37,7 @@fprintf (stderr,": %s: " , __func__); \ fprintf(stderr, ## __VA_ARGS__); \ } \ -}while (0 ); +} while (0)#define DB_PRINT (...) DB_PRINT_L(0, ## __VA_ARGS__)
hw/timer/cadence_ttc.c +1 -1
@@ -24,7 +24,7 @@#define DB_PRINT (...) do { \ fprintf(stderr, ": %s: ", __func__); \ fprintf(stderr, ## __VA_ARGS__); \ - } while (0); + } while (0)#else #define DB_PRINT (...)#endif
hw/timer/mss-timer.c +1 -1
@@ -36,7 +36,7 @@if (MSS_TIMER_ERR_DEBUG >= lvl) { \ qemu_log("%s: " fmt "\n", __func__, ## args); \ } \ -}while (0 ); +}while (0 ) #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
hw/timer/stm32f2xx_timer.c +1 -1
@@ -34,7 +34,7 @@if (STM_TIMER_ERR_DEBUG >= lvl) { \ qemu_log("%s: " fmt, __func__, ## args); \ } \ -}while (0 ); +}while (0 ) #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
hw/tpm/tpm_passthrough.c +1 -1
@@ -38,7 +38,7 @@if (DEBUG_TPM ) { \ fprintf(stderr, fmt, ## __VA_ARGS__); \ } \ -}while (0 ); +} while (0)#define TYPE_TPM_PASSTHROUGH "tpm-passthrough"#define TPM_PASSTHROUGH (obj) \
hw/tpm/tpm_tis.c +1 -1
@@ -90,7 +90,7 @@ typedef struct TPMState {if (DEBUG_TIS ) { \ printf(fmt, ## __VA_ARGS__); \ } \ -}while (0 ); +}while (0 ) /* tis registers */#define TPM_TIS_REG_ACCESS 0x00
migration/rdma.c +1 -1
@@ -88,7 +88,7 @@ static uint32_t known_capabilities = RDMA_CAPABILITY_PIN_ALL; } \return rdma->error_state; \ } \ - }while (0 ); + }while (0 )/* * A work request ID is 64-bits and we split up these bits
target/arm/translate-a64.c +1 -1
@@ -400,7 +400,7 @@ static void unallocated_encoding(DisasContext *s)"at pc=%016" PRIx64"\n" , \ __FILE__, __LINE__, insn, s->pc - 4); \unallocated_encoding (s); \ - }while (0 ); + }while (0 ) static void init_tmp_a64_array(DisasContext *s) {
target/s390x/kvm.c +1 -1
@@ -58,7 +58,7 @@if (DEBUG_KVM ) { \ fprintf(stderr, fmt, ## __VA_ARGS__); \ } \ -}while (0 ); +} while (0)#define kvm_vm_check_mem_attr (s, attr) \ kvm_vm_check_attr(s, KVM_S390_VM_MEM_CTRL, attr)
tests/acpi-utils.h +4 -4
@@ -32,7 +32,7 @@ typedef struct {do { \memread (addr, &field,sizeof (field)); \ addr +=sizeof (field); \ - }while (0 ); + } while (0)#define ACPI_READ_ARRAY_PTR (arr, length, addr) \ do { \
@@ -40,7 +40,7 @@ typedef struct {for (idx =0 ; idx < length; ++idx) { \ACPI_READ_FIELD (arr[idx], addr); \ } \ - }while (0 ); + } while (0)#define ACPI_READ_ARRAY (arr, addr) \ ACPI_READ_ARRAY_PTR(arr, sizeof(arr) / sizeof(arr[0]), addr)
@@ -56,7 +56,7 @@ typedef struct {ACPI_READ_FIELD ((table)->oem_revision, addr); \ACPI_READ_ARRAY ((table)->asl_compiler_id, addr); \ACPI_READ_FIELD ((table)->asl_compiler_revision, addr); \ - }while (0 ); + } while (0)#define ACPI_ASSERT_CMP (actual, expected) do { \ char ACPI_ASSERT_CMP_str[5] = {}; \
@@ -77,7 +77,7 @@ typedef struct {ACPI_READ_FIELD ((field).bit_offset, addr); \ACPI_READ_FIELD ((field).access_width, addr); \ACPI_READ_FIELD ((field).address, addr); \ - }while (0 ); + }while (0 ) uint8_t acpi_calc_checksum(const uint8_t *data, int len);
tests/tcg/test-mmap.c +1 -1
@@ -39,7 +39,7 @@ do \fprintf (stderr,"FAILED at %s:%d\n" , __FILE__, __LINE__); \exit (EXIT_FAILURE ); \ } \ -}while (0 ); +}while (0 ) unsigned char *dummybuf;static unsigned int pagesize;
ui/sdl_zoom_template.h +4 -4
@@ -34,22 +34,22 @@#define setRed (r, pcolor) do { \ *pcolor = ((*pcolor) & (~(dpf->Rmask))) + \ (((r) & (dpf->Rmask >> dpf->Rshift)) << dpf->Rshift); \ -} while (0); +} while (0)#define setGreen (g, pcolor) do { \ *pcolor = ((*pcolor) & (~(dpf->Gmask))) + \ (((g) & (dpf->Gmask >> dpf->Gshift)) << dpf->Gshift); \ -} while (0); +} while (0)#define setBlue (b, pcolor) do { \ *pcolor = ((*pcolor) & (~(dpf->Bmask))) + \ (((b) & (dpf->Bmask >> dpf->Bshift)) << dpf->Bshift); \ -} while (0); +} while (0)#define setAlpha (a, pcolor) do { \ *pcolor = ((*pcolor) & (~(dpf->Amask))) + \ (((a) & (dpf->Amask >> dpf->Ashift)) << dpf->Ashift); \ -} while (0); +} while (0)static void glue (sdl_zoom_rgb ,BPP )(SDL_Surface *src,SDL_Surface *dst,int smooth,SDL_Rect *dst_rect)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 47/52] find_ram_offset: Add comments and tracing
In reply to Paolo BonziniFrom: "Dr. David Alan Gilbert" <[email protected]>
Add some comments so I can understand the various nested loops. Add some tracing so I can see what they're doing.
Message-Id: <[email protected]>
--- exec.c | 29 ++++++++++++++++++++++------- trace-events | 4 ++++ 2 files changed, 26 insertions(+), 7 deletions(-)
exec.c +22 -7
@@ -1660,7 +1660,10 @@ static void *file_ram_alloc(RAMBlock *block, }#endif -/* Called with the ramlist lock held. */ +/* Allocate space within the ram_addr_t space that governs the +* dirty bitmaps. +* Called with the ramlist lock held. +*/ static ram_addr_t find_ram_offset (ram_addr_t size) {RAMBlock *block, *next_block;
@@ -1673,19 +1676,29 @@ static ram_addr_t find_ram_offset(ram_addr_t size) }RAMBLOCK_FOREACH (block) { -ram_addr_t end, next =RAM_ADDR_MAX ; +ram_addr_t candidate, next =RAM_ADDR_MAX ; - end = block->offset + block->max_length; + candidate = block->offset + block->max_length; +/* Search for the closest following block +* and find the gap. +*/ RAMBLOCK_FOREACH (next_block) { -if (next_block->offset >= end) { +if (next_block->offset >= candidate) { next =MIN (next, next_block->offset); } } -if (next - end >= size && next - end < mingap) { - offset = end; - mingap = next - end; + +/* If it fits remember our place and remember the size +* of gap, but keep going so that we might find a smaller +* gap to fill so avoiding fragmentation. +*/ +if (next - candidate >= size && next - candidate < mingap) { + offset = candidate; + mingap = next - candidate; } + +trace_find_ram_offset_loop (size, candidate, offset, next, mingap); }if (offset ==RAM_ADDR_MAX ) {
@@ -1694,6 +1707,8 @@ static ram_addr_t find_ram_offset(ram_addr_t size)abort (); } +trace_find_ram_offset (size, offset); +return offset; }
trace-events +4 -0
@@ -55,6 +55,10 @@ dma_complete(void *dbs, int ret, void *cb) "dbs=%p ret=%d cb=%p" dma_blk_cb(void *dbs, int ret) "dbs=%p ret=%d" dma_map_wait(void *dbs) "dbs=%p" +# # exec.c +find_ram_offset(uint64_t size, uint64_t offset) "size: 0x%" PRIx64 " @ 0x%" PRIx64 +find_ram_offset_loop(uint64_t size, uint64_t candidate, uint64_t offset, uint64_t next, uint64_t mingap) "trying size: 0x%" PRIx64 " @ 0x%" PRIx64 ", offset: 0x%" PRIx64" next: 0x%" PRIx64 " mingap: 0x%" PRIx64 + # memory.c memory_region_ops_read(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u" memory_region_ops_write(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u"
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 48/52] find_ram_offset: Align ram_addr_t allocation on long boundaries
In reply to Paolo BonziniFrom: "Dr. David Alan Gilbert" <[email protected]>
The dirty bitmaps are built from 'long's and there is fast-path code for synchronising the case where the RAMBlock is aligned to the start of a long boundary. Align the allocation to this boundary to cause the fast path to be used.
Offsets before change:
[email protected]:find_ram_offset size: 0x1e0000 @ 0x8000000 [email protected]:find_ram_offset size: 0x20000 @ 0x81e0000 [email protected]:find_ram_offset size: 0x20000 @ 0x8200000 [email protected]:find_ram_offset size: 0x1000000 @ 0x8220000 [email protected]:find_ram_offset size: 0x10000 @ 0x9220000 [email protected]:find_ram_offset size: 0x40000 @ 0x9230000 [email protected]:find_ram_offset size: 0x200000 @ 0x9270000 [email protected]:find_ram_offset size: 0x1000 @ 0x9470000 [email protected]:find_ram_offset size: 0x1000 @ 0x9471000
after change:
[email protected]:find_ram_offset size: 0x1e0000 @ 0x8000000 [email protected]:find_ram_offset size: 0x20000 @ 0x8200000 [email protected]:find_ram_offset size: 0x20000 @ 0x8240000 [email protected]:find_ram_offset size: 0x1000000 @ 0x8280000 [email protected]:find_ram_offset size: 0x10000 @ 0x9280000 [email protected]:find_ram_offset size: 0x40000 @ 0x92c0000 [email protected]:find_ram_offset size: 0x200000 @ 0x9300000 [email protected]:find_ram_offset size: 0x1000 @ 0x9500000 [email protected]:find_ram_offset size: 0x1000 @ 0x9540000
Message-Id: <[email protected]>
--- exec.c | 4 ++++ 1 file changed, 4 insertions(+)
exec.c +4 -0
@@ -1678,7 +1678,11 @@ static ram_addr_t find_ram_offset(ram_addr_t size)RAMBLOCK_FOREACH (block) {ram_addr_t candidate, next =RAM_ADDR_MAX ; +/* Align blocks to start on a 'long' in the bitmap +* which makes the bitmap sync'ing take the fast path. +*/ candidate = block->offset + block->max_length; + candidate =ROUND_UP (candidate,BITS_PER_LONG <<TARGET_PAGE_BITS );/* Search for the closest following block * and find the gap.
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 49/52] block/iscsi: fix initialization of iTask in iscsi_co_get_block_status
In reply to Paolo BonziniFrom: Peter Lieven <[email protected]>
in case of unaligned requests or on a target that does not support block provisioning we leave iTask uninitialized and check iTask.task for NULL later.
Message-Id: <[email protected]>
--- block/iscsi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
block/iscsi.c +2 -1
@@ -658,6 +658,8 @@ static int64_t coroutine_fn iscsi_co_get_block_status(BlockDriverState *bs,uint64_t lba;int64_t ret; +iscsi_co_init_iscsitask (iscsilun, &iTask); +if (!is_sector_request_lun_aligned (sector_num, nb_sectors, iscsilun)) { ret = -EINVAL ; goto out;
@@ -675,7 +677,6 @@ static int64_t coroutine_fn iscsi_co_get_block_status(BlockDriverState *bs, lba =sector_qemu2lun (sector_num, iscsilun); -iscsi_co_init_iscsitask (iscsilun, &iTask);qemu_mutex_lock (&iscsilun->mutex); retry: if (iscsi_get_lba_status_task(iscsilun->iscsi, iscsilun->lun,
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 50/52] cpu: flush TB cache when loading VMState
In reply to Paolo BonziniFrom: Pavel Dovgalyuk <[email protected]>
Flushing TB cache is required because TBs key in the cache may match different code which existed in the previous state.
Message-Id: <20180110134846.12940.99993.stgit@pasha-VirtualBox>
--- exec.c | 7 +++++++ 1 file changed, 7 insertions(+)
exec.c +7 -0
@@ -623,6 +623,13 @@ static int cpu_common_post_load(void *opaque, int version_id) cpu->interrupt_request &= ~0x01 ;tlb_flush (cpu); +/* loadvm has just updated the content of RAM, bypassing the +* usual mechanisms that ensure we flush TBs for writes to +* memory we've translated code from. So we must flush all TBs, +* which will now be stale. +*/ +tb_flush (cpu); +return 0 ; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 51/52] util/qemu-thread-*: add qemu_lock, locked and unlock trace events
In reply to Paolo BonziniFrom: Alex Bennée <[email protected]>
--- include/qemu/thread.h | 39 +++++++++++++++++++++++++++++++++++---- util/qemu-thread-posix.c | 21 ++++++++++++--------- util/qemu-thread-win32.c | 20 +++++++++++--------- util/trace-events | 7 ++++--- 4 files changed, 62 insertions(+), 25 deletions(-)
include/qemu/thread.h +35 -4
@@ -22,9 +22,31 @@ typedef struct QemuThread QemuThread;void qemu_mutex_init (QemuMutex *mutex);void qemu_mutex_destroy (QemuMutex *mutex); -void qemu_mutex_lock (QemuMutex *mutex); -int qemu_mutex_trylock (QemuMutex *mutex); -void qemu_mutex_unlock (QemuMutex *mutex); +int qemu_mutex_trylock_impl (QemuMutex *mutex,const char *file,const int line); +void qemu_mutex_lock_impl (QemuMutex *mutex,const char *file,const int line); +void qemu_mutex_unlock_impl (QemuMutex *mutex,const char *file,const int line); + +#define qemu_mutex_lock (mutex) \ + qemu_mutex_lock_impl(mutex, __FILE__, __LINE__) +#define qemu_mutex_trylock (mutex) \ + qemu_mutex_trylock_impl(mutex, __FILE__, __LINE__) +#define qemu_mutex_unlock (mutex) \ + qemu_mutex_unlock_impl(mutex, __FILE__, __LINE__) + +static inline void (qemu_mutex_lock)(QemuMutex *mutex) +{ +qemu_mutex_lock (mutex); +} + +static inline int (qemu_mutex_trylock)(QemuMutex *mutex) +{ +return qemu_mutex_trylock (mutex); +} + +static inline void (qemu_mutex_unlock)(QemuMutex *mutex) +{ +qemu_mutex_unlock (mutex); +}/* Prototypes for other functions are in thread-posix.h/thread-win32.h. */ void qemu_rec_mutex_init (QemuRecMutex *mutex);
@@ -39,7 +61,16 @@ void qemu_cond_destroy(QemuCond *cond);*/ void qemu_cond_signal (QemuCond *cond);void qemu_cond_broadcast (QemuCond *cond); -void qemu_cond_wait (QemuCond *cond,QemuMutex *mutex); +void qemu_cond_wait_impl (QemuCond *cond,QemuMutex *mutex, +const char *file,const int line); + +#define qemu_cond_wait (cond, mutex) \ + qemu_cond_wait_impl(cond, mutex, __FILE__, __LINE__) + +static inline void (qemu_cond_wait)(QemuCond *cond,QemuMutex *mutex) +{ +qemu_cond_wait (cond, mutex); +}void qemu_sem_init (QemuSemaphore *sem,int init);void qemu_sem_post (QemuSemaphore *sem);
util/qemu-thread-posix.c +12 -9
@@ -57,26 +57,28 @@ void qemu_mutex_destroy(QemuMutex *mutex)error_exit (err, __func__); } -void qemu_mutex_lock (QemuMutex *mutex) +void qemu_mutex_lock_impl (QemuMutex *mutex,const char *file,const int line) {int err;assert (mutex->initialized); +trace_qemu_mutex_lock (mutex, file, line); + err =pthread_mutex_lock (&mutex->lock);if (err)error_exit (err, __func__); -trace_qemu_mutex_locked (mutex); +trace_qemu_mutex_locked (mutex, file, line); } -int qemu_mutex_trylock (QemuMutex *mutex) +int qemu_mutex_trylock_impl (QemuMutex *mutex,const char *file,const int line) {int err;assert (mutex->initialized); err =pthread_mutex_trylock (&mutex->lock);if (err ==0 ) { -trace_qemu_mutex_locked (mutex); +trace_qemu_mutex_locked (mutex, file, line);return 0 ; }if (err !=EBUSY ) {
@@ -85,15 +87,16 @@ int qemu_mutex_trylock(QemuMutex *mutex)return -EBUSY ; } -void qemu_mutex_unlock (QemuMutex *mutex) +void qemu_mutex_unlock_impl (QemuMutex *mutex,const char *file,const int line) {int err;assert (mutex->initialized); -trace_qemu_mutex_unlocked (mutex); err =pthread_mutex_unlock (&mutex->lock);if (err)error_exit (err, __func__); + +trace_qemu_mutex_unlock (mutex, file, line); }void qemu_rec_mutex_init (QemuRecMutex *mutex)
@@ -152,14 +155,14 @@ void qemu_cond_broadcast(QemuCond *cond)error_exit (err, __func__); } -void qemu_cond_wait (QemuCond *cond,QemuMutex *mutex) +void qemu_cond_wait_impl (QemuCond *cond,QemuMutex *mutex,const char *file,const int line) {int err;assert (cond->initialized); -trace_qemu_mutex_unlocked (mutex); +trace_qemu_mutex_unlock (mutex, file, line); err =pthread_cond_wait (&cond->cond, &mutex->lock); -trace_qemu_mutex_locked (mutex); +trace_qemu_mutex_locked (mutex, file, line);if (err)error_exit (err, __func__); }
util/qemu-thread-win32.c +11 -9
@@ -56,30 +56,32 @@ void qemu_mutex_destroy(QemuMutex *mutex)InitializeSRWLock (&mutex->lock); } -void qemu_mutex_lock (QemuMutex *mutex) +void qemu_mutex_lock_impl (QemuMutex *mutex,const char *file,const int line) {assert (mutex->initialized); +trace_qemu_mutex_lock (mutex, file, line); +AcquireSRWLockExclusive (&mutex->lock); -trace_qemu_mutex_locked (mutex); +trace_qemu_mutex_locked (mutex, file, line); } -int qemu_mutex_trylock (QemuMutex *mutex) +int qemu_mutex_trylock_impl (QemuMutex *mutex,const char *file,const int line) {int owned;assert (mutex->initialized); owned =TryAcquireSRWLockExclusive (&mutex->lock);if (owned) { -trace_qemu_mutex_locked (mutex); +trace_qemu_mutex_locked (mutex, file, line);return 0 ; }return -EBUSY ; } -void qemu_mutex_unlock (QemuMutex *mutex) +void qemu_mutex_unlock_impl (QemuMutex *mutex,const char *file,const int line) {assert (mutex->initialized); -trace_qemu_mutex_unlocked (mutex); +trace_qemu_mutex_unlock (mutex, file, line);ReleaseSRWLockExclusive (&mutex->lock); }
@@ -140,12 +142,12 @@ void qemu_cond_broadcast(QemuCond *cond)WakeAllConditionVariable (&cond->var); } -void qemu_cond_wait (QemuCond *cond,QemuMutex *mutex) +void qemu_cond_wait_impl (QemuCond *cond,QemuMutex *mutex,const char *file,const int line) {assert (cond->initialized); -trace_qemu_mutex_unlocked (mutex); +trace_qemu_mutex_unlock (mutex, file, line);SleepConditionVariableSRW (&cond->var, &mutex->lock,INFINITE ,0 ); -trace_qemu_mutex_locked (mutex); +trace_qemu_mutex_locked (mutex, file, line); }void qemu_sem_init (QemuSemaphore *sem,int init)
util/trace-events +4 -3
@@ -56,6 +56,7 @@ lockcnt_futex_wait(const void *lockcnt, int val) "lockcnt %p waiting on %d" lockcnt_futex_wait_resume(const void *lockcnt, int new) "lockcnt %p after wait: %d" lockcnt_futex_wake(const void *lockcnt) "lockcnt %p waking up one waiter" -# util/qemu-thread-posix.c -qemu_mutex_locked(void *lock) "locked mutex %p" -qemu_mutex_unlocked(void *lock) "unlocked mutex %p" +# util/qemu-thread.c +qemu_mutex_lock(void *mutex, const char *file, const int line) "waiting on mutex %p (%s:%d)" +qemu_mutex_locked(void *mutex, const char *file, const int line) "taken mutex %p (%s:%d)" +qemu_mutex_unlock(void *mutex, const char *file, const int line) "released mutex %p (%s:%d)"
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 52/52] scripts/analyse-locks-simpletrace.py: script to analyse lock times
In reply to Paolo BonziniFrom: Alex Bennée <[email protected]>
This script allows analysis of mutex acquisition and hold times based on a trace file. Given a trace control file of:
qemu_mutex_lock
qemu_mutex_locked
qemu_mutex_unlock
And running with:
$QEMU $QEMU_ARGS -trace events=./lock-trace
You can analyse the results with:
./scripts/analyse-locks-simpletrace.py trace-events-all ./trace-21812
--- scripts/analyse-locks-simpletrace.py | 99 ++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100755 scripts/analyse-locks-simpletrace.py
scripts/analyse-locks-simpletrace.py new file +99 -0
@@ -0,0 +1,99 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Analyse lock events and +# +# Author: Alex Bennée <[email protected]> +# + +import os +import simpletrace +import argparse +import numpy as np + +class MutexAnalyser(simpletrace.Analyzer): + "A simpletrace Analyser for checking locks." + + def __init__(self): + self.locks = 0 + self.locked = 0 + self.unlocks = 0 + self.mutex_records = {} + + def _get_mutex(self, mutex): + if not mutex in self.mutex_records: + self.mutex_records[mutex] = {"locks": 0, + "lock_time": 0, + "acquire_times": [], + "locked": 0, + "locked_time": 0, + "held_times": [], + "unlocked": 0} + + return self.mutex_records[mutex] + + def qemu_mutex_lock(self, timestamp, mutex, filename, line): + self.locks += 1 + rec = self._get_mutex(mutex) + rec["locks"] += 1 + rec["lock_time"] = timestamp[0] + rec["lock_loc"] = (filename, line) + + def qemu_mutex_locked(self, timestamp, mutex, filename, line): + self.locked += 1 + rec = self._get_mutex(mutex) + rec["locked"] += 1 + rec["locked_time"] = timestamp[0] + acquire_time = rec["locked_time"] - rec["lock_time"] + rec["locked_loc"] = (filename, line) + rec["acquire_times"].append(acquire_time) + + def qemu_mutex_unlock(self, timestamp, mutex, filename, line): + self.unlocks += 1 + rec = self._get_mutex(mutex) + rec["unlocked"] += 1 + held_time = timestamp[0] - rec["locked_time"] + rec["held_times"].append(held_time) + rec["unlock_loc"] = (filename, line) + + +def get_args(): + "Grab options" + parser = argparse.ArgumentParser() + parser.add_argument("--output", "-o", type=str, help="Render plot to file") + parser.add_argument("events", type=str, help='trace file read from') + parser.add_argument("tracefile", type=str, help='trace file read from') + return parser.parse_args() + +if __name__ == '__main__': + args = get_args() + + # Gather data from the trace + analyser = MutexAnalyser() + simpletrace.process(args.events, args.tracefile, analyser) + + print ("Total locks: %d, locked: %d, unlocked: %d" % + (analyser.locks, analyser.locked, analyser.unlocks)) + + # Now dump the individual lock stats + for key, val in sorted(analyser.mutex_records.iteritems(), + key=lambda (k,v): v["locks"]): + print ("Lock: %#x locks: %d, locked: %d, unlocked: %d" % + (key, val["locks"], val["locked"], val["unlocked"])) + + acquire_times = np.array(val["acquire_times"]) + if len(acquire_times) > 0: + print (" Acquire Time: min:%d median:%d avg:%.2f max:%d" % + (acquire_times.min(), np.median(acquire_times), + acquire_times.mean(), acquire_times.max())) + + held_times = np.array(val["held_times"]) + if len(held_times) > 0: + print (" Held Time: min:%d median:%d avg:%.2f max:%d" % + (held_times.min(), np.median(held_times), + held_times.mean(), held_times.max())) + + # Check if any locks still held + if val["locks"] > val["locked"]: + print (" LOCK HELD (%s:%s)" % (val["locked_loc"])) + print (" BLOCKED (%s:%s)" % (val["lock_loc"]))
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PULL 52/52] scripts/analyse-locks-simpletrace.py: script to analyse lock times
Quoted 30 lines · Paolo Bonzini
From: Alex Bennée <[email protected]>
This script allows analysis of mutex acquisition and hold times based on a trace file. Given a trace control file of:
qemu_mutex_lock
qemu_mutex_locked
qemu_mutex_unlockAnd running with:
$QEMU $QEMU_ARGS -trace events=./lock-trace
You can analyse the results with:
./scripts/analyse-locks-simpletrace.pytrace-events-all ./trace-21812Signed-off-by Alex Bennée <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- scripts/analyse-locks-simpletrace.py | 99 ++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100755 scripts/analyse-locks-simpletrace.pyscripts/analyse-locks-simpletrace.py new file +0
-0
scripts/analyse-locks-simpletrace.py line 5
Quoted 5 lines
scripts/analyse-locks-simpletrace.py new file +5
-0@@ -0,0 +1,99 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Analyse lock events and +#
Truncated sentence?
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org