From patchwork Wed Aug 18 19:19:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 498979 Delivered-To: patch@linaro.org Received: by 2002:a02:6f15:0:0:0:0:0 with SMTP id x21csp1003335jab; Wed, 18 Aug 2021 13:16:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtRhLhfIWYtRtUz6v2ylWWHuvcYG1nCyPjy3B0bgu/PyB9H9Jmk00cgTiXUaJngYkHXv4z X-Received: by 2002:a05:6122:2087:: with SMTP id i7mr9031895vkd.25.1629317791217; Wed, 18 Aug 2021 13:16:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629317791; cv=none; d=google.com; s=arc-20160816; b=wLenjWdJ/RZIsV52FPujGEALnRE8hb3gy3r0JKgyxoh+5YAjxu1gVbkukpkaRxmMuc 8AimoZSBby+BsNHsbQif+Qsolfh0qLEpzjLySY6JxLwPasDkNPJg0tw+62okJt1CE+gl SBOwdblg++JeBLI2MMyg5eVcjtENHIQmGX7szYNWrnvSZ1Mp9Xp7ysyONAFJH74amqqb 5dHMQOJCsiV7H3Sy2yq03OfsHPvKba6bdlGvLk0SChVncLe38QAFxhXRmh8GXfgUMrjC 4NLbVS/KN4m0+7GSCD0Bc2Scy94u26BOgnynfSsEC6GsWhvNECQRb4wvq2mP7DXM50/Q HDuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=tNc7kjivBSXK/2oaNMevLGDoAV8pJMGnlziC9HUk9AQ=; b=TL5dXUcCPmUxxDQNWZMsFuWEwRT0gASuF/aZ+Nuetg6ouphAranx5JPxIwjUhbtB8V 84qY1f3m7R6slk+/XeJHPQBwOtGa6DI3qmeYpfib45L/bciwOfLF073T8I7Wscm1xVfm tLYhqTdt4LaSfsiw499oWHq4NENs+rm3gaKXVxSdk3fCngL2RLQhycNsDSUyfsQtoq/v u+TEW8+txEGyekkldCF7Dgnq0/pot6CYwFtgmuAy/rAxm7vI7z+IvhHIFLzJS+M+rowL riZziQP18nRZ65a0xJgFW1HXsWjAIUU/K+BoSqqj/RJuV8Sq8s3rhnEBg3BTzgPduIYo FEYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=p4OslaN3; 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 h3si481462vsj.220.2021.08.18.13.16.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Aug 2021 13:16:31 -0700 (PDT) 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=p4OslaN3; 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]:57456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mGRzC-0001ms-H1 for patch@linaro.org; Wed, 18 Aug 2021 16:16:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59082) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mGRA7-0008Mp-Qn for qemu-devel@nongnu.org; Wed, 18 Aug 2021 15:23:43 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]:36727) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mGRA6-0002wp-3t for qemu-devel@nongnu.org; Wed, 18 Aug 2021 15:23:43 -0400 Received: by mail-pl1-x632.google.com with SMTP id f3so2464676plg.3 for ; Wed, 18 Aug 2021 12:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=tNc7kjivBSXK/2oaNMevLGDoAV8pJMGnlziC9HUk9AQ=; b=p4OslaN3T4mcV/zlOqywUNrw0AZoWTNe4L8qV43jswGpnQd6/dUdUzpnNo63gSijnX bJM3awk++YHrXCVEA0UwCfMtZBZtnY8GktnLA98HNzk+qprlc6iVK7yZy1fyZ3an6JUM TyxUr/OzPXEbgSVEYYrVEQo1fIdjYsnyCc9fgtLkhYibO4Mw6rAOua466IksO/HAk/sV MsP13pr0XXwHQ8hhuW579sGMidRViR/Q9uTd8kHcma1CUw5n/9TVTLffw1u/ihY9m4PL MNElH+RfS7zJk6n4sOxmHuTWkzX8NqVkBg6Mqm0igTKgqqDFn7VK9jQs7zDuqqxokWZ5 IEWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tNc7kjivBSXK/2oaNMevLGDoAV8pJMGnlziC9HUk9AQ=; b=POOcbx/nDm8PB4ImV1hDafAar2LAN8VRKAz2sxRNZX4TR2dYyMRaTZO2Vq8LIR9SJt WVuR90Ghc5OWP0Bx6/YItNX74nFDw3WfHAvB64Ru8FblF7PdWU+cPINGqbHwEqFIYTyf 0Np1gPO7f3T4Oa/AKs6IZeWltWEl1FxgHm6mygkqhJ3W94MhDRyAhFlYip0cR465ONB0 8OHs1FooRzOYQ898m43X8T4AU6qHz7cOA6dScFUAuyeozY5EPmYUERd8uI7PipEbH5hr MuXJsAKqDmqbgCXGuuMvklpopDkT7bPxHdfQ2B1YKDQFsy0jDdj3wG31HCzMbHagFue3 vxrg== X-Gm-Message-State: AOAM530N7vh87i5pZam0Ux5c8QCqUs+B8ruTe8fvuiN4vbArS8LfE12u yw5OGFszD22CbNBI8awn1mbFoNPJEA3rTQ== X-Received: by 2002:a17:90a:de16:: with SMTP id m22mr11078824pjv.54.1629314620815; Wed, 18 Aug 2021 12:23:40 -0700 (PDT) Received: from localhost.localdomain ([173.197.107.15]) by smtp.gmail.com with ESMTPSA id w82sm569302pff.112.2021.08.18.12.23.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 12:23:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 65/66] tcg/riscv: Support raising sigbus for user-only Date: Wed, 18 Aug 2021 09:19:19 -1000 Message-Id: <20210818191920.390759-66-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210818191920.390759-1-richard.henderson@linaro.org> References: <20210818191920.390759-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- tcg/riscv/tcg-target.h | 2 -- tcg/riscv/tcg-target.c.inc | 64 +++++++++++++++++++++++++++++++++++--- 2 files changed, 60 insertions(+), 6 deletions(-) -- 2.25.1 diff --git a/tcg/riscv/tcg-target.h b/tcg/riscv/tcg-target.h index ef78b99e98..11c9b3e4f4 100644 --- a/tcg/riscv/tcg-target.h +++ b/tcg/riscv/tcg-target.h @@ -165,9 +165,7 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t); #define TCG_TARGET_DEFAULT_MO (0) -#ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS -#endif #define TCG_TARGET_NEED_POOL_LABELS #define TCG_TARGET_HAS_MEMORY_BSWAP 0 diff --git a/tcg/riscv/tcg-target.c.inc b/tcg/riscv/tcg-target.c.inc index c1b0c3764d..f75dcf88f8 100644 --- a/tcg/riscv/tcg-target.c.inc +++ b/tcg/riscv/tcg-target.c.inc @@ -27,6 +27,7 @@ * THE SOFTWARE. */ +#include "../tcg-ldst.c.inc" #include "../tcg-pool.c.inc" #ifdef CONFIG_DEBUG_TCG @@ -847,8 +848,6 @@ static void tcg_out_mb(TCGContext *s, TCGArg a0) */ #if defined(CONFIG_SOFTMMU) -#include "../tcg-ldst.c.inc" - /* helper signature: helper_ret_ld_mmu(CPUState *env, target_ulong addr, * MemOpIdx oi, uintptr_t ra) */ @@ -1053,6 +1052,53 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l) tcg_out_goto(s, l->raddr); return true; } +#else + +static void tcg_out_test_alignment(TCGContext *s, bool is_ld, TCGReg addr_reg, + unsigned a_bits) +{ + unsigned a_mask = (1 << a_bits) - 1; + TCGLabelQemuLdst *l = new_ldst_label(s); + + l->is_ld = is_ld; + l->addrlo_reg = addr_reg; + + /* We are expecting a_bits to max out at 7, so we can always use andi. */ + tcg_debug_assert(a_bits < 12); + tcg_out_opc_imm(s, OPC_ANDI, TCG_REG_TMP1, addr_reg, a_mask); + + l->label_ptr[0] = s->code_ptr; + tcg_out_opc_branch(s, OPC_BNE, TCG_REG_TMP1, TCG_REG_ZERO, 0); + + l->raddr = tcg_splitwx_to_rx(s->code_ptr); +} + +static bool tcg_out_fail_alignment(TCGContext *s, TCGLabelQemuLdst *l) +{ + /* resolve label address */ + if (!reloc_sbimm12(l->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) { + return false; + } + + tcg_out_mov(s, TCG_TYPE_TL, TCG_REG_A1, l->addrlo_reg); + tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_A0, TCG_AREG0); + /* tail call, with the return address back inline for unwinding */ + tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_RA, (uintptr_t)l->raddr); + tcg_out_call_int(s, (const void *)(l->is_ld ? helper_unaligned_ld + : helper_unaligned_st), true); + 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 /* CONFIG_SOFTMMU */ static void tcg_out_qemu_ld_direct(TCGContext *s, TCGReg lo, TCGReg hi, @@ -1108,6 +1154,8 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64) MemOp opc; #if defined(CONFIG_SOFTMMU) tcg_insn_unit *label_ptr[1]; +#else + unsigned a_bits; #endif TCGReg base = TCG_REG_TMP0; @@ -1130,7 +1178,10 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64) tcg_out_ext32u(s, base, addr_regl); addr_regl = base; } - + a_bits = get_alignment_bits(opc); + if (a_bits) { + tcg_out_test_alignment(s, true, addr_regl, a_bits); + } if (guest_base == 0) { tcg_out_opc_reg(s, OPC_ADD, base, addr_regl, TCG_REG_ZERO); } else { @@ -1177,6 +1228,8 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64) MemOp opc; #if defined(CONFIG_SOFTMMU) tcg_insn_unit *label_ptr[1]; +#else + unsigned a_bits; #endif TCGReg base = TCG_REG_TMP0; @@ -1199,7 +1252,10 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64) tcg_out_ext32u(s, base, addr_regl); addr_regl = base; } - + a_bits = get_alignment_bits(opc); + if (a_bits) { + tcg_out_test_alignment(s, false, addr_regl, a_bits); + } if (guest_base == 0) { tcg_out_opc_reg(s, OPC_ADD, base, addr_regl, TCG_REG_ZERO); } else {