Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5816983ioo; Wed, 1 Jun 2022 13:12:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnhlq8jkpQFkh5X37irRLUoP2B9HB58mQzeB6//e3eiwiS1el1jPjRrVPo3yx5jNUZxA4d X-Received: by 2002:a17:90b:4f82:b0:1e0:4852:bc5d with SMTP id qe2-20020a17090b4f8200b001e04852bc5dmr36101988pjb.64.1654114362166; Wed, 01 Jun 2022 13:12:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654114362; cv=none; d=google.com; s=arc-20160816; b=Y/y8iWAbLzVfMdrJV36Iw3dHoVgPGhKMEYUfUJOVMy/COonV83fr0lXY30jVUgly2K Poq/trS48aL8N04+NfENoFwWnMlNhDqhXafs3O17XPoS645meRl6w5c/tuo23FuHBueS on918NCs77xjRLA4Xx8phf1Vzp5hY/QG4dYDKoyQJ0oT4HLM+/jhyqSzrOZ3rb7COkp1 GF2yYS5Gw26ylycPOboRd9biDSUEeZo3Xn3a8grKiFNwUnWaub0E2k2tGs2j4uQxCm+Z YxmpuszGN9roMSYUanKT+U5bJkj0Bp72uCcE0vquDx2Q2vTvXNlncI7DE8kf1EN7YCGL yxmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=5c1Ux5q09brkMilfop68xT33fNHK9r2FFOhRcKeyXB0=; b=x48hsg2IuzdbJj0VZrWC8G1JHZ2PBrM575D8HKaFVO4tGd6+/jzZVSjBGe+v0nwRwm cRDTOJtHSOxH10RKFDlcytxD6rSlH61v7VatU04O0e91Woi7y1GINM5+868d1CW+adPh vrlYSo+A1HapSqbRPsRt0txNu7pNiG0McJMrrx6LYlUkg5bkAAd+OhcuEfcds8IjZR1e b52bGlVycNxh4j2N02PIjvIxK1tSZuzItYeWTLj85/GtOfzhQpmpZoWgRCCsIdKIJnYE LV/tyJDEylTIaqcmkVXfhWs1sHoLC/qxh+yBQX7El+6folXImZg0WWFM1qt4x5LHiwDB JHHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=o7qp+Ztt; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id e17-20020a170902ef5100b00156bdbdedf4si3348622plx.269.2022.06.01.13.12.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 13:12:42 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=o7qp+Ztt; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3DA22213296; Wed, 1 Jun 2022 12:26:24 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346197AbiEaQrs (ORCPT + 99 others); Tue, 31 May 2022 12:47:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229800AbiEaQrr (ORCPT ); Tue, 31 May 2022 12:47:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FC164D9E1; Tue, 31 May 2022 09:47:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1E21260DD6; Tue, 31 May 2022 16:47:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7AA38C3411D; Tue, 31 May 2022 16:47:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654015665; bh=5c1Ux5q09brkMilfop68xT33fNHK9r2FFOhRcKeyXB0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=o7qp+Ztt2w1RLNnioq7owDkKvnLT02AUV1OwX7svsMGJmUkpiQZA0RTr6Ldmg6sgy EGTHO1wbTdS7RZDhevtr6QLFiurVfKYDmhVmvZTe8Cyesv8uqEY4bl6ID4Xfz6R/bK uqLlE0oKo3nR9FeRhYS0ABEstngbxMS/CpyyiFIisapMzB15C+uBWShY2lmAlilqFR jN1sO0s0aBLdk9bBhkH69pDHEYm5fcXUgBzYm0i2DM7zlFxOQXxPoxvOTjJsu5n8ZU yZpur9AHTvLPJLZt52Rrja3585fAMyMlF0KUtZmsYRjiCNZXbI4Qjl+D1aalsxXvCA 0Jq7oWuiXgw9A== Received: by mail-yb1-f172.google.com with SMTP id e184so15414444ybf.8; Tue, 31 May 2022 09:47:45 -0700 (PDT) X-Gm-Message-State: AOAM532ohtQj2j8EUaRE7z4pEl8LQwIpEUSpNNskLLW+N8ALzZony3Lv ZyoDEagUHIXN3ja8C7nPyrxACCNPt/uXfa/8Jmo= X-Received: by 2002:a25:4705:0:b0:65d:43f8:5652 with SMTP id u5-20020a254705000000b0065d43f85652mr3545432yba.389.1654015664482; Tue, 31 May 2022 09:47:44 -0700 (PDT) MIME-Version: 1.0 References: <20220530145639.slbwvbwewonj6im2@kashmir.localdomain> In-Reply-To: <20220530145639.slbwvbwewonj6im2@kashmir.localdomain> From: Song Liu Date: Tue, 31 May 2022 09:47:33 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf-next 0/2] Add PROG_TEST_RUN support to BPF_PROG_TYPE_KPROBE To: Daniel Xu Cc: bpf , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , open list Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 30, 2022 at 7:56 AM Daniel Xu wrote: > > Hi Song, > > On Sun, May 29, 2022 at 11:00:48PM -0700, Song Liu wrote: > > On Sun, May 29, 2022 at 3:06 PM Daniel Xu wrote: > > > > > > 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. > > > > We have BPF_PROG_RUN which is an alias of BPF_PROG_TEST_RUN. I guess > > that's a better name for the BEGIN/END use case. > > Right, sorry. Was getting names mixed up. > > > > > Have you checked out bpf_prog_test_run_raw_tp()? AFAICT, it works as good as > > kprobe for this use case. > > I just took a look -- I think it'll work for BEGIN/END use case. But > also like I mentioned, BPF_PROG_RUN/BPF_PROG_TEST_RUN support for > kprobes is probably still useful. For example if kprobe accesses 13th > register. I suppose the raw_tp 12 arg limit could be lifted but it might > be tricky to capture that logic in the absence of something like `struct > pt_regs` to check the ctx_size_in against. Agreed that unit tests support for kprobe programs is great. Thanks, Song