NetBSD Problem Report #54702
From www@netbsd.org Sun Nov 17 06:09:27 2019
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 7C9C57A249
for <gnats-bugs@gnats.NetBSD.org>; Sun, 17 Nov 2019 06:09:27 +0000 (UTC)
Message-Id: <20191117060926.3F56E7A279@mollari.NetBSD.org>
Date: Sun, 17 Nov 2019 06:09:26 +0000 (UTC)
From: rokuyama.rk@gmail.com
Reply-To: rokuyama.rk@gmail.com
To: gnats-bugs@NetBSD.org
Subject: Support earmv6hf binary for COMPAT_NETBSD32 on aarch64
X-Send-Pr-Version: www-1.0
>Number: 54702
>Category: port-arm
>Synopsis: Support earmv6hf binary for COMPAT_NETBSD32 on aarch64
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: port-arm-maintainer
>State: closed
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Sun Nov 17 06:10:00 +0000 2019
>Closed-Date: Sun Jul 25 03:12:50 +0000 2021
>Last-Modified: Sun Jul 25 03:12:50 +0000 2021
>Originator: Rin Okuyama
>Release: 9.99.17
>Organization:
Department of Physics, Meiji University
>Environment:
NetBSD rpi 9.99.17 NetBSD 9.99.17 (GENERIC64) #26: Sat Nov 16 08:24:23 JST 2019 rin@latipes:/build/src/sys/arch/evbarm/compile/GENERIC64 evbarm
>Description:
Currently, earmv6hf binaries cannot run on COMPAT_NETBSD32 on aarch64
due to illegal instructions; ARMv6 instructions with cache operations
register (c7) were deprecated in ARMv7, and are not supported on ARMv8
with LP64 kernel.
This patch
http://www.netbsd.org/~rin/aarch64_emul_armv6_20191113.patch
adds software emulation for such instructions. Also, ep_machine_arch
(default: earmv7hf) is copied from executables if present, as we do for
mips64; uname -p reports earmv6hf if it is built for earmv6hf.
With this patch, evbarm-earmv6hf-el userland works just fine on aarch64
kernel as far as I can see. Older earm architectures may be supported,
in principle, in a similar manner.
Some remarks:
Linux also emulates these instructions on arm64 kernel:
https://github.com/torvalds/linux/blob/master/arch/arm64/kernel/armv8_deprecated.c#L460
However, it just ignores "mcr p15, 0, <Rd>, c7, c5, 4"
(flush prefetch buffer). This patch emulates it by "isb".
The condition code in the instructions are neglected as in the same
manner as Linux does. I expect it is no problem in practice.
>How-To-Repeat:
Run binary compiled for earmv6hf on aarch64 kernel.
>Fix:
Described above.
>Release-Note:
>Audit-Trail:
From: "Rin Okuyama" <rin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/54702 CVS commit: src/sys/arch/aarch64
Date: Sun, 24 Nov 2019 04:08:36 +0000
Module Name: src
Committed By: rin
Date: Sun Nov 24 04:08:36 UTC 2019
Modified Files:
src/sys/arch/aarch64/aarch64: exec_machdep.c netbsd32_machdep.c trap.c
src/sys/arch/aarch64/include: netbsd32_machdep.h param.h proc.h
Log Message:
PR port-arm/54702
Add support for earmv6hf binaries on COMPAT_NETBSD32 for aarch64:
- Emulate ARMv6 instructions with cache operations register (c7), that
are deprecated since ARMv7, and disabled on ARMv8 with LP64 kernel.
- ep_machine_arch (default: earmv7hf) is copied from executables, as we
do for mips64. "uname -p" reports earmv6hf if compiled for earmv6hf;
configure scripts etc can determine the appropriate architecture.
Many thanks to ryo@ for helping me to add support of Thumb-mode,
as well as providing exhaustive test cases:
https://github.com/ryo/mcr_test/
We've confirmed:
- Emulation works in Thumb-mode.
- T32 16-bit length illegal instruction results in SIGILL, even if
it is located nearby a boundary b/w mapped and unmapped pages.
- T32 32-bit instruction results in SIGSEGV if it is located across
a boundary b/w mapped and unmapped pages.
XXX
pullup to netbsd-9
To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/aarch64/aarch64/exec_machdep.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/aarch64/aarch64/netbsd32_machdep.c
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/aarch64/aarch64/trap.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/aarch64/include/netbsd32_machdep.h
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/aarch64/include/param.h
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/aarch64/include/proc.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Rin Okuyama" <rin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/54702 CVS commit: src/sys/arch/aarch64/include
Date: Sun, 24 Nov 2019 11:28:40 +0000
Module Name: src
Committed By: rin
Date: Sun Nov 24 11:28:40 UTC 2019
Modified Files:
src/sys/arch/aarch64/include: proc.h
Log Message:
part of PR port-arm/54702
Having md_march32 unconditionally in struct mdproc, in order to
make libkvm happy.
XXX
pullup to netbsd-9
To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/aarch64/include/proc.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Rin Okuyama" <rin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/54702 CVS commit: src/sys/arch/aarch64/aarch64
Date: Sun, 24 Nov 2019 11:45:00 +0000
Module Name: src
Committed By: rin
Date: Sun Nov 24 11:45:00 UTC 2019
Modified Files:
src/sys/arch/aarch64/aarch64: exec_machdep.c
Log Message:
part of PR port-arm/54702
Make sure that md_march32 and ep_machine_arch have same size.
XXX
pullup to netbsd-9
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/aarch64/aarch64/exec_machdep.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->needs-pullups
State-Changed-By: maya@NetBSD.org
State-Changed-When: Tue, 21 Apr 2020 17:28:52 +0000
State-Changed-Why:
I assume the patches resolve the problem, as they were committed by the reporter.
Changing state due to the "XXX pullup" in the commit messages and no pullup filed.
From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/54702 CVS commit: [netbsd-9] src/sys/arch/aarch64/aarch64
Date: Fri, 1 Jan 2021 12:31:19 +0000
Module Name: src
Committed By: martin
Date: Fri Jan 1 12:31:19 UTC 2021
Modified Files:
src/sys/arch/aarch64/aarch64 [netbsd-9]: trap.c
Log Message:
Pull up following revision(s) (requested by rin in ticket #1169):
sys/arch/aarch64/aarch64/trap.c: revision 1.21
sys/arch/aarch64/aarch64/trap.c: revision 1.26
PR port-arm/54702
Add support for earmv6hf binaries on COMPAT_NETBSD32 for aarch64:
- Emulate ARMv6 instructions with cache operations register (c7), that
are deprecated since ARMv7, and disabled on ARMv8 with LP64 kernel.
Many thanks to ryo@ for helping me to add support of Thumb-mode,
as well as providing exhaustive test cases:
https://github.com/ryo/mcr_test/
We've confirmed:
- Emulation works in Thumb-mode.
- T32 16-bit length illegal instruction results in SIGILL, even if
it is located nearby a boundary b/w mapped and unmapped pages.
- T32 32-bit instruction results in SIGSEGV if it is located across
a boundary b/w mapped and unmapped pages.
When emulating obsoleted arm32 instructions, use ufetch(9) rather than
dereference tf_pc directly to retrieve an instruction.
Even if tf_pc is valid when processor decodes the instruction, someone
can unmap its page before tf_pc is read in the exception handler.
Now, SIGSEGV is delivered correctly to the process in this case, rather
than kernel panic.
Pointed out by maxv.
Discussed with ryo and skrll.
To generate a diff of this commit:
cvs rdiff -u -r1.17.4.2 -r1.17.4.3 src/sys/arch/aarch64/aarch64/trap.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: needs-pullups->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sun, 25 Jul 2021 03:12:50 +0000
State-Changed-Why:
the pullup request was not reported here, but the pullup happened
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.