From nobody Tue Oct 11 13:40:09 2022 X-Original-To: dev-commits-src-main@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 4Mmxjj2PQLz4fl7x; Tue, 11 Oct 2022 13:40:09 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Mmxjj1tWfz3kTB; Tue, 11 Oct 2022 13:40:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665495609; 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=NJGG000lFTIRfOzNr4UesdXbEHyCnIpRDBDCmoN71LI=; b=qpb3TwPFWLNGaq38JeDvMePmpv2AZIN7CypeMNLhskktw+e2ugVFkBZk4yP6tfxqyOa4Ba 3T3TdY8RXkCP5YtNsrwAbpE6+4hrfbIkiWN+Ll2urNPwMmb9CdQu4NZlIZLp5xsqtTZLZE XafiFSIQfdroLsPGYQpIzcnIRHg0W1lwonempyWEW59okKd/nTowryBF9GkAsfIPsgJR67 a41WWEltcgaBzuf7bDE1WxqhkJbKlthqzfhftnVzoPmVAGzZcLR2j4q08CS34qkc9bQngc VJJrJN9cVH1gCPUmKDE1+5SFArBOLZ8EqU2R2B/0kCoscSYKKFwQKNI3c29eKg== 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 4Mmxjj0xpDzyfP; Tue, 11 Oct 2022 13:40:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 29BDe9eP078971; Tue, 11 Oct 2022 13:40:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29BDe9KG078969; Tue, 11 Oct 2022 13:40:09 GMT (envelope-from git) Date: Tue, 11 Oct 2022 13:40:09 GMT Message-Id: <202210111340.29BDe9KG078969@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 9b4cbaa9c3da - main - riscv: handle misaligned address exceptions List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9b4cbaa9c3da233cf06381c3d22e3472ee586585 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665495609; 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=NJGG000lFTIRfOzNr4UesdXbEHyCnIpRDBDCmoN71LI=; b=CpNHLLpqsjm8QgG+7p13wEFp3o5S5D1oHGaSVyH/LqJlbmgM4+IiYpzuxbjhj3kljH6mMQ 0szTOKabIK9jjUst0D+XapQ/tavSl30A84RSH9P2qEHlIGS5PvXJfmWG+4vROlYeK2SN/s R4bYP/O1S7tOSvjMvyyah6OuawkQMi3yCVdMo0c90S7tlFWD8kBbVG0k5IungQsx4kDNDo JAuVZDMhLdYpxxki1B/dPeYYybxDXcOFA0Zi+uuRtU+7PDX1wmmrqYOJY48tBNFVyIddHH f7jAwWmcAv6Yrf14K5VNx6UQEE+BTjTq9uNSjaOcI9ai46u33iEFQvBGlOvEeQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1665495609; a=rsa-sha256; cv=none; b=KCMVG/ClHGix/FXhfSi7KWnNfkYf6XDEJ/CNgd0SdvArX+hLsBB+8s5UYPa4nBn9JyZFC1 I0GiKAYFEjSvi9oT6UR4++bObImjzO7kwzZBWtvbhSN5VjLGLTT9EWtAgBQQsA2xluj2G2 8h7M1PJlB375Z1sA17gmD32o3hLGo42GWKIpzXIbCdYixqMk6H1RNNX7KtWFAEwV4BbU/t VRhbZYb6hrFnY+aEs28UC05EsXe7Cz97DfMuMdkeVvd+n6wBfhr1ge7ZSur1W3CxopNALl zCNmNcwvjiVBd8gGuOx6wLSbOaTn+AXxX/EqIcmqgNf6bCkB8rMmR5fky0M4UQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=9b4cbaa9c3da233cf06381c3d22e3472ee586585 commit 9b4cbaa9c3da233cf06381c3d22e3472ee586585 Author: Mitchell Horne AuthorDate: 2022-10-11 13:39:50 +0000 Commit: Mitchell Horne CommitDate: 2022-10-11 13:39:50 +0000 riscv: handle misaligned address exceptions If this exception is coming from userspace, send the appropriate SIGBUS to the process. If it's coming from the kernel this is still fatal, but we can give a better panic message. Typical misaligned loads/stores are emulated by the SBI firmware, and require no intervention from our kernel. The notable exception here is misaligned access with atomic instructions. These can generate the exception and panic seen in the PR. With this, we now handle all defined exception types. PR: 266109 MFC after: 1 week Found by: syzkaller Reported by: P1umer Differential Revision: https://reviews.freebsd.org/D36876 --- sys/riscv/riscv/trap.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sys/riscv/riscv/trap.c b/sys/riscv/riscv/trap.c index 8b709b2de121..39e0fbb1d5bd 100644 --- a/sys/riscv/riscv/trap.c +++ b/sys/riscv/riscv/trap.c @@ -303,6 +303,13 @@ do_trap_supervisor(struct trapframe *frame) dump_regs(frame); panic("Memory access exception at 0x%016lx\n", frame->tf_sepc); break; + case SCAUSE_LOAD_MISALIGNED: + case SCAUSE_STORE_MISALIGNED: + case SCAUSE_INST_MISALIGNED: + dump_regs(frame); + panic("Misaligned address exception at %#016lx: %#016lx\n", + frame->tf_sepc, frame->tf_stval); + break; case SCAUSE_STORE_PAGE_FAULT: case SCAUSE_LOAD_PAGE_FAULT: case SCAUSE_INST_PAGE_FAULT: @@ -371,6 +378,13 @@ do_trap_user(struct trapframe *frame) exception); userret(td, frame); break; + case SCAUSE_LOAD_MISALIGNED: + case SCAUSE_STORE_MISALIGNED: + case SCAUSE_INST_MISALIGNED: + call_trapsignal(td, SIGBUS, BUS_ADRALN, (void *)frame->tf_sepc, + exception); + userret(td, frame); + break; case SCAUSE_STORE_PAGE_FAULT: case SCAUSE_LOAD_PAGE_FAULT: case SCAUSE_INST_PAGE_FAULT: