From: "Jan Beulich" Subject: [PATCH] x86 linux: make MTRR handling SMP safe Date: Thu, 09 Mar 2006 14:38:50 +0100 Message-ID: <44103DFA.76F0.0078.0@novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartE9CCB0FA.0__=" 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@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartE9CCB0FA.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline The usage counters can get corrupted without proper synchronization. Jan --=__PartE9CCB0FA.0__= Content-Type: text/plain; name="xenlinux-x86-mtrr-smp-safe.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="xenlinux-x86-mtrr-smp-safe.patch" Index: head-2006-03-06/arch/i386/kernel/cpu/mtrr/main-xen.c =================================================================== --- head-2006-03-06.orig/arch/i386/kernel/cpu/mtrr/main-xen.c 2006-03-09 12:23:34.191319888 +0100 +++ head-2006-03-06/arch/i386/kernel/cpu/mtrr/main-xen.c 2006-03-09 12:26:12.319280784 +0100 @@ -8,6 +8,8 @@ #include #include "mtrr.h" +static DECLARE_MUTEX(mtrr_sem); + void generic_get_mtrr(unsigned int reg, unsigned long *base, unsigned int *size, mtrr_type * type) { @@ -63,12 +65,15 @@ int mtrr_add_page(unsigned long base, un int error; dom0_op_t op; + down(&mtrr_sem); + op.cmd = DOM0_ADD_MEMTYPE; op.u.add_memtype.mfn = base; op.u.add_memtype.nr_mfns = size; op.u.add_memtype.type = type; error = HYPERVISOR_dom0_op(&op); if (error) { + up(&mtrr_sem); BUG_ON(error > 0); return error; } @@ -76,6 +81,8 @@ int mtrr_add_page(unsigned long base, un if (increment) ++usage_table[op.u.add_memtype.reg]; + up(&mtrr_sem); + return op.u.add_memtype.reg; } @@ -104,17 +111,18 @@ mtrr_add(unsigned long base, unsigned lo int mtrr_del_page(int reg, unsigned long base, unsigned long size) { - int i, max; + unsigned i; mtrr_type ltype; unsigned long lbase; unsigned int lsize; int error = -EINVAL; dom0_op_t op; - max = num_var_ranges; + down(&mtrr_sem); + if (reg < 0) { /* Search for existing MTRR */ - for (i = 0; i < max; ++i) { + for (i = 0; i < num_var_ranges; ++i) { mtrr_if->get(i, &lbase, &lsize, <ype); if (lbase == base && lsize == size) { reg = i; @@ -143,6 +151,7 @@ int mtrr_del_page(int reg, unsigned long } error = reg; out: + up(&mtrr_sem); return error; } --=__PartE9CCB0FA.0__= 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 --=__PartE9CCB0FA.0__=--