Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1436021rwl; Sun, 26 Mar 2023 02:24:26 -0700 (PDT) X-Google-Smtp-Source: AKy350ZSRhAFbMo+hyM9AAAnVH5bOiGR/4g8Fx/8u/hjJK0zNCGXsFcc2POQMtXHycbkEPBb/fVn X-Received: by 2002:a17:906:584a:b0:86a:316:d107 with SMTP id h10-20020a170906584a00b0086a0316d107mr7571430ejs.72.1679822666566; Sun, 26 Mar 2023 02:24:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679822666; cv=none; d=google.com; s=arc-20160816; b=inAxpmyglzKHNb8GuTSgptr02DrsZ8boU/laprBdb9+jbAowNTxLF7vkb8NsmEC6n1 FnCtn78uLh/N7Y83LWulAD3hfhR9FYuyHrLI1h6R0Ip2o7tpFbz3ORFGm6OTuVifiKi1 OvWLdH9e4gUzImlbi5M/ePhbXVM2xqn8nojer292tjvc6rjpB3ptISOQ77O3izZQk/fZ RBDTVwKAgHAaa2yWMBPY876LeWGWo4vVEqKR7Z0fV5cMvdMdjHNrljTbvbpvu6gRGnmB dl5Gwji5akG+5qQlmjlYimmXlzUg1MAScjS+UcxLXnJTd97oYQArlvc0L6i9PI4RX4JK FiUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IttOk0+8XCKRMkImj0Us7L6S+8JkbptYujvUdCdqNsM=; b=oDY/+QE1b3417q3dfa6BHvVp1jfvcogQ9TDFDpH+JcN5n0HKidazYthy4ME6ZQt6zN WxrnM/zV6NhOwzvSsdnQ+nJeHHGAKWBHgyQE4Swp7H35g3uuyrgdi++W0OzyUyz0hmIX vbmbEwtpvYa8Cfnmzv6z+pAiZQ+YYnMFUabc0oQ63YKit+WI9SwBd1z6XhWJshhJg2UJ pJQB+S+iIWX95qIxmaLJy8HwtM7wXH6jgbtA2Mr/7di/oX7VdgUBjY4AJ10nfAdHNmf1 7vKA+kJqvEfK6QcvDexCx//i7WAggFpkLJJblFYLBFdY8TzUZK/Vf7Q3dUuXZuG3CuTA ymVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oFXEPzd8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z1-20020aa7c641000000b004fd2aaa62d0si25039695edr.242.2023.03.26.02.24.02; Sun, 26 Mar 2023 02:24:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oFXEPzd8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232032AbjCZJWp (ORCPT + 99 others); Sun, 26 Mar 2023 05:22:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231881AbjCZJWZ (ORCPT ); Sun, 26 Mar 2023 05:22:25 -0400 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22E9C9740; Sun, 26 Mar 2023 02:22:24 -0700 (PDT) Received: by mail-qt1-x835.google.com with SMTP id hf2so5878003qtb.3; Sun, 26 Mar 2023 02:22:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679822543; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IttOk0+8XCKRMkImj0Us7L6S+8JkbptYujvUdCdqNsM=; b=oFXEPzd8QweT0zM+KjuIeU9h8UCXV3/G5mEHY2UeKsFbQI9jhWfABcjlcjJP79D5R0 BrYviuHlEmow2FWQv2UI09K958ibw7WP/cT4i6cWTSok4yz3gG1PujG66GMT34EmoNk1 4Pl/y4hbHOjkwNA0DVjbbVSKRYmQJq0dPvp9cYNWIwxy3bHSSrewTn3muC09lf5pdPeQ of3RgXmUdfkXleoPA5a8XtV5VdG7VAiup0dGZqSRezLf4v4dNARza+2ciiMOQ10MMy0V lRfEJq1z5+5g5LxwqZhHWQbgSduSqp6OzEAr7qcST9lI3JyqsiBM2DGVGU3Q0jv/gA/Q AGWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679822543; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IttOk0+8XCKRMkImj0Us7L6S+8JkbptYujvUdCdqNsM=; b=hoOrgcng4Y/JihUyBcgGbQAOZVl5PeOlf0gjYqS84eUeKsb+m39w7oTLCNkEU9NNbE SwM3vmzc+H2XU22XUZefe1Rnrr3lN5SF7LLaJi/cqOtiRl7f0DW559LYs9PorRv+Gro6 O5g7r09MPVDG/L7eELJVxnBOu7xLMFDvh28TUab6ag6n24SU+mJjM9r5GOtzQImaGfPX fiQJSE2lxcIQ9BaJXRQREGRiKfL9BNT9pHHhK4lHEefDUzc2xFY986dlVaAkQDGzM7fg kpImEu+QjBDoW9ClnRhW7qXe4sTOqulaHKN0VcxB15EZtx3gf7kBYdnxnnyiWWneDfUr fv+g== X-Gm-Message-State: AO0yUKWRbEDdW0EbVDgM01JO95VGI9L5Vxipj4x6BsN8kx9XnOOD6NeN XUY1SHY8EYh3uvhbkSn/lbI4718pgwlg6eWnp5k= X-Received: by 2002:a05:622a:214:b0:3e3:902a:a084 with SMTP id b20-20020a05622a021400b003e3902aa084mr14239455qtx.6.1679822543297; Sun, 26 Mar 2023 02:22:23 -0700 (PDT) Received: from vultr.guest ([2001:19f0:1000:1a1f:5400:4ff:fe5e:1d32]) by smtp.gmail.com with ESMTPSA id y5-20020ac87085000000b003e014845d9esm10257987qto.74.2023.03.26.02.22.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Mar 2023 02:22:22 -0700 (PDT) From: Yafang Shao To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Yafang Shao Subject: [RFC PATCH bpf-next 07/13] bpf: Add bpf helper to get bpf object id Date: Sun, 26 Mar 2023 09:22:02 +0000 Message-Id: <20230326092208.13613-8-laoar.shao@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230326092208.13613-1-laoar.shao@gmail.com> References: <20230326092208.13613-1-laoar.shao@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A new bpf helper is introduced to get bpf object id in a tracing bpf prog. Signed-off-by: Yafang Shao --- include/linux/bpf.h | 1 + include/uapi/linux/bpf.h | 7 +++++++ kernel/bpf/task_iter.c | 12 ++++++++++++ kernel/trace/bpf_trace.c | 2 ++ tools/include/uapi/linux/bpf.h | 7 +++++++ 5 files changed, 29 insertions(+) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 2d8f3f6..c94034a 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -2867,6 +2867,7 @@ static inline int bpf_fd_reuseport_array_update_elem(struct bpf_map *map, extern const struct bpf_func_proto bpf_user_ringbuf_drain_proto; extern const struct bpf_func_proto bpf_cgrp_storage_get_proto; extern const struct bpf_func_proto bpf_cgrp_storage_delete_proto; +extern const struct bpf_func_proto bpf_find_obj_id_proto; const struct bpf_func_proto *tracing_prog_func_proto( enum bpf_func_id func_id, const struct bpf_prog *prog); diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index e3d3b51..3009877 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -5540,6 +5540,12 @@ struct bpf_stack_build_id { * 0 on success. * * **-ENOENT** if the bpf_local_storage cannot be found. + * + * int bpf_find_obj_id(void *obj_id) + * Description + * Get bpf object id in current bpf namespace. + * Return + * bpf object id is returned on success. */ #define ___BPF_FUNC_MAPPER(FN, ctx...) \ FN(unspec, 0, ##ctx) \ @@ -5754,6 +5760,7 @@ struct bpf_stack_build_id { FN(user_ringbuf_drain, 209, ##ctx) \ FN(cgrp_storage_get, 210, ##ctx) \ FN(cgrp_storage_delete, 211, ##ctx) \ + FN(find_obj_id, 212, ##ctx) \ /* */ /* backwards-compatibility macros for users of __BPF_FUNC_MAPPER that don't diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c index c4ab9d6..a551743 100644 --- a/kernel/bpf/task_iter.c +++ b/kernel/bpf/task_iter.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "mmap_unlock_work.h" static const char * const iter_task_type_names[] = { @@ -823,6 +824,17 @@ static void bpf_iter_task_show_fdinfo(const struct bpf_iter_aux_info *aux, struc .arg5_type = ARG_ANYTHING, }; +BPF_CALL_1(bpf_find_obj_id, void *, obj_id) +{ + return bpf_obj_id_vnr(obj_id); +} + +const struct bpf_func_proto bpf_find_obj_id_proto = { + .func = bpf_find_obj_id, + .ret_type = RET_INTEGER, + .arg1_type = ARG_ANYTHING, +}; + DEFINE_PER_CPU(struct mmap_unlock_irq_work, mmap_unlock_work); static void do_mmap_read_unlock(struct irq_work *entry) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index bcf91bc..977bb61 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -1510,6 +1510,8 @@ static int __init bpf_key_sig_kfuncs_init(void) return &bpf_find_vma_proto; case BPF_FUNC_trace_vprintk: return bpf_get_trace_vprintk_proto(); + case BPF_FUNC_find_obj_id: + return &bpf_find_obj_id_proto; default: return bpf_base_func_proto(func_id); } diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index d6c5a02..8beacad 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -5540,6 +5540,12 @@ struct bpf_stack_build_id { * 0 on success. * * **-ENOENT** if the bpf_local_storage cannot be found. + * + * int bpf_find_obj_id(void *obj_id) + * Description + * Get bpf object id in current bpf namespace. + * Return + * bpf object id is returned on success. */ #define ___BPF_FUNC_MAPPER(FN, ctx...) \ FN(unspec, 0, ##ctx) \ @@ -5754,6 +5760,7 @@ struct bpf_stack_build_id { FN(user_ringbuf_drain, 209, ##ctx) \ FN(cgrp_storage_get, 210, ##ctx) \ FN(cgrp_storage_delete, 211, ##ctx) \ + FN(find_obj_id, 212, ##ctx) \ /* */ /* backwards-compatibility macros for users of __BPF_FUNC_MAPPER that don't -- 1.8.3.1