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 mutex(9) instead of spl(9). Add further...



details:   https://anonhg.NetBSD.org/src/rev/db3025956048
branches:  trunk
changeset: 771921:db3025956048
user:      cherry <cherry%NetBSD.org@localhost>
date:      Fri Dec 09 03:58:12 2011 +0000

description:
Use mutex(9) instead of spl(9). Add further locks around grant table access.

diffstat:

 sys/arch/xen/xen/xengnt.c |  22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)

diffs (116 lines):

diff -r 7cc13c113dcc -r db3025956048 sys/arch/xen/xen/xengnt.c
--- a/sys/arch/xen/xen/xengnt.c Thu Dec 08 23:36:57 2011 +0000
+++ b/sys/arch/xen/xen/xengnt.c Fri Dec 09 03:58:12 2011 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: xengnt.c,v 1.20 2011/09/20 00:12:24 jym Exp $      */
+/*      $NetBSD: xengnt.c,v 1.21 2011/12/09 03:58:12 cherry Exp $      */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.20 2011/09/20 00:12:24 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.21 2011/12/09 03:58:12 cherry Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -35,6 +35,7 @@
 #include <sys/queue.h>
 #include <sys/extent.h>
 #include <sys/kernel.h>
+#include <sys/mutex.h>
 #include <uvm/uvm.h>
 
 #include <xen/hypervisor.h>
@@ -64,6 +65,7 @@
 
 /* VM address of the grant table */
 grant_entry_t *grant_table;
+kmutex_t grant_lock;
 
 static grant_ref_t xengnt_get_entry(void);
 static void xengnt_free_entry(grant_ref_t);
@@ -99,6 +101,8 @@
        for (i = 0; i <= nr_grant_entries; i++)
                gnt_entries[i] = XENGNT_NO_ENTRY;
 
+       mutex_init(&grant_lock, MUTEX_DEFAULT, IPL_VM);
+
        xengnt_resume();
 
 }
@@ -217,13 +221,13 @@
 xengnt_get_entry(void)
 {
        grant_ref_t entry;
-       int s = splvm();
+       mutex_enter(&grant_lock);
        static struct timeval xengnt_nonmemtime;
        static const struct timeval xengnt_nonmemintvl = {5,0};
 
        if (last_gnt_entry == 0) {
                if (xengnt_more_entries()) {
-                       splx(s);
+                       mutex_exit(&grant_lock);
                        if (ratecheck(&xengnt_nonmemtime, &xengnt_nonmemintvl))
                                printf("xengnt_get_entry: out of grant "
                                    "table entries\n");
@@ -234,7 +238,7 @@
        last_gnt_entry--;
        entry = gnt_entries[last_gnt_entry];
        gnt_entries[last_gnt_entry] = XENGNT_NO_ENTRY;
-       splx(s);
+       mutex_exit(&grant_lock);
        KASSERT(entry != XENGNT_NO_ENTRY);
        KASSERT(last_gnt_entry >= 0);
        KASSERT(last_gnt_entry <= gnt_max_grant_frames * NR_GRANT_ENTRIES_PER_PAGE);
@@ -247,13 +251,13 @@
 static void
 xengnt_free_entry(grant_ref_t entry)
 {
-       int s = splvm();
+       mutex_enter(&grant_lock);
        KASSERT(gnt_entries[last_gnt_entry] == XENGNT_NO_ENTRY);
        KASSERT(last_gnt_entry >= 0);
        KASSERT(last_gnt_entry <= gnt_max_grant_frames * NR_GRANT_ENTRIES_PER_PAGE);
        gnt_entries[last_gnt_entry] = entry;
        last_gnt_entry++;
-       splx(s);
+       mutex_exit(&grant_lock);
 }
 
 int
@@ -263,6 +267,7 @@
        if (__predict_false(*entryp == XENGNT_NO_ENTRY))
                return ENOMEM;
 
+       mutex_enter(&grant_lock);
        grant_table[*entryp].frame = ma >> PAGE_SHIFT;
        grant_table[*entryp].domid = dom;
        /*
@@ -272,6 +277,7 @@
        xen_rmb();
        grant_table[*entryp].flags =
            GTF_permit_access | (ro ? GTF_readonly : 0);
+       mutex_exit(&grant_lock);
        return 0;
 }
 
@@ -298,6 +304,7 @@
        if (__predict_false(*entryp == XENGNT_NO_ENTRY))
                return ENOMEM;
 
+       mutex_enter(&grant_lock);
        grant_table[*entryp].frame = 0;
        grant_table[*entryp].domid = dom;
        /*
@@ -306,6 +313,7 @@
         */
        xen_rmb();
        grant_table[*entryp].flags = GTF_accept_transfer;
+       mutex_exit(&grant_lock);
        return 0;
 }
 



Home | Main Index | Thread Index | Old Index