Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/sh3/sh3 For cpu_switchto(), inherit PSL_IMASK field...



details:   https://anonhg.NetBSD.org/src/rev/8cac8c8f73c9
branches:  trunk
changeset: 1022377:8cac8c8f73c9
user:      rin <rin%NetBSD.org@localhost>
date:      Thu Jul 15 04:58:33 2021 +0000

description:
For cpu_switchto(), inherit PSL_IMASK field of SR between lwp's.

Otherwise, IPL is lost during context switch, which allows improper
interrupts when, e.g., spin mutexes are hold.

With this fix, full ATF is successfully completed on DIAGNOSTIC
kernel (with one KASSERT in uvm_map.c, which triggers kern/51254,
converted to printf).

Thanks uwe@ for review and suggesting optimization.

Also thanks ad@ for useful comment, and ryo@ for giving me reference
manuals of SH-4!

diffstat:

 sys/arch/sh3/sh3/locore_subr.S |  21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)

diffs (42 lines):

diff -r 91e10a9e2fab -r 8cac8c8f73c9 sys/arch/sh3/sh3/locore_subr.S
--- a/sys/arch/sh3/sh3/locore_subr.S    Thu Jul 15 04:05:47 2021 +0000
+++ b/sys/arch/sh3/sh3/locore_subr.S    Thu Jul 15 04:58:33 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore_subr.S,v 1.60 2020/08/03 16:43:44 uwe Exp $     */
+/*     $NetBSD: locore_subr.S,v 1.61 2021/07/15 04:58:33 rin Exp $     */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
 #include <sh3/mmu_sh3.h>
 #include <sh3/mmu_sh4.h>
 
-__KERNEL_RCSID(0, "$NetBSD: locore_subr.S,v 1.60 2020/08/03 16:43:44 uwe Exp $")
+__KERNEL_RCSID(0, "$NetBSD: locore_subr.S,v 1.61 2021/07/15 04:58:33 rin Exp $")
 
 
 /*
@@ -140,7 +140,22 @@
        mov     r10, r1         ! &nlwp->l_md.md_pcb->pcb_sf
        mov     r9, r0          ! return olwp (we are about to clobber r9)
        ldc.l   @r1+, gbr
-       ldc.l   @r1+, sr
+
+       /*
+        * We cannot simply pop SR here; PSL_IMASK field should be
+        * inherited to nlwp. Otherwise, IPL is lost during context
+        * switch, which allows improper interrupts when, e.g.,
+        * spin mutexes are hold.
+        */
+       mov.l   @r1+, r8        ! r8  = new SR
+       mov     #0x78, r9
+       shll    r9              ! r9  =  PSL_IMASK
+       not     r9, r10         ! r10 = ~PSL_IMASK
+       and     r9, r11         ! r11 = old SR & PSL_IMASK
+       and     r10, r8
+       or      r11, r8
+       ldc     r8, sr
+
        lds.l   @r1+, pr
        mov.l   @r1+, r8
        mov.l   @r1+, r9



Home | Main Index | Thread Index | Old Index