Skip to content

Commit 455a2d2

Browse files
committed
plugins/api: split out the vaddr/hwaddr helpers
These only work for system-mode and are NOPs for user-mode. Reviewed-by: Richard Henderson <[email protected]> Signed-off-by: Alex Bennée <[email protected]> Message-Id: <[email protected]>
1 parent 903e870 commit 455a2d2

File tree

4 files changed

+99
-71
lines changed

4 files changed

+99
-71
lines changed

plugins/api-system.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
#include "qemu/osdep.h"
1414
#include "qemu/main-loop.h"
15+
#include "qapi/error.h"
16+
#include "migration/blocker.h"
17+
#include "hw/boards.h"
18+
#include "qemu/plugin-memory.h"
1519
#include "qemu/plugin.h"
1620

1721
/*
@@ -37,3 +41,57 @@ uint64_t qemu_plugin_entry_code(void)
3741
{
3842
return 0;
3943
}
44+
45+
/*
46+
* Virtual Memory queries
47+
*/
48+
49+
static __thread struct qemu_plugin_hwaddr hwaddr_info;
50+
51+
struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,
52+
uint64_t vaddr)
53+
{
54+
CPUState *cpu = current_cpu;
55+
unsigned int mmu_idx = get_mmuidx(info);
56+
enum qemu_plugin_mem_rw rw = get_plugin_meminfo_rw(info);
57+
hwaddr_info.is_store = (rw & QEMU_PLUGIN_MEM_W) != 0;
58+
59+
assert(mmu_idx < NB_MMU_MODES);
60+
61+
if (!tlb_plugin_lookup(cpu, vaddr, mmu_idx,
62+
hwaddr_info.is_store, &hwaddr_info)) {
63+
error_report("invalid use of qemu_plugin_get_hwaddr");
64+
return NULL;
65+
}
66+
67+
return &hwaddr_info;
68+
}
69+
70+
bool qemu_plugin_hwaddr_is_io(const struct qemu_plugin_hwaddr *haddr)
71+
{
72+
return haddr->is_io;
73+
}
74+
75+
uint64_t qemu_plugin_hwaddr_phys_addr(const struct qemu_plugin_hwaddr *haddr)
76+
{
77+
if (haddr) {
78+
return haddr->phys_addr;
79+
}
80+
return 0;
81+
}
82+
83+
const char *qemu_plugin_hwaddr_device_name(const struct qemu_plugin_hwaddr *h)
84+
{
85+
if (h && h->is_io) {
86+
MemoryRegion *mr = h->mr;
87+
if (!mr->name) {
88+
unsigned maddr = (uintptr_t)mr;
89+
g_autofree char *temp = g_strdup_printf("anon%08x", maddr);
90+
return g_intern_string(temp);
91+
} else {
92+
return g_intern_string(mr->name);
93+
}
94+
} else {
95+
return g_intern_static_string("RAM");
96+
}
97+
}

plugins/api-user.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* QEMU Plugin API - user-mode only implementations
3+
*
4+
* This provides the APIs that have a user-mode specific
5+
* implementations or are only relevant to user-mode.
6+
*
7+
* Copyright (C) 2017, Emilio G. Cota <[email protected]>
8+
* Copyright (C) 2019-2025, Linaro
9+
*
10+
* SPDX-License-Identifier: GPL-2.0-or-later
11+
*/
12+
13+
#include "qemu/osdep.h"
14+
#include "qemu/plugin.h"
15+
16+
/*
17+
* Virtual Memory queries - these are all NOPs for user-mode which
18+
* only ever has visibility of virtual addresses.
19+
*/
20+
21+
struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,
22+
uint64_t vaddr)
23+
{
24+
return NULL;
25+
}
26+
27+
bool qemu_plugin_hwaddr_is_io(const struct qemu_plugin_hwaddr *haddr)
28+
{
29+
return false;
30+
}
31+
32+
uint64_t qemu_plugin_hwaddr_phys_addr(const struct qemu_plugin_hwaddr *haddr)
33+
{
34+
return 0;
35+
}
36+
37+
const char *qemu_plugin_hwaddr_device_name(const struct qemu_plugin_hwaddr *h)
38+
{
39+
return g_intern_static_string("Invalid");
40+
}

plugins/api.c

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -383,76 +383,6 @@ qemu_plugin_mem_value qemu_plugin_mem_get_value(qemu_plugin_meminfo_t info)
383383
return value;
384384
}
385385

386-
/*
387-
* Virtual Memory queries
388-
*/
389-
390-
#ifdef CONFIG_SOFTMMU
391-
static __thread struct qemu_plugin_hwaddr hwaddr_info;
392-
#endif
393-
394-
struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,
395-
uint64_t vaddr)
396-
{
397-
#ifdef CONFIG_SOFTMMU
398-
CPUState *cpu = current_cpu;
399-
unsigned int mmu_idx = get_mmuidx(info);
400-
enum qemu_plugin_mem_rw rw = get_plugin_meminfo_rw(info);
401-
hwaddr_info.is_store = (rw & QEMU_PLUGIN_MEM_W) != 0;
402-
403-
assert(mmu_idx < NB_MMU_MODES);
404-
405-
if (!tlb_plugin_lookup(cpu, vaddr, mmu_idx,
406-
hwaddr_info.is_store, &hwaddr_info)) {
407-
error_report("invalid use of qemu_plugin_get_hwaddr");
408-
return NULL;
409-
}
410-
411-
return &hwaddr_info;
412-
#else
413-
return NULL;
414-
#endif
415-
}
416-
417-
bool qemu_plugin_hwaddr_is_io(const struct qemu_plugin_hwaddr *haddr)
418-
{
419-
#ifdef CONFIG_SOFTMMU
420-
return haddr->is_io;
421-
#else
422-
return false;
423-
#endif
424-
}
425-
426-
uint64_t qemu_plugin_hwaddr_phys_addr(const struct qemu_plugin_hwaddr *haddr)
427-
{
428-
#ifdef CONFIG_SOFTMMU
429-
if (haddr) {
430-
return haddr->phys_addr;
431-
}
432-
#endif
433-
return 0;
434-
}
435-
436-
const char *qemu_plugin_hwaddr_device_name(const struct qemu_plugin_hwaddr *h)
437-
{
438-
#ifdef CONFIG_SOFTMMU
439-
if (h && h->is_io) {
440-
MemoryRegion *mr = h->mr;
441-
if (!mr->name) {
442-
unsigned maddr = (uintptr_t)mr;
443-
g_autofree char *temp = g_strdup_printf("anon%08x", maddr);
444-
return g_intern_string(temp);
445-
} else {
446-
return g_intern_string(mr->name);
447-
}
448-
} else {
449-
return g_intern_static_string("RAM");
450-
}
451-
#else
452-
return g_intern_static_string("Invalid");
453-
#endif
454-
}
455-
456386
int qemu_plugin_num_vcpus(void)
457387
{
458388
return plugin_num_vcpus();

plugins/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ if host_os == 'windows'
5858
)
5959
endif
6060

61-
user_ss.add(files('user.c'))
61+
user_ss.add(files('user.c', 'api-user.c'))
6262
system_ss.add(files('system.c', 'api-system.c'))
6363

6464
common_ss.add(files('loader.c'))

0 commit comments

Comments
 (0)