diff options
author | rwatson <rwatson@FreeBSD.org> | 2008-10-30 17:47:57 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2008-10-30 17:47:57 +0000 |
commit | c2d297d449b640aaad618243e9e61311598a1d4c (patch) | |
tree | ebc92ca7282d870b5322287d5c6c8fde2c3fba49 /sys/security | |
parent | 6094a6154c8f505530a7a0d0d49990faecc969b7 (diff) | |
download | FreeBSD-src-c2d297d449b640aaad618243e9e61311598a1d4c.zip FreeBSD-src-c2d297d449b640aaad618243e9e61311598a1d4c.tar.gz |
Protect the event->class lookup database using an rwlock instead of a
mutex, as it's rarely changed but frequently accessed read-only from
multiple threads, so a potentially significant source of contention.
MFC after: 1 month
Sponsored by: Apple, Inc.
Diffstat (limited to 'sys/security')
-rw-r--r-- | sys/security/audit/audit_bsm_klib.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/sys/security/audit/audit_bsm_klib.c b/sys/security/audit/audit_bsm_klib.c index 65f0ecb..94e5b29 100644 --- a/sys/security/audit/audit_bsm_klib.c +++ b/sys/security/audit/audit_bsm_klib.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2005 Apple Inc. + * Copyright (c) 1999-2008 Apple Inc. * Copyright (c) 2005 Robert N. M. Watson * All rights reserved. * @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include <sys/malloc.h> #include <sys/mount.h> #include <sys/proc.h> +#include <sys/rwlock.h> #include <sys/sem.h> #include <sys/sbuf.h> #include <sys/syscall.h> @@ -65,9 +66,15 @@ struct evclass_list { }; static MALLOC_DEFINE(M_AUDITEVCLASS, "audit_evclass", "Audit event class"); -static struct mtx evclass_mtx; +static struct rwlock evclass_lock; static struct evclass_list evclass_hash[EVCLASSMAP_HASH_TABLE_SIZE]; +#define EVCLASS_LOCK_INIT() rw_init(&evclass_lock, "evclass_lock") +#define EVCLASS_RLOCK() rw_rlock(&evclass_lock) +#define EVCLASS_RUNLOCK() rw_runlock(&evclass_lock) +#define EVCLASS_WLOCK() rw_wlock(&evclass_lock) +#define EVCLASS_WUNLOCK() rw_wunlock(&evclass_lock) + /* * Look up the class for an audit event in the class mapping table. */ @@ -78,7 +85,7 @@ au_event_class(au_event_t event) struct evclass_elem *evc; au_class_t class; - mtx_lock(&evclass_mtx); + EVCLASS_RLOCK(); evcl = &evclass_hash[event % EVCLASSMAP_HASH_TABLE_SIZE]; class = 0; LIST_FOREACH(evc, &evcl->head, entry) { @@ -88,7 +95,7 @@ au_event_class(au_event_t event) } } out: - mtx_unlock(&evclass_mtx); + EVCLASS_RUNLOCK(); return (class); } @@ -111,12 +118,12 @@ au_evclassmap_insert(au_event_t event, au_class_t class) */ evc_new = malloc(sizeof(*evc), M_AUDITEVCLASS, M_WAITOK); - mtx_lock(&evclass_mtx); + EVCLASS_WLOCK(); evcl = &evclass_hash[event % EVCLASSMAP_HASH_TABLE_SIZE]; LIST_FOREACH(evc, &evcl->head, entry) { if (evc->event == event) { evc->class = class; - mtx_unlock(&evclass_mtx); + EVCLASS_WUNLOCK(); free(evc_new, M_AUDITEVCLASS); return; } @@ -125,7 +132,7 @@ au_evclassmap_insert(au_event_t event, au_class_t class) evc->event = event; evc->class = class; LIST_INSERT_HEAD(&evcl->head, evc, entry); - mtx_unlock(&evclass_mtx); + EVCLASS_WUNLOCK(); } void @@ -133,7 +140,7 @@ au_evclassmap_init(void) { int i; - mtx_init(&evclass_mtx, "evclass_mtx", NULL, MTX_DEF); + EVCLASS_LOCK_INIT(); for (i = 0; i < EVCLASSMAP_HASH_TABLE_SIZE; i++) LIST_INIT(&evclass_hash[i].head); |