From patchwork Mon Sep 20 02:45:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 514293 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp1667923jao; Sun, 19 Sep 2021 19:47:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3y4Vln6GQashxu3Jhv9b3QKA2im4dIHCiLMJOPfhYSxAkdcwgd0F5jddUWnaZRzY/AZud X-Received: by 2002:ac8:7d84:: with SMTP id c4mr21062157qtd.254.1632106029041; Sun, 19 Sep 2021 19:47:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632106029; cv=none; d=google.com; s=arc-20160816; b=OzVy4b0iKrG8eCvGNdoqtnzkcE3XAiK/EjT65GPWRfQrIP1myJuhS+lVby1SygTG5M /xRlM2M/Fy6AzWosAeIpuoCUo3iUWmkSr60rvWXcttZIgDVa8cw+Nbt3YytyVU+mlxDj p5JXRvbBFZQ+6FNMuuo638XJiEw426/w3MwHnKl/Ol1c4R3N31789IonmZsCC+hwcB83 1qEA6FNBtiBeL/7GwGQtYxOnY+lX/qDeqlFWAMQqGU7XlxhYbeWlA6P5WZatFlcziH0y 121Vnp1c7x0Rr3p/77I4tg9V0wEujQdPr4rq/dhtzZnEQP0GVTskGRhOLlFvYffIlKfl kG4Q== 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=6vZb5MWAv/fM2L9STadGzJOqVrgkaOYinJFwq93jV/c=; b=jTyK41osb5/YrI4ykT9oTd9UAyOlmibn0xPbBHqLkZjhAomkxobSS/qMegGv3+M/b8 nucmK5bNbWYBCLFij9JHAaQAOSa+TDAJa5/qyG3PMnpiskdXj8WMn3XxjTKpGBX1HYrR LlWAugaDBPLoXVW0tu4KkTkCHuNaYr6kQUT0zrRNknFLQzR9moBWSxAwhxHz6tgVY1D3 v3xfgRyzMJ1YoWqUKzcY1kIaoJ4p323VLn0gx89W3VDf0P9kr3EigWUqeaOztDztrdg6 NcX9ptbzNtZ2IZvQIDvfYafd7wheFGy9/h/GDRR8k6hP1YjgkTv+s/CTDmWnomnu0SVl FrHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=lKIx7rDq; 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=fail (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 x125si8026084qke.183.2021.09.19.19.47.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 19 Sep 2021 19:47:09 -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=fail header.i=@linaro.org header.s=google header.b=lKIx7rDq; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:40174 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mS9Km-0005Fe-BH for patch@linaro.org; Sun, 19 Sep 2021 22:47:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57450) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mS9It-0005D0-5d for qemu-devel@nongnu.org; Sun, 19 Sep 2021 22:45:12 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]:36706) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mS9Ir-0008Co-63 for qemu-devel@nongnu.org; Sun, 19 Sep 2021 22:45:10 -0400 Received: by mail-pf1-x429.google.com with SMTP id m26so14907822pff.3 for ; Sun, 19 Sep 2021 19:45:08 -0700 (PDT) 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=6vZb5MWAv/fM2L9STadGzJOqVrgkaOYinJFwq93jV/c=; b=lKIx7rDq/+M2DK6H7v1tQhDLkae1ND9EkyyKSubRMo6LZt6CGZxLX7aeMKwb5tzFHd VQhI9SRUHKGzPvVbM9kvkEbA9IJlXGEP51SCWX0c4HeVvAi1Ymy1RVGNRaPBuEbp1Wnf 1KzsmTB86ibaUJkimv3hekUTe/6qiS9lvd9H7RClVV/J51c9wF6Ce6bzkDyHXZyjLLgb 2dGbqNhtEscguz4BjS66wGGL/IBP4bdDuaBNtCf/3K//69yWMtNCc3wm/AIEh2BUErW/ TVxFzG2vfI4QtVn5ag4Si6F8cQ+RIB8Ko1/iimKmlpHmZOpvJ09eixnb6pAMnhrBDtpo U4Mg== 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=6vZb5MWAv/fM2L9STadGzJOqVrgkaOYinJFwq93jV/c=; b=gMknAYHtSv/Y6Nt/rL3zmByZw7B/ZT3eG7brGa2lGAmPKwOLrLHM6R2fw42B6atmAc jTu9/PLOy0gm+f7XYSapPfZP3c3/UHhZiezhiPQF039xQFjLKbfLLdwqN/cE+CO5U7Po jmui83prOLqbMHBqY7R238GcGmN0xrBbZlN4rYfEo5iveFkRDqfgHweRJ4f/JQnTgBUa 1hQ3pmXxDXKaO0LbpWmFeLq3evkwPop36vA6kba8Kq2lc9lPHXczyxkVy1oL+RUNqUZq vOBfpMilJEbRn8cSCaKgKUDcdzRTNP4t7/NVDPzl32AyjnNy0PzzCeCgtW5KLYfqDhun qqRA== X-Gm-Message-State: AOAM532Y/AidxMKpPj//Z2WMs1Yuu1esFt+BXSmw58FMoBxiPgiqsiGw KCTmCf8RqvFGM94ERMEU+r/LEMLv6CniIg== X-Received: by 2002:a63:f5b:: with SMTP id 27mr12402253pgp.302.1632105907798; Sun, 19 Sep 2021 19:45:07 -0700 (PDT) Received: from localhost.localdomain ([71.212.134.125]) by smtp.gmail.com with ESMTPSA id fh3sm16164767pjb.8.2021.09.19.19.45.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Sep 2021 19:45:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 2/6] linux-user/arm: Report SIGBUS and SIGSEGV correctly Date: Sun, 19 Sep 2021 19:45:00 -0700 Message-Id: <20210920024504.625965-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210920024504.625965-1-richard.henderson@linaro.org> References: <20210920024504.625965-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.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=unavailable 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: Peter Maydell , qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Pull the fault information from where we placed it, in arm_cpu_tlb_fill and arm_cpu_do_unaligned_access. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/arm/cpu_loop.c | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) -- 2.25.1 diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c index d4b4f0c71f..1377a80620 100644 --- a/linux-user/arm/cpu_loop.c +++ b/linux-user/arm/cpu_loop.c @@ -24,6 +24,7 @@ #include "cpu_loop-common.h" #include "signal-common.h" #include "semihosting/common-semi.h" +#include "target/arm/syndrome.h" #define get_user_code_u32(x, gaddr, env) \ ({ abi_long __r = get_user_u32((x), (gaddr)); \ @@ -279,8 +280,8 @@ static bool emulate_arm_fpa11(CPUARMState *env, uint32_t opcode) void cpu_loop(CPUARMState *env) { CPUState *cs = env_cpu(env); - int trapnr; - unsigned int n, insn; + int trapnr, si_signo, si_code; + unsigned int n, insn, ec, fsc; abi_ulong ret; for(;;) { @@ -422,9 +423,37 @@ void cpu_loop(CPUARMState *env) break; case EXCP_PREFETCH_ABORT: case EXCP_DATA_ABORT: - /* XXX: check env->error_code */ - force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR, - env->exception.vaddress); + /* + * For user-only we don't set TTBCR_EAE, so we always get + * short-form FSC, which then tells us to look at the FSR. + */ + ec = syn_get_ec(env->exception.syndrome); + assert(ec == EC_DATAABORT || ec == EC_INSNABORT); + fsc = extract32(env->exception.syndrome, 0, 6); + assert(fsc == 0x3f); + switch (env->exception.fsr & 0x1f) { + case 0x1: /* Alignment */ + si_signo = TARGET_SIGBUS; + si_code = TARGET_BUS_ADRALN; + break; + case 0x3: /* Access flag fault, level 1 */ + case 0x6: /* Access flag fault, level 2 */ + case 0x9: /* Domain fault, level 1 */ + case 0xb: /* Domain fault, level 2 */ + case 0xd: /* Permission fault, level 1 */ + case 0xf: /* Permission fault, level 2 */ + si_signo = TARGET_SIGSEGV; + si_code = TARGET_SEGV_ACCERR; + break; + case 0x5: /* Translation fault, level 1 */ + case 0x7: /* Translation fault, level 2 */ + si_signo = TARGET_SIGSEGV; + si_code = TARGET_SEGV_MAPERR; + break; + default: + g_assert_not_reached(); + } + force_sig_fault(si_signo, si_code, env->exception.vaddress); break; case EXCP_DEBUG: case EXCP_BKPT: