From nobody Tue Feb 10 02:45:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1566605002; cv=none; d=zoho.com; s=zohoarc; b=S6Gz03xtm2umMUryfQQkpodwUmrVuMZNzpBoDGX1uFknOMXvsFdMZRksRBKu+BL9JYdYTrE1ZZx6KlXqFWRbkdS+uPEs8mK0H3CvYKTq5KEKTc6RLLPHOi0GWSgbgXoREd6fGWfK+sw6BCBezyZy47HkhMOBoxkbZhIpacQyq2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566605002; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=w8DI/005NKc39jIu/V/otyjjhYWoPwqYcFjH9T3/2EM=; b=YUfRUUx44gwmUlVUqk38mF+NjiHdrQCehCkjLqtW9JMZbsbocFUW+nI4rAch5pkQyJeczjGKLaj6eCtTwoLzHyTguZ7XT6kYnX4WA8q65A9mszbBJi6kj7D/jaVwXUJwFgRMy+8+8Kj4AeluEiKSBaHvCKD2PcR5KxRt//mwu6g= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail header.i=@wdc.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566605002858668.3459686410205; Fri, 23 Aug 2019 17:03:22 -0700 (PDT) Received: from localhost ([::1]:35250 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1JWb-0004ms-FD for importer@patchew.org; Fri, 23 Aug 2019 20:03:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49860) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1JCP-0001BP-VJ for qemu-devel@nongnu.org; Fri, 23 Aug 2019 19:42:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1JCO-0000KR-O3 for qemu-devel@nongnu.org; Fri, 23 Aug 2019 19:42:29 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:38476) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i1JCO-0000Il-DH; Fri, 23 Aug 2019 19:42:28 -0400 Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 24 Aug 2019 07:42:29 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2019 16:39:45 -0700 Received: from risc6-mainframe.sdcorp.global.sandisk.com (HELO risc6-mainframe.int.fusionio.com) ([10.196.157.58]) by uls-op-cesaip02.wdc.com with ESMTP; 23 Aug 2019 16:42:27 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1566603749; x=1598139749; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2K2heKwYI3ZlRTWb1vXPZVntWORWGCN1A7mMqHQXzJ8=; b=NcO9BieRwZcYOfNcuxPdbMfDDdLsZ7qCKLOOj1MimjYo/2yhxJ3zGbPf S6dqHDOOdPQjbqha64dKQ9nTj4QvDx/XODKCEz694M8pWYgOZ8zmdBhKm JeHgh4Tn6Y2rclJ+rIGkImqJJL92gYHkj6iVyo3iWsuf65glEcXpvfgTw r1V5lMP7p8Tb12GW+wXAZR0FN+R1FlcRnCfi6FiV3LXUk/2futsAg0f4m nbOgakcQLv+0DQLrH0HcuQuSdHyhDh/cSG+VeKartbQQ9+DDSTPNtX6GV 24KOmsURprUVf+P0YdaL4OptBtEvHIgkCLy9TZwrUmSPMZJ35ivL0aZUG g==; IronPort-SDR: GJq8Tcu0MFA2en6CJsBOlGv6c9mbWhewOoAh3cVUVqKwtO17+FFYKSm13vCZIwIZXCP0jQHnPJ tM3rGITwScYmiOotQ9FONXg46GMdS+LQpjNMQ4ywuXAeWkckjx41OieQoaYN92/kHr3zynljxl wMXAa1436Gnu5biorABUmK2UpQQluNzIn52DqaWhi9TIXHUTK8Dxm+IqwTz0j/gOTnjgCrzpu5 eHNmjffZwSVbl0afHD+cfwzdeoj6eu5SfgBkkl60eY2asYPS9it5jOQDxff8WNAKc5zVzl96yb nPc= X-IronPort-AV: E=Sophos;i="5.64,422,1559491200"; d="scan'208";a="117486911" IronPort-SDR: 3UPduKeBdVtNLkqRMurCni0PZnHOyAL2UHY4Tn+zBbEQLw4dg/G5LhPtDrtcLrvT9w6YQ0/I1K pbP7DmvHhaAexQtRiHxRF/ib4G9OZnygym+4+LnQK7KTHngYATb+Oa7yVRSbpNo0x//FmrzoB7 u/ZoekblXL6oNDQgxa2D5+C5NpqYP0CqqErAF3Uy53s6UlORJ95OuhUugSbCMRlN56RYuwQR10 C0fZvPZZXLKf7APEZuxIkUrse0JbCYGX8NuvBkks9lPtamw6tqdGubFUawUWNMPsGfCAgR7vgH fbzdhZECIAlB8/x+3HdXWyQm IronPort-SDR: GLUIVrpebuDeLf9BzATPTNFU10RmE4mzgmE0bTFP2F345YOrNbKs3XZmhhB02hq0MnPUPZtxyY CsqI2AIUk6NnUOMiJx72AgWrBOox1ghMLpkd+cqmWTX9n7jX+yYynGonlnUe/lV5MXlotbQ27d 3q6lAi+TOboke54+nMT3iQUuOsGH9TcZDB+5rmmPY2d+0Mcq8yDDtaP36nD9ykqQiscFnoERo3 rBD7ZJidSm4R7RM5doaQw77vwKyQm8Bcw77JKmndn70wxM03KNoq1CCxqQWPgZfSkcFNT7GAMt yj4= WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Date: Fri, 23 Aug 2019 16:38:47 -0700 Message-Id: <4d84c887def558fc178c31e3adc52f1c4b2fb075.1566603412.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x X-Received-From: 216.71.153.144 Subject: [Qemu-devel] [PATCH v1 22/28] target/riscv: Allow specifying MMU stage 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: alistair23@gmail.com, Anup.Patel@wdc.com, palmer@sifive.com, alistair.francis@wdc.com, Atish.Patra@wdc.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Alistair Francis --- target/riscv/cpu_helper.c | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 098873c83e..9aa6906acd 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -318,10 +318,19 @@ void riscv_cpu_set_mode(CPURISCVState *env, target_ul= ong newpriv) * * Adapted from Spike's mmu_t::translate and mmu_t::walk * + * @env: CPURISCVState + * @physical: This will be set to the calculated physical address + * @prot: The returned protection attributes + * @addr: The virtual address to be translated + * @access_type: The type of MMU access + * @mmu_idx: Indicates current privilege level + * @first_stage: Are we in first stage translation? + * Second stage is used for hypervisor guest translation */ static int get_physical_address(CPURISCVState *env, hwaddr *physical, int *prot, target_ulong addr, - int access_type, int mmu_idx) + int access_type, int mmu_idx, + bool first_stage) { /* NOTE: the env->pc value visible here will not be * correct, but the value visible to the exception handler @@ -518,13 +527,23 @@ restart: } =20 static void raise_mmu_exception(CPURISCVState *env, target_ulong address, - MMUAccessType access_type, bool pmp_violat= ion) + MMUAccessType access_type, bool pmp_violat= ion, + bool first_stage) { CPUState *cs =3D env_cpu(env); - int page_fault_exceptions =3D - (env->priv_ver >=3D PRIV_VERSION_1_10_0) && - get_field(env->satp, SATP_MODE) !=3D VM_1_10_MBARE && - !pmp_violation; + int page_fault_exceptions; + if (first_stage) { + page_fault_exceptions =3D + (env->priv_ver >=3D PRIV_VERSION_1_10_0) && + get_field(env->satp, SATP_MODE) !=3D VM_1_10_MBARE && + !pmp_violation; + riscv_cpu_set_force_hs_excep(env, CLEAR_HS_EXCEP); + } else { + page_fault_exceptions =3D + get_field(env->hgatp, HGATP_MODE) !=3D VM_1_10_MBARE && + !pmp_violation; + riscv_cpu_set_force_hs_excep(env, FORCE_HS_EXCEP); + } switch (access_type) { case MMU_INST_FETCH: cs->exception_index =3D page_fault_exceptions ? @@ -551,7 +570,8 @@ hwaddr riscv_cpu_get_phys_page_debug(CPUState *cs, vadd= r addr) int prot; int mmu_idx =3D cpu_mmu_index(&cpu->env, false); =20 - if (get_physical_address(&cpu->env, &phys_addr, &prot, addr, 0, mmu_id= x)) { + if (get_physical_address(&cpu->env, &phys_addr, &prot, addr, 0, mmu_id= x, + true)) { return -1; } return phys_addr; @@ -613,7 +633,8 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, in= t size, qemu_log_mask(CPU_LOG_MMU, "%s ad %" VADDR_PRIx " rw %d mmu_idx %d\n", __func__, address, access_type, mmu_idx); =20 - ret =3D get_physical_address(env, &pa, &prot, address, access_type, mm= u_idx); + ret =3D get_physical_address(env, &pa, &prot, address, access_type, mm= u_idx, + true); =20 if (mode =3D=3D PRV_M && access_type !=3D MMU_INST_FETCH) { if (get_field(*env->mstatus, MSTATUS_MPRV)) { @@ -640,7 +661,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, in= t size, } else if (probe) { return false; } else { - raise_mmu_exception(env, address, access_type, pmp_violation); + raise_mmu_exception(env, address, access_type, pmp_violation, true= ); riscv_raise_exception(env, cs->exception_index, retaddr); } #else --=20 2.22.0