From patchwork Wed Nov 10 22:07:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 12613183 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA599C433EF for ; Wed, 10 Nov 2021 22:09:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 82B2B6112F for ; Wed, 10 Nov 2021 22:09:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 82B2B6112F Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 96F2F6B00AC; Wed, 10 Nov 2021 17:08:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A37A6B00AE; Wed, 10 Nov 2021 17:08:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 744FF6B00AF; Wed, 10 Nov 2021 17:08:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 5FF236B00AC for ; Wed, 10 Nov 2021 17:08:45 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1CC91181AF5EA for ; Wed, 10 Nov 2021 22:08:45 +0000 (UTC) X-FDA: 78794411010.21.E69166E Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2074.outbound.protection.outlook.com [40.107.92.74]) by imf04.hostedemail.com (Postfix) with ESMTP id 069A15000313 for ; Wed, 10 Nov 2021 22:08:33 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CPGJQitw9kXLUTHOVkBJtHRBr8FShwSacp2OhhFxt2iPmk79StKie+vbZ7wamLgy3gKyKrvIo1/lxPUqrqFsLgUpr6LJly9cQYGR+UUHi40d0g4ziI3bLbgYy62LBCgOL46+SRz/b5eap9CRVggTvSW9tFvmsRIAdRE60uY0zvywqqmHSTNYHFS3vvPMvJ2nJkpB4tkv7fuesi8WMDhi4iCATJNLYNT+DNl1orN5ttWagwMtr3nb2+oQ/9Amkh9teuXNypvoCtjvgLkX092dugb8psYLDzkyQwWy59YPZH4GsevCxp+UktOFfQ2l5iLBtMsbgBjc6bWUsb4oPO4FfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=sGjTpKzDP7c6ROB4BD0Wz20WdJwwCdbU1Vg7fEMir8A=; b=M6FyfruqlPPwkCpsyOZ3neLmtgwKQl3B+02p+5cCrQ9Obtxqcj4LJ4ZBVCbohp3bwqqQRlRxwwJzga9H9/rs71La+8TuP4cHGdfKiJQRx9lJ1fbnH5XGyQkmh21oo28LKTVpPuIPAi14+lP7sReljnXO07u+/AEYLnRBNKafwkJS7Mzncx9ncn+qPa8bxg8g+S0u3Nei+CJU+PcIPkxd6aWz1dYU/4hX3hc6cAn5giNz+Fx6KVsio2id+7hcEfU0KUYGyUFeOFPmVhfwi3UJKQhtfeDyyJeqVBaXdlLTKFd6C1Onjp5W3ylrtRxvl6Pt6+1XrOvZXbOyNuLG8Qo0AA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sGjTpKzDP7c6ROB4BD0Wz20WdJwwCdbU1Vg7fEMir8A=; b=l7lmsM34TUWYoG+3Mw5pLEJT7jYTHYko8QHApUmDKoWn2VHSVnYYchyVL7zWgIIs3eppABTOotTCudu0qwffj6s6+SOaf5WhKFDuwj5tLdSISO1KU73qM+HbncdzGIqIHulScVv3xXN5Ocu+KI2Csw+H22ZwrRZRenuovy2mjy0= Received: from DM3PR08CA0009.namprd08.prod.outlook.com (2603:10b6:0:52::19) by BY5PR12MB5014.namprd12.prod.outlook.com (2603:10b6:a03:1c4::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.15; Wed, 10 Nov 2021 22:08:42 +0000 Received: from DM6NAM11FT041.eop-nam11.prod.protection.outlook.com (2603:10b6:0:52:cafe::6f) by DM3PR08CA0009.outlook.office365.com (2603:10b6:0:52::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11 via Frontend Transport; Wed, 10 Nov 2021 22:08:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT041.mail.protection.outlook.com (10.13.172.98) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4690.15 via Frontend Transport; Wed, 10 Nov 2021 22:08:41 +0000 Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Wed, 10 Nov 2021 16:08:39 -0600 From: Brijesh Singh To: , , , , , , CC: Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , "Vitaly Kuznetsov" , Jim Mattson , "Andy Lutomirski" , Dave Hansen , Sergio Lopez , Peter Gonda , "Peter Zijlstra" , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , Michael Roth , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , "Dr . David Alan Gilbert" , , , , Brijesh Singh Subject: [PATCH v7 29/45] x86/compressed/acpi: move EFI system table lookup to helper Date: Wed, 10 Nov 2021 16:07:15 -0600 Message-ID: <20211110220731.2396491-30-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211110220731.2396491-1-brijesh.singh@amd.com> References: <20211110220731.2396491-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2277680b-2803-4568-8973-08d9a496a7dc X-MS-TrafficTypeDiagnostic: BY5PR12MB5014: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qLjwsozlCZ7gHizYjjVmne9Dqmlg02ycBeCi2BaJuXNJ3u/K1+qO60wKBhMFteXMLZy2MhMWJrinI7H6unYtb8LxppGixGJnQfgJAebbY4uPWgCutmGhc3l/WzjCAxLVlYOs3s4ERkJlvB2Y6M1e71r11gwZKQcMZ7YdK97Yx9ukIK3ZrdYeYqTZ/TJR3CElfVah0vMHlMJGsAE1W2jmAVnIsHGtucKgbmStwCmhRsCDuirBdOhG49PqR8/obvLssLu4I07LtTjIl7B2Lgb54WIZ4ezwXGCsoCa7AI4EDre0Ggpj3MyKXlChayBqFMQapa7USin9uR8poeXvErQJTzstq0lMteuQETQ1e6Cuexfd198FUAEaA0cXQjkaYZpZyCCAJ7sJgj69LoGkekfaEdkymwn3WuqmZHbZXjFaj4NgpZiOI+K5PQmHdmTc4MQXoL7xVZHrJW/A1/tFtriWwr5I3PVK5oYEvnVHOnKl7Ryq52G8gY9Kt11X/JHExnvrV1XE+wA54bwIBGsmvGe85wBHdXPvmX+BdmH3KVoWzDp9gnOjNaz3x9qxTM8X5QsunQgPPT0cFF7UGnpg5EQdpmXtFLQVnE8B1D6yQ59egRuo57bkPiKRPq/N4tFnmM9EmsExUNFy+8aGRl6nN1hZ0Hmt9908qoZ2t7HtxVKkG0rNqDoTIZy2Gsl+ZiOK06E/xKgrmK5EhlAqwGPyMTWJAG1l/apiaZKNNu6BhUVQzj5RYRT4hiv140Hc/4xen/Eh X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(316002)(356005)(7416002)(6666004)(26005)(7406005)(508600001)(8936002)(336012)(8676002)(186003)(54906003)(16526019)(81166007)(5660300002)(110136005)(70206006)(36860700001)(70586007)(36756003)(7696005)(4326008)(44832011)(82310400003)(47076005)(2616005)(86362001)(1076003)(2906002)(426003)(83380400001)(2101003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2021 22:08:41.7074 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2277680b-2803-4568-8973-08d9a496a7dc X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT041.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB5014 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 069A15000313 X-Stat-Signature: jbygo451849d9texz48fmat8rbu3aqfn Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=l7lmsM34; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf04.hostedemail.com: domain of brijesh.singh@amd.com designates 40.107.92.74 as permitted sender) smtp.mailfrom=brijesh.singh@amd.com X-HE-Tag: 1636582113-841570 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Michael Roth Future patches for SEV-SNP-validated CPUID will also require early parsing of the EFI configuration. Incrementally move the related code into a set of helpers that can be re-used for that purpose. Signed-off-by: Michael Roth Signed-off-by: Brijesh Singh --- arch/x86/boot/compressed/Makefile | 1 + arch/x86/boot/compressed/acpi.c | 60 ++++++++++---------------- arch/x86/boot/compressed/efi.c | 71 +++++++++++++++++++++++++++++++ arch/x86/boot/compressed/misc.h | 14 ++++++ 4 files changed, 108 insertions(+), 38 deletions(-) create mode 100644 arch/x86/boot/compressed/efi.c diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index 431bf7f846c3..d364192c2367 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -100,6 +100,7 @@ endif vmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o +vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o efi-obj-$(CONFIG_EFI_STUB) = $(objtree)/drivers/firmware/efi/libstub/lib.a $(obj)/vmlinux: $(vmlinux-objs-y) $(efi-obj-y) FORCE diff --git a/arch/x86/boot/compressed/acpi.c b/arch/x86/boot/compressed/acpi.c index 8bcbcee54aa1..9e784bd7b2e6 100644 --- a/arch/x86/boot/compressed/acpi.c +++ b/arch/x86/boot/compressed/acpi.c @@ -86,8 +86,8 @@ static acpi_physical_address kexec_get_rsdp_addr(void) { efi_system_table_64_t *systab; struct efi_setup_data *esd; - struct efi_info *ei; - char *sig; + bool efi_64; + int ret; esd = (struct efi_setup_data *)get_kexec_setup_data_addr(); if (!esd) @@ -98,18 +98,16 @@ static acpi_physical_address kexec_get_rsdp_addr(void) return 0; } - ei = &boot_params->efi_info; - sig = (char *)&ei->efi_loader_signature; - if (strncmp(sig, EFI64_LOADER_SIGNATURE, 4)) { + /* Get systab from boot params. */ + ret = efi_get_system_table(boot_params, (unsigned long *)&systab, &efi_64); + if (ret) + error("EFI system table not found in kexec boot_params."); + + if (!efi_64) { debug_putstr("Wrong kexec EFI loader signature.\n"); return 0; } - /* Get systab from boot params. */ - systab = (efi_system_table_64_t *) (ei->efi_systab | ((__u64)ei->efi_systab_hi << 32)); - if (!systab) - error("EFI system table not found in kexec boot_params."); - return __efi_get_rsdp_addr((unsigned long)esd->tables, systab->nr_tables, true); } #else @@ -119,45 +117,31 @@ static acpi_physical_address kexec_get_rsdp_addr(void) { return 0; } static acpi_physical_address efi_get_rsdp_addr(void) { #ifdef CONFIG_EFI - unsigned long systab, config_tables; + unsigned long systab_tbl_pa, config_tables; unsigned int nr_tables; - struct efi_info *ei; bool efi_64; - char *sig; - - ei = &boot_params->efi_info; - sig = (char *)&ei->efi_loader_signature; - - if (!strncmp(sig, EFI64_LOADER_SIGNATURE, 4)) { - efi_64 = true; - } else if (!strncmp(sig, EFI32_LOADER_SIGNATURE, 4)) { - efi_64 = false; - } else { - debug_putstr("Wrong EFI loader signature.\n"); - return 0; - } + int ret; - /* Get systab from boot params. */ -#ifdef CONFIG_X86_64 - systab = ei->efi_systab | ((__u64)ei->efi_systab_hi << 32); -#else - if (ei->efi_systab_hi || ei->efi_memmap_hi) { - debug_putstr("Error getting RSDP address: EFI system table located above 4GB.\n"); + /* + * This function is called even for non-EFI BIOSes, and callers expect + * failure to locate the EFI system table to result in 0 being returned + * as indication that EFI is not available, rather than outright + * failure/abort. + */ + ret = efi_get_system_table(boot_params, &systab_tbl_pa, &efi_64); + if (ret == -EOPNOTSUPP) return 0; - } - systab = ei->efi_systab; -#endif - if (!systab) - error("EFI system table not found."); + if (ret) + error("EFI support advertised, but unable to locate system table."); /* Handle EFI bitness properly */ if (efi_64) { - efi_system_table_64_t *stbl = (efi_system_table_64_t *)systab; + efi_system_table_64_t *stbl = (efi_system_table_64_t *)systab_tbl_pa; config_tables = stbl->tables; nr_tables = stbl->nr_tables; } else { - efi_system_table_32_t *stbl = (efi_system_table_32_t *)systab; + efi_system_table_32_t *stbl = (efi_system_table_32_t *)systab_tbl_pa; config_tables = stbl->tables; nr_tables = stbl->nr_tables; diff --git a/arch/x86/boot/compressed/efi.c b/arch/x86/boot/compressed/efi.c new file mode 100644 index 000000000000..bcf1d5650e26 --- /dev/null +++ b/arch/x86/boot/compressed/efi.c @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Helpers for early access to EFI configuration table + * + * Copyright (C) 2021 Advanced Micro Devices, Inc. + * + * Author: Michael Roth + */ + +#include "misc.h" +#include +#include + +/** + * Given boot_params, retrieve the physical address of EFI system table. + * + * @boot_params: pointer to boot_params + * @sys_tbl_pa: location to store physical address of system table + * @is_efi_64: location to store whether using 64-bit EFI or not + * + * Returns 0 on success. On error, return params are left unchanged. + * + * Note: Existing callers like ACPI will call this unconditionally even for + * non-EFI BIOSes. In such cases, those callers may treat cases where + * bootparams doesn't indicate that a valid EFI system table is available as + * non-fatal errors to allow fall-through to non-EFI alternatives. This + * class of errors are reported as EOPNOTSUPP and should be kept in sync with + * callers who check for that specific error. + */ +int efi_get_system_table(struct boot_params *boot_params, unsigned long *sys_tbl_pa, + bool *is_efi_64) +{ + unsigned long sys_tbl; + struct efi_info *ei; + bool efi_64; + char *sig; + + if (!sys_tbl_pa || !is_efi_64) + return -EINVAL; + + ei = &boot_params->efi_info; + sig = (char *)&ei->efi_loader_signature; + + if (!strncmp(sig, EFI64_LOADER_SIGNATURE, 4)) { + efi_64 = true; + } else if (!strncmp(sig, EFI32_LOADER_SIGNATURE, 4)) { + efi_64 = false; + } else { + debug_putstr("Wrong EFI loader signature.\n"); + return -EOPNOTSUPP; + } + + /* Get systab from boot params. */ +#ifdef CONFIG_X86_64 + sys_tbl = ei->efi_systab | ((__u64)ei->efi_systab_hi << 32); +#else + if (ei->efi_systab_hi || ei->efi_memmap_hi) { + debug_putstr("Error: EFI system table located above 4GB.\n"); + return -EOPNOTSUPP; + } + sys_tbl = ei->efi_systab; +#endif + if (!sys_tbl) { + debug_putstr("EFI system table not found."); + return -ENOENT; + } + + *sys_tbl_pa = sys_tbl; + *is_efi_64 = efi_64; + return 0; +} diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h index 01cc13c12059..165640f64b71 100644 --- a/arch/x86/boot/compressed/misc.h +++ b/arch/x86/boot/compressed/misc.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -176,4 +177,17 @@ void boot_stage2_vc(void); unsigned long sev_verify_cbit(unsigned long cr3); +#ifdef CONFIG_EFI +/* helpers for early EFI config table access */ +int efi_get_system_table(struct boot_params *boot_params, + unsigned long *sys_tbl_pa, bool *is_efi_64); +#else +static inline int +efi_get_system_table(struct boot_params *boot_params, + unsigned long *sys_tbl_pa, bool *is_efi_64) +{ + return -ENOENT; +} +#endif /* CONFIG_EFI */ + #endif /* BOOT_COMPRESSED_MISC_H */