Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DEDB606A323 for ; Sun, 29 Nov 2026 12:55:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=EQP2jmpH Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xXeQq-0002Bb-Mh; Sun, 29 Nov 2026 07:55:04 -0500 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 1xXZy1-00077l-0e for qemu-riscv@nongnu.org; Sun, 29 Nov 2026 03:09:01 -0500 Received: from mail-oo1-xc2c.google.com ([2607:f8b0:4864:20::c2c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xXZxz-00051D-Du for qemu-riscv@nongnu.org; Sun, 29 Nov 2026 03:09:00 -0500 Received: by mail-oo1-xc2c.google.com with SMTP id 006d021491bc7-71b30ed75a1so5330998eaf.0 for ; Sun, 29 Nov 2026 00:08:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795939738; x=1796544538; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=lEsewkypl8G0H9H3RahvRVbuHsiV0bfa7JEwFl9EFLk=; b=EQP2jmpHUSwKtuTIji+taoh8w5LN/1SnO3Mnql8SjwzUhSI9km50+Q0XYkOQMCPp17 plKaeQrutqe1KADS750bLA2CrxhhwPUQML76Trr/WoiN4UH9BHtUvKX9gK7jiUcrgSMh cz0DY0FqVVooXAsHwQ0UwzTMNyZbv5VOBYmDvHGye1I8V/WJFJWb4aj5xSiV0O8wd4KN hPM8fmYVKlptTFFU6yO+cMxl+EfeUlp2bdbP2h69QH3FhdxZqemTbJrOJ3dVjpuhNlsd MVDvUHRqvtgRRtKCeynIhWYG20TmACUSTocQb3sZnscfUL7yIbNN6MRezlrWysaOICGu Urcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795939738; x=1796544538; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=lEsewkypl8G0H9H3RahvRVbuHsiV0bfa7JEwFl9EFLk=; b=DRNHWBVyowI7SpnAMyRneGVIP/U1nr8fqWITsdIm2HetMgEj83iOu2Tr13eAAgfnQC DyrzZ0BmRzKVp9M9FsGLNsxIJM6xfMK3FGiklHTaWjre6yPXqETq4Aj7u1qpzfWTdBlo m3wsXAewP8o1vLchiULdNO8LTC3votBeFikPq3orrc/HBl0gef3l6bnJirnbxZECHm+Z BL6nVldoTJHadD9Q8P7TXWk4nBmoophtzBCmbJpcciNJed6nfmyr2s8qksTVioY5QAPA uJcAcS/g3oFgjwux1kesLq3Trf60ipyf86h/afpX5iw8U/uK7o6QpXGYB3k5w5LMJhf0 5xAw== X-Forwarded-Encrypted: i=1; AL+hErFP4ONhhSMFO/Eh7iY5PCk/2vY0n3XqgZs3EKaHk+c0CoS3jE9zNHA3f/MWWkGQIAaxQCi/cFyBcaLZ@nongnu.org X-Gm-Message-State: APuU4Z+dD12hisobjXpAem8dbklwoBOgpHEanVpk73RTD3TUKeuw857q kB8haz/S6hx9QGHwPWWfsoJt5b5+mCU8FZv9qHRTfIDnZ2MWZgkew62Y X-Gm-Gg: AZFdTZff9paK4kgzdkSiKCVuXAL8ydSa2dRo1S2OUUeBRqulpJOHsAXq0p8yYGUW0Ip xg4bmYTfFpjFfuiDhPe6IkYtvRBT/um0sUB6q4FFTV+PQgtkNcQF8//04yZG7SVJ8CCW+HvijdJ oGoZ60EesFkaY0e9Hbvdi2TXd+gX3N9V7iKS00KI7vRGnvnTTFOtIybAWN2wYtVY63L9fMBOTyl /TpF/SqFzLsaWdCoBkGPmy7aCYpTsuHtL4FTYCDgJWnqn8fY6ubtkGx/5tC30DGzFOBl1A8jpO4 MAO/EC+fwxbPYJT9FRukc4cEe2mtNjaWU1p0YUYJovuFrc/otJZtgHCDsq7IcF1f19I2Zj+ptlf iu75oDL5UWjJdYHJVbOH0VBhzpQQxc//Dx+BaNaeEkO949SdEnhCkATH0rEVYlXyZhi/suHhneG yNHS+kpY4IrXCppT+LcF9DU/5no+2T+j58y8ezHj1W6WovuH0OjutctqDyuqXECLh61DKGeGUoA KI8dmrHbm7Fzup43Fk/zA1YN40yWTjXAgWIXxNKhFWRH6e9ULS4zKQkBKd7AU7NcHAwphkZl+VC zkCj7MHJ/btO6tmCIoJ4QdaIUo0/iCPt/7HIX5Z/0rlMaYHYlfr6DaZPmqZpP1NFkLab9AG4Oia BGlZullDgtA1jLS/z0aZA X-Received: by 2002:a05:6820:4088:b0:71a:e62f:62ee with SMTP id 006d021491bc7-71b39404b5amr22534646eaf.23.1795939737543; Sun, 29 Nov 2026 00:08:57 -0800 (PST) Received: from larptup ([2605:a601:81cd:b600:f1ab:1690:fce5:608d]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4bc5ebdbb4fsm24377252fac.5.2026.11.29.00.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 00:08:56 -0800 (PST) From: Juliet Mathis To: qemu-devel@nongnu.org Cc: Weiwei Li , Palmer Dabbelt , Liu Zhiwei , Alistair Francis , Daniel Henrique Barboza , qemu-riscv@nongnu.org, Chao Liu , Juliet Mathis , Samarth Sarda , Dana Coates Subject: [PATCH] target/riscv: fix VS-mode sireg access to a counter exception Date: Sun, 29 Nov 2026 02:08:54 -0600 Message-ID: <20261129080854.1860-1-julietmathis2004@gmail.com> X-Mailer: git-send-email 2.56.1.windows.1 X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::c2c; envelope-from=julietmathis2004@gmail.com; helo=mail-oo1-xc2c.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 29 Nov 2026 07:54:55 -0500 X-BeenThere: qemu-riscv@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-20.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_PASS,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 When counter delegation is disabled, the counter range is unimplemented. Any access to a counter while in VS-mode should raise an illegal instruction exception. Any failure to access a register in VS-mode raises a virtual instruction exception without considering the value of menvcfg.CDE. Our fix raises an illegal instruction exception on failure to access a register in VS-mode if menvcfg.CDE = 0 and vsiselect is within the counter range. Fixes: 5e33a2082715 ("target/riscv: Support generic CSR indirect access") Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4830 Signed-off-by: Samarth Sarda Signed-off-by: Dana Coates Signed-off-by: Juliet Mathis --- target/riscv/tcg/csr.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/target/riscv/tcg/csr.c b/target/riscv/tcg/csr.c index af444e3e6f..ed9ae72c8c 100644 --- a/target/riscv/tcg/csr.c +++ b/target/riscv/tcg/csr.c @@ -2923,6 +2923,12 @@ static int rmw_xireg_csrind(CPURISCVState *env, int csrno, if (xiselect_cd_range(isel)) { ret = rmw_xireg_cd(env, csrno, isel, val, new_val, wr_mask); + + if (ret && env->virt_enabled && virt && + !get_field(env->menvcfg, MENVCFG_CDE)) { + return RISCV_EXCP_ILLEGAL_INST; + } + } else if (xiselect_ctr_range(csrno, isel)) { ret = rmw_xireg_ctr(env, csrno, isel, val, new_val, wr_mask); } else { -- 2.56.1.windows.1