All of lore.kernel.org
 help / color / mirror / Atom feed
* Add private syscalls to support NPTL
@ 2009-08-17 21:48 Maxim Kuvyrkov
  2009-08-17 22:11 ` Andreas Schwab
                   ` (3 more replies)
  0 siblings, 4 replies; 37+ messages in thread
From: Maxim Kuvyrkov @ 2009-08-17 21:48 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Andreas Schwab, linux-m68k

[-- Attachment #1: Type: text/plain, Size: 994 bytes --]

Hello Geert,

The attached patches add kernel support for userspace NPTL bits for m68k.

Since the draft m68k/ColdFire NPTL ABI was posted at 
http://marc.info/?l=linux-m68k&m=119644992713696&w=2 several issues 
surfaced that called for syscall equivalents of the vDSO helpers; the 
main reason for the syscalls is that GLIBC does not support linking in 
vDSO for static binaries.

Another reason is that I'm having problems implementing user-space 
atomic_cmpxchg (for ColdFire) and context switching for user-space TP 
(both m68k and ColdFire).  I've spent quite some time trying to figure 
these two out, but couldn't make everything work reliably.  I'll follow 
up on this in a different thread.

These patches were tested on a ColdFire board running a 2.6.29 kernel, 
and the system passed GLIBC's nptl tests.

The one issue I know of with this patch is that strace needs update to 
pretty print the new [negative] syscalls.

Does the patches look fine?

Thanks,

--
Maxim K.
CodeSourcery

[-- Attachment #2: 0001-Add-syscalls-to-support-m68k-NPTL.patch --]
[-- Type: text/plain, Size: 5581 bytes --]

>From fda8fc4e5706e93f527c2cbc554813f090a1a3fe Mon Sep 17 00:00:00 2001
From: Maxim Kuvyrkov <maxim@codesourcery.com>
Date: Mon, 17 Aug 2009 12:16:36 -0700
Subject: [PATCH 1/2] Add syscalls to support m68k NPTL.

This patch adds several syscalls, private to M68K, that provide necessary
functionality to support NPTL.
The syscalls are read_tp, write_tp, atomic_cmpxchg_32 and atomic_barrier.
The cmpxchg syscall is required for ColdFire as it doesn't support 'cas'
instruction.

Signed-off-by: Maxim Kuvyrkov <maxim@codesourcery.com>
---
 arch/m68k/include/asm/thread_info_mm.h |    1 +
 arch/m68k/include/asm/unistd.h         |    7 +++
 arch/m68k/kernel/entry.S               |   10 ++++-
 arch/m68k/kernel/sys_m68k.c            |   78 ++++++++++++++++++++++++++++++++
 4 files changed, 95 insertions(+), 1 deletions(-)

diff --git a/arch/m68k/include/asm/thread_info_mm.h b/arch/m68k/include/asm/thread_info_mm.h
index 6ea5c33..c24a353 100644
--- a/arch/m68k/include/asm/thread_info_mm.h
+++ b/arch/m68k/include/asm/thread_info_mm.h
@@ -10,6 +10,7 @@ struct thread_info {
 	struct exec_domain	*exec_domain;	/* execution domain */
 	int			preempt_count;	/* 0 => preemptable, <0 => BUG */
 	__u32 cpu; /* should always be 0 on m68k */
+	unsigned long tp_value;
 	struct restart_block    restart_block;
 };
 
diff --git a/arch/m68k/include/asm/unistd.h b/arch/m68k/include/asm/unistd.h
index aa29a86..619677c 100644
--- a/arch/m68k/include/asm/unistd.h
+++ b/arch/m68k/include/asm/unistd.h
@@ -335,9 +335,16 @@
 #define __NR_preadv		329
 #define __NR_pwritev		330
 
+/* Private syscalls.  */
+#define __M68K_NR_read_tp		0xffffffff
+#define __M68K_NR_write_tp		0xfffffffe
+#define __M68K_NR_atomic_cmpxchg_32	0xfffffffd
+#define __M68K_NR_atomic_barrier	0xfffffffc
+
 #ifdef __KERNEL__
 
 #define NR_syscalls		331
+#define M68K_NR_syscalls	0xfffffffb
 
 #define __ARCH_WANT_IPC_PARSE_VERSION
 #define __ARCH_WANT_OLD_READDIR
diff --git a/arch/m68k/kernel/entry.S b/arch/m68k/kernel/entry.S
index 8744f60..fc834d6 100644
--- a/arch/m68k/kernel/entry.S
+++ b/arch/m68k/kernel/entry.S
@@ -86,6 +86,8 @@ do_trace_entry:
 	movel	%sp@(PT_ORIG_D0),%d0
 	cmpl	#NR_syscalls,%d0
 	jcs	syscall
+	cmpl	#M68K_NR_syscalls,%d0
+	jcc	syscall
 badsys:
 	movel	#-ENOSYS,%sp@(PT_D0)
 	jra	ret_from_syscall
@@ -124,7 +126,9 @@ ENTRY(system_call)
 	tstb	%curptr@(TASK_INFO+TINFO_FLAGS+2)
 	jmi	do_trace_entry
 	cmpl	#NR_syscalls,%d0
-	jcc	badsys
+	jcs	syscall
+	cmpl	#M68K_NR_syscalls,%d0
+	jcs	badsys
 syscall:
 	jbsr	@(sys_call_table,%d0:l:4)@(0)
 	movel	%d0,%sp@(PT_D0)		| save the return value
@@ -423,6 +427,10 @@ resume:
 
 .data
 ALIGN
+	.long m68k_sys_atomic_barrier		/* 0xfffffffc */
+	.long m68k_sys_atomic_cmpxchg_32	/* 0xfffffffd */
+	.long m68k_sys_write_tp			/* 0xfffffffe */
+	.long m68k_sys_read_tp			/* 0xffffffff */
 sys_call_table:
 	.long sys_restart_syscall	/* 0 - old "setup()" system call, used for restarting */
 	.long sys_exit
diff --git a/arch/m68k/kernel/sys_m68k.c b/arch/m68k/kernel/sys_m68k.c
index 7f54efa..bc39ce6 100644
--- a/arch/m68k/kernel/sys_m68k.c
+++ b/arch/m68k/kernel/sys_m68k.c
@@ -29,6 +29,8 @@
 #include <asm/traps.h>
 #include <asm/page.h>
 #include <asm/unistd.h>
+#include <linux/elf.h>
+#include <asm/tlb.h>
 
 /* common code for old and new mmaps */
 static inline long do_mmap2(
@@ -663,3 +665,79 @@ int kernel_execve(const char *filename, char *const argv[], char *const envp[])
 			: "d" (__a), "d" (__b), "d" (__c));
 	return __res;
 }
+
+asmlinkage unsigned long
+m68k_sys_read_tp(void)
+{
+	return current_thread_info()->tp_value;
+}
+
+asmlinkage void
+m68k_sys_write_tp(unsigned long tp)
+{
+	current_thread_info()->tp_value = tp;
+}
+
+/* This syscall gets its arguments in A0 (mem), A1 (oldval) and
+   D1 (newval).  */
+asmlinkage int
+m68k_sys_atomic_cmpxchg_32(unsigned long newval, int d2, int d3, int d4, int d5,
+			unsigned long __user *mem, unsigned long oldval)
+{
+	/* This was borrowed from ARM's implementation.  */
+	for(;;) {
+		struct mm_struct *mm = current->mm;
+		pgd_t *pgd; pmd_t *pmd; pte_t *pte;
+		spinlock_t *ptl;
+		unsigned long mem_value;
+
+		down_read(&mm->mmap_sem);
+		pgd = pgd_offset(mm, (unsigned long)mem);
+		if (!pgd_present(*pgd))
+			goto bad_access;
+		pmd = pmd_offset(pgd, (unsigned long)mem);
+		if (!pmd_present(*pmd))
+			goto bad_access;
+		pte = pte_offset_map_lock(mm, pmd, (unsigned long)mem, &ptl);
+		if (!pte_present(*pte) || !pte_dirty(*pte)) {
+			pte_unmap_unlock(pte, ptl);
+			goto bad_access;
+		}
+
+		mem_value = *mem;
+		if (mem_value == oldval)
+			*mem = newval;
+
+		pte_unmap_unlock(pte, ptl);
+		up_read(&mm->mmap_sem);
+		return mem_value;
+
+	bad_access:
+		up_read(&mm->mmap_sem);
+		/* This is not necessarily a bad access, we can get here if
+		   a memory we're trying to write to should be copied-on-write.
+		   Make the kernel do the necessary page stuff, then re-iterate.
+		   Simulate a write access fault to do that.  */
+		{
+			int do_page_fault(struct pt_regs *, unsigned long,
+					unsigned long);
+			/* The first argument of the function corresponds to
+			   D1, which is the first field of struct pt_regs.  */
+			struct pt_regs *fp = (struct pt_regs *)&newval;
+	   
+			/* '3' is an RMW flag.  */
+			if (do_page_fault(fp, (unsigned long)mem, 3))
+				/* If the do_page_fault() failed, we don't
+				   have anything meaningful to return.
+				   There should be a SIGSEGV pending for
+				   the process.  */
+				return 0xdeadbeef;
+		}
+	}
+}
+
+asmlinkage void
+m68k_sys_atomic_barrier(void)
+{
+  /* no code needed for uniprocs */
+}
-- 
1.6.2.4


[-- Attachment #3: 0002-Update-m68k-s-clone_thread.patch --]
[-- Type: text/plain, Size: 961 bytes --]

>From 14291fcace3b39c5302716f0b1972e586d2b991a Mon Sep 17 00:00:00 2001
From: Maxim Kuvyrkov <maxim@codesourcery.com>
Date: Mon, 17 Aug 2009 12:40:56 -0700
Subject: [PATCH 2/2] Update m68k's clone_thread.

This patch adds handling of CLONE_SETTLS flag to m68k's clone_thread.

Signed-off-by: Maxim Kuvyrkov <maxim@codesourcery.com>
---
 arch/m68k/kernel/process.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c
index 72bad65..0d7f9ff 100644
--- a/arch/m68k/kernel/process.c
+++ b/arch/m68k/kernel/process.c
@@ -251,6 +251,10 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
 
 	p->thread.usp = usp;
 	p->thread.ksp = (unsigned long)childstack;
+
+	if (clone_flags & CLONE_SETTLS)
+	  task_thread_info(p)->tp_value = regs->d5;
+
 	/*
 	 * Must save the current SFC/DFC value, NOT the value when
 	 * the parent was last descheduled - RGH  10-08-96
-- 
1.6.2.4


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-08-17 21:48 Add private syscalls to support NPTL Maxim Kuvyrkov
@ 2009-08-17 22:11 ` Andreas Schwab
  2009-08-18  7:15   ` Maxim Kuvyrkov
  2009-08-17 22:18 ` Andreas Schwab
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 37+ messages in thread
From: Andreas Schwab @ 2009-08-17 22:11 UTC (permalink / raw)
  To: Maxim Kuvyrkov; +Cc: Geert Uytterhoeven, linux-m68k

Maxim Kuvyrkov <maxim@codesourcery.com> writes:

> diff --git a/arch/m68k/include/asm/unistd.h b/arch/m68k/include/asm/unistd.h
> index aa29a86..619677c 100644
> --- a/arch/m68k/include/asm/unistd.h
> +++ b/arch/m68k/include/asm/unistd.h
> @@ -335,9 +335,16 @@
>  #define __NR_preadv		329
>  #define __NR_pwritev		330
>  
> +/* Private syscalls.  */
> +#define __M68K_NR_read_tp		0xffffffff
> +#define __M68K_NR_write_tp		0xfffffffe
> +#define __M68K_NR_atomic_cmpxchg_32	0xfffffffd
> +#define __M68K_NR_atomic_barrier	0xfffffffc

I don't see the need for these weird syscall numbers.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-08-17 21:48 Add private syscalls to support NPTL Maxim Kuvyrkov
  2009-08-17 22:11 ` Andreas Schwab
@ 2009-08-17 22:18 ` Andreas Schwab
  2009-08-18  7:10   ` Maxim Kuvyrkov
  2009-08-18  2:28 ` Brad Boyer
  2009-12-07  8:38 ` Maxim Kuvyrkov
  3 siblings, 1 reply; 37+ messages in thread
From: Andreas Schwab @ 2009-08-17 22:18 UTC (permalink / raw)
  To: Maxim Kuvyrkov; +Cc: Geert Uytterhoeven, linux-m68k

Maxim Kuvyrkov <maxim@codesourcery.com> writes:

> +		{
> +			int do_page_fault(struct pt_regs *, unsigned long,
> +					unsigned long);

Functions should always be declared in headers, and definitely never in
block scope.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-08-17 21:48 Add private syscalls to support NPTL Maxim Kuvyrkov
  2009-08-17 22:11 ` Andreas Schwab
  2009-08-17 22:18 ` Andreas Schwab
@ 2009-08-18  2:28 ` Brad Boyer
  2009-08-18  7:07   ` Maxim Kuvyrkov
  2009-12-07  8:38 ` Maxim Kuvyrkov
  3 siblings, 1 reply; 37+ messages in thread
From: Brad Boyer @ 2009-08-18  2:28 UTC (permalink / raw)
  To: Maxim Kuvyrkov; +Cc: Geert Uytterhoeven, Andreas Schwab, linux-m68k

On Tue, Aug 18, 2009 at 01:48:39AM +0400, Maxim Kuvyrkov wrote:
> +/* This syscall gets its arguments in A0 (mem), A1 (oldval) and
> +   D1 (newval).  */
> +asmlinkage int
> +m68k_sys_atomic_cmpxchg_32(unsigned long newval, int d2, int d3, int d4, int d5,
> +			unsigned long __user *mem, unsigned long oldval)
> +{

Any particular reason for this calling convention? The real CAS instruction
specifically takes two data registers for the two values. It seems more
logical to me to have oldval and newval in data registers and just have
the mem argument in an address register.

For reference, here's the syntax summary from the m68k PRM:

CAS Dc, Du, <ea>

	Brad Boyer
	flar@allandria.com


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-08-18  2:28 ` Brad Boyer
@ 2009-08-18  7:07   ` Maxim Kuvyrkov
  2009-08-18 23:40     ` Brad Boyer
  0 siblings, 1 reply; 37+ messages in thread
From: Maxim Kuvyrkov @ 2009-08-18  7:07 UTC (permalink / raw)
  To: Brad Boyer; +Cc: Geert Uytterhoeven, Andreas Schwab, linux-m68k

Brad Boyer wrote:
> On Tue, Aug 18, 2009 at 01:48:39AM +0400, Maxim Kuvyrkov wrote:
>> +/* This syscall gets its arguments in A0 (mem), A1 (oldval) and
>> +   D1 (newval).  */
>> +asmlinkage int
>> +m68k_sys_atomic_cmpxchg_32(unsigned long newval, int d2, int d3, int d4, int d5,
>> +			unsigned long __user *mem, unsigned long oldval)
>> +{
> 
> Any particular reason for this calling convention? The real CAS instruction
> specifically takes two data registers for the two values. It seems more
> logical to me to have oldval and newval in data registers and just have
> the mem argument in an address register.

The reason for this calling convention is to minimize difference in 
invokation of the vDSO helper and the syscall.  The helper gets its 
arguments in a0 (mem), d0 (oldval) and d1 (newval); in a stub, which is 
used when vDSO is not available, one then can do:

movel %d0,%a1
movel #NR,%d0
trap #0

--
Maxim

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-08-17 22:18 ` Andreas Schwab
@ 2009-08-18  7:10   ` Maxim Kuvyrkov
  0 siblings, 0 replies; 37+ messages in thread
From: Maxim Kuvyrkov @ 2009-08-18  7:10 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Geert Uytterhoeven, linux-m68k

Andreas Schwab wrote:
> Maxim Kuvyrkov <maxim@codesourcery.com> writes:
> 
>> +		{
>> +			int do_page_fault(struct pt_regs *, unsigned long,
>> +					unsigned long);
> 
> Functions should always be declared in headers, and definitely never in
> block scope.

I missed that when cleaning up the patch, will follow up with the fix 
once other issues are resolved.

--
Maxim

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-08-17 22:11 ` Andreas Schwab
@ 2009-08-18  7:15   ` Maxim Kuvyrkov
  2009-08-18  8:06     ` Andreas Schwab
  0 siblings, 1 reply; 37+ messages in thread
From: Maxim Kuvyrkov @ 2009-08-18  7:15 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Geert Uytterhoeven, linux-m68k

Andreas Schwab wrote:
> Maxim Kuvyrkov <maxim@codesourcery.com> writes:
> 
>> diff --git a/arch/m68k/include/asm/unistd.h b/arch/m68k/include/asm/unistd.h
>> index aa29a86..619677c 100644
>> --- a/arch/m68k/include/asm/unistd.h
>> +++ b/arch/m68k/include/asm/unistd.h
>> @@ -335,9 +335,16 @@
>>  #define __NR_preadv		329
>>  #define __NR_pwritev		330
>>  
>> +/* Private syscalls.  */
>> +#define __M68K_NR_read_tp		0xffffffff
>> +#define __M68K_NR_write_tp		0xfffffffe
>> +#define __M68K_NR_atomic_cmpxchg_32	0xfffffffd
>> +#define __M68K_NR_atomic_barrier	0xfffffffc
> 
> I don't see the need for these weird syscall numbers.

The need would be (a) use numbers that are very unlikely to used for 
normal syscalls, and (b) using -1..-4 for the syscall numbers works out 
quite nicely for the code in entry.S.  It adds just a couple of 
instructions to the execution path.

Do you think it's better to assign different numbers to the 
m68k-specific syscall?

--
Maxim

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-08-18  7:15   ` Maxim Kuvyrkov
@ 2009-08-18  8:06     ` Andreas Schwab
  2009-08-18  8:56       ` Maxim Kuvyrkov
  0 siblings, 1 reply; 37+ messages in thread
From: Andreas Schwab @ 2009-08-18  8:06 UTC (permalink / raw)
  To: Maxim Kuvyrkov; +Cc: Geert Uytterhoeven, linux-m68k

Maxim Kuvyrkov <maxim@codesourcery.com> writes:

> The need would be (a) use numbers that are very unlikely to used for
> normal syscalls,

I don't understand.  These are normal syscalls.

> and (b) using -1..-4 for the syscall numbers works out quite nicely
> for the code in entry.S.  It adds just a couple of instructions to the
> execution path.

Those additional instructions are totally unnecessary.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-08-18  8:06     ` Andreas Schwab
@ 2009-08-18  8:56       ` Maxim Kuvyrkov
  2009-08-18  9:22         ` Geert Uytterhoeven
  0 siblings, 1 reply; 37+ messages in thread
From: Maxim Kuvyrkov @ 2009-08-18  8:56 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Geert Uytterhoeven, linux-m68k

Andreas Schwab wrote:
> Maxim Kuvyrkov <maxim@codesourcery.com> writes:
> 
>> The need would be (a) use numbers that are very unlikely to used for
>> normal syscalls,
> 
> I don't understand.  These are normal syscalls.
> 
>> and (b) using -1..-4 for the syscall numbers works out quite nicely
>> for the code in entry.S.  It adds just a couple of instructions to the
>> execution path.
> 
> Those additional instructions are totally unnecessary.

Hm, I though it would be preferable to keep syscalls that are specific 
to m68k (in the sense that no other target requires them) separate from 
the ones implementing standard unix/linux functionality.

If the consensus is that the new syscalls should received 331..334 
numbers, that would only simplify the implementation.

--
Maxim

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-08-18  8:56       ` Maxim Kuvyrkov
@ 2009-08-18  9:22         ` Geert Uytterhoeven
  2009-08-18  9:36           ` Maxim Kuvyrkov
                             ` (2 more replies)
  0 siblings, 3 replies; 37+ messages in thread
From: Geert Uytterhoeven @ 2009-08-18  9:22 UTC (permalink / raw)
  To: Maxim Kuvyrkov; +Cc: Andreas Schwab, linux-m68k

On Tue, Aug 18, 2009 at 10:56, Maxim Kuvyrkov<maxim@codesourcery.com> wrote:
> Andreas Schwab wrote:
>> Maxim Kuvyrkov <maxim@codesourcery.com> writes:
>>> The need would be (a) use numbers that are very unlikely to used for
>>> normal syscalls,
>>
>> I don't understand.  These are normal syscalls.
>>
>>> and (b) using -1..-4 for the syscall numbers works out quite nicely
>>> for the code in entry.S.  It adds just a couple of instructions to the
>>> execution path.
>>
>> Those additional instructions are totally unnecessary.
>
> Hm, I though it would be preferable to keep syscalls that are specific to
> m68k (in the sense that no other target requires them) separate from the
> ones implementing standard unix/linux functionality.
>
> If the consensus is that the new syscalls should received 331..334 numbers,
> that would only simplify the implementation.

I prefer to just add them at the bottom of the list.

(slowly recovering from my backlog) I noticed some new syscalls got
added recently:

| <stdin>:1515:2: warning: #warning syscall rt_tgsigqueueinfo not implemented
| <stdin>:1519:2: warning: #warning syscall perf_counter_open not implemented

Probably I should wire those up first (for 2.6.31, if still possible).

Next I should reserve 333..336 for you?

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-m68k" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-08-18  9:22         ` Geert Uytterhoeven
@ 2009-08-18  9:36           ` Maxim Kuvyrkov
  2009-08-18 18:18           ` Andreas Schwab
  2009-08-23 20:21           ` Maxim Kuvyrkov
  2 siblings, 0 replies; 37+ messages in thread
From: Maxim Kuvyrkov @ 2009-08-18  9:36 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Andreas Schwab, linux-m68k

Geert Uytterhoeven wrote:
> On Tue, Aug 18, 2009 at 10:56, Maxim Kuvyrkov<maxim@codesourcery.com> wrote:
>> Andreas Schwab wrote:
>>> Maxim Kuvyrkov <maxim@codesourcery.com> writes:
>>>> The need would be (a) use numbers that are very unlikely to used for
>>>> normal syscalls,
>>> I don't understand.  These are normal syscalls.
>>>
>>>> and (b) using -1..-4 for the syscall numbers works out quite nicely
>>>> for the code in entry.S.  It adds just a couple of instructions to the
>>>> execution path.
>>> Those additional instructions are totally unnecessary.
>> Hm, I though it would be preferable to keep syscalls that are specific to
>> m68k (in the sense that no other target requires them) separate from the
>> ones implementing standard unix/linux functionality.
>>
>> If the consensus is that the new syscalls should received 331..334 numbers,
>> that would only simplify the implementation.
> 
> I prefer to just add them at the bottom of the list.
> 
> (slowly recovering from my backlog) I noticed some new syscalls got
> added recently:
> 
> | <stdin>:1515:2: warning: #warning syscall rt_tgsigqueueinfo not implemented
> | <stdin>:1519:2: warning: #warning syscall perf_counter_open not implemented
> 
> Probably I should wire those up first (for 2.6.31, if still possible).
> 
> Next I should reserve 333..336 for you?

That's fine, thank you.  I'll follow up with an updated patch in couple 
of days.

--
Maxim


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-08-18  9:22         ` Geert Uytterhoeven
  2009-08-18  9:36           ` Maxim Kuvyrkov
@ 2009-08-18 18:18           ` Andreas Schwab
  2009-08-23 20:21           ` Maxim Kuvyrkov
  2 siblings, 0 replies; 37+ messages in thread
From: Andreas Schwab @ 2009-08-18 18:18 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Maxim Kuvyrkov, linux-m68k

Geert Uytterhoeven <geert@linux-m68k.org> writes:

> Probably I should wire those up first (for 2.6.31, if still possible).
>
> Next I should reserve 333..336 for you?

We could even (re-)use some of the smaller numbers that were never
implemented, allowing the use of moveq.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-08-18  7:07   ` Maxim Kuvyrkov
@ 2009-08-18 23:40     ` Brad Boyer
  2009-08-19  8:06       ` Maxim Kuvyrkov
  2009-08-19  8:35       ` Andreas Schwab
  0 siblings, 2 replies; 37+ messages in thread
From: Brad Boyer @ 2009-08-18 23:40 UTC (permalink / raw)
  To: Maxim Kuvyrkov; +Cc: Geert Uytterhoeven, Andreas Schwab, linux-m68k

On Tue, Aug 18, 2009 at 11:07:26AM +0400, Maxim Kuvyrkov wrote:
> Brad Boyer wrote:
> >On Tue, Aug 18, 2009 at 01:48:39AM +0400, Maxim Kuvyrkov wrote:
> >>+/* This syscall gets its arguments in A0 (mem), A1 (oldval) and
> >>+   D1 (newval).  */
> >>+asmlinkage int
> >>+m68k_sys_atomic_cmpxchg_32(unsigned long newval, int d2, int d3, int d4, 
> >>int d5,
> >>+			unsigned long __user *mem, unsigned long oldval)
> >>+{
> >
> >Any particular reason for this calling convention? The real CAS instruction
> >specifically takes two data registers for the two values. It seems more
> >logical to me to have oldval and newval in data registers and just have
> >the mem argument in an address register.
> 
> The reason for this calling convention is to minimize difference in 
> invokation of the vDSO helper and the syscall.  The helper gets its 
> arguments in a0 (mem), d0 (oldval) and d1 (newval); in a stub, which is 
> used when vDSO is not available, one then can do:
> 
> movel %d0,%a1
> movel #NR,%d0
> trap #0

Then wouldn't it make sense to use %d2 instead of %a1?

	Brad Boyer
	flar@allandria.com


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-08-18 23:40     ` Brad Boyer
@ 2009-08-19  8:06       ` Maxim Kuvyrkov
  2009-08-19  8:35       ` Andreas Schwab
  1 sibling, 0 replies; 37+ messages in thread
From: Maxim Kuvyrkov @ 2009-08-19  8:06 UTC (permalink / raw)
  To: Brad Boyer; +Cc: Geert Uytterhoeven, Andreas Schwab, linux-m68k

Brad Boyer wrote:
> On Tue, Aug 18, 2009 at 11:07:26AM +0400, Maxim Kuvyrkov wrote:
>> Brad Boyer wrote:
>>> On Tue, Aug 18, 2009 at 01:48:39AM +0400, Maxim Kuvyrkov wrote:
>>>> +/* This syscall gets its arguments in A0 (mem), A1 (oldval) and
>>>> +   D1 (newval).  */
>>>> +asmlinkage int
>>>> +m68k_sys_atomic_cmpxchg_32(unsigned long newval, int d2, int d3, int d4, 
>>>> int d5,
>>>> +			unsigned long __user *mem, unsigned long oldval)
>>>> +{
>>> Any particular reason for this calling convention? The real CAS instruction
>>> specifically takes two data registers for the two values. It seems more
>>> logical to me to have oldval and newval in data registers and just have
>>> the mem argument in an address register.
>> The reason for this calling convention is to minimize difference in 
>> invokation of the vDSO helper and the syscall.  The helper gets its 
>> arguments in a0 (mem), d0 (oldval) and d1 (newval); in a stub, which is 
>> used when vDSO is not available, one then can do:
>>
>> movel %d0,%a1
>> movel #NR,%d0
>> trap #0
> 
> Then wouldn't it make sense to use %d2 instead of %a1?

Thanks for pointing this out, there's no reason for using %a1 /anymore/. 
  As for the past, %d2 is call-clobbered, so it would've needed saving 
on the stack.

Initially, I planned to argue changing ABI of the vDSO kernel helper to 
allow clobber of %a1, but then decided that it doesn't worth it and that 
it's better to save/restore whatever register a value from %d0 is being 
moved to.

As there's no reasoning for using %a1 anymore, I'll make the syscall 
expect its arguments in %a0(mem), %d1(newval) and %d2(oldval).

--
Maxim K.
CodeSourcery

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-08-18 23:40     ` Brad Boyer
  2009-08-19  8:06       ` Maxim Kuvyrkov
@ 2009-08-19  8:35       ` Andreas Schwab
  1 sibling, 0 replies; 37+ messages in thread
From: Andreas Schwab @ 2009-08-19  8:35 UTC (permalink / raw)
  To: Brad Boyer; +Cc: Maxim Kuvyrkov, Geert Uytterhoeven, linux-m68k

Brad Boyer <flar@allandria.com> writes:

> On Tue, Aug 18, 2009 at 11:07:26AM +0400, Maxim Kuvyrkov wrote:
>> The reason for this calling convention is to minimize difference in 
>> invokation of the vDSO helper and the syscall.  The helper gets its 
>> arguments in a0 (mem), d0 (oldval) and d1 (newval); in a stub, which is 
>> used when vDSO is not available, one then can do:
>> 
>> movel %d0,%a1
>> movel #NR,%d0
>> trap #0
>
> Then wouldn't it make sense to use %d2 instead of %a1?

d2 is a callee-saved register, a1 isn't.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-08-18  9:22         ` Geert Uytterhoeven
  2009-08-18  9:36           ` Maxim Kuvyrkov
  2009-08-18 18:18           ` Andreas Schwab
@ 2009-08-23 20:21           ` Maxim Kuvyrkov
  2009-08-25 19:43             ` Maxim Kuvyrkov
  2 siblings, 1 reply; 37+ messages in thread
From: Maxim Kuvyrkov @ 2009-08-23 20:21 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Andreas Schwab, linux-m68k

[-- Attachment #1: Type: text/plain, Size: 654 bytes --]

Geert Uytterhoeven wrote:

> I prefer to just add them at the bottom of the list.
> 
> (slowly recovering from my backlog) I noticed some new syscalls got
> added recently:
> 
> | <stdin>:1515:2: warning: #warning syscall rt_tgsigqueueinfo not implemented
> | <stdin>:1519:2: warning: #warning syscall perf_counter_open not implemented
> 
> Probably I should wire those up first (for 2.6.31, if still possible).
> 
> Next I should reserve 333..336 for you?

Here is the updated patch.

I moved the declaration of do_page_fault() to the beginning of the file, 
same as another user of this function -- traps.c -- does.

Regards,

--
Maxim K.
CodeSourcery

[-- Attachment #2: 0001-Add-syscalls-to-support-m68k-NPTL.patch --]
[-- Type: text/plain, Size: 4311 bytes --]

From 2e11b258c406cd5cd71b82c39066d9dc35010891 Mon Sep 17 00:00:00 2001
From: Maxim Kuvyrkov <maxim@codesourcery.com>
Date: Mon, 24 Aug 2009 00:10:33 +0400
Subject: [PATCH] Add syscalls to support m68k NPTL.

This patch adds several syscalls, private to M68K, that provide necessary
functionality to support NPTL.
The syscalls are read_tp, write_tp, atomic_cmpxchg_32 and atomic_barrier.
The cmpxchg syscall is required for ColdFire as it doesn't support 'cas'
instruction.

Signed-off-by: Maxim Kuvyrkov <maxim@codesourcery.com>
---
 arch/m68k/include/asm/thread_info_mm.h |    1 +
 arch/m68k/kernel/entry.S               |    4 ++
 arch/m68k/kernel/sys_m68k.c            |   82 ++++++++++++++++++++++++++++++++
 3 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/arch/m68k/include/asm/thread_info_mm.h b/arch/m68k/include/asm/thread_info_mm.h
index af0fda4..a240244 100644
--- a/arch/m68k/include/asm/thread_info_mm.h
+++ b/arch/m68k/include/asm/thread_info_mm.h
@@ -10,6 +10,7 @@ struct thread_info {
 	struct exec_domain	*exec_domain;	/* execution domain */
 	int			preempt_count;	/* 0 => preemptable, <0 => BUG */
 	__u32 cpu; /* should always be 0 on m68k */
+	unsigned long tp_value;
 	struct restart_block    restart_block;
 };
 
diff --git a/arch/m68k/kernel/entry.S b/arch/m68k/kernel/entry.S
index c3735cd..e2a245f 100644
--- a/arch/m68k/kernel/entry.S
+++ b/arch/m68k/kernel/entry.S
@@ -757,4 +757,8 @@ sys_call_table:
 	.long sys_pwritev		/* 330 */
 	.long sys_rt_tgsigqueueinfo
 	.long sys_perf_counter_open
+ 	.long sys_read_tp
+ 	.long sys_write_tp
+ 	.long sys_atomic_cmpxchg_32	/* 335 */
+ 	.long sys_atomic_barrier
 
diff --git a/arch/m68k/kernel/sys_m68k.c b/arch/m68k/kernel/sys_m68k.c
index 7f54efa..03651e5 100644
--- a/arch/m68k/kernel/sys_m68k.c
+++ b/arch/m68k/kernel/sys_m68k.c
@@ -29,6 +29,11 @@
 #include <asm/traps.h>
 #include <asm/page.h>
 #include <asm/unistd.h>
+#include <linux/elf.h>
+#include <asm/tlb.h>
+
+asmlinkage int do_page_fault(struct pt_regs *regs, unsigned long address,
+			unsigned long error_code);
 
 /* common code for old and new mmaps */
 static inline long do_mmap2(
@@ -663,3 +668,80 @@ int kernel_execve(const char *filename, char *const argv[], char *const envp[])
 			: "d" (__a), "d" (__b), "d" (__c));
 	return __res;
 }
+
+asmlinkage unsigned long
+sys_read_tp(void)
+{
+	return current_thread_info()->tp_value;
+}
+
+asmlinkage int
+sys_write_tp(unsigned long tp)
+{
+	current_thread_info()->tp_value = tp;
+	return 0;
+}
+
+/* This syscall gets its arguments in A0 (mem), D2 (oldval) and
+   D1 (newval).  */
+asmlinkage int
+sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3, int d4, int d5,
+		unsigned long __user *mem)
+{
+	struct mm_struct *mm = current->mm;
+
+	/* This was borrowed from ARM's implementation.  */
+	for(;;) {
+		pgd_t *pgd; pmd_t *pmd; pte_t *pte;
+		spinlock_t *ptl;
+		unsigned long mem_value;
+
+		down_read(&mm->mmap_sem);
+		pgd = pgd_offset(mm, (unsigned long)mem);
+		if (!pgd_present(*pgd))
+			goto bad_access;
+		pmd = pmd_offset(pgd, (unsigned long)mem);
+		if (!pmd_present(*pmd))
+			goto bad_access;
+		pte = pte_offset_map_lock(mm, pmd, (unsigned long)mem, &ptl);
+		if (!pte_present(*pte) || !pte_dirty(*pte)) {
+			pte_unmap_unlock(pte, ptl);
+			goto bad_access;
+		}
+
+		mem_value = *mem;
+		if (mem_value == oldval)
+			*mem = newval;
+
+		pte_unmap_unlock(pte, ptl);
+		up_read(&mm->mmap_sem);
+		return mem_value;
+
+	bad_access:
+		up_read(&mm->mmap_sem);
+		/* This is not necessarily a bad access, we can get here if
+		   a memory we're trying to write to should be copied-on-write.
+		   Make the kernel do the necessary page stuff, then re-iterate.
+		   Simulate a write access fault to do that.  */
+		{
+			/* The first argument of the function corresponds to
+			   D1, which is the first field of struct pt_regs.  */
+			struct pt_regs *fp = (struct pt_regs *)&newval;
+	   
+			/* '3' is an RMW flag.  */
+			if (do_page_fault(fp, (unsigned long)mem, 3))
+				/* If the do_page_fault() failed, we don't
+				   have anything meaningful to return.
+				   There should be a SIGSEGV pending for
+				   the process.  */
+				return 0xdeadbeef;
+		}
+	}
+}
+
+asmlinkage int
+sys_atomic_barrier(void)
+{
+	/* no code needed for uniprocs */
+	return 0;
+}
-- 
1.6.4


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-08-23 20:21           ` Maxim Kuvyrkov
@ 2009-08-25 19:43             ` Maxim Kuvyrkov
  2009-08-28 10:51               ` Maxim Kuvyrkov
  0 siblings, 1 reply; 37+ messages in thread
From: Maxim Kuvyrkov @ 2009-08-25 19:43 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Andreas Schwab, linux-m68k

[-- Attachment #1: Type: text/plain, Size: 160 bytes --]

Maxim Kuvyrkov wrote:

> Here is the updated patch.

Hm, I've attached the patch without the unistd.h hunk.  Here is the 
proper one.

--
Maxim K.
CodeSourcery

[-- Attachment #2: 0001-Add-syscalls-to-support-m68k-NPTL.patch --]
[-- Type: text/plain, Size: 4937 bytes --]

From 828160ab5d329e15543a50d0b50ce50f2975966b Mon Sep 17 00:00:00 2001
From: Maxim Kuvyrkov <maxim@codesourcery.com>
Date: Tue, 25 Aug 2009 23:37:26 +0400
Subject: [PATCH] Add syscalls to support m68k NPTL.

This patch adds several syscalls, private to M68K, that provide necessary
functionality to support NPTL.
The syscalls are read_tp, write_tp, atomic_cmpxchg_32 and atomic_barrier.
The cmpxchg syscall is required for ColdFire as it doesn't support 'cas'
instruction.

Signed-off-by: Maxim Kuvyrkov <maxim@codesourcery.com>
---
 arch/m68k/include/asm/thread_info_mm.h |    1 +
 arch/m68k/include/asm/unistd.h         |    6 ++-
 arch/m68k/kernel/entry.S               |    4 ++
 arch/m68k/kernel/sys_m68k.c            |   82 ++++++++++++++++++++++++++++++++
 4 files changed, 92 insertions(+), 1 deletions(-)

diff --git a/arch/m68k/include/asm/thread_info_mm.h b/arch/m68k/include/asm/thread_info_mm.h
index af0fda4..a240244 100644
--- a/arch/m68k/include/asm/thread_info_mm.h
+++ b/arch/m68k/include/asm/thread_info_mm.h
@@ -10,6 +10,7 @@ struct thread_info {
 	struct exec_domain	*exec_domain;	/* execution domain */
 	int			preempt_count;	/* 0 => preemptable, <0 => BUG */
 	__u32 cpu; /* should always be 0 on m68k */
+	unsigned long tp_value;
 	struct restart_block    restart_block;
 };
 
diff --git a/arch/m68k/include/asm/unistd.h b/arch/m68k/include/asm/unistd.h
index 946d869..c035c8b 100644
--- a/arch/m68k/include/asm/unistd.h
+++ b/arch/m68k/include/asm/unistd.h
@@ -336,10 +336,14 @@
 #define __NR_pwritev		330
 #define __NR_rt_tgsigqueueinfo	331
 #define __NR_perf_counter_open	332
+#define __NR_read_tp		333
+#define __NR_write_tp		334
+#define __NR_atomic_cmpxchg_32	335
+#define __NR_atomic_barrier	336
 
 #ifdef __KERNEL__
 
-#define NR_syscalls		333
+#define NR_syscalls		337
 
 #define __ARCH_WANT_IPC_PARSE_VERSION
 #define __ARCH_WANT_OLD_READDIR
diff --git a/arch/m68k/kernel/entry.S b/arch/m68k/kernel/entry.S
index c3735cd..e2a245f 100644
--- a/arch/m68k/kernel/entry.S
+++ b/arch/m68k/kernel/entry.S
@@ -757,4 +757,8 @@ sys_call_table:
 	.long sys_pwritev		/* 330 */
 	.long sys_rt_tgsigqueueinfo
 	.long sys_perf_counter_open
+ 	.long sys_read_tp
+ 	.long sys_write_tp
+ 	.long sys_atomic_cmpxchg_32	/* 335 */
+ 	.long sys_atomic_barrier
 
diff --git a/arch/m68k/kernel/sys_m68k.c b/arch/m68k/kernel/sys_m68k.c
index 7f54efa..03651e5 100644
--- a/arch/m68k/kernel/sys_m68k.c
+++ b/arch/m68k/kernel/sys_m68k.c
@@ -29,6 +29,11 @@
 #include <asm/traps.h>
 #include <asm/page.h>
 #include <asm/unistd.h>
+#include <linux/elf.h>
+#include <asm/tlb.h>
+
+asmlinkage int do_page_fault(struct pt_regs *regs, unsigned long address,
+			unsigned long error_code);
 
 /* common code for old and new mmaps */
 static inline long do_mmap2(
@@ -663,3 +668,80 @@ int kernel_execve(const char *filename, char *const argv[], char *const envp[])
 			: "d" (__a), "d" (__b), "d" (__c));
 	return __res;
 }
+
+asmlinkage unsigned long
+sys_read_tp(void)
+{
+	return current_thread_info()->tp_value;
+}
+
+asmlinkage int
+sys_write_tp(unsigned long tp)
+{
+	current_thread_info()->tp_value = tp;
+	return 0;
+}
+
+/* This syscall gets its arguments in A0 (mem), D2 (oldval) and
+   D1 (newval).  */
+asmlinkage int
+sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3, int d4, int d5,
+		unsigned long __user *mem)
+{
+	struct mm_struct *mm = current->mm;
+
+	/* This was borrowed from ARM's implementation.  */
+	for(;;) {
+		pgd_t *pgd; pmd_t *pmd; pte_t *pte;
+		spinlock_t *ptl;
+		unsigned long mem_value;
+
+		down_read(&mm->mmap_sem);
+		pgd = pgd_offset(mm, (unsigned long)mem);
+		if (!pgd_present(*pgd))
+			goto bad_access;
+		pmd = pmd_offset(pgd, (unsigned long)mem);
+		if (!pmd_present(*pmd))
+			goto bad_access;
+		pte = pte_offset_map_lock(mm, pmd, (unsigned long)mem, &ptl);
+		if (!pte_present(*pte) || !pte_dirty(*pte)) {
+			pte_unmap_unlock(pte, ptl);
+			goto bad_access;
+		}
+
+		mem_value = *mem;
+		if (mem_value == oldval)
+			*mem = newval;
+
+		pte_unmap_unlock(pte, ptl);
+		up_read(&mm->mmap_sem);
+		return mem_value;
+
+	bad_access:
+		up_read(&mm->mmap_sem);
+		/* This is not necessarily a bad access, we can get here if
+		   a memory we're trying to write to should be copied-on-write.
+		   Make the kernel do the necessary page stuff, then re-iterate.
+		   Simulate a write access fault to do that.  */
+		{
+			/* The first argument of the function corresponds to
+			   D1, which is the first field of struct pt_regs.  */
+			struct pt_regs *fp = (struct pt_regs *)&newval;
+	   
+			/* '3' is an RMW flag.  */
+			if (do_page_fault(fp, (unsigned long)mem, 3))
+				/* If the do_page_fault() failed, we don't
+				   have anything meaningful to return.
+				   There should be a SIGSEGV pending for
+				   the process.  */
+				return 0xdeadbeef;
+		}
+	}
+}
+
+asmlinkage int
+sys_atomic_barrier(void)
+{
+	/* no code needed for uniprocs */
+	return 0;
+}
-- 
1.6.4


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-08-25 19:43             ` Maxim Kuvyrkov
@ 2009-08-28 10:51               ` Maxim Kuvyrkov
  2009-10-02  9:59                 ` Maxim Kuvyrkov
  0 siblings, 1 reply; 37+ messages in thread
From: Maxim Kuvyrkov @ 2009-08-28 10:51 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Andreas Schwab, linux-m68k

[-- Attachment #1: Type: text/plain, Size: 442 bytes --]

Maxim Kuvyrkov wrote:
> Maxim Kuvyrkov wrote:
> 
>> Here is the updated patch.
> 
> Hm, I've attached the patch without the unistd.h hunk.  Here is the 
> proper one.

Yet, another update patch.  This version fixes several indentation errors.

BTW, Geert, what is the preferred branch in m68k git repository for 
patches to be sent against?  I looked around and 'for-linus' seems to be 
the most appropriate choice.

--
Maxim K.
CodeSourcery

[-- Attachment #2: 0001-Add-syscalls-to-support-m68k-NPTL.patch --]
[-- Type: text/plain, Size: 5499 bytes --]

From 2d7f5332009cf6bbc4029fb62979d0cd19b2e0d9 Mon Sep 17 00:00:00 2001
From: Maxim Kuvyrkov <maxim@codesourcery.com>
Date: Fri, 28 Aug 2009 14:46:21 +0400
Subject: [PATCH] Add syscalls to support m68k NPTL.

This patch adds several syscalls, that provide necessary
functionality to support NPTL on m68k/ColdFire.
The syscalls are read_tp, write_tp, atomic_cmpxchg_32 and atomic_barrier.
The cmpxchg syscall is required for ColdFire as it doesn't support 'cas'
instruction.

Signed-off-by: Maxim Kuvyrkov <maxim@codesourcery.com>
---
 arch/m68k/include/asm/thread_info_mm.h |    1 +
 arch/m68k/include/asm/unistd.h         |    6 ++-
 arch/m68k/kernel/entry.S               |    4 ++
 arch/m68k/kernel/process.c             |    4 ++
 arch/m68k/kernel/sys_m68k.c            |   82 ++++++++++++++++++++++++++++++++
 5 files changed, 96 insertions(+), 1 deletions(-)

diff --git a/arch/m68k/include/asm/thread_info_mm.h b/arch/m68k/include/asm/thread_info_mm.h
index 6ea5c33..c24a353 100644
--- a/arch/m68k/include/asm/thread_info_mm.h
+++ b/arch/m68k/include/asm/thread_info_mm.h
@@ -10,6 +10,7 @@ struct thread_info {
 	struct exec_domain	*exec_domain;	/* execution domain */
 	int			preempt_count;	/* 0 => preemptable, <0 => BUG */
 	__u32 cpu; /* should always be 0 on m68k */
+	unsigned long tp_value;
 	struct restart_block    restart_block;
 };
 
diff --git a/arch/m68k/include/asm/unistd.h b/arch/m68k/include/asm/unistd.h
index 946d869..c035c8b 100644
--- a/arch/m68k/include/asm/unistd.h
+++ b/arch/m68k/include/asm/unistd.h
@@ -336,10 +336,14 @@
 #define __NR_pwritev		330
 #define __NR_rt_tgsigqueueinfo	331
 #define __NR_perf_counter_open	332
+#define __NR_read_tp		333
+#define __NR_write_tp		334
+#define __NR_atomic_cmpxchg_32	335
+#define __NR_atomic_barrier	336
 
 #ifdef __KERNEL__
 
-#define NR_syscalls		333
+#define NR_syscalls		337
 
 #define __ARCH_WANT_IPC_PARSE_VERSION
 #define __ARCH_WANT_OLD_READDIR
diff --git a/arch/m68k/kernel/entry.S b/arch/m68k/kernel/entry.S
index c3735cd..bd168a1 100644
--- a/arch/m68k/kernel/entry.S
+++ b/arch/m68k/kernel/entry.S
@@ -757,4 +757,8 @@ sys_call_table:
 	.long sys_pwritev		/* 330 */
 	.long sys_rt_tgsigqueueinfo
 	.long sys_perf_counter_open
+	.long sys_read_tp
+	.long sys_write_tp
+	.long sys_atomic_cmpxchg_32	/* 335 */
+	.long sys_atomic_barrier
 
diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c
index 72bad65..2e0ad07 100644
--- a/arch/m68k/kernel/process.c
+++ b/arch/m68k/kernel/process.c
@@ -251,6 +251,10 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
 
 	p->thread.usp = usp;
 	p->thread.ksp = (unsigned long)childstack;
+
+	if (clone_flags & CLONE_SETTLS)
+		task_thread_info(p)->tp_value = regs->d5;
+
 	/*
 	 * Must save the current SFC/DFC value, NOT the value when
 	 * the parent was last descheduled - RGH  10-08-96
diff --git a/arch/m68k/kernel/sys_m68k.c b/arch/m68k/kernel/sys_m68k.c
index 7f54efa..a56c18f 100644
--- a/arch/m68k/kernel/sys_m68k.c
+++ b/arch/m68k/kernel/sys_m68k.c
@@ -29,6 +29,11 @@
 #include <asm/traps.h>
 #include <asm/page.h>
 #include <asm/unistd.h>
+#include <linux/elf.h>
+#include <asm/tlb.h>
+
+asmlinkage int do_page_fault(struct pt_regs *regs, unsigned long address,
+			unsigned long error_code);
 
 /* common code for old and new mmaps */
 static inline long do_mmap2(
@@ -663,3 +668,80 @@ int kernel_execve(const char *filename, char *const argv[], char *const envp[])
 			: "d" (__a), "d" (__b), "d" (__c));
 	return __res;
 }
+
+asmlinkage unsigned long
+sys_read_tp(void)
+{
+	return current_thread_info()->tp_value;
+}
+
+asmlinkage int
+sys_write_tp(unsigned long tp)
+{
+	current_thread_info()->tp_value = tp;
+	return 0;
+}
+
+/* This syscall gets its arguments in A0 (mem), D2 (oldval) and
+   D1 (newval).  */
+asmlinkage int
+sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3, int d4, int d5,
+		unsigned long __user *mem)
+{
+	struct mm_struct *mm = current->mm;
+
+	/* This was borrowed from ARM's implementation.  */
+	for (;;) {
+		pgd_t *pgd; pmd_t *pmd; pte_t *pte;
+		spinlock_t *ptl;
+		unsigned long mem_value;
+
+		down_read(&mm->mmap_sem);
+		pgd = pgd_offset(mm, (unsigned long)mem);
+		if (!pgd_present(*pgd))
+			goto bad_access;
+		pmd = pmd_offset(pgd, (unsigned long)mem);
+		if (!pmd_present(*pmd))
+			goto bad_access;
+		pte = pte_offset_map_lock(mm, pmd, (unsigned long)mem, &ptl);
+		if (!pte_present(*pte) || !pte_dirty(*pte)) {
+			pte_unmap_unlock(pte, ptl);
+			goto bad_access;
+		}
+
+		mem_value = *mem;
+		if (mem_value == oldval)
+			*mem = newval;
+
+		pte_unmap_unlock(pte, ptl);
+		up_read(&mm->mmap_sem);
+		return mem_value;
+
+bad_access:
+		up_read(&mm->mmap_sem);
+		/* This is not necessarily a bad access, we can get here if
+		   a memory we're trying to write to should be copied-on-write.
+		   Make the kernel do the necessary page stuff, then re-iterate.
+		   Simulate a write access fault to do that.  */
+		{
+			/* The first argument of the function corresponds to
+			   D1, which is the first field of struct pt_regs.  */
+			struct pt_regs *fp = (struct pt_regs *)&newval;
+
+			/* '3' is an RMW flag.  */
+			if (do_page_fault(fp, (unsigned long)mem, 3))
+				/* If the do_page_fault() failed, we don't
+				   have anything meaningful to return.
+				   There should be a SIGSEGV pending for
+				   the process.  */
+				return 0xdeadbeef;
+		}
+	}
+}
+
+asmlinkage int
+sys_atomic_barrier(void)
+{
+	/* no code needed for uniprocs */
+	return 0;
+}
-- 
1.6.4


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-08-28 10:51               ` Maxim Kuvyrkov
@ 2009-10-02  9:59                 ` Maxim Kuvyrkov
  2009-10-26 15:01                   ` Maxim Kuvyrkov
  0 siblings, 1 reply; 37+ messages in thread
From: Maxim Kuvyrkov @ 2009-10-02  9:59 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Andreas Schwab, linux-m68k

[-- Attachment #1: Type: text/plain, Size: 934 bytes --]

Maxim Kuvyrkov wrote:
> Maxim Kuvyrkov wrote:
>> Maxim Kuvyrkov wrote:
>>
>>> Here is the updated patch.
>>
>> Hm, I've attached the patch without the unistd.h hunk.  Here is the 
>> proper one.
> 
> Yet, another update patch.  This version fixes several indentation errors.
> 
> BTW, Geert, what is the preferred branch in m68k git repository for 
> patches to be sent against?  I looked around and 'for-linus' seems to be 
> the most appropriate choice.

Yet another update.  The difference compared to the previous patch is 
attached in the first file.

The new version fixes a potential bug in the cmpxchg implementation and 
adds ptrace hook to allow debugging of TLS variables (corresponding 
gdbserver patch is yet to be submitted).

Geert, in case there'll be further changes in the NPTL patch, would you 
like me submit full patch against original tree or only the incremental 
difference?

Thanks,

--
Maxim K.
CodeSourcery

[-- Attachment #2: diff.patch --]
[-- Type: text/plain, Size: 1426 bytes --]

diff --git a/arch/m68k/include/asm/ptrace.h b/arch/m68k/include/asm/ptrace.h
index 8c9194b..6d76bba 100644
--- a/arch/m68k/include/asm/ptrace.h
+++ b/arch/m68k/include/asm/ptrace.h
@@ -71,6 +71,8 @@ struct switch_stack {
 #define PTRACE_GETFPREGS          14
 #define PTRACE_SETFPREGS          15
 
+#define PTRACE_GET_THREAD_AREA    25
+
 #ifdef __KERNEL__
 
 #ifndef PS_S
diff --git a/arch/m68k/kernel/ptrace.c b/arch/m68k/kernel/ptrace.c
index 2075543..0cf7827 100644
--- a/arch/m68k/kernel/ptrace.c
+++ b/arch/m68k/kernel/ptrace.c
@@ -265,6 +265,11 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 			ret = -EFAULT;
 		break;
 
+	case PTRACE_GET_THREAD_AREA:
+		ret = put_user(task_thread_info(child)->tp_value,
+				(unsigned long __user *) data);
+		break;
+
 	default:
 		ret = ptrace_request(child, request, addr, data);
 		break;
diff --git a/arch/m68k/kernel/sys_m68k.c b/arch/m68k/kernel/sys_m68k.c
index a56c18f..c9ad4f9 100644
--- a/arch/m68k/kernel/sys_m68k.c
+++ b/arch/m68k/kernel/sys_m68k.c
@@ -688,10 +688,9 @@ asmlinkage int
 sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3, int d4, int d5,
 		unsigned long __user *mem)
 {
-	struct mm_struct *mm = current->mm;
-
 	/* This was borrowed from ARM's implementation.  */
 	for (;;) {
+		struct mm_struct *mm = current->mm;
 		pgd_t *pgd; pmd_t *pmd; pte_t *pte;
 		spinlock_t *ptl;
 		unsigned long mem_value;

[-- Attachment #3: 0001-Add-NPTL-support-for-m68k.patch --]
[-- Type: text/plain, Size: 6562 bytes --]

From 5e74222fec124ea8d3c6d8b2514c638dc5622a25 Mon Sep 17 00:00:00 2001
From: Maxim Kuvyrkov <maxim@codesourcery.com>
Date: Fri, 28 Aug 2009 14:46:21 +0400
Subject: [PATCH] Add NPTL support for m68k.

This patch adds several syscalls, that provide necessary
functionality to support NPTL on m68k/ColdFire.
The syscalls are read_tp, write_tp, atomic_cmpxchg_32 and atomic_barrier.
The cmpxchg syscall is required for ColdFire as it doesn't support 'cas'
instruction.

Also a ptrace call PTRACE_GET_THREAD_AREA is added to allow debugger to
inspect the TLS storage.

Signed-off-by: Maxim Kuvyrkov <maxim@codesourcery.com>
---
 arch/m68k/include/asm/ptrace.h         |    2 +
 arch/m68k/include/asm/thread_info_mm.h |    1 +
 arch/m68k/include/asm/unistd.h         |    6 ++-
 arch/m68k/kernel/entry.S               |    4 ++
 arch/m68k/kernel/process.c             |    4 ++
 arch/m68k/kernel/ptrace.c              |    5 ++
 arch/m68k/kernel/sys_m68k.c            |   81 ++++++++++++++++++++++++++++++++
 7 files changed, 102 insertions(+), 1 deletions(-)

diff --git a/arch/m68k/include/asm/ptrace.h b/arch/m68k/include/asm/ptrace.h
index 8c9194b..6d76bba 100644
--- a/arch/m68k/include/asm/ptrace.h
+++ b/arch/m68k/include/asm/ptrace.h
@@ -71,6 +71,8 @@ struct switch_stack {
 #define PTRACE_GETFPREGS          14
 #define PTRACE_SETFPREGS          15
 
+#define PTRACE_GET_THREAD_AREA    25
+
 #ifdef __KERNEL__
 
 #ifndef PS_S
diff --git a/arch/m68k/include/asm/thread_info_mm.h b/arch/m68k/include/asm/thread_info_mm.h
index 6ea5c33..c24a353 100644
--- a/arch/m68k/include/asm/thread_info_mm.h
+++ b/arch/m68k/include/asm/thread_info_mm.h
@@ -10,6 +10,7 @@ struct thread_info {
 	struct exec_domain	*exec_domain;	/* execution domain */
 	int			preempt_count;	/* 0 => preemptable, <0 => BUG */
 	__u32 cpu; /* should always be 0 on m68k */
+	unsigned long tp_value;
 	struct restart_block    restart_block;
 };
 
diff --git a/arch/m68k/include/asm/unistd.h b/arch/m68k/include/asm/unistd.h
index 946d869..c035c8b 100644
--- a/arch/m68k/include/asm/unistd.h
+++ b/arch/m68k/include/asm/unistd.h
@@ -336,10 +336,14 @@
 #define __NR_pwritev		330
 #define __NR_rt_tgsigqueueinfo	331
 #define __NR_perf_counter_open	332
+#define __NR_read_tp		333
+#define __NR_write_tp		334
+#define __NR_atomic_cmpxchg_32	335
+#define __NR_atomic_barrier	336
 
 #ifdef __KERNEL__
 
-#define NR_syscalls		333
+#define NR_syscalls		337
 
 #define __ARCH_WANT_IPC_PARSE_VERSION
 #define __ARCH_WANT_OLD_READDIR
diff --git a/arch/m68k/kernel/entry.S b/arch/m68k/kernel/entry.S
index c3735cd..bd168a1 100644
--- a/arch/m68k/kernel/entry.S
+++ b/arch/m68k/kernel/entry.S
@@ -757,4 +757,8 @@ sys_call_table:
 	.long sys_pwritev		/* 330 */
 	.long sys_rt_tgsigqueueinfo
 	.long sys_perf_counter_open
+	.long sys_read_tp
+	.long sys_write_tp
+	.long sys_atomic_cmpxchg_32	/* 335 */
+	.long sys_atomic_barrier
 
diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c
index 72bad65..2e0ad07 100644
--- a/arch/m68k/kernel/process.c
+++ b/arch/m68k/kernel/process.c
@@ -251,6 +251,10 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
 
 	p->thread.usp = usp;
 	p->thread.ksp = (unsigned long)childstack;
+
+	if (clone_flags & CLONE_SETTLS)
+		task_thread_info(p)->tp_value = regs->d5;
+
 	/*
 	 * Must save the current SFC/DFC value, NOT the value when
 	 * the parent was last descheduled - RGH  10-08-96
diff --git a/arch/m68k/kernel/ptrace.c b/arch/m68k/kernel/ptrace.c
index 2075543..0cf7827 100644
--- a/arch/m68k/kernel/ptrace.c
+++ b/arch/m68k/kernel/ptrace.c
@@ -265,6 +265,11 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 			ret = -EFAULT;
 		break;
 
+	case PTRACE_GET_THREAD_AREA:
+		ret = put_user(task_thread_info(child)->tp_value,
+				(unsigned long __user *) data);
+		break;
+
 	default:
 		ret = ptrace_request(child, request, addr, data);
 		break;
diff --git a/arch/m68k/kernel/sys_m68k.c b/arch/m68k/kernel/sys_m68k.c
index 7f54efa..c9ad4f9 100644
--- a/arch/m68k/kernel/sys_m68k.c
+++ b/arch/m68k/kernel/sys_m68k.c
@@ -29,6 +29,11 @@
 #include <asm/traps.h>
 #include <asm/page.h>
 #include <asm/unistd.h>
+#include <linux/elf.h>
+#include <asm/tlb.h>
+
+asmlinkage int do_page_fault(struct pt_regs *regs, unsigned long address,
+			unsigned long error_code);
 
 /* common code for old and new mmaps */
 static inline long do_mmap2(
@@ -663,3 +668,79 @@ int kernel_execve(const char *filename, char *const argv[], char *const envp[])
 			: "d" (__a), "d" (__b), "d" (__c));
 	return __res;
 }
+
+asmlinkage unsigned long
+sys_read_tp(void)
+{
+	return current_thread_info()->tp_value;
+}
+
+asmlinkage int
+sys_write_tp(unsigned long tp)
+{
+	current_thread_info()->tp_value = tp;
+	return 0;
+}
+
+/* This syscall gets its arguments in A0 (mem), D2 (oldval) and
+   D1 (newval).  */
+asmlinkage int
+sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3, int d4, int d5,
+		unsigned long __user *mem)
+{
+	/* This was borrowed from ARM's implementation.  */
+	for (;;) {
+		struct mm_struct *mm = current->mm;
+		pgd_t *pgd; pmd_t *pmd; pte_t *pte;
+		spinlock_t *ptl;
+		unsigned long mem_value;
+
+		down_read(&mm->mmap_sem);
+		pgd = pgd_offset(mm, (unsigned long)mem);
+		if (!pgd_present(*pgd))
+			goto bad_access;
+		pmd = pmd_offset(pgd, (unsigned long)mem);
+		if (!pmd_present(*pmd))
+			goto bad_access;
+		pte = pte_offset_map_lock(mm, pmd, (unsigned long)mem, &ptl);
+		if (!pte_present(*pte) || !pte_dirty(*pte)) {
+			pte_unmap_unlock(pte, ptl);
+			goto bad_access;
+		}
+
+		mem_value = *mem;
+		if (mem_value == oldval)
+			*mem = newval;
+
+		pte_unmap_unlock(pte, ptl);
+		up_read(&mm->mmap_sem);
+		return mem_value;
+
+bad_access:
+		up_read(&mm->mmap_sem);
+		/* This is not necessarily a bad access, we can get here if
+		   a memory we're trying to write to should be copied-on-write.
+		   Make the kernel do the necessary page stuff, then re-iterate.
+		   Simulate a write access fault to do that.  */
+		{
+			/* The first argument of the function corresponds to
+			   D1, which is the first field of struct pt_regs.  */
+			struct pt_regs *fp = (struct pt_regs *)&newval;
+
+			/* '3' is an RMW flag.  */
+			if (do_page_fault(fp, (unsigned long)mem, 3))
+				/* If the do_page_fault() failed, we don't
+				   have anything meaningful to return.
+				   There should be a SIGSEGV pending for
+				   the process.  */
+				return 0xdeadbeef;
+		}
+	}
+}
+
+asmlinkage int
+sys_atomic_barrier(void)
+{
+	/* no code needed for uniprocs */
+	return 0;
+}
-- 
1.6.4


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-10-02  9:59                 ` Maxim Kuvyrkov
@ 2009-10-26 15:01                   ` Maxim Kuvyrkov
  2009-10-28  1:19                     ` Finn Thain
  0 siblings, 1 reply; 37+ messages in thread
From: Maxim Kuvyrkov @ 2009-10-26 15:01 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Andreas Schwab, linux-m68k

Maxim Kuvyrkov wrote:
...
> Geert, in case there'll be further changes in the NPTL patch, would you 
> like me submit full patch against original tree or only the incremental 
> difference?

Ping.

Geert, did you have a chance to look over the patch from Oct. 2 2009?

I've done a lot of testing since then and TLS/NPTL support on 
m68k/ColdFire is now stable enough to have no unexpected failures on 
binutils, gcc, g++, libstdc++ and glibc testsuites.

Thanks,

-- 
Maxim Kuvyrkov
CodeSourcery
maxim@codesourcery.com
(650) 331-3385 x724

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-10-26 15:01                   ` Maxim Kuvyrkov
@ 2009-10-28  1:19                     ` Finn Thain
  2009-10-28  6:54                       ` Maxim Kuvyrkov
  0 siblings, 1 reply; 37+ messages in thread
From: Finn Thain @ 2009-10-28  1:19 UTC (permalink / raw)
  To: Maxim Kuvyrkov; +Cc: Geert Uytterhoeven, Andreas Schwab, linux-m68k



On Mon, 26 Oct 2009, Maxim Kuvyrkov wrote:

> Maxim Kuvyrkov wrote:
> ...
> > Geert, in case there'll be further changes in the NPTL patch, would 
> > you like me submit full patch against original tree or only the 
> > incremental difference?
> 
> Ping.
> 
> Geert, did you have a chance to look over the patch from Oct. 2 2009?
> 
> I've done a lot of testing since then and TLS/NPTL support on 
> m68k/ColdFire is now stable enough to have no unexpected failures on 
> binutils, gcc, g++, libstdc++ and glibc testsuites.

Nice work. I'm looking forward to eglibc patches so I can build a current 
toolchain.

I suppose you can't really backport to eglibc 2.10 until the siginfo 
question is resolved. It appears from the list traffic that the consensus 
is to adopt the generic struct layout here. Is that the solution that 
you've used in testing? If so, can you send the patches you been testing?

Thanks,

Finn


> 
> Thanks,
> 
> 

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-10-28  1:19                     ` Finn Thain
@ 2009-10-28  6:54                       ` Maxim Kuvyrkov
  2009-10-28 16:38                         ` Finn Thain
  2009-11-06  8:38                         ` Finn Thain
  0 siblings, 2 replies; 37+ messages in thread
From: Maxim Kuvyrkov @ 2009-10-28  6:54 UTC (permalink / raw)
  To: Finn Thain; +Cc: Geert Uytterhoeven, Andreas Schwab, linux-m68k

Finn Thain wrote:
> 
> On Mon, 26 Oct 2009, Maxim Kuvyrkov wrote:
> 
>> Maxim Kuvyrkov wrote:
>> ...
>>> Geert, in case there'll be further changes in the NPTL patch, would 
>>> you like me submit full patch against original tree or only the 
>>> incremental difference?
>> Ping.
>>
>> Geert, did you have a chance to look over the patch from Oct. 2 2009?
>>
>> I've done a lot of testing since then and TLS/NPTL support on 
>> m68k/ColdFire is now stable enough to have no unexpected failures on 
>> binutils, gcc, g++, libstdc++ and glibc testsuites.
> 
> Nice work. I'm looking forward to eglibc patches so I can build a current 
> toolchain.

We [CodeSourcery] have just updated all of our toolchains, and the 
GNU/Linux toolchain is based on EGLIBC 2.10 and has well tested TLS/NPTL 
support.  If you are targeting ColdFire you can simply download the 
toolchain at <http://www.codesourcery.com/sgpp/lite/coldfire>.

> I suppose you can't really backport to eglibc 2.10 until the siginfo 
> question is resolved. It appears from the list traffic that the consensus 
> is to adopt the generic struct layout here. Is that the solution that 
> you've used in testing?

I'm not sure if any parts of the m68k kernel port depend on the custom 
layout of siginfo, so I've only fixed the pieces which I'm sure are 
wrong.  I.e, I've been testing with this 
<http://marc.info/?l=linux-m68k&m=125447365311948&w=2> patch.

> If so, can you send the patches you been testing?

All the patches are in the mailing lists.

The kernel patches are at

http://marc.info/?l=linux-m68k&m=125447760017098&w=2
http://marc.info/?l=linux-m68k&m=125447365311948&w=2

The [E]GLIBC patches are at

[M68K/ColdFire patch 1/n] Update sysdep.h
http://sourceware.org/ml/libc-ports/2009-08/msg00006.html

[M68K/ColdFire patch 2/n] Add CFI information to dl-trampoline.S
http://sourceware.org/ml/libc-ports/2009-08/msg00007.html

[M68K/ColdFire patch 3/n] Update jmpbuf-unwind.h
http://sourceware.org/ml/libc-ports/2009-08/msg00008.html

[M68K/ColdFire patch 4/n] Remove kernel headers
Update by hand to match your kernel

[M68K/ColdFire patch 5/n] Main NPTL patch
http://sourceware.org/ml/libc-ports/2009-10/msg00006.html
http://sourceware.org/ml/libc-ports/2009-10/msg00030.html

[M68K/ColdFire patch 6/n] Add TLS relocations to elf/elf.h
http://sourceware.org/ml/libc-ports/2009-08/msg00012.html
Should I post this one to glibc-alpha@ for the review?

[M68K/ColdFire patch 7/n] Handle libgcc_s.so.2
http://sourceware.org/bugzilla/show_bug.cgi?id=4457

Let me know if you find any particular problems with these patches.

-- 
Maxim Kuvyrkov
CodeSourcery
maxim@codesourcery.com
(650) 331-3385 x724

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-10-28  6:54                       ` Maxim Kuvyrkov
@ 2009-10-28 16:38                         ` Finn Thain
  2009-11-06  8:38                         ` Finn Thain
  1 sibling, 0 replies; 37+ messages in thread
From: Finn Thain @ 2009-10-28 16:38 UTC (permalink / raw)
  To: Maxim Kuvyrkov; +Cc: Geert Uytterhoeven, Andreas Schwab, linux-m68k



On Wed, 28 Oct 2009, Maxim Kuvyrkov wrote:

> Finn Thain wrote:
> > 
> > On Mon, 26 Oct 2009, Maxim Kuvyrkov wrote:
> > 
> > > Maxim Kuvyrkov wrote:
> > > ...
> > > > Geert, in case there'll be further changes in the NPTL patch, 
> > > > would you like me submit full patch against original tree or only 
> > > > the incremental difference?
> > > Ping.
> > > 
> > > Geert, did you have a chance to look over the patch from Oct. 2 
> > > 2009?
> > > 
> > > I've done a lot of testing since then and TLS/NPTL support on 
> > > m68k/ColdFire is now stable enough to have no unexpected failures on 
> > > binutils, gcc, g++, libstdc++ and glibc testsuites.
> > 
> > Nice work. I'm looking forward to eglibc patches so I can build a 
> > current toolchain.
> 
> We [CodeSourcery] have just updated all of our toolchains, and the 
> GNU/Linux toolchain is based on EGLIBC 2.10 and has well tested TLS/NPTL 
> support.  If you are targeting ColdFire you can simply download the 
> toolchain at <http://www.codesourcery.com/sgpp/lite/coldfire>.

At the moment I'm more interested in the m68k toolchain, particularly for 
debian. But thanks for the link, I was unaware of the free download.

> > I suppose you can't really backport to eglibc 2.10 until the siginfo 
> > question is resolved. It appears from the list traffic that the 
> > consensus is to adopt the generic struct layout here. Is that the 
> > solution that you've used in testing?
> 
> I'm not sure if any parts of the m68k kernel port depend on the custom 
> layout of siginfo, so I've only fixed the pieces which I'm sure are 
> wrong.  I.e, I've been testing with this 
> <http://marc.info/?l=linux-m68k&m=125447365311948&w=2> patch.
> 
> > If so, can you send the patches you been testing?
> 
> All the patches are in the mailing lists.
> 
> The kernel patches are at
> 
> http://marc.info/?l=linux-m68k&m=125447760017098&w=2
> http://marc.info/?l=linux-m68k&m=125447365311948&w=2
> 
> The [E]GLIBC patches are at
> 
> [M68K/ColdFire patch 1/n] Update sysdep.h
> http://sourceware.org/ml/libc-ports/2009-08/msg00006.html
> 
> [M68K/ColdFire patch 2/n] Add CFI information to dl-trampoline.S
> http://sourceware.org/ml/libc-ports/2009-08/msg00007.html
> 
> [M68K/ColdFire patch 3/n] Update jmpbuf-unwind.h
> http://sourceware.org/ml/libc-ports/2009-08/msg00008.html
> 
> [M68K/ColdFire patch 4/n] Remove kernel headers
> Update by hand to match your kernel
> 
> [M68K/ColdFire patch 5/n] Main NPTL patch
> http://sourceware.org/ml/libc-ports/2009-10/msg00006.html
> http://sourceware.org/ml/libc-ports/2009-10/msg00030.html
> 
> [M68K/ColdFire patch 6/n] Add TLS relocations to elf/elf.h
> http://sourceware.org/ml/libc-ports/2009-08/msg00012.html
> Should I post this one to glibc-alpha@ for the review?
> 
> [M68K/ColdFire patch 7/n] Handle libgcc_s.so.2
> http://sourceware.org/bugzilla/show_bug.cgi?id=4457
> 
> Let me know if you find any particular problems with these patches.
> 

That's a great help, thanks.

Finn

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-10-28  6:54                       ` Maxim Kuvyrkov
  2009-10-28 16:38                         ` Finn Thain
@ 2009-11-06  8:38                         ` Finn Thain
  2009-11-06  8:59                           ` Maxim Kuvyrkov
  1 sibling, 1 reply; 37+ messages in thread
From: Finn Thain @ 2009-11-06  8:38 UTC (permalink / raw)
  To: Maxim Kuvyrkov; +Cc: Geert Uytterhoeven, Andreas Schwab, linux-m68k, debian-68k

[-- Attachment #1: Type: TEXT/PLAIN, Size: 5335 bytes --]


On Wed, 28 Oct 2009, Maxim Kuvyrkov wrote:

>...
> 
> We [CodeSourcery] have just updated all of our toolchains, and the 
> GNU/Linux toolchain is based on EGLIBC 2.10 and has well tested TLS/NPTL 
> support.  If you are targeting ColdFire you can simply download the 
> toolchain at <http://www.codesourcery.com/sgpp/lite/coldfire>.
> 
> > I suppose you can't really backport to eglibc 2.10 until the siginfo 
> > question is resolved. It appears from the list traffic that the 
> > consensus is to adopt the generic struct layout here. Is that the 
> > solution that you've used in testing?
> 
> I'm not sure if any parts of the m68k kernel port depend on the custom 
> layout of siginfo, so I've only fixed the pieces which I'm sure are 
> wrong.  I.e, I've been testing with this 
> <http://marc.info/?l=linux-m68k&m=125447365311948&w=2> patch.
> 
> > If so, can you send the patches you been testing?
> 
> All the patches are in the mailing lists.
> 
> The kernel patches are at
> 
> http://marc.info/?l=linux-m68k&m=125447760017098&w=2 

For the benefit of anyone playing along at home, I found that the first 
attachment ("patch.diff") is already merged in the second attachment
 of the same message ("0001-Add-NPTL-support-for-m68k.patch").

> http://marc.info/?l=linux-m68k&m=125447365311948&w=2
> 
> The [E]GLIBC patches are at
> 
> [M68K/ColdFire patch 1/n] Update sysdep.h 
> http://sourceware.org/ml/libc-ports/2009-08/msg00006.html
>
> [M68K/ColdFire patch 2/n] Add CFI information to dl-trampoline.S 
> http://sourceware.org/ml/libc-ports/2009-08/msg00007.html
> 
> [M68K/ColdFire patch 3/n] Update jmpbuf-unwind.h 
> http://sourceware.org/ml/libc-ports/2009-08/msg00008.html
> 
> [M68K/ColdFire patch 4/n] Remove kernel headers
> Update by hand to match your kernel

I suppose I don't need to remove or update anything, since I build eglibc 
against fresh new kernel headers, from linux-2.6.31 patched with your TLS 
patches.

> [M68K/ColdFire patch 5/n] Main NPTL patch 
> http://sourceware.org/ml/libc-ports/2009-10/msg00006.html

For the benefit of anyone else attempting this, the first patch in that 
email ("Don't bind rtld's vdso pointers to libc symbols") is merged into 
the second patch in the same email ("Nptl support for m68k/ColdFire").

I did run into a problem with this second patch. It doesn't apply to the 
eglibc_2.10 branch in svn as of yesterday. The following hunk is the 
problem:

--- a/sysdeps/unix/sysv/linux/m68k/Versions
+++ b/sysdeps/unix/sysv/linux/m68k/Versions
@@ -31,5 +31,17 @@ libc {
   }
   GLIBC_2.11 {
     fallocate64;
+    __m68k_read_tp;
+  }
+  GLIBC_PRIVATE {
+    __vdso_atomic_cmpxchg_32; __vdso_atomic_barrier;
+  }
+}
+
+ld {
+  GLIBC_PRIVATE {
+    __rtld___vdso_read_tp;
+    __rtld___vdso_atomic_cmpxchg_32;
+    __rtld___vdso_atomic_barrier;
   }
 }

It appears that another patch is needed, to allow your patch to apply:
  http://sourceware.org/ml/libc-ports/2009-05/msg00028.html
And probably this patch too (I used both):
  http://sourceware.org/ml/libc-hacker/2009-05/msg00003.html

Should I be using any other patches?

> http://sourceware.org/ml/libc-ports/2009-10/msg00030.html
>
> [M68K/ColdFire patch 6/n] Add TLS relocations to elf/elf.h
> http://sourceware.org/ml/libc-ports/2009-08/msg00012.html

(Trap for the uwary: this patch is for eglibc/libc, the others are for 
eglibc/ports.)

> Should I post this one to glibc-alpha@ for the review?
>
> [M68K/ColdFire patch 7/n] Handle libgcc_s.so.2
> http://sourceware.org/bugzilla/show_bug.cgi?id=4457

The two patches attached to that bug are already in the eglibc_2.10 
branch, BTW.

> 
> Let me know if you find any particular problems with these patches.
> 

Using the above patches, I am almost able to compile eglibc_2.10. But 
there is an old build failure (since glibc-2.4 I think) when linking 
libc.so:

/tmp/build/glibc-m68k-linux-gnu-3/libc_pic.os: In function `fchownat': (.text+0x911c2): undefined reference to `__atfct_seterrno'
/tmp/gcc-4.4.1/lib/gcc/m68k-linux-gnu/4.4.1/../../../../m68k-linux-gnu/bin/ld: /tmp/build/glibc-m68k-linux-gnu-3/libc.so: hidden symbol `__atfct_seterrno' isn't defined
/tmp/gcc-4.4.1/lib/gcc/m68k-linux-gnu/4.4.1/../../../../m68k-linux-gnu/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
make[1]: *** [/tmp/build/glibc-m68k-linux-gnu-3/libc.so] Error 1
make[1]: Leaving directory `/tmp/build/glibc-2.10.1'
make: *** [all] Error 2

To try to fix this issue, I've basically copied this patch:
  http://sources.redhat.com/ml/libc-hacker/2006-08/msg00004.html
An m68k version is attached. Can someone have a look at it and tell 
whether this is the correct fix or not?

The end result is that I now have a NPTL/TLS m68k toolchain 
(binutils-2.19.51 and patched gcc-4.4.1). Thank you for making that 
possible. I've not run the test suites yet, but so far it seems to work.

Only, I did find that a statically linked binary (pccardctl) built with 
this toolchain segfaults ("unknown errorSegmentation fault") when run 
under a linux-2.6.31 kernel that lacks your patches. Is this expected?

Etch-m68k seems to run fine with or without the kernel patches. I've CC'd 
the debian-m68k list but I suppose they can't use any of this until both 
the siginfo ABI is resolved and eglibc passes its tests on m68k 
hardware.

Finn

[-- Attachment #2: Type: TEXT/PLAIN, Size: 1942 bytes --]


--- glibc-2.5/ports/sysdeps/unix/sysv/linux/m68k/fchownat.c.orig	2007-09-18 00:25:39.000000000 +1000
+++ glibc-2.5/ports/sysdeps/unix/sysv/linux/m68k/fchownat.c	2007-09-18 00:38:21.000000000 +1000
@@ -40,6 +40,24 @@
 int
 fchownat (int fd, const char *file, uid_t owner, gid_t group, int flag)
 {
+  int result;
+
+#ifdef __NR_fchownat
+# ifndef __ASSUME_ATFCTS
+  if (__have_atfcts >= 0)
+# endif
+    {
+      result = INLINE_SYSCALL (fchownat, 5, fd, file, owner, group, flag);
+# ifndef __ASSUME_ATFCTS
+      if (result == -1 && errno == ENOSYS)
+	__have_atfcts = -1;
+      else
+# endif
+	return result;
+    }
+#endif
+
+#ifndef __ASSUME_ATFCTS
   if (flag & ~AT_SYMLINK_NOFOLLOW)
     {
       __set_errno (EINVAL);
@@ -66,18 +84,17 @@
       file = buf;
     }
 
-  int result;
   INTERNAL_SYSCALL_DECL (err);
 
-#if __ASSUME_32BITUIDS > 0
+# if __ASSUME_32BITUIDS > 0
   if (flag & AT_SYMLINK_NOFOLLOW)
     result = INTERNAL_SYSCALL (lchown32, err, 3, CHECK_STRING (file), owner,
 			       group);
   else
     result = INTERNAL_SYSCALL (chown32, err, 3, CHECK_STRING (file), owner,
 			       group);
-#else
-# ifdef __NR_chown32
+# else
+#  ifdef __NR_chown32
   if (__libc_missing_32bit_uids <= 0)
     {
       if (flag & AT_SYMLINK_NOFOLLOW)
@@ -94,7 +111,7 @@
 
       __libc_missing_32bit_uids = 1;
     }
-# endif /* __NR_chown32 */
+#  endif /* __NR_chown32 */
 
   if (((owner + 1) > (gid_t) ((__kernel_uid_t) -1U))
       || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
@@ -109,7 +126,7 @@
   else
     result = INTERNAL_SYSCALL (chown, err, 3, CHECK_STRING (file), owner,
 			       group);
-#endif
+# endif
 
   if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
     {
@@ -117,6 +134,7 @@
       __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
       result = -1;
     }
+#endif
 
   return result;
 }

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-11-06  8:38                         ` Finn Thain
@ 2009-11-06  8:59                           ` Maxim Kuvyrkov
  2009-11-10  4:07                             ` Finn Thain
  0 siblings, 1 reply; 37+ messages in thread
From: Maxim Kuvyrkov @ 2009-11-06  8:59 UTC (permalink / raw)
  To: Finn Thain; +Cc: Geert Uytterhoeven, Andreas Schwab, linux-m68k, debian-68k

Finn Thain wrote:
> On Wed, 28 Oct 2009, Maxim Kuvyrkov wrote:
> 
>> ...
>>
>> We [CodeSourcery] have just updated all of our toolchains, and the 
>> GNU/Linux toolchain is based on EGLIBC 2.10 and has well tested TLS/NPTL 
>> support.  If you are targeting ColdFire you can simply download the 
>> toolchain at <http://www.codesourcery.com/sgpp/lite/coldfire>.
...
> I did run into a problem with this second patch. It doesn't apply to the 
> eglibc_2.10 branch in svn as of yesterday. The following hunk is the 
> problem:

The patches posted are all against FSF GLIBC, not EGLIBC, so some 
conflicts are expected.
...
> Using the above patches, I am almost able to compile eglibc_2.10. But 
> there is an old build failure (since glibc-2.4 I think) when linking 
> libc.so:
> 
> /tmp/build/glibc-m68k-linux-gnu-3/libc_pic.os: In function `fchownat': (.text+0x911c2): undefined reference to `__atfct_seterrno'
> /tmp/gcc-4.4.1/lib/gcc/m68k-linux-gnu/4.4.1/../../../../m68k-linux-gnu/bin/ld: /tmp/build/glibc-m68k-linux-gnu-3/libc.so: hidden symbol `__atfct_seterrno' isn't defined
> /tmp/gcc-4.4.1/lib/gcc/m68k-linux-gnu/4.4.1/../../../../m68k-linux-gnu/bin/ld: final link failed: Nonrepresentable section on output
> collect2: ld returned 1 exit status
> make[1]: *** [/tmp/build/glibc-m68k-linux-gnu-3/libc.so] Error 1
> make[1]: Leaving directory `/tmp/build/glibc-2.10.1'
> make: *** [all] Error 2
> 
> To try to fix this issue, I've basically copied this patch:
>   http://sources.redhat.com/ml/libc-hacker/2006-08/msg00004.html
> An m68k version is attached. Can someone have a look at it and tell 
> whether this is the correct fix or not?

I don't really know, this is the first time I see this failure.

> The end result is that I now have a NPTL/TLS m68k toolchain 
> (binutils-2.19.51 and patched gcc-4.4.1). Thank you for making that 
> possible. I've not run the test suites yet, but so far it seems to work.
> 
> Only, I did find that a statically linked binary (pccardctl) built with 
> this toolchain segfaults ("unknown errorSegmentation fault") when run 
> under a linux-2.6.31 kernel that lacks your patches. Is this expected?

The binary will certainly not work, but I remember run-time linker 
gracefully exiting with a proper error message when invoked on a system 
with unpatched kernel.  I don't think I tested statically linked 
binaries on such system.

-- 
Maxim Kuvyrkov
CodeSourcery
maxim@codesourcery.com
(650) 331-3385 x724

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-11-06  8:59                           ` Maxim Kuvyrkov
@ 2009-11-10  4:07                             ` Finn Thain
  2009-11-10  4:20                               ` Brad Boyer
  2009-11-10 10:51                               ` Maxim Kuvyrkov
  0 siblings, 2 replies; 37+ messages in thread
From: Finn Thain @ 2009-11-10  4:07 UTC (permalink / raw)
  To: Maxim Kuvyrkov; +Cc: Geert Uytterhoeven, Andreas Schwab, linux-m68k, debian-68k



On Fri, 6 Nov 2009, Maxim Kuvyrkov wrote:

> Finn Thain wrote:
> > On Wed, 28 Oct 2009, Maxim Kuvyrkov wrote:
> > 
> > > ...
> > > 
> > > We [CodeSourcery] have just updated all of our toolchains, and the 
> > > GNU/Linux toolchain is based on EGLIBC 2.10 and has well tested 
> > > TLS/NPTL support.  If you are targeting ColdFire you can simply 
> > > download the toolchain at 
> > > <http://www.codesourcery.com/sgpp/lite/coldfire>.
> ...
> > I did run into a problem with this second patch. It doesn't apply to 
> > the eglibc_2.10 branch in svn as of yesterday. The following hunk is 
> > the problem:
> 
> The patches posted are all against FSF GLIBC, not EGLIBC, so some 
> conflicts are expected. ...

OK. I suppose that means no back-porting of other patches is required.

> > Using the above patches, I am almost able to compile eglibc_2.10. But 
> > there is an old build failure (since glibc-2.4 I think) when linking 
> > libc.so:
> > 
> > /tmp/build/glibc-m68k-linux-gnu-3/libc_pic.os: In function `fchownat':
> > (.text+0x911c2): undefined reference to `__atfct_seterrno'
> > /tmp/gcc-4.4.1/lib/gcc/m68k-linux-gnu/4.4.1/../../../../m68k-linux-gnu/bin/ld:
> > /tmp/build/glibc-m68k-linux-gnu-3/libc.so: hidden symbol `__atfct_seterrno'
> > isn't defined
> > /tmp/gcc-4.4.1/lib/gcc/m68k-linux-gnu/4.4.1/../../../../m68k-linux-gnu/bin/ld:
> > final link failed: Nonrepresentable section on output
> > collect2: ld returned 1 exit status
> > make[1]: *** [/tmp/build/glibc-m68k-linux-gnu-3/libc.so] Error 1
> > make[1]: Leaving directory `/tmp/build/glibc-2.10.1'
> > make: *** [all] Error 2
> > 
> > To try to fix this issue, I've basically copied this patch:
> >   http://sources.redhat.com/ml/libc-hacker/2006-08/msg00004.html 
> > An m68k version is attached. Can someone have a look at it and tell 
> > whether this is the correct fix or not?
> 
> I don't really know, this is the first time I see this failure.

I found out why it happens.

If you build eglibc with "--enable-kernel=2.6.31" it fails as above.
If you omit that option, it works.

Do you think my patch is a reasonable solution? I don't understand it, I 
just copied it from x86 -- "monkey see, monkey do."

I used the eglibc-2.10/EGLIBC.cross-building script to test this. I 
configured eglibc with "--enable-add-ons=ports,nptl" to prevent localedef 
from breaking the configure step. Package versions were binutils-2.19.51, 
gcc-4.4.1 (patched), linux-2.6.31 (patched), eglibc 2_10 branch (patched).

I also tried eglibc trunk but the build failed elsewhere:

../sysdeps/unix/sysv/linux/i386/fcntl.c: In function '__fcntl_nocancel':
../sysdeps/unix/sysv/linux/i386/fcntl.c:133: error: storage size of 'fex' isn't known
../sysdeps/unix/sysv/linux/i386/fcntl.c:134: error: 'F_GETOWN_EX' undeclared (first use in this function)
../sysdeps/unix/sysv/linux/i386/fcntl.c:134: error: (Each undeclared identifier is reported only once
../sysdeps/unix/sysv/linux/i386/fcntl.c:134: error: for each function it appears in.)
../sysdeps/unix/sysv/linux/i386/fcntl.c:136: error: 'F_OWNER_GID' undeclared (first use in this function)
../sysdeps/unix/sysv/linux/i386/fcntl.c:133: warning: unused variable 'fex'
make[2]: *** [/home/fthain/cross-build/m68k/obj/eglibc/io/fcntl.o] Error 1
make[2]: Leaving directory `/home/fthain/cross-build/src/eglibc-trunk-r9191/io'
make[1]: *** [io/subdir_lib] Error 2
make[1]: Leaving directory `/home/fthain/cross-build/src/eglibc-trunk-r9191'
make: *** [all] Error 2

For now I'm content with eglibc-2.10, since that is the version in the 
debian archive.

> 
> > The end result is that I now have a NPTL/TLS m68k toolchain 
> > (binutils-2.19.51 and patched gcc-4.4.1). Thank you for making that 
> > possible. I've not run the test suites yet, but so far it seems to 
> > work.
> > 
> > Only, I did find that a statically linked binary (pccardctl) built 
> > with this toolchain segfaults ("unknown errorSegmentation fault") when 
> > run under a linux-2.6.31 kernel that lacks your patches. Is this 
> > expected?
> 
> The binary will certainly not work,

Right. I see that this is documented in the CodeSourcery G++ Lite m68k 
docs.

Finn

> but I remember run-time linker gracefully exiting with a proper error 
> message when invoked on a system with unpatched kernel.  I don't think I 
> tested statically linked binaries on such system.
> 
> 

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-11-10  4:07                             ` Finn Thain
@ 2009-11-10  4:20                               ` Brad Boyer
  2009-11-10 10:51                               ` Maxim Kuvyrkov
  1 sibling, 0 replies; 37+ messages in thread
From: Brad Boyer @ 2009-11-10  4:20 UTC (permalink / raw)
  To: Finn Thain
  Cc: Maxim Kuvyrkov, Geert Uytterhoeven, Andreas Schwab, linux-m68k,
	debian-68k

On Tue, Nov 10, 2009 at 03:07:28PM +1100, Finn Thain wrote:
> I also tried eglibc trunk but the build failed elsewhere:
> 
> ../sysdeps/unix/sysv/linux/i386/fcntl.c: In function '__fcntl_nocancel':
> ../sysdeps/unix/sysv/linux/i386/fcntl.c:133: error: storage size of 'fex' isn't known
> ../sysdeps/unix/sysv/linux/i386/fcntl.c:134: error: 'F_GETOWN_EX' undeclared (first use in this function)
> ../sysdeps/unix/sysv/linux/i386/fcntl.c:134: error: (Each undeclared identifier is reported only once
> ../sysdeps/unix/sysv/linux/i386/fcntl.c:134: error: for each function it appears in.)
> ../sysdeps/unix/sysv/linux/i386/fcntl.c:136: error: 'F_OWNER_GID' undeclared (first use in this function)
> ../sysdeps/unix/sysv/linux/i386/fcntl.c:133: warning: unused variable 'fex'
> make[2]: *** [/home/fthain/cross-build/m68k/obj/eglibc/io/fcntl.o] Error 1
> make[2]: Leaving directory `/home/fthain/cross-build/src/eglibc-trunk-r9191/io'
> make[1]: *** [io/subdir_lib] Error 2
> make[1]: Leaving directory `/home/fthain/cross-build/src/eglibc-trunk-r9191'
> make: *** [all] Error 2
> 
> For now I'm content with eglibc-2.10, since that is the version in the 
> debian archive.

It looks like this needs a newer version of the kernel headers. That stuff
was added relatively recently:

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=ba0a6c9f6fceed11c6a99e8326f0477fe383e6b5

If I'm reading the dates correctly, this commit wasn't in 2.6.31.

As a side note, there is already a patch floating around to fix that commit,
which apparently broke stuff.

http://patchwork.kernel.org/patch/56568/

	Brad Boyer
	flar@allandria.com

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-11-10  4:07                             ` Finn Thain
  2009-11-10  4:20                               ` Brad Boyer
@ 2009-11-10 10:51                               ` Maxim Kuvyrkov
  2009-11-10 16:11                                 ` Finn Thain
  1 sibling, 1 reply; 37+ messages in thread
From: Maxim Kuvyrkov @ 2009-11-10 10:51 UTC (permalink / raw)
  To: Finn Thain; +Cc: Geert Uytterhoeven, Andreas Schwab, linux-m68k, debian-68k

Finn Thain wrote:
> 
> On Fri, 6 Nov 2009, Maxim Kuvyrkov wrote:
> 
>> Finn Thain wrote:
>>> On Wed, 28 Oct 2009, Maxim Kuvyrkov wrote:
>>>
>>>> ...
>>>>
>>>> We [CodeSourcery] have just updated all of our toolchains, and the 
>>>> GNU/Linux toolchain is based on EGLIBC 2.10 and has well tested 
>>>> TLS/NPTL support.  If you are targeting ColdFire you can simply 
>>>> download the toolchain at 
>>>> <http://www.codesourcery.com/sgpp/lite/coldfire>.
>> ...
>>> I did run into a problem with this second patch. It doesn't apply to 
>>> the eglibc_2.10 branch in svn as of yesterday. The following hunk is 
>>> the problem:
>> The patches posted are all against FSF GLIBC, not EGLIBC, so some 
>> conflicts are expected. ...
> 
> OK. I suppose that means no back-porting of other patches is required.
> 
>>> Using the above patches, I am almost able to compile eglibc_2.10. But 
>>> there is an old build failure (since glibc-2.4 I think) when linking 
>>> libc.so:
>>>
>>> /tmp/build/glibc-m68k-linux-gnu-3/libc_pic.os: In function `fchownat':
>>> (.text+0x911c2): undefined reference to `__atfct_seterrno'
>>> /tmp/gcc-4.4.1/lib/gcc/m68k-linux-gnu/4.4.1/../../../../m68k-linux-gnu/bin/ld:
>>> /tmp/build/glibc-m68k-linux-gnu-3/libc.so: hidden symbol `__atfct_seterrno'
>>> isn't defined
>>> /tmp/gcc-4.4.1/lib/gcc/m68k-linux-gnu/4.4.1/../../../../m68k-linux-gnu/bin/ld:
>>> final link failed: Nonrepresentable section on output
>>> collect2: ld returned 1 exit status
>>> make[1]: *** [/tmp/build/glibc-m68k-linux-gnu-3/libc.so] Error 1
>>> make[1]: Leaving directory `/tmp/build/glibc-2.10.1'
>>> make: *** [all] Error 2
>>>
>>> To try to fix this issue, I've basically copied this patch:
>>>   http://sources.redhat.com/ml/libc-hacker/2006-08/msg00004.html 
>>> An m68k version is attached. Can someone have a look at it and tell 
>>> whether this is the correct fix or not?
>> I don't really know, this is the first time I see this failure.
> 
> I found out why it happens.
> 
> If you build eglibc with "--enable-kernel=2.6.31" it fails as above.
> If you omit that option, it works.
> 
> Do you think my patch is a reasonable solution? I don't understand it, I 
> just copied it from x86 -- "monkey see, monkey do."

I can't spot anything wrong in it.

> 
> I used the eglibc-2.10/EGLIBC.cross-building script to test this. I 
> configured eglibc with "--enable-add-ons=ports,nptl" to prevent localedef 
> from breaking the configure step. Package versions were binutils-2.19.51, 
> gcc-4.4.1 (patched), linux-2.6.31 (patched), eglibc 2_10 branch (patched).

What hardware / emulator do you use to test the result?  I tested all 
the work on ColdFire systems, but I also would like to run some tests on 
a usual m68k.

Regards,

-- 
Maxim Kuvyrkov
CodeSourcery
maxim@codesourcery.com
(650) 331-3385 x724

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-11-10 10:51                               ` Maxim Kuvyrkov
@ 2009-11-10 16:11                                 ` Finn Thain
  0 siblings, 0 replies; 37+ messages in thread
From: Finn Thain @ 2009-11-10 16:11 UTC (permalink / raw)
  To: Maxim Kuvyrkov; +Cc: Geert Uytterhoeven, Andreas Schwab, linux-m68k, debian-68k



On Tue, 10 Nov 2009, Maxim Kuvyrkov wrote:

> Finn Thain wrote:
>
> > 
> > Do you think my patch is a reasonable solution? I don't understand it, I
> > just copied it from x86 -- "monkey see, monkey do."
> 
> I can't spot anything wrong in it.

Thanks for looking it over. I'll send it upstream.

> > 
> > I used the eglibc-2.10/EGLIBC.cross-building script to test this. I 
> > configured eglibc with "--enable-add-ons=ports,nptl" to prevent 
> > localedef from breaking the configure step. Package versions were 
> > binutils-2.19.51, gcc-4.4.1 (patched), linux-2.6.31 (patched), eglibc 
> > 2_10 branch (patched).
> 
> What hardware / emulator do you use to test the result?  I tested all 
> the work on ColdFire systems, but I also would like to run some tests on 
> a usual m68k.

I've been testing on 68040 machines. I've not yet tried the test suites.

The latest random test I did was to build the cross toolchain using 
patched debian sid source packages. Then I copied sshd and its supporting 
libraries etc from an etch-m68k system into the toolchain sysroot, along 
with a few old busybox bits and pieces that I had lying around. I then 
exported the sysroot with NFS and booted that. After some messing around I 
was able to log in with ssh and gather the info below.

So far, so good!

Finn


# cat /proc/cpuinfo 
CPU:            68040
MMU:            68040
FPU:            68040
Clocking:       24.6MHz
BogoMips:       16.43
Calibration:    82176 loops
# cat /proc/version
Linux version 2.6.31.5-mac (fthain@nippy) (gcc version 4.4.1 (GCC) ) #2 Wed Nov 11 00:52:38 EST 2009
# /lib/libc.so.6 
GNU C Library (EGLIBC) stable release version 2.10.1, by Roland McGrath et al.
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.4.1.
Compiled on a Linux >>2.6.31.5<< system on 2009-11-10.
Available extensions:
        crypt add-on version 2.1 by Michael Glad and others
        GNU Libidn by Simon Josefsson
        Native POSIX Threads Library by Ulrich Drepper et al
        Support for some architectures added on, not maintained in glibc core.
        BIND-8.2.3-T5B
For bug reporting instructions, please see:
<http://www.eglibc.org/issues/>.
# cat /proc/649/maps
80000000-80047000 r-xp 00000000 00:0c 84898      /etch-m68k-root/usr/sbin/sshd
80048000-80049000 rw-p 00046000 00:0c 84898      /etch-m68k-root/usr/sbin/sshd
80049000-8006f000 rwxp 00000000 00:00 0          [heap]
c0000000-c0018000 r-xp 00000000 00:0c 115132     /lib/ld-2.10.1.so
c0018000-c0019000 rw-p 00000000 00:00 0 
c0019000-c001a000 r--p 00019000 00:0c 115132     /lib/ld-2.10.1.so
c001a000-c001b000 rw-p 0001a000 00:0c 115132     /lib/ld-2.10.1.so
c001b000-c0022000 r-xp 00000000 00:0c 442806     /usr/local/lib/libwrap.so.0.7.6
c0022000-c0023000 ---p 00007000 00:0c 442806     /usr/local/lib/libwrap.so.0.7.6
c0023000-c0024000 rw-p 00006000 00:0c 442806     /usr/local/lib/libwrap.so.0.7.6
c0024000-c0025000 rw-p 00000000 00:00 0 
c0025000-c002c000 r-xp 00000000 00:0c 442808     /usr/local/lib/libpam.so.0.79
c002c000-c002d000 ---p 00007000 00:0c 442808     /usr/local/lib/libpam.so.0.79
c002d000-c002f000 rw-p 00006000 00:0c 442808     /usr/local/lib/libpam.so.0.79
c002f000-c0030000 rw-p 00000000 00:00 0 
c0030000-c0032000 r-xp 00000000 00:0c 115080     /lib/libdl-2.10.1.so
c0032000-c0033000 ---p 00002000 00:0c 115080     /lib/libdl-2.10.1.so
c0033000-c0034000 r--p 00001000 00:0c 115080     /lib/libdl-2.10.1.so
c0034000-c0035000 rw-p 00002000 00:0c 115080     /lib/libdl-2.10.1.so
c0035000-c0046000 r-xp 00000000 00:0c 442809     /usr/local/lib/libselinux.so.1
c0046000-c0047000 ---p 00011000 00:0c 442809     /usr/local/lib/libselinux.so.1
c0047000-c0048000 rw-p 00010000 00:0c 442809     /usr/local/lib/libselinux.so.1
c0048000-c0049000 rw-p 00000000 00:00 0 
c0049000-c0058000 r-xp 00000000 00:0c 115096     /lib/libresolv-2.10.1.so
c0058000-c005a000 ---p 0000f000 00:0c 115096     /lib/libresolv-2.10.1.so
c005a000-c005b000 r--p 0000f000 00:0c 115096     /lib/libresolv-2.10.1.so
c005b000-c005c000 rw-p 00010000 00:0c 115096     /lib/libresolv-2.10.1.so
c005c000-c005e000 rw-p 00000000 00:00 0 
c005e000-c016b000 r-xp 00000000 00:0c 442810     /usr/local/lib/libcrypto.so.0.9.8
c016b000-c016c000 ---p 0010d000 00:0c 442810     /usr/local/lib/libcrypto.so.0.9.8
c016c000-c0180000 rw-p 0010c000 00:0c 442810     /usr/local/lib/libcrypto.so.0.9.8
c0180000-c0184000 rw-p 00000000 00:00 0 
c0184000-c0186000 r-xp 00000000 00:0c 115130     /lib/libutil-2.10.1.so
c0186000-c0187000 ---p 00002000 00:0c 115130     /lib/libutil-2.10.1.so
c0187000-c0188000 r--p 00001000 00:0c 115130     /lib/libutil-2.10.1.so
c0188000-c0189000 rw-p 00002000 00:0c 115130     /lib/libutil-2.10.1.so
c0189000-c019a000 r-xp 00000000 00:0c 442812     /usr/local/lib/libz.so.1.2.3
c019a000-c019b000 ---p 00011000 00:0c 442812     /usr/local/lib/libz.so.1.2.3
c019b000-c019c000 rw-p 00010000 00:0c 442812     /usr/local/lib/libz.so.1.2.3
c019c000-c019d000 rw-p 00000000 00:00 0 
c019d000-c01af000 r-xp 00000000 00:0c 115120     /lib/libnsl-2.10.1.so
c01af000-c01b0000 ---p 00012000 00:0c 115120     /lib/libnsl-2.10.1.so
c01b0000-c01b1000 r--p 00011000 00:0c 115120     /lib/libnsl-2.10.1.so
c01b1000-c01b2000 rw-p 00012000 00:0c 115120     /lib/libnsl-2.10.1.so
c01b2000-c01b4000 rw-p 00000000 00:00 0 
c01b4000-c01bd000 r-xp 00000000 00:0c 115088     /lib/libcrypt-2.10.1.so
c01bd000-c01bf000 ---p 00009000 00:0c 115088     /lib/libcrypt-2.10.1.so
c01bf000-c01c0000 r--p 00009000 00:0c 115088     /lib/libcrypt-2.10.1.so
c01c0000-c01c1000 rw-p 0000a000 00:0c 115088     /lib/libcrypt-2.10.1.so
c01c1000-c01e8000 rw-p 00000000 00:00 0 
c01e8000-c01ff000 r-xp 00000000 00:0c 442814     /usr/local/lib/libgssapi_krb5.so.2.2
c01ff000-c0200000 ---p 00017000 00:0c 442814     /usr/local/lib/libgssapi_krb5.so.2.2
c0200000-c0201000 rw-p 00016000 00:0c 442814     /usr/local/lib/libgssapi_krb5.so.2.2
c0201000-c0269000 r-xp 00000000 00:0c 442816     /usr/local/lib/libkrb5.so.3.2
c0269000-c026a000 ---p 00068000 00:0c 442816     /usr/local/lib/libkrb5.so.3.2
c026a000-c026d000 rw-p 00067000 00:0c 442816     /usr/local/lib/libkrb5.so.3.2
c026d000-c028d000 r-xp 00000000 00:0c 442822     /usr/local/lib/libk5crypto.so.3.0
c028d000-c028e000 ---p 00020000 00:0c 442822     /usr/local/lib/libk5crypto.so.3.0
c028e000-c0290000 rw-p 0001f000 00:0c 442822     /usr/local/lib/libk5crypto.so.3.0
c0290000-c0292000 r-xp 00000000 00:0c 442818     /usr/local/lib/libcom_err.so.2.1
c0292000-c0293000 ---p 00002000 00:0c 442818     /usr/local/lib/libcom_err.so.2.1
c0293000-c0294000 rw-p 00001000 00:0c 442818     /usr/local/lib/libcom_err.so.2.1
c0294000-c0295000 rw-p 00000000 00:00 0 
c0295000-c0298000 r-xp 00000000 00:0c 442820     /usr/local/lib/libkrb5support.so.0.0
c0298000-c0299000 ---p 00003000 00:0c 442820     /usr/local/lib/libkrb5support.so.0.0
c0299000-c029b000 rw-p 00002000 00:0c 442820     /usr/local/lib/libkrb5support.so.0.0
c029b000-c03b7000 r-xp 00000000 00:0c 114361     /lib/libc-2.10.1.so
c03b7000-c03b9000 r--p 0011c000 00:0c 114361     /lib/libc-2.10.1.so
c03b9000-c03bc000 rw-p 0011e000 00:0c 114361     /lib/libc-2.10.1.so
c03bc000-c03bf000 rw-p 00000000 00:00 0 
c03bf000-c03f1000 r-xp 00000000 00:0c 442823     /usr/local/lib/libsepol.so.1
c03f1000-c03f2000 ---p 00032000 00:0c 442823     /usr/local/lib/libsepol.so.1
c03f2000-c03f4000 rw-p 00031000 00:0c 442823     /usr/local/lib/libsepol.so.1
c03f4000-c0401000 rw-p 00000000 00:00 0 
c0401000-c0407000 r-xp 00000000 00:0c 115126     /lib/libnss_compat-2.10.1.so
c0407000-c0408000 ---p 00006000 00:0c 115126     /lib/libnss_compat-2.10.1.so
c0408000-c0409000 r--p 00005000 00:0c 115126     /lib/libnss_compat-2.10.1.so
c0409000-c040a000 rw-p 00006000 00:0c 115126     /lib/libnss_compat-2.10.1.so
c040a000-c0412000 r-xp 00000000 00:0c 115122     /lib/libnss_nis-2.10.1.so
c0412000-c0413000 ---p 00008000 00:0c 115122     /lib/libnss_nis-2.10.1.so
c0413000-c0414000 r--p 00007000 00:0c 115122     /lib/libnss_nis-2.10.1.so
c0414000-c0415000 rw-p 00008000 00:0c 115122     /lib/libnss_nis-2.10.1.so
c0415000-c041e000 r-xp 00000000 00:0c 115108     /lib/libnss_files-2.10.1.so
c041e000-c0420000 ---p 00009000 00:0c 115108     /lib/libnss_files-2.10.1.so
c0420000-c0421000 r--p 00009000 00:0c 115108     /lib/libnss_files-2.10.1.so
c0421000-c0422000 rw-p 0000a000 00:0c 115108     /lib/libnss_files-2.10.1.so
efcb7000-efccc000 rw-p 00000000 00:00 0          [stack]

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-08-17 21:48 Add private syscalls to support NPTL Maxim Kuvyrkov
                   ` (2 preceding siblings ...)
  2009-08-18  2:28 ` Brad Boyer
@ 2009-12-07  8:38 ` Maxim Kuvyrkov
  2009-12-09 10:25   ` Klaus Kuehnhammer
  2009-12-11 14:01   ` Geert Uytterhoeven
  3 siblings, 2 replies; 37+ messages in thread
From: Maxim Kuvyrkov @ 2009-12-07  8:38 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Andreas Schwab, linux-m68k

[-- Attachment #1: Type: text/plain, Size: 472 bytes --]

Maxim Kuvyrkov wrote:
> Hello Geert,
> 
> The attached patches add kernel support for userspace NPTL bits for m68k.

Here is yet another final version of the patch.  As Andreas pointed out 
in another thread, the indentation is off in couple of places, so I 
fixed that by formatting the code with scripts/Lindent.  I also 
forwarded the reformatted version of the uClinux patch to uclinux-dev@.

-- 
Maxim Kuvyrkov
CodeSourcery
maxim@codesourcery.com
(650) 331-3385 x724

[-- Attachment #2: 0001-Add-NPTL-support-for-m68k.patch --]
[-- Type: text/plain, Size: 6673 bytes --]

>From 571248e741ab66392ec0296f4662f3e893a9d105 Mon Sep 17 00:00:00 2001
From: Maxim Kuvyrkov <maxim@codesourcery.com>
Date: Mon, 7 Dec 2009 00:24:27 -0800
Subject: [PATCH 1/2] Add NPTL support for m68k

This patch adds several syscalls, that provide necessary
functionality to support NPTL on m68k/ColdFire.
The syscalls are read_tp, write_tp, atomic_cmpxchg_32 and atomic_barrier.
The cmpxchg syscall is required for ColdFire as it doesn't support 'cas'
instruction.

Also a ptrace call PTRACE_GET_THREAD_AREA is added to allow debugger to
inspect the TLS storage.

Signed-off-by: Maxim Kuvyrkov <maxim@codesourcery.com>
---
 arch/m68k/include/asm/ptrace.h         |    2 +
 arch/m68k/include/asm/thread_info_mm.h |    1 +
 arch/m68k/include/asm/unistd.h         |    6 ++-
 arch/m68k/kernel/entry.S               |    4 ++
 arch/m68k/kernel/process.c             |    4 ++
 arch/m68k/kernel/ptrace.c              |    5 ++
 arch/m68k/kernel/sys_m68k.c            |   80 ++++++++++++++++++++++++++++++++
 7 files changed, 101 insertions(+), 1 deletions(-)

diff --git a/arch/m68k/include/asm/ptrace.h b/arch/m68k/include/asm/ptrace.h
index a6ab663..43ab86a 100644
--- a/arch/m68k/include/asm/ptrace.h
+++ b/arch/m68k/include/asm/ptrace.h
@@ -71,6 +71,8 @@ struct switch_stack {
 #define PTRACE_GETFPREGS          14
 #define PTRACE_SETFPREGS          15
 
+#define PTRACE_GET_THREAD_AREA    25
+
 #define PTRACE_SINGLEBLOCK	33	/* resume execution until next branch */
 
 #ifdef __KERNEL__
diff --git a/arch/m68k/include/asm/thread_info_mm.h b/arch/m68k/include/asm/thread_info_mm.h
index 167e518..67c2f7b 100644
--- a/arch/m68k/include/asm/thread_info_mm.h
+++ b/arch/m68k/include/asm/thread_info_mm.h
@@ -16,6 +16,7 @@ struct thread_info {
 	struct exec_domain	*exec_domain;	/* execution domain */
 	int			preempt_count;	/* 0 => preemptable, <0 => BUG */
 	__u32 cpu; /* should always be 0 on m68k */
+	unsigned long tp_value;
 	struct restart_block    restart_block;
 };
 #endif /* __ASSEMBLY__ */
diff --git a/arch/m68k/include/asm/unistd.h b/arch/m68k/include/asm/unistd.h
index 48b87f5..d076bea 100644
--- a/arch/m68k/include/asm/unistd.h
+++ b/arch/m68k/include/asm/unistd.h
@@ -336,10 +336,14 @@
 #define __NR_pwritev		330
 #define __NR_rt_tgsigqueueinfo	331
 #define __NR_perf_event_open	332
+#define __NR_read_tp		333
+#define __NR_write_tp		334
+#define __NR_atomic_cmpxchg_32	335
+#define __NR_atomic_barrier	336
 
 #ifdef __KERNEL__
 
-#define NR_syscalls		333
+#define NR_syscalls		337
 
 #define __ARCH_WANT_IPC_PARSE_VERSION
 #define __ARCH_WANT_OLD_READDIR
diff --git a/arch/m68k/kernel/entry.S b/arch/m68k/kernel/entry.S
index 77fc7c1..4238ac3 100644
--- a/arch/m68k/kernel/entry.S
+++ b/arch/m68k/kernel/entry.S
@@ -761,4 +761,8 @@ sys_call_table:
 	.long sys_pwritev		/* 330 */
 	.long sys_rt_tgsigqueueinfo
 	.long sys_perf_event_open
+	.long sys_read_tp
+	.long sys_write_tp
+	.long sys_atomic_cmpxchg_32	/* 335 */
+	.long sys_atomic_barrier
 
diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c
index 0529659..17c3f32 100644
--- a/arch/m68k/kernel/process.c
+++ b/arch/m68k/kernel/process.c
@@ -251,6 +251,10 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
 
 	p->thread.usp = usp;
 	p->thread.ksp = (unsigned long)childstack;
+
+	if (clone_flags & CLONE_SETTLS)
+		task_thread_info(p)->tp_value = regs->d5;
+
 	/*
 	 * Must save the current SFC/DFC value, NOT the value when
 	 * the parent was last descheduled - RGH  10-08-96
diff --git a/arch/m68k/kernel/ptrace.c b/arch/m68k/kernel/ptrace.c
index 1fc217e..616e597 100644
--- a/arch/m68k/kernel/ptrace.c
+++ b/arch/m68k/kernel/ptrace.c
@@ -245,6 +245,11 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 			ret = -EFAULT;
 		break;
 
+	case PTRACE_GET_THREAD_AREA:
+		ret = put_user(task_thread_info(child)->tp_value,
+			       (unsigned long __user *)data);
+		break;
+
 	default:
 		ret = ptrace_request(child, request, addr, data);
 		break;
diff --git a/arch/m68k/kernel/sys_m68k.c b/arch/m68k/kernel/sys_m68k.c
index 7deb402..69b5f38 100644
--- a/arch/m68k/kernel/sys_m68k.c
+++ b/arch/m68k/kernel/sys_m68k.c
@@ -28,6 +28,11 @@
 #include <asm/traps.h>
 #include <asm/page.h>
 #include <asm/unistd.h>
+#include <linux/elf.h>
+#include <asm/tlb.h>
+
+asmlinkage int do_page_fault(struct pt_regs *regs, unsigned long address,
+			     unsigned long error_code);
 
 /* common code for old and new mmaps */
 static inline long do_mmap2(
@@ -662,3 +667,78 @@ int kernel_execve(const char *filename, char *const argv[], char *const envp[])
 			: "d" (__a), "d" (__b), "d" (__c));
 	return __res;
 }
+
+asmlinkage unsigned long sys_read_tp(void)
+{
+	return current_thread_info()->tp_value;
+}
+
+asmlinkage int sys_write_tp(unsigned long tp)
+{
+	current_thread_info()->tp_value = tp;
+	return 0;
+}
+
+/* This syscall gets its arguments in A0 (mem), D2 (oldval) and
+   D1 (newval).  */
+asmlinkage int
+sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3, int d4, int d5,
+		      unsigned long __user * mem)
+{
+	/* This was borrowed from ARM's implementation.  */
+	for (;;) {
+		struct mm_struct *mm = current->mm;
+		pgd_t *pgd;
+		pmd_t *pmd;
+		pte_t *pte;
+		spinlock_t *ptl;
+		unsigned long mem_value;
+
+		down_read(&mm->mmap_sem);
+		pgd = pgd_offset(mm, (unsigned long)mem);
+		if (!pgd_present(*pgd))
+			goto bad_access;
+		pmd = pmd_offset(pgd, (unsigned long)mem);
+		if (!pmd_present(*pmd))
+			goto bad_access;
+		pte = pte_offset_map_lock(mm, pmd, (unsigned long)mem, &ptl);
+		if (!pte_present(*pte) || !pte_dirty(*pte)) {
+			pte_unmap_unlock(pte, ptl);
+			goto bad_access;
+		}
+
+		mem_value = *mem;
+		if (mem_value == oldval)
+			*mem = newval;
+
+		pte_unmap_unlock(pte, ptl);
+		up_read(&mm->mmap_sem);
+		return mem_value;
+
+	      bad_access:
+		up_read(&mm->mmap_sem);
+		/* This is not necessarily a bad access, we can get here if
+		   a memory we're trying to write to should be copied-on-write.
+		   Make the kernel do the necessary page stuff, then re-iterate.
+		   Simulate a write access fault to do that.  */
+		{
+			/* The first argument of the function corresponds to
+			   D1, which is the first field of struct pt_regs.  */
+			struct pt_regs *fp = (struct pt_regs *)&newval;
+
+			/* '3' is an RMW flag.  */
+			if (do_page_fault(fp, (unsigned long)mem, 3))
+				/* If the do_page_fault() failed, we don't
+				   have anything meaningful to return.
+				   There should be a SIGSEGV pending for
+				   the process.  */
+				return 0xdeadbeef;
+		}
+	}
+}
+
+asmlinkage int sys_atomic_barrier(void)
+{
+	/* no code needed for uniprocs */
+	return 0;
+}
-- 
1.6.2.4


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-12-07  8:38 ` Maxim Kuvyrkov
@ 2009-12-09 10:25   ` Klaus Kuehnhammer
  2009-12-09 11:05     ` Maxim Kuvyrkov
  2009-12-11 14:01   ` Geert Uytterhoeven
  1 sibling, 1 reply; 37+ messages in thread
From: Klaus Kuehnhammer @ 2009-12-09 10:25 UTC (permalink / raw)
  To: linux-m68k, Maxim Kuvyrkov

Hi!

I've been testing this patch (together w/the latest codesourcery toolchain release) on an m548x the last couple of days.

It looks like there is still an issue in sys_atomic_cmpxchg_32. When cloning a large process, it accesses memory it shouldn't:


cmpxchg32: new 1, old 0, mem 801cb604
cmpxchg32: new 2, old 1, mem 807f2404
cmpxchg32: new 1, old 0, mem 807f15b8
cmpxchg32: new 0, old 1, mem 801cb604
cmpxchg32: new 0, old 1, mem 801cb604
cmpxchg32: new 1, old 0, mem 801cb604
cmpxchg32: new 0, old 1, mem 801cb604
cmpxchg32: new 1, old 0, mem 801cb604
cmpxchg32: new 1, old 0, mem 801cbc7c
cmpxchg32: new 0, old 1, mem 801cb604
cmpxchg32: new 0, old 1, mem 801cbc7c
cmpxchg32: new 0, old 1, mem 807f15b8
cmpxchg32: new 1, old 0, mem 801cb5e0
cmpxchg32: new 0, old 1, mem 801cb5e0
cmpxchg32: new 1, old 0, mem 801cb604
cmpxchg32: new 1, old 2, mem 807f2404
cmpxchg32: new 1, old 0, mem 801cb5ec
cmpxchg32: new 0, old 1, mem 801cb604
Unable to handle kernel access at virtual address 807f2404
Oops: 00000000
PC: [<00021e50>]<0>
SR: 2004  SP: 031ebf54  a2: 0321c920
d0: 03ac7411    d1: 0315877c    d2: 807f2404    d3: 00000002
d4: 000007e4    d5: 00000002    a0: 807f2404    a1: 0004f020
Process dapper (pid: 334, stackpage=0321e920)
Stack from 031ebf54:
       <0> 0315877c<0> 807f2404<0> 00000002<0> 000007e4<0> 00000002<0> 807f2404<0> 0004f020<0> 0321c920
       <0> 03ac7411<0> ffffffff<0> 00000000<0> 807f2404<0> 0000000a<0> 48092004<0> 00021e50<0> 00000002
       <0> 00000000<0> 80822278<0> 00000155<0> 00000002<0> 0000014e<0> 807f23f0<0> 806db658<0> 807ef2dc
       <0> 01832000<0> 03158778<0> bf94fbec<0> 00023d2e<0> 00000001<0> 00000002<0> 00000000<0> 80822278
       <0> 00000155<0> 807f2404<0> 807f2404<0> bf94fbac<0> 0000014f<0> 0000014f<0> 00000000<0> 807ef2f8
       <0> 00000000<0> 40800000<0> 806db664

System.map:
00021d70 T sys_read_tp
00021d7c T sys_write_tp
00021d8c T sys_atomic_barrier
00021d96 T sys_atomic_cmpxchg_32
00021e92 T sys_cacheflush
00021fdc T sys_ipc

I'm not sure why the page table calls that precede the *mem don't catch the forbidden access. Could the relevant TLB get replaced?

This happens every time one of our applications calls popen(). In smaller apps, popen works fine.. I'm currently trying to create a test app that reproduces this, will send that as soon as it's done. It looks like the difference is the amount of libraries the calling application is linked against, and/or stack usage.

I'll happily provide any additional debug info to help track this down.
best regards,
Klaus

On 07.12.2009, at 09:38, Maxim Kuvyrkov wrote:

> Maxim Kuvyrkov wrote:
>> Hello Geert,
>> The attached patches add kernel support for userspace NPTL bits for m68k.
> 
> Here is yet another final version of the patch.  As Andreas pointed out in another thread, the indentation is off in couple of places, so I fixed that by formatting the code with scripts/Lindent.  I also forwarded the reformatted version of the uClinux patch to uclinux-dev@.
> 
> -- 
> Maxim Kuvyrkov
> CodeSourcery
> maxim@codesourcery.com
> (650) 331-3385 x724
>> From 571248e741ab66392ec0296f4662f3e893a9d105 Mon Sep 17 00:00:00 2001
> From: Maxim Kuvyrkov <maxim@codesourcery.com>
> Date: Mon, 7 Dec 2009 00:24:27 -0800
> Subject: [PATCH 1/2] Add NPTL support for m68k
> 
> This patch adds several syscalls, that provide necessary
> functionality to support NPTL on m68k/ColdFire.
> The syscalls are read_tp, write_tp, atomic_cmpxchg_32 and atomic_barrier.
> The cmpxchg syscall is required for ColdFire as it doesn't support 'cas'
> instruction.
> 
> Also a ptrace call PTRACE_GET_THREAD_AREA is added to allow debugger to
> inspect the TLS storage.
> 
> Signed-off-by: Maxim Kuvyrkov <maxim@codesourcery.com>
> ---
> arch/m68k/include/asm/ptrace.h         |    2 +
> arch/m68k/include/asm/thread_info_mm.h |    1 +
> arch/m68k/include/asm/unistd.h         |    6 ++-
> arch/m68k/kernel/entry.S               |    4 ++
> arch/m68k/kernel/process.c             |    4 ++
> arch/m68k/kernel/ptrace.c              |    5 ++
> arch/m68k/kernel/sys_m68k.c            |   80 ++++++++++++++++++++++++++++++++
> 7 files changed, 101 insertions(+), 1 deletions(-)
> 
> diff --git a/arch/m68k/include/asm/ptrace.h b/arch/m68k/include/asm/ptrace.h
> index a6ab663..43ab86a 100644
> --- a/arch/m68k/include/asm/ptrace.h
> +++ b/arch/m68k/include/asm/ptrace.h
> @@ -71,6 +71,8 @@ struct switch_stack {
> #define PTRACE_GETFPREGS          14
> #define PTRACE_SETFPREGS          15
> 
> +#define PTRACE_GET_THREAD_AREA    25
> +
> #define PTRACE_SINGLEBLOCK	33	/* resume execution until next branch */
> 
> #ifdef __KERNEL__
> diff --git a/arch/m68k/include/asm/thread_info_mm.h b/arch/m68k/include/asm/thread_info_mm.h
> index 167e518..67c2f7b 100644
> --- a/arch/m68k/include/asm/thread_info_mm.h
> +++ b/arch/m68k/include/asm/thread_info_mm.h
> @@ -16,6 +16,7 @@ struct thread_info {
> 	struct exec_domain	*exec_domain;	/* execution domain */
> 	int			preempt_count;	/* 0 => preemptable, <0 => BUG */
> 	__u32 cpu; /* should always be 0 on m68k */
> +	unsigned long tp_value;
> 	struct restart_block    restart_block;
> };
> #endif /* __ASSEMBLY__ */
> diff --git a/arch/m68k/include/asm/unistd.h b/arch/m68k/include/asm/unistd.h
> index 48b87f5..d076bea 100644
> --- a/arch/m68k/include/asm/unistd.h
> +++ b/arch/m68k/include/asm/unistd.h
> @@ -336,10 +336,14 @@
> #define __NR_pwritev		330
> #define __NR_rt_tgsigqueueinfo	331
> #define __NR_perf_event_open	332
> +#define __NR_read_tp		333
> +#define __NR_write_tp		334
> +#define __NR_atomic_cmpxchg_32	335
> +#define __NR_atomic_barrier	336
> 
> #ifdef __KERNEL__
> 
> -#define NR_syscalls		333
> +#define NR_syscalls		337
> 
> #define __ARCH_WANT_IPC_PARSE_VERSION
> #define __ARCH_WANT_OLD_READDIR
> diff --git a/arch/m68k/kernel/entry.S b/arch/m68k/kernel/entry.S
> index 77fc7c1..4238ac3 100644
> --- a/arch/m68k/kernel/entry.S
> +++ b/arch/m68k/kernel/entry.S
> @@ -761,4 +761,8 @@ sys_call_table:
> 	.long sys_pwritev		/* 330 */
> 	.long sys_rt_tgsigqueueinfo
> 	.long sys_perf_event_open
> +	.long sys_read_tp
> +	.long sys_write_tp
> +	.long sys_atomic_cmpxchg_32	/* 335 */
> +	.long sys_atomic_barrier
> 
> diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c
> index 0529659..17c3f32 100644
> --- a/arch/m68k/kernel/process.c
> +++ b/arch/m68k/kernel/process.c
> @@ -251,6 +251,10 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
> 
> 	p->thread.usp = usp;
> 	p->thread.ksp = (unsigned long)childstack;
> +
> +	if (clone_flags & CLONE_SETTLS)
> +		task_thread_info(p)->tp_value = regs->d5;
> +
> 	/*
> 	 * Must save the current SFC/DFC value, NOT the value when
> 	 * the parent was last descheduled - RGH  10-08-96
> diff --git a/arch/m68k/kernel/ptrace.c b/arch/m68k/kernel/ptrace.c
> index 1fc217e..616e597 100644
> --- a/arch/m68k/kernel/ptrace.c
> +++ b/arch/m68k/kernel/ptrace.c
> @@ -245,6 +245,11 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
> 			ret = -EFAULT;
> 		break;
> 
> +	case PTRACE_GET_THREAD_AREA:
> +		ret = put_user(task_thread_info(child)->tp_value,
> +			       (unsigned long __user *)data);
> +		break;
> +
> 	default:
> 		ret = ptrace_request(child, request, addr, data);
> 		break;
> diff --git a/arch/m68k/kernel/sys_m68k.c b/arch/m68k/kernel/sys_m68k.c
> index 7deb402..69b5f38 100644
> --- a/arch/m68k/kernel/sys_m68k.c
> +++ b/arch/m68k/kernel/sys_m68k.c
> @@ -28,6 +28,11 @@
> #include <asm/traps.h>
> #include <asm/page.h>
> #include <asm/unistd.h>
> +#include <linux/elf.h>
> +#include <asm/tlb.h>
> +
> +asmlinkage int do_page_fault(struct pt_regs *regs, unsigned long address,
> +			     unsigned long error_code);
> 
> /* common code for old and new mmaps */
> static inline long do_mmap2(
> @@ -662,3 +667,78 @@ int kernel_execve(const char *filename, char *const argv[], char *const envp[])
> 			: "d" (__a), "d" (__b), "d" (__c));
> 	return __res;
> }
> +
> +asmlinkage unsigned long sys_read_tp(void)
> +{
> +	return current_thread_info()->tp_value;
> +}
> +
> +asmlinkage int sys_write_tp(unsigned long tp)
> +{
> +	current_thread_info()->tp_value = tp;
> +	return 0;
> +}
> +
> +/* This syscall gets its arguments in A0 (mem), D2 (oldval) and
> +   D1 (newval).  */
> +asmlinkage int
> +sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3, int d4, int d5,
> +		      unsigned long __user * mem)
> +{
> +	/* This was borrowed from ARM's implementation.  */
> +	for (;;) {
> +		struct mm_struct *mm = current->mm;
> +		pgd_t *pgd;
> +		pmd_t *pmd;
> +		pte_t *pte;
> +		spinlock_t *ptl;
> +		unsigned long mem_value;
> +
> +		down_read(&mm->mmap_sem);
> +		pgd = pgd_offset(mm, (unsigned long)mem);
> +		if (!pgd_present(*pgd))
> +			goto bad_access;
> +		pmd = pmd_offset(pgd, (unsigned long)mem);
> +		if (!pmd_present(*pmd))
> +			goto bad_access;
> +		pte = pte_offset_map_lock(mm, pmd, (unsigned long)mem, &ptl);
> +		if (!pte_present(*pte) || !pte_dirty(*pte)) {
> +			pte_unmap_unlock(pte, ptl);
> +			goto bad_access;
> +		}
> +
> +		mem_value = *mem;
> +		if (mem_value == oldval)
> +			*mem = newval;
> +
> +		pte_unmap_unlock(pte, ptl);
> +		up_read(&mm->mmap_sem);
> +		return mem_value;
> +
> +	      bad_access:
> +		up_read(&mm->mmap_sem);
> +		/* This is not necessarily a bad access, we can get here if
> +		   a memory we're trying to write to should be copied-on-write.
> +		   Make the kernel do the necessary page stuff, then re-iterate.
> +		   Simulate a write access fault to do that.  */
> +		{
> +			/* The first argument of the function corresponds to
> +			   D1, which is the first field of struct pt_regs.  */
> +			struct pt_regs *fp = (struct pt_regs *)&newval;
> +
> +			/* '3' is an RMW flag.  */
> +			if (do_page_fault(fp, (unsigned long)mem, 3))
> +				/* If the do_page_fault() failed, we don't
> +				   have anything meaningful to return.
> +				   There should be a SIGSEGV pending for
> +				   the process.  */
> +				return 0xdeadbeef;
> +		}
> +	}
> +}
> +
> +asmlinkage int sys_atomic_barrier(void)
> +{
> +	/* no code needed for uniprocs */
> +	return 0;
> +}
> -- 
> 1.6.2.4
> 

--
Klaus Kuehnhammer
Bitstem Software
Wasnergasse 11/5
1200 Wien, Austria
+43 664 2133466
klaus@bitstem.com

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-12-09 10:25   ` Klaus Kuehnhammer
@ 2009-12-09 11:05     ` Maxim Kuvyrkov
       [not found]       ` <DBFD40BF-19FC-47DF-8A7C-B71261AFBD85@parq.net>
  0 siblings, 1 reply; 37+ messages in thread
From: Maxim Kuvyrkov @ 2009-12-09 11:05 UTC (permalink / raw)
  To: Klaus Kuehnhammer; +Cc: linux-m68k

Klaus Kuehnhammer wrote:
> Hi!
> 
> I've been testing this patch (together w/the latest codesourcery toolchain release) on an m548x the last couple of days.
> 
> It looks like there is still an issue in sys_atomic_cmpxchg_32. When cloning a large process, it accesses memory it shouldn't:

Hi Klaus,

Which kernel version are you using?  Where does the kernel oops?  Is it 
at `mem_value = *mem;' ?

Regards,

-- 
Maxim Kuvyrkov
CodeSourcery
maxim@codesourcery.com
(650) 331-3385 x724

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
       [not found]         ` <4B1F9492.6030604@codesourcery.com>
@ 2009-12-09 15:44           ` Klaus Kuehnhammer
  2009-12-10  9:18             ` Maxim Kuvyrkov
  0 siblings, 1 reply; 37+ messages in thread
From: Klaus Kuehnhammer @ 2009-12-09 15:44 UTC (permalink / raw)
  To: Maxim Kuvyrkov; +Cc: linux-m68k

[-- Attachment #1: Type: text/plain, Size: 689 bytes --]

Hello again,

It looks like the issue is caused by the page being write-protected. Adding !pte_write(*pte) to the checks seems to fix this, it goes into page fault and reloads the page entry writable. A patch is attached.

I'm not entirely comfortable w/this solution... I understand why calling do_page_fault w/a fixed RMW flag makes the write access work on the next iteration, but why would this page lack the write flag in the first place? Or, conversely, why does glibc call cmpxchg on a mem location in a non-writeable page?

Regarding the freescale kernel issues: Is there another kernel version we could try? 

best regards,
Klaus

PS I'm putting the list back on CC


[-- Attachment #2: linux-2.6.25-nptl-page-not-writeable-fix.patch --]
[-- Type: application/octet-stream, Size: 453 bytes --]

--- aaa/arch/m68k/kernel/sys_m68k.c	2009-12-09 12:41:46.000000000 +0100
+++ bbb/arch/m68k/kernel/sys_m68k.c	2009-12-09 16:36:58.000000000 +0100
@@ -736,7 +736,7 @@
 		if (!pmd_present(*pmd))
 			goto bad_access;
 		pte = pte_offset_map_lock(mm, pmd, (unsigned long)mem, &ptl);
-		if (!pte_present(*pte) || !pte_dirty(*pte)) {
+		if (!pte_write(*pte) || !pte_present(*pte) || !pte_dirty(*pte)) {
 			pte_unmap_unlock(pte, ptl);
 			goto bad_access;
 		}

[-- Attachment #3: Type: text/plain, Size: 1156 bytes --]



On 09.12.2009, at 13:14, Maxim Kuvyrkov wrote:

> Klaus Kuehnhammer wrote:
>> Hi!
>> Thanks for the quick reply!
>> It's a 2.6.25 kernel from the mid-2008 freescale BSP, w/the NPTL patches for the latest toolchain.
>> Linux version 2.6.25 (klaus@uvirt) (gcc version 4.4.1 (Sourcery G++ Lite 4.4-54) )
> 
> This kernel has several known issues, some of them can be triggered by NPTL support.
> 
>> I haven't run this in the debugger yet so i don't know for certain. From the address the oops gives, it's definitely in sys_atomic_cmpxchg_32. I added a printk, and the offending address comes in via the mem param, so yes, I guess the first *mem is the place.
> 
> Would you please provide a dump of the code near the place where the oops occurs, you should be able to do that with `m68k-linux-gnu-objdump -d vmlinux | grep -C 80 00021e50'.  And, of cause, a testcase will be of great help for tracking this down.
> 
> Thanks,
> 
> -- 
> Maxim Kuvyrkov
> CodeSourcery
> maxim@codesourcery.com
> (650) 331-3385 x724

--
Klaus Kuehnhammer
Bitstem Software
Wasnergasse 11/5
1200 Wien, Austria
+43 664 2133466
klaus@bitstem.com


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-12-09 15:44           ` Klaus Kuehnhammer
@ 2009-12-10  9:18             ` Maxim Kuvyrkov
  0 siblings, 0 replies; 37+ messages in thread
From: Maxim Kuvyrkov @ 2009-12-10  9:18 UTC (permalink / raw)
  To: Klaus Kuehnhammer; +Cc: linux-m68k, Jin Zhengxiong-R64188

On 12/9/09 6:44 PM, Klaus Kuehnhammer wrote:
> Hello again,
>
> It looks like the issue is caused by the page being write-protected.
> Adding !pte_write(*pte) to the checks seems to fix this, it goes into
> page fault and reloads the page entry writable. A patch is attached.
>
> I'm not entirely comfortable w/this solution... I understand why
> calling do_page_fault w/a fixed RMW flag makes the write access work
> on the next iteration, but why would this page lack the write flag in
> the first place?

It may have the write bit cleared (or have a readonly bit set) when the 
page should be copied-on-write.  What strange is why !pte_dirty() 
doesn't imply !pte_write().  The cmpxchg code was ported from 
arm.c:traps.c; here is the comment to the patch that changed 
!pte_write() to !pte_dirty in ARM's implementation:

|pte_write() just says that the page _may_ be writable. It doesn't say
|that the MMU is programmed to allow writes. If pte_dirty() doesn't
|return true, that means that the page is _not_ writable from userspace.
|If you write to it from kernel mode (without using put_user) you'll
|bypass the MMU read-only protection and may end up writing to a page
|owned by two separate processes.

 From the above it seems that your patch is safe.  However, it may be 
papering over the consequences of a different bug.  Is there a linux 
memory management expert around to comment on this?

...

> Regarding the freescale kernel issues: Is there another kernel
> version we could try?

I sent a link to this thread to Jason (Jin) who's working at Freescale 
and he suggested you try the following patch and see if it fixes the 
problem.  This patch fixes a cache handling problem on some of the 
ColdFire CPUs.

-------------------
diff --git a/arch/m68k/coldfire/signal.c b/arch/m68k/coldfire/signal.c
index 38671c4..b1b2bfb 100644
--- a/arch/m68k/coldfire/signal.c
+++ b/arch/m68k/coldfire/signal.c
@@ -608,9 +608,8 @@ static inline int rt_setup_ucontext(struct ucontext
__user *uc,

  static inline void push_cache(unsigned long vaddr)
  {
-#if 0
-// JKM -- need to add into the old cpushl cache stuff
-       cf_cache_push(__pa(vaddr), 8);
+#ifdef CONFIG_M547X_8X
+       flush_icache_range(vaddr, vaddr + 8);
  #endif
  }
-------------------

Regards,

-- 
Maxim Kuvyrkov
CodeSourcery
maxim@codesourcery.com
(650) 331-3385 x724

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-12-07  8:38 ` Maxim Kuvyrkov
  2009-12-09 10:25   ` Klaus Kuehnhammer
@ 2009-12-11 14:01   ` Geert Uytterhoeven
  2009-12-11 16:23     ` Maxim Kuvyrkov
  1 sibling, 1 reply; 37+ messages in thread
From: Geert Uytterhoeven @ 2009-12-11 14:01 UTC (permalink / raw)
  To: Maxim Kuvyrkov; +Cc: linux-m68k, Andreas Schwab, uClinux development list

On Mon, Dec 7, 2009 at 09:38, Maxim Kuvyrkov <maxim@codesourcery.com> wrote:
> Maxim Kuvyrkov wrote:
>> The attached patches add kernel support for userspace NPTL bits for m68k.
>
> Here is yet another final version of the patch.  As Andreas pointed out in
> another thread, the indentation is off in couple of places, so I fixed that
> by formatting the code with scripts/Lindent.  I also forwarded the
> reformatted version of the uClinux patch to uclinux-dev@.

> diff --git a/arch/m68k/include/asm/unistd.h b/arch/m68k/include/asm/unistd.h
> index 48b87f5..d076bea 100644
> --- a/arch/m68k/include/asm/unistd.h
> +++ b/arch/m68k/include/asm/unistd.h
> @@ -336,10 +336,14 @@
>  #define __NR_pwritev           330
>  #define __NR_rt_tgsigqueueinfo 331
>  #define __NR_perf_event_open   332
> +#define __NR_read_tp           333
> +#define __NR_write_tp          334
> +#define __NR_atomic_cmpxchg_32 335
> +#define __NR_atomic_barrier    336

BTW, other architectures seem to call these __NR_[gs]et_thread_area
instead of __NR_{read,write}_tp?
Shouldn't we follow for consistency?

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds
_______________________________________________
uClinux-dev mailing list
uClinux-dev@uclinux.org
http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
This message was resent by uclinux-dev@uclinux.org
To unsubscribe see:
http://mailman.uclinux.org/mailman/options/uclinux-dev

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-12-11 14:01   ` Geert Uytterhoeven
@ 2009-12-11 16:23     ` Maxim Kuvyrkov
  2009-12-17 17:53       ` Maxim Kuvyrkov
  0 siblings, 1 reply; 37+ messages in thread
From: Maxim Kuvyrkov @ 2009-12-11 16:23 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Andreas Schwab, linux-m68k, uClinux development list

On 12/11/09 5:01 PM, Geert Uytterhoeven wrote:
> On Mon, Dec 7, 2009 at 09:38, Maxim Kuvyrkov<maxim@codesourcery.com>  wrote:
...
>> diff --git a/arch/m68k/include/asm/unistd.h b/arch/m68k/include/asm/unistd.h
>> index 48b87f5..d076bea 100644
>> --- a/arch/m68k/include/asm/unistd.h
>> +++ b/arch/m68k/include/asm/unistd.h
>> @@ -336,10 +336,14 @@
>>   #define __NR_pwritev           330
>>   #define __NR_rt_tgsigqueueinfo 331
>>   #define __NR_perf_event_open   332
>> +#define __NR_read_tp           333
>> +#define __NR_write_tp          334
>> +#define __NR_atomic_cmpxchg_32 335
>> +#define __NR_atomic_barrier    336
>
> BTW, other architectures seem to call these __NR_[gs]et_thread_area
> instead of __NR_{read,write}_tp?
> Shouldn't we follow for consistency?

Yes, we may.  As long as the syscall numbers stay the same.  I'll send 
the updated patch once the memory handling issue is resolved.

BTW, does the analysis of the memory handling bug 
(http://marc.info/?l=linux-m68k&m=126043678613032&w=2) look right to you?

Regards,

-- 
Maxim Kuvyrkov
CodeSourcery
maxim@codesourcery.com
(650) 331-3385 x724

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: Add private syscalls to support NPTL
  2009-12-11 16:23     ` Maxim Kuvyrkov
@ 2009-12-17 17:53       ` Maxim Kuvyrkov
  0 siblings, 0 replies; 37+ messages in thread
From: Maxim Kuvyrkov @ 2009-12-17 17:53 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Andreas Schwab, linux-m68k, uClinux development list

[-- Attachment #1: Type: text/plain, Size: 918 bytes --]

On 12/11/09 7:23 PM, Maxim Kuvyrkov wrote:
> On 12/11/09 5:01 PM, Geert Uytterhoeven wrote:
>> On Mon, Dec 7, 2009 at 09:38, Maxim Kuvyrkov<maxim@codesourcery.com>
>> wrote:
...
>> BTW, other architectures seem to call these __NR_[gs]et_thread_area
>> instead of __NR_{read,write}_tp?
>> Shouldn't we follow for consistency?
>
> Yes, we may. As long as the syscall numbers stay the same. I'll send the
> updated patch once the memory handling issue is resolved.

Here is the updated patch.  I renamed {read,write}_tp syscalls to 
[gs]et_thread_area.  Regarding the memory access issue in cmpxchg 
syscall, I looked through the mm/ files and it seems that checking for 
!pte_write() is the right way to fix the problem; so the patch fixes 
that too.

As I understand, this patch fixes all outstanding issues and is ready 
for merge.

Regards,

-- 
Maxim Kuvyrkov
CodeSourcery
maxim@codesourcery.com
(650) 331-3385 x724

[-- Attachment #2: 0001-Add-NPTL-support-for-m68k.patch --]
[-- Type: text/plain, Size: 6809 bytes --]

From f1e2bdaa191f08d33938bd42cf090f3d9466866e Mon Sep 17 00:00:00 2001
From: Maxim Kuvyrkov <maxim@codesourcery.com>
Date: Mon, 7 Dec 2009 00:24:27 -0800
Subject: [PATCH 1/2] Add NPTL support for m68k

This patch adds several syscalls, that provide necessary
functionality to support NPTL on m68k/ColdFire.
The syscalls are get_thread_area, set_thread_area, atomic_cmpxchg_32 and
atomic_barrier.
The cmpxchg syscall is required for ColdFire as it doesn't support 'cas'
instruction.

Also a ptrace call PTRACE_GET_THREAD_AREA is added to allow debugger to
inspect the TLS storage.

Signed-off-by: Maxim Kuvyrkov <maxim@codesourcery.com>
---
 arch/m68k/include/asm/ptrace.h         |    2 +
 arch/m68k/include/asm/swab.h           |    2 +-
 arch/m68k/include/asm/thread_info_mm.h |    1 +
 arch/m68k/include/asm/unistd.h         |    6 ++-
 arch/m68k/kernel/entry.S               |    4 ++
 arch/m68k/kernel/process.c             |    4 ++
 arch/m68k/kernel/ptrace.c              |    5 ++
 arch/m68k/kernel/sys_m68k.c            |   81 ++++++++++++++++++++++++++++++++
 8 files changed, 103 insertions(+), 2 deletions(-)

diff --git a/arch/m68k/include/asm/ptrace.h b/arch/m68k/include/asm/ptrace.h
index a6ab663..43ab86a 100644
--- a/arch/m68k/include/asm/ptrace.h
+++ b/arch/m68k/include/asm/ptrace.h
@@ -71,6 +71,8 @@ struct switch_stack {
 #define PTRACE_GETFPREGS          14
 #define PTRACE_SETFPREGS          15
 
+#define PTRACE_GET_THREAD_AREA    25
+
 #define PTRACE_SINGLEBLOCK	33	/* resume execution until next branch */
 
 #ifdef __KERNEL__
diff --git a/arch/m68k/include/asm/swab.h b/arch/m68k/include/asm/swab.h
index 5b754aa..b7b37a4 100644
--- a/arch/m68k/include/asm/thread_info_mm.h
+++ b/arch/m68k/include/asm/thread_info_mm.h
@@ -16,6 +16,7 @@ struct thread_info {
 	struct exec_domain	*exec_domain;	/* execution domain */
 	int			preempt_count;	/* 0 => preemptable, <0 => BUG */
 	__u32 cpu; /* should always be 0 on m68k */
+	unsigned long		tp_value;	/* thread pointer */
 	struct restart_block    restart_block;
 };
 #endif /* __ASSEMBLY__ */
diff --git a/arch/m68k/include/asm/unistd.h b/arch/m68k/include/asm/unistd.h
index 48b87f5..d72a71d 100644
--- a/arch/m68k/include/asm/unistd.h
+++ b/arch/m68k/include/asm/unistd.h
@@ -336,10 +336,14 @@
 #define __NR_pwritev		330
 #define __NR_rt_tgsigqueueinfo	331
 #define __NR_perf_event_open	332
+#define __NR_get_thread_area	333
+#define __NR_set_thread_area	334
+#define __NR_atomic_cmpxchg_32	335
+#define __NR_atomic_barrier	336
 
 #ifdef __KERNEL__
 
-#define NR_syscalls		333
+#define NR_syscalls		337
 
 #define __ARCH_WANT_IPC_PARSE_VERSION
 #define __ARCH_WANT_OLD_READDIR
diff --git a/arch/m68k/kernel/entry.S b/arch/m68k/kernel/entry.S
index 77fc7c1..e136b8c 100644
--- a/arch/m68k/kernel/entry.S
+++ b/arch/m68k/kernel/entry.S
@@ -761,4 +761,8 @@ sys_call_table:
 	.long sys_pwritev		/* 330 */
 	.long sys_rt_tgsigqueueinfo
 	.long sys_perf_event_open
+	.long sys_get_thread_area
+	.long sys_set_thread_area
+	.long sys_atomic_cmpxchg_32	/* 335 */
+	.long sys_atomic_barrier
 
diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c
index 0529659..17c3f32 100644
--- a/arch/m68k/kernel/process.c
+++ b/arch/m68k/kernel/process.c
@@ -251,6 +251,10 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
 
 	p->thread.usp = usp;
 	p->thread.ksp = (unsigned long)childstack;
+
+	if (clone_flags & CLONE_SETTLS)
+		task_thread_info(p)->tp_value = regs->d5;
+
 	/*
 	 * Must save the current SFC/DFC value, NOT the value when
 	 * the parent was last descheduled - RGH  10-08-96
diff --git a/arch/m68k/kernel/ptrace.c b/arch/m68k/kernel/ptrace.c
index 1fc217e..616e597 100644
--- a/arch/m68k/kernel/ptrace.c
+++ b/arch/m68k/kernel/ptrace.c
@@ -245,6 +245,11 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 			ret = -EFAULT;
 		break;
 
+	case PTRACE_GET_THREAD_AREA:
+		ret = put_user(task_thread_info(child)->tp_value,
+			       (unsigned long __user *)data);
+		break;
+
 	default:
 		ret = ptrace_request(child, request, addr, data);
 		break;
diff --git a/arch/m68k/kernel/sys_m68k.c b/arch/m68k/kernel/sys_m68k.c
index 7deb402..1f0db88 100644
--- a/arch/m68k/kernel/sys_m68k.c
+++ b/arch/m68k/kernel/sys_m68k.c
@@ -28,6 +28,11 @@
 #include <asm/traps.h>
 #include <asm/page.h>
 #include <asm/unistd.h>
+#include <linux/elf.h>
+#include <asm/tlb.h>
+
+asmlinkage int do_page_fault(struct pt_regs *regs, unsigned long address,
+			     unsigned long error_code);
 
 /* common code for old and new mmaps */
 static inline long do_mmap2(
@@ -662,3 +667,79 @@ int kernel_execve(const char *filename, char *const argv[], char *const envp[])
 			: "d" (__a), "d" (__b), "d" (__c));
 	return __res;
 }
+
+asmlinkage unsigned long sys_get_thread_area(void)
+{
+	return current_thread_info()->tp_value;
+}
+
+asmlinkage int sys_set_thread_area(unsigned long tp)
+{
+	current_thread_info()->tp_value = tp;
+	return 0;
+}
+
+/* This syscall gets its arguments in A0 (mem), D2 (oldval) and
+   D1 (newval).  */
+asmlinkage int
+sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3, int d4, int d5,
+		      unsigned long __user * mem)
+{
+	/* This was borrowed from ARM's implementation.  */
+	for (;;) {
+		struct mm_struct *mm = current->mm;
+		pgd_t *pgd;
+		pmd_t *pmd;
+		pte_t *pte;
+		spinlock_t *ptl;
+		unsigned long mem_value;
+
+		down_read(&mm->mmap_sem);
+		pgd = pgd_offset(mm, (unsigned long)mem);
+		if (!pgd_present(*pgd))
+			goto bad_access;
+		pmd = pmd_offset(pgd, (unsigned long)mem);
+		if (!pmd_present(*pmd))
+			goto bad_access;
+		pte = pte_offset_map_lock(mm, pmd, (unsigned long)mem, &ptl);
+		if (!pte_present(*pte) || !pte_dirty(*pte)
+		    || !pte_write(*pte)) {
+			pte_unmap_unlock(pte, ptl);
+			goto bad_access;
+		}
+
+		mem_value = *mem;
+		if (mem_value == oldval)
+			*mem = newval;
+
+		pte_unmap_unlock(pte, ptl);
+		up_read(&mm->mmap_sem);
+		return mem_value;
+
+	      bad_access:
+		up_read(&mm->mmap_sem);
+		/* This is not necessarily a bad access, we can get here if
+		   a memory we're trying to write to should be copied-on-write.
+		   Make the kernel do the necessary page stuff, then re-iterate.
+		   Simulate a write access fault to do that.  */
+		{
+			/* The first argument of the function corresponds to
+			   D1, which is the first field of struct pt_regs.  */
+			struct pt_regs *fp = (struct pt_regs *)&newval;
+
+			/* '3' is an RMW flag.  */
+			if (do_page_fault(fp, (unsigned long)mem, 3))
+				/* If the do_page_fault() failed, we don't
+				   have anything meaningful to return.
+				   There should be a SIGSEGV pending for
+				   the process.  */
+				return 0xdeadbeef;
+		}
+	}
+}
+
+asmlinkage int sys_atomic_barrier(void)
+{
+	/* no code needed for uniprocs */
+	return 0;
+}
-- 
1.6.2.4


^ permalink raw reply related	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2009-12-17 17:53 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-17 21:48 Add private syscalls to support NPTL Maxim Kuvyrkov
2009-08-17 22:11 ` Andreas Schwab
2009-08-18  7:15   ` Maxim Kuvyrkov
2009-08-18  8:06     ` Andreas Schwab
2009-08-18  8:56       ` Maxim Kuvyrkov
2009-08-18  9:22         ` Geert Uytterhoeven
2009-08-18  9:36           ` Maxim Kuvyrkov
2009-08-18 18:18           ` Andreas Schwab
2009-08-23 20:21           ` Maxim Kuvyrkov
2009-08-25 19:43             ` Maxim Kuvyrkov
2009-08-28 10:51               ` Maxim Kuvyrkov
2009-10-02  9:59                 ` Maxim Kuvyrkov
2009-10-26 15:01                   ` Maxim Kuvyrkov
2009-10-28  1:19                     ` Finn Thain
2009-10-28  6:54                       ` Maxim Kuvyrkov
2009-10-28 16:38                         ` Finn Thain
2009-11-06  8:38                         ` Finn Thain
2009-11-06  8:59                           ` Maxim Kuvyrkov
2009-11-10  4:07                             ` Finn Thain
2009-11-10  4:20                               ` Brad Boyer
2009-11-10 10:51                               ` Maxim Kuvyrkov
2009-11-10 16:11                                 ` Finn Thain
2009-08-17 22:18 ` Andreas Schwab
2009-08-18  7:10   ` Maxim Kuvyrkov
2009-08-18  2:28 ` Brad Boyer
2009-08-18  7:07   ` Maxim Kuvyrkov
2009-08-18 23:40     ` Brad Boyer
2009-08-19  8:06       ` Maxim Kuvyrkov
2009-08-19  8:35       ` Andreas Schwab
2009-12-07  8:38 ` Maxim Kuvyrkov
2009-12-09 10:25   ` Klaus Kuehnhammer
2009-12-09 11:05     ` Maxim Kuvyrkov
     [not found]       ` <DBFD40BF-19FC-47DF-8A7C-B71261AFBD85@parq.net>
     [not found]         ` <4B1F9492.6030604@codesourcery.com>
2009-12-09 15:44           ` Klaus Kuehnhammer
2009-12-10  9:18             ` Maxim Kuvyrkov
2009-12-11 14:01   ` Geert Uytterhoeven
2009-12-11 16:23     ` Maxim Kuvyrkov
2009-12-17 17:53       ` Maxim Kuvyrkov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.