From patchwork Thu Apr 11 00:07:37 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: 1922296 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=RnFQoD4g; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=JauJ1MEO; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=CKsMfwbF; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VFKpd5g8Sz1yY8 for ; Thu, 11 Apr 2024 10:10:33 +1000 (AEST) 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5cT6Noc3yP8O7Wr7fiY0THZL0s0qKrQlBZusdaI0nBU=; b=RnFQoD4gwW8ubZ hNpFCdz+Q5IcAkmtVpC+EsFpTkvcn8PUVjRyjchA9q96ExClPfIUpaTAW0hYcUPrOLo9VLhv7ESGp KSq4V+WS7ncAi7ZkSCgG9Zuai8haf3j5JT5kj9xwRFiO51w9qlPynEJ2RrEGpZYx4sxiwQutb8w2N tWaEGeJdXF3YklLDFwLlSwIPcUZBqovMTp62gmCiGopRk7/u7J76dz1iNOyG2k6zgZzVw5BQTnjc6 L0D6y6dYw63csTFahn0kxHloHZJMussx1ZZEfuJHn8MBRfGOCXIelEgiTcV4aPk6SdNSYwmXCwoei i6g89B2ref4/Nu0NaS1w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rui1P-00000009bR3-47bf; Thu, 11 Apr 2024 00:10:31 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rui0C-00000009aQC-3IHV for kvm-riscv@bombadil.infradead.org; Thu, 11 Apr 2024 00:09:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=JsjqhFGYXnwJEbG5VdNtPW4Uvi+s8iNjRkGrxpWiI64=; b=JauJ1MEOBrcn57ZVvVHhEHACiW q4lsbu+MlOip18fpo8FJAo/8uZ6Tw0ckHeM10bya/hv5Uyxk7suTTgIPwaGRuW5dn4Lap6K00R+fb I5hXK7hO+rTsniFXL4TYQH4E77eOQyC8Y+T218/71V96tK1opiK22cLH4lWaCBa0rlAtvszTcbrDx uAkYzZae0PZDuYivS+mmESwe+AYeMSca737pAMXhE6TEbb2+33wVDz9eoSiqAtJToGfAHolfc7WvU dTcTeIrfXBWbd1M2asKVcamWFvp/1F7ygnXT63iDVA0ln5hCYQYKA/+CmXewKDgwiepKLgVsM8Jbu GyBJNJrw==; Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rui00-00000008Jn2-0Mnu for kvm-riscv@lists.infradead.org; Thu, 11 Apr 2024 00:09:15 +0000 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1e3ff14f249so2793125ad.1 for ; Wed, 10 Apr 2024 17:08:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1712794111; x=1713398911; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JsjqhFGYXnwJEbG5VdNtPW4Uvi+s8iNjRkGrxpWiI64=; b=CKsMfwbFSoSEeQ2ptKzIZjO8h0BqSFSJOxKv1ClwenAJHcT8Xsnxhis9jdCZoelH7S UOZw1l6gD0bdBJeFGgJMYPC78RTdfpBGGRBW+Vb/PL9l03o+Y4dcKxlqfQOO2yjO16yd 2Mn9ll9rDJT+n9YEyPZYZjqTTVTCDiCyymycWQPYO9sXrYdRs8SPhcPtV5jOdvHDttNU Zt3xJxtBbEvenWucLaplt2PhDwAUeLaA3buFOBN31WwwH3J09UBACFJlOLUe8rTf40ui DzP6AM+sDVRrxUdBoT2KPsb4ALIaiQGCQYeO3/AESwk8sU0yoXDlMluNSPcHsZlsXOoL vrjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712794111; x=1713398911; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JsjqhFGYXnwJEbG5VdNtPW4Uvi+s8iNjRkGrxpWiI64=; b=Xamv6KdIPvSmwVPL1whzA/nM6OgoeTiTyZW5XQNsCiYBAwZmbFizKW2n1xrpxpUCeq AIziqpyq5BwOkAytqMiK51hXN9SuZvFe/6Qatju9Su0YfCR1F5JTWJMS0VHRLedcih6V JVX+/LAqV85jXwA7fCpc4yCaBJTLbHkSMhu/WdT4n/pxaPdsYieEIeP3A3cjbvwDvmzZ 9+v+yk9FpckbuPiZAuP75TZmd66vEr2YfW+h0ML/OopyyYP8ZbzYucZFsBXBQhIeuWUO lGlCqZFIwrvqehgou8JzPJfklWIlvpz/EcVHclkXJ70icchm8oHbuI/RpK6iaB+BwXIm ImnA== X-Forwarded-Encrypted: i=1; AJvYcCXLR8728CMziDToDhsnO/lXkFPDoESdUMuZAARu71J5GhVtB4+WlKTyeMOFhZ28QoCB2yCClxxJ5EHGRnEG85ZY4CvT6+wHuYwKT+1C6A== X-Gm-Message-State: AOJu0YwQRGGfXAa+FoelYrlu3+tR+nUhzAvNz3jz+Fhv6eO5mdmFW+MW tiLF0YCYxobOy89C47DDeeP7O13tdLVYeQIwP/yAwAUOPs/MIj16imVLQpnRjSo= X-Google-Smtp-Source: AGHT+IGuFutR246dxqGbmU1WdGFmdIotjRuJtHTIKb2Ia1SDWO/lAEbkSs2TMc+GghFhVq0a3R7XvA== X-Received: by 2002:a17:902:f94e:b0:1e4:7bf1:521 with SMTP id kx14-20020a170902f94e00b001e47bf10521mr1213882plb.19.1712794111648; Wed, 10 Apr 2024 17:08:31 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id f7-20020a170902684700b001e3d8a70780sm130351pln.171.2024.04.10.17.08.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 17:08:30 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Andrew Jones , Ajay Kaher , Albert Ou , Alexandre Ghiti , Alexey Makhalov , Anup Patel , Atish Patra , Broadcom internal kernel review list , Conor Dooley , Juergen Gross , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paolo Bonzini , Paul Walmsley , Shuah Khan , virtualization@lists.linux.dev, Will Deacon , x86@kernel.org Subject: [PATCH v6 09/24] drivers/perf: riscv: Fix counter mask iteration for RV32 Date: Wed, 10 Apr 2024 17:07:37 -0700 Message-Id: <20240411000752.955910-10-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240411000752.955910-1-atishp@rivosinc.com> References: <20240411000752.955910-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240411_010907_090249_4A7BC66D X-CRM114-Status: GOOD ( 15.10 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: For RV32, used_hw_ctrs can have more than 1 word if the firmware chooses to interleave firmware/hardware counters indicies. Even though it's a unlikely scenario, handle that case by iterating over all [...] Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:62b listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: kvm-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: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org For RV32, used_hw_ctrs can have more than 1 word if the firmware chooses to interleave firmware/hardware counters indicies. Even though it's a unlikely scenario, handle that case by iterating over all the words instead of just using the first word. Reviewed-by: Andrew Jones Signed-off-by: Atish Patra --- drivers/perf/riscv_pmu_sbi.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index e2881415ca0a..a6e74f4ad1c2 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -772,13 +772,15 @@ static inline void pmu_sbi_stop_hw_ctrs(struct riscv_pmu *pmu) { struct cpu_hw_events *cpu_hw_evt = this_cpu_ptr(pmu->hw_events); unsigned long flag = 0; + int i; if (sbi_pmu_snapshot_available()) flag = SBI_PMU_STOP_FLAG_TAKE_SNAPSHOT; - /* No need to check the error here as we can't do anything about the error */ - sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_STOP, 0, - cpu_hw_evt->used_hw_ctrs[0], flag, 0, 0, 0); + for (i = 0; i < BITS_TO_LONGS(RISCV_MAX_COUNTERS); i++) + /* No need to check the error here as we can't do anything about the error */ + sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_STOP, i * BITS_PER_LONG, + cpu_hw_evt->used_hw_ctrs[i], flag, 0, 0, 0); } /* @@ -790,7 +792,7 @@ static inline void pmu_sbi_stop_hw_ctrs(struct riscv_pmu *pmu) static noinline void pmu_sbi_start_ovf_ctrs_sbi(struct cpu_hw_events *cpu_hw_evt, unsigned long ctr_ovf_mask) { - int idx = 0; + int idx = 0, i; struct perf_event *event; unsigned long flag = SBI_PMU_START_FLAG_SET_INIT_VALUE; unsigned long ctr_start_mask = 0; @@ -798,11 +800,12 @@ static noinline void pmu_sbi_start_ovf_ctrs_sbi(struct cpu_hw_events *cpu_hw_evt struct hw_perf_event *hwc; u64 init_val = 0; - ctr_start_mask = cpu_hw_evt->used_hw_ctrs[0] & ~ctr_ovf_mask; - - /* Start all the counters that did not overflow in a single shot */ - sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, 0, ctr_start_mask, - 0, 0, 0, 0); + for (i = 0; i < BITS_TO_LONGS(RISCV_MAX_COUNTERS); i++) { + ctr_start_mask = cpu_hw_evt->used_hw_ctrs[i] & ~ctr_ovf_mask; + /* Start all the counters that did not overflow in a single shot */ + sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, i * BITS_PER_LONG, ctr_start_mask, + 0, 0, 0, 0); + } /* Reinitialize and start all the counter that overflowed */ while (ctr_ovf_mask) {