From: Phil Dennis-Jordan <phil@philjordan.eu>
To: qemu-devel@nongnu.org
Cc: dirty@apple.com, rbolshakov@ddn.com, pbonzini@redhat.com,
Phil Dennis-Jordan <phil@philjordan.eu>
Subject: [PATCH 1/5] i386/hvf: Integrates x2APIC support with hvf accel
Date: Tue, 5 Nov 2024 16:57:56 +0100 [thread overview]
Message-ID: <20241105155800.5461-2-phil@philjordan.eu> (raw)
In-Reply-To: <20241105155800.5461-1-phil@philjordan.eu>
Support for x2APIC mode was recently introduced in the software emulated
APIC implementation for TCG. Enabling it when using macOS’s 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 <phil@philjordan.eu>
---
v2:
* Fixed merge conflict due to recent upstream CPUID code change.
target/i386/hvf/x86_cpuid.c | 2 +-
target/i386/hvf/x86_emu.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/target/i386/hvf/x86_cpuid.c b/target/i386/hvf/x86_cpuid.c
index 3a116548a3d..ac922d7fd16 100644
--- a/target/i386/hvf/x86_cpuid.c
+++ b/target/i386/hvf/x86_cpuid.c
@@ -77,7 +77,7 @@ uint32_t hvf_get_supported_cpuid(uint32_t func, uint32_t idx,
ecx &= 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_POPCNT | CPUID_EXT_AES |
+ CPUID_EXT_POPCNT | CPUID_EXT_AES | CPUID_EXT_X2APIC |
(supported_xcr0 ? CPUID_EXT_XSAVE : 0) |
CPUID_EXT_AVX | CPUID_EXT_F16C | CPUID_EXT_RDRAND;
ecx |= CPUID_EXT_HYPERVISOR;
diff --git a/target/i386/hvf/x86_emu.c b/target/i386/hvf/x86_emu.c
index 38c782b8e3b..be675bcfb71 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_decode *decode)
env->eip += decode->len;
}
+static void raise_exception(CPUX86State *env, int exception_index,
+ int error_code)
+{
+ env->exception_nr = exception_index;
+ env->error_code = error_code;
+ env->has_error_code = true;
+ env->exception_injected = 1;
+}
+
void simulate_rdmsr(CPUX86State *env)
{
X86CPU *cpu = env_archcpu(env);
@@ -677,6 +686,17 @@ void simulate_rdmsr(CPUX86State *env)
case MSR_IA32_APICBASE:
val = cpu_get_apic_base(cpu->apic_state);
break;
+ case MSR_APIC_START ... MSR_APIC_END: {
+ int ret;
+ int index = (uint32_t)env->regs[R_ECX] - MSR_APIC_START;
+
+ ret = apic_msr_read(index, &val);
+ if (ret < 0) {
+ raise_exception(env, EXCP0D_GPF, 0);
+ }
+
+ break;
+ }
case MSR_IA32_UCODE_REV:
val = 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 = (uint32_t)env->regs[R_ECX] - MSR_APIC_START;
+
+ ret = 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;
--
2.39.3 (Apple Git-145)
next prev parent reply other threads:[~2024-11-05 16:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-05 15:57 [PATCH 0/5] i386/hvf: x2apic support and some small fixes Phil Dennis-Jordan
2024-11-05 15:57 ` Phil Dennis-Jordan [this message]
2024-11-06 10:44 ` [PATCH 1/5] i386/hvf: Integrates x2APIC support with hvf accel Roman Bolshakov
2024-11-05 15:57 ` [PATCH 2/5] i386/hvf: Fix for UB in handling CPUID function 0xD Phil Dennis-Jordan
2024-11-06 14:01 ` Roman Bolshakov
2024-11-05 15:57 ` [PATCH 3/5] i386/hvf: Fixes startup memory leak (vmcs caps) Phil Dennis-Jordan
2024-11-06 14:03 ` Roman Bolshakov
2024-11-05 15:57 ` [PATCH 4/5] i386/hvf: Raise exception on error setting APICBASE Phil Dennis-Jordan
2024-11-06 14:04 ` Roman Bolshakov
2024-11-05 15:58 ` [PATCH 5/5] i386/hvf: Removes duplicate/shadowed variables in hvf_vcpu_exec Phil Dennis-Jordan
2024-11-06 14:05 ` Roman Bolshakov
2024-11-06 15:26 ` [PATCH 0/5] i386/hvf: x2apic support and some small fixes Roman Bolshakov
2024-11-06 18:45 ` Phil Dennis-Jordan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241105155800.5461-2-phil@philjordan.eu \
--to=phil@philjordan.eu \
--cc=dirty@apple.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rbolshakov@ddn.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).