From patchwork Sat Jan 8 06:33:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 530698 Delivered-To: patch@linaro.org Received: by 2002:ad5:544f:0:0:0:0:0 with SMTP id a15csp993397imp; Fri, 7 Jan 2022 23:48:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJxQEYGWpUMbIrITjFsFhZXa/2EmuFaRlju+4vRCcX0c6FtTSXjMOISRKD5F/UDyfSmgV2QY X-Received: by 2002:a25:6d06:: with SMTP id i6mr58213701ybc.444.1641628112677; Fri, 07 Jan 2022 23:48:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641628112; cv=none; d=google.com; s=arc-20160816; b=GwyDq0tB/s4U/n+qWubHbMyHCZZ1SUJ0/w0SCGfi5cpIL68gkgQUfKoBscfVtlJkDb zAdLbDD2Yv9jvBVK+D+k9ivzoYisJo2KR7BjZr0mBSw/ZFrLl/4XWM3mawL6UDAAwpaY QvDfWDNKuX66Z3Z79Uql8Z94IS7dHJgnOhnfONHHhKgEreO++CrGXy8csu9VDEwCv6n9 Lt3MB8x4/ohm8c2y+FYAD8bUIZqdKfWsJb/nr7eAHmvu5t4ckJKyCxwPD23K8+5QpxAp oAbcpAevyMMC7mP8X//1C5erwK3k+l755or9IHOJcW4u6zCpbl9gEE5khu8XFaPqTsxl 0/vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=mVWQbudPOl/uR8TYUS3zfMkysmPkX3RNf4TSFjZ3tBg=; b=NkpDP928M42BlVPkzulcn+VTsWa7xufCH0ikts7ZsrkNuPqvKyjf7JU+WX4bADb+2+ x4LPXyPQQ0e37Zh4lPVK85Um6tekBtqyS47M+FBMJci7uN3P2Tgj9MXoC2smo2iE7bDt 1ZRnf4UOA0dfHcak86QAuGmWPdhpbovh6g62/YdGS74eKRvfJ5QxKttjTe/yUju0XDKx j5gsBzatIqGw68PbHQRfmfD4htWsCV3V8l8tV8toBWqAAxj1M6VifWQTh5YV0J793LVw BmNMtai1M93GSpGptOQfFTpXKtkdDMQqvRS619Ubd5tDgC4EKU+8dcRBf2UfrxmgEW2O jmyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iyphgsqx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r10si907552ybu.765.2022.01.07.23.48.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jan 2022 23:48:32 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iyphgsqx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:40096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n66Sm-0005es-4f for patch@linaro.org; Sat, 08 Jan 2022 02:48:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57760) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n65IE-0001MF-PW for qemu-devel@nongnu.org; Sat, 08 Jan 2022 01:33:36 -0500 Received: from [2607:f8b0:4864:20::1031] (port=46666 helo=mail-pj1-x1031.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n65I9-0003dC-RF for qemu-devel@nongnu.org; Sat, 08 Jan 2022 01:33:31 -0500 Received: by mail-pj1-x1031.google.com with SMTP id rj2-20020a17090b3e8200b001b1944bad25so8916094pjb.5 for ; Fri, 07 Jan 2022 22:33:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mVWQbudPOl/uR8TYUS3zfMkysmPkX3RNf4TSFjZ3tBg=; b=iyphgsqxYs01DBAEg6Ngp0VYmLKlgCkTd9dX14k40zGsCL4hU+D/Hw2lLDR0udXCE7 qHqET75hcHqo764JVB2xEmz0i6xm6B5MvixxFGYnLF6khTbmZh6j90E26bQUOy4LlasQ tRYsJL1USXc9ChFOOF3WPvXFEw4EyddTInT3GVFJlz5VG24bWFLbEs3eNATkHJuwwsCh uo+MoNBSrSHYPxHY3yZJWWnaOwdf+ihe3OdY2ElYEoKsABBK3Extv2dJszgK1vZrWEKI FQJl9mkjS9hiro3l85jk81sFPEjHCrUG7FCuAGtbt+J+sigxBWYXnDR1jrMH96rx5wca S5eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mVWQbudPOl/uR8TYUS3zfMkysmPkX3RNf4TSFjZ3tBg=; b=PV0dfA1Wy529ZQjEPerZchwJ5UyATQza0DKzNXp/IZN5RitWyiWar7z+L2cenOXcGQ uec/BTWVKdp3mlPMTtLxSFPBg1TrBb+EoDmpcNkFvY0uYT0FKbjMZ84y5T/5DevksRtV xEWi5ptrptFbnU3piwhWZUI71LM0GGY7YgYKcrwEC4urdH/rKsaVWIgmfd3wpHKfNdRE APWadC6X/tpannnmgtlN/1lcIWEG4AxzpRrbmjM704SOzxWfoz5YIuG6w7bAbVFawa68 /qXsoRxu1pqQauKaArf9RFhskGcgINmYuu3wYgzfewffkjBJCtvsJ1QL1TSBW/ZmHNzb Wp1g== X-Gm-Message-State: AOAM532YGN89He5A4eV+mbGM1iuBYzNSBb7UBgNxZyqCOQ0kuoD62820 h9Op3s3DTRqJDahOF/neU50MwZOeMR5rsQ== X-Received: by 2002:a17:902:7c15:b0:148:fddf:d828 with SMTP id x21-20020a1709027c1500b00148fddfd828mr24569119pll.2.1641623608606; Fri, 07 Jan 2022 22:33:28 -0800 (PST) Received: from localhost.localdomain (174-21-75-75.tukw.qwest.net. [174.21.75.75]) by smtp.gmail.com with ESMTPSA id s7sm834760pfu.133.2022.01.07.22.33.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jan 2022 22:33:26 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 7/7] tcg/arm: Support raising sigbus for user-only Date: Fri, 7 Jan 2022 22:33:13 -0800 Message-Id: <20220108063313.477784-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220108063313.477784-1-richard.henderson@linaro.org> References: <20220108063313.477784-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::1031 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- tcg/arm/tcg-target.h | 2 - tcg/arm/tcg-target.c.inc | 83 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 81 insertions(+), 4 deletions(-) diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h index 1dd4cd5377..27c27a1f14 100644 --- a/tcg/arm/tcg-target.h +++ b/tcg/arm/tcg-target.h @@ -151,9 +151,7 @@ extern bool use_neon_instructions; /* not defined -- call should be eliminated at compile time */ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t); -#ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS -#endif #define TCG_TARGET_NEED_POOL_LABELS #endif diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc index 1c00311877..1e336a0eea 100644 --- a/tcg/arm/tcg-target.c.inc +++ b/tcg/arm/tcg-target.c.inc @@ -23,6 +23,7 @@ */ #include "elf.h" +#include "../tcg-ldst.c.inc" #include "../tcg-pool.c.inc" int arm_arch = __ARM_ARCH; @@ -1289,8 +1290,6 @@ static void tcg_out_vldst(TCGContext *s, ARMInsn insn, } #ifdef CONFIG_SOFTMMU -#include "../tcg-ldst.c.inc" - /* helper signature: helper_ret_ld_mmu(CPUState *env, target_ulong addr, * int mmu_idx, uintptr_t ra) */ @@ -1589,6 +1588,74 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb) tcg_out_goto(s, COND_AL, qemu_st_helpers[opc & MO_SIZE]); return true; } +#else + +static void tcg_out_test_alignment(TCGContext *s, bool is_ld, TCGReg addrlo, + TCGReg addrhi, unsigned a_bits) +{ + unsigned a_mask = (1 << a_bits) - 1; + TCGLabelQemuLdst *label = new_ldst_label(s); + + label->is_ld = is_ld; + label->addrlo_reg = addrlo; + label->addrhi_reg = addrhi; + + /* We are expecting a_bits to max out at 7, and can easily support 8. */ + tcg_debug_assert(a_mask <= 0xff); + /* tst addr, #mask */ + tcg_out_dat_imm(s, COND_AL, ARITH_TST, 0, addrlo, a_mask); + + /* blne slow_path */ + label->label_ptr[0] = s->code_ptr; + tcg_out_bl_imm(s, COND_NE, 0); + + label->raddr = tcg_splitwx_to_rx(s->code_ptr); +} + +static bool tcg_out_fail_alignment(TCGContext *s, TCGLabelQemuLdst *l) +{ + if (!reloc_pc24(l->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) { + return false; + } + + if (TARGET_LONG_BITS == 64) { + /* 64-bit target address is aligned into R2:R3. */ + if (l->addrhi_reg != TCG_REG_R2) { + tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R2, l->addrlo_reg); + tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R3, l->addrhi_reg); + } else if (l->addrlo_reg != TCG_REG_R3) { + tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R3, l->addrhi_reg); + tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R2, l->addrlo_reg); + } else { + tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R1, TCG_REG_R2); + tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R2, TCG_REG_R3); + tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R3, TCG_REG_R1); + } + } else { + tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R1, l->addrlo_reg); + } + tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_R0, TCG_AREG0); + + /* + * Tail call to the helper, with the return address back inline, + * just for the clarity of the debugging traceback -- the helper + * cannot return. We have used BLNE to arrive here, so LR is + * already set. + */ + tcg_out_goto(s, COND_AL, (const void *) + (l->is_ld ? helper_unaligned_ld : helper_unaligned_st)); + return true; +} + +static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l) +{ + return tcg_out_fail_alignment(s, l); +} + +static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l) +{ + return tcg_out_fail_alignment(s, l); +} #endif /* SOFTMMU */ static void tcg_out_qemu_ld_index(TCGContext *s, MemOp opc, @@ -1686,6 +1753,8 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64) int mem_index; TCGReg addend; tcg_insn_unit *label_ptr; +#else + unsigned a_bits; #endif datalo = *args++; @@ -1709,6 +1778,10 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64) add_qemu_ldst_label(s, true, oi, datalo, datahi, addrlo, addrhi, s->code_ptr, label_ptr); #else /* !CONFIG_SOFTMMU */ + a_bits = get_alignment_bits(opc); + if (a_bits) { + tcg_out_test_alignment(s, true, addrlo, addrhi, a_bits); + } if (guest_base) { tcg_out_qemu_ld_index(s, opc, datalo, datahi, addrlo, TCG_REG_GUEST_BASE, false); @@ -1798,6 +1871,8 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64) int mem_index; TCGReg addend; tcg_insn_unit *label_ptr; +#else + unsigned a_bits; #endif datalo = *args++; @@ -1821,6 +1896,10 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64) add_qemu_ldst_label(s, false, oi, datalo, datahi, addrlo, addrhi, s->code_ptr, label_ptr); #else /* !CONFIG_SOFTMMU */ + a_bits = get_alignment_bits(opc); + if (a_bits) { + tcg_out_test_alignment(s, true, addrlo, addrhi, a_bits); + } if (guest_base) { tcg_out_qemu_st_index(s, COND_AL, opc, datalo, datahi, addrlo, TCG_REG_GUEST_BASE, false);