From: Bernhard Beschow <shentey@gmail.com>
To: qemu-devel@nongnu.org
Cc: Roman Bolshakov <rbolshakov@ddn.com>,
Laurent Vivier <laurent@vivier.eu>,
Eduardo Habkost <eduardo@habkost.net>,
Cameron Esfahani <dirty@apple.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Sunil Muthuswamy <sunilmut@microsoft.com>,
Zhao Liu <zhao1.liu@intel.com>,
Richard Henderson <richard.henderson@linaro.org>,
Fabiano Rosas <farosas@suse.de>,
qemu-trivial@nongnu.org, Gerd Hoffmann <kraxel@redhat.com>,
qemu-block@nongnu.org, Phil Dennis-Jordan <phil@philjordan.eu>,
Michael Tokarev <mjt@tls.msk.ru>, John Snow <jsnow@redhat.com>,
kvm@vger.kernel.org, Laurent Vivier <lvivier@redhat.com>,
Bernhard Beschow <shentey@gmail.com>
Subject: [PATCH v2 08/11] hw/i386/apic: Ensure own APIC use in apic_msr_{read,write}
Date: Fri, 17 Oct 2025 16:11:14 +0200 [thread overview]
Message-ID: <20251017141117.105944-9-shentey@gmail.com> (raw)
In-Reply-To: <20251017141117.105944-1-shentey@gmail.com>
Avoids the `current_cpu` global and seems more robust by not "forgetting" the
own APIC and then re-determining it by cpu_get_current_apic() which uses the
global.
Signed-off-by: Bernhard Beschow <shentey@gmail.com>
---
include/hw/i386/apic.h | 4 ++--
hw/intc/apic.c | 10 ++--------
target/i386/hvf/hvf.c | 4 ++--
target/i386/tcg/system/misc_helper.c | 5 +++--
4 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/include/hw/i386/apic.h b/include/hw/i386/apic.h
index 871f142888..6a0933f401 100644
--- a/include/hw/i386/apic.h
+++ b/include/hw/i386/apic.h
@@ -19,8 +19,8 @@ void apic_sipi(APICCommonState *s);
void apic_poll_irq(APICCommonState *s);
void apic_designate_bsp(APICCommonState *s, bool bsp);
int apic_get_highest_priority_irr(APICCommonState *s);
-int apic_msr_read(int index, uint64_t *val);
-int apic_msr_write(int index, uint64_t val);
+int apic_msr_read(APICCommonState *s, int index, uint64_t *val);
+int apic_msr_write(APICCommonState *s, int index, uint64_t val);
bool is_x2apic_mode(APICCommonState *s);
/* pc.c */
diff --git a/hw/intc/apic.c b/hw/intc/apic.c
index cb35c80c75..ba0eda3921 100644
--- a/hw/intc/apic.c
+++ b/hw/intc/apic.c
@@ -881,11 +881,8 @@ static uint64_t apic_mem_read(void *opaque, hwaddr addr, unsigned size)
return val;
}
-int apic_msr_read(int index, uint64_t *val)
+int apic_msr_read(APICCommonState *s, int index, uint64_t *val)
{
- APICCommonState *s;
-
- s = cpu_get_current_apic();
if (!s) {
return -1;
}
@@ -1079,11 +1076,8 @@ static void apic_mem_write(void *opaque, hwaddr addr, uint64_t val,
apic_register_write(index, val);
}
-int apic_msr_write(int index, uint64_t val)
+int apic_msr_write(APICCommonState *s, int index, uint64_t val)
{
- APICCommonState *s;
-
- s = cpu_get_current_apic();
if (!s) {
return -1;
}
diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 8445cadece..33f723a76a 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -527,7 +527,7 @@ void hvf_simulate_rdmsr(CPUState *cs)
int ret;
int index = (uint32_t)env->regs[R_ECX] - MSR_APIC_START;
- ret = apic_msr_read(index, &val);
+ ret = apic_msr_read(cpu->apic_state, index, &val);
if (ret < 0) {
x86_emul_raise_exception(env, EXCP0D_GPF, 0);
}
@@ -638,7 +638,7 @@ void hvf_simulate_wrmsr(CPUState *cs)
int ret;
int index = (uint32_t)env->regs[R_ECX] - MSR_APIC_START;
- ret = apic_msr_write(index, data);
+ ret = apic_msr_write(cpu->apic_state, index, data);
if (ret < 0) {
x86_emul_raise_exception(env, EXCP0D_GPF, 0);
}
diff --git a/target/i386/tcg/system/misc_helper.c b/target/i386/tcg/system/misc_helper.c
index 9c3f5cc99b..360e0e71f0 100644
--- a/target/i386/tcg/system/misc_helper.c
+++ b/target/i386/tcg/system/misc_helper.c
@@ -132,6 +132,7 @@ void helper_write_crN(CPUX86State *env, int reg, target_ulong t0)
void helper_wrmsr(CPUX86State *env)
{
uint64_t val;
+ X86CPU *x86_cpu = env_archcpu(env);
CPUState *cs = env_cpu(env);
cpu_svm_check_intercept_param(env, SVM_EXIT_MSR, 1, GETPC());
@@ -299,7 +300,7 @@ void helper_wrmsr(CPUX86State *env)
int index = (uint32_t)env->regs[R_ECX] - MSR_APIC_START;
bql_lock();
- ret = apic_msr_write(index, val);
+ ret = apic_msr_write(x86_cpu->apic_state, index, val);
bql_unlock();
if (ret < 0) {
goto error;
@@ -477,7 +478,7 @@ void helper_rdmsr(CPUX86State *env)
int index = (uint32_t)env->regs[R_ECX] - MSR_APIC_START;
bql_lock();
- ret = apic_msr_read(index, &val);
+ ret = apic_msr_read(x86_cpu->apic_state, index, &val);
bql_unlock();
if (ret < 0) {
raise_exception_err_ra(env, EXCP0D_GPF, 0, GETPC());
--
2.51.1.dirty
next prev parent reply other threads:[~2025-10-17 14:12 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-17 14:11 [PATCH v2 00/11] Cleanup patches, mostly PC-related Bernhard Beschow
2025-10-17 14:11 ` [PATCH v2 01/11] hw/timer/i8254: Add I/O trace events Bernhard Beschow
2025-10-17 14:11 ` [PATCH v2 02/11] hw/audio/pcspk: " Bernhard Beschow
2025-10-17 14:11 ` [PATCH v2 03/11] hw/rtc/mc146818rtc: Convert CMOS_DPRINTF() into " Bernhard Beschow
2025-10-17 14:11 ` [PATCH v2 04/11] hw/rtc/mc146818rtc: Use ARRAY_SIZE macro Bernhard Beschow
2025-10-17 14:11 ` [PATCH v2 05/11] hw/rtc/mc146818rtc: Assert correct usage of mc146818rtc_set_cmos_data() Bernhard Beschow
2025-10-17 14:11 ` [PATCH v2 06/11] hw/ide/ide-internal: Move dma_buf_commit() into ide "namespace" Bernhard Beschow
2025-10-17 14:11 ` [PATCH v2 07/11] hw/i386/apic: Prefer APICCommonState over DeviceState Bernhard Beschow
2025-10-17 14:11 ` Bernhard Beschow [this message]
2025-10-17 14:11 ` [PATCH v2 09/11] hw/intc/apic: Ensure own APIC use in apic_register_{read,write} Bernhard Beschow
2025-10-17 14:58 ` [PATCH v2 09/11] hw/intc/apic: Ensure own APIC use in apic_register_{read, write} Michael Tokarev
2025-10-17 19:34 ` Bernhard Beschow
2025-10-19 22:38 ` Bernhard Beschow
2025-10-17 14:11 ` [PATCH v2 10/11] hw/i386/x86-cpu: Remove now unused cpu_get_current_apic() Bernhard Beschow
2025-10-17 14:11 ` [PATCH v2 11/11] tests/qtest/ds1338-test: Reuse from_bcd() Bernhard Beschow
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=20251017141117.105944-9-shentey@gmail.com \
--to=shentey@gmail.com \
--cc=dirty@apple.com \
--cc=eduardo@habkost.net \
--cc=farosas@suse.de \
--cc=jsnow@redhat.com \
--cc=kraxel@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=laurent@vivier.eu \
--cc=lvivier@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mjt@tls.msk.ru \
--cc=mst@redhat.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=phil@philjordan.eu \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=rbolshakov@ddn.com \
--cc=richard.henderson@linaro.org \
--cc=sunilmut@microsoft.com \
--cc=zhao1.liu@intel.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