Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2891678rwb; Thu, 17 Nov 2022 18:23:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf7JWoUUWClAASc6rlDYVEAXja/7H5Pu6vaFGN8yldXmnbF4vl9P/ox6xw3gPiBXCBez9qtC X-Received: by 2002:a17:90a:3f8e:b0:212:d644:fc20 with SMTP id m14-20020a17090a3f8e00b00212d644fc20mr5777658pjc.3.1668738218130; Thu, 17 Nov 2022 18:23:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668738218; cv=none; d=google.com; s=arc-20160816; b=a/RGQNhWhhNohOG3YMoBpmcvfoY6FIvWfP4QDwVZNE1MRdxMgugbpVF7Zq9S1Qk8fz G+G6S8do5NC3jNEEtfXENvFOZ7+G/v4YagEK4kt+gSLmTyVNoJEUArg1aHM7P0+2kwk3 7RXYwwohchtxiKm19dR/DniWEg5JN/tY5sfwg9TvKDy7DgE4w+nBN220bt/gF2F3C2UI zCYKIUSYKg6Yp9a0xLRcExdOyGq+eQb1RWaUDCt0ssMZ12DVJlCk7RDq76HYH83ed32F 2zi6MQKbbudSxE/02nPjnvcsGk8A/BGd6cPWdJU6mDc4/kh8d3KWoTThdhFxXFQOEM9n Xeqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=mVeGwgjkw8SFSZLaTuC1qLOpd/bEt/bbHeW4Bm6uI5U=; b=ehAsK5YbjxbcSrvFKRR4cKo5r2OyY7ImlVO7r+2lx4kMwaGGATGhd98FGjHvodNsMe 1M5ia2tlTpQ+18ivYV03OTUFUzxkx4Hfmhhqe5Qec9FFqjgKjQzkapM1zT5qmFO1mETl lTWUNRMqvZd6FxvwV++3fRo+yUBDggslsE41mRiQbdDG1Q8umwJpGnJVOP7vl49RjTX2 3a+8yiMpcI5a2JWqRsQvxotICxMy2ac1r3AE5HQVQ9aFg58SlRM1/qesiFzPcLhGMqZk IyJH8OI4PyYuWZlUpvbMpiHakZjPbu9DDX67L+a2baFsSfeCHJpVQnUeI4nAXOrS4IMu SuKA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b3-20020a170902b60300b001768a29b9dfsi2387453pls.68.2022.11.17.18.23.25; Thu, 17 Nov 2022 18:23:38 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240604AbiKRCRg (ORCPT + 93 others); Thu, 17 Nov 2022 21:17:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240291AbiKRCRc (ORCPT ); Thu, 17 Nov 2022 21:17:32 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 845B787575; Thu, 17 Nov 2022 18:17:30 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1C6FE6230C; Fri, 18 Nov 2022 02:17:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5ADB5C433C1; Fri, 18 Nov 2022 02:17:28 +0000 (UTC) Date: Thu, 17 Nov 2022 21:17:26 -0500 From: Steven Rostedt To: Rafael Mendonca 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: <20221117211726.4bbbb96a@gandalf.local.home> In-Reply-To: <20221116192552.1066630-1-rafaelmendsr@gmail.com> References: <20221116192552.1066630-1-rafaelmendsr@gmail.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,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 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. -- Steve