From patchwork Wed Apr 3 03:43:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 161665 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp2518761jan; Tue, 2 Apr 2019 20:57:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2j/KgyRsXDeBZOPUCuf5OuMWXk3Xb6vm4JLtHDpMKx5CZz8Ip5d36afyS0liFl4dv2SRq X-Received: by 2002:a0d:e613:: with SMTP id p19mr57824135ywe.96.1554263868048; Tue, 02 Apr 2019 20:57:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554263868; cv=none; d=google.com; s=arc-20160816; b=KFJfbN76V0HLQOXpWoW9bqgxQbNs73fyVyr7vvUiqp4K5EI85rbG5NNShOfZSPeA4T K2AhIc3DfPYmooFXJwDo03u1mdnMbBdCcf9En8dynnKbRilo+e7+MJVdHnslkj/iE8Xb BVd328H51JH6O3/7e4hlTLFggGHrjwHCXdTc3g+zs1Jch7ijdA9LH/aQIpX/jKPhnF9S 36Hcx83mOcElYJhYnryHR6sASwkKMZVlabrmukmyVYcvn5ALNhX8Lh72XB3lE8f5rwK0 k/rC4NYMhyfw0Cgbfib5yywfije8OYMshoA+kqFfo0uha9pEbNlLweJAIATczpHPHrM7 axOw== 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:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=w70bbHQzT+7HnMGIXg0cJi7OJv7Pp3pD0PUOZFKz1Ws=; b=Ao7iyE5ZhkuLKQeLbiQeZskK00b3QACYeHbETO8KK9zPDK+1mTbWQltjcfFahlSDyi EUWjLujTVSpwnzzAIZXDVFWJJ4eP5JvJLt7+FYVTeLPWA+xrS+EXYVX/dr9yWzSCsZPr QUoTkTMfgr6YEe/ozqotLy1C0bLBy4Fp3GOjdTkxSDVn4ypmEcz9KaVKgrsNZLf7RFp6 Gx+HcVufxtWW2+VG6ex4vjptQBtdLfnikg3qEp4a6gJHrOSihiBFOTx+dTznEIvriyeJ rZ0ZNVaEiuVvySDVXMQneCm8w3k0kTH41JK6Bge6NvgTfSfM7GyYnbltnZ+4gBPgjd1B 0WGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="PS/U3kRJ"; 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 p133si9633055ywe.91.2019.04.02.20.57.47 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 02 Apr 2019 20:57:48 -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="PS/U3kRJ"; 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 ([127.0.0.1]:54500 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hBX23-0005p3-GO for patch@linaro.org; Tue, 02 Apr 2019 23:57:47 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48725) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hBWpJ-00031q-NX for qemu-devel@nongnu.org; Tue, 02 Apr 2019 23:44:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hBWpI-00005X-Cn for qemu-devel@nongnu.org; Tue, 02 Apr 2019 23:44:37 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:39396) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hBWpI-0008WA-59 for qemu-devel@nongnu.org; Tue, 02 Apr 2019 23:44:36 -0400 Received: by mail-pl1-x641.google.com with SMTP id b65so7312868plb.6 for ; Tue, 02 Apr 2019 20:44:36 -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; bh=w70bbHQzT+7HnMGIXg0cJi7OJv7Pp3pD0PUOZFKz1Ws=; b=PS/U3kRJhxCe0D+7YI+igq8A3154U98cOMEoZvMYPzxzIdP+/pGLRN0s1zkjjfwKYH dOSd5yLy4g+PsyYxVzORFINDLOzJCKRLLzQASxjk/DiHzEeyEIh+5TKrHtU2jyo1OZVO 4/VDDVEbduYTj70uabkOkcXlRwXwds/9nL76Q86dXqi5mxtgpE+4qYgE5niiCScQogQd rsuKS8ovoIgwMB+XVvhXXD/s8lU0cpTI+K4gWI7/hzVOfUIrzIKJ5JCVf9wS9HDWVD6i XBfe65cN7yCjMCnc8Chq85zlFx703UG6vk1EJp7fFsB71tFC6plLBReTGqFRnqqBvG1U BgAA== 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; bh=w70bbHQzT+7HnMGIXg0cJi7OJv7Pp3pD0PUOZFKz1Ws=; b=Tlsv/PANuLniZ4VuYaXekOUbthQM2luCai3H6+rykNPBuzuTRiNGjJqqBSUWHHy3MZ I2HAkmPi7+1PhjP+isOqIbTW5gv2zMd5LaE3KJQa+FTXkXwhAJDpUEc7eHg8cNMzxgT1 9Qc1OljIYjMS1OwW3GmACiAq6+WDiM50vkudKXMDRpFOKxsHZ8VyhXRQ8vBkBR5Sp5aJ vX3hPa7x//mnlyjlLd9/TlXOtbv2zimNk74LhK4WcrV8eqFJ68glkYAxM8m6mGE2GCqn GZJMsr1Lqi2aLCkfh7Jrvf5IcyDYe6l7CcVRLuYgPH9ZVg0Q5f9njWaKAwTUajnlAPOp b4wA== X-Gm-Message-State: APjAAAWSWQE7/ujnJlPVIFK9wIxDMrkdVa1grwP8F++3VMm8EJJyoSx9 7Lu3vwtlzoWU6GJG2DyKBI84V/EY6zlsJA== X-Received: by 2002:a17:902:2bab:: with SMTP id l40mr74192068plb.273.1554263074966; Tue, 02 Apr 2019 20:44:34 -0700 (PDT) Received: from cloudburst.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id z6sm26753214pgo.31.2019.04.02.20.44.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 20:44:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 3 Apr 2019 10:43:48 +0700 Message-Id: <20190403034358.21999-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190403034358.21999-1-richard.henderson@linaro.org> References: <20190403034358.21999-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::641 Subject: [Qemu-devel] [PATCH 16/26] target/riscv: Convert to CPUClass::tlb_fill X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alistair Francis , Palmer Dabbelt , qemu-riscv@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Note that env->pc is removed from the qemu_log as that value is garbage. The PC isn't recovered until cpu_restore_state, called from cpu_loop_exit_restore, called from riscv_raise_exception. Cc: qemu-riscv@nongnu.org Cc: Palmer Dabbelt Cc: Alistair Francis Signed-off-by: Richard Henderson --- target/riscv/cpu.h | 5 +++-- target/riscv/cpu.c | 5 ++--- target/riscv/cpu_helper.c | 46 ++++++++++++++++++--------------------- 3 files changed, 26 insertions(+), 30 deletions(-) -- 2.17.1 Reviewed-by: Alistair Francis diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 20bce8742e..40c1254408 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -261,8 +261,9 @@ hwaddr riscv_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr, MMUAccessType access_type, int mmu_idx, uintptr_t retaddr); -int riscv_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int size, - int rw, int mmu_idx); +bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, + MMUAccessType access_type, int mmu_idx, + bool probe, uintptr_t retaddr); char *riscv_isa_string(RISCVCPU *cpu); void riscv_cpu_list(FILE *f, fprintf_function cpu_fprintf); diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index d61bce6d55..e9f569c665 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -355,9 +355,8 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) #endif cc->gdb_stop_before_watchpoint = true; cc->disas_set_info = riscv_cpu_disas_set_info; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = riscv_cpu_handle_mmu_fault; -#else + cc->tlb_fill = riscv_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->do_unaligned_access = riscv_cpu_do_unaligned_access; cc->get_phys_page_debug = riscv_cpu_get_phys_page_debug; #endif diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index b17f169681..2535435260 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -379,53 +379,49 @@ void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr, riscv_raise_exception(env, cs->exception_index, retaddr); } -/* called by qemu's softmmu to fill the qemu tlb */ void tlb_fill(CPUState *cs, target_ulong addr, int size, MMUAccessType access_type, int mmu_idx, uintptr_t retaddr) { - int ret; - ret = riscv_cpu_handle_mmu_fault(cs, addr, size, access_type, mmu_idx); - if (ret == TRANSLATE_FAIL) { - RISCVCPU *cpu = RISCV_CPU(cs); - CPURISCVState *env = &cpu->env; - riscv_raise_exception(env, cs->exception_index, retaddr); - } + riscv_cpu_tlb_fill(cs, addr, size, access_type, mmu_idx, false, retaddr); } - #endif -int riscv_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, - int rw, int mmu_idx) +bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, + MMUAccessType access_type, int mmu_idx, + bool probe, uintptr_t retaddr) { +#ifndef CONFIG_USER_ONLY RISCVCPU *cpu = RISCV_CPU(cs); CPURISCVState *env = &cpu->env; -#if !defined(CONFIG_USER_ONLY) hwaddr pa = 0; int prot; -#endif int ret = TRANSLATE_FAIL; - qemu_log_mask(CPU_LOG_MMU, - "%s pc " TARGET_FMT_lx " ad %" VADDR_PRIx " rw %d mmu_idx \ - %d\n", __func__, env->pc, address, rw, mmu_idx); + qemu_log_mask(CPU_LOG_MMU, "%s ad %" VADDR_PRIx " rw %d mmu_idx %d\n", + __func__, address, access_type, mmu_idx); + + ret = get_physical_address(env, &pa, &prot, address, access_type, mmu_idx); -#if !defined(CONFIG_USER_ONLY) - ret = get_physical_address(env, &pa, &prot, address, rw, mmu_idx); qemu_log_mask(CPU_LOG_MMU, - "%s address=%" VADDR_PRIx " ret %d physical " TARGET_FMT_plx - " prot %d\n", __func__, address, ret, pa, prot); + "%s address=%" VADDR_PRIx " ret %d physical " TARGET_FMT_plx + " prot %d\n", __func__, address, ret, pa, prot); + if (riscv_feature(env, RISCV_FEATURE_PMP) && - !pmp_hart_has_privs(env, pa, TARGET_PAGE_SIZE, 1 << rw)) { + !pmp_hart_has_privs(env, pa, TARGET_PAGE_SIZE, 1 << access_type)) { ret = TRANSLATE_FAIL; } if (ret == TRANSLATE_SUCCESS) { tlb_set_page(cs, address & TARGET_PAGE_MASK, pa & TARGET_PAGE_MASK, prot, mmu_idx, TARGET_PAGE_SIZE); - } else if (ret == TRANSLATE_FAIL) { - raise_mmu_exception(env, address, rw); + return true; + } else if (probe) { + return false; + } else { + raise_mmu_exception(env, address, access_type); + riscv_raise_exception(env, cs->exception_index, retaddr); } #else - switch (rw) { + switch (access_type) { case MMU_INST_FETCH: cs->exception_index = RISCV_EXCP_INST_PAGE_FAULT; break; @@ -436,8 +432,8 @@ int riscv_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, cs->exception_index = RISCV_EXCP_STORE_PAGE_FAULT; break; } + cpu_loop_exit_restore(cs, retaddr); #endif - return ret; } /*