Tue Jul 7 00:37:46 2020 UTC ()
For booke, restore callee saved registers when recovery for page fault
fails for kernel.

OOPS! How on the earth we had overlooked this error so far...


(rin)
diff -r1.29 -r1.30 src/sys/arch/powerpc/booke/trap.c

cvs diff -r1.29 -r1.30 src/sys/arch/powerpc/booke/trap.c (expand / switch to unified diff)

--- src/sys/arch/powerpc/booke/trap.c 2020/07/06 10:13:02 1.29
+++ src/sys/arch/powerpc/booke/trap.c 2020/07/07 00:37:46 1.30
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: trap.c,v 1.29 2020/07/06 10:13:02 rin Exp $ */ 1/* $NetBSD: trap.c,v 1.30 2020/07/07 00:37:46 rin Exp $ */
2/*- 2/*-
3 * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc. 3 * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * This code is derived from software contributed to The NetBSD Foundation 6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects 7 * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects
8 * Agency and which was developed by Matt Thomas of 3am Software Foundry. 8 * Agency and which was developed by Matt Thomas of 3am Software Foundry.
9 * 9 *
10 * This material is based upon work supported by the Defense Advanced Research 10 * This material is based upon work supported by the Defense Advanced Research
11 * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under 11 * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under
12 * Contract No. N66001-09-C-2073. 12 * Contract No. N66001-09-C-2073.
13 * Approved for Public Release, Distribution Unlimited 13 * Approved for Public Release, Distribution Unlimited
14 * 14 *
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE. 34 * POSSIBILITY OF SUCH DAMAGE.
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.29 2020/07/06 10:13:02 rin Exp $"); 38__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.30 2020/07/07 00:37:46 rin Exp $");
39 39
40#ifdef _KERNEL_OPT 40#ifdef _KERNEL_OPT
41#include "opt_altivec.h" 41#include "opt_altivec.h"
42#include "opt_ddb.h" 42#include "opt_ddb.h"
43#endif 43#endif
44 44
45#include <sys/param.h> 45#include <sys/param.h>
46#include <sys/systm.h> 46#include <sys/systm.h>
47#include <sys/siginfo.h> 47#include <sys/siginfo.h>
48#include <sys/lwp.h> 48#include <sys/lwp.h>
49#include <sys/proc.h> 49#include <sys/proc.h>
50#include <sys/cpu.h> 50#include <sys/cpu.h>
51#include <sys/kauth.h> 51#include <sys/kauth.h>
@@ -680,26 +680,27 @@ static bool @@ -680,26 +680,27 @@ static bool
680onfaulted(struct trapframe *tf, register_t rv) 680onfaulted(struct trapframe *tf, register_t rv)
681{ 681{
682 struct lwp * const l = curlwp; 682 struct lwp * const l = curlwp;
683 struct pcb * const pcb = lwp_getpcb(l); 683 struct pcb * const pcb = lwp_getpcb(l);
684 struct faultbuf * const fb = pcb->pcb_onfault; 684 struct faultbuf * const fb = pcb->pcb_onfault;
685 if (fb == NULL) 685 if (fb == NULL)
686 return false; 686 return false;
687 tf->tf_srr0 = fb->fb_pc; 687 tf->tf_srr0 = fb->fb_pc;
688 tf->tf_srr1 = fb->fb_msr; 688 tf->tf_srr1 = fb->fb_msr;
689 tf->tf_cr = fb->fb_cr; 689 tf->tf_cr = fb->fb_cr;
690 tf->tf_fixreg[1] = fb->fb_sp; 690 tf->tf_fixreg[1] = fb->fb_sp;
691 tf->tf_fixreg[2] = fb->fb_r2; 691 tf->tf_fixreg[2] = fb->fb_r2;
692 tf->tf_fixreg[3] = rv; 692 tf->tf_fixreg[3] = rv;
 693 memcpy(&tf->tf_fixreg[13], fb->fb_fixreg, sizeof(fb->fb_fixreg));
693 pcb->pcb_onfault = NULL; 694 pcb->pcb_onfault = NULL;
694 return true; 695 return true;
695} 696}
696 697
697void 698void
698trap(enum ppc_booke_exceptions trap_code, struct trapframe *tf) 699trap(enum ppc_booke_exceptions trap_code, struct trapframe *tf)
699{ 700{
700 const bool usertrap = usertrap_p(tf); 701 const bool usertrap = usertrap_p(tf);
701 struct cpu_info * const ci = curcpu(); 702 struct cpu_info * const ci = curcpu();
702 struct lwp * const l = curlwp; 703 struct lwp * const l = curlwp;
703 struct proc * const p = l->l_proc; 704 struct proc * const p = l->l_proc;
704 ksiginfo_t ksi; 705 ksiginfo_t ksi;
705 int rv = EACCES; 706 int rv = EACCES;