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: 13178087 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF96BC6FD19 for ; Thu, 16 Mar 2023 17:02:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 74622900003; Thu, 16 Mar 2023 13:02:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F532900002; Thu, 16 Mar 2023 13:02:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E3AF900003; Thu, 16 Mar 2023 13:02:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4B84B900002 for ; Thu, 16 Mar 2023 13:02:04 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9D2CD121405 for ; Thu, 16 Mar 2023 17:02:03 +0000 (UTC) X-FDA: 80575378926.20.BFC5FC4 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf21.hostedemail.com (Postfix) with ESMTP id 8206C1C004B for ; Thu, 16 Mar 2023 17:02:00 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UrAFSXvL; spf=pass (imf21.hostedemail.com: domain of jolsa@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=jolsa@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678986120; a=rsa-sha256; cv=none; b=Jhlz/Ut6pqgBzkIWovcIXPSvd0MDI9/ZNtUayvu92xqTAdo4fds7SBRFcoxX29BrYJnc4t +XZd6ZCDr5vgYAY5/O6qydnPzkk53h9Az63hIJqGP20Os1w1+Gp/Jjw7qcHhKFxKOHnpo2 far4V7wTBwg+98YhYnBGRG5hsZcQ/uU= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UrAFSXvL; spf=pass (imf21.hostedemail.com: domain of jolsa@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=jolsa@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678986120; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=ZkvKvJt+eJg/SeKNdkv1gwouQVQ7vX28N/OqVgKgUOc=; b=xv5kDypRXeibQtvYWl/NYCGwNNqfJcboNaBpGELswjW/tErjHuxqLT8RulXGzmyDmIOQEw S/tzft2j0ZbnzKzXEgA3MDA+WqwK2FzoDGDwRuPTtGPOgKdiY/Quy/abC3ifQMsmrmihwE cbZDJzR6yAKMBlVJRSgyOEVnjm7wGiw= 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 7964FB8227B; 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-Rspam-User: X-Rspamd-Queue-Id: 8206C1C004B X-Rspamd-Server: rspam01 X-Stat-Signature: jinongwgqpb3qk3uwt5qfrufap5pjtq6 X-HE-Tag: 1678986120-90393 X-HE-Meta: U2FsdGVkX19odYGeYCnHlJx2IgtGoD7c4hw5i9NBLjXNXGkNpdIj0iyVPSAWNAWlTL3lk55pMB13z6RQwR9U0qLzETr1emyVPTCBhd5VYbdo0PeKA6I9DtJFmLBqpF0MkOd3q+lQuKXBFyLp3vHQMn7TGn2CTY4dCXXpgQ4w34k+Dtis2iJIgl04c3Jc1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QgzC+tzqm2hR/QsWD2vita4YGd4vuYo/XdqtiOf2alHA3C3GAkUEmwwhThPpYeimMcRHDSso2X2sQtZ1ij5skvadOMqYDC51DX0RTVvP/AFeuaUjIbhjd2cFjqHhAJSvqeSl4yfJICmSiT5PYSthCcko8Ex3C/t37rttZCEwoxvrE+K+WEfZIrWu X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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