From patchwork Tue Nov 19 20:29:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13880530 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 7EFF6D6C299 for ; Tue, 19 Nov 2024 20:34:49 +0000 (UTC) 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:Cc:To:In-Reply-To:References:Message-Id :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=jdtNfP4wfrdlMbD7slhXCzzkva8zZjscA0x+ABP0Q4U=; b=j4BmPTtMxKLt44 r2cbg4nExV7qr6O+g1OrL8tvRt+/tGe/xzT8ZiKOMaRhmbwaMukkQy+dexj5e4iCs4ma70w41+SN4 Zx8JAZzbm8P8YVWdjp8Sq1P6Fy8pdIzXyY8er8G+chHw4aGBnWOK4nGAWQ4gEtnvOaGBRzIJJFD0M gRrkKuVM+mivzpHVrEQgsbo/GuZYsmxQVtCl4lxXgQpH59Jb1REvUwh1L1M1xjakIWAPLO1Hfh0tI Tp/fw9oPzJqCrMVaYaE1ygKu95HZ9txIBdlU0P+pUDu4lzQv/Ywrld6TwornO7ibPIILFWtAtW5mt TBzp8xzm6oojbdAKHZJA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tDUvs-0000000DiOX-3NxO; Tue, 19 Nov 2024 20:34:44 +0000 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tDUsA-0000000Dh06-01S0 for linux-riscv@lists.infradead.org; Tue, 19 Nov 2024 20:30:55 +0000 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-7ee020ec76dso1086634a12.3 for ; Tue, 19 Nov 2024 12:30:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1732048253; x=1732653053; darn=lists.infradead.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=FB/tddqfX+5D+NwPYtCZBvpcbtznximYassXddDySaI=; b=EKQ35d/zj/eCIDyCs5WxKKU4Odkw33a91eskAoJrs9seScr6jfuQXWkGBL0qW9cFZ4 K1xkvV5rbznK85d15/iJo4im2jxHEyuUraog5boZJ1i+cf8MVAAQ8x4dncP5amel1ERm U+Po/aq4jg2iPa4LBfXC8dFmTDrIUNdmzJoJsnRvluPJWZMWeY/lEbegbwULYj7GQEkW u36ptU1EKHvoS2T4TTwrrtGYYalTAF1+HduxB+UF0794A/Hjlk7QGayjhF+C/2xhKIbw 4tXWkKrTiFTE9zXw90D4fI/X1+m+TcyKPOZOjSdFXa4DkDTkcd6lml6VnuSgByrG6/+C tH2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732048253; x=1732653053; 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=FB/tddqfX+5D+NwPYtCZBvpcbtznximYassXddDySaI=; b=l1SKn9rtwOWMuphlUT6Rn57eVXBZJe25FM9o/AVG0Fl8x/QvG6MLt5mSwlNUuWAT3C hXmp0+ogkTCDjljYWpDYTCZcvpoS4GSjNDaEb/Cq3kZsOhW+pQ0cMCn65+5EIw3zzH7m 9uFjl58ajRb2aS4Sr7AhRZiBR9IoDZRpuoBRcFyEqRrxM3nUQ9Jej0z9Exx0jecyL6Gl 8m+oBSTTCA8njuipoibiDS8HE8GWy0MlJjcUJ84AaJ7nHSyyR4kyt1VP2UZ4yU2Noklm X9YQFRP4cKTnZYWedQ33HNTjZR9C5pjj8tmyI5CYbrBpkHBJLfL9/UWc0N66st0uCXhf PD+A== X-Gm-Message-State: AOJu0YwhHbDhbVo4DtQx5KgPGxdouCa0eiXbJQT7OyyZP3wjLN3QRVaU VkaSiOR0cu6bJLlkeZf7nKhzTQoWYtpcFOanhlTwk6fXW20C/HAY77pFWyJpo8Y= X-Google-Smtp-Source: AGHT+IGG3BOEKBQHByHPNxLGRscpaUzNEj7RMHYMCOiguADUgT/ZA6zCcmpHgOYphyvS5L29CLFFRQ== X-Received: by 2002:a05:6a21:3287:b0:1d8:a29b:8f6f with SMTP id adf61e73a8af0-1ddae4e24bbmr613518637.16.1732048251371; Tue, 19 Nov 2024 12:30:51 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211d0f34f2fsm79001315ad.159.2024.11.19.12.30.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 12:30:51 -0800 (PST) From: Atish Patra Date: Tue, 19 Nov 2024 12:29:50 -0800 Subject: [PATCH 2/8] drivers/perf: riscv: Fix Platform firmware event data MIME-Version: 1.0 Message-Id: <20241119-pmu_event_info-v1-2-a4f9691421f8@rivosinc.com> References: <20241119-pmu_event_info-v1-0-a4f9691421f8@rivosinc.com> In-Reply-To: <20241119-pmu_event_info-v1-0-a4f9691421f8@rivosinc.com> To: Anup Patel , Will Deacon , Mark Rutland , Paul Walmsley , Palmer Dabbelt , Mayuresh Chitale Cc: linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Atish Patra X-Mailer: b4 0.15-dev-13183 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241119_123054_086281_F76A6EF1 X-CRM114-Status: GOOD ( 14.36 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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 98f631b051db..9be38b05f4ad 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -158,6 +158,7 @@ struct riscv_pmu_snapshot_data { }; #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 diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index cb98efa9b106..50cbdbf66bb7 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -508,7 +508,6 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig) { u32 type = event->attr.type; u64 config = event->attr.config; - u64 raw_config_val; int ret; /* @@ -529,21 +528,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 = config & RISCV_PMU_RAW_EVENT_MASK; + switch (config >> 62) { case 0: ret = RISCV_PMU_RAW_EVENT_IDX; - *econfig = raw_config_val; + *econfig = config & RISCV_PMU_RAW_EVENT_MASK; break; case 2: - ret = (raw_config_val & 0xFFFF) | - (SBI_PMU_EVENT_TYPE_FW << 16); + ret = (config & 0xFFFF) | (SBI_PMU_EVENT_TYPE_FW << 16); break; case 3: /* @@ -552,7 +550,7 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig) * Event data - raw event encoding */ ret = SBI_PMU_EVENT_TYPE_FW << 16 | RISCV_PLAT_FW_EVENT; - *econfig = raw_config_val; + *econfig = config & RISCV_PMU_PLAT_FW_EVENT_MASK; break; } break;