Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1c3fad93 authored by Paul Moore's avatar Paul Moore Committed by James Morris
Browse files

NetLabel: Consolidate the LSM domain mapping/hashing locks



Currently we use two separate spinlocks to protect both the hash/mapping table
and the default entry.  This could be considered a bit foolish because it adds
complexity without offering any real performance advantage.  This patch
removes the dedicated default spinlock and protects the default entry with the
hash/mapping table spinlock.

Signed-off-by: default avatarPaul Moore <paul.moore@hp.com>
Signed-off-by: default avatarJames Morris <jmorris@namei.org>
parent b64397e0
Loading
Loading
Loading
Loading
+9 −21
Original line number Original line Diff line number Diff line
@@ -54,9 +54,6 @@ struct netlbl_domhsh_tbl {
 * hash table should be okay */
 * hash table should be okay */
static DEFINE_SPINLOCK(netlbl_domhsh_lock);
static DEFINE_SPINLOCK(netlbl_domhsh_lock);
static struct netlbl_domhsh_tbl *netlbl_domhsh = NULL;
static struct netlbl_domhsh_tbl *netlbl_domhsh = NULL;

/* Default domain mapping */
static DEFINE_SPINLOCK(netlbl_domhsh_def_lock);
static struct netlbl_dom_map *netlbl_domhsh_def = NULL;
static struct netlbl_dom_map *netlbl_domhsh_def = NULL;


/*
/*
@@ -239,24 +236,22 @@ int netlbl_domhsh_add(struct netlbl_dom_map *entry,
	INIT_RCU_HEAD(&entry->rcu);
	INIT_RCU_HEAD(&entry->rcu);


	rcu_read_lock();
	rcu_read_lock();
	spin_lock(&netlbl_domhsh_lock);
	if (entry->domain != NULL) {
	if (entry->domain != NULL) {
		bkt = netlbl_domhsh_hash(entry->domain);
		bkt = netlbl_domhsh_hash(entry->domain);
		spin_lock(&netlbl_domhsh_lock);
		if (netlbl_domhsh_search(entry->domain) == NULL)
		if (netlbl_domhsh_search(entry->domain) == NULL)
			list_add_tail_rcu(&entry->list,
			list_add_tail_rcu(&entry->list,
				    &rcu_dereference(netlbl_domhsh)->tbl[bkt]);
				    &rcu_dereference(netlbl_domhsh)->tbl[bkt]);
		else
		else
			ret_val = -EEXIST;
			ret_val = -EEXIST;
		spin_unlock(&netlbl_domhsh_lock);
	} else {
	} else {
		INIT_LIST_HEAD(&entry->list);
		INIT_LIST_HEAD(&entry->list);
		spin_lock(&netlbl_domhsh_def_lock);
		if (rcu_dereference(netlbl_domhsh_def) == NULL)
		if (rcu_dereference(netlbl_domhsh_def) == NULL)
			rcu_assign_pointer(netlbl_domhsh_def, entry);
			rcu_assign_pointer(netlbl_domhsh_def, entry);
		else
		else
			ret_val = -EEXIST;
			ret_val = -EEXIST;
		spin_unlock(&netlbl_domhsh_def_lock);
	}
	}
	spin_unlock(&netlbl_domhsh_lock);
	audit_buf = netlbl_audit_start_common(AUDIT_MAC_MAP_ADD, audit_info);
	audit_buf = netlbl_audit_start_common(AUDIT_MAC_MAP_ADD, audit_info);
	if (audit_buf != NULL) {
	if (audit_buf != NULL) {
		audit_log_format(audit_buf,
		audit_log_format(audit_buf,
@@ -337,23 +332,16 @@ int netlbl_domhsh_remove(const char *domain, struct netlbl_audit *audit_info)
					   entry->domain);
					   entry->domain);
		break;
		break;
	}
	}
	if (entry != rcu_dereference(netlbl_domhsh_def)) {
	spin_lock(&netlbl_domhsh_lock);
	spin_lock(&netlbl_domhsh_lock);
	if (entry->valid) {
	if (entry->valid) {
		entry->valid = 0;
		entry->valid = 0;
		if (entry != rcu_dereference(netlbl_domhsh_def))
			list_del_rcu(&entry->list);
			list_del_rcu(&entry->list);
			ret_val = 0;
		else
		}
		spin_unlock(&netlbl_domhsh_lock);
	} else {
		spin_lock(&netlbl_domhsh_def_lock);
		if (entry->valid) {
			entry->valid = 0;
			rcu_assign_pointer(netlbl_domhsh_def, NULL);
			rcu_assign_pointer(netlbl_domhsh_def, NULL);
		ret_val = 0;
		ret_val = 0;
	}
	}
		spin_unlock(&netlbl_domhsh_def_lock);
	spin_unlock(&netlbl_domhsh_lock);
	}


	audit_buf = netlbl_audit_start_common(AUDIT_MAC_MAP_DEL, audit_info);
	audit_buf = netlbl_audit_start_common(AUDIT_MAC_MAP_DEL, audit_info);
	if (audit_buf != NULL) {
	if (audit_buf != NULL) {