From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794243281; b=O3VAas2HprFoKtDohLLUsBcxdm3WQ3vbz1pFR+n+ziI6TTPsjCoTPBARkR5X48YRCmYt wNWNQOjEpLNggm0IgRVqT9of3imbnjmusahb5V8DDit2Lunx1YVAzw9Rg7LSm3ZI+4N3L wYZNbJK+lHdRta97Z0IglUXyKrHEouRKxxexfMJ8w7JTz8oO/2QHiCTfu1MS0VAZ98Kny 0i9qDPDSXXruxDY/TB9Le13wy9BFl+aWrM9BMiwOZqzkcR6LtGj7Qdev2At+PU59e4+04 JGAJzSNMQa5W6aA6DZ+iLgx4IjbO+x0+ZC1Ue7YYtocamrNACfiwaRHSf7t+TOy3Vlw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794243281; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=DLsTnaW3uXr9AC/QbRfpXuwiBDpvXM/nxSHrEfIP3lc=; b=2zK9ETbqjuuX3o+BTUgXUsjduTFZLYwJZNrj+XKwhibH1HfR/aREeLoFMwsKFFVLUfp9 fWZcZNBaucqQIFvNDJa6DTWcvWPaMPg1wmuBqKK4fG9WuI4z2XJd0pzC0WHj2u+DaCoZq lPIbO6wQ+PvcoW0Mseum6vz+AD6OvEU1UjJDqPwfvwOz8SAQfOctch9hW3ecU8oam7hiH A0rP265b36blCZJzcrIvHiF45SiW9jq+3TByYUXuo1IuenfuXGfjJh011KQQu2ut8kgl2 3Ksaale/8cuS5wnSESjYe+pR+7Kb9qxHmKM/p9wOIR2ald8V+53trgWEmfYIWTXn2LQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=P8e719wF; arc=none smtp.remote-ip=209.85.221.43 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F2E560A2635 for ; Mon, 9 Nov 2026 16:54:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0F2E560A2635 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=P8e719wF Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-48dee593f18so711169f8f.3 for ; Mon, 09 Nov 2026 08:54:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794243279; x=1794848079; darn=vger.kernel.org; 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:content-type; bh=DLsTnaW3uXr9AC/QbRfpXuwiBDpvXM/nxSHrEfIP3lc=; b=P8e719wF715utMM0BRS2kJqVSYe7YveQ4yQjF9Y97k3HMC2eLyNsR81rVvRxTet/+0 efqilVOrYrRw2N1MbsFwhDJ06wH2C1I6jHwgVzf5U694NTaMX3p5X4Zk9RXR/RQ5EY3x 7m4NS8oCbD41RfDBB8Jx6M+FkVV+5qKOS7/oRQ2W+1x5oQAoLoUGkFmPB07cqcCm1xZd 7j35awHvoSMcapN/fc64O/igLu46J3Ex3g9pJeudIaZF1CeoLM6HHC0pirXloJ/jTqeB Urd3DB0d601rhCF1ZfGGLRGzJgNnIQqWfl6gWX+7Ij2gLLcJdSeMpgbAxBfVoFK8JbUA kkUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794243279; x=1794848079; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=DLsTnaW3uXr9AC/QbRfpXuwiBDpvXM/nxSHrEfIP3lc=; b=cIUMCTKGJea5K/Mus0n7O097b7JhznKcYtk2o6+kqJ4D54EUwXgCziftmFam8hgGrt olgbBhbTlNmhvpjz6ek2Od1F4t8ec/BOjl4D2Ag5J9B/NFl8fbAla2TYwN4xW45zHN2E ST5vc8QaZdLmzMIzb4i5uKizYX9uJ1P1/aXbwV0aihmY81/ndGEntTQHv6O3PxqBlN4w yY9lnHG2DJEa7pSj4NYbdzaQHm7OU6fASQ214/PX7i1RWfJ9cq4O6f/PnEM/b3gAWMBS EFRbjcn3r0w6/hSXp32LK4pGYGzDj7vK7YPqYyflVScNsVdTrdqd9scPYhyIXZevFGXm WCCQ== X-Forwarded-Encrypted: i=1; AL+hErGloqZ6wJ8ueKCSxM+3Y4HjaRQgvJCAhMgYRjgbVFsuQ0KZipmyy1FlXEWp8G4h0LbqdClVeC4JmIf0b90=@vger.kernel.org X-Gm-Message-State: APuU4Z/lCtsS5MlOKJCiAHqgboLmloAtsTR3z3QHnTRg5+YrrCPyw4+n cv01+gfInsy+r5dRJ2/U7j/CLUiREqgYlsx+Y9eP91wnxpOIMkrfRVRr X-Gm-Gg: AYBFou3KEoiAhX1ZFLsejeUknnx75PxLNwZgEcJFHvgI7PZ2kFWj2yUE4M4D34to8kW OYJmgqoAnNyINgVjn+McizYO6KGTPfV2HS1xdWgs3Hw7r6jY84snJHn61axznUy23YnPXEhVjyo fU6czPeTimL97zVeSiT19SgbNvWR42X8IOhOi7RFC4O/+D8NZ5QOZ+kq4R+D1AS5vEo/RD+tasE JmvQtymqiZ1E/T1gGffHe7YhWPhyM2+Hua4YSeERoVaIcnx+2SH0xYGgynxp8iHB2Ej2EdaNRjv DGfdc0PfwBHjIsH3KIF6tI2GVO7F4LDM0qTNyf+9oOaxQlsBsAygt4B2tFqp9U+HeLiOqZuy0Fw VLHrQPwP/y5eirzTDVhQ3F63/y/HgaibCX0+ZB61rsmFwx/XHvlIQyfb6jRga/sbEzJ6x3KqjgV kmsmzhcOjLkhRsJIcvonfQQEnCqAT3qZ3Q4/dj23jyH0lERZ1bovQ34OI4U2dg1bqS3/xe0P4MW 9qJLo3FTWSBnk2jAzQjfwLfhOYAlsPq7Sq6R8KoC2DMDBb/N19JMvX1WjFPMoNYgxwlb6oSUzO3 nBx/SsMgxjGmbaBi5hZ3MDEfOLO0h+MAKAJO6NvX6qsmyo7n X-Received: by 2002:a05:6000:288f:b0:48e:5cd4:aa60 with SMTP id ffacd0b85a97d-49830206f10mr57743f8f.42.1794243279402; Mon, 09 Nov 2026 08:54:39 -0800 (PST) Received: from localhost.localdomain ([2a04:ee41:4:b2de:1ac0:4dff:fe0f:3782]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4959783fd04sm11392369f8f.47.2026.11.09.08.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2026 08:54:37 -0800 (PST) From: Anton Protopopov To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Alan Maguire , John Fastabend , Quentin Monnet , Christian Brauner , KP Singh , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , Sasha Levin , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Anton Protopopov Subject: [PATCH v2 bpf-next 02/18] bpf: Add a btf_id_set8_entry helper Date: Mon, 9 Nov 2026 17:05:22 +0000 Message-ID: <20261109170550.141443-3-a.s.protopopov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261109170550.141443-1-a.s.protopopov@gmail.com> References: <20261109170550.141443-1-a.s.protopopov@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The pairs of a struct btf_id_set8 have an anonymous type, and the btf_id_set8_contains() helper returns a void pointer to the pair it finds. All its users but one only check if a set contains an ID. The one which needs the flags, btf_kfunc_id_set_contains(), finds them as the word next to the ID. Name the type struct btf_id_set8_pair, and add a btf_id_set8_entry() helper which returns a pointer to it. Make btf_id_set8_contains() return bool, like btf_id_set_contains() does, and use the new helper in btf_kfunc_id_set_contains(). The layout of the set doesn't change. Update the tools copy of btf_ids.h as well. A later patch uses the new helper to set the flags of a pair. Signed-off-by: Anton Protopopov --- include/linux/btf.h | 8 +++++++- include/linux/btf_ids.h | 10 ++++++---- kernel/bpf/btf.c | 9 ++++----- tools/include/linux/btf_ids.h | 10 ++++++---- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/include/linux/btf.h b/include/linux/btf.h index 87fad4076f0e..00495e7833b6 100644 --- a/include/linux/btf.h +++ b/include/linux/btf.h @@ -558,11 +558,17 @@ static inline bool btf_id_set_contains(const struct btf_id_set *set, u32 id) return bsearch(&id, set->ids, set->cnt, sizeof(u32), btf_id_cmp_func) != NULL; } -static inline void *btf_id_set8_contains(const struct btf_id_set8 *set, u32 id) +static inline struct btf_id_set8_pair * +btf_id_set8_entry(const struct btf_id_set8 *set, u32 id) { return bsearch(&id, set->pairs, set->cnt, sizeof(set->pairs[0]), btf_id_cmp_func); } +static inline bool btf_id_set8_contains(const struct btf_id_set8 *set, u32 id) +{ + return btf_id_set8_entry(set, id) != NULL; +} + bool btf_param_match_suffix(const struct btf *btf, const struct btf_param *arg, const char *suffix); diff --git a/include/linux/btf_ids.h b/include/linux/btf_ids.h index f27b7db81100..f5985acf661b 100644 --- a/include/linux/btf_ids.h +++ b/include/linux/btf_ids.h @@ -19,13 +19,15 @@ struct btf_id_set { */ #define BTF_SET8_FMODRET (1 << 1) +struct btf_id_set8_pair { + u32 id; + u32 flags; +}; + struct btf_id_set8 { u32 cnt; u32 flags; - struct { - u32 id; - u32 flags; - } pairs[]; + struct btf_id_set8_pair pairs[]; }; #ifdef CONFIG_DEBUG_INFO_BTF diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 228b93d4f8c9..61d2df6776a9 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -9973,8 +9973,8 @@ static u32 *btf_kfunc_id_set_contains(const struct btf *btf, enum btf_kfunc_hook hook, u32 kfunc_btf_id) { + struct btf_id_set8_pair *pair; struct btf_id_set8 *set; - u32 *id; if (hook >= BTF_KFUNC_HOOK_MAX) return NULL; @@ -9983,11 +9983,10 @@ static u32 *btf_kfunc_id_set_contains(const struct btf *btf, set = btf->kfunc_set_tab->sets[hook]; if (!set) return NULL; - id = btf_id_set8_contains(set, kfunc_btf_id); - if (!id) + pair = btf_id_set8_entry(set, kfunc_btf_id); + if (!pair) return NULL; - /* The flags for BTF ID are located next to it */ - return id + 1; + return &pair->flags; } static bool __btf_kfunc_is_allowed(const struct btf *btf, diff --git a/tools/include/linux/btf_ids.h b/tools/include/linux/btf_ids.h index b371ef7241b9..3b5b2856c628 100644 --- a/tools/include/linux/btf_ids.h +++ b/tools/include/linux/btf_ids.h @@ -19,13 +19,15 @@ struct btf_id_set { */ #define BTF_SET8_FMODRET (1 << 1) +struct btf_id_set8_pair { + u32 id; + u32 flags; +}; + struct btf_id_set8 { u32 cnt; u32 flags; - struct { - u32 id; - u32 flags; - } pairs[]; + struct btf_id_set8_pair pairs[]; }; #ifdef CONFIG_DEBUG_INFO_BTF -- 2.43.0