From patchwork Thu May 9 22:26:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163777 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1577123ilr; Thu, 9 May 2019 15:39:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqwohoOy2y7cDy+HvCKtOw69DIpJqLoAFzg1rZ6fSNrFPgEdyiDDqfwGh6EGPAh1MG12abPF X-Received: by 2002:a7b:c5c4:: with SMTP id n4mr4646205wmk.151.1557441585188; Thu, 09 May 2019 15:39:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557441585; cv=none; d=google.com; s=arc-20160816; b=y1Njyny6EapLNgbQG9QQaQXIqXhPxAKJqaYIuMv5mYtDqUxXE+PZXSkfO+MsUeR3II VU6LtSikWH7vwN+tUsQPe1Ezxm+bpzVhkCfbuGrWl0IzNI6l/w51FwYE+kqnOzZ51oOQ /JqEsiS/aDWkbPu63wM/9CIiY0rGhGuLjAvCnlxGEz9bCl3bh+Fb7gIpkL8UReUMDT13 /vmj+OcFu6F2rertE2gcKv5Qbl3foW7gPZFx6Icl6nXEWhz5nMtqx360jCjVuPMMHEfT pYdioUCO6YAni7LLj9YbKur1aoxFNTtT0YYxdtwJ3hPahFvT6+gQrBgBJZ6MNCbgcD+b 5OCw== 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=jFiOLbzDz1sji7rdhiIl1UIG07vaIVhoy6dgsMAsHtw=; b=a8a5qlSk0y5T+BOwghjwCK92Erap98u2O/7+R8wCjykM4ADrqyG2IwP0uT0OViEr+R Xl2aPXgr5Z1sdWFQT5oIvz5hFYyzeIYeC8pe8CXiwfdE1ihcyIVZd1I/3PHSHMbmMceL WgYPQYFKEazRFNYm/zUykY6iE1AxKhhl+D18tyvB+5UHLu5T51qOfzqzX8a0L5fjJF7l CXMyihVOp3rYtqzoRBVrj5Ltii1r3QAy2ufOzuCbY8Jf1LFsvOWt+ntRQu3EBiNvHYMj giJtanq/FxDHFFOzNg5zfaF7mDQK/dE9jiDaECC5bu3JHCnsfhlE61u4nqLthXLi70dd v9yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="aV3a8BO/"; 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 h18si2571266wrm.60.2019.05.09.15.39.44 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 15:39:45 -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="aV3a8BO/"; 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]:33603 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOrhY-0002Js-0D for patch@linaro.org; Thu, 09 May 2019 18:39:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33095) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOrVC-0007pw-IL for qemu-devel@nongnu.org; Thu, 09 May 2019 18:26:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOrVB-0005Yy-7b for qemu-devel@nongnu.org; Thu, 09 May 2019 18:26:58 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:45493) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOrVA-0005Y3-WB for qemu-devel@nongnu.org; Thu, 09 May 2019 18:26:57 -0400 Received: by mail-pl1-x643.google.com with SMTP id a5so1796313pls.12 for ; Thu, 09 May 2019 15:26:56 -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=jFiOLbzDz1sji7rdhiIl1UIG07vaIVhoy6dgsMAsHtw=; b=aV3a8BO/vH4AIMaRdqrMLk1KK2MOingD2OeAuNiWNFHsiWnleab5viMP3EWhF39+hv FaPIkwdhPAcsdmAlDn32Fz/ZERWUx0YZdRRDHvipca806xlynz/qmF/5QqS+IXjJOe5m QjqcPZA2Fldc1cP7H5iMHG84RGZeMSKHTgIOQ6KXXCcVROdQllrKGQUm9ZoMp/YEaz5w Gb7F6G0OSp9KRTGXdLL5B0OE8UgJcU8GNvKi+L+FL/K4b1lvS8KicS6X17pyMaPHvZI9 VwL9j1/CKFi80H7p+41SwU1v08WRU81YqSFme27v+SCT/FtepvY+2tqK8rihQ0IdWXjE i7OQ== 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=jFiOLbzDz1sji7rdhiIl1UIG07vaIVhoy6dgsMAsHtw=; b=jGSONJfg2l9ECsOk+XbKxwXawz5F5PbtPoRJv3hBqaKXSIQjcCaEbPAlb5JhRZBms3 tX6K+fLL0U4O6JOcSMnOHt3MgBa5GAgsTmxqEsxzWhEchhrJNsOQUF+ysQMSceL+b9BC HsBwZcD1086eOEftA1YM+FKp2LbgBe75xVs4O4+FVOFewqt9VahoBSWnZ6anHK4cpWvk 0CXA2zl1UMMXpVaBRD36JvSxZzmF8YDwF9m2dxNqQUSl+4RPkSFEEho+jgxc1m2Tnxs6 vSP6COBXNbkJEvOX2nRudnhCMU8cLdhxtURnJn2kBAUx0Zxi/09ZIAnKKpI5so+eZcFb 7GcA== X-Gm-Message-State: APjAAAXCwUGGjE9R+CwkfhdIjnVwBQFVXQLHjx3/DZBNpB6razZjfllA wvTJBL+IW2Hf+mRn0YjMVkcYxUvu8uQ= X-Received: by 2002:a17:902:f24:: with SMTP id 33mr8499442ply.33.1557440815722; Thu, 09 May 2019 15:26:55 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id m2sm4490521pfi.24.2019.05.09.15.26.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 15:26:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 15:26:21 -0700 Message-Id: <20190509222631.14271-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190509222631.14271-1-richard.henderson@linaro.org> References: <20190509222631.14271-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::643 Subject: [Qemu-devel] [PATCH v3 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: 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..34a54ef2ed 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; } /*