From nobody Mon Feb 9 19:08:15 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1642717080058678.5025337188665; Thu, 20 Jan 2022 14:18:00 -0800 (PST) Received: from localhost ([::1]:33302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAfkj-0007ZF-SG for importer@patchew.org; Thu, 20 Jan 2022 17:17:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44528) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAdj8-0002qE-2o for qemu-devel@nongnu.org; Thu, 20 Jan 2022 15:08:10 -0500 Received: from [2607:f8b0:4864:20::834] (port=45633 helo=mail-qt1-x834.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nAdj6-0006ib-2H for qemu-devel@nongnu.org; Thu, 20 Jan 2022 15:08:09 -0500 Received: by mail-qt1-x834.google.com with SMTP id x8so7557543qta.12 for ; Thu, 20 Jan 2022 12:08:07 -0800 (PST) Received: from rivos-atish.. (adsl-70-228-75-190.dsl.akrnoh.ameritech.net. [70.228.75.190]) by smtp.gmail.com with ESMTPSA id a136sm1834160qkc.56.2022.01.20.12.08.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 12:08:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=D+ihxa1Ld5LxT20StF+81LT6lsXU3VYkkQbIBKYyb9w=; b=EbqYbbOu9agKYYpJipy722ZUTzDgTp25eZ+Y7AlBKndmwkenu4yJ1+S7UjS1nzWO0e 2/s4LyUypr1TncQoulW2uk60+MIiw+sPvgn7htpwTW9TJ5uSRD8BHlj0BK5cJhufKq7b Vm3ryvYwK4goxLQxHDSaslVhS+XCsuEKgeb8V+9v8Ur02SGDpE2Jk0g7yn6NK40QngEr u8E9nTR2lJ4sdYxtjff/LsDQ+Ho3CR0jliEFwJvrR+bWjMCbxlG8nEExTgsgwoetIm98 t6qwThhw7eAlv6K3ohA4OY2iSPYvjhOvl26yJH4nxh9Ng2nTrCn6zg0COl8fftE20Scc xdyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=D+ihxa1Ld5LxT20StF+81LT6lsXU3VYkkQbIBKYyb9w=; b=YorJtkB/QTJm2m5dVfjFSjBSX2yKt1L+2IJlYHrviomZzDhlesdv5v3aC1GN8iNnxh cjAXTftvKNBYhdrd17dkPFLiFe5vLkGbQAlAEjxdKuI+XaiXC2kZ2toJlX9HqmvnIIip HbHySaMRYO93ge5DYEPsRXFZ7nPrrM92Pbo2UhA+e63Hp29ElYW1qaqfyXGZMtzVIfQ4 Bhq3z346sqjTKtniFT6RQR9NBO4XMJNtE5C7hQmMsTBBSOqlclbUd6zKYMwusbMcbTF8 BF3DxrJL5b9idKoHhTNgC7tZ3ScUEUfMAYUuCzPdny1ekxiTreEF5mUKLRJ5bBPU8D6p VwoA== X-Gm-Message-State: AOAM531vZTpadGllQq921lDfr85rfjbefa/q7OnFsc5LXr2l/W8GBSMd DJB63vksmEDfkf2w3c6FYxTVYEgEppkS9A== X-Google-Smtp-Source: ABdhPJw+Vp5wD9222Ynvu/EQCjpP8cSEINE6XOkd9qh8kq+l86VQk+Rouu0C7OqVicbMVLR7YIj4nQ== X-Received: by 2002:a05:622a:512:: with SMTP id l18mr641866qtx.120.1642709286765; Thu, 20 Jan 2022 12:08:06 -0800 (PST) From: Atish Patra To: qemu-devel@nongnu.org Subject: [RFC 2/5] target/riscv: Introduce privilege version field in the CSR ops. Date: Thu, 20 Jan 2022 12:07:32 -0800 Message-Id: <20220120200735.2739543-3-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220120200735.2739543-1-atishp@rivosinc.com> References: <20220120200735.2739543-1-atishp@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::834 (failed) 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::834; envelope-from=atishp@rivosinc.com; helo=mail-qt1-x834.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Cc: qemu-riscv@nongnu.org, Anup Patel , Bin Meng , Atish Patra , Alistair Francis , Palmer Dabbelt Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1642717082974100001 Content-Type: text/plain; charset="utf-8" To allow/disallow the CSR access based on the privilege spec, a new field in the csr_ops is introduced. It also adds the privileged specification version (v1.12) for the CSRs introduced in the v1.12. This includes the new ratified extensions such as Vector, Hypervisor and secconfig CSR. Signed-off-by: Atish Patra --- target/riscv/cpu.h | 1 + target/riscv/csr.c | 103 ++++++++++++++++++++++++++++++--------------- 2 files changed, 69 insertions(+), 35 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 671f65100b1a..7f87917204c5 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -521,6 +521,7 @@ typedef struct { riscv_csr_op_fn op; riscv_csr_read128_fn read128; riscv_csr_write128_fn write128; + uint32_t min_priv_ver; } riscv_csr_operations; =20 /* CSR function table constants */ diff --git a/target/riscv/csr.c b/target/riscv/csr.c index adb3d4381d1f..762d3269b4a4 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1991,13 +1991,20 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_FRM] =3D { "frm", fs, read_frm, write_frm }, [CSR_FCSR] =3D { "fcsr", fs, read_fcsr, write_fcsr }, /* Vector CSRs */ - [CSR_VSTART] =3D { "vstart", vs, read_vstart, write_vstart }, - [CSR_VXSAT] =3D { "vxsat", vs, read_vxsat, write_vxsat }, - [CSR_VXRM] =3D { "vxrm", vs, read_vxrm, write_vxrm }, - [CSR_VCSR] =3D { "vcsr", vs, read_vcsr, write_vcsr }, - [CSR_VL] =3D { "vl", vs, read_vl }, - [CSR_VTYPE] =3D { "vtype", vs, read_vtype }, - [CSR_VLENB] =3D { "vlenb", vs, read_vlenb }, + [CSR_VSTART] =3D { "vstart", vs, read_vstart, write_vstart, N= ULL, + NULL, NULL, PRIV_VERSION_1_12_0= }, + [CSR_VXSAT] =3D { "vxsat", vs, read_vxsat, write_vxsat, NU= LL, + NULL, NULL, PRIV_VERSION_1_12_0= }, + [CSR_VXRM] =3D { "vxrm", vs, read_vxrm, write_vxrm, NUL= L, + NULL, NULL, PRIV_VERSION_1_12_0= }, + [CSR_VCSR] =3D { "vcsr", vs, read_vcsr, write_vcsr, NUL= L, + NULL, NULL, PRIV_VERSION_1_12_0= }, + [CSR_VL] =3D { "vl", vs, read_vl, NULL, NULL, NULL, NU= LL, + PRIV_VERSION_1_12_0 }, + [CSR_VTYPE] =3D { "vtype", vs, read_vtype, NULL, NULL, NULL,= NULL, + PRIV_VERSION_1_12_0 }, + [CSR_VLENB] =3D { "vlenb", vs, read_vlenb, NULL, NULL, NULL,= NULL, + PRIV_VERSION_1_12_0 }, /* User Timers and Counters */ [CSR_CYCLE] =3D { "cycle", ctr, read_instret }, [CSR_INSTRET] =3D { "instret", ctr, read_instret }, @@ -2063,36 +2070,62 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { /* Supervisor Protection and Translation */ [CSR_SATP] =3D { "satp", smode, read_satp, write_satp = }, =20 - [CSR_HSTATUS] =3D { "hstatus", hmode, read_hstatus, writ= e_hstatus }, - [CSR_HEDELEG] =3D { "hedeleg", hmode, read_hedeleg, writ= e_hedeleg }, - [CSR_HIDELEG] =3D { "hideleg", hmode, read_hideleg, writ= e_hideleg }, - [CSR_HVIP] =3D { "hvip", hmode, NULL, NULL, rmw_= hvip }, - [CSR_HIP] =3D { "hip", hmode, NULL, NULL, rmw_= hip }, - [CSR_HIE] =3D { "hie", hmode, read_hie, writ= e_hie }, - [CSR_HCOUNTEREN] =3D { "hcounteren", hmode, read_hcounteren, writ= e_hcounteren }, - [CSR_HGEIE] =3D { "hgeie", hmode, read_zero, writ= e_hgeie }, - [CSR_HTVAL] =3D { "htval", hmode, read_htval, writ= e_htval }, - [CSR_HTINST] =3D { "htinst", hmode, read_htinst, writ= e_htinst }, - [CSR_HGEIP] =3D { "hgeip", hmode, read_zero, writ= e_hgeip }, - [CSR_HGATP] =3D { "hgatp", hmode, read_hgatp, writ= e_hgatp }, - [CSR_HTIMEDELTA] =3D { "htimedelta", hmode, read_htimedelta, writ= e_htimedelta }, - [CSR_HTIMEDELTAH] =3D { "htimedeltah", hmode32, read_htimedeltah, writ= e_htimedeltah }, - - [CSR_VSSTATUS] =3D { "vsstatus", hmode, read_vsstatus, writ= e_vsstatus }, - [CSR_VSIP] =3D { "vsip", hmode, NULL, NULL, rmw_= vsip }, - [CSR_VSIE] =3D { "vsie", hmode, read_vsie, writ= e_vsie }, - [CSR_VSTVEC] =3D { "vstvec", hmode, read_vstvec, writ= e_vstvec }, - [CSR_VSSCRATCH] =3D { "vsscratch", hmode, read_vsscratch, writ= e_vsscratch }, - [CSR_VSEPC] =3D { "vsepc", hmode, read_vsepc, writ= e_vsepc }, - [CSR_VSCAUSE] =3D { "vscause", hmode, read_vscause, writ= e_vscause }, - [CSR_VSTVAL] =3D { "vstval", hmode, read_vstval, writ= e_vstval }, - [CSR_VSATP] =3D { "vsatp", hmode, read_vsatp, writ= e_vsatp }, - - [CSR_MTVAL2] =3D { "mtval2", hmode, read_mtval2, writ= e_mtval2 }, - [CSR_MTINST] =3D { "mtinst", hmode, read_mtinst, writ= e_mtinst }, + [CSR_HSTATUS] =3D { "hstatus", hmode, read_hstatus, write_= hstatus, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + [CSR_HEDELEG] =3D { "hedeleg", hmode, read_hedeleg, write_= hedeleg, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + [CSR_HIDELEG] =3D { "hideleg", hmode, read_hideleg, write_= hideleg, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + [CSR_HVIP] =3D { "hvip", hmode, NULL, NULL, rmw_hv= ip, + NULL, NULL, PRIV_VERSION_1_12_0 }, + [CSR_HIP] =3D { "hip", hmode, NULL, NULL, rmw_hi= p, + NULL, NULL, PRIV_VERSION_1_12_0 }, + [CSR_HIE] =3D { "hie", hmode, read_hie, write_= hie, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + [CSR_HCOUNTEREN] =3D { "hcounteren", hmode, read_hcounteren, write= _hcounteren, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + [CSR_HGEIE] =3D { "hgeie", hmode, read_zero, write_= hgeie, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + [CSR_HTVAL] =3D { "htval", hmode, read_htval, write_= htval, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + [CSR_HTINST] =3D { "htinst", hmode, read_htinst, write_= htinst, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + [CSR_HGEIP] =3D { "hgeip", hmode, read_zero, write_= hgeip, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + [CSR_HGATP] =3D { "hgatp", hmode, read_hgatp, write_= hgatp, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + [CSR_HTIMEDELTA] =3D { "htimedelta", hmode, read_htimedelta, write= _htimedelta, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + [CSR_HTIMEDELTAH] =3D { "htimedeltah", hmode32, read_htimedeltah, writ= e_htimedeltah, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + + [CSR_VSSTATUS] =3D { "vsstatus", hmode, read_vsstatus, write_= vsstatus, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + [CSR_VSIP] =3D { "vsip", hmode, NULL, NULL, rmw_vs= ip, + NULL, NULL, PRIV_VERSION_1_12_0 }, + [CSR_VSIE] =3D { "vsie", hmode, read_vsie, write_= vsie, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + [CSR_VSTVEC] =3D { "vstvec", hmode, read_vstvec, write_= vstvec, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + [CSR_VSSCRATCH] =3D { "vsscratch", hmode, read_vsscratch, write_= vsscratch, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + [CSR_VSEPC] =3D { "vsepc", hmode, read_vsepc, write_= vsepc, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + [CSR_VSCAUSE] =3D { "vscause", hmode, read_vscause, write_= vscause, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + [CSR_VSTVAL] =3D { "vstval", hmode, read_vstval, write_= vstval, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + [CSR_VSATP] =3D { "vsatp", hmode, read_vsatp, write_= vsatp, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + + [CSR_MTVAL2] =3D { "mtval2", hmode, read_mtval2, write_= mtval2, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, + [CSR_MTINST] =3D { "mtinst", hmode, read_mtinst, write_= mtinst, + NULL, NULL, NULL, PRIV_VERSION_1_= 12_0 }, =20 /* Physical Memory Protection */ - [CSR_MSECCFG] =3D { "mseccfg", epmp, read_mseccfg, write_mseccfg }, + [CSR_MSECCFG] =3D { "mseccfg", epmp, read_mseccfg, write_mseccfg, + NULL, NULL, NULL, PRIV_VERSION_1_12_0= }, [CSR_PMPCFG0] =3D { "pmpcfg0", pmp, read_pmpcfg, write_pmpcfg }, [CSR_PMPCFG1] =3D { "pmpcfg1", pmp, read_pmpcfg, write_pmpcfg }, [CSR_PMPCFG2] =3D { "pmpcfg2", pmp, read_pmpcfg, write_pmpcfg }, --=20 2.30.2