From patchwork Sun May 27 14:13:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 137022 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1793085lji; Sun, 27 May 2018 07:26:17 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLSxTFy33OZEPsm77rh5/5DLsw3PkgsdT8IqxpdieIghWAZqTHI4bbPbxHWtM2B/48NnGZT X-Received: by 2002:a0c:bc90:: with SMTP id l16-v6mr8867425qvg.178.1527431177882; Sun, 27 May 2018 07:26:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527431177; cv=none; d=google.com; s=arc-20160816; b=rOSfsdEqjRnz2NVLlTVvGMccJhmvOTwWlVDAUWUgddxFxTiB9HSz6yTuPGzfPwapm8 D67rXOP8w8BXXcXC0HAmIGxelq01h1HollnMPOeVNtCtlY7Ly8ytCurT7f8W1eYo0PI0 h5ct4LLktSDAexcjzW2HJ8kebD+85mxPwVQdFos/qOcn2iy/L6upO7JZ88ctyftS5y4l ipzvsRjImRS30v2jiBSpb7z5MYDRG26aV7dtiQY7amW1FYEsFUky5tw8Cl7uXt/xJP5E UypB4pEpvkZMRH+gHGAw9Ny1aJuHtzpP1jw6U+GB11NYLiLD0X03qS+IwIJ2ixkvljDJ TfMA== 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:arc-authentication-results; bh=+UJZeN1m/QtO2jUaIK6hf846Z5qo9hFYlZMDX00ufaI=; b=Qc7AZuTMcCtM0U5elvQ9ApZtXCu3pKsHyUbXdBRC0nzQQVHCAgHj6ZrcCtX7PZaz2W aT/hNOwXONw4t44GOiz9zFw3Z3YT3OGnmZH8VwsBG2NOnfQkmDuCLq/JG8FWZ7g/tx1b /o69rD/vSuIKBi45wHdkbE8I9d8K7D8WqA6J0jAxMTWd/8GMjnTRlDI9aK+MEbkXUuA7 f5E36gJIWERfrbFvccpdwaLmBdJSiuv9qIFbOyrNSQ3HaM39+7t/XV7jtXYEysx6J9no tpJW2TQZCx65+PKabPS3BrfX87ZFmTbEuqq7fM3bvVoJHgdYSUmX0QCGjaG4siTjwCiw CsAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MiVO6F7Y; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id m30-v6si1209114qtd.17.2018.05.27.07.26.17 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 27 May 2018 07:26:17 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MiVO6F7Y; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:52252 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fMwcj-0000JK-7v for patch@linaro.org; Sun, 27 May 2018 10:26:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57808) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fMwQh-00009s-5o for qemu-devel@nongnu.org; Sun, 27 May 2018 10:13:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fMwQf-0004RA-Ms for qemu-devel@nongnu.org; Sun, 27 May 2018 10:13:51 -0400 Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]:34966) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fMwQf-0004Qs-Dq for qemu-devel@nongnu.org; Sun, 27 May 2018 10:13:49 -0400 Received: by mail-pl0-x243.google.com with SMTP id i5-v6so5739204plt.2 for ; Sun, 27 May 2018 07:13:49 -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=+UJZeN1m/QtO2jUaIK6hf846Z5qo9hFYlZMDX00ufaI=; b=MiVO6F7YcZj/oB0vIRZXdcfSf5Gavgqsueoxz9bdb66s9MDi4TUWPcTFaxzLB7wvR5 8ypebk1bmROL6c1VCn80XqBR4BkeK85PKWyR5v0xB3oKrnOjyrCSJtnG8O3gQ0nA7LYe hJQrWzVDEiR7juvyyMyRBu1t8bT5y8Kr+6p+M= 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=+UJZeN1m/QtO2jUaIK6hf846Z5qo9hFYlZMDX00ufaI=; b=RvR7C01ACLGaMCSCMl74Pd9aOr62hQC61FxbmYg1UH7KlyJth+HqSrcOz9jhFmDRDL tyyHbNhppBApVzVnRuiBb+L9kwDkelb45AqZf4kMTTsTV9bjKuSmmzkOYgQCDuRpSg9u T2VkTUUqro4TnbqGOGIXCp+Up/OEiKUaq20X4NPajHGgeaLK57RFrWnyn1KwQ+wm2beb EDQyBuLgYOu6G6BxfH7cQa4SmI65LcgCTujWHrs+FHiyirl+O7QPzxopN/beCPh2qQpu ljsYBDCUBR6+YbZ28QaQoSvs//J8QFcmrLJTsmGUnfnAycMVxPnncc1FjrB3p5o/uTxE TloQ== X-Gm-Message-State: ALKqPwfuR4T02BGcEcZAVK8gxSA7zGqmV299xCl/XE9fnG4ZC0ZJjCm0 IC/vw+15ZBX8kUVxADuI7XnpNH/n3idszw== X-Received: by 2002:a17:902:9048:: with SMTP id w8-v6mr9974559plz.34.1527430428148; Sun, 27 May 2018 07:13:48 -0700 (PDT) Received: from cloudburst.twiddle.net (50-233-235-3-static.hfc.comcastbusiness.net. [50.233.235.3]) by smtp.gmail.com with ESMTPSA id b89-v6sm66680075pfd.85.2018.05.27.07.13.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 27 May 2018 07:13:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sun, 27 May 2018 09:13:17 -0500 Message-Id: <20180527141324.11937-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180527141324.11937-1-richard.henderson@linaro.org> References: <20180527141324.11937-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::243 Subject: [Qemu-devel] [PATCH 13/20] target/openrisc: Fix cpu_mmu_index 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: Stafford Horne Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The code in cpu_mmu_index does not properly honor SR_DME. This bug has workarounds elsewhere in that we flush the tlb more often than necessary, on the state changes that should be reflected in a change of mmu_index. Fixing this means that we can respect the mmu_index that is given to tlb_flush. Signed-off-by: Richard Henderson --- target/openrisc/cpu.h | 23 +++++++++++++-------- target/openrisc/interrupt.c | 4 ---- target/openrisc/interrupt_helper.c | 15 +++----------- target/openrisc/mmu.c | 33 +++++++++++++++++++++++++++--- target/openrisc/sys_helper.c | 4 ---- target/openrisc/translate.c | 2 +- 6 files changed, 49 insertions(+), 32 deletions(-) -- 2.17.0 diff --git a/target/openrisc/cpu.h b/target/openrisc/cpu.h index 947ca00d8d..c48802ad8f 100644 --- a/target/openrisc/cpu.h +++ b/target/openrisc/cpu.h @@ -384,9 +384,12 @@ void cpu_openrisc_count_stop(OpenRISCCPU *cpu); #include "exec/cpu-all.h" -#define TB_FLAGS_DFLAG 1 -#define TB_FLAGS_R0_0 2 +#define TB_FLAGS_SM SR_SM +#define TB_FLAGS_DME SR_DME +#define TB_FLAGS_IME SR_IME #define TB_FLAGS_OVE SR_OVE +#define TB_FLAGS_DFLAG 2 /* reuse SR_TEE */ +#define TB_FLAGS_R0_0 4 /* reuse SR_IEE */ static inline uint32_t cpu_get_gpr(const CPUOpenRISCState *env, int i) { @@ -404,17 +407,21 @@ static inline void cpu_get_tb_cpu_state(CPUOpenRISCState *env, { *pc = env->pc; *cs_base = 0; - *flags = (env->dflag - | (cpu_get_gpr(env, 0) == 0 ? TB_FLAGS_R0_0 : 0) - | (env->sr & SR_OVE)); + *flags = (env->dflag ? TB_FLAGS_DFLAG : 0) + | (cpu_get_gpr(env, 0) ? 0 : TB_FLAGS_R0_0) + | (env->sr & (SR_SM | SR_DME | SR_IME | SR_OVE)); } static inline int cpu_mmu_index(CPUOpenRISCState *env, bool ifetch) { - if (!(env->sr & SR_IME)) { - return MMU_NOMMU_IDX; + int ret = MMU_NOMMU_IDX; /* mmu is disabled */ + + if (env->sr & (ifetch ? SR_IME : SR_DME)) { + /* The mmu is enabled; test supervisor state. */ + ret = env->sr & SR_SM ? MMU_SUPERVISOR_IDX : MMU_USER_IDX; } - return (env->sr & SR_SM) == 0 ? MMU_USER_IDX : MMU_SUPERVISOR_IDX; + + return ret; } static inline uint32_t cpu_get_sr(const CPUOpenRISCState *env) diff --git a/target/openrisc/interrupt.c b/target/openrisc/interrupt.c index d9cb363fea..e28042856a 100644 --- a/target/openrisc/interrupt.c +++ b/target/openrisc/interrupt.c @@ -50,10 +50,6 @@ void openrisc_cpu_do_interrupt(CPUState *cs) env->eear = env->pc; } - /* For machine-state changed between user-mode and supervisor mode, - we need flush TLB when we enter&exit EXCP. */ - tlb_flush(cs); - env->esr = cpu_get_sr(env); env->sr &= ~SR_DME; env->sr &= ~SR_IME; diff --git a/target/openrisc/interrupt_helper.c b/target/openrisc/interrupt_helper.c index a2e9003969..9c5489f5f7 100644 --- a/target/openrisc/interrupt_helper.c +++ b/target/openrisc/interrupt_helper.c @@ -25,16 +25,7 @@ void HELPER(rfe)(CPUOpenRISCState *env) { - OpenRISCCPU *cpu = openrisc_env_get_cpu(env); -#ifndef CONFIG_USER_ONLY - int need_flush_tlb = (cpu->env.sr & (SR_SM | SR_IME | SR_DME)) ^ - (cpu->env.esr & (SR_SM | SR_IME | SR_DME)); - if (need_flush_tlb) { - CPUState *cs = CPU(cpu); - tlb_flush(cs); - } -#endif - cpu->env.pc = cpu->env.epcr; - cpu->env.lock_addr = -1; - cpu_set_sr(&cpu->env, cpu->env.esr); + env->pc = env->epcr; + env->lock_addr = -1; + cpu_set_sr(env, env->esr); } diff --git a/target/openrisc/mmu.c b/target/openrisc/mmu.c index 23edd8c78c..11b8187cda 100644 --- a/target/openrisc/mmu.c +++ b/target/openrisc/mmu.c @@ -246,9 +246,36 @@ hwaddr openrisc_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) void tlb_fill(CPUState *cs, target_ulong addr, int size, MMUAccessType access_type, int mmu_idx, uintptr_t retaddr) { - int ret = openrisc_cpu_handle_mmu_fault(cs, addr, size, - access_type, mmu_idx); - if (ret) { + OpenRISCCPU *cpu = OPENRISC_CPU(cs); + int ret, prot = 0; + hwaddr physical = 0; + + if (mmu_idx == MMU_NOMMU_IDX) { + ret = get_phys_nommu(&physical, &prot, addr); + } else { + bool super = mmu_idx == MMU_SUPERVISOR_IDX; + if (access_type == MMU_INST_FETCH) { + ret = get_phys_code(cpu, &physical, &prot, addr, 2, super); + } else { + ret = get_phys_data(cpu, &physical, &prot, addr, + access_type == MMU_DATA_STORE, super); + } + } + + if (ret == TLBRET_MATCH) { + tlb_set_page(cs, addr & TARGET_PAGE_MASK, + physical & TARGET_PAGE_MASK, prot, + mmu_idx, TARGET_PAGE_SIZE); + } else if (ret < 0) { + int rw; + if (access_type == MMU_INST_FETCH) { + rw = 2; + } else if (access_type == MMU_DATA_STORE) { + rw = 1; + } else { + rw = 0; + } + cpu_openrisc_raise_mmu_exception(cpu, addr, rw, ret); /* Raise Exception. */ cpu_loop_exit_restore(cs, retaddr); } diff --git a/target/openrisc/sys_helper.c b/target/openrisc/sys_helper.c index e00aaa332e..0a74c9522f 100644 --- a/target/openrisc/sys_helper.c +++ b/target/openrisc/sys_helper.c @@ -56,10 +56,6 @@ void HELPER(mtspr)(CPUOpenRISCState *env, target_ulong spr, target_ulong rb) break; case TO_SPR(0, 17): /* SR */ - if ((env->sr & (SR_IME | SR_DME | SR_SM)) ^ - (rb & (SR_IME | SR_DME | SR_SM))) { - tlb_flush(cs); - } cpu_set_sr(env, rb); break; diff --git a/target/openrisc/translate.c b/target/openrisc/translate.c index b26c473870..59e2df01cf 100644 --- a/target/openrisc/translate.c +++ b/target/openrisc/translate.c @@ -59,7 +59,7 @@ static inline bool is_user(DisasContext *dc) #ifdef CONFIG_USER_ONLY return true; #else - return dc->mem_idx == MMU_USER_IDX; + return !(dc->tb_flags & TB_FLAGS_SM); #endif }