From patchwork Thu Aug 29 09:00:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13782811 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 ADAA3C71135 for ; Thu, 29 Aug 2024 09:07:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=BeNRcsK1VBAVknVZMYL7LYgNLSYxmT3BPkThGqZl++4=; b=gtH/QEK76cwUnrVhLu9tAKqzWr zAdyzPPLByMpKGMaCX6oc2AeHUcwA4bJTjzrc4pEQeVUmQ6Ppyzr2dbsemLD9gV+dNqwjpow2HPvs v5hWQW5K5s7xWOZjutTu9vXMuPElJeAKoAdZBaOg9UYsUlETq42xCMIX8GKlx2tRrb+6jvSkfhQjT tlhuYdgPhc0O8oajOBEmdjb0A9kv6vuiNvo8Ui/IG62LyYD9QvBaKEG2m0Uh7NUGMaORRtlk4l7tv 1ob7+7wcqLnS7behLA7gLM/Sh/jvCq61IkQ0Q5nPACl4/COjQ8+rV67+fvD4/vo7AagCZv30MAIIu soUOzqzA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjb7S-00000001I1q-1BWq; Thu, 29 Aug 2024 09:07:06 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjb1D-00000001Fzj-0tMk for linux-arm-kernel@lists.infradead.org; Thu, 29 Aug 2024 09:00:41 +0000 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-371a6fcd863so282119f8f.1 for ; Thu, 29 Aug 2024 02:00:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724922037; x=1725526837; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=BeNRcsK1VBAVknVZMYL7LYgNLSYxmT3BPkThGqZl++4=; b=ji5u1e+UvA5Q3LRrQWbTLc7YHGlZzOxreM+9DJ2TFdPRzEjv3d2npe2PlywymUdozV Bn2XOVITPVhHZzsbCoU5q/L59Jzhj+oHmYVUrXjN8DWFugQPgyPTQYP4ity6UuebZDn/ fnR8f17ApmIhhJ2RgGmtgvcNT+sp2PWwqm+lWe3WpwRZvWuMe1MitIdMFEhmbSFjiHZu zaCPhrQJ4AJMbtDCPYv8aA7Khk4/RmGEt9+Av6Nm5to8vHLL7Gia7g8zsqpsoXGki901 +1dVpzDJPTA09OB/y+1Agk7lyHISGcGllZjhdLxOw4Y7eYhrzDTbSapuMiJouWBAYYRR tb5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724922037; x=1725526837; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=BeNRcsK1VBAVknVZMYL7LYgNLSYxmT3BPkThGqZl++4=; b=Fqk7HCPUq93uSekyW9Tcl/uBE3liHCyozrXBUlb5ijdWdJAxKyIQGz6OKDlXL4UP0M /0FqrTGffcebtweBEi/+D1/fCY+vdCwD4gVuPfaSwjH6MAa0ekQcyZE3K6OOkR297rBH Rq66VboRfKMNIdEhKCWs5Rs+XQpoKHFekyNP48z4XBo9NjNLG9zXgqulthK0sXx/rqmx 8w6H0mYZyD/hPfgsUfrIDBB2KtUbRBq0zMupgtKaHwgccK0k5JYz9bqeXtEZZS+Sg11+ JFgpJv/6AtVKxxPONZNE1Fh9TspxqOB0bCYkSPqGGU8z2CWjhXUKMUcKQVh1jZxUyA4S +r9A== X-Forwarded-Encrypted: i=1; AJvYcCV+Wo6qpVKBPGkhJ/rID4m7tEKnhak4gqvd/IOc0m97mqX0kMrf8WPdxesZQ0hznILWblApCUQ33kHgourXGycy@lists.infradead.org X-Gm-Message-State: AOJu0YwOr5+n3uX5KSuVmtxY4SP0V0MNKzDv/y3rIzExkkWIhtpVTW0p 8wkSCpgj2x6O6MlwUco1DVJG6O7n3iG3qtKiMuLk6N+b7607Fmu6iZssbBhq1Xk= X-Google-Smtp-Source: AGHT+IFDn/Gg69njG25mI4d4sEhZazC4fYygfh318ZFGyBPM6YU+PgABbs6EeHt9ufd4I3vB2nPnxQ== X-Received: by 2002:a5d:51c9:0:b0:368:4218:a3d with SMTP id ffacd0b85a97d-3749b54fe8bmr1391056f8f.37.1724922036607; Thu, 29 Aug 2024 02:00:36 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3749efb15b8sm860971f8f.105.2024.08.29.02.00.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 02:00:36 -0700 (PDT) From: Alexandre Ghiti To: Atish Patra , Anup Patel , Will Deacon , Mark Rutland , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrea Parri , Nam Cao Subject: [PATCH -fixes v2] drivers: perf: Fix smp_processor_id() use in preemptible code Date: Thu, 29 Aug 2024 11:00:34 +0200 Message-Id: <20240829090034.15777-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240829_020039_627528_46A96702 X-CRM114-Status: GOOD ( 14.14 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org As reported in [1], the use of smp_processor_id() in pmu_sbi_device_probe() must be protected by disabling the preemption, so simply use get_cpu()/put_cpu() instead. Reported-by: Andrea Parri Reported-by: Nam Cao Closes: https://lore.kernel.org/linux-riscv/20240820074925.ReMKUPP3@linutronix.de/ [1] Signed-off-by: Alexandre Ghiti Reviewed-by: Atish Patra Tested-by: Nam Cao --- Changes in v2: - Do not disable the preemption in static_key_enable() (Will) drivers/perf/riscv_pmu_sbi.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 31a17a56eb3b..febd8e74a72f 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -1373,11 +1373,16 @@ static int pmu_sbi_device_probe(struct platform_device *pdev) /* SBI PMU Snapsphot is only available in SBI v2.0 */ if (sbi_v2_available) { + int cpu; + ret = pmu_sbi_snapshot_alloc(pmu); if (ret) goto out_unregister; - ret = pmu_sbi_snapshot_setup(pmu, smp_processor_id()); + cpu = get_cpu(); + ret = pmu_sbi_snapshot_setup(pmu, cpu); + put_cpu(); + if (ret) { /* Snapshot is an optional feature. Continue if not available */ pmu_sbi_snapshot_free(pmu);