aboutsummaryrefslogtreecommitdiff
path: root/target/i386
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2024-01-02 10:35:25 -0500
committerStefan Hajnoczi <stefanha@redhat.com>2024-01-08 10:45:43 -0500
commit195801d700c008b6a8d8acfa299aa5f177446647 (patch)
tree7ab423e4a773b818f6c6d65f2fa06dc4517cad24 /target/i386
parent897a06c6d7ce8fb962a33cea1910d17218c746e9 (diff)
downloadqemu-195801d700c008b6a8d8acfa299aa5f177446647.zip
qemu-195801d700c008b6a8d8acfa299aa5f177446647.tar.gz
qemu-195801d700c008b6a8d8acfa299aa5f177446647.tar.bz2
system/cpus: rename qemu_mutex_lock_iothread() to bql_lock()
The Big QEMU Lock (BQL) has many names and they are confusing. The actual QemuMutex variable is called qemu_global_mutex but it's commonly referred to as the BQL in discussions and some code comments. The locking APIs, however, are called qemu_mutex_lock_iothread() and qemu_mutex_unlock_iothread(). The "iothread" name is historic and comes from when the main thread was split into into KVM vcpu threads and the "iothread" (now called the main loop thread). I have contributed to the confusion myself by introducing a separate --object iothread, a separate concept unrelated to the BQL. The "iothread" name is no longer appropriate for the BQL. Rename the locking APIs to: - void bql_lock(void) - void bql_unlock(void) - bool bql_locked(void) There are more APIs with "iothread" in their names. Subsequent patches will rename them. There are also comments and documentation that will be updated in later patches. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Paul Durrant <paul@xen.org> Acked-by: Fabiano Rosas <farosas@suse.de> Acked-by: David Woodhouse <dwmw@amazon.co.uk> Reviewed-by: Cédric Le Goater <clg@kaod.org> Acked-by: Peter Xu <peterx@redhat.com> Acked-by: Eric Farman <farman@linux.ibm.com> Reviewed-by: Harsh Prateek Bora <harshpb@linux.ibm.com> Acked-by: Hyman Huang <yong.huang@smartx.com> Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> Message-id: 20240102153529.486531-2-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'target/i386')
-rw-r--r--target/i386/hvf/README.md2
-rw-r--r--target/i386/hvf/hvf.c6
-rw-r--r--target/i386/kvm/hyperv.c4
-rw-r--r--target/i386/kvm/kvm.c28
-rw-r--r--target/i386/kvm/xen-emu.c14
-rw-r--r--target/i386/nvmm/nvmm-accel-ops.c4
-rw-r--r--target/i386/nvmm/nvmm-all.c20
-rw-r--r--target/i386/tcg/sysemu/fpu_helper.c6
-rw-r--r--target/i386/tcg/sysemu/misc_helper.c4
-rw-r--r--target/i386/whpx/whpx-accel-ops.c4
-rw-r--r--target/i386/whpx/whpx-all.c24
11 files changed, 58 insertions, 58 deletions
diff --git a/target/i386/hvf/README.md b/target/i386/hvf/README.md
index 2d33477..64a8935 100644
--- a/target/i386/hvf/README.md
+++ b/target/i386/hvf/README.md
@@ -4,4 +4,4 @@ These sources (and ../hvf-all.c) are adapted from Veertu Inc's vdhh (Veertu Desk
1. Adapt to our current QEMU's `CPUState` structure and `address_space_rw` API; many struct members have been moved around (emulated x86 state, xsave_buf) due to historical differences + QEMU needing to handle more emulation targets.
2. Removal of `apic_page` and hyperv-related functionality.
-3. More relaxed use of `qemu_mutex_lock_iothread`.
+3. More relaxed use of `bql_lock`.
diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 20b9ca3..11ffdd4 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -429,9 +429,9 @@ int hvf_vcpu_exec(CPUState *cpu)
}
vmx_update_tpr(cpu);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
if (!cpu_is_bsp(X86_CPU(cpu)) && cpu->halted) {
- qemu_mutex_lock_iothread();
+ bql_lock();
return EXCP_HLT;
}
@@ -450,7 +450,7 @@ int hvf_vcpu_exec(CPUState *cpu)
rip = rreg(cpu->accel->fd, HV_X86_RIP);
env->eflags = rreg(cpu->accel->fd, HV_X86_RFLAGS);
- qemu_mutex_lock_iothread();
+ bql_lock();
update_apic_tpr(cpu);
current_cpu = cpu;
diff --git a/target/i386/kvm/hyperv.c b/target/i386/kvm/hyperv.c
index e3ac978..6825c89 100644
--- a/target/i386/kvm/hyperv.c
+++ b/target/i386/kvm/hyperv.c
@@ -45,9 +45,9 @@ void hyperv_x86_synic_update(X86CPU *cpu)
static void async_synic_update(CPUState *cs, run_on_cpu_data data)
{
- qemu_mutex_lock_iothread();
+ bql_lock();
hyperv_x86_synic_update(X86_CPU(cs));
- qemu_mutex_unlock_iothread();
+ bql_unlock();
}
int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit)
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 4ce8055..76a6624 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -4713,9 +4713,9 @@ void kvm_arch_pre_run(CPUState *cpu, struct kvm_run *run)
/* Inject NMI */
if (cpu->interrupt_request & (CPU_INTERRUPT_NMI | CPU_INTERRUPT_SMI)) {
if (cpu->interrupt_request & CPU_INTERRUPT_NMI) {
- qemu_mutex_lock_iothread();
+ bql_lock();
cpu->interrupt_request &= ~CPU_INTERRUPT_NMI;
- qemu_mutex_unlock_iothread();
+ bql_unlock();
DPRINTF("injected NMI\n");
ret = kvm_vcpu_ioctl(cpu, KVM_NMI);
if (ret < 0) {
@@ -4724,9 +4724,9 @@ void kvm_arch_pre_run(CPUState *cpu, struct kvm_run *run)
}
}
if (cpu->interrupt_request & CPU_INTERRUPT_SMI) {
- qemu_mutex_lock_iothread();
+ bql_lock();
cpu->interrupt_request &= ~CPU_INTERRUPT_SMI;
- qemu_mutex_unlock_iothread();
+ bql_unlock();
DPRINTF("injected SMI\n");
ret = kvm_vcpu_ioctl(cpu, KVM_SMI);
if (ret < 0) {
@@ -4737,7 +4737,7 @@ void kvm_arch_pre_run(CPUState *cpu, struct kvm_run *run)
}
if (!kvm_pic_in_kernel()) {
- qemu_mutex_lock_iothread();
+ bql_lock();
}
/* Force the VCPU out of its inner loop to process any INIT requests
@@ -4790,7 +4790,7 @@ void kvm_arch_pre_run(CPUState *cpu, struct kvm_run *run)
DPRINTF("setting tpr\n");
run->cr8 = cpu_get_apic_tpr(x86_cpu->apic_state);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
}
}
@@ -4838,12 +4838,12 @@ MemTxAttrs kvm_arch_post_run(CPUState *cpu, struct kvm_run *run)
/* We need to protect the apic state against concurrent accesses from
* different threads in case the userspace irqchip is used. */
if (!kvm_irqchip_in_kernel()) {
- qemu_mutex_lock_iothread();
+ bql_lock();
}
cpu_set_apic_tpr(x86_cpu->apic_state, run->cr8);
cpu_set_apic_base(x86_cpu->apic_state, run->apic_base);
if (!kvm_irqchip_in_kernel()) {
- qemu_mutex_unlock_iothread();
+ bql_unlock();
}
return cpu_get_mem_attrs(env);
}
@@ -5277,17 +5277,17 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
switch (run->exit_reason) {
case KVM_EXIT_HLT:
DPRINTF("handle_hlt\n");
- qemu_mutex_lock_iothread();
+ bql_lock();
ret = kvm_handle_halt(cpu);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
break;
case KVM_EXIT_SET_TPR:
ret = 0;
break;
case KVM_EXIT_TPR_ACCESS:
- qemu_mutex_lock_iothread();
+ bql_lock();
ret = kvm_handle_tpr_access(cpu);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
break;
case KVM_EXIT_FAIL_ENTRY:
code = run->fail_entry.hardware_entry_failure_reason;
@@ -5313,9 +5313,9 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
break;
case KVM_EXIT_DEBUG:
DPRINTF("kvm_exit_debug\n");
- qemu_mutex_lock_iothread();
+ bql_lock();
ret = kvm_handle_debug(cpu, &run->debug.arch);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
break;
case KVM_EXIT_HYPERV:
ret = kvm_hv_handle_exit(cpu, &run->hyperv);
diff --git a/target/i386/kvm/xen-emu.c b/target/i386/kvm/xen-emu.c
index c0631f9..b0ed2e6 100644
--- a/target/i386/kvm/xen-emu.c
+++ b/target/i386/kvm/xen-emu.c
@@ -403,7 +403,7 @@ void kvm_xen_maybe_deassert_callback(CPUState *cs)
/* If the evtchn_upcall_pending flag is cleared, turn the GSI off. */
if (!vi->evtchn_upcall_pending) {
- qemu_mutex_lock_iothread();
+ bql_lock();
/*
* Check again now we have the lock, because it may have been
* asserted in the interim. And we don't want to take the lock
@@ -413,7 +413,7 @@ void kvm_xen_maybe_deassert_callback(CPUState *cs)
X86_CPU(cs)->env.xen_callback_asserted = false;
xen_evtchn_set_callback_level(0);
}
- qemu_mutex_unlock_iothread();
+ bql_unlock();
}
}
@@ -773,9 +773,9 @@ static bool handle_set_param(struct kvm_xen_exit *exit, X86CPU *cpu,
switch (hp.index) {
case HVM_PARAM_CALLBACK_IRQ:
- qemu_mutex_lock_iothread();
+ bql_lock();
err = xen_evtchn_set_callback_param(hp.value);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
xen_set_long_mode(exit->u.hcall.longmode);
break;
default:
@@ -1408,7 +1408,7 @@ int kvm_xen_soft_reset(void)
CPUState *cpu;
int err;
- assert(qemu_mutex_iothread_locked());
+ assert(bql_locked());
trace_kvm_xen_soft_reset();
@@ -1481,9 +1481,9 @@ static int schedop_shutdown(CPUState *cs, uint64_t arg)
break;
case SHUTDOWN_soft_reset:
- qemu_mutex_lock_iothread();
+ bql_lock();
ret = kvm_xen_soft_reset();
- qemu_mutex_unlock_iothread();
+ bql_unlock();
break;
default:
diff --git a/target/i386/nvmm/nvmm-accel-ops.c b/target/i386/nvmm/nvmm-accel-ops.c
index 6c46101..f9d5e9a 100644
--- a/target/i386/nvmm/nvmm-accel-ops.c
+++ b/target/i386/nvmm/nvmm-accel-ops.c
@@ -25,7 +25,7 @@ static void *qemu_nvmm_cpu_thread_fn(void *arg)
rcu_register_thread();
- qemu_mutex_lock_iothread();
+ bql_lock();
qemu_thread_get_self(cpu->thread);
cpu->thread_id = qemu_get_thread_id();
current_cpu = cpu;
@@ -55,7 +55,7 @@ static void *qemu_nvmm_cpu_thread_fn(void *arg)
nvmm_destroy_vcpu(cpu);
cpu_thread_signal_destroyed(cpu);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
rcu_unregister_thread();
return NULL;
}
diff --git a/target/i386/nvmm/nvmm-all.c b/target/i386/nvmm/nvmm-all.c
index 7d752bc..cfdca91 100644
--- a/target/i386/nvmm/nvmm-all.c
+++ b/target/i386/nvmm/nvmm-all.c
@@ -399,7 +399,7 @@ nvmm_vcpu_pre_run(CPUState *cpu)
uint8_t tpr;
int ret;
- qemu_mutex_lock_iothread();
+ bql_lock();
tpr = cpu_get_apic_tpr(x86_cpu->apic_state);
if (tpr != qcpu->tpr) {
@@ -462,7 +462,7 @@ nvmm_vcpu_pre_run(CPUState *cpu)
}
}
- qemu_mutex_unlock_iothread();
+ bql_unlock();
}
/*
@@ -485,9 +485,9 @@ nvmm_vcpu_post_run(CPUState *cpu, struct nvmm_vcpu_exit *exit)
tpr = exit->exitstate.cr8;
if (qcpu->tpr != tpr) {
qcpu->tpr = tpr;
- qemu_mutex_lock_iothread();
+ bql_lock();
cpu_set_apic_tpr(x86_cpu->apic_state, qcpu->tpr);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
}
}
@@ -648,7 +648,7 @@ nvmm_handle_halted(struct nvmm_machine *mach, CPUState *cpu,
CPUX86State *env = cpu_env(cpu);
int ret = 0;
- qemu_mutex_lock_iothread();
+ bql_lock();
if (!((cpu->interrupt_request & CPU_INTERRUPT_HARD) &&
(env->eflags & IF_MASK)) &&
@@ -658,7 +658,7 @@ nvmm_handle_halted(struct nvmm_machine *mach, CPUState *cpu,
ret = 1;
}
- qemu_mutex_unlock_iothread();
+ bql_unlock();
return ret;
}
@@ -721,7 +721,7 @@ nvmm_vcpu_loop(CPUState *cpu)
return 0;
}
- qemu_mutex_unlock_iothread();
+ bql_unlock();
cpu_exec_start(cpu);
/*
@@ -806,16 +806,16 @@ nvmm_vcpu_loop(CPUState *cpu)
error_report("NVMM: Unexpected VM exit code 0x%lx [hw=0x%lx]",
exit->reason, exit->u.inv.hwcode);
nvmm_get_registers(cpu);
- qemu_mutex_lock_iothread();
+ bql_lock();
qemu_system_guest_panicked(cpu_get_crash_info(cpu));
- qemu_mutex_unlock_iothread();
+ bql_unlock();
ret = -1;
break;
}
} while (ret == 0);
cpu_exec_end(cpu);
- qemu_mutex_lock_iothread();
+ bql_lock();
qatomic_set(&cpu->exit_request, false);
diff --git a/target/i386/tcg/sysemu/fpu_helper.c b/target/i386/tcg/sysemu/fpu_helper.c
index 93506cd..e0305ba 100644
--- a/target/i386/tcg/sysemu/fpu_helper.c
+++ b/target/i386/tcg/sysemu/fpu_helper.c
@@ -32,9 +32,9 @@ void x86_register_ferr_irq(qemu_irq irq)
void fpu_check_raise_ferr_irq(CPUX86State *env)
{
if (ferr_irq && !(env->hflags2 & HF2_IGNNE_MASK)) {
- qemu_mutex_lock_iothread();
+ bql_lock();
qemu_irq_raise(ferr_irq);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
return;
}
}
@@ -49,7 +49,7 @@ void cpu_set_ignne(void)
{
CPUX86State *env = &X86_CPU(first_cpu)->env;
- assert(qemu_mutex_iothread_locked());
+ assert(bql_locked());
env->hflags2 |= HF2_IGNNE_MASK;
/*
diff --git a/target/i386/tcg/sysemu/misc_helper.c b/target/i386/tcg/sysemu/misc_helper.c
index e1528b7..1ddfc9f 100644
--- a/target/i386/tcg/sysemu/misc_helper.c
+++ b/target/i386/tcg/sysemu/misc_helper.c
@@ -118,9 +118,9 @@ void helper_write_crN(CPUX86State *env, int reg, target_ulong t0)
break;
case 8:
if (!(env->hflags2 & HF2_VINTR_MASK)) {
- qemu_mutex_lock_iothread();
+ bql_lock();
cpu_set_apic_tpr(env_archcpu(env)->apic_state, t0);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
}
env->int_ctl = (env->int_ctl & ~V_TPR_MASK) | (t0 & V_TPR_MASK);
diff --git a/target/i386/whpx/whpx-accel-ops.c b/target/i386/whpx/whpx-accel-ops.c
index 67cad86..e783a76 100644
--- a/target/i386/whpx/whpx-accel-ops.c
+++ b/target/i386/whpx/whpx-accel-ops.c
@@ -25,7 +25,7 @@ static void *whpx_cpu_thread_fn(void *arg)
rcu_register_thread();
- qemu_mutex_lock_iothread();
+ bql_lock();
qemu_thread_get_self(cpu->thread);
cpu->thread_id = qemu_get_thread_id();
current_cpu = cpu;
@@ -55,7 +55,7 @@ static void *whpx_cpu_thread_fn(void *arg)
whpx_destroy_vcpu(cpu);
cpu_thread_signal_destroyed(cpu);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
rcu_unregister_thread();
return NULL;
}
diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c
index d29ba91..a726265 100644
--- a/target/i386/whpx/whpx-all.c
+++ b/target/i386/whpx/whpx-all.c
@@ -1324,7 +1324,7 @@ static int whpx_first_vcpu_starting(CPUState *cpu)
struct whpx_state *whpx = &whpx_global;
HRESULT hr;
- g_assert(qemu_mutex_iothread_locked());
+ g_assert(bql_locked());
if (!QTAILQ_EMPTY(&cpu->breakpoints) ||
(whpx->breakpoints.breakpoints &&
@@ -1442,7 +1442,7 @@ static int whpx_handle_halt(CPUState *cpu)
CPUX86State *env = cpu_env(cpu);
int ret = 0;
- qemu_mutex_lock_iothread();
+ bql_lock();
if (!((cpu->interrupt_request & CPU_INTERRUPT_HARD) &&
(env->eflags & IF_MASK)) &&
!(cpu->interrupt_request & CPU_INTERRUPT_NMI)) {
@@ -1450,7 +1450,7 @@ static int whpx_handle_halt(CPUState *cpu)
cpu->halted = true;
ret = 1;
}
- qemu_mutex_unlock_iothread();
+ bql_unlock();
return ret;
}
@@ -1472,7 +1472,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu)
memset(&new_int, 0, sizeof(new_int));
memset(reg_values, 0, sizeof(reg_values));
- qemu_mutex_lock_iothread();
+ bql_lock();
/* Inject NMI */
if (!vcpu->interruption_pending &&
@@ -1563,7 +1563,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu)
reg_count += 1;
}
- qemu_mutex_unlock_iothread();
+ bql_unlock();
vcpu->ready_for_pic_interrupt = false;
if (reg_count) {
@@ -1590,9 +1590,9 @@ static void whpx_vcpu_post_run(CPUState *cpu)
uint64_t tpr = vcpu->exit_ctx.VpContext.Cr8;
if (vcpu->tpr != tpr) {
vcpu->tpr = tpr;
- qemu_mutex_lock_iothread();
+ bql_lock();
cpu_set_apic_tpr(x86_cpu->apic_state, whpx_cr8_to_apic_tpr(vcpu->tpr));
- qemu_mutex_unlock_iothread();
+ bql_unlock();
}
vcpu->interruption_pending =
@@ -1652,7 +1652,7 @@ static int whpx_vcpu_run(CPUState *cpu)
WhpxStepMode exclusive_step_mode = WHPX_STEP_NONE;
int ret;
- g_assert(qemu_mutex_iothread_locked());
+ g_assert(bql_locked());
if (whpx->running_cpus++ == 0) {
/* Insert breakpoints into memory, update exception exit bitmap. */
@@ -1690,7 +1690,7 @@ static int whpx_vcpu_run(CPUState *cpu)
}
}
- qemu_mutex_unlock_iothread();
+ bql_unlock();
if (exclusive_step_mode != WHPX_STEP_NONE) {
start_exclusive();
@@ -2028,9 +2028,9 @@ static int whpx_vcpu_run(CPUState *cpu)
error_report("WHPX: Unexpected VP exit code %d",
vcpu->exit_ctx.ExitReason);
whpx_get_registers(cpu);
- qemu_mutex_lock_iothread();
+ bql_lock();
qemu_system_guest_panicked(cpu_get_crash_info(cpu));
- qemu_mutex_unlock_iothread();
+ bql_unlock();
break;
}
@@ -2055,7 +2055,7 @@ static int whpx_vcpu_run(CPUState *cpu)
cpu_exec_end(cpu);
}
- qemu_mutex_lock_iothread();
+ bql_lock();
current_cpu = cpu;
if (--whpx->running_cpus == 0) {