The existing probe_access* functions do not allow to specify the access size and a non-faulting behavior at the same time.
This is resolved by adding a generalization of probe_access_flags() that takes an additional size parameter. The semantics is basically the same as probe_access_flags(), but instead of assuming an access to any byte of the addressed page, we can restrict to access to a specific area, like probe_access() allows. Signed-off-by: Christoph Muellner <cmuell...@linux.com> --- accel/tcg/cputlb.c | 17 +++++++++++++---- accel/tcg/user-exec.c | 15 ++++++++++++--- include/exec/exec-all.h | 24 ++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 5e0d0eebc3..b4f0eb20b0 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1624,13 +1624,14 @@ static int probe_access_internal(CPUArchState *env, target_ulong addr, return flags; } -int probe_access_flags(CPUArchState *env, target_ulong addr, - MMUAccessType access_type, int mmu_idx, - bool nonfault, void **phost, uintptr_t retaddr) +int probe_access_range_flags(CPUArchState *env, target_ulong addr, + int size, MMUAccessType access_type, + int mmu_idx, bool nonfault, void **phost, + uintptr_t retaddr) { int flags; - flags = probe_access_internal(env, addr, 0, access_type, mmu_idx, + flags = probe_access_internal(env, addr, size, access_type, mmu_idx, nonfault, phost, retaddr); /* Handle clean RAM pages. */ @@ -1645,6 +1646,14 @@ int probe_access_flags(CPUArchState *env, target_ulong addr, return flags; } +int probe_access_flags(CPUArchState *env, target_ulong addr, + MMUAccessType access_type, int mmu_idx, + bool nonfault, void **phost, uintptr_t retaddr) +{ + return probe_access_range_flags(env, addr, 0, access_type, mmu_idx, + nonfault, phost, retaddr); +} + void *probe_access(CPUArchState *env, target_ulong addr, int size, MMUAccessType access_type, int mmu_idx, uintptr_t retaddr) { diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 6f5d4933f0..0dbc345e63 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -176,9 +176,10 @@ static int probe_access_internal(CPUArchState *env, target_ulong addr, cpu_loop_exit_sigsegv(env_cpu(env), addr, access_type, maperr, ra); } -int probe_access_flags(CPUArchState *env, target_ulong addr, - MMUAccessType access_type, int mmu_idx, - bool nonfault, void **phost, uintptr_t ra) +int probe_access_range_flags(CPUArchState *env, target_ulong addr, + int size, MMUAccessType access_type, + int mmu_idx, bool nonfault, void **phost, + uintptr_t ra) { int flags; @@ -187,6 +188,14 @@ int probe_access_flags(CPUArchState *env, target_ulong addr, return flags; } +int probe_access_flags(CPUArchState *env, target_ulong addr, + MMUAccessType access_type, int mmu_idx, + bool nonfault, void **phost, uintptr_t ra) +{ + return probe_access_range_flags(env, addr, 0, access_type, mmu_idx, + nonfault, phost, ra); +} + void *probe_access(CPUArchState *env, target_ulong addr, int size, MMUAccessType access_type, int mmu_idx, uintptr_t ra) { diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 35d8e93976..0d06b45c62 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -441,6 +441,30 @@ static inline void *probe_read(CPUArchState *env, target_ulong addr, int size, return probe_access(env, addr, size, MMU_DATA_LOAD, mmu_idx, retaddr); } +/** + * probe_access_range_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 access range, 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_range_flags(CPUArchState *env, target_ulong addr, + int size, MMUAccessType access_type, + int mmu_idx, bool nonfault, void **phost, + uintptr_t retaddr); + /** * probe_access_flags: * @env: CPUArchState -- 2.35.1