Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.219.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796146426; b=HtmwdQNJEjI+7QWnOwmZSC9mVdftJpUnx14Ozkfj8VJIRQl8kWwtGikvxXxB1/buz8tC 0N7DxkuLi47UNji0+Ls4JCGeHyAEEiZtDVUQHkcmPV9V7lnmg/ef5z8O1VjoIIlj0JpNz UMHBKQH+jkOJttB8vUSnVr/kVs3zZJvz2iGCkqfOfgVSIYWg2mWCoqKuiJRt/OA+sesZ1 OOccF4g9l6zQti7VjINU8qeU7tMKUhPVywz+aWgCjT12X9eAtjGwX4HiA9PLmU84xTGZU doa8PqU91fqZrBI0dUaHy0aQCxtNQZXt7BL5/QKOEzlUWun+tKW4AB5Nc1dcxYSZvxg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796146426; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Received:Date:Mime-Version:X-B4-Tracking: X-Change-Id:X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=VKlSUTAmU/dqDs2J5zK/0vSDpm7rIWF/l24z3iNUf2g=; b=nS14F3hzchyTuH0Kp+noziAX/JOBfS+QWHTv7QdvGLO8KuNGdTEQDKFoyDtEZ4zkRphE 53Xz88CbgWUlcTg9Ca+yorkOxqiOn6mihbso3r/+sUKfDQvSHeraQU47/DsWDkReQvYdf A8jFWAE728ZEYziZEANr/UUKkKUd+Vry4UFTiCyS3E8gA+ylIoqbXqL2LSmabsW8d2N9W 8ZT5D8Z+sS15YPZSHD8nvpfB9gIZo5XFZ00/sobjqMDbDDEHoKoLxn2IM0yww/xdfznIN WmLTI9Jq3gqQBXERRTfP5k7PzI7Q0JRmdn/n6P8yGwoaSPH3Dc1Cq+2/JEKoBZRqiwQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--sidnayyar.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=VJxawphI; arc=none smtp.remote-ip=209.85.219.70 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (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 BD36D606A320 for ; Tue, 1 Dec 2026 17:33:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BD36D606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sidnayyar.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=VJxawphI Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-9212d968d19so190551476d6.3 for ; Tue, 01 Dec 2026 09:33:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796146424; x=1796751224; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=VKlSUTAmU/dqDs2J5zK/0vSDpm7rIWF/l24z3iNUf2g=; b=VJxawphIWTDWOURyDB1ToVglEWcwOS6SqmuGUIJZjj/K57Yc9ZOEesLyYalCKYo0qD hjPZnSvew6f3BRPSnkT4vZrB47CB7qRklMhxd1p0qBDhpEMsTg0FKExbSh23rQ2ec9IR b9T0kiJbczRazKpEYRr1ydlhpQMt7eiSErcMFSgpcLOBJmsD6qhcYY0kJQIJwZZN/otl uc5JHOhsr9QsAXlhgVvfuRO4+rhxyp3YqpjN62vVY5Z6X52Y5SMlZSfXYpHfbfTCofmY fCgDUte6iYBEN7kK6U5BYIsFq0wEsBqBcNVNmW8m8JZs4+wu9FITKs8ig2YfWNDLxXpB c1HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796146424; x=1796751224; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=VKlSUTAmU/dqDs2J5zK/0vSDpm7rIWF/l24z3iNUf2g=; b=AnRoLuis7MQ2BXd6vqRDmbC7v+cfvmDsxwwyLXLoGY/ipk2I0z7/t247BH/UzZ3YVX 6NyFOEBKrLSMT7dCfsywnnuufkU+8QFTUKpAS8fYdfY/nao1DNSyDt51U2dgL9EiYmlt abXDXlU6yIZvIPQVY1jlf/qaabuzC2R47x3O+abUdnVIoJKFEhsRDm59qm27FxjVnVk6 w7vmX6mo/3yoKygMPoEgSxEkdHSGRGC3W3/ZRSQmnBLbHQtGF5qvcTAGy/fnR1MbgSDv P0BYsJiNUN9OUgcXCf1a+9IIZA4Sf13aDVpFYl2CE/lns6p/xKDqm6OKkjaI2bEMCosd +ASA== X-Gm-Message-State: APuU4Z8Dgisjws25xphRuBrycHQVnz5QnRMBWD3bjPUbdXnOGX9D9wRk BpToAUqmw6s95zFE/kixfvCynyO1AVP0mpsasXxfrdjkGP3ZrmgQuwcFx7sek/1E3pl6C3K4UKO KrY8b0eFzvq5KC1YhIA== X-Received: from qvh14.prod.google.com ([2002:a05:6214:d0e:b0:921:3bc:3a87]) (user=sidnayyar job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6214:29e8:b0:91b:8b2b:5a0 with SMTP id 6a1803df08f44-92134a59f89mr715411676d6.23.1796146422630; Tue, 01 Dec 2026 09:33:42 -0800 (PST) Date: Tue, 01 Dec 2026 17:33:36 +0000 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAPAED2sC/23NSw7CIBgE4Ks0rMXwkrauvIdxQfGnJdbSAJKap neXEBcaXU4m882KAngLAR2rFXlINlg35cB3FdKDmnrA9pozYoRJSgnDY7jBiEP0Dx2xmwMmnLR EMKGNYijPZg/GLoU8o242eIIloktuBhui88/ylWjp36z8ZRPFBCshGmmMrlvdnXrn+hH22t2Ll tiHwMkfgWWh6WoJ8kBqrr6FbdtePHU8xv0AAAA= X-Change-Id: 20261102-lskel-struct-ops-03090424cfa2 X-Mailer: b4 0.14.3 Message-ID: <20261201-lskel-struct-ops-v3-0-057f3d23ac0c@google.com> Subject: [PATCH bpf-next v3 0/4] bpf: Support struct_ops in light skeletons From: Siddharth Nayyar To: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , Quentin Monnet , Shuah Khan Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Anton Protopopov , Giuliano Procida , Neill Kapron , "=?utf-8?q?Thi=C3=A9baud_Weksteen?=" , Maxime Ripard , Siddharth Nayyar , Alexei Starovoitov Content-Type: text/plain; charset="utf-8" BPF light skeletons (bpftool gen skeleton -L) compile BPF object loading into a self-contained BPF_PROG_TYPE_SYSCALL loader program (gen_loader) embedded in a C header, removing any runtime dependency on libbpf or userspace BTF parsing. Currently, light skeletons do not support BPF_MAP_TYPE_STRUCT_OPS maps or BPF_PROG_TYPE_STRUCT_OPS programs because preparing a struct_ops map normally relies on libbpf parsing the target vmlinux or kernel module BTF in userspace to resolve type IDs, struct sizes, member byte offsets, and member indices. Since the kernel already has access to both the BPF object's BTF (loaded by the light skeleton via btf_fd) and vmlinux/module BTFs, the loader can pass static object-BTF metadata known at skeleton generation time and let the kernel match the target struct_ops type and members by name. This avoids adding a new BPF helper or kfunc, eliminates runtime BTF queries and module BTF FD management from the loader program, and avoids pre-allocating a fixed-size kernel value buffer in the loader blob. This series adds BPF_MAP_TYPE_STRUCT_OPS support for link-based (SEC(".struct_ops.link")) maps in light skeletons across both vmlinux and kernel module BTF targets: - Patch 1 teaches the kernel to resolve BPF_MAP_TYPE_STRUCT_OPS maps and BPF_PROG_TYPE_STRUCT_OPS attach targets from the BPF object's BTF by name (stripping any CO-RE ___flavor suffix). BPF_MAP_CREATE accepts a local struct btf_value_type_id and value_size, BPF_PROG_LOAD accepts the object BTF FD in attach_btf_obj_fd with the local struct ID and member index, and BPF_MAP_UPDATE_ELEM validates and copies the local struct layout into the kernel struct_ops value buffer. - Patch 2 updates libbpf's gen_loader to record local struct_ops type IDs and member indices, retain btf_value_type_id on BPF_MAP_CREATE, pass the object btf_fd in attach_btf_obj_fd on BPF_PROG_LOAD, and emit bpf_gen__struct_ops_update_elem() to populate callback FDs and issue BPF_MAP_UPDATE_ELEM. - Patch 3 teaches bpftool to generate per-map skel_link_create() attach functions and skel__attach() / skel__detach() plumbing for BPF_F_LINK struct_ops maps in light skeletons, skips gen_st_ops_shadow() so the light skeleton ctx layout is preserved, and rejects non-link struct_ops maps. - Patch 4 adds light skeleton struct_ops selftests covering both vmlinux (tcp_congestion_ops) and bpf_testmod (bpf_testmod_ops, including a reordered subset struct bpf_testmod_ops___v2 with a zeroed member absent from the kernel, shared callbacks, scalar fields, detach, and per-map re-attachment). Non-link struct_ops support =========================== Non-link struct_ops maps (SEC(".struct_ops") without BPF_F_LINK) remain rejected in light skeletons for now. Because BPF_MAP_UPDATE_ELEM runs inside the loader program during skel__load(), a non-link struct_ops map would register and activate callbacks before skel__attach() is called, prevent re-attaching after detach, and leak an active registration if a later loader step fails. Supporting non-link struct_ops can be added as follow-up work by deferring BPF_MAP_UPDATE_ELEM to userspace skel__attach(). AI assistance and testing ========================= This series (code, selftests, commit messages, and cover letter) was developed interactively with an AI coding assistant (Google Gemini), with me guiding the design step by step across each patch and reviewing all changes. The series was built with clang/LLVM and tested in a QEMU x86_64 VM using test_progs (covering the new struct_ops_lskel selftests for both vmlinux tcp_congestion_ops and bpf_testmod_ops, as well as existing struct_ops and light skeleton tests). Signed-off-by: Siddharth Nayyar --- Changes in v3: - Bounds-check local struct members against the local struct size and reject non-kflag bitfields and unaligned bit offsets in local_to_kern_value(). - Pin module BTF via btf_try_get_module() before searching struct_ops_tab in find_desc_by_local_type() to avoid racing with module init. - Remove the redundant function-pointer mismatch check (allowing NULL void * callback placeholders) and local struct padding-hole check in local_to_kern_value(). - Add selftest coverage for a NULL void * callback placeholder in bpf_testmod_ops___v2 and an invalid_local_btf subtest verifying rejection of crafted local BTF structs. - Link to v2: https://lore.kernel.org/r/20261130-lskel-struct-ops-v2-0-8b76e65073ab@google.com Changes in v2: - Replaced the BPF helper approach from v1 with kernel-side object-BTF name matching as suggested by Alexei Starovoitov, replacing patches 1-5 with two patches (kernel and libbpf). - Added kernel validation for local member BTF kind/func-ptr matching, non-zero padding holes, and non-kernel btf_fd, and synced st_ops->progs from st_ops->data in libbpf. - Updated bpftool light skeleton skel__detach() to zero detached struct_ops link FDs. - Updated struct_ops_lskel selftests to assert detached link FDs are zeroed and to test skipping a zeroed field absent from the kernel. - Dropped the RFC prefix. - Link to v1: https://lore.kernel.org/r/20261106-lskel-struct-ops-v1-0-a4486ffc79cb@google.com --- Siddharth Nayyar (4): bpf: Support struct_ops with object BTF libbpf: Support struct_ops in light skeleton loader bpftool: Generate attach and detach for struct_ops in light skeletons selftests/bpf: Add light skeleton struct_ops tests include/linux/bpf.h | 14 ++ include/uapi/linux/bpf.h | 17 +- kernel/bpf/bpf_struct_ops.c | 266 ++++++++++++++++++++- kernel/bpf/syscall.c | 14 +- tools/bpf/bpftool/gen.c | 72 +++++- tools/include/uapi/linux/bpf.h | 17 +- tools/lib/bpf/bpf_gen_internal.h | 3 + tools/lib/bpf/gen_loader.c | 35 +++ tools/lib/bpf/libbpf.c | 110 ++++++++- tools/testing/selftests/bpf/Makefile.skel | 3 +- .../selftests/bpf/prog_tests/struct_ops_lskel.c | 200 ++++++++++++++++ tools/testing/selftests/bpf/progs/struct_ops_mod.c | 53 ++++ .../selftests/bpf/progs/struct_ops_vmlinux.c | 42 ++++ 13 files changed, 824 insertions(+), 22 deletions(-) --- base-commit: b7a509bd447085118d03dd962d2cca308e283b57 change-id: 20261102-lskel-struct-ops-03090424cfa2 Best regards, -- Siddharth Nayyar