[patch-2.3.99-pre7-6] exec_domains_lock refined

From: Tigran Aivazian (tigran@veritas.com)
Date: Mon May 08 2000 - 12:39:40 EST


Hi Linus,

This patch refines exec_domains_lock to the status of read/write lock
instead of plain spinlock.

Rationale: the same as for file_systems_lock

More rationale: the case of exec_domains_lock, just like file_systems_lock
benefits substantially from being rw. Why? Because it is possible to
simulate from userspace lots of traversals of the list that should not be
mutually exclussive, e.g. personality(2) system call and reading from
/proc/execdomains. This is not the case with, for example, nls_lock where
plain spinlock suffices just fine, imho. (although I tried to improve that
one too recently)

Please consider this patch, tested of course.

Regards,
Tigran

--- linux/kernel/exec_domain.c Thu Apr 27 09:01:31 2000
+++ work/kernel/exec_domain.c Mon May 8 18:16:30 2000
@@ -23,7 +23,7 @@
 };
 
 static struct exec_domain *exec_domains = &default_exec_domain;
-static spinlock_t exec_domains_lock = SPIN_LOCK_UNLOCKED;
+static rwlock_t exec_domains_lock = RW_LOCK_UNLOCKED;
 
 static asmlinkage void no_lcall7(int segment, struct pt_regs * regs)
 {
@@ -48,15 +48,15 @@
         unsigned long pers = personality & PER_MASK;
         struct exec_domain *it;
 
- spin_lock(&exec_domains_lock);
+ read_lock(&exec_domains_lock);
         for (it=exec_domains; it; it=it->next)
                 if (pers >= it->pers_low && pers <= it->pers_high) {
                         if (!try_inc_mod_count(it->module))
                                 continue;
- spin_unlock(&exec_domains_lock);
+ read_unlock(&exec_domains_lock);
                         return it;
                 }
- spin_unlock(&exec_domains_lock);
+ read_unlock(&exec_domains_lock);
 
         /* Should never get this far. */
         printk(KERN_ERR "No execution domain for personality 0x%02lx\n", pers);
@@ -71,15 +71,15 @@
                 return -EINVAL;
         if (it->next)
                 return -EBUSY;
- spin_lock(&exec_domains_lock);
+ write_lock(&exec_domains_lock);
         for (tmp=exec_domains; tmp; tmp=tmp->next)
                 if (tmp == it) {
- spin_unlock(&exec_domains_lock);
+ write_unlock(&exec_domains_lock);
                         return -EBUSY;
                 }
         it->next = exec_domains;
         exec_domains = it;
- spin_unlock(&exec_domains_lock);
+ write_unlock(&exec_domains_lock);
         return 0;
 }
 
@@ -88,17 +88,17 @@
         struct exec_domain ** tmp;
 
         tmp = &exec_domains;
- spin_lock(&exec_domains_lock);
+ write_lock(&exec_domains_lock);
         while (*tmp) {
                 if (it == *tmp) {
                         *tmp = it->next;
                         it->next = NULL;
- spin_unlock(&exec_domains_lock);
+ write_unlock(&exec_domains_lock);
                         return 0;
                 }
                 tmp = &(*tmp)->next;
         }
- spin_unlock(&exec_domains_lock);
+ write_unlock(&exec_domains_lock);
         return -EINVAL;
 }
 
@@ -141,11 +141,11 @@
         int len = 0;
         struct exec_domain * e;
 
- spin_lock(&exec_domains_lock);
+ read_lock(&exec_domains_lock);
         for (e=exec_domains; e && len < PAGE_SIZE - 80; e=e->next)
                 len += sprintf(page+len, "%d-%d\t%-16s\t[%s]\n",
                         e->pers_low, e->pers_high, e->name,
                         e->module ? e->module->name : "kernel");
- spin_unlock(&exec_domains_lock);
+ read_unlock(&exec_domains_lock);
         return len;
 }

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon May 15 2000 - 21:00:11 EST