From nobody Fri Dec 27 11:12:01 2024 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 41810380 for ; Tue, 10 Dec 2024 00:04:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733789095; cv=none; b=DEbJXiwWYcI76hD3V7f9mYoMw+fbklwc2HMHCTHH1eVn4bF0tb2xhGSnG++ZftYsQJbI0J3rzdw9Zt0gKf0ojlPVQyk9a+9EnqVGPsn96WQ4SZ0sOXB/QwjBs194vP0X1GswEbGt0F9Kavy0IUERMzMeDW7aU6/uP6/Lkwtv55Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733789095; c=relaxed/simple; bh=yh1WhPVHnUXGeUqDrFmWYHG3GtqtO4RO4NHAH/4shqA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=abBb3tt5CEJ8LRK3wE7R1lGW7/qZD0J36xSJ1snKeKgiEkUZ8/SWbDD5bbl51MA3EClRxY2/c0i4z1zLcqrYpC6sOQYb+4TVV8M0hCWCxPnLIsMfXg7xaXiayzZ96TJSZeFcdnDty6gF6G1+m+rUqs5/8z4RtZvR2up/+63zgBo= 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=Bn4bMMUY; arc=none smtp.client-ip=209.85.210.180 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="Bn4bMMUY" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-725e71a11f7so1299005b3a.1 for ; Mon, 09 Dec 2024 16:04:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1733789092; x=1734393892; 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=IcoCLi142uVK6LZxiJuwIjRZD/c9pyPS+Cs4D2LMz+8=; b=Bn4bMMUYVaBMr3V5c7AcrBw0PQ5w9OEJWeOC2PLPiMD5pvVZNw141vlQDE9YxEBsA1 dV5ZujCeDMFlMr2p+LOGhtD2MYeTgZE3Nmwz5AcvLZbRgqBkj5GuidPF+utVWvRiHfpA ltDsQgejC3d0Qm7QWwhRyEzD8kjJQ4J6YF1hDJy+r6uZqW53uTAWtIvn3Bdm+z5GmA5+ 2kw6AJuHRLaOFrckEPDrQUgZGhh/c9dlCRd0/tqkLYD0KRQ9N9GuxrKJcnlhV91d/rEJ uETe4VosnoMEjoeBwyn8+zcRTrOaPoMRGFcsUxztRPrLuFEZC1ZyeGNf6GjTguPZbbMb y9sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733789092; x=1734393892; 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=IcoCLi142uVK6LZxiJuwIjRZD/c9pyPS+Cs4D2LMz+8=; b=LJ8KjhBbhPk229w1a55cll/ZFKwh0ga3PvKb4V42Jr8x89UFcogzihHYjQqEADupWb fXo6ROKpVMYTaINy/qfIYYuu7RIG4955NKTjkNS/pyA9tXKK5SZGTT+l4R4ZjV5n7GPS 4krdPB/2hpYIEdpv5jzvF5ERql+gOmFSA3K5mlyMIXEst0r/TOBHOxIJBnTvvzPYSln2 HCDnWDOELC6v4kl/PK3pf8z1uIIrFH6AIo7CRTXdpxmMEZfKwfMi6QRMCyO0CvHD09qq xSfyshBHQXve87M+n4Rt1/jDfMd9FZXoB2YH4WIipbqfbqHUBWCPrwNdrefQBn0upoaA INFg== X-Forwarded-Encrypted: i=1; AJvYcCW7CTW5FF1FiZsLlqY5zCMUbF2TQvK2g0Ah1tCtStBd+QBOIQcuECgF5xDyVsTMhE5JqThFyvH2IJcGm+Y=@vger.kernel.org X-Gm-Message-State: AOJu0YwI4wa3Pt89glE5ETMfetL8zLN/eL0bG/6YVn2/ja3IiJAiuFG3 U/fm4xeOFqZKNwjEdIjmn6QTaAjMBYeqSASQnjnlZoslApAG0AJEqsO9AKul19vE/OoyzSQxK02 8 X-Gm-Gg: ASbGnctam/N7q/LqEJEvWBSX/2ne6Fc7F+JlZqlQO2M9I9HdBaJeO3I1fGWP4x3VieX KiREpVTCnlsqauREcyCQEBpJ+v39WfU3l0jpiZkYU3ZBn2W4M5/f00LcxeFoDAc3fC+LgSaDfeI 7UMatDsIhbCSJ8JSCNSR1fCiI785XnCOiwEqSu1yxrbE742fnYBS3wfoEQEkuweTAO+wCF2h61a fbLdhUKLxRSqnkmfDi9/E18ZitJYUUIvN0/kTARK12AHmWFxRwoy2OeyxRRNAVO4qU= X-Google-Smtp-Source: AGHT+IHtQv72nuw+PgMFj/lyteqN8ZPPPaSuF1PYTBDxNzcw7rsi++0gLI3vMd4O/SEk4kaL5+EgJA== X-Received: by 2002:aa7:91d8:0:b0:725:ce39:4516 with SMTP id d2e1a72fcca58-72888ca9b12mr1728764b3a.7.1733789092221; Mon, 09 Dec 2024 16:04:52 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725e3ca46f0sm3477249b3a.15.2024.12.09.16.04.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 16:04:51 -0800 (PST) From: Atish Patra Date: Mon, 09 Dec 2024 16:04:45 -0800 Subject: [PATCH 1/2] drivers/perf: riscv: Fix Platform firmware event data 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: <20241209-pmu_event_fixes-v1-1-d9525e90072c@rivosinc.com> References: <20241209-pmu_event_fixes-v1-0-d9525e90072c@rivosinc.com> In-Reply-To: <20241209-pmu_event_fixes-v1-0-d9525e90072c@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Atish Patra , Anup Patel , Will Deacon , Mark Rutland , Mayuresh Chitale , Samuel Holland Cc: Palmer Dabbelt , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Atish Patra X-Mailer: b4 0.15-dev-13183 Platform firmware event data field is allowed to be 62 bits for Linux as uppper most two bits are reserved to indicate SBI fw or platform specific firmware events. However, the event data field is masked as per the hardware raw event mask which is not correct. Fix the platform firmware event data field with proper mask. Fixes: f0c9363db2dd ("perf/riscv-sbi: Add platform specific firmware event = handling") Signed-off-by: Atish Patra --- arch/riscv/include/asm/sbi.h | 1 + drivers/perf/riscv_pmu_sbi.c | 12 +++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 6c82318065cf..3d250824178b 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -159,6 +159,7 @@ struct riscv_pmu_snapshot_data { }; =20 #define RISCV_PMU_RAW_EVENT_MASK GENMASK_ULL(47, 0) +#define RISCV_PMU_PLAT_FW_EVENT_MASK GENMASK_ULL(61, 0) #define RISCV_PMU_RAW_EVENT_IDX 0x20000 #define RISCV_PLAT_FW_EVENT 0xFFFF =20 diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 1aa303f76cc7..3473ba02abf3 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -507,7 +507,6 @@ static int pmu_sbi_event_map(struct perf_event *event, = u64 *econfig) { u32 type =3D event->attr.type; u64 config =3D event->attr.config; - u64 raw_config_val; int ret; =20 /* @@ -528,21 +527,20 @@ static int pmu_sbi_event_map(struct perf_event *event= , u64 *econfig) case PERF_TYPE_RAW: /* * As per SBI specification, the upper 16 bits must be unused - * for a raw event. + * for a hardware raw event. * Bits 63:62 are used to distinguish between raw events * 00 - Hardware raw event * 10 - SBI firmware events * 11 - Risc-V platform specific firmware event */ - raw_config_val =3D config & RISCV_PMU_RAW_EVENT_MASK; + switch (config >> 62) { case 0: ret =3D RISCV_PMU_RAW_EVENT_IDX; - *econfig =3D raw_config_val; + *econfig =3D config & RISCV_PMU_RAW_EVENT_MASK; break; case 2: - ret =3D (raw_config_val & 0xFFFF) | - (SBI_PMU_EVENT_TYPE_FW << 16); + ret =3D (config & 0xFFFF) | (SBI_PMU_EVENT_TYPE_FW << 16); break; case 3: /* @@ -551,7 +549,7 @@ static int pmu_sbi_event_map(struct perf_event *event, = u64 *econfig) * Event data - raw event encoding */ ret =3D SBI_PMU_EVENT_TYPE_FW << 16 | RISCV_PLAT_FW_EVENT; - *econfig =3D raw_config_val; + *econfig =3D config & RISCV_PMU_PLAT_FW_EVENT_MASK; break; } break; --=20 2.34.1 From nobody Fri Dec 27 11:12:01 2024 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 219DE17C for ; Tue, 10 Dec 2024 00:04:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733789095; cv=none; b=IoSD7UfKwDP8bZUhWFqEJDaG8tw56ZVWd+cVAhlRmqevQJ5GhGl9te3AXIZE9rh1SzaSbjTGNQRv27+pzIoR7iiaHKbrLUDB6PnCzpkld7Jl572RM6zbvvWSOLSNsPtYGXtvcaLC6Y6k81sgi+rD0gH6CnX2wjZDG5HmyZyTxPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733789095; c=relaxed/simple; bh=Vy1XWln5Cw8TzDTS9fgOpLLRadpmi2eqtCYUaJxD/QE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qgpLC+8/8ZSB0nrFjhXYzFsHUggwYEZUJmyexQBbZjIUl9huFH+w5DkWneAo4Cvz25Ark172UVTBf3r7LADh+m49AVbQBJlcWe2gD7ZFQxIuV3I7aKDKoPaOJS/pqkuMgttFnSEPVnhVvaWtYjYsCid+0wR42lYsjXLFlfWXlSo= 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=KvMGilK7; arc=none smtp.client-ip=209.85.210.176 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="KvMGilK7" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-725ed193c9eso1380814b3a.1 for ; Mon, 09 Dec 2024 16:04:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1733789093; x=1734393893; 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=i0pKu4QEUWyKrGc51Cv9urYoL6jDqPoRBL3/5PZAkyU=; b=KvMGilK7tdoVho1C1wJ2prwu5DsYyHuk1gh0TwOo4PmSNVqAb5mIn6dYQXdof3VIid 6wLCoYe2NxMK6kLGXITRrVGGcofnCJSUnBe6+5MnWTlXAcuMOOurHNyvzqpB3mqT1Mmy LZsvo24IXkZmRr6fqpS8dwcYASywQ6Kx7TzhyxF72IVraRR05zRbkycXWW1kXhCVWKeH cLXG+wLqNeb0IGqYYucWQwDthbrI49v1W27ChkvX93Bs7oPEjEi9jhSkohaEvBrk52DG m5WQ9TWOQFAuAph0vz+EZu9O+FoVK99sIA3v6hpbBcLcZbnLpL3eBwIxgavG2qFYyi+p 47gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733789093; x=1734393893; 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=i0pKu4QEUWyKrGc51Cv9urYoL6jDqPoRBL3/5PZAkyU=; b=HGju483FVtIBC+XjaUnKStcZteSGwCc5oTmn1AT9BSSIgTSRFkt3QxGdycwkhZ7plK mzXcUwHufZnumq0TeHU6NnE7YFBhjdSD886M0zchyMqulFd3PV3RE3nR9fX8D4m0eFA6 0ildOwu3lpX0/fnpNRhY+mOG2f88q6V80X4LlBJe/mal6pmWzQZShnkv4dEEv/xiZJxT yYFSVF9idRZMB4PGeVK4jkR9ijB40E6g3To0Il8HuWT8m/PMUPXkVqiwZaQKQNhvWeM8 1TSXnSNIyb88wgTa8jbt+UVaivLaHl6eCOIV0zApGgigmHg6EV16IKorgoYOVcD8lYyY H2LA== X-Forwarded-Encrypted: i=1; AJvYcCXEauPZQMvXqWQflTIhDFckXyFBjyJo65kwgIfpDeCjcnM2fqoZGTS9SCcBsF4llK+dtS6Jh6410Vsfavw=@vger.kernel.org X-Gm-Message-State: AOJu0YyvVujna7gy0VyRNCc39TIWIbSCQbvcd6DCw0T5M/bJkwK22o3B 6S9Kvc1pnzcx/lDdAMrS0wk6c1l0NzQ/G0HMGy6Aslv49oEWoyAdVt//51Syk+vHcbELutViBV1 m X-Gm-Gg: ASbGncvcxZ5MbAI/jV/ReKU+Tu8J093kBlRHK+2K1QldRJ2b+N2blSptzZdLuIak5Vb avw1QViUowPQnZGvaKgBjGnkRuWS2oT4Kl8h/B7B+7h/pPugakoP2mxgYHGECaT/7vzG7Blo5bL ukWPpLPyQSxq8ttbktKFfJRLyUE0Osx9Wu03hDWenQlNfVqxUTiNPPt7wJlVHKqersv8yeI93J4 lYeJfpMEBW6fcnTGDA8DB86uHjWkzU4URC6od46ghChhObn+Hi88tsO7aWDNalNmmU= X-Google-Smtp-Source: AGHT+IHXM6yBIyUN5IOl2XwzQf3IuEJpf0cNwCaDErthAQJRzZCXMS7KQIlXRIe7/2ggUbe+PD0Nmg== X-Received: by 2002:a05:6a00:1acc:b0:725:ead7:fcae with SMTP id d2e1a72fcca58-7273cb7fb3emr3815468b3a.18.1733789093256; Mon, 09 Dec 2024 16:04:53 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725e3ca46f0sm3477249b3a.15.2024.12.09.16.04.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 16:04:52 -0800 (PST) From: Atish Patra Date: Mon, 09 Dec 2024 16:04:46 -0800 Subject: [PATCH 2/2] drivers/perf: riscv: Do not allow invalid raw event config 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: <20241209-pmu_event_fixes-v1-2-d9525e90072c@rivosinc.com> References: <20241209-pmu_event_fixes-v1-0-d9525e90072c@rivosinc.com> In-Reply-To: <20241209-pmu_event_fixes-v1-0-d9525e90072c@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Atish Patra , Anup Patel , Will Deacon , Mark Rutland , Mayuresh Chitale , Samuel Holland Cc: Palmer Dabbelt , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Atish Patra X-Mailer: b4 0.15-dev-13183 The SBI specification allows only lower 48bits of hpmeventX to be configured via SBI PMU. Currently, the driver masks of the higher bits but doesn't return an error. This will lead to an additional SBI call for config matching which should return for an invalid event error in most of the cases. However, if a platform(i.e Rocket and sifive cores) implements a bitmap of all bits in the event encoding this will lead to an incorrect event being programmed leading to user confusion. Report the error to the user if higher bits are set during the event mapping itself to avoid the confusion and save an additional SBI call. Suggested-by: Samuel Holland Signed-off-by: Atish Patra --- drivers/perf/riscv_pmu_sbi.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 3473ba02abf3..fb6eda90f771 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -507,7 +507,7 @@ static int pmu_sbi_event_map(struct perf_event *event, = u64 *econfig) { u32 type =3D event->attr.type; u64 config =3D event->attr.config; - int ret; + int ret =3D -ENOENT; =20 /* * Ensure we are finished checking standard hardware events for @@ -536,8 +536,11 @@ static int pmu_sbi_event_map(struct perf_event *event,= u64 *econfig) =20 switch (config >> 62) { case 0: - ret =3D RISCV_PMU_RAW_EVENT_IDX; - *econfig =3D config & RISCV_PMU_RAW_EVENT_MASK; + /* Return error any bits [48-63] is set as it is not allowed by the sp= ec */ + if (!(config & ~RISCV_PMU_RAW_EVENT_MASK)) { + *econfig =3D config & RISCV_PMU_RAW_EVENT_MASK; + ret =3D RISCV_PMU_RAW_EVENT_IDX; + } break; case 2: ret =3D (config & 0xFFFF) | (SBI_PMU_EVENT_TYPE_FW << 16); @@ -554,7 +557,6 @@ static int pmu_sbi_event_map(struct perf_event *event, = u64 *econfig) } break; default: - ret =3D -ENOENT; break; } =20 --=20 2.34.1