From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1A15606A32C for ; Wed, 2 Dec 2026 02:39:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=mUuqJYr7; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=eT8fefjp; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=kTVUnS7m 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:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Unsubscribe-Post:List-Owner; bh=ony9qBd4b7dU28Ld4u+515vGeFjqL+35wIzeCSaosdQ=; b=mUuqJYr7zc+BiN4wkUFNNhaNuY fUo+I5mAVqEyp6nK9YV+AM8rwtrQriZEw+5nLFs6fJo5exgLi+8Xhq8utyxsO0NJKP/mE1p+RxR+j PCWu6lNHx0ABi1NSdT4DS8COqavPoXm6Z6+zgHs2jeJUQbaai854PwFcbC/8+rmP3OsK5BOB0La1B m5bbu9OwKWtBwzIhUei94J5pNGqyRr/IoKAKfxO/gXdWrEM4G9A5hvDDvivCoQkFlZDWesdJVfEuE ALue7RzJgEw48CWHJhozpSSqZQvvwfW7X9UClKgm/LWSOrfswosqCgy+UY1mjgaocEbPOON5KQakY 7FqY1PNQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYaG1-00000009ymQ-3nwV; Wed, 02 Dec 2026 02:39:45 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYaFz-00000009yhQ-1yke for linux-riscv@bombadil.infradead.org; Wed, 02 Dec 2026 02:39:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: Message-ID:References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=E442JYo85y3qiFHINqVIiTjIuoKvNijr60QcWJGv6Ro=; b=eT8fefjpRsANgWMC6VR0vZIedB fz7XJA2LaslzNjxHtiM/vi2j81UH/ypDA/f0HAOFwaeN+B87U+i8Pr6e8M3QlthGdCVoTZqKXfaiZ +JF0Ee4fiPVjDoxEHd1Y7wVmo9NHgFxUrIqDGz89CPW6xhL5yjkvI85yqt+q5f4IByYKtI0nS4ltR dr9KZctK9ce8TOruHHTalHL/EB3sgoeSXxJJOn/pVs/epHLKlhfpw4XzgWMReFgy/TjHsZNl+L4Mi J3CTfWXb0+RjUD6b3tA6RHXHYwzm/0AgeZn7U1nx+ZW03BZUrUYU6rgwQQdPZScOVd9hOXqLUjqfF 8D+nc6Nw==; Received: from mail-pf1-x446.google.com ([2607:f8b0:4864:20::446]) by casper.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYaFw-00000000XLE-0nvR for linux-riscv@lists.infradead.org; Wed, 02 Dec 2026 02:39:42 +0000 Received: by mail-pf1-x446.google.com with SMTP id d2e1a72fcca58-8a064f294cbso9841685b3a.2 for ; Tue, 01 Dec 2026 18:39:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796179177; x=1796783977; darn=lists.infradead.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=E442JYo85y3qiFHINqVIiTjIuoKvNijr60QcWJGv6Ro=; b=kTVUnS7m+7jR6e3xK5oLkZPt/NtI7zZoR8I2XBZy+aBx4XgM5WpyKc3wHV7TSJCKf2 1cDWfP/7F3iht3uJwG3OSuBYWwqfjw/H2A11DDLdqOQcyc+77xDx/6inKT2Jo4Qa6azz CNP/VtPb5ZHXtuqNS+SOE1qECnTclkWFdg7YG/AEVVwPcK24iU/ZkYpJWqRblsfgfSop 1WfOY7YffujkggOCExjlUTETm2Ilc1C7IVfcA0KAy28iflpxwYf8ZTByJhtH7wFIf1Bl bTochgfZ0Qd1OvN+oidQRoEXdg+XSmysJ65Nxu/A9rd/cMn69Q/m7Wc6ypa9oepbPGNn nN/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796179177; x=1796783977; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=E442JYo85y3qiFHINqVIiTjIuoKvNijr60QcWJGv6Ro=; b=gOjcT43M69WlrMe7Lx7y0y5Bsde0o8j+m1paQnGXZshf8MwF7iUfKsh4wgVif+MMJe ZGSBAJd7PQL08uJe1Z6xQHsHxna8WhtVo8h4dBlgi4wT7xPXdUMO6Y9sZs4ycYOWOCWd 2gw1vG1PfiXj+Yk2ik5gaM2GZ3dzyUt6LDgdtg5Dh5zGri1+x/AhuG3ebGa1n1VgSgNt oeEcbB9pJVIwmqEdsJrw9P7nXWhgHyHukW9p1ic3t86wxaAl19D750oGuHJj6V4zvd9n 7gbukZ3Vn5oR1RMkL8WwARe9Us+tPCzaTtcAUhE8nd2Ysrjhox4EJ9OpVJk60BpuY8su TPsQ== X-Forwarded-Encrypted: i=1; AL+hErEhPxaX35gAEC6tAT0mapbtvgIEzyGckdvH0uuo0ICekOh2ycL/8q/uniVmENNUdTF3ElL2MvVSLNuCqQ==@lists.infradead.org X-Gm-Message-State: APuU4Z+gMFfk6UM7oN6iZINjyWI0dCQy4BSDjkiMAgq2jBJIMOfmPX2I wBwo0uOk0SDuFyWMcEHTLfVGioROK+RzNLFNiGKe8AONXwK/VpLVvNJ8m1/4PYPDyEQkMxj09VJ 2ys72xM0N045EZ5XSJn4ftA== X-Received: from pfbld1.prod.google.com ([2002:a05:6a00:4f81:b0:88f:f68e:660b]) (user=jthoughton job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:4407:b0:89e:cfbb:e8a2 with SMTP id d2e1a72fcca58-8c8793b7dd6mr36946682b3a.4.1796179177082; Tue, 01 Dec 2026 18:39:37 -0800 (PST) Date: Wed, 2 Dec 2026 02:39:15 +0000 In-Reply-To: <20261202023920.595207-1-jthoughton@google.com> X-Archived-By: Mime-Version: 1.0 References: <20261202023920.595207-1-jthoughton@google.com> X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261202023920.595207-9-jthoughton@google.com> Subject: [PATCH v2 08/12] powerpc/perf: Don't read user memory without an mm in BHRB decoding From: James Houghton To: Andrew Morton , Alexander Viro , Arnd Bergmann Cc: Sean Christopherson , Paolo Bonzini , Jim Mattson , Jens Axboe , David Hildenbrand , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , Madhavan Srinivasan , Chris Zankel , Max Filippov , Dinh Nguyen , Simon Schuster , David Sterba , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , KP Singh , Matt Bobrowski , Peter Zijlstra , Arnaldo Carvalho de Melo , Namhyung Kim , Steven Rostedt , Masami Hiramatsu , linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, io-uring@vger.kernel.org, James Houghton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261202_023940_303862_1089CEC4 X-CRM114-Status: GOOD ( 16.53 ) X-Spam-Score: -9.5 (---------) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" X-Spam-Status: No, score=-16.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 power_pmu_bhrb_to() reads the branch instruction at a user address to compute the branch target of a BHRB entry. It runs from the PMU interrupt. The BHRB is cleared when a task is scheduled in, but not when a task exits, so between exit_mm() and its final schedule, an exiting task can still have its own user branches in the BHRB. On ISA v3.1, which only records user branches, they stay there for the rest of the exit; on older processors, the kernel's own branches push them out after a while. If a CPU-wide event with a branch stack samples the task in that window, e.g. during exit_files() or exit_task_work(), power_pmu_bhrb_to() reads one of those user addresses with current->mm == NULL. (The task's own events are already gone, as perf_event_exit_task() runs before exit_mm().) This doesn't read another task's memory: the mm that is still loaded is the exiting task's own, so the read either faults, if exit_mmap() has already torn it down, or returns the right instruction, if another thread still uses the mm. But a later patch in this series makes the uaccess helpers warn when current->mm is NULL, and this path can be reached by anyone allowed to open CPU-wide events (CAP_PERFMON, or a low enough perf_event_paranoid), so it must not get there. Check for a NULL current->mm first, and treat it like a failed read. Signed-off-by: James Houghton --- arch/powerpc/perf/core-book3s.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c index 10ded865583c..88425e40854c 100644 --- a/arch/powerpc/perf/core-book3s.c +++ b/arch/powerpc/perf/core-book3s.c @@ -471,6 +471,13 @@ static __u64 power_pmu_bhrb_to(u64 addr) return branch_target(&instr); } + /* + * The PMU interrupt may hit a task without an mm, e.g. a kernel + * thread, which has no user memory to read. + */ + if (!current->mm) + return 0; + /* Userspace: need copy instruction here then translate it */ if (copy_from_user_nofault(&instr, (unsigned int __user *)addr, sizeof(instr))) -- 2.56.1.911.g883d8bcb20-goog _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv