From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796179179; b=tvXICvoxhCYFToKFHFiyanYNPNg3cJqJuAbTN8XInyyZFwxDfdN2wp7oCOF01eOCYA7K aiVzPDUGQmmD1xZlbeLNFuPZ9d4h1r7SdPxcvbiHRgmHqXpS2nSSkxByp/HVes8UBOGKJ eBhkASUyON6v6mmNAeoK+P82GFECRsiTuNsBH8Ri1Da1MWmVL7vDy1vQ9nZ7PvD/UWylL 0EreMlhegoXdsSFPkIoa/Mfu4VlbO/EKZtl+ounciBHX+2z0shdPjm6Jy9GPW5efmbFTq ajQvp37Nl+fsvrfl3ECNP8EGtLTtVnHUHT63RxSRAuKMcgOEyREPbDbU7ozuU1/eY/A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796179179; 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=CHLONqK58fvGa4nG7z39DQC1LpZ2J+t5WL28G68Gvm5uQR/DiYbiLsFgxcTKcEcbcjWL AFnPBQfV5vsrcuErnszxRcWiVth1exSsXuVq9ycOZWS6Ud0UhmKBdJgqA9sq2j9vl9DcA 7xkHtEe5mxrpr9EMn/Gv0Kho/wziyLrG9pDE8C9XIKfG1L2TtPsKKKdeQZ5T0fo/FXQKt cxDYylhEwgZWaeIXzuM0JzhEww2Xac2cBtXI+RMOyb/E5kOZ/r8trnPV4WeF8oFslxfOh 4Pe0ecCyDtwacpQGW9+0DQA7b+mLqi96ZG94erfqDXnZhdthoGCqqFn7G65rJTMcYhg== 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.197 Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (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 19DC7606B7CF for ; Wed, 2 Dec 2026 02:39:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 19DC7606B7CF 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-f197.google.com with SMTP id d2e1a72fcca58-8a064f294cbso9841688b3a.2 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=RcZZ2bUeXExBH3PfrMWDxrnD64wle6g1jSC/xoX/NJBMdafp4qseiLaeDyo3k23lL7 J0E/vePjCKrYrY600BgaYupBWBrmOQA9LBIHLnrV7Qcs8eFiPH4rTcmZeCTDLw1XqglA u6wovLYGCWBoNPoLOS+//z7+TxGTSUUlgqqx6RPLufVXgBInwo6kSa6Fl9COZ4u1wX/C 4b9nGefoxMU4FE2Sq+YgmIoOkbyjhlSY+qoj3/tk8OJTOfhH+76g0Lb72faPid+VY4U0 EmnEBHuh6EV2DftKvq5scdLOtMxJxRWtPfW92lhIIu8xlY3HWvKxfawgbLdXl/HseW4Z QVmw== X-Forwarded-Encrypted: i=1; AL+hErFTe3Pfv2J9KYC841P0iQ5ObUzdI3mn0nIa5q2A+sbtXHC7fy5uRcggRigImU7ua/YaBJUkjPnjeQ==@vger.kernel.org X-Gm-Message-State: APuU4Z+bOZWjZLURSk0VuBi51KgHYH5C1QqTQ6J8pRswa9z+L8WqUz4t CigNAnha0vmmuxoaqrf1mRuyfdbOZ8kl++BSoOUWy/qFGcTVJB5y2sr5RYEXBSOzwbe0lYcv70t 8Yq0wZ5XSVzMmWEh9o75eLA== 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: io-uring@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