From mboxrd@z Thu Jan 1 00:00:00 1970 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=QNaFk/2twM/0EUWA3GgRwM8LR9I1zw0MxJyOw+MjcKirJOshynCkWyfgY3cTz2XI6WkR EQzpUIBGUzU7dwQxTKfnoMVQ9SiEJZ47mMgDCPS7ggLJX5q/LIcnxc7rnji5xi0EEzwGa r21tKF9pBSxoy1usRnDwf6kwqCFcamQl0SlDMWSHXJ7Har9CW8c5NxbQQt7VO0trDhJG0 BPUWEXR6JyLiE7Eu7csZf7ut7Jqd2nlo6CfjQaiBmLlDP6zIXTvAi8WyxyFsiqlvfvLKW HTgpwTl7QCripF6NOu8rvJyKcN3ZoZIyzfevv+kqqQTvDXHKFGd78V4/RdAo/82OGxQ== 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-Forwarded-Encrypted: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=rPpnx2q3mPLc5WD7LaZ7OPXjg9VttnP62Z3Ocn+SnOHx/vj++KgQkxQqOlGkNCFZWSXs lsTMo7+N9ZtcNqT2VVLf1zgL38TPM13BylIqCj9NjMaPsY8yW5B0+PXSldb0MrwRe0p3T lj8IK470e6fqdq7V4UzH/a4q8YOX6ByWN5wj45wSwY4wJC8gXAh9e4fyh6ue2EBl2ko5a Z70Qy83JH3c3lYxNEy7nxFlDS9UOysaiDIHtxLXdCdRblU39aHp5zArTC4TF9Z3c5CqLG jUUIOt3W8KLTa6jcYbdYZEmvf2Q0qgpJ+j8h4omfSSU5qPQKdwv5/DtQWj3yKZKCE/g== 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 BD41C606A322 for ; Tue, 1 Dec 2026 17:33:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BD41C606A322 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-9213730b07eso192628956d6.1 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=fXLiazeDzMOkhvYA6MwUpRMPbxHnxMNWJtMlwvJP8W0WyauhK6jTDZMY/JVy8Txr2B O5nwn5dvZLEYXwjOnmd2uHIz9D8Bo923dTBg9NRrHduljIg6Zflxa6C/aF0ufhmRNXlY umdzsLDqZ9tcKfDJ72WuJzn+eDAuJR5GCc2RhnAFfYnmpa7F1noNL8E8uvPFBAw9uPcZ YJSY1gITiX71W5C26EBSBPCvXrBxDHNL7kdbyNfAQ9rRnCfdO2m1juDO9sgih8nY4fW7 fO/gsXnKdC+GLVCduI3pgDJeUBnTI2+JwC8bEWLURe8YkU1BNs16WQ27okaEwyNWcOXR 3ORQ== X-Forwarded-Encrypted: i=1; AL+hErFhkiO72MOFD20DMVwhe3b/4o9SVuJjoFRi5UvNoi5UR9wpwI8nr/ku5WALEwI92WsIzZEDLaj1J5AZN4M=@vger.kernel.org X-Gm-Message-State: APuU4Z9vT0XD/5sVKIlp+PJJsc8v5RSWPN1DgmSg4p7EUJ4P/ybAVGHY jX8LFdxokl+sOkhWUocAxtqsTyJx5W3EijON7WT7+JQDb+qnUD6Ad1Fa/GTYvjOslPNDNo8Enfn 8fXsxFqkLsrexGwphuA== 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: linux-kernel@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