qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Alexandre Iooss" <erdnaxe@crans.org>,
	"Mahmoud Mandour" <ma.mandourr@gmail.com>,
	"Pierrick Bouvier" <pierrick.bouvier@linaro.org>
Subject: [PULL 27/31] plugins/api: split out the vaddr/hwaddr helpers
Date: Sat,  8 Mar 2025 21:53:22 +0000	[thread overview]
Message-ID: <20250308215326.2907828-28-alex.bennee@linaro.org> (raw)
In-Reply-To: <20250308215326.2907828-1-alex.bennee@linaro.org>

These only work for system-mode and are NOPs for user-mode.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20250304222439.2035603-28-alex.bennee@linaro.org>

diff --git a/plugins/api-system.c b/plugins/api-system.c
index cb0dd8f730..38560de342 100644
--- a/plugins/api-system.c
+++ b/plugins/api-system.c
@@ -12,6 +12,10 @@
 
 #include "qemu/osdep.h"
 #include "qemu/main-loop.h"
+#include "qapi/error.h"
+#include "migration/blocker.h"
+#include "hw/boards.h"
+#include "qemu/plugin-memory.h"
 #include "qemu/plugin.h"
 
 /*
@@ -37,3 +41,57 @@ uint64_t qemu_plugin_entry_code(void)
 {
     return 0;
 }
+
+/*
+ * Virtual Memory queries
+ */
+
+static __thread struct qemu_plugin_hwaddr hwaddr_info;
+
+struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,
+                                                  uint64_t vaddr)
+{
+    CPUState *cpu = current_cpu;
+    unsigned int mmu_idx = get_mmuidx(info);
+    enum qemu_plugin_mem_rw rw = get_plugin_meminfo_rw(info);
+    hwaddr_info.is_store = (rw & QEMU_PLUGIN_MEM_W) != 0;
+
+    assert(mmu_idx < NB_MMU_MODES);
+
+    if (!tlb_plugin_lookup(cpu, vaddr, mmu_idx,
+                           hwaddr_info.is_store, &hwaddr_info)) {
+        error_report("invalid use of qemu_plugin_get_hwaddr");
+        return NULL;
+    }
+
+    return &hwaddr_info;
+}
+
+bool qemu_plugin_hwaddr_is_io(const struct qemu_plugin_hwaddr *haddr)
+{
+    return haddr->is_io;
+}
+
+uint64_t qemu_plugin_hwaddr_phys_addr(const struct qemu_plugin_hwaddr *haddr)
+{
+    if (haddr) {
+        return haddr->phys_addr;
+    }
+    return 0;
+}
+
+const char *qemu_plugin_hwaddr_device_name(const struct qemu_plugin_hwaddr *h)
+{
+    if (h && h->is_io) {
+        MemoryRegion *mr = h->mr;
+        if (!mr->name) {
+            unsigned maddr = (uintptr_t)mr;
+            g_autofree char *temp = g_strdup_printf("anon%08x", maddr);
+            return g_intern_string(temp);
+        } else {
+            return g_intern_string(mr->name);
+        }
+    } else {
+        return g_intern_static_string("RAM");
+    }
+}
diff --git a/plugins/api-user.c b/plugins/api-user.c
new file mode 100644
index 0000000000..867b420339
--- /dev/null
+++ b/plugins/api-user.c
@@ -0,0 +1,40 @@
+/*
+ * QEMU Plugin API - user-mode only implementations
+ *
+ * This provides the APIs that have a user-mode specific
+ * implementations or are only relevant to user-mode.
+ *
+ * Copyright (C) 2017, Emilio G. Cota <cota@braap.org>
+ * Copyright (C) 2019-2025, Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/plugin.h"
+
+/*
+ * Virtual Memory queries - these are all NOPs for user-mode which
+ * only ever has visibility of virtual addresses.
+ */
+
+struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,
+                                                  uint64_t vaddr)
+{
+    return NULL;
+}
+
+bool qemu_plugin_hwaddr_is_io(const struct qemu_plugin_hwaddr *haddr)
+{
+    return false;
+}
+
+uint64_t qemu_plugin_hwaddr_phys_addr(const struct qemu_plugin_hwaddr *haddr)
+{
+    return 0;
+}
+
+const char *qemu_plugin_hwaddr_device_name(const struct qemu_plugin_hwaddr *h)
+{
+    return g_intern_static_string("Invalid");
+}
diff --git a/plugins/api.c b/plugins/api.c
index ffccd71e4b..82241699a5 100644
--- a/plugins/api.c
+++ b/plugins/api.c
@@ -383,76 +383,6 @@ qemu_plugin_mem_value qemu_plugin_mem_get_value(qemu_plugin_meminfo_t info)
     return value;
 }
 
-/*
- * Virtual Memory queries
- */
-
-#ifdef CONFIG_SOFTMMU
-static __thread struct qemu_plugin_hwaddr hwaddr_info;
-#endif
-
-struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,
-                                                  uint64_t vaddr)
-{
-#ifdef CONFIG_SOFTMMU
-    CPUState *cpu = current_cpu;
-    unsigned int mmu_idx = get_mmuidx(info);
-    enum qemu_plugin_mem_rw rw = get_plugin_meminfo_rw(info);
-    hwaddr_info.is_store = (rw & QEMU_PLUGIN_MEM_W) != 0;
-
-    assert(mmu_idx < NB_MMU_MODES);
-
-    if (!tlb_plugin_lookup(cpu, vaddr, mmu_idx,
-                           hwaddr_info.is_store, &hwaddr_info)) {
-        error_report("invalid use of qemu_plugin_get_hwaddr");
-        return NULL;
-    }
-
-    return &hwaddr_info;
-#else
-    return NULL;
-#endif
-}
-
-bool qemu_plugin_hwaddr_is_io(const struct qemu_plugin_hwaddr *haddr)
-{
-#ifdef CONFIG_SOFTMMU
-    return haddr->is_io;
-#else
-    return false;
-#endif
-}
-
-uint64_t qemu_plugin_hwaddr_phys_addr(const struct qemu_plugin_hwaddr *haddr)
-{
-#ifdef CONFIG_SOFTMMU
-    if (haddr) {
-        return haddr->phys_addr;
-    }
-#endif
-    return 0;
-}
-
-const char *qemu_plugin_hwaddr_device_name(const struct qemu_plugin_hwaddr *h)
-{
-#ifdef CONFIG_SOFTMMU
-    if (h && h->is_io) {
-        MemoryRegion *mr = h->mr;
-        if (!mr->name) {
-            unsigned maddr = (uintptr_t)mr;
-            g_autofree char *temp = g_strdup_printf("anon%08x", maddr);
-            return g_intern_string(temp);
-        } else {
-            return g_intern_string(mr->name);
-        }
-    } else {
-        return g_intern_static_string("RAM");
-    }
-#else
-    return g_intern_static_string("Invalid");
-#endif
-}
-
 int qemu_plugin_num_vcpus(void)
 {
     return plugin_num_vcpus();
diff --git a/plugins/meson.build b/plugins/meson.build
index 9c9bc9e5bb..942b59e904 100644
--- a/plugins/meson.build
+++ b/plugins/meson.build
@@ -58,7 +58,7 @@ if host_os == 'windows'
   )
 endif
 
-user_ss.add(files('user.c'))
+user_ss.add(files('user.c', 'api-user.c'))
 system_ss.add(files('system.c', 'api-system.c'))
 
 common_ss.add(files('loader.c'))
-- 
2.39.5



  parent reply	other threads:[~2025-03-08 22:00 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-08 21:52 [PULL 00/31] testing, plugin and maintainer updates Alex Bennée
2025-03-08 21:52 ` [PULL 01/31] tests/functional: move aarch64 GPU test into own file Alex Bennée
2025-03-08 21:52 ` [PULL 02/31] tests/functional: factor out common code in gpu test Alex Bennée
2025-03-08 21:52 ` [PULL 03/31] tests/functional: ensure we have a GPU device for tests Alex Bennée
2025-03-08 21:52 ` [PULL 04/31] tests/functional: bail early if vkmark hangs Alex Bennée
2025-03-08 21:53 ` [PULL 05/31] tests/functional: skip vulkan tests with nVidia Alex Bennée
2025-03-08 21:53 ` [PULL 06/31] tests/functional: expand tests to cover virgl Alex Bennée
2025-03-08 21:53 ` [PULL 07/31] tests/functional: update the aarch64_virg_gpu images Alex Bennée
2025-03-08 21:53 ` [PULL 08/31] plugins: add explicit dependency in functional tests Alex Bennée
2025-03-08 21:53 ` [PULL 09/31] tests/functional: Introduce the dso_suffix() helper Alex Bennée
2025-03-08 21:53 ` [PULL 10/31] tests/functional: Allow running TCG plugins tests on non-Linux/BSD hosts Alex Bennée
2025-03-08 21:53 ` [PULL 11/31] libvirt-ci: bump to latest for vulkan-tools Alex Bennée
2025-03-08 21:53 ` [PULL 12/31] tests/vm: bump timeout for shutdown Alex Bennée
2025-03-08 21:53 ` [PULL 13/31] tests/tcg: mark test-vma as a linux-only test Alex Bennée
2025-03-08 21:53 ` [PULL 14/31] tests/tcg: add message to _Static_assert in test-avx Alex Bennée
2025-03-08 21:53 ` [PULL 15/31] tests/tcg: fix constraints in test-i386-adcox Alex Bennée
2025-03-08 21:53 ` [PULL 16/31] tests/tcg: enable -fwrapv for test-i386-bmi Alex Bennée
2025-03-08 21:53 ` [PULL 17/31] tests/tcg: Suppress compiler false-positive warning on sha1.c Alex Bennée
2025-03-08 21:53 ` [PULL 18/31] gitlab: add a new build_unit job to track build size Alex Bennée
2025-03-08 21:53 ` [PULL 19/31] tests/functional: add boot error detection for RME tests Alex Bennée
2025-03-08 21:53 ` [PULL 20/31] plugins/api: use qemu_target_page_mask() to get value Alex Bennée
2025-03-08 21:53 ` [PULL 21/31] plugins/loader: populate target_name with target_name() Alex Bennée
2025-03-08 21:53 ` [PULL 22/31] include/qemu: plugin-memory.h doesn't need cpu-defs.h Alex Bennée
2025-03-08 21:53 ` [PULL 23/31] plugins/api: clean-up the includes Alex Bennée
2025-03-08 21:53 ` [PULL 24/31] plugins/plugin.h: include queue.h Alex Bennée
2025-03-08 21:53 ` [PULL 25/31] plugins/loader: compile loader only once Alex Bennée
2025-03-08 21:53 ` [PULL 26/31] plugins/api: split out binary path/start/end/entry code Alex Bennée
2025-03-08 21:53 ` Alex Bennée [this message]
2025-03-08 21:53 ` [PULL 28/31] plugins/api: split out time control helpers Alex Bennée
2025-03-08 21:53 ` [PULL 29/31] plugins/api: build only once Alex Bennée
2025-03-08 21:53 ` [PULL 30/31] plugins/core: make a single build unit Alex Bennée
2025-03-08 21:53 ` [PULL 31/31] MAINTAINERS: remove widely sanctioned entities Alex Bennée
2025-03-09  3:44 ` [PULL 00/31] testing, plugin and maintainer updates Stefan Hajnoczi
2025-03-09 21:02   ` Alex Bennée
2025-03-10  5:44     ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250308215326.2907828-28-alex.bennee@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=erdnaxe@crans.org \
    --cc=ma.mandourr@gmail.com \
    --cc=pierrick.bouvier@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).