]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commit
selinux: reduce locking overhead in inode_free_security()
authorWaiman Long <Waiman.Long@hp.com>
Fri, 10 Jul 2015 21:19:56 +0000 (17:19 -0400)
committerPaul Moore <pmoore@redhat.com>
Mon, 13 Jul 2015 17:31:59 +0000 (13:31 -0400)
commit9629d04ae06812f217846b69728c969afee690b4
tree27a52f6f1744c528b10e3b923ee381264c08b540
parentfa1aa143ac4a682c7f5fd52a3cf05f5a6fe44a0a
selinux: reduce locking overhead in inode_free_security()

The inode_free_security() function just took the superblock's isec_lock
before checking and trying to remove the inode security struct from the
linked list. In many cases, the list was empty and so the lock taking
is wasteful as no useful work is done. On multi-socket systems with
a large number of CPUs, there can also be a fair amount of spinlock
contention on the isec_lock if many tasks are exiting at the same time.

This patch changes the code to check the state of the list first before
taking the lock and attempting to dequeue it. The list_del_init()
can be called more than once on the same list with no harm as long
as they are properly serialized. It should not be possible to have
inode_free_security() called concurrently with list_add(). For better
safety, however, we use list_empty_careful() here even though it is
still not completely safe in case that happens.

Signed-off-by: Waiman Long <Waiman.Long@hp.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: Paul Moore <pmoore@redhat.com>
security/selinux/hooks.c