From patchwork Fri Feb 23 16:21:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 775155 Delivered-To: patch@linaro.org Received: by 2002:adf:a356:0:b0:33b:4db1:f5b3 with SMTP id d22csp438808wrb; Fri, 23 Feb 2024 08:46:19 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXgXlmL/+tfVYCBwqxyQu8grZHKkChLfWg3rCu6ljHp1/i6B9/es1ZqqVGDU1Cl40a7MP38VsaKCuqWCripEUkQ X-Google-Smtp-Source: AGHT+IG/eKb7SS2H//22s+M4Lxi+3uv+mpItVmDm3/H10OFwILF3UGyBIb9OUGf+bQviEE82cE1i X-Received: by 2002:a05:620a:1d98:b0:787:9e64:d8e3 with SMTP id pj24-20020a05620a1d9800b007879e64d8e3mr347031qkn.75.1708706778850; Fri, 23 Feb 2024 08:46:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708706778; cv=none; d=google.com; s=arc-20160816; b=qmX3ilskQ3iAkfCnHnU0IgEaPSgKcrP1DriLj/gI912VtDKktng9tJxPj4EHG48Rjq gPJd6DqJuxhO/JL9HErIHHJg/T3/v8ZnMJCqfIjqOvpXlWXX7LhQtGmuHilI/NLfyh3f k+KHSQwH+sE9vTQ57LBiUt9ly1h3YF6K/JSPN++pXVcSbFsVD003niYVWuZzoRYSodIZ QjnlaWuYKDKQfCWNdlJPuiFCRy1Rw+hgoaTkV9cWbvqNv1D4uHHlylJzkkJQEplJ0Bfy FD/K55Fg03pcUJGvMhJPk6VhdGW7ejdZKmUnvLBotbG5835uZY+C1T+RJcZ5zrtc7V+T JGgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WxIxN69mT6binki8hNqCNdb7O9kbw1pOd+inZU6HSwA=; fh=/YEu+IjZM84YWRDAuPeJeqMoLNTdSzM/iYv/jybOCWk=; b=OvaG2v4xmq2fYWqog148ruQIELcjmQ78uMUkwR7RUVMIkLj+42SM21rOCNP5qq5Qt2 Twc90ToqM2jXM41PKWms62pfHVph+3Gk3vjYObV23DjF6hUhtnjmxTy7Mz7/YxPTErqq TOsy+mJuF/RFivN8N2SqHO41z+ql7109IvKUol4ty7AuUBkDG45rMsYXmFhzqBaM5w9A V0XFt4WAEaxjyYT27VxW2uZdqH33nUU6WCql9HrEFy6m0/+3VktMm7ldgnQ/8k7SJsOz neCC+gMQuNvtgR/9DIjFUX+B5AG69A3Ofh/ttNWHgRa7GmZB2GWD3pw4E6sESZVZOjh9 Xm1A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vZLecIZe; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id de14-20020a05620a370e00b00785d5a7e686si16790088qkb.643.2024.02.23.08.46.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Feb 2024 08:46:18 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vZLecIZe; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdYfr-0000w3-1C; Fri, 23 Feb 2024 11:45:23 -0500 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 1rdYQU-00064y-SE for qemu-devel@nongnu.org; Fri, 23 Feb 2024 11:29:31 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdYQ3-0007Ho-5s for qemu-devel@nongnu.org; Fri, 23 Feb 2024 11:29:24 -0500 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-412985de139so738475e9.1 for ; Fri, 23 Feb 2024 08:28:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708705733; x=1709310533; 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=WxIxN69mT6binki8hNqCNdb7O9kbw1pOd+inZU6HSwA=; b=vZLecIZeTHbMg8rhojJXNxBSsDKxeO+jfxbB44ZbQNJNDb00bVLOg0SsSwVA4hB72Y hQPb5Jle9fHnYP39IJktBehuXMqWFGaqdJuMF9It5iMXH/toHZMDadCcDXnLS9YNEMLL DUoxXADF0inN2mOLuTIccXWbBp2Sjdv7XQ0n8Wno+qGfXDVYKb+Wsyz4UHYllLa1DcfL glatWm7gFswotffs+RfYnru1q0R2+zbe47m8k8NE8nYjv8HRrdYovEd9s5+B+FgDPgsj uSC62PC1QnmW6Bpj2B858njpRK9uTmog7SW7KS/uzDSz09ZCVswem1e942vPUM6O9Yc2 V6Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708705733; x=1709310533; 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=WxIxN69mT6binki8hNqCNdb7O9kbw1pOd+inZU6HSwA=; b=M+N7pwa1gtHpM2X1q0X/xUPnNSwIYmkwpHVH8r9GicBzipraK/MmAkrKGtvEtW4kXg 1VH3E6yF/+O8t+OPdvuhQy1iKthAA7IVRrco8MsvgiQRC3gY3KAOzfPcsR8/Awc9UAhV PxIx37bun2Q3ITlg6fKYRP2kXlpugl9abVZtoZenmb6/4YkIcyyzWIWlY1/K8lS7MaK+ pj95nXejoyVfyvQI+B3pTqVLSgNIdKxQlNwHJBYPylKDj46RRyWHZehprePcCXdIb1ez NjKeu0vO/52AnQ0BVJxLJfg3JknaAURMIwmqFWqjCQqiqNOTuxHoC29KhyQZG7iXCXTT GtcQ== X-Gm-Message-State: AOJu0Yxol83/86LGdNT89mqx/yjzF0MNDJn/mn7caJeqhD7+O/nt7pQK 1rmAYO4MBBjwC7F17diJ4IDgA7yIzNSOxjx2NAgQ1+zw7InprDmiXGwqzABS4pw= X-Received: by 2002:a05:600c:4752:b0:410:c69f:4db7 with SMTP id w18-20020a05600c475200b00410c69f4db7mr238820wmo.20.1708705732928; Fri, 23 Feb 2024 08:28:52 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 26-20020a05600c029a00b004128e903b2csm2803955wmk.39.2024.02.23.08.28.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 08:28:47 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 72A2C5F935; Fri, 23 Feb 2024 16:22:04 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Song Gao , qemu-s390x@nongnu.org, Liu Zhiwei , Pierrick Bouvier , Thomas Huth , Daniel Henrique Barboza , Bin Meng , Yanan Wang , Laurent Vivier , qemu-ppc@nongnu.org, David Hildenbrand , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Ilya Leoshkevich , Cleber Rosa , Nicholas Piggin , Marcel Apfelbaum , Eduardo Habkost , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= , Alexandre Iooss , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Daniel Henrique Barboza , qemu-arm@nongnu.org, qemu-riscv@nongnu.org, Palmer Dabbelt , Mahmoud Mandour , John Snow , Weiwei Li , Alistair Francis , Yoshinori Sato , Brian Cain , Paolo Bonzini , "Edgar E. Iglesias" , Michael Rolnik Subject: [PATCH v2 20/27] plugins: create CPUPluginState and migrate plugin_mask Date: Fri, 23 Feb 2024 16:21:55 +0000 Message-Id: <20240223162202.1936541-21-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240223162202.1936541-1-alex.bennee@linaro.org> References: <20240223162202.1936541-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32f.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org We are going to want to keep track of some per-vCPU data for plugins and the logical place to do so is in track it in CPUState. For now this just moves the plugin_mask (renamed to event_mask) as the memory callbacks are accessed directly by TCG generated code. Signed-off-by: Alex Bennée Reviewed-by: Pierrick Bouvier --- include/hw/core/cpu.h | 11 +++++++---- include/qemu/plugin.h | 13 +++++++++++++ include/qemu/typedefs.h | 1 + accel/tcg/plugin-gen.c | 3 ++- hw/core/cpu-common.c | 1 + plugins/core.c | 12 +++++++++--- 6 files changed, 33 insertions(+), 8 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 4b659799b00..af1a29526d4 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -31,7 +31,6 @@ #include "qemu/rcu_queue.h" #include "qemu/queue.h" #include "qemu/thread.h" -#include "qemu/plugin-event.h" #include "qom/object.h" typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size, @@ -434,7 +433,8 @@ struct qemu_work_item; * @kvm_fd: vCPU file descriptor for KVM. * @work_mutex: Lock to prevent multiple access to @work_list. * @work_list: List of pending asynchronous work. - * @plugin_mask: Plugin event bitmap. Modified only via async work. + * @plugin_mem_cbs: active plugin memory callbacks + * @plugin_state: per-CPU plugin state * @ignore_memory_transaction_failures: Cached copy of the MachineState * flag of the same name: allows the board to suppress calling of the * CPU do_transaction_failed hook function. @@ -526,10 +526,13 @@ struct CPUState { /* Use by accel-block: CPU is executing an ioctl() */ QemuLockCnt in_ioctl_lock; - DECLARE_BITMAP(plugin_mask, QEMU_PLUGIN_EV_MAX); - #ifdef CONFIG_PLUGIN + /* + * The callback pointer stays in the main CPUState as it is + * accessed via TCG (see gen_empty_mem_helper). + */ GArray *plugin_mem_cbs; + CPUPluginState *plugin_state; #endif /* TODO Move common fields from CPUArchState here. */ diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index b0c5ac68293..0e7b9693d80 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -186,6 +186,19 @@ struct qemu_plugin_insn *qemu_plugin_tb_insn_get(struct qemu_plugin_tb *tb, return insn; } +/** + * struct CPUPluginState - per-CPU state for plugins + * @event_mask: plugin event bitmap. Modified only via async work. + */ +struct CPUPluginState { + DECLARE_BITMAP(event_mask, QEMU_PLUGIN_EV_MAX); +}; + +/** + * qemu_plugin_create_vcpu_state: allocate plugin state + */ +CPUPluginState * qemu_plugin_create_vcpu_state(void); + void qemu_plugin_vcpu_init_hook(CPUState *cpu); void qemu_plugin_vcpu_exit_hook(CPUState *cpu); void qemu_plugin_tb_trans_cb(CPUState *cpu, struct qemu_plugin_tb *tb); diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index d7c703b4ae9..a028dba4d0b 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -42,6 +42,7 @@ typedef struct CompatProperty CompatProperty; typedef struct ConfidentialGuestSupport ConfidentialGuestSupport; typedef struct CPUAddressSpace CPUAddressSpace; typedef struct CPUArchState CPUArchState; +typedef struct CPUPluginState CPUPluginState; typedef struct CpuInfoFast CpuInfoFast; typedef struct CPUJumpCache CPUJumpCache; typedef struct CPUState CPUState; diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index b37ce7683e6..ac6b52b9ec9 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -43,6 +43,7 @@ * CPU's index into a TCG temp, since the first callback did it already. */ #include "qemu/osdep.h" +#include "qemu/plugin.h" #include "cpu.h" #include "tcg/tcg.h" #include "tcg/tcg-temp-internal.h" @@ -831,7 +832,7 @@ bool plugin_gen_tb_start(CPUState *cpu, const DisasContextBase *db, { bool ret = false; - if (test_bit(QEMU_PLUGIN_EV_VCPU_TB_TRANS, cpu->plugin_mask)) { + if (test_bit(QEMU_PLUGIN_EV_VCPU_TB_TRANS, cpu->plugin_state->event_mask)) { struct qemu_plugin_tb *ptb = tcg_ctx->plugin_tb; int i; diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index 68786360ea5..6a8c290fc75 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -224,6 +224,7 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) /* Plugin initialization must wait until the cpu start executing code */ if (tcg_enabled()) { + cpu->plugin_state = qemu_plugin_create_vcpu_state(); async_run_on_cpu(cpu, qemu_plugin_vcpu_init__async, RUN_ON_CPU_NULL); } diff --git a/plugins/core.c b/plugins/core.c index 2392bbb8889..83745663f32 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -17,6 +17,7 @@ #include "qapi/error.h" #include "qemu/lockable.h" #include "qemu/option.h" +#include "qemu/plugin.h" #include "qemu/rcu_queue.h" #include "qemu/xxhash.h" #include "qemu/rcu.h" @@ -53,7 +54,7 @@ struct qemu_plugin_ctx *plugin_id_to_ctx_locked(qemu_plugin_id_t id) static void plugin_cpu_update__async(CPUState *cpu, run_on_cpu_data data) { - bitmap_copy(cpu->plugin_mask, &data.host_ulong, QEMU_PLUGIN_EV_MAX); + bitmap_copy(cpu->plugin_state->event_mask, &data.host_ulong, QEMU_PLUGIN_EV_MAX); tcg_flush_jmp_cache(cpu); } @@ -208,6 +209,11 @@ plugin_register_cb_udata(qemu_plugin_id_t id, enum qemu_plugin_event ev, do_plugin_register_cb(id, ev, func, udata); } +CPUPluginState * qemu_plugin_create_vcpu_state(void) +{ + return g_new0(CPUPluginState, 1); +} + void qemu_plugin_vcpu_init_hook(CPUState *cpu) { bool success; @@ -356,7 +362,7 @@ qemu_plugin_vcpu_syscall(CPUState *cpu, int64_t num, uint64_t a1, uint64_t a2, struct qemu_plugin_cb *cb, *next; enum qemu_plugin_event ev = QEMU_PLUGIN_EV_VCPU_SYSCALL; - if (!test_bit(ev, cpu->plugin_mask)) { + if (!test_bit(ev, cpu->plugin_state->event_mask)) { return; } @@ -378,7 +384,7 @@ void qemu_plugin_vcpu_syscall_ret(CPUState *cpu, int64_t num, int64_t ret) struct qemu_plugin_cb *cb, *next; enum qemu_plugin_event ev = QEMU_PLUGIN_EV_VCPU_SYSCALL_RET; - if (!test_bit(ev, cpu->plugin_mask)) { + if (!test_bit(ev, cpu->plugin_state->event_mask)) { return; }