tools/testing/selftests/bpf/progs/cgroup_read_xattr.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/cgroup_read_xattr.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/cgroup_read_xattr.c- Extension
.c- Size
- 3133 bytes
- Lines
- 159
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
vmlinux.hbpf/bpf_tracing.hbpf/bpf_helpers.hbpf/bpf_core_read.hbpf_experimental.hbpf_misc.h
Detected Declarations
function read_xattrfunction BPF_PROGfunction BPF_PROGfunction BPF_PROGfunction __msgfunction BPF_PROGfunction BPF_PROGfunction BPF_PROG
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */
#include <vmlinux.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_core_read.h>
#include "bpf_experimental.h"
#include "bpf_misc.h"
char _license[] SEC("license") = "GPL";
char value[16];
static __always_inline void read_xattr(struct cgroup *cgroup)
{
struct bpf_dynptr value_ptr;
bpf_dynptr_from_mem(value, sizeof(value), 0, &value_ptr);
bpf_cgroup_read_xattr(cgroup, "user.bpf_test",
&value_ptr);
}
SEC("lsm.s/socket_connect")
__success
int BPF_PROG(trusted_cgroup_ptr_sleepable)
{
u64 cgrp_id = bpf_get_current_cgroup_id();
struct cgroup *cgrp;
cgrp = bpf_cgroup_from_id(cgrp_id);
if (!cgrp)
return 0;
read_xattr(cgrp);
bpf_cgroup_release(cgrp);
return 0;
}
SEC("lsm/socket_connect")
__success
int BPF_PROG(trusted_cgroup_ptr_non_sleepable)
{
u64 cgrp_id = bpf_get_current_cgroup_id();
struct cgroup *cgrp;
cgrp = bpf_cgroup_from_id(cgrp_id);
if (!cgrp)
return 0;
read_xattr(cgrp);
bpf_cgroup_release(cgrp);
return 0;
}
SEC("lsm/socket_connect")
__success
int BPF_PROG(use_css_iter_non_sleepable)
{
u64 cgrp_id = bpf_get_current_cgroup_id();
struct cgroup_subsys_state *css;
struct cgroup *cgrp;
cgrp = bpf_cgroup_from_id(cgrp_id);
if (!cgrp)
return 0;
bpf_for_each(css, css, &cgrp->self, BPF_CGROUP_ITER_ANCESTORS_UP)
read_xattr(css->cgroup);
bpf_cgroup_release(cgrp);
return 0;
}
SEC("lsm.s/socket_connect")
__failure __msg("kernel func bpf_iter_css_new requires RCU critical section protection")
int BPF_PROG(use_css_iter_sleepable_missing_rcu_lock)
{
u64 cgrp_id = bpf_get_current_cgroup_id();
struct cgroup_subsys_state *css;
struct cgroup *cgrp;
cgrp = bpf_cgroup_from_id(cgrp_id);
if (!cgrp)
return 0;
bpf_for_each(css, css, &cgrp->self, BPF_CGROUP_ITER_ANCESTORS_UP)
read_xattr(css->cgroup);
bpf_cgroup_release(cgrp);
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_tracing.h`, `bpf/bpf_helpers.h`, `bpf/bpf_core_read.h`, `bpf_experimental.h`, `bpf_misc.h`.
- Detected declarations: `function read_xattr`, `function BPF_PROG`, `function BPF_PROG`, `function BPF_PROG`, `function __msg`, `function BPF_PROG`, `function BPF_PROG`, `function BPF_PROG`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.