Skip to contentSkip to conversation

SKAS on AMD 64-Bit

uml-devel Anthony Brock 4 participants 5 messages Aug 6, 2004 – Aug 31, 2004 User-mode Linux (UML)

lore
Share & tools
lore
#0 lore raw

I would like to implement SKAS on my AMD 64-bit host. However, the current patch applies to files within the i386 arch directory:

# patch -p0 < ../host-skas3-2.6.7-v1.patch 
patching file ./arch/i386/kernel/sys_i386.c
patching file ./arch/i386/kernel/ptrace.c
patching file ./arch/i386/kernel/ldt.c
patching file ./arch/i386/Kconfig
patching file ./include/linux/mm.h
patching file ./include/linux/proc_mm.h
patching file ./include/asm-i386/desc.h
patching file ./include/asm-i386/processor.h
patching file ./include/asm-i386/ptrace.h
patching file ./include/asm-i386/mmu_context.h
patching file ./mm/mmap.c
patching file ./mm/mprotect.c
patching file ./mm/proc_mm.c
patching file ./mm/Makefile

Has anyone converted this patch to apply against the x86_64 architecture? Should the changes be relatively transparent (merely a matter of figuring out how to impose them, or do I need to worry about functional changes...)? Any help is greatly appreciated!

Tony

-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now, one more big change to announce. We are now OSTG- Open Source Technology Group. Come see the changes on the new OSTG site. www.ostg.com
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#1 lore raw

Given a lack of responses to my inquiry, I've attempted to migrate the existing patches to the "arch/i386" and "include/asm-i386" directories to the corresponding "arch/x86_64" and "include/asm-x86_64" directories.

However, I am experiencing the following issue during boot of a previously functional guest UML when I use the new Host Kernel:

Checking for the skas3 patch in the host...found
Checking for /proc/mm...found
Linux version 2.6.7-1um (root@vs1) (gcc version 3.3.3 (SuSE Linux)) #2 Thu

Jul 29 08:57:53 PDT 2004

On node 0 totalpages: 122880
DMA zone: 122880 pages, LIFO batch:16
Normal zone: 0 pages, LIFO batch:1
HighMem zone: 0 pages, LIFO batch:1
Built 1 zonelists

*** OUTPUT TRIMMED ***

kjournald starting. Commit interval 5 seconds
EXT3-fs: mounted filesystem with ordered data mode.
VFS: Mounted root (ext3 filesystem) readonly.

Kernel panic: kernel BUG at mm/mmap.c:700!

Any ideas? How would I generate a backtrace for this issue?

I am attaching a copy of the non-functional patch. This patch applies against a vanilla 2.6.7 kernel with host-skas3-2.6.7-v1.patch pre-applied (in other words, it's a patch to the SKAS3 patch). Thanks in advance!

Tony

-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#2 lore raw

It would probably help if I included the patch! :)

Tony

Quoted 44 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]On Behalf Of Anthony Brock
Sent: Sunday, August 15, 2004 2:44 PM
To: [email protected]
Subject: RE: [uml-devel] SKAS on AMD 64-Bit

Given a lack of responses to my inquiry, I've attempted to migrate the existing patches to the "arch/i386" and "include/asm-i386" directories to the corresponding "arch/x86_64" and "include/asm-x86_64" directories.

However, I am experiencing the following issue during boot of a previously functional guest UML when I use the new Host Kernel:

Checking for the skas3 patch in the host...found
Checking for /proc/mm...found
Linux version 2.6.7-1um (root@vs1) (gcc version 3.3.3 (SuSE Linux)) #2 Thu

Jul 29 08:57:53 PDT 2004

On node 0 totalpages: 122880
DMA zone: 122880 pages, LIFO batch:16
Normal zone: 0 pages, LIFO batch:1
HighMem zone: 0 pages, LIFO batch:1
Built 1 zonelists

*** OUTPUT TRIMMED ***

kjournald starting. Commit interval 5 seconds
EXT3-fs: mounted filesystem with ordered data mode.
VFS: Mounted root (ext3 filesystem) readonly.

Kernel panic: kernel BUG at mm/mmap.c:700!

Any ideas? How would I generate a backtrace for this issue?

I am attaching a copy of the non-functional patch. This patch applies against a vanilla 2.6.7 kernel with host-skas3-2.6.7-v1.patch pre-applied (in other words, it's a patch to the SKAS3 patch). Thanks in advance!

Tony

Quoted 10 lines

-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

x86_64/Kconfig renamed from x86_64/Kconfig.skas +4 -0
diff -ur arch/x86_64/Kconfig.skas arch/x86_64/Kconfig
@@ -249,6 +249,10 @@
 	  cost of slightly increased overhead in some places. If unsure say
 	  N here.
 
+config PROC_MM
+       bool "/proc/mm support"
+       default y
+
 config K8_NUMA
        bool "K8 NUMA support"
        depends on SMP
x86_64/kernel/ldt.c renamed from x86_64/kernel/ldt.c.skas +22 -14
diff -ur arch/x86_64/kernel/ldt.c.skas arch/x86_64/kernel/ldt.c
@@ -58,7 +58,7 @@
 	wmb();
 	pc->size = mincount;
 	wmb();
-	if (reload) {
+	if (reload && (&current->active_mm->context == pc)) {
 #ifdef CONFIG_SMP
 		cpumask_t mask;
 
@@ -94,14 +94,12 @@
  * we do not have to muck with descriptors here, that is
  * done in switch_mm() as needed.
  */
-int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
+int __init_new_context(struct mm_struct *mm, struct mm_struct *old_mm)
 {
-	struct mm_struct * old_mm;
 	int retval = 0;
 
 	init_MUTEX(&mm->context.sem);
 	mm->context.size = 0;
-	old_mm = current->mm;
 	if (old_mm && old_mm->context.size > 0) {
 		down(&old_mm->context.sem);
 		retval = copy_ldt(&mm->context, &old_mm->context);
@@ -110,6 +108,11 @@
 	return retval;
 }
 
+int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
+{
+	return __init_new_context(mm, current->mm);
+}
+
 /*
  * 
  * Don't touch the LDT register - we're already in the next thread.
@@ -125,11 +128,11 @@
 	}
 }
 
-static int read_ldt(void __user * ptr, unsigned long bytecount)
+static int read_ldt(struct mm_struct * mm, void __user * ptr,
+		    unsigned long bytecount)
 {
 	int err;
 	unsigned long size;
-	struct mm_struct * mm = current->mm;
 
 	if (!mm->context.size)
 		return 0;
@@ -164,10 +167,9 @@
 	return bytecount; 
 }
 
-static int write_ldt(void __user * ptr, unsigned long bytecount, int oldmode)
+static int write_ldt(struct mm_struct * mm, void __user * ptr,
+		     unsigned long bytecount, int oldmode)
 {
-	struct task_struct *me = current;
-	struct mm_struct * mm = me->mm;
 	__u32 entry_1, entry_2, *lp;
 	int error;
 	struct user_desc ldt_info;
@@ -192,7 +194,7 @@
 
 	down(&mm->context.sem);
 	if (ldt_info.entry_number >= (unsigned)mm->context.size) {
-		error = alloc_ldt(&current->mm->context, ldt_info.entry_number+1, 1);
+		error = alloc_ldt(&mm->context, ldt_info.entry_number+1, 1);
 		if (error < 0)
 			goto out_unlock;
 	}
@@ -225,23 +227,29 @@
 	return error;
 }
 
-asmlinkage int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount)
+int modify_ldt(struct mm_struct * mm, int func, void __user *ptr,
+		   unsigned long bytecount)
 {
 	int ret = -ENOSYS;
 
 	switch (func) {
 	case 0:
-		ret = read_ldt(ptr, bytecount);
+		ret = read_ldt(mm, ptr, bytecount);
 		break;
 	case 1:
-		ret = write_ldt(ptr, bytecount, 1);
+		ret = write_ldt(mm, ptr, bytecount, 1);
 		break;
 	case 2:
 		ret = read_default_ldt(ptr, bytecount);
 		break;
 	case 0x11:
-		ret = write_ldt(ptr, bytecount, 0);
+		ret = write_ldt(mm, ptr, bytecount, 0);
 		break;
 	}
 	return ret;
 }
+
+asmlinkage int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount)
+{
+	return modify_ldt(current->mm, func, ptr, bytecount);
+}
x86_64/kernel/ptrace.c renamed from x86_64/kernel/ptrace.c.skas +51 -0

63 lines not on this page · raw message

x86_64/kernel/sys_x86_64.c renamed from x86_64/kernel/sys_x86_64.c.skas +12 -4
diff -ur arch/x86_64/kernel/sys_x86_64.c.skas arch/x86_64/kernel/sys_x86_64.c
@@ -38,7 +38,9 @@
 	return error;
 }
 
-long sys_mmap(unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags,
+long do_mmap2(struct mm_struct *mm,
+	unsigned long addr, unsigned long len,
+	unsigned long prot, unsigned long flags,
 	unsigned long fd, unsigned long off)
 {
 	long error;
@@ -56,9 +58,9 @@
 		if (!file)
 			goto out;
 	}
-	down_write(&current->mm->mmap_sem);
-	error = do_mmap_pgoff(file, addr, len, prot, flags, off >> PAGE_SHIFT);
-	up_write(&current->mm->mmap_sem);
+	down_write(&mm->mmap_sem);
+	error = __do_mmap_pgoff(mm, file, addr, len, prot, flags, off >> PAGE_SHIFT);
+	up_write(&mm->mmap_sem);
 
 	if (file)
 		fput(file);
@@ -66,6 +68,12 @@
 	return error;
 }
 
+long sys_mmap(unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags,
+	unsigned long fd, unsigned long off)
+{
+	return do_mmap2(current->mm, addr, len, prot, flags, fd, off);
+}
+
 static void find_start_end(unsigned long flags, unsigned long *begin,
 			   unsigned long *end)
 {
asm-x86_64/desc.h renamed from asm-x86_64/desc.h.skas +3 -0
diff -ur include/asm-x86_64/desc.h.skas include/asm-x86_64/desc.h
@@ -210,6 +210,9 @@
 	put_cpu();
 }
 
+extern int modify_ldt(struct mm_struct * mm, int func, void __user *ptr,
+		      unsigned long bytecount);
+
 #endif /* !__ASSEMBLY__ */
 
 #endif
asm-x86_64/processor.h renamed from asm-x86_64/processor.h.skas +2 -0
diff -ur include/asm-x86_64/processor.h.skas include/asm-x86_64/processor.h
@@ -454,6 +454,8 @@
 	ti->task;					\
 })
 
+extern int __init_new_context(struct mm_struct *mm, struct mm_struct *old_mm);
+
 #define cache_line_size() (boot_cpu_data.x86_cache_alignment)
 
 #ifdef CONFIG_SCHED_SMT
asm-x86_64/ptrace.h renamed from asm-x86_64/ptrace.h.skas +22 -0
diff -ur include/asm-x86_64/ptrace.h.skas include/asm-x86_64/ptrace.h
@@ -110,4 +110,26 @@
 
 #endif
 
+/*For SKAS3 support.*/
+#ifndef _LINUX_PTRACE_STRUCT_DEF
+#define _LINUX_PTRACE_STRUCT_DEF
+
+#define PTRACE_FAULTINFO	52
+#define PTRACE_SIGPENDING	53
+#define PTRACE_LDT		54
+#define PTRACE_SWITCH_MM	55
+
+struct ptrace_faultinfo {
+	int is_write;
+	unsigned long addr;
+};
+
+struct ptrace_ldt {
+	int func;
+	void *ptr;
+	unsigned long bytecount;
+};
+
+#endif /*ifndef _LINUX_PTRACE_STRUCT_DEF*/
+
 #endif
#3 lore raw

Alle 01:13, lunedì 16 agosto 2004, Anthony Brock ha scritto:

Quoted 1 line

It would probably help if I included the patch! :)

Hmmm... are you trying to run a normal UML binary, I guess, i.e. a 32-bit app which would also run onto a x86 pc, right? 64bit UMLs don't support well the SKAS mode (actually, I never tested this, but there are some significant changes in the SKAS code in the x86_64-UML patch).

I wrote a patch for this, applying onto a vanilla 2.4 kernel tree, but I never tested it (not even if it compiled). And I'm rechecking it, and there are some bugs in it.

About your patch, there is just a big bug in your patch (if you want to run a *32* bit UML): when a 32 bit app invokes a syscall, let's say mmap, actually it calls the sys32_ version of it, if that one exists, in this case sys32_mmap. You can check the name of the syscall functions in arch/x86_64/ia32/ia32entry.S. There are some such bugs in my patch, too, in fact. However, when I come back (I'm on holidays and far from Internet - today is 23 August), if you want to help (i.e. actually test the patches), just email me and I'll finish the porting and publish it.

Signature · 14 lines
Paolo Giarrusso, aka Blaisorblade
Linux registered user n. 292729



-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_idP47&alloc_id808&opÌk
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
#4 lore raw

[uml-devel] UML on AMD 64-Bit

In reply to Anthony Brock

Hi,

Does there any released patch for AMD 64 system? Thanks.

Regards,
Qinghua(Kevin) Ye

-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel