Hexagon (target/hexagon) probe the stores in a packet at start of commit
PATCH 1/1 Hexagon (target/hexagon) probe the stores in a packet at start of commit
When a packet has 2 stores, either both commit or neither commit. At the beginning of gen_commit_packet, we check for multiple stores. If there are multiple stores, call a helper that will probe each of them before proceeding with the commit.
Note that we don't call the probe helper for packets with only one store. Therefore, we call process_store_log before anything else involved in committing the packet.
Test case added in tests/tcg/hexagon/hex_sigsegv.c
--- target/hexagon/helper.h | 2 + target/hexagon/op_helper.c | 30 +++++++++++ target/hexagon/translate.c | 27 +++++++++- tests/tcg/hexagon/hex_sigsegv.c | 106 ++++++++++++++++++++++++++++++++++++++ tests/tcg/hexagon/Makefile.target | 1 + 5 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/hexagon/hex_sigsegv.c
target/hexagon/helper.h +2 -0
@@ -89,3 +89,5 @@ DEF_HELPER_4(sffms_lib, f32, env, f32, f32, f32) DEF_HELPER_3(dfmpyfix, f64, env, f64, f64) DEF_HELPER_4(dfmpyhh, f64, env, f64, f64, f64) + +DEF_HELPER_5 (probe_pkt_stores, void, env, int, int, int, int)
target/hexagon/op_helper.c +30 -0
@@ -377,6 +377,36 @@ int32_t HELPER(vacsh_pred)(CPUHexagonState *env,return PeV; } +static inline void probe_store (CPUHexagonState *env,int slot,int mmu_idx) +{ +if (!(env->slot_cancelled & (1 << slot))) { +size1u_t width = env->mem_log_stores[slot].width; +target_ulong va = env->mem_log_stores[slot].va; +uintptr_t ra =GETPC (); +probe_write (env, va, width, mmu_idx, ra); + } +} + +void HELPER (probe_pkt_stores )(CPUHexagonState *env,int has_st0,int has_st1, +int has_dczeroa,int mmu_idx) +{ +if (has_st0 && !has_dczeroa) { +probe_store (env,0 , mmu_idx); + } +if (has_st1 && !has_dczeroa) { +probe_store (env,1 , mmu_idx); + } +if (has_dczeroa) { +/* Probe 32 bytes starting at (dczero_addr & ~0x1f) */ +target_ulong va = env->dczero_addr & ~0x1f ; +uintptr_t ra =GETPC (); +probe_write (env, va +0 ,8 , mmu_idx, ra); +probe_write (env, va +8 ,8 , mmu_idx, ra); +probe_write (env, va +16 ,8 , mmu_idx, ra); +probe_write (env, va +24 ,8 , mmu_idx, ra); + } +} +/* * mem_noshuf * Section 5.5 of the Hexagon V67 Programmer's Reference Manual
target/hexagon/translate.c +26 -1
@@ -471,9 +471,34 @@ static void update_exec_counters(DisasContext *ctx, Packet *pkt)static void gen_commit_packet (DisasContext *ctx,Packet *pkt) { +/* +* If there is more than one store in a packet, make sure they are all OK +* before proceeding with the rest of the packet commit. +* +* Note that we don't call the probe helper for packets with only one +* store. Therefore, we call process_store_log before anything else +* involved in committing the packet. +*/ +if ((pkt->pkt_has_store_s0 && pkt->pkt_has_store_s1) || + pkt->pkt_has_dczeroa) { +TCGv has_st0 =tcg_const_tl (pkt->pkt_has_store_s0); +TCGv has_st1 =tcg_const_tl (pkt->pkt_has_store_s1); +TCGv has_dczeroa =tcg_const_tl (pkt->pkt_has_dczeroa); +TCGv mem_idx =tcg_const_tl (ctx->mem_idx); + +gen_helper_probe_pkt_stores (cpu_env, has_st0, has_st1, + has_dczeroa, mem_idx); + +tcg_temp_free (has_st0); +tcg_temp_free (has_st1); +tcg_temp_free (has_dczeroa); +tcg_temp_free (mem_idx); + } + +process_store_log (ctx, pkt); +gen_reg_writes (ctx);gen_pred_writes (ctx, pkt); -process_store_log (ctx, pkt);process_dczeroa (ctx, pkt);update_exec_counters (ctx, pkt);if (HEX_DEBUG ) {
tests/tcg/hexagon/hex_sigsegv.c new file +106 -0
106 lines not on this page · raw message
tests/tcg/hexagon/Makefile.target +1 -0
@@ -28,6 +28,7 @@ first: $(HEX_SRC)/first.S $(CC) -static -mv67 -nostdlib $^ -o $@ HEX_TESTS = first +HEX_TESTS += hex_sigsegv HEX_TESTS += misc HEX_TESTS += preg_alias HEX_TESTS += dual_stores
Signature · 1 line
2.7.4
Quoted 19 lines · Taylor Simpson
target/hexagon/op_helper.c +19
-0+static inline void probe_store (CPUHexagonState *env,int slot,int mmu_idx) +{ +if (!(env->slot_cancelled & (1 << slot))) { +size1u_t width = env->mem_log_stores[slot].width; +target_ulong va = env->mem_log_stores[slot].va; +uintptr_t ra =GETPC (); +probe_write (env, va, width, mmu_idx, ra); + } +} + +void HELPER (probe_pkt_stores )(CPUHexagonState *env,int has_st0,int has_st1, +int has_dczeroa,int mmu_idx) +{ +if (has_st0 && !has_dczeroa) { +probe_store (env,0 , mmu_idx); + } +if (has_st1 && !has_dczeroa) { +probe_store (env,1 , mmu_idx); + }
target/hexagon/op_helper.c int32_t HELPER(vacsh_pred)(CPUHexagonState *env, · line 408
Quoted 10 lines
target/hexagon/op_helper.c +10
-0+if (has_dczeroa) { +/* Probe 32 bytes starting at (dczero_addr & ~0x1f) */ +target_ulong va = env->dczero_addr & ~0x1f ; +uintptr_t ra =GETPC (); +probe_write (env, va +0 ,8 , mmu_idx, ra); +probe_write (env, va +8 ,8 , mmu_idx, ra); +probe_write (env, va +16 ,8 , mmu_idx, ra); +probe_write (env, va +24 ,8 , mmu_idx, ra); + } +}
You know at translate time the value of all of these has_* variables.
Since has_dczeroa disables the other two probes, surely probe_pkt_dczeroa should be its own helper.
That said, if dczeroa (apparently) cannot be paired with other stores, why do you need to probe for it at all? Since the operation is 32-byte aligned, surely the first real store will validate the write for the entire block.
Once you eliminate dczeroa from this helper, the only time it will be called is with both has_st0 and has_st1 true, at which point you don't need to pass the arguments in at all.
r~
Quoted 46 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Thursday, September 23, 2021 12:05 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH] Hexagon (target/hexagon) probe the stores in a packet at start of committarget/hexagon/op_helper.c int32_t HELPER(vacsh_pred)(CPUHexagonState *env,
Quoted 11 lines · Taylor Simpson
target/hexagon/op_helper.c +11
-0+static inline void probe_store (CPUHexagonState *env,int slot,int +mmu_idx) { +if (!(env->slot_cancelled & (1 << slot))) { +size1u_t width = env->mem_log_stores[slot].width; +target_ulong va = env->mem_log_stores[slot].va; +uintptr_t ra =GETPC (); +probe_write (env, va, width, mmu_idx, ra); + } +} + +void HELPER(probe_pkt_stores)(CPUHexagonState *env, int has_st0, int
has_st1,Quoted 7 lines
target/hexagon/op_helper.c +7
-0+ int has_dczeroa, int mmu_idx) { +if (has_st0 && !has_dczeroa) { +probe_store (env,0 , mmu_idx); + } +if (has_st1 && !has_dczeroa) { +probe_store (env,1 , mmu_idx); + }target/hexagon/op_helper.c int32_t HELPER(vacsh_pred)(CPUHexagonState *env, · line 408
Quoted 10 lines
target/hexagon/op_helper.c +10
-0+if (has_dczeroa) { +/* Probe 32 bytes starting at (dczero_addr & ~0x1f) */ +target_ulong va = env->dczero_addr & ~0x1f ; +uintptr_t ra =GETPC (); +probe_write (env, va +0 ,8 , mmu_idx, ra); +probe_write (env, va +8 ,8 , mmu_idx, ra); +probe_write (env, va +16 ,8 , mmu_idx, ra); +probe_write (env, va +24 ,8 , mmu_idx, ra); + } +}You know at translate time the value of all of these has_* variables.
Since
has_dczeroadisables the other two probes, surelyprobe_pkt_dczeroashould be its own helper.
Quoted 8 lines
That said, if dczeroa (apparently) cannot be paired with other stores, why do you need to probe for it at all? Since the operation is 32-byte aligned, surely the first real store will validate the write for the entire block.
Once you eliminate dczeroa from this helper, the only time it will be called is with both
has_st0andhas_st1true, at which point you don't need to pass the arguments in at all.
You are correct, dczeroa can't be in a packet with any other memory op, so it could be its own helper.
We also need to account for HVX stores in the other patch series under review. With HVX, we could have an HVX store and a scalar store in the same packet. I'll go ahead and make the changes you suggest here. I'll create a more general helper in the HVX series. For efficiency, I'd like to only call a single helper that will do all the probes. So, we'll either end up with one for each possible combination or a one for scalar only and one for the other combinations with a mask.
Thanks,
Taylor