From nobody Sat Feb 7 17:23:19 2026 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 6BE25352076 for ; Fri, 5 Sep 2025 13:30:48 +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=1757079050; cv=none; b=QrTaCA2esjXEEAKvec+Em8MPggY/kH8/DOi/TGGpmkKu50ORp+qEKguDLPOlKqA4zsfGq5VVNJ+N3tQF9lner+WW8X4fWkncWAMAgYerkAPBQtbdRF7AEQWOZTRw2qYZsFOkgOh0ljkiZqs91mMHxsAakoeQba41MuVzxpqkZlU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757079050; c=relaxed/simple; bh=ECzWVd+AzMHGkO1axC4Nxd2WiHY2CoMBXtmHlgaGTvQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GffghDlw0juRggT6hrSrMJmXb510OljLlQKbopN8En/MXU0F6iEwfRujiO1ZD/jAA+Fmrk5lItxXTzKj/75uaLrbbH9Yj+BA6U0YdqIorJFhERZs80rm+o8A4UOwfNm2AdxtELYVe3VUpM7Xd+YjUGZ9zafwONSQ9X/siO8DgHI= 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=LtvAR4/W; 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="LtvAR4/W" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-45b990eb77cso14204745e9.0 for ; Fri, 05 Sep 2025 06:30:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1757079047; x=1757683847; 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=hFUi3FlPm9KOXLVkivG1TPAn4U/BsKfwoh1VfKcakJg=; b=LtvAR4/WArVQW1TnlYFCe/2oMHGblFXcqmpbcORaMDW8BmbYYVGxY1VA8sSIXH3zP8 XNLPcyg2xUzO5op/qC3u4P2F9aq1fD/OBY2HDUql2wzHzI7o74ywaelMUE0S9b5dvtkt aNdRXPafJf7Rm65g9sgv1WTg79dvsC6XvmCh/R/9+Gd+Y7XO+ouMZrsBGdUE+dKwmBaS yedP6cvdZziv8YiF6reueLrnB2pcDFS6eyk6xTMpHa4T7qhBehE/Rfo5bIiN75MiOytm lK0a6yziAtk8Q8Q4Pv86lFMcOkD5H7LYGT9oJIDTydbsRI2O07MYET5h1KSV17VWudqW v2lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757079047; x=1757683847; 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=hFUi3FlPm9KOXLVkivG1TPAn4U/BsKfwoh1VfKcakJg=; b=LUjWRHaN1e5+hBshkQfhOwu4BDU/VzmqhlahYlnInNo3dokKMWGwVmDxiPgC7B88dy GPwpbtjS482Z0QOP5WFmfho7r7Nk4DHUYg/8eusoV7kk+eCYMbgVX0gq3l+OSTEILUqh JpfXYRA5J9H3NalBVpy7Jz0MoRb5OJNsm4HIhfnkm0JKoDapU2QcEdXDaVCYyFXpypos aG2MXaJNfyAtlLGwH3Ui1q5nT6S5TMRtMMPttRm7CQ5J9jEGEG6OXRSmTUS+OsjULTnu jlLvl8DqIO2Jiuxn/MlGSZUcTzTCUf6tpY6FjuBQQ/wnclbZMD5QP9kEm7QkiMRGaKS+ VcEg== X-Gm-Message-State: AOJu0YzPsDA5RqgWIvaNjlCdOz0EjU4bmKip55TN5b1UfXa69WzbbidI ki1wEtv0R3flfAVItuefm2I0BH88QjKEG9pfgFs9b8udAMmRqTjIhgvs/1SeE439EKf3ELEdFA= = X-Google-Smtp-Source: AGHT+IGf+vRi3XmR/QGP16LgsrUNxoVVujkhlQmO0eAfjGcLlZWZe2h4Qdaq8UaJGcAf86n7aeIE74J6 X-Received: from wmbez15.prod.google.com ([2002:a05:600c:83cf:b0:45d:d3ef:abb8]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:35d4:b0:45d:d259:9a48 with SMTP id 5b1f17b1804b1-45dd5b456c0mr26381175e9.9.1757079046680; Fri, 05 Sep 2025 06:30:46 -0700 (PDT) Date: Fri, 5 Sep 2025 15:30:37 +0200 In-Reply-To: <20250905133035.275517-9-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: <20250905133035.275517-9-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=RXdT7wNu/pdGAxus7uiLMzLf2wBNTNItEYxQJXgozmU=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIWPX07+PF7pdfzyJ+/va/jMpCWVesYfLU/VO3srL2bJD/ 4fqsgueHaUsDGJcDLJiiiwCs/++23l6olSt8yxZmDmsTCBDGLg4BWAilj8YGT493y9u4lk5z1xi txTTy/Lzcl7Ji9u4P7zflnZWYklnqS/DP93qaRt32exPZ3yexOYXL//w9rNPK+5sdlVi/yC+SiB rAicA X-Mailer: git-send-email 2.51.0.355.g5224444f11-goog Message-ID: <20250905133035.275517-10-ardb+git@google.com> Subject: [PATCH v2 1/7] 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 , 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 Reviewed-by: Yeoreum Yun --- 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.355.g5224444f11-goog From nobody Sat Feb 7 17:23:19 2026 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 5F74435208A for ; Fri, 5 Sep 2025 13:30:49 +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=1757079051; cv=none; b=ix5FaGrbcqyvfByl0x/oV1VSNsM2Lssd3hRZKR95vjh38XKjSMVo2UAuT/EFjzihWyGbT/28mtK7Pv8RjAFHymqjwTjamMtPHArDalOVyJd8NoIbSE8eSZBlVa8NfS738MSGJM3sUZvRnMTxfArEYmEAvn78RpFYT4TCkx8r6FI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757079051; c=relaxed/simple; bh=0m/8gh/l82++JSDONCCBj3AtslRmuEaMeOFM1uKkYlw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=s5Y6xb2djlioAmcGhqkmK6bzJAHgOg717RxmXwsnDdAFo07GgscJ1rIrLxGJ3fi5q1xoK9eIC7OQJfenQvns/rYNmbNwnKPcNvIwUzkTyuG9JIbqpLl6pMMfzBAH15KcYKbD/FxABll47XRR80fzcBf3j3QTio9W7kHblfHte60= 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=0B1UPLpP; 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="0B1UPLpP" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-45ddbdb92c5so2359065e9.3 for ; Fri, 05 Sep 2025 06:30:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1757079048; x=1757683848; 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=RnWShrZLR7vPEU2B78j7+Lb7nzOaNYK0ui51c7MAe+o=; b=0B1UPLpP88rLa3lsWB90SnnJz8kOZRUsWx4a4yM3zXOs3gZPX1Ld0qfwt/3j9q+IGK St+WyCgVk4tVFOi+uhSTB87uGIxPyEsGIdWToUcP4aev5IJfNC4bncpr9LAl7G9O0/ui Wd6WwQeh0vbKnL7f/lzxrcBCszAHOuVl4IJPVdfgSYSVJHRJLHB7+y7HyJTvp0cWVmQ7 OUg4a4FUs3gWp+Hc9+Yps/nSV4Ype/IXwpf4y6BTF5EGIO5SaLR+iVb6SlMpy1PIB5/6 0dMX1LdyI51YbaanJbK/4fjRl38l414Hu1tc/wU7ZoX1jVVY6tGuExGZDQxRRt2Xx4bs v9yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757079048; x=1757683848; 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=RnWShrZLR7vPEU2B78j7+Lb7nzOaNYK0ui51c7MAe+o=; b=FNPaDSTLGsR0v7o/NTZ08r74Z3s5zatnozN5sI5qOvgARDkhbQj98NLAJmLs0B+W84 v9PDwDAVvEQ8vQGJKWp4sjLYSWc0cUBF+C5EPAUqQtdgntuBxMW3j5bWMX1eE6ktKDAJ BWBgDeI/nnjkAGqZujuodtC8B6c5gLf3E+bfrADr6/tGTO7Wjc9Sqmko8Mw5+eAS60Yg mBOhICIBBvtRF0lFHOrR8R2igaYcxBTtqbrNBSM5Z9nbGXpX1jl14x+kSf4Y33zo2QKM eEF6cLhhWUU+UR5wH4apJ4KTcA2gG69G7BlVLP9dCDzo6V0UUywqbjQkCiOlz/ln4bhr bOdQ== X-Gm-Message-State: AOJu0YwkVTG7cihEgmmP+Yh1rXd79lsJBR2ZSEYifJDTFbBbpRq55c18 YHBdPyRj6wMEJ9rZeqnFzwzetUttFg06s1/Z2XpkIoDJk1mHSxmThB9lYix9AqUQKUDexM5AgQ= = X-Google-Smtp-Source: AGHT+IElALc0lZ+KzdRQ2dRMVCGqhkLpgISWWuaMfOGta1rBFF8GrBs1+cH4A40kb4E6vXjqoOQHmNcF X-Received: from wmbhj7.prod.google.com ([2002:a05:600c:5287:b0:45b:883d:4704]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:8b22:b0:45b:4a98:91cf with SMTP id 5b1f17b1804b1-45b8554fa14mr221341505e9.15.1757079047829; Fri, 05 Sep 2025 06:30:47 -0700 (PDT) Date: Fri, 5 Sep 2025 15:30:38 +0200 In-Reply-To: <20250905133035.275517-9-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: <20250905133035.275517-9-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=j5/ecr8uALf7Q3nJBo6TOOBIUrCfY89Wx0Sfg11CrLo=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIWPX03/PGg7Hc66b+swzatZ//hyxHTtL6q8f+id1TzVOs mP7n33eHaUsDGJcDLJiiiwCs/++23l6olSt8yxZmDmsTCBDGLg4BWAij+8yMhyzX+Fb8tmx1cBh ubWomssPdta0xuBQ/kRP/ZqzT5JMDzAy/D6vknj/wtZNKmIrLhlwyp7sfPve3XVZjKvxH7cjZzi KGAE= X-Mailer: git-send-email 2.51.0.355.g5224444f11-goog Message-ID: <20250905133035.275517-11-ardb+git@google.com> Subject: [PATCH v2 2/7] 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 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 Reviewed-by: Yeoreum Yun --- 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.355.g5224444f11-goog From nobody Sat Feb 7 17:23:19 2026 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 53BD1352FE8 for ; Fri, 5 Sep 2025 13:30:50 +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=1757079052; cv=none; b=r56/ryD2mdHQNxQFRgDhzqjn2jDhnnaqYIkdkbxbRwJQRTpz5XKRsxLBtJ4qDdfcWuOcMtb9UMBeWEPdRNow/AV4aX+d0F0dr/E37E2NQ4RElPAnv98Ng4+K6MbUf8UC1rqZ3LiJ7bSGoRbVGrT3g45tGbntBvZbD1NinKpGMZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757079052; c=relaxed/simple; bh=96M80QLlOWDIQWQkbn/8Qkxz4zRnLs8vvaM6+45npjA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Z+DIwYI6NuSpHW8JJS8mfxowsQvqwG5Q6pcJn1U3hnVJvX912eMr0sGxV4/4g3ZdIAK+B9PHIG2P0gHbqQZhq62raa4MabqZ3ea/GsaH8yZoKlNDgq+rqepTsSgk30HfSrEndTOl7v4XIl6I2Qvbwy7yhKw4dHkg2hGp2DgS4o0= 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=1sTFyaI3; 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="1sTFyaI3" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-45b9912a07dso15339355e9.3 for ; Fri, 05 Sep 2025 06:30:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1757079049; x=1757683849; 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=6+gwoCjWfTju3sP/jVtuc7/g8X3wct7nCOhB3h1yVAQ=; b=1sTFyaI3pftxxcNiRC7sBtXZcP9nDtgJOOu0ivWdNE+mAE8FKifbYbnxFLGC3eEshX Cu7uARX8Cn+xw90vJQOVBiFlL8OboeYIC7UFOx+WhrLyGcoNoWkCLuER0UkkjzQA4PVF RdJt49TbNMpf2Dylkrzv9gqoWHScsJlhy5z7UvaZfKXH46l2U5YRomVsKC0S3LhKHUSW K/PFfvzqnw/mh2+5/HD6Hw/CWTakIZcs7/h7HUTYIJ50AORkxS9FTaMyRJnh0lmzCIpQ JSpO8iHRJjH1Ntf/J9IQhFnxcWqqinpSEgh0dEknn1iUiOiW07XuFNrARnmEUVK1Q27s nUAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757079049; x=1757683849; 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=6+gwoCjWfTju3sP/jVtuc7/g8X3wct7nCOhB3h1yVAQ=; b=Lm9NolpNDkZ1akUNLjL21yKDNVrmB085kz0/uWU69dNAsQO0/vRuqzkOHVQ1oOozUi 9taw1HvzvZ+s6cs5tY1Fxc6VrVLA4yg3j2ZMhwUhKZzBvvdLr7QMovw4ZHxikVE6Quy8 bzs8TBXMJ7jIe2aalWGABecjQS/GqoSXTl3FbHtzsGlYK6WuKTAJTe00ib5tE8GBLxdF XxPpLtY4rXFx0xGORoP20fmWgaCt7Qoy85KwiCg+eK2keMI6ZTES7BSQD78+H0ipzu3e ofLUR6n/hIsS9z2D7MIX/EpjJ1f+c+8vENnfk5LBUVDO5YKPSNhB8RULYVYLTwIXpwCV gZuQ== X-Gm-Message-State: AOJu0Yw3HjwnoxmGClLdjqKsg5eq7AD5iuVOWbaMM4xSIMVLxzMVub0K ADGZ2M2+oDyUnax8RI7dhA7YY1j5ki0eAm1s1f+STSfWd6DN5qyuSOoSSw/q+ziXxWW2NpEKKQ= = X-Google-Smtp-Source: AGHT+IFopEjOcoNJYtItMHOege0+1Lpxw3R3ZwN0yI0iXz4fJJsgWwvzjjGw2Y/Y7xXxRt/ZprPJuGNY X-Received: from wmqd18.prod.google.com ([2002:a05:600c:34d2:b0:459:d8e5:ae9d]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1e87:b0:45b:47e1:ef68 with SMTP id 5b1f17b1804b1-45b855bec6emr184837055e9.35.1757079048728; Fri, 05 Sep 2025 06:30:48 -0700 (PDT) Date: Fri, 5 Sep 2025 15:30:39 +0200 In-Reply-To: <20250905133035.275517-9-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: <20250905133035.275517-9-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=zNP081W6ZhtW0flsDQ3N/BMuwKS0QOlu9XU/sv9Pxgo=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIWPX03+yk0xKTJwl38T/f51SZBqVXMC0s9Fo/qwXrmWqL PG3gzd3lLIwiHExyIopsgjM/vtu5+mJUrXOs2Rh5rAygQxh4OIUgIloZjP8FXQxVZrZNXWLnZXB Ow1ze94vX/Zzz2VK+c92/LwAi+f1BQz/q3YrzN9To71e2LlDVqzuLIftb65dFrlRy2baqk/8tUa YDQA= X-Mailer: git-send-email 2.51.0.355.g5224444f11-goog Message-ID: <20250905133035.275517-12-ardb+git@google.com> Subject: [PATCH v2 3/7] 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 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 Reviewed-by: Yeoreum Yun --- 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.355.g5224444f11-goog From nobody Sat Feb 7 17:23:19 2026 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 F243B353371 for ; Fri, 5 Sep 2025 13:30:52 +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=1757079054; cv=none; b=P0XRRON4BTwMYwP+LaDx5bJnPX35mp7REkVhIlhclqpk9SkUUhFwkbJYDob+7iy4+YTKoXebDB7F3WYpQH2sKAI04LidaKb74lL8Q7BJY784FbAWLFYlLjrl1r8gjhE34opNMEVz6JLAL7gVgrQFGNxvVqORpYbIEh+puXsxnyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757079054; c=relaxed/simple; bh=3x4Ov+quw/0QQMe9W2h79+/nvRgwRJWoim/Yeb3cedU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Y3OwyYLM+X3HKOAUVl72mDNPZxT8GgJ6G2VMnEhOPRMuhjkbEGYz7HJaLb5sC6NJ9kOcPWEtPrcTfdlTckwAKmrWoxgtnjyeq7TQGiMjAIybkYiAoHyMfpFpIuWZxoIptWrMe4NtZHN1PM4+uKtOPkJ+nu3EZUwVVxyqq4N04Nc= 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=OVwAq2Ei; 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="OVwAq2Ei" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-45b9912a07dso15340285e9.3 for ; Fri, 05 Sep 2025 06:30:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1757079051; x=1757683851; 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=prmt6wujZXZEYu4jILQGXIbirUOdEqPv5dUXUHxMI1Y=; b=OVwAq2Ei+WydT0GtqATN3sjs03DNvBdz46+DDo7ESR0ATU+F9wYuH7tBKvedMd/Eo+ eMhtepXzfnmYl12Cp018LABtf0s3rbGrLk1ttjc5KByqETUwgq7cjHEzGgS7vNlSbSjB 5tXAU2c1W5498ksagDXQn0ccZ8H9I0+d3vdjxz+bCHjdnc/g/UQhZ7aLwqSGPUc74zPr hhkUXHJrRvvUlEg1bhHvEjdyP7tdCrDSSzfjXZzZJYdB01Fs+mQEtZWrJ1HjONrHzbz8 J1IQypQU5PxGih8chn5zMkiUJAU/IIB4QuQ4etd4DXDe25koqLZfkHnCPFsOJ1y22kDA vYMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757079051; x=1757683851; 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=prmt6wujZXZEYu4jILQGXIbirUOdEqPv5dUXUHxMI1Y=; b=uCIqQ1mBDC6ENTQjLGna7+GPXmKg/jH2y29gjhvL3hZWoOd8F9pgswFe/uunFWWNw5 DmcnDsRpdYZ9Jr27qDEB/zwD/3h+OwWgTYYmVrYMRZC1E9z+JXroGYHGg2mTldO9cszu TQnJ8SZC93qiR26h9idnOqAi7Ir234L622XrIWOxxud9a0VNPspX9wRGHFfmKnLl4DZw VKiwUq7/KT7XkMASKOF6zrwc4JOGDDVXCb5BbDIcHP8SR7b2fanYqISun72LRL8B51/Z mUWeLRh8i2KAk7/RhT1C7VLWJu3jFH22VpFGOpSoZmeEork1X5zgMUxw9Bgd6Izr0rAP 9oVA== X-Gm-Message-State: AOJu0Yw3Zc1gOx7SGrYmj3IrtYLJxuvJrWEVOFnEPamcy6TVSDR1vHXK jC8WktEKXtBDXRqByrMmt7EZa19wAQBMLHvL1aA+Zg8Lj8iyQhucIYGvzno8VB12JZ7thEqvBw= = X-Google-Smtp-Source: AGHT+IGcrXQUr4V8mfgwMOKWStLEjIiWgtx5sJLHPBI6rSUhc/g7n+CYYfQRUgy3XXrsY4OjTKbfO2Oh X-Received: from wmqc10.prod.google.com ([2002:a05:600c:a4a:b0:45d:dbd2:ec9a]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:548a:b0:45c:b5f7:c6e1 with SMTP id 5b1f17b1804b1-45cb5f7c990mr92681555e9.0.1757079051352; Fri, 05 Sep 2025 06:30:51 -0700 (PDT) Date: Fri, 5 Sep 2025 15:30:40 +0200 In-Reply-To: <20250905133035.275517-9-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: <20250905133035.275517-9-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=901; i=ardb@kernel.org; h=from:subject; bh=ymeoG2jyFnfZxHt/XMud96BPHY4rNxDq3fGtVI/uoN4=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIWPX0/86gcet7k75+ikp4N/VlzWbwz3MFzX3nZsSJbTfe Mrlys9+HaUsDGJcDLJiiiwCs/++23l6olSt8yxZmDmsTCBDGLg4BWAiLa8Z/ukpNH9K793d5xX9 gO3t6erK2Tt3XzghVfr337TlRnsmpzcyMvTJHGnzzFyjnTCjaMLd7e8XO6x7ZlfDxzbt1OKi0lP dqxgB X-Mailer: git-send-email 2.51.0.355.g5224444f11-goog Message-ID: <20250905133035.275517-13-ardb+git@google.com> Subject: [PATCH v2 4/7] arm64/fpsimd: Don't warn when EFI execution context is preemptible 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Kernel mode FP/SIMD no longer requires preemption to be disabled, so only warn on uses of FP/SIMD from preemptible context if the fallback path is taken for cases where kernel mode NEON would not be allowed otherwise. Signed-off-by: Ard Biesheuvel Reviewed-by: Yeoreum Yun --- arch/arm64/kernel/fpsimd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index c37f02d7194e..d26a02ea2bb9 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -1933,11 +1933,11 @@ void __efi_fpsimd_begin(void) if (!system_supports_fpsimd()) return; =20 - WARN_ON(preemptible()); - if (may_use_simd()) { kernel_neon_begin(); } else { + WARN_ON(preemptible()); + /* * If !efi_sve_state, SVE can't be in use yet and doesn't need * preserving: --=20 2.51.0.355.g5224444f11-goog From nobody Sat Feb 7 17:23:19 2026 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.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 3677C3568E9 for ; Fri, 5 Sep 2025 13:30:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757079055; cv=none; b=GdtkEDhMk7kScJ69rPCK2o3iQD/3HIuL8m1daKjxLuZ0WXIwHAP1n5LpmySVOwrQr1Wn00EewWWZ7huLqd9cz8vhMiqpAD2g1N6i6Dk4o3ubW4praSDXg5vK7+cfls819ck0GEgk2PesfV7JvSRe8M25ApNt9Bm21/QVZp8t+4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757079055; c=relaxed/simple; bh=dSZsAM8dQkdzxBR5dzeF0mi5iq6iad7XREh2ikihpVI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GfFcaQ8EVTvo6STYhb7nKlFfwbpVo1zmZ5EYouJ5rECqD7f73iOYsNd6ryjIWjVC2oM4q9GgVpHOb9AHU/ZgaCWXhvGP+jrqQjiRvyFwathTU01GUw5RMNHU8Q8jkSfPuazFu6poLS5bLwff5wkG+eGKxZWgORa+Pf3T88Zsv4E= 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=OBWUu/fX; arc=none smtp.client-ip=209.85.221.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="OBWUu/fX" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-3df9f185c7cso1799039f8f.1 for ; Fri, 05 Sep 2025 06:30:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1757079052; x=1757683852; 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=M5LnJAE3YZc7C+MgCps2xix2Kr7DZlZm+g8SIPc04+Q=; b=OBWUu/fXYinPjbPvXRDhB+IKUgafaRfJA48OqobKipgMMMoA0bJ8upCvFEr7GGTotb eyAVm6QoZAtHuCrNEyUggnIG0ql/ovNKr/74wtOiJvmcggcDdcNy/r5n84ly4pW1C1+Z /MbVgiy4I9UVjKvsyMixmXEV1tM701a4g0vQA+poDBlrFGCiSN+ZT6CwgEaxjVJaqMvV TN/ZdyYa90bTnjRgKV7mx43zMa2jFFh0f9r0MoN3rRxw+SvytlqisgZpi1nlgtdZ/0YA t2iKqABdHhphbzHLXDXmR4DuKo1jQ143gJLwFf5FwTpA2slEZboS68INE29lO0vmnbu3 HJeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757079052; x=1757683852; 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=M5LnJAE3YZc7C+MgCps2xix2Kr7DZlZm+g8SIPc04+Q=; b=baGDss/CMATRh7G+QNWCHEByk4b9aeroZvPbXWK0UYCB+h+3Atpb3onDTgwemHOF2w luG/AvoTirYnUZERSO60gBaROTKyx4EKTeSOMHkZiqNCoIdMYGs3O0tlP8Rl68C8MOUl tMdXnEXNGR63W5MHmA85lBcmfXTzPvntIQ1rtrhNFYkYfL8BGaTLQ+Sy4BuebzFej3nB CIwevalARLns+37w3jJikSZJ9Yb/zmcZU0seHJQkXE7NVKfCqvYHKDpgFLCDmCsGvlGd KM/447iJc6Ry3Cj+1om4/OVYwbUrAHAsDTtl9m7YilU9P5fWC4sj4T7veh0kYDAYIw4d 4QUA== X-Gm-Message-State: AOJu0Yxf7WqLQrnMhSd3ohSbkEmJxcgLquDRUWpJGOx12sWfpdocLDOw N0JRm5uMQoKshVl4SN1U2u/ohFYQvamoOxHjCOeMgzXQbUKgze3+es5fXf5R6otkTdh1JtvAgg= = X-Google-Smtp-Source: AGHT+IHMbBeVKy4nTkbHNNXw1E6U+lB/o2tBsWIP/XOdZuFF9D5csjYK61b/Q6qJIegwb6HxvZsJhbcI X-Received: from wmbf9.prod.google.com ([2002:a05:600c:5949:b0:45b:7262:8426]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:268a:b0:3d4:2f8c:1d37 with SMTP id ffacd0b85a97d-3d42f8c2014mr18693666f8f.26.1757079052632; Fri, 05 Sep 2025 06:30:52 -0700 (PDT) Date: Fri, 5 Sep 2025 15:30:41 +0200 In-Reply-To: <20250905133035.275517-9-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: <20250905133035.275517-9-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1404; i=ardb@kernel.org; h=from:subject; bh=LG9z8ZfG/9lulzNu83d9OgD0HFnWetupMNmr542q5Ks=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIWPXM4Y7F0JYuPJPl/FPqAhOvOS/S0fsxmm5cIbmeQeWv /m6IntxRykLgxgXg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZjI+oeMDBuXdugdkF+/+e3a sumKH1zmv9ZLvBy+SMj9znyFJZlnEtUY/lnIbpn4UqD00YKSc7W+PmpfbbSXM27XOuGjy3zkxZ1 oSQ4A X-Mailer: git-send-email 2.51.0.355.g5224444f11-goog Message-ID: <20250905133035.275517-14-ardb+git@google.com> Subject: [PATCH v2 5/7] arm64/efi: Use a semaphore 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 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 semaphore, so that the CPU can preempted while running the EFI runtime service. Signed-off-by: Ard Biesheuvel Reviewed-by: Yeoreum Yun --- 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 9b03f3d77a25..8b999c07c7d1 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -165,12 +165,19 @@ 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_SEMAPHORE(efi_rt_lock, 1); =20 bool arch_efi_call_virt_setup(void) { + /* + * This might be called from a non-sleepable context so try to take the + * lock but don't block on it. This should never occur in practice, as + * all EFI runtime calls are serialized under the efi_runtime_lock. + */ + if (WARN_ON(down_trylock(&efi_rt_lock))) + return false; + efi_virtmap_load(); - raw_spin_lock(&efi_rt_lock); __efi_fpsimd_begin(); return true; } @@ -178,8 +185,8 @@ bool arch_efi_call_virt_setup(void) void arch_efi_call_virt_teardown(void) { __efi_fpsimd_end(); - raw_spin_unlock(&efi_rt_lock); efi_virtmap_unload(); + up(&efi_rt_lock); } =20 asmlinkage u64 *efi_rt_stack_top __ro_after_init; --=20 2.51.0.355.g5224444f11-goog From nobody Sat Feb 7 17:23:19 2026 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.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 CFF31356909 for ; Fri, 5 Sep 2025 13:30:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757079057; cv=none; b=UAwZdAYpXdr5/4TCDCfxrLfMh13lD4iUE4mhcj9HrD16vJfxUahIClc9Hb5sB445/SwYAuJwJVIC9RAGiTOjpJ26ikSCJjXYxC/dMWhTiSYKGbTmL5wXSE4Uw3rfqB20HoqafdzJYDagZuCQr+WT/Pc1EJ77DGocoaibfLFus3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757079057; c=relaxed/simple; bh=vCN+7KY/Jr0TywSZW8mKMyvfechRFEsHvYFf7BYUBzI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=IP1z0DO+TlPBpPNF/A0rBBjfFlNQ2ARHTEXu8HCp2DAi395IZEt9x/ts8f+boDafbU67n5Hg/6lpqmQ5M8MkYmFEH3q771AnwmQDmB9emgWEx89iStD9ErDlPPu+opE2QJM5hSYmmoVs/Aq4NZbJbvc9sStzxmJZIZTSVzpRrpc= 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=2l4vZB4E; arc=none smtp.client-ip=209.85.221.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="2l4vZB4E" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-3dbc72f8d32so987160f8f.3 for ; Fri, 05 Sep 2025 06:30:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1757079054; x=1757683854; 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=UAF98sQpATPhOILk8yZBv19jRmRkto76vQZwCOx0WtQ=; b=2l4vZB4Ezl/R7QWLvaxLA4D+C0dFWMngn/ljacW1xtRxgee8YSinkOzjSsBIFwFC/m dE8lilcvEneBap82hfq/7pKfNddwT65/mZxeh7xBT2mNVUEOb+eg2bF9Y1tS3dbcK6Gu br5JSAyS22g8Qu3gwuUQ4Z+QXZgNB/7JYhJb4SeVuTnE1F5UnJ2pddK+kScF1/X1Ttuw iO/OG3BwYGCsAC3QTNzIxNYcDn80moUGmTQllyW39dGKtAMz83upzuGm8Te32IwJ9MNK jKmZWOT3OK0sleUP5+hNe33R9yUn3ztQ/wx7bb2QOwvjbZ7S7rHR/FHBcHfpmBpRuhlQ /pVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757079054; x=1757683854; 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=UAF98sQpATPhOILk8yZBv19jRmRkto76vQZwCOx0WtQ=; b=UMQrokAGxECd2lE31n16BU7xli/j1dg4eFwprZ08SNu0SDjYYxcYFNLBEd4TBgmyvu oPyvt4twKU4Ybryk5ORXUKZBvoWUmdNjAOcy74jBx2qmjBznhoBPcJYZWRXEHzZbg8cM rlT234Ykx3cWeWAuSnYPdR0lPHHSZV0yHSZwD8w7bkUBE/RcCrJOIa+3AHHUsBv5MowJ cEDotF00xhFoUIYvPUxBp2C8vAaY9B44Tv8oFSBeMH4mlXwagBOu5dEKD0GbXFcCSFuO pFZ0ET1MUOTngMSFzm0PuDNG9RDqytnEXUFHfH2D/28Ew9dnbSxOlvL/N4W32o0ziTqh KzDw== X-Gm-Message-State: AOJu0Yy6bfUXL+xaE1mAE4Y/VkZudbHN9Y/4aQgzgaLb7lu9sSw4ubOV VSmum84XFLxs9YMAO0MPE5jkjC9rM/rkwFKfIcG1nhBXrJhxwlOPAD0xxMdPw9xw+zdZr7NP6g= = X-Google-Smtp-Source: AGHT+IHLpO7vPeIPvV0hzS6kpc52u4CYIVWVnX+yyG4DktDXavuZLD82XV3iPv6GN2Z2q98RRymwXSY0 X-Received: from wmbds17.prod.google.com ([2002:a05:600c:6291:b0:45d:cf67:3908]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:65b:b0:3d4:a64:6758 with SMTP id ffacd0b85a97d-3d40a646c13mr15248912f8f.3.1757079054348; Fri, 05 Sep 2025 06:30:54 -0700 (PDT) Date: Fri, 5 Sep 2025 15:30:42 +0200 In-Reply-To: <20250905133035.275517-9-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: <20250905133035.275517-9-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2686; i=ardb@kernel.org; h=from:subject; bh=EAF0+F/3qCMp7xJeOjrqAiIGXMepd3zxzLCGJhcn/30=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIWPXM8YdJe3LeJP4vwf3THd6ylR4S3rtYu34UmZbxSsJR pLrjm7qKGVhEONikBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABOpO8/IsO1P5uV/fr7rn8sb HFA07HxQLGpdHLL5R/aHORPLOqddXszwhytGu7NGZYpawm6jP93C5XNWqF49PV9rVtz7Q79O/bN YxQkA X-Mailer: git-send-email 2.51.0.355.g5224444f11-goog Message-ID: <20250905133035.275517-15-ardb+git@google.com> Subject: [PATCH v2 6/7] 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 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 Reviewed-by: Yeoreum Yun --- 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 8b999c07c7d1..ece046bcf0db 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -178,6 +178,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(); + __efi_fpsimd_begin(); return true; } @@ -185,6 +194,15 @@ bool arch_efi_call_virt_setup(void) void arch_efi_call_virt_teardown(void) { __efi_fpsimd_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(); up(&efi_rt_lock); } --=20 2.51.0.355.g5224444f11-goog From nobody Sat Feb 7 17:23:19 2026 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 9037D35691E for ; Fri, 5 Sep 2025 13:30:56 +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=1757079058; cv=none; b=MfwS72DVHYKKUE8Me7nyl0L4U0pED/fkylwnP+zl6O4nIRUaIM/vamEJVo4W8F0rW0LRHr1BiNC5ggtMLKpAOPIF6hxkBrZ6WgnAMJ+CgRSAGuXqXr6swW9jvpRdkxlZccSxm+aDOxpCjMZkoLtgQrtGvuktq1rJY9tdwA27p0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757079058; c=relaxed/simple; bh=Xvp85F/Dx4S0XK/y27QHNKNLSZPPXOsjzftN/mdI1yw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ippI6ZgW3ob2XYGGC04IEHqURZAUD4k9muh1uq1CD2MecsZgWlKDh/jMQngyfLt7Q5InKvpdAOR8/c16EYXbnBVWLBsHdsvrY5Kq5CXEh37cuVY3mQBbUJc3qN3UFybUfea5KknShrb5ZvhNamAnsBIUCpw88NGbrb+iFpOGH24= 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=HUgm5XfA; 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="HUgm5XfA" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-45dd5c1b67dso7125325e9.2 for ; Fri, 05 Sep 2025 06:30:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1757079055; x=1757683855; 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=k7SGgiq8e0ibQjNE492pNxUn28Q/j5kSsNWzW80icFw=; b=HUgm5XfAMLak3zZnaDg1v+l8z2p6ts9VdCXLiI3tio/WUs43+oI550FZLkcd39V/z2 31vZMRpcxlETz7yRzQX+sgRrJpD8D/pWR0FWo/DRYXunauytJTtxBtAwNzo8IIsAqnBh P7tDG8342Sxr1NH6dVgNyMEEpXUjjW4WcRlS0pGkvJTeRXcf3LxcICjaQ6EdWeO4EB7u r2MAd18GQ46R4YDvJdxmkyt5u+HJugqlXEiBBdRXABmC/AJp/8UdDBBd1gcksitf7tkC 3+pndo46N7ajvlaZgOaYnxzAKNqCrJJTdUB3UxTLlAGZzyubfr4ht53qlILjalxpOnrX kndA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757079055; x=1757683855; 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=k7SGgiq8e0ibQjNE492pNxUn28Q/j5kSsNWzW80icFw=; b=gf+y7kphE/EbHipB5OrOuubdcel/+L/5uJUH2aSC9Y/sgsFL0ZA1oVlUrUd/7A7tAk efY59SVqtQk3JcIDbFRGJdZYefNHKePwGQcKeRAa9gWODYRwzHh+6XArGa/wUkD9YZ/E ASurr4Pcm3ezeABSKUT4vXnr18nfPJyp59QBDr/hlMUMznyQy9mHaXFK1vhHsY8JjCnM tAwh11IFYBzEmPzuu+7jUcrboYZaEgGHpotjpPignyPI4++w6VXCeg4H9qftxBcHMjSn Ofj8q8ea/ye6fC47ulTRa66abyFWynQ5thvU6MpTH5veTRb04BLYXqebXh7cFCEXC0jD 1++g== X-Gm-Message-State: AOJu0YwBNstxF1eOqzTtxiJT9SIw1yxyRntn/ZL5gFbaU0zKdlKMJzpY yY3qSTkYCpaeKNxEVxpFzOto3+alGcPuh/TM7QqZh0FU5lwOg1vksZ7rcaJV3X0HauC8/xytrA= = X-Google-Smtp-Source: AGHT+IFvcFnuIOuoqBisDROlcvYmwSXQfsXo7xa1mO1oe2SxbUKBbSt14Xcgr/JdOQQx2fY9o0Bwyd8Z X-Received: from wmbds17.prod.google.com ([2002:a05:600c:6291:b0:45d:cf67:3908]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1584:b0:45d:d609:117f with SMTP id 5b1f17b1804b1-45dd60912c7mr22883895e9.8.1757079055152; Fri, 05 Sep 2025 06:30:55 -0700 (PDT) Date: Fri, 5 Sep 2025 15:30:43 +0200 In-Reply-To: <20250905133035.275517-9-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: <20250905133035.275517-9-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=3214; i=ardb@kernel.org; h=from:subject; bh=p0S4tXXYoOutiRiXN4g5SW9wNTpd5LNBz7e6ejjtylE=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIWPXM6a5x+oyuYWeVatHRHPziD3YeKNUdPtTxXs12SJnl Od3eJl2lLIwiHExyIopsgjM/vtu5+mJUrXOs2Rh5rAygQxh4OIUgImomjH8U0s6sDv2b+D/4x6C tWKuAms0VPqiFj35WPi5XDr/7YONqowMx9Vfi//Ymfzk8RSXx5mrF5VGb3q0ap1LTp9bBVtGypV SdgA= X-Mailer: git-send-email 2.51.0.355.g5224444f11-goog Message-ID: <20250905133035.275517-16-ardb+git@google.com> Subject: [PATCH v2 7/7] 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 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 Reviewed-by: Yeoreum Yun --- 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 ece046bcf0db..cf62980006ea 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include =20 @@ -177,7 +178,19 @@ bool arch_efi_call_virt_setup(void) if (WARN_ON(down_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 @@ -203,7 +216,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(); + } + up(&efi_rt_lock); } =20 --=20 2.51.0.355.g5224444f11-goog