linux-user: Avoid conditional cpu_reset()
RFC PATCH 1/1 linux-user: Avoid conditional cpu_reset()
Some CPUs reset as part of cpu_init(), some others were reset afterwards, some not at all. While some targets didn't implement a cpu_[state_]reset() function, QOM cpu_reset() is always available. There's nothing wrong with resetting twice on startup, so drop the #ifdef.
---
This had been discussed as a possible cleanup for the #ifdef. I am uncertain whether we should do this since it hides the TODO item of investigating ppc and sparc CPU reset.
linux-user/main.c | 2 -- 1 file changed, 2 deletions(-)
linux-user/main.c +0 -2
@@ -3637,9 +3637,7 @@ int main(int argc, char **argv, char **envp)fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } -#if defined(TARGET_SPARC ) || defined(TARGET_PPC )cpu_reset (ENV_GET_CPU (env)); -#endif thread_cpu =ENV_GET_CPU (env);
Signature · 1 line
1.8.1.4
Quoted 22 lines · Andreas Färber
Some CPUs reset as part of
cpu_init(), some others were reset afterwards, some not at all. While some targets didn't implement a cpu_[state_]reset() function, QOMcpu_reset()is always available. There's nothing wrong with resetting twice on startup, so drop the #ifdef.Suggested-by Peter Maydell <[email protected]>Signed-off-by Andreas Färber <[email protected]>Cc Eduardo Habkost <[email protected]>---
This had been discussed as a possible cleanup for the #ifdef. I am uncertain whether we should do this since it hides the TODO item of investigating ppc and sparc CPU reset.linux-user/main.c | 2 -- 1 file changed, 2 deletions(-)linux-user/main.c +0
-0
linux-user/main.c int main(int argc, char **argv, char **envp) · line 3642
Quoted 6 lines
linux-user/main.c +0
-2@@ -3637,9 +3637,7 @@ int main(int argc, char **argv, char **envp)fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } -#if defined(TARGET_SPARC ) || defined(TARGET_PPC )cpu_reset (ENV_GET_CPU (env)); -#endif
Most of the cpu_reset() implementations I have looked at (including sparc) contain something like:
memset(env, 0, offsetof(CPUXXXState, breakpoints));
Isn't this clearing userspace registers that are not supposed to be touched by clone()?
Signature · 1 line
Eduardo
Quoted 33 lines · Eduardo Habkost
Quoted 22 lines · Andreas Färber
Some CPUs reset as part of
cpu_init(), some others were reset afterwards, some not at all. While some targets didn't implement a cpu_[state_]reset() function, QOMcpu_reset()is always available. There's nothing wrong with resetting twice on startup, so drop the #ifdef.Suggested-by Peter Maydell <[email protected]>Signed-off-by Andreas Färber <[email protected]>Cc Eduardo Habkost <[email protected]>---
This had been discussed as a possible cleanup for the #ifdef. I am uncertain whether we should do this since it hides the TODO item of investigating ppc and sparc CPU reset.linux-user/main.c | 2 -- 1 file changed, 2 deletions(-)linux-user/main.c +0
-0linux-user/main.c int main(int argc, char **argv, char **envp) · line 3642
Quoted 6 lines
linux-user/main.c +0
-2@@ -3637,9 +3637,7 @@ int main(int argc, char **argv, char **envp)fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } -#if defined(TARGET_SPARC ) || defined(TARGET_PPC )cpu_reset (ENV_GET_CPU (env)); -#endif Most of the
cpu_reset()implementations I have looked at (including sparc) contain something like:
Quoted 4 lines
memset(env, 0, offsetof(CPUXXXState, breakpoints));Isn't this clearing userspace registers that are not supposed to be touched by
clone()?
You're thinking about the other cpu_reset() -- this one is in main.c and happens only for the main thread, immediately after we've created that thread's CPU, and before we set up its registers for initial program start. The cpu_reset() that sometimes happens in the clone() path is in syscall.c (and is addressed by patch
http://patchwork.ozlabs.org/patch/257232/ )
-- PMM
Quoted 39 lines · Peter Maydell
Quoted 33 lines · Eduardo Habkost
Quoted 22 lines · Andreas Färber
Some CPUs reset as part of
cpu_init(), some others were reset afterwards, some not at all. While some targets didn't implement a cpu_[state_]reset() function, QOMcpu_reset()is always available. There's nothing wrong with resetting twice on startup, so drop the #ifdef.Suggested-by Peter Maydell <[email protected]>Signed-off-by Andreas Färber <[email protected]>Cc Eduardo Habkost <[email protected]>---
This had been discussed as a possible cleanup for the #ifdef. I am uncertain whether we should do this since it hides the TODO item of investigating ppc and sparc CPU reset.linux-user/main.c | 2 -- 1 file changed, 2 deletions(-)linux-user/main.c +0
-0linux-user/main.c int main(int argc, char **argv, char **envp) · line 3642
Quoted 6 lines
linux-user/main.c +0
-2@@ -3637,9 +3637,7 @@ int main(int argc, char **argv, char **envp)fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } -#if defined(TARGET_SPARC ) || defined(TARGET_PPC )cpu_reset (ENV_GET_CPU (env)); -#endif Most of the
cpu_reset()implementations I have looked at (including sparc) contain something like:Quoted 4 lines
memset(env, 0, offsetof(CPUXXXState, breakpoints));Isn't this clearing userspace registers that are not supposed to be touched by
clone()?
Quoted 7 lines
You're thinking about the other
cpu_reset()-- this one is inmain.cand happens only for the main thread, immediately after we've created that thread's CPU, and before we set up its registers for initial program start. Thecpu_reset()that sometimes happens in theclone()path is insyscall.c(and is addressed by patch
http://patchwork.ozlabs.org/patch/257232/ )
Oh, nevermind. We discussed do_fork() for so long that I didn't even notice we had _another_ cpu_reset() #ifdef on main.c.
In this case the patch looks simple and safe, to me.
Signature · 1 line
Eduardo