From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796261919; b=QZHlo7FhzQqKXWyZ8nOKB1IR0ftBFpM6MyORxilUGO24Om3gWdElp52XB6Z0DiOpzBr1 PFl5Ejumj5JJpqzBu5jIdxnhpTpdsIGZH5lNw+nnhq6eodT6tycvOEk1clReWD/gmzvig yVamdsCRgSA56rYxQb2u32CMjlL4O0W8xvto97l5Rg9RWNdekH6jv68izEZRY5pJwr7Bn WdfpY0D47ylYjSzC8/Ryzs88pWHnUe/EGA+j575mD94nuihWBKCqPy9vxGYki5VJ/IACR i6lGG47Ebiz1WUDEy4IaWYfucIcxhTZx7inxRHzk7rvpAqBUSs+JHwCO4FiFjd8Me3g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796261919; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=i39RA67v9OYjjkffqFRzky9C04/9Toz8msKACDM8a2Y=; b=CYJRXg8cK630ZeHsBvwosxYWuzuEt09CnkIFmHmktSQ4VvJWvXCDE6TYriEKgRoME0Jm 5lYi47veOBNwLHRG/NoSv22/nRMPEUj3O++Qq6nTEHfzAp31TsiNpjkOwf1C6UTfXWUdA jbx+RgdYwPHILXquuMPX/TQgVqJ6/G5xvyKPIWTmo+F4IOQ/JZuHjAYSAP1sPMwaiM4lU 5VOyihMdVbt/wLEq6wkhcWvTppIqYcYH0upqsDu4AZ849KDJ15WHbmUfPoSOMVjeQckV2 a9mPSR+M64Af0F0nMfWqOhjrYWnPqU3i5BBrF8mgBGquG5vHsMZlpASY8qTe7eFqeng== 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=oqp3Wu7M; arc=none smtp.remote-ip=209.85.221.47 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 AACB2606A32D for ; Thu, 3 Dec 2026 01:38:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AACB2606A32D 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) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=oqp3Wu7M Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-4a9be758734so8787864f8f.1 for ; Wed, 02 Dec 2026 17:38:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796261917; x=1796866717; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=i39RA67v9OYjjkffqFRzky9C04/9Toz8msKACDM8a2Y=; b=oqp3Wu7MK5jSYpbbXsAmxLvKQLHCvq/ObPIjjozmyUV2Usoxn2wyyULODkTwr8j8gH qoow+Tp688mY9f4dymfuZ6sVeHq+L8jorTWHU250yz/nTY+vlRa+U5jCw4x15DwIPeaY 2yi1bnhQKQ39Eu7L6zi3CUoD3oyHPbtFZyNUilXO3GnCRr2dYMvOwVhx/JmXqg/GyBYS CrRk9Nk0ygPpttXy/H6mjKDZ24+wNejltXUXh9C0J7fFb1DsfrO1/5cIBHkVNMH3VUH/ cGJ9bGMRdFbRbSjx+L3eCQmOoB7UAoXfQVarjEWpRvABj6mqjgMjG9bP9JaD8DsqEx4r SRAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796261917; x=1796866717; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=i39RA67v9OYjjkffqFRzky9C04/9Toz8msKACDM8a2Y=; b=bQ+TY35JuAhOBWr9hFL+3zUpWVxHzWvzRnCdR7J1moA8UfrFG6tIS7PtzYd/T/ZilJ 2956TCvYwxtCJHrgpz55EHjeMN2aQpmlLEVthH/AaO8xMgMVW6OrMH7MTPQw8AIbp7mU ZXIieukypac+7V5jCNL/Zppu6QzEbzQ4CEy6qucd4mN7zMdGP5MnyTUA9STcdPqEHOWK JZAnTIHxAYs9KjrWy5c9HeWXU+aUUbTCvugTxD2E4PZMbEbJJeBGXRmVNKfcO+N9pLvO y/TG1Z3bPSoIBWsqag0Z3bWms7QO7Sllspt9v6cLHPCe2DaqzjBUZuS5RmljWOlZ9328 SoHw== X-Forwarded-Encrypted: i=1; AL+hErEbgnVsb38U42u+2QZCiER+sSXJhmM8YA41N0zK4HMq9noXkeBOuzsJhoJopn/6Ne6lV6yZA5YjBvC+4ok=@vger.kernel.org X-Gm-Message-State: APuU4Z/IejYXKliGsgF/DgeEWtsFkACni6EuwrYm5XWSbHlInwm4kjTX RKybykrRK8b6yAqfdlFDYlk+hZAdaOAg3dUdBxxndQWs+Zx2PmRMLVWQhqwH0WKt X-Gm-Gg: AZFdTZfp7IQ6vB45URq5GBeEuQy/tmLxB2fmp5TdBfxkLNd5/Eqi8Z6Pf35hy5EMr1t ehEVmfwPYquchQQOP7fGpwdEtozbiaqIT4y0dLfOdN3Dp/u3qrXfsL8ZJgOHUSII7Oxu2YopBRz c5fqVqwIVPoo1bQzGMxdA4kI+C9mgyBpltzdVBOpw+HlL5SFaXvzq12V7yGGkHoFSwbFAhNWZN3 TTWKZvseN/GcJzzUuBYdvOuZQAaJj8MQstCpYbkY+hf/MvuHbj/qlujEWK/oTlnKdqWO0U3Y2jk MdwtoPjN45Ud8SEbAH7uj/xJ7eBe7FnG/eV/zG0Y90ikFQW1aJdDgiMSYH5UoheBYJL1/DVVAjy VyB8Rtx7F6fiI9J43C56Cuj46gzj61/n3N07mUVDT5OANY7+1dlL7+45ISIQhJwiBpTcawdLDC5 9bWZ/v8+q832v35JtufYftudUqFH2+Bn2CI+NX28zkCaFLlyVVp5wQaaYtg2tLFtWiESZJd8gA2 f0H/KA1/fMtI7hEiiT319t3RTBDcMo0MAkNBBTGU+efe2NZZn75ozw5PcUGOXyOjZkAGW/9+Qhu 2/yLtnWeW0/Rcx3Fq2lMezH7BDoLDsUUifhKtr2+e8lRYgw7Ut4Ub+7q8de8RLdasLaoKdQTTea ddw+7nXot/sTFJd3vTzRqtUky/jbssykLul4q5zScZZuRUc9K8w9J14NCKbyleV/U8Xzm6ezHtJ n07RskQGSFKlW5YKdZitvben8rvdOx/EI/9f9r83P5Vsydq24= X-Received: by 2002:a5d:5f88:0:b0:4a9:b6e8:7c6 with SMTP id ffacd0b85a97d-4abab02c3bfmr76828764f8f.8.1796261916921; Wed, 02 Dec 2026 17:38:36 -0800 (PST) Received: from MacBook-Pro-von-Karl.localdomain (dynamic-2a02-3100-b32d-7d01-c8ca-f084-554a-f0a8.310.pool.telefonica.de. [2a02:3100:b32d:7d01:c8ca:f084:554a:f0a8]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6b2050f1sm78249075f8f.38.2026.12.02.17.38.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 02 Dec 2026 17:38:35 -0800 (PST) From: Karl Mehltretter To: Steven Rostedt , Masami Hiramatsu Cc: Karl Mehltretter , Mathieu Desnoyers , Peter Zijlstra , Thomas Gleixner , Song Liu , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] tracing: Keep preemption disabled until the recursion bit is cleared Date: Thu, 3 Dec 2026 02:38:24 +0100 Message-Id: <20261203013824.72197-1-kmehltretter@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) 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-Transfer-Encoding: 8bit Function tracing can falsely reject callbacks for interrupt entry and exit functions, such as irq_enter_rcu(), as recursive. trace_test_and_set_recursion() sets the recursion bit before disabling preemption, and trace_clear_recursion() enables preemption before clearing the bit. If the task is preempted in either window, a traced scheduler function sees the bit set and uses the transition bit. Tracing in an interrupt arriving during that callback then finds both bits set and rejects the callback. Disable preemption right before setting the bit and re-enable it after clearing the bit. Leaving the RCU and recursion checks before preempt_disable_notrace() avoids touching the preempt count on rejected calls. The preempt count helpers then run outside the recursion guard. They must remain untraced, as preempt_schedule_notrace() already requires. Suggested-by: Steven Rostedt Signed-off-by: Karl Mehltretter --- Assisted by an LLM. Changes since v1 [1]: - Move preempt_disable_notrace() after the RCU and recursion checks, following Steven's suggestion [2], so rejected calls do not update the preempt count. - Rebase from v7.4-rc2 to v7.4-rc5. No Fixes: tag. Most callers had the same ordering before ce5e48036c9e ("ftrace: disable preemption when recursion locked") moved the preempt calls into these helpers. Tested on v7.4-rc5 in QEMU x86_64 TCG with PREEMPT, DEBUG_PREEMPT, PROVE_LOCKING, FTRACE_RECORD_RECURSION, FTRACE_VALIDATE_RCU_IS_WATCHING and FTRACE_STARTUP_TEST. Each boot ran fork bursts and the callback/IPI overlap test module under the function and function_graph tracers. Distinct recursion sites recorded, two boots each (function / function_graph): v7.4-rc5 + this patch x86_64 0 / 13-14 0 / 0 All 14 ftrace startup self-tests passed on every boot with no warnings. Earlier v7.4-rc2 tests of this diff with the transition bit removed for testing, distinct recursion sites recorded (function / function_graph): v7.4-rc2 + this patch x86_64 103-105 / 124-128 12-13 / 13-14 arm64 36 / 62 4 / 6 x86_64 ran under KVM with and without VMAP_STACK (matching v1), and arm64 ran under TCG. Forcing a traced call right after preempt_disable_notrace() on v7.4-rc2 was rejected by mainline's recursion guard. With this patch it hung with VMAP_STACK and triple-faulted without it. Replacing preempt_disable_notrace() with traced preempt_count_add() also hung mainline. [1] https://lore.kernel.org/all/20261113011333.20813-1-kmehltretter@gmail.com/ [2] https://lore.kernel.org/all/20261130113108.293e4d1d@gandalf.local.home/ include/linux/trace_recursion.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/trace_recursion.h b/include/linux/trace_recursion.h index e6ca052b2a8..95c3a066dab 100644 --- a/include/linux/trace_recursion.h +++ b/include/linux/trace_recursion.h @@ -149,12 +149,12 @@ static __always_inline int trace_test_and_set_recursion(unsigned long ip, unsign } } + preempt_disable_notrace(); + val |= 1 << bit; current->trace_recursion = val; barrier(); - preempt_disable_notrace(); - return bit; } @@ -163,9 +163,9 @@ static __always_inline int trace_test_and_set_recursion(unsigned long ip, unsign */ static __always_inline void trace_clear_recursion(int bit) { - preempt_enable_notrace(); barrier(); trace_recursion_clear(bit); + preempt_enable_notrace(); } /** base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244 -- 2.39.5 (Apple Git-154)