Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2424978ioo; Mon, 23 May 2022 19:09:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyT4pLWFErR3Va/ASleey0sKUyfFncyCSJ9ALQTMVhkbc/sredKFQXEa+mAvU8v7h8Lzxuh X-Received: by 2002:a17:902:e841:b0:162:48cc:fd83 with SMTP id t1-20020a170902e84100b0016248ccfd83mr11866plg.163.1653358154201; Mon, 23 May 2022 19:09:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653358154; cv=none; d=google.com; s=arc-20160816; b=A1UWAFMrPcRSRNiNnYcl7ePO1RJO6Ia/h96W2PHYIO1GGozRPDOERHjtbOyH3vnrBS HoN+NzbJEeLBLJhafQtFyT9G15r4M5hBsWaQ0XVPkZmoXjrwYA785EIpjSyPbyMjFuP/ ujnl/sz8YFZYDqXAtGB0Zqum4alhFvy6TJKWnSrYgLHzg98ZUoFPrmQFH4gogDSeivo2 hI4F00NpRjvuXI83b95cV4Jzyh+lMsYgi4+4R5i5Ao5qXQwv1Dw3ppHpwZPH/aW0drMr pWaATmkQLOrxnIdm5d0NsvmMjFgaEMC4IvxZhXEVCbWo0oLa3E21lrr/sWAiq0wPdVWe jUWg== 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=zBLmmput+KXdegWc4QMnBp9iZpEyw6fPZcdYbjC97v1IWxoE9tsTTD/dV9HznHgXBR rYBtYotu8hWW94OpTI1avrvv6SlcruntT59Y4gP8DLK8gLR93mPh2jWOXNdMJ0nVr1/o vMryrKlsq1aOcH53KVvt2elm6rSwLZyF0VR82+gD+S+8uZDUtLINP7F2bofMsip8MZYR T7MLdl1NtUQIzJcC/J7P0ghGMxsZ93cUNBbzsoZXX0PTzyRT2gejQ5t7ukquzyCQpWo4 VwVRU22XGoXD5UKaKEjp59qTP2qtwhE68dm1vCW28PJPe4fv2/d5FMrTLdMuIslWG3vH OgLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=1Bbfnz2C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k1-20020a170902ce0100b00156b46e2407si12865139plg.471.2022.05.23.19.09.02; Mon, 23 May 2022 19:09:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=1Bbfnz2C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231294AbiEWXvo (ORCPT + 99 others); Mon, 23 May 2022 19:51:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230379AbiEWXva (ORCPT ); Mon, 23 May 2022 19:51:30 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 306004EA00 for ; Mon, 23 May 2022 16:51:29 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id i1so14434735plg.7 for ; Mon, 23 May 2022 16:51:29 -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=1Bbfnz2CEe3CP9LuZgH+Yi1fosFu5sP9Wokpgm4F8+Wl9npqToJoqlWYHB2GNrs2qx rlppxfa2xd3Qd9AjvKs+mgZpfPqlNuXBfcrTuvxBRJHcZgOgCi7W88DYelz9vIsKQ8ly FnRw1ZnbOobOuwdNsFSuy3GDQgEot5lnQqU81hduACOaAnFAR4bJ+iLBiyoaqUWX8PDd tl2Npwks1KsQ3V/+E82XsiXfKk32h0LPfXIQ5d/fwTftR/XFPQHhbavNHKxnWeAco6OW l6OQARpN/P0NJ3DBXgyUR6b40b30+NDHtST9M7jU2eloJxdPLbIebTHeen03ZC2PD9SJ PzvQ== 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=WtQklHRSiY5vRtzi+DcaHn90aRb12XkYXuzbWtuYSJ1WUr+QEnuMkFDfQEbH8ew/SO 0M87DWTSnqrqTD98sr/EqF8z85gjhOSapgsZsGu8OHOLvoVndQT+MrLrP5tRXSwMWWbY BdssFP1F/poNI9dLPXLkaaI9F0UcTtzwYMlKnSgo1iOrdut0x4+PuTaspETTozNJwEUB l7J99qdP8hsSApsIMYOYo5fwDc1AXMjkA93uUz25FeCGw0zQ1L7TL3eob61Wi2T2N6M3 HMKeFyon5NJf67wK5iBFQOgCvAprbThe6W6n1Jp0hFC3dDrGmKZx1pEoPhObAWtrcgkS QF/A== X-Gm-Message-State: AOAM532um8LyPexUYhZbXrF0iJtiH0kmUkp9uLT3vn1ANbSDo7PRF/AJ 4icvNmJGPGIzQmqrStSjNDUo5jO+BmKy5A== X-Received: by 2002:a17:90b:391:b0:1df:42e2:ae17 with SMTP id ga17-20020a17090b039100b001df42e2ae17mr1543973pjb.198.1653349888392; Mon, 23 May 2022 16:51:28 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id pl15-20020a17090b268f00b001df4b919937sm257084pjb.16.2022.05.23.16.51.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 16:51:27 -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 v9 02/12] target/riscv: Implement PMU CSR predicate function for S-mode Date: Mon, 23 May 2022 16:50:47 -0700 Message-Id: <20220523235057.123882-3-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220523235057.123882-1-atishp@rivosinc.com> References: <20220523235057.123882-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,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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