eb1e9ff8bb
There is such error info when running linux kernel: tcg_handle_interrupt: assertion failed: (qemu_mutex_iothread_locked()). calling stack: #0 in raise () at /lib64/libc.so.6 #1 in abort () at /lib64/libc.so.6 #2 in g_assertion_message_expr.cold () at /lib64/libglib-2.0.so.0 #3 in g_assertion_message_expr () at /lib64/libglib-2.0.so.0 #4 in tcg_handle_interrupt (cpu=0x632000030800, mask=2) at ../accel/tcg/tcg-accel-ops.c:79 #5 in cpu_interrupt (cpu=0x632000030800, mask=2) at ../softmmu/cpus.c:248 #6 in loongarch_cpu_set_irq (opaque=0x632000030800, irq=11, level=0) at ../target/loongarch/cpu.c:100 #7 in helper_csrwr_ticlr (env=0x632000039440, val=1) at ../target/loongarch/csr_helper.c:85 #8 in code_gen_buffer () #9 in cpu_tb_exec (cpu=0x632000030800, itb=0x7fff946ac280, tb_exit=0x7ffe4fcb6c30) at ../accel/tcg/cpu-exec.c:358 Add mutex iothread lock around loongarch_cpu_set_irq in csrwr_ticlr() to fix the bug. Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20220701093407.2150607-10-yangxiaojuan@loongson.cn> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
90 lines
1.9 KiB
C
90 lines
1.9 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* LoongArch emulation helpers for CSRs
|
|
*
|
|
* Copyright (c) 2021 Loongson Technology Corporation Limited
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "qemu/main-loop.h"
|
|
#include "cpu.h"
|
|
#include "internals.h"
|
|
#include "qemu/host-utils.h"
|
|
#include "exec/helper-proto.h"
|
|
#include "exec/exec-all.h"
|
|
#include "exec/cpu_ldst.h"
|
|
#include "hw/irq.h"
|
|
#include "cpu-csr.h"
|
|
#include "tcg/tcg-ldst.h"
|
|
|
|
target_ulong helper_csrrd_pgd(CPULoongArchState *env)
|
|
{
|
|
int64_t v;
|
|
|
|
if (env->CSR_TLBRERA & 0x1) {
|
|
v = env->CSR_TLBRBADV;
|
|
} else {
|
|
v = env->CSR_BADV;
|
|
}
|
|
|
|
if ((v >> 63) & 0x1) {
|
|
v = env->CSR_PGDH;
|
|
} else {
|
|
v = env->CSR_PGDL;
|
|
}
|
|
|
|
return v;
|
|
}
|
|
|
|
target_ulong helper_csrrd_tval(CPULoongArchState *env)
|
|
{
|
|
LoongArchCPU *cpu = env_archcpu(env);
|
|
|
|
return cpu_loongarch_get_constant_timer_ticks(cpu);
|
|
}
|
|
|
|
target_ulong helper_csrwr_estat(CPULoongArchState *env, target_ulong val)
|
|
{
|
|
int64_t old_v = env->CSR_ESTAT;
|
|
|
|
/* Only IS[1:0] can be written */
|
|
env->CSR_ESTAT = deposit64(env->CSR_ESTAT, 0, 2, val);
|
|
|
|
return old_v;
|
|
}
|
|
|
|
target_ulong helper_csrwr_asid(CPULoongArchState *env, target_ulong val)
|
|
{
|
|
int64_t old_v = env->CSR_ASID;
|
|
|
|
/* Only ASID filed of CSR_ASID can be written */
|
|
env->CSR_ASID = deposit64(env->CSR_ASID, 0, 10, val);
|
|
if (old_v != env->CSR_ASID) {
|
|
tlb_flush(env_cpu(env));
|
|
}
|
|
return old_v;
|
|
}
|
|
|
|
target_ulong helper_csrwr_tcfg(CPULoongArchState *env, target_ulong val)
|
|
{
|
|
LoongArchCPU *cpu = env_archcpu(env);
|
|
int64_t old_v = env->CSR_TCFG;
|
|
|
|
cpu_loongarch_store_constant_timer_config(cpu, val);
|
|
|
|
return old_v;
|
|
}
|
|
|
|
target_ulong helper_csrwr_ticlr(CPULoongArchState *env, target_ulong val)
|
|
{
|
|
LoongArchCPU *cpu = env_archcpu(env);
|
|
int64_t old_v = 0;
|
|
|
|
if (val & 0x1) {
|
|
qemu_mutex_lock_iothread();
|
|
loongarch_cpu_set_irq(cpu, IRQ_TIMER, 0);
|
|
qemu_mutex_unlock_iothread();
|
|
}
|
|
return old_v;
|
|
}
|