aboutsummaryrefslogtreecommitdiffstats
path: root/extras/mini-os/gnttab.c
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2008-03-26 13:13:50 +0000
committerKeir Fraser <keir.fraser@citrix.com>2008-03-26 13:13:50 +0000
commitaecea1aa6522c44d8111731c8b6f0e9a6e08f001 (patch)
tree9c8efebd9eb0586717662f5462e1814a6495c751 /extras/mini-os/gnttab.c
parenta363bc0ce024186ad26ec3c38074b7565b01611f (diff)
downloadxen-aecea1aa6522c44d8111731c8b6f0e9a6e08f001.tar.gz
xen-aecea1aa6522c44d8111731c8b6f0e9a6e08f001.tar.bz2
xen-aecea1aa6522c44d8111731c8b6f0e9a6e08f001.zip
minios: more assertions
- assert that we never allocate or free the same grant twice - assert that network packets do not exceed a page - assert that incoming network event IDs make sense Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
Diffstat (limited to 'extras/mini-os/gnttab.c')
-rw-r--r--extras/mini-os/gnttab.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/extras/mini-os/gnttab.c b/extras/mini-os/gnttab.c
index 5c2dcea863..dd66b043bf 100644
--- a/extras/mini-os/gnttab.c
+++ b/extras/mini-os/gnttab.c
@@ -32,6 +32,9 @@
static grant_entry_t *gnttab_table;
static grant_ref_t gnttab_list[NR_GRANT_ENTRIES];
+#ifdef GNT_DEBUG
+static char inuse[NR_GRANT_ENTRIES];
+#endif
static __DECLARE_SEMAPHORE_GENERIC(gnttab_sem, NR_GRANT_ENTRIES);
static void
@@ -39,6 +42,10 @@ put_free_entry(grant_ref_t ref)
{
unsigned long flags;
local_irq_save(flags);
+#ifdef GNT_DEBUG
+ BUG_ON(!inuse[ref]);
+ inuse[ref] = 0;
+#endif
gnttab_list[ref] = gnttab_list[0];
gnttab_list[0] = ref;
local_irq_restore(flags);
@@ -54,6 +61,10 @@ get_free_entry(void)
local_irq_save(flags);
ref = gnttab_list[0];
gnttab_list[0] = gnttab_list[ref];
+#ifdef GNT_DEBUG
+ BUG_ON(inuse[ref]);
+ inuse[ref] = 1;
+#endif
local_irq_restore(flags);
return ref;
}
@@ -92,10 +103,12 @@ gnttab_end_access(grant_ref_t ref)
{
u16 flags, nflags;
+ BUG_ON(ref >= NR_GRANT_ENTRIES || ref < NR_RESERVED_ENTRIES);
+
nflags = gnttab_table[ref].flags;
do {
if ((flags = nflags) & (GTF_reading|GTF_writing)) {
- printk("WARNING: g.e. still in use!\n");
+ printk("WARNING: g.e. still in use! (%x)\n", flags);
return 0;
}
} while ((nflags = synch_cmpxchg(&gnttab_table[ref].flags, flags, 0)) !=
@@ -111,6 +124,8 @@ gnttab_end_transfer(grant_ref_t ref)
unsigned long frame;
u16 flags;
+ BUG_ON(ref >= NR_GRANT_ENTRIES || ref < NR_RESERVED_ENTRIES);
+
while (!((flags = gnttab_table[ref].flags) & GTF_transfer_committed)) {
if (synch_cmpxchg(&gnttab_table[ref].flags, flags, 0) == flags) {
printk("Release unused transfer grant.\n");
@@ -164,6 +179,9 @@ init_gnttab(void)
unsigned long frames[NR_GRANT_FRAMES];
int i;
+#ifdef GNT_DEBUG
+ memset(inuse, 1, sizeof(inuse));
+#endif
for (i = NR_RESERVED_ENTRIES; i < NR_GRANT_ENTRIES; i++)
put_free_entry(i);