From nobody Sun Aug 16 23:46:04 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 4hNXfc1R2Rz6pmSj; Sun, 16 Aug 2026 23:46:16 +0000 (UTC) (envelope-from dtf@shxd.cx) Received: from shxd.cx (shxd.cx [207.231.82.159]) (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 mx1.freebsd.org (Postfix) with ESMTPS id 4hNXfb4Hlvz3bNL; Sun, 16 Aug 2026 23:46:15 +0000 (UTC) (envelope-from dtf@shxd.cx) Authentication-Results: mx1.freebsd.org; none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=shxd.cx; s=shxd2024; h=Sender:References:To:Cc:In-Reply-To:Date:Subject:Mime-Version: Content-Type:Message-Id:From:Reply-to:Content-Transfer-Encoding:Content-ID: Content-Description; bh=7Zl0hvo+CQGJ1GajHfnhw3CP7WkbCmyz4z9EYeSLXn8=; b=e1OpD Spxf0r0aZr4iKLIx9qlCQBN4x+lWS0rAU2YR3rN1p11Hpii7AeA0gZKLfEQYeAc/+T8zegtvY9wko /i2QJ0snWjKX7/5WgFUSyEh0jKnSmXWHw77otT1oiBkOyXOcGLJ8hY+7tnWQ+wEL9iaRZvGNr96ni dnNCcoYWOO5c=; Received: from lummox.shxd.cx ([10.0.0.254]:58304 helo=smtpclient.apple) by shxd.cx with esmtpsa (TLS1.2) tls TLS_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1 (FreeBSD)) (envelope-from ) id 1wvkY1-000000005mr-2V2W; Sun, 16 Aug 2026 16:45:49 -0700 From: Devin Teske Message-Id: <7AA6F794-343B-405D-BC40-A8AD5F7AFB7B@freebsd.org> Content-Type: multipart/alternative; boundary="Apple-Mail=_1F91D23F-96C7-4431-90A8-CC0E66DFC15C" 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 List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.600.51.1.1\)) Subject: Re: git: bdb561843e86 - main - linux: implement pkey_alloc, pkey_free and pkey_mprotect Date: Sun, 16 Aug 2026 16:46:04 -0700 In-Reply-To: Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" , Devin Teske To: Michael Tuexen References: <6a810bcc.3ab17.312eef3@gitrepo.freebsd.org> X-Mailer: Apple Mail (2.3864.600.51.1.1) X-Rspamd-Queue-Id: 4hNXfb4Hlvz3bNL X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:14051, ipnet:207.231.64.0/19, country:US] X-Spamd-Bar: ---- : at_start: {auth_results {shxd.cx}} --Apple-Mail=_1F91D23F-96C7-4431-90A8-CC0E66DFC15C Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Aug 16, 2026, at 6:31=E2=80=AFAM, Michael Tuexen = wrote: >=20 >=20 >=20 >> On 16. Aug 2026, at 03:01, Devin Teske wrote: >>=20 >> The branch main has been updated by dteske: >>=20 >> URL: = https://cgit.FreeBSD.org/src/commit/?id=3Dbdb561843e865eaa5bbdc5394ed9d9c9= 1136240c >>=20 >> commit bdb561843e865eaa5bbdc5394ed9d9c91136240c >> Author: Devin Teske >> AuthorDate: 2026-08-16 00:58:19 +0000 >> Commit: Devin Teske >> CommitDate: 2026-08-16 00:58:43 +0000 >>=20 >> linux: implement pkey_alloc, pkey_free and pkey_mprotect >>=20 >> Bridge the Linux memory protection key syscalls to FreeBSD's native >> MPK support instead of returning ENOSYS. Modern Linux software >> probes these at startup: Chromium-based browsers (found via >> www/linux-brave) use protection keys for V8's heap and JIT >> sandboxing, and glibc >=3D 2.27 exposes the full API. >>=20 >> pkey_alloc() allocates from a per-process bitmap kept in the = process >> emuldata (key 0 implicitly allocated, matching Linux's >> mm_pkey_allocation_map; ENOSPC once keys 1..15 are exhausted or = when >> PKU is absent, as Linux returns on such hardware) and applies the >> requested initial access rights to the calling thread's PKRU, = located >> in the XSAVE area via xsave_area_offset(). pkey_free() is >> bookkeeping only: as on Linux, freeing neither untags pages nor >> updates PKRU. pkey_mprotect() performs the protection change and >> tags the range through amd64_pkru_update(), factored out of >> sysarch(2)'s AMD64_SET_PKRU/AMD64_CLEAR_PKRU implementation so that >> both share the same argument checking and map read lock >> synchronization with a parallel pmap_vmspace_copy() on fork; tags = die >> with the mapping, matching Linux VMA semantics. A pkey of -1 >> degrades to plain mprotect. >>=20 >> The allocation map is inherited on fork and reset on exec. At exec >> the Linux sysvecs initialize PKRU to 0x55555554, Linux's init_pkru >> default (access disabled for keys 1..15), so memory tagged with a >> not yet allocated key is inaccessible to threads that were never >> granted rights -- the property V8's thread isolation relies on. >> Setting PKRU at exec initializes the user FPU state slightly = earlier >> than the lazy first-use path; the state would be initialized = moments >> later in rtld/libc startup regardless. Protection key faults >> already deliver SEGV_PKUERR through the existing siginfo >> translation. >>=20 >> The common code carries no architecture ifdefs. Machine-dependent >> state lives in struct linux_pemuldata_md, embedded in the process >> emuldata in the manner of struct mdthread, and common code calls >> per-arch lifecycle hooks (linux_pemuldata_init_md/_exec_md) and = pkey >> back ends after performing the parameter validation Linux applies >> regardless of hardware support. On amd64 the implementation lives >> in sys/amd64/linux/linux_pkru.c, compiled into linux_common and >> serving both the 64-bit and 32-bit Linux ABIs. Elsewhere (arm64, >> i386) linux_emul_md.c provides stubs returning what Linux returns = on >> hardware without protection keys (ENOSPC from pkey_alloc; >> pkey_mprotect with a pkey of -1 acts as plain mprotect), so >> applications take their normal no-PKU fallback instead of the = ENOSYS >> path. >>=20 >> PR: 297427 >> MFC after: 1 month >> Reviewed by: kib >> Differential Revision: https://reviews.freebsd.org/D58782 > Hi Devin, >=20 > This breaks compilation for me on arm64. In = sys/arm64/linux/linux_emul_md.c > the file compat/linux/linux_emul.h is included which needs an = inclusion > of sys/imgact.h. >=20 > So >=20 > diff --git a/sys/arm64/linux/linux_emul_md.c = b/sys/arm64/linux/linux_emul_md.c > index 9dd507ad4f49..e55d3b712056 100644 > --- a/sys/arm64/linux/linux_emul_md.c > +++ b/sys/arm64/linux/linux_emul_md.c > @@ -7,6 +7,7 @@ > #include > #include > #include > +#include > #include > #include >=20 > fixes compilation for me. >=20 > Best regards > Michael Thank you, Michael. Fixed-up =E2=80=94=20 Devin --Apple-Mail=_1F91D23F-96C7-4431-90A8-CC0E66DFC15C Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On Aug 16, 2026, at 6:31=E2=80=AFAM, Michael Tuexen = <tuexen@FreeBSD.org> wrote:



On = 16. Aug 2026, at 03:01, Devin Teske <dteske@FreeBSD.org> = wrote:

The branch main has been updated by dteske:

URL: = https://cgit.FreeBSD.org/src/commit/?id=3Dbdb561843e865eaa5bbdc5394ed9d9c9= 1136240c

commit = bdb561843e865eaa5bbdc5394ed9d9c91136240c
Author: =     Devin Teske = <dteske@FreeBSD.org>
AuthorDate: 2026-08-16 00:58:19 = +0000
Commit:     Devin Teske = <dteske@FreeBSD.org>
CommitDate: 2026-08-16 00:58:43 = +0000

  linux: implement pkey_alloc, pkey_free and = pkey_mprotect

  Bridge the Linux memory protection key = syscalls to FreeBSD's native
  MPK support instead of = returning ENOSYS. Modern Linux software
  probes these at = startup: Chromium-based browsers (found = via
  www/linux-brave) use protection keys for V8's heap = and JIT
  sandboxing, and glibc >=3D 2.27 exposes the = full API.

  pkey_alloc() allocates from a per-process = bitmap kept in the process
  emuldata (key 0 implicitly = allocated, matching Linux's
  mm_pkey_allocation_map; = ENOSPC once keys 1..15 are exhausted or when
  PKU is = absent, as Linux returns on such hardware) and applies = the
  requested initial access rights to the calling = thread's PKRU, located
  in the XSAVE area via = xsave_area_offset(). pkey_free() is
  bookkeeping only: as = on Linux, freeing neither untags pages nor
  updates PKRU. = pkey_mprotect() performs the protection change and
  tags = the range through amd64_pkru_update(), factored out = of
  sysarch(2)'s AMD64_SET_PKRU/AMD64_CLEAR_PKRU = implementation so that
  both share the same argument = checking and map read lock
  synchronization with a = parallel pmap_vmspace_copy() on fork; tags die
  with the = mapping, matching Linux VMA semantics. A pkey of = -1
  degrades to plain mprotect.

  The = allocation map is inherited on fork and reset on exec. At = exec
  the Linux sysvecs initialize PKRU to 0x55555554, = Linux's init_pkru
  default (access disabled for keys = 1..15), so memory tagged with a
  not yet allocated key is = inaccessible to threads that were never
  granted rights -- = the property V8's thread isolation relies on.
  Setting = PKRU at exec initializes the user FPU state slightly = earlier
  than the lazy first-use path; the state would be = initialized moments
  later in rtld/libc startup = regardless. Protection key faults
  already deliver = SEGV_PKUERR through the existing = siginfo
  translation.

  The common code = carries no architecture ifdefs. Machine-dependent
  state = lives in struct linux_pemuldata_md, embedded in the = process
  emuldata in the manner of struct mdthread, and = common code calls
  per-arch lifecycle hooks = (linux_pemuldata_init_md/_exec_md) and pkey
  back ends = after performing the parameter validation Linux = applies
  regardless of hardware support. On amd64 the = implementation lives
  in sys/amd64/linux/linux_pkru.c, = compiled into linux_common and
  serving both the 64-bit = and 32-bit Linux ABIs. Elsewhere (arm64,
  i386) = linux_emul_md.c provides stubs returning what Linux returns = on
  hardware without protection keys (ENOSPC from = pkey_alloc;
  pkey_mprotect with a pkey of -1 acts as plain = mprotect), so
  applications take their normal no-PKU = fallback instead of the = ENOSYS
  path.

  PR: =             29= 7427
  MFC after:      1 = month
  Reviewed by: =    kib
  Differential Revision: =  https://reviews.freebsd.org/D58782
Hi Devin,

This breaks compilation for me on arm64. In = sys/arm64/linux/linux_emul_md.c
the file compat/linux/linux_emul.h is = included which needs an inclusion
of sys/imgact.h.

So

diff --git = a/sys/arm64/linux/linux_emul_md.c = b/sys/arm64/linux/linux_emul_md.c
index 9dd507ad4f49..e55d3b712056 = 100644
--- = a/sys/arm64/linux/linux_emul_md.c
+++ = b/sys/arm64/linux/linux_emul_md.c
@@ -7,6 +7,7 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
+#include <sys/imgact.h>
  #include = <compat/linux/linux_emul.h>
#include = <compat/linux/linux_mmap.h>

fixes compilation for me.

Best regards
Michael

Thank you, = Michael.

Fixed-up
=E2=80=94 
=
Devin

= --Apple-Mail=_1F91D23F-96C7-4431-90A8-CC0E66DFC15C--