Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp648043rwb; Fri, 18 Nov 2022 06:33:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf6Z3GBqeVclWxnmlevQHMgrHjhseqr5DJlOYb8gWeDG1EdGT/Ps13LsrfIwe2nDBhcgNYm7 X-Received: by 2002:a17:906:af65:b0:7ae:41e6:9076 with SMTP id os5-20020a170906af6500b007ae41e69076mr6308523ejb.321.1668781993624; Fri, 18 Nov 2022 06:33:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668781993; cv=none; d=google.com; s=arc-20160816; b=UAbfPiXAxzzL8fkN3goO6RZz/GCOXbcBzTjSInXBwxJZzdUSMYAiWa2iyQItsE/A9a 10Wgwx2fEHhMd1ACWZMrAuhjk0h3dcANZOXUOh+61721rbd/GylAkb8ORrGTcCOacitJ D1Lb9YmHt3cmdW8qPx+WI8NE4WCP/7qiBcJDjIj5VMbLUwNskXYV4bo54tB7vpkcr/Lr 9I4jZcJtPC4en29LAz4Sj4Fhqqs3urnSAM1TPjDJ6G59k+bkakvS0NsjXnN0JjkPmbKb VdUiqc4Dq1E7CTvUco4ae3cHb7tMRPcsEXTDWFBYC+mngLcNnP3JHxyXcKNXmhEVICf1 X+SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=CeypTGsSQ7hIMjMqb97acJUIT2o1NQ3MZu5l62YdM1U=; b=qsRzzZta36JjcpT+goLfsGA3O62uCqr6GtvJr+5b/fxreqnIotH3/3nO3BlMZ8nhX2 Lvy5ljK8+7EEbcG+H9kG3uWq5w/mckcTrrcLC+SD8te2xgTj9sGuo4YWTi4mSHWuCQeA LSaMa9mUgA1u/zaSfIISeoNrFjUfhKSAmzc6mbUZr2GXjot0/tR46US7XWdkp4rjFFXD 39UOP10x96pbiV4fl/mf4GGBHn/Gjuhf7CJhIxUV3ei/LBzlcs9B2vS1/wUHfe58mu2/ 2N6kn43VJ5V7J59siQeqGgi8d3OrdIaSOj35sQk0AYuPgI7wZzyOvh17JP58uOva5ZAj 5nvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GEHvLShA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ds2-20020a0564021cc200b00461891a8138si3236738edb.446.2022.11.18.06.32.44; Fri, 18 Nov 2022 06:33:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GEHvLShA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240700AbiKRNhV (ORCPT + 91 others); Fri, 18 Nov 2022 08:37:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242036AbiKRNgW (ORCPT ); Fri, 18 Nov 2022 08:36:22 -0500 Received: from mail-oo1-xc2f.google.com (mail-oo1-xc2f.google.com [IPv6:2607:f8b0:4864:20::c2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6C8696705; Fri, 18 Nov 2022 05:34:45 -0800 (PST) Received: by mail-oo1-xc2f.google.com with SMTP id t15-20020a4a96cf000000b0049f7e18db0dso771736ooi.10; Fri, 18 Nov 2022 05:34:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=CeypTGsSQ7hIMjMqb97acJUIT2o1NQ3MZu5l62YdM1U=; b=GEHvLShAbIGmNaho6pyZ66GONWFROU14cnZomsWqLHcRDc1dbiHUynvkq6gM7tOPyb NLtqglztFcPlZjGgUmIUxJ7rpcRYZotezE6E9B9n55PEMgDiMuLCbrBRprMyaVY2dfm4 AqcwbS9XbMqFw6QJDd0TnsMYUTFzMAVb3mNXA2G1ub9IfaCweCQ6atEiNmIo4ERlPRZW Fo7X14u/99YWOwLoe0ZHkKPkJRhSe++WcmNCabvTyCB9Qz9AP4KEWtJOv762SX+6ufj2 6sER7Q4BtpwVEK51dSWUzbsuauxUmpPXxrnFGV2TLCmJ8mla2wsHXGRVAwYsJrIw6DL1 3wtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=CeypTGsSQ7hIMjMqb97acJUIT2o1NQ3MZu5l62YdM1U=; b=Vfwdz4fNaYL2cB2DO2Vbrn0snJytLHEJ6tmhrmvsL5K3i3NAIc9fiHk74242XTAWDp BS+RrNLKciq2NlQM+51/g8q9IxPQVZsPLQ7iTMAw6uyKGBf0pcBnwJ3vjKGm/UEOaWU9 hJ2/Zw5T0jImqBfTpnykDL0hb2DmYu+ZT4DEV6xwXur0BG8Wt4r+2/tCNk2hEKzTFmVU QOEE4/8BWAAEiLZ1z+GuqVjAhC2C89cOulODQa1rB1MO6l98B89fhKI7hrSmwe8Hn1er fyQhmI8lEu03RrHBGCj0Q7kcwhyztZZEgoyet/oDZCrdzvBZb1b1uB+5/oqxcVYhdPgf x0ZA== X-Gm-Message-State: ANoB5pnRnZ96N3Jh9YEYnJS1xpk1oW/7H7BvmRCaAuLx4t0sJl9o8fic p3gHEd/rvxfLIq97Anovk/w= X-Received: by 2002:a4a:d404:0:b0:49f:69ab:4afd with SMTP id n4-20020a4ad404000000b0049f69ab4afdmr3483297oos.19.1668778485003; Fri, 18 Nov 2022 05:34:45 -0800 (PST) Received: from macondo ([2804:431:e7cc:5fdd:4170:7dca:de7e:f578]) by smtp.gmail.com with ESMTPSA id 187-20020aca06c4000000b0035485b54caesm427421oig.28.2022.11.18.05.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 05:34:44 -0800 (PST) Date: Fri, 18 Nov 2022 10:34:40 -0300 From: Rafael Mendonca To: Steven Rostedt Cc: Masami Hiramatsu , "Tzvetomir Stoyanov (VMware)" , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Tom Zanussi Subject: Re: [PATCH] tracing/eprobe: Update cond flag before enabling trigger Message-ID: References: <20221116192552.1066630-1-rafaelmendsr@gmail.com> <20221117211726.4bbbb96a@gandalf.local.home> <20221117213109.6119750e@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 18, 2022 at 09:40:09AM -0300, Rafael Mendonca wrote: > On Thu, Nov 17, 2022 at 09:31:09PM -0500, Steven Rostedt wrote: > > On Thu, 17 Nov 2022 21:17:26 -0500 > > Steven Rostedt wrote: > > > > > On Wed, 16 Nov 2022 16:25:51 -0300 > > > Rafael Mendonca wrote: > > > > > > > That happens because enable_eprobe() will eventually trigger the > > > > kmem/mm_page_alloc trace event: > > > > > > > > - enable_eprobe [trace_eprobe.c] > > > > - trace_event_trigger_enable_disable [trace_events_trigger.c] > > > > - trace_event_enable_disable [trace_events.c] > > > > - __ftrace_event_enable_disable [trace_events.c] > > > > - trace_buffered_event_enable [trace.c] > > > > - alloc_pages_node [gfp.h] > > > > ... > > > > - __alloc_pages [page_alloc.c] > > > > - trace_mm_page_alloc // eprobe event file without TRIGGER_COND bit set > > > > > > > > By the time kmem/mm_page_alloc trace event is hit, the eprobe event file > > > > does not have the TRIGGER_COND flag set yet, which causes the eprobe's > > > > trigger to be invoked (through the trace_trigger_soft_disabled() path) > > > > without a trace record, causing a NULL pointer dereference when fetching > > > > the event fields. > > > > > > > > Fix this by setting the cond flag beforehand when enabling the eprobe's > > > > trigger. > > > > > > > > Fixes: 7491e2c44278 ("tracing: Add a probe that attaches to trace events") > > > > Signed-off-by: Rafael Mendonca > > > > --- > > > > > > Thanks for the report, but I'm worried that this isn't enough because of > > > how memory ordering can happen on different architectures. That is, just > > > because you switch the order of updates, doesn't mean that the architecture > > > will honor it. > > > > > > I don't want to add memory barriers in the fast path, but instead we can > > > simply check if rec is NULL in the handler. > > > > > > So basically: > > > > > > > > > static void eprobe_trigger_func(struct event_trigger_data *data, > > > struct trace_buffer *buffer, void *rec, > > > struct ring_buffer_event *rbe) > > > { > > > struct eprobe_data *edata = data->private_data; > > > > > > if (!rec) > > > return; > > > > > > __eprobe_trace_func(edata, rec); > > > } > > > > > > And this should be documented. > > > > > > > In fact, does this fix it for you? > > It does. I found this while enabling eprobe for all events in my setup. > Doing the same test wih the proposed patch it did not trigger any issue. > Thanks. It did not trigger the NULL pointer issue to be more specific. When creating event probe for all events I was unable to create any event for the xhci-hcd system: root@localhost:/sys/kernel/tracing# echo 'e xhci-hcd/xhci_add_endpoint' > dynamic_events -bash: echo: write error: Invalid argument Debugging the issue it seems that the problem is in the is_good_name() check, which returns false for "xhci-hcd". Should we sanitize it by converting '-' into '_'? > > > > > I'm going to take this patch and reference you as a reported-by, as I have > > a lot of urgent code that needs to got upstream, and I need to start > > testing it. > > > > Thanks! > > > > -- Steve > > > > diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c > > index 5dd0617e5df6..6b31b74954d9 100644 > > --- a/kernel/trace/trace_eprobe.c > > +++ b/kernel/trace/trace_eprobe.c > > @@ -563,6 +563,9 @@ static void eprobe_trigger_func(struct event_trigger_data *data, > > { > > struct eprobe_data *edata = data->private_data; > > > > + if (!rec) > > + return; > > + > > __eprobe_trace_func(edata, rec); > > } > > > >