From patchwork Thu Aug 29 17:42:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13783515 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 D52D8C87FCD for ; Thu, 29 Aug 2024 17:42:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CBE216B00B4; Thu, 29 Aug 2024 13:42:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BF8226B00B5; Thu, 29 Aug 2024 13:42:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 95EA16B00B6; Thu, 29 Aug 2024 13:42:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 722B86B00B4 for ; Thu, 29 Aug 2024 13:42:55 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 237D91A0701 for ; Thu, 29 Aug 2024 17:42:55 +0000 (UTC) X-FDA: 82506003510.09.592B68F Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf13.hostedemail.com (Postfix) with ESMTP id 45B3C20018 for ; Thu, 29 Aug 2024 17:42:53 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=WBvaoWsW; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf13.hostedemail.com: domain of andrii@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=andrii@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724953274; 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:in-reply-to:references:references:dkim-signature; bh=D40VGjjdavlr4wHnP2dKrdOmyuV2VKSC1QVisv7AqNc=; b=PtX1Jd0bMS1LQSoRsFHzxbmDV4/5XT/jzaOyRrbc7vAl8+CNmpWaUu6zzei002ZLcv54PU 9xB8/yOqgKqk0QQfZ/atIoXt4q6zQJwG1PsCfRBe7Dt6XTbgv6p4hKSP8iwPxGgshDBxh5 eZDBcnCkhOuYrR0jwu7ms/kP04+JzwA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724953274; a=rsa-sha256; cv=none; b=SnUxqkSj3G+o1OJ6MsCZvjAg1yPwByFPPcMv3lZTPQM4WZB3ryK6uZTkXoSyZJjffXVwkY +daj85L6mplD74FbPF73j2XbGZmek2lr6Sqngb5NiN3FIAWi5zZTbyk9AeCwMNEij/HQar 2pcI+P+VSNtIpjo/CMy4YKiYRFrjfqI= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=WBvaoWsW; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf13.hostedemail.com: domain of andrii@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=andrii@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 6220BAE2CD0; Thu, 29 Aug 2024 17:42:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06A05C4CEC2; Thu, 29 Aug 2024 17:42:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724953371; bh=wB28U31vHwT6YnSflEoFZZLqW1/CPRZJ0NPgjrn1UhQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WBvaoWsWRNVaVVuv2xXmqKIidjDuVADjq04fALxrs8n8+Z5Z3hEHKp/HA+4xhHFSD brILKgXRIkFDpN5DzPx+mllCuOIHi9V7mdzAZXcEmd+s8zHKfXjA+0KyMip+Vi9/wp CCirREQsumrgyna4aVPLp/Ya9O/58JxFnA/FkPTa06cM6ckklB4Rz5djcyHcyHCyN5 GGsnbNf4Hh1qf+tAB8uplWEqkEVpbgwnyqP5HY+favLHYtKQCJujOUxrTpshZSSQ1s bLAQuj0/TAY1FGELr/AIHUMOx/y9QWbQZbs7xjvfJrYNhYjyjBzOAOOj+fupfgiymK xaHRkSHKGHyqg== From: Andrii Nakryiko To: bpf@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, adobriyan@gmail.com, shakeel.butt@linux.dev, hannes@cmpxchg.org, ak@linux.intel.com, osandov@osandov.com, song@kernel.org, jannh@google.com, linux-fsdevel@vger.kernel.org, willy@infradead.org, Andrii Nakryiko , Eduard Zingerman Subject: [PATCH v7 bpf-next 05/10] lib/buildid: rename build_id_parse() into build_id_parse_nofault() Date: Thu, 29 Aug 2024 10:42:27 -0700 Message-ID: <20240829174232.3133883-6-andrii@kernel.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240829174232.3133883-1-andrii@kernel.org> References: <20240829174232.3133883-1-andrii@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 45B3C20018 X-Stat-Signature: c46ta4o9mjysx95t9rymtwqp4htwxe4j X-Rspam-User: X-HE-Tag: 1724953373-757888 X-HE-Meta: U2FsdGVkX18sXVMNzM04nKrTNRZGWst1D3eEOHisGhF0CC1e52YSVNCTLVxfuKgGfIQaFKPw/SQqqHhQxzIOANWiIJXe7TCYQJo+pqyauKzjVmcc6CkS/q0Opaev23gMY0CTrlONGaFBdDsv5pGr8isDPfECfd5r7r2hf9JzEe5KcXRydF7fYeT4CsQuygN2BbJX3QrNgnguI1x3V79Y6tjeQOh0M2TWaqGi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-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: List-Subscribe: List-Unsubscribe: Make it clear that build_id_parse() assumes that it can take no page fault by renaming it and current few users to build_id_parse_nofault(). Also add build_id_parse() stub which for now falls back to non-sleepable implementation, but will be changed in subsequent patches to take advantage of sleepable context. PROCMAP_QUERY ioctl() on /proc//maps file is using build_id_parse() and will automatically take advantage of more reliable sleepable context implementation. Reviewed-by: Eduard Zingerman Signed-off-by: Andrii Nakryiko --- include/linux/buildid.h | 4 ++-- kernel/bpf/stackmap.c | 2 +- kernel/events/core.c | 2 +- lib/buildid.c | 25 ++++++++++++++++++++++--- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/include/linux/buildid.h b/include/linux/buildid.h index 20aa3c2d89f7..014a88c41073 100644 --- a/include/linux/buildid.h +++ b/include/linux/buildid.h @@ -7,8 +7,8 @@ #define BUILD_ID_SIZE_MAX 20 struct vm_area_struct; -int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id, - __u32 *size); +int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id, __u32 *size); +int build_id_parse_nofault(struct vm_area_struct *vma, unsigned char *build_id, __u32 *size); int build_id_parse_buf(const void *buf, unsigned char *build_id, u32 buf_size); #if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) || IS_ENABLED(CONFIG_VMCORE_INFO) diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c index c99f8e5234ac..770ae8e88016 100644 --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -156,7 +156,7 @@ static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs, goto build_id_valid; } vma = find_vma(current->mm, ips[i]); - if (!vma || build_id_parse(vma, id_offs[i].build_id, NULL)) { + if (!vma || build_id_parse_nofault(vma, id_offs[i].build_id, NULL)) { /* per entry fall back to ips */ id_offs[i].status = BPF_STACK_BUILD_ID_IP; id_offs[i].ip = ips[i]; diff --git a/kernel/events/core.c b/kernel/events/core.c index c973e3c11e03..c78a77f9dce4 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -8851,7 +8851,7 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event) mmap_event->event_id.header.size = sizeof(mmap_event->event_id) + size; if (atomic_read(&nr_build_id_events)) - build_id_parse(vma, mmap_event->build_id, &mmap_event->build_id_size); + build_id_parse_nofault(vma, mmap_event->build_id, &mmap_event->build_id_size); perf_iterate_sb(perf_event_mmap_output, mmap_event, diff --git a/lib/buildid.c b/lib/buildid.c index e8fc4aeb01f2..c1cbd34f3685 100644 --- a/lib/buildid.c +++ b/lib/buildid.c @@ -293,10 +293,12 @@ static int get_build_id_64(struct freader *r, unsigned char *build_id, __u32 *si * @build_id: buffer to store build id, at least BUILD_ID_SIZE long * @size: returns actual build id size in case of success * - * Return: 0 on success, -EINVAL otherwise + * Assumes no page fault can be taken, so if relevant portions of ELF file are + * not already paged in, fetching of build ID fails. + * + * Return: 0 on success; negative error, otherwise */ -int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id, - __u32 *size) +int build_id_parse_nofault(struct vm_area_struct *vma, unsigned char *build_id, __u32 *size) { const Elf32_Ehdr *ehdr; struct freader r; @@ -335,6 +337,23 @@ int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id, return ret; } +/* + * Parse build ID of ELF file mapped to VMA + * @vma: vma object + * @build_id: buffer to store build id, at least BUILD_ID_SIZE long + * @size: returns actual build id size in case of success + * + * Assumes faultable context and can cause page faults to bring in file data + * into page cache. + * + * Return: 0 on success; negative error, otherwise + */ +int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id, __u32 *size) +{ + /* fallback to non-faultable version for now */ + return build_id_parse_nofault(vma, build_id, size); +} + /** * build_id_parse_buf - Get build ID from a buffer * @buf: ELF note section(s) to parse