From nobody Mon Feb 9 16:53:51 2026 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1579809278; cv=none; d=zohomail.com; s=zohoarc; b=aaK9FaEusHwpx9XusWBYOhPW+rcBpfw7eVffpXYS0BjdIoV7w6DAaXFaKENrhtmuqmTTsbqEq2GRDrHLIX8bbIdjso9tsxsdvjqIo02D2gxPnfIXjUIQLiqhj1Tdm4d0isBGASY9ME5iMfpt/f4lp2Bb8ZBpfqrG8rvS6gCVyDs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579809278; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject; bh=8t+fDncYfgnFj/SFRiDptoWecMF8tAS/UKt2nRHgxxQ=; b=MwW7EBKUZQvVyfg9Lw8+Cdhhb22kSoL0d/WXqdwtWW3gSdNRb+nF1DbGrODQz7wqGFQx3xTTjgD6qr155Ly15EnSkYFl5hBVSQLGgTD+D2RlYPgd8Dawd4N8V/b/AIh+imYeCeMSfAr1a048xbZ6ptln1saLs6ue2zA8mes52Hc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157980927779650.479603648446414; Thu, 23 Jan 2020 11:54:37 -0800 (PST) Received: from localhost ([::1]:60808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuiYm-0004BX-QD for importer@patchew.org; Thu, 23 Jan 2020 14:54:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39204) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuiXo-0002Tx-HF for qemu-devel@nongnu.org; Thu, 23 Jan 2020 14:53:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iuiXn-0000ph-Gv for qemu-devel@nongnu.org; Thu, 23 Jan 2020 14:53:36 -0500 Received: from rs224.mailgun.us ([209.61.151.224]:18895) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iuiXn-0000lC-Bn for qemu-devel@nongnu.org; Thu, 23 Jan 2020 14:53:35 -0500 Received: from jonathan-ThinkPad-X1-Carbon.pdos.lcs.mit.edu (26-5-211.dynamic.csail.mit.edu [18.26.5.211]) by mxa.mailgun.org with ESMTP id 5e29f9b7.7fca702fc818-smtp-out-n03; Thu, 23 Jan 2020 19:53:27 -0000 (UTC) DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=fintelia.io; q=dns/txt; s=pic; t=1579809209; h=Content-Transfer-Encoding: MIME-Version: Message-Id: Date: Subject: Cc: To: From: Sender; bh=8t+fDncYfgnFj/SFRiDptoWecMF8tAS/UKt2nRHgxxQ=; b=XPCxl8DOP04VubHDUT+Pl5xqKqfVdI02jiyZev/xNzdrEZF189YdyjpHGaX6e158PE+0D0i0 BOT5vJ4rtXT+b5Of6/b5GMT2xXketMQWMCoI8BBS8KZoRMjUiJdTb4eA/9qjBRyANwbvlQTd G6OerZZlXjULEdqTFeQlip83yH3lOPJEu9lWKqkspvP5HIsGo+fS93PW/i16EEZsuAG/QPkn TNTxBNynI0ZeBr1GyouPvuQP/uz48IhMCrLSejaBjvayM1gt1iRLiAf9K4olWqKPHNKgBobY zQBeVaKHyJlm7zZ+oxyeMmkU+fzh40OtA3/P+f6I2lROHQ1RsVd3pw== X-Mailgun-Sending-Ip: 209.61.151.224 X-Mailgun-Sid: WyJlMGM5NSIsICJxZW11LWRldmVsQG5vbmdudS5vcmciLCAiOWI0ZTc2Il0= From: Jonathan Behrens To: Subject: [PATCH] target/riscv: Disallow WFI instruction from U-mode Date: Thu, 23 Jan 2020 14:52:00 -0500 Message-Id: <20200123195200.206355-1-jonathan@fintelia.io> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.61.151.224 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: Palmer Dabbelt , "open list:RISC-V TCG CPUs" , Sagar Karandikar , Jonathan Behrens , Palmer Dabbelt , "open list:All patches CC here" , Alistair Francis , Bastian Koppelmann 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" From the RISC-V Priviliged Specification: "When S-mode is implemented, then executing WFI in U-mode causes an illegal instruction exception, unless it completes within an implementation-specifi= c, bounded time limit. A future revision of this specification might add a fea= ture that allows S-mode to selectively permit WFI in U-mode." Signed-off-by: Jonathan Behrens Reviewed-by: Alistair Francis --- target/riscv/op_helper.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index 331cc36232..2e5a980192 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -129,10 +129,10 @@ target_ulong helper_mret(CPURISCVState *env, target_u= long cpu_pc_deb) void helper_wfi(CPURISCVState *env) { CPUState *cs =3D env_cpu(env); - - if (env->priv =3D=3D PRV_S && - env->priv_ver >=3D PRIV_VERSION_1_10_0 && - get_field(env->mstatus, MSTATUS_TW)) { + if (!(env->priv >=3D PRV_S) || + (env->priv =3D=3D PRV_S && + env->priv_ver >=3D PRIV_VERSION_1_10_0 && + get_field(env->mstatus, MSTATUS_TW))) { riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); } else { cs->halted =3D 1; --=20 2.25.0