From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.198 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796075144; b=zVmzQx5abtxhsnNYbsnlbwdrUq0bIRXln9bsGDEzNQfhOSwINYnL9Yn37y8zhVuh1bTM 1YGQ/lofXSac18JfbWcPL7KQS9vyRjmFizKucGPUCqkgNjxYsCVnsMMJvpisBMIUv7uDO nHCGU44RRT03jyba46J9M4xGi6hl1IwuoM2USDPIcARKAqU7BrjMjmWTsetZC9pXoj54T bLY1HzlfRhcZGqDO9Lu/4uipDO6tia8Gw6IrsjTqlRoMXJEOj2vPemSoTT4iu/g7pGOP7 5h6xy+dY3npJSl4bT6bVJRHobcOEcMIBVDh16bJf6vOtJLF3zzK3VFMmwvJlBW0pclg== 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-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=D39cBk2E7Y05mFaYq14SHosKWqWoVmwEPxbzWk8Dc08oXKoSqvO4xEg9FWMyLvmt2Ep2 BwO6yw+garp8XSOQTHjdIMPfEt/EubwtkDabTWZscTWzVaVlyDCDuEYEPnAFd4BpN5E7z x35DlZ86J6lCx89Z+DvXOK8tCETIGMcdVzC/n203taFu1cG7OI8RoFWSY39EmdjFAQXPx 8BO5jgx1rIGAJSOFtOqUXz6ULj5i7B8WRnoEcZx64VhKliGP2I04vO0PswQMgBZa81V1o fHzEgj1XjCOQT9AEAfNFyBphNnezXQd11+OsFF2ryvRiGpMYZQowjkFovx1xCguM2Rw== 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.198 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (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 10B9F606A325 for ; Mon, 30 Nov 2026 21:45:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 10B9F606A325 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-f198.google.com with SMTP id af79cd13be357-93f32050e72so2368457085a.1 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=EH8G2r+SMsYwsndaAFTgWWkWQUGrNaS3q1hl105XCBP4ENsvvlYSP6+hqoOStp0Awc iSGdKpIKnj4DnvKOpz3UMCcWrBk3z644c2DtUa2Xq945U1sR32Tef1Vv4npTB8UGT+vM 5tLQW8TfY3S4Niz25n6G5kpvWqKlUL2xbX4sc6QwNDbt9Ei760WS+7wz0BlYaVIqccKL T4sWQMsH0a0I+xmsupvKMpwQu/zJSeIzQ9ThnB/Uji1gvepAbVZPN6Yfymq6XN12NMhz zyMGg2j9RL8RuT9FDCq99IgJ/iYD2Wo3Y1dCuFPAAH3tJxBS/6wZOm1I0TcQ+8xLELJk WRDQ== X-Gm-Message-State: APuU4Z/9bzZE4ndSZJjT5xhocg9CjhvVuGzV1NPTi6qcnBcZ8fMuVCPB s3pLRMm2ajfvP5YEwpta0AKbf9AHFaBbOSzWsjHwyh0e6vFmglEX/vEDnmy4AX0KdB0XUbpgvq2 3VykP8hLDj0kdkdSL+A== 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: 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=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