From patchwork Sun Nov 8 23:24:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joelle van Dyne X-Patchwork-Id: 1396429 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=getutm.app Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CTqxp1Jdrz9sVK for ; Mon, 9 Nov 2020 10:26:06 +1100 (AEDT) Received: from localhost ([::1]:35354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kbu4S-0000m6-52 for incoming@patchwork.ozlabs.org; Sun, 08 Nov 2020 18:26:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45216) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbu2y-0000lC-6W; Sun, 08 Nov 2020 18:24:32 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:45187) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kbu2w-0000FN-HF; Sun, 08 Nov 2020 18:24:31 -0500 Received: by mail-pg1-f196.google.com with SMTP id 62so5230341pgg.12; Sun, 08 Nov 2020 15:24:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eTDNRgkwVFVIO6gfDAlg28i26N+Iawwag3UMxHNMUOo=; b=fCdr5u3B4kR7B2u6hwcAro5q6k/MXZ6ae8Tk4DWQoQ27nuquovu7s4nNZMFRkVW5Zh tG5wd7qJRZ3It//H5mkKPgjE1ZKKpVkdcmVAUKF/GMmqDh6UgzRdSOT8bVmv1rLkg8Zf bX8dLkuQg9EUGhScK7f4cdCmdRy0ALARvFD6eNuuCDOJIx1/zjuajFu2k1e1Isnm+1vT zDJ3USIYlv8YmdER2RDf83SMkyea2atcj5GhaLxeTbpAknX0RQtyM2Qq/B5kRUtEjEhU IBgIGlJGTDRhVVO5ccE+Zg5PGhz83mKcuYtQ21U8MUjRTd21VzhxJb9oQ4gXOsTBoC0U RGfw== X-Gm-Message-State: AOAM53003WFon/rZxBTXnN/OAU5rymQp1TrRXl+dRXkvOl3QdFgNP9uI n7BjxlP/bkHQk3lrivOD6YZEbVUcuk8= X-Google-Smtp-Source: ABdhPJzAmwZwiKBAmCqLw77426IMKrUqwxHuY/jI+c/8k6HlnAcDPZqfwKeOpjNR14vN2MJJKZ1Lxw== X-Received: by 2002:a63:4c12:: with SMTP id z18mr6379260pga.143.1604877868542; Sun, 08 Nov 2020 15:24:28 -0800 (PST) Received: from localhost.localdomain ([73.93.154.215]) by smtp.gmail.com with ESMTPSA id z3sm8275171pgl.73.2020.11.08.15.24.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Nov 2020 15:24:28 -0800 (PST) From: Joelle van Dyne To: qemu-devel@nongnu.org Subject: [PATCH v5 1/7] configure: option to disable host block devices Date: Sun, 8 Nov 2020 15:24:18 -0800 Message-Id: <20201108232425.1705-2-j@getutm.app> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201108232425.1705-1-j@getutm.app> References: <20201108232425.1705-1-j@getutm.app> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.215.196; envelope-from=osy86github@gmail.com; helo=mail-pg1-f196.google.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/08 18:24:29 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , "open list:raw" , Markus Armbruster , Max Reitz , Joelle van Dyne Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 2c3c69f118..97a879808d 100755 --- a/configure +++ b/configure @@ -448,6 +448,7 @@ meson="" ninja="" skip_meson=no gettext="" +host_block_device_support="yes" bogus_os="no" malloc_trim="auto" @@ -5907,6 +5908,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 39ac5cf6d8..fd822346e7 100644 --- a/meson.build +++ b/meson.build @@ -2166,6 +2166,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 1b8b4156b4..408be635ae 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -980,7 +980,8 @@ 'discriminator': 'driver', 'data': { 'file': 'BlockStatsSpecificFile', - 'host_device': 'BlockStatsSpecificFile', + 'host_device': { 'type': 'BlockStatsSpecificFile', + 'if': 'defined(CONFIG_HOST_BLOCK_DEVICE)' }, 'nvme': 'BlockStatsSpecificNvme' } } ## @@ -2848,7 +2849,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)' }, @@ -4016,7 +4019,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 c63926d592..a0fa9aad3a 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 #include #include @@ -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); From patchwork Sun Nov 8 23:24:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Joelle van Dyne X-Patchwork-Id: 1396433 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=getutm.app Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CTr3P1bw2z9sSf for ; Mon, 9 Nov 2020 10:30:57 +1100 (AEDT) Received: from localhost ([::1]:43516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kbu99-0004Tw-6L for incoming@patchwork.ozlabs.org; Sun, 08 Nov 2020 18:30:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45218) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbu2y-0000lZ-LV for qemu-devel@nongnu.org; Sun, 08 Nov 2020 18:24:32 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:42638) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kbu2x-0000FS-3r for qemu-devel@nongnu.org; Sun, 08 Nov 2020 18:24:32 -0500 Received: by mail-pl1-f194.google.com with SMTP id t22so3679666plr.9 for ; Sun, 08 Nov 2020 15:24:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=clC6oHTfnrMMN3FfznLE0Frgl/AYxxtTAqo83NQAGqs=; b=QVmJP7K1ecniehBySBC0etbRxLlbuC/VAY5Yxy3YPEFWdGVXI59xQGHYYhfSeol3V+ a5aL39FVQPyX6APyRZ9ZPUfroRoo5wF11p0S6fki0bOU99K3whhS4jeZMTDTyzPvwol8 rMkhFl6eTKs1YlMO3ZNDyuI10J3VaQa/CCR4L0H+DuaoPQ3JvrP65bhx9jqt4T6ymm8S FPDtgZRdqw2vsaUkAzH2dyiMiGGIJRExdhPsd3lcRG4esQHPiICnXu9c3QntQF1oFNku c41q5SfexbmZV/S8ySufUWwwSDAPKVqR6Q22ONPxv20Ky8j5+CcouV62caSIT2qZ7DG+ Lcyg== X-Gm-Message-State: AOAM531TK22YO6VRxBGk6/54hnnOFpjxUM7oaNLypJeFy1JIwz9RAu7a QIyYu9RSa0J4KoCLduiQTQeceHMNk60= X-Google-Smtp-Source: ABdhPJyZztW4mdpzqMuNVv+amDuDxQLcIN8oVGd63NFHMHTKQNnU7UxZotkD/lhI42KhB8IlcPie0Q== X-Received: by 2002:a17:902:d698:b029:d6:b974:13c5 with SMTP id v24-20020a170902d698b02900d6b97413c5mr10702095ply.13.1604877869564; Sun, 08 Nov 2020 15:24:29 -0800 (PST) Received: from localhost.localdomain ([73.93.154.215]) by smtp.gmail.com with ESMTPSA id z3sm8275171pgl.73.2020.11.08.15.24.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Nov 2020 15:24:29 -0800 (PST) From: Joelle van Dyne To: qemu-devel@nongnu.org Subject: [PATCH v5 2/7] configure: cross-compiling with empty cross_prefix Date: Sun, 8 Nov 2020 15:24:19 -0800 Message-Id: <20201108232425.1705-3-j@getutm.app> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201108232425.1705-1-j@getutm.app> References: <20201108232425.1705-1-j@getutm.app> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.214.194; envelope-from=osy86github@gmail.com; helo=mail-pl1-f194.google.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/08 18:24:30 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joelle van Dyne Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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. Signed-off-by: Joelle van Dyne Reviewed-by: Philippe Mathieu-Daudé --- configure | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 97a879808d..fda7a875f7 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="" @@ -458,6 +459,7 @@ for opt do optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)') case "$opt" in --cross-prefix=*) cross_prefix="$optarg" + cross_compile="yes" ;; --cc=*) CC="$optarg" ;; @@ -1657,7 +1659,7 @@ $(echo Available targets: $default_target_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 @@ -6933,7 +6935,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 From patchwork Sun Nov 8 23:24:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joelle van Dyne X-Patchwork-Id: 1396435 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=getutm.app Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CTr855Cr2z9sSf for ; Mon, 9 Nov 2020 10:35:01 +1100 (AEDT) Received: from localhost ([::1]:47914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kbuD5-0006eG-KJ for incoming@patchwork.ozlabs.org; Sun, 08 Nov 2020 18:34:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45250) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbu31-0000pD-Nr; Sun, 08 Nov 2020 18:24:35 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:33728) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kbu2z-0000Fm-7c; Sun, 08 Nov 2020 18:24:35 -0500 Received: by mail-pg1-f193.google.com with SMTP id r186so5271578pgr.0; Sun, 08 Nov 2020 15:24:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ttY5ncyy7BrT7Kmjsqme660xtaDnKnSGuGFstQY6vK4=; b=dXHb03XP8SmduZOAci22lvEmxxSTc055e/X4FpwLH0fCjbwtjO6ZZFhgmKQXiKxSQW oXISDD9NvZ1kFfcfgjtwsz29g0Ksav9+pQIQovjyeXZAdeBG1fjZ/7G8t1ENcsArXfgq Mpq3X7+hfmhVNN7HhqG15stMACY832ZXzfX+RUA9CPhjdq4Sf947uKicESXxtb+AfSwn o74WQdTEL08xYTYr9teXPs3BM5yuDx2E+rQRdSccIA30OiQP97Vk/8wDqau/YICchgsl J4hfVyXHH6bN19mGHEFTQywTYgKJc1V9SgTIa6DXQU3kEQPNn83smiAivGB48exRuuMw QVGQ== X-Gm-Message-State: AOAM530gKZ54UWTlP+Pw8HdA0bIIijMldypVBdxbGkuwQ74rctdOAA47 Ts76TXHnUnVOxMD0kbK+SteVwPYhzEM= X-Google-Smtp-Source: ABdhPJxNF/Lczuhsboa16wsPG/IBRvDNiF0AAWPgg5oy5CXQJ3GNeWX2qdAS4Vte8QeBDZyPDRWgZw== X-Received: by 2002:a17:90a:ab0f:: with SMTP id m15mr378851pjq.188.1604877871216; Sun, 08 Nov 2020 15:24:31 -0800 (PST) Received: from localhost.localdomain ([73.93.154.215]) by smtp.gmail.com with ESMTPSA id z3sm8275171pgl.73.2020.11.08.15.24.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Nov 2020 15:24:30 -0800 (PST) From: Joelle van Dyne To: qemu-devel@nongnu.org Subject: [PATCH v5 3/7] qemu: add support for iOS host Date: Sun, 8 Nov 2020 15:24:20 -0800 Message-Id: <20201108232425.1705-4-j@getutm.app> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201108232425.1705-1-j@getutm.app> References: <20201108232425.1705-1-j@getutm.app> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.215.193; envelope-from=osy86github@gmail.com; helo=mail-pg1-f193.google.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/08 18:24:31 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Laurent Vivier , Thomas Huth , "open list:Block layer core" , Jason Wang , Michael Roth , Max Reitz , Joelle van Dyne , Paolo Bonzini , Samuel Thibault Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 77baae5c77..a46740929f 100644 --- a/docs/devel/index.rst +++ b/docs/devel/index.rst @@ -34,3 +34,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 fda7a875f7..2a6db88a46 100755 --- a/configure +++ b/configure @@ -557,6 +557,19 @@ EOF compile_object } +check_ios() { + cat > $TMPC < $TMPC < @@ -599,7 +612,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 @@ -777,6 +794,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}" @@ -5962,6 +5995,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 @@ -6926,6 +6963,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 @@ -6944,6 +6982,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 fd822346e7..8894171bd1 100644 --- a/meson.build +++ b/meson.build @@ -176,7 +176,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 56bacc9e9f..e99cbf25ee 100644 --- a/block.c +++ b/block.c @@ -53,7 +53,7 @@ #ifdef CONFIG_BSD #include #include -#ifndef __DragonFly__ +#if !defined(__DragonFly__) && !defined(CONFIG_IOS) #include #endif #endif diff --git a/block/file-posix.c b/block/file-posix.c index a0fa9aad3a..d83219df55 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. @@ -2306,7 +2323,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 #include #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 3711080d07..66a2f2ac9e 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 #define environ (*_NSGetEnviron()) #else diff --git a/MAINTAINERS b/MAINTAINERS index 63223e1183..1ec4c67a62 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -528,6 +528,13 @@ F: include/*/*win32* X: qga/*win32* F: qemu.nsi +IOS +M: Joelle van Dyne +S: Maintained +K: ^Subject:.*(?i)iOS +F: docs/devel/ios.rst +F: include/tcg/tcg-apple-jit.h + Alpha Machines -------------- M: Richard Henderson diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index c19f1c8503..8a151ee2da 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', From patchwork Sun Nov 8 23:24:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Joelle van Dyne X-Patchwork-Id: 1396432 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=getutm.app Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CTqy90j3Qz9sSs for ; Mon, 9 Nov 2020 10:26:21 +1100 (AEDT) Received: from localhost ([::1]:36006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kbu4f-00015b-DD for incoming@patchwork.ozlabs.org; Sun, 08 Nov 2020 18:26:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45288) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbu33-0000rj-Aj for qemu-devel@nongnu.org; Sun, 08 Nov 2020 18:24:37 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:33730) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kbu2z-0000G3-TD for qemu-devel@nongnu.org; Sun, 08 Nov 2020 18:24:36 -0500 Received: by mail-pg1-f194.google.com with SMTP id r186so5271618pgr.0 for ; Sun, 08 Nov 2020 15:24:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=k7nWDNSu2uxZanbJsgfUYWfPU9vJuXxEsNE9XhtXX7E=; b=N0CSEb4s9oEV6RYegHzvTUiAxLSfejUTiecwBLzXMQIORlpLhco1VQ4Cgd9WBY3DUa 87UOW7aOsJg7ic0R7c/WnvCJw1AvWMFRdDt+ccD8UZ1F30EnDcbGjrdoc3jIVB5KWrNH iLaIbybCYoScCbYIdq6I2ypCg5YoRTpDgvGjz9gQ/WT0TTOpnrGqw+3UriD3QaRiJoPH Wz2IdoV3b7MTHrsDTiL/LjDENprtBlOTNUJCAeiuJHNwyuo+JPXVHPUeFSbyZZkwWXJU nazhDkCOlC4OOm2fAgIxqBIl0Se23UCIcWIIzLB83LBQ3ryd/YF4YVIVntgaVcJcTbWn 91bQ== X-Gm-Message-State: AOAM531Giq1O9TwsLAdRCpIcrwOkp4zP3Cqds5FafYMnZ4vGUN24HStX URJ+IPlFk6e31Cl61LNBvfdwJRsVwhk= X-Google-Smtp-Source: ABdhPJwxLwHzn9bcsWgIlqk2Ij2LDZHwIgsS+Xj6Ks3kNpPhVI0b6EfJFsRdscfnVaUfZMfLKlwPTw== X-Received: by 2002:a17:90a:6309:: with SMTP id e9mr9558694pjj.115.1604877872322; Sun, 08 Nov 2020 15:24:32 -0800 (PST) Received: from localhost.localdomain ([73.93.154.215]) by smtp.gmail.com with ESMTPSA id z3sm8275171pgl.73.2020.11.08.15.24.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Nov 2020 15:24:31 -0800 (PST) From: Joelle van Dyne To: qemu-devel@nongnu.org Subject: [PATCH v5 4/7] coroutine: add libucontext as external library Date: Sun, 8 Nov 2020 15:24:21 -0800 Message-Id: <20201108232425.1705-5-j@getutm.app> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201108232425.1705-1-j@getutm.app> References: <20201108232425.1705-1-j@getutm.app> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.215.194; envelope-from=osy86github@gmail.com; helo=mail-pg1-f194.google.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/08 18:24:32 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Joelle van Dyne , Stefan Hajnoczi Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tested-by: Philippe Mathieu-Daudé --- configure | 23 ++++++++++++++++++++--- meson.build | 28 +++++++++++++++++++++++++++- util/coroutine-ucontext.c | 9 +++++++++ .gitmodules | 3 +++ libucontext | 1 + meson_options.txt | 2 ++ 6 files changed, 62 insertions(+), 4 deletions(-) create mode 160000 libucontext diff --git a/configure b/configure index 2a6db88a46..d1c6aa9750 100755 --- a/configure +++ b/configure @@ -1750,7 +1750,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 @@ -4883,6 +4883,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 @@ -4906,12 +4908,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} libucontext" + mkdir -p libucontext + coroutine_impl=ucontext + libucontext="enabled" + ;; +*) + coroutine_impl=$coroutine + libucontext="disabled" + ;; +esac + if test "$coroutine_pool" = ""; then coroutine_pool=yes fi @@ -6457,7 +6474,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 @@ -7035,7 +7052,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 \ $cross_arg \ diff --git a/meson.build b/meson.build index 8894171bd1..b087721f63 100644 --- a/meson.build +++ b/meson.build @@ -1259,9 +1259,34 @@ if not fdt.found() and fdt_required.length() > 0 error('fdt not available but required by targets ' + ', '.join(fdt_required)) endif +ucontext = not_found +if get_option('ucontext').enabled() + arch = host_machine.cpu() + if not fs.is_dir(meson.current_source_dir() / 'libucontext/arch' / arch) + error('libucontext is wanted but not implemented for host ' + arch) + endif + ucontext_cargs = ['-DG_LOG_DOMAIN="ucontext"', '-DCUSTOM_IMPL'] + ucontext_files = [ + 'libucontext/arch' / arch / 'getcontext.S', + 'libucontext/arch' / arch / 'setcontext.S', + 'libucontext/arch' / arch / 'makecontext.c', + 'libucontext/arch' / arch / 'startcontext.S', + 'libucontext/arch' / arch / 'swapcontext.S', + ] + + ucontext_inc = include_directories('libucontext/include') + libucontext = static_library('ucontext', + sources: ucontext_files, + c_args: ucontext_cargs, + include_directories: ucontext_inc) + ucontext = declare_dependency(link_with: libucontext, + include_directories: ucontext_inc) +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 # @@ -1477,7 +1502,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) @@ -2135,6 +2160,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..1e1dd43512 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 +#define ucontext_t libucontext_ucontext_t +#define getcontext libucontext_getcontext +#define setcontext libucontext_setcontext +#define swapcontext libucontext_swapcontext +#define makecontext libucontext_makecontext +#else #include +#endif #include "qemu/coroutine_int.h" #ifdef CONFIG_VALGRIND_H diff --git a/.gitmodules b/.gitmodules index 2bdeeacef8..065b52867f 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 = libucontext + url = https://github.com/utmapp/libucontext.git diff --git a/libucontext b/libucontext new file mode 160000 index 0000000000..455ecd495f --- /dev/null +++ b/libucontext @@ -0,0 +1 @@ +Subproject commit 455ecd495f706d5b57be3ff5b572c120c2a7a5a2 diff --git a/meson_options.txt b/meson_options.txt index b4f1801875..da24102898 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -64,6 +64,8 @@ option('xkbcommon', type : 'feature', value : 'auto', description: 'xkbcommon support') option('virtiofsd', type: 'feature', value: 'auto', description: 'build virtiofs daemon (virtiofsd)') +option('ucontext', type : 'feature', value : 'disabled', + description: 'libucontext support') option('capstone', type: 'combo', value: 'auto', choices: ['disabled', 'enabled', 'auto', 'system', 'internal'], From patchwork Sun Nov 8 23:24:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joelle van Dyne X-Patchwork-Id: 1396436 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=getutm.app Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CTrCy0v5Pz9sSf for ; Mon, 9 Nov 2020 10:38:19 +1100 (AEDT) Received: from localhost ([::1]:53302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kbuGG-0000bP-6l for incoming@patchwork.ozlabs.org; Sun, 08 Nov 2020 18:38:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45276) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbu33-0000rU-5K for qemu-devel@nongnu.org; Sun, 08 Nov 2020 18:24:37 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:38313) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kbu31-0000GD-Co for qemu-devel@nongnu.org; Sun, 08 Nov 2020 18:24:36 -0500 Received: by mail-pl1-f196.google.com with SMTP id f21so3684073plr.5 for ; Sun, 08 Nov 2020 15:24:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=x7c1G4sLPVoD9U12VrxMHshwvUYHPPrNVoUtKYDzjSE=; b=nUbNKCkVgZJbxJdvri9k2T0gCXA8GW04BMXJ2Ua8YI0WjXyooe1Ma+dC+1k+Rfds38 eN3tQASLUloQklOt9PwxqtCTkprNXRpBOqPVYQlyqjMhvkaVDYHc3YGzbYDpm5Cd69I2 f34bh4aS6FPReM0qfgIi4V8rnkbmcldWhEu7G+SZRG7e/44Gkxwju8mD4ppC1rnue74T xCBWK/5lpMurk24on9UbliI23UOieo6n18GT/UxO8H6WZbg35FI3GXL8vLNOJgquv/fe 6jyxlCw/oycGr7W6SJBtIH7jEnCwOKPDZ1Tp6h+rrdz6Oshn3IPzHrVxr/gOpIdD75ib vN/A== X-Gm-Message-State: AOAM531k/OvIIgFM4PUEXinO5P1q6vnWJSf/vul/cX51Ks3vQ4Qq5iBs 7dp/2n4723pZrRTMKeTjaj+bX1iadAw= X-Google-Smtp-Source: ABdhPJyIskYdBBOxFpjmwxcD5ngxyEa0oEMbDvTDA9qLC/nixqGUGrW++7KRqZyJW9Wqafw7j7unIg== X-Received: by 2002:a17:902:b196:b029:d6:ffaf:c3c9 with SMTP id s22-20020a170902b196b02900d6ffafc3c9mr9731978plr.62.1604877873444; Sun, 08 Nov 2020 15:24:33 -0800 (PST) Received: from localhost.localdomain ([73.93.154.215]) by smtp.gmail.com with ESMTPSA id z3sm8275171pgl.73.2020.11.08.15.24.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Nov 2020 15:24:33 -0800 (PST) From: Joelle van Dyne To: qemu-devel@nongnu.org Subject: [PATCH v5 5/7] slirp: update build flags for iOS resolv fix Date: Sun, 8 Nov 2020 15:24:22 -0800 Message-Id: <20201108232425.1705-6-j@getutm.app> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201108232425.1705-1-j@getutm.app> References: <20201108232425.1705-1-j@getutm.app> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.214.196; envelope-from=osy86github@gmail.com; helo=mail-pl1-f196.google.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/08 18:24:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joelle van Dyne , Stefan Hajnoczi Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" A future libslirp update will use libresolv on Darwin systems, so we add the flags in QEMU build now. Reviewed-by: Stefan Hajnoczi Signed-off-by: Joelle van Dyne --- meson.build | 2 ++ 1 file changed, 2 insertions(+) diff --git a/meson.build b/meson.build index b087721f63..40dd3b30fc 100644 --- a/meson.build +++ b/meson.build @@ -1156,6 +1156,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]) From patchwork Sun Nov 8 23:24:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joelle van Dyne X-Patchwork-Id: 1396434 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=getutm.app Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CTr3p56wcz9sSf for ; Mon, 9 Nov 2020 10:31:18 +1100 (AEDT) Received: from localhost ([::1]:44132 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kbu9U-0004kU-Kk for incoming@patchwork.ozlabs.org; Sun, 08 Nov 2020 18:31:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbu34-0000tc-A4 for qemu-devel@nongnu.org; Sun, 08 Nov 2020 18:24:38 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:41151) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kbu32-0000GM-5Q for qemu-devel@nongnu.org; Sun, 08 Nov 2020 18:24:37 -0500 Received: by mail-pg1-f196.google.com with SMTP id f18so769794pgi.8 for ; Sun, 08 Nov 2020 15:24:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oqTRRse3ML08CbYMBMir3imYmfVxmJCy/vR5/9jdsfA=; b=uee72tzzBOfOSt4ecT17oG9023oMrORREMO3hjRXfisVbAHYquuODTy6F412UCP0Nc y/J3au5d02j/9l6AUW7b7W8ks4tP5YfmzOxuuolS6mVE1X4pm4ZQrzrvjRiVlmD1mAgG IoBam8MzuSGbtDTNubH4tP6mGSEOmyDnQBycjpO4ngBwsvawvevTuKNUE4SosiYptmib 4o3Gj/DmnrCeUl0BBlg/YPWhY+7aJ5sMApqGhq1SnmKpOs8U4XxmiTl6oXP2YMGu9jDN 1o5vh0Yg0BTKgPnhHcLZVI0Gw1CqiLhrGp10Z6dpkYRVxIR8B/FAD3lLl9OweV5vxykH fqAw== X-Gm-Message-State: AOAM533VIuZmNY33nPGYrmSttnihi64hQFbb+tgKN4crQkhX0U5cVLIp 7C8pdbumVZL162MZyf+BGza7WpNveDM= X-Google-Smtp-Source: ABdhPJz2CwfqeamI2DkpxiOMaVyE2ZHBUiqZGfpwcmep4NXMYEmMpOVPvKocMnINVZRo3D8Ddna/LQ== X-Received: by 2002:a17:90a:5204:: with SMTP id v4mr9427428pjh.188.1604877874671; Sun, 08 Nov 2020 15:24:34 -0800 (PST) Received: from localhost.localdomain ([73.93.154.215]) by smtp.gmail.com with ESMTPSA id z3sm8275171pgl.73.2020.11.08.15.24.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Nov 2020 15:24:34 -0800 (PST) From: Joelle van Dyne To: qemu-devel@nongnu.org Subject: [PATCH v5 6/7] tcg: implement JIT for iOS and Apple Silicon Date: Sun, 8 Nov 2020 15:24:23 -0800 Message-Id: <20201108232425.1705-7-j@getutm.app> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201108232425.1705-1-j@getutm.app> References: <20201108232425.1705-1-j@getutm.app> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.215.196; envelope-from=osy86github@gmail.com; helo=mail-pg1-f196.google.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/08 18:24:29 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Joelle van Dyne , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" When entitlements are available (macOS or jailbroken iOS), a hardware feature called APRR exists on newer Apple Silicon that can cheaply mark JIT pages as either RX or RW. Reverse engineered functions from libsystem_pthread.dylib are implemented to handle this. The following rules apply for JIT write protect: * JIT write-protect is enabled before tcg_qemu_tb_exec() * JIT write-protect is disabled after tcg_qemu_tb_exec() returns * JIT write-protect is disabled inside do_tb_phys_invalidate() but if it is called inside of tcg_qemu_tb_exec() then write-protect will be enabled again before returning. * JIT write-protect is disabled by cpu_loop_exit() for interrupt handling. * JIT write-protect is disabled everywhere else. See https://developer.apple.com/documentation/apple_silicon/porting_just-in-time_compilers_to_apple_silicon Signed-off-by: Joelle van Dyne --- include/exec/exec-all.h | 2 + include/tcg/tcg-apple-jit.h | 86 +++++++++++++++++++++++++++++++++++++ include/tcg/tcg.h | 3 ++ accel/tcg/cpu-exec-common.c | 2 + accel/tcg/cpu-exec.c | 2 + accel/tcg/translate-all.c | 46 ++++++++++++++++++++ tcg/tcg.c | 4 ++ 7 files changed, 145 insertions(+) create mode 100644 include/tcg/tcg-apple-jit.h diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index aa65103702..3829f3d470 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -549,6 +549,8 @@ TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc, target_ulong cs_base, uint32_t flags, uint32_t cf_mask); void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr); +void tb_exec_lock(void); +void tb_exec_unlock(void); /* GETPC is the true target of the return instruction that we'll execute. */ #if defined(CONFIG_TCG_INTERPRETER) diff --git a/include/tcg/tcg-apple-jit.h b/include/tcg/tcg-apple-jit.h new file mode 100644 index 0000000000..9efdb2000d --- /dev/null +++ b/include/tcg/tcg-apple-jit.h @@ -0,0 +1,86 @@ +/* + * Apple Silicon functions for JIT handling + * + * Copyright (c) 2020 osy + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef TCG_APPLE_JIT_H +#define TCG_APPLE_JIT_H + +/* + * APRR handling + * Credits to: https://siguza.github.io/APRR/ + * Reversed from /usr/lib/system/libsystem_pthread.dylib + */ + +#if defined(__aarch64__) && defined(CONFIG_DARWIN) + +#define _COMM_PAGE_START_ADDRESS (0x0000000FFFFFC000ULL) /* In TTBR0 */ +#define _COMM_PAGE_APRR_SUPPORT (_COMM_PAGE_START_ADDRESS + 0x10C) +#define _COMM_PAGE_APPR_WRITE_ENABLE (_COMM_PAGE_START_ADDRESS + 0x110) +#define _COMM_PAGE_APRR_WRITE_DISABLE (_COMM_PAGE_START_ADDRESS + 0x118) + +static __attribute__((__always_inline__)) bool jit_write_protect_supported(void) +{ + /* Access shared kernel page at fixed memory location. */ + uint8_t aprr_support = *(volatile uint8_t *)_COMM_PAGE_APRR_SUPPORT; + return aprr_support > 0; +} + +/* write protect enable = write disable */ +static __attribute__((__always_inline__)) void jit_write_protect(int enabled) +{ + /* Access shared kernel page at fixed memory location. */ + uint8_t aprr_support = *(volatile uint8_t *)_COMM_PAGE_APRR_SUPPORT; + if (aprr_support == 0 || aprr_support > 3) { + return; + } else if (aprr_support == 1) { + __asm__ __volatile__ ( + "mov x0, %0\n" + "ldr x0, [x0]\n" + "msr S3_4_c15_c2_7, x0\n" + "isb sy\n" + :: "r" (enabled ? _COMM_PAGE_APRR_WRITE_DISABLE + : _COMM_PAGE_APPR_WRITE_ENABLE) + : "memory", "x0" + ); + } else { + __asm__ __volatile__ ( + "mov x0, %0\n" + "ldr x0, [x0]\n" + "msr S3_6_c15_c1_5, x0\n" + "isb sy\n" + :: "r" (enabled ? _COMM_PAGE_APRR_WRITE_DISABLE + : _COMM_PAGE_APPR_WRITE_ENABLE) + : "memory", "x0" + ); + } +} + +#else /* defined(__aarch64__) && defined(CONFIG_DARWIN) */ + +static __attribute__((__always_inline__)) bool jit_write_protect_supported(void) +{ + return false; +} + +static __attribute__((__always_inline__)) void jit_write_protect(int enabled) +{ +} + +#endif + +#endif /* define TCG_APPLE_JIT_H */ diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 477919aeb6..b16b687d0b 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -625,6 +625,9 @@ struct TCGContext { size_t code_gen_buffer_size; void *code_gen_ptr; void *data_gen_ptr; +#if defined(CONFIG_DARWIN) && !defined(CONFIG_TCG_INTERPRETER) + bool code_gen_locked; /* on Darwin each thread tracks W^X flags */ +#endif /* Threshold to flush the translated code buffer. */ void *code_gen_highwater; diff --git a/accel/tcg/cpu-exec-common.c b/accel/tcg/cpu-exec-common.c index 12c1e3e974..f1eb767b02 100644 --- a/accel/tcg/cpu-exec-common.c +++ b/accel/tcg/cpu-exec-common.c @@ -64,6 +64,8 @@ void cpu_reloading_memory_map(void) void cpu_loop_exit(CPUState *cpu) { + /* Unlock JIT write protect if applicable. */ + tb_exec_unlock(); /* Undo the setting in cpu_tb_exec. */ cpu->can_do_io = 1; siglongjmp(cpu->jmp_env, 1); diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 8df0a1782e..960e0c1f36 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -176,7 +176,9 @@ static inline TranslationBlock *cpu_tb_exec(CPUState *cpu, } #endif /* DEBUG_DISAS */ + tb_exec_lock(); ret = tcg_qemu_tb_exec(env, tb_ptr); + tb_exec_unlock(); cpu->can_do_io = 1; /* * TODO: Delay swapping back to the read-write region of the TB diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 06102871e7..5773c561cb 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -27,6 +27,9 @@ #include "disas/disas.h" #include "exec/exec-all.h" #include "tcg/tcg.h" +#if defined(CONFIG_DARWIN) +#include "tcg/tcg-apple-jit.h" +#endif #if defined(CONFIG_USER_ONLY) #include "qemu.h" #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) @@ -61,6 +64,9 @@ #include "sysemu/tcg.h" #include "qapi/error.h" +static bool tb_exec_is_locked(void); +static void tb_exec_change(bool locked); + /* #define DEBUG_TB_INVALIDATE */ /* #define DEBUG_TB_FLUSH */ /* make various TB consistency checks */ @@ -1339,6 +1345,7 @@ void tcg_exec_init(unsigned long tb_size, int splitwx) splitwx, &error_fatal); assert(ok); + tb_exec_unlock(); #if defined(CONFIG_SOFTMMU) /* There's no guest base to take into account, so go ahead and initialize the prologue now. */ @@ -1615,8 +1622,11 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list) PageDesc *p; uint32_t h; tb_page_addr_t phys_pc; + bool code_gen_locked; assert_memory_lock(); + code_gen_locked = tb_exec_is_locked(); + tb_exec_unlock(); /* make sure no further incoming jumps will be chained to this TB */ qemu_spin_lock(&tb->jmp_lock); @@ -1629,6 +1639,7 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list) tb->trace_vcpu_dstate); if (!(tb->cflags & CF_NOCACHE) && !qht_remove(&tb_ctx.htable, tb, h)) { + tb_exec_change(code_gen_locked); return; } @@ -1661,6 +1672,8 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list) qatomic_set(&tcg_ctx->tb_phys_invalidate_count, tcg_ctx->tb_phys_invalidate_count + 1); + + tb_exec_change(code_gen_locked); } static void tb_phys_invalidate__locked(TranslationBlock *tb) @@ -2899,3 +2912,36 @@ void tcg_flush_softmmu_tlb(CPUState *cs) tlb_flush(cs); #endif } + +#if defined(CONFIG_DARWIN) && !defined(CONFIG_TCG_INTERPRETER) +static bool tb_exec_is_locked(void) +{ + return tcg_ctx->code_gen_locked; +} + +static void tb_exec_change(bool locked) +{ + if (jit_write_protect_supported()) { + jit_write_protect(locked); + } + tcg_ctx->code_gen_locked = locked; +} +#else /* not needed on non-Darwin platforms */ +static bool tb_exec_is_locked(void) +{ + return false; +} + +static void tb_exec_change(bool locked) {} +#endif + +void tb_exec_lock(void) +{ + /* assumes sys_icache_invalidate already called */ + tb_exec_change(true); +} + +void tb_exec_unlock(void) +{ + tb_exec_change(false); +} diff --git a/tcg/tcg.c b/tcg/tcg.c index d3052031cb..5ed79d2724 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -809,6 +809,8 @@ static void alloc_tcg_plugin_context(TCGContext *s) void tcg_register_thread(void) { tcg_ctx = &tcg_init_ctx; + + tb_exec_unlock(); } #else void tcg_register_thread(void) @@ -843,6 +845,8 @@ void tcg_register_thread(void) err = tcg_region_initial_alloc__locked(tcg_ctx); g_assert(!err); qemu_mutex_unlock(®ion.lock); + + tb_exec_unlock(); } #endif /* !CONFIG_USER_ONLY */ From patchwork Sun Nov 8 23:24:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joelle van Dyne X-Patchwork-Id: 1396431 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=getutm.app Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CTqxx3NkZz9sSf for ; Mon, 9 Nov 2020 10:26:13 +1100 (AEDT) Received: from localhost ([::1]:35688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kbu4Z-0000wC-D6 for incoming@patchwork.ozlabs.org; Sun, 08 Nov 2020 18:26:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45318) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbu35-0000ux-Ad; Sun, 08 Nov 2020 18:24:39 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:37522) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kbu33-0000GW-Jh; Sun, 08 Nov 2020 18:24:38 -0500 Received: by mail-pg1-f195.google.com with SMTP id h6so5262085pgk.4; Sun, 08 Nov 2020 15:24:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8sFMHG4A1NXc60aR+dQ5Qpal+/YO08FLzmS69fkJXIc=; b=VzeD3JWqfR4TAehKhCHvkwyn8feNGYEHcqCIQT/1M57Y/TJn271BNPw9ZtV6/Gtvc0 5odW5sKYOElMkmkIQ8NTrHOmLY8U5xdgZStBVzFeL0nfkxdgGiSuxrbYz6yWFv2SR0fC FwD4U8NVRNNMz4u7WgCDY5uTkDhT/LorTJCaT6GxZ5v2DmsXw70cnKLBU6edH741/EgJ 4b4FlUJaAoEvInRhonBaedNFx0rOxRPp9/s4m+Xw1xQDQzEQECIdAuPtjAOVCUgvnsWi Uy6KGKsTyrdExO3St5cKobD2iCoPMhIckuxyrztmUww++yE3d2cbASrksZojw893Xmt2 BGDA== X-Gm-Message-State: AOAM530VDmiRzz9AZ4BJw7dbwh8pOaNpyLBsg31CSiCKK9EDThJPEkPg iXjNZKjS0mzAh4hrg+RWlvDMoQTl6MQ= X-Google-Smtp-Source: ABdhPJxdVCYJU4IEOzNMXxjr7Km/+3nMznVGvzPu+SeXt/gVuuGVar/D5SA1+wCbem3yiMEOQgcoLQ== X-Received: by 2002:a17:90a:3d0f:: with SMTP id h15mr9881096pjc.234.1604877875779; Sun, 08 Nov 2020 15:24:35 -0800 (PST) Received: from localhost.localdomain ([73.93.154.215]) by smtp.gmail.com with ESMTPSA id z3sm8275171pgl.73.2020.11.08.15.24.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Nov 2020 15:24:35 -0800 (PST) From: Joelle van Dyne To: qemu-devel@nongnu.org Subject: [PATCH v5 7/7] block: check availablity for preadv/pwritev on mac Date: Sun, 8 Nov 2020 15:24:24 -0800 Message-Id: <20201108232425.1705-8-j@getutm.app> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201108232425.1705-1-j@getutm.app> References: <20201108232425.1705-1-j@getutm.app> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.215.195; envelope-from=osy86github@gmail.com; helo=mail-pg1-f195.google.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/08 18:24:36 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Joelle van Dyne , "open list:raw" , Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index d83219df55..a9d69746a0 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1394,12 +1394,24 @@ static bool preadv_present = true; 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 (!__builtin_available(macOS 11, iOS 14, watchOS 7, tvOS 14, *)) { + preadv_present = false; + return -ENOSYS; + } else +#endif return preadv(fd, iov, nr_iov, offset); } static ssize_t qemu_pwritev(int fd, const struct iovec *iov, int nr_iov, off_t offset) { +#ifdef CONFIG_DARWIN /* pwritev introduced in macOS 11 */ + if (!__builtin_available(macOS 11, iOS 14, watchOS 7, tvOS 14, *)) { + preadv_present = false; + return -ENOSYS; + } else +#endif return pwritev(fd, iov, nr_iov, offset); }