From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795991702; b=Mq2lOtm6yAWfeffVD2f1TnHq47P03JbxH11AUpPBiLjZ8GNd7gbsTE8p9frXfGeLp8mW odDtNj6D3PBNQOaaIoNUlvJHvAiGNf90dybec5n6AhvrYDKvyEH8FsKohujJi/OD/ANal 2oEavK7qcUHWmcoYVo6vGDOCUd2dndv3Zv8sqByd+d/epACinr4QnE7lYtkJ2Lf7lnXKY FqAu0efqKHeTudemqg9GSI3mE8dhBtFidrOzJEWNjLBc81Jdrom+2DUak/ocLtR8b+v3b PRjoqPfoTzceBp7cd+f9DxterJ7Jq2rPke8omJddBUJPAjhAhZVUO7F1XKfU6kPHtrQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795991702; 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=YoeoBKSPk6Pao5qOeykrmeU00LVfXwNGf5PK8HOSSvwX+mmRCkx3i4sJNGfulfRAU9Vm vk2dgBAopAzyShw2jbaW1USl62hcZDe3ZULhLxy4QSIpD1hWO3aLZXN39l22nQgAX7qBW wNkoFl7pP1DjqeIMFWAdGFNrJTFIDecMiep1bXYHIMvxVC+ByoeLOCeRkm6KmrFI14LcI 3u63uBziR+IaCebeARQWrcw+D8XUNuhcvz3WgtVI+Wv4OVketz3vUVhvUylPEskURYGYq potEdyg6HvrKA4BPhQyAWUkkFtEo4EgFZRVkASijC5f5As+vosnOWpNpRO7OE9eCRGg== 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.49 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 6C06D606A33A for ; Sun, 29 Nov 2026 22:35:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6C06D606A33A 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-f49.google.com with SMTP id 5b1f17b1804b1-4bb70074ab2so103375325e9.0 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=tgy/XL6vYS6dc2k4pm6U1zRmXPovknBVMxLlIH9H9MxGsC0/BoPZbVVURj/kA8DFCS pdFuUJrI+Yxx7S00llfTA0DeymhZERCK3Pvhh9bm1dVbM3/kOMlPOI+MRCA7Jwevq4oW GRLGJf0z4NqGh5riTiDrz5QF2trAknjFMUSU1FM7xZvVqG7aVyImGyjA8igWb6yy1fMl 1r6bsgichdnk9FTCflKN0FY7WAkW10TNNH4XeKkJdtSt2AtW6nrkB3Qftli/iRBdJJxT wqKcZBUR1xttnMjp+4J1FwtM0GeAkc30jkMqYaapymj5trG+PVejyL8dY3q60pZ/fMJn Gq5Q== X-Forwarded-Encrypted: i=1; AL+hErFNy5WAl2ymGZ8K5zPCjYuXGP9QulWHYuHWCV0bKD5QkOD0hkql5SZ/kEQ+N9wUjEThmikpAJu6KFJqvRXnHrJksDQ=@vger.kernel.org X-Gm-Message-State: APuU4Z+AqL+eoi5deZ4QLUAs9xxLrVgu2EXh/CX12oRePQtty46uGJI7 ErrIq3bpiX3Q9aOPKzoUaN173RQvsdGp2Reqrs7otw/VJHhX8pJ9RKo2 X-Gm-Gg: AZFdTZc9gF08cLTscRxcb9mgXSxbnpcRSEuVQQC2psoV8EPv6CwHub+YIxLTVsN/TYz hTDlRmGnjdhVaHvUPec8rIssbYbkJ4lmN8d6NKuQZfjPM5zzOYCgWm6CxFdI3dn2SwP0PCOvlB+ GWlsOb2hQMO4YdjJkj+DbeSkF18ACrF00l5Eji69yXAav/o5rh3WUQQUNwhTTIAYiw6Sz66m1Gq n9zPdzRKrk/uM9yL1faZJpcaJTEegDQ44as0IT28ipfpHTwWQ4r4ULTShfBe/mMZL9yB032NQ43 GtROgAKtiUIp8qhNVh7hi/Uw4crDuhylOj85Xj3TQDYRCwW/gDBK69Gf2ksYP19T6Ac/neFSJ5O jAOe5Yq6cBGHGdlTGRBJvlgz7EMFfyQ/j9BmZ/YoQD58J86lGxSfTUnCOy0oDIKzGeZaKIgN2CS OVL/aM6BKd5R+DriVpT4q34gH1rkZUzm0cYST6JsXqjBJ1CNaiXrbXmUvI9Yq23u4e53GvdchH7 EFe/731r9U/phvfLQOcesIjA6JC2/5QHAfOk4onyq5FCFzDBbRKor65yJ0Q5toXjmP3mAE9c4Yx gz/x3WLZB6INOkMtDGIdIjm7ALIbbpF41k+xGFScMCFXd81qKNxHvXI/gfPrJnY4Q32/xABOnjA PRbSuittvjIrU8z0L5NqsKdNtuhG1ABppujuy2Pmv5wXWT8dRAvZesXSh/hVTEl80NBNLhQX+xN svbX5gBcPnHlfIanbwaLhVsddBh3Yynw== 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-trace-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