From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796075145; b=4h1cZIjpsrJH1WMF+XIqtRm7iGd3bWvk4g9MP+pvnS/jK+ggrP5QB6roTq3MFK6gBHuh JuydZ/Oc9LVYt7stkhBStT4fOSCUI+p+oNpErV1mAuConKOKO3e2fApnKXc6LDJyWX2TR ObD3LHCaN+LYVZbe/2shphoQXha2wHEtGVRxrYzN0GayHk3LUSIHC4lFNonWzHo6Tq5Ai FgzLdD1raHI/t65DzsvwrmCyf6hn4ZgcRV1aUOicxsYvJ7E/CMjlZQEmr+MNiH+AaX/00 EP0VIfUL8eADwPEkTPpd1CJFurmDRKp81cqoIvH5j6HQPBqVpz4UEqVXJpiEByXB6cw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796075145; 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=r+B7RPp0OS2B+JecoBB8vNrwg0jk7Acn9B4sspKLsMb1RA7uZn2WIWPki1aJQguyeiuQ b4xipDzKuPHi90tTdAHL9wnd7DOFoxwUhG1dn6h0f4xdM2f10CZPdMtyrIhvPFh/UauD0 fNy5gYnXECdZffZn0hFDM3rhHdGirEHuxRLP+RDBCPRuSYrlVdcAxQiZLGmKXgAJWc0LH p9O/tYDhzQqaA/Bu6yX/kqk4VMBpUP4Wy8R8aiRGZpZOdFih3xC90q5xS2lo7X6BSvx+i UcX8FgKhIeDYzv/O69tdDbY+crg+qfyBgI3siA1RYS9Wtm4QWbgNHs7dw80Oooli4ng== 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.199 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (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 102F2606A320 for ; Mon, 30 Nov 2026 21:45:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 102F2606A320 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-f199.google.com with SMTP id af79cd13be357-93f26dd2165so2636946485a.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=B1CdUIZr6Mmdmn2WtbQFjgtWuJHFR25/NqGqXV4lyfqOxoutxYA1aP7vCVZTuzpb1S QhnD/JM2SOYkP+0CsmThN7M83rDDzpNXadziKf2l/8v71I86wHLElbU+5Qmj2g1iQsA9 F3jOuFozlNh2ys2D8ylThPtbxJPCLqGT7JW86tiNBo8HSRiOMUJd/ipVuxOmOO6vzUGg ZbgGVMPE9ij8AE3LQ58L17Ar6Gytp2beWZt3blNAAfDHxGNQPnv214QxWjGbOShvjha6 wMIYjPjl2Mjd5eQ56FkpeKs2orcrgsMwxPm/6dOTqq9XAEGuoSWvIAQokFmFUmKDXdpi aw1g== X-Forwarded-Encrypted: i=1; AL+hErEvuxkD2YGvgX0czXxJlZ6JkO2WL8rT4ib4ptb/TA8ceSerYJ7GfRvjEKNMT/2ichDMT+LQwwfu2NCLidV4APY=@vger.kernel.org X-Gm-Message-State: APuU4Z/2np/MC2rB/xKsV0/J6hQ1igGGdgBbAgdSSc6BJOiJ6ZSxalWA xXlmlNmxaVPylDlFwvOwofr5qn7bAchXjRp4kRY41I/vGk/1YeaCzsNLyMMqB1P4k1vUFHmj1Do up+k4T71EfIXfUDDm8A== 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-kselftest@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