From patchwork Thu Oct 25 17:20:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656289 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 776E913A9 for ; Thu, 25 Oct 2018 17:46:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 684242C291 for ; Thu, 25 Oct 2018 17:46:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CA5E2C2A5; Thu, 25 Oct 2018 17:46: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EAC6E2C291 for ; Thu, 25 Oct 2018 17:46:15 +0000 (UTC) Received: from localhost ([::1]:56142 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFji3-0005ho-AY for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:46:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKm-0006hv-Kh for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjJk-0008Ol-OO for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:11 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:51189) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjJk-0008Nz-Er for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:08 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id E9FF222145; Thu, 25 Oct 2018 13:21:07 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=Ie8oCK8Hqrp4QCcb5EiWjVyTCD230QzoRU0Yp4AVUdU=; b=GNK76 ez7MiPXL7UYuxj4k4kWwVjZ5K0d13lYnlMuPIHPR7iF2M3+1ZzCKp2Vs4upn1v1Q AXUV4nlnFgnNFbqwYlP9B6FogJSi9B6Vn9i1Qx8Ix28U1MV+HyhW5cazk7OVpIl4 Jl8UbZPOisybadIIAt9dDIaKY6gCAQAn6SeyfU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=Ie8oCK8Hqrp4QCcb5EiWjVyTCD230 QzoRU0Yp4AVUdU=; b=oSe3ESJNvP2aDMQsNxDM9EV4Xwm9x5zx4BB5gjGvDZ6H4 QwYunhW/MtcPNix8VcM8IiDl/nkYVfiU7TUbzylY9YjpNWWihAbQ5Jizt0YyKZMn sPj7fPSaakwpLLKf9DRz/xO6GJ/MQ+idpDm6ih25r96OLSNKwGNRIkXSd5auA3+f JGu7+ydzkEUGtUcZpWFjzBnoki0rFKfAYDRZe81Ebui9xSV7nPqQjRQxV++jWNMZ XrtF92QYjOXJNkiN+hmG+eN5Zi/562A+l2vz/K68SHqAtIiSw/JHchPoyNOrLHWH VlDXsGZGOncOjcKnwqE7v7lggol9oRlaAP/CLObbg== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 985ABE4074; Thu, 25 Oct 2018 13:21:06 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:10 -0400 Message-Id: <20181025172057.20414-2-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 01/48] cpu: introduce run_on_cpu_no_bql X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This allows us to queue synchronous CPU work without the BQL. Will gain a user soon. Signed-off-by: Emilio G. Cota Reviewed-by: Alex Bennée --- include/qom/cpu.h | 13 +++++++++++++ cpus-common.c | 28 ++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 204bc94056..863aa2bff1 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -877,6 +877,19 @@ bool cpu_is_stopped(CPUState *cpu); */ void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data); +/** + * run_on_cpu_no_bql + * @cpu: The vCPU to run on. + * @func: The function to be executed. + * @data: Data to pass to the function. + * + * Schedules the function @func for execution on the vCPU @cpu. + * This function is run outside the BQL. + * See also: run_on_cpu() + */ +void run_on_cpu_no_bql(CPUState *cpu, run_on_cpu_func func, + run_on_cpu_data data); + /** * async_run_on_cpu: * @cpu: The vCPU to run on. diff --git a/cpus-common.c b/cpus-common.c index cffb2b71ac..b478fc8741 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -144,7 +144,8 @@ static void queue_work_on_cpu(CPUState *cpu, struct qemu_work_item *wi) cpu_mutex_unlock(cpu); } -void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data) +static void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, + run_on_cpu_data data, bool bql) { struct qemu_work_item wi; bool has_bql = qemu_mutex_iothread_locked(); @@ -152,12 +153,16 @@ void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data) g_assert(no_cpu_mutex_locked()); if (qemu_cpu_is_self(cpu)) { - if (has_bql) { - func(cpu, data); + if (bql) { + if (has_bql) { + func(cpu, data); + } else { + qemu_mutex_lock_iothread(); + func(cpu, data); + qemu_mutex_unlock_iothread(); + } } else { - qemu_mutex_lock_iothread(); func(cpu, data); - qemu_mutex_unlock_iothread(); } return; } @@ -172,7 +177,7 @@ void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data) wi.done = false; wi.free = false; wi.exclusive = false; - wi.bql = true; + wi.bql = bql; cpu_mutex_lock(cpu); queue_work_on_cpu_locked(cpu, &wi); @@ -189,6 +194,17 @@ void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data) } } +void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data) +{ + do_run_on_cpu(cpu, func, data, true); +} + +void +run_on_cpu_no_bql(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data) +{ + do_run_on_cpu(cpu, func, data, false); +} + void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data) { struct qemu_work_item *wi; From patchwork Thu Oct 25 17:20:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656327 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 DD8CC13BF for ; Thu, 25 Oct 2018 18:01:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6BA32C309 for ; Thu, 25 Oct 2018 18:01:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAB4E2C284; Thu, 25 Oct 2018 18:01: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7792D2C330 for ; Thu, 25 Oct 2018 18:01:02 +0000 (UTC) Received: from localhost ([::1]:56235 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjwL-00047P-76 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 14:01:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40358) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKp-0006hu-Dj for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjJk-0008OY-Mo for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:11 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:41487) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjJk-0008O1-Eq for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:08 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id E8B10220E7; Thu, 25 Oct 2018 13:21:07 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=7+9XeQHXavr0gaJxWBiVkbgbEdjq4rANuZZrJ5opD9E=; b=mrGlk KQ219z9F3tW3f53BxfchaKhuGWKmuIAtQzKw5wMxEIfsUckq45c4JkwKWjIVZ9PU i2Aop+ZKY/9ZT9vPeClgmu4FK/6eQRkGfvjli4MvCL8Hvzsnqo3VsRS/jT3fbAnd 8VhsXo0W60RYa2b21N8lxNjLrgsz1F93fEyrG0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=7+9XeQHXavr0gaJxWBiVkbgbEdjq4 rANuZZrJ5opD9E=; b=FadUBiSwDboMVXeaoHVM5xFext0NsGoiFxzzidNAh9j5O 5f5LD5+B2ZHo1KGCLvTEiUKGVdIUaAkaJXeeeKQRt7GZ5GltTWQ9GE29on1v6nU3 1wo/VnTdA60XUSgwbEl18Gfsql8vmAWU1PZMIhpSbwL+HqPbBoojoknYvlOM0ZHn oZuuvUf9tmUY8+jYvI9OOQdVvhYMj6DO1dsr/LjrmKqwhLDXpZ8yyCbpW2xsArmt DkuRhuknADDTSjkKIJqcoEqXvt5Z+7NkMiG+vwWTKWVHQJyPTh+AFDZ71Pdkr05+ U2T2DRpeNPFflcASjvPcBzHQkyjDgFfjKmyjnBIkw== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id E4DD9E455F; Thu, 25 Oct 2018 13:21:06 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:11 -0400 Message-Id: <20181025172057.20414-3-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 02/48] trace: expand mem_info:size_shift to 3 bits X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This will allow us to trace 16B-long memory accesses. While at it, add some defines for the mem_info bits and simplify trace_mem_get_info by making it a wrapper around trace_mem_build_info. Signed-off-by: Emilio G. Cota --- trace-events | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trace-events b/trace-events index 4fd2cb4b97..9d65d472d2 100644 --- a/trace-events +++ b/trace-events @@ -151,7 +151,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 : 3; /* 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 Thu Oct 25 17:20:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656309 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 806F313B5 for ; Thu, 25 Oct 2018 17:52:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 733FF2C2A6 for ; Thu, 25 Oct 2018 17:52:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67CC42C2AC; Thu, 25 Oct 2018 17:52: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0259B2C2A6 for ; Thu, 25 Oct 2018 17:52:41 +0000 (UTC) Received: from localhost ([::1]:56165 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjoF-00026O-S7 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:52:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40311) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKp-0006hn-8L for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjJk-0008Ou-O0 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:11 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:52007) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjJk-0008O0-Es for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:08 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id EB1B322171; Thu, 25 Oct 2018 13:21:07 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=KPVGlEz++2TbZFAlnWu7EGM6NBDron2IJ5LJF/d41FM=; b=mrbvL 6FG3u2wMMTdpUq5YKP7AUO+6kcnjJqrkuvBp3bA8uD9OBAdvZTCighH+yuou/7Jc 5z0YJ91S7xJfPqLCvs4TDdeQSuxGnHCYEt4ZEbDCooXN30vuQY0sAa1JyD16+gad TqiHGj97nyraHzdloiw6nFRGX8iUkhMjL5wBBA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=KPVGlEz++2TbZFAlnWu7EGM6NBDro n2IJ5LJF/d41FM=; b=SjLo3ocdIBZiFLDbWCXOebDb6UIB1VLsL3y0gysUEL1Cz PlDirhs8vI16pOB6t1hCuLLC8txl3Vzc1Pu2zBg83ABeRgneisKSam3N4W2fzyLR fgo4om7+YTEYqdMnC+xQDex9MI0oPNuY8kXL1UBal7oJITi99GUSy3XEyLBMHaHF ruxmURmf4qVhy8EEmt8c1rav4BV0WBO39T29LCaTMHKwZCbofig1aN5Sl/jA9pyk 1EB+CZyMld4tKgvtS6QtzcOJ/6pWxva8sEL0hLn34QvCokQ75A0vy1KVzIf9MFCJ ixjbdds1FLtg5WbDqxuw7fc1Q8K7H/WUWeqcKWTYQ== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 2FD47E49EB; Thu, 25 Oct 2018 13:21:07 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:12 -0400 Message-Id: <20181025172057.20414-4-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 03/48] tcg/README: fix typo s/afterwise/afterwards/ X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Afterwise is "wise after the fact", as in "hindsight". Here we meant "afterwards" (as in "subsequently"). Fix it. Signed-off-by: Emilio G. Cota Reviewed-by: Alex Bennée --- tcg/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcg/README b/tcg/README index d22ee084b8..3fa8a7059f 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 Thu Oct 25 17:20:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656315 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 905F313BF for ; Thu, 25 Oct 2018 17:55:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 847CC2C072 for ; Thu, 25 Oct 2018 17:55:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 773FC2C2B0; Thu, 25 Oct 2018 17:55:36 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EBE2C2C072 for ; Thu, 25 Oct 2018 17:55:35 +0000 (UTC) Received: from localhost ([::1]:56199 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjr5-0006nA-8m for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:55:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40445) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKo-0006it-W4 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjJk-0008OZ-Ml for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:11 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:34953) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjJk-0008Ny-Eu for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:08 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id E92502210C; Thu, 25 Oct 2018 13:21:07 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=P9CSTu1jb9B8pcxMZQu8QILOuGihEtq79EBRaHJRFy0=; b=xDZ3Z qLogL6baeHdVnvXvNkfbmKtqFTcPd/wutKjba/5IgcknvzzKoPGsjHIsuj3NiRiQ DYuTm69EhMzaYeMQnGp+v1BbYB9++Z6oSWSKlV2x6cgehDEDs7ajE8Q4ucyWTUp/ FW/nNwYy9TpsPzXNbB5E7b/0acVCtlyhSA2YSg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=P9CSTu1jb9B8pcxMZQu8QILOuGihE tq79EBRaHJRFy0=; b=URsQv9WWdbWAGo1ZHn9bM3EFNaEN2L3JH2G34Cuk5LlBr xoFuWjogkJLyAJG7VA/8l82kfpPPNHxX56Ts/IL/kJjAHuLZnlSEJW1hLuh2X8Sk jJVoryEUljOVQQX5zvqyT/S7rTWv0k5tt60ZI7G8eOOlJvDMjRx9qtvf2syRWsq7 1NSFOWK+g/NxMYui9E4v4Iz2OHiAhlWfaVU7KF3CSxGaS0lvyuNRnpkvb7l0BUUL aBJmZQkvwfvmPKXDdE5bCrjiV4fzM+k+jMRgsoEyEmi2ixpKh3alLyaS35kWo2y2 DMVuIgP97TpGIgoTRRcN7my1Q/Yp1IWKfqsZhNfnw== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 702BBE4897; Thu, 25 Oct 2018 13:21:07 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:13 -0400 Message-Id: <20181025172057.20414-5-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 04/48] exec: introduce qemu_xxhash{2,4,5,6,7} X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Before moving them all to include/qemu/xxhash.h. Signed-off-by: Emilio G. Cota Reviewed-by: Alex Bennée --- include/exec/tb-hash-xx.h | 41 +++++++++++++++++++++++++++++---------- include/exec/tb-hash.h | 2 +- tests/qht-bench.c | 2 +- util/qsp.c | 12 ++++++------ 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/include/exec/tb-hash-xx.h b/include/exec/tb-hash-xx.h index 747a9a612c..98ce4b628a 100644 --- a/include/exec/tb-hash-xx.h +++ b/include/exec/tb-hash-xx.h @@ -42,23 +42,23 @@ #define PRIME32_4 668265263U #define PRIME32_5 374761393U -#define TB_HASH_XX_SEED 1 +#define QEMU_XXHASH_SEED 1 /* * xxhash32, customized for input variables that are not guaranteed to be * contiguous in memory. */ static inline uint32_t -tb_hash_func7(uint64_t a0, uint64_t b0, uint32_t e, uint32_t f, uint32_t g) +qemu_xxhash7(uint64_t ab, uint64_t cd, uint32_t e, uint32_t f, uint32_t g) { - uint32_t v1 = TB_HASH_XX_SEED + PRIME32_1 + PRIME32_2; - uint32_t v2 = TB_HASH_XX_SEED + PRIME32_2; - uint32_t v3 = TB_HASH_XX_SEED + 0; - uint32_t v4 = TB_HASH_XX_SEED - PRIME32_1; - uint32_t a = a0 >> 32; - uint32_t b = a0; - uint32_t c = b0 >> 32; - uint32_t d = b0; + uint32_t v1 = QEMU_XXHASH_SEED + PRIME32_1 + PRIME32_2; + uint32_t v2 = QEMU_XXHASH_SEED + PRIME32_2; + uint32_t v3 = QEMU_XXHASH_SEED + 0; + uint32_t v4 = QEMU_XXHASH_SEED - PRIME32_1; + uint32_t a = ab >> 32; + uint32_t b = ab; + uint32_t c = cd >> 32; + uint32_t d = cd; uint32_t h32; v1 += a * PRIME32_2; @@ -98,4 +98,25 @@ tb_hash_func7(uint64_t a0, uint64_t b0, uint32_t e, uint32_t f, uint32_t g) return h32; } +static inline uint32_t qemu_xxhash2(uint64_t ab) +{ + return qemu_xxhash7(ab, 0, 0, 0, 0); +} + +static inline uint32_t qemu_xxhash4(uint64_t ab, uint64_t cd) +{ + return qemu_xxhash7(ab, cd, 0, 0, 0); +} + +static inline uint32_t qemu_xxhash5(uint64_t ab, uint64_t cd, uint32_t e) +{ + return qemu_xxhash7(ab, cd, e, 0, 0); +} + +static inline uint32_t qemu_xxhash6(uint64_t ab, uint64_t cd, uint32_t e, + uint32_t f) +{ + return qemu_xxhash7(ab, cd, e, f, 0); +} + #endif /* EXEC_TB_HASH_XX_H */ diff --git a/include/exec/tb-hash.h b/include/exec/tb-hash.h index 0526c4f678..731ba4c272 100644 --- a/include/exec/tb-hash.h +++ b/include/exec/tb-hash.h @@ -61,7 +61,7 @@ static inline uint32_t tb_hash_func(tb_page_addr_t phys_pc, target_ulong pc, uint32_t flags, uint32_t cf_mask, uint32_t trace_vcpu_dstate) { - return tb_hash_func7(phys_pc, pc, flags, cf_mask, trace_vcpu_dstate); + return qemu_xxhash7(phys_pc, pc, flags, cf_mask, trace_vcpu_dstate); } #endif diff --git a/tests/qht-bench.c b/tests/qht-bench.c index 2089e2bed1..2ea132fe57 100644 --- a/tests/qht-bench.c +++ b/tests/qht-bench.c @@ -104,7 +104,7 @@ static bool is_equal(const void *ap, const void *bp) static uint32_t h(unsigned long v) { - return tb_hash_func7(v, 0, 0, 0, 0); + return qemu_xxhash2(v); } static uint32_t hval(unsigned long v) diff --git a/util/qsp.c b/util/qsp.c index a848b09c6d..dc29c41fde 100644 --- a/util/qsp.c +++ b/util/qsp.c @@ -135,13 +135,13 @@ QemuCondWaitFunc qemu_cond_wait_func = qemu_cond_wait_impl; * without it we still get a pretty unique hash. */ static inline -uint32_t do_qsp_callsite_hash(const QSPCallSite *callsite, uint64_t a) +uint32_t do_qsp_callsite_hash(const QSPCallSite *callsite, uint64_t ab) { - uint64_t b = (uint64_t)(uintptr_t)callsite->obj; + uint64_t cd = (uint64_t)(uintptr_t)callsite->obj; uint32_t e = callsite->line; uint32_t f = callsite->type; - return tb_hash_func7(a, b, e, f, 0); + return qemu_xxhash6(ab, cd, e, f); } static inline @@ -169,11 +169,11 @@ static uint32_t qsp_entry_no_thread_hash(const QSPEntry *entry) static uint32_t qsp_entry_no_thread_obj_hash(const QSPEntry *entry) { const QSPCallSite *callsite = entry->callsite; - uint64_t a = g_str_hash(callsite->file); - uint64_t b = callsite->line; + uint64_t ab = g_str_hash(callsite->file); + uint64_t cd = callsite->line; uint32_t e = callsite->type; - return tb_hash_func7(a, b, e, 0, 0); + return qemu_xxhash5(ab, cd, e); } static bool qsp_callsite_cmp(const void *ap, const void *bp) From patchwork Thu Oct 25 17:20:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656337 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 B638A13BF for ; Thu, 25 Oct 2018 18:04:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE2972C31E for ; Thu, 25 Oct 2018 18:04:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A22F32C32B; Thu, 25 Oct 2018 18:04:08 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 75C662C31E for ; Thu, 25 Oct 2018 18:04:07 +0000 (UTC) Received: from localhost ([::1]:56253 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjzK-0006yk-8E for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 14:04:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40350) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKo-0006hs-Rn for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjJl-0008PL-9k for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:11 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:53323) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjJl-0008Oy-1u for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:09 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 26E3D22189; Thu, 25 Oct 2018 13:21:08 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=VbwpaYszSV2eD0yLbxxBku9i7G4n/IBl6u5NGiw18Uk=; b=TMFa7 qZTIiz4xl0cqqTJe7+KL8R2vRir5A1DkeqFipuukJU+lght5KXW7dJo85u79g6e4 w/sqMCfyIclRAsGhUJnrvSzWE5bI6spS5quvsWOqXGqFHaQ5IczJVhYJHMTCBRRR GOVsmWhrIDlBSoihFJRho6DR9KobTf0cFQ3MmE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=VbwpaYszSV2eD0yLbxxBku9i7G4n/ IBl6u5NGiw18Uk=; b=VnDEXBDADvytEEKG0AK9dYXV6TJQImubiuQMxf73nEOSC 761bGw6k9xhSm5T2En9OEwTRJlR4Z1a7k8rns36P2wj2Nb8qldX4dQCW8hU+HS5c +7chWsix3xGu3L1fL+hNfotfy22zf4yciFdj9v/BXTdnkPaheCbhWEuAYR32s3oX 6VvcI66T3C17Epcr7ZVTfETVEXMQq2DhTjXLaEb6mOxARvW7fRrzQM7pDz4X4E2X N+GXcq6UJHeeO2rnUipShGQ5cab80LA5dr3c73JEPx+/D2gekW0yrNVAYD7+aGee mveizOhc+/DCOgyqH+mHA6dCq7NajDMq4C56goxMQ== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id AB378E4A46; Thu, 25 Oct 2018 13:21:07 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:14 -0400 Message-Id: <20181025172057.20414-6-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 05/48] include: move exec/tb-hash-xx.h to qemu/xxhash.h X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota Reviewed-by: Alex Bennée --- include/exec/tb-hash.h | 2 +- include/{exec/tb-hash-xx.h => qemu/xxhash.h} | 6 +++--- tests/qht-bench.c | 2 +- util/qsp.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) rename include/{exec/tb-hash-xx.h => qemu/xxhash.h} (97%) diff --git a/include/exec/tb-hash.h b/include/exec/tb-hash.h index 731ba4c272..4f3a37d927 100644 --- a/include/exec/tb-hash.h +++ b/include/exec/tb-hash.h @@ -20,7 +20,7 @@ #ifndef EXEC_TB_HASH_H #define EXEC_TB_HASH_H -#include "exec/tb-hash-xx.h" +#include "qemu/xxhash.h" #ifdef CONFIG_SOFTMMU diff --git a/include/exec/tb-hash-xx.h b/include/qemu/xxhash.h similarity index 97% rename from include/exec/tb-hash-xx.h rename to include/qemu/xxhash.h index 98ce4b628a..fe35dde328 100644 --- a/include/exec/tb-hash-xx.h +++ b/include/qemu/xxhash.h @@ -31,8 +31,8 @@ * - xxHash source repository : https://github.com/Cyan4973/xxHash */ -#ifndef EXEC_TB_HASH_XX_H -#define EXEC_TB_HASH_XX_H +#ifndef QEMU_XXHASH_H +#define QEMU_XXHASH_H #include "qemu/bitops.h" @@ -119,4 +119,4 @@ static inline uint32_t qemu_xxhash6(uint64_t ab, uint64_t cd, uint32_t e, return qemu_xxhash7(ab, cd, e, f, 0); } -#endif /* EXEC_TB_HASH_XX_H */ +#endif /* QEMU_XXHASH_H */ diff --git a/tests/qht-bench.c b/tests/qht-bench.c index 2ea132fe57..4d885ca303 100644 --- a/tests/qht-bench.c +++ b/tests/qht-bench.c @@ -9,7 +9,7 @@ #include "qemu/atomic.h" #include "qemu/qht.h" #include "qemu/rcu.h" -#include "exec/tb-hash-xx.h" +#include "qemu/xxhash.h" struct thread_stats { size_t rd; diff --git a/util/qsp.c b/util/qsp.c index dc29c41fde..410f1ba004 100644 --- a/util/qsp.c +++ b/util/qsp.c @@ -61,7 +61,7 @@ #include "qemu/timer.h" #include "qemu/qht.h" #include "qemu/rcu.h" -#include "exec/tb-hash-xx.h" +#include "qemu/xxhash.h" enum QSPType { QSP_MUTEX, From patchwork Thu Oct 25 17:20:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656295 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 18F9217DE for ; Thu, 25 Oct 2018 17:49:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0987E2BED9 for ; Thu, 25 Oct 2018 17:49:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1DDF2C28B; Thu, 25 Oct 2018 17:49:39 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5A94A2C183 for ; Thu, 25 Oct 2018 17:49:39 +0000 (UTC) Received: from localhost ([::1]:56154 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjlK-0000q2-Ct for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:49:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKp-0006hw-BO for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjJl-0008PR-C8 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:11 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:33175) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjJl-0008Oz-4B for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:09 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 77DCA21D40; Thu, 25 Oct 2018 13:21:08 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=fYsZGRW0YHhXGv8pP27rHxV616A9uwdwPf1z17lY9Wc=; b=exkgU yxF8U6VJ+kjn+nm2ToVwu37W+bmSx0oCMWhTjtJHfY7xFahXxpEs0vHcxr5B/Zyi Io/lD4rv4YI4BHbS2qvWXahsT3gjglVIpC3tVs2iAAoykkkV+z4qIy6Ha5LmVKZD EXr5CJ/CloeOOpMQcQuEOJ+RxPQpVuA89XZPps= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=fYsZGRW0YHhXGv8pP27rHxV616A9u wdwPf1z17lY9Wc=; b=BWFpXVKgmiU7PxhbejjXT5C7kJo0oPx/QGBePYDg9gwgK cDAzCzEdI6hoXKYv56GqrdbA1hcuGZXXDA4nKiRhe7tNMjTLNFxcw/Aa5/sTY3lH h6+fkx8aHV1MBvcgPDQFNfyF1QIiqJlA+mnDc7fa+10TxOLTSWKJgCp47RI7j/2G YXGfc/Y/pCNrxidygQSCMnFtXOmR8IXM7BbL7dMQO2l8aE4GR0QCcNONAH1lx0gh YEtXE/qKd504nrk/IzEY0NF2rORx70UZEGUiCDeuAnDml+JjC9Q4rY2kwMlRWEec yLwrrM4vFDRogSfA85Qh2bpglCjZ09vLla0fR84FQ== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id F04A3E4A48; Thu, 25 Oct 2018 13:21:07 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:15 -0400 Message-Id: <20181025172057.20414-7-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 06/48] tcg: use QHT for helper_table X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This will allow us to add TCG helpers at run-time. While at it, rename tcg_find_helper to tcg_helper_find for consistency with the added tcg_helper_foo functions. Signed-off-by: Emilio G. Cota Reviewed-by: Alex Bennée --- tcg/tcg.c | 59 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index e85133ef05..65da3c5dbf 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -33,6 +33,7 @@ #include "qemu/error-report.h" #include "qemu/cutils.h" #include "qemu/host-utils.h" +#include "qemu/xxhash.h" #include "qemu/timer.h" /* Note: the long term plan is to reduce the dependencies on the QEMU @@ -879,13 +880,46 @@ typedef struct TCGHelperInfo { static const TCGHelperInfo all_helpers[] = { #include "exec/helper-tcg.h" }; -static GHashTable *helper_table; +static struct qht helper_table; +static bool helper_table_inited; static int indirect_reg_alloc_order[ARRAY_SIZE(tcg_target_reg_alloc_order)]; static void process_op_defs(TCGContext *s); static TCGTemp *tcg_global_reg_new_internal(TCGContext *s, TCGType type, TCGReg reg, const char *name); +static inline uint32_t tcg_helper_func_hash(const void *func) +{ + return qemu_xxhash2((uint64_t)func); +} + +static bool tcg_helper_cmp(const void *ap, const void *bp) +{ + const TCGHelperInfo *a = ap; + const TCGHelperInfo *b = bp; + + return a->func == b->func && + a->flags == b->flags && + a->sizemask == b->sizemask && + !strcmp(a->name, b->name); +} + +static bool tcg_helper_lookup_cmp(const void *obj, const void *func) +{ + const TCGHelperInfo *info = obj; + + return info->func == func; +} + +static void tcg_helper_insert(const TCGHelperInfo *info) +{ + uint32_t hash = tcg_helper_func_hash(info->func); + bool inserted; + + inserted = qht_insert(&helper_table, (void *)info, hash, NULL); + g_assert(inserted); +} + void tcg_context_init(TCGContext *s) { int op, total_args, n, i; @@ -919,13 +953,13 @@ void tcg_context_init(TCGContext *s) } /* Register helpers. */ - /* Use g_direct_hash/equal for direct pointer comparisons on func. */ - helper_table = g_hash_table_new(NULL, NULL); + qht_init(&helper_table, tcg_helper_cmp, ARRAY_SIZE(all_helpers), + QHT_MODE_AUTO_RESIZE); for (i = 0; i < ARRAY_SIZE(all_helpers); ++i) { - g_hash_table_insert(helper_table, (gpointer)all_helpers[i].func, - (gpointer)&all_helpers[i]); + tcg_helper_insert(&all_helpers[i]); } + helper_table_inited = true; tcg_target_init(s); process_op_defs(s); @@ -1620,9 +1654,10 @@ void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args) int i, real_args, nb_rets, pi; unsigned sizemask, flags; TCGHelperInfo *info; + uint32_t hash = tcg_helper_func_hash(func); TCGOp *op; - info = g_hash_table_lookup(helper_table, (gpointer)func); + info = qht_lookup_custom(&helper_table, func, hash, tcg_helper_lookup_cmp); flags = info->flags; sizemask = info->sizemask; @@ -1825,11 +1860,15 @@ static char *tcg_get_arg_str(TCGContext *s, char *buf, } /* Find helper name. */ -static inline const char *tcg_find_helper(TCGContext *s, uintptr_t val) +static inline const char *tcg_helper_find(TCGContext *s, uintptr_t val) { const char *ret = NULL; - if (helper_table) { - TCGHelperInfo *info = g_hash_table_lookup(helper_table, (gpointer)val); + if (helper_table_inited) { + uint32_t hash = tcg_helper_func_hash((void *)val); + TCGHelperInfo *info; + + info = qht_lookup_custom(&helper_table, (void *)val, hash, + tcg_helper_lookup_cmp); if (info) { ret = info->name; } @@ -1919,7 +1958,7 @@ void tcg_dump_ops(TCGContext *s) /* function name, flags, out args */ col += qemu_log(" %s %s,$0x%" TCG_PRIlx ",$%d", def->name, - tcg_find_helper(s, op->args[nb_oargs + nb_iargs]), + tcg_helper_find(s, op->args[nb_oargs + nb_iargs]), op->args[nb_oargs + nb_iargs + 1], nb_oargs); for (i = 0; i < nb_oargs; i++) { col += qemu_log(",%s", tcg_get_arg_str(s, buf, sizeof(buf), From patchwork Thu Oct 25 17:20:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656287 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 628AF13A9 for ; Thu, 25 Oct 2018 17:46:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 528A32C291 for ; Thu, 25 Oct 2018 17:46:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 46D4A2C2A5; Thu, 25 Oct 2018 17:46: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DE4B52C291 for ; Thu, 25 Oct 2018 17:46:14 +0000 (UTC) Received: from localhost ([::1]:56132 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFji2-0004Rg-4E for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:46:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40308) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKp-0006hk-AT for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjJl-0008PX-D9 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:11 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:58655) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjJl-0008P2-57 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:09 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id A83FE21F48; Thu, 25 Oct 2018 13:21:08 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=JJZJj/dsU8+ne8K8pHId98CGbQWxHiA+kGRp8vLaJJY=; b=IbnM3 Dmv2mEVpJKOr1lx2QmgixkuwbtmGKW6vYef/+jpeoGquj6ZmnU5BS8ffIFaFgMWm EfOcoxgsRP6P4dws7cPuDG/ulYDMMjp08hDy4CkBhZxc172m1vnoRmbYYH01PvuO Z49fh+el/7cxHrR4HEMoHBzq2HfPCKkW1qR9Uk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=JJZJj/dsU8+ne8K8pHId98CGbQWxH iA+kGRp8vLaJJY=; b=h4T6hn471K/RpwnMgKvsy0nkVhVPBIX9XsvNpVegFhFwZ zTXU5O5IuL3j9oZIpLKXu4xjKmARwV+xdYMb2AQcJa7EieENSYqunb6N+gKl4RUF R7/QAayLvQwX5YTFH46JT4ihH4NvOZeu+uCuPoi/icHWba1ecdu0JUS64Qh/1fnr VIx5FyyPiQnRp9lhT7RTnlhpxkGX/XRPOyT5umXyTkyugbDN78fW9U3fNpxHqZjo grYxpdk1KS6Ma7tYvhfLHgU+o7PPsX6kRlTLPXjJxj9mfMCsV87W2Kj6KM1HjIqH 2/ssScgFhtzUa0bSnRBWk50Rlqud2LGjnsHEM38hw== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 462C6E4074; Thu, 25 Oct 2018 13:21:08 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:16 -0400 Message-Id: <20181025172057.20414-8-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 07/48] tcg: export TCGHelperInfo X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota Reviewed-by: Alex Bennée --- tcg/tcg.h | 7 +++++++ tcg/tcg.c | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tcg/tcg.h b/tcg/tcg.h index f4efbaa680..9f9643b470 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -480,6 +480,13 @@ typedef TCGv_ptr TCGv_env; /* Used to align parameters. See the comment before tcgv_i32_temp. */ #define TCG_CALL_DUMMY_ARG ((TCGArg)0) +typedef struct TCGHelperInfo { + void *func; + const char *name; + unsigned flags; + unsigned sizemask; +} TCGHelperInfo; + /* Conditions. Note that these are laid out for easy manipulation by the functions below: bit 0 is used for inverting; diff --git a/tcg/tcg.c b/tcg/tcg.c index 65da3c5dbf..08b6926894 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -868,13 +868,6 @@ void tcg_pool_reset(TCGContext *s) s->pool_current = NULL; } -typedef struct TCGHelperInfo { - void *func; - const char *name; - unsigned flags; - unsigned sizemask; -} TCGHelperInfo; - #include "exec/helper-proto.h" static const TCGHelperInfo all_helpers[] = { From patchwork Thu Oct 25 17:20:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656335 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 7371414BB for ; Thu, 25 Oct 2018 18:03:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6ABBE2C311 for ; Thu, 25 Oct 2018 18:03:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F0F32C329; Thu, 25 Oct 2018 18:03: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E824E2C311 for ; Thu, 25 Oct 2018 18:03:44 +0000 (UTC) Received: from localhost ([::1]:56252 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjyy-0006XG-31 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 14:03:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40449) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKp-0006ix-31 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjJl-0008Pf-Ez for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:11 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:59947) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjJl-0008P8-8Z for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:09 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id D2ECC21FFB; Thu, 25 Oct 2018 13:21:08 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=HLL/G79KuxQKfKUIsck2JrML9KIg9iIgCze5lz6eDBk=; b=CV0H0 K9+gdwCpVm2NmuI7Zu9zhrRQTw1YW6ctcX17E66NJulneAgZk0KyT7f+NNKmzdrj md0EyHPE7a/+yihm1PkFU2RAFbL877Bec7myJnNfyAH01jx8ddh9/knj1bUK7k3j 7fHYu2rfpzOIpobCudNopzqLbpPZQJcbLnqzBY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=HLL/G79KuxQKfKUIsck2JrML9KIg9 iIgCze5lz6eDBk=; b=tyEAM1VkszmST+LMfI4sXcQCVk0CNnWrk5txeKCPxikaF IJ/5stpxOQWYGNrvLhqvyDh43v8G63hu/IeNwuLCMpNU9ca7sJv6uUSn7nCZ9IwG wBcuMZ9SCO4vvl7i876Q6kWshRu01bUjNYZG+L8mm4NBqmpRdA2KFq1l2wvpRb2b ZxtBbO5pyeYpd/oV9Pkofh2FH6yrjP+NEw0dtribjbtHpmKIreH/ccEwl8p3r/7s 2I/yfZKHGbR+cE+etDbj3sv3idXt9raO6ne/bRBuA/K9gyLfwOVjh64aWsn3tU/a UqXoCVW2qgYf9AWWGe6vb00D3Kw1+riH0oMKWruUw== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 7E737E455F; Thu, 25 Oct 2018 13:21:08 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:17 -0400 Message-Id: <20181025172057.20414-9-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 08/48] tcg: export tcg_gen_runtime_helper X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This takes the TCGHelperInfo directly, which will allow us to generate helpers at run-time. Signed-off-by: Emilio G. Cota Reviewed-by: Alex Bennée --- tcg/tcg.h | 2 ++ tcg/tcg.c | 50 +++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/tcg/tcg.h b/tcg/tcg.h index 9f9643b470..3fa434d891 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -1077,6 +1077,8 @@ do {\ bool tcg_op_supported(TCGOpcode op); void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args); +void tcg_gen_runtime_helper(const TCGHelperInfo *orig, TCGTemp *ret, int nargs, + TCGTemp **args); TCGOp *tcg_emit_op(TCGOpcode opc); void tcg_op_remove(TCGContext *s, TCGOp *op); diff --git a/tcg/tcg.c b/tcg/tcg.c index 08b6926894..87e02da740 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1642,15 +1642,13 @@ bool tcg_op_supported(TCGOpcode op) /* Note: we convert the 64 bit args to 32 bit and do some alignment and endian swap. Maybe it would be better to do the alignment and endian swap in tcg_reg_alloc_call(). */ -void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args) +static void do_tcg_gen_callN(TCGHelperInfo *info, TCGTemp *ret, int nargs, + TCGTemp **args) { int i, real_args, nb_rets, pi; unsigned sizemask, flags; - TCGHelperInfo *info; - uint32_t hash = tcg_helper_func_hash(func); TCGOp *op; - info = qht_lookup_custom(&helper_table, func, hash, tcg_helper_lookup_cmp); flags = info->flags; sizemask = info->sizemask; @@ -1774,7 +1772,7 @@ void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args) op->args[pi++] = temp_arg(args[i]); real_args++; } - op->args[pi++] = (uintptr_t)func; + op->args[pi++] = (uintptr_t)info->func; op->args[pi++] = flags; TCGOP_CALLI(op) = real_args; @@ -1812,6 +1810,48 @@ void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args) #endif /* TCG_TARGET_EXTEND_ARGS */ } +void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args) +{ + TCGHelperInfo *info; + uint32_t hash = tcg_helper_func_hash(func); + + /* + * Here we can get away with tcg_helper_lookup_cmp, which only looks + * at the function pointer, since we have the compile-time guarantee + * that @func can only be in one TCGHelperInfo. + */ + info = qht_lookup_custom(&helper_table, func, hash, tcg_helper_lookup_cmp); + do_tcg_gen_callN(info, ret, nargs, args); +} + +void tcg_gen_runtime_helper(const TCGHelperInfo *orig, TCGTemp *ret, int nargs, + TCGTemp **args) +{ + TCGHelperInfo *info; + uint32_t hash = tcg_helper_func_hash(orig->func); + + /* + * Use the full TCGHelperInfo lookup, since there is no guarantee that func + * will be unique to each TCGHelperInfo. For instance, we could have the + * same helper function registered in several TCGHelperInfo's, each of them + * with different flags. + */ + info = qht_lookup(&helper_table, orig, hash); + if (info == NULL) { + void *existing = NULL; + + /* @orig might be in the stack, so we need to allocate a new struct */ + info = g_new(TCGHelperInfo, 1); + memcpy(info, orig, sizeof(TCGHelperInfo)); + qht_insert(&helper_table, info, hash, &existing); + if (unlikely(existing)) { + g_free(info); + info = existing; + } + } + do_tcg_gen_callN(info, ret, nargs, args); +} + static void tcg_reg_alloc_start(TCGContext *s) { int i, n; From patchwork Thu Oct 25 17:20:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656321 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 3C4FB13BF for ; Thu, 25 Oct 2018 17:58:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 325832C2AF for ; Thu, 25 Oct 2018 17:58:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 24B302C2BD; Thu, 25 Oct 2018 17:58: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A18A92C2AF for ; Thu, 25 Oct 2018 17:58:14 +0000 (UTC) Received: from localhost ([::1]:56211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjtd-0001jC-En for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:58:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40456) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKm-0006j1-KA for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjJl-0008Pr-JQ for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:12 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:49907) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjJl-0008PG-Eb for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:09 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 2AF0B21F30; Thu, 25 Oct 2018 13:21:09 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=VZpcu0cRqtxF3QM9uVZkd8VKZVm6+pUJegReZs6l8LU=; b=K52kk 8VDHk4ONoTH/nBqsTDuauHbtzjfCnEFqJf7irb1FMJz6WVp6vz0R54ZD8N32Jirh GgCyUdJ6fmFsu/0CbXmKWcuk1PGy1BM49mwSuxb8iCFcRhTwsLxe+6ncIrYVuQyo g478eOTPM8TwDBuKC1PbtfqGv1qizaLaB4NcCQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=VZpcu0cRqtxF3QM9uVZkd8VKZVm6+ pUJegReZs6l8LU=; b=EBJltfVsXYvk3pKfiQyEzj4SiC1tpqMxz0HaH0Rj504jh 2zGktllFlhe837NQEmg4VrXxlSQ2nAemzBQ4dasXd/F9aJD9rNTdAS1wHfaxg70Z ytUIojKyGAqD4zRwsEVHrCNrnhi8Bhcz24m7zb9c4NA5hc+/knRYk9gg4kYxMHl9 lu8OCPb1Dh3w/jli8YJQ2tshWYmWsqd6TLds7M3AAXn/UZ9cqsLQY7dCsrN2Ktts 0P8GgAllGcATpGZCsfs/hspEdq9pV6XXoQPttCX8n5xipLSsnWh4+7kVSff48pBL lP1B0Y7DGjjHcLJTsruy6bf2TTxIZiH33JkKCFIHA== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id BC5A5E4074; Thu, 25 Oct 2018 13:21:08 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:18 -0400 Message-Id: <20181025172057.20414-10-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 09/48] tcg: reset runtime helpers when flushing the code cache X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In preparation for adding plugin support. One of the clean-up actions when uninstalling plugins will be to flush the code cache. We'll also have to clear the runtime helpers, since some of those runtime helpers may belong to the plugin being uninstalled. Signed-off-by: Emilio G. Cota Reviewed-by: Alex Bennée --- tcg/tcg.h | 1 + accel/tcg/translate-all.c | 1 + tcg/tcg.c | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/tcg/tcg.h b/tcg/tcg.h index 3fa434d891..2c378415d2 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -1079,6 +1079,7 @@ bool tcg_op_supported(TCGOpcode op); void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args); void tcg_gen_runtime_helper(const TCGHelperInfo *orig, TCGTemp *ret, int nargs, TCGTemp **args); +void tcg_reset_runtime_helpers(void); TCGOp *tcg_emit_op(TCGOpcode opc); void tcg_op_remove(TCGContext *s, TCGOp *op); diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 038d82fdb5..c8b3e0a491 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1255,6 +1255,7 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) qht_reset_size(&tb_ctx.htable, CODE_GEN_HTABLE_SIZE); page_flush_tb(); + tcg_reset_runtime_helpers(); tcg_region_reset_all(); /* XXX: flush processor icache at this point if cache flush is diff --git a/tcg/tcg.c b/tcg/tcg.c index 87e02da740..a6824145b0 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -874,6 +874,7 @@ static const TCGHelperInfo all_helpers[] = { #include "exec/helper-tcg.h" }; static struct qht helper_table; +static struct qht runtime_helper_table; static bool helper_table_inited; static int indirect_reg_alloc_order[ARRAY_SIZE(tcg_target_reg_alloc_order)]; @@ -913,6 +914,22 @@ static void tcg_helper_insert(const TCGHelperInfo *info) g_assert(inserted); } +static void +rm_from_helper_table_and_free(void *p, uint32_t h, void *userp) +{ + bool success; + + success = qht_remove(&helper_table, p, h); + g_assert(success); + g_free(p); +} + +void tcg_reset_runtime_helpers(void) +{ + qht_iter(&runtime_helper_table, rm_from_helper_table_and_free, NULL); + qht_reset(&runtime_helper_table); +} + void tcg_context_init(TCGContext *s) { int op, total_args, n, i; @@ -948,6 +965,7 @@ void tcg_context_init(TCGContext *s) /* Register helpers. */ qht_init(&helper_table, tcg_helper_cmp, ARRAY_SIZE(all_helpers), QHT_MODE_AUTO_RESIZE); + qht_init(&runtime_helper_table, tcg_helper_cmp, 1, QHT_MODE_AUTO_RESIZE); for (i = 0; i < ARRAY_SIZE(all_helpers); ++i) { tcg_helper_insert(&all_helpers[i]); @@ -1847,6 +1865,9 @@ void tcg_gen_runtime_helper(const TCGHelperInfo *orig, TCGTemp *ret, int nargs, if (unlikely(existing)) { g_free(info); info = existing; + } else { + qht_insert(&runtime_helper_table, info, hash, &existing); + g_assert(existing == NULL); } } do_tcg_gen_callN(info, ret, nargs, args); From patchwork Thu Oct 25 17:20:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656281 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 5427C17DE for ; Thu, 25 Oct 2018 17:43:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4233928918 for ; Thu, 25 Oct 2018 17:43:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 36AE6289B2; Thu, 25 Oct 2018 17:43: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D74CC28997 for ; Thu, 25 Oct 2018 17:43:19 +0000 (UTC) Received: from localhost ([::1]:56120 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjfD-0000vr-6m for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:43:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKm-0006hw-Jm for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjJl-0008Q2-Sg for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:12 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:60607) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjJl-0008Pl-Nk for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:09 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 6710721C76; Thu, 25 Oct 2018 13:21:09 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=NTyI7vmxP4VeWurS6nQYnlLb8Q8tSG2hiviKf4pMGWg=; b=OUEWl G9gJDy9aicWTbbRTV5HRFDLE6j9HzRJYih4MF1rOvs6wkud88gtAdb0JXZfsUmjq pZUqHhv4pyo5GDx4eRkUtjzbfgoqhUFcXypgtku05+GE9porsqLi62T/CEzaivmn SSshaTxwL2FXgKVSKLQyDhO4LDzajfOg4sQEYc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=NTyI7vmxP4VeWurS6nQYnlLb8Q8tS G2hiviKf4pMGWg=; b=mDxO1bEDHSuWb3cNlJzttRjDausGEe4jfr775w/H/CkIc aJWLrmamfcXyG18oaXAp6gybVrsz6a+VFkXiFDqVU751sTV9ZMTlkK0VC2y7gGb4 bMEEPdY0fNjKkX9XuNlS/DSPJoX3Hn4N7CHPPZPqaHbgZ0nYGRB/qpX8Id7LuNtf eBL8oRFj4N2IOp5NJ68ZPu9kFUzk6/E21Gv2FP75DUD1P2utqQVtk6sjqWShoMa7 hjXqxjQpVXyE20fX8b6/ZcW7FCgV6L5RVDzqldtEB2pvV1ZUGhkWkH7Lpq3F1Zyu GTV8aiZJD7ctxlxvytSAk0L9ClED1xw0pb9R7spvg== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 0045BE455F; Thu, 25 Oct 2018 13:21:08 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:19 -0400 Message-Id: <20181025172057.20414-11-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 10/48] exec: export do_tb_flush X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This will be used by plugin code to flush the code cache as well as doing other bookkeeping in a safe work environment. Signed-off-by: Emilio G. Cota --- include/exec/exec-all.h | 1 + accel/tcg/translate-all.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 815e5b1e83..232e2f8966 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -427,6 +427,7 @@ void tb_invalidate_phys_range(target_ulong start, target_ulong end); void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs); #endif void tb_flush(CPUState *cpu); +void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count); void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr); TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc, target_ulong cs_base, uint32_t flags, diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index c8b3e0a491..db2d28f8d3 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1230,7 +1230,7 @@ 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) +void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) { mmap_lock(); /* If it is already been done on request of another CPU, From patchwork Thu Oct 25 17:20:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656317 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 2757013A9 for ; Thu, 25 Oct 2018 17:55:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B42F2C2AF for ; Thu, 25 Oct 2018 17:55:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AB672C2B0; Thu, 25 Oct 2018 17:55:44 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A82552C072 for ; Thu, 25 Oct 2018 17:55:43 +0000 (UTC) Received: from localhost ([::1]:56200 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjrD-0006tH-19 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:55:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40415) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKm-0006hx-HD for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjK6-0008Vm-RY for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:34 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:49235) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjJw-0008Px-VB for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:23 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 9BFD022137; Thu, 25 Oct 2018 13:21:09 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=KmCPqnK2BfHt1Gtj4u7ABavBFfQyW6ZLiTTZuJelsYE=; b=CbgMe vncidM4+l3ftS/OerHaUFp7Skp/1v+vh0y7A3SgRVhQdX44tiV5yPsV5+Oy9zj2y H8c/VS/66I1DraQ8DUHVqcA2eb0OsEEIOvy1Hv7ATUvdLRLDbGczWVMToHPKXZEf yk/CXO78GSf2SqaORsB8Lpn/RoXLDC1+AR2fd8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=KmCPqnK2BfHt1Gtj4u7ABavBFfQyW 6ZLiTTZuJelsYE=; b=lPvPFL/eOzqtRjn7d9K8DqwxugUvz1Sqgao/yZC/1hyvb WxW6FcJ9tv106smf8HQX1KFVWJTdYFSJhMbDM/ZWpwZ0DHbxT6KnOzkgVbO7gBfx EJHsrOM/RKzkVoktvOjAy/v/vz7tDLUw4xK5LVCTzXBgjAWAlci/W4tXWbYltiR1 cseqy96wHONCekmW+o1IywfkFScCGT8vcIJVaee/FIm9IjGF1rD0nDX3T8kCxnjR yOcuWyBxFvPFH/MWXNm8jVWB5ecgIz9AjKm801m/4iYan7l8P3SXIVwfIPnwXiKq UFzl8tcVVh5JHhcGajGSjIb3iGLWVdDEHkH9rp3+Q== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 37D68E47CB; Thu, 25 Oct 2018 13:21:09 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:20 -0400 Message-Id: <20181025172057.20414-12-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 11/48] atomic_template: fix indentation in GEN_ATOMIC_HELPER X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota Reviewed-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 efde12fdb2..8d177fefef 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 Thu Oct 25 17:20:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656329 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 93EB713BF for ; Thu, 25 Oct 2018 18:01:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 897612C345 for ; Thu, 25 Oct 2018 18:01:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DC672C342; Thu, 25 Oct 2018 18:01: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 079692C33A for ; Thu, 25 Oct 2018 18:01:22 +0000 (UTC) Received: from localhost ([::1]:56223 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjwg-0003Bv-53 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 14:01:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKm-0006ht-D1 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKJ-00008D-5V for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:44 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:51715) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKH-0008Q9-90 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:41 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id D94952212E; Thu, 25 Oct 2018 13:21:09 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=DsCaQrNP/7gV6grEs/67BbM9qG/fCds8qH+++Q104yg=; b=EjA9L A53pPJsGI9kIv5pJzb93ydNn2fed151GGr6WraLnmGERUnoDRaO2iT1VKXYD9Viw nxTc81N5FUCJNDWBqbvWGRqC6A0k0KXhED4lwLUeNRCex9Rvsp/msmeEXPyZwlDW ef8KZpz+4PttDNsmTjoukhTzFRm/cK9VGY2boA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=DsCaQrNP/7gV6grEs/67BbM9qG/fC ds8qH+++Q104yg=; b=h6Q8WU53IizFkWDEGpUfer/mTsBBQEv14Tkf5l4OydYQn pdwaPl95qbL7IlXBOw8HwZSqlKPL+N+CO8f67LJW0/pj1QVXdTHzlbH/ZdjQ5Tyu 182i4gY7IT9Mxq5CtGC0KUKmPqrqGmlhZcvhXinFb/o2r9M8gfdYaP/1BDgKkrKQ 9U/0i2swW65sNLJn9JAhu5elqTN2L0p1yxCUJ7weEOxJm6540aGsyqK/7bMAyUi7 FEorls64FtM1QgF4Zcfkrnxh+mp6FH6ldgKAFVVi/aIHuv/RO7+dKPQVlmJ5L8oW kErtBQN+jpGzkusarKvtdH86MZ4uTapSurxEz+Ypw== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 74295E4074; Thu, 25 Oct 2018 13:21:09 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:21 -0400 Message-Id: <20181025172057.20414-13-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 12/48] atomic_template: define pre/post macros X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In preparation for plugin support. Signed-off-by: Emilio G. Cota --- accel/tcg/atomic_template.h | 92 +++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 35 deletions(-) diff --git a/accel/tcg/atomic_template.h b/accel/tcg/atomic_template.h index 8d177fefef..b13318c1ce 100644 --- a/accel/tcg/atomic_template.h +++ b/accel/tcg/atomic_template.h @@ -59,25 +59,26 @@ # define ABI_TYPE uint32_t #endif -#define ATOMIC_TRACE_RMW do { \ - uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false); \ - \ - trace_guest_mem_before_exec(ENV_GET_CPU(env), addr, info); \ - trace_guest_mem_before_exec(ENV_GET_CPU(env), addr, \ - info | TRACE_MEM_ST); \ - } while (0) - -#define ATOMIC_TRACE_LD do { \ - uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false); \ - \ - trace_guest_mem_before_exec(ENV_GET_CPU(env), addr, info); \ - } while (0) - -# define ATOMIC_TRACE_ST do { \ - uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, true); \ - \ - trace_guest_mem_before_exec(ENV_GET_CPU(env), addr, info); \ - } while (0) +/* these don't depend on MEND/SHIFT, so we just define them once */ +#ifndef ATOMIC_TRACE_RMW_PRE +# define ATOMIC_TRACE_RMW_PRE do { \ + trace_guest_mem_before_exec(ENV_GET_CPU(env), addr, info); \ + trace_guest_mem_before_exec(ENV_GET_CPU(env), addr, info | TRACE_MEM_ST); \ +} while (0) + +# define ATOMIC_TRACE_RMW_POST \ + +# define ATOMIC_TRACE_LD_PRE \ + trace_guest_mem_before_exec(ENV_GET_CPU(env), addr, info) + +# define ATOMIC_TRACE_LD_POST \ + +# define ATOMIC_TRACE_ST_PRE \ + trace_guest_mem_before_exec(ENV_GET_CPU(env), addr, info) + +# define ATOMIC_TRACE_ST_POST \ + +#endif /* ATOMIC_TRACE_RMW_PRE */ /* Define host-endian atomic operations. Note that END is used within the ATOMIC_NAME macro, and redefined below. */ @@ -98,14 +99,16 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, target_ulong addr, ATOMIC_MMU_DECLS; DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; DATA_TYPE ret; + uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false); - ATOMIC_TRACE_RMW; + ATOMIC_TRACE_RMW_PRE; #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; return ret; } @@ -115,10 +118,12 @@ ABI_TYPE ATOMIC_NAME(ld)(CPUArchState *env, target_ulong addr EXTRA_ARGS) { ATOMIC_MMU_DECLS; DATA_TYPE val, *haddr = ATOMIC_MMU_LOOKUP; + uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false); - ATOMIC_TRACE_LD; + ATOMIC_TRACE_LD_PRE; val = atomic16_read(haddr); ATOMIC_MMU_CLEANUP; + ATOMIC_TRACE_LD_POST; return val; } @@ -127,10 +132,12 @@ void ATOMIC_NAME(st)(CPUArchState *env, target_ulong addr, { ATOMIC_MMU_DECLS; DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; + uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, true); - ATOMIC_TRACE_ST; + ATOMIC_TRACE_ST_PRE; atomic16_set(haddr, val); ATOMIC_MMU_CLEANUP; + ATOMIC_TRACE_ST_POST; } #endif #else @@ -140,10 +147,12 @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, target_ulong addr, ATOMIC_MMU_DECLS; DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; DATA_TYPE ret; + uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false); - ATOMIC_TRACE_RMW; + ATOMIC_TRACE_RMW_PRE; ret = atomic_xchg__nocheck(haddr, val); ATOMIC_MMU_CLEANUP; + ATOMIC_TRACE_RMW_POST; return ret; } @@ -154,10 +163,12 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr, \ ATOMIC_MMU_DECLS; \ DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; \ DATA_TYPE ret; \ + uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false); \ \ - ATOMIC_TRACE_RMW; \ + ATOMIC_TRACE_RMW_PRE; \ ret = atomic_##X(haddr, val); \ ATOMIC_MMU_CLEANUP; \ + ATOMIC_TRACE_RMW_POST; \ return ret; \ } @@ -186,8 +197,9 @@ 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; \ + uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false); \ \ - ATOMIC_TRACE_RMW; \ + ATOMIC_TRACE_RMW_PRE; \ smp_mb(); \ cmp = atomic_read__nocheck(haddr); \ do { \ @@ -195,6 +207,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; \ return RET; \ } @@ -232,14 +245,16 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, target_ulong addr, ATOMIC_MMU_DECLS; DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; DATA_TYPE ret; + uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false); - ATOMIC_TRACE_RMW; + ATOMIC_TRACE_RMW_PRE; #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; return BSWAP(ret); } @@ -249,10 +264,12 @@ ABI_TYPE ATOMIC_NAME(ld)(CPUArchState *env, target_ulong addr EXTRA_ARGS) { ATOMIC_MMU_DECLS; DATA_TYPE val, *haddr = ATOMIC_MMU_LOOKUP; + uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false); - ATOMIC_TRACE_LD; + ATOMIC_TRACE_LD_PRE; val = atomic16_read(haddr); ATOMIC_MMU_CLEANUP; + ATOMIC_TRACE_LD_POST; return BSWAP(val); } @@ -261,11 +278,14 @@ void ATOMIC_NAME(st)(CPUArchState *env, target_ulong addr, { ATOMIC_MMU_DECLS; DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; + uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, true); - ATOMIC_TRACE_ST; + val = BSWAP(val); + ATOMIC_TRACE_ST_PRE; val = BSWAP(val); atomic16_set(haddr, val); ATOMIC_MMU_CLEANUP; + ATOMIC_TRACE_ST_POST; } #endif #else @@ -275,10 +295,12 @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, target_ulong addr, ATOMIC_MMU_DECLS; DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; ABI_TYPE ret; + uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false); - ATOMIC_TRACE_RMW; + ATOMIC_TRACE_RMW_PRE; ret = atomic_xchg__nocheck(haddr, BSWAP(val)); ATOMIC_MMU_CLEANUP; + ATOMIC_TRACE_RMW_POST; return BSWAP(ret); } @@ -289,10 +311,12 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr, \ ATOMIC_MMU_DECLS; \ DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; \ DATA_TYPE ret; \ + uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false); \ \ - ATOMIC_TRACE_RMW; \ + ATOMIC_TRACE_RMW_PRE; \ ret = atomic_##X(haddr, BSWAP(val)); \ ATOMIC_MMU_CLEANUP; \ + ATOMIC_TRACE_RMW_POST; \ return BSWAP(ret); \ } @@ -319,8 +343,9 @@ 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; \ + uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false); \ \ - ATOMIC_TRACE_RMW; \ + ATOMIC_TRACE_RMW_PRE; \ smp_mb(); \ ldn = atomic_read__nocheck(haddr); \ do { \ @@ -328,6 +353,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; \ return RET; \ } @@ -355,10 +381,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 From patchwork Thu Oct 25 17:20:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656293 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 B85B213B5 for ; Thu, 25 Oct 2018 17:49:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A81A22BED9 for ; Thu, 25 Oct 2018 17:49:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A8F92C2A3; Thu, 25 Oct 2018 17:49:39 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 351552BED9 for ; Thu, 25 Oct 2018 17:49:39 +0000 (UTC) Received: from localhost ([::1]:56153 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjlK-0000q0-72 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:49:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKm-0006hj-D5 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKJ-00007y-24 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:44 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:58607) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKH-0008QE-5R for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:41 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 1255E2217B; Thu, 25 Oct 2018 13:21:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=2UHt0Q44vKeSkx7tBqripzHNqohH5jICgeUlXxutG3s=; b=Vt6su JWNsQyxopkC/4V0UiqSJb0vjkHmxLip7RQH/u04rBBA+Z1NeaXIu3I6aYPCNtQ1r eSUOSHjhXGJwcQSf5HSHHHjArT5YNAWLvTztZR5iBqvVLOSdI+UKNiYbmXhAdOAZ YxnzyKX6X3ziv+nmYx3yaU6zv7dHmyXwpC1s3U= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=2UHt0Q44vKeSkx7tBqripzHNqohH5 jICgeUlXxutG3s=; b=mDSQBXMWp+hZrwHUqTh2JDHUz7Qi2O/7l0Z8cpphmTGRq aDphaZyzIE8PGtVb8zO1d87eDTPMyq1NrRsrSIKodNQQZemXBxrcLLKf5J6B5D1v 6p4Z7es3Du3qS8n82+/Wy45R8YKGckL3wu1Oa+eiCoIRJCliuK9jXGEhy6QQbwbb FMKoKjZ5UhcqyUz70GiuVhrQW4EphkeP70F7OWVbzoAPXYB01qlmk5Ef7dDqZwun sdmKgZe89cay+Srpyh2FNm7dD0k1fQldTNR1FrahSOc1o7kqmYjNag9ypMwnU32A +zuOOyeMEHKNnU6SEsPk+9mgmivsI+lx2r0WGr+Tw== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id A72FDE455F; Thu, 25 Oct 2018 13:21:09 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:22 -0400 Message-Id: <20181025172057.20414-14-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 13/48] xxhash: add qemu_xxhash8 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP It will be used for TB hashing soon. Signed-off-by: Emilio G. Cota --- include/qemu/xxhash.h | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/include/qemu/xxhash.h b/include/qemu/xxhash.h index fe35dde328..450427eeaa 100644 --- a/include/qemu/xxhash.h +++ b/include/qemu/xxhash.h @@ -49,7 +49,8 @@ * contiguous in memory. */ static inline uint32_t -qemu_xxhash7(uint64_t ab, uint64_t cd, uint32_t e, uint32_t f, uint32_t g) +qemu_xxhash8(uint64_t ab, uint64_t cd, uint32_t e, uint32_t f, uint32_t g, + uint32_t h) { uint32_t v1 = QEMU_XXHASH_SEED + PRIME32_1 + PRIME32_2; uint32_t v2 = QEMU_XXHASH_SEED + PRIME32_2; @@ -77,17 +78,24 @@ qemu_xxhash7(uint64_t ab, uint64_t cd, uint32_t e, uint32_t f, uint32_t g) v4 = rol32(v4, 13); v4 *= PRIME32_1; - h32 = rol32(v1, 1) + rol32(v2, 7) + rol32(v3, 12) + rol32(v4, 18); - h32 += 28; + v1 += e * PRIME32_2; + v1 = rol32(v1, 13); + v1 *= PRIME32_1; - h32 += e * PRIME32_3; - h32 = rol32(h32, 17) * PRIME32_4; + v2 += f * PRIME32_2; + v2 = rol32(v2, 13); + v2 *= PRIME32_1; + + v3 += g * PRIME32_2; + v3 = rol32(v3, 13); + v3 *= PRIME32_1; - h32 += f * PRIME32_3; - h32 = rol32(h32, 17) * PRIME32_4; + v4 += h * PRIME32_2; + v4 = rol32(v4, 13); + v4 *= PRIME32_1; - h32 += g * PRIME32_3; - h32 = rol32(h32, 17) * PRIME32_4; + h32 = rol32(v1, 1) + rol32(v2, 7) + rol32(v3, 12) + rol32(v4, 18); + h32 += 32; h32 ^= h32 >> 15; h32 *= PRIME32_2; @@ -100,23 +108,29 @@ qemu_xxhash7(uint64_t ab, uint64_t cd, uint32_t e, uint32_t f, uint32_t g) static inline uint32_t qemu_xxhash2(uint64_t ab) { - return qemu_xxhash7(ab, 0, 0, 0, 0); + return qemu_xxhash8(ab, 0, 0, 0, 0, 0); } static inline uint32_t qemu_xxhash4(uint64_t ab, uint64_t cd) { - return qemu_xxhash7(ab, cd, 0, 0, 0); + return qemu_xxhash8(ab, cd, 0, 0, 0, 0); } static inline uint32_t qemu_xxhash5(uint64_t ab, uint64_t cd, uint32_t e) { - return qemu_xxhash7(ab, cd, e, 0, 0); + return qemu_xxhash8(ab, cd, e, 0, 0, 0); } static inline uint32_t qemu_xxhash6(uint64_t ab, uint64_t cd, uint32_t e, uint32_t f) { - return qemu_xxhash7(ab, cd, e, f, 0); + return qemu_xxhash8(ab, cd, e, f, 0, 0); +} + +static inline uint32_t qemu_xxhash7(uint64_t ab, uint64_t cd, uint32_t e, + uint32_t f, uint32_t g) +{ + return qemu_xxhash8(ab, cd, e, f, g, 0); } #endif /* QEMU_XXHASH_H */ From patchwork Thu Oct 25 17:20:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656263 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 793CE13BF for ; Thu, 25 Oct 2018 17:37:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6704E283D1 for ; Thu, 25 Oct 2018 17:37:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B3C12C22A; Thu, 25 Oct 2018 17:37: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A8B39283D1 for ; Thu, 25 Oct 2018 17:37:04 +0000 (UTC) Received: from localhost ([::1]:56095 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjZA-0004XQ-1D for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:37:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40415) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKj-0006hx-JY for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKJ-00008V-91 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:44 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:50179) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKJ-0008QK-1H for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:43 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 511BC221BC; Thu, 25 Oct 2018 13:21:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=LmTh7DSDiTuHxutEBC+I44ZRT8UUTrZ1GAYxZJ2UNiQ=; b=uFlOu 7hr0ZdwPGmB99svncW4J2nj1Uxc9hCINufguiIeNdtouMCB60bs+hoLwLdfAmO7Z YiJ9ePBng1uzX+zjh/1bJe4ClnWTgas2lvtZoY+bMav5EPxFeS/v055ecEpuDUAA rkn5o5PR6S4ljrqRERx8ZVL0jpT0Sygazxk00k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=LmTh7DSDiTuHxutEBC+I44ZRT8UUT rZ1GAYxZJ2UNiQ=; b=kCY0wt6QfVLOpwYVT8HyZOm2LXhANOcBjj0F4BvteOCak Uf0PwiX/eLRccUTdqVXj5WVlBZefxmO8cnj4r1cpH/xm9ACyblAi6wjHCrxkrBz1 cPM5e/a9rhefx+ox2ohTjIijejIYjwmZgFwDpyrMr3srv2JTfB0QJ5EA94zVlzn7 5d2q9A5QG/NmpkF9SZGxy+hhf+esSs9LeW9y93X+TXeoZmnGf6bbTtF3lq/6Ii5u 0hN30GjxNBIV1imkOo9OG3bOssD/GTQl9xDVCkVgspkuJHUVm3wUmXHZlyvLvPOI 6BhoNv63y/G7O0y43D8N8h5R4V570NnPs3weP3y0A== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id E182EE47CB; Thu, 25 Oct 2018 13:21:09 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:23 -0400 Message-Id: <20181025172057.20414-15-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 14/48] plugin: preliminary user-facing API X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add the API first to ease review. Signed-off-by: Emilio G. Cota --- include/qemu/plugin-api.h | 227 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 include/qemu/plugin-api.h diff --git a/include/qemu/plugin-api.h b/include/qemu/plugin-api.h new file mode 100644 index 0000000000..5c6bb45279 --- /dev/null +++ b/include/qemu/plugin-api.h @@ -0,0 +1,227 @@ +/* + * 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_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: @argv is freed after this function returns. + */ +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, int argc, + char **argv); + +typedef void (*qemu_plugin_uninstall_cb_t)(qemu_plugin_id_t id); + +/** + * 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 might still receive callbacks + * from prior subscriptions _until_ @cb is called. + */ +void qemu_plugin_uninstall(qemu_plugin_id_t id, qemu_plugin_uninstall_cb_t cb); + +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_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); + +void qemu_plugin_register_vcpu_idle_cb(qemu_plugin_id_t id, + qemu_plugin_vcpu_simple_cb_t cb); + +void qemu_plugin_register_vcpu_resume_cb(qemu_plugin_id_t id, + qemu_plugin_vcpu_simple_cb_t cb); + +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 */ +}; + +typedef void (*qemu_plugin_vcpu_tb_trans_cb_t)(qemu_plugin_id_t id, + unsigned int vcpu_index, + 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); + +/* can only call from tb_trans_cb callback */ +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, +}; + +void qemu_plugin_register_vcpu_tb_exec_inline(struct qemu_plugin_tb *tb, + enum qemu_plugin_op op, + void *ptr, uint64_t 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 *userdata); + +typedef uint32_t qemu_plugin_meminfo_t; + +unsigned 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); + +typedef void +(*qemu_plugin_vcpu_mem_cb_t)(unsigned int vcpu_index, + qemu_plugin_meminfo_t info, uint64_t vaddr, + void *userdata); + +typedef void +(*qemu_plugin_vcpu_mem_haddr_cb_t)(unsigned int vcpu_index, + qemu_plugin_meminfo_t info, uint64_t vaddr, + void *haddr, 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, + void *userdata); + +void qemu_plugin_register_vcpu_mem_haddr_cb(struct qemu_plugin_insn *insn, + qemu_plugin_vcpu_mem_haddr_cb_t cb, + enum qemu_plugin_cb_flags flags, + void *userdata); + +void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, + enum qemu_plugin_op op, void *ptr, + uint64_t imm); + +uint64_t qemu_plugin_ram_addr_from_host(void *haddr); + +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); + +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); + +/** + * 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 Thu Oct 25 17:20:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656297 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 80E9813A9 for ; Thu, 25 Oct 2018 17:49:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D6042BED9 for ; Thu, 25 Oct 2018 17:49:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5FD262C28B; Thu, 25 Oct 2018 17:49: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2FBC02BED9 for ; Thu, 25 Oct 2018 17:49:40 +0000 (UTC) Received: from localhost ([::1]:56155 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjlK-0000r0-Rz for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:49:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40309) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKj-0006hl-9i for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKJ-00009H-OC for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:47 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:50345) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKJ-0008QV-Fv for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:43 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id A332E221BD; Thu, 25 Oct 2018 13:21:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=fwr03WICwUoLM4C1sHx8VhMz+50G4vfl4RGpTeGKbJ4=; b=X0urA VUdoFPo3UpzvSQzEIGkkWlvvDMTS9peNp5oPsrVR8cwWJcQg35lCJggz614GXakz Yfnj4Kf+wm43suERSNC4IwZxTr6DVaQgp0okZqSWNSeMfSe2Q7m/BBvVD8qLtg51 CdZFq7VFmhyUhHCtx0q1Cz2o0xYNC0ikceQpHo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=fwr03WICwUoLM4C1sHx8VhMz+50G4 vfl4RGpTeGKbJ4=; b=nkH38LP6L4Jkkxbmkm9u0RBLP3SfXDb+Oo05C3msbcqvQ EafYrq+5SLVL6IgWx6F9YzbmZMQ85PKabLQJra3EFr5OeFjU1RjdaeGf66Eyoq/v tU8JuIjsg05wdOIp1KOs5K+XQCOnjucBxaMK/FZPrd4RBAJSzI0S2OLbYxyROzuH dNJPzyof+JeOq7oJU6yOMy31HQpX/258X9UzMVKCniwIIx4f2uKyiRLop+nKaNhE eQb5szNEqZx5fc8uTajzAvQqbN/YzByseCfkTlAQrnwC3Da22YS5r0sEpls+wb1T Rt2DcRi7C159ZqwXCSPAmHmj+xW85i51Ba7xYJFHQ== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 237C3E4897; Thu, 25 Oct 2018 13:21:10 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:24 -0400 Message-Id: <20181025172057.20414-16-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 15/48] plugin: add core code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The goals are to: - Have a simple implementation that shares nothing with tracing code. - Make sure we cannot deadlock, particularly under MTTCG. For this, we acquire a lock when called from plugin code, and keep RCU lists of callbacks 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. * Some functions such as vcpu_for_each will call plugin code with the lock held. Instead of making the lock recursive, just document that the function called by vcpu_for_each cannot call any other plugin API. - Support as many plugins as the user wants (e.g. -plugin foo -plugin bar), just like other tools (e.g. dynamorio) do. - Support the installation/uninstallation of a plugin any time (i.e. from any callback from the guest, or from QAPI/QMP). - Avoid malicious plugins from abusing the API. This is done by: * Adding a qemu_plugin_id_t that all calls need to use. This is a unique id per plugin. * Hiding CPUState * under cpu_index. Plugin code can keep per-vcpu data by using said index (say to index an array). * Only exporting the relevant qemu_plugin symbols to the plugins by passing --dynamic-file to the linker (when supported), instead of exporting all symbols with -rdynamic. - Performance: registering/unregistering callbacks is slow. But this is very infrequent; we want performance when calling (or not) callbacks. Using RCU is great for this. The only difficulty is when uninstalling a plugin, where some callbacks might still be called after the uninstall returns. An alternative would be to use r/w locks, but that would complicate code quite a bit for very little gain; I suspect most plugins will just run until QEMU exits. Some design decisions: - I considered registering callbacks per-vcpu, but really I don't see the use case for it (would complicate the API and 99% of plugins won't care, so I'd rather make that 1% slower by letting them discard unwanted callbacks). - Using a per-vcpu mask is key to allow for maximum performance/scalability. With RCU callbacks and async work we can ensure no events are missed, and we keep maximum scalability (again, we assume callbacks are a lot more common than callback registration). - Last, 'plugin' vs. 'instrumentation' naming: I think instrumentation is a subset of the functionality that plugins can provide. IOW, in the future not all plugins might be considered instrumentation, even if currently my goal is to use them for that purpose. Signed-off-by: Emilio G. Cota --- Makefile | 7 +- Makefile.target | 2 + include/qemu/plugin.h | 239 ++++++++++ include/qom/cpu.h | 6 + plugin.c | 981 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1234 insertions(+), 1 deletion(-) create mode 100644 include/qemu/plugin.h create mode 100644 plugin.c diff --git a/Makefile b/Makefile index f2947186a4..e4c0b0877e 100644 --- a/Makefile +++ b/Makefile @@ -862,8 +862,10 @@ ifneq (,$(findstring qemu-ga,$(TOOLS))) endif endif +install-includedir: + $(INSTALL_DIR) "$(DESTDIR)$(includedir)" -install: all $(if $(BUILD_DOCS),install-doc) install-datadir install-localstatedir +install: all $(if $(BUILD_DOCS),install-doc) install-datadir install-localstatedir install-includedir ifneq ($(TOOLS),) $(call install-prog,$(subst qemu-ga,qemu-ga$(EXESUF),$(TOOLS)),$(DESTDIR)$(bindir)) endif @@ -885,6 +887,9 @@ ifneq ($(BLOBS),) endif ifdef CONFIG_GTK $(MAKE) -C po $@ +endif +ifeq ($(CONFIG_PLUGINS),y) + $(INSTALL_DATA) $(SRC_PATH)/include/qemu/plugin-api.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 4d56298bbf..75637c285c 100644 --- a/Makefile.target +++ b/Makefile.target @@ -107,6 +107,8 @@ obj-y += target/$(TARGET_BASE_ARCH)/ obj-y += disas.o obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o +obj-$(CONFIG_PLUGINS) += plugin.o + ######################################################### # Linux user emulator target diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h new file mode 100644 index 0000000000..0da0f1b892 --- /dev/null +++ b/include/qemu/plugin.h @@ -0,0 +1,239 @@ +/* + * 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/plugin-api.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; +QTAILQ_HEAD(qemu_plugin_list, qemu_plugin_desc); + +#ifdef CONFIG_PLUGINS +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, struct qemu_plugin_list *head); +int qemu_plugin_load_list(struct qemu_plugin_list *head); +#else /* !CONFIG_PLUGINS */ +static inline void qemu_plugin_add_opts(void) +{ } + +static inline void qemu_plugin_opt_parse(const char *optarg, + struct qemu_plugin_list *head) +{ + error_report("plugin interface not enabled in this build"); + exit(1); +} + +static inline int qemu_plugin_load_list(struct qemu_plugin_list *head) +{ + return 0; +} +#endif /* !CONFIG_PLUGINS */ + +/* + * 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, +}; + +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_mem_haddr_cb_t vcpu_mem_haddr; + qemu_plugin_vcpu_syscall_cb_t vcpu_syscall; + qemu_plugin_vcpu_syscall_ret_cb_t vcpu_syscall_ret; + void *generic; +}; + +enum qemu_plugin_dyn_cb_type { + QEMU_PLUGIN_DYN_CB_TYPE_REGULAR, + QEMU_PLUGIN_DYN_CB_TYPE_INLINE, +}; + +/* + * 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 qemu_plugin_dyn_cb_type type; + /* fields specific to each dyn_cb type go here */ + union { + struct { + bool haddr; + } mem; + struct { + enum qemu_plugin_op op; + uint64_t imm; + } inline_insn; + }; +}; + +struct qemu_plugin_dyn_cb_arr { + struct qemu_plugin_dyn_cb *data; + size_t n; + size_t capacity; +}; + +struct qemu_plugin_insn { + void *data; + size_t size; + size_t capacity; + uint64_t vaddr; + struct qemu_plugin_dyn_cb_arr exec_cbs; + struct qemu_plugin_dyn_cb_arr mem_cbs; + bool calls_helpers; +}; + +struct qemu_plugin_tb { + struct qemu_plugin_insn *insns; + size_t n; + size_t capacity; + uint64_t vaddr; + struct qemu_plugin_dyn_cb_arr cbs; +}; + +static inline void qemu_plugin_insn_append(struct qemu_plugin_insn *insn, + const void *from, size_t size) +{ + if (insn == NULL) { + return; + } + if (unlikely(insn->size + size > insn->capacity)) { + insn->data = g_realloc(insn->data, insn->size + size); + insn->capacity = insn->size + size; + } + memcpy(insn->data + insn->size, from, size); + insn->size += size; +} + +static inline +void qemu_plugin_dyn_cb_arr_init(struct qemu_plugin_dyn_cb_arr *arr) +{ + arr->data = NULL; + arr->capacity = 0; +} + +static inline +struct qemu_plugin_insn *qemu_plugin_tb_insn_get(struct qemu_plugin_tb *tb) +{ + struct qemu_plugin_insn *insn; + + if (unlikely(tb->n == tb->capacity)) { + tb->insns = g_renew(struct qemu_plugin_insn, tb->insns, ++tb->capacity); + insn = &tb->insns[tb->capacity - 1]; + insn->data = NULL; + insn->capacity = 0; + qemu_plugin_dyn_cb_arr_init(&insn->exec_cbs); + qemu_plugin_dyn_cb_arr_init(&insn->mem_cbs); + } + insn = &tb->insns[tb->n++]; + insn->size = 0; + insn->exec_cbs.n = 0; + insn->mem_cbs.n = 0; + insn->calls_helpers = false; + + return insn; +} + +#ifdef CONFIG_PLUGINS + +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, void *haddr, + uint32_t meminfo); + +void qemu_plugin_flush_cb(void); + +void qemu_plugin_atexit_cb(void); + +void qemu_plugin_add_dyn_cb_arr(struct qemu_plugin_dyn_cb_arr *arr); + +#else /* !CONFIG_PLUGINS */ + +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, + void *haddr, 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(struct qemu_plugin_dyn_cb_arr *arr) +{ } + +#endif /* !CONFIG_PLUGINS */ + +#endif /* QEMU_PLUGIN_H */ diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 863aa2bff1..1ac56fe84b 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -30,6 +30,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); @@ -326,6 +327,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. @@ -413,6 +415,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); + + struct qemu_plugin_dyn_cb_arr *plugin_mem_cbs; + /* TODO Move common fields from CPUArchState here. */ int cpu_index; uint32_t can_do_io; diff --git a/plugin.c b/plugin.c new file mode 100644 index 0000000000..76609f1da4 --- /dev/null +++ b/plugin.c @@ -0,0 +1,981 @@ +/* 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 "exec/plugin-gen.h" +#include "sysemu/sysemu.h" +#include "tcg/tcg.h" +#include "tcg/tcg-op.h" +#include "trace/mem-internal.h" /* mem_info macros */ + +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_ctx { + void *handle; /* dlopen */ + qemu_plugin_id_t id; + struct qemu_plugin_cb *callbacks[QEMU_PLUGIN_EV_MAX]; + QTAILQ_ENTRY(qemu_plugin_ctx) entry; + qemu_plugin_uninstall_cb_t uninstall_cb; + bool uninstalling; /* protected by plugin.lock */ +}; + +/* 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; +}; + +/* + * 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 { + struct qemu_plugin_list *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 **); + +static struct qemu_plugin_state plugin; + +static bool plugin_dyn_cb_arr_cmp(const void *ap, const void *bp) +{ + return ap == bp; +} + +void qemu_plugin_add_dyn_cb_arr(struct qemu_plugin_dyn_cb_arr *arr) +{ + uint32_t hash = qemu_xxhash2((uint64_t)arr); + bool inserted; + + inserted = qht_insert(&plugin.dyn_cb_arr_ht, arr, hash, NULL); + g_assert(inserted); +} + +static void free_dyn_cb_arr(void *p, uint32_t h, void *userp) +{ + struct qemu_plugin_dyn_cb_arr *arr = p; + + g_free(arr->data); + g_free(arr); +} + +static struct qemu_plugin_desc *plugin_find_desc(struct qemu_plugin_list *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, struct qemu_plugin_list *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->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)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); + qemu_rec_mutex_unlock(&plugin.lock); + + rc = install(ctx->id, desc->argc, desc->argv); + 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 already call it. + */ + qemu_rec_mutex_lock(&plugin.lock); + if (!ctx->uninstalling) { + qemu_plugin_uninstall(ctx->id, NULL); + } + qemu_rec_mutex_unlock(&plugin.lock); + return 1; + } + return 0; + + 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 and then freed. + */ +int qemu_plugin_load_list(struct qemu_plugin_list *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); + plugin_desc_free(desc); + } + return 0; +} + +static struct qemu_plugin_ctx *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); + } +} + +static 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); + } +} + +struct qemu_plugin_uninstall_data { + struct qemu_plugin_ctx *ctx; + unsigned tb_flush_count; +}; + +static void plugin_destroy(CPUState *cpu, run_on_cpu_data arg) +{ + struct qemu_plugin_uninstall_data *data = arg.host_ptr; + struct qemu_plugin_ctx *ctx = data->ctx; + bool success; + + do_tb_flush(cpu, RUN_ON_CPU_HOST_INT(data->tb_flush_count)); + + qemu_rec_mutex_lock(&plugin.lock); + g_assert(ctx->uninstalling); + success = g_hash_table_remove(plugin.id_ht, &ctx->id); + g_assert(success); + + QTAILQ_REMOVE(&plugin.ctxs, ctx, entry); + qemu_rec_mutex_unlock(&plugin.lock); + + if (ctx->uninstall_cb) { + ctx->uninstall_cb(ctx->id); + } + if (dlclose(ctx->handle)) { + warn_report("%s: %s", __func__, dlerror()); + } + qemu_vfree(ctx); + g_free(data); +} + +void qemu_plugin_uninstall(qemu_plugin_id_t id, qemu_plugin_uninstall_cb_t cb) +{ + struct qemu_plugin_uninstall_data *data; + struct qemu_plugin_ctx *ctx; + enum qemu_plugin_event ev; + + qemu_rec_mutex_lock(&plugin.lock); + ctx = id_to_ctx__locked(id); + if (unlikely(ctx->uninstalling)) { + error_report("plugin: called %s more than once", __func__); + abort(); + } + ctx->uninstalling = true; + ctx->uninstall_cb = cb; + /* + * Unregister all callbacks. This is an RCU list so it is possible that some + * callbacks will still be called in this RCU grace period. For this reason + * we cannot yet uninstall the plugin. + */ + for (ev = 0; ev < QEMU_PLUGIN_EV_MAX; ev++) { + plugin_unregister_cb__locked(ctx, ev); + } + qemu_rec_mutex_unlock(&plugin.lock); + + /* XXX how to flush when we're not in a vCPU thread? */ + if (current_cpu) { + data = g_new(struct qemu_plugin_uninstall_data, 1); + data->ctx = ctx; + data->tb_flush_count = atomic_mb_read(&tb_ctx.tb_flush_count); + async_safe_run_on_cpu(current_cpu, plugin_destroy, + RUN_ON_CPU_HOST_PTR(data)); + } +} + +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 = 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); +} + +static void plugin_register_cb(qemu_plugin_id_t id, enum qemu_plugin_event ev, + void *func) +{ + do_plugin_register_cb(id, ev, func, NULL); +} + +static 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_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_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 = 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); +} + +static struct qemu_plugin_dyn_cb * +plugin_get_dyn_cb(struct qemu_plugin_dyn_cb_arr *arr) +{ + if (arr->n == arr->capacity) { + arr->data = g_renew(struct qemu_plugin_dyn_cb, arr->data, arr->n + 1); + arr->capacity++; + } + + return &arr->data[arr->n++]; +} + +static void plugin_register_inline_op(struct qemu_plugin_dyn_cb_arr *arr, + 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 = QEMU_PLUGIN_DYN_CB_TYPE_INLINE; + 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; +} + +static inline void +plugin_register_dyn_cb__udata(struct qemu_plugin_dyn_cb_arr *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 = QEMU_PLUGIN_DYN_CB_TYPE_REGULAR; +} + +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, 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, 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->exec_cbs, cb, flags, udata); +} + +static void plugin_register_vcpu_mem_cb(struct qemu_plugin_insn *insn, void *cb, + enum qemu_plugin_cb_flags flags, + void *udata, bool haddr) +{ + struct qemu_plugin_dyn_cb *dyn_cb; + + dyn_cb = plugin_get_dyn_cb(&insn->mem_cbs); + dyn_cb->userp = udata; + dyn_cb->tcg_flags = cb_to_tcg_flags(flags); + dyn_cb->type = QEMU_PLUGIN_DYN_CB_TYPE_REGULAR; + dyn_cb->mem.haddr = haddr; + dyn_cb->f.generic = cb; +} + +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, + void *udata) +{ + plugin_register_vcpu_mem_cb(insn, cb, flags, udata, false); +} + +void qemu_plugin_register_vcpu_mem_haddr_cb(struct qemu_plugin_insn *insn, + qemu_plugin_vcpu_mem_haddr_cb_t cb, + enum qemu_plugin_cb_flags flags, + void *udata) +{ + plugin_register_vcpu_mem_cb(insn, cb, flags, udata, true); +} + +void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, + enum qemu_plugin_op op, void *ptr, + uint64_t imm) +{ + plugin_register_inline_op(&insn->mem_cbs, op, ptr, imm); +} + +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, cpu->cpu_index, tb); + } +} + +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_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_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_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_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); +} + +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 &tb->insns[idx]; +} + +const void *qemu_plugin_insn_data(const struct qemu_plugin_insn *insn) +{ + return insn->data; +} + +size_t qemu_plugin_insn_size(const struct qemu_plugin_insn *insn) +{ + return insn->size; +} + +uint64_t qemu_plugin_insn_vaddr(const struct qemu_plugin_insn *insn) +{ + return insn->vaddr; +} + +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); +} + +void qemu_plugin_flush_cb(void) +{ + qht_iter(&plugin.dyn_cb_arr_ht, free_dyn_cb_arr, NULL); + qht_reset(&plugin.dyn_cb_arr_ht); + + plugin_cb__simple(QEMU_PLUGIN_EV_FLUSH); +} + +static 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, void *haddr, + uint32_t info) +{ + struct qemu_plugin_dyn_cb_arr *arr = cpu->plugin_mem_cbs; + size_t i; + + if (arr == NULL) { + return; + } + for (i = 0; i < arr->n; i++) { + struct qemu_plugin_dyn_cb *cb = &arr->data[i]; + + switch (cb->type) { + case QEMU_PLUGIN_DYN_CB_TYPE_REGULAR: + if (cb->mem.haddr) { + cb->f.vcpu_mem_haddr(cpu->cpu_index, info, vaddr, haddr, + cb->userp); + } else { + cb->f.vcpu_mem(cpu->cpu_index, info, vaddr, cb->userp); + } + break; + case QEMU_PLUGIN_DYN_CB_TYPE_INLINE: + exec_inline_op(cb); + break; + default: + g_assert_not_reached(); + } + } +} + +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); +} + +int qemu_plugin_n_vcpus(void) +{ +#ifdef CONFIG_USER_ONLY + return -1; +#else + return smp_cpus; +#endif +} + +int qemu_plugin_n_max_vcpus(void) +{ +#ifdef CONFIG_USER_ONLY + return -1; +#else + return max_cpus; +#endif +} + +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); +} + +uint64_t qemu_plugin_ram_addr_from_host(void *haddr) +{ +#ifdef CONFIG_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 +} + +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); +} From patchwork Thu Oct 25 17:20:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656279 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 2FD9A13B5 for ; Thu, 25 Oct 2018 17:43:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B14328918 for ; Thu, 25 Oct 2018 17:43:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 096C828A1D; Thu, 25 Oct 2018 17:43: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6E54528918 for ; Thu, 25 Oct 2018 17:43:19 +0000 (UTC) Received: from localhost ([::1]:56123 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjfC-0003GW-OI for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:43:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40310) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKm-0006hm-EP for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKC-00005n-0Y for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:39 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:34579) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjK6-0008QZ-Qb for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:33 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id C757A22196; Thu, 25 Oct 2018 13:21:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=nFRoYADpH+Uwz9yTgJLV4GnU3nc+oF/5Bdi0xYGoTZU=; b=FZNHD CjrDSmiljLIqukYiCq7QPetJQrrR6y2cnyBb5+ueCCha3C3jCxyInp8j5WPF9QxR QkkHcAdMhFP+P+gKeQBnfNoAxt14lCWZuIUGY/PntYA/6letJsisIMUPzkOo2791 +JXxe8ZidRP+grrKAaaXEBYqDEXS6qwWKPH6Xk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=nFRoYADpH+Uwz9yTgJLV4GnU3nc+o F/5Bdi0xYGoTZU=; b=fCHJmIG+Xofzo+k+K1E/MMuUGMfwxN3jbvyCHAX1kKdSV vPuJcUQpdIrE9ESwg9G6Qmc1UCcjdgtLLC9sNU+yddS8Xsg1XQYL9B0kqy9lqlxy We0aWmU82QqsuhvoJErdinB6i4PtGScw8KqI338l7gnwk7UR9+eadaNTDxMn8jq4 /PSxzpa7CODI8hbQ1NvZPyPWfoY6yv4Zpf6uJTBcAYn1tYZMIkwUheoGAa93/Jyg ROS9fIMSRokEsae9XrHyoh0W6PvsUXEGwH6my+bGPzknSMeSNtuHNioLRtBT00M7 5TpdmYmOlxgc+PfZ0HagTHUwL8plyqDkVf6nt8HKA== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 5B120E4A46; Thu, 25 Oct 2018 13:21:10 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:25 -0400 Message-Id: <20181025172057.20414-17-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 16/48] tcg: add plugin_mask to TB hash X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- include/exec/exec-all.h | 2 ++ include/exec/tb-hash.h | 6 ++++-- include/exec/tb-lookup.h | 1 + accel/tcg/cpu-exec.c | 6 +++++- accel/tcg/translate-all.c | 6 ++++-- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 232e2f8966..a1f60404b6 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -358,6 +358,8 @@ struct TranslationBlock { /* Per-vCPU dynamic tracing state used to generate this TB */ uint32_t trace_vcpu_dstate; + uint32_t plugin_mask; + struct tb_tc tc; /* original tb when cflags has CF_NOCACHE */ diff --git a/include/exec/tb-hash.h b/include/exec/tb-hash.h index 4f3a37d927..37292474b7 100644 --- a/include/exec/tb-hash.h +++ b/include/exec/tb-hash.h @@ -59,9 +59,11 @@ static inline unsigned int tb_jmp_cache_hash_func(target_ulong pc) static inline uint32_t tb_hash_func(tb_page_addr_t phys_pc, target_ulong pc, uint32_t flags, - uint32_t cf_mask, uint32_t trace_vcpu_dstate) + uint32_t cf_mask, uint32_t trace_vcpu_dstate, + uint32_t plugin_mask) { - return qemu_xxhash7(phys_pc, pc, flags, cf_mask, trace_vcpu_dstate); + return qemu_xxhash8(phys_pc, pc, flags, cf_mask, trace_vcpu_dstate, + plugin_mask); } #endif diff --git a/include/exec/tb-lookup.h b/include/exec/tb-lookup.h index 492cb68289..dd1572f481 100644 --- a/include/exec/tb-lookup.h +++ b/include/exec/tb-lookup.h @@ -33,6 +33,7 @@ tb_lookup__cpu_state(CPUState *cpu, target_ulong *pc, target_ulong *cs_base, tb->cs_base == *cs_base && tb->flags == *flags && tb->trace_vcpu_dstate == *cpu->trace_dstate && + tb->plugin_mask == *cpu->plugin_mask && (tb_cflags(tb) & (CF_HASH_MASK | CF_INVALID)) == cf_mask)) { return tb; } diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index d590f1f6c0..27aa3451da 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -287,6 +287,7 @@ struct tb_desc { uint32_t flags; uint32_t cf_mask; uint32_t trace_vcpu_dstate; + uint32_t plugin_mask; }; static bool tb_lookup_cmp(const void *p, const void *d) @@ -299,6 +300,7 @@ static bool tb_lookup_cmp(const void *p, const void *d) tb->cs_base == desc->cs_base && tb->flags == desc->flags && tb->trace_vcpu_dstate == desc->trace_vcpu_dstate && + tb->plugin_mask == desc->plugin_mask && (tb_cflags(tb) & (CF_HASH_MASK | CF_INVALID)) == desc->cf_mask) { /* check next page if needed */ if (tb->page_addr[1] == -1) { @@ -330,13 +332,15 @@ TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc, desc.flags = flags; desc.cf_mask = cf_mask; desc.trace_vcpu_dstate = *cpu->trace_dstate; + desc.plugin_mask = *cpu->plugin_mask; desc.pc = pc; phys_pc = get_page_addr_code(desc.env, pc); if (phys_pc == -1) { return NULL; } desc.phys_page1 = phys_pc & TARGET_PAGE_MASK; - h = tb_hash_func(phys_pc, pc, flags, cf_mask, *cpu->trace_dstate); + h = tb_hash_func(phys_pc, pc, flags, cf_mask, *cpu->trace_dstate, + *cpu->plugin_mask); return qht_lookup_custom(&tb_ctx.htable, &desc, h, tb_lookup_cmp); } diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index db2d28f8d3..3423cf74db 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1129,6 +1129,7 @@ static bool tb_cmp(const void *ap, const void *bp) a->flags == b->flags && (tb_cflags(a) & CF_HASH_MASK) == (tb_cflags(b) & CF_HASH_MASK) && a->trace_vcpu_dstate == b->trace_vcpu_dstate && + a->plugin_mask == b->plugin_mask && a->page_addr[0] == b->page_addr[0] && a->page_addr[1] == b->page_addr[1]; } @@ -1444,7 +1445,7 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list) /* remove the TB from the hash list */ phys_pc = tb->page_addr[0] + (tb->pc & ~TARGET_PAGE_MASK); h = tb_hash_func(phys_pc, tb->pc, tb->flags, tb_cflags(tb) & CF_HASH_MASK, - tb->trace_vcpu_dstate); + tb->trace_vcpu_dstate, tb->plugin_mask); if (!(tb->cflags & CF_NOCACHE) && !qht_remove(&tb_ctx.htable, tb, h)) { return; @@ -1640,7 +1641,7 @@ tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc, /* add in the hash table */ h = tb_hash_func(phys_pc, tb->pc, tb->flags, tb->cflags & CF_HASH_MASK, - tb->trace_vcpu_dstate); + tb->trace_vcpu_dstate, tb->plugin_mask); qht_insert(&tb_ctx.htable, tb, h, &existing_tb); /* remove TB from the page(s) if we couldn't insert it */ @@ -1712,6 +1713,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tb->cflags = cflags; tb->trace_vcpu_dstate = *cpu->trace_dstate; tcg_ctx->tb_cflags = cflags; + tb->plugin_mask = *cpu->plugin_mask; #ifdef CONFIG_PROFILER /* includes aborted translations because of exceptions */ From patchwork Thu Oct 25 17:20:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656261 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 F057E13BF for ; Thu, 25 Oct 2018 17:37:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC39A283D1 for ; Thu, 25 Oct 2018 17:37:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D042E2C22A; Thu, 25 Oct 2018 17:37: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 12D9E283D1 for ; Thu, 25 Oct 2018 17:37:00 +0000 (UTC) Received: from localhost ([::1]:56094 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjZ5-0004Vc-BY for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:36:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40419) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKl-0006hz-6y for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKH-00007P-Ar for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:44 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:58817) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKF-0008Qf-Rg for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:41 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 20826221CC; Thu, 25 Oct 2018 13:21:11 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=nHNZGKhfVZ4jUtv2dSbuFnbN8wa/CiobFD05+W8f8Zg=; b=R3V2e mqVpQ1uCYOfK8MxxdzWva8O60nYZ2B3BoqWJXqPJW5vFi/3gsNSz870kysouzojq 5UJvDH51d2BdSuOyBhfYAri7z5Y40UHyx7kKtC/q8t1+ef9NY7osWyWRnMOORzvo NcknC1QNaXh0qYBJ5WbqXtA33i+FrixXJ038nE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=nHNZGKhfVZ4jUtv2dSbuFnbN8wa/C iobFD05+W8f8Zg=; b=lyQZoHWCksVtHvfMXQrcqv93o17SYaruSlYA1+8bWLF64 82WgT71F+Gch3x7q8Tl8F1ZDFg/9wkWgx4kX4l1HXuz1eUCpaRnC/J6vb/dz/MzZ SM29/lK4QPX410eTfoCk7ou4ctNDIXkMPuzk5UJAPlFX1lu8kRc0MZNU/pCNz6yz oJg82KCccFY1VMpl083Mx09DFJCf7SX6QIOCgIf8rcLJ9jsTZJyTw0/Y4fjfbFgU sYnLevnFemYRvesqigICQ/Tx9xa5TjrZBECphjn/+lHG1Kexjg4zWxEfLfiFbCCE /5Rl3OEKhI9FNTIoJ/xMa2aXEPIlZn4bL6wJZ1GNw== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 959BBE47CB; Thu, 25 Oct 2018 13:21:10 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:26 -0400 Message-Id: <20181025172057.20414-18-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 17/48] plugin-gen: add TCG code generation helpers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Here we implement several features: - Inlining TCG code for simple operations. Crucially, 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 comment. Signed-off-by: Emilio G. Cota --- include/exec/plugin-gen.h | 51 +++++++++ accel/tcg/plugin-gen.c | 230 ++++++++++++++++++++++++++++++++++++++ accel/tcg/Makefile.objs | 1 + 3 files changed, 282 insertions(+) create mode 100644 include/exec/plugin-gen.h create mode 100644 accel/tcg/plugin-gen.c diff --git a/include/exec/plugin-gen.h b/include/exec/plugin-gen.h new file mode 100644 index 0000000000..46a167527e --- /dev/null +++ b/include/exec/plugin-gen.h @@ -0,0 +1,51 @@ +/* + * 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" + +#ifdef CONFIG_PLUGINS + +void qemu_plugin_gen_vcpu_mem_callbacks(struct qemu_plugin_dyn_cb_arr *arr, + TCGv vaddr, uint8_t info); + +void qemu_plugin_gen_vcpu_udata_callbacks(struct qemu_plugin_dyn_cb_arr *arr); + +void qemu_plugin_gen_disable_mem_helpers(void); + +void +qemu_plugin_gen_enable_mem_helpers(const struct qemu_plugin_dyn_cb_arr *orig); + +#else /* !CONFIG_PLUGINS */ + +static inline void +qemu_plugin_gen_vcpu_mem_callbacks(struct qemu_plugin_dyn_cb_arr *arr, + TCGv vaddr, uint8_t info) +{ } + +static inline void +qemu_plugin_gen_vcpu_udata_callbacks(struct qemu_plugin_dyn_cb_arr *arr) +{ } + +static inline void qemu_plugin_gen_disable_mem_helpers(void) +{ } + +static inline void +qemu_plugin_gen_enable_mem_helpers(const struct qemu_plugin_dyn_cb_arr *orig) +{ } + +#endif /* CONFIG_PLUGINS */ + +#endif /* QEMU_PLUGIN_GEN_H */ + diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c new file mode 100644 index 0000000000..75f182be37 --- /dev/null +++ b/accel/tcg/plugin-gen.c @@ -0,0 +1,230 @@ +#include "qemu/osdep.h" +#include "cpu.h" +#include "tcg/tcg.h" +#include "tcg/tcg-op.h" +#include "exec/exec-all.h" +#include "exec/plugin-gen.h" + +static void gen_inline_op(struct qemu_plugin_dyn_cb *cb) +{ + TCGv_i64 val = tcg_temp_new_i64(); + TCGv_ptr ptr = tcg_const_ptr(cb->userp); + + tcg_gen_ld_i64(val, ptr, 0); + switch (cb->inline_insn.op) { + case QEMU_PLUGIN_INLINE_ADD_U64: + tcg_gen_addi_i64(val, val, cb->inline_insn.imm); + break; + default: + g_assert_not_reached(); + } + tcg_gen_st_i64(val, ptr, 0); + + tcg_temp_free_ptr(ptr); + tcg_temp_free_i64(val); +} + +static void gen_helper_mem_cb(const char *name, unsigned flags, + qemu_plugin_vcpu_mem_cb_t cb, TCGv_i32 cpu_index, + TCGv_i32 meminfo, TCGv_i64 vaddr, TCGv_ptr udata) +{ + TCGHelperInfo info = { + .func = cb, + .name = name, + .flags = flags, + .sizemask = dh_sizemask(void, 0) | + dh_sizemask(i32, 1) | + dh_sizemask(i32, 2) | + dh_sizemask(i64, 3) | + dh_sizemask(ptr, 4), + + }; + TCGTemp *args[] = { + tcgv_i32_temp(cpu_index), + tcgv_i32_temp(meminfo), + tcgv_i64_temp(vaddr), + tcgv_ptr_temp(udata), + }; + + tcg_gen_runtime_helper(&info, NULL, ARRAY_SIZE(args), args); +} + +static void gen_helper_mem_haddr_cb(const char *name, unsigned flags, + qemu_plugin_vcpu_mem_haddr_cb_t cb, + TCGv_i32 cpu_index, TCGv_i32 meminfo, + TCGv_i64 vaddr, TCGv_ptr haddr, + TCGv_ptr udata) +{ + TCGHelperInfo info = { + .func = cb, + .name = name, + .flags = flags, + .sizemask = dh_sizemask(void, 0) | + dh_sizemask(i32, 1) | + dh_sizemask(i32, 2) | + dh_sizemask(i64, 3) | + dh_sizemask(ptr, 4) | + dh_sizemask(ptr, 5), + + }; + TCGTemp *args[] = { + tcgv_i32_temp(cpu_index), + tcgv_i32_temp(meminfo), + tcgv_i64_temp(vaddr), + tcgv_ptr_temp(haddr), + tcgv_ptr_temp(udata), + }; + + tcg_gen_runtime_helper(&info, NULL, ARRAY_SIZE(args), args); +} + +static void gen_mem_cb(struct qemu_plugin_dyn_cb *cb, TCGv vaddr, uint8_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(cb->userp); + TCGv_ptr haddr; + + tcg_gen_ld_i32(cpu_index, cpu_env, + -ENV_OFFSET + offsetof(CPUState, cpu_index)); + tcg_gen_extu_tl_i64(vaddr64, vaddr); + + if (cb->mem.haddr) { +#ifdef CONFIG_SOFTMMU + haddr = tcg_temp_new_ptr(); + tcg_gen_ld_ptr(haddr, cpu_env, offsetof(CPUArchState, hostaddr)); +#else + haddr = tcg_const_ptr(NULL); +#endif + gen_helper_mem_haddr_cb("helper_plugin_vcpu_mem_haddr_cb", + cb->tcg_flags, cb->f.vcpu_mem_haddr, + cpu_index, meminfo, vaddr64, haddr, udata); + tcg_temp_free_ptr(haddr); + } else { + gen_helper_mem_cb("helper_plugin_vcpu_mem_cb", cb->tcg_flags, + cb->f.vcpu_mem, 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); +} + +void qemu_plugin_gen_vcpu_mem_callbacks(struct qemu_plugin_dyn_cb_arr *arr, + TCGv vaddr, uint8_t info) +{ + size_t i; + + for (i = 0; i < arr->n; i++) { + struct qemu_plugin_dyn_cb *cb = &arr->data[i]; + + switch (cb->type) { + case QEMU_PLUGIN_DYN_CB_TYPE_REGULAR: + gen_mem_cb(cb, vaddr, info); + break; + case QEMU_PLUGIN_DYN_CB_TYPE_INLINE: + gen_inline_op(cb); + break; + default: + g_assert_not_reached(); + } + } +} + +static void gen_helper_vcpu_udata_cb(const char *name, unsigned flags, + qemu_plugin_vcpu_udata_cb_t cb, + TCGv_i32 cpu_index, TCGv_ptr udata) +{ + TCGHelperInfo info = { + .func = cb, + .name = name, + .flags = flags, + .sizemask = dh_sizemask(void, 0) | + dh_sizemask(i32, 1) | + dh_sizemask(ptr, 2), + }; + TCGTemp *args[] = { + tcgv_i32_temp(cpu_index), + tcgv_ptr_temp(udata), + }; + + tcg_gen_runtime_helper(&info, NULL, ARRAY_SIZE(args), args); +} + +static void gen_vcpu_udata_cb(struct qemu_plugin_dyn_cb *cb) +{ + TCGv_i32 cpu_index = tcg_temp_new_i32(); + TCGv_ptr udata = tcg_const_ptr(cb->userp); + + tcg_gen_ld_i32(cpu_index, cpu_env, + -ENV_OFFSET + offsetof(CPUState, cpu_index)); + + gen_helper_vcpu_udata_cb("helper_plugin_vcpu_udata_cb", cb->tcg_flags, + cb->f.vcpu_udata, cpu_index, udata); + + tcg_temp_free_ptr(udata); + tcg_temp_free_i32(cpu_index); +} + +void qemu_plugin_gen_vcpu_udata_callbacks(struct qemu_plugin_dyn_cb_arr *arr) +{ + size_t i; + + for (i = 0; i < arr->n; i++) { + struct qemu_plugin_dyn_cb *cb = &arr->data[i]; + + switch (cb->type) { + case QEMU_PLUGIN_DYN_CB_TYPE_REGULAR: + gen_vcpu_udata_cb(cb); + break; + case QEMU_PLUGIN_DYN_CB_TYPE_INLINE: + gen_inline_op(cb); + break; + default: + g_assert_not_reached(); + } + } +} + +/* + * Tracking memory accesses performed from helpers requires extra work. + * If an instruction is emulated with helpers, struct qemu_plugin_insn's + * .calls_helpers is set. If so, this function is called. Here we do two + * things: (1) copy the CB descriptor, and keep track of it so that it can be + * freed later on, and (2) point CPUState.plugin_mem_cbs to the descriptor, so + * that we can read it at run-time (i.e. when the helper executes). + * This run-time access is performed from qemu_plugin_vcpu_mem_cb. + * + * Note that qemu_plugin_gen_disable_mem_helpers undoes (2). + */ +void +qemu_plugin_gen_enable_mem_helpers(const struct qemu_plugin_dyn_cb_arr *orig) +{ + struct qemu_plugin_dyn_cb_arr *arr; + TCGv_ptr ptr; + + arr = g_new(struct qemu_plugin_dyn_cb_arr, 1); + arr->capacity = orig->n; + arr->n = orig->n; + arr->data = g_new(struct qemu_plugin_dyn_cb, arr->n); + memcpy(arr->data, orig->data, sizeof(*arr->data) * arr->n); + qemu_plugin_add_dyn_cb_arr(arr); + + ptr = tcg_const_ptr(arr); + tcg_gen_st_ptr(ptr, cpu_env, -ENV_OFFSET + offsetof(CPUState, + plugin_mem_cbs)); + tcg_temp_free_ptr(ptr); +} + +/* Called once we're done instrumenting an instruction that calls helpers */ +void qemu_plugin_gen_disable_mem_helpers(void) +{ + TCGv_ptr ptr = tcg_const_ptr(NULL); + + tcg_gen_st_ptr(ptr, cpu_env, -ENV_OFFSET + offsetof(CPUState, + plugin_mem_cbs)); + tcg_temp_free_ptr(ptr); +} diff --git a/accel/tcg/Makefile.objs b/accel/tcg/Makefile.objs index d381a02f34..4f617e4fe5 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_PLUGINS) += plugin-gen.o From patchwork Thu Oct 25 17:20:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656271 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 EE14A17DE for ; Thu, 25 Oct 2018 17:40:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DABA22C26C for ; Thu, 25 Oct 2018 17:40:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE55B2C2AC; Thu, 25 Oct 2018 17:40: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 985072C29B for ; Thu, 25 Oct 2018 17:40:18 +0000 (UTC) Received: from localhost ([::1]:56112 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjcI-00089d-0f for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:40:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40311) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKj-0006hn-At for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKJ-00008N-7F for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:45 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:37033) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKH-0008Qz-9l for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:43 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 6D16D221DB; Thu, 25 Oct 2018 13:21:11 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=bpnD0ZnLUoFh8c4992Zev1J45j9zHMTl9UIsGquI/bY=; b=gx6Ta JBLWkY++MMRxayWMuBkAJGpASCamA818dlZiSYLNEwJMzIL8imFbDbm0eWVUJxGh KVPX29fNqN/rsK2bbExwIZsjI45sg7zAGKZJS/g4Hl7hd8ygmWfpJiV6QNOaJ1Jf Yykv6WonPagxWlYFJRWn8fBQXNegPsBMeizdn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=bpnD0ZnLUoFh8c4992Zev1J45j9zH MTl9UIsGquI/bY=; b=zYr9DUD7vgvAwjgnU1m4s96zZYq6TXiaNV5l548t/jyuz EajojuKNmz9dR9hWtNc+acNiyp0f/gSeQXiA7FqIxFGADvkKxKHYc1fbUuNUl/0U vr8tjKpRp/GSLpY+nSEuzJEPUWK5Ny93eTPzptD3KuPuz17auLiA44up7mGhqK+T 9phIeJBb2np50fc8kvi2+U9vZQ/LBJ7x7uM4DC72jbrTmWm8XzuDRTbsuiuSbVj6 CU5/N3KZK75p6IADIASLJf+/aMFmlNzLzF/axnScH8oTdhBvsNOMMq7mlZ5HCETM dsubyOn7mDp7PclAumrD/OvfikiR3wLFGhwDuFcrQ== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id D061FE4897; Thu, 25 Oct 2018 13:21:10 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:27 -0400 Message-Id: <20181025172057.20414-19-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 18/48] tcg: add memory callbacks for plugins (WIP) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP XXX: store hostaddr from non-i386 TCG backends XXX: what hostaddr to return for I/O accesses? XXX: what hostaddr to return for cross-page accesses? Here the trickiest feature is passing the host address to memory callbacks that request it. Perhaps it would be more appropriate to pass a "physical" address to plugins, but since in QEMU host addr ~= guest physical, I'm going with that for simplicity. To keep the implementation simple we piggy-back on the TLB fast path, and thus can only provide the host address _after_ memory accesses have occurred. For the slow path, it's a bit tedious because there are many places to update, but it's fairly simple. However, note that cross-page accesses are tricky, since the access might be to non-contiguous host addresses. So I'm punting on that and just passing NULL. Signed-off-by: Emilio G. Cota --- accel/tcg/atomic_template.h | 8 ++++- accel/tcg/softmmu_template.h | 39 ++++++++++++++++++++ include/exec/cpu-defs.h | 2 ++ include/exec/cpu_ldst_template.h | 43 +++++++++++++++-------- include/exec/cpu_ldst_useronly_template.h | 42 +++++++++++++++------- tcg/tcg-op.h | 5 +++ tcg/tcg.h | 4 +++ tcg/i386/tcg-target.inc.c | 5 +++ tcg/tcg-op.c | 37 ++++++++++++++----- tcg/tcg.c | 3 ++ 10 files changed, 152 insertions(+), 36 deletions(-) diff --git a/accel/tcg/atomic_template.h b/accel/tcg/atomic_template.h index b13318c1ce..3de34dc462 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 @@ -66,17 +67,22 @@ trace_guest_mem_before_exec(ENV_GET_CPU(env), addr, info | TRACE_MEM_ST); \ } while (0) -# define ATOMIC_TRACE_RMW_POST \ +# define ATOMIC_TRACE_RMW_POST do { \ + qemu_plugin_vcpu_mem_cb(ENV_GET_CPU(env), addr, haddr, info); \ + qemu_plugin_vcpu_mem_cb(ENV_GET_CPU(env), addr, haddr, info | TRACE_MEM_ST); \ +} while (0) # define ATOMIC_TRACE_LD_PRE \ trace_guest_mem_before_exec(ENV_GET_CPU(env), addr, info) # define ATOMIC_TRACE_LD_POST \ + qemu_plugin_vcpu_mem_cb(ENV_GET_CPU(env), addr, haddr, info) # define ATOMIC_TRACE_ST_PRE \ trace_guest_mem_before_exec(ENV_GET_CPU(env), addr, info) # define ATOMIC_TRACE_ST_POST \ + qemu_plugin_vcpu_mem_cb(ENV_GET_CPU(env), addr, haddr, info) #endif /* ATOMIC_TRACE_RMW_PRE */ diff --git a/accel/tcg/softmmu_template.h b/accel/tcg/softmmu_template.h index b0adea045e..f6d2f60b81 100644 --- a/accel/tcg/softmmu_template.h +++ b/accel/tcg/softmmu_template.h @@ -103,6 +103,11 @@ static inline DATA_TYPE glue(io_read, SUFFIX)(CPUArchState *env, MMUAccessType access_type) { CPUIOTLBEntry *iotlbentry = &env->iotlb[mmu_idx][index]; + + /* XXX Any sensible choice other than NULL? */ + if (tcg_ctx->plugin_mem_cb) { + env->hostaddr = NULL; + } return io_readx(env, iotlbentry, mmu_idx, addr, retaddr, recheck, access_type, DATA_SIZE); } @@ -162,12 +167,23 @@ WORD_TYPE helper_le_ld_name(CPUArchState *env, target_ulong addr, res2 = helper_le_ld_name(env, addr2, oi, retaddr); shift = (addr & (DATA_SIZE - 1)) * 8; + /* + * XXX cross-page accesses would have to be split into separate accesses + * for the host address to make sense. For now, just return NULL. + */ + if (tcg_ctx->plugin_mem_cb) { + env->hostaddr = NULL; + } + /* Little-endian combine. */ res = (res1 >> shift) | (res2 << ((DATA_SIZE * 8) - shift)); return res; } haddr = addr + entry->addend; + if (tcg_ctx->plugin_mem_cb) { + env->hostaddr = (void *)haddr; + } #if DATA_SIZE == 1 res = glue(glue(ld, LSUFFIX), _p)((uint8_t *)haddr); #else @@ -231,12 +247,19 @@ WORD_TYPE helper_be_ld_name(CPUArchState *env, target_ulong addr, res2 = helper_be_ld_name(env, addr2, oi, retaddr); shift = (addr & (DATA_SIZE - 1)) * 8; + if (tcg_ctx->plugin_mem_cb) { + env->hostaddr = NULL; + } + /* Big-endian combine. */ res = (res1 << shift) | (res2 >> ((DATA_SIZE * 8) - shift)); return res; } haddr = addr + entry->addend; + if (tcg_ctx->plugin_mem_cb) { + env->hostaddr = (void *)haddr; + } res = glue(glue(ld, LSUFFIX), _be_p)((uint8_t *)haddr); return res; } @@ -270,6 +293,10 @@ static inline void glue(io_write, SUFFIX)(CPUArchState *env, bool recheck) { CPUIOTLBEntry *iotlbentry = &env->iotlb[mmu_idx][index]; + + if (tcg_ctx->plugin_mem_cb) { + env->hostaddr = NULL; + } return io_writex(env, iotlbentry, mmu_idx, val, addr, retaddr, recheck, DATA_SIZE); } @@ -340,10 +367,16 @@ void helper_le_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val, glue(helper_ret_stb, MMUSUFFIX)(env, addr + i, val8, oi, retaddr); } + if (tcg_ctx->plugin_mem_cb) { + env->hostaddr = NULL; + } return; } haddr = addr + entry->addend; + if (tcg_ctx->plugin_mem_cb) { + env->hostaddr = (void *)haddr; + } #if DATA_SIZE == 1 glue(glue(st, SUFFIX), _p)((uint8_t *)haddr, val); #else @@ -418,10 +451,16 @@ void helper_be_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val, glue(helper_ret_stb, MMUSUFFIX)(env, addr + i, val8, oi, retaddr); } + if (tcg_ctx->plugin_mem_cb) { + env->hostaddr = NULL; + } return; } haddr = addr + entry->addend; + if (tcg_ctx->plugin_mem_cb) { + env->hostaddr = (void *)haddr; + } glue(glue(st, SUFFIX), _be_p)((uint8_t *)haddr, val); } #endif /* DATA_SIZE > 1 */ diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h index 40cd5d4774..c92c24a4a3 100644 --- a/include/exec/cpu-defs.h +++ b/include/exec/cpu-defs.h @@ -186,6 +186,8 @@ typedef struct CPUTLBDesc { CPUTLBEntry tlb_v_table[NB_MMU_MODES][CPU_VTLB_SIZE]; \ CPU_IOTLB \ CPUIOTLBEntry iotlb_v[NB_MMU_MODES][CPU_VTLB_SIZE]; \ + /* stores the host address of a guest access, if needed for plugins */ \ + void *hostaddr; \ size_t tlb_flush_count; \ target_ulong tlb_flush_addr; \ target_ulong tlb_flush_mask; \ diff --git a/include/exec/cpu_ldst_template.h b/include/exec/cpu_ldst_template.h index 0f061d47ef..e25319de4b 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,11 @@ glue(glue(glue(cpu_ld, USUFFIX), MEMSUFFIX), _ra)(CPUArchState *env, target_ulong addr; int mmu_idx; TCGMemOpIdx oi; - + uintptr_t hostaddr; #if !defined(SOFTMMU_CODE_ACCESS) - trace_guest_mem_before_exec( - ENV_GET_CPU(env), ptr, - trace_mem_build_info(SHIFT, false, MO_TE, false)); + uint8_t meminfo = trace_mem_build_info(SHIFT, false, MO_TE, false); + + trace_guest_mem_before_exec(ENV_GET_CPU(env), ptr, meminfo); #endif addr = ptr; @@ -101,10 +102,14 @@ glue(glue(glue(cpu_ld, USUFFIX), MEMSUFFIX), _ra)(CPUArchState *env, oi = make_memop_idx(SHIFT, mmu_idx); res = glue(glue(helper_ret_ld, URETSUFFIX), MMUSUFFIX)(env, addr, oi, retaddr); + hostaddr = (uintptr_t)env->hostaddr; } else { - uintptr_t hostaddr = addr + entry->addend; + hostaddr = addr + entry->addend; res = glue(glue(ld, USUFFIX), _p)((uint8_t *)hostaddr); } +#ifndef SOFTMMU_CODE_ACCESS + qemu_plugin_vcpu_mem_cb(ENV_GET_CPU(env), ptr, (void *)hostaddr, meminfo); +#endif return res; } @@ -125,11 +130,11 @@ glue(glue(glue(cpu_lds, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env, target_ulong addr; int mmu_idx; TCGMemOpIdx oi; - + uintptr_t hostaddr; #if !defined(SOFTMMU_CODE_ACCESS) - trace_guest_mem_before_exec( - ENV_GET_CPU(env), ptr, - trace_mem_build_info(SHIFT, true, MO_TE, false)); + uint8_t meminfo = trace_mem_build_info(SHIFT, false, MO_TE, false); + + trace_guest_mem_before_exec(ENV_GET_CPU(env), ptr, meminfo); #endif addr = ptr; @@ -140,10 +145,14 @@ glue(glue(glue(cpu_lds, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env, oi = make_memop_idx(SHIFT, mmu_idx); res = (DATA_STYPE)glue(glue(helper_ret_ld, SRETSUFFIX), MMUSUFFIX)(env, addr, oi, retaddr); + hostaddr = (uintptr_t)env->hostaddr; } else { - uintptr_t hostaddr = addr + entry->addend; + hostaddr = addr + entry->addend; res = glue(glue(lds, SUFFIX), _p)((uint8_t *)hostaddr); } +#ifndef SOFTMMU_CODE_ACCESS + qemu_plugin_vcpu_mem_cb(ENV_GET_CPU(env), ptr, (void *)hostaddr, meminfo); +#endif return res; } @@ -167,11 +176,11 @@ glue(glue(glue(cpu_st, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env, target_ulong addr; int mmu_idx; TCGMemOpIdx oi; - + uintptr_t hostaddr; #if !defined(SOFTMMU_CODE_ACCESS) - trace_guest_mem_before_exec( - ENV_GET_CPU(env), ptr, - trace_mem_build_info(SHIFT, false, MO_TE, true)); + uint8_t meminfo = trace_mem_build_info(SHIFT, false, MO_TE, true); + + trace_guest_mem_before_exec(ENV_GET_CPU(env), ptr, meminfo); #endif addr = ptr; @@ -182,10 +191,14 @@ glue(glue(glue(cpu_st, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env, oi = make_memop_idx(SHIFT, mmu_idx); glue(glue(helper_ret_st, SUFFIX), MMUSUFFIX)(env, addr, v, oi, retaddr); + hostaddr = (uintptr_t)env->hostaddr; } else { - uintptr_t hostaddr = addr + entry->addend; + hostaddr = addr + entry->addend; glue(glue(st, SUFFIX), _p)((uint8_t *)hostaddr, v); } +#ifndef SOFTMMU_CODE_ACCESS + qemu_plugin_vcpu_mem_cb(ENV_GET_CPU(env), ptr, (void *)hostaddr, meminfo); +#endif } static inline void diff --git a/include/exec/cpu_ldst_useronly_template.h b/include/exec/cpu_ldst_useronly_template.h index 0fd6019af0..e752e9c00e 100644 --- a/include/exec/cpu_ldst_useronly_template.h +++ b/include/exec/cpu_ldst_useronly_template.h @@ -64,12 +64,19 @@ static inline RES_TYPE glue(glue(cpu_ld, USUFFIX), MEMSUFFIX)(CPUArchState *env, abi_ptr ptr) { + RES_TYPE ret; +#if !defined(CODE_ACCESS) + uint8_t meminfo = trace_mem_build_info(SHIFT, false, MO_TE, false); + + trace_guest_mem_before_exec(ENV_GET_CPU(env), ptr, meminfo); +#endif + + ret = glue(glue(ld, USUFFIX), _p)(g2h(ptr)); + #if !defined(CODE_ACCESS) - trace_guest_mem_before_exec( - ENV_GET_CPU(env), ptr, - trace_mem_build_info(SHIFT, false, MO_TE, false)); + qemu_plugin_vcpu_mem_cb(ENV_GET_CPU(env), ptr, NULL, meminfo); #endif - return glue(glue(ld, USUFFIX), _p)(g2h(ptr)); + return ret; } static inline RES_TYPE @@ -88,12 +95,19 @@ glue(glue(glue(cpu_ld, USUFFIX), MEMSUFFIX), _ra)(CPUArchState *env, static inline int glue(glue(cpu_lds, SUFFIX), MEMSUFFIX)(CPUArchState *env, abi_ptr ptr) { + int ret; #if !defined(CODE_ACCESS) - trace_guest_mem_before_exec( - ENV_GET_CPU(env), ptr, - trace_mem_build_info(SHIFT, true, MO_TE, false)); + uint8_t meminfo = trace_mem_build_info(SHIFT, true, MO_TE, false); + + trace_guest_mem_before_exec(ENV_GET_CPU(env), ptr, meminfo); #endif - return glue(glue(lds, SUFFIX), _p)(g2h(ptr)); + + ret = glue(glue(lds, SUFFIX), _p)(g2h(ptr)); + +#if !defined(CODE_ACCESS) + qemu_plugin_vcpu_mem_cb(ENV_GET_CPU(env), ptr, NULL, meminfo); +#endif + return ret; } static inline int @@ -109,17 +123,21 @@ glue(glue(glue(cpu_lds, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env, } #endif -#ifndef CODE_ACCESS +#if !defined(CODE_ACCESS) static inline void glue(glue(cpu_st, SUFFIX), MEMSUFFIX)(CPUArchState *env, abi_ptr ptr, RES_TYPE v) { #if !defined(CODE_ACCESS) - trace_guest_mem_before_exec( - ENV_GET_CPU(env), ptr, - trace_mem_build_info(SHIFT, false, MO_TE, true)); + uint8_t meminfo = trace_mem_build_info(SHIFT, false, MO_TE, true); + trace_guest_mem_before_exec(ENV_GET_CPU(env), ptr, meminfo); #endif + glue(glue(st, SUFFIX), _p)(g2h(ptr), v); + +#if !defined(CODE_ACCESS) + qemu_plugin_vcpu_mem_cb(ENV_GET_CPU(env), ptr, NULL, meminfo); +#endif } static inline void diff --git a/tcg/tcg-op.h b/tcg/tcg-op.h index 7513c1eb7c..cded8fc05b 100644 --- a/tcg/tcg-op.h +++ b/tcg/tcg-op.h @@ -1208,6 +1208,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); diff --git a/tcg/tcg.h b/tcg/tcg.h index 2c378415d2..d5afe25c97 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -29,6 +29,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" @@ -719,6 +720,9 @@ struct TCGContext { TCGLabel *exitreq_label; + struct qemu_plugin_dyn_cb_arr *plugin_mem_cb; + struct qemu_plugin_insn *plugin_insn; + TCGTempSet free_temps[TCG_TYPE_COUNT * 2]; TCGTemp temps[TCG_MAX_TEMPS]; /* globals first, temps after */ diff --git a/tcg/i386/tcg-target.inc.c b/tcg/i386/tcg-target.inc.c index 5cbb07deab..7d9e6765c4 100644 --- a/tcg/i386/tcg-target.inc.c +++ b/tcg/i386/tcg-target.inc.c @@ -1685,6 +1685,11 @@ static inline void tcg_out_tlb_load(TCGContext *s, TCGReg addrlo, TCGReg addrhi, /* add addend(r0), r1 */ tcg_out_modrm_offset(s, OPC_ADD_GvEv + hrexw, r1, r0, offsetof(CPUTLBEntry, addend)); + + if (s->plugin_mem_cb) { + tcg_out_st(s, TCG_TYPE_PTR, r1, TCG_AREG0, + offsetof(CPUArchState, hostaddr)); + } } /* diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c index 7a8015c5a9..add63547e3 100644 --- a/tcg/tcg-op.c +++ b/tcg/tcg-op.c @@ -31,6 +31,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 @@ -2699,26 +2700,42 @@ static void tcg_gen_req_mo(TCGBar type) } } +static inline void plugin_gen_mem_callbacks(TCGv vaddr, uint8_t info) +{ + struct qemu_plugin_dyn_cb_arr *arr = tcg_ctx->plugin_mem_cb; + + if (arr == NULL) { + return; + } + qemu_plugin_gen_vcpu_mem_callbacks(arr, vaddr, info); +} + void tcg_gen_qemu_ld_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop) { + uint8_t info = trace_mem_get_info(memop, 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, 0)); + trace_guest_mem_before_tcg(tcg_ctx->cpu, cpu_env, addr, info); gen_ldst_i32(INDEX_op_qemu_ld_i32, val, addr, memop, idx); + plugin_gen_mem_callbacks(addr, info); } void tcg_gen_qemu_st_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop) { + uint8_t info = trace_mem_get_info(memop, 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, 1)); + trace_guest_mem_before_tcg(tcg_ctx->cpu, cpu_env, addr, info); gen_ldst_i32(INDEX_op_qemu_st_i32, val, addr, memop, idx); + plugin_gen_mem_callbacks(addr, info); } void tcg_gen_qemu_ld_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) { + uint8_t info; + tcg_gen_req_mo(TCG_MO_LD_LD | TCG_MO_ST_LD); if (TCG_TARGET_REG_BITS == 32 && (memop & MO_SIZE) < MO_64) { tcg_gen_qemu_ld_i32(TCGV_LOW(val), addr, idx, memop); @@ -2731,13 +2748,16 @@ void tcg_gen_qemu_ld_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) } memop = tcg_canonicalize_memop(memop, 1, 0); - trace_guest_mem_before_tcg(tcg_ctx->cpu, cpu_env, - addr, trace_mem_get_info(memop, 0)); + info = trace_mem_get_info(memop, 0); + trace_guest_mem_before_tcg(tcg_ctx->cpu, cpu_env, addr, info); gen_ldst_i64(INDEX_op_qemu_ld_i64, val, addr, memop, idx); + plugin_gen_mem_callbacks(addr, info); } void tcg_gen_qemu_st_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) { + uint8_t info; + tcg_gen_req_mo(TCG_MO_LD_ST | TCG_MO_ST_ST); if (TCG_TARGET_REG_BITS == 32 && (memop & MO_SIZE) < MO_64) { tcg_gen_qemu_st_i32(TCGV_LOW(val), addr, idx, memop); @@ -2745,9 +2765,10 @@ void tcg_gen_qemu_st_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) } memop = tcg_canonicalize_memop(memop, 1, 1); - trace_guest_mem_before_tcg(tcg_ctx->cpu, cpu_env, - addr, trace_mem_get_info(memop, 1)); + info = trace_mem_get_info(memop, 1); + trace_guest_mem_before_tcg(tcg_ctx->cpu, cpu_env, addr, info); gen_ldst_i64(INDEX_op_qemu_st_i64, val, addr, memop, idx); + plugin_gen_mem_callbacks(addr, info); } static void tcg_gen_ext_i32(TCGv_i32 ret, TCGv_i32 val, TCGMemOp opc) diff --git a/tcg/tcg.c b/tcg/tcg.c index a6824145b0..b10bda587a 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1839,6 +1839,9 @@ void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args) * that @func can only be in one TCGHelperInfo. */ info = qht_lookup_custom(&helper_table, func, hash, tcg_helper_lookup_cmp); + if (unlikely(tcg_ctx->plugin_insn)) { + tcg_ctx->plugin_insn->calls_helpers = true; + } do_tcg_gen_callN(info, ret, nargs, args); } From patchwork Thu Oct 25 17:20:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656311 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 D4FBD13B5 for ; Thu, 25 Oct 2018 17:52:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8EA62C2A6 for ; Thu, 25 Oct 2018 17:52:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD25F2C2AC; Thu, 25 Oct 2018 17:52: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6921D2C2A6 for ; Thu, 25 Oct 2018 17:52:48 +0000 (UTC) Received: from localhost ([::1]:56168 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjoN-0002Dr-Dx for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:52:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40316) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKm-0006ho-Bc for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKJ-00008d-Ab for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:44 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:58443) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKJ-0008Qr-2n for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:43 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 6069822163; Thu, 25 Oct 2018 13:21:11 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=9iGjhLn6k03jD8By1o8bOkvChm5ZuxbnfvwkWshftdU=; b=xqDvs r0HEdS17NwAWKWWxdJVMpH9ghiI2liWOTMVav32sOHhNE7n2BAcaxYrSqo2KegIZ 7OdZ5seP5okZUMoCIeL8rS6vqGb/GlP8pz0OyJmB9oUH4LWw1zKkYc6hwfqp5ccU IG8fCfKAfvg99uLaufEoRk2HGWoGu1/MzilGGI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=9iGjhLn6k03jD8By1o8bOkvChm5Zu xbnfvwkWshftdU=; b=F2RtLX+0IaWdIR3AXdtv9qspDh2nlxG8GWvZ4SwLvuOOS MlnAPZ9a24VE0xxh1HES1D8F6aUlYP1GMiarYor94djebJ2ElmvHuUC7MWFUvAOW hyr0QgIVq8PtMBVDZmrrSMRdx31yj7Gol7zsAeLxegWop8KVVFgilogwQZnVmkUp C6Ae58yakLdFNU+2aVg7sQDcyItEOqs2Pd1DqeQGSNoyudhx6cWeBfzcgPff5RcU z/OVQVOAlo2ou34jXT7iYtJJ2Bi/MCrt8l7EgUyPdw5n/XMse8M5wlduLB7syGKR 7+AR7c+NOMTWO6q6LGmE8o3MifykxphPb6FebLhlQ== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 21223E455F; Thu, 25 Oct 2018 13:21:11 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:28 -0400 Message-Id: <20181025172057.20414-20-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 19/48] translate-all: notify plugin code of tb_flush X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota Reviewed-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 3423cf74db..1690e3fd5b 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1233,6 +1233,8 @@ static gboolean tb_host_size_iter(gpointer key, gpointer value, gpointer data) /* flush all the translation blocks */ 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. @@ -1240,6 +1242,7 @@ 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(); @@ -1265,6 +1268,9 @@ 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 Thu Oct 25 17:20:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656323 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 56C5213A9 for ; Thu, 25 Oct 2018 17:58:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CC7B2BF92 for ; Thu, 25 Oct 2018 17:58:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E9AC2BF98; Thu, 25 Oct 2018 17:58: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D3E1B2BF92 for ; Thu, 25 Oct 2018 17:58:33 +0000 (UTC) Received: from localhost ([::1]:56213 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjtx-0001z7-5p for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:58:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40455) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKm-0006j0-Fi for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKA-00005J-Fw for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:38 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:45331) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjK5-0008RB-QK for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:31 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id BBE25221CD; Thu, 25 Oct 2018 13:21:11 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=bTgXBL5M5A8WbcrDXxhbACSxPu5lhrRIU6or8cts1GU=; b=Trqe6 StoV9xD3HWQyjnJqH2yVj1gqannG4vTugzSjFz1YeRHvpJqbiFlLoqmAbsnD5kMO /HuxWu4Mx/oDN9a8zorB8a9o4s0LQMHolIbBx0NmRBwUVWNU1ZL025bswwABhDUQ e9OZA1Br3/XlgK7CJBaN0aSggVnAULMeJD2CI0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=bTgXBL5M5A8WbcrDXxhbACSxPu5lh rRIU6or8cts1GU=; b=Cp03ufaAK7v+xhYpxC2s2xRHjdfRsgp/Suqm1Qg4q4AhF wA/A4Eoi3eiA2opQnE4PaOb7y8284MaGEXN0+aIVZbOLBL69MC6x8a39SAWO33B3 51cqD3LcWPLaTEnznoO5HDX2UwOyR7OYa9aItH3HuSTZpOrbaB+WJG+vbwDBJgq3 eURvsDiiZNVlK/p7uiLqV7j44ydCXm5tt/uZ02aeikS5kQYL7b7pkrjg/mxd71jI 8sWSt23DxV93PfR4TkNGa10bxlaEWy1zhy+VOCRc7vTtuUUr8qIbV+/96lBWak7s teZc25JJsuv9isY2swB9ph27PTX7cc/+4Nl42mKqQ== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 562C9E4074; Thu, 25 Oct 2018 13:21:11 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:29 -0400 Message-Id: <20181025172057.20414-21-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 20/48] *-user: notify plugin of exit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota Reviewed-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 66492aaf5d..b7818af450 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 14e94e28fa..768856483a 100644 --- a/linux-user/exit.c +++ b/linux-user/exit.c @@ -32,4 +32,5 @@ void preexit_cleanup(CPUArchState *env, int code) __gcov_dump(); #endif gdb_exit(env, code); + qemu_plugin_atexit_cb(); } From patchwork Thu Oct 25 17:20:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656277 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 35CFC13B5 for ; Thu, 25 Oct 2018 17:43:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25E192C276 for ; Thu, 25 Oct 2018 17:43:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19EC82C2AC; Thu, 25 Oct 2018 17:43: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 518172C276 for ; Thu, 25 Oct 2018 17:43:12 +0000 (UTC) Received: from localhost ([::1]:56122 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjf5-00039x-8T for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:43:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKh-0006hv-Ey for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKf-0000Ny-GQ for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:07 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:41303) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKc-0008Vr-4x for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:02 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id F1DEE221E9; Thu, 25 Oct 2018 13:21:11 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=iiOLO/zxFbwGEMh0OmoiNmwqdarGkjYousvml3jEDN0=; b=E8SAg 18TTRsdFiaN/3Qrffly+A2nHvm0rrUsE0ZwzitQByOc+aLUlgVyzmAuVCaPQhz3u 9RtGsExgXGmun4HIq2qD8ilnFuQRwa3tN3vXSNLhBAcK5iacVll8kbKSH/HbW63h naqFgioE4PUDKdbcb2s+h/6J0br6mWkj7Q6wlc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=iiOLO/zxFbwGEMh0OmoiNmwqdarGk jYousvml3jEDN0=; b=nC7BkTk2PUHh7tL+fiaMEIsP9Dung2ewq1Oe0kOEtZ+ih wrYMTd5LHhPtmPmUtFznM8pxzodlY3ndx/y9+JW02i8S5fo30v7ynYpLD9LBwJFJ kLsVfE5imuGtyQTnBSGTE3B5+StA+BbEqJO7BsvW1hzC9WSSVjd370ayQ3XXinHN X8HYcdwwwByJO+TjsvescWGx5UcQ/16naxB6zsdiFusRDRPGEUh5hoQ/Skt56Oum X9R29MDmC3B5V85TM/OglHGcfH/5U6EUcw4OAoTz4rty7O9ruTDJm6C0xwQGo8Rt tZX/6r4zi36kjvfEUwtaxfvoZFY1j64YG4vzXCbrA== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 845AEE455F; Thu, 25 Oct 2018 13:21:11 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:30 -0400 Message-Id: <20181025172057.20414-22-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 21/48] *-user: plugin syscalls X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- bsd-user/syscall.c | 9 +++++++++ linux-user/syscall.c | 3 +++ 2 files changed, 12 insertions(+) diff --git a/bsd-user/syscall.c b/bsd-user/syscall.c index b7818af450..4993f81b2b 100644 --- a/bsd-user/syscall.c +++ b/bsd-user/syscall.c @@ -323,6 +323,8 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, gemu_log("freebsd syscall %d\n", num); #endif 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); if(do_strace) print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); @@ -404,6 +406,7 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, if (do_strace) print_freebsd_syscall_ret(num, ret); trace_guest_user_syscall_ret(cpu, num, ret); + qemu_plugin_vcpu_syscall_ret(cpu, num, ret); return ret; efault: ret = -TARGET_EFAULT; @@ -422,6 +425,8 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1, gemu_log("netbsd syscall %d\n", num); #endif trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0); + qemu_plugin_vcpu_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, + 0); if(do_strace) print_netbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); @@ -480,6 +485,7 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1, if (do_strace) print_netbsd_syscall_ret(num, ret); trace_guest_user_syscall_ret(cpu, num, ret); + qemu_plugin_vcpu_syscall_ret(cpu, num, ret); return ret; efault: ret = -TARGET_EFAULT; @@ -498,6 +504,8 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1, gemu_log("openbsd syscall %d\n", num); #endif trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0); + qemu_plugin_vcpu_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, + 0); if(do_strace) print_openbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); @@ -556,6 +564,7 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1, if (do_strace) print_openbsd_syscall_ret(num, ret); trace_guest_user_syscall_ret(cpu, num, ret); + qemu_plugin_vcpu_syscall_ret(cpu, num, ret); return ret; efault: ret = -TARGET_EFAULT; diff --git a/linux-user/syscall.c b/linux-user/syscall.c index ae3c0dfef7..a6d17a9f37 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -11232,6 +11232,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, 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); if (unlikely(do_strace)) { print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); @@ -11244,5 +11246,6 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, } trace_guest_user_syscall_ret(cpu, num, ret); + qemu_plugin_vcpu_syscall_ret(cpu, num, ret); return ret; } From patchwork Thu Oct 25 17:20:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656259 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 5CEAE109C for ; Thu, 25 Oct 2018 17:36:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A7B4283D1 for ; Thu, 25 Oct 2018 17:36:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DC6F2C22A; Thu, 25 Oct 2018 17:36: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D7615283D1 for ; Thu, 25 Oct 2018 17:36:58 +0000 (UTC) Received: from localhost ([::1]:56093 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjZ4-0004Tn-5P for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:36:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKi-0006hj-TU for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKX-0000J4-Vp for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:59 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:38281) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKV-0008Vq-Uu for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:57 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 3521422195; Thu, 25 Oct 2018 13:21:12 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=g7CeQWYfDlSfIkIX14kuqFCAQ4a/V7lnl/Y3E8tQnOM=; b=1ouw/ rSH0DBQsGD/7d/7OHli9rJvE1g6vWE4kpOsADLDuRTfaPHHxv8cHRPTVroxUJT4M uk+y/6GMAwMEJpjaKTwdUHhHyPIHQP37rupJpcaU4JVvP6Q1LG34wUoSHb4vEBKV 7GMnkiQvpMwq6wySs8G8/u4ijDsAzV2gB6fqo8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=g7CeQWYfDlSfIkIX14kuqFCAQ4a/V 7lnl/Y3E8tQnOM=; b=RB23N7/en05O1q+Hfmkq/KJ0Ru5E8JiFm35hXNkBOcoRv jTT9k2ADgBFlTduViWQ/NhiY8XUDpI459V/dQDSd/O+kKW1C6pACfGZqiHVYmFWW axtx34fqjaLJyAOLey3wy4D4otY7AlEvBsuRp/2BkcOCDbRwKlh4fcKw+qsqLPja I0k8DLj+GuWKWrz1zQVOrD7gSOHj/B/dDPwwIOnOHO7hDJ7nEbucW9O5OCcTeQkg VZciRkqCOTzuh+bcoo77FDuNnK9NO0IQ2ECAqCKEQNbyEPr/ylD3uatLKMXcXYuR NRSBD8coaiIlxCnxt2yej3eBImp7BDYFUn14dmhAw== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id BAFC2E47CB; Thu, 25 Oct 2018 13:21:11 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:31 -0400 Message-Id: <20181025172057.20414-23-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 22/48] cpu: hook plugin vcpu events X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- cpus.c | 10 ++++++++++ exec.c | 2 ++ qom/cpu.c | 2 ++ 3 files changed, 14 insertions(+) diff --git a/cpus.c b/cpus.c index 28e39f045a..3efe89354d 100644 --- a/cpus.c +++ b/cpus.c @@ -43,6 +43,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" @@ -1322,12 +1323,21 @@ static void qemu_tcg_rr_wait_io_event(CPUState *cpu) static void qemu_wait_io_event(CPUState *cpu) { + bool asleep = false; + g_assert(cpu_mutex_locked(cpu)); g_assert(!qemu_mutex_iothread_locked()); while (cpu_thread_is_idle(cpu)) { + if (!asleep) { + asleep = true; + qemu_plugin_vcpu_idle_cb(cpu); + } qemu_cond_wait(&cpu->halt_cond, &cpu->lock); } + if (asleep) { + 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 cd171adb93..71fc76f55e 100644 --- a/exec.c +++ b/exec.c @@ -967,6 +967,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 d1e6ecae03..062817c03b 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -32,6 +32,7 @@ #include "hw/boards.h" #include "hw/qdev-properties.h" #include "trace-root.h" +#include "qemu/plugin.h" CPUInterruptHandler cpu_interrupt_handler; @@ -353,6 +354,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 Thu Oct 25 17:20:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656255 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 E72EB1751 for ; Thu, 25 Oct 2018 17:33:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2A63283D1 for ; Thu, 25 Oct 2018 17:33:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C70712842D; Thu, 25 Oct 2018 17:33:39 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ED9F9283D1 for ; Thu, 25 Oct 2018 17:33:38 +0000 (UTC) Received: from localhost ([::1]:56071 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjVq-0007DB-B9 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:33:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKj-0006ht-5k for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKP-0000C0-I8 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:51 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:54151) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKP-00005M-Ap for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:49 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 558BB221B0; Thu, 25 Oct 2018 13:21:12 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=LzeHWfSGmZjbsrJYUC22VsMFpXN1fAmLAwSjXIr9Kbk=; b=vim8z mNUDrfgd8sEoTjnMb2puh7nZJrnipL7SuZhS+xs8AWNCoGV7tfM1OcV6mNOZc5+N eSl9NWplqVu+hlbArHRrMgnJY7puBSCU05aO4JhQnnw1zXDV6oUG1iMntnbNjD9R 5L6xCXCaJKn8dabVyKVcnKoHpm0+7ndrZgIYtk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=LzeHWfSGmZjbsrJYUC22VsMFpXN1f AmLAwSjXIr9Kbk=; b=KCxo/1+2+gc7K4ySaFgnrc63Oj2TLXwLFBsp8Cfmu15a3 qZHzMQH4x15ulhdldPjCqKHMIH2ZsVv91iH+42evHrs0MGjnrb352KckaElzPseK 183KzsYFIF8RPnEY6JkdoKLUyjtCfhcp5neNOtF7aFMFyw0UKrq1gdvn0x7KaSRz /a1ncjCQuokdF0U6QeBG7ezSYAb0HwcfOKnZjQ1RA7lRvIljhVlqnDIA/lhb59BD aTkPqovUSEECvEAZNACPGtUeWHuC02so4/xPUPNyZRa9uSaAtB45rCkgWojtkfwF yApsXs6LO4bHjzkbf9TzxbfutXXvsFJ/6rpWZqzlw== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id F1372E4074; Thu, 25 Oct 2018 13:21:11 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:32 -0400 Message-Id: <20181025172057.20414-24-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 23/48] translator: add plugin_insn argument to translate_insn X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- include/exec/translator.h | 4 +++- accel/tcg/translator.c | 4 ++-- target/alpha/translate.c | 3 ++- target/arm/translate-a64.c | 3 ++- target/arm/translate.c | 6 ++++-- target/hppa/translate.c | 3 ++- target/i386/translate.c | 3 ++- target/m68k/translate.c | 3 ++- target/mips/translate.c | 3 ++- target/openrisc/translate.c | 3 ++- target/ppc/translate.c | 3 ++- target/riscv/translate.c | 3 ++- target/s390x/translate.c | 3 ++- target/sh4/translate.c | 3 ++- target/sparc/translate.c | 3 ++- target/xtensa/translate.c | 3 ++- 16 files changed, 35 insertions(+), 18 deletions(-) diff --git a/include/exec/translator.h b/include/exec/translator.h index 71e7b2c347..a28147b3dd 100644 --- a/include/exec/translator.h +++ b/include/exec/translator.h @@ -20,6 +20,7 @@ #include "exec/exec-all.h" +#include "qemu/plugin.h" #include "tcg/tcg.h" @@ -112,7 +113,8 @@ typedef struct TranslatorOps { void (*insn_start)(DisasContextBase *db, CPUState *cpu); bool (*breakpoint_check)(DisasContextBase *db, CPUState *cpu, const CPUBreakpoint *bp); - void (*translate_insn)(DisasContextBase *db, CPUState *cpu); + void (*translate_insn)(DisasContextBase *db, CPUState *cpu, + struct qemu_plugin_insn *plugin_insn); void (*tb_stop)(DisasContextBase *db, CPUState *cpu); void (*disas_log)(const DisasContextBase *db, CPUState *cpu); } TranslatorOps; diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index afd0a49ea6..8591e4b72a 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -101,10 +101,10 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, && (tb_cflags(db->tb) & CF_LAST_IO)) { /* Accept I/O on the last instruction. */ gen_io_start(); - ops->translate_insn(db, cpu); + ops->translate_insn(db, cpu, NULL); gen_io_end(); } else { - ops->translate_insn(db, cpu); + ops->translate_insn(db, cpu, NULL); } /* Stop translation if translate_insn so indicated. */ diff --git a/target/alpha/translate.c b/target/alpha/translate.c index 25cd95931d..72a302e102 100644 --- a/target/alpha/translate.c +++ b/target/alpha/translate.c @@ -2983,7 +2983,8 @@ static bool alpha_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cpu, return true; } -static void alpha_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) +static void alpha_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu, + struct qemu_plugin_insn *plugin_insn) { DisasContext *ctx = container_of(dcbase, DisasContext, base); CPUAlphaState *env = cpu->env_ptr; diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index bb9c4d8ac7..8b1e20dd59 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -13937,7 +13937,8 @@ static bool aarch64_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cpu, return true; } -static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) +static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu, + struct qemu_plugin_insn *plugin_insn) { DisasContext *dc = container_of(dcbase, DisasContext, base); CPUARMState *env = cpu->env_ptr; diff --git a/target/arm/translate.c b/target/arm/translate.c index 1b4bacb522..2fd32a2684 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -12787,7 +12787,8 @@ static void arm_post_translate_insn(DisasContext *dc) translator_loop_temp_check(&dc->base); } -static void arm_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) +static void arm_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu, + struct qemu_plugin_insn *plugin_insn) { DisasContext *dc = container_of(dcbase, DisasContext, base); CPUARMState *env = cpu->env_ptr; @@ -12854,7 +12855,8 @@ static bool thumb_insn_is_unconditional(DisasContext *s, uint32_t insn) return false; } -static void thumb_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) +static void thumb_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu, + struct qemu_plugin_insn *plugin_insn) { DisasContext *dc = container_of(dcbase, DisasContext, base); CPUARMState *env = cpu->env_ptr; diff --git a/target/hppa/translate.c b/target/hppa/translate.c index df9179e70f..6c2a7fbc46 100644 --- a/target/hppa/translate.c +++ b/target/hppa/translate.c @@ -4737,7 +4737,8 @@ static bool hppa_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cs, return true; } -static void hppa_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) +static void hppa_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs, + struct qemu_plugin_insn *plugin_insn) { DisasContext *ctx = container_of(dcbase, DisasContext, base); CPUHPPAState *env = cs->env_ptr; diff --git a/target/i386/translate.c b/target/i386/translate.c index 83c1ebe491..86e59d7bf7 100644 --- a/target/i386/translate.c +++ b/target/i386/translate.c @@ -8525,7 +8525,8 @@ static bool i386_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cpu, } } -static void i386_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) +static void i386_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu, + struct qemu_plugin_insn *plugin_insn) { DisasContext *dc = container_of(dcbase, DisasContext, base); target_ulong pc_next = disas_insn(dc, cpu); diff --git a/target/m68k/translate.c b/target/m68k/translate.c index d55e707cf6..dd7d868b25 100644 --- a/target/m68k/translate.c +++ b/target/m68k/translate.c @@ -6087,7 +6087,8 @@ static bool m68k_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cpu, return true; } -static void m68k_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) +static void m68k_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu, + struct qemu_plugin_insn *plugin_insn) { DisasContext *dc = container_of(dcbase, DisasContext, base); CPUM68KState *env = cpu->env_ptr; diff --git a/target/mips/translate.c b/target/mips/translate.c index 544e4dc19c..efafc6e795 100644 --- a/target/mips/translate.c +++ b/target/mips/translate.c @@ -25349,7 +25349,8 @@ static bool mips_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cs, return true; } -static void mips_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) +static void mips_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs, + struct qemu_plugin_insn *plugin_insn) { CPUMIPSState *env = cs->env_ptr; DisasContext *ctx = container_of(dcbase, DisasContext, base); diff --git a/target/openrisc/translate.c b/target/openrisc/translate.c index a271cd3903..947330e10a 100644 --- a/target/openrisc/translate.c +++ b/target/openrisc/translate.c @@ -1301,7 +1301,8 @@ static bool openrisc_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cs, return true; } -static void openrisc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) +static void openrisc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs, + struct qemu_plugin_insn *plugin_insn) { DisasContext *dc = container_of(dcbase, DisasContext, base); OpenRISCCPU *cpu = OPENRISC_CPU(cs); diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 2d31b5f7a1..34c3ed0a41 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -7545,7 +7545,8 @@ static bool ppc_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cs, return true; } -static void ppc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) +static void ppc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs, + struct qemu_plugin_insn *plugin_insn) { DisasContext *ctx = container_of(dcbase, DisasContext, base); CPUPPCState *env = cs->env_ptr; diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 18d7b6d147..a33cf6802b 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -1843,7 +1843,8 @@ static bool riscv_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cpu, } -static void riscv_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) +static void riscv_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu, + struct qemu_plugin_insn *plugin_insn) { DisasContext *ctx = container_of(dcbase, DisasContext, base); CPURISCVState *env = cpu->env_ptr; diff --git a/target/s390x/translate.c b/target/s390x/translate.c index b5bd56b7ee..6ac1a8d821 100644 --- a/target/s390x/translate.c +++ b/target/s390x/translate.c @@ -6228,7 +6228,8 @@ static bool s390x_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cs, return true; } -static void s390x_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) +static void s390x_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs, + struct qemu_plugin_insn *plugin_insn) { CPUS390XState *env = cs->env_ptr; DisasContext *dc = container_of(dcbase, DisasContext, base); diff --git a/target/sh4/translate.c b/target/sh4/translate.c index ab254b0e8d..ea88d46c04 100644 --- a/target/sh4/translate.c +++ b/target/sh4/translate.c @@ -2313,7 +2313,8 @@ static bool sh4_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cs, return true; } -static void sh4_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) +static void sh4_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs, + struct qemu_plugin_insn *plugin_insn) { CPUSH4State *env = cs->env_ptr; DisasContext *ctx = container_of(dcbase, DisasContext, base); diff --git a/target/sparc/translate.c b/target/sparc/translate.c index 74315cdf09..2fa8b68e0a 100644 --- a/target/sparc/translate.c +++ b/target/sparc/translate.c @@ -5894,7 +5894,8 @@ static bool sparc_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cs, return true; } -static void sparc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) +static void sparc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs, + struct qemu_plugin_insn *plugin_insn) { DisasContext *dc = container_of(dcbase, DisasContext, base); CPUSPARCState *env = cs->env_ptr; diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c index 46e1338448..14ab1c5ceb 100644 --- a/target/xtensa/translate.c +++ b/target/xtensa/translate.c @@ -1146,7 +1146,8 @@ static bool xtensa_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cpu, return true; } -static void xtensa_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) +static void xtensa_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu, + struct qemu_plugin_insn *plugin_insn) { DisasContext *dc = container_of(dcbase, DisasContext, base); CPUXtensaState *env = cpu->env_ptr; From patchwork Thu Oct 25 17:20:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656291 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 3E88C13A9 for ; Thu, 25 Oct 2018 17:49:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C7482C183 for ; Thu, 25 Oct 2018 17:49:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F7512C2A6; Thu, 25 Oct 2018 17:49: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BFA942C183 for ; Thu, 25 Oct 2018 17:49:24 +0000 (UTC) Received: from localhost ([::1]:56146 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjl5-0006pk-HJ for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:49:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKj-0006hw-1T for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKR-0000DX-Bk for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:56 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:46825) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKR-00005K-51 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:51 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 914E5221D7; Thu, 25 Oct 2018 13:21:12 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=RdKw0VYMLqJ4uQlFIKB1lEb75wqkafIN+uDRelpNa1Q=; b=LAp2F GOsZvsuqIy9JemvSnTPVy+DUHgcj6rYudgaEol/ZkwNilnURc2hfwVaIYW/QpG+4 j3WQ0V9+AvY71mOJAZqy8zqBsIztu8TWJhTyQbQvYdPjc755I4mG9xA0TbNxd/qg FTrvt/sY+O+osquYEFugav/PGswA0LCQKk3Lxk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=RdKw0VYMLqJ4uQlFIKB1lEb75wqka fIN+uDRelpNa1Q=; b=i7zLuLj9JLA8+JPul7638ZziOCGuoZZnfZ7m5ntcEPsPP yT/7VNTlpjaoB5pyw/7X/vOnvgYk1Z9oLt7+M/f7Bhw5QX79OIB6vZhwxniXVPz5 yRjYMWN1kTc3ReDju/YxK9niur9+YUg/qcZoMGb7HaDFw4W99t5OvNx4+PHm3gxq 1P+M6U9cCGQ2/Zhy1SGn0pZSaXfKBFHdqDEsd1zWWEIeWhiaAETRrMBd/Hg5glhr 9wRPhDs/dKWX+uXQhFpc7RkNTEFCaVv1HhVjtiGuTuPFmIridzbLE6+qjVQ3Ff5k lu8ESyMBepArbq8Bwiyxi5zS0ZYc7IHtKtlD40qqg== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 36DE4E4A44; Thu, 25 Oct 2018 13:21:12 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:33 -0400 Message-Id: <20181025172057.20414-25-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 24/48] translator: add .ctx_base_offset and .ctx_size to TranslatorOps X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- include/exec/translator.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/exec/translator.h b/include/exec/translator.h index a28147b3dd..e20ca9f854 100644 --- a/include/exec/translator.h +++ b/include/exec/translator.h @@ -106,6 +106,8 @@ typedef struct DisasContextBase { * * @disas_log: * Print instruction disassembly to log. + * @ctx_base_offset: offset of DisasContextBase within DisasContext. + * @ctx_size: size of DisasContext. */ typedef struct TranslatorOps { void (*init_disas_context)(DisasContextBase *db, CPUState *cpu); @@ -117,6 +119,8 @@ typedef struct TranslatorOps { struct qemu_plugin_insn *plugin_insn); void (*tb_stop)(DisasContextBase *db, CPUState *cpu); void (*disas_log)(const DisasContextBase *db, CPUState *cpu); + size_t ctx_base_offset; + size_t ctx_size; } TranslatorOps; /** From patchwork Thu Oct 25 17:20:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656285 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 5E3F913A9 for ; Thu, 25 Oct 2018 17:46:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DE252C27C for ; Thu, 25 Oct 2018 17:46:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 423022C298; Thu, 25 Oct 2018 17:46:08 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B66632C27C for ; Thu, 25 Oct 2018 17:46:07 +0000 (UTC) Received: from localhost ([::1]:56140 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjhv-0005cv-26 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:46:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKj-0006hv-7W for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKP-0000CE-NU for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:50 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:37021) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKP-00005r-Gv for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:49 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 10C94221D2; Thu, 25 Oct 2018 13:21:13 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=watJ1az68IcwbN8Dd3xba8M1ow7onC1SkxnvCoRBDNQ=; b=ZJmBJ AWhcxlra7PwkDODMnOItxPOqn2K5ob3/C6XWvBAXxrltsHyN/eeAT4QUYVCKLMBJ ph98rFMLJraKRxo6jUf+ZnI5qvF1YtHcKr62IyHKVgP1ZFNZRxGNqCYyG0PgerY9 yLUgTCnXilkUNbrPDikqnWSVzl8kZoK+yr8mw8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=watJ1az68IcwbN8Dd3xba8M1ow7on C1SkxnvCoRBDNQ=; b=jTeny/uoMBs3UleOkqpH4PQa5bsZF7RczjEdljpopxzah ZymobSTNymE5asPmJJpMkXMBGyFgux4VgbWXtWCJkdCcn3/tmzWKTei/yp6T9kKw j+unoe9laKZ34fQSUI2F9+/AE+vXYYh1L7POtmuSNw7dQpBJArtRUAQXsnO10dIr b3ov/K91/01+UwOfxJVk0SAmFMH/cqxtB8Y01QMvUFdblPAEPY8vnjCCRp5WurC5 NksLWCTlhmImQP+CbC3TmaObpGDti3h4C3Q/sOuxDURkD3+krgZ1SOzcimURnEay 38rOAYQnfilLGXTvPTMyxZprkoy/L212Lda8mtzxg== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 77CFBE4074; Thu, 25 Oct 2018 13:21:12 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:34 -0400 Message-Id: <20181025172057.20414-26-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 25/48] target/arm: prepare for 2-pass translation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- target/arm/translate-a64.c | 8 ++++++-- target/arm/translate.c | 25 +++++++++++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 8b1e20dd59..dab5f6efd3 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -13783,11 +13783,13 @@ static void disas_data_proc_simd_fp(DisasContext *s, uint32_t insn) } /* C3.1 A64 instruction index by encoding */ -static void disas_a64_insn(CPUARMState *env, DisasContext *s) +static void disas_a64_insn(CPUARMState *env, DisasContext *s, + struct qemu_plugin_insn *plugin_insn) { uint32_t insn; insn = arm_ldl_code(env, s->pc, s->sctlr_b); + qemu_plugin_insn_append(plugin_insn, &insn, sizeof(insn)); s->insn = insn; s->pc += 4; @@ -13959,7 +13961,7 @@ static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu, default_exception_el(dc)); dc->base.is_jmp = DISAS_NORETURN; } else { - disas_a64_insn(env, dc); + disas_a64_insn(env, dc, plugin_insn); } dc->base.pc_next = dc->pc; @@ -14058,4 +14060,6 @@ const TranslatorOps aarch64_translator_ops = { .translate_insn = aarch64_tr_translate_insn, .tb_stop = aarch64_tr_tb_stop, .disas_log = aarch64_tr_disas_log, + .ctx_base_offset = offsetof(DisasContext, base), + .ctx_size = sizeof(DisasContext), }; diff --git a/target/arm/translate.c b/target/arm/translate.c index 2fd32a2684..015153a260 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -10198,7 +10198,8 @@ gen_thumb2_data_op(DisasContext *s, int op, int conds, uint32_t shifter_out, } /* Translate a 32-bit thumb instruction. */ -static void disas_thumb2_insn(DisasContext *s, uint32_t insn) +static void disas_thumb2_insn(DisasContext *s, uint32_t insn, + struct qemu_plugin_insn *plugin_insn) { uint32_t imm, shift, offset; uint32_t rd, rn, rm, rs; @@ -11736,7 +11737,8 @@ illegal_op: default_exception_el(s)); } -static void disas_thumb_insn(DisasContext *s, uint32_t insn) +static void disas_thumb_insn(DisasContext *s, uint32_t insn, + struct qemu_plugin_insn *plugin_insn) { uint32_t val, op, rm, rn, rd, shift, cond; int32_t offset; @@ -12800,6 +12802,7 @@ static void arm_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu, insn = arm_ldl_code(env, dc->pc, dc->sctlr_b); dc->insn = insn; + qemu_plugin_insn_append(plugin_insn, &insn, sizeof(insn)); dc->pc += 4; disas_arm_insn(dc, insn); @@ -12870,11 +12873,21 @@ static void thumb_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu, insn = arm_lduw_code(env, dc->pc, dc->sctlr_b); is_16bit = thumb_insn_is_16bit(dc, insn); dc->pc += 2; + if (plugin_insn) { + uint16_t insn16 = insn; + + qemu_plugin_insn_append(plugin_insn, &insn16, sizeof(insn16)); + } if (!is_16bit) { uint32_t insn2 = arm_lduw_code(env, dc->pc, dc->sctlr_b); insn = insn << 16 | insn2; dc->pc += 2; + if (plugin_insn) { + uint16_t insn16 = insn2; + + qemu_plugin_insn_append(plugin_insn, &insn16, sizeof(insn16)); + } } dc->insn = insn; @@ -12887,9 +12900,9 @@ static void thumb_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu, } if (is_16bit) { - disas_thumb_insn(dc, insn); + disas_thumb_insn(dc, insn, plugin_insn); } else { - disas_thumb2_insn(dc, insn); + disas_thumb2_insn(dc, insn, plugin_insn); } /* Advance the Thumb condexec condition. */ @@ -13064,6 +13077,8 @@ static const TranslatorOps arm_translator_ops = { .translate_insn = arm_tr_translate_insn, .tb_stop = arm_tr_tb_stop, .disas_log = arm_tr_disas_log, + .ctx_base_offset = offsetof(DisasContext, base), + .ctx_size = sizeof(DisasContext), }; static const TranslatorOps thumb_translator_ops = { @@ -13074,6 +13089,8 @@ static const TranslatorOps thumb_translator_ops = { .translate_insn = thumb_tr_translate_insn, .tb_stop = arm_tr_tb_stop, .disas_log = arm_tr_disas_log, + .ctx_base_offset = offsetof(DisasContext, base), + .ctx_size = sizeof(DisasContext), }; /* generate intermediate code for basic block 'tb'. */ From patchwork Thu Oct 25 17:20:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656253 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 A07D2109C for ; Thu, 25 Oct 2018 17:33:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8EB2528415 for ; Thu, 25 Oct 2018 17:33:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81FA32844B; Thu, 25 Oct 2018 17:33:39 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2E65928415 for ; Thu, 25 Oct 2018 17:33:39 +0000 (UTC) Received: from localhost ([::1]:56075 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjVq-0001DA-Bx for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:33:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40350) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKj-0006hs-0S for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKU-0000GD-BL for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:56 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:44461) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKT-00005s-PJ for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:53 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 2DCAB221F2; Thu, 25 Oct 2018 13:21:13 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=IQVGck2mgk51UqLFEMtL0FTWXlJPPCViUNdCANE89qM=; b=rRhbJ slmSJrWeeRYJgpu0OK+2TuiyazwBwdWfGbnNvTve8Ew5v6qwsa96O+APU3ZIkJJ6 MBQ9Mt0/i3rPRAgpuJHP4kDA8Wqces89IZInqfv70tj+8lCfaKYG9URldpenqajK 4pUzoeqeElwaUItc/wI8QCIrjTV0wrcG6yuN0k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=IQVGck2mgk51UqLFEMtL0FTWXlJPP CViUNdCANE89qM=; b=GLi5uiqGxpVV71GvD6JE57e7ONgkRzqKpUe92kvIzlQa0 /+EKUPUHYcaINVgcV8evP6v1QvO5HwwS8FOlz3Xm4dqgxkLRbQea9uWr+4yF4rFk Re6bt7ZjiXKVH7aDUsWJzVRROG8SxRgpzWixsrGJA7Qs+H4Th5l7209HfzL10UaB OlI1eL95zxcL2qZEv8UpFYOLiqB/+IYwUqtTP25YH4Rsw8zqU/gXh6OWQkhMx/TH 3YxlANHB80S10qkCRFbx9/A5/R7JnbGLVnVwXOzqnL9jHrV08/BClrpRpIU1CN2b xhZrFf5r1U71wNoSDK7I6wEuyBztFXh61vNruJjFA== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id B5FDDE455F; Thu, 25 Oct 2018 13:21:12 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:35 -0400 Message-Id: <20181025172057.20414-27-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 26/48] target/ppc: prepare for 2-pass translation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- target/ppc/translate.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 34c3ed0a41..88f88adaff 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -7565,6 +7565,9 @@ static void ppc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs, ctx->opcode, opc1(ctx->opcode), opc2(ctx->opcode), opc3(ctx->opcode), opc4(ctx->opcode), ctx->le_mode ? "little" : "big"); + + qemu_plugin_insn_append(plugin_insn, &ctx->opcode, sizeof(ctx->opcode)); + ctx->base.pc_next += 4; table = env->opcodes; handler = table[opc1(ctx->opcode)]; @@ -7664,6 +7667,8 @@ static const TranslatorOps ppc_tr_ops = { .translate_insn = ppc_tr_translate_insn, .tb_stop = ppc_tr_tb_stop, .disas_log = ppc_tr_disas_log, + .ctx_base_offset = offsetof(DisasContext, base), + .ctx_size = sizeof(DisasContext), }; void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) From patchwork Thu Oct 25 17:20:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656239 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 3176A109C for ; Thu, 25 Oct 2018 17:27:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BDFF2C1AD for ; Thu, 25 Oct 2018 17:27:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F9892C1DE; Thu, 25 Oct 2018 17:27: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AA83D2C1DB for ; Thu, 25 Oct 2018 17:27:15 +0000 (UTC) Received: from localhost ([::1]:56044 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjPe-0003Ho-Th for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:27:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40316) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKi-0006ho-Vn for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKX-0000IN-Ie for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:59 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:37637) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKU-00007U-7C for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:54 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 5B828221EA; Thu, 25 Oct 2018 13:21:13 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=+5M00HdujBuSkMjR0HFh7RlV448o6SDN7DfXoWBp1kI=; b=K/Cyq 5RNs9Z7czer2gYGZPIclg6V1hUHVZgBwIY8LuihKUkNaQjTlSiCczzEtc3GuUya2 Jc+KKnj3e8WddaIi9O00Mkc9C0SlyXt+GEmdYubEe51HRDpkuhFfqiViaK62zTqq /Gmj0babg4OU0WhdNWKJOSP+7k6bK27wAriJNc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=+5M00HdujBuSkMjR0HFh7RlV448o6 SDN7DfXoWBp1kI=; b=Mjh4CEcEOaVGVAGGcqSHoBKWOIY6gxOLTetcBGH0Pxwr9 IoXzzwBZtEBe1VDDK2GLzi72WfFZwMvcZw+ykH0gsL9SLBKnYk3i/wgURTo6cH4O cmeIbHxciupQH2NXgUX/XhweGAtxa/PVs6rv/nV5NpP9HKJXVqcN83mMiD3UfYLz sEm6p77b0cunYAxt4taXZ5Qw3QqHSYwpLUd8wrsvToyYobDo3x1I6vcEpBECwoyu 8Lfwx5GmVLFPf3t1Wwl2xH5z+RvGYg+0yEexEgFeqv19slGDbFQHQSjuc+QcxOWb pR0kbfzBpHuu++uzJPAMAmC657+DYDOBVq/Z68Geg== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id EE9F8E47CB; Thu, 25 Oct 2018 13:21:12 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:36 -0400 Message-Id: <20181025172057.20414-28-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 27/48] target/sh4: prepare for 2-pass translation (WIP) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP XXX: cleanly get the gUSA instructions Signed-off-by: Emilio G. Cota --- target/sh4/translate.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/sh4/translate.c b/target/sh4/translate.c index ea88d46c04..a3b0fb46a2 100644 --- a/target/sh4/translate.c +++ b/target/sh4/translate.c @@ -2333,6 +2333,7 @@ static void sh4_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs, #endif ctx->opcode = cpu_lduw_code(env, ctx->base.pc_next); + qemu_plugin_insn_append(plugin_insn, &ctx->opcode, sizeof(ctx->opcode)); decode_opc(ctx); ctx->base.pc_next += 2; } @@ -2381,6 +2382,8 @@ static const TranslatorOps sh4_tr_ops = { .translate_insn = sh4_tr_translate_insn, .tb_stop = sh4_tr_tb_stop, .disas_log = sh4_tr_disas_log, + .ctx_base_offset = offsetof(DisasContext, base), + .ctx_size = sizeof(DisasContext), }; void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) From patchwork Thu Oct 25 17:20:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656247 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 ECEBC17F3 for ; Thu, 25 Oct 2018 17:30:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7F962C231 for ; Thu, 25 Oct 2018 17:30:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC4432C258; Thu, 25 Oct 2018 17:30:13 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 507BF2C258 for ; Thu, 25 Oct 2018 17:30:13 +0000 (UTC) Received: from localhost ([::1]:56061 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjSW-0005xi-HB for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:30:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40310) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKj-0006hm-30 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKT-0000Fe-TS for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:56 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:45535) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKT-00007T-2J for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:53 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id A8857221ED; Thu, 25 Oct 2018 13:21:13 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=4rd+fb8gH/E7yXP4HxMspq5xyVDrxyl1J+SrWGglYhU=; b=TPAMj lmmwPJkUW2z7Jk9KkM8KP6ySMORQHk57pB7TKa1iKnQcfH8G9PQeiIRPmnwealWc ElaNVmSihLtHFv56cPzyhpZSc3NNssLdimsm3KmOkCaO19u+bQEvGMqj2bo5Sa6U s50rKfZ5UPC/PeETi8d4Rrn2vrYYWAsjNN1NiI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=4rd+fb8gH/E7yXP4HxMspq5xyVDrx yl1J+SrWGglYhU=; b=DDVQ75YVdxDRV3ROy+6Q4YVRpn6gOQgN1aeJbN9eQXW/I NHPKo5YVBep+Z9zv4WLVs0HkSTgHd/PpSPQs01d2X2LhPp32gyos3bWnshHMVj44 Fs0X/XmXzPSL8AY1c1IPKTH3iVDy09PXWnWYbgiGIuqkLPnCD39K5U4ZLYBVsHbw cWuK4uMquDGaEsq8T72M4lzQmo+mvdPNNanaCQUqkVYCtF43HMzjgdJpfuFq012Z jxCDfdLdP/w6WBnRa9ddAoo6NrRAt3PEQtFYDFuRXrK413uF66cYha6vP1RKAhnj KpMp6hx9r+jRZDkSF4YqYXbKxCJtNSWQhAY0KuU0A== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 37BC0E4897; Thu, 25 Oct 2018 13:21:13 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:37 -0400 Message-Id: <20181025172057.20414-29-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 28/48] target/i386: prepare for 2-pass translation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- target/i386/translate.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/target/i386/translate.c b/target/i386/translate.c index 86e59d7bf7..1d7b20bce3 100644 --- a/target/i386/translate.c +++ b/target/i386/translate.c @@ -142,6 +142,7 @@ typedef struct DisasContext { TCGv_i32 tmp3_i32; TCGv_i64 tmp1_i64; + struct qemu_plugin_insn *plugin_insn; sigjmp_buf jmpbuf; } DisasContext; @@ -1900,28 +1901,43 @@ 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)); + uint8_t ret = cpu_ldub_code(env, advance_pc(env, s, 1)); + + qemu_plugin_insn_append(s->plugin_insn, &ret, sizeof(ret)); + return ret; } static inline int16_t x86_ldsw_code(CPUX86State *env, DisasContext *s) { - return cpu_ldsw_code(env, advance_pc(env, s, 2)); + int16_t ret = cpu_ldsw_code(env, advance_pc(env, s, 2)); + + qemu_plugin_insn_append(s->plugin_insn, &ret, sizeof(ret)); + return ret; } static inline uint16_t x86_lduw_code(CPUX86State *env, DisasContext *s) { - return cpu_lduw_code(env, advance_pc(env, s, 2)); + uint16_t ret = cpu_lduw_code(env, advance_pc(env, s, 2)); + + qemu_plugin_insn_append(s->plugin_insn, &ret, sizeof(ret)); + return ret; } static inline uint32_t x86_ldl_code(CPUX86State *env, DisasContext *s) { - return cpu_ldl_code(env, advance_pc(env, s, 4)); + uint32_t ret = cpu_ldl_code(env, advance_pc(env, s, 4)); + + qemu_plugin_insn_append(s->plugin_insn, &ret, sizeof(ret)); + return ret; } #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)); + uint64_t ret = cpu_ldq_code(env, advance_pc(env, s, 8)); + + qemu_plugin_insn_append(s->plugin_insn, &ret, sizeof(ret)); + return ret; } #endif @@ -4473,7 +4489,8 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b, /* convert one instruction. s->base.is_jmp is set if the translation must be stopped. Return the next pc value */ -static target_ulong disas_insn(DisasContext *s, CPUState *cpu) +static target_ulong disas_insn(DisasContext *s, CPUState *cpu, + struct qemu_plugin_insn *plugin_insn) { CPUX86State *env = cpu->env_ptr; int b, prefixes; @@ -4484,6 +4501,8 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) int rex_w, rex_r; target_ulong pc_start = s->base.pc_next; + s->plugin_insn = plugin_insn; + s->pc_start = s->pc = pc_start; s->override = -1; #ifdef TARGET_X86_64 @@ -8529,7 +8548,7 @@ static void i386_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu, struct qemu_plugin_insn *plugin_insn) { DisasContext *dc = container_of(dcbase, DisasContext, base); - target_ulong pc_next = disas_insn(dc, cpu); + target_ulong pc_next = disas_insn(dc, cpu, plugin_insn); if (dc->tf || (dc->base.tb->flags & HF_INHIBIT_IRQ_MASK)) { /* if single step mode, we generate only one instruction and @@ -8584,6 +8603,8 @@ static const TranslatorOps i386_tr_ops = { .translate_insn = i386_tr_translate_insn, .tb_stop = i386_tr_tb_stop, .disas_log = i386_tr_disas_log, + .ctx_base_offset = offsetof(DisasContext, base), + .ctx_size = sizeof(DisasContext), }; /* generate intermediate code for basic block 'tb'. */ From patchwork Thu Oct 25 17:20:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656237 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 0428313A9 for ; Thu, 25 Oct 2018 17:27:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA85E2C1DE for ; Thu, 25 Oct 2018 17:27:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD0082C1AD; Thu, 25 Oct 2018 17:27: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6D0C42C1AD for ; Thu, 25 Oct 2018 17:27:15 +0000 (UTC) Received: from localhost ([::1]:56045 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjPe-0003II-Lq for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:27:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40316) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKg-0006ho-2n for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKc-0000Mt-KR for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:04 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:36879) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKb-000085-SL for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:02 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id C6442221F4; Thu, 25 Oct 2018 13:21:13 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=RmFi/0AGG399b47l7MBRD+r2dl326fV1b5eRzpDR25Y=; b=c/EZu Idcie2glnokWJf2wTD27ohJqo4xhbAyA6VWfeE8MkbvCpQzBQ5lxvyMVgHLAeiwc ymnTZ8e+aWmeFazvU59BmnQ0WPc8PT7hZh63vY97HB22o6AGALCDT1tOPesZ25YD D+p5wvldnXraw/jWfLvIgWAE+6C2TfbFhsZlSw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=RmFi/0AGG399b47l7MBRD+r2dl326 fV1b5eRzpDR25Y=; b=yecxr2p1wF1zcbUHsssBChDjLjbOppqws6HliABjDVPv0 zd9G82fLMUWSPc7dbQQpCwpYzB91zvdLyUf5QrPeehuO3yOYnTW2etHfN0SSzBsG lamid8mkrv1NDtE0OXLyyU4/Q900ctbdje/jmtVsG9AbFBwDnUanfY+97Klf1qV1 bhMrPKRgM9rKJDkvm4gMqIaE8vQ1fO2qSN9/+TyN+FP6ZNQNBISro/BtlB/yyGHa qIBM5E+bd2jotKJ9h5spOZNYcwu+t2HMY/yEsP3FzX2ZUU8vNYfu1rf9E8f4cvPc JzS4AV7Ik55q6ZSJ1tUhVhvIesak3wtL+Q2WmpZxg== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 76F71E455F; Thu, 25 Oct 2018 13:21:13 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:38 -0400 Message-Id: <20181025172057.20414-30-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 29/48] target/hppa: prepare for 2-pass translation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- target/hppa/translate.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/hppa/translate.c b/target/hppa/translate.c index 6c2a7fbc46..08ebbeb21c 100644 --- a/target/hppa/translate.c +++ b/target/hppa/translate.c @@ -4757,6 +4757,8 @@ static void hppa_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs, the page permissions for execute. */ uint32_t insn = cpu_ldl_code(env, ctx->base.pc_next); + qemu_plugin_insn_append(plugin_insn, &insn, sizeof(insn)); + /* Set up the IA queue for the next insn. This will be overwritten by a branch. */ if (ctx->iaoq_b == -1) { @@ -4887,6 +4889,8 @@ static const TranslatorOps hppa_tr_ops = { .translate_insn = hppa_tr_translate_insn, .tb_stop = hppa_tr_tb_stop, .disas_log = hppa_tr_disas_log, + .ctx_base_offset = offsetof(DisasContext, base), + .ctx_size = sizeof(DisasContext), }; void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) From patchwork Thu Oct 25 17:20:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656243 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 609A8109C for ; Thu, 25 Oct 2018 17:30:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CA6B2C255 for ; Thu, 25 Oct 2018 17:30:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4096A2C22E; Thu, 25 Oct 2018 17:30:13 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DBB9D2C252 for ; Thu, 25 Oct 2018 17:30:12 +0000 (UTC) Received: from localhost ([::1]:56058 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjSW-0005vK-4J for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:30:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKh-0006hw-Fo for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKf-0000O0-GP for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:07 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:44519) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKc-000084-5W for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:02 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 1E5602218B; Thu, 25 Oct 2018 13:21:14 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=PWAsb1dRzEnBWr5qEJ0wJ7TRXVgWBoFL4+CAWKH6/Pk=; b=OpVVF 8N2ALQImtj8bRNLEYvSUIW5BeeW51vVXqQjDnnc7pYluIeWtO9bQH0b4JI7ydlLN hJen6fUM8lgdFzD0hPQKZbt62bI6ht+V55TyQBOigTsZG10VNsZsOMZ5TrHlH5Po PYoHJAVWMF5PvXmrf9iWD6aA+WWDr7eJqwhoQk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=PWAsb1dRzEnBWr5qEJ0wJ7TRXVgWB oFL4+CAWKH6/Pk=; b=fJ8MiZmFs60Ji9/Fh5LjCRHbny3Bu8xXE9xc6ZqLjYjSn YQlOz4RyscaOg/YuKqydxeXxEvEbeLLfJjsaj5ax5eF63eqUX4EmawWsDZe2KR4d almx2AsSivAg5mAcnjwBTWOkPmdN9uAaUgfS6dXpucrcB/5QtRlRHQVdwjOLPnIC T6lcFRVk8wIU/MZjCLN7TD7Lom7c9uwLwO3aGoEQj3I6Y2Upg8vOObyZ0OqVD9fu RtJZHZJjgmXPX/rYyj2MmB8blJQqrPcSLebTiUsGY2oyCvF0rt+WW1F2Ex0HIBtB QkluywEwoTHzMR/gSYI5GA89ESjSI/NMbgU+h1HRw== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id A7232E47CB; Thu, 25 Oct 2018 13:21:13 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:39 -0400 Message-Id: <20181025172057.20414-31-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 30/48] target/m68k: prepare for 2-pass translation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- target/m68k/translate.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/target/m68k/translate.c b/target/m68k/translate.c index dd7d868b25..9b5a4b1eb5 100644 --- a/target/m68k/translate.c +++ b/target/m68k/translate.c @@ -116,6 +116,7 @@ typedef struct DisasContext { int done_mac; int writeback_mask; TCGv writeback[8]; + struct qemu_plugin_insn *plugin_insn; #define MAX_TO_RELEASE 8 int release_count; TCGv release[MAX_TO_RELEASE]; @@ -375,6 +376,7 @@ static inline uint16_t read_im16(CPUM68KState *env, DisasContext *s) uint16_t im; im = cpu_lduw_code(env, s->pc); s->pc += 2; + qemu_plugin_insn_append(s->plugin_insn, &im, sizeof(im)); return im; } @@ -6092,7 +6094,10 @@ static void m68k_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu, { DisasContext *dc = container_of(dcbase, DisasContext, base); CPUM68KState *env = cpu->env_ptr; - uint16_t insn = read_im16(env, dc); + uint16_t insn; + + dc->plugin_insn = plugin_insn; + insn = read_im16(env, dc); opcode_table[insn](env, dc, insn); do_writebacks(dc); @@ -6167,6 +6172,8 @@ static const TranslatorOps m68k_tr_ops = { .translate_insn = m68k_tr_translate_insn, .tb_stop = m68k_tr_tb_stop, .disas_log = m68k_tr_disas_log, + .ctx_base_offset = offsetof(DisasContext, base), + .ctx_size = sizeof(DisasContext), }; void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb) From patchwork Thu Oct 25 17:20:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656229 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 9808F14BB for ; Thu, 25 Oct 2018 17:23:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81AD82C19F for ; Thu, 25 Oct 2018 17:23:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 753722C1DB; Thu, 25 Oct 2018 17:23: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2510E2C1A6 for ; Thu, 25 Oct 2018 17:23:55 +0000 (UTC) Received: from localhost ([::1]:56026 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjMQ-0000pC-Ct for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:23:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40415) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKi-0006hx-Ky for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKh-0000Px-RH for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:08 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:38687) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKh-00009E-J5 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:07 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 4523B221F7; Thu, 25 Oct 2018 13:21:14 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=dwARwK3H2gk2Qe4bseiIpFGmSo6ceThCPoGLgVdRnAw=; b=I4Qx6 JHm5R5Y++2D/n67P9cHq0ymqrvHB1hpISuWpWfLkBePvmRd6TPmcvHND54SMyYua PV0FJsn7oYOQjuKZQmELQm/4GBv0t3i7cDbE1ClZBytCIkeW1NlKB+nVjJ/GF7R+ addZmGm8Dzx4aMF4ASGFf4TaS/EDCnqL/kAvlY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=dwARwK3H2gk2Qe4bseiIpFGmSo6ce ThCPoGLgVdRnAw=; b=GhNqKGTBuoOXlpC7pIr8JxsKqWc6zkUx3SysCii2vsqn9 VMNDNx814LI6R1EDH/PGBLBhwcFHfvMlgSWC2hAPQKDz71Ee1haNrZBD2uBIhpuS /4zhca/kYlBWhu0BM/5ho0RYB5BpVLyqHBqhE+59fXVVRU4eGc/l8rM/6WL4/XB2 Zsrsov2UlkTTYm8f3YpIVwVOxbHvJEFbfmwVStx3UupHa6S1tzFVY9KvUk1FQvPm 1BI35jMKB0YufQsthnRu7hpledET3MB6R01JuhEM6fH0+H9VBd27c0s9TjrzETod wO5RugscrcJVsb6sjMo2l6aRF0LQ8j/zb3MlCUWMw== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id DD661E455F; Thu, 25 Oct 2018 13:21:13 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:40 -0400 Message-Id: <20181025172057.20414-32-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 31/48] target/mips: prepare for 2-pass translation (WIP) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP XXX: fill in plugin_insn Signed-off-by: Emilio G. Cota --- target/mips/translate.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/target/mips/translate.c b/target/mips/translate.c index efafc6e795..46ed40cf8f 100644 --- a/target/mips/translate.c +++ b/target/mips/translate.c @@ -25455,6 +25455,8 @@ static const TranslatorOps mips_tr_ops = { .translate_insn = mips_tr_translate_insn, .tb_stop = mips_tr_tb_stop, .disas_log = mips_tr_disas_log, + .ctx_base_offset = offsetof(DisasContext, base), + .ctx_size = sizeof(DisasContext), }; void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) From patchwork Thu Oct 25 17:20:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656251 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 92CB813BF for ; Thu, 25 Oct 2018 17:33:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 807A7283D1 for ; Thu, 25 Oct 2018 17:33:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 74C4C2842D; Thu, 25 Oct 2018 17:33: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 29C25283D1 for ; Thu, 25 Oct 2018 17:33:33 +0000 (UTC) Received: from localhost ([::1]:56074 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjVk-00014m-F0 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:33:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40308) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKg-0006hk-1q for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKb-0000M7-Pl for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:03 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:57139) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKa-00008h-Gh for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:01 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 6F4962221B; Thu, 25 Oct 2018 13:21:14 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=iV5MmvAiJOQkbMJAsRroULDFZEbx7XE8kXmiYV+YBeo=; b=Ff29L s97HwQrW1DJNEqfkc1kuT6kL3OkUymvP5Fk1tnIkc3EEQjGgAy0TwqacXYTKjZQr 79Jaaph8oLvavIJWa3jBFdhgpD7l9tqn4AQM0JnacNQsiux744t0Gn+nJkMH66K3 7xU56ophymqf7KzJi13ZcRB3AaAtC1llM9KhFw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=iV5MmvAiJOQkbMJAsRroULDFZEbx7 XE8kXmiYV+YBeo=; b=cotNPMsw6+hD/3k7oTAY0MMQ77P2wpT66ILpvj3FyYL9C +Enr57hRvDQO9yTvM+Hqs8UQ1KHzQpPn0aPIThkqa/SsNBokxZW361O2v76GG4ZV g8xj54S47yR0oRZL3mGXQHHQGVS++8cimWxKddSMwaVZT7ut5W8pXs9EO5nEK4Ta s6Vv0UVXuc3UIbVWxkTgM8HKVwcERLiYkWmtunmndMm7oZR1Hb+vhSAFsXg6O/PK JENGLbVgGqLAFRYUwP5A2dduG2oozX2ZsxQpGHEM/ijmFg5UfAtq2BzkHtQa9yHX xBe6uKl1ASCzvSBS+1jOxZVh0CRSfgYyQE8po5gXA== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 17187E4074; Thu, 25 Oct 2018 13:21:14 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:41 -0400 Message-Id: <20181025172057.20414-33-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 32/48] target/alpha: prepare for 2-pass translation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- target/alpha/translate.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/alpha/translate.c b/target/alpha/translate.c index 72a302e102..21405df2b8 100644 --- a/target/alpha/translate.c +++ b/target/alpha/translate.c @@ -2990,6 +2990,7 @@ static void alpha_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu, CPUAlphaState *env = cpu->env_ptr; uint32_t insn = cpu_ldl_code(env, ctx->base.pc_next); + qemu_plugin_insn_append(plugin_insn, &insn, sizeof(insn)); ctx->base.pc_next += 4; ctx->base.is_jmp = translate_one(ctx, insn); @@ -3046,6 +3047,8 @@ static const TranslatorOps alpha_tr_ops = { .translate_insn = alpha_tr_translate_insn, .tb_stop = alpha_tr_tb_stop, .disas_log = alpha_tr_disas_log, + .ctx_base_offset = offsetof(DisasContext, base), + .ctx_size = sizeof(DisasContext), }; void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb) From patchwork Thu Oct 25 17:20:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656267 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 C9D5517F3 for ; Thu, 25 Oct 2018 17:40:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA4642C28D for ; Thu, 25 Oct 2018 17:40:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AED8E2C29D; Thu, 25 Oct 2018 17:40: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 632032C28D for ; Thu, 25 Oct 2018 17:40:11 +0000 (UTC) Received: from localhost ([::1]:56107 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjcA-0007zR-My for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:40:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40232) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKi-0006h0-SW for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKX-0000Ih-Td for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:59 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:39503) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKU-00008b-AW for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:56 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id C7BC0221F0; Thu, 25 Oct 2018 13:21:14 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=Glw9hWjrgcyz5ShDqD0rAzNcCeB3f35Bwo88MCFIC7g=; b=qv6ML WBQL2AQuWUkZOFx5HuUDBWkL0QhAdvRPIPuX57J5ax4Hjkyc7OGBBclYdFmBKQDF e/KVeIrtuYQM42hegUOpsRHdKD5XHR66rZR1az9zj/AoQrhiEsbqlSlnCzoQ9n4u AOJUe5E+rElQ/AAE80BuTme3hkvxNBxdg7LHgI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=Glw9hWjrgcyz5ShDqD0rAzNcCeB3f 35Bwo88MCFIC7g=; b=uiTaInV7sZ+koguM5Zd3nl1YmpTgWP+FKx7GQdLz4c4uw bQKyWUfVhQH1odFThBjZat0ynQlbjy0TPGLuixAPUdmpJBd7puGu3PwdYA3A2TC8 0uaRXOEjbpFjfc+Rfj9+jXehrqAA1rbl52TDJOv3JVH4ngXt12YT5t5q7PCqqD2n InLYp2M3Cc+KgvG3wU0hbcjUCtd/RVHAv4O3SJbV8nLaowE+jPktsKd8ofQhYdLi c3vHrdI7Nx+L3pVb8hd4v+Q2N5cJfkneQRsRvVlwnlZqhkhbptnmtJY1EGKyNPRK 5DKoOyn3x7x6iMC4URudjUy+2tX1pU7kX6Aca+tig== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 51831E47CB; Thu, 25 Oct 2018 13:21:14 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:42 -0400 Message-Id: <20181025172057.20414-34-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 33/48] target/riscv: prepare for 2-pass translation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- target/riscv/translate.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index a33cf6802b..6f5be8e7d7 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -1851,6 +1851,7 @@ static void riscv_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu, ctx->opcode = cpu_ldl_code(env, ctx->base.pc_next); decode_opc(env, ctx); + qemu_plugin_insn_append(plugin_insn, &ctx->opcode, sizeof(ctx->opcode)); ctx->base.pc_next = ctx->pc_succ_insn; if (ctx->base.is_jmp == DISAS_NEXT) { @@ -1892,6 +1893,8 @@ static const TranslatorOps riscv_tr_ops = { .translate_insn = riscv_tr_translate_insn, .tb_stop = riscv_tr_tb_stop, .disas_log = riscv_tr_disas_log, + .ctx_base_offset = offsetof(DisasContext, base), + .ctx_size = sizeof(DisasContext), }; void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) From patchwork Thu Oct 25 17:20:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656235 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 AB51113A9 for ; Thu, 25 Oct 2018 17:27:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95AA32C1AD for ; Thu, 25 Oct 2018 17:27:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 899422C1DE; Thu, 25 Oct 2018 17:27: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 083042C1AD for ; Thu, 25 Oct 2018 17:27:13 +0000 (UTC) Received: from localhost ([::1]:56043 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjPd-0003HN-70 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:27:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40232) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKf-0006h0-DT for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKX-0000J8-Vp for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:59 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:33567) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKW-00009D-0x for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:57 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 8414D221CB; Thu, 25 Oct 2018 13:21:15 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=e/BHzRnE2mUdr294JMe4l4Xhe8lifavFXwcoTix71pM=; b=w5qD3 dZIKadLbHMo9eFJvVWvWzD4du2YYrpt2xMao9aYeY6BKLtCXPo7ocpj/Tn3NiPne 2IPBBw1snXo3Euc6Ud04TTfEAoRWLlzv5NfT3I3bdQv8jLyDAuKUV/4SGF87n+am SCLxeXhzbVypaNmks12cQdl9oIGYzRgA/VzVeM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=e/BHzRnE2mUdr294JMe4l4Xhe8lif avFXwcoTix71pM=; b=WQ6ZztSSA7ieUk0NA4yxoWY7JCci5qgY5ZxAJIG4jJNcg VRimEkrZgDKh2WhFUe12f9JOY5jyzYfqxCusfEtXr8QBqrOKiEolxMeUBS8MHHru wrq9452rIs/pKE+zwrJqZdsPqEk/k3bNnWGmNd0fCVr7aW60K0aVM7bDmdnQLRQt FxT818LdcYl4sPBVRTgYNAquc83FjHGOYoFlnSeDIWE6s9cz7NVXEqD8V18fbyLR ajn7b9nODoIzyM0qCluwCUyGiVyz+xuEqaQpafmX/3Uy/LrT39yiCcxSk/3RFSvA W2BAF2/tPuA0dk7W1/Wnw7BgtNmJYY2zqC5yVm40w== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 8EF0BE4897; Thu, 25 Oct 2018 13:21:14 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:43 -0400 Message-Id: <20181025172057.20414-35-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 34/48] target/s390x: prepare for 2-pass translation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- target/s390x/translate.c | 49 ++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/target/s390x/translate.c b/target/s390x/translate.c index 6ac1a8d821..0c41e0d83a 100644 --- a/target/s390x/translate.c +++ b/target/s390x/translate.c @@ -5934,13 +5934,39 @@ static void extract_field(DisasFields *o, const DisasField *f, uint64_t insn) o->c[f->indexC] = r; } +static inline void +s390_plugin_insn(uint64_t insn, struct qemu_plugin_insn *plugin_insn, int len) +{ + uint16_t insn2; + uint32_t insn4; + + if (plugin_insn == NULL) { + return; + } + + switch (len) { + case 2: + insn2 = insn; + qemu_plugin_insn_append(plugin_insn, &insn2, sizeof(insn2)); + break; + case 4: + insn4 = insn; + qemu_plugin_insn_append(plugin_insn, &insn4, sizeof(insn4)); + break; + default: + g_assert_not_reached(); + } +} + /* Lookup the insn at the current PC, extracting the operands into O and returning the info struct for the insn. Returns NULL for invalid insn. */ static const DisasInsn *extract_insn(CPUS390XState *env, DisasContext *s, - DisasFields *f) + DisasFields *f, + struct qemu_plugin_insn *plugin_insn) { uint64_t insn, pc = s->base.pc_next; + uint64_t insn4; int op, op2, ilen; const DisasInsn *info; @@ -5960,13 +5986,19 @@ static const DisasInsn *extract_insn(CPUS390XState *env, DisasContext *s, ilen = get_ilen(op); switch (ilen) { case 2: - insn = insn << 48; + s390_plugin_insn(insn, plugin_insn, 2); + insn <<= 48; break; case 4: - insn = ld_code4(env, pc) << 32; + insn = ld_code4(env, pc); + s390_plugin_insn(insn, plugin_insn, 4); + insn <<= 32; break; case 6: - insn = (insn << 48) | (ld_code4(env, pc + 2) << 16); + s390_plugin_insn(insn, plugin_insn, 2); + insn4 = ld_code4(env, pc + 2); + s390_plugin_insn(insn4, plugin_insn, 4); + insn = (insn << 48) | (insn4 << 16); break; default: g_assert_not_reached(); @@ -6049,7 +6081,8 @@ static bool is_fp_pair(int reg) return !(reg & 0x2); } -static DisasJumpType translate_one(CPUS390XState *env, DisasContext *s) +static DisasJumpType translate_one(CPUS390XState *env, DisasContext *s, + struct qemu_plugin_insn *plugin_insn) { const DisasInsn *insn; DisasJumpType ret = DISAS_NEXT; @@ -6057,7 +6090,7 @@ static DisasJumpType translate_one(CPUS390XState *env, DisasContext *s) DisasOps o; /* Search for the insn in the table. */ - insn = extract_insn(env, s, &f); + insn = extract_insn(env, s, &f, plugin_insn); /* Not found means unimplemented/illegal opcode. */ if (insn == NULL) { @@ -6234,7 +6267,7 @@ static void s390x_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs, CPUS390XState *env = cs->env_ptr; DisasContext *dc = container_of(dcbase, DisasContext, base); - dc->base.is_jmp = translate_one(env, dc); + dc->base.is_jmp = translate_one(env, dc, plugin_insn); if (dc->base.is_jmp == DISAS_NEXT) { uint64_t page_start; @@ -6300,6 +6333,8 @@ static const TranslatorOps s390x_tr_ops = { .translate_insn = s390x_tr_translate_insn, .tb_stop = s390x_tr_tb_stop, .disas_log = s390x_tr_disas_log, + .ctx_base_offset = offsetof(DisasContext, base), + .ctx_size = sizeof(DisasContext), }; void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) From patchwork Thu Oct 25 17:20:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656241 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 231E0109C for ; Thu, 25 Oct 2018 17:30:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DA762C23C for ; Thu, 25 Oct 2018 17:30:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F047F2C237; Thu, 25 Oct 2018 17:30:08 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E6A342C235 for ; Thu, 25 Oct 2018 17:30:07 +0000 (UTC) Received: from localhost ([::1]:56050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjSQ-0004jg-Kl for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:30:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKg-0006hj-1r for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKa-0000Jw-0P for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:03 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:40721) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKY-00008m-0j for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:58 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 8470D22221; Thu, 25 Oct 2018 13:21:15 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=3RG3bVXWbfX21XdwJsUjdSnk/d+rwkhlQXCiz9hXEh8=; b=U/f+g 6MGFtRaaWbI01/kLz1ofnRwXcHvRNqBmi4AvUUiTJqSHhH6qtC4jGAnYXhpYSnbD VFjdcKg9BG4z41ALvQEW8BMA0TT5iRqzgnP8iBW+s+Qr5pnYY+6By4Ae//ln9SiH b73GH90u3rVTU1vrdX0ECanAcauCPlvC9ot76Q= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=3RG3bVXWbfX21XdwJsUjdSnk/d+rw khlQXCiz9hXEh8=; b=RM/Ib4AtwtqeNvVhAQWLhBTCYPWiBhtG49TmNUJc/cmZn cTjXPcpSx6Wv4KCVwliJZnLK9Lv8zSquhnH6PuvjQ+9tjZgki/Ww4PELsq863XSc 8WpoT9Z+IfEbyehDOp69QmL3MSBtrULtxfjJRmkgmj7BxXkahrE+TBXqSu2iYtJP ExmHYGy5ufqeOV4B5YZyEFR0peJFYjB78qK8qzhS9LIb02b+sn0pE3zGrPnp7RaA W42wL2rkgEID0UvhOuL+J++g2vClJMRomjcnHxtz1xSY0vcLpyPCTEjb4J/2F/ND jTdRXGDGFrEvyhOAl8pxjQKWYgSa1RiivBag4oo8A== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id C2F75E49EB; Thu, 25 Oct 2018 13:21:14 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:44 -0400 Message-Id: <20181025172057.20414-36-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 35/48] target/sparc: prepare for 2-pass translation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- target/sparc/translate.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/sparc/translate.c b/target/sparc/translate.c index 2fa8b68e0a..74889de426 100644 --- a/target/sparc/translate.c +++ b/target/sparc/translate.c @@ -5902,6 +5902,7 @@ static void sparc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs, unsigned int insn; insn = cpu_ldl_code(env, dc->pc); + qemu_plugin_insn_append(plugin_insn, &insn, sizeof(insn)); dc->base.pc_next += 4; disas_sparc_insn(dc, insn); @@ -5961,6 +5962,8 @@ static const TranslatorOps sparc_tr_ops = { .translate_insn = sparc_tr_translate_insn, .tb_stop = sparc_tr_tb_stop, .disas_log = sparc_tr_disas_log, + .ctx_base_offset = offsetof(DisasContext, base), + .ctx_size = sizeof(DisasContext), }; void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) From patchwork Thu Oct 25 17:20:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656231 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 5383214BB for ; Thu, 25 Oct 2018 17:23:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C27C2C19F for ; Thu, 25 Oct 2018 17:23:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 303142C1C3; Thu, 25 Oct 2018 17:23:58 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CD5D12C19F for ; Thu, 25 Oct 2018 17:23:57 +0000 (UTC) Received: from localhost ([::1]:56028 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjMT-0000rY-47 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:23:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40350) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKh-0006hs-91 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKd-0000NB-68 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:05 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:40625) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKb-00008k-U3 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:02 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 8474622223; Thu, 25 Oct 2018 13:21:15 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=E5jR0FxbWhzdP/nGFhH6wVPz/MvbKGgLHZAN9+KFX3s=; b=2A5GQ rTOZWNpnZeXA76+DQre7rpz+7DXEwFWoXl9zD4G4MsROI3uYvJqnE3AszyRV0mBL EIzrCWj/o8A9KU9WXKQbImNkwTsrsOSm1pT2jX/iZs2+R8+wSdD6UJ20far5yRzB 5MrMigmgu/5c75kRaQj7SFs2t7qqwMWdDpo0WY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=E5jR0FxbWhzdP/nGFhH6wVPz/MvbK GgLHZAN9+KFX3s=; b=roczPYacxGM4CtH2nZMcVWiWN1tOdvtMMQzxCnk47Mc+A d1jBBiZoabD43Qwa0e+DkEQm0ZgD30nDFA29qEkr1ogJctDGf9XKxPKDtsvU2X9N h9x72FWK3Ay62fKSXJfhcsxkT1/Q2kF0wAP+0k+WNmiCA93afwI+lnb8NRp/tuIV nR7/dReQmL6KEdOYelO/5EfIIwOnhky63ozy3xDy8dNfcssz6lQ7ASr5BdCCR3Yf MDajbQImagOsQi2kRblU+Bymd6vDsHtJnSnkpkJCkpRKoZBLDxP1qaSO5usZiNlw LZgJlHEGH+lT+mjF9bhnbqFmF3BL+tp4JWJlBsgeg== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 043C1E4A44; Thu, 25 Oct 2018 13:21:15 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:45 -0400 Message-Id: <20181025172057.20414-37-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 36/48] target/xtensa: prepare for 2-pass translation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- target/xtensa/translate.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c index 14ab1c5ceb..83711f2a18 100644 --- a/target/xtensa/translate.c +++ b/target/xtensa/translate.c @@ -879,7 +879,8 @@ static inline unsigned xtensa_op0_insn_len(DisasContext *dc, uint8_t op0) return xtensa_isa_length_from_chars(dc->config->isa, &op0); } -static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc) +static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc, + struct qemu_plugin_insn *plugin_insn) { xtensa_isa isa = dc->config->isa; unsigned char b[MAX_INSN_LENGTH] = {cpu_ldub_code(env, dc->pc)}; @@ -916,6 +917,7 @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc) for (i = 1; i < len; ++i) { b[i] = cpu_ldub_code(env, dc->pc + i); } + qemu_plugin_insn_append(plugin_insn, b, len); xtensa_insnbuf_from_chars(isa, dc->insnbuf, b, len); fmt = xtensa_format_decode(isa, dc->insnbuf); if (fmt == XTENSA_UNDEFINED) { @@ -1183,7 +1185,7 @@ static void xtensa_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu, gen_ibreak_check(env, dc); } - disas_xtensa_insn(env, dc); + disas_xtensa_insn(env, dc, plugin_insn); if (dc->icount) { tcg_gen_mov_i32(cpu_SR[ICOUNT], dc->next_icount); @@ -1241,6 +1243,8 @@ static const TranslatorOps xtensa_translator_ops = { .translate_insn = xtensa_tr_translate_insn, .tb_stop = xtensa_tr_tb_stop, .disas_log = xtensa_tr_disas_log, + .ctx_base_offset = offsetof(DisasContext, base), + .ctx_size = sizeof(DisasContext), }; void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb) From patchwork Thu Oct 25 17:20:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656225 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 BCFCE109C for ; Thu, 25 Oct 2018 17:23:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A68C72C19F for ; Thu, 25 Oct 2018 17:23:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A23F2C1C3; Thu, 25 Oct 2018 17:23: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2178A2C19F for ; Thu, 25 Oct 2018 17:23:52 +0000 (UTC) Received: from localhost ([::1]:56024 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjMN-0000ld-O5 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:23:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40232) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKb-0006h0-HH for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKZ-0000Jn-R0 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:00 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:51383) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKX-00008l-Vu for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:58 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 847E52222A; Thu, 25 Oct 2018 13:21:15 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=/IJASdCfEQEGLWk+fSrUPbv2L3KHEUqNmu4p3azHRe8=; b=iLnX5 /wmcgCao8GmPw1XDNbGL+wP1FbG54Ym8wPfazlYRjMd5d2nr7p511tLD7uycDyrP NhCwktZwo56IuwMYcMHjB6Dwe1FdPBxU82L7NA1EKRQS5g/n2GK2N8dqoCj3v3ai OD2IhxKiEMy+P6aC01wBOV0L2Xt7BsaLki1qt8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=/IJASdCfEQEGLWk+fSrUPbv2L3KHE UqNmu4p3azHRe8=; b=VWwaNJGvG3w8iLfdnnWJw2L/CqPKzl2aBnYBGGDxo1ABz oL0YDSSWgpo45Tf7r03sdxS70ytNCkJzWl/0U1dD2bcj84VnfmssjM5QTeyIkOXk FzwEbT8p/z1rvx5belhdT9FeePMqHg51bgi+Qpc6YkON6uzG6q6ZQ1fX5L6qrgwg rPU2zB+wb3Ij62WHyU2ENXXdpiIfRLmvewmv2RyXTGXNx+w1/VAxJGmMA11aqMgn qjhWF0cGtkEA00LiBDT9gWczdJ9c8B0rnLmQ+4W6MAM5sxDn7ni2O1z1XdHDFDKR tDkckYCwiDVK+pDz7Pd8zPRvCAwELANIfVOYy1s7Q== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 3921FE4A45; Thu, 25 Oct 2018 13:21:15 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:46 -0400 Message-Id: <20181025172057.20414-38-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 37/48] target/openrisc: prepare for 2-pass translation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- target/openrisc/translate.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/openrisc/translate.c b/target/openrisc/translate.c index 947330e10a..2f084668f9 100644 --- a/target/openrisc/translate.c +++ b/target/openrisc/translate.c @@ -1308,6 +1308,8 @@ static void openrisc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs, OpenRISCCPU *cpu = OPENRISC_CPU(cs); uint32_t insn = cpu_ldl_code(&cpu->env, dc->base.pc_next); + qemu_plugin_insn_append(plugin_insn, &insn, sizeof(insn)); + if (!decode(dc, insn)) { gen_illegal_exception(dc); } @@ -1407,6 +1409,8 @@ static const TranslatorOps openrisc_tr_ops = { .translate_insn = openrisc_tr_translate_insn, .tb_stop = openrisc_tr_tb_stop, .disas_log = openrisc_tr_disas_log, + .ctx_base_offset = offsetof(DisasContext, base), + .ctx_size = sizeof(DisasContext), }; void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) From patchwork Thu Oct 25 17:20:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656265 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 1493817F3 for ; Thu, 25 Oct 2018 17:40:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0366A2C298 for ; Thu, 25 Oct 2018 17:40:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 018822C29D; Thu, 25 Oct 2018 17:40: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 616CF2C291 for ; Thu, 25 Oct 2018 17:40:09 +0000 (UTC) Received: from localhost ([::1]:56106 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjc8-0007y3-G0 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:40:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40310) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKg-0006hm-24 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKb-0000MD-R4 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:03 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:41217) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKb-00008c-Fn for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:01 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 848262222C; Thu, 25 Oct 2018 13:21:15 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=8J8VIfOqFAQeLyhXTZq7723F+xZbh1AX6+hbsJEyN8I=; b=f8ToN NnaCN4yi62jmTmrDd5xBopoxDOk8YgDk7vNkBWWd3CsENNYDZKB/PVFXzuc+FJE8 Nu4SPPi9DEw4fm0AnreRAQU0rG+0jYCc0VFG7Zy+Slk+o3cLDZrWTt0OfJMI39O4 +u9GB0JcbJzxzTH6zkjKOIT5OJKHMnD4/koHj0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=8J8VIfOqFAQeLyhXTZq7723F+xZbh 1AX6+hbsJEyN8I=; b=DXA6+XV/+5OeWJnxV6zSijSuqdNjcT+YlABSNEOLQ46mj xiTlKgTYx94qgfmAp1DpVwkS2Kxd9uj+utQ+UR62FBYCHaEBpjvXY2mf5E2oZcUc MMbwz2w9d/QmeHGGJ8Cv/DqjIgX8rKESVAPAsvikqLRdRZqo4fAfNr4PBXE83TN3 eKdcMdloxyosimY49NADY9qsskHqr0tVFMVqRj067CcIbzYh5R55rY2ewY+9Oeay 1IJBV0aQ9PHyoB5MkOqstfcVjqNeS6G8IyfgRQbWUNlRiEHoJbdRKNlYj5wUZHfE Z4wL9/594YmjMK5CXIH2cPiL06Lp2crU4a7Z4kO2g== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 64F4CE4A46; Thu, 25 Oct 2018 13:21:15 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:47 -0400 Message-Id: <20181025172057.20414-39-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 38/48] translator: implement 2-pass translation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The second pass only occurs when a plugin has subscribed to TB translation events. Signed-off-by: Emilio G. Cota --- tcg/tcg.h | 8 ++++ accel/tcg/translator.c | 91 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 97 insertions(+), 2 deletions(-) diff --git a/tcg/tcg.h b/tcg/tcg.h index d5afe25c97..479b57d65f 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -720,6 +720,14 @@ struct TCGContext { TCGLabel *exitreq_label; + /* + * 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; struct qemu_plugin_dyn_cb_arr *plugin_mem_cb; struct qemu_plugin_insn *plugin_insn; diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index 8591e4b72a..88f9ac62a3 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -17,6 +17,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 @@ -35,6 +36,21 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, CPUState *cpu, TranslationBlock *tb) { int bp_insn = 0; + int insn_idx = 0; + bool tb_trans_cb = false; + bool first_pass = true; /* second pass otherwise */ + void *saved_dc = g_alloca(ops->ctx_size); + /* tb->plugin_mask is a u32 */ + unsigned long plugin_mask = tb->plugin_mask; + struct qemu_plugin_tb *plugin_tb = &tcg_ctx->plugin_tb; + + if (test_bit(QEMU_PLUGIN_EV_VCPU_TB_TRANS, &plugin_mask)) { + tb_trans_cb = true; + plugin_tb->cbs.n = 0; + plugin_tb->n = 0; + plugin_tb->vaddr = tb->pc; + tcg_ctx->plugin_mem_cb = NULL; + } /* Initialize DisasContext */ db->tb = tb; @@ -56,6 +72,21 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, db->max_insns = 1; } + translate: + tcg_func_start(tcg_ctx); + + /* See the "2-pass translation" comment below */ + if (tb_trans_cb) { + void *dc = db; + + dc -= ops->ctx_base_offset; + if (first_pass) { + memcpy(saved_dc, dc, ops->ctx_size); + } else { + memcpy(dc, saved_dc, ops->ctx_size); + } + } + ops->init_disas_context(db, cpu); tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */ @@ -67,7 +98,53 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, ops->tb_start(db, cpu); tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */ + if (!first_pass && plugin_tb->cbs.n) { + qemu_plugin_gen_vcpu_udata_callbacks(&plugin_tb->cbs); + } + while (true) { + struct qemu_plugin_insn *plugin_insn = NULL; + bool mem_helpers = false; + + /* + * 2-pass translation. + * + * In the first pass we fully determine the TB. + * If no plugins have subscribed to TB translation events, we're done. + * + * If they have, we first share with plugins a TB descriptor so + * that plugins can subscribe to instruction-related events, e.g. + * memory accesses of particular instructions, or TB execution. + * With this info, which is kept in plugin_tb, we then do a second pass, + * inserting the appropriate instrumentation into the translated TB. + * + * Since all translation state is kept in DisasContext, we copy it + * before the first pass, and restore it before the second. + */ + if (tb_trans_cb) { + if (first_pass) { + plugin_insn = qemu_plugin_tb_insn_get(plugin_tb); + tcg_ctx->plugin_insn = plugin_insn; + plugin_insn->vaddr = db->pc_next; + g_assert(tcg_ctx->plugin_mem_cb == NULL); + } else { + struct qemu_plugin_insn *insn = &plugin_tb->insns[insn_idx++]; + + tcg_ctx->plugin_insn = NULL; + if (unlikely(insn->exec_cbs.n)) { + qemu_plugin_gen_vcpu_udata_callbacks(&insn->exec_cbs); + } + if (insn->mem_cbs.n) { + tcg_ctx->plugin_mem_cb = &insn->mem_cbs; + if (insn->calls_helpers) { + qemu_plugin_gen_enable_mem_helpers(&insn->mem_cbs); + mem_helpers = true; + } + } else { + tcg_ctx->plugin_mem_cb = NULL; + } + } + } db->num_insns++; ops->insn_start(db, cpu); tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */ @@ -101,10 +178,14 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, && (tb_cflags(db->tb) & CF_LAST_IO)) { /* Accept I/O on the last instruction. */ gen_io_start(); - ops->translate_insn(db, cpu, NULL); + ops->translate_insn(db, cpu, plugin_insn); gen_io_end(); } else { - ops->translate_insn(db, cpu, NULL); + ops->translate_insn(db, cpu, plugin_insn); + } + + if (unlikely(mem_helpers)) { + qemu_plugin_gen_disable_mem_helpers(); } /* Stop translation if translate_insn so indicated. */ @@ -120,6 +201,12 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, } } + if (tb_trans_cb && first_pass) { + qemu_plugin_tb_trans_cb(cpu, plugin_tb); + first_pass = false; + goto translate; + } + /* Emit code to exit the TB, as indicated by db->is_jmp. */ ops->tb_stop(db, cpu); gen_tb_end(db->tb, db->num_insns - bp_insn); From patchwork Thu Oct 25 17:20:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656305 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 1394813A9 for ; Thu, 25 Oct 2018 17:52:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06F252C2A6 for ; Thu, 25 Oct 2018 17:52:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF9822C2AC; Thu, 25 Oct 2018 17:52:29 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A14DB2C2A6 for ; Thu, 25 Oct 2018 17:52:29 +0000 (UTC) Received: from localhost ([::1]:56170 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjo4-00034o-Tw for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:52:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40445) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKj-0006it-7h for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKh-0000Q9-UC for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:09 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:49169) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKh-00008A-LM for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:07 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 8495F2222F; Thu, 25 Oct 2018 13:21:16 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=R0cWWYoVPqgj4951Sj8JkAk4frKglrLTJYRtdzZ+ma4=; b=lGpGe NIAdR41Cm17dFRCmYIZKsrN8/UsozAbOFQzDOLafPMZ5kPWEHyqwNbIeMn7ZC+Et jXzptaLKAj1W+9Xijv9LbOjCaltbkf4SqaBQhV+4RTGOf2SLQdCnLnzh/rl4O6Px LjSwGgble+/dU0BVxGzi6YjJFDkPjD71T/320g= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=R0cWWYoVPqgj4951Sj8JkAk4frKgl rLTJYRtdzZ+ma4=; b=dwP4RlI5rurD+8d2tFIczS0lBBpfD7CcFEUnk8wstHxPg e+JCwLTij/xkaVlBgsJWIzhufNDCnFFrqL8sngZKX3zJkNxBJLSW2/jpVWFPywfJ MtR4sgZXxPvTinhLTJt6cWnpQrSfmvM7SJBfiFSSUPn6ZgO9iqQVSGXzWQIoXpC9 asWxTA/W/AYysg4kiXMiTAJTIkHW6e/JCDQ1ZwRDzYJ8OlNl+w50+JxxkNOSaKIW TWOsM4RaIBraM8IMXQ7+jjGSYU7YpGPcN5t1K7bxGDpR9Y9ytVT+rDR7i+48dwjX V8WotY9cHN05WchbWUCSjp2wUmoFrgHHdviziCnqQ== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id B5BC4E4A4A; Thu, 25 Oct 2018 13:21:15 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:48 -0400 Message-Id: <20181025172057.20414-40-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 39/48] plugin: add API symbols to qemu-plugins.symbols X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- qemu-plugins.symbols | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 qemu-plugins.symbols diff --git a/qemu-plugins.symbols b/qemu-plugins.symbols new file mode 100644 index 0000000000..76a57e62bb --- /dev/null +++ b/qemu-plugins.symbols @@ -0,0 +1,32 @@ +{ + qemu_plugin_uninstall; + 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_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_mem_size_shift; + qemu_plugin_mem_is_sign_extended; + qemu_plugin_mem_is_big_endian; + qemu_plugin_mem_is_store; + qemu_plugin_vcpu_for_each; + qemu_plugin_n_vcpus; + qemu_plugin_n_max_vcpus; +}; From patchwork Thu Oct 25 17:20:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656245 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 DBACD13BF for ; Thu, 25 Oct 2018 17:30:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C62D82C22E for ; Thu, 25 Oct 2018 17:30:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BAA642C254; Thu, 25 Oct 2018 17:30:13 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F28472C231 for ; Thu, 25 Oct 2018 17:30:12 +0000 (UTC) Received: from localhost ([::1]:56060 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjSW-0005wY-9p for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:30:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40455) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKj-0006j0-Bp for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKh-0000Pr-Pn for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:09 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:54545) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKh-000089-Hj for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:07 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 84ABE22231; Thu, 25 Oct 2018 13:21:16 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=XfR82fSVFws5xnGSbnMvDlP4t/oV4ytjd8+UV2zc6kc=; b=eV5bs 9YVDeD1Uh5UFtVxvHsNOU/7WEvx7tF/PEYM61bDSQxGfcySQTLi2IvyY9WQN/u7m XAffgUdoYdjKSpZz7fh5hY8n0ueis6aCoQb48Uzg7UuuH1r/TX/ZTXnQrKaCxGXe sAZPnjtoBN0+IFncnq3DWMymG558CCEVfWxOl0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=XfR82fSVFws5xnGSbnMvDlP4t/oV4 ytjd8+UV2zc6kc=; b=n/ucud8XOV3W1cUyg95YyL+Hph9yTNhK5Cw6WsS1idMYb QTwM0mSFxjoFKIZwtsnsF2UBNCXSMIRen+iHLK4ITEXhcYznSEcYPPwKQifqG3ca xqHLjMcLjGrSm7hcnDcmGf2+plu8W6honPY7T/bEVLAur3JK2V8LMQjsVnpVU8ue J5iAiLOEcseD+yDVw0kYbqo64Rb6IY3585L8niH51GEujbl5kiTC4tDsdOQKPklJ vImnnQP0Ko+3SJuM8wwxFLUd+zUbnlcjZZykTQ7VRp4blb8gv/92r1WYjRL7YFZ5 8zg9QGQxKCzKL91HSmHkFQOHByT/5tOFEGiFyMxGQ== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 01353E4AB8; Thu, 25 Oct 2018 13:21:16 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:49 -0400 Message-Id: <20181025172057.20414-41-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 40/48] plugin: let plugins control the virtual clock X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- include/qemu/plugin-api.h | 9 +++++ include/qemu/plugin.h | 5 +++ plugin.c | 79 +++++++++++++++++++++++++++++++++++++++ stubs/plugin.c | 9 +++++ util/qemu-timer.c | 3 ++ qemu-plugins.symbols | 1 + stubs/Makefile.objs | 1 + 7 files changed, 107 insertions(+) create mode 100644 stubs/plugin.c diff --git a/include/qemu/plugin-api.h b/include/qemu/plugin-api.h index 5c6bb45279..076353a2d2 100644 --- a/include/qemu/plugin-api.h +++ b/include/qemu/plugin-api.h @@ -218,6 +218,15 @@ void qemu_plugin_register_flush_cb(qemu_plugin_id_t id, void qemu_plugin_register_atexit_cb(qemu_plugin_id_t id, qemu_plugin_udata_cb_t cb, void *userdata); +typedef int64_t (*qemu_plugin_clock_func_t)(void); + +/* + * Can only be called from plugin_init. + * Returns true on success + */ +bool qemu_plugin_register_virtual_clock(qemu_plugin_id_t id, + qemu_plugin_clock_func_t clock); + /* returns -1 in user-mode */ int qemu_plugin_n_vcpus(void); diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index 0da0f1b892..617161329f 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -127,6 +127,8 @@ struct qemu_plugin_tb { struct qemu_plugin_dyn_cb_arr cbs; }; +extern bool use_plugin_clock; + static inline void qemu_plugin_insn_append(struct qemu_plugin_insn *insn, const void *from, size_t size) { @@ -191,6 +193,7 @@ void qemu_plugin_flush_cb(void); void qemu_plugin_atexit_cb(void); void qemu_plugin_add_dyn_cb_arr(struct qemu_plugin_dyn_cb_arr *arr); +int64_t plugin_get_clock(void); #else /* !CONFIG_PLUGINS */ @@ -234,6 +237,8 @@ static inline void qemu_plugin_add_dyn_cb_arr(struct qemu_plugin_dyn_cb_arr *arr) { } +int64_t plugin_get_clock(void); + #endif /* !CONFIG_PLUGINS */ #endif /* QEMU_PLUGIN_H */ diff --git a/plugin.c b/plugin.c index 76609f1da4..291767f2bb 100644 --- a/plugin.c +++ b/plugin.c @@ -71,6 +71,13 @@ struct qemu_plugin_state { * the code cache is flushed. */ struct qht dyn_cb_arr_ht; + /* + * We support a single clock reference from plugins. We keep a pointer + * to the context of the plugin that provides the reference, + * so that we can remove the reference when the plugin is uninstalled. + */ + qemu_plugin_clock_func_t clock_ref; + struct qemu_plugin_ctx *clock_ctx; }; /* @@ -104,6 +111,8 @@ QemuOptsList qemu_plugin_opts = { typedef int (*qemu_plugin_install_func_t)(qemu_plugin_id_t, int, char **); static struct qemu_plugin_state plugin; +bool use_plugin_clock; +static bool plugin_installing; static bool plugin_dyn_cb_arr_cmp(const void *ap, const void *bp) { @@ -251,7 +260,9 @@ static int plugin_load(struct qemu_plugin_desc *desc) QTAILQ_INSERT_TAIL(&plugin.ctxs, ctx, entry); qemu_rec_mutex_unlock(&plugin.lock); + plugin_installing = true; rc = install(ctx->id, desc->argc, desc->argv); + plugin_installing = false; if (rc) { error_report("%s: qemu_plugin_install returned error code %d", __func__, rc); @@ -418,6 +429,10 @@ void qemu_plugin_uninstall(qemu_plugin_id_t id, qemu_plugin_uninstall_cb_t cb) for (ev = 0; ev < QEMU_PLUGIN_EV_MAX; ev++) { plugin_unregister_cb__locked(ctx, ev); } + if (ctx == plugin.clock_ctx) { + atomic_set(&plugin.clock_ref, NULL); + plugin.clock_ctx = NULL; + } qemu_rec_mutex_unlock(&plugin.lock); /* XXX how to flush when we're not in a vCPU thread? */ @@ -964,6 +979,70 @@ uint64_t qemu_plugin_ram_addr_from_host(void *haddr) #endif } +#ifndef CONFIG_USER_ONLY +static bool +qemu_plugin_register_virtual_clock__locked(qemu_plugin_id_t id, + qemu_plugin_clock_func_t clock) +{ + struct qemu_plugin_ctx *ctx = id_to_ctx__locked(id); + + if (!plugin_installing) { + error_report("plugin: can only call %s during plugin installation", + __func__); + return false; + } + if (use_plugin_clock) { + error_report("plugin: clock reference already registered"); + return false; + } + if (clock == NULL) { + error_report("%s: cannot pass NULL clock", __func__); + return false; + } + plugin.clock_ctx = ctx; + use_plugin_clock = true; + atomic_set(&plugin.clock_ref, clock); + return true; +} +#endif /* !CONFIG_USER_ONLY */ + +bool qemu_plugin_register_virtual_clock(qemu_plugin_id_t id, + qemu_plugin_clock_func_t clock) +{ +#ifdef CONFIG_USER_ONLY + return false; +#else + bool ret; + + qemu_rec_mutex_lock(&plugin.lock); + ret = qemu_plugin_register_virtual_clock__locked(id, clock); + qemu_rec_mutex_unlock(&plugin.lock); + return ret; +#endif +} + +#ifdef CONFIG_USER_ONLY +int64_t plugin_get_clock(void) +{ + abort(); + return 0; +} +#else +/* + * Note: use_plugin_clock might be set, but the plugin providing the clock + * might have been uninstalled. + */ +int64_t plugin_get_clock(void) +{ + qemu_plugin_clock_func_t clock_ref = atomic_read(&plugin.clock_ref); + + if (clock_ref) { + return clock_ref(); + } + return cpu_get_clock(); +} +#endif + static void __attribute__((__constructor__)) plugin_init(void) { int i; diff --git a/stubs/plugin.c b/stubs/plugin.c new file mode 100644 index 0000000000..ab70365652 --- /dev/null +++ b/stubs/plugin.c @@ -0,0 +1,9 @@ +#include "qemu/osdep.h" +#include "qemu/plugin.h" + +bool use_plugin_clock; + +int64_t plugin_get_clock(void) +{ + abort(); +} diff --git a/util/qemu-timer.c b/util/qemu-timer.c index eb60d8f73a..d20ab0331c 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -24,6 +24,7 @@ #include "qemu/osdep.h" #include "qemu/main-loop.h" +#include "qemu/plugin.h" #include "qemu/timer.h" #include "sysemu/replay.h" #include "sysemu/sysemu.h" @@ -601,6 +602,8 @@ int64_t qemu_clock_get_ns(QEMUClockType type) case QEMU_CLOCK_VIRTUAL_EXT: if (use_icount) { return cpu_get_icount(); + } else if (use_plugin_clock) { + return plugin_get_clock(); } else { return cpu_get_clock(); } diff --git a/qemu-plugins.symbols b/qemu-plugins.symbols index 76a57e62bb..93587b07e1 100644 --- a/qemu-plugins.symbols +++ b/qemu-plugins.symbols @@ -16,6 +16,7 @@ qemu_plugin_register_vcpu_syscall_cb; qemu_plugin_register_vcpu_syscall_ret_cb; qemu_plugin_register_atexit_cb; + qemu_plugin_register_virtual_clock; qemu_plugin_tb_n_insns; qemu_plugin_tb_get_insn; qemu_plugin_tb_vaddr; diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index fbcdc0256d..f32bea429f 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -23,6 +23,7 @@ stub-obj-y += migr-blocker.o stub-obj-y += change-state-handler.o stub-obj-y += monitor.o stub-obj-y += notify-event.o +stub-obj-y += plugin.o stub-obj-y += qtest.o stub-obj-y += replay.o stub-obj-y += runstate-check.o From patchwork Thu Oct 25 17:20:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656257 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 5C0E713BF for ; Thu, 25 Oct 2018 17:36:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 40847283D1 for ; Thu, 25 Oct 2018 17:36:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2ED9E2C22A; Thu, 25 Oct 2018 17:36:58 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A8B07283D1 for ; Thu, 25 Oct 2018 17:36:57 +0000 (UTC) Received: from localhost ([::1]:56092 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjZ2-0004RD-MW for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:36:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40311) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKg-0006hn-24 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKb-0000MJ-TH for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:03 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:57675) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKb-0000C4-IX for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:01 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id F1685221C9; Thu, 25 Oct 2018 13:21:16 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=FuYhJcRsEANKO2wrKj9v/dx0BceTs4MLE9f3oGgohck=; b=wRjPd lhT3E4yf+YLPUzl9pKLPGkJrIOdrJwB8UAkUi/UW/h9gPTWDjaS8jZaiUWFP5Nux ehy6nTwWUmHrXbgJgwU94u/Tla/wCc8M37UXv8FcCmrbHYZeZyaBXfFCDngrgb3+ kQDq1/mjU2TbrF4F7gcmrm3mWmVynabm5yPkPw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=FuYhJcRsEANKO2wrKj9v/dx0BceTs 4MLE9f3oGgohck=; b=HB42xCcSo8RnaI6hEd1u/lGuvEOGHkc+2D26B99APrD+I DJMpCOpYu/8jzolgz4MAnXsX8YExcI+3SBtzhV4w5KGeL5blmwQtpufBlgIsJOpZ ClVI2K409CzTWgTBwsLFEnhkDS2YoahoXugzEa8j7ObR6JYN+Kh8XRLWSxdWm/xm ro+4lOI1NCE1GflU5wH7IncMTv6E1ZeKjk4tu7ZpXeZnCnzUuEQwIZ4V/jBU0b4D g+7DDu3GoFurLr7Ju/JxgSSQPuXDwab2Ea7GDmKQUwDypTHYJOdjJXuaf7CXh+Xr gUyYS2zQ20r0L1JcosgWySjwnaxzVEC0iV3dH6BTg== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 3D862E4AB9; Thu, 25 Oct 2018 13:21:16 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:50 -0400 Message-Id: <20181025172057.20414-42-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 41/48] configure: add --enable-plugins X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP For now only add it for ELF platforms, since we rely on the linker's --dynamic-list flag to pass a list of symbols to be exported to the executable. An alternative would be to use -rdynamic, but that would expose all of QEMU's objects to plugins. I have no experience with non-ELF systems but I suspect adding support for those should be pretty easy. Signed-off-by: Emilio G. Cota Reviewed-by: Alex Bennée --- configure | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/configure b/configure index 03bf719ca7..78e86098e5 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 @@ -477,6 +478,7 @@ libxml2="" docker="no" debug_mutex="no" libpmem="" +plugins="no" # cross compilers defaults, can be overridden with --cross-cc-ARCH cross_cc_aarch64="aarch64-linux-gnu-gcc" @@ -1443,6 +1445,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" @@ -1633,6 +1639,8 @@ Advanced options (experts only): xen pv domain builder --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: @@ -5204,6 +5212,42 @@ 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 + +if compile_prog "" "-Wl,--dynamic-list=$TMPTXT" ; then + ld_dynamic_list="yes" +else + if test "$plugins" = "yes" ; then + error_exit \ + "Plugin support requires specifying a set of symbols that " \ + "are exported to plugins. Unfortunately your linker doesn't " \ + "support the flag (--dynamic-list) used for this purpose." + fi +fi + ######################################## # See if 16-byte vector operations are supported. # Even without a vector unit the compiler may expand these. @@ -6091,6 +6135,7 @@ echo "VxHS block device $vxhs" echo "capstone $capstone" echo "docker $docker" echo "libpmem support $libpmem" +echo "plugin support $plugins" if test "$sdl_too_old" = "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support" @@ -6849,6 +6894,12 @@ if test "$libpmem" = "yes" ; then echo "CONFIG_LIBPMEM=y" >> $config_host_mak fi +if test "$plugins" = "yes" ; then + echo "CONFIG_PLUGINS=y" >> $config_host_mak + LIBS="-ldl $LIBS" + LDFLAGS="-Wl,--dynamic-list=\$(SRC_PATH)/qemu-plugins.symbols $LDFLAGS" +fi + if test "$tcg_interpreter" = "yes"; then QEMU_INCLUDES="-iquote \$(SRC_PATH)/tcg/tci $QEMU_INCLUDES" elif test "$ARCH" = "sparc64" ; then From patchwork Thu Oct 25 17:20:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656249 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 4BF4913BF for ; Thu, 25 Oct 2018 17:33:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 382F7283D1 for ; Thu, 25 Oct 2018 17:33:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C4BA2842D; Thu, 25 Oct 2018 17:33:32 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8F827283D1 for ; Thu, 25 Oct 2018 17:33:31 +0000 (UTC) Received: from localhost ([::1]:56068 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjVg-00079S-Qn for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:33:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40309) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKg-0006hl-1v for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKc-0000MV-5f for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:03 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:37971) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKb-0000C5-Oq for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:01 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id F1849221D0; Thu, 25 Oct 2018 13:21:16 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=mesmtp; bh=FX7AVqrDwIhKrslQIwPg80IljEIEqJFqaXeTG0xChRA=; b=eTvsaBEq7GZm rSx7VwB2GLbuXz7Fzl7vbR9hxpChhbYBZu4HhEztReBDic5cV5FLDWe1SFZd8Qhu NXmd6WzG01HafJBe6xfEJrZEltpmLZR0pEMtSovo1nj1ZMMA68GZcg+E9vPz7jBy fRu10utzjVu/FJv7eaRZb3FBKatll6k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=FX7AVqrDwIhKrslQIwPg80IljEIEqJFqaXeTG0xCh RA=; b=wcAretpwTb3wm6ZP/12jxG9sW34UeVBW0koPiO/+twKtFeTLgWeW8RX77 PtajlfeaD3f8zVEqmykPmDyIXuiFWJyBGv0ZgrG+8uwMpsfeP3nGQ83xAGu+jqpb BBgde2VuMcC+Wi+IMZp6AUhlLnXNX1/beG7lvPeLk4WY+seg8XdQctfb94XEAOkE h/t3I2ojOURsx9FNXoE2hbj954GOBu3UZI/viOow+qrBZyUpT2SEdgi8QN5ThAJ0 PnZBWdsvkvskw4t0R5Mz7KmrZa/lx/cxanN56fkz256h/PcI0kfJoD5Vmu/nmGUU H9W5KUwX3WaA/bPACKXQFqNV9TIAg== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 7B951E4ABC; Thu, 25 Oct 2018 13:21:16 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:51 -0400 Message-Id: <20181025172057.20414-43-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 42/48] vl: support -plugin option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , 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: Lluís Vilanova Signed-off-by: Lluís Vilanova [ cota: s/instrument/plugin ] Signed-off-by: Emilio G. Cota --- vl.c | 11 +++++++++++ qemu-options.hx | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/vl.c b/vl.c index 4e25c78bff..ebb188552e 100644 --- a/vl.c +++ b/vl.c @@ -111,6 +111,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" @@ -2962,6 +2963,7 @@ int main(int argc, char **argv, char **envp) } BlockdevOptions_queue; QSIMPLEQ_HEAD(, BlockdevOptions_queue) bdo_queue = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue); + struct qemu_plugin_list plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list); module_call_init(MODULE_INIT_TRACE); @@ -2990,6 +2992,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); @@ -3806,6 +3809,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); @@ -4107,6 +4113,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"), diff --git a/qemu-options.hx b/qemu-options.hx index f139459e80..5cd1d84df4 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3838,6 +3838,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) From patchwork Thu Oct 25 17:20:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656313 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 53E9413A9 for ; Thu, 25 Oct 2018 17:55:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 468E42C2AC for ; Thu, 25 Oct 2018 17:55:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39FC92C2B0; Thu, 25 Oct 2018 17:55: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D0FB72C2AC for ; Thu, 25 Oct 2018 17:55:25 +0000 (UTC) Received: from localhost ([::1]:56198 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjqu-0006dd-Oo for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:55:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40449) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKj-0006ix-9V for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKh-0000Q4-T8 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:09 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:34201) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKh-0000CD-KQ for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:07 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 32448221EE; Thu, 25 Oct 2018 13:21:17 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=mesmtp; bh=MKHat/22//I/LLXdHqd+NGCp1Wrms7QA+9XMZx05kKM=; b=NSjBMwSCffaj Ew7U2Ae8QRCfOLuhkbIEm4/LHR9vmQbhI207pXkLRjPvgMkEaBKATJutKOJaP1TR erhYfACjh5WJNjSjVsiIhNUevw4usrFDryiT2aUbiiLeYa6XqSKwJPe0R5pZcNni bos1chCMXyZHZtbVzFxpnCbUbGHEHDk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=MKHat/22//I/LLXdHqd+NGCp1Wrms7QA+9XMZx05k KM=; b=rWEqi72IRIgdIgCpi+9XsMTs4c7zQWkGlJnKzwM/jrhSyRoq4VY9M/Npd daHdeVELnKWuBOhXxDlMeGkYC4WprJ0H5eNVveFAzFZNWzHtpNCf5gyAHhG/kdT8 W2y0cOD3bnJXpxMgX8ulBxcuf1qBLCd/WFqhNeHMHDaphsRAflU/dbSYwFpP1c4x W/m3BUyyfBDpdzfri5wBtNrXoDbRC0aZsidrTFrFiihsKio7Yr5cb0nwM2AAuITM cPo3m9Pi/JwHJVcCjVn7E/Yv7MnVljA7u624JlJ/YVN/zgytMXRJ9w7fXHkSEARY nQTa1akLj/wHtt3HhDVbBUsdw/3pg== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id AD998E4074; Thu, 25 Oct 2018 13:21:16 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:52 -0400 Message-Id: <20181025172057.20414-44-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 43/48] linux-user: support -plugin option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , 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: Lluís Vilanova Signed-off-by: Lluís Vilanova [ cota: s/instrument/plugin ] Signed-off-by: Emilio G. Cota --- linux-user/main.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/linux-user/main.c b/linux-user/main.c index 923cbb753a..0244ad736c 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -28,6 +28,7 @@ #include "qemu/config-file.h" #include "qemu/cutils.h" #include "qemu/help_option.h" +#include "qemu/plugin.h" #include "cpu.h" #include "exec/exec-all.h" #include "tcg.h" @@ -385,6 +386,15 @@ static void handle_arg_trace(const char *arg) trace_file = trace_opt_parse(arg); } +static struct qemu_plugin_list plugins = QTAILQ_HEAD_INITIALIZER(plugins); + +#ifdef CONFIG_PLUGINS +static void handle_arg_plugin(const char *arg) +{ + qemu_plugin_opt_parse(arg, &plugins); +} +#endif + struct qemu_argument { const char *argv; const char *env; @@ -436,6 +446,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_PLUGINS + {"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} @@ -627,6 +641,7 @@ int main(int argc, char **argv, char **envp) srand(time(NULL)); qemu_add_opts(&qemu_trace_opts); + qemu_plugin_add_opts(); optind = parse_args(argc, argv); @@ -634,6 +649,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 Thu Oct 25 17:20:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656227 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 8B1BA109C for ; Thu, 25 Oct 2018 17:23:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 727DA2C1C3 for ; Thu, 25 Oct 2018 17:23:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6624C2C1D5; Thu, 25 Oct 2018 17:23: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C52732C19F for ; Thu, 25 Oct 2018 17:23:54 +0000 (UTC) Received: from localhost ([::1]:56025 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjMQ-0000oC-2u for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:23:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKh-0006ht-93 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKc-0000Mn-Ja for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:05 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:36331) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKb-0000CB-RV for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:01 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 6D509221F5; Thu, 25 Oct 2018 13:21:17 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=sI6lJztZK5hJVK1lfweSOxsqopisVE0RPdjo68zG7tk=; b=r1gqX Ha32nSV8ypr7AT+gRoZGv+QFij8IxR6iRkwGYzAfEyA5iFd3dYP28PQVl5cdNd3F wbuE5ImqOTTCvTx74ntlcTlHOkIzfGqsQr2B0yrcmJ/NFj2IUOjYI4cuEw3Jal5u I7IadLI/2TXh8LrtmkJBLp5PmFaF/OoUCHgKkY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=sI6lJztZK5hJVK1lfweSOxsqopisV E0RPdjo68zG7tk=; b=P80YzKfcwJj+qGzCrUnfOpEOHYg7eKqkSiWHTaLHOGxGP FTrrxKIIl4K1KKa7hTNAy2878rjJ8g97VPGwj0/Y0kGn/rDjq/pxRJ/byMzBpp/v le5zhWyiuwEDIWsKyYbRM5AJR8lwCEVhrhCgFL+Ha3H/Af4VW7IxDAbZT0ywcqOL j5BJmjYt1zd3/ZaOh2HyMc5HRxMZT7EWfzKu+zqTSYbQyk14oZGFpP5w/N17u54I p9Xtc25AoTlwC3GU03Jg6yd5x2lsGb6D1HJLMXA4lCAhIYewJxmrFgFhqoJXBjZS mOYrOT0Zu2jQUiRxzPgqflPVLo10eC00x1NkLSuwA== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id F3A7AE455F; Thu, 25 Oct 2018 13:21:16 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:53 -0400 Message-Id: <20181025172057.20414-45-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 44/48] cpus: lockstep execution support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- include/qom/cpu.h | 27 +++++++++++ cpus.c | 113 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 139 insertions(+), 1 deletion(-) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 1ac56fe84b..5841421a20 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -279,6 +279,12 @@ typedef void (*run_on_cpu_func)(CPUState *cpu, run_on_cpu_data data); struct qemu_work_item; +enum cpu_lockstep { + CPU_LOCKSTEP_RUN, + CPU_LOCKSTEP_STOP_REQUEST, + CPU_LOCKSTEP_WAIT, +}; + #define CPU_UNSET_NUMA_NODE_ID -1 #define CPU_TRACE_DSTATE_MAX_EVENTS 32 @@ -364,6 +370,7 @@ struct CPUState { QemuCond halt_cond; QSIMPLEQ_HEAD(, qemu_work_item) work_list; uint32_t halted; + enum cpu_lockstep lockstep; bool created; bool stop; bool stopped; @@ -1019,6 +1026,26 @@ static inline void cpu_interrupt(CPUState *cpu, int mask) cpu_interrupt_handler(cpu, mask); } +/** + * cpu_lockstep_enable - Enable execution of CPUs in lockstep + * + * Note: this feature is MTTCG-only. + * Lockstep execution allows CPUs to partition their execution into windows + * whose start is synchronized with that of other CPUs. This can have many + * uses, e.g. limiting execution skew in the guest. + * + * See also: cpu_lockstep_request_stop() + */ +void cpu_lockstep_enable(void); + +/** + * cpu_lockstep_request_stop - Finish the CPU's execution window + * @cpu: the CPU of interest + * + * See also: cpu_lockstep_enable() + */ +void cpu_lockstep_request_stop(CPUState *cpu); + #else /* USER_ONLY */ void cpu_interrupt(CPUState *cpu, int mask); diff --git a/cpus.c b/cpus.c index 3efe89354d..a446632a5c 100644 --- a/cpus.c +++ b/cpus.c @@ -80,6 +80,14 @@ int64_t max_advance; static QEMUTimer *throttle_timer; static unsigned int throttle_percentage; +/* lockstep execution */ +static bool lockstep_enabled; +static bool lockstep_ongoing_wakeup; +static QemuMutex lockstep_lock; +static int n_lockstep_running_cpus; +static int n_lockstep_cpus; +static CPUState **lockstep_cpus; + #define CPU_THROTTLE_PCT_MIN 1 #define CPU_THROTTLE_PCT_MAX 99 #define CPU_THROTTLE_TIMESLICE_NS 10000000 @@ -1174,6 +1182,11 @@ static bool cpu_can_run(CPUState *cpu) if (cpu_is_stopped(cpu)) { return false; } + if (lockstep_enabled && + (cpu->lockstep == CPU_LOCKSTEP_STOP_REQUEST || + cpu->lockstep == CPU_LOCKSTEP_WAIT)) { + return false; + } return true; } @@ -1246,6 +1259,7 @@ void qemu_init_cpu_loop(void) { qemu_init_sigbus(); qemu_mutex_init(&qemu_global_mutex); + qemu_mutex_init(&lockstep_lock); qemu_thread_get_self(&io_thread); } @@ -1298,6 +1312,90 @@ static void qemu_wait_io_event_common(CPUState *cpu) cpu_mutex_lock(cpu); } +void cpu_lockstep_enable(void) +{ + atomic_xchg(&lockstep_enabled, true); +} + +void cpu_lockstep_request_stop(CPUState *cpu) +{ + bool locked = cpu_mutex_locked(cpu); + + g_assert(lockstep_enabled); + if (!locked) { + cpu_mutex_lock(cpu); + } + g_assert(cpu->lockstep == CPU_LOCKSTEP_RUN || + cpu->lockstep == CPU_LOCKSTEP_STOP_REQUEST); + cpu->lockstep = CPU_LOCKSTEP_STOP_REQUEST; + if (!locked) { + cpu_mutex_unlock(cpu); + } + cpu_exit(cpu); +} + +static void lockstep_resume(CPUState *cpu, run_on_cpu_data ignored) +{ + g_assert(lockstep_enabled); + cpu_mutex_lock(cpu); + g_assert(cpu->lockstep == CPU_LOCKSTEP_WAIT); + cpu->lockstep = CPU_LOCKSTEP_RUN; + cpu_mutex_unlock(cpu); +} + +static void lockstep_check_stop(CPUState *cpu) +{ + if (!lockstep_enabled) { + return; + } + if (cpu->lockstep == CPU_LOCKSTEP_STOP_REQUEST || + (cpu->lockstep == CPU_LOCKSTEP_RUN && cpu_thread_is_idle(cpu))) { + qemu_mutex_lock(&lockstep_lock); + cpu->lockstep = CPU_LOCKSTEP_WAIT; + n_lockstep_running_cpus--; + if (n_lockstep_running_cpus == 0) { + int i; + + /* wake up all waiting cpus */ + lockstep_ongoing_wakeup = true; + n_lockstep_running_cpus = n_lockstep_cpus; + qemu_mutex_unlock(&lockstep_lock); + cpu_mutex_unlock(cpu); + for (i = 0; i < n_lockstep_cpus; i++) { + run_on_cpu_no_bql(lockstep_cpus[i], lockstep_resume, + RUN_ON_CPU_NULL); + } + cpu_mutex_lock(cpu); + qemu_mutex_lock(&lockstep_lock); + lockstep_ongoing_wakeup = false; + } + qemu_mutex_unlock(&lockstep_lock); + } +} + +static void cpu_lockstep_init(CPUState *cpu) +{ + if (!lockstep_enabled) { + return; + } + qemu_mutex_lock(&lockstep_lock); + /* + * HACK: avoid racing with a wakeup, which would miss the addition + * of this CPU; just wait until no wakeup is ongoing. + */ + while (unlikely(lockstep_ongoing_wakeup)) { + qemu_mutex_unlock(&lockstep_lock); + sched_yield(); + qemu_mutex_lock(&lockstep_lock); + } + lockstep_cpus = g_realloc(lockstep_cpus, + (n_lockstep_cpus + 1) * sizeof(CPUState *)); + lockstep_cpus[n_lockstep_cpus++] = cpu; + n_lockstep_running_cpus++; + qemu_mutex_unlock(&lockstep_lock); + cpu->lockstep = CPU_LOCKSTEP_RUN; +} + static void qemu_tcg_rr_wait_io_event(CPUState *cpu) { g_assert(qemu_mutex_iothread_locked()); @@ -1321,6 +1419,15 @@ static void qemu_tcg_rr_wait_io_event(CPUState *cpu) cpu_mutex_unlock(cpu); } +static inline bool lockstep_is_waiting(CPUState *cpu) +{ + if (!lockstep_enabled) { + return true; + } + g_assert(cpu_mutex_locked(cpu)); + return cpu->lockstep == CPU_LOCKSTEP_WAIT; +} + static void qemu_wait_io_event(CPUState *cpu) { bool asleep = false; @@ -1328,7 +1435,9 @@ static void qemu_wait_io_event(CPUState *cpu) g_assert(cpu_mutex_locked(cpu)); g_assert(!qemu_mutex_iothread_locked()); - while (cpu_thread_is_idle(cpu)) { + lockstep_check_stop(cpu); + + while (cpu_thread_is_idle(cpu) && lockstep_is_waiting(cpu)) { if (!asleep) { asleep = true; qemu_plugin_vcpu_idle_cb(cpu); @@ -1884,6 +1993,8 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) cpu->can_do_io = 1; current_cpu = cpu; qemu_cond_signal(&cpu->cond); + /* init lockstep */ + cpu_lockstep_init(cpu); /* process any pending work */ cpu->exit_request = 1; From patchwork Thu Oct 25 17:20:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656233 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 ED06C109C for ; Thu, 25 Oct 2018 17:27:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D66E22C1AD for ; Thu, 25 Oct 2018 17:27:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C941A2C1DE; Thu, 25 Oct 2018 17: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4DFAB2C1AD for ; Thu, 25 Oct 2018 17:27:11 +0000 (UTC) Received: from localhost ([::1]:56042 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjPa-0003FO-Jf for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:27:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40358) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKh-0006hu-Eg for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKg-0000OT-4k for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:07 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:37891) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKc-0000Dc-JC for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:03 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id AA3BC2222E; Thu, 25 Oct 2018 13:21:17 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=VVLOs12hxAzHgeFEt+gfeG+nAaTZ5tl4TIusAXlKp4Q=; b=Djk03 IYBmgLgdBxiLNiHUXl52l9QKljDyP8x3Bt/7NF3W814LrpCSyWyRMrZmEu41S7eK gUHwRMeONKj4gbu8dVP0vHq3f+qB73+vrtLZEVp9Eu9JngMmfsHfkXfY/9lgAWr3 AY98DT3BRwTdVw2the9NWso6tav8mk4I7qq9e0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=VVLOs12hxAzHgeFEt+gfeG+nAaTZ5 tl4TIusAXlKp4Q=; b=XSHSvgRdEfhp2QBLh5QZzWoQklmktgVzs25VAkiQHkf/e w4+nGF1oMqkyiYgwXLeFQ0V1h4Kd6lInF7FnftECQOJtLiM/o0NG7ux7GNAG/OVj hX1rDqafME58etKI3g7ar/s39cPUCdD/1iG6MD0BLGSuEiOcEKAk0xxZgaQ7Rfy6 7LCo8dTE89KEY50LEVYIbzOFzbWyFF5T4BvtJqSFNCmD0WGeFOLM6qhF/6qzo/LC aj+9hhBPDcbKfYPw3UNBoYo6rOE14HCIaLnjcbMbIMfpoIJuba3iLUIjzfaQQzht U9OPLnjh5t+zqc6A2xgZEqT/ne2AHxUoZzPPQO/vQ== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 44BD8E4074; Thu, 25 Oct 2018 13:21:17 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:54 -0400 Message-Id: <20181025172057.20414-46-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 45/48] plugin: lockstep execution support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- include/qemu/plugin-api.h | 7 +++++++ include/qemu/plugin.h | 5 +++++ cpus.c | 1 + plugin.c | 35 +++++++++++++++++++++++++++++++++++ qemu-plugins.symbols | 3 +++ 5 files changed, 51 insertions(+) diff --git a/include/qemu/plugin-api.h b/include/qemu/plugin-api.h index 076353a2d2..5062e20e08 100644 --- a/include/qemu/plugin-api.h +++ b/include/qemu/plugin-api.h @@ -227,6 +227,13 @@ typedef int64_t (*qemu_plugin_clock_func_t)(void); bool qemu_plugin_register_virtual_clock(qemu_plugin_id_t id, qemu_plugin_clock_func_t clock); +void qemu_plugin_enable_lockstep_execution(void); + +void qemu_plugin_register_lockstep_cb(qemu_plugin_id_t id, + qemu_plugin_simple_cb_t cb); + +void qemu_plugin_end_time_slice(void); + /* returns -1 in user-mode */ int qemu_plugin_n_vcpus(void); diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index 617161329f..c19071bdbe 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -58,6 +58,7 @@ enum qemu_plugin_event { QEMU_PLUGIN_EV_VCPU_RESUME, QEMU_PLUGIN_EV_VCPU_SYSCALL, QEMU_PLUGIN_EV_VCPU_SYSCALL_RET, + QEMU_PLUGIN_EV_LOCKSTEP, QEMU_PLUGIN_EV_FLUSH, QEMU_PLUGIN_EV_ATEXIT, QEMU_PLUGIN_EV_MAX, @@ -194,6 +195,7 @@ void qemu_plugin_atexit_cb(void); void qemu_plugin_add_dyn_cb_arr(struct qemu_plugin_dyn_cb_arr *arr); int64_t plugin_get_clock(void); +void plugin_lockstep_cb(void); #else /* !CONFIG_PLUGINS */ @@ -237,6 +239,9 @@ static inline void qemu_plugin_add_dyn_cb_arr(struct qemu_plugin_dyn_cb_arr *arr) { } +static inline void plugin_lockstep_cb(void) +{ } + int64_t plugin_get_clock(void); #endif /* !CONFIG_PLUGINS */ diff --git a/cpus.c b/cpus.c index a446632a5c..8f490d1b11 100644 --- a/cpus.c +++ b/cpus.c @@ -1359,6 +1359,7 @@ static void lockstep_check_stop(CPUState *cpu) /* wake up all waiting cpus */ lockstep_ongoing_wakeup = true; n_lockstep_running_cpus = n_lockstep_cpus; + plugin_lockstep_cb(); qemu_mutex_unlock(&lockstep_lock); cpu_mutex_unlock(cpu); for (i = 0; i < n_lockstep_cpus; i++) { diff --git a/plugin.c b/plugin.c index 291767f2bb..117f303249 100644 --- a/plugin.c +++ b/plugin.c @@ -472,6 +472,7 @@ static void plugin_cb__simple(enum qemu_plugin_event ev) switch (ev) { case QEMU_PLUGIN_EV_FLUSH: + case QEMU_PLUGIN_EV_LOCKSTEP: QLIST_FOREACH_SAFE_RCU(cb, &plugin.cb_lists[ev], entry, next) { qemu_plugin_simple_cb_t func = cb->f.simple; @@ -1043,6 +1044,40 @@ int64_t plugin_get_clock(void) } #endif +/* + * We manage the CPU state changes; the plugin will control the length of the + * execution windows. + */ +void qemu_plugin_enable_lockstep_execution(void) +{ +#ifdef CONFIG_USER_ONLY + abort(); +#else + cpu_lockstep_enable(); +#endif +} + +void qemu_plugin_end_time_slice(void) +{ +#ifdef CONFIG_USER_ONLY + abort(); +#else + g_assert(current_cpu); + cpu_lockstep_request_stop(current_cpu); +#endif +} + +void qemu_plugin_register_lockstep_cb(qemu_plugin_id_t id, + qemu_plugin_simple_cb_t cb) +{ + plugin_register_cb(id, QEMU_PLUGIN_EV_LOCKSTEP, cb); +} + +void plugin_lockstep_cb(void) +{ + plugin_cb__simple(QEMU_PLUGIN_EV_LOCKSTEP); +} + static void __attribute__((__constructor__)) plugin_init(void) { int i; diff --git a/qemu-plugins.symbols b/qemu-plugins.symbols index 93587b07e1..a3268a40c7 100644 --- a/qemu-plugins.symbols +++ b/qemu-plugins.symbols @@ -1,5 +1,8 @@ { qemu_plugin_uninstall; + qemu_plugin_enable_lockstep_execution; + qemu_plugin_end_time_slice; + qemu_plugin_register_lockstep_cb; qemu_plugin_register_vcpu_init_cb; qemu_plugin_register_vcpu_exit_cb; qemu_plugin_register_vcpu_idle_cb; From patchwork Thu Oct 25 17:20:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656283 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 B985E13B5 for ; Thu, 25 Oct 2018 17:46:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A59142C277 for ; Thu, 25 Oct 2018 17:46:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98C312C291; Thu, 25 Oct 2018 17:46:03 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F3E5B2C277 for ; Thu, 25 Oct 2018 17:46:02 +0000 (UTC) Received: from localhost ([::1]:56128 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjhq-0004KN-7D for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:46:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40419) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKi-0006hz-Mw for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKh-0000PX-EJ for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:08 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:35403) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKf-0000Db-0J for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:06 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id C69EB22237; Thu, 25 Oct 2018 13:21:17 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=Z1x/zdp+0kPaBhrjJuPKkVMYOi2ZXqSST6hzA2VY/VE=; b=U5Sr7 s/T7Q1sp8AgymLsiaqOW28G1T70x2d0zL6UFOYQ7mJDvbWhTWR3QiiwNocRyzioj PPIdDgEPzhZ/5J0SKmT2EQASw8/Igga01Ba9OtTGfR8XTZu46KJWQC6wdO8OmzON K5Iwpab67bDL+bhiCwl+EwbL15yEnBgeCKJUjo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=Z1x/zdp+0kPaBhrjJuPKkVMYOi2ZX qSST6hzA2VY/VE=; b=Gw1+zP1x2Bw+bHLk261fQH9263FYQTvO0XzdpyU7FHqOb ZkxXaLP+R6MJ3l3JL25TitpJICbnB1VLR0XBiKR4CwyOtunwHDo76tWf7FyOcA0C d36vbDi1ILmb/Atjks9DSWfpUmu+eHPvR+FzpqDvMx8Jj2oH5L282C+0/6iY6DLD GkrimLzJCwfA1ISf3wtBTOBtGqgxx/Gt5nXtlVWSuj4/mS1AMS6GMbXBiCJ8gf3P m6S5fSmxadoUkv/dyzuOOpEySJ4N5QD6bAZWyrQqM+u9uQgTl2JdprTVu7vfmg6c c3uzWXFArOT+5E2epc/lNC46KErlgBCGLBSx0dV4A== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 751CEE4897; Thu, 25 Oct 2018 13:21:17 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:55 -0400 Message-Id: <20181025172057.20414-47-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 46/48] plugin: add plugin-chan PCI device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This will allow communication between guest and plugins. Signed-off-by: Emilio G. Cota --- Makefile.target | 2 + include/hw/pci/pci.h | 2 + include/qemu/plugin.h | 1 + hw/plugin/plugin-chan.c | 136 ++++++++++++++++++++++++++++++++++++++++ plugin.c | 4 ++ 5 files changed, 145 insertions(+) create mode 100644 hw/plugin/plugin-chan.c diff --git a/Makefile.target b/Makefile.target index 75637c285c..719699696d 100644 --- a/Makefile.target +++ b/Makefile.target @@ -156,6 +156,8 @@ else obj-y += hw/$(TARGET_BASE_ARCH)/ endif +obj-$(CONFIG_PLUGINS) += hw/plugin/plugin-chan.o + GENERATED_FILES += hmp-commands.h hmp-commands-info.h endif # CONFIG_SOFTMMU diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index e6514bba23..6878d02254 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -86,6 +86,8 @@ extern bool pci_available; #define PCI_DEVICE_ID_VIRTIO_9P 0x1009 #define PCI_DEVICE_ID_VIRTIO_VSOCK 0x1012 +#define PCI_DEVICE_ID_QEMU_PLUGIN_CHAN 0x10f0 + #define PCI_VENDOR_ID_REDHAT 0x1b36 #define PCI_DEVICE_ID_REDHAT_BRIDGE 0x0001 #define PCI_DEVICE_ID_REDHAT_SERIAL 0x0002 diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index c19071bdbe..f3c18d1032 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -196,6 +196,7 @@ void qemu_plugin_atexit_cb(void); void qemu_plugin_add_dyn_cb_arr(struct qemu_plugin_dyn_cb_arr *arr); int64_t plugin_get_clock(void); void plugin_lockstep_cb(void); +void plugin_chan_xmit(uint32_t cmd, const void *data, size_t size); #else /* !CONFIG_PLUGINS */ diff --git a/hw/plugin/plugin-chan.c b/hw/plugin/plugin-chan.c new file mode 100644 index 0000000000..c0749ce089 --- /dev/null +++ b/hw/plugin/plugin-chan.c @@ -0,0 +1,136 @@ +#include "qemu/osdep.h" +#include "hw/pci/pci.h" +#include "qemu/plugin.h" +#include "qapi/error.h" +#include "qemu/error-report.h" + +#define PLUGIN_CHAN_CFG_BAR 0 +#define PLUGIN_CHAN_CMD_BAR 1 +#define PLUGIN_CHAN_DATA_BAR 2 + +struct plugin_chan_cfg { + uint32_t data_max_len; +}; + +struct plugin_chan { + PCIDevice dev; + MemoryRegion cfg_region; + MemoryRegion cmd_region; + MemoryRegion data_region; + void *data; + size_t data_size; + struct plugin_chan_cfg cfg; +}; + +static uint64_t chan_cfg_read(void *obj, hwaddr addr, unsigned size) +{ + struct plugin_chan *s = obj; + + g_assert(size == 4); + switch (addr) { + case 0: + return s->cfg.data_max_len; + break; + } + g_assert_not_reached(); + return 0; +} + +static void chan_cmd_write(void *obj, hwaddr addr, uint64_t val, unsigned size) +{ + struct plugin_chan *s = obj; + + g_assert(size == 4); + switch (addr) { + case 0: + plugin_chan_xmit(val, s->data_size ? s->data : NULL, s->data_size); + break; + case 4: + s->data_size = val; + break; + default: + g_assert_not_reached(); + } +} + +static const MemoryRegionOps chan_cfg_ops = { + .read = chan_cfg_read, + .endianness = DEVICE_LITTLE_ENDIAN, + .impl = { + .min_access_size = 4, + .max_access_size = 4, + }, +}; + +static const MemoryRegionOps chan_cmd_ops = { + .write = chan_cmd_write, + .endianness = DEVICE_LITTLE_ENDIAN, + .impl = { + .min_access_size = 4, + .max_access_size = 4, + }, +}; + +static void plugin_chan_realize(PCIDevice *pci_dev, Error **errp) +{ + struct plugin_chan *s = DO_UPCAST(struct plugin_chan, dev, pci_dev); + Error *err = NULL; + + s->cfg.data_max_len = 4096; + + pci_set_word(s->dev.config + PCI_COMMAND, + PCI_COMMAND_IO | PCI_COMMAND_MEMORY); + + /* data */ + memory_region_init_ram(&s->data_region, OBJECT(s), "plugin_chan.data", + pow2ceil(s->cfg.data_max_len), &err); + if (err) { + error_propagate(errp, err); + return; + } + pci_register_bar(&s->dev, PLUGIN_CHAN_DATA_BAR, + PCI_BASE_ADDRESS_SPACE_MEMORY, &s->data_region); + s->data = qemu_map_ram_ptr(s->data_region.ram_block, 0); + + /* config */ + memory_region_init_io(&s->cfg_region, OBJECT(s), &chan_cfg_ops, s, + "plugin_chan.cfg", sizeof(struct plugin_chan_cfg)); + pci_register_bar(&s->dev, PLUGIN_CHAN_CFG_BAR, + PCI_BASE_ADDRESS_SPACE_MEMORY, &s->cfg_region); + + /* cmd */ + memory_region_init_io(&s->cmd_region, OBJECT(s), &chan_cmd_ops, s, + "plugin_chan.cmd", 8); + pci_register_bar(&s->dev, PLUGIN_CHAN_CMD_BAR, + PCI_BASE_ADDRESS_SPACE_MEMORY, &s->cmd_region); +} + +static void plugin_chan_class_init(ObjectClass *class, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(class); + PCIDeviceClass *p = PCI_DEVICE_CLASS(class); + + p->realize = plugin_chan_realize; + p->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; + p->device_id = PCI_DEVICE_ID_QEMU_PLUGIN_CHAN; + p->class_id = PCI_CLASS_MEMORY_RAM; + dc->desc = "Plugin communication channel between guest and host"; +} + +static TypeInfo plugin_chan_info = { + .name = "qemu-plugin-chan", + .parent = TYPE_PCI_DEVICE, + .instance_size = sizeof(struct plugin_chan), + .class_init = plugin_chan_class_init, + .interfaces = (InterfaceInfo[]) { + { INTERFACE_CONVENTIONAL_PCI_DEVICE }, + { } + }, +}; + +static void plugin_chan_register_types(void) +{ + type_register_static(&plugin_chan_info); +} + +type_init(plugin_chan_register_types) diff --git a/plugin.c b/plugin.c index 117f303249..2bbc14e2f3 100644 --- a/plugin.c +++ b/plugin.c @@ -1078,6 +1078,10 @@ void plugin_lockstep_cb(void) plugin_cb__simple(QEMU_PLUGIN_EV_LOCKSTEP); } +void plugin_chan_xmit(uint32_t cmd, const void *data, size_t size) +{ +} + static void __attribute__((__constructor__)) plugin_init(void) { int i; From patchwork Thu Oct 25 17:20:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656275 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 0D20814BB for ; Thu, 25 Oct 2018 17:43:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F02B42C29D for ; Thu, 25 Oct 2018 17:43:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E31052C2B4; Thu, 25 Oct 2018 17:43: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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 518BD2C29D for ; Thu, 25 Oct 2018 17:43:12 +0000 (UTC) Received: from localhost ([::1]:56121 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjf4-00039r-Vb for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:43:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40456) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKj-0006j1-Bz for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKi-0000QZ-AQ for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:09 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:41187) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKi-0000Fb-3c for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:08 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 15C4D2222D; Thu, 25 Oct 2018 13:21:18 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=i+fXvUzaYM5HOyP4QlU+qVmfBzTAQfhOU7Pi/vvTMEs=; b=PKuNw V4T3/42FmjNiOg9Ms0DbFAnzhOoodrRMQgkaooEUbu+/zqKGicU501P3m3qyehmc NKQ6AwFMd5dJijwIcUKWs25zPoRvcR7AekNvUte4XfhCysO4Xr8Ir+jsgf0l3pJM fBNdLNnwQbTtNMHBSjUfa7iKycC6dE8TzWPS5A= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=i+fXvUzaYM5HOyP4QlU+qVmfBzTAQ fhOU7Pi/vvTMEs=; b=sZH6TRRxWSQN7X3Yh+Dat/9LPNUy/7twgkx+Q/l+Alt8B CmFD8/RcAcB8qPfgaPYF0U0fKRinqUceskwyYgoHPeK/aR9hnM+mRGDpxF1MNdb3 YZlKwtzys88MqKyF/UXOHQYEGjCnJn8TRQxuJCoLgf0WGfhsCrpRXYaGSLUwKKco rXgil68Ug2ISikCPYpNv1rR8O0ylCQQ7SoSxe08xrQswnqE3Y65vYd6F61fmmBdy F8G4nXzjpaEHIkERO9Ll0Ys9K/AVidHkGtva/Ok+K+guaha5CDurBegt/lsEWoWI Gboj7Zj+dzIdnqToP8mmP8lSdMCZOM86/dPE1lizQ== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id AC2ECE455F; Thu, 25 Oct 2018 13:21:17 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:56 -0400 Message-Id: <20181025172057.20414-48-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 47/48] plugin: support guest hooks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP These "hooks" are callbacks from the guest to plugins. This is useful when we need guest-host communication, for instance to signal the beginning/end of a certain "region of interest" in the guest program. Simulators typically would use "magic" instructions for this, but that is painful to maintain across ISAs. Instead, we use plugin-chan PCI device through which we can relay guest messages to the host. Signed-off-by: Emilio G. Cota --- include/qemu/plugin-api.h | 6 ++++++ include/qemu/plugin.h | 2 ++ plugin.c | 13 +++++++++++++ qemu-plugins.symbols | 1 + 4 files changed, 22 insertions(+) diff --git a/include/qemu/plugin-api.h b/include/qemu/plugin-api.h index 5062e20e08..a5faff6a2a 100644 --- a/include/qemu/plugin-api.h +++ b/include/qemu/plugin-api.h @@ -234,6 +234,12 @@ void qemu_plugin_register_lockstep_cb(qemu_plugin_id_t id, void qemu_plugin_end_time_slice(void); +typedef void (*qemu_plugin_hook_cb_t)(uint32_t cmd, const void *data, + size_t size); + +void qemu_plugin_register_hook_cb(qemu_plugin_id_t id, + qemu_plugin_hook_cb_t cb); + /* returns -1 in user-mode */ int qemu_plugin_n_vcpus(void); diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index f3c18d1032..ced265a127 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -61,12 +61,14 @@ enum qemu_plugin_event { QEMU_PLUGIN_EV_LOCKSTEP, QEMU_PLUGIN_EV_FLUSH, QEMU_PLUGIN_EV_ATEXIT, + QEMU_PLUGIN_EV_HOOK, QEMU_PLUGIN_EV_MAX, }; union qemu_plugin_cb_sig { qemu_plugin_simple_cb_t simple; qemu_plugin_udata_cb_t udata; + qemu_plugin_hook_cb_t hook; 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; diff --git a/plugin.c b/plugin.c index 2bbc14e2f3..4004451bdb 100644 --- a/plugin.c +++ b/plugin.c @@ -1078,8 +1078,21 @@ void plugin_lockstep_cb(void) plugin_cb__simple(QEMU_PLUGIN_EV_LOCKSTEP); } +void qemu_plugin_register_hook_cb(qemu_plugin_id_t id, qemu_plugin_hook_cb_t cb) +{ + plugin_register_cb(id, QEMU_PLUGIN_EV_HOOK, cb); +} + void plugin_chan_xmit(uint32_t cmd, const void *data, size_t size) { + struct qemu_plugin_cb *cb, *next; + enum qemu_plugin_event ev = QEMU_PLUGIN_EV_HOOK; + + QLIST_FOREACH_SAFE_RCU(cb, &plugin.cb_lists[ev], entry, next) { + qemu_plugin_hook_cb_t func = cb->f.hook; + + func(cmd, data, size); + } } static void __attribute__((__constructor__)) plugin_init(void) diff --git a/qemu-plugins.symbols b/qemu-plugins.symbols index a3268a40c7..2e17693da8 100644 --- a/qemu-plugins.symbols +++ b/qemu-plugins.symbols @@ -31,6 +31,7 @@ qemu_plugin_mem_is_big_endian; qemu_plugin_mem_is_store; qemu_plugin_vcpu_for_each; + qemu_plugin_register_hook_cb; qemu_plugin_n_vcpus; qemu_plugin_n_max_vcpus; }; From patchwork Thu Oct 25 17:20:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10656269 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 830D417DE for ; Thu, 25 Oct 2018 17:40:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 700472C29B for ; Thu, 25 Oct 2018 17:40:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 642802C294; Thu, 25 Oct 2018 17:40:18 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D1C8D2C29B for ; Thu, 25 Oct 2018 17:40:17 +0000 (UTC) Received: from localhost ([::1]:56111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjcH-00087j-5d for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 13:40:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40556) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKm-0006mD-Q3 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjKk-0000Sr-00 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:12 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:36425) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjKj-0000Fa-Oz for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:09 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 4187D2221C; Thu, 25 Oct 2018 13:21:18 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=0rGxpgjZDCD3/+qCLPmFZWluORjN0xaoJLWO5RaPgwA=; b=ukqt+ hu4NyWgTTwDhNIVglTkCy1GSbx+ut+As5Dvu5LFSKnIPuFhL4jd5M80biZrRVuqy EyM7gODIvBTiwD3VxO73eVVvEJHEqStf1Du85vAi3BPNTHsZKiz+VRAQAbUswpRZ ngvJFRWtvtftjRkzruOSr5M7tCHJoGmEjAkVKQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=0rGxpgjZDCD3/+qCLPmFZWluORjN0 xaoJLWO5RaPgwA=; b=nOEj3gz5EDBNBUtxQDLUB3CT3bfJHKBoPeBb/G97mG6QL 3oOayUI175Ol5d9epzUebNv3GLTuoOeCIO8rKM0kQSTntIjPGY5QvKUQ9OIICjBl RIMlYVSxO/zm//MzDxFxy6vYmrMK5gsOl1Cr5kearLnvT5mYmFZBJW+YKlrdGVks skQoWnaB7BnNviBS8aLxgofYDGqgohHJntgb9AHJz8UHx0o8Jy7QY7k4IAMJLuzr cPB/xAKp3j6p6JclkQOzpVxxiBuvJGRfEk8I88RjYyf44Rg+IY8+4wx4a+4yF0sr M/U5xxmkFfjO1QxsKUHyi/NMdv5pX5DunrvRgMvfQ== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id DC2B1E4074; Thu, 25 Oct 2018 13:21:17 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:57 -0400 Message-Id: <20181025172057.20414-49-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 48/48] plugin: add a couple of very simple examples X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Llu=C3=ADs?= =?utf-8?q?_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi 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: Emilio G. Cota --- plugin-examples/bbcount_avgsize_racy.c | 50 ++++++++++++++++++++++ plugin-examples/mem_count_racy_both.c | 58 ++++++++++++++++++++++++++ plugin-examples/Makefile | 31 ++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 plugin-examples/bbcount_avgsize_racy.c create mode 100644 plugin-examples/mem_count_racy_both.c create mode 100644 plugin-examples/Makefile diff --git a/plugin-examples/bbcount_avgsize_racy.c b/plugin-examples/bbcount_avgsize_racy.c new file mode 100644 index 0000000000..ccdf96c1fa --- /dev/null +++ b/plugin-examples/bbcount_avgsize_racy.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include +#include + +#include + +static uint64_t bb_count; +static uint64_t insn_count; +const char *filename; +static int stdout_fd; + +static void plugin_exit(qemu_plugin_id_t id, void *p) +{ + dprintf(stdout_fd, "insns: %" PRIu64", bb: %" PRIu64 ", " + "avg insns/bb: %.2f\n", + insn_count, bb_count, (double)insn_count / bb_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, unsigned int cpu_index, + struct qemu_plugin_tb *tb) +{ + unsigned long n_insns = qemu_plugin_tb_n_insns(tb); + + 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) +{ + /* 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; +} diff --git a/plugin-examples/mem_count_racy_both.c b/plugin-examples/mem_count_racy_both.c new file mode 100644 index 0000000000..a47f2025bf --- /dev/null +++ b/plugin-examples/mem_count_racy_both.c @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include +#include + +#include + +static uint64_t mem_count; +static int stdout_fd; +static bool do_inline; + +static void plugin_exit(qemu_plugin_id_t id, void *p) +{ + dprintf(stdout_fd, "accesses: %" PRIu64 "\n", mem_count); +} + +static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, + uint64_t vaddr, void *udata) +{ + mem_count++; +} + +static void vcpu_tb_trans(qemu_plugin_id_t id, unsigned int cpu_index, + 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, + QEMU_PLUGIN_INLINE_ADD_U64, + &mem_count, 1); + } else { + qemu_plugin_register_vcpu_mem_cb(insn, vcpu_mem, + QEMU_PLUGIN_CB_NO_REGS, NULL); + } + } +} + +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; + } + /* 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; +} diff --git a/plugin-examples/Makefile b/plugin-examples/Makefile new file mode 100644 index 0000000000..71bbcda7a8 --- /dev/null +++ b/plugin-examples/Makefile @@ -0,0 +1,31 @@ +NAMES := +NAMES += bbcount_avgsize_racy +NAMES += mem_count_racy_both + +SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES))) + +# QEMU installed path, set by --prefix during configure +QEMU_PATH ?= /data/src/qemu-inst/plugin-test + +CC := gcc +CFLAGS := +CFLAGS += -O2 -Werror -Wall +CFLAGS += -Wundef -Wwrite-strings -Wmissing-prototypes +CFLAGS += -Wstrict-prototypes -Wredundant-decls +CFLAGS += -fno-strict-aliasing -fno-common -fwrapv +CFLAGS += -I$(QEMU_PATH)/include +LDLIBS := -lc + +all: $(SONAMES) + +%.o: %.c + $(CC) $(CFLAGS) -fPIC -c $< -o $@ + +lib%.so: %.o + $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDLIBS) + +clean: + $(RM) -f *.o *.so + $(RM) -Rf .libs + +.PHONY: all clean