From nobody Mon May 12 12:50:21 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 4ZwzwY49h3z5w0bS; Mon, 12 May 2025 12:50:21 +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 4ZwzwY26bFz3r4j; Mon, 12 May 2025 12:50:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1747054221; 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=pG0Gq74V2VyTIEAUVIwU6l/0atRp62NTISoeUNaLPFo=; b=PE9oTvApuPMlg/xXKmuKkbl2gRwVgt9ErBMJFPXaswX+4GK0t7KCs0CaY5+c89LfW6jomd /EwT/7U8SU3AIgb9OAznc4i9bCR8iO93p6bE/dZMK1ZAitrHFk61CEOunN/Ot5kMajqynl CrwPQQ2gWka0/Lldt8NWRheW7J76QHmvv0hJ8XW2TZmGgKh7EH48XiyouLmE9Y70zTlu/k c41aIrJURuXjO0f06y+7caSK8g7bLNqdHszk3mWTpEiHOhHnSyEvKqjJwCxfhyWgQTVrk2 PV6udp9Y8wBB3L2Bwy8WIW48cbuuuNRMs38zP3pcuwbb95cdQ8TsjqsyLG21KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1747054221; 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=pG0Gq74V2VyTIEAUVIwU6l/0atRp62NTISoeUNaLPFo=; b=shiOJsQA9ZiaW50h0wZPkN/bYwu6BLjzuYkdQVnV0o0sS5sCU2W2Idpo0AIAEhs5UiYLDN 1yazKf520LYhqsUJ5A+Ai2LoP+ljD2u9t1rYZzybQA2QypzX0RnV0dFQyNiTLAXoZeX02D ZojJ6U+9qNVQjEAvdCVA78rn0u5B4xFnUq/B74ckQbZAswM2IiM478xbxIGkwta5FFd0G8 Rtv8k6ea6Wr1fx1tQqHPQDDrlSEknt93I8P8htdteegmTuecj4ww1JlerG0VnPfJT8dCc4 KNddZlJ0+wTCTfPwmLHXB9+Bs5xbEXNRc885OysaUA2pEYZg7uiKAINBL6F/hA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1747054221; a=rsa-sha256; cv=none; b=paXCJ9K8k+8EvQULxk4Y0FuZDcMDTgCh/3IlfqPfjmgIU0tNryf6oq/Gt2NbwXQtYc5Aq5 2u72jE1DThreDwWtk5SpTuUxiMol+CLpwMdiKgUDf6+JPvy/daiWH/zLzwNBqFgCDcBiIz hxw5R3ZreyfSvydSV95fsCCi2sqZPtZMjvudT60QnkK/MK1UuhY6uWAV/kOv8Q0R4QmKDs x9PyNHCJzPgMWInTnKTmA9izMH7MXgss4UrfuGucwitsNEY09rsW6UXWAiL0p/2zOvXS8V ooGK7Wc01Dp5BB2KPnf5mer/fHZ24ZiUfwW7dRdOPtnu44nsmjzUM2Y93pqjCw== 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 4ZwzwY1HTgz1Fyt; Mon, 12 May 2025 12:50:21 +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 54CCoLon082856; Mon, 12 May 2025 12:50:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 54CCoLqi082853; Mon, 12 May 2025 12:50:21 GMT (envelope-from git) Date: Mon, 12 May 2025 12:50:21 GMT Message-Id: <202505121250.54CCoLqi082853@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: f68ca1421a1d - main - arm64: Remove kernel undef instruction support 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: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f68ca1421a1d54b29b2d2059b77459e00e86bba0 Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=f68ca1421a1d54b29b2d2059b77459e00e86bba0 commit f68ca1421a1d54b29b2d2059b77459e00e86bba0 Author: Andrew Turner AuthorDate: 2025-05-12 11:06:08 +0000 Commit: Andrew Turner CommitDate: 2025-05-12 11:06:08 +0000 arm64: Remove kernel undef instruction support Now we don't handle any undefined instructions in the kernel remove the support to handle them. The kernel should only ever execute valid instructions. The only case it needed to handle was an old emulator that is now well out of support, and the handler for this has been removed. Reviewed by: harry.moulton_arm.com Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D50205 --- sys/arm/arm/generic_timer.c | 2 +- sys/arm64/arm64/identcpu.c | 4 ++-- sys/arm64/arm64/trap.c | 6 ++---- sys/arm64/arm64/undefined.c | 37 ++++++++++++++----------------------- sys/arm64/include/undefined.h | 4 ++-- 5 files changed, 21 insertions(+), 32 deletions(-) diff --git a/sys/arm/arm/generic_timer.c b/sys/arm/arm/generic_timer.c index 685398117396..a82f8756b806 100644 --- a/sys/arm/arm/generic_timer.c +++ b/sys/arm/arm/generic_timer.c @@ -332,7 +332,7 @@ tmr_setup_user_access(void *arg __unused) #ifdef __aarch64__ if (TUNABLE_INT_FETCH("hw.emulate_phys_counter", &emulate) && emulate != 0) { - install_undef_handler(true, cntpct_handler); + install_undef_handler(cntpct_handler); } #endif } diff --git a/sys/arm64/arm64/identcpu.c b/sys/arm64/arm64/identcpu.c index 654a1b63d165..663c1a335114 100644 --- a/sys/arm64/arm64/identcpu.c +++ b/sys/arm64/arm64/identcpu.c @@ -2792,8 +2792,8 @@ identify_cpu_sysinit(void *dummy __unused) panic("CPU does not support LSE atomic instructions"); #endif - install_undef_handler(true, user_ctr_handler); - install_undef_handler(true, user_mrs_handler); + install_undef_handler(user_ctr_handler); + install_undef_handler(user_mrs_handler); } SYSINIT(identify_cpu, SI_SUB_CPU, SI_ORDER_MIDDLE, identify_cpu_sysinit, NULL); diff --git a/sys/arm64/arm64/trap.c b/sys/arm64/arm64/trap.c index fdcc38cd9a31..bed58095201a 100644 --- a/sys/arm64/arm64/trap.c +++ b/sys/arm64/arm64/trap.c @@ -578,8 +578,6 @@ do_el1h_sync(struct thread *td, struct trapframe *frame) panic("FPAC kernel exception"); break; case EXCP_UNKNOWN: - if (undef_insn(1, frame)) - break; print_registers(frame); print_gp_register("far", far); panic("Undefined instruction: %08x", @@ -676,7 +674,7 @@ do_el0_sync(struct thread *td, struct trapframe *frame) } break; case EXCP_UNKNOWN: - if (!undef_insn(0, frame)) + if (!undef_insn(frame)) call_trapsignal(td, SIGILL, ILL_ILLTRP, (void *)far, exception); userret(td, frame); @@ -716,7 +714,7 @@ do_el0_sync(struct thread *td, struct trapframe *frame) * instruction to access a special register userspace doesn't * have access to. */ - if (!undef_insn(0, frame)) + if (!undef_insn(frame)) call_trapsignal(td, SIGILL, ILL_PRVOPC, (void *)frame->tf_elr, exception); userret(td, frame); diff --git a/sys/arm64/arm64/undefined.c b/sys/arm64/arm64/undefined.c index 1f44114af544..71c9b689aa78 100644 --- a/sys/arm64/arm64/undefined.c +++ b/sys/arm64/arm64/undefined.c @@ -83,10 +83,11 @@ struct undef_handler { }; /* - * Create two undefined instruction handler lists, one for userspace, one for - * the kernel. This allows us to handle instructions that will trap + * Create the undefined instruction handler lists. + * This allows us to handle instructions that will trap. */ -LIST_HEAD(, undef_handler) undef_handlers[2]; +LIST_HEAD(, undef_handler) undef_handlers = + LIST_HEAD_INITIALIZER(undef_handlers); static bool arm_cond_match(uint32_t insn, struct trapframe *frame) @@ -248,24 +249,20 @@ fault: void undef_init(void) { - - LIST_INIT(&undef_handlers[0]); - LIST_INIT(&undef_handlers[1]); - #ifdef COMPAT_FREEBSD32 - install_undef_handler(true, gdb_trapper); - install_undef_handler(true, swp_emulate); + install_undef_handler(gdb_trapper); + install_undef_handler(swp_emulate); #endif } void * -install_undef_handler(bool user, undef_handler_t func) +install_undef_handler(undef_handler_t func) { struct undef_handler *uh; uh = malloc(sizeof(*uh), M_UNDEF, M_WAITOK); uh->uh_handler = func; - LIST_INSERT_HEAD(&undef_handlers[user ? 0 : 1], uh, uh_link); + LIST_INSERT_HEAD(&undef_handlers, uh, uh_link); return (uh); } @@ -281,24 +278,18 @@ remove_undef_handler(void *handle) } int -undef_insn(u_int el, struct trapframe *frame) +undef_insn(struct trapframe *frame) { struct undef_handler *uh; uint32_t insn; int ret; - KASSERT(el < 2, ("Invalid exception level %u", el)); - - if (el == 0) { - ret = fueword32((uint32_t *)frame->tf_elr, &insn); - /* Raise a SIGILL if we are unable to read the instruction */ - if (ret != 0) - return (0); - } else { - insn = *(uint32_t *)frame->tf_elr; - } + ret = fueword32((uint32_t *)frame->tf_elr, &insn); + /* Raise a SIGILL if we are unable to read the instruction */ + if (ret != 0) + return (0); - LIST_FOREACH(uh, &undef_handlers[el], uh_link) { + LIST_FOREACH(uh, &undef_handlers, uh_link) { ret = uh->uh_handler(frame->tf_elr, insn, frame, frame->tf_esr); if (ret) return (1); diff --git a/sys/arm64/include/undefined.h b/sys/arm64/include/undefined.h index db5d0523e711..1370a648b17c 100644 --- a/sys/arm64/include/undefined.h +++ b/sys/arm64/include/undefined.h @@ -57,9 +57,9 @@ MRS_GET(CRm) MRS_GET(Op2) void undef_init(void); -void *install_undef_handler(bool, undef_handler_t); +void *install_undef_handler(undef_handler_t); void remove_undef_handler(void *); -int undef_insn(u_int, struct trapframe *); +int undef_insn(struct trapframe *); #endif /* _KERNEL */