Skip to content

Commit 0e3aff9

Browse files
committed
Merge tag 'pull-10.0-gdb-plugins-doc-updates-170125-1' of https://gitlab.com/stsquad/qemu into staging
semihosting, plugin and doc updates: - log a guest_error for failed semihosting open() - clean up semihosting includes to reduce build duplication - re-factor misc device initialisation to fail with &error_exit - propagate Error * to gdbserver_start sub-functions - fix 32-bit build of plugins and re-enable by default - ensure IRQs don't preempt io recompiled instructions - remove usage of gcc_struct to enable clang builds - enable clang/lld to build plugins on windows - various small kdoc typo fixes - add perl scripts to editorconfig - remove unused field from MemoryRegion - make kdoc script a dependency so doc rebuilds get triggered - expand developer documentation: - notes on git-publish - describe usage of b4 - setting up build dependencies - codebase layout - add a glossary of common terms - optimise the windows ndis script # -----BEGIN PGP SIGNATURE----- # # iQEzBAABCgAdFiEEZoWumedRZ7yvyN81+9DbCVqeKkQFAmeKO8sACgkQ+9DbCVqe # KkTbBQf9HRlspCl2r5a8K9O1ymylKiZ653OBWMStGTQ8xPXeLDFhT+ION34VBgBh # LXHEcjIHn24cN2s1BO5+xJs0nzqYe7UEAK6JQmdX3/HEuf8VmaVslvhm+nCWKoIL # JQbsHno92wh6vvTWQu53zijEuG5HdBseWiwQKHbE1oSRc2CikG70o902AL9zXAsp # mpUYWxUmWwg5uQATztp4XfylJBcSX3SiVgv22jXLqBj9drXPftl/E33fcWXxTj5f # AM3kz9fxaCfo5+znmYw3R1tT/Hv52Q6hW+oNAm34XeWp1/+ho27QMRrpIi/dpdwX # mCbvJwI75sCnD91p9NW7vZIYZJKsLg== # =SLCY # -----END PGP SIGNATURE----- # gpg: Signature made Fri 17 Jan 2025 06:15:23 EST # gpg: using RSA key 6685AE99E75167BCAFC8DF35FBD0DB095A9E2A44 # gpg: Good signature from "Alex Bennée (Master Work Key) <alex.bennee@linaro.org>" [unknown] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: 6685 AE99 E751 67BC AFC8 DF35 FBD0 DB09 5A9E 2A44 * tag 'pull-10.0-gdb-plugins-doc-updates-170125-1' of https://gitlab.com/stsquad/qemu: (37 commits) scripts/nsis.py: Run dependency check for each DLL file only once docs: add a glossary docs/devel: add a codebase section docs/devel: add information on how to setup build environments docs/devel: add b4 for patch retrieval docs/devel: add git-publish for patch submitting docs/sphinx: include kernel-doc script as a dependency include/exec: remove warning_printed from MemoryRegion include/exec: fix some copy and paste errors in kdoc tests/qtest: fix some copy and paste errors in kdoc editorconfig: update for perl scripts plugins: fix kdoc annotation plugins: enable linking with clang/lld docs/devel/style: add a section about bitfield, and disallow them for packed structures win32: remove usage of attribute gcc_struct accel/tcg: also suppress asynchronous IRQs for cpu_io_recompile configure: reenable plugins by default for 32-bit hosts contrib/plugins/hotpages: fix 32-bit build contrib/plugins/hwprofile: fix 32-bit build contrib/plugins/cflow: fix 32-bit build ... Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2 parents 09360a0 + b9eab5e commit 0e3aff9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1035
-226
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,16 @@ emacs_mode = glsl
4747
[*.json]
4848
indent_style = space
4949
emacs_mode = python
50+
51+
# by default follow QEMU's style
52+
[*.pl]
53+
indent_style = space
54+
indent_size = 4
55+
emacs_mode = perl
56+
57+
# but user kernel "style" for imported scripts
58+
[scripts/{kernel-doc,get_maintainer.pl,checkpatch.pl}]
59+
indent_style = tab
60+
indent_size = 8
61+
emacs_mode = perl
62+

MAINTAINERS

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,14 @@ R: Markus Armbruster <armbru@redhat.com>
7272
R: Philippe Mathieu-Daudé <philmd@linaro.org>
7373
W: https://www.qemu.org/docs/master/devel/index.html
7474
S: Odd Fixes
75-
F: docs/devel/style.rst
75+
F: docs/devel/build-environment.rst
7676
F: docs/devel/code-of-conduct.rst
77+
F: docs/devel/codebase.rst
7778
F: docs/devel/conflict-resolution.rst
79+
F: docs/devel/style.rst
7880
F: docs/devel/submitting-a-patch.rst
7981
F: docs/devel/submitting-a-pull-request.rst
82+
F: docs/glossary.rst
8083

8184
Responsible Disclosure, Reporting Security Issues
8285
-------------------------------------------------

accel/tcg/translate-all.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,9 +633,10 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)
633633
* Exit the loop and potentially generate a new TB executing the
634634
* just the I/O insns. We also limit instrumentation to memory
635635
* operations only (which execute after completion) so we don't
636-
* double instrument the instruction.
636+
* double instrument the instruction. Also don't let an IRQ sneak
637+
* in before we execute it.
637638
*/
638-
cpu->cflags_next_tb = curr_cflags(cpu) | CF_MEMI_ONLY | n;
639+
cpu->cflags_next_tb = curr_cflags(cpu) | CF_MEMI_ONLY | CF_NOIRQ | n;
639640

640641
if (qemu_loglevel_mask(CPU_LOG_EXEC)) {
641642
vaddr pc = cpu->cc->get_pc(cpu);

bsd-user/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ int main(int argc, char **argv)
628628
target_cpu_init(env, regs);
629629

630630
if (gdbstub) {
631-
gdbserver_start(gdbstub);
631+
gdbserver_start(gdbstub, &error_fatal);
632632
gdb_handlesig(cpu, 0, NULL, NULL, 0);
633633
}
634634
cpu_loop(env);

configure

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -528,25 +528,6 @@ case "$cpu" in
528528
;;
529529
esac
530530

531-
# Now we have our CPU_CFLAGS we can check if we are targeting a 32 or
532-
# 64 bit host.
533-
534-
check_64bit_host() {
535-
cat > $TMPC <<EOF
536-
#if __SIZEOF_POINTER__ != 8
537-
#error not 64 bit system
538-
#endif
539-
int main(void) { return 0; }
540-
EOF
541-
compile_object "$1"
542-
}
543-
544-
if check_64bit_host "$CPU_CFLAGS"; then
545-
host_bits=64
546-
else
547-
host_bits=32
548-
fi
549-
550531
if test -n "$host_arch" && {
551532
! test -d "$source_path/linux-user/include/host/$host_arch" ||
552533
! test -d "$source_path/common-user/host/$host_arch"; }; then
@@ -1072,7 +1053,7 @@ if test "$static" = "yes" ; then
10721053
fi
10731054
plugins="no"
10741055
fi
1075-
if test "$plugins" != "no" && test $host_bits -eq 64; then
1056+
if test "$plugins" != "no"; then
10761057
if has_meson_option "-Dtcg_interpreter=true"; then
10771058
plugins="no"
10781059
else

contrib/plugins/cache.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static int fifo_get_first_block(Cache *cache, int set)
208208
static void fifo_update_on_miss(Cache *cache, int set, int blk_idx)
209209
{
210210
GQueue *q = cache->sets[set].fifo_queue;
211-
g_queue_push_head(q, GINT_TO_POINTER(blk_idx));
211+
g_queue_push_head(q, (gpointer)(intptr_t) blk_idx);
212212
}
213213

214214
static void fifo_destroy(Cache *cache)
@@ -471,28 +471,22 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
471471
n_insns = qemu_plugin_tb_n_insns(tb);
472472
for (i = 0; i < n_insns; i++) {
473473
struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i);
474-
uint64_t effective_addr;
475-
476-
if (sys) {
477-
effective_addr = (uint64_t) qemu_plugin_insn_haddr(insn);
478-
} else {
479-
effective_addr = (uint64_t) qemu_plugin_insn_vaddr(insn);
480-
}
474+
uint64_t effective_addr = sys ? (uintptr_t) qemu_plugin_insn_haddr(insn) :
475+
qemu_plugin_insn_vaddr(insn);
481476

482477
/*
483478
* Instructions might get translated multiple times, we do not create
484479
* new entries for those instructions. Instead, we fetch the same
485480
* entry from the hash table and register it for the callback again.
486481
*/
487482
g_mutex_lock(&hashtable_lock);
488-
data = g_hash_table_lookup(miss_ht, GUINT_TO_POINTER(effective_addr));
483+
data = g_hash_table_lookup(miss_ht, &effective_addr);
489484
if (data == NULL) {
490485
data = g_new0(InsnData, 1);
491486
data->disas_str = qemu_plugin_insn_disas(insn);
492487
data->symbol = qemu_plugin_insn_symbol(insn);
493488
data->addr = effective_addr;
494-
g_hash_table_insert(miss_ht, GUINT_TO_POINTER(effective_addr),
495-
(gpointer) data);
489+
g_hash_table_insert(miss_ht, &data->addr, data);
496490
}
497491
g_mutex_unlock(&hashtable_lock);
498492

@@ -853,7 +847,7 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info,
853847
qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans);
854848
qemu_plugin_register_atexit_cb(id, plugin_exit, NULL);
855849

856-
miss_ht = g_hash_table_new_full(NULL, g_direct_equal, NULL, insn_free);
850+
miss_ht = g_hash_table_new_full(g_int64_hash, g_int64_equal, NULL, insn_free);
857851

858852
return 0;
859853
}

contrib/plugins/cflow.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ typedef struct {
7676

7777
/* We use this to track the current execution state */
7878
typedef struct {
79+
/* address of current translated block */
80+
uint64_t tb_pc;
7981
/* address of end of block */
8082
uint64_t end_block;
8183
/* next pc after end of block */
@@ -85,6 +87,7 @@ typedef struct {
8587
} VCPUScoreBoard;
8688

8789
/* descriptors for accessing the above scoreboard */
90+
static qemu_plugin_u64 tb_pc;
8891
static qemu_plugin_u64 end_block;
8992
static qemu_plugin_u64 pc_after_block;
9093
static qemu_plugin_u64 last_pc;
@@ -189,10 +192,11 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
189192
static void plugin_init(void)
190193
{
191194
g_mutex_init(&node_lock);
192-
nodes = g_hash_table_new(NULL, g_direct_equal);
195+
nodes = g_hash_table_new(g_int64_hash, g_int64_equal);
193196
state = qemu_plugin_scoreboard_new(sizeof(VCPUScoreBoard));
194197

195198
/* score board declarations */
199+
tb_pc = qemu_plugin_scoreboard_u64_in_struct(state, VCPUScoreBoard, tb_pc);
196200
end_block = qemu_plugin_scoreboard_u64_in_struct(state, VCPUScoreBoard,
197201
end_block);
198202
pc_after_block = qemu_plugin_scoreboard_u64_in_struct(state, VCPUScoreBoard,
@@ -215,10 +219,10 @@ static NodeData *fetch_node(uint64_t addr, bool create_if_not_found)
215219
NodeData *node = NULL;
216220

217221
g_mutex_lock(&node_lock);
218-
node = (NodeData *) g_hash_table_lookup(nodes, (gconstpointer) addr);
222+
node = (NodeData *) g_hash_table_lookup(nodes, &addr);
219223
if (!node && create_if_not_found) {
220224
node = create_node(addr);
221-
g_hash_table_insert(nodes, (gpointer) addr, (gpointer) node);
225+
g_hash_table_insert(nodes, &node->addr, node);
222226
}
223227
g_mutex_unlock(&node_lock);
224228
return node;
@@ -234,7 +238,7 @@ static void vcpu_tb_branched_exec(unsigned int cpu_index, void *udata)
234238
uint64_t lpc = qemu_plugin_u64_get(last_pc, cpu_index);
235239
uint64_t ebpc = qemu_plugin_u64_get(end_block, cpu_index);
236240
uint64_t npc = qemu_plugin_u64_get(pc_after_block, cpu_index);
237-
uint64_t pc = GPOINTER_TO_UINT(udata);
241+
uint64_t pc = qemu_plugin_u64_get(tb_pc, cpu_index);
238242

239243
/* return early for address 0 */
240244
if (!lpc) {
@@ -305,10 +309,11 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
305309
* handle both early block exits and normal branches in the
306310
* callback if we hit it.
307311
*/
308-
gpointer udata = GUINT_TO_POINTER(pc);
312+
qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu(
313+
tb, QEMU_PLUGIN_INLINE_STORE_U64, tb_pc, pc);
309314
qemu_plugin_register_vcpu_tb_exec_cond_cb(
310315
tb, vcpu_tb_branched_exec, QEMU_PLUGIN_CB_NO_REGS,
311-
QEMU_PLUGIN_COND_NE, pc_after_block, pc, udata);
316+
QEMU_PLUGIN_COND_NE, pc_after_block, pc, NULL);
312317

313318
/*
314319
* Now we can set start/end for this block so the next block can

contrib/plugins/hotblocks.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static guint64 limit = 20;
2929
*
3030
* The internals of the TCG are not exposed to plugins so we can only
3131
* get the starting PC for each block. We cheat this slightly by
32-
* xor'ing the number of instructions to the hash to help
32+
* checking the number of instructions as well to help
3333
* differentiate.
3434
*/
3535
typedef struct {
@@ -50,6 +50,20 @@ static gint cmp_exec_count(gconstpointer a, gconstpointer b)
5050
return count_a > count_b ? -1 : 1;
5151
}
5252

53+
static guint exec_count_hash(gconstpointer v)
54+
{
55+
const ExecCount *e = v;
56+
return e->start_addr ^ e->insns;
57+
}
58+
59+
static gboolean exec_count_equal(gconstpointer v1, gconstpointer v2)
60+
{
61+
const ExecCount *ea = v1;
62+
const ExecCount *eb = v2;
63+
return (ea->start_addr == eb->start_addr) &&
64+
(ea->insns == eb->insns);
65+
}
66+
5367
static void exec_count_free(gpointer key, gpointer value, gpointer user_data)
5468
{
5569
ExecCount *cnt = value;
@@ -91,7 +105,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
91105

92106
static void plugin_init(void)
93107
{
94-
hotblocks = g_hash_table_new(NULL, g_direct_equal);
108+
hotblocks = g_hash_table_new(exec_count_hash, exec_count_equal);
95109
}
96110

97111
static void vcpu_tb_exec(unsigned int cpu_index, void *udata)
@@ -111,10 +125,15 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
111125
ExecCount *cnt;
112126
uint64_t pc = qemu_plugin_tb_vaddr(tb);
113127
size_t insns = qemu_plugin_tb_n_insns(tb);
114-
uint64_t hash = pc ^ insns;
115128

116129
g_mutex_lock(&lock);
117-
cnt = (ExecCount *) g_hash_table_lookup(hotblocks, (gconstpointer) hash);
130+
{
131+
ExecCount e;
132+
e.start_addr = pc;
133+
e.insns = insns;
134+
cnt = (ExecCount *) g_hash_table_lookup(hotblocks, &e);
135+
}
136+
118137
if (cnt) {
119138
cnt->trans_count++;
120139
} else {
@@ -123,7 +142,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
123142
cnt->trans_count = 1;
124143
cnt->insns = insns;
125144
cnt->exec_count = qemu_plugin_scoreboard_new(sizeof(uint64_t));
126-
g_hash_table_insert(hotblocks, (gpointer) hash, (gpointer) cnt);
145+
g_hash_table_insert(hotblocks, cnt, cnt);
127146
}
128147

129148
g_mutex_unlock(&lock);

contrib/plugins/hotpages.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
103103
static void plugin_init(void)
104104
{
105105
page_mask = (page_size - 1);
106-
pages = g_hash_table_new(NULL, g_direct_equal);
106+
pages = g_hash_table_new(g_int64_hash, g_int64_equal);
107107
}
108108

109109
static void vcpu_haddr(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo,
@@ -130,12 +130,12 @@ static void vcpu_haddr(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo,
130130
page &= ~page_mask;
131131

132132
g_mutex_lock(&lock);
133-
count = (PageCounters *) g_hash_table_lookup(pages, GUINT_TO_POINTER(page));
133+
count = (PageCounters *) g_hash_table_lookup(pages, &page);
134134

135135
if (!count) {
136136
count = g_new0(PageCounters, 1);
137137
count->page_address = page;
138-
g_hash_table_insert(pages, GUINT_TO_POINTER(page), (gpointer) count);
138+
g_hash_table_insert(pages, &count->page_address, count);
139139
}
140140
if (qemu_plugin_mem_is_store(meminfo)) {
141141
count->writes++;

contrib/plugins/howvec.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ static struct qemu_plugin_scoreboard *find_counter(
253253
int i;
254254
uint64_t *cnt = NULL;
255255
uint32_t opcode = 0;
256+
/* if opcode is greater than 32 bits, we should refactor insn hash table. */
257+
G_STATIC_ASSERT(sizeof(opcode) == sizeof(uint32_t));
256258
InsnClassExecCount *class = NULL;
257259

258260
/*
@@ -284,7 +286,7 @@ static struct qemu_plugin_scoreboard *find_counter(
284286

285287
g_mutex_lock(&lock);
286288
icount = (InsnExecCount *) g_hash_table_lookup(insns,
287-
GUINT_TO_POINTER(opcode));
289+
(gpointer)(intptr_t) opcode);
288290

289291
if (!icount) {
290292
icount = g_new0(InsnExecCount, 1);
@@ -295,8 +297,7 @@ static struct qemu_plugin_scoreboard *find_counter(
295297
qemu_plugin_scoreboard_new(sizeof(uint64_t));
296298
icount->count = qemu_plugin_scoreboard_u64(score);
297299

298-
g_hash_table_insert(insns, GUINT_TO_POINTER(opcode),
299-
(gpointer) icount);
300+
g_hash_table_insert(insns, (gpointer)(intptr_t) opcode, icount);
300301
}
301302
g_mutex_unlock(&lock);
302303

0 commit comments

Comments
 (0)