From patchwork Fri Feb 12 18:48:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 381881 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp3205953jah; Fri, 12 Feb 2021 11:35:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJxRW06uY/yQvrx5eB8gBJyhEUwRhfgGgjx9591S8obpWV8+tbeOojkY+DE/gJJ1Xwo/f7Lh X-Received: by 2002:a25:f81d:: with SMTP id u29mr6393218ybd.335.1613158545480; Fri, 12 Feb 2021 11:35:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613158545; cv=none; d=google.com; s=arc-20160816; b=tJLwmTHwqCVQzj5l4iocY/yyNdPLv+QYy7yCxIUalcRxGFjyje+8IJ8JgvogeAj/+1 oMhnsBzoYqxVNO8hYdlAODYbMzgX+ev5vAs4Mzz65be1lAlFX1vBOtwVWzfkIqDrzfAf 8prqU+T9g8uF7eYp7jhb8vmWz7QMBZNqKY5tj7iClyV1AKeAxVgTvkHDE188l2c6+lwC qdqBWn7kD3Te2+NQApkavYVLPwJE+lCK7tBj1pBKvIyO+Uwx+ms7yfTG0a7R6g1lWxGD M/iD2i2x100KVg8N0d+FwF7iNF9Oa5kHGC1rjI5rcei/5H8oSV+ezVC+gKBeuyxAQ1e0 eQXQ== 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=+5hZcB3mFjnWG5tCYVBAVH8vDfhhkDYHCqbXJC4msCo=; b=uf7Dw1J2UQAxnJLxm98xJeFE6ZgnOrdd4VFG2iv0ylneWVFq/b3sUaUuvYQeW2/6Io h9rv55o0Sm8dxmx3mCSiJkeKg8U1UtKPUBz+g0ayK3oLpj5NwykQ74omupB++7+PeYid afMnpmzdFO4rjhpCPUyH6bligpjve1uYEwo4Jb5rIVy4VVtozB6FctDSiDK18GNaP04D 9as5HaXp9ejyFaoPZjXer/j+JULxT43JHZoenrb4oQxWe8G+mOd7l3PYyJd53RHLr4Vo yUObDk/cs4lhuO+hrJXiyQZWvEO3Th+N//nd+Jib6VYQWFrL6G22Wp8mZkrhgMskgOQs TqoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GtQ9tGDz; 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 k3si10858511ybg.167.2021.02.12.11.35.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Feb 2021 11:35:45 -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=GtQ9tGDz; 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]:51786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lAeEC-0006Za-VE for patch@linaro.org; Fri, 12 Feb 2021 14:35:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lAdVh-00028y-MB for qemu-devel@nongnu.org; Fri, 12 Feb 2021 13:49:45 -0500 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:35455) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lAdVa-0007td-UH for qemu-devel@nongnu.org; Fri, 12 Feb 2021 13:49:45 -0500 Received: by mail-pg1-x535.google.com with SMTP id t25so260566pga.2 for ; Fri, 12 Feb 2021 10:49:38 -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=+5hZcB3mFjnWG5tCYVBAVH8vDfhhkDYHCqbXJC4msCo=; b=GtQ9tGDzfX//z1tZrGnr4M0HenudlN48lmOguoujGKTgVc19m1m/SlpvKBoqqCiXI5 KXcZCGgpi4GXncaAz9CtnsAQr5G6f9JUAST+PhvBZhm6cSZITDTjvIdrgsySaSCQUZUm 4UXrwSU2llZkj7W2K2DpC4qPo59mRfuCoODbcLafDpDPc4R1aWGPgZoMvWA/9/uZHpiA WBoCEYMs3mFJJAbo1jx06/yicE4bH8x+IZKnKzH7gEhEEe807zilzPiP8x7T+yEvZv5W qoOekpX0zHDRByFoqO8T5eGjbU4KRMCZ4kWFnOjy7EjBOINUuCVShdYPPrxZvD4wjizy 9w7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+5hZcB3mFjnWG5tCYVBAVH8vDfhhkDYHCqbXJC4msCo=; b=oesnK6KjvkUgjcYR8FCBci9rHaJ1UpSWtWkBm2RFLj3e86dLq03EwP+XMjbI8C67Ud edtFgQdmj/ZcGt+n4Y/AyOXeLpc1S10WijoKxcBE/vEH5MololMIZgJv51Gi8cy8PJOQ 36ejVPjlU+0C7qUFKoCzSLasXhNwPjUVzDTLYQfSz6FES1eZiwW6L0zX1miSurOrEubJ LPQOTa08pL2HOIzUPrZTozwgMLZmgb0M482BNiKSuT4oi0BL0g+AbnDS2LIUAEhUBEMd szJdOo1ZceLIvzA+J8H752QJ2kw3znpt9NZyZF5X2LbKcN2UUcw6oWUzPnr1ism4l4/q odlA== X-Gm-Message-State: AOAM531j+HXH9tvRPrls5SM0lq2K+Kzus7ukBvp1/8OO1pLAuTGnL5Ml y6ItSX2/BdhU221hNBeA9e1LtSHKOFKqvg== X-Received: by 2002:a63:1611:: with SMTP id w17mr4431324pgl.330.1613155776661; Fri, 12 Feb 2021 10:49:36 -0800 (PST) Received: from localhost.localdomain (174-21-150-71.tukw.qwest.net. [174.21.150.71]) by smtp.gmail.com with ESMTPSA id k5sm9427618pfi.31.2021.02.12.10.49.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Feb 2021 10:49:36 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v7 26/31] linux-user/aarch64: Pass syndrome to EXC_*_ABORT Date: Fri, 12 Feb 2021 10:48:57 -0800 Message-Id: <20210212184902.1251044-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210212184902.1251044-1-richard.henderson@linaro.org> References: <20210212184902.1251044-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x535.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: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" A proper syndrome is required to fill in the proper si_code. Use page_get_flags to determine permission vs translation for user-only. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/aarch64/cpu_loop.c | 24 +++++++++++++++++++++--- target/arm/tlb_helper.c | 15 +++++++++------ 2 files changed, 30 insertions(+), 9 deletions(-) -- 2.25.1 diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index 42b9c15f53..4e43906e66 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -23,6 +23,7 @@ #include "cpu_loop-common.h" #include "qemu/guest-random.h" #include "hw/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)); \ @@ -76,7 +77,7 @@ void cpu_loop(CPUARMState *env) { CPUState *cs = env_cpu(env); - int trapnr; + int trapnr, ec, fsc; abi_long ret; target_siginfo_t info; @@ -117,9 +118,26 @@ void cpu_loop(CPUARMState *env) case EXCP_DATA_ABORT: info.si_signo = TARGET_SIGSEGV; info.si_errno = 0; - /* XXX: check env->error_code */ - info.si_code = TARGET_SEGV_MAPERR; info._sifields._sigfault._addr = env->exception.vaddress; + + /* We should only arrive here with EC in {DATAABORT, INSNABORT}. */ + ec = syn_get_ec(env->exception.syndrome); + assert(ec == EC_DATAABORT || ec == EC_INSNABORT); + + /* Both EC have the same format for FSC, or close enough. */ + fsc = extract32(env->exception.syndrome, 0, 6); + switch (fsc) { + case 0x04 ... 0x07: /* Translation fault, level {0-3} */ + info.si_code = TARGET_SEGV_MAPERR; + break; + case 0x09 ... 0x0b: /* Access flag fault, level {1-3} */ + case 0x0d ... 0x0f: /* Permission fault, level {1-3} */ + info.si_code = TARGET_SEGV_ACCERR; + break; + default: + g_assert_not_reached(); + } + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); break; case EXCP_DEBUG: diff --git a/target/arm/tlb_helper.c b/target/arm/tlb_helper.c index df85079d9f..9609333cbd 100644 --- a/target/arm/tlb_helper.c +++ b/target/arm/tlb_helper.c @@ -154,21 +154,24 @@ bool arm_cpu_tlb_fill(CPUState *cs, vaddr address, int size, bool probe, uintptr_t retaddr) { ARMCPU *cpu = ARM_CPU(cs); + ARMMMUFaultInfo fi = {}; #ifdef CONFIG_USER_ONLY - cpu->env.exception.vaddress = address; - if (access_type == MMU_INST_FETCH) { - cs->exception_index = EXCP_PREFETCH_ABORT; + int flags = page_get_flags(useronly_clean_ptr(address)); + if (flags & PAGE_VALID) { + fi.type = ARMFault_Permission; } else { - cs->exception_index = EXCP_DATA_ABORT; + fi.type = ARMFault_Translation; } - cpu_loop_exit_restore(cs, retaddr); + + /* now we have a real cpu fault */ + cpu_restore_state(cs, retaddr, true); + arm_deliver_fault(cpu, address, access_type, mmu_idx, &fi); #else hwaddr phys_addr; target_ulong page_size; int prot, ret; MemTxAttrs attrs = {}; - ARMMMUFaultInfo fi = {}; ARMCacheAttrs cacheattrs = {}; /*