From patchwork Mon Nov 20 20:54:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 167379 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp211437vqb; Mon, 20 Nov 2023 12:56:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IHxeJoVFqcDDasMbd7m5W5fCyirjjoPITD/XpC8BNfx9YFAN3Y9EQxt7twPLNK3Pw/LWmeL X-Received: by 2002:a05:6830:11ce:b0:6cd:4358:1f02 with SMTP id v14-20020a05683011ce00b006cd43581f02mr9666203otq.34.1700513781424; Mon, 20 Nov 2023 12:56:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700513781; cv=none; d=google.com; s=arc-20160816; b=iTONxhzMDnxXGeZmh2b5zn5JaWK8v0x2zhdy8RrnXVZHEabT+y6Qtye0LMk2i50SIQ TnVuploMVhBttdNPTSaaY1++mLxQcbvQ40Tp7xcU7X6laftbf1zTFUMuXIRILdqXiKsK +mIoy8TlRjcqpzHnTTeOokvHd5JvIOZokaNysLOV+xQjCzGR+1kDYDZGjGG0RDY5S1zr M8QZJtpN1KUgMdilPp4EsFLsUyrI0jukOh87Ufhf6qTsjxSO8ahgqhxaUzbJu6Tojpz4 T+/OKxpUHkqZofPKPipud6wp3Ra/fJifuNif+UbAfCJ5fURtIJDmi7/LK+JP6c/VoeYZ JgnQ== 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 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id u22-20020a631416000000b005be1955657esi8816290pgl.127.2023.11.20.12.56.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 12:56:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; 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 23.128.96.35 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 E56BA8076661; Mon, 20 Nov 2023 12:55:47 -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 S231204AbjKTUyu (ORCPT + 27 others); Mon, 20 Nov 2023 15:54:50 -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 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:48 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783117938915005285 X-GMAIL-MSGID: 1783117938915005285 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)