From patchwork Mon Mar 20 10:09:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 1758916 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=f6Oj+iGq; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20210112.gappssmtp.com header.i=@rivosinc-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=L4pmH4gm; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pg9Tx5pwlz246f for ; Mon, 20 Mar 2023 21:10:29 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Hd12YeeYTCHNfpxIqcISdzxi5P6neBu8juuuhyeSifc=; b=f6Oj+iGqaRv80j ar/IDPEarE5ADW9yzVk0FzO/RdTCL49w6lx0WHy6NiZX1EAC2JQBS+9Sfph2Z9zEgcU1H6VgY0fp4 qKh2qg7g3ne0G/1recAmBmCyGuwQNKbc4+UVg0kN/eRTd7NhsrwSLRgWf8mRKy6WWHR8mFWqCAcET 40u/GQiDGpCKE017FqnCFSypzT+0bBT33fSmWVxKCt0g/osHhbnvJDtZlpKsBKI3xvLU3owRtNiHN ZZR+K57T6DWdqIU+i3frjGoRwgtsJ6/rMajL7fyOT+C/VHBb7b8KkBydt2rIH7EyOn3tsJfehcVAx 2g8cGsNIKM6PTpv2O1Yw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1peCSt-008aAV-2L; Mon, 20 Mar 2023 10:10:07 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1peCSq-008a9P-2h for opensbi@lists.infradead.org; Mon, 20 Mar 2023 10:10:06 +0000 Received: by mail-wr1-x42d.google.com with SMTP id v1so3644907wrv.1 for ; Mon, 20 Mar 2023 03:10:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1679307000; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=DYrdeT5//0r+Xune6fgXtNtOTV+ckFVn9cAIuykpB0s=; b=L4pmH4gmYGEnFl44+Z6dnaLxG25sz5WYDjDizcs4nEuFH2qf/msL2ErE4r9/DwZGZv 9jKgrFRQzCSelbY3cBBWf/qq3Qi1TM/n6o8+q8Ge7HgkaHxIDmvGAUkWq5g5WfcZcsE8 FQfPfEsAmg8yDhcN8WTTrnLMStLKHX9Vcs+ccleYi1AcLR/GwOUsOQkE5A9mbEODcdhl 74cBvk64KtMPs+i8/Mf+YWQFKAlPu/PL1bfCPB99BdSTvXN2Ov/so0DbN2sxOKSn7m4J KbEDBTfDPMDvGaHVMGpGjyqFzzkrRcW11lfxmKBSHjcJ94ubd20nUg24MKP0GKsPr+W6 06sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679307000; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DYrdeT5//0r+Xune6fgXtNtOTV+ckFVn9cAIuykpB0s=; b=iJ/yHuio2rYlqMA0/hVBVHI8Fl9zkCKuFgT/gPb6dksauH4tUkWyxvBvMmtn+Bj5Iz M16YhFyxUBcoKdfoAu/y8sQ2AgaVZ3NTg39oW4DRN+10FCCRc/soqSG6KfbgJmdNp91d h5ztWFhG58N4CNjifZZPPEGv5HcKOfDB/qsl3orbXJ1TNyd1nBydPASmiXy192EARwQh nL2eihF5RsAmHDWUVnn2PhDC+7BiNlJprMxZDhDet8J4xOOjzkFK60Fk/qM1j5pBRu3H KRvfBUYxP2O0UDS62gCVKs2gfQZQaAgvQJ4Tmgy8Caj8SO1Q1+M3wGT+WdKE0lLvU5VP Uyug== X-Gm-Message-State: AO0yUKW9kX2wCaskUX7yISvclUdfC9+BN7RJoMtNw/N67gdR0g0ey2qi zVmImSqRJEwmwBgAHVgp0oT190OtY5s8MNpYZSc= X-Google-Smtp-Source: AK7set/Tdgu8C7or4W9Yke95vOcXF3FPbq7j96/d7jYfQQyh7e0MX2EaynG5jGBmjD5VoEDAPdJOgQ== X-Received: by 2002:a5d:6a83:0:b0:2cf:ea3a:2b9e with SMTP id s3-20020a5d6a83000000b002cfea3a2b9emr14434340wru.43.1679307000431; Mon, 20 Mar 2023 03:10:00 -0700 (PDT) Received: from alex-rivos.home (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id v7-20020a5d4b07000000b002c56af32e8csm8455881wrq.35.2023.03.20.03.09.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 03:10:00 -0700 (PDT) From: Alexandre Ghiti To: opensbi@lists.infradead.org Cc: Alexandre Ghiti Subject: [PATCH 1/2] lib: sbi: Do not clear active_events for cycle/instret when stopping Date: Mon, 20 Mar 2023 11:09:57 +0100 Message-Id: <20230320100958.16831-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230320_031005_111929_31977A7E X-CRM114-Status: GOOD ( 10.39 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Those events are enabled by default and should not be reset afterwards since when using SBI_PMU_CFG_FLAG_SKIP_MATCH, it leads to unaccessible counters after the first use. Signed-off-by: Alexandre Ghiti --- lib/sbi/sbi_pmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:42d listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Those events are enabled by default and should not be reset afterwards since when using SBI_PMU_CFG_FLAG_SKIP_MATCH, it leads to unaccessible counters after the first use. Signed-off-by: Alexandre Ghiti Reviewed-by: Atish Patra --- lib/sbi/sbi_pmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c index 74d6912..2176cc7 100644 --- a/lib/sbi/sbi_pmu.c +++ b/lib/sbi/sbi_pmu.c @@ -531,7 +531,7 @@ int sbi_pmu_ctr_stop(unsigned long cbase, unsigned long cmask, else ret = pmu_ctr_stop_hw(cidx); - if (flag & SBI_PMU_STOP_FLAG_RESET) { + if (cidx > (CSR_INSTRET - CSR_CYCLE) && flag & SBI_PMU_STOP_FLAG_RESET) { active_events[hartid][cidx] = SBI_PMU_EVENT_IDX_INVALID; pmu_reset_hw_mhpmevent(cidx); } From patchwork Mon Mar 20 10:09:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 1758919 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=uYWRKluU; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20210112.gappssmtp.com header.i=@rivosinc-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=vod4fIVA; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pg9Vz5pHQz246f for ; Mon, 20 Mar 2023 21:11:23 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WR5DJR0476Fdu6S2C50pbazsOqVtKyQxGq2Nhkjok2U=; b=uYWRKluULc6i0f jP4A34F9IsB6Llx++0FK8kVjaGBlBEeCZoz+0tvXFLOnc/gbaV0Y7qiALPShtvGy0604Uc3kDcM4v lO12OXK+myeqXv1Ygb/KDTBS18Qz5l1XhgkPCaE+OWaXAA8GlF1YGZ5G7zz5PnT1/VBU0oyNBZb50 MlxNVGfz5ACZ2bBY6O/6jTEn0Uy/DFtu0gRmqQtSgIszEbPnf08bls/0NN0HTNhSqH43EVXH/fQDv g9rV6URkX9VgGtb2bvthYEdYgSNEfUZW0mNjxgwu1v3EAEOZN0EmKa+0dx/WEoQZnB9wb7pOcSp/w 6XBWeLSzO379tbX4PNiA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1peCTq-008aJZ-28; Mon, 20 Mar 2023 10:11:06 +0000 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1peCTo-008aIp-0s for opensbi@lists.infradead.org; Mon, 20 Mar 2023 10:11:05 +0000 Received: by mail-wr1-x42f.google.com with SMTP id d17so1323914wrb.11 for ; Mon, 20 Mar 2023 03:11:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1679307062; 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=fLdPekMMLA6aAa9OzTzOg6cDJ8E2UkUFTf/ruNkebDM=; b=vod4fIVAAODzrb/6+dKf3Oq8iPc1VEaIllB0RipRU3+tSpBYdKbv5QIWWZjcBKEM0z oGodrBCtsMiWKcKUkm3zxncdGm7SrBkMEjKh6CwrWylMziib6AfJE4fkgDS/x7gXeDTx m35mJcLoAfwwXKtfI9TOXvdP77nik5qG59/sBy1mEz1qHzwz/w44v0uxj9nDy64MAZCh p64a72KdGjpoN9omyQmvjkcu/XAMkS8oKv7GOcADfz5Z+GwFJ+UkJQANMu5c/Y5b1Fvo ZrerFpiAlh7xHwwFHU1jUf4Mbrdz4ZPIGJ+6hb7j6Niod3IXndQWNUSAkP7gW4cBO6De zljA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679307062; 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=fLdPekMMLA6aAa9OzTzOg6cDJ8E2UkUFTf/ruNkebDM=; b=ZZ9dAymiajQZabqIDq0wqIw9g0DdirDePx+Y0RsEUUEZK9W+9GGps6AadJA0B2FNDl OS2gVCTu2l5NU2CGmvaYmyWJynwKabK3E6wgUWJbUWlpJg7nxDTqodUKIw1+xyLAcZv6 rYwAK9kr6fhAeyeVEAHsmFIVa6prtzNPj1ZqJbBrz5oEHdGX0HEhx6O1ityw6Gp/Ondb drd13P2oNyVubJ9IAWOLei7+b7vs7KbuigiKiRqSDDm8MmUvaHVsTYauud4anNLdsL6b HbybPhHYqVefSeCPCA/hH1xR3nx6JYm5vJX4w77tD4l8OXYsfeZZMSmc05gC/n5Nwe3Z t3qA== X-Gm-Message-State: AO0yUKXCSBM4DYKZraoxOBvGgkzI0EptLLdoLERsPcONoS6GusLUOBBI /+cWrKHpei8GNrq9sFb1ny1OtnEVZOeh4kdrEqM= X-Google-Smtp-Source: AK7set/BETeAo1S8ufmTlkIwV7v3VQrKP3JFFf6GkIS+1jpttGrmirUJ71/6+U/ABrJkHeyuTXVQhw== X-Received: by 2002:a5d:6641:0:b0:2cf:ee25:18ce with SMTP id f1-20020a5d6641000000b002cfee2518cemr12030825wrw.27.1679307061214; Mon, 20 Mar 2023 03:11:01 -0700 (PDT) Received: from alex-rivos.home (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id y16-20020a5d4ad0000000b002d51d10a3fasm5230770wrs.55.2023.03.20.03.11.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 03:11:01 -0700 (PDT) From: Alexandre Ghiti To: opensbi@lists.infradead.org Cc: Alexandre Ghiti Subject: [PATCH 2/2] lib: sbi: Fix cidx_base check when SBI_PMU_CFG_FLAG_SKIP_MATCH is set Date: Mon, 20 Mar 2023 11:09:58 +0100 Message-Id: <20230320100958.16831-2-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230320100958.16831-1-alexghiti@rivosinc.com> References: <20230320100958.16831-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230320_031104_311338_DDE95D9D X-CRM114-Status: GOOD ( 11.10 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: When SBI_PMU_CFG_FLAG_SKIP_MATCH is set, cidx_base is used to represent the counter index to match, so make sure we don't return an error in this case. Signed-off-by: Alexandre Ghiti --- lib/sbi/sbi_pmu.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:42f listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org When SBI_PMU_CFG_FLAG_SKIP_MATCH is set, cidx_base is used to represent the counter index to match, so make sure we don't return an error in this case. Signed-off-by: Alexandre Ghiti --- lib/sbi/sbi_pmu.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c index 2176cc7..ffdbe65 100644 --- a/lib/sbi/sbi_pmu.c +++ b/lib/sbi/sbi_pmu.c @@ -722,8 +722,16 @@ int sbi_pmu_ctr_cfg_match(unsigned long cidx_base, unsigned long cidx_mask, u32 event_code, hartid = current_hartid(); int event_type; - /* Do a basic sanity check of counter base & mask */ - if ((cidx_base + sbi_fls(cidx_mask)) >= total_ctrs) + /* + * Do a basic sanity check of counter base & mask but not when + * flags has the skip match bit set since cidx_base has a + * different meaning there. + */ + if ((flags & SBI_PMU_CFG_FLAG_SKIP_MATCH) && cidx_base > total_ctrs) + return SBI_EINVAL; + + if (!(flags & SBI_PMU_CFG_FLAG_SKIP_MATCH) && + ((cidx_base + sbi_fls(cidx_mask)) >= total_ctrs)) return SBI_EINVAL; event_type = pmu_event_validate(event_idx, event_data);