From patchwork Fri Sep 22 14:09:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Dennis-Jordan X-Patchwork-Id: 13395827 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 BE0ECE6FE32 for ; Fri, 22 Sep 2023 14:10:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qjgqr-0002vF-LO; Fri, 22 Sep 2023 10:09: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 1qjgqm-0002u6-1X for qemu-devel@nongnu.org; Fri, 22 Sep 2023 10:09:44 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qjgqk-0008P3-Js for qemu-devel@nongnu.org; Fri, 22 Sep 2023 10:09:43 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-31fe2c8db0dso1925941f8f.3 for ; Fri, 22 Sep 2023 07:09:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1695391781; x=1695996581; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NwlBBf3rtKK44LxBF31RQ5uFpkLivnaBoZpAWCqLFCs=; b=yhjg11L28hHZw8onSiiyz0iJ8CTuC9ATQ7JVX+O+jlfSrNnNHbvUq0wB41HuUZbWum 0PgNOPsR7JGcKnkSPty7wjsE04SudNyF6cDAdrinRtbYtR3ESg2xuDO+vAMtFgbOgGN4 snf3pV7BODov6fV9MfSvwE5XGTpJm5O+77TUQYMckV+vVYzOB+cTPZ5SwjPJQi9MqA9n qziL7N4VqPWXohLJ5YDNHPPxp7o5zyVS73z40YmkaB/+k18JS46ELEliIP6RlVWz1riq Bct1ATj4vvlfmcEb9njIw4fKm8FShqTaShDBoLQR84oFwsB/F/JVJLXFgH2Q98AlaZrh bQoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695391781; x=1695996581; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NwlBBf3rtKK44LxBF31RQ5uFpkLivnaBoZpAWCqLFCs=; b=AfDbBmKmQCLvkPbfRkBU6FV/0lxify0JqrOCaK5fP3ZB0bF8W3W69Oy98pVY/tDLeD 581CZHs9ForvhqTfT4LrSsGyohHtC2N9hLlhsQdvok6qEgrUTl+GfFAOedRuAnvPnxNW ze8f13yZ7CMij/Vah43o0IOBEld4zJ26DmJSldInjPGE853SUTJu54NLgVpQGdj5jUbl ftBnaTtQ6jP+ZvAPVhQZXxEghaTV1osF8YK+ig5zlJTpSvBO9SHhg/WuRbs7d/Gvx6W5 WGfxYIGI87qck0eXNph6CAQI7SJwS+kXm/lARYo32qpHjh5Vv7PK+zK6YPftmC4N4hCU WxEQ== X-Gm-Message-State: AOJu0Yw7k0cWRkFgLYnOOJObzazsfwvCMSX4BdialyOVHqZ1kZ4I0UuL pLEL+UzLX81G3Q0u/6CmTYQ39dYDl+x3/3QQyUM= X-Google-Smtp-Source: AGHT+IHoBMN1jFEO04emIPxLz8c1aKi9bFLbR7D1HioY0UNIggIa6G/4kdSgIBW8PxmbAPfQoQAh9g== X-Received: by 2002:adf:fc92:0:b0:31f:fa61:961d with SMTP id g18-20020adffc92000000b0031ffa61961dmr8334632wrr.63.1695391781119; Fri, 22 Sep 2023 07:09:41 -0700 (PDT) Received: from localhost.localdomain (89-104-8-249.customer.bnet.at. [89.104.8.249]) by smtp.gmail.com with ESMTPSA id g27-20020a170906395b00b009ae587ce128sm2725823eje.216.2023.09.22.07.09.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 07:09:40 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: dirty@apple.com, rbolshakov@ddn.com, lists@philjordan.eu, Phil Dennis-Jordan Subject: [PATCH 1/3] i386: hvf: Adds support for INVTSC cpuid bit Date: Fri, 22 Sep 2023 16:09:12 +0200 Message-Id: <20230922140914.13906-2-phil@philjordan.eu> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20230922140914.13906-1-phil@philjordan.eu> References: <20230922140914.13906-1-phil@philjordan.eu> MIME-Version: 1.0 Received-SPF: neutral client-ip=2a00:1450:4864:20::429; envelope-from=phil@philjordan.eu; helo=mail-wr1-x429.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list 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 adds the INVTSC bit to the Hypervisor.framework accelerator's CPUID bit passthrough allow-list. Previously, specifying +invtsc in the CPU configuration would fail with the following warning despite the host CPU advertising the feature: qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000007H:EDX.invtsc [bit 8] x86 macOS itself relies on a fixed rate TSC for its own Mach absolute time timestamp mechanism, so there's no reason we can't enable this bit for guests. Signed-off-by: Phil Dennis-Jordan Reviewed-by: Roman Bolshakov Tested-by: Roman Bolshakov --- target/i386/hvf/x86_cpuid.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/i386/hvf/x86_cpuid.c b/target/i386/hvf/x86_cpuid.c index 7323a7a94b..d2721bd2a7 100644 --- a/target/i386/hvf/x86_cpuid.c +++ b/target/i386/hvf/x86_cpuid.c @@ -145,6 +145,10 @@ uint32_t hvf_get_supported_cpuid(uint32_t func, uint32_t idx, CPUID_EXT3_3DNOWPREFETCH | CPUID_EXT3_OSVW | CPUID_EXT3_XOP | CPUID_EXT3_FMA4 | CPUID_EXT3_TBM; break; + case 0x80000007: + edx &= CPUID_APM_INVTSC; + eax = ebx = ecx = 0; + break; default: return 0; } From patchwork Fri Sep 22 14:09:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Dennis-Jordan X-Patchwork-Id: 13395829 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 477B1E6FE2F for ; Fri, 22 Sep 2023 14:10:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qjgqw-0002xy-P6; Fri, 22 Sep 2023 10:09:54 -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 1qjgqp-0002uv-Dq for qemu-devel@nongnu.org; Fri, 22 Sep 2023 10:09:47 -0400 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qjgqn-0008PY-Ub for qemu-devel@nongnu.org; Fri, 22 Sep 2023 10:09:47 -0400 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2c007d6159aso37174111fa.3 for ; Fri, 22 Sep 2023 07:09:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1695391784; x=1695996584; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RwgPyvay9DFmsLuOUJUHjUScLN28OjxwI/Y1FI48aMc=; b=RUwVJC1EJcctYPFti4fCvVIX+NkdzJtzSZeUljmJsL1hj+qZILfjB51Z7bvMR4Tz3U p6OITbZz+E6E0Dc6rQFzCZZ9nK5HHbDJq4C8Ap8iRp7tCj5NHp4yrfvH4jn+hN14YCis itDahkmERN1DWTlXgNiH3e1YTBTWPY1UwhV50btxmHlv6ZGKjXxa2AYKUUR69R0hyst2 bX3MiigiZuqHugzdRCqDfc3MSWGkhc8pr+uKgEHsyJD0ozmNAFda7MvqNelAaDdCJi8H c9Rjc9G9sI/3iJJH33LrBNse82eHeb/PYiOOfRdV/oQrlpDronGYYxhMLTrwbRIo2q1d b+NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695391784; x=1695996584; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RwgPyvay9DFmsLuOUJUHjUScLN28OjxwI/Y1FI48aMc=; b=t/OA3C7qDNtxddUqS0ylPkg6fZ4pUsQaoX9jGwtyFzKTrirenA5ZYw+8NChv4GFhV+ 36I/Ftbn1hU79j60ERay7NyY3o55e4nlzGhz3p5NSP2z3rpBC/5difot0N1swAWRRcQP 3NzRoFrXfUyXJRxM5V8/OlwIba0xwZH9m7h5CKnXUI3OFBczu9NbM40LdI73Usfp5ZrH 5B4UG8kbqxLTlD32cSZiWwBjBHRdbyVzf+2gkkdSr44RJ9jFOy1PNB2zwtSYX+tsqAFm frAkREC1+RRIc48ZzRKQOiR/qa2a2JlThN8JwoYDozCOGF47azF6/+6hNi9hSi7mo7jr IRVw== X-Gm-Message-State: AOJu0YzQBH7hZffvqmgysXw2yF+5NWmwtaQJM8/6PXlbyd5GOxLk5Tm2 pAiyZ/Q2YKY2EIpnwZrQjHTueqSiIU51jQCn9Ek= X-Google-Smtp-Source: AGHT+IETnI/4u8YyfHlagvukoYXzlEM9QY8mUCNmZocylHYkU7Q/8cYIrAIgdBXhby/cWT4JpsiIbA== X-Received: by 2002:a2e:9b86:0:b0:2bf:fb49:6619 with SMTP id z6-20020a2e9b86000000b002bffb496619mr7325385lji.23.1695391784123; Fri, 22 Sep 2023 07:09:44 -0700 (PDT) Received: from localhost.localdomain (89-104-8-249.customer.bnet.at. [89.104.8.249]) by smtp.gmail.com with ESMTPSA id g27-20020a170906395b00b009ae587ce128sm2725823eje.216.2023.09.22.07.09.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 07:09:43 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: dirty@apple.com, rbolshakov@ddn.com, lists@philjordan.eu, Phil Dennis-Jordan Subject: [PATCH 2/3] i386: hvf: In kick_vcpu use hv_vcpu_interrupt to force exit Date: Fri, 22 Sep 2023 16:09:13 +0200 Message-Id: <20230922140914.13906-3-phil@philjordan.eu> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20230922140914.13906-1-phil@philjordan.eu> References: <20230922140914.13906-1-phil@philjordan.eu> MIME-Version: 1.0 Received-SPF: neutral client-ip=2a00:1450:4864:20::22e; envelope-from=phil@philjordan.eu; helo=mail-lj1-x22e.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list 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 When interrupting a vCPU thread, this patch actually tells the hypervisor to stop running guest code on that vCPU. Calling hv_vcpu_interrupt actually forces a vCPU exit, analogously to hv_vcpus_exit on aarch64. Previously, hvf_kick_vcpu_thread relied upon hv_vcpu_run returning very frequently, including many spurious exits, which made it less of a problem that nothing was actively done to stop the vCPU thread running guest code. The newer, more efficient hv_vcpu_run_until exits much more rarely, so a true "kick" is needed. Signed-off-by: Phil Dennis-Jordan --- target/i386/hvf/hvf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index cb2cd0b02f..55bd7d2af8 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -209,7 +209,10 @@ static inline bool apic_bus_freq_is_known(CPUX86State *env) void hvf_kick_vcpu_thread(CPUState *cpu) { + hv_vcpuid_t hvf_vcpuid; cpus_kick_thread(cpu); + hvf_vcpuid = cpu->accel->fd; + hv_vcpu_interrupt(&hvf_vcpuid, 1); } int hvf_arch_init(void) From patchwork Fri Sep 22 14:09:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Phil Dennis-Jordan X-Patchwork-Id: 13395830 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 D5100E6FE2F for ; Fri, 22 Sep 2023 14:10:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qjgqx-0002yn-Fm; Fri, 22 Sep 2023 10:09:55 -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 1qjgqs-0002w0-He for qemu-devel@nongnu.org; Fri, 22 Sep 2023 10:09:52 -0400 Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qjgqq-0008Py-Ca for qemu-devel@nongnu.org; Fri, 22 Sep 2023 10:09:49 -0400 Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2bfea381255so37141771fa.3 for ; Fri, 22 Sep 2023 07:09:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1695391786; x=1695996586; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WgvxkIY3+j2qIvKdDbYfJBN2du/aHpWbM4Y0iyDsskY=; b=EJtFwnG6zCCNE0iw3NW0ALzTsi+lkMRJEPTzXPI5k1kfg78KhBsGT4KKYH7OPOI8jK T+Fk7uynpXTC6epeZuGUx7XM5qBCcjGmKzcG7OIBJWEIfWB8JpBvPSs+50ug923lG+Cn Ic9UrbUyM11jAGkwFp+UsTfTp+xGou2NUqc5qWFfIzRhX61YUaRw1wacSwkmhZbzvLy4 qVcnXoA2IFpggvSXecmox28gHM3uVVv2WswXIqWXOJBx3i74RNsj7FS8xBC/Hfda8nA1 crO+QaLfPHDNBA6W+3fYCOusLaXxB4KGaOtnk0syR4F+Dy+X3UpmJvYX+BAPVFFUONXL VAZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695391786; x=1695996586; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WgvxkIY3+j2qIvKdDbYfJBN2du/aHpWbM4Y0iyDsskY=; b=q4sZnB23ZFavlGUIvUKjATyreISolCE8GG2xp12XuxkY9xVMiMtlTk93ZyGCYHRv5B xVGLa/AjTBBNbiTfeXXrwwMwaqOG2nb7FJ99WuWVbfO2k2nY780p6DUsMQrl9DGeookS m+ex6LdeZ+bgwFntliKxLcNzbP/il9jUGaaX3BGQr7NAsrdDkjcNwWdm7HhuKK44iHAO RbU542fFKrScPEFvo17WsOoTfoBg4klTd9Qe5HA1gXN2K+BphZK/d1A9e6HSJDGm+NPG gw7Hs8dvAmG9ko2T+6B8wZBucQgFB0gKjbqulOaxaZDe/4dSsxyNaSNchetYkq/5EUro Nw/A== X-Gm-Message-State: AOJu0YzDXUpYxmcl/SLKBeycfSZSZWTDZd42bWII5Vmmlq6OtX3fS/Zn gTFBNlSQ/OQVzeF40z1nzhQpAeMKRg7pifOF1wQ= X-Google-Smtp-Source: AGHT+IGUqOhxUCB82o+yTrCJioaXz1V/a3rdke6PWrJaTZB/0NHLVQM35YmT3MUbasnmhSo3hqKiEg== X-Received: by 2002:a2e:9c07:0:b0:2c0:2583:520e with SMTP id s7-20020a2e9c07000000b002c02583520emr7651387lji.41.1695391786598; Fri, 22 Sep 2023 07:09:46 -0700 (PDT) Received: from localhost.localdomain (89-104-8-249.customer.bnet.at. [89.104.8.249]) by smtp.gmail.com with ESMTPSA id g27-20020a170906395b00b009ae587ce128sm2725823eje.216.2023.09.22.07.09.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 07:09:46 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: dirty@apple.com, rbolshakov@ddn.com, lists@philjordan.eu, Phil Dennis-Jordan Subject: [PATCH 3/3] i386: hvf: Updates API usage to use modern vCPU run function Date: Fri, 22 Sep 2023 16:09:14 +0200 Message-Id: <20230922140914.13906-4-phil@philjordan.eu> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20230922140914.13906-1-phil@philjordan.eu> References: <20230922140914.13906-1-phil@philjordan.eu> MIME-Version: 1.0 Received-SPF: neutral client-ip=2a00:1450:4864:20::22f; envelope-from=phil@philjordan.eu; helo=mail-lj1-x22f.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list 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 macOS 10.15 introduced the more efficient hv_vcpu_run_until() function to supersede hv_vcpu_run(). According to the documentation, there is no longer any reason to use the latter on modern host OS versions. Observed behaviour of the newer function is that as documented, it exits much less frequently - and most of the original function’s exits seem to have been effectively pointless. Another reason to use the new function is that it is a prerequisite for using newer features such as in-kernel APIC support. (Not covered by this patch.) This change implements the upgrade by selecting one of three code paths at compile time: two static code paths for the new and old functions respectively, when building for targets where the new function is either not available, or where the built executable won’t run on older platforms lacking the new function anyway. The third code path selects dynamically based on runtime detected availability of the weakly-linked symbol. Signed-off-by: Phil Dennis-Jordan --- target/i386/hvf/hvf.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index 55bd7d2af8..e4c785c686 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -410,6 +410,27 @@ static void hvf_cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, } } +static hv_return_t hvf_vcpu_run(hv_vcpuid_t vcpu_id) +{ + /* + * hv_vcpu_run_until is available and recommended from macOS 10.15+. + * Test for availability at runtime and fall back to hv_vcpu_run() only + * where necessary. + */ +#ifndef MAC_OS_X_VERSION_10_15 + return hv_vcpu_run(vcpu_id); +#elif MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15 + return hv_vcpu_run_until(vcpu_id, HV_DEADLINE_FOREVER); +#else /* MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_15 */ + /* 10.15 SDK or newer, but could be < 10.15 at runtime */ + if (__builtin_available(macOS 10.15, *)) { + return hv_vcpu_run(vcpu_id); + } else { + return hv_vcpu_run_until(vcpu_id, HV_DEADLINE_FOREVER); + } +#endif +} + int hvf_vcpu_exec(CPUState *cpu) { X86CPU *x86_cpu = X86_CPU(cpu); @@ -438,7 +459,7 @@ int hvf_vcpu_exec(CPUState *cpu) return EXCP_HLT; } - hv_return_t r = hv_vcpu_run(cpu->accel->fd); + hv_return_t r = hvf_vcpu_run(cpu->accel->fd); assert_hvf_ok(r); /* handle VMEXIT */