<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
From: Zachary Amsden &lt;zach@vmware.com&gt;

Add hooks that the hypervisor can use to establish writable and non-writable
pages for LDT pages.  I made these parallel the page flags as defined in
include/linux/page-flags.h, since the flag mechanism is very similar to the
hypercall page flagging, and extended easily later to include PT, PD, PDP,
GDT, etc.

Signed-off-by: Zachary Amsden &lt;zach@vmware.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@osdl.org&gt;
---

 arch/i386/kernel/ldt.c                       |    9 ++++++++-
 include/asm-i386/mach-default/mach_pgalloc.h |    7 +++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff -puN arch/i386/kernel/ldt.c~i386--introduce-hypervisor-ldt-hooks arch/i386/kernel/ldt.c
--- 25/arch/i386/kernel/ldt.c~i386--introduce-hypervisor-ldt-hooks	Wed Aug 17 13:34:02 2005
+++ 25-akpm/arch/i386/kernel/ldt.c	Wed Aug 17 13:34:02 2005
@@ -18,6 +18,7 @@
 #include &lt;asm/system.h&gt;
 #include &lt;asm/ldt.h&gt;
 #include &lt;asm/desc.h&gt;
+#include &lt;mach_pgalloc.h&gt;
 
 #ifdef CONFIG_SMP /* avoids "defined but not used" warning */
 static void flush_ldt(void *null)
@@ -59,16 +60,19 @@ static inline int alloc_ldt(mm_context_t
 #ifdef CONFIG_SMP
 		cpumask_t mask;
 		preempt_disable();
+		SetPagesLDT(pc-&gt;ldt, (pc-&gt;size * LDT_ENTRY_SIZE) / PAGE_SIZE);
 		load_LDT(pc);
 		mask = cpumask_of_cpu(smp_processor_id());
 		if (!cpus_equal(current-&gt;mm-&gt;cpu_vm_mask, mask))
 			smp_call_function(flush_ldt, NULL, 1, 1);
 		preempt_enable();
 #else
+		SetPagesLDT(pc-&gt;ldt, (pc-&gt;size * LDT_ENTRY_SIZE) / PAGE_SIZE);
 		load_LDT(pc);
 #endif
 	}
 	if (oldsize) {
+		ClearPagesLDT(oldldt, (oldsize * LDT_ENTRY_SIZE) / PAGE_SIZE);
 		if (oldsize*LDT_ENTRY_SIZE &gt; PAGE_SIZE)
 			vfree(oldldt);
 		else
@@ -83,8 +87,10 @@ int copy_ldt(mm_context_t *new, mm_conte
 
 	down(&amp;old-&gt;sem);
 	err = alloc_ldt(new, 0, old-&gt;size, 0);
-	if (!err)
+	if (!err) {
 		memcpy(new-&gt;ldt, old-&gt;ldt, old-&gt;size*LDT_ENTRY_SIZE);
+		SetPagesLDT(new-&gt;ldt, (new-&gt;size * LDT_ENTRY_SIZE) / PAGE_SIZE);
+	}
 	up(&amp;old-&gt;sem);
 	return err;
 }
@@ -93,6 +99,7 @@ void destroy_ldt(struct mm_struct *mm)
 {
 	if (mm == current-&gt;active_mm)
 		clear_LDT();
+	ClearPagesLDT(mm-&gt;context.ldt, (mm-&gt;context.size * LDT_ENTRY_SIZE) / PAGE_SIZE);
 	if (mm-&gt;context.size*LDT_ENTRY_SIZE &gt; PAGE_SIZE)
 		vfree(mm-&gt;context.ldt);
 	else
diff -puN include/asm-i386/mach-default/mach_pgalloc.h~i386--introduce-hypervisor-ldt-hooks include/asm-i386/mach-default/mach_pgalloc.h
--- 25/include/asm-i386/mach-default/mach_pgalloc.h~i386--introduce-hypervisor-ldt-hooks	Wed Aug 17 13:34:02 2005
+++ 25-akpm/include/asm-i386/mach-default/mach_pgalloc.h	Wed Aug 17 13:34:02 2005
@@ -0,0 +1,7 @@
+#ifndef __ASM_MACH_PGALLOC_H
+#define __ASM_MACH_PGALLOC_H
+
+#define SetPagesLDT(_va, _pages)
+#define ClearPagesLDT(_va, _pages)
+
+#endif
_
</pre></body></html>