From patchwork Mon Nov 20 20:54:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 167377 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp210877vqb; Mon, 20 Nov 2023 12:55:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKqxjNcryFAWug8Ks9Nc9fUMBS6REtkNwA3iAQ8CzBeY3thM66jKxVguiKE3c0Vp2/ifNO X-Received: by 2002:a17:902:968e:b0:1cc:361b:7b10 with SMTP id n14-20020a170902968e00b001cc361b7b10mr6935095plp.24.1700513701782; Mon, 20 Nov 2023 12:55:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700513701; cv=none; d=google.com; s=arc-20160816; b=xM5pYSubn7xyOnDTOx6DytaJz/yoc5mFEhp11CZz5Wf3YXuNXqa4cgcre2Z9CFfcBe sAlt8UZEVLAhoeClX9jf8KBM5WEi8mC6CH6r0SYcRaTQFT3YWYIc15x4odKEaZ8XyJxU gUUFJuJW2zqqApwBW3cBH2q0LIiaAPlOgAJCSAfc6DaQ3/KODngZoCxP5kgaKR8T9Dgy Ea4hzfwhkey3krg3HqkVJhK1VWg3uxEVVOPGG0dowabXmH1Im36AbUFnGdytSfd2AbRe qVx+CVuNFVVunBZvzHWqmoagOz1GQW3gkZnG/iI3+ug4UtssgqgTWuTB+2X48Tk85cay G2vQ== 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:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id e13-20020a170902d38d00b001cf641feee3si1889226pld.494.2023.11.20.12.55.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 12:55:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; 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:7 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 snail.vger.email (Postfix) with ESMTP id D5936801F763; Mon, 20 Nov 2023 12:54:59 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231724AbjKTUyy (ORCPT + 27 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 X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED,RDNS_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 20 Nov 2023 12:54:59 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783117855294705079 X-GMAIL-MSGID: 1783117855294705079 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