aboutsummaryrefslogtreecommitdiffstats
path: root/extras/mini-os/gnttab.c
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2007-11-28 12:40:57 +0000
committerKeir Fraser <keir.fraser@citrix.com>2007-11-28 12:40:57 +0000
commit1c0c172695a42a11ca7206283b4f1d6a486d05ac (patch)
treef4b821a303752bfb60fb9833469e81c7db489235 /extras/mini-os/gnttab.c
parent7f4955ee5fc5f9f45e8d201a25b7ac445838b1a2 (diff)
downloadxen-1c0c172695a42a11ca7206283b4f1d6a486d05ac.tar.gz
xen-1c0c172695a42a11ca7206283b4f1d6a486d05ac.tar.bz2
xen-1c0c172695a42a11ca7206283b4f1d6a486d05ac.zip
[Mini-OS] Make gnttab allocation/free safe
Add a semaphore to protect gnttab_list from exhaustion, and disable callbacks during allocation/free. Fix the network frontend accordingly. Signed-off-by: Samuel Thibault <samuel.thibault@citrix.com>
Diffstat (limited to 'extras/mini-os/gnttab.c')
-rw-r--r--extras/mini-os/gnttab.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/extras/mini-os/gnttab.c b/extras/mini-os/gnttab.c
index b22f51ceae..5c2dcea863 100644
--- a/extras/mini-os/gnttab.c
+++ b/extras/mini-os/gnttab.c
@@ -18,6 +18,7 @@
#include <os.h>
#include <mm.h>
#include <gnttab.h>
+#include <semaphore.h>
#define NR_RESERVED_ENTRIES 8
@@ -31,20 +32,29 @@
static grant_entry_t *gnttab_table;
static grant_ref_t gnttab_list[NR_GRANT_ENTRIES];
+static __DECLARE_SEMAPHORE_GENERIC(gnttab_sem, NR_GRANT_ENTRIES);
static void
put_free_entry(grant_ref_t ref)
{
+ unsigned long flags;
+ local_irq_save(flags);
gnttab_list[ref] = gnttab_list[0];
gnttab_list[0] = ref;
-
+ local_irq_restore(flags);
+ up(&gnttab_sem);
}
static grant_ref_t
get_free_entry(void)
{
- unsigned int ref = gnttab_list[0];
+ unsigned int ref;
+ unsigned long flags;
+ down(&gnttab_sem);
+ local_irq_save(flags);
+ ref = gnttab_list[0];
gnttab_list[0] = gnttab_list[ref];
+ local_irq_restore(flags);
return ref;
}