From owner-svn-src-all@freebsd.org Fri Dec 14 21:07:13 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9064A1316B69; Fri, 14 Dec 2018 21:07:13 +0000 (UTC) (envelope-from markj@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 350F16B6E0; Fri, 14 Dec 2018 21:07:13 +0000 (UTC) (envelope-from markj@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 04BC95306; Fri, 14 Dec 2018 21:07:13 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wBEL7CsY003347; Fri, 14 Dec 2018 21:07:12 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wBEL7CxP003346; Fri, 14 Dec 2018 21:07:12 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201812142107.wBEL7CxP003346@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Fri, 14 Dec 2018 21:07:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r342100 - head/sys/riscv/riscv X-SVN-Group: head X-SVN-Commit-Author: markj X-SVN-Commit-Paths: head/sys/riscv/riscv X-SVN-Commit-Revision: 342100 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 350F16B6E0 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.83 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-0.99)[-0.990,0]; NEURAL_HAM_LONG(-0.88)[-0.881,0]; NEURAL_HAM_SHORT(-0.96)[-0.965,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] 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: Fri, 14 Dec 2018 21:07:13 -0000 Author: markj Date: Fri Dec 14 21:07:12 2018 New Revision: 342100 URL: https://svnweb.freebsd.org/changeset/base/342100 Log: Add some more checking to the RISC-V page fault handler. - Panic immediately if witness says we're holding non-sleepable locks. This helps ensure that we don't recurse on the pmap lock in pmap_fault_fixup(). - Panic if the kernel faults on a user address without setting an onfault handler. - Panic if the fault occurred in a critical section or interrupt handler, like we do on other platforms. - Fix some style issues in trap_pfault(). Reviewed by: jhb MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D18561 Modified: head/sys/riscv/riscv/trap.c Modified: head/sys/riscv/riscv/trap.c ============================================================================== --- head/sys/riscv/riscv/trap.c Fri Dec 14 21:04:30 2018 (r342099) +++ head/sys/riscv/riscv/trap.c Fri Dec 14 21:07:12 2018 (r342100) @@ -167,7 +167,7 @@ svc_handler(struct trapframe *frame) } static void -data_abort(struct trapframe *frame, int lower) +data_abort(struct trapframe *frame, int usermode) { struct vm_map *map; uint64_t sbadaddr; @@ -176,9 +176,7 @@ data_abort(struct trapframe *frame, int lower) vm_prot_t ftype; vm_offset_t va; struct proc *p; - int ucode; - int error; - int sig; + int error, sig, ucode; #ifdef KDB if (kdb_active) { @@ -188,19 +186,23 @@ data_abort(struct trapframe *frame, int lower) #endif td = curthread; + p = td->td_proc; pcb = td->td_pcb; sbadaddr = frame->tf_sbadaddr; - p = td->td_proc; + if (td->td_critnest != 0 || td->td_intr_nesting_level != 0 || + WITNESS_CHECK(WARN_SLEEPOK | WARN_GIANTOK, NULL, + "Kernel page fault") != 0) + goto fatal; - if (lower) + if (usermode) map = &td->td_proc->p_vmspace->vm_map; + else if (sbadaddr >= VM_MAX_USER_ADDRESS) + map = kernel_map; else { - /* The top bit tells us which range to use */ - if ((sbadaddr >> 63) == 1) - map = kernel_map; - else - map = &td->td_proc->p_vmspace->vm_map; + if (pcb->pcb_onfault == 0) + goto fatal; + map = &td->td_proc->p_vmspace->vm_map; } va = trunc_page(sbadaddr); @@ -241,7 +243,7 @@ data_abort(struct trapframe *frame, int lower) } if (error != KERN_SUCCESS) { - if (lower) { + if (usermode) { sig = SIGSEGV; if (error == KERN_PROTECTION_FAILURE) ucode = SEGV_ACCERR; @@ -249,21 +251,23 @@ data_abort(struct trapframe *frame, int lower) ucode = SEGV_MAPERR; call_trapsignal(td, sig, ucode, (void *)sbadaddr); } else { - if (td->td_intr_nesting_level == 0 && - pcb->pcb_onfault != 0) { + if (pcb->pcb_onfault != 0) { frame->tf_a[0] = error; frame->tf_sepc = pcb->pcb_onfault; return; } - dump_regs(frame); - panic("vm_fault failed: %lx, va 0x%016lx", - frame->tf_sepc, sbadaddr); + goto fatal; } } done: - if (lower) + if (usermode) userret(td, frame); + return; + +fatal: + dump_regs(frame); + panic("Fatal page fault at %#lx: %#016lx", frame->tf_sepc, sbadaddr); } void