mirror of
https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-10.git
synced 2026-09-09 12:04:49 +08:00
JIRA: https://issues.redhat.com/browse/RHEL-80552 Upstream Status: RHEL only The mem_cgroup and obj_cgroup structure are allocated dynamically, self-contained and is not embedded in other data structures. Third-party kernel modules are not supposed to access mem_cgroup structure directly. To support new features, mem_cgroup structure often changes quite a lot over time. The obj_cgroup structure is more stable, but it has a pointer to the mem_cgroup structure. A number of other important data structures like the task_struct contain pointers to mem_cgroup and/or obj_cgroup. So any change to mem_cgroup can affect the kABI signatures of the other data structures leading to kABI breakage. Instead of carefully messaging the mem_cgroup structure every time when change is needed in order not to break kABI signature, it is more efficient to just decouple changes to mem_cgroup from affecting kABI signatures of other data structures by using the RH_KABI_EXCLUDE() macro to exclude mem_cgroup pointers from being included in the computation of kABI signature. This macro is applied to mem_cgroup/obj_cgroup pointers in the task_struct, mm_struct, shrink_control, fsnotify_group, bpf_map, bpf_mem_alloc and sock data structures. Signed-off-by: Waiman Long <longman@redhat.com> Signed-off-by: Nico Pache <npache@redhat.com>
52 lines
2.1 KiB
C
52 lines
2.1 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */
|
|
#ifndef _BPF_MEM_ALLOC_H
|
|
#define _BPF_MEM_ALLOC_H
|
|
#include <linux/compiler_types.h>
|
|
#include <linux/workqueue.h>
|
|
|
|
struct bpf_mem_cache;
|
|
struct bpf_mem_caches;
|
|
|
|
struct bpf_mem_alloc {
|
|
struct bpf_mem_caches __percpu *caches;
|
|
struct bpf_mem_cache __percpu *cache;
|
|
RH_KABI_EXCLUDE(struct obj_cgroup *objcg)
|
|
bool percpu;
|
|
struct work_struct work;
|
|
};
|
|
|
|
/* 'size != 0' is for bpf_mem_alloc which manages fixed-size objects.
|
|
* Alloc and free are done with bpf_mem_cache_{alloc,free}().
|
|
*
|
|
* 'size = 0' is for bpf_mem_alloc which manages many fixed-size objects.
|
|
* Alloc and free are done with bpf_mem_{alloc,free}() and the size of
|
|
* the returned object is given by the size argument of bpf_mem_alloc().
|
|
* If percpu equals true, error will be returned in order to avoid
|
|
* large memory consumption and the below bpf_mem_alloc_percpu_unit_init()
|
|
* should be used to do on-demand per-cpu allocation for each size.
|
|
*/
|
|
int bpf_mem_alloc_init(struct bpf_mem_alloc *ma, int size, bool percpu);
|
|
/* Initialize a non-fix-size percpu memory allocator */
|
|
int bpf_mem_alloc_percpu_init(struct bpf_mem_alloc *ma, struct obj_cgroup *objcg);
|
|
/* The percpu allocation with a specific unit size. */
|
|
int bpf_mem_alloc_percpu_unit_init(struct bpf_mem_alloc *ma, int size);
|
|
void bpf_mem_alloc_destroy(struct bpf_mem_alloc *ma);
|
|
|
|
/* Check the allocation size for kmalloc equivalent allocator */
|
|
int bpf_mem_alloc_check_size(bool percpu, size_t size);
|
|
|
|
/* kmalloc/kfree equivalent: */
|
|
void *bpf_mem_alloc(struct bpf_mem_alloc *ma, size_t size);
|
|
void bpf_mem_free(struct bpf_mem_alloc *ma, void *ptr);
|
|
void bpf_mem_free_rcu(struct bpf_mem_alloc *ma, void *ptr);
|
|
|
|
/* kmem_cache_alloc/free equivalent: */
|
|
void *bpf_mem_cache_alloc(struct bpf_mem_alloc *ma);
|
|
void bpf_mem_cache_free(struct bpf_mem_alloc *ma, void *ptr);
|
|
void bpf_mem_cache_free_rcu(struct bpf_mem_alloc *ma, void *ptr);
|
|
void bpf_mem_cache_raw_free(void *ptr);
|
|
void *bpf_mem_cache_alloc_flags(struct bpf_mem_alloc *ma, gfp_t flags);
|
|
|
|
#endif /* _BPF_MEM_ALLOC_H */
|