Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/xen/xen Use spin mutices correctly.



details:   https://anonhg.NetBSD.org/src/rev/e8826bd7ba00
branches:  trunk
changeset: 768274:e8826bd7ba00
user:      cherry <cherry%NetBSD.org@localhost>
date:      Sat Aug 13 17:23:42 2011 +0000

description:
Use spin mutices correctly.
 - Prune redundant splxx()/splx() pairs.
 - Do not "leak" a mutex_spin_enter() via conditional return.

Thanks rmind@

diffstat:

 sys/arch/xen/xen/evtchn.c |  23 ++++++-----------------
 1 files changed, 6 insertions(+), 17 deletions(-)

diffs (135 lines):

diff -r 8132780fe247 -r e8826bd7ba00 sys/arch/xen/xen/evtchn.c
--- a/sys/arch/xen/xen/evtchn.c Sat Aug 13 16:22:15 2011 +0000
+++ b/sys/arch/xen/xen/evtchn.c Sat Aug 13 17:23:42 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: evtchn.c,v 1.50 2011/08/11 17:59:00 cherry Exp $       */
+/*     $NetBSD: evtchn.c,v 1.51 2011/08/13 17:23:42 cherry Exp $       */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.50 2011/08/11 17:59:00 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.51 2011/08/13 17:23:42 cherry Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -336,9 +336,7 @@
 {
        evtchn_op_t op;
        evtchn_port_t evtchn;
-       int s;
 
-       s = splhigh();
        mutex_spin_enter(&evtchn_lock);
 
        evtchn = vcpu_ipi_to_evtch[vcpu];
@@ -355,7 +353,6 @@
        evtch_bindcount[evtchn]++;
 
        mutex_spin_exit(&evtchn_lock);
-       splx(s);
     
        return evtchn;
 }
@@ -364,9 +361,8 @@
 bind_virq_to_evtch(int virq)
 {
        evtchn_op_t op;
-       int evtchn, s;
+       int evtchn;
 
-       s = splhigh();
        mutex_spin_enter(&evtchn_lock);
 
        /* 
@@ -379,6 +375,7 @@
        struct cpu_info *ci = curcpu();
 
        if (virq == VIRQ_DEBUG && ci != &cpu_info_primary) {
+               mutex_spin_exit(&evtchn_lock);
                return -1;
        }
 
@@ -402,7 +399,6 @@
        evtch_bindcount[evtchn]++;
 
        mutex_spin_exit(&evtchn_lock);
-       splx(s);
     
        return evtchn;
 }
@@ -412,7 +408,6 @@
 {
        evtchn_op_t op;
        int evtchn;
-       int s;
 
        struct cpu_info *ci = curcpu();
 
@@ -427,7 +422,6 @@
                return -1;
        }
 
-       s = splhigh();
        mutex_spin_enter(&evtchn_lock);
 
        evtch_bindcount[evtchn]--;
@@ -441,7 +435,6 @@
        }
 
        mutex_spin_exit(&evtchn_lock);
-       splx(s);
 
        return evtchn;
 }
@@ -451,13 +444,12 @@
 bind_pirq_to_evtch(int pirq)
 {
        evtchn_op_t op;
-       int evtchn, s;
+       int evtchn;
 
        if (pirq >= NR_PIRQS) {
                panic("pirq %d out of bound, increase NR_PIRQS", pirq);
        }
 
-       s = splhigh();
        mutex_spin_enter(&evtchn_lock);
 
        evtchn = pirq_to_evtch[pirq];
@@ -478,7 +470,6 @@
        evtch_bindcount[evtchn]++;
 
        mutex_spin_exit(&evtchn_lock);
-       splx(s);
     
        return evtchn;
 }
@@ -488,7 +479,6 @@
 {
        evtchn_op_t op;
        int evtchn = pirq_to_evtch[pirq];
-       int s = splhigh();
 
        mutex_spin_enter(&evtchn_lock);
 
@@ -503,7 +493,6 @@
        }
 
        mutex_spin_exit(&evtchn_lock);
-       splx(s);
 
        return evtchn;
 }
@@ -650,7 +639,7 @@
                 * is more explicitly implemented.
                 */
                evts->ev_cpu = ci; 
-               mutex_init(&evtlock[evtch], MUTEX_DEFAULT, IPL_VM);
+               mutex_init(&evtlock[evtch], MUTEX_DEFAULT, IPL_HIGH);
                evtsource[evtch] = evts;
                if (evname)
                        strncpy(evts->ev_evname, evname,



Home | Main Index | Thread Index | Old Index