All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roberto Sassu <roberto.sassu@huawei.com>
To: <ast@kernel.org>, <daniel@iogearbox.net>, <andrii@kernel.org>,
	<kpsingh@kernel.org>
Cc: <bpf@vger.kernel.org>, <netdev@vger.kernel.org>,
	<linux-kselftest@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Roberto Sassu <roberto.sassu@huawei.com>
Subject: [PATCH v2 2/9] libbpf: Introduce bpf_obj_get_flags()
Date: Thu, 2 Jun 2022 16:37:41 +0200	[thread overview]
Message-ID: <20220602143748.673971-3-roberto.sassu@huawei.com> (raw)
In-Reply-To: <20220602143748.673971-1-roberto.sassu@huawei.com>

Introduce the bpf_obj_get_flags() function, so that it is possible to
specify the needed permissions for obtaining a file descriptor from a
pinned object.

Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
---
 tools/lib/bpf/bpf.c      | 8 +++++++-
 tools/lib/bpf/bpf.h      | 1 +
 tools/lib/bpf/libbpf.map | 1 +
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 33bac2006043..a5fc40f6ce13 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -670,18 +670,24 @@ int bpf_obj_pin(int fd, const char *pathname)
 	return libbpf_err_errno(ret);
 }
 
-int bpf_obj_get(const char *pathname)
+int bpf_obj_get_flags(const char *pathname, __u32 flags)
 {
 	union bpf_attr attr;
 	int fd;
 
 	memset(&attr, 0, sizeof(attr));
 	attr.pathname = ptr_to_u64((void *)pathname);
+	attr.file_flags = flags;
 
 	fd = sys_bpf_fd(BPF_OBJ_GET, &attr, sizeof(attr));
 	return libbpf_err_errno(fd);
 }
 
+int bpf_obj_get(const char *pathname)
+{
+	return bpf_obj_get_flags(pathname, 0);
+}
+
 int bpf_prog_attach(int prog_fd, int target_fd, enum bpf_attach_type type,
 		    unsigned int flags)
 {
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index 20e4c852362d..6d0ceb2e90c4 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -339,6 +339,7 @@ LIBBPF_API int bpf_map_update_batch(int fd, const void *keys, const void *values
 				    const struct bpf_map_batch_opts *opts);
 
 LIBBPF_API int bpf_obj_pin(int fd, const char *pathname);
+LIBBPF_API int bpf_obj_get_flags(const char *pathname, __u32 flags);
 LIBBPF_API int bpf_obj_get(const char *pathname);
 
 struct bpf_prog_attach_opts {
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index 019278e66836..6c3ace12b27b 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -467,6 +467,7 @@ LIBBPF_1.0.0 {
 		libbpf_bpf_map_type_str;
 		libbpf_bpf_prog_type_str;
 		bpf_map_get_fd_by_id_flags;
+		bpf_obj_get_flags;
 
 	local: *;
 };
-- 
2.25.1


  parent reply	other threads:[~2022-06-02 14:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-02 14:37 [PATCH v2 0/9] bpf: Per-operation map permissions Roberto Sassu
2022-06-02 14:37 ` [PATCH v2 1/9] libbpf: Introduce bpf_map_get_fd_by_id_flags() Roberto Sassu
2022-06-03 20:58   ` Andrii Nakryiko
2022-06-02 14:37 ` Roberto Sassu [this message]
2022-06-03 20:59   ` [PATCH v2 2/9] libbpf: Introduce bpf_obj_get_flags() Andrii Nakryiko
2022-06-02 14:37 ` [PATCH v2 3/9] bpftool: Add flags parameter to open_obj_pinned_any() and open_obj_pinned() Roberto Sassu
2022-06-02 14:37 ` [PATCH v2 4/9] bpftool: Add flags parameter to *_parse_fd() functions Roberto Sassu
2022-06-02 14:37 ` [PATCH v2 5/9] bpftool: Add flags parameter to map_parse_fds() Roberto Sassu
2022-06-02 14:37 ` [PATCH v2 6/9] bpftool: Add flags parameter to map_parse_fd_and_info() Roberto Sassu
2022-06-02 14:37 ` [PATCH v2 7/9] bpftool: Add flags parameter in struct_ops functions Roberto Sassu
2022-06-02 14:37 ` [PATCH v2 8/9] bpftool: Adjust map permissions Roberto Sassu
2022-06-02 14:37 ` [PATCH v2 9/9] selftests/bpf: Add map access tests Roberto Sassu
2022-06-03 20:59   ` Andrii Nakryiko
2022-06-03 21:00 ` [PATCH v2 0/9] bpf: Per-operation map permissions Andrii Nakryiko
2022-06-09 12:55   ` Roberto Sassu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220602143748.673971-3-roberto.sassu@huawei.com \
    --to=roberto.sassu@huawei.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.