From nobody Tue Dec 10 15:09:37 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Y72Fs6cwKz5gFlX; Tue, 10 Dec 2024 15:09:37 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Y72Fs65nGz4grc; Tue, 10 Dec 2024 15:09:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733843377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6I0XTQuqoedN6Jv8IMLwhUPdZUvdePT+M12Gco/c7no=; b=fOkQBBSH2c/F5j48GG7CSRchBM7B/h+DjsEKrjlXNudTNx0D6qNpP4ZV+CGMGkt/rwp2+T NsC/7nZDkWPFT/p5PnsxDtvTaPmEjNX/xelLyUvlRrSosE/fjsZT9AxxpWFiAGhYfhkhs4 xJNhBhk2x1cg/ZtuTujOpBGtmip2QGJg2B3GUzOULLFd5mMaoPgbVrt2w/RgnKRewMikl+ rkr4eOnHk0ba/z5dyKmRzWjV2JFvPqEE0b+0KxY2oJj/7lnfLC22DytYqjeHNCPiCLyhFc ct1uIwhzAO+lHW673m4ihufUKUglrOvfFbgo/7KJiN1r751/wBbgWymZXtM8OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733843377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6I0XTQuqoedN6Jv8IMLwhUPdZUvdePT+M12Gco/c7no=; b=G2zhH0ds2R3pud8QfTCu/TmLx0q3nUf4WXbE5vzVLKKbzWtDVPW4Hi/2k1wTWmG3PEI7bQ 6c02khtA0EO3T3swN0VbddP5WZ4Xv0jee6UhFks7GgrwRj2fo3qIjMyEL5QSZI6QEPKZan nrixWNe4eGkP549qGuNFZnLlWULw+wsquRdSUtGbclCpcVYaOWpJuj7kIc2o55U6XBk0GK /OZDQsoNG1Mcv1Cowrp8jtXykjwRANajTABIjxxpY46maDr/njimYomC2EuajyQW62VKnK WxmUL+k0ABgPB5MxINb7RMxM1M7TBpON8mKlxeAVS73Aopg1phTnfJovxyEQHQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1733843377; a=rsa-sha256; cv=none; b=Op/R1R+XCwQbmFlUVhniss3ShhywkTW4vlFRZzkongq1wBBGM8FgXEUSHognwiRc+7B15F qbt9PP+WVssd6VZb1FjcZ2xzLZdz+VpJhbTuAcF5+XbRiMna6hLxGotUjT/MSxye2JIcaK Lc6MOsOvVfc8KEBKsrOjTyaNQ29BwtZ5eF5Vq8l2d3NHMx1DxJkz22d1j+nH7Na2scu1D6 2iWxWNd87c81zrvvPu8PJn0MJN2V+kwkz/+DaNgmx4P0y6kh25/bTqpva2/sK2muNHUm5B Nf1uQ/le+C//2smbyhrBDNi4nEile5sRUNcW3HVB8CXumIw8Hod65R8ztNlztA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Y72Fs5SMnzSdR; Tue, 10 Dec 2024 15:09:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4BAF9bRl071513; Tue, 10 Dec 2024 15:09:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BAF9bZI071510; Tue, 10 Dec 2024 15:09:37 GMT (envelope-from git) Date: Tue, 10 Dec 2024 15:09:37 GMT Message-Id: <202412101509.4BAF9bZI071510@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: c226f193515c - main - riscv: Permit spurious faults in kernel mode List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c226f193515c8c0665610cb519fe381987f8ee24 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=c226f193515c8c0665610cb519fe381987f8ee24 commit c226f193515c8c0665610cb519fe381987f8ee24 Author: Mark Johnston AuthorDate: 2024-12-10 15:07:28 +0000 Commit: Mark Johnston CommitDate: 2024-12-10 15:07:28 +0000 riscv: Permit spurious faults in kernel mode Right now, pmap_enter() does not issue an sfence.vma after overwriting an invalid PTE, so the kernel can trigger a page fault when accessing a freshly created mapping. In this case, pmap_fault() can handle the exception, but we may panic before that. Move the check; this is consistent with arm64 and serves to ensure that we don't call vm_fault() etc. from a context where that's not permitted. Also fix a related bug: don't enable interrupts if they were disabled in the context where the exception occurred. Reviewed by: br Tested by: br MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D47688 --- sys/riscv/riscv/trap.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sys/riscv/riscv/trap.c b/sys/riscv/riscv/trap.c index 3bb1fc7f1010..a1a30eb58220 100644 --- a/sys/riscv/riscv/trap.c +++ b/sys/riscv/riscv/trap.c @@ -227,11 +227,6 @@ page_fault_handler(struct trapframe *frame, int usermode) pcb = td->td_pcb; stval = frame->tf_stval; - 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 (usermode) { if (!VIRT_IS_VALID(stval)) { call_trapsignal(td, SIGSEGV, SEGV_MAPERR, (void *)stval, @@ -244,7 +239,8 @@ page_fault_handler(struct trapframe *frame, int usermode) * Enable interrupts for the duration of the page fault. For * user faults this was done already in do_trap_user(). */ - intr_enable(); + if ((frame->tf_sstatus & SSTATUS_SIE) != 0) + intr_enable(); if (stval >= VM_MIN_KERNEL_ADDRESS) { map = kernel_map; @@ -268,6 +264,11 @@ page_fault_handler(struct trapframe *frame, int usermode) if (VIRT_IS_VALID(va) && pmap_fault(map->pmap, va, ftype)) goto done; + if (td->td_critnest != 0 || td->td_intr_nesting_level != 0 || + WITNESS_CHECK(WARN_SLEEPOK | WARN_GIANTOK, NULL, + "Kernel page fault") != 0) + goto fatal; + error = vm_fault_trap(map, va, ftype, VM_FAULT_NORMAL, &sig, &ucode); if (error != KERN_SUCCESS) { if (usermode) {