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: 989258 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=braap.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=braap.org header.i=@braap.org header.b="PKuNwV4T"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="sZH6TRRx"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42gvb80CThz9sDF for ; Fri, 26 Oct 2018 04:42:27 +1100 (AEDT) Received: from localhost ([::1]:56115 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjeK-0000nE-4l for incoming@patchwork.ozlabs.org; Thu, 25 Oct 2018 13:42:24 -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_Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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; };