Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp940583iob; Fri, 13 May 2022 17:11:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+CGmlfJsmuVVg5o9gPKvcny17JtHThwhgkuQmcaPijn9xlkW3/GKf+mt1Y/qqQ5FXf+97 X-Received: by 2002:adf:fa91:0:b0:20c:4fde:171e with SMTP id h17-20020adffa91000000b0020c4fde171emr5662801wrr.533.1652487064452; Fri, 13 May 2022 17:11:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652487064; cv=none; d=google.com; s=arc-20160816; b=iDEYmOPqXJLB1CiKGWREHZc8siH4yr/c/bMgWtZaOHdLVHod+eihsrTErRmDKQemw5 OmkY/H86f26V39CjZmRN9KITq19wQhqbhMj6NB7pW7PR4PqgHOVi+0ei50Hx6G5D2Hd5 +piilEQZVFPJIZLp4eldFsuseUJWEW4QAXD9fXMYyVP/Gzb9eHpyXI+LeTjs+V/WvD52 tFtWq+xfh460TtcRf5nGzhMMJb7vI7elSNRgn2nkfk2y3J5Myaq83khKG+/hixegKYKO p2VNcf3gNMXIsN25asGBTUm72KSWfXFaX+u983MbSd1rS2Sl3JJ2XxktKbFKHvXR265Q HxzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7AhCdNNL1uDdWvnH8n7UysRuRPz3w0BpqFn1GxNQ6wo=; b=F3ccEXhBsaT1A/bBbLtv3oiZ+Zdo765kXymYre0BU0rdrOCQTLDqRaGRf2xX24XTx6 +K8c4r1VQuUZqDyLbLsFvxWSHMQ/AvCSSzdK++8vg3QW/3cbNcYNJprVu/w/jzxtsFT3 vmdfOGKUVQlSO32z2U0ip7BqGhiQQV/yhhx4G0W9gdQTo424yZ4iCvXYxANHbFO32Rq0 TqvpD8zQC2UG3tFWELuZEziobPeHOn5p6TPIL0Dq+p28ZPIJMMjCoStFhv4ANCxc/4MG VOdVVzIwMnNYsGAGqtZeTa0rbryZ7fmSimTWeIuldTKZipTM+jua/DMzqo5lDGTsb2mr zxpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=fytPneEm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j25-20020a05600c1c1900b0038e79b62377si7573878wms.52.2022.05.13.17.11.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 17:11:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=fytPneEm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4FE232FCF04; Fri, 13 May 2022 16:12:34 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348467AbiEKWAY (ORCPT + 99 others); Wed, 11 May 2022 18:00:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348425AbiEKWAL (ORCPT ); Wed, 11 May 2022 18:00:11 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50DDA6F4AC for ; Wed, 11 May 2022 15:00:10 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id c1-20020a17090a558100b001dca2694f23so3215493pji.3 for ; Wed, 11 May 2022 15:00:10 -0700 (PDT) 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=7AhCdNNL1uDdWvnH8n7UysRuRPz3w0BpqFn1GxNQ6wo=; b=fytPneEmsny+Pj54XsjvH+yJyKiyIQXqjgxcMFBdfycFD7t0ELgrStCgfZhKF0iO55 LDrK5qUaSCFmzgdMPxAa0kf6Xthyw3EG5+R2Q+B1ERzA2JAIboEeJfDoKw4qGlv5eVgU LabepkR8cYWhInEcTPRbtB4d9xGeGcZrMSL5c5Zm9m3rjxc+QaylulqtTXmLxzKpBqgU fMoaOcCaAkAf1fxHTDT+QLLuIPhMkUQvRBxj8H6mjbE+IvU6rVbiOvhqesoHL+oEjYzp sXmZiV/X29rj4H46Ix4rZN2wctlsJMqhU1IFVVhv6Rxw4ks63A9c1ZTI8SgKKfHrlPjp fQSw== 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=7AhCdNNL1uDdWvnH8n7UysRuRPz3w0BpqFn1GxNQ6wo=; b=CGOeCFuxLaFMCExVKQAXmn2TzrLgECxUaJr2gjupUC8//iJXlQbaAIlCX5CkGpViBr N5coQ7r1EGxIIQpOC7SVKBx1ZmRYBNzGlmgi57KtGTjklEWCoPK3Nn4ciLvDGDgDWjFG gfHJTJ+xJ7Ks04LjT/euCItws/j3LUOK1AiHbMDqCyvtZAM8d2Ai/OJbwHX6VbW/FUyj a97q+Ce7LWRsHElHdJT7DgM0umBl7iMdCef6m/GAhIxyDxu5cPF7RJyd9L1OAqoCseRJ JO1aO+7NdZ6EUE5VKZswvlElCJJlmlGEOFqrgnOYuyvwkgQijqBqMlPY+vTQGJXFKd3s 9RHQ== X-Gm-Message-State: AOAM53028EwpvnPd6Cpd+ij7DjnuhJsFoHfeGZt2n4JkRoDmPCGRc0/b AF1CMSUUYGtzvgFpcu2fQyzRNzUWcoEdkQ== X-Received: by 2002:a17:90b:3e8b:b0:1dc:e471:1a69 with SMTP id rj11-20020a17090b3e8b00b001dce4711a69mr7517540pjb.60.1652306409472; Wed, 11 May 2022 15:00:09 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id r23-20020a62e417000000b0050dc762816asm2261303pfh.68.2022.05.11.15.00.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 15:00:08 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Alistair Francis , Bin Meng , Atish Patra , Bin Meng , Palmer Dabbelt , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v8 02/12] target/riscv: Implement PMU CSR predicate function for S-mode Date: Wed, 11 May 2022 14:59:46 -0700 Message-Id: <20220511215956.2351243-3-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220511215956.2351243-1-atishp@rivosinc.com> References: <20220511215956.2351243-1-atishp@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Atish Patra Currently, the predicate function for PMU related CSRs only works if virtualization is enabled. It also does not check mcounteren bits before before cycle/minstret/hpmcounterx access. Support supervisor mode access in the predicate function as well. Reviewed-by: Alistair Francis Reviewed-by: Bin Meng Signed-off-by: Atish Patra Signed-off-by: Atish Patra --- target/riscv/csr.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index ee3a35afa256..d175fe3f1af3 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -79,6 +79,57 @@ static RISCVException ctr(CPURISCVState *env, int csrno) return RISCV_EXCP_ILLEGAL_INST; } + if (env->priv == PRV_S) { + switch (csrno) { + case CSR_CYCLE: + if (!get_field(env->mcounteren, COUNTEREN_CY)) { + return RISCV_EXCP_ILLEGAL_INST; + } + break; + case CSR_TIME: + if (!get_field(env->mcounteren, COUNTEREN_TM)) { + return RISCV_EXCP_ILLEGAL_INST; + } + break; + case CSR_INSTRET: + if (!get_field(env->mcounteren, COUNTEREN_IR)) { + return RISCV_EXCP_ILLEGAL_INST; + } + break; + case CSR_HPMCOUNTER3...CSR_HPMCOUNTER31: + ctr_index = csrno - CSR_CYCLE; + if (!get_field(env->mcounteren, 1 << ctr_index)) { + return RISCV_EXCP_ILLEGAL_INST; + } + break; + } + if (riscv_cpu_mxl(env) == MXL_RV32) { + switch (csrno) { + case CSR_CYCLEH: + if (!get_field(env->mcounteren, COUNTEREN_CY)) { + return RISCV_EXCP_ILLEGAL_INST; + } + break; + case CSR_TIMEH: + if (!get_field(env->mcounteren, COUNTEREN_TM)) { + return RISCV_EXCP_ILLEGAL_INST; + } + break; + case CSR_INSTRETH: + if (!get_field(env->mcounteren, COUNTEREN_IR)) { + return RISCV_EXCP_ILLEGAL_INST; + } + break; + case CSR_HPMCOUNTER3H...CSR_HPMCOUNTER31H: + ctr_index = csrno - CSR_CYCLEH; + if (!get_field(env->mcounteren, 1 << ctr_index)) { + return RISCV_EXCP_ILLEGAL_INST; + } + break; + } + } + } + if (riscv_cpu_virt_enabled(env)) { switch (csrno) { case CSR_CYCLE: -- 2.25.1