Re: [PATCH] adjust/fix LDT handling for Xen

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jeremy Fitzhardinge
Date: Monday, January 14, 2008 - 10:04 am

Jan Beulich wrote:

I've got the unified version here. 

Subject: xen: adjust/fix LDT handling for Xen

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: Jan Beulich <jbeulich@novell.com>
Acked-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: Ingo Molnar <mingo@elte.hu>

---
 arch/x86/kernel/ldt.c    |    7 +++----
 arch/x86/xen/enlighten.c |    9 +--------
 2 files changed, 4 insertions(+), 12 deletions(-)

===================================================================
--- a/arch/x86/kernel/ldt.c
+++ b/arch/x86/kernel/ldt.c
@@ -12,7 +12,6 @@
 #include <linux/mm.h>
 #include <linux/smp.h>
 #include <linux/vmalloc.h>
-#include <linux/slab.h>
 
 #include <asm/uaccess.h>
 #include <asm/system.h>
@@ -40,7 +39,7 @@ static int alloc_ldt(mm_context_t *pc, i
 	if (mincount * LDT_ENTRY_SIZE > PAGE_SIZE)
 		newldt = vmalloc(mincount * LDT_ENTRY_SIZE);
 	else
-		newldt = kmalloc(mincount * LDT_ENTRY_SIZE, GFP_KERNEL);
+		newldt = (void *)__get_free_page(GFP_KERNEL);
 
 	if (!newldt)
 		return -ENOMEM;
@@ -78,7 +77,7 @@ static int alloc_ldt(mm_context_t *pc, i
 		if (oldsize * LDT_ENTRY_SIZE > PAGE_SIZE)
 			vfree(oldldt);
 		else
-			kfree(oldldt);
+			put_page(virt_to_page(oldldt));
 	}
 	return 0;
 }
@@ -129,7 +128,7 @@ void destroy_context(struct mm_struct *m
 		if (mm->context.size * LDT_ENTRY_SIZE > PAGE_SIZE)
 			vfree(mm->context.ldt);
 		else
-			kfree(mm->context.ldt);
+			put_page(virt_to_page(mm->context.ldt));
 		mm->context.size = 0;
 	}
 }
===================================================================
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -275,19 +275,12 @@ static unsigned long xen_store_tr(void)
 
 static void xen_set_ldt(const void *addr, unsigned entries)
 {
-	unsigned long linear_addr = (unsigned long)addr;
 	struct mmuext_op *op;
 	struct multicall_space mcs = xen_mc_entry(sizeof(*op));
 
 	op = mcs.args;
 	op->cmd = MMUEXT_SET_LDT;
-	if (linear_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->arg1.linear_addr = (unsigned long)addr;
 	op->arg2.nr_ents = entries;
 
 	MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF);

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] adjust/fix LDT handling for Xen, Jan Beulich, (Fri Jan 11, 2:22 am)
Re: [PATCH] adjust/fix LDT handling for Xen, Jan Beulich, (Fri Jan 11, 3:08 am)
Re: [PATCH] adjust/fix LDT handling for Xen, Jeremy Fitzhardinge, (Fri Jan 11, 10:28 am)
Re: [PATCH] adjust/fix LDT handling for Xen, Jan Beulich, (Mon Jan 14, 1:22 am)
Re: [PATCH] adjust/fix LDT handling for Xen, Ingo Molnar, (Mon Jan 14, 8:48 am)
Re: [PATCH] adjust/fix LDT handling for Xen, Jan Beulich, (Mon Jan 14, 9:06 am)
Re: [PATCH] adjust/fix LDT handling for Xen, Jeremy Fitzhardinge, (Mon Jan 14, 10:04 am)
Re: [PATCH] adjust/fix LDT handling for Xen, Ingo Molnar, (Tue Jan 15, 6:24 am)
Re: [PATCH] adjust/fix LDT handling for Xen, Jeremy Fitzhardinge, (Tue Jan 15, 2:47 pm)