From patchwork Wed Jul 31 16:06:26 2019 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: 11068587 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C999912 for ; Wed, 31 Jul 2019 16:09:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3747D27F2B for ; Wed, 31 Jul 2019 16:09:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B59F205A4; Wed, 31 Jul 2019 16:09:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C472D28066 for ; Wed, 31 Jul 2019 16:09:32 +0000 (UTC) Received: from localhost ([::1]:42342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrAR-0004LK-Sm for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:09:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40175) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsr8O-000220-8R for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsr8N-0000bn-7a for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:24 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:36637) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsr8M-0000aZ-UE for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:23 -0400 Received: by mail-wr1-x442.google.com with SMTP id n4so70383564wrs.3 for ; Wed, 31 Jul 2019 09:07:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BaXv1gxEuljYaje+hDfDXRtILG3ZeT8f0aD36Klyo9c=; b=sb3fmYCXvcBIFBymPMWalTLUOpAbWOteQclHXy7FnJExFFrkzOYQoguvAH1lD3QR0J dN1ZmK35Ulc/ANwNfl3kthVlisVySXVZi6p/L/od1lwC6YM0W46r05zO7Bcg+Obd+CWe AP5vTp8qBYYxTTzIZ76GagnLi210R1oONKmCmzBJwrOuAyVQ+iaUqsBfc88fV8Ne5pHQ TgfWH0yP+/wmQiTpZJUqw8F3pVr45HU51cPBkq3Yym/OzCKf4SgksoRQMYAVxctmUKBN 9MYY4ui9Qk8kng03WsIyQ6rsvIfG/kDJNE5A+tQvU7V/VeMCR/5G5lMrDoTMizolgeXq UtZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BaXv1gxEuljYaje+hDfDXRtILG3ZeT8f0aD36Klyo9c=; b=Mhoj8aMOcXTUtuRgYQnXFZTSBvUHmE7WLZw/69ZlPdq8MpFJi5e3ZjoZ0DzQKLweAb ptOhSBtH2tp6Q1Fip8nULKukBvWFtTvYZJ8CmkIpBgD0FVcxx0SVACROxzUOSCOeme+Y jpynpyClYCPw52FghIM/CahoXND0Ze3MEb14OGDSKnj2nrLjvP8iz7m2T47zphi/BOGi V9UoitZZcRN0kEzb+V27HACdAGeMk+n4manOEfA9XxagIaCol1g4DkIKStIUgSOQBv/m hTTTNeetZIEaypmWwhMJJ9F4i2YmMVjXKYGNQIkZZUtUmLXZbwftbnsYuc6EnqnP+pbF Iy3A== X-Gm-Message-State: APjAAAVVXXjF8BjYvbWtyuxuz4mX69td5eUaaYM01dxni9ryUSojnxyu 1AmiY3qPMohtw/4HJZJbaRSgJA== X-Google-Smtp-Source: APXvYqx2kVDaK2wid8La7qtnYhl346vxT88x9tVsuZakK4ByPzS/a8xLyVWxIg/gFBWteQ1aNZ7FLA== X-Received: by 2002:a5d:4941:: with SMTP id r1mr130043288wrs.225.1564589241724; Wed, 31 Jul 2019 09:07:21 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id r15sm72111534wrj.68.2019.07.31.09.07.19 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:07:20 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 8D6121FF8C; Wed, 31 Jul 2019 17:07:19 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:26 +0100 Message-Id: <20190731160719.11396-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PATCH v4 01/54] target/arm: handle M-profile semihosting at translate time X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Richard Henderson , aaron@os.amperecomputing.com, cota@braap.org, "open list:ARM TCG CPUs" , bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We do this for other semihosting calls so we might as well do it for M-profile as well. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- target/arm/m_helper.c | 18 ++++++------------ target/arm/translate.c | 20 +++++++++++++++++++- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/target/arm/m_helper.c b/target/arm/m_helper.c index 84609f446e6..129d52a56bf 100644 --- a/target/arm/m_helper.c +++ b/target/arm/m_helper.c @@ -2113,19 +2113,13 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) break; } break; + case EXCP_SEMIHOST: + qemu_log_mask(CPU_LOG_INT, + "...handling as semihosting call 0x%x\n", + env->regs[0]); + env->regs[0] = do_arm_semihosting(env); + return; case EXCP_BKPT: - if (semihosting_enabled()) { - int nr; - nr = arm_lduw_code(env, env->regs[15], arm_sctlr_b(env)) & 0xff; - if (nr == 0xab) { - env->regs[15] += 2; - qemu_log_mask(CPU_LOG_INT, - "...handling as semihosting call 0x%x\n", - env->regs[0]); - env->regs[0] = do_arm_semihosting(env); - return; - } - } armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_DEBUG, false); break; case EXCP_IRQ: diff --git a/target/arm/translate.c b/target/arm/translate.c index 7853462b21b..0b02c520395 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -10976,6 +10976,24 @@ illegal_op: default_exception_el(s)); } +/* + * Thumb BKPT. On M-profile CPUs this may be a semihosting call which + * we can process much the same way as gen_hlt() above. + */ +static inline void gen_thumb_bkpt(DisasContext *s, int imm8) +{ + if (arm_dc_feature(s, ARM_FEATURE_M) && + semihosting_enabled() && +#ifndef CONFIG_USER_ONLY + s->current_el != 0 && +#endif + (imm8 == 0xab)) { + gen_exception_internal_insn(s, 0, EXCP_SEMIHOST); + return; + } + gen_exception_bkpt_insn(s, 2, syn_aa32_bkpt(imm8, true)); +} + static void disas_thumb_insn(DisasContext *s, uint32_t insn) { uint32_t val, op, rm, rn, rd, shift, cond; @@ -11611,7 +11629,7 @@ static void disas_thumb_insn(DisasContext *s, uint32_t insn) { int imm8 = extract32(insn, 0, 8); ARCH(5); - gen_exception_bkpt_insn(s, 2, syn_aa32_bkpt(imm8, true)); + gen_thumb_bkpt(s, imm8); break; } From patchwork Wed Jul 31 16:06:27 2019 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: 11068583 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 660CA746 for ; Wed, 31 Jul 2019 16:09:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53AB9205A4 for ; Wed, 31 Jul 2019 16:09:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4793727C05; Wed, 31 Jul 2019 16:09:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 67C98205A4 for ; Wed, 31 Jul 2019 16:09:14 +0000 (UTC) Received: from localhost ([::1]:42336 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrA9-0003yn-J0 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:09:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40174) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsr8O-00021z-8B for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsr8N-0000be-72 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:24 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:40519) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsr8M-0000aF-TY for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:23 -0400 Received: by mail-wr1-x442.google.com with SMTP id r1so70281970wrl.7 for ; Wed, 31 Jul 2019 09:07:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qkiw3jBwg/vICATtfRTry9vznckLVpbUV1wDKMXT5GE=; b=j0ex1P+VZmKuzOcUzLHFA1DkvDrTWj0nCyfYZqB2dcoD7k6OGXFl+1CPQDgL4BnlMP dhsWZuOD3zK9OAGjVmWpqF7y0EM7RUqGIHfCY2Tn/WgN4/11+QvKtz0jFGVNMxzNTlbl NQTfFeVuGO6jHkwmzAsoKHG57r74kDXgpKrLFv6g9n/vBlPRJ9OFySx8F8nbc0hieCCv 6sgXTSO5ItUEOXIZwTEha34BLvT3y1Lj9OnFrSbzv2t5ldiBMEUWYwF6BAkon/NSaJQm 5nHMGW26Zc1SakGWOAusGgqtXHGrZD7lzBqJDmAuIteCKa8foFZmcwmeI7rmW88BxoNp x8FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qkiw3jBwg/vICATtfRTry9vznckLVpbUV1wDKMXT5GE=; b=dD+91ttFZbTicfaXNq0v462UGGY+a55o0AYK3T/lrNOjtLwwV9YI+H7CMoOIHLaZ3h Mhogk/a02ZpqZmv98fsLfS6SvPVjriyn2gsmdh2wQITVdV571XnoHq99v8DaDNvNj987 dzmqWfmPj8T3sq8zuXu/ZT4OUck7zUwC8/aJc/FfoQeWR/45oMqArHwVGCv5UkGBoy0w Vr7rb2KYDeyVtUF8eEod6fcy8WscEATpNgaep+JcZ/Q/0TeuwL8K9R6uUGhrzETj7PcM 6rAEKZ9TWuD67tWuCJguBnIhJeLrdPvIHZjuPc319gVEzPuLbkKZuNWiR88GeB9JZNOe ek9g== X-Gm-Message-State: APjAAAVSKvoJfybS84kW0A/XAojY2GF90tRaFfOwO63sjL+t1BtdJvSg tnBuUXYDuo1nAioF7cUH1rFBwQ== X-Google-Smtp-Source: APXvYqw1zRVEORnd48ZvKdvz/39bCPB0QF5U9Omhd6pI/uOrZl3ZpZJV7Xl6K8hn/GHq4yH9WYwRQw== X-Received: by 2002:a5d:56c7:: with SMTP id m7mr13439910wrw.64.1564589240911; Wed, 31 Jul 2019 09:07:20 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id n9sm114495893wrp.54.2019.07.31.09.07.19 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:07:20 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id A1B441FF8F; Wed, 31 Jul 2019 17:07:19 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:27 +0100 Message-Id: <20190731160719.11396-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PATCH v4 02/54] target/arm: handle A-profile T32 semihosting at translate time X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Richard Henderson , aaron@os.amperecomputing.com, cota@braap.org, "open list:ARM TCG CPUs" , bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP As for the other semihosting calls we can resolve this at translate time. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- target/arm/translate.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/target/arm/translate.c b/target/arm/translate.c index 0b02c520395..662d6f49115 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -10994,6 +10994,24 @@ static inline void gen_thumb_bkpt(DisasContext *s, int imm8) gen_exception_bkpt_insn(s, 2, syn_aa32_bkpt(imm8, true)); } +/* + * Thumb SWI. On A-profile CPUs this may be a semihosting call. + */ +static inline void gen_thumb_swi(DisasContext *s, int imm8) +{ + if (semihosting_enabled() && +#ifndef CONFIG_USER_ONLY + s->current_el != 0 && +#endif + (imm8 == 0xab)) { + gen_exception_internal_insn(s, 0, EXCP_SEMIHOST); + return; + } + gen_set_pc_im(s, s->pc); + s->svc_imm = imm8; + s->base.is_jmp = DISAS_SWI; +} + static void disas_thumb_insn(DisasContext *s, uint32_t insn) { uint32_t val, op, rm, rn, rd, shift, cond; @@ -11758,10 +11776,8 @@ static void disas_thumb_insn(DisasContext *s, uint32_t insn) goto undef; if (cond == 0xf) { - /* swi */ - gen_set_pc_im(s, s->pc); - s->svc_imm = extract32(insn, 0, 8); - s->base.is_jmp = DISAS_SWI; + /* swi/svc */ + gen_thumb_swi(s, extract32(insn, 0, 8)); break; } /* generate a conditional jump to next instruction */ From patchwork Wed Jul 31 16:06:28 2019 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: 11068585 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EAFD814DB for ; Wed, 31 Jul 2019 16:09:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8FDB26E7B for ; Wed, 31 Jul 2019 16:09:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD66B27C05; Wed, 31 Jul 2019 16:09:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D717A26E7B for ; Wed, 31 Jul 2019 16:09:14 +0000 (UTC) Received: from localhost ([::1]:42338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrAA-000419-7T for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:09:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40239) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsr8U-00022J-2V for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsr8O-0000dM-P9 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:29 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:35770) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsr8O-0000bI-7S for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:24 -0400 Received: by mail-wm1-x344.google.com with SMTP id l2so60318606wmg.0 for ; Wed, 31 Jul 2019 09:07:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JEIhsoUVe/t2uBROzqs6p6wGD1/psRv2lgg50pkn0Cw=; b=cduasaV5SuAXu9fYxB4y5rpUSMxkR6CW9rKalNPPx1C5RQfwqkQGImFKAgSfPNNKmV lVrCEJmDXp8/Dg49ixeYLENJTKVgSSB5wz5z1fHnaLUR2FxKuhLsO21jmOZRbHfI16Vk kVQONHFlMVsfT8qFawZo28BrUphomvyR1MQnhOSJZO9g020DnxIRdO+QXOmbxlNwIETc AcD2tAsB1irO6er6Nc6zIQAJbXiHwijRwBLSa/3EldfS+keboB8ftABk8vV9NTwcTaIA W6pF7I6j186Dt5vbNBLIGnDYyiUA8cwo17xESMFSN9ZvyQbbAEoY0BVMhElBM7bRib0m Z6uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JEIhsoUVe/t2uBROzqs6p6wGD1/psRv2lgg50pkn0Cw=; b=tqo9jSr17RR6NTDJ2w+106y2fq5AvKER/Nld2rMOUkaMatNONKnl0IrnRtFySFAaYm wlJSrYuoNKUo7wtvwjRvFXGChgFOvQ34jOpjpXJOObD6EIBKDD7a6uijym0y99zhmxDT Fbqcn2nbHJCvUZQGs3M1GNqkvCD9r7iYr/a9YGwEuJuK6VSvcZxLUT2zkdGl5IIvKTUe FJDUCLNqBGxAiroTh9bmVnP+C48j/SxSLTqQVwMnxen/ZFgEjhNjclgvHbLGHsx+JFvS 6/pBRD74MY8w7/sjbAfqTJ6YxVzZpi5wnNiGypkSDaPpc3uolYa0C8Y3ihCK/2ONDRkM SMJQ== X-Gm-Message-State: APjAAAVLQ38m9Cj2E0qcqUCZtlZsLQUqVHOKxNnUQ9Q2xbY15lGnlPJK 1ct2dyHCYnS7MEMFzis3UDe3ROPjHfI= X-Google-Smtp-Source: APXvYqyX0VwEQ5jcPnSFugLIR8CX/1cAaIk7a4XUdejJxpHFgqHEsaj7brqle0Pjwld1DAMgv0dx/A== X-Received: by 2002:a7b:cb94:: with SMTP id m20mr107284760wmi.144.1564589242451; Wed, 31 Jul 2019 09:07:22 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id i12sm81289977wrx.61.2019.07.31.09.07.20 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:07:20 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B50E01FF90; Wed, 31 Jul 2019 17:07:19 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:28 +0100 Message-Id: <20190731160719.11396-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 Subject: [Qemu-devel] [PATCH v4 03/54] target/arm: handle A-profile A32 semihosting at translate time X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Richard Henderson , aaron@os.amperecomputing.com, cota@braap.org, "open list:ARM TCG CPUs" , bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP As for the other semihosting calls we can resolve this at translate time. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- target/arm/translate.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/target/arm/translate.c b/target/arm/translate.c index 662d6f49115..4cb0e6fd835 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -7698,6 +7698,22 @@ static void arm_skip_unless(DisasContext *s, uint32_t cond) arm_gen_test_cc(cond ^ 1, s->condlabel); } +static inline void gen_arm_swi(DisasContext *s, int imm24) +{ + if (semihosting_enabled() && +#ifndef CONFIG_USER_ONLY + s->current_el != 0 && +#endif + (imm24 == 0x123456)) { + gen_exception_internal_insn(s, 0, EXCP_SEMIHOST); + return; + } + + gen_set_pc_im(s, s->pc); + s->svc_imm = imm24; + s->base.is_jmp = DISAS_SWI; +} + static void disas_arm_insn(DisasContext *s, unsigned int insn) { unsigned int cond, val, op1, i, shift, rm, rs, rn, rd, sh; @@ -9248,9 +9264,7 @@ static void disas_arm_insn(DisasContext *s, unsigned int insn) break; case 0xf: /* swi */ - gen_set_pc_im(s, s->pc); - s->svc_imm = extract32(insn, 0, 24); - s->base.is_jmp = DISAS_SWI; + gen_arm_swi(s, extract32(insn, 0, 24)); break; default: illegal_op: From patchwork Wed Jul 31 16:06:29 2019 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: 11068591 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 32F7D912 for ; Wed, 31 Jul 2019 16:11:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 218A9205FC for ; Wed, 31 Jul 2019 16:11:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 15C8826D08; Wed, 31 Jul 2019 16:11:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7228D26E73 for ; Wed, 31 Jul 2019 16:11:11 +0000 (UTC) Received: from localhost ([::1]:42364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrC2-0007S8-Nr for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:11:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40242) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsr8U-00022M-2w for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsr8O-0000dZ-QZ for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:29 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:46242) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsr8O-0000cL-C2 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:24 -0400 Received: by mail-wr1-x444.google.com with SMTP id z1so70279133wru.13 for ; Wed, 31 Jul 2019 09:07:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SWna9UxNFjHgSxxpvUscIhoIHkEj4BqQ4tH+9BGOa3A=; b=UO5G9+rcGZ5XmAXAxpryg7fOu5CohkrhcC0NWHWk2zbNSnedwbSgdSedzKdZVklKl3 vWts0bzK+80fVS8FzhiGS5SzOpL3c9IQ2/5vEdFA0wzY+hChEG2X+5rRflelaUIr2zPN zj9vfXyr7pLNjuuI7FDnOXawx2GKxh2jASiU0eO4V1gMCsrvAp9/jdF51zV8tqiqPtM2 hXTsDDeCkH9yytBhQqgJfaTAV5kDSMjk4ySksDcEdj33N80+yx0mc23gNnTDw4yLN9KA fEASMzsiKAmKK6DDNjbfVZ/VR2Uf3NLUF1lsXTaKCffcNAAT5Hp54JJslX0A7djoM+wP rY2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SWna9UxNFjHgSxxpvUscIhoIHkEj4BqQ4tH+9BGOa3A=; b=B3iP3KQ3ufyGTtK3Ttm+PAUhbhO+AkCZjeLnbuIF/QkGtVbb9JOgfonh7nFxxxpTEh m3T2Uuql4fLLNNUWy7mukzlKCJc211bje1AnMA7ws2m7fJ+skWqsQxR49IcQWzW7Nufe WHeCa4R8wds7F3FAxA/VqEyncAmmSYM+YPr9JF2bw9JY4QioCorVfQa02VNhk+Hp3qIW TF2Up2aXR2ddYLjC6GBm/84o1+Ij1DJQBeBU/EzTf+S7lnDiVwl0Up6pkOoHKLYqOtZt 6Kft5KzIayUN5xzwNENJLDy/jKezPguI8B+KIRaZTz9oRWixU/UfwqwppQD9TMFFhxNc ZrIw== X-Gm-Message-State: APjAAAWf6M8IXPZwuB3R818VA+hVqGJdCmMp60UsH7AiMGqXG4hsAB/z Ib6+OeVdgVrMBkAaikM9lnAPgw== X-Google-Smtp-Source: APXvYqz3GnwA05tW0vBlHCYvNyfgu8hypO9oW57pfsupEm56IiJchEx0NHftAK0dCsP7wFUafbsFDw== X-Received: by 2002:adf:cd04:: with SMTP id w4mr86500409wrm.230.1564589242963; Wed, 31 Jul 2019 09:07:22 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id p10sm2143203wmk.2.2019.07.31.09.07.20 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:07:20 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C8BD71FF91; Wed, 31 Jul 2019 17:07:19 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:29 +0100 Message-Id: <20190731160719.11396-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH v4 04/54] target/arm: remove run time semihosting checks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , aaron@os.amperecomputing.com, cota@braap.org, "open list:ARM TCG CPUs" , bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Now we do all our checking and use a common EXCP_SEMIHOST for semihosting operations we can make helper code a lot simpler. Signed-off-by: Alex Bennée --- v2 - fix re-base conflicts - hoist EXCP_SEMIHOST check - comment cleanups --- target/arm/helper.c | 90 +++++++++------------------------------------ 1 file changed, 18 insertions(+), 72 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index b74c23a9bc0..c5b90a83d36 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -8259,86 +8259,30 @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs) new_el, env->pc, pstate_read(env)); } -static inline bool check_for_semihosting(CPUState *cs) +/* + * Do semihosting call and set the appropriate return value. All the + * permission and validity checks have been done at translate time. + * + * We only see semihosting exceptions in TCG only as they are not + * trapped to the hypervisor in KVM. + */ +static void handle_semihosting(CPUState *cs) { #ifdef CONFIG_TCG - /* Check whether this exception is a semihosting call; if so - * then handle it and return true; otherwise return false. - */ ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; if (is_a64(env)) { - if (cs->exception_index == EXCP_SEMIHOST) { - /* This is always the 64-bit semihosting exception. - * The "is this usermode" and "is semihosting enabled" - * checks have been done at translate time. - */ - qemu_log_mask(CPU_LOG_INT, - "...handling as semihosting call 0x%" PRIx64 "\n", - env->xregs[0]); - env->xregs[0] = do_arm_semihosting(env); - return true; - } - return false; + qemu_log_mask(CPU_LOG_INT, + "...handling as semihosting call 0x%" PRIx64 "\n", + env->xregs[0]); + env->xregs[0] = do_arm_semihosting(env); } else { - uint32_t imm; - - /* Only intercept calls from privileged modes, to provide some - * semblance of security. - */ - if (cs->exception_index != EXCP_SEMIHOST && - (!semihosting_enabled() || - ((env->uncached_cpsr & CPSR_M) == ARM_CPU_MODE_USR))) { - return false; - } - - switch (cs->exception_index) { - case EXCP_SEMIHOST: - /* This is always a semihosting call; the "is this usermode" - * and "is semihosting enabled" checks have been done at - * translate time. - */ - break; - case EXCP_SWI: - /* Check for semihosting interrupt. */ - if (env->thumb) { - imm = arm_lduw_code(env, env->regs[15] - 2, arm_sctlr_b(env)) - & 0xff; - if (imm == 0xab) { - break; - } - } else { - imm = arm_ldl_code(env, env->regs[15] - 4, arm_sctlr_b(env)) - & 0xffffff; - if (imm == 0x123456) { - break; - } - } - return false; - case EXCP_BKPT: - /* See if this is a semihosting syscall. */ - if (env->thumb) { - imm = arm_lduw_code(env, env->regs[15], arm_sctlr_b(env)) - & 0xff; - if (imm == 0xab) { - env->regs[15] += 2; - break; - } - } - return false; - default: - return false; - } - qemu_log_mask(CPU_LOG_INT, "...handling as semihosting call 0x%x\n", env->regs[0]); env->regs[0] = do_arm_semihosting(env); - return true; } -#else - return false; #endif } @@ -8371,11 +8315,13 @@ void arm_cpu_do_interrupt(CPUState *cs) return; } - /* Semihosting semantics depend on the register width of the - * code that caused the exception, not the target exception level, - * so must be handled here. + /* + * Semihosting semantics depend on the register width of the code + * that caused the exception, not the target exception level, so + * must be handled here. */ - if (check_for_semihosting(cs)) { + if (cs->exception_index == EXCP_SEMIHOST) { + handle_semihosting(cs); return; } From patchwork Wed Jul 31 16:06:30 2019 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: 11068647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A3B9912 for ; Wed, 31 Jul 2019 16:18:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77EB91FE8D for ; Wed, 31 Jul 2019 16:18:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B9961FFBD; Wed, 31 Jul 2019 16:18:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 122F21FE8D for ; Wed, 31 Jul 2019 16:18:51 +0000 (UTC) Received: from localhost ([::1]:42482 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrJS-0004Y8-Dt for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:18:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40442) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsr8m-0002AZ-9v for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsr8h-0000mO-Fi for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:45 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:42500) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsr8f-0000dv-6T for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:41 -0400 Received: by mail-wr1-x441.google.com with SMTP id x1so20404052wrr.9 for ; Wed, 31 Jul 2019 09:07:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uLNFFdsSuak+Uy2t3FRbExjx92r6RyqLYQAFwuvDHzw=; b=HLAQf80lv0Lb/1bSS69wcmuEszlSD+YIxlbf6jVuGFw++d1bTM9wPioHO2Res0xz64 CzB7qmOtWf8iZWDzTb0j25GNDreDP3VXg5v+QUyQNpXz91odPYht908236wXvTIJ2q0w Hyma+8H7IQO2IJJW5uFlpe3JuistRDQAnGh15BuMsJi8Ijz54lo3erWearoEJn+xaF9I JPqk4f4ul+sSsL1kmGUXK+IoODkZW1zfX9cNy1GC3GSNhKYfrkMiHEjHPe/xLvIP5ZYy 8+IpEtqmIGJ7AVO4tE3I18SAd3/N/rmasggBzg+MuDzkIhdaahUfUAkXLuTEH2MjhnVh wAsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uLNFFdsSuak+Uy2t3FRbExjx92r6RyqLYQAFwuvDHzw=; b=cTHVkTPqBU2AzxWNIzH5N/hXHJASos4SJ6huZ0srBCD/gAubYr493gmHii0OA3EVeV mqeh/WLBHR0CzCLhTW3bWkE9HiQE4R9mOa2SkGLdig6EKIg3Q922lxWNqzW1ByGcNu0y B3jPu5HRekg4u8cOf6XTjtW+jTH7scYt5cugklNFUZHBPnFrSickLPIJ1SDgjDfIjvgx kHbw6ccpn9hm8rJN0GGyaHtMpSkhDjKNJ5N3lxwBe+srCZDD+BUqpi6tu7+6P2Bq6szu 4dwKB+Rx3Ac7ZUiTuiBNLrvRHQxZ9M/Fe669gi8t8zzdf/fN9khMFy5nRBcDOKzyYfMt YurA== X-Gm-Message-State: APjAAAWZXHGePHIaNK9LhmdosI+Xr7W6f4zAr6mqhjYVmKEa3y1ZIHJA nWnfv0KtNQct/nAKqgPzppLQYA== X-Google-Smtp-Source: APXvYqxtiPUqHMCXlkNYlvFTBvypJCnxo2XtuLeNGBhqTIXlO+qcEj+YcqvTNwqZqAHKI+WtAH3qrA== X-Received: by 2002:adf:ec8e:: with SMTP id z14mr12171241wrn.269.1564589244646; Wed, 31 Jul 2019 09:07:24 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id t185sm59154541wma.11.2019.07.31.09.07.20 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:07:23 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id DD0A51FF92; Wed, 31 Jul 2019 17:07:19 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:30 +0100 Message-Id: <20190731160719.11396-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PATCH v4 05/54] includes: remove stale [smp|max]_cpus externs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bobby.prani@gmail.com, cota@braap.org, =?utf-8?q?Alex_Benn=C3=A9e?= , aaron@os.amperecomputing.com, Like Xu Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Commit a5e0b3311 removed these in favour of querying machine properties. Remove the extern declarations as well. Signed-off-by: Alex Bennée Cc: Like Xu Message-Id: <20190711130546.18578-1-alex.bennee@linaro.org> Reviewed-by: Richard Henderson --- include/sysemu/sysemu.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 984c439ac96..e70edf7c1cf 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -103,8 +103,6 @@ extern const char *keyboard_layout; extern int win2k_install_hack; extern int alt_grab; extern int ctrl_grab; -extern int smp_cpus; -extern unsigned int max_cpus; extern int cursor_hide; extern int graphic_rotate; extern int no_quit; From patchwork Wed Jul 31 16:06:31 2019 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: 11068601 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8DEED912 for ; Wed, 31 Jul 2019 16:13:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C9D322362 for ; Wed, 31 Jul 2019 16:13:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70E4622B39; Wed, 31 Jul 2019 16:13:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1EBF021327 for ; Wed, 31 Jul 2019 16:13:14 +0000 (UTC) Received: from localhost ([::1]:42388 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrE1-0002OR-CQ for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:13:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40293) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsr8Z-00025f-Sf for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsr8W-0000hT-A8 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:34 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:35769) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsr8T-0000dG-V1 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:30 -0400 Received: by mail-wm1-x342.google.com with SMTP id l2so60318717wmg.0 for ; Wed, 31 Jul 2019 09:07:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=q2ZVpkuPZWWQPipjqK7QM3P7xcGJr7m8OUgkDGruy80=; b=yPHwt37CO8xUdFkdMw0bpZRaFeSdTJIGAsDdqTiQlRFh63rYPgIUS1Dejn8lsSvvFZ 56FeZqkcNA5kMQJL8DSNBmwY3cskkyHQcoQp9GXl3CySbkZoFCmiE3YJ8WhxF1qhqpnR p3f4KNTEiizPqmgWm22UGHzSUyzlvc5PG1WYtJ4czezbzpepFHHmUEOeeBlfavTAQgBo 1MoZxkrh0vich5TRTOtSDj0GtKq4fPb/hIynlvX1U4cs98uZuMQv35XQKbeKY6AXwAYJ 9h41q9OdAnTVoKnJdMwIEy+RGjowYpmwpH+I5xt89xZ/2cBi1SHDZkE4RsO80KoSfL9b ifNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=q2ZVpkuPZWWQPipjqK7QM3P7xcGJr7m8OUgkDGruy80=; b=bxMBsN4CqoqGsBq02QMSZuW4tAFEy/HNbCGG1kuQkWvfik3s38nKXjVFmhEcy9dZmJ KmTn3GTpvGu4x/INmHxeLy7vtXU85bJ5r3Bhki1Bet/96V2D2ai7SqNuyN5bf8CHcCGE +kRC19btV+VMznAKnuTBOff6g2ps85R7gUZKs3WoMQp41GCCcgSh3gEelT6/GE/HYq1F d4MRfp8Fdm6ycRTjshOD/h8IYPrjUQF3Grdo4ps7Bm/lJhUSWDtcLeWV4lMJ+iTG6E1z eM64bao/93r6ItYZq80u1vx7H+4BpUU5YF7C283Dw5VCMmTGBrXc/DB8cGBwe3c+iKMb m/hg== X-Gm-Message-State: APjAAAUFhPB68apXfdMKxmWNVXV2U0ltElL/ypQXKJFiVQg/zhbiKQan 7CTqSTdYX/7M7yOu28lFDR9o0A== X-Google-Smtp-Source: APXvYqwjijozrDRhWUAndMWO5/xdg0VgA1fpRQYaJeShpUiGqcveaJquSgLpfUt1lvD7+ylXBxEg9A== X-Received: by 2002:a1c:be11:: with SMTP id o17mr110956032wmf.115.1564589244207; Wed, 31 Jul 2019 09:07:24 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id y16sm149394681wrg.85.2019.07.31.09.07.20 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:07:23 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id F01FB1FF93; Wed, 31 Jul 2019 17:07:19 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:31 +0100 Message-Id: <20190731160719.11396-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 Subject: [Qemu-devel] [PATCH v4 06/54] trace: expand mem_info:size_shift to 4 bits X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bobby.prani@gmail.com, cota@braap.org, =?utf-8?q?Alex_Benn=C3=A9e?= , aaron@os.amperecomputing.com, Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" This will allow us to trace 32k-long memory accesses (although our maximum is something like 256 bytes at the moment). Reviewed-by: Alex Bennée Signed-off-by: Emilio G. Cota [AJB: expanded to 3->4 bits] Signed-off-by: Alex Bennée --- trace-events | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trace-events b/trace-events index aeea3c2bdbf..63bb192ade6 100644 --- a/trace-events +++ b/trace-events @@ -149,7 +149,7 @@ vcpu guest_cpu_reset(void) # Access information can be parsed as: # # struct mem_info { -# uint8_t size_shift : 2; /* interpreted as "1 << size_shift" bytes */ +# uint8_t size_shift : 4; /* interpreted as "1 << size_shift" bytes */ # bool sign_extend: 1; /* sign-extended */ # uint8_t endianness : 1; /* 0: little, 1: big */ # bool store : 1; /* wheter it's a store operation */ From patchwork Wed Jul 31 16:06:32 2019 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: 11068597 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A9152912 for ; Wed, 31 Jul 2019 16:12:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95B4227F8C for ; Wed, 31 Jul 2019 16:12:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8966927F82; Wed, 31 Jul 2019 16:12:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A01B922701 for ; Wed, 31 Jul 2019 16:12:09 +0000 (UTC) Received: from localhost ([::1]:42374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrCy-0000ht-Ua for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:12:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40496) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsr8q-0002E9-Da for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsr8n-0000pc-16 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:51 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:46242) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsr8i-0000eG-Qi for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:46 -0400 Received: by mail-wr1-x443.google.com with SMTP id z1so70279280wru.13 for ; Wed, 31 Jul 2019 09:07:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AexkS+KIZIi617DuYDFY2BBLLVS//3vHoI6KKZ6c7Dk=; b=fE37pb4HagnHfPebsD/2E/4jDX5VgWAr8uk0/gFxfhr1gdwulCuL8+seSekmg60X9q 0nySGwSMoU7fiNeEOPFBlHw6Sf4Zw3wuJEpfWdzRfr7JTOvuVQ5nC5MH8J36Z+8AWnTF dmZI/iyLkTb+hrxdtw90DClOaLBHG/3t4o3L5H8RC6asIGomiIJhP+NiEvllMehFzTEF gcnch0zmEHL/RJwU4BOhBFUYAfx2P8R+eBNW/QRqGaS+yELpXIlySNKDNzsjvLh1yJ6B 8Felpt3U47CATL699gDL1oXO027lVqlhmq4cAW91QgLGp5flctlzuFSTfttf1h1RuV1P IYxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AexkS+KIZIi617DuYDFY2BBLLVS//3vHoI6KKZ6c7Dk=; b=KptTEEG2Ncqhs6uKtAmBjqpQMRKVLxWydqnub4QR43FW8y8VyhOc31KPnUdbb3KuUM plyaemLLZEBSuiP2kCP1HA2CPlqRvH5VrQ1omFB+l5gwsosKlCsgWG50kFrEUTm1GQvL 402UEHjcVMGnNp8hTa2ZIYwoMkMqZrshsOM7596MlbSvvNjc0VUydVVBIVcrULKBBFUH mnA84yKWmSqjE4yTNDvViJ9O2ELoa/mBzaIgVcJ2vKN2iWUxGHiZHL8wFqd2+cJ016N0 d8dPwYjrUhYHP3BHgLE2BPW34iFfOcwd1UbBrnhmOgpH17EUwW5dC7ofgHWY2sych/y9 BX5w== X-Gm-Message-State: APjAAAU3qhS4PGJqlPLH082aH2meqc0ZD36tq2gXoR/HQO/OOXJbJKg3 IZ0AkqfLoErxykMU7nxxIDNh/gtD1Mg= X-Google-Smtp-Source: APXvYqzojp/RM57Z9oEOISILqAZQPblszdO67p49hnu+7jIemlH9AURob6jlTa4EePHUIaNt1FftgA== X-Received: by 2002:adf:f206:: with SMTP id p6mr63923775wro.216.1564589245376; Wed, 31 Jul 2019 09:07:25 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id k17sm90660728wrq.83.2019.07.31.09.07.21 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:07:23 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 1D8661FF96; Wed, 31 Jul 2019 17:07:20 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:32 +0100 Message-Id: <20190731160719.11396-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [PATCH v4 07/54] trace: add mmu_index to mem_info X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , aaron@os.amperecomputing.com, cota@braap.org, Stefan Hajnoczi , Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We are going to re-use mem_info later for plugins and will need to track the mmu_idx for softmmu code. [TODO: convert everything to use TCGMemOpIdx?] Signed-off-by: Alex Bennée --- accel/tcg/atomic_template.h | 6 ++--- accel/tcg/cputlb.c | 2 ++ accel/tcg/user-exec.c | 1 + include/exec/cpu_ldst_template.h | 15 +++++------ include/exec/cpu_ldst_useronly_template.h | 6 ++--- scripts/tracetool/transform.py | 1 + tcg/tcg-op.c | 8 +++--- trace-events | 6 +++-- trace/mem-internal.h | 31 ++++++++++++++++------- trace/mem.h | 7 ++--- 10 files changed, 50 insertions(+), 33 deletions(-) diff --git a/accel/tcg/atomic_template.h b/accel/tcg/atomic_template.h index 5aaf1862539..313a4c7ed97 100644 --- a/accel/tcg/atomic_template.h +++ b/accel/tcg/atomic_template.h @@ -60,7 +60,7 @@ #endif #define ATOMIC_TRACE_RMW do { \ - uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false); \ + uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false, ATOMIC_MMU_IDX); \ \ trace_guest_mem_before_exec(env_cpu(env), addr, info); \ trace_guest_mem_before_exec(env_cpu(env), addr, \ @@ -68,13 +68,13 @@ } while (0) #define ATOMIC_TRACE_LD do { \ - uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false); \ + uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false, ATOMIC_MMU_IDX); \ \ trace_guest_mem_before_exec(env_cpu(env), addr, info); \ } while (0) # define ATOMIC_TRACE_ST do { \ - uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, true); \ + uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, true, ATOMIC_MMU_IDX); \ \ trace_guest_mem_before_exec(env_cpu(env), addr, info); \ } while (0) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index bb9897b25a3..bffdb251580 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1692,6 +1692,7 @@ void helper_be_stq_mmu(CPUArchState *env, target_ulong addr, uint64_t val, memory_notdirty_write_complete(&ndi); \ } \ } while (0) +#define ATOMIC_MMU_IDX oi #define DATA_SIZE 1 #include "atomic_template.h" @@ -1734,6 +1735,7 @@ void helper_be_stq_mmu(CPUArchState *env, target_ulong addr, uint64_t val, #define DATA_SIZE 8 #include "atomic_template.h" #endif +#undef ATOMIC_MMU_IDX /* Code access functions. */ diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 897d1571c4a..bff1934cf1b 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -719,6 +719,7 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr, #define ATOMIC_MMU_DECLS do {} while (0) #define ATOMIC_MMU_LOOKUP atomic_mmu_lookup(env, addr, DATA_SIZE, GETPC()) #define ATOMIC_MMU_CLEANUP do { clear_helper_retaddr(); } while (0) +#define ATOMIC_MMU_IDX 0 #define ATOMIC_NAME(X) HELPER(glue(glue(atomic_ ## X, SUFFIX), END)) #define EXTRA_ARGS diff --git a/include/exec/cpu_ldst_template.h b/include/exec/cpu_ldst_template.h index af7e0b49f2d..5750a26b9ec 100644 --- a/include/exec/cpu_ldst_template.h +++ b/include/exec/cpu_ldst_template.h @@ -84,17 +84,16 @@ glue(glue(glue(cpu_ld, USUFFIX), MEMSUFFIX), _ra)(CPUArchState *env, CPUTLBEntry *entry; RES_TYPE res; target_ulong addr; - int mmu_idx; + int mmu_idx = CPU_MMU_INDEX; TCGMemOpIdx oi; #if !defined(SOFTMMU_CODE_ACCESS) trace_guest_mem_before_exec( env_cpu(env), ptr, - trace_mem_build_info(SHIFT, false, MO_TE, false)); + trace_mem_build_info(SHIFT, false, MO_TE, false, mmu_idx)); #endif addr = ptr; - mmu_idx = CPU_MMU_INDEX; entry = tlb_entry(env, mmu_idx, addr); if (unlikely(entry->ADDR_READ != (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))))) { @@ -123,17 +122,16 @@ glue(glue(glue(cpu_lds, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env, CPUTLBEntry *entry; int res; target_ulong addr; - int mmu_idx; + int mmu_idx = CPU_MMU_INDEX; TCGMemOpIdx oi; #if !defined(SOFTMMU_CODE_ACCESS) trace_guest_mem_before_exec( env_cpu(env), ptr, - trace_mem_build_info(SHIFT, true, MO_TE, false)); + trace_mem_build_info(SHIFT, true, MO_TE, false, mmu_idx)); #endif addr = ptr; - mmu_idx = CPU_MMU_INDEX; entry = tlb_entry(env, mmu_idx, addr); if (unlikely(entry->ADDR_READ != (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))))) { @@ -165,17 +163,16 @@ glue(glue(glue(cpu_st, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env, { CPUTLBEntry *entry; target_ulong addr; - int mmu_idx; + int mmu_idx = CPU_MMU_INDEX; TCGMemOpIdx oi; #if !defined(SOFTMMU_CODE_ACCESS) trace_guest_mem_before_exec( env_cpu(env), ptr, - trace_mem_build_info(SHIFT, false, MO_TE, true)); + trace_mem_build_info(SHIFT, false, MO_TE, true, mmu_idx)); #endif addr = ptr; - mmu_idx = CPU_MMU_INDEX; entry = tlb_entry(env, mmu_idx, addr); if (unlikely(tlb_addr_write(entry) != (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))))) { diff --git a/include/exec/cpu_ldst_useronly_template.h b/include/exec/cpu_ldst_useronly_template.h index 2378f2958c9..8f7f117ad44 100644 --- a/include/exec/cpu_ldst_useronly_template.h +++ b/include/exec/cpu_ldst_useronly_template.h @@ -73,7 +73,7 @@ glue(glue(cpu_ld, USUFFIX), MEMSUFFIX)(CPUArchState *env, abi_ptr ptr) #else trace_guest_mem_before_exec( env_cpu(env), ptr, - trace_mem_build_info(SHIFT, false, MO_TE, false)); + trace_mem_build_info(SHIFT, false, MO_TE, false, 0)); return glue(glue(ld, USUFFIX), _p)(g2h(ptr)); #endif } @@ -105,7 +105,7 @@ glue(glue(cpu_lds, SUFFIX), MEMSUFFIX)(CPUArchState *env, abi_ptr ptr) #else trace_guest_mem_before_exec( env_cpu(env), ptr, - trace_mem_build_info(SHIFT, true, MO_TE, false)); + trace_mem_build_info(SHIFT, true, MO_TE, false, 0)); return glue(glue(lds, SUFFIX), _p)(g2h(ptr)); #endif } @@ -132,7 +132,7 @@ glue(glue(cpu_st, SUFFIX), MEMSUFFIX)(CPUArchState *env, abi_ptr ptr, { trace_guest_mem_before_exec( env_cpu(env), ptr, - trace_mem_build_info(SHIFT, false, MO_TE, true)); + trace_mem_build_info(SHIFT, false, MO_TE, true, 0)); glue(glue(st, SUFFIX), _p)(g2h(ptr), v); } diff --git a/scripts/tracetool/transform.py b/scripts/tracetool/transform.py index e18b05315ef..2ca9286046d 100644 --- a/scripts/tracetool/transform.py +++ b/scripts/tracetool/transform.py @@ -83,6 +83,7 @@ TCG_2_HOST = { HOST_2_TCG_COMPAT = { "uint8_t": "uint32_t", + "uint16_t": "uint32_t", } diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c index 587d0922384..38e62dcba97 100644 --- a/tcg/tcg-op.c +++ b/tcg/tcg-op.c @@ -2795,7 +2795,7 @@ void tcg_gen_qemu_ld_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop) tcg_gen_req_mo(TCG_MO_LD_LD | TCG_MO_ST_LD); memop = tcg_canonicalize_memop(memop, 0, 0); trace_guest_mem_before_tcg(tcg_ctx->cpu, cpu_env, - addr, trace_mem_get_info(memop, 0)); + addr, trace_mem_get_info(memop, idx, 0)); orig_memop = memop; if (!TCG_TARGET_HAS_MEMORY_BSWAP && (memop & MO_BSWAP)) { @@ -2832,7 +2832,7 @@ void tcg_gen_qemu_st_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop) tcg_gen_req_mo(TCG_MO_LD_ST | TCG_MO_ST_ST); memop = tcg_canonicalize_memop(memop, 0, 1); trace_guest_mem_before_tcg(tcg_ctx->cpu, cpu_env, - addr, trace_mem_get_info(memop, 1)); + addr, trace_mem_get_info(memop, idx, 1)); if (!TCG_TARGET_HAS_MEMORY_BSWAP && (memop & MO_BSWAP)) { swap = tcg_temp_new_i32(); @@ -2875,7 +2875,7 @@ void tcg_gen_qemu_ld_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) tcg_gen_req_mo(TCG_MO_LD_LD | TCG_MO_ST_LD); memop = tcg_canonicalize_memop(memop, 1, 0); trace_guest_mem_before_tcg(tcg_ctx->cpu, cpu_env, - addr, trace_mem_get_info(memop, 0)); + addr, trace_mem_get_info(memop, idx, 0)); orig_memop = memop; if (!TCG_TARGET_HAS_MEMORY_BSWAP && (memop & MO_BSWAP)) { @@ -2923,7 +2923,7 @@ void tcg_gen_qemu_st_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) tcg_gen_req_mo(TCG_MO_LD_ST | TCG_MO_ST_ST); memop = tcg_canonicalize_memop(memop, 1, 1); trace_guest_mem_before_tcg(tcg_ctx->cpu, cpu_env, - addr, trace_mem_get_info(memop, 1)); + addr, trace_mem_get_info(memop, idx, 1)); if (!TCG_TARGET_HAS_MEMORY_BSWAP && (memop & MO_BSWAP)) { swap = tcg_temp_new_i64(); diff --git a/trace-events b/trace-events index 63bb192ade6..9f15a0c1fe6 100644 --- a/trace-events +++ b/trace-events @@ -152,12 +152,14 @@ vcpu guest_cpu_reset(void) # uint8_t size_shift : 4; /* interpreted as "1 << size_shift" bytes */ # bool sign_extend: 1; /* sign-extended */ # uint8_t endianness : 1; /* 0: little, 1: big */ -# bool store : 1; /* wheter it's a store operation */ +# bool store : 1; /* whether it is a store operation */ +# pad : 1; +# uint8_t mmuidx : 4; /* mmuidx (softmmu only) */ # }; # # Mode: user, softmmu # Targets: TCG(all) -vcpu tcg guest_mem_before(TCGv vaddr, uint8_t info) "info=%d", "vaddr=0x%016"PRIx64" info=%d" +vcpu tcg guest_mem_before(TCGv vaddr, uint16_t info) "info=%d", "vaddr=0x%016"PRIx64" info=%d" # linux-user/syscall.c # bsd-user/syscall.c diff --git a/trace/mem-internal.h b/trace/mem-internal.h index f6efaf6d6b7..35da998c16b 100644 --- a/trace/mem-internal.h +++ b/trace/mem-internal.h @@ -14,11 +14,13 @@ #define TRACE_MEM_SE (1ULL << 3) /* sign extended (y/n) */ #define TRACE_MEM_BE (1ULL << 4) /* big endian (y/n) */ #define TRACE_MEM_ST (1ULL << 5) /* store (y/n) */ +#define TRACE_MEM_MMU_SHIFT 8 /* mmu idx */ -static inline uint8_t trace_mem_build_info( - int size_shift, bool sign_extend, TCGMemOp endianness, bool store) +static inline uint16_t trace_mem_build_info( + int size_shift, bool sign_extend, TCGMemOp endianness, + bool store, unsigned int mmu_idx) { - uint8_t res; + uint16_t res; res = size_shift & TRACE_MEM_SZ_SHIFT_MASK; if (sign_extend) { @@ -30,25 +32,36 @@ static inline uint8_t trace_mem_build_info( if (store) { res |= TRACE_MEM_ST; } +#ifdef CONFIG_SOFTMMU + res |= mmu_idx << TRACE_MEM_MMU_SHIFT; +#endif return res; } -static inline uint8_t trace_mem_get_info(TCGMemOp op, bool store) +static inline uint16_t trace_mem_get_info(TCGMemOp op, + unsigned int mmu_idx, + bool store) { return trace_mem_build_info(op & MO_SIZE, !!(op & MO_SIGN), - op & MO_BSWAP, store); + op & MO_BSWAP, store, + mmu_idx); } +/* Used by the atomic helpers */ static inline -uint8_t trace_mem_build_info_no_se_be(int size_shift, bool store) +uint16_t trace_mem_build_info_no_se_be(int size_shift, bool store, + TCGMemOpIdx oi) { - return trace_mem_build_info(size_shift, false, MO_BE, store); + return trace_mem_build_info(size_shift, false, MO_BE, store, + get_mmuidx(oi)); } static inline -uint8_t trace_mem_build_info_no_se_le(int size_shift, bool store) +uint16_t trace_mem_build_info_no_se_le(int size_shift, bool store, + TCGMemOpIdx oi) { - return trace_mem_build_info(size_shift, false, MO_LE, store); + return trace_mem_build_info(size_shift, false, MO_LE, store, + get_mmuidx(oi)); } #endif /* TRACE__MEM_INTERNAL_H */ diff --git a/trace/mem.h b/trace/mem.h index 2b58196e536..0f9cd4862ac 100644 --- a/trace/mem.h +++ b/trace/mem.h @@ -18,15 +18,16 @@ * * Return a value for the 'info' argument in guest memory access traces. */ -static uint8_t trace_mem_get_info(TCGMemOp op, bool store); +static uint16_t trace_mem_get_info(TCGMemOp op, unsigned int mmu_idx, bool store); /** * trace_mem_build_info: * * Return a value for the 'info' argument in guest memory access traces. */ -static uint8_t trace_mem_build_info(int size_shift, bool sign_extend, - TCGMemOp endianness, bool store); +static uint16_t trace_mem_build_info(int size_shift, bool sign_extend, + TCGMemOp endianness, bool store, + unsigned int mmuidx); #include "trace/mem-internal.h" From patchwork Wed Jul 31 16:06:33 2019 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: 11068655 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4B7D813AC for ; Wed, 31 Jul 2019 16:20:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3644F1FFCD for ; Wed, 31 Jul 2019 16:20:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 298A22012F; Wed, 31 Jul 2019 16:20:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 13BAC200CB for ; Wed, 31 Jul 2019 16:20:29 +0000 (UTC) Received: from localhost ([::1]:42518 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrKx-000832-DF for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:20:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40461) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsr8o-0002Bf-Ba for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsr8l-0000ox-M9 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:50 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:40523) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsr8h-0000eP-Go for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:44 -0400 Received: by mail-wr1-x444.google.com with SMTP id r1so70282238wrl.7 for ; Wed, 31 Jul 2019 09:07:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HmgqT/HIUKoP+z/2ztUMKoEQehWucsoXeXun56Y0Jjg=; b=RWDekH6OsbRhvKymT2V+CCx2+QFkfT7pWbng6zOPaUuLSMgnxJmPQL87R62kCBlgFl 6xDK+Y1CKqSM6kDAvf2QEEKDnj7JeKIt6SAz2R28JDwvZKH7pBYQ4WVZmv29zQ9YAhZU v6J47t69pwwsnBmcX25D9gadyX9MWS0eitL17Yhn/kQeiYh+N28spa5uu4tXigylDj1a 6jz4C1BwVaVIMor0yfhjallTVm49TJ/j/S9h7Oz24+NWz0grSsj+8zzbKQSrA+P5ElNm vrquHJt5/SAnuPw8LGflUx3iqxTn8ahr5WVdFXZEqtKFWghndRaKtQlmvFPSabxPvd+H Se+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HmgqT/HIUKoP+z/2ztUMKoEQehWucsoXeXun56Y0Jjg=; b=V/oO6Rd7ikpolj2+vctsMcNr+HuiOSON12pLpodA6Wk11+lVMc1jrWSCbyEE5eDCrD O3hxxyZSH/LA90azVMLXJaLEbGd1dNscAa82rAQX1+pPRgeRLC8wkxc2v4QPg3BQb9yZ llRGb9vZoMK2zzJGHDmMoDN3O/xualuf9ZO1ssAKkDb/zn5obH2ijCbdgYvTJGH47Ae8 IWbRieU6JR/Z5ZosGWaMglEk4GPJKHUmXJmdLlThckPm0VM9b6Ui++4IoB+aMriZwynx N62NXSLkOmtqYDeRAZserMteo7uN47mWY+Nlil1d16qASr09nNaMptmUDFD9NYA4XkL4 CPDw== X-Gm-Message-State: APjAAAW8XGBu6q9NeqEMa9K8nf8KxQsSdU5CA6YJsXeGpuDqJJvry9NZ e+Zh+9/0F/w0Dq+BV7Bd75c5CQ== X-Google-Smtp-Source: APXvYqxfKqFU4nwid9PrN3JBh+lOUsIlUqdPtDHryYYO5FoPebexv2Oj58NwcYsdT6HiptrExJIerw== X-Received: by 2002:adf:f246:: with SMTP id b6mr14115306wrp.92.1564589245847; Wed, 31 Jul 2019 09:07:25 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id x18sm60674566wmi.12.2019.07.31.09.07.21 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:07:23 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 311FF1FF98; Wed, 31 Jul 2019 17:07:20 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:33 +0100 Message-Id: <20190731160719.11396-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH v4 08/54] tcg/README: fix typo s/afterwise/afterwards/ X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , aaron@os.amperecomputing.com, cota@braap.org, bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Afterwise is "wise after the fact", as in "hindsight". Here we meant "afterwards" (as in "subsequently"). Fix it. Reviewed-by: Alex Bennée Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- tcg/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcg/README b/tcg/README index 21fcdf737ff..ef9be5ba90e 100644 --- a/tcg/README +++ b/tcg/README @@ -101,7 +101,7 @@ This can be overridden using the following function modifiers: canonical locations before calling the helper. - TCG_CALL_NO_WRITE_GLOBALS means that the helper does not modify any globals. They will only be saved to their canonical location before calling helpers, - but they won't be reloaded afterwise. + but they won't be reloaded afterwards. - TCG_CALL_NO_SIDE_EFFECTS means that the call to the function is removed if the return value is not used. From patchwork Wed Jul 31 16:06:34 2019 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: 11068603 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A80A912 for ; Wed, 31 Jul 2019 16:13:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58A4E20223 for ; Wed, 31 Jul 2019 16:13:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C5BE204FB; Wed, 31 Jul 2019 16:13:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D7A0820223 for ; Wed, 31 Jul 2019 16:13:23 +0000 (UTC) Received: from localhost ([::1]:42392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrEB-0002pc-8e for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:13:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40374) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsr8h-00027t-GI for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsr8e-0000kZ-CK for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:42 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:44122) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsr8d-0000ev-FB for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:39 -0400 Received: by mail-wr1-x443.google.com with SMTP id p17so70287613wrf.11 for ; Wed, 31 Jul 2019 09:07:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gqRoR6HeTII8sj4+++ItlQ9YsCPjf/Rl0PEZ/zeyKFI=; b=s6nNj18AsKMrJqBZ0JC3IwkFmgsVUwB1p2HwNr7yzxRDZ0q53fSFwd7i8CqdNygHBF NnHt7jaxqcvckTzl+//AHdAdo17aoSpADU3jbGVr3R/DJUBmVQGNPwAndwzj6ATmJUY+ cO7Bq9vjF5lTBQTsY083ZebT0R8o+yEEqPEq5WLnNkAEjQz57jPIwRPEJ0GHQe4pYRUi dkZ8DjPQg5O/W1gKkQlWSvBricR0P2rtNhkEUhssKEMPAFLP/N+3z1VEuy+uzBnpmTQE 7eQgrhKY1SuI3UHp0GHn2ngKlP/HoehWz5F9yT3996fA2GZvHqjbrixn4sml0dWs/4C2 GLQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gqRoR6HeTII8sj4+++ItlQ9YsCPjf/Rl0PEZ/zeyKFI=; b=XdRVT0wbVbs86PT6h9pY4P1uQaNcsuzbRtKMdaIX/KT3qE55z7ZMTwMuaI5wIajFhN gbwM5VG1ApeQS19JsI7ApNS4/MQoISKvncfU5aoUQQeaRXormE8VNV1XRtgeExbBEYrm Hm5HA5lHHtF15Vm4EGzD6lS4wRjci3ytWnkvh6pjqz9vbKakU/ODtxKG+euGQ9+Y84pY l9BjrG7POI3Rv+iHlAQjLLJjCbL7i0tdB8Ryv4fx/aO1OVZrx1pI7qXYNDeAFWQhHLDa 7gLQKaE1ImSvM+Z/HUku2rCkGMxsFDgbITuaNMRrJBZn/+wLWvHeOMu6TbjgjAhyNnlk v6og== X-Gm-Message-State: APjAAAWbJhHn3np8WBKymhLrFgDkRM2zXqVttpv1a0Wmrj8lCBxeeDPi jWeWdqJ3oQztod+FDfjRS1tWjA== X-Google-Smtp-Source: APXvYqwIcCeyCIJDrsGo/q9Qrtirk9OsKfd7qIBnaxGk3YVpWqYZDyiRxJDoKGRG28CSH9PYJBHfDg== X-Received: by 2002:adf:fb8e:: with SMTP id a14mr40487717wrr.263.1564589247173; Wed, 31 Jul 2019 09:07:27 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id l2sm46099782wmj.4.2019.07.31.09.07.21 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:07:23 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 49F8F1FF99; Wed, 31 Jul 2019 17:07:20 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:34 +0100 Message-Id: <20190731160719.11396-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [PATCH v4 09/54] cpu: introduce cpu_in_exclusive_context() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Suggested-by: Alex Bennée Reviewed-by: Alex Bennée Signed-off-by: Emilio G. Cota [AJB: moved inside start/end_exclusive fns + cleanup] Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v4 - -> cpu_in_exclusive_context - moved inside start/end exclusive - fixed up cpu_exec_step_atomic --- accel/tcg/cpu-exec.c | 5 +---- cpus-common.c | 4 ++++ include/qom/cpu.h | 13 +++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 6c85c3ee1e9..ab9dfd4f908 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -239,8 +239,6 @@ void cpu_exec_step_atomic(CPUState *cpu) uint32_t flags; uint32_t cflags = 1; uint32_t cf_mask = cflags & CF_HASH_MASK; - /* volatile because we modify it between setjmp and longjmp */ - volatile bool in_exclusive_region = false; if (sigsetjmp(cpu->jmp_env, 0) == 0) { tb = tb_lookup__cpu_state(cpu, &pc, &cs_base, &flags, cf_mask); @@ -254,7 +252,6 @@ void cpu_exec_step_atomic(CPUState *cpu) /* Since we got here, we know that parallel_cpus must be true. */ parallel_cpus = false; - in_exclusive_region = true; cc->cpu_exec_enter(cpu); /* execute the generated code */ trace_exec_tb(tb, pc); @@ -274,7 +271,7 @@ void cpu_exec_step_atomic(CPUState *cpu) assert_no_pages_locked(); } - if (in_exclusive_region) { + if (cpu_in_exclusive_context(cpu)) { /* We might longjump out of either the codegen or the * execution, so must make sure we only end the exclusive * region if we started it. diff --git a/cpus-common.c b/cpus-common.c index 3ca58c64e80..e87400834be 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -208,11 +208,15 @@ void start_exclusive(void) * section until end_exclusive resets pending_cpus to 0. */ qemu_mutex_unlock(&qemu_cpu_list_lock); + + current_cpu->in_exclusive_context = true; } /* Finish an exclusive operation. */ void end_exclusive(void) { + current_cpu->in_exclusive_context = false; + qemu_mutex_lock(&qemu_cpu_list_lock); atomic_set(&pending_cpus, 0); qemu_cond_broadcast(&exclusive_resume); diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 5ee0046b629..65a0926c49a 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -373,6 +373,7 @@ struct CPUState { bool unplug; bool crash_occurred; bool exit_request; + bool in_exclusive_context; uint32_t cflags_next_tb; /* updates protected by BQL */ uint32_t interrupt_request; @@ -785,6 +786,18 @@ void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data) */ void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data); +/** + * cpu_in_exclusive_context() + * @cpu: The vCPU to check + * + * Returns true if @cpu is an exclusive context, for example running + * something which has previously been queued via async_safe_run_on_cpu(). + */ +static inline bool cpu_in_exclusive_context(const CPUState *cpu) +{ + return cpu->in_exclusive_context; +} + /** * qemu_get_cpu: * @index: The CPUState@cpu_index value of the CPU to obtain. From patchwork Wed Jul 31 16:06:35 2019 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: 11068609 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8FD82746 for ; Wed, 31 Jul 2019 16:13:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D05F204FA for ; Wed, 31 Jul 2019 16:13:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7172622ADC; Wed, 31 Jul 2019 16:13:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 25194204FB for ; Wed, 31 Jul 2019 16:13:42 +0000 (UTC) Received: from localhost ([::1]:42394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrET-0003D9-Gy for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:13:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40372) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsr8h-00027q-G8 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsr8e-0000kw-Rw for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:43 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:38113) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsr8e-0000ed-CP for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:40 -0400 Received: by mail-wm1-x342.google.com with SMTP id s15so38988665wmj.3 for ; Wed, 31 Jul 2019 09:07:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=x7RGFDz62fM8+46VM8mYT+u7ako6VpEUPrNMjeMtALg=; b=rZ3qN8oqK9kJSDDW+QP2nyYQA6VsxAb55XFQtHdMPASlLfsdHxWIySIwZBiwYf5svf r7CugMnDuw1kLmx7QxXbiyHvQJBNb9Wg1BCYV8FrF2JGSZDtqKD9nvQG/Uq419ps4M8f hT/z3eVaBF3Kst6oBnZZYv6m0EK0DNBaDtOGvB8TzAbHh476EDHlwNRW/jpo1sTPIsTm agyxPPA+RQsHQSCFGQ1tzR6A2LYlIeRjoPnE5zbEx8T23S/nOHI0JUrFEJNr8U2wZDw8 x5Z1NBeX6N5j075VIrQwopKDbiGg0gg2T4z8XvqHK0M9sXBZ8MlsJnWEUie13qTFWGZf yTFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=x7RGFDz62fM8+46VM8mYT+u7ako6VpEUPrNMjeMtALg=; b=IftYZD444X+3kafTxLcnfNRUsb/6lWxlWz6nZWblULDCrzJXlXtfR/qwqaLp+th7rU PCanA5qHAQY0TezNzcBOctGQeCXilOv5p9e7La9wyr1fdsKvz64VWONctUc5+Oo2X6hH Jl5aVou0ZE8094oDy3nJaJn6iStej/7tRUXrR0oo6C+DmZUIP1rK37W4ccojz4RnHbvt jSk2O0drZARb+mC335iLBhmcgoz15FOS0QxGWWmG4eFlXYYn7w1CFZJL8m2ZuCiIeHmC /83uekqKRdhWz53WUnZjDwpLMjLmYGqYbA9nxOVD8koQAmHXsNLnVN+Prd2l6IvoLjbb BIuw== X-Gm-Message-State: APjAAAXO2EsqMaQjHLzP9GPTmuWS96YGVesIRVHoerxEaKWNp9jwVMdZ J7VCycgrRq2mKdkjiQRi0DkIRw== X-Google-Smtp-Source: APXvYqwjUsp1IVBy6xrCqi1tVXrWJVCUtSduOhHwQ7RF1c+nNgCjnBVPanLhuaU8ryQy+a5kRuIkhw== X-Received: by 2002:a05:600c:20c3:: with SMTP id y3mr114925235wmm.3.1564589246646; Wed, 31 Jul 2019 09:07:26 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id g8sm68930589wmf.17.2019.07.31.09.07.21 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:07:23 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 5D11B1FF9A; Wed, 31 Jul 2019 17:07:20 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:35 +0100 Message-Id: <20190731160719.11396-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 Subject: [Qemu-devel] [PATCH v4 10/54] translate-all: use cpu_in_exclusive_work_context() in tb_flush X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" tb_flush will be called by the plugin module from a safe work environment. Prepare for that. Suggested-by: Alex Bennée Reviewed-by: Alex Bennée Signed-off-by: Emilio G. Cota Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- accel/tcg/translate-all.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 5d1e08b1699..9c5c60ed964 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1268,8 +1268,13 @@ void tb_flush(CPUState *cpu) { if (tcg_enabled()) { unsigned tb_flush_count = atomic_mb_read(&tb_ctx.tb_flush_count); - async_safe_run_on_cpu(cpu, do_tb_flush, - RUN_ON_CPU_HOST_INT(tb_flush_count)); + + if (cpu_in_exclusive_context(cpu)) { + do_tb_flush(cpu, RUN_ON_CPU_HOST_INT(tb_flush_count)); + } else { + async_safe_run_on_cpu(cpu, do_tb_flush, + RUN_ON_CPU_HOST_INT(tb_flush_count)); + } } } From patchwork Wed Jul 31 16:06:36 2019 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: 11068619 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1DD951395 for ; Wed, 31 Jul 2019 16:15:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 09C6A20008 for ; Wed, 31 Jul 2019 16:15:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1FBE2012F; Wed, 31 Jul 2019 16:15:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6CA1A20008 for ; Wed, 31 Jul 2019 16:15:23 +0000 (UTC) Received: from localhost ([::1]:42426 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrG6-0005om-K9 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:15:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40373) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsr8h-00027r-GB for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsr8e-0000kT-CE for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:43 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:50651) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsr8d-0000fE-F8 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:39 -0400 Received: by mail-wm1-x341.google.com with SMTP id v15so61447898wml.0 for ; Wed, 31 Jul 2019 09:07:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1nyFaFW/wTOm9VXlvjfZCzFrDnNypgzHnbD0BmcShzY=; b=RQGsW7X45cJA5Ute1FzYGoYoH3q6mW6FHCEK620UxSjtuDovwy7Bp0ajbxc3ErOxj/ H2dovLD3E46rfG+Ptc0SkNnRoM7dTGupkIlFvAder0si4q85nefqfbDrw48cOL7xpICc lzx1QTn9z5HSMlW0ksyzbalh8MT6kphywqcl4AiYvpV8lOlwmXYHABv6h+zxM9YFq0yu KDzbBThRgFNqbRNj7wfGKvX5KbONoNT+g416Hy/vs5ZzFRvzysJ3CSvC3rz6Lv3ujv44 kWEyJVmbSJro0ApGAamjIaHXeFuEjCPNjqtx0ReOsOEUQII5If8FVTiEILWFle8hS1EC 6CIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1nyFaFW/wTOm9VXlvjfZCzFrDnNypgzHnbD0BmcShzY=; b=NAbUs2hxGVao+Rp74LfBItn+O6Cu+Wk1noC8GZHoZyGrwrDRjwktxKabZgiawj07mN L7U/KIV9mCb6pEUyfkCztCKSaqWpsNaoieWnHUk10+6LLxtIied6N4Sg4AU5B56I3m/o EHtU4xS1I7yqlN9MWXt9wadpU4YsNpirunEik9UKDVz53cZkqmZsGFvhfoENz4dYTbce E0uww4fnxZrt6twMAbP1ogcl8r3UVQCqDAgSLOMzpn7hDBy4NdL3g5inZbrB8u6GJRlv zWA9s7wOJv3lBr8Bwx+QKCSH5gXbI0Ni05dkR/b4dicVHRTiUe+gsd4AdSHE3+d0n/At 1VxA== X-Gm-Message-State: APjAAAUd51VyrqnbZqSOuHy2uCJfNy98dbPH4nTSJtjP6mqaQndDhlBD kTOf++YGSLWyfgk9qN6kVWSMVw== X-Google-Smtp-Source: APXvYqzA5vwrBGB1EW1V1+kcijpdq+RQtodwRTg59IEE2FtM+6cdGVvpHCnfLQZLa5JgXCy90oiZCQ== X-Received: by 2002:a1c:9c8a:: with SMTP id f132mr111826314wme.29.1564589247908; Wed, 31 Jul 2019 09:07:27 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id t1sm82381007wra.74.2019.07.31.09.07.22 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:07:23 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 71BBD1FF87; Wed, 31 Jul 2019 17:07:20 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:36 +0100 Message-Id: <20190731160719.11396-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 Subject: [Qemu-devel] [PATCH v4 11/54] docs/devel: add plugins.rst design document X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bobby.prani@gmail.com, cota@braap.org, =?utf-8?q?Alex_Benn=C3=A9e?= , aaron@os.amperecomputing.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This is mostly extracted from Emilio's more verbose commit comments with some additional verbiage from me. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v4 - some rewording and tweaks - made non-atomicity of inline ops more explicit - expanded description of plugin unload --- docs/devel/index.rst | 1 + docs/devel/plugins.rst | 107 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 docs/devel/plugins.rst diff --git a/docs/devel/index.rst b/docs/devel/index.rst index 1ec61fcfed9..2ff058bae38 100644 --- a/docs/devel/index.rst +++ b/docs/devel/index.rst @@ -22,3 +22,4 @@ Contents: decodetree secure-coding-practices tcg + plugins diff --git a/docs/devel/plugins.rst b/docs/devel/plugins.rst new file mode 100644 index 00000000000..0a31227b613 --- /dev/null +++ b/docs/devel/plugins.rst @@ -0,0 +1,107 @@ +.. + Copyright (C) 2017, Emilio G. Cota + Copyright (c) 2019, Linaro Limited + Written by Emilio Cota and Alex Bennée + +================ +QEMU TCG Plugins +================ + +QEMU TCG plugins provide a way for users to run experiments taking +advantage of the total system control emulation can have over a guest. +It provides a mechanism for plugins to subscribe to events during +translation and execution and optionally callback into the plugin +during these events. + +API Stability +============= + +This is a new feature for QEMU and it does allow people to develop +out-of-tree plugins that can be dynamically linked into a running QEMU +process. However the project reserves the right to change or break the +API should it need to do so. + +Exposure of QEMU internals +-------------------------- + +The plugin architecture actively avoids leaking implementation details +about how QEMU's translation works to the plugins. While there are +conceptions such as translation time and translation blocks the +details are opaque to plugins. The plugin is able to query select +details of instructions and system configuration only through the +exported *qemu_plugin* functions. The types used to describe +instructions and events are opaque to the plugins themselves. + +Usage +===== + +The QEMU binary needs to be compiled for plugin support: + +:: + configure --enable-plugins + +Once built a program can be run with multiple plugins loaded each with +their own arguments: + +:: + $QEMU $OTHER_QEMU_ARGS \ + -plugin tests/plugin/libhowvec.so,arg=inline,arg=hint \ + -plugin tests/plugin/libhotblocks.so + +Arguments are plugin specific and can be used to modify their +behaviour. In this case the howvec plugin is being asked to use inline +ops to count and break down the hint instructions by type. + +Plugin Life cycle +================= + +First the plugin is loaded and the public qemu_plugin_install function +is called. The plugin will then register callbacks for various plugin +events. Generally plugins will register a handler for the *atexit* +if they want to dump a summary of collected information once the +program/system has finished running. + +When a registered event occurs the plugin callback is invoked. The +callbacks may provide additional information. In the case of a +translation event the plugin has an option to enumerate the +instructions in a block of instructions and optionally register +callbacks to some or all instructions when they are executed. + +There is also a facility to add an inline event where code to +increment a counter can be directly inlined with the translation. +Currently only a simple increment is supported. This is not atomic so +can miss counts. If you want absolute precision you should use a +callback which can then ensure atomicity itself. + +Finally when QEMU exits all the registered *atexit* callbacks are +invoked. + +Internals +========= + +Locking +------- + +We have to ensure we cannot deadlock, particularly under MTTCG. For +this we acquire a lock when called from plugin code. We also keep the +list of callbacks under RCU so that we do not have to hold the lock +when calling the callbacks. This is also for performance, since some +callbacks (e.g. memory access callbacks) might be called very +frequently. + + * A consequence of this is that we keep our own list of CPUs, so that + we do not have to worry about locking order wrt cpu_list_lock. + * Use a recursive lock, since we can get registration calls from + callbacks. + +As a result registering/unregistering callbacks is "slow", since it +takes a lock. But this is very infrequent; we want performance when +calling (or not calling) callbacks, not when registering them. Using +RCU is great for this. + +We support the uninstallation of a plugin at any time (e.g. from +plugin callbacks). This allows plugins to remove themselves if they no +longer want to instrument the code. This operation is asynchronous +which means callbacks may still occur after the uninstall operation is +requested. The plugin isn't completely uninstalled until the safe work +has executed while all vCPUs are quiescent. From patchwork Wed Jul 31 16:06:37 2019 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: 11068589 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8042D912 for ; Wed, 31 Jul 2019 16:10:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DF8C27EED for ; Wed, 31 Jul 2019 16:10:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61A2A27F91; Wed, 31 Jul 2019 16:10:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DBC0727EED for ; Wed, 31 Jul 2019 16:10:11 +0000 (UTC) Received: from localhost ([::1]:42348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrB5-0005eF-59 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:10:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40460) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsr8o-0002BZ-BL for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsr8k-0000oS-Pj for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:48 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:33422) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsr8h-0000fL-FA for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:44 -0400 Received: by mail-wm1-x342.google.com with SMTP id h19so1627101wme.0 for ; Wed, 31 Jul 2019 09:07:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7+yS4VWJqkSD6ydwUwgfwcLX4YEx0h4kZ8SydG4heHg=; b=FYnOYtoPUiiUca7fOl27hYNxq8Wo46wK804tILavsG/nyRwG9yH14HkIRo7o0nAjP8 OFpIzOGZbDxLYoU9Em88BasJBHKQ+U17ImSewknxFCoSVpCf2470jnlC+gji93/NEHvb +oUZpHb5oLh+/VL16dcfs7ClOMz6VGaPc/ji9mDnShYwWrQniLKB9fxXKHJA80FMebxJ yEpImr9PGJezIgrp1q7HYIstxFddlqouHVWMEZOLkER3vbYLraIWzdQG4+K5RsV4CI0a 08zEdLpjR4KHElNQvaHdLeBRAflVffgomF3onPleDBIPWHrSi27R4nuE6OcgUo1aS4oE +1Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7+yS4VWJqkSD6ydwUwgfwcLX4YEx0h4kZ8SydG4heHg=; b=QpLStrB7osWIaa5oQzl7nXQul3EzvkzMV9nEZ5Qvj+OOk6+DtZ1LVR8//lyeyY7ogy qd1P08bFhbRphaQ+YaffuOq5xBq2pSS3WT6YZtDUbGp3ekXWchxN+6Ka3BWGdnxiH75J OAOjjjFwFCNHNZqV1F7SpeIDbnnGWC+rW3Nw/Btdww68liGWYaxGUJiHNHSpEPMoEC7/ vrGuVqwO7ADossJMVqql/iOGv9RfLQJhCgqdu+yegn/HC/ucTmlvniOxdqHdEEfpyGyY OA3LSmuZFu/WZS0Kck2gSVEJeRRLSrr7bwZLK4C/qLkyquzkbB+vN1jMyrLsGKFunMMR yc3g== X-Gm-Message-State: APjAAAV5LUdEZb4PwbbVEbvlttTFq66Ol+CnYycRX/ghmbVO771mRHQq IJRBp7YTB9L3RpJx7eVGOYojX41+bT4= X-Google-Smtp-Source: APXvYqxdiYpHDGarcyUXg34qKcgsR48EbuNQv5IHt54VDfvrBrPboDt7Um3kTxUNCeGQaqrLW7ZDMg== X-Received: by 2002:a1c:a019:: with SMTP id j25mr111967752wme.95.1564589248400; Wed, 31 Jul 2019 09:07:28 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id a81sm72210857wmh.3.2019.07.31.09.07.22 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:07:23 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 8490F1FF9B; Wed, 31 Jul 2019 17:07:20 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:37 +0100 Message-Id: <20190731160719.11396-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 Subject: [Qemu-devel] [PATCH v4 12/54] configure: add --enable-plugins (MOVE TO END) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bobby.prani@gmail.com, cota@braap.org, =?utf-8?q?Alex_Benn=C3=A9e?= , aaron@os.amperecomputing.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This adds the basic boilerplate feature enable option for the build. We shall expand it later. XXX: currently this patch is included at the start of development to aid with incremental building. It should be moved to the end once the plugins are feature complete. [AJB: split from larger patch] Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- configure | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/configure b/configure index 714e7fb6a1f..dbc78f21b0c 100755 --- a/configure +++ b/configure @@ -499,6 +499,7 @@ docker="no" debug_mutex="no" libpmem="" default_devices="yes" +plugins="no" # cross compilers defaults, can be overridden with --cross-cc-ARCH cross_cc_aarch64="aarch64-linux-gnu-gcc" @@ -1543,6 +1544,10 @@ for opt do ;; --disable-libpmem) libpmem=no ;; + --enable-plugins) plugins="yes" + ;; + --disable-plugins) plugins="no" + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information" @@ -1740,6 +1745,8 @@ Advanced options (experts only): --enable-profiler profiler support --enable-debug-stack-usage track the maximum stack usage of stacks created by qemu_alloc_stack + --enable-plugins + enable plugins via shared library loading Optional features, enabled with --enable-FEATURE and disabled with --disable-FEATURE, default is enabled if available: @@ -6481,6 +6488,7 @@ echo "docker $docker" echo "libpmem support $libpmem" echo "libudev $libudev" echo "default devices $default_devices" +echo "plugin support $plugins" if test "$supported_cpu" = "no"; then echo @@ -7307,6 +7315,11 @@ if test "$sheepdog" = "yes" ; then echo "CONFIG_SHEEPDOG=y" >> $config_host_mak fi +if test "$plugins" = "yes" ; then + echo "CONFIG_PLUGIN=y" >> $config_host_mak + LIBS="-ldl $LIBS" +fi + if test "$tcg_interpreter" = "yes"; then QEMU_INCLUDES="-iquote \$(SRC_PATH)/tcg/tci $QEMU_INCLUDES" elif test "$ARCH" = "sparc64" ; then From patchwork Wed Jul 31 16:06:38 2019 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: 11068595 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D5A4746 for ; Wed, 31 Jul 2019 16:11:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 883F91FFBE for ; Wed, 31 Jul 2019 16:11:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C73126E16; Wed, 31 Jul 2019 16:11:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 87EE82624D for ; Wed, 31 Jul 2019 16:11:50 +0000 (UTC) Received: from localhost ([::1]:42370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrCf-0008E3-R9 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:11:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40342) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsr8f-00026n-6A for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsr8d-0000jn-08 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:41 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:42502) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsr8Y-0000go-UM for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:36 -0400 Received: by mail-wr1-x442.google.com with SMTP id x1so20404420wrr.9 for ; Wed, 31 Jul 2019 09:07:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o8GF3SlglsMFL92PLwLiZiSe0FHvXJ564WFkE3oIhzU=; b=Gp/fli3tbsp8d6epoMPjZal+0HiTArcZS8ns7t9hhwLGn+h0at87p9612hT1G9OmzS l95zppiBpYe6i0K70QrhInMURG62LgsBAX6JwirHScyk0Rg0lpiyw+A7V+CE0qk4wM3X Xh2HdHgWBvhBn/OOwxGbt7sT0ADpKmTO+gO7lvXBe5fQEDw0nQ1YMxadFGGzHMqXH89l RXDUmRFT21+JOhnZtoQhB11rwUPu+IBnbNeOXMseuzAYUW+DuKFhTjFQKTglU6fBUog/ rfUPEcOE+yPqSuIamHwoZFAcvYfvfmPn9QtbZUOkSOwtSqPf84C7dyYQwcJ2EXg+oBe4 /frw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o8GF3SlglsMFL92PLwLiZiSe0FHvXJ564WFkE3oIhzU=; b=AfpohDuROkmPTjn2O7SEn6NFLv/UW5/AxUIg+8HBbf9whDPkibH6vVSZfQuJote/ce mCTmd1G0mda+J5FLOdpkLNa978jxQPovseXW6hXEGWMCzImnq83UhNgXDQ9PuWwASUPF 2uDn6elFjkJmkHXe8CuyY8Et0wBI1NKAXrStNlBpHw/DeUMUu56nlsfYAfg288rt2Iuj QJ4ZegcwLkMdLmfRB25LS+EfMr4RaXFs1pda2ZrxnAdm6WMZJVtRqy+M1T1w9gmAHJRr rlKdr0uVOA3o8+LC0Wq2xwpDepFklZYlTK+2kowI+EMTnd4PwoTP50W9dt7f2ba+9eiF W8Ww== X-Gm-Message-State: APjAAAVV1qZgD+7eZrqC5as8ptjqcnFwL9Y/O1Bb+cDC0kbp/xfbNCe1 2qIFfjB5E4fDsvivo0e0f3SriQ== X-Google-Smtp-Source: APXvYqwN22P8fqiqOE9ooT6DKNDgkIsp+UABxnHAq3RRJAWtAEi5mX3XmvWv/jHO7fbNzJbK5/BBAA== X-Received: by 2002:adf:b64e:: with SMTP id i14mr124219409wre.248.1564589250472; Wed, 31 Jul 2019 09:07:30 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id f12sm74090173wrg.5.2019.07.31.09.07.23 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:07:25 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 9829D1FF9C; Wed, 31 Jul 2019 17:07:20 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:38 +0100 Message-Id: <20190731160719.11396-14-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PATCH v4 13/54] plugin: add user-facing API X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bobby.prani@gmail.com, cota@braap.org, =?utf-8?q?Alex_Benn=C3=A9e?= , aaron@os.amperecomputing.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Add the API first to ease review. Signed-off-by: Emilio G. Cota Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v3 - merge in changes to plugin install/reset/uninstall - split api file v4 - s/is/it/ - more docstrings - remove qemu_plugin_register_vcpu_mem_haddr_cb and related bits - add qemu_plugin_get_hwaddr and related bits - drop vcpu_index from tb_trans_cb_t --- include/qemu/qemu-plugin.h | 351 +++++++++++++++++++++++++++++++++++++ 1 file changed, 351 insertions(+) create mode 100644 include/qemu/qemu-plugin.h diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h new file mode 100644 index 00000000000..d9c1ca3b4cf --- /dev/null +++ b/include/qemu/qemu-plugin.h @@ -0,0 +1,351 @@ +/* + * Copyright (C) 2017, Emilio G. Cota + * Copyright (C) 2019, Linaro + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef QEMU_PLUGIN_API_H +#define QEMU_PLUGIN_API_H + +#include +#include + +/* + * For best performance, build the plugin with -fvisibility=hidden so that + * QEMU_PLUGIN_LOCAL is implicit. Then, just mark qemu_plugin_install with + * QEMU_PLUGIN_EXPORT. For more info, see + * https://gcc.gnu.org/wiki/Visibility + */ +#if defined _WIN32 || defined __CYGWIN__ + #ifdef BUILDING_DLL + #define QEMU_PLUGIN_EXPORT __declspec(dllexport) + #else + #define QEMU_PLUGIN_EXPORT __declspec(dllimport) + #endif + #define QEMU_PLUGIN_LOCAL +#else + #if __GNUC__ >= 4 + #define QEMU_PLUGIN_EXPORT __attribute__((visibility("default"))) + #define QEMU_PLUGIN_LOCAL __attribute__((visibility("hidden"))) + #else + #define QEMU_PLUGIN_EXPORT + #define QEMU_PLUGIN_LOCAL + #endif +#endif + +typedef uint64_t qemu_plugin_id_t; + +/** + * qemu_plugin_install() - Install a plugin + * @id: this plugin's opaque ID + * @argc: number of arguments + * @argv: array of arguments (@argc elements) + * + * All plugins must export this symbol. + * + * Note: Calling qemu_plugin_uninstall() from this function is a bug. To raise + * an error during install, return !0. + * + * Note: @argv remains valid throughout the lifetime of the loaded plugin. + */ +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, int argc, + char **argv); + +/* + * Prototypes for the various callback styles we will be registering + * in the following functions. + */ +typedef void (*qemu_plugin_simple_cb_t)(qemu_plugin_id_t id); + +typedef void (*qemu_plugin_udata_cb_t)(qemu_plugin_id_t id, void *userdata); + +typedef void (*qemu_plugin_vcpu_simple_cb_t)(qemu_plugin_id_t id, + unsigned int vcpu_index); + +typedef void (*qemu_plugin_vcpu_udata_cb_t)(unsigned int vcpu_index, + void *userdata); + +/** + * qemu_plugin_uninstall() - Uninstall a plugin + * @id: this plugin's opaque ID + * @cb: callback to be called once the plugin has been removed + * + * Do NOT assume that the plugin has been uninstalled once this function + * returns. Plugins are uninstalled asynchronously, and therefore the given + * plugin receives callbacks until @cb is called. + * + * Note: Calling this function from qemu_plugin_install() is a bug. + */ +void qemu_plugin_uninstall(qemu_plugin_id_t id, qemu_plugin_simple_cb_t cb); + +/** + * qemu_plugin_reset() - Reset a plugin + * @id: this plugin's opaque ID + * @cb: callback to be called once the plugin has been reset + * + * Unregisters all callbacks for the plugin given by @id. + * + * Do NOT assume that the plugin has been reset once this function returns. + * Plugins are reset asynchronously, and therefore the given plugin receives + * callbacks until @cb is called. + */ +void qemu_plugin_reset(qemu_plugin_id_t id, qemu_plugin_simple_cb_t cb); + +/** + * qemu_plugin_register_vcpu_init_cb() - register a vCPU initialization callback + * @id: plugin ID + * @cb: callback function + * + * The @cb function is called every time a vCPU is initialized. + * + * See also: qemu_plugin_register_vcpu_exit_cb() + */ +void qemu_plugin_register_vcpu_init_cb(qemu_plugin_id_t id, + qemu_plugin_vcpu_simple_cb_t cb); + +/** + * qemu_plugin_register_vcpu_exit_cb() - register a vCPU exit callback + * @id: plugin ID + * @cb: callback function + * + * The @cb function is called every time a vCPU exits. + * + * See also: qemu_plugin_register_vcpu_init_cb() + */ +void qemu_plugin_register_vcpu_exit_cb(qemu_plugin_id_t id, + qemu_plugin_vcpu_simple_cb_t cb); + +/** + * qemu_plugin_register_vcpu_idle_cb() - register a vCPU idle callback + * @id: plugin ID + * @cb: callback function + * + * The @cb function is called every time a vCPU idles. + */ +void qemu_plugin_register_vcpu_idle_cb(qemu_plugin_id_t id, + qemu_plugin_vcpu_simple_cb_t cb); + +/** + * qemu_plugin_register_vcpu_resume_cb() - register a vCPU resume callback + * @id: plugin ID + * @cb: callback function + * + * The @cb function is called every time a vCPU resumes execution. + */ +void qemu_plugin_register_vcpu_resume_cb(qemu_plugin_id_t id, + qemu_plugin_vcpu_simple_cb_t cb); + +/* + * Opaque types that the plugin is given during the translation and + * instrumentation phase. + */ +struct qemu_plugin_tb; +struct qemu_plugin_insn; + +enum qemu_plugin_cb_flags { + QEMU_PLUGIN_CB_NO_REGS, /* callback does not access the CPU's regs */ + QEMU_PLUGIN_CB_R_REGS, /* callback reads the CPU's regs */ + QEMU_PLUGIN_CB_RW_REGS, /* callback reads and writes the CPU's regs */ +}; + +enum qemu_plugin_mem_rw { + QEMU_PLUGIN_MEM_R = 1, + QEMU_PLUGIN_MEM_W, + QEMU_PLUGIN_MEM_RW, +}; + +/** + * qemu_plugin_register_vcpu_tb_trans_cb() - register a translate cb + * @id: plugin ID + * @cb: callback function + * + * The @cb function is called every time a translation occurs. The @cb + * function is passed an opaque qemu_plugin_type which it can query + * for additional information including the list of translated + * instructions. At this point the plugin can register further + * callbacks to be triggered when the block or individual instruction + * executes. + */ +typedef void (*qemu_plugin_vcpu_tb_trans_cb_t)(qemu_plugin_id_t id, + struct qemu_plugin_tb *tb); + +void qemu_plugin_register_vcpu_tb_trans_cb(qemu_plugin_id_t id, + qemu_plugin_vcpu_tb_trans_cb_t cb); + +/** + * qemu_plugin_register_vcpu_tb_trans_exec_cb() - register execution callback + * @tb: the opaque qemu_plugin_tb handle for the translation + * @cb: callback function + * @flags: does the plugin read or write the CPU's registers? + * @userdata: any plugin data to pass to the @cb? + * + * The @cb function is called every time a translated unit executes. + */ +void qemu_plugin_register_vcpu_tb_exec_cb(struct qemu_plugin_tb *tb, + qemu_plugin_vcpu_udata_cb_t cb, + enum qemu_plugin_cb_flags flags, + void *userdata); + +enum qemu_plugin_op { + QEMU_PLUGIN_INLINE_ADD_U64, +}; + +/** + * qemu_plugin_register_vcpu_tb_trans_exec_inline() - execution inline op + * @tb: the opaque qemu_plugin_tb handle for the translation + * @op: the type of qemu_plugin_op (e.g. ADD_U64) + * @ptr: the target memory location for the op + * @imm: the op data (e.g. 1) + * + * Insert an inline op to every time a translated unit executes. + * Useful if you just want to increment a single counter somewhere in + * memory. + */ +void qemu_plugin_register_vcpu_tb_exec_inline(struct qemu_plugin_tb *tb, + enum qemu_plugin_op op, + void *ptr, uint64_t imm); + +/** + * qemu_plugin_register_vcpu_insn_exec_cb() - register insn execution cb + * @insn: the opaque qemu_plugin_insn handle for an instruction + * @cb: callback function + * @flags: does the plugin read or write the CPU's registers? + * @userdata: any plugin data to pass to the @cb? + * + * The @cb function is called every time an instruction is executed + */ +void qemu_plugin_register_vcpu_insn_exec_cb(struct qemu_plugin_insn *insn, + qemu_plugin_vcpu_udata_cb_t cb, + enum qemu_plugin_cb_flags flags, + void *userdata); + +/** + * qemu_plugin_register_vcpu_insn_exec_inline() - insn execution inline op + * @insn: the opaque qemu_plugin_insn handle for an instruction + * @cb: callback function + * @op: the type of qemu_plugin_op (e.g. ADD_U64) + * @ptr: the target memory location for the op + * @imm: the op data (e.g. 1) + * + * Insert an inline op to every time an instruction executes. Useful + * if you just want to increment a single counter somewhere in memory. + */ +void qemu_plugin_register_vcpu_insn_exec_inline(struct qemu_plugin_insn *insn, + enum qemu_plugin_op op, + void *ptr, uint64_t imm); + +/* + * Helpers to query information about the instructions in a block + */ +size_t qemu_plugin_tb_n_insns(const struct qemu_plugin_tb *tb); + +uint64_t qemu_plugin_tb_vaddr(const struct qemu_plugin_tb *tb); + +struct qemu_plugin_insn * +qemu_plugin_tb_get_insn(const struct qemu_plugin_tb *tb, size_t idx); + +const void *qemu_plugin_insn_data(const struct qemu_plugin_insn *insn); + +size_t qemu_plugin_insn_size(const struct qemu_plugin_insn *insn); + +uint64_t qemu_plugin_insn_vaddr(const struct qemu_plugin_insn *insn); +void *qemu_plugin_insn_haddr(const struct qemu_plugin_insn *insn); + +/* + * Memory Instrumentation + * + * The anonymous qemu_plugin_meminfo_t and qemu_plugin_hwaddr types + * can be used in queries to QEMU to get more information about a + * given memory access. + */ +typedef uint32_t qemu_plugin_meminfo_t; +struct qemu_plugin_hwaddr; + +/* meminfo queries */ +unsigned int qemu_plugin_mem_size_shift(qemu_plugin_meminfo_t info); +bool qemu_plugin_mem_is_sign_extended(qemu_plugin_meminfo_t info); +bool qemu_plugin_mem_is_big_endian(qemu_plugin_meminfo_t info); +bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info); + +/* + * qemu_plugin_get_hwaddr(): + * @vaddr: the virtual address of the memory operation + * + * For system emulation returns a qemu_plugin_hwaddr handle to query + * details about the actual physical address backing the virtual + * address. For linux-user guests it just returns NULL. + * + * This handle is *only* valid for the duration of the callback. Any + * information about the handle should be recovered before the + * callback returns. + */ +struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info, + uint64_t vaddr); + +bool qemu_plugin_hwaddr_is_io(struct qemu_plugin_hwaddr *hwaddr); +uint64_t qemu_plugin_hwaddr_to_raddr(const struct qemu_plugin_hwaddr *haddr); + +typedef void +(*qemu_plugin_vcpu_mem_cb_t)(unsigned int vcpu_index, + qemu_plugin_meminfo_t info, uint64_t vaddr, + void *userdata); + +void qemu_plugin_register_vcpu_mem_cb(struct qemu_plugin_insn *insn, + qemu_plugin_vcpu_mem_cb_t cb, + enum qemu_plugin_cb_flags flags, + enum qemu_plugin_mem_rw rw, + void *userdata); + +void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, + enum qemu_plugin_mem_rw rw, + enum qemu_plugin_op op, void *ptr, + uint64_t imm); + + + +typedef void +(*qemu_plugin_vcpu_syscall_cb_t)(qemu_plugin_id_t id, unsigned int vcpu_index, + int64_t num, uint64_t a1, uint64_t a2, + uint64_t a3, uint64_t a4, uint64_t a5, + uint64_t a6, uint64_t a7, uint64_t a8); + +void qemu_plugin_register_vcpu_syscall_cb(qemu_plugin_id_t id, + qemu_plugin_vcpu_syscall_cb_t cb); + +typedef void +(*qemu_plugin_vcpu_syscall_ret_cb_t)(qemu_plugin_id_t id, unsigned int vcpu_idx, + int64_t num, int64_t ret); + +void +qemu_plugin_register_vcpu_syscall_ret_cb(qemu_plugin_id_t id, + qemu_plugin_vcpu_syscall_ret_cb_t cb); + + +/** + * qemu_plugin_vcpu_for_each() - iterate over the existing vCPU + * @id: plugin ID + * @cb: callback function + * + * The @cb function is called once for each existing vCPU. + * + * See also: qemu_plugin_register_vcpu_init_cb() + */ +void qemu_plugin_vcpu_for_each(qemu_plugin_id_t id, + qemu_plugin_vcpu_simple_cb_t cb); + +void qemu_plugin_register_flush_cb(qemu_plugin_id_t id, + qemu_plugin_simple_cb_t cb); + +void qemu_plugin_register_atexit_cb(qemu_plugin_id_t id, + qemu_plugin_udata_cb_t cb, void *userdata); + +/* returns -1 in user-mode */ +int qemu_plugin_n_vcpus(void); + +/* returns -1 in user-mode */ +int qemu_plugin_n_max_vcpus(void); + +#endif /* QEMU_PLUGIN_API_H */ From patchwork Wed Jul 31 16:06:39 2019 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: 11068629 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 32AA5174A for ; Wed, 31 Jul 2019 16:17:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 192961FE8D for ; Wed, 31 Jul 2019 16:17:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D1551FFCD; Wed, 31 Jul 2019 16:17:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 02F361FE8D for ; Wed, 31 Jul 2019 16:17:18 +0000 (UTC) Received: from localhost ([::1]:42454 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrHx-0001fQ-Bj for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:17:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40499) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsr8q-0002EA-FE for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsr8l-0000os-M4 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:52 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:53439) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsr8h-0000hE-Fk for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:44 -0400 Received: by mail-wm1-x343.google.com with SMTP id x15so61446575wmj.3 for ; Wed, 31 Jul 2019 09:07:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PyuNAd62WafBkPyzjLkLJFNPloDx6RxzH0iHKy1UcSQ=; b=PCtpoxzn2H/A++70irpf2948apFcjaDzCGYKsRHSjJbA1TfCbO2GE4IcZddDX4dOZi cu4oJlF8eohOrwU9y1QkzZUlRandMtWNUKCZFLxM8ybLlMfIGYxMd/sFtnJP8xg+VqEO Tt7YtVKi0eytWxFPVsM+CUp0F2RzKLInjONeb6DCSXdQrYBsDtoJhyTp6wswflBbk5tg vift3mjuQ/SWghQfH87VXal49r8usUYAOWq5ou3RwrUiFXtU8A5b8ei3xhcf/c2r4Rj7 glcHKDhfp2sBFya0x/BmcvyNjp3n0IrMefBSjzegujaY67Fs45Azsv8+Tt3dzk5Q/8Ur qVPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PyuNAd62WafBkPyzjLkLJFNPloDx6RxzH0iHKy1UcSQ=; b=SFDxWr4pBm4x3WVA7CBIzQkU5jC4kqwvvi0E4FkiL8uSEvG9dpkTpmrhycJ2RlRMQt PadQOvhk1QFRHuYBADPoz9yLo0AHK3K0cwhVIbtDkq4NN3Hc7p8GVliKAIc7Fa0tFgd6 DhmDRCfo+aRoVdKAzkfs62FXOokWdQN6tiJtajSnOgQs3SFNE5DRgIDAjmf07CVcctHy XWPMbKF+KQOsEsY7yMRnHmFoufG99qbc3RKVAoO9BRkoX8JlN+HF3v916wvpLtwnouMV f+pXgV9bUpOb9mlIwk9+YAhWt0dK3U6/jku8wjPd1Xo8/FwZKxPs9/CbkOAMMPjJLDq/ P9+Q== X-Gm-Message-State: APjAAAVyXKhG+4i0mCSQMvTQCLYBCgo26juwqC7GUJYBKBlBUShgJj59 R3BKbTCl2g4iaklMFdWhFm9WtQ== X-Google-Smtp-Source: APXvYqx+F181WY+ffA+q4JtJ2ztza7bIe3gKRfTapJb+px991HjyyL+L5nroWpeNKKBOMc0HuhLaqg== X-Received: by 2002:a05:600c:2503:: with SMTP id d3mr114974638wma.41.1564589250899; Wed, 31 Jul 2019 09:07:30 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id a64sm4591646wmf.1.2019.07.31.09.07.23 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:07:26 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id BA93D1FF9D; Wed, 31 Jul 2019 17:07:20 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:39 +0100 Message-Id: <20190731160719.11396-15-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 Subject: [Qemu-devel] [PATCH v4 14/54] plugin: add core code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , aaron@os.amperecomputing.com, cota@braap.org, bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota [AJB: moved directory and merged various fixes] Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v3 - moved to plugins/ - merged plugin: remove uninstall_cb_t and just use simple_cb_t plugin: handle uninstall when !current_cpu plugin: introduce qemu_plugin_reset - split into core/loader - use GArray/GByteArray/GPtrArray instead of homegrown funcs v4 - document QEMU_PLUGIN_EV_MAX - move qemu_plugin_ram_addr_from_host to api - drop vcpu_index from trans cb - s/plugin_dyn_cb_type/plugin_dyn_cb_subtype/ in qemu_plugin_dyn_cb - remove haddr from memory hooks - checkpatch fixes --- Makefile | 9 +- Makefile.target | 2 + include/qemu/plugin.h | 255 +++++++++++++++++++++ include/qom/cpu.h | 6 + plugins/Makefile.objs | 6 + plugins/core.c | 499 ++++++++++++++++++++++++++++++++++++++++++ plugins/loader.c | 353 ++++++++++++++++++++++++++++++ plugins/plugin.h | 95 ++++++++ 8 files changed, 1224 insertions(+), 1 deletion(-) create mode 100644 include/qemu/plugin.h create mode 100644 plugins/Makefile.objs create mode 100644 plugins/core.c create mode 100644 plugins/loader.c create mode 100644 plugins/plugin.h diff --git a/Makefile b/Makefile index cfab1561b9c..ed4bb87f224 100644 --- a/Makefile +++ b/Makefile @@ -841,7 +841,11 @@ endif ICON_SIZES=16x16 24x24 32x32 48x48 64x64 128x128 256x256 512x512 -install: all $(if $(BUILD_DOCS),install-doc) install-datadir install-localstatedir \ +install-includedir: + $(INSTALL_DIR) "$(DESTDIR)$(includedir)" + +install: all $(if $(BUILD_DOCS),install-doc) \ + install-datadir install-localstatedir install-includedir \ $(if $(INSTALL_BLOBS),$(edk2-decompressed)) \ recurse-install ifneq ($(TOOLS),) @@ -903,6 +907,9 @@ endif "$(DESTDIR)$(qemu_desktopdir)/qemu.desktop" ifdef CONFIG_GTK $(MAKE) -C po $@ +endif +ifeq ($(CONFIG_PLUGIN),y) + $(INSTALL_DATA) $(SRC_PATH)/include/qemu/qemu-plugin.h "$(DESTDIR)$(includedir)/qemu-plugin.h" endif $(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/keymaps" set -e; for x in $(KEYMAPS); do \ diff --git a/Makefile.target b/Makefile.target index 933b27453a1..1c73028d17a 100644 --- a/Makefile.target +++ b/Makefile.target @@ -122,6 +122,8 @@ obj-y += disas.o obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o LIBS := $(libs_cpu) $(LIBS) +obj-$(CONFIG_PLUGIN) += plugins/ + ######################################################### # Linux user emulator target diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h new file mode 100644 index 00000000000..3c46a241669 --- /dev/null +++ b/include/qemu/plugin.h @@ -0,0 +1,255 @@ +/* + * Copyright (C) 2017, Emilio G. Cota + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#ifndef QEMU_PLUGIN_H +#define QEMU_PLUGIN_H + +#include "qemu/config-file.h" +#include "qemu/qemu-plugin.h" +#include "qemu/error-report.h" +#include "qemu/queue.h" +#include "qemu/option.h" + +/* + * Option parsing/processing. + * Note that we can load an arbitrary number of plugins. + */ +struct qemu_plugin_desc; +typedef QTAILQ_HEAD(, qemu_plugin_desc) QemuPluginList; + +#ifdef CONFIG_PLUGIN +extern QemuOptsList qemu_plugin_opts; + +static inline void qemu_plugin_add_opts(void) +{ + qemu_add_opts(&qemu_plugin_opts); +} + +void qemu_plugin_opt_parse(const char *optarg, QemuPluginList *head); +int qemu_plugin_load_list(QemuPluginList *head); +#else /* !CONFIG_PLUGIN */ +static inline void qemu_plugin_add_opts(void) +{ } + +static inline void qemu_plugin_opt_parse(const char *optarg, + QemuPluginList *head) +{ + error_report("plugin interface not enabled in this build"); + exit(1); +} + +static inline int qemu_plugin_load_list(QemuPluginList *head) +{ + return 0; +} +#endif /* !CONFIG_PLUGIN */ + +/* + * Events that plugins can subscribe to. + */ +enum qemu_plugin_event { + QEMU_PLUGIN_EV_VCPU_INIT, + QEMU_PLUGIN_EV_VCPU_EXIT, + QEMU_PLUGIN_EV_VCPU_TB_TRANS, + QEMU_PLUGIN_EV_VCPU_IDLE, + QEMU_PLUGIN_EV_VCPU_RESUME, + QEMU_PLUGIN_EV_VCPU_SYSCALL, + QEMU_PLUGIN_EV_VCPU_SYSCALL_RET, + QEMU_PLUGIN_EV_FLUSH, + QEMU_PLUGIN_EV_ATEXIT, + QEMU_PLUGIN_EV_MAX, /* total number of plugin events we support */ +}; + +union qemu_plugin_cb_sig { + qemu_plugin_simple_cb_t simple; + qemu_plugin_udata_cb_t udata; + qemu_plugin_vcpu_simple_cb_t vcpu_simple; + qemu_plugin_vcpu_udata_cb_t vcpu_udata; + qemu_plugin_vcpu_tb_trans_cb_t vcpu_tb_trans; + qemu_plugin_vcpu_mem_cb_t vcpu_mem; + qemu_plugin_vcpu_syscall_cb_t vcpu_syscall; + qemu_plugin_vcpu_syscall_ret_cb_t vcpu_syscall_ret; + void *generic; +}; + +enum plugin_dyn_cb_type { + PLUGIN_CB_INSN, + PLUGIN_CB_MEM, + PLUGIN_N_CB_TYPES, +}; + +enum plugin_dyn_cb_subtype { + PLUGIN_CB_REGULAR, + PLUGIN_CB_INLINE, + PLUGIN_N_CB_SUBTYPES, +}; + +/* + * A dynamic callback has an insertion point that is determined at run-time. + * Usually the insertion point is somewhere in the code cache; think for + * instance of a callback to be called upon the execution of a particular TB. + */ +struct qemu_plugin_dyn_cb { + union qemu_plugin_cb_sig f; + void *userp; + unsigned tcg_flags; + enum plugin_dyn_cb_subtype type; + /* @rw applies to mem callbacks only (both regular and inline) */ + enum qemu_plugin_mem_rw rw; + /* fields specific to each dyn_cb type go here */ + union { + struct { + enum qemu_plugin_op op; + uint64_t imm; + } inline_insn; + }; +}; + +struct qemu_plugin_insn { + GByteArray *data; + uint64_t vaddr; + void *haddr; + GArray *cbs[PLUGIN_N_CB_TYPES][PLUGIN_N_CB_SUBTYPES]; + bool calls_helpers; + bool mem_helper; +}; + +/* + * qemu_plugin_insn allocate and cleanup functions. We don't expect to + * cleanup many of these structures. They are reused for each fresh + * translation. + */ + +static inline void qemu_plugin_insn_cleanup_fn(gpointer data) +{ + struct qemu_plugin_insn *insn = (struct qemu_plugin_insn *) data; + g_byte_array_free(insn->data, true); +} + +static inline struct qemu_plugin_insn * qemu_plugin_insn_alloc(void) +{ + int i, j; + struct qemu_plugin_insn *insn = g_new0(struct qemu_plugin_insn, 1); + insn->data = g_byte_array_sized_new(4); + + for (i = 0; i < PLUGIN_N_CB_TYPES; i++) { + for (j = 0; j < PLUGIN_N_CB_SUBTYPES; j++) { + insn->cbs[i][j] = g_array_new(false, false, + sizeof(struct qemu_plugin_dyn_cb)); + } + } + return insn; +} + +struct qemu_plugin_tb { + GPtrArray *insns; + size_t n; + uint64_t vaddr; + uint64_t vaddr2; + void *haddr1; + void *haddr2; + GArray *cbs[PLUGIN_N_CB_SUBTYPES]; +}; + +/** + * qemu_plugin_tb_insn_get(): get next plugin record for translation. + * + */ +static inline +struct qemu_plugin_insn *qemu_plugin_tb_insn_get(struct qemu_plugin_tb *tb) +{ + struct qemu_plugin_insn *insn; + int i, j; + + if (unlikely(tb->n == tb->insns->len)) { + struct qemu_plugin_insn *new_insn = qemu_plugin_insn_alloc(); + g_ptr_array_add(tb->insns, new_insn); + } + insn = g_ptr_array_index(tb->insns, tb->n++); + g_byte_array_set_size(insn->data, 0); + insn->calls_helpers = false; + insn->mem_helper = false; + + for (i = 0; i < PLUGIN_N_CB_TYPES; i++) { + for (j = 0; j < PLUGIN_N_CB_SUBTYPES; j++) { + g_array_set_size(insn->cbs[i][j], 0); + } + } + + return insn; +} + +#ifdef CONFIG_PLUGIN + +void qemu_plugin_vcpu_init_hook(CPUState *cpu); +void qemu_plugin_vcpu_exit_hook(CPUState *cpu); +void qemu_plugin_tb_trans_cb(CPUState *cpu, struct qemu_plugin_tb *tb); +void qemu_plugin_vcpu_idle_cb(CPUState *cpu); +void qemu_plugin_vcpu_resume_cb(CPUState *cpu); +void +qemu_plugin_vcpu_syscall(CPUState *cpu, int64_t num, uint64_t a1, + uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, + uint64_t a6, uint64_t a7, uint64_t a8); +void qemu_plugin_vcpu_syscall_ret(CPUState *cpu, int64_t num, int64_t ret); + +void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr, uint32_t meminfo); + +void qemu_plugin_flush_cb(void); + +void qemu_plugin_atexit_cb(void); + +void qemu_plugin_add_dyn_cb_arr(GArray *arr); + +void qemu_plugin_disable_mem_helpers(CPUState *cpu); + +#else /* !CONFIG_PLUGIN */ + +static inline void qemu_plugin_vcpu_init_hook(CPUState *cpu) +{ } + +static inline void qemu_plugin_vcpu_exit_hook(CPUState *cpu) +{ } + +static inline void qemu_plugin_tb_trans_cb(CPUState *cpu, + struct qemu_plugin_tb *tb) +{ } + +static inline void qemu_plugin_vcpu_idle_cb(CPUState *cpu) +{ } + +static inline void qemu_plugin_vcpu_resume_cb(CPUState *cpu) +{ } + +static inline void +qemu_plugin_vcpu_syscall(CPUState *cpu, int64_t num, uint64_t a1, uint64_t a2, + uint64_t a3, uint64_t a4, uint64_t a5, uint64_t a6, + uint64_t a7, uint64_t a8) +{ } + +static inline +void qemu_plugin_vcpu_syscall_ret(CPUState *cpu, int64_t num, int64_t ret) +{ } + +static inline void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr, + uint32_t meminfo) +{ } + +static inline void qemu_plugin_flush_cb(void) +{ } + +static inline void qemu_plugin_atexit_cb(void) +{ } + +static inline +void qemu_plugin_add_dyn_cb_arr(GArray *arr) +{ } + +static inline void qemu_plugin_disable_mem_helpers(CPUState *cpu) +{ } + +#endif /* !CONFIG_PLUGIN */ + +#endif /* QEMU_PLUGIN_H */ diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 65a0926c49a..7a71d0017fa 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -29,6 +29,7 @@ #include "qemu/rcu_queue.h" #include "qemu/queue.h" #include "qemu/thread.h" +#include "qemu/plugin.h" typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size, void *opaque); @@ -345,6 +346,7 @@ struct qemu_work_item; * @trace_dstate_delayed: Delayed changes to trace_dstate (includes all changes * to @trace_dstate). * @trace_dstate: Dynamic tracing state of events for this vCPU (bitmask). + * @plugin_mask: Plugin event bitmap. Modified only via async work. * @ignore_memory_transaction_failures: Cached copy of the MachineState * flag of the same name: allows the board to suppress calling of the * CPU do_transaction_failed hook function. @@ -430,6 +432,10 @@ struct CPUState { DECLARE_BITMAP(trace_dstate_delayed, CPU_TRACE_DSTATE_MAX_EVENTS); DECLARE_BITMAP(trace_dstate, CPU_TRACE_DSTATE_MAX_EVENTS); + DECLARE_BITMAP(plugin_mask, QEMU_PLUGIN_EV_MAX); + + GArray *plugin_mem_cbs; + /* TODO Move common fields from CPUArchState here. */ int cpu_index; int cluster_index; diff --git a/plugins/Makefile.objs b/plugins/Makefile.objs new file mode 100644 index 00000000000..58940335bca --- /dev/null +++ b/plugins/Makefile.objs @@ -0,0 +1,6 @@ +# +# Plugin Support +# + +obj-y += loader.o +obj-y += core.o diff --git a/plugins/core.c b/plugins/core.c new file mode 100644 index 00000000000..28616b724ee --- /dev/null +++ b/plugins/core.c @@ -0,0 +1,499 @@ +/* + * plugin.c - QEMU Plugin interface + * + * Copyright (C) 2017, Emilio G. Cota + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "qemu/config-file.h" +#include "qapi/error.h" +#include "qemu/option.h" +#include "qemu/rcu_queue.h" +#include "qemu/xxhash.h" +#include "qemu/rcu.h" +#include "qom/cpu.h" +#include "exec/cpu-common.h" +#include + +#include "cpu.h" +#include "exec/exec-all.h" +#include "exec/helper-proto.h" +#include "sysemu/sysemu.h" +#include "tcg/tcg.h" +#include "tcg/tcg-op.h" +#include "trace/mem-internal.h" /* mem_info macros */ +#include "plugin.h" + +struct qemu_plugin_cb { + struct qemu_plugin_ctx *ctx; + union qemu_plugin_cb_sig f; + void *udata; + QLIST_ENTRY(qemu_plugin_cb) entry; +}; + +QLIST_HEAD(qemu_plugin_cb_head, qemu_plugin_cb); + +struct qemu_plugin_state plugin; + +struct qemu_plugin_ctx *plugin_id_to_ctx_locked(qemu_plugin_id_t id) +{ + struct qemu_plugin_ctx *ctx; + qemu_plugin_id_t *id_p; + + id_p = g_hash_table_lookup(plugin.id_ht, &id); + ctx = container_of(id_p, struct qemu_plugin_ctx, id); + if (ctx == NULL) { + error_report("plugin: invalid plugin id %" PRIu64, id); + abort(); + } + return ctx; +} + +static void plugin_cpu_update__async(CPUState *cpu, run_on_cpu_data data) +{ + bitmap_copy(cpu->plugin_mask, &data.host_ulong, QEMU_PLUGIN_EV_MAX); + cpu_tb_jmp_cache_clear(cpu); +} + +static void plugin_cpu_update__locked(gpointer k, gpointer v, gpointer udata) +{ + CPUState *cpu = container_of(k, CPUState, cpu_index); + run_on_cpu_data mask = RUN_ON_CPU_HOST_ULONG(*plugin.mask); + + if (cpu->created) { + async_run_on_cpu(cpu, plugin_cpu_update__async, mask); + } else { + plugin_cpu_update__async(cpu, mask); + } +} + +void plugin_unregister_cb__locked(struct qemu_plugin_ctx *ctx, + enum qemu_plugin_event ev) +{ + struct qemu_plugin_cb *cb = ctx->callbacks[ev]; + + if (cb == NULL) { + return; + } + QLIST_REMOVE_RCU(cb, entry); + g_free(cb); + ctx->callbacks[ev] = NULL; + if (QLIST_EMPTY_RCU(&plugin.cb_lists[ev])) { + clear_bit(ev, plugin.mask); + g_hash_table_foreach(plugin.cpu_ht, plugin_cpu_update__locked, NULL); + } +} + +static void plugin_vcpu_cb__simple(CPUState *cpu, enum qemu_plugin_event ev) +{ + struct qemu_plugin_cb *cb, *next; + + switch (ev) { + case QEMU_PLUGIN_EV_VCPU_INIT: + case QEMU_PLUGIN_EV_VCPU_EXIT: + case QEMU_PLUGIN_EV_VCPU_IDLE: + case QEMU_PLUGIN_EV_VCPU_RESUME: + /* iterate safely; plugins might uninstall themselves at any time */ + QLIST_FOREACH_SAFE_RCU(cb, &plugin.cb_lists[ev], entry, next) { + qemu_plugin_vcpu_simple_cb_t func = cb->f.vcpu_simple; + + func(cb->ctx->id, cpu->cpu_index); + } + break; + default: + g_assert_not_reached(); + } +} + +static void plugin_cb__simple(enum qemu_plugin_event ev) +{ + struct qemu_plugin_cb *cb, *next; + + switch (ev) { + case QEMU_PLUGIN_EV_FLUSH: + QLIST_FOREACH_SAFE_RCU(cb, &plugin.cb_lists[ev], entry, next) { + qemu_plugin_simple_cb_t func = cb->f.simple; + + func(cb->ctx->id); + } + break; + default: + g_assert_not_reached(); + } +} + +static void plugin_cb__udata(enum qemu_plugin_event ev) +{ + struct qemu_plugin_cb *cb, *next; + + switch (ev) { + case QEMU_PLUGIN_EV_ATEXIT: + QLIST_FOREACH_SAFE_RCU(cb, &plugin.cb_lists[ev], entry, next) { + qemu_plugin_udata_cb_t func = cb->f.udata; + + func(cb->ctx->id, cb->udata); + } + break; + default: + g_assert_not_reached(); + } +} + +static void +do_plugin_register_cb(qemu_plugin_id_t id, enum qemu_plugin_event ev, + void *func, void *udata) +{ + struct qemu_plugin_ctx *ctx; + + qemu_rec_mutex_lock(&plugin.lock); + ctx = plugin_id_to_ctx_locked(id); + /* if the plugin is on its way out, ignore this request */ + if (unlikely(ctx->uninstalling)) { + goto out_unlock; + } + if (func) { + struct qemu_plugin_cb *cb = ctx->callbacks[ev]; + + if (cb) { + cb->f.generic = func; + cb->udata = udata; + } else { + cb = g_new(struct qemu_plugin_cb, 1); + cb->ctx = ctx; + cb->f.generic = func; + cb->udata = udata; + ctx->callbacks[ev] = cb; + QLIST_INSERT_HEAD_RCU(&plugin.cb_lists[ev], cb, entry); + if (!test_bit(ev, plugin.mask)) { + set_bit(ev, plugin.mask); + g_hash_table_foreach(plugin.cpu_ht, plugin_cpu_update__locked, + NULL); + } + } + } else { + plugin_unregister_cb__locked(ctx, ev); + } + out_unlock: + qemu_rec_mutex_unlock(&plugin.lock); +} + +void plugin_register_cb(qemu_plugin_id_t id, enum qemu_plugin_event ev, + void *func) +{ + do_plugin_register_cb(id, ev, func, NULL); +} + +void +plugin_register_cb_udata(qemu_plugin_id_t id, enum qemu_plugin_event ev, + void *func, void *udata) +{ + do_plugin_register_cb(id, ev, func, udata); +} + +void qemu_plugin_vcpu_init_hook(CPUState *cpu) +{ + bool success; + + qemu_rec_mutex_lock(&plugin.lock); + plugin_cpu_update__locked(&cpu->cpu_index, NULL, NULL); + success = g_hash_table_insert(plugin.cpu_ht, &cpu->cpu_index, + &cpu->cpu_index); + g_assert(success); + qemu_rec_mutex_unlock(&plugin.lock); + + plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_INIT); +} + +void qemu_plugin_vcpu_exit_hook(CPUState *cpu) +{ + bool success; + + plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_EXIT); + + qemu_rec_mutex_lock(&plugin.lock); + success = g_hash_table_remove(plugin.cpu_ht, &cpu->cpu_index); + g_assert(success); + qemu_rec_mutex_unlock(&plugin.lock); +} + +struct plugin_for_each_args { + struct qemu_plugin_ctx *ctx; + qemu_plugin_vcpu_simple_cb_t cb; +}; + +static void plugin_vcpu_for_each(gpointer k, gpointer v, gpointer udata) +{ + struct plugin_for_each_args *args = udata; + int cpu_index = *(int *)k; + + args->cb(args->ctx->id, cpu_index); +} + +void qemu_plugin_vcpu_for_each(qemu_plugin_id_t id, + qemu_plugin_vcpu_simple_cb_t cb) +{ + struct plugin_for_each_args args; + + if (cb == NULL) { + return; + } + qemu_rec_mutex_lock(&plugin.lock); + args.ctx = plugin_id_to_ctx_locked(id); + args.cb = cb; + g_hash_table_foreach(plugin.cpu_ht, plugin_vcpu_for_each, &args); + qemu_rec_mutex_unlock(&plugin.lock); +} + +/* Allocate and return a callback record */ +static struct qemu_plugin_dyn_cb *plugin_get_dyn_cb(GArray **arr) +{ + GArray *cbs = *arr; + + if (!cbs) { + cbs = g_array_sized_new(false, false, sizeof(struct qemu_plugin_dyn_cb), 1); + *arr = cbs; + } + + g_array_set_size(cbs, cbs->len + 1); + return &g_array_index(cbs, struct qemu_plugin_dyn_cb, cbs->len - 1); +} + +void plugin_register_inline_op(GArray **arr, + enum qemu_plugin_mem_rw rw, + enum qemu_plugin_op op, void *ptr, + uint64_t imm) +{ + struct qemu_plugin_dyn_cb *dyn_cb; + + dyn_cb = plugin_get_dyn_cb(arr); + dyn_cb->userp = ptr; + dyn_cb->type = PLUGIN_CB_INLINE; + dyn_cb->rw = rw; + dyn_cb->inline_insn.op = op; + dyn_cb->inline_insn.imm = imm; +} + +static inline uint32_t cb_to_tcg_flags(enum qemu_plugin_cb_flags flags) +{ + uint32_t ret; + + switch (flags) { + case QEMU_PLUGIN_CB_RW_REGS: + ret = 0; + case QEMU_PLUGIN_CB_R_REGS: + ret = TCG_CALL_NO_WG; + break; + case QEMU_PLUGIN_CB_NO_REGS: + default: + ret = TCG_CALL_NO_RWG; + } + return ret; +} + +inline void +plugin_register_dyn_cb__udata(GArray **arr, + qemu_plugin_vcpu_udata_cb_t cb, + enum qemu_plugin_cb_flags flags, void *udata) +{ + struct qemu_plugin_dyn_cb *dyn_cb = plugin_get_dyn_cb(arr); + + dyn_cb->userp = udata; + dyn_cb->tcg_flags = cb_to_tcg_flags(flags); + dyn_cb->f.vcpu_udata = cb; + dyn_cb->type = PLUGIN_CB_REGULAR; +} + +void plugin_register_vcpu_mem_cb(GArray **arr, + void *cb, + enum qemu_plugin_cb_flags flags, + enum qemu_plugin_mem_rw rw, + void *udata) +{ + struct qemu_plugin_dyn_cb *dyn_cb; + + dyn_cb = plugin_get_dyn_cb(arr); + dyn_cb->userp = udata; + dyn_cb->tcg_flags = cb_to_tcg_flags(flags); + dyn_cb->type = PLUGIN_CB_REGULAR; + dyn_cb->rw = rw; + dyn_cb->f.generic = cb; +} + +void qemu_plugin_tb_trans_cb(CPUState *cpu, struct qemu_plugin_tb *tb) +{ + struct qemu_plugin_cb *cb, *next; + enum qemu_plugin_event ev = QEMU_PLUGIN_EV_VCPU_TB_TRANS; + + /* no plugin_mask check here; caller should have checked */ + + QLIST_FOREACH_SAFE_RCU(cb, &plugin.cb_lists[ev], entry, next) { + qemu_plugin_vcpu_tb_trans_cb_t func = cb->f.vcpu_tb_trans; + + func(cb->ctx->id, tb); + } +} + +void +qemu_plugin_vcpu_syscall(CPUState *cpu, int64_t num, uint64_t a1, uint64_t a2, + uint64_t a3, uint64_t a4, uint64_t a5, + uint64_t a6, uint64_t a7, uint64_t a8) +{ + struct qemu_plugin_cb *cb, *next; + enum qemu_plugin_event ev = QEMU_PLUGIN_EV_VCPU_SYSCALL; + + if (!test_bit(ev, cpu->plugin_mask)) { + return; + } + + QLIST_FOREACH_SAFE_RCU(cb, &plugin.cb_lists[ev], entry, next) { + qemu_plugin_vcpu_syscall_cb_t func = cb->f.vcpu_syscall; + + func(cb->ctx->id, cpu->cpu_index, num, a1, a2, a3, a4, a5, a6, a7, a8); + } +} + +void qemu_plugin_vcpu_syscall_ret(CPUState *cpu, int64_t num, int64_t ret) +{ + struct qemu_plugin_cb *cb, *next; + enum qemu_plugin_event ev = QEMU_PLUGIN_EV_VCPU_SYSCALL_RET; + + if (!test_bit(ev, cpu->plugin_mask)) { + return; + } + + QLIST_FOREACH_SAFE_RCU(cb, &plugin.cb_lists[ev], entry, next) { + qemu_plugin_vcpu_syscall_ret_cb_t func = cb->f.vcpu_syscall_ret; + + func(cb->ctx->id, cpu->cpu_index, num, ret); + } +} + +void qemu_plugin_vcpu_idle_cb(CPUState *cpu) +{ + plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_IDLE); +} + +void qemu_plugin_vcpu_resume_cb(CPUState *cpu) +{ + plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_RESUME); +} + +void qemu_plugin_register_vcpu_idle_cb(qemu_plugin_id_t id, + qemu_plugin_vcpu_simple_cb_t cb) +{ + plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_IDLE, cb); +} + +void qemu_plugin_register_vcpu_resume_cb(qemu_plugin_id_t id, + qemu_plugin_vcpu_simple_cb_t cb) +{ + plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_RESUME, cb); +} + +void qemu_plugin_register_flush_cb(qemu_plugin_id_t id, + qemu_plugin_simple_cb_t cb) +{ + plugin_register_cb(id, QEMU_PLUGIN_EV_FLUSH, cb); +} + +static bool free_dyn_cb_arr(void *p, uint32_t h, void *userp) +{ + g_array_free((GArray *) p, true); + return true; +} + +void qemu_plugin_flush_cb(void) +{ + qht_iter_remove(&plugin.dyn_cb_arr_ht, free_dyn_cb_arr, NULL); + qht_reset(&plugin.dyn_cb_arr_ht); + + plugin_cb__simple(QEMU_PLUGIN_EV_FLUSH); +} + +void exec_inline_op(struct qemu_plugin_dyn_cb *cb) +{ + uint64_t *val = cb->userp; + + switch (cb->inline_insn.op) { + case QEMU_PLUGIN_INLINE_ADD_U64: + *val += cb->inline_insn.imm; + break; + default: + g_assert_not_reached(); + } +} + +void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr, uint32_t info) +{ + GArray *arr = cpu->plugin_mem_cbs; + size_t i; + + if (arr == NULL) { + return; + } + for (i = 0; i < arr->len; i++) { + struct qemu_plugin_dyn_cb *cb = + &g_array_index(arr, struct qemu_plugin_dyn_cb, i); + int w = !!(info & TRACE_MEM_ST) + 1; + + if (!(w & cb->rw)) { + break; + } + switch (cb->type) { + case PLUGIN_CB_REGULAR: + cb->f.vcpu_mem(cpu->cpu_index, info, vaddr, cb->userp); + break; + case PLUGIN_CB_INLINE: + exec_inline_op(cb); + break; + default: + g_assert_not_reached(); + } + } +} + +void qemu_plugin_atexit_cb(void) +{ + plugin_cb__udata(QEMU_PLUGIN_EV_ATEXIT); +} + +void qemu_plugin_register_atexit_cb(qemu_plugin_id_t id, + qemu_plugin_udata_cb_t cb, + void *udata) +{ + plugin_register_cb_udata(id, QEMU_PLUGIN_EV_ATEXIT, cb, udata); +} + +/* + * Call this function after longjmp'ing to the main loop. It's possible that the + * last instruction of a TB might have used helpers, and therefore the + * "disable" instruction will never execute because it ended up as dead code. + */ +void qemu_plugin_disable_mem_helpers(CPUState *cpu) +{ + cpu->plugin_mem_cbs = NULL; +} + +static bool plugin_dyn_cb_arr_cmp(const void *ap, const void *bp) +{ + return ap == bp; +} + +static void __attribute__((__constructor__)) plugin_init(void) +{ + int i; + + for (i = 0; i < QEMU_PLUGIN_EV_MAX; i++) { + QLIST_INIT(&plugin.cb_lists[i]); + } + qemu_rec_mutex_init(&plugin.lock); + plugin.id_ht = g_hash_table_new(g_int64_hash, g_int64_equal); + plugin.cpu_ht = g_hash_table_new(g_int_hash, g_int_equal); + QTAILQ_INIT(&plugin.ctxs); + qht_init(&plugin.dyn_cb_arr_ht, plugin_dyn_cb_arr_cmp, 16, + QHT_MODE_AUTO_RESIZE); + atexit(qemu_plugin_atexit_cb); +} diff --git a/plugins/loader.c b/plugins/loader.c new file mode 100644 index 00000000000..bd77e88ede0 --- /dev/null +++ b/plugins/loader.c @@ -0,0 +1,353 @@ +#include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "qemu/config-file.h" +#include "qapi/error.h" +#include "qemu/option.h" +#include "qemu/rcu_queue.h" +#include "qemu/qht.h" +#include "qemu/bitmap.h" +#include "qemu/xxhash.h" +#include "qemu/plugin.h" +#include "qom/cpu.h" +#include +#include "cpu.h" +#include "exec/exec-all.h" + +#include "plugin.h" + +/* + * For convenience we use a bitmap for plugin.mask, but really all we need is a + * u32, which is what we store in TranslationBlock. + */ +QEMU_BUILD_BUG_ON(QEMU_PLUGIN_EV_MAX > 32); + +struct qemu_plugin_desc { + char *path; + char **argv; + QTAILQ_ENTRY(qemu_plugin_desc) entry; + int argc; +}; + +struct qemu_plugin_parse_arg { + QemuPluginList *head; + struct qemu_plugin_desc *curr; +}; + +QemuOptsList qemu_plugin_opts = { + .name = "plugin", + .implied_opt_name = "file", + .head = QTAILQ_HEAD_INITIALIZER(qemu_plugin_opts.head), + .desc = { + /* do our own parsing to support multiple plugins */ + { /* end of list */ } + }, +}; + +typedef int (*qemu_plugin_install_func_t)(qemu_plugin_id_t, int, char **); + +extern struct qemu_plugin_state plugin; + +void qemu_plugin_add_dyn_cb_arr(GArray *arr) +{ + uint32_t hash = qemu_xxhash2((uint64_t)(uintptr_t)arr); + bool inserted; + + inserted = qht_insert(&plugin.dyn_cb_arr_ht, arr, hash, NULL); + g_assert(inserted); +} + +static struct qemu_plugin_desc *plugin_find_desc(QemuPluginList *head, + const char *path) +{ + struct qemu_plugin_desc *desc; + + QTAILQ_FOREACH(desc, head, entry) { + if (strcmp(desc->path, path) == 0) { + return desc; + } + } + return NULL; +} + +static int plugin_add(void *opaque, const char *name, const char *value, + Error **errp) +{ + struct qemu_plugin_parse_arg *arg = opaque; + struct qemu_plugin_desc *p; + + if (strcmp(name, "file") == 0) { + if (strcmp(value, "") == 0) { + error_setg(errp, "requires a non-empty argument"); + return 1; + } + p = plugin_find_desc(arg->head, value); + if (p == NULL) { + p = g_new0(struct qemu_plugin_desc, 1); + p->path = g_strdup(value); + QTAILQ_INSERT_TAIL(arg->head, p, entry); + } + arg->curr = p; + } else if (strcmp(name, "arg") == 0) { + if (arg->curr == NULL) { + error_setg(errp, "missing earlier '-plugin file=' option"); + return 1; + } + p = arg->curr; + p->argc++; + p->argv = g_realloc_n(p->argv, p->argc, sizeof(char *)); + p->argv[p->argc - 1] = g_strdup(value); + } else { + error_setg(errp, "-plugin: unexpected parameter '%s'; ignored", name); + } + return 0; +} + +void qemu_plugin_opt_parse(const char *optarg, QemuPluginList *head) +{ + struct qemu_plugin_parse_arg arg; + QemuOpts *opts; + + opts = qemu_opts_parse_noisily(qemu_find_opts("plugin"), optarg, true); + if (opts == NULL) { + exit(1); + } + arg.head = head; + arg.curr = NULL; + qemu_opt_foreach(opts, plugin_add, &arg, &error_fatal); + qemu_opts_del(opts); +} + +/* + * From: https://en.wikipedia.org/wiki/Xorshift + * This is faster than rand_r(), and gives us a wider range (RAND_MAX is only + * guaranteed to be >= INT_MAX). + */ +static uint64_t xorshift64star(uint64_t x) +{ + x ^= x >> 12; /* a */ + x ^= x << 25; /* b */ + x ^= x >> 27; /* c */ + return x * UINT64_C(2685821657736338717); +} + +static int plugin_load(struct qemu_plugin_desc *desc) +{ + qemu_plugin_install_func_t install; + struct qemu_plugin_ctx *ctx; + char *err; + int rc; + + ctx = qemu_memalign(qemu_dcache_linesize, sizeof(*ctx)); + memset(ctx, 0, sizeof(*ctx)); + ctx->desc = desc; + + ctx->handle = dlopen(desc->path, RTLD_NOW); + if (ctx->handle == NULL) { + error_report("%s: %s", __func__, dlerror()); + goto err_dlopen; + } + + /* clear any previous dlerror, call dlsym, then check dlerror */ + dlerror(); + install = dlsym(ctx->handle, "qemu_plugin_install"); + err = dlerror(); + if (err) { + error_report("%s: %s", __func__, err); + goto err_symbol; + } + /* symbol was found; it could be NULL though */ + if (install == NULL) { + error_report("%s: %s: qemu_plugin_install is NULL", + __func__, desc->path); + goto err_symbol; + } + + qemu_rec_mutex_lock(&plugin.lock); + + /* find an unused random id with &ctx as the seed */ + ctx->id = (uint64_t)(uintptr_t)ctx; + for (;;) { + void *existing; + + ctx->id = xorshift64star(ctx->id); + existing = g_hash_table_lookup(plugin.id_ht, &ctx->id); + if (likely(existing == NULL)) { + bool success; + + success = g_hash_table_insert(plugin.id_ht, &ctx->id, &ctx->id); + g_assert(success); + break; + } + } + QTAILQ_INSERT_TAIL(&plugin.ctxs, ctx, entry); + ctx->installing = true; + rc = install(ctx->id, desc->argc, desc->argv); + ctx->installing = false; + if (rc) { + error_report("%s: qemu_plugin_install returned error code %d", + __func__, rc); + /* + * we cannot rely on the plugin doing its own cleanup, so + * call a full uninstall if the plugin did not yet call it. + */ + /* if (!ctx->uninstalling) { */ + /* qemu_plugin_uninstall(ctx->id, NULL); */ + /* } */ + } + + qemu_rec_mutex_unlock(&plugin.lock); + return rc; + + err_symbol: + if (dlclose(ctx->handle)) { + warn_report("%s: %s", __func__, dlerror()); + } + err_dlopen: + qemu_vfree(ctx); + return 1; +} + +/* call after having removed @desc from the list */ +static void plugin_desc_free(struct qemu_plugin_desc *desc) +{ + int i; + + for (i = 0; i < desc->argc; i++) { + g_free(desc->argv[i]); + } + g_free(desc->argv); + g_free(desc->path); + g_free(desc); +} + +/** + * qemu_plugin_load_list - load a list of plugins + * @head: head of the list of descriptors of the plugins to be loaded + * + * Returns 0 if all plugins in the list are installed, !0 otherwise. + * + * Note: the descriptor of each successfully installed plugin is removed + * from the list given by @head. + */ +int qemu_plugin_load_list(QemuPluginList *head) +{ + struct qemu_plugin_desc *desc, *next; + + QTAILQ_FOREACH_SAFE(desc, head, entry, next) { + int err; + + err = plugin_load(desc); + if (err) { + return err; + } + QTAILQ_REMOVE(head, desc, entry); + } + return 0; +} + +struct qemu_plugin_reset_data { + struct qemu_plugin_ctx *ctx; + qemu_plugin_simple_cb_t cb; + bool reset; +}; + +static void plugin_reset_destroy__locked(struct qemu_plugin_reset_data *data) +{ + struct qemu_plugin_ctx *ctx = data->ctx; + enum qemu_plugin_event ev; + bool success; + + /* + * After updating the subscription lists there is no need to wait for an RCU + * grace period to elapse, because right now we either are in a "safe async" + * work environment (i.e. all vCPUs are asleep), or no vCPUs have yet been + * created. + */ + for (ev = 0; ev < QEMU_PLUGIN_EV_MAX; ev++) { + plugin_unregister_cb__locked(ctx, ev); + } + + if (data->reset) { + g_assert(ctx->resetting); + if (data->cb) { + data->cb(ctx->id); + } + ctx->resetting = false; + g_free(data); + return; + } + + g_assert(ctx->uninstalling); + /* we cannot dlclose if we are going to return to plugin code */ + if (ctx->installing) { + error_report("Calling qemu_plugin_uninstall from the install function " + "is a bug. Instead, return !0 from the install function."); + abort(); + } + + success = g_hash_table_remove(plugin.id_ht, &ctx->id); + g_assert(success); + QTAILQ_REMOVE(&plugin.ctxs, ctx, entry); + if (data->cb) { + data->cb(ctx->id); + } + if (dlclose(ctx->handle)) { + warn_report("%s: %s", __func__, dlerror()); + } + plugin_desc_free(ctx->desc); + qemu_vfree(ctx); + g_free(data); +} + +static void plugin_reset_destroy(struct qemu_plugin_reset_data *data) +{ + qemu_rec_mutex_lock(&plugin.lock); + plugin_reset_destroy__locked(data); + qemu_rec_mutex_lock(&plugin.lock); +} + +static void plugin_flush_destroy(CPUState *cpu, run_on_cpu_data arg) +{ + struct qemu_plugin_reset_data *data = arg.host_ptr; + + g_assert(cpu_in_exclusive_context(cpu)); + tb_flush(cpu); + plugin_reset_destroy(data); +} + +void plugin_reset_uninstall(qemu_plugin_id_t id, + qemu_plugin_simple_cb_t cb, + bool reset) +{ + struct qemu_plugin_reset_data *data; + struct qemu_plugin_ctx *ctx; + + qemu_rec_mutex_lock(&plugin.lock); + ctx = plugin_id_to_ctx_locked(id); + if (ctx->uninstalling || (reset && ctx->resetting)) { + qemu_rec_mutex_unlock(&plugin.lock); + return; + } + ctx->resetting = reset; + ctx->uninstalling = !reset; + qemu_rec_mutex_unlock(&plugin.lock); + + data = g_new(struct qemu_plugin_reset_data, 1); + data->ctx = ctx; + data->cb = cb; + data->reset = reset; + /* + * Only flush the code cache if the vCPUs have been created. If so, + * current_cpu must be non-NULL. + */ + if (current_cpu) { + async_safe_run_on_cpu(current_cpu, plugin_flush_destroy, + RUN_ON_CPU_HOST_PTR(data)); + } else { + /* + * If current_cpu isn't set, then we don't have yet any vCPU threads + * and we therefore can remove the callbacks synchronously. + */ + plugin_reset_destroy(data); + } +} diff --git a/plugins/plugin.h b/plugins/plugin.h new file mode 100644 index 00000000000..641f006dd76 --- /dev/null +++ b/plugins/plugin.h @@ -0,0 +1,95 @@ +/* + * Plugin Shared Internal Functions + * + * Copyright (C) 2019, Linaro + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef _PLUGIN_INTERNAL_H_ +#define _PLUGIN_INTERNAL_H_ + +/* global state */ +struct qemu_plugin_state { + QTAILQ_HEAD(, qemu_plugin_ctx) ctxs; + QLIST_HEAD(, qemu_plugin_cb) cb_lists[QEMU_PLUGIN_EV_MAX]; + /* + * Use the HT as a hash map by inserting k == v, which saves memory as + * documented by GLib. The parent struct is obtained with container_of(). + */ + GHashTable *id_ht; + /* + * Use the HT as a hash map. Note that we could use a list here, + * but with the HT we avoid adding a field to CPUState. + */ + GHashTable *cpu_ht; + DECLARE_BITMAP(mask, QEMU_PLUGIN_EV_MAX); + /* + * @lock protects the struct as well as ctx->uninstalling. + * The lock must be acquired by all API ops. + * The lock is recursive, which greatly simplifies things, e.g. + * callback registration from qemu_plugin_vcpu_for_each(). + */ + QemuRecMutex lock; + /* + * HT of callbacks invoked from helpers. All entries are freed when + * the code cache is flushed. + */ + struct qht dyn_cb_arr_ht; +}; + + +struct qemu_plugin_ctx { + void *handle; /* dlopen */ + qemu_plugin_id_t id; + struct qemu_plugin_cb *callbacks[QEMU_PLUGIN_EV_MAX]; + QTAILQ_ENTRY(qemu_plugin_ctx) entry; + /* + * keep a reference to @desc until uninstall, so that plugins do not have + * to strdup plugin args. + */ + struct qemu_plugin_desc *desc; + bool installing; + bool uninstalling; + bool resetting; +}; + +struct qemu_plugin_ctx *plugin_id_to_ctx_locked(qemu_plugin_id_t id); + +void plugin_register_inline_op(GArray **arr, + enum qemu_plugin_mem_rw rw, + enum qemu_plugin_op op, void *ptr, + uint64_t imm); + +void plugin_reset_uninstall(qemu_plugin_id_t id, + qemu_plugin_simple_cb_t cb, + bool reset); + +void plugin_register_cb(qemu_plugin_id_t id, enum qemu_plugin_event ev, + void *func); + +void plugin_unregister_cb__locked(struct qemu_plugin_ctx *ctx, + enum qemu_plugin_event ev); + +void +plugin_register_cb_udata(qemu_plugin_id_t id, enum qemu_plugin_event ev, + void *func, void *udata); + +void +plugin_register_dyn_cb__udata(GArray **arr, + qemu_plugin_vcpu_udata_cb_t cb, + enum qemu_plugin_cb_flags flags, void *udata); + + +void plugin_register_vcpu_mem_cb(GArray **arr, + void *cb, + enum qemu_plugin_cb_flags flags, + enum qemu_plugin_mem_rw rw, + void *udata); + +void exec_inline_op(struct qemu_plugin_dyn_cb *cb); + +#endif /* _PLUGIN_INTERNAL_H_ */ From patchwork Wed Jul 31 16:06:40 2019 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: 11068627 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DA9D1174A for ; Wed, 31 Jul 2019 16:17:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C64351FE8D for ; Wed, 31 Jul 2019 16:17:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BAA821FFE4; Wed, 31 Jul 2019 16:17:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0E2A71FFCD for ; Wed, 31 Jul 2019 16:17:07 +0000 (UTC) Received: from localhost ([::1]:42452 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrHm-000161-CY for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:17:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40380) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsr8h-000285-I7 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsr8f-0000l9-58 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:43 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:53438) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsr8e-0000hJ-BR for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:40 -0400 Received: by mail-wm1-x341.google.com with SMTP id x15so61446591wmj.3 for ; Wed, 31 Jul 2019 09:07:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Pb+n1pLkj8AhZKqjkxNnDL9/hWK9uOwVyl2qXfcl7wU=; b=XIztQcaB6e4IgC5zUg34kZo9QxfoRF1b9u4s7XH2WcPrWds2uZPwB1mH2wnvGCUrpG j3aI+5xraMnBz5zsYggK9XFel73hUEzjd0YllxUknijjDuxvGAxKZhIz2Y5dhfxbRU3u HzaKlp8rBWG1D7O/n7tMdvHF/ofBSde3ZzRV8Z6vmJeEPRosimrHp1zBsz518I6HwvQo tgRywy4QHhDGppLvjpkn1t1EQ2J7vrAuporeyD6d+VHWU17L/YBvPWebv8O4TG5ghiAC J6e4z3WcKs69QzaXdibzOO+Aen0nK8ogLOPwyKd4+Uf3qXJYnlz2i3y/Niuqw+dIScEt jskQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Pb+n1pLkj8AhZKqjkxNnDL9/hWK9uOwVyl2qXfcl7wU=; b=eka02mJrQFLQ1YpbpyGDMnBn3PX/l5qO8WaY0n5L0oteNIbawlD1yWJV8F4s1a0fhX cJ9vrG6HxT/BfYvHsQmqXi7ImQuBymmhKKl7EKztwFssM9xrEyGrLzzMJqgcFluGmYKQ QWBOsZu/n0x+a6tTIJMviNma8+2mEMrYj6yjc17LP9QLZgkdbYjPNVXQImSmFOaCd6ur db0K3dj/4W/iEby7iwgFMHXdymZDmDpsvjwJow7AEi35OSnEckPpN/HJJbyEH74MtZo1 0/UUX8nwfIiJT+bauLnW5xK89LlvHXZpOu8VOu6e2y0Wq9kkwBOihuAdaErmbEWCeWyX Q93A== X-Gm-Message-State: APjAAAVgHRcDpFLWwLm2fAEfF1jrCMDJsZeV3EDMucBCx2OmuRUzZ+Tq jMfn1MIrvenONo4yg/yJr+n5XQ== X-Google-Smtp-Source: APXvYqxI+X30qJ1Xu7RiZ6SBrqxBl1Be3WeRHwQZ3hcPAc8eYZmbcxTWAu4XaQw6cXKv0GnQcBo93A== X-Received: by 2002:a1c:e90d:: with SMTP id q13mr111014849wmc.89.1564589251509; Wed, 31 Jul 2019 09:07:31 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id p10sm2143420wmk.2.2019.07.31.09.07.24 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:07:28 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id D0ABE1FF9E; Wed, 31 Jul 2019 17:07:20 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:40 +0100 Message-Id: <20190731160719.11396-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 Subject: [Qemu-devel] [PATCH v4 15/54] plugin: add implementation of the api X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bobby.prani@gmail.com, cota@braap.org, =?utf-8?q?Alex_Benn=C3=A9e?= , aaron@os.amperecomputing.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP [AJB: split from the core code commit] Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v4 - add qemu_plugin_ram_addr_from_host - remove _haddr api calls --- plugins/Makefile.objs | 1 + plugins/api.c | 299 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 300 insertions(+) create mode 100644 plugins/api.c diff --git a/plugins/Makefile.objs b/plugins/Makefile.objs index 58940335bca..95baabf3d2f 100644 --- a/plugins/Makefile.objs +++ b/plugins/Makefile.objs @@ -4,3 +4,4 @@ obj-y += loader.o obj-y += core.o +obj-y += api.o diff --git a/plugins/api.c b/plugins/api.c new file mode 100644 index 00000000000..586bb8789f1 --- /dev/null +++ b/plugins/api.c @@ -0,0 +1,299 @@ +/* + * QEMU Plugin API + * + * This provides the API that is available to the plugins to interact + * with QEMU. We have to be careful not to expose internal details of + * how QEMU works so we abstract out things like translation and + * instructions to anonymous data types: + * + * qemu_plugin_tb + * qemu_plugin_insn + * + * Which can then be passed back into the API to do additional things. + * As such all the public functions in here are exported in + * qemu-plugin.h. + * + * The general life-cycle of a plugin is: + * + * - plugin is loaded, public qemu_plugin_install called + * - the install func registers callbacks for events + * - usually an atexit_cb is registered to dump info at the end + * - when a registered event occurs the plugin is called + * - some events pass additional info + * - during translation the plugin can decide to instrument any + * instruction + * - when QEMU exits all the registered atexit callbacks are called + * + * Copyright (C) 2017, Emilio G. Cota + * Copyright (C) 2019, Linaro + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + */ + +#include "qemu/osdep.h" +#include "qemu/plugin.h" +#include "cpu.h" +#include "sysemu/sysemu.h" +#include "tcg/tcg.h" +#include "trace/mem-internal.h" /* mem_info macros */ +#include "plugin.h" +#ifndef CONFIG_USER_ONLY +#include "hw/boards.h" +#endif + +/* Uninstall and Reset handlers */ + +void qemu_plugin_uninstall(qemu_plugin_id_t id, qemu_plugin_simple_cb_t cb) +{ + plugin_reset_uninstall(id, cb, false); +} + +void qemu_plugin_reset(qemu_plugin_id_t id, qemu_plugin_simple_cb_t cb) +{ + plugin_reset_uninstall(id, cb, true); +} + +/* + * Plugin Register Functions + * + * This allows the plugin to register callbacks for various events + * during the translation. + */ + +void qemu_plugin_register_vcpu_init_cb(qemu_plugin_id_t id, + qemu_plugin_vcpu_simple_cb_t cb) +{ + plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_INIT, cb); +} + +void qemu_plugin_register_vcpu_exit_cb(qemu_plugin_id_t id, + qemu_plugin_vcpu_simple_cb_t cb) +{ + plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_EXIT, cb); +} + +void qemu_plugin_register_vcpu_tb_exec_cb(struct qemu_plugin_tb *tb, + qemu_plugin_vcpu_udata_cb_t cb, + enum qemu_plugin_cb_flags flags, + void *udata) +{ + plugin_register_dyn_cb__udata(&tb->cbs[PLUGIN_CB_REGULAR], + cb, flags, udata); +} + +void qemu_plugin_register_vcpu_tb_exec_inline(struct qemu_plugin_tb *tb, + enum qemu_plugin_op op, + void *ptr, uint64_t imm) +{ + plugin_register_inline_op(&tb->cbs[PLUGIN_CB_INLINE], 0, op, ptr, imm); +} + +void qemu_plugin_register_vcpu_insn_exec_cb(struct qemu_plugin_insn *insn, + qemu_plugin_vcpu_udata_cb_t cb, + enum qemu_plugin_cb_flags flags, + void *udata) +{ + plugin_register_dyn_cb__udata(&insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_REGULAR], + cb, flags, udata); +} + +void qemu_plugin_register_vcpu_insn_exec_inline(struct qemu_plugin_insn *insn, + enum qemu_plugin_op op, + void *ptr, uint64_t imm) +{ + plugin_register_inline_op(&insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_INLINE], + 0, op, ptr, imm); +} + + + +void qemu_plugin_register_vcpu_mem_cb(struct qemu_plugin_insn *insn, + qemu_plugin_vcpu_mem_cb_t cb, + enum qemu_plugin_cb_flags flags, + enum qemu_plugin_mem_rw rw, + void *udata) +{ + plugin_register_vcpu_mem_cb(&insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_REGULAR], + cb, flags, rw, udata); +} + +void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, + enum qemu_plugin_mem_rw rw, + enum qemu_plugin_op op, void *ptr, + uint64_t imm) +{ + plugin_register_inline_op(&insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_INLINE], + rw, op, ptr, imm); +} + +void qemu_plugin_register_vcpu_tb_trans_cb(qemu_plugin_id_t id, + qemu_plugin_vcpu_tb_trans_cb_t cb) +{ + plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_TB_TRANS, cb); +} + +void qemu_plugin_register_vcpu_syscall_cb(qemu_plugin_id_t id, + qemu_plugin_vcpu_syscall_cb_t cb) +{ + plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_SYSCALL, cb); +} + +void +qemu_plugin_register_vcpu_syscall_ret_cb(qemu_plugin_id_t id, + qemu_plugin_vcpu_syscall_ret_cb_t cb) +{ + plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_SYSCALL_RET, cb); +} + +/* + * Plugin Queries + * + * These are queries that the plugin can make to gauge information + * from our opaque data types. We do not want to leak internal details + * here just information useful to the plugin. + */ + +/* + * Translation block information: + * + * A plugin can query the virtual address of the start of the block + * and the number of instructions in it. It can also get access to + * each translated instruction. + */ + +size_t qemu_plugin_tb_n_insns(const struct qemu_plugin_tb *tb) +{ + return tb->n; +} + +uint64_t qemu_plugin_tb_vaddr(const struct qemu_plugin_tb *tb) +{ + return tb->vaddr; +} + +struct qemu_plugin_insn * +qemu_plugin_tb_get_insn(const struct qemu_plugin_tb *tb, size_t idx) +{ + if (unlikely(idx >= tb->n)) { + return NULL; + } + return g_ptr_array_index(tb->insns, idx); +} + +/* + * Instruction information + * + * These queries allow the plugin to retrieve information about each + * instruction being translated. + */ + +const void *qemu_plugin_insn_data(const struct qemu_plugin_insn *insn) +{ + return insn->data->data; +} + +size_t qemu_plugin_insn_size(const struct qemu_plugin_insn *insn) +{ + return insn->data->len; +} + +uint64_t qemu_plugin_insn_vaddr(const struct qemu_plugin_insn *insn) +{ + return insn->vaddr; +} + +void *qemu_plugin_insn_haddr(const struct qemu_plugin_insn *insn) +{ + return insn->haddr; +} + +/* + * The memory queries allow the plugin to query information about a + * memory access. + */ + +unsigned qemu_plugin_mem_size_shift(qemu_plugin_meminfo_t info) +{ + return info & TRACE_MEM_SZ_SHIFT_MASK; +} + +bool qemu_plugin_mem_is_sign_extended(qemu_plugin_meminfo_t info) +{ + return !!(info & TRACE_MEM_SE); +} + +bool qemu_plugin_mem_is_big_endian(qemu_plugin_meminfo_t info) +{ + return !!(info & TRACE_MEM_BE); +} + +bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info) +{ + return !!(info & TRACE_MEM_ST); +} + +/* + * Virtual Memory queries + */ + +struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info, + uint64_t vaddr) +{ + return NULL; +} + +bool qemu_plugin_hwaddr_is_io(struct qemu_plugin_hwaddr *hwaddr) +{ + return false; +} + +uint64_t qemu_plugin_hwaddr_to_raddr(const struct qemu_plugin_hwaddr *haddr) +{ +#if 0 /* XXX FIXME should be SOFTMMU */ + ram_addr_t ram_addr; + + g_assert(haddr); + ram_addr = qemu_ram_addr_from_host(haddr); + if (ram_addr == RAM_ADDR_INVALID) { + error_report("Bad ram pointer %p", haddr); + abort(); + } + return ram_addr; +#else + return 0; +#endif +} + +/* + * Queries to the number and potential maximum number of vCPUs there + * will be. This helps the plugin dimension per-vcpu arrays. + */ + +#ifndef CONFIG_USER_ONLY +static MachineState * get_ms(void) +{ + return MACHINE(qdev_get_machine()); +} +#endif + +int qemu_plugin_n_vcpus(void) +{ +#ifdef CONFIG_USER_ONLY + return -1; +#else + return get_ms()->smp.cpus; +#endif +} + +int qemu_plugin_n_max_vcpus(void) +{ +#ifdef CONFIG_USER_ONLY + return -1; +#else + return get_ms()->smp.max_cpus; +#endif +} From patchwork Wed Jul 31 16:06:41 2019 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: 11068719 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 86E14912 for ; Wed, 31 Jul 2019 16:29:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D3482000A for ; Wed, 31 Jul 2019 16:29:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D386203B9; Wed, 31 Jul 2019 16:29:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0C05E2000A for ; Wed, 31 Jul 2019 16:29:54 +0000 (UTC) Received: from localhost ([::1]:42792 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrUA-0000DF-B1 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:29:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45222) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrPo-00052W-9P for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrPn-0000NZ-9R for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:24 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:32769) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrPn-0000N6-3G for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:23 -0400 Received: by mail-wr1-x443.google.com with SMTP id n9so70471426wru.0 for ; Wed, 31 Jul 2019 09:25:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SeHSnn6Q7MbUbj1wOiuXEk2fDQ1yqleXTuadw7oSvuI=; b=LNeoSnN6Kg+VGwYH8Z4RbpDn3H9/yFqSwzDxeJtve72ahZzm0iXMyXKgWAaR8+fkWH DmbSPVaBUmj3G3umtKXnbKOkZszfjqr0NjxxtyF1m+3EKl5AhM2VC2XC5+dv+l/U96SD UFOk1x5CBDu32Y9cmkb58bzynzAzP2jtdzgiStBZXC7DCfVIfr/2pFt+AIDRoNXVjgUq g2tQ0NMMO6yn2W4oSE8OXAnTl1dPN1VeL7yMCrMK96lyDfLgKWYTysNZMj6/XjmLm9jI vWRgcldwl9zb8QZmYE8L+GHy0PDCAFHZOrMDTTpuaL21/NP4b/2EcIYyPOMpwgLpVXGg HIPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SeHSnn6Q7MbUbj1wOiuXEk2fDQ1yqleXTuadw7oSvuI=; b=q4217IYDg0zpiSlarf9ZcRaNq0cXni3zMwKidYbZdVSyZFAY2TJgx/tFmUahQ+V8wr N3b4/nGzcMP6cY4tluA/Sh8Q/ADz68oGzff8OfRr0F0y/to0CkskUHWeq4UCUtSXGyUa XDlfKMgs4rEdmBuSp45ETRvlgflSqM3ezEus1sScqg2h8yOObMTCEMD5z/LQtu8b2C6o g3CTrrGH5ahzjkPsTPa4XkB/Orh9wHFEnUVUL8vzTY2uRuOJjPXCe2XdswE0gmFGY+UE Fmcd4gz1m+AjuiEumPDzOpGg5+MAZeSgnD5MJAoN1mm5mIqTcxuLpIkr0tk3cvNPhudi zt2w== X-Gm-Message-State: APjAAAXXmNqtqoRmdFudQYmUpPV4DEK5MwFwigTIwzoTvgJ2LQFRzpIo XjmmomUUNuFmpExXoHIVFaxmIg== X-Google-Smtp-Source: APXvYqyo24WJUOkbGrYkUhB1Rs2vPWdpsX9Vo/dmAgoeOdpFUJAVoawbuS28Fgh+ULuGWXgANjcs+w== X-Received: by 2002:adf:ef8d:: with SMTP id d13mr130688452wro.60.1564590322088; Wed, 31 Jul 2019 09:25:22 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id h16sm74107395wrv.88.2019.07.31.09.25.15 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:25:17 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id E5B591FF8F; Wed, 31 Jul 2019 17:07:20 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:41 +0100 Message-Id: <20190731160719.11396-17-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [PATCH v4 16/54] queue: add QTAILQ_REMOVE_SEVERAL X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bobby.prani@gmail.com, cota@braap.org, =?utf-8?q?Alex_Benn=C3=A9e?= , aaron@os.amperecomputing.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" This is faster than removing elements one by one. Will gain a user soon. Signed-off-by: Emilio G. Cota Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- include/qemu/queue.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/qemu/queue.h b/include/qemu/queue.h index 0379bd8fdbb..66e834dad11 100644 --- a/include/qemu/queue.h +++ b/include/qemu/queue.h @@ -422,6 +422,16 @@ union { \ (elm)->field.tqe_circ.tql_prev = NULL; \ } while (/*CONSTCOND*/0) +/* remove @left, @right and all elements in between from @head */ +#define QTAILQ_REMOVE_SEVERAL(head, left, right, field) do { \ + if (((right)->field.tqe_next) != NULL) \ + (right)->field.tqe_next->field.tqe_circ.tql_prev = \ + (left)->field.tqe_circ.tql_prev; \ + else \ + (head)->tqh_circ.tql_prev = (left)->field.tqe_circ.tql_prev; \ + (left)->field.tqe_circ.tql_prev->tql_next = (right)->field.tqe_next; \ + } while (/*CONSTCOND*/0) + #define QTAILQ_FOREACH(var, head, field) \ for ((var) = ((head)->tqh_first); \ (var); \ From patchwork Wed Jul 31 16:06:42 2019 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: 11068687 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9357E912 for ; Wed, 31 Jul 2019 16:26:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F325203B9 for ; Wed, 31 Jul 2019 16:26:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70DD620453; Wed, 31 Jul 2019 16:26:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0C9FC203B9 for ; Wed, 31 Jul 2019 16:26:09 +0000 (UTC) Received: from localhost ([::1]:42682 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrQW-0006Y6-D2 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:26:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45017) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrPg-0004jW-DD for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrPf-0000Fh-8f for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:16 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:43122) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrPf-0000Eo-2W for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:15 -0400 Received: by mail-wr1-x442.google.com with SMTP id p13so70341376wru.10 for ; Wed, 31 Jul 2019 09:25:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xUIrrQym9hhHiF/ew6BTz6jTay6S+r9Vm5o3Xaev8Hs=; b=pe5a9RDdmLDJXrO4vomLHcNnwWulzPfhQIU+Vx6E0POxF7lnvb/Ou387A0TG+PVU4+ DRj0bfJpQ71cW6V8rK0XPJOB0cKb7oLvEw8MXHQyACjIMVWbh/CMEXST0X7NIOmkTXZG ck59fQClGudA6f9TnBoQmZTutGPa7JTBQ4ajP1sTlmOs0tjsSNVUglGoLdzDsXNIxWES 7nE2nYjL7CmrUvzyVq3pXIaQovyuxXy5Z3UT8b1AJ5ksZQxm+Cqc1M37yhU+TOaP+WV1 W3Gnhl6m8cdl0erAvKk2BLTF2uqNyBkGI1GeLaZZAdmiY3EvcXVyRMt5WIw6wFnNFIwb D46Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xUIrrQym9hhHiF/ew6BTz6jTay6S+r9Vm5o3Xaev8Hs=; b=s35Iwh72qXfFusBXE9lt6ZCIKWxyvC70fBZAZHfpnrPRWiPNgehzqqvBREi1MxPSPK JkAyQSeShMnfO0SQ5Ij9XPURAAv14TrhO6FQKtVnfRji4t1XXUNgUus8EnX7TFqgJ89i bRvD85M8i36jHoQXNSE29rBQL6zBP2GBhmJd+RDCiX4qH4PkEIK7h/BoGKB4HAv0D11b 2b7N9iL9TOCbPEFf+7Wq9q8u0yZ+TGNYojENngnTJx+Rs6he6jQWdGPHe4Wro+G3r+TE NzrNEvXOX7aaSt7sIjt4Q3+SLHGlP9nGayYzgjgOx0nEGC6T8iLVbEp4AVvlJB84mdit 53Jw== X-Gm-Message-State: APjAAAUw048b9gZXNZQpbKKNtNbz+b2uHokW8RqHGXC360tUAuX9oZD4 JeT5m87it7xvYJqncydlVRWmNg== X-Google-Smtp-Source: APXvYqwxlB6/H/TsA842jlg4Tulj9fgHDp0BVeGsZR2fhODR2vGXK4+p08LFLaZsFl3ZIc9GG9Ftrw== X-Received: by 2002:a5d:48cf:: with SMTP id p15mr87208181wrs.151.1564590313855; Wed, 31 Jul 2019 09:25:13 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id f70sm91237513wme.22.2019.07.31.09.25.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:25:12 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 0747E1FF9F; Wed, 31 Jul 2019 17:07:21 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:42 +0100 Message-Id: <20190731160719.11396-18-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PATCH v4 17/54] cputlb: document get_page_addr_code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Suggested-by: Alex Bennée Signed-off-by: Emilio G. Cota Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- accel/tcg/cputlb.c | 5 ----- include/exec/exec-all.h | 24 +++++++++++++++++++++--- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index bffdb251580..a01e04c5416 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1015,11 +1015,6 @@ static bool victim_tlb_hit(CPUArchState *env, size_t mmu_idx, size_t index, victim_tlb_hit(env, mmu_idx, index, offsetof(CPUTLBEntry, TY), \ (ADDR) & TARGET_PAGE_MASK) -/* NOTE: this function can trigger an exception */ -/* NOTE2: the returned address is not exactly the physical address: it - * is actually a ram_addr_t (in system mode; the user mode emulation - * version of this function returns a guest virtual address). - */ tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr) { uintptr_t mmu_idx = cpu_mmu_index(env, true); diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 16034ee651e..8b1c3d5b9db 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -480,7 +480,15 @@ void mmap_lock(void); void mmap_unlock(void); bool have_mmap_lock(void); -static inline tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong addr) +/** + * get_page_addr_code() - user-mode version + * @env: CPUArchState + * @addr: guest virtual address of guest code + * + * Returns @addr. + */ +static inline tb_page_addr_t get_page_addr_code(CPUArchState *env, + target_ulong addr) { return addr; } @@ -488,8 +496,18 @@ static inline tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong static inline void mmap_lock(void) {} static inline void mmap_unlock(void) {} -/* cputlb.c */ -tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong addr); +/** + * get_page_addr_code() - full-system version + * @env: CPUArchState + * @addr: guest virtual address of guest code + * + * If we cannot translate and execute from the entire RAM page, or if + * the region is not backed by RAM, returns -1. Otherwise, returns the + * ram_addr_t corresponding to the guest code at @addr. + * + * Note: this function can trigger an exception. + */ +tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr); void tlb_reset_dirty(CPUState *cpu, ram_addr_t start1, ram_addr_t length); void tlb_set_dirty(CPUState *cpu, target_ulong vaddr); From patchwork Wed Jul 31 16:06:43 2019 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: 11068667 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EC88613AC for ; Wed, 31 Jul 2019 16:22:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D85601FF41 for ; Wed, 31 Jul 2019 16:22:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC78020182; Wed, 31 Jul 2019 16:22:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5F2411FF41 for ; Wed, 31 Jul 2019 16:22:27 +0000 (UTC) Received: from localhost ([::1]:42560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrMw-000577-Lm for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:22:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42434) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrG8-0005yR-6z for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrG6-0004AM-9U for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:24 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:40592) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrG6-00048u-0f for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:22 -0400 Received: by mail-wr1-x442.google.com with SMTP id r1so70310838wrl.7 for ; Wed, 31 Jul 2019 09:15:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iNk53UNeX1NNAe+JEukLVQQBwgjFTkD+CslUIM9XJKY=; b=CriTWfqh07MbCdF67DxGcRMN6e7Kn9RZy1Mr3l+QOXfFRamsvzGk5h1DluzoWOJJTh Iipcr4LvGa61bd5NstOSXzLny956jJg8TCfj2Q3F1qVPZhh07YxJT4lij3CJMkHMUmfh VwOf0zZc5DPJghjCbEXz8kynKjzXoK4uSxk0vnqMGOI/3IjP/NkNgkToa5y791XNfGDa 7t4lWxMk5lgxeK3Z8k4/oliGCFB5SZ6z7oAfpFEXoJWuLRSn/qzFwghvqirRJLcQS0Lp bBjzJaaYOukVi0gkCcgKSYOccLz83aZVQdulmN77Tu/r9TnjEGufc+fL52djck+3XPpD A1tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iNk53UNeX1NNAe+JEukLVQQBwgjFTkD+CslUIM9XJKY=; b=TiHL/CsWtWroRq9YM8o6ZiWt0dsAZ6ejCS5TGtqcXOZOgus8o/4EHwA9ujHDnPCu82 lPHb0m3RVH4mr+csOl32wpLphuIzk1nSClsxIqQpcyjEWO6o/cdADc3SBAsR59qAeZjn C6eTya52kxxyepuM+eA8dUxSZTX5dJGXI/BDLLD3yX5+UkoS6vhRkckjmhmvw30mwheC pJTHLgR6I0NGlM5oN3ETITjx5uaPFC3jM1bvLZO2+4Y2lkvKVIWXG1y90VmPKvsyPPge HLtEnegtvRkIPDGpe7hONWy+KDtDEupWlsnNOzBEjDVXr63LefPZY5fNMv9l3BvcRbZb E35A== X-Gm-Message-State: APjAAAWaFI5m1aHInmr/wTupo/NpxzbBccAXJ+DoZGv3Fr5Y9AtchIa6 JYU8v0hjYl+ADAfd1US9iDwsnQ== X-Google-Smtp-Source: APXvYqwEL+HRYl+to53QdI3zzo4Ve/gImLgw1E+ljn4uESILli2/kXFGrrxyMKNO597m9WFExR241Q== X-Received: by 2002:a5d:680d:: with SMTP id w13mr137497767wru.141.1564589720861; Wed, 31 Jul 2019 09:15:20 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id w67sm89738808wma.24.2019.07.31.09.15.15 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:15:17 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 1C5C71FFA3; Wed, 31 Jul 2019 17:07:21 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:43 +0100 Message-Id: <20190731160719.11396-19-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PATCH v4 18/54] cputlb: introduce get_page_addr_code_hostp X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" This will be used by plugins to get the host address of instructions. Signed-off-by: Emilio G. Cota Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- accel/tcg/cputlb.c | 14 +++++++++++++- include/exec/exec-all.h | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index a01e04c5416..21ba71ea9dd 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1015,7 +1015,8 @@ static bool victim_tlb_hit(CPUArchState *env, size_t mmu_idx, size_t index, victim_tlb_hit(env, mmu_idx, index, offsetof(CPUTLBEntry, TY), \ (ADDR) & TARGET_PAGE_MASK) -tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr) +tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr, + void **hostp) { uintptr_t mmu_idx = cpu_mmu_index(env, true); uintptr_t index = tlb_index(env, mmu_idx, addr); @@ -1040,13 +1041,24 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr) * than a target page, so we must redo the MMU check every insn * - TLB_MMIO: region is not backed by RAM */ + if (hostp) { + *hostp = NULL; + } return -1; } p = (void *)((uintptr_t)addr + entry->addend); + if (hostp) { + *hostp = p; + } return qemu_ram_addr_from_host_nofail(p); } +tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr) +{ + return get_page_addr_code_hostp(env, addr, NULL); +} + /* Probe for whether the specified guest write access is permitted. * If it is not permitted then an exception will be taken in the same * way as if this were a real write access (and we will not return). diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 8b1c3d5b9db..90045e77c1f 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -21,6 +21,7 @@ #define EXEC_ALL_H #include "exec/tb-context.h" +#include "exec/cpu_ldst.h" #include "sysemu/cpus.h" /* allow to see translation results - the slowdown should be negligible, so we leave it */ @@ -492,6 +493,26 @@ static inline tb_page_addr_t get_page_addr_code(CPUArchState *env, { return addr; } + +/** + * get_page_addr_code_hostp() - user-mode version + * @env: CPUArchState + * @addr: guest virtual address of guest code + * + * Returns @addr. + * + * If @hostp is non-NULL, sets *@hostp to the host address where @addr's content + * is kept. + */ +static inline tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, + target_ulong addr, + void **hostp) +{ + if (hostp) { + *hostp = g2h(addr); + } + return addr; +} #else static inline void mmap_lock(void) {} static inline void mmap_unlock(void) {} @@ -509,6 +530,23 @@ static inline void mmap_unlock(void) {} */ tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr); +/** + * get_page_addr_code_hostp() - full-system version + * @env: CPUArchState + * @addr: guest virtual address of guest code + * + * See get_page_addr_code() (full-system version) for documentation on the + * return value. + * + * Sets *@hostp (when @hostp is non-NULL) as follows. + * If the return value is -1, sets *@hostp to NULL. Otherwise, sets *@hostp + * to the host address where @addr's content is kept. + * + * Note: this function can trigger an exception. + */ +tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr, + void **hostp); + void tlb_reset_dirty(CPUState *cpu, ram_addr_t start1, ram_addr_t length); void tlb_set_dirty(CPUState *cpu, target_ulong vaddr); From patchwork Wed Jul 31 16:06:44 2019 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: 11068665 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 36EF3912 for ; Wed, 31 Jul 2019 16:22:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 223541FF41 for ; Wed, 31 Jul 2019 16:22:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1620920415; Wed, 31 Jul 2019 16:22:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BBF9F20182 for ; Wed, 31 Jul 2019 16:22:01 +0000 (UTC) Received: from localhost ([::1]:42550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrMX-0003qi-5a for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:22:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42391) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrG7-0005up-E9 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrG6-00049v-1N for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:23 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:43030) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrG5-00048G-Or for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:21 -0400 Received: by mail-wr1-x444.google.com with SMTP id p13so70305491wru.10 for ; Wed, 31 Jul 2019 09:15:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lyP5gbjSZYFvC7g5QsskrcGKhwqRElrOHldYQXubnjI=; b=WkSMIXUxydI/KCqK6+zuYbzYnRKBjvosqzjsR/QrJpma8sM+g02VxrUKl0Edq5YsXm VYIs5nX9+kuxqNb4te6S/V5+p5eCdIepVmZM8MuN9Dr4hVrGRTFxRTqSUbeSCJ1f9C6e xMlbZ84BRxh7G871rBucEczQy8z8XZysSJaVowKsrCBsQQJG92hJrnzYB8VvB7qQcQ+2 qIqdyOzwHCCfMov7rBjvTYvy5oyWjmjV0Umdjmm6BPa9ZJllf43fvdd0piM/B03SA7bk puSvZ9MnAtMUYw+S18z/3ohnGs5GANNYt+U69zumnAdwbm8M9e2R7NKG60ryd0BM4d3R CJTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lyP5gbjSZYFvC7g5QsskrcGKhwqRElrOHldYQXubnjI=; b=jgS16WOq83br59RIpKY303kbs5HpeFh0VRQncPSKjsYzEN6H6O1c1+Uxg648zpO28R EC5eaHSbHe/v7WOXffy/RgYJ6SKKdbXEFz9HXRKyywIe3LgiLnbf5Gn8pZ8HKzNtM9R9 j8kGr+08KalHrpkSUj/YEezn4BdjJ9G+eF7rpHa0oVaXKuK6z9ZT1sTPO6f1eM0T+cLT C4UDVAUsmR49/l47QSn8Pwl8kBcv91Ze+Y5P/kWJtP+wrxPPBPrY5gkoC08REkUO9jqR MTwoSHOUlSvN4z8S+C7NTDI+TaQBDjbojhEMA9uXUcSbC2ohKx3uvsw7e/nImXpWMBHC +VlA== X-Gm-Message-State: APjAAAVs8J0nFsM4P4mkmooZIuFLR9ENqQxpO9ElzxxB1Fj9roEa4NXB Kbqkx25j80WIND8GNszkA+Q+Ig== X-Google-Smtp-Source: APXvYqxAOPzse0KuhGxk5NEObK5X+GhyP5bP3dn6jrVgfUAiHWV87gxjiRge4GXi7vtMu1/21HVKig== X-Received: by 2002:adf:f40b:: with SMTP id g11mr66901499wro.81.1564589718677; Wed, 31 Jul 2019 09:15:18 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id g11sm66774709wrq.92.2019.07.31.09.15.14 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:15:15 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 3241A1FFA5; Wed, 31 Jul 2019 17:07:21 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:44 +0100 Message-Id: <20190731160719.11396-20-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH v4 19/54] tcg: add tcg_gen_st_ptr X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , aaron@os.amperecomputing.com, cota@braap.org, bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Will gain a user soon. Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- tcg/tcg-op.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tcg/tcg-op.h b/tcg/tcg-op.h index 2d4dd5cd7de..698f3111eb2 100644 --- a/tcg/tcg-op.h +++ b/tcg/tcg-op.h @@ -1249,6 +1249,11 @@ static inline void tcg_gen_ld_ptr(TCGv_ptr r, TCGv_ptr a, intptr_t o) glue(tcg_gen_ld_,PTR)((NAT)r, a, o); } +static inline void tcg_gen_st_ptr(TCGv_ptr r, TCGv_ptr a, intptr_t o) +{ + glue(tcg_gen_st_, PTR)((NAT)r, a, o); +} + static inline void tcg_gen_discard_ptr(TCGv_ptr a) { glue(tcg_gen_discard_,PTR)((NAT)a); From patchwork Wed Jul 31 16:06:45 2019 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: 11068683 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F2E513AC for ; Wed, 31 Jul 2019 16:25:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4597520182 for ; Wed, 31 Jul 2019 16:25:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39452201B1; Wed, 31 Jul 2019 16:25:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 25D3D20182 for ; Wed, 31 Jul 2019 16:25:08 +0000 (UTC) Received: from localhost ([::1]:42640 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrPX-0004Kf-8F for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:25:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42514) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrGB-00069g-8X for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrG5-00049J-Nd for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:27 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]:36180) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrG1-00046W-Ly for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:19 -0400 Received: by mail-wr1-x436.google.com with SMTP id n4so70412883wrs.3 for ; Wed, 31 Jul 2019 09:15:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JIhEq/P0QyzB3dXCXr89K5QpW3hW2ZoC/7R/nN0YXsM=; b=O4sLsoeEu8oqAgVLF7WHcfLYpjOvCcbzYMN5yZEyfp7loKmdQ+S2Loz2QSD2f/hMNV HMLH6EmK9/dREQk06cF87jKUiweG5k0Hwz+XlXQBRzTHri2/zQcua9dzndEEpOCEYFWK CN77Jq3o9EYAT6ar1Ug8vsOFAlVDQ/9xQY+xIqPdedoY5t9QfY0wh3IR5PE2ARVC/ONz qzkGj7yAOPkml81PiCKoL5BzlrYq7pJOIQpMzrQE5ZK/mWI1O/1YosdIFaVsxPbNjl+M 9ez3u6EAFiiko0oaoeOs8ZLCzTQzR++hHEfLSRHEsPUqqhXAsGyDv+FL31sOrCn5lG/+ MnyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JIhEq/P0QyzB3dXCXr89K5QpW3hW2ZoC/7R/nN0YXsM=; b=H4QLfohhVZb3Unt/m4JE3B3oNVUhKmIw+cZSHt9Talo+mTAT6IJyXeZgOR14Xf15c/ TvOIMJn46afLbEneZQFBa+94WzzXn/08MzXmX4cob54QEVMpeBLHmrHzSLBEbRyb8Gqk tZCBl4ByaUiZAcrAvXcHm2SwHRbsLtOLgle3b8r50EEBg9J4JquQH+Nt9v/Dgylma5g0 PcSMK1ef+T8+oGp2QskbonYHubmCpzUrIFZDauoWbh+S/0Gzn0Dv9x3gIw4aG0Ohk/n0 7kn0srIOczKs0FJumGwnn8GDS2/DjSPn+IFL/baNcLDrbG/8B5pGLjPjnPuppNq83xoj WSfg== X-Gm-Message-State: APjAAAURnS9eAB+LywDkE3UIZfLMmBQV9VhaGz5adXvZJkuU/ipOxRJ9 BAlTEcsrX70s7hRD3hZRNdQOxA== X-Google-Smtp-Source: APXvYqwexhBgJGpnDVJAPqquD3i4mm1WDHrc2GZOiPU3Y0DoxydroY5/xTqEMesX9rigwzeIACoe7w== X-Received: by 2002:a5d:5152:: with SMTP id u18mr138564973wrt.9.1564589715760; Wed, 31 Jul 2019 09:15:15 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id p14sm56289062wrx.17.2019.07.31.09.15.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:15:13 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 5B2991FFA6; Wed, 31 Jul 2019 17:07:21 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:45 +0100 Message-Id: <20190731160719.11396-21-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::436 Subject: [Qemu-devel] [PATCH v4 20/54] plugin-gen: add module for TCG-related code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" We first inject empty instrumentation from translator_loop. After translation, we go through the plugins to see what they want to register for, filling in the empty instrumentation. If if turns out that some instrumentation remains unused, we remove it. This approach supports the following features: - Inlining TCG code for simple operations. Note that we do not export TCG ops to plugins. Instead, we give them a C API to insert inlined ops. So far we only support adding an immediate to a u64, e.g. to count events. - "Direct" callbacks. These are callbacks that do not go via a helper. Instead, the helper is defined at run-time, so that the plugin code is directly called from TCG. This makes direct callbacks as efficient as possible; they are therefore used for very frequent events, e.g. memory callbacks. - Passing the host address to memory callbacks. Most of this is implemented in a later patch though. - Instrumentation of memory accesses performed from helpers. See the corresponding comment, as well as a later patch. Signed-off-by: Emilio G. Cota [AJB: add alloc_tcg_plugin_context, use glib, rm hwaddr] Signed-off-by: Alex Bennée --- v3 - introduce alloc_tcg_plugin_context - allocate GPtrArray for tracking insns v4 - remove hwaddr variants of callbacks - pass full 32bit meminfo - remove now unused code - move plugin_gen_from into .c file --- accel/tcg/Makefile.objs | 1 + accel/tcg/plugin-gen.c | 977 ++++++++++++++++++++++++++++++++++++ accel/tcg/plugin-helpers.h | 5 + include/exec/helper-gen.h | 1 + include/exec/helper-proto.h | 1 + include/exec/helper-tcg.h | 1 + include/exec/plugin-gen.h | 57 +++ tcg/tcg-op.h | 11 + tcg/tcg-opc.h | 3 + tcg/tcg.c | 22 + tcg/tcg.h | 20 + 11 files changed, 1099 insertions(+) create mode 100644 accel/tcg/plugin-gen.c create mode 100644 accel/tcg/plugin-helpers.h create mode 100644 include/exec/plugin-gen.h diff --git a/accel/tcg/Makefile.objs b/accel/tcg/Makefile.objs index d381a02f347..a92f2c454b9 100644 --- a/accel/tcg/Makefile.objs +++ b/accel/tcg/Makefile.objs @@ -6,3 +6,4 @@ obj-y += translator.o obj-$(CONFIG_USER_ONLY) += user-exec.o obj-$(call lnot,$(CONFIG_SOFTMMU)) += user-exec-stub.o +obj-$(CONFIG_PLUGIN) += plugin-gen.o diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c new file mode 100644 index 00000000000..f93ee85d83a --- /dev/null +++ b/accel/tcg/plugin-gen.c @@ -0,0 +1,977 @@ +/* + * plugin-gen.c - TCG-related bits of plugin infrastructure + * + * Copyright (C) 2018, Emilio G. Cota + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + * We support instrumentation at an instruction granularity. That is, + * if a plugin wants to instrument the memory accesses performed by a + * particular instruction, it can just do that instead of instrumenting + * all memory accesses. Thus, in order to do this we first have to + * translate a TB, so that plugins can decide what/where to instrument. + * + * Injecting the desired instrumentation could be done with a second + * translation pass that combined the instrumentation requests, but that + * would be ugly and inefficient since we would decode the guest code twice. + * Instead, during TB translation we add "empty" instrumentation calls for all + * possible instrumentation events, and then once we collect the instrumentation + * requests from plugins, we either "fill in" those empty events or remove them + * if they have no requests. + * + * When "filling in" an event we first copy the empty callback's TCG ops. This + * might seem unnecessary, but it is done to support an arbitrary number + * of callbacks per event. Take for example a regular instruction callback. + * We first generate a callback to an empty helper function. Then, if two + * plugins register one callback each for this instruction, we make two copies + * of the TCG ops generated for the empty callback, substituting the function + * pointer that points to the empty helper function with the plugins' desired + * callback functions. After that we remove the empty callback's ops. + * + * Note that the location in TCGOp.args[] of the pointer to a helper function + * varies across different guest and host architectures. Instead of duplicating + * the logic that figures this out, we rely on the fact that the empty + * callbacks point to empty functions that are unique pointers in the program. + * Thus, to find the right location we just have to look for a match in + * TCGOp.args[]. This is the main reason why we first copy an empty callback's + * TCG ops and then fill them in; regardless of whether we have one or many + * callbacks for that event, the logic to add all of them is the same. + * + * When generating more than one callback per event, we make a small + * optimization to avoid generating redundant operations. For instance, for the + * second and all subsequent callbacks of an event, we do not need to reload the + * CPU's index into a TCG temp, since the first callback did it already. + */ +#include "qemu/osdep.h" +#include "cpu.h" +#include "tcg/tcg.h" +#include "tcg/tcg-op.h" +#include "trace/mem.h" +#include "exec/exec-all.h" +#include "exec/plugin-gen.h" +#include "exec/translator.h" + +#ifdef CONFIG_SOFTMMU +# define CONFIG_SOFTMMU_GATE 1 +#else +# define CONFIG_SOFTMMU_GATE 0 +#endif + +/* + * plugin_cb_start TCG op args[]: + * 0: enum plugin_gen_from + * 1: enum plugin_gen_cb + * 2: set to 1 for mem callback that is a write, 0 otherwise. + */ + +enum plugin_gen_from { + PLUGIN_GEN_FROM_TB, + PLUGIN_GEN_FROM_INSN, + PLUGIN_GEN_FROM_MEM, + PLUGIN_GEN_AFTER_INSN, + PLUGIN_GEN_N_FROMS, +}; + +enum plugin_gen_cb { + PLUGIN_GEN_CB_UDATA, + PLUGIN_GEN_CB_INLINE, + PLUGIN_GEN_CB_MEM, + PLUGIN_GEN_ENABLE_MEM_HELPER, + PLUGIN_GEN_DISABLE_MEM_HELPER, + PLUGIN_GEN_N_CBS, +}; + +/* + * 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_mem_cb)(unsigned int vcpu_index, + qemu_plugin_meminfo_t info, uint64_t vaddr, + void *userdata) +{ } + +static void do_gen_mem_cb(TCGv vaddr, uint32_t info) +{ + TCGv_i32 cpu_index = tcg_temp_new_i32(); + TCGv_i32 meminfo = tcg_const_i32(info); + TCGv_i64 vaddr64 = tcg_temp_new_i64(); + TCGv_ptr udata = tcg_const_ptr(NULL); + + tcg_gen_ld_i32(cpu_index, cpu_env, + -offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index)); + tcg_gen_extu_tl_i64(vaddr64, vaddr); + + gen_helper_plugin_vcpu_mem_cb(cpu_index, meminfo, vaddr64, udata); + + tcg_temp_free_ptr(udata); + tcg_temp_free_i64(vaddr64); + tcg_temp_free_i32(meminfo); + tcg_temp_free_i32(cpu_index); +} + +static void gen_empty_udata_cb(void) +{ + TCGv_i32 cpu_index = tcg_temp_new_i32(); + TCGv_ptr udata = tcg_const_ptr(NULL); /* will be overwritten later */ + + tcg_gen_ld_i32(cpu_index, cpu_env, + -offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index)); + gen_helper_plugin_vcpu_udata_cb(cpu_index, udata); + + tcg_temp_free_ptr(udata); + tcg_temp_free_i32(cpu_index); +} + +/* + * For now we only support addi_i64. + * When we support more ops, we can generate one empty inline cb for each. + */ +static void gen_empty_inline_cb(void) +{ + TCGv_i64 val = tcg_temp_new_i64(); + TCGv_ptr ptr = tcg_const_ptr(NULL); /* overwritten later */ + + tcg_gen_ld_i64(val, ptr, 0); + /* pass an immediate != 0 so that it doesn't get optimized away */ + tcg_gen_addi_i64(val, val, 0xdeadface); + tcg_gen_st_i64(val, ptr, 0); + tcg_temp_free_ptr(ptr); + tcg_temp_free_i64(val); +} + +static void gen_empty_mem_cb(TCGv addr, uint32_t info) +{ + do_gen_mem_cb(addr, info); +} + +/* + * Share the same function for enable/disable. When enabling, the NULL + * pointer will be overwritten later. + */ +static void gen_empty_mem_helper(void) +{ + TCGv_ptr ptr; + + ptr = tcg_const_ptr(NULL); + tcg_gen_st_ptr(ptr, cpu_env, offsetof(CPUState, plugin_mem_cbs)); + tcg_temp_free_ptr(ptr); +} + +static inline +void gen_plugin_cb_start(enum plugin_gen_from from, + enum plugin_gen_cb type, unsigned wr) +{ + TCGOp *op; + + tcg_gen_plugin_cb_start(from, type, wr); + op = tcg_last_op(); + QSIMPLEQ_INSERT_TAIL(&tcg_ctx->plugin_ops, op, plugin_link); +} + +static void gen_wrapped(enum plugin_gen_from from, + enum plugin_gen_cb type, void (*func)(void)) +{ + gen_plugin_cb_start(from, type, 0); + func(); + tcg_gen_plugin_cb_end(); +} + +static inline void plugin_gen_empty_callback(enum plugin_gen_from from) +{ + switch (from) { + case PLUGIN_GEN_AFTER_INSN: + gen_wrapped(from, PLUGIN_GEN_DISABLE_MEM_HELPER, + gen_empty_mem_helper); + break; + case PLUGIN_GEN_FROM_INSN: + /* + * Note: plugin_gen_inject() relies on ENABLE_MEM_HELPER being + * the first callback of an instruction + */ + gen_wrapped(from, PLUGIN_GEN_ENABLE_MEM_HELPER, + 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_INLINE, gen_empty_inline_cb); + break; + default: + g_assert_not_reached(); + } +} + +union mem_gen_fn { + void (*mem_fn)(TCGv, uint32_t); + void (*inline_fn)(void); +}; + +static void gen_mem_wrapped(enum plugin_gen_cb type, + const union mem_gen_fn *f, TCGv addr, + uint32_t info, bool is_mem) +{ + int wr = !!(info & TRACE_MEM_ST); + + gen_plugin_cb_start(PLUGIN_GEN_FROM_MEM, type, wr); + if (is_mem) { + f->mem_fn(addr, info); + } else { + f->inline_fn(); + } + tcg_gen_plugin_cb_end(); +} + +void plugin_gen_empty_mem_callback(TCGv addr, uint32_t info) +{ + union mem_gen_fn fn; + + fn.mem_fn = gen_empty_mem_cb; + gen_mem_wrapped(PLUGIN_GEN_CB_MEM, &fn, addr, info, true); + + fn.inline_fn = gen_empty_inline_cb; + gen_mem_wrapped(PLUGIN_GEN_CB_INLINE, &fn, 0, info, false); +} + +static TCGOp *find_op(TCGOp *op, TCGOpcode opc) +{ + while (op) { + if (op->opc == opc) { + return op; + } + op = QTAILQ_NEXT(op, link); + } + return NULL; +} + +static TCGOp *rm_ops_range(TCGOp *begin, TCGOp *end) +{ + TCGOp *ret = QTAILQ_NEXT(end, link); + + QTAILQ_REMOVE_SEVERAL(&tcg_ctx->ops, begin, end, link); + return ret; +} + +/* remove all ops until (and including) plugin_cb_end */ +static TCGOp *rm_ops(TCGOp *op) +{ + TCGOp *end_op = find_op(op, INDEX_op_plugin_cb_end); + + tcg_debug_assert(end_op); + return rm_ops_range(op, end_op); +} + +static TCGOp *copy_op_nocheck(TCGOp **begin_op, TCGOp *op) +{ + *begin_op = QTAILQ_NEXT(*begin_op, link); + tcg_debug_assert(*begin_op); + op = tcg_op_insert_after(tcg_ctx, op, (*begin_op)->opc); + memcpy(op->args, (*begin_op)->args, sizeof(op->args)); + return op; +} + +static TCGOp *copy_op(TCGOp **begin_op, TCGOp *op, TCGOpcode opc) +{ + op = copy_op_nocheck(begin_op, op); + tcg_debug_assert((*begin_op)->opc == opc); + return op; +} + +static TCGOp *copy_extu_i32_i64(TCGOp **begin_op, TCGOp *op) +{ + if (TCG_TARGET_REG_BITS == 32) { + /* mov_i32 */ + op = copy_op(begin_op, op, INDEX_op_mov_i32); + /* movi_i32 */ + op = copy_op(begin_op, op, INDEX_op_movi_i32); + } else { + /* extu_i32_i64 */ + op = copy_op(begin_op, op, INDEX_op_extu_i32_i64); + } + return op; +} + +static TCGOp *copy_mov_i64(TCGOp **begin_op, TCGOp *op) +{ + if (TCG_TARGET_REG_BITS == 32) { + /* 2x mov_i32 */ + op = copy_op(begin_op, op, INDEX_op_mov_i32); + op = copy_op(begin_op, op, INDEX_op_mov_i32); + } else { + /* mov_i64 */ + op = copy_op(begin_op, op, INDEX_op_mov_i64); + } + return op; +} + +static TCGOp *copy_movi_i64(TCGOp **begin_op, TCGOp *op, uint64_t v) +{ + if (TCG_TARGET_REG_BITS == 32) { + /* 2x movi_i32 */ + op = copy_op(begin_op, op, INDEX_op_movi_i32); + op->args[1] = v; + + op = copy_op(begin_op, op, INDEX_op_movi_i32); + op->args[1] = v >> 32; + } else { + /* movi_i64 */ + op = copy_op(begin_op, op, INDEX_op_movi_i64); + op->args[1] = v; + } + return op; +} + +static TCGOp *copy_const_ptr(TCGOp **begin_op, TCGOp *op, void *ptr) +{ + if (UINTPTR_MAX == UINT32_MAX) { + /* movi_i32 */ + op = copy_op(begin_op, op, INDEX_op_movi_i32); + op->args[1] = (uintptr_t)ptr; + } else { + /* movi_i64 */ + op = copy_movi_i64(begin_op, op, (uint64_t)(uintptr_t)ptr); + } + return op; +} + +static TCGOp *copy_const_i64(TCGOp **begin_op, TCGOp *op, uint64_t v) +{ + return copy_movi_i64(begin_op, op, v); +} + +static TCGOp *copy_extu_tl_i64(TCGOp **begin_op, TCGOp *op) +{ + if (TARGET_LONG_BITS == 32) { + /* extu_i32_i64 */ + op = copy_extu_i32_i64(begin_op, op); + } else { + /* mov_i64 */ + op = copy_mov_i64(begin_op, op); + } + return op; +} + +static TCGOp *copy_ld_i64(TCGOp **begin_op, TCGOp *op) +{ + if (TCG_TARGET_REG_BITS == 32) { + /* 2x ld_i32 */ + op = copy_op(begin_op, op, INDEX_op_ld_i32); + op = copy_op(begin_op, op, INDEX_op_ld_i32); + } else { + /* ld_i64 */ + op = copy_op(begin_op, op, INDEX_op_ld_i64); + } + return op; +} + +#if 0 /* XXX: no longer needed? */ +static TCGOp *copy_ld_ptr(TCGOp **begin_op, TCGOp *op) +{ + if (UINTPTR_MAX == UINT32_MAX) { + /* ld_i32 */ + op = copy_op(begin_op, op, INDEX_op_ld_i32); + } else { + /* ld_i64 */ + op = copy_ld_i64(begin_op, op); + } + return op; +} + +static TCGOp *skip_ld_i64(TCGOp *begin_op) +{ + TCGOp *op; + + if (TCG_TARGET_REG_BITS == 32) { + /* 2x ld_i32 */ + op = QTAILQ_NEXT(begin_op, link); + tcg_debug_assert(op->opc == INDEX_op_ld_i32); + op = QTAILQ_NEXT(op, link); + tcg_debug_assert(op->opc == INDEX_op_ld_i32); + } else { + /* ld_i64 */ + op = QTAILQ_NEXT(begin_op, link); + tcg_debug_assert(op->opc == INDEX_op_ld_i64); + } + return op; +} + +static TCGOp *skip_ld_ptr(TCGOp *begin_op) +{ + TCGOp *op; + + if (UINTPTR_MAX == UINT32_MAX) { + /* ld_i32 */ + op = QTAILQ_NEXT(begin_op, link); + tcg_debug_assert(op->opc == INDEX_op_ld_i32); + } else { + /* ld_i64 */ + op = skip_ld_i64(begin_op); + } + return op; +} +#endif + +static TCGOp *copy_st_i64(TCGOp **begin_op, TCGOp *op) +{ + if (TCG_TARGET_REG_BITS == 32) { + /* 2x st_i32 */ + op = copy_op(begin_op, op, INDEX_op_st_i32); + op = copy_op(begin_op, op, INDEX_op_st_i32); + } else { + /* st_i64 */ + op = copy_op(begin_op, op, INDEX_op_st_i64); + } + return op; +} + +static TCGOp *copy_add_i64(TCGOp **begin_op, TCGOp *op) +{ + if (TCG_TARGET_REG_BITS == 32) { + /* all 32-bit backends must implement add2_i32 */ + g_assert(TCG_TARGET_HAS_add2_i32); + op = copy_op(begin_op, op, INDEX_op_add2_i32); + } else { + op = copy_op(begin_op, op, INDEX_op_add_i64); + } + return op; +} + +static TCGOp *copy_st_ptr(TCGOp **begin_op, TCGOp *op) +{ + if (UINTPTR_MAX == UINT32_MAX) { + /* st_i32 */ + op = copy_op(begin_op, op, INDEX_op_st_i32); + } else { + /* st_i64 */ + op = copy_st_i64(begin_op, op); + } + return op; +} + +static TCGOp *copy_call(TCGOp **begin_op, TCGOp *op, void *empty_func, + void *func, unsigned tcg_flags, int *cb_idx) +{ + /* copy all ops until the call */ + do { + op = copy_op_nocheck(begin_op, op); + } while (op->opc != INDEX_op_call); + + /* fill in the op call */ + op->param1 = (*begin_op)->param1; + op->param2 = (*begin_op)->param2; + tcg_debug_assert(op->life == 0); + if (*cb_idx == -1) { + int i; + + /* + * Instead of working out the position of the callback in args[], just + * look for @empty_func, since it should be a unique pointer. + */ + for (i = 0; i < MAX_OPC_PARAM_ARGS; i++) { + if ((uintptr_t)(*begin_op)->args[i] == (uintptr_t)empty_func) { + *cb_idx = i; + break; + } + } + tcg_debug_assert(i < MAX_OPC_PARAM_ARGS); + } + op->args[*cb_idx] = (uintptr_t)func; + op->args[*cb_idx + 1] = tcg_flags; + + return op; +} + +static TCGOp *append_udata_cb(const struct qemu_plugin_dyn_cb *cb, + TCGOp *begin_op, TCGOp *op, int *cb_idx) +{ + /* const_ptr */ + op = copy_const_ptr(&begin_op, op, cb->userp); + + /* copy the ld_i32, but note that we only have to copy it once */ + begin_op = QTAILQ_NEXT(begin_op, link); + tcg_debug_assert(begin_op && begin_op->opc == INDEX_op_ld_i32); + if (*cb_idx == -1) { + op = tcg_op_insert_after(tcg_ctx, op, INDEX_op_ld_i32); + memcpy(op->args, begin_op->args, sizeof(op->args)); + } + + /* call */ + op = copy_call(&begin_op, op, HELPER(plugin_vcpu_udata_cb), + cb->f.vcpu_udata, cb->tcg_flags, cb_idx); + + return op; +} + +static TCGOp *append_inline_cb(const struct qemu_plugin_dyn_cb *cb, + TCGOp *begin_op, TCGOp *op, + int *unused) +{ + /* const_ptr */ + op = copy_const_ptr(&begin_op, op, cb->userp); + + /* ld_i64 */ + op = copy_ld_i64(&begin_op, op); + + /* const_i64 */ + op = copy_const_i64(&begin_op, op, cb->inline_insn.imm); + + /* add_i64 */ + op = copy_add_i64(&begin_op, op); + + /* st_i64 */ + op = copy_st_i64(&begin_op, op); + + return op; +} + +static TCGOp *append_mem_cb(const struct qemu_plugin_dyn_cb *cb, + TCGOp *begin_op, TCGOp *op, int *cb_idx) +{ + enum plugin_gen_cb type = begin_op->args[1]; + + tcg_debug_assert(type == PLUGIN_GEN_CB_MEM); + + /* const_i32 == movi_i32 ("info", so it remains as is) */ + op = copy_op(&begin_op, op, INDEX_op_movi_i32); + + /* const_ptr */ + op = copy_const_ptr(&begin_op, op, cb->userp); + + /* copy the ld_i32, but note that we only have to copy it once */ + begin_op = QTAILQ_NEXT(begin_op, link); + tcg_debug_assert(begin_op && begin_op->opc == INDEX_op_ld_i32); + if (*cb_idx == -1) { + op = tcg_op_insert_after(tcg_ctx, op, INDEX_op_ld_i32); + memcpy(op->args, begin_op->args, sizeof(op->args)); + } + + /* extu_tl_i64 */ + op = copy_extu_tl_i64(&begin_op, op); + + if (type == PLUGIN_GEN_CB_MEM) { + /* call */ + op = copy_call(&begin_op, op, HELPER(plugin_vcpu_mem_cb), + cb->f.vcpu_udata, cb->tcg_flags, cb_idx); + } + + return op; +} + +typedef TCGOp *(*inject_fn)(const struct qemu_plugin_dyn_cb *cb, + TCGOp *begin_op, TCGOp *op, int *intp); +typedef bool (*op_ok_fn)(const TCGOp *op, const struct qemu_plugin_dyn_cb *cb); + +static bool op_ok(const TCGOp *op, const struct qemu_plugin_dyn_cb *cb) +{ + return true; +} + +static bool op_rw(const TCGOp *op, const struct qemu_plugin_dyn_cb *cb) +{ + int w; + + w = op->args[2]; + return !!(cb->rw & (w + 1)); +} + +static inline +void inject_cb_type(const GArray *cbs, TCGOp *begin_op, inject_fn inject, + op_ok_fn ok) +{ + TCGOp *end_op; + TCGOp *op; + int cb_idx = -1; + int i; + + if (!cbs || cbs->len == 0) { + rm_ops(begin_op); + return; + } + + end_op = find_op(begin_op, INDEX_op_plugin_cb_end); + tcg_debug_assert(end_op); + + op = end_op; + for (i = 0; i < cbs->len; i++) { + struct qemu_plugin_dyn_cb *cb = + &g_array_index(cbs, struct qemu_plugin_dyn_cb, i); + + if (!ok(begin_op, cb)) { + continue; + } + op = inject(cb, begin_op, op, &cb_idx); + } + rm_ops_range(begin_op, end_op); +} + +static void +inject_udata_cb(const GArray *cbs, TCGOp *begin_op) +{ + inject_cb_type(cbs, begin_op, append_udata_cb, op_ok); +} + +static void +inject_inline_cb(const GArray *cbs, TCGOp *begin_op, op_ok_fn ok) +{ + inject_cb_type(cbs, begin_op, append_inline_cb, ok); +} + +static void +inject_mem_cb(const GArray *cbs, TCGOp *begin_op) +{ + inject_cb_type(cbs, begin_op, append_mem_cb, op_rw); +} + +/* we could change the ops in place, but we can reuse more code by copying */ +static void inject_mem_helper(TCGOp *begin_op, GArray *arr) +{ + TCGOp *orig_op = begin_op; + TCGOp *end_op; + TCGOp *op; + + end_op = find_op(begin_op, INDEX_op_plugin_cb_end); + tcg_debug_assert(end_op); + + /* const ptr */ + op = copy_const_ptr(&begin_op, end_op, arr); + + /* st_ptr */ + op = copy_st_ptr(&begin_op, op); + + rm_ops_range(orig_op, end_op); +} + +/* + * Tracking memory accesses performed from helpers requires extra work. + * If an instruction is emulated with helpers, we do two things: + * (1) copy the CB descriptors, and keep track of it so that they can be + * freed later on, and (2) point CPUState.plugin_mem_cbs to the descriptors, so + * that we can read them at run-time (i.e. when the helper executes). + * This run-time access is performed from qemu_plugin_vcpu_mem_cb. + * + * Note that plugin_gen_disable_mem_helpers undoes (2). Since it + * is possible that the code we generate after the instruction is + * dead, we also add checks before generating tb_exit etc. + */ +static void inject_mem_enable_helper(struct qemu_plugin_insn *plugin_insn, + TCGOp *begin_op) +{ + GArray *cbs[2]; + GArray *arr; + size_t n_cbs, i; + + cbs[0] = plugin_insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_REGULAR]; + cbs[1] = plugin_insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_INLINE]; + + n_cbs = 0; + for (i = 0; i < ARRAY_SIZE(cbs); i++) { + n_cbs += cbs[i]->len; + } + + plugin_insn->mem_helper = plugin_insn->calls_helpers && n_cbs; + if (likely(!plugin_insn->mem_helper)) { + rm_ops(begin_op); + return; + } + + arr = g_array_sized_new(false, false, + sizeof(struct qemu_plugin_dyn_cb), n_cbs); + + for (i = 0; i < ARRAY_SIZE(cbs); i++) { + g_array_append_vals(arr, cbs[i]->data, cbs[i]->len); + } + + qemu_plugin_add_dyn_cb_arr(arr); + inject_mem_helper(begin_op, arr); +} + +static void inject_mem_disable_helper(struct qemu_plugin_insn *plugin_insn, + TCGOp *begin_op) +{ + if (likely(!plugin_insn->mem_helper)) { + rm_ops(begin_op); + return; + } + inject_mem_helper(begin_op, NULL); +} + +/* called before finishing a TB with exit_tb, goto_tb or goto_ptr */ +void plugin_gen_disable_mem_helpers(void) +{ + TCGv_ptr ptr; + + if (likely(tcg_ctx->plugin_insn == NULL || + !tcg_ctx->plugin_insn->mem_helper)) { + return; + } + ptr = tcg_const_ptr(NULL); + tcg_gen_st_ptr(ptr, cpu_env, offsetof(CPUState, plugin_mem_cbs)); + tcg_temp_free_ptr(ptr); + tcg_ctx->plugin_insn->mem_helper = false; +} + +static void plugin_gen_tb_udata(const struct qemu_plugin_tb *ptb, + TCGOp *begin_op) +{ + inject_udata_cb(ptb->cbs[PLUGIN_CB_REGULAR], begin_op); +} + +static void plugin_gen_tb_inline(const struct qemu_plugin_tb *ptb, + TCGOp *begin_op) +{ + inject_inline_cb(ptb->cbs[PLUGIN_CB_INLINE], begin_op, op_ok); +} + +static void plugin_gen_insn_udata(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], begin_op); +} + +static void plugin_gen_insn_inline(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_inline_cb(insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_INLINE], + begin_op, op_ok); +} + +static void plugin_gen_mem_regular(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_mem_cb(insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_REGULAR], begin_op); +} + +static void plugin_gen_mem_inline(const struct qemu_plugin_tb *ptb, + TCGOp *begin_op, int insn_idx) +{ + const GArray *cbs; + struct qemu_plugin_insn *insn = g_ptr_array_index(ptb->insns, insn_idx); + + cbs = insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_INLINE]; + inject_inline_cb(cbs, begin_op, op_rw); +} + +static void plugin_gen_enable_mem_helper(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_mem_enable_helper(insn, begin_op); +} + +static void plugin_gen_disable_mem_helper(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_mem_disable_helper(insn, begin_op); +} + +static void plugin_inject_cb(const struct qemu_plugin_tb *ptb, TCGOp *begin_op, + int insn_idx) +{ + enum plugin_gen_from from = begin_op->args[0]; + enum plugin_gen_cb type = begin_op->args[1]; + + switch (from) { + case PLUGIN_GEN_FROM_TB: + switch (type) { + case PLUGIN_GEN_CB_UDATA: + plugin_gen_tb_udata(ptb, begin_op); + return; + case PLUGIN_GEN_CB_INLINE: + plugin_gen_tb_inline(ptb, begin_op); + return; + default: + g_assert_not_reached(); + } + case PLUGIN_GEN_FROM_INSN: + switch (type) { + case PLUGIN_GEN_CB_UDATA: + plugin_gen_insn_udata(ptb, begin_op, insn_idx); + return; + case PLUGIN_GEN_CB_INLINE: + plugin_gen_insn_inline(ptb, begin_op, insn_idx); + return; + case PLUGIN_GEN_ENABLE_MEM_HELPER: + plugin_gen_enable_mem_helper(ptb, begin_op, insn_idx); + return; + default: + g_assert_not_reached(); + } + case PLUGIN_GEN_FROM_MEM: + switch (type) { + case PLUGIN_GEN_CB_MEM: + plugin_gen_mem_regular(ptb, begin_op, insn_idx); + return; + case PLUGIN_GEN_CB_INLINE: + plugin_gen_mem_inline(ptb, begin_op, insn_idx); + return; + default: + g_assert_not_reached(); + } + case PLUGIN_GEN_AFTER_INSN: + switch (type) { + case PLUGIN_GEN_DISABLE_MEM_HELPER: + plugin_gen_disable_mem_helper(ptb, begin_op, insn_idx); + return; + default: + g_assert_not_reached(); + } + default: + g_assert_not_reached(); + } +} + +/* #define DEBUG_PLUGIN_GEN_OPS */ +static void pr_ops(void) +{ +#ifdef DEBUG_PLUGIN_GEN_OPS + TCGOp *op; + int i = 0; + + QTAILQ_FOREACH(op, &tcg_ctx->ops, link) { + const char *name = ""; + const char *type = ""; + + if (op->opc == INDEX_op_plugin_cb_start) { + switch (op->args[0]) { + case PLUGIN_GEN_FROM_TB: + name = "tb"; + break; + case PLUGIN_GEN_FROM_INSN: + name = "insn"; + break; + case PLUGIN_GEN_FROM_MEM: + name = "mem"; + break; + case PLUGIN_GEN_AFTER_INSN: + name = "after insn"; + break; + default: + break; + } + switch (op->args[1]) { + case PLUGIN_GEN_CB_UDATA: + type = "udata"; + break; + case PLUGIN_GEN_CB_INLINE: + type = "inline"; + break; + case PLUGIN_GEN_CB_MEM: + type = "mem"; + break; + case PLUGIN_GEN_ENABLE_MEM_HELPER: + type = "enable mem helper"; + break; + case PLUGIN_GEN_DISABLE_MEM_HELPER: + type = "disable mem helper"; + break; + default: + break; + } + } + printf("op[%2i]: %s %s %s\n", i, tcg_op_defs[op->opc].name, name, type); + i++; + } +#endif +} + +static void plugin_gen_inject(const struct qemu_plugin_tb *plugin_tb) +{ + TCGOp *op; + int insn_idx; + + pr_ops(); + insn_idx = -1; + QSIMPLEQ_FOREACH(op, &tcg_ctx->plugin_ops, plugin_link) { + enum plugin_gen_from from = op->args[0]; + enum plugin_gen_cb type = op->args[1]; + + tcg_debug_assert(op->opc == INDEX_op_plugin_cb_start); + /* ENABLE_MEM_HELPER is the first callback of an instruction */ + if (from == PLUGIN_GEN_FROM_INSN && + type == PLUGIN_GEN_ENABLE_MEM_HELPER) { + insn_idx++; + } + plugin_inject_cb(plugin_tb, op, insn_idx); + } + pr_ops(); +} + +bool plugin_gen_tb_start(CPUState *cpu, const TranslationBlock *tb) +{ + struct qemu_plugin_tb *ptb = tcg_ctx->plugin_tb; + bool ret = false; + + if (test_bit(QEMU_PLUGIN_EV_VCPU_TB_TRANS, cpu->plugin_mask)) { + ret = true; + + QSIMPLEQ_INIT(&tcg_ctx->plugin_ops); + ptb->vaddr = tb->pc; + ptb->vaddr2 = -1; + get_page_addr_code_hostp(cpu->env_ptr, tb->pc, &ptb->haddr1); + ptb->haddr2 = NULL; + + plugin_gen_empty_callback(PLUGIN_GEN_FROM_TB); + } + return ret; +} + +void plugin_gen_insn_start(CPUState *cpu, const DisasContextBase *db) +{ + struct qemu_plugin_tb *ptb = tcg_ctx->plugin_tb; + struct qemu_plugin_insn *pinsn; + + pinsn = qemu_plugin_tb_insn_get(ptb); + tcg_ctx->plugin_insn = pinsn; + pinsn->vaddr = db->pc_next; + plugin_gen_empty_callback(PLUGIN_GEN_FROM_INSN); + + /* + * Detect page crossing to get the new host address. + * Note that we skip this when haddr1 == NULL, e.g. when we're + * fetching instructions from a region not backed by RAM. + */ + if (likely(ptb->haddr1 != NULL && ptb->vaddr2 == -1) && + unlikely((db->pc_next & TARGET_PAGE_MASK) != + (db->pc_first & TARGET_PAGE_MASK))) { + get_page_addr_code_hostp(cpu->env_ptr, db->pc_next, + &ptb->haddr2); + ptb->vaddr2 = db->pc_next; + } + if (likely(ptb->vaddr2 == -1)) { + pinsn->haddr = ptb->haddr1 + pinsn->vaddr - ptb->vaddr; + } else { + pinsn->haddr = ptb->haddr2 + pinsn->vaddr - ptb->vaddr2; + } +} + +void plugin_gen_insn_end(void) +{ + plugin_gen_empty_callback(PLUGIN_GEN_AFTER_INSN); +} + +void plugin_gen_tb_end(CPUState *cpu) +{ + struct qemu_plugin_tb *ptb = tcg_ctx->plugin_tb; + int i; + + /* collect instrumentation requests */ + qemu_plugin_tb_trans_cb(cpu, ptb); + + /* inject the instrumentation at the appropriate places */ + plugin_gen_inject(ptb); + + /* clean up */ + for (i = 0; i < PLUGIN_N_CB_SUBTYPES; i++) { + if (ptb->cbs[i]) { + g_array_set_size(ptb->cbs[i], 0); + } + } + ptb->n = 0; + tcg_ctx->plugin_insn = NULL; +} diff --git a/accel/tcg/plugin-helpers.h b/accel/tcg/plugin-helpers.h new file mode 100644 index 00000000000..1916ee79206 --- /dev/null +++ b/accel/tcg/plugin-helpers.h @@ -0,0 +1,5 @@ +#ifdef CONFIG_PLUGIN +/* Note: no TCG flags because those are overwritten later */ +DEF_HELPER_2(plugin_vcpu_udata_cb, void, i32, ptr) +DEF_HELPER_4(plugin_vcpu_mem_cb, void, i32, i32, i64, ptr) +#endif diff --git a/include/exec/helper-gen.h b/include/exec/helper-gen.h index 22381a17088..236ff405243 100644 --- a/include/exec/helper-gen.h +++ b/include/exec/helper-gen.h @@ -70,6 +70,7 @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ #include "trace/generated-helpers.h" #include "trace/generated-helpers-wrappers.h" #include "tcg-runtime.h" +#include "plugin-helpers.h" #undef DEF_HELPER_FLAGS_0 #undef DEF_HELPER_FLAGS_1 diff --git a/include/exec/helper-proto.h b/include/exec/helper-proto.h index 74943edb13a..1c4ba9bc788 100644 --- a/include/exec/helper-proto.h +++ b/include/exec/helper-proto.h @@ -33,6 +33,7 @@ dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2), dh_ctype(t3), \ #include "helper.h" #include "trace/generated-helpers.h" #include "tcg-runtime.h" +#include "plugin-helpers.h" #undef DEF_HELPER_FLAGS_0 #undef DEF_HELPER_FLAGS_1 diff --git a/include/exec/helper-tcg.h b/include/exec/helper-tcg.h index 268e0f804be..573c2ce2e98 100644 --- a/include/exec/helper-tcg.h +++ b/include/exec/helper-tcg.h @@ -55,6 +55,7 @@ #include "helper.h" #include "trace/generated-helpers.h" #include "tcg-runtime.h" +#include "plugin-helpers.h" #undef str #undef DEF_HELPER_FLAGS_0 diff --git a/include/exec/plugin-gen.h b/include/exec/plugin-gen.h new file mode 100644 index 00000000000..de519883b16 --- /dev/null +++ b/include/exec/plugin-gen.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2017, Emilio G. Cota + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + * plugin-gen.h - TCG-dependent definitions for generating plugin code + * + * This header should be included only from plugin.c and C files that emit + * TCG code. + */ +#ifndef QEMU_PLUGIN_GEN_H +#define QEMU_PLUGIN_GEN_H + +#include "qemu/plugin.h" +#include "tcg/tcg.h" + +struct DisasContextBase; + +#ifdef CONFIG_PLUGIN + +bool plugin_gen_tb_start(CPUState *cpu, const TranslationBlock *tb); +void plugin_gen_tb_end(CPUState *cpu); +void plugin_gen_insn_start(CPUState *cpu, const struct DisasContextBase *db); +void plugin_gen_insn_end(void); + +void plugin_gen_disable_mem_helpers(void); +void plugin_gen_empty_mem_callback(TCGv addr, uint32_t info); + +#else /* !CONFIG_PLUGIN */ + +static inline +bool plugin_gen_tb_start(CPUState *cpu, const TranslationBlock *tb) +{ + return false; +} + +static inline +void plugin_gen_insn_start(CPUState *cpu, const struct DisasContextBase *db) +{ } + +static inline void plugin_gen_insn_end(void) +{ } + +static inline void plugin_gen_tb_end(CPUState *cpu) +{ } + +static inline void plugin_gen_disable_mem_helpers(void) +{ } + +static inline void plugin_gen_empty_mem_callback(TCGv addr, uint32_t info) +{ } + +#endif /* CONFIG_PLUGIN */ + +#endif /* QEMU_PLUGIN_GEN_H */ + diff --git a/tcg/tcg-op.h b/tcg/tcg-op.h index 698f3111eb2..edf12de1f31 100644 --- a/tcg/tcg-op.h +++ b/tcg/tcg-op.h @@ -833,6 +833,17 @@ void tcg_gen_goto_tb(unsigned idx); */ void tcg_gen_lookup_and_goto_ptr(void); +static inline void tcg_gen_plugin_cb_start(unsigned from, unsigned type, + unsigned wr) +{ + tcg_gen_op3(INDEX_op_plugin_cb_start, from, type, wr); +} + +static inline void tcg_gen_plugin_cb_end(void) +{ + tcg_emit_op(INDEX_op_plugin_cb_end); +} + #if TARGET_LONG_BITS == 32 #define tcg_temp_new() tcg_temp_new_i32() #define tcg_global_reg_new tcg_global_reg_new_i32 diff --git a/tcg/tcg-opc.h b/tcg/tcg-opc.h index 242d608e6db..9288a049468 100644 --- a/tcg/tcg-opc.h +++ b/tcg/tcg-opc.h @@ -198,6 +198,9 @@ DEF(goto_tb, 0, 0, 1, TCG_OPF_BB_EXIT | TCG_OPF_BB_END) DEF(goto_ptr, 0, 1, 0, TCG_OPF_BB_EXIT | TCG_OPF_BB_END | IMPL(TCG_TARGET_HAS_goto_ptr)) +DEF(plugin_cb_start, 0, 0, 3, TCG_OPF_NOT_PRESENT) +DEF(plugin_cb_end, 0, 0, 0, TCG_OPF_NOT_PRESENT) + DEF(qemu_ld_i32, 1, TLADDR_ARGS, 1, TCG_OPF_CALL_CLOBBER | TCG_OPF_SIDE_EFFECTS) DEF(qemu_st_i32, 0, TLADDR_ARGS + 1, 1, diff --git a/tcg/tcg.c b/tcg/tcg.c index be2c33c400c..516128dc21a 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -737,6 +737,15 @@ void tcg_region_init(void) #endif } +static void alloc_tcg_plugin_context(TCGContext *s) +{ +#ifdef CONFIG_PLUGIN + s->plugin_tb = g_new0(struct qemu_plugin_tb, 1); + s->plugin_tb->insns = + g_ptr_array_new_with_free_func(qemu_plugin_insn_cleanup_fn); +#endif +} + /* * All TCG threads except the parent (i.e. the one that called tcg_context_init * and registered the target's TCG globals) must register with this function @@ -781,6 +790,10 @@ void tcg_register_thread(void) g_assert(n < ms->smp.max_cpus); atomic_set(&tcg_ctxs[n], s); + if (n > 0) { + alloc_tcg_plugin_context(s); + } + tcg_ctx = s; qemu_mutex_lock(®ion.lock); err = tcg_region_initial_alloc__locked(tcg_ctx); @@ -977,6 +990,8 @@ void tcg_context_init(TCGContext *s) indirect_reg_alloc_order[i] = tcg_target_reg_alloc_order[i]; } + alloc_tcg_plugin_context(s); + tcg_ctx = s; /* * In user-mode we simply share the init context among threads, since we @@ -1682,6 +1697,13 @@ void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args) flags = info->flags; sizemask = info->sizemask; +#ifdef CONFIG_PLUGIN + /* detect non-plugin helpers */ + if (tcg_ctx->plugin_insn && unlikely(strncmp(info->name, "plugin_", 7))) { + tcg_ctx->plugin_insn->calls_helpers = true; + } +#endif + #if defined(__sparc__) && !defined(__arch64__) \ && !defined(CONFIG_TCG_INTERPRETER) /* We have 64-bit values in one register, but need to pass as two diff --git a/tcg/tcg.h b/tcg/tcg.h index b411e17a28f..2385e758e55 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -625,6 +625,9 @@ typedef struct TCGOp { /* Next and previous opcodes. */ QTAILQ_ENTRY(TCGOp) link; +#ifdef CONFIG_PLUGIN + QSIMPLEQ_ENTRY(TCGOp) plugin_link; +#endif /* Arguments for the opcode. */ TCGArg args[MAX_OPC_PARAM]; @@ -726,6 +729,23 @@ struct TCGContext { TCGLabel *exitreq_label; +#ifdef CONFIG_PLUGIN + /* + * We keep one plugin_tb struct per TCGContext. Note that on every TB + * translation we clear but do not free its contents; this way we + * avoid a lot of malloc/free churn, since after a few TB's it's + * unlikely that we'll need to allocate either more instructions or more + * space for instructions (for variable-instruction-length ISAs). + */ + struct qemu_plugin_tb *plugin_tb; + + /* descriptor of the instruction being translated */ + struct qemu_plugin_insn *plugin_insn; + + /* list to quickly access the injected ops */ + QSIMPLEQ_HEAD(, TCGOp) plugin_ops; +#endif + TCGTempSet free_temps[TCG_TYPE_COUNT * 2]; TCGTemp temps[TCG_MAX_TEMPS]; /* globals first, temps after */ From patchwork Wed Jul 31 16:06:46 2019 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: 11068745 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33634112C for ; Wed, 31 Jul 2019 16:33:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F480203B9 for ; Wed, 31 Jul 2019 16:33:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 139C4205A9; Wed, 31 Jul 2019 16:33:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B8480203B9 for ; Wed, 31 Jul 2019 16:33:39 +0000 (UTC) Received: from localhost ([::1]:42866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrXn-0006lP-5n for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:33:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45281) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrPr-0005Bd-1c for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrPq-0000Pr-3y for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:26 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]:35215) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrPp-0000P8-UI for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:26 -0400 Received: by mail-wr1-x436.google.com with SMTP id y4so70383353wrm.2 for ; Wed, 31 Jul 2019 09:25:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3EcRLt1hOeMs35DCT9AnFf1hI7OqAUwmCSb9V9Rrwzo=; b=AB2l6WKzxHgRFsZ5PZAJAcK/ibVegEzzDoCy3zEIF559/7rCnSqxUx3CjonlDv/CDa ISrqRCauJ+zBTlBLl1dk12lzJ4Xx/JgFL3bhgvUfKlMIWCFqI+YyT4u3533Sh/SXf33O tg5mfW8E1e/Fmb/z4RgUMj98lfnGaZc8F9m74Ie4sbNIEr9Sg37aIsvG5IXtPtnd80zR Y9yGKHnNVZ/2jg/hJIO7liddESi+m8W48s13fP6gHmhrJmdBV8B5H02i3/HPyGaBt9It oL2APUdiEqzSbD3SjtZVLK2yASZjvMD8AafV/JQT8Ux7/SHj4RyYNmqqG2a0iKblPcqk lBZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3EcRLt1hOeMs35DCT9AnFf1hI7OqAUwmCSb9V9Rrwzo=; b=UM4Vc3j1/ugPvXmL9W+/rDhUwTwhA2IrXwRv/OBKrCSqUkxC0YkRi5U1442NI5miZl x6Ao4NxSccb1QfxRE29LAvghy1J9B1btkpET6HK5QwuU3jWYF9aZKUtHj3uQW4MK2WlX l7ADMs3ev4dkoWNoV5EKsWkvv3vONJN9v/YiPJt8kBsvonYJqS2D9haP3IOO9Ql36DoH BInuRGc9uABhR9xf3PdpPk/uJbzCTDo8f0sadhtsztjuy+qD16UeOlXAZ5g65mWSLEgh n28TXBcbR8fHqHdHlJcGvMF8LTMDbNshe1U61ViBwJU23NNYc8U/jKbieQDsefOHu0vJ ji9w== X-Gm-Message-State: APjAAAWWXtxoLJUafRjf8fiknbzmjkBT+AjUoAILZ7UEp9TfSFxKELWv nQzUsCoozkoLMN+NO6yJzeXY5Q== X-Google-Smtp-Source: APXvYqyHNEn8K2uJNImDkMwQwHbJuE652ANIAoiFhmGUhmI1DteCEDwddkmLv5whIS49IQlDwGvfsg== X-Received: by 2002:adf:9ece:: with SMTP id b14mr85957473wrf.192.1564590324820; Wed, 31 Jul 2019 09:25:24 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id l17sm47513042wrr.94.2019.07.31.09.25.16 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:25:22 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 710331FFA9; Wed, 31 Jul 2019 17:07:21 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:46 +0100 Message-Id: <20190731160719.11396-22-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::436 Subject: [Qemu-devel] [PATCH v4 21/54] atomic_template: fix indentation in GEN_ATOMIC_HELPER X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Reviewed-by: Alex Bennée Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- accel/tcg/atomic_template.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accel/tcg/atomic_template.h b/accel/tcg/atomic_template.h index 313a4c7ed97..53899bbbc21 100644 --- a/accel/tcg/atomic_template.h +++ b/accel/tcg/atomic_template.h @@ -284,7 +284,7 @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, target_ulong addr, #define GEN_ATOMIC_HELPER(X) \ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr, \ - ABI_TYPE val EXTRA_ARGS) \ + ABI_TYPE val EXTRA_ARGS) \ { \ ATOMIC_MMU_DECLS; \ DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; \ From patchwork Wed Jul 31 16:06:47 2019 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: 11068775 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C230112C for ; Wed, 31 Jul 2019 16:45:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38C9022ADC for ; Wed, 31 Jul 2019 16:45:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B1BB27FB1; Wed, 31 Jul 2019 16:45:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5795028173 for ; Wed, 31 Jul 2019 16:45:54 +0000 (UTC) Received: from localhost ([::1]:43000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrjd-00036V-MF for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:45:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51221) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrj3-0001h6-R9 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:45:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrj2-0000r0-3G for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:45:17 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:44482) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrj1-0000oo-Rc for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:45:16 -0400 Received: by mail-wr1-x441.google.com with SMTP id p17so70418868wrf.11 for ; Wed, 31 Jul 2019 09:45:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eC3XCZD9HgCTHQjJiNXgLX49Tv5qbDgWg1bMsuBuPhU=; b=takOPE83F83DP8Y0uqs9thnZZcre+djfNLeM6bfUSMSbdyCxNipsb7VD0deUb21eaP LGvvLaGedKyqi5WzgrrzhEHvSe0hI5GGM/eU5G2DVGQh+LotyT6qwudN6oiAKkqlhbr2 bTk37aClqhEgt3Yj+53W/oxnUCf+M8Z6CIPr1YrxMg4lY/Tdb1S73WsUsXTqdyd9n1Rx NTgSejXfPm4/9b+DsXAecnwEDasOSsBEwTzvXVIXWNMMPgQM29gCDgJ/VbN6xzOPABtD GvUmwV/A13bjwGe5vs6pRctaXApYJAMPk93Y1nl2yXNEN3DjZfiU6BhTHeWpQUoeOqZN qZiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eC3XCZD9HgCTHQjJiNXgLX49Tv5qbDgWg1bMsuBuPhU=; b=FYZ3wCGkvB8PK0WuMQb43MvUVXFObDO6UPJress9LYs3QJoW8U86BDC+ImZRYD4zEn LUJLmJFQAF9UvVAet/Chx0CGf181A9dW4penbJYkR7X1T2mtsJG+zHSYjPZju3wE+dl1 2yqnSgiyfd4/NMIFaWvtlk98kK/XjIvYhIlTRqveU5JZT7Z+s1yVHjalupxGtDJKE0/V UUJBDglssYvuONi4hvNAJHOVpv8iJE0Do71UwKdxE3qAdKVLqKiQeezxxfD/PiMvy1zn GH5KGWsN1k8ixYVfIYv5YIHbwaEmtJJGfJf2hWq7SbeRr7Ux/sCYKk9QkMTdhTS6v4IK hdfQ== X-Gm-Message-State: APjAAAXZWPYS/YC2PTobz9blOCZPymaQfGYxSN9CkNbiF2ukAn/aj/+U 4eeYdY29fD+pgV50Kqnwd5DxcQ== X-Google-Smtp-Source: APXvYqwNOZNo2trd622Iwn5v+apzFJdp8vZI1sVeiAgni5KV9BHsJEdLirqBw3sE973y37t918s5+w== X-Received: by 2002:a5d:46d1:: with SMTP id g17mr81997425wrs.160.1564591513753; Wed, 31 Jul 2019 09:45:13 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id d10sm57499852wrx.34.2019.07.31.09.45.13 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:45:13 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 8B3441FFAA; Wed, 31 Jul 2019 17:07:21 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:47 +0100 Message-Id: <20190731160719.11396-23-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PATCH v4 22/54] atomic_template: add inline trace/plugin helpers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" In preparation for plugin support. Signed-off-by: Emilio G. Cota Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v4 - move common stuff to atomic_common.inc.c - fix ups for widened uint16_t info - drop haddr in helpers - fix wide lines --- accel/tcg/atomic_common.inc.c | 50 +++++++++++++++++++ accel/tcg/atomic_template.h | 93 +++++++++++++++++++++-------------- accel/tcg/cputlb.c | 2 + accel/tcg/user-exec.c | 2 + 4 files changed, 111 insertions(+), 36 deletions(-) create mode 100644 accel/tcg/atomic_common.inc.c diff --git a/accel/tcg/atomic_common.inc.c b/accel/tcg/atomic_common.inc.c new file mode 100644 index 00000000000..a86098fb2de --- /dev/null +++ b/accel/tcg/atomic_common.inc.c @@ -0,0 +1,50 @@ +/* + * Common Atomic Helper Functions + * + * This file should be included before the various instantiations of + * the atomic_template.h helpers. + * + * Copyright (c) 2019 Linaro + * Written by Alex Bennée + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +static inline +void atomic_trace_rmw_pre(CPUArchState *env, target_ulong addr, uint16_t info) +{ + CPUState *cpu = env_cpu(env); + + trace_guest_mem_before_exec(cpu, addr, info); + trace_guest_mem_before_exec(cpu, addr, info | TRACE_MEM_ST); +} + +static inline void +atomic_trace_rmw_post(CPUArchState *env, target_ulong addr, uint16_t info) +{ +} + +static inline +void atomic_trace_ld_pre(CPUArchState *env, target_ulong addr, uint16_t info) +{ + trace_guest_mem_before_exec(env_cpu(env), addr, info); +} + +static inline +void atomic_trace_ld_post(CPUArchState *env, target_ulong addr, uint16_t info) +{ +} + +static inline +void atomic_trace_st_pre(CPUArchState *env, target_ulong addr, uint16_t info) +{ + trace_guest_mem_before_exec(env_cpu(env), addr, info); +} + +static inline +void atomic_trace_st_post(CPUArchState *env, target_ulong addr, uint16_t info) +{ +} diff --git a/accel/tcg/atomic_template.h b/accel/tcg/atomic_template.h index 53899bbbc21..34f891d4a62 100644 --- a/accel/tcg/atomic_template.h +++ b/accel/tcg/atomic_template.h @@ -59,26 +59,6 @@ # define ABI_TYPE uint32_t #endif -#define ATOMIC_TRACE_RMW do { \ - uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false, ATOMIC_MMU_IDX); \ - \ - trace_guest_mem_before_exec(env_cpu(env), addr, info); \ - trace_guest_mem_before_exec(env_cpu(env), addr, \ - info | TRACE_MEM_ST); \ - } while (0) - -#define ATOMIC_TRACE_LD do { \ - uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false, ATOMIC_MMU_IDX); \ - \ - trace_guest_mem_before_exec(env_cpu(env), addr, info); \ - } while (0) - -# define ATOMIC_TRACE_ST do { \ - uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, true, ATOMIC_MMU_IDX); \ - \ - trace_guest_mem_before_exec(env_cpu(env), addr, info); \ - } while (0) - /* Define host-endian atomic operations. Note that END is used within the ATOMIC_NAME macro, and redefined below. */ #if DATA_SIZE == 1 @@ -98,14 +78,17 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, target_ulong addr, ATOMIC_MMU_DECLS; DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; DATA_TYPE ret; + uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false, + ATOMIC_MMU_IDX); - ATOMIC_TRACE_RMW; + atomic_trace_rmw_pre(env, addr, info); #if DATA_SIZE == 16 ret = atomic16_cmpxchg(haddr, cmpv, newv); #else ret = atomic_cmpxchg__nocheck(haddr, cmpv, newv); #endif ATOMIC_MMU_CLEANUP; + atomic_trace_rmw_post(env, addr, info); return ret; } @@ -115,10 +98,13 @@ ABI_TYPE ATOMIC_NAME(ld)(CPUArchState *env, target_ulong addr EXTRA_ARGS) { ATOMIC_MMU_DECLS; DATA_TYPE val, *haddr = ATOMIC_MMU_LOOKUP; + uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false, + ATOMIC_MMU_IDX); - ATOMIC_TRACE_LD; + atomic_trace_ld_pre(env, addr, info); val = atomic16_read(haddr); ATOMIC_MMU_CLEANUP; + atomic_trace_ld_post(env, addr, info); return val; } @@ -127,10 +113,13 @@ void ATOMIC_NAME(st)(CPUArchState *env, target_ulong addr, { ATOMIC_MMU_DECLS; DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; + uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, true, + ATOMIC_MMU_IDX); - ATOMIC_TRACE_ST; + atomic_trace_st_pre(env, addr, info); atomic16_set(haddr, val); ATOMIC_MMU_CLEANUP; + atomic_trace_st_post(env, addr, info); } #endif #else @@ -140,10 +129,13 @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, target_ulong addr, ATOMIC_MMU_DECLS; DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; DATA_TYPE ret; + uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false, + ATOMIC_MMU_IDX); - ATOMIC_TRACE_RMW; + atomic_trace_rmw_pre(env, addr, info); ret = atomic_xchg__nocheck(haddr, val); ATOMIC_MMU_CLEANUP; + atomic_trace_rmw_post(env, addr, info); return ret; } @@ -154,10 +146,14 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr, \ ATOMIC_MMU_DECLS; \ DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; \ DATA_TYPE ret; \ + uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, \ + false, \ + ATOMIC_MMU_IDX); \ \ - ATOMIC_TRACE_RMW; \ + atomic_trace_rmw_pre(env, addr, info); \ ret = atomic_##X(haddr, val); \ ATOMIC_MMU_CLEANUP; \ + atomic_trace_rmw_post(env, addr, info); \ return ret; \ } @@ -186,8 +182,11 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr, \ ATOMIC_MMU_DECLS; \ XDATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; \ XDATA_TYPE cmp, old, new, val = xval; \ + uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, \ + false, \ + ATOMIC_MMU_IDX); \ \ - ATOMIC_TRACE_RMW; \ + atomic_trace_rmw_pre(env, addr, info); \ smp_mb(); \ cmp = atomic_read__nocheck(haddr); \ do { \ @@ -195,6 +194,7 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr, \ cmp = atomic_cmpxchg__nocheck(haddr, old, new); \ } while (cmp != old); \ ATOMIC_MMU_CLEANUP; \ + atomic_trace_rmw_post(env, addr, info); \ return RET; \ } @@ -232,14 +232,18 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, target_ulong addr, ATOMIC_MMU_DECLS; DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; DATA_TYPE ret; + uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, + false, + ATOMIC_MMU_IDX); - ATOMIC_TRACE_RMW; + atomic_trace_rmw_pre(env, addr, info); #if DATA_SIZE == 16 ret = atomic16_cmpxchg(haddr, BSWAP(cmpv), BSWAP(newv)); #else ret = atomic_cmpxchg__nocheck(haddr, BSWAP(cmpv), BSWAP(newv)); #endif ATOMIC_MMU_CLEANUP; + atomic_trace_rmw_post(env, addr, info); return BSWAP(ret); } @@ -249,10 +253,14 @@ ABI_TYPE ATOMIC_NAME(ld)(CPUArchState *env, target_ulong addr EXTRA_ARGS) { ATOMIC_MMU_DECLS; DATA_TYPE val, *haddr = ATOMIC_MMU_LOOKUP; + uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, + false, + ATOMIC_MMU_IDX); - ATOMIC_TRACE_LD; + atomic_trace_ld_pre(env, addr, info); val = atomic16_read(haddr); ATOMIC_MMU_CLEANUP; + atomic_trace_ld_post(env, addr, info); return BSWAP(val); } @@ -261,11 +269,16 @@ void ATOMIC_NAME(st)(CPUArchState *env, target_ulong addr, { ATOMIC_MMU_DECLS; DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; + uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, + true, + ATOMIC_MMU_IDX); - ATOMIC_TRACE_ST; + val = BSWAP(val); + atomic_trace_st_pre(env, addr, info); val = BSWAP(val); atomic16_set(haddr, val); ATOMIC_MMU_CLEANUP; + atomic_trace_st_post(env, addr, info); } #endif #else @@ -275,10 +288,14 @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, target_ulong addr, ATOMIC_MMU_DECLS; DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; ABI_TYPE ret; + uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, + false, + ATOMIC_MMU_IDX); - ATOMIC_TRACE_RMW; + atomic_trace_rmw_pre(env, addr, info); ret = atomic_xchg__nocheck(haddr, BSWAP(val)); ATOMIC_MMU_CLEANUP; + atomic_trace_rmw_post(env, addr, info); return BSWAP(ret); } @@ -289,10 +306,14 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr, \ ATOMIC_MMU_DECLS; \ DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; \ DATA_TYPE ret; \ + uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, \ + false, \ + ATOMIC_MMU_IDX); \ \ - ATOMIC_TRACE_RMW; \ + atomic_trace_rmw_pre(env, addr, info); \ ret = atomic_##X(haddr, BSWAP(val)); \ ATOMIC_MMU_CLEANUP; \ + atomic_trace_rmw_post(env, addr, info); \ return BSWAP(ret); \ } @@ -319,8 +340,11 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr, \ ATOMIC_MMU_DECLS; \ XDATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; \ XDATA_TYPE ldo, ldn, old, new, val = xval; \ + uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, \ + false, \ + ATOMIC_MMU_IDX); \ \ - ATOMIC_TRACE_RMW; \ + atomic_trace_rmw_pre(env, addr, info); \ smp_mb(); \ ldn = atomic_read__nocheck(haddr); \ do { \ @@ -328,6 +352,7 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr, \ ldn = atomic_cmpxchg__nocheck(haddr, ldo, BSWAP(new)); \ } while (ldo != ldn); \ ATOMIC_MMU_CLEANUP; \ + atomic_trace_rmw_post(env, addr, info); \ return RET; \ } @@ -355,10 +380,6 @@ GEN_ATOMIC_HELPER_FN(add_fetch, ADD, DATA_TYPE, new) #undef MEND #endif /* DATA_SIZE > 1 */ -#undef ATOMIC_TRACE_ST -#undef ATOMIC_TRACE_LD -#undef ATOMIC_TRACE_RMW - #undef BSWAP #undef ABI_TYPE #undef DATA_TYPE diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 21ba71ea9dd..e4ac06041a2 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1701,6 +1701,8 @@ void helper_be_stq_mmu(CPUArchState *env, target_ulong addr, uint64_t val, } while (0) #define ATOMIC_MMU_IDX oi +#include "atomic_common.inc.c" + #define DATA_SIZE 1 #include "atomic_template.h" diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index bff1934cf1b..1c8aee943dc 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -724,6 +724,8 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr, #define ATOMIC_NAME(X) HELPER(glue(glue(atomic_ ## X, SUFFIX), END)) #define EXTRA_ARGS +#include "atomic_common.inc.c" + #define DATA_SIZE 1 #include "atomic_template.h" From patchwork Wed Jul 31 16:06:48 2019 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: 11068681 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7E9DA912 for ; Wed, 31 Jul 2019 16:24:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 661642018F for ; Wed, 31 Jul 2019 16:24:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5772F20223; Wed, 31 Jul 2019 16:24:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3D03B2018F for ; Wed, 31 Jul 2019 16:24:39 +0000 (UTC) Received: from localhost ([::1]:42604 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrP4-0002su-KJ for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:24:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42544) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrGD-0006HY-8K for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrGA-0004E0-Tg for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:29 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:35825) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrGA-0004DK-HV for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:26 -0400 Received: by mail-wm1-x342.google.com with SMTP id l2so60342626wmg.0 for ; Wed, 31 Jul 2019 09:15:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MQ+MbYzqozJQ8J6CVJK/Op+zhd+3OFxe+UkgMgIDHKA=; b=pSvQZhvkyprZK7snFzo91Oqawkfc0q/fKdUBHufj4NtJBlWkCWd3XEQLHppE/2Sf46 PsGzODxQpphNnCS5RlsmnucIkEJye6mpTdFJsX9zCMZqJzd4eDQfBCE7P8kFNlLMkCjZ sHxAsAuI5GtqiJWA+HVPNOtkcN2XbZ+o6fLbo02jEvYa83Ojn6qbiiRc5240JAASQIzs +ZsNA9+GmbMAQva4sd2cfdD1QjL4Hhh//p5PsYh5joqyJwmEULuxDveAxtL5ZTMwpyYm dmNk+J3kal00Hw247GuPE3E8Ar7k0ZV8llvcw4lSTDb61w5SJdQ6mJcayun2Ja4pr/Hz PLhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MQ+MbYzqozJQ8J6CVJK/Op+zhd+3OFxe+UkgMgIDHKA=; b=MRq/JXXyPAO1lUEvjKAVXeYQ/sd8dT+KuN+41khmrR4v0ZvME8aQWTn7GoG5qHdcty 5M/D8Cbma1YsP76dVOAMXSLI7bfPYMUH2TLh0VmSzUYx6G0P3xUOUvLLJMf7b/u4yQFY +N65xk33K6apMtZ5XEtYNtswq7Y4IZIJKEJcs+WX+Udot48TZy/8wRHKF5UkrhUznv50 /PbOsvu5cBu4VoDc9rAH80KW6E/gqWD+3jeJrxFEgkpP8VKoBqVpGbp3niN1tdKmnA9+ npFWHIGQZi1rKDuKU0VV9d62TcfwB4tWxoBua2yxpQkdu0gtMs9s/4R8A3J/o5oBMQLf ic+w== X-Gm-Message-State: APjAAAVHqMjkSYNhUHPD3tQuGCQtGz/YfNHFaB6+f1lwSU87kzIC7dlN E82rEPrcVTX9y/TxhupQSuPE7A== X-Google-Smtp-Source: APXvYqzSzarbNKsHiwJd2hN91qSf8CNBHvH4IyKWQzCOC3cz4EvwXaMntvuOMaabUkHn5M46LPQfrA== X-Received: by 2002:a1c:770d:: with SMTP id t13mr38442572wmi.79.1564589725297; Wed, 31 Jul 2019 09:15:25 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id a67sm77037062wmh.40.2019.07.31.09.15.17 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:15:22 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id AC47E1FFAB; Wed, 31 Jul 2019 17:07:21 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:48 +0100 Message-Id: <20190731160719.11396-24-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 Subject: [Qemu-devel] [PATCH v4 23/54] tcg: let plugins instrument virtual memory accesses X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" To capture all memory accesses we need hook into all the various helper functions that are involved in memory operations as well as the injected inline helper calls. A later commit will allow us to resolve the actual guest HW addresses by replaying the lookup. Signed-off-by: Emilio G. Cota [AJB: drop haddr handling, just deal in vaddr] Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v3 - fixes for cpu_neg() v4 - rebase fixups, moved cpu_neg() fixes down the stack - drop haddr support - will be restored with later helper - reword commit --- accel/tcg/atomic_common.inc.c | 4 +++ accel/tcg/atomic_template.h | 1 + accel/tcg/cpu-exec.c | 3 ++ accel/tcg/cputlb.c | 14 ++++---- include/exec/cpu-defs.h | 1 + include/exec/cpu_ldst_template.h | 28 +++++++++------- include/exec/cpu_ldst_useronly_template.h | 29 ++++++++-------- tcg/tcg-op.c | 40 ++++++++++++++++++----- tcg/tcg.h | 1 + 9 files changed, 79 insertions(+), 42 deletions(-) diff --git a/accel/tcg/atomic_common.inc.c b/accel/tcg/atomic_common.inc.c index a86098fb2de..344525b0bb3 100644 --- a/accel/tcg/atomic_common.inc.c +++ b/accel/tcg/atomic_common.inc.c @@ -25,6 +25,8 @@ void atomic_trace_rmw_pre(CPUArchState *env, target_ulong addr, uint16_t info) static inline void atomic_trace_rmw_post(CPUArchState *env, target_ulong addr, uint16_t info) { + qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, info); + qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, info | TRACE_MEM_ST); } static inline @@ -36,6 +38,7 @@ void atomic_trace_ld_pre(CPUArchState *env, target_ulong addr, uint16_t info) static inline void atomic_trace_ld_post(CPUArchState *env, target_ulong addr, uint16_t info) { + qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, info); } static inline @@ -47,4 +50,5 @@ void atomic_trace_st_pre(CPUArchState *env, target_ulong addr, uint16_t info) static inline void atomic_trace_st_post(CPUArchState *env, target_ulong addr, uint16_t info) { + qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, info); } diff --git a/accel/tcg/atomic_template.h b/accel/tcg/atomic_template.h index 34f891d4a62..4f209c8e18c 100644 --- a/accel/tcg/atomic_template.h +++ b/accel/tcg/atomic_template.h @@ -18,6 +18,7 @@ * License along with this library; if not, see . */ +#include "qemu/plugin.h" #include "trace/mem.h" #if DATA_SIZE == 16 diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index ab9dfd4f908..81be72a373d 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -269,6 +269,7 @@ void cpu_exec_step_atomic(CPUState *cpu) qemu_mutex_unlock_iothread(); } assert_no_pages_locked(); + qemu_plugin_disable_mem_helpers(cpu); } if (cpu_in_exclusive_context(cpu)) { @@ -702,6 +703,8 @@ int cpu_exec(CPUState *cpu) if (qemu_mutex_iothread_locked()) { qemu_mutex_unlock_iothread(); } + qemu_plugin_disable_mem_helpers(cpu); + assert_no_pages_locked(); } diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index e4ac06041a2..f7c0290639c 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -881,7 +881,7 @@ static void tlb_fill(CPUState *cpu, target_ulong addr, int size, static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry, int mmu_idx, target_ulong addr, uintptr_t retaddr, - MMUAccessType access_type, int size) + TCGMemOp mo, MMUAccessType access_type, int size) { CPUState *cpu = env_cpu(env); hwaddr mr_offset; @@ -925,7 +925,7 @@ static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry, static void io_writex(CPUArchState *env, CPUIOTLBEntry *iotlbentry, int mmu_idx, uint64_t val, target_ulong addr, - uintptr_t retaddr, int size) + uintptr_t retaddr, TCGMemOp mo, int size) { CPUState *cpu = env_cpu(env); hwaddr mr_offset; @@ -1264,7 +1264,8 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, offsetof(CPUTLBEntry, addr_code) : offsetof(CPUTLBEntry, addr_read); const MMUAccessType access_type = code_read ? MMU_INST_FETCH : MMU_DATA_LOAD; - unsigned a_bits = get_alignment_bits(get_memop(oi)); + TCGMemOp mo = get_memop(oi); + unsigned a_bits = get_alignment_bits(mo); void *haddr; uint64_t res; @@ -1313,7 +1314,7 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, } res = io_readx(env, &env_tlb(env)->d[mmu_idx].iotlb[index], - mmu_idx, addr, retaddr, access_type, size); + mmu_idx, addr, retaddr, mo, access_type, size); return handle_bswap(res, size, big_endian); } @@ -1513,7 +1514,8 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val, CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr); target_ulong tlb_addr = tlb_addr_write(entry); const size_t tlb_off = offsetof(CPUTLBEntry, addr_write); - unsigned a_bits = get_alignment_bits(get_memop(oi)); + TCGMemOp mo = get_memop(oi); + unsigned a_bits = get_alignment_bits(mo); void *haddr; /* Handle CPU specific unaligned behaviour */ @@ -1562,7 +1564,7 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val, io_writex(env, &env_tlb(env)->d[mmu_idx].iotlb[index], mmu_idx, handle_bswap(val, size, big_endian), - addr, retaddr, size); + addr, retaddr, mo, size); return; } diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h index 9bc713a70b2..31deca369ea 100644 --- a/include/exec/cpu-defs.h +++ b/include/exec/cpu-defs.h @@ -215,6 +215,7 @@ typedef struct CPUTLBCommon { * Since this is placed within CPUNegativeOffsetState, the smallest * negative offsets are at the end of the struct. */ + typedef struct CPUTLB { CPUTLBCommon c; CPUTLBDesc d[NB_MMU_MODES]; diff --git a/include/exec/cpu_ldst_template.h b/include/exec/cpu_ldst_template.h index 5750a26b9ec..6f0d3407979 100644 --- a/include/exec/cpu_ldst_template.h +++ b/include/exec/cpu_ldst_template.h @@ -28,6 +28,7 @@ #include "trace-root.h" #endif +#include "qemu/plugin.h" #include "trace/mem.h" #if DATA_SIZE == 8 @@ -86,11 +87,9 @@ glue(glue(glue(cpu_ld, USUFFIX), MEMSUFFIX), _ra)(CPUArchState *env, target_ulong addr; int mmu_idx = CPU_MMU_INDEX; TCGMemOpIdx oi; - #if !defined(SOFTMMU_CODE_ACCESS) - trace_guest_mem_before_exec( - env_cpu(env), ptr, - trace_mem_build_info(SHIFT, false, MO_TE, false, mmu_idx)); + uint16_t meminfo = trace_mem_build_info(SHIFT, false, MO_TE, false, mmu_idx); + trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); #endif addr = ptr; @@ -104,6 +103,9 @@ glue(glue(glue(cpu_ld, USUFFIX), MEMSUFFIX), _ra)(CPUArchState *env, uintptr_t hostaddr = addr + entry->addend; res = glue(glue(ld, USUFFIX), _p)((uint8_t *)hostaddr); } +#ifndef SOFTMMU_CODE_ACCESS + qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); +#endif return res; } @@ -124,11 +126,9 @@ glue(glue(glue(cpu_lds, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env, target_ulong addr; int mmu_idx = CPU_MMU_INDEX; TCGMemOpIdx oi; - #if !defined(SOFTMMU_CODE_ACCESS) - trace_guest_mem_before_exec( - env_cpu(env), ptr, - trace_mem_build_info(SHIFT, true, MO_TE, false, mmu_idx)); + uint16_t meminfo = trace_mem_build_info(SHIFT, true, MO_TE, false, mmu_idx); + trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); #endif addr = ptr; @@ -142,6 +142,9 @@ glue(glue(glue(cpu_lds, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env, uintptr_t hostaddr = addr + entry->addend; res = glue(glue(lds, SUFFIX), _p)((uint8_t *)hostaddr); } +#ifndef SOFTMMU_CODE_ACCESS + qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); +#endif return res; } @@ -165,11 +168,9 @@ glue(glue(glue(cpu_st, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env, target_ulong addr; int mmu_idx = CPU_MMU_INDEX; TCGMemOpIdx oi; - #if !defined(SOFTMMU_CODE_ACCESS) - trace_guest_mem_before_exec( - env_cpu(env), ptr, - trace_mem_build_info(SHIFT, false, MO_TE, true, mmu_idx)); + uint16_t meminfo = trace_mem_build_info(SHIFT, false, MO_TE, true, mmu_idx); + trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); #endif addr = ptr; @@ -183,6 +184,9 @@ glue(glue(glue(cpu_st, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env, uintptr_t hostaddr = addr + entry->addend; glue(glue(st, SUFFIX), _p)((uint8_t *)hostaddr, v); } +#ifndef SOFTMMU_CODE_ACCESS + qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); +#endif } static inline void diff --git a/include/exec/cpu_ldst_useronly_template.h b/include/exec/cpu_ldst_useronly_template.h index 8f7f117ad44..5cd0fa3b99d 100644 --- a/include/exec/cpu_ldst_useronly_template.h +++ b/include/exec/cpu_ldst_useronly_template.h @@ -64,18 +64,17 @@ static inline RES_TYPE glue(glue(cpu_ld, USUFFIX), MEMSUFFIX)(CPUArchState *env, abi_ptr ptr) { -#ifdef CODE_ACCESS RES_TYPE ret; +#ifdef CODE_ACCESS set_helper_retaddr(1); ret = glue(glue(ld, USUFFIX), _p)(g2h(ptr)); clear_helper_retaddr(); - return ret; #else - trace_guest_mem_before_exec( - env_cpu(env), ptr, - trace_mem_build_info(SHIFT, false, MO_TE, false, 0)); - return glue(glue(ld, USUFFIX), _p)(g2h(ptr)); + uint16_t meminfo = trace_mem_build_info(SHIFT, false, MO_TE, false, 0); + trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); + ret = glue(glue(ld, USUFFIX), _p)(g2h(ptr)); #endif + return ret; } #ifndef CODE_ACCESS @@ -96,18 +95,18 @@ glue(glue(glue(cpu_ld, USUFFIX), MEMSUFFIX), _ra)(CPUArchState *env, static inline int glue(glue(cpu_lds, SUFFIX), MEMSUFFIX)(CPUArchState *env, abi_ptr ptr) { -#ifdef CODE_ACCESS int ret; +#ifdef CODE_ACCESS set_helper_retaddr(1); ret = glue(glue(lds, SUFFIX), _p)(g2h(ptr)); clear_helper_retaddr(); - return ret; #else - trace_guest_mem_before_exec( - env_cpu(env), ptr, - trace_mem_build_info(SHIFT, true, MO_TE, false, 0)); - return glue(glue(lds, SUFFIX), _p)(g2h(ptr)); + uint16_t meminfo = trace_mem_build_info(SHIFT, true, MO_TE, false, 0); + trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); + ret = glue(glue(lds, SUFFIX), _p)(g2h(ptr)); + qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); #endif + return ret; } #ifndef CODE_ACCESS @@ -130,10 +129,10 @@ static inline void glue(glue(cpu_st, SUFFIX), MEMSUFFIX)(CPUArchState *env, abi_ptr ptr, RES_TYPE v) { - trace_guest_mem_before_exec( - env_cpu(env), ptr, - trace_mem_build_info(SHIFT, false, MO_TE, true, 0)); + uint16_t meminfo = trace_mem_build_info(SHIFT, false, MO_TE, true, 0); + trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); glue(glue(st, SUFFIX), _p)(g2h(ptr), v); + qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); } static inline void diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c index 38e62dcba97..b60b42e6410 100644 --- a/tcg/tcg-op.c +++ b/tcg/tcg-op.c @@ -30,6 +30,7 @@ #include "tcg-mo.h" #include "trace-tcg.h" #include "trace/mem.h" +#include "exec/plugin-gen.h" /* Reduce the number of ifdefs below. This assumes that all uses of TCGV_HIGH and TCGV_LOW are properly protected by a conditional that @@ -2684,6 +2685,7 @@ void tcg_gen_exit_tb(TranslationBlock *tb, unsigned idx) tcg_debug_assert(idx == TB_EXIT_REQUESTED); } + plugin_gen_disable_mem_helpers(); tcg_gen_op1i(INDEX_op_exit_tb, val); } @@ -2696,6 +2698,7 @@ void tcg_gen_goto_tb(unsigned idx) tcg_debug_assert((tcg_ctx->goto_tb_issue_mask & (1 << idx)) == 0); tcg_ctx->goto_tb_issue_mask |= 1 << idx; #endif + plugin_gen_disable_mem_helpers(); /* When not chaining, we simply fall through to the "fallback" exit. */ if (!qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN)) { tcg_gen_op1i(INDEX_op_goto_tb, idx); @@ -2705,7 +2708,10 @@ void tcg_gen_goto_tb(unsigned idx) void tcg_gen_lookup_and_goto_ptr(void) { if (TCG_TARGET_HAS_goto_ptr && !qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN)) { - TCGv_ptr ptr = tcg_temp_new_ptr(); + TCGv_ptr ptr; + + plugin_gen_disable_mem_helpers(); + ptr = tcg_temp_new_ptr(); gen_helper_lookup_tb_ptr(ptr, cpu_env); tcg_gen_op1i(INDEX_op_goto_ptr, tcgv_ptr_arg(ptr)); tcg_temp_free_ptr(ptr); @@ -2788,14 +2794,24 @@ static void tcg_gen_req_mo(TCGBar type) } } +static inline void plugin_gen_mem_callbacks(TCGv vaddr, uint16_t info) +{ +#ifdef CONFIG_PLUGIN + if (tcg_ctx->plugin_insn == NULL) { + return; + } + plugin_gen_empty_mem_callback(vaddr, info); +#endif +} + void tcg_gen_qemu_ld_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop) { TCGMemOp orig_memop; + uint16_t info = trace_mem_get_info(memop, idx, 0); tcg_gen_req_mo(TCG_MO_LD_LD | TCG_MO_ST_LD); memop = tcg_canonicalize_memop(memop, 0, 0); - trace_guest_mem_before_tcg(tcg_ctx->cpu, cpu_env, - addr, trace_mem_get_info(memop, idx, 0)); + trace_guest_mem_before_tcg(tcg_ctx->cpu, cpu_env, addr, info); orig_memop = memop; if (!TCG_TARGET_HAS_MEMORY_BSWAP && (memop & MO_BSWAP)) { @@ -2807,6 +2823,7 @@ void tcg_gen_qemu_ld_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop) } gen_ldst_i32(INDEX_op_qemu_ld_i32, val, addr, memop, idx); + plugin_gen_mem_callbacks(addr, info); if ((orig_memop ^ memop) & MO_BSWAP) { switch (orig_memop & MO_SIZE) { @@ -2828,11 +2845,11 @@ void tcg_gen_qemu_ld_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop) void tcg_gen_qemu_st_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop) { TCGv_i32 swap = NULL; + uint16_t info = trace_mem_get_info(memop, idx, 1); tcg_gen_req_mo(TCG_MO_LD_ST | TCG_MO_ST_ST); memop = tcg_canonicalize_memop(memop, 0, 1); - trace_guest_mem_before_tcg(tcg_ctx->cpu, cpu_env, - addr, trace_mem_get_info(memop, idx, 1)); + trace_guest_mem_before_tcg(tcg_ctx->cpu, cpu_env, addr, info); if (!TCG_TARGET_HAS_MEMORY_BSWAP && (memop & MO_BSWAP)) { swap = tcg_temp_new_i32(); @@ -2852,6 +2869,7 @@ void tcg_gen_qemu_st_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop) } gen_ldst_i32(INDEX_op_qemu_st_i32, val, addr, memop, idx); + plugin_gen_mem_callbacks(addr, info); if (swap) { tcg_temp_free_i32(swap); @@ -2861,6 +2879,7 @@ void tcg_gen_qemu_st_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop) void tcg_gen_qemu_ld_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) { TCGMemOp orig_memop; + uint16_t info; if (TCG_TARGET_REG_BITS == 32 && (memop & MO_SIZE) < MO_64) { tcg_gen_qemu_ld_i32(TCGV_LOW(val), addr, idx, memop); @@ -2874,8 +2893,8 @@ void tcg_gen_qemu_ld_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) tcg_gen_req_mo(TCG_MO_LD_LD | TCG_MO_ST_LD); memop = tcg_canonicalize_memop(memop, 1, 0); - trace_guest_mem_before_tcg(tcg_ctx->cpu, cpu_env, - addr, trace_mem_get_info(memop, idx, 0)); + info = trace_mem_get_info(memop, idx, 0); + trace_guest_mem_before_tcg(tcg_ctx->cpu, cpu_env, addr, info); orig_memop = memop; if (!TCG_TARGET_HAS_MEMORY_BSWAP && (memop & MO_BSWAP)) { @@ -2887,6 +2906,7 @@ void tcg_gen_qemu_ld_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) } gen_ldst_i64(INDEX_op_qemu_ld_i64, val, addr, memop, idx); + plugin_gen_mem_callbacks(addr, info); if ((orig_memop ^ memop) & MO_BSWAP) { switch (orig_memop & MO_SIZE) { @@ -2914,6 +2934,7 @@ void tcg_gen_qemu_ld_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) void tcg_gen_qemu_st_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) { TCGv_i64 swap = NULL; + uint16_t info; if (TCG_TARGET_REG_BITS == 32 && (memop & MO_SIZE) < MO_64) { tcg_gen_qemu_st_i32(TCGV_LOW(val), addr, idx, memop); @@ -2922,8 +2943,8 @@ void tcg_gen_qemu_st_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) tcg_gen_req_mo(TCG_MO_LD_ST | TCG_MO_ST_ST); memop = tcg_canonicalize_memop(memop, 1, 1); - trace_guest_mem_before_tcg(tcg_ctx->cpu, cpu_env, - addr, trace_mem_get_info(memop, idx, 1)); + info = trace_mem_get_info(memop, idx, 1); + trace_guest_mem_before_tcg(tcg_ctx->cpu, cpu_env, addr, info); if (!TCG_TARGET_HAS_MEMORY_BSWAP && (memop & MO_BSWAP)) { swap = tcg_temp_new_i64(); @@ -2947,6 +2968,7 @@ void tcg_gen_qemu_st_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) } gen_ldst_i64(INDEX_op_qemu_st_i64, val, addr, memop, idx); + plugin_gen_mem_callbacks(addr, info); if (swap) { tcg_temp_free_i64(swap); diff --git a/tcg/tcg.h b/tcg/tcg.h index 2385e758e55..93f52f4ca93 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -28,6 +28,7 @@ #include "cpu.h" #include "exec/tb-context.h" #include "qemu/bitops.h" +#include "qemu/plugin.h" #include "qemu/queue.h" #include "tcg-mo.h" #include "tcg-target.h" From patchwork Wed Jul 31 16:06:49 2019 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: 11068737 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2C48F912 for ; Wed, 31 Jul 2019 16:32:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18830205A9 for ; Wed, 31 Jul 2019 16:32:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C46C205F7; Wed, 31 Jul 2019 16:32:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7A15F205A9 for ; Wed, 31 Jul 2019 16:31:59 +0000 (UTC) Received: from localhost ([::1]:42820 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrWA-0003ML-DT for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:31:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45205) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrPn-00051s-GW for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrPm-0000MS-0K for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:23 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:35107) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrPl-0000Ly-QB for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:21 -0400 Received: by mail-wr1-x444.google.com with SMTP id y4so70383126wrm.2 for ; Wed, 31 Jul 2019 09:25:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nwwivd4l04F9lotguBi5Pm9ljTTEntqAZyI9oEyrjH8=; b=sDO1fhpFlvG0YQoaMXLyUECDLb92YEL+YNc8Ll9Tqnl1Yyu8fW78x/hEpRuRewSQpX hKc4+mvpSE8YHZej0UNrw8gFlTvIUhHpjoLPs5yX8EJfr+wg+mFt4NVUe74rhrcjHCnG s5FtNIHTCGfPI/bCv1nt7tLymIyDKlDHz2WkhROZBnFx7vGyUhIufL8S0/CayDobrSyr d2zkcuHbdnV50XuTtjAqnTdm3dmEnf2ABd9y2Zldyc85F3mh7eankudz99l1ZwRAOZ0d PEGAYA5oQg11E9M1xTv+0xy74GPIG3Y/hR5PGV41Pw3L7H9QeTS1gUG9ZDzNTe4J3Hhu /CIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nwwivd4l04F9lotguBi5Pm9ljTTEntqAZyI9oEyrjH8=; b=boqW/XHOSZS0uXx2ibGaJ33ZBfiguKDm977hUsDZ4CHmRdhe8zqE2CCo3HtbBrQYaz WeNmT7oMG785at19xmMbPQe/uojJTwxTsVqf/CTqo3iraU8auRN2Ax02Jd0n6k0nzYDz PLUR/SNbbaGJ/rkdvScBuh/BF6+a/tT+qWFgB89EHchIAcHG5QczfHSoVUA55259F/j2 ikspq/AXL8pg04BCd+Xcjsf3CodFRdddWfqcZBVkZ98aYNyh2mohhz1RGnMEBYkG1ro2 4OqSpo7ob2uzwh8upxRIx9ycsiSMzNSmXXsGJC6LPDdF6SG1V/TIptoNfmDTg37bNqUT BqSg== X-Gm-Message-State: APjAAAXLfeDYnzLjjPwkNMkehSRLFUfm0yNEL9HKgknCnA4qAD5k3Na+ TCmsyP9zaA+rFUYIJYe3HcTL0IVuTpM= X-Google-Smtp-Source: APXvYqxXd+H0GGKlOoRndl0xFfWeP2MV9/3GiCirZoIGXWxFw6fCzS5Q7hY+WMe5STFayodVYELVug== X-Received: by 2002:a5d:6144:: with SMTP id y4mr5708897wrt.84.1564590320731; Wed, 31 Jul 2019 09:25:20 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id j17sm113934938wrb.35.2019.07.31.09.25.14 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:25:16 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C480D1FF8C; Wed, 31 Jul 2019 17:07:21 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:49 +0100 Message-Id: <20190731160719.11396-25-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH v4 24/54] plugins: implement helpers for resolving hwaddr X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We need to keep a local per-cpu copy of the data as other threads may be running. We use a automatically growing array and re-use the space for subsequent queries. Signed-off-by: Alex Bennée --- accel/tcg/cputlb.c | 32 ++++++++++++++++++++++++++ include/exec/exec-all.h | 17 ++++++++++++++ include/qemu/plugin.h | 6 +++++ plugins/api.c | 50 +++++++++++++++++++++++++++++++++-------- 4 files changed, 96 insertions(+), 9 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index f7c0290639c..f37e89c806d 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1130,6 +1130,38 @@ void *tlb_vaddr_to_host(CPUArchState *env, abi_ptr addr, return (void *)((uintptr_t)addr + entry->addend); } + +#ifdef CONFIG_PLUGIN +/* + * Perform a TLB lookup and populate the qemu_plugin_hwaddr structure. + * This should be a hot path as we will have just looked this path up + * in the softmmu lookup code (or helper). We don't handle re-fills or + * checking the victim table. This is purely informational. + */ + +bool tlb_plugin_lookup(CPUState *cpu, target_ulong addr, int mmu_idx, + bool is_store, struct qemu_plugin_hwaddr *data) +{ + CPUArchState *env = cpu->env_ptr; + CPUTLBEntry *tlbe = tlb_entry(env, mmu_idx, addr); + target_ulong tlb_addr = is_store ? tlb_addr_write(tlbe) : tlbe->addr_read; + + if (tlb_hit(tlb_addr, addr)) { + if (tlb_addr & TLB_MMIO) { + data->hostaddr = 0; + data->is_io = true; + /* XXX: lookup device */ + } else { + data->hostaddr = addr + tlbe->addend; + data->is_io = false; + } + return true; + } + return false; +} + +#endif + /* Probe for a read-modify-write atomic operation. Do not allow unaligned * operations, or io operations to proceed. Return the host address. */ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr, diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 90045e77c1f..c42626e35b1 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -262,6 +262,17 @@ void tlb_set_page(CPUState *cpu, target_ulong vaddr, int mmu_idx, target_ulong size); void probe_write(CPUArchState *env, target_ulong addr, int size, int mmu_idx, uintptr_t retaddr); + +/** + * tlb_plugin_lookup: query last TLB lookup + * @cpu: cpu environment + * + * This function can be used directly after a memory operation to + * query information about the access. It is used by the plugin + * infrastructure to expose more information about the address. + */ +bool tlb_plugin_lookup(CPUState *cpu, target_ulong addr, int mmu_idx, + bool is_store, struct qemu_plugin_hwaddr *data); #else static inline void tlb_init(CPUState *cpu) { @@ -311,6 +322,12 @@ static inline void tlb_flush_by_mmuidx_all_cpus_synced(CPUState *cpu, uint16_t idxmap) { } +static inline bool tlb_plugin_lookup(CPUState *cpu, target_ulong addr, + int mmu_idx, bool is_store, + struct qemu_plugin_hwaddr *data) +{ + return false; +} #endif #define CODE_GEN_ALIGN 16 /* must be >= of the size of a icache line */ diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index 3c46a241669..657345df60c 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -182,6 +182,12 @@ struct qemu_plugin_insn *qemu_plugin_tb_insn_get(struct qemu_plugin_tb *tb) return insn; } +struct qemu_plugin_hwaddr { + uint64_t hostaddr; + bool is_io; +}; + + #ifdef CONFIG_PLUGIN void qemu_plugin_vcpu_init_hook(CPUState *cpu); diff --git a/plugins/api.c b/plugins/api.c index 586bb8789f1..4b3ac9e31fb 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -39,7 +39,7 @@ #include "cpu.h" #include "sysemu/sysemu.h" #include "tcg/tcg.h" -#include "trace/mem-internal.h" /* mem_info macros */ +#include "exec/exec-all.h" #include "plugin.h" #ifndef CONFIG_USER_ONLY #include "hw/boards.h" @@ -240,11 +240,42 @@ bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info) * Virtual Memory queries */ +#ifdef CONFIG_SOFTMMU +static GArray *hwaddr_refs; + +struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info, + uint64_t vaddr) +{ + CPUState *cpu = current_cpu; + unsigned int mmu_idx = info >> TRACE_MEM_MMU_SHIFT; + struct qemu_plugin_hwaddr *hwaddr; + + /* Ensure we have memory allocated for this work */ + if (!hwaddr_refs) { + hwaddr_refs = g_array_sized_new(false, true, + sizeof(struct qemu_plugin_hwaddr), + cpu->cpu_index + 1); + } else if (cpu->cpu_index >= hwaddr_refs->len) { + hwaddr_refs = g_array_set_size(hwaddr_refs, cpu->cpu_index + 1); + } + + hwaddr = &g_array_index(hwaddr_refs, struct qemu_plugin_hwaddr, + cpu->cpu_index); + + if (!tlb_plugin_lookup(cpu, vaddr, mmu_idx, + info & TRACE_MEM_ST, hwaddr)) { + return NULL; + } + + return hwaddr; +} +#else struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info, uint64_t vaddr) { return NULL; } +#endif bool qemu_plugin_hwaddr_is_io(struct qemu_plugin_hwaddr *hwaddr) { @@ -253,14 +284,15 @@ bool qemu_plugin_hwaddr_is_io(struct qemu_plugin_hwaddr *hwaddr) uint64_t qemu_plugin_hwaddr_to_raddr(const struct qemu_plugin_hwaddr *haddr) { -#if 0 /* XXX FIXME should be SOFTMMU */ - ram_addr_t ram_addr; - - g_assert(haddr); - ram_addr = qemu_ram_addr_from_host(haddr); - if (ram_addr == RAM_ADDR_INVALID) { - error_report("Bad ram pointer %p", haddr); - abort(); +#ifdef CONFIG_SOFTMMU + ram_addr_t ram_addr = 0; + + if (haddr && !haddr->is_io) { + ram_addr = qemu_ram_addr_from_host((void *) haddr->hostaddr); + if (ram_addr == RAM_ADDR_INVALID) { + error_report("Bad ram pointer %"PRIx64"", haddr->hostaddr); + abort(); + } } return ram_addr; #else From patchwork Wed Jul 31 16:06:50 2019 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: 11068669 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 30553912 for ; Wed, 31 Jul 2019 16:22:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C1881FF41 for ; Wed, 31 Jul 2019 16:22:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1069820182; Wed, 31 Jul 2019 16:22:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AD5E91FF41 for ; Wed, 31 Jul 2019 16:22:45 +0000 (UTC) Received: from localhost ([::1]:42568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrNF-00065X-23 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:22:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42496) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrGA-00066j-Cp for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrG9-0004Co-Ay for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:26 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:54438) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrG9-0004CP-3i for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:25 -0400 Received: by mail-wm1-x341.google.com with SMTP id p74so61416665wme.4 for ; Wed, 31 Jul 2019 09:15:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KsjX33kvThYIDWRhxE9xiNalYsaeNYqt8GFqXTwRIQ4=; b=mcWF+VuzfacZ4sDjA64W2nMGZhyaeJT1PCRRBvE7OWcChgcBsuqT/j0uNMTyiCMa8u IoYAml+vnU6yxWnJS5gBW1s/ehk7wo/+pn/1rdmOaKvfMLvvg1aRhvXhCj7bZS7JzVrc 8L74rY86WKNo9ZVUEjJbQSRciK/zph8oNH8S56QQ6DRevXHOKlIRK1TAzrwiGLA4Ug1J ydMWXOJzl7GL1J2OvgL2o01rAs7S12t1AGN790oO7wxYBUDd861vutOUFAsCyBQPlxLH qtoBnMRH6uHccE3PG3jHTGdnq7CoQ5V78PD2jF9jimw7EhWgHS/XTsdWCPOaKJD9tR0T +p9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KsjX33kvThYIDWRhxE9xiNalYsaeNYqt8GFqXTwRIQ4=; b=cZpsKTeD6ta2pDsD35f63mCfyV5RZ1JpRXIug0it77y7PN8naiYKF8m/BfKr4Zrov1 QOk1eSQJivYvWnT2Qq8DSTHuaqr3co01rFVwpX7w1mLiLi6dNUxO4dmD4TsChTQT8lR4 uxF+2PpQCPdEQVZ7Hbjv1SbbWRehc+e42cHFmTB1Cl4biR1RhKKOZ/6/DsYN7EPa3RXn CGvvBTo3D4teL5wSbJQty25hAPX8UCrlUN/JMjGYvjH6arDOu1+Q3v87APy/DT1v2+s/ kCNpYi6ALH/d/ClcfF+Fy52Bd5qH+6arSBtldFauEUxyze6IoB1LknP9KWHmFSkoUu+M Jd/A== X-Gm-Message-State: APjAAAVBvbzk54ugfc7uG5txFhoUv+bpaPv4vi0fJjL2fA29aBQtvZNk BmAmUTV2Xok+KMTaunJgrZgh/g== X-Google-Smtp-Source: APXvYqw4k5EyDnVJzwPQ8fptRlyI2X/Rke3Qv8DmFMGyhV++BQrYC2CQxVOOvtjTBQfCiNywZCeynQ== X-Received: by 2002:a1c:f918:: with SMTP id x24mr10734467wmh.132.1564589724044; Wed, 31 Jul 2019 09:15:24 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id u186sm122762892wmu.26.2019.07.31.09.15.17 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:15:22 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id D9A591FFAC; Wed, 31 Jul 2019 17:07:21 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:50 +0100 Message-Id: <20190731160719.11396-26-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 Subject: [Qemu-devel] [PATCH v4 25/54] translate-all: notify plugin code of tb_flush X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Plugins might allocate per-TB data that then they get passed each time a TB is executed (via the *userdata pointer). Notify plugin code every time a code cache flush occurs, so that plugins can then reclaim the memory of the per-TB data. Reviewed-by: Alex Bennée Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- accel/tcg/translate-all.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 9c5c60ed964..7379df8f19c 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1231,6 +1231,8 @@ static gboolean tb_host_size_iter(gpointer key, gpointer value, gpointer data) /* flush all the translation blocks */ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) { + bool did_flush = false; + mmap_lock(); /* If it is already been done on request of another CPU, * just retry. @@ -1238,6 +1240,7 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) if (tb_ctx.tb_flush_count != tb_flush_count.host_int) { goto done; } + did_flush = true; if (DEBUG_TB_FLUSH_GATE) { size_t nb_tbs = tcg_nb_tbs(); @@ -1262,6 +1265,9 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) done: mmap_unlock(); + if (did_flush) { + qemu_plugin_flush_cb(); + } } void tb_flush(CPUState *cpu) From patchwork Wed Jul 31 16:06:51 2019 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: 11068689 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BE2A013AC for ; Wed, 31 Jul 2019 16:26:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8FA7203B9 for ; Wed, 31 Jul 2019 16:26:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9CB6220453; Wed, 31 Jul 2019 16:26:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 474F0203B9 for ; Wed, 31 Jul 2019 16:26:26 +0000 (UTC) Received: from localhost ([::1]:42696 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrQn-0007Ny-Hk for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:26:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45176) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrPm-0004yB-9B for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrPl-0000Ll-4K for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:22 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:34878) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrPk-0000L4-Ty for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:21 -0400 Received: by mail-wm1-x342.google.com with SMTP id l2so60370227wmg.0 for ; Wed, 31 Jul 2019 09:25:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ebMkUd6CcShKU9UYDJ7SLcVLe6tn+eNZsn2v2BV3RF0=; b=jTtbi57v2A9AIQS1kwDrZxUWLHa+PX9hwXrvh4s268kWwUsfpsNbiMl45yfQMKqrok lPBsP97ihEjpbR/Gxog0y3J9lEAZoLauEmy+XMFlVaOfjtVn4FkOBU1WITQbClPiHl1D mxdN2cPJiOeVO4izcsP7GcOpNaMySkn3U8Vsydl8EWaZGRYe2XtWVdwItsTYMJ32wP8I J2v6MwtmynyNHNFti3JV3Jv4M8vVy9XDXGynwiF2kZm+VZWPwFVanrH9eh1u1XTEKsEe /8y2I99gqfm1tjEyGij+0HgbrQVA7aV282Nc2W3wE16G1xU0hBUZF7jRE2Ap7gt/LXdh 64Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ebMkUd6CcShKU9UYDJ7SLcVLe6tn+eNZsn2v2BV3RF0=; b=O8/OI2xBv+UMe/qEMhd3H02/wc/nR85f5Uq478sVVCXBk1CJAFsi6bPlsKjD8QrCpd sl4SU6T91gp1lH0/eXUXkyheC/Ydk3E9GJOD34ZKHmkRTejtYcBEKBEI8FZ75dtIh/R6 ZUoiH89rOejz3kugn0DtJtlR7FjCADlNT3+gp6KDEZeXy1iRF5OmyXw/2y/cskdvC6fa QMVPLjKbdPFyF92OXf6ZeseAsxTNpON2+ExSDstf/JTN5dDSeJX1q3m5O4d4ibL/pMwQ uPUQ4pU6TrzeA1U6Ix4roRHjFvyqNHO9poCaI0G1WAgeejDy0BBChrc18qGdCgDZAkht h44g== X-Gm-Message-State: APjAAAW4QBMDZsQXnTsCvHqYDq4JHYIPPVI75D5eHOgoFOcR+ss1ji41 N93EDeUCaiuwlZTJ4lJpg7DD+g== X-Google-Smtp-Source: APXvYqza7P4XH/IdvKaXaY1OkCjWG8fNN1Y9IdGKi5c8CeKLzp9hvYuwFTGfFyHjEExmV8uxTqERLQ== X-Received: by 2002:a1c:345:: with SMTP id 66mr113107626wmd.8.1564590319865; Wed, 31 Jul 2019 09:25:19 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id v15sm65510695wrt.25.2019.07.31.09.25.14 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:25:16 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id EFE1A1FFAE; Wed, 31 Jul 2019 17:07:21 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:51 +0100 Message-Id: <20190731160719.11396-27-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 Subject: [Qemu-devel] [PATCH v4 26/54] *-user: notify plugin of exit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Richard Henderson , Laurent Vivier , aaron@os.amperecomputing.com, cota@braap.org, bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Reviewed-by: Alex Bennée Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- bsd-user/syscall.c | 3 +++ linux-user/exit.c | 1 + 2 files changed, 4 insertions(+) diff --git a/bsd-user/syscall.c b/bsd-user/syscall.c index 1ee6195d9ff..84a983a9a12 100644 --- a/bsd-user/syscall.c +++ b/bsd-user/syscall.c @@ -332,6 +332,7 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, _mcleanup(); #endif gdb_exit(cpu_env, arg1); + qemu_plugin_atexit_cb(); /* XXX: should free thread stack and CPU env */ _exit(arg1); ret = 0; /* avoid warning */ @@ -430,6 +431,7 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1, _mcleanup(); #endif gdb_exit(cpu_env, arg1); + qemu_plugin_atexit_cb(); /* XXX: should free thread stack and CPU env */ _exit(arg1); ret = 0; /* avoid warning */ @@ -505,6 +507,7 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1, _mcleanup(); #endif gdb_exit(cpu_env, arg1); + qemu_plugin_atexit_cb(); /* XXX: should free thread stack and CPU env */ _exit(arg1); ret = 0; /* avoid warning */ diff --git a/linux-user/exit.c b/linux-user/exit.c index bdda7205532..a362ef67d2c 100644 --- a/linux-user/exit.c +++ b/linux-user/exit.c @@ -35,4 +35,5 @@ void preexit_cleanup(CPUArchState *env, int code) __gcov_dump(); #endif gdb_exit(env, code); + qemu_plugin_atexit_cb(); } From patchwork Wed Jul 31 16:06:52 2019 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: 11068685 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 16CC8174A for ; Wed, 31 Jul 2019 16:25:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1BF9203B9 for ; Wed, 31 Jul 2019 16:25:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1C0B20453; Wed, 31 Jul 2019 16:25:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5CA4D203B9 for ; Wed, 31 Jul 2019 16:25:42 +0000 (UTC) Received: from localhost ([::1]:42670 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrQ5-0005Qw-Ly for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:25:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42438) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrG8-0005z5-Bz for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrG6-0004Ah-MS for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:24 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:38179) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrG6-00049j-FV for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:22 -0400 Received: by mail-wr1-x443.google.com with SMTP id g17so70335005wrr.5 for ; Wed, 31 Jul 2019 09:15:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w8IWQyMyO7sgKHvlJ76dzk+gbyQ37XPlBpRgrQD8Bqw=; b=qxKnLaeNmmmzxrwId9vmijktIDvFEnv1WhUhxd8kE+x6mKYsqEm++eb6cMpKTy3wNl Ka6YHugSJaHQrq9juihNRF5Z6Qhsky3B2nTqau8pWVczgRGJDRx+ba2AFu/o3YiX0VRR 7ouEF8Us034A0dkx2BrVL4joP9iNzAuTuCrAhqNo3gFqoWMEwfaIU9RX4CX5bVLvxTVT iyF1WkZmbJIV9JIuiWDEhpUL5cbIn4+WL/BRYkUNOPs2fe90FfEJQfRQdscOLuSHMxT9 PEr7MZDjLisJKuLMDihIfrIezoXBPy1+KcW2MEaAiOOF1jOY8Dh71C8HEgoUfbEt6fEI HyuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w8IWQyMyO7sgKHvlJ76dzk+gbyQ37XPlBpRgrQD8Bqw=; b=pk0Jf0yb4nh8lD0yXR0l97Er5Q60Noahnu2bGKYim72RkaDTgst2mfWtIgdTq3vH8I PMNPI61BPOB85pklbQC17crblB/vZKyl26w2GDNtMlN2tzRVSVLhUyHanxNIpv0Qt0GF Rj+JfNB5Dz4K6OFmS7B662umTK7kwz8i9EVoCO2zpVpeIp9U0yd29eF0edDN7gBa0ZvA mv4iURNC9ljx/w0aBCPyXey88iNwHgZ76lqFa5juKv7Tjc2X9c0FA0h3bzi1JwtPVbXT 5YSbiGG7iM9jsDW48COHQ8GoV5lnsMBbMDI+GJPd/MsVgsOJU4fGbcOIj4kYSZqpz6GA 6Vug== X-Gm-Message-State: APjAAAXwXtxB3LIJ9Z6689uOKitA/4ClDGuPPkw/p8mjDHoTA3Vkxgvi YLlpdjQeiQyCUiBAfohWHpQZj8oGzO8= X-Google-Smtp-Source: APXvYqzzl0ejljgPUBz1xLqkU38DNGBW/C8M7s+R4/087dZAFYV4IWR3jdHbM3cf2Z277PBBwq+OWg== X-Received: by 2002:a5d:4111:: with SMTP id l17mr12277924wrp.59.1564589721290; Wed, 31 Jul 2019 09:15:21 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id j16sm13522465wrp.62.2019.07.31.09.15.15 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:15:17 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 13F5B1FFAF; Wed, 31 Jul 2019 17:07:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:52 +0100 Message-Id: <20190731160719.11396-28-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [PATCH v4 27/54] *-user: plugin syscalls X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Richard Henderson , Laurent Vivier , aaron@os.amperecomputing.com, cota@braap.org, bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" To avoid too much duplication add a wrapper that the existing trace and the new plugin calls can live in. We could move the -strace code here as well but that is left for a future series as the code is subtly different between the bsd and linux. Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson [AJB: wrap in syscall-trace.h, expand commit msg] Signed-off-by: Alex Bennée --- bsd-user/syscall.c | 21 +++++++++++++------ include/user/syscall-trace.h | 40 ++++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 7 ++++--- 3 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 include/user/syscall-trace.h diff --git a/bsd-user/syscall.c b/bsd-user/syscall.c index 84a983a9a12..0d45b654bb3 100644 --- a/bsd-user/syscall.c +++ b/bsd-user/syscall.c @@ -26,6 +26,7 @@ #include "qemu.h" #include "qemu-common.h" +#include "user/syscall-trace.h" //#define DEBUG @@ -322,7 +323,8 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, #ifdef DEBUG gemu_log("freebsd syscall %d\n", num); #endif - trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + record_syscall_start(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0); + if(do_strace) print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); @@ -403,7 +405,8 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, #endif if (do_strace) print_freebsd_syscall_ret(num, ret); - trace_guest_user_syscall_ret(cpu, num, ret); + + record_syscall_return(cpu, num, ret); return ret; efault: ret = -TARGET_EFAULT; @@ -421,7 +424,9 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1, #ifdef DEBUG gemu_log("netbsd syscall %d\n", num); #endif - trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0); + + record_syscall_start(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0); + if(do_strace) print_netbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); @@ -479,7 +484,8 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1, #endif if (do_strace) print_netbsd_syscall_ret(num, ret); - trace_guest_user_syscall_ret(cpu, num, ret); + + record_syscall_return(cpu, num, ret); return ret; efault: ret = -TARGET_EFAULT; @@ -497,7 +503,9 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1, #ifdef DEBUG gemu_log("openbsd syscall %d\n", num); #endif - trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0); + + record_syscall_start(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0); + if(do_strace) print_openbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); @@ -555,7 +563,8 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1, #endif if (do_strace) print_openbsd_syscall_ret(num, ret); - trace_guest_user_syscall_ret(cpu, num, ret); + + record_syscall_return(cpu, num, ret); return ret; efault: ret = -TARGET_EFAULT; diff --git a/include/user/syscall-trace.h b/include/user/syscall-trace.h new file mode 100644 index 00000000000..9e604736433 --- /dev/null +++ b/include/user/syscall-trace.h @@ -0,0 +1,40 @@ +/* + * Common System Call Tracing Wrappers for *-user + * + * Copyright (c) 2019 Linaro + * Written by Alex Bennée + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef _SYSCALL_TRACE_H_ +#define _SYSCALL_TRACE_H_ + +/* + * These helpers just provide a common place for the various + * subsystems that want to track syscalls to put their hooks in. We + * could potentially unify the -strace code here as well. + */ + +static inline void record_syscall_start(void *cpu, int num, + abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4, + abi_long arg5, abi_long arg6, + abi_long arg7, abi_long arg8) +{ + trace_guest_user_syscall(cpu, num, + arg1, arg2, arg3, arg4, + arg5, arg6, arg7, arg8); + qemu_plugin_vcpu_syscall(cpu, num, + arg1, arg2, arg3, arg4, + arg5, arg6, arg7, arg8); +} + +static inline void record_syscall_return(void *cpu, int num, abi_long ret) +{ + trace_guest_user_syscall_ret(cpu, num, ret); + qemu_plugin_vcpu_syscall_ret(cpu, num, ret); +} + + +#endif /* _SYSCALL_TRACE_H_ */ diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 8367cb138df..9132f6d2663 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -109,6 +109,7 @@ #include "qemu.h" #include "qemu/guest-random.h" +#include "user/syscall-trace.h" #include "qapi/error.h" #include "fd-trans.h" @@ -11968,8 +11969,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, } #endif - trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, - arg5, arg6, arg7, arg8); + record_syscall_start(cpu, num, arg1, + arg2, arg3, arg4, arg5, arg6, arg7, arg8); if (unlikely(do_strace)) { print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); @@ -11981,6 +11982,6 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, arg5, arg6, arg7, arg8); } - trace_guest_user_syscall_ret(cpu, num, ret); + record_syscall_return(cpu, num, ret); return ret; } From patchwork Wed Jul 31 16:06:53 2019 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: 11068741 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2BE4912 for ; Wed, 31 Jul 2019 16:33:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE96221BED for ; Wed, 31 Jul 2019 16:33:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CDBFF223C7; Wed, 31 Jul 2019 16:33:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6EB6B21327 for ; Wed, 31 Jul 2019 16:33:06 +0000 (UTC) Received: from localhost ([::1]:42850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrXF-0005Zf-SN for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:33:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45267) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrPq-00059d-Hb for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrPp-0000PI-Gk for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:26 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:34321) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrPp-0000Om-9u for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:25 -0400 Received: by mail-wr1-x444.google.com with SMTP id 31so70406825wrm.1 for ; Wed, 31 Jul 2019 09:25:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NZPJc3zYVl2nOnmRetp03IWG86OpIb2lpqWUrvn/Bks=; b=lHZEjEKgtFtZ3MYo1QDovaqQEGDCTQU9V1WKGUbhfugZV/k2qg8DGVOHf2WZ4ruwf9 f9vi2n/WI2xOpMc6IBKsFtlKnzZomjLimL3kstT7tlPCiuI0HqFoNGm1LKm1JgVFUEvA zcJo3WxONnl8WAliaISdt0MCxqaVYed9I/fiDb6aR9DJWggCjELVwkCEWC4O2LZfQzN4 wCe9BiseZvPOPHqiaipcuAtozt1eXxXzJCck+OzNpLAbyTLCBjbcJkssgJ0nMArld9fM rj3bPEc4BvHWOYcMnxZXxayuwUgWKgqxO/fEHzTTne5XkdxizVc/5SXoo2DK6N343PLc CYbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NZPJc3zYVl2nOnmRetp03IWG86OpIb2lpqWUrvn/Bks=; b=aFerla8RHXJAzHS58xXtPCOXJ388EV1HTTOjOKjQ6oActuTIXA65Ur8Pj+t1BxHKKP T3aP19xh1HqvjZN6xpDU5X/X+SDDU7+HtQ7I+LaUWniEpXTqLQcEW99HUAEU34AKY3M+ osMrnNGj9jYgvsH2XR6ZjLTXNbc7BpDzmXHDYfZ/KIS/Uvo+N7+38Os1kDKEow3UpHwC gqUVDCd47JMxNVpqgMIyFjm0cW25JPEvGSv4BChSPTp++Xpdq6q5cMA1AnPIwCRHjvSu bkJHRSq7KUa5q7DGn7HNuNJenj3egs+c4H41zEQIi6+hdoGy/Jzs7A/Stc9X7A4K0JtE Wmdg== X-Gm-Message-State: APjAAAV+3ZE69u1pXt+KtimZAH+zfdKVn1hEFRZnUuw9eLRnh93ZOr3F 0NCt5tbd3lvmB48CYZK9VFw0Ug== X-Google-Smtp-Source: APXvYqzBTEH4lk4w9QsZyu+x5cZzGeG4LKxuI5fKhOpCRit1RzuzDYJJbd8+vH08DKaoa61fUXcdwA== X-Received: by 2002:a5d:4cca:: with SMTP id c10mr129112522wrt.233.1564590324261; Wed, 31 Jul 2019 09:25:24 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id l17sm47513161wrr.94.2019.07.31.09.25.17 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:25:22 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 2CB3E1FFB1; Wed, 31 Jul 2019 17:07:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:53 +0100 Message-Id: <20190731160719.11396-29-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH v4 28/54] cpu: hook plugin vcpu events X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Richard Henderson , aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- cpus.c | 10 ++++++++++ exec.c | 2 ++ qom/cpu.c | 2 ++ 3 files changed, 14 insertions(+) diff --git a/cpus.c b/cpus.c index 927a00aa90b..cef94560e31 100644 --- a/cpus.c +++ b/cpus.c @@ -44,6 +44,7 @@ #include "exec/exec-all.h" #include "qemu/thread.h" +#include "qemu/plugin.h" #include "sysemu/cpus.h" #include "sysemu/qtest.h" #include "qemu/main-loop.h" @@ -1241,9 +1242,18 @@ static void qemu_tcg_rr_wait_io_event(void) static void qemu_wait_io_event(CPUState *cpu) { + bool slept = false; + while (cpu_thread_is_idle(cpu)) { + if (!slept) { + slept = true; + qemu_plugin_vcpu_idle_cb(cpu); + } qemu_cond_wait(cpu->halt_cond, &qemu_global_mutex); } + if (slept) { + qemu_plugin_vcpu_resume_cb(cpu); + } #ifdef _WIN32 /* Eat dummy APC queued by qemu_cpu_kick_thread. */ diff --git a/exec.c b/exec.c index 3e78de3b8f8..65374d0bdc8 100644 --- a/exec.c +++ b/exec.c @@ -974,6 +974,8 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp) } tlb_init(cpu); + qemu_plugin_vcpu_init_hook(cpu); + #ifndef CONFIG_USER_ONLY if (qdev_get_vmsd(DEVICE(cpu)) == NULL) { vmstate_register(NULL, cpu->cpu_index, &vmstate_cpu_common, cpu); diff --git a/qom/cpu.c b/qom/cpu.c index f376f782d83..90ebb214bb2 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -33,6 +33,7 @@ #include "hw/boards.h" #include "hw/qdev-properties.h" #include "trace-root.h" +#include "qemu/plugin.h" CPUInterruptHandler cpu_interrupt_handler; @@ -354,6 +355,7 @@ static void cpu_common_unrealizefn(DeviceState *dev, Error **errp) CPUState *cpu = CPU(dev); /* NOTE: latest generic point before the cpu is fully unrealized */ trace_fini_vcpu(cpu); + qemu_plugin_vcpu_exit_hook(cpu); cpu_exec_unrealizefn(cpu); } From patchwork Wed Jul 31 16:06:54 2019 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: 11068621 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 09E1E1395 for ; Wed, 31 Jul 2019 16:15:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA72320008 for ; Wed, 31 Jul 2019 16:15:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE410200DF; Wed, 31 Jul 2019 16:15:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8A78420008 for ; Wed, 31 Jul 2019 16:15:33 +0000 (UTC) Received: from localhost ([::1]:42428 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrGG-0006Sq-UB for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:15:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40375) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsr8h-00027w-GZ for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsr8f-0000lE-5T for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:43 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:33613) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsr8e-0000hn-Cz for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:40 -0400 Received: by mail-wr1-x441.google.com with SMTP id n9so70407051wru.0 for ; Wed, 31 Jul 2019 09:07:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GmxoVYqSi+9b817kRDEMuLT6apMjPTB3tafVvwHS5rQ=; b=sM5s12xnGTDAcJgriEAPd069+NsIoDM75HbkFazGQOGkmgQqIwCwYuOK6xz7Mx0Bc+ tnduWy/ebK0pTGdAUfXJI7Af8UmnpPh7XWo31loVDo7GHj2e5psthcg0ImmtlQc0bHBM OgprmpnjWiYaXLzgE1c6qNoyEzbQDZy97uRU32bPK4Iz3My1YgT0UZxqUDGvXNW85sZx frZI5pCnO5cfNWUsfWymNM+HpC4RWS9PUvRPpX3VjBLcNfowFNmwHcxElcprI+g92vqE yY5rwUX9R3Ns0ItyvdCoPAH8uQkwzJ9v/LeIIWTG380fCGP2aqU8D7NhuVHHjwWjCk8X rAIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GmxoVYqSi+9b817kRDEMuLT6apMjPTB3tafVvwHS5rQ=; b=MtN8gTxikcS7PtDQdtx/z5UdyT3SNxBQZNe/WC+0hA9/J/el48w2CgPWesjRZC3aED R6Zdoq4pch4GvFD7C4RwdCKjWRkxv3X8dkeYlN1NiiFKZn89wIKu5ZMpRBbxonufwVyQ Gj3J4GaKgRgesXKqbY/QxLanOUly6cyGSfwPerwGIGf4+6rNC7MkAfe/KdFixvQHiDKH e+B0akv3ilSvGvyGXwMX1A9CBvu2idUZZdaMeMlqJIgEiBJqsPDW8EfaYEcYowWyV8DS eRjQOClNVSHmwva1SCCJ7hm1WuspnDv74A/tAZ7req+yfagcX1FXYQnua1n+iW8GW/+/ pi7A== X-Gm-Message-State: APjAAAXyXoTCD73M56OqzUl97Hf2cJpg+btyGOrtFqtpY7AzbvnQyTAw EvAsLDa0v/GohBUpy+qfYwyaPQ== X-Google-Smtp-Source: APXvYqzonY00aribchdiGNrDW2Cz73vIuscEhJItbN2oO6pAbM7yKq/zagDIfkyUJfN42RQ4q1WfPg== X-Received: by 2002:adf:f646:: with SMTP id x6mr143350740wrp.18.1564589252615; Wed, 31 Jul 2019 09:07:32 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id z1sm72144165wrp.51.2019.07.31.09.07.25 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:07:31 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 419831FFB3; Wed, 31 Jul 2019 17:07:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:54 +0100 Message-Id: <20190731160719.11396-30-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PATCH v4 29/54] plugin-gen: add plugin_insn_append X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bobby.prani@gmail.com, cota@braap.org, =?utf-8?q?Alex_Benn=C3=A9e?= , aaron@os.amperecomputing.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" By adding it to plugin-gen's header file, we can export is as an inline, since tcg.h is included in the header (we need tcg_ctx). Signed-off-by: Emilio G. Cota [AJB: use g_byte_array] Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v3 - use g_byte_array --- include/exec/plugin-gen.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/exec/plugin-gen.h b/include/exec/plugin-gen.h index de519883b16..4834a9e2f40 100644 --- a/include/exec/plugin-gen.h +++ b/include/exec/plugin-gen.h @@ -27,6 +27,17 @@ void plugin_gen_insn_end(void); void plugin_gen_disable_mem_helpers(void); void plugin_gen_empty_mem_callback(TCGv addr, uint32_t info); +static inline void plugin_insn_append(const void *from, size_t size) +{ + struct qemu_plugin_insn *insn = tcg_ctx->plugin_insn; + + if (insn == NULL) { + return; + } + + insn->data = g_byte_array_append(insn->data, from, size); +} + #else /* !CONFIG_PLUGIN */ static inline @@ -51,6 +62,9 @@ static inline void plugin_gen_disable_mem_helpers(void) static inline void plugin_gen_empty_mem_callback(TCGv addr, uint32_t info) { } +static inline void plugin_insn_append(const void *from, size_t size) +{ } + #endif /* CONFIG_PLUGIN */ #endif /* QEMU_PLUGIN_GEN_H */ From patchwork Wed Jul 31 16:06:55 2019 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: 11068661 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B7F0B13AC for ; Wed, 31 Jul 2019 16:21:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A360020182 for ; Wed, 31 Jul 2019 16:21:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97498201B1; Wed, 31 Jul 2019 16:21:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 17C052018F for ; Wed, 31 Jul 2019 16:21:23 +0000 (UTC) Received: from localhost ([::1]:42544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrLu-0002Wj-F4 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:21:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42403) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrG7-0005w8-Mh for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrG5-00049K-Nd for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:23 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:33697) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrG1-00046g-Qo for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:19 -0400 Received: by mail-wr1-x442.google.com with SMTP id n9so70436154wru.0 for ; Wed, 31 Jul 2019 09:15:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wNexri908PTiPWm1XMgESUAKCJc8K1I1ZWLPF6fkVnU=; b=Dvqjhk3Whwr8YN8/XkYURjnj4DWkrCi0NowTwwgxYkqW4060jU1KZZsC2IN1B4kkpm TOxOYFy+sFzJaf/rLKBoA0WvXzow82jIuz304gOpvApHbPrUjWJmF+sXsi/dPIyRQR89 B8yEYtGDEL2+BUDhSbPXWI/vqIEtpNizPeD/a4P1F9Y/Rz95xhfQPTS/LiNqsb3iRnRu RgN9mNAyhQ91EG15Ytx89ylQZxs6dDg9liPjtVrWMfWhCNQEocu3Mkwl5iXIp/Y/obtB wiaxaJwadnPQDpsBrNq4Ju20tg9xNExnNHdmF68NOPAfIkNIi81AruurYcgcEabw1ID9 X/Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wNexri908PTiPWm1XMgESUAKCJc8K1I1ZWLPF6fkVnU=; b=leUzcjLsJSS2/2KLNrZGvinw1Aa0xAr6l8mVeYJntEVjkOI3+GrTkIgiAPAikIc2Pw SUuiUBqAnt3L+UTIBw8YLPC9w7dr1XXlcgoXDDiDJ1Yw+wgm+wmgOta9N82ElY2Fpv4r g5HbDzM9ebwJMN0YXjbUA/gWmCC4Jd/DC1kQSN/HC0BqquEkWH3BjbKtwb0bTvqAp8Be Cd8iYN6iuvy6Vji6AplJNaq3CpDRxpZVaA4QY+1S0AKFiCzdYS9Tjx5edC2yqE+/k7J/ AHSkvcCaQ3jRFoazPuycpw1FrDhzZLIBQiKLkIENL5NOnC5xKpgXhSW/mbBzNzebIAth KYRA== X-Gm-Message-State: APjAAAUUzg5MdUEFdzdXdhN+/mGa/fNLpT8gQ0K/QRFVZg/jQnBc3cbl b2QvJM7jv8Ef0eXa3MeroyXGfA== X-Google-Smtp-Source: APXvYqy8k1e8wQ6s4CapOQFYxk5nty4PAj1rYhjZFNGeTNWMzpJFxo4aI+qyuFM54HBFeCZZcIlG+Q== X-Received: by 2002:adf:80e1:: with SMTP id 88mr48054009wrl.127.1564589716736; Wed, 31 Jul 2019 09:15:16 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id r11sm107266157wre.14.2019.07.31.09.15.13 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:15:14 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 5A32A1FFB4; Wed, 31 Jul 2019 17:07:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:55 +0100 Message-Id: <20190731160719.11396-31-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PATCH v4 30/54] translator: add translator_ld{ub, sw, uw, l, q} X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Suggested-by: Richard Henderson Signed-off-by: Emilio G. Cota [AJB: directly plumb into softmmu/user helpers] Signed-off-by: Alex Bennée --- v4 - don't use the cpu_ldst helpers, plumb directly into the lower level - mark the CODE_ACCESS/SOFTMMU_CODE_ACCESS as deprecated --- include/exec/cpu_ldst.h | 11 ++++++++ include/exec/translator.h | 58 ++++++++++++++++++++++++++++++++++++++- include/qemu/bswap.h | 5 ++++ tcg/tcg.h | 2 ++ 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h index 9151fdb042c..fd499f7e2ff 100644 --- a/include/exec/cpu_ldst.h +++ b/include/exec/cpu_ldst.h @@ -129,6 +129,11 @@ static inline void clear_helper_retaddr(void) #include "exec/cpu_ldst_useronly_template.h" #undef MEMSUFFIX +/* + * Code access is deprecated in favour of translator_ld* functions + * (see translator.h). However there are still users that need to + * converted so for now these stay. + */ #define MEMSUFFIX _code #define CODE_ACCESS #define DATA_SIZE 1 @@ -427,6 +432,12 @@ static inline CPUTLBEntry *tlb_entry(CPUArchState *env, uintptr_t mmu_idx, #undef CPU_MMU_INDEX #undef MEMSUFFIX +/* + * Code access is deprecated in favour of translator_ld* functions + * (see translator.h). However there are still users that need to + * converted so for now these stay. + */ + #define CPU_MMU_INDEX (cpu_mmu_index(env, true)) #define MEMSUFFIX _code #define SOFTMMU_CODE_ACCESS diff --git a/include/exec/translator.h b/include/exec/translator.h index 180c51d5092..30b1a594fc1 100644 --- a/include/exec/translator.h +++ b/include/exec/translator.h @@ -19,7 +19,10 @@ */ +#include "qemu/bswap.h" #include "exec/exec-all.h" +#include "exec/cpu_ldst.h" +#include "exec/plugin-gen.h" #include "tcg/tcg.h" @@ -142,4 +145,57 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, void translator_loop_temp_check(DisasContextBase *db); -#endif /* EXEC__TRANSLATOR_H */ +/* + * Translator Load Functions + * + * These are intended to replace the old cpu_ld*_code functions and + * are mandatory for front-ends that have been migrated to the common + * translator_loop. These functions are only intended to be called + * from the translation stage and should not be called from helper + * functions. Those functions should be converted to encode the + * relevant at translation time. + */ + +#ifdef CONFIG_USER_ONLY + +#define DO_LOAD(type, name, shift) \ + set_helper_retaddr(1); \ + ret = name ## _p(g2h(pc)); \ + clear_helper_retaddr(); + +#else + +#define DO_LOAD(type, name, shift) \ + int mmu_idx = cpu_mmu_index(env, true); \ + TCGMemOpIdx oi = make_memop_idx(shift, mmu_idx); \ + ret = helper_ret_ ## name ## _cmmu(env, pc, oi, 0); + +#endif + +#define GEN_TRANSLATOR_LD(fullname, name, type, shift, swap_fn) \ + static inline type \ + fullname ## _swap(CPUArchState *env, abi_ptr pc, bool do_swap) \ + { \ + type ret; \ + DO_LOAD(type, name, shift) \ + \ + if (do_swap) { \ + ret = swap_fn(ret); \ + } \ + plugin_insn_append(&ret, sizeof(ret)); \ + return ret; \ + } \ + \ + static inline type fullname(CPUArchState *env, abi_ptr pc) \ + { \ + return fullname ## _swap(env, pc, false); \ + } + +GEN_TRANSLATOR_LD(translator_ldub, ldb, uint8_t, 1, /* no swap needed */) +GEN_TRANSLATOR_LD(translator_ldsw, lduw, int16_t, 2, bswap16) +GEN_TRANSLATOR_LD(translator_lduw, lduw, uint16_t, 2, bswap16) +GEN_TRANSLATOR_LD(translator_ldl, ldl, uint32_t, 3, bswap32) +GEN_TRANSLATOR_LD(translator_ldq, ldq, uint64_t, 4, bswap64) +#undef GEN_TRANSLATOR_LD + +#endif /* EXEC__TRANSLATOR_H */ diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h index 2a9f3fe783e..4f707278740 100644 --- a/include/qemu/bswap.h +++ b/include/qemu/bswap.h @@ -306,6 +306,11 @@ static inline int ldub_p(const void *ptr) return *(uint8_t *)ptr; } +static inline int ldb_p(const void *ptr) +{ + return ldub_p(ptr); +} + static inline int ldsb_p(const void *ptr) { return *(int8_t *)ptr; diff --git a/tcg/tcg.h b/tcg/tcg.h index 93f52f4ca93..c918fdd87c4 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -1404,6 +1404,7 @@ uint64_t helper_be_ldq_cmmu(CPUArchState *env, target_ulong addr, # define helper_ret_stl_mmu helper_be_stl_mmu # define helper_ret_stq_mmu helper_be_stq_mmu # define helper_ret_ldw_cmmu helper_be_ldw_cmmu +# define helper_ret_lduw_cmmu helper_be_ldw_cmmu # define helper_ret_ldl_cmmu helper_be_ldl_cmmu # define helper_ret_ldq_cmmu helper_be_ldq_cmmu #else @@ -1417,6 +1418,7 @@ uint64_t helper_be_ldq_cmmu(CPUArchState *env, target_ulong addr, # define helper_ret_stl_mmu helper_le_stl_mmu # define helper_ret_stq_mmu helper_le_stq_mmu # define helper_ret_ldw_cmmu helper_le_ldw_cmmu +# define helper_ret_lduw_cmmu helper_le_ldw_cmmu # define helper_ret_ldl_cmmu helper_le_ldl_cmmu # define helper_ret_ldq_cmmu helper_le_ldq_cmmu #endif From patchwork Wed Jul 31 16:06:56 2019 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: 11068657 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D034912 for ; Wed, 31 Jul 2019 16:20:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9AE11FFFF for ; Wed, 31 Jul 2019 16:20:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCE49200CB; Wed, 31 Jul 2019 16:20:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8025E1FFFF for ; Wed, 31 Jul 2019 16:20:37 +0000 (UTC) Received: from localhost ([::1]:42520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrLA-0000Ih-Pw for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:20:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42390) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrG7-0005uW-8e for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrG6-0004A0-1m for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:23 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:53508) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrG5-00047H-Q6 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:21 -0400 Received: by mail-wm1-x344.google.com with SMTP id x15so61472968wmj.3 for ; Wed, 31 Jul 2019 09:15:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TwsNXkTsHTv8y1ITkoQ5QIXyXHIc1coCol9uilfBzDM=; b=ApKufer1ZmNFvz+1aMwTxRKO9pQL6ZDR3EM5lxC6cKVhXLgL10LatRlQGd+EOt+pL0 Vfq6Y3DikqFLXLa4LOuvxZQSI4NEL1U2tG8odekY24u/s7SZ8jZYaitFdKiH7mvGlLYI d2tSWlgoY21T0+CXJiEosDttlzv24VDzJElrNv3TaOBOtstJzL0CqW3rnboNH8Q+XB0V zQ2zr9LPan0SOg0jRtVzuBkasLOBnoWrL2BKqvaAyo/Aq4qtRGB+ct2ue9Z3UR+ECg9k /yZ5THI5hlQvy7zCTPob5jLgsCa/JWIDKAGNtkGd2+EBJuggayHrZ+czjqiu8DpECMf0 bKyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TwsNXkTsHTv8y1ITkoQ5QIXyXHIc1coCol9uilfBzDM=; b=LK7rgTfoKCKhXAR/CSlxw5Ud0WgPkOCUZhSE/p1jQ2XfNpOh8/UWpcm7Rtm6GqEm3o 3TnH7DMenElTDucuHyFozmigZ7leRXgfZHI58bTqP5mZt9SKHeXTNuNWNaVYo/URsWiu c608W7scABT5G/WXShA7Wo6FSfv2YUiqKkEEX2D0nEUWWb8wc5MT4arj5D27IaTOOknk 7ExXwcNgFC2rs1xl5GaiDkTPZL5pmJY+stSM1XCONCLqP0ToGqu26QB4j9ZVA0UKuOXL QAB9Mf+L6umti3nSmlG7iClhQBDv/ECS1rCW5l3UqzSJb2rimrkUDfvobS+d2UZQBofF XVSA== X-Gm-Message-State: APjAAAUpk3qhTt8qFsxQolH6cklOLULGeWxdzEviX070/1AAGAqkTAEi +i2zbZG3YJZhSQYKfpeozbVBXw== X-Google-Smtp-Source: APXvYqwlsnN3B64lkx7YjD8MjHOEzJBHHB263RewdHibl9X2zGzGIj8+FhBugarytxweyWBP60SG1w== X-Received: by 2002:a1c:7e14:: with SMTP id z20mr108780131wmc.83.1564589717279; Wed, 31 Jul 2019 09:15:17 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id t63sm62639657wmt.6.2019.07.31.09.15.13 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:15:14 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 6FCE71FFB5; Wed, 31 Jul 2019 17:07:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:56 +0100 Message-Id: <20190731160719.11396-32-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 Subject: [Qemu-devel] [PATCH v4 31/54] target/arm: fetch code with translator_ld X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , aaron@os.amperecomputing.com, cota@braap.org, "open list:ARM TCG CPUs" , bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Now the arm_ld*_code functions are only used at translate time we can just pass down to translator_ld functions. Signed-off-by: Emilio G. Cota [AJB: convert from plugin_insn_append to translator_ld] Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v4 - use translator_ld like the rest of them --- target/arm/arm_ldst.h | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/target/arm/arm_ldst.h b/target/arm/arm_ldst.h index 5e0ac8bef06..45edb108f6a 100644 --- a/target/arm/arm_ldst.h +++ b/target/arm/arm_ldst.h @@ -20,25 +20,20 @@ #ifndef ARM_LDST_H #define ARM_LDST_H -#include "exec/cpu_ldst.h" +#include "exec/translator.h" #include "qemu/bswap.h" /* Load an instruction and return it in the standard little-endian order */ static inline uint32_t arm_ldl_code(CPUARMState *env, target_ulong addr, bool sctlr_b) { - uint32_t insn = cpu_ldl_code(env, addr); - if (bswap_code(sctlr_b)) { - return bswap32(insn); - } - return insn; + return translator_ldl_swap(env, addr, bswap_code(sctlr_b)); } /* Ditto, for a halfword (Thumb) instruction */ static inline uint16_t arm_lduw_code(CPUARMState *env, target_ulong addr, bool sctlr_b) { - uint16_t insn; #ifndef CONFIG_USER_ONLY /* In big-endian (BE32) mode, adjacent Thumb instructions have been swapped within each word. Undo that now. */ @@ -46,11 +41,7 @@ static inline uint16_t arm_lduw_code(CPUARMState *env, target_ulong addr, addr ^= 2; } #endif - insn = cpu_lduw_code(env, addr); - if (bswap_code(sctlr_b)) { - return bswap16(insn); - } - return insn; + return translator_lduw_swap(env, addr, bswap_code(sctlr_b)); } #endif From patchwork Wed Jul 31 16:06:57 2019 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: 11068773 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9B58A13AC for ; Wed, 31 Jul 2019 16:45:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A366280B0 for ; Wed, 31 Jul 2019 16:45:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EBB728179; Wed, 31 Jul 2019 16:45:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2B3E0280B0 for ; Wed, 31 Jul 2019 16:45:53 +0000 (UTC) Received: from localhost ([::1]:42998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrjc-00031j-Dl for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:45:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51235) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrj4-0001hJ-Pr for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:45:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrj3-0000sW-Qv for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:45:18 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:45347) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrj3-0000rs-JG for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:45:17 -0400 Received: by mail-wr1-x442.google.com with SMTP id f9so70417107wre.12 for ; Wed, 31 Jul 2019 09:45:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VKH7CA7PvW2n45iUTxcQG9XbQH7DlhtsC6UTV58NGHI=; b=QvmF5A8nk+b7B8r2io9vc5yx9XNz7bu5ezc1cTjG86E9KJs2H4TnSJLPsFZ2Khn2Id x19PMcbMMn/nZmRy4Lm3rtwqmyfllTW910BgUrTx/ouRApFlO9b+4ji5weNjGhLQy5uf 1qGs4+p/9hLEIAAjQ2yyCmcTAvQNJMBLTnZFWo5hHkRFJSzXQ79H3rIbPcLnngMVfhAv J4UjjrL4oI14F0xVALOM0EAZm7vgDfQxm1PkoIL7AxnYapxwQ9KImbFrb90mkcGKTNOD paRDFylBxMVkuOuYnJGPRTq8Yx5FosZacR7NB1fqoeu9P9yw7b6/EcfIuY//WYskNqVY bgeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VKH7CA7PvW2n45iUTxcQG9XbQH7DlhtsC6UTV58NGHI=; b=jDDHUIqChl1Kz88t/YK+NZjSyLaPyJmBhYE2jBLdekRmWUVgNiWwk8v0ipiAReZ+u+ NFRKJIg/fPbfM4FrPZ9Ms7yEnTANNgNrvdtCl6iGEswRgkRR8DIk6qhVbf88nP50UqP3 nQe6RTVYc49DFDNDGIxxkOrNrMFCtPip0zLsOHDe5VPWXZVF8jnmwjJhc8hqZCvhdNd1 S4+NYk60uNbu7C9H332X3+b/KUM8elGzVwJDZXrWRrt+VCyncEO2lovY5IFBDNFO0cN9 kMxnhIT7b7gG8y7Ovz/KuyNb4Oj3UItZvqqBQQvISK+psb+90dp6UrGx3JXO/In3gG47 phJA== X-Gm-Message-State: APjAAAVw8b+yBy6Lv+n/mthynX/P5xctWs/aGn8r0qyoMNuPxzXaRf2g SF4GS4PPxZz9D5mKYHELfpxOag== X-Google-Smtp-Source: APXvYqyz6kp4bWBu1Hw4PPAi8ROKnT/KUyLqECUC0sLfP60Oe2U1VqGkVc+hXidiO4TR6B1tXiVkFw== X-Received: by 2002:a5d:630c:: with SMTP id i12mr47735850wru.312.1564591516472; Wed, 31 Jul 2019 09:45:16 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id q10sm70580250wrf.32.2019.07.31.09.45.13 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:45:13 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 82ED21FF90; Wed, 31 Jul 2019 17:07:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:57 +0100 Message-Id: <20190731160719.11396-33-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PATCH v4 32/54] target/ppc: fetch code with translator_ld X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , aaron@os.amperecomputing.com, cota@braap.org, "open list:PowerPC TCG CPUs" , bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , David Gibson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Acked-by: David Gibson Signed-off-by: Alex Bennée --- target/ppc/translate.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 4a5de280365..a27b5659f46 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -7864,11 +7864,9 @@ static void ppc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n", ctx->base.pc_next, ctx->mem_idx, (int)msr_ir); - if (unlikely(need_byteswap(ctx))) { - ctx->opcode = bswap32(cpu_ldl_code(env, ctx->base.pc_next)); - } else { - ctx->opcode = cpu_ldl_code(env, ctx->base.pc_next); - } + ctx->opcode = translator_ldl_swap(env, ctx->base.pc_next, + need_byteswap(ctx)); + LOG_DISAS("translate opcode %08x (%02x %02x %02x %02x) (%s)\n", ctx->opcode, opc1(ctx->opcode), opc2(ctx->opcode), opc3(ctx->opcode), opc4(ctx->opcode), From patchwork Wed Jul 31 16:06:58 2019 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: 11068645 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 19AAB912 for ; Wed, 31 Jul 2019 16:18:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06A4E1FE8D for ; Wed, 31 Jul 2019 16:18:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF0AD1FFCD; Wed, 31 Jul 2019 16:18:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 913981FE8D for ; Wed, 31 Jul 2019 16:18:15 +0000 (UTC) Received: from localhost ([::1]:42480 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrIs-0003fW-Vm for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:18:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42321) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrG5-0005pG-Nm for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrG1-00046y-OD for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:19 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:42575) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrFz-00045S-RN for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:17 -0400 Received: by mail-wr1-x442.google.com with SMTP id x1so20432580wrr.9 for ; Wed, 31 Jul 2019 09:15:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iZ2OY4t64w/OXbcRBQzkejkLpoLwcOyY1K+BIeISZRQ=; b=B8WF5kedwnmAyRbmvR5+KcOT2SJ+DR9KN1Rk8JrBbkevCjGkGOP8We/aCgdcDSkznJ GUKA5PMbnAscXFKm1Vb7eiApdJLh5uLHbp+JVMhyyrusk/Cv74O57XHXQs+5KBaMunkg P71HaeE9m5+2tXegJwC+uz5tdYOv59P9UOCmUsFaPXz7uIOGL+GlFqzZ+OD4sBOF7NuB 9c6cKCPchYRIAPd/1yfAbZ7/yj2xChydosq5blidQYKl9rP6yLHpnM+B8hFl6s6FCyp8 Mt9IqDZGH/QeUDuXTqd4vJ3H5djZkeUbth6QdcLE4PpsoqobCQJx3xwYyFCBuwAWh5W9 zGcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iZ2OY4t64w/OXbcRBQzkejkLpoLwcOyY1K+BIeISZRQ=; b=Q+3gHBRAY6Clp0HDpJhoTT3qIw9RPu1LJFvvwM8lMjYOE1PzEFBCfRyhsOc9xxuETK 9GDFaNy+uVvQvF9weLVjO9tTUW+uaTlg70ldbp60uNlUbc3QH7T61kYx701LXe3lMF01 kdx4xbj7NImE+SC9Sm44U0/wYFyAO1dIN8yeAjdYDU62pH8ffpnN328XwDPYjhoIYWwq zs0fh1QIrIo5YGCp//0Z+C3yVDxGrTlxraB/qqciICFXgpQvAe+bmA8F/0H3ixvxRivK kRYcQvhTY4TaUZYC6GXDfTBBMYe1iPrY7saj9lCqU5/72n6IuDcnqnOWI7U96GM5DSnl OgEQ== X-Gm-Message-State: APjAAAUl2q+epd86VSwvnN+4M2rq6O4R9GqSemw0IBw0IeikyOFzvnkb bL3Yw1Refit0w8Qe3S57OP6rSg== X-Google-Smtp-Source: APXvYqzh/tJtxvypzwg9UvgvObuGjOdn0JpB/DskkMRxmqumBUmYh2tbqyKu3J7yZT/wor2/Rt2Qig== X-Received: by 2002:adf:91c2:: with SMTP id 60mr81069472wri.334.1564589713784; Wed, 31 Jul 2019 09:15:13 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id g2sm59980886wmh.0.2019.07.31.09.15.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:15:12 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 9726F1FFB7; Wed, 31 Jul 2019 17:07:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:58 +0100 Message-Id: <20190731160719.11396-34-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PATCH v4 33/54] target/sh4: fetch code with translator_ld X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , aaron@os.amperecomputing.com, cota@braap.org, bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Aurelien Jarno Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" There is a small wrinkle with the gUSA instruction. The translator effectively treats a (known) gUSA sequence as a single instruction. For the purposes of the plugin we end up with a long multi-instruction qemu_plugin_insn. If the known sequence isn't detected we shall never run this translation anyway. Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- target/sh4/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/sh4/translate.c b/target/sh4/translate.c index 5a7d8c45355..922785e225e 100644 --- a/target/sh4/translate.c +++ b/target/sh4/translate.c @@ -1917,7 +1917,7 @@ static void decode_gusa(DisasContext *ctx, CPUSH4State *env) /* Read all of the insns for the region. */ for (i = 0; i < max_insns; ++i) { - insns[i] = cpu_lduw_code(env, pc + i * 2); + insns[i] = translator_lduw(env, pc + i * 2); } ld_adr = ld_dst = ld_mop = -1; @@ -2332,7 +2332,7 @@ static void sh4_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) } #endif - ctx->opcode = cpu_lduw_code(env, ctx->base.pc_next); + ctx->opcode = translator_lduw(env, ctx->base.pc_next); decode_opc(ctx); ctx->base.pc_next += 2; } From patchwork Wed Jul 31 16:06:59 2019 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: 11068715 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 708E9912 for ; Wed, 31 Jul 2019 16:28:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D0E32012F for ; Wed, 31 Jul 2019 16:28:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 515D920415; Wed, 31 Jul 2019 16:28:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F07C52012F for ; Wed, 31 Jul 2019 16:28:55 +0000 (UTC) Received: from localhost ([::1]:42774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrTD-0006IL-B6 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:28:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45130) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrPk-0004rI-0o for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrPi-0000K1-VX for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:19 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:42668) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrPi-0000Iz-Ol for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:18 -0400 Received: by mail-wr1-x441.google.com with SMTP id x1so20468004wrr.9 for ; Wed, 31 Jul 2019 09:25:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6rBgm6yeoP4dSiIy9CSawJxQKN5hehrRgPjAazWUJvg=; b=OJr6W4aF4LvhNjVK1hCkkFmZgQP9e6wbXNdnO2MZgZNyOxXhAqYS/K3wI0s8Hbk2Fs jCzUZPw78pbnnlsENV3YB11PuFHzD8Zoy0NkQbrhFPYQcWYuWM5q31jqzYkyFk9ca3yc SqcF0OBDS/ig7Xp7ygtGafRlNYgmPXrHhLFAnE/Iu0NtIU4VjzGV5qFeJBev0GkAOK4l g1K3/PhKuLvpETKpjarTWRKavoEFmuG/iLMsxW4nAqsS9/+eTpAeQtYInZ7vmjtxCJqe lmriFRRCvS4cvAixFDvsryIG4MRI6JBa0mipU3Ku2ffUrvD/6WF7itExGt5zf3CCa7jb vHXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6rBgm6yeoP4dSiIy9CSawJxQKN5hehrRgPjAazWUJvg=; b=lg6xwmIFfJo1IuWiHByfUtDxgSZbSqlByEVBuqjgjV2/OGnj5Gt737XaKZO28uYGxQ LdhBzWkNQAC5Qnk9cgtdWSi8BeSExHfKXYBY8Pg0rWMxCqVzd7u6hjSYSZUtUuvV3mN+ G7nGOnquXNEr1eamBcZFqNemA15fZ/x2TOYVtDtP4nnBxArzFNYAWRHQZj6DrpkvMqeW dTUwfyD4aK+r/upa3VKLxR4mipkTNSBjyPNtKrfReMKA/D4rU7GCOl4GHoI27dfTIU6E wXhPmMlY9Ef6VdmmzOOQ5mqN0qGnKlKh5XXqsVjeYCMgwGjk4Yw4utNSTtWgA59iAmc8 zcpw== X-Gm-Message-State: APjAAAVNzs84L9xPSilTwKENpu2X5TAIT3XTEAAdurI/yhJBKQw6Q4Mx p2YU/ouPBPxP3AAhCchLylwYTpkwQJQ= X-Google-Smtp-Source: APXvYqwxDYOiTdll1q5kYxnUFXr+mgD1tt3VhB701NmMYKXG0o9Oy+E4itq9UKqE9MQtWwMXvO7xVA== X-Received: by 2002:adf:eb0f:: with SMTP id s15mr58680526wrn.324.1564590317693; Wed, 31 Jul 2019 09:25:17 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id t63sm62676709wmt.6.2019.07.31.09.25.13 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:25:15 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id AB41D1FFB8; Wed, 31 Jul 2019 17:07:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:59 +0100 Message-Id: <20190731160719.11396-35-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PATCH v4 34/54] target/i386: fetch code with translator_ld X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Richard Henderson , aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- target/i386/translate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/target/i386/translate.c b/target/i386/translate.c index 03150a86e23..bf4cd875aba 100644 --- a/target/i386/translate.c +++ b/target/i386/translate.c @@ -1925,28 +1925,28 @@ static uint64_t advance_pc(CPUX86State *env, DisasContext *s, int num_bytes) static inline uint8_t x86_ldub_code(CPUX86State *env, DisasContext *s) { - return cpu_ldub_code(env, advance_pc(env, s, 1)); + return translator_ldub(env, advance_pc(env, s, 1)); } static inline int16_t x86_ldsw_code(CPUX86State *env, DisasContext *s) { - return cpu_ldsw_code(env, advance_pc(env, s, 2)); + return translator_ldsw(env, advance_pc(env, s, 2)); } static inline uint16_t x86_lduw_code(CPUX86State *env, DisasContext *s) { - return cpu_lduw_code(env, advance_pc(env, s, 2)); + return translator_lduw(env, advance_pc(env, s, 2)); } static inline uint32_t x86_ldl_code(CPUX86State *env, DisasContext *s) { - return cpu_ldl_code(env, advance_pc(env, s, 4)); + return translator_ldl(env, advance_pc(env, s, 4)); } #ifdef TARGET_X86_64 static inline uint64_t x86_ldq_code(CPUX86State *env, DisasContext *s) { - return cpu_ldq_code(env, advance_pc(env, s, 8)); + return translator_ldq(env, advance_pc(env, s, 8)); } #endif From patchwork Wed Jul 31 16:07:00 2019 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: 11068721 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5A1FC746 for ; Wed, 31 Jul 2019 16:30:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 452182012F for ; Wed, 31 Jul 2019 16:30:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38EE520453; Wed, 31 Jul 2019 16:30:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DE2552012F for ; Wed, 31 Jul 2019 16:30:30 +0000 (UTC) Received: from localhost ([::1]:42800 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrUk-0000fd-43 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:30:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45175) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrPm-0004xz-8k for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrPl-0000Lu-8F for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:22 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:51711) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrPl-0000KK-1k for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:21 -0400 Received: by mail-wm1-x332.google.com with SMTP id 207so61496622wma.1 for ; Wed, 31 Jul 2019 09:25:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2kztZJN5eNMXPYR/yV/k5e4rXASSvPn0RzjkaYHqSic=; b=sixXPJUt+07ZX+aqJ0Iamag0fuRCtaFGtRLLI379yh6hh0lEr3NlNM6Huje/cHNt5R w0vaO1Eh5HLlUeqq7v7B39sbyO0FBCzMlZJ/D+RMTVpYu19viQeBC7xbePA6yxRQFryF HO6TxmIBAU/dXDQvIItN9tklOZDJKCVu3exs9TgGE3SbZ3E8O+LJNVM1agFyqLloPO5D bP3dfo46ok0XPo8yjiyFcvnUoarKzTKiF/ZAvkyoAW/7fHXIMnUw3OW9KhO3WJl6kHB6 tBwX/0t/oOfhbu4bs6PxdtaDS7BW9wN4FQ13OZXicKsX8HZn5QYWSLaMm/JLTs2lQ0qU 6O4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2kztZJN5eNMXPYR/yV/k5e4rXASSvPn0RzjkaYHqSic=; b=Yz0GNHR6Mgfeaaof4tF5PQ3p14/BVPQx9rT+bCHK80OSsfR0plftPXVzM76z22Ivy0 Doxg4+JBAMQzoyzxnndeiAwKmBkavy6nUcVfZxsMJo76aYRGafIt9Boi0dFn2ujjnpq/ dvnPzzOTOYJ0Fo8ZQVJQCpsS9IXLoDg8SGkrJOGfC/z+N2kJrxaOMG78qANcYTA6o1X2 G0vDzzsHNAXNGsYHT2/vVwztytGurPQ6qLUrRLW9T8lzsdL6VK08wZEb/DLcwigQnqNv Fn+cgt2XFo59VGLamqzhYl4ysr0O9UiJ5yoleiNA4nqWn/DdxWQ8eQ2Ctrtu5re/20zL qmGw== X-Gm-Message-State: APjAAAXfb2DjJzeSsqolAtIBrf+R9YpnniTRCseDn+H66Sqm0EUNCUxD QoRuu5cnfyziX9JnT8cg5djq+g== X-Google-Smtp-Source: APXvYqzcsxWt6zX0whmLEwx4gsxEE3TISt51tyMlNk+NzLuOD8yk7s2AmdDGh6/pHdlIeFK+RlChng== X-Received: by 2002:a1c:c78d:: with SMTP id x135mr104527300wmf.82.1564590318914; Wed, 31 Jul 2019 09:25:18 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id y16sm149475699wrg.85.2019.07.31.09.25.14 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:25:16 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C0FC31FFBA; Wed, 31 Jul 2019 17:07:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:00 +0100 Message-Id: <20190731160719.11396-36-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::332 Subject: [Qemu-devel] [PATCH v4 35/54] target/hppa: fetch code with translator_ld X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , aaron@os.amperecomputing.com, cota@braap.org, bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- target/hppa/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/hppa/translate.c b/target/hppa/translate.c index 188fe688cbe..36a784e2932 100644 --- a/target/hppa/translate.c +++ b/target/hppa/translate.c @@ -4217,7 +4217,7 @@ static void hppa_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) { /* Always fetch the insn, even if nullified, so that we check the page permissions for execute. */ - uint32_t insn = cpu_ldl_code(env, ctx->base.pc_next); + uint32_t insn = translator_ldl(env, ctx->base.pc_next); /* Set up the IA queue for the next insn. This will be overwritten by a branch. */ From patchwork Wed Jul 31 16:07:01 2019 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: 11068695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 54BC4912 for ; Wed, 31 Jul 2019 16:27:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 40F08203B9 for ; Wed, 31 Jul 2019 16:27:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3548F20453; Wed, 31 Jul 2019 16:27:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D9A3F203B9 for ; Wed, 31 Jul 2019 16:27:10 +0000 (UTC) Received: from localhost ([::1]:42728 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrRW-0001To-9E for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:27:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45059) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrPh-0004l2-Nb for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrPg-0000Hc-NU for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:17 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:36972) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrPg-0000FU-HE for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:16 -0400 Received: by mail-wr1-x443.google.com with SMTP id n9so45294692wrr.4 for ; Wed, 31 Jul 2019 09:25:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JKs278UKgH4oI2AFtIL9RfBZue/0oRf2Q9p+k2Ejw74=; b=eWzP6JfGc/TdhIDLLu3kHnqQ+rheOQSCb3pKHq/N9m/ssu6FjF3l3O/0+wi6DSJQp/ cluN+FpQ6n6mq/czY0vzk21mkaD+733XZzj+nHnuQT/6mN2BfXUm0qPuCG/s+0ZtaxdY HuY5JsxfcP4o/ByMZwiDwJ2OCDRUoYH4GEeAMkfC4SZ3zjZNJbtFxVcJzfmbc10NDp33 o+Q9gskb1LEebSufpmhlFswqCUHx4BSDMuPINzTUYC6PrwnRbNIKho5ikgULfin9bYkb idc9ksUr5Q0CU5D6N2Q7NVpvrVhAHBFjbfV1ZzYRfOstwF4mr+LWGh99TaUoZ2+aOcuC k3NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JKs278UKgH4oI2AFtIL9RfBZue/0oRf2Q9p+k2Ejw74=; b=JEay9ugG+ghNXoktUPt6EGz1ulXfJ9cqpwIgvPbqSzVO2NNjLjjwbJZn68dehiGGz6 tSBNqzeuqNtUqDrbzPBuH0g70Qj/eLpcBP0cAgGNVbgr3XBD+ftu0JP+nusjSm2yOAXD PQSawfKgsEDQDLlt1KaHVi/bCMmCn6c+jZ9KbLr/MW11Dvxeugma3Zy1LZxLlrGb/GFJ pCDyFk1tAUMYFzKz7KMrwdNSqnBHdxtzH2bv0AJSZ6Cy461uToq2PfY1kpY2zDqeKmdF Rk2Zcdkos1JjiSV5ZWbTe50x04qgHgApA9QZdQmnMatSdZom93OCm58X61XSdNmQwe70 wqyQ== X-Gm-Message-State: APjAAAV/guuz487cgHaOXRbjvcbWeJgIuBnanBjITAuSvmUhBru6D+yr jrzeYYKNVTd52G7P8ztEq2ImlQ== X-Google-Smtp-Source: APXvYqxZ2dof9W93CZDoCyrWkvL+ATntb2jP3O3IDDxWtTATIVVd65J1w2vk5tFtGHkAclLcbPFjpg== X-Received: by 2002:adf:efd2:: with SMTP id i18mr133031558wrp.145.1564590314549; Wed, 31 Jul 2019 09:25:14 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id f2sm66260974wrq.48.2019.07.31.09.25.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:25:12 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id D56A31FFBB; Wed, 31 Jul 2019 17:07:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:01 +0100 Message-Id: <20190731160719.11396-37-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [PATCH v4 36/54] target/m68k: fetch code with translator_ld X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , Laurent Vivier , aaron@os.amperecomputing.com, cota@braap.org, bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- target/m68k/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/m68k/translate.c b/target/m68k/translate.c index 60bcfb7bd0c..92785befaac 100644 --- a/target/m68k/translate.c +++ b/target/m68k/translate.c @@ -384,7 +384,7 @@ static TCGv gen_ldst(DisasContext *s, int opsize, TCGv addr, TCGv val, static inline uint16_t read_im16(CPUM68KState *env, DisasContext *s) { uint16_t im; - im = cpu_lduw_code(env, s->pc); + im = translator_lduw(env, s->pc); s->pc += 2; return im; } From patchwork Wed Jul 31 16:07:02 2019 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: 11068725 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F605746 for ; Wed, 31 Jul 2019 16:31:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F00E3205A9 for ; Wed, 31 Jul 2019 16:31:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3B7C20564; Wed, 31 Jul 2019 16:31:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8851620564 for ; Wed, 31 Jul 2019 16:31:28 +0000 (UTC) Received: from localhost ([::1]:42818 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrVf-0002pF-V4 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:31:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45251) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrPp-00056y-H9 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrPo-0000Og-KW for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:25 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:36355) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrPo-0000O3-EU for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:24 -0400 Received: by mail-wm1-x341.google.com with SMTP id g67so56286575wme.1 for ; Wed, 31 Jul 2019 09:25:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=V98Zmvzo/uFuI/92KeHfM/lcI3tBexjtRM2UXdiaujA=; b=fV8ff6+nfET7t8dH6zsmqcMQMxohhdTO03oI9PpGu5opcNDYTGB1J0E4XdxOgg0y/z 8aSTH/vTHvk2W0rl1PFWctG6lBO6gvTtV1+vszoKl1oS42zXSlFmsbbuRhXcJ3EK6gea rFpd2EsMINoh8SECWeT275fd8NqmaF5r3MfQshfYZaJa2tL1N2e1HuEbH4i6PXcPDI/9 9gZSs61TgD6zxupcStUfd9yBhRyjGnkuzPTr0SaXufxb6x7DM/0XpKFxwSX6oMHkBYnl IBoUmIv1QEq0KE8HYcChW8I6OEFczfWIISqHhyh++b3jdkBGw5v4AhrLZHxIhazaYSWh Oz1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=V98Zmvzo/uFuI/92KeHfM/lcI3tBexjtRM2UXdiaujA=; b=SrVaiA7T853+2AHYZO5yjQ10cXp5LuN23B3f8jON68RRRgIePHlLBK/L3ADy1r1FYm fjHq9ESQ+zVYbNL2kDCnbS5QNPHfaZmHHLxFOFtVwfM9R4v1XYiezKAuFirmsT6qaWNu V/dPJYXVEVwktqUjjhVjRdN/BJ99p6DEALvQYeTkGwE3sQ1j/Fznj6Ar2POk+CmAyCRi cuX6Q0Hg8wNba5/o/tcCUoDMkq1/BUvp7TItCelstKdCu2VmnQ6ug4nWSRE9Wm+FI0Vf L65ua6mDn/1bKC+2A2KVMa/ZWxC3XZm3UgoTn86Qd44gQFfWIaos+dfwRJhFAGjH6nPR Y9Qg== X-Gm-Message-State: APjAAAVWummDsqNPOSjkIxXx7h77Rig98qx4j2i0sa+o5QcGkDkGcLMW tekUQGVcpePDTyeuKNVczCIp39bcqX8= X-Google-Smtp-Source: APXvYqx/rm6cyft+eS11gvuutof+D3J7YWSWOa2ntiSmDVzeVbJNIQyHfMedP334S7YNYwk5wWABvg== X-Received: by 2002:a7b:cbc6:: with SMTP id n6mr84155160wmi.14.1564590323303; Wed, 31 Jul 2019 09:25:23 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id f70sm91237836wme.22.2019.07.31.09.25.16 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:25:21 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id EAF771FFBC; Wed, 31 Jul 2019 17:07:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:02 +0100 Message-Id: <20190731160719.11396-38-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 Subject: [Qemu-devel] [PATCH v4 37/54] target/alpha: fetch code with translator_ld X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , aaron@os.amperecomputing.com, cota@braap.org, bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- target/alpha/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/alpha/translate.c b/target/alpha/translate.c index 2c9cccf6c1b..daf1e05cba6 100644 --- a/target/alpha/translate.c +++ b/target/alpha/translate.c @@ -2989,7 +2989,7 @@ static void alpha_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) { DisasContext *ctx = container_of(dcbase, DisasContext, base); CPUAlphaState *env = cpu->env_ptr; - uint32_t insn = cpu_ldl_code(env, ctx->base.pc_next); + uint32_t insn = translator_ldl(env, ctx->base.pc_next); ctx->base.pc_next += 4; ctx->base.is_jmp = translate_one(ctx, insn); From patchwork Wed Jul 31 16:07:03 2019 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: 11068697 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 98880912 for ; Wed, 31 Jul 2019 16:27:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84558203B9 for ; Wed, 31 Jul 2019 16:27:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 77F7520453; Wed, 31 Jul 2019 16:27:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 295F7203B9 for ; Wed, 31 Jul 2019 16:27:22 +0000 (UTC) Received: from localhost ([::1]:42730 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrRh-000234-FY for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:27:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45038) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrPh-0004k9-37 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrPg-0000Ge-3X for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:17 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:36797) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrPf-0000Eb-UG for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:16 -0400 Received: by mail-wr1-x441.google.com with SMTP id n4so70447861wrs.3 for ; Wed, 31 Jul 2019 09:25:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3KilUfW5qE8/qCyjKP1J8YJaC2amH5E2ZqjPJpVHgBQ=; b=tj7Eo6sqm2GcI0DJtEVG85i84SqjoykzrrEnT52+0xcOKzYKLkz+AB0JBDVKDoMI9v TGxYf1c25rKALLef4Tn3KF6jLEI9vEd1gZCdMP60aWR22I6M2yTES8+6AfVXOyHUAhpx bNJ5eCJoTUpEr7lzQ6Yc2n9VBC++ROgAjaDC+NE6Oy1GwhsA+4EMX9rQbqa0VbWh+Koz 2ot0fA2FwuAg+07dlc56oOsW4jr9UeOc+rHMcBuMnvLcEWBFzW2lnt+82p2pGdQ01D12 q4N8HdEL+zYdAlGmcrmDj3oi2S5oxaskz5E6x1svlmeLpL0XvwYu8lMpH5kfylQm1nt9 n2ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3KilUfW5qE8/qCyjKP1J8YJaC2amH5E2ZqjPJpVHgBQ=; b=eBfMdn3bBTLgwBNz7KY4eoOxQdPsTPRU3KPJCMwVtTpnXUcOTYRWndv3Eb5gr126kg d1IB40fobGVpEEiorGWiGJKqzBdAmQnPyC/lAl60UAdjcAOBSVnmIWrGyxSgbwqhslnG F0M9JoS+QULnhHQdOdjFvGyYah1tNYFLdk0Hlf8Nk6OfmqMXcMKXeqpB87dmmcomRkya TmnIPWK3yYVLfFRrCOfyn2nJqCoh9qz68B5rGWN3+6PlMlB6vPRQJbnQ9E1rOsbuwfUi 5Z1gvtgz3BWeuEfnhWJL5tT/ZA5xJHjaKOtgsmU688i8sgb+dLMo63v+ZcmOgwO3TEan S58w== X-Gm-Message-State: APjAAAVLyHAD09tJuOoTuwiwt+S3Ey+GqV1UFSIdW11eZLT67/snNjvk ImZAK0VS77KIhJB7NyFGQJrBxQ== X-Google-Smtp-Source: APXvYqyJIUlDhKfWYo4qh3ESjQp2QpEacFk9TGgyRsVeGYmH/zJEx7DsSB3+mNkFcdRbLOWfi59z4w== X-Received: by 2002:a5d:4e06:: with SMTP id p6mr54233807wrt.336.1564590313436; Wed, 31 Jul 2019 09:25:13 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id w67sm89785102wma.24.2019.07.31.09.25.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:25:12 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 0A82C1FF91; Wed, 31 Jul 2019 17:07:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:03 +0100 Message-Id: <20190731160719.11396-39-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PATCH v4 38/54] target/riscv: fetch code with translator_ld X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "open list:RISC-V TCG CPUs" , Sagar Karandikar , Bastian Koppelmann , Palmer Dabbelt , Richard Henderson , aaron@os.amperecomputing.com, cota@braap.org, Alistair Francis , bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- target/riscv/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 8d6ab732588..73cea63e4a2 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -796,7 +796,7 @@ static void riscv_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) DisasContext *ctx = container_of(dcbase, DisasContext, base); CPURISCVState *env = cpu->env_ptr; - ctx->opcode = cpu_ldl_code(env, ctx->base.pc_next); + ctx->opcode = translator_ldl(env, ctx->base.pc_next); decode_opc(ctx); ctx->base.pc_next = ctx->pc_succ_insn; From patchwork Wed Jul 31 16:07:04 2019 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: 11068673 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A362F13AC for ; Wed, 31 Jul 2019 16:23:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9012C1FF41 for ; Wed, 31 Jul 2019 16:23:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8443C20182; Wed, 31 Jul 2019 16:23:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 320331FF41 for ; Wed, 31 Jul 2019 16:23:09 +0000 (UTC) Received: from localhost ([::1]:42579 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrNc-0007Oh-J0 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:23:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42462) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrG9-00062U-4v for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrG8-0004By-5a for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:25 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:36278) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrG7-0004BH-Ut for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:24 -0400 Received: by mail-wm1-x343.google.com with SMTP id g67so56258810wme.1 for ; Wed, 31 Jul 2019 09:15:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jB7W3FnB4bnhencvSWp2/0bfRyouD1FARGQ5v7psx1U=; b=tLN/i8crKQj7EKMJUlE3vyW8kdZW+EFbyYA6oT/h30aGTqZcQHySyzP9d+1+YtwIe0 4Cdc+bY24k0svWVv4sHHcJ4Q4nv/ovyxiIwCo+ir3DG4gHBhIaieNKY7FZVm9jz8YhhX YI7FGjsu0Q0ucs8N/Pl/Fn9UoPeGRcShsYVR/DJtx7dTwm+ZgUH6EqeCjBioYj8OkTuC 6XaVnM+gdV2wPtBfpMjeqJYCHYrVe4V2/4Ai63VCoeZXoPfGxYq+LcTaTCd0MNckQoFP OEkEEPCQwSsY3vEdabHplEFc3V4HvZZCqjCMB8+DEb3d3nz/7hzUonUpLfkWJo687BHW Sx8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jB7W3FnB4bnhencvSWp2/0bfRyouD1FARGQ5v7psx1U=; b=nK6eBUbeMv7YjSW/KRTxcf0vofcsX3X3C5hXf81RzeU/vLqGS4mWbM0QdRa73yXURh 4MXkEzFwtdD0ZeO8/bwAmyL+6K4qBWcrfKAJpEdFBe2dwPQ/7XqA8PiUzDJ0b06Owg9p iMFlc2WihsNLMP2dWEI2ShrYSUHuxz/J1NAZmP+XeW3HTtxGaAlBQMNRQCdckezOBFwp 4+Vxccs7AZ1bFsa0AyHhe/t8ILlfFM7IpPty3mBdWlGILrHiP0tf7PUl6q1TpkP4QyS0 7e1uNV7zzpjM5QUTlG4zsftiq3W4SbdkDeXrPHK0K/IKT73gGV9NOtqJX548ZNeDVqMG AqkQ== X-Gm-Message-State: APjAAAUT+0KMR5jqQ2giiEojnRv5l2r6LRA3nKuFuB4ztvgtxVV2LawJ 9tkLZR4zyqaUTtpFBssaALZ2cA== X-Google-Smtp-Source: APXvYqxE+mrvkBZo4zbsGfnX4ypyJYo3glke8K0nik+skrWxrzZJj9jqOep1j0iaEaazp7r2Ibmb1g== X-Received: by 2002:a1c:7f08:: with SMTP id a8mr63599005wmd.1.1564589722735; Wed, 31 Jul 2019 09:15:22 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id n9sm114528509wrp.54.2019.07.31.09.15.16 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:15:18 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 1E1B91FFBD; Wed, 31 Jul 2019 17:07:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:04 +0100 Message-Id: <20190731160719.11396-40-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 Subject: [Qemu-devel] [PATCH v4 39/54] target/sparc: fetch code with translator_ld X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , Mark Cave-Ayland , aaron@os.amperecomputing.com, cota@braap.org, bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Artyom Tarasenko Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- target/sparc/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/sparc/translate.c b/target/sparc/translate.c index 091bab53af3..c91ff118099 100644 --- a/target/sparc/translate.c +++ b/target/sparc/translate.c @@ -5900,7 +5900,7 @@ static void sparc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) CPUSPARCState *env = cs->env_ptr; unsigned int insn; - insn = cpu_ldl_code(env, dc->pc); + insn = translator_ldl(env, dc->pc); dc->base.pc_next += 4; disas_sparc_insn(dc, insn); From patchwork Wed Jul 31 16:07:05 2019 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: 11068679 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BC2AD912 for ; Wed, 31 Jul 2019 16:24:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A74142012F for ; Wed, 31 Jul 2019 16:24:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B8DB2018F; Wed, 31 Jul 2019 16:24:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 43BAE2012F for ; Wed, 31 Jul 2019 16:24:19 +0000 (UTC) Received: from localhost ([::1]:42599 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrOk-0001pW-Kx for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:24:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42450) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrG8-000610-NQ for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrG7-0004BW-Lz for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:24 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:51536) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrG7-0004Ao-DG for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:23 -0400 Received: by mail-wm1-x341.google.com with SMTP id 207so61462395wma.1 for ; Wed, 31 Jul 2019 09:15:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9b3X+OxdFS4s7ijxIWOdR10EruuJKJ1r4dNBV9mBKeA=; b=GqX2unwfVNB4UDNslGdAIvSoHlJrPIqSs4kzXFgk1mcCrcKahuPQcvsASyxPI/zAkG C8uE1loDQXi6Q5g/9tJV1Ke8ZB4wiUf50qhO4Dr3lNGmBwMUHlKkXPJQesTVYap8MQsL ZWVS84BsT4xIpjhT1JtxJKLj4wA0/g95WJON2D+Lugnof1YO6iNtFXAUOJnC8pBgRf2C xz3iRFKZ+jLDtuuXjO/fvjphl2mEIoRen9ZAaOvb5a80pIC8dwQvcoezfu6CrDecoCoC aKipOLMDIWSxKJWIcuyQtQpS7YKG0x85wQxlUZRJeXs5dbeNHgOIt6WQJV479qMeZDMs y5sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9b3X+OxdFS4s7ijxIWOdR10EruuJKJ1r4dNBV9mBKeA=; b=MIjCd2bsNoTevlaCGzNaawOo7tzF0MAKEG6TXAfSuveqNA8cKk4nbnzxLbAtusHae6 jtUEkuqgpA/ibeB/7hgCiKBCUjGILKM1zZdwbLGtiw/FAqXLiir5gHpBcH1FsS/wNQI0 U+C3yM1p64TGGR5j6TLupwMshVM5bLe+iIGtt7awuUs867ha+AaSEExCEcDZ40pZ8Kpa 4iD36w5Tbdxnu0nc34emGGWlDAsjpOa/mcMazQt6yEBzIv3nCMFPVgCdiXiRERyLoK3y LsE0KP08G37HjfqnaPwNTT8auvb41bN+1BoPq9VYCb6yH+1tqTDqUcOwby/SyzKjZ1Tr bSCg== X-Gm-Message-State: APjAAAVv9VlCRw8dNVIcJqCe8pounyaTE4f/EbVKVa6xiS7XSNp+iGN1 3NGz6byskvkXilhFym/8uQC1Og== X-Google-Smtp-Source: APXvYqxZmwoTcjgKOWMcrWp+z5Vn5mjWjCVx0gH3izl1zP0MGCxrdmwvS9T4Aywdbjx4/14oKLnQKQ== X-Received: by 2002:a1c:cc0d:: with SMTP id h13mr109006434wmb.119.1564589722202; Wed, 31 Jul 2019 09:15:22 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id n9sm114528408wrp.54.2019.07.31.09.15.14 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:15:17 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 332B41FFBE; Wed, 31 Jul 2019 17:07:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:05 +0100 Message-Id: <20190731160719.11396-41-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 Subject: [Qemu-devel] [PATCH v4 40/54] target/xtensa: fetch code with translator_ld X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , Max Filippov , aaron@os.amperecomputing.com, cota@braap.org, bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- target/xtensa/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c index 6f1da878752..cb849ae2d9b 100644 --- a/target/xtensa/translate.c +++ b/target/xtensa/translate.c @@ -863,7 +863,7 @@ static int arg_copy_compare(const void *a, const void *b) static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc) { xtensa_isa isa = dc->config->isa; - unsigned char b[MAX_INSN_LENGTH] = {cpu_ldub_code(env, dc->pc)}; + unsigned char b[MAX_INSN_LENGTH] = {translator_ldub(env, dc->pc)}; unsigned len = xtensa_op0_insn_len(dc, b[0]); xtensa_format fmt; int slot, slots; @@ -887,7 +887,7 @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc) dc->base.pc_next = dc->pc + len; for (i = 1; i < len; ++i) { - b[i] = cpu_ldub_code(env, dc->pc + i); + b[i] = translator_ldub(env, dc->pc + i); } xtensa_insnbuf_from_chars(isa, dc->insnbuf, b, len); fmt = xtensa_format_decode(isa, dc->insnbuf); From patchwork Wed Jul 31 16:07:06 2019 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: 11068677 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4644A912 for ; Wed, 31 Jul 2019 16:24:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 32D582012F for ; Wed, 31 Jul 2019 16:24:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2714C2018F; Wed, 31 Jul 2019 16:24:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BEC682012F for ; Wed, 31 Jul 2019 16:24:13 +0000 (UTC) Received: from localhost ([::1]:42596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrOf-0001XD-4N for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:24:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42515) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrGB-00069h-8X for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrGA-0004DS-3b for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:27 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:43029) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrG9-0004Cs-SH for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:26 -0400 Received: by mail-wr1-x442.google.com with SMTP id p13so70305874wru.10 for ; Wed, 31 Jul 2019 09:15:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t7tqVUjAD2PfWwfma6adF8tsYdFtgp6/4kEZrCKl67k=; b=VDb83tAnPSPUoNZ8WUGqv2g/foqveCWQxQOwIurq3poRKLQv5WtJhrbnwovRuAjd7N ysBBJlu79JPB/fcPjHEvsxXNRoY+F/mAmLSHOGI3PbX4ZEtwJN1bLXlvMIzBJr7had+Z Pd0mheFbqz+LKZnlZX9/2AEC116E8VzPBhGta4t4PDoDM7YiPORjjicYU1/o0Z779XL6 Btnaa8/7nO+Y8/bkPf8YvsQRqZ0Ropu7zuJUp1wbCHhL+0NJwTNt84XeEH3+416WuyHw KH93OytR58v37uPJMMvvQcRxq5JdG7wr5KuqGXZrRZ9B9Ryd0JuMPaC8Tt5/DV/rbglL qLhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t7tqVUjAD2PfWwfma6adF8tsYdFtgp6/4kEZrCKl67k=; b=JPOVxwbtFtnC4oMJNUYTjVywuU/JyDvStP+rNpJXQtvXkUAxzYWrvHCbtP4f7NFrNf G+FvAzNPaSp5Quxpi4dikohJ++i2aEoAAg7fKhlzwEEyN0ucZ2dAelpNIFcSEVBllu11 jgvOtYPiqaYzq8rbkLG5a+ZmOBm+vDVlO+TGa2DnEeXoSc9Y/ToHD5/V8ac6FoHItzmL Q4P+GfW5YnYTAFXxYkIz7ODJZLnMM4DZaPwTTTJX0hGdxC1oX271R6FLj7kdclvXo3zm bOW4SccP29MP69ziGwNJzuxydGIPkpLJJb1X7HzbrIFQNL5+JFhaVg1z+nlb8DwRRFo4 iraQ== X-Gm-Message-State: APjAAAU6JlBgDZC1roX3JO35vb24lVOpd+B0823OHY4Y8UZEJKsgZF65 K7R3hf6HhSq43JUWmEGS4juN4g== X-Google-Smtp-Source: APXvYqwpi0Nf9un6FExiRZUuuZkcR6fGjpdRPdPmB0RzYel7ZPCJhWobKuqDTYLSTAC6mhDjJmq2hg== X-Received: by 2002:adf:afe7:: with SMTP id y39mr131632998wrd.350.1564589724833; Wed, 31 Jul 2019 09:15:24 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id g8sm68961022wmf.17.2019.07.31.09.15.17 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:15:22 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 48ACA1FFBF; Wed, 31 Jul 2019 17:07:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:06 +0100 Message-Id: <20190731160719.11396-42-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PATCH v4 41/54] target/openrisc: fetch code with translator_ld X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , aaron@os.amperecomputing.com, cota@braap.org, Stafford Horne , =?utf-8?q?Alex_Benn=C3=A9e?= , bobby.prani@gmail.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- target/openrisc/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/openrisc/translate.c b/target/openrisc/translate.c index 4360ce40452..7df4c68d158 100644 --- a/target/openrisc/translate.c +++ b/target/openrisc/translate.c @@ -1305,7 +1305,7 @@ static void openrisc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) { DisasContext *dc = container_of(dcbase, DisasContext, base); OpenRISCCPU *cpu = OPENRISC_CPU(cs); - uint32_t insn = cpu_ldl_code(&cpu->env, dc->base.pc_next); + uint32_t insn = translator_ldl(&cpu->env, dc->base.pc_next); if (!decode(dc, insn)) { gen_illegal_exception(dc); From patchwork Wed Jul 31 16:07:07 2019 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: 11068649 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7DE2613AC for ; Wed, 31 Jul 2019 16:19:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B0CD1FE8D for ; Wed, 31 Jul 2019 16:19:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5EBB11FFCD; Wed, 31 Jul 2019 16:19:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F1E121FE8D for ; Wed, 31 Jul 2019 16:19:04 +0000 (UTC) Received: from localhost ([::1]:42484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrJg-0005DW-94 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:19:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42328) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrG5-0005pP-OK for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrG3-00048O-Od for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:21 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:36708) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrG1-00046M-Mj for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:17 -0400 Received: by mail-wr1-x442.google.com with SMTP id n4so70412820wrs.3 for ; Wed, 31 Jul 2019 09:15:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NeBjS48hgLPnN+/FAA6/R9TYKzQRsPV0AVfEZ4tlPs0=; b=awe2Z7+UteZ1OleIoymnp2TEcFmXxOeCtR8TTDIqq3AsphDj/P1onA61KvN9yMF7Sc qAsURm5ljRnRGJmUorKK3GksZ2rOSvkUFREGrg1G5a8hUDSyX7Hqu4MWJ3C/5vRifr1g vAN2X8rNbVYxGooWneSnVlR5d8YUNV0xq1qGRe9SdBm9r2CEgJNHbzl+DPkkGlvJvnA3 Qw747TQcSDd+wp7rk25MdhzuYQqLArUaT0URpXn1LIebxTvasytbyL50Lxsu+CcYVLHq R5VLliTFFiuGsA84SVOcHX8ixhhjU8NSUneqfcHiVu1ldVnfpROHW2FQdhA2IipWTWn8 EitQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NeBjS48hgLPnN+/FAA6/R9TYKzQRsPV0AVfEZ4tlPs0=; b=gw/yo1bApCfMtQTDFWZXs8eINRKG/qBHsFqS7QL2ImGeRdwN52U2ovKmlKKISSIjKT 2aOYrIHwBWagSHqBxpR+vTDedWZFHQTiyiWWFA5V35z2TAraIEuIWyDfEQxkSPt3Mjgl hWf5Rfj8S6YYUs7HIMPFvMb24aSX6m77aJOR006KnQ1O6j0+qiWHCe07mYYPTKyjpScK e6f8Gdnr5v7MxU9FmqkXyU2Bav/Dwr6sPLpVSk3v4TXEmNdIJhMv/Kx8sSvk9x9QESYu rwP8R5w6eI8UkKH1R+FsPnWsDRXMn+UGVGdQhUIuZan/K7eQx6NKG1px8wLJaZIICNnx H43Q== X-Gm-Message-State: APjAAAUtTpSHElD0go5uMEitePTxy8GgPmn5GCPYosLFrZTuJWJz0Aw/ bV2WVTPFlBhmscO76EX3dnBDug== X-Google-Smtp-Source: APXvYqxEhzihtvLD7CSapmPIv8LnuLqDPPqlA+/iYYKcJM4As1ZlqIbhZw0Qf4ZxROfdFYtyhjlApw== X-Received: by 2002:a5d:50d1:: with SMTP id f17mr4932906wrt.124.1564589715274; Wed, 31 Jul 2019 09:15:15 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id x6sm71886710wrt.63.2019.07.31.09.15.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:15:13 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 5D2141FFC0; Wed, 31 Jul 2019 17:07:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:07 +0100 Message-Id: <20190731160719.11396-43-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PATCH v4 42/54] translator: inject instrumentation from plugins X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v4 - note we can't inject instrumentation if ! DISAS_NEXT --- accel/tcg/translator.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index 9226a348a39..4e30772f8cb 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -16,6 +16,7 @@ #include "exec/gen-icount.h" #include "exec/log.h" #include "exec/translator.h" +#include "exec/plugin-gen.h" /* Pairs with tcg_clear_temp_count. To be called by #TranslatorOps.{translate_insn,tb_stop} if @@ -34,6 +35,7 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, CPUState *cpu, TranslationBlock *tb, int max_insns) { int bp_insn = 0; + bool plugin_enabled; /* Initialize DisasContext */ db->tb = tb; @@ -55,11 +57,17 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, ops->tb_start(db, cpu); tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */ + plugin_enabled = plugin_gen_tb_start(cpu, tb); + while (true) { db->num_insns++; ops->insn_start(db, cpu); tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */ + if (plugin_enabled) { + plugin_gen_insn_start(cpu, db); + } + /* Pass breakpoint hits to target for further processing */ if (!db->singlestep_enabled && unlikely(!QTAILQ_EMPTY(&cpu->breakpoints))) { @@ -100,6 +108,14 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, break; } + /* + * We can't instrument after instructions that change control + * flow although this only really affects post-load operations. + */ + if (plugin_enabled) { + plugin_gen_insn_end(); + } + /* Stop translation if the output buffer is full, or we have executed all of the allowed instructions. */ if (tcg_op_buf_full() || db->num_insns >= db->max_insns) { @@ -112,6 +128,10 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, ops->tb_stop(db, cpu); gen_tb_end(db->tb, db->num_insns - bp_insn); + if (plugin_enabled) { + plugin_gen_tb_end(cpu); + } + /* The disas_log hook may use these values rather than recompute. */ db->tb->size = db->pc_next - db->pc_first; db->tb->icount = db->num_insns; From patchwork Wed Jul 31 16:07:08 2019 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: 11068699 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EFE8013AC for ; Wed, 31 Jul 2019 16:27:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAFD52000A for ; Wed, 31 Jul 2019 16:27:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF20C20415; Wed, 31 Jul 2019 16:27:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 40B192000A for ; Wed, 31 Jul 2019 16:27:37 +0000 (UTC) Received: from localhost ([::1]:42736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrRw-0002oz-Kd for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:27:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45254) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrPp-00057p-ST for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrPo-0000OM-5r for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:25 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:41823) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrPn-0000Ng-Va for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:24 -0400 Received: by mail-wr1-x443.google.com with SMTP id c2so67154890wrm.8 for ; Wed, 31 Jul 2019 09:25:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4EXaES14kXYuknV6BmgHILnMsjbpC7Jf9OLUvLs/j/Y=; b=oh5VGq5dG6uFB4+VG7/rZwM0llAIDdbsHHAtnoRlXp7pEAlCLrzyNRjkqPv/toNcS4 QzetqV+RSSzbTyVXuS/b9QTZDEuhIARsUNnL3d0t7YeU7yIpgP7k1Tanhhk5SZJCgY/G Cj6fyIp5oAzLtLlO6qsmqALPw+jpEjwhWksBvzNhx2+GEKJBNPrkdgRKadVWLUS1VQyy bM0NzML9TlIe3nRF8SJaUYud2maL+AmULON3LbGBfog8or5X0ULTNJqtNV3jwfx4kUqU W/Hp/WdXleANNg3fFgddOBpTsp41bM8ie9WATAHDbbhQx9inhRHQK6HdX3TnKxZGW1yN bVnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4EXaES14kXYuknV6BmgHILnMsjbpC7Jf9OLUvLs/j/Y=; b=TWcTz7r0zsOyvEcVOWjwEHMM/M5qVr0PbLHsN0C+XuP38knP1vDC07puG2aw5goTMy bzEmzr0aPkARGa4lpJo6UPJTytIYCEfuvzQMRPbCcpMLgGn+p5COiZgPys7ZZATXVPGA WHO78j4OXl15wMYM1Qp7X1o3Ti3aIheTlj+mBFaJdt8Tgc04ONjg5HF6RcfYKAk72jeV KV8b84UGf0/n7ooxziH6nGwwmVME1yv9UNKg0k97YHTfFtdyoWis/dZjj6y5upLP6+7R 20PhNionh77e9Ti/M1mBtyDiKgbolhUMAEx2KRD4CfcH7yR1UlT5e/29qV0ogTDWG1L4 TGRQ== X-Gm-Message-State: APjAAAVL7ta60yKOqFosJ/Hghc6WYJXmglEneNDxWypBTOvZEMflbgvV xk3TzlbZm7gpA0j/kNcdeFGI5Q== X-Google-Smtp-Source: APXvYqzGU2Xb1CfqjqXoCbKXVARBLXLm8hKX7om61dLyU1TDgtfwKdebyx0NQvj1lKAnSCPCiZb/ZA== X-Received: by 2002:a05:6000:1148:: with SMTP id d8mr119764076wrx.354.1564590322859; Wed, 31 Jul 2019 09:25:22 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id a8sm55555823wma.31.2019.07.31.09.25.17 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:25:21 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 77E911FFC1; Wed, 31 Jul 2019 17:07:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:08 +0100 Message-Id: <20190731160719.11396-44-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [PATCH v4 43/54] plugin: add API symbols to qemu-plugins.symbols X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bobby.prani@gmail.com, cota@braap.org, =?utf-8?q?Alex_Benn=C3=A9e?= , aaron@os.amperecomputing.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota [AJB: moved into plugins] Signed-off-by: Alex Bennée --- v3 - moved to plugins/ - include qemu_plugin_reset --- Makefile | 1 + configure | 69 ++++++++++++++++++++++++++++++++++++ plugins/.gitignore | 2 ++ plugins/Makefile.objs | 14 ++++++++ plugins/qemu-plugins.symbols | 38 ++++++++++++++++++++ 5 files changed, 124 insertions(+) create mode 100644 plugins/.gitignore create mode 100644 plugins/qemu-plugins.symbols diff --git a/Makefile b/Makefile index ed4bb87f224..485e4bb2e85 100644 --- a/Makefile +++ b/Makefile @@ -726,6 +726,7 @@ distclean: clean rm -f qemu-doc.fn qemu-doc.fns qemu-doc.info qemu-doc.ky qemu-doc.kys rm -f qemu-doc.log qemu-doc.pdf qemu-doc.pg qemu-doc.toc qemu-doc.tp rm -f qemu-doc.vr qemu-doc.txt + rm -f qemu-plugins-ld.symbols qemu-plugins-ld64.symbols rm -f config.log rm -f linux-headers/asm rm -f docs/version.texi diff --git a/configure b/configure index dbc78f21b0c..7f6a1556fe2 100755 --- a/configure +++ b/configure @@ -30,6 +30,7 @@ TMPO="${TMPDIR1}/${TMPB}.o" TMPCXX="${TMPDIR1}/${TMPB}.cxx" TMPE="${TMPDIR1}/${TMPB}.exe" TMPMO="${TMPDIR1}/${TMPB}.mo" +TMPTXT="${TMPDIR1}/${TMPB}.txt" rm -f config.log @@ -5498,6 +5499,58 @@ if compile_prog "" "" ; then atomic64=yes fi +######################################### +# See if --dynamic-list is supported by the linker + +cat > $TMPTXT < $TMPC < +void foo(void); + +void foo(void) +{ + printf("foo\n"); +} + +int main(void) +{ + foo(); + return 0; +} +EOF + +ld_dynamic_list="no" +if compile_prog "" "-Wl,--dynamic-list=$TMPTXT" ; then + ld_dynamic_list="yes" +fi + +######################################### +# See if -exported_symbols_list is supported by the linker + +cat > $TMPTXT <> $config_host_mak LIBS="-ldl $LIBS" + # Copy the export object list to the build dir + if test "$ld_dynamic_list" = "yes" ; then + echo "CONFIG_HAS_LD_DYNAMIC_LIST=yes" >> $config_host_mak + ld_symbols=qemu-plugins-ld.symbols + cp "$source_path/plugins/qemu-plugins.symbols" $ld_symbols + elif test "$ld_exported_symbols_list" = "yes" ; then + echo "CONFIG_HAS_LD_EXPORTED_SYMBOLS_LIST=yes" >> $config_host_mak + ld64_symbols=qemu-plugins-ld64.symbols + echo "# Automatically generated by configure - do not modify" > $ld64_symbols + grep 'qemu_' "$source_path/plugins/qemu-plugins.symbols" | sed 's/;//g' | \ + sed -E 's/^[[:space:]]*(.*)/_\1/' >> $ld64_symbols + else + error_exit \ + "If \$plugins=yes, either \$ld_dynamic_list or " \ + "\$ld_exported_symbols_list should have been set to 'yes'." + fi fi if test "$tcg_interpreter" = "yes"; then diff --git a/plugins/.gitignore b/plugins/.gitignore new file mode 100644 index 00000000000..7b8aaa1f109 --- /dev/null +++ b/plugins/.gitignore @@ -0,0 +1,2 @@ +qemu-plugins-ld.symbols +qemu-plugins-ld64.symbols diff --git a/plugins/Makefile.objs b/plugins/Makefile.objs index 95baabf3d2f..6f14d91ccb9 100644 --- a/plugins/Makefile.objs +++ b/plugins/Makefile.objs @@ -5,3 +5,17 @@ obj-y += loader.o obj-y += core.o obj-y += api.o + +# Abuse -libs suffix to only link with --dynamic-list/-exported_symbols_list +# when the final binary includes the plugin object. +# +# Note that simply setting LDFLAGS is not enough: we build binaries that +# never link plugin.o, and the linker might fail (at least ld64 does) +# if the symbols in the list are not in the output binary. +ifdef CONFIG_HAS_LD_DYNAMIC_LIST +api.o-libs := -Wl,--dynamic-list=$(BUILD_DIR)/qemu-plugins-ld.symbols +else +ifdef CONFIG_HAS_LD_EXPORTED_SYMBOLS_LIST +api.o-libs := -Wl,-exported_symbols_list,$(BUILD_DIR)/qemu-plugins-ld64.symbols +endif +endif diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols new file mode 100644 index 00000000000..40c0d1abd2f --- /dev/null +++ b/plugins/qemu-plugins.symbols @@ -0,0 +1,38 @@ +{ + qemu_plugin_uninstall; + qemu_plugin_reset; + qemu_plugin_register_vcpu_init_cb; + qemu_plugin_register_vcpu_exit_cb; + qemu_plugin_register_vcpu_idle_cb; + qemu_plugin_register_vcpu_resume_cb; + qemu_plugin_register_vcpu_insn_exec_cb; + qemu_plugin_register_vcpu_insn_exec_inline; + qemu_plugin_register_vcpu_mem_cb; + qemu_plugin_register_vcpu_mem_haddr_cb; + qemu_plugin_register_vcpu_mem_inline; + qemu_plugin_ram_addr_from_host; + qemu_plugin_register_vcpu_tb_trans_cb; + qemu_plugin_register_vcpu_tb_exec_cb; + qemu_plugin_register_vcpu_tb_exec_inline; + qemu_plugin_register_flush_cb; + qemu_plugin_register_vcpu_syscall_cb; + qemu_plugin_register_vcpu_syscall_ret_cb; + qemu_plugin_register_atexit_cb; + qemu_plugin_tb_n_insns; + qemu_plugin_tb_get_insn; + qemu_plugin_tb_vaddr; + qemu_plugin_insn_data; + qemu_plugin_insn_size; + qemu_plugin_insn_vaddr; + qemu_plugin_insn_haddr; + qemu_plugin_mem_size_shift; + qemu_plugin_mem_is_sign_extended; + qemu_plugin_mem_is_big_endian; + qemu_plugin_mem_is_store; + qemu_plugin_get_hwaddr; + qemu_plugin_hwaddr_is_io; + qemu_plugin_hwaddr_to_raddr; + qemu_plugin_vcpu_for_each; + qemu_plugin_n_vcpus; + qemu_plugin_n_max_vcpus; +}; From patchwork Wed Jul 31 16:07:09 2019 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: 11068771 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 90B9113AC for ; Wed, 31 Jul 2019 16:45:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FC4F27CEE for ; Wed, 31 Jul 2019 16:45:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73FC028173; Wed, 31 Jul 2019 16:45:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 09A9227CEE for ; Wed, 31 Jul 2019 16:45:51 +0000 (UTC) Received: from localhost ([::1]:42996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrja-0002xe-To for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:45:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51208) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrj3-0001h3-5T for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:45:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrj2-0000qo-28 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:45:17 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:43165) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrj1-0000oz-QS for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:45:15 -0400 Received: by mail-wr1-x42f.google.com with SMTP id p13so70408859wru.10 for ; Wed, 31 Jul 2019 09:45:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mjk2DnvfJD1k/p+MqNImwcO38VXfRv1NAD/8zcwI2MQ=; b=vf3Qhf4qL45sidOgROi8Ul9+tgpNUnxyKODPFMrd5NpW+c3Yya3bnu3xPP6Qm2Xo2z jYsDmCrBSX8Ehlqx3GK3X9DbewB+nZFp5Jh5xy4GbT8Ff0idt1VXCeIKp926jAohQhVB IBSEZXUb3E+e0Ef7KIoXlHP/3Uh6kexxfeObgcycullKID62vZGMlFq6leHxaZoIwZbN itHyHHnPA3kk2/yNEQcbRARG3OYAwG69XnldtFXfqmrbIBc+iljlJV8wmJwJg0ys1wV5 UFxyxs2/C2785hrgov1RaNoXr+5gOOdzaQkOywuR994lE+aAmT6jR4GqgmXFWfQD3hSe vo1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mjk2DnvfJD1k/p+MqNImwcO38VXfRv1NAD/8zcwI2MQ=; b=jIEWQuy2n3yL1jhNaLJ4G9AbzsyYspRrCa59rZTXFkwGFHGGv+QxXppWyq585Ft+ZG V1gImozwWnc0sKlOrCfsOLX/PEmQqmTejsSZnceFmK4yGz6/Ynz9QJ8of3OiNoPB+5fT KGXx02oy94TgZoEL5+ueOeTBmdHnOmRdMyI+FmXWv8G1WJWvRKkkvDff5041bDDUXo3l zTNrK+bzhrwgxrXXTsVHv4Z2Yksy56tBx9wXV4AHeub3wgyHXorJSeyaM/Drjminn5CW KfLMlzanceXSYZxWF19fNlkDiQ+za6LVWZZbHHiShIlIOmPdhbWdT/A5tQ+aNgNag09o bElA== X-Gm-Message-State: APjAAAUWsTkWPUk1VnSKziXOWfXQEIkxng66IhZLc98vuALeJNajAf+/ C1PqNN48guUYHVPv90yyBKi4940HjUE= X-Google-Smtp-Source: APXvYqxZmJZr7PKRMxVZgJU5+u0tZYUHVe0M2VFciORbq0cG3ExDZ2sjLa+yj3wXpEzcsPQ+xO+7lw== X-Received: by 2002:adf:ed41:: with SMTP id u1mr129156373wro.162.1564591514200; Wed, 31 Jul 2019 09:45:14 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id z5sm49307630wmf.48.2019.07.31.09.45.13 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:45:13 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 8C49B1FFC2; Wed, 31 Jul 2019 17:07:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:09 +0100 Message-Id: <20190731160719.11396-45-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42f Subject: [Qemu-devel] [PATCH v4 44/54] vl: support -plugin option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs_Vila?= =?utf-8?q?nova?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Lluís Vilanova Signed-off-by: Lluís Vilanova [ cota: s/instrument/plugin ] Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- qemu-options.hx | 17 +++++++++++++++++ vl.c | 11 +++++++++++ 2 files changed, 28 insertions(+) diff --git a/qemu-options.hx b/qemu-options.hx index 9621e934c0b..7b438f61734 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4131,6 +4131,23 @@ HXCOMM HX does not support conditional compilation of text. @findex -trace @include qemu-option-trace.texi ETEXI +DEF("plugin", HAS_ARG, QEMU_OPTION_plugin, + "-plugin [file=][,arg=]\n" + " load a plugin\n", + QEMU_ARCH_ALL) +STEXI +@item -plugin file=@var{file}[,arg=@var{string}] +@findex -plugin + +Load a plugin. + +@table @option +@item file=@var{file} +Load the given plugin from a shared library file. +@item arg=@var{string} +Argument string passed to the plugin. (Can be given multiple times.) +@end table +ETEXI HXCOMM Internal use DEF("qtest", HAS_ARG, QEMU_OPTION_qtest, "", QEMU_ARCH_ALL) diff --git a/vl.c b/vl.c index b426b321346..bb62989f776 100644 --- a/vl.c +++ b/vl.c @@ -109,6 +109,7 @@ int main(int argc, char **argv) #include "trace-root.h" #include "trace/control.h" +#include "qemu/plugin.h" #include "qemu/queue.h" #include "sysemu/arch_init.h" @@ -2889,6 +2890,7 @@ int main(int argc, char **argv, char **envp) bool list_data_dirs = false; char *dir, **dirs; BlockdevOptionsQueue bdo_queue = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue); + QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list); os_set_line_buffering(); @@ -2919,6 +2921,7 @@ int main(int argc, char **argv, char **envp) qemu_add_opts(&qemu_global_opts); qemu_add_opts(&qemu_mon_opts); qemu_add_opts(&qemu_trace_opts); + qemu_plugin_add_opts(); qemu_add_opts(&qemu_option_rom_opts); qemu_add_opts(&qemu_machine_opts); qemu_add_opts(&qemu_accel_opts); @@ -3697,6 +3700,9 @@ int main(int argc, char **argv, char **envp) g_free(trace_file); trace_file = trace_opt_parse(optarg); break; + case QEMU_OPTION_plugin: + qemu_plugin_opt_parse(optarg, &plugin_list); + break; case QEMU_OPTION_readconfig: { int ret = qemu_read_config_file(optarg); @@ -4010,6 +4016,11 @@ int main(int argc, char **argv, char **envp) machine_class->default_machine_opts, 0); } + /* process plugin before CPUs are created, but once -smp has been parsed */ + if (qemu_plugin_load_list(&plugin_list)) { + exit(1); + } + qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, NULL); qemu_opts_foreach(qemu_find_opts("global"), From patchwork Wed Jul 31 16:07:10 2019 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: 11068659 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C0C48912 for ; Wed, 31 Jul 2019 16:20:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD5801FFDB for ; Wed, 31 Jul 2019 16:20:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9AAA82000A; Wed, 31 Jul 2019 16:20:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DEA721FFDB for ; Wed, 31 Jul 2019 16:20:40 +0000 (UTC) Received: from localhost ([::1]:42522 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrLE-0000Sz-51 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:20:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42322) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrG5-0005pH-Ng for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrG1-000475-Os for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:19 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:33696) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrFz-00045J-R9 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:17 -0400 Received: by mail-wr1-x444.google.com with SMTP id n9so70435911wru.0 for ; Wed, 31 Jul 2019 09:15:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ETn84aVwzraVZR/ukzhhM5DHZ0Q2gcDn01igaexosx0=; b=IXVI1UXYGYFOZ9jKBjjo/7x0/5Ula4rEgEDzcFYTcVYscj+i1zbqbhNxiX0fo8JAvu 2RcwY8m5MgfpX/zX/lLdeZL6mvvvQCbfZoHfURxRe44hPBhbtO5Hqodi53cnVEPwV3dK pZWO2rSB7Q+6jI1zFjbaodmMdDf4Wyc7uqoBOVGNyvksNCYJ7TVNLkCxl4HnU3NaQRcf F1ApoJSMzdwD4SrjL6GdkBY92p1+CI/NIJXDB6xY3UaFjlqi5AneOL+gAzm3YPYemv3u gf4AEjbHV5a/u9n6GDzt9bPPdJVro0Y5Jz52g6+Zgol0763C5A3FIfG9h3/98kOWSHsc duJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ETn84aVwzraVZR/ukzhhM5DHZ0Q2gcDn01igaexosx0=; b=pZcgfX6XmX2FSGHKO6HgIWXZ7Gnaht8hihEfWoKH6KdPGfiX0wRjSfbmF2/8fZMGZl Do0hI/vVHim72xiqpHUP1YdrWVrqdXCP2mDPHDva5/Q21Fx8I6VierrAHcaGx0PEjqvL IsAok8MEzfpP2trnKzuDGHyx0RY5t8NOiaCpY96tXwjWsjsHW0gJDi0lNK4bfTtzNo05 Az7Ma8aV6P7qyUgpk9vYPmChH7S0tVhFxWnnxT+hi1XGjKeG3/ay0nSBGyxtCBE7MsTu v/wb7aJubRd4+av7Xuc/mnP5F4NhiaVjpO0LSgkmhofnqL7j0iKZ920bP56HkTJF594g hGbw== X-Gm-Message-State: APjAAAUfmNC3GjJpWCxXd/E3BT7PdRNgi55rj/z5Lp1FYlbzue4kcHZm aCZr+8ZQlLbsx4IzZ8IjCFfpvQ== X-Google-Smtp-Source: APXvYqzT697wIZ21eVsK4mf9nOLgLFWnWSRF96rbadKVA/ceGWCUPmVc5kXiXUK2cx68ZRM3EomM8w== X-Received: by 2002:adf:e705:: with SMTP id c5mr87792253wrm.270.1564589713239; Wed, 31 Jul 2019 09:15:13 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id l2sm46111132wmj.4.2019.07.31.09.15.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:15:12 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 9FE611FFC3; Wed, 31 Jul 2019 17:07:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:10 +0100 Message-Id: <20190731160719.11396-46-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH v4 45/54] linux-user: support -plugin option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Richard Henderson , Laurent Vivier , aaron@os.amperecomputing.com, cota@braap.org, bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Lluís Vilanova Signed-off-by: Lluís Vilanova [ cota: s/instrument/plugin ] Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- linux-user/main.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/linux-user/main.c b/linux-user/main.c index 8ffc5251955..42daa47dd3c 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -33,6 +33,7 @@ #include "qemu/error-report.h" #include "qemu/help_option.h" #include "qemu/module.h" +#include "qemu/plugin.h" #include "cpu.h" #include "exec/exec-all.h" #include "tcg.h" @@ -392,6 +393,15 @@ static void handle_arg_trace(const char *arg) trace_file = trace_opt_parse(arg); } +static QemuPluginList plugins = QTAILQ_HEAD_INITIALIZER(plugins); + +#ifdef CONFIG_PLUGIN +static void handle_arg_plugin(const char *arg) +{ + qemu_plugin_opt_parse(arg, &plugins); +} +#endif + struct qemu_argument { const char *argv; const char *env; @@ -443,6 +453,10 @@ static const struct qemu_argument arg_table[] = { "", "Seed for pseudo-random number generator"}, {"trace", "QEMU_TRACE", true, handle_arg_trace, "", "[[enable=]][,events=][,file=]"}, +#ifdef CONFIG_PLUGIN + {"plugin", "QEMU_PLUGIN", true, handle_arg_plugin, + "", "[file=][,arg=]"}, +#endif {"version", "QEMU_VERSION", false, handle_arg_version, "", "display version information and exit"}, {NULL, NULL, false, NULL, NULL, NULL} @@ -633,6 +647,7 @@ int main(int argc, char **argv, char **envp) cpu_model = NULL; qemu_add_opts(&qemu_trace_opts); + qemu_plugin_add_opts(); optind = parse_args(argc, argv); @@ -640,6 +655,9 @@ int main(int argc, char **argv, char **envp) exit(1); } trace_init_file(trace_file); + if (qemu_plugin_load_list(&plugins)) { + exit(1); + } /* Zero out regs */ memset(regs, 0, sizeof(struct target_pt_regs)); From patchwork Wed Jul 31 16:07:11 2019 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: 11068723 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 435EB912 for ; Wed, 31 Jul 2019 16:31:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C87220502 for ; Wed, 31 Jul 2019 16:31:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D44C20572; Wed, 31 Jul 2019 16:31:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5251720502 for ; Wed, 31 Jul 2019 16:31:15 +0000 (UTC) Received: from localhost ([::1]:42816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrVS-0002Vx-LB for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:31:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45185) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrPm-0004zC-JB for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrPk-0000LI-Os for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:22 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:46392) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrPk-0000Kv-Hy for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:20 -0400 Received: by mail-wr1-x444.google.com with SMTP id z1so70344383wru.13 for ; Wed, 31 Jul 2019 09:25:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pI2PSe031dP9Z8EwvDY5ZLfPiW1DefLEAiLsti8QtY0=; b=XuSHU5yYHNdZuW2ou7/dBZ0vPp+8XWw/B9fYsYnAjZYBNtq35dvrcl5uMHKRnWrNcm agSZpSMH1Qv48lvIl8BgfzItjNgxD3Vf9zo0ohRakDMyFpRXEOEEaYM93UNq10KoJY0m fosVd0LN7ca2+cUuExs96h08fPkOtBfQ8VIRjcIQ1GjkRwX1BY7X+gAi5iKuR3jfOYfF SRNN8L4JfLHfmDmjb83aDSApG4UtuCFAP2gD7NqSbq5CGiR/GnFcYSpXO3+do9y4RMff iph44KU05hcyqriS3C4T57J8wIAoxEDO2O8mIaipJcnuwDptXRfA6m/mP75Xvy4SUZ4L cMXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pI2PSe031dP9Z8EwvDY5ZLfPiW1DefLEAiLsti8QtY0=; b=AFn9qqeRW/QRd1KEVmuIQEoLEr0Gr0ywUx5xJGCLTv1Oro9knV2zHXY56vhArd/QBu nzdEogUfBTbgv4ibSAcHOWC63vgmjpVIGe4UOT4KciHV0Zr0zMvtkoHDTTUyNLJfpPZf tm/s/uzNVXdxNs9XNqDD31FHGDnPan+hm7Vi04k7R618Q2pUcdGvXVAjfea+u7pybGMB s1Dh+e6VGuBH7fOrQGwzCfNp8bLn3kY8283NTN/8ldHZZjSNNfJpKFeeQ7c2lWFLBLOp aEnIo9l2ktMfMpSVGfWMETI0R8v8ZcmAyIFdi0PsI0P7RpN+TZDYtRnomodRCyZ+2/Oi Z2ng== X-Gm-Message-State: APjAAAVDT5C9UtE+pXwPAZyVX6OrEERYSFki4kGkvFQerm44xKa8UIlb ACb0amGLlvRYi55/+a6E1OW9ig== X-Google-Smtp-Source: APXvYqzJUAjpXa2e17Q7VNsYRg7QkA6+vpfoXH57EVW3KFDLy1stmy4WGh02y2yXJLnugq0jNsqYaA== X-Received: by 2002:adf:f591:: with SMTP id f17mr122722190wro.119.1564590319431; Wed, 31 Jul 2019 09:25:19 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id c30sm130677786wrb.15.2019.07.31.09.25.14 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:25:16 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id BA4D81FFC4; Wed, 31 Jul 2019 17:07:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:11 +0100 Message-Id: <20190731160719.11396-47-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH v4 46/54] tests/plugin: add sample plugins X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bobby.prani@gmail.com, cota@braap.org, =?utf-8?q?Alex_Benn=C3=A9e?= , aaron@os.amperecomputing.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" Pass arguments with -plugin=libfoo.so,arg=bar,arg=baz Signed-off-by: Emilio G. Cota Signed-off-by: Alex Bennée --- v4 - tweaks for hwaddr API --- configure | 4 +- tests/plugin/Makefile | 28 +++++++++++++ tests/plugin/bb.c | 65 +++++++++++++++++++++++++++++ tests/plugin/empty.c | 29 +++++++++++++ tests/plugin/insn.c | 62 ++++++++++++++++++++++++++++ tests/plugin/mem.c | 96 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 282 insertions(+), 2 deletions(-) create mode 100644 tests/plugin/Makefile create mode 100644 tests/plugin/bb.c create mode 100644 tests/plugin/empty.c create mode 100644 tests/plugin/insn.c create mode 100644 tests/plugin/mem.c diff --git a/configure b/configure index 7f6a1556fe2..26afcc6061b 100755 --- a/configure +++ b/configure @@ -8006,14 +8006,14 @@ fi # tests might fail. Prefer to keep the relevant files in their own # directory and symlink the directory instead. DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32 tests/libqos tests/qapi-schema tests/tcg/xtensa tests/qemu-iotests tests/vm" -DIRS="$DIRS tests/fp tests/qgraph" +DIRS="$DIRS tests/fp tests/qgraph tests/plugin" DIRS="$DIRS docs docs/interop fsdev scsi" DIRS="$DIRS pc-bios/optionrom pc-bios/spapr-rtas pc-bios/s390-ccw" DIRS="$DIRS roms/seabios roms/vgabios" LINKS="Makefile tests/tcg/Makefile" LINKS="$LINKS tests/tcg/cris/Makefile tests/tcg/cris/.gdbinit" LINKS="$LINKS tests/tcg/lm32/Makefile tests/tcg/xtensa/Makefile po/Makefile" -LINKS="$LINKS tests/fp/Makefile" +LINKS="$LINKS tests/fp/Makefile tests/plugin/Makefile" LINKS="$LINKS pc-bios/optionrom/Makefile pc-bios/keymaps" LINKS="$LINKS pc-bios/spapr-rtas/Makefile" LINKS="$LINKS pc-bios/s390-ccw/Makefile" diff --git a/tests/plugin/Makefile b/tests/plugin/Makefile new file mode 100644 index 00000000000..f9a3546ea32 --- /dev/null +++ b/tests/plugin/Makefile @@ -0,0 +1,28 @@ +BUILD_DIR := $(CURDIR)/../.. + +include $(BUILD_DIR)/config-host.mak +include $(SRC_PATH)/rules.mak + +$(call set-vpath, $(SRC_PATH)/tests/plugin) + +NAMES := +NAMES += bb +NAMES += empty +NAMES += insn +NAMES += mem + +SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES))) + +QEMU_CFLAGS += -fPIC +QEMU_CFLAGS += -I$(SRC_PATH)/include/qemu + +all: $(SONAMES) + +lib%.so: %.o + $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDLIBS) + +clean: + rm -f *.o *.so *.d + rm -Rf .libs + +.PHONY: all clean diff --git a/tests/plugin/bb.c b/tests/plugin/bb.c new file mode 100644 index 00000000000..93d25de3639 --- /dev/null +++ b/tests/plugin/bb.c @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2018, Emilio G. Cota + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#include +#include +#include +#include +#include +#include + +#include + +static uint64_t bb_count; +static uint64_t insn_count; +static int stdout_fd; +static bool do_inline; + +static void plugin_exit(qemu_plugin_id_t id, void *p) +{ + dprintf(stdout_fd, "bb's: %" PRIu64", insns: %" PRIu64 "\n", + bb_count, insn_count); +} + +static void vcpu_tb_exec(unsigned int cpu_index, void *udata) +{ + unsigned long n_insns = (unsigned long)udata; + + insn_count += n_insns; + bb_count++; +} + +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ + unsigned long n_insns = qemu_plugin_tb_n_insns(tb); + + if (do_inline) { + qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_ADD_U64, + &bb_count, 1); + qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_ADD_U64, + &insn_count, n_insns); + } else { + qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, + QEMU_PLUGIN_CB_NO_REGS, + (void *)n_insns); + } +} + +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, int argc, + char **argv) +{ + if (argc && strcmp(argv[0], "inline") == 0) { + do_inline = true; + } + + /* to be used when in the exit hook */ + stdout_fd = dup(STDOUT_FILENO); + assert(stdout_fd); + + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + return 0; +} diff --git a/tests/plugin/empty.c b/tests/plugin/empty.c new file mode 100644 index 00000000000..b141ddd0df4 --- /dev/null +++ b/tests/plugin/empty.c @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2018, Emilio G. Cota + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#include +#include +#include +#include +#include +#include + +#include + +/* + * Empty TB translation callback. + * This allows us to measure the overhead of injecting and then + * removing empty instrumentation. + */ +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ } + +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, int argc, + char **argv) +{ + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); + return 0; +} diff --git a/tests/plugin/insn.c b/tests/plugin/insn.c new file mode 100644 index 00000000000..3000ab4b731 --- /dev/null +++ b/tests/plugin/insn.c @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2018, Emilio G. Cota + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#include +#include +#include +#include +#include +#include + +#include + +static int stdout_fd; +static uint64_t insn_count; +static bool do_inline; + +static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata) +{ + insn_count++; +} + +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ + size_t n = qemu_plugin_tb_n_insns(tb); + size_t i; + + for (i = 0; i < n; i++) { + struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i); + + if (do_inline) { + qemu_plugin_register_vcpu_insn_exec_inline( + insn, QEMU_PLUGIN_INLINE_ADD_U64, &insn_count, 1); + } else { + qemu_plugin_register_vcpu_insn_exec_cb( + insn, vcpu_insn_exec_before, QEMU_PLUGIN_CB_NO_REGS, NULL); + } + } +} + +static void plugin_exit(qemu_plugin_id_t id, void *p) +{ + dprintf(stdout_fd, "insns: %" PRIu64 "\n", insn_count); +} + +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, int argc, + char **argv) +{ + if (argc && !strcmp(argv[0], "inline")) { + do_inline = true; + } + + /* to be used when in the exit hook */ + stdout_fd = dup(STDOUT_FILENO); + assert(stdout_fd); + + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + return 0; +} diff --git a/tests/plugin/mem.c b/tests/plugin/mem.c new file mode 100644 index 00000000000..e5490f4a99d --- /dev/null +++ b/tests/plugin/mem.c @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2018, Emilio G. Cota + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#include +#include +#include +#include +#include +#include + +#include + +static uint64_t mem_count; +static uint64_t io_count; +static int stdout_fd; +static bool do_inline; +static bool do_haddr; +static enum qemu_plugin_mem_rw rw = QEMU_PLUGIN_MEM_RW; + +static void plugin_exit(qemu_plugin_id_t id, void *p) +{ + dprintf(stdout_fd, "mem accesses: %" PRIu64 "\n", mem_count); + if (do_haddr) { + dprintf(stdout_fd, "io accesses: %" PRIu64 "\n", mem_count); + } +} + +static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, + uint64_t vaddr, void *udata) +{ + if (do_haddr) { + struct qemu_plugin_hwaddr *hwaddr; + hwaddr = qemu_plugin_get_hwaddr(meminfo, vaddr); + if (qemu_plugin_hwaddr_is_io(hwaddr)) { + io_count++; + } else { + mem_count++; + } + } else { + mem_count++; + } +} + +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ + size_t n = qemu_plugin_tb_n_insns(tb); + size_t i; + + for (i = 0; i < n; i++) { + struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i); + + if (do_inline) { + qemu_plugin_register_vcpu_mem_inline(insn, rw, + QEMU_PLUGIN_INLINE_ADD_U64, + &mem_count, 1); + } else { + qemu_plugin_register_vcpu_mem_cb(insn, vcpu_mem, + QEMU_PLUGIN_CB_NO_REGS, + rw, NULL); + } + } +} + +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, int argc, + char **argv) +{ + if (argc) { + if (argc >= 3) { + if (!strcmp(argv[2], "haddr")) { + do_haddr = true; + } + } + if (argc >= 2) { + const char *str = argv[1]; + + if (!strcmp(str, "r")) { + rw = QEMU_PLUGIN_MEM_R; + } else if (!strcmp(str, "w")) { + rw = QEMU_PLUGIN_MEM_W; + } + } + if (!strcmp(argv[0], "inline")) { + do_inline = true; + } + } + /* plugin_exit might write to stdout after stdout has been closed */ + stdout_fd = dup(STDOUT_FILENO); + assert(stdout_fd); + + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + return 0; +} From patchwork Wed Jul 31 16:07:12 2019 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: 11068717 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 321F013AC for ; Wed, 31 Jul 2019 16:29:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CF562012F for ; Wed, 31 Jul 2019 16:29:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E6BB20415; Wed, 31 Jul 2019 16:29:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8503D2012F for ; Wed, 31 Jul 2019 16:29:40 +0000 (UTC) Received: from localhost ([::1]:42790 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrTu-0008ES-P7 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:29:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45126) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrPj-0004qk-RA for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrPi-0000JV-GJ for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:19 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:42667) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrPi-0000HN-78 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:18 -0400 Received: by mail-wr1-x441.google.com with SMTP id x1so20467924wrr.9 for ; Wed, 31 Jul 2019 09:25:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JaUAcLe7WApBUvZggWzDrAHFeYLwHQ7XG4Fw2HOaxGw=; b=RSFIrqYEdE0/yJtJEOEytzg/HWvurEB5+6/0P4Y7M8RjoE3E19CgVLQ2nHgxHF50Oa Yo8s9TAN5BYiLAAzdx1Yvsx5J7WrTNv6Hq7xsztPBX6cx3gAgMYFsQ1++CanGF52bQQJ FmM2Sp3YvcjsAlqJt6F5iMSSAf6/K+JbYiH7iSYnmwrSAu2TXyAZqCt8CLh33s/lnkNn IZ3rAofmjv2nga/Wh3IirCS9TMvvsH1VHOFQG1ZnXTYr2q3443rwLboWgft2eoUaSkZE 3+B3Ah8cvE65Wxfs5NReXi+OyfgJItAIabF9puSzA4YcHIw2BWI2MpTQBZX3kq04Q5u/ v0zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JaUAcLe7WApBUvZggWzDrAHFeYLwHQ7XG4Fw2HOaxGw=; b=lQ9oYW8XFCvtz0rFI7d9DT+Yc+TtLwLeJA2TXHIMvInzAlCzHPbiO1OYCNyU4D3AtS BHp9ILEMQP845X+ySaCla6pFqW1rKMrkc+/ANopSkHnnLymKAEr7ZU960NkeAWoZKgHO 2slSODEPQEYENgTAabCkMIEvspHlUVrlykm3xO1ZqMXvR3B1Ro7NTuV8AJrPbdsw9dXg OedPQFlfDc6i1CtPbnFdHBy/VtEUi0tEyhFvnikdYIzE5aw9P5sRctmWMxYe17O+wqVp /avkyCEcfBpu0RsltrZWgj3rZfQqZbHm6mz0nzQQ8UxXq6LSsSRHaeTnvsiIHaoL+DlQ ncSA== X-Gm-Message-State: APjAAAUDOHRkDOf212Iyv6P+pyNdvlQflP2FsZHoEIiT1vdot+IJyfAN DPTDYO7+04j1/qGp+sSVFKWMyg== X-Google-Smtp-Source: APXvYqz3/YHQEZOTMAcbkA3Lf+i3exv17hiPoKmTxaxo6s+QWNg4ka/DQKghtk3X6i7WtFJBaDLD5Q== X-Received: by 2002:adf:f6d2:: with SMTP id y18mr59384191wrp.102.1564590316038; Wed, 31 Jul 2019 09:25:16 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id d10sm57418559wrx.34.2019.07.31.09.25.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:25:13 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id D022B1FFC5; Wed, 31 Jul 2019 17:07:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:12 +0100 Message-Id: <20190731160719.11396-48-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PATCH v4 47/54] tests/tcg: enable plugin testing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , aaron@os.amperecomputing.com, cota@braap.org, "open list:ARM TCG CPUs" , bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP If CONFIG_PLUGINS is enabled then lets enable testing for all our TCG targets. This is a simple smoke test that ensure we don't crash or otherwise barf out by running each plugin against each test. There is a minor knock on effect for additional runners which need specialised QEMU_OPTS which will also need to declare a plugin version of the runner. If this gets onerous we might need to add another helper. Checking the results of the plugins is left for a later exercise. Signed-off-by: Alex Bennée --- tests/Makefile.include | 10 +++++++- tests/tcg/Makefile | 34 +++++++++++++++++++++++++++ tests/tcg/arm/Makefile.softmmu-target | 1 + 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index fd7fdb86586..0611aede077 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -1052,6 +1052,14 @@ check-softfloat: "SKIPPED for non-TCG builds") endif +# Plugins +ifeq ($(CONFIG_PLUGIN),y) +plugins: + $(call quiet-command,\ + $(MAKE) $(SUBDIR_MAKEFLAGS) -C tests/plugin V="$(V)", \ + "BUILD", "plugins") +endif + # Per guest TCG tests BUILD_TCG_TARGET_RULES=$(patsubst %,build-tcg-tests-%, $(TARGET_DIRS)) @@ -1066,7 +1074,7 @@ $(foreach PROBE_TARGET,$(TARGET_DIRS), \ $(eval build-tcg-tests-$(PROBE_TARGET): $(DOCKER_PREREQ)))) endif -build-tcg-tests-%: +build-tcg-tests-%: $(if $(CONFIG_PLUGIN),plugins) $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $* V="$(V)" \ SKIP_DOCKER_BUILD=1 TARGET_DIR="$*/" guest-tests, \ "BUILD", "TCG tests for $*") diff --git a/tests/tcg/Makefile b/tests/tcg/Makefile index 9f567686240..8341a5345bc 100644 --- a/tests/tcg/Makefile +++ b/tests/tcg/Makefile @@ -120,11 +120,37 @@ all: $(TESTS) # RUN_TESTS=$(patsubst %,run-%, $(TESTS)) + +# If plugins exist also include those in the tests +ifeq ($(CONFIG_PLUGIN),y) +PLUGIN_DIR=../../tests/plugin +VPATH+=$(PLUGIN_DIR) +PLUGINS=$(notdir $(wildcard $(PLUGIN_DIR)/*.so)) + +# We need to ensure expand the run-plugin-TEST-with-PLUGIN +# pre-requistes manually here as we can't use stems to handle it. We +# also add some special helpers the run-plugin- rules can use bellow. + +$(foreach p,$(PLUGINS), \ + $(foreach t,$(TESTS),\ + $(eval run-plugin-$(t)-with-$(p): $t $p) \ + $(eval RUN_TESTS+=run-plugin-$(t)-with-$(p)))) +endif + +strip-plugin = $(wordlist 1, 1, $(subst -with-, ,$1)) +extract-plugin = $(wordlist 2, 2, $(subst -with-, ,$1)) + RUN_TESTS+=$(EXTRA_RUNS) ifdef CONFIG_USER_ONLY run-%: % $(call run-test, $<, $(QEMU) $(QEMU_OPTS) $<, "$< on $(TARGET_NAME)") + +run-plugin-%: + $(call run-test, $@, $(QEMU) $(QEMU_OPTS) \ + -plugin $(PLUGIN_DIR)/$(call extract-plugin,$@) \ + $(call strip-plugin,$<), \ + "$< on $(TARGET_NAME)") else run-%: % $(call run-test, $<, \ @@ -132,6 +158,14 @@ run-%: % -chardev file$(COMMA)path=$<.out$(COMMA)id=output \ $(QEMU_OPTS) $<, \ "$< on $(TARGET_NAME)") + +run-plugin-%: + $(call run-test, $@, \ + $(QEMU) -monitor none -display none \ + -chardev file$(COMMA)path=$@.out$(COMMA)id=output \ + -plugin $(PLUGIN_DIR)/$(call extract-plugin,$@) \ + $(QEMU_OPTS) $(call strip-plugin,$<), \ + "$< on $(TARGET_NAME)") endif gdb-%: % diff --git a/tests/tcg/arm/Makefile.softmmu-target b/tests/tcg/arm/Makefile.softmmu-target index 49d48d8a1c3..cd628306b3e 100644 --- a/tests/tcg/arm/Makefile.softmmu-target +++ b/tests/tcg/arm/Makefile.softmmu-target @@ -25,5 +25,6 @@ LDFLAGS+=-nostdlib -N -static test-armv6m-undef: EXTRA_CFLAGS+=-mcpu=cortex-m0 run-test-armv6m-undef: QEMU_OPTS+=-semihosting -M microbit -kernel +run-plugin-test-armv6m-undef-%: QEMU_OPTS+=-semihosting -M microbit -kernel endif From patchwork Wed Jul 31 16:07:13 2019 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: 11068739 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0C4C5112C for ; Wed, 31 Jul 2019 16:32:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAC85205A9 for ; Wed, 31 Jul 2019 16:32:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCB91205F7; Wed, 31 Jul 2019 16:32:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5D21D205A9 for ; Wed, 31 Jul 2019 16:32:54 +0000 (UTC) Received: from localhost ([::1]:42848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrX3-00057Y-Oj for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:32:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45209) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrPn-000527-ND for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrPm-0000N0-Fh for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:23 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:53598) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrPm-0000MG-8n for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:22 -0400 Received: by mail-wm1-x342.google.com with SMTP id x15so61507168wmj.3 for ; Wed, 31 Jul 2019 09:25:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=898tEWdGiv953asq1ongyZK/wyng6GChLBGHElMvPoQ=; b=gexkOurS8jNsbNusFYOIW6SeQiWs1BjBexsFvouTeFiDNAIFY/PSUuP1bKrqNMDCQ1 KJYUlPMI7Yei5R8KvuZkJek1A5rMUCn0nQM1LZZqGsYvvcDOlsPcMVsfBQsVkYZ9z4/9 ugktaMsy+VsFhW2v1NNl4BV/7tP33kgZnMAg2yvXXuJyVM2H135AxWGlxQK19C/UpbTP OeMjEBItE8Peu/WjPcE7OyLtIq8SWHc6vXRUtJESaz9bwxNTQF9dQamKRSS95jAbfvHM taAbmFqT+SiE8QBBE5YLY515Pj3UYnhhvrP+Wq96SFTeDpirJhwWVSSLEmJTeXxOpIAo SWuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=898tEWdGiv953asq1ongyZK/wyng6GChLBGHElMvPoQ=; b=WolpCh51rWnPK8UtxZyqKxyMTp7iQQFqsUC1ZdVoaA3XUMVMLMZlIkeNf3ATQLI56D +bu3gTjuSs2mMs9tXzmjRBElqnpmnAHoIPJVlFZZ/chN9WajI1r21SDMa9sbgrd2aS80 0NJ8u7Py2N/Bw3MKkoTFUtDXJVecSXy7z76EGYSEywAvXpF+lXORULNccMJ/pMrqmhbs D/tzfSoxZ13iwFa4AqqaKVVzTrz++y3qKFhHOUWHC6nqTpuWNtnHARLCZKUszJ2q6g5l 0ditOxKNbF6sFEgXJ2CbcwSHUnCqdoyBj6VFt6rrJGqo/xnsH3XcO2DXc0emKQ4n+Ugr dICQ== X-Gm-Message-State: APjAAAVrVi7+ShTnsK77P8eW44wNfecZC93UGcuECKf+02TVPi1uzSMB WFAHJldQEyDwo7/3idDgj+a8ig== X-Google-Smtp-Source: APXvYqzk/p2MlFFfstjPpWfDlo9YswlPRmvPD+VXlyUGmgVleNaUaVzyIkpfzvX/XKpsgcvA4VxsgQ== X-Received: by 2002:a05:600c:230c:: with SMTP id 12mr14294064wmo.151.1564590321196; Wed, 31 Jul 2019 09:25:21 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id q193sm54698640wme.8.2019.07.31.09.25.15 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:25:17 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id E58F51FFC6; Wed, 31 Jul 2019 17:07:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:13 +0100 Message-Id: <20190731160719.11396-49-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 Subject: [Qemu-devel] [PATCH v4 48/54] tests/plugin: add a hotblocks plugin X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bobby.prani@gmail.com, cota@braap.org, =?utf-8?q?Alex_Benn=C3=A9e?= , aaron@os.amperecomputing.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This is a simple plugin to track which translation blocks are call most often. As we don't have a view of the internals of TCG we can only work by the address of the start of the block so we also need to tracks how often the address is translated. As there will be multiple blocks starting at the same address. We can try and work around this by futzing the value to feed to the hash with the insn count. Signed-off-by: Alex Bennée --- tests/plugin/Makefile | 1 + tests/plugin/hotblocks.c | 146 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 tests/plugin/hotblocks.c diff --git a/tests/plugin/Makefile b/tests/plugin/Makefile index f9a3546ea32..e74940eaac5 100644 --- a/tests/plugin/Makefile +++ b/tests/plugin/Makefile @@ -10,6 +10,7 @@ NAMES += bb NAMES += empty NAMES += insn NAMES += mem +NAMES += hotblocks SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES))) diff --git a/tests/plugin/hotblocks.c b/tests/plugin/hotblocks.c new file mode 100644 index 00000000000..3654afbc887 --- /dev/null +++ b/tests/plugin/hotblocks.c @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2019, Alex Bennée + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +static bool do_inline; +static int stdout_fd; + +/* Plugins need to take care of their own locking */ +static GMutex lock; +static GHashTable *hotblocks; +static guint64 limit = 20; + +/* + * Counting Structure + * + * The internals of the TCG are not exposed to plugins so we can only + * get the starting PC for each block. We cheat this slightly by + * xor'ing the number of instructions to the hash to help + * differentiate. + */ +typedef struct { + uint64_t start_addr; + uint64_t exec_count; + int trans_count; + unsigned long insns; +} ExecCount; + +static gint cmp_exec_count(gconstpointer a, gconstpointer b) +{ + ExecCount *ea = (ExecCount *) a; + ExecCount *eb = (ExecCount *) b; + return ea->exec_count > eb->exec_count ? -1 : 1; +} + +static void plugin_exit(qemu_plugin_id_t id, void *p) +{ + GString *report = g_string_new("collected "); + GList *counts, *it; + int i; + + g_mutex_lock(&lock); + g_string_append_printf(report, "%d entries in the hash table\n", + g_hash_table_size(hotblocks)); + counts = g_hash_table_get_values(hotblocks); + it = g_list_sort(counts, cmp_exec_count); + + g_string_append_printf(report, "pc, tcount, icount, ecount\n"); + + for (i = 0; i < limit && it->next; i++, it = it->next) { + ExecCount *rec = (ExecCount *) it->data; + g_string_append_printf(report, "%#016"PRIx64", %d, %ld, %"PRId64"\n", + rec->start_addr, rec->trans_count, + rec->insns, rec->exec_count); + } + + g_mutex_unlock(&lock); + g_list_free(it); + + dprintf(stdout_fd, "%s", report->str); + g_string_free(report, true); +} + +static void plugin_init(void) +{ + hotblocks = g_hash_table_new(NULL, g_direct_equal); +} + +static void vcpu_tb_exec(unsigned int cpu_index, void *udata) +{ + ExecCount *cnt; + uint64_t hash = (uint64_t) udata; + + g_mutex_lock(&lock); + cnt = (ExecCount *) g_hash_table_lookup(hotblocks, (gconstpointer) hash); + /* should always succeed */ + g_assert(cnt); + cnt->exec_count++; + g_mutex_unlock(&lock); +} + +/* + * When do_inline we ask the plugin to increment the counter for us. + * Otherwise a helper is inserted which calls the vcpu_tb_exec + * callback. + */ +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ + ExecCount *cnt; + uint64_t pc = qemu_plugin_tb_vaddr(tb); + unsigned long insns = qemu_plugin_tb_n_insns(tb); + uint64_t hash = pc ^ insns; + + g_mutex_lock(&lock); + cnt = (ExecCount *) g_hash_table_lookup(hotblocks, (gconstpointer) hash); + if (cnt) { + cnt->trans_count++; + } else { + cnt = g_new0(ExecCount, 1); + cnt->start_addr = pc; + cnt->trans_count = 1; + cnt->insns = insns; + g_hash_table_insert(hotblocks, (gpointer) hash, (gpointer) cnt); + } + + g_mutex_unlock(&lock); + + if (do_inline) { + qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_ADD_U64, + &cnt->exec_count, 1); + } else { + qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, + QEMU_PLUGIN_CB_NO_REGS, + (void *)hash); + } +} + +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, int argc, + char **argv) +{ + if (argc && strcmp(argv[0], "inline") == 0) { + do_inline = true; + } + + /* to be used when in the exit hook */ + stdout_fd = dup(STDOUT_FILENO); + assert(stdout_fd); + + plugin_init(); + + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + return 0; +} From patchwork Wed Jul 31 16:07:14 2019 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: 11068713 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9421513AC for ; Wed, 31 Jul 2019 16:28:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F7B32000A for ; Wed, 31 Jul 2019 16:28:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7403A203B9; Wed, 31 Jul 2019 16:28:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6065A2000A for ; Wed, 31 Jul 2019 16:28:47 +0000 (UTC) Received: from localhost ([::1]:42772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrT4-0005nL-LF for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:28:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45060) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrPh-0004l4-OM for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrPg-0000Gq-9I for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:17 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:44292) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrPg-0000G4-2v for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:16 -0400 Received: by mail-wr1-x443.google.com with SMTP id p17so70350835wrf.11 for ; Wed, 31 Jul 2019 09:25:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BnGODuR3Ycz5wS1Vq+gAFUjpRMhPGEguKfmXZgD+ipE=; b=xnEFkAm/zWatmrROcSkSEvr63uPFYqEEk3yDbnOK6SwJW68+amL9e+gaCXhGJ7nKh4 NLHzib3BT7uCP1EEqeLXgmyFER8zK2oJNK+YdF61icDx3hOjxwhkWu+xTFWmwKv8P+fR eYswyn+ru1s9xOowYI1p+DqcETTZ+PSJSGyuXp43oWoWsmKO2HeSUKuDf7sAivKQtzFj ucjrZN1ZNE/kc97sNfCY37euJ7fGHJD52Hy/SjpZZERS8i9+V4PJ9hvhu0e7Fuyxctgb KcNO3hO3Kv86zgvkSthjh/p6tmhJLggn15WI3vlmxyMiAjXxmOmpvu7mlLrHEYe0zx26 VFkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BnGODuR3Ycz5wS1Vq+gAFUjpRMhPGEguKfmXZgD+ipE=; b=WwrdBN3hz/EG5Y7CXitkonUsxKlaQmKWCX3fLgUMI004qG7q7v8ckv0mTjcq0FSyPf AHk5mrFvAftlHGawOD+1CfPsPI61V09wbOBfl9ZC7DF6CIwX0ayUu+V9B4umtbMJxiJl pEGodtlKyqgHC9EMJPbQrgYwX47KsCY4Yuhn6pU9gkrtcBWPqsibzH+CQcJ3BeM9B04D lvJO92yc0vhbFXz0Al0zI15eVhS7ogtOj2cSGGyk+QwVJc0ccbXJaoiEGNC7r41w6i5m OdG7Hob/VpaomHWjbxzKJ+wBN9j4NY+fo5CwqAT2ms8bl/2taUBF7d41QdOoU8+OPHox FOTg== X-Gm-Message-State: APjAAAUD5nJrOiox82UCAnyjMdmojIuK8ML8IVcEb3iw2b5I3S6aBGeC YHzRDglqST9IK08JeJef0A9r9w== X-Google-Smtp-Source: APXvYqzG0hFrgZLJ/WmOs174TOIh5X5FgoaT1X8dTrw70jFjKYp78d1dosIHTVoIUfRxXliwTtzhbw== X-Received: by 2002:adf:d08e:: with SMTP id y14mr106235925wrh.309.1564590315002; Wed, 31 Jul 2019 09:25:15 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id x20sm157165737wrg.10.2019.07.31.09.25.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:25:13 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 09B251FFC7; Wed, 31 Jul 2019 17:07:24 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:14 +0100 Message-Id: <20190731160719.11396-50-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [PATCH v4 49/54] plugin: add qemu_plugin_insn_disas helper X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , bobby.prani@gmail.com, cota@braap.org, =?utf-8?q?Alex_Benn=C3=A9e?= , aaron@os.amperecomputing.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Give the plugins access to the QEMU dissasembler so they don't have to re-invent the wheel. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- disas.c | 103 +++++++++++++++++++++++++++++++++++ include/disas/disas.h | 2 + include/qemu/qemu-plugin.h | 9 +++ plugins/api.c | 7 +++ plugins/qemu-plugins.symbols | 1 + 5 files changed, 122 insertions(+) diff --git a/disas.c b/disas.c index 3e2bfa572b1..4b127369c36 100644 --- a/disas.c +++ b/disas.c @@ -475,6 +475,109 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code, } } +static GString plugin_disas_output; + +static int plugin_printf(FILE *stream, const char *fmt, ...) +{ + va_list va; + GString *s = &plugin_disas_output; + int initial_len = s->len; + + va_start(va, fmt); + g_string_append_printf(s, fmt, va); + va_end(va); + + return s->len - initial_len; +} + +static void plugin_print_address(bfd_vma addr, struct disassemble_info *info) +{ + /* does nothing */ +} + +/* Disassemble a single instruction directly into plugin output */ +static +bool plugin_cap_disas_insn(disassemble_info *info, uint64_t pc, size_t size) +{ + uint8_t cap_buf[1024]; + csh handle; + cs_insn *insn; + size_t csize = 0; + int count; + GString *s = &plugin_disas_output; + + if (cap_disas_start(info, &handle) != CS_ERR_OK) { + return false; + } + insn = cap_insn; + + size_t tsize = MIN(sizeof(cap_buf) - csize, size); + const uint8_t *cbuf = cap_buf; + target_read_memory(pc, cap_buf, tsize, info); + + count = cs_disasm(handle, cbuf, size, 0, 1, &insn); + + if (count) { + g_string_printf(s, "%s %s", insn->mnemonic, insn->op_str); + } else { + g_string_printf(s, "cs_disasm failed"); + } + + cs_close(&handle); + return true; +} + +char * plugin_disas(CPUState *cpu, uint64_t addr, size_t size) +{ + CPUClass *cc = CPU_GET_CLASS(cpu); + target_ulong pc; + int count; + CPUDebug s; + GString *ds = g_string_set_size(&plugin_disas_output, 0); + + g_assert(ds == &plugin_disas_output); + + INIT_DISASSEMBLE_INFO(s.info, NULL, plugin_printf); + + s.cpu = cpu; + s.info.read_memory_func = target_read_memory; + s.info.buffer_vma = addr; + s.info.buffer_length = size; + s.info.print_address_func = plugin_print_address; + s.info.cap_arch = -1; + s.info.cap_mode = 0; + s.info.cap_insn_unit = 4; + s.info.cap_insn_split = 4; + +#ifdef TARGET_WORDS_BIGENDIAN + s.info.endian = BFD_ENDIAN_BIG; +#else + s.info.endian = BFD_ENDIAN_LITTLE; +#endif + + if (cc->disas_set_info) { + cc->disas_set_info(cpu, &s.info); + } + + if (s.info.cap_arch >= 0 && plugin_cap_disas_insn(&s.info, addr, size)) { + return g_strdup(ds->str); + } + + if (s.info.print_insn == NULL) { + s.info.print_insn = print_insn_od_target; + } + + for (pc = addr; size > 0; pc += count, size -= count) { + count = s.info.print_insn(pc, &s.info); + if (count < 0) { + break; + } + g_assert(size >= count); + } + + return g_strdup(ds->str); +} + /* Disassemble this for me please... (debugging). */ void disas(FILE *out, void *code, unsigned long size) { diff --git a/include/disas/disas.h b/include/disas/disas.h index 15da511f49c..119df9e9bdf 100644 --- a/include/disas/disas.h +++ b/include/disas/disas.h @@ -13,6 +13,8 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code, void monitor_disas(Monitor *mon, CPUState *cpu, target_ulong pc, int nb_insn, int is_physical); +char * plugin_disas(CPUState *cpu, uint64_t addr, size_t size); + /* Look up symbol for debugging purpose. Returns "" if unknown. */ const char *lookup_symbol(target_ulong orig_addr); #endif diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index d9c1ca3b4cf..8b403dd6157 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -324,6 +324,15 @@ qemu_plugin_register_vcpu_syscall_ret_cb(qemu_plugin_id_t id, qemu_plugin_vcpu_syscall_ret_cb_t cb); +/** + * qemu_plugin_insn_disas() - return disassembly string for instruction + * @insn: instruction reference + * + * Returns an allocated string containing the disassembly + */ + +char * qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn); + /** * qemu_plugin_vcpu_for_each() - iterate over the existing vCPU * @id: plugin ID diff --git a/plugins/api.c b/plugins/api.c index 4b3ac9e31fb..5a0bed1b1e0 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -40,6 +40,7 @@ #include "sysemu/sysemu.h" #include "tcg/tcg.h" #include "exec/exec-all.h" +#include "disas/disas.h" #include "plugin.h" #ifndef CONFIG_USER_ONLY #include "hw/boards.h" @@ -211,6 +212,12 @@ void *qemu_plugin_insn_haddr(const struct qemu_plugin_insn *insn) return insn->haddr; } +char *qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn) +{ + CPUState *cpu = current_cpu; + return plugin_disas(cpu, insn->vaddr, insn->data->len); +} + /* * The memory queries allow the plugin to query information about a * memory access. diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 40c0d1abd2f..267ec381b4a 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -25,6 +25,7 @@ qemu_plugin_insn_size; qemu_plugin_insn_vaddr; qemu_plugin_insn_haddr; + qemu_plugin_insn_disas; qemu_plugin_mem_size_shift; qemu_plugin_mem_is_sign_extended; qemu_plugin_mem_is_big_endian; From patchwork Wed Jul 31 16:07:15 2019 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: 11068675 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AC972912 for ; Wed, 31 Jul 2019 16:23:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 976AC2012F for ; Wed, 31 Jul 2019 16:23:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A82D2018F; Wed, 31 Jul 2019 16:23:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B8F302012F for ; Wed, 31 Jul 2019 16:23:44 +0000 (UTC) Received: from localhost ([::1]:42590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrOB-0000WV-S0 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:23:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42509) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrGA-00068W-Th for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrG8-0004CZ-V2 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:26 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]:40609) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrG8-0004Bl-NC for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:24 -0400 Received: by mail-wm1-x32c.google.com with SMTP id v19so60387930wmj.5 for ; Wed, 31 Jul 2019 09:15:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xwP+mV0r3qT985xxGF4TCqT0a6cc9tGilhISQJihOk8=; b=ib3eNgFRsowNuceFgiSQlQ3r2izO2U77qb3q2+PRrv2Fb5i3/T+lFFh8nKNfWbDqYG V8PUbSTC7kaVzYa96HSn/7B7JGm1YvFfaOwQ1DRUOctmE/hsMQEhuQh/EfadbrwnPY1K /IEOujmnF5RN8p5Ym7t9k2b7IH5KQeYPSo9K69w8gd/mQSkG9EkBDTIhMTCNoXZMPIHv 3dD2Sys8GJ9Zw0+Sudo0bWxxDEdECAEGQqXde6nat5/JmDlgpznR22ooIoI8CyS0RpKA tnIKIPc3y/SNePcPmPk/m5396X2yvD0vBBy1ZbDWS4rfDRTk6jqzdzucnoS6FqWg3FYf Xlkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xwP+mV0r3qT985xxGF4TCqT0a6cc9tGilhISQJihOk8=; b=sD1aCgmuqBQhPFE02fJhIEwkLvwLW23XxJZOumt2V2keLw9tKKdgXo+SeBL2FnZ9xh 3H/5UfWcCEuSPt5vyHZOdubrS9zgTC7KCOzy0o1C+D7LhequMo7GNsPYYydcDq1sVlTC NAqwp3kWcTsNbHro6MPUwdOvxZIZA1ZLxRTWMvBx9khHZfvZ6oV/g4w3DBNiJMoIxI4Y vrw5JHfFH+bJx7981c6qS7fpNeL7nqiOh+YIQeZwDb80WDAamlCV3dvOLscAzWAZas6B BENN4zYa2JYknmVEg3FVXGrYaesGc2J/cP0c1iQGAkwVOXBDlLxyN0RMuTd4c6XPb1I/ rKQQ== X-Gm-Message-State: APjAAAVCoi4rVva50Ri9jzr6sn6iGvZCdgVBV6D7MZk5a4yazGisLIng /EjEUhbG7S6VJkfLXR54XF9LYA== X-Google-Smtp-Source: APXvYqw5SnAM0P2MRNGTZrpZD9RrGxfHaM79RruQ2iUySw07WKKx2HCOMAhQB8UxC116gPhSJHd9lw== X-Received: by 2002:a1c:c5c2:: with SMTP id v185mr118307155wmf.161.1564589723370; Wed, 31 Jul 2019 09:15:23 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id z25sm71736508wmf.38.2019.07.31.09.15.16 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:15:18 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 1E31B1FFC8; Wed, 31 Jul 2019 17:07:24 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:15 +0100 Message-Id: <20190731160719.11396-51-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32c Subject: [Qemu-devel] [PATCH v4 50/54] tests/plugin: add instruction execution breakdown X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bobby.prani@gmail.com, cota@braap.org, =?utf-8?q?Alex_Benn=C3=A9e?= , aaron@os.amperecomputing.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This gives a break down of instruction classes and individual instruction types. Signed-off-by: Alex Bennée --- tests/plugin/Makefile | 1 + tests/plugin/howvec.c | 301 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 302 insertions(+) create mode 100644 tests/plugin/howvec.c diff --git a/tests/plugin/Makefile b/tests/plugin/Makefile index e74940eaac5..3656429d46b 100644 --- a/tests/plugin/Makefile +++ b/tests/plugin/Makefile @@ -11,6 +11,7 @@ NAMES += empty NAMES += insn NAMES += mem NAMES += hotblocks +NAMES += howvec SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES))) diff --git a/tests/plugin/howvec.c b/tests/plugin/howvec.c new file mode 100644 index 00000000000..accf8611ff4 --- /dev/null +++ b/tests/plugin/howvec.c @@ -0,0 +1,301 @@ +/* + * Copyright (C) 2019, Alex Bennée + * + * How vectorised is this code? + * + * Attempt to measure the amount of vectorisation that has been done + * on some code by counting classes of instruction. This is very much + * ARM specific. + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +typedef enum { + COUNT_CLASS, + COUNT_INDIVIDUAL, + COUNT_NONE +} CountType; + +static int limit = 50; +static int stdout_fd; +static bool do_inline; +static bool verbose; + +static GMutex lock; +static GHashTable *insns; + +typedef struct { + const char *class; + const char *opt; + uint32_t mask; + uint32_t pattern; + CountType what; + uint64_t count; +} InsnClassExecCount; + +typedef struct { + char *insn; + uint32_t opcode; + uint64_t count; + InsnClassExecCount *class; +} InsnExecCount; + +/* + * Matchers for classes of instructions, order is important. + * + * Your most precise match must be before looser matches. If no match + * is found in the table we can create an individual entry. + */ +InsnClassExecCount insn_classes[] = { + /* "Reserved"" */ + { " UDEF", "udef", 0xffff0000, 0x00000000, COUNT_NONE}, + { " SVE", "sve", 0x1e000000, 0x04000000, COUNT_CLASS}, + { "Reserved", "res", 0x1e000000, 0x00000000, COUNT_CLASS}, + /* Data Processing Immediate */ + { " PCrel addr", "pcrel", 0x1f000000, 0x10000000, COUNT_CLASS}, + { " Add/Sub (imm,tags)","asit", 0x1f800000, 0x11800000, COUNT_CLASS}, + { " Add/Sub (imm)", "asi", 0x1f000000, 0x11000000, COUNT_CLASS}, + { " Logical (imm)", "logi", 0x1f800000, 0x12000000, COUNT_CLASS}, + { " Move Wide (imm)", "movwi", 0x1f800000, 0x12800000, COUNT_CLASS}, + { " Bitfield", "bitf", 0x1f800000, 0x13000000, COUNT_CLASS}, + { " Extract", "extr", 0x1f800000, 0x13800000, COUNT_CLASS}, + { "Data Proc Imm", "dpri", 0x1c000000, 0x10000000, COUNT_CLASS}, + /* Branches */ + { " Cond Branch (imm)", "cndb", 0xfe000000, 0x54000000, COUNT_CLASS}, + { " Exception Gen", "excp", 0xff000000, 0xd4000000, COUNT_CLASS}, + { " NOP", "nop", 0xffffffff, 0xd503201f, COUNT_NONE}, + { " Hints", "hint", 0xfffff000, 0xd5032000, COUNT_CLASS}, + { " Barriers", "barr", 0xfffff000, 0xd5033000, COUNT_CLASS}, + { " PSTATE", "psta", 0xfff8f000, 0xd5004000, COUNT_CLASS}, + { " System Insn", "sins", 0xffd80000, 0xd5080000, COUNT_CLASS}, + { " System Reg", "sreg", 0xffd00000, 0xd5100000, COUNT_CLASS}, + { " Branch (reg)", "breg", 0xfe000000, 0xd6000000, COUNT_CLASS}, + { " Branch (imm)", "bimm", 0x7c000000, 0x14000000, COUNT_CLASS}, + { " Cmp & Branch", "cmpb", 0x7e000000, 0x34000000, COUNT_CLASS}, + { " Tst & Branch", "tstb", 0x7e000000, 0x36000000, COUNT_CLASS}, + { "Branches", "branch", 0x1c000000, 0x14000000, COUNT_CLASS}, + /* Loads and Stores */ + { " AdvSimd ldstmult", "advlsm", 0xbfbf0000, 0x0c000000, COUNT_CLASS}, + { " AdvSimd ldstmult++","advlsmp",0xbfb00000, 0x0c800000, COUNT_CLASS}, + { " AdvSimd ldst", "advlss", 0xbf9f0000, 0x0d000000, COUNT_CLASS}, + { " AdvSimd ldst++", "advlssp",0xbf800000, 0x0d800000, COUNT_CLASS}, + { " ldst excl", "ldstx", 0x3f000000, 0x08000000, COUNT_CLASS}, + { " Prefetch", "prfm", 0xff000000, 0xd8000000, COUNT_CLASS}, + { " Load Reg (lit)", "ldlit", 0x1b000000, 0x18000000, COUNT_CLASS}, + { " ldst noalloc pair", "ldstnap",0x3b800000, 0x28000000, COUNT_CLASS}, + { " ldst pair", "ldstp", 0x38000000, 0x28000000, COUNT_CLASS}, + { " ldst reg", "ldstr", 0x3b200000, 0x38000000, COUNT_CLASS}, + { " Atomic ldst", "atomic", 0x3b200c00, 0x38200000, COUNT_CLASS}, + { " ldst reg (reg off)","ldstro", 0x3b200b00, 0x38200800, COUNT_CLASS}, + { " ldst reg (pac)", "ldstpa", 0x3b200200, 0x38200800, COUNT_CLASS}, + { " ldst reg (imm)", "ldsti", 0x3b000000, 0x39000000, COUNT_CLASS}, + { "Loads & Stores", "ldst", 0x0a000000, 0x08000000, COUNT_CLASS}, + /* Data Processing Register */ + { "Data Proc Reg", "dprr", 0x0e000000, 0x0a000000, COUNT_CLASS}, + /* Scalar FP */ + { "Scalar FP ", "fpsimd", 0x0e000000, 0x0e000000, COUNT_CLASS}, + /* Unclassified */ + { "Unclassified", "unclas", 0x00000000, 0x00000000, COUNT_CLASS} +}; + +static gint cmp_exec_count(gconstpointer a, gconstpointer b) +{ + InsnExecCount *ea = (InsnExecCount *) a; + InsnExecCount *eb = (InsnExecCount *) b; + return ea->count > eb->count ? -1 : 1; +} + +static void plugin_exit(qemu_plugin_id_t id, void *p) +{ + GString *report = g_string_new("Instruction Classes:\n"); + int i; + GList *counts; + + for (i = 0; i < ARRAY_SIZE(insn_classes); i++) { + switch (insn_classes[i].what) { + case COUNT_CLASS: + if (insn_classes[i].count || verbose) { + g_string_append_printf(report, "Class: %-24s\t(%ld hits)\n", + insn_classes[i].class, + insn_classes[i].count); + } + break; + case COUNT_INDIVIDUAL: + g_string_append_printf(report, "Class: %-24s\tcounted individually\n", + insn_classes[i].class); + break; + case COUNT_NONE: + g_string_append_printf(report, "Class: %-24s\tnot counted\n", + insn_classes[i].class); + break; + default: + break; + } + } + + counts = g_hash_table_get_values(insns); + if (counts && g_list_next(counts)) { + GList *it; + + g_string_append_printf(report,"Individual Instructions:\n"); + + it = g_list_sort(counts, cmp_exec_count); + + for (i = 0; i < limit && it->next; i++, it = it->next) { + InsnExecCount *rec = (InsnExecCount *) it->data; + g_string_append_printf(report, "Instr: %-24s\t(%ld hits)\t(op=%#08x/%s)\n", + rec->insn, + rec->count, + rec->opcode, + rec->class ? + rec->class->class : "un-categorised"); + } + g_list_free(it); + } + + dprintf(stdout_fd, "%s", report->str); + g_string_free(report, true); +} + +static void plugin_init(void) +{ + insns = g_hash_table_new(NULL, g_direct_equal); +} + +static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata) +{ + uint64_t *count = (uint64_t *) udata; + (*count)++; +} + +static uint64_t * find_counter(struct qemu_plugin_insn *insn) +{ + int i; + uint64_t *cnt = NULL; + uint32_t opcode; + InsnClassExecCount *class = NULL; + + /* we expect all instructions to by 32 bits for ARM */ + g_assert(qemu_plugin_insn_size(insn) == 4); + opcode = *((uint32_t *)qemu_plugin_insn_data(insn)); + + for (i = 0; !cnt && i < ARRAY_SIZE(insn_classes); i++) { + uint32_t masked_bits = opcode & insn_classes[i].mask; + if (masked_bits == insn_classes[i].pattern) { + class = &insn_classes[i]; + break; + } + } + + g_assert(class); + + switch (class->what) { + case COUNT_NONE: + return NULL; + case COUNT_CLASS: + return &class->count; + case COUNT_INDIVIDUAL: + { + InsnExecCount *icount; + + g_mutex_lock(&lock); + icount = (InsnExecCount *) g_hash_table_lookup(insns, + GUINT_TO_POINTER(opcode)); + + if (!icount) { + icount = g_new0(InsnExecCount, 1); + icount->opcode = opcode; + icount->insn = qemu_plugin_insn_disas(insn); + icount->class = class; + + if (verbose) { + dprintf(stdout_fd, "adding for %s (%#08x @ %#20lx from %s)\n", + icount->insn, opcode, qemu_plugin_insn_vaddr(insn), + class->class); + } + g_hash_table_insert(insns, GUINT_TO_POINTER(opcode), + (gpointer) icount); + } + g_mutex_unlock(&lock); + + return &icount->count; + } + default: + g_assert_not_reached(); + } + + return NULL; +} + +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ + size_t n = qemu_plugin_tb_n_insns(tb); + size_t i; + + for (i = 0; i < n; i++) { + uint64_t *cnt; + struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i); + cnt = find_counter(insn); + + if (cnt) { + if (do_inline) { + qemu_plugin_register_vcpu_insn_exec_inline( + insn, QEMU_PLUGIN_INLINE_ADD_U64, cnt, 1); + } else { + qemu_plugin_register_vcpu_insn_exec_cb( + insn, vcpu_insn_exec_before, QEMU_PLUGIN_CB_NO_REGS, cnt); + } + } + } +} + +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, int argc, + char **argv) +{ + int i; + + for (i = 0; i < argc; i++) { + char *p = argv[i]; + if (strcmp(p, "inline") == 0) { + do_inline = true; + } else if (strcmp(p, "verbose") == 0) { + verbose = true; + } else { + int j; + CountType type = COUNT_INDIVIDUAL; + if (*p == '!') { + type = COUNT_NONE; + p++; + } + for (j = 0; j < ARRAY_SIZE(insn_classes); j++) { + if (strcmp(p, insn_classes[j].opt) == 0) { + insn_classes[j].what = type; + break; + } + } + } + } + + /* to be used when in the exit hook */ + stdout_fd = dup(STDOUT_FILENO); + assert(stdout_fd); + + plugin_init(); + + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + return 0; +} From patchwork Wed Jul 31 16:07:16 2019 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: 11068693 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 507D0912 for ; Wed, 31 Jul 2019 16:26:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DB24203B9 for ; Wed, 31 Jul 2019 16:26:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 31DDD20453; Wed, 31 Jul 2019 16:26:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A4D51203B9 for ; Wed, 31 Jul 2019 16:26:58 +0000 (UTC) Received: from localhost ([::1]:42722 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrRJ-0000dT-U1 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:26:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42439) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrG8-0005zJ-G9 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrG6-0004AB-4I for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:24 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:33461) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrG5-00048p-Rq for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:22 -0400 Received: by mail-wm1-x344.google.com with SMTP id h19so1641598wme.0 for ; Wed, 31 Jul 2019 09:15:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JAsL9lKxpSV7gJFxFeCPfJnq/9l3IF3WkKcMWFNHkFQ=; b=Gofb3qoizzTEFOrIm6gY/3mjfRv4Me7XXMW1YJZSHIoq1utaJv189tPrtL+XPVsmTR XLEiDlX9ibfSFJE+ujZ0Ch3FDJqLg+2CcL714dkzfrHcBv9SiwWkb9kBvD9tNc2lT12p Vdf9eklBWH7NMxoYY4EqbxzwoRRmntM4X5pJE+Vye8PTzPduhdNaPgyNwuJFMhy/kR2w i6fa+VwJnzioj6YzGhfZ1xpEpcgwxWO6ws1Q6FbgqAhftu5DXfMJ+P8bR2K3ozDEJvD3 3M/JcqbeHm7NYiDZw/466sh9fZT/aIKSmPgAo+IawBPynCH4iHXT5979K8bXB0XgZ1oO 2Bkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JAsL9lKxpSV7gJFxFeCPfJnq/9l3IF3WkKcMWFNHkFQ=; b=YWiQNGugSU2KNJapd1T3GZ48jqCYUoroUpc7j/nD//Ila+Kpa95XwR8+LZcg+jl+w1 605+EJ1D1MQHcd2+g9kuRvEZ6HN8BNbm6n33kPIIMYfJ+7Fmk+lcPmuY48uOZ3bQBvbc l3kA4XtbFcqTGj1ow2aQpgXvze/0PLt1v3fWXf0CeWXxABRB+fzE2IDMgiiB3nyhxfAV yeW1NVFjjIaxihEnzs3Ra2lPiNuxOrklF51L/98l4u3t9mhIyogno1JYntwBR018OaKd 2SwbMYeXJWiMBftxFrG54TCtqGCyTqrKZxfk5RRnsTH8cLWIIpihirmOA20C+10LYier TRdA== X-Gm-Message-State: APjAAAWpouphnFzV3i0/tZGW4RymCPGGmQtGSdR+fR0ZPGlUXyT1BueL lOtKW9LcURcRYki3jP95fFoGPQ== X-Google-Smtp-Source: APXvYqweIncqGHtkBm9WAAowNUtnX7rzJ9XJod8v0iIgCDeMguinb185qEsp46reHChWw6zAMdg8YQ== X-Received: by 2002:a1c:a686:: with SMTP id p128mr50348737wme.130.1564589720435; Wed, 31 Jul 2019 09:15:20 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id p18sm68312914wrm.16.2019.07.31.09.15.14 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:15:17 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 338C11FFC9; Wed, 31 Jul 2019 17:07:24 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:16 +0100 Message-Id: <20190731160719.11396-52-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 Subject: [Qemu-devel] [PATCH v4 51/54] tests/plugin: add hotpages plugin to breakdown memory access patterns X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bobby.prani@gmail.com, cota@braap.org, =?utf-8?q?Alex_Benn=C3=A9e?= , aaron@os.amperecomputing.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This plugin gives a break down of access patterns grouped into pages. Signed-off-by: Alex Bennée --- v4 - tweaks for new hwaddr api - add sorting and pagesize selection args --- tests/plugin/Makefile | 1 + tests/plugin/hotpages.c | 179 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 tests/plugin/hotpages.c diff --git a/tests/plugin/Makefile b/tests/plugin/Makefile index 3656429d46b..75467b6db85 100644 --- a/tests/plugin/Makefile +++ b/tests/plugin/Makefile @@ -12,6 +12,7 @@ NAMES += insn NAMES += mem NAMES += hotblocks NAMES += howvec +NAMES += hotpages SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES))) diff --git a/tests/plugin/hotpages.c b/tests/plugin/hotpages.c new file mode 100644 index 00000000000..13ce8ffeb8b --- /dev/null +++ b/tests/plugin/hotpages.c @@ -0,0 +1,179 @@ +/* + * Copyright (C) 2019, Alex Bennée + * + * Hot Pages - show which pages saw the most memory accesses. + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +static uint64_t page_size = 4096; +static uint64_t page_mask; +static int stdout_fd; +static int limit = 50; +static enum qemu_plugin_mem_rw rw = QEMU_PLUGIN_MEM_RW; + +enum sort_type { + SORT_RW = 0, + SORT_R, + SORT_W +}; + +static int sort_by = SORT_RW; + +typedef struct { + uint64_t page_address; + int cpu_read; + int cpu_write; + uint64_t reads; + uint64_t writes; +} PageCounters; + +static GMutex lock; +static GHashTable *pages; + +static gint cmp_access_count(gconstpointer a, gconstpointer b) +{ + PageCounters *ea = (PageCounters *) a; + PageCounters *eb = (PageCounters *) b; + int r; + switch (sort_by) { + case SORT_RW: + r = (ea->reads + ea->writes) > (eb->reads + eb->writes) ? -1 : 1; + break; + case SORT_R: + r = ea->reads > eb->reads ? -1 : 1; + break; + case SORT_W: + r = ea->writes > eb->writes ? -1 : 1; + break; + default: + g_assert_not_reached(); + } + return r; +} + + +static void plugin_exit(qemu_plugin_id_t id, void *p) +{ + GString *report = g_string_new("Addr, RCPUs, Reads, WCPUs, Writes\n"); + int i; + GList *counts; + + counts = g_hash_table_get_values(pages); + if (counts && g_list_next(counts)) { + GList *it; + + it = g_list_sort(counts, cmp_access_count); + + for (i = 0; i < limit && it->next; i++, it = it->next) { + PageCounters *rec = (PageCounters *) it->data; + g_string_append_printf(report, + "%#016"PRIx64", 0x%04x, %"PRId64 + ", 0x%04x, %"PRId64"\n", + rec->page_address, + rec->cpu_read, rec->reads, + rec->cpu_write, rec->writes); + } + g_list_free(it); + } + + dprintf(stdout_fd, "%s", report->str); + g_string_free(report, true); +} + +static void plugin_init(void) +{ + page_mask = (page_size - 1); + pages = g_hash_table_new(NULL, g_direct_equal); +} + +static void vcpu_haddr(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, + uint64_t vaddr, void *udata) +{ + struct qemu_plugin_hwaddr *hwaddr = qemu_plugin_get_hwaddr(meminfo, vaddr); + uint64_t page; + PageCounters *count; + + /* We only get a hwaddr for system emulation */ + if (hwaddr) { + page = (uint64_t) qemu_plugin_hwaddr_to_raddr(hwaddr); + } else { + page = vaddr; + } + page &= ~page_mask; + + g_mutex_lock(&lock); + count = (PageCounters *) g_hash_table_lookup(pages, GUINT_TO_POINTER(page)); + + if (!count) { + count = g_new0(PageCounters, 1); + count->page_address = page; + g_hash_table_insert(pages, GUINT_TO_POINTER(page), (gpointer) count); + } + if (qemu_plugin_mem_is_store(meminfo)) { + count->writes++; + count->cpu_write |= (1 << cpu_index); + } else { + count->reads++; + count->cpu_read |= (1 << cpu_index); + } + + g_mutex_unlock(&lock); +} + +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ + size_t n = qemu_plugin_tb_n_insns(tb); + size_t i; + + for (i = 0; i < n; i++) { + struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i); + qemu_plugin_register_vcpu_mem_cb(insn, vcpu_haddr, + QEMU_PLUGIN_CB_NO_REGS, + rw, NULL); + } +} + +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, int argc, + char **argv) +{ + int i; + + /* to be used when in the exit hook */ + stdout_fd = dup(STDOUT_FILENO); + assert(stdout_fd); + + for (i = 0; i < argc; i++) { + char *opt = argv[i]; + if (g_strcmp0(opt, "reads") == 0) { + sort_by = SORT_R; + } else if (g_strcmp0(opt, "writes") == 0) { + sort_by = SORT_W; + } else if (g_str_has_prefix(opt, "pagesize=")) { + page_size = g_ascii_strtoull(opt + 9, NULL, 10); + } else { + dprintf(stdout_fd, "option parsing failed: %s\n", opt); + return -1; + } + } + + plugin_init(); + + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + return 0; +} From patchwork Wed Jul 31 16:07:17 2019 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: 11068711 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C9F3813AC for ; Wed, 31 Jul 2019 16:28:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B767420415 for ; Wed, 31 Jul 2019 16:28:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AB7BA204C4; Wed, 31 Jul 2019 16:28:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5193420415 for ; Wed, 31 Jul 2019 16:28:25 +0000 (UTC) Received: from localhost ([::1]:42770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrSi-00057J-ND for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:28:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45113) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrPj-0004q6-JH for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrPi-0000JN-GA for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:19 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:40461) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrPi-0000IK-6I for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:25:18 -0400 Received: by mail-wr1-x42f.google.com with SMTP id r1so70345177wrl.7 for ; Wed, 31 Jul 2019 09:25:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=71PC3LPMQ7lE0ThGx+IfFN7xPEpt1fYEADeiWTvDA7s=; b=BaNLFgp7IprdtgYQFWlB5XUJfCGlbnrvhF+Lt59pn3U1OulSdQWgXVf82/rA+QxpHA Gn0SVfG/ZMJpRmKGFPTwt1Ibn3dDWic9+/mMDoTOHFFOMcXqeiTUxj8Z7jrWavA6x5ze sTrERoku5cHJT7mD1HZ3siLXW8x+UM9ecP7vzw91YIYfcFUxdgsvP9ayslWQ7UQLIUPG oaSGi0/wP+cg82pChb2y3d7lusuyQf7OCMhmQvpDeyiyVELqLnVlhPxAPXAH6uxIryih fsXYXc9Di4d5DCgK1sXkDyckdgSIjTg+B757OcUGk/qLdVGHqEhSJ1s2Wbibb0hlqA2b QacA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=71PC3LPMQ7lE0ThGx+IfFN7xPEpt1fYEADeiWTvDA7s=; b=nTKpGz9/rqiiCqEOeU+ou76oD5+PVJ+xKuY+bkQduOidCs63CjVvq/qva3lCmUQLyF zEHnvVa0iXNReoY/lBL4XMz5uZi5Xh58NRUMOWoZUN0cd28SBnQVEn4TEKmx+i1SRhqo 0lzPc3Gk+tw1oNHp2qeNe56p0UvAd+IeP0PCBxFVrLEUfEAWwlobt1Z4ZGwADSfXMiuj iz5vrHdgUaR9OeM1LXQTNRjejld9d1aRvx/Apa3Tvz8RUzELDF7oUoqi+kichjL6ecEW 564WMg3AdRFwk4s8Y2pUwDVW59GSP/rOLRk4Or2W6tGN2gUBpX15nIg54nfJtrQc2sHM DLDA== X-Gm-Message-State: APjAAAXPYRwz/v08eMpcSAFM5ZsUfliaSPFaOnLgFUdnBOvWxBPNUezN tOiuEW9godoVfh2JWnMyW9+Q3w== X-Google-Smtp-Source: APXvYqxFsQyX63Ufqiz1zfohjUE+QsF9GVojU6XEdiiukcts54H+0JBa93uy0/4Oii4/kLydLZa9lg== X-Received: by 2002:a05:6000:187:: with SMTP id p7mr12000274wrx.189.1564590317023; Wed, 31 Jul 2019 09:25:17 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id h133sm74457531wme.28.2019.07.31.09.25.13 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:25:15 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 461F71FF93; Wed, 31 Jul 2019 17:07:24 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:17 +0100 Message-Id: <20190731160719.11396-53-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42f Subject: [Qemu-devel] [PATCH v4 52/54] accel/stubs: reduce headers from tcg-stub X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We don't need much for these. However I do wonder why these aren't just null inlines in exec-all.h Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- accel/stubs/tcg-stub.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/accel/stubs/tcg-stub.c b/accel/stubs/tcg-stub.c index 76ae461749e..431ec7d7e6c 100644 --- a/accel/stubs/tcg-stub.c +++ b/accel/stubs/tcg-stub.c @@ -11,10 +11,7 @@ */ #include "qemu/osdep.h" -#include "qemu-common.h" #include "cpu.h" -#include "tcg/tcg.h" -#include "exec/cpu-common.h" #include "exec/exec-all.h" void tb_flush(CPUState *cpu) From patchwork Wed Jul 31 16:07:18 2019 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: 11068625 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1890C1395 for ; Wed, 31 Jul 2019 16:16:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0526F1FFDB for ; Wed, 31 Jul 2019 16:16:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED093200CB; Wed, 31 Jul 2019 16:16:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9456D1FFDB for ; Wed, 31 Jul 2019 16:16:38 +0000 (UTC) Received: from localhost ([::1]:42450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrHJ-0000FJ-Tx for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:16:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42320) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrG5-0005pF-NN for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrG1-00047A-PY for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:19 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:36709) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrFz-00045h-RA for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:17 -0400 Received: by mail-wr1-x444.google.com with SMTP id n4so70412745wrs.3 for ; Wed, 31 Jul 2019 09:15:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hRMRp/kI4c6YkREQzYFhfvajgB0U5gRdKHztblUpjFI=; b=j2Y3K20SDQD+/el2Zi3u3VV+45SKWz+Eel35LKG+Am/PqcOqxfhtKH5492aI24/bzj har7/X4PRmRUFNPIs2d2S+y4PfO5xrb9Y6LkvaTllYZShHH6l5Z3nQ4+2SvVWIS45TzG /gA0f7IXU9m96Ll1qCWHbWGdQyeaqosA2Ojjm0huVBehynvhHN+ke33Quxoa71KnqXCr pg+ZhawYUURQjGGUhbCu10fwZLNrXbsa5WYe38GkR4f2hFipvhImgm0o7HUZmxCqr32a WkMIz+pchCp2fKWG0RBO/AoF0uJL1OljncOF6c2a53c+rrmBTwSDiKiL117hwDVsQkHz 6PKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hRMRp/kI4c6YkREQzYFhfvajgB0U5gRdKHztblUpjFI=; b=omi4u989LhcGafDQvDWcn9L8EtmPRTnvoLU3Aqn5AR+dwQJy4nXhVCLlFEMxNga936 PkwlIL3Xvb+3qHfcg/w0ro9Vow5BQxFa73+hoGj9465zOdM1hQ2qK7z2Sd8gzd4xNnmX EXW3Q2f/ElcTDyPChS4DqHx5EmeYue43e8e67EgjM5QnzV95ux0Ok+0qLUYiR4homMSU CeJ9rC+gIBtoM/jRUSPRpyyYNEXZpMVeXCwEyKe5fUz7SjO0sChqkvlC9QMu3miDRiSP WAWFHFIa5XLV1dUGpuuOpDyYZWazWU8lA93mf9++Etx30o6H0ZoyrvutgiErAnNj6+DT 6GzQ== X-Gm-Message-State: APjAAAWW7E7cFQJwm0Sgs2nbGftMcrsVqyTQ09760dgGC1eVQkMLAKtx GYE8FCQrLJbdmi4XWtnhyVTu6Q== X-Google-Smtp-Source: APXvYqzhiljH59Xbyu6AsqatCyuXim7vcES7HuHQvwoNYB8jLxmb6hQi0Yn64kKMX6dgdkPVuSnqpw== X-Received: by 2002:a05:6000:42:: with SMTP id k2mr14230044wrx.80.1564589714403; Wed, 31 Jul 2019 09:15:14 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id g19sm79297294wmg.10.2019.07.31.09.15.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:15:13 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 594F31FFCA; Wed, 31 Jul 2019 17:07:24 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:18 +0100 Message-Id: <20190731160719.11396-54-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH v4 53/54] include/exec: wrap cpu_ldst.h in CONFIG_TCG X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This gets around a build problem with --disable-tcg. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- include/exec/exec-all.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index c42626e35b1..e6b9b460c81 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -21,7 +21,9 @@ #define EXEC_ALL_H #include "exec/tb-context.h" +#ifdef CONFIG_TCG #include "exec/cpu_ldst.h" +#endif #include "sysemu/cpus.h" /* allow to see translation results - the slowdown should be negligible, so we leave it */ From patchwork Wed Jul 31 16:07:19 2019 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: 11068653 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CEF74912 for ; Wed, 31 Jul 2019 16:19:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA8591FFCD for ; Wed, 31 Jul 2019 16:19:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD6302000A; Wed, 31 Jul 2019 16:19:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 54F2F1FFCD for ; Wed, 31 Jul 2019 16:19:53 +0000 (UTC) Received: from localhost ([::1]:42516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrKS-0007QT-Ek for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 12:19:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42404) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrG7-0005wF-Lx for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrG6-0004A5-2p for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:23 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:38178) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrG5-00047z-QL for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:21 -0400 Received: by mail-wr1-x442.google.com with SMTP id g17so70334827wrr.5 for ; Wed, 31 Jul 2019 09:15:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Snunrr/avWrIhXGLbDExuqiqLPGhcfnkTu5o+XPO9YI=; b=mGqpAqrb6thsotXl+ANgkByVidUUeGUcohf/pZCyVb1wV2wR+IBNiGzBgyKA3NATm2 jeYtXQUeplIyRZ07zwvc1B/EcN61hPdFRj9f5Qq8tDudDcbOhmSZSTDRxovlj4Zxw8ic u9nv6N02rQj627dcANzy0vOvkiKp8J6txTLn52YlKZXqe+83dSt9jq2qpzg1CxN4oSXb 0hkk9ZY8ZFcCx78LvjaT24bD/8utggVRYcERHOeziLt8tyyOSeRPmC5aQO6T1lHKKnzq eC8lfwuxSGtPL/pfaEwlyTGGGptKwPb0mQzYVJ+yrSH4AtgYSBv/wqj6bTY0VH9WAXqH lY8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Snunrr/avWrIhXGLbDExuqiqLPGhcfnkTu5o+XPO9YI=; b=RKdWF4vO064N4Z58gRgbHebCMfwQ9PRv9UGWn1a075ghHJi0gAF9KECa+6XHMIgO51 Lbx6thxLtBAhjHPSWLpS4sNdLY21eNC8nuBygsGOEes1O9DGv2cXuz3bbbcoAdDDcHME al6tV5zxZ7hfHyojDN3sTuK5RegkvXDx/ViTD4ctmRSQc6joX3siFLuveaIW3lVmuCvG 7Q1NhDvy9bToWyJrulydQBdcwnv1ueuaSI0CzqCbqJKeTCZrcI/iC90+9DD2N+lw91Bw VdLufz5fgC3ADP/hNOQhHiD1w/BOGwDlTsnL8ULenyuTn+3rNkJeLbU+4lOpw0VKso/v ljpQ== X-Gm-Message-State: APjAAAUPQIsPqn9cxTD64xUlZwPa8D36DtGcYZPssfXlCDDIRmowuXVJ TGeHXYitMlbTBtZ4nP68+ZamIQ== X-Google-Smtp-Source: APXvYqwLOjp0cptjpeQn31nEqTgFcH9lYtDKPV+Sdy9JVjNh8krSLdLRoaLgtFi0h4iY/Hpqzx9yYQ== X-Received: by 2002:a5d:5644:: with SMTP id j4mr54415173wrw.144.1564589718242; Wed, 31 Jul 2019 09:15:18 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id x185sm63457489wmg.46.2019.07.31.09.15.14 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:15:15 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 6C43F1FFCB; Wed, 31 Jul 2019 17:07:24 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:19 +0100 Message-Id: <20190731160719.11396-55-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PATCH v4 54/54] include/exec/cpu-defs.h: fix typo X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- include/exec/cpu-defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h index 31deca369ea..355fa817a93 100644 --- a/include/exec/cpu-defs.h +++ b/include/exec/cpu-defs.h @@ -233,7 +233,7 @@ typedef struct CPUTLB { } CPUTLB; #endif /* !CONFIG_USER_ONLY && CONFIG_TCG */ /* - * This structure must be placed in ArchCPU immedately + * This structure must be placed in ArchCPU immediately * before CPUArchState, as a field named "neg". */ typedef struct CPUNegativeOffsetState {