Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp691954rwe; Fri, 26 Aug 2022 12:25:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR4/24gq3dosgYWZLrZzZanIeolAK32MPWyiYvn5TOTRUyrtfXzkRNo63c1Rpsq/PIHI6YQk X-Received: by 2002:a63:f704:0:b0:42b:7fa6:19bd with SMTP id x4-20020a63f704000000b0042b7fa619bdmr2447583pgh.283.1661541904597; Fri, 26 Aug 2022 12:25:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661541904; cv=none; d=google.com; s=arc-20160816; b=lhlTfcwoew7RlO+M+cwVGTzrApXtzLEtDzKkOPs3m/QNyNcRm0WP2i+2xjgTlEILX6 coaW5TGYgAg5Eiwx5SA3j7W79mLlhxN/a7gVwOIyX8ESxdYIUGr190ad9CyYeVjuIQeK 10CvN6j5O4UV/yYYr20M9YRQTdT/TOdm9qLMBmi37WWD+Gpj2T1SkL8KHLUJobofuW2M goraHtVhfntNm/tnzwzkt8MmSPX7WKTO83lCB3E5FfNf42sPXJ+ya2gtQ+V7ORi1U1+2 MuWJ9+l8h81irmSvNY5m/aXcjudL+frYhT2rVQDK+PECm9g+vIEM4iKkyI1O8tqFZ4rG 5ICQ== 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; bh=9Mtsf8bHADcXsmpT2IJ7HPB/pQKds1pL0AHVcqCIStc=; b=NnWQgP+1K9DIrj5dw9SzSzm9rWnTlp+i+pHzN5+S03weXUsY/S9NBDEsD4KH2ajg5b bQmo8bxOgIwnbvSFjcmB74Oc4tnsVX84TS9XlAZgCTD9BCaLwXwneO2Ag0Sww5iyi85g ABRaYVlTuO/z7VVsoj62tXzO8/oMdJNCwTvK0GCCMrkBXNNaJAlwgboD47hEuyLuosiF fuOJff34KrSYMj/S7iBWnHkOmqsL4Z6S4jb2HMZUYPOCu9edq13QA2A/1pcEUHF7ZY3/ 0NbF8snftTiF8nswJZVbZ+3dY/uRWBPPR/lGPVdG8QqAjPmfbtKrnZ0vZTz7o8sonyFB 6sxg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 8-20020a631248000000b0042b6821bbc4si2187031pgs.604.2022.08.26.12.24.52; Fri, 26 Aug 2022 12:25:04 -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; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245286AbiHZTWB (ORCPT + 99 others); Fri, 26 Aug 2022 15:22:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231181AbiHZTWA (ORCPT ); Fri, 26 Aug 2022 15:22:00 -0400 Received: from mail-oa1-f47.google.com (mail-oa1-f47.google.com [209.85.160.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB482BD1C4; Fri, 26 Aug 2022 12:21:59 -0700 (PDT) Received: by mail-oa1-f47.google.com with SMTP id 586e51a60fabf-11c5505dba2so3227540fac.13; Fri, 26 Aug 2022 12:21:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=9Mtsf8bHADcXsmpT2IJ7HPB/pQKds1pL0AHVcqCIStc=; b=cmENxV6t64cmV6cBRxnLLTtChQqCKRodwQtDzqMwtZaEMlD8RjdgCLGS85CQ4MvqXa HpAHyZJPS/9WkAYlGHkce9f2B44I9edJ7EZfuxYZW63+GXZ8ZYG2bInHrzmOpMc4LJdm PZW7OTGJyTA349itbBnsM/NemiZ333Q7dBWoZGVOQkGKRxTndxWVV7RXJJcXo0fqQdyS tR5dwp/po4McmFReOCeQaSLq7kFnTaXOtP1bdOHh+D+xBExNXfCjPOBfaE9wmOe9ktTB rq/Ueq+7rTt+3rlryKqkv8nJLeX8x1kqgwBl5FN0U25EQEHTUwWXF/Cern7b39ZjSm3I EwUA== X-Gm-Message-State: ACgBeo0yc5TNr+bte9Ly44xtv2Hm8x/zTqaicfmIgizjDX0ZNg5RqvAb mz8er7T7jrA/jefH6ruUPiRZVLhJZWfGKx1KQdk= X-Received: by 2002:a05:6870:a184:b0:116:bd39:7f94 with SMTP id a4-20020a056870a18400b00116bd397f94mr2610720oaf.5.1661541719270; Fri, 26 Aug 2022 12:21:59 -0700 (PDT) MIME-Version: 1.0 References: <20220823210354.1407473-1-namhyung@kernel.org> In-Reply-To: From: Namhyung Kim Date: Fri, 26 Aug 2022 12:21:48 -0700 Message-ID: Subject: Re: [PATCH bpf-next] bpf: Add bpf_read_raw_record() helper To: Song Liu Cc: Song Liu , Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin Lau , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Steven Rostedt , Peter Zijlstra , Ingo Molnar , "bpf@vger.kernel.org" , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 Fri, Aug 26, 2022 at 11:09 AM Song Liu wrote: > > > > > On Aug 26, 2022, at 9:33 AM, Namhyung Kim wrote: > > > > On Thu, Aug 25, 2022 at 10:53 PM Song Liu wrote: > >> > >> On Thu, Aug 25, 2022 at 10:22 PM Namhyung Kim wrote: > >>> > >>> On Thu, Aug 25, 2022 at 7:35 PM Song Liu wrote: > >>>> Actually, since we are on this, can we make it more generic, and handle > >>>> all possible PERF_SAMPLE_* (in enum perf_event_sample_format)? Something > >>>> like: > >>>> > >>>> long bpf_perf_event_read_sample(void *ctx, void *buf, u64 size, u64 flags); > >>>> > >>>> WDYT Namhyung? > >>> > >>> Do you mean reading the whole sample data at once? > >>> Then it needs to parse the sample data format properly > >>> which is non trivial due to a number of variable length > >>> fields like callchains and branch stack, etc. > >>> > >>> Also I'm afraid I might need event configuration info > >>> other than sample data like attr.type, attr.config, > >>> attr.sample_type and so on. > >>> > >>> Hmm.. maybe we can add it to the ctx directly like ctx.attr_type? > >> > >> The user should have access to the perf_event_attr used to > >> create the event. This is also available in ctx->event->attr. > > > > Do you mean from BPF? I'd like to have a generic BPF program > > that can handle various filtering according to the command line > > arguments. I'm not sure but it might do something differently > > for each event based on the attr settings. > > Yeah, we can access perf_event_attr from BPF program. Note that > the ctx for perf_event bpf program is struct bpf_perf_event_data_kern: > > SEC("perf_event") > int perf_e(struct bpf_perf_event_data_kern *ctx) > { > ... > } > > struct bpf_perf_event_data_kern { > bpf_user_pt_regs_t *regs; > struct perf_sample_data *data; > struct perf_event *event; > }; I didn't know that it's allowed to access the kernel data directly. For some reason, I thought it should use fields in bpf_event_event_data only, like sample_period and addr. And the verifier will convert the access to them according to pe_prog_convert_ctx_access(). > > Alternatively, we can also have bpf user space configure the BPF > program via a few knobs. > > And actually, we can just read ctx->data and get the raw record, > right..? If it's possible, sure, it'd be more powerful. Thanks, Namhyung