mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream-mttcg' into staging
Base patches for MTTCG enablement. # gpg: Signature made Mon 31 Oct 2016 14:01:41 GMT # gpg: using RSA key 0xBFFBD25F78C7AE83 # gpg: Good signature from "Paolo Bonzini <bonzini@gnu.org>" # gpg: aka "Paolo Bonzini <pbonzini@redhat.com>" # Primary key fingerprint: 46F5 9FBD 57D6 12E7 BFD4 E2F7 7E15 100C CD36 69B1 # Subkey fingerprint: F133 3857 4B66 2389 866C 7682 BFFB D25F 78C7 AE83 * remotes/bonzini/tags/for-upstream-mttcg: tcg: move locking for tb_invalidate_phys_page_range up *_run_on_cpu: introduce run_on_cpu_data type cpus: re-factor out handle_icount_deadline tcg: cpus rm tcg_exec_all() tcg: move tcg_exec_all and helpers above thread fn target-arm/arm-powerctl: wake up sleeping CPUs tcg: protect translation related stuff with tb_lock. translate-all: Add assert_(memory|tb)_lock annotations linux-user/elfload: ensure mmap_lock() held while setting up tcg: comment on which functions have to be called with tb_lock held cpu-exec: include cpu_index in CPU_LOG_EXEC messages translate-all: add DEBUG_LOCKING asserts translate_all: DEBUG_FLUSH -> DEBUG_TB_FLUSH cpus: make all_vcpus_paused() return bool Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
@@ -42,6 +42,11 @@ void mmap_unlock(void)
|
||||
}
|
||||
}
|
||||
|
||||
bool have_mmap_lock(void)
|
||||
{
|
||||
return mmap_lock_count > 0 ? true : false;
|
||||
}
|
||||
|
||||
/* Grab lock to make sure things are in a consistent state after fork(). */
|
||||
void mmap_fork_start(void)
|
||||
{
|
||||
|
||||
+9
-2
@@ -143,8 +143,9 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb)
|
||||
uint8_t *tb_ptr = itb->tc_ptr;
|
||||
|
||||
qemu_log_mask_and_addr(CPU_LOG_EXEC, itb->pc,
|
||||
"Trace %p [" TARGET_FMT_lx "] %s\n",
|
||||
itb->tc_ptr, itb->pc, lookup_symbol(itb->pc));
|
||||
"Trace %p [%d: " TARGET_FMT_lx "] %s\n",
|
||||
itb->tc_ptr, cpu->cpu_index, itb->pc,
|
||||
lookup_symbol(itb->pc));
|
||||
|
||||
#if defined(DEBUG_DISAS)
|
||||
if (qemu_loglevel_mask(CPU_LOG_TB_CPU)
|
||||
@@ -204,15 +205,21 @@ static void cpu_exec_nocache(CPUState *cpu, int max_cycles,
|
||||
if (max_cycles > CF_COUNT_MASK)
|
||||
max_cycles = CF_COUNT_MASK;
|
||||
|
||||
tb_lock();
|
||||
tb = tb_gen_code(cpu, orig_tb->pc, orig_tb->cs_base, orig_tb->flags,
|
||||
max_cycles | CF_NOCACHE
|
||||
| (ignore_icount ? CF_IGNORE_ICOUNT : 0));
|
||||
tb->orig_tb = orig_tb;
|
||||
tb_unlock();
|
||||
|
||||
/* execute the generated code */
|
||||
trace_exec_tb_nocache(tb, tb->pc);
|
||||
cpu_tb_exec(cpu, tb);
|
||||
|
||||
tb_lock();
|
||||
tb_phys_invalidate(tb, -1);
|
||||
tb_free(tb);
|
||||
tb_unlock();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
+5
-4
@@ -109,7 +109,7 @@ void cpu_list_remove(CPUState *cpu)
|
||||
struct qemu_work_item {
|
||||
struct qemu_work_item *next;
|
||||
run_on_cpu_func func;
|
||||
void *data;
|
||||
run_on_cpu_data data;
|
||||
bool free, exclusive, done;
|
||||
};
|
||||
|
||||
@@ -129,7 +129,7 @@ static void queue_work_on_cpu(CPUState *cpu, struct qemu_work_item *wi)
|
||||
qemu_cpu_kick(cpu);
|
||||
}
|
||||
|
||||
void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data,
|
||||
void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,
|
||||
QemuMutex *mutex)
|
||||
{
|
||||
struct qemu_work_item wi;
|
||||
@@ -154,7 +154,7 @@ void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data,
|
||||
}
|
||||
}
|
||||
|
||||
void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data)
|
||||
void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data)
|
||||
{
|
||||
struct qemu_work_item *wi;
|
||||
|
||||
@@ -296,7 +296,8 @@ void cpu_exec_end(CPUState *cpu)
|
||||
}
|
||||
}
|
||||
|
||||
void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data)
|
||||
void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func,
|
||||
run_on_cpu_data data)
|
||||
{
|
||||
struct qemu_work_item *wi;
|
||||
|
||||
|
||||
@@ -69,7 +69,6 @@
|
||||
|
||||
#endif /* CONFIG_LINUX */
|
||||
|
||||
static CPUState *next_cpu;
|
||||
int64_t max_delay;
|
||||
int64_t max_advance;
|
||||
|
||||
@@ -557,7 +556,7 @@ static const VMStateDescription vmstate_timers = {
|
||||
}
|
||||
};
|
||||
|
||||
static void cpu_throttle_thread(CPUState *cpu, void *opaque)
|
||||
static void cpu_throttle_thread(CPUState *cpu, run_on_cpu_data opaque)
|
||||
{
|
||||
double pct;
|
||||
double throttle_ratio;
|
||||
@@ -588,7 +587,8 @@ static void cpu_throttle_timer_tick(void *opaque)
|
||||
}
|
||||
CPU_FOREACH(cpu) {
|
||||
if (!atomic_xchg(&cpu->throttle_thread_scheduled, 1)) {
|
||||
async_run_on_cpu(cpu, cpu_throttle_thread, NULL);
|
||||
async_run_on_cpu(cpu, cpu_throttle_thread,
|
||||
RUN_ON_CPU_NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -915,7 +915,7 @@ void qemu_init_cpu_loop(void)
|
||||
qemu_thread_get_self(&io_thread);
|
||||
}
|
||||
|
||||
void run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data)
|
||||
void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data)
|
||||
{
|
||||
do_run_on_cpu(cpu, func, data, &qemu_global_mutex);
|
||||
}
|
||||
@@ -1055,12 +1055,102 @@ static void *qemu_dummy_cpu_thread_fn(void *arg)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void tcg_exec_all(void);
|
||||
static int64_t tcg_get_icount_limit(void)
|
||||
{
|
||||
int64_t deadline;
|
||||
|
||||
if (replay_mode != REPLAY_MODE_PLAY) {
|
||||
deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL);
|
||||
|
||||
/* Maintain prior (possibly buggy) behaviour where if no deadline
|
||||
* was set (as there is no QEMU_CLOCK_VIRTUAL timer) or it is more than
|
||||
* INT32_MAX nanoseconds ahead, we still use INT32_MAX
|
||||
* nanoseconds.
|
||||
*/
|
||||
if ((deadline < 0) || (deadline > INT32_MAX)) {
|
||||
deadline = INT32_MAX;
|
||||
}
|
||||
|
||||
return qemu_icount_round(deadline);
|
||||
} else {
|
||||
return replay_get_instructions();
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_icount_deadline(void)
|
||||
{
|
||||
if (use_icount) {
|
||||
int64_t deadline =
|
||||
qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL);
|
||||
|
||||
if (deadline == 0) {
|
||||
qemu_clock_notify(QEMU_CLOCK_VIRTUAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int tcg_cpu_exec(CPUState *cpu)
|
||||
{
|
||||
int ret;
|
||||
#ifdef CONFIG_PROFILER
|
||||
int64_t ti;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_PROFILER
|
||||
ti = profile_getclock();
|
||||
#endif
|
||||
if (use_icount) {
|
||||
int64_t count;
|
||||
int decr;
|
||||
timers_state.qemu_icount -= (cpu->icount_decr.u16.low
|
||||
+ cpu->icount_extra);
|
||||
cpu->icount_decr.u16.low = 0;
|
||||
cpu->icount_extra = 0;
|
||||
count = tcg_get_icount_limit();
|
||||
timers_state.qemu_icount += count;
|
||||
decr = (count > 0xffff) ? 0xffff : count;
|
||||
count -= decr;
|
||||
cpu->icount_decr.u16.low = decr;
|
||||
cpu->icount_extra = count;
|
||||
}
|
||||
cpu_exec_start(cpu);
|
||||
ret = cpu_exec(cpu);
|
||||
cpu_exec_end(cpu);
|
||||
#ifdef CONFIG_PROFILER
|
||||
tcg_time += profile_getclock() - ti;
|
||||
#endif
|
||||
if (use_icount) {
|
||||
/* Fold pending instructions back into the
|
||||
instruction counter, and clear the interrupt flag. */
|
||||
timers_state.qemu_icount -= (cpu->icount_decr.u16.low
|
||||
+ cpu->icount_extra);
|
||||
cpu->icount_decr.u32 = 0;
|
||||
cpu->icount_extra = 0;
|
||||
replay_account_executed_instructions();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Destroy any remaining vCPUs which have been unplugged and have
|
||||
* finished running
|
||||
*/
|
||||
static void deal_with_unplugged_cpus(void)
|
||||
{
|
||||
CPUState *cpu;
|
||||
|
||||
CPU_FOREACH(cpu) {
|
||||
if (cpu->unplug && !cpu_can_run(cpu)) {
|
||||
qemu_tcg_destroy_vcpu(cpu);
|
||||
cpu->created = false;
|
||||
qemu_cond_signal(&qemu_cpu_cond);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void *qemu_tcg_cpu_thread_fn(void *arg)
|
||||
{
|
||||
CPUState *cpu = arg;
|
||||
CPUState *remove_cpu = NULL;
|
||||
|
||||
rcu_register_thread();
|
||||
|
||||
@@ -1087,29 +1177,44 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
|
||||
/* process any pending work */
|
||||
atomic_mb_set(&exit_request, 1);
|
||||
|
||||
cpu = first_cpu;
|
||||
|
||||
while (1) {
|
||||
tcg_exec_all();
|
||||
/* Account partial waits to QEMU_CLOCK_VIRTUAL. */
|
||||
qemu_account_warp_timer();
|
||||
|
||||
if (use_icount) {
|
||||
int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL);
|
||||
|
||||
if (deadline == 0) {
|
||||
qemu_clock_notify(QEMU_CLOCK_VIRTUAL);
|
||||
}
|
||||
if (!cpu) {
|
||||
cpu = first_cpu;
|
||||
}
|
||||
qemu_tcg_wait_io_event(QTAILQ_FIRST(&cpus));
|
||||
CPU_FOREACH(cpu) {
|
||||
if (cpu->unplug && !cpu_can_run(cpu)) {
|
||||
remove_cpu = cpu;
|
||||
|
||||
for (; cpu != NULL && !exit_request; cpu = CPU_NEXT(cpu)) {
|
||||
|
||||
qemu_clock_enable(QEMU_CLOCK_VIRTUAL,
|
||||
(cpu->singlestep_enabled & SSTEP_NOTIMER) == 0);
|
||||
|
||||
if (cpu_can_run(cpu)) {
|
||||
int r;
|
||||
r = tcg_cpu_exec(cpu);
|
||||
if (r == EXCP_DEBUG) {
|
||||
cpu_handle_guest_debug(cpu);
|
||||
break;
|
||||
}
|
||||
} else if (cpu->stop || cpu->stopped) {
|
||||
if (cpu->unplug) {
|
||||
cpu = CPU_NEXT(cpu);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (remove_cpu) {
|
||||
qemu_tcg_destroy_vcpu(remove_cpu);
|
||||
cpu->created = false;
|
||||
qemu_cond_signal(&qemu_cpu_cond);
|
||||
remove_cpu = NULL;
|
||||
}
|
||||
|
||||
} /* for cpu.. */
|
||||
|
||||
/* Pairs with smp_wmb in qemu_cpu_kick. */
|
||||
atomic_mb_set(&exit_request, 0);
|
||||
|
||||
handle_icount_deadline();
|
||||
|
||||
qemu_tcg_wait_io_event(QTAILQ_FIRST(&cpus));
|
||||
deal_with_unplugged_cpus();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -1207,17 +1312,17 @@ void qemu_mutex_unlock_iothread(void)
|
||||
qemu_mutex_unlock(&qemu_global_mutex);
|
||||
}
|
||||
|
||||
static int all_vcpus_paused(void)
|
||||
static bool all_vcpus_paused(void)
|
||||
{
|
||||
CPUState *cpu;
|
||||
|
||||
CPU_FOREACH(cpu) {
|
||||
if (!cpu->stopped) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
void pause_all_vcpus(void)
|
||||
@@ -1412,106 +1517,6 @@ int vm_stop_force_state(RunState state)
|
||||
}
|
||||
}
|
||||
|
||||
static int64_t tcg_get_icount_limit(void)
|
||||
{
|
||||
int64_t deadline;
|
||||
|
||||
if (replay_mode != REPLAY_MODE_PLAY) {
|
||||
deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL);
|
||||
|
||||
/* Maintain prior (possibly buggy) behaviour where if no deadline
|
||||
* was set (as there is no QEMU_CLOCK_VIRTUAL timer) or it is more than
|
||||
* INT32_MAX nanoseconds ahead, we still use INT32_MAX
|
||||
* nanoseconds.
|
||||
*/
|
||||
if ((deadline < 0) || (deadline > INT32_MAX)) {
|
||||
deadline = INT32_MAX;
|
||||
}
|
||||
|
||||
return qemu_icount_round(deadline);
|
||||
} else {
|
||||
return replay_get_instructions();
|
||||
}
|
||||
}
|
||||
|
||||
static int tcg_cpu_exec(CPUState *cpu)
|
||||
{
|
||||
int ret;
|
||||
#ifdef CONFIG_PROFILER
|
||||
int64_t ti;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_PROFILER
|
||||
ti = profile_getclock();
|
||||
#endif
|
||||
if (use_icount) {
|
||||
int64_t count;
|
||||
int decr;
|
||||
timers_state.qemu_icount -= (cpu->icount_decr.u16.low
|
||||
+ cpu->icount_extra);
|
||||
cpu->icount_decr.u16.low = 0;
|
||||
cpu->icount_extra = 0;
|
||||
count = tcg_get_icount_limit();
|
||||
timers_state.qemu_icount += count;
|
||||
decr = (count > 0xffff) ? 0xffff : count;
|
||||
count -= decr;
|
||||
cpu->icount_decr.u16.low = decr;
|
||||
cpu->icount_extra = count;
|
||||
}
|
||||
cpu_exec_start(cpu);
|
||||
ret = cpu_exec(cpu);
|
||||
cpu_exec_end(cpu);
|
||||
#ifdef CONFIG_PROFILER
|
||||
tcg_time += profile_getclock() - ti;
|
||||
#endif
|
||||
if (use_icount) {
|
||||
/* Fold pending instructions back into the
|
||||
instruction counter, and clear the interrupt flag. */
|
||||
timers_state.qemu_icount -= (cpu->icount_decr.u16.low
|
||||
+ cpu->icount_extra);
|
||||
cpu->icount_decr.u32 = 0;
|
||||
cpu->icount_extra = 0;
|
||||
replay_account_executed_instructions();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void tcg_exec_all(void)
|
||||
{
|
||||
int r;
|
||||
|
||||
/* Account partial waits to QEMU_CLOCK_VIRTUAL. */
|
||||
qemu_account_warp_timer();
|
||||
|
||||
if (next_cpu == NULL) {
|
||||
next_cpu = first_cpu;
|
||||
}
|
||||
for (; next_cpu != NULL && !exit_request; next_cpu = CPU_NEXT(next_cpu)) {
|
||||
CPUState *cpu = next_cpu;
|
||||
|
||||
qemu_clock_enable(QEMU_CLOCK_VIRTUAL,
|
||||
(cpu->singlestep_enabled & SSTEP_NOTIMER) == 0);
|
||||
|
||||
if (cpu_can_run(cpu)) {
|
||||
r = tcg_cpu_exec(cpu);
|
||||
if (r == EXCP_DEBUG) {
|
||||
cpu_handle_guest_debug(cpu);
|
||||
break;
|
||||
} else if (r == EXCP_ATOMIC) {
|
||||
cpu_exec_step_atomic(cpu);
|
||||
}
|
||||
} else if (cpu->stop || cpu->stopped) {
|
||||
if (cpu->unplug) {
|
||||
next_cpu = CPU_NEXT(cpu);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Pairs with smp_wmb in qemu_cpu_kick. */
|
||||
atomic_mb_set(&exit_request, 0);
|
||||
}
|
||||
|
||||
void list_cpus(FILE *f, fprintf_function cpu_fprintf, const char *optarg)
|
||||
{
|
||||
/* XXX: implement xxx_cpu_list for targets that still miss it */
|
||||
|
||||
@@ -687,7 +687,11 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp)
|
||||
#if defined(CONFIG_USER_ONLY)
|
||||
static void breakpoint_invalidate(CPUState *cpu, target_ulong pc)
|
||||
{
|
||||
mmap_lock();
|
||||
tb_lock();
|
||||
tb_invalidate_phys_page_range(pc, pc + 1, 0);
|
||||
tb_unlock();
|
||||
mmap_unlock();
|
||||
}
|
||||
#else
|
||||
static void breakpoint_invalidate(CPUState *cpu, target_ulong pc)
|
||||
@@ -696,6 +700,7 @@ static void breakpoint_invalidate(CPUState *cpu, target_ulong pc)
|
||||
hwaddr phys = cpu_get_phys_page_attrs_debug(cpu, pc, &attrs);
|
||||
int asidx = cpu_asidx_from_attrs(cpu, attrs);
|
||||
if (phys != -1) {
|
||||
/* Locks grabbed by tb_invalidate_phys_addr */
|
||||
tb_invalidate_phys_addr(cpu->cpu_ases[asidx].as,
|
||||
phys | (pc & ~TARGET_PAGE_MASK));
|
||||
}
|
||||
@@ -1988,7 +1993,11 @@ ram_addr_t qemu_ram_addr_from_host(void *ptr)
|
||||
static void notdirty_mem_write(void *opaque, hwaddr ram_addr,
|
||||
uint64_t val, unsigned size)
|
||||
{
|
||||
bool locked = false;
|
||||
|
||||
if (!cpu_physical_memory_get_dirty_flag(ram_addr, DIRTY_MEMORY_CODE)) {
|
||||
locked = true;
|
||||
tb_lock();
|
||||
tb_invalidate_phys_page_fast(ram_addr, size);
|
||||
}
|
||||
switch (size) {
|
||||
@@ -2004,6 +2013,11 @@ static void notdirty_mem_write(void *opaque, hwaddr ram_addr,
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
||||
if (locked) {
|
||||
tb_unlock();
|
||||
}
|
||||
|
||||
/* Set both VGA and migration bits for simplicity and to remove
|
||||
* the notdirty callback faster.
|
||||
*/
|
||||
@@ -2064,6 +2078,12 @@ static void check_watchpoint(int offset, int len, MemTxAttrs attrs, int flags)
|
||||
continue;
|
||||
}
|
||||
cpu->watchpoint_hit = wp;
|
||||
|
||||
/* The tb_lock will be reset when cpu_loop_exit or
|
||||
* cpu_loop_exit_noexc longjmp back into the cpu_exec
|
||||
* main loop.
|
||||
*/
|
||||
tb_lock();
|
||||
tb_check_watchpoint(cpu);
|
||||
if (wp->flags & BP_STOP_BEFORE_ACCESS) {
|
||||
cpu->exception_index = EXCP_DEBUG;
|
||||
@@ -2471,7 +2491,9 @@ static void invalidate_and_set_dirty(MemoryRegion *mr, hwaddr addr,
|
||||
cpu_physical_memory_range_includes_clean(addr, length, dirty_log_mask);
|
||||
}
|
||||
if (dirty_log_mask & (1 << DIRTY_MEMORY_CODE)) {
|
||||
tb_lock();
|
||||
tb_invalidate_phys_range(addr, addr + length);
|
||||
tb_unlock();
|
||||
dirty_log_mask &= ~(1 << DIRTY_MEMORY_CODE);
|
||||
}
|
||||
cpu_physical_memory_set_dirty_range(addr, length, dirty_log_mask);
|
||||
|
||||
+7
-7
@@ -133,9 +133,9 @@ static void kvm_apic_vapic_base_update(APICCommonState *s)
|
||||
}
|
||||
}
|
||||
|
||||
static void kvm_apic_put(CPUState *cs, void *data)
|
||||
static void kvm_apic_put(CPUState *cs, run_on_cpu_data data)
|
||||
{
|
||||
APICCommonState *s = data;
|
||||
APICCommonState *s = data.host_ptr;
|
||||
struct kvm_lapic_state kapic;
|
||||
int ret;
|
||||
|
||||
@@ -151,12 +151,12 @@ static void kvm_apic_put(CPUState *cs, void *data)
|
||||
|
||||
static void kvm_apic_post_load(APICCommonState *s)
|
||||
{
|
||||
run_on_cpu(CPU(s->cpu), kvm_apic_put, s);
|
||||
run_on_cpu(CPU(s->cpu), kvm_apic_put, RUN_ON_CPU_HOST_PTR(s));
|
||||
}
|
||||
|
||||
static void do_inject_external_nmi(CPUState *cpu, void *data)
|
||||
static void do_inject_external_nmi(CPUState *cpu, run_on_cpu_data data)
|
||||
{
|
||||
APICCommonState *s = data;
|
||||
APICCommonState *s = data.host_ptr;
|
||||
uint32_t lvt;
|
||||
int ret;
|
||||
|
||||
@@ -174,7 +174,7 @@ static void do_inject_external_nmi(CPUState *cpu, void *data)
|
||||
|
||||
static void kvm_apic_external_nmi(APICCommonState *s)
|
||||
{
|
||||
run_on_cpu(CPU(s->cpu), do_inject_external_nmi, s);
|
||||
run_on_cpu(CPU(s->cpu), do_inject_external_nmi, RUN_ON_CPU_HOST_PTR(s));
|
||||
}
|
||||
|
||||
static void kvm_send_msi(MSIMessage *msg)
|
||||
@@ -213,7 +213,7 @@ static void kvm_apic_reset(APICCommonState *s)
|
||||
/* Not used by KVM, which uses the CPU mp_state instead. */
|
||||
s->wait_for_sipi = 0;
|
||||
|
||||
run_on_cpu(CPU(s->cpu), kvm_apic_put, s);
|
||||
run_on_cpu(CPU(s->cpu), kvm_apic_put, RUN_ON_CPU_HOST_PTR(s));
|
||||
}
|
||||
|
||||
static void kvm_apic_realize(DeviceState *dev, Error **errp)
|
||||
|
||||
+10
-7
@@ -17,6 +17,7 @@
|
||||
#include "sysemu/kvm.h"
|
||||
#include "hw/i386/apic_internal.h"
|
||||
#include "hw/sysbus.h"
|
||||
#include "tcg/tcg.h"
|
||||
|
||||
#define VAPIC_IO_PORT 0x7e
|
||||
|
||||
@@ -449,6 +450,9 @@ static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)
|
||||
resume_all_vcpus();
|
||||
|
||||
if (!kvm_enabled()) {
|
||||
/* tb_lock will be reset when cpu_loop_exit_noexc longjmps
|
||||
* back into the cpu_exec loop. */
|
||||
tb_lock();
|
||||
tb_gen_code(cs, current_pc, current_cs_base, current_flags, 1);
|
||||
cpu_loop_exit_noexc(cs);
|
||||
}
|
||||
@@ -483,10 +487,9 @@ typedef struct VAPICEnableTPRReporting {
|
||||
bool enable;
|
||||
} VAPICEnableTPRReporting;
|
||||
|
||||
static void vapic_do_enable_tpr_reporting(CPUState *cpu, void *data)
|
||||
static void vapic_do_enable_tpr_reporting(CPUState *cpu, run_on_cpu_data data)
|
||||
{
|
||||
VAPICEnableTPRReporting *info = data;
|
||||
|
||||
VAPICEnableTPRReporting *info = data.host_ptr;
|
||||
apic_enable_tpr_access_reporting(info->apic, info->enable);
|
||||
}
|
||||
|
||||
@@ -501,7 +504,7 @@ static void vapic_enable_tpr_reporting(bool enable)
|
||||
CPU_FOREACH(cs) {
|
||||
cpu = X86_CPU(cs);
|
||||
info.apic = cpu->apic_state;
|
||||
run_on_cpu(cs, vapic_do_enable_tpr_reporting, &info);
|
||||
run_on_cpu(cs, vapic_do_enable_tpr_reporting, RUN_ON_CPU_HOST_PTR(&info));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -734,9 +737,9 @@ static void vapic_realize(DeviceState *dev, Error **errp)
|
||||
nb_option_roms++;
|
||||
}
|
||||
|
||||
static void do_vapic_enable(CPUState *cs, void *data)
|
||||
static void do_vapic_enable(CPUState *cs, run_on_cpu_data data)
|
||||
{
|
||||
VAPICROMState *s = data;
|
||||
VAPICROMState *s = data.host_ptr;
|
||||
X86CPU *cpu = X86_CPU(cs);
|
||||
|
||||
static const uint8_t enabled = 1;
|
||||
@@ -758,7 +761,7 @@ static void kvmvapic_vm_state_change(void *opaque, int running,
|
||||
|
||||
if (s->state == VAPIC_ACTIVE) {
|
||||
if (smp_cpus == 1) {
|
||||
run_on_cpu(first_cpu, do_vapic_enable, s);
|
||||
run_on_cpu(first_cpu, do_vapic_enable, RUN_ON_CPU_HOST_PTR(s));
|
||||
} else {
|
||||
zero = g_malloc0(s->rom_state.vapic_size);
|
||||
cpu_physical_memory_write(s->vapic_paddr, zero,
|
||||
|
||||
@@ -84,11 +84,11 @@ static void mmubooke_create_initial_mapping(CPUPPCState *env,
|
||||
env->tlb_dirty = true;
|
||||
}
|
||||
|
||||
static void spin_kick(CPUState *cs, void *data)
|
||||
static void spin_kick(CPUState *cs, run_on_cpu_data data)
|
||||
{
|
||||
PowerPCCPU *cpu = POWERPC_CPU(cs);
|
||||
CPUPPCState *env = &cpu->env;
|
||||
SpinInfo *curspin = data;
|
||||
SpinInfo *curspin = data.host_ptr;
|
||||
hwaddr map_size = 64 * 1024 * 1024;
|
||||
hwaddr map_start;
|
||||
|
||||
@@ -147,7 +147,7 @@ static void spin_write(void *opaque, hwaddr addr, uint64_t value,
|
||||
|
||||
if (!(ldq_p(&curspin->addr) & 1)) {
|
||||
/* run CPU */
|
||||
run_on_cpu(cpu, spin_kick, curspin);
|
||||
run_on_cpu(cpu, spin_kick, RUN_ON_CPU_HOST_PTR(curspin));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -2186,7 +2186,7 @@ static void spapr_machine_finalizefn(Object *obj)
|
||||
g_free(spapr->kvm_type);
|
||||
}
|
||||
|
||||
static void ppc_cpu_do_nmi_on_cpu(CPUState *cs, void *arg)
|
||||
static void ppc_cpu_do_nmi_on_cpu(CPUState *cs, run_on_cpu_data arg)
|
||||
{
|
||||
cpu_synchronize_state(cs);
|
||||
ppc_cpu_do_system_reset(cs);
|
||||
@@ -2197,7 +2197,7 @@ static void spapr_nmi(NMIState *n, int cpu_index, Error **errp)
|
||||
CPUState *cs;
|
||||
|
||||
CPU_FOREACH(cs) {
|
||||
async_run_on_cpu(cs, ppc_cpu_do_nmi_on_cpu, NULL);
|
||||
async_run_on_cpu(cs, ppc_cpu_do_nmi_on_cpu, RUN_ON_CPU_NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ struct SPRSyncState {
|
||||
target_ulong mask;
|
||||
};
|
||||
|
||||
static void do_spr_sync(CPUState *cs, void *arg)
|
||||
static void do_spr_sync(CPUState *cs, run_on_cpu_data arg)
|
||||
{
|
||||
struct SPRSyncState *s = arg;
|
||||
struct SPRSyncState *s = arg.host_ptr;
|
||||
PowerPCCPU *cpu = POWERPC_CPU(cs);
|
||||
CPUPPCState *env = &cpu->env;
|
||||
|
||||
@@ -38,7 +38,7 @@ static void set_spr(CPUState *cs, int spr, target_ulong value,
|
||||
.value = value,
|
||||
.mask = mask
|
||||
};
|
||||
run_on_cpu(cs, do_spr_sync, &s);
|
||||
run_on_cpu(cs, do_spr_sync, RUN_ON_CPU_HOST_PTR(&s));
|
||||
}
|
||||
|
||||
static bool has_spr(PowerPCCPU *cpu, int spr)
|
||||
@@ -886,10 +886,10 @@ typedef struct {
|
||||
Error *err;
|
||||
} SetCompatState;
|
||||
|
||||
static void do_set_compat(CPUState *cs, void *arg)
|
||||
static void do_set_compat(CPUState *cs, run_on_cpu_data arg)
|
||||
{
|
||||
PowerPCCPU *cpu = POWERPC_CPU(cs);
|
||||
SetCompatState *s = arg;
|
||||
SetCompatState *s = arg.host_ptr;
|
||||
|
||||
cpu_synchronize_state(cs);
|
||||
ppc_set_compat(cpu, s->cpu_version, &s->err);
|
||||
@@ -990,7 +990,7 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu_,
|
||||
.err = NULL,
|
||||
};
|
||||
|
||||
run_on_cpu(cs, do_set_compat, &s);
|
||||
run_on_cpu(cs, do_set_compat, RUN_ON_CPU_HOST_PTR(&s));
|
||||
|
||||
if (s.err) {
|
||||
error_report_err(s.err);
|
||||
|
||||
@@ -316,6 +316,7 @@ static inline void tb_set_jmp_target(TranslationBlock *tb,
|
||||
|
||||
#endif
|
||||
|
||||
/* Called with tb_lock held. */
|
||||
static inline void tb_add_jump(TranslationBlock *tb, int n,
|
||||
TranslationBlock *tb_next)
|
||||
{
|
||||
@@ -369,6 +370,7 @@ void tlb_fill(CPUState *cpu, target_ulong addr, MMUAccessType access_type,
|
||||
#if defined(CONFIG_USER_ONLY)
|
||||
void mmap_lock(void);
|
||||
void mmap_unlock(void);
|
||||
bool have_mmap_lock(void);
|
||||
|
||||
static inline tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong addr)
|
||||
{
|
||||
|
||||
+26
-5
@@ -231,7 +231,25 @@ struct kvm_run;
|
||||
#define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
|
||||
|
||||
/* work queue */
|
||||
typedef void (*run_on_cpu_func)(CPUState *cpu, void *data);
|
||||
|
||||
/* The union type allows passing of 64 bit target pointers on 32 bit
|
||||
* hosts in a single parameter
|
||||
*/
|
||||
typedef union {
|
||||
int host_int;
|
||||
unsigned long host_ulong;
|
||||
void *host_ptr;
|
||||
vaddr target_ptr;
|
||||
} run_on_cpu_data;
|
||||
|
||||
#define RUN_ON_CPU_HOST_PTR(p) ((run_on_cpu_data){.host_ptr = (p)})
|
||||
#define RUN_ON_CPU_HOST_INT(i) ((run_on_cpu_data){.host_int = (i)})
|
||||
#define RUN_ON_CPU_HOST_ULONG(ul) ((run_on_cpu_data){.host_ulong = (ul)})
|
||||
#define RUN_ON_CPU_TARGET_PTR(v) ((run_on_cpu_data){.target_ptr = (v)})
|
||||
#define RUN_ON_CPU_NULL RUN_ON_CPU_HOST_PTR(NULL)
|
||||
|
||||
typedef void (*run_on_cpu_func)(CPUState *cpu, run_on_cpu_data data);
|
||||
|
||||
struct qemu_work_item;
|
||||
|
||||
/**
|
||||
@@ -319,7 +337,10 @@ struct CPUState {
|
||||
MemoryRegion *memory;
|
||||
|
||||
void *env_ptr; /* CPUArchState */
|
||||
|
||||
/* Writes protected by tb_lock, reads not thread-safe */
|
||||
struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];
|
||||
|
||||
struct GDBRegisterState *gdb_regs;
|
||||
int gdb_num_regs;
|
||||
int gdb_num_g_regs;
|
||||
@@ -634,7 +655,7 @@ bool cpu_is_stopped(CPUState *cpu);
|
||||
*
|
||||
* Used internally in the implementation of run_on_cpu.
|
||||
*/
|
||||
void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data,
|
||||
void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,
|
||||
QemuMutex *mutex);
|
||||
|
||||
/**
|
||||
@@ -645,7 +666,7 @@ void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data,
|
||||
*
|
||||
* Schedules the function @func for execution on the vCPU @cpu.
|
||||
*/
|
||||
void run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data);
|
||||
void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
|
||||
|
||||
/**
|
||||
* async_run_on_cpu:
|
||||
@@ -655,7 +676,7 @@ void run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data);
|
||||
*
|
||||
* Schedules the function @func for execution on the vCPU @cpu asynchronously.
|
||||
*/
|
||||
void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data);
|
||||
void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
|
||||
|
||||
/**
|
||||
* async_safe_run_on_cpu:
|
||||
@@ -669,7 +690,7 @@ void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data);
|
||||
* Unlike run_on_cpu and async_run_on_cpu, the function is run outside the
|
||||
* BQL.
|
||||
*/
|
||||
void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data);
|
||||
void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
|
||||
|
||||
/**
|
||||
* qemu_get_cpu:
|
||||
|
||||
@@ -1856,7 +1856,7 @@ void kvm_flush_coalesced_mmio_buffer(void)
|
||||
s->coalesced_flush_in_progress = false;
|
||||
}
|
||||
|
||||
static void do_kvm_cpu_synchronize_state(CPUState *cpu, void *arg)
|
||||
static void do_kvm_cpu_synchronize_state(CPUState *cpu, run_on_cpu_data arg)
|
||||
{
|
||||
if (!cpu->kvm_vcpu_dirty) {
|
||||
kvm_arch_get_registers(cpu);
|
||||
@@ -1867,11 +1867,11 @@ static void do_kvm_cpu_synchronize_state(CPUState *cpu, void *arg)
|
||||
void kvm_cpu_synchronize_state(CPUState *cpu)
|
||||
{
|
||||
if (!cpu->kvm_vcpu_dirty) {
|
||||
run_on_cpu(cpu, do_kvm_cpu_synchronize_state, NULL);
|
||||
run_on_cpu(cpu, do_kvm_cpu_synchronize_state, RUN_ON_CPU_NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void do_kvm_cpu_synchronize_post_reset(CPUState *cpu, void *arg)
|
||||
static void do_kvm_cpu_synchronize_post_reset(CPUState *cpu, run_on_cpu_data arg)
|
||||
{
|
||||
kvm_arch_put_registers(cpu, KVM_PUT_RESET_STATE);
|
||||
cpu->kvm_vcpu_dirty = false;
|
||||
@@ -1879,10 +1879,10 @@ static void do_kvm_cpu_synchronize_post_reset(CPUState *cpu, void *arg)
|
||||
|
||||
void kvm_cpu_synchronize_post_reset(CPUState *cpu)
|
||||
{
|
||||
run_on_cpu(cpu, do_kvm_cpu_synchronize_post_reset, NULL);
|
||||
run_on_cpu(cpu, do_kvm_cpu_synchronize_post_reset, RUN_ON_CPU_NULL);
|
||||
}
|
||||
|
||||
static void do_kvm_cpu_synchronize_post_init(CPUState *cpu, void *arg)
|
||||
static void do_kvm_cpu_synchronize_post_init(CPUState *cpu, run_on_cpu_data arg)
|
||||
{
|
||||
kvm_arch_put_registers(cpu, KVM_PUT_FULL_STATE);
|
||||
cpu->kvm_vcpu_dirty = false;
|
||||
@@ -1890,7 +1890,7 @@ static void do_kvm_cpu_synchronize_post_init(CPUState *cpu, void *arg)
|
||||
|
||||
void kvm_cpu_synchronize_post_init(CPUState *cpu)
|
||||
{
|
||||
run_on_cpu(cpu, do_kvm_cpu_synchronize_post_init, NULL);
|
||||
run_on_cpu(cpu, do_kvm_cpu_synchronize_post_init, RUN_ON_CPU_NULL);
|
||||
}
|
||||
|
||||
int kvm_cpu_exec(CPUState *cpu)
|
||||
@@ -2218,9 +2218,10 @@ struct kvm_set_guest_debug_data {
|
||||
int err;
|
||||
};
|
||||
|
||||
static void kvm_invoke_set_guest_debug(CPUState *cpu, void *data)
|
||||
static void kvm_invoke_set_guest_debug(CPUState *cpu, run_on_cpu_data data)
|
||||
{
|
||||
struct kvm_set_guest_debug_data *dbg_data = data;
|
||||
struct kvm_set_guest_debug_data *dbg_data =
|
||||
(struct kvm_set_guest_debug_data *) data.host_ptr;
|
||||
|
||||
dbg_data->err = kvm_vcpu_ioctl(cpu, KVM_SET_GUEST_DEBUG,
|
||||
&dbg_data->dbg);
|
||||
@@ -2237,7 +2238,8 @@ int kvm_update_guest_debug(CPUState *cpu, unsigned long reinject_trap)
|
||||
}
|
||||
kvm_arch_update_guest_debug(cpu, &data.dbg);
|
||||
|
||||
run_on_cpu(cpu, kvm_invoke_set_guest_debug, &data);
|
||||
run_on_cpu(cpu, kvm_invoke_set_guest_debug,
|
||||
RUN_ON_CPU_HOST_PTR(&data));
|
||||
return data.err;
|
||||
}
|
||||
|
||||
|
||||
@@ -1842,6 +1842,8 @@ static void load_elf_image(const char *image_name, int image_fd,
|
||||
info->pt_dynamic_addr = 0;
|
||||
#endif
|
||||
|
||||
mmap_lock();
|
||||
|
||||
/* Find the maximum size of the image and allocate an appropriate
|
||||
amount of memory to handle that. */
|
||||
loaddr = -1, hiaddr = 0;
|
||||
@@ -2002,6 +2004,8 @@ static void load_elf_image(const char *image_name, int image_fd,
|
||||
load_symbols(ehdr, image_fd, load_bias);
|
||||
}
|
||||
|
||||
mmap_unlock();
|
||||
|
||||
close(image_fd);
|
||||
return;
|
||||
|
||||
|
||||
@@ -41,6 +41,11 @@ void mmap_unlock(void)
|
||||
}
|
||||
}
|
||||
|
||||
bool have_mmap_lock(void)
|
||||
{
|
||||
return mmap_lock_count > 0 ? true : false;
|
||||
}
|
||||
|
||||
/* Grab lock to make sure things are in a consistent state after fork(). */
|
||||
void mmap_fork_start(void)
|
||||
{
|
||||
|
||||
@@ -9,4 +9,4 @@ obj-y += neon_helper.o iwmmxt_helper.o
|
||||
obj-y += gdbstub.o
|
||||
obj-$(TARGET_AARCH64) += cpu64.o translate-a64.o helper-a64.o gdbstub64.o
|
||||
obj-y += crypto_helper.o
|
||||
obj-y += arm-powerctl.o
|
||||
obj-$(CONFIG_SOFTMMU) += arm-powerctl.o
|
||||
|
||||
@@ -166,6 +166,8 @@ int arm_set_cpu_on(uint64_t cpuid, uint64_t entry, uint64_t context_id,
|
||||
/* Start the new CPU at the requested address */
|
||||
cpu_set_pc(target_cpu_state, entry);
|
||||
|
||||
qemu_cpu_kick(target_cpu_state);
|
||||
|
||||
/* We are good to go */
|
||||
return QEMU_ARM_POWERCTL_RET_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1121,9 +1121,9 @@ typedef struct MCEInjectionParams {
|
||||
int flags;
|
||||
} MCEInjectionParams;
|
||||
|
||||
static void do_inject_x86_mce(CPUState *cs, void *data)
|
||||
static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)
|
||||
{
|
||||
MCEInjectionParams *params = data;
|
||||
MCEInjectionParams *params = data.host_ptr;
|
||||
X86CPU *cpu = X86_CPU(cs);
|
||||
CPUX86State *cenv = &cpu->env;
|
||||
uint64_t *banks = cenv->mce_banks + 4 * params->bank;
|
||||
@@ -1230,7 +1230,7 @@ void cpu_x86_inject_mce(Monitor *mon, X86CPU *cpu, int bank,
|
||||
return;
|
||||
}
|
||||
|
||||
run_on_cpu(cs, do_inject_x86_mce, ¶ms);
|
||||
run_on_cpu(cs, do_inject_x86_mce, RUN_ON_CPU_HOST_PTR(¶ms));
|
||||
if (flags & MCE_INJECT_BROADCAST) {
|
||||
CPUState *other_cs;
|
||||
|
||||
@@ -1243,7 +1243,7 @@ void cpu_x86_inject_mce(Monitor *mon, X86CPU *cpu, int bank,
|
||||
if (other_cs == cs) {
|
||||
continue;
|
||||
}
|
||||
run_on_cpu(other_cs, do_inject_x86_mce, ¶ms);
|
||||
run_on_cpu(other_cs, do_inject_x86_mce, RUN_ON_CPU_HOST_PTR(¶ms));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -183,7 +183,7 @@ static int kvm_get_tsc(CPUState *cs)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void do_kvm_synchronize_tsc(CPUState *cpu, void *arg)
|
||||
static inline void do_kvm_synchronize_tsc(CPUState *cpu, run_on_cpu_data arg)
|
||||
{
|
||||
kvm_get_tsc(cpu);
|
||||
}
|
||||
@@ -194,7 +194,7 @@ void kvm_synchronize_all_tsc(void)
|
||||
|
||||
if (kvm_enabled()) {
|
||||
CPU_FOREACH(cpu) {
|
||||
run_on_cpu(cpu, do_kvm_synchronize_tsc, NULL);
|
||||
run_on_cpu(cpu, do_kvm_synchronize_tsc, RUN_ON_CPU_NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -164,7 +164,7 @@ static void s390_cpu_machine_reset_cb(void *opaque)
|
||||
{
|
||||
S390CPU *cpu = opaque;
|
||||
|
||||
run_on_cpu(CPU(cpu), s390_do_cpu_full_reset, NULL);
|
||||
run_on_cpu(CPU(cpu), s390_do_cpu_full_reset, RUN_ON_CPU_NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -220,7 +220,7 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp)
|
||||
s390_cpu_gdb_init(cs);
|
||||
qemu_init_vcpu(cs);
|
||||
#if !defined(CONFIG_USER_ONLY)
|
||||
run_on_cpu(cs, s390_do_cpu_full_reset, NULL);
|
||||
run_on_cpu(cs, s390_do_cpu_full_reset, RUN_ON_CPU_NULL);
|
||||
#else
|
||||
cpu_reset(cs);
|
||||
#endif
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user