accel/tcg: Extract probe API out of 'exec/exec-all.h'

Declare probe methods in "accel/tcg/probe.h" to emphasize
they are specific to TCG accelerator.

Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20250424202412.91612-13-philmd@linaro.org>
This commit is contained in:
Philippe Mathieu-Daudé 2025-04-24 22:24:11 +02:00 committed by Richard Henderson
parent f12b717717
commit fe1a3ace13
24 changed files with 128 additions and 100 deletions

View file

@ -21,6 +21,7 @@
#include "qemu/main-loop.h" #include "qemu/main-loop.h"
#include "accel/tcg/cpu-ops.h" #include "accel/tcg/cpu-ops.h"
#include "accel/tcg/iommu.h" #include "accel/tcg/iommu.h"
#include "accel/tcg/probe.h"
#include "exec/exec-all.h" #include "exec/exec-all.h"
#include "exec/page-protection.h" #include "exec/page-protection.h"
#include "system/memory.h" #include "system/memory.h"

View file

@ -27,6 +27,7 @@
#include "qemu/bitops.h" #include "qemu/bitops.h"
#include "qemu/rcu.h" #include "qemu/rcu.h"
#include "accel/tcg/cpu-ldst.h" #include "accel/tcg/cpu-ldst.h"
#include "accel/tcg/probe.h"
#include "user/cpu_loop.h" #include "user/cpu_loop.h"
#include "qemu/main-loop.h" #include "qemu/main-loop.h"
#include "user/page-protection.h" #include "user/page-protection.h"

106
include/accel/tcg/probe.h Normal file
View file

@ -0,0 +1,106 @@
/*
* Probe guest virtual addresses for access permissions.
*
* Copyright (c) 2003 Fabrice Bellard
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#ifndef ACCEL_TCG_PROBE_H
#define ACCEL_TCG_PROBE_H
#include "exec/mmu-access-type.h"
#include "exec/vaddr.h"
/**
* probe_access:
* @env: CPUArchState
* @addr: guest virtual address to look up
* @size: size of the access
* @access_type: read, write or execute permission
* @mmu_idx: MMU index to use for lookup
* @retaddr: return address for unwinding
*
* Look up the guest virtual address @addr. Raise an exception if the
* page does not satisfy @access_type. Raise an exception if the
* access (@addr, @size) hits a watchpoint. For writes, mark a clean
* page as dirty.
*
* Finally, return the host address for a page that is backed by RAM,
* or NULL if the page requires I/O.
*/
void *probe_access(CPUArchState *env, vaddr addr, int size,
MMUAccessType access_type, int mmu_idx, uintptr_t retaddr);
static inline void *probe_write(CPUArchState *env, vaddr addr, int size,
int mmu_idx, uintptr_t retaddr)
{
return probe_access(env, addr, size, MMU_DATA_STORE, mmu_idx, retaddr);
}
static inline void *probe_read(CPUArchState *env, vaddr addr, int size,
int mmu_idx, uintptr_t retaddr)
{
return probe_access(env, addr, size, MMU_DATA_LOAD, mmu_idx, retaddr);
}
/**
* probe_access_flags:
* @env: CPUArchState
* @addr: guest virtual address to look up
* @size: size of the access
* @access_type: read, write or execute permission
* @mmu_idx: MMU index to use for lookup
* @nonfault: suppress the fault
* @phost: return value for host address
* @retaddr: return address for unwinding
*
* Similar to probe_access, loosely returning the TLB_FLAGS_MASK for
* the page, and storing the host address for RAM in @phost.
*
* If @nonfault is set, do not raise an exception but return TLB_INVALID_MASK.
* Do not handle watchpoints, but include TLB_WATCHPOINT in the returned flags.
* Do handle clean pages, so exclude TLB_NOTDIRY from the returned flags.
* For simplicity, all "mmio-like" flags are folded to TLB_MMIO.
*/
int probe_access_flags(CPUArchState *env, vaddr addr, int size,
MMUAccessType access_type, int mmu_idx,
bool nonfault, void **phost, uintptr_t retaddr);
#ifndef CONFIG_USER_ONLY
/**
* probe_access_full:
* Like probe_access_flags, except also return into @pfull.
*
* The CPUTLBEntryFull structure returned via @pfull is transient
* and must be consumed or copied immediately, before any further
* access or changes to TLB @mmu_idx.
*
* This function will not fault if @nonfault is set, but will
* return TLB_INVALID_MASK if the page is not mapped, or is not
* accessible with @access_type.
*
* This function will return TLB_MMIO in order to force the access
* to be handled out-of-line if plugins wish to instrument the access.
*/
int probe_access_full(CPUArchState *env, vaddr addr, int size,
MMUAccessType access_type, int mmu_idx,
bool nonfault, void **phost,
CPUTLBEntryFull **pfull, uintptr_t retaddr);
/**
* probe_access_full_mmu:
* Like probe_access_full, except:
*
* This function is intended to be used for page table accesses by
* the target mmu itself. Since such page walking happens while
* handling another potential mmu fault, this function never raises
* exceptions (akin to @nonfault true for probe_access_full).
* Likewise this function does not trigger plugin instrumentation.
*/
int probe_access_full_mmu(CPUArchState *env, vaddr addr, int size,
MMUAccessType access_type, int mmu_idx,
void **phost, CPUTLBEntryFull **pfull);
#endif /* !CONFIG_USER_ONLY */
#endif

View file

@ -20,104 +20,4 @@
#ifndef EXEC_ALL_H #ifndef EXEC_ALL_H
#define EXEC_ALL_H #define EXEC_ALL_H
#include "exec/hwaddr.h"
#include "exec/mmu-access-type.h"
#include "exec/vaddr.h"
#if defined(CONFIG_TCG)
/**
* probe_access:
* @env: CPUArchState
* @addr: guest virtual address to look up
* @size: size of the access
* @access_type: read, write or execute permission
* @mmu_idx: MMU index to use for lookup
* @retaddr: return address for unwinding
*
* Look up the guest virtual address @addr. Raise an exception if the
* page does not satisfy @access_type. Raise an exception if the
* access (@addr, @size) hits a watchpoint. For writes, mark a clean
* page as dirty.
*
* Finally, return the host address for a page that is backed by RAM,
* or NULL if the page requires I/O.
*/
void *probe_access(CPUArchState *env, vaddr addr, int size,
MMUAccessType access_type, int mmu_idx, uintptr_t retaddr);
static inline void *probe_write(CPUArchState *env, vaddr addr, int size,
int mmu_idx, uintptr_t retaddr)
{
return probe_access(env, addr, size, MMU_DATA_STORE, mmu_idx, retaddr);
}
static inline void *probe_read(CPUArchState *env, vaddr addr, int size,
int mmu_idx, uintptr_t retaddr)
{
return probe_access(env, addr, size, MMU_DATA_LOAD, mmu_idx, retaddr);
}
/**
* probe_access_flags:
* @env: CPUArchState
* @addr: guest virtual address to look up
* @size: size of the access
* @access_type: read, write or execute permission
* @mmu_idx: MMU index to use for lookup
* @nonfault: suppress the fault
* @phost: return value for host address
* @retaddr: return address for unwinding
*
* Similar to probe_access, loosely returning the TLB_FLAGS_MASK for
* the page, and storing the host address for RAM in @phost.
*
* If @nonfault is set, do not raise an exception but return TLB_INVALID_MASK.
* Do not handle watchpoints, but include TLB_WATCHPOINT in the returned flags.
* Do handle clean pages, so exclude TLB_NOTDIRY from the returned flags.
* For simplicity, all "mmio-like" flags are folded to TLB_MMIO.
*/
int probe_access_flags(CPUArchState *env, vaddr addr, int size,
MMUAccessType access_type, int mmu_idx,
bool nonfault, void **phost, uintptr_t retaddr);
#ifndef CONFIG_USER_ONLY
/**
* probe_access_full:
* Like probe_access_flags, except also return into @pfull.
*
* The CPUTLBEntryFull structure returned via @pfull is transient
* and must be consumed or copied immediately, before any further
* access or changes to TLB @mmu_idx.
*
* This function will not fault if @nonfault is set, but will
* return TLB_INVALID_MASK if the page is not mapped, or is not
* accessible with @access_type.
*
* This function will return TLB_MMIO in order to force the access
* to be handled out-of-line if plugins wish to instrument the access.
*/
int probe_access_full(CPUArchState *env, vaddr addr, int size,
MMUAccessType access_type, int mmu_idx,
bool nonfault, void **phost,
CPUTLBEntryFull **pfull, uintptr_t retaddr);
/**
* probe_access_full_mmu:
* Like probe_access_full, except:
*
* This function is intended to be used for page table accesses by
* the target mmu itself. Since such page walking happens while
* handling another potential mmu fault, this function never raises
* exceptions (akin to @nonfault true for probe_access_full).
* Likewise this function does not trigger plugin instrumentation.
*/
int probe_access_full_mmu(CPUArchState *env, vaddr addr, int size,
MMUAccessType access_type, int mmu_idx,
void **phost, CPUTLBEntryFull **pfull);
#endif /* !CONFIG_USER_ONLY */
#endif /* CONFIG_TCG */
#endif #endif

View file

@ -9,6 +9,7 @@
#include "qemu/osdep.h" #include "qemu/osdep.h"
#include "accel/tcg/cpu-mmu-index.h" #include "accel/tcg/cpu-mmu-index.h"
#include "accel/tcg/probe.h"
#include "exec/exec-all.h" #include "exec/exec-all.h"
#include "exec/target_page.h" #include "exec/target_page.h"
#include "exec/tlb-flags.h" #include "exec/tlb-flags.h"

View file

@ -30,6 +30,7 @@
#include "qapi/error.h" #include "qapi/error.h"
#include "qemu/guest-random.h" #include "qemu/guest-random.h"
#ifdef CONFIG_TCG #ifdef CONFIG_TCG
#include "accel/tcg/probe.h"
#include "semihosting/common-semi.h" #include "semihosting/common-semi.h"
#endif #endif
#include "cpregs.h" #include "cpregs.h"

View file

@ -14,6 +14,7 @@
#include "exec/page-protection.h" #include "exec/page-protection.h"
#include "exec/target_page.h" #include "exec/target_page.h"
#include "exec/tlb-flags.h" #include "exec/tlb-flags.h"
#include "accel/tcg/probe.h"
#include "cpu.h" #include "cpu.h"
#include "internals.h" #include "internals.h"
#include "cpu-features.h" #include "cpu-features.h"

View file

@ -31,6 +31,7 @@
#include "exec/cpu-common.h" #include "exec/cpu-common.h"
#include "exec/exec-all.h" #include "exec/exec-all.h"
#include "accel/tcg/cpu-ldst.h" #include "accel/tcg/cpu-ldst.h"
#include "accel/tcg/probe.h"
#include "exec/target_page.h" #include "exec/target_page.h"
#include "exec/tlb-flags.h" #include "exec/tlb-flags.h"
#include "qemu/int128.h" #include "qemu/int128.h"

View file

@ -30,6 +30,7 @@
#include "system/ram_addr.h" #include "system/ram_addr.h"
#endif #endif
#include "accel/tcg/cpu-ldst.h" #include "accel/tcg/cpu-ldst.h"
#include "accel/tcg/probe.h"
#include "exec/helper-proto.h" #include "exec/helper-proto.h"
#include "exec/tlb-flags.h" #include "exec/tlb-flags.h"
#include "accel/tcg/cpu-ops.h" #include "accel/tcg/cpu-ops.h"

View file

@ -25,6 +25,7 @@
#include "cpu-features.h" #include "cpu-features.h"
#include "exec/exec-all.h" #include "exec/exec-all.h"
#include "accel/tcg/cpu-ldst.h" #include "accel/tcg/cpu-ldst.h"
#include "accel/tcg/probe.h"
#include "cpregs.h" #include "cpregs.h"
#define SIGNBIT (uint32_t)0x80000000 #define SIGNBIT (uint32_t)0x80000000

View file

@ -32,6 +32,7 @@
#include "sve_ldst_internal.h" #include "sve_ldst_internal.h"
#include "accel/tcg/cpu-ldst.h" #include "accel/tcg/cpu-ldst.h"
#include "accel/tcg/cpu-ops.h" #include "accel/tcg/cpu-ops.h"
#include "accel/tcg/probe.h"
#ifdef CONFIG_USER_ONLY #ifdef CONFIG_USER_ONLY
#include "user/page-protection.h" #include "user/page-protection.h"
#endif #endif

View file

@ -22,6 +22,7 @@
#include "arch.h" #include "arch.h"
#include "mmvec/system_ext_mmvec.h" #include "mmvec/system_ext_mmvec.h"
#include "accel/tcg/getpc.h" #include "accel/tcg/getpc.h"
#include "accel/tcg/probe.h"
#ifndef QEMU_GENERATE #ifndef QEMU_GENERATE
#define VdV (*(MMVector *restrict)(VdV_void)) #define VdV (*(MMVector *restrict)(VdV_void))

View file

@ -19,6 +19,7 @@
#include "qemu/log.h" #include "qemu/log.h"
#include "exec/exec-all.h" #include "exec/exec-all.h"
#include "accel/tcg/cpu-ldst.h" #include "accel/tcg/cpu-ldst.h"
#include "accel/tcg/probe.h"
#include "exec/helper-proto.h" #include "exec/helper-proto.h"
#include "fpu/softfloat.h" #include "fpu/softfloat.h"
#include "cpu.h" #include "cpu.h"

View file

@ -23,6 +23,7 @@
#include "exec/exec-all.h" #include "exec/exec-all.h"
#include "exec/cputlb.h" #include "exec/cputlb.h"
#include "accel/tcg/cpu-mmu-index.h" #include "accel/tcg/cpu-mmu-index.h"
#include "accel/tcg/probe.h"
#include "exec/page-protection.h" #include "exec/page-protection.h"
#include "exec/target_page.h" #include "exec/target_page.h"
#include "exec/helper-proto.h" #include "exec/helper-proto.h"

View file

@ -23,6 +23,7 @@
#include "exec/exec-all.h" #include "exec/exec-all.h"
#include "exec/helper-proto.h" #include "exec/helper-proto.h"
#include "accel/tcg/cpu-ldst.h" #include "accel/tcg/cpu-ldst.h"
#include "accel/tcg/probe.h"
#include "qemu/timer.h" #include "qemu/timer.h"
#include "trace.h" #include "trace.h"
#ifdef CONFIG_USER_ONLY #ifdef CONFIG_USER_ONLY

View file

@ -4,6 +4,7 @@
#include "qemu/osdep.h" #include "qemu/osdep.h"
#include "cpu.h" #include "cpu.h"
#include "accel/tcg/cpu-ldst.h" #include "accel/tcg/cpu-ldst.h"
#include "accel/tcg/probe.h"
#include "exec/exec-all.h" #include "exec/exec-all.h"
#include "exec/target_page.h" #include "exec/target_page.h"
#include "access.h" #include "access.h"

View file

@ -24,6 +24,7 @@
#include "exec/helper-proto.h" #include "exec/helper-proto.h"
#include "exec/exec-all.h" #include "exec/exec-all.h"
#include "accel/tcg/cpu-ldst.h" #include "accel/tcg/cpu-ldst.h"
#include "accel/tcg/probe.h"
#include "exec/log.h" #include "exec/log.h"
#include "helper-tcg.h" #include "helper-tcg.h"
#include "seg_helper.h" #include "seg_helper.h"

View file

@ -20,6 +20,7 @@
#include "qemu/osdep.h" #include "qemu/osdep.h"
#include "cpu.h" #include "cpu.h"
#include "accel/tcg/cpu-ldst.h" #include "accel/tcg/cpu-ldst.h"
#include "accel/tcg/probe.h"
#include "exec/cputlb.h" #include "exec/cputlb.h"
#include "exec/page-protection.h" #include "exec/page-protection.h"
#include "exec/target_page.h" #include "exec/target_page.h"

View file

@ -23,6 +23,7 @@
#include "tcg/tcg.h" #include "tcg/tcg.h"
#include "exec/exec-all.h" #include "exec/exec-all.h"
#include "accel/tcg/cpu-ldst.h" #include "accel/tcg/cpu-ldst.h"
#include "accel/tcg/probe.h"
#include "exec/helper-proto.h" #include "exec/helper-proto.h"
#include "exec/memop.h" #include "exec/memop.h"
#include "exec/target_page.h" #include "exec/target_page.h"

View file

@ -25,6 +25,7 @@
#include "exec/helper-proto.h" #include "exec/helper-proto.h"
#include "helper_regs.h" #include "helper_regs.h"
#include "accel/tcg/cpu-ldst.h" #include "accel/tcg/cpu-ldst.h"
#include "accel/tcg/probe.h"
#include "internal.h" #include "internal.h"
#include "qemu/atomic128.h" #include "qemu/atomic128.h"

View file

@ -24,6 +24,7 @@
#include "exec/exec-all.h" #include "exec/exec-all.h"
#include "exec/cputlb.h" #include "exec/cputlb.h"
#include "accel/tcg/cpu-ldst.h" #include "accel/tcg/cpu-ldst.h"
#include "accel/tcg/probe.h"
#include "exec/helper-proto.h" #include "exec/helper-proto.h"
#include "exec/tlb-flags.h" #include "exec/tlb-flags.h"
#include "trace.h" #include "trace.h"

View file

@ -23,6 +23,7 @@
#include "exec/memop.h" #include "exec/memop.h"
#include "exec/exec-all.h" #include "exec/exec-all.h"
#include "accel/tcg/cpu-ldst.h" #include "accel/tcg/cpu-ldst.h"
#include "accel/tcg/probe.h"
#include "exec/page-protection.h" #include "exec/page-protection.h"
#include "exec/helper-proto.h" #include "exec/helper-proto.h"
#include "exec/tlb-flags.h" #include "exec/tlb-flags.h"

View file

@ -29,6 +29,7 @@
#include "exec/cputlb.h" #include "exec/cputlb.h"
#include "exec/page-protection.h" #include "exec/page-protection.h"
#include "accel/tcg/cpu-ldst.h" #include "accel/tcg/cpu-ldst.h"
#include "accel/tcg/probe.h"
#include "exec/target_page.h" #include "exec/target_page.h"
#include "exec/tlb-flags.h" #include "exec/tlb-flags.h"
#include "accel/tcg/cpu-ops.h" #include "accel/tcg/cpu-ops.h"

View file

@ -34,6 +34,7 @@
#include "qemu/host-utils.h" #include "qemu/host-utils.h"
#include "exec/cputlb.h" #include "exec/cputlb.h"
#include "accel/tcg/cpu-mmu-index.h" #include "accel/tcg/cpu-mmu-index.h"
#include "accel/tcg/probe.h"
#include "exec/exec-all.h" #include "exec/exec-all.h"
#include "exec/page-protection.h" #include "exec/page-protection.h"
#include "exec/target_page.h" #include "exec/target_page.h"