From nobody Sun Nov 24 22:27:41 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1719222463; cv=none; d=zohomail.com; s=zohoarc; b=U61RdoWE6WpxKVyffizlzgHJmlGA4tmok8HPQ9c5va1ANM2fWG2PCriL1RIfNIWGHfD8k9iUEXclK9+1pTgEd6gORlgQsNuJm6SlDgYJaQh4I9OhGgzTwjVbL0DdPotP5AImR4E6PKIsxVaOReeL2H92qh8a9H9iFX1Em0TD1Sk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719222463; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vm1+u9RMLtAJgeoBM6Efk666xOoNwf4tI75owi8IaIk=; b=fTu7IzyOazJL30TB+nZzWWK/6sXUL+lXxJ9/ELxlLp0YiJG/9je39ekF5N/IMVU7oRVZG6NKWJXNzySijC7NkdWblE8DjiyQNbCD7hWTkX9FNlc2r/DzBZMMxV6BXZPUK8Hi7n/RvKNOvgiMrF081cmlUqbWDU9qHToLGsw7u6Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 171922246315070.117498766209; Mon, 24 Jun 2024 02:47:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLgIB-0005vL-IA; Mon, 24 Jun 2024 05:47:19 -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 1sLgI9-0005vB-Bc for qemu-devel@nongnu.org; Mon, 24 Jun 2024 05:47:17 -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 1sLgI7-0001tU-3G for qemu-devel@nongnu.org; Mon, 24 Jun 2024 05:47:17 -0400 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-57d203d4682so4838807a12.0 for ; Mon, 24 Jun 2024 02:47:14 -0700 (PDT) Received: from localhost.localdomain (89-104-8-17.customer.bnet.at. [89.104.8.17]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57d30534e35sm4464712a12.62.2024.06.24.02.47.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 02:47:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1719222433; x=1719827233; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=vm1+u9RMLtAJgeoBM6Efk666xOoNwf4tI75owi8IaIk=; b=YEtQGQ4xeuR5oHpLvmlsEj99IgAAfaP2WZ9m+f59HwbHXVk/Q0n3aRJpWZYejXEaDL 2butHQo9IJP+cpzQS5ILCkJAynNRhFoeBZT8SN27DQwS2qwJovd8Jv0oJ2MJLLAVjKnd R/VEmw21ojErlltt5nDhsKYLMILTK2SXG6gck4xbE7gaRTVGxDN+RDxv7qrDJQOnMdab r2ikpoF6AitzovoU2jya56CAqPgtpZ0FWYPQ1PHyq6nCuJKIZgF+vNH0pA5To8zX7mLh 2xUJj+2rvkubtT+0ZPcZD54Uw6EE0dYvJBjbqh0s4nSQUhgJRbSG3Ebp2uYZmuMH01YE 8Spw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719222433; x=1719827233; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vm1+u9RMLtAJgeoBM6Efk666xOoNwf4tI75owi8IaIk=; b=PzAF2a0utryyJ4jexQ55/1LsDrdCxI0/OxLT689kygIUpIMNdY8wO+dbDrLP598Fpv souyj5W8Fzz7DSZFtjNvs+FHd8b3O/ZL8vk5Bw6Lun3X+SkAp1IkH8Q7au2H7kDMhidw Ol1eOh0i75XYNTAt5WYxppU3A3Od3RB9HAplY2PFJUb2eqvhkly6EnouTBGoxn1Q7C3O B6IOuNQo2raLqMsJnzOg4RMOLs7MayDQK0xeD02qhPokmkFSXvG3Eh6v/c/judF6bd0l 67+QYcMXMNnDp+Lvc9v1+qxUN52nQyoiyi353t+wxMxtqa9avsj8OzJS0Hx4sGixFGwo +VNw== X-Gm-Message-State: AOJu0YwFQC4eHHMUHLwvgdJ8fy5t10AGJFd2RNFVQMcZRIczSYg5EhIR 1z0Wx5butHwFoHQgtX4AQt3l08MG9GqWXtxXOJlMpRzbIR/v/4ejotlm1g72jFZxRSnuQgDOuqN ylg== X-Google-Smtp-Source: AGHT+IEbDYLCDbnoYpYflpY8CKgNvuyj2GSykkwADn6OojuvV7soONOZrCGQUj2qon0C47Gnlynz4w== X-Received: by 2002:a50:d50c:0:b0:578:676e:324 with SMTP id 4fb4d7f45d1cf-57d45791fc4mr2910621a12.17.1719222432898; Mon, 24 Jun 2024 02:47:12 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: dirty@apple.com, rbolshakov@ddn.com, lists@philjordan.eu, minhquangbui99@gmail.com, Phil Dennis-Jordan Subject: [PATCH] i386/hvf: Integrates x2APIC support with hvf accel Date: Mon, 24 Jun 2024 11:46:47 +0200 Message-Id: <20240624094647.77156-1-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1719222465217100003 Support for x2APIC mode was recently introduced in the software emulated APIC implementation for TCG. Enabling it when using macOS=E2=80=99s hvf accelerator is useful and significantly helps performance, as Qemu currently uses the emulated APIC when running on hvf as well. This change wires up the read & write operations for the MSR VM exits and allow-lists the CPUID flag in the x86 hvf runtime. Signed-off-by: Phil Dennis-Jordan Acked-by: Bui Quang Minh --- target/i386/hvf/x86_cpuid.c | 4 ++-- target/i386/hvf/x86_emu.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/target/i386/hvf/x86_cpuid.c b/target/i386/hvf/x86_cpuid.c index e56cd8411b..4f260d46a8 100644 --- a/target/i386/hvf/x86_cpuid.c +++ b/target/i386/hvf/x86_cpuid.c @@ -64,8 +64,8 @@ uint32_t hvf_get_supported_cpuid(uint32_t func, uint32_t = idx, CPUID_PAT | CPUID_PSE36 | CPUID_CLFLUSH | CPUID_MMX | CPUID_FXSR | CPUID_SSE | CPUID_SSE2 | CPUID_SS; ecx &=3D CPUID_EXT_SSE3 | CPUID_EXT_PCLMULQDQ | CPUID_EXT_SSSE3 | - CPUID_EXT_FMA | CPUID_EXT_CX16 | CPUID_EXT_PCID | - CPUID_EXT_SSE41 | CPUID_EXT_SSE42 | CPUID_EXT_MOVBE | + CPUID_EXT_FMA | CPUID_EXT_CX16 | CPUID_EXT_PCID | CPUID_EXT_S= SE41 | + CPUID_EXT_SSE42 | CPUID_EXT_X2APIC | CPUID_EXT_MOVBE | CPUID_EXT_POPCNT | CPUID_EXT_AES | CPUID_EXT_XSAVE | CPUID_EXT_AVX | CPUID_EXT_F16C | CPUID_EXT_RDRAND; ecx |=3D CPUID_EXT_HYPERVISOR; diff --git a/target/i386/hvf/x86_emu.c b/target/i386/hvf/x86_emu.c index 38c782b8e3..be675bcfb7 100644 --- a/target/i386/hvf/x86_emu.c +++ b/target/i386/hvf/x86_emu.c @@ -663,6 +663,15 @@ static void exec_lods(CPUX86State *env, struct x86_dec= ode *decode) env->eip +=3D decode->len; } =20 +static void raise_exception(CPUX86State *env, int exception_index, + int error_code) +{ + env->exception_nr =3D exception_index; + env->error_code =3D error_code; + env->has_error_code =3D true; + env->exception_injected =3D 1; +} + void simulate_rdmsr(CPUX86State *env) { X86CPU *cpu =3D env_archcpu(env); @@ -677,6 +686,17 @@ void simulate_rdmsr(CPUX86State *env) case MSR_IA32_APICBASE: val =3D cpu_get_apic_base(cpu->apic_state); break; + case MSR_APIC_START ... MSR_APIC_END: { + int ret; + int index =3D (uint32_t)env->regs[R_ECX] - MSR_APIC_START; + + ret =3D apic_msr_read(index, &val); + if (ret < 0) { + raise_exception(env, EXCP0D_GPF, 0); + } + + break; + } case MSR_IA32_UCODE_REV: val =3D cpu->ucode_rev; break; @@ -777,6 +797,17 @@ void simulate_wrmsr(CPUX86State *env) case MSR_IA32_APICBASE: cpu_set_apic_base(cpu->apic_state, data); break; + case MSR_APIC_START ... MSR_APIC_END: { + int ret; + int index =3D (uint32_t)env->regs[R_ECX] - MSR_APIC_START; + + ret =3D apic_msr_write(index, data); + if (ret < 0) { + raise_exception(env, EXCP0D_GPF, 0); + } + + break; + } case MSR_FSBASE: wvmcs(cs->accel->fd, VMCS_GUEST_FS_BASE, data); break; --=20 2.39.3 (Apple Git-146)