Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3221706ioo; Sun, 29 May 2022 17:47:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypTJjFqUd11+2R4E9wz3PBzBfLdkh7dj1gpL6ZQGZDiJPXozhaIRBA0nCA8wJ4hn5ai3CJ X-Received: by 2002:a05:6402:2682:b0:42b:5ace:b0e5 with SMTP id w2-20020a056402268200b0042b5aceb0e5mr39803016edd.358.1653871663286; Sun, 29 May 2022 17:47:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653871663; cv=none; d=google.com; s=arc-20160816; b=sr7iEOiqq6ElZcWaLoTVs7g0DDqsCZw03ErOxoeuOaMHb7K9gLz/xFmfa8qYscGTUL 7HIk17AAcg1sJLjMSpSp/iQ2pDHNysDvsyCpBdOZFQ05vsyNZHbveN3Shz5gT8/RB/mY 0GOAwgxhwpBSEM0g6hywm1Zq1T0Xp03E+FBEwD2SR0/ONAcvZ16ptyy32t4pMz/K5LIh MMfIptUp21zlmQeelWxvPkuDRVasG2ilz/st7Hfu23p0UMY/gjETyEglaUG3mFdFt4WS xoO1HKm5xBxdLCS7PbJcvrnTiFSAOMTUaENPTDtIfuz7YZxfaWXlrPHOYgJW49ksHAxn xeCg== 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 :message-id:date:subject:cc:to:from:feedback-id:dkim-signature :dkim-signature; bh=uL7tQhldtntuHotWwMklpuGYSaIxV8IbejYp0K3iJKE=; b=bCFSb3hTPFKSDs7OgnQsR9+5ZggmZ30gMqW4qdpkBS2ncDxQjddx1SG8KWzwZ6HPCu EQsIpCQ/65LuJuSUaNzbZ9WAJwZF/tN4nuJvitwhE24Ry+9hkKObfYygawv+ocDr+3p2 UgUtBN9dLQImU4se0TgJOCuwClpHXado5ZdnbzbjGy1/r/19QlH7o1+h9QUO3SXfX4Qd pisFamgRZ0zweaudanXrbRPkr9XFDf2JPhMBuvz2/xBndkHNQMMgL7p/8qdqE4/NL3Rz Su4fBGktxox/iSyxw/KwVM4QWAx7Y/cZdSyHCucc962yQR9x7s42fa49eyHfL1n4gzx3 HJPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=wIeVqxy3; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=PY7MAlvZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e1-20020a50fb81000000b0042dba57ce96si4345519edq.493.2022.05.29.17.47.17; Sun, 29 May 2022 17:47:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=wIeVqxy3; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=PY7MAlvZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231905AbiE2WGg (ORCPT + 99 others); Sun, 29 May 2022 18:06:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231876AbiE2WGa (ORCPT ); Sun, 29 May 2022 18:06:30 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF1C579810; Sun, 29 May 2022 15:06:26 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 4E21F5C00C4; Sun, 29 May 2022 18:06:24 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sun, 29 May 2022 18:06:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:sender:subject:subject:to:to; s=fm3; t=1653861984; x=1653948384; bh=uL7tQhldtntuHotWwMklpuGYS aIxV8IbejYp0K3iJKE=; b=wIeVqxy3qdgsMed2yxjJNZa4/nNcDhrZiKOTcBj88 U2L8abwfruqVW8OReKAFi+E0CuSMT4lDVH0rBBqu0D8MXWAXrV82DJAtXcdbfRyc yhFPX8rv+DrgoMhXghj/NicuXwON2K4iXYNNOXA9HU7d7Fgy6y5wHFg4Y85Mbxfg ikxZgkbxzrmgjXF3O3jNnYfW3fwivbAhGGOpSNXcJlSjkIFbbAp+cZmWYlr3Ioa7 oDSSR4yZYrwqftQcKtHmIQ/EEffjclcFyx3ix7ENZRuHQ4OlyM19UNdvLRs/xt5I eb1331W0q+pNKiHjURQgZchiQ0mPO3d5/UhqfsBa7f3tg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1653861984; x=1653948384; bh=uL7tQhldtntuHotWwMklpuGYSaIxV8IbejY p0K3iJKE=; b=PY7MAlvZURI82SB9CsAv3VVHXzMzZbhXYCeEZhPhMf3mQMMffdH Dva1s6uF4fbHhZ2Veu5tcG2j+4R/SCQ9CMODicc7XEhaPfNrlVZFFYgbBq3ajzai L4ZvZFmgDfUi41qcmsZLtZuuH3ld60Q+BnZDg87Hj/NBoysYoruNlEXofIEzspUX FQirsTrIcd890qL776Y+Mly3et2nlLJJPoIBXmtHHcF5fIsVcEzZpb4X2FZph0bl bPdJq/gatHsNP5izxD+iaPI+CIgrgT0pPh5t+ovKXP15zktXBm5NkpsP/hUHg6Y8 wGiXxEYpU4cTCdLfUDJ1sf3bqvA3GJhpLgQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrkeehgddtfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtddmnecujfgurhephffvve fufffkofgggfestdekredtredttdenucfhrhhomhepffgrnhhivghlucgiuhcuoegugihu segugihuuhhurdighiiiqeenucggtffrrghtthgvrhhnpedvgefgtefgleehhfeufeekud dvgfeuvdfhgeeljeduudfffffgteeuudeiieekjeenucevlhhushhtvghrufhiiigvpedt necurfgrrhgrmhepmhgrihhlfhhrohhmpegugihusegugihuuhhurdighiii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 29 May 2022 18:06:23 -0400 (EDT) From: Daniel Xu To: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org Cc: Daniel Xu , linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 0/2] Add PROG_TEST_RUN support to BPF_PROG_TYPE_KPROBE Date: Sun, 29 May 2022 17:06:04 -0500 Message-Id: X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FROM_SUSPICIOUS_NTLD, FROM_SUSPICIOUS_NTLD_FP,PDS_OTHER_BAD_TLD,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * 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 This patchset adds PROG_TEST_RUN support to BPF_PROG_TYPE_KPROBE progs. On top of being generally useful for unit testing kprobe progs, this feature more specifically helps solve a relability problem with bpftrace BEGIN and END probes. BEGIN and END probes are run exactly once at the beginning and end of a bpftrace tracing session, respectively. bpftrace currently implements the probes by creating two dummy functions and attaching the BEGIN and END progs, if defined, to those functions and calling the dummy functions as appropriate. This works pretty well most of the time except for when distros strip symbols from bpftrace. Every now and then this happens and users get confused. Having PROG_TEST_RUN support will help solve this issue by allowing us to directly trigger uprobes from userspace. Admittedly, this is a pretty specific problem and could probably be solved other ways. However, PROG_TEST_RUN also makes unit testing more convenient, especially as users start building more complex tracing applications. So I see this as killing two birds with one stone. Daniel Xu (2): bpf, test_run: Add PROG_TEST_RUN support to kprobe Add PROG_TEST_RUN selftest for BPF_PROG_TYPE_KPROBE include/linux/bpf.h | 10 ++++ kernel/trace/bpf_trace.c | 1 + net/bpf/test_run.c | 36 ++++++++++++ .../selftests/bpf/prog_tests/kprobe_ctx.c | 57 +++++++++++++++++++ .../testing/selftests/bpf/progs/kprobe_ctx.c | 33 +++++++++++ 5 files changed, 137 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/kprobe_ctx.c create mode 100644 tools/testing/selftests/bpf/progs/kprobe_ctx.c -- 2.36.1