ia64/xen-unstable

changeset 9209:e0d32d7cb5da

Apply proper locking in xenlinux mtrr interface functions.

From: Jan Beulich
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Mar 09 15:59:53 2006 +0100 (2006-03-09)
parents c176d2e45117
children df0ad1c46f10
files linux-2.6-xen-sparse/arch/i386/kernel/cpu/mtrr/main-xen.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/cpu/mtrr/main-xen.c	Thu Mar 09 15:57:32 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/cpu/mtrr/main-xen.c	Thu Mar 09 15:59:53 2006 +0100
     1.3 @@ -8,6 +8,8 @@
     1.4  #include <asm/mtrr.h>
     1.5  #include "mtrr.h"
     1.6  
     1.7 +static DECLARE_MUTEX(mtrr_sem);
     1.8 +
     1.9  void generic_get_mtrr(unsigned int reg, unsigned long *base,
    1.10  		      unsigned int *size, mtrr_type * type)
    1.11  {
    1.12 @@ -63,12 +65,15 @@ int mtrr_add_page(unsigned long base, un
    1.13  	int error;
    1.14  	dom0_op_t op;
    1.15  
    1.16 +	down(&mtrr_sem);
    1.17 +
    1.18  	op.cmd = DOM0_ADD_MEMTYPE;
    1.19  	op.u.add_memtype.mfn     = base;
    1.20  	op.u.add_memtype.nr_mfns = size;
    1.21  	op.u.add_memtype.type    = type;
    1.22  	error = HYPERVISOR_dom0_op(&op);
    1.23  	if (error) {
    1.24 +		up(&mtrr_sem);
    1.25  		BUG_ON(error > 0);
    1.26  		return error;
    1.27  	}
    1.28 @@ -76,6 +81,8 @@ int mtrr_add_page(unsigned long base, un
    1.29  	if (increment)
    1.30  		++usage_table[op.u.add_memtype.reg];
    1.31  
    1.32 +	up(&mtrr_sem);
    1.33 +
    1.34  	return op.u.add_memtype.reg;
    1.35  }
    1.36  
    1.37 @@ -104,17 +111,18 @@ mtrr_add(unsigned long base, unsigned lo
    1.38  
    1.39  int mtrr_del_page(int reg, unsigned long base, unsigned long size)
    1.40  {
    1.41 -	int i, max;
    1.42 +	unsigned i;
    1.43  	mtrr_type ltype;
    1.44  	unsigned long lbase;
    1.45  	unsigned int lsize;
    1.46  	int error = -EINVAL;
    1.47  	dom0_op_t op;
    1.48  
    1.49 -	max = num_var_ranges;
    1.50 +	down(&mtrr_sem);
    1.51 +
    1.52  	if (reg < 0) {
    1.53  		/*  Search for existing MTRR  */
    1.54 -		for (i = 0; i < max; ++i) {
    1.55 +		for (i = 0; i < num_var_ranges; ++i) {
    1.56  			mtrr_if->get(i, &lbase, &lsize, &ltype);
    1.57  			if (lbase == base && lsize == size) {
    1.58  				reg = i;
    1.59 @@ -143,6 +151,7 @@ int mtrr_del_page(int reg, unsigned long
    1.60  	}
    1.61  	error = reg;
    1.62   out:
    1.63 +	up(&mtrr_sem);
    1.64  	return error;
    1.65  }
    1.66