From nobody Sat Jan 04 14:08:14 2025 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 4YQMjW36Grz5kK0y; Sat, 04 Jan 2025 14:08:15 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YQMjW09XQz4Txm; Sat, 4 Jan 2025 14:08:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735999695; 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=1C8ziHyCskFNvTMlOqf9vsVhBnLrbtGsQA230O1NuCw=; b=Xu9QUbnqKNLWwiSvtfE8K3wHkBNQjEMZICN/Eu9Jjt7RU+KYyTeh8R+ravH3yi8EbHJBR2 48ypvgA/KXNtUwk684Nya/YYuf86HKcxU+ZRcQOqpRdkQS7qOIKjR211xD+bTW5tNJFAEB FxA14lMZdfsJJlp3JNyl6GWJ+J12p4z0aHyKkz9sMpABqvWKkiqJsnwjKt5O6w1VnNr2rk Dv7hCT4vNWQEOe1csf+TVWUx5XgDg9EWSSbG5VI36xttUUDBqMjosyIqJQrGsJaZ3/Jqhy cX8NFcadfXSBL9W+q8p+NjR4DSrOE0kOSmmJ1VOGFEXyyxIWK3b9AXuTR7Tu3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735999695; 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=1C8ziHyCskFNvTMlOqf9vsVhBnLrbtGsQA230O1NuCw=; b=XLBhPeQfIu2UhbCz8ex1tgai1l16HETpm+f3GjfedI5rhFDuKKNkhuqVKMGxaooz4vRNPA aGCPThFpB2dViggOeKQVs4+IHkAUlSuWWA5vTyQucrEg/doZcaSxiWtNJqEkBuUfsLh6Ka XJjheogdKIacxmrSCpHT8XBC3MC6p3ZYMItdykZLnBht4FwZJRp0JyJIrzi0HAI4yL9uC5 mdAKCYoX+Mb3Cdldx/O2OnGfL0cs/jKuwffM3wDHzAI1ruqVvcoYp2gpwdACPYqvmPigkS ueV7ZpK2fW4isNqdmSzGrXgHZRulJcIFLv6nYlXCT8G0AGzzOlkTYTLV8Ra2Fg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1735999695; a=rsa-sha256; cv=none; b=ao6T47mEl/NTIzzPbbH7vJIgBh/uqvu2Z7XNRh7nRlnxwJ9U5+LL1dcRS/84KFkPvwaHzU QjPrqbIrMx8knww7J3aN1z4qZ17PJNZOSZJwz5etHcS7LhbQvxjJpb52kzb8EV0qcSiTJA VzfpL3k2kYFf109QZVcmSj0MjzQG5jF68j2vsg39tRe8hKWC5sE/SyLJvgJ+1DKBPphDo/ 87sdSAXH5QeOSuFYoEIhuCxvooNWGkEKHLA7IBZ3+Mr9SBJmXeKIt+RjIXDs4opKOG+dxK +xsV64q/2YhJyQIPFsREqHOuBrBYlaULak+ALSu1KPBm4BtZz0iwA7d1DXaLgQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4YQMjV6tJGzwVg; Sat, 04 Jan 2025 14:08:14 +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 504E8EaJ070434; Sat, 4 Jan 2025 14:08:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 504E8ENS070431; Sat, 4 Jan 2025 14:08:14 GMT (envelope-from git) Date: Sat, 4 Jan 2025 14:08:14 GMT Message-Id: <202501041408.504E8ENS070431@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: f9275f94f33b - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: f9275f94f33bd017a05ed791b1ee56a68ab42be7 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=f9275f94f33bd017a05ed791b1ee56a68ab42be7 commit f9275f94f33bd017a05ed791b1ee56a68ab42be7 Author: Mark Johnston AuthorDate: 2024-12-10 15:07:28 +0000 Commit: Mark Johnston CommitDate: 2025-01-04 13:56:34 +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 (cherry picked from commit c226f193515c8c0665610cb519fe381987f8ee24) --- 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 3a7b3fba26b9..0b6db7982847 100644 --- a/sys/riscv/riscv/trap.c +++ b/sys/riscv/riscv/trap.c @@ -229,11 +229,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, @@ -246,7 +241,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; @@ -270,6 +266,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) {