* [PATCH 0/2] Preserve the VFP state across the fork() call @ 2011-02-14 10:37 Catalin Marinas 2011-02-14 10:37 ` [PATCH 1/2] ARM: Introduce THREAD_NOTIFY_COPY for copy_thread() hooks Catalin Marinas 2011-02-14 10:37 ` [PATCH 2/2] ARM: Preserve the VFP state during fork Catalin Marinas 0 siblings, 2 replies; 5+ messages in thread From: Catalin Marinas @ 2011-02-14 10:37 UTC (permalink / raw) To: linux-arm-kernel The VFP state should be copied to the child process during the fork() system call. This is important because the d16-d31 registers are callee saved and the compiler may use them for preserving data across function calls. Catalin Marinas (2): ARM: Introduce THREAD_NOTIFY_COPY for copy_thread() hooks ARM: Preserve the VFP state during fork arch/arm/include/asm/thread_notify.h | 1 + arch/arm/kernel/process.c | 2 ++ arch/arm/vfp/vfpmodule.c | 34 +++++++++++++++++++++++++++------- 3 files changed, 30 insertions(+), 7 deletions(-) -- Catalin ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] ARM: Introduce THREAD_NOTIFY_COPY for copy_thread() hooks 2011-02-14 10:37 [PATCH 0/2] Preserve the VFP state across the fork() call Catalin Marinas @ 2011-02-14 10:37 ` Catalin Marinas 2011-02-14 12:12 ` Will Deacon 2011-02-14 10:37 ` [PATCH 2/2] ARM: Preserve the VFP state during fork Catalin Marinas 1 sibling, 1 reply; 5+ messages in thread From: Catalin Marinas @ 2011-02-14 10:37 UTC (permalink / raw) To: linux-arm-kernel This patch adds THREAD_NOTIFY_COPY for colling registered handlers during the copy_thread() function call. It also changes the VFP handler to use a switch statement rather than if..else and ignore this event. Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> --- arch/arm/include/asm/thread_notify.h | 1 + arch/arm/kernel/process.c | 2 ++ arch/arm/vfp/vfpmodule.c | 22 +++++++++++++++------- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/arch/arm/include/asm/thread_notify.h b/arch/arm/include/asm/thread_notify.h index c4391ba..1dc9806 100644 --- a/arch/arm/include/asm/thread_notify.h +++ b/arch/arm/include/asm/thread_notify.h @@ -43,6 +43,7 @@ static inline void thread_notify(unsigned long rc, struct thread_info *thread) #define THREAD_NOTIFY_FLUSH 0 #define THREAD_NOTIFY_EXIT 1 #define THREAD_NOTIFY_SWITCH 2 +#define THREAD_NOTIFY_COPY 3 #endif #endif diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c index 94bbedb..5e1e541 100644 --- a/arch/arm/kernel/process.c +++ b/arch/arm/kernel/process.c @@ -372,6 +372,8 @@ copy_thread(unsigned long clone_flags, unsigned long stack_start, if (clone_flags & CLONE_SETTLS) thread->tp_value = regs->ARM_r3; + thread_notify(THREAD_NOTIFY_COPY, thread); + return 0; } diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c index 0797cb5..5153135 100644 --- a/arch/arm/vfp/vfpmodule.c +++ b/arch/arm/vfp/vfpmodule.c @@ -104,12 +104,17 @@ static void vfp_thread_exit(struct thread_info *thread) static int vfp_notifier(struct notifier_block *self, unsigned long cmd, void *v) { struct thread_info *thread = v; + u32 fpexc; +#ifdef CONFIG_SMP + unsigned int cpu; +#endif - if (likely(cmd == THREAD_NOTIFY_SWITCH)) { - u32 fpexc = fmrx(FPEXC); + switch (cmd) { + case THREAD_NOTIFY_SWITCH: + fpexc = fmrx(FPEXC); #ifdef CONFIG_SMP - unsigned int cpu = thread->cpu; + cpu = thread->cpu; /* * On SMP, if VFP is enabled, save the old state in @@ -134,13 +139,16 @@ static int vfp_notifier(struct notifier_block *self, unsigned long cmd, void *v) * old state. */ fmxr(FPEXC, fpexc & ~FPEXC_EN); - return NOTIFY_DONE; - } + break; - if (cmd == THREAD_NOTIFY_FLUSH) + case THREAD_NOTIFY_FLUSH: vfp_thread_flush(thread); - else + break; + + case THREAD_NOTIFY_EXIT: vfp_thread_exit(thread); + break; + } return NOTIFY_DONE; } ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 1/2] ARM: Introduce THREAD_NOTIFY_COPY for copy_thread() hooks 2011-02-14 10:37 ` [PATCH 1/2] ARM: Introduce THREAD_NOTIFY_COPY for copy_thread() hooks Catalin Marinas @ 2011-02-14 12:12 ` Will Deacon 2011-02-14 16:13 ` Russell King - ARM Linux 0 siblings, 1 reply; 5+ messages in thread From: Will Deacon @ 2011-02-14 12:12 UTC (permalink / raw) To: linux-arm-kernel Hi Catalin, > Subject: [PATCH 1/2] ARM: Introduce THREAD_NOTIFY_COPY for copy_thread() hooks > > This patch adds THREAD_NOTIFY_COPY for colling registered handlers > during the copy_thread() function call. It also changes the VFP handler > to use a switch statement rather than if..else and ignore this event. > > Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> > --- > arch/arm/include/asm/thread_notify.h | 1 + > arch/arm/kernel/process.c | 2 ++ > arch/arm/vfp/vfpmodule.c | 22 +++++++++++++++------- > 3 files changed, 18 insertions(+), 7 deletions(-) This would be useful for the hw-breakpoint code, where we need to clear (memset 0) the breakpoint structures in the child so that they don't get unregistered later on. However, we also need to flush (unregister) breakpoints in flush_thread so that they don't persist across an exec. Ideally, we'd have a single notifier block and act on THREAD_NOTIFY_{FLUSH,COPY} accordingly, but the problem is that THREAD_NOTIFY_FLUSH is only notified *after* zeroing most of the thread structure, so the call is currently inlined into flush_thread and we don't use a notifier. This could be solved by either notifying the FLUSH before zeroing the various thread structures or by moving the zeroing of the debug struct into the hw-breakpoint notifier. The latter probably makes more sense once we've removed the single-step functionality from ptrace. Will ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] ARM: Introduce THREAD_NOTIFY_COPY for copy_thread() hooks 2011-02-14 12:12 ` Will Deacon @ 2011-02-14 16:13 ` Russell King - ARM Linux 0 siblings, 0 replies; 5+ messages in thread From: Russell King - ARM Linux @ 2011-02-14 16:13 UTC (permalink / raw) To: linux-arm-kernel On Mon, Feb 14, 2011 at 12:12:05PM -0000, Will Deacon wrote: > Hi Catalin, > > > Subject: [PATCH 1/2] ARM: Introduce THREAD_NOTIFY_COPY for copy_thread() hooks > > > > This patch adds THREAD_NOTIFY_COPY for colling registered handlers > > during the copy_thread() function call. It also changes the VFP handler > > to use a switch statement rather than if..else and ignore this event. > > > > Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> > > --- > > arch/arm/include/asm/thread_notify.h | 1 + > > arch/arm/kernel/process.c | 2 ++ > > arch/arm/vfp/vfpmodule.c | 22 +++++++++++++++------- > > 3 files changed, 18 insertions(+), 7 deletions(-) > > This would be useful for the hw-breakpoint code, where we need to clear > (memset 0) the breakpoint structures in the child so that they don't get > unregistered later on. > > However, we also need to flush (unregister) breakpoints in flush_thread > so that they don't persist across an exec. Ideally, we'd have a single > notifier block and act on THREAD_NOTIFY_{FLUSH,COPY} accordingly, but > the problem is that THREAD_NOTIFY_FLUSH is only notified *after* zeroing > most of the thread structure, so the call is currently inlined into > flush_thread and we don't use a notifier. It's better to avoid the thread notifier if you don't need all the facilities it offers as it gets called for every thread switch. Every additional registration will add additional cycles to the thread switch. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] ARM: Preserve the VFP state during fork 2011-02-14 10:37 [PATCH 0/2] Preserve the VFP state across the fork() call Catalin Marinas 2011-02-14 10:37 ` [PATCH 1/2] ARM: Introduce THREAD_NOTIFY_COPY for copy_thread() hooks Catalin Marinas @ 2011-02-14 10:37 ` Catalin Marinas 1 sibling, 0 replies; 5+ messages in thread From: Catalin Marinas @ 2011-02-14 10:37 UTC (permalink / raw) To: linux-arm-kernel VFP registers d16-d31 are callee saved registers and must be preserved during function calls, including fork(). The VFP configuration should also be preserved. The patch copies the full VFP state to the child process. Reported-by: Paul Wright <paul.wright@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> --- arch/arm/vfp/vfpmodule.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c index 5153135..cb7a88c 100644 --- a/arch/arm/vfp/vfpmodule.c +++ b/arch/arm/vfp/vfpmodule.c @@ -78,6 +78,14 @@ static void vfp_thread_exit(struct thread_info *thread) put_cpu(); } +static void vfp_thread_copy(struct thread_info *thread) +{ + struct thread_info *parent = current_thread_info(); + + vfp_sync_hwstate(parent); + thread->vfpstate = parent->vfpstate; +} + /* * When this function is called with the following 'cmd's, the following * is true while this function is being run: @@ -148,6 +156,10 @@ static int vfp_notifier(struct notifier_block *self, unsigned long cmd, void *v) case THREAD_NOTIFY_EXIT: vfp_thread_exit(thread); break; + + case THREAD_NOTIFY_COPY: + vfp_thread_copy(thread); + break; } return NOTIFY_DONE; ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-02-14 16:13 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-02-14 10:37 [PATCH 0/2] Preserve the VFP state across the fork() call Catalin Marinas 2011-02-14 10:37 ` [PATCH 1/2] ARM: Introduce THREAD_NOTIFY_COPY for copy_thread() hooks Catalin Marinas 2011-02-14 12:12 ` Will Deacon 2011-02-14 16:13 ` Russell King - ARM Linux 2011-02-14 10:37 ` [PATCH 2/2] ARM: Preserve the VFP state during fork Catalin Marinas
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).