From nobody Tue Feb 10 20:51:36 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zohomail.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=1592587149; cv=none; d=zohomail.com; s=zohoarc; b=Fh6XnanDhgLQPO2GNutzLZUPUndjssq2bWkMSp25GcQJO3Pxup2HTp+yQKH/HfS1JA2YGVqPdbkx+5Ol8/y3ZSkxoUUMcgNTJFG6u90X3Iqrmks6Hpca6BLbWQqD62gkrQkpbDe3nnFyQ112DGOVvPTLIxZKCdzjLTPLuHQ04XI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592587149; 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; bh=svr+SKYAM1aMwQSwQAB3OTFRRph4M9LjHDkAJDCQkbY=; b=KELta+6js2lU/vjA5ib2ziEdGXN8qES+eq/6XmBnhn1rIyJR4/0QUfQgIuJICG+imqEgoZZp/NuEEhaIzxSvFdmYL38qnD+zbQl3ciHkDiFfgJV6dLfUY5JuIWyPtfDuO/UikDKpwka46XMEqJ1ZOeGzgJAtfphQ+yxs5/MKb5I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zohomail.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 159258714908596.2564143051419; Fri, 19 Jun 2020 10:19:09 -0700 (PDT) Received: from localhost ([::1]:49950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmKfT-0001pa-Fk for importer@patchew.org; Fri, 19 Jun 2020 13:19:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58286) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmKUL-0000pi-Mp for qemu-devel@nongnu.org; Fri, 19 Jun 2020 13:07:38 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:19125) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmKUG-0004PR-3M for qemu-devel@nongnu.org; Fri, 19 Jun 2020 13:07:37 -0400 Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 20 Jun 2020 01:07:23 +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; 19 Jun 2020 09:56:33 -0700 Received: from unknown (HELO risc6-mainframe.hgst.com) ([10.86.58.142]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Jun 2020 10:07:24 -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=1592586452; x=1624122452; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=melHyBNyq+GBsmbi68L0crjn+k4ZDNG0okkKwoQJd1E=; b=WDJrDptaXabXE60fGKqvHWkSaLIZVwVAF09vb/6YHOf4Vox6xnMsdqh+ 06deDkso/fcM53Y+W3JKiuY0FfRoHTuAhh2sHFyjfn0fW42wgGnOpOTnf aIYeGF+0U3JD03ShxNbbcxRXvOzeCFrXi0GZfr4zXwprVriic7elo4NoN mZPTgwJ+LnU6CCdDvzVJXfxZCZ8rztXD0Ve6saYTNI9DYfJAOg6QeTa1K C4H/Ci1B+PUYUMsJS+n29S3Y05dIA7Mey9+trQVWJH0xk2oPz8tac3BFx uxWQqw4Kg3mfIhHlpNwR8QrEdFyFL4oTk5TbpVAzn5znAkNgzagYPIkOO w==; IronPort-SDR: 2f2e9DrkxKt0TvInIYK+8XLU55FlPFCIZOc6LBxBCnQJ4b7JGuHa7eLBEZjdJsGBZmRnABU/lx pt30hgmTL37pX6q7s+T/8sg3RB1669HaeYmSxyPiX0SzneDKz3C9ICSlYFJsvVl6WZnQ9d60xV 9jFLSuTSjlp0uTdiDVLp43nTcPQiN9puWaHIQHyCJ9++g85tRbUDuEgF3NJ/zAqUEz7r2ZCTeH laSpWvOv8iXCj4+8hXCAcMt7loAZg2O1vvVNQbdqSDGl6OMjsE+QqtwoDTp5scpzHzx1stRxzm as0= X-IronPort-AV: E=Sophos;i="5.75,256,1589212800"; d="scan'208";a="144763327" IronPort-SDR: 6xwowBLhNMZu9tJKEt1fWW8OFsgB067nmoS/k2xZG4Aw5tg0Ywwag3KORIpLbnyot5hUwf8qaK +HpGonOZzaiDx5ze78x+nEE9K8MhaYuAk= IronPort-SDR: tX4WVnppWyeEaM/LdRYn1c9CUUefhDT+KGF6VXtu4JxYNd/6Fe68k+lerR/HdZmM1XNMQ1441N Kgjpd5r4rLPw== WDCIronportException: Internal From: Alistair Francis To: peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL v2 10/32] target/riscv: Implement checks for hfence Date: Fri, 19 Jun 2020 09:57:55 -0700 Message-Id: <20200619165817.4144200-11-alistair.francis@wdc.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619165817.4144200-1-alistair.francis@wdc.com> References: <20200619165817.4144200-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=216.71.153.141; envelope-from=prvs=4324eb4de=alistair.francis@wdc.com; helo=esa3.hgst.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/19 13:07:21 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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, Richard Henderson , Alistair Francis 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" Call the helper_hyp_tlb_flush() function on hfence instructions which will generate an illegal insruction execption if we don't have permission to flush the Hypervisor level TLBs. Signed-off-by: Alistair Francis Reviewed-by: Richard Henderson --- target/riscv/helper.h | 5 ++++ target/riscv/insn_trans/trans_rvh.inc.c | 32 +++++-------------------- target/riscv/op_helper.c | 13 ++++++++++ 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/target/riscv/helper.h b/target/riscv/helper.h index debb22a480..b36be978d5 100644 --- a/target/riscv/helper.h +++ b/target/riscv/helper.h @@ -76,3 +76,8 @@ DEF_HELPER_2(mret, tl, env, tl) DEF_HELPER_1(wfi, void, env) DEF_HELPER_1(tlb_flush, void, env) #endif + +/* Hypervisor functions */ +#ifndef CONFIG_USER_ONLY +DEF_HELPER_1(hyp_tlb_flush, void, env) +#endif diff --git a/target/riscv/insn_trans/trans_rvh.inc.c b/target/riscv/insn_tr= ans/trans_rvh.inc.c index 2c0359819d..263b652d90 100644 --- a/target/riscv/insn_trans/trans_rvh.inc.c +++ b/target/riscv/insn_trans/trans_rvh.inc.c @@ -18,40 +18,20 @@ =20 static bool trans_hfence_gvma(DisasContext *ctx, arg_sfence_vma *a) { + REQUIRE_EXT(ctx, RVH); #ifndef CONFIG_USER_ONLY - if (ctx->priv_ver >=3D PRIV_VERSION_1_10_0 && - has_ext(ctx, RVH)) { - /* Hpervisor extensions exist */ - /* - * if (env->priv =3D=3D PRV_M || - * (env->priv =3D=3D PRV_S && - * !riscv_cpu_virt_enabled(env) && - * get_field(ctx->mstatus_fs, MSTATUS_TVM))) { - */ - gen_helper_tlb_flush(cpu_env); - return true; - /* } */ - } + gen_helper_hyp_tlb_flush(cpu_env); + return true; #endif return false; } =20 static bool trans_hfence_vvma(DisasContext *ctx, arg_sfence_vma *a) { + REQUIRE_EXT(ctx, RVH); #ifndef CONFIG_USER_ONLY - if (ctx->priv_ver >=3D PRIV_VERSION_1_10_0 && - has_ext(ctx, RVH)) { - /* Hpervisor extensions exist */ - /* - * if (env->priv =3D=3D PRV_M || - * (env->priv =3D=3D PRV_S && - * !riscv_cpu_virt_enabled(env) && - * get_field(ctx->mstatus_fs, MSTATUS_TVM))) { - */ - gen_helper_tlb_flush(cpu_env); - return true; - /* } */ - } + gen_helper_hyp_tlb_flush(cpu_env); + return true; #endif return false; } diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index b0c49efc4a..7cccd42a1e 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -194,4 +194,17 @@ void helper_tlb_flush(CPURISCVState *env) } } =20 +void helper_hyp_tlb_flush(CPURISCVState *env) +{ + CPUState *cs =3D env_cpu(env); + + if (env->priv =3D=3D PRV_M || + (env->priv =3D=3D PRV_S && !riscv_cpu_virt_enabled(env))) { + tlb_flush(cs); + return; + } + + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); +} + #endif /* !CONFIG_USER_ONLY */ --=20 2.27.0