From nobody Tue Oct 18 14:10:28 2022 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 4MsG3S6v3Bz4ftjf; Tue, 18 Oct 2022 14:10:28 +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 4MsG3S6RFGz3Gd9; Tue, 18 Oct 2022 14:10:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666102228; 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=ffguPz+Hf3o9xV1PqVd9XqdJ1Ab6588VV4sm7lFgrp8=; b=m0YX4T9NNLSh7z3YK4oUZnrrO52BPo2BoKXuBTFY8jqnlU6/tlP7+ZzTMs/OlRg+msxw5e h7L3XGggi6xw1WfROPGsY3I7Kml1m9Zj0fnPkeyrsmCxR6J+IHjBqSQHMUnAKfCv+GP0P9 SCS/N76OnFbIeexjmIaEjAw+ntOxiOgf3slZY3fxwf5ilPgJ5t9SrLpwfk3oxJJxPxeZBy yv1A/wezQmp8xmeeKX4rHaGEWQqWlWAejlTzhoZzp6cRosJ5Tdn2xVbcBXD/WB5zz2OxDS 91kl3eT5Od9QeOGG+glGvO8NcfQUVPcGflH9geSQWLGT8hTdoPtzg/Wb0rPGfQ== 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 4MsG3S5SDvz1BrM; Tue, 18 Oct 2022 14:10:28 +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 29IEASp9001782; Tue, 18 Oct 2022 14:10:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29IEASpM001781; Tue, 18 Oct 2022 14:10:28 GMT (envelope-from git) Date: Tue, 18 Oct 2022 14:10:28 GMT Message-Id: <202210181410.29IEASpM001781@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: 97edb6baa910 - stable/13 - riscv: handle misaligned address exceptions 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 97edb6baa91096a2d7d37546ad59596abe5c5b1b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666102228; 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=ffguPz+Hf3o9xV1PqVd9XqdJ1Ab6588VV4sm7lFgrp8=; b=UvULL3zp4WANIVVmr9qVPKBzcWPyplb11qqFGaBEG4w5O81U/2gBQWYiZzovrv2nRf9eiU uT57A/hrmUhxqD+4RPEdgoTpkVUPNPyZmRi26CLDiqHekAgcpm2ZdDr5zbgaOlQYy5zZFC +9xx9znaLhH1pn63oeKJakYLrl7iUyBs25jnjb3iG0rbbSTC5sa/qykB23z+b6EUUGKLwi 6kPrAkttrk5LW8CS3MCkvdB7ngYKbci94MrWHOOVfmZqU5LpcvVT/Mz/I5Lqb3AZroO0/V HAijb99XksSYOR+EfzdABhz78eMzhzaWtm9jHcuhGWoONNuB5ZaYrMkc0ZqYhA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666102228; a=rsa-sha256; cv=none; b=EhrpYOJLT7Kv7R52dURNle+k7RIHt/GtAqrl5PaRpqcqu311HBMQtE5N+kK2I+i5Zg60n/ turX9RP5uDrZiLeei+m8kK0x66uW46dpdEamR8T9sP6tVreEDjaK7j0YCYcyqCoKwbXlOo t/wXv5CAaTZPoP/39rXpZIH5i7TqDF63UU4gAwViAjYks5fUk3VeexuzvqIG1/3Lxw1GYb IZJS7K86tHhBW2gVH4FGoVF5DWCoEMWie6aqC95w9x0snkb+QGGRlz4/+LNxLKUotp2g/s xMnZAYJeqyIQBFthNkqpN+FmpTvUJvyUdlq+BmQvP2H9KMlIaw2evJvGwL4W8A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=97edb6baa91096a2d7d37546ad59596abe5c5b1b commit 97edb6baa91096a2d7d37546ad59596abe5c5b1b Author: Mitchell Horne AuthorDate: 2022-10-11 13:39:50 +0000 Commit: Mitchell Horne CommitDate: 2022-10-18 14:08:22 +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 (cherry picked from commit 9b4cbaa9c3da233cf06381c3d22e3472ee586585) --- 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 9a889661b965..4da6c9d21502 100644 --- a/sys/riscv/riscv/trap.c +++ b/sys/riscv/riscv/trap.c @@ -302,6 +302,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: @@ -370,6 +377,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: