Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp645018lqs; Tue, 5 Mar 2024 11:58:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUxA1qjDRGQHoBsFnUzfzh56E9L4r8bzictU5wvy7CgOYl2AR2d76WXb720p4reAJJ2tHT75V+BN/HbEqUgVdhHbBF6wsWqYq6P3UIb7Q== X-Google-Smtp-Source: AGHT+IELFlT7c4lZu29zBQdGbg4BujOJrZmXUEcemBfWVtcYBpVqjEyC3qTNBn5kajENoptLg0E2 X-Received: by 2002:a17:906:1d55:b0:a44:e371:a31b with SMTP id o21-20020a1709061d5500b00a44e371a31bmr6822160ejh.10.1709668723924; Tue, 05 Mar 2024 11:58:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709668723; cv=pass; d=google.com; s=arc-20160816; b=ZoeN3SoCQO2g/uFUwo9lik+VpePjLMx9HdMABrpuY4hYWbynQl7HaCd167RbimQ+cz 3XbQDseY8VpkutVreNMs1YQ1dHkXEF7dPZ+TY3jIeXTQ3AikJSj8de0v8H3thuHlz5KU KOw6S3TWb2UJ5yn0xcHpa9b7j+ChNx2OKbUCzpuDajUvREMztNqc/ojqmVDwjiZPeHAM +z//pN3E9ESKtYXFhsUiablvDD0d8iuE5Cjsg1QIRRvzqtoud4fZsB6Ojaxsd81z+ZA7 jjjAy4FXSoJjG/pN3HaUoe1OV3Gxrv7natvAFRQnNzbrzRrb8G3QughgI09hJTf45tKO pxfA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=bu6OOQSRl1sDFQs7j7Vd7xby0Zeb6tsaJ5E1lIc+eTs=; fh=yxBF47Yp9rtUv4Wv3gxAStHTSRvgkZrMILitYWewjqM=; b=y9OZ3PXWSPZQ6afHXh9VRjpH8qFwXZPATqw22E+uoLDnHXI99khlGxjXGEt7c+d6TL 253eE1SB5OpL+usgvvda7UCH56Zwf1ieDZbIg6vwk+qNNKrAic1Eq1E62vliKxFDpc53 9IkfOx4NFSBUI2UXRfJ/MP5+DQf7/lFetDo1EssSCOb2QrI3WD8eU8YhFsjLUGkgLXaa 06eGz2EjkHWv9lLiUTgGm850VWCAQZJ+n+TfP0wMzO6r6bHFAPWoaUvVwBrBfyJew6ny PsfpyMTVX2flr5h4hAa+vNTPhEIf4dQ+sUjGkqCmMWuZOiHjQaZxEJXX7qwK9JvC8cNI eDSA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-92917-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-92917-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id sh35-20020a1709076ea300b00a448c94aa35si4464367ejc.554.2024.03.05.11.58.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 11:58:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-92917-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-92917-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-92917-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A391C1F26048 for ; Tue, 5 Mar 2024 19:58:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4E8CD86AD7; Tue, 5 Mar 2024 19:57:49 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 13CF65C601; Tue, 5 Mar 2024 19:57:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709668668; cv=none; b=LVT/2LN6PF9O8J35lq4YyoKGRYHrv6SqBMCH2PHk1TLUZIYoBna4zAIYL7gLgHWwd9L3zT7Tb3tMzAt0WIzUYoRFMreiN0VlzSOjCn2GWFDesx4R1tsXYosDtoJvAuBCO/LKIT2rYzQAil84P81MjtmK2ukj/427TUp1lSE3CCI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709668668; c=relaxed/simple; bh=aYz9x/2baT4VzDD9DzcaMPV6cSDul7JABLqGj4Vy7fU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TMPpQ3dMVlwxiJZPPPv+G+Y4wcfQKT+pTR+K3yEls29BIfnAPV9E47SS7sU6dzWNu49s0FLRufxBCtaE0jdgYtHeXgf2d3AUmH1Gr0/M7T9FzXPZHgtiudNPUwzM2SuNVF5nCo+3vcyTVSF0azW8fel02NJOsjaGwN8+DOG/VDw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B6C4D1FB; Tue, 5 Mar 2024 11:58:21 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.69.116]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9325C3F73F; Tue, 5 Mar 2024 11:57:43 -0800 (PST) Date: Tue, 5 Mar 2024 19:57:40 +0000 From: Mark Rutland To: "Paul E. McKenney" Cc: Joel Fernandes , Steven Rostedt , Network Development , LKML , rcu@vger.kernel.org, kernel-team Subject: Re: [PATCH] net: raise RCU qs after each threaded NAPI poll Message-ID: References: <55900c6a-f181-4c5c-8de2-bca640c4af3e@paulmck-laptop> <10FC3F5F-AA33-4F81-9EB6-87EB2D41F3EE@joelfernandes.org> <99b2ccae-07f6-4350-9c55-25ec7ae065c0@paulmck-laptop> <1e8d070e-5616-4c6d-a08b-4b6e1a0a2bad@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1e8d070e-5616-4c6d-a08b-4b6e1a0a2bad@paulmck-laptop> On Tue, Mar 05, 2024 at 09:53:42AM -0800, Paul E. McKenney wrote: > On Mon, Mar 04, 2024 at 04:16:01AM -0500, Joel Fernandes wrote: > > Hi Paul, > > Thank you, Joel! > > > On 3/2/2024 8:01 PM, Joel Fernandes wrote: > > >> As you noted, one thing that Ankur's series changes is that preemption > > >> can occur anywhere that it is not specifically disabled in kernels > > >> built with CONFIG_PREEMPT_NONE=y or CONFIG_PREEMPT_VOLUNTARY=y. This in > > >> turn changes Tasks Rude RCU's definition of a quiescent state for these > > >> kernels, adding all code regions where preemption is not specifically > > >> disabled to the list of such quiescent states. > > >> > > >> Although from what I know, this is OK, it would be good to check the > > >> calls to call_rcu_tasks_rude() or synchronize_rcu_tasks_rude() are set > > >> up so as to expect these new quiescent states. One example where it > > >> would definitely be OK is if there was a call to synchronize_rcu_tasks() > > >> right before or after that call to synchronize_rcu_tasks_rude(). > > >> > > >> Would you be willing to check the call sites to verify that they > > >> are OK with this change in > > > Yes, I will analyze and make sure those users did not unexpectedly > > > assume something about AUTO (i.e. preempt enabled sections using > > > readers). > > > > Other than RCU test code, there are just 3 call sites for RUDE right now, all in > > ftrace.c. > > > > (Long story short, PREEMPT_AUTO should not cause wreckage in TASKS_RCU_RUDE > > other than any preexisting wreckage that !PREEMPT_AUTO already had. Steve is on > > CC as well to CMIIW). > > > > Case 1: For !CONFIG_DYNAMIC_FTRACE update of ftrace_trace_function > > > > This config is itself expected to be slow. However seeing what it does, it is > > trying to make sure the global function pointer "ftrace_trace_function" is > > updated and any readers of that pointers would have finished reading it. I don't > > personally think preemption has to be disabled across the entirety of the > > section that calls into this function. So sensitivity to preempt disabling > > should not be relevant for this case IMO, but lets see if ftrace folks disagree > > (on CC). It has more to do with, any callers of this function pointer are no > > longer calling into the old function. > > Assuming the loads from the function pointer aren't torn by the compiler, > they will be loaded by a single instruction, which as you say cannot > be preempted. Might be good to have READ_ONCE() if they aren't already > in place. As a heads-up I'm actively digging through case 1 now and I think the existing code is actually redundant or broken depending on architecture and configuration (but largely redundant, hence not seeing any reports of an issue). I've dug through v3.14 up to v5.4, and I'll hopefully have a writeup of that out tomorrow, or in the next couple of hours if I continue after dinner... I haven't yet looked at cases 2 or 3 yet, and I haven't convinced myself on how the CONFIG_DYNAMIC_FTRACE=y case works either. Mark. > > Case 2: Trampoline structures accessing > > > > For this there is a code comment that says preemption will disabled so it should > > not be dependent on any of the preemptiblity modes, because preempt_disable() > > should disable preempt with PREEMPT_AUTO. > > > > /* > > * We need to do a hard force of sched synchronization. > > * This is because we use preempt_disable() to do RCU, but > > * the function tracers can be called where RCU is not watching > > * (like before user_exit()). We can not rely on the RCU > > * infrastructure to do the synchronization, thus we must do it > > * ourselves. > > */ > > synchronize_rcu_tasks_rude(); > > [...] > > ftrace_trampoline_free(ops); > > > > Code comment probably needs update because it says 'can not rely on RCU..' ;-) > > My guess is that this comment is left over from when that call to > synchronize_rcu_tasks_rude() was open-coded. ;-) > > Maybe "We can not rely on vanilla RCU to do..."? > > > My *guess* is the preempt_disable() mentioned in this case is > > ftrace_ops_trampoline() where trampoline-related datas tructures are accessed > > for stack unwinding purposes. This is a data structure protection thing AFAICS > > and nothing to do with "trampoline execution" itself which needs "Tasks RCU" to > > allow for preemption in trampolines. > > Sounds plausible to me, but let's see what Steve's thoughts are. > > > Case 3: This has to do with update of function graph tracing and there is the > > same comment as case 2, where preempt will be disabled in readers, so it should > > be safe for PREEMPT_AUTO (famous last words). > > > > Though I am not yet able to locate that preempt_disable() which is not an > > PREEMPT_AUTO-related issue anyway. Maybe its buried in function graph tracing > > logic somewhere? > > With the trampolines, isn't synchronize_rcu_tasks_rude() paired with > a call to synchronize_rcu_tasks()? In that case, rude's only job is > getting all CPUs out of their previous sojourn in either the entry/exit > code or the deep idle loop. RCU Tasks waits for each task to voluntarily > block, which takes care of all tasks executing elsewhere. (Recall that > RCU Tasks ignores the idle tasks.) > > > Finally, my thought also was, if any of these thread usages/cases of Tasks RCU > > RUDE assume working only on a CONFIG_PREEMPT_NONE=y or > > CONFIG_PREEMPT_VOLUNTARY=y kernel, that could be worrying but AFAICS, they don't > > assume anything related to that. > > Good point, most generic code should need to tolerate preemption in > any case. But I have nine commits queued thus far that handle some > CONFIG_AUTO breakage or another, so a little paranoia won't go too > far amiss. ;-) > > Remaining on my list are uses of the various CONFIG_PREEMPT* Kconfig > options, both in code and in Makefiles. Though who knows? Perhaps Ankur > or Thomas have already done that. > > Thanx, Paul >