From 3e9d5f02f0e124633edb3a638fe614466c8d0a51 Mon Sep 17 00:00:00 2001 From: Qingqing Zhou Date: Tue, 30 Nov 2021 10:20:40 +0800 Subject: [PATCH] ANDROID: Configure out the macros in android_kabi and android_vendor Add one CONFIG to control removing the macros or not. On some platform, configureing out the macros removes the associated members from the structs, this reduces the object size of the slabs related with the structs, therefore reduces the total slab memory consumption of system. Besides, this also reduces vmlinux size a bit, therefore the total kernel memory size increses a bit. The macros are ANDROID_KABI_RESERVE, ANDROID_VENDOR_DATA, ANDROID_VENDOR_DATA_ARRAY, ANDROID_OEM_DATA, ANDROID_OEM_DATA_ARRAY. Bug: 206561931 Signed-off-by: Qingqing Zhou Change-Id: Iea4b962dff386a17c9bef20ae048be4e17bf43ab (cherry picked from commit b7a6c15a6f06cc7e324c8d63b87cdd06b5597851) Signed-off-by: Jaskaran Singh (cherry picked from commit 3c06a5ce5e5857a1dff88a784e58e32bbddaf759) --- drivers/android/Kconfig | 35 ++++++++++++++++++++++++++++++++++ include/linux/android_kabi.h | 4 ++++ include/linux/android_vendor.h | 15 +++++++++++++++ init/init_task.c | 2 ++ kernel/fork.c | 4 ++-- 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/drivers/android/Kconfig b/drivers/android/Kconfig index 884630851831..c5e063b723dd 100644 --- a/drivers/android/Kconfig +++ b/drivers/android/Kconfig @@ -67,4 +67,39 @@ config ANDROID_DEBUG_KINFO - UTS_RELEASE - BUILD_INFO(ro.build.fingerprint) +config ANDROID_KABI_RESERVE + bool "Android KABI reserve padding" + default y + help + This option enables the padding that the Android GKI kernel adds + to many different kernel structures to support an in-kernel stable ABI + over the lifespan of support for the kernel. + + Only disable this option if you have a system that needs the Android + kernel drivers, but is NOT an Android GKI kernel image. If disabled + it has the possibility to make the kernel static and runtime image + slightly smaller but will NOT be supported by the Google Android + kernel team. + + If even slightly unsure, say Y. + +config ANDROID_VENDOR_OEM_DATA + bool "Android vendor and OEM data padding" + default y + help + This option enables the padding that the Android GKI kernel adds + to many different kernel structures to support an in-kernel stable ABI + over the lifespan of support for the kernel as well as OEM additional + fields that are needed by some of the Android kernel tracepoints. The + macros enabled by this option are used to enable padding in vendor modules + used for the above specified purposes. + + Only disable this option if you have a system that needs the Android + kernel drivers, but is NOT an Android GKI kernel image and you do NOT + use the Android kernel tracepoints. If disabled it has the possibility + to make the kernel static and runtime image slightly smaller but will + NOT be supported by the Google Android kernel team. + + If even slightly unsure, say Y. + endmenu diff --git a/include/linux/android_kabi.h b/include/linux/android_kabi.h index 9c7b6c035ad3..f6dd7f00b386 100644 --- a/include/linux/android_kabi.h +++ b/include/linux/android_kabi.h @@ -83,7 +83,11 @@ * number: the "number" of the padding variable in the structure. Start with * 1 and go up. */ +#ifdef CONFIG_ANDROID_KABI_RESERVE #define ANDROID_KABI_RESERVE(number) _ANDROID_KABI_RESERVE(number) +#else +#define ANDROID_KABI_RESERVE(number) +#endif /* diff --git a/include/linux/android_vendor.h b/include/linux/android_vendor.h index 59fc5734bca2..af3014ccc82e 100644 --- a/include/linux/android_vendor.h +++ b/include/linux/android_vendor.h @@ -26,10 +26,25 @@ * Same as ANDROID_VENDOR_DATA but allocates an array of u64 with * the specified size */ +#ifdef CONFIG_ANDROID_VENDOR_OEM_DATA #define ANDROID_VENDOR_DATA(n) u64 android_vendor_data##n #define ANDROID_VENDOR_DATA_ARRAY(n, s) u64 android_vendor_data##n[s] #define ANDROID_OEM_DATA(n) u64 android_oem_data##n #define ANDROID_OEM_DATA_ARRAY(n, s) u64 android_oem_data##n[s] +#define android_init_vendor_data(p, n) \ + memset(&p->android_vendor_data##n, 0, sizeof(p->android_vendor_data##n)) +#define android_init_oem_data(p, n) \ + memset(&p->android_oem_data##n, 0, sizeof(p->android_oem_data##n)) +#else +#define ANDROID_VENDOR_DATA(n) +#define ANDROID_VENDOR_DATA_ARRAY(n, s) +#define ANDROID_OEM_DATA(n) +#define ANDROID_OEM_DATA_ARRAY(n, s) + +#define android_init_vendor_data(p, n) +#define android_init_oem_data(p, n) +#endif + #endif /* _ANDROID_VENDOR_H */ diff --git a/init/init_task.c b/init/init_task.c index 96471bd699aa..31ceb0e469f7 100644 --- a/init/init_task.c +++ b/init/init_task.c @@ -210,8 +210,10 @@ struct task_struct init_task #ifdef CONFIG_SECCOMP_FILTER .seccomp = { .filter_count = ATOMIC_INIT(0) }, #endif +#ifdef CONFIG_ANDROID_VENDOR_OEM_DATA .android_vendor_data1 = {0, }, .android_oem_data1 = {0, }, +#endif }; EXPORT_SYMBOL(init_task); diff --git a/kernel/fork.c b/kernel/fork.c index a336dddc029b..898ea2d04184 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1057,8 +1057,8 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node) tsk->reported_split_lock = 0; #endif - memset(&tsk->android_vendor_data1, 0, sizeof(tsk->android_vendor_data1)); - memset(&tsk->android_oem_data1, 0, sizeof(tsk->android_oem_data1)); + android_init_vendor_data(tsk, 1); + android_init_oem_data(tsk, 1); return tsk;