Misc patches for soft freeze
The following changes since commit 4a83bf2f339d4b63ecd5ef48b9816c3b7ee24553:
Merge remote-tracking branch 'remotes/juanquintela/tags/migration/20180627' into staging (2018-06-28 15:31:42 +0100)
are available in the git repository at:
git://github.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to 4cd00cd65e8f3d6301426c1f223f676935b3e9b8:
tests/boot-serial: Do not delete the output file in case of errors (2018-06-28 19:05:39 +0200)
A separate pull request will come with Philippe's IEC unit series. This one is already big enough!
----------------------------------------------------------------
* "info mtree" improvements (Alexey)
* fake VPD block limits for SCSI passthrough (Daniel Barboza)
* chardev and main loop fixes (Daniel Berrangé, Sergio, Stefan)
* help fixes (Eduardo)
* pc-dimm refactoring (David)
* tests improvements and fixes (Emilio, Thomas)
* SVM emulation fixes (Jan)
* MemoryRegionCache fix (Eric)
* WHPX improvements (Justin)
* ESP cleanup (Mark)
* -overcommit option (Michael)
* qemu-pr-helper fixes (me)
* "info pic" improvements for x86 (Peter)
* x86 TCG emulation fixes (Richard)
* KVM slot handling fix (Shannon)
* Next round of deprecation (Thomas)
* Windows dump format support (Viktor)
----------------------------------------------------------------
Alexey Kardashevskiy (1):
memory/hmp: Print owners/parents in "info mtree"
Daniel Henrique Barboza (3):
hw/scsi: cleanups before VPD BL emulation hw/scsi: centralize SG_IO calls into single function hw/scsi: add VPD Block Limits emulation
Daniel P. Berrangé (1):
chardev: don't splatter terminal settings on exit if not previously set
David Hildenbrand (15):
memory-device: turn alignment assert into check
exec: check that alignment is a power of two
pc-dimm: remove leftover "struct pc_dimms_capacity"
pc: rename pc_dimm_(plug|unplug|...)* into pc_memory_(plug|unplug|...)*
pc-dimm: rename pc_dimm_memory_* to pc_dimm_*
pc-dimm: remove pc_dimm_get_free_slot() from header
pc: factor out pc specific dimm checks into pc_memory_pre_plug()
nvdimm: no need to overwrite get_vmstate_memory_region()
hostmem: drop error variable from host_memory_backend_get_memory()
pc-dimm: merge get_(vmstate_)memory_region()
nvdimm: convert "unarmed" into a static property
nvdimm: convert nvdimm_mr into a pointer
nvdimm: make get_memory_region() perform checks and initialization
pc-dimm: get_memory_region() will not fail after realize
numa: report all DIMM/NVDIMMs as plugged memory
Eduardo Habkost (1):
qemu-options: Add missing newline to -accel help text
Emilio G. Cota (1):
tests/atomic_add-bench: add -m option to use mutexes
Eric Auger (1):
exec: Fix MAP_RAM for cached access
Jan Kiszka (3):
target-i386: Add NMI interception to SVM
target-i386: Allow interrupt injection after STGI
target-i386: Mark cpu_vmexit noreturn
Justin Terry (VM) (2):
WHPX workaround bug in OSVW handling
WHPX: register for unrecognized MSR exits
Mark Cave-Ayland (2):
hw/mips/jazz: create ESP device directly via qdev
esp: remove legacy esp_init() function
Michael S. Tsirkin (2):
kvm: support -overcommit cpu-pm=on|off i386/cpu: make -cpu host support monitor/mwait
Paolo Bonzini (10):
move public invalidate APIs out of translate-all.{c,h}, clean up
whpx: commit missing file
QemuMutex: support --enable-debug-mutex
osdep: work around Coverity parsing errors
pr-helper: fix --socket-path default in help
pr-helper: fix assertion failure on failed multipath PERSISTENT RESERVE IN
pr-manager-helper: avoid SIGSEGV when writing to the socket fail
pr-manager: put stubs in .c file
pr-manager: add query-pr-managers QMP command
pr-manager-helper: report event on connection/disconnection
Peter Xu (7):
qemu-thread: introduce qemu-thread-common.h
configure: enable debug-mutex if debug enabled
doc: another fix to "info pic"
ioapic: support "info pic"
ioapic: some proper indents when dump info
ioapic: support "info irq"
hmp: obsolete "info ioapic"
Richard Henderson (1):
target/i386: Fix BLSR and BLSI
Sergio Lopez (1):
hw/char/serial: Only retry if qemu_chr_fe_write returns 0
Shannon Zhao (1):
kvm: Delete the slot if and only if the KVM_MEM_READONLY flag is changed
Stefan Hajnoczi (1):
main-loop: document IOCanReadHandler
Thomas Huth (3):
Replace '-enable-kvm' with '-accel kvm' in docs and help texts Deprecate the -enable-hax option
tests/boot-serial: Do not delete the output file in case of errors
Viktor Prutyanov (4):
dump: add Windows dump format to dump-guest-memory
dump: use system context in Windows dump
dump: add fallback KDBG using in Windows dump
dump: add Windows live system dump
Makefile.target | 1 + accel/kvm/kvm-all.c | 17 +- accel/tcg/translate-all.c | 28 +-- accel/tcg/translate-all.h | 1 - backends/hostmem.c | 3 +- chardev/char-stdio.c | 6 +- configure | 11 + docs/COLO-FT.txt | 8 +- docs/can.txt | 4 +- docs/multi-thread-compression.txt | 2 +- docs/multiseat.txt | 2 +- docs/specs/tpm.txt | 8 +- dump.c | 24 ++- exec.c | 39 +++- hmp-commands-info.hx | 9 +- hmp-commands.hx | 13 +- hmp.c | 9 +- hw/block/dataplane/virtio-blk.c | 4 +- hw/char/serial.c | 2 +- hw/i386/kvm/ioapic.c | 11 +- hw/i386/pc.c | 73 +++---- hw/intc/ioapic.c | 12 +- hw/intc/ioapic_common.c | 47 ++++- hw/mem/memory-device.c | 8 +- hw/mem/nvdimm.c | 93 +++++---- hw/mem/pc-dimm.c | 35 ++-- hw/mips/mips_jazz.c | 19 +- hw/misc/ivshmem.c | 3 +- hw/ppc/spapr.c | 18 +- hw/scsi/esp.c | 30 --- hw/scsi/scsi-disk.c | 427 +++++++++++++++++++------------------- hw/scsi/scsi-generic.c | 246 ++++++++++++++++------ hw/scsi/virtio-scsi-dataplane.c | 4 +- include/exec/exec-all.h | 8 +- include/exec/memory.h | 2 +- include/exec/ram_addr.h | 2 + include/hw/i386/ioapic_internal.h | 3 + include/hw/i386/pc.h | 3 - include/hw/mem/nvdimm.h | 2 +- include/hw/mem/pc-dimm.h | 17 +- include/hw/scsi/esp.h | 5 - include/hw/scsi/scsi.h | 6 +- include/qemu/main-loop.h | 14 ++ include/qemu/osdep.h | 15 ++ include/qemu/thread-posix.h | 4 + include/qemu/thread-win32.h | 4 + include/scsi/pr-manager.h | 11 +- include/sysemu/hostmem.h | 3 +- include/sysemu/kvm_int.h | 1 + include/sysemu/sysemu.h | 1 + linux-user/mmap.c | 1 - memory.c | 72 ++++++- memory_ldst.inc.c | 47 ++--- monitor.c | 4 +- numa.c | 9 +- qapi/block.json | 52 +++++ qapi/misc.json | 5 +- qemu-doc.texi | 5 + qemu-options.hx | 28 ++- scsi/Makefile.objs | 1 + scsi/pr-manager-helper.c | 28 +++ scsi/pr-manager-stub.c | 30 +++ scsi/pr-manager.c | 45 ++++ scsi/qemu-pr-helper.c | 21 +- target/i386/cpu.c | 19 +- target/i386/cpu.h | 13 +- target/i386/kvm.c | 32 +++ target/i386/monitor.c | 8 +- target/i386/seg_helper.c | 1 + target/i386/svm_helper.c | 1 + target/i386/translate.c | 29 +-- target/i386/whp-dispatch.h | 56 +++++ target/i386/whpx-all.c | 54 ++++- target/xtensa/op_helper.c | 9 +- tests/atomic_add-bench.c | 19 +- tests/boot-serial-test.c | 17 +- trace/control-target.c | 1 - util/qemu-thread-common.h | 55 +++++ util/qemu-thread-posix.c | 19 +- util/qemu-thread-win32.c | 17 +- vl.c | 33 ++- win_dump.c | 385 ++++++++++++++++++++++++++++++++++ win_dump.h | 176 ++++++++++++++++ 83 files changed, 1923 insertions(+), 687 deletions(-) create mode 100644 scsi/pr-manager-stub.c create mode 100644 target/i386/whp-dispatch.h create mode 100644 util/qemu-thread-common.h create mode 100644 win_dump.c create mode 100644 win_dump.h
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 01/60] exec: Fix MAP_RAM for cached access
From: Eric Auger <[email protected]>
When an IOMMUMemoryRegion is in front of a virtio device, address_space_cache_init does not set cache->ptr as the memory region is not RAM. However when the device performs an access, we end up in glue() which performs the translation and then uses MAP_RAM. This latter uses the unset ptr and returns a wrong value which leads to a SIGSEV in address_space_lduw_internal_cached_slow, for instance.
In slow path cache->ptr is NULL and MAP_RAM must redirect to qemu_map_ram_ptr((mr)->ram_block, ofs).
As MAP_RAM, IS_DIRECT and INVALIDATE are the same in _cached_slow and non cached mode, let's remove those macros.
This fixes the use cases featuring vIOMMU (Intel and ARM SMMU) which lead to a SIGSEV.
Message-Id: <[email protected]>
--- exec.c | 6 ------ memory_ldst.inc.c | 47 ++++++++++++++++++++++------------------------- 2 files changed, 22 insertions(+), 31 deletions(-)
exec.c +0 -6
@@ -3702,9 +3702,6 @@ void cpu_physical_memory_unmap(void *buffer, hwaddr len,#define ARG1 as#define SUFFIX #define TRANSLATE (...) address_space_translate(as, __VA_ARGS__) -#define IS_DIRECT (mr, is_write) memory_access_is_direct(mr, is_write) -#define MAP_RAM (mr, ofs) qemu_map_ram_ptr((mr)->ram_block, ofs) -#define INVALIDATE (mr, ofs, len) invalidate_and_set_dirty(mr, ofs, len)#define RCU_READ_LOCK (...) rcu_read_lock()#define RCU_READ_UNLOCK (...) rcu_read_unlock()#include "memory_ldst.inc.c"
@@ -3841,9 +3838,6 @@ address_space_write_cached_slow(MemoryRegionCache *cache, hwaddr addr,#define ARG1 cache#define SUFFIX _cached_slow#define TRANSLATE (...) address_space_translate_cached(cache, __VA_ARGS__) -#define IS_DIRECT (mr, is_write) memory_access_is_direct(mr, is_write) -#define MAP_RAM (mr, ofs) (cache->ptr + (ofs - cache->xlat)) -#define INVALIDATE (mr, ofs, len) invalidate_and_set_dirty(mr, ofs, len)#define RCU_READ_LOCK () ((void)0)#define RCU_READ_UNLOCK () ((void)0)#include "memory_ldst.inc.c"
memory_ldst.inc.c +22 -25
175 lines not on this page · raw message
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 02/60] move public invalidate APIs out of translate-all.{c, h}, clean up
In reply to Paolo BonziniPlace them in exec.c, exec-all.h and ram_addr.h. This removes knowledge of translate-all.h (which is an internal header) from several files outside accel/tcg and removes knowledge of AddressSpace from translate-all.c (as it only operates on ram_addr_t).
--- accel/tcg/translate-all.c | 28 ++++++---------------------- accel/tcg/translate-all.h | 1 - exec.c | 29 +++++++++++++++++++++++++---- include/exec/exec-all.h | 8 ++++---- include/exec/ram_addr.h | 2 ++ linux-user/mmap.c | 1 - target/xtensa/op_helper.c | 9 +-------- trace/control-target.c | 1 - 8 files changed, 38 insertions(+), 41 deletions(-)
accel/tcg/translate-all.c +6 -22
@@ -46,7 +46,7 @@#endif #endif #else -#include "exec/address-spaces.h" +#include "exec/ram_addr.h" #endif #include "exec/cputlb.h"
@@ -1934,7 +1934,11 @@ void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,* * Called with mmap_lock held for user-mode emulation. */ -void tb_invalidate_phys_range (tb_page_addr_t start,tb_page_addr_t end) +#ifdef CONFIG_SOFTMMU +void tb_invalidate_phys_range(ram_addr_t start, ram_addr_t end) +#else +void tb_invalidate_phys_range(target_ulong start, target_ulong end) +#endif {struct page_collection *pages;tb_page_addr_t next;
@@ -2073,26 +2077,6 @@ static bool tb_invalidate_phys_page(tb_page_addr_t addr, uintptr_t pc) }#endif -#if !defined(CONFIG_USER_ONLY ) -void tb_invalidate_phys_addr (AddressSpace *as,hwaddr addr,MemTxAttrs attrs) -{ -ram_addr_t ram_addr; -MemoryRegion *mr; -hwaddr l =1 ; - -rcu_read_lock (); - mr =address_space_translate (as, addr, &addr, &l, false, attrs); -if (!(memory_region_is_ram (mr) - ||memory_region_is_romd (mr))) { -rcu_read_unlock (); -return ; - } - ram_addr =memory_region_get_ram_addr (mr) + addr; -tb_invalidate_phys_page_range (ram_addr, ram_addr +1 ,0 ); -rcu_read_unlock (); -} -#endif /* !defined(CONFIG_USER_ONLY) */ -/* user-mode: call with mmap_lock held */ void tb_check_watchpoint (CPUState *cpu) {
accel/tcg/translate-all.h +0 -1
@@ -30,7 +30,6 @@ void tb_invalidate_phys_page_fast(struct page_collection *pages, tb_page_addr_t start, int len);void tb_invalidate_phys_page_range (tb_page_addr_t start,tb_page_addr_t end,int is_cpu_write_access); -void tb_invalidate_phys_range (tb_page_addr_t start,tb_page_addr_t end);void tb_check_watchpoint (CPUState *cpu);#ifdef CONFIG_USER_ONLY
exec.c +25 -4
@@ -1028,13 +1028,36 @@ const char *parse_cpu_model(const char *cpu_model) }#if defined(CONFIG_USER_ONLY ) -static void breakpoint_invalidate (CPUState *cpu,target_ulong pc) +void tb_invalidate_phys_addr (target_ulong addr) {mmap_lock (); -tb_invalidate_phys_page_range (pc, pc +1 ,0 ); +tb_invalidate_phys_page_range (addr, addr +1 ,0 );mmap_unlock (); } + +static void breakpoint_invalidate (CPUState *cpu,target_ulong pc) +{ +tb_invalidate_phys_addr (pc); +}#else +void tb_invalidate_phys_addr (AddressSpace *as,hwaddr addr,MemTxAttrs attrs) +{ +ram_addr_t ram_addr; +MemoryRegion *mr; +hwaddr l =1 ; + +rcu_read_lock (); + mr =address_space_translate (as, addr, &addr, &l, false, attrs); +if (!(memory_region_is_ram (mr) + ||memory_region_is_romd (mr))) { +rcu_read_unlock (); +return ; + } + ram_addr =memory_region_get_ram_addr (mr) + addr; +tb_invalidate_phys_page_range (ram_addr, ram_addr +1 ,0 ); +rcu_read_unlock (); +} +static void breakpoint_invalidate (CPUState *cpu,target_ulong pc) {MemTxAttrs attrs;
@@ -3146,9 +3169,7 @@ static void invalidate_and_set_dirty(MemoryRegion *mr, hwaddr addr, }if (dirty_log_mask & (1 <<DIRTY_MEMORY_CODE )) {assert (tcg_enabled ()); -mmap_lock ();tb_invalidate_phys_range (addr, addr + length); -mmap_unlock (); dirty_log_mask &= ~(1 <<DIRTY_MEMORY_CODE ); }cpu_physical_memory_set_dirty_range (addr, length, dirty_log_mask);
include/exec/exec-all.h +4 -4
@@ -299,14 +299,14 @@ static inline void tlb_flush_page_by_mmuidx_all_cpus_synced(CPUState *cpu,static inline void tlb_flush_by_mmuidx_all_cpus (CPUState *cpu,uint16_t idxmap) { } +static inline void tlb_flush_by_mmuidx_all_cpus_synced (CPUState *cpu,uint16_t idxmap) { } -static inline void tb_invalidate_phys_addr (AddressSpace *as,hwaddr addr, -MemTxAttrs attrs) -{ -} + +void tb_invalidate_phys_addr (target_ulong addr); +void tb_invalidate_phys_range (target_ulong start,target_ulong end);#endif #define CODE_GEN_ALIGN 16/* must be >= of the size of a icache line */
include/exec/ram_addr.h +2 -0
@@ -93,6 +93,8 @@ int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp);#define DIRTY_CLIENTS_ALL ((1 << DIRTY_MEMORY_NUM) - 1)#define DIRTY_CLIENTS_NOCODE (DIRTY_CLIENTS_ALL & ~(1 << DIRTY_MEMORY_CODE)) +void tb_invalidate_phys_range (ram_addr_t start,ram_addr_t end); +static inline bool cpu_physical_memory_get_dirty (ram_addr_t start,ram_addr_t length,unsigned client)
linux-user/mmap.c +0 -1
@@ -20,7 +20,6 @@#include "qemu.h" #include "qemu-common.h" -#include "translate-all.h" //#define DEBUG_MMAP
target/xtensa/op_helper.c +1 -8
@@ -36,11 +36,6 @@#include "qemu/timer.h" #include "fpu/softfloat.h" -#ifdef CONFIG_USER_ONLY -/* tb_invalidate_phys_range */ -#include "accel/tcg/translate-all.h" -#endif -#ifndef CONFIG_USER_ONLY void xtensa_cpu_do_unaligned_access(CPUState *cs,
@@ -114,9 +109,7 @@ static void tb_invalidate_virtual_addr(CPUXtensaState *env, uint32_t vaddr)static void tb_invalidate_virtual_addr (CPUXtensaState *env,uint32_t vaddr) { -mmap_lock (); -tb_invalidate_phys_range (vaddr, vaddr +1 ); -mmap_unlock (); +tb_invalidate_phys_addr (vaddr); }#endif
trace/control-target.c +0 -1
@@ -11,7 +11,6 @@#include "cpu.h" #include "trace-root.h" #include "trace/control.h" -#include "translate-all.h" void trace_event_set_state_dynamic_init (TraceEvent *ev,bool state)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 03/60] chardev: don't splatter terminal settings on exit if not previously set
In reply to Paolo BonziniFrom: Daniel P. Berrangé <[email protected]>
The stdio chardev finalize method calls term_exit() to restore the original terminal settings that were saved in the "oldtty" global. If the qemu_chr_open_stdio() method exited with an error, we might not have any original terminal settings saved in "oldtty" yet.
eg
$ qemu-system-x86_64 -monitor stdio -daemonize qemu-system-x86_64: -monitor stdio: cannot use stdio with -daemonize
will cause QEMU to splatter the terminal settings with an all-zeros "struct termios", with predictably unpleasant results. Fortunately the existing "stdio_in_use" flag is suitable witness for whether "oldtty" contains settings that need restoring.
Message-Id: <[email protected]>
--- chardev/char-stdio.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
chardev/char-stdio.c +4 -2
@@ -46,8 +46,10 @@ static bool stdio_echo_state;static void term_exit (void ) { -tcsetattr (0 ,TCSANOW , &oldtty); -fcntl (0 ,F_SETFL , old_fd0_flags); +if (stdio_in_use) { +tcsetattr (0 ,TCSANOW , &oldtty); +fcntl (0 ,F_SETFL , old_fd0_flags); + } }static void qemu_chr_set_echo_stdio (Chardev *chr,bool echo)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 04/60] main-loop: document IOCanReadHandler
In reply to Paolo BonziniFrom: Stefan Hajnoczi <[email protected]>
Message-Id: <[email protected]>
--- include/qemu/main-loop.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
include/qemu/main-loop.h +14 -0
@@ -168,6 +168,20 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);/* async I/O support */ typedef void IOReadHandler (void *opaque,const uint8_t *buf,int size); + +/** +* IOCanReadHandler: Return the number of bytes that #IOReadHandler can accept +* +* This function reports how many bytes #IOReadHandler is prepared to accept. +* #IOReadHandler may be invoked with up to this number of bytes. If this +* function returns 0 then #IOReadHandler is not invoked. +* +* This function is typically called from an event loop. If the number of +* bytes changes outside the event loop (e.g. because a vcpu thread drained the +* buffer), then it is necessary to kick the event loop so that this function +* is called again. aio_notify() or qemu_notify_event() can be used to kick +* the event loop. +*/ typedef int IOCanReadHandler (void *opaque);/**
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 05/60] hw/char/serial: Only retry if qemu_chr_fe_write returns 0
In reply to Paolo BonziniFrom: Sergio Lopez <[email protected]>
Only retry on serial_xmit if qemu_chr_fe_write returns 0, as this is the only recoverable error.
Retrying with any other scenario, in addition to being a waste of CPU cycles, can compromise the Guest stability if by the vCPU issuing the write and the main loop thread are, by chance or explicit pinning, running on the same pCPU.
Previous discussion:
https://lists.nongnu.org/archive/html/qemu-devel/2018-05/msg06998.html
Message-Id: <[email protected]>
--- hw/char/serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/char/serial.c +1 -1
@@ -260,7 +260,7 @@ static void serial_xmit(SerialState *s)if (s->mcr &UART_MCR_LOOP ) {/* in loopback mode, say that we just received a char */ serial_receive1 (s, &s->tsr,1 ); - }else if (qemu_chr_fe_write (&s->chr, &s->tsr,1 ) !=1 && + }else if (qemu_chr_fe_write (&s->chr, &s->tsr,1 ) ==0 && s->tsr_retry <MAX_XMIT_RETRY ) {assert (s->watch_tag ==0 ); s->watch_tag =
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 06/60] target/i386: Fix BLSR and BLSI
In reply to Paolo BonziniFrom: Richard Henderson <[email protected]>
The implementation of these two instructions was swapped. At the same time, unify the setup of eflags for the insn group.
Message-Id: <[email protected]>
--- target/i386/translate.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-)
target/i386/translate.c +9 -17
@@ -4059,34 +4059,26 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b, ot =mo_64_32 (s->dflag);gen_ldst_modrm (env, s, modrm, ot,OR_TMP0 ,0 ); +tcg_gen_mov_tl (cpu_cc_src, cpu_T0);switch (reg &7 ) {case 1 :/* blsr By,Ey */ -tcg_gen_neg_tl (cpu_T1, cpu_T0); +tcg_gen_subi_tl (cpu_T1, cpu_T0,1 );tcg_gen_and_tl (cpu_T0, cpu_T0, cpu_T1); -gen_op_mov_reg_v (ot, s->vex_v, cpu_T0); -gen_op_update2_cc (); -set_cc_op (s,CC_OP_BMILGB + ot);break ; -case 2 :/* blsmsk By,Ey */ -tcg_gen_mov_tl (cpu_cc_src, cpu_T0); -tcg_gen_subi_tl (cpu_T0, cpu_T0,1 ); -tcg_gen_xor_tl (cpu_T0, cpu_T0, cpu_cc_src); -tcg_gen_mov_tl (cpu_cc_dst, cpu_T0); -set_cc_op (s,CC_OP_BMILGB + ot); +tcg_gen_subi_tl (cpu_T1, cpu_T0,1 ); +tcg_gen_xor_tl (cpu_T0, cpu_T0, cpu_T1);break ; -case 3 :/* blsi By, Ey */ -tcg_gen_mov_tl (cpu_cc_src, cpu_T0); -tcg_gen_subi_tl (cpu_T0, cpu_T0,1 ); -tcg_gen_and_tl (cpu_T0, cpu_T0, cpu_cc_src); -tcg_gen_mov_tl (cpu_cc_dst, cpu_T0); -set_cc_op (s,CC_OP_BMILGB + ot); +tcg_gen_neg_tl (cpu_T1, cpu_T0); +tcg_gen_and_tl (cpu_T0, cpu_T0, cpu_T1);break ; -default : goto unknown_op; } +tcg_gen_mov_tl (cpu_cc_dst, cpu_T0); +gen_op_mov_reg_v (ot, s->vex_v, cpu_T0); +set_cc_op (s,CC_OP_BMILGB + ot);break ;default :
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 07/60] whpx: commit missing file
In reply to Paolo BonziniNot included by mistake in commit 327fccb288976f95808efa968082fc9d4a9ced84.
--- target/i386/whp-dispatch.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 target/i386/whp-dispatch.h
target/i386/whp-dispatch.h new file +56 -0
@@ -0,0 +1,56 @@ +#include "windows.h" +#include <stdbool.h> + +#include <WinHvPlatform.h> +#include <WinHvEmulation.h> + +#ifndef WHP_DISPATCH_H +#define WHP_DISPATCH_H + + +#define LIST_WINHVPLATFORM_FUNCTIONS(X) \ + X(HRESULT, WHvGetCapability, (WHV_CAPABILITY_CODE CapabilityCode, VOID* CapabilityBuffer, UINT32 CapabilityBufferSizeInBytes, UINT32* WrittenSizeInBytes)) \ + X(HRESULT, WHvCreatePartition, (WHV_PARTITION_HANDLE* Partition)) \ + X(HRESULT, WHvSetupPartition, (WHV_PARTITION_HANDLE Partition)) \ + X(HRESULT, WHvDeletePartition, (WHV_PARTITION_HANDLE Partition)) \ + X(HRESULT, WHvGetPartitionProperty, (WHV_PARTITION_HANDLE Partition, WHV_PARTITION_PROPERTY_CODE PropertyCode, VOID* PropertyBuffer, UINT32 PropertyBufferSizeInBytes, UINT32* WrittenSizeInBytes)) \ + X(HRESULT, WHvSetPartitionProperty, (WHV_PARTITION_HANDLE Partition, WHV_PARTITION_PROPERTY_CODE PropertyCode, const VOID* PropertyBuffer, UINT32 PropertyBufferSizeInBytes)) \ + X(HRESULT, WHvMapGpaRange, (WHV_PARTITION_HANDLE Partition, VOID* SourceAddress, WHV_GUEST_PHYSICAL_ADDRESS GuestAddress, UINT64 SizeInBytes, WHV_MAP_GPA_RANGE_FLAGS Flags)) \ + X(HRESULT, WHvUnmapGpaRange, (WHV_PARTITION_HANDLE Partition, WHV_GUEST_PHYSICAL_ADDRESS GuestAddress, UINT64 SizeInBytes)) \ + X(HRESULT, WHvTranslateGva, (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, WHV_GUEST_VIRTUAL_ADDRESS Gva, WHV_TRANSLATE_GVA_FLAGS TranslateFlags, WHV_TRANSLATE_GVA_RESULT* TranslationResult, WHV_GUEST_PHYSICAL_ADDRESS* Gpa)) \ + X(HRESULT, WHvCreateVirtualProcessor, (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, UINT32 Flags)) \ + X(HRESULT, WHvDeleteVirtualProcessor, (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex)) \ + X(HRESULT, WHvRunVirtualProcessor, (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, VOID* ExitContext, UINT32 ExitContextSizeInBytes)) \ + X(HRESULT, WHvCancelRunVirtualProcessor, (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, UINT32 Flags)) \ + X(HRESULT, WHvGetVirtualProcessorRegisters, (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, const WHV_REGISTER_NAME* RegisterNames, UINT32 RegisterCount, WHV_REGISTER_VALUE* RegisterValues)) \ + X(HRESULT, WHvSetVirtualProcessorRegisters, (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, const WHV_REGISTER_NAME* RegisterNames, UINT32 RegisterCount, const WHV_REGISTER_VALUE* RegisterValues)) \ + + +#define LIST_WINHVEMULATION_FUNCTIONS(X) \ + X(HRESULT, WHvEmulatorCreateEmulator, (const WHV_EMULATOR_CALLBACKS* Callbacks, WHV_EMULATOR_HANDLE* Emulator)) \ + X(HRESULT, WHvEmulatorDestroyEmulator, (WHV_EMULATOR_HANDLE Emulator)) \ + X(HRESULT, WHvEmulatorTryIoEmulation, (WHV_EMULATOR_HANDLE Emulator, VOID* Context, const WHV_VP_EXIT_CONTEXT* VpContext, const WHV_X64_IO_PORT_ACCESS_CONTEXT* IoInstructionContext, WHV_EMULATOR_STATUS* EmulatorReturnStatus)) \ + X(HRESULT, WHvEmulatorTryMmioEmulation, (WHV_EMULATOR_HANDLE Emulator, VOID* Context, const WHV_VP_EXIT_CONTEXT* VpContext, const WHV_MEMORY_ACCESS_CONTEXT* MmioInstructionContext, WHV_EMULATOR_STATUS* EmulatorReturnStatus)) \ + + +#define WHP_DEFINE_TYPE(return_type, function_name, signature) \ + typedef return_type (WINAPI *function_name ## _t) signature; + +#define WHP_DECLARE_MEMBER(return_type, function_name, signature) \ + function_name ## _t function_name; + +/* Define function typedef */ +LIST_WINHVPLATFORM_FUNCTIONS(WHP_DEFINE_TYPE) +LIST_WINHVEMULATION_FUNCTIONS(WHP_DEFINE_TYPE) + +struct WHPDispatch { + LIST_WINHVPLATFORM_FUNCTIONS(WHP_DECLARE_MEMBER) + LIST_WINHVEMULATION_FUNCTIONS(WHP_DECLARE_MEMBER) +}; + +extern struct WHPDispatch whp_dispatch; + +bool init_whp_dispatch(void); + + +#endif /* WHP_DISPATCH_H */
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 08/60] memory-device: turn alignment assert into check
In reply to Paolo BonziniFrom: David Hildenbrand <[email protected]>
The start of the address space indicates which maximum alignment is supported by our machine (e.g. ppc, x86 1GB). This is helpful to catch fragmenting guest physical memory in strange fashions.
Right now we can crash QEMU by e.g. (there might be easier examples)
qemu-system-x86_64 -m 256M,maxmem=20G,slots=2 \
-object memory-backend-file,id=mem0,size=8192M,mem-path=/dev/zero,align=8192M \
-device pc-dimm,id=dimm1,memdev=mem0
Message-Id: <[email protected]>
--- hw/mem/memory-device.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
hw/mem/memory-device.c +7 -1
@@ -116,9 +116,15 @@ uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint, address_space_start = ms->device_memory->base; address_space_end = address_space_start +memory_region_size (&ms->device_memory->mr); -g_assert (QEMU_ALIGN_UP (address_space_start, align) == address_space_start);g_assert (address_space_end >= address_space_start); +/* address_space_start indicates the maximum alignment we expect */ +if (QEMU_ALIGN_UP (address_space_start, align) != address_space_start) { +error_setg (errp,"the alignment (0%" PRIx64") is not supported" , + align); +return 0 ; + } +memory_device_check_addable (ms, size, errp);if (*errp) {return 0 ;
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 09/60] exec: check that alignment is a power of two
In reply to Paolo BonziniFrom: David Hildenbrand <[email protected]>
Right now we can crash QEMU using e.g.
qemu-system-x86_64 -m 256M,maxmem=20G,slots=2 \
-object memory-backend-file,id=mem0,size=12288,mem-path=/dev/zero,align=12288 \
-device pc-dimm,id=dimm1,memdev=mem0
qemu-system-x86_64: util/mmap-alloc.c:115:
qemu_ram_mmap: Assertion `is_power_of_2(align)' failed
Fix this by adding a proper check.
Message-Id: <[email protected]>
--- exec.c | 4 ++++ 1 file changed, 4 insertions(+)
exec.c +4 -0
@@ -1841,6 +1841,10 @@ static void *file_ram_alloc(RAMBlock *block," must be multiples of page size 0x%zx" , block->mr->align, block->page_size);return NULL ; + }else if (block->mr->align && !is_power_of_2 (block->mr->align)) { +error_setg (errp,"alignment 0x%" PRIx64 +" must be a power of two" , block->mr->align); +return NULL ; } block->mr->align =MAX (block->page_size, block->mr->align);#if defined(__s390x__)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 10/60] kvm: Delete the slot if and only if the KVM_MEM_READONLY flag is changed
In reply to Paolo BonziniFrom: Shannon Zhao <[email protected]>
According to KVM commit 75d61fbc, it needs to delete the slot before changing the KVM_MEM_READONLY flag. But QEMU commit 235e8982 only check whether KVM_MEM_READONLY flag is set instead of changing. It doesn't need to delete the slot if the KVM_MEM_READONLY flag is not changed.
This fixes a issue that migrating a VM at the OVMF startup stage and VM is executing the codes in rom. Between the deleting and adding the slot in kvm_set_user_memory_region, there is a chance that guest access rom and trap to KVM, then KVM can't find the corresponding memslot. While KVM (on ARM) injects an abort to guest due to the broken hva, then guest will get stuck.
Message-Id: <[email protected]>
--- accel/kvm/kvm-all.c | 17 ++++++++--------- include/sysemu/kvm_int.h | 1 + 2 files changed, 9 insertions(+), 9 deletions(-)
accel/kvm/kvm-all.c +8 -9
@@ -256,7 +256,7 @@ int kvm_physical_memory_addr_from_host(KVMState *s, void *ram,return 0 ; } -static int kvm_set_user_memory_region (KVMMemoryListener *kml,KVMSlot *slot) +static int kvm_set_user_memory_region (KVMMemoryListener *kml,KVMSlot *slot,bool new) {KVMState *s = kvm_state;struct kvm_userspace_memory_region mem;
@@ -267,7 +267,7 @@ static int kvm_set_user_memory_region(KVMMemoryListener *kml, KVMSlot *slot) mem.userspace_addr = (unsigned long )slot->ram; mem.flags = slot->flags; -if (slot->memory_size && mem.flags &KVM_MEM_READONLY ) { +if (slot->memory_size && !new && (mem.flags ^ slot->old_flags) &KVM_MEM_READONLY ) {/* Set the slot size to 0 before setting the slot to the desired * value. This is needed based on KVM commit 75d61fbc. */ mem.memory_size =0 ;
@@ -275,6 +275,7 @@ static int kvm_set_user_memory_region(KVMMemoryListener *kml, KVMSlot *slot) } mem.memory_size = slot->memory_size; ret =kvm_vm_ioctl (s,KVM_SET_USER_MEMORY_REGION , &mem); + slot->old_flags = mem.flags;trace_kvm_set_user_memory (mem.slot, mem.flags, mem.guest_phys_addr, mem.memory_size, mem.userspace_addr, ret);return ret;
@@ -391,17 +392,14 @@ static int kvm_mem_flags(MemoryRegion *mr)static int kvm_slot_update_flags (KVMMemoryListener *kml,KVMSlot *mem,MemoryRegion *mr) { -int old_flags; - - old_flags = mem->flags; mem->flags =kvm_mem_flags (mr);/* If nothing changed effectively, no need to issue ioctl */ -if (mem->flags == old_flags) { +if (mem->flags == mem->old_flags) {return 0 ; } -return kvm_set_user_memory_region (kml, mem); +return kvm_set_user_memory_region (kml, mem, false); } static int kvm_section_update_flags(KVMMemoryListener *kml,
@@ -755,7 +753,8 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml,/* unregister the slot */ mem->memory_size =0 ; - err =kvm_set_user_memory_region (kml, mem); + mem->flags =0 ; + err =kvm_set_user_memory_region (kml, mem, false);if (err) {fprintf (stderr,"%s: error unregistering slot: %s\n" , __func__,strerror (-err));
@@ -771,7 +770,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, mem->ram = ram; mem->flags =kvm_mem_flags (mr); - err =kvm_set_user_memory_region (kml, mem); + err =kvm_set_user_memory_region (kml, mem, true);if (err) {fprintf (stderr,"%s: error registering slot: %s\n" , __func__,strerror (-err));
include/sysemu/kvm_int.h +1 -0
@@ -20,6 +20,7 @@ typedef struct KVMSlotvoid *ram;int slot;int flags; +int old_flags; } KVMSlot; typedef struct KVMMemoryListener {
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 11/60] tests/atomic_add-bench: add -m option to use mutexes
In reply to Paolo BonziniFrom: "Emilio G. Cota" <[email protected]>
This allows us to use atomic-add-bench as a microbenchmark for evaluating qemu_mutex_lock's performance.
Message-Id: <[email protected]>
--- tests/atomic_add-bench.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
tests/atomic_add-bench.c +17 -2
@@ -8,6 +8,7 @@ struct thread_info { }QEMU_ALIGNED (64 );struct count { +QemuMutex lock;unsigned long val; } QEMU_ALIGNED(64);
@@ -18,11 +19,13 @@ static unsigned int n_ready_threads;static struct count *counts;static unsigned int duration =1 ;static unsigned int range =1024 ; +static bool use_mutex;static bool test_start;static bool test_stop;static const char commands_string[] =" -n = number of threads\n" +" -m = use mutexes instead of atomic increments\n" " -d = duration in seconds\n" " -r = range (will be rounded up to pow2)" ;
@@ -59,7 +62,13 @@ static void *thread_func(void *arg) info->r =xorshift64star (info->r); index = info->r & (range -1 ); -atomic_inc (&counts[index].val); +if (use_mutex) { +qemu_mutex_lock (&counts[index].lock); + counts[index].val +=1 ; +qemu_mutex_unlock (&counts[index].lock); + }else { +atomic_inc (&counts[index].val); + } }return NULL ; }
@@ -91,6 +100,9 @@ static void create_threads(void) th_info = g_new(struct thread_info, n_threads); counts =qemu_memalign (64 ,sizeof (*counts) * range);memset (counts,0 ,sizeof (*counts) * range); +for (i =0 ; i < range; i++) { +qemu_mutex_init (&counts[i].lock); + }for (i =0 ; i < n_threads; i++) {struct thread_info *info = &th_info[i];
@@ -131,7 +143,7 @@ static void parse_args(int argc, char *argv[])int c;for (;;) { - c =getopt (argc, argv,"hd:n:r:" ); + c =getopt (argc, argv,"hd:n:mr:" );if (c <0 ) {break ; }
@@ -145,6 +157,9 @@ static void parse_args(int argc, char *argv[])case 'n' : n_threads =atoi (optarg);break ; +case 'm' : + use_mutex = true; +break ;case 'r' : range =pow2ceil (atoi (optarg));break ;
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 12/60] qemu-thread: introduce qemu-thread-common.h
In reply to Paolo BonziniFrom: Peter Xu <[email protected]>
Introduce some hooks for the shared part of qemu thread between POSIX and Windows implementations. Note that in qemu_mutex_unlock_impl() we moved the call before unlock operation which should make more sense. And we don't need qemu_mutex_post_unlock() hook.
Put all these shared hooks into the header files. It should be internal to qemu-thread but not for qemu-thread users, hence put into util/ directory.
Message-Id: <[email protected]>
--- util/qemu-thread-common.h | 43 +++++++++++++++++++++++++++++++++++++++++++ util/qemu-thread-posix.c | 19 ++++++++----------- util/qemu-thread-win32.c | 17 ++++++++--------- 3 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 util/qemu-thread-common.h
util/qemu-thread-common.h new file +43 -0
@@ -0,0 +1,43 @@ +/* +* Common qemu-thread implementation header file. +* +* Copyright Red Hat, Inc. 2018 +* +* Authors: +* Peter Xu <[email protected]>, +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef QEMU_THREAD_COMMON_H +#define QEMU_THREAD_COMMON_H + +#include "qemu/typedefs.h" +#include "qemu/thread.h" +#include "trace.h" + +static inline void qemu_mutex_post_init (QemuMutex *mutex) +{ + mutex->initialized = true; +} + +static inline void qemu_mutex_pre_lock (QemuMutex *mutex, +const char *file,int line) +{ +trace_qemu_mutex_lock (mutex, file, line); +} + +static inline void qemu_mutex_post_lock (QemuMutex *mutex, +const char *file,int line) +{ +trace_qemu_mutex_locked (mutex, file, line); +} + +static inline void qemu_mutex_pre_unlock (QemuMutex *mutex, +const char *file,int line) +{ +trace_qemu_mutex_unlock (mutex, file, line); +} + +#endif
util/qemu-thread-posix.c +8 -11
@@ -14,7 +14,7 @@#include "qemu/thread.h" #include "qemu/atomic.h" #include "qemu/notify.h" -#include "trace.h" +#include "qemu-thread-common.h" static bool name_threads;
@@ -43,7 +43,7 @@ void qemu_mutex_init(QemuMutex *mutex) err =pthread_mutex_init (&mutex->lock,NULL );if (err)error_exit (err, __func__); - mutex->initialized = true; +qemu_mutex_post_init (mutex); }void qemu_mutex_destroy (QemuMutex *mutex)
@@ -62,13 +62,11 @@ 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); - +qemu_mutex_pre_lock (mutex, file, line); err =pthread_mutex_lock (&mutex->lock);if (err)error_exit (err, __func__); - -trace_qemu_mutex_locked (mutex, file, line); +qemu_mutex_post_lock (mutex, file, line); }int qemu_mutex_trylock_impl (QemuMutex *mutex,const char *file,const int line)
@@ -78,7 +76,7 @@ int qemu_mutex_trylock_impl(QemuMutex *mutex, const char *file, const int line)assert (mutex->initialized); err =pthread_mutex_trylock (&mutex->lock);if (err ==0 ) { -trace_qemu_mutex_locked (mutex, file, line); +qemu_mutex_post_lock (mutex, file, line);return 0 ; }if (err !=EBUSY ) {
@@ -92,11 +90,10 @@ void qemu_mutex_unlock_impl(QemuMutex *mutex, const char *file, const int line)int err;assert (mutex->initialized); +qemu_mutex_pre_unlock (mutex, file, line); 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)
@@ -160,9 +157,9 @@ void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mutex, const char *file, conint err;assert (cond->initialized); -trace_qemu_mutex_unlock (mutex, file, line); +qemu_mutex_pre_unlock (mutex, file, line); err =pthread_cond_wait (&cond->cond, &mutex->lock); -trace_qemu_mutex_locked (mutex, file, line); +qemu_mutex_post_lock (mutex, file, line);if (err)error_exit (err, __func__); }
util/qemu-thread-win32.c +8 -9
@@ -19,7 +19,7 @@#include "qemu-common.h" #include "qemu/thread.h" #include "qemu/notify.h" -#include "trace.h" +#include "qemu-thread-common.h" #include <process.h> static bool name_threads;
@@ -46,7 +46,7 @@ static void error_exit(int err, const char *msg)void qemu_mutex_init (QemuMutex *mutex) {InitializeSRWLock (&mutex->lock); - mutex->initialized = true; +qemu_mutex_post_init (mutex); }void qemu_mutex_destroy (QemuMutex *mutex)
@@ -59,10 +59,9 @@ void qemu_mutex_destroy(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); - +qemu_mutex_pre_lock (mutex, file, line);AcquireSRWLockExclusive (&mutex->lock); -trace_qemu_mutex_locked (mutex, file, line); +qemu_mutex_post_lock (mutex, file, line); }int qemu_mutex_trylock_impl (QemuMutex *mutex,const char *file,const int line)
@@ -72,7 +71,7 @@ int qemu_mutex_trylock_impl(QemuMutex *mutex, const char *file, const int line)assert (mutex->initialized); owned =TryAcquireSRWLockExclusive (&mutex->lock);if (owned) { -trace_qemu_mutex_locked (mutex, file, line); +qemu_mutex_post_lock (mutex, file, line);return 0 ; }return -EBUSY ;
@@ -81,7 +80,7 @@ int qemu_mutex_trylock_impl(QemuMutex *mutex, const char *file, const int line)void qemu_mutex_unlock_impl (QemuMutex *mutex,const char *file,const int line) {assert (mutex->initialized); -trace_qemu_mutex_unlock (mutex, file, line); +qemu_mutex_pre_unlock (mutex, file, line);ReleaseSRWLockExclusive (&mutex->lock); }
@@ -145,9 +144,9 @@ void qemu_cond_broadcast(QemuCond *cond)void qemu_cond_wait_impl (QemuCond *cond,QemuMutex *mutex,const char *file,const int line) {assert (cond->initialized); -trace_qemu_mutex_unlock (mutex, file, line); +qemu_mutex_pre_unlock (mutex, file, line);SleepConditionVariableSRW (&cond->var, &mutex->lock,INFINITE ,0 ); -trace_qemu_mutex_locked (mutex, file, line); +qemu_mutex_post_lock (mutex, file, line); }void qemu_sem_init (QemuSemaphore *sem,int init)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 13/60] QemuMutex: support --enable-debug-mutex
In reply to Paolo BonziniWe have had some tracing tools for mutex but it's not easy to use them for e.g. dead locks. Let's provide "--enable-debug-mutex" parameter when configure to allow QemuMutex to store the last owner that took specific lock. It will be easy to use this tool to debug deadlocks since we can directly know who took the lock then as long as we can have a debugger attached to the process.
Message-Id: <[email protected]>
--- configure | 10 ++++++++++ include/qemu/thread-posix.h | 4 ++++ include/qemu/thread-win32.h | 4 ++++ util/qemu-thread-common.h | 12 ++++++++++++ 4 files changed, 30 insertions(+)
configure +10 -0
@@ -456,6 +456,7 @@ replication="yes" vxhs="" libxml2="" docker="no" +debug_mutex="no" # cross compilers defaults, can be overridden with --cross-cc-ARCH cross_cc_aarch64="aarch64-linux-gnu-gcc"
@@ -1411,6 +1412,10 @@ for opt do ;; --disable-git-update) git_update=no ;; + --enable-debug-mutex) debug_mutex=yes + ;; + --disable-debug-mutex) debug_mutex=no + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information"
@@ -1685,6 +1690,7 @@ disabled with --disable-FEATURE, default is enabled if available: crypto-afalg Linux AF_ALG crypto backend driver vhost-user vhost-user support capstone capstone disassembler support + debug-mutex mutex debugging support NOTE: The object files are built at the place where configure is launched EOF
@@ -5951,6 +5957,7 @@ echo "seccomp support $seccomp" echo "coroutine backend $coroutine" echo "coroutine pool $coroutine_pool" echo "debug stack usage $debug_stack_usage" +echo "mutex debugging $debug_mutex" echo "crypto afalg $crypto_afalg" echo "GlusterFS support $glusterfs" echo "gcov $gcov_tool"
@@ -6704,6 +6711,9 @@ fi if test "$capstone" != "no" ; then echo "CONFIG_CAPSTONE=y" >> $config_host_mak fi +if test "$debug_mutex" = "yes" ; then + echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak +fi # Hold two types of flag: # CONFIG_THREAD_SETNAME_BYTHREAD - we've got a way of setting the name on
include/qemu/thread-posix.h +4 -0
@@ -12,6 +12,10 @@ typedef QemuMutex QemuRecMutex;struct QemuMutex {pthread_mutex_t lock; +#ifdef CONFIG_DEBUG_MUTEX +const char *file; +int line; +#endif bool initialized; };
include/qemu/thread-win32.h +4 -0
@@ -5,6 +5,10 @@struct QemuMutex {SRWLOCK lock; +#ifdef CONFIG_DEBUG_MUTEX +const char *file; +int line; +#endif bool initialized; };
util/qemu-thread-common.h +12 -0
@@ -19,6 +19,10 @@static inline void qemu_mutex_post_init (QemuMutex *mutex) { +#ifdef CONFIG_DEBUG_MUTEX + mutex->file =NULL ; + mutex->line =0 ; +#endif mutex->initialized = true; }
@@ -31,12 +35,20 @@ static inline void qemu_mutex_pre_lock(QemuMutex *mutex,static inline void qemu_mutex_post_lock (QemuMutex *mutex,const char *file,int line) { +#ifdef CONFIG_DEBUG_MUTEX + mutex->file = file; + mutex->line = line; +#endif trace_qemu_mutex_locked (mutex, file, line); }static inline void qemu_mutex_pre_unlock (QemuMutex *mutex,const char *file,int line) { +#ifdef CONFIG_DEBUG_MUTEX + mutex->file =NULL ; + mutex->line =0 ; +#endif trace_qemu_mutex_unlock (mutex, file, line); }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 14/60] configure: enable debug-mutex if debug enabled
In reply to Paolo BonziniFrom: Peter Xu <[email protected]>
Message-Id: <[email protected]>
--- configure | 1 + 1 file changed, 1 insertion(+)
configure +1 -0
@@ -1042,6 +1042,7 @@ for opt do --enable-debug) # Enable debugging options that aren't excessively noisy debug_tcg="yes" + debug_mutex="yes" debug="yes" strip_opt="no" fortify_source="no"
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 15/60] Replace '-enable-kvm' with '-accel kvm' in docs and help texts
In reply to Paolo BonziniFrom: Thomas Huth <[email protected]>
The preferred way to select the KVM accelerator is to use "-accel kvm" these days, so let's be consistent in our documentation and help texts.
Message-Id: <[email protected]>
--- docs/COLO-FT.txt | 8 ++++---- docs/can.txt | 4 ++-- docs/multi-thread-compression.txt | 2 +- docs/multiseat.txt | 2 +- docs/specs/tpm.txt | 8 ++++---- hw/block/dataplane/virtio-blk.c | 4 ++-- hw/scsi/virtio-scsi-dataplane.c | 4 ++-- 7 files changed, 16 insertions(+), 16 deletions(-)
docs/COLO-FT.txt +4 -4
@@ -113,16 +113,16 @@ by using 'x-colo-lost-heartbeat' command. == Test procedure == 1. Startup qemu Primary: -# qemu-kvm -enable-kvm -m 2048 -smp 2 -qmp stdio -vnc :7 -name primary \ - -device piix3-usb-uhci \ +# qemu-system-x86_64 -accel kvm -m 2048 -smp 2 -qmp stdio -name primary \ + -device piix3-usb-uhci -vnc :7 \ -device usb-tablet -netdev tap,id=hn0,vhost=off \ -device virtio-net-pci,id=net-pci0,netdev=hn0 \ -drive if=virtio,id=primary-disk0,driver=quorum,read-pattern=fifo,vote-threshold=1,\ children.0.file.filename=1.raw,\ children.0.driver=raw -S Secondary: -# qemu-kvm -enable-kvm -m 2048 -smp 2 -qmp stdio -vnc :7 -name secondary \ - -device piix3-usb-uhci \ +# qemu-system-x86_64 -accel kvm -m 2048 -smp 2 -qmp stdio -name secondary \ + -device piix3-usb-uhci -vnc :7 \ -device usb-tablet -netdev tap,id=hn0,vhost=off \ -device virtio-net-pci,id=net-pci0,netdev=hn0 \ -drive if=none,id=secondary-disk0,file.filename=1.raw,driver=raw,node-name=node0 \
docs/can.txt +2 -2
@@ -52,7 +52,7 @@ The ''kvaser_pci'' board/device model is compatible with and has been tested wit The tested setup was Linux 4.9 kernel on the host and guest side. Example for qemu-system-x86_64: - qemu-system-x86_64 -enable-kvm -kernel /boot/vmlinuz-4.9.0-4-amd64 \ + qemu-system-x86_64 -accel kvm -kernel /boot/vmlinuz-4.9.0-4-amd64 \ -initrd ramdisk.cpio \ -virtfs local,path=shareddir,security_model=none,mount_tag=shareddir \ -object can-bus,id=canbus0 \
@@ -104,4 +104,4 @@ Links to other resources Slides http://rtime.felk.cvut.cz/publications/public/rtlws2015-qemu-can-slides.pdf (5) Linux SocketCAN utilities - https://github.com/linux-can/can-utils/ + https://github.com/linux-can/can-utils/
docs/multi-thread-compression.txt +1 -1
@@ -62,7 +62,7 @@ RAM: 128G NIC: Intel I350 (10/100/1000Mbps) Host OS: CentOS 7 64-bit Guest OS: RHEL 6.5 64-bit -Parameter: qemu-system-x86_64 -enable-kvm -smp 4 -m 4096 +Parameter: qemu-system-x86_64 -accel kvm -smp 4 -m 4096 /share/ia32e_rhel6u5.qcow -monitor stdio There is no additional application is running on the guest when doing
docs/multiseat.txt +1 -1
@@ -18,7 +18,7 @@ or Next put together the qemu command line (sdk/gtk): -qemu -enable-kvm -usb $memory $disk $whatever \ +qemu -accel kvm -usb $memory $disk $whatever \ -display [ sdl | gtk ] \ -vga std \ -device usb-tablet
docs/specs/tpm.txt +4 -4
@@ -98,7 +98,7 @@ QEMU files related to the TPM passthrough device: Command line to start QEMU with the TPM passthrough device using the host's hardware TPM /dev/tpm0: -qemu-system-x86_64 -display sdl -enable-kvm \ +qemu-system-x86_64 -display sdl -accel kvm \ -m 1024 -boot d -bios bios-256k.bin -boot menu=on \ -tpmdev passthrough,id=tpm0,path=/dev/tpm0 \ -device tpm-tis,tpmdev=tpm0 test.img
@@ -164,7 +164,7 @@ swtpm socket --tpmstate dir=/tmp/mytpm1 \ Command line to start QEMU with the TPM emulator device communicating with the swtpm: -qemu-system-x86_64 -display sdl -enable-kvm \ +qemu-system-x86_64 -display sdl -accel kvm \ -m 1024 -boot d -bios bios-256k.bin -boot menu=on \ -chardev socket,id=chrtpm,path=/tmp/mytpm1/swtpm-sock \ -tpmdev emulator,id=tpm0,chardev=chrtpm \
@@ -222,7 +222,7 @@ swtpm socket --tpmstate dir=/tmp/mytpm1 \ In a 2nd terminal start the VM: -qemu-system-x86_64 -display sdl -enable-kvm \ +qemu-system-x86_64 -display sdl -accel kvm \ -m 1024 -boot d -bios bios-256k.bin -boot menu=on \ -chardev socket,id=chrtpm,path=/tmp/mytpm1/swtpm-sock \ -tpmdev emulator,id=tpm0,chardev=chrtpm \
@@ -255,7 +255,7 @@ swtpm socket --tpmstate dir=/tmp/mytpm1 \ In the 2nd terminal restore the state of the VM using the additonal '-incoming' option. -qemu-system-x86_64 -display sdl -enable-kvm \ +qemu-system-x86_64 -display sdl -accel kvm \ -m 1024 -boot d -bios bios-256k.bin -boot menu=on \ -chardev socket,id=chrtpm,path=/tmp/mytpm1/swtpm-sock \ -tpmdev emulator,id=tpm0,chardev=chrtpm \
hw/block/dataplane/virtio-blk.c +2 -2
@@ -190,8 +190,8 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev)/* Set up guest notifier (irq) */ r = k->set_guest_notifiers (qbus->parent, nvqs, true);if (r !=0 ) { -fprintf (stderr,"virtio-blk failed to set guest notifier (%d), " -"ensure -enable-kvm is set\n" , r); +error_report ("virtio-blk failed to set guest notifier (%d), " +"ensure -accel kvm is set." , r); goto fail_guest_notifiers; }
hw/scsi/virtio-scsi-dataplane.c +2 -2
@@ -142,8 +142,8 @@ int virtio_scsi_dataplane_start(VirtIODevice *vdev)/* Set up guest notifier (irq) */ rc = k->set_guest_notifiers (qbus->parent, vs->conf.num_queues +2 , true);if (rc !=0 ) { -fprintf (stderr,"virtio-scsi: Failed to set guest notifiers (%d), " -"ensure -enable-kvm is set\n" , rc); +error_report ("virtio-scsi: Failed to set guest notifiers (%d), " +"ensure -accel kvm is set." , rc); goto fail_guest_notifiers; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 16/60] qemu-options: Add missing newline to -accel help text
In reply to Paolo BonziniFrom: Eduardo Habkost <[email protected]>
The newline was removed by commit c97d6d2c, and broke -help output:
Before this patch:
$ qemu-system-x86_64 -help | grep smp
thread=single|multi (enable multi-threaded TCG)-smp [...]After this patch:
$ qemu-system-x86_64 -help | grep smp -smp [cpus=]n[,maxcpus=cpus][,cores=cores][,threads=threads][,sockets=sockets]
Message-Id: <[email protected]>
--- qemu-options.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-options.hx +1 -1
@@ -130,7 +130,7 @@ ETEXI DEF("accel", HAS_ARG, QEMU_OPTION_accel, "-accel [accel=]accelerator[,thread=single|multi]\n" " select accelerator (kvm, xen, hax, hvf, whpx or tcg; use 'help' for a list)\n" - " thread=single|multi (enable multi-threaded TCG)", QEMU_ARCH_ALL) + " thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL) STEXI @item -accel @var{name}[,prop=@var{value}[,...]] @findex -accel
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 17/60] pc-dimm: remove leftover "struct pc_dimms_capacity"
In reply to Paolo BonziniFrom: David Hildenbrand <[email protected]>
Not needed anymore, let's drop it.
Message-Id: <[email protected]>
--- hw/mem/pc-dimm.c | 5 ----- 1 file changed, 5 deletions(-)
hw/mem/pc-dimm.c +0 -5
@@ -27,11 +27,6 @@#include "sysemu/numa.h" #include "trace.h" -typedef struct pc_dimms_capacity { -uint64_t size; -Error **errp; -}pc_dimms_capacity ; -void pc_dimm_memory_plug (DeviceState *dev,MachineState *machine,uint64_t align,Error **errp) {
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 18/60] pc: rename pc_dimm_(plug|unplug|...)* into pc_memory_(plug|unplug|...)*
In reply to Paolo BonziniFrom: David Hildenbrand <[email protected]>
Use a similar naming scheme as spapr. This way, we can go ahead and rename e.g. pc_dimm_memory_plug to pc_dimm_plug, which avoids confusion.
Message-Id: <[email protected]>
--- hw/i386/pc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
hw/i386/pc.c +9 -9
@@ -1674,8 +1674,8 @@ void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name) } } -static void pc_dimm_plug (HotplugHandler *hotplug_dev, -DeviceState *dev,Error **errp) +static void pc_memory_plug (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp) {HotplugHandlerClass *hhc;Error *local_err =NULL ;
@@ -1728,8 +1728,8 @@ out:error_propagate (errp, local_err); } -static void pc_dimm_unplug_request (HotplugHandler *hotplug_dev, -DeviceState *dev,Error **errp) +static void pc_memory_unplug_request (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp) {HotplugHandlerClass *hhc;Error *local_err =NULL ;
@@ -1759,8 +1759,8 @@ out:error_propagate (errp, local_err); } -static void pc_dimm_unplug (HotplugHandler *hotplug_dev, -DeviceState *dev,Error **errp) +static void pc_memory_unplug (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp) {PCMachineState *pcms =PC_MACHINE (hotplug_dev);HotplugHandlerClass *hhc;
@@ -2015,7 +2015,7 @@ static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -pc_dimm_plug (hotplug_dev, dev, errp); +pc_memory_plug (hotplug_dev, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) {pc_cpu_plug (hotplug_dev, dev, errp); }
@@ -2025,7 +2025,7 @@ static void pc_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -pc_dimm_unplug_request (hotplug_dev, dev, errp); +pc_memory_unplug_request (hotplug_dev, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) {pc_cpu_unplug_request_cb (hotplug_dev, dev, errp); }else {
@@ -2038,7 +2038,7 @@ static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { -pc_dimm_unplug (hotplug_dev, dev, errp); +pc_memory_unplug (hotplug_dev, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) {pc_cpu_unplug_cb (hotplug_dev, dev, errp); }else {
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 20/60] pc-dimm: remove pc_dimm_get_free_slot() from header
In reply to Paolo BonziniFrom: David Hildenbrand <[email protected]>
Not used outside of pc-dimm.c and there shouldn't be other users. If other devices (e.g. memory devices) ever have to also use slots, then we will have to factor this out.
Message-Id: <[email protected]>
--- hw/mem/pc-dimm.c | 4 +++- include/hw/mem/pc-dimm.h | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-)
hw/mem/pc-dimm.c +3 -1
@@ -27,6 +27,8 @@#include "sysemu/numa.h" #include "trace.h" +static int pc_dimm_get_free_slot (const int *hint,int max_slots,Error **errp); +void pc_dimm_plug (DeviceState *dev,MachineState *machine,uint64_t align,Error **errp) {
@@ -111,7 +113,7 @@ static int pc_dimm_slot2bitmap(Object *obj, void *opaque)return 0 ; } -int pc_dimm_get_free_slot (const int *hint,int max_slots,Error **errp) +static int pc_dimm_get_free_slot (const int *hint,int max_slots,Error **errp) {unsigned long *bitmap;int slot =0 ;
include/hw/mem/pc-dimm.h +0 -2
@@ -76,8 +76,6 @@ typedef struct PCDIMMDeviceClass { MemoryRegion *(*get_vmstate_memory_region)(PCDIMMDevice *dimm); } PCDIMMDeviceClass; -int pc_dimm_get_free_slot (const int *hint,int max_slots,Error **errp); -void pc_dimm_plug (DeviceState *dev,MachineState *machine,uint64_t align,Error **errp);void pc_dimm_unplug (DeviceState *dev,MachineState *machine);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 19/60] pc-dimm: rename pc_dimm_memory_* to pc_dimm_*
In reply to Paolo BonziniFrom: David Hildenbrand <[email protected]>
Let's rename it to make it look more consistent.
Message-Id: <[email protected]>
--- hw/i386/pc.c | 4 ++-- hw/mem/pc-dimm.c | 6 +++--- hw/ppc/spapr.c | 6 +++--- include/hw/mem/pc-dimm.h | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-)
hw/i386/pc.c +2 -2
@@ -1713,7 +1713,7 @@ static void pc_memory_plug(HotplugHandler *hotplug_dev, goto out; } -pc_dimm_memory_plug (dev,MACHINE (pcms), align, &local_err); +pc_dimm_plug (dev,MACHINE (pcms), align, &local_err);if (local_err) { goto out; }
@@ -1773,7 +1773,7 @@ static void pc_memory_unplug(HotplugHandler *hotplug_dev, goto out; } -pc_dimm_memory_unplug (dev,MACHINE (pcms)); +pc_dimm_unplug (dev,MACHINE (pcms));object_unparent (OBJECT (dev)); out:
hw/mem/pc-dimm.c +3 -3
@@ -27,8 +27,8 @@#include "sysemu/numa.h" #include "trace.h" -void pc_dimm_memory_plug (DeviceState *dev,MachineState *machine, -uint64_t align,Error **errp) +void pc_dimm_plug (DeviceState *dev,MachineState *machine,uint64_t align, +Error **errp) {int slot;PCDIMMDevice *dimm =PC_DIMM (dev);
@@ -84,7 +84,7 @@ out:error_propagate (errp, local_err); } -void pc_dimm_memory_unplug (DeviceState *dev,MachineState *machine) +void pc_dimm_unplug (DeviceState *dev,MachineState *machine) {PCDIMMDevice *dimm =PC_DIMM (dev);PCDIMMDeviceClass *ddc =PC_DIMM_GET_CLASS (dimm);
hw/ppc/spapr.c +3 -3
@@ -3160,7 +3160,7 @@ static void spapr_memory_plug(HotplugHandler *hotplug_dev, DeviceState *dev, align =memory_region_get_alignment (mr); size =memory_region_size (mr); -pc_dimm_memory_plug (dev,MACHINE (ms), align, &local_err); +pc_dimm_plug (dev,MACHINE (ms), align, &local_err);if (local_err) { goto out; }
@@ -3183,7 +3183,7 @@ static void spapr_memory_plug(HotplugHandler *hotplug_dev, DeviceState *dev,return ; out_unplug: -pc_dimm_memory_unplug (dev,MACHINE (ms)); +pc_dimm_unplug (dev,MACHINE (ms)); out:error_propagate (errp, local_err); }
@@ -3332,7 +3332,7 @@ static void spapr_memory_unplug(HotplugHandler *hotplug_dev, DeviceState *dev)sPAPRMachineState *spapr =SPAPR_MACHINE (hotplug_dev);sPAPRDIMMState *ds =spapr_pending_dimm_unplugs_find (spapr,PC_DIMM (dev)); -pc_dimm_memory_unplug (dev,MACHINE (hotplug_dev)); +pc_dimm_unplug (dev,MACHINE (hotplug_dev));object_unparent (OBJECT (dev));spapr_pending_dimm_unplugs_remove (spapr, ds); }
include/hw/mem/pc-dimm.h +3 -3
@@ -78,7 +78,7 @@ typedef struct PCDIMMDeviceClass {int pc_dimm_get_free_slot (const int *hint,int max_slots,Error **errp); -void pc_dimm_memory_plug (DeviceState *dev,MachineState *machine, -uint64_t align,Error **errp); -void pc_dimm_memory_unplug (DeviceState *dev,MachineState *machine); +void pc_dimm_plug (DeviceState *dev,MachineState *machine,uint64_t align, +Error **errp); +void pc_dimm_unplug (DeviceState *dev,MachineState *machine);#endif
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 21/60] pc: factor out pc specific dimm checks into pc_memory_pre_plug()
In reply to Paolo BonziniFrom: David Hildenbrand <[email protected]>
We can perform these checks before the device is actually realized.
Message-Id: <[email protected]>
--- hw/i386/pc.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-)
hw/i386/pc.c +26 -18
@@ -1674,6 +1674,29 @@ void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name) } } +static void pc_memory_pre_plug (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp) +{ +const PCMachineState *pcms =PC_MACHINE (hotplug_dev); +const bool is_nvdimm =object_dynamic_cast (OBJECT (dev),TYPE_NVDIMM ); + +/* +* 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 (errp, +"memory hotplug is not enabled: missing acpi device or acpi disabled" ); +return ; + } + +if (is_nvdimm && !pcms->acpi_nvdimm_state.is_enabled) { +error_setg (errp,"nvdimm is not enabled: missing 'nvdimm' in '-M'" ); +return ; + } +} +static void pc_memory_plug (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) {
@@ -1696,23 +1719,6 @@ static void pc_memory_plug(HotplugHandler *hotplug_dev, align =memory_region_get_alignment (mr); } -/* -* 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 or acpi disabled" ); - goto out; - } - -if (is_nvdimm && !pcms->acpi_nvdimm_state.is_enabled) { -error_setg (&local_err, -"nvdimm is not enabled: missing 'nvdimm' in '-M'" ); - goto out; - } -pc_dimm_plug (dev,MACHINE (pcms), align, &local_err);if (local_err) { goto out;
@@ -2006,7 +2012,9 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev,static void pc_machine_device_pre_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) { -if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { +if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) { +pc_memory_pre_plug (hotplug_dev, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) {pc_cpu_pre_plug (hotplug_dev, dev, errp); } }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 22/60] nvdimm: no need to overwrite get_vmstate_memory_region()
In reply to Paolo BonziniFrom: David Hildenbrand <[email protected]>
Our parent class (PC_DIMM) provides exactly the same function.
Message-Id: <[email protected]>
--- hw/mem/nvdimm.c | 6 ------ 1 file changed, 6 deletions(-)
hw/mem/nvdimm.c +0 -6
@@ -166,11 +166,6 @@ static void nvdimm_write_label_data(NVDIMMDevice *nvdimm, const void *buf,memory_region_set_dirty (mr, backend_offset, size); } -static MemoryRegion *nvdimm_get_vmstate_memory_region (PCDIMMDevice *dimm) -{ -return host_memory_backend_get_memory (dimm->hostmem, &error_abort); -} -static void nvdimm_class_init (ObjectClass *oc,void *data) {PCDIMMDeviceClass *ddc =PC_DIMM_CLASS (oc);
@@ -178,7 +173,6 @@ static void nvdimm_class_init(ObjectClass *oc, void *data) ddc->realize = nvdimm_realize; ddc->get_memory_region = nvdimm_get_memory_region; - ddc->get_vmstate_memory_region = nvdimm_get_vmstate_memory_region; nvc->read_label_data = nvdimm_read_label_data; nvc->write_label_data = nvdimm_write_label_data;
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 23/60] hostmem: drop error variable from host_memory_backend_get_memory()
In reply to Paolo BonziniFrom: David Hildenbrand <[email protected]>
Unused, so let's remove it.
Message-Id: <[email protected]>
--- backends/hostmem.c | 3 +-- hw/mem/nvdimm.c | 4 ++-- hw/mem/pc-dimm.c | 4 ++-- hw/misc/ivshmem.c | 3 +-- include/sysemu/hostmem.h | 3 +-- numa.c | 3 +-- 6 files changed, 8 insertions(+), 12 deletions(-)
backends/hostmem.c +1 -2
@@ -247,8 +247,7 @@ bool host_memory_backend_mr_inited(HostMemoryBackend *backend)return memory_region_size (&backend->mr) !=0 ; } -MemoryRegion * -host_memory_backend_get_memory (HostMemoryBackend *backend,Error **errp) +MemoryRegion *host_memory_backend_get_memory (HostMemoryBackend *backend) {return host_memory_backend_mr_inited (backend) ? &backend->mr :NULL ; }
hw/mem/nvdimm.c +2 -2
@@ -105,7 +105,7 @@ static MemoryRegion *nvdimm_get_memory_region(PCDIMMDevice *dimm, Error **errp)static void nvdimm_realize (PCDIMMDevice *dimm,Error **errp) { -MemoryRegion *mr =host_memory_backend_get_memory (dimm->hostmem, errp); +MemoryRegion *mr =host_memory_backend_get_memory (dimm->hostmem);NVDIMMDevice *nvdimm =NVDIMM (dimm);uint64_t align, pmem_size, size =memory_region_size (mr);
@@ -161,7 +161,7 @@ static void nvdimm_write_label_data(NVDIMMDevice *nvdimm, const void *buf,memcpy (nvdimm->label_data + offset, buf, size); - mr =host_memory_backend_get_memory (dimm->hostmem, &error_abort); + mr =host_memory_backend_get_memory (dimm->hostmem); backend_offset =memory_region_size (mr) - nvdimm->label_size + offset;memory_region_set_dirty (mr, backend_offset, size); }
hw/mem/pc-dimm.c +2 -2
@@ -226,12 +226,12 @@ static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm, Error **errp)return NULL ; } -return host_memory_backend_get_memory (dimm->hostmem, errp); +return host_memory_backend_get_memory (dimm->hostmem); }static MemoryRegion *pc_dimm_get_vmstate_memory_region (PCDIMMDevice *dimm) { -return host_memory_backend_get_memory (dimm->hostmem, &error_abort); +return host_memory_backend_get_memory (dimm->hostmem); }static uint64_t pc_dimm_md_get_addr (const MemoryDeviceState *md)
hw/misc/ivshmem.c +1 -2
@@ -909,8 +909,7 @@ static void ivshmem_common_realize(PCIDevice *dev, Error **errp)if (s->hostmem !=NULL ) {IVSHMEM_DPRINTF ("using hostmem\n" ); - s->ivshmem_bar2 =host_memory_backend_get_memory (s->hostmem, - &error_abort); + s->ivshmem_bar2 =host_memory_backend_get_memory (s->hostmem); }else {Chardev *chr =qemu_chr_fe_get_driver (&s->server_chr);assert (chr);
include/sysemu/hostmem.h +1 -2
@@ -62,8 +62,7 @@ struct HostMemoryBackend { };bool host_memory_backend_mr_inited (HostMemoryBackend *backend); -MemoryRegion *host_memory_backend_get_memory (HostMemoryBackend *backend, -Error **errp); +MemoryRegion *host_memory_backend_get_memory (HostMemoryBackend *backend);void host_memory_backend_set_mapped (HostMemoryBackend *backend,bool mapped);bool host_memory_backend_is_mapped (HostMemoryBackend *backend);
numa.c +1 -2
@@ -523,8 +523,7 @@ void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,if (!backend) {continue ; } -MemoryRegion *seg =host_memory_backend_get_memory (backend, - &error_fatal); +MemoryRegion *seg =host_memory_backend_get_memory (backend);if (memory_region_is_mapped (seg)) {char *path =object_get_canonical_path_component (OBJECT (backend));
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 24/60] pc-dimm: merge get_(vmstate_)memory_region()
In reply to Paolo BonziniFrom: David Hildenbrand <[email protected]>
Importantly, get_vmstate_memory_region() should also fail with a proper error if called before the device is realized. For a PCDIMM, both functions are to return the same thing, so share the implementation.
All current users are called after the device has been realized, so we can expect the calls to succeed.
Message-Id: <[email protected]>
--- hw/mem/pc-dimm.c | 13 +++++-------- include/hw/mem/pc-dimm.h | 3 ++- 2 files changed, 7 insertions(+), 9 deletions(-)
hw/mem/pc-dimm.c +5 -8
@@ -35,7 +35,8 @@ void pc_dimm_plug(DeviceState *dev, MachineState *machine, uint64_t align,int slot;PCDIMMDevice *dimm =PC_DIMM (dev);PCDIMMDeviceClass *ddc =PC_DIMM_GET_CLASS (dimm); -MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region (dimm); +MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region (dimm, + &error_abort);Error *local_err =NULL ;MemoryRegion *mr;uint64_t addr;
@@ -90,7 +91,8 @@ void pc_dimm_unplug(DeviceState *dev, MachineState *machine) {PCDIMMDevice *dimm =PC_DIMM (dev);PCDIMMDeviceClass *ddc =PC_DIMM_GET_CLASS (dimm); -MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region (dimm); +MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region (dimm, + &error_abort);MemoryRegion *mr = ddc->get_memory_region (dimm, &error_abort);memory_device_unplug_region (machine, mr);
@@ -229,11 +231,6 @@ static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm, Error **errp)return host_memory_backend_get_memory (dimm->hostmem); } -static MemoryRegion *pc_dimm_get_vmstate_memory_region (PCDIMMDevice *dimm) -{ -return host_memory_backend_get_memory (dimm->hostmem); -} -static uint64_t pc_dimm_md_get_addr (const MemoryDeviceState *md) {const PCDIMMDevice *dimm =PC_DIMM (md);
@@ -298,7 +295,7 @@ static void pc_dimm_class_init(ObjectClass *oc, void *data) dc->desc ="DIMM memory module" ; ddc->get_memory_region = pc_dimm_get_memory_region; - ddc->get_vmstate_memory_region = pc_dimm_get_vmstate_memory_region; + ddc->get_vmstate_memory_region = pc_dimm_get_memory_region; mdc->get_addr = pc_dimm_md_get_addr;/* for a dimm plugged_size == region_size */
include/hw/mem/pc-dimm.h +2 -1
@@ -73,7 +73,8 @@ typedef struct PCDIMMDeviceClass {/* public */ void (*realize)(PCDIMMDevice *dimm,Error **errp); MemoryRegion *(*get_memory_region)(PCDIMMDevice *dimm, Error **errp); - MemoryRegion *(*get_vmstate_memory_region)(PCDIMMDevice *dimm); + MemoryRegion *(*get_vmstate_memory_region)(PCDIMMDevice *dimm, + Error **errp); } PCDIMMDeviceClass; void pc_dimm_plug(DeviceState *dev, MachineState *machine, uint64_t align,
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 25/60] nvdimm: convert "unarmed" into a static property
In reply to Paolo BonziniFrom: David Hildenbrand <[email protected]>
We don't allow to modify it after realization. So we can simply turn it into a static property.
Message-Id: <[email protected]>
--- hw/mem/nvdimm.c | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-)
hw/mem/nvdimm.c +7 -25
@@ -64,36 +64,11 @@ out:error_propagate (errp, local_err); } -static bool nvdimm_get_unarmed (Object *obj,Error **errp) -{ -NVDIMMDevice *nvdimm =NVDIMM (obj); - -return nvdimm->unarmed; -} - -static void nvdimm_set_unarmed (Object *obj,bool value,Error **errp) -{ -NVDIMMDevice *nvdimm =NVDIMM (obj); -Error *local_err =NULL ; - -if (memory_region_size (&nvdimm->nvdimm_mr)) { -error_setg (&local_err,"cannot change property value" ); - goto out; - } - - nvdimm->unarmed = value; - - out: -error_propagate (errp, local_err); -} -static void nvdimm_init (Object *obj) {object_property_add (obj,NVDIMM_LABEL_SIZE_PROP ,"int" , nvdimm_get_label_size, nvdimm_set_label_size,NULL ,NULL ,NULL ); -object_property_add_bool (obj,NVDIMM_UNARMED_PROP , - nvdimm_get_unarmed, nvdimm_set_unarmed,NULL ); }static MemoryRegion *nvdimm_get_memory_region (PCDIMMDevice *dimm,Error **errp)
@@ -166,13 +141,20 @@ static void nvdimm_write_label_data(NVDIMMDevice *nvdimm, const void *buf,memory_region_set_dirty (mr, backend_offset, size); } +static Property nvdimm_properties[] = { +DEFINE_PROP_BOOL (NVDIMM_UNARMED_PROP , NVDIMMDevice, unarmed, false), +DEFINE_PROP_END_OF_LIST (), +}; +static void nvdimm_class_init (ObjectClass *oc,void *data) {PCDIMMDeviceClass *ddc =PC_DIMM_CLASS (oc);NVDIMMClass *nvc =NVDIMM_CLASS (oc); +DeviceClass *dc =DEVICE_CLASS (oc); ddc->realize = nvdimm_realize; ddc->get_memory_region = nvdimm_get_memory_region; + dc->props = nvdimm_properties; nvc->read_label_data = nvdimm_read_label_data; nvc->write_label_data = nvdimm_write_label_data;
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 26/60] nvdimm: convert nvdimm_mr into a pointer
In reply to Paolo BonziniFrom: David Hildenbrand <[email protected]>
This way we can easily check if the region has already been inititalized without having to rely on the size of an uninitialized region being 0.
Free the region in nvdimm_finalize() and not in unrealize() as we will allow to create the region before realization in following patches.
Message-Id: <[email protected]>
--- hw/mem/nvdimm.c | 17 +++++++++++++---- include/hw/mem/nvdimm.h | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-)
hw/mem/nvdimm.c +13 -4
@@ -43,7 +43,7 @@ static void nvdimm_set_label_size(Object *obj, Visitor *v, const char *name,Error *local_err =NULL ;uint64_t value; -if (memory_region_size (&nvdimm->nvdimm_mr)) { +if (nvdimm->nvdimm_mr) {error_setg (&local_err,"cannot change property value" ); goto out; }
@@ -71,11 +71,18 @@ static void nvdimm_init(Object *obj) NULL, NULL); } +static void nvdimm_finalize (Object *obj) +{ +NVDIMMDevice *nvdimm =NVDIMM (obj); + +g_free (nvdimm->nvdimm_mr); +} +static MemoryRegion *nvdimm_get_memory_region (PCDIMMDevice *dimm,Error **errp) {NVDIMMDevice *nvdimm =NVDIMM (dimm); -return &nvdimm->nvdimm_mr; +return nvdimm->nvdimm_mr; }static void nvdimm_realize (PCDIMMDevice *dimm,Error **errp)
@@ -102,9 +109,10 @@ static void nvdimm_realize(PCDIMMDevice *dimm, Error **errp)return ; } -memory_region_init_alias (&nvdimm->nvdimm_mr,OBJECT (dimm), + nvdimm->nvdimm_mr =g_new (MemoryRegion,1 ); +memory_region_init_alias (nvdimm->nvdimm_mr,OBJECT (dimm),"nvdimm-memory" , mr,0 , pmem_size); - nvdimm->nvdimm_mr.align = align; + nvdimm->nvdimm_mr->align = align; }/*
@@ -167,6 +175,7 @@ static TypeInfo nvdimm_info = { .class_init = nvdimm_class_init, .instance_size = sizeof(NVDIMMDevice), .instance_init = nvdimm_init, + .instance_finalize = nvdimm_finalize, };static void nvdimm_register_types (void )
include/hw/mem/nvdimm.h +1 -1
@@ -74,7 +74,7 @@ struct NVDIMMDevice {* it's the PMEM region in NVDIMM device, which is presented to * guest via ACPI NFIT and _FIT method if NVDIMM hotplug is supported. */ -MemoryRegion nvdimm_mr; +MemoryRegion *nvdimm_mr;/* * The 'on' value results in the unarmed flag set in ACPI NFIT,
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 27/60] nvdimm: make get_memory_region() perform checks and initialization
In reply to Paolo BonziniFrom: David Hildenbrand <[email protected]>
We might get a call to get_memory_region() before the device has been realized. We should return a consistent value, as the return value will e.g. later on be used in the pre_plug handler.
To avoid duplicating too much code, factor the initialization and checks out into a helper function.
Message-Id: <[email protected]>
--- hw/mem/nvdimm.c | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-)
hw/mem/nvdimm.c +35 -9
@@ -78,20 +78,22 @@ static void nvdimm_finalize(Object *obj)g_free (nvdimm->nvdimm_mr); } -static MemoryRegion *nvdimm_get_memory_region (PCDIMMDevice *dimm,Error **errp) +static void nvdimm_prepare_memory_region (NVDIMMDevice *nvdimm,Error **errp) { -NVDIMMDevice *nvdimm =NVDIMM (dimm); +PCDIMMDevice *dimm =PC_DIMM (nvdimm); +uint64_t align, pmem_size, size; +MemoryRegion *mr; -return nvdimm->nvdimm_mr; -} +g_assert (!nvdimm->nvdimm_mr); -static void nvdimm_realize (PCDIMMDevice *dimm,Error **errp) -{ -MemoryRegion *mr =host_memory_backend_get_memory (dimm->hostmem); -NVDIMMDevice *nvdimm =NVDIMM (dimm); -uint64_t align, pmem_size, size =memory_region_size (mr); +if (!dimm->hostmem) { +error_setg (errp,"'" PC_DIMM_MEMDEV_PROP "' property must be set" ); +return ; + } + mr =host_memory_backend_get_memory (dimm->hostmem); align =memory_region_get_alignment (mr); + size =memory_region_size (mr); pmem_size = size - nvdimm->label_size; nvdimm->label_data =memory_region_get_ram_ptr (mr) + pmem_size;
@@ -115,6 +117,30 @@ static void nvdimm_realize(PCDIMMDevice *dimm, Error **errp) nvdimm->nvdimm_mr->align = align; } +static MemoryRegion *nvdimm_get_memory_region (PCDIMMDevice *dimm,Error **errp) +{ +NVDIMMDevice *nvdimm =NVDIMM (dimm); +Error *local_err =NULL ; + +if (!nvdimm->nvdimm_mr) { +nvdimm_prepare_memory_region (nvdimm, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return NULL ; + } + } +return nvdimm->nvdimm_mr; +} + +static void nvdimm_realize (PCDIMMDevice *dimm,Error **errp) +{ +NVDIMMDevice *nvdimm =NVDIMM (dimm); + +if (!nvdimm->nvdimm_mr) { +nvdimm_prepare_memory_region (nvdimm, errp); + } +} +/* * the caller should check the input parameters before calling * label read/write functions.
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 28/60] pc-dimm: get_memory_region() will not fail after realize
In reply to Paolo BonziniFrom: David Hildenbrand <[email protected]>
Let's try to reduce error handling a bit. In the plug/unplug case, the device was realized and therefore we can assume that getting access to the memory region will not fail.
For get_vmstate_memory_region() this is already handled that way. Document both cases.
Message-Id: <[email protected]>
--- hw/i386/pc.c | 7 +------ hw/mem/pc-dimm.c | 7 +------ hw/ppc/spapr.c | 12 ++---------- include/hw/mem/pc-dimm.h | 6 ++++-- 4 files changed, 8 insertions(+), 24 deletions(-)
hw/i386/pc.c +1 -6
@@ -1706,15 +1706,10 @@ static void pc_memory_plug(HotplugHandler *hotplug_dev,PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms);PCDIMMDevice *dimm =PC_DIMM (dev);PCDIMMDeviceClass *ddc =PC_DIMM_GET_CLASS (dimm); -MemoryRegion *mr; +MemoryRegion *mr = ddc->get_memory_region (dimm, &error_abort);uint64_t align =TARGET_PAGE_SIZE ;bool is_nvdimm =object_dynamic_cast (OBJECT (dev),TYPE_NVDIMM ); - mr = ddc->get_memory_region (dimm, &local_err); -if (local_err) { - goto out; - } -if (memory_region_get_alignment (mr) && pcmc->enforce_aligned_dimm) { align =memory_region_get_alignment (mr); }
hw/mem/pc-dimm.c +1 -6
@@ -37,15 +37,10 @@ void pc_dimm_plug(DeviceState *dev, MachineState *machine, uint64_t align,PCDIMMDeviceClass *ddc =PC_DIMM_GET_CLASS (dimm);MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region (dimm, &error_abort); +MemoryRegion *mr = ddc->get_memory_region (dimm, &error_abort);Error *local_err =NULL ; -MemoryRegion *mr;uint64_t addr; - mr = ddc->get_memory_region (dimm, &local_err); -if (local_err) { - goto out; - } - addr =object_property_get_uint (OBJECT (dimm),PC_DIMM_ADDR_PROP , &local_err);if (local_err) {
hw/ppc/spapr.c +2 -10
@@ -3149,14 +3149,10 @@ static void spapr_memory_plug(HotplugHandler *hotplug_dev, DeviceState *dev,sPAPRMachineState *ms =SPAPR_MACHINE (hotplug_dev);PCDIMMDevice *dimm =PC_DIMM (dev);PCDIMMDeviceClass *ddc =PC_DIMM_GET_CLASS (dimm); -MemoryRegion *mr; +MemoryRegion *mr = ddc->get_memory_region (dimm, &error_abort);uint64_t align, size, addr;uint32_t node; - mr = ddc->get_memory_region (dimm, &local_err); -if (local_err) { - goto out; - } align =memory_region_get_alignment (mr); size =memory_region_size (mr);
@@ -3344,16 +3340,12 @@ static void spapr_memory_unplug_request(HotplugHandler *hotplug_dev,Error *local_err =NULL ;PCDIMMDevice *dimm =PC_DIMM (dev);PCDIMMDeviceClass *ddc =PC_DIMM_GET_CLASS (dimm); -MemoryRegion *mr; +MemoryRegion *mr = ddc->get_memory_region (dimm, &error_abort);uint32_t nr_lmbs;uint64_t size, addr_start, addr;int i;sPAPRDRConnector *drc; - mr = ddc->get_memory_region (dimm, &local_err); -if (local_err) { - goto out; - } size =memory_region_size (mr); nr_lmbs = size /SPAPR_MEMORY_BLOCK_SIZE ;
include/hw/mem/pc-dimm.h +4 -2
@@ -62,9 +62,11 @@ typedef struct PCDIMMDevice {* @realize: called after common dimm is realized so that the dimm based * devices get the chance to do specified operations. * @get_memory_region: returns #MemoryRegion associated with @dimm which -* is directly mapped into the physical address space of guest. +* is directly mapped into the physical address space of guest. Will not +* fail after the device was realized. * @get_vmstate_memory_region: returns #MemoryRegion which indicates the -* memory of @dimm should be kept during live migration. +* memory of @dimm should be kept during live migration. Will not fail +* after the device was realized. */ typedef struct PCDIMMDeviceClass { /* private */
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 29/60] numa: report all DIMM/NVDIMMs as plugged memory
In reply to Paolo BonziniFrom: David Hildenbrand <[email protected]>
Right now, there is some inconsistency between hotplugged and coldplugged memory. DIMMs added via "-device" result in different stats than DIMMs added using "device_add".
E.g.
[...]
-numa node,nodeid=0,cpus=0-1 -numa node,nodeid=1,cpus=2-3 \
-m 4G,maxmem=20G,slots=2 \
-object memory-backend-ram,id=mem0,size=8G \
-device pc-dimm,id=dimm0,memdev=mem0 \
-object memory-backend-ram,id=mem1,size=8G \
-device nvdimm,id=dimm1,memdev=mem1,node=1Results in NUMA info
(qemu) info numa
info numa
2 nodes
node 0 cpus: 0 1
node 0 size: 10240 MB
node 0 plugged: 0 MB
node 1 cpus: 2 3
node 1 size: 10240 MB
node 1 plugged: 0 MB
But in memory size summary:
(qemu) info memory_size_summary
info memory_size_summary
base memory: 4294967296
plugged memory: 17179869184Make this consistent by reporting all hot and coldplugged memory a.k.a. DIMM and NVDIMM as "plugged".
Message-Id: <[email protected]>
--- numa.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
numa.c +2 -4
@@ -566,10 +566,8 @@ static void numa_stat_memory_devices(NumaNodeMem node_mem[])if (pcdimm_info) { node_mem[pcdimm_info->node].node_mem += pcdimm_info->size; -if (pcdimm_info->hotpluggable && pcdimm_info->hotplugged) { - node_mem[pcdimm_info->node].node_plugged_mem += - pcdimm_info->size; - } + node_mem[pcdimm_info->node].node_plugged_mem += + pcdimm_info->size; } } }
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PULL 29/60] numa: report all DIMM/NVDIMMs as plugged memory
Quoted 51 lines · Paolo Bonzini
From: David Hildenbrand <[email protected]>
Right now, there is some inconsistency between hotplugged and coldplugged memory. DIMMs added via "-device" result in different stats than DIMMs added using "
device_add".E.g.
[...] -numa node,nodeid=0,cpus=0-1 -numa node,nodeid=1,cpus=2-3 \ -m 4G,maxmem=20G,slots=2 \ -object memory-backend-ram,id=mem0,size=8G \ -device pc-dimm,id=dimm0,memdev=mem0 \ -object memory-backend-ram,id=mem1,size=8G \ -device nvdimm,id=dimm1,memdev=mem1,node=1Results in NUMA info
(qemu) info numa
info numa
2 nodes
node 0 cpus: 0 1
node 0 size: 10240 MB
node 0 plugged: 0 MB
node 1 cpus: 2 3
node 1 size: 10240 MB
node 1 plugged: 0 MBBut in memory size summary:
(qemu) info memory_size_summary info memory_size_summary base memory: 4294967296 plugged memory: 17179869184Make this consistent by reporting all hot and coldplugged memory a.k.a. DIMM and NVDIMM as "plugged".
Fixes 31959e82fb0 ("hmp: extend "info numa" with hotplugged memory information")Signed-off-by David Hildenbrand <[email protected]>Message-Id: <[email protected]>
Signed-off-by Paolo Bonzini <[email protected]>--- numa.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)numa.c +0
-0@@ -566,10 +566,8 @@ static void numa_stat_memory_devices(NumaNodeMem node_mem[])if (pcdimm_info) {
numa.c static void numa_stat_memory_devices(NumaNodeMem node_mem[]) · line 573
Quoted 10 lines
numa.c +2
-4node_mem[pcdimm_info->node].node_mem += pcdimm_info->size; -if (pcdimm_info->hotpluggable && pcdimm_info->hotplugged) { - node_mem[pcdimm_info->node].node_plugged_mem += - pcdimm_info->size; - } + node_mem[pcdimm_info->node].node_plugged_mem += + pcdimm_info->size; } } }
There was a v2 with a tweaked description, but the content remained the same.
Signature · 3 lines
Thanks, David / dhildenb
[Qemu-devel] [PULL 30/60] osdep: work around Coverity parsing errors
In reply to Paolo BonziniCoverity does not like the new _Float* types that are used by recent glibc, and croaks on every single file that includes stdlib.h. Add dummy typedefs to please it.
--- include/qemu/osdep.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
include/qemu/osdep.h +15 -0
@@ -33,6 +33,21 @@#else #include "exec/poison.h" #endif +#ifdef __COVERITY__ +/* Coverity does not like the new _Float* types that are used by +* recent glibc, and croaks on every single file that includes +* stdlib.h. These typedefs are enough to please it. +* +* Note that these fix parse errors so they cannot be placed in +* scripts/coverity-model.c. +*/ +typedef float _Float32 ; +typedef double _Float32x ; +typedef double _Float64 ; +typedef __float80 _Float64x ; +typedef __float128 _Float128 ; +#endif +#include "qemu/compiler.h" /* Older versions of C++ don't get definitions of various macros from
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 31/60] Deprecate the -enable-hax option
In reply to Paolo BonziniFrom: Thomas Huth <[email protected]>
We currently have got three ways of turning on the HAX accelerator:
"-machine accel=hax", "-accel hax" and "-enable-hax". That's really confusing and overloaded. Since "-accel" is our preferred way to enable an accelerator nowadays, and "-accel hax" is even less to type than "-enable-hax", let's deprecate the "-enable-hax" option now.
Note: While "-enable-kvm" is available since a long time and can hardly be removed since it is used in a lot of upper layer tools and scripts, the "-enable-hax" option is still rather new and not very widespread yet, so I think that it should be OK if we remove this in a couple of releases again (we'll see whether someone complains after seeing the deprecation message - then we could still reconsider to keep it if there a well-founded reasons).
Message-Id: <[email protected]>
--- qemu-doc.texi | 5 +++++ qemu-options.hx | 2 +- vl.c | 1 + 3 files changed, 7 insertions(+), 1 deletion(-)
qemu-doc.texi +5 -0
@@ -2912,6 +2912,11 @@ Option @option{-virtioconsole} has been replaced by The @code{-clock} option is ignored since QEMU version 1.7.0. There is no replacement since it is not needed anymore. +@subsection -enable-hax (since 3.0.0) + +The @option{-enable-hax} option has been replaced by @option{-accel hax}. +Both options have been introduced in QEMU version 2.9.0. + @section QEMU Machine Protocol (QMP) commands @subsection block-dirty-bitmap-add "autoload" parameter (since 2.12.0)
qemu-options.hx +1 -1
@@ -3421,7 +3421,7 @@ STEXI Enable HAX (Hardware-based Acceleration eXecution) support. This option is only available if HAX support is enabled when compiling. HAX is only applicable to MAC and Windows platform, and thus does not conflict with -KVM. +KVM. This option is deprecated, use @option{-accel hax} instead. ETEXI DEF("xen-domid", HAS_ARG, QEMU_OPTION_xen_domid,
vl.c +1 -0
@@ -3581,6 +3581,7 @@ int main(int argc, char **argv, char **envp)qemu_opts_parse_noisily (olist,"accel=kvm" , false);break ;case QEMU_OPTION_enable_hax: +warn_report ("Option is deprecated, use '-accel hax' instead" ); olist =qemu_find_opts ("machine" );qemu_opts_parse_noisily (olist,"accel=hax" , false);break ;
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 32/60] pr-helper: fix --socket-path default in help
In reply to Paolo BonziniCurrently --help shows "(default '(null)')" for the -k/--socket-path option. Fix it by getting the default path in /var/run.
--- scsi/qemu-pr-helper.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
scsi/qemu-pr-helper.c +8 -7
@@ -74,8 +74,16 @@ static int uid = -1;static int gid =-1 ;#endif +static void compute_default_paths (void ) +{ +if (!socket_path) { + socket_path =qemu_get_local_state_pathname ("run/qemu-pr-helper.sock" ); + } +} +static void usage (const char *name) { +compute_default_paths (); (printf) ("Usage: %s [OPTIONS] FILE\n" "Persistent Reservation helper program for QEMU\n"
@@ -845,13 +853,6 @@ static const char *socket_activation_validate_opts(void)return NULL ; } -static void compute_default_paths (void ) -{ -if (!socket_path) { - socket_path =qemu_get_local_state_pathname ("run/qemu-pr-helper.sock" ); - } -} -static void termsig_handler (int signum) {atomic_cmpxchg (&state,RUNNING ,TERMINATE );
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 33/60] pr-helper: fix assertion failure on failed multipath PERSISTENT RESERVE IN
In reply to Paolo BonziniThe response size is expected to be zero if the SCSI status is not "GOOD", but nothing was resetting it.
This can be reproduced simply by "sg_persist -s /dev/sdb" where /dev/sdb in the guest is a scsi-block device corresponding to a multipath device on the host.
Before:
PR in (Read full status): Aborted command
and on the host:
prh_write_response: Assertion `resp->sz == 0' failed.
After:
PR in (Read full status): bad field in cdb or parameter list (perhaps unsupported service action)
--- scsi/qemu-pr-helper.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
scsi/qemu-pr-helper.c +5 -1
@@ -558,7 +558,11 @@ static int do_pr_in(int fd, const uint8_t *cdb, uint8_t *sense,#ifdef CONFIG_MPATH if (is_mpath (fd)) {/* multipath_pr_in fills the whole input buffer. */ -return multipath_pr_in (fd, cdb, sense, data, *resp_sz); +int r =multipath_pr_in (fd, cdb, sense, data, *resp_sz); +if (r !=GOOD ) { + *resp_sz =0 ; + } +return r; }#endif
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 34/60] pr-manager-helper: avoid SIGSEGV when writing to the socket fail
In reply to Paolo BonziniWhen writing to the qemu-pr-helper socket failed, the persistent reservation manager was correctly disconnecting the socket, but it did not clear pr_mgr->ioc. So the rest of the code did not know that the socket had been disconnected, accessed pr_mgr->ioc and happily caused a crash.
To reproduce, it is enough to stop qemu-pr-helper between QEMU startup and executing e.g. sg_persist -k /dev/sdb.
--- scsi/pr-manager-helper.c | 1 + 1 file changed, 1 insertion(+)
scsi/pr-manager-helper.c +1 -0
@@ -71,6 +71,7 @@ static int pr_manager_helper_write(PRManagerHelper *pr_mgr,if (n_written <=0 ) {assert (n_written !=QIO_CHANNEL_ERR_BLOCK );object_unref (OBJECT (pr_mgr->ioc)); + pr_mgr->ioc =NULL ;return n_written <0 ? -EINVAL :0 ; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 35/60] pr-manager: put stubs in .c file
In reply to Paolo Bonzini--- include/scsi/pr-manager.h | 9 --------- scsi/Makefile.objs | 1 + scsi/pr-manager-stub.c | 24 ++++++++++++++++++++++++ 3 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 scsi/pr-manager-stub.c
include/scsi/pr-manager.h +0 -9
@@ -41,15 +41,6 @@ BlockAIOCB *pr_manager_execute(PRManager *pr_mgr, BlockCompletionFunc *complete, void *opaque); -#ifdef CONFIG_LINUX PRManager *pr_manager_lookup (const char *id,Error **errp); -#else -static inline PRManager *pr_manager_lookup (const char *id,Error **errp) -{ -/* The classes do not exist at all! */ -error_setg (errp,"No persistent reservation manager with id '%s'" , id); -return NULL ; -} -#endif #endif
scsi/Makefile.objs +1 -0
@@ -1,3 +1,4 @@ block-obj-y += utils.o block-obj-$(CONFIG_LINUX) += pr-manager.o pr-manager-helper.o +block-obj-$(call lnot,$(CONFIG_LINUX)) += pr-manager-stub.o
scsi/pr-manager-stub.c new file +24 -0
@@ -0,0 +1,24 @@ +/* +* Persistent reservation manager - stub for non-Linux platforms +* +* Copyright (c) 2018 Red Hat, Inc. +* +* Author: Paolo Bonzini <[email protected]> +* +* This code is licensed under the LGPL. +* +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "scsi/pr-manager.h" +#include "trace.h" +#include "qapi/qapi-types-block.h" +#include "qapi/qapi-commands-block.h" + +PRManager *pr_manager_lookup (const char *id,Error **errp) +{ +/* The classes do not exist at all! */ +error_setg (errp,"No persistent reservation manager with id '%s'" , id); +return NULL ; +}
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 36/60] pr-manager: add query-pr-managers QMP command
In reply to Paolo BonziniThis command lets you query the connection status of each pr-manager-helper object.
--- include/scsi/pr-manager.h | 2 ++ qapi/block.json | 28 ++++++++++++++++++++++++++++ scsi/pr-manager-helper.c | 13 +++++++++++++ scsi/pr-manager-stub.c | 6 ++++++ scsi/pr-manager.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 94 insertions(+)
include/scsi/pr-manager.h +2 -0
@@ -33,8 +33,10 @@ typedef struct PRManagerClass {/* <public> */ int (*run)(PRManager *pr_mgr,int fd,struct sg_io_hdr *hdr); +bool (*is_connected)(PRManager *pr_mgr); } PRManagerClass; +bool pr_manager_is_connected (PRManager *pr_mgr); BlockAIOCB *pr_manager_execute(PRManager *pr_mgr, AioContext *ctx, int fd, struct sg_io_hdr *hdr,
qapi/block.json +28 -0
@@ -78,6 +78,34 @@ 'data': { 'device': 'str', 'name': 'str' } } ## +# @PRManagerInfo: +# +# Information about a persistent reservation manager +# +# @id: the identifier of the persistent reservation manager +# +# @connected: true if the persistent reservation manager is connected to +# the underlying storage or helper +# +# Since: 3.0 +## +{ 'struct': 'PRManagerInfo', + 'data': {'id': 'str', 'connected': 'bool'} } + +## +# @query-pr-managers: +# +# Returns a list of information about each persistent reservation manager. +# +# Returns: a list of @PRManagerInfo for each persistent reservation manager +# +# Since: 3.0 +## +{ 'command': 'query-pr-managers', 'returns': ['PRManagerInfo'], + 'allow-preconfig': true } + + +## # @blockdev-snapshot-internal-sync: # # Synchronously take an internal snapshot of a block device, when the
scsi/pr-manager-helper.c +13 -0
@@ -235,6 +235,18 @@ out:return ret; } +static bool pr_manager_helper_is_connected (PRManager *p) +{ +PRManagerHelper *pr_mgr =PR_MANAGER_HELPER (p); +bool result; + +qemu_mutex_lock (&pr_mgr->lock); + result = (pr_mgr->ioc !=NULL ); +qemu_mutex_unlock (&pr_mgr->lock); + +return result; +} +static void pr_manager_helper_complete (UserCreatable *uc,Error **errp) {PRManagerHelper *pr_mgr =PR_MANAGER_HELPER (uc);
@@ -284,6 +296,7 @@ static void pr_manager_helper_class_init(ObjectClass *klass, &error_abort); uc_klass->complete = pr_manager_helper_complete; prmgr_klass->run = pr_manager_helper_run; + prmgr_klass->is_connected = pr_manager_helper_is_connected; }static const TypeInfo pr_manager_helper_info = {
scsi/pr-manager-stub.c +6 -0
@@ -22,3 +22,9 @@ PRManager *pr_manager_lookup(const char *id, Error **errp)error_setg (errp,"No persistent reservation manager with id '%s'" , id);return NULL ; } + + +PRManagerInfoList *qmp_query_pr_managers (Error **errp) +{ +return NULL ; +}
scsi/pr-manager.c +45 -0
62 lines not on this page · raw message
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 37/60] pr-manager-helper: report event on connection/disconnection
In reply to Paolo BonziniLet management know if there were any problems communicating with qemu-pr-helper. The event is edge-triggered, and is sent every time the connection status of the pr-manager-helper object changes.
--- qapi/block.json | 24 ++++++++++++++++++++++++ scsi/pr-manager-helper.c | 14 ++++++++++++++ 2 files changed, 38 insertions(+)
qapi/block.json +24 -0
@@ -359,6 +359,30 @@ 'data': { 'device': 'str', 'id': 'str', 'tray-open': 'bool' } } ## +# @PR_MANAGER_STATUS_CHANGED: +# +# Emitted whenever the connected status of a persistent reservation +# manager changes. +# +# @id: The id of the PR manager object +# +# @connected: true if the PR manager is connected to a backend +# +# Since: 3.0 +# +# Example: +# +# <- { "event": "PR_MANAGER_STATUS_CHANGED", +# "data": { "id": "pr-helper0", +# "connected": true +# }, +# "timestamp": { "seconds": 1519840375, "microseconds": 450486 } } +# +## +{ 'event': 'PR_MANAGER_STATUS_CHANGED', + 'data': { 'id': 'str', 'connected': 'bool' } } + +## # @QuorumOpType: # # An enumeration of the quorum operation types
scsi/pr-manager-helper.c +14 -0
@@ -17,6 +17,7 @@#include "io/channel.h" #include "io/channel-socket.h" #include "pr-helper.h" +#include "qapi/qapi-events-block.h" #include <scsi/sg.h>
@@ -38,6 +39,16 @@ typedef struct PRManagerHelper {QIOChannel *ioc; } PRManagerHelper; +static void pr_manager_send_status_changed_event (PRManagerHelper *pr_mgr) +{ +char *id =object_get_canonical_path_component (OBJECT (pr_mgr)); + +if (id) { +qapi_event_send_pr_manager_status_changed (id, !!pr_mgr->ioc, + &error_abort); + } +} +/* Called with lock held. */ static int pr_manager_helper_read (PRManagerHelper *pr_mgr,void *buf,int sz,Error **errp)
@@ -47,6 +58,7 @@ static int pr_manager_helper_read(PRManagerHelper *pr_mgr,if (r <0 ) {object_unref (OBJECT (pr_mgr->ioc)); pr_mgr->ioc =NULL ; +pr_manager_send_status_changed_event (pr_mgr);return -EINVAL ; }
@@ -72,6 +84,7 @@ static int pr_manager_helper_write(PRManagerHelper *pr_mgr,assert (n_written !=QIO_CHANNEL_ERR_BLOCK );object_unref (OBJECT (pr_mgr->ioc)); pr_mgr->ioc =NULL ; +pr_manager_send_status_changed_event (pr_mgr);return n_written <0 ? -EINVAL :0 ; }
@@ -127,6 +140,7 @@ static int pr_manager_helper_initialize(PRManagerHelper *pr_mgr, goto out_close; } +pr_manager_send_status_changed_event (pr_mgr);return 0 ; out_close:
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 38/60] hw/mips/jazz: create ESP device directly via qdev
In reply to Paolo BonziniFrom: Mark Cave-Ayland <[email protected]>
MIPS jazz is the last user of the legacy esp_init() function so move creation of the ESP device over to use qdev.
Note that the esp_reset and dma_enable qemu_irqs are currently unused and so we do not wire these up and instead remove the variables to prevent the compiler emitting unused variable warnings.
Message-Id: <[email protected]>
--- hw/mips/mips_jazz.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
hw/mips/mips_jazz.c +16 -3
@@ -145,10 +145,10 @@ static void mips_jazz_init(MachineState *machine,ISABus *isa_bus;ISADevice *pit;DriveInfo *fds[MAX_FD ]; -qemu_irq esp_reset, dma_enable;MemoryRegion *ram =g_new (MemoryRegion,1 );MemoryRegion *bios =g_new (MemoryRegion,1 );MemoryRegion *bios2 =g_new (MemoryRegion,1 ); +SysBusESPState *sysbus_esp;ESPState *esp;/* init CPUs */
@@ -281,8 +281,21 @@ static void mips_jazz_init(MachineState *machine, }/* SCSI adapter */ - esp =esp_init (0x80002000 ,0 , rc4030_dma_read, rc4030_dma_write, dmas[0 ], -qdev_get_gpio_in (rc4030,5 ), &esp_reset, &dma_enable); + dev =qdev_create (NULL ,TYPE_ESP ); + sysbus_esp =ESP_STATE (dev); + esp = &sysbus_esp->esp; + esp->dma_memory_read = rc4030_dma_read; + esp->dma_memory_write = rc4030_dma_write; + esp->dma_opaque = dmas[0 ]; + sysbus_esp->it_shift =0 ; +/* XXX for now until rc4030 has been changed to use DMA enable signal */ + esp->dma_enabled =1 ; +qdev_init_nofail (dev); + + sysbus =SYS_BUS_DEVICE (dev); +sysbus_connect_irq (sysbus,0 ,qdev_get_gpio_in (rc4030,5 )); +sysbus_mmio_map (sysbus,0 ,0x80002000 ); +scsi_bus_legacy_handle_cmdline (&esp->bus);/* Floppy */
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 39/60] esp: remove legacy esp_init() function
In reply to Paolo BonziniFrom: Mark Cave-Ayland <[email protected]>
Remove the legacy esp_init() function now that there are no more remaining users.
Message-Id: <[email protected]>
--- hw/scsi/esp.c | 30 ------------------------------ include/hw/scsi/esp.h | 5 ----- 2 files changed, 35 deletions(-)
hw/scsi/esp.c +0 -30
@@ -619,36 +619,6 @@ static const MemoryRegionOps sysbus_esp_mem_ops = { .valid.accepts = esp_mem_accepts, }; -ESPState *esp_init (hwaddr espaddr,int it_shift, -ESPDMAMemoryReadWriteFunc dma_memory_read, -ESPDMAMemoryReadWriteFunc dma_memory_write, -void *dma_opaque,qemu_irq irq,qemu_irq *reset, -qemu_irq *dma_enable) -{ -DeviceState *dev; -SysBusDevice *s; -SysBusESPState *sysbus; -ESPState *esp; - - dev =qdev_create (NULL ,TYPE_ESP ); - sysbus =ESP_STATE (dev); - esp = &sysbus->esp; - esp->dma_memory_read = dma_memory_read; - esp->dma_memory_write = dma_memory_write; - esp->dma_opaque = dma_opaque; - sysbus->it_shift = it_shift; -/* XXX for now until rc4030 has been changed to use DMA enable signal */ - esp->dma_enabled =1 ; -qdev_init_nofail (dev); - s =SYS_BUS_DEVICE (dev); -sysbus_connect_irq (s,0 , irq); -sysbus_mmio_map (s,0 , espaddr); - *reset =qdev_get_gpio_in (dev,0 ); - *dma_enable =qdev_get_gpio_in (dev,1 ); - -return esp; -} -static const struct SCSIBusInfo esp_scsi_info = { .tcq = false, .max_target =ESP_MAX_DEVS ,
include/hw/scsi/esp.h +0 -5
@@ -131,11 +131,6 @@ typedef struct {#define TCHI_FAS100A 0x4#define TCHI_AM53C974 0x12 -ESPState *esp_init (hwaddr espaddr,int it_shift, -ESPDMAMemoryReadWriteFunc dma_memory_read, -ESPDMAMemoryReadWriteFunc dma_memory_write, -void *dma_opaque,qemu_irq irq,qemu_irq *reset, -qemu_irq *dma_enable);void esp_dma_enable (ESPState *s,int irq,int level);void esp_request_cancelled (SCSIRequest *req);void esp_command_complete (SCSIRequest *req,uint32_t status,size_t resid);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 40/60] WHPX workaround bug in OSVW handling
In reply to Paolo BonziniFrom: "Justin Terry (VM)" <[email protected]>
Adds a workaround to an incorrect value setting
CPUID Fn8000_0001_ECX[bit 9 OSVW] = 1. This can cause a guest linux kernel to panic when an issue to rdmsr C001_0140h returns 0. Disabling this feature correctly allows the guest to boot without accessing the osv workarounds.
Message-Id: <[email protected]>
--- target/i386/whpx-all.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
target/i386/whpx-all.c +12 -1
@@ -964,6 +964,16 @@ static int whpx_vcpu_run(CPUState *cpu) rdx = vcpu->exit_ctx.CpuidAccess.DefaultResultRdx; rbx = vcpu->exit_ctx.CpuidAccess.DefaultResultRbx;break ; +case 0x80000001 : + rax = vcpu->exit_ctx.CpuidAccess.DefaultResultRax; +/* Remove any support of OSVW */ + rcx = + vcpu->exit_ctx.CpuidAccess.DefaultResultRcx & + ~CPUID_EXT3_OSVW ; + + rdx = vcpu->exit_ctx.CpuidAccess.DefaultResultRdx; + rbx = vcpu->exit_ctx.CpuidAccess.DefaultResultRbx; +break ;default : rax = vcpu->exit_ctx.CpuidAccess.DefaultResultRax; rcx = vcpu->exit_ctx.CpuidAccess.DefaultResultRcx;
@@ -1382,12 +1392,13 @@ static int whpx_accel_init(MachineState *ms) goto error; } -UINT32 cpuidExitList[] = {1 }; +UINT32 cpuidExitList[] = {1 ,0x80000001 }; hr = whp_dispatch.WHvSetPartitionProperty ( whpx->partition, WHvPartitionPropertyCodeCpuidExitList, cpuidExitList,RTL_NUMBER_OF (cpuidExitList) *sizeof (UINT32 )); +if (FAILED (hr)) {error_report ("WHPX: Failed to set partition CpuidExitList hr=%08lx" , hr);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 41/60] WHPX: register for unrecognized MSR exits
In reply to Paolo BonziniFrom: "Justin Terry (VM)" <[email protected]>
Some variations of Linux kernels end up accessing MSR's that the Windows Hypervisor doesn't implement which causes a GP to be returned to the guest. This fix registers QEMU for unimplemented MSR access and globally returns 0 on reads and ignores writes. This behavior is allows the Linux kernel to probe the MSR with a write/read/check sequence it does often without failing the access.
Message-Id: <[email protected]>
--- target/i386/whpx-all.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-)
target/i386/whpx-all.c +38 -3
@@ -932,6 +932,7 @@ static int whpx_vcpu_run(CPUState *cpu)case WHvRunVpExitReasonX64InterruptWindow: vcpu->window_registered =0 ; + ret =0 ;break ;case WHvRunVpExitReasonX64Halt:
@@ -943,6 +944,40 @@ static int whpx_vcpu_run(CPUState *cpu) ret =1 ;break ; +case WHvRunVpExitReasonX64MsrAccess: { +WHV_REGISTER_VALUE reg_values[3 ] = {0 }; +WHV_REGISTER_NAME reg_names[3 ]; +UINT32 reg_count; + + reg_names[0 ] = WHvX64RegisterRip; + reg_names[1 ] = WHvX64RegisterRax; + reg_names[2 ] = WHvX64RegisterRdx; + + reg_values[0 ].Reg64 = + vcpu->exit_ctx.VpContext.Rip + + vcpu->exit_ctx.VpContext.InstructionLength; + +/* +* For all unsupported MSR access we: +* ignore writes +* return 0 on read. +*/ + reg_count = vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite ? +1 :3 ; + + hr = whp_dispatch.WHvSetVirtualProcessorRegisters ( + whpx->partition, + cpu->cpu_index, + reg_names, reg_count, + reg_values); + +if (FAILED (hr)) { +error_report ("WHPX: Failed to set MsrAccess state " +" registers, hr=%08lx" , hr); + } + ret =0 ; +break ; + }case WHvRunVpExitReasonX64Cpuid: {WHV_REGISTER_VALUE reg_values[5 ];WHV_REGISTER_NAME reg_names[5 ];
@@ -1010,7 +1045,6 @@ static int whpx_vcpu_run(CPUState *cpu)case WHvRunVpExitReasonUnrecoverableException:case WHvRunVpExitReasonInvalidVpRegisterValue:case WHvRunVpExitReasonUnsupportedFeature: -case WHvRunVpExitReasonX64MsrAccess:case WHvRunVpExitReasonException:default : error_report("WHPX: Unexpected VP exit code %d",
@@ -1378,6 +1412,7 @@ static int whpx_accel_init(MachineState *ms) }memset (&prop,0 ,sizeof (WHV_PARTITION_PROPERTY )); + prop.ExtendedVmExits.X64MsrExit =1 ; prop.ExtendedVmExits.X64CpuidExit =1 ; hr = whp_dispatch.WHvSetPartitionProperty( whpx->partition,
@@ -1386,8 +1421,8 @@ static int whpx_accel_init(MachineState *ms) sizeof(WHV_PARTITION_PROPERTY));if (FAILED (hr)) { -error_report ("WHPX: Failed to enable partition extended X64CpuidExit" -" hr=%08lx" , hr); +error_report ("WHPX: Failed to enable partition extended X64MsrExit and" +" X64CpuidExit hr=%08lx" , hr); ret = -EINVAL ; goto error; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 43/60] target-i386: Add NMI interception to SVM
In reply to Paolo BonziniFrom: Jan Kiszka <[email protected]>
Check for SVM interception prior to injecting an NMI. Tested via the Jailhouse hypervisor.
Message-Id: <c65877e9a011ee4962931287e59f502c482b8d0b.1522769774.git.jan.kiszka@web.de>
--- target/i386/seg_helper.c | 1 + 1 file changed, 1 insertion(+)
target/i386/seg_helper.c +1 -0
@@ -1337,6 +1337,7 @@ bool x86_cpu_exec_interrupt(CPUState *cs, int interrupt_request) ret = true; }else if ((interrupt_request &CPU_INTERRUPT_NMI ) && !(env->hflags2 &HF2_NMI_MASK )) { +cpu_svm_check_intercept_param (env,SVM_EXIT_NMI ,0 ,0 ); cs->interrupt_request &= ~CPU_INTERRUPT_NMI ; env->hflags2 |=HF2_NMI_MASK ;do_interrupt_x86_hardirq (env,EXCP02_NMI ,1 );
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 42/60] memory/hmp: Print owners/parents in "info mtree"
In reply to Paolo BonziniFrom: Alexey Kardashevskiy <[email protected]>
This adds owners/parents (which are the same, just occasionally owner==NULL) printing for memory regions; a new '-o' flag enabled new output.
Message-Id: <[email protected]>
--- hmp-commands-info.hx | 7 ++--- include/exec/memory.h | 2 +- memory.c | 72 ++++++++++++++++++++++++++++++++++++++++++++------- monitor.c | 4 ++- 4 files changed, 70 insertions(+), 15 deletions(-)
hmp-commands-info.hx +4 -3
@@ -253,10 +253,11 @@ ETEXI { .name = "mtree", - .args_type = "flatview:-f,dispatch_tree:-d", - .params = "[-f][-d]", + .args_type = "flatview:-f,dispatch_tree:-d,owner:-o", + .params = "[-f][-d][-o]", .help = "show memory tree (-f: dump flat view for address spaces;" - "-d: dump dispatch tree, valid with -f only)", + "-d: dump dispatch tree, valid with -f only);" + "-o: dump region owners/parents", .cmd = hmp_info_mtree, },
include/exec/memory.h +1 -1
@@ -1665,7 +1665,7 @@ void memory_global_dirty_log_start(void);void memory_global_dirty_log_stop (void );void mtree_info (fprintf_function mon_printf,void *f,bool flatview, -bool dispatch_tree); +bool dispatch_tree,bool owner);/** * memory_region_request_mmio_ptr: request a pointer to an mmio
memory.c +62 -10
155 lines not on this page · raw message
monitor.c +3 -1
@@ -2007,8 +2007,10 @@ static void hmp_info_mtree(Monitor *mon, const QDict *qdict) {bool flatview =qdict_get_try_bool (qdict,"flatview" , false);bool dispatch_tree =qdict_get_try_bool (qdict,"dispatch_tree" , false); +bool owner =qdict_get_try_bool (qdict,"owner" , false); -mtree_info ((fprintf_function )monitor_printf, mon, flatview, dispatch_tree); +mtree_info ((fprintf_function )monitor_printf, mon, flatview, dispatch_tree, + owner); }static void hmp_info_numa (Monitor *mon,const QDict *qdict)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 44/60] target-i386: Allow interrupt injection after STGI
In reply to Paolo BonziniFrom: Jan Kiszka <[email protected]>
We need to terminate the translation block after STGI so that pending interrupts can be injected.
This fixes pending NMI injection for Jailhouse which uses "stgi; clgi" to open a brief injection window.
Message-Id: <37939b244dda0e9cccf96ce50f2b15df1e48315d.1522769774.git.jan.kiszka@web.de>
--- target/i386/translate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target/i386/translate.c +2 -1
@@ -7444,8 +7444,9 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu)break ; }gen_update_cc_op (s); -gen_jmp_im (pc_start - s->cs_base);gen_helper_stgi (cpu_env); +gen_jmp_im (s->pc - s->cs_base); +gen_eob (s);break ;case 0xdd :/* CLGI */
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 45/60] target-i386: Mark cpu_vmexit noreturn
In reply to Paolo BonziniFrom: Jan Kiszka <[email protected]>
It calls cpu_loop_exit in system emulation mode (and should never be called in user emulation mode).
Message-Id: <6f4d44ffde55d074cbceb48309c1678600abad2f.1522769774.git.jan.kiszka@web.de>
--- target/i386/cpu.h | 4 ++-- target/i386/svm_helper.c | 1 + 2 files changed, 3 insertions(+), 2 deletions(-)
target/i386/cpu.h +2 -2
@@ -1840,8 +1840,8 @@ void helper_lock_init(void);/* svm_helper.c */ void cpu_svm_check_intercept_param (CPUX86State *env1,uint32_t type,uint64_t param,uintptr_t retaddr); -void cpu_vmexit (CPUX86State *nenv,uint32_t exit_code,uint64_t exit_info_1, -uintptr_t retaddr); +void QEMU_NORETURN cpu_vmexit(CPUX86State *nenv, uint32_t exit_code, +uint64_t exit_info_1,uintptr_t retaddr);void do_vmexit (CPUX86State *env,uint32_t exit_code,uint64_t exit_info_1);/* seg_helper.c */
target/i386/svm_helper.c +1 -0
@@ -62,6 +62,7 @@ void helper_invlpga(CPUX86State *env, int aflag)void cpu_vmexit (CPUX86State *nenv,uint32_t exit_code,uint64_t exit_info_1,uintptr_t retaddr) { +assert (0 ); } void helper_svm_check_intercept_param(CPUX86State *env, uint32_t type,
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 46/60] doc: another fix to "info pic"
In reply to Paolo BonziniFrom: Peter Xu <[email protected]>
Something that commit 254316fa1f ("intc: make HMP 'info irq' and 'info pic' commands available on all targets", 2016-10-04) forgot to touch up.
Message-Id: <[email protected]>
--- hmp-commands-info.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hmp-commands-info.hx +1 -1
@@ -201,7 +201,7 @@ ETEXI STEXI @item info pic @findex info pic -Show i8259 (PIC) state. +Show PIC state. ETEXI {
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 48/60] ioapic: some proper indents when dump info
In reply to Paolo BonziniFrom: Peter Xu <[email protected]>
So that now it looks better when with other irqchips.
Message-Id: <[email protected]>
--- hw/intc/ioapic_common.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
hw/intc/ioapic_common.c +4 -4
@@ -59,7 +59,7 @@ void ioapic_print_redtbl(Monitor *mon, IOAPICCommonState *s)uint32_t remote_irr =0 ;int i; -monitor_printf (mon,"ioapic ver=0x%x id=0x%02x sel=0x%02x" , +monitor_printf (mon,"ioapic0: ver=0x%x id=0x%02x sel=0x%02x" , s->version, s->id, s->ioregsel);if (s->ioregsel) { monitor_printf(mon, " (redir[%u])\n",
@@ -71,7 +71,7 @@ void ioapic_print_redtbl(Monitor *mon, IOAPICCommonState *s)uint64_t entry = s->ioredtbl[i];uint32_t delm = (uint32_t )((entry &IOAPIC_LVT_DELIV_MODE ) >>IOAPIC_LVT_DELIV_MODE_SHIFT ); - monitor_printf(mon, "pin %-2u 0x%016"PRIx64" dest=%"PRIx64 + monitor_printf(mon, " pin %-2u 0x%016"PRIx64" dest=%"PRIx64 " vec=%-3"PRIu64" %s %-5s %-6s %-6s %s\n", i, entry, (entry >> IOAPIC_LVT_DEST_SHIFT) &
@@ -86,8 +86,8 @@ void ioapic_print_redtbl(Monitor *mon, IOAPICCommonState *s) remote_irr |= entry &IOAPIC_LVT_TRIGGER_MODE ? (entry &IOAPIC_LVT_REMOTE_IRR ? (1 << i) :0 ) :0 ; } -ioapic_irr_dump (mon,"IRR" , s->irr); -ioapic_irr_dump (mon,"Remote IRR" , remote_irr); +ioapic_irr_dump (mon," IRR" , s->irr); +ioapic_irr_dump (mon," Remote IRR" , remote_irr); }void ioapic_reset_common (DeviceState *dev)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 47/60] ioapic: support "info pic"
In reply to Paolo BonziniFrom: Peter Xu <[email protected]>
People start to use "info pic" for all kinds of irqchip dumps. Let x86 ioapic join the family. It dumps the same thing as "info ioapic".
Message-Id: <[email protected]>
--- hw/intc/ioapic_common.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
hw/intc/ioapic_common.c +16 -0
@@ -24,6 +24,7 @@#include "monitor/monitor.h" #include "hw/i386/ioapic.h" #include "hw/i386/ioapic_internal.h" +#include "hw/intc/intc.h" #include "hw/sysbus.h" /* ioapic_no count start from 0 to MAX_IOAPICS,
@@ -142,6 +143,15 @@ static void ioapic_common_realize(DeviceState *dev, Error **errp) ioapic_no++; } +static void ioapic_print_info (InterruptStatsProvider *obj, +Monitor *mon) +{ +IOAPICCommonState *s =IOAPIC_COMMON (obj); + +ioapic_dispatch_pre_save (s); +ioapic_print_redtbl (mon, s); +} +static const VMStateDescription vmstate_ioapic_common = { .name ="ioapic" , .version_id =3 ,
@@ -161,9 +171,11 @@ static const VMStateDescription vmstate_ioapic_common = {static void ioapic_common_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); +InterruptStatsProviderClass *ic =INTERRUPT_STATS_PROVIDER_CLASS (klass); dc->realize = ioapic_common_realize; dc->vmsd = &vmstate_ioapic_common; + ic->print_info = ioapic_print_info; }static const TypeInfo ioapic_common_type = {
@@ -173,6 +185,10 @@ static const TypeInfo ioapic_common_type = { .class_size = sizeof(IOAPICCommonClass), .class_init = ioapic_common_class_init, .abstract = true, + .interfaces = (InterfaceInfo []) { + {TYPE_INTERRUPT_STATS_PROVIDER }, + { } + }, };static void ioapic_common_register_types (void )
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 49/60] ioapic: support "info irq"
In reply to Paolo BonziniFrom: Peter Xu <[email protected]>
This include both userspace and in-kernel ioapic. Note that the numbers can be inaccurate for kvm-ioapic. One reason is the same with kvm-i8259, that when irqfd is used, irqs can be delivered all inside kernel without our notice. Meanwhile, kvm-ioapic is specially treated when irq numbers <ISA_NUM_IRQS, those irqs will be delivered in kernel too via kvm-i8259 (please refer to kvm_pc_gsi_handler).
Message-Id: <[email protected]>
--- hw/i386/kvm/ioapic.c | 2 ++ hw/intc/ioapic.c | 1 + hw/intc/ioapic_common.c | 23 +++++++++++++++++++++++ include/hw/i386/ioapic_internal.h | 3 +++ 4 files changed, 29 insertions(+)
hw/i386/kvm/ioapic.c +2 -0
@@ -132,8 +132,10 @@ static void kvm_ioapic_reset(DeviceState *dev)static void kvm_ioapic_set_irq (void *opaque,int irq,int level) {KVMIOAPICState *s = opaque; +IOAPICCommonState *common =IOAPIC_COMMON (s);int delivered; +ioapic_stat_update_irq (common, irq, level); delivered =kvm_set_irq (kvm_state, s->kvm_gsi_base + irq, level);apic_report_irq_delivered (delivered); }
hw/intc/ioapic.c +1 -0
@@ -148,6 +148,7 @@ static void ioapic_set_irq(void *opaque, int vector, int level)* the cleanest way of doing it but it should work. */ trace_ioapic_set_irq (vector, level); +ioapic_stat_update_irq (s, vector, level);if (vector ==0 ) { vector =2 ; }
hw/intc/ioapic_common.c +23 -0
@@ -35,6 +35,28 @@*/ int ioapic_no; +void ioapic_stat_update_irq (IOAPICCommonState *s,int irq,int level) +{ +if (level != s->irq_level[irq]) { + s->irq_level[irq] = level; +if (level ==1 ) { + s->irq_count[irq]++; + } + } +} + +static bool ioapic_get_statistics (InterruptStatsProvider *obj, +uint64_t **irq_counts, +unsigned int *nb_irqs) +{ +IOAPICCommonState *s =IOAPIC_COMMON (obj); + + *irq_counts = s->irq_count; + *nb_irqs =IOAPIC_NUM_PINS ; + +return true; +} +static void ioapic_irr_dump (Monitor *mon,const char *name,uint32_t bitmap) {int i;
@@ -176,6 +198,7 @@ static void ioapic_common_class_init(ObjectClass *klass, void *data) dc->realize = ioapic_common_realize; dc->vmsd = &vmstate_ioapic_common; ic->print_info = ioapic_print_info; + ic->get_statistics = ioapic_get_statistics; }static const TypeInfo ioapic_common_type = {
include/hw/i386/ioapic_internal.h +3 -0
@@ -109,10 +109,13 @@ struct IOAPICCommonState {uint64_t ioredtbl[IOAPIC_NUM_PINS ];Notifier machine_done;uint8_t version; +uint64_t irq_count[IOAPIC_NUM_PINS ]; + int irq_level[IOAPIC_NUM_PINS]; };void ioapic_reset_common (DeviceState *dev);void ioapic_print_redtbl (Monitor *mon,IOAPICCommonState *s); +void ioapic_stat_update_irq (IOAPICCommonState *s,int irq,int level);#endif /* QEMU_IOAPIC_INTERNAL_H */
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 50/60] hmp: obsolete "info ioapic"
In reply to Paolo BonziniFrom: Peter Xu <[email protected]>
Let's start to use "info pic" just like other platforms. For now we keep the command for a while so that old users can know what is the new command to use.
Message-Id: <[email protected]>
--- hw/i386/kvm/ioapic.c | 9 --------- hw/intc/ioapic.c | 11 ----------- include/hw/i386/pc.h | 3 --- target/i386/monitor.c | 8 ++------ 4 files changed, 2 insertions(+), 29 deletions(-)
hw/i386/kvm/ioapic.c +0 -9
@@ -112,15 +112,6 @@ static void kvm_ioapic_put(IOAPICCommonState *s) } } -void kvm_ioapic_dump_state (Monitor *mon,const QDict *qdict) -{ -IOAPICCommonState *s =IOAPIC_COMMON (object_resolve_path ("ioapic" ,NULL )); - -assert (s); -kvm_ioapic_get (s); -ioapic_print_redtbl (mon, s); -} -static void kvm_ioapic_reset (DeviceState *dev) {IOAPICCommonState *s =IOAPIC_COMMON (dev);
hw/intc/ioapic.c +0 -11
@@ -234,17 +234,6 @@ void ioapic_eoi_broadcast(int vector) } } -void ioapic_dump_state (Monitor *mon,const QDict *qdict) -{ -int i; - -for (i =0 ; i <MAX_IOAPICS ; i++) { -if (ioapics[i] !=0 ) { -ioapic_print_redtbl (mon, ioapics[i]); - } - } -} -static uint64_t ioapic_mem_read (void *opaque,hwaddr addr,unsigned int size) {
include/hw/i386/pc.h +0 -3
@@ -154,9 +154,6 @@ int pic_get_output(DeviceState *d);/* ioapic.c */ -void kvm_ioapic_dump_state (Monitor *mon,const QDict *qdict); -void ioapic_dump_state (Monitor *mon,const QDict *qdict); -/* Global System Interrupts */ #define GSI_NUM_PINS IOAPIC_NUM_PINS
target/i386/monitor.c +2 -6
@@ -658,12 +658,8 @@ void hmp_info_local_apic(Monitor *mon, const QDict *qdict)void hmp_info_io_apic (Monitor *mon,const QDict *qdict) { -if (kvm_irqchip_in_kernel () && - !kvm_irqchip_is_split ()) { -kvm_ioapic_dump_state (mon, qdict); - }else { -ioapic_dump_state (mon, qdict); - } +monitor_printf (mon,"This command is obsolete and will be " +"removed soon. Please use 'info pic' instead.\n" ); }SevInfo *qmp_query_sev (Error **errp)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 51/60] kvm: support -overcommit cpu-pm=on|off
In reply to Paolo BonziniFrom: "Michael S. Tsirkin" <[email protected]>
With this flag, kvm allows guest to control host CPU power state. This increases latency for other processes using same host CPU in an unpredictable way, but if decreases idle entry/exit times for the running VCPU, so to use it QEMU needs a hint about whether host CPU is overcommitted, hence the flag name.
Follow-up patches will expose this capability to guest (using mwait leaf).
Based on a patch by Wanpeng Li <[email protected]> .
Message-Id: <[email protected]>
--- include/sysemu/sysemu.h | 1 + qemu-options.hx | 24 ++++++++++++++++++++++++ target/i386/kvm.c | 23 +++++++++++++++++++++++ vl.c | 32 +++++++++++++++++++++++++++++++- 4 files changed, 79 insertions(+), 1 deletion(-)
include/sysemu/sysemu.h +1 -0
@@ -128,6 +128,7 @@ extern bool boot_strict;extern uint8_t *boot_splash_filedata;extern size_t boot_splash_filedata_size;extern bool enable_mlock; +extern bool enable_cpu_pm;extern uint8_t qemu_extra_params_fw[2 ];extern QEMUClockType rtc_clock;extern const char *mem_path;
qemu-options.hx +24 -0
@@ -3325,6 +3325,30 @@ mlocking qemu and guest memory can be enabled via @option{mlock=on} (enabled by default). ETEXI +DEF("overcommit", HAS_ARG, QEMU_OPTION_overcommit, + "--overcommit [mem-lock=on|off][cpu-pm=on|off]\n" + " run qemu with overcommit hints\n" + " mem-lock=on|off controls memory lock support (default: off)\n" + " cpu-pm=on|off controls cpu power management (default: off)\n", + QEMU_ARCH_ALL) +STEXI +@item -overcommit mem-lock=on|off +@item -overcommit cpu-pm=on|off +@findex -overcommit +Run qemu with hints about host resource overcommit. The default is +to assume that host overcommits all resources. + +Locking qemu and guest memory can be enabled via @option{mem-lock=on} (disabled +by default). This works when host memory is not overcommitted and reduces the +worst-case latency for guest. This is equivalent to @option{realtime}. + +Guest ability to manage power state of host cpus (increasing latency for other +processes on the same host cpu, but decreasing latency for guest) can be +enabled via @option{cpu-pm=on} (disabled by default). This works best when +host CPU is not overcommitted. When used, host estimates of CPU cycle and power +utilization will be incorrect, not taking into account guest idle time. +ETEXI + DEF("gdb", HAS_ARG, QEMU_OPTION_gdb, \ "-gdb dev wait for gdb connection on 'dev'\n", QEMU_ARCH_ALL) STEXI
target/i386/kvm.c +23 -0
@@ -1387,6 +1387,29 @@ int kvm_arch_init(MachineState *ms, KVMState *s) smram_machine_done.notify = register_smram_listener;qemu_add_machine_init_done_notifier (&smram_machine_done); } + +if (enable_cpu_pm) { +int disable_exits =kvm_check_extension (s,KVM_CAP_X86_DISABLE_EXITS ); +int ret; + +/* Work around for kernel header with a typo. TODO: fix header and drop. */ +#if defined(KVM_X86_DISABLE_EXITS_HTL ) && !defined(KVM_X86_DISABLE_EXITS_HLT ) +#define KVM_X86_DISABLE_EXITS_HLT KVM_X86_DISABLE_EXITS_HTL +#endif +if (disable_exits) { + disable_exits &= (KVM_X86_DISABLE_EXITS_MWAIT | +KVM_X86_DISABLE_EXITS_HLT | +KVM_X86_DISABLE_EXITS_PAUSE ); + } + + ret =kvm_vm_enable_cap (s,KVM_CAP_X86_DISABLE_EXITS ,0 , + disable_exits); +if (ret <0 ) { +error_report ("kvm: guest stopping CPU not supported: %s" , +strerror (-ret)); + } + } +return 0 ; }
vl.c +31 -1
@@ -142,6 +142,7 @@ ram_addr_t ram_size;const char *mem_path =NULL ;int mem_prealloc =0 ;/* force preallocation of physical target memory */ bool enable_mlock = false; +bool enable_cpu_pm = false;int nb_nics;NICInfo nd_table[MAX_NICS ];int autostart;
@@ -390,6 +391,22 @@ static QemuOptsList qemu_realtime_opts = { }, }; +static QemuOptsList qemu_overcommit_opts = { + .name ="overcommit" , + .head =QTAILQ_HEAD_INITIALIZER (qemu_overcommit_opts.head), + .desc = { + { + .name ="mem-lock" , + .type =QEMU_OPT_BOOL , + }, + { + .name ="cpu-pm" , + .type =QEMU_OPT_BOOL , + }, + {/* end of list */ } + }, +}; +static QemuOptsList qemu_msg_opts = { .name ="msg" , .head =QTAILQ_HEAD_INITIALIZER (qemu_msg_opts.head),
@@ -3906,7 +3923,20 @@ int main(int argc, char **argv, char **envp)if (!opts) {exit (1 ); } - enable_mlock =qemu_opt_get_bool (opts,"mlock" , true); +/* Don't override the -overcommit option if set */ + enable_mlock = enable_mlock || +qemu_opt_get_bool (opts,"mlock" , true); +break ; +case QEMU_OPTION_overcommit: + opts =qemu_opts_parse_noisily (qemu_find_opts ("overcommit" ), + optarg, false); +if (!opts) { +exit (1 ); + } +/* Don't override the -realtime option if set */ + enable_mlock = enable_mlock || +qemu_opt_get_bool (opts,"mem-lock" , false); + enable_cpu_pm =qemu_opt_get_bool (opts,"cpu-pm" , false);break ;case QEMU_OPTION_msg: opts = qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg,
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 52/60] i386/cpu: make -cpu host support monitor/mwait
In reply to Paolo BonziniFrom: "Michael S. Tsirkin" <[email protected]>
When guest CPU PM is enabled, and with -cpu host, expose the host CPU MWAIT leaf in the CPUID so guest can make good PM decisions.
Note: the result is 100% CPU utilization reported by host as host no longer knows that the CPU is halted.
Message-Id: <[email protected]>
--- target/i386/cpu.c | 19 ++++++++++++++----- target/i386/cpu.h | 9 +++++++++ target/i386/kvm.c | 9 +++++++++ 3 files changed, 32 insertions(+), 5 deletions(-)
target/i386/cpu.c +14 -5
@@ -3959,11 +3959,11 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, }break ;case 5 : -/* mwait info: needed for Core compatibility */ - *eax =0 ;/* Smallest monitor-line size in bytes */ - *ebx =0 ;/* Largest monitor-line size in bytes */ - *ecx =CPUID_MWAIT_EMX |CPUID_MWAIT_IBE ; - *edx =0 ; +/* MONITOR/MWAIT Leaf */ + *eax = cpu->mwait.eax;/* Smallest monitor-line size in bytes */ + *ebx = cpu->mwait.ebx;/* Largest monitor-line size in bytes */ + *ecx = cpu->mwait.ecx;/* flags */ + *edx = cpu->mwait.edx;/* mwait substates */ break ;case 6 :/* Thermal and Power Leaf */
@@ -4811,6 +4811,15 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) goto out; } +if (xcc->host_cpuid_required && enable_cpu_pm) { +host_cpuid (5 ,0 , &cpu->mwait.eax, &cpu->mwait.ebx, + &cpu->mwait.ecx, &cpu->mwait.edx); + env->features[FEAT_1_ECX ] |=CPUID_EXT_MONITOR ; + } +/* mwait extended info: needed for Core compatibility */ +/* We always wake on interrupt even if host does not have the capability */ + cpu->mwait.ecx |=CPUID_MWAIT_EMX |CPUID_MWAIT_IBE ; +if (cpu->apic_id ==UNASSIGNED_APIC_ID ) {error_setg (errp,"apic-id property was not initialized properly" );return ;
target/i386/cpu.h +9 -0
@@ -1382,6 +1382,15 @@ struct X86CPU {/* if true the CPUID code directly forward host cache leaves to the guest */ bool cache_info_passthrough; +/* if true the CPUID code directly forwards +* host monitor/mwait leaves to the guest */ +struct { +uint32_t eax; +uint32_t ebx; +uint32_t ecx; +uint32_t edx; + } mwait; +/* Features that were filtered out because of missing host capabilities */ uint32_t filtered_features[FEATURE_WORDS ];
target/i386/kvm.c +9 -0
@@ -366,6 +366,15 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,if (!kvm_irqchip_in_kernel ()) { ret &= ~CPUID_EXT_X2APIC ; } + +if (enable_cpu_pm) { +int disable_exits =kvm_check_extension (s, +KVM_CAP_X86_DISABLE_EXITS ); + +if (disable_exits &KVM_X86_DISABLE_EXITS_MWAIT ) { + ret |=CPUID_EXT_MONITOR ; + } + } }else if (function ==6 && reg ==R_EAX ) { ret |=CPUID_6_EAX_ARAT ;/* safe to allow because of emulated APIC */ }else if (function ==7 && index ==0 && reg ==R_EBX ) {
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 53/60] dump: add Windows dump format to dump-guest-memory
In reply to Paolo BonziniFrom: Viktor Prutyanov <[email protected]>
This patch adds Windows crashdumping feature. Now QEMU can produce ELF-dump containing Windows crashdump header, which can help to convert to a valid WinDbg-understandable crashdump file, or immediately create such file. The crashdump will be obtained by joining physical memory dump and 8K header exposed through vmcoreinfo/fw_cfg device by guest driver at BSOD time. Option '-w' was added to dump-guest-memory command. At the moment, only x64 configuration is supported.
Suitable driver can be found at
https://github.com/virtio-win/kvm-guest-drivers-windows/tree/master/fwcfg64
Message-Id: <[email protected]>
--- Makefile.target | 1 + dump.c | 24 ++++++- hmp-commands.hx | 13 ++-- hmp.c | 9 ++- qapi/misc.json | 5 +- win_dump.c | 209 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ win_dump.h | 87 +++++++++++++++++++++++ 7 files changed, 339 insertions(+), 9 deletions(-) create mode 100644 win_dump.c create mode 100644 win_dump.h
Makefile.target +1 -0
@@ -143,6 +143,7 @@ obj-y += hw/ obj-y += memory.o obj-y += memory_mapping.o obj-y += dump.o +obj-$(TARGET_X86_64) += win_dump.o obj-y += migration/ram.o LIBS := $(libs_softmmu) $(LIBS)
dump.c +23 -1
@@ -29,6 +29,10 @@#include "qemu/error-report.h" #include "hw/misc/vmcoreinfo.h" +#ifdef TARGET_X86_64 +#include "win_dump.h" +#endif +#include <zlib.h> #ifdef CONFIG_LZO #include <lzo/lzo1x.h>
@@ -1866,7 +1870,11 @@ static void dump_process(DumpState *s, Error **errp)Error *local_err =NULL ;DumpQueryResult *result =NULL ; -if (s->has_format && s->format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) { +if (s->has_format && s->format ==DUMP_GUEST_MEMORY_FORMAT_WIN_DMP ) { +#ifdef TARGET_X86_64 +create_win_dump (s, &local_err); +#endif + }else if (s->has_format && s->format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) {create_kdump_vmcore (s, &local_err); }else {create_vmcore (s, &local_err);
@@ -1970,6 +1978,13 @@ void qmp_dump_guest_memory(bool paging, const char *file, }#endif +#ifndef TARGET_X86_64 +if (has_format && format ==DUMP_GUEST_MEMORY_FORMAT_WIN_DMP ) { +error_setg (errp,"Windows dump is only available for x86-64" ); +return ; + } +#endif +#if !defined(WIN32 )if (strstart (file,"fd:" , &p)) { fd =monitor_get_fd (cur_mon, p, errp);
@@ -2044,5 +2059,12 @@ DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability(Error **errp) item->value =DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY ;#endif +/* Windows dump is available only if target is x86_64 */ +#ifdef TARGET_X86_64 + item->next =g_malloc0 (sizeof (DumpGuestMemoryFormatList)); + item = item->next; + item->value =DUMP_GUEST_MEMORY_FORMAT_WIN_DMP ; +#endif +return cap; }
hmp-commands.hx +8 -5
@@ -1136,30 +1136,33 @@ ETEXI { .name = "dump-guest-memory", - .args_type = "paging:-p,detach:-d,zlib:-z,lzo:-l,snappy:-s,filename:F,begin:l?,length:l?", - .params = "[-p] [-d] [-z|-l|-s] filename [begin length]", + .args_type = "paging:-p,detach:-d,windmp:-w,zlib:-z,lzo:-l,snappy:-s,filename:F,begin:l?,length:l?", + .params = "[-p] [-d] [-z|-l|-s|-w] filename [begin length]", .help = "dump guest memory into file 'filename'.\n\t\t\t" "-p: do paging to get guest's memory mapping.\n\t\t\t" "-d: return immediately (do not wait for completion).\n\t\t\t" "-z: dump in kdump-compressed format, with zlib compression.\n\t\t\t" "-l: dump in kdump-compressed format, with lzo compression.\n\t\t\t" "-s: dump in kdump-compressed format, with snappy compression.\n\t\t\t" + "-w: dump in Windows crashdump format (can be used instead of ELF-dump converting),\n\t\t\t" + " for Windows x64 guests with vmcoreinfo driver only.\n\t\t\t" "begin: the starting physical address.\n\t\t\t" "length: the memory size, in bytes.", .cmd = hmp_dump_guest_memory, }, - STEXI @item dump-guest-memory [-p] @var{filename} @var{begin} @var{length} -@item dump-guest-memory [-z|-l|-s] @var{filename} +@item dump-guest-memory [-z|-l|-s|-w] @var{filename} @findex dump-guest-memory Dump guest memory to @var{protocol}. The file can be processed with crash or -gdb. Without -z|-l|-s, the dump format is ELF. +gdb. Without -z|-l|-s|-w, the dump format is ELF. -p: do paging to get guest's memory mapping. -z: dump in kdump-compressed format, with zlib compression. -l: dump in kdump-compressed format, with lzo compression. -s: dump in kdump-compressed format, with snappy compression. + -w: dump in Windows crashdump format (can be used instead of ELF-dump converting), + for Windows x64 guests with vmcoreinfo driver only filename: dump file name. begin: the starting physical address. It's optional, and should be specified together with length.
hmp.c +7 -2
@@ -2014,6 +2014,7 @@ void hmp_device_del(Monitor *mon, const QDict *qdict)void hmp_dump_guest_memory (Monitor *mon,const QDict *qdict) {Error *err =NULL ; +bool win_dmp =qdict_get_try_bool (qdict,"windmp" , false);bool paging =qdict_get_try_bool (qdict,"paging" , false);bool zlib =qdict_get_try_bool (qdict,"zlib" , false);bool lzo =qdict_get_try_bool (qdict,"lzo" , false);
@@ -2028,12 +2029,16 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)enum DumpGuestMemoryFormat dump_format =DUMP_GUEST_MEMORY_FORMAT_ELF ;char *prot; -if (zlib + lzo + snappy >1 ) { -error_setg (&err,"only one of '-z|-l|-s' can be set" ); +if (zlib + lzo + snappy + win_dmp >1 ) { +error_setg (&err,"only one of '-z|-l|-s|-w' can be set" );hmp_handle_error (mon, &err);return ; } +if (win_dmp) { + dump_format =DUMP_GUEST_MEMORY_FORMAT_WIN_DMP ; + } +if (zlib) { dump_format =DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB ; }
qapi/misc.json +4 -1
@@ -1677,10 +1677,13 @@ # # @kdump-snappy: kdump-compressed format with snappy-compressed # +# @win-dmp: Windows full crashdump format, +# can be used instead of ELF converting (since 2.13) +# # Since: 2.0 ## { 'enum': 'DumpGuestMemoryFormat', - 'data': [ 'elf', 'kdump-zlib', 'kdump-lzo', 'kdump-snappy' ] } + 'data': [ 'elf', 'kdump-zlib', 'kdump-lzo', 'kdump-snappy', 'win-dmp' ] } ## # @dump-guest-memory:
win_dump.c new file +209 -0
209 lines not on this page · raw message
win_dump.h new file +87 -0
87 lines not on this page · raw message
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 54/60] dump: use system context in Windows dump
In reply to Paolo BonziniFrom: Viktor Prutyanov <[email protected]>
We use CPU #0 to access guest virtual memory, but it can execute user thread at that moment. So, switch CR3 to PageDirectoryBase from header and restore original value at the end.
Message-Id: <[email protected]>
--- win_dump.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
win_dump.c +17 -9
@@ -111,12 +111,6 @@ static void patch_header(WinDumpHeader64 *h) h->PhysicalMemoryBlock.unused =0 ; h->unused1 =0 ; -/* -* We assume h->DirectoryBase and current CR3 are the same when we access -* memory by virtual address. In other words, we suppose current context -* is system context. It is definetely true in case of BSOD. -*/ -patch_mm_pfn_database (h, &local_err);if (local_err) {warn_report_err (local_err);
@@ -171,6 +165,8 @@ void create_win_dump(DumpState *s, Error **errp) { WinDumpHeader64 *h = (WinDumpHeader64 *)(s->guest_note + VMCOREINFO_ELF_NOTE_HDR_SIZE); + X86CPU *first_x86_cpu = X86_CPU(first_cpu); + uint64_t saved_cr3 = first_x86_cpu->env.cr[3]; Error *local_err = NULL; if (s->guest_note_size != sizeof(WinDumpHeader64) +
@@ -185,10 +181,17 @@ void create_win_dump(DumpState *s, Error **errp)return ; } +/* +* Further access to kernel structures by virtual addresses +* should be made from system context. +*/ + + first_x86_cpu->env.cr[3 ] = h->DirectoryTableBase; +check_kdbg (h, &local_err);if (local_err) {error_propagate (errp, local_err); -return ; + goto out_cr3; }patch_header (h);
@@ -198,12 +201,17 @@ void create_win_dump(DumpState *s, Error **errp) s->written_size =qemu_write_full (s->fd, h,sizeof (*h));if (s->written_size !=sizeof (*h)) {error_setg (errp,QERR_IO_ERROR ); -return ; + goto out_cr3; }write_runs (s, h, &local_err);if (local_err) {error_propagate (errp, local_err); -return ; + goto out_cr3; } + +out_cr3: + first_x86_cpu->env.cr[3 ] = saved_cr3; + +return ; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 55/60] dump: add fallback KDBG using in Windows dump
In reply to Paolo BonziniFrom: Viktor Prutyanov <[email protected]>
KdDebuggerDataBlock may be encrypted in guest memory and dump will be useless in this case. But guest driver can obtain decrypted KDBG and expose its address through BugcheckParameter1 field in raw header. After this patch, QEMU will be able to use fallback KdDebuggerDataBlock.
Message-Id: <[email protected]>
--- win_dump.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
win_dump.c +22 -6
@@ -144,21 +144,37 @@ static void check_kdbg(WinDumpHeader64 *h, Error **errp) {const char OwnerTag[] ="KDBG" ;char read_OwnerTag[4 ]; +uint64_t KdDebuggerDataBlock = h->KdDebuggerDataBlock; +bool try_fallback = true; +try_again:if (cpu_memory_rw_debug (first_cpu, - h->KdDebuggerDataBlock +KDBG_OWNER_TAG_OFFSET64 , + KdDebuggerDataBlock +KDBG_OWNER_TAG_OFFSET64 , (uint8_t *)&read_OwnerTag,sizeof (read_OwnerTag),0 )) {error_setg (errp,"win-dump: failed to read OwnerTag" );return ; }if (memcmp (read_OwnerTag, OwnerTag,sizeof (read_OwnerTag))) { -error_setg (errp,"win-dump: invalid KDBG OwnerTag," -" expected '%.4s', got '%.4s'," -" KdDebuggerDataBlock seems to be encrypted" , - OwnerTag, read_OwnerTag); -return ; +if (try_fallback) { +/* +* If attempt to use original KDBG failed +* (most likely because of its encryption), +* we try to use KDBG obtained by guest driver. +*/ + + KdDebuggerDataBlock = h->BugcheckParameter1; + try_fallback = false; + goto try_again; + }else { +error_setg (errp,"win-dump: invalid KDBG OwnerTag," +" expected '%.4s', got '%.4s'" , + OwnerTag, read_OwnerTag); +return ; + } } + + h->KdDebuggerDataBlock = KdDebuggerDataBlock; }void create_win_dump (DumpState *s,Error **errp)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 56/60] dump: add Windows live system dump
In reply to Paolo BonziniFrom: Viktor Prutyanov <[email protected]>
Unlike dying Windows, live system memory doesn't contain correct register contexts. But they can be populated with QEMU register values.
After this patch, QEMU will be able to produce guest Windows live system dump.
Message-Id: <[email protected]>
--- win_dump.c | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- win_dump.h | 95 +++++++++++++++++++++++++++++++++++-- 2 files changed, 246 insertions(+), 5 deletions(-)
win_dump.c +154 -2
@@ -97,6 +97,14 @@ static void patch_bugcheck_data(WinDumpHeader64 *h, Error **errp)error_setg (errp,"win-dump: failed to read bugcheck data" );return ; } + +/* +* If BugcheckCode wasn't saved, we consider guest OS as alive. +*/ + +if (!h->BugcheckCode) { + h->BugcheckCode =LIVE_SYSTEM_DUMP ; + } }/*
@@ -177,12 +185,139 @@ try_again: h->KdDebuggerDataBlock = KdDebuggerDataBlock; } +struct saved_context { +WinContext ctx; +uint64_t addr; +}; + +static void patch_and_save_context (WinDumpHeader64 *h, +struct saved_context *saved_ctx, +Error **errp) +{ +uint64_t KiProcessorBlock; +uint16_t OffsetPrcbContext; +CPUState *cpu; +int i =0 ; + +if (cpu_memory_rw_debug (first_cpu, + h->KdDebuggerDataBlock +KDBG_KI_PROCESSOR_BLOCK_OFFSET64 , + (uint8_t *)&KiProcessorBlock,sizeof (KiProcessorBlock),0 )) { +error_setg (errp,"win-dump: failed to read KiProcessorBlock" ); +return ; + } + +if (cpu_memory_rw_debug (first_cpu, + h->KdDebuggerDataBlock +KDBG_OFFSET_PRCB_CONTEXT_OFFSET64 , + (uint8_t *)&OffsetPrcbContext,sizeof (OffsetPrcbContext),0 )) { +error_setg (errp,"win-dump: failed to read OffsetPrcbContext" ); +return ; + } + +CPU_FOREACH (cpu) { +X86CPU *x86_cpu =X86_CPU (cpu); +CPUX86State *env = &x86_cpu->env; +uint64_t Prcb; +uint64_t Context; +WinContext ctx; + +if (cpu_memory_rw_debug (first_cpu, + KiProcessorBlock + i *sizeof (uint64_t ), + (uint8_t *)&Prcb,sizeof (Prcb),0 )) { +error_setg (errp,"win-dump: failed to read" +" CPU #%d PRCB location" , i); +return ; + } + +if (cpu_memory_rw_debug (first_cpu, + Prcb + OffsetPrcbContext, + (uint8_t *)&Context,sizeof (Context),0 )) { +error_setg (errp,"win-dump: failed to read" +" CPU #%d ContextFrame location" , i); +return ; + } + + saved_ctx[i].addr = Context; + + ctx = (WinContext ){ + .ContextFlags =WIN_CTX_ALL , + .MxCsr = env->mxcsr, + + .SegEs = env->segs[0 ].selector, + .SegCs = env->segs[1 ].selector, + .SegSs = env->segs[2 ].selector, + .SegDs = env->segs[3 ].selector, + .SegFs = env->segs[4 ].selector, + .SegGs = env->segs[5 ].selector, + .EFlags =cpu_compute_eflags (env), + + .Dr0 = env->dr[0 ], + .Dr1 = env->dr[1 ], + .Dr2 = env->dr[2 ], + .Dr3 = env->dr[3 ], + .Dr6 = env->dr[6 ], + .Dr7 = env->dr[7 ], + + .Rax = env->regs[R_EAX ], + .Rbx = env->regs[R_EBX ], + .Rcx = env->regs[R_ECX ], + .Rdx = env->regs[R_EDX ], + .Rsp = env->regs[R_ESP ], + .Rbp = env->regs[R_EBP ], + .Rsi = env->regs[R_ESI ], + .Rdi = env->regs[R_EDI ], + .R8 = env->regs[8 ], + .R9 = env->regs[9 ], + .R10 = env->regs[10 ], + .R11 = env->regs[11 ], + .R12 = env->regs[12 ], + .R13 = env->regs[13 ], + .R14 = env->regs[14 ], + .R15 = env->regs[15 ], + + .Rip = env->eip, + .FltSave = { + .MxCsr = env->mxcsr, + }, + }; + +if (cpu_memory_rw_debug (first_cpu, Context, + (uint8_t *)&saved_ctx[i].ctx,sizeof (WinContext),0 )) { +error_setg (errp,"win-dump: failed to save CPU #%d context" , i); +return ; + } + +if (cpu_memory_rw_debug (first_cpu, Context, + (uint8_t *)&ctx,sizeof (WinContext),1 )) { +error_setg (errp,"win-dump: failed to write CPU #%d context" , i); +return ; + } + + i++; + } +} + +static void restore_context (WinDumpHeader64 *h, +struct saved_context *saved_ctx) +{ +int i; +Error *err =NULL ; + +for (i =0 ; i < h->NumberProcessors; i++) { +if (cpu_memory_rw_debug (first_cpu, saved_ctx[i].addr, + (uint8_t *)&saved_ctx[i].ctx,sizeof (WinContext),1 )) { +error_setg (&err,"win-dump: failed to restore CPU #%d context" , i); +warn_report_err (err); + } + } +} + void create_win_dump(DumpState *s, Error **errp) { WinDumpHeader64 *h = (WinDumpHeader64 *)(s->guest_note + VMCOREINFO_ELF_NOTE_HDR_SIZE); X86CPU *first_x86_cpu = X86_CPU(first_cpu); uint64_t saved_cr3 = first_x86_cpu->env.cr[3]; + struct saved_context *saved_ctx = NULL; Error *local_err = NULL; if (s->guest_note_size != sizeof(WinDumpHeader64) +
@@ -212,20 +347,37 @@ void create_win_dump(DumpState *s, Error **errp)patch_header (h); + saved_ctx = g_new(struct saved_context, h->NumberProcessors); + +/* +* Always patch context because there is no way +* to determine if the system-saved context is valid +*/ + +patch_and_save_context (h, saved_ctx, &local_err); +if (local_err) { +error_propagate (errp, local_err); + goto out_free; + } + s->total_size = h->RequiredDumpSpace; s->written_size =qemu_write_full (s->fd, h,sizeof (*h));if (s->written_size !=sizeof (*h)) {error_setg (errp,QERR_IO_ERROR ); - goto out_cr3; + goto out_restore; }write_runs (s, h, &local_err);if (local_err) {error_propagate (errp, local_err); - goto out_cr3; + goto out_restore; } +out_restore: +restore_context (h, saved_ctx); +out_free: +g_free (saved_ctx); out_cr3: first_x86_cpu->env.cr[3 ] = saved_cr3;
win_dump.h +92 -3
100 lines not on this page · raw message
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 58/60] hw/scsi: centralize SG_IO calls into single function
In reply to Paolo BonziniFrom: Daniel Henrique Barboza <[email protected]>
For the VPD Block Limits emulation with SCSI passthrough, we'll issue an Inquiry request with EVPD set to retrieve the available VPD pages of the device. This would be done in a way similar of what scsi_generic_read_device_identification
does: create a SCSI command and a reply buffer, fill in the sg_io_hdr_t structure, call blk_ioctl, check if an error occurred, process the response.
This same process is done in other 2 functions, get_device_type and get_stream_blocksize. They differ in the command/reply buffer and post-processing, everything else is almost a copy/paste.
Instead of adding a forth copy/pasted-ish code when adding the passthrough VPD BL emulation, this patch extirpates this repetition of those 3 functions and put it into a new one called scsi_SG_IO_FROM_DEV. Any future code that wants to execute an SG_DXFER_FROM_DEV to the device can use it, avoiding filling sg_io_hdr_t again and et cetera.
Message-Id: <[email protected]>
--- hw/scsi/scsi-disk.c | 18 +++------------ hw/scsi/scsi-generic.c | 61 +++++++++++++++++++++++++------------------------- include/hw/scsi/scsi.h | 2 ++ 3 files changed, 36 insertions(+), 45 deletions(-)
hw/scsi/scsi-disk.c +3 -15
@@ -2578,8 +2578,6 @@ static int get_device_type(SCSIDiskState *s) {uint8_t cmd[16 ];uint8_t buf[36 ]; -uint8_t sensebuf[8 ]; -sg_io_hdr_t io_header;int ret;memset (cmd,0 ,sizeof (cmd));
@@ -2587,19 +2585,9 @@ static int get_device_type(SCSIDiskState *s) cmd[0 ] =INQUIRY ; cmd[4 ] =sizeof (buf); -memset (&io_header,0 ,sizeof (io_header)); - io_header.interface_id ='S' ; - io_header.dxfer_direction =SG_DXFER_FROM_DEV ; - io_header.dxfer_len =sizeof (buf); - io_header.dxferp = buf; - io_header.cmdp = cmd; - io_header.cmd_len =sizeof (cmd); - io_header.mx_sb_len =sizeof (sensebuf); - io_header.sbp = sensebuf; - io_header.timeout =6000 ;/* XXX */ - - ret =blk_ioctl (s->qdev.conf.blk,SG_IO , &io_header); -if (ret <0 || io_header.driver_status || io_header.host_status) { + ret =scsi_SG_IO_FROM_DEV (s->qdev.conf.blk, cmd,sizeof (cmd), + buf,sizeof (buf)); +if (ret <0 ) {return -1 ; } s->qdev.type = buf[0 ];
hw/scsi/scsi-generic.c +31 -30
95 lines not on this page · raw message
include/hw/scsi/scsi.h +2 -0
@@ -187,6 +187,8 @@ void scsi_device_unit_attention_reported(SCSIDevice *dev);void scsi_generic_read_device_identification (SCSIDevice *dev);int scsi_device_get_sense (SCSIDevice *dev,uint8_t *buf,int len,bool fixed);int scsi_disk_emulate_vpd_page (SCSIRequest *req,uint8_t *outbuf); +int scsi_SG_IO_FROM_DEV (BlockBackend *blk,uint8_t *cmd,uint8_t cmd_size, +uint8_t *buf,uint8_t buf_size);SCSIDevice *scsi_device_find (SCSIBus *bus,int channel,int target,int lun);/* scsi-generic.c. */
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 60/60] tests/boot-serial: Do not delete the output file in case of errors
In reply to Paolo BonziniFrom: Thomas Huth <[email protected]>
Peter reported that the boot-serial tester sometimes runs into timeouts with SPARC guests. It's currently completely unclear whether this is due to too much load on the host machine (so that the guest really just ran too slow), or whether there is something wrong with the guest's firmware boot. For further debugging, we need the serial output of the guest in case of errors, so instead of unlinking the file immediately, this is now only done in case of success. In case of error, print the name of the file with the serial output via g_error() (which then also calls abort() internally to mark the test as failed).
Message-Id: <[email protected]>
--- tests/boot-serial-test.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
tests/boot-serial-test.c +9 -8
@@ -111,9 +111,8 @@ static testdef_t tests[] = { { NULL } }; -static void check_guest_output (const testdef_t *test,int fd) +static bool check_guest_output (const testdef_t *test,int fd) { -bool output_ok = false;int i, nbr =0 , pos =0 , ccnt;char ch;
@@ -125,8 +124,7 @@ static void check_guest_output(const testdef_t *test, int fd) pos +=1 ;if (test->expect[pos] =='\0' ) {/* We've reached the end of the expected string! */ - output_ok = true; - goto done; +return true; } }else { pos =0 ;
@@ -136,8 +134,7 @@ static void check_guest_output(const testdef_t *test, int fd)g_usleep (10000 ); } -done: -g_assert (output_ok); +return false; }static void test_machine (const void *data)
@@ -180,12 +177,16 @@ static void test_machine(const void *data)"-no-shutdown -serial chardev:serial0 %s" , codeparam, code ? codetmp :"" , test->machine, serialtmp, test->extra); -unlink (serialtmp);if (code) {unlink (codetmp); } -check_guest_output (test, ser_fd); +if (!check_guest_output (test, ser_fd)) { +g_error ("Failed to find expected string. Please check '%s'" , + serialtmp); + } +unlink (serialtmp); +qtest_quit (global_qtest);close (ser_fd);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 57/60] hw/scsi: cleanups before VPD BL emulation
In reply to Paolo BonziniFrom: Daniel Henrique Barboza <[email protected]>
To add support for the emulation of Block Limits VPD page for passthrough devices, a few adjustments in the current code base is required to avoid repetition and improve clarity.
In scsi-generic.c, detach the Inquiry handling from scsi_read_complete and put it into a new function called scsi_handle_inquiry_reply. This change aims to avoid cluttering of scsi_read_complete when we more logic in the Inquiry response handling is added in the next patches, centralizing the changes in the new function.
In scsi-disk.c, take the build of all emulated VPD pages from scsi_disk_emulate_inquiry and make it available to other files into a non-static function called scsi_disk_emulate_vpd_page. Making it public will allow the future VPD BL emulation code for passthrough devices to use it from scsi-generic.c, avoiding copy/pasting this code solely for that purpose. It also has the advantage of providing emulation of all VPD pages in case we need to emulate other pages in other scenarios. As a bonus, scsi_disk_emulate_inquiry got tidier.
Message-Id: <[email protected]>
--- hw/scsi/scsi-disk.c | 407 +++++++++++++++++++++++++------------------------ hw/scsi/scsi-generic.c | 71 +++++---- include/hw/scsi/scsi.h | 1 + 3 files changed, 249 insertions(+), 230 deletions(-)
hw/scsi/scsi-disk.c +210 -197
@@ -585,219 +585,228 @@ static uint8_t *scsi_get_buf(SCSIRequest *req)return (uint8_t *)r->iov.iov_base; } -static int scsi_disk_emulate_inquiry (SCSIRequest *req,uint8_t *outbuf) +int scsi_disk_emulate_vpd_page (SCSIRequest *req,uint8_t *outbuf) {SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, req->dev); -int buflen =0 ; -int start; - -if (req->cmd.buf[1 ] &0x1 ) { -/* Vital product data */ -uint8_t page_code = req->cmd.buf[2 ]; - - outbuf[buflen++] = s->qdev.type &0x1f ; - outbuf[buflen++] = page_code ;// this page - outbuf[buflen++] =0x00 ; - outbuf[buflen++] =0x00 ; - start = buflen; - -switch (page_code) { -case 0x00 :/* Supported page codes, mandatory */ - { -DPRINTF ("Inquiry EVPD[Supported pages] " -"buffer size %zd\n" , req->cmd.xfer); - outbuf[buflen++] =0x00 ;// list of supported pages (this page) -if (s->serial) { - outbuf[buflen++] =0x80 ;// unit serial number - } - outbuf[buflen++] =0x83 ;// device identification -if (s->qdev.type ==TYPE_DISK ) { - outbuf[buflen++] =0xb0 ;// block limits - outbuf[buflen++] =0xb1 ;/* block device characteristics */ - outbuf[buflen++] =0xb2 ;// thin provisioning - } -break ; - } -case 0x80 :/* Device serial number, optional */ - { -int l; +uint8_t page_code = req->cmd.buf[2 ]; +int start, buflen =0 ; -if (!s->serial) { -DPRINTF ("Inquiry (EVPD[Serial number] not supported\n" ); -return -1 ; - } + outbuf[buflen++] = s->qdev.type &0x1f ; + outbuf[buflen++] = page_code; + outbuf[buflen++] =0x00 ; + outbuf[buflen++] =0x00 ; + start = buflen; - l =strlen (s->serial); -if (l >36 ) { - l =36 ; - } +switch (page_code) { +case 0x00 :/* Supported page codes, mandatory */ + { +DPRINTF ("Inquiry EVPD[Supported pages] " +"buffer size %zd\n" , req->cmd.xfer); + outbuf[buflen++] =0x00 ;/* list of supported pages (this page) */ +if (s->serial) { + outbuf[buflen++] =0x80 ;/* unit serial number */ + } + outbuf[buflen++] =0x83 ;/* device identification */ +if (s->qdev.type ==TYPE_DISK ) { + outbuf[buflen++] =0xb0 ;/* block limits */ + outbuf[buflen++] =0xb1 ;/* block device characteristics */ + outbuf[buflen++] =0xb2 ;/* thin provisioning */ + } +break ; + } +case 0x80 :/* Device serial number, optional */ + { +int l; -DPRINTF ("Inquiry EVPD[Serial number] " -"buffer size %zd\n" , req->cmd.xfer); -memcpy (outbuf+buflen, s->serial, l); - buflen += l; -break ; +if (!s->serial) { +DPRINTF ("Inquiry (EVPD[Serial number] not supported\n" ); +return -1 ; } -case 0x83 :/* Device identification page, mandatory */ - { -const char *str = s->serial ?:blk_name (s->qdev.conf.blk); -int max_len = s->serial ?20 :255 -8 ; -int id_len =strlen (str); + l =strlen (s->serial); +if (l >36 ) { + l =36 ; + } -if (id_len > max_len) { - id_len = max_len; - } -DPRINTF ("Inquiry EVPD[Device identification] " -"buffer size %zd\n" , req->cmd.xfer); - - outbuf[buflen++] =0x2 ;// ASCII - outbuf[buflen++] =0 ;// not officially assigned - outbuf[buflen++] =0 ;// reserved - outbuf[buflen++] = id_len;// length of data following -memcpy (outbuf+buflen, str, id_len); - buflen += id_len; - -if (s->qdev.wwn) { - outbuf[buflen++] =0x1 ;// Binary - outbuf[buflen++] =0x3 ;// NAA - outbuf[buflen++] =0 ;// reserved - outbuf[buflen++] =8 ; -stq_be_p (&outbuf[buflen], s->qdev.wwn); - buflen +=8 ; - } +DPRINTF ("Inquiry EVPD[Serial number] " +"buffer size %zd\n" , req->cmd.xfer); +memcpy (outbuf + buflen, s->serial, l); + buflen += l; +break ; + } -if (s->qdev.port_wwn) { - outbuf[buflen++] =0x61 ;// SAS / Binary - outbuf[buflen++] =0x93 ;// PIV / Target port / NAA - outbuf[buflen++] =0 ;// reserved - outbuf[buflen++] =8 ; -stq_be_p (&outbuf[buflen], s->qdev.port_wwn); - buflen +=8 ; - } +case 0x83 :/* Device identification page, mandatory */ + { +const char *str = s->serial ?:blk_name (s->qdev.conf.blk); +int max_len = s->serial ?20 :255 -8 ; +int id_len =strlen (str); -if (s->port_index) { - outbuf[buflen++] =0x61 ;// SAS / Binary - outbuf[buflen++] =0x94 ;// PIV / Target port / relative target port - outbuf[buflen++] =0 ;// reserved - outbuf[buflen++] =4 ; -stw_be_p (&outbuf[buflen +2 ], s->port_index); - buflen +=4 ; - } -break ; +if (id_len > max_len) { + id_len = max_len; } -case 0xb0 :/* block limits */ - { -unsigned int unmap_sectors = - s->qdev.conf.discard_granularity / s->qdev.blocksize; -unsigned int min_io_size = - s->qdev.conf.min_io_size / s->qdev.blocksize; -unsigned int opt_io_size = - s->qdev.conf.opt_io_size / s->qdev.blocksize; -unsigned int max_unmap_sectors = - s->max_unmap_size / s->qdev.blocksize; -unsigned int max_io_sectors = - s->max_io_size / s->qdev.blocksize; - -if (s->qdev.type ==TYPE_ROM ) { -DPRINTF ("Inquiry (EVPD[%02X] not supported for CDROM\n" , - page_code); -return -1 ; - } -if (s->qdev.type ==TYPE_DISK ) { -int max_transfer_blk =blk_get_max_transfer (s->qdev.conf.blk); -int max_io_sectors_blk = - max_transfer_blk / s->qdev.blocksize; - - max_io_sectors = -MIN_NON_ZERO (max_io_sectors_blk, max_io_sectors); - -/* min_io_size and opt_io_size can't be greater than -* max_io_sectors */ -if (min_io_size) { - min_io_size =MIN (min_io_size, max_io_sectors); - } -if (opt_io_size) { - opt_io_size =MIN (opt_io_size, max_io_sectors); - } - } -/* required VPD size with unmap support */ - buflen =0x40 ; -memset (outbuf +4 ,0 , buflen -4 ); - - outbuf[4 ] =0x1 ;/* wsnz */ - -/* optimal transfer length granularity */ - outbuf[6 ] = (min_io_size >>8 ) &0xff ; - outbuf[7 ] = min_io_size &0xff ; - -/* maximum transfer length */ - outbuf[8 ] = (max_io_sectors >>24 ) &0xff ; - outbuf[9 ] = (max_io_sectors >>16 ) &0xff ; - outbuf[10 ] = (max_io_sectors >>8 ) &0xff ; - outbuf[11 ] = max_io_sectors &0xff ; - -/* optimal transfer length */ - outbuf[12 ] = (opt_io_size >>24 ) &0xff ; - outbuf[13 ] = (opt_io_size >>16 ) &0xff ; - outbuf[14 ] = (opt_io_size >>8 ) &0xff ; - outbuf[15 ] = opt_io_size &0xff ; - -/* max unmap LBA count, default is 1GB */ - outbuf[20 ] = (max_unmap_sectors >>24 ) &0xff ; - outbuf[21 ] = (max_unmap_sectors >>16 ) &0xff ; - outbuf[22 ] = (max_unmap_sectors >>8 ) &0xff ; - outbuf[23 ] = max_unmap_sectors &0xff ; - -/* max unmap descriptors, 255 fit in 4 kb with an 8-byte header. */ - outbuf[24 ] =0 ; - outbuf[25 ] =0 ; - outbuf[26 ] =0 ; - outbuf[27 ] =255 ; - -/* optimal unmap granularity */ - outbuf[28 ] = (unmap_sectors >>24 ) &0xff ; - outbuf[29 ] = (unmap_sectors >>16 ) &0xff ; - outbuf[30 ] = (unmap_sectors >>8 ) &0xff ; - outbuf[31 ] = unmap_sectors &0xff ; - -/* max write same size */ - outbuf[36 ] =0 ; - outbuf[37 ] =0 ; - outbuf[38 ] =0 ; - outbuf[39 ] =0 ; - - outbuf[40 ] = (max_io_sectors >>24 ) &0xff ; - outbuf[41 ] = (max_io_sectors >>16 ) &0xff ; - outbuf[42 ] = (max_io_sectors >>8 ) &0xff ; - outbuf[43 ] = max_io_sectors &0xff ; -break ; +DPRINTF ("Inquiry EVPD[Device identification] " +"buffer size %zd\n" , req->cmd.xfer); + + outbuf[buflen++] =0x2 ;/* ASCII */ + outbuf[buflen++] =0 ;/* not officially assigned */ + outbuf[buflen++] =0 ;/* reserved */ + outbuf[buflen++] = id_len;/* length of data following */ +memcpy (outbuf + buflen, str, id_len); + buflen += id_len; + +if (s->qdev.wwn) { + outbuf[buflen++] =0x1 ;/* Binary */ + outbuf[buflen++] =0x3 ;/* NAA */ + outbuf[buflen++] =0 ;/* reserved */ + outbuf[buflen++] =8 ; +stq_be_p (&outbuf[buflen], s->qdev.wwn); + buflen +=8 ; } -case 0xb1 :/* block device characteristics */ - { - buflen =8 ; - outbuf[4 ] = (s->rotation_rate >>8 ) &0xff ; - outbuf[5 ] = s->rotation_rate &0xff ; - outbuf[6 ] =0 ; - outbuf[7 ] =0 ; -break ; + +if (s->qdev.port_wwn) { + outbuf[buflen++] =0x61 ;/* SAS / Binary */ + outbuf[buflen++] =0x93 ;/* PIV / Target port / NAA */ + outbuf[buflen++] =0 ;/* reserved */ + outbuf[buflen++] =8 ; +stq_be_p (&outbuf[buflen], s->qdev.port_wwn); + buflen +=8 ; } -case 0xb2 :/* thin provisioning */ - { - buflen =8 ; - outbuf[4 ] =0 ; - outbuf[5 ] =0xe0 ;/* unmap & write_same 10/16 all supported */ - outbuf[6 ] = s->qdev.conf.discard_granularity ?2 :1 ; - outbuf[7 ] =0 ; -break ; + +if (s->port_index) { + outbuf[buflen++] =0x61 ;/* SAS / Binary */ + +/* PIV/Target port/relative target port */ + outbuf[buflen++] =0x94 ; + + outbuf[buflen++] =0 ;/* reserved */ + outbuf[buflen++] =4 ; +stw_be_p (&outbuf[buflen +2 ], s->port_index); + buflen +=4 ; } -default : +break ; + } +case 0xb0 :/* block limits */ + { +unsigned int unmap_sectors = + s->qdev.conf.discard_granularity / s->qdev.blocksize; +unsigned int min_io_size = + s->qdev.conf.min_io_size / s->qdev.blocksize; +unsigned int opt_io_size = + s->qdev.conf.opt_io_size / s->qdev.blocksize; +unsigned int max_unmap_sectors = + s->max_unmap_size / s->qdev.blocksize; +unsigned int max_io_sectors = + s->max_io_size / s->qdev.blocksize; + +if (s->qdev.type ==TYPE_ROM ) { +DPRINTF ("Inquiry (EVPD[%02X] not supported for CDROM\n" , + page_code);return -1 ; } -/* done with EVPD */ -assert (buflen - start <=255 ); - outbuf[start -1 ] = buflen - start; -return buflen; +if (s->qdev.type ==TYPE_DISK ) { +int max_transfer_blk =blk_get_max_transfer (s->qdev.conf.blk); +int max_io_sectors_blk = + max_transfer_blk / s->qdev.blocksize; + + max_io_sectors = +MIN_NON_ZERO (max_io_sectors_blk, max_io_sectors); + +/* min_io_size and opt_io_size can't be greater than +* max_io_sectors */ +if (min_io_size) { + min_io_size =MIN (min_io_size, max_io_sectors); + } +if (opt_io_size) { + opt_io_size =MIN (opt_io_size, max_io_sectors); + } + } +/* required VPD size with unmap support */ + buflen =0x40 ; +memset (outbuf +4 ,0 , buflen -4 ); + + outbuf[4 ] =0x1 ;/* wsnz */ + +/* optimal transfer length granularity */ + outbuf[6 ] = (min_io_size >>8 ) &0xff ; + outbuf[7 ] = min_io_size &0xff ; + +/* maximum transfer length */ + outbuf[8 ] = (max_io_sectors >>24 ) &0xff ; + outbuf[9 ] = (max_io_sectors >>16 ) &0xff ; + outbuf[10 ] = (max_io_sectors >>8 ) &0xff ; + outbuf[11 ] = max_io_sectors &0xff ; + +/* optimal transfer length */ + outbuf[12 ] = (opt_io_size >>24 ) &0xff ; + outbuf[13 ] = (opt_io_size >>16 ) &0xff ; + outbuf[14 ] = (opt_io_size >>8 ) &0xff ; + outbuf[15 ] = opt_io_size &0xff ; + +/* max unmap LBA count, default is 1GB */ + outbuf[20 ] = (max_unmap_sectors >>24 ) &0xff ; + outbuf[21 ] = (max_unmap_sectors >>16 ) &0xff ; + outbuf[22 ] = (max_unmap_sectors >>8 ) &0xff ; + outbuf[23 ] = max_unmap_sectors &0xff ; + +/* max unmap descriptors, 255 fit in 4 kb with an 8-byte header */ + outbuf[24 ] =0 ; + outbuf[25 ] =0 ; + outbuf[26 ] =0 ; + outbuf[27 ] =255 ; + +/* optimal unmap granularity */ + outbuf[28 ] = (unmap_sectors >>24 ) &0xff ; + outbuf[29 ] = (unmap_sectors >>16 ) &0xff ; + outbuf[30 ] = (unmap_sectors >>8 ) &0xff ; + outbuf[31 ] = unmap_sectors &0xff ; + +/* max write same size */ + outbuf[36 ] =0 ; + outbuf[37 ] =0 ; + outbuf[38 ] =0 ; + outbuf[39 ] =0 ; + + outbuf[40 ] = (max_io_sectors >>24 ) &0xff ; + outbuf[41 ] = (max_io_sectors >>16 ) &0xff ; + outbuf[42 ] = (max_io_sectors >>8 ) &0xff ; + outbuf[43 ] = max_io_sectors &0xff ; +break ; + } +case 0xb1 :/* block device characteristics */ + { + buflen =8 ; + outbuf[4 ] = (s->rotation_rate >>8 ) &0xff ; + outbuf[5 ] = s->rotation_rate &0xff ; + outbuf[6 ] =0 ; + outbuf[7 ] =0 ; +break ; + } +case 0xb2 :/* thin provisioning */ + { + buflen =8 ; + outbuf[4 ] =0 ; + outbuf[5 ] =0xe0 ;/* unmap & write_same 10/16 all supported */ + outbuf[6 ] = s->qdev.conf.discard_granularity ?2 :1 ; + outbuf[7 ] =0 ; +break ; + } +default : +return -1 ; + } +/* done with EVPD */ +assert (buflen - start <=255 ); + outbuf[start -1 ] = buflen - start; +return buflen; +} + +static int scsi_disk_emulate_inquiry (SCSIRequest *req,uint8_t *outbuf) +{ +SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, req->dev); +int buflen =0 ; + +if (req->cmd.buf[1 ] &0x1 ) { +/* Vital product data */ +return scsi_disk_emulate_vpd_page (req, outbuf); }/* Standard INQUIRY data */
@@ -3039,6 +3048,10 @@ static Property scsi_block_properties[] = {DEFINE_PROP_DRIVE ("drive" , SCSIDiskState, qdev.conf.blk),DEFINE_PROP_BOOL ("share-rw" , SCSIDiskState, qdev.conf.share_rw, false),DEFINE_PROP_UINT16 ("rotation_rate" , SCSIDiskState, rotation_rate,0 ), +DEFINE_PROP_UINT64 ("max_unmap_size" , SCSIDiskState, max_unmap_size, +DEFAULT_MAX_UNMAP_SIZE ), +DEFINE_PROP_UINT64 ("max_io_size" , SCSIDiskState, max_io_size, +DEFAULT_MAX_IO_SIZE ),DEFINE_PROP_INT32 ("scsi_version" , SCSIDiskState, qdev.default_scsi_version,-1 ), DEFINE_PROP_END_OF_LIST(),
hw/scsi/scsi-generic.c +38 -33
83 lines not on this page · raw message
include/hw/scsi/scsi.h +1 -0
@@ -186,6 +186,7 @@ void scsi_device_report_change(SCSIDevice *dev, SCSISense sense);void scsi_device_unit_attention_reported (SCSIDevice *dev);void scsi_generic_read_device_identification (SCSIDevice *dev);int scsi_device_get_sense (SCSIDevice *dev,uint8_t *buf,int len,bool fixed); +int scsi_disk_emulate_vpd_page (SCSIRequest *req,uint8_t *outbuf);SCSIDevice *scsi_device_find (SCSIBus *bus,int channel,int target,int lun);/* scsi-generic.c. */
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 59/60] hw/scsi: add VPD Block Limits emulation
In reply to Paolo BonziniFrom: Daniel Henrique Barboza <[email protected]>
The VPD Block Limits Inquiry page is optional, allowing SCSI devices to not implement it. This is the case for devices like the MegaRAID SAS 9361-8i and Microsemi PM8069.
In case of SCSI passthrough, the response of this request is used by the QEMU SCSI layer to set the max_io_sectors that the guest device will support, based on the value of the max_sectors_kb that the device has set in the host at that time. Without this response, the guest kernel is free to assume any value of max_io_sectors for the SCSI device. If this value is greater than the value from the host, SCSI Sense errors will occur because the guest will send read/write requests that are larger than the underlying host device is configured to support. An example of this behavior can be seen in [1].
A workaround is to set the max_sectors_kb host value back in the guest kernel (a process that can be automated using rc.local startup scripts and the like), but this has several drawbacks:
- it can be troublesome if the guest has many passthrough devices that needs this tuning;
- if a change in max_sectors_kb is made in the host side, manual change in the guests will also be required;
- during an OS install it is difficult, and sometimes not possible, to go to a terminal and change the max_sectors_kb prior to the installation. This means that the disk can't be used during the install process. The easiest alternative here is to roll back to scsi-hd, install the guest and then go back to SCSI passthrough when the installation is done and max_sectors_kb can be set.
An easier way would be to QEMU handle the absence of the Block Limits VPD device response, setting max_io_sectors accordingly and allowing the guest to use the device without the hassle.
This patch adds emulation of the Block Limits VPD response for SCSI passthrough devices of type TYPE_DISK that doesn't support it. The following changes were made:
- scsi_handle_inquiry_reply will now check the available VPD pages from the Inquiry EVPD reply. In case the device does not
- a new function called scsi_generic_set_vpd_bl_emulation, that is called during device realize, was created to set a new flag 'needs_vpd_bl_emulation' of the device. This function retrieves the Inquiry EVPD response of the device to check for VPD BL support.
- scsi_handle_inquiry_reply will now check the available VPD pages from the Inquiry EVPD reply in case the device needs VPD BL emulation, adding the Block Limits page (0xb0) to the list. This will make the guest kernel aware of the support that we're now providing by emulation.
- a new function scsi_emulate_block_limits creates the emulated Block Limits response. This function is called inside scsi_read_complete in case the device requires Block Limits VPD emulation and we detected a SCSI Sense error in the VPD Block Limits reply that was issued from the guest kernel to the device. This error is
expected: we're reporting support from our side, but the device isn't aware of it.
With this patch, the guest now queries the Block Limits page during the device configuration because it is being advertised in the Supported Pages response. It will either receive the Block Limits page from the hardware, if it supports it, or will receive an emulated response from QEMU. At any rate, the guest now has the information to set the max_sectors_kb parameter accordingly, sparing the user of SCSI sense errors that would happen without the emulated response and in the absence of Block Limits support from the hardware.
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1566195
Message-Id: <[email protected]>
--- hw/scsi/scsi-disk.c | 2 +- hw/scsi/scsi-generic.c | 132 +++++++++++++++++++++++++++++++++++++++++++++---- include/hw/scsi/scsi.h | 3 +- 3 files changed, 125 insertions(+), 12 deletions(-)
hw/scsi/scsi-disk.c +1 -1
@@ -2645,7 +2645,7 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp) s->features |= (1 <<SCSI_DISK_F_NO_REMOVABLE_DEVOPS );scsi_realize (&s->qdev, errp); -scsi_generic_read_device_identification (&s->qdev); +scsi_generic_read_device_inquiry (&s->qdev); } typedef struct SCSIBlockReq {
hw/scsi/scsi-generic.c +122 -10
182 lines not on this page · raw message
include/hw/scsi/scsi.h +2 -1
@@ -87,6 +87,7 @@ struct SCSIDeviceuint64_t port_wwn;int scsi_version;int default_scsi_version; +bool needs_vpd_bl_emulation; };extern const VMStateDescription vmstate_scsi_device;
@@ -184,7 +185,7 @@ void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense);void scsi_device_set_ua (SCSIDevice *sdev,SCSISense sense);void scsi_device_report_change (SCSIDevice *dev,SCSISense sense);void scsi_device_unit_attention_reported (SCSIDevice *dev); -void scsi_generic_read_device_identification (SCSIDevice *dev); +void scsi_generic_read_device_inquiry (SCSIDevice *dev);int scsi_device_get_sense (SCSIDevice *dev,uint8_t *buf,int len,bool fixed);int scsi_disk_emulate_vpd_page (SCSIRequest *req,uint8_t *outbuf); int scsi_SG_IO_FROM_DEV(BlockBackend *blk, uint8_t *cmd, uint8_t cmd_size,
Signature · 1 line
1.8.3.1
Quoted 9 lines · Paolo Bonzini
The following changes since commit
4a83bf2f339d4b63ecd5ef48b9816c3b7ee24553:Merge remote-tracking branch 'remotes/juanquintela/tags/migration/20180627' into staging (2018-06-28 15:31:42 +0100)
are available in the git repository at:
git://github.com/bonzini/qemu.gittags/for-upstream
Quoted 8 lines
for you to fetch changes up to
4cd00cd65e8f3d6301426c1f223f676935b3e9b8:tests/boot-serial: Do not delete the output file in case of errors (2018-06-28 19:05:39 +0200)
A separate pull request will come with Philippe's IEC unit series. This one is already big enough!
----------------------------------------------------------------
Hi; this fails to link the i386 linux-user binaries (x86-64 Linux host, debug build):
LINK i386-linux-user/qemu-i386target/i386/cpu.o: In function `x86_cpu_realizefn':/home/petmay01/linaro/qemu-for-merges/target/i386/cpu.c:4814:
undefined reference to `enable_cpu_pm'
because enable_cpu_pm is defined in vl.c but used in code in target/i386 which isn't softmmu-specific.
thanks
-- PMM
Quoted 10 lines · Peter Maydell
Hi; this fails to link the i386 linux-user binaries (x86-64 Linux host, debug build):
LINK i386-linux-user/qemu-i386
target/i386/cpu.o: In function `x86_cpu_realizefn':/home/petmay01/linaro/qemu-for-merges/target/i386/cpu.c:4814:
undefined reference to `enable_cpu_pm'because
enable_cpu_pmis defined invl.cbut used in code in target/i386 which isn't softmmu-specific.
That breaks depending on the optimization level. I'll fix that and resend.
Paolo