Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2509554rdb; Mon, 20 Nov 2023 12:55:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHjSbtjy8u0KG+bo7SqeY8GMSgKCMJaPy0BUqw+/jd8ytPYIpJLlLPBi1Xbcn33GnKAG8xz X-Received: by 2002:a17:902:7595:b0:1ca:7909:6ee6 with SMTP id j21-20020a170902759500b001ca79096ee6mr6131792pll.61.1700513745483; Mon, 20 Nov 2023 12:55:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700513745; cv=none; d=google.com; s=arc-20160816; b=o6A1JoxVNITdQUe4OK9Nb0ktx2/ZMQqOCqzveNgnuPKjj6WzOYFnqMaEACcMEQWoik XKJHZ7A9g+Y71ID62SznAOQlJPbTcEhaDBa3pTPTR79E3uA6MxTssDHXdV558BhPHJP4 pWtO3AsPJovWDY5eO4UGQyf88B3xXf3ciHcr4rUhNLVA09ZaGiJzgDB5Yjf3Z3BXycKl SZDcdLgHMEpljdtUQ7zW5idhqRJEMlNZ06XDIztftDWAOFwSMyQN2T3J5rozYzN2/dAt 6BYjra9AZ1j3Y4Qr8nyNZhqFTIA3SA5unFovFOI89hrQ0wzh9vBqI3ZGesVxzo8e+T9k SJQA== 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=hTc99U5QpZHJo4970DapfP/0dO6JpKRNReE4z6smZoY=; fh=JZL+K55lXFxcyRYngJxDU2F2dZwuWhBnvU/9dYWYrHY=; b=hldlecre/YkFIlxmuKWFPEx4XO64AaOhmQ3rPm9uqYH86u2KphCOohZbmdVahglyCv 3Maoo9PmH3+wH7dvgN2wrAqHVUpeU0hBtsites4hnx5acAGZGqRDhM6TXO+flnBszI2x td5un2McVRCcbv+7jRDA+7UF44rmH+dXhGb45tl7YwEGsdCbT1xIXdQBzCbk8l74JACj 0dX0yyG8RzoZW86iKUaOtUNJQNPNbGtnoIYauvQu90CKaZltXUhH+MgO8ufIFn63jP9D thDFp+Q+vJj9reyBobS4kKXK/JV35v0iWOlyC7x8CGEavBxmuJZKAaDgz1sYN/BK06rG WTPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=oLQ5Jv2J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id m7-20020a170902db0700b001cf5c9985efsi3388110plx.186.2023.11.20.12.55.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 12:55:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=oLQ5Jv2J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 610FC8039F5F; Mon, 20 Nov 2023 12:55:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230465AbjKTUyt (ORCPT + 99 others); Mon, 20 Nov 2023 15:54:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230296AbjKTUys (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 E51F2CF; 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=T7Nr4r/6B9r8V/IXWfdEL5nzZ2OVp6Lt4IjgQKAxAJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oLQ5Jv2JPcwEa+icp0BZjOHxsNfVcK1LCUYVoZE6SmDGbC4oUBOBiPOLXxmGi1tSE TTU0pgrcELQpQZNXJeXv4CTpqZFJHcp1M9apNGovdE+d3p5eYKVkUlA5EG5cyxu5UL p4gsrZ6RFVRKcyBBpvaCkTTadHxj81t2Brg5uj9sDR/R7sEBe4EPIGcIFDUV8IfDAp a70A5F4j9Fny9L/8f8YtOA7slJQRCi4yiVbOj8gbledJttrdjEBXKMSuX1j02u9uTe eMkqMQT8uVVGDjAWOv6dbzwU4Ez0kp/RrMECEjt+0iB337XZoXPL+CrnboG4fquTxp QeQa34EMelXAQ== Received: from localhost.localdomain (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4SZ0B80w7Zz1cy0; 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 3/5] tracing/bpf-trace: add support for faultable tracepoints Date: Mon, 20 Nov 2023 15:54:16 -0500 Message-Id: <20231120205418.334172-4-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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Mon, 20 Nov 2023 12:55:21 -0800 (PST) In preparation for converting system call enter/exit instrumentation into faultable tracepoints, make sure that bpf can handle registering to such tracepoints by explicitly disabling preemption within the bpf tracepoint probes to respect the current expectations within bpf tracing code. This change does not yet allow bpf 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/bpf_probe.h | 21 +++++++++++++++++---- kernel/trace/bpf_trace.c | 11 ++++++++--- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/include/trace/bpf_probe.h b/include/trace/bpf_probe.h index e609cd7da47e..dd4b42715e5d 100644 --- a/include/trace/bpf_probe.h +++ b/include/trace/bpf_probe.h @@ -42,17 +42,30 @@ /* tracepoints with more than 12 arguments will hit build error */ #define CAST_TO_U64(...) CONCATENATE(__CAST, COUNT_ARGS(__VA_ARGS__))(__VA_ARGS__) -#define __BPF_DECLARE_TRACE(call, proto, args) \ +#define __BPF_DECLARE_TRACE(call, proto, args, tp_flags) \ static notrace void \ __bpf_trace_##call(void *__data, proto) \ { \ struct bpf_prog *prog = __data; \ + \ + if ((tp_flags) & TRACEPOINT_MAY_FAULT) { \ + might_fault(); \ + preempt_disable_notrace(); \ + } \ + \ CONCATENATE(bpf_trace_run, COUNT_ARGS(args))(prog, CAST_TO_U64(args)); \ + \ + if ((tp_flags) & TRACEPOINT_MAY_FAULT) \ + preempt_enable_notrace(); \ } #undef DECLARE_EVENT_CLASS #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ - __BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args)) + __BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args), 0) + +#undef DECLARE_EVENT_CLASS_MAY_FAULT +#define DECLARE_EVENT_CLASS_MAY_FAULT(call, proto, args, tstruct, assign, print) \ + __BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args), TRACEPOINT_MAY_FAULT) /* * This part is compiled out, it is only here as a build time check @@ -106,13 +119,13 @@ static inline void bpf_test_buffer_##call(void) \ #undef DECLARE_TRACE #define DECLARE_TRACE(call, proto, args) \ - __BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args)) \ + __BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args), 0) \ __DEFINE_EVENT(call, call, PARAMS(proto), PARAMS(args), 0) #undef DECLARE_TRACE_WRITABLE #define DECLARE_TRACE_WRITABLE(call, proto, args, size) \ __CHECK_WRITABLE_BUF_SIZE(call, PARAMS(proto), PARAMS(args), size) \ - __BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args)) \ + __BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args), 0) \ __DEFINE_EVENT(call, call, PARAMS(proto), PARAMS(args), size) #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 344a41873445..1eb770dafa8a 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2368,9 +2368,14 @@ static int __bpf_probe_register(struct bpf_raw_event_map *btp, struct bpf_prog * if (prog->aux->max_tp_access > btp->writable_size) return -EINVAL; - return tracepoint_probe_register_prio_flags(tp, (void *)btp->bpf_func, - prog, TRACEPOINT_DEFAULT_PRIO, - TRACEPOINT_MAY_EXIST); + if (tp->flags & TRACEPOINT_MAY_FAULT) + return tracepoint_probe_register_prio_flags(tp, (void *)btp->bpf_func, + prog, TRACEPOINT_DEFAULT_PRIO, + TRACEPOINT_MAY_EXIST | TRACEPOINT_MAY_FAULT); + else + return tracepoint_probe_register_prio_flags(tp, (void *)btp->bpf_func, + prog, TRACEPOINT_DEFAULT_PRIO, + TRACEPOINT_MAY_EXIST); } int bpf_probe_register(struct bpf_raw_event_map *btp, struct bpf_prog *prog) -- 2.25.1