From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793939436; b=eB2FvNDWhc5OB53AoSWgcdvkGb0BIL3RtvjLqlxlxnW0JFbMvEPG6BzqEqz2MnqPpG/q c6xqmnXqGj3IAlXaJH/LS7NCaDgJSuPVsjbNv0DpIAw8iLLGwlcp0XgiXWFoH+5nMWfr0 aGgb8Y1i0xAJTMvIg/U3h5oOjaFl8uk0FPYHFLIeoDHa1VYOPK2ghOxFVxjOoDPOS6KUr qlzDDlaguegFUwiVoSzj/RPdWYwcq7F6NLWJllMs/zrD2fMyTM5I+jdXAKGG1pKUknHTM /tngs3tPUE8NmtWq/Fma58zPEP73ViySaZtEI0SFofkBzKvyND7WVI8c6ouh/W7yibw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793939436; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key; bh=yhfMQyhA4yeVo/bZMJr9JjklAVTmBlY2c8c0GfiXoB0=; b=S5IcIhiyxfYXIE4oakJXw8fGQtdM/9WeRAAliJdt1UTexKks1gjZeLfRweZ59K6+rmkR /3bJY0doqoteRbFwUKM+HwyTEhxt0lctOfU1XPOlXOX26pTXl9rLxkXS5nBQDYdr+SOKC Psw7kbBYWhHbgVYO++c+nDC1ATGJNmD2YldKg5Kr92u2tmhy2/OwrNrrGyoCpUFIuhoSh nWDkr1LDtEoWR53erbi1GXfzAovru2msm8aH3x6R7Oo9BfdOVgLnqzOgOfO/E9dJyejbr Jp+FIvuvH3YM5dW2myootGwSGb2+aZIq11Prbv9MqUy8IdwOp7p+s/Td9dbGKAd01oQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=dksUbeah; arc=none smtp.remote-ip=209.85.128.176 Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) (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 37DC9606A332 for ; Fri, 6 Nov 2026 04:30:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 37DC9606A332 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=dksUbeah Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-8b33de9d2b1so1119807b3.3 for ; Thu, 05 Nov 2026 20:30:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793939435; x=1794544235; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=yhfMQyhA4yeVo/bZMJr9JjklAVTmBlY2c8c0GfiXoB0=; b=dksUbeahZ8reFu9wOwXHAIUKkSljyGXtB7Sne/QUYMi6K2eeS+eI0O+2atL2v+wz5P nLpw3dDQ257aN+8bZ61k9Ol5Cu5ljugc8G5M2a0mI1fRcmTmgtOEax8D2fPVViXhESwc fYre8Da/L3y8B4sshYo5QS9P+y1NEWh2on7aAJov31U29k/SdGrMVwfYcK5NsdAlWpES hsKu1cXYZSPmsQe9LyTpal5Fb7xMtRq34SpZBtupHqnavHjiVY8U9nLxCeS1b6IV7//N NBXgAwgw28ZeliHf2RBVrPj2jfIDiVR+qAexgCExLqzgcuRHMARe4az6BNLoxdRr1oCk ltLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793939435; x=1794544235; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=yhfMQyhA4yeVo/bZMJr9JjklAVTmBlY2c8c0GfiXoB0=; b=zcaGu3pViWjHE+7g1FPO6L9W8VtugNWwV9tDRPe3ZcfFnpSqvB1L8bBXg/O61/gdW2 csZfzhe6dJA5snlsADcNRsAl4plhAm+USzTPYuxD/V6bU8QeGmoUFG8YGmoBW3heg26c k1aawvNJCoax5ma1HI+ucmee1GLRzOGaNsWIM8+YGwG3IpGkLY30STjmQyKLY42/6207 R+vykLMG+XYCdY2jmf7skNb7WNgQ32hPBUOByYV5rdNhl+WKL9QcZBtO7ZX4TxOqXxhi e0uzAWSMg437hXaO3IjDyWheacfQ5aaGvpiv4R2b0qTbTkH31LW1Xjw+QVVGQAjZgKAW ha1A== X-Forwarded-Encrypted: i=1; AL+hErEV6xsQsTiqUJ88ncThFPMbdD2+mAN+AO0yVXV979R97Z5AiUZp2ojfKwKxagbyJAtZvAp4uhYdcmpjPtQ=@vger.kernel.org X-Gm-Message-State: APuU4Z90xd+doIX8kkC1+RWMo+RMq3rcT0JEDQkskJj7XdarojFap2FH 2PeKrmhvvCY1GT5lT4w/XBCn7fDbp6fmQ4Bse3pdxXwIM3oDkyOhN8ON X-Gm-Gg: AYBFou2jSmJcmbsyLkKvHAdK4zp1QJh8ZV8OpouH9LJhl5RMa4bhQvHssIjGzVte+Hg 9aN2+XMQtm07tcISSF0aXlNt+1Y1+aTcw+2rkYbyxTdga2Trk+Evt8C+Os7dQj4C/rKiZOWjmRF qHW4iYOCKK1y7RinA1CGZ0i73qRq5Qm4UCDadeTzIUXd9qnEu1+MRa7WocmPbhxHJ6hFB4t58Pv yx/Q/8OoaeAHJuMchK8IYwm0yDUoW8Qx610PjebsKW1A1qmfQBbr5UhwRwjqDb3GADHgZXLjEWi FFssVzrFmSQwz+NRbbVaIvPBVPS/6Rq2UJS8yh+3+FN7ToUFMO4FhnhaNRHSaoIwcmfUuLu/PDm 85oF/xew1Qrq7DYw3In7v1JeMLeL1GjHva1mM+P9GbaH7dUJmyWr1z6S0yWGK3BcPxVwCSNjNh8 QLgdC8G+HAXLTX4NZSuxmlGhQxIn/PMm6aEm0dfvzZ9Luv/2IftmtMwJTZNx9BRTHwk7zV5QUnD XROmMDuZ9qsU2pJZ+HjpMm4Uw5pXVGxIUb9h/wTZ8b2hiHVHH9xY9xnjMSslW8++UnFGRocuX46 PQYsXoh3GoUbfhXKfB2SC6SFjOPx59w558kkM79VquUtnp/4Sr3ocNUUDLKflwkUeYVAS1D8uTs dMLABKXXUhA== X-Received: by 2002:a05:690c:39d:b0:8b0:875d:d4d8 with SMTP id 00721157ae682-8b3419c293amr6075207b3.88.1793939435188; Thu, 05 Nov 2026 20:30:35 -0800 (PST) Received: from localhost ([2600:1702:7a90:6f9f:8bc4:8aec:108d:7a04]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8b33f5f3161sm11430927b3.6.2026.11.05.20.30.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 20:30:33 -0800 (PST) From: Matt Turner Date: Thu, 05 Nov 2026 23:30:24 -0500 Subject: [PATCH v7 05/14] alpha/perf: do not report user registers from the entry code 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261105-alpha-profileme-v7-5-c474e892abb0@gmail.com> References: <20261105-alpha-profileme-v7-0-c474e892abb0@gmail.com> In-Reply-To: <20261105-alpha-profileme-v7-0-c474e892abb0@gmail.com> To: Richard Henderson , Magnus Lindholm , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Michael Cree Cc: linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Matt Turner X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3878; i=mattst88@gmail.com; h=from:subject:message-id; bh=LiN+Yv+pum+ZIoYCbCmWoIHtlAzTvYQXPQL0PlKXs7o=; b=owGbwMvMwCW25rVmCc8sv+mMp9WSGLLeht/lmpUzR87t/S379Zd8fDzqVynPmTu/Ie1Yaf9e3 cfZnY1MHR9ZGMS4GGaKKbLErVdkmdW2Y6nPaelfMHNYmUCGSIs0MAABCwNfbmJeqZGOkZ6ptqGe IZChYxQPkdNj0MgsLi5NLdJNKyhyyMsvSSzJzM8r1ssvSM0rSC/QS8tMK8nIyC8qTgUaoZeXWmL q6uhmZGhgYuloYeZk4Whq4uzsZOjk5ujo7OpkZGluYuBs6WjiamnOwMUpAHONfgPD//BZhwKP7v 0Zkbu61uewyqNFy7XXiUW7TLgSOmU2h/DtDa2MDMuseM42BPuGGEneCa//eHFXpMyua+wSpdmye alND7gi+AA= X-Developer-Key: i=mattst88@gmail.com; a=openpgp; fpr=3BB639E56F861FA2E86505690FDD682D974CA72A perf_get_regs_user() returns task_pt_regs() whenever a sample of a user task lands in the kernel. But exception entry runs with interrupts enabled, so the sample can land before the entry code has saved the user registers. Only the part PALcode pushed is valid then. An interrupt taken on the first instruction of entUna, say, pushes its own frame on top of PALcode's, which overlaps the rest of the user frame, so r7 and r8 read as the interrupt's r23 and r24. Report no user registers while the interrupted PC is in the entry code. Such a sample also gets no user stack dump. The range is all of the entry code from entInt to the end of the save in entSys, so it also drops the registers of samples that land after they were saved there. An interrupt that nests on one taken in the entry code still reads the incomplete frame, as its own PC has left the entry code. Fixes: 9280e99d87dd ("alpha: add HAVE_PERF_REGS and HAVE_PERF_USER_STACK_DUMP support") Assisted-by: Claude:claude-opus-5-5 Reviewed-by: Magnus Lindholm Tested-by: Magnus Lindholm Signed-off-by: Matt Turner --- arch/alpha/include/asm/ptrace.h | 12 ++++++++++++ arch/alpha/kernel/entry.S | 9 +++++++++ arch/alpha/kernel/perf_regs.c | 13 +++++++++++++ 3 files changed, 34 insertions(+) diff --git a/arch/alpha/include/asm/ptrace.h b/arch/alpha/include/asm/ptrace.h index 45d1229344b6..1400ba3e7d43 100644 --- a/arch/alpha/include/asm/ptrace.h +++ b/arch/alpha/include/asm/ptrace.h @@ -14,6 +14,18 @@ #define task_pt_regs(task) \ ((struct pt_regs *) (task_stack_page(task) + 2*PAGE_SIZE) - 1) +/* + * Whether pc is in entry code that may not have completed the frame at + * task_pt_regs(). See entry.S. + */ +static inline bool in_entry_save_code(unsigned long pc) +{ + extern char __entry_save_start[], __entry_save_end[]; + + return pc >= (unsigned long)__entry_save_start && + pc < (unsigned long)__entry_save_end; +} + #define current_pt_regs() \ ((struct pt_regs *) ((char *)current_thread_info() + 2*PAGE_SIZE) - 1) diff --git a/arch/alpha/kernel/entry.S b/arch/alpha/kernel/entry.S index 790389a15c3c..b8d7804e5aa3 100644 --- a/arch/alpha/kernel/entry.S +++ b/arch/alpha/kernel/entry.S @@ -186,8 +186,14 @@ /* * Non-syscall kernel entry points. + * + * Between __entry_save_start and __entry_save_end the frame at task_pt_regs() + * may not be complete. perf uses these to avoid reading it. */ + .globl __entry_save_start +__entry_save_start: + CFI_START_OSF_FRAME entInt SAVE_ALL lda $8, 0x3fff @@ -479,9 +485,12 @@ entSys: lda $8, 0x3fff bic $sp, $8, $8 + /* PAL_callsys does not save these, unlike the other entries. */ stq $16, SP_OFF+24($sp) stq $17, SP_OFF+32($sp) stq $18, SP_OFF+40($sp) + .globl __entry_save_end +__entry_save_end: mov $0, $1 lda $16, 7 diff --git a/arch/alpha/kernel/perf_regs.c b/arch/alpha/kernel/perf_regs.c index 33ea2e831ba0..894683851b30 100644 --- a/arch/alpha/kernel/perf_regs.c +++ b/arch/alpha/kernel/perf_regs.c @@ -59,6 +59,19 @@ u64 perf_reg_abi(struct task_struct *task) void perf_get_regs_user(struct perf_regs *regs_user, struct pt_regs *regs) { + /* + * Exception entry runs with interrupts enabled, so a sample can land + * before the entry code has saved the user registers. PALcode has + * pushed only its part of the frame, and the rest may hold an + * interrupt's frame. An interrupt that nests on top of one taken here + * is not caught, as its PC has left the entry code. + */ + if (in_entry_save_code(regs->pc)) { + regs_user->regs = NULL; + regs_user->abi = PERF_SAMPLE_REGS_ABI_NONE; + return; + } + regs_user->regs = task_pt_regs(current); regs_user->abi = perf_reg_abi(current); } -- 2.55.0