From nobody Tue Nov 26 08:58:04 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 ARC-Seal: i=1; a=rsa-sha256; t=1709146357; cv=none; d=zohomail.com; s=zohoarc; b=SLeZt4JLd9v1CnctFuhCGjhuZWW1lDkRD6TAvxj2+vaLVPbkMnsIxep75mdRMmKYolltXzsEHQixB1mQHPh6CT+eeGr6mQhaP9ngzAX8vAkuk5cwXGcyjpq8QB/d5TN89zBDtEz7SKUa8PYO5OJjXnTUMY44bUDUbVYaXrt4xfo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709146357; 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:Message-Id:Reply-To:To; bh=wsd4UJgUqZBGQqVPr0loi27Ch+LSMtssoNWVgdi64OI=; b=ecy/Ytegu92DBzqdKGu553zsD2R8+oZdmpWzmLK8fgDVceMWyJg7wUiV9wzqxyE9SIR7Z7IuzyjzecBIBsNc+jVrD+gWaNwisfUeeJVlLPKPLwqJOn4FzB4bm1suhNWbWhMkhN0fa7tA/zlbmevDgu8w9+CCQPiwDcZI7BlsbX4= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709146357243812.0593256385636; Wed, 28 Feb 2024 10:52:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfP2A-0000q1-3p; Wed, 28 Feb 2024 13:52:03 -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 1rfP24-0000mY-6Y for qemu-devel@nongnu.org; Wed, 28 Feb 2024 13:51:56 -0500 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfP22-0006us-Gu for qemu-devel@nongnu.org; Wed, 28 Feb 2024 13:51:55 -0500 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6da202aa138so4007750b3a.2 for ; Wed, 28 Feb 2024 10:51:54 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id o20-20020a635d54000000b005dbed0ffb10sm49562pgm.83.2024.02.28.10.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 10:51:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1709146313; x=1709751113; 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=wsd4UJgUqZBGQqVPr0loi27Ch+LSMtssoNWVgdi64OI=; b=N4EcU+kSWEaYnQr2WekNE5+1L5tnOOnbESdh/oFjUZBFn/cRdWEKN/tpBaNDCu/EaB Zx0YvH44WBuJGV1gyo22NPQU43Df5mi8ZJylKx8bIivHcOKtg01wGJ3AgBG/n4bbHESs RVdgBl2DAo+fRZqBQu+Giw/hXqpjy22JgBYSPMHbs8FzZukHVpqJTuBoFTLuoBSS7Dzy yF+/Zlp6od088jqQzkEnoYlTvWFNrg10GkMuH9GnIs/qTKKwG20FGrldXQ3AQJgETFkx uP27fzbDra0ID5LVucp44qDV6nI77qcjMAQBHZ+QQGQrLKhY47uhOgxB8hBrhMUaa+9Z qMXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709146313; x=1709751113; 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=wsd4UJgUqZBGQqVPr0loi27Ch+LSMtssoNWVgdi64OI=; b=ID52QQ8B63NmjtF0oALhNY/kFfHeVrcIE7CJ6FiBwjj+Uc/q2AIpuFRGCeBsAH7PED EZ4fmTL0dwOj49mzJaMcXBAqDxB/o6nGmZ9rocveeFUVpIYO42c5w2ZWV7rKbEkSPWiv OqpAovmBXWEcjw5YuaItiL8/YtnT8GfXKcy9bHSZc1foysT/Sdj1bvkWrfhEoy3wpd0I y68vhPBVeQEDa8jqOJB4H2b62ErD2FPOETFtF4VowRboEkvdIuEMLMAKMOW2pLbTL1bL DfnfjxJdxUaB1ot4FdLjg0KsxYaNox9WgvhgWx4CGFm6ShWEibUGQDKNDSQgMA+rU/XT YuxQ== X-Forwarded-Encrypted: i=1; AJvYcCXeRYbVfsB8ULPJgHS3sRmNqnajBVZtYy2HvC5pZXxNQIUkSk1BW8hncfw831oZeSn8di0NBwgMrO4cGaxNHUEi90ywuCw= X-Gm-Message-State: AOJu0YytWSEg+2UN/1GSE30MYdZie2gvolgtIN4zO7tegVMxSw9Tpbql wAaunuSu/mwwjpwwdZnA4uTtRNu6zX2A7F9ilVGfzSNfY48VkSK/NW+zx6gkIPA= X-Google-Smtp-Source: AGHT+IGViUo8qyT0MguJlDC6CdWNrZuARrlncVaSm2N8N02GKmAyc8JrY2Bo1Y1nUl0KqrO1A537Hw== X-Received: by 2002:a05:6a21:3183:b0:1a1:1f7b:9b0f with SMTP id za3-20020a056a21318300b001a11f7b9b0fmr96768pzb.42.1709146313210; Wed, 28 Feb 2024 10:51:53 -0800 (PST) From: Atish Patra To: Cc: Atish Patra , Daniel Henrique Barboza , Alistair Francis , Bin Meng , Liu Zhiwei , Palmer Dabbelt , qemu-devel@nongnu.org, qemu-riscv@nongnu.org, Weiwei Li , kaiwenxue1@gmail.com Subject: [PATCH v5 4/5] target/riscv: Add cycle & instret privilege mode filtering support Date: Wed, 28 Feb 2024 10:51:15 -0800 Message-Id: <20240228185116.1321730-5-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228185116.1321730-1-atishp@rivosinc.com> References: <20240228185116.1321730-1-atishp@rivosinc.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::42f; envelope-from=atishp@rivosinc.com; helo=mail-pf1-x42f.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, 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 @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709146359677100003 Content-Type: text/plain; charset="utf-8" From: Kaiwen Xue QEMU only calculates dummy cycles and instructions, so there is no actual means to stop the icount in QEMU. Hence this patch merely adds the functionality of accessing the cfg registers, and cause no actual effects on the counting of cycle and instret counters. Signed-off-by: Atish Patra Reviewed-by: Daniel Henrique Barboza Signed-off-by: Kaiwen Xue --- target/riscv/csr.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index a3d979c4c72c..ff9bac537593 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -236,6 +236,24 @@ static RISCVException sscofpmf_32(CPURISCVState *env, = int csrno) return sscofpmf(env, csrno); } =20 +static RISCVException smcntrpmf(CPURISCVState *env, int csrno) +{ + if (!riscv_cpu_cfg(env)->ext_smcntrpmf) { + return RISCV_EXCP_ILLEGAL_INST; + } + + return RISCV_EXCP_NONE; +} + +static RISCVException smcntrpmf_32(CPURISCVState *env, int csrno) +{ + if (riscv_cpu_mxl(env) !=3D MXL_RV32) { + return RISCV_EXCP_ILLEGAL_INST; + } + + return smcntrpmf(env, csrno); +} + static RISCVException any(CPURISCVState *env, int csrno) { return RISCV_EXCP_NONE; @@ -826,6 +844,62 @@ static RISCVException read_hpmcounterh(CPURISCVState *= env, int csrno, =20 #else /* CONFIG_USER_ONLY */ =20 +static RISCVException read_mcyclecfg(CPURISCVState *env, int csrno, + target_ulong *val) +{ + *val =3D env->mcyclecfg; + return RISCV_EXCP_NONE; +} + +static RISCVException write_mcyclecfg(CPURISCVState *env, int csrno, + target_ulong val) +{ + env->mcyclecfg =3D val; + return RISCV_EXCP_NONE; +} + +static RISCVException read_mcyclecfgh(CPURISCVState *env, int csrno, + target_ulong *val) +{ + *val =3D env->mcyclecfgh; + return RISCV_EXCP_NONE; +} + +static RISCVException write_mcyclecfgh(CPURISCVState *env, int csrno, + target_ulong val) +{ + env->mcyclecfgh =3D val; + return RISCV_EXCP_NONE; +} + +static RISCVException read_minstretcfg(CPURISCVState *env, int csrno, + target_ulong *val) +{ + *val =3D env->minstretcfg; + return RISCV_EXCP_NONE; +} + +static RISCVException write_minstretcfg(CPURISCVState *env, int csrno, + target_ulong val) +{ + env->minstretcfg =3D val; + return RISCV_EXCP_NONE; +} + +static RISCVException read_minstretcfgh(CPURISCVState *env, int csrno, + target_ulong *val) +{ + *val =3D env->minstretcfgh; + return RISCV_EXCP_NONE; +} + +static RISCVException write_minstretcfgh(CPURISCVState *env, int csrno, + target_ulong val) +{ + env->minstretcfgh =3D val; + return RISCV_EXCP_NONE; +} + static RISCVException read_mhpmevent(CPURISCVState *env, int csrno, target_ulong *val) { @@ -4985,6 +5059,13 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { write_mcountinhibit, .min_priv_ver =3D PRIV_VERSION_1_11_0 }, =20 + [CSR_MCYCLECFG] =3D { "mcyclecfg", smcntrpmf, read_mcyclecfg, + write_mcyclecfg, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_MINSTRETCFG] =3D { "minstretcfg", smcntrpmf, read_minstretcfg, + write_minstretcfg, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_MHPMEVENT3] =3D { "mhpmevent3", any, read_mhpmevent, write_mhpmevent }, [CSR_MHPMEVENT4] =3D { "mhpmevent4", any, read_mhpmevent, @@ -5044,6 +5125,13 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_MHPMEVENT31] =3D { "mhpmevent31", any, read_mhpmevent, write_mhpmevent }, =20 + [CSR_MCYCLECFGH] =3D { "mcyclecfgh", smcntrpmf_32, read_mcyclecf= gh, + write_mcyclecfgh, + .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, + [CSR_MINSTRETCFGH] =3D { "minstretcfgh", smcntrpmf_32, read_minstret= cfgh, + write_minstretcfgh, + .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, + [CSR_MHPMEVENT3H] =3D { "mhpmevent3h", sscofpmf_32, read_mhpmev= enth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, --=20 2.34.1