Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp6581837ybv; Wed, 12 Feb 2020 15:21:25 -0800 (PST) X-Google-Smtp-Source: APXvYqzJCOXRVJVZOaIl612pus8d85PdrcABR2OOD28HKPLm8CEF7neoasfA8t18lGR29g+jkTni X-Received: by 2002:a9d:518b:: with SMTP id y11mr10568170otg.349.1581549685175; Wed, 12 Feb 2020 15:21:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581549685; cv=none; d=google.com; s=arc-20160816; b=qlDv3yY3wO0EIFf0DpR3xuhpUIdv8/fgIVxyqLk9lcRisVN6xqyLxNrHmYEnKreThf rJZnAiTCI4tIPwW74cR8NMuAha/jTUDS/VBhOmlKff7o8A9X1FQHvt1V7cCaVt/hGEhc IVgntJRovZBDCmSoBZRccJ/gPK7AuStIGIiLEAL3uiFXfS4elJE8adjbuvv0AExvEZoq tE1MkjMPvXPPYHjlx8equK1NmzCdOGdXUIQk70PNfs4baZAyYYWorFgmQl2v+RF61rOr 7bi4dleHswpR5kdLZTNEQaMpGekPswPjyWQCHg9f5mMQH7qHBvwlBw9eLj0Mr9L2q8L/ UF+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Kj4wAENiFAyk/ksaomW43f74+pAzdzX97670e6813g4=; b=N7wmpECmTbjp5VrEt/jr64Dwpd9lE6P4eiwjieGUhGdeIBNjw4TmZUDAkhmmbsbWl6 WfQ9zUdzTyk5e4+VMHsmumqm+W1NfbvYEMwFKSSjScgujK9jMwaeIzluFo+CZZIYbQZc rEqrOzuOk4HcJdAQD4COm7+c2dJ4bLjkC+xlfazIEL2K1bYWQU5/IoO7lYTALopTaDOX RGf+TlP5ly+ec6w9bBjwuAJDFtRy8pNLisg+P/cdAY2mpyuhG7EDCcWc/0vspzJUsUPd GoLGweVSX1EduxsG9BlrM7tA6a1jXs9c0iAZUYGHoHAsZLf06iMPr2vXGixH+57RmY0h i+eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=GfOAIlmN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z15si277399oih.41.2020.02.12.15.20.51; Wed, 12 Feb 2020 15:21:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=GfOAIlmN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729185AbgBLXUH (ORCPT + 99 others); Wed, 12 Feb 2020 18:20:07 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:44635 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729119AbgBLXUH (ORCPT ); Wed, 12 Feb 2020 18:20:07 -0500 Received: by mail-qk1-f193.google.com with SMTP id v195so3849397qkb.11 for ; Wed, 12 Feb 2020 15:20:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Kj4wAENiFAyk/ksaomW43f74+pAzdzX97670e6813g4=; b=GfOAIlmNStttHMGlzt0UneZ8tf9pgLrxytukwlUmueS54q+x1mE/xMz3zdtNtH6K6f mpSUawXfAtlBnCv93JHCT/3QXMVcL7I8BeWFpwPcmePMWVJ7Av7stI1qC7aB+qdFICYf zkRY5Gdmf1xUsPc1oNtdGaFP5gj653tUK86lo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Kj4wAENiFAyk/ksaomW43f74+pAzdzX97670e6813g4=; b=ACeKVQWU2hvNtXbh8Zsqlsta4sonUzZX61MEe9WX2NxnAOsch/JlJM08O6Z8Rd5UtJ W7/ziymHotPMxrn+1ica7OiRlLclEzOCz6nTuf/LXPZDnNY3pRSJ9kNvmXMOK9T4klPv 0cPUP1lLbO5Thu5Jw+ulX9QQZx07CjOTC2XImQmRtJnR9cVCMoXQAG7eTG7FRA0ZEe5L TEm9jNZjBwigBDnf/LanlO4opJk3m0ggum2NPeFUmba9pE6gJDwvus97fmEflTocHdMq tRnBJws4rBNTtwfQKLNbud9EmrLDiE8aDMn61SyHnt8AvfzpGtvbiZfR2xg5jWo6ucbr 1h2g== X-Gm-Message-State: APjAAAWqCYtVjZnAe3Z+DYYUgn0HROLgaasJimTSJeKcTzjnqfZlk2Pw lxOkjQ24kZOouGEmNuRlBDuFaw== X-Received: by 2002:a37:4894:: with SMTP id v142mr9265899qka.220.1581549606252; Wed, 12 Feb 2020 15:20:06 -0800 (PST) Received: from localhost ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id q130sm227784qka.114.2020.02.12.15.20.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2020 15:20:05 -0800 (PST) Date: Wed, 12 Feb 2020 18:20:05 -0500 From: Joel Fernandes To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, rostedt@goodmis.org, mingo@kernel.org, gregkh@linuxfoundation.org, gustavo@embeddedor.com, tglx@linutronix.de, paulmck@kernel.org, josh@joshtriplett.org, mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com Subject: Re: [PATCH v2 3/9] rcu,tracing: Create trace_rcu_{enter,exit}() Message-ID: <20200212232005.GC115917@google.com> References: <20200212210139.382424693@infradead.org> <20200212210749.971717428@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200212210749.971717428@infradead.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 12, 2020 at 10:01:42PM +0100, Peter Zijlstra wrote: > To facilitate tracers that need RCU, add some helpers to wrap the > magic required. > > The problem is that we can call into tracers (trace events and > function tracing) while RCU isn't watching and this can happen from > any context, including NMI. > > It is this latter that is causing most of the trouble; we must make > sure in_nmi() returns true before we land in anything tracing, > otherwise we cannot recover. > > These helpers are macros because of header-hell; they're placed here > because of the proximity to nmi_{enter,exit{(). > > Signed-off-by: Peter Zijlstra (Intel) > --- > include/linux/hardirq.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 48 insertions(+) > > --- a/include/linux/hardirq.h > +++ b/include/linux/hardirq.h > @@ -89,4 +89,52 @@ extern void irq_exit(void); > arch_nmi_exit(); \ > } while (0) > > +/* > + * Tracing vs RCU > + * -------------- > + * > + * tracepoints and function-tracing can happen when RCU isn't watching (idle, > + * or early IRQ/NMI entry). > + * > + * When it happens during idle or early during IRQ entry, tracing will have > + * to inform RCU that it ought to pay attention, this is done by calling > + * rcu_irq_enter_irqsave(). > + * > + * On NMI entry, we must be very careful that tracing only happens after we've > + * incremented preempt_count(), otherwise we cannot tell we're in NMI and take > + * the special path. > + */ > + > +#define __TR_IRQ 1 > +#define __TR_NMI 2 > + > +#define trace_rcu_enter() \ > +({ \ > + unsigned long state = 0; \ > + if (!rcu_is_watching()) { \ > + if (in_nmi()) { \ > + state = __TR_NMI; \ > + rcu_nmi_enter(); \ > + } else { \ > + state = __TR_IRQ; \ > + rcu_irq_enter_irqsave(); \ I think this can be simplified. You don't need to rely on in_nmi() here. I believe for NMI's, you can just call rcu_irq_enter_irqsave() and that should be sufficient to get RCU watching. Paul can correct me if I'm wrong, but I am pretty sure that would work. In fact, I think a better naming for rcu_irq_enter_irqsave() pair could be (in the first patch): rcu_ensure_watching_begin(); rcu_ensure_watching_end(); thanks, - Joel > + } \ > + } \ > + state; \ > +}) > + > +#define trace_rcu_exit(state) \ > +do { \ > + switch (state) { \ > + case __TR_IRQ: \ > + rcu_irq_exit_irqsave(); \ > + break; \ > + case __TR_NMI: \ > + rcu_nmi_exit(); \ > + break; \ > + default: \ > + break; \ > + } \ > +} while (0) > + > #endif /* LINUX_HARDIRQ_H */ > >