From patchwork Sat Sep 16 08:01:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1835428 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=Nnf8eKYg; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RnkCd5lDxz1yfd for ; Sat, 16 Sep 2023 18:06:21 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qhQGu-0004If-Df; Sat, 16 Sep 2023 04:03:20 -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 1qhQGs-0004E6-Rg for qemu-devel@nongnu.org; Sat, 16 Sep 2023 04:03:18 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qhQGk-0006DH-2d for qemu-devel@nongnu.org; Sat, 16 Sep 2023 04:03:18 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-68a3ced3ec6so2699243b3a.1 for ; Sat, 16 Sep 2023 01:03:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1694851387; x=1695456187; 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=ilI8SXEV4hZ7IsqJh+1hYxWm1mnGnjzep4yVtP0lQYY=; b=Nnf8eKYgRLkt6tQNHJn43Vl+Q3QH1HneuLciFYfYoctsRu0+/UF8QWe0XERncil+2R TefrRH9Ba9zU8JvwejWc9a6kAJlwCYarfxJkKeZaAyE2B8yTc0HEJ2+lS0PT3EPc5aPT LgQXR2WFCMlbd0rP3MLEPYqkNVSxGvrZe74fyH5fFIerwzL+7LhIVgVPuxR004C3CDmG DQHcdHbQYznjobCNI8d2Ys/c8rJNDz/oJlaMfrHUJqu4GySMrJ/dZSVJ/pgiuXnAvLxq 3SBlMI7VuVz2prxgAxQPOHknOnP9xiTT37/9CY1097DeEGtr7vOHVppqyFLtxAKhRErq QpoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694851387; x=1695456187; 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=ilI8SXEV4hZ7IsqJh+1hYxWm1mnGnjzep4yVtP0lQYY=; b=ZEvcs2fb/hEP6IC5Aayhx+Op91/uwz7jR2QshiQmULWlTX6tNIsv4vfjfFiB7+NUx/ 29ufOrZkqv8Wo7zkkthMubkJ+/w3NY/+V/krmw8kzgeADt0n51nf+oSJupdeklmm8VdV QMwCfhv4axFw+CW0KMA54QdDJpfIgaocfRXWroGtzW+vVfvrIUP5y6JU3g7dEeMNvkVI GIGxoiqq+ZvejgyOuTcp5dUpKg/ulJ1WjZmz7a5r9pRNrEu1mVoTKEv/sHQLnm6KgQaJ aVxWDaDf1KwqLeqYDpELavdEBJep0TrHQU3N9TzFvXdUfhOwgGEjJJvRysgjx6ojRqHL kYrw== X-Gm-Message-State: AOJu0YzHwQN4MOf/KPf6D3hNZCxcfK+zdU4tQgY7BHK4PzZh/l+RR/b3 CJpERvTP/ymXtBcjkdhOFfQvFw== X-Google-Smtp-Source: AGHT+IEId4pJwb3qGdRiWr56YM/8TdYIgz2GATItyEYapU0PzDHYa/8LNd0wGnovHTgGrzRT6zy/4w== X-Received: by 2002:a05:6a00:2d26:b0:68a:49bc:e0af with SMTP id fa38-20020a056a002d2600b0068a49bce0afmr3966053pfb.1.1694851387724; Sat, 16 Sep 2023 01:03:07 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id z21-20020aa791d5000000b0068a46cd4120sm4029484pfa.199.2023.09.16.01.03.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 01:03:07 -0700 (PDT) From: Akihiko Odaki To: Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Mikhail Tyutin , Aleksandr Anenkov , qemu-devel@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Akihiko Odaki , Alexandre Iooss , Mahmoud Mandour Subject: [PATCH v8 16/19] plugins: Allow to read registers Date: Sat, 16 Sep 2023 17:01:33 +0900 Message-ID: <20230916080149.129989-17-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230916080149.129989-1-akihiko.odaki@daynix.com> References: <20230916080149.129989-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::433; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x433.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org It is based on GDB protocol to ensure interface stability. The timing of the vcpu init hook is also changed so that the hook will get called after GDB features are initialized. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1706 Signed-off-by: Akihiko Odaki --- include/qemu/qemu-plugin.h | 52 +++++++++++++++++++++++++++++++++--- plugins/api.c | 20 ++++++++++++++ plugins/qemu-plugins.symbols | 3 +++ 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 50a9957279..40aae8db68 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -11,6 +11,7 @@ #ifndef QEMU_QEMU_PLUGIN_H #define QEMU_QEMU_PLUGIN_H +#include #include #include #include @@ -51,7 +52,7 @@ typedef uint64_t qemu_plugin_id_t; extern QEMU_PLUGIN_EXPORT int qemu_plugin_version; -#define QEMU_PLUGIN_VERSION 1 +#define QEMU_PLUGIN_VERSION 2 /** * struct qemu_info_t - system information for plugins @@ -218,8 +219,8 @@ struct qemu_plugin_insn; * @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 unused, plugins cannot read or change system - * register state. + * 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, @@ -664,4 +665,49 @@ uint64_t qemu_plugin_end_code(void); */ uint64_t qemu_plugin_entry_code(void); +/** + * qemu_plugin_find_register_file() - find register file + * + * @vcpu_index: the index of the vcpu context + * @name: the name of the register file. + * + * Returns the identifier of the register file if it was found, and a negative + * value otherwise. + * + * The names of register files are identical with names of GDB's standard + * target features with some extensions. For details, see: + * https://sourceware.org/gdb/onlinedocs/gdb/Standard-Target-Features.html + */ +int qemu_plugin_find_register_file(unsigned int vcpu_index, const char *name); + +/** + * qemu_plugin_find_register() - find register + * + * @vcpu_index: the index of the vcpu context + * @file: the register file identifier determined with + * qemu_plugin_find_register_file(). + * @name: the name of the register. + * + * The names of register are identical with names used in GDB's standard + * target features with some extensions. For details, see: + * https://sourceware.org/gdb/onlinedocs/gdb/Standard-Target-Features.html + */ +int qemu_plugin_find_register(unsigned int vcpu_index, int file, + const char *name); + +/** + * qemu_plugin_read_register() - read register + * + * @buf: the byte array to append the read register content to. + * @reg: the register identifier determined with + * qemu_plugin_find_register(). + * + * This function is only available in a context that register read access is + * explicitly requested. + * + * Returns the size of the read register. The content of @buf is in target byte + * order. + */ +int qemu_plugin_read_register(GByteArray *buf, int reg); + #endif /* QEMU_QEMU_PLUGIN_H */ diff --git a/plugins/api.c b/plugins/api.c index 2078b16edb..7c2843da1a 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -35,10 +35,12 @@ */ #include "qemu/osdep.h" +#include "qemu/main-loop.h" #include "qemu/plugin.h" #include "qemu/log.h" #include "tcg/tcg.h" #include "exec/exec-all.h" +#include "exec/gdbstub.h" #include "exec/ram_addr.h" #include "disas/disas.h" #include "plugin.h" @@ -442,3 +444,21 @@ uint64_t qemu_plugin_entry_code(void) #endif return entry; } + +int qemu_plugin_find_register_file(unsigned int vcpu_index, const char *name) +{ + QEMU_IOTHREAD_LOCK_GUARD(); + return gdb_find_feature(qemu_get_cpu(vcpu_index), name); +} + +int qemu_plugin_find_register(unsigned int vcpu_index, int file, + const char *name) +{ + QEMU_IOTHREAD_LOCK_GUARD(); + return gdb_find_feature_register(qemu_get_cpu(vcpu_index), file, name); +} + +int qemu_plugin_read_register(GByteArray *buf, int reg) +{ + return gdb_read_register(current_cpu, buf, reg); +} diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 71f6c90549..977f1fcfcb 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -42,4 +42,7 @@ qemu_plugin_tb_vaddr; qemu_plugin_uninstall; qemu_plugin_vcpu_for_each; + qemu_plugin_find_register_file; + qemu_plugin_find_register; + qemu_plugin_read_register; };