From: Jacob Gorm Hansen Subject: [PATCH] minios: simplified freelists in gnttab.c Date: Thu, 04 Jan 2007 18:13:39 +0100 Message-ID: <1167930820.2883.13.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-bmDS85q3WltNIERniJOY" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel List-Id: xen-devel@lists.xenproject.org --=-bmDS85q3WltNIERniJOY Content-Type: text/plain Content-Transfer-Encoding: 7bit hi, I found some strange freelist error conditions in gnttab.c under heavy load, and replaced the get/put_free_entry() functions with code similar to that of XenLinux' netfront.c. Without this patch out-of-range ids will be returned under heavy load. Jacob --=-bmDS85q3WltNIERniJOY Content-Disposition: attachment; filename=minios-gnttab-freelist.patch Content-Type: text/x-patch; name=minios-gnttab-freelist.patch; charset=us-ascii Content-Transfer-Encoding: 7bit Signed-off-by: Jacob Gorm Hansen diff -r 52ae8dd4bc75 extras/mini-os/gnttab.c --- a/extras/mini-os/gnttab.c Tue Oct 17 22:09:52 2006 +0100 +++ b/extras/mini-os/gnttab.c Thu Jan 04 18:09:09 2007 +0100 @@ -23,31 +23,24 @@ #define NR_GRANT_FRAMES 4 #define NR_GRANT_ENTRIES (NR_GRANT_FRAMES * PAGE_SIZE / sizeof(grant_entry_t)) -#define GNTTAB_LIST_END (NR_GRANT_ENTRIES + 1) static grant_entry_t *gnttab_table; static grant_ref_t gnttab_list[NR_GRANT_ENTRIES]; -static grant_ref_t gnttab_free_head; + +static void +put_free_entry(grant_ref_t ref) +{ + gnttab_list[ref] = gnttab_list[0]; + gnttab_list[0] = ref; + +} static grant_ref_t -get_free_entries(int count) +get_free_entry(void) { - grant_ref_t ref; - grant_ref_t head; - - ref = head = gnttab_free_head; - while (count-- > 1) - head = gnttab_list[head]; - gnttab_free_head = gnttab_list[head]; - gnttab_list[head] = GNTTAB_LIST_END; + unsigned int ref = gnttab_list[0]; + gnttab_list[0] = gnttab_list[ref]; return ref; -} - -static void -put_free_entry(grant_ref_t gref) -{ - gnttab_list[gref] = gnttab_free_head; - gnttab_free_head = gref; } grant_ref_t @@ -55,7 +48,7 @@ gnttab_grant_access(domid_t domid, unsig { grant_ref_t ref; - ref = get_free_entries(1); + ref = get_free_entry(); gnttab_table[ref].frame = frame; gnttab_table[ref].domid = domid; wmb(); @@ -70,7 +63,7 @@ gnttab_grant_transfer(domid_t domid, uns { grant_ref_t ref; - ref = get_free_entries(1); + ref = get_free_entry(); gnttab_table[ref].frame = pfn; gnttab_table[ref].domid = domid; wmb(); @@ -157,8 +150,7 @@ init_gnttab(void) int i; for (i = NR_RESERVED_ENTRIES; i < NR_GRANT_ENTRIES; i++) - gnttab_list[i] = i + 1; - gnttab_free_head = NR_RESERVED_ENTRIES; + put_free_entry(i); setup.dom = DOMID_SELF; setup.nr_frames = NR_GRANT_FRAMES; --=-bmDS85q3WltNIERniJOY Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=-bmDS85q3WltNIERniJOY--