From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 35421C43458 for ; Wed, 1 Jul 2026 08:48:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=2exj47iWI8m59zE0VktO/cVpTYfa8tTYnWLe+Y16FOA=; b=gxGXhpMeJ4eoLYynTk5Mg25Ttl eqWyphbE0h//MP4ceYXAS5PoM03YS+0w/FhBXm+o61RtK7vc6loz9NIGaZ01PHAGEe4sRSfVjfPVH 4/uYM97dlXNJ+N27LTwsmhTKMMtZlpEt1vW7n52v3jxPAKGv0/wStixkig8pNfT4g6kV+DmaazmgT EQtME1nDMofo3RGQjNqpmRyS0sQ3MGxnvvAs2OnUOM2z291Z5XuFFcAIk0A8QasU7kSJh3dx5tQe8 tywjIRxzyXGVb9N29uegl4q5a+sRlePhPBQ6N/pbNr54BqLD2yGEBg1mmherlkKWA+IgGJf63ghY6 qROPMw2Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1weqch-000000015hQ-1qFD; Wed, 01 Jul 2026 08:48:47 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1weqcg-000000015fL-39ID for linux-arm-kernel@bombadil.infradead.org; Wed, 01 Jul 2026 08:48:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=2exj47iWI8m59zE0VktO/cVpTYfa8tTYnWLe+Y16FOA=; b=Bfw9ktRkwGR4n0Qs4JJy5zroVQ MescPypusemCMAjioeiUeXBNjULGWSqxKgzqwy8bEgAYgignSaC6BXxNvMthUHA4ginvxh1A2pNwi E6fMNdg2jtJ5py0EEh9yHtT8hND5WUK9M++SIakyu+pkKJvskSEY5t3r+daLPrZA+RY2hD550bszG KL4ITXLizRCpOxkHZDQX5QWk/X6RwQSEk0ZNs6wJc3SWu+Y/osztsqYXhSOC4EgMC27qJ+kbUHpYG lvoWouiHMkwFMtBksFSPf8WRCJfx19VNHhYQ36BfZiK3TtvJCc2O5RJDcPCOdfYWNVkqoOt5hayyD axI1lUVQ==; Received: from out-183.mta1.migadu.com ([2001:41d0:203:375::b7]) by desiato.infradead.org with esmtps (Exim 4.99.2 #2 (Red Hat Linux)) id 1weqcb-00000002Wqq-2TDa for linux-arm-kernel@lists.infradead.org; Wed, 01 Jul 2026 08:48:45 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1782895720; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2exj47iWI8m59zE0VktO/cVpTYfa8tTYnWLe+Y16FOA=; b=XnPNVO83CvB8pqol+h3agWAEzUMnVIbjNbjLQkY8J3Es/yt6a2KoNAeFQHckgw8kMGZPGp VJzkif3pNZlXews/KdijZngTSCNV0r4mdke3GZADTzr0qCC7bUd5K3tRQNWWMsiii5Tzzx G6j63yShnMRlbojIvX/Q51LrGSwfXl0= From: Atish Patra Date: Wed, 01 Jul 2026 01:47:03 -0700 Subject: [PATCH v8 15/22] RISC-V: perf: Skip PMU SBI extension when not implemented MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260701-counter_delegation-v8-15-7909f863a645@meta.com> References: <20260701-counter_delegation-v8-0-7909f863a645@meta.com> In-Reply-To: <20260701-counter_delegation-v8-0-7909f863a645@meta.com> To: Jiri Olsa , Paul Walmsley , Mark Rutland , Rob Herring , Anup Patel , Namhyung Kim , Arnaldo Carvalho de Melo , Krzysztof Kozlowski , Atish Patra , Ian Rogers , Will Deacon , James Clark Cc: linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-perf-users@vger.kernel.org, Conor Dooley X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260701_094841_938257_CACEBE51 X-CRM114-Status: GOOD ( 16.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Charlie Jenkins When the PMU SBI extension is not implemented, sbi_v2_available should not be set to true. The SBI implementation for counter config matching and firmware counter read should also be skipped when the SBI extension is not implemented. Signed-off-by: Atish Patra Signed-off-by: Charlie Jenkins --- drivers/perf/riscv_pmu_sbi.c | 49 ++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 7995da4a98a1..fcf8fbb6fd86 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -495,27 +495,32 @@ static void rvpmu_sbi_check_event(struct sbi_pmu_event_data *edata) } } -static void rvpmu_sbi_check_std_events(struct work_struct *work) +static void rvpmu_check_std_events(struct work_struct *work) { int ret; - if (sbi_v3_available) { - ret = pmu_sbi_check_event_info(); - if (ret) - pr_err("pmu_sbi_check_event_info failed with error %d\n", ret); - return; - } + if (riscv_pmu_sbi_available()) { + if (sbi_v3_available) { + ret = pmu_sbi_check_event_info(); + if (ret) + pr_err("pmu_sbi_check_event_info failed with error %d\n", ret); + return; + } - for (int i = 0; i < ARRAY_SIZE(pmu_hw_event_sbi_map); i++) - rvpmu_sbi_check_event(&pmu_hw_event_sbi_map[i]); + for (int i = 0; i < ARRAY_SIZE(pmu_hw_event_sbi_map); i++) + rvpmu_sbi_check_event(&pmu_hw_event_sbi_map[i]); - for (int i = 0; i < ARRAY_SIZE(pmu_cache_event_sbi_map); i++) - for (int j = 0; j < ARRAY_SIZE(pmu_cache_event_sbi_map[i]); j++) - for (int k = 0; k < ARRAY_SIZE(pmu_cache_event_sbi_map[i][j]); k++) - rvpmu_sbi_check_event(&pmu_cache_event_sbi_map[i][j][k]); + for (int i = 0; i < ARRAY_SIZE(pmu_cache_event_sbi_map); i++) + for (int j = 0; j < ARRAY_SIZE(pmu_cache_event_sbi_map[i]); j++) + for (int k = 0; k < ARRAY_SIZE(pmu_cache_event_sbi_map[i][j]); k++) + rvpmu_sbi_check_event(&pmu_cache_event_sbi_map[i][j][k]); + } else { + DO_ONCE_LITE_IF(1, pr_info, + "Boot time config matching not required for smcdeleg\n"); + } } -static DECLARE_WORK(check_std_events_work, rvpmu_sbi_check_std_events); +static DECLARE_WORK(check_std_events_work, rvpmu_check_std_events); static ssize_t rvpmu_format_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -708,6 +713,9 @@ static int rvpmu_sbi_ctr_get_idx(struct perf_event *event) cflags = rvpmu_sbi_get_filter_flags(event); + if (!riscv_pmu_sbi_available()) + return -ENOENT; + /* * In legacy mode, we have to force the fixed counters for those events * but not in the user access mode as we want to use the other counters @@ -985,7 +993,7 @@ static u64 rvpmu_ctr_read(struct perf_event *event) return val; } - if (pmu_sbi_is_fw_event(event)) { + if (pmu_sbi_is_fw_event(event) && riscv_pmu_sbi_available()) { ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_FW_READ, hwc->idx, 0, 0, 0, 0, 0); if (ret.error) @@ -2094,12 +2102,13 @@ static int __init rvpmu_devinit(void) int ret; struct platform_device *pdev; - if (sbi_spec_version >= sbi_mk_version(0, 3) && - sbi_probe_extension(SBI_EXT_PMU)) - static_branch_enable(&riscv_pmu_sbi_available); + if (sbi_probe_extension(SBI_EXT_PMU)) { + if (sbi_spec_version >= sbi_mk_version(0, 3)) + static_branch_enable(&riscv_pmu_sbi_available); + if (sbi_spec_version >= sbi_mk_version(2, 0)) + sbi_v2_available = true; + } - if (sbi_spec_version >= sbi_mk_version(2, 0)) - sbi_v2_available = true; /* * We need all three extensions to be present to access the counters * in S-mode via Supervisor Counter delegation. -- 2.53.0-Meta