From patchwork Thu Aug 17 00:28:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 136117 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp1969166vqi; Sat, 19 Aug 2023 04:30:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEo6W3YUsRtsZ2MCZWPlOZLGfKFA9VyeXZsqBzZd4JUxinTZlRujydhDDm59RMypErbugVB X-Received: by 2002:a05:6a00:2d0e:b0:682:3126:961a with SMTP id fa14-20020a056a002d0e00b006823126961amr1397228pfb.5.1692444616460; Sat, 19 Aug 2023 04:30:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692444616; cv=none; d=google.com; s=arc-20160816; b=G0w3IYKBwy7XHaumXofPESr1urQeqeKei4UDxfl/wG3SoYWnKGpTB9eZPRAJHlaYFD oSKf7J6kksA68F4/G9X9eV8IJhhD+h5SePVD0+HoxKg/igP6tCHxd7UMq1wls0TwHkWB 1ln4xgQxmlNO9BUarH+ICb/o7Itay1jmVWm8iteVLlKV/QdCkfaIpil1hOfI6Ym/zMsV nQWI8ibgr2ENdD5IReq3YbutJETgL0+c1jr4aulFJhIi59mZxRFlBsc0VaqkjLbzvNey iLUlx/fxBzgJv/YGgRJ7DhdnAI6PD35wO7fDtMyU5WieZQU/9YOSlz6tt1hRw1LnqHY2 qr7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=xTYKA52r6ECDwb4T4jQ43Y9KeB1NpBx6hhbUJvCMgWM=; fh=YvUsqMLdWnmFipdg+QBGYL7sqzgVyVyZZLbtIEZ+18c=; b=xyMqhvjvueLRvG8Bl+fMzaJdyqOil6ZYq8tHn4foPt7yxeN3PhYysM0tXPY2YzRNQw yatfAY2Y0YrLmH1hiMp2LsNqGXk6bUHWRSgFqVAWzuc6HGMiNTZus7X8TZGrDgknSuL3 SB5eYk8Zj6fEFi2RmdN/vGxC6iuGexkOUnIVkdUOy+HxAsNGp7h+BYT2dWBzl7u89jnx xMUGXKXOMwloZl9A5LnHG5T3eckGk6Y7g4wRRGjrQaFOXKPMadcJpWqhgk3jYnbal+TK CZM0Otj//mqcSA5MwkncbtiQHVUDwNxT4fga2Ugtz3yYS3CY569q6xAkiRE4KVh07dr7 b1Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WaY7wanE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id cj20-20020a056a00299400b0068735997aa9si3255142pfb.243.2023.08.19.04.30.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 04:30:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WaY7wanE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 44E286630D; Sat, 19 Aug 2023 01:34:18 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347316AbjHQA3U (ORCPT + 99 others); Wed, 16 Aug 2023 20:29:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347317AbjHQA2u (ORCPT ); Wed, 16 Aug 2023 20:28:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB4E4E76 for ; Wed, 16 Aug 2023 17:28:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 78D3B63C74 for ; Thu, 17 Aug 2023 00:28:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75F93C433C8; Thu, 17 Aug 2023 00:28:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692232128; bh=KuJ1u/Ptd1yFGVDRhEhDSVMIhKS60TBUWM8biRyZBv8=; h=Date:From:To:Cc:Subject:From; b=WaY7wanEr2DFpfb8YQ09wFRFZgdhxiwZhJ5zXucrNmGmqQuZuJcz1ag6mmAjNkN4h Q+M3SaBNqWvsaq+GLURjJPe90JpYGrR/p1VZP4Klx3lEZGG5ISuIMLOSO6HVYAuZ11 XKZirib3+9JvdP/ra0bpTrS7MRg40In4D+k7tK2tuc6X8mRDPUwKHN8SgEKLbDYGZ2 emWIFz3Q4rTVNofa9iHDDBRGWaapcATEvthJ18r7bWCsvNMGX80oxaoyA5qibJKgBL OYAgElYiI4a/QUXIJUTGwGv/silN6qu5a7mhHrVDY8k0kYu1tm1RWyjWny1Xj4nVbN AQO6PUofwpr4A== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 5A37A404DF; Wed, 16 Aug 2023 21:28:45 -0300 (-03) Date: Wed, 16 Aug 2023 21:28:45 -0300 From: Arnaldo Carvalho de Melo To: Alan Maguire Cc: Ian Rogers , Jiri Olsa , Namhyung Kim , Adrian Hunter , Linux Kernel Mailing List Subject: Dumping a struct to a buffer in an strace like style using BTF Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Url: http://acmel.wordpress.com X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774649926334914845 X-GMAIL-MSGID: 1774656806012264832 Hi Alan, Something I planned to do since forever is to get the contents of syscall args and print in 'perf trace' using BTF, right now we have things like: [root@quaco ~]# perf trace -e connect* ssh localhost 0.000 ( 0.342 ms): ssh/438068 connect(fd: 3, uservaddr: { .family: INET, port: 22, addr: 127.0.0.1 }, addrlen: 16) = 0 root@localhost's password: in perf-tools-next when building with BUILD_BPF_SKEL=1 that will hook into that specific syscall and collect the uservaddr sockaddr struct and then pretty print it. That is done manually (the last leg) in tools/perf/trace/beauty/sockaddr.c: syscall_arg__scnprintf_augmented_sockaddr af_scnprintfs[family](syscall pointer contents collected via BPF) which leads to struct sockaddr_in or sockaddr_in6 specific pretty printers, I wanted to do what these two struct specific pretty printers do but using BTF. I guess this is already available, but from a _really_ quick look at libbpf I couldn't find it, ideas? I want to try the code at the end of this message for another multiplexer syscall, bpf(), with this on top of what is at: git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git perf-tools-next Best regards, - Arnaldo diff --git a/tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c b/tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c index 9c1d0b271b20f693..79767422efe9479c 100644 --- a/tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c +++ b/tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c @@ -319,6 +319,27 @@ int sys_enter_perf_event_open(struct syscall_enter_args *args) return 1; /* Failure: don't filter */ } +SEC("tp/syscalls/sys_enter_bpf") +int sys_enter_bpf(struct syscall_enter_args *args) +{ + struct augmented_args_payload *augmented_args = augmented_args_payload(); + const void *attr = (void *)args->args[1]; + unsigned int size = args->args[2]; + unsigned int len = sizeof(augmented_args->args); + + if (augmented_args == NULL) + goto failure; + + size &= sizeof(augmented_args->__data) - 1; + + if (bpf_probe_read(&augmented_args->__data, size, attr) < 0) + goto failure; + + return augmented__output(args, augmented_args, len + size); +failure: + return 1; /* Failure: don't filter */ +} + SEC("tp/syscalls/sys_enter_clock_nanosleep") int sys_enter_clock_nanosleep(struct syscall_enter_args *args) {