diff mbox series

[PATCHv3,bpf-next,3/9] bpf: Use file object build id in stackmap

Message ID 20230316170149.4106586-4-jolsa@kernel.org (mailing list archive)
State New
Headers show
Series mm/bpf/perf: Store build id in file object | expand

Commit Message

Jiri Olsa March 16, 2023, 5:01 p.m. UTC
Use build id from file object in stackmap if it's available.

The file's f_build_id is available (for CONFIG_FILE_BUILD_ID option)
when the file is mmap-ed, so it will be available (if present) when
used by stackmap.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 kernel/bpf/stackmap.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

Comments

Andrii Nakryiko March 16, 2023, 10:07 p.m. UTC | #1
On Thu, Mar 16, 2023 at 10:02 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> Use build id from file object in stackmap if it's available.
>
> The file's f_build_id is available (for CONFIG_FILE_BUILD_ID option)
> when the file is mmap-ed, so it will be available (if present) when
> used by stackmap.
>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---

LGTM.

Acked-by: Andrii Nakryiko <andrii@kernel.org>

>  kernel/bpf/stackmap.c | 24 +++++++++++++++++++++++-
>  1 file changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c
> index 0f1d8dced933..14d27bd83081 100644
> --- a/kernel/bpf/stackmap.c
> +++ b/kernel/bpf/stackmap.c
> @@ -124,6 +124,28 @@ static struct bpf_map *stack_map_alloc(union bpf_attr *attr)
>         return ERR_PTR(err);
>  }
>
> +#ifdef CONFIG_FILE_BUILD_ID
> +static int vma_get_build_id(struct vm_area_struct *vma, unsigned char *build_id)
> +{
> +       struct build_id *bid;
> +
> +       if (!vma->vm_file)
> +               return -EINVAL;
> +       bid = vma->vm_file->f_build_id;
> +       if (IS_ERR_OR_NULL(bid))
> +               return bid ? PTR_ERR(bid) : -ENOENT;
> +       if (bid->sz > BUILD_ID_SIZE_MAX)
> +               return -EINVAL;
> +       memcpy(build_id, bid->data, bid->sz);
> +       return 0;
> +}
> +#else
> +static int vma_get_build_id(struct vm_area_struct *vma, unsigned char *build_id)
> +{
> +       return build_id_parse(vma, build_id, NULL);
> +}
> +#endif
> +
>  static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs,
>                                           u64 *ips, u32 trace_nr, bool user)
>  {
> @@ -156,7 +178,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 || vma_get_build_id(vma, id_offs[i].build_id)) {
>                         /* per entry fall back to ips */
>                         id_offs[i].status = BPF_STACK_BUILD_ID_IP;
>                         id_offs[i].ip = ips[i];
> --
> 2.39.2
>
diff mbox series

Patch

diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c
index 0f1d8dced933..14d27bd83081 100644
--- a/kernel/bpf/stackmap.c
+++ b/kernel/bpf/stackmap.c
@@ -124,6 +124,28 @@  static struct bpf_map *stack_map_alloc(union bpf_attr *attr)
 	return ERR_PTR(err);
 }
 
+#ifdef CONFIG_FILE_BUILD_ID
+static int vma_get_build_id(struct vm_area_struct *vma, unsigned char *build_id)
+{
+	struct build_id *bid;
+
+	if (!vma->vm_file)
+		return -EINVAL;
+	bid = vma->vm_file->f_build_id;
+	if (IS_ERR_OR_NULL(bid))
+		return bid ? PTR_ERR(bid) : -ENOENT;
+	if (bid->sz > BUILD_ID_SIZE_MAX)
+		return -EINVAL;
+	memcpy(build_id, bid->data, bid->sz);
+	return 0;
+}
+#else
+static int vma_get_build_id(struct vm_area_struct *vma, unsigned char *build_id)
+{
+	return build_id_parse(vma, build_id, NULL);
+}
+#endif
+
 static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs,
 					  u64 *ips, u32 trace_nr, bool user)
 {
@@ -156,7 +178,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 || vma_get_build_id(vma, id_offs[i].build_id)) {
 			/* per entry fall back to ips */
 			id_offs[i].status = BPF_STACK_BUILD_ID_IP;
 			id_offs[i].ip = ips[i];