Skip to content

Commit 641e021

Browse files
Hongru Zhangpcmoore
authored andcommitted
selinux: Introduce a new config to make avc cache slot size adjustable
On mobile device high-load situations, permission check can happen more than 90,000/s (8 core system). With default 512 cache nodes configuration, avc cache miss happens more often and occasionally leads to long time (>2ms) irqs off on both big and little cores, which decreases system real-time capability. An actual call stack is as follows: => avc_compute_av => avc_perm_nonode => avc_has_perm_noaudit => selinux_capable => security_capable => capable => __sched_setscheduler => do_sched_setscheduler => __arm64_sys_sched_setscheduler => invoke_syscall => el0_svc_common => do_el0_svc => el0_svc => el0t_64_sync_handler => el0t_64_sync Although we can expand avc nodes through /sys/fs/selinux/cache_threshold to mitigate long time irqs off, hash conflicts make the bucket average length longer because of the fixed size of cache slots, leading to avc_search_node() latency increase. So introduce a new config to make avc cache slot size also configurable, and with fine tuning, we can mitigate long time irqs off with slightly avc_search_node() performance regression. Theoretically, the main overhead is memory consumption. Signed-off-by: Hongru Zhang <zhanghongru@xiaomi.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 094e94d commit 641e021

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

security/selinux/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ config SECURITY_SELINUX_SID2STR_CACHE_SIZE
6969

7070
If unsure, keep the default value.
7171

72+
config SECURITY_SELINUX_AVC_HASH_BITS
73+
int "SELinux avc hashtable size"
74+
depends on SECURITY_SELINUX
75+
range 9 14
76+
default 9
77+
help
78+
This option sets the number of buckets used in the AVC hash table
79+
to 2^SECURITY_SELINUX_AVC_HASH_BITS. A higher value helps maintain
80+
shorter chain lengths especially when expanding AVC nodes via
81+
/sys/fs/selinux/avc/cache_threshold.
82+
7283
config SECURITY_SELINUX_DEBUG
7384
bool "SELinux kernel debugging support"
7485
depends on SECURITY_SELINUX

security/selinux/avc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
#define CREATE_TRACE_POINTS
3535
#include <trace/events/avc.h>
3636

37-
#define AVC_CACHE_SLOTS 512
38-
#define AVC_DEF_CACHE_THRESHOLD 512
39-
#define AVC_CACHE_RECLAIM 16
37+
#define AVC_CACHE_SLOTS (1 << CONFIG_SECURITY_SELINUX_AVC_HASH_BITS)
38+
#define AVC_DEF_CACHE_THRESHOLD AVC_CACHE_SLOTS
39+
#define AVC_CACHE_RECLAIM 16
4040

4141
#ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
4242
#define avc_cache_stats_incr(field) this_cpu_inc(avc_cache_stats.field)

0 commit comments

Comments
 (0)