Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 18 Jan 2018 07:42:51 +0000 (UTC)
From:      Wojciech Macek <wma@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r328112 - head/sys/powerpc/powerpc
Message-ID:  <201801180742.w0I7gpav058438@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: wma
Date: Thu Jan 18 07:42:51 2018
New Revision: 328112
URL: https://svnweb.freebsd.org/changeset/base/328112

Log:
  PPC64: fix TOC behavior on process initialization
  
  Set stack pointer to correct value after thread's stack pointer restore
  
  Restoring new thread's stack pointer caused stack corruption because
  restored stack pointer didn't point to callee (cpu_switch) stack frame but
  caller stack frame.
  
  As a result we had mysterious errors in caller function (sched_switch).
  
  Solution: simply set stack pointer to correct value
  
  Also, initialize TOC to a valid pointer once the thread is being
  created.
  
  Created by:            Patryk Duda <pdk@semihalf.com>
  Submitted by:          Wojciech Macek <wma@semihalf.com>
  Obtained from:         Semihalf
  Reviewed by:           nwhitehorn
  Differential revision: https://reviews.freebsd.org/D13947
  Sponsored by:          QCM Technologies

Modified:
  head/sys/powerpc/powerpc/swtch64.S
  head/sys/powerpc/powerpc/vm_machdep.c

Modified: head/sys/powerpc/powerpc/swtch64.S
==============================================================================
--- head/sys/powerpc/powerpc/swtch64.S	Thu Jan 18 07:41:04 2018	(r328111)
+++ head/sys/powerpc/powerpc/swtch64.S	Thu Jan 18 07:42:51 2018	(r328112)
@@ -160,6 +160,7 @@ blocked_loop:
 	
 	ld	%r17,TD_PCB(%r13)	/* Get new PCB */
 	ld	%r1,PCB_SP(%r17)	/* Load the stack pointer */
+	addi	%r1,%r1,-48		/* Remember about cpu_switch stack frame */
 
 	/* Release old thread now that we have a stack pointer set up */
 	cmpdi	%r14,0

Modified: head/sys/powerpc/powerpc/vm_machdep.c
==============================================================================
--- head/sys/powerpc/powerpc/vm_machdep.c	Thu Jan 18 07:41:04 2018	(r328111)
+++ head/sys/powerpc/powerpc/vm_machdep.c	Thu Jan 18 07:42:51 2018	(r328112)
@@ -190,6 +190,9 @@ cpu_fork_kthread_handler(struct thread *td, void (*fun
 
 	cf = (struct callframe *)td->td_pcb->pcb_sp;
 
+	#if defined(__powerpc64__) && (!defined(_CALL_ELF) || _CALL_ELF == 1)
+	cf->cf_toc = ((register_t *)func)[1];
+	#endif
 	cf->cf_func = (register_t)func;
 	cf->cf_arg0 = (register_t)arg;
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801180742.w0I7gpav058438>