From nobody Sat Feb 7 06:49:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1750349870; cv=none; d=zohomail.com; s=zohoarc; b=HN7ksnra0ikv/Gz2mQgENlcc1OH/ivqpm4alA+q0e00aD2PbrAQm8z33J1dantAGlRSjA1q6FF+xRF5OVwlSbsRT1oWnjpppcaipxCbrALLeLdXFVeLXQtp+n7vTXp7OQ7zaBAaHUrghwd14vR4FPBV2gp2tYp7gBW58YrpSBqM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750349870; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XnnF1uBpsF7ta/mg2wqDkU618epFEeVBHaFGc0cQD7o=; b=cTW60PU7XJKl4QRC//RWVtii3NKVmgNjxaUKJ9uHNxGuV3T7bKwcKMCCARqHLm55L3kjjSwmtO7hgCmOyyLE8VAuhBlzqmMSR3Mz87uWV7hQIbGf51sofP4uZ6J6IGuN2m0Ro5HJ7c5HCooQkEk1fRqdnilhGpPzGFWbKS0In4A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17503498705190.9127237098148271; Thu, 19 Jun 2025 09:17:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uSHwQ-0001eY-US; Thu, 19 Jun 2025 12:16:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uSHvk-0001Lw-3J for qemu-devel@nongnu.org; Thu, 19 Jun 2025 12:16:01 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uSHve-0003f4-2c for qemu-devel@nongnu.org; Thu, 19 Jun 2025 12:15:55 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-7426c44e014so771484b3a.3 for ; Thu, 19 Jun 2025 09:15:51 -0700 (PDT) Received: from shemhazi.lan ([50.46.174.34]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b2fe168a0f8sm13168683a12.53.2025.06.19.09.15.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jun 2025 09:15:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750349750; x=1750954550; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XnnF1uBpsF7ta/mg2wqDkU618epFEeVBHaFGc0cQD7o=; b=QRN3uxCzweuiGqpBjnzPUv4cd3jCOVnBjUqqAJfWaAn1JovTn8hgOolPzxtXuHiV70 UElhHYt7+4jHqDR7wrQK+b89mHGPsCtRyloaxnvMcsZfpHLykTkb1uwM7/9F+f9oMKDz 1qrVZH1L6rOpF6f/g14uLdUN/OUo+JHBrnLdoQ0IvUmBJN5OWCCejWoZRnZz43QFTa7n lzhLIML83NdTMP3TWb9KdkrGdSUHs6ywpzIUuA6fDhtag/GWmjViIyOJOGFHsVmjn7j3 7lPLy2h35MTYu5aFJeWsdhGlKKElalWEyQwhAVp0tmx3ZylTSi7PLHiRtVtI7otwVJlP R3nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750349750; x=1750954550; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XnnF1uBpsF7ta/mg2wqDkU618epFEeVBHaFGc0cQD7o=; b=hUvJxPABtXJpYnL5QuGztKOQE+eqLl53WfwotZsMRcJ0q57OhDe00meJSQpUFpJv3Q evpTitKM9uBs9w8qTgKBy/+MDgLxhZzRUn37RXINooclBNQbpZ4VKRLkpxNKwEfEB7Bs iE9vuxu5nNFODeP5BpAzITcaSjjpUuMtlRXBu+7X5KxsNonM1l3oV6gwkcZgboJyCKKC YcVADZC3E+kKkZD8dmSJ2I0Eaj5vdEAwfaalb3ZNjTuylhWxrrpmZZFFOqlzV1ArUtBB +lhHqsKPjOxeYh4MA0iTxh+1BPaYYjc2jkztGaQTRSpweZLGwprlsbMI6xlNfj9FvWh0 LVlA== X-Gm-Message-State: AOJu0Yx95sk710yZrQq2qZtP2WyOvHhNmQnBWyR1PsfxtUJb0SJHPXQN fGABZ+fHEiG44tfsRnYcBQhfkluP4m+4pkW+kabbpnMFkhwPRuANbQCA1LawLIw5 X-Gm-Gg: ASbGncvXAullPeFDfkuaWJ8y9bceHP778pZSgjh7QDEbE1R8E1HYvbzMqG+WleAHQew gpaXj73nxDZPUZbUmGBZ4y25CGBJyNnfylc36CCI0Ebtxjz6PdEH9wKrfslZbkvhIuxOAWDqfmN KOX8hPOZp34BPG7ReSzYy+ZiT3o0LR6Hhxre18P1IDOCxYikgpKMf/ooV9LfUdYv4TB+lWoNUDm GfOWinpzvKxfirXq9NlmA5CB/kgdbiO48TLOwsRbGeSCnbWMW7BIHqQ+gojIA558Bs9LsqVxGLu t6BVz+csgGulz/n9MYzI6ymW86eAYBPZBnYbVCO3aRrRkG+2WzZVv2xgZ2L84A== X-Google-Smtp-Source: AGHT+IE/ZACCaeGyRq3zAtvfBllf80bmDiE4INglf/AYah9hB/4PoqjqSaKSUC9A/VDTajLrEc/lLA== X-Received: by 2002:a05:6a00:10d2:b0:748:fd94:e62a with SMTP id d2e1a72fcca58-748fd94edb7mr3492345b3a.1.1750349750053; Thu, 19 Jun 2025 09:15:50 -0700 (PDT) From: Rowan Hart To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Marcel Apfelbaum , Zhao Liu , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , Mahmoud Mandour , Paolo Bonzini , novafacing , Julian Ganz Subject: [PATCH v13 1/7] gdbstub: Expose gdb_write_register function to consumers of gdbstub Date: Thu, 19 Jun 2025 09:15:41 -0700 Message-ID: <20250619161547.1401448-2-rowanbhart@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250619161547.1401448-1-rowanbhart@gmail.com> References: <20250619161547.1401448-1-rowanbhart@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=rowanbhart@gmail.com; helo=mail-pf1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1750349872297116600 From: novafacing This patch exposes the gdb_write_register function from gdbstub/gdbstub.c via the exec/gdbstub.h header file to support use in plugins to write register contents. Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Julian Ganz Reviewed-by: Pierrick Bouvier Signed-off-by: Rowan Hart --- gdbstub/gdbstub.c | 2 +- include/exec/gdbstub.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index def0b7e877..dd5fb5667c 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -535,7 +535,7 @@ int gdb_read_register(CPUState *cpu, GByteArray *buf, i= nt reg) return 0; } =20 -static int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg) +int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg) { GDBRegisterState *r; =20 diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 0675b0b646..a16c0051ce 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -124,6 +124,20 @@ const GDBFeature *gdb_find_static_feature(const char *= xmlname); */ int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); =20 +/** + * gdb_write_register() - Write a register associated with a CPU. + * @cpu: The CPU associated with the register. + * @buf: The buffer that the register contents will be set to. + * @reg: The register's number returned by gdb_find_feature_register(). + * + * The size of @buf must be at least the size of the register being + * written. + * + * Return: The number of written bytes, or 0 if an error occurred (for + * example, an unknown register was provided). + */ +int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg); + /** * typedef GDBRegDesc - a register description from gdbstub */ --=20 2.49.0 From nobody Sat Feb 7 06:49:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1750349825; cv=none; d=zohomail.com; s=zohoarc; b=P93QuQBmKzvgKY1DXEj91814Q+eoQhrW24iRH00Yd79ydX+IADnKwp9he6Al579SuORQ9Lck/QoXB2KviAlYXwVIaoutUmfGW9UbzfmP4EtzmMEqtlzhgdXp8MJtcIm84dqjE+6rxp5AbMpwIOTXQTSj1cKyi+h2lMgKhKGVO8U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750349825; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DkzAOT9KPhbXdwiYkwrjtSXHJRVHCh65cjh/wF+xrzM=; b=GKYt8rU0ayu2XhOcWa6Rziqh0+3qItCd6AjichxqLGs5UexKQjho0b9J+kGhgRJ3bhml+U5HUK2McwTHvbywF0/8vydg0iSbPOVY11GgljVIdZifcc0zidMIlLlThrvCIGD6KnYwijwSXW8LYcHNJNDpZPBd2tWqtAmH6KVEkQM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1750349825692656.2202043170679; Thu, 19 Jun 2025 09:17:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uSHw6-0001TE-Dt; Thu, 19 Jun 2025 12:16:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uSHvk-0001Ly-6f for qemu-devel@nongnu.org; Thu, 19 Jun 2025 12:16:01 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uSHve-0003fC-4c for qemu-devel@nongnu.org; Thu, 19 Jun 2025 12:15:57 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-748f54dfa5fso647839b3a.2 for ; Thu, 19 Jun 2025 09:15:52 -0700 (PDT) Received: from shemhazi.lan ([50.46.174.34]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b2fe168a0f8sm13168683a12.53.2025.06.19.09.15.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jun 2025 09:15:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750349751; x=1750954551; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DkzAOT9KPhbXdwiYkwrjtSXHJRVHCh65cjh/wF+xrzM=; b=EywmehJNO78IOKRiqcuHFNqd0UiowlJ0igRkyR8hT8Ocv/lp+iSqwas+FL6gZ2UpXG TIs8Kl96Gh28F3AT7CXeW/NwijSD6v1NH0aUPT+Gy80OdmfpEW6wu70v94iT9s7Nql7J qrKvW22aoxZPZmomLeymyy2OoWtOVSGsBGHT96TUtk+4AOXz9vShsu3sQLTF6NpQqtqd MJX9Ixc+bo9BU/H0ErNaTYGbvd7QFSTcxtCB8BoKsi3K7PbuVKMM1UL7vf7ce66ZJjlL qC/N8uSR/jeBsS4qMDuP8D837ZV7oE1YM0xtHRuAVDiK+/MZ7i47qmD+ym2joZmbGG42 +09A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750349751; x=1750954551; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DkzAOT9KPhbXdwiYkwrjtSXHJRVHCh65cjh/wF+xrzM=; b=YjYTZeOmJ99f4s/UFg3RCyKkmyKb3QU1W+Lhvx3SHhMNTiReqic8zcMbTVNr66s0ZS t8GcoN5MRwErfaGJiRNEjBvNvNqw8kw0n2ieS8T41H/h8M+vQmw2sYq+Z7d2QOsxjK3P whPnFSkgutjG0yUfHbxe/P3lPe21SGJGPs3E4oE4orsd40mb2Vtyt32LM7hw8ZDNI4k2 grgun1JQeLTDH0MOIEuFUV5o7l1fCiD3H6dB7uflVbPkBg1ocOm7bB8ueTt28FfcpsAN B3bkSxIlGtcV/Ihhx6xbQBft/Uc+lDThHXNt5VynjvMXt6/DpCWoq4nQrGDVlZ+CEx5I xLNw== X-Gm-Message-State: AOJu0YyCOIVzxL9AwgWpAnrfoTAN+is5FS+jsV6ZxqaKU1LvKTbZN3LZ BYf6UVal64L/u12pcxO0s3HNqswZKf8wkK3j+DPGPCHfHpFaKs4R32kfoJjljfKE X-Gm-Gg: ASbGncvEYMGFolgPB4/eP2r10MRH5zemJuIqwqnfLBRGVBD1qO903USs/5V5xPuGBvB p2C44JNYPJY0wmUJchk3o02CfZTT5rBk8SmKiGjGGxkuSWoidz+bwwEj57NjRwK1b1tjepDEqZd tyvapC4mARjY7cI76g/yp7JdIUMCMIJJ3vp7Nvf0h5/l7b5oMQnZTD50ndrsW6T9n+OQEJ/OJ1c M9EU1HZ3cowrD0k3086JWKimkL3BYPt20Gt5Y4otrMLN8ZOCz3oRN4TMkwJQF517coAoC6Xadsw Z+dnDTry+V8IWXBKV02YHJ/ZeLV33gHqbi9oiUIjOHB+RSwyAc0x01CW6ykhTA== X-Google-Smtp-Source: AGHT+IGfmKRAcxgMCCrjJjYIiwGt1ZCbh3Xw5MIbPZyzpwKdYuhN4VDcdttnTo5zI/54yeFv4rIurA== X-Received: by 2002:a05:6a21:48b:b0:1f5:6c94:2cd7 with SMTP id adf61e73a8af0-21fbd6927e2mr33394430637.42.1750349751017; Thu, 19 Jun 2025 09:15:51 -0700 (PDT) From: Rowan Hart To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Marcel Apfelbaum , Zhao Liu , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , Mahmoud Mandour , Paolo Bonzini , novafacing Subject: [PATCH v13 2/7] plugins: Add register write API Date: Thu, 19 Jun 2025 09:15:42 -0700 Message-ID: <20250619161547.1401448-3-rowanbhart@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250619161547.1401448-1-rowanbhart@gmail.com> References: <20250619161547.1401448-1-rowanbhart@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=rowanbhart@gmail.com; helo=mail-pf1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1750349827905116600 Content-Type: text/plain; charset="utf-8" From: novafacing This patch adds a function to the plugins API to allow plugins to write register contents. It also moves the qemu_plugin_read_register function so all the register-related functions are grouped together in the file. Reviewed-by: Pierrick Bouvier Signed-off-by: Rowan Hart --- include/qemu/qemu-plugin.h | 54 ++++++++++++++++++++++++++------------ plugins/api.c | 26 +++++++++++++----- 2 files changed, 56 insertions(+), 24 deletions(-) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 3a850aa216..cfe1692ecb 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -871,7 +871,8 @@ struct qemu_plugin_register; /** * typedef qemu_plugin_reg_descriptor - register descriptions * - * @handle: opaque handle for retrieving value with qemu_plugin_read_regis= ter + * @handle: opaque handle for retrieving value with qemu_plugin_read_regis= ter or + * writing value with qemu_plugin_write_register * @name: register name * @feature: optional feature descriptor, can be NULL */ @@ -893,6 +894,41 @@ typedef struct { QEMU_PLUGIN_API GArray *qemu_plugin_get_registers(void); =20 +/** + * qemu_plugin_read_register() - read register for current vCPU + * + * @handle: a @qemu_plugin_reg_handle handle + * @buf: A GByteArray for the data owned by the plugin + * + * This function is only available in a context that register read access = is + * explicitly requested via the QEMU_PLUGIN_CB_R_REGS flag. + * + * Returns the size of the read register. The content of @buf is in target= byte + * order. On failure returns -1. + */ +QEMU_PLUGIN_API +int qemu_plugin_read_register(struct qemu_plugin_register *handle, + GByteArray *buf); + +/** + * qemu_plugin_write_register() - write register for current vCPU + * + * @handle: a @qemu_plugin_reg_handle handle + * @buf: A GByteArray for the data owned by the plugin + * + * This function is only available in a context that register write access= is + * explicitly requested via the QEMU_PLUGIN_CB_RW_REGS flag. + * + * The size of @buf must be at least the size of the requested register. + * Attempting to write a register with @buf smaller than the register size + * will result in a crash or other undesired behavior. + * + * Returns the number of bytes written. On failure returns 0. + */ +QEMU_PLUGIN_API +int qemu_plugin_write_register(struct qemu_plugin_register *handle, + GByteArray *buf); + /** * qemu_plugin_read_memory_vaddr() - read from memory using a virtual addr= ess * @@ -915,22 +951,6 @@ QEMU_PLUGIN_API bool qemu_plugin_read_memory_vaddr(uint64_t addr, GByteArray *data, size_t len); =20 -/** - * qemu_plugin_read_register() - read register for current vCPU - * - * @handle: a @qemu_plugin_reg_handle handle - * @buf: A GByteArray for the data owned by the plugin - * - * This function is only available in a context that register read access = is - * explicitly requested via the QEMU_PLUGIN_CB_R_REGS flag. - * - * Returns the size of the read register. The content of @buf is in target= byte - * order. On failure returns -1. - */ -QEMU_PLUGIN_API -int qemu_plugin_read_register(struct qemu_plugin_register *handle, - GByteArray *buf); - /** * qemu_plugin_scoreboard_new() - alloc a new scoreboard * diff --git a/plugins/api.c b/plugins/api.c index 3c9d4832e9..6514f2c76a 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -433,6 +433,25 @@ GArray *qemu_plugin_get_registers(void) return create_register_handles(regs); } =20 +int qemu_plugin_read_register(struct qemu_plugin_register *reg, GByteArray= *buf) +{ + g_assert(current_cpu); + + return gdb_read_register(current_cpu, buf, GPOINTER_TO_INT(reg) - 1); +} + +int qemu_plugin_write_register(struct qemu_plugin_register *reg, + GByteArray *buf) +{ + g_assert(current_cpu); + + if (buf->len =3D=3D 0 || qemu_plugin_get_cb_flags() !=3D QEMU_PLUGIN_C= B_RW_REGS) { + return -1; + } + + return gdb_write_register(current_cpu, buf->data, GPOINTER_TO_INT(reg)= - 1); +} + bool qemu_plugin_read_memory_vaddr(uint64_t addr, GByteArray *data, size_t= len) { g_assert(current_cpu); @@ -453,13 +472,6 @@ bool qemu_plugin_read_memory_vaddr(uint64_t addr, GByt= eArray *data, size_t len) return true; } =20 -int qemu_plugin_read_register(struct qemu_plugin_register *reg, GByteArray= *buf) -{ - g_assert(current_cpu); - - return gdb_read_register(current_cpu, buf, GPOINTER_TO_INT(reg) - 1); -} - struct qemu_plugin_scoreboard *qemu_plugin_scoreboard_new(size_t element_s= ize) { return plugin_scoreboard_new(element_size); --=20 2.49.0 From nobody Sat Feb 7 06:49:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1750349820; cv=none; d=zohomail.com; s=zohoarc; b=N7WFelI5YIzfzkP8toWrW9ekwz4ebxKo6xNuAJ4T1+XNbgpsnV5ONf4ZA0TRrNSwoo+06M9O1ERWcDUXoDPY6zFM7pOb9jVIUkAE9UAalrSFIjwylhe3oqM4cqfLAq13/OPX3RjgSMqiAn5DYt84rnBTYxVFd1QbyktR+Xw0NgY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750349820; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=m7zN4lzjHX97r8bgkj2U9G9NZtqeOC5YwH/K0eCJa2k=; b=KqW+UVLxOF9IMxiD+T1RM3jR1TLHiTmCFATO1p0siaC9qgnpqdnNkV5qZ0aSdlcbKa+CbQdkIx+KynUfW0iEXi3tEUqUTkdt8BnkDqbFUHtYUsFTcjlyS8E+McB85Ih4aXMDViGcolO+egLxU45ryZl0P9KLP7Mq5hVbiufb8mA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1750349820745650.9644329639665; Thu, 19 Jun 2025 09:17:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uSHwL-0001Y7-Jb; Thu, 19 Jun 2025 12:16:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uSHvk-0001Lv-33 for qemu-devel@nongnu.org; Thu, 19 Jun 2025 12:16:01 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uSHve-0003fI-31 for qemu-devel@nongnu.org; Thu, 19 Jun 2025 12:15:56 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-739b3fe7ce8so643401b3a.0 for ; Thu, 19 Jun 2025 09:15:53 -0700 (PDT) Received: from shemhazi.lan ([50.46.174.34]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b2fe168a0f8sm13168683a12.53.2025.06.19.09.15.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jun 2025 09:15:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750349752; x=1750954552; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=m7zN4lzjHX97r8bgkj2U9G9NZtqeOC5YwH/K0eCJa2k=; b=mwN31WqEBu6UbQh4QOxA/VVktQ+SZ5CxYjBAhSCJmaGofF/lFoe+ogmmP6iTzTAdHa 37jPX+Yrpw1hhsPrwhNmyu+i2kBdd3jyD9Y2mzH/A7l4wRsYlgfgL95tdzdQAXfarlhF 3GKBzJUc3aapXBfip4Ac1FOAIBrWilPX1xabN6wvGtszzuETCDj2vHxGTZ0bGJBOlNpJ o153DrKNqaD1TRQj9+ECHngWod2Ate92Tw/XZgzDhgnLTEviJofI2mS2H2CphM9ebDEP /8uLOtMf1FOlVVz1TH553T4HkFH4xN2NaBDIUw7Ft/WI0CqFP+A8vzCz03FJOTLgK9mz wP4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750349752; x=1750954552; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m7zN4lzjHX97r8bgkj2U9G9NZtqeOC5YwH/K0eCJa2k=; b=U1lC2YBbCKRYcw5cjCkH8xYNll/thBEy5OQ4D5/NZYweipLQpbsBi7LtH3s0+TphnC 5zh5OZqypIUZWg5UH92XgFkivpg6kehlyo/iHU2lSJSqUG87uAlsGDjfzdigab2pCd5P aSDOvbyfSmCGaRr27UUUI2U7WgYv6JOOTIJ75xQXd67n4nXbBEJjY3+LRnmBsXn7t3U8 XlOIYuxcuS0At17+CcPBuRbfx56ZalcDBW8EAaR5nMHXk0aOKjMxQlaaarqr4815Kuun 89APumEdwaou67x7hokegS0jlIgIizYjLKfnf8gwwNz3lBpnfvHulCBH577gOnIX85x6 y2Ag== X-Gm-Message-State: AOJu0Yy6sZDAw7nh80X7+jMXAQFGZEhYEPZNUVFRXYHPM9TXsfDW93VH XIiRuZ2muC58sH5IC3OdfqsbnYQaYY77pDRioSVteqdDtD/eoFaSbtBQko5NKnw6 X-Gm-Gg: ASbGncvyUpH4qUFsxtecqpwtakgCuCmeZrdGQimmBK3H3YIiaysLikzXYa4ttnicBdv rRcfOg/qs1ES3unCr0pENHo1UrF276G7RWypPxt0rBvYJgEfxR90lcUEg1II5FyxKNOUX6SHwCd fVUCQlF6vOREQ+qyEUMGk5Pvvc5KUtwAJr9XwvkCZ1qpYqlHfdcbWQBBot5roc2OuzICPtr+hvK rfQiFr/0blKYXcnCqBlxaLVVKABkQnn/AvlIerY5+nlz9N/ovUEcBmYuG9aro4iWQQyLBV783re r4mAj9UERNPB0ItyXkavm9rLySe+zTkYZKClT9x8I/sLpaII1a2iXbRHn9KJ3UpNZOH/aQ0y X-Google-Smtp-Source: AGHT+IEP5hQ1XF0HvbMkjwZOtOHsz/vvyVBGBrCc8zIwL5zYeVAHwgJgQwtQ/CQ/6wHO4MZt8Ht1xQ== X-Received: by 2002:a05:6a00:14c2:b0:748:2e1a:84e3 with SMTP id d2e1a72fcca58-7489ce0c6bbmr36340091b3a.8.1750349751843; Thu, 19 Jun 2025 09:15:51 -0700 (PDT) From: Rowan Hart To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Marcel Apfelbaum , Zhao Liu , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , Mahmoud Mandour , Paolo Bonzini , Rowan Hart Subject: [PATCH v13 3/7] plugins: Add enforcement of QEMU_PLUGIN_CB flags in register R/W callbacks Date: Thu, 19 Jun 2025 09:15:43 -0700 Message-ID: <20250619161547.1401448-4-rowanbhart@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250619161547.1401448-1-rowanbhart@gmail.com> References: <20250619161547.1401448-1-rowanbhart@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=rowanbhart@gmail.com; helo=mail-pf1-x429.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1750349822148116600 Content-Type: text/plain; charset="utf-8" This patch adds functionality to enforce the requested QEMU_PLUGIN_CB_ flags level passed when registering a callback function using the plugins API. Each time a callback is about to be invoked, a thread-local variable will be updated with the level that callback requested. Then, called API functions (in particular, the register read and write API) will call qemu_plugin_get_cb_flags() to check the level is at least the level they require. Reviewed-by: Pierrick Bouvier Signed-off-by: Rowan Hart --- accel/tcg/plugin-gen.c | 30 ++++++++++++++++++++++++++++++ include/hw/core/cpu.h | 1 + include/qemu/plugin.h | 15 +++++++++++++++ include/qemu/qemu-plugin.h | 19 +++++++++++++------ plugins/api.c | 4 ++++ plugins/core.c | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 96 insertions(+), 6 deletions(-) diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index c1da753894..9920381a84 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -117,10 +117,20 @@ static TCGv_i32 gen_cpu_index(void) static void gen_udata_cb(struct qemu_plugin_regular_cb *cb) { TCGv_i32 cpu_index =3D gen_cpu_index(); + enum qemu_plugin_cb_flags cb_flags =3D + tcg_call_to_qemu_plugin_cb_flags(cb->info->flags); + TCGv_i32 flags =3D tcg_constant_i32(cb_flags); + TCGv_i32 clear_flags =3D tcg_constant_i32(QEMU_PLUGIN_CB_NO_REGS); + tcg_gen_st_i32(flags, tcg_env, + offsetof(CPUState, neg.plugin_cb_flags) - sizeof(CPUState)); tcg_gen_call2(cb->f.vcpu_udata, cb->info, NULL, tcgv_i32_temp(cpu_index), tcgv_ptr_temp(tcg_constant_ptr(cb->userp))); + tcg_gen_st_i32(clear_flags, tcg_env, + offsetof(CPUState, neg.plugin_cb_flags) - sizeof(CPUState)); tcg_temp_free_i32(cpu_index); + tcg_temp_free_i32(flags); + tcg_temp_free_i32(clear_flags); } =20 static TCGv_ptr gen_plugin_u64_ptr(qemu_plugin_u64 entry) @@ -173,10 +183,20 @@ static void gen_udata_cond_cb(struct qemu_plugin_cond= itional_cb *cb) tcg_gen_ld_i64(val, ptr, 0); tcg_gen_brcondi_i64(cond, val, cb->imm, after_cb); TCGv_i32 cpu_index =3D gen_cpu_index(); + enum qemu_plugin_cb_flags cb_flags =3D + tcg_call_to_qemu_plugin_cb_flags(cb->info->flags); + TCGv_i32 flags =3D tcg_constant_i32(cb_flags); + TCGv_i32 clear_flags =3D tcg_constant_i32(QEMU_PLUGIN_CB_NO_REGS); + tcg_gen_st_i32(flags, tcg_env, + offsetof(CPUState, neg.plugin_cb_flags) - sizeof(CPUState)); tcg_gen_call2(cb->f.vcpu_udata, cb->info, NULL, tcgv_i32_temp(cpu_index), tcgv_ptr_temp(tcg_constant_ptr(cb->userp))); + tcg_gen_st_i32(clear_flags, tcg_env, + offsetof(CPUState, neg.plugin_cb_flags) - sizeof(CPUState)); tcg_temp_free_i32(cpu_index); + tcg_temp_free_i32(flags); + tcg_temp_free_i32(clear_flags); gen_set_label(after_cb); =20 tcg_temp_free_i64(val); @@ -210,12 +230,22 @@ static void gen_mem_cb(struct qemu_plugin_regular_cb = *cb, qemu_plugin_meminfo_t meminfo, TCGv_i64 addr) { TCGv_i32 cpu_index =3D gen_cpu_index(); + enum qemu_plugin_cb_flags cb_flags =3D + tcg_call_to_qemu_plugin_cb_flags(cb->info->flags); + TCGv_i32 flags =3D tcg_constant_i32(cb_flags); + TCGv_i32 clear_flags =3D tcg_constant_i32(QEMU_PLUGIN_CB_NO_REGS); + tcg_gen_st_i32(flags, tcg_env, + offsetof(CPUState, neg.plugin_cb_flags) - sizeof(CPUState)); tcg_gen_call4(cb->f.vcpu_mem, cb->info, NULL, tcgv_i32_temp(cpu_index), tcgv_i32_temp(tcg_constant_i32(meminfo)), tcgv_i64_temp(addr), tcgv_ptr_temp(tcg_constant_ptr(cb->userp))); + tcg_gen_st_i32(clear_flags, tcg_env, + offsetof(CPUState, neg.plugin_cb_flags) - sizeof(CPUState)); tcg_temp_free_i32(cpu_index); + tcg_temp_free_i32(flags); + tcg_temp_free_i32(clear_flags); } =20 static void inject_cb(struct qemu_plugin_dyn_cb *cb) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 33296a1c08..162a56a5da 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -368,6 +368,7 @@ typedef struct CPUNegativeOffsetState { GArray *plugin_mem_cbs; uint64_t plugin_mem_value_low; uint64_t plugin_mem_value_high; + int32_t plugin_cb_flags; #endif IcountDecr icount_decr; bool can_do_io; diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index 9726a9ebf3..f355c7cb8a 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -209,6 +209,21 @@ void qemu_plugin_user_prefork_lock(void); */ void qemu_plugin_user_postfork(bool is_child); =20 +enum qemu_plugin_cb_flags tcg_call_to_qemu_plugin_cb_flags(int flags); + +static inline void qemu_plugin_set_cb_flags(CPUState *cpu, + enum qemu_plugin_cb_flags flag= s) +{ + assert(cpu); + cpu->neg.plugin_cb_flags =3D flags; +} + +static inline enum qemu_plugin_cb_flags qemu_plugin_get_cb_flags(void) +{ + assert(current_cpu); + return current_cpu->neg.plugin_cb_flags; +} + #else /* !CONFIG_PLUGIN */ =20 static inline void qemu_plugin_add_opts(void) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index cfe1692ecb..9c9ebf6ce0 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -254,9 +254,6 @@ typedef struct { * @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 - * - * Note: currently QEMU_PLUGIN_CB_RW_REGS is unused, plugins cannot change - * system register state. */ enum qemu_plugin_cb_flags { QEMU_PLUGIN_CB_NO_REGS, @@ -901,7 +898,12 @@ GArray *qemu_plugin_get_registers(void); * @buf: A GByteArray for the data owned by the plugin * * This function is only available in a context that register read access = is - * explicitly requested via the QEMU_PLUGIN_CB_R_REGS flag. + * explicitly requested via the QEMU_PLUGIN_CB_R_REGS flag, if called insi= de a + * callback that can be registered with a qemu_plugin_cb_flags argument. T= his + * function can also be used in any callback context that does not use a f= lags + * argument, such as in a callback registered with + * qemu_plugin_register_vcpu_init_cb(), except for callbacks registered wi= th + * qemu_plugin_register_atexit_cb() and qemu_plugin_register_flush_cb(). * * Returns the size of the read register. The content of @buf is in target= byte * order. On failure returns -1. @@ -916,8 +918,13 @@ int qemu_plugin_read_register(struct qemu_plugin_regis= ter *handle, * @handle: a @qemu_plugin_reg_handle handle * @buf: A GByteArray for the data owned by the plugin * - * This function is only available in a context that register write access= is - * explicitly requested via the QEMU_PLUGIN_CB_RW_REGS flag. + * This function is only available in a context that register read access = is + * explicitly requested via the QEMU_PLUGIN_CB_RW_REGS flag, if called ins= ide a + * callback that can be registered with a qemu_plugin_cb_flags argument. T= his + * function can also be used in any callback context that does not use a f= lags + * argument, such as in a callback registered with + * qemu_plugin_register_vcpu_init_cb(), except for callbacks registered wi= th + * qemu_plugin_register_atexit_cb() and qemu_plugin_register_flush_cb(). * * The size of @buf must be at least the size of the requested register. * Attempting to write a register with @buf smaller than the register size diff --git a/plugins/api.c b/plugins/api.c index 6514f2c76a..3f04399c26 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -437,6 +437,10 @@ int qemu_plugin_read_register(struct qemu_plugin_regis= ter *reg, GByteArray *buf) { g_assert(current_cpu); =20 + if (qemu_plugin_get_cb_flags() =3D=3D QEMU_PLUGIN_CB_NO_REGS) { + return -1; + } + return gdb_read_register(current_cpu, buf, GPOINTER_TO_INT(reg) - 1); } =20 diff --git a/plugins/core.c b/plugins/core.c index eb9281fe54..6ae5bbc0ef 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -15,6 +15,7 @@ #include "qemu/lockable.h" #include "qemu/option.h" #include "qemu/plugin.h" +#include "qemu/qemu-plugin.h" #include "qemu/queue.h" #include "qemu/rcu_queue.h" #include "qemu/rcu.h" @@ -266,7 +267,9 @@ static void qemu_plugin_vcpu_init__async(CPUState *cpu,= run_on_cpu_data unused) plugin_grow_scoreboards__locked(cpu); qemu_rec_mutex_unlock(&plugin.lock); =20 + qemu_plugin_set_cb_flags(cpu, QEMU_PLUGIN_CB_RW_REGS); plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_INIT); + qemu_plugin_set_cb_flags(cpu, QEMU_PLUGIN_CB_NO_REGS); } =20 void qemu_plugin_vcpu_init_hook(CPUState *cpu) @@ -279,7 +282,9 @@ void qemu_plugin_vcpu_exit_hook(CPUState *cpu) { bool success; =20 + qemu_plugin_set_cb_flags(cpu, QEMU_PLUGIN_CB_RW_REGS); plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_EXIT); + qemu_plugin_set_cb_flags(cpu, QEMU_PLUGIN_CB_NO_REGS); =20 assert(cpu->cpu_index !=3D UNASSIGNED_CPU_INDEX); qemu_rec_mutex_lock(&plugin.lock); @@ -367,6 +372,7 @@ void plugin_register_dyn_cb__udata(GArray **arr, static TCGHelperInfo info[3] =3D { [QEMU_PLUGIN_CB_NO_REGS].flags =3D TCG_CALL_NO_RWG, [QEMU_PLUGIN_CB_R_REGS].flags =3D TCG_CALL_NO_WG, + [QEMU_PLUGIN_CB_RW_REGS].flags =3D 0, /* * Match qemu_plugin_vcpu_udata_cb_t: * void (*)(uint32_t, void *) @@ -396,6 +402,7 @@ void plugin_register_dyn_cond_cb__udata(GArray **arr, static TCGHelperInfo info[3] =3D { [QEMU_PLUGIN_CB_NO_REGS].flags =3D TCG_CALL_NO_RWG, [QEMU_PLUGIN_CB_R_REGS].flags =3D TCG_CALL_NO_WG, + [QEMU_PLUGIN_CB_RW_REGS].flags =3D 0, /* * Match qemu_plugin_vcpu_udata_cb_t: * void (*)(uint32_t, void *) @@ -434,6 +441,7 @@ void plugin_register_vcpu_mem_cb(GArray **arr, static TCGHelperInfo info[3] =3D { [QEMU_PLUGIN_CB_NO_REGS].flags =3D TCG_CALL_NO_RWG, [QEMU_PLUGIN_CB_R_REGS].flags =3D TCG_CALL_NO_WG, + [QEMU_PLUGIN_CB_RW_REGS].flags =3D 0, /* * Match qemu_plugin_vcpu_mem_cb_t: * void (*)(uint32_t, qemu_plugin_meminfo_t, uint64_t, void *) @@ -473,7 +481,9 @@ void qemu_plugin_tb_trans_cb(CPUState *cpu, struct qemu= _plugin_tb *tb) QLIST_FOREACH_SAFE_RCU(cb, &plugin.cb_lists[ev], entry, next) { qemu_plugin_vcpu_tb_trans_cb_t func =3D cb->f.vcpu_tb_trans; =20 + qemu_plugin_set_cb_flags(cpu, QEMU_PLUGIN_CB_RW_REGS); func(cb->ctx->id, tb); + qemu_plugin_set_cb_flags(cpu, QEMU_PLUGIN_CB_NO_REGS); } } =20 @@ -498,7 +508,9 @@ qemu_plugin_vcpu_syscall(CPUState *cpu, int64_t num, ui= nt64_t a1, uint64_t a2, QLIST_FOREACH_SAFE_RCU(cb, &plugin.cb_lists[ev], entry, next) { qemu_plugin_vcpu_syscall_cb_t func =3D cb->f.vcpu_syscall; =20 + qemu_plugin_set_cb_flags(cpu, QEMU_PLUGIN_CB_RW_REGS); func(cb->ctx->id, cpu->cpu_index, num, a1, a2, a3, a4, a5, a6, a7,= a8); + qemu_plugin_set_cb_flags(cpu, QEMU_PLUGIN_CB_NO_REGS); } } =20 @@ -520,7 +532,9 @@ void qemu_plugin_vcpu_syscall_ret(CPUState *cpu, int64_= t num, int64_t ret) QLIST_FOREACH_SAFE_RCU(cb, &plugin.cb_lists[ev], entry, next) { qemu_plugin_vcpu_syscall_ret_cb_t func =3D cb->f.vcpu_syscall_ret; =20 + qemu_plugin_set_cb_flags(cpu, QEMU_PLUGIN_CB_RW_REGS); func(cb->ctx->id, cpu->cpu_index, num, ret); + qemu_plugin_set_cb_flags(cpu, QEMU_PLUGIN_CB_NO_REGS); } } =20 @@ -528,14 +542,18 @@ void qemu_plugin_vcpu_idle_cb(CPUState *cpu) { /* idle and resume cb may be called before init, ignore in this case */ if (cpu->cpu_index < plugin.num_vcpus) { + qemu_plugin_set_cb_flags(cpu, QEMU_PLUGIN_CB_RW_REGS); plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_IDLE); + qemu_plugin_set_cb_flags(cpu, QEMU_PLUGIN_CB_NO_REGS); } } =20 void qemu_plugin_vcpu_resume_cb(CPUState *cpu) { if (cpu->cpu_index < plugin.num_vcpus) { + qemu_plugin_set_cb_flags(cpu, QEMU_PLUGIN_CB_RW_REGS); plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_RESUME); + qemu_plugin_set_cb_flags(cpu, QEMU_PLUGIN_CB_NO_REGS); } } =20 @@ -615,9 +633,13 @@ void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t v= addr, switch (cb->type) { case PLUGIN_CB_MEM_REGULAR: if (rw & cb->regular.rw) { + qemu_plugin_set_cb_flags(cpu, + tcg_call_to_qemu_plugin_cb_flags(cb->regular.info->fla= gs)); + cb->regular.f.vcpu_mem(cpu->cpu_index, make_plugin_meminfo(oi, rw), vaddr, cb->regular.userp); + qemu_plugin_set_cb_flags(cpu, QEMU_PLUGIN_CB_NO_REGS); } break; case PLUGIN_CB_INLINE_ADD_U64: @@ -760,3 +782,14 @@ void plugin_scoreboard_free(struct qemu_plugin_scorebo= ard *score) g_array_free(score->data, TRUE); g_free(score); } + +enum qemu_plugin_cb_flags tcg_call_to_qemu_plugin_cb_flags(int flags) +{ + if (flags & TCG_CALL_NO_RWG) { + return QEMU_PLUGIN_CB_NO_REGS; + } else if (flags & TCG_CALL_NO_WG) { + return QEMU_PLUGIN_CB_R_REGS; + } else { + return QEMU_PLUGIN_CB_RW_REGS; + } +} \ No newline at end of file --=20 2.49.0 From nobody Sat Feb 7 06:49:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1750349820; cv=none; d=zohomail.com; s=zohoarc; b=OQFeNRhVXm2B9nRigmAWAs6YchqrxRkJhHKvy5iPZZkrpUcfdKx4ZSg6BvGgJYnZs+FrDU+ubUfsCfM27+DU+XVpIyaZgCA1yOypiDbZ3lREBSPgRF+VjozotfqGBEKP/u3WClCj1zRYBQasaZd5rBRo+Y7oEwhfZDuG3vFuIa8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750349820; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Xl2CsCbMIdd7IA6Ry113lx92Qe9OahNuvq02EUlL3YI=; b=cb/dJnn3hov4T6qhpqjdq5D6UQ+Zi/LqaNxf9cmBjDrxFdwSwzWPnz6BZxRmA+yUcr/wl79Ii02VerWZB7l1LmkLYHSOVAQgaqUEqhpupg6Yv72FAf/FX/N9aYDmyjjlmFV5Miq/VLG7jR+pppjP3aB63BGaOdvLkgFJO4ZsOXY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17503498205111.751005064121955; Thu, 19 Jun 2025 09:17:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uSHw0-0001Qj-Tc; Thu, 19 Jun 2025 12:16:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uSHvk-0001Lz-7p for qemu-devel@nongnu.org; Thu, 19 Jun 2025 12:16:01 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uSHve-0003fO-QC for qemu-devel@nongnu.org; Thu, 19 Jun 2025 12:15:57 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-747fba9f962so689053b3a.0 for ; Thu, 19 Jun 2025 09:15:54 -0700 (PDT) Received: from shemhazi.lan ([50.46.174.34]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b2fe168a0f8sm13168683a12.53.2025.06.19.09.15.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jun 2025 09:15:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750349753; x=1750954553; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Xl2CsCbMIdd7IA6Ry113lx92Qe9OahNuvq02EUlL3YI=; b=ckdFEnsZ9+q1N+cXbq1s/g55aQkTvsn7+/8mnsCxOnAP4pXy4b0tVZRg652I0Cddpq QDyn5vKUxjgeZqGuWD//pnj5GeZ1WCgY5+DPDX17ghVCt1MRpyko8CIaVV6JmR6x/Epg FT9Vo7s3lRlySRYoufrh+hiHvvcYG/06UjWZFf6ucVdEdru7XIm7yUN0PCt+ZjXGs0Lh OAkhusc70qEhfLcwmpGr/TNMn1tBxDF+gNGSXtxKQPvlPXwVB9IEJjoce1zqVYpUIpjc c5u/ziHnWwyW1R9jQRBLOdNdsmxtA4Ln0Njw2Ner1eW8Xe3Jpd4nt5ZJdNfV5oMCI9dh msNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750349753; x=1750954553; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Xl2CsCbMIdd7IA6Ry113lx92Qe9OahNuvq02EUlL3YI=; b=siojYVWn9y4xT1d+3YPUKi+uRM+8oSusRpiS1xESjSRZmBLr6ognvWHcuKCWHYDZSl GxqzfVSQRkHlLVfIVpraXryW1IqXAQ4wE9T9S+xTUZ4CLvonAp1lSCEkCg2hvF6KrSrx 8xYY9WHoIYCeCRrJp5n6jCF+V5uqlL/pLkJK71afRxW6n1+SvJOctyK2hhIzKIMTXlRj fH3hPVCf0UB3TOmhEkSAOIC1ed7sOSbSCWlU0m3Q5rzBnqKnTVc+iL2H7fbuc0sx3CzX 4PF/Cr2EXBVeeoGQmNmeN/hM4fupLXImVFryAbbCmzPKoNp2yjBk9L4nnO/Qi8WPnYcu KPsg== X-Gm-Message-State: AOJu0YysG8kChyDnRM8n+JyN4e29EjUPJ/ngyByVQh18q6Za5C9f3UKv jfIL33dPPSP8qi3F+gAlbhc1ZEHXXzyU1rS+2HY4bcmoyA4YWekGeaVc4M2+haFQ X-Gm-Gg: ASbGncu3HNjRiGZiEE1q+G27pOT0L6xoJDDJlCNowC1VQswlzYP5oKUMXer50CQ2UQF nF/20SXKijfYiUPBpckPtzCIEI81W1dPTKvgYTw7NWv1jgq/+3tEIpuXsJWssUPNYT0hIpT6NjC ww2t0GLqscS72hmU6BqQ9Fnd+XBKDWF3Uvr3Jt0Bb8iCqMWaMsxujTtCWY3zoq2snKLhBFycdVq eLRhAinxUw+6k7K9pnAKus2UGxx12Kgi4wR/gU69FOk3fvlCOuTVuqhhejUSMNgYw6cP6/QpTvJ HFe3TOfDg5Tqabw7azHYCOkDqL4Gfb3H7jeNsiAKSTzQtWt9iuHgnpFvhUKB6g== X-Google-Smtp-Source: AGHT+IFVWKAM8H60gdn7Jp++YgRbEjqKdH1eQrXsxj2ZNtUID18RGXcd84WGWYkI0gebaoytM/X5uw== X-Received: by 2002:a05:6a21:62cc:b0:21e:2b2c:8f4f with SMTP id adf61e73a8af0-2201113b564mr6743453637.7.1750349752859; Thu, 19 Jun 2025 09:15:52 -0700 (PDT) From: Rowan Hart To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Marcel Apfelbaum , Zhao Liu , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , Mahmoud Mandour , Paolo Bonzini , novafacing Subject: [PATCH v13 4/7] plugins: Add memory virtual address write API Date: Thu, 19 Jun 2025 09:15:44 -0700 Message-ID: <20250619161547.1401448-5-rowanbhart@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250619161547.1401448-1-rowanbhart@gmail.com> References: <20250619161547.1401448-1-rowanbhart@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=rowanbhart@gmail.com; helo=mail-pf1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1750349821872116600 Content-Type: text/plain; charset="utf-8" From: novafacing This patch adds functions to the plugins API to allow reading and writing memory via virtual addresses. These functions only permit doing so on the current CPU, because there is no way to ensure consistency if plugins are allowed to read or write to other CPUs that aren't currently in the context of the plugin. Reviewed-by: Pierrick Bouvier Signed-off-by: Rowan Hart --- include/qemu/qemu-plugin.h | 21 +++++++++++++++++++++ plugins/api.c | 18 ++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 9c9ebf6ce0..4167c46c2a 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -958,6 +958,27 @@ QEMU_PLUGIN_API bool qemu_plugin_read_memory_vaddr(uint64_t addr, GByteArray *data, size_t len); =20 +/** + * qemu_plugin_write_memory_vaddr() - write to memory using a virtual addr= ess + * + * @addr: A virtual address to write to + * @data: A byte array containing the data to write + * + * The contents of @data will be written to memory starting at the virtual + * address @addr. + * + * This function does not guarantee consistency of writes, nor does it ens= ure + * that pending writes are flushed either before or after the write takes = place, + * so callers should take care to only call this function in vCPU context = (i.e. + * in callbacks) and avoid depending on the existence of data written usin= g this + * function which may be overwritten afterward. + * + * Returns true on success and false on failure. + */ +QEMU_PLUGIN_API +bool qemu_plugin_write_memory_vaddr(uint64_t addr, + GByteArray *data); + /** * qemu_plugin_scoreboard_new() - alloc a new scoreboard * diff --git a/plugins/api.c b/plugins/api.c index 3f04399c26..1f64a9ea64 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -476,6 +476,24 @@ bool qemu_plugin_read_memory_vaddr(uint64_t addr, GByt= eArray *data, size_t len) return true; } =20 +bool qemu_plugin_write_memory_vaddr(uint64_t addr, GByteArray *data) +{ + g_assert(current_cpu); + + if (data->len =3D=3D 0) { + return false; + } + + int result =3D cpu_memory_rw_debug(current_cpu, addr, data->data, + data->len, true); + + if (result < 0) { + return false; + } + + return true; +} + struct qemu_plugin_scoreboard *qemu_plugin_scoreboard_new(size_t element_s= ize) { return plugin_scoreboard_new(element_size); --=20 2.49.0 From nobody Sat Feb 7 06:49:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1750349820; cv=none; d=zohomail.com; s=zohoarc; b=XwbLUUKiU9+7f1PLJyUF7d4Bmftogqf0V8CBGjQFS3+URqAvs6cJJf/2VyOAgTZ81aB0zmB76mMPQsJB7EbrUq0F78lw0siEne38AfOOFMSOpDwgvwjNcPoxH5aCWSDzDloGsqigoXin0GMtyjQ5wulH6u4SjoGy+qYN+JyRB4U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750349820; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=97wbn1fyVd354+uZeRkmCwxgLDzBnsPU4MLpqSMDiPM=; b=IiGkNs57+jUYo8yaZQ1XaylNKzYDj/yxdEyfoxJFEOQzHwIPI0ZR6BLLzfv05zmFWFBI+1hEjdqCmXfxgf6YlJQrZ3pey25esh5t9P7eTem5599jAu+QozESMBdqfh/hOwlOH8HBqCA6JpD+ygvLmJzRSnrtWws8HpReRbHEx08= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1750349820775144.52183895028634; Thu, 19 Jun 2025 09:17:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uSHwP-0001cB-3h; Thu, 19 Jun 2025 12:16:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uSHvl-0001MD-VX for qemu-devel@nongnu.org; Thu, 19 Jun 2025 12:16:06 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uSHvg-0003fk-BO for qemu-devel@nongnu.org; Thu, 19 Jun 2025 12:16:01 -0400 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-7490acf57b9so48822b3a.2 for ; Thu, 19 Jun 2025 09:15:55 -0700 (PDT) Received: from shemhazi.lan ([50.46.174.34]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b2fe168a0f8sm13168683a12.53.2025.06.19.09.15.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jun 2025 09:15:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750349754; x=1750954554; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=97wbn1fyVd354+uZeRkmCwxgLDzBnsPU4MLpqSMDiPM=; b=ntBwG0mECUTJcAoMXhAHtBTNFR3wE7qyMIrhl335u4Ofrrto3tqIglqvtECgbKO5dE RqPI6f1/mphY11OfZ6y9TM2zKOWmejOXZdvCVYnIJP31bA/mTyQFjQU2pcjxvGW3q7wi 80B1qPO+yLtLlywxbs3lIeZ6qe1jmGzBTDQK3N/Jn8fj6rLX6Ni+pbKR00rER9ugRkxm XRiCa/FOG0FhALxgoTxn8xZ7+e6wVrmKJoAGm6Y1Dz2gWYHAQoRnL4k94n2JDHPGZzoN 6H/TZXvUjDRVtAr6Mk1IdAEMd+3QSA4WrTzd6G4QzdLSZdybUrp4OSJo5VEhEZNE0vrL IE6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750349754; x=1750954554; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=97wbn1fyVd354+uZeRkmCwxgLDzBnsPU4MLpqSMDiPM=; b=T6J07D0hm3uNOkGb7eHnYcnFXskSwMpfZ4AwZE9prlJnDiINLlCXTz32A8ZncfsPT3 ONMPMjFL8LIXpzLEBEyVgpP9joiLfEWjHKX3oJfy4SIRLjZKYTZ1HVQ4tXZJ9NBXBpj5 7rvgvmOBaxLpH4ju0p+lmhb5oxaUzVIxmAYc6jUduBZpAelBSQVrUYowahrZdr+PtEM/ ZToWPKNWv9JyuUKHQckIBY+i8Fb7PkOoJovQxetfeFPUVzXY4cnNEeFZzN7mmTyANncX gLsfo/+KuE3Ne79OUTcy5N5BSxB9w0NrDYFL+URKcFOWZinkeSwhECellLnJ726hjnwS YGIg== X-Gm-Message-State: AOJu0YxludXeo7RIe3yYdlDhD1gSpXtPs7Fy+FLe76txj9f/shlOzTTE tKPQZtuO9ZZz2iiK55WEgxTTQ19EZOZuZZwZC4Si6WZEoMWVYgWrYXR5O4GGoeRL X-Gm-Gg: ASbGnctGJx/8nwYAgTOtR2oRzyqpRz+6PdfYN5UtxvpLGW3cvirOkIrGoEGgheKKnEZ gddLWzKrR79jMsjUAnpTvyTy/eVCmQFCREe3mvSqaG0OsP5noJvMAu+GXjf3dIIy3957UUzABPg mKnpUu7SWD4fm5XXI2yS29mcq3VdCx8ao4ULG7bh9yRvfsewl2U+RjVJQauumwhyajsNG8UMwrP gOpnpK3kA4ksVpk1cux/Yi/EULl/ZAm3E+AW408hPqwSje72uAKyPpPg+BXpNx7NqmUilMTA3pU nmyKQnYXjIUpqeVf/Q62rzA/NJBGG8QQyTOuqX+3+g8z/9gR3lpVYuvBmfX5bQ== X-Google-Smtp-Source: AGHT+IE3bTg77mYp0Gqg7dDcXaR17WMg/QLEhmadJTerTeUHFCXEHwP9priGGf7y7X+uOp+hVGTHow== X-Received: by 2002:a05:6a20:43a4:b0:21a:eabb:ab93 with SMTP id adf61e73a8af0-21fbd495d38mr35657697637.6.1750349753997; Thu, 19 Jun 2025 09:15:53 -0700 (PDT) From: Rowan Hart To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Marcel Apfelbaum , Zhao Liu , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , Mahmoud Mandour , Paolo Bonzini , novafacing Subject: [PATCH v13 5/7] plugins: Add memory hardware address read/write API Date: Thu, 19 Jun 2025 09:15:45 -0700 Message-ID: <20250619161547.1401448-6-rowanbhart@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250619161547.1401448-1-rowanbhart@gmail.com> References: <20250619161547.1401448-1-rowanbhart@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=rowanbhart@gmail.com; helo=mail-pf1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1750349822037116600 Content-Type: text/plain; charset="utf-8" From: novafacing This patch adds functions to the plugins API to allow plugins to read and write memory via hardware addresses. The functions use the current address space of the current CPU in order to avoid exposing address space information to users. A later patch may want to add a function to permit a specified address space, for example to facilitate architecture-specific plugins that want to operate on them, for example reading ARM secure memory. Reviewed-by: Pierrick Bouvier Signed-off-by: Rowan Hart --- include/qemu/qemu-plugin.h | 93 ++++++++++++++++++++++++++++++++++++ plugins/api.c | 97 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 4167c46c2a..5eecdccc67 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -979,6 +979,99 @@ QEMU_PLUGIN_API bool qemu_plugin_write_memory_vaddr(uint64_t addr, GByteArray *data); =20 +/** + * enum qemu_plugin_hwaddr_operation_result - result of a memory operation + * + * @QEMU_PLUGIN_HWADDR_OPERATION_OK: hwaddr operation succeeded + * @QEMU_PLUGIN_HWADDR_OPERATION_ERROR: unexpected error occurred + * @QEMU_PLUGIN_HWADDR_OPERATION_DEVICE_ERROR: error in memory device + * @QEMU_PLUGIN_HWADDR_OPERATION_ACCESS_DENIED: permission error + * @QEMU_PLUGIN_HWADDR_OPERATION_INVALID_ADDRESS: address was invalid + * @QEMU_PLUGIN_HWADDR_OPERATION_INVALID_ADDRESS_SPACE: invalid address sp= ace + */ +enum qemu_plugin_hwaddr_operation_result { + QEMU_PLUGIN_HWADDR_OPERATION_OK, + QEMU_PLUGIN_HWADDR_OPERATION_ERROR, + QEMU_PLUGIN_HWADDR_OPERATION_DEVICE_ERROR, + QEMU_PLUGIN_HWADDR_OPERATION_ACCESS_DENIED, + QEMU_PLUGIN_HWADDR_OPERATION_INVALID_ADDRESS, + QEMU_PLUGIN_HWADDR_OPERATION_INVALID_ADDRESS_SPACE, +}; + +/** + * qemu_plugin_read_memory_hwaddr() - read from memory using a hardware ad= dress + * + * @addr: The physical address to read from + * @data: A byte array to store data into + * @len: The number of bytes to read, starting from @addr + * + * @len bytes of data is read from the current memory space for the current + * vCPU starting at @addr and stored into @data. If @data is not large eno= ugh to + * hold @len bytes, it will be expanded to the necessary size, reallocatin= g if + * necessary. @len must be greater than 0. + * + * This function does not ensure writes are flushed prior to reading, so + * callers should take care when calling this function in plugin callbacks= to + * avoid attempting to read data which may not yet be written and should u= se + * the memory callback API instead. + * + * This function is only valid for softmmu targets. + * + * Returns a qemu_plugin_hwaddr_operation_result indicating the result of = the + * operation. + */ +QEMU_PLUGIN_API +enum qemu_plugin_hwaddr_operation_result +qemu_plugin_read_memory_hwaddr(uint64_t addr, GByteArray *data, size_t len= ); + +/** + * qemu_plugin_write_memory_hwaddr() - write to memory using a hardware ad= dress + * + * @addr: A physical address to write to + * @data: A byte array containing the data to write + * + * The contents of @data will be written to memory starting at the hardware + * address @addr in the current address space for the current vCPU. + * + * This function does not guarantee consistency of writes, nor does it ens= ure + * that pending writes are flushed either before or after the write takes = place, + * so callers should take care when calling this function in plugin callba= cks to + * avoid depending on the existence of data written using this function wh= ich + * may be overwritten afterward. In addition, this function requires that = the + * pages containing the address are not locked. Practically, this means th= at you + * should not write instruction memory in a current translation block insi= de a + * callback registered with qemu_plugin_register_vcpu_tb_trans_cb. + * + * You can, for example, write instruction memory in a current translation= block + * in a callback registered with qemu_plugin_register_vcpu_tb_exec_cb, alt= hough + * be aware that the write will not be flushed until after the translation= block + * has finished executing. In general, this function should be used to wr= ite + * data memory or to patch code at a known address, not in a current trans= lation + * block. + * + * This function is only valid for softmmu targets. + * + * Returns a qemu_plugin_hwaddr_operation_result indicating the result of = the + * operation. + */ +QEMU_PLUGIN_API +enum qemu_plugin_hwaddr_operation_result +qemu_plugin_write_memory_hwaddr(uint64_t addr, GByteArray *data); + +/** + * qemu_plugin_translate_vaddr() - translate virtual address for current v= CPU + * + * @vaddr: virtual address to translate + * @hwaddr: pointer to store the physical address + * + * This function is only valid in vCPU context (i.e. in callbacks) and is = only + * valid for softmmu targets. + * + * Returns true on success and false on failure. + */ +QEMU_PLUGIN_API +bool qemu_plugin_translate_vaddr(uint64_t vaddr, uint64_t *hwaddr); + /** * qemu_plugin_scoreboard_new() - alloc a new scoreboard * diff --git a/plugins/api.c b/plugins/api.c index 1f64a9ea64..eac04cc1f6 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -39,6 +39,7 @@ #include "qemu/main-loop.h" #include "qemu/plugin.h" #include "qemu/log.h" +#include "system/memory.h" #include "tcg/tcg.h" #include "exec/gdbstub.h" #include "exec/target_page.h" @@ -494,6 +495,102 @@ bool qemu_plugin_write_memory_vaddr(uint64_t addr, GB= yteArray *data) return true; } =20 +enum qemu_plugin_hwaddr_operation_result +qemu_plugin_read_memory_hwaddr(hwaddr addr, GByteArray *data, size_t len) +{ +#ifdef CONFIG_SOFTMMU + if (len =3D=3D 0) { + return QEMU_PLUGIN_HWADDR_OPERATION_ERROR; + } + + g_assert(current_cpu); + + + int as_idx =3D cpu_asidx_from_attrs(current_cpu, MEMTXATTRS_UNSPECIFIE= D); + AddressSpace *as =3D cpu_get_address_space(current_cpu, as_idx); + + if (as =3D=3D NULL) { + return QEMU_PLUGIN_HWADDR_OPERATION_INVALID_ADDRESS_SPACE; + } + + g_byte_array_set_size(data, len); + MemTxResult res =3D address_space_rw(as, addr, + MEMTXATTRS_UNSPECIFIED, data->data, + data->len, false); + + switch (res) { + case MEMTX_OK: + return QEMU_PLUGIN_HWADDR_OPERATION_OK; + case MEMTX_ERROR: + return QEMU_PLUGIN_HWADDR_OPERATION_DEVICE_ERROR; + case MEMTX_DECODE_ERROR: + return QEMU_PLUGIN_HWADDR_OPERATION_INVALID_ADDRESS; + case MEMTX_ACCESS_ERROR: + return QEMU_PLUGIN_HWADDR_OPERATION_ACCESS_DENIED; + default: + return QEMU_PLUGIN_HWADDR_OPERATION_ERROR; + } +#else + return QEMU_PLUGIN_HWADDR_OPERATION_ERROR; +#endif +} + +enum qemu_plugin_hwaddr_operation_result +qemu_plugin_write_memory_hwaddr(hwaddr addr, GByteArray *data) +{ +#ifdef CONFIG_SOFTMMU + if (data->len =3D=3D 0) { + return QEMU_PLUGIN_HWADDR_OPERATION_ERROR; + } + + g_assert(current_cpu); + + int as_idx =3D cpu_asidx_from_attrs(current_cpu, MEMTXATTRS_UNSPECIFIE= D); + AddressSpace *as =3D cpu_get_address_space(current_cpu, as_idx); + + if (as =3D=3D NULL) { + return QEMU_PLUGIN_HWADDR_OPERATION_INVALID_ADDRESS_SPACE; + } + + MemTxResult res =3D address_space_rw(as, addr, + MEMTXATTRS_UNSPECIFIED, data->data, + data->len, true); + switch (res) { + case MEMTX_OK: + return QEMU_PLUGIN_HWADDR_OPERATION_OK; + case MEMTX_ERROR: + return QEMU_PLUGIN_HWADDR_OPERATION_DEVICE_ERROR; + case MEMTX_DECODE_ERROR: + return QEMU_PLUGIN_HWADDR_OPERATION_INVALID_ADDRESS; + case MEMTX_ACCESS_ERROR: + return QEMU_PLUGIN_HWADDR_OPERATION_ACCESS_DENIED; + default: + return QEMU_PLUGIN_HWADDR_OPERATION_ERROR; + } +#else + return QEMU_PLUGIN_HWADDR_OPERATION_ERROR; +#endif +} + +bool qemu_plugin_translate_vaddr(uint64_t vaddr, uint64_t *hwaddr) +{ +#ifdef CONFIG_SOFTMMU + g_assert(current_cpu); + + uint64_t res =3D cpu_get_phys_page_debug(current_cpu, vaddr); + + if (res =3D=3D (uint64_t)-1) { + return false; + } + + *hwaddr =3D res | (vaddr & ~TARGET_PAGE_MASK); + + return true; +#else + return false; +#endif +} + struct qemu_plugin_scoreboard *qemu_plugin_scoreboard_new(size_t element_s= ize) { return plugin_scoreboard_new(element_size); --=20 2.49.0 From nobody Sat Feb 7 06:49:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1750349838; cv=none; d=zohomail.com; s=zohoarc; b=DTVsy2bLKhlzNqBg1e4XpoUkQv6RuC1I6mTPamFwO2Ps1ZT9Nx45FMr6ClM3Qth35fBiV5wMyp8mZ+ua8MGmwrSHoJ3jNfMedRCgLUQWBt9yjj1nuoimfEmSUIsYWS+piUX5sxdunR3vf3fTKA7JZuPPhe2mcr5ixfebmNCafJk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750349838; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2vLerCmIZWerVR6lOT+c5v8QLYn8/ZN/T9f/NpJiZng=; b=XPAo4tgn19t5ptDd/gZR7wsQxKzchWdA8nBBO6cWRnu06pA9qRpkfrMxZO3PaBPFzVWmKE23ItvCKi1Wu4h9uwxxNUM/HQ5L5Z1lydB2Uw6c4afw0fgo+iNUTky97MZtvOLbQ6aCVQxe2/QMFGrq0rieKsD47n9XCQ9j/bslNRU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1750349838892737.9680213752636; Thu, 19 Jun 2025 09:17:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uSHwS-0001fD-0j; Thu, 19 Jun 2025 12:16:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uSHvn-0001MV-MS for qemu-devel@nongnu.org; Thu, 19 Jun 2025 12:16:06 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uSHvh-0003g0-Sf for qemu-devel@nongnu.org; Thu, 19 Jun 2025 12:16:03 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-747e41d5469so883397b3a.3 for ; Thu, 19 Jun 2025 09:15:56 -0700 (PDT) Received: from shemhazi.lan ([50.46.174.34]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b2fe168a0f8sm13168683a12.53.2025.06.19.09.15.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jun 2025 09:15:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750349755; x=1750954555; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2vLerCmIZWerVR6lOT+c5v8QLYn8/ZN/T9f/NpJiZng=; b=S4Rgg2nhs/GJrFDBV6RKMuqniaqM35hirgpbzmMYHHATFQOaESSLLj8G0/llTu3gkF mV8HQF91e1G8srxIPg5MZ0hBHo1EUc0QgePFME9TfD2NhbrkuFE1Ub4bGyKutOmGJpu9 YqZq+IvtJoHBSqfhV4LpSjzUhhQP5lujFRch5Vh/PWljHn4yTESoKNcOtqMKamDD9d+t QA8Rwh4Fv4Tejl/YXKKMiQOXGW0PdmZdgOHMYqKw0XfQLBo4GNC7xdKo5NJ2/wMDOrXq cFU+cTGgiTIB/hfgeNBRSPBC+PTMnT6jp7bMg016lW3cHmf1fN/PDLtYUuZa70sW6QdZ mZqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750349755; x=1750954555; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2vLerCmIZWerVR6lOT+c5v8QLYn8/ZN/T9f/NpJiZng=; b=GW0DqzC0QT08P7XjNHYtWYUwiS7Slo+j5BQ6JImxfUa/uH5TpWrY5Zlcgn8vkVsZQD 4QWR2Wen8BLzZ2agfLYrg6H8w75I4qADYJfqVAgQSS+mBWnTyuyH3iix67ljZWzHwjKP t2Ui8hCmPjKp3FZlqiHJTfiMUZoQWIln2Q9BX9B/+miHRRJnjvcgc+gkMGxDa/CXN4vP XJcA7xSSTTGV3BMD5y6V6/lg2nhhnX95OOFlxBtfW+Sy7DCm3ayuQXHWqXR0Y6Dc1DLj 7Krc619fdKWqgXkzFRPv+Kb+PN/+G2n8qbsJ4B25sV/kOpf4AtxOEYYu7T3JeVlDtkNV 5Biw== X-Gm-Message-State: AOJu0Yxo6qrpaN9bAhosNaE3VBdW7E8R5WCs2XOs6q/ya4gjSjdkw9wl GptxS72+MGJoXQEF1mr7+uz15cEFg+UyBglWZfPuKE//U86NU4e7krMoQ5mcIEOA X-Gm-Gg: ASbGncu9oPKmXi7GbYS201X3sOibpv4QHseu9fIKswUQ/arSwT4XZBnEAm8suAFGHLl rhT7PaR7zThh+z552YL7Pm2iuV6le3YFxi3qtyE7WTUm008vyJs2gCiUeM5EDv+6qO0o10+loVf GDSAqeKUhLwijx1/vRKbkbKPy7AJJe7NqFHBJn23uxT5XrMwAXcaVhjFZpbbC+vg/4IIvIC1ota LB2/k6XIyMwHEX1kSj2IZM7AOpYXms57IW08WP7L45/Nat4WUlZ5w1rK2IwoMgD2qlo0aew9yAD xrus/VCB5tCmwoKmp7vR+UBkuRNjhAPlOpKaiY0rjplyG1jTaLNCg6OBpg9xcA== X-Google-Smtp-Source: AGHT+IEEJ7/wf/gNbL0wMEAJc+XZ4QGJaQ/7WuXJgcaBYfypwjrA/aCmhPHnERQHowV8etl7lRCWQg== X-Received: by 2002:a05:6a00:4f88:b0:747:ee09:1fd2 with SMTP id d2e1a72fcca58-7489cfcb1d3mr31362743b3a.12.1750349755241; Thu, 19 Jun 2025 09:15:55 -0700 (PDT) From: Rowan Hart To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Marcel Apfelbaum , Zhao Liu , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , Mahmoud Mandour , Paolo Bonzini , novafacing Subject: [PATCH v13 6/7] plugins: Add patcher plugin and test Date: Thu, 19 Jun 2025 09:15:46 -0700 Message-ID: <20250619161547.1401448-7-rowanbhart@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250619161547.1401448-1-rowanbhart@gmail.com> References: <20250619161547.1401448-1-rowanbhart@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=rowanbhart@gmail.com; helo=mail-pf1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1750349840072116600 Content-Type: text/plain; charset="utf-8" From: novafacing This patch adds a plugin that exercises the virtual and hardware memory read-write API functions added in a previous patch. The plugin takes a target and patch byte sequence, and will overwrite any instruction matching the target byte sequence with the patch. Signed-off-by: Rowan Hart --- tests/tcg/Makefile.target | 7 +- tests/tcg/plugins/meson.build | 2 +- tests/tcg/plugins/patch.c | 241 ++++++++++++++++++++++ tests/tcg/x86_64/Makefile.softmmu-target | 7 + tests/tcg/x86_64/system/patch-target.c | 22 ++ tests/tcg/x86_64/system/validate-patch.py | 39 ++++ 6 files changed, 316 insertions(+), 2 deletions(-) create mode 100644 tests/tcg/plugins/patch.c create mode 100644 tests/tcg/x86_64/system/patch-target.c create mode 100755 tests/tcg/x86_64/system/validate-patch.py diff --git a/tests/tcg/Makefile.target b/tests/tcg/Makefile.target index 95ff76ea44..af68f11664 100644 --- a/tests/tcg/Makefile.target +++ b/tests/tcg/Makefile.target @@ -151,7 +151,12 @@ ifeq ($(CONFIG_PLUGIN),y) PLUGIN_SRC=3D$(SRC_PATH)/tests/tcg/plugins PLUGIN_LIB=3D../plugins VPATH+=3D$(PLUGIN_LIB) -PLUGINS=3D$(patsubst %.c, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.c))) +# Some plugins need to be disabled for all tests to avoid exponential expl= osion. +# For example, libpatch.so only needs to run against the arch-specific pat= ch +# target test, so we explicitly run it in the arch-specific Makefile. +DISABLE_PLUGINS=3Dlibpatch.so +PLUGINS=3D$(filter-out $(DISABLE_PLUGINS), \ + $(patsubst %.c, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.c)))) =20 # We need to ensure expand the run-plugin-TEST-with-PLUGIN # pre-requistes manually here as we can't use stems to handle it. We diff --git a/tests/tcg/plugins/meson.build b/tests/tcg/plugins/meson.build index 41f02f2c7f..163042e601 100644 --- a/tests/tcg/plugins/meson.build +++ b/tests/tcg/plugins/meson.build @@ -1,6 +1,6 @@ t =3D [] if get_option('plugins') - foreach i : ['bb', 'empty', 'inline', 'insn', 'mem', 'reset', 'syscall'] + foreach i : ['bb', 'empty', 'inline', 'insn', 'mem', 'reset', 'syscall',= 'patch'] if host_os =3D=3D 'windows' t +=3D shared_module(i, files(i + '.c') + '../../../contrib/plugins/= win32_linker.c', include_directories: '../../../include/qemu', diff --git a/tests/tcg/plugins/patch.c b/tests/tcg/plugins/patch.c new file mode 100644 index 0000000000..450fc51c88 --- /dev/null +++ b/tests/tcg/plugins/patch.c @@ -0,0 +1,241 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This plugin patches instructions matching a pattern to a different + * instruction as they execute + * + */ + +#include "glib.h" +#include "glibconfig.h" + +#include +#include +#include + +QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; + +static bool use_hwaddr; +static GByteArray *target_data; +static GByteArray *patch_data; + +/** + * Parse a string of hexadecimal digits into a GByteArray. The string must= be + * even length + */ +static GByteArray *str_to_bytes(const char *str) +{ + size_t len =3D strlen(str); + + if (len =3D=3D 0 || len % 2 !=3D 0) { + return NULL; + } + + GByteArray *bytes =3D g_byte_array_new(); + char byte[3] =3D {0}; + guint8 value =3D 0; + + for (size_t i =3D 0; i < len; i +=3D 2) { + byte[0] =3D str[i]; + byte[1] =3D str[i + 1]; + value =3D (guint8)g_ascii_strtoull(byte, NULL, 16); + g_byte_array_append(bytes, &value, 1); + } + + return bytes; +} + +static void patch_hwaddr(unsigned int vcpu_index, void *userdata) +{ + uint64_t addr =3D (uint64_t)userdata; + g_autoptr(GString) str =3D g_string_new(NULL); + g_string_printf(str, "patching: @0x%" + PRIx64 "\n", + addr); + qemu_plugin_outs(str->str); + + enum qemu_plugin_hwaddr_operation_result result =3D + qemu_plugin_write_memory_hwaddr(addr, patch_data); + + + if (result !=3D QEMU_PLUGIN_HWADDR_OPERATION_OK) { + g_autoptr(GString) errmsg =3D g_string_new(NULL); + g_string_printf(errmsg, "Failed to write memory: %d\n", result); + qemu_plugin_outs(errmsg->str); + return; + } + + GByteArray *read_data =3D g_byte_array_new(); + + result =3D qemu_plugin_read_memory_hwaddr(addr, read_data, + patch_data->len); + + qemu_plugin_outs("Reading memory...\n"); + + if (result !=3D QEMU_PLUGIN_HWADDR_OPERATION_OK) { + g_autoptr(GString) errmsg =3D g_string_new(NULL); + g_string_printf(errmsg, "Failed to read memory: %d\n", result); + qemu_plugin_outs(errmsg->str); + return; + } + + if (memcmp(patch_data->data, read_data->data, patch_data->len) !=3D 0)= { + qemu_plugin_outs("Failed to read back written data\n"); + } + + qemu_plugin_outs("Success!\n"); + + return; +} + +static void patch_vaddr(unsigned int vcpu_index, void *userdata) +{ + uint64_t addr =3D (uint64_t)userdata; + uint64_t hwaddr =3D 0; + if (!qemu_plugin_translate_vaddr(addr, &hwaddr)) { + qemu_plugin_outs("Failed to translate vaddr\n"); + return; + } + g_autoptr(GString) str =3D g_string_new(NULL); + g_string_printf(str, "patching: @0x%" + PRIx64 " hw: @0x%" PRIx64 "\n", + addr, hwaddr); + qemu_plugin_outs(str->str); + + qemu_plugin_outs("Writing memory (vaddr)...\n"); + + if (!qemu_plugin_write_memory_vaddr(addr, patch_data)) { + qemu_plugin_outs("Failed to write memory\n"); + return; + } + + qemu_plugin_outs("Reading memory (vaddr)...\n"); + + g_autoptr(GByteArray) read_data =3D g_byte_array_new(); + + if (!qemu_plugin_read_memory_vaddr(addr, read_data, patch_data->len)) { + qemu_plugin_outs("Failed to read memory\n"); + return; + } + + if (memcmp(patch_data->data, read_data->data, patch_data->len) !=3D 0)= { + qemu_plugin_outs("Failed to read back written data\n"); + } + + qemu_plugin_outs("Success!\n"); + + return; +} + +/* + * Callback on translation of a translation block. + */ +static void vcpu_tb_trans_cb(qemu_plugin_id_t id, struct qemu_plugin_tb *t= b) +{ + uint64_t addr =3D 0; + g_autoptr(GByteArray) insn_data =3D g_byte_array_new(); + for (size_t i =3D 0; i < qemu_plugin_tb_n_insns(tb); i++) { + struct qemu_plugin_insn *insn =3D qemu_plugin_tb_get_insn(tb, i); + + if (use_hwaddr) { + uint64_t vaddr =3D qemu_plugin_insn_vaddr(insn); + if (!qemu_plugin_translate_vaddr(vaddr, &addr)) { + qemu_plugin_outs("Failed to translate vaddr\n"); + continue; + } + } else { + addr =3D qemu_plugin_insn_vaddr(insn); + } + + g_byte_array_set_size(insn_data, qemu_plugin_insn_size(insn)); + qemu_plugin_insn_data(insn, insn_data->data, insn_data->len); + + if (insn_data->len >=3D target_data->len && + !memcmp(insn_data->data, target_data->data, + MIN(target_data->len, insn_data->len))) { + if (use_hwaddr) { + qemu_plugin_register_vcpu_tb_exec_cb(tb, patch_hwaddr, + QEMU_PLUGIN_CB_NO_REG= S, + (void *)addr); + } else { + qemu_plugin_register_vcpu_tb_exec_cb(tb, patch_vaddr, + QEMU_PLUGIN_CB_NO_REG= S, + (void *)addr); + } + } + } +} + +static void usage(void) +{ + fprintf(stderr, "Usage: ,target=3D,patch=3D" + "[,use_hwaddr=3Dtrue|false]"); +} + +/* + * Called when the plugin is installed + */ +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, + const qemu_info_t *info, int ar= gc, + char **argv) +{ + + use_hwaddr =3D true; + target_data =3D NULL; + patch_data =3D NULL; + + if (argc > 4) { + usage(); + return -1; + } + + for (size_t i =3D 0; i < argc; i++) { + char *opt =3D argv[i]; + g_auto(GStrv) tokens =3D g_strsplit(opt, "=3D", 2); + if (g_strcmp0(tokens[0], "use_hwaddr") =3D=3D 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &use_hwaddr)= ) { + fprintf(stderr, + "Failed to parse boolean argument use_hwaddr\n"); + return -1; + } + } else if (g_strcmp0(tokens[0], "target") =3D=3D 0) { + target_data =3D str_to_bytes(tokens[1]); + if (!target_data) { + fprintf(stderr, + "Failed to parse target bytes.\n"); + return -1; + } + } else if (g_strcmp0(tokens[0], "patch") =3D=3D 0) { + patch_data =3D str_to_bytes(tokens[1]); + if (!patch_data) { + fprintf(stderr, "Failed to parse patch bytes.\n"); + return -1; + } + } else { + fprintf(stderr, "Unknown argument: %s\n", tokens[0]); + usage(); + return -1; + } + } + + if (!target_data) { + fprintf(stderr, "target argument is required\n"); + usage(); + return -1; + } + + if (!patch_data) { + fprintf(stderr, "patch argument is required\n"); + usage(); + return -1; + } + + if (target_data->len !=3D patch_data->len) { + fprintf(stderr, "Target and patch data must be the same length\n"); + return -1; + } + + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans_cb); + + return 0; +} diff --git a/tests/tcg/x86_64/Makefile.softmmu-target b/tests/tcg/x86_64/Ma= kefile.softmmu-target index ef6bcb4dc7..819165ae36 100644 --- a/tests/tcg/x86_64/Makefile.softmmu-target +++ b/tests/tcg/x86_64/Makefile.softmmu-target @@ -35,3 +35,10 @@ memory: CFLAGS+=3D-DCHECK_UNALIGNED=3D1 =20 # Running QEMU_OPTS+=3D-device isa-debugcon,chardev=3Doutput -device isa-debug-exit,= iobase=3D0xf4,iosize=3D0x4 -kernel + +run-plugin-patch-target-with-libpatch.so: \ + PLUGIN_ARGS=3D$(COMMA)target=3Dffc0$(COMMA)patch=3D9090$(COMMA)use_hwaddr= =3Dtrue +run-plugin-patch-target-with-libpatch.so: \ + CHECK_PLUGIN_OUTPUT_COMMAND=3D$(X64_SYSTEM_SRC)/validate-patch.py $@.out +run-plugin-patch-target-with-libpatch.so: patch-target libpatch.so +EXTRA_RUNS+=3Drun-plugin-patch-target-with-libpatch.so \ No newline at end of file diff --git a/tests/tcg/x86_64/system/patch-target.c b/tests/tcg/x86_64/syst= em/patch-target.c new file mode 100644 index 0000000000..8c2b6f4ba7 --- /dev/null +++ b/tests/tcg/x86_64/system/patch-target.c @@ -0,0 +1,22 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This test target increments a value 100 times. The patcher converts the + * inc instruction to a nop, so it only increments the value once. + * + */ +#include + +int main(void) +{ + ml_printf("Running test...\n"); + unsigned int x =3D 0; + for (int i =3D 0; i < 100; i++) { + asm volatile ( + "inc %[x]" + : [x] "+a" (x) + ); + } + ml_printf("Value: %d\n", x); + return 0; +} diff --git a/tests/tcg/x86_64/system/validate-patch.py b/tests/tcg/x86_64/s= ystem/validate-patch.py new file mode 100755 index 0000000000..700950eae5 --- /dev/null +++ b/tests/tcg/x86_64/system/validate-patch.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +# +# validate-patch.py: check the patch applies +# +# This program takes two inputs: +# - the plugin output +# - the binary output +# +# Copyright (C) 2024 +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import sys +from argparse import ArgumentParser + +def main() -> None: + """ + Process the arguments, injest the program and plugin out and + verify they match up and report if they do not. + """ + parser =3D ArgumentParser(description=3D"Validate patch") + parser.add_argument('test_output', + help=3D"The output from the test itself") + parser.add_argument('plugin_output', + help=3D"The output from plugin") + args =3D parser.parse_args() + + with open(args.test_output, 'r') as f: + test_data =3D f.read() + with open(args.plugin_output, 'r') as f: + plugin_data =3D f.read() + if "Value: 1" in test_data: + sys.exit(0) + else: + sys.exit(1) + +if __name__ =3D=3D "__main__": + main() + --=20 2.49.0 From nobody Sat Feb 7 06:49:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1750349874; cv=none; d=zohomail.com; s=zohoarc; b=krVuoQvNTNfMtayUF/k6pky4Is0Zln6wvbuxMdM2sbZm0v+GPO/o04ZN6h3u0vDIiEFOVOIcyTgJwBHSBhfr+HEFVIUGHtl/2G67yr3rxNc2qbIqUzZw7gxY1gFIExVlO7/dGtYUfu8U6yJF9FLZUrDZS2MohRmO4x1ef3A5hBY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750349874; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xngZvcERBrHIiDDbzOPfea5jz0IsdaSOpmqYDGzty7Y=; b=jKTt7zOVmpBWvmH50IEA1UCechQPb2enNfxNIOiEDoLgCvUbQBA+CIva8zdksSKljiHJko2MnYaBYPnSdquUckF3A14f1aQa9EvRLdNrdEmkAWz6nQDJdYxtipsH/6HWQMayOHNpzGQPV9P4NYz4dAlDjZR+jpRHsti1QdJOrvU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1750349874872489.1238648840797; Thu, 19 Jun 2025 09:17:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uSHwQ-0001eX-Us; Thu, 19 Jun 2025 12:16:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uSHvm-0001MN-Qf for qemu-devel@nongnu.org; Thu, 19 Jun 2025 12:16:06 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uSHvj-0003gL-Qw for qemu-devel@nongnu.org; Thu, 19 Jun 2025 12:16:02 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-7424ccbef4eso673483b3a.2 for ; Thu, 19 Jun 2025 09:15:57 -0700 (PDT) Received: from shemhazi.lan ([50.46.174.34]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b2fe168a0f8sm13168683a12.53.2025.06.19.09.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jun 2025 09:15:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750349756; x=1750954556; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xngZvcERBrHIiDDbzOPfea5jz0IsdaSOpmqYDGzty7Y=; b=aFzKdVhlnD6ovo9UuZnkoWxFyQWdnJaMkast3a9s7GJIlsq9heHZp7rR+9pbY58sDG NVk/iKVqVRtq930FwwLoqDa66q7X/KeaR5h/Th/aXEMmlu2o49KO3VXMkPlot125XQBY RKUie1+EBXe2vcKf4Sc7qgX4auyrDaXFcN8cCF+Db7w+XNhu+1/VYlL2qI86iuI02aQT XdAfMpuwBpk04PaxgJAfHqtx32/dq+E4LDnd7RooQZHw5nUUbyNAL43wZfmC9g+JgZwJ CjkoP9J831DyC/+kgUMyldHozVicKnHJOpJ0JV7LC1feoP6CAS2Ek0hNpuYsnPjUPmpj Nq8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750349756; x=1750954556; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xngZvcERBrHIiDDbzOPfea5jz0IsdaSOpmqYDGzty7Y=; b=O3j0LziwrgJk+682bkZR+wKXKK7Lfnqu/bIHN7j/VESQOGH9OvupqEIQaKOLH3mr2f G7BclNVdEO65MnaYoM2It6cyIy/aQLrviIc2O1gexouST1ZkS8dTZkNv2ze6IBiKlSUm /b8XXzxcq9waDCBrAbGQ/X34WLtWS09WfnQp1o9C644zAUmp3Dbz85wVC6WWwRnOp8KZ 31umzp3tjpegb4oCn6dfCgflUIKEevevlSQc8PZhAjGZkMlZHop3v+Q3zKsFK2gMFe3p 9/PmbWEPB8GJifhOCIT3E1UhLIsQSGwQ97JAizb4ryXXVNbTA1/1Xbg3h1JStTbB2rI0 XIOQ== X-Gm-Message-State: AOJu0Yxrf2LzIcG+wrLpRikRM7cI32MZKnxDIfZ+TmVOCRIirDbY/ph4 u0Bkx0zsR1OpxT4EnhPnHA88QvKS8F53xY7ncYI51geVMLTWez+WP+6+ZKwvpv8c X-Gm-Gg: ASbGncu7AxDTWRjIq7zkxzuG71Td69SoKEqMmM2knLAK8lBtigbMNpPSdM6vlo4oWVm r1ZhxDCp5HBdaaXE9Oe2/FbtLN/RwpCta52OA9Y7JONxIH5SMJrZLhoR5CJWZULJ+yNlR/rv5Uo pfCrLIiT5srBXEQwBNmmSNA04JYanLL99CDWHNqyIaNLbIWZ5vc+r++fR4owXO9FWtVGvSGikyN 66qp2BHuNCT+ikU5ffIihn/ZNLSk6h6QAuQe3QpnhojtceUE1B9CtBr7+t9zKZyctuwnnzh13Ij 9ZYxM7gPE7pQPopkbWag/mlsQ2B3JNOI+liVUnEvvFBYS5Qb9/VYmI2RWDTT7w== X-Google-Smtp-Source: AGHT+IG8+hlY84oCE1sa8zWJJWx11QQl8AoPiEUBIawwtUrN/S1oVAb1Kuq4AmXSTxjv1RNeo2k06w== X-Received: by 2002:a05:6a20:d04c:b0:215:e818:9fda with SMTP id adf61e73a8af0-21fbd67f904mr32317653637.27.1750349756331; Thu, 19 Jun 2025 09:15:56 -0700 (PDT) From: Rowan Hart To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Marcel Apfelbaum , Zhao Liu , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Eduardo Habkost , Mahmoud Mandour , Paolo Bonzini , novafacing Subject: [PATCH v13 7/7] plugins: Update plugin version and add notes Date: Thu, 19 Jun 2025 09:15:47 -0700 Message-ID: <20250619161547.1401448-8-rowanbhart@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250619161547.1401448-1-rowanbhart@gmail.com> References: <20250619161547.1401448-1-rowanbhart@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=rowanbhart@gmail.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1750349876335116600 Content-Type: text/plain; charset="utf-8" From: novafacing This patch updates the plugin version to gate new APIs and adds notes describing what has been added. Reviewed-by: Pierrick Bouvier Signed-off-by: Rowan Hart --- include/qemu/qemu-plugin.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 5eecdccc67..c450106af1 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -65,11 +65,18 @@ typedef uint64_t qemu_plugin_id_t; * * version 4: * - added qemu_plugin_read_memory_vaddr + * + * version 5: + * - added qemu_plugin_write_memory_vaddr + * - added qemu_plugin_read_memory_hwaddr + * - added qemu_plugin_write_memory_hwaddr + * - added qemu_plugin_write_register + * - added qemu_plugin_translate_vaddr */ =20 extern QEMU_PLUGIN_EXPORT int qemu_plugin_version; =20 -#define QEMU_PLUGIN_VERSION 4 +#define QEMU_PLUGIN_VERSION 5 =20 /** * struct qemu_info_t - system information for plugins --=20 2.49.0