From patchwork Tue Jan 14 11:37:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 857245 Delivered-To: patch@linaro.org Received: by 2002:a5d:525c:0:b0:385:e875:8a9e with SMTP id k28csp1873163wrc; Tue, 14 Jan 2025 03:43:15 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWBj6QW9Xjflc8U7yu4WpJrQZzQqmOr4llk1L71If9R90T1kTv6rAbMz1qHItXEKRQYvB3qUQ==@linaro.org X-Google-Smtp-Source: AGHT+IEOUAdJxdaBxRG+Ft8UAoTyeXojwnk6Mn9oxIKc+yJgH0Vfpz+Mbs6fVYpdzOYJi/VB3JiK X-Received: by 2002:a05:6214:5405:b0:6da:dc79:a3cd with SMTP id 6a1803df08f44-6df9b0ef91fmr409483076d6.0.1736854995723; Tue, 14 Jan 2025 03:43:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1736854995; cv=none; d=google.com; s=arc-20240605; b=WBPmYb/7j5QUrhU8bcac6fcLVM1Zz9equgvPttQs3Z1sXlKCuxr87sP/CHiQDfghg0 A80iqLnwbE1MVUw+3grFkAAzFPXkwK4Vsv4fLrsOWFiW8+SS4qjOp2doHGeUDl1T/8V/ rAstong5Z5JcsF8vhh6rs97hRNHbMTNiFVRzaiEn7Jy04xf5r3/Z2m3+N5loH793nzAD mh9ODHnhbBX01DHLbgtDEtk5CzXpuwXX6+Vbk2gOpQJCSkdvKO/Z/j6SaQK8cXumBGah 2pfB1wuH4eUcQxMJq48gj6cvjL8vFQEoXfFfbPczSZHlW4ZvyYvFuI94/Ik+GNfWjAZH HMJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ut5L3H7ENukAVXMf9ucpT4mEYkt3Qt71rdTcSo9h+fA=; fh=kybcMgHu6G3G1kz+Iwx2Y7lVQ4lMSqWHrwHMI/PcVVA=; b=MOP6JwV6ZFaahfQY2qCxPEwUNVOtkZRS00tmYPmZr5MmuGOQnhF3FecUnQ75QERejy e6iYbXWKzYPUUivcZ7Ze7S92Yxy07nJ9/o0FA4t5YDww1pQVOq+D184J4MK9zCKoXVqM By3YyGnHUIDc7qFvxdRfmNE8ucmTHK84PA6SVREdayqdLyPTyVduM80NLh0mLd0mo5nB 82VvFA09WAaIXd0sSQlvb+CUDyitLRVPHcF4lmeYLtmdH3AgDDMFpL0gDfp7Ka7OzoIg 9Tp04iXuiKMZ08IsMyRWjjV6djDo8vH6DuQC4NKgNE30GGoMmXPhBOWku/Ea6ujhUslr iaMw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=caQZd1pf; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6dfadedde94si119650746d6.306.2025.01.14.03.43.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 Jan 2025 03:43:15 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=caQZd1pf; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXfFr-0005BR-0K; Tue, 14 Jan 2025 06:38:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tXfFk-00057t-R7 for qemu-devel@nongnu.org; Tue, 14 Jan 2025 06:38:39 -0500 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tXfFh-0005Ql-Vu for qemu-devel@nongnu.org; Tue, 14 Jan 2025 06:38:36 -0500 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5d0ac27b412so7192202a12.1 for ; Tue, 14 Jan 2025 03:38:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736854711; x=1737459511; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ut5L3H7ENukAVXMf9ucpT4mEYkt3Qt71rdTcSo9h+fA=; b=caQZd1pfnd8EZ2W3jDsJ0H/AocTRhT4pTJe1AMpBJ9TC1AhKissI86DVBAbozCgIKf uzw0rF1tCQFA+W2rbvZJ0oV94yANJZPH+EOs8aXgaHg3XccM0sgkVquDMFhiRyYul2im Y5QqNDMaSXcpn3VSRbIq6oAPTXf2i7piJujLUEw5k5RAn9GpaTWm8PqE6JKEORePUdO1 yKzOSsrgtZIRAGyjdRGYU6D9w382Nb0H7iO44q0/eis+7r6jDsW9ZopQAYMuFkr2FslD /HogYkQlix/qBDGrFU4UYc2OfW6D2jhGKdupMvj169Rr8HdUDu6re416l0OhVP3qIQq6 OU3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736854711; x=1737459511; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ut5L3H7ENukAVXMf9ucpT4mEYkt3Qt71rdTcSo9h+fA=; b=X3Q6A1gDPSej+/b418TBiApfJTSyu/PR7iUhIlRLHGPtfj2M28S2+VM0TwfES7BtF8 i3+NHFuzWqGGOv/moEbJT0CpGEPGEIe/8IW6Jjcy0qid8yu+o0SKTBUhWcpVME10tkQW /0WI66HhNTQDU2919V5CfF52HToxlWFogjvZ6bCZMBYK9KFJDGDefuynoXCQkM+xSJ1o CWHom8tjaP0WVp5d0yQSyGKBEeUmwV3uxULU/bwn7gTToDb702dnE0Ukv5MiH0zJ64eJ 6Wa8Q7Y2R3jrPtFkS8bft4B5inPs1QkQSXd44Sq9KFn0Ecu+BxhmO9qHEIi3PdPyeapI T76g== X-Gm-Message-State: AOJu0YzqYJCnFRjW7WxvazWHK6oYMwaJONigXeUTxgy6RtS1iQf7/Roq sj5N4GgAaraTrwEzZ1IG3rvSzxT966HrFEZNqYenJPj2nY2KLBBUqHttViGlBK0= X-Gm-Gg: ASbGncuOe+BdkpV1u11jYKQinZn1YdWQhlseuBFITNfVwe/rseOVrM9YQspQ+vgyYCt AEKo6CGHEzKsJw8/FeR/gCMFhOwcse/+lPRYFlqqvwZL5vIp7nnY2PP57QNOgocQfnNcrxE/Jfo clwdFqcK6x87GYfjODXMMH9TWCXgssv7yYKIam45rep1DjbMTtd/9lvAO5xV3gZlu7zduFP6Ccq ZNZPM37QoyRYZKaN8PFIu3DkCjh965Iy5VK2I6/ptYNI4an3dt/ZY4= X-Received: by 2002:a17:906:c155:b0:aa6:b5e0:8c59 with SMTP id a640c23a62f3a-ab2ab74b2admr1811818166b.35.1736854711200; Tue, 14 Jan 2025 03:38:31 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c90dc570sm630304666b.51.2025.01.14.03.38.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 03:38:28 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 2C11C5FA05; Tue, 14 Jan 2025 11:38:23 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Stefan Weil , Pierrick Bouvier , Richard Henderson , =?utf-8?q?Alex_Benn=C3=A9?= =?utf-8?q?e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PATCH v2 15/37] contrib/plugins/stoptrigger: fix 32-bit build Date: Tue, 14 Jan 2025 11:37:59 +0000 Message-Id: <20250114113821.768750-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250114113821.768750-1-alex.bennee@linaro.org> References: <20250114113821.768750-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52b; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x52b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Pierrick Bouvier Signed-off-by: Pierrick Bouvier Reviewed-by: Richard Henderson Message-Id: <20241217224306.2900490-6-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée --- contrib/plugins/stoptrigger.c | 48 ++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/contrib/plugins/stoptrigger.c b/contrib/plugins/stoptrigger.c index 03ee22f4c6..b3a6ed66a7 100644 --- a/contrib/plugins/stoptrigger.c +++ b/contrib/plugins/stoptrigger.c @@ -21,9 +21,11 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; /* Scoreboard to track executed instructions count */ typedef struct { uint64_t insn_count; + uint64_t current_pc; } InstructionsCount; static struct qemu_plugin_scoreboard *insn_count_sb; static qemu_plugin_u64 insn_count; +static qemu_plugin_u64 current_pc; static uint64_t icount; static int icount_exit_code; @@ -34,6 +36,11 @@ static bool exit_on_address; /* Map trigger addresses to exit code */ static GHashTable *addrs_ht; +typedef struct { + uint64_t exit_addr; + int exit_code; +} ExitInfo; + static void exit_emulation(int return_code, char *message) { qemu_plugin_outs(message); @@ -43,23 +50,18 @@ static void exit_emulation(int return_code, char *message) static void exit_icount_reached(unsigned int cpu_index, void *udata) { - uint64_t insn_vaddr = GPOINTER_TO_UINT(udata); + uint64_t insn_vaddr = qemu_plugin_u64_get(current_pc, cpu_index); char *msg = g_strdup_printf("icount reached at 0x%" PRIx64 ", exiting\n", insn_vaddr); - exit_emulation(icount_exit_code, msg); } static void exit_address_reached(unsigned int cpu_index, void *udata) { - uint64_t insn_vaddr = GPOINTER_TO_UINT(udata); - char *msg = g_strdup_printf("0x%" PRIx64 " reached, exiting\n", insn_vaddr); - int exit_code; - - exit_code = GPOINTER_TO_INT( - g_hash_table_lookup(addrs_ht, GUINT_TO_POINTER(insn_vaddr))); - - exit_emulation(exit_code, msg); + ExitInfo *ei = udata; + g_assert(ei); + char *msg = g_strdup_printf("0x%" PRIx64 " reached, exiting\n", ei->exit_addr); + exit_emulation(ei->exit_code, msg); } static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) @@ -67,23 +69,25 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) size_t tb_n = qemu_plugin_tb_n_insns(tb); for (size_t i = 0; i < tb_n; i++) { struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i); - gpointer insn_vaddr = GUINT_TO_POINTER(qemu_plugin_insn_vaddr(insn)); + uint64_t insn_vaddr = qemu_plugin_insn_vaddr(insn); if (exit_on_icount) { /* Increment and check scoreboard for each instruction */ qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( insn, QEMU_PLUGIN_INLINE_ADD_U64, insn_count, 1); + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( + insn, QEMU_PLUGIN_INLINE_STORE_U64, current_pc, insn_vaddr); qemu_plugin_register_vcpu_insn_exec_cond_cb( insn, exit_icount_reached, QEMU_PLUGIN_CB_NO_REGS, - QEMU_PLUGIN_COND_EQ, insn_count, icount + 1, insn_vaddr); + QEMU_PLUGIN_COND_EQ, insn_count, icount + 1, NULL); } if (exit_on_address) { - if (g_hash_table_contains(addrs_ht, insn_vaddr)) { + ExitInfo *ei = g_hash_table_lookup(addrs_ht, &insn_vaddr); + if (ei) { /* Exit triggered by address */ qemu_plugin_register_vcpu_insn_exec_cb( - insn, exit_address_reached, QEMU_PLUGIN_CB_NO_REGS, - insn_vaddr); + insn, exit_address_reached, QEMU_PLUGIN_CB_NO_REGS, ei); } } } @@ -99,11 +103,13 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, int argc, char **argv) { - addrs_ht = g_hash_table_new(NULL, g_direct_equal); + addrs_ht = g_hash_table_new_full(g_int64_hash, g_int64_equal, NULL, g_free); insn_count_sb = qemu_plugin_scoreboard_new(sizeof(InstructionsCount)); insn_count = qemu_plugin_scoreboard_u64_in_struct( insn_count_sb, InstructionsCount, insn_count); + current_pc = qemu_plugin_scoreboard_u64_in_struct( + insn_count_sb, InstructionsCount, current_pc); for (int i = 0; i < argc; i++) { char *opt = argv[i]; @@ -124,13 +130,13 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, exit_on_icount = true; } else if (g_strcmp0(tokens[0], "addr") == 0) { g_auto(GStrv) addr_tokens = g_strsplit(tokens[1], ":", 2); - uint64_t exit_addr = g_ascii_strtoull(addr_tokens[0], NULL, 0); - int exit_code = 0; + ExitInfo *ei = g_malloc(sizeof(ExitInfo)); + ei->exit_addr = g_ascii_strtoull(addr_tokens[0], NULL, 0); + ei->exit_code = 0; if (addr_tokens[1]) { - exit_code = g_ascii_strtoull(addr_tokens[1], NULL, 0); + ei->exit_code = g_ascii_strtoull(addr_tokens[1], NULL, 0); } - g_hash_table_insert(addrs_ht, GUINT_TO_POINTER(exit_addr), - GINT_TO_POINTER(exit_code)); + g_hash_table_insert(addrs_ht, &ei->exit_addr, ei); exit_on_address = true; } else { fprintf(stderr, "option parsing failed: %s\n", opt);