From patchwork Wed Jan 24 02:21:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13528385 X-Patchwork-Delegate: paul@paul-moore.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B4EB168B1; Wed, 24 Jan 2024 02:22:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706062939; cv=none; b=Nf80kWx4gw/ghmaKnt343DC8Vjb0HC5FiGw1ixpUTwWYuCkPrKMrSj4ATQpmx0YKaUijgMrNlkKlCA14LWAm6UL/8jZaYUSDpT7tL9rArQQVxn7m9vWgokhI6mJP29blM+206DxEIeAMHMvJJlstZNaL3KwKWmpT2kxb2QMDg9o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706062939; c=relaxed/simple; bh=OAf0H8xCjgTehuy6LEv785Gpeiz7HDBuitlgXR1tzP0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FboUrxJfwSbmpDGUhwsPRkJQ3l7TcehIoBcoc3I9+q+dWDqCj01XhOOB6Cnc0zoSClr+sbOlqAUeCrVJjZPaU+UbStcrEl52LAHYaLbqylQsjGIirG7lvBRxTYrGDTGVguxSXv0dwHOcmkyCH7jPbvKGD2A/6KKFBXb9oFj/vDA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HCWOufW8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HCWOufW8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C530C433C7; Wed, 24 Jan 2024 02:22:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706062939; bh=OAf0H8xCjgTehuy6LEv785Gpeiz7HDBuitlgXR1tzP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HCWOufW8NjxXHeZtsX5Da22b8eFnTSjLYENxmBuC1VUK6yHt1377m65n7tJr1pW6n JvPJ3ecN+dXZdQ9IegvCZ7n/BNP8NfBXP70ugmwqr8JQLZTROaTpzCj9D9GONh8j5E 12cQfsqMPJdzXiATQhu06sIgUL57CrXWu42vYa5RQCWOCEtKHPxkxOMVKYXek3gyc5 wmqaLgPJvQKaTpgH2RrSUInpmgI94D8yKKNXsfC3kIkB8P18grMgaMNYEafewXFJRC MoXCxvXCweAsmQmvcJ63uKJMt9zRqUq+3pUn+hv1+suLQ5yjgMZUGQrmwMtLdc2JrV FFizHsG70AEHQ== From: Andrii Nakryiko To: bpf@vger.kernel.org, netdev@vger.kernel.org, paul@paul-moore.com, brauner@kernel.org Cc: torvalds@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, kernel-team@meta.com Subject: [PATCH v2 bpf-next 13/30] libbpf: add BPF token support to bpf_map_create() API Date: Tue, 23 Jan 2024 18:21:10 -0800 Message-Id: <20240124022127.2379740-14-andrii@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240124022127.2379740-1-andrii@kernel.org> References: <20240124022127.2379740-1-andrii@kernel.org> Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add ability to provide token_fd for BPF_MAP_CREATE command through bpf_map_create() API. Signed-off-by: Andrii Nakryiko --- tools/lib/bpf/bpf.c | 4 +++- tools/lib/bpf/bpf.h | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index d4019928a864..1653b64b7015 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -169,7 +169,7 @@ int bpf_map_create(enum bpf_map_type map_type, __u32 max_entries, const struct bpf_map_create_opts *opts) { - const size_t attr_sz = offsetofend(union bpf_attr, map_extra); + const size_t attr_sz = offsetofend(union bpf_attr, map_token_fd); union bpf_attr attr; int fd; @@ -198,6 +198,8 @@ int bpf_map_create(enum bpf_map_type map_type, attr.numa_node = OPTS_GET(opts, numa_node, 0); attr.map_ifindex = OPTS_GET(opts, map_ifindex, 0); + attr.map_token_fd = OPTS_GET(opts, token_fd, 0); + fd = sys_bpf_fd(BPF_MAP_CREATE, &attr, attr_sz); return libbpf_err_errno(fd); } diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index e49254c9f68f..ae2136f596b4 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h @@ -51,8 +51,11 @@ struct bpf_map_create_opts { __u32 numa_node; __u32 map_ifindex; + + __u32 token_fd; + size_t :0; }; -#define bpf_map_create_opts__last_field map_ifindex +#define bpf_map_create_opts__last_field token_fd LIBBPF_API int bpf_map_create(enum bpf_map_type map_type, const char *map_name,