Skip to content

Commit 8978a31

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-2.6: sparc64: Use a TS_RESTORE_SIGMASK lmb: Make lmb debugging more useful. lmb: Fix inconsistent alignment of size argument. sparc: Fix mremap address range validation.
2 parents f7fd63c + 9a28dbf commit 8978a31

File tree

10 files changed

+89
-151
lines changed

10 files changed

+89
-151
lines changed

arch/sparc/kernel/sys_sparc.c

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ asmlinkage int sys_ipc (uint call, int first, int second, int third, void __user
219219
return err;
220220
}
221221

222-
int sparc_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
222+
int sparc_mmap_check(unsigned long addr, unsigned long len)
223223
{
224224
if (ARCH_SUN4C_SUN4 &&
225225
(len > 0x20000000 ||
@@ -295,52 +295,14 @@ asmlinkage unsigned long sparc_mremap(unsigned long addr,
295295
unsigned long old_len, unsigned long new_len,
296296
unsigned long flags, unsigned long new_addr)
297297
{
298-
struct vm_area_struct *vma;
299298
unsigned long ret = -EINVAL;
300-
if (ARCH_SUN4C_SUN4) {
301-
if (old_len > 0x20000000 || new_len > 0x20000000)
302-
goto out;
303-
if (addr < 0xe0000000 && addr + old_len > 0x20000000)
304-
goto out;
305-
}
306-
if (old_len > TASK_SIZE - PAGE_SIZE ||
307-
new_len > TASK_SIZE - PAGE_SIZE)
299+
300+
if (unlikely(sparc_mmap_check(addr, old_len)))
301+
goto out;
302+
if (unlikely(sparc_mmap_check(new_addr, new_len)))
308303
goto out;
309304
down_write(&current->mm->mmap_sem);
310-
if (flags & MREMAP_FIXED) {
311-
if (ARCH_SUN4C_SUN4 &&
312-
new_addr < 0xe0000000 &&
313-
new_addr + new_len > 0x20000000)
314-
goto out_sem;
315-
if (new_addr + new_len > TASK_SIZE - PAGE_SIZE)
316-
goto out_sem;
317-
} else if ((ARCH_SUN4C_SUN4 && addr < 0xe0000000 &&
318-
addr + new_len > 0x20000000) ||
319-
addr + new_len > TASK_SIZE - PAGE_SIZE) {
320-
unsigned long map_flags = 0;
321-
struct file *file = NULL;
322-
323-
ret = -ENOMEM;
324-
if (!(flags & MREMAP_MAYMOVE))
325-
goto out_sem;
326-
327-
vma = find_vma(current->mm, addr);
328-
if (vma) {
329-
if (vma->vm_flags & VM_SHARED)
330-
map_flags |= MAP_SHARED;
331-
file = vma->vm_file;
332-
}
333-
334-
new_addr = get_unmapped_area(file, addr, new_len,
335-
vma ? vma->vm_pgoff : 0,
336-
map_flags);
337-
ret = new_addr;
338-
if (new_addr & ~PAGE_MASK)
339-
goto out_sem;
340-
flags |= MREMAP_FIXED;
341-
}
342305
ret = do_mremap(addr, old_len, new_len, flags, new_addr);
343-
out_sem:
344306
up_write(&current->mm->mmap_sem);
345307
out:
346308
return ret;

arch/sparc64/kernel/rtrap.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ __handle_user_windows:
4646
wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
4747
ldx [%g6 + TI_FLAGS], %l0
4848

49-
1: andcc %l0, (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK), %g0
49+
1: andcc %l0, _TIF_SIGPENDING, %g0
5050
be,pt %xcc, __handle_user_windows_continue
5151
nop
5252
mov %l5, %o1
@@ -86,7 +86,7 @@ __handle_perfctrs:
8686
wrpr %g0, RTRAP_PSTATE, %pstate
8787
wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
8888
ldx [%g6 + TI_FLAGS], %l0
89-
1: andcc %l0, (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK), %g0
89+
1: andcc %l0, _TIF_SIGPENDING, %g0
9090

9191
be,pt %xcc, __handle_perfctrs_continue
9292
sethi %hi(TSTATE_PEF), %o0
@@ -195,7 +195,7 @@ __handle_preemption_continue:
195195
andcc %l1, %o0, %g0
196196
andcc %l0, _TIF_NEED_RESCHED, %g0
197197
bne,pn %xcc, __handle_preemption
198-
andcc %l0, (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK), %g0
198+
andcc %l0, _TIF_SIGPENDING, %g0
199199
bne,pn %xcc, __handle_signal
200200
__handle_signal_continue:
201201
ldub [%g6 + TI_WSAVED], %o2

arch/sparc64/kernel/signal.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ static long _sigpause_common(old_sigset_t set)
247247

248248
current->state = TASK_INTERRUPTIBLE;
249249
schedule();
250-
set_thread_flag(TIF_RESTORE_SIGMASK);
250+
251+
set_restore_sigmask();
252+
251253
return -ERESTARTNOHAND;
252254
}
253255

@@ -537,7 +539,7 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
537539
} else
538540
restart_syscall = 0;
539541

540-
if (test_thread_flag(TIF_RESTORE_SIGMASK))
542+
if (current_thread_info()->status & TS_RESTORE_SIGMASK)
541543
oldset = &current->saved_sigmask;
542544
else
543545
oldset = &current->blocked;
@@ -566,13 +568,12 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
566568
syscall_restart(orig_i0, regs, &ka.sa);
567569
handle_signal(signr, &ka, &info, oldset, regs);
568570

569-
/* a signal was successfully delivered; the saved
571+
/* A signal was successfully delivered; the saved
570572
* sigmask will have been stored in the signal frame,
571573
* and will be restored by sigreturn, so we can simply
572-
* clear the TIF_RESTORE_SIGMASK flag.
574+
* clear the TS_RESTORE_SIGMASK flag.
573575
*/
574-
if (test_thread_flag(TIF_RESTORE_SIGMASK))
575-
clear_thread_flag(TIF_RESTORE_SIGMASK);
576+
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
576577
return;
577578
}
578579
if (restart_syscall &&
@@ -591,17 +592,17 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
591592
regs->tnpc -= 4;
592593
}
593594

594-
/* if there's no signal to deliver, we just put the saved sigmask
595+
/* If there's no signal to deliver, we just put the saved sigmask
595596
* back
596597
*/
597-
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
598-
clear_thread_flag(TIF_RESTORE_SIGMASK);
598+
if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
599+
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
599600
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
600601
}
601602
}
602603

603604
void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned long thread_info_flags)
604605
{
605-
if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
606+
if (thread_info_flags & _TIF_SIGPENDING)
606607
do_signal(regs, orig_i0);
607608
}

arch/sparc64/kernel/signal32.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -788,13 +788,12 @@ void do_signal32(sigset_t *oldset, struct pt_regs * regs,
788788
syscall_restart32(orig_i0, regs, &ka.sa);
789789
handle_signal32(signr, &ka, &info, oldset, regs);
790790

791-
/* a signal was successfully delivered; the saved
791+
/* A signal was successfully delivered; the saved
792792
* sigmask will have been stored in the signal frame,
793793
* and will be restored by sigreturn, so we can simply
794-
* clear the TIF_RESTORE_SIGMASK flag.
794+
* clear the TS_RESTORE_SIGMASK flag.
795795
*/
796-
if (test_thread_flag(TIF_RESTORE_SIGMASK))
797-
clear_thread_flag(TIF_RESTORE_SIGMASK);
796+
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
798797
return;
799798
}
800799
if (restart_syscall &&
@@ -813,11 +812,11 @@ void do_signal32(sigset_t *oldset, struct pt_regs * regs,
813812
regs->tnpc -= 4;
814813
}
815814

816-
/* if there's no signal to deliver, we just put the saved sigmask
815+
/* If there's no signal to deliver, we just put the saved sigmask
817816
* back
818817
*/
819-
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
820-
clear_thread_flag(TIF_RESTORE_SIGMASK);
818+
if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
819+
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
821820
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
822821
}
823822
}

arch/sparc64/kernel/sys_sparc.c

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,7 @@ asmlinkage long sparc64_personality(unsigned long personality)
542542
return ret;
543543
}
544544

545-
int sparc64_mmap_check(unsigned long addr, unsigned long len,
546-
unsigned long flags)
545+
int sparc64_mmap_check(unsigned long addr, unsigned long len)
547546
{
548547
if (test_thread_flag(TIF_32BIT)) {
549548
if (len >= STACK_TOP32)
@@ -609,46 +608,19 @@ asmlinkage unsigned long sys64_mremap(unsigned long addr,
609608
unsigned long old_len, unsigned long new_len,
610609
unsigned long flags, unsigned long new_addr)
611610
{
612-
struct vm_area_struct *vma;
613611
unsigned long ret = -EINVAL;
614612

615613
if (test_thread_flag(TIF_32BIT))
616614
goto out;
617615
if (unlikely(new_len >= VA_EXCLUDE_START))
618616
goto out;
619-
if (unlikely(invalid_64bit_range(addr, old_len)))
617+
if (unlikely(sparc64_mmap_check(addr, old_len)))
618+
goto out;
619+
if (unlikely(sparc64_mmap_check(new_addr, new_len)))
620620
goto out;
621621

622622
down_write(&current->mm->mmap_sem);
623-
if (flags & MREMAP_FIXED) {
624-
if (invalid_64bit_range(new_addr, new_len))
625-
goto out_sem;
626-
} else if (invalid_64bit_range(addr, new_len)) {
627-
unsigned long map_flags = 0;
628-
struct file *file = NULL;
629-
630-
ret = -ENOMEM;
631-
if (!(flags & MREMAP_MAYMOVE))
632-
goto out_sem;
633-
634-
vma = find_vma(current->mm, addr);
635-
if (vma) {
636-
if (vma->vm_flags & VM_SHARED)
637-
map_flags |= MAP_SHARED;
638-
file = vma->vm_file;
639-
}
640-
641-
/* MREMAP_FIXED checked above. */
642-
new_addr = get_unmapped_area(file, addr, new_len,
643-
vma ? vma->vm_pgoff : 0,
644-
map_flags);
645-
ret = new_addr;
646-
if (new_addr & ~PAGE_MASK)
647-
goto out_sem;
648-
flags |= MREMAP_FIXED;
649-
}
650623
ret = do_mremap(addr, old_len, new_len, flags, new_addr);
651-
out_sem:
652624
up_write(&current->mm->mmap_sem);
653625
out:
654626
return ret;

arch/sparc64/kernel/sys_sparc32.c

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -867,44 +867,15 @@ asmlinkage unsigned long sys32_mremap(unsigned long addr,
867867
unsigned long old_len, unsigned long new_len,
868868
unsigned long flags, u32 __new_addr)
869869
{
870-
struct vm_area_struct *vma;
871870
unsigned long ret = -EINVAL;
872871
unsigned long new_addr = __new_addr;
873872

874-
if (old_len > STACK_TOP32 || new_len > STACK_TOP32)
873+
if (unlikely(sparc64_mmap_check(addr, old_len)))
875874
goto out;
876-
if (addr > STACK_TOP32 - old_len)
875+
if (unlikely(sparc64_mmap_check(new_addr, new_len)))
877876
goto out;
878877
down_write(&current->mm->mmap_sem);
879-
if (flags & MREMAP_FIXED) {
880-
if (new_addr > STACK_TOP32 - new_len)
881-
goto out_sem;
882-
} else if (addr > STACK_TOP32 - new_len) {
883-
unsigned long map_flags = 0;
884-
struct file *file = NULL;
885-
886-
ret = -ENOMEM;
887-
if (!(flags & MREMAP_MAYMOVE))
888-
goto out_sem;
889-
890-
vma = find_vma(current->mm, addr);
891-
if (vma) {
892-
if (vma->vm_flags & VM_SHARED)
893-
map_flags |= MAP_SHARED;
894-
file = vma->vm_file;
895-
}
896-
897-
/* MREMAP_FIXED checked above. */
898-
new_addr = get_unmapped_area(file, addr, new_len,
899-
vma ? vma->vm_pgoff : 0,
900-
map_flags);
901-
ret = new_addr;
902-
if (new_addr & ~PAGE_MASK)
903-
goto out_sem;
904-
flags |= MREMAP_FIXED;
905-
}
906878
ret = do_mremap(addr, old_len, new_len, flags, new_addr);
907-
out_sem:
908879
up_write(&current->mm->mmap_sem);
909880
out:
910881
return ret;

include/asm-sparc/mman.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@
2424

2525
#ifdef __KERNEL__
2626
#ifndef __ASSEMBLY__
27-
#define arch_mmap_check sparc_mmap_check
28-
int sparc_mmap_check(unsigned long addr, unsigned long len,
29-
unsigned long flags);
27+
#define arch_mmap_check(addr,len,flags) sparc_mmap_check(addr,len)
28+
int sparc_mmap_check(unsigned long addr, unsigned long len);
3029
#endif
3130
#endif
3231

include/asm-sparc64/mman.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@
2424

2525
#ifdef __KERNEL__
2626
#ifndef __ASSEMBLY__
27-
#define arch_mmap_check sparc64_mmap_check
28-
int sparc64_mmap_check(unsigned long addr, unsigned long len,
29-
unsigned long flags);
27+
#define arch_mmap_check(addr,len,flags) sparc64_mmap_check(addr,len)
28+
int sparc64_mmap_check(unsigned long addr, unsigned long len);
3029
#endif
3130
#endif
3231

include/asm-sparc64/thread_info.h

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct thread_info {
3838
struct task_struct *task;
3939
unsigned long flags;
4040
__u8 fpsaved[7];
41-
__u8 pad;
41+
__u8 status;
4242
unsigned long ksp;
4343

4444
/* D$ line 2 */
@@ -217,7 +217,7 @@ register struct thread_info *current_thread_info_reg asm("g6");
217217
* nop
218218
*/
219219
#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
220-
#define TIF_RESTORE_SIGMASK 1 /* restore signal mask in do_signal() */
220+
/* flags bit 1 is available */
221221
#define TIF_SIGPENDING 2 /* signal pending */
222222
#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
223223
#define TIF_PERFCTR 4 /* performance counters active */
@@ -244,14 +244,34 @@ register struct thread_info *current_thread_info_reg asm("g6");
244244
#define _TIF_32BIT (1<<TIF_32BIT)
245245
#define _TIF_SECCOMP (1<<TIF_SECCOMP)
246246
#define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
247-
#define _TIF_RESTORE_SIGMASK (1<<TIF_RESTORE_SIGMASK)
248247
#define _TIF_ABI_PENDING (1<<TIF_ABI_PENDING)
249248
#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
250249

251250
#define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
252-
(_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK | \
251+
(_TIF_SIGPENDING | \
253252
_TIF_NEED_RESCHED | _TIF_PERFCTR))
254253

254+
/*
255+
* Thread-synchronous status.
256+
*
257+
* This is different from the flags in that nobody else
258+
* ever touches our thread-synchronous status, so we don't
259+
* have to worry about atomic accesses.
260+
*
261+
* Note that there are only 8 bits available.
262+
*/
263+
#define TS_RESTORE_SIGMASK 0x0001 /* restore signal mask in do_signal() */
264+
265+
#ifndef __ASSEMBLY__
266+
#define HAVE_SET_RESTORE_SIGMASK 1
267+
static inline void set_restore_sigmask(void)
268+
{
269+
struct thread_info *ti = current_thread_info();
270+
ti->status |= TS_RESTORE_SIGMASK;
271+
set_bit(TIF_SIGPENDING, &ti->flags);
272+
}
273+
#endif /* !__ASSEMBLY__ */
274+
255275
#endif /* __KERNEL__ */
256276

257277
#endif /* _ASM_THREAD_INFO_H */

0 commit comments

Comments
 (0)