Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2509830rdb; Mon, 20 Nov 2023 12:56:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IGn6vRs+6ugmHJ2AH8Hlk03Iebc5mBtdPixBg26e2JbbJsgRj79JQ+gn+7wvg1aiLPao2d4 X-Received: by 2002:a05:6808:14cd:b0:3a8:43d5:878b with SMTP id f13-20020a05680814cd00b003a843d5878bmr3787291oiw.2.1700513782863; Mon, 20 Nov 2023 12:56:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700513782; cv=none; d=google.com; s=arc-20160816; b=zCHoqOVAO7rG0Ii2jtDJwwJaoB1v46dMhbC1x8i36/Cpnas+2PzGxQd6PWR03FyJaV 1x7wheSRU9E6uMocC1HDIS1fhAFXua99xN5CkZFFo65ebOZlPiGZgveipWajZKoSOtE/ fWegFkWD9FWgZcyYo8dTuiXggMAvsfYMsEXfNIIsekTQl6R0P25Ys/Jn+aUNcG3/3qf2 f2AcJI/bFXzHWM8jIVjDcfSDaGA3rUaj4uDlvwdT9jOlBhwyyI89eijOVj7dN2/coxgD iZDrUjMcn8Lw/SIg7QJpQnzJOHAFdRqVqQCq3/bhQsbyiyvJz0RbhDL8aF3dOPTwxFZP E1Nw== 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:date:subject:cc:to:from :dkim-signature; bh=uhPGCTfPEyhleVGHSQGIWrRH/PSYsUhWP4eniAeNcOs=; fh=JZL+K55lXFxcyRYngJxDU2F2dZwuWhBnvU/9dYWYrHY=; b=HmxiIoGq10BzVHhCJtYorM9DVBeiT6HP5W2DA+oEnnCqqtuTmwcw66MSIsr/urYWX1 4m80EzJuDD6e22BnyfZlbT9p+wWwizsNxCWqGbbkitc02VnfVBcPPOR3bpp/tBVcf63U AV33SE3mgAmUJgqSC3nOb7tGRv2rncBlsQWikEIRTQUC0jfWcHUUbeiKygLTv8OLgWh5 ICqDvQpInas7Wq8T7lkJ7fmmif681zMAi1Xnxg0JhsKaE4hX8GWHrS4jzvYyNowgIphr E1UnO5v5NdzddXZDVQ61zx4d69LcqlteOZhUZCA1T+BWob/PTAsNsigPRTfSvw20aU8M xclQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=UVLZmdzA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id r27-20020a635d1b000000b005c1b283fd08si8087086pgb.73.2023.11.20.12.56.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 12:56:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=UVLZmdzA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id CB4FF8096593; Mon, 20 Nov 2023 12:55:52 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231557AbjKTUyy (ORCPT + 99 others); Mon, 20 Nov 2023 15:54:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230357AbjKTUys (ORCPT ); Mon, 20 Nov 2023 15:54:48 -0500 Received: from smtpout.efficios.com (unknown [IPv6:2607:5300:203:b2ee::31e5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5F2DDC; Mon, 20 Nov 2023 12:54:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1700513680; bh=Daj+/1NhYCfniiA2tUuq6iASXun5yE8kO5F1mYx3zX4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UVLZmdzA+6t/55WMLsBXzqGOH8ntevxRZQqooyook/p6evO7BV6kRTHOkHQSjrDyh sgj8aO9h/0cs/5EmYRRmMU+kJLDaFW2SgpvGgEOIBgiEXZTnSylEfkU0GuZIOZMkNb E1JKWFH4vgz4bgrLhBUih5or6T0ROIy4GtJAoVxvnPgYdwBS0MF9VDjU2mtNI9ExGT CUUTDmJeyPtUKOrDfSkGlB/e977Z9bUpqJSVAKZSlPZnyCRPi7kX5e0cLMm/pPXN+k VfGPh9tcOOJ1RZaPQVb6xxx4DzDe7YDytJvsIjmuxUkk94Rjn+DJY/yMvpjjEqDMoZ /ebfrTLj3uixQ== Received: from localhost.localdomain (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4SZ0B83q4Sz1cb0; Mon, 20 Nov 2023 15:54:40 -0500 (EST) From: Mathieu Desnoyers To: Steven Rostedt , Masami Hiramatsu Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Michael Jeanson , Peter Zijlstra , Alexei Starovoitov , Yonghong Song , "Paul E . McKenney" , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , bpf@vger.kernel.org, Joel Fernandes Subject: [PATCH v4 4/5] tracing/perf: add support for faultable tracepoints Date: Mon, 20 Nov 2023 15:54:17 -0500 Message-Id: <20231120205418.334172-5-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231120205418.334172-1-mathieu.desnoyers@efficios.com> References: <20231120205418.334172-1-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 20 Nov 2023 12:55:53 -0800 (PST) In preparation for converting system call enter/exit instrumentation into faultable tracepoints, make sure that perf can handle registering to such tracepoints by explicitly disabling preemption within the perf tracepoint probes to respect the current expectations within perf ring buffer code. This change does not yet allow perf to take page faults per se within its probe, but allows its existing probes to connect to faultable tracepoints. Link: https://lore.kernel.org/lkml/20231002202531.3160-1-mathieu.desnoyers@efficios.com/ Co-developed-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers Signed-off-by: Michael Jeanson Cc: Steven Rostedt Cc: Masami Hiramatsu Cc: Peter Zijlstra Cc: Alexei Starovoitov Cc: Yonghong Song Cc: Paul E. McKenney Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Mark Rutland Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Namhyung Kim Cc: bpf@vger.kernel.org Cc: Joel Fernandes --- include/trace/perf.h | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/include/trace/perf.h b/include/trace/perf.h index 2c11181c82e0..fb47815f6eff 100644 --- a/include/trace/perf.h +++ b/include/trace/perf.h @@ -12,8 +12,8 @@ #undef __perf_task #define __perf_task(t) (__task = (t)) -#undef DECLARE_EVENT_CLASS -#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ +#undef _DECLARE_EVENT_CLASS +#define _DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print, tp_flags) \ static notrace void \ perf_trace_##call(void *__data, proto) \ { \ @@ -28,13 +28,18 @@ perf_trace_##call(void *__data, proto) \ int __data_size; \ int rctx; \ \ + if ((tp_flags) & TRACEPOINT_MAY_FAULT) { \ + might_fault(); \ + preempt_disable_notrace(); \ + } \ + \ __data_size = trace_event_get_offsets_##call(&__data_offsets, args); \ \ head = this_cpu_ptr(event_call->perf_events); \ if (!bpf_prog_array_valid(event_call) && \ __builtin_constant_p(!__task) && !__task && \ hlist_empty(head)) \ - return; \ + goto end; \ \ __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\ sizeof(u64)); \ @@ -42,7 +47,7 @@ perf_trace_##call(void *__data, proto) \ \ entry = perf_trace_buf_alloc(__entry_size, &__regs, &rctx); \ if (!entry) \ - return; \ + goto end; \ \ perf_fetch_caller_regs(__regs); \ \ @@ -53,8 +58,22 @@ perf_trace_##call(void *__data, proto) \ perf_trace_run_bpf_submit(entry, __entry_size, rctx, \ event_call, __count, __regs, \ head, __task); \ +end: \ + if ((tp_flags) & TRACEPOINT_MAY_FAULT) \ + preempt_enable_notrace(); \ } +#undef DECLARE_EVENT_CLASS +#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ + _DECLARE_EVENT_CLASS(call, PARAMS(proto), PARAMS(args), \ + PARAMS(tstruct), PARAMS(assign), PARAMS(print), 0) + +#undef DECLARE_EVENT_CLASS_MAY_FAULT +#define DECLARE_EVENT_CLASS_MAY_FAULT(call, proto, args, tstruct, assign, print) \ + _DECLARE_EVENT_CLASS(call, PARAMS(proto), PARAMS(args), \ + PARAMS(tstruct), PARAMS(assign), PARAMS(print), \ + TRACEPOINT_MAY_FAULT) + /* * This part is compiled out, it is only here as a build time check * to make sure that if the tracepoint handling changes, the -- 2.25.1