From nobody Mon Nov 16 12:34:39 2026 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 4jSnPC1sHBz70X4f for ; Mon, 16 Nov 2026 12:34:39 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jSnPC0mw4z3DZ2 for ; Mon, 16 Nov 2026 12:34:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794832479; 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=tYi4F5Sl1TxfRTdDYNDr4BAP8D1/0mVrvYwTIrNQgE4=; b=V72Ht+kM0BvlM99zntdmjbxr0CCso+cJbVf1SxcO2jspbUImVD3HWKW0fFCIk6ndXFG+XS eE36WElK4kXSQCDqKAb5crEOqmatFa2WsIPQKElelgmXoqSTxZ5gaRgupnZgVaSULF9ti6 sxMWhA8WobaUpBb2oouUCQjz9YOHDKFZ+8KLSRODIc4sgbgG8NG59q2rhM0Pb9eirPfkvU TPn+PWR6Kh+qItruGUxqHmHRRasECoo3NZBs7cVDF6N9lvPkiLQ8WWwDMKOoLRlT1BmnNs kTGXH7hquxiGrVMhnWecgg9+5ReuWT1OvbdLoVC+qaYiF9DwACtxvqKwnnV9MQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794832479; b=qKB4y845ZyHZrGOWn+P/3N1Kb7EFnNxpC0Lt2anZsLvjbwZjOKl8hAd0cH2Nwb1lswV3xN edBwvKmScRrJyAUvOJzsIwRf8Batw5Kn5HhUpofUUz62SHcFq2elg+F2BE8r3FWjjfdr8s U2+nZG54IPtPTUOD7eChpzvDvmVVn3CeKGu1hkUFOWnU2ze5HjZBMEgfsHfCqPyS6H+vWB fbORCjKa8+kgKFSC9wEQafVC805WlzwgX4r/H5pP5OApK8SxtEE3OznGFbgcyMg6AFg8j1 j5adLgbgs7UUZXeozHZh92KuJCZuMneM+jeybJ6v1spKkDH26RhAcnkEorkuZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794832479; 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=tYi4F5Sl1TxfRTdDYNDr4BAP8D1/0mVrvYwTIrNQgE4=; b=j6hcOFxidsMhYYboCBCBZd0iVuxNvXWlicPCV72FNnlM+bqEwmrSNJm/WLaT02N45TifzW oQj5wJgzQdoLrZDO5ECGG3Sdq91oofehdNnmfuh1Yt8N1XClMLb2DA/MP7AcpEgh4YJ/u4 dTVU5atirfXSLTapGPlAwy+2FPmyX9PzWR5sgZAxSC8wAKrKiCpAXalo7bIeUf7d7MoSZc GfwHOeTGCJtvj2Nqe588nsgU0vaovt0T5llWb/7uSTJNFFnmRcgaBmZaQKiFn/SUwdrIUf y+Qy9Xsz+sFrbIhs95C2CX+moWvecBImcJWWxreeHMT5sBRUjJWnDdn+IgyX0Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jSnPC0RY5ztHD for ; Mon, 16 Nov 2026 12:34:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1a63f by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 16 Nov 2026 12:34:39 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Piotr Kubaj Subject: git: 5f2956673c28 - main - powerpc64: give processes a 48-bit address space by default List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pkubaj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5f2956673c280fa3de5615dfeecdc6c92e62d307 Auto-Submitted: auto-generated Date: Mon, 16 Nov 2026 12:34:39 +0000 Message-Id: <6afaf85f.1a63f.4bda89fd@gitrepo.freebsd.org> The branch main has been updated by pkubaj: URL: https://cgit.FreeBSD.org/src/commit/?id=5f2956673c280fa3de5615dfeecdc6c92e62d307 commit 5f2956673c280fa3de5615dfeecdc6c92e62d307 Author: Piotr Kubaj AuthorDate: 2026-11-15 20:57:41 +0000 Commit: Piotr Kubaj CommitDate: 2026-11-16 12:34:19 +0000 powerpc64: give processes a 48-bit address space by default Since ASLR got enabled for ELFv2, the random bases for the heap, the dynamic linker and PIE binaries can land anywhere in the 52-bit address space radix gives us. A lot of userland doesn't like that: SpiderMonkey, JavaScriptCore, QV4 and friends pack pointers into 47 or 48 bits and crash on startup (gjs, cjs, qml, ...). Do what amd64 does on LA57 hardware: keep the full range in the kernel and give processes a smaller map by default through a second set of sysvecs. The default is 48 bits (256 TiB), the same as arm64. One caveat for 48 bits: SpiderMonkey's GC allocator has no fallback there and relies on mmap(2) hints staying 1 MiB-aligned, which ASLR on FreeBSD breaks (hinted mappings move in 4 KiB steps, 64 KiB on arm64). The versions in ports need Mozilla's bug 1876632 (MAP_ALIGNED on FreeBSD, in Firefox 143) to be reliable; with it gjs runs clean. The full 52 bits stay available per process through the la52 feature control note (elfctl(1)) and PROC_LA_CTL (proccontrol(1)), and vm.pmap.prefer_uva_la48 flips the default. la52 is the powerpc64 name for the note bit amd64 calls la57, the procctl(2) values are the same. Fixes: 30ed27ff2556 ("sys/powerpc/powerpc/elf64_machdep.c: enable ASLR on ELFv2") Reviewed by: kib MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D61331 --- share/man/man7/arch.7 | 25 +++- sys/powerpc/include/proc.h | 8 +- sys/powerpc/include/procctl.h | 21 ++++ sys/powerpc/include/vmparam.h | 25 +++- sys/powerpc/powerpc/elf64_machdep.c | 227 +++++++++++++++++++++++++++++++----- sys/powerpc/powerpc/exec_machdep.c | 6 +- sys/powerpc/powerpc/vm_machdep.c | 86 +++++++++++++- sys/sys/elf_common.h | 3 +- 8 files changed, 357 insertions(+), 44 deletions(-) diff --git a/share/man/man7/arch.7 b/share/man/man7/arch.7 index 86461cd2b24f..22d184b8ebd2 100644 --- a/share/man/man7/arch.7 +++ b/share/man/man7/arch.7 @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd June 24, 2026 +.Dd November 11, 2026 .Dt ARCH 7 .Os .Sh NAME @@ -271,7 +271,7 @@ is 8 bytes on all supported architectures except i386. .It riscv64c Ta 4K, 2M, 1G .El .Ss User Address Space Layout -.Bl -column -offset indent "riscv64 (Sv48)" "0x0001000000000000" "NNNU" +.Bl -column -offset indent "powerpc64le (LA48)" "0x0001000000000000" "NNNU" .It Sy Architecture Ta Sy Maximum Address Ta Sy Address Space Size .It aarch64 Ta 0x0001000000000000 Ta 256TiB .It aarch64c Ta 0x0001000000000000 Ta 256TiB @@ -280,8 +280,10 @@ is 8 bytes on all supported architectures except i386. .It armv7 Ta 0xbfc00000 Ta 3GiB .It i386 Ta 0xffc00000 Ta 4GiB .It powerpc Ta 0xfffff000 Ta 4GiB -.It powerpc64 Ta 0x000fffffc0000000 Ta 4PiB -.It powerpc64le Ta 0x000fffffc0000000 Ta 4PiB +.It powerpc64 (LA48) Ta 0x0001000000000000 Ta 256TiB +.It powerpc64 (LA52) Ta 0x000fffffc0000000 Ta 4PiB +.It powerpc64le (LA48) Ta 0x0001000000000000 Ta 256TiB +.It powerpc64le (LA52) Ta 0x000fffffc0000000 Ta 4PiB .It riscv64 (Sv39) Ta 0x0000004000000000 Ta 256GiB .It riscv64c (Sv39) Ta 0x0000004000000000 Ta 256GiB .It riscv64 (Sv48) Ta 0x0000800000000000 Ta 128TiB @@ -303,7 +305,7 @@ tunable to 0 forces the system into 4-level paging mode, even on hardware that supports 5-level paging. In this mode, all processes get a 48-bit address space. The -.Va vm.pmap.prefer_la48_uva +.Va vm.pmap.prefer_uva_la48 tunable determines whether processes running on a LA57 system are limited to a 48-bit address space by default. Some applications make use of unused upper bits in pointer values to store @@ -316,6 +318,19 @@ Similarly, .Xr proccontrol 1 can be used to configure the address space layout when executing a process. .Pp +On powerpc64 the radix MMU provides a 52-bit user address space, but for the +same reason processes are limited to 48 bits (256TiB) by default, as they are +on aarch64. +The +.Va vm.pmap.prefer_uva_la48 +tunable, +.Xr elfctl 1 +and +.Xr proccontrol 1 +work as on amd64, with +.Dq la52 +requesting the full 52-bit address space. +.Pp The RISC-V specification permits 3-level (Sv39), 4-level (Sv48), and 5-level (Sv57) page tables. Hardware is only required to implement Sv39; implementations which support diff --git a/sys/powerpc/include/proc.h b/sys/powerpc/include/proc.h index c8c9b6370711..a386c7181a1c 100644 --- a/sys/powerpc/include/proc.h +++ b/sys/powerpc/include/proc.h @@ -45,12 +45,12 @@ struct mdthread { }; struct mdproc { - /* - * Avoid empty structs because they are undefined behavior. - */ - long md_spare; + u_int md_flags; /* (c) md process flags P_MD */ }; +#define P_MD_LA48 0x00000001 /* Request LA48 after exec */ +#define P_MD_LA52 0x00000002 /* Request LA52 after exec */ + #ifdef __powerpc64__ #define KINFO_PROC_SIZE 1088 #define KINFO_PROC32_SIZE 816 diff --git a/sys/powerpc/include/procctl.h b/sys/powerpc/include/procctl.h index b340002b45ee..1e8756b24ee3 100644 --- a/sys/powerpc/include/procctl.h +++ b/sys/powerpc/include/procctl.h @@ -1,3 +1,24 @@ /*- * This file is in the public domain. */ + +#ifndef _MACHINE_PROCCTL_H_ +#define _MACHINE_PROCCTL_H_ + +/* + * Per-process user address space size, see vmparam.h: la48 is the default + * 48-bit (256 TiB) address space, la52 the full 52 bits of the radix MMU. + * The values match amd64's PROC_LA_CTL so that proccontrol(1) can share + * the code. + */ +#define PROC_LA_CTL (PROC_PROCCTL_MD_MIN + 2) +#define PROC_LA_STATUS (PROC_PROCCTL_MD_MIN + 3) + +#define PROC_LA_CTL_LA48_ON_EXEC 1 +#define PROC_LA_CTL_LA52_ON_EXEC 2 +#define PROC_LA_CTL_DEFAULT_ON_EXEC 3 + +#define PROC_LA_STATUS_LA48 0x01000000 +#define PROC_LA_STATUS_LA52 0x02000000 + +#endif /* !_MACHINE_PROCCTL_H_ */ diff --git a/sys/powerpc/include/vmparam.h b/sys/powerpc/include/vmparam.h index ffbfccdfee7d..a29cc5a6ecc4 100644 --- a/sys/powerpc/include/vmparam.h +++ b/sys/powerpc/include/vmparam.h @@ -87,24 +87,43 @@ * kernel map should be able to start at 0xc008000000000000 - * but at least the functional simulator doesn't like it * - * 0x0000000000000000 - 0x000fffffffffffff user map + * 0x0000000000000000 - 0x00007fffffffffff user map (default) + * 0x0000000000000000 - 0x000fffffffffffff user map (la52) * 0xc000000000000000 - 0xc007ffffffffffff direct map * 0xc008000000000000 - 0xc00fffffffffffff kernel map * */ #define VM_MIN_ADDRESS 0x0000000000000000 -#define VM_MAXUSER_ADDRESS 0x000fffffc0000000 +/* + * Radix lets user space address 52 bits, but a process only gets the low + * 48 bits (256 TiB) by default, like on arm64: lots of userland + * (SpiderMonkey, JavaScriptCore, QV4, ...) packs pointers into 48 bits and + * crashes once ASLR puts the heap above that. The full 52 bits are + * available per process through the la52 feature control note or + * PROC_LA_CTL, see elf64_machdep.c. + */ +#define VM_MAXUSER_ADDRESS_LA48 0x0001000000000000 +#define VM_MAXUSER_ADDRESS_LA52 0x000fffffc0000000 +#define VM_MAXUSER_ADDRESS VM_MAXUSER_ADDRESS_LA52 #define VM_MAX_ADDRESS 0xc00fffffffffffff #define VM_MIN_KERNEL_ADDRESS 0xc008000000000000 #define VM_MAX_KERNEL_ADDRESS 0xc00801ffffffffff #define VM_MAX_SAFE_KERNEL_ADDRESS VM_MAX_KERNEL_ADDRESS + +#define SHAREDPAGE_LA48 (VM_MAXUSER_ADDRESS_LA48 - PAGE_SIZE) +#define SHAREDPAGE_LA52 (VM_MAXUSER_ADDRESS_LA52 - PAGE_SIZE) +#define SHAREDPAGE SHAREDPAGE_LA48 +#define USRSTACK_LA48 SHAREDPAGE_LA48 +#define USRSTACK_LA52 SHAREDPAGE_LA52 +#define PS_STRINGS_LA48 (USRSTACK_LA48 - sizeof(struct ps_strings)) +#define PS_STRINGS_LA52 (USRSTACK_LA52 - sizeof(struct ps_strings)) #else #define VM_MIN_ADDRESS 0 #define VM_MAXUSER_ADDRESS VM_MAXUSER_ADDRESS32 #define VM_MAX_ADDRESS 0xffffffff -#endif #define SHAREDPAGE (VM_MAXUSER_ADDRESS - PAGE_SIZE) +#endif #define FREEBSD32_SHAREDPAGE (VM_MAXUSER_ADDRESS32 - PAGE_SIZE) #define FREEBSD32_USRSTACK FREEBSD32_SHAREDPAGE diff --git a/sys/powerpc/powerpc/elf64_machdep.c b/sys/powerpc/powerpc/elf64_machdep.c index 4f59f0c4bff7..182a60accf07 100644 --- a/sys/powerpc/powerpc/elf64_machdep.c +++ b/sys/powerpc/powerpc/elf64_machdep.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -61,7 +62,7 @@ static void exec_setregs_funcdesc(struct thread *td, struct image_params *imgp, uintptr_t stack); -struct sysentvec elf64_freebsd_sysvec_v1 = { +struct sysentvec elf64_freebsd_sysvec_v1_la48 = { .sv_size = SYS_MAXSYSCALL, .sv_table = sysent, .sv_fixup = __elfN(freebsd_fixup), @@ -75,9 +76,9 @@ struct sysentvec elf64_freebsd_sysvec_v1 = { .sv_elf_core_prepare_notes = __elfN(prepare_notes), .sv_minsigstksz = MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, - .sv_maxuser = VM_MAXUSER_ADDRESS, - .sv_usrstack = USRSTACK, - .sv_psstrings = PS_STRINGS, + .sv_maxuser = VM_MAXUSER_ADDRESS_LA48, + .sv_usrstack = USRSTACK_LA48, + .sv_psstrings = PS_STRINGS_LA48, .sv_psstringssz = sizeof(struct ps_strings), .sv_stackprot = VM_PROT_ALL, .sv_copyout_auxargs = __elfN(powerpc_copyout_auxargs), @@ -89,7 +90,7 @@ struct sysentvec elf64_freebsd_sysvec_v1 = { .sv_set_syscall_retval = cpu_set_syscall_retval, .sv_fetch_syscall_args = cpu_fetch_syscall_args, .sv_syscallnames = syscallnames, - .sv_shared_page_base = SHAREDPAGE, + .sv_shared_page_base = SHAREDPAGE_LA48, .sv_shared_page_len = PAGE_SIZE, .sv_schedtail = NULL, .sv_thread_detach = NULL, @@ -104,7 +105,93 @@ struct sysentvec elf64_freebsd_sysvec_v1 = { .sv_regset_end = SET_LIMIT(__elfN(regset)), }; -struct sysentvec elf64_freebsd_sysvec_v2 = { +struct sysentvec elf64_freebsd_sysvec_v1_la52 = { + .sv_size = SYS_MAXSYSCALL, + .sv_table = sysent, + .sv_fixup = __elfN(freebsd_fixup), + .sv_sendsig = sendsig, + .sv_sigcode = sigcode64, + .sv_szsigcode = &szsigcode64, + .sv_name = "FreeBSD ELF64", + .sv_coredump = __elfN(coredump), + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = __elfN(prepare_notes), + .sv_minsigstksz = MINSIGSTKSZ, + .sv_minuser = VM_MIN_ADDRESS, + .sv_maxuser = VM_MAXUSER_ADDRESS_LA52, + .sv_usrstack = USRSTACK_LA52, + .sv_psstrings = PS_STRINGS_LA52, + .sv_psstringssz = sizeof(struct ps_strings), + .sv_stackprot = VM_PROT_ALL, + .sv_copyout_auxargs = __elfN(powerpc_copyout_auxargs), + .sv_copyout_strings = exec_copyout_strings, + .sv_setregs = exec_setregs_funcdesc, + .sv_fixlimit = NULL, + .sv_maxssiz = NULL, + .sv_flags = SV_ABI_FREEBSD_FLAGS | SV_LP64, + .sv_set_syscall_retval = cpu_set_syscall_retval, + .sv_fetch_syscall_args = cpu_fetch_syscall_args, + .sv_syscallnames = syscallnames, + .sv_shared_page_base = SHAREDPAGE_LA52, + .sv_shared_page_len = PAGE_SIZE, + .sv_schedtail = NULL, + .sv_thread_detach = NULL, + .sv_trap = NULL, + .sv_hwcap = &cpu_features, + .sv_hwcap2 = &cpu_features2, + .sv_hwcap3 = NULL, + .sv_hwcap4 = NULL, + .sv_onexec_old = exec_onexec_old, + .sv_onexit = exit_onexit, + .sv_regset_begin = SET_BEGIN(__elfN(regset)), + .sv_regset_end = SET_LIMIT(__elfN(regset)), +}; + +struct sysentvec elf64_freebsd_sysvec_v2_la48 = { + .sv_size = SYS_MAXSYSCALL, + .sv_table = sysent, + .sv_fixup = __elfN(freebsd_fixup), + .sv_sendsig = sendsig, + .sv_sigcode = sigcode64, /* Fixed up in ppc64_init_sysvecs(). */ + .sv_szsigcode = &szsigcode64, + .sv_name = "FreeBSD ELF64 V2", + .sv_coredump = __elfN(coredump), + .sv_elf_core_osabi = ELFOSABI_FREEBSD, + .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, + .sv_elf_core_prepare_notes = __elfN(prepare_notes), + .sv_minsigstksz = MINSIGSTKSZ, + .sv_minuser = VM_MIN_ADDRESS, + .sv_maxuser = VM_MAXUSER_ADDRESS_LA48, + .sv_usrstack = USRSTACK_LA48, + .sv_psstrings = PS_STRINGS_LA48, + .sv_psstringssz = sizeof(struct ps_strings), + .sv_stackprot = VM_PROT_ALL, + .sv_copyout_auxargs = __elfN(powerpc_copyout_auxargs), + .sv_copyout_strings = exec_copyout_strings, + .sv_setregs = exec_setregs, + .sv_fixlimit = NULL, + .sv_maxssiz = NULL, + .sv_flags = SV_ABI_FREEBSD_FLAGS | SV_LP64, + .sv_set_syscall_retval = cpu_set_syscall_retval, + .sv_fetch_syscall_args = cpu_fetch_syscall_args, + .sv_syscallnames = syscallnames, + .sv_shared_page_base = SHAREDPAGE_LA48, + .sv_shared_page_len = PAGE_SIZE, + .sv_schedtail = NULL, + .sv_thread_detach = NULL, + .sv_trap = NULL, + .sv_hwcap = &cpu_features, + .sv_hwcap2 = &cpu_features2, + .sv_hwcap3 = NULL, + .sv_hwcap4 = NULL, + .sv_onexec_old = exec_onexec_old, + .sv_onexit = exit_onexit, + .sv_regset_begin = SET_BEGIN(__elfN(regset)), + .sv_regset_end = SET_LIMIT(__elfN(regset)), +}; + +struct sysentvec elf64_freebsd_sysvec_v2_la52 = { .sv_size = SYS_MAXSYSCALL, .sv_table = sysent, .sv_fixup = __elfN(freebsd_fixup), @@ -118,9 +205,9 @@ struct sysentvec elf64_freebsd_sysvec_v2 = { .sv_elf_core_prepare_notes = __elfN(prepare_notes), .sv_minsigstksz = MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, - .sv_maxuser = VM_MAXUSER_ADDRESS, - .sv_usrstack = USRSTACK, - .sv_psstrings = PS_STRINGS, + .sv_maxuser = VM_MAXUSER_ADDRESS_LA52, + .sv_usrstack = USRSTACK_LA52, + .sv_psstrings = PS_STRINGS_LA52, .sv_psstringssz = sizeof(struct ps_strings), .sv_stackprot = VM_PROT_ALL, .sv_copyout_auxargs = __elfN(powerpc_copyout_auxargs), @@ -132,7 +219,7 @@ struct sysentvec elf64_freebsd_sysvec_v2 = { .sv_set_syscall_retval = cpu_set_syscall_retval, .sv_fetch_syscall_args = cpu_fetch_syscall_args, .sv_syscallnames = syscallnames, - .sv_shared_page_base = SHAREDPAGE, + .sv_shared_page_base = SHAREDPAGE_LA52, .sv_shared_page_len = PAGE_SIZE, .sv_schedtail = NULL, .sv_thread_detach = NULL, @@ -149,47 +236,82 @@ struct sysentvec elf64_freebsd_sysvec_v2 = { static bool ppc64_elfv1_header_match(const struct image_params *params, const int32_t *, const uint32_t *); +static bool ppc64_elfv1_la52_header_match(const struct image_params *params, + const int32_t *, const uint32_t *); static bool ppc64_elfv2_header_match(const struct image_params *params, const int32_t *, const uint32_t *); +static bool ppc64_elfv2_la52_header_match(const struct image_params *params, + const int32_t *, const uint32_t *); -static const Elf64_Brandinfo freebsd_brand_info_elfv1 = { +static const Elf64_Brandinfo freebsd_brand_info_elfv1_la48 = { .brand = ELFOSABI_FREEBSD, .machine = EM_PPC64, .compat_3_brand = "FreeBSD", .interp_path = "/libexec/ld-elf.so.1", - .sysvec = &elf64_freebsd_sysvec_v1, + .sysvec = &elf64_freebsd_sysvec_v1_la48, .interp_newpath = NULL, .brand_note = &elf64_freebsd_brandnote, .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE, .header_supported = &ppc64_elfv1_header_match }; -C_SYSINIT(elf64v1, SI_SUB_EXEC, SI_ORDER_ANY, - (sysinit_cfunc_t) elf64_insert_brand_entry, - &freebsd_brand_info_elfv1); +static const Elf64_Brandinfo freebsd_brand_info_elfv1_la52 = { + .brand = ELFOSABI_FREEBSD, + .machine = EM_PPC64, + .compat_3_brand = "FreeBSD", + .interp_path = "/libexec/ld-elf.so.1", + .sysvec = &elf64_freebsd_sysvec_v1_la52, + .interp_newpath = NULL, + .brand_note = &elf64_freebsd_brandnote, + .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE, + .header_supported = &ppc64_elfv1_la52_header_match +}; -static const Elf64_Brandinfo freebsd_brand_info_elfv2 = { +static const Elf64_Brandinfo freebsd_brand_info_elfv2_la48 = { .brand = ELFOSABI_FREEBSD, .machine = EM_PPC64, .compat_3_brand = "FreeBSD", .interp_path = "/libexec/ld-elf.so.1", - .sysvec = &elf64_freebsd_sysvec_v2, + .sysvec = &elf64_freebsd_sysvec_v2_la48, .interp_newpath = NULL, .brand_note = &elf64_freebsd_brandnote, .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE, .header_supported = &ppc64_elfv2_header_match }; -C_SYSINIT(elf64v2, SI_SUB_EXEC, SI_ORDER_ANY, - (sysinit_cfunc_t) elf64_insert_brand_entry, - &freebsd_brand_info_elfv2); +static const Elf64_Brandinfo freebsd_brand_info_elfv2_la52 = { + .brand = ELFOSABI_FREEBSD, + .machine = EM_PPC64, + .compat_3_brand = "FreeBSD", + .interp_path = "/libexec/ld-elf.so.1", + .sysvec = &elf64_freebsd_sysvec_v2_la52, + .interp_newpath = NULL, + .brand_note = &elf64_freebsd_brandnote, + .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE, + .header_supported = &ppc64_elfv2_la52_header_match +}; + +static void +ppc64_register_brand_entries(void *arg __unused) +{ + /* + * The la52 entries must go first so they can either claim the + * image or hand it to the la48 ones. + */ + elf64_insert_brand_entry(&freebsd_brand_info_elfv2_la52); + elf64_insert_brand_entry(&freebsd_brand_info_elfv2_la48); + elf64_insert_brand_entry(&freebsd_brand_info_elfv1_la52); + elf64_insert_brand_entry(&freebsd_brand_info_elfv1_la48); +} +SYSINIT(elf64_brands, SI_SUB_EXEC, SI_ORDER_FIRST, + ppc64_register_brand_entries, NULL); static const Elf64_Brandinfo freebsd_brand_oinfo = { .brand = ELFOSABI_FREEBSD, .machine = EM_PPC64, .compat_3_brand = "FreeBSD", .interp_path = "/usr/libexec/ld-elf.so.1", - .sysvec = &elf64_freebsd_sysvec_v1, + .sysvec = &elf64_freebsd_sysvec_v1_la48, .interp_newpath = NULL, .brand_note = &elf64_freebsd_brandnote, .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE, @@ -205,20 +327,27 @@ void elf_reloc_self(Elf_Dyn *dynp, Elf_Addr relocbase); static void ppc64_init_sysvecs(void *arg) { - exec_sysvec_init(&elf64_freebsd_sysvec_v2); - exec_sysvec_init_secondary(&elf64_freebsd_sysvec_v2, - &elf64_freebsd_sysvec_v1); + exec_sysvec_init(&elf64_freebsd_sysvec_v2_la48); + exec_sysvec_init_secondary(&elf64_freebsd_sysvec_v2_la48, + &elf64_freebsd_sysvec_v2_la52); + exec_sysvec_init_secondary(&elf64_freebsd_sysvec_v2_la48, + &elf64_freebsd_sysvec_v1_la48); + exec_sysvec_init_secondary(&elf64_freebsd_sysvec_v2_la48, + &elf64_freebsd_sysvec_v1_la52); /* - * Adjust elfv2 sigcode after elfv1 sysvec is initialized. + * Adjust elfv2 sigcode after the elfv1 sysvecs are initialized. * exec_sysvec_init_secondary() assumes secondary sysvecs use * identical signal code, and skips allocating a second copy. * Since the ELFv2 trampoline is a strict subset of the ELFv1 code, * we can work around this by adjusting the offset. This also * avoids two copies of the trampoline code being allocated! */ - elf64_freebsd_sysvec_v2.sv_sigcode_offset += + elf64_freebsd_sysvec_v2_la48.sv_sigcode_offset += + (uintptr_t)sigcode64_elfv2 - (uintptr_t)&sigcode64; + elf64_freebsd_sysvec_v2_la48.sv_szsigcode = &szsigcode64_elfv2; + elf64_freebsd_sysvec_v2_la52.sv_sigcode_offset += (uintptr_t)sigcode64_elfv2 - (uintptr_t)&sigcode64; - elf64_freebsd_sysvec_v2.sv_szsigcode = &szsigcode64_elfv2; + elf64_freebsd_sysvec_v2_la52.sv_szsigcode = &szsigcode64_elfv2; } SYSINIT(elf64_sysvec, SI_SUB_EXEC, SI_ORDER_ANY, ppc64_init_sysvecs, NULL); @@ -242,6 +371,50 @@ ppc64_elfv2_header_match(const struct image_params *params, return (abi == 2); } +/* + * Processes get a 48-bit address space by default, see vmparam.h. The full + * 52 bits are available through the la52 feature control note or + * PROC_LA_CTL; vm.pmap.prefer_uva_la48 flips the default like on amd64. + */ +static int prefer_uva_la48 = 1; +SYSCTL_DECL(_vm_pmap); +SYSCTL_INT(_vm_pmap, OID_AUTO, prefer_uva_la48, CTLFLAG_RDTUN, + &prefer_uva_la48, 0, + "Userspace maps are limited to LA48 unless otherwise configured"); + +static bool +ppc64_la52_img_compat(const struct image_params *imgp, const uint32_t *fctl0) +{ + + if ((imgp->proc->p_md.md_flags & P_MD_LA52) != 0) + return (true); + if (fctl0 != NULL && (*fctl0 & NT_FREEBSD_FCTL_LA52) != 0) + return (true); + if (fctl0 == NULL || (*fctl0 & NT_FREEBSD_FCTL_LA48) != 0) + return (false); + if ((imgp->proc->p_md.md_flags & P_MD_LA48) != 0) + return (false); + return (!prefer_uva_la48); +} + +static bool +ppc64_elfv1_la52_header_match(const struct image_params *params, + const int32_t *osrel, const uint32_t *fctl0) +{ + + return (ppc64_elfv1_header_match(params, osrel, fctl0) && + ppc64_la52_img_compat(params, fctl0)); +} + +static bool +ppc64_elfv2_la52_header_match(const struct image_params *params, + const int32_t *osrel, const uint32_t *fctl0) +{ + + return (ppc64_elfv2_header_match(params, osrel, fctl0) && + ppc64_la52_img_compat(params, fctl0)); +} + static void exec_setregs_funcdesc(struct thread *td, struct image_params *imgp, uintptr_t stack) diff --git a/sys/powerpc/powerpc/exec_machdep.c b/sys/powerpc/powerpc/exec_machdep.c index 3fa136372c9b..d7166b13f67d 100644 --- a/sys/powerpc/powerpc/exec_machdep.c +++ b/sys/powerpc/powerpc/exec_machdep.c @@ -128,7 +128,8 @@ static int grab_mcontext(struct thread *, mcontext_t *, int); static void cleanup_power_extras(struct thread *); #ifdef __powerpc64__ -extern struct sysentvec elf64_freebsd_sysvec_v2; +extern struct sysentvec elf64_freebsd_sysvec_v2_la48; +extern struct sysentvec elf64_freebsd_sysvec_v2_la52; #endif #ifdef __powerpc64__ @@ -1204,7 +1205,8 @@ cpu_set_upcall(struct thread *td, void (*entry)(void *), void *arg, #endif } else { #ifdef __powerpc64__ - if (td->td_proc->p_sysent == &elf64_freebsd_sysvec_v2) { + if (td->td_proc->p_sysent == &elf64_freebsd_sysvec_v2_la48 || + td->td_proc->p_sysent == &elf64_freebsd_sysvec_v2_la52) { tf->srr0 = (register_t)entry; /* ELFv2 ABI requires that the global entry point be in r12. */ tf->fixreg[12] = (register_t)entry; diff --git a/sys/powerpc/powerpc/vm_machdep.c b/sys/powerpc/powerpc/vm_machdep.c index 1dc28739ad7c..4fa15e282da9 100644 --- a/sys/powerpc/powerpc/vm_machdep.c +++ b/sys/powerpc/powerpc/vm_machdep.c @@ -79,9 +79,11 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -128,6 +130,9 @@ cpu_fork(struct thread *td1, struct proc *p2, struct thread *td2, int flags) /* Copy the pcb */ bcopy(td1->td_pcb, pcb, sizeof(struct pcb)); + /* Inherit the machine-dependent process flags. */ + bcopy(&td1->td_proc->p_md, &p2->p_md, sizeof(p2->p_md)); + /* * Create a fresh stack for the new process. * Copy the trap frame for the return to user mode as if from a @@ -214,12 +219,89 @@ cpu_exec_vmspace_reuse(struct proc *p __unused, vm_map_t map __unused) return (true); } +#ifdef __powerpc64__ +static void +cpu_procctl_la_ctl(struct proc *p, int val) +{ + + switch (val) { + case PROC_LA_CTL_LA48_ON_EXEC: + p->p_md.md_flags |= P_MD_LA48; + p->p_md.md_flags &= ~P_MD_LA52; + break; + case PROC_LA_CTL_LA52_ON_EXEC: + p->p_md.md_flags &= ~P_MD_LA48; + p->p_md.md_flags |= P_MD_LA52; + break; + case PROC_LA_CTL_DEFAULT_ON_EXEC: + p->p_md.md_flags &= ~(P_MD_LA48 | P_MD_LA52); + break; + } +} + +static void +cpu_procctl_la_status(struct proc *p, int *val) +{ + int res; + + if ((p->p_md.md_flags & P_MD_LA48) != 0) + res = PROC_LA_CTL_LA48_ON_EXEC; + else if ((p->p_md.md_flags & P_MD_LA52) != 0) + res = PROC_LA_CTL_LA52_ON_EXEC; + else + res = PROC_LA_CTL_DEFAULT_ON_EXEC; + if (p->p_sysent->sv_maxuser <= VM_MAXUSER_ADDRESS_LA48) + res |= PROC_LA_STATUS_LA48; + else + res |= PROC_LA_STATUS_LA52; + *val = res; +} +#endif + int -cpu_procctl(struct thread *td __unused, int idtype __unused, id_t id __unused, - int com __unused, void *data __unused) +cpu_procctl(struct thread *td, int idtype, id_t id, int com, void *data) { +#ifdef __powerpc64__ + struct proc *p; + int error, val; + switch (com) { + case PROC_LA_CTL: + case PROC_LA_STATUS: + if (idtype != P_PID) { + error = EINVAL; + break; + } + if (com == PROC_LA_CTL) { + error = copyin(data, &val, sizeof(val)); + if (error != 0) + break; + if (val != PROC_LA_CTL_LA48_ON_EXEC && + val != PROC_LA_CTL_LA52_ON_EXEC && + val != PROC_LA_CTL_DEFAULT_ON_EXEC) { + error = EINVAL; + break; + } + } + error = pget(id, PGET_CANSEE | PGET_NOTWEXIT | PGET_NOTID, &p); + if (error != 0) + break; + if (com == PROC_LA_CTL) + cpu_procctl_la_ctl(p, val); + else + cpu_procctl_la_status(p, &val); + PROC_UNLOCK(p); + if (com == PROC_LA_STATUS) + error = copyout(&val, data, sizeof(val)); + break; + default: + error = EINVAL; + break; + } + return (error); +#else return (EINVAL); +#endif } void diff --git a/sys/sys/elf_common.h b/sys/sys/elf_common.h index 32621041cb44..2a24eb33e729 100644 --- a/sys/sys/elf_common.h +++ b/sys/sys/elf_common.h @@ -839,7 +839,8 @@ typedef struct { #define NT_FREEBSD_FCTL_WXNEEDED 0x00000008 #define NT_FREEBSD_FCTL_LA48 0x00000010 /* was ASG_DISABLE, do not reuse 0x00000020 */ -#define NT_FREEBSD_FCTL_LA57 0x00000040 +#define NT_FREEBSD_FCTL_LA57 0x00000040 /* amd64 */ +#define NT_FREEBSD_FCTL_LA52 0x00000040 /* powerpc64 */ /* Values for n_type. Used in core files. */ #define NT_PRSTATUS 1 /* Process status. */