[PATCH v8 11/11] darwin: remove 64-bit build detection on 32-bit OS

2021-01-22 Thread Joelle van Dyne
A workaround added in early days of 64-bit OSX forced x86_64 if the
host machine had 64-bit support. This creates issues when cross-
compiling for ARM64. Additionally, the user can always use --cpu=* to
manually set the host CPU and therefore this workaround should be
removed.

Reviewed-by: Peter Maydell 
Signed-off-by: Joelle van Dyne 
---
 configure | 11 ---
 1 file changed, 11 deletions(-)

diff --git a/configure b/configure
index 70061e195d..5f23f5b907 100755
--- a/configure
+++ b/configure
@@ -626,13 +626,6 @@ fi
 # the correct CPU with the --cpu option.
 case $targetos in
 Darwin)
-  # on Leopard most of the system is 32-bit, so we have to ask the kernel if 
we can
-  # run 64-bit userspace code.
-  # If the user didn't specify a CPU explicitly and the kernel says this is
-  # 64 bit hw, then assume x86_64. Otherwise fall through to the usual 
detection code.
-  if test -z "$cpu" && test "$(sysctl -n hw.optional.x86_64)" = "1"; then
-cpu="x86_64"
-  fi
   HOST_DSOSUF=".dylib"
   ;;
 SunOS)
@@ -776,10 +769,6 @@ OpenBSD)
 Darwin)
   bsd="yes"
   darwin="yes"
-  if [ "$cpu" = "x86_64" ] ; then
-QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS"
-QEMU_LDFLAGS="-arch x86_64 $QEMU_LDFLAGS"
-  fi
   audio_drv_list="try-coreaudio try-sdl"
   audio_possible_drivers="coreaudio sdl"
   # Disable attempts to use ObjectiveC features in os/object.h since they
-- 
2.28.0




[PATCH v8 10/11] darwin: detect CoreAudio for build

2021-01-22 Thread Joelle van Dyne
On iOS there is no CoreAudio, so we should not assume Darwin always
has it.

Signed-off-by: Joelle van Dyne 
---
 configure | 35 +--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index b8ae4609fd..70061e195d 100755
--- a/configure
+++ b/configure
@@ -319,6 +319,7 @@ fdt="auto"
 netmap="no"
 sdl="auto"
 sdl_image="auto"
+coreaudio="auto"
 virtiofsd="auto"
 virtfs="auto"
 libudev="auto"
@@ -779,7 +780,7 @@ Darwin)
 QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS"
 QEMU_LDFLAGS="-arch x86_64 $QEMU_LDFLAGS"
   fi
-  audio_drv_list="coreaudio try-sdl"
+  audio_drv_list="try-coreaudio try-sdl"
   audio_possible_drivers="coreaudio sdl"
   # Disable attempts to use ObjectiveC features in os/object.h since they
   # won't work when we're compiling with gcc as a C compiler.
@@ -3162,6 +3163,24 @@ EOF
   fi
 fi
 
+##
+# detect CoreAudio
+if test "$coreaudio" != "no" ; then
+  coreaudio_libs="-framework CoreAudio"
+  cat > $TMPC << EOF
+#include 
+int main(void)
+{
+  return (int)AudioGetCurrentHostTime();
+}
+EOF
+  if compile_prog "" "$coreaudio_libs" ; then
+coreaudio=yes
+  else
+coreaudio=no
+  fi
+fi
+
 ##
 # Sound support libraries probe
 
@@ -3218,8 +3237,20 @@ for drv in $audio_drv_list; do
 fi
 ;;
 
-coreaudio)
+coreaudio | try-coreaudio)
+if test "$coreaudio" = "no"; then
+  if test "$drv" = "try-coreaudio"; then
+audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-coreaudio//')
+  else
+error_exit "$drv check failed" \
+"Make sure to have the $drv is available."
+  fi
+else
   coreaudio_libs="-framework CoreAudio"
+  if test "$drv" = "try-coreaudio"; then
+audio_drv_list=$(echo "$audio_drv_list" | sed -e 
's/try-coreaudio/coreaudio/')
+  fi
+fi
 ;;
 
 dsound)
-- 
2.28.0




[PATCH v8 08/11] configure: cross compile should use x86_64 cpu_family

2021-01-22 Thread Joelle van Dyne
Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: Joelle van Dyne 
---
 configure | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index d4588ed892..b8ae4609fd 100755
--- a/configure
+++ b/configure
@@ -6445,9 +6445,12 @@ if test "$cross_compile" = "yes"; then
 echo "system = 'darwin'" >> $cross
 fi
 case "$ARCH" in
-i386|x86_64)
+i386)
 echo "cpu_family = 'x86'" >> $cross
 ;;
+x86_64)
+echo "cpu_family = 'x86_64'" >> $cross
+;;
 ppc64le)
 echo "cpu_family = 'ppc64'" >> $cross
 ;;
-- 
2.28.0




[PATCH v8 09/11] block: check availablity for preadv/pwritev on mac

2021-01-22 Thread Joelle van Dyne
macOS 11/iOS 14 added preadv/pwritev APIs. Due to weak linking, configure
will succeed with CONFIG_PREADV even when targeting a lower OS version.
We therefore need to check at run time if we can actually use these APIs.

Signed-off-by: Joelle van Dyne 
---
 block/file-posix.c | 33 +
 1 file changed, 33 insertions(+)

diff --git a/block/file-posix.c b/block/file-posix.c
index 666d3e7504..6473f84db8 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -1386,17 +1386,50 @@ static int handle_aiocb_flush(void *opaque)
 #ifdef CONFIG_PREADV
 
 static bool preadv_present = true;
+static bool preadv_checked;
 
 static ssize_t
 qemu_preadv(int fd, const struct iovec *iov, int nr_iov, off_t offset)
 {
+#ifdef CONFIG_DARWIN /* preadv introduced in macOS 11 */
+if (unlikely(!preadv_checked)) {
+if (__builtin_available(macOS 11, iOS 14, watchOS 7, tvOS 14, *)) {
+preadv_checked = true;
+} else {
+preadv_present = false;
+return -ENOSYS;
+}
+}
+/* Now we suppress the availability warning since we use the cached check 
*/
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunguarded-availability-new"
+return preadv(fd, iov, nr_iov, offset);
+#pragma clang diagnostic pop
+#else /* CONFIG_DARWIN */
 return preadv(fd, iov, nr_iov, offset);
+#endif
 }
 
 static ssize_t
 qemu_pwritev(int fd, const struct iovec *iov, int nr_iov, off_t offset)
 {
+#ifdef CONFIG_DARWIN /* preadv introduced in macOS 11 */
+if (unlikely(!preadv_checked)) {
+if (__builtin_available(macOS 11, iOS 14, watchOS 7, tvOS 14, *)) {
+preadv_checked = true;
+} else {
+preadv_present = false;
+return -ENOSYS;
+}
+}
+/* Now we suppress the availability warning since we use the cached check 
*/
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunguarded-availability-new"
+return pwritev(fd, iov, nr_iov, offset);
+#pragma clang diagnostic pop
+#else /* CONFIG_DARWIN */
 return pwritev(fd, iov, nr_iov, offset);
+#endif
 }
 
 #else
-- 
2.28.0




[PATCH v8 03/11] configure: check for sys/disk.h

2021-01-22 Thread Joelle van Dyne
Some BSD platforms do not have this header.

Signed-off-by: Joelle van Dyne 
---
 meson.build| 1 +
 block.c| 2 +-
 block/file-posix.c | 2 +-
 3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/meson.build b/meson.build
index 27110075df..6818d97df5 100644
--- a/meson.build
+++ b/meson.build
@@ -1117,6 +1117,7 @@ config_host_data.set('HAVE_PTY_H', cc.has_header('pty.h'))
 config_host_data.set('HAVE_SYS_IOCCOM_H', cc.has_header('sys/ioccom.h'))
 config_host_data.set('HAVE_SYS_KCOV_H', cc.has_header('sys/kcov.h'))
 config_host_data.set('HAVE_HOST_BLOCK_DEVICE', have_host_block_device)
+config_host_data.set('HAVE_SYS_DISK_H', cc.has_header('sys/disk.h'))
 
 ignored = ['CONFIG_QEMU_INTERP_PREFIX'] # actually per-target
 arrays = ['CONFIG_AUDIO_DRIVERS', 'CONFIG_BDRV_RW_WHITELIST', 
'CONFIG_BDRV_RO_WHITELIST']
diff --git a/block.c b/block.c
index 8b9d457546..c4cf391dea 100644
--- a/block.c
+++ b/block.c
@@ -54,7 +54,7 @@
 #ifdef CONFIG_BSD
 #include 
 #include 
-#ifndef __DragonFly__
+#if defined(HAVE_SYS_DISK_H)
 #include 
 #endif
 #endif
diff --git a/block/file-posix.c b/block/file-posix.c
index 11d2021346..666d3e7504 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -2320,7 +2320,7 @@ again:
 }
 if (size == 0)
 #endif
-#if defined(__APPLE__) && defined(__MACH__)
+#if defined(HAVE_SYS_DISK_H) && defined(__APPLE__) && defined(__MACH__)
 {
 uint64_t sectors = 0;
 uint32_t sector_size = 0;
-- 
2.28.0




[PATCH v8 05/11] osdep: build with non-working system() function

2021-01-22 Thread Joelle van Dyne
Build without error on hosts without a working system(). If system()
is called, return -1 with ENOSYS.

Signed-off-by: Joelle van Dyne 
---
 configure| 20 
 include/qemu/osdep.h | 12 
 2 files changed, 32 insertions(+)

diff --git a/configure b/configure
index d72ab22da5..de7487a0c7 100755
--- a/configure
+++ b/configure
@@ -5302,6 +5302,22 @@ but not implemented on your system"
 fi
 fi
 
+##
+# check for system()
+# make sure there is no compile error
+
+have_system_function=no
+cat > $TMPC << EOF
+#include 
+int main(void) {
+return system("");
+}
+EOF
+if compile_prog "" "" ; then
+have_system_function=yes
+fi
+
+
 ##
 # End of CC checks
 # After here, no more $cc or $ld runs
@@ -6200,6 +6216,10 @@ if test "$secret_keyring" = "yes" ; then
   echo "CONFIG_SECRET_KEYRING=y" >> $config_host_mak
 fi
 
+if test "$have_system_function" = "yes" ; then
+  echo "HAVE_SYSTEM_FUNCTION=y" >> $config_host_mak
+fi
+
 echo "ROMS=$roms" >> $config_host_mak
 echo "MAKE=$make" >> $config_host_mak
 echo "PYTHON=$python" >> $config_host_mak
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index a434382c58..5bd1a67769 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -682,4 +682,16 @@ char *qemu_get_host_name(Error **errp);
  */
 size_t qemu_get_host_physmem(void);
 
+/**
+ * Platforms which do not support system() return ENOSYS
+ */
+#ifndef HAVE_SYSTEM_FUNCTION
+#define system platform_does_not_support_system
+static inline int platform_does_not_support_system(const char *command)
+{
+errno = ENOSYS;
+return -1;
+}
+#endif /* !HAVE_SYSTEM_FUNCTION */
+
 #endif
-- 
2.28.0




[PATCH v8 06/11] darwin: remove redundant dependency declaration

2021-01-22 Thread Joelle van Dyne
Meson will find CoreFoundation, IOKit, and Cocoa as needed.

Reviewed-by: Peter Maydell 
Signed-off-by: Joelle van Dyne 
---
 configure | 1 -
 1 file changed, 1 deletion(-)

diff --git a/configure b/configure
index de7487a0c7..0fd3f14c5e 100755
--- a/configure
+++ b/configure
@@ -781,7 +781,6 @@ Darwin)
   fi
   audio_drv_list="coreaudio try-sdl"
   audio_possible_drivers="coreaudio sdl"
-  QEMU_LDFLAGS="-framework CoreFoundation -framework IOKit $QEMU_LDFLAGS"
   # Disable attempts to use ObjectiveC features in os/object.h since they
   # won't work when we're compiling with gcc as a C compiler.
   QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
-- 
2.28.0




[PATCH v8 07/11] darwin: fix cross-compiling for Darwin

2021-01-22 Thread Joelle van Dyne
Add objc to the Meson cross file as well as detection of Darwin.

Reviewed-by: Peter Maydell 
Signed-off-by: Joelle van Dyne 
---
 configure | 4 
 1 file changed, 4 insertions(+)

diff --git a/configure b/configure
index 0fd3f14c5e..d4588ed892 100755
--- a/configure
+++ b/configure
@@ -6422,6 +6422,7 @@ echo "cpp_link_args = [${LDFLAGS:+$(meson_quote 
$LDFLAGS)}]" >> $cross
 echo "[binaries]" >> $cross
 echo "c = [$(meson_quote $cc)]" >> $cross
 test -n "$cxx" && echo "cpp = [$(meson_quote $cxx)]" >> $cross
+test -n "$objcc" && echo "objc = [$(meson_quote $objcc)]" >> $cross
 echo "ar = [$(meson_quote $ar)]" >> $cross
 echo "nm = [$(meson_quote $nm)]" >> $cross
 echo "pkgconfig = [$(meson_quote $pkg_config_exe)]" >> $cross
@@ -6440,6 +6441,9 @@ if test "$cross_compile" = "yes"; then
 if test "$linux" = "yes" ; then
 echo "system = 'linux'" >> $cross
 fi
+if test "$darwin" = "yes" ; then
+echo "system = 'darwin'" >> $cross
+fi
 case "$ARCH" in
 i386|x86_64)
 echo "cpu_family = 'x86'" >> $cross
-- 
2.28.0




[PATCH v8 01/11] block: feature detection for host block support

2021-01-22 Thread Joelle van Dyne
On Darwin (iOS), there are no system level APIs for directly accessing
host block devices. We detect this at configure time.

Signed-off-by: Joelle van Dyne 
---
 meson.build  |  6 +-
 qapi/block-core.json | 10 +++---
 block/file-posix.c   | 33 ++---
 3 files changed, 34 insertions(+), 15 deletions(-)

diff --git a/meson.build b/meson.build
index af2bc89741..27110075df 100644
--- a/meson.build
+++ b/meson.build
@@ -180,7 +180,7 @@ if targetos == 'windows'
   include_directories: 
include_directories('.'))
 elif targetos == 'darwin'
   coref = dependency('appleframeworks', modules: 'CoreFoundation')
-  iokit = dependency('appleframeworks', modules: 'IOKit')
+  iokit = dependency('appleframeworks', modules: 'IOKit', required: false)
 elif targetos == 'sunos'
   socket = [cc.find_library('socket'),
 cc.find_library('nsl'),
@@ -1023,6 +1023,9 @@ if get_option('cfi')
   add_project_link_arguments(cfi_flags, native: false, language: ['c', 'cpp', 
'objc'])
 endif
 
+have_host_block_device = (targetos != 'darwin' or
+cc.has_header('IOKit/storage/IOMedia.h'))
+
 #
 # config-host.h #
 #
@@ -1113,6 +1116,7 @@ config_host_data.set('HAVE_DRM_H', 
cc.has_header('libdrm/drm.h'))
 config_host_data.set('HAVE_PTY_H', cc.has_header('pty.h'))
 config_host_data.set('HAVE_SYS_IOCCOM_H', cc.has_header('sys/ioccom.h'))
 config_host_data.set('HAVE_SYS_KCOV_H', cc.has_header('sys/kcov.h'))
+config_host_data.set('HAVE_HOST_BLOCK_DEVICE', have_host_block_device)
 
 ignored = ['CONFIG_QEMU_INTERP_PREFIX'] # actually per-target
 arrays = ['CONFIG_AUDIO_DRIVERS', 'CONFIG_BDRV_RW_WHITELIST', 
'CONFIG_BDRV_RO_WHITELIST']
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 3484986d1c..1a9576de8d 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -959,7 +959,8 @@
   'discriminator': 'driver',
   'data': {
   'file': 'BlockStatsSpecificFile',
-  'host_device': 'BlockStatsSpecificFile',
+  'host_device': { 'type': 'BlockStatsSpecificFile',
+   'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' },
   'nvme': 'BlockStatsSpecificNvme' } }
 
 ##
@@ -2827,7 +2828,9 @@
 { 'enum': 'BlockdevDriver',
   'data': [ 'blkdebug', 'blklogwrites', 'blkreplay', 'blkverify', 'bochs',
 'cloop', 'compress', 'copy-on-read', 'dmg', 'file', 'ftp', 'ftps',
-'gluster', 'host_cdrom', 'host_device', 'http', 'https', 'iscsi',
+'gluster', 'host_cdrom',
+{'name': 'host_device', 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' },
+'http', 'https', 'iscsi',
 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels',
 'preallocate', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd',
 { 'name': 'replication', 'if': 'defined(CONFIG_REPLICATION)' },
@@ -4012,7 +4015,8 @@
   'ftps':   'BlockdevOptionsCurlFtps',
   'gluster':'BlockdevOptionsGluster',
   'host_cdrom': 'BlockdevOptionsFile',
-  'host_device':'BlockdevOptionsFile',
+  'host_device': { 'type': 'BlockdevOptionsFile',
+   'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' },
   'http':   'BlockdevOptionsCurlHttp',
   'https':  'BlockdevOptionsCurlHttps',
   'iscsi':  'BlockdevOptionsIscsi',
diff --git a/block/file-posix.c b/block/file-posix.c
index 00cdaaa2d4..11d2021346 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -42,6 +42,8 @@
 #include "scsi/constants.h"
 
 #if defined(__APPLE__) && (__MACH__)
+#include 
+#if defined(HAVE_HOST_BLOCK_DEVICE)
 #include 
 #include 
 #include 
@@ -52,6 +54,7 @@
 //#include 
 #include 
 #include 
+#endif /* defined(HAVE_HOST_BLOCK_DEVICE) */
 #endif
 
 #ifdef __sun__
@@ -181,7 +184,17 @@ typedef struct BDRVRawReopenState {
 bool check_cache_dropped;
 } BDRVRawReopenState;
 
-static int fd_open(BlockDriverState *bs);
+static int fd_open(BlockDriverState *bs)
+{
+BDRVRawState *s = bs->opaque;
+
+/* this is just to ensure s->fd is sane (its called by io ops) */
+if (s->fd >= 0) {
+return 0;
+}
+return -EIO;
+}
+
 static int64_t raw_getlength(BlockDriverState *bs);
 
 typedef struct RawPosixAIOData {
@@ -3014,6 +3027,7 @@ static BlockStatsSpecific 
*raw_get_specific_stats(BlockDriverState *bs)
 return stats;
 }
 
+#if defined(HAVE_HOST_BLOCK_DEVICE)
 static BlockStatsSpecific *hdev_get_specific_stats(BlockDriverState *bs)
 {
 BlockStatsSpecific *stats = g_new(BlockStatsSpecific, 1);
@@ -3023,6 +3037,7 @@ static BlockStatsSpecific 
*hdev_get_specific_stats(BlockDriverState *bs)
 
 return stats;
 }
+#endif /* HAVE_HOST_BLOCK_DEVICE */
 
 static QemuOptsList raw_create_opts = {
 .name = "raw-create-opts",
@@ -3247,6 +3262,8 @@ BlockDriver bdrv_file = {
 /***/
 /* host device */
 
+#if defined(HAVE_HOST_BLOCK_DEVICE)
+
 #if defined(__APPLE__) && defined(__MACH__)
 

[PATCH v8 00/11] iOS and Apple Silicon host support

2021-01-22 Thread Joelle van Dyne
These set of changes brings QEMU TCG to iOS devices and future Apple Silicon
devices. They were originally developed last year and have been working in the
UTM app. Recently, we ported the changes to master, re-wrote a lot of the build
script changes for meson, and broke up the patches into more distinct units.

The bulk of the changes allow for cross-compiling for both iOS and macOS running
Apple Silicon and adds feature detection for parts of QEMU that are not
compatible with iOS.

Since v8:

* Moved some feature checks to meson.build
* system() stub return error instead of assertion

Since v7:

* Removed libucontext (will be submitted in another patchset)
* Removed slirp build flags update (superseded by subproject patchset)
* Reworked all patches to use feature detection instead of #ifdef CONFIG_IOS
* Added feature detection for CoreAudio
* Fix various cross compiling issues on macOS

Since v6:

* Dropped the Apple Silicon JIT support patch (superseded by another patchset)
* Changed libucontext to be a Meson subproject
* Cache availablity check for preadv/pwritev on macOS 11 and iOS 14

Since v5:

* Fixed some more instances of QAPI define of CONFIG_HOST_BLOCK_DEVICE
* Fixed libucontext build on newer version of GCC

Since v4:

* Updated QAPI schema for CONFIG_HOST_BLOCK_DEVICE
* Updated maintainers file for iOS host support
* Moved system() changes to osdep.h
* Fixed typo in libucontext meson.build change

Since v3:

* Moved mirror JIT support to a different patch set.
* Removed dependency on `pthread_jit_write_protect_np` because it was redundent
  and also crashes if called on a non-jailbroken iOS device.
* Removed `--enable-cross-compile` option
* Fixed checkpatch errors
* Fixed iOS build on master due to new test recently added which calls system()

Since v2:

* Changed getting mirror pointer from a macro to inline functions
* Split constification of TCG code pointers to separate patch
* Removed slirp updates (will send future patch once slirp changes are in)
* Removed shared library patch (will send future patch)

-j

Joelle van Dyne (11):
  block: feature detection for host block support
  configure: cross-compiling with empty cross_prefix
  configure: check for sys/disk.h
  slirp: feature detection for smbd
  osdep: build with non-working system() function
  darwin: remove redundant dependency declaration
  darwin: fix cross-compiling for Darwin
  configure: cross compile should use x86_64 cpu_family
  block: check availablity for preadv/pwritev on mac
  darwin: detect CoreAudio for build
  darwin: remove 64-bit build detection on 32-bit OS

 configure| 104 +++
 meson.build  |   9 +++-
 qapi/block-core.json |  10 +++--
 include/qemu/osdep.h |  12 +
 block.c  |   2 +-
 block/file-posix.c   |  68 +++-
 net/slirp.c  |  16 +++
 7 files changed, 177 insertions(+), 44 deletions(-)

-- 
2.28.0




[PATCH v8 02/11] configure: cross-compiling with empty cross_prefix

2021-01-22 Thread Joelle van Dyne
The iOS toolchain does not use the host prefix naming convention. So we
need to enable cross-compile options while allowing the PREFIX to be
blank.

Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: Joelle van Dyne 
---
 configure | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 6f6a319c2f..8d8a4733d7 100755
--- a/configure
+++ b/configure
@@ -238,6 +238,7 @@ cpu=""
 iasl="iasl"
 interp_prefix="/usr/gnemul/qemu-%M"
 static="no"
+cross_compile="no"
 cross_prefix=""
 audio_drv_list=""
 block_drv_rw_whitelist=""
@@ -469,6 +470,7 @@ for opt do
   optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
   case "$opt" in
   --cross-prefix=*) cross_prefix="$optarg"
+cross_compile="yes"
   ;;
   --cc=*) CC="$optarg"
   ;;
@@ -1696,7 +1698,7 @@ $(echo Deprecated targets: $deprecated_targets_list | \
   --target-list-exclude=LIST exclude a set of targets from the default 
target-list
 
 Advanced options (experts only):
-  --cross-prefix=PREFIXuse PREFIX for compile tools [$cross_prefix]
+  --cross-prefix=PREFIXuse PREFIX for compile tools, PREFIX can be blank 
[$cross_prefix]
   --cc=CC  use C compiler CC [$cc]
   --iasl=IASL  use ACPI compiler IASL [$iasl]
   --host-cc=CC use C compiler CC [$host_cc] for code run at
@@ -6390,7 +6392,7 @@ if has $sdl2_config; then
 fi
 echo "strip = [$(meson_quote $strip)]" >> $cross
 echo "windres = [$(meson_quote $windres)]" >> $cross
-if test -n "$cross_prefix"; then
+if test "$cross_compile" = "yes"; then
 cross_arg="--cross-file config-meson.cross"
 echo "[host_machine]" >> $cross
 if test "$mingw32" = "yes" ; then
-- 
2.28.0




[PATCH v8 04/11] slirp: feature detection for smbd

2021-01-22 Thread Joelle van Dyne
Replace Windows specific macro with a more generic feature detection
macro. Allows slirp smb feature to be disabled manually as well.

Signed-off-by: Joelle van Dyne 
---
 configure   | 22 +-
 meson.build |  2 +-
 net/slirp.c | 16 
 3 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/configure b/configure
index 8d8a4733d7..d72ab22da5 100755
--- a/configure
+++ b/configure
@@ -464,6 +464,7 @@ fuse="auto"
 fuse_lseek="auto"
 
 malloc_trim="auto"
+slirp_smbd="auto"
 
 # parse CC options second
 for opt do
@@ -845,7 +846,18 @@ do
 fi
 done
 
+# Check for smbd dupport
 : ${smbd=${SMBD-/usr/sbin/smbd}}
+if test "$slirp_smbd" != "no" ; then
+  if test "$mingw32" = "yes" ; then
+if test "$slirp_smbd" = "yes" ; then
+  error_exit "Host smbd not supported on this platform."
+fi
+slirp_smbd=no
+  else
+slirp_smbd=yes
+  fi
+fi
 
 # Default objcc to clang if available, otherwise use CC
 if has clang; then
@@ -1560,6 +1572,10 @@ for opt do
   ;;
   --disable-fuse-lseek) fuse_lseek="disabled"
   ;;
+  --enable-slirp-smbd) slirp_smbd=yes
+  ;;
+  --disable-slirp-smbd) slirp_smbd=no
+  ;;
   *)
   echo "ERROR: unknown option $opt"
   echo "Try '$0 --help' for more information"
@@ -1899,6 +1915,7 @@ disabled with --disable-FEATURE, default is enabled if 
available
   libdaxctl   libdaxctl support
   fuseFUSE block device export
   fuse-lseek  SEEK_HOLE/SEEK_DATA support for FUSE exports
+  slirp-smbd  use smbd (at path --smbd=*) in slirp networking
 
 NOTE: The object files are built at the place where configure is launched
 EOF
@@ -5573,7 +5590,10 @@ fi
 if test "$guest_agent" = "yes" ; then
   echo "CONFIG_GUEST_AGENT=y" >> $config_host_mak
 fi
-echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak
+if test "$slirp_smbd" = "yes" ; then
+  echo "CONFIG_SLIRP_SMBD=y" >> $config_host_mak
+  echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak
+fi
 if test "$vde" = "yes" ; then
   echo "CONFIG_VDE=y" >> $config_host_mak
   echo "VDE_LIBS=$vde_libs" >> $config_host_mak
diff --git a/meson.build b/meson.build
index 6818d97df5..f1e67b8cd1 100644
--- a/meson.build
+++ b/meson.build
@@ -2336,7 +2336,7 @@ summary_info += {'sphinx-build':  
sphinx_build.found()}
 summary_info += {'genisoimage':   config_host['GENISOIMAGE']}
 # TODO: add back version
 summary_info += {'slirp support': slirp_opt == 'disabled' ? false : 
slirp_opt}
-if slirp_opt != 'disabled'
+if slirp_opt != 'disabled' and 'CONFIG_SLIRP_SMBD' in config_host
   summary_info += {'smbd':config_host['CONFIG_SMBD_COMMAND']}
 endif
 summary_info += {'module support':config_host.has_key('CONFIG_MODULES')}
diff --git a/net/slirp.c b/net/slirp.c
index 8350c6d45f..4348e74805 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -27,7 +27,7 @@
 #include "net/slirp.h"
 
 
-#ifndef _WIN32
+#if defined(CONFIG_SLIRP_SMBD)
 #include 
 #include 
 #endif
@@ -90,7 +90,7 @@ typedef struct SlirpState {
 Slirp *slirp;
 Notifier poll_notifier;
 Notifier exit_notifier;
-#ifndef _WIN32
+#if defined(CONFIG_SLIRP_SMBD)
 gchar *smb_dir;
 #endif
 GSList *fwd;
@@ -103,7 +103,7 @@ static QTAILQ_HEAD(, SlirpState) slirp_stacks =
 static int slirp_hostfwd(SlirpState *s, const char *redir_str, Error **errp);
 static int slirp_guestfwd(SlirpState *s, const char *config_str, Error **errp);
 
-#ifndef _WIN32
+#if defined(CONFIG_SLIRP_SMBD)
 static int slirp_smb(SlirpState *s, const char *exported_dir,
  struct in_addr vserver_addr, Error **errp);
 static void slirp_smb_cleanup(SlirpState *s);
@@ -367,7 +367,7 @@ static int net_slirp_init(NetClientState *peer, const char 
*model,
 struct in6_addr ip6_prefix;
 struct in6_addr ip6_host;
 struct in6_addr ip6_dns;
-#ifndef _WIN32
+#if defined(CONFIG_SLIRP_SMBD)
 struct in_addr smbsrv = { .s_addr = 0 };
 #endif
 NetClientState *nc;
@@ -477,7 +477,7 @@ static int net_slirp_init(NetClientState *peer, const char 
*model,
 return -1;
 }
 
-#ifndef _WIN32
+#if defined(CONFIG_SLIRP_SMBD)
 if (vsmbserver && !inet_aton(vsmbserver, )) {
 error_setg(errp, "Failed to parse SMB address");
 return -1;
@@ -592,7 +592,7 @@ static int net_slirp_init(NetClientState *peer, const char 
*model,
 }
 }
 }
-#ifndef _WIN32
+#if defined(CONFIG_SLIRP_SMBD)
 if (smb_export) {
 if (slirp_smb(s, smb_export, smbsrv, errp) < 0) {
 goto error;
@@ -784,7 +784,7 @@ void hmp_hostfwd_add(Monitor *mon, const QDict *qdict)
 
 }
 
-#ifndef _WIN32
+#if defined(CONFIG_SLIRP_SMBD)
 
 /* automatic user mode samba server configuration */
 static void slirp_smb_cleanup(SlirpState *s)
@@ -899,7 +899,7 @@ static int slirp_smb(SlirpState* s, const char 
*exported_dir,
 return 0;
 }
 
-#endif /* !defined(_WIN32) */
+#endif /* defined(CONFIG_SLIRP_SMBD) */
 
 static int guestfwd_can_read(void *opaque)
 {
-- 
2.28.0




[Bug 1745895] Re: Unable to migrate vhost-net to virtio-1.0-capable kernel

2021-01-22 Thread Launchpad Bug Tracker
[Expired for QEMU because there has been no activity for 60 days.]

** Changed in: qemu
   Status: Incomplete => Expired

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1745895

Title:
  Unable to migrate vhost-net to virtio-1.0-capable kernel

Status in QEMU:
  Expired

Bug description:
  I am running QEMU 2.11 (from upstream source, not Red Hat package) on
  stock RHEL 6 and RHEL 7 kernels. Only the RHEL 7 kernel supports
  VIRTIO_F_VERSION_1 in its vhost-net driver.

  When migrating a guest using vhost-net from the RHEL 6 host to RHEL 7,
  the PCI config is rejected by QEMU on the target machine.

  A simple test case:

  1. On the RHEL 7 host, prepare for an incoming migration:

rhel7# qemu-system-x86_64 -S -accel kvm -nographic -monitor stdio
  -nodefaults -netdev tap,id=net0,vhost=on,script=no,downscript=no
  -device virtio-net-pci,netdev=net0,mac=54:52:00:ff:ff:ff -incoming
  tcp:0.0.0.0:12345

  2. On the RHEL 6 host, start a guest and migrate it to the RHEL 7
  host:

rhel6# qemu-system-x86_64 -S -accel kvm -nographic -monitor stdio 
-nodefaults -netdev tap,id=net0,vhost=on,script=no,downscript=no -device 
virtio-net-pci,netdev=net0,mac=54:52:00:ff:ff:ff
  QEMU 2.11.0 monitor - type 'help' for more information
(qemu) migrate tcp:rhel7:12345

  The RHEL 7 QEMU errors out:

qemu-system-x86_64: get_pci_config_device: Bad config data: i=0x20 read: 0 
device: c cmask: ff wmask: 0 w1cmask:0
qemu-system-x86_64: Failed to load PCIDevice:config
qemu-system-x86_64: Failed to load virtio-net:virtio
qemu-system-x86_64: error while loading state for instance 0x0 of device 
':00:02.0/virtio-net'
qemu-system-x86_64: load of migration failed: Invalid argument

  If I start the source QEMU with vhost=off, or the target QEMU with
  disable-modern=true, the migration is successful.

  My hunch here is that the target QEMU prepares the PCI device to
  support VIRTIO_F_VERSION_1, as that's available in the kernel there,
  but then fails to (or does not know to) disable this during the
  migration.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1745895/+subscriptions



[Bug 1800156] Re: windows 8.1 loose grab/leave window on windowed

2021-01-22 Thread Launchpad Bug Tracker
[Expired for QEMU because there has been no activity for 60 days.]

** Changed in: qemu
   Status: Incomplete => Expired

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1800156

Title:
  windows 8.1 loose grab/leave window on windowed

Status in QEMU:
  Expired

Bug description:
  Hello, i am new to QEMU and i encounter that annoying issue (windowed)
  when i move the mouse a bit too much then it leave the window.

  Windows 8.1, Latest QEMU (Windows binaries).

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1800156/+subscriptions



Re: [PATCH 8/8] configure: automatically parse command line for meson -D options

2021-01-22 Thread Yonggang Luo
On Sat, Jan 23, 2021 at 4:44 AM Paolo Bonzini  wrote:
>
>
>
> Il ven 22 gen 2021, 09:00 罗勇刚(Yonggang Luo)  ha
scritto:
>>
>> Hi Paolo, as python and meson are required dependencies to building qemu
now,
>> can we detecting python/meson at the very begining of configure,
>> even before the --help parameter.
>
>
> We could and I did it in the first version. However it's ugly that the
user has to use --python on some setups in order to get a full help message.

  Yeap, but finally configure should gone, so I think --python are
acceptable by user, just need make sure to be noticed when the default
python
are not python3

>
> Paolo
>
>>
>> On Wed, Jan 13, 2021 at 6:08 AM Paolo Bonzini 
wrote:
>> >
>> > On 13/01/21 11:31, Daniel P. Berrangé wrote:
>> > >>   meson-buildoptions.json | 717

>> > > I'm not a fan of seeing this file introduced as it has significant
>> > > overlap with meson_options.txt.I feel like the latter has enough
>> > > information present to do an acceptable job for help output. After
>> > > all that's sufficient if we were using meson directly.
>> >
>> > Sorry, I missed this remark.  meson-buildoptions.json is not
>> > hand-written.  It is the result of Meson's own parsing
meson_options.txt
>> > exported as JSON.
>> >
>> > In the commit message "because we parse command-line options before
>> > meson is available, the introspection output is stored in the source
>> > tree.  This is the reason for the unattractive diffstat; the number of
>> > JSON lines added is higher than the number of configure lines removed.
>> > Of course the latter are code that must be maintained manually and the
>> > former is not".
>> >
>> > Paolo
>> >
>> >
>>
>>
>> --
>>  此致
>> 礼
>> 罗勇刚
>> Yours
>> sincerely,
>> Yonggang Luo



--
 此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo


Re: [PATCH v7 05/11] osdep: build with non-working system() function

2021-01-22 Thread Joelle van Dyne
Unfortunately, this doesn't work for iOS, which defines system() but
throws a compile time error if you try to call it.

-j

On Fri, Jan 22, 2021 at 3:17 PM Peter Maydell  wrote:
>
> On Fri, 22 Jan 2021 at 23:12, Peter Maydell  wrote:
> >
> > On Fri, 22 Jan 2021 at 20:13, Joelle van Dyne  wrote:
> > >
> > > Build without error on hosts without a working system(). An assertion
> > > will trigger if system() is called.
> > >
> > > Signed-off-by: Joelle van Dyne 
> >
> >  configure| 19 +++
> >
> > Can we do the "does system() exist?" check in meson.build ?
> > Untested, but looking at the existing check for "does gettid() exist?"
> > it should be two lines:
> >
> > has_system = cc.has_function('system')
> >
> > and then later:
> >
> > config_host_data.set('HAVE_SYSTEM_FUNCTION', has_system)
>
> ...looking at how we do the HAVE_FOO_H settings, I think we
> can just collapse this into one line:
>
> config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system'))
>
> thanks
> -- PMM



Re: [PATCH] spapr: Adjust firmware path of PCI devices

2021-01-22 Thread Alexey Kardashevskiy




On 23/01/2021 04:01, Greg Kurz wrote:

It is currently not possible to perform a strict boot from USB storage:

$ qemu-system-ppc64 -accel kvm -nodefaults -nographic -serial stdio \
-boot strict=on \
-device qemu-xhci \
-device usb-storage,drive=disk,bootindex=0 \
-blockdev driver=file,node-name=disk,filename=fedora-ppc64le.qcow2


SLOF **
QEMU Starting
  Build Date = Jul 17 2020 11:15:24
  FW Version = git-e18ddad8516ff2cf
  Press "s" to enter Open Firmware.

Populating /vdevice methods
Populating /vdevice/vty@7100
Populating /vdevice/nvram@7101
Populating /pci@8002000
  00  (D) : 1b36 000dserial bus [ usb-xhci ]
No NVRAM common partition, re-initializing...
Scanning USB
   XHCI: Initializing
 USB Storage
SCSI: Looking for devices
   101 DISK : "QEMU QEMU HARDDISK2.5+"
Using default console: /vdevice/vty@7100

   Welcome to Open Firmware

   Copyright (c) 2004, 2017 IBM Corporation All rights reserved.
   This program and the accompanying materials are made available
   under the terms of the BSD License available at
   http://www.opensource.org/licenses/bsd-license.php


Trying to load:  from: 
/pci@8002000/usb@0/storage@1/disk@101 ...
E3405: No such device

E3407: Load failed

   Type 'boot' and press return to continue booting the system.
   Type 'reset-all' and press return to reboot the system.


Ready!
0 >

The device tree handed over by QEMU to SLOF indeed contains:

qemu,boot-list =
"/pci@8002000/usb@0/storage@1/disk@101 HALT";

but the device node is named usb-xhci@0, not usb@0.



I'd expect it to be a return of qdev_fw_name() so in this case something 
like "nec-usb-xhci" (which would still be broken) but seeing a plain 
"usb" is a bit strange.


While your patch works, I wonder if we should assign fw_name to all pci 
nodes to avoid similar problems in the future? Thanks,







This happens because the firmware names of PCI devices returned
by get_boot_devices_list() come from pcibus_get_fw_dev_path(),
while the sPAPR PHB code uses a different naming scheme for
device nodes. This inconsistency has always been there but it was
hidden for a long time because SLOF used to rename USB device
nodes, until this commit, merged in QEMU 4.2.0 :

commit 85164ad4ed9960cac842fa4cc067c6b6699b0994
Author: Alexey Kardashevskiy 
Date:   Wed Sep 11 16:24:32 2019 +1000

 pseries: Update SLOF firmware image

 This fixes USB host bus adapter name in the device tree to match QEMU's
 one.

 Signed-off-by: Alexey Kardashevskiy 
 Signed-off-by: David Gibson 

Fortunately, sPAPR implements the firmware path provider interface.
This provides a way to override the default firmware paths.

Just factor out the sPAPR PHB naming logic from spapr_dt_pci_device()
to a helper, and use it in the sPAPR firmware path provider hook.

Fixes: 85164ad4ed99 ("pseries: Update SLOF firmware image")
Signed-off-by: Greg Kurz 
---
  include/hw/pci-host/spapr.h |  2 ++
  hw/ppc/spapr.c  |  5 +
  hw/ppc/spapr_pci.c  | 33 ++---
  3 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/include/hw/pci-host/spapr.h b/include/hw/pci-host/spapr.h
index bd014823a933..5b03a7b0eb3f 100644
--- a/include/hw/pci-host/spapr.h
+++ b/include/hw/pci-host/spapr.h
@@ -210,4 +210,6 @@ static inline unsigned 
spapr_phb_windows_supported(SpaprPhbState *sphb)
  return sphb->ddw_enabled ? SPAPR_PCI_DMA_MAX_WINDOWS : 1;
  }
  
+char *spapr_pci_fw_dev_name(PCIDevice *dev);

+
  #endif /* PCI_HOST_SPAPR_H */
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 6ab27ea269d5..632502c2ecf8 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -3048,6 +3048,7 @@ static char *spapr_get_fw_dev_path(FWPathProvider *p, 
BusState *bus,
  SCSIDevice *d = CAST(SCSIDevice,  dev, TYPE_SCSI_DEVICE);
  SpaprPhbState *phb = CAST(SpaprPhbState, dev, TYPE_SPAPR_PCI_HOST_BRIDGE);
  VHostSCSICommon *vsc = CAST(VHostSCSICommon, dev, TYPE_VHOST_SCSI_COMMON);
+PCIDevice *pcidev = CAST(PCIDevice, dev, TYPE_PCI_DEVICE);
  
  if (d) {

  void *spapr = CAST(void, bus->parent, "spapr-vscsi");
@@ -3121,6 +3122,10 @@ static char *spapr_get_fw_dev_path(FWPathProvider *p, 
BusState *bus,
  return g_strdup_printf("pci@%x", PCI_SLOT(pcidev->devfn));
  }
  
+if (pcidev) {

+return spapr_pci_fw_dev_name(pcidev);
+}
+
  return NULL;
  }
  
diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c

index 76d7c91e9c64..da6eb58724c8 100644
--- a/hw/ppc/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -1334,15 +1334,29 @@ static int spapr_dt_pci_bus(SpaprPhbState *sphb, PCIBus 
*bus,
  return offset;
  }
  
+char *spapr_pci_fw_dev_name(PCIDevice *dev)

+{
+const gchar *basename;
+int slot = PCI_SLOT(dev->devfn);
+int func = 

Re: [PATCH v2 1/1] spapr_caps.c: check user input before warning about TCG only caps

2021-01-22 Thread David Gibson
On Wed, Jan 20, 2021 at 07:54:06AM -0300, Daniel Henrique Barboza wrote:
> Commit 006e9d361869 added warning messages for cap-cfpc, cap-ibs and
> cap-sbbc when enabled under TCG. Commit 8ff43ee404d3 did the same thing
> when introducing cap-ccf-assist.
> 
> These warning messages, although benign to the machine launch, can make
> users a bit confused. E.g:
> 
> $ sudo ./ppc64-softmmu/qemu-system-ppc64
> qemu-system-ppc64: warning: TCG doesn't support requested feature, 
> cap-cfpc=workaround
> qemu-system-ppc64: warning: TCG doesn't support requested feature, 
> cap-sbbc=workaround
> qemu-system-ppc64: warning: TCG doesn't support requested feature, 
> cap-ibs=workaround
> qemu-system-ppc64: warning: TCG doesn't support requested feature, 
> cap-ccf-assist=on
> 
> We're complaining about "TCG doesn't support requested feature" when the
> user didn't request any of those caps in the command line.
> 
> Check if these caps were set in the command line before sending an user
> warning.
> 
> Signed-off-by: Daniel Henrique Barboza 

Oof.  I have real mixed feelings about this.

So, yes, the warnings are annoying, but they're not meaningless.  They
are really indicating that the guest environment is different from the
one you requested (implicitly, via the machine version). The fact that
they are only warnings, not hard errors, is already a compromise
because otherwise there would be no real way to use TCG at all with
current machines.

In short, the warnings are scary because they're *meant* to be scary.
TCG will not, and cannot, supply the Spectre mitigations that are
expected on a current machine type.

I agree that the current behaviour is pretty irritating, but I don't
know that silently pretending TCG can do what's normally expected of
that command line is a great option either.


> ---
>  hw/ppc/spapr_caps.c | 47 ++---
>  1 file changed, 36 insertions(+), 11 deletions(-)
> 
> diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
> index 9341e9782a..629c24a96d 100644
> --- a/hw/ppc/spapr_caps.c
> +++ b/hw/ppc/spapr_caps.c
> @@ -244,9 +244,15 @@ static void cap_safe_cache_apply(SpaprMachineState 
> *spapr, uint8_t val,
>  uint8_t kvm_val =  kvmppc_get_cap_safe_cache();
>  
>  if (tcg_enabled() && val) {
> -/* TCG only supports broken, allow other values and print a warning 
> */
> -warn_report("TCG doesn't support requested feature, cap-cfpc=%s",
> -cap_cfpc_possible.vals[val]);
> +/*
> + * TCG only supports broken, allow other values and print a warning
> + * in case the user attempted to set a different value in the command
> + * line.
> + */
> +if (spapr->cmd_line_caps[SPAPR_CAP_CFPC] != SPAPR_CAP_BROKEN) {
> +warn_report("TCG doesn't support requested feature, cap-cfpc=%s",
> +cap_cfpc_possible.vals[val]);
> +}
>  } else if (kvm_enabled() && (val > kvm_val)) {
>  error_setg(errp,
> "Requested safe cache capability level not supported by 
> KVM");
> @@ -269,9 +275,15 @@ static void 
> cap_safe_bounds_check_apply(SpaprMachineState *spapr, uint8_t val,
>  uint8_t kvm_val =  kvmppc_get_cap_safe_bounds_check();
>  
>  if (tcg_enabled() && val) {
> -/* TCG only supports broken, allow other values and print a warning 
> */
> -warn_report("TCG doesn't support requested feature, cap-sbbc=%s",
> -cap_sbbc_possible.vals[val]);
> +/*
> + * TCG only supports broken, allow other values and print a warning
> + * in case the user attempted to set a different value in the command
> + * line.
> + */
> +if (spapr->cmd_line_caps[SPAPR_CAP_SBBC] != SPAPR_CAP_BROKEN) {
> +warn_report("TCG doesn't support requested feature, cap-sbbc=%s",
> +cap_sbbc_possible.vals[val]);
> +}
>  } else if (kvm_enabled() && (val > kvm_val)) {
>  error_setg(errp,
>  "Requested safe bounds check capability level not supported by KVM");
> @@ -297,9 +309,15 @@ static void 
> cap_safe_indirect_branch_apply(SpaprMachineState *spapr,
>  uint8_t kvm_val = kvmppc_get_cap_safe_indirect_branch();
>  
>  if (tcg_enabled() && val) {
> -/* TCG only supports broken, allow other values and print a warning 
> */
> -warn_report("TCG doesn't support requested feature, cap-ibs=%s",
> -cap_ibs_possible.vals[val]);
> +/*
> + * TCG only supports broken, allow other values and print a warning
> + * in case the user attempted to set a different value in the command
> + * line.
> + */
> +if (spapr->cmd_line_caps[SPAPR_CAP_IBS] != SPAPR_CAP_BROKEN) {
> +warn_report("TCG doesn't support requested feature, cap-ibs=%s",
> +cap_ibs_possible.vals[val]);
> +}
>  } else if (kvm_enabled() && 

Re: [PATCH 1/1] os_find_datadir: search as in version 4.2

2021-01-22 Thread Brian Norris
Just to follow-up here, since nobody followed up for months...

On Mon, Aug 10, 2020 at 2:41 PM Brian Norris  wrote:
> On Mon, Aug 10, 2020 at 12:29 AM Marc-André Lureau
>  wrote:
> > On Sat, Aug 8, 2020 at 7:34 PM Peter Maydell  
> > wrote:
> > > On Sat, 8 Aug 2020 at 02:35, Brian Norris  
> > > wrote:
> > > It's just missed 5.1, unfortunately :-(

And it missed 5.2 too :(

> > > Marc-André, did you want to review it ?
> >
> > I tried an alternative approach, and ack his version instead:
> >
> > https://patchew.org/QEMU/20200716141100.398296-1-marcandre.lur...@redhat.com/
> >
> > (I am going to do this in this thread instead)
>
> FWIW, you already provided your Review a month ago:
> https://lore.kernel.org/qemu-devel/caj+f1cjmmv6py6r0p6uknza_q+w6ylvaxekgnusgxyuuip6...@mail.gmail.com/
>
> But I see you've now repeated it ;)
> https://lore.kernel.org/qemu-devel/caj+f1cjdho7r9rnmod1clezsylfsfvvjcar5ucsyfgfcw3z...@mail.gmail.com/
>
> In any case, thanks! We'll likely carry this patch in Chrome OS, until
> it gets applied to a proper release.

It turns out that Paolo inadvertently (?) fixed this issue by
refactoring, in v5.2.0:
ea1edcd7da1a vl: relocate paths to data directories
https://git.qemu.org/?p=qemu.git;a=commitdiff;h=ea1edcd7da1a375ef7ccf8aa93b72827b518ad8e;hp=63c4db4c2e6d221cecb5aafa365934bb05724cb4

I tested that out here, and the new find_datadir() is able to track
relocations properly, by looking for a common directory ancestor of
the running executable. Thanks Paolo!

Brian



Re: [PATCH V5 4/6] hw/block/nvme: support for multi-controller in subsystem

2021-01-22 Thread Minwoo Im
On 21-01-22 10:42:36, Keith Busch wrote:
> On Fri, Jan 22, 2021 at 09:07:34PM +0900, Minwoo Im wrote:
> > index b525fca14103..3dedefb8ebba 100644
> > --- a/hw/block/nvme.c
> > +++ b/hw/block/nvme.c
> > @@ -4435,6 +4435,9 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice 
> > *pci_dev)
> >  strpadcpy((char *)id->mn, sizeof(id->mn), "QEMU NVMe Ctrl", ' ');
> >  strpadcpy((char *)id->fr, sizeof(id->fr), "1.0", ' ');
> >  strpadcpy((char *)id->sn, sizeof(id->sn), n->params.serial, ' ');
> > +
> > +id->cntlid = n->cntlid;
> 
> cpu_to_le16()? It might be okay to not do that since the only
> requirement is that this is a unique value, but it would be confusing
> for decoding commands that have a controller id field.

Agreed.

Yes, cntlids are allocated in unique values so that functionality has no
problem here.  But, even if so, we should make it have proper value in
Identify data structure with the policy it has to avoid confusing.

Thanks Keith! will fix it :)



[PATCH] hvf: Fetch cr4 before evaluating CPUID(1)

2021-01-22 Thread Alexander Graf
The CPUID function 1 has a bit called OSXSAVE which tells user space the
status of the CR4.OSXSAVE bit. Our generic CPUID function injects that bit
based on the status of CR4.

With Hypervisor.framework, we do not synchronize full CPU state often enough
for this function to see the CR4 update before guest user space asks for it.

To be on the save side, let's just always synchronize it when we receive a
CPUID(1) request. That way we can set the bit with real confidence.

Reported-by: Asad Ali 
Signed-off-by: Alexander Graf 
---
 target/i386/hvf/hvf.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 08b4adecd9..f660b829ac 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -426,6 +426,10 @@ int hvf_vcpu_exec(CPUState *cpu)
 uint32_t rcx = (uint32_t)rreg(cpu->hvf->fd, HV_X86_RCX);
 uint32_t rdx = (uint32_t)rreg(cpu->hvf->fd, HV_X86_RDX);
 
+if (rax == 1) {
+/* CPUID1.ecx.OSXSAVE needs to know CR4 */
+env->cr[4] = rvmcs(cpu->hvf->fd, VMCS_GUEST_CR4);
+}
 cpu_x86_cpuid(env, rax, rcx, , , , );
 
 wreg(cpu->hvf->fd, HV_X86_RAX, rax);
-- 
2.24.3 (Apple Git-128)




Re: [PATCH] coroutine-sigaltstack: Keep SIGUSR2 handler up

2021-01-22 Thread Laszlo Ersek
On 01/22/21 22:26, Laszlo Ersek wrote:

> I'm drifting towards an overhaul of coroutine-sigaltstack, based on my
> personal understanding of POSIX, but given that I can absolutely not
> *test* coroutine-sigaltstack on the platforms where it actually matters,
> an "overhaul" by me would be reckless.
> 
> I didn't expect these skeletons when I first read Max's "Thread safety
> of coroutine-sigaltstack" email :/
> 
> Max, after having worked on top of your patch for a few hours, I
> officially endorse your mutex approach. I can't encourage you or myself
> to touch this code, in good conscience. It's not that it's "bad"; it's
> inexplicable and (to me) untestable.

I'm attaching a patch (based on 0e3246263068). I'm not convinced that I
should take responsibility for this, given the lack of testability on my
end. So I'm not posting it stand-alone even as an RFC. I've built it and
have booted one of my existent domains with it, but that's all.

Thanks
Laszlo
>From c6c05052961e6066d36f5c7c6e32d36ea9f17dff Mon Sep 17 00:00:00 2001
From: Laszlo Ersek 
Date: Fri, 22 Jan 2021 11:20:41 +0100
Subject: [PATCH] coroutine-sigaltstack: overhaul SIGUSR2 treatment
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

(1) Disposition (action) for any given signal is global for the process.
When two threads run coroutine-sigaltstack's qemu_coroutine_new()
concurrently, they may interfere with each other: one of them may
revert the SIGUSR2 handler to SIG_DFL, between the other thread (a)
setting up coroutine_trampoline() as the handler and (b) raising
SIGUSR2. That SIGUSR2 will then terminate the QEMU process abnormally.

Outside of coroutine-sigaltstack, qemu does not use SIGUSR2 [*]. So
move the pthread_sigmask() and sigaction() calls from
qemu_coroutine_new() to coroutine_init(). This will keep the handler
installed all the time, while also ensuring that all threads block
SIGUSR2 all the time.

[*] In user-mode emulation, the guest can register signal handlers for
any signal but SIGSEGV and SIGBUS, so if it registers a SIGUSR2
handler, that will interfere with coroutine-sigaltstack. However,
we do not use coroutines for user-mode emulation, so that is fine.

(2) The temporary unblocking of SIGUSR2 in qemu_coroutine_new() with
sigsuspend(), which implements the synchronous delivery of SIGUSR2 to
the thread, is needlessly complicated. Remove the "tr_called"-based
loop around sigsuspend(), as by the time we reach sigsuspend(),
SIGUSR2 is certainly pending.

(3) Relatedly, the top of the signal handler can only be entered via the
sigsuspend() in qemu_coroutine_new(). Express this fact in the signal
handler by abort()ing on (tr_handler==NULL).

First, even if another process sends a SIGUSR2 to the QEMU process
asynchronously, SIGUSR2 will only be unblocked by sigsuspend() in the
next qemu_coroutine_new() execution, and by that time, the thread in
question will have raised SIGUSR2 anyway.

Second, there is no reason for sigsuspend() *not* to be both a
compiler barrier and a memory barrier.

(4) Finally, the "tr_handler" field should be more strongly typed; it only
ever points to a CoroutineSigAltStack object.

Based on Max's original patch.

Cc: "Daniel P. Berrangé" 
Cc: Eric Blake 
Cc: Kevin Wolf 
Cc: Markus Armbruster 
Cc: Max Reitz 
Cc: Paolo Bonzini 
Cc: Peter Maydell 
Cc: Stefan Hajnoczi 
Signed-off-by: Max Reitz 
Signed-off-by: Laszlo Ersek 
---
 util/coroutine-sigaltstack.c | 89 +---
 1 file changed, 52 insertions(+), 37 deletions(-)

diff --git a/util/coroutine-sigaltstack.c b/util/coroutine-sigaltstack.c
index aade82afb8c0..a59513367532 100644
--- a/util/coroutine-sigaltstack.c
+++ b/util/coroutine-sigaltstack.c
@@ -44,21 +44,22 @@ typedef struct {
 /**
  * Per-thread coroutine bookkeeping
  */
 typedef struct {
 /** Currently executing coroutine */
 Coroutine *current;
 
 /** The default coroutine */
 CoroutineSigAltStack leader;
 
 /** Information for the signal handler (trampoline) */
 sigjmp_buf tr_reenter;
-volatile sig_atomic_t tr_called;
-void *tr_handler;
+CoroutineSigAltStack *tr_handler;
 } CoroutineThreadState;
 
 static pthread_key_t thread_state_key;
 
+static void coroutine_trampoline(int signal);
+
 static CoroutineThreadState *coroutine_get_thread_state(void)
 {
 CoroutineThreadState *s = pthread_getspecific(thread_state_key);
@@ -81,16 +82,51 @@ static void qemu_coroutine_thread_cleanup(void *opaque)
 static void __attribute__((constructor)) coroutine_init(void)
 {
 int ret;
+sigset_t sigs;
+struct sigaction sa;
 
 ret = pthread_key_create(_state_key, qemu_coroutine_thread_cleanup);
 if (ret != 0) {
 fprintf(stderr, "unable to create leader key: %s\n", strerror(errno));
 abort();
 }
+
+/*
+ * This constructor function is running in 

Re: [PATCH v2 1/3] target/arm: Remove PSTATE_SS from cpsr and move it into env->pstate.

2021-01-22 Thread Rebecca Cran

On 1/22/21 2:03 PM, Richard Henderson wrote:

On 1/21/21 6:45 PM, Rebecca Cran wrote:



  cpsr_write(env, spsr, mask, CPSRWriteRaw);
-if (!arm_singlestep_active(env)) {
-env->uncached_cpsr &= ~PSTATE_SS;
-}
+env->pstate &= ~PSTATE_SS;


Why are you removing the singlestep check?



-env->uncached_cpsr &= ~PSTATE_SS;
-env->spsr = cpsr_read(env);
+env->pstate &= ~PSTATE_SS;
+env->spsr &= ~PSTATE_SS;


This loses the saving of cpsr into spsr.


Oh, right. I've fixed both this and the above issue in the next revision 
which I'll send out early next week (giving a chance for any extra 
feedback).


Thanks.
--
Rebecca Cran



Re: [PATCH v2 3/3] target/arm: Set ID_AA64PFR0.DIT and ID_PFR0.DIT to 1 for "max" AA64 CPU

2021-01-22 Thread Rebecca Cran

On 1/22/21 2:06 PM, Richard Henderson wrote:

On 1/21/21 6:45 PM, Rebecca Cran wrote:

Enable FEAT_DIT for the "max" AARCH64 CPU.

Signed-off-by: Rebecca Cran 
Reviewed-by: Richard Henderson 
---
  target/arm/cpu64.c | 5 +
  1 file changed, 5 insertions(+)


There is also a 32-bit "max" cpu in cpu.c.


Thanks. I've fixed it in the next revision.



Re: Thread safety of coroutine-sigaltstack

2021-01-22 Thread Laszlo Ersek
On 01/22/21 11:14, Peter Maydell wrote:
> On Fri, 22 Jan 2021 at 08:50, Max Reitz  wrote:
>>
>> On 20.01.21 18:25, Laszlo Ersek wrote:
>>
>> [...]
>>
>>> A simple grep for SIGUSR2 seems to indicate that SIGUSR2 is not used by
>>> system emulation for anything else, in practice. Is it possible to
>>> dedicate SIGUSR2 explicitly to coroutine-sigaltstack, and set up the
>>> action beforehand, from some init function that executes on a "central"
>>> thread, before qemu_coroutine_new() is ever called?
>>
>> I wrote a patch to that effect, but just before sending I wondered
>> whether SIGUSR2 cannot be registered by the “guest” in user-mode
>> emulation, and whether that would then break coroutines from there on.
>>
>> (I have no experience dealing with user-mode emulation, but it does look
>> like the guest can just register handlers for any signal but SIGSEGV and
>> SIGBUS.)
> 
> Yes, SIGUSR2 is for the guest in user-emulation mode. OTOH do we
> even use the coroutine code in user-emulation mode? Looking at
> the meson.build files, we only add the coroutine_*.c to util_ss
> if 'have_block', and we set have_block = have_system or have_tools.
> I think (but have not checked) that that means we will build and
> link the object file into the user-mode binaries if you happen
> to build them in the same run as system-mode binaries,

I did that, first running

 ./configure \
--enable-debug \
--target-list==x86_64-softmmu,x86_64-linux-user \
--with-coroutine=sigaltstack

Then I checked the "qemu-system-x86_64" and "qemu-x86_64" binaries with
"nm". Only the former contains "coroutine_init":

009725e4 t coroutine_init

So I believe the coroutine object file(s) are not even linked into the
user-mode emulators. (coroutine_init() is a constructor function, so I
think it would be preserved otherwise, even if it had no explicit caller.)

I tried a different approach too: an #error in
"coroutine-sigaltstack.c", if CONFIG_LINUX_USER were #defined. But that
aborted the build, due to CONFIG_LINUX_USER being poisoned in the first
place. Maybe that result was already enough to answer the question, but
I wasn't sure, hence the check with "nm".

Thanks,
Laszlo

> but won't
> build them in if you built the user-mode binaries as a separate
> build. Which is odd and probably worth fixing, but does mean we
> know that we aren't actually using coroutines in user-mode.
> (Also user-mode really means Linux or BSD and I think both of
> those have working ucontext.)
> 
> thanks
> -- PMM
> 




[Bug 1912857] Re: virtio-serial blocks hostfwd ssh on windows 10 host

2021-01-22 Thread Ven Karri
** Description changed:

  qemu-system-x86_64
    -display none
    -hda archlinux.qcow2
    -m 4G
    -netdev user,id=n1,hostfwd=tcp::-:22
    -device virtio-net-pci,netdev=n1
  
  --> THIS WORKS - meaning I can ssh into the vm via port 
  
  qemu-system-x86_64
    -display none
    -hda archlinux.qcow2
    -m 4G
    -netdev user,id=n1,hostfwd=tcp::-:22
    -device virtio-net-pci,netdev=n1
    -device virtio-serial
    -device virtserialport,chardev=cid0
    -chardev socket,id=cid0,host=localhost,port=55298,server,nowait
  
  --> DOES NOT WORK - meaning I cannot ssh into the vm
  
  Not only does the port  not work, but I am not able to perform any
  serial transfer on port 55298 as well.
  
  The following doesn't work either:
  
  qemu-system-x86_64
    -display none
    -hda archlinux.qcow2
    -m 4G
    -netdev user,id=n1,hostfwd=tcp::-:22
    -device virtio-net-pci,netdev=n1
    -device virtio-serial
    -device virtserialport,chardev=cid0
    -chardev file,id=cid0,path=mypath
  
  No matter which character device I use for my virtserialport
  communication (socket or udp or file or pipe), the hostfwd doesn't work.
  
  Also, if I enable the display, I am unable to type anything in the
  emulator window when I use virtserialport.
  
  Host: Windows 10
  Guest: archlinux
  QEMU version 5.2
+ 
+ The same thing works just fine on a Mac OS X host (tested on Big Sur)

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1912857

Title:
  virtio-serial blocks hostfwd ssh on windows 10 host

Status in QEMU:
  New

Bug description:
  qemu-system-x86_64
    -display none
    -hda archlinux.qcow2
    -m 4G
    -netdev user,id=n1,hostfwd=tcp::-:22
    -device virtio-net-pci,netdev=n1

  --> THIS WORKS - meaning I can ssh into the vm via port 

  qemu-system-x86_64
    -display none
    -hda archlinux.qcow2
    -m 4G
    -netdev user,id=n1,hostfwd=tcp::-:22
    -device virtio-net-pci,netdev=n1
    -device virtio-serial
    -device virtserialport,chardev=cid0
    -chardev socket,id=cid0,host=localhost,port=55298,server,nowait

  --> DOES NOT WORK - meaning I cannot ssh into the vm

  Not only does the port  not work, but I am not able to perform any
  serial transfer on port 55298 as well.

  The following doesn't work either:

  qemu-system-x86_64
    -display none
    -hda archlinux.qcow2
    -m 4G
    -netdev user,id=n1,hostfwd=tcp::-:22
    -device virtio-net-pci,netdev=n1
    -device virtio-serial
    -device virtserialport,chardev=cid0
    -chardev file,id=cid0,path=mypath

  No matter which character device I use for my virtserialport
  communication (socket or udp or file or pipe), the hostfwd doesn't
  work.

  Also, if I enable the display, I am unable to type anything in the
  emulator window when I use virtserialport.

  Host: Windows 10
  Guest: archlinux
  QEMU version 5.2

  The same thing works just fine on a Mac OS X host (tested on Big Sur)

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1912857/+subscriptions



Re: [PATCHv9 0/3] arm-virt: add secure pl061 for reset/power down

2021-01-22 Thread Peter Maydell
On Fri, 22 Jan 2021 at 21:52, Maxim Uvarov  wrote:
>
>  v9: - cosmetic changes (move if from patch2 to patch3, rename function name
>and define).
>  v8: - use gpio 0 and 1, align dtb with kernel gpio-restart, gpio-poweroff,
>change define names, trigger on upper front. (Peter Maydell).
>  v7: - same as v6, but resplit patches: patch 2 no function changes and 
> refactor
> gpio setup for virt platfrom and patch 3 adds secure gpio.
>  v6: - 64k align gpio memory region (Andrew Jones)
>  - adjusted memory region to map this address in the corresponding atf 
> patch
>  v5: - removed vms flag, added fdt  (Andrew Jones)
>  - added patch3 to combine secure and non secure pl061. It has to be
>more easy to review if this changes are in the separate patch.
>  v4: rework patches accodring to Peter Maydells comments:
> - split patches on gpio-pwr driver and arm-virt integration.
> - start secure gpio only from virt-6.0.
> - rework qemu interface for gpio-pwr to use 2 named gpio.
> - put secure gpio to secure name space.
>  v3: added missed include qemu/log.h for qemu_log(..
>  v2: replace printf with qemu_log (Philippe Mathieu-Daudé)
>
> This patch works together with ATF patch:
> 
> https://github.com/muvarov/arm-trusted-firmware/commit/886965bddb0624bdf85103efb2b39fd4eb73d89b
>
> Maxim Uvarov (3):
>   hw: gpio: implement gpio-pwr driver for qemu reset/poweroff
>   arm-virt: refactor gpios creation
>   arm-virt: add secure pl061 for reset/power down

Applied to target-arm.next, thanks. I realized we forgot the
documentation, so I'm going to squash this change in to patch 3:

--- a/docs/system/arm/virt.rst
+++ b/docs/system/arm/virt.rst
@@ -43,6 +43,8 @@ The virt board supports:
 - Secure-World-only devices if the CPU has TrustZone:

   - A second PL011 UART
+  - A second PL061 GPIO controller, with GPIO lines for triggering
+a system reset or system poweroff
   - A secure flash memory
   - 16MB of secure RAM

-- PMM



[Bug 1912857] Re: virtio-serial blocks hostfwd ssh on windows 10 host

2021-01-22 Thread Ven Karri
** Description changed:

- qemu-system-x86_64 -display none -hda archlinux.qcow2 -m 4G -netdev
- user,id=n1,hostfwd=tcp::-:22 -device virtio-net-pci,netdev=n1 -->
- WORKS - meaning I can ssh into the vm via port 
+ qemu-system-x86_64 
+   -display none 
+   -hda archlinux.qcow2 
+   -m 4G 
+   -netdev user,id=n1,hostfwd=tcp::-:22 
+   -device virtio-net-pci,netdev=n1 
  
- qemu-system-x86_64 -display none -hda archlinux.qcow2 -m 4G -netdev
- user,id=n1,hostfwd=tcp::-:22 -device virtio-net-pci,netdev=n1
- -device virtio-serial -device virtserialport,chardev=cid0 -chardev
- socket,id=cid0,host:localhost,port:55298,server,nowait --> DOES NOT WORK
- - meaning I cannot ssh into the vm
+ --> THIS WORKS - meaning I can ssh into the vm via port 
+ 
+ qemu-system-x86_64 
+   -display none 
+   -hda archlinux.qcow2 
+   -m 4G 
+   -netdev user,id=n1,hostfwd=tcp::-:22 
+   -device virtio-net-pci,netdev=n1 
+   -device virtio-serial 
+   -device virtserialport,chardev=cid0 
+   -chardev socket,id=cid0,host:localhost,port:55298,server,nowait 
+ 
+ --> DOES NOT WORK - meaning I cannot ssh into the vm
  
  Not only does the port  not work, but I am not able to perform any
  serial transfer on port 55298 as well.
  
  The following doesn't work either:
  
- qemu-system-x86_64 -display none -hda archlinux.qcow2 -m 4G -netdev
- user,id=n1,hostfwd=tcp::-:22 -device virtio-net-pci,netdev=n1
- -device virtio-serial -device virtserialport,chardev=cid0 -chardev
- file,id=cid0,path=temp,server,nowait
+ qemu-system-x86_64 
+   -display none 
+   -hda archlinux.qcow2 
+   -m 4G 
+   -netdev user,id=n1,hostfwd=tcp::-:22 
+   -device virtio-net-pci,netdev=n1 
+   -device virtio-serial -device virtserialport,chardev=cid0 
+   -chardev file,id=cid0,path=temp,server,nowait
  
  No matter which character device I use for my virtserialport
  communication (socket or udp or file or pipe), the hostfwd doesn't work.
  
  Host: Windows 10
  Guest: archlinux
  QEMU version 5.2

** Description changed:

- qemu-system-x86_64 
-   -display none 
-   -hda archlinux.qcow2 
-   -m 4G 
-   -netdev user,id=n1,hostfwd=tcp::-:22 
-   -device virtio-net-pci,netdev=n1 
+ qemu-system-x86_64
+   -display none
+   -hda archlinux.qcow2
+   -m 4G
+   -netdev user,id=n1,hostfwd=tcp::-:22
+   -device virtio-net-pci,netdev=n1
  
  --> THIS WORKS - meaning I can ssh into the vm via port 
  
- qemu-system-x86_64 
-   -display none 
-   -hda archlinux.qcow2 
-   -m 4G 
-   -netdev user,id=n1,hostfwd=tcp::-:22 
-   -device virtio-net-pci,netdev=n1 
-   -device virtio-serial 
-   -device virtserialport,chardev=cid0 
-   -chardev socket,id=cid0,host:localhost,port:55298,server,nowait 
+ qemu-system-x86_64
+   -display none
+   -hda archlinux.qcow2
+   -m 4G
+   -netdev user,id=n1,hostfwd=tcp::-:22
+   -device virtio-net-pci,netdev=n1
+   -device virtio-serial
+   -device virtserialport,chardev=cid0
+   -chardev socket,id=cid0,host=localhost,port=55298,server,nowait
  
  --> DOES NOT WORK - meaning I cannot ssh into the vm
  
  Not only does the port  not work, but I am not able to perform any
  serial transfer on port 55298 as well.
  
  The following doesn't work either:
  
- qemu-system-x86_64 
-   -display none 
-   -hda archlinux.qcow2 
-   -m 4G 
-   -netdev user,id=n1,hostfwd=tcp::-:22 
-   -device virtio-net-pci,netdev=n1 
-   -device virtio-serial -device virtserialport,chardev=cid0 
-   -chardev file,id=cid0,path=temp,server,nowait
+ qemu-system-x86_64
+   -display none
+   -hda archlinux.qcow2
+   -m 4G
+   -netdev user,id=n1,hostfwd=tcp::-:22
+   -device virtio-net-pci,netdev=n1
+   -device virtio-serial -device virtserialport,chardev=cid0
+   -chardev file,id=cid0,path=temp,server,nowait
  
  No matter which character device I use for my virtserialport
  communication (socket or udp or file or pipe), the hostfwd doesn't work.
  
  Host: Windows 10
  Guest: archlinux
  QEMU version 5.2

** Description changed:

  qemu-system-x86_64
    -display none
    -hda archlinux.qcow2
    -m 4G
    -netdev user,id=n1,hostfwd=tcp::-:22
    -device virtio-net-pci,netdev=n1
  
  --> THIS WORKS - meaning I can ssh into the vm via port 
  
  qemu-system-x86_64
    -display none
    -hda archlinux.qcow2
    -m 4G
    -netdev user,id=n1,hostfwd=tcp::-:22
    -device virtio-net-pci,netdev=n1
    -device virtio-serial
    -device virtserialport,chardev=cid0
    -chardev socket,id=cid0,host=localhost,port=55298,server,nowait
  
  --> DOES NOT WORK - meaning I cannot ssh into the vm
  
  Not only does the port  not work, but I am not able to perform any
  serial transfer on port 55298 as well.
  
  The following doesn't work either:
  
  qemu-system-x86_64
    -display none
    -hda archlinux.qcow2
    -m 4G
    -netdev user,id=n1,hostfwd=tcp::-:22
    -device virtio-net-pci,netdev=n1
-   -device virtio-serial -device virtserialport,chardev=cid0
+   -device virtio-serial 
+   -device 

[Bug 1912857] Re: virtio-serial blocks hostfwd ssh on windows 10 host

2021-01-22 Thread Ven Karri
** Description changed:

  qemu-system-x86_64 -display none -hda archlinux.qcow2 -m 4G -netdev
  user,id=n1,hostfwd=tcp::-:22 -device virtio-net-pci,netdev=n1 -->
  WORKS - meaning I can ssh into the vm via port 
  
  qemu-system-x86_64 -display none -hda archlinux.qcow2 -m 4G -netdev
  user,id=n1,hostfwd=tcp::-:22 -device virtio-net-pci,netdev=n1
  -device virtio-serial -device virtserialport,chardev=cid0 -chardev
- socket,id=cid0,{socket_addr_serial},server,nowait --> DOES NOT WORK -
- meaning I cannot ssh into the vm
+ socket,id=cid0,host:localhost,port:55298,server,nowait --> DOES NOT WORK
+ - meaning I cannot ssh into the vm
  
  Not only does the port  not work, but I am not able to perform any
  serial transfer on port 55298 as well.
  
+ The following doesn't work either:
+ 
+ qemu-system-x86_64 -display none -hda archlinux.qcow2 -m 4G -netdev
+ user,id=n1,hostfwd=tcp::-:22 -device virtio-net-pci,netdev=n1
+ -device virtio-serial -device virtserialport,chardev=cid0 -chardev
+ file,id=cid0,path=temp,server,nowait
+ 
+ No matter which character device I use for my virtio-serial-port
+ communication (socket or udp or file or pipe), the hostfwd doesn't work.
+ 
  Host: Windows 10
  Guest: archlinux
  QEMU version 5.2

** Description changed:

  qemu-system-x86_64 -display none -hda archlinux.qcow2 -m 4G -netdev
  user,id=n1,hostfwd=tcp::-:22 -device virtio-net-pci,netdev=n1 -->
  WORKS - meaning I can ssh into the vm via port 
  
  qemu-system-x86_64 -display none -hda archlinux.qcow2 -m 4G -netdev
  user,id=n1,hostfwd=tcp::-:22 -device virtio-net-pci,netdev=n1
  -device virtio-serial -device virtserialport,chardev=cid0 -chardev
  socket,id=cid0,host:localhost,port:55298,server,nowait --> DOES NOT WORK
  - meaning I cannot ssh into the vm
  
  Not only does the port  not work, but I am not able to perform any
  serial transfer on port 55298 as well.
  
  The following doesn't work either:
  
  qemu-system-x86_64 -display none -hda archlinux.qcow2 -m 4G -netdev
  user,id=n1,hostfwd=tcp::-:22 -device virtio-net-pci,netdev=n1
  -device virtio-serial -device virtserialport,chardev=cid0 -chardev
  file,id=cid0,path=temp,server,nowait
  
- No matter which character device I use for my virtio-serial-port
+ No matter which character device I use for my virtserialport
  communication (socket or udp or file or pipe), the hostfwd doesn't work.
  
  Host: Windows 10
  Guest: archlinux
  QEMU version 5.2

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1912857

Title:
  virtio-serial blocks hostfwd ssh on windows 10 host

Status in QEMU:
  New

Bug description:
  qemu-system-x86_64
    -display none
    -hda archlinux.qcow2
    -m 4G
    -netdev user,id=n1,hostfwd=tcp::-:22
    -device virtio-net-pci,netdev=n1

  --> THIS WORKS - meaning I can ssh into the vm via port 

  qemu-system-x86_64
    -display none
    -hda archlinux.qcow2
    -m 4G
    -netdev user,id=n1,hostfwd=tcp::-:22
    -device virtio-net-pci,netdev=n1
    -device virtio-serial
    -device virtserialport,chardev=cid0
    -chardev socket,id=cid0,host=localhost,port=55298,server,nowait

  --> DOES NOT WORK - meaning I cannot ssh into the vm

  Not only does the port  not work, but I am not able to perform any
  serial transfer on port 55298 as well.

  The following doesn't work either:

  qemu-system-x86_64
    -display none
    -hda archlinux.qcow2
    -m 4G
    -netdev user,id=n1,hostfwd=tcp::-:22
    -device virtio-net-pci,netdev=n1
    -device virtio-serial 
-device virtserialport,chardev=cid0
    -chardev file,id=cid0,path=temp,server,nowait

  No matter which character device I use for my virtserialport
  communication (socket or udp or file or pipe), the hostfwd doesn't
  work.

  Host: Windows 10
  Guest: archlinux
  QEMU version 5.2

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1912857/+subscriptions



Re: [PATCH v7 05/11] osdep: build with non-working system() function

2021-01-22 Thread Peter Maydell
On Fri, 22 Jan 2021 at 23:12, Peter Maydell  wrote:
>
> On Fri, 22 Jan 2021 at 20:13, Joelle van Dyne  wrote:
> >
> > Build without error on hosts without a working system(). An assertion
> > will trigger if system() is called.
> >
> > Signed-off-by: Joelle van Dyne 
>
>  configure| 19 +++
>
> Can we do the "does system() exist?" check in meson.build ?
> Untested, but looking at the existing check for "does gettid() exist?"
> it should be two lines:
>
> has_system = cc.has_function('system')
>
> and then later:
>
> config_host_data.set('HAVE_SYSTEM_FUNCTION', has_system)

...looking at how we do the HAVE_FOO_H settings, I think we
can just collapse this into one line:

config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system'))

thanks
-- PMM



Re: [PATCH v7 03/11] configure: check for sys/disk.h

2021-01-22 Thread Peter Maydell
On Fri, 22 Jan 2021 at 20:13, Joelle van Dyne  wrote:
>
> Some BSD platforms do not have this header.
>
> Signed-off-by: Joelle van Dyne 
> ---
>  configure  | 9 +
>  block.c| 2 +-
>  block/file-posix.c | 2 +-
>  3 files changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/configure b/configure
> index 32be5d225d..951de427bb 100755
> --- a/configure
> +++ b/configure
> @@ -5295,6 +5295,12 @@ else
>have_host_block_device=no
>  fi
>
> +if check_include "sys/disk.h" ; then
> +  sys_disk_h=yes
> +else
> +  sys_disk_h=no
> +fi
> +
>  ##
>  # End of CC checks
>  # After here, no more $cc or $ld runs
> @@ -5528,6 +5534,9 @@ echo "ARCH=$ARCH" >> $config_host_mak
>  if test "$have_host_block_device" = "yes" ; then
>echo "HAVE_HOST_BLOCK_DEVICE=y" >> $config_host_mak
>  fi
> +if test "$sys_disk_h" = "yes" ; then
> +  echo "HAVE_SYS_DISK_H=y" >> $config_host_mak
> +fi
>  if test "$debug_tcg" = "yes" ; then
>echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
>  fi

We should do this check in meson.build, where it is a one-liner:

config_host_data.set('HAVE_SYS_DISK_H', cc.has_header('sys/disk.h'))

(compare the existing HAVE_PTY_H etc).

thanks
-- PMM



Re: [PATCH v7 04/11] slirp: feature detection for smbd

2021-01-22 Thread Joelle van Dyne
On Fri, Jan 22, 2021 at 2:49 PM Peter Maydell  wrote:
>
> On Fri, 22 Jan 2021 at 20:16, Joelle van Dyne  wrote:
> >
> > Replace Windows specific macro with a more generic feature detection
> > macro. Allows slirp smb feature to be disabled manually as well.
> >
> > Signed-off-by: Joelle van Dyne 
> > ---
>
>
> > +if test "$slirp_smbd" = "yes" ; then
> > +  echo "CONFIG_SLIRP_SMBD=y" >> $config_host_mak
> > +  echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak
> > +fi
>
> This sets "CONFIG_SLIRP_SMBD" and "CONFIG_SMBD_COMMAND"...
>
> >  if test "$vde" = "yes" ; then
> >echo "CONFIG_VDE=y" >> $config_host_mak
> >echo "VDE_LIBS=$vde_libs" >> $config_host_mak
> > diff --git a/meson.build b/meson.build
> > index 6c3ee7f8ca..9577138d7f 100644
> > --- a/meson.build
> > +++ b/meson.build
> > @@ -2331,7 +2331,7 @@ summary_info += {'sphinx-build':  
> > sphinx_build.found()}
> >  summary_info += {'genisoimage':   config_host['GENISOIMAGE']}
> >  # TODO: add back version
> >  summary_info += {'slirp support': slirp_opt == 'disabled' ? false : 
> > slirp_opt}
> > -if slirp_opt != 'disabled'
> > +if slirp_opt != 'disabled' and 'HAVE_HOST_SMBD' in config_host
>
> ...but this is looking for "HAVE_HOST_SMBD". Should it be something else?
Yes, it is a typo, will fix.

-j
>
> >summary_info += {'smbd':config_host['CONFIG_SMBD_COMMAND']}
> >  endif
> >  summary_info += {'module support':
> > config_host.has_key('CONFIG_MODULES')}
>
> thanks
> -- PMM



Re: [PATCH v7 05/11] osdep: build with non-working system() function

2021-01-22 Thread Peter Maydell
On Fri, 22 Jan 2021 at 20:13, Joelle van Dyne  wrote:
>
> Build without error on hosts without a working system(). An assertion
> will trigger if system() is called.
>
> Signed-off-by: Joelle van Dyne 

 configure| 19 +++

Can we do the "does system() exist?" check in meson.build ?
Untested, but looking at the existing check for "does gettid() exist?"
it should be two lines:

has_system = cc.has_function('system')

and then later:

config_host_data.set('HAVE_SYSTEM_FUNCTION', has_system)

> +/**
> + * Platforms which do not support system() gets an assertion failure.
> + */
> +#ifndef HAVE_SYSTEM_FUNCTION
> +#define system platform_does_not_support_system
> +static inline int platform_does_not_support_system(const char *command)
> +{
> +assert(0);
> +}
> +#endif /* !HAVE_SYSTEM_FUNCTION */

I think we should make this return an error code rather than assert:

errno = ENOSYS;
return -1;

In particular, the arm, m68k and nios2 semihosting ABIs presented
to the guest include 'SYSTEM' semihosting calls which we implement
as "call system() with the string the guest hands us". On a
platform without a system() function we want to return an
error to the guest there, not assert.

The other possible approach would be to find all the places
which want to call system() and add suitable ifdeffery to handle
platforms without system:
 * a win32-specific part of the guest-agent (no action needed)
 * net/slirp.c (already handled by the smbd patch in this series)
 * code in tests/ (5 instances)
 * the 3 semihosting uses

But I think providing an always-fails system() is fine.

thanks
-- PMM



[Bug 1912857] Re: virtio-serial blocks hostfwd ssh on windows 10 host

2021-01-22 Thread Ven Karri
** Description changed:

  qemu-system-x86_64 -display none -hda archlinux.qcow2 -m 4G -netdev
  user,id=n1,hostfwd=tcp::-:22 -device virtio-net-pci,netdev=n1 -->
  WORKS - meaning I can ssh into the vm via port 
  
  qemu-system-x86_64 -display none -hda archlinux.qcow2 -m 4G -netdev
  user,id=n1,hostfwd=tcp::-:22 -device virtio-net-pci,netdev=n1
- -device virtio-serial -serial tcp:localhost:55298,server,nowait --> DOES
- NOT WORK - meaning I cannot ssh into the vm
+ -device virtio-serial -device virtserialport,chardev=cid0 -chardev
+ socket,id=cid0,{socket_addr_serial},server,nowait --> DOES NOT WORK -
+ meaning I cannot ssh into the vm
  
  Not only does the port  not work, but I am not able to perform any
  serial transfer on port 55298 as well.
  
  Host: Windows 10
  Guest: archlinux
  QEMU version 5.2

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1912857

Title:
  virtio-serial blocks hostfwd ssh on windows 10 host

Status in QEMU:
  New

Bug description:
  qemu-system-x86_64 -display none -hda archlinux.qcow2 -m 4G -netdev
  user,id=n1,hostfwd=tcp::-:22 -device virtio-net-pci,netdev=n1 -->
  WORKS - meaning I can ssh into the vm via port 

  qemu-system-x86_64 -display none -hda archlinux.qcow2 -m 4G -netdev
  user,id=n1,hostfwd=tcp::-:22 -device virtio-net-pci,netdev=n1
  -device virtio-serial -device virtserialport,chardev=cid0 -chardev
  socket,id=cid0,{socket_addr_serial},server,nowait --> DOES NOT WORK -
  meaning I cannot ssh into the vm

  Not only does the port  not work, but I am not able to perform any
  serial transfer on port 55298 as well.

  Host: Windows 10
  Guest: archlinux
  QEMU version 5.2

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1912857/+subscriptions



Re: [PATCH v7 04/11] slirp: feature detection for smbd

2021-01-22 Thread Peter Maydell
On Fri, 22 Jan 2021 at 20:16, Joelle van Dyne  wrote:
>
> Replace Windows specific macro with a more generic feature detection
> macro. Allows slirp smb feature to be disabled manually as well.
>
> Signed-off-by: Joelle van Dyne 
> ---


> +if test "$slirp_smbd" = "yes" ; then
> +  echo "CONFIG_SLIRP_SMBD=y" >> $config_host_mak
> +  echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak
> +fi

This sets "CONFIG_SLIRP_SMBD" and "CONFIG_SMBD_COMMAND"...

>  if test "$vde" = "yes" ; then
>echo "CONFIG_VDE=y" >> $config_host_mak
>echo "VDE_LIBS=$vde_libs" >> $config_host_mak
> diff --git a/meson.build b/meson.build
> index 6c3ee7f8ca..9577138d7f 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -2331,7 +2331,7 @@ summary_info += {'sphinx-build':  
> sphinx_build.found()}
>  summary_info += {'genisoimage':   config_host['GENISOIMAGE']}
>  # TODO: add back version
>  summary_info += {'slirp support': slirp_opt == 'disabled' ? false : 
> slirp_opt}
> -if slirp_opt != 'disabled'
> +if slirp_opt != 'disabled' and 'HAVE_HOST_SMBD' in config_host

...but this is looking for "HAVE_HOST_SMBD". Should it be something else?

>summary_info += {'smbd':config_host['CONFIG_SMBD_COMMAND']}
>  endif
>  summary_info += {'module support':config_host.has_key('CONFIG_MODULES')}

thanks
-- PMM



Re: [PATCH v7 34/35] Hexagon build infrastructure

2021-01-22 Thread Philippe Mathieu-Daudé
On 1/22/21 11:41 PM, Philippe Mathieu-Daudé wrote:
> On 1/22/21 11:34 PM, Philippe Mathieu-Daudé wrote:
>> On 1/20/21 4:29 AM, Taylor Simpson wrote:
>>> Add file to default-configs
>>> Add hexagon to meson.build
>>> Add hexagon to target/meson.build
>>> Add target/hexagon/meson.build
>>> Change scripts/qemu-binfmt-conf.sh
>>>
>>> We can build a hexagon-linux-user target and run programs on the Hexagon
>>> scalar core.  With hexagon-linux-clang installed, "make check-tcg" will
>>> pass.
>>>
>>> Signed-off-by: Taylor Simpson 
>>> ---
>>>  default-configs/targets/hexagon-linux-user.mak |   1 +
>>>  meson.build|   1 +
>>>  scripts/qemu-binfmt-conf.sh|   6 +-
>>>  target/hexagon/meson.build | 187 
>>> +
>>>  target/meson.build |   1 +
>>>  5 files changed, 195 insertions(+), 1 deletion(-)
>>>  create mode 100644 default-configs/targets/hexagon-linux-user.mak
>>>  create mode 100644 target/hexagon/meson.build
>> ...
> 
> BTW you should test your branch on gitlab-ci, I'm pretty sure
> various jobs fail.

Forgot to paste this link:
https://wiki.qemu.org/Testing/CI/GitLabCI



Re: [PATCH v7 06/11] darwin: remove redundant dependency declaration

2021-01-22 Thread Peter Maydell
On Fri, 22 Jan 2021 at 20:20, Joelle van Dyne  wrote:
>
> Meson will find CoreFoundation, IOKit, and Cocoa as needed.
>
> Signed-off-by: Joelle van Dyne 
> ---
>  configure | 1 -
>  1 file changed, 1 deletion(-)
>
> diff --git a/configure b/configure
> index 82ce28c660..4c485dd962 100755
> --- a/configure
> +++ b/configure
> @@ -781,7 +781,6 @@ Darwin)
>fi
>audio_drv_list="coreaudio try-sdl"
>audio_possible_drivers="coreaudio sdl"
> -  QEMU_LDFLAGS="-framework CoreFoundation -framework IOKit $QEMU_LDFLAGS"
># Disable attempts to use ObjectiveC features in os/object.h since they
># won't work when we're compiling with gcc as a C compiler.
>QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
> --

Reviewed-by: Peter Maydell 

I notice that configure also sets
  coreaudio_libs="-framework CoreAudio"
but that looks like it's something that hasn't yet been moved
into meson.build, so we can't remove it yet.

thanks
-- PMM



Re: [PATCH v7 34/35] Hexagon build infrastructure

2021-01-22 Thread Philippe Mathieu-Daudé
On 1/22/21 11:34 PM, Philippe Mathieu-Daudé wrote:
> On 1/20/21 4:29 AM, Taylor Simpson wrote:
>> Add file to default-configs
>> Add hexagon to meson.build
>> Add hexagon to target/meson.build
>> Add target/hexagon/meson.build
>> Change scripts/qemu-binfmt-conf.sh
>>
>> We can build a hexagon-linux-user target and run programs on the Hexagon
>> scalar core.  With hexagon-linux-clang installed, "make check-tcg" will
>> pass.
>>
>> Signed-off-by: Taylor Simpson 
>> ---
>>  default-configs/targets/hexagon-linux-user.mak |   1 +
>>  meson.build|   1 +
>>  scripts/qemu-binfmt-conf.sh|   6 +-
>>  target/hexagon/meson.build | 187 
>> +
>>  target/meson.build |   1 +
>>  5 files changed, 195 insertions(+), 1 deletion(-)
>>  create mode 100644 default-configs/targets/hexagon-linux-user.mak
>>  create mode 100644 target/hexagon/meson.build
> ...
> 
>> +++ b/target/hexagon/meson.build
>> @@ -0,0 +1,187 @@
>> +##
>> +##  Copyright(c) 2020-2021 Qualcomm Innovation Center, Inc. All Rights 
>> Reserved.
>> +##
>> +##  This program is free software; you can redistribute it and/or modify
>> +##  it under the terms of the GNU General Public License as published by
>> +##  the Free Software Foundation; either version 2 of the License, or
>> +##  (at your option) any later version.
>> +##
>> +##  This program is distributed in the hope that it will be useful,
>> +##  but WITHOUT ANY WARRANTY; without even the implied warranty of
>> +##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> +##  GNU General Public License for more details.
>> +##
>> +##  You should have received a copy of the GNU General Public License
>> +##  along with this program; if not, see .
>> +##
>> +
>> +hexagon_ss = ss.source_set()
>> +
>> +prog_python = import('python').find_installation('python3')
>> +
>> +hex_common_py = 'hex_common.py'
>> +attribs_def_h = meson.current_source_dir() / 'attribs_def.h'
>> +gen_tcg_h = meson.current_source_dir() / 'gen_tcg.h'
>> +
>> +#
>> +#  Step 1
>> +#  We use a C program to create semantics_generated.pyinc
>> +#
>> +gen_semantics = executable('gen_semantics', 'gen_semantics.c')
>> +
>> +semantics = custom_target(
>> +'semantics_generated.pyinc',
>> +output: 'semantics_generated.pyinc',
>> +input: gen_semantics,
>> +command: ['@INPUT@', '@OUTPUT@'],
>> +)
>> +hexagon_ss.add(semantics)
> 
> Is something missing here?
> 
> $ make -j8
> [316/1048] Generating semantics_generated.pyinc with a custom command
> FAILED: target/hexagon/semantics_generated.pyinc
> target/hexagon/gen_semantics target/hexagon/semantics_generated.pyinc
> /bin/sh: 1: target/hexagon/gen_semantics: not found
> ninja: build stopped: subcommand failed.
> 
> $ make target/hexagon/semantics_generated.pyinc V=1
> /usr/bin/ninja -v   -j1  target/hexagon/semantics_generated.pyinc | cat
> [1/1] target/hexagon/gen_semantics target/hexagon/semantics_generated.pyinc
> FAILED: target/hexagon/semantics_generated.pyinc
> target/hexagon/gen_semantics target/hexagon/semantics_generated.pyinc
> /bin/sh: 1: target/hexagon/gen_semantics: not found
> ninja: build stopped: subcommand failed.
> make: *** [Makefile:172: run-ninja] Error 1
> 
> OK, I'm cross-compiling, target/hexagon/gen_semantics has been generated
> but with as target, and we want it linked for the host...

So I compiled it manually using:

$ gcc -o target/hexagon/gen_semantics
~/source/qemu/target/hexagon/gen_semantics.c

Then same story:

[14/68] Generating iset.py with a custom command
FAILED: target/hexagon/iset.py
target/hexagon/gen_dectree_import target/hexagon/iset.py
/bin/sh: 1: target/hexagon/gen_dectree_import: not found
ninja: build stopped: subcommand failed.

$ gcc -o target/hexagon/gen_dectree_import
~/source/qemu/target/hexagon/gen_dectree_import.c
target/hexagon/gen_dectree_import.c:24:10: fatal error: qemu/osdep.h: No
such file or directory
 #include "qemu/osdep.h"
  ^~

It is late here, so enough testing for today. TBC ;)

BTW you should test your branch on gitlab-ci, I'm pretty sure
various jobs fail.

Regards,

Phil.



Re: [PATCH v7 07/11] darwin: fix cross-compiling for Darwin

2021-01-22 Thread Peter Maydell
On Fri, 22 Jan 2021 at 20:18, Joelle van Dyne  wrote:
>
> Add objc to the Meson cross file as well as detection of Darwin.
>
> Signed-off-by: Joelle van Dyne 

Reviewed-by: Peter Maydell 

thanks
-- PMM



Re: [PATCH v7 11/11] darwin: remove 64-bit build detection on 32-bit OS

2021-01-22 Thread Peter Maydell
On Fri, 22 Jan 2021 at 20:16, Joelle van Dyne  wrote:
>
> A workaround added in early days of 64-bit OSX forced x86_64 if the
> host machine had 64-bit support. This creates issues when cross-
> compiling for ARM64. Additionally, the user can always use --cpu=* to
> manually set the host CPU and therefore this workaround should be
> removed.
>
> Signed-off-by: Joelle van Dyne 
> ---
>  configure | 11 ---
>  1 file changed, 11 deletions(-)
>
> diff --git a/configure b/configure
> index fb671258e6..c7fbda22b9 100755
> --- a/configure
> +++ b/configure
> @@ -626,13 +626,6 @@ fi
>  # the correct CPU with the --cpu option.
>  case $targetos in
>  Darwin)
> -  # on Leopard most of the system is 32-bit, so we have to ask the kernel if 
> we can
> -  # run 64-bit userspace code.
> -  # If the user didn't specify a CPU explicitly and the kernel says this is
> -  # 64 bit hw, then assume x86_64. Otherwise fall through to the usual 
> detection code.
> -  if test -z "$cpu" && test "$(sysctl -n hw.optional.x86_64)" = "1"; then
> -cpu="x86_64"
> -  fi
>HOST_DSOSUF=".dylib"
>;;
>  SunOS)

I was just thinking the other day that we could remove this hack...

Reviewed-by: Peter Maydell 

thanks
-- PMM



Re: [PATCH v7 34/35] Hexagon build infrastructure

2021-01-22 Thread Philippe Mathieu-Daudé
On 1/20/21 4:29 AM, Taylor Simpson wrote:
> Add file to default-configs
> Add hexagon to meson.build
> Add hexagon to target/meson.build
> Add target/hexagon/meson.build
> Change scripts/qemu-binfmt-conf.sh
> 
> We can build a hexagon-linux-user target and run programs on the Hexagon
> scalar core.  With hexagon-linux-clang installed, "make check-tcg" will
> pass.
> 
> Signed-off-by: Taylor Simpson 
> ---
>  default-configs/targets/hexagon-linux-user.mak |   1 +
>  meson.build|   1 +
>  scripts/qemu-binfmt-conf.sh|   6 +-
>  target/hexagon/meson.build | 187 
> +
>  target/meson.build |   1 +
>  5 files changed, 195 insertions(+), 1 deletion(-)
>  create mode 100644 default-configs/targets/hexagon-linux-user.mak
>  create mode 100644 target/hexagon/meson.build
...

> +++ b/target/hexagon/meson.build
> @@ -0,0 +1,187 @@
> +##
> +##  Copyright(c) 2020-2021 Qualcomm Innovation Center, Inc. All Rights 
> Reserved.
> +##
> +##  This program is free software; you can redistribute it and/or modify
> +##  it under the terms of the GNU General Public License as published by
> +##  the Free Software Foundation; either version 2 of the License, or
> +##  (at your option) any later version.
> +##
> +##  This program is distributed in the hope that it will be useful,
> +##  but WITHOUT ANY WARRANTY; without even the implied warranty of
> +##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +##  GNU General Public License for more details.
> +##
> +##  You should have received a copy of the GNU General Public License
> +##  along with this program; if not, see .
> +##
> +
> +hexagon_ss = ss.source_set()
> +
> +prog_python = import('python').find_installation('python3')
> +
> +hex_common_py = 'hex_common.py'
> +attribs_def_h = meson.current_source_dir() / 'attribs_def.h'
> +gen_tcg_h = meson.current_source_dir() / 'gen_tcg.h'
> +
> +#
> +#  Step 1
> +#  We use a C program to create semantics_generated.pyinc
> +#
> +gen_semantics = executable('gen_semantics', 'gen_semantics.c')
> +
> +semantics = custom_target(
> +'semantics_generated.pyinc',
> +output: 'semantics_generated.pyinc',
> +input: gen_semantics,
> +command: ['@INPUT@', '@OUTPUT@'],
> +)
> +hexagon_ss.add(semantics)

Is something missing here?

$ make -j8
[316/1048] Generating semantics_generated.pyinc with a custom command
FAILED: target/hexagon/semantics_generated.pyinc
target/hexagon/gen_semantics target/hexagon/semantics_generated.pyinc
/bin/sh: 1: target/hexagon/gen_semantics: not found
ninja: build stopped: subcommand failed.

$ make target/hexagon/semantics_generated.pyinc V=1
/usr/bin/ninja -v   -j1  target/hexagon/semantics_generated.pyinc | cat
[1/1] target/hexagon/gen_semantics target/hexagon/semantics_generated.pyinc
FAILED: target/hexagon/semantics_generated.pyinc
target/hexagon/gen_semantics target/hexagon/semantics_generated.pyinc
/bin/sh: 1: target/hexagon/gen_semantics: not found
ninja: build stopped: subcommand failed.
make: *** [Makefile:172: run-ninja] Error 1

OK, I'm cross-compiling, target/hexagon/gen_semantics has been generated
but with as target, and we want it linked for the host...

Cc'ing Paolo in case he figures the issue simply looking at this patch
:)

Phil.



RE: [PATCH v7 12/35] Hexagon (target/hexagon) instruction attributes

2021-01-22 Thread Taylor Simpson

> -Original Message-
> From: Philippe Mathieu-Daudé  On
> Behalf Of Philippe Mathieu-Daudé
> Sent: Friday, January 22, 2021 11:54 AM
> To: Taylor Simpson ; qemu-devel@nongnu.org
> Cc: richard.hender...@linaro.org; alex.ben...@linaro.org;
> laur...@vivier.eu; a...@rev.ng; Brian Cain 
> Subject: Re: [PATCH v7 12/35] Hexagon (target/hexagon) instruction
> attributes
>
> On 1/20/21 4:28 AM, Taylor Simpson wrote:
> > Signed-off-by: Taylor Simpson 
> > ---
> >  target/hexagon/attribs.h | 30 ++
> >  target/hexagon/attribs_def.h | 95
> 
> >  2 files changed, 125 insertions(+)
> >  create mode 100644 target/hexagon/attribs.h
> >  create mode 100644 target/hexagon/attribs_def.h
> >
> > diff --git a/target/hexagon/attribs.h b/target/hexagon/attribs.h
> > new file mode 100644
> > index 000..e88e5eb
> > --- /dev/null
> > +++ b/target/hexagon/attribs.h
> > @@ -0,0 +1,30 @@
> > +
> > +enum {
> > +#define DEF_ATTRIB(NAME, ...) A_##NAME,
> > +#include "attribs_def.h"
>
> Per QEMU conventions, this file has to be named "attribs_def.h.inc".

Didn't know that.  Which files should end in .inc?

>
> Otherwise:
> Reviewed-by: Philippe Mathieu-Daudé 

Thanks!!




Re: [PATCH] target/mips: fetch code with translator_ld

2021-01-22 Thread Philippe Mathieu-Daudé
On 1/18/21 6:40 PM, Richard Henderson wrote:
> On 1/16/21 8:13 AM, Philippe Mathieu-Daudé wrote:
>> +++ b/target/mips/tlb_helper.c
>> @@ -21,7 +21,7 @@
>>  #include "cpu.h"
>>  #include "internal.h"
>>  #include "exec/exec-all.h"
>> -#include "exec/cpu_ldst.h"
>> +#include "exec/translator.h"
>>  #include "exec/log.h"
>>  #include "hw/mips/cpudevs.h"
>>  
>> @@ -526,9 +526,9 @@ static bool get_pte(CPUMIPSState *env, uint64_t vaddr, 
>> int entry_size,
>>  return false;
>>  }
>>  if (entry_size == 64) {
>> -*pte = cpu_ldq_code(env, vaddr);
>> +*pte = translator_ldq(env, vaddr);
>>  } else {
>> -*pte = cpu_ldl_code(env, vaddr);
>> +*pte = translator_ldl(env, vaddr);
>>  }
>>  return true;
>>  }
> 
> NACK.  This is not within the translator.

Oops...

Thanks for catching this mistake,

Phil.



RE: [PATCH v7 15/35] Hexagon (target/hexagon/arch.[ch]) utility functions

2021-01-22 Thread Taylor Simpson


> -Original Message-
> From: Philippe Mathieu-Daudé  On
> Behalf Of Philippe Mathieu-Daudé
> Sent: Friday, January 22, 2021 12:09 PM
> To: Taylor Simpson ; qemu-devel@nongnu.org
> Cc: richard.hender...@linaro.org; alex.ben...@linaro.org;
> laur...@vivier.eu; a...@rev.ng; Brian Cain 
> Subject: Re: [PATCH v7 15/35] Hexagon (target/hexagon/arch.[ch]) utility
> functions
>
> Hi Taylor,
>
> On 1/20/21 4:28 AM, Taylor Simpson wrote:
> > Signed-off-by: Taylor Simpson 
> > ---
> >  target/hexagon/arch.h |  35 ++
> >  target/hexagon/arch.c | 294
> ++
> >  2 files changed, 329 insertions(+)
> >  create mode 100644 target/hexagon/arch.h
> >  create mode 100644 target/hexagon/arch.c
> >
> > diff --git a/target/hexagon/arch.h b/target/hexagon/arch.h
> > new file mode 100644
> > index 000..a8374a3
> > --- /dev/null
> > +++ b/target/hexagon/arch.h
>
> Maybe rename "arch_utils.[ch]"?

Any particular reason?

>
> > +extern int arch_sf_invsqrt_common(float32 *Rs, float32 *Rd, int *adjust,
> > +  float_status *fp_status);
>
> (Again, no need for 'extern').

OK, I will change these.

> > diff --git a/target/hexagon/arch.c b/target/hexagon/arch.c
> > new file mode 100644
> > index 000..c59cad5
> > --- /dev/null
> > +++ b/target/hexagon/arch.c
> ...
>
> > +#define RAISE_FP_EXCEPTION \
> > +do {} while (0)/* Not modelled in qemu user mode */
>
> I don't understand why... Can you explain please?

Our Linux kernel only sets the relevant bits in USR (user status register).  
The exception isn't raised to user mode.



[PATCHv9 1/3] hw: gpio: implement gpio-pwr driver for qemu reset/poweroff

2021-01-22 Thread Maxim Uvarov
Implement gpio-pwr driver to allow reboot and poweroff machine.
This is simple driver with just 2 gpios lines. Current use case
is to reboot and poweroff virt machine in secure mode. Secure
pl066 gpio chip is needed for that.

Signed-off-by: Maxim Uvarov 
Reviewed-by: Hao Wu 
Reviewed-by: Peter Maydell 
---
 hw/gpio/Kconfig |  3 ++
 hw/gpio/gpio_pwr.c  | 70 +
 hw/gpio/meson.build |  1 +
 3 files changed, 74 insertions(+)
 create mode 100644 hw/gpio/gpio_pwr.c

diff --git a/hw/gpio/Kconfig b/hw/gpio/Kconfig
index b6fdaa2586..f0e7405f6e 100644
--- a/hw/gpio/Kconfig
+++ b/hw/gpio/Kconfig
@@ -8,5 +8,8 @@ config PL061
 config GPIO_KEY
 bool
 
+config GPIO_PWR
+bool
+
 config SIFIVE_GPIO
 bool
diff --git a/hw/gpio/gpio_pwr.c b/hw/gpio/gpio_pwr.c
new file mode 100644
index 00..7714fa0dc4
--- /dev/null
+++ b/hw/gpio/gpio_pwr.c
@@ -0,0 +1,70 @@
+/*
+ * GPIO qemu power controller
+ *
+ * Copyright (c) 2020 Linaro Limited
+ *
+ * Author: Maxim Uvarov 
+ *
+ * Virtual gpio driver which can be used on top of pl061
+ * to reboot and shutdown qemu virtual machine. One of use
+ * case is gpio driver for secure world application (ARM
+ * Trusted Firmware.).
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+/*
+ * QEMU interface:
+ * two named input GPIO lines:
+ *   'reset' : when asserted, trigger system reset
+ *   'shutdown' : when asserted, trigger system shutdown
+ */
+
+#include "qemu/osdep.h"
+#include "hw/sysbus.h"
+#include "sysemu/runstate.h"
+
+#define TYPE_GPIOPWR "gpio-pwr"
+OBJECT_DECLARE_SIMPLE_TYPE(GPIO_PWR_State, GPIOPWR)
+
+struct GPIO_PWR_State {
+SysBusDevice parent_obj;
+};
+
+static void gpio_pwr_reset(void *opaque, int n, int level)
+{
+if (level) {
+qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
+}
+}
+
+static void gpio_pwr_shutdown(void *opaque, int n, int level)
+{
+if (level) {
+qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+}
+}
+
+static void gpio_pwr_init(Object *obj)
+{
+DeviceState *dev = DEVICE(obj);
+
+qdev_init_gpio_in_named(dev, gpio_pwr_reset, "reset", 1);
+qdev_init_gpio_in_named(dev, gpio_pwr_shutdown, "shutdown", 1);
+}
+
+static const TypeInfo gpio_pwr_info = {
+.name  = TYPE_GPIOPWR,
+.parent= TYPE_SYS_BUS_DEVICE,
+.instance_size = sizeof(GPIO_PWR_State),
+.instance_init = gpio_pwr_init,
+};
+
+static void gpio_pwr_register_types(void)
+{
+type_register_static(_pwr_info);
+}
+
+type_init(gpio_pwr_register_types)
diff --git a/hw/gpio/meson.build b/hw/gpio/meson.build
index 5c0a7d7b95..79568f00ce 100644
--- a/hw/gpio/meson.build
+++ b/hw/gpio/meson.build
@@ -1,5 +1,6 @@
 softmmu_ss.add(when: 'CONFIG_E500', if_true: files('mpc8xxx.c'))
 softmmu_ss.add(when: 'CONFIG_GPIO_KEY', if_true: files('gpio_key.c'))
+softmmu_ss.add(when: 'CONFIG_GPIO_PWR', if_true: files('gpio_pwr.c'))
 softmmu_ss.add(when: 'CONFIG_MAX7310', if_true: files('max7310.c'))
 softmmu_ss.add(when: 'CONFIG_PL061', if_true: files('pl061.c'))
 softmmu_ss.add(when: 'CONFIG_PUV3', if_true: files('puv3_gpio.c'))
-- 
2.17.1




[PATCHv9 3/3] arm-virt: add secure pl061 for reset/power down

2021-01-22 Thread Maxim Uvarov
Add secure pl061 for reset/power down machine from
the secure world (Arm Trusted Firmware). Connect it
with gpio-pwr driver.

Signed-off-by: Maxim Uvarov 
Reviewed-by: Andrew Jones 
---
 hw/arm/Kconfig|  1 +
 hw/arm/virt.c | 56 ++-
 include/hw/arm/virt.h |  2 ++
 3 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index 0a242e4c5d..13cc42dcc8 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -17,6 +17,7 @@ config ARM_VIRT
 select PL011 # UART
 select PL031 # RTC
 select PL061 # GPIO
+select GPIO_PWR
 select PLATFORM_BUS
 select SMBIOS
 select VIRTIO_MMIO
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index a135316741..bc99b5419d 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -153,6 +153,7 @@ static const MemMapEntry base_memmap[] = {
 [VIRT_ACPI_GED] =   { 0x0908, ACPI_GED_EVT_SEL_LEN },
 [VIRT_NVDIMM_ACPI] ={ 0x0909, NVDIMM_ACPI_IO_LEN},
 [VIRT_PVTIME] = { 0x090a, 0x0001 },
+[VIRT_SECURE_GPIO] ={ 0x090b, 0x1000 },
 [VIRT_MMIO] =   { 0x0a00, 0x0200 },
 /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */
 [VIRT_PLATFORM_BUS] =   { 0x0c00, 0x0200 },
@@ -841,6 +842,43 @@ static void create_gpio_keys(const VirtMachineState *vms,
"gpios", phandle, 3, 0);
 }
 
+#define SECURE_GPIO_POWEROFF 0
+#define SECURE_GPIO_RESET1
+
+static void create_secure_gpio_pwr(const VirtMachineState *vms,
+   DeviceState *pl061_dev,
+   uint32_t phandle)
+{
+DeviceState *gpio_pwr_dev;
+
+/* gpio-pwr */
+gpio_pwr_dev = sysbus_create_simple("gpio-pwr", -1, NULL);
+
+/* connect secure pl061 to gpio-pwr */
+qdev_connect_gpio_out(pl061_dev, SECURE_GPIO_RESET,
+  qdev_get_gpio_in_named(gpio_pwr_dev, "reset", 0));
+qdev_connect_gpio_out(pl061_dev, SECURE_GPIO_POWEROFF,
+  qdev_get_gpio_in_named(gpio_pwr_dev, "shutdown", 0));
+
+qemu_fdt_add_subnode(vms->fdt, "/gpio-poweroff");
+qemu_fdt_setprop_string(vms->fdt, "/gpio-poweroff", "compatible",
+"gpio-poweroff");
+qemu_fdt_setprop_cells(vms->fdt, "/gpio-poweroff",
+   "gpios", phandle, SECURE_GPIO_POWEROFF, 0);
+qemu_fdt_setprop_string(vms->fdt, "/gpio-poweroff", "status", "disabled");
+qemu_fdt_setprop_string(vms->fdt, "/gpio-poweroff", "secure-status",
+"okay");
+
+qemu_fdt_add_subnode(vms->fdt, "/gpio-restart");
+qemu_fdt_setprop_string(vms->fdt, "/gpio-restart", "compatible",
+"gpio-restart");
+qemu_fdt_setprop_cells(vms->fdt, "/gpio-restart",
+   "gpios", phandle, SECURE_GPIO_RESET, 0);
+qemu_fdt_setprop_string(vms->fdt, "/gpio-restart", "status", "disabled");
+qemu_fdt_setprop_string(vms->fdt, "/gpio-restart", "secure-status",
+"okay");
+}
+
 static void create_gpio_devices(const VirtMachineState *vms, int gpio,
 MemoryRegion *mem)
 {
@@ -873,10 +911,19 @@ static void create_gpio_devices(const VirtMachineState 
*vms, int gpio,
 qemu_fdt_setprop_string(vms->fdt, nodename, "clock-names", "apb_pclk");
 qemu_fdt_setprop_cell(vms->fdt, nodename, "phandle", phandle);
 
+if (gpio != VIRT_GPIO) {
+/* Mark as not usable by the normal world */
+qemu_fdt_setprop_string(vms->fdt, nodename, "status", "disabled");
+qemu_fdt_setprop_string(vms->fdt, nodename, "secure-status", "okay");
+}
 g_free(nodename);
 
 /* Child gpio devices */
-create_gpio_keys(vms, pl061_dev, phandle);
+if (gpio == VIRT_GPIO) {
+create_gpio_keys(vms, pl061_dev, phandle);
+} else {
+create_secure_gpio_pwr(vms, pl061_dev, phandle);
+}
 }
 
 static void create_virtio_devices(const VirtMachineState *vms)
@@ -2008,6 +2055,10 @@ static void machvirt_init(MachineState *machine)
 create_gpio_devices(vms, VIRT_GPIO, sysmem);
 }
 
+if (vms->secure && !vmc->no_secure_gpio) {
+create_gpio_devices(vms, VIRT_SECURE_GPIO, secure_sysmem);
+}
+
  /* connect powerdown request */
  vms->powerdown_notifier.notify = virt_powerdown_req;
  qemu_register_powerdown_notifier(>powerdown_notifier);
@@ -2623,8 +2674,11 @@ DEFINE_VIRT_MACHINE_AS_LATEST(6, 0)
 
 static void virt_machine_5_2_options(MachineClass *mc)
 {
+VirtMachineClass *vmc = VIRT_MACHINE_CLASS(OBJECT_CLASS(mc));
+
 virt_machine_6_0_options(mc);
 compat_props_add(mc->compat_props, hw_compat_5_2, hw_compat_5_2_len);
+vmc->no_secure_gpio = true;
 }
 DEFINE_VIRT_MACHINE(5, 2)
 
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
index abf54fab49..6f6c85ffcf 100644
--- a/include/hw/arm/virt.h

[Bug 1912857] [NEW] virtio-serial blocks hostfwd ssh on windows 10 host

2021-01-22 Thread Ven Karri
Public bug reported:

qemu-system-x86_64 -display none -hda archlinux.qcow2 -m 4G -netdev
user,id=n1,hostfwd=tcp::-:22 -device virtio-net-pci,netdev=n1 -->
WORKS - meaning I can ssh into the vm via port 

qemu-system-x86_64 -display none -hda archlinux.qcow2 -m 4G -netdev
user,id=n1,hostfwd=tcp::-:22 -device virtio-net-pci,netdev=n1
-device virtio-serial -serial tcp:localhost:55298,server,nowait --> DOES
NOT WORK - meaning I cannot ssh into the vm

Not only does the port  not work, but I am not able to perform any
serial transfer on port 55298 as well.

Host: Windows 10
Guest: archlinux
QEMU version 5.2

** Affects: qemu
 Importance: Undecided
 Status: New

** Description changed:

  qemu-system-x86_64 -display none -hda archlinux.qcow2 -m 4G -netdev
  user,id=n1,hostfwd=tcp::-:22 -device virtio-net-pci,netdev=n1 -->
  WORKS - meaning I can ssh into the vm via port 
  
  qemu-system-x86_64 -display none -hda archlinux.qcow2 -m 4G -netdev
  user,id=n1,hostfwd=tcp::-:22 -device virtio-net-pci,netdev=n1
  -device virtio-serial -serial tcp:localhost:55298,server,nowait --> DOES
  NOT WORK - meaning I cannot ssh into the vm
  
- Not only does the port  work, but I am not able to perform any
+ Not only does the port  not work, but I am not able to perform any
  serial transfer on port 55298 as well.
  
  Host: Windows 10
  Guest: archlinux
  QEMU version 5.2

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1912857

Title:
  virtio-serial blocks hostfwd ssh on windows 10 host

Status in QEMU:
  New

Bug description:
  qemu-system-x86_64 -display none -hda archlinux.qcow2 -m 4G -netdev
  user,id=n1,hostfwd=tcp::-:22 -device virtio-net-pci,netdev=n1 -->
  WORKS - meaning I can ssh into the vm via port 

  qemu-system-x86_64 -display none -hda archlinux.qcow2 -m 4G -netdev
  user,id=n1,hostfwd=tcp::-:22 -device virtio-net-pci,netdev=n1
  -device virtio-serial -serial tcp:localhost:55298,server,nowait -->
  DOES NOT WORK - meaning I cannot ssh into the vm

  Not only does the port  not work, but I am not able to perform any
  serial transfer on port 55298 as well.

  Host: Windows 10
  Guest: archlinux
  QEMU version 5.2

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1912857/+subscriptions



[PATCHv9 2/3] arm-virt: refactor gpios creation

2021-01-22 Thread Maxim Uvarov
No functional change. Just refactor code to better
support secure and normal world gpios.

Signed-off-by: Maxim Uvarov 
Reviewed-by: Andrew Jones 
---
 hw/arm/virt.c | 57 ---
 1 file changed, 36 insertions(+), 21 deletions(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 96985917d3..a135316741 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -820,17 +820,43 @@ static void virt_powerdown_req(Notifier *n, void *opaque)
 }
 }
 
-static void create_gpio(const VirtMachineState *vms)
+static void create_gpio_keys(const VirtMachineState *vms,
+ DeviceState *pl061_dev,
+ uint32_t phandle)
+{
+gpio_key_dev = sysbus_create_simple("gpio-key", -1,
+qdev_get_gpio_in(pl061_dev, 3));
+
+qemu_fdt_add_subnode(vms->fdt, "/gpio-keys");
+qemu_fdt_setprop_string(vms->fdt, "/gpio-keys", "compatible", "gpio-keys");
+qemu_fdt_setprop_cell(vms->fdt, "/gpio-keys", "#size-cells", 0);
+qemu_fdt_setprop_cell(vms->fdt, "/gpio-keys", "#address-cells", 1);
+
+qemu_fdt_add_subnode(vms->fdt, "/gpio-keys/poweroff");
+qemu_fdt_setprop_string(vms->fdt, "/gpio-keys/poweroff",
+"label", "GPIO Key Poweroff");
+qemu_fdt_setprop_cell(vms->fdt, "/gpio-keys/poweroff", "linux,code",
+  KEY_POWER);
+qemu_fdt_setprop_cells(vms->fdt, "/gpio-keys/poweroff",
+   "gpios", phandle, 3, 0);
+}
+
+static void create_gpio_devices(const VirtMachineState *vms, int gpio,
+MemoryRegion *mem)
 {
 char *nodename;
 DeviceState *pl061_dev;
-hwaddr base = vms->memmap[VIRT_GPIO].base;
-hwaddr size = vms->memmap[VIRT_GPIO].size;
-int irq = vms->irqmap[VIRT_GPIO];
+hwaddr base = vms->memmap[gpio].base;
+hwaddr size = vms->memmap[gpio].size;
+int irq = vms->irqmap[gpio];
 const char compat[] = "arm,pl061\0arm,primecell";
+SysBusDevice *s;
 
-pl061_dev = sysbus_create_simple("pl061", base,
- qdev_get_gpio_in(vms->gic, irq));
+pl061_dev = qdev_new("pl061");
+s = SYS_BUS_DEVICE(pl061_dev);
+sysbus_realize_and_unref(s, _fatal);
+memory_region_add_subregion(mem, base, sysbus_mmio_get_region(s, 0));
+sysbus_connect_irq(s, 0, qdev_get_gpio_in(vms->gic, irq));
 
 uint32_t phandle = qemu_fdt_alloc_phandle(vms->fdt);
 nodename = g_strdup_printf("/pl061@%" PRIx64, base);
@@ -847,21 +873,10 @@ static void create_gpio(const VirtMachineState *vms)
 qemu_fdt_setprop_string(vms->fdt, nodename, "clock-names", "apb_pclk");
 qemu_fdt_setprop_cell(vms->fdt, nodename, "phandle", phandle);
 
-gpio_key_dev = sysbus_create_simple("gpio-key", -1,
-qdev_get_gpio_in(pl061_dev, 3));
-qemu_fdt_add_subnode(vms->fdt, "/gpio-keys");
-qemu_fdt_setprop_string(vms->fdt, "/gpio-keys", "compatible", "gpio-keys");
-qemu_fdt_setprop_cell(vms->fdt, "/gpio-keys", "#size-cells", 0);
-qemu_fdt_setprop_cell(vms->fdt, "/gpio-keys", "#address-cells", 1);
-
-qemu_fdt_add_subnode(vms->fdt, "/gpio-keys/poweroff");
-qemu_fdt_setprop_string(vms->fdt, "/gpio-keys/poweroff",
-"label", "GPIO Key Poweroff");
-qemu_fdt_setprop_cell(vms->fdt, "/gpio-keys/poweroff", "linux,code",
-  KEY_POWER);
-qemu_fdt_setprop_cells(vms->fdt, "/gpio-keys/poweroff",
-   "gpios", phandle, 3, 0);
 g_free(nodename);
+
+/* Child gpio devices */
+create_gpio_keys(vms, pl061_dev, phandle);
 }
 
 static void create_virtio_devices(const VirtMachineState *vms)
@@ -1990,7 +2005,7 @@ static void machvirt_init(MachineState *machine)
 if (has_ged && aarch64 && firmware_loaded && virt_is_acpi_enabled(vms)) {
 vms->acpi_dev = create_acpi_ged(vms);
 } else {
-create_gpio(vms);
+create_gpio_devices(vms, VIRT_GPIO, sysmem);
 }
 
  /* connect powerdown request */
-- 
2.17.1




[PATCHv9 0/3] arm-virt: add secure pl061 for reset/power down

2021-01-22 Thread Maxim Uvarov
 v9: - cosmetic changes (move if from patch2 to patch3, rename function name
   and define).
 v8: - use gpio 0 and 1, align dtb with kernel gpio-restart, gpio-poweroff,
   change define names, trigger on upper front. (Peter Maydell).
 v7: - same as v6, but resplit patches: patch 2 no function changes and refactor
gpio setup for virt platfrom and patch 3 adds secure gpio.
 v6: - 64k align gpio memory region (Andrew Jones)
 - adjusted memory region to map this address in the corresponding atf patch
 v5: - removed vms flag, added fdt  (Andrew Jones)
 - added patch3 to combine secure and non secure pl061. It has to be
   more easy to review if this changes are in the separate patch.
 v4: rework patches accodring to Peter Maydells comments:
- split patches on gpio-pwr driver and arm-virt integration.
- start secure gpio only from virt-6.0.
- rework qemu interface for gpio-pwr to use 2 named gpio.
- put secure gpio to secure name space.
 v3: added missed include qemu/log.h for qemu_log(.. 
 v2: replace printf with qemu_log (Philippe Mathieu-Daudé)

This patch works together with ATF patch:

https://github.com/muvarov/arm-trusted-firmware/commit/886965bddb0624bdf85103efb2b39fd4eb73d89b

Maxim Uvarov (3):
  hw: gpio: implement gpio-pwr driver for qemu reset/poweroff
  arm-virt: refactor gpios creation
  arm-virt: add secure pl061 for reset/power down

 hw/arm/Kconfig|   1 +
 hw/arm/virt.c | 111 ++
 hw/gpio/Kconfig   |   3 ++
 hw/gpio/gpio_pwr.c|  70 ++
 hw/gpio/meson.build   |   1 +
 include/hw/arm/virt.h |   2 +
 6 files changed, 167 insertions(+), 21 deletions(-)
 create mode 100644 hw/gpio/gpio_pwr.c

-- 
2.17.1




RE: [PATCH v7 07/35] Hexagon (target/hexagon) scalar core helpers

2021-01-22 Thread Taylor Simpson


> -Original Message-
> From: Philippe Mathieu-Daudé  On
> Behalf Of Philippe Mathieu-Daudé
> Sent: Friday, January 22, 2021 2:30 PM
> To: Taylor Simpson ; qemu-devel@nongnu.org
> Cc: richard.hender...@linaro.org; alex.ben...@linaro.org;
> laur...@vivier.eu; a...@rev.ng; Brian Cain 
> Subject: Re: [PATCH v7 07/35] Hexagon (target/hexagon) scalar core helpers
>
> Hi Taylor,
>
> On 1/20/21 4:28 AM, Taylor Simpson wrote:
> > The majority of helpers are generated.  Define the helper functions
> needed
> > then include the generated file
> >
> > Signed-off-by: Taylor Simpson 
> > ---
> >  target/hexagon/helper.h|   85 
> >  target/hexagon/op_helper.c | 1066
> 
> >  2 files changed, 1151 insertions(+)
> >  create mode 100644 target/hexagon/helper.h
> >  create mode 100644 target/hexagon/op_helper.c
> ...
>
> > diff --git a/target/hexagon/op_helper.c b/target/hexagon/op_helper.c
> > new file mode 100644
> > index 000..5186dd1
> > --- /dev/null
> > +++ b/target/hexagon/op_helper.c
> > @@ -0,0 +1,1066 @@
> > +/*
>
> I'm getting:
>
> In file included from ../target/hexagon/op_helper.c:23:
> ../target/hexagon/op_helper.c: In function ‘log_reg_write_pair’:
> ../target/hexagon/op_helper.c:74:19: error: format ‘%ld’ expects
> argument of type ‘long int’, but argument 4 has type ‘int64_t’ {aka
> ‘long long int’} [-Werror=format=]
>74 | HEX_DEBUG_LOG("log_reg_write_pair[%d:%d] = %ld\n", rnum + 1,
> rnum, val);
>   |   ^~~
>~~~
>   |
>|
>   |
>int64_t {aka long long int}
> ../target/hexagon/internal.h:28:22: note: in definition of macro
> ‘HEX_DEBUG_LOG’
>28 | qemu_log(__VA_ARGS__); \
>   |  ^~~
> ../target/hexagon/op_helper.c:74:50: note: format string is defined here
>74 | HEX_DEBUG_LOG("log_reg_write_pair[%d:%d] = %ld\n", rnum + 1,
> rnum, val);
>   |~~^
>   |  |
>   |  long int
>   |%lld
> In file included from ../target/hexagon/op_helper.c:23:
> ../target/hexagon/op_helper.c: In function ‘log_store64’:
> ../target/hexagon/op_helper.c:109:19: error: format ‘%ld’ expects
> argument of type ‘long int’, but argument 4 has type ‘int64_t’ {aka
> ‘long long int’} [-Werror=format=]
>   109 | HEX_DEBUG_LOG("log_store%d(0x" TARGET_FMT_lx ", %ld
> [0x%lx])\n",
>   |   ^~~~
>   110 |width, addr, val, val);
>   | ~~~
>   | |
>   | int64_t {aka long long int}
> ../target/hexagon/internal.h:28:22: note: in definition of macro
> ‘HEX_DEBUG_LOG’
>28 | qemu_log(__VA_ARGS__); \
>   |  ^~~
> ../target/hexagon/op_helper.c:109:19: error: format ‘%lx’ expects
> argument of type ‘long unsigned int’, but argument 5 has type ‘int64_t’
> {aka ‘long long int’} [-Werror=format=]
>   109 | HEX_DEBUG_LOG("log_store%d(0x" TARGET_FMT_lx ", %ld
> [0x%lx])\n",
>   |   ^~~~
>   110 |width, addr, val, val);
>   |  ~~~
>   |  |
>   |  int64_t {aka long long int}
> ../target/hexagon/internal.h:28:22: note: in definition of macro
> ‘HEX_DEBUG_LOG’
>28 | qemu_log(__VA_ARGS__); \
>   |  ^~~
> ../target/hexagon/op_helper.c: In function ‘print_store’:
> ../target/hexagon/op_helper.c:201:27: error: format ‘%lu’ expects
> argument of type ‘long unsigned int’, but argument 3 has type ‘uint64_t’
> {aka ‘long long unsigned int’} [-Werror=format=]
>   201 | HEX_DEBUG_LOG("\tmemd[0x" TARGET_FMT_lx "] = %lu
> (0x%016lx)\n",
>   |   ^~~
>   202 |   env->mem_log_stores[slot].va,
>   203 |   env->mem_log_stores[slot].data64,
>   |   
>   ||
>   |uint64_t {aka
> long long unsigned int}
> ../target/hexagon/internal.h:28:22: note: in definition of macro
> ‘HEX_DEBUG_LOG’
>28 | qemu_log(__VA_ARGS__); \
>   |  ^~~
> ../target/hexagon/op_helper.c:201:27: error: format ‘%lx’ expects
> argument of type ‘long unsigned int’, but argument 4 has type ‘uint64_t’
> {aka ‘long long unsigned int’} [-Werror=format=]
>   201 | HEX_DEBUG_LOG("\tmemd[0x" TARGET_FMT_lx "] = %lu
> (0x%016lx)\n",
>   |   

Re: [PATCH v7 07/35] Hexagon (target/hexagon) scalar core helpers

2021-01-22 Thread Philippe Mathieu-Daudé
On 1/22/21 9:30 PM, Philippe Mathieu-Daudé wrote:
> Hi Taylor,
> 
> On 1/20/21 4:28 AM, Taylor Simpson wrote:
>> The majority of helpers are generated.  Define the helper functions needed
>> then include the generated file
>>
>> Signed-off-by: Taylor Simpson 
>> ---
>>  target/hexagon/helper.h|   85 
>>  target/hexagon/op_helper.c | 1066 
>> 
>>  2 files changed, 1151 insertions(+)
>>  create mode 100644 target/hexagon/helper.h
>>  create mode 100644 target/hexagon/op_helper.c
> ...

> I'm getting:
> 
> In file included from ../target/hexagon/op_helper.c:23:
> ../target/hexagon/op_helper.c: In function ‘log_reg_write_pair’:
> ../target/hexagon/op_helper.c:74:19: error: format ‘%ld’ expects
> argument of type ‘long int’, but argument 4 has type ‘int64_t’ {aka
> ‘long long int’} [-Werror=format=]
>74 | HEX_DEBUG_LOG("log_reg_write_pair[%d:%d] = %ld\n", rnum + 1,
> rnum, val);
>   |   ^~~
>~~~
>   |
>|
>   |
>int64_t {aka long long int}
> ../target/hexagon/internal.h:28:22: note: in definition of macro
> ‘HEX_DEBUG_LOG’
>28 | qemu_log(__VA_ARGS__); \
>   |  ^~~
> ../target/hexagon/op_helper.c:74:50: note: format string is defined here
>74 | HEX_DEBUG_LOG("log_reg_write_pair[%d:%d] = %ld\n", rnum + 1,
> rnum, val);
>   |~~^
>   |  |
>   |  long int
>   |%lld
> In file included from ../target/hexagon/op_helper.c:23:
> ../target/hexagon/op_helper.c: In function ‘log_store64’:
> ../target/hexagon/op_helper.c:109:19: error: format ‘%ld’ expects
> argument of type ‘long int’, but argument 4 has type ‘int64_t’ {aka
> ‘long long int’} [-Werror=format=]
>   109 | HEX_DEBUG_LOG("log_store%d(0x" TARGET_FMT_lx ", %ld [0x%lx])\n",
>   |   ^~~~
>   110 |width, addr, val, val);
>   | ~~~
>   | |
>   | int64_t {aka long long int}
> ../target/hexagon/internal.h:28:22: note: in definition of macro
> ‘HEX_DEBUG_LOG’
>28 | qemu_log(__VA_ARGS__); \
>   |  ^~~
> ../target/hexagon/op_helper.c:109:19: error: format ‘%lx’ expects
> argument of type ‘long unsigned int’, but argument 5 has type ‘int64_t’
> {aka ‘long long int’} [-Werror=format=]
>   109 | HEX_DEBUG_LOG("log_store%d(0x" TARGET_FMT_lx ", %ld [0x%lx])\n",
>   |   ^~~~
>   110 |width, addr, val, val);
>   |  ~~~
>   |  |
>   |  int64_t {aka long long int}
> ../target/hexagon/internal.h:28:22: note: in definition of macro
> ‘HEX_DEBUG_LOG’
>28 | qemu_log(__VA_ARGS__); \
>   |  ^~~
> ../target/hexagon/op_helper.c: In function ‘print_store’:
> ../target/hexagon/op_helper.c:201:27: error: format ‘%lu’ expects
> argument of type ‘long unsigned int’, but argument 3 has type ‘uint64_t’
> {aka ‘long long unsigned int’} [-Werror=format=]
>   201 | HEX_DEBUG_LOG("\tmemd[0x" TARGET_FMT_lx "] = %lu
> (0x%016lx)\n",
>   |   ^~~
>   202 |   env->mem_log_stores[slot].va,
>   203 |   env->mem_log_stores[slot].data64,
>   |   
>   ||
>   |uint64_t {aka
> long long unsigned int}
> ../target/hexagon/internal.h:28:22: note: in definition of macro
> ‘HEX_DEBUG_LOG’
>28 | qemu_log(__VA_ARGS__); \
>   |  ^~~
> ../target/hexagon/op_helper.c:201:27: error: format ‘%lx’ expects
> argument of type ‘long unsigned int’, but argument 4 has type ‘uint64_t’
> {aka ‘long long unsigned int’} [-Werror=format=]
>   201 | HEX_DEBUG_LOG("\tmemd[0x" TARGET_FMT_lx "] = %lu
> (0x%016lx)\n",
>   |   ^~~
> ..
>   204 |   env->mem_log_stores[slot].data64);
>   |   
>   ||
>   |uint64_t {aka
> long long unsigned int}
> ../target/hexagon/internal.h:28:22: note: in definition of macro
> ‘HEX_DEBUG_LOG’
>28 | qemu_log(__VA_ARGS__); \
>   |  ^~~
> 

Fixed with:

-- >8 --
diff --git 

Re: Thread safety of coroutine-sigaltstack

2021-01-22 Thread Laszlo Ersek
On 01/22/21 22:34, Laszlo Ersek wrote:
> On 01/22/21 21:38, Laszlo Ersek wrote:

>> The behavior of "savemask=0" is a platform trait that platforms are not
>> required to document (the behavior is unspecified, not
>> implementation-defined), so it really boils down to where this code
>> actually runs...
>>
>> NB Linux is more specific:
>>
>> https://man7.org/linux/man-pages/man3/setjmp.3.html
>>
>>sigsetjmp() and siglongjmp()
>>sigsetjmp() and siglongjmp() also perform nonlocal gotos, but
>>provide predictable handling of the process signal mask.
>>
>>If, and only if, the savesigs argument provided to sigsetjmp() is
>>nonzero, the process's current signal mask is saved in env and
>>will be restored if a siglongjmp() is later performed with this
>>env.
>>
>> Cue "and only if".
> 
> ... I notice commit 6ab7e5465a4d ("Replace all setjmp()/longjmp() with
> sigsetjmp()/siglongjmp()", 2013-02-23) chose the Linux definition, not
> the POSIX one.

My bad: the commit message is correct. While the effect of savemask=0 is
indeed unspecified for sigsetjmp(), it is completely defined for
siglongjmp().

https://pubs.opengroup.org/onlinepubs/9699919799/functions/siglongjmp.html

Commit 6ab7e5465a4d even carries my R-b :/

Sorry about the noise,
Laszlo




Re: [PATCH 19/25] hw/timer/cmsdk-apb-dualtimer: Convert to use Clock input

2021-01-22 Thread Peter Maydell
On Fri, 22 Jan 2021 at 20:48, Luc Michel  wrote:
>
> On 19:06 Thu 21 Jan , Peter Maydell wrote:
> > Switch the CMSDK APB dualtimer device over to using its Clock input;
> > the pclk-frq property is now ignored.
> >
> > Signed-off-by: Peter Maydell 
> > ---
> >  hw/timer/cmsdk-apb-dualtimer.c | 42 ++
> >  1 file changed, 37 insertions(+), 5 deletions(-)
> >
> > diff --git a/hw/timer/cmsdk-apb-dualtimer.c b/hw/timer/cmsdk-apb-dualtimer.c
> > index 781b496037b..828127b366f 100644
> > --- a/hw/timer/cmsdk-apb-dualtimer.c
> > +++ b/hw/timer/cmsdk-apb-dualtimer.c
> > @@ -106,6 +106,22 @@ static void 
> > cmsdk_apb_dualtimer_update(CMSDKAPBDualTimer *s)
> >  qemu_set_irq(s->timerintc, timintc);
> >  }
> >
> > +static int cmsdk_dualtimermod_divisor(CMSDKAPBDualTimerModule *m)
> > +{
> > +/* Return the divisor set by the current CONTROL.PRESCALE value */
> > +switch (FIELD_EX32(m->control, CONTROL, PRESCALE)) {
> > +case 0:
> > +return 1;
> > +case 1:
> > +return 16;
> > +case 2:
> > +case 3: /* UNDEFINED, we treat like 2 (and complained when it was set) 
> > */
> > +return 256;
> > +default:
> > +g_assert_not_reached();
> > +}
> > +}
> > +
> >  static void cmsdk_dualtimermod_write_control(CMSDKAPBDualTimerModule *m,
> >   uint32_t newctrl)
> >  {
> > @@ -146,7 +162,7 @@ static void 
> > cmsdk_dualtimermod_write_control(CMSDKAPBDualTimerModule *m,
> >  default:
> >  g_assert_not_reached();
> >  }
> > -ptimer_set_freq(m->timer, m->parent->pclk_frq / divisor);
> > +ptimer_set_period_from_clock(m->timer, m->parent->timclk, divisor);
>
> Just a small cosmetic note, maybe you can use your new
> cmsdk_dualtimermod_divisor function to factor out the switch above?
> Something like:
>
> if (changed & R_CONTROL_PRESCALE_MASK) {
> if (FIELD_EX32(newctrl, CONTROL, PRESCALE) == 3) {
> qemu_log_mask(LOG_GUEST_ERROR,
>   "CMSDK APB dual-timer: CONTROL.PRESCALE==0b11"
>   " is undefined behaviour\n");
> }
>
> ptimer_set_period_from_clock(m->timer, m->parent->timclk,
>  cmsdk_dualtimermod_divisor(m));
> }

Nope, because cmsdk_dualtimermod_divisor() uses the current
m->control value, and at this point in the code we need the
divisor from the new control value which isn't in m->control yet.
I liked the slight duplication better than either having to
pass m->control in in all the other callsites or trying to
refactor the control write handling so that m->control is
updated before this point in the code.

thanks
-- PMM



Re: Thread safety of coroutine-sigaltstack

2021-01-22 Thread Laszlo Ersek
On 01/22/21 21:38, Laszlo Ersek wrote:
> On 01/21/21 18:24, Paolo Bonzini wrote:
>> On 21/01/21 17:44, Peter Maydell wrote:
>>> On Thu, 21 Jan 2021 at 16:10, Daniel P. Berrangé 
>>> wrote:
 FWIW The libucontext impl is all ASM based and has coverage for all the
 arches we care about:

     https://github.com/kaniini/libucontext

 so doesn't seem like there's a need for  coroutine-asm if we can rely
 on libucontext for portability where neede.
>>>
>>> The README for that notes a couple of pretty major omissions:
>>>   * it doesn't handle floating point registers
>>>   * it doesn't do anything about the signal mask
>>> I'm pretty sure that not handling the fp regs could cause breakage
>>> for Arm at least (depending on what the compiler chooses to do
>>> in the functions that work with the ucontext functions). The
>>> signal mask stuff might be OK for us because of the carefully
>>> limited use we make of the ucontext functions, but it would be
>>> a bit of a pain to have to analyse that code for both sets of semantics.
>>
>> The lack of signal mask handling is an improvement for us. :)  We want
>> the signal mask to be per thread, not per coroutine.
> 
> I didn't quite get this when I first read it, but now that I'm digging
> through the code, I have a follow-up comment.
> 
> According to POSIX, passing savemask=0 to sigsetjmp() may or may not
> save the current signal mask, into "env". A nonzero savemask is required
> to save the signal mask, but a zero savemask is not forbidden to -- it
> is only not required to:
> 
> https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigsetjmp.html#tag_16_554_07
> 
> Note that since this function is defined in terms of setjmp(), if
> savemask is zero, it is unspecified whether the signal mask is
> saved.
> 
> And I feel that's a bit of a problem, because when we first exit the
> trampoline -- executed as a signal handler -- via sigsetjmp(), *all
> signals* are masked, and sigsetjmp might actually stash that mask in
> "tr_reenter", because savemask=0 does not suffice for forbidding that.
> 
> When we reenter the trampoline via siglongjmp(tr_reenter), and
> subsequently call coroutine_bootstrap(), it's possible (per POSIX, see
> above) that all signals are masked again. And then that could further be
> remembered in "self->env", in coroutine_bootstrap(). Which would be
> wrong IMO; co-routines in general should receive synchronous signals if
> they mess up somewhere (terminating the process).
> 
> IOW, just before the call to coroutine_bootstrap(),
> coroutine_trampoline() should explicitly restore the signal mask that
> was in effect when qemu_coroutine_new() was entered.
> 
> Has this been a problem in practice, or should we ignore it?
> 
> IOW, should we assume "savemask=0" for *never* saving the signal mask?
> 
> The behavior of "savemask=0" is a platform trait that platforms are not
> required to document (the behavior is unspecified, not
> implementation-defined), so it really boils down to where this code
> actually runs...
> 
> NB Linux is more specific:
> 
> https://man7.org/linux/man-pages/man3/setjmp.3.html
> 
>sigsetjmp() and siglongjmp()
>sigsetjmp() and siglongjmp() also perform nonlocal gotos, but
>provide predictable handling of the process signal mask.
> 
>If, and only if, the savesigs argument provided to sigsetjmp() is
>nonzero, the process's current signal mask is saved in env and
>will be restored if a siglongjmp() is later performed with this
>env.
> 
> Cue "and only if".

... I notice commit 6ab7e5465a4d ("Replace all setjmp()/longjmp() with
sigsetjmp()/siglongjmp()", 2013-02-23) chose the Linux definition, not
the POSIX one.

Thanks
Laszlo




Re: [PATCH 3/4] hw/riscv: virt: Limit RAM size in a 32-bit system

2021-01-22 Thread Alistair Francis
On Fri, Jan 22, 2021 at 4:34 AM Bin Meng  wrote:
>
> From: Bin Meng 
>
> RV32 supports 34-bit physical address hence the maximum RAM size
> should be limitted. Limit the RAM size to 10 GiB, which leaves
> some room for PCIe high mmio space.
>
> Signed-off-by: Bin Meng 

Reviewed-by: Alistair Francis 

Alistair

> ---
>
>  hw/riscv/virt.c | 13 +
>  1 file changed, 13 insertions(+)
>
> diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
> index 1d05bb3ef9..4f44509360 100644
> --- a/hw/riscv/virt.c
> +++ b/hw/riscv/virt.c
> @@ -590,6 +590,19 @@ static void virt_machine_init(MachineState *machine)
>  }
>  }
>
> +/* limit RAM size in a 32-bit system */
> +if (riscv_is_32bit(>soc[0])) {
> +/*
> + * Cast machine->ram_size to 64-bit for 32-bit host,
> + * to make the build on 32-bit host happy.
> + */
> +if ((uint64_t)(machine->ram_size) > 10 * GiB) {
> +/* 32-bit host won't have a chance to execute here */
> +machine->ram_size = 10 * GiB;
> +error_report("Limitting RAM size to 10 GiB");
> +}
> +}
> +
>  /* register system main memory (actual RAM) */
>  memory_region_init_ram(main_mem, NULL, "riscv_virt_board.ram",
> machine->ram_size, _fatal);
> --
> 2.25.1
>
>



Re: [PATCH] coroutine-sigaltstack: Keep SIGUSR2 handler up

2021-01-22 Thread Laszlo Ersek
On 01/22/21 19:29, Laszlo Ersek wrote:

> OK, I'll try my hand at it; I hope I won't be eating my words.

The more I look at it, the less comfortable I am with the existent code.

For example, I don't understand why the original commit -- 3194c8ceeba0,
"coroutine: adding sigaltstack method (.c source)", 2012-03-12 --
wrapped the sigsuspend() in a loop, dependent on the "tr_called" flag.
That looks like a platform bug workaround -- it suggests that
sigsuspend() could wake spuriously, i.e., not in response to the pending
SIGUSR2.

That seems bogus, per POSIX, given that all signals except SIGUSR2 are
included in the mask passed to sigsuspend().

https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigsuspend.html

Also, the comment says, "the signal can be delivered the first time
sigsuspend() is called", which is misleading -- the signal *IS*
delivered the first time sigsuspend() is called, given that we call
pthread_kill(pthread_self()) just before, with SIGUSR2 masked. So by the
time we reach sigsuspend(), the signal is pending.

(The synchronous nature of pthread_kill(pthread_self()) is confirmed by:

https://pubs.opengroup.org/onlinepubs/9699919799/functions/raise.html

which explains (a) the equivalence of raise() with
pthread_kill(pthread_self()), and (b) the fact that raise() does not
return until after the signal handler does, if a signal handler is
called. Given that delivery is dependent on generation, and delivery is
synchronous per description, generation *cannot* be asynchronous.)

All of this makes me super uncomfortable with the code. Either the
platform(s) where it was written & tested did not conform to POSIX, or
the original author missed something, or *I* am missing something. In
each case, I should not be modifying this code; I'm flying blind.

I'm drifting towards an overhaul of coroutine-sigaltstack, based on my
personal understanding of POSIX, but given that I can absolutely not
*test* coroutine-sigaltstack on the platforms where it actually matters,
an "overhaul" by me would be reckless.

I didn't expect these skeletons when I first read Max's "Thread safety
of coroutine-sigaltstack" email :/

Max, after having worked on top of your patch for a few hours, I
officially endorse your mutex approach. I can't encourage you or myself
to touch this code, in good conscience. It's not that it's "bad"; it's
inexplicable and (to me) untestable.

Laszlo




Re: [PATCH 2/4] hw/riscv: virt: Drop the 'link_up' parameter of gpex_pcie_init()

2021-01-22 Thread Alistair Francis
On Fri, Jan 22, 2021 at 4:32 AM Bin Meng  wrote:
>
> From: Bin Meng 
>
> `link_up` is never used in gpex_pcie_init(). Drop it.
>
> Signed-off-by: Bin Meng 

Reviewed-by: Alistair Francis 

Alistair

> ---
>
>  hw/riscv/virt.c | 14 +++---
>  1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
> index cfd52bc59b..1d05bb3ef9 100644
> --- a/hw/riscv/virt.c
> +++ b/hw/riscv/virt.c
> @@ -449,7 +449,7 @@ static inline DeviceState *gpex_pcie_init(MemoryRegion 
> *sys_mem,
>hwaddr ecam_base, hwaddr ecam_size,
>hwaddr mmio_base, hwaddr mmio_size,
>hwaddr pio_base,
> -  DeviceState *plic, bool link_up)
> +  DeviceState *plic)
>  {
>  DeviceState *dev;
>  MemoryRegion *ecam_alias, *ecam_reg;
> @@ -669,12 +669,12 @@ static void virt_machine_init(MachineState *machine)
>  }
>
>  gpex_pcie_init(system_memory,
> - memmap[VIRT_PCIE_ECAM].base,
> - memmap[VIRT_PCIE_ECAM].size,
> - memmap[VIRT_PCIE_MMIO].base,
> - memmap[VIRT_PCIE_MMIO].size,
> - memmap[VIRT_PCIE_PIO].base,
> - DEVICE(pcie_plic), true);
> +   memmap[VIRT_PCIE_ECAM].base,
> +   memmap[VIRT_PCIE_ECAM].size,
> +   memmap[VIRT_PCIE_MMIO].base,
> +   memmap[VIRT_PCIE_MMIO].size,
> +   memmap[VIRT_PCIE_PIO].base,
> +   DEVICE(pcie_plic));
>
>  serial_mm_init(system_memory, memmap[VIRT_UART0].base,
>  0, qdev_get_gpio_in(DEVICE(mmio_plic), UART0_IRQ), 399193,
> --
> 2.25.1
>
>



Re: [PATCH 1/4] hw/riscv: Drop 'struct MemmapEntry'

2021-01-22 Thread Alistair Francis
On Fri, Jan 22, 2021 at 4:31 AM Bin Meng  wrote:
>
> From: Bin Meng 
>
> There is already a MemMapEntry type defined in hwaddr.h. Let's drop
> the RISC-V defined `struct MemmapEntry` and use the existing one.
>
> Signed-off-by: Bin Meng 

Reviewed-by: Alistair Francis 

Alistair

> ---
>
>  hw/riscv/microchip_pfsoc.c |  9 +++--
>  hw/riscv/opentitan.c   |  9 +++--
>  hw/riscv/sifive_e.c|  9 +++--
>  hw/riscv/sifive_u.c| 11 ---
>  hw/riscv/spike.c   |  9 +++--
>  hw/riscv/virt.c|  9 +++--
>  6 files changed, 19 insertions(+), 37 deletions(-)
>
> diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c
> index e952b49e8c..266f1c3342 100644
> --- a/hw/riscv/microchip_pfsoc.c
> +++ b/hw/riscv/microchip_pfsoc.c
> @@ -86,10 +86,7 @@
>   *   - Register Map/PF_SoC_RegMap_V1_1/MPFS250T/mpfs250t_ioscb_memmap_dri.htm
>   * describes the complete IOSCB modules memory maps
>   */
> -static const struct MemmapEntry {
> -hwaddr base;
> -hwaddr size;
> -} microchip_pfsoc_memmap[] = {
> +static const MemMapEntry microchip_pfsoc_memmap[] = {
>  [MICROCHIP_PFSOC_RSVD0] =   {0x0,  0x100 },
>  [MICROCHIP_PFSOC_DEBUG] =   {  0x100,  0xf00 },
>  [MICROCHIP_PFSOC_E51_DTIM] ={  0x100, 0x2000 },
> @@ -182,7 +179,7 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, 
> Error **errp)
>  {
>  MachineState *ms = MACHINE(qdev_get_machine());
>  MicrochipPFSoCState *s = MICROCHIP_PFSOC(dev);
> -const struct MemmapEntry *memmap = microchip_pfsoc_memmap;
> +const MemMapEntry *memmap = microchip_pfsoc_memmap;
>  MemoryRegion *system_memory = get_system_memory();
>  MemoryRegion *rsvd0_mem = g_new(MemoryRegion, 1);
>  MemoryRegion *e51_dtim_mem = g_new(MemoryRegion, 1);
> @@ -451,7 +448,7 @@ type_init(microchip_pfsoc_soc_register_types)
>  static void microchip_icicle_kit_machine_init(MachineState *machine)
>  {
>  MachineClass *mc = MACHINE_GET_CLASS(machine);
> -const struct MemmapEntry *memmap = microchip_pfsoc_memmap;
> +const MemMapEntry *memmap = microchip_pfsoc_memmap;
>  MicrochipIcicleKitState *s = MICROCHIP_ICICLE_KIT_MACHINE(machine);
>  MemoryRegion *system_memory = get_system_memory();
>  MemoryRegion *mem_low = g_new(MemoryRegion, 1);
> diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c
> index af3456932f..e168bffe69 100644
> --- a/hw/riscv/opentitan.c
> +++ b/hw/riscv/opentitan.c
> @@ -28,10 +28,7 @@
>  #include "qemu/units.h"
>  #include "sysemu/sysemu.h"
>
> -static const struct MemmapEntry {
> -hwaddr base;
> -hwaddr size;
> -} ibex_memmap[] = {
> +static const MemMapEntry ibex_memmap[] = {
>  [IBEX_DEV_ROM] ={  0x8000, 16 * KiB },
>  [IBEX_DEV_RAM] ={  0x1000,  0x1 },
>  [IBEX_DEV_FLASH] =  {  0x2000,  0x8 },
> @@ -66,7 +63,7 @@ static const struct MemmapEntry {
>
>  static void opentitan_board_init(MachineState *machine)
>  {
> -const struct MemmapEntry *memmap = ibex_memmap;
> +const MemMapEntry *memmap = ibex_memmap;
>  OpenTitanState *s = g_new0(OpenTitanState, 1);
>  MemoryRegion *sys_mem = get_system_memory();
>  MemoryRegion *main_mem = g_new(MemoryRegion, 1);
> @@ -114,7 +111,7 @@ static void lowrisc_ibex_soc_init(Object *obj)
>
>  static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp)
>  {
> -const struct MemmapEntry *memmap = ibex_memmap;
> +const MemMapEntry *memmap = ibex_memmap;
>  MachineState *ms = MACHINE(qdev_get_machine());
>  LowRISCIbexSoCState *s = RISCV_IBEX_SOC(dev_soc);
>  MemoryRegion *sys_mem = get_system_memory();
> diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c
> index 59bac4cc9a..f939bcf9ea 100644
> --- a/hw/riscv/sifive_e.c
> +++ b/hw/riscv/sifive_e.c
> @@ -50,10 +50,7 @@
>  #include "sysemu/sysemu.h"
>  #include "exec/address-spaces.h"
>
> -static const struct MemmapEntry {
> -hwaddr base;
> -hwaddr size;
> -} sifive_e_memmap[] = {
> +static MemMapEntry sifive_e_memmap[] = {
>  [SIFIVE_E_DEV_DEBUG] ={0x0, 0x1000 },
>  [SIFIVE_E_DEV_MROM] = { 0x1000, 0x2000 },
>  [SIFIVE_E_DEV_OTP] =  {0x2, 0x2000 },
> @@ -77,7 +74,7 @@ static const struct MemmapEntry {
>
>  static void sifive_e_machine_init(MachineState *machine)
>  {
> -const struct MemmapEntry *memmap = sifive_e_memmap;
> +const MemMapEntry *memmap = sifive_e_memmap;
>
>  SiFiveEState *s = RISCV_E_MACHINE(machine);
>  MemoryRegion *sys_mem = get_system_memory();
> @@ -187,7 +184,7 @@ static void sifive_e_soc_init(Object *obj)
>  static void sifive_e_soc_realize(DeviceState *dev, Error **errp)
>  {
>  MachineState *ms = MACHINE(qdev_get_machine());
> -const struct MemmapEntry *memmap = sifive_e_memmap;
> +const MemMapEntry *memmap = sifive_e_memmap;
>  SiFiveESoCState *s = RISCV_E_SOC(dev);
> 

Re: [PATCH v2 2/3] target/arm: Add support for FEAT_DIT, Data Independent Timing

2021-01-22 Thread Richard Henderson
On 1/21/21 6:45 PM, Rebecca Cran wrote:
> Add support for FEAT_DIT. DIT (Data Independent Timing) is a required
> feature for ARMv8.4. Since virtual machine execution is largely
> nondeterministic and TCG is outside of the security domain, it's
> implemented as a NOP.
> 
> Signed-off-by: Rebecca Cran 
> ---
>  target/arm/cpu.h   | 12 +++
>  target/arm/helper.c| 22 
>  target/arm/internals.h |  6 ++
>  target/arm/translate-a64.c | 12 +++
>  4 files changed, 52 insertions(+)

Reviewed-by: Richard Henderson 

r~



Re: [PATCH v2 3/3] target/arm: Set ID_AA64PFR0.DIT and ID_PFR0.DIT to 1 for "max" AA64 CPU

2021-01-22 Thread Richard Henderson
On 1/21/21 6:45 PM, Rebecca Cran wrote:
> Enable FEAT_DIT for the "max" AARCH64 CPU.
> 
> Signed-off-by: Rebecca Cran 
> Reviewed-by: Richard Henderson 
> ---
>  target/arm/cpu64.c | 5 +
>  1 file changed, 5 insertions(+)

There is also a 32-bit "max" cpu in cpu.c.


r~



Re: [PATCH v2 1/3] target/arm: Remove PSTATE_SS from cpsr and move it into env->pstate.

2021-01-22 Thread Richard Henderson
On 1/21/21 6:45 PM, Rebecca Cran wrote:
> cpsr has been treated as being the same as spsr, but it isn't.
> Since PSTATE_SS isn't in cpsr, remove it and move it into env->pstate.
> 
> Signed-off-by: Rebecca Cran 
> ---
>  target/arm/helper-a64.c | 4 +---
>  target/arm/helper.c | 4 ++--
>  target/arm/op_helper.c  | 9 +
>  3 files changed, 4 insertions(+), 13 deletions(-)
> 
> diff --git a/target/arm/helper-a64.c b/target/arm/helper-a64.c
> index c426c23d2c4e..0d2ac7bb7ee3 100644
> --- a/target/arm/helper-a64.c
> +++ b/target/arm/helper-a64.c
> @@ -1000,9 +1000,7 @@ void HELPER(exception_return)(CPUARMState *env, 
> uint64_t new_pc)
>   */
>  mask = aarch32_cpsr_valid_mask(env->features, 
> _archcpu(env)->isar);
>  cpsr_write(env, spsr, mask, CPSRWriteRaw);
> -if (!arm_singlestep_active(env)) {
> -env->uncached_cpsr &= ~PSTATE_SS;
> -}
> +env->pstate &= ~PSTATE_SS;

Why are you removing the singlestep check?

>  aarch64_sync_64_to_32(env);
>  
>  if (spsr & CPSR_T) {
> diff --git a/target/arm/helper.c b/target/arm/helper.c
> index d2ead3fcbdbd..01b50316046b 100644
> --- a/target/arm/helper.c
> +++ b/target/arm/helper.c
> @@ -9402,8 +9402,8 @@ static void take_aarch32_exception(CPUARMState *env, 
> int new_mode,
>   * For exceptions taken to AArch32 we must clear the SS bit in both
>   * PSTATE and in the old-state value we save to SPSR_, so zero it 
> now.
>   */
> -env->uncached_cpsr &= ~PSTATE_SS;
> -env->spsr = cpsr_read(env);
> +env->pstate &= ~PSTATE_SS;
> +env->spsr &= ~PSTATE_SS;

This loses the saving of cpsr into spsr.


r~



Re: [PATCH v1 2/3] target/microblaze: use MMUAccessType instead of int in mmu_translate

2021-01-22 Thread Richard Henderson
On 1/21/21 2:18 PM, Joe Komlodi wrote:
> Using MMUAccessType makes it more clear what the variable's use is.
> No functional change.
> 
> Signed-off-by: Joe Komlodi 
> ---
>  target/microblaze/mmu.c | 2 +-
>  target/microblaze/mmu.h | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson 

r~



Re: [PATCH 20/25] hw/watchdog/cmsdk-apb-watchdog: Convert to use Clock input

2021-01-22 Thread Luc Michel
On 19:06 Thu 21 Jan , Peter Maydell wrote:
> Switch the CMSDK APB watchdog device over to using its Clock input;
> the wdogclk_frq property is now ignored.
> 
> Signed-off-by: Peter Maydell 

Reviewed-by: Luc Michel 

> ---
>  hw/watchdog/cmsdk-apb-watchdog.c | 18 ++
>  1 file changed, 14 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/watchdog/cmsdk-apb-watchdog.c 
> b/hw/watchdog/cmsdk-apb-watchdog.c
> index b03bcb73628..9cad0c67da4 100644
> --- a/hw/watchdog/cmsdk-apb-watchdog.c
> +++ b/hw/watchdog/cmsdk-apb-watchdog.c
> @@ -310,6 +310,15 @@ static void cmsdk_apb_watchdog_reset(DeviceState *dev)
>  ptimer_transaction_commit(s->timer);
>  }
>  
> +static void cmsdk_apb_watchdog_clk_update(void *opaque)
> +{
> +CMSDKAPBWatchdog *s = CMSDK_APB_WATCHDOG(opaque);
> +
> +ptimer_transaction_begin(s->timer);
> +ptimer_set_period_from_clock(s->timer, s->wdogclk, 1);
> +ptimer_transaction_commit(s->timer);
> +}
> +
>  static void cmsdk_apb_watchdog_init(Object *obj)
>  {
>  SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
> @@ -319,7 +328,8 @@ static void cmsdk_apb_watchdog_init(Object *obj)
>s, "cmsdk-apb-watchdog", 0x1000);
>  sysbus_init_mmio(sbd, >iomem);
>  sysbus_init_irq(sbd, >wdogint);
> -s->wdogclk = qdev_init_clock_in(DEVICE(s), "WDOGCLK", NULL, NULL);
> +s->wdogclk = qdev_init_clock_in(DEVICE(s), "WDOGCLK",
> +cmsdk_apb_watchdog_clk_update, s);
>  
>  s->is_luminary = false;
>  s->id = cmsdk_apb_watchdog_id;
> @@ -329,9 +339,9 @@ static void cmsdk_apb_watchdog_realize(DeviceState *dev, 
> Error **errp)
>  {
>  CMSDKAPBWatchdog *s = CMSDK_APB_WATCHDOG(dev);
>  
> -if (s->wdogclk_frq == 0) {
> +if (!clock_has_source(s->wdogclk)) {
>  error_setg(errp,
> -   "CMSDK APB watchdog: wdogclk-frq property must be set");
> +   "CMSDK APB watchdog: WDOGCLK clock must be connected");
>  return;
>  }
>  
> @@ -342,7 +352,7 @@ static void cmsdk_apb_watchdog_realize(DeviceState *dev, 
> Error **errp)
> PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
>  
>  ptimer_transaction_begin(s->timer);
> -ptimer_set_freq(s->timer, s->wdogclk_frq);
> +ptimer_set_period_from_clock(s->timer, s->wdogclk, 1);
>  ptimer_transaction_commit(s->timer);
>  }
>  
> -- 
> 2.20.1
> 

-- 



Re: [PATCH 19/25] hw/timer/cmsdk-apb-dualtimer: Convert to use Clock input

2021-01-22 Thread Luc Michel
On 19:06 Thu 21 Jan , Peter Maydell wrote:
> Switch the CMSDK APB dualtimer device over to using its Clock input;
> the pclk-frq property is now ignored.
> 
> Signed-off-by: Peter Maydell 
> ---
>  hw/timer/cmsdk-apb-dualtimer.c | 42 ++
>  1 file changed, 37 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/timer/cmsdk-apb-dualtimer.c b/hw/timer/cmsdk-apb-dualtimer.c
> index 781b496037b..828127b366f 100644
> --- a/hw/timer/cmsdk-apb-dualtimer.c
> +++ b/hw/timer/cmsdk-apb-dualtimer.c
> @@ -106,6 +106,22 @@ static void cmsdk_apb_dualtimer_update(CMSDKAPBDualTimer 
> *s)
>  qemu_set_irq(s->timerintc, timintc);
>  }
>  
> +static int cmsdk_dualtimermod_divisor(CMSDKAPBDualTimerModule *m)
> +{
> +/* Return the divisor set by the current CONTROL.PRESCALE value */
> +switch (FIELD_EX32(m->control, CONTROL, PRESCALE)) {
> +case 0:
> +return 1;
> +case 1:
> +return 16;
> +case 2:
> +case 3: /* UNDEFINED, we treat like 2 (and complained when it was set) */
> +return 256;
> +default:
> +g_assert_not_reached();
> +}
> +}
> +
>  static void cmsdk_dualtimermod_write_control(CMSDKAPBDualTimerModule *m,
>   uint32_t newctrl)
>  {
> @@ -146,7 +162,7 @@ static void 
> cmsdk_dualtimermod_write_control(CMSDKAPBDualTimerModule *m,
>  default:
>  g_assert_not_reached();
>  }
> -ptimer_set_freq(m->timer, m->parent->pclk_frq / divisor);
> +ptimer_set_period_from_clock(m->timer, m->parent->timclk, divisor);

Just a small cosmetic note, maybe you can use your new
cmsdk_dualtimermod_divisor function to factor out the switch above?
Something like:

if (changed & R_CONTROL_PRESCALE_MASK) {
if (FIELD_EX32(newctrl, CONTROL, PRESCALE) == 3) {
qemu_log_mask(LOG_GUEST_ERROR,
  "CMSDK APB dual-timer: CONTROL.PRESCALE==0b11"
  " is undefined behaviour\n");
}

ptimer_set_period_from_clock(m->timer, m->parent->timclk,
 cmsdk_dualtimermod_divisor(m));
}

With or without this modification:
Reviewed-by: Luc Michel 


Luc

>  }
>  
>  if (changed & R_CONTROL_MODE_MASK) {
> @@ -414,7 +430,8 @@ static void 
> cmsdk_dualtimermod_reset(CMSDKAPBDualTimerModule *m)
>   * limit must both be set to 0x, so we wrap at 16 bits.
>   */
>  ptimer_set_limit(m->timer, 0x, 1);
> -ptimer_set_freq(m->timer, m->parent->pclk_frq);
> +ptimer_set_period_from_clock(m->timer, m->parent->timclk,
> + cmsdk_dualtimermod_divisor(m));
>  ptimer_transaction_commit(m->timer);
>  }
>  
> @@ -432,6 +449,20 @@ static void cmsdk_apb_dualtimer_reset(DeviceState *dev)
>  s->timeritop = 0;
>  }
>  
> +static void cmsdk_apb_dualtimer_clk_update(void *opaque)
> +{
> +CMSDKAPBDualTimer *s = CMSDK_APB_DUALTIMER(opaque);
> +int i;
> +
> +for (i = 0; i < ARRAY_SIZE(s->timermod); i++) {
> +CMSDKAPBDualTimerModule *m = >timermod[i];
> +ptimer_transaction_begin(m->timer);
> +ptimer_set_period_from_clock(m->timer, m->parent->timclk,
> + cmsdk_dualtimermod_divisor(m));
> +ptimer_transaction_commit(m->timer);
> +}
> +}
> +
>  static void cmsdk_apb_dualtimer_init(Object *obj)
>  {
>  SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
> @@ -446,7 +477,8 @@ static void cmsdk_apb_dualtimer_init(Object *obj)
>  for (i = 0; i < ARRAY_SIZE(s->timermod); i++) {
>  sysbus_init_irq(sbd, >timermod[i].timerint);
>  }
> -s->timclk = qdev_init_clock_in(DEVICE(s), "TIMCLK", NULL, NULL);
> +s->timclk = qdev_init_clock_in(DEVICE(s), "TIMCLK",
> +   cmsdk_apb_dualtimer_clk_update, s);
>  }
>  
>  static void cmsdk_apb_dualtimer_realize(DeviceState *dev, Error **errp)
> @@ -454,8 +486,8 @@ static void cmsdk_apb_dualtimer_realize(DeviceState *dev, 
> Error **errp)
>  CMSDKAPBDualTimer *s = CMSDK_APB_DUALTIMER(dev);
>  int i;
>  
> -if (s->pclk_frq == 0) {
> -error_setg(errp, "CMSDK APB timer: pclk-frq property must be set");
> +if (!clock_has_source(s->timclk)) {
> +error_setg(errp, "CMSDK APB dualtimer: TIMCLK clock must be 
> connected");
>  return;
>  }
>  
> -- 
> 2.20.1
> 

-- 



[PATCH v2 11/12] qapi/meson: Restrict system-mode specific modules

2021-01-22 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 qapi/meson.build | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/qapi/meson.build b/qapi/meson.build
index b301a46f04a..7aca8d50484 100644
--- a/qapi/meson.build
+++ b/qapi/meson.build
@@ -18,8 +18,6 @@
 endif
 
 qapi_all_modules = [
-  'acpi',
-  'audio',
   'authz',
   'block',
   'block-core',
@@ -39,14 +37,10 @@
   'misc-target',
   'net',
   'pragma',
-  'pci',
   'qom',
-  'rdma',
   'replay',
-  'rocker',
   'run-state',
   'sockets',
-  'tpm',
   'trace',
   'transaction',
   'ui',
@@ -54,7 +48,13 @@
 ]
 if have_system
   qapi_all_modules += [
+'acpi',
+'audio',
 'qdev',
+'pci',
+'rdma',
+'rocker',
+'tpm',
   ]
 endif
 
-- 
2.26.2




[PATCH v2 08/12] meson: Restrict emulation code

2021-01-22 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
Cc: Richard Henderson 
---
 meson.build | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/meson.build b/meson.build
index 396ea3aa19b..b5afa2923b3 100644
--- a/meson.build
+++ b/meson.build
@@ -1809,16 +1809,18 @@
 qemuutil = declare_dependency(link_with: libqemuutil,
   sources: genh + version_res)
 
-decodetree = generator(find_program('scripts/decodetree.py'),
-   output: 'decode-@basen...@.c.inc',
-   arguments: ['@INPUT@', '@EXTRA_ARGS@', '-o', 
'@OUTPUT@'])
+if have_system or have_user
+  decodetree = generator(find_program('scripts/decodetree.py'),
+ output: 'decode-@basen...@.c.inc',
+ arguments: ['@INPUT@', '@EXTRA_ARGS@', '-o', 
'@OUTPUT@'])
+  subdir('libdecnumber')
+  subdir('target')
+endif
 
 subdir('audio')
 subdir('io')
 subdir('chardev')
 subdir('fsdev')
-subdir('libdecnumber')
-subdir('target')
 subdir('dump')
 
 block_ss.add(files(
-- 
2.26.2




[PATCH v2 06/12] meson: Merge trace_events_subdirs array

2021-01-22 Thread Philippe Mathieu-Daudé
The trace_events_subdirs array is split in two different
locations, merge it as one.

Signed-off-by: Philippe Mathieu-Daudé 
---
Cc: Stefan Hajnoczi 
---
 meson.build | 28 +---
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/meson.build b/meson.build
index 181f8795f5a..c43538a1523 100644
--- a/meson.build
+++ b/meson.build
@@ -1686,7 +1686,20 @@
   'accel/kvm',
   'accel/tcg',
   'crypto',
+  'hw/core',
+  'qapi',
+  'qom',
   'monitor',
+  'target/arm',
+  'target/hppa',
+  'target/i386',
+  'target/i386/kvm',
+  'target/mips',
+  'target/ppc',
+  'target/riscv',
+  'target/s390x',
+  'target/sparc',
+  'util',
 ]
 if have_user
   trace_events_subdirs += [ 'linux-user' ]
@@ -1759,21 +1772,6 @@
 'ui',
   ]
 endif
-trace_events_subdirs += [
-  'hw/core',
-  'qapi',
-  'qom',
-  'target/arm',
-  'target/hppa',
-  'target/i386',
-  'target/i386/kvm',
-  'target/mips',
-  'target/ppc',
-  'target/riscv',
-  'target/s390x',
-  'target/sparc',
-  'util',
-]
 
 vhost_user = not_found
 if 'CONFIG_VHOST_USER' in config_host
-- 
2.26.2




[PATCH v2 07/12] meson: Restrict some trace event directories to user/system emulation

2021-01-22 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
Cc: Stefan Hajnoczi 
---
 meson.build | 28 
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/meson.build b/meson.build
index c43538a1523..396ea3aa19b 100644
--- a/meson.build
+++ b/meson.build
@@ -1683,22 +1683,10 @@
 # TODO: add each directory to the subdirs from its own meson.build, once
 # we have those
 trace_events_subdirs = [
-  'accel/kvm',
-  'accel/tcg',
   'crypto',
-  'hw/core',
   'qapi',
   'qom',
   'monitor',
-  'target/arm',
-  'target/hppa',
-  'target/i386',
-  'target/i386/kvm',
-  'target/mips',
-  'target/ppc',
-  'target/riscv',
-  'target/s390x',
-  'target/sparc',
   'util',
 ]
 if have_user
@@ -1715,6 +1703,7 @@
 endif
 if have_system
   trace_events_subdirs += [
+'accel/kvm',
 'audio',
 'backends',
 'backends/tpm',
@@ -1772,6 +1761,21 @@
 'ui',
   ]
 endif
+if have_system or have_user
+  trace_events_subdirs += [
+'accel/tcg',
+'hw/core',
+'target/arm',
+'target/hppa',
+'target/i386',
+'target/i386/kvm',
+'target/mips',
+'target/ppc',
+'target/riscv',
+'target/s390x',
+'target/sparc',
+  ]
+endif
 
 vhost_user = not_found
 if 'CONFIG_VHOST_USER' in config_host
-- 
2.26.2




[PATCH v2 03/12] pc-bios/meson: Only install EDK2 blob firmwares with system emulation

2021-01-22 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 pc-bios/meson.build | 1 +
 1 file changed, 1 insertion(+)

diff --git a/pc-bios/meson.build b/pc-bios/meson.build
index fab323af84e..68705d405ce 100644
--- a/pc-bios/meson.build
+++ b/pc-bios/meson.build
@@ -16,6 +16,7 @@
 
   foreach f : fds
 custom_target(f,
+  build_by_default: have_system,
   output: f,
   input: '@0@.bz2'.format(f),
   capture: true,
-- 
2.26.2




[PATCH v2 05/12] meson: Restrict block subsystem processing

2021-01-22 Thread Philippe Mathieu-Daudé
Avoid generating module_block.h and block-gen.c if we are
not going to use them.

Signed-off-by: Philippe Mathieu-Daudé 
---
Cc: qemu-bl...@nongnu.org
---
 meson.build | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index 61cbb89cd44..181f8795f5a 100644
--- a/meson.build
+++ b/meson.build
@@ -1829,7 +1829,9 @@
 
 subdir('nbd')
 subdir('scsi')
-subdir('block')
+if have_block
+  subdir('block')
+endif
 
 blockdev_ss.add(files(
   'blockdev.c',
-- 
2.26.2




[PATCH v2 01/12] configure: Only check for audio drivers if system-mode is selected

2021-01-22 Thread Philippe Mathieu-Daudé
Acked-by: Gerd Hoffmann 
Signed-off-by: Philippe Mathieu-Daudé 
---
 configure | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/configure b/configure
index 6f6a319c2f6..a4476d457e0 100755
--- a/configure
+++ b/configure
@@ -2324,6 +2324,12 @@ if test -z "$want_tools"; then
 fi
 fi
 
+##
+# Disable features only meaningful for system-mode emulation
+if test "$softmmu" = "no"; then
+audio_drv_list=""
+fi
+
 ##
 # Some versions of Mac OS X incorrectly define SIZE_MAX
 cat > $TMPC << EOF
-- 
2.26.2




[PATCH v2 12/12] qapi/meson: Restrict UI module to system emulation and tools

2021-01-22 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
Cc: Gerd Hoffmann 
---
 qapi/meson.build | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/qapi/meson.build b/qapi/meson.build
index 7aca8d50484..0652569bc43 100644
--- a/qapi/meson.build
+++ b/qapi/meson.build
@@ -43,7 +43,6 @@
   'sockets',
   'trace',
   'transaction',
-  'ui',
   'yank',
 ]
 if have_system
@@ -57,6 +56,11 @@
 'tpm',
   ]
 endif
+if have_system or have_tools
+  qapi_all_modules += [
+'ui',
+  ]
+endif
 
 qapi_storage_daemon_modules = [
   'block-core',
-- 
2.26.2




[PATCH v2 09/12] qapi/meson: Restrict qdev code to system-mode emulation

2021-01-22 Thread Philippe Mathieu-Daudé
Beside a CPU device, user-mode emulation doesn't access
anything else from qdev subsystem.

Tools don't need anything from qdev.

Signed-off-by: Philippe Mathieu-Daudé 
---
Cc: Laurent Vivier 
Cc: Eduardo Habkost 
---
 stubs/qdev.c  | 23 +++
 MAINTAINERS   |  1 +
 qapi/meson.build  |  6 +-
 stubs/meson.build |  2 ++
 4 files changed, 31 insertions(+), 1 deletion(-)
 create mode 100644 stubs/qdev.c

diff --git a/stubs/qdev.c b/stubs/qdev.c
new file mode 100644
index 000..92e61431344
--- /dev/null
+++ b/stubs/qdev.c
@@ -0,0 +1,23 @@
+/*
+ * QOM stubs
+ *
+ * Copyright (c) 2021 Red Hat, Inc.
+ *
+ * Author:
+ *   Philippe Mathieu-Daudé 
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/qapi-events-qdev.h"
+
+void qapi_event_send_device_deleted(bool has_device,
+const char *device,
+const char *path)
+{
+/* Nothing to do. */
+}
diff --git a/MAINTAINERS b/MAINTAINERS
index 34359a99b8e..d2dd7c24228 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2523,6 +2523,7 @@ F: qapi/qom.json
 F: qapi/qdev.json
 F: scripts/coccinelle/qom-parent-type.cocci
 F: softmmu/qdev-monitor.c
+F: stubs/qdev.c
 F: qom/
 F: tests/check-qom-interface.c
 F: tests/check-qom-proplist.c
diff --git a/qapi/meson.build b/qapi/meson.build
index ab68e7900e4..2839871b478 100644
--- a/qapi/meson.build
+++ b/qapi/meson.build
@@ -35,7 +35,6 @@
   'misc-target',
   'net',
   'pragma',
-  'qdev',
   'pci',
   'qom',
   'rdma',
@@ -49,6 +48,11 @@
   'ui',
   'yank',
 ]
+if have_system
+  qapi_all_modules += [
+'qdev',
+  ]
+endif
 
 qapi_storage_daemon_modules = [
   'block-core',
diff --git a/stubs/meson.build b/stubs/meson.build
index 1a656cd0704..a054d5877fb 100644
--- a/stubs/meson.build
+++ b/stubs/meson.build
@@ -53,4 +53,6 @@
 if have_system
   stub_ss.add(files('semihost.c'))
   stub_ss.add(files('xen-hw-stub.c'))
+else
+  stub_ss.add(files('qdev.c'))
 endif
-- 
2.26.2




[PATCH v2 00/12] buildsys: Do not build various objects if not necessary

2021-01-22 Thread Philippe Mathieu-Daudé
In this series we deselect a bunch of features when they
not required, so less objects are built.

While this reduce pressure on CI and slow systems, this is
particularly helpful for developers regularly testing multiple
build configurations.

All CI tests pass:
https://gitlab.com/philmd/qemu/-/pipelines/245654160

Supersedes: <20210120151916.1167448-1-phi...@redhat.com>

Philippe Mathieu-Daudé (12):
  configure: Only check for audio drivers if system-mode is selected
  tests/meson: Only build softfloat objects if TCG is selected
  pc-bios/meson: Only install EDK2 blob firmwares with system emulation
  meson: Do not build optional libraries by default
  meson: Restrict block subsystem processing
  meson: Merge trace_events_subdirs array
  meson: Restrict some trace event directories to user/system emulation
  meson: Restrict emulation code
  qapi/meson: Restrict qdev code to system-mode emulation
  qapi/meson: Remove QMP from user-mode emulation
  qapi/meson: Restrict system-mode specific modules
  qapi/meson: Restrict UI module to system emulation and tools

 configure   |  6 +
 meson.build | 55 ++---
 stubs/qdev.c| 23 +++
 MAINTAINERS |  1 +
 pc-bios/meson.build |  1 +
 qapi/meson.build| 34 +++-
 stubs/meson.build   |  2 ++
 tests/meson.build   | 11 +++--
 8 files changed, 97 insertions(+), 36 deletions(-)
 create mode 100644 stubs/qdev.c

-- 
2.26.2





[PATCH v2 10/12] qapi/meson: Remove QMP from user-mode emulation

2021-01-22 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
Cc: Laurent Vivier 
---
 qapi/meson.build  | 10 +++---
 tests/meson.build |  7 ++-
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/qapi/meson.build b/qapi/meson.build
index 2839871b478..b301a46f04a 100644
--- a/qapi/meson.build
+++ b/qapi/meson.build
@@ -4,14 +4,18 @@
   'qapi-dealloc-visitor.c',
   'qapi-util.c',
   'qapi-visit-core.c',
-  'qmp-dispatch.c',
-  'qmp-event.c',
-  'qmp-registry.c',
   'qobject-input-visitor.c',
   'qobject-output-visitor.c',
   'string-input-visitor.c',
   'string-output-visitor.c',
 ))
+if have_system or have_tools
+  util_ss.add(files(
+'qmp-dispatch.c',
+'qmp-event.c',
+'qmp-registry.c',
+  ))
+endif
 
 qapi_all_modules = [
   'acpi',
diff --git a/tests/meson.build b/tests/meson.build
index 6f1ff926d26..7d7da6a6364 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -86,7 +86,6 @@
   'test-qobject-input-visitor': [testqapi],
   'test-string-input-visitor': [testqapi],
   'test-string-output-visitor': [testqapi],
-  'test-qmp-event': [testqapi],
   'test-opts-visitor': [testqapi],
   'test-visitor-serialization': [testqapi],
   'test-bitmap': [],
@@ -117,6 +116,12 @@
   'test-qapi-util': [],
 }
 
+if have_system or have_tools
+  tests += {
+'test-qmp-event': [testqapi],
+  }
+endif
+
 test_deps = {
   'test-qht-par': qht_bench,
 }
-- 
2.26.2




[PATCH v2 04/12] meson: Do not build optional libraries by default

2021-01-22 Thread Philippe Mathieu-Daudé
The following libraries will be selected if a feature requires it:

- capstone
- fdt
- SLiRP

Suggested-by: Paolo Bonzini 
Signed-off-by: Philippe Mathieu-Daudé 
---
Cc: Marc-André Lureau 
Cc: David Gibson 
Cc: Samuel Thibault 
---
 meson.build | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/meson.build b/meson.build
index a1e1eb318a5..61cbb89cd44 100644
--- a/meson.build
+++ b/meson.build
@@ -1446,6 +1446,7 @@
   ]
 
   libcapstone = static_library('capstone',
+   build_by_default: false,
sources: capstone_files,
c_args: capstone_cargs,
include_directories: 'capstone/include')
@@ -1523,6 +1524,7 @@
 
 slirp_inc = include_directories('slirp', 'slirp/src')
 libslirp = static_library('slirp',
+  build_by_default: false,
   sources: slirp_files,
   c_args: slirp_cargs,
   include_directories: slirp_inc)
@@ -1568,6 +1570,7 @@
 
 fdt_inc = include_directories('dtc/libfdt')
 libfdt = static_library('fdt',
+build_by_default: false,
 sources: fdt_files,
 include_directories: fdt_inc)
 fdt = declare_dependency(link_with: libfdt,
-- 
2.26.2




[PATCH v2 02/12] tests/meson: Only build softfloat objects if TCG is selected

2021-01-22 Thread Philippe Mathieu-Daudé
Suggested-by: Paolo Bonzini 
Signed-off-by: Philippe Mathieu-Daudé 
---
Cc: Richard Henderson 
Cc: Alex Bennée 
Cc: Emilio G. Cota 
---
 tests/meson.build | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tests/meson.build b/tests/meson.build
index 29ebaba48d2..6f1ff926d26 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -276,7 +276,9 @@
  workdir: meson.current_source_dir() / 'decode',
  suite: 'decodetree')
 
-subdir('fp')
+if 'CONFIG_TCG' in config_all
+  subdir('fp')
+endif
 
 if not get_option('tcg').disabled()
   if 'CONFIG_PLUGIN' in config_host
-- 
2.26.2




Re: [PATCH 8/8] configure: automatically parse command line for meson -D options

2021-01-22 Thread Paolo Bonzini
Il ven 22 gen 2021, 09:00 罗勇刚(Yonggang Luo)  ha
scritto:

> Hi Paolo, as python and meson are required dependencies to building qemu
> now,
> can we detecting python/meson at the very begining of configure,
> even before the --help parameter.
>

We could and I did it in the first version. However it's ugly that the user
has to use --python on some setups in order to get a full help message.

Paolo


> On Wed, Jan 13, 2021 at 6:08 AM Paolo Bonzini  wrote:
> >
> > On 13/01/21 11:31, Daniel P. Berrangé wrote:
> > >>   meson-buildoptions.json | 717
> 
> > > I'm not a fan of seeing this file introduced as it has significant
> > > overlap with meson_options.txt.I feel like the latter has enough
> > > information present to do an acceptable job for help output. After
> > > all that's sufficient if we were using meson directly.
> >
> > Sorry, I missed this remark.  meson-buildoptions.json is not
> > hand-written.  It is the result of Meson's own parsing meson_options.txt
> > exported as JSON.
> >
> > In the commit message "because we parse command-line options before
> > meson is available, the introspection output is stored in the source
> > tree.  This is the reason for the unattractive diffstat; the number of
> > JSON lines added is higher than the number of configure lines removed.
> > Of course the latter are code that must be maintained manually and the
> > former is not".
> >
> > Paolo
> >
> >
>
>
> --
>  此致
> 礼
> 罗勇刚
> Yours
> sincerely,
> Yonggang Luo
>


Re: Thread safety of coroutine-sigaltstack

2021-01-22 Thread Laszlo Ersek
On 01/21/21 18:24, Paolo Bonzini wrote:
> On 21/01/21 17:44, Peter Maydell wrote:
>> On Thu, 21 Jan 2021 at 16:10, Daniel P. Berrangé 
>> wrote:
>>> FWIW The libucontext impl is all ASM based and has coverage for all the
>>> arches we care about:
>>>
>>>     https://github.com/kaniini/libucontext
>>>
>>> so doesn't seem like there's a need for  coroutine-asm if we can rely
>>> on libucontext for portability where neede.
>>
>> The README for that notes a couple of pretty major omissions:
>>   * it doesn't handle floating point registers
>>   * it doesn't do anything about the signal mask
>> I'm pretty sure that not handling the fp regs could cause breakage
>> for Arm at least (depending on what the compiler chooses to do
>> in the functions that work with the ucontext functions). The
>> signal mask stuff might be OK for us because of the carefully
>> limited use we make of the ucontext functions, but it would be
>> a bit of a pain to have to analyse that code for both sets of semantics.
> 
> The lack of signal mask handling is an improvement for us. :)  We want
> the signal mask to be per thread, not per coroutine.

I didn't quite get this when I first read it, but now that I'm digging
through the code, I have a follow-up comment.

According to POSIX, passing savemask=0 to sigsetjmp() may or may not
save the current signal mask, into "env". A nonzero savemask is required
to save the signal mask, but a zero savemask is not forbidden to -- it
is only not required to:

https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigsetjmp.html#tag_16_554_07

Note that since this function is defined in terms of setjmp(), if
savemask is zero, it is unspecified whether the signal mask is
saved.

And I feel that's a bit of a problem, because when we first exit the
trampoline -- executed as a signal handler -- via sigsetjmp(), *all
signals* are masked, and sigsetjmp might actually stash that mask in
"tr_reenter", because savemask=0 does not suffice for forbidding that.

When we reenter the trampoline via siglongjmp(tr_reenter), and
subsequently call coroutine_bootstrap(), it's possible (per POSIX, see
above) that all signals are masked again. And then that could further be
remembered in "self->env", in coroutine_bootstrap(). Which would be
wrong IMO; co-routines in general should receive synchronous signals if
they mess up somewhere (terminating the process).

IOW, just before the call to coroutine_bootstrap(),
coroutine_trampoline() should explicitly restore the signal mask that
was in effect when qemu_coroutine_new() was entered.

Has this been a problem in practice, or should we ignore it?

IOW, should we assume "savemask=0" for *never* saving the signal mask?

The behavior of "savemask=0" is a platform trait that platforms are not
required to document (the behavior is unspecified, not
implementation-defined), so it really boils down to where this code
actually runs...

NB Linux is more specific:

https://man7.org/linux/man-pages/man3/setjmp.3.html

   sigsetjmp() and siglongjmp()
   sigsetjmp() and siglongjmp() also perform nonlocal gotos, but
   provide predictable handling of the process signal mask.

   If, and only if, the savesigs argument provided to sigsetjmp() is
   nonzero, the process's current signal mask is saved in env and
   will be restored if a siglongjmp() is later performed with this
   env.

Cue "and only if".

Thanks
Laszlo

> 
> Floating point however is an issue if they don't save-restore v8-v15
> (for aarch64, I don't remember what the AAPCS32 says).
> 
> Paolo
> 
> 




getting the console output for s390 cdrom-test?

2021-01-22 Thread Peter Maydell
Hi; I've been looking at why the s390 cdrom test has an intermittent
failure on my aarch64 box. Looking at some TCG debug log output
I think what is happening is that sometimes execution diverges from
a successful run inside virtio_scsi_setup() and we end up failing
a vs_assert(), which triggers a "Guest crashed on cpu 0: disabled-wait"
which then makes the qtest hang until its timeout.

I think that vs_assert() ought to be printing some information
to the console about which assert fails when it happens, but
how do I need to tweak the qtest to get it to capture this
console log somewhere?

Specifically, the test in question is this one:
QTEST_QEMU_BINARY=qemu-system-s390x
./build/s390/tests/qtest/cdrom-test -p
/s390x/cdrom/boot/without-bootindex

PS: it would be nice if "guest BIOS asserts and puts the
system into a detected-guest-crash state" resulted in the
test failing rather than hanging :-)

(Annoyingly, most of my attempts to get more information about
where things go wrong seem to cause the bug to stop manifesting
itself: eg building the s390-ccw.img without -O2; enabling
TCG 'exec' logging; enabling 'trace:virtio*' tracepoints.
The failure itself started with commit 7a3d37a3f233 updating
the s390 bios blobs, but the changes that went into the new
blobs don't really look like they would be responsible.
I am starting to have gloomy thoughts about potential missing
memory barrier insns between the CPU thread and the iothread
doing the virtio device end of things...)

thanks
-- PMM



Re: [PATCH 18/25] hw/timer/cmsdk-apb-timer: Convert to use Clock input

2021-01-22 Thread Luc Michel
On 19:06 Thu 21 Jan , Peter Maydell wrote:
> Switch the CMSDK APB timer device over to using its Clock input; the
> pclk-frq property is now ignored.
> 
> Signed-off-by: Peter Maydell 

Reviewed-by: Luc Michel 

> ---
>  hw/timer/cmsdk-apb-timer.c | 18 ++
>  1 file changed, 14 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/timer/cmsdk-apb-timer.c b/hw/timer/cmsdk-apb-timer.c
> index c63145ff553..f053146d88f 100644
> --- a/hw/timer/cmsdk-apb-timer.c
> +++ b/hw/timer/cmsdk-apb-timer.c
> @@ -204,6 +204,15 @@ static void cmsdk_apb_timer_reset(DeviceState *dev)
>  ptimer_transaction_commit(s->timer);
>  }
>  
> +static void cmsdk_apb_timer_clk_update(void *opaque)
> +{
> +CMSDKAPBTimer *s = CMSDK_APB_TIMER(opaque);
> +
> +ptimer_transaction_begin(s->timer);
> +ptimer_set_period_from_clock(s->timer, s->pclk, 1);
> +ptimer_transaction_commit(s->timer);
> +}
> +
>  static void cmsdk_apb_timer_init(Object *obj)
>  {
>  SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
> @@ -213,15 +222,16 @@ static void cmsdk_apb_timer_init(Object *obj)
>s, "cmsdk-apb-timer", 0x1000);
>  sysbus_init_mmio(sbd, >iomem);
>  sysbus_init_irq(sbd, >timerint);
> -s->pclk = qdev_init_clock_in(DEVICE(s), "pclk", NULL, NULL);
> +s->pclk = qdev_init_clock_in(DEVICE(s), "pclk",
> + cmsdk_apb_timer_clk_update, s);
>  }
>  
>  static void cmsdk_apb_timer_realize(DeviceState *dev, Error **errp)
>  {
>  CMSDKAPBTimer *s = CMSDK_APB_TIMER(dev);
>  
> -if (s->pclk_frq == 0) {
> -error_setg(errp, "CMSDK APB timer: pclk-frq property must be set");
> +if (!clock_has_source(s->pclk)) {
> +error_setg(errp, "CMSDK APB timer: pclk clock must be connected");
>  return;
>  }
>  
> @@ -232,7 +242,7 @@ static void cmsdk_apb_timer_realize(DeviceState *dev, 
> Error **errp)
> PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
>  
>  ptimer_transaction_begin(s->timer);
> -ptimer_set_freq(s->timer, s->pclk_frq);
> +ptimer_set_period_from_clock(s->timer, s->pclk, 1);
>  ptimer_transaction_commit(s->timer);
>  }
>  
> -- 
> 2.20.1
> 

-- 



Re: [PATCH v7 07/35] Hexagon (target/hexagon) scalar core helpers

2021-01-22 Thread Philippe Mathieu-Daudé
Hi Taylor,

On 1/20/21 4:28 AM, Taylor Simpson wrote:
> The majority of helpers are generated.  Define the helper functions needed
> then include the generated file
> 
> Signed-off-by: Taylor Simpson 
> ---
>  target/hexagon/helper.h|   85 
>  target/hexagon/op_helper.c | 1066 
> 
>  2 files changed, 1151 insertions(+)
>  create mode 100644 target/hexagon/helper.h
>  create mode 100644 target/hexagon/op_helper.c
...

> diff --git a/target/hexagon/op_helper.c b/target/hexagon/op_helper.c
> new file mode 100644
> index 000..5186dd1
> --- /dev/null
> +++ b/target/hexagon/op_helper.c
> @@ -0,0 +1,1066 @@
> +/*
> + *  Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights 
> Reserved.
> + *
> + *  This program is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License as published by
> + *  the Free Software Foundation; either version 2 of the License, or
> + *  (at your option) any later version.
> + *
> + *  This program is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + *  You should have received a copy of the GNU General Public License
> + *  along with this program; if not, see .
> + */
> +
> +#include "qemu/osdep.h"
> +#include "qemu.h"
> +#include "exec/helper-proto.h"
> +#include "fpu/softfloat.h"
> +#include "cpu.h"
> +#include "internal.h"
> +#include "macros.h"
> +#include "arch.h"
> +#include "hex_arch_types.h"
> +#include "fma_emu.h"
> +#include "conv_emu.h"
> +
> +#define SF_BIAS127
> +#define SF_MANTBITS23
> +
> +/* Exceptions processing helpers */
> +static void QEMU_NORETURN do_raise_exception_err(CPUHexagonState *env,
> + uint32_t exception,
> + uintptr_t pc)
> +{
> +CPUState *cs = CPU(hexagon_env_get_cpu(env));
> +qemu_log_mask(CPU_LOG_INT, "%s: %d\n", __func__, exception);
> +cs->exception_index = exception;
> +cpu_loop_exit_restore(cs, pc);
> +}
> +
> +void QEMU_NORETURN HELPER(raise_exception)(CPUHexagonState *env, uint32_t 
> excp)
> +{
> +do_raise_exception_err(env, excp, 0);
> +}
> +
> +static inline void log_reg_write(CPUHexagonState *env, int rnum,
> + target_ulong val, uint32_t slot)
> +{
> +HEX_DEBUG_LOG("log_reg_write[%d] = " TARGET_FMT_ld " (0x" TARGET_FMT_lx 
> ")",
> +  rnum, val, val);
> +if (env->slot_cancelled & (1 << slot)) {
> +HEX_DEBUG_LOG(" CANCELLED");
> +}
> +if (val == env->gpr[rnum]) {
> +HEX_DEBUG_LOG(" NO CHANGE");
> +}
> +HEX_DEBUG_LOG("\n");
> +if (!(env->slot_cancelled & (1 << slot))) {
> +env->new_value[rnum] = val;
> +#if HEX_DEBUG
> +/* Do this so HELPER(debug_commit_end) will know */
> +env->reg_written[rnum] = 1;
> +#endif
> +}
> +}
> +
> +static __attribute__((unused))
> +inline void log_reg_write_pair(CPUHexagonState *env, int rnum,
> +  int64_t val, uint32_t slot)
> +{
> +HEX_DEBUG_LOG("log_reg_write_pair[%d:%d] = %ld\n", rnum + 1, rnum, val);
> +log_reg_write(env, rnum, val & 0x, slot);
> +log_reg_write(env, rnum + 1, (val >> 32) & 0x, slot);
> +}
> +
> +static inline void log_pred_write(CPUHexagonState *env, int pnum,
> +  target_ulong val)
> +{
> +HEX_DEBUG_LOG("log_pred_write[%d] = " TARGET_FMT_ld
> +  " (0x" TARGET_FMT_lx ")\n",
> +  pnum, val, val);
> +
> +/* Multiple writes to the same preg are and'ed together */
> +if (env->pred_written & (1 << pnum)) {
> +env->new_pred_value[pnum] &= val & 0xff;
> +} else {
> +env->new_pred_value[pnum] = val & 0xff;
> +env->pred_written |= 1 << pnum;
> +}
> +}
> +
> +static inline void log_store32(CPUHexagonState *env, target_ulong addr,
> +   target_ulong val, int width, int slot)
> +{
> +HEX_DEBUG_LOG("log_store%d(0x" TARGET_FMT_lx ", " TARGET_FMT_ld
> +  " [0x" TARGET_FMT_lx "])\n",
> +  width, addr, val, val);
> +env->mem_log_stores[slot].va = addr;
> +env->mem_log_stores[slot].width = width;
> +env->mem_log_stores[slot].data32 = val;
> +}
> +
> +static inline void log_store64(CPUHexagonState *env, target_ulong addr,
> +   int64_t val, int width, int slot)
> +{
> +HEX_DEBUG_LOG("log_store%d(0x" TARGET_FMT_lx ", %ld [0x%lx])\n",
> +   width, addr, val, val);
> +env->mem_log_stores[slot].va = addr;
> +env->mem_log_stores[slot].width = width;
> +env->mem_log_stores[slot].data64 = val;
> +}
> +
> +static inline void 

Re: [PATCH 17/25] hw/arm/stellaris: Create Clock input for watchdog

2021-01-22 Thread Luc Michel
On 19:06 Thu 21 Jan , Peter Maydell wrote:
> Create and connect the Clock input for the watchdog device on the
> Stellaris boards.  Because the Stellaris boards model the ability to
> change the clock rate by programming PLL registers, we have to create
> an output Clock on the ssys_state device and wire it up to the
> watchdog.
> 
> Note that the old comment on ssys_calculate_system_clock() got the
> units wrong -- system_clock_scale is in nanoseconds, not
> milliseconds.  Improve the commentary to clarify how we are
> calculating the period.
> 
> Signed-off-by: Peter Maydell 

Reviewed-by: Luc Michel 

> ---
>  hw/arm/stellaris.c | 43 +++
>  1 file changed, 31 insertions(+), 12 deletions(-)
> 
> diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
> index 0194ede2fe0..9b67c739ef2 100644
> --- a/hw/arm/stellaris.c
> +++ b/hw/arm/stellaris.c
> @@ -26,6 +26,7 @@
>  #include "hw/watchdog/cmsdk-apb-watchdog.h"
>  #include "migration/vmstate.h"
>  #include "hw/misc/unimp.h"
> +#include "hw/qdev-clock.h"
>  #include "cpu.h"
>  #include "qom/object.h"
>  
> @@ -377,6 +378,7 @@ struct ssys_state {
>  uint32_t clkvclr;
>  uint32_t ldoarst;
>  qemu_irq irq;
> +Clock *sysclk;
>  /* Properties (all read-only registers) */
>  uint32_t user0;
>  uint32_t user1;
> @@ -555,15 +557,26 @@ static bool ssys_use_rcc2(ssys_state *s)
>  }
>  
>  /*
> - * Caculate the sys. clock period in ms.
> + * Calculate the system clock period. We only want to propagate
> + * this change to the rest of the system if we're not being called
> + * from migration post-load.
>   */
> -static void ssys_calculate_system_clock(ssys_state *s)
> +static void ssys_calculate_system_clock(ssys_state *s, bool propagate_clock)
>  {
> +/*
> + * SYSDIV field specifies divisor: 0 == /1, 1 == /2, etc.  Input
> + * clock is 200MHz, which is a period of 5 ns. Dividing the clock
> + * frequency by X is the same as multiplying the period by X.
> + */
>  if (ssys_use_rcc2(s)) {
>  system_clock_scale = 5 * (((s->rcc2 >> 23) & 0x3f) + 1);
>  } else {
>  system_clock_scale = 5 * (((s->rcc >> 23) & 0xf) + 1);
>  }
> +clock_set_ns(s->sysclk, system_clock_scale);
> +if (propagate_clock) {
> +clock_propagate(s->sysclk);
> +}
>  }
>  
>  static void ssys_write(void *opaque, hwaddr offset,
> @@ -598,7 +611,7 @@ static void ssys_write(void *opaque, hwaddr offset,
>  s->int_status |= (1 << 6);
>  }
>  s->rcc = value;
> -ssys_calculate_system_clock(s);
> +ssys_calculate_system_clock(s, true);
>  break;
>  case 0x070: /* RCC2 */
>  if (ssys_board_class(s) == DID0_CLASS_SANDSTORM) {
> @@ -610,7 +623,7 @@ static void ssys_write(void *opaque, hwaddr offset,
>  s->int_status |= (1 << 6);
>  }
>  s->rcc2 = value;
> -ssys_calculate_system_clock(s);
> +ssys_calculate_system_clock(s, true);
>  break;
>  case 0x100: /* RCGC0 */
>  s->rcgc[0] = value;
> @@ -679,7 +692,8 @@ static void stellaris_sys_reset_hold(Object *obj)
>  {
>  ssys_state *s = STELLARIS_SYS(obj);
>  
> -ssys_calculate_system_clock(s);
> +/* OK to propagate clocks from the hold phase */
> +ssys_calculate_system_clock(s, true);
>  }
>  
>  static void stellaris_sys_reset_exit(Object *obj)
> @@ -690,7 +704,7 @@ static int stellaris_sys_post_load(void *opaque, int 
> version_id)
>  {
>  ssys_state *s = opaque;
>  
> -ssys_calculate_system_clock(s);
> +ssys_calculate_system_clock(s, false);
>  
>  return 0;
>  }
> @@ -713,6 +727,7 @@ static const VMStateDescription vmstate_stellaris_sys = {
>  VMSTATE_UINT32_ARRAY(dcgc, ssys_state, 3),
>  VMSTATE_UINT32(clkvclr, ssys_state),
>  VMSTATE_UINT32(ldoarst, ssys_state),
> +/* No field for sysclk -- handled in post-load instead */
>  VMSTATE_END_OF_LIST()
>  }
>  };
> @@ -738,11 +753,12 @@ static void stellaris_sys_instance_init(Object *obj)
>  memory_region_init_io(>iomem, obj, _ops, s, "ssys", 0x1000);
>  sysbus_init_mmio(sbd, >iomem);
>  sysbus_init_irq(sbd, >irq);
> +s->sysclk = qdev_init_clock_out(DEVICE(s), "SYSCLK");
>  }
>  
> -static int stellaris_sys_init(uint32_t base, qemu_irq irq,
> -  stellaris_board_info * board,
> -  uint8_t *macaddr)
> +static DeviceState *stellaris_sys_init(uint32_t base, qemu_irq irq,
> +   stellaris_board_info *board,
> +   uint8_t *macaddr)
>  {
>  DeviceState *dev = qdev_new(TYPE_STELLARIS_SYS);
>  SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
> @@ -774,7 +790,7 @@ static int stellaris_sys_init(uint32_t base, qemu_irq irq,
>   */
>  device_cold_reset(dev);
>  
> -return 0;
> +return dev;
>  }
>  
>  /* I2C controller.  */
> @@ -1341,6 

Re: [PATCH 16/25] hw/arm/stellaris: Convert SSYS to QOM device

2021-01-22 Thread Luc Michel
On 19:06 Thu 21 Jan , Peter Maydell wrote:
> Convert the SSYS code in the Stellaris boards (which encapsulates the
> system registers) to a proper QOM device.  This will provide us with
> somewhere to put the output Clock whose frequency depends on the
> setting of the PLL configuration registers.
> 
> This is a migration compatibility break for lm3s811evb, lm3s6965evb.
> 
> We use 3-phase reset here because the Clock will need to propagate
> its value in the hold phase.
> 
> For the moment we reset the device during the board creation so that
> the system_clock_scale global gets set; this will be removed in a
> subsequent commit.
> 
> Signed-off-by: Peter Maydell 

Reviewed-by: Luc Michel 

> ---
>  hw/arm/stellaris.c | 132 -
>  1 file changed, 107 insertions(+), 25 deletions(-)
> 
> diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
> index 652823195b1..0194ede2fe0 100644
> --- a/hw/arm/stellaris.c
> +++ b/hw/arm/stellaris.c
> @@ -357,7 +357,12 @@ static void stellaris_gptm_realize(DeviceState *dev, 
> Error **errp)
>  
>  /* System controller.  */
>  
> -typedef struct {
> +#define TYPE_STELLARIS_SYS "stellaris-sys"
> +OBJECT_DECLARE_SIMPLE_TYPE(ssys_state, STELLARIS_SYS)
> +
> +struct ssys_state {
> +SysBusDevice parent_obj;
> +
>  MemoryRegion iomem;
>  uint32_t pborctl;
>  uint32_t ldopctl;
> @@ -371,11 +376,18 @@ typedef struct {
>  uint32_t dcgc[3];
>  uint32_t clkvclr;
>  uint32_t ldoarst;
> +qemu_irq irq;
> +/* Properties (all read-only registers) */
>  uint32_t user0;
>  uint32_t user1;
> -qemu_irq irq;
> -stellaris_board_info *board;
> -} ssys_state;
> +uint32_t did0;
> +uint32_t did1;
> +uint32_t dc0;
> +uint32_t dc1;
> +uint32_t dc2;
> +uint32_t dc3;
> +uint32_t dc4;
> +};
>  
>  static void ssys_update(ssys_state *s)
>  {
> @@ -430,7 +442,7 @@ static uint32_t pllcfg_fury[16] = {
>  
>  static int ssys_board_class(const ssys_state *s)
>  {
> -uint32_t did0 = s->board->did0;
> +uint32_t did0 = s->did0;
>  switch (did0 & DID0_VER_MASK) {
>  case DID0_VER_0:
>  return DID0_CLASS_SANDSTORM;
> @@ -456,19 +468,19 @@ static uint64_t ssys_read(void *opaque, hwaddr offset,
>  
>  switch (offset) {
>  case 0x000: /* DID0 */
> -return s->board->did0;
> +return s->did0;
>  case 0x004: /* DID1 */
> -return s->board->did1;
> +return s->did1;
>  case 0x008: /* DC0 */
> -return s->board->dc0;
> +return s->dc0;
>  case 0x010: /* DC1 */
> -return s->board->dc1;
> +return s->dc1;
>  case 0x014: /* DC2 */
> -return s->board->dc2;
> +return s->dc2;
>  case 0x018: /* DC3 */
> -return s->board->dc3;
> +return s->dc3;
>  case 0x01c: /* DC4 */
> -return s->board->dc4;
> +return s->dc4;
>  case 0x030: /* PBORCTL */
>  return s->pborctl;
>  case 0x034: /* LDOPCTL */
> @@ -646,9 +658,9 @@ static const MemoryRegionOps ssys_ops = {
>  .endianness = DEVICE_NATIVE_ENDIAN,
>  };
>  
> -static void ssys_reset(void *opaque)
> +static void stellaris_sys_reset_enter(Object *obj, ResetType type)
>  {
> -ssys_state *s = (ssys_state *)opaque;
> +ssys_state *s = STELLARIS_SYS(obj);
>  
>  s->pborctl = 0x7ffd;
>  s->rcc = 0x078e3ac0;
> @@ -661,9 +673,19 @@ static void ssys_reset(void *opaque)
>  s->rcgc[0] = 1;
>  s->scgc[0] = 1;
>  s->dcgc[0] = 1;
> +}
> +
> +static void stellaris_sys_reset_hold(Object *obj)
> +{
> +ssys_state *s = STELLARIS_SYS(obj);
> +
>  ssys_calculate_system_clock(s);
>  }
>  
> +static void stellaris_sys_reset_exit(Object *obj)
> +{
> +}
> +
>  static int stellaris_sys_post_load(void *opaque, int version_id)
>  {
>  ssys_state *s = opaque;
> @@ -695,27 +717,66 @@ static const VMStateDescription vmstate_stellaris_sys = 
> {
>  }
>  };
>  
> +static Property stellaris_sys_properties[] = {
> +DEFINE_PROP_UINT32("user0", ssys_state, user0, 0),
> +DEFINE_PROP_UINT32("user1", ssys_state, user1, 0),
> +DEFINE_PROP_UINT32("did0", ssys_state, did0, 0),
> +DEFINE_PROP_UINT32("did1", ssys_state, did1, 0),
> +DEFINE_PROP_UINT32("dc0", ssys_state, dc0, 0),
> +DEFINE_PROP_UINT32("dc1", ssys_state, dc1, 0),
> +DEFINE_PROP_UINT32("dc2", ssys_state, dc2, 0),
> +DEFINE_PROP_UINT32("dc3", ssys_state, dc3, 0),
> +DEFINE_PROP_UINT32("dc4", ssys_state, dc4, 0),
> +DEFINE_PROP_END_OF_LIST()
> +};
> +
> +static void stellaris_sys_instance_init(Object *obj)
> +{
> +ssys_state *s = STELLARIS_SYS(obj);
> +SysBusDevice *sbd = SYS_BUS_DEVICE(s);
> +
> +memory_region_init_io(>iomem, obj, _ops, s, "ssys", 0x1000);
> +sysbus_init_mmio(sbd, >iomem);
> +sysbus_init_irq(sbd, >irq);
> +}
> +
>  static int stellaris_sys_init(uint32_t base, qemu_irq irq,
>stellaris_board_info * board,
>

Re: [PATCH] virtio: Add corresponding memory_listener_unregister to unrealize

2021-01-22 Thread Peter Xu
On Fri, Jan 22, 2021 at 09:08:51PM +0100, Eugenio Pérez wrote:
> Cannot destroy address spaces of IOMMU-aware virtio devices without it,
> since they can contain memory listeners.
> 
> Fixes: c611c76417f ("virtio: add MemoryListener to cache ring translations")
> Buglink: https://bugs.launchpad.net/qemu/+bug/1912846
> Signed-off-by: Eugenio Pérez 
> ---
>  hw/virtio/virtio.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index b308026596..67efd2c301 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -3680,6 +3680,7 @@ static void virtio_device_unrealize(DeviceState *dev)
>  VirtIODevice *vdev = VIRTIO_DEVICE(dev);
>  VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(dev);
>  
> +memory_listener_unregister(>listener);
>  virtio_bus_device_unplugged(vdev);
>  
>  if (vdc->unrealize != NULL) {
> -- 
> 2.27.0
> 

Reviewed-by: Peter Xu 

CC stable, assuming that's what we need too.

Thanks,

-- 
Peter Xu




[PATCH v7 08/11] configure: cross compile should use x86_64 cpu_family

2021-01-22 Thread Joelle van Dyne
Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: Joelle van Dyne 
---
 configure | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 7e5ec7a5a1..f487be3cfe 100755
--- a/configure
+++ b/configure
@@ -6466,9 +6466,12 @@ if test "$cross_compile" = "yes"; then
 echo "system = 'darwin'" >> $cross
 fi
 case "$ARCH" in
-i386|x86_64)
+i386)
 echo "cpu_family = 'x86'" >> $cross
 ;;
+x86_64)
+echo "cpu_family = 'x86_64'" >> $cross
+;;
 ppc64le)
 echo "cpu_family = 'ppc64'" >> $cross
 ;;
-- 
2.28.0




[PATCH v7 10/11] darwin: detect CoreAudio for build

2021-01-22 Thread Joelle van Dyne
On iOS there is no CoreAudio, so we should not assume Darwin always
has it.

Signed-off-by: Joelle van Dyne 
---
 configure | 35 +--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index f487be3cfe..fb671258e6 100755
--- a/configure
+++ b/configure
@@ -319,6 +319,7 @@ fdt="auto"
 netmap="no"
 sdl="auto"
 sdl_image="auto"
+coreaudio="auto"
 virtiofsd="auto"
 virtfs="auto"
 libudev="auto"
@@ -779,7 +780,7 @@ Darwin)
 QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS"
 QEMU_LDFLAGS="-arch x86_64 $QEMU_LDFLAGS"
   fi
-  audio_drv_list="coreaudio try-sdl"
+  audio_drv_list="try-coreaudio try-sdl"
   audio_possible_drivers="coreaudio sdl"
   # Disable attempts to use ObjectiveC features in os/object.h since they
   # won't work when we're compiling with gcc as a C compiler.
@@ -3162,6 +3163,24 @@ EOF
   fi
 fi
 
+##
+# detect CoreAudio
+if test "$coreaudio" != "no" ; then
+  coreaudio_libs="-framework CoreAudio"
+  cat > $TMPC << EOF
+#include 
+int main(void)
+{
+  return (int)AudioGetCurrentHostTime();
+}
+EOF
+  if compile_prog "" "$coreaudio_libs" ; then
+coreaudio=yes
+  else
+coreaudio=no
+  fi
+fi
+
 ##
 # Sound support libraries probe
 
@@ -3218,8 +3237,20 @@ for drv in $audio_drv_list; do
 fi
 ;;
 
-coreaudio)
+coreaudio | try-coreaudio)
+if test "$coreaudio" = "no"; then
+  if test "$drv" = "try-coreaudio"; then
+audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-coreaudio//')
+  else
+error_exit "$drv check failed" \
+"Make sure to have the $drv is available."
+  fi
+else
   coreaudio_libs="-framework CoreAudio"
+  if test "$drv" = "try-coreaudio"; then
+audio_drv_list=$(echo "$audio_drv_list" | sed -e 
's/try-coreaudio/coreaudio/')
+  fi
+fi
 ;;
 
 dsound)
-- 
2.28.0




[PATCH v7 06/11] darwin: remove redundant dependency declaration

2021-01-22 Thread Joelle van Dyne
Meson will find CoreFoundation, IOKit, and Cocoa as needed.

Signed-off-by: Joelle van Dyne 
---
 configure | 1 -
 1 file changed, 1 deletion(-)

diff --git a/configure b/configure
index 82ce28c660..4c485dd962 100755
--- a/configure
+++ b/configure
@@ -781,7 +781,6 @@ Darwin)
   fi
   audio_drv_list="coreaudio try-sdl"
   audio_possible_drivers="coreaudio sdl"
-  QEMU_LDFLAGS="-framework CoreFoundation -framework IOKit $QEMU_LDFLAGS"
   # Disable attempts to use ObjectiveC features in os/object.h since they
   # won't work when we're compiling with gcc as a C compiler.
   QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
-- 
2.28.0




[PATCH v7 07/11] darwin: fix cross-compiling for Darwin

2021-01-22 Thread Joelle van Dyne
Add objc to the Meson cross file as well as detection of Darwin.

Signed-off-by: Joelle van Dyne 
---
 configure | 4 
 1 file changed, 4 insertions(+)

diff --git a/configure b/configure
index 4c485dd962..7e5ec7a5a1 100755
--- a/configure
+++ b/configure
@@ -6443,6 +6443,7 @@ echo "cpp_link_args = [${LDFLAGS:+$(meson_quote 
$LDFLAGS)}]" >> $cross
 echo "[binaries]" >> $cross
 echo "c = [$(meson_quote $cc)]" >> $cross
 test -n "$cxx" && echo "cpp = [$(meson_quote $cxx)]" >> $cross
+test -n "$objcc" && echo "objc = [$(meson_quote $objcc)]" >> $cross
 echo "ar = [$(meson_quote $ar)]" >> $cross
 echo "nm = [$(meson_quote $nm)]" >> $cross
 echo "pkgconfig = [$(meson_quote $pkg_config_exe)]" >> $cross
@@ -6461,6 +6462,9 @@ if test "$cross_compile" = "yes"; then
 if test "$linux" = "yes" ; then
 echo "system = 'linux'" >> $cross
 fi
+if test "$darwin" = "yes" ; then
+echo "system = 'darwin'" >> $cross
+fi
 case "$ARCH" in
 i386|x86_64)
 echo "cpu_family = 'x86'" >> $cross
-- 
2.28.0




[PATCH v7 02/11] configure: cross-compiling with empty cross_prefix

2021-01-22 Thread Joelle van Dyne
The iOS toolchain does not use the host prefix naming convention. So we
need to enable cross-compile options while allowing the PREFIX to be
blank.

Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: Joelle van Dyne 
---
 configure | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index acf7f7414a..32be5d225d 100755
--- a/configure
+++ b/configure
@@ -238,6 +238,7 @@ cpu=""
 iasl="iasl"
 interp_prefix="/usr/gnemul/qemu-%M"
 static="no"
+cross_compile="no"
 cross_prefix=""
 audio_drv_list=""
 block_drv_rw_whitelist=""
@@ -469,6 +470,7 @@ for opt do
   optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
   case "$opt" in
   --cross-prefix=*) cross_prefix="$optarg"
+cross_compile="yes"
   ;;
   --cc=*) CC="$optarg"
   ;;
@@ -1696,7 +1698,7 @@ $(echo Deprecated targets: $deprecated_targets_list | \
   --target-list-exclude=LIST exclude a set of targets from the default 
target-list
 
 Advanced options (experts only):
-  --cross-prefix=PREFIXuse PREFIX for compile tools [$cross_prefix]
+  --cross-prefix=PREFIXuse PREFIX for compile tools, PREFIX can be blank 
[$cross_prefix]
   --cc=CC  use C compiler CC [$cc]
   --iasl=IASL  use ACPI compiler IASL [$iasl]
   --host-cc=CC use C compiler CC [$host_cc] for code run at
@@ -6403,7 +6405,7 @@ if has $sdl2_config; then
 fi
 echo "strip = [$(meson_quote $strip)]" >> $cross
 echo "windres = [$(meson_quote $windres)]" >> $cross
-if test -n "$cross_prefix"; then
+if test "$cross_compile" = "yes"; then
 cross_arg="--cross-file config-meson.cross"
 echo "[host_machine]" >> $cross
 if test "$mingw32" = "yes" ; then
-- 
2.28.0




[PATCH v7 11/11] darwin: remove 64-bit build detection on 32-bit OS

2021-01-22 Thread Joelle van Dyne
A workaround added in early days of 64-bit OSX forced x86_64 if the
host machine had 64-bit support. This creates issues when cross-
compiling for ARM64. Additionally, the user can always use --cpu=* to
manually set the host CPU and therefore this workaround should be
removed.

Signed-off-by: Joelle van Dyne 
---
 configure | 11 ---
 1 file changed, 11 deletions(-)

diff --git a/configure b/configure
index fb671258e6..c7fbda22b9 100755
--- a/configure
+++ b/configure
@@ -626,13 +626,6 @@ fi
 # the correct CPU with the --cpu option.
 case $targetos in
 Darwin)
-  # on Leopard most of the system is 32-bit, so we have to ask the kernel if 
we can
-  # run 64-bit userspace code.
-  # If the user didn't specify a CPU explicitly and the kernel says this is
-  # 64 bit hw, then assume x86_64. Otherwise fall through to the usual 
detection code.
-  if test -z "$cpu" && test "$(sysctl -n hw.optional.x86_64)" = "1"; then
-cpu="x86_64"
-  fi
   HOST_DSOSUF=".dylib"
   ;;
 SunOS)
@@ -776,10 +769,6 @@ OpenBSD)
 Darwin)
   bsd="yes"
   darwin="yes"
-  if [ "$cpu" = "x86_64" ] ; then
-QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS"
-QEMU_LDFLAGS="-arch x86_64 $QEMU_LDFLAGS"
-  fi
   audio_drv_list="try-coreaudio try-sdl"
   audio_possible_drivers="coreaudio sdl"
   # Disable attempts to use ObjectiveC features in os/object.h since they
-- 
2.28.0




[PATCH v7 04/11] slirp: feature detection for smbd

2021-01-22 Thread Joelle van Dyne
Replace Windows specific macro with a more generic feature detection
macro. Allows slirp smb feature to be disabled manually as well.

Signed-off-by: Joelle van Dyne 
---
 configure   | 22 +-
 meson.build |  2 +-
 net/slirp.c | 16 
 3 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/configure b/configure
index 951de427bb..92da27846e 100755
--- a/configure
+++ b/configure
@@ -464,6 +464,7 @@ fuse="auto"
 fuse_lseek="auto"
 
 malloc_trim="auto"
+slirp_smbd="auto"
 
 # parse CC options second
 for opt do
@@ -845,7 +846,18 @@ do
 fi
 done
 
+# Check for smbd dupport
 : ${smbd=${SMBD-/usr/sbin/smbd}}
+if test "$slirp_smbd" != "no" ; then
+  if test "$mingw32" = "yes" ; then
+if test "$slirp_smbd" = "yes" ; then
+  error_exit "Host smbd not supported on this platform."
+fi
+slirp_smbd=no
+  else
+slirp_smbd=yes
+  fi
+fi
 
 # Default objcc to clang if available, otherwise use CC
 if has clang; then
@@ -1560,6 +1572,10 @@ for opt do
   ;;
   --disable-fuse-lseek) fuse_lseek="disabled"
   ;;
+  --enable-slirp-smbd) slirp_smbd=yes
+  ;;
+  --disable-slirp-smbd) slirp_smbd=no
+  ;;
   *)
   echo "ERROR: unknown option $opt"
   echo "Try '$0 --help' for more information"
@@ -1899,6 +1915,7 @@ disabled with --disable-FEATURE, default is enabled if 
available
   libdaxctl   libdaxctl support
   fuseFUSE block device export
   fuse-lseek  SEEK_HOLE/SEEK_DATA support for FUSE exports
+  slirp-smbd  use smbd (at path --smbd=*) in slirp networking
 
 NOTE: The object files are built at the place where configure is launched
 EOF
@@ -5595,7 +5612,10 @@ fi
 if test "$guest_agent" = "yes" ; then
   echo "CONFIG_GUEST_AGENT=y" >> $config_host_mak
 fi
-echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak
+if test "$slirp_smbd" = "yes" ; then
+  echo "CONFIG_SLIRP_SMBD=y" >> $config_host_mak
+  echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak
+fi
 if test "$vde" = "yes" ; then
   echo "CONFIG_VDE=y" >> $config_host_mak
   echo "VDE_LIBS=$vde_libs" >> $config_host_mak
diff --git a/meson.build b/meson.build
index 6c3ee7f8ca..9577138d7f 100644
--- a/meson.build
+++ b/meson.build
@@ -2331,7 +2331,7 @@ summary_info += {'sphinx-build':  
sphinx_build.found()}
 summary_info += {'genisoimage':   config_host['GENISOIMAGE']}
 # TODO: add back version
 summary_info += {'slirp support': slirp_opt == 'disabled' ? false : 
slirp_opt}
-if slirp_opt != 'disabled'
+if slirp_opt != 'disabled' and 'HAVE_HOST_SMBD' in config_host
   summary_info += {'smbd':config_host['CONFIG_SMBD_COMMAND']}
 endif
 summary_info += {'module support':config_host.has_key('CONFIG_MODULES')}
diff --git a/net/slirp.c b/net/slirp.c
index 8350c6d45f..4348e74805 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -27,7 +27,7 @@
 #include "net/slirp.h"
 
 
-#ifndef _WIN32
+#if defined(CONFIG_SLIRP_SMBD)
 #include 
 #include 
 #endif
@@ -90,7 +90,7 @@ typedef struct SlirpState {
 Slirp *slirp;
 Notifier poll_notifier;
 Notifier exit_notifier;
-#ifndef _WIN32
+#if defined(CONFIG_SLIRP_SMBD)
 gchar *smb_dir;
 #endif
 GSList *fwd;
@@ -103,7 +103,7 @@ static QTAILQ_HEAD(, SlirpState) slirp_stacks =
 static int slirp_hostfwd(SlirpState *s, const char *redir_str, Error **errp);
 static int slirp_guestfwd(SlirpState *s, const char *config_str, Error **errp);
 
-#ifndef _WIN32
+#if defined(CONFIG_SLIRP_SMBD)
 static int slirp_smb(SlirpState *s, const char *exported_dir,
  struct in_addr vserver_addr, Error **errp);
 static void slirp_smb_cleanup(SlirpState *s);
@@ -367,7 +367,7 @@ static int net_slirp_init(NetClientState *peer, const char 
*model,
 struct in6_addr ip6_prefix;
 struct in6_addr ip6_host;
 struct in6_addr ip6_dns;
-#ifndef _WIN32
+#if defined(CONFIG_SLIRP_SMBD)
 struct in_addr smbsrv = { .s_addr = 0 };
 #endif
 NetClientState *nc;
@@ -477,7 +477,7 @@ static int net_slirp_init(NetClientState *peer, const char 
*model,
 return -1;
 }
 
-#ifndef _WIN32
+#if defined(CONFIG_SLIRP_SMBD)
 if (vsmbserver && !inet_aton(vsmbserver, )) {
 error_setg(errp, "Failed to parse SMB address");
 return -1;
@@ -592,7 +592,7 @@ static int net_slirp_init(NetClientState *peer, const char 
*model,
 }
 }
 }
-#ifndef _WIN32
+#if defined(CONFIG_SLIRP_SMBD)
 if (smb_export) {
 if (slirp_smb(s, smb_export, smbsrv, errp) < 0) {
 goto error;
@@ -784,7 +784,7 @@ void hmp_hostfwd_add(Monitor *mon, const QDict *qdict)
 
 }
 
-#ifndef _WIN32
+#if defined(CONFIG_SLIRP_SMBD)
 
 /* automatic user mode samba server configuration */
 static void slirp_smb_cleanup(SlirpState *s)
@@ -899,7 +899,7 @@ static int slirp_smb(SlirpState* s, const char 
*exported_dir,
 return 0;
 }
 
-#endif /* !defined(_WIN32) */
+#endif /* defined(CONFIG_SLIRP_SMBD) */
 
 static int guestfwd_can_read(void *opaque)
 {
-- 
2.28.0




[PATCH v7 09/11] block: check availablity for preadv/pwritev on mac

2021-01-22 Thread Joelle van Dyne
macOS 11/iOS 14 added preadv/pwritev APIs. Due to weak linking, configure
will succeed with CONFIG_PREADV even when targeting a lower OS version.
We therefore need to check at run time if we can actually use these APIs.

Signed-off-by: Joelle van Dyne 
---
 block/file-posix.c | 33 +
 1 file changed, 33 insertions(+)

diff --git a/block/file-posix.c b/block/file-posix.c
index 666d3e7504..6473f84db8 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -1386,17 +1386,50 @@ static int handle_aiocb_flush(void *opaque)
 #ifdef CONFIG_PREADV
 
 static bool preadv_present = true;
+static bool preadv_checked;
 
 static ssize_t
 qemu_preadv(int fd, const struct iovec *iov, int nr_iov, off_t offset)
 {
+#ifdef CONFIG_DARWIN /* preadv introduced in macOS 11 */
+if (unlikely(!preadv_checked)) {
+if (__builtin_available(macOS 11, iOS 14, watchOS 7, tvOS 14, *)) {
+preadv_checked = true;
+} else {
+preadv_present = false;
+return -ENOSYS;
+}
+}
+/* Now we suppress the availability warning since we use the cached check 
*/
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunguarded-availability-new"
+return preadv(fd, iov, nr_iov, offset);
+#pragma clang diagnostic pop
+#else /* CONFIG_DARWIN */
 return preadv(fd, iov, nr_iov, offset);
+#endif
 }
 
 static ssize_t
 qemu_pwritev(int fd, const struct iovec *iov, int nr_iov, off_t offset)
 {
+#ifdef CONFIG_DARWIN /* preadv introduced in macOS 11 */
+if (unlikely(!preadv_checked)) {
+if (__builtin_available(macOS 11, iOS 14, watchOS 7, tvOS 14, *)) {
+preadv_checked = true;
+} else {
+preadv_present = false;
+return -ENOSYS;
+}
+}
+/* Now we suppress the availability warning since we use the cached check 
*/
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunguarded-availability-new"
+return pwritev(fd, iov, nr_iov, offset);
+#pragma clang diagnostic pop
+#else /* CONFIG_DARWIN */
 return pwritev(fd, iov, nr_iov, offset);
+#endif
 }
 
 #else
-- 
2.28.0




[PATCH v7 01/11] block: feature detection for host block support

2021-01-22 Thread Joelle van Dyne
On Darwin (iOS), there are no system level APIs for directly accessing
host block devices. We detect this at configure time.

Signed-off-by: Joelle van Dyne 
---
 configure| 13 +
 meson.build  |  2 +-
 qapi/block-core.json | 10 +++---
 block/file-posix.c   | 33 ++---
 4 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/configure b/configure
index 6f6a319c2f..acf7f7414a 100755
--- a/configure
+++ b/configure
@@ -5283,6 +5283,16 @@ but not implemented on your system"
 fi
 fi
 
+##
+# check for host block device
+# assume always true for non-Darwin hosts
+
+if ! test "$darwin" == "yes" || check_include "IOKit/storage/IOMedia.h" ; then
+  have_host_block_device=yes
+else
+  have_host_block_device=no
+fi
+
 ##
 # End of CC checks
 # After here, no more $cc or $ld runs
@@ -5513,6 +5523,9 @@ echo "GIT_UPDATE=$git_update" >> $config_host_mak
 
 echo "ARCH=$ARCH" >> $config_host_mak
 
+if test "$have_host_block_device" = "yes" ; then
+  echo "HAVE_HOST_BLOCK_DEVICE=y" >> $config_host_mak
+fi
 if test "$debug_tcg" = "yes" ; then
   echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
 fi
diff --git a/meson.build b/meson.build
index af2bc89741..6c3ee7f8ca 100644
--- a/meson.build
+++ b/meson.build
@@ -180,7 +180,7 @@ if targetos == 'windows'
   include_directories: 
include_directories('.'))
 elif targetos == 'darwin'
   coref = dependency('appleframeworks', modules: 'CoreFoundation')
-  iokit = dependency('appleframeworks', modules: 'IOKit')
+  iokit = dependency('appleframeworks', modules: 'IOKit', required: 
'HAVE_HOST_BLOCK_DEVICE' in config_host)
 elif targetos == 'sunos'
   socket = [cc.find_library('socket'),
 cc.find_library('nsl'),
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 3484986d1c..1a9576de8d 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -959,7 +959,8 @@
   'discriminator': 'driver',
   'data': {
   'file': 'BlockStatsSpecificFile',
-  'host_device': 'BlockStatsSpecificFile',
+  'host_device': { 'type': 'BlockStatsSpecificFile',
+   'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' },
   'nvme': 'BlockStatsSpecificNvme' } }
 
 ##
@@ -2827,7 +2828,9 @@
 { 'enum': 'BlockdevDriver',
   'data': [ 'blkdebug', 'blklogwrites', 'blkreplay', 'blkverify', 'bochs',
 'cloop', 'compress', 'copy-on-read', 'dmg', 'file', 'ftp', 'ftps',
-'gluster', 'host_cdrom', 'host_device', 'http', 'https', 'iscsi',
+'gluster', 'host_cdrom',
+{'name': 'host_device', 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' },
+'http', 'https', 'iscsi',
 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels',
 'preallocate', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd',
 { 'name': 'replication', 'if': 'defined(CONFIG_REPLICATION)' },
@@ -4012,7 +4015,8 @@
   'ftps':   'BlockdevOptionsCurlFtps',
   'gluster':'BlockdevOptionsGluster',
   'host_cdrom': 'BlockdevOptionsFile',
-  'host_device':'BlockdevOptionsFile',
+  'host_device': { 'type': 'BlockdevOptionsFile',
+   'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' },
   'http':   'BlockdevOptionsCurlHttp',
   'https':  'BlockdevOptionsCurlHttps',
   'iscsi':  'BlockdevOptionsIscsi',
diff --git a/block/file-posix.c b/block/file-posix.c
index 00cdaaa2d4..11d2021346 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -42,6 +42,8 @@
 #include "scsi/constants.h"
 
 #if defined(__APPLE__) && (__MACH__)
+#include 
+#if defined(HAVE_HOST_BLOCK_DEVICE)
 #include 
 #include 
 #include 
@@ -52,6 +54,7 @@
 //#include 
 #include 
 #include 
+#endif /* defined(HAVE_HOST_BLOCK_DEVICE) */
 #endif
 
 #ifdef __sun__
@@ -181,7 +184,17 @@ typedef struct BDRVRawReopenState {
 bool check_cache_dropped;
 } BDRVRawReopenState;
 
-static int fd_open(BlockDriverState *bs);
+static int fd_open(BlockDriverState *bs)
+{
+BDRVRawState *s = bs->opaque;
+
+/* this is just to ensure s->fd is sane (its called by io ops) */
+if (s->fd >= 0) {
+return 0;
+}
+return -EIO;
+}
+
 static int64_t raw_getlength(BlockDriverState *bs);
 
 typedef struct RawPosixAIOData {
@@ -3014,6 +3027,7 @@ static BlockStatsSpecific 
*raw_get_specific_stats(BlockDriverState *bs)
 return stats;
 }
 
+#if defined(HAVE_HOST_BLOCK_DEVICE)
 static BlockStatsSpecific *hdev_get_specific_stats(BlockDriverState *bs)
 {
 BlockStatsSpecific *stats = g_new(BlockStatsSpecific, 1);
@@ -3023,6 +3037,7 @@ static BlockStatsSpecific 
*hdev_get_specific_stats(BlockDriverState *bs)
 
 return stats;
 }
+#endif /* HAVE_HOST_BLOCK_DEVICE */
 
 static QemuOptsList raw_create_opts = {
 .name = "raw-create-opts",
@@ -3247,6 +3262,8 @@ BlockDriver bdrv_file = {
 

[PATCH v7 00/11] iOS and Apple Silicon host support

2021-01-22 Thread Joelle van Dyne
These set of changes brings QEMU TCG to iOS devices and future Apple Silicon
devices. They were originally developed last year and have been working in the
UTM app. Recently, we ported the changes to master, re-wrote a lot of the build
script changes for meson, and broke up the patches into more distinct units.

The bulk of the changes allow for cross-compiling for both iOS and macOS running
Apple Silicon and adds feature detection for parts of QEMU that are not
compatible with iOS.

Since v7:

* Removed libucontext (will be submitted in another patchset)
* Removed slirp build flags update (superseded by subproject patchset)
* Reworked all patches to use feature detection instead of #ifdef CONFIG_IOS
* Added feature detection for CoreAudio
* Fix various cross compiling issues on macOS

Since v6:

* Dropped the Apple Silicon JIT support patch (superseded by another patchset)
* Changed libucontext to be a Meson subproject
* Cache availablity check for preadv/pwritev on macOS 11 and iOS 14

Since v5:

* Fixed some more instances of QAPI define of CONFIG_HOST_BLOCK_DEVICE
* Fixed libucontext build on newer version of GCC

Since v4:

* Updated QAPI schema for CONFIG_HOST_BLOCK_DEVICE
* Updated maintainers file for iOS host support
* Moved system() changes to osdep.h
* Fixed typo in libucontext meson.build change

Since v3:

* Moved mirror JIT support to a different patch set.
* Removed dependency on `pthread_jit_write_protect_np` because it was redundent
  and also crashes if called on a non-jailbroken iOS device.
* Removed `--enable-cross-compile` option
* Fixed checkpatch errors
* Fixed iOS build on master due to new test recently added which calls system()

Since v2:

* Changed getting mirror pointer from a macro to inline functions
* Split constification of TCG code pointers to separate patch
* Removed slirp updates (will send future patch once slirp changes are in)
* Removed shared library patch (will send future patch)

-j

Joelle van Dyne (11):
  block: feature detection for host block support
  configure: cross-compiling with empty cross_prefix
  configure: check for sys/disk.h
  slirp: feature detection for smbd
  osdep: build with non-working system() function
  darwin: remove redundant dependency declaration
  darwin: fix cross-compiling for Darwin
  configure: cross compile should use x86_64 cpu_family
  block: check availablity for preadv/pwritev on mac
  darwin: detect CoreAudio for build
  darwin: remove 64-bit build detection on 32-bit OS

 configure| 125 ---
 meson.build  |   4 +-
 qapi/block-core.json |  10 ++--
 include/qemu/osdep.h |  11 
 block.c  |   2 +-
 block/file-posix.c   |  68 ++-
 net/slirp.c  |  16 +++---
 7 files changed, 192 insertions(+), 44 deletions(-)

-- 
2.28.0




[PATCH v7 05/11] osdep: build with non-working system() function

2021-01-22 Thread Joelle van Dyne
Build without error on hosts without a working system(). An assertion
will trigger if system() is called.

Signed-off-by: Joelle van Dyne 
---
 configure| 19 +++
 include/qemu/osdep.h | 11 +++
 2 files changed, 30 insertions(+)

diff --git a/configure b/configure
index 92da27846e..82ce28c660 100755
--- a/configure
+++ b/configure
@@ -5318,6 +5318,21 @@ else
   sys_disk_h=no
 fi
 
+##
+# check for system()
+
+have_system_function=no
+cat > $TMPC << EOF
+#include 
+int main(void) {
+return system("");
+}
+EOF
+if compile_prog "" "" ; then
+have_system_function=yes
+fi
+
+
 ##
 # End of CC checks
 # After here, no more $cc or $ld runs
@@ -6222,6 +6237,10 @@ if test "$secret_keyring" = "yes" ; then
   echo "CONFIG_SECRET_KEYRING=y" >> $config_host_mak
 fi
 
+if test "$have_system_function" = "yes" ; then
+  echo "HAVE_SYSTEM_FUNCTION=y" >> $config_host_mak
+fi
+
 echo "ROMS=$roms" >> $config_host_mak
 echo "MAKE=$make" >> $config_host_mak
 echo "PYTHON=$python" >> $config_host_mak
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index a434382c58..73346c4349 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -682,4 +682,15 @@ char *qemu_get_host_name(Error **errp);
  */
 size_t qemu_get_host_physmem(void);
 
+/**
+ * Platforms which do not support system() gets an assertion failure.
+ */
+#ifndef HAVE_SYSTEM_FUNCTION
+#define system platform_does_not_support_system
+static inline int platform_does_not_support_system(const char *command)
+{
+assert(0);
+}
+#endif /* !HAVE_SYSTEM_FUNCTION */
+
 #endif
-- 
2.28.0




[PATCH v7 03/11] configure: check for sys/disk.h

2021-01-22 Thread Joelle van Dyne
Some BSD platforms do not have this header.

Signed-off-by: Joelle van Dyne 
---
 configure  | 9 +
 block.c| 2 +-
 block/file-posix.c | 2 +-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 32be5d225d..951de427bb 100755
--- a/configure
+++ b/configure
@@ -5295,6 +5295,12 @@ else
   have_host_block_device=no
 fi
 
+if check_include "sys/disk.h" ; then
+  sys_disk_h=yes
+else
+  sys_disk_h=no
+fi
+
 ##
 # End of CC checks
 # After here, no more $cc or $ld runs
@@ -5528,6 +5534,9 @@ echo "ARCH=$ARCH" >> $config_host_mak
 if test "$have_host_block_device" = "yes" ; then
   echo "HAVE_HOST_BLOCK_DEVICE=y" >> $config_host_mak
 fi
+if test "$sys_disk_h" = "yes" ; then
+  echo "HAVE_SYS_DISK_H=y" >> $config_host_mak
+fi
 if test "$debug_tcg" = "yes" ; then
   echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
 fi
diff --git a/block.c b/block.c
index 8b9d457546..c4cf391dea 100644
--- a/block.c
+++ b/block.c
@@ -54,7 +54,7 @@
 #ifdef CONFIG_BSD
 #include 
 #include 
-#ifndef __DragonFly__
+#if defined(HAVE_SYS_DISK_H)
 #include 
 #endif
 #endif
diff --git a/block/file-posix.c b/block/file-posix.c
index 11d2021346..666d3e7504 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -2320,7 +2320,7 @@ again:
 }
 if (size == 0)
 #endif
-#if defined(__APPLE__) && defined(__MACH__)
+#if defined(HAVE_SYS_DISK_H) && defined(__APPLE__) && defined(__MACH__)
 {
 uint64_t sectors = 0;
 uint32_t sector_size = 0;
-- 
2.28.0




[Bug 1912846] [NEW] Assertion hit on hot-unplugging virtio iommu enabled device

2021-01-22 Thread Eugenio Pérez
Public bug reported:

>From commit ("2d24a646 device-core: use RCU for
list of children of a bus") an assertion is hit when
removing a iommu aware virtio device, since as->listeners
are not properly removed. To reproduce:

/home/qemu/build/x86_64-softmmu/qemu-system-x86_64 -qmp 
tcp:0:,server,nowait ... \
-netdev tap,id=hostnet0,vhostforce=on,vhost=on \
-device 
virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:14:18:cc,bus=pci.1,addr=0x0,iommu_platform=on,ats=on

In QMP:
{'execute': 'qmp_capabilities'}
{"execute": "device_del", "arguments": {"id": "net0"} }

And crash:
../softmmu/memory.c:2818: do_address_space_destroy: Assertion 
`QTAILQ_EMPTY(>listeners)' failed.

** Affects: qemu
 Importance: Undecided
 Status: New


** Tags: iommu

** Description changed:

  From commit ("2d24a646 device-core: use RCU for
  list of children of a bus") an assertion is hit when
- removing a device, since mr->listeners are not properly
+ removing a device, since as->listeners are not properly
  removed. To reproduce:
  
  /home/qemu/build/x86_64-softmmu/qemu-system-x86_64 -qmp 
tcp:0:,server,nowait ... \
- -netdev tap,id=hostnet0,vhostforce=on,vhost=on \
- -device 
virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:14:18:cc,bus=pci.1,addr=0x0,iommu_platform=on,ats=on
+ -netdev tap,id=hostnet0,vhostforce=on,vhost=on \
+ -device 
virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:14:18:cc,bus=pci.1,addr=0x0,iommu_platform=on,ats=on
  
  In QMP:
  {'execute': 'qmp_capabilities'}
  {"execute": "device_del", "arguments": {"id": "net0"} }
  
  And crash:
  ../softmmu/memory.c:2818: do_address_space_destroy: Assertion 
`QTAILQ_EMPTY(>listeners)' failed.

** Description changed:

  From commit ("2d24a646 device-core: use RCU for
  list of children of a bus") an assertion is hit when
- removing a device, since as->listeners are not properly
- removed. To reproduce:
+ removing a iommu aware virtio device, since as->listeners
+ are not properly removed. To reproduce:
  
  /home/qemu/build/x86_64-softmmu/qemu-system-x86_64 -qmp 
tcp:0:,server,nowait ... \
  -netdev tap,id=hostnet0,vhostforce=on,vhost=on \
  -device 
virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:14:18:cc,bus=pci.1,addr=0x0,iommu_platform=on,ats=on
  
  In QMP:
  {'execute': 'qmp_capabilities'}
  {"execute": "device_del", "arguments": {"id": "net0"} }
  
  And crash:
  ../softmmu/memory.c:2818: do_address_space_destroy: Assertion 
`QTAILQ_EMPTY(>listeners)' failed.

** Summary changed:

- Assertion hit on hot-unplugging iommu enabled device
+ Assertion hit on hot-unplugging virtio iommu enabled device

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1912846

Title:
  Assertion hit on hot-unplugging virtio iommu enabled device

Status in QEMU:
  New

Bug description:
  From commit ("2d24a646 device-core: use RCU for
  list of children of a bus") an assertion is hit when
  removing a iommu aware virtio device, since as->listeners
  are not properly removed. To reproduce:

  /home/qemu/build/x86_64-softmmu/qemu-system-x86_64 -qmp 
tcp:0:,server,nowait ... \
  -netdev tap,id=hostnet0,vhostforce=on,vhost=on \
  -device 
virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:14:18:cc,bus=pci.1,addr=0x0,iommu_platform=on,ats=on

  In QMP:
  {'execute': 'qmp_capabilities'}
  {"execute": "device_del", "arguments": {"id": "net0"} }

  And crash:
  ../softmmu/memory.c:2818: do_address_space_destroy: Assertion 
`QTAILQ_EMPTY(>listeners)' failed.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1912846/+subscriptions



[PATCH] virtio: Add corresponding memory_listener_unregister to unrealize

2021-01-22 Thread Eugenio Pérez
Cannot destroy address spaces of IOMMU-aware virtio devices without it,
since they can contain memory listeners.

Fixes: c611c76417f ("virtio: add MemoryListener to cache ring translations")
Buglink: https://bugs.launchpad.net/qemu/+bug/1912846
Signed-off-by: Eugenio Pérez 
---
 hw/virtio/virtio.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index b308026596..67efd2c301 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -3680,6 +3680,7 @@ static void virtio_device_unrealize(DeviceState *dev)
 VirtIODevice *vdev = VIRTIO_DEVICE(dev);
 VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(dev);
 
+memory_listener_unregister(>listener);
 virtio_bus_device_unplugged(vdev);
 
 if (vdc->unrealize != NULL) {
-- 
2.27.0




Re: [PATCH 15/25] hw/arm/musca: Create and connect ARMSSE Clocks

2021-01-22 Thread Luc Michel
On 19:06 Thu 21 Jan , Peter Maydell wrote:
> Create and connect the two clocks needed by the ARMSSE.
> 
> Signed-off-by: Peter Maydell 

Reviewed-by: Luc Michel 

> ---
>  hw/arm/musca.c | 12 
>  1 file changed, 12 insertions(+)
> 
> diff --git a/hw/arm/musca.c b/hw/arm/musca.c
> index d82bef11cf2..a9292482a06 100644
> --- a/hw/arm/musca.c
> +++ b/hw/arm/musca.c
> @@ -33,6 +33,7 @@
>  #include "hw/misc/tz-ppc.h"
>  #include "hw/misc/unimp.h"
>  #include "hw/rtc/pl031.h"
> +#include "hw/qdev-clock.h"
>  #include "qom/object.h"
>  
>  #define MUSCA_NUMIRQ_MAX 96
> @@ -82,6 +83,8 @@ struct MuscaMachineState {
>  UnimplementedDeviceState sdio;
>  UnimplementedDeviceState gpio;
>  UnimplementedDeviceState cryptoisland;
> +Clock *sysclk;
> +Clock *s32kclk;
>  };
>  
>  #define TYPE_MUSCA_MACHINE "musca"
> @@ -96,6 +99,8 @@ OBJECT_DECLARE_TYPE(MuscaMachineState, MuscaMachineClass, 
> MUSCA_MACHINE)
>   * don't model that in our SSE-200 model yet.
>   */
>  #define SYSCLK_FRQ 4000
> +/* Slow 32Khz S32KCLK frequency in Hz */
> +#define S32KCLK_FRQ (32 * 1000)
>  
>  static qemu_irq get_sse_irq_in(MuscaMachineState *mms, int irqno)
>  {
> @@ -367,6 +372,11 @@ static void musca_init(MachineState *machine)
>  exit(1);
>  }
>  
> +mms->sysclk = clock_new(OBJECT(machine), "SYSCLK");
> +clock_set_hz(mms->sysclk, SYSCLK_FRQ);
> +mms->s32kclk = clock_new(OBJECT(machine), "S32KCLK");
> +clock_set_hz(mms->s32kclk, S32KCLK_FRQ);
> +
>  object_initialize_child(OBJECT(machine), "sse-200", >sse,
>  TYPE_SSE200);
>  ssedev = DEVICE(>sse);
> @@ -376,6 +386,8 @@ static void musca_init(MachineState *machine)
>  qdev_prop_set_uint32(ssedev, "init-svtor", mmc->init_svtor);
>  qdev_prop_set_uint32(ssedev, "SRAM_ADDR_WIDTH", mmc->sram_addr_width);
>  qdev_prop_set_uint32(ssedev, "MAINCLK_FRQ", SYSCLK_FRQ);
> +qdev_connect_clock_in(ssedev, "MAINCLK", mms->sysclk);
> +qdev_connect_clock_in(ssedev, "S32KCLK", mms->s32kclk);
>  /*
>   * Musca-A takes the default SSE-200 FPU/DSP settings (ie no for
>   * CPU0 and yes for CPU1); Musca-B1 explicitly enables them for CPU0.
> -- 
> 2.20.1
> 

-- 



  1   2   3   4   >