Skip to contentSkip to conversation

Problems with the SKAS patch and 2.6

uml-devel Steven Elliott 3 participants 3 messages Apr 16, 2004

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

I'd like to first thank you for creating a very valuable kernel debugging tool. I wish more people knew about UML as a means of learning about how kernels work.

I may be overlooking something, but as far as I can tell it is not currently possible to apply any of the SKAS patches to 2.6.

The host-skas3.patch patch has several conflicts when applied to 2.6. I attempted to manually port host-skas3.patch to 2.6, but I ran into a missing file or function (unfortunately I can remember what it was).

Also, it is not obvious what host-skas-2.6.0-test1.diff should be applied to. It seems to somehow depend on code added by the host-skas3.patch patch, but first applying the host-skas3.patch patch is not sufficient. If someone could regenerate host-skas-2.6.0-test1.diff such that it can be applied to a straight 2.6 kernel that would be very helpful.

Right now I'll assume that there are some technical problems with porting SKAS to 2.6, so it is not just a simple matter of shuffling code from the host-skas3.patch patch to the corresponding place in 2.6.

Also, my experience has been that debugging with GDB works better when SKAS mode is used. So, you might want to mention that in either the SKAS page or the debugging page.

Signature · 15 lines
-----------------------------------------------------------------------
|          Steven Elliott          |      [email protected]     |
-----------------------------------------------------------------------



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
#1 lore raw

It is possible to run SKAS on 2.6. I'm running 2.6.6-rc1-1um SKAS now.

Try the attached patch (00-2.6.6-v0-host-SKAS2.patch.bz2) for 2.6.6-rc1. It's slightly modified from the original 00-2.6.2-v1-host-SKAS2.patch.bz2 patch, which should apply up to 2.6.5.

Up to 2.6.5, the uml kernel should compile fine, but to compile 2.6.6-rc1, those files in arch/um/util need to be modified. I'll try to post those modifications if you're interested. Currently, I just simply modified those files to get the kernel to compile, and need to go back to trace the changes.

Thanks,
Jeff

Quoted 43 lines · Steven Elliott

I'd like to first thank you for creating a very valuable kernel debugging tool. I wish more people knew about UML as a means of learning about how kernels work.

I may be overlooking something, but as far as I can tell it is not currently possible to apply any of the SKAS patches to 2.6.

The host-skas3.patch patch has several conflicts when applied to 2.6. I attempted to manually port host-skas3.patch to 2.6, but I ran into a missing file or function (unfortunately I can remember what it was).

Also, it is not obvious what host-skas-2.6.0-test1.diff should be applied to. It seems to somehow depend on code added by the host-skas3.patch patch, but first applying the host-skas3.patch patch is not sufficient. If someone could regenerate host-skas-2.6.0-test1.diff such that it can be applied to a straight 2.6 kernel that would be very helpful.

Right now I'll assume that there are some technical problems with porting SKAS to 2.6, so it is not just a simple matter of shuffling code from the host-skas3.patch patch to the corresponding place in 2.6.

Also, my experience has been that debugging with GDB works better when SKAS mode is used. So, you might want to mention that in either the SKAS page or the debugging page.

--
-----------------------------------------------------------------------
| Steven Elliott | [email protected] |
-----------------------------------------------------------------------

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#2 lore raw

Alle 10:19, venerdì 16 aprile 2004, Jeff Chua ha scritto:

Quoted 5 lines

It is possible to run SKAS on 2.6. I'm running 2.6.6-rc1-1um SKAS now.

Try the attached patch (00-2.6.6-v0-host-SKAS2.patch.bz2) for 2.6.6-rc1. It's slightly modified from the original 00-2.6.2-v1-host-SKAS2.patch.bz2 patch, which should apply up to 2.6.5.

It applies until 2.6.5, yes, but I posted some time ago a new SKAS patch onto my home page because that one had a bug with SMP hosts, which is fixed in the new one (I have reports that it now works).

Also, that patch applies onto a kernel which has already been UML - patched, while the later version applies onto a vanilla kernel.

There is a separate version which can be applied like the old one, i.e. onto the kernel + UML patch, in the main UML page.

I applied your slight change to this 2nd version and attached the result - test at least if it applies correctly (this one goes onto the UML patch).

Bye and thanks for your update!

Signature · 2 lines
Paolo Giarrusso, aka Blaisorblade
Linux registered user n. 292729
arch/i386/kernel/sys_i386.c renamed from arch/i386/kernel/sys_i386.c.~1~ +6 -6
@@ -40,7 +40,7 @@
 }
 
 /* common code for old and new mmaps */
-static inline long do_mmap2(
+long do_mmap2(struct mm_struct *mm,
 	unsigned long addr, unsigned long len,
 	unsigned long prot, unsigned long flags,
 	unsigned long fd, unsigned long pgoff)
@@ -55,9 +55,9 @@
 			goto out;
 	}
 
-	down_write(&current->mm->mmap_sem);
-	error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
-	up_write(&current->mm->mmap_sem);
+	down_write(&mm->mmap_sem);
+	error = __do_mmap_pgoff(mm, file, addr, len, prot, flags, pgoff);
+	up_write(&mm->mmap_sem);
 
 	if (file)
 		fput(file);
@@ -69,7 +69,7 @@
 	unsigned long prot, unsigned long flags,
 	unsigned long fd, unsigned long pgoff)
 {
-	return do_mmap2(addr, len, prot, flags, fd, pgoff);
+	return do_mmap2(current->mm, addr, len, prot, flags, fd, pgoff);
 }
 
 /*
@@ -100,7 +100,7 @@
 	if (a.offset & ~PAGE_MASK)
 		goto out;
 
-	err = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
+	err = do_mmap2(current->mm, a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
 out:
 	return err;
 }
arch/i386/kernel/ptrace.c renamed from arch/i386/kernel/ptrace.c.~1~ +51 -0

60 lines not on this page · raw message

arch/i386/kernel/ldt.c renamed from arch/i386/kernel/ldt.c.~1~ +21 -13
@@ -54,7 +54,7 @@
 	pc->size = mincount;
 	wmb();
 
-	if (reload) {
+	if (reload && (&current->active_mm->context == pc)) {
 #ifdef CONFIG_SMP
 		cpumask_t mask;
 		preempt_disable();
@@ -89,14 +89,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);
@@ -105,6 +103,11 @@
 	return retval;
 }
 
+int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
+{
+	return __init_new_context(mm, current->mm);
+}
+
 /*
  * No need to lock the MM as we are the last user
  */
@@ -121,11 +124,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;
@@ -169,9 +172,8 @@
 	return err;
 }
 
-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 mm_struct * mm = current->mm;
 	__u32 entry_1, entry_2, *lp;
 	int error;
 	struct user_desc ldt_info;
@@ -195,7 +197,7 @@
 
 	down(&mm->context.sem);
 	if (ldt_info.entry_number >= 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;
 	}
@@ -228,23 +230,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);
+}
arch/i386/Kconfig renamed from arch/i386/Kconfig.~1~ +3 -0
@@ -698,6 +698,9 @@
 	depends on HIGHMEM64G
 	default y
 
+config PROC_MM
+	bool "/proc/mm support"
+
 # Common NUMA Features
 config NUMA
 	bool "Numa Memory Allocation Support"
arch/um/include/skas_ptrace.h renamed from arch/um/include/skas_ptrace.h.~1~ +6 -0
@@ -6,6 +6,10 @@
 #ifndef __SKAS_PTRACE_H
 #define __SKAS_PTRACE_H
 
+
+#ifndef _LINUX_PTRACE_STRUCT_DEF
+#define _LINUX_PTRACE_STRUCT_DEF
+
 struct ptrace_faultinfo {
 	int is_write;
 	unsigned long addr;
@@ -17,6 +21,8 @@
 	unsigned long bytecount;
 };
 
+#endif /*ifndef _LINUX_PTRACE_STRUCT_DEF*/
+
 #define PTRACE_FAULTINFO 52
 #define PTRACE_SIGPENDING 53
 #define PTRACE_LDT 54
arch/um/kernel/ptrace.c renamed from arch/um/kernel/ptrace.c.~1~ +0 -5
@@ -24,11 +24,6 @@
 { 
 }
 
-extern long do_mmap2(struct task_struct *task, unsigned long addr, 
-		     unsigned long len, unsigned long prot, 
-		     unsigned long flags, unsigned long fd,
-		     unsigned long pgoff);
-
 int sys_ptrace(long request, long pid, long addr, long data)
 {
 	struct task_struct *child;
arch/um/kernel/syscall_kern.c renamed from arch/um/kernel/syscall_kern.c.~1~ +1 -1
@@ -81,7 +81,7 @@
 	}
 
 	down_write(&mm->mmap_sem);
-	error = do_mmap_pgoff(mm, file, addr, len, prot, flags, pgoff);
+	error = __do_mmap_pgoff(mm, file, addr, len, prot, flags, pgoff);
 	up_write(&mm->mmap_sem);
 
 	if (file)
include/linux/mm.h renamed from include/linux/mm.h.~1~ +7 -3
@@ -540,10 +540,15 @@
 
 extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
 
-extern unsigned long do_mmap_pgoff(struct mm_struct *mm, struct file *file, 
+extern unsigned long __do_mmap_pgoff(struct mm_struct *mm, struct file *file, 
 				   unsigned long addr, unsigned long len,
 				   unsigned long prot, unsigned long flag,
 				   unsigned long pgoff);
+static inline unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
+	unsigned long len, unsigned long prot,
+	unsigned long flag, unsigned long pgoff) {
+	return __do_mmap_pgoff(current->mm, file, addr, len, prot, flag, pgoff);
+}
 
 static inline unsigned long do_mmap(struct file *file, unsigned long addr,
 	unsigned long len, unsigned long prot,
@@ -553,8 +558,7 @@
 	if ((offset + PAGE_ALIGN(len)) < offset)
 		goto out;
 	if (!(offset & ~PAGE_MASK))
-		ret = do_mmap_pgoff(current->mm, file, addr, len, prot, flag, 
-				    offset >> PAGE_SHIFT);
+		ret = do_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
 out:
 	return ret;
 }
include/asm-i386/desc.h renamed from include/asm-i386/desc.h.~1~ +3 -0
@@ -123,6 +123,9 @@
 	put_cpu();
 }
 
+extern int modify_ldt(struct mm_struct * mm, int func, void __user *ptr,
+		      unsigned long bytecount);
+
 #endif /* !__ASSEMBLY__ */
 
 #endif
include/asm-i386/processor.h renamed from include/asm-i386/processor.h.~1~ +2 -0
@@ -630,4 +630,6 @@
 
 extern void select_idle_routine(const struct cpuinfo_x86 *c);
 
+extern int __init_new_context(struct mm_struct *mm, struct mm_struct *old_mm);
+
 #endif /* __ASM_I386_PROCESSOR_H */
include/asm-i386/ptrace.h renamed from include/asm-i386/ptrace.h.~1~ +22 -0
@@ -59,4 +59,26 @@
 #define instruction_pointer(regs) ((regs)->eip)
 #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
include/asm-i386/mmu_context.h renamed from include/asm-i386/mmu_context.h.~1~ +4 -1
@@ -29,6 +29,10 @@
 {
 	int cpu = smp_processor_id();
 
+#ifdef CONFIG_SMP
+	prev = cpu_tlbstate[cpu].active_mm;
+#endif
+
 	if (likely(prev != next)) {
 		/* stop flush ipis for the previous mm */
 		cpu_clear(cpu, prev->cpu_vm_mask);
@@ -50,7 +54,6 @@
 #ifdef CONFIG_SMP
 	else {
 		cpu_tlbstate[cpu].state = TLBSTATE_OK;
-		BUG_ON(cpu_tlbstate[cpu].active_mm != next);
 
 		if (!cpu_test_and_set(cpu, next->cpu_vm_mask)) {
 			/* We were in lazy tlb mode and leave_mm disabled 
include/asm-um/processor-generic.h renamed from include/asm-um/processor-generic.h.~1~ +2 -2
@@ -101,9 +101,9 @@
 
 extern unsigned long thread_saved_pc(struct task_struct *t);
 
-static inline void mm_copy_segments(struct mm_struct *from_mm, 
-				    struct mm_struct *new_mm)
+static inline int __init_new_context(struct mm_struct *mm, struct mm_struct *old_mm)
 {
+  return 0;
 }
 
 #define init_stack	(init_thread_union.stack)
mm/mmap.c renamed from mm/mmap.c.~1~ +2 -2
@@ -460,7 +460,7 @@
  * The caller must hold down_write(current->mm->mmap_sem).
  */
 
-unsigned long do_mmap_pgoff(struct mm_struct *mm, struct file * file, 
+unsigned long __do_mmap_pgoff(struct mm_struct *mm, struct file * file, 
 			    unsigned long addr, unsigned long len,
 			    unsigned long prot, unsigned long flags,
 			    unsigned long pgoff)
@@ -712,7 +712,7 @@
 	return error;
 }
 
-EXPORT_SYMBOL(do_mmap_pgoff);
+EXPORT_SYMBOL(__do_mmap_pgoff);
 
 /* Get an address range which is currently unmapped.
  * For shmat() with addr=0.
mm/mprotect.c renamed from mm/mprotect.c.~1~ +1 -1
@@ -221,7 +221,7 @@
 	return error;
 }
 
-asmlinkage long
+long
 do_mprotect(struct mm_struct *mm, unsigned long start, size_t len, 
 	     unsigned long prot)
 {
mm/proc_mm.c renamed from mm/proc_mm.c.~1~ +1 -1
@@ -93,7 +93,7 @@
 			break;
 		}
 
-		mm_copy_segments(from, mm);
+		__init_new_context(mm, from);
 		break;
 	}
 	default: