mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
Merge remote-tracking branch 'remotes/bonzini-gitlab/tags/for-upstream' into staging
* qtest documentation improvements (Eduardo, myself) * libqtest event buffering (Maxim) * use RCU for list of children of a bus (Maxim) * move more files to softmmu/ (myself) * meson.build cleanups, qemu-storage-daemon fix (Philippe) # gpg: Signature made Mon 12 Oct 2020 16:55:19 BST # gpg: using RSA key F13338574B662389866C7682BFFBD25F78C7AE83 # gpg: issuer "pbonzini@redhat.com" # gpg: Good signature from "Paolo Bonzini <bonzini@gnu.org>" [full] # gpg: aka "Paolo Bonzini <pbonzini@redhat.com>" [full] # 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-gitlab/tags/for-upstream: (38 commits) meson: identify more sections of meson.build scsi/scsi_bus: fix races in REPORT LUNS virtio-scsi: use scsi_device_get scsi/scsi_bus: Add scsi_device_get scsi/scsi-bus: scsi_device_find: don't return unrealized devices device-core: use atomic_set on .realized property scsi: switch to bus->check_address device-core: use RCU for list of children of a bus device_core: use drain_call_rcu in in qmp_device_add scsi/scsi_bus: switch search direction in scsi_device_find qdev: add "check if address free" callback for buses qemu-iotests, qtest: rewrite test 067 as a qtest qtest: check that drives are really appearing and disappearing qtest: switch users back to qtest_qmp_receive device-plug-test: use qtest_qmp to send the device_del command qtest: remove qtest_qmp_receive_success qtest: Reintroduce qtest_qmp_receive with QMP event buffering qtest: rename qtest_qmp_receive to qtest_qmp_receive_dict meson.build: Re-enable KVM support for MIPS build-sys: fix git version from -version ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
+1
-1
@@ -232,7 +232,7 @@ build-tcg-disabled:
|
||||
- ./check -raw 001 002 003 004 005 008 009 010 011 012 021 025 032 033 048
|
||||
052 063 077 086 101 104 106 113 148 150 151 152 157 159 160 163
|
||||
170 171 183 184 192 194 197 208 215 221 222 226 227 236 253 277
|
||||
- ./check -qcow2 028 051 056 057 058 065 067 068 082 085 091 095 096 102 122
|
||||
- ./check -qcow2 028 051 056 057 058 065 068 082 085 091 095 096 102 122
|
||||
124 132 139 142 144 145 151 152 155 157 165 194 196 197 200 202
|
||||
208 209 215 216 218 222 227 234 246 247 248 250 254 255 257 258
|
||||
260 261 262 263 264 270 272 273 277 279
|
||||
|
||||
+9
-7
@@ -117,7 +117,6 @@ R: Paolo Bonzini <pbonzini@redhat.com>
|
||||
S: Maintained
|
||||
F: softmmu/cpus.c
|
||||
F: cpus-common.c
|
||||
F: exec.c
|
||||
F: accel/tcg/
|
||||
F: accel/stubs/tcg-stub.c
|
||||
F: scripts/decodetree.py
|
||||
@@ -1525,6 +1524,7 @@ Machine core
|
||||
M: Eduardo Habkost <ehabkost@redhat.com>
|
||||
M: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
|
||||
S: Supported
|
||||
F: cpu.c
|
||||
F: hw/core/cpu.c
|
||||
F: hw/core/machine-qmp-cmds.c
|
||||
F: hw/core/machine.c
|
||||
@@ -2055,7 +2055,7 @@ R: Laszlo Ersek <lersek@redhat.com>
|
||||
R: Gerd Hoffmann <kraxel@redhat.com>
|
||||
S: Supported
|
||||
F: docs/specs/fw_cfg.txt
|
||||
F: hw/nvram/fw_cfg.c
|
||||
F: hw/nvram/fw_cfg*.c
|
||||
F: stubs/fw_cfg.c
|
||||
F: include/hw/nvram/fw_cfg.h
|
||||
F: include/standard-headers/linux/qemu_fw_cfg.h
|
||||
@@ -2235,7 +2235,7 @@ Device Tree
|
||||
M: Alistair Francis <alistair.francis@wdc.com>
|
||||
R: David Gibson <david@gibson.dropbear.id.au>
|
||||
S: Maintained
|
||||
F: device_tree.c
|
||||
F: softmmu/device_tree.c
|
||||
F: include/sysemu/device_tree.h
|
||||
|
||||
Dump
|
||||
@@ -2281,10 +2281,11 @@ F: include/exec/memop.h
|
||||
F: include/exec/memory.h
|
||||
F: include/exec/ram_addr.h
|
||||
F: include/exec/ramblock.h
|
||||
F: softmmu/dma-helpers.c
|
||||
F: softmmu/ioport.c
|
||||
F: softmmu/memory.c
|
||||
F: softmmu/physmem.c
|
||||
F: include/exec/memory-internal.h
|
||||
F: exec.c
|
||||
F: scripts/coccinelle/memory-region-housekeeping.cocci
|
||||
|
||||
SPICE
|
||||
@@ -2461,7 +2462,8 @@ F: include/monitor/qdev.h
|
||||
F: include/qom/
|
||||
F: qapi/qom.json
|
||||
F: qapi/qdev.json
|
||||
F: qdev-monitor.c
|
||||
F: scripts/coccinelle/qom-parent-type.cocci
|
||||
F: softmmu/qdev-monitor.c
|
||||
F: qom/
|
||||
F: tests/check-qom-interface.c
|
||||
F: tests/check-qom-proplist.c
|
||||
@@ -2591,7 +2593,7 @@ F: docs/interop/dbus-vmstate.rst
|
||||
Seccomp
|
||||
M: Eduardo Otubo <otubo@redhat.com>
|
||||
S: Supported
|
||||
F: qemu-seccomp.c
|
||||
F: softmmu/qemu-seccomp.c
|
||||
F: include/sysemu/seccomp.h
|
||||
|
||||
Cryptography
|
||||
@@ -2957,7 +2959,7 @@ T: git https://github.com/stefanha/qemu.git block
|
||||
Bootdevice
|
||||
M: Gonglei <arei.gonglei@huawei.com>
|
||||
S: Maintained
|
||||
F: bootdevice.c
|
||||
F: softmmu/bootdevice.c
|
||||
|
||||
Quorum
|
||||
M: Alberto Garcia <berto@igalia.com>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
authz_ss = ss.source_set()
|
||||
authz_ss.add(genh)
|
||||
authz_ss.add(files(
|
||||
'base.c',
|
||||
@@ -8,12 +7,3 @@ authz_ss.add(files(
|
||||
))
|
||||
|
||||
authz_ss.add(when: ['CONFIG_AUTH_PAM', pam], if_true: files('pamacct.c'))
|
||||
|
||||
authz_ss = authz_ss.apply(config_host, strict: false)
|
||||
libauthz = static_library('authz', authz_ss.sources() + genh,
|
||||
dependencies: [authz_ss.dependencies()],
|
||||
name_suffix: 'fa',
|
||||
build_by_default: false)
|
||||
|
||||
authz = declare_dependency(link_whole: libauthz,
|
||||
dependencies: qom)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
chardev_ss = ss.source_set()
|
||||
chardev_ss.add(files(
|
||||
'char-fe.c',
|
||||
'char-file.c',
|
||||
@@ -25,11 +24,6 @@ chardev_ss.add(when: 'CONFIG_WIN32', if_true: files(
|
||||
))
|
||||
|
||||
chardev_ss = chardev_ss.apply(config_host, strict: false)
|
||||
libchardev = static_library('chardev', chardev_ss.sources() + genh,
|
||||
name_suffix: 'fa',
|
||||
build_by_default: false)
|
||||
|
||||
chardev = declare_dependency(link_whole: libchardev)
|
||||
|
||||
softmmu_ss.add(files('chardev-sysemu.c', 'msmouse.c', 'wctablet.c', 'testdev.c'))
|
||||
softmmu_ss.add(when: ['CONFIG_SPICE', spice], if_true: files('spice.c'))
|
||||
|
||||
@@ -0,0 +1,452 @@
|
||||
/*
|
||||
* Target-specific parts of the CPU object
|
||||
*
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu-common.h"
|
||||
#include "qapi/error.h"
|
||||
|
||||
#include "exec/target_page.h"
|
||||
#include "hw/qdev-core.h"
|
||||
#include "hw/qdev-properties.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "migration/vmstate.h"
|
||||
#ifdef CONFIG_USER_ONLY
|
||||
#include "qemu.h"
|
||||
#else
|
||||
#include "exec/address-spaces.h"
|
||||
#endif
|
||||
#include "sysemu/tcg.h"
|
||||
#include "sysemu/kvm.h"
|
||||
#include "sysemu/replay.h"
|
||||
#include "translate-all.h"
|
||||
#include "exec/log.h"
|
||||
|
||||
uintptr_t qemu_host_page_size;
|
||||
intptr_t qemu_host_page_mask;
|
||||
|
||||
#ifndef CONFIG_USER_ONLY
|
||||
static int cpu_common_post_load(void *opaque, int version_id)
|
||||
{
|
||||
CPUState *cpu = opaque;
|
||||
|
||||
/* 0x01 was CPU_INTERRUPT_EXIT. This line can be removed when the
|
||||
version_id is increased. */
|
||||
cpu->interrupt_request &= ~0x01;
|
||||
tlb_flush(cpu);
|
||||
|
||||
/* loadvm has just updated the content of RAM, bypassing the
|
||||
* usual mechanisms that ensure we flush TBs for writes to
|
||||
* memory we've translated code from. So we must flush all TBs,
|
||||
* which will now be stale.
|
||||
*/
|
||||
tb_flush(cpu);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cpu_common_pre_load(void *opaque)
|
||||
{
|
||||
CPUState *cpu = opaque;
|
||||
|
||||
cpu->exception_index = -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool cpu_common_exception_index_needed(void *opaque)
|
||||
{
|
||||
CPUState *cpu = opaque;
|
||||
|
||||
return tcg_enabled() && cpu->exception_index != -1;
|
||||
}
|
||||
|
||||
static const VMStateDescription vmstate_cpu_common_exception_index = {
|
||||
.name = "cpu_common/exception_index",
|
||||
.version_id = 1,
|
||||
.minimum_version_id = 1,
|
||||
.needed = cpu_common_exception_index_needed,
|
||||
.fields = (VMStateField[]) {
|
||||
VMSTATE_INT32(exception_index, CPUState),
|
||||
VMSTATE_END_OF_LIST()
|
||||
}
|
||||
};
|
||||
|
||||
static bool cpu_common_crash_occurred_needed(void *opaque)
|
||||
{
|
||||
CPUState *cpu = opaque;
|
||||
|
||||
return cpu->crash_occurred;
|
||||
}
|
||||
|
||||
static const VMStateDescription vmstate_cpu_common_crash_occurred = {
|
||||
.name = "cpu_common/crash_occurred",
|
||||
.version_id = 1,
|
||||
.minimum_version_id = 1,
|
||||
.needed = cpu_common_crash_occurred_needed,
|
||||
.fields = (VMStateField[]) {
|
||||
VMSTATE_BOOL(crash_occurred, CPUState),
|
||||
VMSTATE_END_OF_LIST()
|
||||
}
|
||||
};
|
||||
|
||||
const VMStateDescription vmstate_cpu_common = {
|
||||
.name = "cpu_common",
|
||||
.version_id = 1,
|
||||
.minimum_version_id = 1,
|
||||
.pre_load = cpu_common_pre_load,
|
||||
.post_load = cpu_common_post_load,
|
||||
.fields = (VMStateField[]) {
|
||||
VMSTATE_UINT32(halted, CPUState),
|
||||
VMSTATE_UINT32(interrupt_request, CPUState),
|
||||
VMSTATE_END_OF_LIST()
|
||||
},
|
||||
.subsections = (const VMStateDescription*[]) {
|
||||
&vmstate_cpu_common_exception_index,
|
||||
&vmstate_cpu_common_crash_occurred,
|
||||
NULL
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
void cpu_exec_unrealizefn(CPUState *cpu)
|
||||
{
|
||||
CPUClass *cc = CPU_GET_CLASS(cpu);
|
||||
|
||||
tlb_destroy(cpu);
|
||||
cpu_list_remove(cpu);
|
||||
|
||||
#ifdef CONFIG_USER_ONLY
|
||||
assert(cc->vmsd == NULL);
|
||||
#else
|
||||
if (cc->vmsd != NULL) {
|
||||
vmstate_unregister(NULL, cc->vmsd, cpu);
|
||||
}
|
||||
if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
|
||||
vmstate_unregister(NULL, &vmstate_cpu_common, cpu);
|
||||
}
|
||||
tcg_iommu_free_notifier_list(cpu);
|
||||
#endif
|
||||
}
|
||||
|
||||
Property cpu_common_props[] = {
|
||||
#ifndef CONFIG_USER_ONLY
|
||||
/* Create a memory property for softmmu CPU object,
|
||||
* so users can wire up its memory. (This can't go in hw/core/cpu.c
|
||||
* because that file is compiled only once for both user-mode
|
||||
* and system builds.) The default if no link is set up is to use
|
||||
* the system address space.
|
||||
*/
|
||||
DEFINE_PROP_LINK("memory", CPUState, memory, TYPE_MEMORY_REGION,
|
||||
MemoryRegion *),
|
||||
#endif
|
||||
DEFINE_PROP_BOOL("start-powered-off", CPUState, start_powered_off, false),
|
||||
DEFINE_PROP_END_OF_LIST(),
|
||||
};
|
||||
|
||||
void cpu_exec_initfn(CPUState *cpu)
|
||||
{
|
||||
cpu->as = NULL;
|
||||
cpu->num_ases = 0;
|
||||
|
||||
#ifndef CONFIG_USER_ONLY
|
||||
cpu->thread_id = qemu_get_thread_id();
|
||||
cpu->memory = get_system_memory();
|
||||
object_ref(OBJECT(cpu->memory));
|
||||
#endif
|
||||
}
|
||||
|
||||
void cpu_exec_realizefn(CPUState *cpu, Error **errp)
|
||||
{
|
||||
CPUClass *cc = CPU_GET_CLASS(cpu);
|
||||
static bool tcg_target_initialized;
|
||||
|
||||
cpu_list_add(cpu);
|
||||
|
||||
if (tcg_enabled() && !tcg_target_initialized) {
|
||||
tcg_target_initialized = true;
|
||||
cc->tcg_initialize();
|
||||
}
|
||||
tlb_init(cpu);
|
||||
|
||||
qemu_plugin_vcpu_init_hook(cpu);
|
||||
|
||||
#ifdef CONFIG_USER_ONLY
|
||||
assert(cc->vmsd == NULL);
|
||||
#else /* !CONFIG_USER_ONLY */
|
||||
if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
|
||||
vmstate_register(NULL, cpu->cpu_index, &vmstate_cpu_common, cpu);
|
||||
}
|
||||
if (cc->vmsd != NULL) {
|
||||
vmstate_register(NULL, cpu->cpu_index, cc->vmsd, cpu);
|
||||
}
|
||||
|
||||
tcg_iommu_init_notifier_list(cpu);
|
||||
#endif
|
||||
}
|
||||
|
||||
const char *parse_cpu_option(const char *cpu_option)
|
||||
{
|
||||
ObjectClass *oc;
|
||||
CPUClass *cc;
|
||||
gchar **model_pieces;
|
||||
const char *cpu_type;
|
||||
|
||||
model_pieces = g_strsplit(cpu_option, ",", 2);
|
||||
if (!model_pieces[0]) {
|
||||
error_report("-cpu option cannot be empty");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
oc = cpu_class_by_name(CPU_RESOLVING_TYPE, model_pieces[0]);
|
||||
if (oc == NULL) {
|
||||
error_report("unable to find CPU model '%s'", model_pieces[0]);
|
||||
g_strfreev(model_pieces);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
cpu_type = object_class_get_name(oc);
|
||||
cc = CPU_CLASS(oc);
|
||||
cc->parse_features(cpu_type, model_pieces[1], &error_fatal);
|
||||
g_strfreev(model_pieces);
|
||||
return cpu_type;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_USER_ONLY)
|
||||
void tb_invalidate_phys_addr(target_ulong addr)
|
||||
{
|
||||
mmap_lock();
|
||||
tb_invalidate_phys_page_range(addr, addr + 1);
|
||||
mmap_unlock();
|
||||
}
|
||||
|
||||
static void breakpoint_invalidate(CPUState *cpu, target_ulong pc)
|
||||
{
|
||||
tb_invalidate_phys_addr(pc);
|
||||
}
|
||||
#else
|
||||
void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs)
|
||||
{
|
||||
ram_addr_t ram_addr;
|
||||
MemoryRegion *mr;
|
||||
hwaddr l = 1;
|
||||
|
||||
if (!tcg_enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
RCU_READ_LOCK_GUARD();
|
||||
mr = address_space_translate(as, addr, &addr, &l, false, attrs);
|
||||
if (!(memory_region_is_ram(mr)
|
||||
|| memory_region_is_romd(mr))) {
|
||||
return;
|
||||
}
|
||||
ram_addr = memory_region_get_ram_addr(mr) + addr;
|
||||
tb_invalidate_phys_page_range(ram_addr, ram_addr + 1);
|
||||
}
|
||||
|
||||
static void breakpoint_invalidate(CPUState *cpu, target_ulong pc)
|
||||
{
|
||||
/*
|
||||
* There may not be a virtual to physical translation for the pc
|
||||
* right now, but there may exist cached TB for this pc.
|
||||
* Flush the whole TB cache to force re-translation of such TBs.
|
||||
* This is heavyweight, but we're debugging anyway.
|
||||
*/
|
||||
tb_flush(cpu);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Add a breakpoint. */
|
||||
int cpu_breakpoint_insert(CPUState *cpu, vaddr pc, int flags,
|
||||
CPUBreakpoint **breakpoint)
|
||||
{
|
||||
CPUBreakpoint *bp;
|
||||
|
||||
bp = g_malloc(sizeof(*bp));
|
||||
|
||||
bp->pc = pc;
|
||||
bp->flags = flags;
|
||||
|
||||
/* keep all GDB-injected breakpoints in front */
|
||||
if (flags & BP_GDB) {
|
||||
QTAILQ_INSERT_HEAD(&cpu->breakpoints, bp, entry);
|
||||
} else {
|
||||
QTAILQ_INSERT_TAIL(&cpu->breakpoints, bp, entry);
|
||||
}
|
||||
|
||||
breakpoint_invalidate(cpu, pc);
|
||||
|
||||
if (breakpoint) {
|
||||
*breakpoint = bp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Remove a specific breakpoint. */
|
||||
int cpu_breakpoint_remove(CPUState *cpu, vaddr pc, int flags)
|
||||
{
|
||||
CPUBreakpoint *bp;
|
||||
|
||||
QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) {
|
||||
if (bp->pc == pc && bp->flags == flags) {
|
||||
cpu_breakpoint_remove_by_ref(cpu, bp);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/* Remove a specific breakpoint by reference. */
|
||||
void cpu_breakpoint_remove_by_ref(CPUState *cpu, CPUBreakpoint *breakpoint)
|
||||
{
|
||||
QTAILQ_REMOVE(&cpu->breakpoints, breakpoint, entry);
|
||||
|
||||
breakpoint_invalidate(cpu, breakpoint->pc);
|
||||
|
||||
g_free(breakpoint);
|
||||
}
|
||||
|
||||
/* Remove all matching breakpoints. */
|
||||
void cpu_breakpoint_remove_all(CPUState *cpu, int mask)
|
||||
{
|
||||
CPUBreakpoint *bp, *next;
|
||||
|
||||
QTAILQ_FOREACH_SAFE(bp, &cpu->breakpoints, entry, next) {
|
||||
if (bp->flags & mask) {
|
||||
cpu_breakpoint_remove_by_ref(cpu, bp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* enable or disable single step mode. EXCP_DEBUG is returned by the
|
||||
CPU loop after each instruction */
|
||||
void cpu_single_step(CPUState *cpu, int enabled)
|
||||
{
|
||||
if (cpu->singlestep_enabled != enabled) {
|
||||
cpu->singlestep_enabled = enabled;
|
||||
if (kvm_enabled()) {
|
||||
kvm_update_guest_debug(cpu, 0);
|
||||
} else {
|
||||
/* must flush all the translated code to avoid inconsistencies */
|
||||
/* XXX: only flush what is necessary */
|
||||
tb_flush(cpu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cpu_abort(CPUState *cpu, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_list ap2;
|
||||
|
||||
va_start(ap, fmt);
|
||||
va_copy(ap2, ap);
|
||||
fprintf(stderr, "qemu: fatal: ");
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fprintf(stderr, "\n");
|
||||
cpu_dump_state(cpu, stderr, CPU_DUMP_FPU | CPU_DUMP_CCOP);
|
||||
if (qemu_log_separate()) {
|
||||
FILE *logfile = qemu_log_lock();
|
||||
qemu_log("qemu: fatal: ");
|
||||
qemu_log_vprintf(fmt, ap2);
|
||||
qemu_log("\n");
|
||||
log_cpu_state(cpu, CPU_DUMP_FPU | CPU_DUMP_CCOP);
|
||||
qemu_log_flush();
|
||||
qemu_log_unlock(logfile);
|
||||
qemu_log_close();
|
||||
}
|
||||
va_end(ap2);
|
||||
va_end(ap);
|
||||
replay_finish();
|
||||
#if defined(CONFIG_USER_ONLY)
|
||||
{
|
||||
struct sigaction act;
|
||||
sigfillset(&act.sa_mask);
|
||||
act.sa_handler = SIG_DFL;
|
||||
act.sa_flags = 0;
|
||||
sigaction(SIGABRT, &act, NULL);
|
||||
}
|
||||
#endif
|
||||
abort();
|
||||
}
|
||||
|
||||
/* physical memory access (slow version, mainly for debug) */
|
||||
#if defined(CONFIG_USER_ONLY)
|
||||
int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
|
||||
void *ptr, target_ulong len, bool is_write)
|
||||
{
|
||||
int flags;
|
||||
target_ulong l, page;
|
||||
void * p;
|
||||
uint8_t *buf = ptr;
|
||||
|
||||
while (len > 0) {
|
||||
page = addr & TARGET_PAGE_MASK;
|
||||
l = (page + TARGET_PAGE_SIZE) - addr;
|
||||
if (l > len)
|
||||
l = len;
|
||||
flags = page_get_flags(page);
|
||||
if (!(flags & PAGE_VALID))
|
||||
return -1;
|
||||
if (is_write) {
|
||||
if (!(flags & PAGE_WRITE))
|
||||
return -1;
|
||||
/* XXX: this code should not depend on lock_user */
|
||||
if (!(p = lock_user(VERIFY_WRITE, addr, l, 0)))
|
||||
return -1;
|
||||
memcpy(p, buf, l);
|
||||
unlock_user(p, addr, l);
|
||||
} else {
|
||||
if (!(flags & PAGE_READ))
|
||||
return -1;
|
||||
/* XXX: this code should not depend on lock_user */
|
||||
if (!(p = lock_user(VERIFY_READ, addr, l, 1)))
|
||||
return -1;
|
||||
memcpy(buf, p, l);
|
||||
unlock_user(p, addr, 0);
|
||||
}
|
||||
len -= l;
|
||||
buf += l;
|
||||
addr += l;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool target_words_bigendian(void)
|
||||
{
|
||||
#if defined(TARGET_WORDS_BIGENDIAN)
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void page_size_init(void)
|
||||
{
|
||||
/* NOTE: we can always suppose that qemu_host_page_size >=
|
||||
TARGET_PAGE_SIZE */
|
||||
if (qemu_host_page_size == 0) {
|
||||
qemu_host_page_size = qemu_real_host_page_size;
|
||||
}
|
||||
if (qemu_host_page_size < TARGET_PAGE_SIZE) {
|
||||
qemu_host_page_size = TARGET_PAGE_SIZE;
|
||||
}
|
||||
qemu_host_page_mask = -(intptr_t)qemu_host_page_size;
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
crypto_ss = ss.source_set()
|
||||
crypto_ss.add(genh)
|
||||
crypto_ss.add(files(
|
||||
'afsplit.c',
|
||||
@@ -52,15 +51,6 @@ if 'CONFIG_GNUTLS' in config_host
|
||||
endif
|
||||
|
||||
|
||||
crypto_ss = crypto_ss.apply(config_host, strict: false)
|
||||
libcrypto = static_library('crypto', crypto_ss.sources() + genh,
|
||||
dependencies: [crypto_ss.dependencies()],
|
||||
name_suffix: 'fa',
|
||||
build_by_default: false)
|
||||
|
||||
crypto = declare_dependency(link_whole: libcrypto,
|
||||
dependencies: [authz, qom])
|
||||
|
||||
util_ss.add(files('aes.c'))
|
||||
util_ss.add(files('init.c'))
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ Contents:
|
||||
atomics
|
||||
stable-process
|
||||
testing
|
||||
qtest
|
||||
decodetree
|
||||
secure-coding-practices
|
||||
tcg
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
========================================
|
||||
QTest Device Emulation Testing Framework
|
||||
========================================
|
||||
|
||||
QTest is a device emulation testing framework. It can be very useful to test
|
||||
device models; it could also control certain aspects of QEMU (such as virtual
|
||||
clock stepping), with a special purpose "qtest" protocol. Refer to
|
||||
:ref:`qtest-protocol` for more details of the protocol.
|
||||
|
||||
QTest cases can be executed with
|
||||
|
||||
.. code::
|
||||
|
||||
make check-qtest
|
||||
|
||||
The QTest library is implemented by ``tests/qtest/libqtest.c`` and the API is
|
||||
defined in ``tests/qtest/libqtest.h``.
|
||||
|
||||
Consider adding a new QTest case when you are introducing a new virtual
|
||||
hardware, or extending one if you are adding functionalities to an existing
|
||||
virtual device.
|
||||
|
||||
On top of libqtest, a higher level library, ``libqos``, was created to
|
||||
encapsulate common tasks of device drivers, such as memory management and
|
||||
communicating with system buses or devices. Many virtual device tests use
|
||||
libqos instead of directly calling into libqtest.
|
||||
|
||||
Steps to add a new QTest case are:
|
||||
|
||||
1. Create a new source file for the test. (More than one file can be added as
|
||||
necessary.) For example, ``tests/qtest/foo-test.c``.
|
||||
|
||||
2. Write the test code with the glib and libqtest/libqos API. See also existing
|
||||
tests and the library headers for reference.
|
||||
|
||||
3. Register the new test in ``tests/qtest/meson.build``. Add the test
|
||||
executable name to an appropriate ``qtests_*`` variable. There is
|
||||
one variable per architecture, plus ``qtests_generic`` for tests
|
||||
that can be run for all architectures. For example::
|
||||
|
||||
qtests_generic = [
|
||||
...
|
||||
'foo-test',
|
||||
...
|
||||
]
|
||||
|
||||
4. If the test has more than one source file or needs to be linked with any
|
||||
dependency other than ``qemuutil`` and ``qos``, list them in the ``qtests``
|
||||
dictionary. For example a test that needs to use the ``QIO`` library
|
||||
will have an entry like::
|
||||
|
||||
{
|
||||
...
|
||||
'foo-test': [io],
|
||||
...
|
||||
}
|
||||
|
||||
Debugging a QTest failure is slightly harder than the unit test because the
|
||||
tests look up QEMU program names in the environment variables, such as
|
||||
``QTEST_QEMU_BINARY`` and ``QTEST_QEMU_IMG``, and also because it is not easy
|
||||
to attach gdb to the QEMU process spawned from the test. But manual invoking
|
||||
and using gdb on the test is still simple to do: find out the actual command
|
||||
from the output of
|
||||
|
||||
.. code::
|
||||
|
||||
make check-qtest V=1
|
||||
|
||||
which you can run manually.
|
||||
|
||||
|
||||
.. _qtest-protocol:
|
||||
|
||||
QTest Protocol
|
||||
--------------
|
||||
|
||||
.. kernel-doc:: softmmu/qtest.c
|
||||
:doc: QTest Protocol
|
||||
|
||||
|
||||
libqtest API reference
|
||||
----------------------
|
||||
|
||||
.. kernel-doc:: tests/qtest/libqos/libqtest.h
|
||||
+11
-53
@@ -41,15 +41,16 @@ add a new unit test:
|
||||
test. The test code should be organized with the glib testing framework.
|
||||
Copying and modifying an existing test is usually a good idea.
|
||||
|
||||
3. Add the test to ``tests/Makefile.include``. First, name the unit test
|
||||
program and add it to ``$(check-unit-y)``; then add a rule to build the
|
||||
executable. For example:
|
||||
3. Add the test to ``tests/meson.build``. The unit tests are listed in a
|
||||
dictionary called ``tests``. The values are any additional sources and
|
||||
dependencies to be linked with the test. For a simple test whose source
|
||||
is in ``tests/foo-test.c``, it is enough to add an entry like::
|
||||
|
||||
.. code::
|
||||
|
||||
check-unit-y += tests/foo-test$(EXESUF)
|
||||
tests/foo-test$(EXESUF): tests/foo-test.o $(test-util-obj-y)
|
||||
...
|
||||
{
|
||||
...
|
||||
'foo-test': [],
|
||||
...
|
||||
}
|
||||
|
||||
Since unit tests don't require environment variables, the simplest way to debug
|
||||
a unit test failure is often directly invoking it or even running it under
|
||||
@@ -70,8 +71,8 @@ QTest
|
||||
|
||||
QTest is a device emulation testing framework. It can be very useful to test
|
||||
device models; it could also control certain aspects of QEMU (such as virtual
|
||||
clock stepping), with a special purpose "qtest" protocol. Refer to the
|
||||
documentation in ``qtest.c`` for more details of the protocol.
|
||||
clock stepping), with a special purpose "qtest" protocol. Refer to
|
||||
:doc:`qtest` for more details.
|
||||
|
||||
QTest cases can be executed with
|
||||
|
||||
@@ -79,49 +80,6 @@ QTest cases can be executed with
|
||||
|
||||
make check-qtest
|
||||
|
||||
The QTest library is implemented by ``tests/qtest/libqtest.c`` and the API is
|
||||
defined in ``tests/qtest/libqtest.h``.
|
||||
|
||||
Consider adding a new QTest case when you are introducing a new virtual
|
||||
hardware, or extending one if you are adding functionalities to an existing
|
||||
virtual device.
|
||||
|
||||
On top of libqtest, a higher level library, ``libqos``, was created to
|
||||
encapsulate common tasks of device drivers, such as memory management and
|
||||
communicating with system buses or devices. Many virtual device tests use
|
||||
libqos instead of directly calling into libqtest.
|
||||
|
||||
Steps to add a new QTest case are:
|
||||
|
||||
1. Create a new source file for the test. (More than one file can be added as
|
||||
necessary.) For example, ``tests/qtest/foo-test.c``.
|
||||
|
||||
2. Write the test code with the glib and libqtest/libqos API. See also existing
|
||||
tests and the library headers for reference.
|
||||
|
||||
3. Register the new test in ``tests/qtest/Makefile.include``. Add the test
|
||||
executable name to an appropriate ``check-qtest-*-y`` variable. For example:
|
||||
|
||||
``check-qtest-generic-y = tests/qtest/foo-test$(EXESUF)``
|
||||
|
||||
4. Add object dependencies of the executable in the Makefile, including the
|
||||
test source file(s) and other interesting objects. For example:
|
||||
|
||||
``tests/qtest/foo-test$(EXESUF): tests/qtest/foo-test.o $(libqos-obj-y)``
|
||||
|
||||
Debugging a QTest failure is slightly harder than the unit test because the
|
||||
tests look up QEMU program names in the environment variables, such as
|
||||
``QTEST_QEMU_BINARY`` and ``QTEST_QEMU_IMG``, and also because it is not easy
|
||||
to attach gdb to the QEMU process spawned from the test. But manual invoking
|
||||
and using gdb on the test is still simple to do: find out the actual command
|
||||
from the output of
|
||||
|
||||
.. code::
|
||||
|
||||
make check-qtest V=1
|
||||
|
||||
which you can run manually.
|
||||
|
||||
QAPI schema tests
|
||||
-----------------
|
||||
|
||||
|
||||
+17
-11
@@ -49,12 +49,14 @@ int qbus_walk_children(BusState *bus,
|
||||
}
|
||||
}
|
||||
|
||||
QTAILQ_FOREACH(kid, &bus->children, sibling) {
|
||||
err = qdev_walk_children(kid->child,
|
||||
pre_devfn, pre_busfn,
|
||||
post_devfn, post_busfn, opaque);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
WITH_RCU_READ_LOCK_GUARD() {
|
||||
QTAILQ_FOREACH_RCU(kid, &bus->children, sibling) {
|
||||
err = qdev_walk_children(kid->child,
|
||||
pre_devfn, pre_busfn,
|
||||
post_devfn, post_busfn, opaque);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,8 +92,10 @@ static void bus_reset_child_foreach(Object *obj, ResettableChildCallback cb,
|
||||
BusState *bus = BUS(obj);
|
||||
BusChild *kid;
|
||||
|
||||
QTAILQ_FOREACH(kid, &bus->children, sibling) {
|
||||
cb(OBJECT(kid->child), opaque, type);
|
||||
WITH_RCU_READ_LOCK_GUARD() {
|
||||
QTAILQ_FOREACH_RCU(kid, &bus->children, sibling) {
|
||||
cb(OBJECT(kid->child), opaque, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,9 +198,11 @@ static void bus_set_realized(Object *obj, bool value, Error **errp)
|
||||
|
||||
/* TODO: recursive realization */
|
||||
} else if (!value && bus->realized) {
|
||||
QTAILQ_FOREACH(kid, &bus->children, sibling) {
|
||||
DeviceState *dev = kid->child;
|
||||
qdev_unrealize(dev);
|
||||
WITH_RCU_READ_LOCK_GUARD() {
|
||||
QTAILQ_FOREACH_RCU(kid, &bus->children, sibling) {
|
||||
DeviceState *dev = kid->child;
|
||||
qdev_unrealize(dev);
|
||||
}
|
||||
}
|
||||
if (bc->unrealize) {
|
||||
bc->unrealize(bus);
|
||||
|
||||
@@ -14,12 +14,6 @@ hwcore_files = files(
|
||||
'qdev-clock.c',
|
||||
)
|
||||
|
||||
libhwcore = static_library('hwcore', sources: hwcore_files + genh,
|
||||
name_suffix: 'fa',
|
||||
build_by_default: false)
|
||||
hwcore = declare_dependency(link_whole: libhwcore)
|
||||
common_ss.add(hwcore)
|
||||
|
||||
common_ss.add(files('cpu.c'))
|
||||
common_ss.add(when: 'CONFIG_FITLOADER', if_true: files('loader-fit.c'))
|
||||
common_ss.add(when: 'CONFIG_GENERIC_LOADER', if_true: files('generic-loader.c'))
|
||||
|
||||
+56
-17
@@ -51,6 +51,12 @@ const VMStateDescription *qdev_get_vmsd(DeviceState *dev)
|
||||
return dc->vmsd;
|
||||
}
|
||||
|
||||
static void bus_free_bus_child(BusChild *kid)
|
||||
{
|
||||
object_unref(OBJECT(kid->child));
|
||||
g_free(kid);
|
||||
}
|
||||
|
||||
static void bus_remove_child(BusState *bus, DeviceState *child)
|
||||
{
|
||||
BusChild *kid;
|
||||
@@ -60,15 +66,16 @@ static void bus_remove_child(BusState *bus, DeviceState *child)
|
||||
char name[32];
|
||||
|
||||
snprintf(name, sizeof(name), "child[%d]", kid->index);
|
||||
QTAILQ_REMOVE(&bus->children, kid, sibling);
|
||||
QTAILQ_REMOVE_RCU(&bus->children, kid, sibling);
|
||||
|
||||
bus->num_children--;
|
||||
|
||||
/* This gives back ownership of kid->child back to us. */
|
||||
object_property_del(OBJECT(bus), name);
|
||||
object_unref(OBJECT(kid->child));
|
||||
g_free(kid);
|
||||
return;
|
||||
|
||||
/* free the bus kid, when it is safe to do so*/
|
||||
call_rcu(kid, bus_free_bus_child, rcu);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,7 +90,7 @@ static void bus_add_child(BusState *bus, DeviceState *child)
|
||||
kid->child = child;
|
||||
object_ref(OBJECT(kid->child));
|
||||
|
||||
QTAILQ_INSERT_HEAD(&bus->children, kid, sibling);
|
||||
QTAILQ_INSERT_HEAD_RCU(&bus->children, kid, sibling);
|
||||
|
||||
/* This transfers ownership of kid->child to the property. */
|
||||
snprintf(name, sizeof(name), "child[%d]", kid->index);
|
||||
@@ -94,13 +101,23 @@ static void bus_add_child(BusState *bus, DeviceState *child)
|
||||
0);
|
||||
}
|
||||
|
||||
void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
|
||||
static bool bus_check_address(BusState *bus, DeviceState *child, Error **errp)
|
||||
{
|
||||
BusClass *bc = BUS_GET_CLASS(bus);
|
||||
return !bc->check_address || bc->check_address(bus, child, errp);
|
||||
}
|
||||
|
||||
bool qdev_set_parent_bus(DeviceState *dev, BusState *bus, Error **errp)
|
||||
{
|
||||
BusState *old_parent_bus = dev->parent_bus;
|
||||
DeviceClass *dc = DEVICE_GET_CLASS(dev);
|
||||
|
||||
assert(dc->bus_type && object_dynamic_cast(OBJECT(bus), dc->bus_type));
|
||||
|
||||
if (!bus_check_address(bus, dev, errp)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (old_parent_bus) {
|
||||
trace_qdev_update_parent_bus(dev, object_get_typename(OBJECT(dev)),
|
||||
old_parent_bus, object_get_typename(OBJECT(old_parent_bus)),
|
||||
@@ -126,6 +143,7 @@ void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
|
||||
object_unref(OBJECT(old_parent_bus));
|
||||
object_unref(OBJECT(dev));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
DeviceState *qdev_new(const char *name)
|
||||
@@ -371,7 +389,9 @@ bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp)
|
||||
assert(!dev->realized && !dev->parent_bus);
|
||||
|
||||
if (bus) {
|
||||
qdev_set_parent_bus(dev, bus);
|
||||
if (!qdev_set_parent_bus(dev, bus, errp)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
assert(!DEVICE_GET_CLASS(dev)->bus_type);
|
||||
}
|
||||
@@ -659,17 +679,19 @@ DeviceState *qdev_find_recursive(BusState *bus, const char *id)
|
||||
DeviceState *ret;
|
||||
BusState *child;
|
||||
|
||||
QTAILQ_FOREACH(kid, &bus->children, sibling) {
|
||||
DeviceState *dev = kid->child;
|
||||
WITH_RCU_READ_LOCK_GUARD() {
|
||||
QTAILQ_FOREACH_RCU(kid, &bus->children, sibling) {
|
||||
DeviceState *dev = kid->child;
|
||||
|
||||
if (dev->id && strcmp(dev->id, id) == 0) {
|
||||
return dev;
|
||||
}
|
||||
if (dev->id && strcmp(dev->id, id) == 0) {
|
||||
return dev;
|
||||
}
|
||||
|
||||
QLIST_FOREACH(child, &dev->child_bus, sibling) {
|
||||
ret = qdev_find_recursive(child, id);
|
||||
if (ret) {
|
||||
return ret;
|
||||
QLIST_FOREACH(child, &dev->child_bus, sibling) {
|
||||
ret = qdev_find_recursive(child, id);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -924,7 +946,25 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
|
||||
}
|
||||
}
|
||||
|
||||
qatomic_store_release(&dev->realized, value);
|
||||
|
||||
} else if (!value && dev->realized) {
|
||||
|
||||
/*
|
||||
* Change the value so that any concurrent users are aware
|
||||
* that the device is going to be unrealized
|
||||
*
|
||||
* TODO: change .realized property to enum that states
|
||||
* each phase of the device realization/unrealization
|
||||
*/
|
||||
|
||||
qatomic_set(&dev->realized, value);
|
||||
/*
|
||||
* Ensure that concurrent users see this update prior to
|
||||
* any other changes done by unrealize.
|
||||
*/
|
||||
smp_wmb();
|
||||
|
||||
QLIST_FOREACH(bus, &dev->child_bus, sibling) {
|
||||
qbus_unrealize(bus);
|
||||
}
|
||||
@@ -939,7 +979,6 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
|
||||
}
|
||||
|
||||
assert(local_err == NULL);
|
||||
dev->realized = value;
|
||||
return;
|
||||
|
||||
child_realize_fail:
|
||||
|
||||
+1
-1
@@ -3138,7 +3138,7 @@ static bool failover_replug_primary(VirtIONet *n, Error **errp)
|
||||
error_setg(errp, "virtio_net: couldn't find primary bus");
|
||||
return false;
|
||||
}
|
||||
qdev_set_parent_bus(n->primary_dev, n->primary_bus);
|
||||
qdev_set_parent_bus(n->primary_dev, n->primary_bus, &error_abort);
|
||||
n->primary_should_be_hidden = false;
|
||||
if (!qemu_opt_set_bool(n->primary_device_opts,
|
||||
"partially_hotplugged", true, errp)) {
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* QEMU Firmware configuration device emulation (QOM interfaces)
|
||||
*
|
||||
* Copyright 2020 Red Hat, Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "hw/nvram/fw_cfg.h"
|
||||
|
||||
static const TypeInfo fw_cfg_data_generator_interface_info = {
|
||||
.parent = TYPE_INTERFACE,
|
||||
.name = TYPE_FW_CFG_DATA_GENERATOR_INTERFACE,
|
||||
.class_size = sizeof(FWCfgDataGeneratorClass),
|
||||
};
|
||||
|
||||
static void fw_cfg_register_interfaces(void)
|
||||
{
|
||||
type_register_static(&fw_cfg_data_generator_interface_info);
|
||||
}
|
||||
|
||||
type_init(fw_cfg_register_interfaces)
|
||||
@@ -1360,18 +1360,11 @@ static const TypeInfo fw_cfg_mem_info = {
|
||||
.class_init = fw_cfg_mem_class_init,
|
||||
};
|
||||
|
||||
static const TypeInfo fw_cfg_data_generator_interface_info = {
|
||||
.parent = TYPE_INTERFACE,
|
||||
.name = TYPE_FW_CFG_DATA_GENERATOR_INTERFACE,
|
||||
.class_size = sizeof(FWCfgDataGeneratorClass),
|
||||
};
|
||||
|
||||
static void fw_cfg_register_types(void)
|
||||
{
|
||||
type_register_static(&fw_cfg_info);
|
||||
type_register_static(&fw_cfg_io_info);
|
||||
type_register_static(&fw_cfg_mem_info);
|
||||
type_register_static(&fw_cfg_data_generator_interface_info);
|
||||
}
|
||||
|
||||
type_init(fw_cfg_register_types)
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
# QOM interfaces must be available anytime QOM is used.
|
||||
qom_ss.add(files('fw_cfg-interface.c'))
|
||||
|
||||
softmmu_ss.add(files('fw_cfg.c'))
|
||||
softmmu_ss.add(when: 'CONFIG_CHRP_NVRAM', if_true: files('chrp_nvram.c'))
|
||||
softmmu_ss.add(when: 'CONFIG_DS1225Y', if_true: files('ds1225y.c'))
|
||||
|
||||
+175
-101
@@ -22,34 +22,67 @@ static void scsi_req_dequeue(SCSIRequest *req);
|
||||
static uint8_t *scsi_target_alloc_buf(SCSIRequest *req, size_t len);
|
||||
static void scsi_target_free_buf(SCSIRequest *req);
|
||||
|
||||
static Property scsi_props[] = {
|
||||
DEFINE_PROP_UINT32("channel", SCSIDevice, channel, 0),
|
||||
DEFINE_PROP_UINT32("scsi-id", SCSIDevice, id, -1),
|
||||
DEFINE_PROP_UINT32("lun", SCSIDevice, lun, -1),
|
||||
DEFINE_PROP_END_OF_LIST(),
|
||||
};
|
||||
static int next_scsi_bus;
|
||||
|
||||
static void scsi_bus_class_init(ObjectClass *klass, void *data)
|
||||
static SCSIDevice *do_scsi_device_find(SCSIBus *bus,
|
||||
int channel, int id, int lun,
|
||||
bool include_unrealized)
|
||||
{
|
||||
BusClass *k = BUS_CLASS(klass);
|
||||
HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
|
||||
BusChild *kid;
|
||||
SCSIDevice *retval = NULL;
|
||||
|
||||
k->get_dev_path = scsibus_get_dev_path;
|
||||
k->get_fw_dev_path = scsibus_get_fw_dev_path;
|
||||
hc->unplug = qdev_simple_device_unplug_cb;
|
||||
QTAILQ_FOREACH_RCU(kid, &bus->qbus.children, sibling) {
|
||||
DeviceState *qdev = kid->child;
|
||||
SCSIDevice *dev = SCSI_DEVICE(qdev);
|
||||
|
||||
if (dev->channel == channel && dev->id == id) {
|
||||
if (dev->lun == lun) {
|
||||
retval = dev;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we don't find exact match (channel/bus/lun),
|
||||
* we will return the first device which matches channel/bus
|
||||
*/
|
||||
|
||||
if (!retval) {
|
||||
retval = dev;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This function might run on the IO thread and we might race against
|
||||
* main thread hot-plugging the device.
|
||||
* We assume that as soon as .realized is set to true we can let
|
||||
* the user access the device.
|
||||
*/
|
||||
|
||||
if (retval && !include_unrealized &&
|
||||
!qatomic_load_acquire(&retval->qdev.realized)) {
|
||||
retval = NULL;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static const TypeInfo scsi_bus_info = {
|
||||
.name = TYPE_SCSI_BUS,
|
||||
.parent = TYPE_BUS,
|
||||
.instance_size = sizeof(SCSIBus),
|
||||
.class_init = scsi_bus_class_init,
|
||||
.interfaces = (InterfaceInfo[]) {
|
||||
{ TYPE_HOTPLUG_HANDLER },
|
||||
{ }
|
||||
SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int id, int lun)
|
||||
{
|
||||
RCU_READ_LOCK_GUARD();
|
||||
return do_scsi_device_find(bus, channel, id, lun, false);
|
||||
}
|
||||
|
||||
SCSIDevice *scsi_device_get(SCSIBus *bus, int channel, int id, int lun)
|
||||
{
|
||||
SCSIDevice *d;
|
||||
RCU_READ_LOCK_GUARD();
|
||||
d = do_scsi_device_find(bus, channel, id, lun, false);
|
||||
if (d) {
|
||||
object_ref(d);
|
||||
}
|
||||
};
|
||||
static int next_scsi_bus;
|
||||
return d;
|
||||
}
|
||||
|
||||
static void scsi_device_realize(SCSIDevice *s, Error **errp)
|
||||
{
|
||||
@@ -160,35 +193,71 @@ static void scsi_dma_restart_cb(void *opaque, int running, RunState state)
|
||||
}
|
||||
}
|
||||
|
||||
static bool scsi_bus_is_address_free(SCSIBus *bus,
|
||||
int channel, int target, int lun,
|
||||
SCSIDevice **p_dev)
|
||||
{
|
||||
SCSIDevice *d;
|
||||
|
||||
RCU_READ_LOCK_GUARD();
|
||||
d = do_scsi_device_find(bus, channel, target, lun, true);
|
||||
if (d && d->lun == lun) {
|
||||
if (p_dev) {
|
||||
*p_dev = d;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (p_dev) {
|
||||
*p_dev = NULL;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool scsi_bus_check_address(BusState *qbus, DeviceState *qdev, Error **errp)
|
||||
{
|
||||
SCSIDevice *dev = SCSI_DEVICE(qdev);
|
||||
SCSIBus *bus = SCSI_BUS(qbus);
|
||||
|
||||
if (dev->channel > bus->info->max_channel) {
|
||||
error_setg(errp, "bad scsi channel id: %d", dev->channel);
|
||||
return false;
|
||||
}
|
||||
if (dev->id != -1 && dev->id > bus->info->max_target) {
|
||||
error_setg(errp, "bad scsi device id: %d", dev->id);
|
||||
return false;
|
||||
}
|
||||
if (dev->lun != -1 && dev->lun > bus->info->max_lun) {
|
||||
error_setg(errp, "bad scsi device lun: %d", dev->lun);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dev->id != -1 && dev->lun != -1) {
|
||||
SCSIDevice *d;
|
||||
if (!scsi_bus_is_address_free(bus, dev->channel, dev->id, dev->lun, &d)) {
|
||||
error_setg(errp, "lun already used by '%s'", d->qdev.id);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void scsi_qdev_realize(DeviceState *qdev, Error **errp)
|
||||
{
|
||||
SCSIDevice *dev = SCSI_DEVICE(qdev);
|
||||
SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus);
|
||||
SCSIDevice *d;
|
||||
bool is_free;
|
||||
Error *local_err = NULL;
|
||||
|
||||
if (dev->channel > bus->info->max_channel) {
|
||||
error_setg(errp, "bad scsi channel id: %d", dev->channel);
|
||||
return;
|
||||
}
|
||||
if (dev->id != -1 && dev->id > bus->info->max_target) {
|
||||
error_setg(errp, "bad scsi device id: %d", dev->id);
|
||||
return;
|
||||
}
|
||||
if (dev->lun != -1 && dev->lun > bus->info->max_lun) {
|
||||
error_setg(errp, "bad scsi device lun: %d", dev->lun);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dev->id == -1) {
|
||||
int id = -1;
|
||||
if (dev->lun == -1) {
|
||||
dev->lun = 0;
|
||||
}
|
||||
do {
|
||||
d = scsi_device_find(bus, dev->channel, ++id, dev->lun);
|
||||
} while (d && d->lun == dev->lun && id < bus->info->max_target);
|
||||
if (d && d->lun == dev->lun) {
|
||||
is_free = scsi_bus_is_address_free(bus, dev->channel, ++id, dev->lun, NULL);
|
||||
} while (!is_free && id < bus->info->max_target);
|
||||
if (!is_free) {
|
||||
error_setg(errp, "no free target");
|
||||
return;
|
||||
}
|
||||
@@ -196,20 +265,13 @@ static void scsi_qdev_realize(DeviceState *qdev, Error **errp)
|
||||
} else if (dev->lun == -1) {
|
||||
int lun = -1;
|
||||
do {
|
||||
d = scsi_device_find(bus, dev->channel, dev->id, ++lun);
|
||||
} while (d && d->lun == lun && lun < bus->info->max_lun);
|
||||
if (d && d->lun == lun) {
|
||||
is_free = scsi_bus_is_address_free(bus, dev->channel, dev->id, ++lun, NULL);
|
||||
} while (!is_free && lun < bus->info->max_lun);
|
||||
if (!is_free) {
|
||||
error_setg(errp, "no free lun");
|
||||
return;
|
||||
}
|
||||
dev->lun = lun;
|
||||
} else {
|
||||
d = scsi_device_find(bus, dev->channel, dev->id, dev->lun);
|
||||
assert(d);
|
||||
if (d->lun == dev->lun && dev != d) {
|
||||
error_setg(errp, "lun already used by '%s'", d->qdev.id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QTAILQ_INIT(&dev->requests);
|
||||
@@ -376,19 +438,23 @@ struct SCSITargetReq {
|
||||
static void store_lun(uint8_t *outbuf, int lun)
|
||||
{
|
||||
if (lun < 256) {
|
||||
/* Simple logical unit addressing method*/
|
||||
outbuf[0] = 0;
|
||||
outbuf[1] = lun;
|
||||
return;
|
||||
} else {
|
||||
/* Flat space addressing method */
|
||||
outbuf[0] = 0x40 | (lun >> 8);
|
||||
outbuf[1] = (lun & 255);
|
||||
}
|
||||
outbuf[1] = (lun & 255);
|
||||
outbuf[0] = (lun >> 8) | 0x40;
|
||||
}
|
||||
|
||||
static bool scsi_target_emulate_report_luns(SCSITargetReq *r)
|
||||
{
|
||||
BusChild *kid;
|
||||
int i, len, n;
|
||||
int channel, id;
|
||||
bool found_lun0;
|
||||
uint8_t tmp[8] = {0};
|
||||
int len = 0;
|
||||
GByteArray *buf;
|
||||
|
||||
if (r->req.cmd.xfer < 16) {
|
||||
return false;
|
||||
@@ -396,42 +462,40 @@ static bool scsi_target_emulate_report_luns(SCSITargetReq *r)
|
||||
if (r->req.cmd.buf[2] > 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* reserve space for 63 LUNs*/
|
||||
buf = g_byte_array_sized_new(512);
|
||||
|
||||
channel = r->req.dev->channel;
|
||||
id = r->req.dev->id;
|
||||
found_lun0 = false;
|
||||
n = 0;
|
||||
QTAILQ_FOREACH(kid, &r->req.bus->qbus.children, sibling) {
|
||||
DeviceState *qdev = kid->child;
|
||||
SCSIDevice *dev = SCSI_DEVICE(qdev);
|
||||
|
||||
if (dev->channel == channel && dev->id == id) {
|
||||
if (dev->lun == 0) {
|
||||
found_lun0 = true;
|
||||
/* add size (will be updated later to correct value */
|
||||
g_byte_array_append(buf, tmp, 8);
|
||||
len += 8;
|
||||
|
||||
/* add LUN0 */
|
||||
g_byte_array_append(buf, tmp, 8);
|
||||
len += 8;
|
||||
|
||||
WITH_RCU_READ_LOCK_GUARD() {
|
||||
QTAILQ_FOREACH_RCU(kid, &r->req.bus->qbus.children, sibling) {
|
||||
DeviceState *qdev = kid->child;
|
||||
SCSIDevice *dev = SCSI_DEVICE(qdev);
|
||||
|
||||
if (dev->channel == channel && dev->id == id && dev->lun != 0) {
|
||||
store_lun(tmp, dev->lun);
|
||||
g_byte_array_append(buf, tmp, 8);
|
||||
len += 8;
|
||||
}
|
||||
n += 8;
|
||||
}
|
||||
}
|
||||
if (!found_lun0) {
|
||||
n += 8;
|
||||
}
|
||||
|
||||
scsi_target_alloc_buf(&r->req, n + 8);
|
||||
r->buf_len = len;
|
||||
r->buf = g_byte_array_free(buf, FALSE);
|
||||
r->len = MIN(len, r->req.cmd.xfer & ~7);
|
||||
|
||||
len = MIN(n + 8, r->req.cmd.xfer & ~7);
|
||||
memset(r->buf, 0, len);
|
||||
stl_be_p(&r->buf[0], n);
|
||||
i = found_lun0 ? 8 : 16;
|
||||
QTAILQ_FOREACH(kid, &r->req.bus->qbus.children, sibling) {
|
||||
DeviceState *qdev = kid->child;
|
||||
SCSIDevice *dev = SCSI_DEVICE(qdev);
|
||||
|
||||
if (dev->channel == channel && dev->id == id) {
|
||||
store_lun(&r->buf[i], dev->lun);
|
||||
i += 8;
|
||||
}
|
||||
}
|
||||
assert(i == n + 8);
|
||||
r->len = len;
|
||||
/* store the LUN list length */
|
||||
stl_be_p(&r->buf[0], len - 8);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1567,25 +1631,6 @@ static char *scsibus_get_fw_dev_path(DeviceState *dev)
|
||||
qdev_fw_name(dev), d->id, d->lun);
|
||||
}
|
||||
|
||||
SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int id, int lun)
|
||||
{
|
||||
BusChild *kid;
|
||||
SCSIDevice *target_dev = NULL;
|
||||
|
||||
QTAILQ_FOREACH_REVERSE(kid, &bus->qbus.children, sibling) {
|
||||
DeviceState *qdev = kid->child;
|
||||
SCSIDevice *dev = SCSI_DEVICE(qdev);
|
||||
|
||||
if (dev->channel == channel && dev->id == id) {
|
||||
if (dev->lun == lun) {
|
||||
return dev;
|
||||
}
|
||||
target_dev = dev;
|
||||
}
|
||||
}
|
||||
return target_dev;
|
||||
}
|
||||
|
||||
/* SCSI request list. For simplicity, pv points to the whole device */
|
||||
|
||||
static int put_scsi_requests(QEMUFile *f, void *pv, size_t size,
|
||||
@@ -1709,6 +1754,13 @@ const VMStateDescription vmstate_scsi_device = {
|
||||
}
|
||||
};
|
||||
|
||||
static Property scsi_props[] = {
|
||||
DEFINE_PROP_UINT32("channel", SCSIDevice, channel, 0),
|
||||
DEFINE_PROP_UINT32("scsi-id", SCSIDevice, id, -1),
|
||||
DEFINE_PROP_UINT32("lun", SCSIDevice, lun, -1),
|
||||
DEFINE_PROP_END_OF_LIST(),
|
||||
};
|
||||
|
||||
static void scsi_device_class_init(ObjectClass *klass, void *data)
|
||||
{
|
||||
DeviceClass *k = DEVICE_CLASS(klass);
|
||||
@@ -1739,6 +1791,28 @@ static const TypeInfo scsi_device_type_info = {
|
||||
.instance_init = scsi_dev_instance_init,
|
||||
};
|
||||
|
||||
static void scsi_bus_class_init(ObjectClass *klass, void *data)
|
||||
{
|
||||
BusClass *k = BUS_CLASS(klass);
|
||||
HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
|
||||
|
||||
k->get_dev_path = scsibus_get_dev_path;
|
||||
k->get_fw_dev_path = scsibus_get_fw_dev_path;
|
||||
k->check_address = scsi_bus_check_address;
|
||||
hc->unplug = qdev_simple_device_unplug_cb;
|
||||
}
|
||||
|
||||
static const TypeInfo scsi_bus_info = {
|
||||
.name = TYPE_SCSI_BUS,
|
||||
.parent = TYPE_BUS,
|
||||
.instance_size = sizeof(SCSIBus),
|
||||
.class_init = scsi_bus_class_init,
|
||||
.interfaces = (InterfaceInfo[]) {
|
||||
{ TYPE_HOTPLUG_HANDLER },
|
||||
{ }
|
||||
}
|
||||
};
|
||||
|
||||
static void scsi_register_types(void)
|
||||
{
|
||||
type_register_static(&scsi_bus_info);
|
||||
|
||||
+18
-9
@@ -33,7 +33,7 @@ static inline int virtio_scsi_get_lun(uint8_t *lun)
|
||||
return ((lun[2] << 8) | lun[3]) & 0x3FFF;
|
||||
}
|
||||
|
||||
static inline SCSIDevice *virtio_scsi_device_find(VirtIOSCSI *s, uint8_t *lun)
|
||||
static inline SCSIDevice *virtio_scsi_device_get(VirtIOSCSI *s, uint8_t *lun)
|
||||
{
|
||||
if (lun[0] != 1) {
|
||||
return NULL;
|
||||
@@ -41,7 +41,7 @@ static inline SCSIDevice *virtio_scsi_device_find(VirtIOSCSI *s, uint8_t *lun)
|
||||
if (lun[2] != 0 && !(lun[2] >= 0x40 && lun[2] < 0x80)) {
|
||||
return NULL;
|
||||
}
|
||||
return scsi_device_find(&s->bus, 0, lun[1], virtio_scsi_get_lun(lun));
|
||||
return scsi_device_get(&s->bus, 0, lun[1], virtio_scsi_get_lun(lun));
|
||||
}
|
||||
|
||||
void virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq, VirtIOSCSIReq *req)
|
||||
@@ -256,7 +256,7 @@ static inline void virtio_scsi_ctx_check(VirtIOSCSI *s, SCSIDevice *d)
|
||||
* case of async cancellation. */
|
||||
static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req)
|
||||
{
|
||||
SCSIDevice *d = virtio_scsi_device_find(s, req->req.tmf.lun);
|
||||
SCSIDevice *d = virtio_scsi_device_get(s, req->req.tmf.lun);
|
||||
SCSIRequest *r, *next;
|
||||
BusChild *kid;
|
||||
int target;
|
||||
@@ -367,12 +367,16 @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req)
|
||||
case VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET:
|
||||
target = req->req.tmf.lun[1];
|
||||
s->resetting++;
|
||||
QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) {
|
||||
d = SCSI_DEVICE(kid->child);
|
||||
if (d->channel == 0 && d->id == target) {
|
||||
qdev_reset_all(&d->qdev);
|
||||
}
|
||||
|
||||
rcu_read_lock();
|
||||
QTAILQ_FOREACH_RCU(kid, &s->bus.qbus.children, sibling) {
|
||||
SCSIDevice *d1 = SCSI_DEVICE(kid->child);
|
||||
if (d1->channel == 0 && d1->id == target) {
|
||||
qdev_reset_all(&d1->qdev);
|
||||
}
|
||||
}
|
||||
rcu_read_unlock();
|
||||
|
||||
s->resetting--;
|
||||
break;
|
||||
|
||||
@@ -382,14 +386,17 @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req)
|
||||
break;
|
||||
}
|
||||
|
||||
object_unref(OBJECT(d));
|
||||
return ret;
|
||||
|
||||
incorrect_lun:
|
||||
req->resp.tmf.response = VIRTIO_SCSI_S_INCORRECT_LUN;
|
||||
object_unref(OBJECT(d));
|
||||
return ret;
|
||||
|
||||
fail:
|
||||
req->resp.tmf.response = VIRTIO_SCSI_S_BAD_TARGET;
|
||||
object_unref(OBJECT(d));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -560,7 +567,7 @@ static int virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req)
|
||||
}
|
||||
}
|
||||
|
||||
d = virtio_scsi_device_find(s, req->req.cmd.lun);
|
||||
d = virtio_scsi_device_get(s, req->req.cmd.lun);
|
||||
if (!d) {
|
||||
req->resp.cmd.response = VIRTIO_SCSI_S_BAD_TARGET;
|
||||
virtio_scsi_complete_cmd_req(req);
|
||||
@@ -576,10 +583,12 @@ static int virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req)
|
||||
req->sreq->cmd.xfer > req->qsgl.size)) {
|
||||
req->resp.cmd.response = VIRTIO_SCSI_S_OVERRUN;
|
||||
virtio_scsi_complete_cmd_req(req);
|
||||
object_unref(OBJECT(d));
|
||||
return -ENOBUFS;
|
||||
}
|
||||
scsi_req_ref(req->sreq);
|
||||
blk_io_plug(d->conf.blk);
|
||||
object_unref(OBJECT(d));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -23,6 +23,7 @@
|
||||
#include "hw/qdev-core.h"
|
||||
#include "hw/sd/sd.h"
|
||||
#include "qemu/module.h"
|
||||
#include "qapi/error.h"
|
||||
#include "trace.h"
|
||||
|
||||
static inline const char *sdbus_name(SDBus *sdbus)
|
||||
@@ -240,7 +241,7 @@ void sdbus_reparent_card(SDBus *from, SDBus *to)
|
||||
readonly = sc->get_readonly(card);
|
||||
|
||||
sdbus_set_inserted(from, false);
|
||||
qdev_set_parent_bus(DEVICE(card), &to->qbus);
|
||||
qdev_set_parent_bus(DEVICE(card), &to->qbus, &error_abort);
|
||||
sdbus_set_inserted(to, true);
|
||||
sdbus_set_readonly(to, readonly);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ void cpu_list_unlock(void);
|
||||
|
||||
void tcg_flush_softmmu_tlb(CPUState *cs);
|
||||
|
||||
void tcg_iommu_init_notifier_list(CPUState *cpu);
|
||||
void tcg_iommu_free_notifier_list(CPUState *cpu);
|
||||
|
||||
#if !defined(CONFIG_USER_ONLY)
|
||||
|
||||
enum device_endian {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user