From patchwork Fri May 10 18:54:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163943 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2755410ilr; Fri, 10 May 2019 12:00:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqxPIL0UjrDLOndGSJ0VNLhSLBWb0E0ddWMfxUUAcf1e1CVn6qrUgMkOT762y5M7YimEieft X-Received: by 2002:a17:906:7056:: with SMTP id r22mr5218633ejj.275.1557514806325; Fri, 10 May 2019 12:00:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557514806; cv=none; d=google.com; s=arc-20160816; b=SwFrfqB61dt3aS550V/qLdYawQ53B6QEeApJVdVNFmr/3gtvPdewYVxb4F99t3se5E 1wMK4Qd4IQjBe1FkwDyAWpRE4i5IvsqkDQoLewWWkV2d3Q+5JAh8fWdRF+Ub42Bykurk kzamGeWOT///e8vhq0sVcbG8auItyz4kUns5DBc4dm3kUx8gJfYD4V4k9hQS4oVt0j81 KiHTBP6INaRxzH2T86STqRKi7xA4wgMsEOMUvoql+wgcV6cnHu+Nm280GwRYkxKj6v18 sVGjdpPWvfpJ4cTJSvaKtED8k/uK5s+kPm0Xqbh5IstrsPoVeTqqP6U9/c6x8g3CckRU V9Rg== 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=2nv1Fz6coVTYizv8OMxkCDga0OEiAnrikMT8xHCBMUM=; b=WUdG97QI6EagKv4/TPsT5Xws6v2ch1OQhWuYqsgnNqzTmJrau6Hi4uohFTIQPbbZIo 1fr2Izh/OUSSuFaEy+fuDK9B2Rcy9v+5q2p0NkwkiOFckL7dmBhD1bbE07cSugKxsqzG lsTeAvvy0e1eEoGh2M2u3IWUilYvqBk0nUsTBASeBMbYS5lz4yXhR75iVUHW3uRH9kag 0MwKkI2VyUQA12oHj3dxvsU8MgkutPYOEw+NrBAZQGXLvAPDVx28EhpWPF6rCYm3FND/ 6jr1YLVirEvPajhp6BD2Tcfq5Ex95QLJ/HA6V6gsRTU0GCJ7otdawwulzt9bcC/u1g6W bXmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XgBIQLVJ; 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 i12si782627edk.333.2019.05.10.12.00.06 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 12:00:06 -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=XgBIQLVJ; 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]:48564 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hPAkX-0004FQ-72 for patch@linaro.org; Fri, 10 May 2019 15:00:05 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48655) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hPAfb-0007xI-DM for qemu-devel@nongnu.org; Fri, 10 May 2019 14:55:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hPAfR-0005ut-FY for qemu-devel@nongnu.org; Fri, 10 May 2019 14:54:58 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:35381) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hPAfR-0005sM-3W for qemu-devel@nongnu.org; Fri, 10 May 2019 14:54:49 -0400 Received: by mail-pf1-x441.google.com with SMTP id t87so3703326pfa.2 for ; Fri, 10 May 2019 11:54:48 -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=2nv1Fz6coVTYizv8OMxkCDga0OEiAnrikMT8xHCBMUM=; b=XgBIQLVJzunHW2aEjGIPsFY0aDf7tUEK+y/juLg1z7y3bxWJonO47Y3iA2Mqz0roev IoLEp3BQ5hfdE0BNswP1g+XKkzwIffhlo2oXcxmxc8xCfVoIFZhNR1LDyLC5ztXAV1GL ssi59GoxXntsSiPclIP9rGcBblfo55S4rkk9VuDM0GXwuq5VFqSq5fEbAZizCzN5XcZs pFku/IYqEF2HIhcwJL8yc1X8+jQt99yNxMAPSRDtUGVL7SbD5MC6/wCsyk0t7s/P2cic 9K7kuw372YZcVu9kxrusBmYxrjpQHgVNO1EGUOLZCuOf8oilR3gjvmbQQwuhta8bBJ5m w/4A== 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=2nv1Fz6coVTYizv8OMxkCDga0OEiAnrikMT8xHCBMUM=; b=LaIOeGqOlQO+8n+y3IELOeG53ueqHV9Xacc7JxNuoe24Ar2e1N3vRxlo66T0YmaNk7 d582OS4o9GYZw4n2npaoB3O6J5DZPQirg+Mw4gP66xxwKt8KNZ8wOwA6sNrT3YYm1kR+ PwC8BglX79G8SX3sSz78kgXZ3+IHsbqDbCwm+QWeva6fpBbiJNCXl5c5mITCL2SiEJyi phV6bOOt3M0jD4LP+K4On59DlLr7Rr9FcW3d3PVZm2GCDAnfPgDtTnKFp9J0OUajFwVn u+jyPj6oYiw6GSA4MRXBzG6851dJQRZqbbspA7vlp+mgA4elXpbO/rygHvShs7X0qHsx b2UQ== X-Gm-Message-State: APjAAAXaGByph7vbiZvce4qVpC+Ropu5o3OQFFvWT+3SlGIejhwNRlob qOT8EkExAVJvqv4G0DzLXbdNUzcJ4Yg= X-Received: by 2002:aa7:9afc:: with SMTP id y28mr16719834pfp.101.1557514487752; Fri, 10 May 2019 11:54:47 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id q20sm12733146pfi.166.2019.05.10.11.54.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 11:54:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 11:54:36 -0700 Message-Id: <20190510185438.29533-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510185438.29533-1-richard.henderson@linaro.org> References: <20190510185438.29533-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::441 Subject: [Qemu-devel] [PULL v2 17/27] 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: peter.maydell@linaro.org, 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 Reviewed-by: 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 diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 7d9f48973f..c17184f4e4 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(void); diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 1bcf4eaeb8..b7675707e0 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -355,14 +355,13 @@ 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 +#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 #ifdef CONFIG_TCG cc->tcg_initialize = riscv_translate_init; + cc->tlb_fill = riscv_cpu_tlb_fill; #endif /* For now, mark unmigratable: */ cc->vmsd = &vmstate_riscv_cpu; 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; } /*