From patchwork Sat Oct 21 20:05:15 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: 13431567 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 B958BC001E0 for ; Sat, 21 Oct 2023 20:06:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1quIEJ-0004cB-RY; Sat, 21 Oct 2023 16:05:52 -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 1quIEH-0004U7-Mh for qemu-devel@nongnu.org; Sat, 21 Oct 2023 16:05:49 -0400 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1quIEF-0006r1-TF for qemu-devel@nongnu.org; Sat, 21 Oct 2023 16:05:49 -0400 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-523100882f2so2817425a12.2 for ; Sat, 21 Oct 2023 13:05:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1697918745; x=1698523545; 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=ovMG+qqsPp4n1CFPMcT1aXFMbGSaoM4oGxF97m1LS7I=; b=I4//VssykApD8OGPHsDF5V9ygvSIzZ2vsyFqvWx3fBts0OgsUfMNOlgQdXQKHGywjl K+ktLoS8Gg8z3mjVFZNjakbt0UHtoPgIv6kgVYkogNBfxa8p1fu/HjnRuzSN92cAJzI2 Qd1nR6FUjCAnvI0W4XYM/CdUJWxkTycZE7GsMocY8Sw6YVtSjOBoUvFhiPgkUCx5zCsG OdhjxljFD2nQoslYUR7SGhWNEwkZ2UDiV9AkrEee7GSfFZgGGQx518UzLl6fz+kWgjUv JjwwidptuDwCZ86u8lspLNuYIVvHB11FHkcoBAuhyexqt06DJAPnXREXSYJogHcSLMBG O8vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697918745; x=1698523545; 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=ovMG+qqsPp4n1CFPMcT1aXFMbGSaoM4oGxF97m1LS7I=; b=VqSo1nLNKa6f60KvFGqHRejpidMELORPl5fD1ODXl4b9DZR51fVhu5HUrxaiEFPLz8 wkswTkUoz+60laj2YqUdLs2r/SX5SrCnE72Tu7s0P8MCtZD6+kD549JOwWbYC6W70sNi dP0WnhU40O//mpH7EuhQRmxL4PbfcFDXc+awEFPXa03MPkSgMU25u0xRQTJudDBQ4n+y E1QneKyNRMqpt63PcO6PJXyE//XesgyE3RDKWPJQuUWQyubYB6IvQejLa6bY+5f1p48e Y5SZx0VmLF9XHSa5py4S17KrB0VqE5Vd2BPtSK+XhmhrKOq9I1bu882ZTK7/RZjCB4gk bKuA== X-Gm-Message-State: AOJu0Yy2Vm9C8GMhuXqzorRORMizJMUIoDTD25X4aWvtoJfivmGK/3zw 5EHTzlI5A+x8gGKVejo5HvO866Sx0nQ82njLSfU= X-Google-Smtp-Source: AGHT+IFn8ZuJ3zdT1j6mzl2J0I1SsOa+RLl8pKPzaYd++hf7VvzYs2WV+kTxeEgkxGFoXYq19Sy07A== X-Received: by 2002:a17:907:318d:b0:9ae:6ad0:f6cd with SMTP id xe13-20020a170907318d00b009ae6ad0f6cdmr3799588ejb.24.1697918744975; Sat, 21 Oct 2023 13:05: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 u2-20020a17090617c200b0098ce63e36e9sm4138253eje.16.2023.10.21.13.05.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Oct 2023 13:05:44 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: dirty@apple.com, roman@roolebo.dev, pbonzini@redhat.com, lists@philjordan.eu, phil@philjordan.eu Subject: [PATCH v2 1/4] i386: hvf: Adds support for INVTSC cpuid bit Date: Sat, 21 Oct 2023 22:05:15 +0200 Message-Id: <20231021200518.30125-2-phil@philjordan.eu> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20231021200518.30125-1-phil@philjordan.eu> References: <20231021200518.30125-1-phil@philjordan.eu> MIME-Version: 1.0 Received-SPF: neutral client-ip=2a00:1450:4864:20::533; envelope-from=phil@philjordan.eu; helo=mail-ed1-x533.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. When the feature is enabled, a migration blocker is installed. Signed-off-by: Phil Dennis-Jordan Reviewed-by: Roman Bolshakov Tested-by: Roman Bolshakov --- target/i386/hvf/hvf.c | 18 ++++++++++++++++++ target/i386/hvf/x86_cpuid.c | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index cb2cd0b02f..43d64574ad 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -49,6 +49,8 @@ #include "qemu/osdep.h" #include "qemu/error-report.h" #include "qemu/memalign.h" +#include "qapi/error.h" +#include "migration/blocker.h" #include "sysemu/hvf.h" #include "sysemu/hvf_int.h" @@ -74,6 +76,8 @@ #include "qemu/accel.h" #include "target/i386/cpu.h" +static Error *invtsc_mig_blocker; + void vmx_update_tpr(CPUState *cpu) { /* TODO: need integrate APIC handling */ @@ -221,6 +225,8 @@ int hvf_arch_init_vcpu(CPUState *cpu) { X86CPU *x86cpu = X86_CPU(cpu); CPUX86State *env = &x86cpu->env; + Error *local_err = NULL; + int r; uint64_t reqCap; init_emu(); @@ -238,6 +244,18 @@ int hvf_arch_init_vcpu(CPUState *cpu) } } + if ((env->features[FEAT_8000_0007_EDX] & CPUID_APM_INVTSC) && + invtsc_mig_blocker == NULL) { + error_setg(&invtsc_mig_blocker, + "State blocked by non-migratable CPU device (invtsc flag)"); + r = migrate_add_blocker(&invtsc_mig_blocker, &local_err); + if (r < 0) { + error_report_err(local_err); + return r; + } + } + + if (hv_vmx_read_capability(HV_VMX_CAP_PINBASED, &hvf_state->hvf_caps->vmx_cap_pinbased)) { abort(); diff --git a/target/i386/hvf/x86_cpuid.c b/target/i386/hvf/x86_cpuid.c index 9380b90496..e56cd8411b 100644 --- a/target/i386/hvf/x86_cpuid.c +++ b/target/i386/hvf/x86_cpuid.c @@ -146,6 +146,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 Sat Oct 21 20:05:16 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: 13431566 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 BBE3DC0032E for ; Sat, 21 Oct 2023 20:06:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1quIES-00057X-04; Sat, 21 Oct 2023 16:06:00 -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 1quIEP-0004yu-FC for qemu-devel@nongnu.org; Sat, 21 Oct 2023 16:05:57 -0400 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1quIEL-0006th-W4 for qemu-devel@nongnu.org; Sat, 21 Oct 2023 16:05:56 -0400 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-540105dea92so746951a12.2 for ; Sat, 21 Oct 2023 13:05:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1697918752; x=1698523552; 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=97zIIxwvzvuxLbE1OphDxtWK5OJmfKyrS2a8WN8AJRw=; b=p7jmFuc1jKNPWNqxrEoV/YfE6PDbfyMHv+evQR0vn3qp1SRC/And669Md1Bi6FG28R GYaSvRD+qrLmH/ExnNvJIaM7ga/l/ku8MX6NwDWwb5+32b6k/OiCOoK4799pO1URtL1z RFknyq3UsvgVbE9aytpsWZihSf9QkCPQtHGCghqJY3NhvZIiFFfkGmZWx9ua96+/UAb1 aNUKMe741pt7rpcVeTF/U5cyRTl5fh/3FahxsF+/NoLSEnH3nHfr2K+HZdZZnBIk/76I l5TFxwZqesv6d+optEHhcCpC5lPXVqNMG4XvF+cNLAzK0ShUosmAD+t+6iAW/n/I4FoA g0pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697918752; x=1698523552; 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=97zIIxwvzvuxLbE1OphDxtWK5OJmfKyrS2a8WN8AJRw=; b=KueZPQADgcd0WBWLEfpvvE16ahHcKrgitz5TMLdKeahwwpTpdb/p+I3pXjrAAQ8hyL EZDSOuuZ3lCacWLp+U/v5rMB3djfWrC5/EO6wVojREJMl78LzIg4FIfdptUBBxC196fC swO2aC2+nqxACqNGXNi13DUBvni2bf6O877IxtN0jDZHMTJpzLSEWTTzi9XC2ZKXZ8hL kucxv5sHQ1BcX/Q57zZQYnpEPnrOcj9qaZ4FA0v6NLtFXu/hIqfMyExhvgVf3j88zVxn EsXIDurmnh5MA5EqyqksoTTuC149DZkACs6C34Bgk2rBFGBwe6bU86U+9dKLCVSELFt3 e2/A== X-Gm-Message-State: AOJu0YykKs4Io+0MgMyfuP982WVxDtf0rCHgRbRz1/dSkD87vBH9J4En Sy9Iu39LZ8zGi/ufCCVy4dOzKzVnRGF9YuiK2MQ= X-Google-Smtp-Source: AGHT+IFeOnpuTc8gzWF5zi9kod6ByqZKxgeNeCBT5i3jmcWErGxlesIGEvXY8ACJuuXVep/PEfdibg== X-Received: by 2002:a17:907:930b:b0:9be:71ab:fb58 with SMTP id bu11-20020a170907930b00b009be71abfb58mr3930481ejc.75.1697918751994; Sat, 21 Oct 2023 13:05:51 -0700 (PDT) Received: from localhost.localdomain (89-104-8-249.customer.bnet.at. [89.104.8.249]) by smtp.gmail.com with ESMTPSA id u2-20020a17090617c200b0098ce63e36e9sm4138253eje.16.2023.10.21.13.05.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Oct 2023 13:05:51 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: dirty@apple.com, roman@roolebo.dev, pbonzini@redhat.com, lists@philjordan.eu, phil@philjordan.eu Subject: [PATCH v2 2/4] hvf: Fixes some compilation warnings Date: Sat, 21 Oct 2023 22:05:16 +0200 Message-Id: <20231021200518.30125-3-phil@philjordan.eu> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20231021200518.30125-1-phil@philjordan.eu> References: <20231021200518.30125-1-phil@philjordan.eu> MIME-Version: 1.0 Received-SPF: neutral client-ip=2a00:1450:4864:20::531; envelope-from=phil@philjordan.eu; helo=mail-ed1-x531.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 A bunch of function definitions used empty parentheses instead of (void) syntax, yielding the following warning when building with clang on macOS: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes] In addition to fixing these function headers, it also fixes what appears to be a typo causing a variable to be unused after initialisation. warning: variable 'entry_ctls' set but not used [-Wunused-but-set-variable] Signed-off-by: Phil Dennis-Jordan Reviewed-by: Roman Bolshakov Tested-by: Roman Bolshakov --- target/i386/hvf/vmx.h | 3 +-- target/i386/hvf/x86_decode.c | 2 +- target/i386/hvf/x86_emu.c | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/target/i386/hvf/vmx.h b/target/i386/hvf/vmx.h index 0fffcfa46c..3954ef883d 100644 --- a/target/i386/hvf/vmx.h +++ b/target/i386/hvf/vmx.h @@ -95,8 +95,7 @@ static void enter_long_mode(hv_vcpuid_t vcpu, uint64_t cr0, uint64_t efer) efer |= MSR_EFER_LMA; wvmcs(vcpu, VMCS_GUEST_IA32_EFER, efer); entry_ctls = rvmcs(vcpu, VMCS_ENTRY_CTLS); - wvmcs(vcpu, VMCS_ENTRY_CTLS, rvmcs(vcpu, VMCS_ENTRY_CTLS) | - VM_ENTRY_GUEST_LMA); + wvmcs(vcpu, VMCS_ENTRY_CTLS, entry_ctls | VM_ENTRY_GUEST_LMA); uint64_t guest_tr_ar = rvmcs(vcpu, VMCS_GUEST_TR_ACCESS_RIGHTS); if ((efer & MSR_EFER_LME) && diff --git a/target/i386/hvf/x86_decode.c b/target/i386/hvf/x86_decode.c index 3728d7705e..a4a28f113f 100644 --- a/target/i386/hvf/x86_decode.c +++ b/target/i386/hvf/x86_decode.c @@ -2111,7 +2111,7 @@ uint32_t decode_instruction(CPUX86State *env, struct x86_decode *decode) return decode->len; } -void init_decoder() +void init_decoder(void) { int i; diff --git a/target/i386/hvf/x86_emu.c b/target/i386/hvf/x86_emu.c index ccda568478..852f766161 100644 --- a/target/i386/hvf/x86_emu.c +++ b/target/i386/hvf/x86_emu.c @@ -1410,7 +1410,7 @@ static struct cmd_handler { static struct cmd_handler _cmd_handler[X86_DECODE_CMD_LAST]; -static void init_cmd_handler() +static void init_cmd_handler(void) { int i; for (i = 0; i < ARRAY_SIZE(handlers); i++) { @@ -1482,7 +1482,7 @@ bool exec_instruction(CPUX86State *env, struct x86_decode *ins) return true; } -void init_emu() +void init_emu(void) { init_cmd_handler(); } From patchwork Sat Oct 21 20:05:17 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: 13431568 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 16E70C001E0 for ; Sat, 21 Oct 2023 20:06:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1quIEh-0005Ns-Kk; Sat, 21 Oct 2023 16:06:15 -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 1quIEg-0005M1-5O for qemu-devel@nongnu.org; Sat, 21 Oct 2023 16:06:14 -0400 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1quIEb-0006uv-2P for qemu-devel@nongnu.org; Sat, 21 Oct 2023 16:06:13 -0400 Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-53e3b8f906fso2934815a12.2 for ; Sat, 21 Oct 2023 13:06:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1697918765; x=1698523565; 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=VsUolhqTt9BsjhTqkC8onV1WKcY/dQnGV/wAPJThXRA=; b=I251L+3kvZINlM43FAF4bRTalAZe/V/G2T7fTj7yxn8PwSkZpmOFJyxTSAgTU9bQ3D Je5o+R9jAp1GwYpc/T7Xzh2UkbBR1QtEUQDvmCg0ZF/Y5qsAWGAH+6g4G3sK4IiEfRmD x1+nLk88ec07uLAcRAbV5LiVGyrx3Tp62LHKLPWhQlBy7G2yR/fyg93umBS59+40ix/V oLELqp2IbmMyWc6mjAt4PuiqLPAuCe9kr8uou7vZvRIgMCrQAPjmIzg12MblNq/aigoI j50QXytj1s3VH03ZN5uty4BeXUmmtZxHFiIkPQaFVKpM2OOx59LGrESAxz6A0q3GA3tP uI+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697918765; x=1698523565; 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=VsUolhqTt9BsjhTqkC8onV1WKcY/dQnGV/wAPJThXRA=; b=FfFA9SzVXQuhn6l7a2mHP/zDrPGoO+QkseBx3wwzkE2mT0jx+9ZzZiJ4OByFxZM4tq eF7JNNGIEn/xCqzkWhr/nmc4bxJ0B9S2jEfb6IkYGTmMzq7AMDr66k5TbyjvOeebKE7M AkHolaSuRM4MzxM5qLcu77cgrIxaw5B7ZAzwQOo/tCUqr7j2wRgw3Y59z3z9kd/vOufF YKWyr8otqWSXK4ui+ibreyJOt9DckIwbfXv7PyBg/lYDyBsQ6SfO/ubmCEMVPkAkadOE 1ajo5ibYj9gAPIDmf1b7XKI7FQeStZqSaUsUyRXU5Jjf0M2CW0l6A18/nqZN8EwMeMME 2Qcg== X-Gm-Message-State: AOJu0YxaGxJ0GT5PjbrqB7NrmeW2hRJ/6eMSIZcvH3PgOQL4jbIHoSta 9p02/q7Hy9lP4sNGLtGbrNIYGz6TSwQnA/J1GDI= X-Google-Smtp-Source: AGHT+IG8zrJOXiClewdKeoNrNMCN34ckI155S0Xr/u1IfL71l2TBvVQ3WxgVe2LNpqvs6qIORhUZzQ== X-Received: by 2002:a17:907:70b:b0:9c6:724:fa16 with SMTP id xb11-20020a170907070b00b009c60724fa16mr3806927ejb.59.1697918764637; Sat, 21 Oct 2023 13:06:04 -0700 (PDT) Received: from localhost.localdomain (89-104-8-249.customer.bnet.at. [89.104.8.249]) by smtp.gmail.com with ESMTPSA id u2-20020a17090617c200b0098ce63e36e9sm4138253eje.16.2023.10.21.13.06.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Oct 2023 13:06:03 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: dirty@apple.com, roman@roolebo.dev, pbonzini@redhat.com, lists@philjordan.eu, phil@philjordan.eu Subject: [PATCH v2 3/4] hvf: Consistent types for vCPU handles Date: Sat, 21 Oct 2023 22:05:17 +0200 Message-Id: <20231021200518.30125-4-phil@philjordan.eu> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20231021200518.30125-1-phil@philjordan.eu> References: <20231021200518.30125-1-phil@philjordan.eu> MIME-Version: 1.0 Received-SPF: neutral client-ip=2a00:1450:4864:20::52e; envelope-from=phil@philjordan.eu; helo=mail-ed1-x52e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, T_SPF_TEMPERROR=0.01 autolearn=ham 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 Hypervisor.framework uses different types for identifying vCPUs, hv_vcpu_t or hv_vcpuid_t, depending on host architecture. They are not just differently named typedefs for the same primitive type, but reference different-width integers. Instead of using an integer type and casting where necessary, this change introduces a typedef which resolves to the active architecture’s hvf typedef. It also removes a now-unnecessary cast. Signed-off-by: Phil Dennis-Jordan Reviewed-by: Roman Bolshakov Tested-by: Roman Bolshakov --- accel/hvf/hvf-accel-ops.c | 2 +- include/sysemu/hvf_int.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c index abe7adf7ee..165e54ea27 100644 --- a/accel/hvf/hvf-accel-ops.c +++ b/accel/hvf/hvf-accel-ops.c @@ -400,7 +400,7 @@ static int hvf_init_vcpu(CPUState *cpu) r = hv_vcpu_create(&cpu->accel->fd, (hv_vcpu_exit_t **)&cpu->accel->exit, NULL); #else - r = hv_vcpu_create((hv_vcpuid_t *)&cpu->accel->fd, HV_VCPU_DEFAULT); + r = hv_vcpu_create(&cpu->accel->fd, HV_VCPU_DEFAULT); #endif cpu->vcpu_dirty = 1; assert_hvf_ok(r); diff --git a/include/sysemu/hvf_int.h b/include/sysemu/hvf_int.h index 718beddcdd..7980c90825 100644 --- a/include/sysemu/hvf_int.h +++ b/include/sysemu/hvf_int.h @@ -13,8 +13,10 @@ #ifdef __aarch64__ #include +typedef hv_vcpu_t hvf_vcpuid; #else #include +typedef hv_vcpuid_t hvf_vcpuid; #endif /* hvf_slot flags */ @@ -50,7 +52,7 @@ struct HVFState { extern HVFState *hvf_state; struct AccelCPUState { - uint64_t fd; + hvf_vcpuid fd; void *exit; bool vtimer_masked; sigset_t unblock_ipi_mask; From patchwork Sat Oct 21 20:05:18 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: 13431569 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 6B7D1C001E0 for ; Sat, 21 Oct 2023 20:06:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1quIEj-0005OO-A5; Sat, 21 Oct 2023 16:06:17 -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 1quIEi-0005OG-GL for qemu-devel@nongnu.org; Sat, 21 Oct 2023 16:06:16 -0400 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1quIEg-0006xx-9v for qemu-devel@nongnu.org; Sat, 21 Oct 2023 16:06:16 -0400 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-99c1c66876aso294345066b.2 for ; Sat, 21 Oct 2023 13:06:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1697918772; x=1698523572; 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=hCpmOqx1I8jr4bBASa0Og5iNsiQJYZIhwSMQmZBEF4I=; b=TGbvrKUMFTIkP2flW6ue6pzGOdMbLSyy1LGaJ3CCy+l8ounSQ0Ss1FuighrNPVCUkD ymYX57EE/aQSDLmNCGs0Q3bclb2y6MrkWfBKZz+qpPHCxLztsRBsDsybW97eEJscB+81 3veWs0kY9EThTU6cOC0ErX4TgVNDinjNgs8DJZUbtXtgKQPLnmLspv3It4uS8Mgbj/qT e/EvSmycN7NyLWtBV0yOONs8/FJryd7eY+AK2E+jj4/4m21nleBF9DPEGn/fX28fENOp P30/cGx0HDC32eCLz6j5T24JnxqCNOyB5Uquxw/gLx7CBGFXnyNm8LB0RaVr2PikG1DJ vXqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697918772; x=1698523572; 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=hCpmOqx1I8jr4bBASa0Og5iNsiQJYZIhwSMQmZBEF4I=; b=vjlEogq4bbK4PS+ME4iblMA3cSaTt1p2O2W0qvkPIjtXAFMHXpPjAIeeJeHDAt0yNf 6Urv0LkEy2n3TjNf7g0mZY9Px10RmyO5hv9iM/dTycVcqjmokotRtnjq01KY8VOurV/I hoSqWLoFxA6eau8afMVfqvLacIUVE0PrsqKHgNsYyTkXEARKnpBxd9tW8p+ch4ALBZt+ /36iDDAEbJbdi88sqKgF1dWPpYMTczTIw+gaVcve8nq87VMKAaYKF3KrBN79azRTVIOb uayjzppugy4+CgDEjZg6Ha9XCEAaanQDMgELY4m8Y+QU47NquUiPnd+0iBzKRE0GiR23 llgQ== X-Gm-Message-State: AOJu0YwgI4p96pYg59XeJ5Q1+6BSH5GrPIRjuY6Ris1NtbybfY0fBOEz T2CP7nrR7g9QqdfS9tmqC7RG35ixfF7n6SaEevI= X-Google-Smtp-Source: AGHT+IFSNwEYulDujmEdEcRDzLYBflM7SNE9W9U7LJvVROOLyHeQtuevRW7bR1yc25d+aTa4+bGSbA== X-Received: by 2002:a17:907:74a:b0:9be:4bfd:6a6c with SMTP id xc10-20020a170907074a00b009be4bfd6a6cmr3805342ejb.41.1697918772687; Sat, 21 Oct 2023 13:06:12 -0700 (PDT) Received: from localhost.localdomain (89-104-8-249.customer.bnet.at. [89.104.8.249]) by smtp.gmail.com with ESMTPSA id u2-20020a17090617c200b0098ce63e36e9sm4138253eje.16.2023.10.21.13.06.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Oct 2023 13:06:12 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: dirty@apple.com, roman@roolebo.dev, pbonzini@redhat.com, lists@philjordan.eu, phil@philjordan.eu Subject: [PATCH v2 4/4] i386/hvf: Fixes dirty memory tracking by page granularity RX->RWX change Date: Sat, 21 Oct 2023 22:05:18 +0200 Message-Id: <20231021200518.30125-5-phil@philjordan.eu> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20231021200518.30125-1-phil@philjordan.eu> References: <20231021200518.30125-1-phil@philjordan.eu> MIME-Version: 1.0 Received-SPF: neutral client-ip=2a00:1450:4864:20::62b; envelope-from=phil@philjordan.eu; helo=mail-ej1-x62b.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 using x86 macOS Hypervisor.framework as accelerator, detection of dirty memory regions is implemented by marking logged memory region slots as read-only in the EPT, then setting the dirty flag when a guest write causes a fault. The area marked dirty should then be marked writable in order for subsequent writes to succeed without a VM exit. However, dirty bits are tracked on a per-page basis, whereas the fault handler was marking the whole logged memory region as writable. This change fixes the fault handler so only the protection of the single faulting page is marked as dirty. (Note: the dirty page tracking appeared to work despite this error because HVF’s hv_vcpu_run() function generated unnecessary EPT fault exits, which ended up causing the dirty marking handler to run even when the memory region had been marked RW. When using hv_vcpu_run_until(), a change planned for a subsequent commit, these spurious exits no longer occur, so dirty memory tracking malfunctions.) Additionally, the dirty page is set to permit code execution, the same as all other guest memory; changing memory protection from RX to RW not RWX appears to have been an oversight. Signed-off-by: Phil Dennis-Jordan Reviewed-by: Roman Bolshakov Tested-by: Roman Bolshakov --- target/i386/hvf/hvf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index 43d64574ad..a15ee469c3 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -135,9 +135,10 @@ static bool ept_emulation_fault(hvf_slot *slot, uint64_t gpa, uint64_t ept_qual) if (write && slot) { if (slot->flags & HVF_SLOT_LOG) { + uint64_t dirty_page_start = gpa & ~(TARGET_PAGE_SIZE - 1u); memory_region_set_dirty(slot->region, gpa - slot->start, 1); - hv_vm_protect((hv_gpaddr_t)slot->start, (size_t)slot->size, - HV_MEMORY_READ | HV_MEMORY_WRITE); + hv_vm_protect(dirty_page_start, TARGET_PAGE_SIZE, + HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC); } }