From nobody Wed Mar 5 02:08:54 2025 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F48A22F3BC for ; Thu, 6 Feb 2025 07:23:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738826622; cv=none; b=UJVa45SadKHIAtO6EUbtZhLoIXbpPExlsBIvl0O8ZQ88uamjFqRmIaehn01M5pedLyMCVDFKRDKaWZEJo2ME4XtsazORXZmtl/bvu5+++8mdElqf/vj1Y6hLsl8EGUK+6SUn2QsYnBLmTr8XWSjLZOKmhXl8c9hRGCgoPPuDadQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738826622; c=relaxed/simple; bh=5pQU73YVC2BHWefCjWg3jVhPGLfz1UhgII0sPsu1PmQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FWI3aeOgV7zQlRMmNRus9w7ssMiI8W595Oh5YWxJIc0ZqgCzt0pAgq8EGX9bJTXeZhTe8OuewSbKp/CLZbJPuWoBwx7lF6ejA2zyUSZYyNwdYtlyOy8J4aCCCD9uZu6O2H+nOVlU8yehEQaRmmTEtRm4bTn95eK9g2LxtDoIxig= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=DwH4BTTT; arc=none smtp.client-ip=209.85.216.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="DwH4BTTT" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2f43d17b0e3so988500a91.0 for ; Wed, 05 Feb 2025 23:23:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1738826620; x=1739431420; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=YQ1bM+mdYO24XpbpY93Gza0u/hfSg2U52kt5rlPb2uw=; b=DwH4BTTTfB97psACzZZLJ4kL41CvAHVcTCNrB6muvDLq6DufiNZl/u9Vf0Pki9GsPs mNEbzZ+5x8fk93jAKDn/EZfyfwodGXb/KmUKeWqEOjDbc+1+KLVWkAR5TC1lkc2rkMJG /UGFPIMpxzKHlJDgR37tQxGPjj4DFGUeOd9r6roDMRDfZC1Jiv9vspSF8EBBu7bksHFA gY4deOt6OVs7s19VlEhkxTRILYyQjGM9W7dbuhGNE7Kc2XCDRqrhoWnMGHYhD85VfbUW hu+1gtbO3PZQ6LtteSRbZ17OkHjpxMwZKszdLSVKWAKnj3Q++36DrS8WS5EeigJgp8Xf LFIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738826620; x=1739431420; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YQ1bM+mdYO24XpbpY93Gza0u/hfSg2U52kt5rlPb2uw=; b=EMH48pifbssxrefXcFm41mTzavg6ZK7HbOkg63+sjUJ+a+KQx2hIQLZ2mbGN1192mQ 2no3I2CAQdMSsN2n57nAo+lmq9h9q/v0yX0da2nqe38wDlJd8+0qCRiwVFaL4YGRdfCk YA0bo6Dd+1nqhwodlky1P6ilk5GIEI7X5n7j6+ZZADnv69domPiN3pdp0eMXFmVi/srM Ol50ImkkTLqI3Do52oOJ/yd0jm3T0iwtPNmkc58h6B3tRnGyjo7AAbrV+S3C31YvApAS eY/cLb6K+8ez/2VDkxy0oi5vTztXKtqhah6YlkWKuF7mWrD8NsOjfHZ4PzjJmRoElE+V A8Ww== X-Forwarded-Encrypted: i=1; AJvYcCXJRZJ1mWg5/6GmGlj9YELsEhr/hJjtW1I3w0jt4lf3zadxI7fqSQ+S1O5sBQbzsyh1VEYjU+G95k9qves=@vger.kernel.org X-Gm-Message-State: AOJu0YxxiqYtfgwp4KftSNJ42P5bR3zd93Key97+OtDlU4Un2eVfR6Pc UQjS7DDL+FOjJoMQWi2s5IMxBrWuy/t8OLLz9kk44BccdQxnfLkZHVVOEoOlXyE= X-Gm-Gg: ASbGncscoPCcRrrNS2kakRHSyieAOhtxu+gaidtAGhOXO2sBlrx0qoshrE3vpuCfw9k yzRhHZlkVwrqECfHXBvuBIq9mjGsw7NQakQh0s2Yn6ykHj46pSwbQgsX//9S5g1u9633bBkCMwo SrHgYCoUlkXE3wFel14Smpp6d+TQDkFdZC+BYKVmC9x7fmy7m52wjGwY0mXMSPBDocy2yXfEQn1 OL7k/VFw/EiKI0kq0GsS6o5317vIKi1EdxdoukTsFAR6SETLYJ3ARCEZLxq778dk7OLwThvoya0 TnWNka2nY09B8M4pz9I1mMdnHr0O X-Google-Smtp-Source: AGHT+IHr3HVst/0GQEzeOnoyNAyzJUxG9J5qyTanVRpVP7lxbmu+OPESYtyRFZuabnz8KqnI9biZIQ== X-Received: by 2002:a17:90b:4c43:b0:2ee:fdf3:390d with SMTP id 98e67ed59e1d1-2f9e084fcc0mr8578133a91.31.1738826619909; Wed, 05 Feb 2025 23:23:39 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2fa09a72292sm630883a91.27.2025.02.05.23.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2025 23:23:39 -0800 (PST) From: Atish Patra Date: Wed, 05 Feb 2025 23:23:20 -0800 Subject: [PATCH v4 15/21] RISC-V: perf: Skip PMU SBI extension when not implemented Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250205-counter_delegation-v4-15-835cfa88e3b1@rivosinc.com> References: <20250205-counter_delegation-v4-0-835cfa88e3b1@rivosinc.com> In-Reply-To: <20250205-counter_delegation-v4-0-835cfa88e3b1@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Anup Patel , Atish Patra , Will Deacon , Mark Rutland , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , weilin.wang@intel.com Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Conor Dooley , devicetree@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, Atish Patra , Charlie Jenkins X-Mailer: b4 0.15-dev-13183 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_dev.c | 46 ++++++++++++++++++++++++++--------------= ---- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/drivers/perf/riscv_pmu_dev.c b/drivers/perf/riscv_pmu_dev.c index 5112049b491c..219f65eb167c 100644 --- a/drivers/perf/riscv_pmu_dev.c +++ b/drivers/perf/riscv_pmu_dev.c @@ -410,18 +410,22 @@ static void rvpmu_sbi_check_event(struct sbi_pmu_even= t_data *edata) } } =20 -static void rvpmu_sbi_check_std_events(struct work_struct *work) +static void rvpmu_check_std_events(struct work_struct *work) { - for (int i =3D 0; i < ARRAY_SIZE(pmu_hw_event_sbi_map); i++) - rvpmu_sbi_check_event(&pmu_hw_event_sbi_map[i]); - - for (int i =3D 0; i < ARRAY_SIZE(pmu_cache_event_sbi_map); i++) - for (int j =3D 0; j < ARRAY_SIZE(pmu_cache_event_sbi_map[i]); j++) - for (int k =3D 0; k < ARRAY_SIZE(pmu_cache_event_sbi_map[i][j]); k++) - rvpmu_sbi_check_event(&pmu_cache_event_sbi_map[i][j][k]); + if (riscv_pmu_sbi_available()) { + for (int i =3D 0; i < ARRAY_SIZE(pmu_hw_event_sbi_map); i++) + rvpmu_sbi_check_event(&pmu_hw_event_sbi_map[i]); + + for (int i =3D 0; i < ARRAY_SIZE(pmu_cache_event_sbi_map); i++) + for (int j =3D 0; j < ARRAY_SIZE(pmu_cache_event_sbi_map[i]); j++) + for (int k =3D 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_err, "Boot time config matching not required for s= mcdeleg\n"); + } } =20 -static DECLARE_WORK(check_std_events_work, rvpmu_sbi_check_std_events); +static DECLARE_WORK(check_std_events_work, rvpmu_check_std_events); =20 static ssize_t rvpmu_format_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -549,6 +553,9 @@ static int rvpmu_sbi_ctr_get_idx(struct perf_event *eve= nt) =20 cflags =3D rvpmu_sbi_get_filter_flags(event); =20 + 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 @@ -562,10 +569,9 @@ static int rvpmu_sbi_ctr_get_idx(struct perf_event *ev= ent) cflags |=3D SBI_PMU_CFG_FLAG_SKIP_MATCH; ctr_mask =3D BIT(CSR_INSTRET - CSR_CYCLE); } - } - - if (pmu_sbi_is_fw_event(event) && cdeleg_available) + } else if (pmu_sbi_is_fw_event(event) && cdeleg_available) { ctr_mask =3D firmware_cmask; + } =20 /* retrieve the available counter index */ #if defined(CONFIG_32BIT) @@ -871,7 +877,7 @@ static u64 rvpmu_ctr_read(struct perf_event *event) return val; } =20 - if (pmu_sbi_is_fw_event(event)) { + if (pmu_sbi_is_fw_event(event) && riscv_pmu_sbi_available()) { ret =3D sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_FW_READ, hwc->idx, 0, 0, 0, 0, 0); if (ret.error) @@ -1940,14 +1946,16 @@ static int __init rvpmu_devinit(void) int ret; struct platform_device *pdev; =20 - if (sbi_spec_version >=3D sbi_mk_version(0, 3) && - sbi_probe_extension(SBI_EXT_PMU)) { - static_branch_enable(&riscv_pmu_sbi_available); - sbi_available =3D true; + if (sbi_probe_extension(SBI_EXT_PMU)) { + if (sbi_spec_version >=3D sbi_mk_version(0, 3)) { + static_branch_enable(&riscv_pmu_sbi_available); + sbi_available =3D true; + } + + if (sbi_spec_version >=3D sbi_mk_version(2, 0)) + sbi_v2_available =3D true; } =20 - if (sbi_spec_version >=3D sbi_mk_version(2, 0)) - sbi_v2_available =3D true; /* * We need all three extensions to be present to access the counters * in S-mode via Supervisor Counter delegation. --=20 2.43.0