From owner-svn-src-all@freebsd.org Mon Dec 16 20:15:06 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 4CF5D1CDC63; Mon, 16 Dec 2019 20:15:06 +0000 (UTC) (envelope-from jeff@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47cCDp1F3Dz4HG7; Mon, 16 Dec 2019 20:15:06 +0000 (UTC) (envelope-from jeff@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 25C3028C3; Mon, 16 Dec 2019 20:15:06 +0000 (UTC) (envelope-from jeff@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xBGKF66l050293; Mon, 16 Dec 2019 20:15:06 GMT (envelope-from jeff@FreeBSD.org) Received: (from jeff@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xBGKF4v2050284; Mon, 16 Dec 2019 20:15:04 GMT (envelope-from jeff@FreeBSD.org) Message-Id: <201912162015.xBGKF4v2050284@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jeff set sender to jeff@FreeBSD.org using -f From: Jeff Roberson Date: Mon, 16 Dec 2019 20:15:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r355819 - in head/sys: arm/arm arm64/arm64 i386/i386 mips/mips powerpc/powerpc riscv/riscv X-SVN-Group: head X-SVN-Commit-Author: jeff X-SVN-Commit-Paths: in head/sys: arm/arm arm64/arm64 i386/i386 mips/mips powerpc/powerpc riscv/riscv X-SVN-Commit-Revision: 355819 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Dec 2019 20:15:06 -0000 Author: jeff Date: Mon Dec 16 20:15:04 2019 New Revision: 355819 URL: https://svnweb.freebsd.org/changeset/base/355819 Log: Repeat the spinlock_enter/exit pattern from amd64 on other architectures to fix an assert violation introduced in r355784. Without this spinlock_exit() may see owepreempt and switch before reducing the spinlock count. amd64 had been optimized to do a single critical enter/exit regardless of the number of spinlocks which avoided the problem and this optimization had not been applied elsewhere. Reported by: emaste Suggested by: rlibby Discussed with: jhb, rlibby Tested by: manu (arm64) Modified: head/sys/arm/arm/machdep.c head/sys/arm64/arm64/machdep.c head/sys/i386/i386/machdep.c head/sys/mips/mips/machdep.c head/sys/powerpc/powerpc/machdep.c head/sys/riscv/riscv/machdep.c Modified: head/sys/arm/arm/machdep.c ============================================================================== --- head/sys/arm/arm/machdep.c Mon Dec 16 20:07:04 2019 (r355818) +++ head/sys/arm/arm/machdep.c Mon Dec 16 20:15:04 2019 (r355819) @@ -389,9 +389,9 @@ spinlock_enter(void) cspr = disable_interrupts(PSR_I | PSR_F); td->td_md.md_spinlock_count = 1; td->td_md.md_saved_cspr = cspr; + critical_enter(); } else td->td_md.md_spinlock_count++; - critical_enter(); } void @@ -401,11 +401,12 @@ spinlock_exit(void) register_t cspr; td = curthread; - critical_exit(); cspr = td->td_md.md_saved_cspr; td->td_md.md_spinlock_count--; - if (td->td_md.md_spinlock_count == 0) + if (td->td_md.md_spinlock_count == 0) { + critical_exit(); restore_interrupts(cspr); + } } /* Modified: head/sys/arm64/arm64/machdep.c ============================================================================== --- head/sys/arm64/arm64/machdep.c Mon Dec 16 20:07:04 2019 (r355818) +++ head/sys/arm64/arm64/machdep.c Mon Dec 16 20:15:04 2019 (r355819) @@ -635,9 +635,9 @@ spinlock_enter(void) daif = intr_disable(); td->td_md.md_spinlock_count = 1; td->td_md.md_saved_daif = daif; + critical_enter(); } else td->td_md.md_spinlock_count++; - critical_enter(); } void @@ -647,11 +647,12 @@ spinlock_exit(void) register_t daif; td = curthread; - critical_exit(); daif = td->td_md.md_saved_daif; td->td_md.md_spinlock_count--; - if (td->td_md.md_spinlock_count == 0) + if (td->td_md.md_spinlock_count == 0) { + critical_exit(); intr_restore(daif); + } } #ifndef _SYS_SYSPROTO_H_ Modified: head/sys/i386/i386/machdep.c ============================================================================== --- head/sys/i386/i386/machdep.c Mon Dec 16 20:07:04 2019 (r355818) +++ head/sys/i386/i386/machdep.c Mon Dec 16 20:15:04 2019 (r355819) @@ -2679,9 +2679,9 @@ spinlock_enter(void) flags = intr_disable(); td->td_md.md_spinlock_count = 1; td->td_md.md_saved_flags = flags; + critical_enter(); } else td->td_md.md_spinlock_count++; - critical_enter(); } void @@ -2691,11 +2691,12 @@ spinlock_exit(void) register_t flags; td = curthread; - critical_exit(); flags = td->td_md.md_saved_flags; td->td_md.md_spinlock_count--; - if (td->td_md.md_spinlock_count == 0) + if (td->td_md.md_spinlock_count == 0) { + critical_exit(); intr_restore(flags); + } } #if defined(I586_CPU) && !defined(NO_F00F_HACK) Modified: head/sys/mips/mips/machdep.c ============================================================================== --- head/sys/mips/mips/machdep.c Mon Dec 16 20:07:04 2019 (r355818) +++ head/sys/mips/mips/machdep.c Mon Dec 16 20:15:04 2019 (r355819) @@ -516,9 +516,9 @@ spinlock_enter(void) intr = intr_disable(); td->td_md.md_spinlock_count = 1; td->td_md.md_saved_intr = intr; + critical_enter(); } else td->td_md.md_spinlock_count++; - critical_enter(); } void @@ -528,11 +528,12 @@ spinlock_exit(void) register_t intr; td = curthread; - critical_exit(); intr = td->td_md.md_saved_intr; td->td_md.md_spinlock_count--; - if (td->td_md.md_spinlock_count == 0) + if (td->td_md.md_spinlock_count == 0) { + critical_exit(); intr_restore(intr); + } } /* Modified: head/sys/powerpc/powerpc/machdep.c ============================================================================== --- head/sys/powerpc/powerpc/machdep.c Mon Dec 16 20:07:04 2019 (r355818) +++ head/sys/powerpc/powerpc/machdep.c Mon Dec 16 20:15:04 2019 (r355819) @@ -499,9 +499,9 @@ spinlock_enter(void) msr = intr_disable(); td->td_md.md_spinlock_count = 1; td->td_md.md_saved_msr = msr; + critical_enter(); } else td->td_md.md_spinlock_count++; - critical_enter(); } void @@ -511,10 +511,10 @@ spinlock_exit(void) register_t msr; td = curthread; - critical_exit(); msr = td->td_md.md_saved_msr; td->td_md.md_spinlock_count--; if (td->td_md.md_spinlock_count == 0) { + critical_exit(); intr_restore(msr); nop_prio_medium(); } Modified: head/sys/riscv/riscv/machdep.c ============================================================================== --- head/sys/riscv/riscv/machdep.c Mon Dec 16 20:07:04 2019 (r355818) +++ head/sys/riscv/riscv/machdep.c Mon Dec 16 20:15:04 2019 (r355819) @@ -489,9 +489,9 @@ spinlock_enter(void) reg = intr_disable(); td->td_md.md_spinlock_count = 1; td->td_md.md_saved_sstatus_ie = reg; + critical_enter(); } else td->td_md.md_spinlock_count++; - critical_enter(); } void @@ -501,11 +501,12 @@ spinlock_exit(void) register_t sstatus_ie; td = curthread; - critical_exit(); sstatus_ie = td->td_md.md_saved_sstatus_ie; td->td_md.md_spinlock_count--; - if (td->td_md.md_spinlock_count == 0) + if (td->td_md.md_spinlock_count == 0) { + critical_exit(); intr_restore(sstatus_ie); + } } #ifndef _SYS_SYSPROTO_H_