Skip to content

Commit 257313b

Browse files
committed
selinux: avoid unnecessary avc cache stat hit count
There is no point in counting hits - we can calculate it from the number of lookups and misses. This makes the avc statistics a bit smaller, and makes the code generation better too. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 044aea9 commit 257313b

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

security/selinux/avc.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,10 @@ static struct avc_node *avc_lookup(u32 ssid, u32 tsid, u16 tclass)
343343
node = avc_search_node(ssid, tsid, tclass);
344344

345345
if (node)
346-
avc_cache_stats_incr(hits);
347-
else
348-
avc_cache_stats_incr(misses);
346+
return node;
349347

350-
return node;
348+
avc_cache_stats_incr(misses);
349+
return NULL;
351350
}
352351

353352
static int avc_latest_notif_update(int seqno, int is_insert)
@@ -765,7 +764,7 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
765764
rcu_read_lock();
766765

767766
node = avc_lookup(ssid, tsid, tclass);
768-
if (!node) {
767+
if (unlikely(!node)) {
769768
rcu_read_unlock();
770769

771770
if (in_avd)

security/selinux/include/avc.h

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ struct sk_buff;
4141
*/
4242
struct avc_cache_stats {
4343
unsigned int lookups;
44-
unsigned int hits;
4544
unsigned int misses;
4645
unsigned int allocations;
4746
unsigned int reclaims;

security/selinux/selinuxfs.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -1380,10 +1380,14 @@ static int sel_avc_stats_seq_show(struct seq_file *seq, void *v)
13801380
if (v == SEQ_START_TOKEN)
13811381
seq_printf(seq, "lookups hits misses allocations reclaims "
13821382
"frees\n");
1383-
else
1384-
seq_printf(seq, "%u %u %u %u %u %u\n", st->lookups,
1385-
st->hits, st->misses, st->allocations,
1383+
else {
1384+
unsigned int lookups = st->lookups;
1385+
unsigned int misses = st->misses;
1386+
unsigned int hits = lookups - misses;
1387+
seq_printf(seq, "%u %u %u %u %u %u\n", lookups,
1388+
hits, misses, st->allocations,
13861389
st->reclaims, st->frees);
1390+
}
13871391
return 0;
13881392
}
13891393

0 commit comments

Comments
 (0)