From nobody Sat Feb 7 07:38:57 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=1750787684; cv=none; d=zohomail.com; s=zohoarc; b=gRDmhp//HPlyOI/XYI7isM/i5eN9De5mXIALOtFEF4nW3vxWjWwVNoPCmNQV+iUpaKBE30idDWQQGzgbKOrR/lqMERqx9lJ9hqOqLraCrmfVEGCQ5SiLt0UPvgRT3rbAz4x/fVWqLehjmfASIqPGaX9RP0yyHi0gmNkdrTPrFZ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750787684; 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=nHe8xQirzInPTSI2/m7eUgGXSthWU8jdNTJ3AwcZinw=; b=QNhjOb2ZY+Eq+krT+VvHcb0NOSvhOcofuyy57YIkldezOSj36tw/xw9yYHq1XfA+RMIRC/452ZvNp9QNRfOzvwZ8dKmRWaZFaNAvHbXNTklOXey87r9GHzs/f72Dos6S3IqL9eGq1UW5J5nnx5x5r4Tm0TMSodD9M2BiPJMkxb4= 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 1750787684192963.9164968318712; Tue, 24 Jun 2025 10:54:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uU7qS-0002ya-KG; Tue, 24 Jun 2025 13:54:13 -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 1uU7qJ-0002wk-GF for qemu-devel@nongnu.org; Tue, 24 Jun 2025 13:54:00 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uU7qH-0002lq-78 for qemu-devel@nongnu.org; Tue, 24 Jun 2025 13:53:58 -0400 Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-b34a71d9208so816823a12.3 for ; Tue, 24 Jun 2025 10:53:54 -0700 (PDT) Received: from shemhazi.lan ([50.46.174.34]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b31f12427b7sm9318153a12.40.2025.06.24.10.53.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jun 2025 10:53:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750787634; x=1751392434; 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=nHe8xQirzInPTSI2/m7eUgGXSthWU8jdNTJ3AwcZinw=; b=nof21IAjc2QUKMO8XlRdRKS7MkH/fgNmLsnOKa/ntuN2F9/4mB8FBDFWMUse9FZWJW 6b8EPNVRtjEdYwff77EdIdCoTqTdaVg18NC5tTBCxLZ8UtDEUYzZKhJoLfyiaqy+R79/ x8hZ6JSg7h3brknAC/UDC6HBWGRlHe/IszlmyOuYHv8nx3cLqvh/0GKEN8NO1rq7pGSM 5TjJs7XcsBYQ0zkzbcLqspj21xFbe+BhxY9X9lHEt0BncShbcouvdH717+IyPdv5lxF5 Gf12JpJeRElmW7ZgXMAsIwBDI2rjKrty0G0OnNfAi7rrec5YBa2LB+04NYqYyZ0DdbpF 9LiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750787634; x=1751392434; 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=nHe8xQirzInPTSI2/m7eUgGXSthWU8jdNTJ3AwcZinw=; b=OALrgtjoUJjLgBTkmfZnJsfA6jsXj/JSoKShbOvM3lCcajBm0UV0yJx4FzCLlJ6Gqj CVjzs4G3+m4vgrFgDVCcbFq2JR8TJLnFf6oPujVfzi+N0fOP8HinAZ3B5I7mW0YtgdQb 5XPMwVRuL8IQx0hQ/ej9IysYLpxKov51YtXBRoGUT+Vp7CFVTAeG47/5dRzM/ERWk/4V 29/isBdBFsK5oVZH9MqgUcqc/bEa5FQvhETKEIV5ZOaLdV5iVhv+6leeuKn6LVeS7Mvq XD96YXLjTrJE4VaZNYNC/q2AQcy6MeVQb82Tou8pbrUaCV0u/+FHRxR6ZpR6h+q1MIg1 Hrnw== X-Gm-Message-State: AOJu0Yz5EmgFmqJlJl1Aw9w37ilymGrPu3ePg65hKStKBV2bbgsBpaMR qFoDZbW/+2FYjsWXQNhbBgWqOSvD88zcfNN8iLpQZ8+bn0Yp0RXLWekU9gE7pBdHQcE= X-Gm-Gg: ASbGncsAyV24TgAyLnjphTgocGwEsFdRRkBFJt8G3wtKEuulQDhLJg0+b1cn5pM67Yj uybddvZXcne0uPmLqJo8hqVUT6QhfLInytMhrSb2cSvJAGhp1+kq48yBN8+aWff8Z+bY85nOVJX i69Ygt200W2JPSHWBV93QqMk5mKj0rPQzrEpb2Q/bAK6fBKMZn29ZrSdsG+S541BsFN0e6tEYv7 V2sY+moRAC9Wwwhgrm/sN6p5mSCBsERnvL0amIv3FEmvuWXkG1y16RQHV/UPZuH6wDalrwKaeHq 2aMPbl/mCCClztEr56oRhkLDTccMAkcauH8ObryM7MTyAbdBFuMq3NCko/nruQ== X-Google-Smtp-Source: AGHT+IHDs1T12MFHm40WqppsL21JDdl8ZgeXZP7OBVR1xdJtgqIz7SMZZKz9m/4ogeJUH9nMpgpJ2Q== X-Received: by 2002:a05:6a21:2d04:b0:21f:775d:107e with SMTP id adf61e73a8af0-22026dd980dmr25556123637.17.1750787633666; Tue, 24 Jun 2025 10:53:53 -0700 (PDT) From: Rowan Hart To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , Mahmoud Mandour , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Marcel Apfelbaum , Yanan Wang , Alexandre Iooss , Eduardo Habkost , Zhao Liu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Rowan Hart , Julian Ganz Subject: [PATCH v14 1/8] gdbstub: Expose gdb_write_register function to consumers of gdbstub Date: Tue, 24 Jun 2025 10:53:44 -0700 Message-ID: <20250624175351.440780-2-rowanbhart@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250624175351.440780-1-rowanbhart@gmail.com> References: <20250624175351.440780-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::52c; envelope-from=rowanbhart@gmail.com; helo=mail-pg1-x52c.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: 1750787686065116600 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 07:38:57 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=1750787665; cv=none; d=zohomail.com; s=zohoarc; b=UcJBtYDdFp9DI4phfLIVwX63GeK4QGCkAQjC+2gZcfWdZl2L09VXZdxthwjnWDlG5851Zo7J4HwtfkjKKs5p3MvDny9oYRzcSolkelr8Kc4nmS5iGTemWwfCI8AonTftjMKINk6qU01Cy4QOLq933010wR+hJ86tvE+TGfGdjdc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750787665; 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=LDtY3VYHW8ed7y/lzqSblD3MXgi/fhtDmtDUwDMMsfI=; b=RUq82gayPTZR1uqGJPuz/puhFDDGpkxx7f2kIYI1p1PhgrMaMnfJ51jVady3gVJDMFxaylgSWZaAwhITDBXRdyKCykWoOOfDY+klpX2E6rcwomizz2DPpP5mjNiWyJOnUqljRHCo4IgCDkt6Ru6wHdU2Jw8Iqm+jCtI4jDYfoVg= 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 1750787665227481.70765473960057; Tue, 24 Jun 2025 10:54:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uU7qN-0002x4-6s; Tue, 24 Jun 2025 13:54:05 -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 1uU7qJ-0002wl-GR for qemu-devel@nongnu.org; Tue, 24 Jun 2025 13:54:00 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uU7qH-0002m0-7M for qemu-devel@nongnu.org; Tue, 24 Jun 2025 13:53:58 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-2363616a1a6so48632975ad.3 for ; Tue, 24 Jun 2025 10:53:55 -0700 (PDT) Received: from shemhazi.lan ([50.46.174.34]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b31f12427b7sm9318153a12.40.2025.06.24.10.53.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jun 2025 10:53:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750787634; x=1751392434; 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=LDtY3VYHW8ed7y/lzqSblD3MXgi/fhtDmtDUwDMMsfI=; b=cjLxR5TaUrY9pbnV4bitjSXfSEAgKfRqIjf/KZXuZVRI3ubACk1w1M2pQkZZMNVufr 5c30D8jjQAw2So70t4bHeLUEitr37yjvG4Fz7Wn3Ts+Q3QMNZknn7kDu2WX5XvJj5lRF XVg2+YBL6E7Wgbphl5yibgxmk+bPxWhoZRCXZSO8Ecih7sgRcI1fIzoES4fZoIQ7i0vw MBv99VLH75E6EyXnpC1tbou90Y1vOqi7T5ULmukLRnRXooTwLxfeV9P4Jfntb84lKu4w Bt2A4DEj55j7Xvovk8hM4N/NGz+IvVkO8Xi19a1dUYBo5qLzWGZLCMYdXYdR85smpAoM Ihfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750787634; x=1751392434; 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=LDtY3VYHW8ed7y/lzqSblD3MXgi/fhtDmtDUwDMMsfI=; b=SQTaNBrw60xzs7oRtQEmir9FtYvn3EAcj7mjbei+SOcS4TL3v7+HO2Q55DhKr1DDe/ 7uFrGfDlp41qQotmW8bKZkqXV3ODYup2PvJtgUuj7y9idp5poqrTIpAlPMhjozDi5rF9 XNu4+T9X+Wt9vbp9DNJyC3J1NdEPNu1UG0wfHU85AWFBdthIUJGkAxvUeXyuUVYeNDC5 vtUQbHk4WwsRZY1g25tm3kA2UYANuYRY7zmA+Fq34gUProHw1nLK33R0Ar3tHWEK/f1d wlJfFFC6XIFTySsbkSSAanRVx17mRkG69GJ4BiYa7bNqrAFvD1gIpApJq5PUP1dtDJqI 3pcQ== X-Gm-Message-State: AOJu0Yw4knzmRORXstToy0wQP6ZzGyBpR8iZYyBhZRRMIozM3JTx3Ix4 JTesEOk5RQ1Fs4hxgQPKfa6eDjv49Kg50x+cPO0JUWBzJ5NGXr9voNOqFP7CPbD41Ug= X-Gm-Gg: ASbGncvS+44h24zzXXrMh6IxTeixEqh/V7hurE8Cu1b4T/1D7ngPX3tvrQ17FxYri/W lpaKS//T5FrUcu86eYMS+UYVwW05WZ2P20dM6/7hhSQnhe6uVQynHoj2y/rY07b3DmeEaUy2G96 LIMmv6dFI0v15Z/UDFVxuIZuTIFH/4yfJBEJDHFBXeey5Yyp4+Q1mhMjBAWyhRKLM5yqSscc+s+ NyC730KF4C7h1uq8aHIo8E6DFGNVxpS67siBJZxgPZOxPnOX/nBcgW9sJSwUcZiCmevtrRWH3ki z4pEDYFotYT3F67oIzJfwtMOH9fGq1uHcQRYNQP1Re3gJRNhiE1Q6t5Zd0XkDA== X-Google-Smtp-Source: AGHT+IFuTlGXVWrxHbbZkHbBhnIlJIwLuXZBCLIeHfqeIcCztKkQk7c28BS8j9pPETv7aBrejLnQiA== X-Received: by 2002:a17:902:f68f:b0:234:ed31:fc98 with SMTP id d9443c01a7336-2382406aaf8mr3137155ad.37.1750787634520; Tue, 24 Jun 2025 10:53:54 -0700 (PDT) From: Rowan Hart To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , Mahmoud Mandour , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Marcel Apfelbaum , Yanan Wang , Alexandre Iooss , Eduardo Habkost , Zhao Liu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Rowan Hart Subject: [PATCH v14 2/8] plugins: Add register write API Date: Tue, 24 Jun 2025 10:53:45 -0700 Message-ID: <20250624175351.440780-3-rowanbhart@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250624175351.440780-1-rowanbhart@gmail.com> References: <20250624175351.440780-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::634; envelope-from=rowanbhart@gmail.com; helo=mail-pl1-x634.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: 1750787668031116600 Content-Type: text/plain; charset="utf-8" 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 07:38:57 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=1750787709; cv=none; d=zohomail.com; s=zohoarc; b=JPH7tk7/gg6mwvOvFikYtJtZ5v+T3Lem+9+f+KevMkdkqwT0M6jb7jXtP6vi1EAPC+bD07KyKrPrCvDqzDfvJVrOwW44uYXqO7Rhznojv+jk83ILvyEzAvxsuaS6G46jhiR2Ox2XOnlSBVcTlsijDZ5LVyQKyJcgk9hu5bullb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750787709; 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=XgZm1uyV1qb9UJ2sS7hNDxyPmGesubEoDQCnhuCBxpI=; b=fJ0sVY5/JpCxrpUuMbHr7w4SzJNvhz1MUVmXOGsRhAIxBcUffE7mV8wJ2fKE5EEjmWf8JNwnKlk835TqGewsoTDG8X1v2W/Zg/PErt63ZZ4dbh/YBx6rHKLK+jabYhGX2T6H0gjSpV0vdR2HcwjVHIwJo3Aa0ZQIRnHbc2ZkrHU= 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 1750787709739134.57850463108002; Tue, 24 Jun 2025 10:55:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uU7qb-00034z-G1; Tue, 24 Jun 2025 13:54: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 1uU7qL-0002x2-Dn for qemu-devel@nongnu.org; Tue, 24 Jun 2025 13:54:03 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uU7qH-0002m5-7N for qemu-devel@nongnu.org; Tue, 24 Jun 2025 13:54:00 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-74931666cbcso421225b3a.0 for ; Tue, 24 Jun 2025 10:53:56 -0700 (PDT) Received: from shemhazi.lan ([50.46.174.34]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b31f12427b7sm9318153a12.40.2025.06.24.10.53.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jun 2025 10:53:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750787635; x=1751392435; 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=XgZm1uyV1qb9UJ2sS7hNDxyPmGesubEoDQCnhuCBxpI=; b=JTBCwMZZmGZ87exbeBOTRUZEdq5Y4OveZ3sj4il4IVQPZhrjydVecXjBakuOWGO+bC cLlylw2cA4Y0XfrGTB0h6nVYWWYdvI/gTPC8G/OPyoiuSwIY10OT1j2nt/w9v4mi19fo BWCBFHlUWyEqviFIvPcOvyzySZKmtHd4r9t4B6dBYA4eD5QhUrm3J4/X2uiL0CBxb8Mc N9Ug1MOeUEqYMtswGRWO+73d+K7tbv6YTjaJmu08CGz053fANK6dmQTJt6NthxW//Nbr YSBDhnq3ekw3oW3+nJ14qRTytSqZo96FBa1TX50Xqu6Qn7oRavWwCGuOPsgs/uFg31ne iBEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750787635; x=1751392435; 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=XgZm1uyV1qb9UJ2sS7hNDxyPmGesubEoDQCnhuCBxpI=; b=vnGXj1KLaudajUwszw0K2a+0wyUuK7298UJdgsOLiHPxEsD6G+8QVOt4wGFlgmflVm BRrQ7sc5CSz9xTzXwz/NZryWKuXr74nVjM5UNVamS5T4DKH2qh3XjKLdy//IrBJ6dsa2 52GKpKclNzwgtME9/C846IfwgbvPsfhQrsKNvLqcyh+cQER/Sle0EwA8uPFxkgjtfoND Qf8qtn4Iwin3mUoBNyTL3N0NcGXh3G93RyEYikEqIEgc0yb51G9zQYAtXH3FznmFz6yY 0AtC8Nd0HvHC58yz3K5kjvAyj7TXxakeK0BLYsNZP4pQExW6BclqHOL25tXGhQefxCNh e9hA== X-Gm-Message-State: AOJu0Yx1J+hXRR2OzrOSEt01M1BVDVX6JQC0GNqUFI3vV1xrDdfeoOEb 9vNgoLs7YwBJOIhdepzpAQuZxaoaL6KuuubyG2GSEa12g2k6YEmi0aF7NYcwoB4EjvI= X-Gm-Gg: ASbGncubOHfegdO51n+jbXX2wEMdzafVU9cj9NQIXjeA0YRntqwsaU0HAaJ+82EJOdX Qa8QHTo977aIugtjwrfVrfxP7m8fQquUjDdVTp4MBunlML69yq9yUV2qc5OD0Okz69PBjWMA8E2 GfR+OEaz+fcV7gZvmCyKDHkkzaT3cd/bfO+r8Dg4ZnDm837w0YgOuaudBUzx9z+tSrhizog5fI4 EU5TM+m5mPbVEoPcV58ABbC3wc/gKBuLJMMOEAUMBVdj+9o3jlaQbz1j53UIRFP4XizihU0XltT g/aXBAoSrDI1Hd0JzdIsHNerl3vP+XQv1M/+a5B6hdlI6/WQNaQQqSeWvwcWPr4R3VJZlTVT X-Google-Smtp-Source: AGHT+IHl5bq3L6PjLF12ZxxbEmuUjNKTkpsdlH9wkPYTAmY3V8UjOzTZ+5ncSktukuYyasnQgx6BUw== X-Received: by 2002:a05:6a00:1828:b0:748:34a4:ab13 with SMTP id d2e1a72fcca58-74ad447719amr56028b3a.6.1750787635395; Tue, 24 Jun 2025 10:53:55 -0700 (PDT) From: Rowan Hart To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , Mahmoud Mandour , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Marcel Apfelbaum , Yanan Wang , Alexandre Iooss , Eduardo Habkost , Zhao Liu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Rowan Hart Subject: [PATCH v14 3/8] plugins: Add enforcement of QEMU_PLUGIN_CB flags in register R/W callbacks Date: Tue, 24 Jun 2025 10:53:46 -0700 Message-ID: <20250624175351.440780-4-rowanbhart@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250624175351.440780-1-rowanbhart@gmail.com> References: <20250624175351.440780-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::42e; envelope-from=rowanbhart@gmail.com; helo=mail-pf1-x42e.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: 1750787710636116600 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..c6e9ef1478 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; + } +} --=20 2.49.0 From nobody Sat Feb 7 07:38:57 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=1750787754; cv=none; d=zohomail.com; s=zohoarc; b=CLWklZYcd6UIQGUDtvwWbmuOPrpfbDL55Md8VORcbSe1ib65aJu8btWmZS4hWyXIadOyFkSqk7ASjCQtIogH276ymaWYXROoxbni7c7hPY/SunnqsywlvNK4w2RiO0v/AxtWkRGz14Iwr77S/K2/0uM9xUGT44my9ho61EeD3ec= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750787754; 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=rScIR27n9i6dN1NjlWQKj1zSHK/8glc3yPQGNsFP5G4=; b=MYDV3CK1xbNlfZykokzKqU2ywxHgDX6hZ/WR9tz9PaKi/6lEbS3p5FryoF/gNsZUzs/59SWv1eny/z1ouCRfGcXR2UpRA7iQe93pJFgDXnq1ktBO2XqBfze6Psvpp3su9nNjT8oYFAzFiz6i9/856K695HXK1IZ0kB35quSi68Q= 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 1750787754614668.8751567277541; Tue, 24 Jun 2025 10:55:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uU7qY-00031h-4m; Tue, 24 Jun 2025 13:54:14 -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 1uU7qL-0002x3-Cu for qemu-devel@nongnu.org; Tue, 24 Jun 2025 13:54:01 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uU7qH-0002mC-Um for qemu-devel@nongnu.org; Tue, 24 Jun 2025 13:54:00 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-73c17c770a7so6092256b3a.2 for ; Tue, 24 Jun 2025 10:53:57 -0700 (PDT) Received: from shemhazi.lan ([50.46.174.34]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b31f12427b7sm9318153a12.40.2025.06.24.10.53.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jun 2025 10:53:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750787636; x=1751392436; 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=rScIR27n9i6dN1NjlWQKj1zSHK/8glc3yPQGNsFP5G4=; b=Lg4F/LV5qgMMXgAQwd0WQ2BsyTpbc4KkFRls33YR3AmuwiFZK4IwLMfQK0flPiuq33 Bz6ZHoWXB2fJY/r/Q7JTWt7uLbOgPKbGgwPIqxMlHX7z9vXVCfpW2VipsTQdcjsfvVpp XUY7VwmP3KNuj55l9mDMgtZnEYwy3JllyaJizUXSMD607wZmVB3zXngcDPhW2vyQkv88 OACeCaCTg9kjZsAv4EEXYXEwMniewD372D4ai8jSVk9irfwqkAgki/gmeypITs3GgQap +fZfiCxJBMBCL3dCgxltvoX3dl85MuY9hvxlyKdycGrDtZ4HNPMoLD5QExw4nZHeQEWE /Jfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750787636; x=1751392436; 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=rScIR27n9i6dN1NjlWQKj1zSHK/8glc3yPQGNsFP5G4=; b=ZbHhNi+FBNsUQbT47/9WBFS3uImh/BedURSRNWlM+jD32s5FzIfzmf/lrXwewvMY3f cQU/tqs9IN8PjmR/VCwqJuHNItqVQYExqjcUHb6/DsIBaj8OztgwfTU4y6QXvRdWlr7Y gxWYKbtj+77CfA7cL+VSZhj6Mm5ST3yOV2iSEO/twst1lixgnL33suNQ56YQo3O+U8co ZiEjyA9Swj/ii2H8AYq9b4CLk0pHjfNiWCqJdKENNoYlBC6lxwKZfi2U309g3UJbEAdz MgugAvBDrPMsoSIHgOrfqdX1ycsbKN5bQa1Zbxa4fJd/Gd97aDdluwOOKs5zRdQzGem4 Dkkw== X-Gm-Message-State: AOJu0YxRfMQrSeEQBYGm9QkftlRNXUrPibLMdGjHY+7N/yODNAjNSczh 2412RVhH/YFRMKstsCEPMeMNnB86+XdDlAxwPb5np+AFn6a6BlxZcAUqqQyS5uwS778= X-Gm-Gg: ASbGncsyxtBvheHdHqTLvVIFK+K5hhGAwujkA5/JBXDA+sG7m5TtCwBvuoFnhjXxVMC jNPl0cj0frDPgdmXzDFHaPFcc36DuVwlEBkXOhMFr9qspuSrFtGC2PwMuvccBNVKLMZwUtG+Ht3 l0H4GtVVCLPKlB60Iu6lovDkoIFIGhmvbNLGwSzULAsHaz3lPp75kbRAbJ2uRTNiArflCPReaEe ldaM1Pcn5qN+kaOMxthqXKmDMClQrEVyB2MlKZKrgVq7o+4Yntbt0c73QfW9EwofdeM0krlATWK wlhyzJoR72wI+cXuygR74EkxTSLtNyE2IK6BIOQiHGvH3mPM5cWcKJPk2K1dlA== X-Google-Smtp-Source: AGHT+IHXoW7PY+On6qtK8QvNTetC75fyOjixusiE3pWIbQVk5uq6IBKEwN7veUbAjiNwX+8AksPFIA== X-Received: by 2002:a05:6a00:2d91:b0:736:35d4:f03f with SMTP id d2e1a72fcca58-74ad44774famr58471b3a.6.1750787636301; Tue, 24 Jun 2025 10:53:56 -0700 (PDT) From: Rowan Hart To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , Mahmoud Mandour , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Marcel Apfelbaum , Yanan Wang , Alexandre Iooss , Eduardo Habkost , Zhao Liu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Rowan Hart Subject: [PATCH v14 4/8] plugins: Add memory virtual address write API Date: Tue, 24 Jun 2025 10:53:47 -0700 Message-ID: <20250624175351.440780-5-rowanbhart@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250624175351.440780-1-rowanbhart@gmail.com> References: <20250624175351.440780-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::434; envelope-from=rowanbhart@gmail.com; helo=mail-pf1-x434.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: 1750787756967116600 Content-Type: text/plain; charset="utf-8" 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 07:38:57 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=1750787707; cv=none; d=zohomail.com; s=zohoarc; b=JiTzSliG/3IZNQbkc6YeL9WYpTPnlnel0rKIuXPpU6KEDRkzCDXOJ+FQfAXo+kekI0pY3DE0kn6Zurd1Fx8LTKyeS7znwldS1+68lY8ZRvUfB08y2vL8u/G6cwMYPNCyLUoPLtXMdVcQk8RN+VnCb9DDcw6OyMIBR44f77YjjbU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750787707; 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=OtJopb71Bjtknx1z8AVryV7VrcH2fQAmDjiMwTOEueY=; b=M8CYm27m7rOr1i0mX1QDULX8kdy/Za7gnWH+BfsBUgVidFQLcLVM0Jalz1BAKLl8qEcZLrQVOv0pRXTwdinvVPA5pPa1Z2IlXbHQfjkan3+N2BAsOvg3kR4aAp43rb8L5Wi1IbXWZvAn/fEWFP1qLFlp1EUoHLm7WFhKpOM23u8= 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 1750787707974515.648525685675; Tue, 24 Jun 2025 10:55:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uU7qZ-00033s-MB; Tue, 24 Jun 2025 13:54:15 -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 1uU7qL-0002x5-D1 for qemu-devel@nongnu.org; Tue, 24 Jun 2025 13:54:01 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uU7qJ-0002mG-8s for qemu-devel@nongnu.org; Tue, 24 Jun 2025 13:54:01 -0400 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-b31c84b8052so963324a12.1 for ; Tue, 24 Jun 2025 10:53:58 -0700 (PDT) Received: from shemhazi.lan ([50.46.174.34]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b31f12427b7sm9318153a12.40.2025.06.24.10.53.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jun 2025 10:53:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750787637; x=1751392437; 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=OtJopb71Bjtknx1z8AVryV7VrcH2fQAmDjiMwTOEueY=; b=YcSVlnTjuG3sMiIAjUPAPiruAcuzxGCLqg6S2/1o0/GsQ3K6sKnYV10GTMBDnudb5+ scs2p2zHFx04H72TdUeZnpY0jla+bTymA0uQ0xAwkJfZUBqm3+f/TvGTJf5/aNnEOdQG Pcl8pCgdABJ5aDnpwozxGXIsFILV14fD+JAtR+fUbAUdbY7ZTrkq+11WCFZzh77FhLI4 MsCGzvH37xF7u8e0cE3LWQ3F48mTWREEvNOIEZHB8mdzJyavggVljb/GeBCSghfNeZSe Zq/0NhSktxqam1pc2oIxgVJiJrfnxhDNpQ2TBso6yhKldl2j4Mi3u2sIc97E1CBZfG+k +Aaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750787637; x=1751392437; 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=OtJopb71Bjtknx1z8AVryV7VrcH2fQAmDjiMwTOEueY=; b=VYm5gFA1EK+XnFqS7VPwMJsOvlTeTKOXh2HHoXv4jv7qEB9gBA1XhxiUhhImzZG8lA hKFP2RCxqMNUpAK4QjhsdIag6UQfW1ZlAVqsEZBNoTKj/RZb/xmPLayH/UzmZn8Z4ugv T3gZ14HlVU78fIzdxM7861DGz5jmHf5O1uT4EB+f6D9IiObYyBhDsJOT56agOIcVbnVK 7ijixnFtbtRiza8XiBplmgjnD/FSxF36OwMqtPq0ViIClY3731YtwKO8h/4B47A4Xo7s mJmP85YK1pffzb2YxcY2tHxkx5v8XQ5FhkitnxHWfWSen0xTya5M1Q/f0OcC4RyhmCjW zEHQ== X-Gm-Message-State: AOJu0YziqZHssh+2s8olkrfWpJU7xe32lLeO+fH6C93eQmGIxjat8wgj VVnDbvM3FdwBcgJVEbPzn2f97ZVpJYckPwqgwkzGWxCSXF7yG5oeNL5xf/US7QEIiEw= X-Gm-Gg: ASbGncv+8llAi5XYSq7MdHfoUC7gW8DbzcmbSUwu/TogXVO02RNuTv75M0zBohiUZ/Y GlJvKYRXxdLMYNb9BQuTVDrTC450nRURIDNisv/2uNCKlgWZThnlpMtDG6g4ckQ73WWyId3NX1I 6FY/lfCXayeNJZhquQRAwZkNl5ltUe7rwgYCRnKX9Vhdc9QrSMbHnrONcWmXlvJH0L6sV48i16n o3qQg27+9Tbbq2WGZSQUhOgCK2tU4I82QmfAiK2C5e4IyL3ulqlhpjDUZ/DG8OvlncCrfUXVZhS /LuKJA22ePd7HF54a7WVQ3j4nzyvTHSGo/6RAsGt3/+z9gID9KiGckSUc0XEQw== X-Google-Smtp-Source: AGHT+IH2jXaMz9ZxRv//188PWNwal91X/FdGY0bw/PeutNNPRybGtZ6hBmcbnLFzrxcjeACT2Gh7Rg== X-Received: by 2002:a05:6a21:68e:b0:21a:efe4:5c6f with SMTP id adf61e73a8af0-22026d34e2bmr28540777637.2.1750787637169; Tue, 24 Jun 2025 10:53:57 -0700 (PDT) From: Rowan Hart To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , Mahmoud Mandour , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Marcel Apfelbaum , Yanan Wang , Alexandre Iooss , Eduardo Habkost , Zhao Liu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Rowan Hart Subject: [PATCH v14 5/8] plugins: Add memory hardware address read/write API Date: Tue, 24 Jun 2025 10:53:48 -0700 Message-ID: <20250624175351.440780-6-rowanbhart@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250624175351.440780-1-rowanbhart@gmail.com> References: <20250624175351.440780-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::535; envelope-from=rowanbhart@gmail.com; helo=mail-pg1-x535.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: 1750787710585116600 Content-Type: text/plain; charset="utf-8" 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 07:38:57 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=1750787698; cv=none; d=zohomail.com; s=zohoarc; b=CEGSVE/KjcXGlzZEgbrN8iVGLggjQxwUtsg3APaJYzeTSdhjWCbR9YCJ1GsFJ0sT33xhEpeAqdK+yGkWDUD+J7o0/7Ecr885rM0B0Nd01FaTmtNXr7Ym3dgirl8sfShiwH9mb7+Kc3NB6yvPtMR2/UPA9QyimllRnl7ZXIETMQ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750787698; 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=bgnfCU/cr4K0NH5U9mJ9R96Apm9sPszlIy7NNSUL0Bw=; b=C3o2DwdCdaYz2TgT2Y4HoDDDokb6vJ4geXU3+FGdqv4OFqTWuy140XxgY7T72kuSaM5Gi7Nufem+UtWTx//TI1dKKobV+E1MPsGrOKba47nI/mXlbHt71Ipv8HMHEmmdrjrYPXl70H8brw7IE1E3Zf++IgVZF1JXZ51erayW0Fs= 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 1750787698511212.30951886153173; Tue, 24 Jun 2025 10:54:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uU7qb-00034k-9b; Tue, 24 Jun 2025 13:54: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 1uU7qM-0002xO-Ct for qemu-devel@nongnu.org; Tue, 24 Jun 2025 13:54:03 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uU7qJ-0002mP-OS for qemu-devel@nongnu.org; Tue, 24 Jun 2025 13:54:01 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-234bfe37cccso11197785ad.0 for ; Tue, 24 Jun 2025 10:53:59 -0700 (PDT) Received: from shemhazi.lan ([50.46.174.34]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b31f12427b7sm9318153a12.40.2025.06.24.10.53.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jun 2025 10:53:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750787638; x=1751392438; 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=bgnfCU/cr4K0NH5U9mJ9R96Apm9sPszlIy7NNSUL0Bw=; b=nAvnkZNcf/8RmUvgfcUjEQwvEVM3OeeCOC7aYLIXc5CMOgR+ZEmkDWvUL6SmKmr1as ezQGSxZLSV2YeVQpxkt9/7Fil3lNTs4bPx+2OlUqWJBMrBsm/11MAArsc12v/KFjxu4l ac8Vm3X7R+YDhPA+c1g0WUu6RLzQGEmRF/bptkZRLd4FNAixMtQVBzTj8zSZ6Q6YYnhu yBHY4jOW+u27kCmuIEOGpfO2IfnEUgo0DeYCmEB6SQ8J964CQzL7His+gwsFLOSvuT43 lWZ3ELJgJ2ZZH7gsI+6vES+o7N0aihSQNMVGkROJNdwc/RcaJezw7FxNtxl9FEk91SsN Z9tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750787638; x=1751392438; 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=bgnfCU/cr4K0NH5U9mJ9R96Apm9sPszlIy7NNSUL0Bw=; b=s62u9kU4UfW39kWC58hxEFv9QlOk1aCiYq7qX+uQfydJMbl2aeWhE6Vqz0aa+I9EP5 gkKyOq+QK8JuuDPHRAm1x6+TBJZpw09qY88yatnzZ33+cJSVDwUQTTfFveQ2Af2dmHZ3 39dacMUfUjcIzgbYHgCDlY27y+4CUJQTDcaTWcwa5ZXAplC8Do1DLrxzAHJnIOxaHPow dfN8dOAyZ3TDco7tawxP4+yYE5LvMz3+G+wT5mXlPz6+Gepr4jTc8mRMBM7YE0/7Iuub lGgL90YncYcqh/A4tb7NtIh1uvV6CApnTh1s6fDzFuC37aFv+b2Pz5EqbWmYc+BvOaZp Fg7Q== X-Gm-Message-State: AOJu0YyMq2eM5LbYrYie8mgU/02+/I8YwCeCJN8CmbblTfyfHP4x+HLe luDirP3mnTzDo1F0nb9BEGhvu2qXkkYQUv6eUhP7xA4fUCL5St7cXPsPqwzR0bVX8I4= X-Gm-Gg: ASbGnctQ7cr88pw8SpD6NciwD7Ua4toscheLp9OmsUaky81ar4oZIlZcssu7ucewHoI 6T3/zElnrbFsIxK+qnwr7sfJgAjdvPm52KnKllMsr+SiWSkB2bSFaTdtjNORrixYuCHrzmUXRQ+ 0/JLvm+ID+SbUtMID/k00N9Q3jLhJQu6DwEnmwo3elj3rm1IdC5dEvjPa9T6tKjTuu9jNM6Vw+z GhnWl4ZQysGYKqfSv9YVFAsgzFALBM56Pn9K3weMhM/9oJHyqOeZh5ysatHIVGbO2slY+0jhiCL oXq/qAyyczj+CIgUTr3lZubx1fzJkA8iv3bJBmnGGCzmItTSZcb9sy//eMwFiw== X-Google-Smtp-Source: AGHT+IE7Tq1UhNsdomTEAsnLHhXDAJZcYnLJEfezoQP82WjOqwfquQpG/ww+NZLqNVQuA7t/P5URzA== X-Received: by 2002:a17:902:d492:b0:234:8c64:7878 with SMTP id d9443c01a7336-2382409e007mr3077785ad.11.1750787638073; Tue, 24 Jun 2025 10:53:58 -0700 (PDT) From: Rowan Hart To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , Mahmoud Mandour , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Marcel Apfelbaum , Yanan Wang , Alexandre Iooss , Eduardo Habkost , Zhao Liu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Rowan Hart Subject: [PATCH v14 6/8] tests/tcg: Remove copy-pasted notes and from i386 and add x86_64 system tests to tests Date: Tue, 24 Jun 2025 10:53:49 -0700 Message-ID: <20250624175351.440780-7-rowanbhart@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250624175351.440780-1-rowanbhart@gmail.com> References: <20250624175351.440780-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::62a; envelope-from=rowanbhart@gmail.com; helo=mail-pl1-x62a.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: 1750787701321116600 Content-Type: text/plain; charset="utf-8" The x86_64-softmmu Makefile seems to have been copy-pasted from the i386 Makefile at some point in the past. Cleaning up a vestigial unused variable and removing some outdated comments. Signed-off-by: Rowan Hart --- tests/tcg/x86_64/Makefile.softmmu-target | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/tcg/x86_64/Makefile.softmmu-target b/tests/tcg/x86_64/Ma= kefile.softmmu-target index ef6bcb4dc7..d3e09708a5 100644 --- a/tests/tcg/x86_64/Makefile.softmmu-target +++ b/tests/tcg/x86_64/Makefile.softmmu-target @@ -1,13 +1,11 @@ # -# x86 system tests -# -# This currently builds only for i386. The common C code is built -# with standard compiler flags however so we can support both by -# adding additional boot files for x86_64. +# x86_64 system tests # =20 -I386_SYSTEM_SRC=3D$(SRC_PATH)/tests/tcg/i386/system X64_SYSTEM_SRC=3D$(SRC_PATH)/tests/tcg/x86_64/system +X64_SYSTEM_TESTS=3D$(patsubst $(X64_SYSTEM_SRC)/%.c, %, $(wildcard $(X64_S= YSTEM_SRC)/*.c)) + +VPATH+=3D$(X64_SYSTEM_SRC) =20 # These objects provide the basic boot code and helper functions for all t= ests CRT_OBJS=3Dboot.o @@ -18,7 +16,7 @@ LDFLAGS=3D-Wl,-T$(LINK_SCRIPT) -Wl,-melf_x86_64 CFLAGS+=3D-nostdlib -ggdb -O0 $(MINILIB_INC) LDFLAGS+=3D-static -nostdlib $(CRT_OBJS) $(MINILIB_OBJS) -lgcc =20 -TESTS+=3D$(MULTIARCH_TESTS) +TESTS+=3D$(MULTIARCH_TESTS) $(X64_SYSTEM_TESTS) EXTRA_RUNS+=3D$(MULTIARCH_RUNS) =20 # building head blobs --=20 2.49.0 From nobody Sat Feb 7 07:38:57 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=1750787721; cv=none; d=zohomail.com; s=zohoarc; b=jMDg6dAeYC0O3c22McxGYBjeb8uKVyDYUnKyTbHYhX5nH3jbI0M3OPuv17+uV+unlcdNSIfUsFhUh4YRTcAbouKe3hFDGgZPC+Hpge8FwDLGYxlhu74gg6Z50gu7ChRLgqE6L4NeGb5OMtWwI6ukCjZFh62pL/yXC06mFePrjAk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750787721; 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=Y+Cga35u/V2dpyJodTGHeWA+Et2BkhQsp9yfYqFvkQ8=; b=kUcb9LJmtU/CWyS1Q070Bpoc7ebAwBQqeBNBh/8A1ZUFq2qrMVvsvgz2iQ9u5uXzFAwVsY4UB1l+9owszxpZqKcEKS8C8aN0waki3ndm4Agpo8SUsAhTHRKKiS5Bqb/0UXFo559V1+fiTYrlbsZNV1LZ5bFGFk6uVY8RxsAQcCg= 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 17507877219231017.3408282375703; Tue, 24 Jun 2025 10:55:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uU7qY-00032n-Oi; Tue, 24 Jun 2025 13:54:14 -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 1uU7qP-0002yW-O1 for qemu-devel@nongnu.org; Tue, 24 Jun 2025 13:54:08 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uU7qL-0002mf-3P for qemu-devel@nongnu.org; Tue, 24 Jun 2025 13:54:03 -0400 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-b31c978688dso604876a12.1 for ; Tue, 24 Jun 2025 10:54:00 -0700 (PDT) Received: from shemhazi.lan ([50.46.174.34]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b31f12427b7sm9318153a12.40.2025.06.24.10.53.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jun 2025 10:53:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750787639; x=1751392439; 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=Y+Cga35u/V2dpyJodTGHeWA+Et2BkhQsp9yfYqFvkQ8=; b=hU3fy2rSlV/jXgno1ORL5+A3KMTGDAo6NuxZ1TW5cnEbPTPywgQH5+O48m3HASmoUc /Y+FhAAVAzhkEh2OGS7RY298+kEmUn2xe8ajQ/mybxX3+T6RmPomfr9GuI1lhrii3giz MkpArKCG4aeZ+1weESdGLoE9kSXZOfOjOrUJvKErbP17vmsp3yXRWQ1g62ZBJv4+BsUT sgrWxMgi6u6hEF91LoRdifE/CS4fQI3yE972AVmdBxpbywoprDrT3gVePtYBwkN+PG2E yeNibQCaSg33BR7eyTOAIb+u22pn6kyx67r0tH2y/yuq0ibdtxUI+LkNYTiSe2udbpGY jTCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750787639; x=1751392439; 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=Y+Cga35u/V2dpyJodTGHeWA+Et2BkhQsp9yfYqFvkQ8=; b=dNOFYFXNh56Us734M8AYCyWQCa4wdAzUM10Y4lTpN2ZekeRY4R0/QsWxuKnTLOd1lh zw1nLionb1cRuryrJzui60pOlUqS1NRISEgie5aF4ADSgDSUpQyCRhoymFwj/upQNuXI rKI2FUZymo4alKWRO61LMSyVh3NfmqWwIW41d085DfUheq8Bj+BAXSIkdXxEq53Vv47M n7jHfTxxrJu6JvjoW1lWhvlm6kIwFc004UmA5naqCsDJa005y6CpAyVik7j5lJoA92yY 0bXz5SNLWWwG5M/y020AWNv1twfzxD0SE2xUMU2iMPwpcZXuRT0hVDPzlfGPV+jD8Bqx JCyQ== X-Gm-Message-State: AOJu0Yz0QQMRjgX/E9VBfYvK+zmpiBAumVp6NeH8uJkhBbDcnrJ3vkqa H/XzAMWggAjSJTg76cBajiD6g7xmsvqfJizKAKXrjnb8pWeXFHusJnKsU913eiA+7IA= X-Gm-Gg: ASbGncv3hPYxgabWwvD3SC6E3UzREeMchvYkSSbCuOp95lkcQQeiOcWT5DnSV2Rxv+4 ihRrQ9vdwqoDMbl+Mqf49WEM/NofY5Ajlxe5dJ20OrShR2GCdlaQEfY49MQKBWX6eW4b4txlsps 9rvD2vwQgzhJwjTRtHxvKlNArjS2P4pgRqHNODvcnGklIXfp48F6OJnuoqJDeUXzWLGOxNEaucF ZwX0wI+XBpcArFAmJg443GRzVZP1ubb/lPfRLhhOAPFEo1AEMMTLVEHU1//pWtki90loOv0qZLA DYfhz32j8elfurlRhhlwPpL5343G3fEEfPwrGO+b1uETLxTsG6d6mhylkG+Mbg== X-Google-Smtp-Source: AGHT+IEss7mVJII0N/FGOaEP6zOohlbhIYoV5+9r+zw7gq4nhuk8dqVOYLq/Ro7YMz02bsi2WMJsHA== X-Received: by 2002:a05:6a21:100c:b0:220:41f6:7a6c with SMTP id adf61e73a8af0-2207cd6d697mr1059584637.40.1750787638842; Tue, 24 Jun 2025 10:53:58 -0700 (PDT) From: Rowan Hart To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , Mahmoud Mandour , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Marcel Apfelbaum , Yanan Wang , Alexandre Iooss , Eduardo Habkost , Zhao Liu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Rowan Hart Subject: [PATCH v14 7/8] plugins: Add patcher plugin and test Date: Tue, 24 Jun 2025 10:53:50 -0700 Message-ID: <20250624175351.440780-8-rowanbhart@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250624175351.440780-1-rowanbhart@gmail.com> References: <20250624175351.440780-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::532; envelope-from=rowanbhart@gmail.com; helo=mail-pg1-x532.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: 1750787722660116600 Content-Type: text/plain; charset="utf-8" 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. Reviewed-by: Pierrick Bouvier 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 029342282a..61a007d9e7 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 d3e09708a5..9ea24257d2 100644 --- a/tests/tcg/x86_64/Makefile.softmmu-target +++ b/tests/tcg/x86_64/Makefile.softmmu-target @@ -33,3 +33,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 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 07:38:57 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=1750787745; cv=none; d=zohomail.com; s=zohoarc; b=b5F+qt/ABh5AZlXci24drktqdAdvMMnbBzFq8ZP+Q1lcrd/3xpaGXG7PfuOIX0RGWSjw/0jydIPF1rVNg71VPUg2QBuq6i1/IX3+7ggF8IGmJ3b8dL1ISuiYZd3UNz5LfcS9jr3zp4nNAxIR49O3XTRpsJoiUyPW9Xj2cEdtULg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750787745; 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=NsQHVm/OyW/NFr6cysTM72YPPcsE1O1Z1YjRSYHSSgo=; b=YIdBHX/UBEJIdjy1cKvJ5RGOj9QTXPls0O5CWXs20ZxkOYmfixZlDIHUhkuD5A0ZnDSRE0MwbvrslIbj4GSpvkU3tGfmZap46gV1Dbb6yToFpfpeRJjwGArewsAJ9aHXAJmYnmvBg9rxXShEtrMSkDmymY9h9n4ngAbs7EMV36E= 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 1750787745111804.1386309420521; Tue, 24 Jun 2025 10:55:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uU7qX-00031g-T7; Tue, 24 Jun 2025 13:54:13 -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 1uU7qP-0002yV-Nu for qemu-devel@nongnu.org; Tue, 24 Jun 2025 13:54:08 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uU7qM-0002mn-5M for qemu-devel@nongnu.org; Tue, 24 Jun 2025 13:54:03 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-74ad4533ac5so9667b3a.0 for ; Tue, 24 Jun 2025 10:54:01 -0700 (PDT) Received: from shemhazi.lan ([50.46.174.34]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b31f12427b7sm9318153a12.40.2025.06.24.10.53.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jun 2025 10:53:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750787640; x=1751392440; 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=NsQHVm/OyW/NFr6cysTM72YPPcsE1O1Z1YjRSYHSSgo=; b=DexHvuKU3rWCESdUv8zWilZjNOxs6xvejK5zQcsMfZ8Dh5bNSNa3fCds8Vqixjgcqo qyH8ftOWj3J1LEFcAFBtG5IRgjM6Yqob920dUecwjqhpByelu7t9DazEoK8S1z9cGwsj PcpOPvUhXcUZTEG7lw9LnUjRamxQt+iGwS7vOLhUkAgGNKjqAtKePRvIysnFKWtLDeHf Qn1foje3WboIbtVfQ1SAtV6ZjaboNw9xWORtiLhGiYmAHa4BymihVtmJhgMSvJrtXv+/ RouEz4jXevwxm61IEzHive482chQOrU6U/ecDathrM8ETztfONMhZBt+1EmsoPct7Uvs uvDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750787640; x=1751392440; 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=NsQHVm/OyW/NFr6cysTM72YPPcsE1O1Z1YjRSYHSSgo=; b=U++UB8diMBMbIfqNuPeSQNrfD0amQWsdO/b9DecYUMp//It0E9pgYMcPBC3UKv5eF5 Mg2bo06KnImpVrTNDO2BhRGksRRIJj9BoVM9FL9JIDLbfwZudBKFrw2e7NW0ZAAmmPms VdBmp7Ypxulu+Phk+aQur+DAD/mX/JjiiKv1kkT5ZFXHezdOkmrfJcNIb2M7ohw3xZcc NRtNfX5KjFnDMA4FS9c8qbc251pNfNbvu6JSoltYPnoyB8ON+upTOEKNhkeH5DlbwImK gpSqPHH1oQjOP1iMeH3AHrwhVCqvTdB3Br+GAQAzoHn0AvUW+gCvvrOSR8isAF9Q6OMj RqTg== X-Gm-Message-State: AOJu0YwfE1SC+l/kVoDRrTdTxQq/3bw4G9Oh1krygGbKa6WsIvpIjWuB OIqnSEeDUHJd7zQQUtzHudoULcNd1iq3cDdLv+v89nNvyRocYmJjVCYOwCxZx2e1XYU= X-Gm-Gg: ASbGnctfNZqe2GZmnCCEwKfY2OHs/l9z5YCEM0X3w58B02dn6IjiJigBDyqYuIGB4FN dwtCYquMejlVNIx7JL14dprMpuDH5gq/xNg+Qx6KktqdUq2UEFmxt8+5IUhoKTEd9es+ECyKwC8 CzPDjxzIaU/ShattVchAEoXY2e4YkvLtQoBc1N665EvIG+WKi2KaeCXO6K9nmVdFYkUYk3X61WX gb+tnZsP7XSQPTkG52zU7YWeaq1blzhhXR/usejKi2LbH239cv0V6ti42D/mUihT7DuTMkUn7g9 aG+fZxzYYmblvREALCTkjbyRnumiVaOvmXarA10YQFqnTmJSAv9j++oZ7Ps46FlDO6OcJO5A X-Google-Smtp-Source: AGHT+IHghreWfc60aerczfg+OUSq06KbHz+yVlpzwBY0PemmjUKg9XMQCVWyVqwjJZ1QYZBtSdkc4w== X-Received: by 2002:a05:6a20:94c7:b0:220:480a:8dac with SMTP id adf61e73a8af0-2206a12e7e7mr7034675637.13.1750787639747; Tue, 24 Jun 2025 10:53:59 -0700 (PDT) From: Rowan Hart To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , Mahmoud Mandour , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Marcel Apfelbaum , Yanan Wang , Alexandre Iooss , Eduardo Habkost , Zhao Liu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Rowan Hart Subject: [PATCH v14 8/8] plugins: Update plugin version and add notes Date: Tue, 24 Jun 2025 10:53:51 -0700 Message-ID: <20250624175351.440780-9-rowanbhart@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250624175351.440780-1-rowanbhart@gmail.com> References: <20250624175351.440780-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::42e; envelope-from=rowanbhart@gmail.com; helo=mail-pf1-x42e.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: 1750787746660116600 Content-Type: text/plain; charset="utf-8" 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