public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Again: UML on s390 (31Bit)
@ 2005-04-27 20:21 Bodo Stroesser
  2005-04-28  8:36 ` Martin Schwidefsky
  0 siblings, 1 reply; 24+ messages in thread
From: Bodo Stroesser @ 2005-04-27 20:21 UTC (permalink / raw)
  To: linux-kernel; +Cc: Martin Schwidefsky, Jeff Dike, user-mode-linux devel

I'm sending this mail again, because unfortunately I didn't receive
any reply. It was sent the first time at April, 5th.

Regards, Bodo


Hi,

currently I'm porting UML to s390 31-bit.
A first 2.6.11 UML system already is running in UML-SKAS0 mode,
which normally should run on an unpatched host (no skas3-patch).

To make UML build and run on s390, I needed to do these two little
changes (the patches are copy and paste. I hope that doesn't hurt,
since they are very small):

1) UML includes some of the subarch's (s390) headers. I had to
    change one of them with the following one-liner, to make this
    compile. AFAICS, this change doesn't break compilation of s390
    itself.

==============================================================================
--- linux-2.6.11.orig/include/asm-s390/user.h	2004-12-09 18:45:02.000000000 +0100
+++ linux-2.6.11/include/asm-s390/user.h	2004-12-09 18:48:11.000000000 +0100
@@ -10,7 +10,7 @@
  #define _S390_USER_H

  #include <asm/page.h>
-#include <linux/ptrace.h>
+#include <asm/ptrace.h>
  /* Core file format: The core file is written in such a way that gdb
     can understand it and provide useful information to the user (under
     linux we use the 'trad-core' bfd).  There are quite a number of
==============================================================================

2) UML needs to intercept syscalls via ptrace to invalidate the syscall,
    read syscall's parameters and write the result with the result of
    UML's syscall processing. Also, UML needs to make sure, that the host
    does no syscall restart processing. On i386 for example, this can be
    done by writing -1 to orig_eax on the 2nd syscall interception
    (orig_eax is the syscall number, which after the interception is used
    as a "interrupt was a syscall" flag only.
    Unfortunately, s390 holds syscall number and syscall result in gpr2 and
    its "interrupt was a syscall" flag (trap) is unreachable via ptrace.
    So I changed the host to set trap to -1, if the syscall number is written
    to a negative value on the first syscall interception.
    I hope, this adds what UML needs without changing ptrace visibly to other
    ptrace users.
    (This isn't tested on a 2.6 host yet, because my host still is a 2.4.21 SuSE.
    But I've adapted this change to 2.4 and tested, it works.)


==============================================================================
--- linux-2.6.11.orig/arch/s390/kernel/ptrace.c	2005-04-04 18:57:38.000000000 +0200
+++ linux-2.6.11/arch/s390/kernel/ptrace.c	2005-04-04 19:01:51.000000000 +0200
@@ -726,6 +726,13 @@
				  ? 0x80 : 0));

  	/*
+	 * If debugger has set an invalid syscall number,
+	 * we prepare to skip syscall restart handling
+	 */
+	if (!entryexit && (long )regs->gprs[2] < 0 )
+		regs->trap = -1;
+
+	/*
  	 * this isn't the same as continuing with a signal, but it will do
  	 * for normal use.  strace only continues with a signal if the
  	 * stopping signal is not SIGTRAP.  -brl
==============================================================================


It would be very helpful for me, if these changes could go into s390 mainline.
If there is something wrong with them, please help me find a better solution.


Regards, Bodo

^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re: Again: UML on s390 (31Bit)
@ 2005-05-04 16:04 Martin Schwidefsky
  2005-05-04 19:02 ` Bodo Stroesser
  0 siblings, 1 reply; 24+ messages in thread
From: Martin Schwidefsky @ 2005-05-04 16:04 UTC (permalink / raw)
  To: bstroesser; +Cc: jdike, linux-kernel, user-mode-linux-devel

> Yes. That's what I suggested as a "special magic number". Only if that magic
> is written as syscall number at the first interception, syscall_trace() would
> modify regs->trap to -1.
> Currently my patch uses -1 as the magic number, but there might be better
> choices.
> 
> > 3) -Eyyy, skip the system call but leave regs->trap intact so that a pending
> >    signal will restart the system call.
> Not only -Eyyy, but all values unequal to "special magic number" could leave
> regs->trap intact.
> 
> > 
> > But we really have to be very careful not to break either strace or gdb if
> > we do this change. Probably it is much easier to introduce PTRACE_SET/GET_TRAP.
> It's easier for s390-kernel, but from UML's point of view, the magic number
> solution would be better.
> Anyway, if you decide not to allow the magic number, we have to find a way
> to use PTRACE_SETTRAP in UML without having to call it too often (Performance).
> Because of UML's splitting in kernel-obj and user-obj, this might be a bit
> tricky.
> 
> BTW: I see no reason to implement PTRACE_GETTRAP, as
> PTRACE_SETOPTIONS/PTRACE_TRACESYSGOOD give us a way to distinguish between
> syscall interceptions and other SIGTRAPs.

I talked with Uli about the problem and we came up with a more
elegant solution. We already have a debugger specific code in
do_signal that sets up the registers for system call restarting
BEFORE calling the debugger. Only if the debugger did not change
the restart psw and the return value still indicates 
-ERESTARTNOHAND or -ERESTARTSYS we undo this change. In the case
that the debugger did change the psw or the return value we do
not want to restart a system call if another signal is pending.
This is in fact a bug in the signal delivery code. To fix it we
have to set regs->traps to something != __LC_SVC_OLD_PSW while
the debugger has control. regs->traps is reset to the value
indicating a system call if the system call is not restarted
after all.

Will that make UML happy?

blue skies,
  Martin.

---

Index: arch/s390/kernel/signal.c
===================================================================
RCS file: /home/cvs/linux-2.5/arch/s390/kernel/signal.c,v
retrieving revision 1.22
diff -u -p -r1.22 signal.c
--- arch/s390/kernel/signal.c	23 Mar 2005 08:30:01 -0000	1.22
+++ arch/s390/kernel/signal.c	4 May 2005 14:51:31 -0000
@@ -482,6 +482,7 @@ int do_signal(struct pt_regs *regs, sigs
 		} else if (retval == -ERESTART_RESTARTBLOCK) {
 			regs->gprs[2] = -EINTR;
 		}
+		regs->trap = -1;
 	}
 
 	/* Get signal to deliver.  When running under ptrace, at this point
@@ -497,6 +498,7 @@ int do_signal(struct pt_regs *regs, sigs
 			      & SA_RESTART))) {
 			regs->gprs[2] = -EINTR;
 			regs->psw.addr = continue_addr;
+			regs->trap = __LC_SVC_OLD_PSW;
 		}
 	}
 

^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re: Again: UML on s390 (31Bit)
@ 2005-05-04 21:33 Ulrich Weigand
  2005-05-06 13:04 ` Bodo Stroesser
  0 siblings, 1 reply; 24+ messages in thread
From: Ulrich Weigand @ 2005-05-04 21:33 UTC (permalink / raw)
  To: bstroesser; +Cc: schwidefsky, linux-kernel

Bodo Stroesser wrote:

>Unfortunately, I guess this will not help. But maybe I'm missing
>something, as I don't even understand, what the effect of the
>attached patch should be.
Have you tried it?

>AFAICS, after each call to do_signal(),
>entry.S will return to user without regs->trap being checked again.
>do_signal() is the only place, where regs->trap is checked, and
>it will be called on return to user exactly once.
It will be called multiple times if *multiple* signals are pending,
and this is exactly the situation in your problem case (some other
signal is pending after the ptrace intercept SIGTRAP was delievered).

>So a practical solution should allow to reset regs->trap while the
>child is on the first or second syscall interception.
This is exactly what this patch is supposed to do: whenever during
a ptrace intercept the PSW is changed (as it presumably is by your
sigreturn implementation), regs->trap is automatically reset.

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  Linux on zSeries Development
  Ulrich.Weigand@de.ibm.com

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

end of thread, other threads:[~2005-06-01 10:50 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-27 20:21 Again: UML on s390 (31Bit) Bodo Stroesser
2005-04-28  8:36 ` Martin Schwidefsky
2005-04-28  9:54   ` Bodo Stroesser
2005-04-28 13:03     ` Martin Schwidefsky
2005-04-28 13:41       ` Bodo Stroesser
2005-04-28 15:02         ` [uml-devel] " Bodo Stroesser
2005-04-28 15:27         ` Martin Schwidefsky
2005-04-28 18:50           ` Bodo Stroesser
2005-04-29 11:47             ` Martin Schwidefsky
2005-04-29 12:47               ` Bodo Stroesser
  -- strict thread matches above, loose matches on Subject: below --
2005-05-04 16:04 Martin Schwidefsky
2005-05-04 19:02 ` Bodo Stroesser
2005-05-04 21:33 Ulrich Weigand
2005-05-06 13:04 ` Bodo Stroesser
2005-05-13 15:07   ` Bodo Stroesser
2005-05-13 15:26     ` Martin Schwidefsky
2005-05-13 15:37       ` Bodo Stroesser
2005-05-13 15:40         ` Martin Schwidefsky
2005-05-13 15:45           ` Bodo Stroesser
2005-05-13 15:50             ` Martin Schwidefsky
2005-05-13 16:06               ` Bodo Stroesser
2005-05-20 10:09     ` Bodo Stroesser
2005-05-31 16:57       ` Martin Schwidefsky
2005-06-01 10:50         ` Bodo Stroesser

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox