From nobody Thu Oct 2 09:22:11 2025 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 590AE2F7ABD for ; Thu, 18 Sep 2025 10:30:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758191439; cv=none; b=XjWYcj19xCZ8OvYxezvjZXmJRJeQyC0+2a5nr2Y4j4rbfrGqLoKaNxOPow4qZDktZvzmlknXSeMWccca8ZyiUUey29KzLD4X2K85bFmpDeIZOypq04h0WhUERqdtGFcWvFcHCtFxYYUSJIS3Ai1I26KiAD3eniQpIZAXs0ZVQlY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758191439; c=relaxed/simple; bh=9IGxOSD8/IQWLwc8jT7mSjBjvXiOryrCfl8S8dMZveI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ckbPaqex8ISvHNyW4vZRlWlJek7/xmiHGFHWSLc3eD/OVUn8kPkoZmd42bkfzdVLJN8Oo/W8owd+mJ0XY6Q15infowNKa9nfhhqAC0QQRT4/DD6SxGsLdv/0ARGAIObdehiMWYIKCyfgZ0mz2JRvNC+dGLaTbreP3s6hEArfYTc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jf+Y7Sol; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jf+Y7Sol" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-45dd9a66c3fso2586285e9.1 for ; Thu, 18 Sep 2025 03:30:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1758191435; x=1758796235; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=9g+ayt4FM2fztSLOAfcyGb2gFshK+qygOJzTnKa0+m8=; b=jf+Y7Sol+xrsEKY4qAJ4bS/lgFYjmExMOG8jASjDwJI3oXxGyP7v8mu8bOZqcxbD2K pIDKVkcNpt8dl23XwRA0O2nHoKoDC2iYGTCs908wfsDWEwnQwXUi1o3DIgcnieEnk30E 4C0LW9EPK9vok3aJciech8wBmlsp8W/9wx9QgsD/s8odWX+2pdUlCvKbS99amkDXG16h 7Nx4dtnL7NHSNXc/NUyBZSkGaoDjYYvUbpb4Jdkp7eU7v1LI2ikeWo8KygH6haI6pVOZ UdV1t2ygY3ZVwnpccL8yaFbD6CGkc5PhkZ60Y/uuPO/q7jI+N1qtgXKOlHPogK57wHfp D8yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758191435; x=1758796235; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9g+ayt4FM2fztSLOAfcyGb2gFshK+qygOJzTnKa0+m8=; b=k87jkRrH2y1XI4wQERN5FXSurRKsz+wZzUrjBoecixfqSn7NgXQntaNRLNJc6ydTMP ThCNN3D3IVfTl2EMzADYuVqlOq3DOO94pP8cc0hTsQ/dAzZTeCrLxGp5dQmqipWYQBQ9 r8dHAmZM+3Gy+EtaSiaKYTmUWvkveoRKic4Vvg+0FPw1RkufNWZBw57MNiAaQsrVOIU+ 4XyDwFpsh1kDqZSZdYuieB4myY/kTbaTmRdcu9FUGHGlDOA5GjEjwLRQeJ2Q/lz/zQ6u Tk1XgNrXi9xWyTfQJRWpAukXm/qeVZAM8MXfvM0g8sPBxd7+a8AO6CMtXkmqWiwp7h7u 11pQ== X-Gm-Message-State: AOJu0Yyg/yrha55ZDujgdBeERVqLLpdZyKR19ncd/O1QCrAJJwBfHkPw z+Ot6RXLlvd5fq8+mG9UJq95rcvcTy4JTaTF+5fLsNlZ+KMMnYuu0YO+8GP8S2UixVnE5KcB3w= = X-Google-Smtp-Source: AGHT+IHLme5GiJqIwrRwEMO5+ZWXnbB3UysoUpD5npyfKiKL033RbmiEockBVOaN3XQJRx9xa79Wam2T X-Received: from wmbeq8.prod.google.com ([2002:a05:600c:8488:b0:45d:d39b:53ca]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1d05:b0:459:db7b:988e with SMTP id 5b1f17b1804b1-46202a0e68dmr48837855e9.13.1758191435539; Thu, 18 Sep 2025 03:30:35 -0700 (PDT) Date: Thu, 18 Sep 2025 12:30:12 +0200 In-Reply-To: <20250918103010.2973462-10-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250918103010.2973462-10-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=804; i=ardb@kernel.org; h=from:subject; bh=6f4GfQJsdA/kppXTxBZ4Rl0+1i1W3t0MYvIV3huOmLg=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIeP0fVOTx8nmnjWPnBfWRlyx2Nust7U+6NwL8w/u6QyND RPLOTw7SlkYxLgYZMUUWQRm/3238/REqVrnWbIwc1iZQIYwcHEKwERqTBgZluiZM7wIMHV4y6zk ptEotHLrMlbGvhem5399bg39UWz4i+F/seOk8zl9+Tn7j2ns0a9iejh1HUdq+LoVum3H9upcd1b gBQA= X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog Message-ID: <20250918103010.2973462-11-ardb+git@google.com> Subject: [PATCH v3 1/8] efi: Add missing static initializer for efi_mm::cpus_allowed_lock From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Will Deacon , Mark Rutland , Sebastian Andrzej Siewior , Peter Zijlstra , Catalin Marinas , Mark Brown , stable@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Initialize the cpus_allowed_lock struct member of efi_mm. Cc: Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/efi.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 1ce428e2ac8a..fc407d891348 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -74,6 +74,9 @@ struct mm_struct efi_mm =3D { .page_table_lock =3D __SPIN_LOCK_UNLOCKED(efi_mm.page_table_lock), .mmlist =3D LIST_HEAD_INIT(efi_mm.mmlist), .cpu_bitmap =3D { [BITS_TO_LONGS(NR_CPUS)] =3D 0}, +#ifdef CONFIG_SCHED_MM_CID + .cpus_allowed_lock =3D __RAW_SPIN_LOCK_UNLOCKED(efi_mm.cpus_allowed_lock), +#endif }; =20 struct workqueue_struct *efi_rts_wq; --=20 2.51.0.384.g4c02a37b29-goog From nobody Thu Oct 2 09:22:11 2025 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 7DEAF2F9C2C for ; Thu, 18 Sep 2025 10:30:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758191440; cv=none; b=XliNL8ipNI8t/HtRIPT5+wNoE2fFTkb6H5YkFH3pl6lg8+Aw0U/YfrQS+m8RZ48TXvGW6uGhehlmqg5hvZ/5oS9Y9iH83E70mkxrAo9hI5Y7DmU/2Cy3+Oy+Ukg4vXNdsK4ZvpGVHsGPfbGkdQJ67SHNPAOyNSFGv0WWrrAtz4U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758191440; c=relaxed/simple; bh=XX1si8MsLZL6DKbFp9rsm3tH13zIzZwGncktoL6Zm9E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WssfWaYHBwngZEO7LHUTblDBeBFzySlUHOI7riNGbNUTnZm5GMmlYTXsSyF5ZrjMLqs0jzHHi0Ei3Y8ey98XxmtqJCdmIRL09K9eatG/pb2SdgX84lA+aj/3/0DX/b1LMdFzeiMaVOp7XFd3uBoOJ+n50sqXvZPf2eZ2mHDjUB0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=z2bit+pN; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="z2bit+pN" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-45f2b9b99f0so4711545e9.1 for ; Thu, 18 Sep 2025 03:30:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1758191436; x=1758796236; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=sJFIm2d9T+2x529qILYhaPbYtpi/V7t2rebVAI4uzpE=; b=z2bit+pN/yCaRIMFOnqkn0fsUkG8pi8IDdRMI/kw90pwrRmrigkjZfATSe66zdV1at tjp1waF/mNjMLrvIJ3Y0WVbvrdlBwsdLwKzc19EMvXu/VZ9WbQ6hFHQN7zZpt0UpKP0+ GeeHitv3SPMxzo2eonRtfuGib8r4ZpVaOONnWpRzsosBoxGRMIfr3Lmd6gujqD0VRsrp As4YrwLZb/jqhDRfZEb/KDqt0JaBKtUVknqzDzEvikiRWDOipzh6XO3cDZR02/3iJ92z O6w8/gbkCbtvtzNcIhtDdl//VBuiaAhrpztIsAuSGxwC+en3i+cPW+IM/L9U+diU/h3B IecA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758191436; x=1758796236; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sJFIm2d9T+2x529qILYhaPbYtpi/V7t2rebVAI4uzpE=; b=WnyWPmJZos0U79IjANuOyip6NoeGAx/VBV3Kpjg7FKiOfcKu9dFuHhGfESUlMiN4MZ 9taBOgGpeycIjBab9sEv5TbwCn6sELC/Kwn4J9ItVvq5C0JA0ZkXbCUUrDpoNocFBbZz TbTCtsg8Dz8ZZGyE+vr9obJ67ROeteadtkF0ztgnNyy+MtS3s4J6ZxUqgmn/wJgkZH4m PuNhL7c1RTTbJc3MeRMXmD6WmZJonVT0pi1OLV9GPJk5UeqhZa1gfzCY/pmH76QivVNT yZmoTUgTc/tFmEQ2ysS08f9KgeRRaodnOPmtaxX6OASOZ2zZDwPmNA7WcGC3MqCawfDF 2qqA== X-Gm-Message-State: AOJu0YziMQejXTrOIVEZh/0UvqELCsywXLKoyYtwWjXfviMmTtZzI1V1 05Qv5STz4HTW43ONu8BGnxc9Owu8wJ0COnl4aaOKWSt79pFsDbG+8sFSdTbqmw6X5uAVNE397Q= = X-Google-Smtp-Source: AGHT+IECq4I0w3/6A7apwZOsonOjQiQiwYahHKMYIdDTMnYZ7BWgqvCSc9iRaAPTx8Hq2U9oL40BX8Uq X-Received: from wmbjg18.prod.google.com ([2002:a05:600c:a012:b0:45f:28d1:7681]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a7b:cc13:0:b0:45d:5c71:769d with SMTP id 5b1f17b1804b1-465045b4a35mr22803025e9.8.1758191436765; Thu, 18 Sep 2025 03:30:36 -0700 (PDT) Date: Thu, 18 Sep 2025 12:30:13 +0200 In-Reply-To: <20250918103010.2973462-10-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250918103010.2973462-10-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=5534; i=ardb@kernel.org; h=from:subject; bh=jAbiLA3tzC1h/HOwCrnaLpF/g7Oox62158I7TXeI+Yc=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIeP0fbOrV0QyptVlWF8wjmZdefrUxse3p3dosdhdObh1j 7XsOrVJHaUsDGJcDLJiiiwCs/++23l6olSt8yxZmDmsTCBDGLg4BWAiKYcZ/ifGJYSa/tkbFLAs 8frv13Nephy5xcfFFbx3otAZ/U8hZ5Yz/DMIqHx75Y+EkqJo6Ml5ApsXv1Ow4a9T2ZziNXdjXsK e5xwA X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog Message-ID: <20250918103010.2973462-12-ardb+git@google.com> Subject: [PATCH v3 2/8] efi/runtime: Return success/failure from arch_efi_call_virt_setup() From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Will Deacon , Mark Rutland , Sebastian Andrzej Siewior , Peter Zijlstra , Catalin Marinas , Mark Brown Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Permit the arch glue to signal failure from arch_efi_call_virt_setup(). This permits the use of sleeping locks in the call wrappers, and this will allow EFI runtime services to be invoked without the need for disabling preemption. Signed-off-by: Ard Biesheuvel --- arch/arm/include/asm/efi.h | 2 +- arch/arm64/include/asm/efi.h | 2 +- arch/arm64/kernel/efi.c | 3 ++- arch/loongarch/include/asm/efi.h | 2 +- arch/riscv/include/asm/efi.h | 2 +- arch/x86/include/asm/efi.h | 2 +- arch/x86/platform/efi/efi_32.c | 3 ++- arch/x86/platform/efi/efi_64.c | 3 ++- drivers/firmware/efi/riscv-runtime.c | 3 ++- 9 files changed, 13 insertions(+), 9 deletions(-) diff --git a/arch/arm/include/asm/efi.h b/arch/arm/include/asm/efi.h index e408399d5f0e..0809a69bb579 100644 --- a/arch/arm/include/asm/efi.h +++ b/arch/arm/include/asm/efi.h @@ -23,7 +23,7 @@ void arm_efi_init(void); int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md); int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *m= d, bool); =20 -#define arch_efi_call_virt_setup() efi_virtmap_load() +#define arch_efi_call_virt_setup() (efi_virtmap_load(), true) #define arch_efi_call_virt_teardown() efi_virtmap_unload() =20 #ifdef CONFIG_CPU_TTBR0_PAN diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h index bcd5622aa096..decf87777f57 100644 --- a/arch/arm64/include/asm/efi.h +++ b/arch/arm64/include/asm/efi.h @@ -37,7 +37,7 @@ int efi_set_mapping_permissions(struct mm_struct *mm, efi= _memory_desc_t *md, extern u64 *efi_rt_stack_top; efi_status_t __efi_rt_asm_wrapper(void *, const char *, ...); =20 -void arch_efi_call_virt_setup(void); +bool arch_efi_call_virt_setup(void); void arch_efi_call_virt_teardown(void); =20 /* diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c index 6c371b158b99..9b03f3d77a25 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -167,11 +167,12 @@ asmlinkage efi_status_t efi_handle_corrupted_x18(efi_= status_t s, const char *f) =20 static DEFINE_RAW_SPINLOCK(efi_rt_lock); =20 -void arch_efi_call_virt_setup(void) +bool arch_efi_call_virt_setup(void) { efi_virtmap_load(); raw_spin_lock(&efi_rt_lock); __efi_fpsimd_begin(); + return true; } =20 void arch_efi_call_virt_teardown(void) diff --git a/arch/loongarch/include/asm/efi.h b/arch/loongarch/include/asm/= efi.h index eddc8e79b3fa..84cf2151123f 100644 --- a/arch/loongarch/include/asm/efi.h +++ b/arch/loongarch/include/asm/efi.h @@ -14,7 +14,7 @@ void efifb_setup_from_dmi(struct screen_info *si, const c= har *opt); =20 #define ARCH_EFI_IRQ_FLAGS_MASK 0x00000004 /* Bit 2: CSR.CRMD.IE */ =20 -#define arch_efi_call_virt_setup() +#define arch_efi_call_virt_setup() true #define arch_efi_call_virt_teardown() =20 #define EFI_ALLOC_ALIGN SZ_64K diff --git a/arch/riscv/include/asm/efi.h b/arch/riscv/include/asm/efi.h index 46a355913b27..a7b4d719e7be 100644 --- a/arch/riscv/include/asm/efi.h +++ b/arch/riscv/include/asm/efi.h @@ -40,7 +40,7 @@ static inline unsigned long efi_get_kimg_min_align(void) =20 #define EFI_KIMG_PREFERRED_ADDRESS efi_get_kimg_min_align() =20 -void arch_efi_call_virt_setup(void); +bool arch_efi_call_virt_setup(void); void arch_efi_call_virt_teardown(void); =20 unsigned long stext_offset(void); diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h index f227a70ac91f..879c8402e024 100644 --- a/arch/x86/include/asm/efi.h +++ b/arch/x86/include/asm/efi.h @@ -140,7 +140,7 @@ extern void efi_delete_dummy_variable(void); extern void efi_crash_gracefully_on_page_fault(unsigned long phys_addr); extern void efi_free_boot_services(void); =20 -void arch_efi_call_virt_setup(void); +bool arch_efi_call_virt_setup(void); void arch_efi_call_virt_teardown(void); =20 extern u64 efi_setup; diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c index b2cc7b4552a1..215f16ce84ab 100644 --- a/arch/x86/platform/efi/efi_32.c +++ b/arch/x86/platform/efi/efi_32.c @@ -141,10 +141,11 @@ void __init efi_runtime_update_mappings(void) } } =20 -void arch_efi_call_virt_setup(void) +bool arch_efi_call_virt_setup(void) { efi_fpu_begin(); firmware_restrict_branch_speculation_start(); + return true; } =20 void arch_efi_call_virt_teardown(void) diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c index b4409df2105a..d4b1e70f41fa 100644 --- a/arch/x86/platform/efi/efi_64.c +++ b/arch/x86/platform/efi/efi_64.c @@ -443,12 +443,13 @@ static void efi_leave_mm(void) unuse_temporary_mm(efi_prev_mm); } =20 -void arch_efi_call_virt_setup(void) +bool arch_efi_call_virt_setup(void) { efi_sync_low_kernel_mappings(); efi_fpu_begin(); firmware_restrict_branch_speculation_start(); efi_enter_mm(); + return true; } =20 void arch_efi_call_virt_teardown(void) diff --git a/drivers/firmware/efi/riscv-runtime.c b/drivers/firmware/efi/ri= scv-runtime.c index fa71cd898120..07e04b8f982a 100644 --- a/drivers/firmware/efi/riscv-runtime.c +++ b/drivers/firmware/efi/riscv-runtime.c @@ -142,10 +142,11 @@ static void efi_virtmap_unload(void) preempt_enable(); } =20 -void arch_efi_call_virt_setup(void) +bool arch_efi_call_virt_setup(void) { sync_kernel_mappings(efi_mm.pgd); efi_virtmap_load(); + return true; } =20 void arch_efi_call_virt_teardown(void) --=20 2.51.0.384.g4c02a37b29-goog From nobody Thu Oct 2 09:22:11 2025 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 496482FB0BF for ; Thu, 18 Sep 2025 10:30:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758191441; cv=none; b=QjUUARG+zmVauV/DD6/D6hnRJ/2rFvVcmTsY6NGHfj7uvqbNcBPfIpd5gUNqTHk5KEVY4r2ENe32lqsIXP8JV4BPlqlNRljFePL+iz5KUcEOYr1sybqqaIATCWBWhxFYyB+sKnmdKV/HXuFL4378TsZ06T11pqVZ+bFAjYLYhy0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758191441; c=relaxed/simple; bh=DW2Ev36DfFisiSLl+rnUFogK7g/mxLQ+QNCw/NXoxlI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Ico4pvAFD0dlAI8Ln7QjGxK9pGnV036uqbt74MqXISoNh0C/Is4CiTn9+8Bhx6C5DMK5ixQyZZvhHRo5HC+TjKLs2B+AWCZWNS3ykb6DLy1BD69cOQgBhaDmkQsRUT6wKbzy9FFYGMY77ZIY0Kpi820dNb758AoK7HXld7OjkMM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WdK8EDVX; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WdK8EDVX" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-45f2a1660fcso7003615e9.1 for ; Thu, 18 Sep 2025 03:30:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1758191438; x=1758796238; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ZeKidemFHugBWvlLdngZx3GvGl5BhC7gmcxHsIeIDzM=; b=WdK8EDVXcRdGpQWeXdUKaNqKxWsj+eKbyxkm3UcOG3LA+7r73UH2HmkPv7jl9J+V17 OFKO4mW85xiW/pgC6B54pVVigRy03McVrccke9Q+DMIGcx8VD5Plpm7FkGNW5i5BNs/A OpX2i10fJXlXQp6I2KB6ZsuuV9RefAvlONDNAfLOXegn8oDqE6VeiLDEsjDEmvmbptDh KIDYE3eblncJRxSA4PqzcJM6YAPCBZU3uVcHrMr3Kinos23G8+c4ZQR0bBFUUws8UArC lsJCRWUEaeBXEblwEZmIXcDeIGWHJy3b/cnBqP0VClqRvHPcV5Hp8vmVHKfWFtIRpdD3 Dsag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758191438; x=1758796238; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZeKidemFHugBWvlLdngZx3GvGl5BhC7gmcxHsIeIDzM=; b=nxasyxyR/cLpXGWKOlksuhvR+23jZOt33YJ8Y8eml1QlO5NrJSC0/ECKyokCuZVNR8 izlO2dSIiMwoPLXq+dNhjaA07FiLAYujLIM8gbUMxN4wNcRI6l9YMPGloSgrqKWpCFA8 jU6yy+YRCajcRnSvsOfeBHf2zlVGHfvExk0P1D+4YUJxIQJ/1OmTXKtQqDbxUW1ylT/A 9FUKxEuKNrTmvtMhyXqdEo01onTc1J91J47UzYyMJbIsaUlcwfURPUowA6znMNJpgK77 k2oMGjI8cjoXchweMM4XG6RkcqbXp4OYqE4iK+mouxuWy8rPGh0tbQvSRrKDxWfB0dtJ kSWw== X-Gm-Message-State: AOJu0YxPueU+ZmY/veSI89zqpTMrtxcLEpa06DJzfQ7YuAJvuD5Xx1tl EdYlQZsgee1Bn2LiQc1FDhJ7SK2su2zSnxOqj+olh9I/5kYLqF2De43cohBii/NskcdVS+SrEQ= = X-Google-Smtp-Source: AGHT+IGO4Q3fZanqmM0wjFCsbf3Jf0mIV+3pWr1nuubcDlla09trMD8Lvrvc6pAWYylB9LlHYwGCQUbT X-Received: from wmbhh13.prod.google.com ([2002:a05:600c:530d:b0:45d:cf67:3908]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1554:b0:45d:d6fc:24f7 with SMTP id 5b1f17b1804b1-462074c55cfmr47460695e9.32.1758191437764; Thu, 18 Sep 2025 03:30:37 -0700 (PDT) Date: Thu, 18 Sep 2025 12:30:14 +0200 In-Reply-To: <20250918103010.2973462-10-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250918103010.2973462-10-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=4130; i=ardb@kernel.org; h=from:subject; bh=sXlqN2yq2zEV1WP5L/wE4aoN5/FR7QwPK75VLdrzA4A=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIeP0fYut8ixeb+/ldwe/Zy95q5z8xOp3Z7Xn8vJFqpM+n gip5eDpKGVhEONikBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABNZVcnIMIF7L//dMvlJe1Wb rH1n/p3Hs5TR8aNi56PZO1wKtNOc8xkZvvPc4/2flPr428W+ecVz+P5FL+Ctl25R7tb+f0rg2cF oJgA= X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog Message-ID: <20250918103010.2973462-13-ardb+git@google.com> Subject: [PATCH v3 3/8] efi/runtime: Deal with arch_efi_call_virt_setup() returning failure From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Will Deacon , Mark Rutland , Sebastian Andrzej Siewior , Peter Zijlstra , Catalin Marinas , Mark Brown Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Deal with arch_efi_call_virt_setup() returning failure, by giving up and returning an appropriate error code to the caller. Signed-off-by: Ard Biesheuvel --- arch/x86/platform/uv/bios_uv.c | 3 ++- drivers/firmware/efi/runtime-wrappers.c | 20 +++++++++++++------- include/linux/efi.h | 8 ++++---- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/arch/x86/platform/uv/bios_uv.c b/arch/x86/platform/uv/bios_uv.c index bf31af3d32d6..a442bbe5b1c2 100644 --- a/arch/x86/platform/uv/bios_uv.c +++ b/arch/x86/platform/uv/bios_uv.c @@ -32,7 +32,8 @@ static s64 __uv_bios_call(enum uv_bios_cmd which, u64 a1,= u64 a2, u64 a3, */ return BIOS_STATUS_UNIMPLEMENTED; =20 - ret =3D efi_call_virt_pointer(tab, function, (u64)which, a1, a2, a3, a4, = a5); + ret =3D efi_call_virt_pointer(tab, function, BIOS_STATUS_UNIMPLEMENTED, + (u64)which, a1, a2, a3, a4, a5); =20 return ret; } diff --git a/drivers/firmware/efi/runtime-wrappers.c b/drivers/firmware/efi= /runtime-wrappers.c index 708b777857d3..82a27b414485 100644 --- a/drivers/firmware/efi/runtime-wrappers.c +++ b/drivers/firmware/efi/runtime-wrappers.c @@ -219,7 +219,10 @@ static void __nocfi efi_call_rts(struct work_struct *w= ork) efi_status_t status =3D EFI_NOT_FOUND; unsigned long flags; =20 - arch_efi_call_virt_setup(); + if (!arch_efi_call_virt_setup()) { + status =3D EFI_NOT_READY; + goto out; + } flags =3D efi_call_virt_save_flags(); =20 switch (efi_rts_work.efi_rts_id) { @@ -308,6 +311,7 @@ static void __nocfi efi_call_rts(struct work_struct *wo= rk) efi_call_virt_check_flags(flags, efi_rts_work.caller); arch_efi_call_virt_teardown(); =20 +out: efi_rts_work.status =3D status; complete(&efi_rts_work.efi_rts_comp); } @@ -444,8 +448,8 @@ virt_efi_set_variable_nb(efi_char16_t *name, efi_guid_t= *vendor, u32 attr, if (down_trylock(&efi_runtime_lock)) return EFI_NOT_READY; =20 - status =3D efi_call_virt_pointer(efi.runtime, set_variable, name, vendor, - attr, data_size, data); + status =3D efi_call_virt_pointer(efi.runtime, set_variable, EFI_NOT_READY, + name, vendor, attr, data_size, data); up(&efi_runtime_lock); return status; } @@ -481,9 +485,9 @@ virt_efi_query_variable_info_nb(u32 attr, u64 *storage_= space, if (down_trylock(&efi_runtime_lock)) return EFI_NOT_READY; =20 - status =3D efi_call_virt_pointer(efi.runtime, query_variable_info, attr, - storage_space, remaining_space, - max_variable_size); + status =3D efi_call_virt_pointer(efi.runtime, query_variable_info, + EFI_NOT_READY, attr, storage_space, + remaining_space, max_variable_size); up(&efi_runtime_lock); return status; } @@ -509,12 +513,14 @@ virt_efi_reset_system(int reset_type, efi_status_t st= atus, return; } =20 - arch_efi_call_virt_setup(); + if (!arch_efi_call_virt_setup()) + goto out; efi_rts_work.efi_rts_id =3D EFI_RESET_SYSTEM; arch_efi_call_virt(efi.runtime, reset_system, reset_type, status, data_size, data); arch_efi_call_virt_teardown(); =20 +out: up(&efi_runtime_lock); } =20 diff --git a/include/linux/efi.h b/include/linux/efi.h index a98cc39e7aaa..325d892e559b 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1181,19 +1181,19 @@ static inline void efi_check_for_embedded_firmwares= (void) { } * Restores the usual kernel environment once the call has returned. */ =20 -#define efi_call_virt_pointer(p, f, args...) \ +#define efi_call_virt_pointer(p, f, busy, args...) \ ({ \ - typeof((p)->f(args)) __s; \ + typeof((p)->f(args)) __s =3D (busy); \ unsigned long __flags; \ \ - arch_efi_call_virt_setup(); \ + if (!arch_efi_call_virt_setup()) goto __out; \ \ __flags =3D efi_call_virt_save_flags(); \ __s =3D arch_efi_call_virt(p, f, args); \ efi_call_virt_check_flags(__flags, NULL); \ \ arch_efi_call_virt_teardown(); \ - \ +__out: \ __s; \ }) =20 --=20 2.51.0.384.g4c02a37b29-goog From nobody Thu Oct 2 09:22:11 2025 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 77C78302175 for ; Thu, 18 Sep 2025 10:30:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758191442; cv=none; b=qeoQaEbrBMrzot54YHojrktI7igOuq4w+na7I2EF0RA865vTMOgS/CQQHHxKUmDnmi18k3iHRGaZuVTqwrMSlMJU4TpEdO01A+PZD3URYmB/jRoUN+8KXJyuLuBW88JGqOpZEhYP72714dcZVlM6yjGnQjPqc4x2jReriKo9qXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758191442; c=relaxed/simple; bh=zGTDavJNAxx18PM4b7p0B2MVa9hlUct/kDb6lm3LiYk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=gSer3f9ync0FdtB2M+5pho5vwAT2SDl1MruB3r3k3anCycfsYKjHLsTE1NMmhVAiYUVItvrR+izSeiKwxB30McENJIBCHjVVSI5ge8Y9qKRFN6q+8Kz+0LMfs4Sj7TO0F5Xu400QkiqmEzYZJsUISCvLOaR8gtNtXt8tRkZ3Bdw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=zJwpeDh+; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="zJwpeDh+" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-45f2f15003aso4952475e9.0 for ; Thu, 18 Sep 2025 03:30:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1758191439; x=1758796239; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NR5f/DGegjp210rMbwdyPD4vKBD/9uV5LYcxqzD4mrs=; b=zJwpeDh+vd2H0HViwA6EU7s516fu+i1A8Bx1gWMET9UYMGYG+KKhOjYlHSS0Y7CD4p hp/Q6Lc6hF2d31Sxy01G+7QGJZCovy4gTjSKmwVigMUBcDMwyL+mKPzDnZnMBWYCVWGs hlN8jgbFq4wtiwa4Tbvo01F8KGAu2evkCjklfUmJRn0mBpqsEawpFSLycbeF7hXvJGnr BgFfofOggOOZ5EvCsPUFrlHAaxJGvK11uzfsqs0kQxmDoNs/ZMxaO+o48+n5+fK13JEg 2Bm1iTk+m+sD6z508IQc/fvzcLHDX6FsWBDQPhpixKadrLZt2MIa8OvGhYGvuTimiwlI pPBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758191439; x=1758796239; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NR5f/DGegjp210rMbwdyPD4vKBD/9uV5LYcxqzD4mrs=; b=K4yDTLfHsPEQ3gDge9o5y1rKAElvKVDiKZa/ofmYQnUiV1UgNsTXgBp+OMm/RFhBeB bXZU9lQNYONV73dBUiS0JnH3zGXPmELP0VwAMxGAec4pOWpPb2h4+6DqRa0Ml5muWozf TBqimDy2WkG2BowYoE5HyYbySATCUHEFGp53iV6VJTKXt06cjolZTRAncywKwveUd2M1 nmtFSDs1GjXooOhCm37Xo8ASPTR6NFTVbWpOev4mib99RQSC4i6E3nx3o4Zq7ezW5Rt3 IweeAr3Ms5xzSS5d2JKD/LKghlHye8805Jb3eh1WPKotLMPPyL7T3BFY3U5lueKQOdzb +Anw== X-Gm-Message-State: AOJu0YyofZR/aTSoY9A9eP9Jjjybcn/V14lmkwGxbX7WYVcTKg+9mcNd uWrkdKsJpx31cPyO4nOtPOcIERBfdPCSlwYPbq6AlBrtKRm2jvzkdmtUC0ZVdueyL6GtSKTRbQ= = X-Google-Smtp-Source: AGHT+IGJRDEcVjOSC0x4VhiypKhaeygXXwL8oEycCf0lebIDZdWUzxAElbwqtEPvM8D7TYbl26IgU59P X-Received: from wmbjg15.prod.google.com ([2002:a05:600c:a00f:b0:459:dac7:4ea6]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1e8c:b0:456:29da:bb25 with SMTP id 5b1f17b1804b1-46205adf58emr50900465e9.19.1758191438954; Thu, 18 Sep 2025 03:30:38 -0700 (PDT) Date: Thu, 18 Sep 2025 12:30:15 +0200 In-Reply-To: <20250918103010.2973462-10-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250918103010.2973462-10-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2763; i=ardb@kernel.org; h=from:subject; bh=poM+J5QCFnAX0KM+dokbbxbcB3uDup+BM3HzFyYLTNo=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIeP0fctrGjeLUg8v1i7zzZd+7yCZv9R4om+bjWA9q/VtS U81k6kdpSwMYlwMsmKKLAKz/77beXqiVK3zLFmYOaxMIEMYuDgFYCIGOxgZvkYvit31ctcXe14r 63MzuU/LONUXFV0L36zL3Lud60jtXYb/vtuX/9geGc6oe+3d/UeKUz5pz7ZcX2Rr8l/0zJoVV1d /4AEA X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog Message-ID: <20250918103010.2973462-14-ardb+git@google.com> Subject: [PATCH v3 4/8] arm64/fpsimd: Permit kernel mode NEON with IRQs off From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Will Deacon , Mark Rutland , Sebastian Andrzej Siewior , Peter Zijlstra , Catalin Marinas , Mark Brown Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Currently, may_use_simd() will return false when called from a context where IRQs are disabled. One notable case where this happens is when calling the ResetSystem() EFI runtime service from the reboot/poweroff code path. For this case alone, there is a substantial amount of FP/SIMD support code to handle the corner case where a EFI runtime service is invoked with IRQs disabled. The only reason kernel mode SIMD is not allowed when IRQs are disabled is that re-enabling softirqs in this case produces a noisy diagnostic when lockdep is enabled. The warning is valid, in the sense that delivering pending softirqs over the back of the call to local_bh_enable() is problematic when IRQs are disabled. While the API lacks a facility to simply mask and unmask softirqs without triggering their delivery, disabling softirqs is not needed to begin with when IRQs are disabled, given that softirqs are only every taken asynchronously over the back of a hard IRQ. So dis/enable softirq processing conditionally, based on whether IRQs are enabled, and relax the check in may_use_simd(). Signed-off-by: Ard Biesheuvel Acked-by: Will Deacon --- arch/arm64/include/asm/simd.h | 2 +- arch/arm64/kernel/fpsimd.c | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/simd.h b/arch/arm64/include/asm/simd.h index 8e86c9e70e48..abd642c92f86 100644 --- a/arch/arm64/include/asm/simd.h +++ b/arch/arm64/include/asm/simd.h @@ -29,7 +29,7 @@ static __must_check inline bool may_use_simd(void) */ return !WARN_ON(!system_capabilities_finalized()) && system_supports_fpsimd() && - !in_hardirq() && !irqs_disabled() && !in_nmi(); + !in_hardirq() && !in_nmi(); } =20 #else /* ! CONFIG_KERNEL_MODE_NEON */ diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index c37f02d7194e..96a226316d1f 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -225,10 +225,12 @@ static void fpsimd_bind_task_to_cpu(void); */ static void get_cpu_fpsimd_context(void) { - if (!IS_ENABLED(CONFIG_PREEMPT_RT)) - local_bh_disable(); - else + if (!IS_ENABLED(CONFIG_PREEMPT_RT)) { + if (!irqs_disabled()) + local_bh_disable(); + } else { preempt_disable(); + } } =20 /* @@ -240,10 +242,12 @@ static void get_cpu_fpsimd_context(void) */ static void put_cpu_fpsimd_context(void) { - if (!IS_ENABLED(CONFIG_PREEMPT_RT)) - local_bh_enable(); - else + if (!IS_ENABLED(CONFIG_PREEMPT_RT)) { + if (!irqs_disabled()) + local_bh_enable(); + } else { preempt_enable(); + } } =20 unsigned int task_get_vl(const struct task_struct *task, enum vec_type typ= e) --=20 2.51.0.384.g4c02a37b29-goog From nobody Thu Oct 2 09:22:11 2025 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) (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 D1767302CD6 for ; Thu, 18 Sep 2025 10:30:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758191443; cv=none; b=jux6MG69oDk17TBVAXdmrX4KqyeR6rLDWtxBGGBC/2Nzw6TzZUisfVAEWM1Np0x5e9oO9P+CdXB5HhytLNPxa/u0vtZijartqJDFkENT24nNAmFnvdJhuT5OzRDYQmc5uN5OcI0CX0nWSN4bV6cOm1GtyyVmnLtmZHDWGe63Dn4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758191443; c=relaxed/simple; bh=ZGdtaP9UOrhJQRg7Jb5jXlPg0xetCedeLXyyV6Xl2fI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tulm9CxAJrk85hINvpFk7JNgwykqVeOsYqR7+OEhbxjgLk2UZL2YPOyPuiT2V4ywwdpDTpyFqDf57RkFhOtnociBk8JarXCOEt5XqEQReLqoRFzxvEs+qBXiYjDs1VS0W4Pag2NEcVAbUyDFscJpqX+jxEJXNGVQ8L96RWd4Fec= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=rjjH8yOx; arc=none smtp.client-ip=209.85.208.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rjjH8yOx" Received: by mail-ed1-f73.google.com with SMTP id 4fb4d7f45d1cf-62f935e6221so673525a12.2 for ; Thu, 18 Sep 2025 03:30:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1758191440; x=1758796240; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6H562hA4phalkuc9iW32nFe+iytT6ATVUAyAxRehk0A=; b=rjjH8yOxVU/IKdx87dcq4W0F5+mfwZu2WfCOzPfDo9vw++qjSclxbfHkG16gz0O5On muCkhxlUvLS+CCu5FLag4sL14M/1qWWdQpDXdl3laeSsL8BUDTinAPHPenwpaiZIueHb IXBxhKDBeiZo2FKKrd6ySI7bZXDQj9cOrldruadqjKuuVAbdNrv9smXV8og6Tq+XoBqC uth9OzzCjJTWa+XU75S52GGCucfJGuItwVicuo8UG3WNaD1r3TiiZsZEHLOOKWrz6AqE xilpat96uSBcc7ecKE4BGZdtBjSYaAWpQj/w8rmpMBP2iEFDgGnUFjUNrUuhACrc84Iv 8UOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758191440; x=1758796240; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6H562hA4phalkuc9iW32nFe+iytT6ATVUAyAxRehk0A=; b=eJCj4nckgvn2r7KtzXOoPA02KWs/JnomTdY452bVimYZPPXA6dGnKfRP9d+Jk7Eypv E7Hb6QXbOr9M2OzG4Ed9XqmL/GM5bTF4bGqF7nVeqWOH4WkZhLh530IpeqZrMkdXpWwr bqt3O3GuEYbbVJrWt5yDcGu0S5hSc2RHCM+nvRlGjK35gKbAelWGhmIA3uhL+DHeqQnE 1k4MGcJFYDW1z038uILHN+5AgKvE9vWuavN+F865cjLUQowSLSOrDt/0JkZbL4p/1bLl wNrywHw1UMQVubLmvwr5B5PjVwv6pz+NNs3pgsmcPSrFMJskPBhNresnK5AQMB6OvMLV LYMA== X-Gm-Message-State: AOJu0YxRPbumjOiB4YMMEmiWFsSVyhczi8Uj4MtXne5two88ncElA/sq 0AbhdRjovfv9xnVz4iEHsWvXaDtszTnwexpmRh7KOSM/fAucgt48CexwSrqeNXvaQtfXuR0YFA= = X-Google-Smtp-Source: AGHT+IFkRHFzfELswznyWLkr4CvOF50Fe853eqdKU+2tOajHyQGbMjOvGvY8FOB3foL9HdzwA1/E0NRu X-Received: from ede13.prod.google.com ([2002:a05:6402:20cd:b0:62f:48cb:a0]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:35d2:b0:62f:48e3:2224 with SMTP id 4fb4d7f45d1cf-62f8444146amr4820234a12.20.1758191440174; Thu, 18 Sep 2025 03:30:40 -0700 (PDT) Date: Thu, 18 Sep 2025 12:30:16 +0200 In-Reply-To: <20250918103010.2973462-10-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250918103010.2973462-10-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=5359; i=ardb@kernel.org; h=from:subject; bh=mQrrF+d2zLkSHcwIimPMiS9vJSwzrw0LbijljjwZNyA=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIeP0feskWV6NoLork+f7ttzccMu/xfTijM+qp5L37fx7L rrsZPPWjlIWBjEuBlkxRRaB2X/f7Tw9UarWeZYszBxWJpAhDFycAjAR6S5Ghjf1zQcPLCm9mPG4 XmWlicr89ZPmXw4q2rlK0pD7h3rpndeMDDu3TlBgWrWp4PP1q2p6bawHWIpTpvF1rme6ynCree+ a1TwA X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog Message-ID: <20250918103010.2973462-15-ardb+git@google.com> Subject: [PATCH v3 5/8] arm64/fpsimd: Drop special handling for EFI runtime services From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Will Deacon , Mark Rutland , Sebastian Andrzej Siewior , Peter Zijlstra , Catalin Marinas , Mark Brown Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Now that the use of kernel mode FP/SIMD is generally permitted when IRQs are disabled, the only purpose served by the EFI-specific fallback code in fpsimd.c is the case where an EFI call occurs from hardirq or NMI context. No such cases are known to occur in practice, and it is doubtful whether calling into the EFI firmware for any reason under such conditions would be a good idea to begin with. So disallow EFI runtime services in such cases. This means all the fallback code can be dropped. Signed-off-by: Ard Biesheuvel Reviewed-by: Mark Brown --- arch/arm64/include/asm/fpsimd.h | 4 - arch/arm64/kernel/efi.c | 8 +- arch/arm64/kernel/fpsimd.c | 121 -------------------- 3 files changed, 6 insertions(+), 127 deletions(-) diff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsim= d.h index b8cf0ea43cc0..139ee1393730 100644 --- a/arch/arm64/include/asm/fpsimd.h +++ b/arch/arm64/include/asm/fpsimd.h @@ -458,10 +458,6 @@ static inline size_t sme_state_size(struct task_struct= const *task) =20 #endif /* ! CONFIG_ARM64_SME */ =20 -/* For use by EFI runtime services calls only */ -extern void __efi_fpsimd_begin(void); -extern void __efi_fpsimd_end(void); - #endif =20 #endif diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c index 9b03f3d77a25..0d52414415f3 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -14,6 +14,7 @@ #include =20 #include +#include #include #include =20 @@ -169,15 +170,18 @@ static DEFINE_RAW_SPINLOCK(efi_rt_lock); =20 bool arch_efi_call_virt_setup(void) { + if (!may_use_simd()) + return false; + efi_virtmap_load(); raw_spin_lock(&efi_rt_lock); - __efi_fpsimd_begin(); + kernel_neon_begin(); return true; } =20 void arch_efi_call_virt_teardown(void) { - __efi_fpsimd_end(); + kernel_neon_end(); raw_spin_unlock(&efi_rt_lock); efi_virtmap_unload(); } diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index 96a226316d1f..e543dd569bd7 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -1907,127 +1907,6 @@ void kernel_neon_end(void) clear_thread_flag(TIF_KERNEL_FPSTATE); } EXPORT_SYMBOL_GPL(kernel_neon_end); - -#ifdef CONFIG_EFI - -static struct user_fpsimd_state efi_fpsimd_state; -static bool efi_fpsimd_state_used; -static bool efi_sve_state_used; -static bool efi_sm_state; - -/* - * EFI runtime services support functions - * - * The ABI for EFI runtime services allows EFI to use FPSIMD during the ca= ll. - * This means that for EFI (and only for EFI), we have to assume that FPSI= MD - * is always used rather than being an optional accelerator. - * - * These functions provide the necessary support for ensuring FPSIMD - * save/restore in the contexts from which EFI is used. - * - * Do not use them for any other purpose -- if tempted to do so, you are - * either doing something wrong or you need to propose some refactoring. - */ - -/* - * __efi_fpsimd_begin(): prepare FPSIMD for making an EFI runtime services= call - */ -void __efi_fpsimd_begin(void) -{ - if (!system_supports_fpsimd()) - return; - - WARN_ON(preemptible()); - - if (may_use_simd()) { - kernel_neon_begin(); - } else { - /* - * If !efi_sve_state, SVE can't be in use yet and doesn't need - * preserving: - */ - if (system_supports_sve() && efi_sve_state !=3D NULL) { - bool ffr =3D true; - u64 svcr; - - efi_sve_state_used =3D true; - - if (system_supports_sme()) { - svcr =3D read_sysreg_s(SYS_SVCR); - - efi_sm_state =3D svcr & SVCR_SM_MASK; - - /* - * Unless we have FA64 FFR does not - * exist in streaming mode. - */ - if (!system_supports_fa64()) - ffr =3D !(svcr & SVCR_SM_MASK); - } - - sve_save_state(efi_sve_state + sve_ffr_offset(sve_max_vl()), - &efi_fpsimd_state.fpsr, ffr); - - if (system_supports_sme()) - sysreg_clear_set_s(SYS_SVCR, - SVCR_SM_MASK, 0); - - } else { - fpsimd_save_state(&efi_fpsimd_state); - } - - efi_fpsimd_state_used =3D true; - } -} - -/* - * __efi_fpsimd_end(): clean up FPSIMD after an EFI runtime services call - */ -void __efi_fpsimd_end(void) -{ - if (!system_supports_fpsimd()) - return; - - if (!efi_fpsimd_state_used) { - kernel_neon_end(); - } else { - if (system_supports_sve() && efi_sve_state_used) { - bool ffr =3D true; - - /* - * Restore streaming mode; EFI calls are - * normal function calls so should not return in - * streaming mode. - */ - if (system_supports_sme()) { - if (efi_sm_state) { - sysreg_clear_set_s(SYS_SVCR, - 0, - SVCR_SM_MASK); - - /* - * Unless we have FA64 FFR does not - * exist in streaming mode. - */ - if (!system_supports_fa64()) - ffr =3D false; - } - } - - sve_load_state(efi_sve_state + sve_ffr_offset(sve_max_vl()), - &efi_fpsimd_state.fpsr, ffr); - - efi_sve_state_used =3D false; - } else { - fpsimd_load_state(&efi_fpsimd_state); - } - - efi_fpsimd_state_used =3D false; - } -} - -#endif /* CONFIG_EFI */ - #endif /* CONFIG_KERNEL_MODE_NEON */ =20 #ifdef CONFIG_CPU_PM --=20 2.51.0.384.g4c02a37b29-goog From nobody Thu Oct 2 09:22:11 2025 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) (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 EA354303A27 for ; Thu, 18 Sep 2025 10:30:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758191444; cv=none; b=Fd1PfOkMyIrw5dGDy19eZ/oDuOEct/wW6WjIxbo1CnI+fmOGWdGpawZh8TcbW7rKsHqW1uXvcqkF2u2t7ketBpRSTDzTxiyQ135j9ZvKyGsK+/CG1Sl6a5DEMllYxuTocIxW6FpPqZBOXahJZReRjUvw0DVSTD+GKNwhK/MRJVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758191444; c=relaxed/simple; bh=o/hZvudtfRK4rr9zuVg3PqxrxE8wP3rPGUNeDSxyO5E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Gf5YbwsXN2ApLMM5RCpEF8IsglAqzpL9YGHKug5punqbAjWrhnWbzqmF2LEN7K2ZGwxcEj0UoGwCGoF5BavZUmrVdYFo17sAcaIujs4PQV8NjFPbox8GvTY/yBqfk3JpuIFva8tQTuKZNGcmrmPdQhzkim7cuMNzYUDyOd3Pdcw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=VcndOKmT; arc=none smtp.client-ip=209.85.218.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="VcndOKmT" Received: by mail-ej1-f73.google.com with SMTP id a640c23a62f3a-b04827ca035so67301066b.0 for ; Thu, 18 Sep 2025 03:30:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1758191441; x=1758796241; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=MNHqAVLlhLv5W0htkEcz0OII/0HvpQvRWJKki7ay4x4=; b=VcndOKmTVE2w4LxGmEVmEvb9ZcpHUiWi2vNoUenb5xuE1D7Cxgrjpo9hNr1NaJdOkD AtVsKa/2OGZwD+7SUXQC4rNw4hcjWO7oXQBtUIdNHhtDK0mLllLFVrTt+rJWAeVaINqw 8TQWJL6LqSkobDwX/84eFyCVGYpYxpNaxJ4wGO22ASUbM5SBqSyFj9hw0KMtAmC4ZX5D NeRbmLoCJpFkCFxb1d3xbeLcs9Ffiiu0i9P55Ww7SY9NyHI80zAaQftxzNnZoiInbamX 8IcuTwEv0NtJS/Wb3wE/D/GmmdvH03ak7VOQliY6mYSF9p5LBLV5vjsIxB6fISOIFlP1 e3zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758191441; x=1758796241; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MNHqAVLlhLv5W0htkEcz0OII/0HvpQvRWJKki7ay4x4=; b=EEbQQvuR1EFoP+ZsfV+tM8+xwbxIXY9bYpekC6QqLV/RwL/Lxe/24xKMqUSATBnXJy VOQefQaQD+dDqYywevQWehHqnO889bgbDkXPfObmwRdubbv8LwbWe8ExAKRdUETQEnM1 6Z/vIUffwQi81ySnf8QKQRgmy0CFsR4V+xIqIYYxRyFpsE/lBNwNvuMp6SDN2Wk+GjCA 2vovfW+28ojvPUodOg+fZm2t9CFVm0Zr3QP18dtv3oVkYfkR9ASfMLGtOcvvSv1lcGS1 a0fvEmDt0zJ9424UaBzRBItpJuAeOUF9c0aIst3BUfsXbOErD2Ffby4Nfv1h/fUOw/J8 008A== X-Gm-Message-State: AOJu0Yxm6cA43DOtVybj7DpgPyLLGOzG88vQKYEYuCXilHuuztp688fY buoDrVVYxFEceNZDabHY//86L0aPCuNlLcVxw6o6vUM7/V27Ufl5aS8ak7r4ZQTv1qk05oZzgg= = X-Google-Smtp-Source: AGHT+IFgHxWIDqP1JG9dsjSf5woDKGTvu3LMMfMFqln2zd5f55mk3oKmQw/5olbKzpy9I1HA/uIxbJPg X-Received: from edbio10.prod.google.com ([2002:a05:6402:218a:b0:62f:4a87:a86b]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a17:906:4788:b0:b0f:a22a:4c60 with SMTP id a640c23a62f3a-b1bb17c8ca5mr633978966b.11.1758191441397; Thu, 18 Sep 2025 03:30:41 -0700 (PDT) Date: Thu, 18 Sep 2025 12:30:17 +0200 In-Reply-To: <20250918103010.2973462-10-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250918103010.2973462-10-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1447; i=ardb@kernel.org; h=from:subject; bh=CzllZySlu7Zzk+9rgGtZjOjjeEN/aeVWkoZifxpGWQo=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIeP0fZur/x7YPo49KfFPamHLRgWB3fKCD7LceAUfLt13j mFqzDSujhIWBjEuBlkxRRaB2X/f7Tw9UarWeZYszBxWJpAhDFycAjARp3cMX8U+BHJpr9zO6v9t xoPLDTu/XVfqvcBlKTTHQzN893PmFob/pTUOLdXPImb8152s75qsuTMpV8O3NPLvZo3OTz2Tkw6 xAgA= X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog Message-ID: <20250918103010.2973462-16-ardb+git@google.com> Subject: [PATCH v3 6/8] arm64/efi: Use a mutex to protect the EFI stack and FP/SIMD state From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Will Deacon , Mark Rutland , Sebastian Andrzej Siewior , Peter Zijlstra , Catalin Marinas , Mark Brown Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Replace the spinlock in the arm64 glue code with a mutex, so that the CPU can preempted while running the EFI runtime service. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/efi.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c index 0d52414415f3..4372fafde8e9 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -166,15 +166,22 @@ asmlinkage efi_status_t efi_handle_corrupted_x18(efi_= status_t s, const char *f) return s; } =20 -static DEFINE_RAW_SPINLOCK(efi_rt_lock); +static DEFINE_MUTEX(efi_rt_lock); =20 bool arch_efi_call_virt_setup(void) { if (!may_use_simd()) return false; =20 + /* + * This might be called from a non-sleepable context so try to take the + * lock but don't block on it. This should never fail in practice, as + * all EFI runtime calls are serialized under the efi_runtime_lock. + */ + if (WARN_ON(!mutex_trylock(&efi_rt_lock))) + return false; + efi_virtmap_load(); - raw_spin_lock(&efi_rt_lock); kernel_neon_begin(); return true; } @@ -182,8 +189,8 @@ bool arch_efi_call_virt_setup(void) void arch_efi_call_virt_teardown(void) { kernel_neon_end(); - raw_spin_unlock(&efi_rt_lock); efi_virtmap_unload(); + mutex_unlock(&efi_rt_lock); } =20 asmlinkage u64 *efi_rt_stack_top __ro_after_init; --=20 2.51.0.384.g4c02a37b29-goog From nobody Thu Oct 2 09:22:11 2025 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (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 E45D02BEFEA for ; Thu, 18 Sep 2025 10:30:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758191445; cv=none; b=ckxhC+kr9ZFJmGXMf8VaANB9YNwGTQg7KGR/hrAn48+G7xl+9XwrJXz77UppweJZi3G5BExM48vyQGNj4cOq81uu/lbtV2jCujE6a4HA3svC8G9yG36NVN3cOo5g7WN4L1xpY9qhJCPAiIApfOd68Rce8T/YlPM5cwV5QCRUqEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758191445; c=relaxed/simple; bh=Wiezk90EeDViSxUviUNtzZTTt45XUjxOpMdjJkjt7Z4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=DFv2dKJNCDYU8QAFOJSMSuAPFE+lu+BPDA8kz62r80ZGla6GFBcR/HXVkBPvyAYsWtqVIQuQLuZ3V0JGKjuzF43uyUQc/YjyZIVBdqn100JTI3t4OkDInergqGO6Grts0tzSqB8rbizhM4EgARASupq+QeHFo57M3H1prHYFGUE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=XJ8Q/tMi; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XJ8Q/tMi" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-45b98de0e34so7888265e9.0 for ; Thu, 18 Sep 2025 03:30:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1758191442; x=1758796242; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=DksqsAvPlifD5AcgvqzgUC2XrqtgGq1Wq0QfB7rSyJ4=; b=XJ8Q/tMiEhlkN/DJEBgAZ2myIg+tTe7qKrfvcYeNXDyxdlTfygneoyw85ck6lAq9uR ydy6ojoGz65v6uGdQVu+/dQSAYUMNeHcu0tpQMAeXX8r3zW/FZ6G0Q4tv8gPWwRH4xKY +QFbEKHOJG3igKrxfZ4jer/Px/NxCs3U8yMbS0pwWf05FeLSbk7RVsrx0HXm+tM71YXx vU5Um3n2jPqQA2/xMR8YYiMJCD51Pm2uidepPqSO7WFGRHsjYmIpuQcMaQGS7qPxcDYf ibhGQDyil3cDFNswcYlDpkoJ5xAXkD/WzgUj6bmQd1aTbC0k7jp4rk50mOJQfyVVecRZ 322Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758191442; x=1758796242; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DksqsAvPlifD5AcgvqzgUC2XrqtgGq1Wq0QfB7rSyJ4=; b=DX9duF+bTdWyms8sI4IHAyevqsyLT+pyhxowNjWuKq98heyGodGCvvd61HUhM3Liqi hazRtxH1ANCsJQhAmkDLeTirZqZC7tEc3riLZ0mysHJ6BlVHy+4iCiKFIj0HOGcmelOn zGwbsM+187V0HzuA2fpv1r5egD14lWjXqxTJHL2fId+5lERMUtS1+sSaxt/n1gTb0B3B /KVtfZGtcVkAHCuseoQ3/IrIy4U3+Y966RTRdLW+qNLbfOqmBopxQ5VTs6FvExvrdPrg UNJV0B4iZNd7+JEApHCxnrOfZuqYUL9B5yrZQzVKtBVcYusCyWmIowc0o1iJUJ/TB8Jt gfcQ== X-Gm-Message-State: AOJu0Yy1XOtbpwGFQ1IsIoKtZWhp7ZsMcpIZy+2lxDd+NVWLj8QLNP2g GR7BSgjRlEK8zfTAl/Dz8o+YGr40s90eHErzMDIp0uQ4/TVEMO1JjMS4yhk2CsP6YZsI40lzWQ= = X-Google-Smtp-Source: AGHT+IFUmBh+5gegFiYMOlzv62Mjx0w8SlOm74pqvtSIgATSsKH7e5irJfmo4m3CeekRPpIfN+2PS0jf X-Received: from wrbdn3.prod.google.com ([2002:a05:6000:c03:b0:3e7:6748:fa54]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:5d86:0:b0:3ec:ce37:3a6d with SMTP id ffacd0b85a97d-3ecdfa2ae03mr4664506f8f.47.1758191442249; Thu, 18 Sep 2025 03:30:42 -0700 (PDT) Date: Thu, 18 Sep 2025 12:30:18 +0200 In-Reply-To: <20250918103010.2973462-10-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250918103010.2973462-10-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2694; i=ardb@kernel.org; h=from:subject; bh=xrwXhuc4FPqL3CCntBsstjQDywcZZ1Gih2rwsqKYefE=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIeP0fTvNvTP51tUVfbQO9um+s2tq1D8Lxal183K23BS8W OS76NDVjlIWBjEuBlkxRRaB2X/f7Tw9UarWeZYszBxWJpAhDFycAjCR5XwM/4yCL/hXm09o4V71 pFPRwNjmMcvy2bvZFx2+zTFhrsFOwwuMDNdiUvbEfrd6uzYhzjug5+//uNlJCrzPww5vSfdiK1X VZgQA X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog Message-ID: <20250918103010.2973462-17-ardb+git@google.com> Subject: [PATCH v3 7/8] arm64/efi: Move uaccess en/disable out of efi_set_pgd() From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Will Deacon , Mark Rutland , Sebastian Andrzej Siewior , Peter Zijlstra , Catalin Marinas , Mark Brown Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel efi_set_pgd() will no longer be called when invoking EFI runtime services via the efi_rts_wq work queue, but the uaccess en/disable are still needed when using PAN emulation using TTBR0 switching. So move these into the callers. Signed-off-by: Ard Biesheuvel Acked-by: Will Deacon --- arch/arm64/include/asm/efi.h | 13 +++---------- arch/arm64/kernel/efi.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h index decf87777f57..09650b2e15af 100644 --- a/arch/arm64/include/asm/efi.h +++ b/arch/arm64/include/asm/efi.h @@ -126,21 +126,14 @@ static inline void efi_set_pgd(struct mm_struct *mm) if (mm !=3D current->active_mm) { /* * Update the current thread's saved ttbr0 since it is - * restored as part of a return from exception. Enable - * access to the valid TTBR0_EL1 and invoke the errata - * workaround directly since there is no return from - * exception when invoking the EFI run-time services. + * restored as part of a return from exception. */ update_saved_ttbr0(current, mm); - uaccess_ttbr0_enable(); - post_ttbr_update_workaround(); } else { /* - * Defer the switch to the current thread's TTBR0_EL1 - * until uaccess_enable(). Restore the current - * thread's saved ttbr0 corresponding to its active_mm + * Restore the current thread's saved ttbr0 + * corresponding to its active_mm */ - uaccess_ttbr0_disable(); update_saved_ttbr0(current, current->active_mm); } } diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c index 4372fafde8e9..a60444dcec68 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -182,6 +182,15 @@ bool arch_efi_call_virt_setup(void) return false; =20 efi_virtmap_load(); + + /* + * Enable access to the valid TTBR0_EL1 and invoke the errata + * workaround directly since there is no return from exception when + * invoking the EFI run-time services. + */ + uaccess_ttbr0_enable(); + post_ttbr_update_workaround(); + kernel_neon_begin(); return true; } @@ -189,6 +198,15 @@ bool arch_efi_call_virt_setup(void) void arch_efi_call_virt_teardown(void) { kernel_neon_end(); + + /* + * Defer the switch to the current thread's TTBR0_EL1 until + * uaccess_enable(). Do so before efi_virtmap_unload() updates the + * saved TTBR0 value, so the userland page tables are not activated + * inadvertently over the back of an exception. + */ + uaccess_ttbr0_disable(); + efi_virtmap_unload(); mutex_unlock(&efi_rt_lock); } --=20 2.51.0.384.g4c02a37b29-goog From nobody Thu Oct 2 09:22:11 2025 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) (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 432BE304BCC for ; Thu, 18 Sep 2025 10:30:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758191448; cv=none; b=jLFLmqx/FhJK/c7dZXhbEP/5MEYh7m6ef/RXSP7R3+EEQtb/qeRd1FPw3/Ie6PNabwac13AEYE4kf053oC1pieiGUm2E8BytZK1A8GR/Tx8uVPKwUmF7k2N6eSFMTg2nV6BcFvbnCeDLUgoJaGJWL2XTEbIxaXK6knD54rdhfNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758191448; c=relaxed/simple; bh=nj7i29BJluBpWURQYZUxvNADD0EB9W2SAuUGs1F5qNo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=cfPkLVLPj7+2kQ2Ir5+zGn2j2zmubxSNqykczUcjIs+4iWbYwg2/9zJthq7Q/4q3cggNz2osw7AODRzW9ZVEMbcEGjmZfiKI7R/Y1KD1B7NztGOIxAoif+AP5aM3923mgamT+NLx/o79IQvzIEi2Ph8+7V8FnxmplH8DnBGQ4ZA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=z2v5hAYp; arc=none smtp.client-ip=209.85.208.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="z2v5hAYp" Received: by mail-ed1-f73.google.com with SMTP id 4fb4d7f45d1cf-62f9cfb8075so760288a12.2 for ; Thu, 18 Sep 2025 03:30:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1758191443; x=1758796243; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1LXz7drZR69NRcqoi9vT6ordOH/o85U4ZownXle33jo=; b=z2v5hAYpnReyIWnakau8oe5tl49Qq1x1VQj4Saa27PvWAA8cW8lsMXNZAUNepZuBsu n1QBXB209G1k6wmHEq1OOLfcmd5xXe6iF17CY6kbp6GbrKHJmCjTDIYdZhli562KCrF5 CIvW2LeiuGUXC4EL89PtQoBIXTtJl0qNOzMlpdh53gVGVs5egn40ghbipQ1yYrusaN2d ZKfV31GniYO3vKveS06Cw/aef/sQFc8unE1BCNzfZ23Zvoxszzk1B/AJTfcYFjl/CwCG v8A4747j21EHN2a9DmC8Ze8D0gHpChq8ue+J1xSSxrm22c5CGLYIKaMqrakuA3/BHWcu KMSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758191443; x=1758796243; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1LXz7drZR69NRcqoi9vT6ordOH/o85U4ZownXle33jo=; b=rkTIDe1NRVTsFNFN73KTq625dKBusQGYH8Z5wbAh9HCgAyn6VOS8J9LYdkUYUVsa2K eh/Nc8FZsQlf/jyXjxmwOSLzOOIWknJ34mYlcyOiOTfzPx5Vt346RqgBETAaRWx3dnaT Pcuh5RDDLxu5rossgichyQmrZ+O3bz8xc1D3wVQ1cHBd76GyE3oHGf9PhmjxC23KYDyf u6v2ZKz/h0Xr5HOVnyixQ3Pt9deRNHZ/jeDGWpChIetBuG4LywTAQGFaN8AHThC45laC 6A2f5ktQfwCdArNxL+SaH2fjhj3IGcdlpMTwVzwPQsS4PYGMpZh9euJK5Yx3xCpGKrE6 ukWQ== X-Gm-Message-State: AOJu0YzJ0IBZgB6lcp3S0LNpKwhv/0C41QMIhId8FbwyY0E7pNIgNlcu FtltYSFzD6I78plBf6GBGPUFgKCq/A7H6OEhiygtVh4ohvL+vUYFA+Q6HgWs1B1lS5STMjzSYA= = X-Google-Smtp-Source: AGHT+IGUquYXpi2xrIo18MZawlB6gxNVwBfa77lbrIIZHKX8Fpb5Qx9xXEK4QYttljX7a5cizhaLtJAe X-Received: from edbev11.prod.google.com ([2002:a05:6402:540b:b0:62f:f6a:43ba]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:5210:b0:62f:3721:fc8c with SMTP id 4fb4d7f45d1cf-62f846a13f7mr4583585a12.37.1758191443543; Thu, 18 Sep 2025 03:30:43 -0700 (PDT) Date: Thu, 18 Sep 2025 12:30:19 +0200 In-Reply-To: <20250918103010.2973462-10-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250918103010.2973462-10-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=3226; i=ardb@kernel.org; h=from:subject; bh=AwRe+ieGv51rAlmd3os99ZtjQYVM4Fjtomg80IO3BGI=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIeP0ffu7Hx2rC6Yu2+C13jZCdw5DvK+nWau/35sVhftaX tp8npDfUcrCIMbFICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACbyIp6RYcV5l8DV7Qfd7C7x d5Wun8r8crV6ic8C9h1zMjXOSHO8v8rwP3F1/+/nc0s3B19zT/4R/KFS8CZb2eepvuv4xAMuFnN LcgMA X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog Message-ID: <20250918103010.2973462-18-ardb+git@google.com> Subject: [PATCH v3 8/8] arm64/efi: Call EFI runtime services without disabling preemption From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Will Deacon , Mark Rutland , Sebastian Andrzej Siewior , Peter Zijlstra , Catalin Marinas , Mark Brown Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel The only remaining reason why EFI runtime services are invoked with preemption disabled is the fact that the mm is swapped out behind the back of the context switching code. The kernel no longer disables preemption in kernel_neon_begin(). Furthermore, the EFI spec is being clarified to explicitly state that only baseline FP/SIMD is permitted in EFI runtime service implementations, and so the existing kernel mode NEON context switching code is sufficient to preserve and restore the execution context of an in-progress EFI runtime service call. Most EFI calls are made from the efi_rts_wq, which is serviced by a kthread. As kthreads never return to user space, they usually don't have an mm, and so we can use the existing infrastructure to swap in the efi_mm while the EFI call is in progress. This is visible to the scheduler, which will therefore reactivate the selected mm when switching out the kthread and back in again. Given that the EFI spec explicitly permits runtime services to be called with interrupts enabled, firmware code is already required to tolerate interruptions. So rather than disable preemption, disable only migration so that EFI runtime services are less likely to cause scheduling delays. To avoid potential issues where runtime services are interrupted while polling the secure firmware for async completions, keep migration disabled so that a runtime service invocation does not resume on a different CPU from the one it was started on. Note, though, that the firmware executes at the same privilege level as the kernel, and is therefore able to disable interrupts altogether. Signed-off-by: Ard Biesheuvel Acked-by: Will Deacon --- arch/arm64/kernel/efi.c | 23 ++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c index a60444dcec68..9b1603a69b69 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include =20 @@ -181,7 +182,19 @@ bool arch_efi_call_virt_setup(void) if (WARN_ON(!mutex_trylock(&efi_rt_lock))) return false; =20 - efi_virtmap_load(); + if (preemptible() && (current->flags & PF_KTHREAD)) { + /* + * Disable migration to ensure that a preempted EFI runtime + * service call will be resumed on the same CPU. This avoids + * potential issues with EFI runtime calls that are preempted + * while polling for an asynchronous completion of a secure + * firmware call, which may not permit the CPU to change. + */ + migrate_disable(); + kthread_use_mm(&efi_mm); + } else { + efi_virtmap_load(); + } =20 /* * Enable access to the valid TTBR0_EL1 and invoke the errata @@ -207,7 +220,13 @@ void arch_efi_call_virt_teardown(void) */ uaccess_ttbr0_disable(); =20 - efi_virtmap_unload(); + if (preemptible() && (current->flags & PF_KTHREAD)) { + kthread_unuse_mm(&efi_mm); + migrate_enable(); + } else { + efi_virtmap_unload(); + } + mutex_unlock(&efi_rt_lock); } =20 --=20 2.51.0.384.g4c02a37b29-goog