From patchwork Tue Dec 10 00:04:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 13900526 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 7151EE77180 for ; Tue, 10 Dec 2024 00:05:10 +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=26YB4NGOvzftgBfw+OW5qO1CViL+zo7J19PyhM7Er1Q=; b=4MItt9+SXRGwq/ PT6B1E4RjwZZMAV7nFBgkt9ulQtrUh7adEajzfkOU6Dj1O6rAmtTPL9V7CzIM51GERzi9iCUNUsU0 MlQiEibP4t4bJppZvLiwaRw+aLTGsMoX+1/iLHZbA4ftrB4BR+ESjm1AZUgBiQKozgRJ0Dx/4crqZ CJiKeQXKImB7URmK1IPYigzlue7ni6CPf24LZ+B7sNVpiyPiYJaMH1g+nPyOkj+OT8QI4oM7snyZY gW6att5OqIZ9MYc8NnbvzwIBV85R5vdd5g56VqGUj/glbbaGdmTDPEYHnXvgO6Gd6IArF4gXR3PwJ SWdprntVMdvVga2ObbFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tKnkH-00000009e2k-10b3; Tue, 10 Dec 2024 00:04:57 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tKnkD-00000009e0u-1Lwh for linux-riscv@lists.infradead.org; Tue, 10 Dec 2024 00:04:54 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-725e71a11f7so1299002b3a.1 for ; Mon, 09 Dec 2024 16:04:52 -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=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=IcoCLi142uVK6LZxiJuwIjRZD/c9pyPS+Cs4D2LMz+8=; b=3AW089JhehpQk01GScaigLqlHywh3UGqHe0s5u7rAwMbrDoM/fkUNlQfgpk69Z0bkO Gpmhyc/jMAbplQwcAS2NTF5KJWfMoRjwCRbaj2lA/3aIUTPVDb2+DT/jOZY27Wx3n4V2 IxZCEMJj7gxFojCvnjv4Bf677d8Wn2kQtOMRTXBcscjT/4Oiyn5OHUvBFdp6s/tyA2Nj sU4edgr5zqhDYfH+2jv8LD2SQEvHRl8gCHeU03h1jpdicidb67iG0/YX8A3SFCEdh5vr c8xj74gXgrmtxbn9Ed+bwxbplsArUEsHTiL83n3of0Jg7Vb4vODVvnfMgGGn7Xf8czA+ hWVg== 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=mk+iSQSS5rh0Rlfm2y0izMDLWZoD1aeQXW5Eg1wgeorQ1qI2nclDw6iCRlUVSnr/t1 QbQsi/kr7G+9wbYbk9Uh9Vb0pjiT+k1xSeY5B/jK242BZdefPaA6/teU3DMfs+u7lmvX mH1e3Cpm30pGaRqTThfFnP/nezfHkB5TrrZtpt4t+gNCzx6SIarYIviADVezd6uRtqOO ntd7Rwpvb3DzGTeK7bxlx601edjOaKM/JOcUIhUqCbKnano7qzyOdzogcsCJMqCEB0+c zXR+QF1wEpDyLAyu9SpzP0XP4V/lP8N0SEo/jJGeOe8QMC/0eQ+Ormk4/92lZP6cz+DI bLuQ== X-Forwarded-Encrypted: i=1; AJvYcCXQxI4EUjrJxSS0MR1Bmcpeik9yUSMhJxETtwQBX9hm/flh4p2klQRHRf6zWBalUAyR86MjIjUVIpklRQ==@lists.infradead.org X-Gm-Message-State: AOJu0YzHnRXCpbtKzenBIjQ9RBTi2uyy048QVIbMurenCKLbbiETHpJG dFDYjrelin6xeV/JltzlmWpDZwJudKIk2jrEgN1vo9tlqOZ/pXx5qMsbGCB+5/U= X-Gm-Gg: ASbGncv4AixndauEkd7KdwN687PMYYPFD2wRUmUmwLVA5WnnoEKANDfeSAQsTAkY27/ 5ZIQeIiIKwm2HKI8nyH4DcUp1mWAQVzmyLQT6WODdFZ+W63Ck0ovNZOBI01sCEejVpiKUwTsG/D 9aoKGFA2TyVg8gH47XLqn+P6CkX8dacIY+i6iX0fH5Ai470/rNg0OqzsD6hYgf0WxnVeS66mWdh Kb5tQZPgEruI5ZVjRFWMp2o586wJXdsyOdamoYNjfT5fQO4TVqIvgX5lzQjPw2RbQM= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241209_160453_365043_19C6BA20 X-CRM114-Status: GOOD ( 13.27 ) 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 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 { }; #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 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 = event->attr.type; u64 config = event->attr.config; - u64 raw_config_val; int ret; /* @@ -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 = 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: /* @@ -551,7 +549,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; From patchwork Tue Dec 10 00:04:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 13900527 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 D54A2E7717D for ; Tue, 10 Dec 2024 00:05:18 +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=g6XuRM/bJVNvCLiYXn9Y24qre+CFS26aLYe7EGj0ZPY=; b=YhOT7mMI4zv+Co kQ9jf82FGxMNHSgyXfmp1nNWGsv4qB3mnoLhmWLUVzCNbmScBbL7bYZmhjKwYa1RYNtq6OtCbc+MN 5dUAv1pu4uXLQsrwtIkneVHyMM+OwL7/5T7TyWbJW3SQkAST5S4uVDoLMq9s01Cic/OXuGSxSX0hz lkllpGpf0dtuNnNSoOadq+ecMMmNsR9EPE1vZpsJ1Zmmm3GdeKf0uN/EGNOLAtHR2IGQnFq1YHaYR rbnPHYo6HZgfdqaXc1dP/PCcLwQSxaovCZ5oZJ4GNE9xIdoZIIzLGmpfSgQfojrfqRdilJTghyBR0 7d9CiOuA/XrsMv7DVlqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tKnkH-00000009e2v-3W8b; Tue, 10 Dec 2024 00:04:57 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tKnkE-00000009e1Q-1uju for linux-riscv@lists.infradead.org; Tue, 10 Dec 2024 00:04:55 +0000 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-725ea1e19f0so1394121b3a.3 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=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=i0pKu4QEUWyKrGc51Cv9urYoL6jDqPoRBL3/5PZAkyU=; b=BHJkWnMv+ih+FbuUXVaUBiK5pdcSAHA4zjn9c/MbZ8WGwsJbajFsFHjMFhmVzJ92CZ Fsl16H7Fvqx2T6NczOtlRMI3gbWA5mNAVHfErKEpbvHyXeE0nVIzd0CMhBTonK/zZDgM HrDgKCjCSZ50ooag9UJPjgpQhdHQPb8mQCI3wkts/BAI8jT/G7vAO2BfCAlglpCE9Di4 QfXIkvArUd31F7+aMV3xKvaLrtwLPNB6224siYjefdc3cBWSKYJqEhn2TJi8GpH6HOks FPwoRdOiIoKWxJc4LecrumQOWnrVVM66WAJ3JDd+Xyt7j64bszshKp7s35YXRqarQ722 rfbQ== 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=CoLuH9fiY9TcJefHqB/ljqzs8Krn+OW8z3rQDNulnHenQJWH/tenJQTGMlWklp+Gj/ /a5Ga3sa2BZWiv1b81nMx8URMt5mKNsw832+L14iz8UeZSv2zTnHhhoq5Aur/bmksEFU UXFPKuRbCk4EWFb285VRL+IyRPDZtXmNk0daiJmSLUHl44LBofZ9omqfhp/RXooA+XEh yAyldXlcjnQQsyAbf/wJ4W7wa44EHJLnBs3fdVLYuXkecTBzRXPoLgICQisZWFwAkxxD WVnvJv9lVx658c3BO8o+ODS4pJiVRHFxuXLcbdhmjpr4JeP9ImAPadikFkhYboYcQYis T+XQ== X-Forwarded-Encrypted: i=1; AJvYcCXUpNY7bX/pAxmuh7eW7xuo045LZvb6UyqhkevHFDbTv8JLwURyRiQrexa/RSVPL8a0cW6CziBwnCSx/A==@lists.infradead.org X-Gm-Message-State: AOJu0YxngUA24z9b2VfXz12XJ6LbiF6NbpZ+m89NZa/5lHnQ94tv0MFX eRNucHXxjadRrJNXYMxRkaW48PJH0yCJZALVoyxC80I2XE9kkWSTs4Txdr+suRU= X-Gm-Gg: ASbGnctyvLkV6K5T8qmpU4Z0zFGEMOd5qTc76Z6FKY1JTB1IhYkOWOrduNUTunfd4qf XpixT5bE/LoWPmXWSP7YoAZVAFvFdI7faEpi1K8RWaTalgDELG4/WO8mEdFvKm6JLkv1Tt2zYOz 5rGvyhPdJaG3Gj/FP+AOkEPruXdN0iSXoN2oXFiqHwDqtxAXHgxd6vHWvuULbeTN7i/zpsgUIWx zccVv/igJ7jPq2AnxqcASfDe54D3RigqHn5f04ea8SrGmVE/jnHzDpX0/jwBFafYjE= 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 MIME-Version: 1.0 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241209_160454_498023_166D970D X-CRM114-Status: GOOD ( 15.89 ) 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 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 = event->attr.type; u64 config = event->attr.config; - int ret; + int ret = -ENOENT; /* * 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) switch (config >> 62) { case 0: - ret = RISCV_PMU_RAW_EVENT_IDX; - *econfig = config & RISCV_PMU_RAW_EVENT_MASK; + /* Return error any bits [48-63] is set as it is not allowed by the spec */ + if (!(config & ~RISCV_PMU_RAW_EVENT_MASK)) { + *econfig = config & RISCV_PMU_RAW_EVENT_MASK; + ret = RISCV_PMU_RAW_EVENT_IDX; + } break; case 2: ret = (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 = -ENOENT; break; }