From patchwork Wed Jul 24 22:52:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13741432 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 C001EC3DA61 for ; Wed, 24 Jul 2024 22:52:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C9FB6B009D; Wed, 24 Jul 2024 18:52:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 379996B009E; Wed, 24 Jul 2024 18:52:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 21B106B009F; Wed, 24 Jul 2024 18:52:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id F1E356B009D for ; Wed, 24 Jul 2024 18:52:32 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id AFB4BC0B56 for ; Wed, 24 Jul 2024 22:52:32 +0000 (UTC) X-FDA: 82376146944.09.1431123 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf02.hostedemail.com (Postfix) with ESMTP id 76C2A80004 for ; Wed, 24 Jul 2024 22:52:30 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=esih5uxC; spf=pass (imf02.hostedemail.com: domain of andrii@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=andrii@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=1721861513; 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=RnwNWAK8VLl5llt50/PX/eREunyE6d44xPqD2szPVB8=; b=GeOu3W+/yGQNC52ISXpZTO4rV8qWwDy9bmQnkAGPJZ8Mc0iNeZHhLSb0+1k/Of6Vd4wbvd FTXnhdlYDehaH8/x8/Vqn09DcRVdCRLCZi+JwcVeMZtVTXmPN9tXGsmnjS54wvPqKERtGm oHHgcFNGbSrAaQEedBVCPFWS96w4ls0= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=esih5uxC; spf=pass (imf02.hostedemail.com: domain of andrii@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=andrii@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721861513; a=rsa-sha256; cv=none; b=PiPh0uuAbFJuy8rOoJTklzp0kOk2i3/rg2bukNf6Hf4prfuipfozxaqSaiLwGLDAzC1gSb 15Sqxzz0AUU38ueejO0GYbxbGB7Cr2fzZlI4KGO34J4+wlzrNfFEUixUCMNBBeCSo9209O rwF40FGmTuwImHbL5942yzMMrm3E/+I= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id A1A69CE12C2; Wed, 24 Jul 2024 22:52:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4159C4AF0F; Wed, 24 Jul 2024 22:52:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721861547; bh=ttN3FJZUIXMIoxb3+/1Zwk+6ong/Mn3pgESyR8mPPTQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=esih5uxCybKcEIXW7Uqc3DL51opICdz6HHVG1J6Vfx7wCI6BfOD481/t5nwtlbRzT k/279fhp3fHxpaIW4ahunTN3A2seclhLFmwJeHSW1g8bOO5bBn7LJ94p1JR2vJMjHR ujSSDoyFVwY39DftebQIdmhqOzqe1JpOyu++tQ+yAXxtX2r7SZFFyJH1anQ0eaVCQ/ vhwIvddChY20RKQ9hqKhkNff6xiHNvln9C0KjhbP43WBOvnVRQ2SqikP0Mrum8EZ1X Ilqv1G+KJH8MHKwPSUEdmdEZjTZoCjRAgiT8evGe0tQp0c7BTXqpV/R4SzCScYyJkB msrEBspoAclmw== 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, Andrii Nakryiko Subject: [PATCH v2 bpf-next 04/10] lib/buildid: rename build_id_parse() into build_id_parse_nofault() Date: Wed, 24 Jul 2024 15:52:04 -0700 Message-ID: <20240724225210.545423-5-andrii@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240724225210.545423-1-andrii@kernel.org> References: <20240724225210.545423-1-andrii@kernel.org> MIME-Version: 1.0 X-Stat-Signature: bn9kcehcosimm64cfidopik7ytxkwh7a X-Rspam-User: X-Rspamd-Queue-Id: 76C2A80004 X-Rspamd-Server: rspam02 X-HE-Tag: 1721861550-43858 X-HE-Meta: U2FsdGVkX18eLkJetkKlBiJHtXDROq6PV+43nxiP3+gsAu2TYJnsDWsrteUoCIs/SkcUWDg3tInSnL3jpgTLSu2X0ege06UnqmOrbsfqjQvKQZsMxACsr4gM9D20PnVdV+iOsimyeOTSHErX03Y6yXyr4mGgIR5j2qQakGtYZiBUHd/fRk0h2LShJse9x/XKhKs2IGIjiTeV8L6/xFG8MBBVYEvGIZOK+qTtJZs20XxIaZPDxyub5NFwR11NLhX9MurHQQTtFokqSs7hEr3xv6DzxBsCnulj3GLwKDopDqpI9XFMhcaDd4hAC8/YLAlwCcDqewiG3OWRW4o05w/GulZZ85MUrX1xkAudakSdr8idwGtndzZvURCvLlLzLBVb/9QzpY6OUJN16zKyt4kIhZiYXJcQmvIpKdLZDha/ZnehUkG0o97aAzqI26sX7P0VFSSVwKoIRf4/fnTiqKffAbGoE0ey6KhY4X56ECvUogdWplj7ccvenBRhASZ+lknQxN1LEriE1lLR+wq6URLIny1Or/5q5G+/fP6tj+eMD4lriiJeH6mLBw8Rom20ogMWvtGQs2Jnh7M6Y1h9WACOHOoUx1hW+Sekwe1LWthb+1AquYAqtPT97gTTAA9NFYOeEfYJcHb/6Zb2UIg9r7e64QjeR2iyu2qHXqqj7saXEGyTOFFfAuIwiaG4o1s0Qhm+CmBb0JkYyDW/28Pk/xJaxbRom9ahKIt1Jb5zaxOf6iGlwKohoHbyMLGrhw8+2qhM0+CG/5OCZhMjEWJwol9tciS9l+MdmjOqLum80QDJF5fir2l/Z1otqQ85IvuYHIoQxP+fkBFbXlR4koPZU1HuXCjyF6AWZUhw/HfMjt88Wm2hsCmW3uC2O4CBuMMytpXJtgchh19vhqzLCgmFisRPPInDAEGm4sWTCiSqwzcRcVyRwMmorORbTion2bVApyBVAGHpKvZggVFP6DbLxSz bCJI6uN3 brw2/4unE2wLVa1o4KDtU5Hr/6pABOdvqrFG7qJojGOQqFO1b16EIrbOfVOss3tIk5vhWK10cJX5G5vRw/O8u9AOG3xyOa8t+aJxYq8obVCgc/FX3YwzfDGTLjMSMeGbJATuGLp2M6xPbGsYxpOXQOARl+LWbSL8znMW1/YcA9zPThWPdH3In6SAkX9IF4sUsZBFzHOcGviPepxOTxNOq2LUfJRESvLC9p9yxqwY32N8wcrM7/wjtl3qTxYbFiTGxsZJ0/bxixtQl2NDr9MM++pfVtFfMPXqiqZYj 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: 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 will be implemented in subsequent patches, just to preserve succesful kernel compilation if another upcoming user of build_id_parse() (PROCMAP_QUERY ioctl() for /proc//maps, see [0]) gets merged with bpf-next tree. That ioctl() users of build_id_parse() doesn't have no-page-fault restriction, so it will automatically benefit from sleepable implementation. [0] https://lore.kernel.org/linux-mm/20240627170900.1672542-4-andrii@kernel.org/ Signed-off-by: Andrii Nakryiko --- include/linux/buildid.h | 4 ++-- kernel/bpf/stackmap.c | 2 +- kernel/events/core.c | 2 +- lib/buildid.c | 24 +++++++++++++++++++++--- 4 files changed, 25 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 ab6c4c942f79..c2079e25f211 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -8850,7 +8850,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 49fcb9a549bf..5f898fee43d7 100644 --- a/lib/buildid.c +++ b/lib/buildid.c @@ -276,10 +276,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; @@ -318,6 +320,22 @@ 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) +{ + return -EOPNOTSUPP; +} + /** * build_id_parse_buf - Get build ID from a buffer * @buf: ELF note section(s) to parse