From patchwork Thu Mar 16 17:01:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 6767 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp595324wrt; Thu, 16 Mar 2023 10:04:11 -0700 (PDT) X-Google-Smtp-Source: AK7set+PFpfi6eiTqp8Zo+Plj67qBsiHx8HXsVjCHdKwwht5WhHo0QFR1T9Hj1M8BKgfRTSOZU3v X-Received: by 2002:a05:6808:234b:b0:383:f8a3:2529 with SMTP id ef11-20020a056808234b00b00383f8a32529mr3307315oib.6.1678986251065; Thu, 16 Mar 2023 10:04:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678986251; cv=none; d=google.com; s=arc-20160816; b=MnFcaoB/WRinvzHQKJzWePAr65/IRXeBlupK8eGP5wQrb5dIYKMsqrGilg51mcYeMg jQUCqfgcQsPoau7DOWMg+7cTTA+7vL3R6ywvCMHD70EZaoHMrqXaOAs1JtkpAUwpW7lL yxOUmVOE5C/AnwSxOWn8GG7M1fmM85q8vnqdA+AY6pv+4xLnuI2Ssy1ZpRRIVWHjNmmL eWV+062D9l+FLtIGEyuraIC9iOUibp1MqXbhPsXSUNjP0y9S7Y6kvJIZQTXJKceB7eIP 9OtfGz+cJk3idOyx1r28y+8lyHzdTuZurQhz4YuQXPf62pFRlh/wWTEMkH5ZOhEsvk2t dlfQ== 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:dkim-signature; bh=ZkvKvJt+eJg/SeKNdkv1gwouQVQ7vX28N/OqVgKgUOc=; b=NayswiWCO72vIZ20tKKxjtem/DuSWhIAffBETP5ner1rnJTy9zpoJqijBn0aEtc2i4 zi8Cd0LwmT1QFi3B/nlVQ+q0shCVeS4uRcknIhjDdcGWM9JVNQfJAwi9cBlBvDYLo8GN LhyCSXLsIBG8+fh6N/7XP3xlZ7LRynWI2nXJ/u473s2Dk5XKGiRhkYy5mYK3qIGGomyE E296EXUYI3IaAxIFGQSP0yDv6maDcMfwwCMQyeeklcEr2t/wLL6DC1KlS9WFuMmbtviv hrcTJo13jRPG4A6jiPblMDBgQHlHu17BgVGzrWQFwhS05uJpgZz2OpoE6IJW1OKPJicn 3Pxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UrAFSXvL; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v22-20020a544496000000b00384dd7600fdsi6933932oiv.294.2023.03.16.10.03.57; Thu, 16 Mar 2023 10:04:11 -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=@kernel.org header.s=k20201202 header.b=UrAFSXvL; 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 S229840AbjCPRCI (ORCPT + 99 others); Thu, 16 Mar 2023 13:02:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229631AbjCPRCF (ORCPT ); Thu, 16 Mar 2023 13:02:05 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D43A79B2F7; Thu, 16 Mar 2023 10:01:59 -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 ams.source.kernel.org (Postfix) with ESMTPS id 746D3B8228C; Thu, 16 Mar 2023 17:01:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BABF6C4339B; Thu, 16 Mar 2023 17:01:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678986117; bh=iAe83v06CelvQ5x9yL4BVebJHJ8BOoQ+WiuxJO46PLc=; h=From:To:Cc:Subject:Date:From; b=UrAFSXvLQU2L+HELh4Ww55FjwUFPh88C4WrAY8SuExteQeDon/zQi9uIlnQ0FeLUN IloCjLYHlbUgUQ9Q9TsI1exG7B+AjPZNwB2NWj39PMHS3epq0d2Mth7nidheT4cxW4 6qSEwwCxL3uVBH8whbcX+/nskeSD772HAApttUAqVdHZy8vIyYxWVVxNA5XPFAi4m7 zQjb2XvY9Mw+JrwQftcZWPS7Jfx/qmNqGiaWa0KcCqz2SuzuIhhWdOqR32100jjvvw f3raN7WrqQRL9KfyDpOifwgo1nJj0rDvM57S64hE+TJjTBKfS/cDZ7fCeanU41XyGw z6eEp+AwgZg0w== From: Jiri Olsa To: Alexei Starovoitov , Andrii Nakryiko , Hao Luo , Andrew Morton , Alexander Viro , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Matthew Wilcox Cc: bpf@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-perf-users@vger.kernel.org, Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Daniel Borkmann , Namhyung Kim , Dave Chinner Subject: [PATCHv3 bpf-next 0/9] mm/bpf/perf: Store build id in file object Date: Thu, 16 Mar 2023 18:01:40 +0100 Message-Id: <20230316170149.4106586-1-jolsa@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760544686892055705?= X-GMAIL-MSGID: =?utf-8?q?1760544686892055705?= hi, this patchset adds build id object pointer to struct file object. We have several use cases for build id to be used in BPF programs [2][3]. Having build id pointer stored directly in file object allows to get build id reliably regardless of the execution context as described in [3]. Previous iteration [1] stored build id pointer into inode, but it became clear that struct file object is better place, because we read the build id when the file is mmap-ed and as Dave Chinner said [4]: > Yes, the problem being that we can cache hundreds of millions of > inodes in memory, and only a very small subset of them are going to > have open files associated with them. And an even smaller subset are > going to be mmapped. thanks, jirka v3 changes: - moved build id back to file object (discussed in [4]) - drop patch 4, it's not needed [Andrii] - added ack to patch 7 [Andrii] - replaced BUILD_ID_SIZE_MAX macro with enum [Andrii] - few re-formatting fixes [Andrii] v2 changes: - store build id under inode [Matthew Wilcox] - use urandom_read and liburandom_read.so for test [Andrii] - add libelf-based helper to fetch build ID from elf [Andrii] - store build id or error we got when reading it [Andrii] - use full name i_build_id [Andrii] - several tests fixes [Andrii] [1] https://lore.kernel.org/bpf/20230228093206.821563-1-jolsa@kernel.org/ [2] https://lore.kernel.org/bpf/CA+khW7juLEcrTOd7iKG3C_WY8L265XKNo0iLzV1fE=o-cyeHcQ@mail.gmail.com/ [3] https://lore.kernel.org/bpf/ZABf26mV0D0LS7r%2F@krava/ [4] https://lore.kernel.org/bpf/20230228220714.GJ2825702@dread.disaster.area/ --- Jiri Olsa (9): mm: Store build id in file object perf: Use file object build id in perf_event_mmap_event bpf: Use file object build id in stackmap bpf: Switch BUILD_ID_SIZE_MAX to enum selftests/bpf: Add read_buildid function selftests/bpf: Add err.h header selftests/bpf: Replace extract_build_id with read_build_id selftests/bpf: Add iter_task_vma_buildid test selftests/bpf: Add file_build_id test fs/file_table.c | 3 +++ include/linux/buildid.h | 21 ++++++++++++++++++- include/linux/fs.h | 7 +++++++ kernel/bpf/stackmap.c | 24 +++++++++++++++++++++- kernel/events/core.c | 43 ++++++++++++++++++++++++++++++++++---- lib/buildid.c | 42 +++++++++++++++++++++++++++++++++++++ mm/Kconfig | 9 ++++++++ mm/mmap.c | 18 ++++++++++++++++ tools/testing/selftests/bpf/Makefile | 7 ++++++- tools/testing/selftests/bpf/no_build_id.c | 6 ++++++ tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/testing/selftests/bpf/prog_tests/file_build_id.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/testing/selftests/bpf/prog_tests/stacktrace_build_id.c | 19 +++++++---------- tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c | 17 ++++++--------- tools/testing/selftests/bpf/progs/bpf_iter_task_vma_buildid.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ tools/testing/selftests/bpf/progs/err.h | 18 ++++++++++++++++ tools/testing/selftests/bpf/progs/file_build_id.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/testing/selftests/bpf/progs/profiler.inc.h | 3 +-- tools/testing/selftests/bpf/test_progs.c | 25 ---------------------- tools/testing/selftests/bpf/test_progs.h | 11 +++++++++- tools/testing/selftests/bpf/trace_helpers.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/testing/selftests/bpf/trace_helpers.h | 5 +++++ 22 files changed, 608 insertions(+), 58 deletions(-) create mode 100644 tools/testing/selftests/bpf/no_build_id.c create mode 100644 tools/testing/selftests/bpf/prog_tests/file_build_id.c create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_task_vma_buildid.c create mode 100644 tools/testing/selftests/bpf/progs/err.h create mode 100644 tools/testing/selftests/bpf/progs/file_build_id.c