From mboxrd@z Thu Jan 1 00:00:00 1970 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 7008EC54735 for ; Tue, 27 Aug 2024 12:56:28 +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:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=kRAU3j0x/hY1PPyJPR7V31fkou9aBH92tfEd029oaq4=; b=lYRTNZzGtksp6qCQqss9vYwewi EGgEHfsmaaJY/O+EN34+VEq++tA0g4KxSYXNvx7cSiYDcleYMuw8tioimDzY/z21QfKRZckLVN9Wm hk6h502M7zEEjWtvWWSQaKEFwexjoZug4UHOzUY0zGIIPSUNdET574FTXdDiDTIecU/9uc4H9Qmew tmUSmDacTOGCbuHy0lfypsmFzafzVT4tyPGoUScYvX5iDJUaKqOc2bn63UPsSh80uvV3AminKIAok CQ2IJJ3x6a2fE650PW7CIZb0bviS6sC0zW2So1WcLFNGkCClURfz1hQf4mun8r8BskVnMyphd0Kfr NAq9uiiw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sivkA-0000000BLnM-3R30; Tue, 27 Aug 2024 12:56:18 +0000 Received: from nyc.source.kernel.org ([2604:1380:45d1:ec00::3]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sivhd-0000000BLFb-2sb2; Tue, 27 Aug 2024 12:53:43 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 010BCA41986; Tue, 27 Aug 2024 12:53:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95F09C6105D; Tue, 27 Aug 2024 12:53:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724763220; bh=y1WUu1jEStLUVI5qg4HDk+K18wMW0OvXnCReTnAjNZM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mxFOPqqELuSLP3A0GzfeK1isECIgDfVOyMzXRQlpDlE5td3JdPslpGNHS/aBEOqTm PoiHIbloJkUgAIDELfCqqLjp4B060qQemc9wc3XwzmSFmKS5VK3ZVEvZuH5JQdfQvN cHoj5DPLWBq2x+QeHCvY3+W0oUmGzxJXDL6PvpNzspaD4vi5ihWiPLCA15vJPYIono z/hbPY8MoNFrBriVkjsPSydjljktkb+4Am4OJW9PvQuRXdmLtsako2CZqiytnN6JaV NeWPwutj5QepgD/ZovHDiJx5xCp+qhiPzPsnK1t/zMV8Si6g17UGWlwqjcedHNh3/n nVghFDV7xzFfw== Date: Tue, 27 Aug 2024 13:53:35 +0100 From: Will Deacon To: Alexandre Ghiti Cc: Atish Patra , Anup Patel , Mark Rutland , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Nam Cao Subject: Re: [PATCH -fixes] drivers: perf: Fix smp_processor_id() use in preemptible code Message-ID: <20240827125335.GD4772@willie-the-truck> References: <20240826165210.124696-1-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240826165210.124696-1-alexghiti@rivosinc.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240827_055341_809767_E36E19EB X-CRM114-Status: GOOD ( 19.61 ) 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 On Mon, Aug 26, 2024 at 06:52:10PM +0200, Alexandre Ghiti wrote: > 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 > --- > 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(); Are you sure it's safe to enable the static key with preemption disabled? I thought that could block on a mutex. Will