Skip to content

Commit 45b8fc3

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
lib/buildid: rename build_id_parse() into build_id_parse_nofault()
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/<pid>/maps file is using build_id_parse() and will automatically take advantage of more reliable sleepable context implementation. Reviewed-by: Eduard Zingerman <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 4e9d360 commit 45b8fc3

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

include/linux/buildid.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#define BUILD_ID_SIZE_MAX 20
88

99
struct vm_area_struct;
10-
int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id,
11-
__u32 *size);
10+
int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id, __u32 *size);
11+
int build_id_parse_nofault(struct vm_area_struct *vma, unsigned char *build_id, __u32 *size);
1212
int build_id_parse_buf(const void *buf, unsigned char *build_id, u32 buf_size);
1313

1414
#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) || IS_ENABLED(CONFIG_VMCORE_INFO)

kernel/bpf/stackmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs,
156156
goto build_id_valid;
157157
}
158158
vma = find_vma(current->mm, ips[i]);
159-
if (!vma || build_id_parse(vma, id_offs[i].build_id, NULL)) {
159+
if (!vma || build_id_parse_nofault(vma, id_offs[i].build_id, NULL)) {
160160
/* per entry fall back to ips */
161161
id_offs[i].status = BPF_STACK_BUILD_ID_IP;
162162
id_offs[i].ip = ips[i];

kernel/events/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8851,7 +8851,7 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
88518851
mmap_event->event_id.header.size = sizeof(mmap_event->event_id) + size;
88528852

88538853
if (atomic_read(&nr_build_id_events))
8854-
build_id_parse(vma, mmap_event->build_id, &mmap_event->build_id_size);
8854+
build_id_parse_nofault(vma, mmap_event->build_id, &mmap_event->build_id_size);
88558855

88568856
perf_iterate_sb(perf_event_mmap_output,
88578857
mmap_event,

lib/buildid.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,12 @@ static int get_build_id_64(struct freader *r, unsigned char *build_id, __u32 *si
293293
* @build_id: buffer to store build id, at least BUILD_ID_SIZE long
294294
* @size: returns actual build id size in case of success
295295
*
296-
* Return: 0 on success, -EINVAL otherwise
296+
* Assumes no page fault can be taken, so if relevant portions of ELF file are
297+
* not already paged in, fetching of build ID fails.
298+
*
299+
* Return: 0 on success; negative error, otherwise
297300
*/
298-
int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id,
299-
__u32 *size)
301+
int build_id_parse_nofault(struct vm_area_struct *vma, unsigned char *build_id, __u32 *size)
300302
{
301303
const Elf32_Ehdr *ehdr;
302304
struct freader r;
@@ -335,6 +337,23 @@ int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id,
335337
return ret;
336338
}
337339

340+
/*
341+
* Parse build ID of ELF file mapped to VMA
342+
* @vma: vma object
343+
* @build_id: buffer to store build id, at least BUILD_ID_SIZE long
344+
* @size: returns actual build id size in case of success
345+
*
346+
* Assumes faultable context and can cause page faults to bring in file data
347+
* into page cache.
348+
*
349+
* Return: 0 on success; negative error, otherwise
350+
*/
351+
int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id, __u32 *size)
352+
{
353+
/* fallback to non-faultable version for now */
354+
return build_id_parse_nofault(vma, build_id, size);
355+
}
356+
338357
/**
339358
* build_id_parse_buf - Get build ID from a buffer
340359
* @buf: ELF note section(s) to parse

0 commit comments

Comments
 (0)