From patchwork Fri Feb 23 16:21:53 2024 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: 775138 Delivered-To: patch@linaro.org Received: by 2002:adf:a356:0:b0:33b:4db1:f5b3 with SMTP id d22csp435281wrb; Fri, 23 Feb 2024 08:38:03 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCU2YkIbSGqGDRTMcnqlPZ0Er5Emrh9lfD5dFOhUfkg+o2qhOspmeit9/Q54r4Qtks0eG8e0bNt0Su5XHXjSDtCm X-Google-Smtp-Source: AGHT+IHjhgy+MXhxzmubaMddc1S2BhVI0BJ8QmHkjtSM1mGu/t6Y+Tr/rV8sUDtquSHN8OY1ZyZi X-Received: by 2002:a05:620a:1349:b0:787:aa51:56a0 with SMTP id c9-20020a05620a134900b00787aa5156a0mr362172qkl.43.1708706282851; Fri, 23 Feb 2024 08:38:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708706282; cv=none; d=google.com; s=arc-20160816; b=CYPY0fKXcVW2rlkQ7HvAf6I31ZXoViW0Iio4VdQn7mi7SBCbPQdBseNtK5/yVErWPQ 9V1oFtBTHcSXKzmo880J6K/guT5F4dl1jiSwOZsAJeid7jQABSegVd1GrK85FSEOK5vo YcIBWpC5WaIBvlr0dCn8E5jOam9JrHZ/Gv6FbdSJJKDiWU6vTq48Ru82e8fCheKU2xQ8 vmUVWQSAhdCWBA1nKC6drZyuSbZS5LcL+q6gF3/8M1/ymsn9Dsy1cLVwoCBBWQ+fZXh5 38EaIanwP2aCNMs3m8I/uyK4LDrKLq3BN3keBcNMU9Y7uXoZSL3patLPrhBpWhmJBKj2 yKFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=Nsgms6L+voXWYAHkd/mUu1uICRrRzOf2k5zfNnIBA/s=; fh=2IXDtwkhE3u9iDHwRQ543d03t9X1toYDqf9u6DZTCZM=; b=pI/wlYPnTa2LkS1S23uSnHI2UWJHzl21ZpVWmeZr9Gw3UiLVsgtOtFxeb9Y1q8GIjn 5l+y7T2LsEIvDeTGvlUsAV+h0f5ldpq6FTnivVS65KXNdEJZHrxnxX+CQ/v8d6FtRgwf Y9iJZuSNCBnf/+nosxJNg0RbIB5n8Gvipg1tPMMju6Tzh7qSLBYuiBppW8nT54R1ogbe fu3k+/xp9qJrRELgWYWmpV1Wb2D+xAb2YtouHxW2ZpkYeOVEkSqv1JD+PRXOC9OAzDWh yUYRKf/RIUjjz0AmAWZmYgzGOKLE0XFQ3ssug3Df9MicsDjjtAoUM1vcw8IUvibqdeTT yphg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QIMgcQoW; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m20-20020ae9f214000000b007876c15b6a0si10309810qkg.89.2024.02.23.08.38.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Feb 2024 08:38:02 -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=QIMgcQoW; 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 Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdYVt-0000hu-S4; Fri, 23 Feb 2024 11:35:05 -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 1rdYK2-0004KP-25 for qemu-devel@nongnu.org; Fri, 23 Feb 2024 11:22:50 -0500 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdYJX-00069d-1m for qemu-devel@nongnu.org; Fri, 23 Feb 2024 11:22:49 -0500 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-412985a51ecso803695e9.0 for ; Fri, 23 Feb 2024 08:22:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708705337; x=1709310137; 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=Nsgms6L+voXWYAHkd/mUu1uICRrRzOf2k5zfNnIBA/s=; b=QIMgcQoW4/nA3DKFo2fvNDacLixT3TYqOQCRvzTM3x75RZeqcvsNueClZVDK8VoImN dW4XBIM0+o1i6tY4TaaIgpVmzmqLf9Nh9cr8CCsBhlAM/UxZ6emkpPu0X8cFJVndsHAL zPumP2OhMFTNxnorPXH8rdDyO7LFbXKzbpK0A8D90xghcvQI2Jrx/xmtdhmI3l9QTlkh fGs+Do40RZt8lExstDpMmSYlQazNDJBaRjiXLDvw2TJy8R1Xjs8Az4Qw8KKA8SWB40VQ VVZpgXZy9z83ColdlD9fi/xeglUqCzMN6G1ys0zPwURGh8olmNxZzR6F53T7xLeqCZiQ zEvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708705337; x=1709310137; 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=Nsgms6L+voXWYAHkd/mUu1uICRrRzOf2k5zfNnIBA/s=; b=d/join3f4Bon+z9ZRM/G3LEH6gdxPysY7JE7zQN8GLbPpEgeQFDtZffDQ44WBkHfDo 69dFt0NSBQ6zBLBBRoV3u6sLV+C6fyk8jbpk0zvfSYvfWcVFa9Os43W+j0FXwFSSb0sn OU2JjU247sD40heuZo7pQSzQkZo0BH1fsdQ8tuEyTQeOI+Ul8j5SKVLBzEoA9drHRfuF fYcZOOL169C6KLaGVRkM27WI0qAoA/YjX7aIu8VblcdZlUk7KB3LlnaFYHU04HRse6lI eNn0sqOX6JmEfsbFZhDUMDCbrHzHO4pMLE/+6fGR+k0vZbR3SxtdAQJm+5FUgzVyoODR xEKw== X-Gm-Message-State: AOJu0YyPLczmC1wSpoAwDuMVVOjMTr9stx8VTPcfxBrQRcR6EqFHk9Du UdJHjp8q56PhZy1m3Bb+JO1XbRwnycJYDPD0N/0xKWCa3V2kPOEzQLK3waqpp7o= X-Received: by 2002:a05:600c:46d4:b0:412:913:5484 with SMTP id q20-20020a05600c46d400b0041209135484mr210513wmo.11.1708705337525; Fri, 23 Feb 2024 08:22:17 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id cc11-20020a5d5c0b000000b0033db2d6bf83sm448116wrb.34.2024.02.23.08.22.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 08:22:12 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 43F725F933; Fri, 23 Feb 2024 16:22:04 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Song Gao , qemu-s390x@nongnu.org, Liu Zhiwei , Pierrick Bouvier , Thomas Huth , Daniel Henrique Barboza , Bin Meng , Yanan Wang , Laurent Vivier , qemu-ppc@nongnu.org, David Hildenbrand , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Ilya Leoshkevich , Cleber Rosa , Nicholas Piggin , Marcel Apfelbaum , Eduardo Habkost , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= , Alexandre Iooss , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Daniel Henrique Barboza , qemu-arm@nongnu.org, qemu-riscv@nongnu.org, Palmer Dabbelt , Mahmoud Mandour , John Snow , Weiwei Li , Alistair Francis , Yoshinori Sato , Brian Cain , Paolo Bonzini , "Edgar E. Iglesias" , Michael Rolnik , Akihiko Odaki Subject: [PATCH v2 18/27] plugins: Use different helpers when reading registers Date: Fri, 23 Feb 2024 16:21:53 +0000 Message-Id: <20240223162202.1936541-19-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240223162202.1936541-1-alex.bennee@linaro.org> References: <20240223162202.1936541-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32a.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, T_SCC_BODY_TEXT_LINE=-0.01 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: Akihiko Odaki This avoids optimizations incompatible when reading registers. Signed-off-by: Akihiko Odaki Reviewed-by: Pierrick Bouvier Message-Id: <20240103173349.398526-37-alex.bennee@linaro.org> Message-Id: <20231213-gdb-v17-12-777047380591@daynix.com> Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- accel/tcg/plugin-helpers.h | 3 ++- include/qemu/plugin.h | 1 + accel/tcg/plugin-gen.c | 43 ++++++++++++++++++++++++++++++++++---- plugins/api.c | 12 +++++++++-- 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/accel/tcg/plugin-helpers.h b/accel/tcg/plugin-helpers.h index 8e685e06545..11796436f35 100644 --- a/accel/tcg/plugin-helpers.h +++ b/accel/tcg/plugin-helpers.h @@ -1,4 +1,5 @@ #ifdef CONFIG_PLUGIN -DEF_HELPER_FLAGS_2(plugin_vcpu_udata_cb, TCG_CALL_NO_RWG | TCG_CALL_PLUGIN, void, i32, ptr) +DEF_HELPER_FLAGS_2(plugin_vcpu_udata_cb_no_wg, TCG_CALL_NO_WG | TCG_CALL_PLUGIN, void, i32, ptr) +DEF_HELPER_FLAGS_2(plugin_vcpu_udata_cb_no_rwg, TCG_CALL_NO_RWG | TCG_CALL_PLUGIN, void, i32, ptr) DEF_HELPER_FLAGS_4(plugin_vcpu_mem_cb, TCG_CALL_NO_RWG | TCG_CALL_PLUGIN, void, i32, i32, i64, ptr) #endif diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index 7fdc3a4849f..b0c5ac68293 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -73,6 +73,7 @@ enum plugin_dyn_cb_type { enum plugin_dyn_cb_subtype { PLUGIN_CB_REGULAR, + PLUGIN_CB_REGULAR_R, PLUGIN_CB_INLINE, PLUGIN_N_CB_SUBTYPES, }; diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index 78b331b2510..b37ce7683e6 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -79,6 +79,7 @@ enum plugin_gen_from { enum plugin_gen_cb { PLUGIN_GEN_CB_UDATA, + PLUGIN_GEN_CB_UDATA_R, PLUGIN_GEN_CB_INLINE, PLUGIN_GEN_CB_MEM, PLUGIN_GEN_ENABLE_MEM_HELPER, @@ -90,7 +91,10 @@ enum plugin_gen_cb { * These helpers are stubs that get dynamically switched out for calls * direct to the plugin if they are subscribed to. */ -void HELPER(plugin_vcpu_udata_cb)(uint32_t cpu_index, void *udata) +void HELPER(plugin_vcpu_udata_cb_no_wg)(uint32_t cpu_index, void *udata) +{ } + +void HELPER(plugin_vcpu_udata_cb_no_rwg)(uint32_t cpu_index, void *udata) { } void HELPER(plugin_vcpu_mem_cb)(unsigned int vcpu_index, @@ -98,7 +102,7 @@ void HELPER(plugin_vcpu_mem_cb)(unsigned int vcpu_index, void *userdata) { } -static void gen_empty_udata_cb(void) +static void gen_empty_udata_cb(void (*gen_helper)(TCGv_i32, TCGv_ptr)) { TCGv_i32 cpu_index = tcg_temp_ebb_new_i32(); TCGv_ptr udata = tcg_temp_ebb_new_ptr(); @@ -106,12 +110,22 @@ static void gen_empty_udata_cb(void) tcg_gen_movi_ptr(udata, 0); tcg_gen_ld_i32(cpu_index, tcg_env, -offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index)); - gen_helper_plugin_vcpu_udata_cb(cpu_index, udata); + gen_helper(cpu_index, udata); tcg_temp_free_ptr(udata); tcg_temp_free_i32(cpu_index); } +static void gen_empty_udata_cb_no_wg(void) +{ + gen_empty_udata_cb(gen_helper_plugin_vcpu_udata_cb_no_wg); +} + +static void gen_empty_udata_cb_no_rwg(void) +{ + gen_empty_udata_cb(gen_helper_plugin_vcpu_udata_cb_no_rwg); +} + /* * For now we only support addi_i64. * When we support more ops, we can generate one empty inline cb for each. @@ -192,7 +206,8 @@ static void plugin_gen_empty_callback(enum plugin_gen_from from) gen_empty_mem_helper); /* fall through */ case PLUGIN_GEN_FROM_TB: - gen_wrapped(from, PLUGIN_GEN_CB_UDATA, gen_empty_udata_cb); + gen_wrapped(from, PLUGIN_GEN_CB_UDATA, gen_empty_udata_cb_no_rwg); + gen_wrapped(from, PLUGIN_GEN_CB_UDATA_R, gen_empty_udata_cb_no_wg); gen_wrapped(from, PLUGIN_GEN_CB_INLINE, gen_empty_inline_cb); break; default: @@ -588,6 +603,12 @@ static void plugin_gen_tb_udata(const struct qemu_plugin_tb *ptb, inject_udata_cb(ptb->cbs[PLUGIN_CB_REGULAR], begin_op); } +static void plugin_gen_tb_udata_r(const struct qemu_plugin_tb *ptb, + TCGOp *begin_op) +{ + inject_udata_cb(ptb->cbs[PLUGIN_CB_REGULAR_R], begin_op); +} + static void plugin_gen_tb_inline(const struct qemu_plugin_tb *ptb, TCGOp *begin_op) { @@ -602,6 +623,14 @@ static void plugin_gen_insn_udata(const struct qemu_plugin_tb *ptb, inject_udata_cb(insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_REGULAR], begin_op); } +static void plugin_gen_insn_udata_r(const struct qemu_plugin_tb *ptb, + TCGOp *begin_op, int insn_idx) +{ + struct qemu_plugin_insn *insn = g_ptr_array_index(ptb->insns, insn_idx); + + inject_udata_cb(insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_REGULAR_R], begin_op); +} + static void plugin_gen_insn_inline(const struct qemu_plugin_tb *ptb, TCGOp *begin_op, int insn_idx) { @@ -721,6 +750,9 @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) case PLUGIN_GEN_CB_UDATA: plugin_gen_tb_udata(plugin_tb, op); break; + case PLUGIN_GEN_CB_UDATA_R: + plugin_gen_tb_udata_r(plugin_tb, op); + break; case PLUGIN_GEN_CB_INLINE: plugin_gen_tb_inline(plugin_tb, op); break; @@ -737,6 +769,9 @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) case PLUGIN_GEN_CB_UDATA: plugin_gen_insn_udata(plugin_tb, op, insn_idx); break; + case PLUGIN_GEN_CB_UDATA_R: + plugin_gen_insn_udata_r(plugin_tb, op, insn_idx); + break; case PLUGIN_GEN_CB_INLINE: plugin_gen_insn_inline(plugin_tb, op, insn_idx); break; diff --git a/plugins/api.c b/plugins/api.c index 116b8bd603c..54df72c1c00 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -89,7 +89,11 @@ void qemu_plugin_register_vcpu_tb_exec_cb(struct qemu_plugin_tb *tb, void *udata) { if (!tb->mem_only) { - plugin_register_dyn_cb__udata(&tb->cbs[PLUGIN_CB_REGULAR], + int index = flags == QEMU_PLUGIN_CB_R_REGS || + flags == QEMU_PLUGIN_CB_RW_REGS ? + PLUGIN_CB_REGULAR_R : PLUGIN_CB_REGULAR; + + plugin_register_dyn_cb__udata(&tb->cbs[index], cb, flags, udata); } } @@ -109,7 +113,11 @@ void qemu_plugin_register_vcpu_insn_exec_cb(struct qemu_plugin_insn *insn, void *udata) { if (!insn->mem_only) { - plugin_register_dyn_cb__udata(&insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_REGULAR], + int index = flags == QEMU_PLUGIN_CB_R_REGS || + flags == QEMU_PLUGIN_CB_RW_REGS ? + PLUGIN_CB_REGULAR_R : PLUGIN_CB_REGULAR; + + plugin_register_dyn_cb__udata(&insn->cbs[PLUGIN_CB_INSN][index], cb, flags, udata); } }