From patchwork Mon Aug 26 16:52:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13778202 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 C0A34C5321D for ; Mon, 26 Aug 2024 16:53: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=BL9JjpcnqKHeua2e3XbD0fdD08HoTxgLl7O829TDGu4=; b=vxpFr4+QO0JtkqOaaHtOp+HvRz ABnQwI8PfiTSw6C08TUbQmDqKbwKmhUKDFrQMqPJEln+GPUEu2T4KDziyfgy+qEigC+cgqY5uGzrs wm/aJHZzzZyKbKJrNeTcYTecMhwmfNO+MLZpfN0GWQWcPpX63/w/pzYOnOMBH/oJYeRVp3KtxqTDW 7/22SayRJ/1xB1pBc9F0rfgJU6pBl7GJolRX7nOBCo74WvZ6r1DtbcW7p2Gf9d7fu3F+1Hg/AltP0 viBwrU/nw2Jes9ROX2l6GnPqSI8FqBYtthSKJ0PMSlz3n/C0GZuTcSWlXG0pt4tLMf2NSRQbqmLgM LtaFZVMQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sicxk-000000085ik-0InK; Mon, 26 Aug 2024 16:53:04 +0000 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sicww-000000085ak-1HI4 for linux-arm-kernel@lists.infradead.org; Mon, 26 Aug 2024 16:52:15 +0000 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4280b3a7efaso39327005e9.0 for ; Mon, 26 Aug 2024 09:52:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724691133; x=1725295933; 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=BL9JjpcnqKHeua2e3XbD0fdD08HoTxgLl7O829TDGu4=; b=z3lkgDA0MwA1oXGSXsdLLW2HRdCY8TYXQ3er+LosT2l8jJPKrX0lZeH1cAI/PjA+Hp l3WPOAJmW2wJa1xsW4OmwnJbh2p3xxyFpsv0E9W5Ng39AONulBjjsfa4JsI0Ahu6EKkt CHwmYWS9sFivHF320peRZJPvJmXx/ZSgj3UB3p1+yvHPzozUVbM9Jw7a0uxdj97fSTDG U3uHEfo8+Ms7Et5Osl3FOUie4IWrwXk+g88y+JneGGFQHl2P/fj91N7ADy4mLbXT+N4H 0efjbnQos9wrugeKYk/5Habn7rY52ritaWpJDHj6P+X+bYtRabfIQ612CiDEd4yOTAx9 jmzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724691133; x=1725295933; 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=BL9JjpcnqKHeua2e3XbD0fdD08HoTxgLl7O829TDGu4=; b=K39bXr8GOKqBUw97Macuvk70J1lSbw0AFqvF+7/G8P/BAVu4cJ68VZ+grE5WyuoBmK rUCAJwjaFlsKXb2K2FMjZHrks0VG0j47QlQaw9pNRV4FIIAgb6yKH2AN3owymELk9Jms l6kLNn9q4AXS2C7kDssw3r6cQgd7jSAOSsbjOtY2KRzipUtAuFmM074uHW1GwE9454EC NdpqXRvr9CxwoUsr3/KY9QioyKX5houFeCtnfPbbU/CDAuvHmUbLTJbRm1OAxioF8ESS e6tDnrdtAg513xy3PF9CZ8xk2Lik71szz3yO9z3EXx/x3vztlQBsrNOpwluKJgZeM5hK Mm+Q== X-Forwarded-Encrypted: i=1; AJvYcCUHBNJCrcZGc1aqdl87nZGKTZgBq4Wk/j4UMXe9sggjw1hNixDr3HB8v8n0N+oYNBZMUWE6z1VeuMmZ6Do6WzgT@lists.infradead.org X-Gm-Message-State: AOJu0YwA2y6Vj+ffgC3FRwBLiWrJYJ8AlPwgeiy+KJNNNWmDfrGe/okr AvUTvPdeBE25Yrdw2QXr/szmR8VjxUoDaHgvw6V0IVVhZ4YWSh9xECxHes7QnFE= X-Google-Smtp-Source: AGHT+IHgPww2vGsUStPy4YUKa5Ssz7uxojN5Zc8AsHlLup59YaFfKd8Gz+nUHC6X++d8ON3xrClYDw== X-Received: by 2002:a5d:6885:0:b0:371:8bc9:1682 with SMTP id ffacd0b85a97d-3748c7dcc10mr183591f8f.33.1724691132518; Mon, 26 Aug 2024 09:52:12 -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-3730811044bsm11137226f8f.23.2024.08.26.09.52.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 09:52:12 -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 , Nam Cao Subject: [PATCH -fixes] drivers: perf: Fix smp_processor_id() use in preemptible code Date: Mon, 26 Aug 2024 18:52:10 +0200 Message-Id: <20240826165210.124696-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-20240826_095214_366232_29FE0188 X-CRM114-Status: GOOD ( 13.19 ) 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 simple use get_cpu()/put_cpu() instead. Reported-by: Nam Cao Closes: https://lore.kernel.org/linux-riscv/20240820074925.ReMKUPP3@linutronix.de/ [1] Signed-off-by: Alexandre Ghiti Reviewed-by: Anup Patel Tested-by: Nam Cao Reported-by: Andrea Parri Tested-by: Andrea Parri --- 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..25b1b699b3e2 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -1373,11 +1373,15 @@ 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); if (ret) { /* Snapshot is an optional feature. Continue if not available */ pmu_sbi_snapshot_free(pmu); @@ -1391,6 +1395,7 @@ static int pmu_sbi_device_probe(struct platform_device *pdev) */ static_branch_enable(&sbi_pmu_snapshot_available); } + put_cpu(); } register_sysctl("kernel", sbi_pmu_sysctl_table);