From patchwork Thu Jul 29 00:46:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 488620 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:1185:0:0:0:0 with SMTP id f5csp1702454jas; Wed, 28 Jul 2021 17:52:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvCTCJSE6f22VcBxLMdd0PGSbfCfpx/IAEqyuo6ziVBwfwLOtSNGAAc3f/34QSlN3s6UXy X-Received: by 2002:a05:6e02:170c:: with SMTP id u12mr1788276ill.116.1627519954097; Wed, 28 Jul 2021 17:52:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627519954; cv=none; d=google.com; s=arc-20160816; b=SgUxHp52q1+SRS6a8N7No/xxohnjaylT+kWIWJZ/Ug63o/+IrR5xd/JepFhYSxORmz f0lso46wnuVZyoqoa4UVEtxBz/uU4FVjFDWKin013ZiP43Aqmk7qUUbRtOHsPaF7HCtN XoYI+a9Oe7yEcr46Ojnojaq6FHubVBOmFpXsRgwtYwzyZxTRarOVKNta1eDFcd12tUkP RnquSpNwpU9lEaoonYKx74ccCjCbZhhp7O75xDoSPKOpYMgTh/PiP3iRq6NMmAN/9RNS 21AzEJURnqZfctmMOdZ9BkLoNf1SO9Z2bmdBORgaCYGAXIedbuxRP29xoqAHzhjJ8g7V z1Rg== 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=5SVn6feIQx+0Ew2ry6c3LKcwRGxaKfiCe+3GLQs/DO0=; b=j5hH9psA6mFe7pL77mHps75lucXJppvIckcuOsCqM1Mm53pO8czjoBVqH8WTX7dGAi sd1t2+qs0xQrJzqh8sGt4iUno6EchNqpWxChiiwQH0o4bOiNmQR74ttKWueR1OM0nEcU EUsQSQM2gMZzwrFicBhU/jNPT+hlIk1D10ROFIB0OU8NjzZdWgl//UVH0o3MBXnTk+2g XjAYmgGH9E9rHsN1qnK8XkPHAH1VM9nMWsYLvB93Mrwswcefqepp1UGJuHpUY+JsD3wv b4Wfx57/XWHyi+gR/s7EEsIn1Yog46ibaDw1X3K1oK7eSGvY+fFQbu9rqSXBiWlCYnEB qwnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tcCKdAi2; 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 n14si1592369ilk.78.2021.07.28.17.52.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Jul 2021 17:52:34 -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=tcCKdAi2; 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]:39818 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m8uHp-0001bn-Bn for patch@linaro.org; Wed, 28 Jul 2021 20:52:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36784) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m8uCS-0003y4-9G for qemu-devel@nongnu.org; Wed, 28 Jul 2021 20:47:00 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:35809) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m8uCQ-0002Q3-Hv for qemu-devel@nongnu.org; Wed, 28 Jul 2021 20:47:00 -0400 Received: by mail-pl1-x629.google.com with SMTP id f13so4893018plj.2 for ; Wed, 28 Jul 2021 17:46:58 -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=5SVn6feIQx+0Ew2ry6c3LKcwRGxaKfiCe+3GLQs/DO0=; b=tcCKdAi25mDJZANb8iM5EMuZfgC63vc65PWVHy6dDhCdUcaW5V5Xp1gNCREejml6NN /Hkmf3gDdgID6WOL8afhaXSfzS0P1drmf2Lh/1Laf+lra+SjaWbQdXnEU9G0prA6J/1v JuMMy8NdVrf6EFVPbqC/aM9tHnXwprn0GFTR1f9LIjdcMsiUrQPh8gz7uvFLSQY34YCT PdFxxMBLxCXKLPEw+iCRjJNZhuKlqPmiqDxbijojXUc/M64yP91BLLCv/bqPXBK/wEN6 6/42419qYdaQh3Pdd8MDVV9E3GY5jY83+dzvWKlnPLLzd1XVGZNKHmg2yAs9wDQeW6Js 24WQ== 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=5SVn6feIQx+0Ew2ry6c3LKcwRGxaKfiCe+3GLQs/DO0=; b=lRYWb7qvLt+HwW0C9It/jnNiSxXD54KQrkQe+5cWOaiCdZ0eaqEUHuoHvsrF3xoY1G b4Zw+LihdfDU0PXEP7CyObBAOQ/Oiu2l3erR7sTG8oeuP+24YuxB53OAencyt2qO2ein M4028reyGfi0qlnAal2cWm2Mc2dap/VKqmy2bitout4pQeGtTIbH2cej3rgaZDRwLH5y 3rpJ0f0v2FWqqwNbhn/erGGg8cLnSXx6T0Ewevv7zXhHsaxZNC9iW/OcV2Xhinx6RzZA Qtbc6387xYqOi+7qQjLN5NeQGfZYKAqI4+NCDdy+82fTwdvHjTJaB3C3QIKs9+jYeFmc krWg== X-Gm-Message-State: AOAM533P1lv9SybCpjn6F9jPhFHQl30zSx20MRYjlVEX6lqSSVcpmVKV ChEuYvUdjeFy+W5DF8etbBLFhupRQuohlA== X-Received: by 2002:a63:1e59:: with SMTP id p25mr1468393pgm.110.1627519617374; Wed, 28 Jul 2021 17:46:57 -0700 (PDT) Received: from cloudburst.home (2603-800c-3202-ffa7-dcaa-9e71-a2b2-2604.res6.spectrum.com. [2603:800c:3202:ffa7:dcaa:9e71:a2b2:2604]) by smtp.gmail.com with ESMTPSA id t205sm1305005pfc.32.2021.07.28.17.46.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 17:46:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH for-6.2 06/43] target/mips: Implement do_unaligned_access for user-only Date: Wed, 28 Jul 2021 14:46:10 -1000 Message-Id: <20210729004647.282017-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210729004647.282017-1-richard.henderson@linaro.org> References: <20210729004647.282017-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.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: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Cc: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/mips/cpu_loop.c | 20 ++++++++++++++++---- target/mips/cpu.c | 2 +- target/mips/tcg/op_helper.c | 3 +-- target/mips/tcg/user/tlb_helper.c | 23 +++++++++++------------ 4 files changed, 29 insertions(+), 19 deletions(-) -- 2.25.1 diff --git a/linux-user/mips/cpu_loop.c b/linux-user/mips/cpu_loop.c index 9d813ece4e..51f4eb65a6 100644 --- a/linux-user/mips/cpu_loop.c +++ b/linux-user/mips/cpu_loop.c @@ -158,12 +158,24 @@ done_syscall: break; case EXCP_TLBL: case EXCP_TLBS: - case EXCP_AdEL: - case EXCP_AdES: info.si_signo = TARGET_SIGSEGV; info.si_errno = 0; - /* XXX: check env->error_code */ - info.si_code = TARGET_SEGV_MAPERR; + info.si_code = (env->error_code & EXCP_TLB_NOMATCH + ? TARGET_SEGV_MAPERR : TARGET_SEGV_ACCERR); + info._sifields._sigfault._addr = env->CP0_BadVAddr; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_AdEL: + case EXCP_AdES: + /* + * Note that on real hw AdE is also raised for access to a + * kernel address from user mode instead of a TLB error. + * For simplicity, we do not distinguish this in the user + * version of mips_cpu_tlb_fill so only unaligned comes here. + */ + info.si_signo = TARGET_SIGBUS; + info.si_errno = 0; + info.si_code = TARGET_BUS_ADRALN; info._sifields._sigfault._addr = env->CP0_BadVAddr; queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); break; diff --git a/target/mips/cpu.c b/target/mips/cpu.c index d426918291..a1658af910 100644 --- a/target/mips/cpu.c +++ b/target/mips/cpu.c @@ -541,11 +541,11 @@ static const struct TCGCPUOps mips_tcg_ops = { .synchronize_from_tb = mips_cpu_synchronize_from_tb, .cpu_exec_interrupt = mips_cpu_exec_interrupt, .tlb_fill = mips_cpu_tlb_fill, + .do_unaligned_access = mips_cpu_do_unaligned_access, #if !defined(CONFIG_USER_ONLY) .do_interrupt = mips_cpu_do_interrupt, .do_transaction_failed = mips_cpu_do_transaction_failed, - .do_unaligned_access = mips_cpu_do_unaligned_access, .io_recompile_replay_branch = mips_io_recompile_replay_branch, #endif /* !CONFIG_USER_ONLY */ }; diff --git a/target/mips/tcg/op_helper.c b/target/mips/tcg/op_helper.c index fafbf1faca..0b874823e4 100644 --- a/target/mips/tcg/op_helper.c +++ b/target/mips/tcg/op_helper.c @@ -375,8 +375,6 @@ void helper_pmon(CPUMIPSState *env, int function) } } -#if !defined(CONFIG_USER_ONLY) - void mips_cpu_do_unaligned_access(CPUState *cs, vaddr addr, MMUAccessType access_type, int mmu_idx, uintptr_t retaddr) @@ -402,6 +400,7 @@ void mips_cpu_do_unaligned_access(CPUState *cs, vaddr addr, do_raise_exception_err(env, excp, error_code, retaddr); } +#if !defined(CONFIG_USER_ONLY) void mips_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr, unsigned size, MMUAccessType access_type, diff --git a/target/mips/tcg/user/tlb_helper.c b/target/mips/tcg/user/tlb_helper.c index b835144b82..61a99356e9 100644 --- a/target/mips/tcg/user/tlb_helper.c +++ b/target/mips/tcg/user/tlb_helper.c @@ -26,24 +26,23 @@ static void raise_mmu_exception(CPUMIPSState *env, target_ulong address, MMUAccessType access_type) { CPUState *cs = env_cpu(env); + int error_code = 0; + int flags; - env->error_code = 0; if (access_type == MMU_INST_FETCH) { - env->error_code |= EXCP_INST_NOTAVAIL; + error_code |= EXCP_INST_NOTAVAIL; } - /* Reference to kernel address from user mode or supervisor mode */ - /* Reference to supervisor address from user mode */ - if (access_type == MMU_DATA_STORE) { - cs->exception_index = EXCP_AdES; - } else { - cs->exception_index = EXCP_AdEL; + flags = page_get_flags(address); + if (!(flags & PAGE_VALID)) { + error_code |= EXCP_TLB_NOMATCH; } - /* Raise exception */ - if (!(env->hflags & MIPS_HFLAG_DM)) { - env->CP0_BadVAddr = address; - } + cs->exception_index = (access_type == MMU_DATA_STORE + ? EXCP_TLBS : EXCP_TLBL); + + env->error_code = error_code; + env->CP0_BadVAddr = address; } bool mips_cpu_tlb_fill(CPUState *cs, vaddr address, int size,