From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795991703; b=UENElJvTbNDS8BXeExL/rzvy9opZvxTwp/sA+kQP5HKhKUn6chkA/bJG6g+7DqaA4V0n pTCbNmfw2o+n17wHxp6k/hlKP3y0HAe+dceb791bg4Ss0bMcc8CLS3PHEhQqCnyRkcvyZ YOwewRN6oStkrAjcC5x/1h1w8wNQmMQr7EWZJJq51xxZ7XeiFgRwZTBvz1KOF+2Oy8Jzb JiANXgIZCUhWBc/zaqytD+Lo2Ugme7U6aL1Hj2RM8qoXQhH5KmiE0nmGz4w+IMZmZkaWS b3pLF37bi+pslviGaGkLFDiKZx53a4ai+A8VURfMSmCB13SrWxh3rF7jcNxb4EjFv5g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795991703; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=hvAYV51RvRfp4TQU06qRLTAY1U//NhdjOyYgvBOZ8Lw=; b=TL1p1pSLc4SQc9aEGI5oN4zbPDnWX7eyYJGSGZGnWU8wamhQMgGOC+I443JNmZLXrgKy H0+ibs41iV56ozDRHv9fSj3BSCMgNGftfW4FhYwAasbhc2AkRepo0ruG+och+wzRj0/Nt 6s3lEDoUewxqArCA0MLO4QRQG5H/nzm5YglayOld0i2dCc305tmBnVKrbWumbWUGLPXP5 nBormPFMo/JQuoT09vVpn12oT+h55XO9N3wF2Jfu8keVSWF29vZkNde2SnEKa0ika70re SXqk2vRXxijrKkttaXN/s825YkjFXyHoVjVF+Sr8h9EWbKzWnbJSiWbe6V8ysAAgdMA== 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=gSQFS0Ba; arc=none smtp.remote-ip=209.85.128.41 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 69BA2606A31C for ; Sun, 29 Nov 2026 22:35:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 69BA2606A31C 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=gSQFS0Ba Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4a5b2be99a8so77285155e9.2 for ; Sun, 29 Nov 2026 14:35:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795991701; x=1796596501; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=hvAYV51RvRfp4TQU06qRLTAY1U//NhdjOyYgvBOZ8Lw=; b=gSQFS0Bay6Ia7HMn3yCpRBHsTkULK4TRGwHZCKi+yqAYWxql5duRcJof4zgJEK36f8 LvALyUucivy3WSkj4MWLZjMECQW4gbHzKgYkoJ7/SqucHsdQPm7sHKxooe3cxvkXA9Lv atlwf7xQdEW16HRuYVMU+rpB9IkyyR9p+LWYK8i2tUVyOOEMlQ/DgyJIhFEtSsi+iOjJ eyTSbvwfZWpdUhtqCLxNMGabQpyNwVt/UA75tOX6xx2XcrAe7wInPSVfj6EX71Tzz9ie 08qPJueLSSGITuvhgKQx73/Fw5MpHkV4GGvsJQF5BJg2IwAKElPBvpVjVYfHKMKaNfkI p8LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795991701; x=1796596501; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=hvAYV51RvRfp4TQU06qRLTAY1U//NhdjOyYgvBOZ8Lw=; b=e6Iik2pTNg7dNYwLCE3eBHPYIleTqnhCqOot+r/L/AsNRHTUKeIbMe6lg7f2QKhx4T VkCyOVUkZnePQWuT3g4FMCHC1XKI4WT72/UMGoDnIqPYCaQY1fTOnVpFqvCclHGPLQjk 4CG22kGMxqo0genxjvIsFTtqllUZkC+SomceXCfxBIABUMRT8RuUIx87L9ZCn9qSktR1 0IKLBoguxfxVC94gxNEfmjkqIsTvLfXSgQc5uTRIR7o/+Bq3IIPE1Dn5A1JuOCYBXkQb xM/IDw/2D+XTtxp+r3pxM7V1id8oo6m8WLM6Qufc5Iz2ETT2sdm188ATiTITlMugpOD7 McLA== X-Forwarded-Encrypted: i=1; AL+hErEhFdQEl2VoS29vRVUqaUMiFRDYo+xcICkC1YZGOdJqL9nKQ5K4m+Jd5LF2vDewZpdvy6DWD8NV2zvy3TI=@vger.kernel.org X-Gm-Message-State: APuU4Z9MBALNMHisDuY34kISpvgWg3qTz1NqkRWWP4YWcYZW1khD8m/C eaHECAeXTyBIwE9b1eyhkS3UqIhyk/QKtLdptDnweYsa4YM4C4QSeh91BQh/nA== X-Gm-Gg: AZFdTZfu0wJavnVoR3g1FDXbsGSOjwjVVvMwrlBrafrcAX1N+oR/rFOeO2fIPcf8e+j DalnCBPnszwSTBD5mqnqfrVw5RiJyL5gkto52agKoG2lBnQvLlPC9Q4oKTrmsAPhVFZKzAWFIlX ttnjfgqST5dwc92VVAVd9bedSrOiNzmdDntzCoEmoX5Uo7zYS9NumJ8UHUf4pCKl1NEvQzF1ygP IFc3mrqqBj+TblL8ZYfzYIwIWBhTLiGCF6QeOnxzzfYNvraJBgiT7L/BdCMgednH0VKa5VtCAIW m/XyoIv3tTgmIppVoDcFymbTtIvEJJV5mSZyQHAmQAF+QgHo2nmxPMBvfcOSniWoW1n8Q5pP1MM FIY8v71Wcy5hg8UC4fg5Jlsk7AvmVl9eARfX5fuPEFxE1i9cxE6JJCmetXKA7NOhmeJqRRtEYFV JBbn4xyHh0XRJr4ndFAZY9J0HurhcogDVbabUKrL2tBiJ20PFsVBynJPZJEVkOsOo4UYysMwuto ++a/5c5BESrOi6p3hqZrjkyfNIPh2oz+6fQNJGTJVzrdKv6fWLmamspDuCvORCdFf+QtnwCONbv +Zfft3JDafGm8HVeSo5wm46kqZC73LgM2/yQAOyRwS8eSeeiLw9c3KGizBM3oGUnlAI0QdWd5Qo qzoUXJYIOPXmvsHTiPrtk8aE3pzjq4Kns3cMj6P7RY2yoznO1qSVA9JkPVmR63dPZ9TvZTPABL7 tPbYhNjODncfwsEsK5Gbp7TtJTugHMOg== X-Received: by 2002:a05:600c:a0b:b0:4b7:6a8b:9df2 with SMTP id 5b1f17b1804b1-4bb8882432bmr623497815e9.25.1795991700548; Sun, 29 Nov 2026 14:35:00 -0800 (PST) Received: from unknown748F3CBA5068 (dynamic-2a02-3100-a047-bb01-803a-be9e-8fb5-20e9.310.pool.telefonica.de. [2a02:3100:a047:bb01:803a:be9e:8fb5:20e9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb853a9687sm983064435e9.10.2026.11.29.14.34.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 14:35:00 -0800 (PST) Date: Sun, 29 Nov 2026 23:34:57 +0100 From: Karl Mehltretter To: Steven Rostedt Cc: Masami Hiramatsu , Mathieu Desnoyers , Peter Zijlstra , Thomas Gleixner , Song Liu , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] tracing: Keep preemption disabled until the recursion bit is cleared Message-ID: References: <20261113011333.20813-1-kmehltretter@gmail.com> <20261124111425.487a2ec8@gandalf.local.home> 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=us-ascii Content-Disposition: inline In-Reply-To: <20261124111425.487a2ec8@gandalf.local.home> On Tue, Nov 24, 2026 at 11:14:25AM +0100, Steven Rostedt wrote: > > + preempt_disable_notrace(); > > + > > bit = trace_get_context_bit() + start; > > if (unlikely(val & (1 << bit))) { > > /* > > @@ -145,6 +147,7 @@ static __always_inline int trace_test_and_set_recursion(unsigned long ip, unsign > > bit = TRACE_CTX_TRANSITION + start; > > if (val & (1 << bit)) { > > do_ftrace_record_recursion(ip, pip); > > + preempt_enable_notrace(); > > return -1; > > Honestly, the reason I did it this way was because if for some reason > something in preempt_disable_notrace() was traced, this would catch it. > > I guess we could change it to do it this way, but if something were to be > traced in preempt_disable_notrace() it would triple fault and reboot the > machine with no warning. :-/ > Good point, better keep this check. Making the acquire preempt-count update call traced preempt_count_add() confirms it: the current order catches it on x86 and arm64 (recorded in recursed_functions), while my patch locks up both with no output and triple-faults x86 without VMAP_STACK (under TCG, and in 1 of 12 KVM runs, with gdb attached). Over 99% of scheduler runs with the bit held on x86 come from preempt_enable_notrace() in trace_clear_recursion() rescheduling before trace_recursion_clear(). Moving only the reschedule keeps both count updates under the bit: static __always_inline void trace_clear_recursion(int bit) { barrier(); __preempt_count_dec(); barrier(); trace_recursion_clear(bit); if (unlikely(should_resched(0))) __preempt_schedule_notrace(); } With traced count updates, this still catches the recursion on x86 and arm64. Without them, rejected callbacks per boot on x86: current this change my patch TCG, function 6-58 0 0 TCG, function_graph 755-1463 0 0 KVM + KASAN, function 160-291 0-12 0 KVM + KASAN, function_graph 104-362 0-14 0 With KASAN, this change hit rejects in 1/10 boots per tracer. On arm64 KVM, all variants had 0 rejects in 23 boots each. Two short windows remain where an interrupt can preempt with the bit held (between setting the bit and preempt_disable_notrace(), and between the decrement and clearing the bit). In the KASAN runs, those were the only scheduler entries with the bit held. Would you rather drop the patch, or go with one of these? 1. Send the partial fix above as v2 (keeps your check, fixes >99%, leaves the two short interrupt windows). 2. Reorder as in my patch using small noinstr helpers for the count updates (closes both windows, objtool checks noinstr on x86, loses the runtime check, adds a helper call). Thanks, Karl