Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2997789pxb; Tue, 19 Jan 2021 10:57:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjE6JRy8XvlTwYctWqDiS6rW7SZzMLin1x8TG1DmvYCNfYGWbvRetN0gprRzJpNv0G3zGw X-Received: by 2002:a17:907:d8b:: with SMTP id go11mr3879865ejc.303.1611082674237; Tue, 19 Jan 2021 10:57:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611082674; cv=none; d=google.com; s=arc-20160816; b=IEk6stu2jSOcjQarFHei6iQ2PBuMWibCtHbgX7IEd/Wlw820p6WEPQKsQv4B3PRj9x asZ8UYI+ry7DuAQ5Rti1ejPwCn8ZnjfZB5WqSflxRSECI4Bw0a/Rv79JpCkkvcZJr6y5 Z1GRUPItR8wRfuafJg5aWL3Zmb+hXb3gRXKMiWzGw7tNurSESiJSnIdqAXbbyNG8rSDe t0rTUwCKT/BiUNlXjKpy5JY7tNq1wSTgbHgJZLgu6t7QWG8Mgf1FmMKO0DCfqD4lEK5A VdcMSpkZuDU8T0beEE/BAAOrD9iF9kPMuKAbgxhprceB1aCBAyJdVzIz/5twnjArxq5i 4QgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CgVZBLFoDVNwqCGXq2WltNLWPQkT7lxVs6ly59ikC0M=; b=kLd47pXYLpYURm+Gd4wOTsijork3dUXvm2rN4WfgIob+a/2u3Jpg1rbPnfmSX85zLS YlPP+skkpXOliirce0pNS54X0vtqNf0mHjf1vowv29timlkC9QnPEiXYqEewX6GEqPDY Dd+A+4AV+2wIEAMTfklnjVNpeA2XH2h1RyVO+J17042fCucJyw0zd0FtFIRoQPjJbTyH KtrgytYvjxa2gCYxEGnkKHMFTgUWumTH+zcLO2mY13urRDErHF4bxya1fyGbf7/LADXB eCxkELeX4Gvxl7cCsiO3MsqUY4IUPI926QvnebGynG8HZHhzGe0PVQcqzlnwrBFcK29c sCkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JAaQ3NtJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c8si10294172edq.432.2021.01.19.10.57.29; Tue, 19 Jan 2021 10:57:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JAaQ3NtJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389143AbhASSzz (ORCPT + 99 others); Tue, 19 Jan 2021 13:55:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:48622 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387434AbhASS1e (ORCPT ); Tue, 19 Jan 2021 13:27:34 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2349123731; Tue, 19 Jan 2021 17:39:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611077961; bh=Q7Wt0+lVfhHlWCEGnSufVJdo/kJ3Toujd33xSqH47fI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JAaQ3NtJflXhlixAMzk8fxDVZ2o1ICcpIYRZKUlPjH9KY8mhcSbgCVTc8idFG0vVV v6VKequGBAagyhm6RIjR2edmEvxKrV127aFdYta0Plk+v7ciAueYWiMN7y0y5XwF1b MtxwJyhJNtP9+sfykaBxyWEOiWOoz0JtzHY4zBf4sQCT3PIjhMLfKzex2PucbxrvtP nQ4GcxiIk0qWZSQhSQrfvfPC0m0giDPt0ZGjNuSN34exgtZAY9DNsKzHVmYxVFzR5w I1uGQC9VPt6/1n0breSBEyE/Xo+zrPuIoBhF3btiiw03PeBrSB/rECe84R1d5bYsss NhbTTCodOAw0g== From: Andy Lutomirski To: x86@kernel.org Cc: LKML , Krzysztof Mazur , =?UTF-8?q?Krzysztof=20Ol=C4=99dzki?= , Arnd Bergmann , Andy Lutomirski Subject: [PATCH v2 3/4] x86/fpu: Make the EFI FPU calling convention explicit Date: Tue, 19 Jan 2021 09:39:01 -0800 Message-Id: X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org EFI uses kernel_fpu_begin() to conform to the UEFI calling convention. This specifically requires initializing FCW, whereas no sane 64-bit kernel code should use legacy 387 operations that reference FCW. This should enable us to safely change the default semantics of kernel_fpu_begin() to stop initializing FCW on 64-bit kernels. Cc: Arnd Bergmann Signed-off-by: Andy Lutomirski --- arch/x86/include/asm/efi.h | 24 ++++++++++++++++++++---- arch/x86/platform/efi/efi_64.c | 4 ++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h index bc9758ef292e..f3201544fbf8 100644 --- a/arch/x86/include/asm/efi.h +++ b/arch/x86/include/asm/efi.h @@ -68,17 +68,33 @@ extern unsigned long efi_fw_vendor, efi_config_table; #f " called with too many arguments (" #p ">" #n ")"); \ }) +static inline void efi_fpu_begin(void) +{ + /* + * The UEFI calling convention (UEFI spec 2.3.2 and 2.3.4) requires + * that FCW and MXCSR (64-bit) must be initialized prior to calling + * UEFI code. (Oddly the spec does not require that the FPU stack + * be empty.) + */ + kernel_fpu_begin_mask(KFPU_387 | KFPU_MXCSR); +} + +static inline void efi_fpu_end(void) +{ + kernel_fpu_end(); +} + #ifdef CONFIG_X86_32 #define arch_efi_call_virt_setup() \ ({ \ - kernel_fpu_begin(); \ + efi_fpu_begin(); \ firmware_restrict_branch_speculation_start(); \ }) #define arch_efi_call_virt_teardown() \ ({ \ firmware_restrict_branch_speculation_end(); \ - kernel_fpu_end(); \ + efi_fpu_end(); \ }) #define arch_efi_call_virt(p, f, args...) p->f(args) @@ -107,7 +123,7 @@ struct efi_scratch { #define arch_efi_call_virt_setup() \ ({ \ efi_sync_low_kernel_mappings(); \ - kernel_fpu_begin(); \ + efi_fpu_begin(); \ firmware_restrict_branch_speculation_start(); \ efi_switch_mm(&efi_mm); \ }) @@ -119,7 +135,7 @@ struct efi_scratch { ({ \ efi_switch_mm(efi_scratch.prev_mm); \ firmware_restrict_branch_speculation_end(); \ - kernel_fpu_end(); \ + efi_fpu_end(); \ }) #ifdef CONFIG_KASAN diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c index 8f5759df7776..f042040b5da1 100644 --- a/arch/x86/platform/efi/efi_64.c +++ b/arch/x86/platform/efi/efi_64.c @@ -848,7 +848,7 @@ efi_set_virtual_address_map(unsigned long memory_map_size, virtual_map); efi_switch_mm(&efi_mm); - kernel_fpu_begin(); + efi_fpu_begin(); /* Disable interrupts around EFI calls: */ local_irq_save(flags); @@ -857,7 +857,7 @@ efi_set_virtual_address_map(unsigned long memory_map_size, descriptor_version, virtual_map); local_irq_restore(flags); - kernel_fpu_end(); + efi_fpu_end(); /* grab the virtually remapped EFI runtime services table pointer */ efi.runtime = READ_ONCE(systab->runtime); -- 2.29.2