From nobody Mon Sep 28 01:15:14 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=proton.me ARC-Seal: i=1; a=rsa-sha256; t=1786159203; cv=none; d=zohomail.com; s=zohoarc; b=RIv2xPaV8CrkQJdk6JI8jiiM3F1cNoOzemzgWzLKQukO5CjYbz0p07MGjpGJDF/x5RH9xtJyJSEkIwYD3H/XyqeaHYkJKITGdsYKJhrAw/ZU6fWp+ae5lof00gH0l7liqBLsqiQpspF95Wo8KEoLnFnXimwN2Lum3Ex7F9z4Mjw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786159203; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=mh0FEJqUhB0Yyu+ZUdTjjWJkbEYz7wuDd+G8Ynm31rs=; b=Sxq/KDHnoUf14CkKSUZNv746o2zHlAHCvQU5Xz8aZjcHycoa8bwuoRVygtNTHuJTT7/Fi6tSfHmV3ceg7yPnKFUHYQNQ6GQR7ePodud8R/dPWeiB/tzCX7KJDutqQ67eyxUTZEnsef0tUd3mqzo5XuPuAO7HNRWiw3AgyMChfj0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1786159203191457.5553823207763; Fri, 7 Aug 2026 20:20:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wsXaa-0006O1-TU; Fri, 07 Aug 2026 23:19:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wsXaY-0006NU-HZ for qemu-devel@nongnu.org; Fri, 07 Aug 2026 23:19:11 -0400 Received: from mail-08.mail-europe.com ([57.129.93.249]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wsXaW-00061O-U3 for qemu-devel@nongnu.org; Fri, 07 Aug 2026 23:19:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1786159135; x=1786418335; bh=mh0FEJqUhB0Yyu+ZUdTjjWJkbEYz7wuDd+G8Ynm31rs=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=MwiRb8o46f2Ymj9l7ZCqhp6yLwH8SmCfhHFZZyB2nOFdT8DPDJdb7p6q293vLGK7R 4b69I3I803geaOwU3kChh66DsfZZ9k1+zQi7Mc0QmlFzIQTw1LgqQeIHAIjtLZ5Xm7 f7C4JBoEz8SU4ENHtyi81AqfPYF8Tn2Hvb0959CxGbfP676JdLbBQgl0TvAkCsE0ed oL8Ev8ZJ25elTG7CdZd1tETdNqYntqJWq2ceBfeCDO1hRtBS3zi5dqxNQZbI7BS+SH YFd1okreF0keckIomNp09Y/6L5KPSajqtU8VxMivLeADqVB3bptVFiGbajzJJjD6jI E9zAi0EuNiUKw== Date: Sat, 08 Aug 2026 03:18:54 +0000 To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org, Palmer Dabbelt , Alistair Francis From: "Christian S. Lima" Subject: [PATCH] target/riscv/tcg: sret in virtual user mode raises virtual instruction exception Message-ID: <20260808031849.59726-1-christianslima@proton.me> Feedback-ID: 169431447:user:proton X-Pm-Message-ID: 359855980948a443100c992382e2d1edafb5efdf 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=lists1p.gnu.org; Received-SPF: pass client-ip=57.129.93.249; envelope-from=christianslima@proton.me; helo=mail-08.mail-europe.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @proton.me) X-ZM-MESSAGEID: 1786159207528158500 Content-Type: text/plain; charset="utf-8" Currently, when a `sret` is executed in virtual user mode, qemu raise an `illegal instruction exception`, but in this case the correct behavior is to raise a `virtual instruction exception` and the code already contains a check to it, but it's not enough to catch. This patch is useful to improve the correctness of the virtualization of the risc v architecture. Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3622 Signed-off-by: Christian S. Lima Reviewed-by: Alistair Francis --- target/riscv/tcg/op_helper.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/target/riscv/tcg/op_helper.c b/target/riscv/tcg/op_helper.c index ba3c7da375..429a6186a7 100644 --- a/target/riscv/tcg/op_helper.c +++ b/target/riscv/tcg/op_helper.c @@ -293,6 +293,10 @@ target_ulong helper_sret(CPURISCVState *env) const privilege_mode_t src_priv =3D env->priv; const bool src_virt =3D env->virt_enabled; =20 + if ((env->virt_enabled && env->priv < PRV_S) || (env->virt_enabled && = get_field(env->hstatus, HSTATUS_VTSR))) { + riscv_raise_exception(env, RISCV_EXCP_VIRT_INSTRUCTION_FAULT, GETP= C()); + } + if (!(env->priv >=3D PRV_S)) { riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); } @@ -308,10 +312,6 @@ target_ulong helper_sret(CPURISCVState *env) riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); } =20 - if (env->virt_enabled && get_field(env->hstatus, HSTATUS_VTSR)) { - riscv_raise_exception(env, RISCV_EXCP_VIRT_INSTRUCTION_FAULT, GETP= C()); - } - mstatus =3D env->mstatus; prev_priv =3D get_field(mstatus, MSTATUS_SPP); mstatus =3D set_field(mstatus, MSTATUS_SIE, --=20 2.53.0