Hexagon (target/hexagon) probe the stores in a packet at start of commit
PATCH v2 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
*** Changes in v2 ***
Address feedback from Richard Henderson <[email protected]>
- Since we know the value of all the mask at translation time, call specialized helper
- dczeroa has to be the only store operation in a packet, so we go ahead and process that first
- When there are two scalar stores, we probe the one in slot 0 - the call to process_store_log will do slot 1 first, so we don't need to probe
--- target/hexagon/helper.h | 2 + target/hexagon/op_helper.c | 16 ++++++ target/hexagon/translate.c | 32 +++++++++++- tests/tcg/hexagon/hex_sigsegv.c | 106 ++++++++++++++++++++++++++++++++++++++ tests/tcg/hexagon/Makefile.target | 1 + 5 files changed, 155 insertions(+), 2 deletions(-) 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_2 (probe_pkt_scalar_store_s0, void, env, int)
target/hexagon/op_helper.c +16 -0
@@ -377,6 +377,22 @@ int32_t HELPER(vacsh_pred)(CPUHexagonState *env,return PeV; } +static 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); + } +} + +/* Called during packet commit when there are two scalar stores */ +void HELPER (probe_pkt_scalar_store_s0 )(CPUHexagonState *env,int mmu_idx) +{ +probe_store (env,0 , mmu_idx); +} +/* * mem_noshuf * Section 5.5 of the Hexagon V67 Programmer's Reference Manual
target/hexagon/translate.c +30 -2
@@ -471,10 +471,38 @@ 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. +* +* dczeroa has to be the only store operation in the packet, so we go +* ahead and process that first. +* +* When there are two scalar stores, we probe the one in slot 0. +* +* 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. +*/ +bool has_store_s0 = pkt->pkt_has_store_s0; +bool has_store_s1 = (pkt->pkt_has_store_s1 && !ctx->s1_store_processed); +if (pkt->pkt_has_dczeroa) { +/* +* The dczeroa will be the store in slot 0, check that we don't have +* a store in slot 1. +*/ +g_assert (has_store_s0 && !has_store_s1); +process_dczeroa (ctx, pkt); + }else if (has_store_s0 && has_store_s1) { +TCGv mem_idx =tcg_const_tl (ctx->mem_idx); +gen_helper_probe_pkt_scalar_store_s0 (cpu_env, mem_idx); +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 ) { TCGv has_st0 =
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
Hi Taylor,
Quoted 47 lines · Taylor Simpson
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_logbefore anything else involved in committing the packet.Test case added in
tests/tcg/hexagon/hex_sigsegv.cSigned-off-by Taylor Simpson <[email protected]>*** Changes in v2 ***
Address feedback from Richard Henderson <[email protected]>
- Since we know the value of all the mask at translation time, call specialized helper
- dczeroa has to be the only store operation in a packet, so we go ahead and process that first
- When there are two scalar stores, we probe the one in slot 0 - the call toprocess_store_logwill do slot 1 first, so we don't need to probe--- target/hexagon/helper.h | 2 + target/hexagon/op_helper.c | 16 ++++++ target/hexagon/translate.c | 32 +++++++++++- tests/tcg/hexagon/hex_sigsegv.c | 106 ++++++++++++++++++++++++++++++++++++++ tests/tcg/hexagon/Makefile.target | 1 + 5 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 tests/tcg/hexagon/hex_sigsegv.ctarget/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_2 (probe_pkt_scalar_store_s0, void, env, int)target/hexagon/op_helper.c +0
-0@@ -377,6 +377,22 @@ int32_t HELPER(vacsh_pred)(CPUHexagonState *env,return PeV;
target/hexagon/op_helper.c int32_t HELPER(vacsh_pred)(CPUHexagonState *env, · line 387
Quoted 10 lines
target/hexagon/op_helper.c +8
-0} +static 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); + }
Matter of taste probably:
if (env->slot_cancelled & (1 << slot) {
return;
}
probe_write(env, env->mem_log_stores[slot].va,
env->mem_log_stores[slot].width, mmu_idx, GETPC());Quoted 35 lines
target/hexagon/op_helper.c +8
-0+} + +/* Called during packet commit when there are two scalar stores */ +void HELPER (probe_pkt_scalar_store_s0 )(CPUHexagonState *env,int mmu_idx) +{ +probe_store (env,0 , mmu_idx); +} +/* * mem_noshuf * Section 5.5 of the Hexagon V67 Programmer's Reference Manual target/hexagon/translate.c +16
-0@@ -471,10 +471,38 @@ 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. +* +* dczeroa has to be the only store operation in the packet, so we go +* ahead and process that first. +* +* When there are two scalar stores, we probe the one in slot 0. +* +* 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. +*/ +bool has_store_s0 = pkt->pkt_has_store_s0; +bool has_store_s1 = (pkt->pkt_has_store_s1 && !ctx->s1_store_processed); +if (pkt->pkt_has_dczeroa) {
target/hexagon/translate.c static void update_exec_counters(DisasContext *ctx, Packet *pkt) · line 499
Quoted 10 lines
target/hexagon/translate.c +10
-0+/* +* The dczeroa will be the store in slot 0, check that we don't have +* a store in slot 1. +*/ +g_assert (has_store_s0 && !has_store_s1); +process_dczeroa (ctx, pkt); + }else if (has_store_s0 && has_store_s1) { +TCGv mem_idx =tcg_const_tl (ctx->mem_idx); +gen_helper_probe_pkt_scalar_store_s0 (cpu_env, mem_idx); +tcg_temp_free (mem_idx);
The index is read-only, so you can avoid the temporary:
gen_helper_probe_pkt_scalar_store_s0(cpu_env,
tcg_constant_tl(ctx->mem_idx));Maybe add a (better) comment here:
} else {
/* default path, all constraints OK, we are good */tests/tcg/hexagon/hex_sigsegv.c
Quoted 16 lines
target/hexagon/translate.c +4
-2+ } + +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 ) { TCGv has_st0 =tests/tcg/hexagon/hex_sigsegv.c new file +0
-0
hex_sigsegv is a generic test name ...
Quoted 10 lines
tests/tcg/hexagon/hex_sigsegv.c new file +9
-0@@ -0,0 +1,106 @@ +/* +* Copyright(c) 2021 Qualcomm Innovation Center, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful,
tests/tcg/hexagon/hex_sigsegv.c line 19
Quoted 10 lines
tests/tcg/hexagon/hex_sigsegv.c new file +10
-0+* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +/* +* Test the VLIW semantics of two stores in a packet
... but you are testing a very specific case.
Maybe rename as "multi_pkt_stores" (or better)?
tests/tcg/hexagon/hex_sigsegv.c line 25
Quoted 6 lines
tests/tcg/hexagon/hex_sigsegv.c new file +6
-0+* +* When a packet has 2 stores, either both commit or neither commit. +* We test this with a packet that does stores to both NULL and a global +* variable, "should_not_change". After the SIGSEGV is caught, we check +* that the "should_not_change" value is the same. +*/
Otherwise LGTM.
Regards,
Phil.
target/hexagon/translate.c static void update_exec_counters(DisasContext *ctx, Packet *pkt) · line 500
Quoted 5 lines · Taylor Simpson
target/hexagon/translate.c +5
-0+ }else if (has_store_s0 && has_store_s1) { +TCGv mem_idx =tcg_const_tl (ctx->mem_idx); +gen_helper_probe_pkt_scalar_store_s0 (cpu_env, mem_idx); +tcg_temp_free (mem_idx); + }
So we're assuming that the s1 store happens first? If so, you could expand the comment above.
Otherwise, it looks good.
r~
Quoted 11 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Friday, October 1, 2021 10:55 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; Brian Cain <[email protected]>
Subject: Re: [PATCH v2] Hexagon (target/hexagon) probe the stores in a packet at start of commitOn 9/30/21 5:16 PM, Taylor Simpson wrote:
Quoted 8 lines
target/hexagon/translate.c static void update_exec_counters(DisasContext *ctx, Packet *pkt) · line 500
Quoted 5 lines
target/hexagon/translate.c +5
-0+ }else if (has_store_s0 && has_store_s1) { +TCGv mem_idx =tcg_const_tl (ctx->mem_idx); +gen_helper_probe_pkt_scalar_store_s0 (cpu_env, mem_idx); +tcg_temp_free (mem_idx); + }So we're assuming that the s1 store happens first? If so, you could expand the comment above.
Yes, there's a comment in process_store_log (with a typo fixed here).
/*
* When a packet has two stores, the hardware processes
* slot 1 and then slot 0. This will be important when
* the memory accesses overlap.
*/
I'll fix the typo and expand the comment in the above code.
Also, tests/tcg/hexagon/dual_stores.c tests for this behavior.
Quoted 2 lines
Otherwise, it looks good.
Reviewed-by Richard Henderson <[email protected]>
Thanks!