From nobody Sat May 18 07:48:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@quicinc.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=quicinc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632352389814672.8105138946487; Wed, 22 Sep 2021 16:13:09 -0700 (PDT) Received: from localhost ([::1]:37046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mTBQK-0004TG-1i for importer@patchew.org; Wed, 22 Sep 2021 19:13:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43962) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTBOw-0003ax-St for qemu-devel@nongnu.org; Wed, 22 Sep 2021 19:11:44 -0400 Received: from alexa-out-sd-01.qualcomm.com ([199.106.114.38]:36530) by eggs.gnu.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1mTBOo-0007Ta-6e for qemu-devel@nongnu.org; Wed, 22 Sep 2021 19:11:42 -0400 Received: from unknown (HELO ironmsg03-sd.qualcomm.com) ([10.53.140.143]) by alexa-out-sd-01.qualcomm.com with ESMTP; 22 Sep 2021 16:11:30 -0700 Received: from vu-tsimpson-aus.qualcomm.com (HELO vu-tsimpson1-aus.qualcomm.com) ([10.222.150.1]) by ironmsg03-sd.qualcomm.com with ESMTP; 22 Sep 2021 16:11:30 -0700 Received: by vu-tsimpson1-aus.qualcomm.com (Postfix, from userid 47164) id DE6591639; Wed, 22 Sep 2021 18:11:29 -0500 (CDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1632352293; x=1663888293; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=RZOdYvEEyt5+GTwgj2kfISE4bNW8tl7Wes7sxYJGim0=; b=EdNuXTKbwAnACUBclHlgv9TnwlZwPR/QL69EQrTPhgKzKsx/JjAlEm4m YqpFtXqU68MOuR7NfqGqFrCw17pABvzfry1BJFxw/rA60ukB5Ou3pa79N izGQRklYYK51Myqwq4ZLm9rQc7cRebRCnMoEg6Cu62BKg/7PBdjAEKAwK E=; X-QCInternal: smtphost From: Taylor Simpson To: qemu-devel@nongnu.org Subject: [PATCH v2] Hexagon (target/hexagon) probe the stores in a packet at start of commit Date: Wed, 22 Sep 2021 18:11:27 -0500 Message-Id: <1632352287-19590-1-git-send-email-tsimpson@quicinc.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=199.106.114.38; envelope-from=tsimpson@qualcomm.com; helo=alexa-out-sd-01.qualcomm.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ale@rev.ng, bcain@quicinc.com, tsimpson@quicinc.com, richard.henderson@linaro.org, f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1632352390688100001 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 *** Reduce the overhead of probe_pkt_stores - pass a bit mask instead of multiple booleans Signed-off-by: Taylor Simpson --- target/hexagon/helper.h | 2 + target/hexagon/op_helper.c | 33 ++++++++++++ target/hexagon/translate.c | 33 +++++++++++- tests/tcg/hexagon/hex_sigsegv.c | 106 ++++++++++++++++++++++++++++++++++= ++++ tests/tcg/hexagon/Makefile.target | 1 + 5 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/hexagon/hex_sigsegv.c diff --git a/target/hexagon/helper.h b/target/hexagon/helper.h index ca201fb..412aaf9 100644 --- a/target/hexagon/helper.h +++ b/target/hexagon/helper.h @@ -89,3 +89,5 @@ DEF_HELPER_4(sffms_lib, f32, env, f32, f32, f32) =20 DEF_HELPER_3(dfmpyfix, f64, env, f64, f64) DEF_HELPER_4(dfmpyhh, f64, env, f64, f64, f64) + +DEF_HELPER_3(probe_pkt_stores, void, env, int, int) diff --git a/target/hexagon/op_helper.c b/target/hexagon/op_helper.c index 61d5cde..fa65980 100644 --- a/target/hexagon/op_helper.c +++ b/target/hexagon/op_helper.c @@ -377,6 +377,39 @@ int32_t HELPER(vacsh_pred)(CPUHexagonState *env, return PeV; } =20 +static void probe_store(CPUHexagonState *env, int slot, int mmu_idx) +{ + if (!(env->slot_cancelled & (1 << slot))) { + size1u_t width =3D env->mem_log_stores[slot].width; + target_ulong va =3D env->mem_log_stores[slot].va; + uintptr_t ra =3D GETPC(); + probe_write(env, va, width, mmu_idx, ra); + } +} + +void HELPER(probe_pkt_stores)(CPUHexagonState *env, int mask, int mmu_idx) +{ + bool has_st0 =3D (mask >> 0) & 1; + bool has_st1 =3D (mask >> 1) & 1; + bool has_dczeroa =3D (mask >> 2) & 1; + + 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 =3D env->dczero_addr & ~0x1f; + uintptr_t ra =3D 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 diff --git a/target/hexagon/translate.c b/target/hexagon/translate.c index 6fb4e68..9e8d27a 100644 --- a/target/hexagon/translate.c +++ b/target/hexagon/translate.c @@ -471,9 +471,40 @@ static void update_exec_counters(DisasContext *ctx, Pa= cket *pkt) =20 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 && !ctx->s1_store_processed)) || + pkt->pkt_has_dczeroa) { + TCGv mem_idx =3D tcg_const_tl(ctx->mem_idx); + int mask =3D 0; + TCGv mask_tcgv; + + if (pkt->pkt_has_store_s0) { + mask |=3D (1 << 0); + } + if (pkt->pkt_has_store_s1 && !ctx->s1_store_processed) { + mask |=3D (1 << 1); + } + if (pkt->pkt_has_dczeroa) { + mask |=3D (1 << 2); + } + mask_tcgv =3D tcg_const_tl(mask); + gen_helper_probe_pkt_stores(cpu_env, mask_tcgv, mem_idx); + tcg_temp_free(mem_idx); + tcg_temp_free(mask_tcgv); + } + + 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) { diff --git a/tests/tcg/hexagon/hex_sigsegv.c b/tests/tcg/hexagon/hex_sigseg= v.c new file mode 100644 index 0000000..dc2b349 --- /dev/null +++ b/tests/tcg/hexagon/hex_sigsegv.c @@ -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, + * 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 . + */ + +/* + * Test the VLIW semantics of two stores in a packet + * + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include + +typedef unsigned char uint8_t; + +int err; +int segv_caught; + +#define SHOULD_NOT_CHANGE_VAL 5 +int should_not_change =3D SHOULD_NOT_CHANGE_VAL; + +#define BUF_SIZE 300 +unsigned char buf[BUF_SIZE]; + + +static void __check(const char *filename, int line, int x, int expect) +{ + if (x !=3D expect) { + printf("ERROR %s:%d - %d !=3D %d\n", + filename, line, x, expect); + err++; + } +} + +#define check(x, expect) __check(__FILE__, __LINE__, (x), (expect)) + +static void __chk_error(const char *filename, int line, int ret) +{ + if (ret < 0) { + printf("ERROR %s:%d - %d\n", filename, line, ret); + err++; + } +} + +#define chk_error(ret) __chk_error(__FILE__, __LINE__, (ret)) + +jmp_buf jmp_env; + +static void sig_segv(int sig, siginfo_t *info, void *puc) +{ + check(sig, SIGSEGV); + segv_caught =3D 1; + longjmp(jmp_env, 1); +} + +int main() +{ + struct sigaction act; + + /* SIGSEGV test */ + act.sa_sigaction =3D sig_segv; + sigemptyset(&act.sa_mask); + act.sa_flags =3D SA_SIGINFO; + chk_error(sigaction(SIGSEGV, &act, NULL)); + if (setjmp(jmp_env) =3D=3D 0) { + asm volatile("r18 =3D ##should_not_change\n\t" + "r19 =3D #0\n\t" + "{\n\t" + " memw(r18) =3D #7\n\t" + " memw(r19) =3D #0\n\t" + "}\n\t" + : : : "r18", "r19", "memory"); + } + + act.sa_handler =3D SIG_DFL; + sigemptyset(&act.sa_mask); + act.sa_flags =3D 0; + chk_error(sigaction(SIGSEGV, &act, NULL)); + + check(segv_caught, 1); + check(should_not_change, SHOULD_NOT_CHANGE_VAL); + + puts(err ? "FAIL" : "PASS"); + return err ? EXIT_FAILURE : EXIT_SUCCESS; +} diff --git a/tests/tcg/hexagon/Makefile.target b/tests/tcg/hexagon/Makefile= .target index 050cd61..c1e1650 100644 --- a/tests/tcg/hexagon/Makefile.target +++ b/tests/tcg/hexagon/Makefile.target @@ -28,6 +28,7 @@ first: $(HEX_SRC)/first.S $(CC) -static -mv67 -nostdlib $^ -o $@ =20 HEX_TESTS =3D first +HEX_TESTS +=3D hex_sigsegv HEX_TESTS +=3D misc HEX_TESTS +=3D preg_alias HEX_TESTS +=3D dual_stores --=20 2.7.4