Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3572696imm; Mon, 6 Aug 2018 07:07:44 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdDn7PKTSDpdWWZQSAbbg+BibOJZ5V0YKIQD0CKEZa9rfIdtKypLtAbJgf4T44XZqKuJaaU X-Received: by 2002:a63:f616:: with SMTP id m22-v6mr14494095pgh.293.1533564464217; Mon, 06 Aug 2018 07:07:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533564464; cv=none; d=google.com; s=arc-20160816; b=DEc3rP22Oh1aEmsW6wjNDgX2Qcxf02M1jczj5pLPfP+T1TyTiEvIeE6EFxGbCewbaI 4ZbyXvUW1mLhF8XxCuLXSd5kFJGBnw90821TKhG5lbmGMYkbV1yYa8Ym27D+/U0cg5/T uMfXZg9xBs8KPZv5/HvWHV+IGHkaWHm0lH+f0NMIZRzCuad3ZumXkJffJznT8FuCDKBQ PO5nG8RwMRT0kgBFvEdi1ys875+HcbpQyLexK2D1mhQPLxMS4JaaxEFbDyiHfTdNRjgk R3CrdxWhzyis6ieVqhddSilfiwDFZde0N7dbvqayCg1tHbIx95XDL7Am94ZE1/+I6wED Jsvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=02uacHau/WGUjIVDazwDiZBDz5vZqzQLd6Z5w6RRZVU=; b=q69L4wAlezkiQvsRW7a6C2XXcz1+I361ttG8IxSbpSHb5P2QQp/icOpfU3fDQq1LIy JjRlLwdbJ8Bxn55QxU9vgOKdmn56nlHW6mf2ETXFbq2beiCagcsOGrAuDTQbfzxvzpBY //FO0Irp6yi0PPw5M1Y8W5YACiVc4vZvlPZMXxTECrUXlCcUjuIZXuTboT00zriaLrPu Q0KXhQ/tGvSZDsUcieX3ubrb7Qw812pABD6dycJS6XbyPIIZZJStb8kdrqG3uPIG5bnh QWWkTxfK6n84T+5wdnQqCTIByFx9SZi7sQAlfJ5Y4GygqK7P/++93Al8fKz+bbCPofcr OVbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Vc6Xgr4M; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l18-v6si14573573pfk.78.2018.08.06.07.07.27; Mon, 06 Aug 2018 07:07:44 -0700 (PDT) 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=@kernel.org header.s=default header.b=Vc6Xgr4M; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730503AbeHFQO5 (ORCPT + 99 others); Mon, 6 Aug 2018 12:14:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:58072 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727451AbeHFQO4 (ORCPT ); Mon, 6 Aug 2018 12:14:56 -0400 Received: from devbox (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 98F6421A34; Mon, 6 Aug 2018 14:05:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1533564340; bh=9gGrIi8dWYj25wd843ZKxaqaU70mPpGD2hdXizsph4g=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Vc6Xgr4MYJGF/eTrx2+9QOJW6hjU/ayl59MMnoAMSwuEUIsIYKkuAjWkdXnHsQFsX 1sjhUNp/wkk26E7M7YEfNvncLkRlNA4wcSJt+jIk6HzWuLjMyXrT2bBRc9T9+vRLGK p0iHESfQ5ULSxYhv7T2/LbF+2YUKFVctZ1g+i//8= Date: Mon, 6 Aug 2018 23:05:36 +0900 From: Masami Hiramatsu To: "Joel Fernandes (Google)" Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, Ingo Molnar , Steven Rostedt , Masami Hiramatsu , paulmck@linux.vnet.ibm.com, mathieu.desnoyers@efficios.com, namhyung@kernel.org, peterz@infradead.org Subject: Re: [PATCH ftrace/core] tracing: irqsoff: Account for additional preempt_disable Message-Id: <20180806230536.ef217b2c2c008838606bedc3@kernel.org> In-Reply-To: <20180806034049.67949-1-joel@joelfernandes.org> References: <20180806034049.67949-1-joel@joelfernandes.org> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 5 Aug 2018 20:40:49 -0700 "Joel Fernandes (Google)" wrote: > Recently we tried to make the preemptirqsoff tracer to use irqsoff > tracepoint probes. However this causes issues as reported by Masami: > > [2.271078] Testing tracer preemptirqsoff: .. no entries found ..FAILED! > [2.381015] WARNING: CPU: 0 PID: 1 at /home/mhiramat/ksrc/linux/kernel/ > trace/trace.c:1512 run_tracer_selftest+0xf3/0x154 > > This is due to the tracepoint code increasing the preempt nesting count > by calling an additional preempt_disable before calling into the > preemptoff tracer which messes up the preempt_count() check in > tracer_hardirqs_off. > > To fix this, make the irqsoff tracer probes balance the additional outer > preempt_disable with a preempt_enable_notrace. I've tested it and ensured this fixes the problem. Tested-by: Masami Hiramatsu And I have a comment on this code. > > The other way to fix this is to just use SRCU for all tracepoints. > However we can't do that because we can't use NMIs from RCU context. > > Fixes: c3bc8fd637a9 ("tracing: Centralize preemptirq tracepoints > and unify their usage") > Fixes: e6753f23d961 ("tracepoint: Make rcuidle tracepoint callers use SRCU") > Reported-by: Masami Hiramatsu > Signed-off-by: Joel Fernandes (Google) > --- > kernel/trace/trace_irqsoff.c | 26 ++++++++++++++++++++++++++ > 1 file changed, 26 insertions(+) > > diff --git a/kernel/trace/trace_irqsoff.c b/kernel/trace/trace_irqsoff.c > index 770cd30cda40..ffbf1505d5bc 100644 > --- a/kernel/trace/trace_irqsoff.c > +++ b/kernel/trace/trace_irqsoff.c > @@ -603,14 +603,40 @@ static void irqsoff_tracer_stop(struct trace_array *tr) > */ > static void tracer_hardirqs_on(void *none, unsigned long a0, unsigned long a1) > { To ensure this function must not be preempted even if we increment preempt count, I think you should check irq_disabled() whole this process, put below here. if (unlikely(!irq_disabled())) return; Since irq_disabled() will be checked in irq_trace() anyway, so no problem to return here when !irq_disabled(). > + /* > + * Tracepoint probes are expected to be called with preempt disabled, > + * We don't care about being called with preempt disabled but we need > + * to know in the future if that changes so we can remove the next > + * preempt_enable. > + */ > + WARN_ON_ONCE(!preempt_count()); > + > + /* Tracepoint probes disable preemption atleast once, account for that */ * Even we do this here, we are sure that irq is disabled in this context. * which means preemption is kept disabled. > + preempt_enable_notrace(); > + > if (!preempt_trace() && irq_trace()) > stop_critical_timing(a0, a1); > + > + preempt_disable_notrace(); > } > > static void tracer_hardirqs_off(void *none, unsigned long a0, unsigned long a1) > { Same here. Any though :) ? Thank you, > + /* > + * Tracepoint probes are expected to be called with preempt disabled, > + * We don't care about being called with preempt disabled but we need > + * to know in the future if that changes so we can remove the next > + * preempt_enable. > + */ > + WARN_ON_ONCE(!preempt_count()); > + > + /* Tracepoint probes disable preemption atleast once, account for that */ > + preempt_enable_notrace(); > + > if (!preempt_trace() && irq_trace()) > start_critical_timing(a0, a1); > + > + preempt_disable_notrace(); > } > > static int irqsoff_tracer_init(struct trace_array *tr) > -- > 2.18.0.597.ga71716f1ad-goog > -- Masami Hiramatsu