2012-01-28 16:39:52 +01:00
|
|
|
/*
|
|
|
|
* QEMU CPU model
|
|
|
|
*
|
2014-03-03 23:33:51 +01:00
|
|
|
* Copyright (c) 2012-2014 SUSE LINUX Products GmbH
|
2012-01-28 16:39:52 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, see
|
|
|
|
* <http://www.gnu.org/licenses/gpl-2.0.html>
|
|
|
|
*/
|
|
|
|
|
2016-02-23 12:58:02 +01:00
|
|
|
#include "qemu/osdep.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2019-07-09 17:20:52 +02:00
|
|
|
#include "hw/core/cpu.h"
|
2017-01-10 11:59:55 +01:00
|
|
|
#include "sysemu/hw_accel.h"
|
2013-04-23 10:29:39 +02:00
|
|
|
#include "qemu/notify.h"
|
2013-06-16 07:49:48 +02:00
|
|
|
#include "qemu/log.h"
|
Include qemu/main-loop.h less
In my "build everything" tree, changing qemu/main-loop.h triggers a
recompile of some 5600 out of 6600 objects (not counting tests and
objects that don't depend on qemu/osdep.h). It includes block/aio.h,
which in turn includes qemu/event_notifier.h, qemu/notify.h,
qemu/processor.h, qemu/qsp.h, qemu/queue.h, qemu/thread-posix.h,
qemu/thread.h, qemu/timer.h, and a few more.
Include qemu/main-loop.h only where it's needed. Touching it now
recompiles only some 1700 objects. For block/aio.h and
qemu/event_notifier.h, these numbers drop from 5600 to 2800. For the
others, they shrink only slightly.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20190812052359.30071-21-armbru@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
2019-08-12 07:23:50 +02:00
|
|
|
#include "qemu/main-loop.h"
|
2016-01-07 14:55:28 +01:00
|
|
|
#include "exec/log.h"
|
2020-09-08 14:34:33 +02:00
|
|
|
#include "exec/cpu-common.h"
|
2014-03-04 03:17:10 +01:00
|
|
|
#include "qemu/error-report.h"
|
2019-04-17 21:18:02 +02:00
|
|
|
#include "qemu/qemu-print.h"
|
2019-05-23 16:35:05 +02:00
|
|
|
#include "sysemu/tcg.h"
|
2017-09-07 14:54:54 +02:00
|
|
|
#include "hw/boards.h"
|
2016-06-09 19:11:01 +02:00
|
|
|
#include "hw/qdev-properties.h"
|
2020-02-04 12:20:10 +01:00
|
|
|
#include "trace/trace-root.h"
|
2018-10-21 19:30:35 +02:00
|
|
|
#include "qemu/plugin.h"
|
2013-04-23 10:29:39 +02:00
|
|
|
|
2017-07-26 20:44:35 +02:00
|
|
|
CPUState *cpu_by_arch_id(int64_t id)
|
2013-04-25 16:05:24 +02:00
|
|
|
{
|
2013-07-07 19:50:23 +02:00
|
|
|
CPUState *cpu;
|
|
|
|
|
|
|
|
CPU_FOREACH(cpu) {
|
|
|
|
CPUClass *cc = CPU_GET_CLASS(cpu);
|
2013-04-25 16:05:24 +02:00
|
|
|
|
2013-07-07 19:50:23 +02:00
|
|
|
if (cc->get_arch_id(cpu) == id) {
|
2017-07-26 20:44:35 +02:00
|
|
|
return cpu;
|
2013-07-07 19:50:23 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-26 20:44:35 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cpu_exists(int64_t id)
|
|
|
|
{
|
|
|
|
return !!cpu_by_arch_id(id);
|
2013-04-25 16:05:24 +02:00
|
|
|
}
|
|
|
|
|
2017-09-13 18:04:53 +02:00
|
|
|
CPUState *cpu_create(const char *typename)
|
|
|
|
{
|
|
|
|
Error *err = NULL;
|
|
|
|
CPUState *cpu = CPU(object_new(typename));
|
qdev: Use returned bool to check for qdev_realize() etc. failure
Convert
foo(..., &err);
if (err) {
...
}
to
if (!foo(..., &err)) {
...
}
for qdev_realize(), qdev_realize_and_unref(), qbus_realize() and their
wrappers isa_realize_and_unref(), pci_realize_and_unref(),
sysbus_realize(), sysbus_realize_and_unref(), usb_realize_and_unref().
Coccinelle script:
@@
identifier fun = {
isa_realize_and_unref, pci_realize_and_unref, qbus_realize,
qdev_realize, qdev_realize_and_unref, sysbus_realize,
sysbus_realize_and_unref, usb_realize_and_unref
};
expression list args, args2;
typedef Error;
Error *err;
@@
- fun(args, &err, args2);
- if (err)
+ if (!fun(args, &err, args2))
{
...
}
Chokes on hw/arm/musicpal.c's lcd_refresh() with the unhelpful error
message "no position information". Nothing to convert there; skipped.
Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
ARMSSE being used both as typedef and function-like macro there.
Converted manually.
A few line breaks tidied up manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Message-Id: <20200707160613.848843-5-armbru@redhat.com>
2020-07-07 18:05:32 +02:00
|
|
|
if (!qdev_realize(DEVICE(cpu), NULL, &err)) {
|
2017-09-13 18:04:53 +02:00
|
|
|
error_report_err(err);
|
|
|
|
object_unref(OBJECT(cpu));
|
2017-09-13 18:04:54 +02:00
|
|
|
exit(EXIT_FAILURE);
|
2017-09-13 18:04:53 +02:00
|
|
|
}
|
|
|
|
return cpu;
|
|
|
|
}
|
|
|
|
|
tcg: drop global lock during TCG code execution
This finally allows TCG to benefit from the iothread introduction: Drop
the global mutex while running pure TCG CPU code. Reacquire the lock
when entering MMIO or PIO emulation, or when leaving the TCG loop.
We have to revert a few optimization for the current TCG threading
model, namely kicking the TCG thread in qemu_mutex_lock_iothread and not
kicking it in qemu_cpu_kick. We also need to disable RAM block
reordering until we have a more efficient locking mechanism at hand.
Still, a Linux x86 UP guest and my Musicpal ARM model boot fine here.
These numbers demonstrate where we gain something:
20338 jan 20 0 331m 75m 6904 R 99 0.9 0:50.95 qemu-system-arm
20337 jan 20 0 331m 75m 6904 S 20 0.9 0:26.50 qemu-system-arm
The guest CPU was fully loaded, but the iothread could still run mostly
independent on a second core. Without the patch we don't get beyond
32206 jan 20 0 330m 73m 7036 R 82 0.9 1:06.00 qemu-system-arm
32204 jan 20 0 330m 73m 7036 S 21 0.9 0:17.03 qemu-system-arm
We don't benefit significantly, though, when the guest is not fully
loading a host CPU.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Message-Id: <1439220437-23957-10-git-send-email-fred.konrad@greensocs.com>
[FK: Rebase, fix qemu_devices_reset deadlock, rm address_space_* mutex]
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
[EGC: fixed iothread lock for cpu-exec IRQ handling]
Signed-off-by: Emilio G. Cota <cota@braap.org>
[AJB: -smp single-threaded fix, clean commit msg, BQL fixes]
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Reviewed-by: Pranith Kumar <bobby.prani@gmail.com>
[PM: target-arm changes]
Acked-by: Peter Maydell <peter.maydell@linaro.org>
2017-02-23 19:29:11 +01:00
|
|
|
/* Resetting the IRQ comes from across the code base so we take the
|
|
|
|
* BQL here if we need to. cpu_interrupt assumes it is held.*/
|
2013-01-17 22:30:20 +01:00
|
|
|
void cpu_reset_interrupt(CPUState *cpu, int mask)
|
|
|
|
{
|
tcg: drop global lock during TCG code execution
This finally allows TCG to benefit from the iothread introduction: Drop
the global mutex while running pure TCG CPU code. Reacquire the lock
when entering MMIO or PIO emulation, or when leaving the TCG loop.
We have to revert a few optimization for the current TCG threading
model, namely kicking the TCG thread in qemu_mutex_lock_iothread and not
kicking it in qemu_cpu_kick. We also need to disable RAM block
reordering until we have a more efficient locking mechanism at hand.
Still, a Linux x86 UP guest and my Musicpal ARM model boot fine here.
These numbers demonstrate where we gain something:
20338 jan 20 0 331m 75m 6904 R 99 0.9 0:50.95 qemu-system-arm
20337 jan 20 0 331m 75m 6904 S 20 0.9 0:26.50 qemu-system-arm
The guest CPU was fully loaded, but the iothread could still run mostly
independent on a second core. Without the patch we don't get beyond
32206 jan 20 0 330m 73m 7036 R 82 0.9 1:06.00 qemu-system-arm
32204 jan 20 0 330m 73m 7036 S 21 0.9 0:17.03 qemu-system-arm
We don't benefit significantly, though, when the guest is not fully
loading a host CPU.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Message-Id: <1439220437-23957-10-git-send-email-fred.konrad@greensocs.com>
[FK: Rebase, fix qemu_devices_reset deadlock, rm address_space_* mutex]
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
[EGC: fixed iothread lock for cpu-exec IRQ handling]
Signed-off-by: Emilio G. Cota <cota@braap.org>
[AJB: -smp single-threaded fix, clean commit msg, BQL fixes]
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Reviewed-by: Pranith Kumar <bobby.prani@gmail.com>
[PM: target-arm changes]
Acked-by: Peter Maydell <peter.maydell@linaro.org>
2017-02-23 19:29:11 +01:00
|
|
|
bool need_lock = !qemu_mutex_iothread_locked();
|
|
|
|
|
|
|
|
if (need_lock) {
|
|
|
|
qemu_mutex_lock_iothread();
|
|
|
|
}
|
2013-01-17 22:30:20 +01:00
|
|
|
cpu->interrupt_request &= ~mask;
|
tcg: drop global lock during TCG code execution
This finally allows TCG to benefit from the iothread introduction: Drop
the global mutex while running pure TCG CPU code. Reacquire the lock
when entering MMIO or PIO emulation, or when leaving the TCG loop.
We have to revert a few optimization for the current TCG threading
model, namely kicking the TCG thread in qemu_mutex_lock_iothread and not
kicking it in qemu_cpu_kick. We also need to disable RAM block
reordering until we have a more efficient locking mechanism at hand.
Still, a Linux x86 UP guest and my Musicpal ARM model boot fine here.
These numbers demonstrate where we gain something:
20338 jan 20 0 331m 75m 6904 R 99 0.9 0:50.95 qemu-system-arm
20337 jan 20 0 331m 75m 6904 S 20 0.9 0:26.50 qemu-system-arm
The guest CPU was fully loaded, but the iothread could still run mostly
independent on a second core. Without the patch we don't get beyond
32206 jan 20 0 330m 73m 7036 R 82 0.9 1:06.00 qemu-system-arm
32204 jan 20 0 330m 73m 7036 S 21 0.9 0:17.03 qemu-system-arm
We don't benefit significantly, though, when the guest is not fully
loading a host CPU.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Message-Id: <1439220437-23957-10-git-send-email-fred.konrad@greensocs.com>
[FK: Rebase, fix qemu_devices_reset deadlock, rm address_space_* mutex]
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
[EGC: fixed iothread lock for cpu-exec IRQ handling]
Signed-off-by: Emilio G. Cota <cota@braap.org>
[AJB: -smp single-threaded fix, clean commit msg, BQL fixes]
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Reviewed-by: Pranith Kumar <bobby.prani@gmail.com>
[PM: target-arm changes]
Acked-by: Peter Maydell <peter.maydell@linaro.org>
2017-02-23 19:29:11 +01:00
|
|
|
if (need_lock) {
|
|
|
|
qemu_mutex_unlock_iothread();
|
|
|
|
}
|
2013-01-17 22:30:20 +01:00
|
|
|
}
|
|
|
|
|
2013-05-17 18:26:54 +02:00
|
|
|
void cpu_exit(CPUState *cpu)
|
|
|
|
{
|
2020-09-23 12:56:46 +02:00
|
|
|
qatomic_set(&cpu->exit_request, 1);
|
2015-08-18 15:34:19 +02:00
|
|
|
/* Ensure cpu_exec will see the exit request after TCG has exited. */
|
|
|
|
smp_wmb();
|
2020-09-23 12:56:46 +02:00
|
|
|
qatomic_set(&cpu->icount_decr_ptr->u16.high, -1);
|
2013-05-17 18:26:54 +02:00
|
|
|
}
|
|
|
|
|
2020-03-16 18:21:41 +01:00
|
|
|
static int cpu_common_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg)
|
2013-06-29 04:18:45 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cpu_common_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-17 21:18:02 +02:00
|
|
|
void cpu_dump_state(CPUState *cpu, FILE *f, int flags)
|
2013-05-27 01:33:50 +02:00
|
|
|
{
|
|
|
|
CPUClass *cc = CPU_GET_CLASS(cpu);
|
|
|
|
|
|
|
|
if (cc->dump_state) {
|
2013-08-27 13:19:10 +02:00
|
|
|
cpu_synchronize_state(cpu);
|
2019-04-17 21:18:02 +02:00
|
|
|
cc->dump_state(cpu, f, flags);
|
2013-05-27 01:33:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-28 16:39:52 +01:00
|
|
|
void cpu_reset(CPUState *cpu)
|
|
|
|
{
|
cpu: Use DeviceClass reset instead of a special CPUClass reset
The CPUClass has a 'reset' method. This is a legacy from when
TYPE_CPU used not to inherit from TYPE_DEVICE. We don't need it any
more, as we can simply use the TYPE_DEVICE reset. The 'cpu_reset()'
function is kept as the API which most places use to reset a CPU; it
is now a wrapper which calls device_cold_reset() and then the
tracepoint function.
This change should not cause CPU objects to be reset more often
than they are at the moment, because:
* nobody is directly calling device_cold_reset() or
qdev_reset_all() on CPU objects
* no CPU object is on a qbus, so they will not be reset either
by somebody calling qbus_reset_all()/bus_cold_reset(), or
by the main "reset sysbus and everything in the qbus tree"
reset that most devices are reset by
Note that this does not change the need for each machine or whatever
to use qemu_register_reset() to arrange to call cpu_reset() -- that
is necessary because CPU objects are not on any qbus, so they don't
get reset when the qbus tree rooted at the sysbus bus is reset, and
this isn't being changed here.
All the changes to the files under target/ were made using the
included Coccinelle script, except:
(1) the deletion of the now-inaccurate and not terribly useful
"CPUClass::reset" comments was done with a perl one-liner afterwards:
perl -n -i -e '/ CPUClass::reset/ or print' target/*/*.c
(2) this bit of the s390 change was done by hand, because the
Coccinelle script is not sophisticated enough to handle the
parent_reset call being inside another function:
| @@ -96,8 +96,9 @@ static void s390_cpu_reset(CPUState *s, cpu_reset_type type)
| S390CPU *cpu = S390_CPU(s);
| S390CPUClass *scc = S390_CPU_GET_CLASS(cpu);
| CPUS390XState *env = &cpu->env;
|+ DeviceState *dev = DEVICE(s);
|
|- scc->parent_reset(s);
|+ scc->parent_reset(dev);
| cpu->env.sigp_order = 0;
| s390_cpu_set_state(S390_CPU_STATE_STOPPED, cpu);
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20200303100511.5498-1-peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2020-03-03 11:05:11 +01:00
|
|
|
device_cold_reset(DEVICE(cpu));
|
2016-09-19 14:55:18 +02:00
|
|
|
|
|
|
|
trace_guest_cpu_reset(cpu);
|
2012-01-28 16:39:52 +01:00
|
|
|
}
|
|
|
|
|
2022-11-24 12:50:04 +01:00
|
|
|
static void cpu_common_reset_hold(Object *obj)
|
2012-01-28 16:39:52 +01:00
|
|
|
{
|
2022-11-24 12:50:04 +01:00
|
|
|
CPUState *cpu = CPU(obj);
|
2013-06-16 07:49:48 +02:00
|
|
|
CPUClass *cc = CPU_GET_CLASS(cpu);
|
|
|
|
|
|
|
|
if (qemu_loglevel_mask(CPU_LOG_RESET)) {
|
|
|
|
qemu_log("CPU Reset (CPU %d)\n", cpu->cpu_index);
|
|
|
|
log_cpu_state(cpu, cc->reset_dump_flags);
|
|
|
|
}
|
|
|
|
|
2013-01-17 18:51:17 +01:00
|
|
|
cpu->interrupt_request = 0;
|
2020-08-26 07:55:29 +02:00
|
|
|
cpu->halted = cpu->start_powered_off;
|
2013-08-26 03:41:01 +02:00
|
|
|
cpu->mem_io_pc = 0;
|
2013-08-26 05:39:29 +02:00
|
|
|
cpu->icount_extra = 0;
|
2020-09-23 12:56:46 +02:00
|
|
|
qatomic_set(&cpu->icount_decr_ptr->u32, 0);
|
2015-06-24 14:16:26 +02:00
|
|
|
cpu->can_do_io = 1;
|
2014-12-19 12:53:13 +01:00
|
|
|
cpu->exception_index = -1;
|
2015-07-03 14:01:44 +02:00
|
|
|
cpu->crash_occurred = false;
|
2017-10-13 19:50:02 +02:00
|
|
|
cpu->cflags_next_tb = -1;
|
2016-09-30 23:30:58 +02:00
|
|
|
|
2017-01-12 16:02:50 +01:00
|
|
|
if (tcg_enabled()) {
|
2022-08-15 22:13:05 +02:00
|
|
|
tcg_flush_jmp_cache(cpu);
|
2017-06-26 07:22:55 +02:00
|
|
|
tcg_flush_softmmu_tlb(cpu);
|
2017-01-12 16:02:50 +01:00
|
|
|
}
|
2012-01-28 16:39:52 +01:00
|
|
|
}
|
|
|
|
|
2013-08-25 18:53:55 +02:00
|
|
|
static bool cpu_common_has_work(CPUState *cs)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-21 18:26:21 +01:00
|
|
|
ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model)
|
|
|
|
{
|
2018-02-07 15:30:57 +01:00
|
|
|
CPUClass *cc = CPU_CLASS(object_class_by_name(typename));
|
2013-01-21 18:26:21 +01:00
|
|
|
|
2018-02-07 15:30:57 +01:00
|
|
|
assert(cpu_model && cc->class_by_name);
|
2013-01-21 18:26:21 +01:00
|
|
|
return cc->class_by_name(cpu_model);
|
|
|
|
}
|
|
|
|
|
2016-06-09 19:11:01 +02:00
|
|
|
static void cpu_common_parse_features(const char *typename, char *features,
|
2014-03-03 23:33:51 +01:00
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
char *val;
|
2016-06-09 19:11:01 +02:00
|
|
|
static bool cpu_globals_initialized;
|
2018-02-07 11:40:26 +01:00
|
|
|
/* Single "key=value" string being parsed */
|
|
|
|
char *featurestr = features ? strtok(features, ",") : NULL;
|
2016-06-09 19:11:01 +02:00
|
|
|
|
2018-02-07 11:40:26 +01:00
|
|
|
/* should be called only once, catch invalid users */
|
|
|
|
assert(!cpu_globals_initialized);
|
2016-06-09 19:11:01 +02:00
|
|
|
cpu_globals_initialized = true;
|
2014-03-03 23:33:51 +01:00
|
|
|
|
|
|
|
while (featurestr) {
|
|
|
|
val = strchr(featurestr, '=');
|
|
|
|
if (val) {
|
2016-06-09 19:11:01 +02:00
|
|
|
GlobalProperty *prop = g_new0(typeof(*prop), 1);
|
2014-03-03 23:33:51 +01:00
|
|
|
*val = 0;
|
|
|
|
val++;
|
2016-06-09 19:11:01 +02:00
|
|
|
prop->driver = typename;
|
|
|
|
prop->property = g_strdup(featurestr);
|
|
|
|
prop->value = g_strdup(val);
|
|
|
|
qdev_prop_register_global(prop);
|
2014-03-03 23:33:51 +01:00
|
|
|
} else {
|
|
|
|
error_setg(errp, "Expected key=value format, found %s.",
|
|
|
|
featurestr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
featurestr = strtok(NULL, ",");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-19 06:17:06 +01:00
|
|
|
static void cpu_common_realizefn(DeviceState *dev, Error **errp)
|
|
|
|
{
|
2013-04-23 10:29:36 +02:00
|
|
|
CPUState *cpu = CPU(dev);
|
2017-09-07 14:54:54 +02:00
|
|
|
Object *machine = qdev_get_machine();
|
|
|
|
|
|
|
|
/* qdev_get_machine() can return something that's not TYPE_MACHINE
|
|
|
|
* if this is one of the user-only emulators; in that case there's
|
|
|
|
* no need to check the ignore_memory_transaction_failures board flag.
|
|
|
|
*/
|
|
|
|
if (object_dynamic_cast(machine, TYPE_MACHINE)) {
|
|
|
|
ObjectClass *oc = object_get_class(machine);
|
|
|
|
MachineClass *mc = MACHINE_CLASS(oc);
|
|
|
|
|
|
|
|
if (mc) {
|
|
|
|
cpu->ignore_memory_transaction_failures =
|
|
|
|
mc->ignore_memory_transaction_failures;
|
|
|
|
}
|
|
|
|
}
|
2013-04-23 10:29:36 +02:00
|
|
|
|
|
|
|
if (dev->hotplugged) {
|
|
|
|
cpu_synchronize_post_init(cpu);
|
2013-04-23 10:29:38 +02:00
|
|
|
cpu_resume(cpu);
|
2013-04-23 10:29:36 +02:00
|
|
|
}
|
2016-09-19 14:55:07 +02:00
|
|
|
|
|
|
|
/* NOTE: latest generic point where the cpu is fully realized */
|
|
|
|
trace_init_vcpu(cpu);
|
2013-01-19 06:17:06 +01:00
|
|
|
}
|
|
|
|
|
qdev: Unrealize must not fail
Devices may have component devices and buses.
Device realization may fail. Realization is recursive: a device's
realize() method realizes its components, and device_set_realized()
realizes its buses (which should in turn realize the devices on that
bus, except bus_set_realized() doesn't implement that, yet).
When realization of a component or bus fails, we need to roll back:
unrealize everything we realized so far. If any of these unrealizes
failed, the device would be left in an inconsistent state. Must not
happen.
device_set_realized() lets it happen: it ignores errors in the roll
back code starting at label child_realize_fail.
Since realization is recursive, unrealization must be recursive, too.
But how could a partly failed unrealize be rolled back? We'd have to
re-realize, which can fail. This design is fundamentally broken.
device_set_realized() does not roll back at all. Instead, it keeps
unrealizing, ignoring further errors.
It can screw up even for a device with no buses: if the lone
dc->unrealize() fails, it still unregisters vmstate, and calls
listeners' unrealize() callback.
bus_set_realized() does not roll back either. Instead, it stops
unrealizing.
Fortunately, no unrealize method can fail, as we'll see below.
To fix the design error, drop parameter @errp from all the unrealize
methods.
Any unrealize method that uses @errp now needs an update. This leads
us to unrealize() methods that can fail. Merely passing it to another
unrealize method cannot cause failure, though. Here are the ones that
do other things with @errp:
* virtio_serial_device_unrealize()
Fails when qbus_set_hotplug_handler() fails, but still does all the
other work. On failure, the device would stay realized with its
resources completely gone. Oops. Can't happen, because
qbus_set_hotplug_handler() can't actually fail here. Pass
&error_abort to qbus_set_hotplug_handler() instead.
* hw/ppc/spapr_drc.c's unrealize()
Fails when object_property_del() fails, but all the other work is
already done. On failure, the device would stay realized with its
vmstate registration gone. Oops. Can't happen, because
object_property_del() can't actually fail here. Pass &error_abort
to object_property_del() instead.
* spapr_phb_unrealize()
Fails and bails out when remove_drcs() fails, but other work is
already done. On failure, the device would stay realized with some
of its resources gone. Oops. remove_drcs() fails only when
chassis_from_bus()'s object_property_get_uint() fails, and it can't
here. Pass &error_abort to remove_drcs() instead.
Therefore, no unrealize method can fail before this patch.
device_set_realized()'s recursive unrealization via bus uses
object_property_set_bool(). Can't drop @errp there, so pass
&error_abort.
We similarly unrealize with object_property_set_bool() elsewhere,
always ignoring errors. Pass &error_abort instead.
Several unrealize methods no longer handle errors from other unrealize
methods: virtio_9p_device_unrealize(),
virtio_input_device_unrealize(), scsi_qdev_unrealize(), ...
Much of the deleted error handling looks wrong anyway.
One unrealize methods no longer ignore such errors:
usb_ehci_pci_exit().
Several realize methods no longer ignore errors when rolling back:
v9fs_device_realize_common(), pci_qdev_unrealize(),
spapr_phb_realize(), usb_qdev_realize(), vfio_ccw_realize(),
virtio_device_realize().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-17-armbru@redhat.com>
2020-05-05 17:29:24 +02:00
|
|
|
static void cpu_common_unrealizefn(DeviceState *dev)
|
2016-10-20 13:26:04 +02:00
|
|
|
{
|
|
|
|
CPUState *cpu = CPU(dev);
|
2021-02-04 17:39:11 +01:00
|
|
|
|
2016-12-26 22:24:40 +01:00
|
|
|
/* NOTE: latest generic point before the cpu is fully unrealized */
|
|
|
|
trace_fini_vcpu(cpu);
|
2016-10-20 13:26:04 +02:00
|
|
|
cpu_exec_unrealizefn(cpu);
|
|
|
|
}
|
|
|
|
|
2013-06-28 23:18:47 +02:00
|
|
|
static void cpu_common_initfn(Object *obj)
|
|
|
|
{
|
|
|
|
CPUState *cpu = CPU(obj);
|
|
|
|
CPUClass *cc = CPU_GET_CLASS(obj);
|
|
|
|
|
2016-07-25 11:59:21 +02:00
|
|
|
cpu->cpu_index = UNASSIGNED_CPU_INDEX;
|
2019-01-29 12:46:05 +01:00
|
|
|
cpu->cluster_index = UNASSIGNED_CLUSTER_INDEX;
|
2013-08-12 18:09:47 +02:00
|
|
|
cpu->gdb_num_regs = cpu->gdb_num_g_regs = cc->gdb_num_core_regs;
|
linux-user-i386: Fix crash on cpuid
Running cpuid instructions with a simple run like:
i386-linux-user/qemu-i386 tests/tcg/sha1-i386
Results in the following assert:
#0 0x00007ffff64246f5 in raise () from /lib64/libc.so.6
#1 0x00007ffff64262fa in abort () from /lib64/libc.so.6
#2 0x00007ffff7937ec5 in g_assertion_message () from /lib64/libglib-2.0.so.0
#3 0x00007ffff7937f5a in g_assertion_message_expr () from /lib64/libglib-2.0.so.0
#4 0x000055555561b54c in apicid_bitwidth_for_count (count=0) at /home/elmarco/src/qemu/include/hw/i386/topology.h:58
#5 0x000055555561b58a in apicid_smt_width (nr_cores=0, nr_threads=0) at /home/elmarco/src/qemu/include/hw/i386/topology.h:67
#6 0x000055555561b5c3 in apicid_core_offset (nr_cores=0, nr_threads=0) at /home/elmarco/src/qemu/include/hw/i386/topology.h:82
#7 0x000055555561b5e3 in apicid_pkg_offset (nr_cores=0, nr_threads=0) at /home/elmarco/src/qemu/include/hw/i386/topology.h:89
#8 0x000055555561dd86 in cpu_x86_cpuid (env=0x555557999550, index=4, count=3, eax=0x7fffffffcae8, ebx=0x7fffffffcaec, ecx=0x7fffffffcaf0, edx=0x7fffffffcaf4) at /home/elmarco/src/qemu/target-i386/cpu.c:2405
#9 0x0000555555638e8e in helper_cpuid (env=0x555557999550) at /home/elmarco/src/qemu/target-i386/misc_helper.c:106
#10 0x000055555599dc5e in static_code_gen_buffer ()
#11 0x00005555555952f8 in cpu_tb_exec (cpu=0x5555579912d0, itb=0x7ffff4371ab0) at /home/elmarco/src/qemu/cpu-exec.c:166
#12 0x0000555555595c8e in cpu_loop_exec_tb (cpu=0x5555579912d0, tb=0x7ffff4371ab0, last_tb=0x7fffffffd088, tb_exit=0x7fffffffd084, sc=0x7fffffffd0a0) at /home/elmarco/src/qemu/cpu-exec.c:517
#13 0x0000555555595e50 in cpu_exec (cpu=0x5555579912d0) at /home/elmarco/src/qemu/cpu-exec.c:612
#14 0x00005555555c065b in cpu_loop (env=0x555557999550) at /home/elmarco/src/qemu/linux-user/main.c:297
#15 0x00005555555c25b2 in main (argc=2, argv=0x7fffffffd848, envp=0x7fffffffd860) at /home/elmarco/src/qemu/linux-user/main.c:4803
The fields are set in qemu_init_vcpu() with softmmu, but it's a stub
with linux-user.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2016-09-16 17:50:23 +02:00
|
|
|
/* *-user doesn't have configurable SMP topology */
|
|
|
|
/* the default value is changed by qemu_init_vcpu() for softmmu */
|
|
|
|
cpu->nr_cores = 1;
|
|
|
|
cpu->nr_threads = 1;
|
2022-10-19 12:33:28 +02:00
|
|
|
cpu->cflags_next_tb = -1;
|
linux-user-i386: Fix crash on cpuid
Running cpuid instructions with a simple run like:
i386-linux-user/qemu-i386 tests/tcg/sha1-i386
Results in the following assert:
#0 0x00007ffff64246f5 in raise () from /lib64/libc.so.6
#1 0x00007ffff64262fa in abort () from /lib64/libc.so.6
#2 0x00007ffff7937ec5 in g_assertion_message () from /lib64/libglib-2.0.so.0
#3 0x00007ffff7937f5a in g_assertion_message_expr () from /lib64/libglib-2.0.so.0
#4 0x000055555561b54c in apicid_bitwidth_for_count (count=0) at /home/elmarco/src/qemu/include/hw/i386/topology.h:58
#5 0x000055555561b58a in apicid_smt_width (nr_cores=0, nr_threads=0) at /home/elmarco/src/qemu/include/hw/i386/topology.h:67
#6 0x000055555561b5c3 in apicid_core_offset (nr_cores=0, nr_threads=0) at /home/elmarco/src/qemu/include/hw/i386/topology.h:82
#7 0x000055555561b5e3 in apicid_pkg_offset (nr_cores=0, nr_threads=0) at /home/elmarco/src/qemu/include/hw/i386/topology.h:89
#8 0x000055555561dd86 in cpu_x86_cpuid (env=0x555557999550, index=4, count=3, eax=0x7fffffffcae8, ebx=0x7fffffffcaec, ecx=0x7fffffffcaf0, edx=0x7fffffffcaf4) at /home/elmarco/src/qemu/target-i386/cpu.c:2405
#9 0x0000555555638e8e in helper_cpuid (env=0x555557999550) at /home/elmarco/src/qemu/target-i386/misc_helper.c:106
#10 0x000055555599dc5e in static_code_gen_buffer ()
#11 0x00005555555952f8 in cpu_tb_exec (cpu=0x5555579912d0, itb=0x7ffff4371ab0) at /home/elmarco/src/qemu/cpu-exec.c:166
#12 0x0000555555595c8e in cpu_loop_exec_tb (cpu=0x5555579912d0, tb=0x7ffff4371ab0, last_tb=0x7fffffffd088, tb_exit=0x7fffffffd084, sc=0x7fffffffd0a0) at /home/elmarco/src/qemu/cpu-exec.c:517
#13 0x0000555555595e50 in cpu_exec (cpu=0x5555579912d0) at /home/elmarco/src/qemu/cpu-exec.c:612
#14 0x00005555555c065b in cpu_loop (env=0x555557999550) at /home/elmarco/src/qemu/linux-user/main.c:297
#15 0x00005555555c25b2 in main (argc=2, argv=0x7fffffffd848, envp=0x7fffffffd860) at /home/elmarco/src/qemu/linux-user/main.c:4803
The fields are set in qemu_init_vcpu() with softmmu, but it's a stub
with linux-user.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2016-09-16 17:50:23 +02:00
|
|
|
|
2015-07-10 12:32:32 +02:00
|
|
|
qemu_mutex_init(&cpu->work_mutex);
|
2022-11-11 16:47:56 +01:00
|
|
|
qemu_lockcnt_init(&cpu->in_ioctl_lock);
|
2020-06-12 21:02:24 +02:00
|
|
|
QSIMPLEQ_INIT(&cpu->work_list);
|
2015-04-27 22:00:32 +02:00
|
|
|
QTAILQ_INIT(&cpu->breakpoints);
|
|
|
|
QTAILQ_INIT(&cpu->watchpoints);
|
2016-10-04 15:35:53 +02:00
|
|
|
|
2016-10-20 13:26:02 +02:00
|
|
|
cpu_exec_initfn(cpu);
|
2013-06-28 23:18:47 +02:00
|
|
|
}
|
|
|
|
|
2015-06-24 04:31:13 +02:00
|
|
|
static void cpu_common_finalize(Object *obj)
|
|
|
|
{
|
2019-01-02 08:41:14 +01:00
|
|
|
CPUState *cpu = CPU(obj);
|
|
|
|
|
2022-11-11 16:47:56 +01:00
|
|
|
qemu_lockcnt_destroy(&cpu->in_ioctl_lock);
|
2019-01-02 08:41:14 +01:00
|
|
|
qemu_mutex_destroy(&cpu->work_mutex);
|
2015-06-24 04:31:13 +02:00
|
|
|
}
|
|
|
|
|
2013-04-23 10:29:41 +02:00
|
|
|
static int64_t cpu_common_get_arch_id(CPUState *cpu)
|
|
|
|
{
|
|
|
|
return cpu->cpu_index;
|
|
|
|
}
|
|
|
|
|
2012-01-28 16:39:52 +01:00
|
|
|
static void cpu_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2012-12-05 17:49:13 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2022-11-24 12:50:04 +01:00
|
|
|
ResettableClass *rc = RESETTABLE_CLASS(klass);
|
2012-01-28 16:39:52 +01:00
|
|
|
CPUClass *k = CPU_CLASS(klass);
|
|
|
|
|
2014-03-03 23:33:51 +01:00
|
|
|
k->parse_features = cpu_common_parse_features;
|
2013-04-23 10:29:41 +02:00
|
|
|
k->get_arch_id = cpu_common_get_arch_id;
|
2013-08-25 18:53:55 +02:00
|
|
|
k->has_work = cpu_common_has_work;
|
2013-06-29 04:18:45 +02:00
|
|
|
k->gdb_read_register = cpu_common_gdb_read_register;
|
|
|
|
k->gdb_write_register = cpu_common_gdb_write_register;
|
2017-01-20 14:01:16 +01:00
|
|
|
set_bit(DEVICE_CATEGORY_CPU, dc->categories);
|
2013-01-19 06:17:06 +01:00
|
|
|
dc->realize = cpu_common_realizefn;
|
2016-10-20 13:26:04 +02:00
|
|
|
dc->unrealize = cpu_common_unrealizefn;
|
2022-11-24 12:50:04 +01:00
|
|
|
rc->phases.hold = cpu_common_reset_hold;
|
2021-08-22 09:25:28 +02:00
|
|
|
cpu_class_init_props(dc);
|
2013-11-28 17:26:56 +01:00
|
|
|
/*
|
|
|
|
* Reason: CPUs still need special care by board code: wiring up
|
|
|
|
* IRQs, adding reset handlers, halting non-first CPUs, ...
|
|
|
|
*/
|
2017-05-03 22:35:44 +02:00
|
|
|
dc->user_creatable = false;
|
2012-01-28 16:39:52 +01:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:49:13 +01:00
|
|
|
static const TypeInfo cpu_type_info = {
|
2012-01-28 16:39:52 +01:00
|
|
|
.name = TYPE_CPU,
|
2012-12-05 17:49:13 +01:00
|
|
|
.parent = TYPE_DEVICE,
|
2012-01-28 16:39:52 +01:00
|
|
|
.instance_size = sizeof(CPUState),
|
2013-06-28 23:18:47 +02:00
|
|
|
.instance_init = cpu_common_initfn,
|
2015-06-24 04:31:13 +02:00
|
|
|
.instance_finalize = cpu_common_finalize,
|
2012-01-28 16:39:52 +01:00
|
|
|
.abstract = true,
|
|
|
|
.class_size = sizeof(CPUClass),
|
|
|
|
.class_init = cpu_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void cpu_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&cpu_type_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(cpu_register_types)
|