All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 0/7] iOS and Apple Silicon host support
@ 2021-01-05  2:20 Joelle van Dyne
  2021-01-05  2:20 ` [PATCH v6 1/7] configure: option to disable host block devices Joelle van Dyne
                   ` (7 more replies)
  0 siblings, 8 replies; 21+ messages in thread
From: Joelle van Dyne @ 2021-01-05  2:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: Roman Bolshakov, Joelle van Dyne

Based-on: 20201214140314.18544-1-richard.henderson@linaro.org
([PATCH v4 00/43] Mirror map JIT memory for TCG)

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.

A summary of the changes:

* `CONFIG_IOS` defined when building for iOS and iOS specific changes (as well
  as unsupported code) are gated behind it.
* A new dependency, libucontext is added since iOS does not have native ucontext
  and broken support for sigaltstack. libucontext is available as a new option
  for coroutine backend.

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 (7):
  configure: option to disable host block devices
  configure: cross-compiling with empty cross_prefix
  qemu: add support for iOS host
  coroutine: add libucontext as external library
  configure: cross compile should use x86_64 cpu_family
  slirp: update build flags for iOS resolv fix
  block: check availablity for preadv/pwritev on mac

 docs/devel/index.rst      |  1 +
 docs/devel/ios.rst        | 28 ++++++++++++++
 configure                 | 81 +++++++++++++++++++++++++++++++++++----
 meson.build               | 16 +++++++-
 qapi/block-core.json      | 10 +++--
 include/qemu/osdep.h      | 11 ++++++
 block.c                   |  2 +-
 block/file-posix.c        | 74 ++++++++++++++++++++++++++++-------
 net/slirp.c               | 16 ++++----
 qga/commands-posix.c      |  6 +++
 util/coroutine-ucontext.c |  9 +++++
 .gitmodules               |  3 ++
 MAINTAINERS               |  7 ++++
 meson_options.txt         |  2 +
 subprojects/libucontext   |  1 +
 tests/qtest/meson.build   |  7 ++--
 16 files changed, 236 insertions(+), 38 deletions(-)
 create mode 100644 docs/devel/ios.rst
 create mode 160000 subprojects/libucontext

-- 
2.28.0



^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v6 1/7] configure: option to disable host block devices
  2021-01-05  2:20 [PATCH v6 0/7] iOS and Apple Silicon host support Joelle van Dyne
@ 2021-01-05  2:20 ` Joelle van Dyne
  2021-01-05  2:20 ` [PATCH v6 2/7] configure: cross-compiling with empty cross_prefix Joelle van Dyne
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 21+ messages in thread
From: Joelle van Dyne @ 2021-01-05  2:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, open list:raw, Markus Armbruster, Max Reitz,
	Roman Bolshakov, Joelle van Dyne

Some hosts (iOS) have a sandboxed filesystem and do not provide low-level
APIs for interfacing with host block devices.

Signed-off-by: Joelle van Dyne <j@getutm.app>
---
 configure            |  4 ++++
 meson.build          |  1 +
 qapi/block-core.json | 10 +++++++---
 block/file-posix.c   | 10 +++++++++-
 4 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/configure b/configure
index 3f823ed163..7cd2ee0b9c 100755
--- a/configure
+++ b/configure
@@ -451,6 +451,7 @@ skip_meson=no
 gettext=""
 fuse="auto"
 fuse_lseek="auto"
+host_block_device_support="yes"
 
 bogus_os="no"
 malloc_trim="auto"
@@ -5937,6 +5938,9 @@ if test "$default_devices" = "yes" ; then
 else
   echo "CONFIG_MINIKCONF_MODE=--allnoconfig" >> $config_host_mak
 fi
+if test "$host_block_device_support" = "yes" ; then
+  echo "CONFIG_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 f344b25955..9a640d3407 100644
--- a/meson.build
+++ b/meson.build
@@ -2219,6 +2219,7 @@ summary_info += {'vvfat support':     config_host.has_key('CONFIG_VVFAT')}
 summary_info += {'qed support':       config_host.has_key('CONFIG_QED')}
 summary_info += {'parallels support': config_host.has_key('CONFIG_PARALLELS')}
 summary_info += {'sheepdog support':  config_host.has_key('CONFIG_SHEEPDOG')}
+summary_info += {'host block dev support': config_host.has_key('CONFIG_HOST_BLOCK_DEVICE')}
 summary_info += {'capstone':          capstone_opt == 'disabled' ? false : capstone_opt}
 summary_info += {'libpmem support':   config_host.has_key('CONFIG_LIBPMEM')}
 summary_info += {'libdaxctl support': config_host.has_key('CONFIG_LIBDAXCTL')}
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 04c5196e59..516b823461 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(CONFIG_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(CONFIG_HOST_BLOCK_DEVICE)' },
+            'http', 'https', 'iscsi',
             'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels',
             'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd',
             { 'name': 'replication', 'if': 'defined(CONFIG_REPLICATION)' },
@@ -3995,7 +3998,8 @@
       'ftps':       'BlockdevOptionsCurlFtps',
       'gluster':    'BlockdevOptionsGluster',
       'host_cdrom': 'BlockdevOptionsFile',
-      'host_device':'BlockdevOptionsFile',
+      'host_device': { 'type': 'BlockdevOptionsFile',
+                       'if': 'defined(CONFIG_HOST_BLOCK_DEVICE)' },
       'http':       'BlockdevOptionsCurlHttp',
       'https':      'BlockdevOptionsCurlHttps',
       'iscsi':      'BlockdevOptionsIscsi',
diff --git a/block/file-posix.c b/block/file-posix.c
index 83e2cc5530..c34bb9fac1 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -41,7 +41,7 @@
 #include "scsi/pr-manager.h"
 #include "scsi/constants.h"
 
-#if defined(__APPLE__) && (__MACH__)
+#if defined(CONFIG_HOST_BLOCK_DEVICE) && defined(__APPLE__) && (__MACH__)
 #include <paths.h>
 #include <sys/param.h>
 #include <IOKit/IOKitLib.h>
@@ -3014,6 +3014,7 @@ static BlockStatsSpecific *raw_get_specific_stats(BlockDriverState *bs)
     return stats;
 }
 
+#if defined(CONFIG_HOST_BLOCK_DEVICE)
 static BlockStatsSpecific *hdev_get_specific_stats(BlockDriverState *bs)
 {
     BlockStatsSpecific *stats = g_new(BlockStatsSpecific, 1);
@@ -3023,6 +3024,7 @@ static BlockStatsSpecific *hdev_get_specific_stats(BlockDriverState *bs)
 
     return stats;
 }
+#endif /* CONFIG_HOST_BLOCK_DEVICE */
 
 static QemuOptsList raw_create_opts = {
     .name = "raw-create-opts",
@@ -3247,6 +3249,8 @@ BlockDriver bdrv_file = {
 /***********************************************/
 /* host device */
 
+#if defined(CONFIG_HOST_BLOCK_DEVICE)
+
 #if defined(__APPLE__) && defined(__MACH__)
 static kern_return_t GetBSDPath(io_iterator_t mediaIterator, char *bsdPath,
                                 CFIndex maxPathSize, int flags);
@@ -3872,6 +3876,8 @@ static BlockDriver bdrv_host_cdrom = {
 };
 #endif /* __FreeBSD__ */
 
+#endif /* CONFIG_HOST_BLOCK_DEVICE */
+
 static void bdrv_file_init(void)
 {
     /*
@@ -3879,6 +3885,7 @@ static void bdrv_file_init(void)
      * registered last will get probed first.
      */
     bdrv_register(&bdrv_file);
+#if defined(CONFIG_HOST_BLOCK_DEVICE)
     bdrv_register(&bdrv_host_device);
 #ifdef __linux__
     bdrv_register(&bdrv_host_cdrom);
@@ -3886,6 +3893,7 @@ static void bdrv_file_init(void)
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
     bdrv_register(&bdrv_host_cdrom);
 #endif
+#endif /* CONFIG_HOST_BLOCK_DEVICE */
 }
 
 block_init(bdrv_file_init);
-- 
2.28.0



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v6 2/7] configure: cross-compiling with empty cross_prefix
  2021-01-05  2:20 [PATCH v6 0/7] iOS and Apple Silicon host support Joelle van Dyne
  2021-01-05  2:20 ` [PATCH v6 1/7] configure: option to disable host block devices Joelle van Dyne
@ 2021-01-05  2:20 ` Joelle van Dyne
  2021-01-05  2:20 ` [PATCH v6 3/7] qemu: add support for iOS host Joelle van Dyne
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 21+ messages in thread
From: Joelle van Dyne @ 2021-01-05  2:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: Roman Bolshakov, Philippe Mathieu-Daudé, 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é <f4bug@amsat.org>
Signed-off-by: Joelle van Dyne <j@getutm.app>
---
 configure | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 7cd2ee0b9c..744d1990be 100755
--- a/configure
+++ b/configure
@@ -234,6 +234,7 @@ cpu=""
 iasl="iasl"
 interp_prefix="/usr/gnemul/qemu-%M"
 static="no"
+cross_compile="no"
 cross_prefix=""
 audio_drv_list=""
 block_drv_rw_whitelist=""
@@ -461,6 +462,7 @@ for opt do
   optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
   case "$opt" in
   --cross-prefix=*) cross_prefix="$optarg"
+                    cross_compile="yes"
   ;;
   --cc=*) CC="$optarg"
   ;;
@@ -1674,7 +1676,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=PREFIX    use PREFIX for compile tools [$cross_prefix]
+  --cross-prefix=PREFIX    use 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
@@ -6963,7 +6965,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



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v6 3/7] qemu: add support for iOS host
  2021-01-05  2:20 [PATCH v6 0/7] iOS and Apple Silicon host support Joelle van Dyne
  2021-01-05  2:20 ` [PATCH v6 1/7] configure: option to disable host block devices Joelle van Dyne
  2021-01-05  2:20 ` [PATCH v6 2/7] configure: cross-compiling with empty cross_prefix Joelle van Dyne
@ 2021-01-05  2:20 ` Joelle van Dyne
  2021-01-12 11:56   ` Philippe Mathieu-Daudé
                     ` (2 more replies)
  2021-01-05  2:20 ` [PATCH v6 4/7] coroutine: add libucontext as external library Joelle van Dyne
                   ` (4 subsequent siblings)
  7 siblings, 3 replies; 21+ messages in thread
From: Joelle van Dyne @ 2021-01-05  2:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Laurent Vivier, Thomas Huth,
	open list:Block layer core, Jason Wang, Michael Roth, Max Reitz,
	Roman Bolshakov, Joelle van Dyne, Paolo Bonzini, Samuel Thibault

This introduces support for building for iOS hosts. When the correct Xcode
toolchain is used, iOS host will be detected automatically.

* block: disable features not supported by iOS sandbox
* slirp: disable SMB features for iOS
* osdep: disable system() calls for iOS

Signed-off-by: Joelle van Dyne <j@getutm.app>
---
 docs/devel/index.rst    |  1 +
 docs/devel/ios.rst      | 28 +++++++++++++++++++++++++++
 configure               | 43 ++++++++++++++++++++++++++++++++++++++++-
 meson.build             |  2 +-
 include/qemu/osdep.h    | 11 +++++++++++
 block.c                 |  2 +-
 block/file-posix.c      | 31 +++++++++++++++++------------
 net/slirp.c             | 16 +++++++--------
 qga/commands-posix.c    |  6 ++++++
 MAINTAINERS             |  7 +++++++
 tests/qtest/meson.build |  7 +++----
 11 files changed, 127 insertions(+), 27 deletions(-)
 create mode 100644 docs/devel/ios.rst

diff --git a/docs/devel/index.rst b/docs/devel/index.rst
index f10ed77e4c..2cc8a13ebe 100644
--- a/docs/devel/index.rst
+++ b/docs/devel/index.rst
@@ -35,3 +35,4 @@ Contents:
    clocks
    qom
    block-coroutine-wrapper
+   ios
diff --git a/docs/devel/ios.rst b/docs/devel/ios.rst
new file mode 100644
index 0000000000..b4ab11bec1
--- /dev/null
+++ b/docs/devel/ios.rst
@@ -0,0 +1,28 @@
+===========
+iOS Support
+===========
+
+To run qemu on the iOS platform, some modifications were required. Most of the
+modifications are conditioned on the ``CONFIG_IOS`` and configuration variable.
+
+Build support
+-------------
+
+For the code to compile, certain changes in the block driver and the slirp
+driver had to be made. There is no ``system()`` call, so it has been replaced
+with an assertion error. There should be no code path that call system() from
+iOS.
+
+``ucontext`` support is broken on iOS. The implementation from ``libucontext``
+is used instead.
+
+JIT support
+-----------
+
+On iOS, allocating RWX pages require special entitlements not usually granted to
+apps. However, it is possible to use `bulletproof JIT`_ with a development
+certificate. This means that we need to allocate one chunk of memory with RX
+permissions and then mirror map the same memory with RW permissions. We generate
+code to the mirror mapping and execute the original mapping.
+
+.. _bulletproof JIT: https://www.blackhat.com/docs/us-16/materials/us-16-Krstic.pdf
diff --git a/configure b/configure
index 744d1990be..c1a08f0171 100755
--- a/configure
+++ b/configure
@@ -560,6 +560,19 @@ EOF
   compile_object
 }
 
+check_ios() {
+  cat > $TMPC <<EOF
+#ifdef __APPLE__
+#import "TargetConditionals.h"
+#if !TARGET_OS_IPHONE
+#error TARGET_OS_IPHONE not true
+#endif
+#endif
+int main(void) { return 0; }
+EOF
+  compile_object
+}
+
 check_include() {
 cat > $TMPC <<EOF
 #include <$1>
@@ -602,7 +615,11 @@ elif check_define __DragonFly__ ; then
 elif check_define __NetBSD__; then
   targetos='NetBSD'
 elif check_define __APPLE__; then
-  targetos='Darwin'
+  if check_ios ; then
+    targetos='iOS'
+  else
+    targetos='Darwin'
+  fi
 else
   # This is a fatal error, but don't report it yet, because we
   # might be going to just print the --help text, or it might
@@ -779,6 +796,22 @@ Darwin)
   # won't work when we're compiling with gcc as a C compiler.
   QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
 ;;
+iOS)
+  bsd="yes"
+  darwin="yes"
+  ios="yes"
+  if [ "$cpu" = "x86_64" ] ; then
+    QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS"
+    QEMU_LDFLAGS="-arch x86_64 $QEMU_LDFLAGS"
+  fi
+  host_block_device_support="no"
+  audio_drv_list=""
+  audio_possible_drivers=""
+  QEMU_LDFLAGS="-framework CoreFoundation $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"
+;;
 SunOS)
   solaris="yes"
   make="${MAKE-gmake}"
@@ -5992,6 +6025,10 @@ if test "$darwin" = "yes" ; then
   echo "CONFIG_DARWIN=y" >> $config_host_mak
 fi
 
+if test "$ios" = "yes" ; then
+  echo "CONFIG_IOS=y" >> $config_host_mak
+fi
+
 if test "$solaris" = "yes" ; then
   echo "CONFIG_SOLARIS=y" >> $config_host_mak
 fi
@@ -6956,6 +6993,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
@@ -6974,6 +7012,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
diff --git a/meson.build b/meson.build
index 9a640d3407..ee333b7a94 100644
--- a/meson.build
+++ b/meson.build
@@ -181,7 +181,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: 'CONFIG_IOS' not in config_host)
   cocoa = dependency('appleframeworks', modules: 'Cocoa', required: get_option('cocoa'))
 elif targetos == 'sunos'
   socket = [cc.find_library('socket'),
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index f9ec8c84e9..eb8d06cbf5 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -686,4 +686,15 @@ char *qemu_get_host_name(Error **errp);
  */
 size_t qemu_get_host_physmem(void);
 
+/**
+ * iOS does not support system() so we replace it with an assertion failure.
+ */
+#ifdef CONFIG_IOS
+#define system ios_does_not_support_system
+static inline int ios_does_not_support_system(const char *command)
+{
+    assert(0);
+}
+#endif /* CONFIG_IOS */
+
 #endif
diff --git a/block.c b/block.c
index 8f177504d4..984a73a82c 100644
--- a/block.c
+++ b/block.c
@@ -54,7 +54,7 @@
 #ifdef CONFIG_BSD
 #include <sys/ioctl.h>
 #include <sys/queue.h>
-#ifndef __DragonFly__
+#if !defined(__DragonFly__) && !defined(CONFIG_IOS)
 #include <sys/disk.h>
 #endif
 #endif
diff --git a/block/file-posix.c b/block/file-posix.c
index c34bb9fac1..9f556322e6 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -181,7 +181,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 {
@@ -252,6 +262,12 @@ static int raw_normalize_devicepath(const char **filename, Error **errp)
 }
 #endif
 
+#if defined(CONFIG_IOS)
+static int probe_logical_blocksize(int fd, unsigned int *sector_size_p)
+{
+    return -ENOTSUP; /* not supported on iOS */
+}
+#else /* CONFIG_IOS */
 /*
  * Get logical block size via ioctl. On success store it in @sector_size_p.
  */
@@ -284,6 +300,7 @@ static int probe_logical_blocksize(int fd, unsigned int *sector_size_p)
 
     return success ? 0 : -errno;
 }
+#endif /* !CONFIG_IOS */
 
 /**
  * Get physical block size of @fd.
@@ -2307,7 +2324,7 @@ again:
         }
         if (size == 0)
 #endif
-#if defined(__APPLE__) && defined(__MACH__)
+#if !defined(CONFIG_IOS) && defined(__APPLE__) && defined(__MACH__)
         {
             uint64_t sectors = 0;
             uint32_t sector_size = 0;
@@ -3543,16 +3560,6 @@ hdev_co_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
 }
 #endif /* linux */
 
-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 coroutine_fn int
 hdev_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)
 {
diff --git a/net/slirp.c b/net/slirp.c
index 77042e6df7..8413042c09 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -27,7 +27,7 @@
 #include "net/slirp.h"
 
 
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(CONFIG_IOS)
 #include <pwd.h>
 #include <sys/wait.h>
 #endif
@@ -90,7 +90,7 @@ typedef struct SlirpState {
     Slirp *slirp;
     Notifier poll_notifier;
     Notifier exit_notifier;
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(CONFIG_IOS)
     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(_WIN32) && !defined(CONFIG_IOS)
 static int slirp_smb(SlirpState *s, const char *exported_dir,
                      struct in_addr vserver_addr, Error **errp);
 static void slirp_smb_cleanup(SlirpState *s);
@@ -368,7 +368,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(_WIN32) && !defined(CONFIG_IOS)
     struct in_addr smbsrv = { .s_addr = 0 };
 #endif
     NetClientState *nc;
@@ -478,7 +478,7 @@ static int net_slirp_init(NetClientState *peer, const char *model,
         return -1;
     }
 
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(CONFIG_IOS)
     if (vsmbserver && !inet_aton(vsmbserver, &smbsrv)) {
         error_setg(errp, "Failed to parse SMB address");
         return -1;
@@ -593,7 +593,7 @@ static int net_slirp_init(NetClientState *peer, const char *model,
             }
         }
     }
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(CONFIG_IOS)
     if (smb_export) {
         if (slirp_smb(s, smb_export, smbsrv, errp) < 0) {
             goto error;
@@ -785,7 +785,7 @@ void hmp_hostfwd_add(Monitor *mon, const QDict *qdict)
 
 }
 
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(CONFIG_IOS)
 
 /* automatic user mode samba server configuration */
 static void slirp_smb_cleanup(SlirpState *s)
@@ -900,7 +900,7 @@ static int slirp_smb(SlirpState* s, const char *exported_dir,
     return 0;
 }
 
-#endif /* !defined(_WIN32) */
+#endif /* !defined(_WIN32) && !defined(CONFIG_IOS) */
 
 static int guestfwd_can_read(void *opaque)
 {
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index c089e38120..81e40ac14a 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -34,6 +34,12 @@
 
 #ifndef CONFIG_HAS_ENVIRON
 #ifdef __APPLE__
+#include "TargetConditionals.h"
+#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
+#define APPLE_USE_CRT_EXTERNS
+#endif
+#endif
+#ifdef APPLE_USE_CRT_EXTERNS
 #include <crt_externs.h>
 #define environ (*_NSGetEnviron())
 #else
diff --git a/MAINTAINERS b/MAINTAINERS
index ce5ef9bde6..3baf289a1d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -538,6 +538,13 @@ F: include/*/*win32*
 X: qga/*win32*
 F: qemu.nsi
 
+IOS
+M: Joelle van Dyne <j@getutm.app>
+S: Maintained
+K: ^Subject:.*(?i)iOS
+F: docs/devel/ios.rst
+F: include/tcg/tcg-apple-jit.h
+
 Alpha Machines
 --------------
 M: Richard Henderson <richard.henderson@linaro.org>
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 6a67c538be..42b46a7ca4 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -46,12 +46,11 @@ qtests_i386 = \
   (config_all_devices.has_key('CONFIG_TPM_TIS_ISA') ? ['tpm-tis-test'] : []) +              \
   (config_all_devices.has_key('CONFIG_TPM_TIS_ISA') ? ['tpm-tis-swtpm-test'] : []) +        \
   (config_all_devices.has_key('CONFIG_RTL8139_PCI') ? ['rtl8139-test'] : []) +              \
+  (not config_host.has_key('CONFIG_IOS') ? ['bios-tables-test', 'hd-geo-test'] : []) +      \
   qtests_pci +                                                                              \
   ['fdc-test',
    'ide-test',
-   'hd-geo-test',
    'boot-order-test',
-   'bios-tables-test',
    'rtc-test',
    'i440fx-test',
    'fuzz-test',
@@ -148,9 +147,9 @@ qtests_arm = \
    'boot-serial-test',
    'hexloader-test']
 
-# TODO: once aarch64 TCG is fixed on ARM 32 bit host, make bios-tables-test unconditional
+# TODO: once aarch64 TCG is fixed on ARM 32 bit host, make bios-tables-test unconditional (except on iOS)
 qtests_aarch64 = \
-  (cpu != 'arm' ? ['bios-tables-test'] : []) +                                                  \
+  (cpu != 'arm' and not config_host.has_key('CONFIG_IOS') ? ['bios-tables-test'] : []) +        \
   (config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? ['tpm-tis-device-test'] : []) +        \
   (config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? ['tpm-tis-device-swtpm-test'] : []) +  \
   ['arm-cpu-features',
-- 
2.28.0



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v6 4/7] coroutine: add libucontext as external library
  2021-01-05  2:20 [PATCH v6 0/7] iOS and Apple Silicon host support Joelle van Dyne
                   ` (2 preceding siblings ...)
  2021-01-05  2:20 ` [PATCH v6 3/7] qemu: add support for iOS host Joelle van Dyne
@ 2021-01-05  2:20 ` Joelle van Dyne
  2021-01-21 16:17   ` Daniel P. Berrangé
  2021-01-05  2:20 ` [PATCH v6 5/7] configure: cross compile should use x86_64 cpu_family Joelle van Dyne
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 21+ messages in thread
From: Joelle van Dyne @ 2021-01-05  2:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Roman Bolshakov, Joelle van Dyne, Stefan Hajnoczi

iOS does not support ucontext natively for aarch64 and the sigaltstack is
also unsupported (even worse, it fails silently, see:
https://openradar.appspot.com/13002712 )

As a workaround we include a library implementation of ucontext and add it
as a build option.

Signed-off-by: Joelle van Dyne <j@getutm.app>
---
 configure                 | 23 ++++++++++++++++++++---
 meson.build               | 11 ++++++++++-
 util/coroutine-ucontext.c |  9 +++++++++
 .gitmodules               |  3 +++
 meson_options.txt         |  2 ++
 subprojects/libucontext   |  1 +
 6 files changed, 45 insertions(+), 4 deletions(-)
 create mode 160000 subprojects/libucontext

diff --git a/configure b/configure
index c1a08f0171..09dd22ebad 100755
--- a/configure
+++ b/configure
@@ -1767,7 +1767,7 @@ Advanced options (experts only):
   --oss-lib                path to OSS library
   --cpu=CPU                Build for host CPU [$cpu]
   --with-coroutine=BACKEND coroutine backend. Supported options:
-                           ucontext, sigaltstack, windows
+                           ucontext, libucontext, sigaltstack, windows
   --enable-gcov            enable test coverage analysis with gcov
   --disable-blobs          disable installing provided firmware blobs
   --with-vss-sdk=SDK-path  enable Windows VSS support in QEMU Guest Agent
@@ -4913,6 +4913,8 @@ if test "$coroutine" = ""; then
     coroutine=win32
   elif test "$ucontext_works" = "yes"; then
     coroutine=ucontext
+  elif test "$ios" = "yes"; then
+    coroutine=libucontext
   else
     coroutine=sigaltstack
   fi
@@ -4936,12 +4938,27 @@ else
       error_exit "only the 'windows' coroutine backend is valid for Windows"
     fi
     ;;
+  libucontext)
+  ;;
   *)
     error_exit "unknown coroutine backend $coroutine"
     ;;
   esac
 fi
 
+case $coroutine in
+libucontext)
+  git_submodules="${git_submodules} subprojects/libucontext"
+  mkdir -p libucontext
+  coroutine_impl=ucontext
+  libucontext="enabled"
+  ;;
+*)
+  coroutine_impl=$coroutine
+  libucontext="disabled"
+  ;;
+esac
+
 if test "$coroutine_pool" = ""; then
   coroutine_pool=yes
 fi
@@ -6487,7 +6504,7 @@ if test "$rbd" = "yes" ; then
   echo "RBD_LIBS=$rbd_libs" >> $config_host_mak
 fi
 
-echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
+echo "CONFIG_COROUTINE_BACKEND=$coroutine_impl" >> $config_host_mak
 if test "$coroutine_pool" = "yes" ; then
   echo "CONFIG_COROUTINE_POOL=1" >> $config_host_mak
 else
@@ -7069,7 +7086,7 @@ NINJA=$ninja $meson setup \
         -Dcocoa=$cocoa -Dmpath=$mpath -Dsdl=$sdl -Dsdl_image=$sdl_image \
         -Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \
         -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f -Dvirtiofsd=$virtiofsd \
-        -Dcapstone=$capstone -Dslirp=$slirp -Dfdt=$fdt \
+        -Dcapstone=$capstone -Dslirp=$slirp -Dfdt=$fdt -Ducontext=$libucontext \
         -Diconv=$iconv -Dcurses=$curses -Dlibudev=$libudev\
         -Ddocs=$docs -Dsphinx_build=$sphinx_build -Dinstall_blobs=$blobs \
         -Dvhost_user_blk_server=$vhost_user_blk_server \
diff --git a/meson.build b/meson.build
index ee333b7a94..900dbc36c8 100644
--- a/meson.build
+++ b/meson.build
@@ -1308,9 +1308,17 @@ if not fdt.found() and fdt_required.length() > 0
   error('fdt not available but required by targets ' + ', '.join(fdt_required))
 endif
 
+ucontext = dependency('libucontext', required : false)
+if not ucontext.found() and get_option('ucontext').enabled()
+  libucontext_proj = subproject('libucontext',
+                                default_options: ['freestanding=true'])
+  ucontext = libucontext_proj.get_variable('libucontext_dep')
+endif
+
 config_host_data.set('CONFIG_CAPSTONE', capstone.found())
 config_host_data.set('CONFIG_FDT', fdt.found())
 config_host_data.set('CONFIG_SLIRP', slirp.found())
+config_host_data.set('CONFIG_LIBUCONTEXT', ucontext.found())
 
 #####################
 # Generated sources #
@@ -1528,7 +1536,7 @@ util_ss.add_all(trace_ss)
 util_ss = util_ss.apply(config_all, strict: false)
 libqemuutil = static_library('qemuutil',
                              sources: util_ss.sources() + stub_ss.sources() + genh,
-                             dependencies: [util_ss.dependencies(), m, glib, socket, malloc])
+                             dependencies: [util_ss.dependencies(), m, glib, socket, malloc, ucontext])
 qemuutil = declare_dependency(link_with: libqemuutil,
                               sources: genh + version_res)
 
@@ -2188,6 +2196,7 @@ if targetos == 'windows'
   summary_info += {'QGA MSI support':   config_host.has_key('CONFIG_QGA_MSI')}
 endif
 summary_info += {'seccomp support':   config_host.has_key('CONFIG_SECCOMP')}
+summary_info += {'libucontext support': ucontext.found()}
 summary_info += {'coroutine backend': config_host['CONFIG_COROUTINE_BACKEND']}
 summary_info += {'coroutine pool':    config_host['CONFIG_COROUTINE_POOL'] == '1'}
 summary_info += {'debug stack usage': config_host.has_key('CONFIG_DEBUG_STACK_USAGE')}
diff --git a/util/coroutine-ucontext.c b/util/coroutine-ucontext.c
index 904b375192..220c57a743 100644
--- a/util/coroutine-ucontext.c
+++ b/util/coroutine-ucontext.c
@@ -23,7 +23,16 @@
 #undef _FORTIFY_SOURCE
 #endif
 #include "qemu/osdep.h"
+#if defined(CONFIG_LIBUCONTEXT)
+#include <libucontext/libucontext.h>
+#define ucontext_t libucontext_ucontext_t
+#define getcontext libucontext_getcontext
+#define setcontext libucontext_setcontext
+#define swapcontext libucontext_swapcontext
+#define makecontext libucontext_makecontext
+#else
 #include <ucontext.h>
+#endif
 #include "qemu/coroutine_int.h"
 
 #ifdef CONFIG_VALGRIND_H
diff --git a/.gitmodules b/.gitmodules
index 2bdeeacef8..4f02eed79a 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -64,3 +64,6 @@
 [submodule "roms/vbootrom"]
 	path = roms/vbootrom
 	url = https://git.qemu.org/git/vbootrom.git
+[submodule "libucontext"]
+	path = subprojects/libucontext
+	url = https://github.com/utmapp/libucontext.git
diff --git a/meson_options.txt b/meson_options.txt
index 74ac853548..0a93bccea3 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -70,6 +70,8 @@ option('fuse', type: 'feature', value: 'auto',
        description: 'FUSE block device export')
 option('fuse_lseek', type : 'feature', value : 'auto',
        description: 'SEEK_HOLE/SEEK_DATA support for FUSE exports')
+option('ucontext', type : 'feature', value : 'disabled',
+       description: 'libucontext support')
 
 option('capstone', type: 'combo', value: 'auto',
        choices: ['disabled', 'enabled', 'auto', 'system', 'internal'],
diff --git a/subprojects/libucontext b/subprojects/libucontext
new file mode 160000
index 0000000000..fc3b5e724e
--- /dev/null
+++ b/subprojects/libucontext
@@ -0,0 +1 @@
+Subproject commit fc3b5e724e21c2c01e2c93b344ab0e34b5a6649b
-- 
2.28.0



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v6 5/7] configure: cross compile should use x86_64 cpu_family
  2021-01-05  2:20 [PATCH v6 0/7] iOS and Apple Silicon host support Joelle van Dyne
                   ` (3 preceding siblings ...)
  2021-01-05  2:20 ` [PATCH v6 4/7] coroutine: add libucontext as external library Joelle van Dyne
@ 2021-01-05  2:20 ` Joelle van Dyne
  2021-01-12 11:46   ` Philippe Mathieu-Daudé
  2021-01-05  2:20 ` [PATCH v6 6/7] slirp: update build flags for iOS resolv fix Joelle van Dyne
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 21+ messages in thread
From: Joelle van Dyne @ 2021-01-05  2:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: Roman Bolshakov, Joelle van Dyne

Signed-off-by: Joelle van Dyne <j@getutm.app>
---
 configure | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 09dd22ebad..79dc9811e8 100755
--- a/configure
+++ b/configure
@@ -7033,9 +7033,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



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v6 6/7] slirp: update build flags for iOS resolv fix
  2021-01-05  2:20 [PATCH v6 0/7] iOS and Apple Silicon host support Joelle van Dyne
                   ` (4 preceding siblings ...)
  2021-01-05  2:20 ` [PATCH v6 5/7] configure: cross compile should use x86_64 cpu_family Joelle van Dyne
@ 2021-01-05  2:20 ` Joelle van Dyne
  2021-01-12 11:52   ` Philippe Mathieu-Daudé
  2021-01-05  2:20 ` [PATCH v6 7/7] block: check availablity for preadv/pwritev on mac Joelle van Dyne
  2021-01-12 11:01 ` [PATCH v6 0/7] iOS and Apple Silicon host support Peter Maydell
  7 siblings, 1 reply; 21+ messages in thread
From: Joelle van Dyne @ 2021-01-05  2:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: Roman Bolshakov, Joelle van Dyne, Stefan Hajnoczi

A future libslirp update will use libresolv on Darwin systems, so we add the
flags in QEMU build now.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Joelle van Dyne <j@getutm.app>
---
 meson.build | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/meson.build b/meson.build
index 900dbc36c8..d8951d4d6c 100644
--- a/meson.build
+++ b/meson.build
@@ -1205,6 +1205,8 @@ if have_system
     slirp_deps = []
     if targetos == 'windows'
       slirp_deps = cc.find_library('iphlpapi')
+    elif targetos == 'darwin'
+      slirp_deps = cc.find_library('resolv')
     endif
     slirp_conf = configuration_data()
     slirp_conf.set('SLIRP_MAJOR_VERSION', meson.project_version().split('.')[0])
-- 
2.28.0



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v6 7/7] block: check availablity for preadv/pwritev on mac
  2021-01-05  2:20 [PATCH v6 0/7] iOS and Apple Silicon host support Joelle van Dyne
                   ` (5 preceding siblings ...)
  2021-01-05  2:20 ` [PATCH v6 6/7] slirp: update build flags for iOS resolv fix Joelle van Dyne
@ 2021-01-05  2:20 ` Joelle van Dyne
  2021-01-12 11:01 ` [PATCH v6 0/7] iOS and Apple Silicon host support Peter Maydell
  7 siblings, 0 replies; 21+ messages in thread
From: Joelle van Dyne @ 2021-01-05  2:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Roman Bolshakov, Joelle van Dyne, open list:raw, Max Reitz

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 <j@getutm.app>
---
 block/file-posix.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/block/file-posix.c b/block/file-posix.c
index 9f556322e6..f109e1f305 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -1390,17 +1390,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



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH v6 0/7] iOS and Apple Silicon host support
  2021-01-05  2:20 [PATCH v6 0/7] iOS and Apple Silicon host support Joelle van Dyne
                   ` (6 preceding siblings ...)
  2021-01-05  2:20 ` [PATCH v6 7/7] block: check availablity for preadv/pwritev on mac Joelle van Dyne
@ 2021-01-12 11:01 ` Peter Maydell
  2021-01-12 22:05   ` Joelle van Dyne
  7 siblings, 1 reply; 21+ messages in thread
From: Peter Maydell @ 2021-01-12 11:01 UTC (permalink / raw)
  To: Joelle van Dyne; +Cc: Roman Bolshakov, QEMU Developers

On Tue, 5 Jan 2021 at 02:23, Joelle van Dyne <j@getutm.app> wrote:
>
> Based-on: 20201214140314.18544-1-richard.henderson@linaro.org
> ([PATCH v4 00/43] Mirror map JIT memory for TCG)
>
> 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.
>
> A summary of the changes:
>
> * `CONFIG_IOS` defined when building for iOS and iOS specific changes (as well
>   as unsupported code) are gated behind it.
> * A new dependency, libucontext is added since iOS does not have native ucontext
>   and broken support for sigaltstack. libucontext is available as a new option
>   for coroutine backend.
>
> 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

So is this series now purely iOS support, or are there still
some pieces of it that are needed for Mac systems with Apple silicon ?

thanks
-- PMM


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v6 5/7] configure: cross compile should use x86_64 cpu_family
  2021-01-05  2:20 ` [PATCH v6 5/7] configure: cross compile should use x86_64 cpu_family Joelle van Dyne
@ 2021-01-12 11:46   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 21+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-01-12 11:46 UTC (permalink / raw)
  To: Joelle van Dyne, qemu-devel; +Cc: Roman Bolshakov, Alex Bennée

On 1/5/21 3:20 AM, Joelle van Dyne wrote:
> Signed-off-by: Joelle van Dyne <j@getutm.app>
> ---
>  configure | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/configure b/configure
> index 09dd22ebad..79dc9811e8 100755
> --- a/configure
> +++ b/configure
> @@ -7033,9 +7033,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
>              ;;
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v6 6/7] slirp: update build flags for iOS resolv fix
  2021-01-05  2:20 ` [PATCH v6 6/7] slirp: update build flags for iOS resolv fix Joelle van Dyne
@ 2021-01-12 11:52   ` Philippe Mathieu-Daudé
  2021-01-14 11:07     ` [Slirp] " Marc-André Lureau
  0 siblings, 1 reply; 21+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-01-12 11:52 UTC (permalink / raw)
  To: Joelle van Dyne, qemu-devel, slirp, Paolo Bonzini
  Cc: Samuel Thibault, Roman Bolshakov, Stefan Hajnoczi,
	Marc-André Lureau

Hi Joelle,

On 1/5/21 3:20 AM, Joelle van Dyne wrote:
> A future libslirp update will use libresolv on Darwin systems, so we add the
> flags in QEMU build now.
> 
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> Signed-off-by: Joelle van Dyne <j@getutm.app>
> ---
>  meson.build | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/meson.build b/meson.build
> index 900dbc36c8..d8951d4d6c 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -1205,6 +1205,8 @@ if have_system
>      slirp_deps = []
>      if targetos == 'windows'
>        slirp_deps = cc.find_library('iphlpapi')
> +    elif targetos == 'darwin'
> +      slirp_deps = cc.find_library('resolv')

This is done in libSLiRP commit 9f82a47 ("Add DNS resolving for iOS").

Maybe this commit need to be backported in the stable branch,
or QEMU should use a newer commit. Cc'ing Samuel and Marc-André
who maintain the project (and the SLiRP list).

>      endif
>      slirp_conf = configuration_data()
>      slirp_conf.set('SLIRP_MAJOR_VERSION', meson.project_version().split('.')[0])
> 



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v6 3/7] qemu: add support for iOS host
  2021-01-05  2:20 ` [PATCH v6 3/7] qemu: add support for iOS host Joelle van Dyne
@ 2021-01-12 11:56   ` Philippe Mathieu-Daudé
  2021-01-12 22:18     ` Joelle van Dyne
  2021-01-12 15:03   ` Peter Maydell
  2021-01-21 18:53   ` Peter Maydell
  2 siblings, 1 reply; 21+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-01-12 11:56 UTC (permalink / raw)
  To: Joelle van Dyne, qemu-devel, Thomas Huth, Alex Bennée
  Cc: Kevin Wolf, Laurent Vivier, open list:Block layer core,
	Jason Wang, Michael Roth, Max Reitz, Roman Bolshakov,
	Samuel Thibault, Paolo Bonzini

Hi Joelle,

On 1/5/21 3:20 AM, Joelle van Dyne wrote:
> This introduces support for building for iOS hosts. When the correct Xcode
> toolchain is used, iOS host will be detected automatically.
> 
> * block: disable features not supported by iOS sandbox
> * slirp: disable SMB features for iOS
> * osdep: disable system() calls for iOS
> 
> Signed-off-by: Joelle van Dyne <j@getutm.app>
> ---
>  docs/devel/index.rst    |  1 +
>  docs/devel/ios.rst      | 28 +++++++++++++++++++++++++++
>  configure               | 43 ++++++++++++++++++++++++++++++++++++++++-
>  meson.build             |  2 +-
>  include/qemu/osdep.h    | 11 +++++++++++
>  block.c                 |  2 +-
>  block/file-posix.c      | 31 +++++++++++++++++------------
>  net/slirp.c             | 16 +++++++--------
>  qga/commands-posix.c    |  6 ++++++
>  MAINTAINERS             |  7 +++++++
>  tests/qtest/meson.build |  7 +++----
>  11 files changed, 127 insertions(+), 27 deletions(-)
>  create mode 100644 docs/devel/ios.rst

> 
> diff --git a/docs/devel/index.rst b/docs/devel/index.rst
> index f10ed77e4c..2cc8a13ebe 100644
> --- a/docs/devel/index.rst
> +++ b/docs/devel/index.rst
> @@ -35,3 +35,4 @@ Contents:
>     clocks
>     qom
>     block-coroutine-wrapper
> +   ios
> diff --git a/docs/devel/ios.rst b/docs/devel/ios.rst
> new file mode 100644
> index 0000000000..b4ab11bec1
> --- /dev/null
> +++ b/docs/devel/ios.rst
> @@ -0,0 +1,28 @@
> +===========
> +iOS Support
> +===========
> +
> +To run qemu on the iOS platform, some modifications were required. Most of the
> +modifications are conditioned on the ``CONFIG_IOS`` and configuration variable.
> +
> +Build support
> +-------------
> +
> +For the code to compile, certain changes in the block driver and the slirp
> +driver had to be made. There is no ``system()`` call, so it has been replaced
> +with an assertion error. There should be no code path that call system() from
> +iOS.
> +
> +``ucontext`` support is broken on iOS. The implementation from ``libucontext``
> +is used instead.

Do you have a CI testing plan for these builds?

Is it possible to add a Gitlab-CI job? If not, on Cirrus-CI?

Thanks,

Phil.




^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v6 3/7] qemu: add support for iOS host
  2021-01-05  2:20 ` [PATCH v6 3/7] qemu: add support for iOS host Joelle van Dyne
  2021-01-12 11:56   ` Philippe Mathieu-Daudé
@ 2021-01-12 15:03   ` Peter Maydell
  2021-01-12 22:37     ` Joelle van Dyne
  2021-01-21 18:53   ` Peter Maydell
  2 siblings, 1 reply; 21+ messages in thread
From: Peter Maydell @ 2021-01-12 15:03 UTC (permalink / raw)
  To: Joelle van Dyne
  Cc: Kevin Wolf, Laurent Vivier, Thomas Huth,
	open list:Block layer core, Jason Wang, QEMU Developers,
	Michael Roth, Roman Bolshakov, Samuel Thibault, Paolo Bonzini,
	Max Reitz

On Tue, 5 Jan 2021 at 02:25, Joelle van Dyne <j@getutm.app> wrote:
>
> This introduces support for building for iOS hosts. When the correct Xcode
> toolchain is used, iOS host will be detected automatically.
>
> * block: disable features not supported by iOS sandbox
> * slirp: disable SMB features for iOS
> * osdep: disable system() calls for iOS
>
> Signed-off-by: Joelle van Dyne <j@getutm.app>
> ---
>  docs/devel/index.rst    |  1 +
>  docs/devel/ios.rst      | 28 +++++++++++++++++++++++++++
>  configure               | 43 ++++++++++++++++++++++++++++++++++++++++-
>  meson.build             |  2 +-
>  include/qemu/osdep.h    | 11 +++++++++++
>  block.c                 |  2 +-
>  block/file-posix.c      | 31 +++++++++++++++++------------
>  net/slirp.c             | 16 +++++++--------
>  qga/commands-posix.c    |  6 ++++++
>  MAINTAINERS             |  7 +++++++
>  tests/qtest/meson.build |  7 +++----
>  11 files changed, 127 insertions(+), 27 deletions(-)
>  create mode 100644 docs/devel/ios.rst
>
> diff --git a/docs/devel/index.rst b/docs/devel/index.rst
> index f10ed77e4c..2cc8a13ebe 100644
> --- a/docs/devel/index.rst
> +++ b/docs/devel/index.rst
> @@ -35,3 +35,4 @@ Contents:
>     clocks
>     qom
>     block-coroutine-wrapper
> +   ios
> diff --git a/docs/devel/ios.rst b/docs/devel/ios.rst
> new file mode 100644
> index 0000000000..b4ab11bec1
> --- /dev/null
> +++ b/docs/devel/ios.rst
> @@ -0,0 +1,28 @@
> +===========
> +iOS Support
> +===========
> +
> +To run qemu on the iOS platform, some modifications were required. Most of the

QEMU is upper-cased.

> +modifications are conditioned on the ``CONFIG_IOS`` and configuration variable.
> +
> +Build support
> +-------------
> +
> +For the code to compile, certain changes in the block driver and the slirp
> +driver had to be made. There is no ``system()`` call, so it has been replaced
> +with an assertion error. There should be no code path that call system() from

"calls"

> +iOS.
> +
> +``ucontext`` support is broken on iOS. The implementation from ``libucontext``
> +is used instead.
> +
> +JIT support
> +-----------
> +
> +On iOS, allocating RWX pages require special entitlements not usually granted to

"requires"

> +apps. However, it is possible to use `bulletproof JIT`_ with a development
> +certificate. This means that we need to allocate one chunk of memory with RX
> +permissions and then mirror map the same memory with RW permissions. We generate
> +code to the mirror mapping and execute the original mapping.
> +
> +.. _bulletproof JIT: https://www.blackhat.com/docs/us-16/materials/us-16-Krstic.pdf
> diff --git a/configure b/configure
> index 744d1990be..c1a08f0171 100755
> --- a/configure
> +++ b/configure
> @@ -560,6 +560,19 @@ EOF
>    compile_object
>  }
>
> +check_ios() {
> +  cat > $TMPC <<EOF
> +#ifdef __APPLE__
> +#import "TargetConditionals.h"
> +#if !TARGET_OS_IPHONE
> +#error TARGET_OS_IPHONE not true
> +#endif
> +#endif
> +int main(void) { return 0; }
> +EOF
> +  compile_object
> +}
> +
>  check_include() {
>  cat > $TMPC <<EOF
>  #include <$1>
> @@ -602,7 +615,11 @@ elif check_define __DragonFly__ ; then
>  elif check_define __NetBSD__; then
>    targetos='NetBSD'
>  elif check_define __APPLE__; then
> -  targetos='Darwin'
> +  if check_ios ; then
> +    targetos='iOS'
> +  else
> +    targetos='Darwin'
> +  fi
>  else
>    # This is a fatal error, but don't report it yet, because we
>    # might be going to just print the --help text, or it might

So here targetos=iOS and targetos=Darwin are separate things...

> @@ -6974,6 +7012,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

...so why is this needed if we're not "darwin", but "iOS"...

>      case "$ARCH" in
>          i386|x86_64)
>              echo "cpu_family = 'x86'" >> $cross
> diff --git a/meson.build b/meson.build
> index 9a640d3407..ee333b7a94 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -181,7 +181,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: 'CONFIG_IOS' not in config_host)
>    cocoa = dependency('appleframeworks', modules: 'Cocoa', required: get_option('cocoa'))
>  elif targetos == 'sunos'
>    socket = [cc.find_library('socket'),

...and here ios seems to be a subtype of darwin, not a different
kind of targetos. That's a bit confusing. Maybe this is Meson's fault ?

> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> index f9ec8c84e9..eb8d06cbf5 100644
> --- a/include/qemu/osdep.h
> +++ b/include/qemu/osdep.h
> @@ -686,4 +686,15 @@ char *qemu_get_host_name(Error **errp);
>   */
>  size_t qemu_get_host_physmem(void);
>
> +/**
> + * iOS does not support system() so we replace it with an assertion failure.
> + */
> +#ifdef CONFIG_IOS
> +#define system ios_does_not_support_system
> +static inline int ios_does_not_support_system(const char *command)
> +{
> +    assert(0);
> +}
> +#endif /* CONFIG_IOS */
> +
>  #endif
> diff --git a/block.c b/block.c
> index 8f177504d4..984a73a82c 100644
> --- a/block.c
> +++ b/block.c
> @@ -54,7 +54,7 @@
>  #ifdef CONFIG_BSD
>  #include <sys/ioctl.h>
>  #include <sys/queue.h>
> -#ifndef __DragonFly__
> +#if !defined(__DragonFly__) && !defined(CONFIG_IOS)
>  #include <sys/disk.h>
>  #endif

Instead of extending this ifdef of OSes, can we add a meson.build
test for "does sys/disk.h exist" and then use #ifdef HAVE_SYS_DISK_H ?
(HAVE_PTY_H is probably a good example to crib from.)

This is part of a general preference we have for not testing
"are we building for host OS Foo" if we can test the specific
property we care about instead.

>  #endif
> diff --git a/block/file-posix.c b/block/file-posix.c
> index c34bb9fac1..9f556322e6 100644
> --- a/block/file-posix.c
> +++ b/block/file-posix.c
> @@ -181,7 +181,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 {
> @@ -252,6 +262,12 @@ static int raw_normalize_devicepath(const char **filename, Error **errp)
>  }
>  #endif
>
> +#if defined(CONFIG_IOS)
> +static int probe_logical_blocksize(int fd, unsigned int *sector_size_p)
> +{
> +    return -ENOTSUP; /* not supported on iOS */
> +}
> +#else /* CONFIG_IOS */
>  /*
>   * Get logical block size via ioctl. On success store it in @sector_size_p.
>   */
> @@ -284,6 +300,7 @@ static int probe_logical_blocksize(int fd, unsigned int *sector_size_p)
>
>      return success ? 0 : -errno;
>  }
> +#endif /* !CONFIG_IOS */
>
>  /**
>   * Get physical block size of @fd.
> @@ -2307,7 +2324,7 @@ again:
>          }
>          if (size == 0)
>  #endif
> -#if defined(__APPLE__) && defined(__MACH__)
> +#if !defined(CONFIG_IOS) && defined(__APPLE__) && defined(__MACH__)
>          {
>              uint64_t sectors = 0;
>              uint32_t sector_size = 0;
> @@ -3543,16 +3560,6 @@ hdev_co_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
>  }
>  #endif /* linux */
>
> -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 coroutine_fn int
>  hdev_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)
>  {
> diff --git a/net/slirp.c b/net/slirp.c
> index 77042e6df7..8413042c09 100644
> --- a/net/slirp.c
> +++ b/net/slirp.c
> @@ -27,7 +27,7 @@
>  #include "net/slirp.h"
>
>
> -#ifndef _WIN32
> +#if !defined(_WIN32) && !defined(CONFIG_IOS)
>  #include <pwd.h>
>  #include <sys/wait.h>
>  #endif
> @@ -90,7 +90,7 @@ typedef struct SlirpState {
>      Slirp *slirp;
>      Notifier poll_notifier;
>      Notifier exit_notifier;
> -#ifndef _WIN32
> +#if !defined(_WIN32) && !defined(CONFIG_IOS)
>      gchar *smb_dir;
>  #endif
>      GSList *fwd;

This sort of ifdeffery should probably also be changed to test
what it really cares about rather than just adding another host OS
type to the list.

> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index c089e38120..81e40ac14a 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c

Does it even make sense to build the guest agent for iOS ?
It's not like you can run iOS inside QEMU...

> diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
> index 6a67c538be..42b46a7ca4 100644
> --- a/tests/qtest/meson.build
> +++ b/tests/qtest/meson.build
> @@ -46,12 +46,11 @@ qtests_i386 = \
>    (config_all_devices.has_key('CONFIG_TPM_TIS_ISA') ? ['tpm-tis-test'] : []) +              \
>    (config_all_devices.has_key('CONFIG_TPM_TIS_ISA') ? ['tpm-tis-swtpm-test'] : []) +        \
>    (config_all_devices.has_key('CONFIG_RTL8139_PCI') ? ['rtl8139-test'] : []) +              \
> +  (not config_host.has_key('CONFIG_IOS') ? ['bios-tables-test', 'hd-geo-test'] : []) +      \
>    qtests_pci +                                                                              \
>    ['fdc-test',
>     'ide-test',
> -   'hd-geo-test',
>     'boot-order-test',
> -   'bios-tables-test',
>     'rtc-test',
>     'i440fx-test',
>     'fuzz-test',
> @@ -148,9 +147,9 @@ qtests_arm = \
>     'boot-serial-test',
>     'hexloader-test']
>
> -# TODO: once aarch64 TCG is fixed on ARM 32 bit host, make bios-tables-test unconditional
> +# TODO: once aarch64 TCG is fixed on ARM 32 bit host, make bios-tables-test unconditional (except on iOS)

So, why is bios-tables-test not something to run if we're building for iOS?
If there's a good reason for the exclusion the comment should say what it is.

>  qtests_aarch64 = \
> -  (cpu != 'arm' ? ['bios-tables-test'] : []) +                                                  \
> +  (cpu != 'arm' and not config_host.has_key('CONFIG_IOS') ? ['bios-tables-test'] : []) +        \
>    (config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? ['tpm-tis-device-test'] : []) +        \
>    (config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? ['tpm-tis-device-swtpm-test'] : []) +  \
>    ['arm-cpu-features',
> --
> 2.28.0

thanks
-- PMM


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v6 0/7] iOS and Apple Silicon host support
  2021-01-12 11:01 ` [PATCH v6 0/7] iOS and Apple Silicon host support Peter Maydell
@ 2021-01-12 22:05   ` Joelle van Dyne
  0 siblings, 0 replies; 21+ messages in thread
From: Joelle van Dyne @ 2021-01-12 22:05 UTC (permalink / raw)
  To: Peter Maydell; +Cc: QEMU Developers

After decoupling the MAP_JIT and APRR patches, this should only be for
iOS support. I didn't change the title because I didn't know if
patchew would be smart enough to group it with the older patches.

-j

On Tue, Jan 12, 2021 at 3:01 AM Peter Maydell <peter.maydell@linaro.org> wrote:
>
> On Tue, 5 Jan 2021 at 02:23, Joelle van Dyne <j@getutm.app> wrote:
> >
> > Based-on: 20201214140314.18544-1-richard.henderson@linaro.org
> > ([PATCH v4 00/43] Mirror map JIT memory for TCG)
> >
> > 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.
> >
> > A summary of the changes:
> >
> > * `CONFIG_IOS` defined when building for iOS and iOS specific changes (as well
> >   as unsupported code) are gated behind it.
> > * A new dependency, libucontext is added since iOS does not have native ucontext
> >   and broken support for sigaltstack. libucontext is available as a new option
> >   for coroutine backend.
> >
> > 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
>
> So is this series now purely iOS support, or are there still
> some pieces of it that are needed for Mac systems with Apple silicon ?
>
> thanks
> -- PMM


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v6 3/7] qemu: add support for iOS host
  2021-01-12 11:56   ` Philippe Mathieu-Daudé
@ 2021-01-12 22:18     ` Joelle van Dyne
  0 siblings, 0 replies; 21+ messages in thread
From: Joelle van Dyne @ 2021-01-12 22:18 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé; +Cc: QEMU Developers

I think this was discussed before but the main issue right now is that
there's no packaging system (like homebrew) for iOS cross building on
Mac. Stefan suggested caching built libraries in an external location
to use with the CI. I think this can be done but would require some
thought to it. I am open to other ideas as well (like pretending to
build for iOS while actually building for macOS).

-j

On Tue, Jan 12, 2021 at 3:56 AM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> Hi Joelle,
>
> On 1/5/21 3:20 AM, Joelle van Dyne wrote:
> > This introduces support for building for iOS hosts. When the correct Xcode
> > toolchain is used, iOS host will be detected automatically.
> >
> > * block: disable features not supported by iOS sandbox
> > * slirp: disable SMB features for iOS
> > * osdep: disable system() calls for iOS
> >
> > Signed-off-by: Joelle van Dyne <j@getutm.app>
> > ---
> >  docs/devel/index.rst    |  1 +
> >  docs/devel/ios.rst      | 28 +++++++++++++++++++++++++++
> >  configure               | 43 ++++++++++++++++++++++++++++++++++++++++-
> >  meson.build             |  2 +-
> >  include/qemu/osdep.h    | 11 +++++++++++
> >  block.c                 |  2 +-
> >  block/file-posix.c      | 31 +++++++++++++++++------------
> >  net/slirp.c             | 16 +++++++--------
> >  qga/commands-posix.c    |  6 ++++++
> >  MAINTAINERS             |  7 +++++++
> >  tests/qtest/meson.build |  7 +++----
> >  11 files changed, 127 insertions(+), 27 deletions(-)
> >  create mode 100644 docs/devel/ios.rst
>
> >
> > diff --git a/docs/devel/index.rst b/docs/devel/index.rst
> > index f10ed77e4c..2cc8a13ebe 100644
> > --- a/docs/devel/index.rst
> > +++ b/docs/devel/index.rst
> > @@ -35,3 +35,4 @@ Contents:
> >     clocks
> >     qom
> >     block-coroutine-wrapper
> > +   ios
> > diff --git a/docs/devel/ios.rst b/docs/devel/ios.rst
> > new file mode 100644
> > index 0000000000..b4ab11bec1
> > --- /dev/null
> > +++ b/docs/devel/ios.rst
> > @@ -0,0 +1,28 @@
> > +===========
> > +iOS Support
> > +===========
> > +
> > +To run qemu on the iOS platform, some modifications were required. Most of the
> > +modifications are conditioned on the ``CONFIG_IOS`` and configuration variable.
> > +
> > +Build support
> > +-------------
> > +
> > +For the code to compile, certain changes in the block driver and the slirp
> > +driver had to be made. There is no ``system()`` call, so it has been replaced
> > +with an assertion error. There should be no code path that call system() from
> > +iOS.
> > +
> > +``ucontext`` support is broken on iOS. The implementation from ``libucontext``
> > +is used instead.
>
> Do you have a CI testing plan for these builds?
>
> Is it possible to add a Gitlab-CI job? If not, on Cirrus-CI?
>
> Thanks,
>
> Phil.
>
>


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v6 3/7] qemu: add support for iOS host
  2021-01-12 15:03   ` Peter Maydell
@ 2021-01-12 22:37     ` Joelle van Dyne
  0 siblings, 0 replies; 21+ messages in thread
From: Joelle van Dyne @ 2021-01-12 22:37 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Kevin Wolf, Laurent Vivier, Thomas Huth,
	open list:Block layer core, Jason Wang, QEMU Developers,
	Michael Roth, Roman Bolshakov, Joelle van Dyne, Samuel Thibault,
	Paolo Bonzini, Max Reitz

On Tue, Jan 12, 2021 at 7:03 AM Peter Maydell <peter.maydell@linaro.org> wrote:
>
> On Tue, 5 Jan 2021 at 02:25, Joelle van Dyne <j@getutm.app> wrote:
> >
> > This introduces support for building for iOS hosts. When the correct Xcode
> > toolchain is used, iOS host will be detected automatically.
> >
> > * block: disable features not supported by iOS sandbox
> > * slirp: disable SMB features for iOS
> > * osdep: disable system() calls for iOS
> >
> > Signed-off-by: Joelle van Dyne <j@getutm.app>
> > ---
> >  docs/devel/index.rst    |  1 +
> >  docs/devel/ios.rst      | 28 +++++++++++++++++++++++++++
> >  configure               | 43 ++++++++++++++++++++++++++++++++++++++++-
> >  meson.build             |  2 +-
> >  include/qemu/osdep.h    | 11 +++++++++++
> >  block.c                 |  2 +-
> >  block/file-posix.c      | 31 +++++++++++++++++------------
> >  net/slirp.c             | 16 +++++++--------
> >  qga/commands-posix.c    |  6 ++++++
> >  MAINTAINERS             |  7 +++++++
> >  tests/qtest/meson.build |  7 +++----
> >  11 files changed, 127 insertions(+), 27 deletions(-)
> >  create mode 100644 docs/devel/ios.rst
> >
> > diff --git a/docs/devel/index.rst b/docs/devel/index.rst
> > index f10ed77e4c..2cc8a13ebe 100644
> > --- a/docs/devel/index.rst
> > +++ b/docs/devel/index.rst
> > @@ -35,3 +35,4 @@ Contents:
> >     clocks
> >     qom
> >     block-coroutine-wrapper
> > +   ios
> > diff --git a/docs/devel/ios.rst b/docs/devel/ios.rst
> > new file mode 100644
> > index 0000000000..b4ab11bec1
> > --- /dev/null
> > +++ b/docs/devel/ios.rst
> > @@ -0,0 +1,28 @@
> > +===========
> > +iOS Support
> > +===========
> > +
> > +To run qemu on the iOS platform, some modifications were required. Most of the
>
> QEMU is upper-cased.
>
> > +modifications are conditioned on the ``CONFIG_IOS`` and configuration variable.
> > +
> > +Build support
> > +-------------
> > +
> > +For the code to compile, certain changes in the block driver and the slirp
> > +driver had to be made. There is no ``system()`` call, so it has been replaced
> > +with an assertion error. There should be no code path that call system() from
>
> "calls"
>
> > +iOS.
> > +
> > +``ucontext`` support is broken on iOS. The implementation from ``libucontext``
> > +is used instead.
> > +
> > +JIT support
> > +-----------
> > +
> > +On iOS, allocating RWX pages require special entitlements not usually granted to
>
> "requires"
>
> > +apps. However, it is possible to use `bulletproof JIT`_ with a development
> > +certificate. This means that we need to allocate one chunk of memory with RX
> > +permissions and then mirror map the same memory with RW permissions. We generate
> > +code to the mirror mapping and execute the original mapping.
> > +
> > +.. _bulletproof JIT: https://www.blackhat.com/docs/us-16/materials/us-16-Krstic.pdf
> > diff --git a/configure b/configure
> > index 744d1990be..c1a08f0171 100755
> > --- a/configure
> > +++ b/configure
> > @@ -560,6 +560,19 @@ EOF
> >    compile_object
> >  }
> >
> > +check_ios() {
> > +  cat > $TMPC <<EOF
> > +#ifdef __APPLE__
> > +#import "TargetConditionals.h"
> > +#if !TARGET_OS_IPHONE
> > +#error TARGET_OS_IPHONE not true
> > +#endif
> > +#endif
> > +int main(void) { return 0; }
> > +EOF
> > +  compile_object
> > +}
> > +
> >  check_include() {
> >  cat > $TMPC <<EOF
> >  #include <$1>
> > @@ -602,7 +615,11 @@ elif check_define __DragonFly__ ; then
> >  elif check_define __NetBSD__; then
> >    targetos='NetBSD'
> >  elif check_define __APPLE__; then
> > -  targetos='Darwin'
> > +  if check_ios ; then
> > +    targetos='iOS'
> > +  else
> > +    targetos='Darwin'
> > +  fi
> >  else
> >    # This is a fatal error, but don't report it yet, because we
> >    # might be going to just print the --help text, or it might
>
> So here targetos=iOS and targetos=Darwin are separate things...
>
> > @@ -6974,6 +7012,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
>
> ...so why is this needed if we're not "darwin", but "iOS"...
iOS and macOS being treated the same works in 99% of the cases which
is why this patch is relatively small. For the 1% of time the two
systems behave differently, I added CONFIG_IOS. It's a bit of a hack,
but the alternative is to include <TargetConditionals.h> and check for
"TARGET_OS_IPHONE" (which is how it's usually done).

>
> >      case "$ARCH" in
> >          i386|x86_64)
> >              echo "cpu_family = 'x86'" >> $cross
> > diff --git a/meson.build b/meson.build
> > index 9a640d3407..ee333b7a94 100644
> > --- a/meson.build
> > +++ b/meson.build
> > @@ -181,7 +181,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: 'CONFIG_IOS' not in config_host)
> >    cocoa = dependency('appleframeworks', modules: 'Cocoa', required: get_option('cocoa'))
> >  elif targetos == 'sunos'
> >    socket = [cc.find_library('socket'),
>
> ...and here ios seems to be a subtype of darwin, not a different
> kind of targetos. That's a bit confusing. Maybe this is Meson's fault ?
Meson recognizes 'darwin' only for both macOS and iOS.

>
> > diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> > index f9ec8c84e9..eb8d06cbf5 100644
> > --- a/include/qemu/osdep.h
> > +++ b/include/qemu/osdep.h
> > @@ -686,4 +686,15 @@ char *qemu_get_host_name(Error **errp);
> >   */
> >  size_t qemu_get_host_physmem(void);
> >
> > +/**
> > + * iOS does not support system() so we replace it with an assertion failure.
> > + */
> > +#ifdef CONFIG_IOS
> > +#define system ios_does_not_support_system
> > +static inline int ios_does_not_support_system(const char *command)
> > +{
> > +    assert(0);
> > +}
> > +#endif /* CONFIG_IOS */
> > +
> >  #endif
> > diff --git a/block.c b/block.c
> > index 8f177504d4..984a73a82c 100644
> > --- a/block.c
> > +++ b/block.c
> > @@ -54,7 +54,7 @@
> >  #ifdef CONFIG_BSD
> >  #include <sys/ioctl.h>
> >  #include <sys/queue.h>
> > -#ifndef __DragonFly__
> > +#if !defined(__DragonFly__) && !defined(CONFIG_IOS)
> >  #include <sys/disk.h>
> >  #endif
>
> Instead of extending this ifdef of OSes, can we add a meson.build
> test for "does sys/disk.h exist" and then use #ifdef HAVE_SYS_DISK_H ?
> (HAVE_PTY_H is probably a good example to crib from.)
Can be done.

>
> This is part of a general preference we have for not testing
> "are we building for host OS Foo" if we can test the specific
> property we care about instead.
>
> >  #endif
> > diff --git a/block/file-posix.c b/block/file-posix.c
> > index c34bb9fac1..9f556322e6 100644
> > --- a/block/file-posix.c
> > +++ b/block/file-posix.c
> > @@ -181,7 +181,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 {
> > @@ -252,6 +262,12 @@ static int raw_normalize_devicepath(const char **filename, Error **errp)
> >  }
> >  #endif
> >
> > +#if defined(CONFIG_IOS)
> > +static int probe_logical_blocksize(int fd, unsigned int *sector_size_p)
> > +{
> > +    return -ENOTSUP; /* not supported on iOS */
> > +}
> > +#else /* CONFIG_IOS */
> >  /*
> >   * Get logical block size via ioctl. On success store it in @sector_size_p.
> >   */
> > @@ -284,6 +300,7 @@ static int probe_logical_blocksize(int fd, unsigned int *sector_size_p)
> >
> >      return success ? 0 : -errno;
> >  }
> > +#endif /* !CONFIG_IOS */
> >
> >  /**
> >   * Get physical block size of @fd.
> > @@ -2307,7 +2324,7 @@ again:
> >          }
> >          if (size == 0)
> >  #endif
> > -#if defined(__APPLE__) && defined(__MACH__)
> > +#if !defined(CONFIG_IOS) && defined(__APPLE__) && defined(__MACH__)
> >          {
> >              uint64_t sectors = 0;
> >              uint32_t sector_size = 0;
> > @@ -3543,16 +3560,6 @@ hdev_co_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
> >  }
> >  #endif /* linux */
> >
> > -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 coroutine_fn int
> >  hdev_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)
> >  {
> > diff --git a/net/slirp.c b/net/slirp.c
> > index 77042e6df7..8413042c09 100644
> > --- a/net/slirp.c
> > +++ b/net/slirp.c
> > @@ -27,7 +27,7 @@
> >  #include "net/slirp.h"
> >
> >
> > -#ifndef _WIN32
> > +#if !defined(_WIN32) && !defined(CONFIG_IOS)
> >  #include <pwd.h>
> >  #include <sys/wait.h>
> >  #endif
> > @@ -90,7 +90,7 @@ typedef struct SlirpState {
> >      Slirp *slirp;
> >      Notifier poll_notifier;
> >      Notifier exit_notifier;
> > -#ifndef _WIN32
> > +#if !defined(_WIN32) && !defined(CONFIG_IOS)
> >      gchar *smb_dir;
> >  #endif
> >      GSList *fwd;
>
> This sort of ifdeffery should probably also be changed to test
> what it really cares about rather than just adding another host OS
> type to the list.
I can refactor to test for SMB support and replace the host OS checks.

>
> > diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> > index c089e38120..81e40ac14a 100644
> > --- a/qga/commands-posix.c
> > +++ b/qga/commands-posix.c
>
> Does it even make sense to build the guest agent for iOS ?
> It's not like you can run iOS inside QEMU...
Not currently no, but do we preclude the option?

>
> > diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
> > index 6a67c538be..42b46a7ca4 100644
> > --- a/tests/qtest/meson.build
> > +++ b/tests/qtest/meson.build
> > @@ -46,12 +46,11 @@ qtests_i386 = \
> >    (config_all_devices.has_key('CONFIG_TPM_TIS_ISA') ? ['tpm-tis-test'] : []) +              \
> >    (config_all_devices.has_key('CONFIG_TPM_TIS_ISA') ? ['tpm-tis-swtpm-test'] : []) +        \
> >    (config_all_devices.has_key('CONFIG_RTL8139_PCI') ? ['rtl8139-test'] : []) +              \
> > +  (not config_host.has_key('CONFIG_IOS') ? ['bios-tables-test', 'hd-geo-test'] : []) +      \
> >    qtests_pci +                                                                              \
> >    ['fdc-test',
> >     'ide-test',
> > -   'hd-geo-test',
> >     'boot-order-test',
> > -   'bios-tables-test',
> >     'rtc-test',
> >     'i440fx-test',
> >     'fuzz-test',
> > @@ -148,9 +147,9 @@ qtests_arm = \
> >     'boot-serial-test',
> >     'hexloader-test']
> >
> > -# TODO: once aarch64 TCG is fixed on ARM 32 bit host, make bios-tables-test unconditional
> > +# TODO: once aarch64 TCG is fixed on ARM 32 bit host, make bios-tables-test unconditional (except on iOS)
>
> So, why is bios-tables-test not something to run if we're building for iOS?
> If there's a good reason for the exclusion the comment should say what it is.
Actually this was left over from a previous version of the patch where
I excluded all tests that use system(). Now calling system() will just
fail the test so there's no reason to exclude these anymore.

-j

>
> >  qtests_aarch64 = \
> > -  (cpu != 'arm' ? ['bios-tables-test'] : []) +                                                  \
> > +  (cpu != 'arm' and not config_host.has_key('CONFIG_IOS') ? ['bios-tables-test'] : []) +        \
> >    (config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? ['tpm-tis-device-test'] : []) +        \
> >    (config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? ['tpm-tis-device-swtpm-test'] : []) +  \
> >    ['arm-cpu-features',
> > --
> > 2.28.0
>
> thanks
> -- PMM


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [Slirp] [PATCH v6 6/7] slirp: update build flags for iOS resolv fix
  2021-01-12 11:52   ` Philippe Mathieu-Daudé
@ 2021-01-14 11:07     ` Marc-André Lureau
  0 siblings, 0 replies; 21+ messages in thread
From: Marc-André Lureau @ 2021-01-14 11:07 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: slirp, QEMU, Roman Bolshakov, Joelle van Dyne, Stefan Hajnoczi,
	Samuel Thibault, Paolo Bonzini

[-- Attachment #1: Type: text/plain, Size: 1190 bytes --]

Hi

On Tue, Jan 12, 2021 at 3:52 PM Philippe Mathieu-Daudé <philmd@redhat.com>
wrote:

> Hi Joelle,
>
> On 1/5/21 3:20 AM, Joelle van Dyne wrote:
> > A future libslirp update will use libresolv on Darwin systems, so we add
> the
> > flags in QEMU build now.
> >
> > Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> > Signed-off-by: Joelle van Dyne <j@getutm.app>
> > ---
> >  meson.build | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/meson.build b/meson.build
> > index 900dbc36c8..d8951d4d6c 100644
> > --- a/meson.build
> > +++ b/meson.build
> > @@ -1205,6 +1205,8 @@ if have_system
> >      slirp_deps = []
> >      if targetos == 'windows'
> >        slirp_deps = cc.find_library('iphlpapi')
> > +    elif targetos == 'darwin'
> > +      slirp_deps = cc.find_library('resolv')
>
> This is done in libSLiRP commit 9f82a47 ("Add DNS resolving for iOS").
>
> Maybe this commit need to be backported in the stable branch,
> or QEMU should use a newer commit. Cc'ing Samuel and Marc-André
> who maintain the project (and the SLiRP list).
>

Yes, I am going to send an update to git upstream.

thanks

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 1884 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v6 4/7] coroutine: add libucontext as external library
  2021-01-05  2:20 ` [PATCH v6 4/7] coroutine: add libucontext as external library Joelle van Dyne
@ 2021-01-21 16:17   ` Daniel P. Berrangé
  2021-01-21 17:11     ` Joelle van Dyne
  0 siblings, 1 reply; 21+ messages in thread
From: Daniel P. Berrangé @ 2021-01-21 16:17 UTC (permalink / raw)
  To: Joelle van Dyne; +Cc: Kevin Wolf, Roman Bolshakov, qemu-devel, Stefan Hajnoczi

On Mon, Jan 04, 2021 at 06:20:52PM -0800, Joelle van Dyne wrote:
> iOS does not support ucontext natively for aarch64 and the sigaltstack is
> also unsupported (even worse, it fails silently, see:
> https://openradar.appspot.com/13002712 )
> 
> As a workaround we include a library implementation of ucontext and add it
> as a build option.
> 
> Signed-off-by: Joelle van Dyne <j@getutm.app>
> ---
>  configure                 | 23 ++++++++++++++++++++---
>  meson.build               | 11 ++++++++++-
>  util/coroutine-ucontext.c |  9 +++++++++
>  .gitmodules               |  3 +++
>  meson_options.txt         |  2 ++
>  subprojects/libucontext   |  1 +
>  6 files changed, 45 insertions(+), 4 deletions(-)
>  create mode 160000 subprojects/libucontext

> diff --git a/.gitmodules b/.gitmodules
> index 2bdeeacef8..4f02eed79a 100644
> --- a/.gitmodules
> +++ b/.gitmodules
> @@ -64,3 +64,6 @@
>  [submodule "roms/vbootrom"]
>  	path = roms/vbootrom
>  	url = https://git.qemu.org/git/vbootrom.git
> +[submodule "libucontext"]
> +	path = subprojects/libucontext
> +	url = https://github.com/utmapp/libucontext.git

Using libucontext looks like a good idea to me, but I noticed that
this is a pointing to a fork of the main libucontext project at

   https://github.com/kaniini/libucontext

The main project appears 100's of commits ahead of the utmapp fork

What is in the utmapp fork that isn't present in the primary libucontext
repo ?  I think if we're going to use libucontext we will want to point
to the primary project, and this means anything custom in the fork will
need to get submitted upstream. Maybe you've already started doing that
making this a non-issue ?

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v6 4/7] coroutine: add libucontext as external library
  2021-01-21 16:17   ` Daniel P. Berrangé
@ 2021-01-21 17:11     ` Joelle van Dyne
  0 siblings, 0 replies; 21+ messages in thread
From: Joelle van Dyne @ 2021-01-21 17:11 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Kevin Wolf, Roman Bolshakov, Joelle van Dyne, Stefan Hajnoczi,
	qemu-devel

[-- Attachment #1: Type: text/plain, Size: 2366 bytes --]

Yes since the submission of this patch, we have been working with the
original authors to merge all the changes upstream. The next patch should
point to the original repo.

-j

On Thursday, January 21, 2021, Daniel P. Berrangé <berrange@redhat.com>
wrote:

> On Mon, Jan 04, 2021 at 06:20:52PM -0800, Joelle van Dyne wrote:
> > iOS does not support ucontext natively for aarch64 and the sigaltstack is
> > also unsupported (even worse, it fails silently, see:
> > https://openradar.appspot.com/13002712 )
> >
> > As a workaround we include a library implementation of ucontext and add
> it
> > as a build option.
> >
> > Signed-off-by: Joelle van Dyne <j@getutm.app>
> > ---
> >  configure                 | 23 ++++++++++++++++++++---
> >  meson.build               | 11 ++++++++++-
> >  util/coroutine-ucontext.c |  9 +++++++++
> >  .gitmodules               |  3 +++
> >  meson_options.txt         |  2 ++
> >  subprojects/libucontext   |  1 +
> >  6 files changed, 45 insertions(+), 4 deletions(-)
> >  create mode 160000 subprojects/libucontext
>
> > diff --git a/.gitmodules b/.gitmodules
> > index 2bdeeacef8..4f02eed79a 100644
> > --- a/.gitmodules
> > +++ b/.gitmodules
> > @@ -64,3 +64,6 @@
> >  [submodule "roms/vbootrom"]
> >       path = roms/vbootrom
> >       url = https://git.qemu.org/git/vbootrom.git
> > +[submodule "libucontext"]
> > +     path = subprojects/libucontext
> > +     url = https://github.com/utmapp/libucontext.git
>
> Using libucontext looks like a good idea to me, but I noticed that
> this is a pointing to a fork of the main libucontext project at
>
>    https://github.com/kaniini/libucontext
>
> The main project appears 100's of commits ahead of the utmapp fork
>
> What is in the utmapp fork that isn't present in the primary libucontext
> repo ?  I think if we're going to use libucontext we will want to point
> to the primary project, and this means anything custom in the fork will
> need to get submitted upstream. Maybe you've already started doing that
> making this a non-issue ?
>
> Regards,
> Daniel
> --
> |: https://berrange.com      -o-    https://www.flickr.com/photos/
> dberrange :|
> |: https://libvirt.org         -o-
> https://fstop138.berrange.com :|
> |: https://entangle-photo.org    -o-    https://www.instagram.com/
> dberrange :|
>
>

[-- Attachment #2: Type: text/html, Size: 3529 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v6 3/7] qemu: add support for iOS host
  2021-01-05  2:20 ` [PATCH v6 3/7] qemu: add support for iOS host Joelle van Dyne
  2021-01-12 11:56   ` Philippe Mathieu-Daudé
  2021-01-12 15:03   ` Peter Maydell
@ 2021-01-21 18:53   ` Peter Maydell
  2023-11-28 15:12     ` Philippe Mathieu-Daudé
  2 siblings, 1 reply; 21+ messages in thread
From: Peter Maydell @ 2021-01-21 18:53 UTC (permalink / raw)
  To: Joelle van Dyne
  Cc: Kevin Wolf, Laurent Vivier, Thomas Huth,
	open list:Block layer core, Jason Wang, QEMU Developers,
	Michael Roth, Roman Bolshakov, Samuel Thibault, Paolo Bonzini,
	Max Reitz

On Tue, 5 Jan 2021 at 02:25, Joelle van Dyne <j@getutm.app> wrote:
>
> This introduces support for building for iOS hosts. When the correct Xcode
> toolchain is used, iOS host will be detected automatically.
>
> * block: disable features not supported by iOS sandbox
> * slirp: disable SMB features for iOS
> * osdep: disable system() calls for iOS

> +``ucontext`` support is broken on iOS. The implementation from ``libucontext``
> +is used instead.

Just a note since it came up in another thread today, but
looking at libucontext its aarch64 backend doesn't handle
the floating point registers. I think if the *context
routines don't save/restore the callee-saves fp regs
(v8-v15, FPCR) then it's liable to result in tricky-to-track
down bugs where some kept-in-a-callee-saves-fp-register data
from a function further up the callstack gets corrupted, depending
on what the compiler happens to do. It would be good to work with
the libucontext maintainers to add that functionality.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v6 3/7] qemu: add support for iOS host
  2021-01-21 18:53   ` Peter Maydell
@ 2023-11-28 15:12     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 21+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-11-28 15:12 UTC (permalink / raw)
  To: Peter Maydell, Joelle van Dyne
  Cc: Kevin Wolf, Laurent Vivier, Thomas Huth,
	open list:Block layer core, Jason Wang, QEMU Developers,
	Michael Roth, Roman Bolshakov, Samuel Thibault, Paolo Bonzini,
	Max Reitz, Daniel P. Berrangé,
	Stefan Hajnoczi, Alex Bennée

(Cc'ing Ariadne, libucontext maintainer)

On 21/1/21 19:53, Peter Maydell wrote:
> On Tue, 5 Jan 2021 at 02:25, Joelle van Dyne <j@getutm.app> wrote:
>>
>> This introduces support for building for iOS hosts. When the correct Xcode
>> toolchain is used, iOS host will be detected automatically.
>>
>> * block: disable features not supported by iOS sandbox
>> * slirp: disable SMB features for iOS
>> * osdep: disable system() calls for iOS
> 
>> +``ucontext`` support is broken on iOS. The implementation from ``libucontext``
>> +is used instead.
> 
> Just a note since it came up in another thread today, but
> looking at libucontext its aarch64 backend doesn't handle
> the floating point registers. I think if the *context
> routines don't save/restore the callee-saves fp regs
> (v8-v15, FPCR) then it's liable to result in tricky-to-track
> down bugs where some kept-in-a-callee-saves-fp-register data
> from a function further up the callstack gets corrupted, depending
> on what the compiler happens to do. It would be good to work with
> the libucontext maintainers to add that functionality.

Per https://github.com/kaniini/libucontext/blob/master/README.md#caveats
this is a design choice:

   Only basic GPR registers are saved and restored when context swapping.
   The glibc implementation uses hardware capability detection to
   save/restore other register groups, such as the FPU registers or
   vector processing (AltiVec/AVX/NEON) registers. Adding this capability
   detection would significantly increase the complexity of the project
   and thus is not implemented. Support for compiling in code to
   save/restore FPU registers or vector registers may be added in a later
   release as a build-time setting -- for now, we assume a soft-float ABI
   with no optional processor features.

Minor update in 2022:
https://github.com/kaniini/libucontext/commit/5244775fb93ab9

   This is a work in progress, as newer compilers will spill even
   non-floating-point state through floating point registers when allowed
   to do so.

Regards,

Phil.


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2023-11-28 15:13 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-05  2:20 [PATCH v6 0/7] iOS and Apple Silicon host support Joelle van Dyne
2021-01-05  2:20 ` [PATCH v6 1/7] configure: option to disable host block devices Joelle van Dyne
2021-01-05  2:20 ` [PATCH v6 2/7] configure: cross-compiling with empty cross_prefix Joelle van Dyne
2021-01-05  2:20 ` [PATCH v6 3/7] qemu: add support for iOS host Joelle van Dyne
2021-01-12 11:56   ` Philippe Mathieu-Daudé
2021-01-12 22:18     ` Joelle van Dyne
2021-01-12 15:03   ` Peter Maydell
2021-01-12 22:37     ` Joelle van Dyne
2021-01-21 18:53   ` Peter Maydell
2023-11-28 15:12     ` Philippe Mathieu-Daudé
2021-01-05  2:20 ` [PATCH v6 4/7] coroutine: add libucontext as external library Joelle van Dyne
2021-01-21 16:17   ` Daniel P. Berrangé
2021-01-21 17:11     ` Joelle van Dyne
2021-01-05  2:20 ` [PATCH v6 5/7] configure: cross compile should use x86_64 cpu_family Joelle van Dyne
2021-01-12 11:46   ` Philippe Mathieu-Daudé
2021-01-05  2:20 ` [PATCH v6 6/7] slirp: update build flags for iOS resolv fix Joelle van Dyne
2021-01-12 11:52   ` Philippe Mathieu-Daudé
2021-01-14 11:07     ` [Slirp] " Marc-André Lureau
2021-01-05  2:20 ` [PATCH v6 7/7] block: check availablity for preadv/pwritev on mac Joelle van Dyne
2021-01-12 11:01 ` [PATCH v6 0/7] iOS and Apple Silicon host support Peter Maydell
2021-01-12 22:05   ` Joelle van Dyne

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.