From patchwork Mon Jan 8 00:13:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 13512982 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2C2DEC47074 for ; Mon, 8 Jan 2024 00:14:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rMdH1-0005z5-MF; Sun, 07 Jan 2024 19:13:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rMdGz-0005xy-6P; Sun, 07 Jan 2024 19:13:45 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rMdGx-0000IS-Hd; Sun, 07 Jan 2024 19:13:44 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1d3e6c86868so11085865ad.1; Sun, 07 Jan 2024 16:13:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704672821; x=1705277621; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ydyQcpoWwEBe73HeZcT4G88tDIBP8gJ14l5X8kcFbbM=; b=fu0lqz0+ffhOW8dzQnXy9r2q2y5BKZqYnKx7fql8O0eNC7BPflZSlgk4xEZ17+ZqeW sSaIuC/ie50DPxv/BYVU9D9JlMpU8tQBU86KfOLMiCIaQhGYAOCXUCmMgXiRTXEBPY+B PFejHSnupfbBzK1aF0/WBLAni5Lz7tEAHfi9uN/UibyHaEhJ6cIWmaAiL+aY/KNILeg4 W4kjJRopEnPdLF498z1GSFH9JLA1W9ni/+ZmhxkzpfRv1p/phpIz34ctA6dmFRPAIspu hOr2FYAUyUEmhf/bTF8DVhMMJmFD3d5GCDCJpzjL+k+9twMgfQHdOwx8+o05tFQZzyib i9Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704672821; x=1705277621; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ydyQcpoWwEBe73HeZcT4G88tDIBP8gJ14l5X8kcFbbM=; b=q/wQaqT+EdQk9mW4rbOWc/La5RJZRQ/Nb7f/idaitoyhFx+N+1/qZYsYSQ27IicFQw 9uyk3LpLaBU528DuoiypeqiGcL9e9tUwdwcUy9QMXAMlfD2StJSt1JC5qZbHyQzXM994 Ru4jj9YQXzJVL7D5TBYH+GjxN/woe5yz/LjpdXtfxTSg5mtbocd4PVyPLRBzLEgp3LtA 3yAj0yxfpLp85/dsOFqHQ5KYVL2nD4rAA+f248RBaKGX43j3IbW8xrQIdD8BS+E+9yN7 ogj7hVVI0nw65E4WgI3g+GcVX4LOotiGq1y1mURUyZRT1mVv8jatET7E0c9moe3u47+N 2DNA== X-Gm-Message-State: AOJu0YwLlnbBLBH6QLZp3+us/Q9OBykTE6Z5tdL1lvYSt4BG3Ql9JB7H pH5FbCZQoWgurJn1ggyEJks= X-Google-Smtp-Source: AGHT+IHdHUcyp/ly2k/G7eeBGv3Zh5M9TU4WmWE7CKh6o0oAWBQEnBN2t8AA3J06Zjf2QKEq0t3cvA== X-Received: by 2002:a17:903:24f:b0:1d4:75c8:6d2d with SMTP id j15-20020a170903024f00b001d475c86d2dmr3811976plh.49.1704672821594; Sun, 07 Jan 2024 16:13:41 -0800 (PST) Received: from toolbox.alistair23.me (2403-580b-97e8-0-321-6fb2-58f1-a1b1.ip6.aussiebb.net. [2403:580b:97e8:0:321:6fb2:58f1:a1b1]) by smtp.gmail.com with ESMTPSA id d15-20020a170902b70f00b001d4974385d4sm4943434pls.250.2024.01.07.16.13.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jan 2024 16:13:41 -0800 (PST) From: Alistair Francis X-Google-Original-From: Alistair Francis To: zhiwei_liu@linux.alibaba.com, qemu-riscv@nongnu.org, palmer@dabbelt.com, dbarboza@ventanamicro.com, bin.meng@windriver.com, qemu-devel@nongnu.org, liwei1518@gmail.com Cc: alistair23@gmail.com, Alistair Francis Subject: [PATCH 1/3] target/riscv: Assert that the CSR numbers will be correct Date: Mon, 8 Jan 2024 10:13:26 +1000 Message-ID: <20240108001328.280222-2-alistair.francis@wdc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240108001328.280222-1-alistair.francis@wdc.com> References: <20240108001328.280222-1-alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=alistair23@gmail.com; helo=mail-pl1-x630.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The CSRs will always be between either CSR_MHPMCOUNTER3 and CSR_MHPMCOUNTER31 or CSR_MHPMCOUNTER3H and CSR_MHPMCOUNTER31H. So although ctr_index can't be negative, Coverity doesn't know this and it isn't obvious to human readers either. Let's add an assert to ensure that Coverity knows the values will be within range. To simplify the code let's also change the RV32 adjustment. Fixes: Coverity CID 1523910 Signed-off-by: Alistair Francis Reviewed-by: Daniel Henrique Barboza --- target/riscv/csr.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index fde7ce1a53..336ec7eda7 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -195,8 +195,11 @@ static RISCVException mctr(CPURISCVState *env, int csrno) if ((riscv_cpu_mxl(env) == MXL_RV32) && csrno >= CSR_MCYCLEH) { /* Offset for RV32 mhpmcounternh counters */ - base_csrno += 0x80; + csrno -= 0x80; } + + g_assert(csrno >= CSR_MHPMCOUNTER3 && csrno <= CSR_MHPMCOUNTER31); + ctr_index = csrno - base_csrno; if ((BIT(ctr_index) & pmu_avail_ctrs >> 3) == 0) { /* The PMU is not enabled or counter is out of range */ From patchwork Mon Jan 8 00:13:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 13512984 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CC66EC47073 for ; Mon, 8 Jan 2024 00:14:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rMdH4-0005zb-Al; Sun, 07 Jan 2024 19:13:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rMdH3-0005zJ-5O; Sun, 07 Jan 2024 19:13:49 -0500 Received: from mail-il1-x12f.google.com ([2607:f8b0:4864:20::12f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rMdH1-0000J6-Gf; Sun, 07 Jan 2024 19:13:48 -0500 Received: by mail-il1-x12f.google.com with SMTP id e9e14a558f8ab-3606e11d9cbso9816155ab.0; Sun, 07 Jan 2024 16:13:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704672826; x=1705277626; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=W6qFn/mU863Y6eJbLzzbeKxrgve7EDyIX8A/fR2qJTE=; b=jnifR22zjzcjXA/iS/2QlWFNNG4QhQK35OczxD/ZFILkySec5uvgYICS3fKcP2kvSL /4H6RTo5GVqM3MTQqlP0EouIEfu1CWRUWBPGniV1uluG0U+vjoM7/jHPbTIt71hR4B7y VSCItkI9nlijX3q8Dj+RapmRqbzB1AnQbFFzOUMgSJT4dEtSvZf8Cv/wUQL1STzatZOn Iki/SO6+FaxUDK0UU/Dy7kxTS4koTzZQ7jXFnqBtqZCgbQ8t/LZ4AzEBmOOqVmrvwliR BtwrApMhQqv0phgIkIzxY4lPBYZDxx0YyFb6Qt+Lm9gwV6k59hRihgFluq2HZLFOdtYX J4Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704672826; x=1705277626; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W6qFn/mU863Y6eJbLzzbeKxrgve7EDyIX8A/fR2qJTE=; b=pVz+Mi+mWu+zIv8RrlUCCZWvwcJ0wtmxmUcLWU1YdieJhCKMSHgozGdfiLbxM7dHx+ kNoyVl2RucroyFqJzDJLUPzrq6txVWBXxJykh8YmHSTkW9xV+UrxEVNmH++SKZOeymop MURnAkAVchN13apqJzqm2tvcd3i9R7VO/rgm0lp3Ecw05U20OuNXoCkYK40vj3gfkjAN 4X03a7kecURgW0OgYMEE0ykPa/2c2PNMr9DamC0YBlnEoRlkH6pScuwrFKh+72CbaOmW cnSK2JXwedVVWxDYB5qQISkImlyJ042nO0B/hIV4NUq3HndzLG42KVUnyR9EnfE7VEaZ Oocw== X-Gm-Message-State: AOJu0YzkWwtLoarpJYvfE9a2j51NGRE9pQra5bXwiHD/WryPK2AD50O/ KZAtXT3qCdTuWoX4eyaDR0I= X-Google-Smtp-Source: AGHT+IFTs2HaEKoZrqjErG4QfDVra0ymDxIYgAM9gKYQgE0RmDuCm10BDN7er7vfcZk+xrTin2u2Hg== X-Received: by 2002:a05:6e02:330e:b0:360:5cd9:a726 with SMTP id bm14-20020a056e02330e00b003605cd9a726mr6698449ilb.22.1704672825946; Sun, 07 Jan 2024 16:13:45 -0800 (PST) Received: from toolbox.alistair23.me (2403-580b-97e8-0-321-6fb2-58f1-a1b1.ip6.aussiebb.net. [2403:580b:97e8:0:321:6fb2:58f1:a1b1]) by smtp.gmail.com with ESMTPSA id d15-20020a170902b70f00b001d4974385d4sm4943434pls.250.2024.01.07.16.13.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jan 2024 16:13:45 -0800 (PST) From: Alistair Francis X-Google-Original-From: Alistair Francis To: zhiwei_liu@linux.alibaba.com, qemu-riscv@nongnu.org, palmer@dabbelt.com, dbarboza@ventanamicro.com, bin.meng@windriver.com, qemu-devel@nongnu.org, liwei1518@gmail.com Cc: alistair23@gmail.com, Alistair Francis Subject: [PATCH 2/3] target/riscv: Don't adjust vscause for exceptions Date: Mon, 8 Jan 2024 10:13:27 +1000 Message-ID: <20240108001328.280222-3-alistair.francis@wdc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240108001328.280222-1-alistair.francis@wdc.com> References: <20240108001328.280222-1-alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::12f; envelope-from=alistair23@gmail.com; helo=mail-il1-x12f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We have been incorrectly adjusting both the interrupt and exception cause when using the hypervisor extension and trapping to VS-mode. This patch changes the conditional to ensure we only adjust the cause for interrupts and not exceptions. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1708 Signed-off-by: Alistair Francis Reviewed-by: Daniel Henrique Barboza --- target/riscv/cpu_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index e7e23b34f4..886a558a42 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1749,8 +1749,8 @@ void riscv_cpu_do_interrupt(CPUState *cs) * See if we need to adjust cause. Yes if its VS mode interrupt * no if hypervisor has delegated one of hs mode's interrupt */ - if (cause == IRQ_VS_TIMER || cause == IRQ_VS_SOFT || - cause == IRQ_VS_EXT) { + if (async && (cause == IRQ_VS_TIMER || cause == IRQ_VS_SOFT || + cause == IRQ_VS_EXT)) { cause = cause - 1; } write_gva = false; From patchwork Mon Jan 8 00:13:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 13512985 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DB430C47073 for ; Mon, 8 Jan 2024 00:14:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rMdHN-00061n-4j; Sun, 07 Jan 2024 19:14:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rMdHL-00061Q-VT; Sun, 07 Jan 2024 19:14:07 -0500 Received: from mail-il1-x132.google.com ([2607:f8b0:4864:20::132]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rMdH5-0000Jt-H4; Sun, 07 Jan 2024 19:14:07 -0500 Received: by mail-il1-x132.google.com with SMTP id e9e14a558f8ab-3606c7a4cb5so15257705ab.3; Sun, 07 Jan 2024 16:13:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704672830; x=1705277630; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CzamXCpLxEay9M5YGNIWRAjHptEGseFQM8AYZ2e7o/k=; b=JV05nDa5U6AlKBnpafd4yu9jiI342niFryxOVKIR3jVTcsfpR52iVt+gO+ElCj9RYD ALw8vlsrxbFTfj2l3N8nYZXXDmVwYjjwWKHbeghyCE/6qmRLxRk0aRLzf/k/setSGRKp /levGBv1eTHF54MjxwQME9hd1XbDiAiwJ/ohxaymZlenWUITWXcmok5prdC3Jr7DfaiA NNJvClRKYj2iXjmGACfRLfT0ZSKagKLGOdW6nex2ioJO2Cce8qms/v3U2DvByja0FpoV cdCvriJi/dUQ5TC2cQwH6xQRN/5ZEBcLsEUEKFiqHB6ocY+c+d46Xs9IfFOTyrNovWOC AQig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704672830; x=1705277630; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CzamXCpLxEay9M5YGNIWRAjHptEGseFQM8AYZ2e7o/k=; b=bBpwAGTPXsPD9JOxA1qgIwRaP5atcr+n0nYITUIkt+oBkDUkFcq06IL+nnDVLgoWt3 cn0tyQ3noVcEettM/xUPyhBziO42/AynziC7YkoaBsy7J9yhleeRloP2SdcZBt6I5WhI rJmINjaopuuJ4A2z0Z1U4kq+ZwFZQuES+TWthCVU1WcbOsgNdOVw9tEO85OronfMt9XH eWV61pMJOHGxKlPCbxfLbkw3W4R1I5mr5EN0PzISJ6+55tj65PjLTjX78hVwOk4BcJ7d G4aL4NAmdiYwFHV/oB/moVP3unbVUtmYGtzQcH1YojdI74vTLFY34BARNSQSsRBEYfQn SYyQ== X-Gm-Message-State: AOJu0YxUJyGiLwhXetPbwH/asy356rynlKHKopcOUzYt2YS8KzDh9trZ jPn6ETyiaRfCu1AVBv2PowU= X-Google-Smtp-Source: AGHT+IFN06+nWdsdhZe5odsxv42OnYTo1YV9/R6LO8/4owMscpLto6fOtXdju5hG+V4QRo8yy0BWxg== X-Received: by 2002:a05:6e02:1c48:b0:35f:f3af:3634 with SMTP id d8-20020a056e021c4800b0035ff3af3634mr6097904ilg.125.1704672830146; Sun, 07 Jan 2024 16:13:50 -0800 (PST) Received: from toolbox.alistair23.me (2403-580b-97e8-0-321-6fb2-58f1-a1b1.ip6.aussiebb.net. [2403:580b:97e8:0:321:6fb2:58f1:a1b1]) by smtp.gmail.com with ESMTPSA id d15-20020a170902b70f00b001d4974385d4sm4943434pls.250.2024.01.07.16.13.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jan 2024 16:13:49 -0800 (PST) From: Alistair Francis X-Google-Original-From: Alistair Francis To: zhiwei_liu@linux.alibaba.com, qemu-riscv@nongnu.org, palmer@dabbelt.com, dbarboza@ventanamicro.com, bin.meng@windriver.com, qemu-devel@nongnu.org, liwei1518@gmail.com Cc: alistair23@gmail.com, Alistair Francis Subject: [PATCH 3/3] target/riscv: Ensure mideleg is set correctly on reset Date: Mon, 8 Jan 2024 10:13:28 +1000 Message-ID: <20240108001328.280222-4-alistair.francis@wdc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240108001328.280222-1-alistair.francis@wdc.com> References: <20240108001328.280222-1-alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::132; envelope-from=alistair23@gmail.com; helo=mail-il1-x132.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Bits 10, 6, 2 and 12 of mideleg are read only 1 when the Hypervisor is enabled. We currently only set them on accesses to mideleg, but they aren't correctly set on reset. Let's ensure they are always the correct value. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1617 Signed-off-by: Alistair Francis Reviewed-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index b07a76ef6b..e20ff46c23 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -891,6 +891,14 @@ static void riscv_cpu_reset_hold(Object *obj) /* mmte is supposed to have pm.current hardwired to 1 */ env->mmte |= (EXT_STATUS_INITIAL | MMTE_M_PM_CURRENT); + /* + * Bits 10, 6, 2 and 12 of mideleg are read only 1 when the Hypervisor + * extension is enabled. + */ + if (riscv_has_ext(env, RVH)) { + env->mideleg |= HS_MODE_INTERRUPTS; + } + /* * Clear mseccfg and unlock all the PMP entries upon reset. * This is allowed as per the priv and smepmp specifications