2003-03-16 00:14:40

by Pete Zaitcev

[permalink] [raw]
Subject: [s390x] Patch for execve with a mode switch

If I boot an s390x kernel over a 31 bit userland, /sbin/init segfaults
in the dynamic linker. This happens because mm->free_area_cache
is set with TASK_UNMAPPED_BASE macro, which needs the TIF_31BIT
set right. Setting TIF_31BIT in ELF_PLAT_INIT is way too late
for this.

The patch below basically ports what sparc64 does to s390x,
according to the Andrew Morton's comment in fs/binfmt_elf.c.
To tell the truth, I actually use equivalent of this on 2.4,
but I think it's important to get stock 2.5 right.

Martin, please consider and let me know what you think.

Greetings,
-- Pete

--- linux-2.5.64/arch/s390x/kernel/binfmt_elf32.c 2003-03-04 21:34:14.000000000 -0800
+++ linux-2.5.64-sparc/arch/s390x/kernel/binfmt_elf32.c 2003-03-15 16:17:34.000000000 -0800
@@ -39,7 +39,6 @@
#define ELF_PLAT_INIT(_r) \
do { \
_r->gprs[14] = 0; \
- set_thread_flag(TIF_31BIT); \
} while(0)

#define USE_ELF_CORE_DUMP
@@ -87,6 +86,8 @@

#define SET_PERSONALITY(ex, ibcs2) \
do { \
+ if ((current_thread_info()->flags & _TIF_32BIT) == 0) \
+ set_thread_flag(TIF_ABI_PENDING); \
if (ibcs2) \
set_personality(PER_SVR4); \
else if (current->personality != PER_LINUX32) \
--- linux-2.5.64/arch/s390x/kernel/process.c 2003-03-04 21:34:14.000000000 -0800
+++ linux-2.5.64-sparc/arch/s390x/kernel/process.c 2003-03-15 16:02:19.000000000 -0800
@@ -156,9 +156,14 @@

void flush_thread(void)
{
+ struct thread_info *t = current_thread_info();
+ struct task_struct *tsk = t->task;

- current->used_math = 0;
- clear_tsk_thread_flag(current, TIF_USEDFPU);
+ if (t->flags & _TIF_ABI_PENDING)
+ t->flags ^= (_TIF_ABI_PENDING | _TIF_32BIT);
+
+ tsk->used_math = 0;
+ clear_tsk_thread_flag(tsk, TIF_USEDFPU);
}

void release_thread(struct task_struct *dead_task)
--- linux-2.5.64/include/asm-s390x/elf.h 2003-03-04 21:34:43.000000000 -0800
+++ linux-2.5.64-sparc/include/asm-s390x/elf.h 2003-03-15 16:22:04.000000000 -0800
@@ -39,7 +39,6 @@
#define ELF_PLAT_INIT(_r) \
do { \
_r->gprs[14] = 0; \
- clear_thread_flag(TIF_31BIT); \
} while(0)

#define USE_ELF_CORE_DUMP
@@ -79,11 +78,12 @@
#ifdef __KERNEL__
#define SET_PERSONALITY(ex, ibcs2) \
do { \
+ if (current_thread_info()->flags & _TIF_32BIT) \
+ set_thread_flag(TIF_ABI_PENDING); \
if (ibcs2) \
set_personality(PER_SVR4); \
else if (current->personality != PER_LINUX32) \
set_personality(PER_LINUX); \
- clear_thread_flag(TIF_31BIT); \
} while (0)
#endif

--- linux-2.5.64/include/asm-s390x/thread_info.h 2003-03-04 21:34:43.000000000 -0800
+++ linux-2.5.64-sparc/include/asm-s390x/thread_info.h 2003-03-15 16:04:23.000000000 -0800
@@ -74,6 +74,7 @@
#define TIF_SIGPENDING 2 /* signal pending */
#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
#define TIF_RESTART_SVC 4 /* restart svc with new svc number */
+#define TIF_ABI_PENDING 11 /* flush_thread has to switch ABI */
#define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
#define TIF_POLLING_NRFLAG 17 /* true if poll_idle() is polling
TIF_NEED_RESCHED */
@@ -84,6 +85,7 @@
#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
#define _TIF_RESTART_SVC (1<<TIF_RESTART_SVC)
+#define _TIF_ABI_PENDING (1<<TIF_ABI_PENDING)
#define _TIF_USEDFPU (1<<TIF_USEDFPU)
#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
#define _TIF_31BIT (1<<TIF_31BIT)


2003-03-17 15:11:25

by BOEBLINGEN LINUX390

[permalink] [raw]
Subject: Re: [s390x] Patch for execve with a mode switch


Hi Pete,
> If I boot an s390x kernel over a 31 bit userland, /sbin/init segfaults
> in the dynamic linker. This happens because mm->free_area_cache
> is set with TASK_UNMAPPED_BASE macro, which needs the TIF_31BIT
> set right. Setting TIF_31BIT in ELF_PLAT_INIT is way too late
> for this.
mm->free_area_cache can't cause any problems on s390x because it isn't
used. The idea behind mm->free_area_cache is to speed up the search in
get_unmapped_area/arch_get_unmapped_area. But s390x defines its own
version of arch_get_unmapped_area in arch/s390x/kernel/sys_s390.c
which doesn't start the search at mm->free_area_cache.

> The patch below basically ports what sparc64 does to s390x,
> according to the Andrew Morton's comment in fs/binfmt_elf.c.
> To tell the truth, I actually use equivalent of this on 2.4,
> but I think it's important to get stock 2.5 right.
This patch is severly broken. It wouldn't even compile.

To make sure I retested the kernel 2.5.64 with the patches I sent to
this list and ipled a 31 bit userland successfully.

blue skies,
Martin.


2003-03-17 16:53:00

by Pete Zaitcev

[permalink] [raw]
Subject: Re: [s390x] Patch for execve with a mode switch

> From: "BOEBLINGEN LINUX390" <[email protected]>
> Date: Mon, 17 Mar 2003 16:20:37 +0100

> mm->free_area_cache can't cause any problems on s390x because it isn't
> used. [...]
> This patch is severly broken. It wouldn't even compile.

I am sorry, yes, please don't apply to 2.5. It is only needed
on later 2.4, which use the mm->free_area_cache (our old 2.4.9
works ok, but 2.4.20 doesn't).

I still think you are making a mistake defininig your own
arch_get_unmapped_area(), because: 1. sparc64 does it correctly
with the common code, so it can be done; 2. architecture
specific duplicates of common code may bitrot. But have it
your way, I won't resubmit, for the sake of staying aligned
with upstream.

-- Pete

2003-03-18 08:48:34

by BOEBLINGEN LINUX390

[permalink] [raw]
Subject: Re: [s390x] Patch for execve with a mode switch


Hi Pete,
>I still think you are making a mistake defininig your own
>arch_get_unmapped_area(), because: 1. sparc64 does it correctly
>with the common code, so it can be done; 2. architecture
>specific duplicates of common code may bitrot. But have it
>your way, I won't resubmit, for the sake of staying aligned
>with upstream.

I am not too happy with the arch_get_unmapped_area myself. I not
happpy with the TIF_ABI_PENDING bit either, there has to be a
way to do this in a simply and straighforward way.
I'll keep thinking about it.

blue skies,
Martin.


2003-03-18 14:40:29

by Pete Zaitcev

[permalink] [raw]
Subject: Re: [s390x] Patch for execve with a mode switch

> From: "BOEBLINGEN LINUX390" <[email protected]>
> Date: Tue, 18 Mar 2003 09:57:47 +0100

> I am not too happy with the arch_get_unmapped_area myself. I not
> happpy with the TIF_ABI_PENDING bit either, there has to be a
> way to do this in a simply and straighforward way.
> I'll keep thinking about it.

Actually, I agree, but the only way out that I see is to
add yet another macro, which replaces the second SET_PERSONALITY
on 2.5 and adds a hook for 2.4 in that place.

Current 2.5 code looks bizzare:

for (headers) {
if (is header) {
interpreter = x;
SET_PERSONALITY(elf_ex, ibcs2_interpreter);
break;
}
}
if (interpreter) {
} else {
SET_PERSONALITY(elf_ex, ibcs2_interpreter);
}
flush_old_exec();
some_more_core
SET_PERSONALITY(elf_ex, ibcs2_interpreter); // Cries for extermination!
current->mm->free_area_cache = TASK_UNMAPPED_BASE;

Spaghetti wihout goto's!! There's no way to get to the third
SET_PERSONALITY without being there once, so what does that mean?

-- Pete