Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp754309pxb; Wed, 20 Jan 2021 21:20:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJzz1GuRAZS+rY669Zp4mSDqQCYkCWWt9lKAvs6dw1gEvz0rWeTuga+koREKVxwtCpyMIPXd X-Received: by 2002:a17:906:3b4a:: with SMTP id h10mr7979814ejf.423.1611206436135; Wed, 20 Jan 2021 21:20:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611206436; cv=none; d=google.com; s=arc-20160816; b=IgaV4lxvLBJR3gZgnv5/3c6tS1a7rKwcR9ZRiLwegNG+XaaekEI1bQbVTDaYFEMF6S vBn6S7/gfHSHyieElPejQQNuJwclPZEottq2Zc1DhtGqPA7JNo9/01RE0LiEegG5Xijp wXqucABGXUl+Bdwc9nMvo1fQSg6lS4VR0aGFKxJCMjtdITwmWF7kgl79V7QYg4Tx9YvR s+1BUsKf2gS0ZTqXL0Z8ny1eomd3VEO6X+x2G1JZqcXfRJ0w2rocrKloc53XQKoEHQGj L7b4gzb1Wygj/4OKvJUjhTJ+aq4aECycBiYu0FXpVh8o8qjVrOag5QQLfIV5U9F3x+dA 2VbA== 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=Xc1zceWOENOen3tJh/Q0gDFbn+q6/QXw1NomRy5iJLCoSSPLR4DOCzs1mgqYEdtYIm 4ZREUD4FLqAVOQ8oPc4a/B+9GVzvco5lUtw0SrYArNlGSt4XGrwaqHmJhXF+QVRgd1G7 nBtP2wkWRumCnlvbNe9hM53nOcmlxAFqDMO9GQi0TW4KDZG/02KGBqwTM6djEYGOYQu6 iUdiHKpaihJ478/PdSP52f/ztheNA2NrpL1dskJPXgRqTb2Hug9yaPILTRzL8NHpJo7K LFEbLc51bFhglZ5qbMlWdLIAsAJfOum4dMT+JOFCYkOzuDPa3dOfs2Nz3yzkTeMZ7X+1 J4ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f3Sk+kny; 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 k4si1347476ejk.405.2021.01.20.21.20.12; Wed, 20 Jan 2021 21:20:36 -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=f3Sk+kny; 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 S1727876AbhAUFS0 (ORCPT + 99 others); Thu, 21 Jan 2021 00:18:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:46898 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725874AbhAUFKg (ORCPT ); Thu, 21 Jan 2021 00:10:36 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 76FB72395A; Thu, 21 Jan 2021 05:09:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611205795; bh=Q7Wt0+lVfhHlWCEGnSufVJdo/kJ3Toujd33xSqH47fI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f3Sk+knyM+rW2SYVqQpKPOizCdUHooy9XIbm/SQ+0PVazOsbvVfiOsOm3vrSiEV/5 4SDSq2FkoMUOUCEpWKNQdnugzamXbzmT0kYQeBXIk75jE5YkfT3x6DIUgeAGDHg2Jr SOna8mA3oYw3xabAjDjY4jMGsmSPTBBHJz7tMzfZi+EDB07KsIabNQusOZLenir/WA xmvIpiSQSvtvSeTV+jaEylSMX1HXSQh72tJaOAhHPbl6EzzBIVQO/ykyAun3x34qh2 Q9UH1lODBATkFo4EJ8hDCqsDH7IbFbhTW0XvA1KSsjDkieVUoINSQImcApxZ5orJ6f HNKYaXhN8MFHA== From: Andy Lutomirski To: x86@kernel.org Cc: LKML , Krzysztof Mazur , =?UTF-8?q?Krzysztof=20Ol=C4=99dzki?= , Arnd Bergmann , Andy Lutomirski Subject: [PATCH v3 3/4] x86/fpu: Make the EFI FPU calling convention explicit Date: Wed, 20 Jan 2021 21:09:50 -0800 Message-Id: <25d392fff64680e0f4bb8cf0b1003314dc29eafe.1611205691.git.luto@kernel.org> 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