From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796179178; b=vx+hyx6zK3J9keo1WuUkTM3d8LWUligIPPOy1HhqpIP8U+DzVYfAejdV7w++BcRRZtHG 1AcV124NPPQdGSPFjF+GRTmIc8Ti/kIrt3qG6/PJwOaSzdxxRICw522+oXqiZtPSAEXln YT+KsYJNVcSO0c+5OAbvz+fkBkBIfCvWsoPPiKZZtRrRciY7vZVQQGhUGwUEQBHrNFZhj fnA0RzBogWBFWS7I9S0o8s20tBgiQp52it3ro+99iXKplvq0MZSQuXZHjFcb6FvPmoIBx dIUKEMKJU+GAykyJ0rm0wd/AF9JFOLy5elOSMDV5GXYoYs6G5Nt7ApFP53c+MY2sJvw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796179178; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=E442JYo85y3qiFHINqVIiTjIuoKvNijr60QcWJGv6Ro=; b=Aq3oadfOVzcTRbShrGkbxPdZE8HRLWo5i4p6kRB1d81dIgSqNE995gbnav5MzqVxTgKU jN1u/yiJGNw9O8rEk0zpctjxX8ktEWDJnmtS4Blg6dlf7RRsscuuPDH3rkzo/8xQUZb7F fAl0MngRXe4zTOmTiYfDNzx/p/lv0TFtUSBvSw55yoVpfhFsm5DX/L+nquc2SOHQ1dDHe QR6/zgCFF8APYV1yUho8V1ieKvEgWx8rrRyXMhbAfKfOgT8IhjBtkzn4qhFfly0dDEFDa L0CfQNOVQPZT3kQvnNoWr4nl9uSH86W6DTnKPcIFsIh1bIUI+q8nVTFqVfEnMwURFYA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=nCjwJi67; arc=none smtp.remote-ip=209.85.210.200 Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25EF4606B7D3 for ; Wed, 2 Dec 2026 02:39:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 25EF4606B7D3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=nCjwJi67 Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-89fb6a45c48so9805221b3a.1 for ; Tue, 01 Dec 2026 18:39:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796179177; x=1796783977; darn=vger.kernel.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=nCjwJi67URp+9dF+ejR/Wcb1+pfx2DDmH5XmWwwFNUK4E+XIFJsMVsDz4cJ4NM73ke eG/4ELaBAHeRfH4E6E6V4ioqCtgkJjZe3SowvcvuegTU0W4n+B1fkf8qv0iDEdI2H616 PRmBK6i7Dm6ZeR7JNjPhyC3qep2aWgwkEPjHFRzPrQUwf/BJ6T50yzl7hQ8xCWKC2aQY he9Q7DEyLJvjgWR4eEZY91RwfDifIOuhaQFLNOG60kSukDFSE+wc0Lfn1104Pna1QjUz AhGmd1cLKTpuXzTHIfeEQpxx5U+zbCuOdoSmdgySkH6eutpr8/W6Pr+4YwPt12jOq2Bq x/Mw== 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=mVCbpFVA7TJISp8eBfPJ2xMn/MDLWgAnFlsqRRQOvbRFC10bBVxYkfcYZY+4O5Z2Sa aP3JGZHDuVl9i+kIYumkel+sJVMkPO4z3FkjuZcEHQm5NhyreDpEOnKUBfH1o8DjTh1h RgAyW7oKT10LFR1kcR94xBsU3inljLgICnV7vOi0wuZqc2SnBwxi6+5msqfMVNzqw08x PCPlLWdyfR4ew5wnZuWNpSVZHAbLHzAhRHxzMkGXz7x8pUc/rDeyAt2qOpGsgvAGn+Mk 70DjBJPmy9uQ8sc8gj8IRMQYJf/QD387pFgDxBVn1ntXC50+Kp3+CQtapZUB6cHDnI/1 bY5Q== X-Forwarded-Encrypted: i=1; AL+hErHPeeUTnbZ7XjWBlJtPRt6ag/zqUfReZcmBYh55y4Xj1FIrL2ul9qc1PhIVNVFih+uqinmxNkNI4Bg5H5E=@vger.kernel.org X-Gm-Message-State: APuU4Z9Fc/bvtXUqjGUNWNYF4Jh1ZYLIpTHt47N0AewYJLbGHFdWWc1E 2IRTt1uDnWKgk1aSxomCxy1KjwQskXSMZOOe718r5dN83hknvq1FeahQG/5/pma0tcUxAqajTn8 IDZyEvgE5eTzObWBBHJiYuQ== 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-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 Content-Type: text/plain; charset="UTF-8" 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