From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796075144; b=laoOW2fQ4sETQqXfBWo3EUHEeL762DvGBa+n3ZqcaBWdKUzcYllOrK3R0sJixPodh9LS 6/xzk71B9HU2AMTma5n2h06SY6NVbZAcYkKHcmtQ3yHBk9/gGFScTA4biEl9EokM5HTzT BzUzEYnTXVoOx5n71itC+3niqLrhthzD4l4vd8A2DCWXForT/FRz/8wQQwZK1PwA+N3t1 gKtbBfNifX2MLV7VKeyI5FXgz/1ExnGIvE5ID5sEQ4oS76rZ2Y1hs9vyl3nzQcwtuEgfI l8cyDLCGlOI+14/rHIeJtvzW5mNk0sTsqDIqYIwV3ETRpTS8GCmBdYrooWoZKsdSnAw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796075144; 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=o5Ckmh6l6VmGsjbNdINxLqWmayyKrzIiIxB8oqF1y7o=; b=NvdlWmA1i+6lQ+o5bvVvdrQj9Q3w1L+UC7rCX2vlMZ3/42NWUU4pvfvwr4azMpn6SWqp jdblXNp1kq3R9MllE/0YbvLvTUBEvXpRNQFMIep98YTQd6PSN5ApvFUd5HENlHrfzAdcZ HvnaCmfzyWLEs5e2PmIweI4d3NYPEM5boUykA17+INlZ0MlVW3uerJ0pbeg4u1C87NzeA SObLfuwN7SuvlSR+W0gAhHVzUphIWChM8Zt0//VItPP0bQ9WeKKGZu2r4yeAV/XUEUA71 SlJlKRYzpJ4C29m7uXX54qe5Uc7heHGEmAB8N4EtQ7nqFcXWQkYQlGvv0PJLpYb2KJA== 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=POR4UFrY; arc=none smtp.remote-ip=209.85.222.200 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (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 02DC4606A31A for ; Mon, 30 Nov 2026 21:45:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 02DC4606A31A 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=POR4UFrY Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-93f26dd2165so2636946585a.3 for ; Mon, 30 Nov 2026 13:45:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796075143; x=1796679943; 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=o5Ckmh6l6VmGsjbNdINxLqWmayyKrzIiIxB8oqF1y7o=; b=POR4UFrYjc12uSHiXHxWQvniXKp1KQDbsZMEPeFngvioOUjDmR/fjrYmW2EZ+Tto0t fUgBJ1NSq+CDiD3cA2dRPamx84GS5TSxfs2IAITNmRgu5NENee7KorGWl/OtMDorPXkE dF48qUNAFTt9MaM+HNbhNqmqVK/A5v1USyoBZiLadZ+W7nEewvDVPHZxGf+tOHKrPqM6 LAb9KePl644COjJh0Te2heYrAIpvcPFlgd1gkyimO4nrNyCNuoFGy+1f66BNX4D3PiB3 h5fZ5H4EbcFfZ2T8iklQLPsFiefL7Wak8hHuFNz6TsLvI8aHxsuWG1EEjKJFprNlUIXx K7mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796075143; x=1796679943; 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=o5Ckmh6l6VmGsjbNdINxLqWmayyKrzIiIxB8oqF1y7o=; b=1nuzNf1StJ59wBPhj2ZiH/quTXDenS3PJ8J1X1stjkDIWyV0b5cZ59Ka8gXgDQrgdn Kdckb/okJQlYC1QPzX63PfiN70YC8dbj/L7vuOnzfUxNMwjsQ+BHDu96sWsJCw5J3ChC vmCYqNGz8ql2YE0vPv70mhPqiH7gd9MSGzss3T825yw2Xo/HjoJ6Swl02dFv0WIIzKNx oJaRHjaZuvIivmd6i9HbxV+NdyyaXD6x1C5Sk5JReakZzI5bUsvv98zt8xty96d6TS1o oBXxiuf9ImIl2zTms14xKkUtGqAsselqsobelaUPSwGqTIlvHm8mokJts9L2Li6uwbtJ arnQ== X-Forwarded-Encrypted: i=1; AL+hErHxGFfIVnRmxYxh7clSJX97Hge79e5nVGi7/IltIFWBumDbs18SfCuoWlEVG4KxeCKB+QpiggMf6do2ITI=@vger.kernel.org X-Gm-Message-State: APuU4Z9aqV4E0ehOKkNMJkp+TkdrqMGFyvIJbgGlz53WyoYr1dM8We8Q sKErHvUcrbjK4GeE/pUlo6JqLUWr3GcTCfTS0NnU/8VSw4WX4e1eHNUHTNxKijHd6KpRLuyVwrb 57qi104WUW7BqM/RPxA== X-Received: from qkax2-n2.prod.google.com ([2002:a05:620a:2242:20b0:93f:31eb:2292]) (user=sidnayyar job=prod-delivery.src-stubby-dispatcher) by 2002:a05:620a:a710:b0:94a:3880:e654 with SMTP id af79cd13be357-94a3880e676mr1144709685a.80.1796075142627; Mon, 30 Nov 2026 13:45:42 -0800 (PST) Date: Mon, 30 Nov 2026 21:44:45 +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=H4sIAE7uDWsC/2WNQQ6CMBBFr0Jm7Zi2NlVceQ/DAuoUGpGSTiUY0 rvbEHcuX17++xswRU8M12qDSItnH6YC6lCBHdqpJ/SPwqCEMlIKhSM/aURO8W0ThplRnEQttNL WtQrKbI7k/Lon79DNDidaEzTFDJ5TiJ/9a5G7/2XNf3aRKLDV+mKcs+fadrc+hH6kow0vaHLOX 9gfRoy7AAAA X-Change-Id: 20261102-lskel-struct-ops-03090424cfa2 X-Mailer: b4 0.14.3 Message-ID: <20261130-lskel-struct-ops-v2-0-8b76e65073ab@google.com> Subject: [PATCH bpf-next v2 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 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 | 236 ++++++++++++++++++++- 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 | 122 +++++++++++ tools/testing/selftests/bpf/progs/struct_ops_mod.c | 52 +++++ .../selftests/bpf/progs/struct_ops_vmlinux.c | 42 ++++ 13 files changed, 715 insertions(+), 22 deletions(-) --- base-commit: b7a509bd447085118d03dd962d2cca308e283b57 change-id: 20261102-lskel-struct-ops-03090424cfa2 Best regards, -- Siddharth Nayyar