From patchwork Mon Oct 2 20:25:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 147485 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1711924vqb; Mon, 2 Oct 2023 14:56:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1CNS2Ovn36QqemaR++weFN/dPzlmnVF1motBFyPjCP+OjYbMCdnIuPbmKwlfQwPSM4iSI X-Received: by 2002:a05:6a00:1495:b0:68f:e9ce:92a5 with SMTP id v21-20020a056a00149500b0068fe9ce92a5mr12407480pfu.4.1696283816616; Mon, 02 Oct 2023 14:56:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696283816; cv=none; d=google.com; s=arc-20160816; b=BqWQ5m3izwuGByFWqCfnowJiaqx5XSQvtryn7X+ycTpLEBXw8zAgIdZNH3Zge9Ptob 25f4QIA0E/GP7bpEO/prIn3aFJDz2MfcroaHLkgERKPuB9fYFjNjyp7PCM6ITN0u71fh JRgpdZztWckAGLzXdk08Y8RlyaK9/W1Hje40812hq1AAUdhUp4uF5R/hZBz4lyF8a/Fs 9/U5HPu0Bn5AqWuZItOAXLMeEtNgcqLn/va0KRAagbu3E/G7ky47nEfRfVGh+mnalAe7 UX8heRxT7gjNGjG/WbNZXekB76XFr/KOyiIY+ML4GxvnGB+md0d4vBtp3RJj2nbY5v9v fLCA== 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=4fAGpVMVREzblAWn+7iQZ6yyfDYkn59lrBb/kL6NfJg=; fh=185gnY/jvZ3KyhWEGKx2Ja9SQMRN/yWtD8bZTRNPBJo=; b=YVha7P5kIebGg3UaizhwUNJbzUREQJx6NvTwwJ9Nrfg8KwEmoQFjfdA4nv3/sdly0A Fv9vlotya3GrMjdoIDCM+4KeRv2JU8oIXJ8Qfny82rWm6PckojjA3/g27fF5UUx3ucIR uCVEBChNYhP6SahqVTUnngqSp5f7zj4KUmvF8YCJ0Pti28F3jfUbFFfQVAhUs4ze/oT9 QDB5YJenyRw+2Ih1bW1TEWoy6Zg0uy4t4FFW99GUayIrH1+oKcr3KttOJJjmUmWAP/VU 7t/ubCaR4sI2EjS4Xi5e5Vhlaiv2HVMh/MAoQCvHrDk1J0fArsvsV5xPe6Kod1EdCSQX CxFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=JnGRudYx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id t22-20020a056a0021d600b00690b80126b9si28325341pfj.142.2023.10.02.14.56.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 14:56:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=JnGRudYx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 58BD3805DEE8; Mon, 2 Oct 2023 13:26:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235909AbjJBUZt (ORCPT + 18 others); Mon, 2 Oct 2023 16:25:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229881AbjJBUZp (ORCPT ); Mon, 2 Oct 2023 16:25:45 -0400 Received: from smtpout.efficios.com (unknown [IPv6:2607:5300:203:b2ee::31e5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6A17D3; Mon, 2 Oct 2023 13:25:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1696278340; bh=vYAU4AeTLnE8I/bDRtRMZDB+30vSLOM6ErZFA9kFrHI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JnGRudYxxav/ozwajmmRrIDkAbC1i2iLjSuXV5BXpqr91oHOJl8sYJWFLHvLD6gAy pMkra1snzoS5vm0q3+m+dLOpoWioI/8zB2jYmeDrT8O+vTl2ybEnLwBa/znFQkCjGz rIw5Ek5gokFbJMSzK4shMWM/0sb/yASsfGTgW8FOt6bePmBMgd1T6eC/uI6wi2MHb/ zaXOlZegkRvZktIgrmXoDy596wPgGrSRf+J9/So2jngZbXVjYtMPlV0PVeV/ZEcP0s hcyopxZFGkgv/0ak9TLRUOfp7Bv6r2BP7GtrF1954aaF2T397aQbqxiP3A2LHpg9Yf p0q9tr9571qJw== Received: from localhost.localdomain (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4RzssH6JPHz1Vwc; Mon, 2 Oct 2023 16:25:39 -0400 (EDT) From: Mathieu Desnoyers To: Steven Rostedt 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: [RFC PATCH v3 3/5] tracing/bpf-trace: add support for faultable tracepoints Date: Mon, 2 Oct 2023 16:25:29 -0400 Message-Id: <20231002202531.3160-4-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231002202531.3160-1-mathieu.desnoyers@efficios.com> References: <20231002202531.3160-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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Mon, 02 Oct 2023 13:26:23 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778682499353021334 X-GMAIL-MSGID: 1778682499353021334 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. Co-developed-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers Signed-off-by: Michael Jeanson Cc: Steven Rostedt 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 1f7fc1fc590c..03cb4045a046 100644 --- a/include/trace/bpf_probe.h +++ b/include/trace/bpf_probe.h @@ -40,17 +40,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 @@ -104,13 +117,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 4accf2f138b8..e9942f8e5c66 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2327,9 +2327,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)