From: Samuel Thibault <samuel.thibault@eu.citrix.com>
To: xen-devel@lists.xensource.com
Subject: [PATCH] [Mini-OS] Make gnttab allocation/free safe
Date: Mon, 26 Nov 2007 11:56:51 +0000 [thread overview]
Message-ID: <20071126115651.GA8982@implementation.uk.xensource.com> (raw)
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>
diff -r bb961bda7eff extras/mini-os/gnttab.c
--- a/extras/mini-os/gnttab.c Sun Nov 25 21:24:48 2007 +0000
+++ b/extras/mini-os/gnttab.c Mon Nov 26 11:50:31 2007 +0000
@@ -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;
}
diff -r bb961bda7eff extras/mini-os/netfront.c
--- a/extras/mini-os/netfront.c Sun Nov 25 21:24:48 2007 +0000
+++ b/extras/mini-os/netfront.c Mon Nov 26 11:50:31 2007 +0000
@@ -147,6 +147,7 @@ moretodo:
struct net_buffer* buf = &rx_buffers[id];
void* page = buf->page;
+ /* We are sure to have free gnttab entries since they got released above */
buf->gref = req->gref =
gnttab_grant_access(0,virt_to_mfn(page),0);
@@ -436,8 +437,9 @@ void netfront_xmit(unsigned char* data,i
down(&tx_sem);
local_irq_save(flags);
+ id = get_id_from_freelist(tx_freelist);
+ local_irq_restore(flags);
- id = get_id_from_freelist(tx_freelist);
buf = &tx_buffers[id];
page = buf->page;
@@ -461,7 +463,7 @@ void netfront_xmit(unsigned char* data,i
if(notify) notify_remote_via_evtchn(info->evtchn);
+ local_irq_save(flags);
network_tx_buf_gc();
-
local_irq_restore(flags);
}
reply other threads:[~2007-11-26 11:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071126115651.GA8982@implementation.uk.xensource.com \
--to=samuel.thibault@eu.citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.