various fixes for rc2 (semihosting, tcg, docker, tests/vm)
The following changes since commit 194f8ca825854abef3aceca1ed7eb5a53b08751f:
Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20200725' into staging (2020-07-26 17:17:58 +0100)
are available in the Git repository at:
https://github.com/stsquad/qemu.git tags/pull-fixes-for-rc2-270720-1
for you to fetch changes up to 4a70232b1d26b0d73e1bce60b2c3bdb7e4279d16:
tests/vm: add shutdown timeout in basevm.py (2020-07-27 09:41:58 +0100)
----------------------------------------------------------------
Various fixes for rc2:
- get shippable working again
- semihosting bug fixes
- tweak tb-size handling for low memory machines
- i386 compound literal float fix
- linux-user MAP_FIXED->MAP_NOREPLACE on fallback
- docker binfmt_misc fixes
- linux-user nanosleep fix
- tests/vm drain console fixes
----------------------------------------------------------------
Alex Bennée (8):
shippable: add one more qemu to registry url
util: add qemu_get_host_physmem utility function util/oslib-win32: add qemu_get_host_physmem implementation accel/tcg: better handle memory constrained systems
linux-user: don't use MAP_FIXED in pgd_find_hole_fallback tests/docker: fix update command due to python3 str/bytes distinction tests/docker: fix binfmt_misc image building tests/docker: add support for DEB_KEYRING
KONRAD Frederic (2):
semihosting: defer connect_chardevs a little more to use serialx
semihosting: don't send the trailing '\0'
Laszlo Ersek (1):
target/i386: floatx80: avoid compound literals in static initializers
Laurent Vivier (2):
linux-user: fix clock_nanosleep()
linux-user, ppc: fix clock_nanosleep() for linux-user-ppc
Robert Foley (3):
python/qemu: Cleanup changes to ConsoleSocket python/qemu: Change ConsoleSocket to optionally drain socket. tests/vm: add shutdown timeout in basevm.py
include/fpu/softfloat.h | 1 + include/qemu/osdep.h | 15 + accel/tcg/translate-all.c | 7 +- hw/semihosting/console.c | 4 +- linux-user/elfload.c | 10 +- linux-user/syscall.c | 15 +- softmmu/vl.c | 5 +- target/i386/fpu_helper.c | 426 +++++++++++++------------- util/oslib-posix.c | 15 + util/oslib-win32.c | 11 + .shippable.yml | 2 +- python/qemu/console_socket.py | 137 +++++---- python/qemu/machine.py | 14 +- python/qemu/pylintrc | 2 +- tests/docker/Makefile.include | 2 +- tests/docker/docker.py | 13 +- tests/docker/dockerfiles/debian-bootstrap.pre | 7 + tests/vm/basevm.py | 15 +- 18 files changed, 390 insertions(+), 311 deletions(-)
Signature · 1 line
2.20.1
[PULL 01/16] shippable: add one more qemu to registry url
The registry url is <project>/<repo>/qemu/<image>
Perhaps we should rationalise that some day but for now.
Message-Id: <[email protected]>
.shippable.yml +1 -1
@@ -27,7 +27,7 @@ env: TARGET_LIST=ppc64-softmmu,ppc64-linux-user,ppc64abi32-linux-user build: pre_ci_boot: - image_name: registry.gitlab.com/qemu-project/qemu/${IMAGE} + image_name: registry.gitlab.com/qemu-project/qemu/qemu/${IMAGE} image_tag: latest pull: true options: "-e HOME=/root"
Signature · 1 line
2.20.1
[PULL 04/16] util: add qemu_get_host_physmem utility function
In reply to Alex BennéeThis will be used in a future patch. For POSIX systems _SC_PHYS_PAGES isn't standardised but at least appears in the man pages for Open/FreeBSD. The result is advisory so any users of it shouldn't just fail if we can't work it out.
The win32 stub currently returns 0 until someone with a Windows system can develop and test a patch.
Message-Id: <[email protected]>
include/qemu/osdep.h +12 -0
@@ -668,4 +668,16 @@ static inline void qemu_reset_optind(void)*/ char *qemu_get_host_name (Error **errp); +/** +* qemu_get_host_physmem: +* +* Operating system agnostic way of querying host memory. +* +* Returns amount of physical memory on the system. This is purely +* advisery and may return 0 if we can't work it out. At the other +* end we saturate to SIZE_MAX if you are lucky enough to have that +* much memory. +*/ +size_t qemu_get_host_physmem (void ); +#endif
util/oslib-posix.c +15 -0
@@ -841,3 +841,18 @@ char *qemu_get_host_name(Error **errp)return g_steal_pointer (&hostname); } + +size_t qemu_get_host_physmem (void ) +{ +#ifdef _SC_PHYS_PAGES +long pages =sysconf (_SC_PHYS_PAGES); +if (pages >0 ) { +if (pages >SIZE_MAX / qemu_real_host_page_size) { +return SIZE_MAX ; + }else { +return pages * qemu_real_host_page_size; + } + } +#endif +return 0 ; +}
util/oslib-win32.c +6 -0
@@ -828,3 +828,9 @@ char *qemu_get_host_name(Error **errp)return g_utf16_to_utf8 (tmp, size,NULL ,NULL ,NULL ); } + +size_t qemu_get_host_physmem (void ) +{ +/* currently unimplemented */ +return 0 ; +}
Signature · 1 line
2.20.1
[PULL 05/16] util/oslib-win32: add qemu_get_host_physmem implementation
In reply to Alex BennéeCompile tested only.
Message-Id: <[email protected]>
util/oslib-win32.c +6 -1
@@ -831,6 +831,11 @@ char *qemu_get_host_name(Error **errp)size_t qemu_get_host_physmem (void ) { -/* currently unimplemented */ +MEMORYSTATUSEX statex; + statex.dwLength =sizeof (statex); + +if (GlobalMemoryStatusEx (&statex)) { +return statex.ullTotalPhys; + }return 0 ; }
Signature · 1 line
2.20.1
[PULL 03/16] semihosting: don't send the trailing '\0'
In reply to Alex BennéeFrom: KONRAD Frederic <[email protected]>
Don't send the trailing 0 from the string.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
hw/semihosting/console.c +3 -1
@@ -52,7 +52,9 @@ static GString *copy_user_string(CPUArchState *env, target_ulong addr) do { if (cpu_memory_rw_debug(cpu, addr++, &c, 1, 0) == 0) { - s = g_string_append_c(s, c); + if (c) { + s = g_string_append_c(s, c); + } } else { qemu_log_mask(LOG_GUEST_ERROR, "%s: passed inaccessible address " TARGET_FMT_lx,
Signature · 1 line
2.20.1
[PULL 02/16] semihosting: defer connect_chardevs a little more to use serialx
In reply to Alex BennéeFrom: KONRAD Frederic <[email protected]>
With that we can just use -semihosting-config chardev=serial0.
[AJB: tweak commit message]
Message-Id: <[email protected]>
Message-Id: <[email protected]>
softmmu/vl.c +3 -2
@@ -4127,8 +4127,6 @@ void qemu_init(int argc, char **argv, char **envp)qemu_opts_foreach (qemu_find_opts ("chardev" ), chardev_init_func,NULL , &error_fatal); -/* now chardevs have been created we may have semihosting to connect */ -qemu_semihosting_connect_chardevs ();#ifdef CONFIG_VIRTFS qemu_opts_foreach(qemu_find_opts("fsdev"),
@@ -4279,6 +4277,9 @@ void qemu_init(int argc, char **argv, char **envp)if (foreach_device_config (DEV_DEBUGCON , debugcon_parse) <0 )exit (1 ); +/* now chardevs have been created we may have semihosting to connect */ +qemu_semihosting_connect_chardevs (); +/* If no default VGA is requested, the default is "none". */ if (default_vga) { vga_model =get_default_vga_model (machine_class);
Signature · 1 line
2.20.1
[PULL 06/16] accel/tcg: better handle memory constrained systems
In reply to Alex BennéeIt turns out there are some 64 bit systems that have relatively low amounts of physical memory available to them (typically CI system). Even with swapping available a 1GB translation buffer that fills up can put the machine under increased memory pressure. Detect these low memory situations and reduce tb_size appropriately.
Message-Id: <[email protected]>
accel/tcg/translate-all.c +6 -1
@@ -976,7 +976,12 @@ static inline size_t size_code_gen_buffer(size_t tb_size) {/* Size the buffer. */ if (tb_size ==0 ) { - tb_size =DEFAULT_CODE_GEN_BUFFER_SIZE ; +size_t phys_mem =qemu_get_host_physmem (); +if (phys_mem ==0 ) { + tb_size =DEFAULT_CODE_GEN_BUFFER_SIZE ; + }else { + tb_size =MIN (DEFAULT_CODE_GEN_BUFFER_SIZE , phys_mem /8 ); + } }if (tb_size <MIN_CODE_GEN_BUFFER_SIZE ) { tb_size =MIN_CODE_GEN_BUFFER_SIZE ;
Signature · 1 line
2.20.1
Re: [PULL 06/16] accel/tcg: better handle memory constrained systems
Quoted 6 lines · Alex Bennée
It turns out there are some 64 bit systems that have relatively low amounts of physical memory available to them (typically CI system). Even with swapping available a 1GB translation buffer that fills up can put the machine under increased memory pressure. Detect these low memory situations and reduce
tb_sizeappropriately.
Quoted 9 lines
Fixes 600e17b2615 ("accel/tcg: increase default code gen buffer size for64 bit")
Signed-off-by Alex Bennée <[email protected]>Reviewed-by Richard Henderson <[email protected]>Reviewed-by Robert Foley <[email protected]>Cc BALATON Zoltan <[email protected]>Cc Christian Ehrhardt <[email protected]>Message-Id: <[email protected]>
I beg your pardon for the late reply, but I was out a week.
I see this is already the pull request and my former feedback was included
- thanks.
Never the less I took the chance to test it in the context that I found and reported the initial bug.
If only to show that I didn't fire&forget this case :-)
We know there is quite some noise/deviation, but I only ran single tests as the problem was easily visible despite the noise. Amount of memory qemu settles on:
Host 32G, Guest 512M
4.2 633M
5.0 1672M
5.0+ Fix 1670M
Host 1.5G, Guest 512M
4.2 692M
5.0 16xxM (OOM)
5.0+ Fix 766M
So we seem to have achieved that small environments no more break (a very small amount of very densely sized systems might still) but at the same time get the bigger cache for any normal/large system.
Quoted 23 lines
accel/tcg/translate-all.c +6
-1@@ -976,7 +976,12 @@ static inline size_t size_code_gen_buffer(size_t tb_size) {/* Size the buffer. */ if (tb_size ==0 ) { - tb_size =DEFAULT_CODE_GEN_BUFFER_SIZE ; +size_t phys_mem =qemu_get_host_physmem (); +if (phys_mem ==0 ) { + tb_size =DEFAULT_CODE_GEN_BUFFER_SIZE ; + }else { + tb_size =MIN (DEFAULT_CODE_GEN_BUFFER_SIZE , phys_mem /8 ); + } }if (tb_size <MIN_CODE_GEN_BUFFER_SIZE ) {tb_size = MIN_CODE_GEN_BUFFER_SIZE;--
2.20.1
Signature · 3 lines
Christian Ehrhardt Staff Engineer, Ubuntu Server Canonical Ltd
[PULL 10/16] tests/docker: fix binfmt_misc image building
In reply to Alex BennéeWhen we updated the arguments for docker.py we missed a bit.
Message-Id: <[email protected]>
tests/docker/Makefile.include +1 -1
@@ -78,7 +78,7 @@ docker-binfmt-image-debian-%: $(DOCKER_FILES_DIR)/debian-bootstrap.docker DEB_ARCH=$(DEB_ARCH) \ DEB_TYPE=$(DEB_TYPE) \ $(if $(DEB_URL),DEB_URL=$(DEB_URL),) \ - $(DOCKER_SCRIPT) build qemu/debian-$* $< \ + $(DOCKER_SCRIPT) build -t qemu/debian-$* -f $< \ $(if $V,,--quiet) $(if $(NOCACHE),--no-cache) \ $(if $(NOUSER),,--add-current-user) \ $(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES)) \
Signature · 1 line
2.20.1
[PULL 08/16] linux-user: don't use MAP_FIXED in pgd_find_hole_fallback
In reply to Alex BennéePlain MAP_FIXED has the undesirable behaviour of splatting exiting maps so we don't actually achieve what we want when looking for gaps. We should be using MAP_FIXED_NOREPLACE. As this isn't always available we need to potentially check the returned address to see if the kernel gave us what we asked for.
Message-Id: <[email protected]>
include/qemu/osdep.h +3 -0
@@ -173,6 +173,9 @@ extern int daemon(int, int);#ifndef MAP_ANONYMOUS #define MAP_ANONYMOUS MAP_ANON#endif +#ifndef MAP_FIXED_NOREPLACE +#define MAP_FIXED_NOREPLACE 0 +#endif #ifndef ENOMEDIUM #define ENOMEDIUM ENODEV#endif
linux-user/elfload.c +6 -4
@@ -2134,12 +2134,15 @@ static uintptr_t pgd_find_hole_fallback(uintptr_t guest_size, uintptr_t brk,/* we have run out of space */ return -1 ; }else { -int flags =MAP_ANONYMOUS |MAP_PRIVATE |MAP_NORESERVE |MAP_FIXED ; +int flags =MAP_ANONYMOUS |MAP_PRIVATE |MAP_NORESERVE | +MAP_FIXED_NOREPLACE ;void * mmap_start =mmap ((void *) align_start, guest_size,PROT_NONE , flags,-1 ,0 );if (mmap_start !=MAP_FAILED ) {munmap ((void *) align_start, guest_size); -return (uintptr_t ) mmap_start + offset; +if (MAP_FIXED_NOREPLACE || mmap_start == (void *) align_start) { +return (uintptr_t ) mmap_start + offset; + } } base += qemu_host_page_size; }
@@ -2307,9 +2310,8 @@ static void pgb_reserved_va(const char *image_name, abi_ulong guest_loaddr,/* Widen the "image" to the entire reserved address space. */ pgb_static (image_name,0 , reserved_va, align); -#ifdef MAP_FIXED_NOREPLACE +/* osdep.h defines this as 0 if it's missing */ flags |=MAP_FIXED_NOREPLACE ; -#endif /* Reserve the memory on the host. */ assert (guest_base !=0 );
Signature · 1 line
2.20.1
Re: [PULL 08/16] linux-user: don't use MAP_FIXED in pgd_find_hole_fallback
Quoted 11 lines · Alex Bennée
Plain
MAP_FIXEDhas the undesirable behaviour of splatting exiting maps so we don't actually achieve what we want when looking for gaps. We should be usingMAP_FIXED_NOREPLACE. As this isn't always available we need to potentially check the returned address to see if the kernel gave us what we asked for.Fixes ad592e37dfc ("linux-user: provide fallback pgd_find_hole for bare chroots")Signed-off-by Alex Bennée <[email protected]>Reviewed-by Richard Henderson <[email protected]>Message-Id: <[email protected]>
Hi; Coverity thinks this conditional expression is suspicious (CID 1431059):
linux-user/elfload.c static uintptr_t pgd_find_hole_fallback(uintptr_t guest_size, uintptr_t brk, · line 2143
Quoted 4 lines
if (mmap_start != MAP_FAILED) { munmap((void *) align_start, guest_size);linux-user/elfload.c +1
-1-return (uintptr_t ) mmap_start + offset; +if (MAP_FIXED_NOREPLACE || mmap_start == (void *) align_start) {
because it's performing a logical OR operation where the left operand is an integer constant that's neither 0 nor 1 (it's 1048576). What was this intended to be?
linux-user/elfload.c static uintptr_t pgd_find_hole_fallback(uintptr_t guest_size, uintptr_t brk, · line 2146
Quoted 3 lines
linux-user/elfload.c +2
-0+return (uintptr_t ) mmap_start + offset; + } }
thanks
-- PMM
Re: [PULL 08/16] linux-user: don't use MAP_FIXED in pgd_find_hole_fallback
Quoted 16 lines · Peter Maydell
Quoted 11 lines · Alex Bennée
Plain
MAP_FIXEDhas the undesirable behaviour of splatting exiting maps so we don't actually achieve what we want when looking for gaps. We should be usingMAP_FIXED_NOREPLACE. As this isn't always available we need to potentially check the returned address to see if the kernel gave us what we asked for.Fixes ad592e37dfc ("linux-user: provide fallback pgd_find_hole for bare chroots")Signed-off-by Alex Bennée <[email protected]>Reviewed-by Richard Henderson <[email protected]>Message-Id: <[email protected]>
Hi; Coverity thinks this conditional expression is suspicious (CID 1431059):
Quoted 8 lines
linux-user/elfload.c static uintptr_t pgd_find_hole_fallback(uintptr_t guest_size, uintptr_t brk, · line 2143
Quoted 4 lines
if (mmap_start != MAP_FAILED) { munmap((void *) align_start, guest_size);linux-user/elfload.c +1
-1-return (uintptr_t ) mmap_start + offset; +if (MAP_FIXED_NOREPLACE || mmap_start == (void *) align_start) {because it's performing a logical OR operation where the left operand is an integer constant that's neither 0 nor 1 (it's 1048576). What was this intended to be?
It's 0 if the header doesn't provide it. If it's !0 we don't need to check the address because it should have been in the correct place.
Quoted 7 lines
linux-user/elfload.c static uintptr_t pgd_find_hole_fallback(uintptr_t guest_size, uintptr_t brk, · line 2146
Quoted 4 lines
linux-user/elfload.c +2
-0+return (uintptr_t ) mmap_start + offset; + } }thanks
-- PMM
Signature · 1 line
Alex Bennée
Re: [PULL 08/16] linux-user: don't use MAP_FIXED in pgd_find_hole_fallback
Quoted 9 lines · Alex Bennée
Quoted 8 lines · Peter Maydell
Hi; Coverity thinks this conditional expression is suspicious (CID 1431059):
Quoted 4 lines
if (mmap_start != MAP_FAILED) { munmap((void *) align_start, guest_size);linux-user/elfload.c +1
-1-return (uintptr_t ) mmap_start + offset; +if (MAP_FIXED_NOREPLACE || mmap_start == (void *) align_start) {
Quoted 6 lines
Quoted 3 lines
because it's performing a logical OR operation where the left operand is an integer constant that's neither 0 nor 1 (it's 1048576). What was this intended to be?
It's 0 if the header doesn't provide it. If it's !0 we don't need to check the address because it should have been in the correct place.
OK. "if (MAP_FIXED_NOREPLACE != 0 || ...)" will probably satisfy Coverity then.
-- PMM
[PULL 11/16] tests/docker: add support for DEB_KEYRING
In reply to Alex BennéeFor installing stuff from sid or ports you may need to manually specify the location of the keyring. You can even import keys into your personal keyring and point it there, e.g.:
gpg --keyserver keyring.debian.org --recv-keys 84C573CD4E1AFD6C
make docker-binfmt-image-debian-sid-hppa DEB_TYPE=sid DEB_ARCH=hppa \
DEB_URL=http://ftp.ports.debian.org/debian-ports/ \
EXECUTABLE=./hppa-linux-user/qemu-hppa V=1 \
DEB_KEYRING=${HOME}/.gnupg/pubring.kbxMessage-Id: <[email protected]>
tests/docker/dockerfiles/debian-bootstrap.pre +7 -0
@@ -79,6 +79,13 @@ else fi fi +# +# Add optional args +# +if [ -n "${DEB_KEYRING}" ]; then + DEBOOTSTRAP="${DEBOOTSTRAP} --keyring=${DEB_KEYRING}" +fi + # # Finally check to see if any qemu's are installed #
Signature · 1 line
2.20.1
[PULL 07/16] target/i386: floatx80: avoid compound literals in static initializers
In reply to Alex BennéeFrom: Laszlo Ersek <[email protected]>
Quoting ISO C99 6.7.8p4, "All the expressions in an initializer for an object that has static storage duration shall be constant expressions or string literals".
The compound literal produced by the make_floatx80() macro is not such a constant expression, per 6.6p7-9. (An implementation may accept it, according to 6.6p10, but is not required to.)
Therefore using "floatx80_zero" and make_floatx80() for initializing "f2xm1_table" and "fpatan_table" is not portable. And gcc-4.8 in RHEL-7.6 actually chokes on them:
Quoted 3 lines
target/i386/fpu_helper.c:871:5: error: initializer element is not constant{ make_floatx80(0xbfff, 0x8000000000000000ULL), ^
We've had the make_floatx80_init() macro for this purpose since commit 3bf7e40ab914 ("softfloat: fix for C99", 2012-03-17), so let's use that macro again.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
include/fpu/softfloat.h +1 -0
@@ -822,6 +822,7 @@ static inline bool floatx80_invalid_encoding(floatx80 a) }#define floatx80_zero make_floatx80(0x0000, 0x0000000000000000LL) +#define floatx80_zero_init make_floatx80_init(0x0000, 0x0000000000000000LL)#define floatx80_one make_floatx80(0x3fff, 0x8000000000000000LL)#define floatx80_ln2 make_floatx80(0x3ffe, 0xb17217f7d1cf79acLL)#define floatx80_pi make_floatx80(0x4000, 0xc90fdaa22168c235LL)
target/i386/fpu_helper.c +213 -213
438 lines not on this page · raw message
Signature · 1 line
2.20.1
[PULL 14/16] python/qemu: Cleanup changes to ConsoleSocket
In reply to Alex BennéeFrom: Robert Foley <[email protected]>
The changes to console_socket.py and machine.py are to cleanup for pylint and flake8.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
python/qemu/console_socket.py +29 -28
@@ -1,12 +1,9 @@ -#!/usr/bin/env python3 -# -# This python module implements a ConsoleSocket object which is -# designed always drain the socket itself, and place -# the bytes into a in memory buffer for later processing. -# -# Optionally a file path can be passed in and we will also -# dump the characters to this file for debug. -# +""" +QEMU Console Socket Module: + +This python module implements a ConsoleSocket object, +which can drain a socket and optionally dump the bytes to file. +""" # Copyright 2020 Linaro # # Authors:
@@ -15,20 +12,27 @@ # This code is licensed under the GPL version 2 or later. See # the COPYING file in the top-level directory. # + import asyncore import socket import threading -import io -import os -import sys from collections import deque import time -import traceback + class ConsoleSocket(asyncore.dispatcher): + """ + ConsoleSocket represents a socket attached to a char device. + Drains the socket and places the bytes into an in memory buffer + for later processing. + + Optionally a file path can be passed in and we will also + dump the characters to this file for debugging purposes. + """ def __init__(self, address, file=None): self._recv_timeout_sec = 300 + self._sleep_time = 0.5 self._buffer = deque() self._asyncore_thread = None self._sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
@@ -70,31 +74,28 @@ class ConsoleSocket(asyncore.dispatcher): def handle_read(self): """process arriving characters into in memory _buffer""" - try: - data = asyncore.dispatcher.recv(self, 1) - # latin1 is needed since there are some chars - # we are receiving that cannot be encoded to utf-8 - # such as 0xe2, 0x80, 0xA6. - string = data.decode("latin1") - except: - print("Exception seen.") - traceback.print_exc() - return + data = asyncore.dispatcher.recv(self, 1) + # latin1 is needed since there are some chars + # we are receiving that cannot be encoded to utf-8 + # such as 0xe2, 0x80, 0xA6. + string = data.decode("latin1") if self._logfile: self._logfile.write("{}".format(string)) self._logfile.flush() for c in string: self._buffer.extend(c) - def recv(self, n=1, sleep_delay_s=0.1): - """Return chars from in memory buffer""" + def recv(self, buffer_size=1): + """Return chars from in memory buffer. + Maintains the same API as socket.socket.recv. + """ start_time = time.time() - while len(self._buffer) < n: - time.sleep(sleep_delay_s) + while len(self._buffer) < buffer_size: + time.sleep(self._sleep_time) elapsed_sec = time.time() - start_time if elapsed_sec > self._recv_timeout_sec: raise socket.timeout - chars = ''.join([self._buffer.popleft() for i in range(n)]) + chars = ''.join([self._buffer.popleft() for i in range(buffer_size)]) # We choose to use latin1 to remain consistent with # handle_read() and give back the same data as the user would # receive if they were reading directly from the
python/qemu/machine.py +4 -3
@@ -27,7 +27,7 @@ import socket import tempfile from typing import Optional, Type from types import TracebackType -from qemu.console_socket import ConsoleSocket +from . import console_socket from . import qmp
@@ -674,8 +674,9 @@ class QEMUMachine: """ if self._console_socket is None: if self._drain_console: - self._console_socket = ConsoleSocket(self._console_address, - file=self._console_log_path) + self._console_socket = console_socket.ConsoleSocket( + self._console_address, + file=self._console_log_path) else: self._console_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
python/qemu/pylintrc +1 -1
@@ -33,7 +33,7 @@ good-names=i, Run, _, fd, - + c, [VARIABLES] [STRING]
Signature · 1 line
2.20.1
[PULL 12/16] linux-user: fix clock_nanosleep()
In reply to Alex BennéeFrom: Laurent Vivier <[email protected]>
If the call is interrupted by a signal handler, it fails with error EINTR and if "remain" is not NULL and "flags" is not TIMER_ABSTIME, it returns the remaining unslept time in "remain".
Update linux-user to not overwrite the "remain" structure if there is no error.
Found with "make check-tcg", linux-test fails on nanosleep test:
TEST linux-test on x86_64.../tests/tcg/multiarch/linux-test.c:242: nanosleep
Message-Id: <[email protected]>
Message-Id: <[email protected]>
linux-user/syscall.c +7 -1
@@ -11831,8 +11831,14 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,target_to_host_timespec (&ts, arg3); ret =get_errno (safe_clock_nanosleep (arg1, arg2, &ts, arg4 ? &ts :NULL )); -if (arg4) +/* +* if the call is interrupted by a signal handler, it fails +* with error -TARGET_EINTR and if arg4 is not NULL and arg2 is not +* TIMER_ABSTIME, it returns the remaining unslept time in arg4. +*/ +if (ret == -TARGET_EINTR && arg4 && arg2 !=TIMER_ABSTIME ) {host_to_target_timespec (arg4, &ts); + }#if defined(TARGET_PPC )/* clock_nanosleep is odd in that it returns positive errno values.
Signature · 1 line
2.20.1
[PULL 09/16] tests/docker: fix update command due to python3 str/bytes distinction
In reply to Alex BennéeDoes this seem convoluted to you? It feels a little complicated to me.
Message-Id: <[email protected]>
tests/docker/docker.py +7 -6
@@ -24,7 +24,7 @@ import tempfile import re import signal from tarfile import TarFile, TarInfo -from io import StringIO +from io import StringIO, BytesIO from shutil import copy, rmtree from pwd import getpwuid from datetime import datetime, timedelta
@@ -541,13 +541,14 @@ class UpdateCommand(SubCommand): # Create a Docker buildfile df = StringIO() - df.write("FROM %s\n" % args.tag) - df.write("ADD . /\n") - df.seek(0) + df.write(u"FROM %s\n" % args.tag) + df.write(u"ADD . /\n") + + df_bytes = BytesIO(bytes(df.getvalue(), "UTF-8")) df_tar = TarInfo(name="Dockerfile") - df_tar.size = len(df.buf) - tmp_tar.addfile(df_tar, fileobj=df) + df_tar.size = df_bytes.getbuffer().nbytes + tmp_tar.addfile(df_tar, fileobj=df_bytes) tmp_tar.close()
Signature · 1 line
2.20.1
[PULL 13/16] linux-user, ppc: fix clock_nanosleep() for linux-user-ppc
In reply to Alex BennéeFrom: Laurent Vivier <[email protected]>
Our safe_clock_nanosleep() returns -1 and updates errno.
We don't need to update the CRF bit in syscall.c because it will be updated in ppc/cpu_loop.c as the return value is negative.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
linux-user/syscall.c +0 -7
@@ -11840,13 +11840,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, host_to_target_timespec(arg4, &ts); } -#if defined(TARGET_PPC ) -/* clock_nanosleep is odd in that it returns positive errno values. -* On PPC, CR0 bit 3 should be set in such a situation. */ -if (ret && ret != -TARGET_ERESTARTSYS ) { - ((CPUPPCState *)cpu_env)->crf[0 ] |=1 ; - } -#endif return ret; }#endif
Signature · 1 line
2.20.1
[PULL 15/16] python/qemu: Change ConsoleSocket to optionally drain socket.
In reply to Alex BennéeFrom: Robert Foley <[email protected]>
The primary purpose of this change is to clean up machine.py's console_socket property to return a single type, a ConsoleSocket.
ConsoleSocket now derives from a socket, which means that in the default case (of not draining), machine.py will see the same behavior as it did prior to ConsoleSocket.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
python/qemu/console_socket.py +55 -37
@@ -13,68 +13,75 @@ which can drain a socket and optionally dump the bytes to file. # the COPYING file in the top-level directory. # -import asyncore import socket import threading from collections import deque import time -class ConsoleSocket(asyncore.dispatcher): +class ConsoleSocket(socket.socket): """ ConsoleSocket represents a socket attached to a char device. - Drains the socket and places the bytes into an in memory buffer - for later processing. + Optionally (if drain==True), drains the socket and places the bytes + into an in memory buffer for later processing. Optionally a file path can be passed in and we will also dump the characters to this file for debugging purposes. """ - def __init__(self, address, file=None): + def __init__(self, address, file=None, drain=False): self._recv_timeout_sec = 300 self._sleep_time = 0.5 self._buffer = deque() - self._asyncore_thread = None - self._sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) - self._sock.connect(address) + socket.socket.__init__(self, socket.AF_UNIX, socket.SOCK_STREAM) + self.connect(address) self._logfile = None if file: self._logfile = open(file, "w") - asyncore.dispatcher.__init__(self, sock=self._sock) self._open = True - self._thread_start() + if drain: + self._drain_thread = self._thread_start() + else: + self._drain_thread = None - def _thread_start(self): - """Kick off a thread to wait on the asyncore.loop""" - if self._asyncore_thread is not None: - return - self._asyncore_thread = threading.Thread(target=asyncore.loop, - kwargs={'timeout':1}) - self._asyncore_thread.daemon = True - self._asyncore_thread.start() + def _drain_fn(self): + """Drains the socket and runs while the socket is open.""" + while self._open: + try: + self._drain_socket() + except socket.timeout: + # The socket is expected to timeout since we set a + # short timeout to allow the thread to exit when + # self._open is set to False. + time.sleep(self._sleep_time) - def handle_close(self): - """redirect close to base class""" - # Call the base class close, but not self.close() since - # handle_close() occurs in the context of the thread which - # self.close() attempts to join. - asyncore.dispatcher.close(self) + def _thread_start(self): + """Kick off a thread to drain the socket.""" + # Configure socket to not block and timeout. + # This allows our drain thread to not block + # on recieve and exit smoothly. + socket.socket.setblocking(self, False) + socket.socket.settimeout(self, 1) + drain_thread = threading.Thread(target=self._drain_fn) + drain_thread.daemon = True + drain_thread.start() + return drain_thread def close(self): """Close the base object and wait for the thread to terminate""" if self._open: self._open = False - asyncore.dispatcher.close(self) - if self._asyncore_thread is not None: - thread, self._asyncore_thread = self._asyncore_thread, None + if self._drain_thread is not None: + thread, self._drain_thread = self._drain_thread, None thread.join() + socket.socket.close(self) if self._logfile: self._logfile.close() self._logfile = None - def handle_read(self): + def _drain_socket(self): """process arriving characters into in memory _buffer""" - data = asyncore.dispatcher.recv(self, 1) + data = socket.socket.recv(self, 1) # latin1 is needed since there are some chars # we are receiving that cannot be encoded to utf-8 # such as 0xe2, 0x80, 0xA6.
@@ -85,27 +92,38 @@ class ConsoleSocket(asyncore.dispatcher): for c in string: self._buffer.extend(c) - def recv(self, buffer_size=1): + def recv(self, bufsize=1): """Return chars from in memory buffer. Maintains the same API as socket.socket.recv. """ + if self._drain_thread is None: + # Not buffering the socket, pass thru to socket. + return socket.socket.recv(self, bufsize) start_time = time.time() - while len(self._buffer) < buffer_size: + while len(self._buffer) < bufsize: time.sleep(self._sleep_time) elapsed_sec = time.time() - start_time if elapsed_sec > self._recv_timeout_sec: raise socket.timeout - chars = ''.join([self._buffer.popleft() for i in range(buffer_size)]) + chars = ''.join([self._buffer.popleft() for i in range(bufsize)]) # We choose to use latin1 to remain consistent with # handle_read() and give back the same data as the user would # receive if they were reading directly from the # socket w/o our intervention. return chars.encode("latin1") - def set_blocking(self): - """Maintain compatibility with socket API""" - pass + def setblocking(self, value): + """When not draining we pass thru to the socket, + since when draining we control socket blocking. + """ + if self._drain_thread is None: + socket.socket.setblocking(self, value) def settimeout(self, seconds): - """Set current timeout on recv""" - self._recv_timeout_sec = seconds + """When not draining we pass thru to the socket, + since when draining we control the timeout. + """ + if seconds is not None: + self._recv_timeout_sec = seconds + if self._drain_thread is None: + socket.socket.settimeout(self, seconds)
python/qemu/machine.py +4 -9
@@ -23,7 +23,6 @@ import os import subprocess import shutil import signal -import socket import tempfile from typing import Optional, Type from types import TracebackType
@@ -673,12 +672,8 @@ class QEMUMachine: Returns a socket connected to the console """ if self._console_socket is None: - if self._drain_console: - self._console_socket = console_socket.ConsoleSocket( - self._console_address, - file=self._console_log_path) - else: - self._console_socket = socket.socket(socket.AF_UNIX, - socket.SOCK_STREAM) - self._console_socket.connect(self._console_address) + self._console_socket = console_socket.ConsoleSocket( + self._console_address, + file=self._console_log_path, + drain=self._drain_console) return self._console_socket
Signature · 1 line
2.20.1
[PULL 16/16] tests/vm: add shutdown timeout in basevm.py
In reply to Alex BennéeFrom: Robert Foley <[email protected]>
We are adding the shutdown timeout to solve an issue we now see where the aarch64 VMs timeout on shutdown under TCG.
There is a new 3 second timeout in machine.py, which we override in basevm.py when shutting down.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
tests/vm/basevm.py +10 -5
@@ -80,6 +80,8 @@ class BaseVM(object): arch = "#arch" # command to halt the guest, can be overridden by subclasses poweroff = "poweroff" + # Time to wait for shutdown to finish. + shutdown_timeout_default = 30 # enable IPv6 networking ipv6 = True # This is the timeout on the wait for console bytes.
@@ -87,7 +89,7 @@ class BaseVM(object): # Scale up some timeouts under TCG. # 4 is arbitrary, but greater than 2, # since we found we need to wait more than twice as long. - tcg_ssh_timeout_multiplier = 4 + tcg_timeout_multiplier = 4 def __init__(self, args, config=None): self._guest = None self._genisoimage = args.genisoimage
@@ -141,9 +143,12 @@ class BaseVM(object): if args.jobs and args.jobs > 1: self._args += ["-smp", "%d" % args.jobs] if kvm_available(self.arch): + self._shutdown_timeout = self.shutdown_timeout_default self._args += ["-enable-kvm"] else: logging.info("KVM not available, not using -enable-kvm") + self._shutdown_timeout = \ + self.shutdown_timeout_default * self.tcg_timeout_multiplier self._data_args = [] if self._config['qemu_args'] != None:
@@ -423,7 +428,7 @@ class BaseVM(object): def wait_ssh(self, wait_root=False, seconds=300, cmd="exit 0"): # Allow more time for VM to boot under TCG. if not kvm_available(self.arch): - seconds *= self.tcg_ssh_timeout_multiplier + seconds *= self.tcg_timeout_multiplier starttime = datetime.datetime.now() endtime = starttime + datetime.timedelta(seconds=seconds) cmd_success = False
@@ -441,14 +446,14 @@ class BaseVM(object): raise Exception("Timeout while waiting for guest ssh") def shutdown(self): - self._guest.shutdown() + self._guest.shutdown(timeout=self._shutdown_timeout) def wait(self): - self._guest.wait() + self._guest.wait(timeout=self._shutdown_timeout) def graceful_shutdown(self): self.ssh_root(self.poweroff) - self._guest.wait() + self._guest.wait(timeout=self._shutdown_timeout) def qmp(self, *args, **kwargs): return self._guest.qmp(*args, **kwargs)
Signature · 1 line
2.20.1
Peter Maydell
AppliedQuoted 16 lines · Alex Bennée
The following changes since commit
194f8ca825854abef3aceca1ed7eb5a53b08751f:Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20200725' into staging (2020-07-26 17:17:58 +0100)
are available in the Git repository at:
https://github.com/stsquad/qemu.git tags/pull-fixes-for-rc2-270720-1
for you to fetch changes up to
4a70232b1d26b0d73e1bce60b2c3bdb7e4279d16:tests/vm: add shutdown timeout in
basevm.py(2020-07-27 09:41:58 +0100)----------------------------------------------------------------
Various fixes for rc2:
Quoted 8 lines
- get shippable working again
- semihosting bug fixes
- tweak tb-size handling for low memory machines
- i386 compound literal float fix
- linux-userMAP_FIXED->MAP_NOREPLACEon fallback
- dockerbinfmt_miscfixes
- linux-user nanosleep fix
- tests/vm drain console fixes
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/5.1
for any user-visible changes.
-- PMM