From patchwork Wed Aug 30 16:14:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 13370342 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 03A5EC6FA8F for ; Wed, 30 Aug 2023 16:18:31 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbNqD-00030W-U1; Wed, 30 Aug 2023 12:14:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbNqC-0002zo-2H; Wed, 30 Aug 2023 12:14:48 -0400 Received: from smtp-fw-80006.amazon.com ([99.78.197.217]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbNq9-0003bz-BS; Wed, 30 Aug 2023 12:14:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1693412086; x=1724948086; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=+8hLgFkWvMXm6uldA/BXf1FRkrOuAMgPjsKZWzE7P30=; b=IG0D9hZCBrOIUyCD56e0AM9TeFtjtC3j6fKm4fODzDfnutZQEz1FI8Xk 0kI8ja2wQPreCLSZVt8cA/o4WRmmm7y/IXgCMrydvNbaY1ao61zNxakY1 vXr8R2l8l0aEg7sJRoGJSepYVHv6NTDIDSlXXFZAC6i9CfcvnZAVS6JyI s=; X-IronPort-AV: E=Sophos;i="6.02,214,1688428800"; d="scan'208";a="235834940" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-m6i4x-a65ebc6e.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-80006.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2023 16:14:37 +0000 Received: from EX19MTAUWC001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1e-m6i4x-a65ebc6e.us-east-1.amazon.com (Postfix) with ESMTPS id 8634F67E25; Wed, 30 Aug 2023 16:14:31 +0000 (UTC) Received: from EX19D020UWC004.ant.amazon.com (10.13.138.149) by EX19MTAUWC001.ant.amazon.com (10.250.64.174) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.37; Wed, 30 Aug 2023 16:14:29 +0000 Received: from dev-dsk-graf-1a-5ce218e4.eu-west-1.amazon.com (10.253.83.51) by EX19D020UWC004.ant.amazon.com (10.13.138.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.37; Wed, 30 Aug 2023 16:14:27 +0000 From: Alexander Graf To: CC: , , Cameron Esfahani , Stefan Hajnoczi , "Michael S . Tsirkin" , Kevin Wolf , Hanna Reitz , Marcel Apfelbaum , "Paolo Bonzini" , Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Mads Ynddal , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , Bernhard Beschow , Gerd Hoffmann Subject: [PATCH v2 00/12] Introduce new vmapple machine type Date: Wed, 30 Aug 2023 16:14:13 +0000 Message-ID: <20230830161425.91946-1-graf@amazon.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Originating-IP: [10.253.83.51] X-ClientProxiedBy: EX19D036UWC003.ant.amazon.com (10.13.139.214) To EX19D020UWC004.ant.amazon.com (10.13.138.149) Precedence: Bulk Received-SPF: pass client-ip=99.78.197.217; envelope-from=prvs=599fd62c5=graf@amazon.de; helo=smtp-fw-80006.amazon.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This patch set introduces a new ARM and HVF specific machine type called "vmapple". It mimicks the device model that Apple's proprietary Virtualization.Framework exposes, but implements it in QEMU. With this new machine type, you can run macOS guests on Apple Silicon systems via HVF. To do so, you need to first install macOS using Virtualization.Framework onto a virtual disk image using a tool like macosvm (https://github.com/s-u/macosvm) $ macosvm --disk disk.img,size=32g --aux aux.img \ --restore UniversalMac_12.0.1_21A559_Restore.ipsw vm.json Then, extract the ECID from the installed VM: $ cat "$DIR/macosvm.json" | python3 -c \ 'import json,sys;obj=json.load(sys.stdin);print(obj["machineId"]) | \ base64 -d | plutil -extract ECID raw - In addition, cut off the first 16kb of the aux.img: $ dd if=aux.img of=aux.img.trimmed bs=$(( 0x4000 )) skip=1 Now, you can just launch QEMU with the bits generated above: $ qemu-system-aarch64 -serial mon:stdio \ -m 4G \ -M vmapple,uuid=6240349656165161789 \ -bios /Sys*/Lib*/Fra*/Virtualization.f*/R*/AVPBooter.vmapple2.bin \ -pflash aux.img.trimmed \ -pflash disk.img \ -drive file=disk.img,if=none,id=root \ -device vmapple-virtio-root,drive=root \ -drive file=aux.img.trimmed,if=none,id=aux \ -device vmapple-virtio-aix,drive=aux \ -accel hvf There are a few limitations with this implementation: - Only runs on macOS because it relies on ParavirtualizesGraphics.Framework - Something is not fully correct on interrupt delivery or similar - the keyboard does not work - No Rosetta in the guest because we lack the private entitlement to enable TSO Over time, I hope that some of the limitations above could cease to exist. This device model would enable very nice use cases with KVM on an Asahi Linux device. Please beware that the vmapple device model only works with macOS 12 guests for now. Newer guests run into Hypervisor.Framework incompatibilities. --- v1 -> v2: - Adapt to system_ss meson.build target - Add documentation - Rework virtio-blk patch to make all vmapple virtio-blk logic subclasses - Add log message on write - Move max slot number to define - Use SPDX header - Remove useless includes Alexander Graf (12): build: Only define OS_OBJECT_USE_OBJC with gcc hw/misc/pvpanic: Add MMIO interface hvf: Increase number of possible memory slots hvf: arm: Ignore writes to CNTP_CTL_EL0 hw: Add vmapple subdir gpex: Allow more than 4 legacy IRQs hw/vmapple/aes: Introduce aes engine hw/vmapple/bdif: Introduce vmapple backdoor interface hw/vmapple/cfg: Introduce vmapple cfg region hw/vmapple/apple-gfx: Introduce ParavirtualizedGraphics.Framework support hw/vmapple/virtio-blk: Add support for apple virtio-blk hw/vmapple/vmapple: Add vmapple machine type MAINTAINERS | 7 + docs/system/arm/vmapple.rst | 68 ++++ docs/system/target-arm.rst | 1 + meson.build | 9 +- hw/vmapple/trace.h | 1 + include/hw/misc/pvpanic.h | 1 + include/hw/pci-host/gpex.h | 7 +- include/hw/pci/pci_ids.h | 1 + include/hw/virtio/virtio-blk.h | 11 +- include/hw/vmapple/bdif.h | 31 ++ include/hw/vmapple/cfg.h | 68 ++++ include/hw/vmapple/virtio-blk.h | 39 ++ include/sysemu/hvf_int.h | 4 +- accel/hvf/hvf-accel-ops.c | 2 +- hw/arm/sbsa-ref.c | 2 +- hw/arm/virt.c | 2 +- hw/block/virtio-blk.c | 18 +- hw/i386/microvm.c | 2 +- hw/loongarch/virt.c | 2 +- hw/mips/loongson3_virt.c | 2 +- hw/misc/pvpanic-mmio.c | 61 +++ hw/openrisc/virt.c | 12 +- hw/pci-host/gpex.c | 36 +- hw/riscv/virt.c | 12 +- hw/vmapple/aes.c | 583 ++++++++++++++++++++++++++++ hw/vmapple/bdif.c | 245 ++++++++++++ hw/vmapple/cfg.c | 105 +++++ hw/vmapple/virtio-blk.c | 212 ++++++++++ hw/vmapple/vmapple.c | 661 ++++++++++++++++++++++++++++++++ hw/xtensa/virt.c | 2 +- target/arm/hvf/hvf.c | 9 + hw/Kconfig | 1 + hw/meson.build | 1 + hw/misc/Kconfig | 4 + hw/misc/meson.build | 1 + hw/vmapple/Kconfig | 33 ++ hw/vmapple/apple-gfx.m | 578 ++++++++++++++++++++++++++++ hw/vmapple/meson.build | 6 + hw/vmapple/trace-events | 47 +++ 39 files changed, 2852 insertions(+), 35 deletions(-) create mode 100644 docs/system/arm/vmapple.rst create mode 100644 hw/vmapple/trace.h create mode 100644 include/hw/vmapple/bdif.h create mode 100644 include/hw/vmapple/cfg.h create mode 100644 include/hw/vmapple/virtio-blk.h create mode 100644 hw/misc/pvpanic-mmio.c create mode 100644 hw/vmapple/aes.c create mode 100644 hw/vmapple/bdif.c create mode 100644 hw/vmapple/cfg.c create mode 100644 hw/vmapple/virtio-blk.c create mode 100644 hw/vmapple/vmapple.c create mode 100644 hw/vmapple/Kconfig create mode 100644 hw/vmapple/apple-gfx.m create mode 100644 hw/vmapple/meson.build create mode 100644 hw/vmapple/trace-events