Skip to contentSkip to conversation

Support TIF_RESTORE_SIGMASK on x86_64

PATCH In review David Woodhouse 4 participants 6 messages Jul 3, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Support TIF_RESTORE_SIGMASK on x86_64

We need TIF_RESTORE_SIGMASK in order to support ppoll() and pselect() system calls. This patch originally came from Andi, and was based heavily on David Howells' implementation of same on i386. I fixed a typo which was causing do_signal() to use the wrong signal mask.

arch/x86_64/ia32/ia32_signal.c +11 -17
index 25e5ca2..549de43 100644
@@ -113,25 +113,19 @@ int copy_siginfo_from_user32(siginfo_t *
 }
 
 asmlinkage long
-sys32_sigsuspend(int history0, int history1, old_sigset_t mask,
-		 struct pt_regs *regs)
+sys32_sigsuspend(int history0, int history1, old_sigset_t mask)
 {
-	sigset_t saveset;
-
 	mask &= _BLOCKABLE;
 	spin_lock_irq(&current->sighand->siglock);
-	saveset = current->blocked;
+	current->saved_sigmask = current->blocked;
 	siginitset(&current->blocked, mask);
 	recalc_sigpending();
 	spin_unlock_irq(&current->sighand->siglock);
 
-	regs->rax = -EINTR;
-	while (1) {
-		current->state = TASK_INTERRUPTIBLE;
-		schedule();
-		if (do_signal(regs, &saveset))
-			return -EINTR;
-	}
+	current->state = TASK_INTERRUPTIBLE;
+	schedule();
+	set_thread_flag(TIF_RESTORE_SIGMASK);
+	return -ERESTARTNOHAND;
 }
 
 asmlinkage long
@@ -508,11 +502,11 @@ #if DEBUG_SIG
 		current->comm, current->pid, frame, regs->rip, frame->pretcode);
 #endif
 
-	return 1;
+	return 0;
 
 give_sigsegv:
 	force_sigsegv(sig, current);
-	return 0;
+	return -EFAULT;
 }
 
 int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
@@ -595,7 +589,7 @@ int ia32_setup_rt_frame(int sig, struct 
 	regs->ss = __USER32_DS; 
 
 	set_fs(USER_DS);
-    regs->eflags &= ~TF_MASK;
+	regs->eflags &= ~TF_MASK;
     if (test_thread_flag(TIF_SINGLESTEP))
         ptrace_notify(SIGTRAP);
 
@@ -604,9 +598,9 @@ #if DEBUG_SIG
 		current->comm, current->pid, frame, regs->rip, frame->pretcode);
 #endif
 
-	return 1;
+	return 0;
 
 give_sigsegv:
 	force_sigsegv(sig, current);
-	return 0;
+	return -EFAULT;
 }
arch/x86_64/kernel/signal.c +35 -47

148 lines not on this page · raw message

include/asm-x86_64/signal.h +0 -4
index cef7a7d..00f2d38 100644
@@ -24,10 +24,6 @@ typedef struct {
 } sigset_t;
 
 
-struct pt_regs; 
-asmlinkage int do_signal(struct pt_regs *regs, sigset_t *oldset);
-
-
 #else
 /* Here we must cater to libcs that poke about in kernel headers.  */
 
include/asm-x86_64/thread_info.h +2 -0
index 2029b00..790c512 100644
@@ -114,6 +114,7 @@ #define TIF_SINGLESTEP		4	/* reenable si
 #define TIF_IRET		5	/* force IRET */
 #define TIF_SYSCALL_AUDIT	7	/* syscall auditing active */
 #define TIF_SECCOMP		8	/* secure computing */
+#define TIF_RESTORE_SIGMASK	9	/* restore signal mask in do_signal */
 /* 16 free */
 #define TIF_IA32		17	/* 32bit process */ 
 #define TIF_FORK		18	/* ret_from_fork */
@@ -128,6 +129,7 @@ #define _TIF_NEED_RESCHED	(1<<TIF_NEED_R
 #define _TIF_IRET		(1<<TIF_IRET)
 #define _TIF_SYSCALL_AUDIT	(1<<TIF_SYSCALL_AUDIT)
 #define _TIF_SECCOMP		(1<<TIF_SECCOMP)
+#define _TIF_RESTORE_SIGMASK	(1<<TIF_RESTORE_SIGMASK)
 #define _TIF_IA32		(1<<TIF_IA32)
 #define _TIF_FORK		(1<<TIF_FORK)
 #define _TIF_ABI_PENDING	(1<<TIF_ABI_PENDING)
include/asm-x86_64/unistd.h +1 -0
index 94387c9..c9db37d 100644
@@ -658,6 +658,7 @@ #define __ARCH_WANT_SYS_OLDUMOUNT
 #define __ARCH_WANT_SYS_SIGPENDING
 #define __ARCH_WANT_SYS_SIGPROCMASK
 #define __ARCH_WANT_SYS_RT_SIGACTION
+#define __ARCH_WANT_SYS_RT_SIGSUSPEND
 #define __ARCH_WANT_SYS_TIME
 #define __ARCH_WANT_COMPAT_SYS_TIME
 
Signature · 1 line
dwmw2
#1 lore raw

PATCH 2/2 pselect/ppoll support on x86_64

This adds support for the pselect and ppoll system calls on x86_64.

Andi suggests that it might be too late for the 2.6.18 merge window -- I disagree. I consider it a bug fix, since I don't think we intend x86_64 to be a secondary architecture and lag behind i386 and PowerPC in its system call support. Andi's TIF_RESTORE_SIGMASK implementation is heavily based on the i386 version, where it's had lots of testing already.

arch/x86_64/ia32/ia32entry.S +2 -2
index 5a92fed..07399fe 100644
@@ -687,8 +687,8 @@ #endif
 	.quad sys_readlinkat		/* 305 */
 	.quad sys_fchmodat
 	.quad sys_faccessat
-	.quad quiet_ni_syscall		/* pselect6 for now */
-	.quad quiet_ni_syscall		/* ppoll for now */
+	.quad compat_sys_pselect6
+	.quad compat_sys_ppoll
 	.quad sys_unshare		/* 310 */
 	.quad compat_sys_set_robust_list
 	.quad compat_sys_get_robust_list
include/asm-x86_64/unistd.h +2 -2
index feb77cb..0a08bbf 100644
@@ -600,9 +600,9 @@ __SYSCALL(__NR_fchmodat, sys_fchmodat)
 #define __NR_faccessat		269
 __SYSCALL(__NR_faccessat, sys_faccessat)
 #define __NR_pselect6		270
-__SYSCALL(__NR_pselect6, sys_ni_syscall)	/* for now */
+__SYSCALL(__NR_pselect6, sys_pselect6)
 #define __NR_ppoll		271
-__SYSCALL(__NR_ppoll,	sys_ni_syscall)		/* for now */
+__SYSCALL(__NR_ppoll,	sys_ppoll)
 #define __NR_unshare		272
 __SYSCALL(__NR_unshare,	sys_unshare)
 #define __NR_set_robust_list	273
Signature · 1 line
dwmw2
#2 lore raw

Re: [PATCH 2/2] pselect/ppoll support on x86_64

Quoted 8 lines · David Woodhouse

This adds support for the pselect and ppoll system calls on x86_64.

Andi suggests that it might be too late for the 2.6.18 merge window -- I disagree. I consider it a bug fix, since I don't think we intend x86_64 to be a secondary architecture and lag behind i386 and PowerPC in its system call support. Andi's TIF_RESTORE_SIGMASK implementation is heavily based on the i386 version, where it's had lots of testing already.

I've got burned badly by these patches last time and the 2.6.18 merge window is closed.

I'll add them for testing, but it's 2.6.19 material.

-Andi

#3 lore raw
In reply to David Woodhouse
Quoted 5 lines · On Mon, 03 Jul 2006 10:41:51 +0100 David Woodhouse <[email protected]> wrote:

We need TIF_RESTORE_SIGMASK in order to support ppoll() and pselect() system calls. This patch originally came from Andi, and was based heavily on David Howells' implementation of same on i386. I fixed a typo which was causing do_signal() to use the wrong signal mask.

We struggled with these patches quite a lot when they were in Andi's tree. My test box would get stuck during kernel compiles and Andi could never reproduce it.

<digs back through emails>

x:/home/akpm> ps aux|grep make

akpm      5064  0.0  0.0 40844 1112 pts/0    S+   17:30   0:00 make -j 6 CC= gcc bzImage modules
akpm      5364  0.0  0.0     0    0 pts/0    Z+   17:30   0:00 [make] <defunct>
akpm      5381  0.1  0.0     0    0 pts/0    Z+   17:30   0:00 [make] <defunct>
akpm      5451  0.0  0.0     0    0 pts/0    Z+   17:30   0:00 [make] <defunct>
akpm      5480  0.0  0.0     0    0 pts/0    Z+   17:30   0:00 [make] <defunct>
akpm      6004  0.0  0.0 41496  608 pts/1    S+   17:32   0:00 grep make

make S ffff81017683fdc8 0 5064 5056 5364 (NOTLB)
ffff81017683fdc8 ffff81017aa7ca98 ffff81017982d4b8 ffff810178b7f810

       0000000080168760 ffff81000705baa0 ffff81017fc0b480 ffff810179a24790 
       000000037aa7caa0 0000000000008944 
Call Trace: <ffffffff803cd4d4>{_spin_unlock+19} <ffffffff80178feb>{pipe_wait+119}
       <ffffffff8013eff9>{autoremove_wake_function+0} <ffffffff8013eff9>{autoremove_wake_function+0}
       <ffffffff8017934a>{pipe_readv+621} <ffffffff801793f1>{pipe_read+30}
       <ffffffff8016d29b>{vfs_read+175} <ffffffff8016d5fc>{sys_read+71}
       <ffffffff8010aa5e>{system_call+126}
make          X ffff810176389ed8     0  5364   5064          5381       (L-TLB)
ffff810176389ed8 ffff810176389e28 ffffffff803cd4a4 0000000000000000 
       ffff810175596850 ffff810176389ed8 0000000000000003 ffff810175596850 
       0000000300040001 000000000000c50a 
Call Trace: <ffffffff803cd4a4>{_spin_unlock_irqrestore+27}
       <ffffffff803cd4d4>{_spin_unlock+19} <ffffffff8012e5c5>{do_exit+2225}
       <ffffffff8016c00a>{sys_chdir+90} <ffffffff8012e6dc>{sys_exit_group+0}
       <ffffffff8012e6ee>{sys_exit_group+18} <ffffffff8010aa5e>{system_call+126}
make          X ffff810175199ed8     0  5381   5064          5451  5364 (L-TLB)
ffff810175199ed8 ffff810175199e28 ffffffff803cd4a4 0000000000000000 
       ffff810179a930c0 ffff810175199ed8 0000000000000002 ffff810179a930c0 
       0000000200040001 000000000000ca4c 
Call Trace: <ffffffff803cd4a4>{_spin_unlock_irqrestore+27}
       <ffffffff803cd4d4>{_spin_unlock+19} <ffffffff8012e5c5>{do_exit+2225}
       <ffffffff8016c00a>{sys_chdir+90} <ffffffff8012e6dc>{sys_exit_group+0}
       <ffffffff8012e6ee>{sys_exit_group+18} <ffffffff8010aa5e>{system_call+126}
make          X ffff810176249ed8     0  5451   5064          5480  5381 (L-TLB)
ffff810176249ed8 ffff810176249e28 ffffffff803cd4a4 0000000000000000 
       ffff8101790fe7d0 ffff810176249ed8 0000000000000001 ffff8101790fe7d0 
       0000000100040001 000000000000d408 
Call Trace: <ffffffff803cd4a4>{_spin_unlock_irqrestore+27}
       <ffffffff803cd4d4>{_spin_unlock+19} <ffffffff8012e5c5>{do_exit+2225}
       <ffffffff8016c00a>{sys_chdir+90} <ffffffff8012e6dc>{sys_exit_group+0}
       <ffffffff8012e6ee>{sys_exit_group+18} <ffffffff8010aa5e>{system_call+126}
make          X ffff810174f91ed8     0  5480   5064                5451 (L-TLB)
ffff810174f91ed8 ffff810174f91e28 ffffffff803cd4a4 0000000000000046 
       ffff810178b7f810 ffff810174f91ed8 0000000000000001 ffff810178b7f810 
       0000000100040001 00000000000106aa 
Call Trace: <ffffffff803cd4a4>{_spin_unlock_irqrestore+27}
       <ffffffff803cd4d4>{_spin_unlock+19} <ffffffff8012e5c5>{do_exit+2225}
       <ffffffff8016c00a>{sys_chdir+90} <ffffffff8012e6dc>{sys_exit_group+0}
       <ffffffff8012e6ee>{sys_exit_group+18} <ffffffff8010aa5e>{system_call+126}

It seems OK now with these patches.

Could you please describe the signal mask fix? Is that likely to have caused the above symptoms?

Quoted 17 lines

asmlinkage long

arch/x86_64/ia32/ia32_signal.c +2 -7
-sys32_sigsuspend(int history0, int history1, old_sigset_t mask,
-		 struct pt_regs *regs)
+sys32_sigsuspend(int history0, int history1, old_sigset_t mask)
 {
-	sigset_t saveset;
-
 	mask &= _BLOCKABLE;
 	spin_lock_irq(&current->sighand->siglock);
-	saveset = current->blocked;
+	current->saved_sigmask = current->blocked;
 	siginitset(&current->blocked, mask);
 	recalc_sigpending();
 	spin_unlock_irq(&current->sighand->siglock);
 
-	regs->rax = -EINTR;
-	while (1) {

arch/x86_64/ia32/ia32_signal.c int copy_siginfo_from_user32(siginfo_t * · line 129

Quoted 10 lines
arch/x86_64/ia32/ia32_signal.c +4 -5
-		current->state = TASK_INTERRUPTIBLE;
-		schedule();
-		if (do_signal(regs, &saveset))
-			return -EINTR;
-	}
+	current->state = TASK_INTERRUPTIBLE;
+	schedule();
+	set_thread_flag(TIF_RESTORE_SIGMASK);
+	return -ERESTARTNOHAND;
 }

Should we be setting TASK_INTERRUPTIBLE before releasing that lock?

#4 lore raw
Quoted 1 line · Andrew Morton

Could you please describe the signal mask fix?

@@ -583,7 +583,7 @@

        if (!user_mode(regs))
                return;

- if (!test_thread_flag(TIF_RESTORE_SIGMASK))
+ if (test_thread_flag(TIF_RESTORE_SIGMASK))

                oldset = &current->saved_sigmask;
        else
                oldset = &current->blocked;
Quoted 1 line

Is that likely to have caused the above symptoms?

Yeah, it'll screw up the signal mask all over the place. cf. https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=180567
also https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=179228

Quoted 1 line

Should we be setting TASK_INTERRUPTIBLE before releasing that lock?

Before releasing current->sighand->siglock? Nah, schedule() will check for pending signals -- it's not like racing with a wake_up()

Signature · 1 line
dwmw2
#5 lore raw
In reply to Andrew Morton
Quoted 3 lines · Andrew Morton

We struggled with these patches quite a lot when they were in Andi's tree. My test box would get stuck during kernel compiles and Andi could never reproduce it.

Try the patch. dwmw2's change made all the difference for me. The old
kernel wasn't able to handle the glibc test suite, this one does.

Signature · 1 line
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖