From nobody Fri Oct 2 03:37:47 2026 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5902722689C for ; Thu, 6 Aug 2026 00:02:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785974547; cv=none; b=eOLQuGysnebvCjP7Eldyjgs7NqJLdQWfNA/rHGNenNSgRUvu1uc3Se489FTUb1Zso0RD/4mboQcfOGjsUChFb+slmLlo2YY4iejxITzp8k2ckwncUbZec0ExKSp2fYXZnSSY7U1QGTQVC5ZhzniqkcsoIQCENbUTJeRQZHWpw+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785974547; c=relaxed/simple; bh=OYt1NcAB8ZvbK7dcVxHMwgHBezL+06d25+6wCfka1TU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=UKYOP5bOZ+n4/Z+qElUiyRA8Xa5LSgXTedtfbMvt+dvCQazvrI6FH+li5NRdHlNifBa90fmqmTmKstRU+ECYBoiASKgoiQn+jmWSlnrW0BhkKluNyLz9hMKJJ4TXkOTCrB4EW2q0eukVr50AIFvoeB7Du4rS4b7lLUCZ5x9U3NM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bourg.net; spf=pass smtp.mailfrom=bourg.net; dkim=pass (1024-bit key) header.d=bourg.net header.i=@bourg.net header.b=l1zYmSTJ; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bourg.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bourg.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=bourg.net header.i=@bourg.net header.b="l1zYmSTJ" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-848761b5897so1213658b3a.3 for ; Wed, 05 Aug 2026 17:02:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bourg.net; s=google; t=1785974538; x=1786579338; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=C+ndS92zXPqAJ+cNcpLuaSmLaftIm1AvtWGzzi2M09w=; b=l1zYmSTJaQVZDdvDHsnXEwl4uZyLu1ELt2oVBxPKJvzWR48WQ4y4tJd1N8e/YufR5t d2SPOEIan3hwLdenWWGgKFlDqnIs5Sa5ivHiL2dTi7s/MuyayaZCpB4RZlyf7jMsfgKj 0A7GbzfvqVPko9LSeLKNq1XYVPHs9PBKn3H00= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785974538; x=1786579338; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=C+ndS92zXPqAJ+cNcpLuaSmLaftIm1AvtWGzzi2M09w=; b=HxMsnu48Sq4p7YZ8wQDdgspyi41dA1ItuJYZnRn6Z6q/9ZYUaiM6be4WyoUOaoaLyg S/ZvLqlQPeIq/ar6tgKk2nmNsq3DQKeKUak2a7PSsaVnsH5wGYF2SrS1usFVL/2QstFk jvZRxLT2LDWlOvylsmcVX9hJksh1DIyOZh3zw42/7JLw3qzA+OZs6s3bGhBb6xjS/7G3 xQK92eMtZN/shbsspxuTk1q5/f2HOfirRMrIRowUmL15kMtzo+yY28Ck2P+6z8OTf5vM pOkyr6Pm9m6Ilh2WkioIVbLsAJswHa2ACbimu/SGx2QVLIQPUCwS1lh0rNp0qFUIyby0 HSLw== X-Forwarded-Encrypted: i=1; AHgh+RoQfto+i8rbecOniJvXOu9zkGrtNC2JVWBAuvngUz4nZ6J4BZwMEFedJh2TkwsYLMEiT7TTuylqLE3rCVw=@vger.kernel.org X-Gm-Message-State: AOJu0Ywrh/mu6N/V9iWoXkiNoL9GuFRxuKAOeePES44uLVtysxKCnFWq oARaUoiaTgXDaCLpGV6VXAAqK4ewEa91SYNoM6+MbdfkqDa4IPH0IWE3xRWJmoW87T0= X-Gm-Gg: AR+sD10yCBKgwFLRa0UWL+MiKnsmZOY8shps+8GxE0ByR2Upx/D1BjLOzeyFHJxhAps nt487AnYY5tIfJlqJar4Sgc9z+TvB3ffu5oCGz6J+gsUY5utLB5QmGODMlB8kU5jaMqn/tGmdXV LriiW4julEcVlgAnLZMmR5w1mUWq555vn/WPh6W3/NeV1pNOCoE7PXQAj5fMsJBd8EtYjD8uktx n15smmePJIr/CpNOEbTkNrpYZ8R0qi81LLRouDKpXEveafOdiBuEeBuxYxUR02siQ6xeXc3bFPn MlMEOxiKfuyAR6C3z7lXXTWufw5cXIFF8/FJ4sNfIVpnK86vIY1qIH3yiqv0mbcu/P2SJy2SbIU yoSxtJINM+Wj5icZpca1sSXCKHNJMKjIFkk2yWOVyuqseLFsVoJIQsOkiISLc/1IfHvI8MD5Ffz DHQnY8nnQBF6j/2zK72Tt6JoOxl9+vK0gEUrNqCqgplpQLpqaaRCVbFlwsWwhW+aGXqGIKangp0 U+q4qMfps8ytqv7sgLCMoXVUkifRiZANgiF9EknjnLFgjnW X-Received: by 2002:a05:6a00:8d81:b0:847:7f3c:b5f5 with SMTP id d2e1a72fcca58-84f2dfc8f83mr13807202b3a.11.1785974537350; Wed, 05 Aug 2026 17:02:17 -0700 (PDT) Received: from deskstar (syn-024-216-245-233.biz.spectrum.com. [24.216.245.233]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84f4538bb3bsm180478b3a.12.2026.08.05.17.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2026 17:02:15 -0700 (PDT) From: gus bourg To: ardb@kernel.org Cc: catalin.marinas@arm.com, will@kernel.org, ilias.apalodimas@linaro.org, linux-efi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Gus Bourg Subject: [PATCH] arm64/efi: Do not call EFI runtime services preemptibly under SW PAN Date: Wed, 5 Aug 2026 17:01:44 -0700 Message-ID: <20260806000144.3388823-1-gus@bourg.net> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Gus Bourg When PAN is emulated by switching TTBR0_EL1, arch_efi_call_virt_setup() installs the EFI mm into TTBR0_EL1 via uaccess_ttbr0_enable(), and only a return from exception ever puts it back: check_and_switch_context() skips the register write by design ("Defer TTBR0_EL1 setting for user threads to uaccess_enable() when emulating PAN"), and __switch_to() does not touch it either. switch_mm() updates only thread_info->ttbr0. Since commit a5baf582f4c0 ("arm64/efi: Call EFI runtime services without disabling preemption") the runtime call is preemptible, so the EFI worker can now be scheduled out inside that window. An involuntary preemption is harmless, because __swpan_entry_el1()/__swpan_exit_el1() save and restore the state around the exception. A voluntary reschedule is not: it performs no return from exception, so the worker resumes with another task's TTBR0_EL1 - or reserved_pg_dir - and the next efi_mm access takes a level 0 translation fault. There is such a preemption point in arch_efi_call_virt_setup() itself, immediately after the TTBR0 install: __efi_fpsimd_begin() -> kernel_neon_begin() -> put_cpu_fpsimd_context() -> local_bh_enable() -> preempt_check_resched(). On a Khadas VIM3 (Cortex-A73/A53, no FEAT_PAN, so CONFIG_ARM64_SW_TTBR0_PAN is in use) this reproduces as: Unable to handle kernel access to user memory outside uaccess routines at virtual address 00000000f322ff30 Mem abort info: ESR =3D 0x0000000096000004 FSC =3D 0x04: level 0 translation fault Internal error: Oops: 0000000096000004 [#1] SMP Workqueue: efi_rts_wq efi_call_rts pstate: 80400005 (Nzcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=3D--) pc : efi_call_rts+0xd8/0x288 Call trace: efi_call_rts+0xd8/0x288 (P) process_one_work+0x178/0x4f8 worker_thread+0x194/0x328 The faulting instruction is the kernel's own load of efi.runtime->get_time; firmware is never entered, so efi_runtime_fixup_exception() declines it (the PC is kernel text) and the result is a full oops rather than EFI_ABORTED. The EFI runtime path is then wedged for the rest of the boot: efi_rts_work.efi_rts_comp is never completed and the runtime lock is never released, so every subsequent caller blocks in uninterruptible sleep, and poweroff hangs because EFI_RUNTIME_SERVICES is still set. The failing window was identified with ftrace, tracing efi_call_rts, arch_efi_call_virt_setup, kthread_use_mm, __efi_fpsimd_begin, kernel_neon_begin and arch_efi_call_virt_teardown together with sched_switch. Of four preemptions observed inside the window over 12726 calls, the two that landed before the TTBR0 install (in kthread_use_mm) were harmless and the two that landed in kernel_neon_begin were not; one of those faulted. Keep configurations that emulate PAN on the non-preemptible path, which is what they used before a5baf582f4c0. Systems with FEAT_PAN are unaffected: system_uses_ttbr0_pan() is false there, uaccess_ttbr0_enable() is a no-op, and check_and_switch_context() installs TTBR0_EL1 on every switch. Fixes: a5baf582f4c0 ("arm64/efi: Call EFI runtime services without disablin= g preemption") Cc: # v6.19+ Assisted-by: Claude:claude-opus-5 ftrace Signed-off-by: gus bourg Tested-by: gus bourg --- arch/arm64/kernel/efi.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c index 30cd7f804398..1b666ca79758 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -166,11 +166,32 @@ asmlinkage efi_status_t efi_handle_corrupted_x18(efi_= status_t s, const char *f) return s; } =20 +/* + * Whether an EFI runtime service call may run preemptibly. + * + * When PAN is emulated by switching TTBR0_EL1, the EFI mm is installed in= to + * the register by uaccess_ttbr0_enable() below, and only a return from + * exception ever puts it back: check_and_switch_context() deliberately sk= ips + * the write ("Defer TTBR0_EL1 setting for user threads to uaccess_enable() + * when emulating PAN"), and __switch_to() never touches it. A voluntary + * reschedule performs no return from exception, so a preemptible runtime = call + * can be scheduled back in holding another task's TTBR0_EL1 and take a le= vel 0 + * translation fault on its next efi_mm access. Keep those configurations = on + * the non-preemptible path, which is what they used before commit + * a5baf582f4c0 ("arm64/efi: Call EFI runtime services without disabling + * preemption"). + */ +static bool efi_runtime_preemptible(void) +{ + return !system_uses_ttbr0_pan() && preemptible() && + (current->flags & PF_KTHREAD); +} + void arch_efi_call_virt_setup(void) { efi_runtime_assert_lock_held(); =20 - if (preemptible() && (current->flags & PF_KTHREAD)) { + if (efi_runtime_preemptible()) { /* * Disable migration to ensure that a preempted EFI runtime * service call will be resumed on the same CPU. This avoids @@ -207,7 +228,7 @@ void arch_efi_call_virt_teardown(void) */ uaccess_ttbr0_disable(); =20 - if (preemptible() && (current->flags & PF_KTHREAD)) { + if (efi_runtime_preemptible()) { kthread_unuse_mm(&efi_mm); migrate_enable(); } else { --=20 2.53.0