From nobody Tue Nov 26 20:31:38 2024 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1704672869; cv=none; d=zohomail.com; s=zohoarc; b=c5U4F0xUJupF67WEQp0+TnWN1TECsNJryeiWJCd3RGYT2INQNiGu4QjnNOs3V/m30Xfci9Dnssti5D7GtX+mP+KFTqbbaLqnpAYcsVsncPszm59QkPLhtTYv8EaA467166TQkAMsVVgwFoTzLpybgbOZGeY6ETEgKTBPPvW/EbU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704672869; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ydyQcpoWwEBe73HeZcT4G88tDIBP8gJ14l5X8kcFbbM=; b=m01LpLP+3pmyMesBThgJMbekof6HZ6NtFOCMxWXpuEqsXm2Gu8fPHeyp8Zw0mjt6aabsYvoFHW5GqMNurWDGjiEiBo8avx1tGhfFeK13KHxOavcAPlXUQP9OM3NmTjvzU24CNs4ag4EmVoNhl7c+dvom+FYOotfcSy9Cf88Pyik= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704672869689585.6050518474744; Sun, 7 Jan 2024 16:14:29 -0800 (PST) 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) 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) 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) 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 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=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1704672871391100003 Content-Type: text/plain; charset="utf-8" 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 csr= no) =20 if ((riscv_cpu_mxl(env) =3D=3D MXL_RV32) && csrno >=3D CSR_MCYCLEH) { /* Offset for RV32 mhpmcounternh counters */ - base_csrno +=3D 0x80; + csrno -=3D 0x80; } + + g_assert(csrno >=3D CSR_MHPMCOUNTER3 && csrno <=3D CSR_MHPMCOUNTER31); + ctr_index =3D csrno - base_csrno; if ((BIT(ctr_index) & pmu_avail_ctrs >> 3) =3D=3D 0) { /* The PMU is not enabled or counter is out of range */ --=20 2.43.0 From nobody Tue Nov 26 20:31:38 2024 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1704672891; cv=none; d=zohomail.com; s=zohoarc; b=ZFNyk4ok4bHa+VwkkaseEm7WUJnHF6dLkAFehvklsEVYjKikNRqQG0jd8p4d2uOAi5fenaPHrToGzl9ab7BohfoCiKKzezySw8v2NnCok7PPGvabq+u2tTHq/QtW6L3vkhZAKvfVYVMVCJv6AHISB5kjjk5e3EiIhQYkWHX0l8U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704672891; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=W6qFn/mU863Y6eJbLzzbeKxrgve7EDyIX8A/fR2qJTE=; b=hIK3vAEgiI9t8ZcT0z7TIHkkAK9ZGDlV9vBGtZUB6vPqwJA+RlCdbaNOqmPYdTi+N8cH853YE0+Lfmjv1GaBWVkuYaByTJud8sDXZdJOLEhBzy8pAbArRFvnngupLGH9yYjHT/k2BmDv/SnDhKUgKVLYXLbdEVNDX7gGi041QJI= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17046728919721013.8341275863992; Sun, 7 Jan 2024 16:14:51 -0800 (PST) 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) 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) 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) 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 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=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1704672893135100006 Content-Type: text/plain; charset="utf-8" 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 inte= rrupt * no if hypervisor has delegated one of hs mode's interru= pt */ - if (cause =3D=3D IRQ_VS_TIMER || cause =3D=3D IRQ_VS_SOFT = || - cause =3D=3D IRQ_VS_EXT) { + if (async && (cause =3D=3D IRQ_VS_TIMER || cause =3D=3D IR= Q_VS_SOFT || + cause =3D=3D IRQ_VS_EXT)) { cause =3D cause - 1; } write_gva =3D false; --=20 2.43.0 From nobody Tue Nov 26 20:31:38 2024 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1704672899; cv=none; d=zohomail.com; s=zohoarc; b=FaSCGA8FUidv5zCd7MdLG03oggSbGIi1hBMPZwWH71bTZwGkOOy8R+NYxpDYL4/qNHdb8h4PG6bxJgJV+gXbfakxHFP2sVR+qLRTnTOtsaUmN2K7iarCWkeoiQj9cvTbFufNd0yX646WxrqPvScx7FkbO+hrrLL/aHM+8+Vklbo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704672899; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CzamXCpLxEay9M5YGNIWRAjHptEGseFQM8AYZ2e7o/k=; b=bCddsmrb2eTBI4LrdoO+sTD4YnByeeTqTLEvcOLKiMGz+qGJJLJ4ljbKbGBPZbPQ1ybHV2KW6ZVbnr6SAU48In0sQzJDfSJwC1ra/3DuAyJXJnBQKKtxdJfP8fqj1NOh8kljElk2PHyi0J/rMKG2SA6yTdhvVkUuYZ6N7PbzMak= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704672899075751.0597823589483; Sun, 7 Jan 2024 16:14:59 -0800 (PST) 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) 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) 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) 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 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=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1704672901057100003 Content-Type: text/plain; charset="utf-8" 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 |=3D (EXT_STATUS_INITIAL | MMTE_M_PM_CURRENT); =20 + /* + * 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 |=3D HS_MODE_INTERRUPTS; + } + /* * Clear mseccfg and unlock all the PMP entries upon reset. * This is allowed as per the priv and smepmp specifications --=20 2.43.0