mm/memcg: Exclude mem_cgroup pointer from kABI signature computation

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2036995
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/326
Upstream Status: RHEL only

The mem_cgroup structure is 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. However, a number of other important data structures
like the task_struct contain pointers to mem_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 pointers in the task_struct, bpf_map,
fsnotify_group and sock data structures.

Signed-off-by: Waiman Long <longman@redhat.com>
This commit is contained in:
Waiman Long 2022-01-06 11:07:54 -05:00
parent d27f92307d
commit 1f50357d24
6 changed files with 33 additions and 5 deletions

View File

@ -174,7 +174,7 @@ struct bpf_map {
u32 btf_value_type_id;
struct btf *btf;
#ifdef CONFIG_MEMCG_KMEM
struct mem_cgroup *memcg;
RH_KABI_EXCLUDE(struct mem_cgroup *memcg)
#endif
char name[BPF_OBJ_NAME_LEN];
u32 btf_vmlinux_value_type_id;

View File

@ -216,7 +216,7 @@ struct fsnotify_group {
* notification list is too
* full */
struct mem_cgroup *memcg; /* memcg to charge allocations */
RH_KABI_EXCLUDE(struct mem_cgroup *memcg) /* memcg to charge allocations */
/* groups can define private fields here or use the void *private */
union {

View File

@ -233,6 +233,30 @@ struct obj_cgroup {
* page cache and RSS per cgroup. We would eventually like to provide
* statistics based on the statistics developed by Rik Van Riel for clock-pro,
* to help the administrator determine what knobs to tune.
*
* RHEL9 Notes
* -----------
* The mem_cgroup structure is allocated dynamically and is not embedded in
* other data structures. To support new features, mem_cgroup structure can
* change quite a lot over time. Therefore, the kABI signature of mem_cgroup
* will change over time. The mem_cgroup structure is excluded from the kABI
* signature generation to avoid impacting kABI signature of other structures
* that include a pointer to mem_cgroup. Third-party kernel modules should not
* access mem_cgroup or mem_cgroup_per_node directly or use inlined functions
* that access them directly.
*
* In addition, the following enum types will have new upstream fields added
* in a way that may break kABI if they are used or referenced by 3rd party
* kernel drivers.
* - memcg_memory_event: affect MEMCG_NR_MEMORY_EVENTS
* - node_stat_item: NR_VM_NODE_STAT_ITEMS does get used in lruvec_stat[] of
* mem_cgroup_per_node (memcontrol.h) and lumped into MEMCG_NR_STAT.
* The change in MEMCG_NR_STAT does increase the size of stat[] of
* memcg_vmstats_percpu and vmstats[] of mem_cgroup structures.
* These arrays are not at the end of the structure and so changing
* the array size will break offsets of existing fields that
* follows the arrays.
* - vm_event_item: NR_VM_EVENT_ITEMS used in vmevents[] of memcg.
*/
struct mem_cgroup {
struct cgroup_subsys_state css;

View File

@ -19,6 +19,8 @@
#include <asm/mmu.h>
#include <linux/rh_kabi.h>
#ifndef AT_VECTOR_SIZE_ARCH
#define AT_VECTOR_SIZE_ARCH 0
#endif

View File

@ -36,6 +36,8 @@
#include <linux/kcsan.h>
#include <asm/kmap_size.h>
#include <linux/rh_kabi.h>
/* task_struct member predeclarations (sorted alphabetically): */
struct audit_context;
struct backing_dev_info;
@ -1403,7 +1405,7 @@ struct task_struct {
#endif
#ifdef CONFIG_MEMCG
struct mem_cgroup *memcg_in_oom;
RH_KABI_EXCLUDE(struct mem_cgroup *memcg_in_oom)
gfp_t memcg_oom_gfp_mask;
int memcg_oom_order;
@ -1411,7 +1413,7 @@ struct task_struct {
unsigned int memcg_nr_pages_over_high;
/* Used by memcontrol for targeted memcg charge: */
struct mem_cgroup *active_memcg;
RH_KABI_EXCLUDE(struct mem_cgroup *active_memcg)
#endif
#ifdef CONFIG_BLK_CGROUP

View File

@ -511,7 +511,7 @@ struct sock {
void *sk_security;
#endif
struct sock_cgroup_data sk_cgrp_data;
struct mem_cgroup *sk_memcg;
RH_KABI_EXCLUDE(struct mem_cgroup *sk_memcg)
void (*sk_state_change)(struct sock *sk);
void (*sk_data_ready)(struct sock *sk);
void (*sk_write_space)(struct sock *sk);