From nobody Thu Apr 3 11:02:52 2025 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=syntacore.com ARC-Seal: i=1; a=rsa-sha256; t=1740669904; cv=none; d=zohomail.com; s=zohoarc; b=EFf12jgocQtVqoV4DD19vVGk4TE4SFQjQDpKh9SfKb3uLsjih6z3HDEITK1Nf18ORFRPV8jlD9hkx6Cc0QzYpFyiDOUPE1oRLWghHAW8OixWYxuTfGHO+cKYmANYB1rb8qqkCFqmuH6Hm9GPdt/LyIdV5teYzfGD66T2Y8xjmjU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1740669904; h=Content-Type: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=adUAeS8Pv7eqKYl3hGXwcB8AWI6qvWNM+DnwBPIEL1s=; b=jcOVsYjD+8X7wGhAfj/nTDMDHWi5yQD4NBHedSG/bLdf3pSxFsJ9kmii77OvcrO20GsoIDCd6ACM3ZQhXsHCUQ5Yrsr/sS1YJW8uS5k/0edvJeZrbi9T1WBr1P5BtE3/aUENnGcs7g+um9D16j4TXgUQYHfethmamM7B98IeuRo= 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 1740669904359383.6986642161361; Thu, 27 Feb 2025 07:25:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnfjm-0001J1-1r; Thu, 27 Feb 2025 10:23:46 -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 1tnf6M-0001sg-RM; Thu, 27 Feb 2025 09:43:03 -0500 Received: from m.syntacore.com ([178.249.69.228]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnf6J-0008Tc-N0; Thu, 27 Feb 2025 09:43:02 -0500 Received: from pmg.syntacore.com (localhost.localdomain [127.0.0.1]) by m.syntacore.com (Proxmox) with ESMTP id 81077B41D0C; Thu, 27 Feb 2025 17:42:50 +0300 (MSK) Received: from S-SC-EXCH-01.corp.syntacore.com (exchange.syntacore.com [10.76.202.20]) by m.syntacore.com (Proxmox) with ESMTPS id 6C76EB41D05; Thu, 27 Feb 2025 17:42:50 +0300 (MSK) Received: from le14u.yadro.com (172.17.5.46) by S-SC-EXCH-01.corp.syntacore.com (10.76.202.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 27 Feb 2025 17:41:40 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syntacore.com; h=cc:cc:content-transfer-encoding:content-type:content-type :date:from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=m; bh=adUAeS8Pv7eqKYl3hGXwcB8 AWI6qvWNM+DnwBPIEL1s=; b=RiM2mQHdQvZXjwAHdiYLJvsQLp/wRk2HuZFqIR6 l+S/8v9RVuMv0z18ASV8jBclHvdXgmixrLejOBSMKYK8ll5qLgUhVioS2fqJaBg2 HiUZDY9QiM6CMdDZm5ZRQrw2aU8LPLiW8SDPt8VVoBOZGaofpqTZkC08GOkKE8Bg u2kzELxwS6WaK4SmrGS6fRe9oaujkicklGBuHyWdaLlxZDe1cDvGHAD8JbriZwWM vzXQaHHAcKow0klechYEj/OXCntAMeGY/w8RKaBEyIx6jhFGtEHsTjT/+LUmN0iD Hi/REDzGkSihMLUqzWY2bwXTRr2ZcSv1CcqZVBEilv2enEg== From: Saveliy Motov To: CC: , , , , , , , Saveliy Motov Subject: [PATCH 1/2] target/riscv/csr.c: Fix first Zkr CSR reading Date: Thu, 27 Feb 2025 17:41:59 +0300 Message-ID: <20250227144200.69270-2-saveliy.motov@syntacore.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250227144200.69270-1-saveliy.motov@syntacore.com> References: <20250227144200.69270-1-saveliy.motov@syntacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [172.17.5.46] X-ClientProxiedBy: S-SC-EXCH-01.corp.syntacore.com (10.76.202.20) To S-SC-EXCH-01.corp.syntacore.com (10.76.202.20) 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=178.249.69.228; envelope-from=saveliy.motov@syntacore.com; helo=m.syntacore.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 27 Feb 2025 10:23:37 -0500 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 @syntacore.com) X-ZM-MESSAGEID: 1740669905153019000 Content-Type: text/plain; charset="utf-8" According to RISC-V Cryptography Extensions Volume I. Version 1.0.1 Chapter= 4.1 BIST alarm must be latched until polled at least once to enable software to record its occurrence. Signed-off-by: Saveliy Motov --- target/riscv/cpu.c | 3 +++ target/riscv/cpu.h | 4 ++++ target/riscv/csr.c | 7 ++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index cca24b9f1f..a5724b2fca 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1046,6 +1046,9 @@ static void riscv_cpu_reset_hold(Object *obj, ResetTy= pe type) if (mcc->parent_phases.hold) { mcc->parent_phases.hold(obj, type); } + + env->zkr_csr_is_read =3D false; + #ifndef CONFIG_USER_ONLY env->misa_mxl =3D mcc->misa_mxl_max; env->priv =3D PRV_M; diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 97713681cb..7fc36ae7ba 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -250,6 +250,10 @@ struct CPUArchState { target_ulong excp_uw2; /* sw check code for sw check exception */ target_ulong sw_check_code; + + /* ZKR state */ + bool zkr_csr_is_read; + #ifdef CONFIG_USER_ONLY uint32_t elf_flags; #endif diff --git a/target/riscv/csr.c b/target/riscv/csr.c index afb7544f07..3af4f69698 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -5152,10 +5152,15 @@ static RISCVException rmw_seed(CPURISCVState *env, = int csrno, { target_ulong rval; =20 - rval =3D riscv_new_csr_seed(new_value, write_mask); + if (env->zkr_csr_is_read) { + rval =3D riscv_new_csr_seed(new_value, write_mask); + } else { + rval =3D SEED_OPST_BIST; + } =20 if (ret_value) { *ret_value =3D rval; + env->zkr_csr_is_read =3D true; } =20 return RISCV_EXCP_NONE; --=20 2.34.1 From nobody Thu Apr 3 11:02:52 2025 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=syntacore.com ARC-Seal: i=1; a=rsa-sha256; t=1740669874; cv=none; d=zohomail.com; s=zohoarc; b=Cqi3M6m9uCs8NIuL0bpNebmJHXvUcpWBhxgkQz+2dXLKa4PxO4zB+xhENpzOEm1+NWjfBEl8r5RtNii31UVnQ6gG4eSC307LM/DFz7AQ+8ME1PmTL/N92fu/Ty4bwTOYUBPb3uIrDLWdmeoU/LxF5yo9EaM1VpdNRnI3mIldNJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1740669874; h=Content-Type: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=d+XAQK1xiGQq17VjpVEtbaOswnov1e3zbeiyzXg+Eqc=; b=duDAcrW3ixLHM+Jr3OvjUVwfXnVMKQk6x1pL44WagnKRM1s3YhOBkho3Nxs+8NXK7PJpWkq14ANmadoKfp1jB+3Xii31oQwgpMB7z/pcMmv/AyXUb9XeDGa1i+/qA8vZW3Yt/Vf4Hs0TU8XNFFWElu8HraNvxobUclIMBXoIz+s= 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 1740669874450332.13178487230346; Thu, 27 Feb 2025 07:24:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnfjh-0001IB-Vo; Thu, 27 Feb 2025 10:23:42 -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 1tnf6L-0001sL-LP; Thu, 27 Feb 2025 09:43:01 -0500 Received: from m.syntacore.com ([178.249.69.228]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnf6J-0008Te-N2; Thu, 27 Feb 2025 09:43:01 -0500 Received: from pmg.syntacore.com (localhost.localdomain [127.0.0.1]) by m.syntacore.com (Proxmox) with ESMTP id C5344B41D10; Thu, 27 Feb 2025 17:42:50 +0300 (MSK) Received: from S-SC-EXCH-01.corp.syntacore.com (mail.syntacore.com [10.76.202.20]) by m.syntacore.com (Proxmox) with ESMTPS id B1BEBB41D05; Thu, 27 Feb 2025 17:42:50 +0300 (MSK) Received: from le14u.yadro.com (172.17.5.46) by S-SC-EXCH-01.corp.syntacore.com (10.76.202.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 27 Feb 2025 17:41:40 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syntacore.com; h=cc:cc:content-transfer-encoding:content-type:content-type :date:from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=m; bh=d+XAQK1xiGQq17VjpVEtbaO swnov1e3zbeiyzXg+Eqc=; b=qUWEDldQqlXEcBPClh+U+fk/c6OyZUSGR8kz3ae Gv/XTasqSLC5/QCrnXKHIu62zXn8Q5oEwwYzW3KRYPowMgERIWcg4qPi92mEkPgF vUX27Bw/elrNjA/P2sUkmlHF96pBYZ7/4Pz4FTu8btxWjd0bq202WIQnUo/tT8v8 9i+Bh2HIUULbyUZRCjq+arnAZ+svJWgJUBruAXcsAUO+CLjltrVAOnIvW2fNTiM5 Fyf8BtCfE1YLRxsS9QqaUDhQWOTUpHxdV/MBlKPO1d+8sxtA9BuOPICjhR4PZFa9 NajBv6JjwnkPGwd8Zor11sboXzhKmfhHIncgVVwkzKSfnmw== From: Saveliy Motov To: CC: , , , , , , , Saveliy Motov Subject: [PATCH 2/2] target/riscv/cpu_bits.h: Fix [63:32] bits in Zkr seed CSR Date: Thu, 27 Feb 2025 17:42:00 +0300 Message-ID: <20250227144200.69270-3-saveliy.motov@syntacore.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250227144200.69270-1-saveliy.motov@syntacore.com> References: <20250227144200.69270-1-saveliy.motov@syntacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [172.17.5.46] X-ClientProxiedBy: S-SC-EXCH-01.corp.syntacore.com (10.76.202.20) To S-SC-EXCH-01.corp.syntacore.com (10.76.202.20) 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=178.249.69.228; envelope-from=saveliy.motov@syntacore.com; helo=m.syntacore.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 27 Feb 2025 10:23:37 -0500 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 @syntacore.com) X-ZM-MESSAGEID: 1740669875082019000 Content-Type: text/plain; charset="utf-8" According to: RISC-V Cryptography Extensions Volume I. Version 1.0.1, 4.1. The seed CSR On 64 bit machine 32 bit register must be extended with zeroes in higher bi= ts Previously status mask was formed by integer left bitshift with sign changi= ng, so higher 32 bits was 1. Change type from int to ULL fix ZKR seed. Signed-off-by: Saveliy Motov --- target/riscv/cpu_bits.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index f97c48a394..140b45bda7 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -878,11 +878,11 @@ typedef enum RISCVException { (HVICTL_VTI | HVICTL_IID | HVICTL_IPRIOM | HVICTL_IPRIO) =20 /* seed CSR bits */ -#define SEED_OPST (0b11 << 30) -#define SEED_OPST_BIST (0b00 << 30) -#define SEED_OPST_WAIT (0b01 << 30) -#define SEED_OPST_ES16 (0b10 << 30) -#define SEED_OPST_DEAD (0b11 << 30) +#define SEED_OPST (0b11UL << 30) +#define SEED_OPST_BIST (0b00UL << 30) +#define SEED_OPST_WAIT (0b01UL << 30) +#define SEED_OPST_ES16 (0b10UL << 30) +#define SEED_OPST_DEAD (0b11UL << 30) /* PMU related bits */ #define MIE_LCOFIE (1 << IRQ_PMU_OVF) =20 --=20 2.34.1