Commit 4dbf7af6 authored by Jan Beulich's avatar Jan Beulich Committed by Ingo Molnar

x86: adjust/fix LDT handling for Xen

Based on patch from Jan Beulich <jbeulich@novell.com>.

Don't rely on kmalloc(PAGE_SIZE) returning PAGE_SIZE aligned memory
(Xen requires GDT *and* LDT to be page-aligned). Using the page
allocator interface also removes the (albeit small) slab allocator
overhead. The same change being done for 64-bits for consistency.

Further, the Xen hypercall interface expects the LDT address to be
virtual, not machine.

[ Adjusted to unified ldt.c - Jeremy ]
Signed-off-by: default avatarJan Beulich <jbeulich@novell.com>
Acked-by: default avatarJeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent c0400030
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/smp.h> #include <linux/smp.h>
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
#include <linux/slab.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/system.h> #include <asm/system.h>
...@@ -40,7 +39,7 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload) ...@@ -40,7 +39,7 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
if (mincount * LDT_ENTRY_SIZE > PAGE_SIZE) if (mincount * LDT_ENTRY_SIZE > PAGE_SIZE)
newldt = vmalloc(mincount * LDT_ENTRY_SIZE); newldt = vmalloc(mincount * LDT_ENTRY_SIZE);
else else
newldt = kmalloc(mincount * LDT_ENTRY_SIZE, GFP_KERNEL); newldt = (void *)__get_free_page(GFP_KERNEL);
if (!newldt) if (!newldt)
return -ENOMEM; return -ENOMEM;
...@@ -78,7 +77,7 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload) ...@@ -78,7 +77,7 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
if (oldsize * LDT_ENTRY_SIZE > PAGE_SIZE) if (oldsize * LDT_ENTRY_SIZE > PAGE_SIZE)
vfree(oldldt); vfree(oldldt);
else else
kfree(oldldt); put_page(virt_to_page(oldldt));
} }
return 0; return 0;
} }
...@@ -129,7 +128,7 @@ void destroy_context(struct mm_struct *mm) ...@@ -129,7 +128,7 @@ void destroy_context(struct mm_struct *mm)
if (mm->context.size * LDT_ENTRY_SIZE > PAGE_SIZE) if (mm->context.size * LDT_ENTRY_SIZE > PAGE_SIZE)
vfree(mm->context.ldt); vfree(mm->context.ldt);
else else
kfree(mm->context.ldt); put_page(virt_to_page(mm->context.ldt));
mm->context.size = 0; mm->context.size = 0;
} }
} }
......
...@@ -275,19 +275,12 @@ static unsigned long xen_store_tr(void) ...@@ -275,19 +275,12 @@ static unsigned long xen_store_tr(void)
static void xen_set_ldt(const void *addr, unsigned entries) static void xen_set_ldt(const void *addr, unsigned entries)
{ {
unsigned long linear_addr = (unsigned long)addr;
struct mmuext_op *op; struct mmuext_op *op;
struct multicall_space mcs = xen_mc_entry(sizeof(*op)); struct multicall_space mcs = xen_mc_entry(sizeof(*op));
op = mcs.args; op = mcs.args;
op->cmd = MMUEXT_SET_LDT; op->cmd = MMUEXT_SET_LDT;
if (linear_addr) { op->arg1.linear_addr = (unsigned long)addr;
/* ldt my be vmalloced, use arbitrary_virt_to_machine */
xmaddr_t maddr;
maddr = arbitrary_virt_to_machine((unsigned long)addr);
linear_addr = (unsigned long)maddr.maddr;
}
op->arg1.linear_addr = linear_addr;
op->arg2.nr_ents = entries; op->arg2.nr_ents = entries;
MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF); MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment