From patchwork Fri Jan 28 17:17:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 12728795 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A927C433F5 for ; Fri, 28 Jan 2022 17:19:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D77C6B00EE; Fri, 28 Jan 2022 12:19:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 660826B00F0; Fri, 28 Jan 2022 12:19:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 43F686B00EE; Fri, 28 Jan 2022 12:19:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay026.a.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 1BA688D0002 for ; Fri, 28 Jan 2022 12:19:07 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id C99A6604D7 for ; Fri, 28 Jan 2022 17:19:06 +0000 (UTC) X-FDA: 79080356292.03.B8618CD Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2059.outbound.protection.outlook.com [40.107.92.59]) by imf23.hostedemail.com (Postfix) with ESMTP id CADF3140004 for ; Fri, 28 Jan 2022 17:19:05 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dLimwxID5SwIcNyfYFlTbrpnESEkGyZWxQrkmRWEuAzkd2CPI3umB8wSe6VtCrmpTEgH2yCM6YzS9zWUWbw1XeqFV4O4Gw6XzjyVIIgQznsLNo06GHsG4JnUx3dToJqHLQGNRdHLLe8aKRgwLlJPwKNIVHbVFdrzN16P6/RzCZiarbYzepznpurViaeTuwFUxKmHDaK4KNFx2ZCHAvj6/FotcPskwiQEHBZZ8K7tboaHVKYd6HoyyIGdzmRfqbQYCvHlyF2kdlAsY51VATPDrO/mm4UzjTQ1YvO2TwaAyVYlTi0kJBXQ4cy3We6CgKflIaDkixsSxbKjlYckFFzZiw== 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=wwB4aO1Uz5ZwL0Cy0hXWcHM1BKnthZM2OnL7UBWdnzo=; b=a+mcwy7sEWoQta+N0FoqYEGr0mnjZZAUY7Rmfj2TmLJILvXXjrhhCXwvQqtdLTsgqpsZu1vSM+Bwa+c43AIHxshF9R4SzWSq1WV5xw1Q+oq5enlH3m0Fk06UD6lPKH+2XY0F2PxB+DQulckRYRh+Hj2zXj78C61uH98RNGyHT6O2OVxpGGEWjkRjPXGrbxvjmc85iEYPxlghh653wTdV35J+d92xMQf+gfYJH/IzznWwrBJcUM32npH7uIiKCu2pnIIU2jFCAyoSwnSUIT63PLdp4OkRRhh4y8cNzzw1wjM40fyLGn4MFw7OQpGnJCL1VNaPVhb2Wa9pD6d8Dz83nQ== 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=wwB4aO1Uz5ZwL0Cy0hXWcHM1BKnthZM2OnL7UBWdnzo=; b=YHjVMzs8CVOJcO+EwtYyX4PlveofhhmB+D+LRxTMid5a3H6QH3j1oX/a3ZP+lT6Xb9CpddTapWgb3Y8gYUdp/czBUof5zplvlY0ODRqXWgH41/My5FQgrjqHQv0k7p+CY0zssDPBxUySOGTmmRg80fZuBO0j6BlE88t0G/6Pv48= Received: from DS7PR03CA0320.namprd03.prod.outlook.com (2603:10b6:8:2b::15) by MWHPR1201MB2527.namprd12.prod.outlook.com (2603:10b6:300:df::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.12; Fri, 28 Jan 2022 17:19:02 +0000 Received: from DM6NAM11FT021.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2b:cafe::fc) by DS7PR03CA0320.outlook.office365.com (2603:10b6:8:2b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15 via Frontend Transport; Fri, 28 Jan 2022 17:19:02 +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 DM6NAM11FT021.mail.protection.outlook.com (10.13.173.76) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4930.15 via Frontend Transport; Fri, 28 Jan 2022 17:19:02 +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.18; Fri, 28 Jan 2022 11:19:00 -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 v9 26/43] x86/compressed/acpi: Move EFI config table lookup to helper Date: Fri, 28 Jan 2022 11:17:47 -0600 Message-ID: <20220128171804.569796-27-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220128171804.569796-1-brijesh.singh@amd.com> References: <20220128171804.569796-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: d1e285ec-7178-4628-08d7-08d9e2824797 X-MS-TrafficTypeDiagnostic: MWHPR1201MB2527:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uH1XLmIaiHaPQBc68YsQqNUuoFsJBA74XWadIQiGBdZ3v2vGpvf//Z4FzWnpOE5a6lBM2PaHJJRBK1zpxPT2TltwkN/1/4utBuKNtOJF2JwJ9A8PCHeMswPLB+ah3NeWrgz6bsPEuWlm7PcswUQQEf+ctSD4S90WqCdxxhxxys8KqkEH360RDJwdc8SvZxKBo9npJBDBGN4I9AVOUHELujmOexkyyDCES8mrF4Ml2EXesz4pazj/zmd+Es4Vict04TQ8CEOcee+Frrc792eOMsWxH2XyVndFAkJ+7NAnRIVNrd5bpSYEVmP6I5+Ymkcr/P81MXbLszlsFTyQtJnD4av3g3Nu/a61MU1XIVMJxgKSv/LwT1XjQsuiPgqBBKW3EQWZUrJYipV/3jRm82/Y7wtJHYI1e28gF2x+RBiBtUJwHBg2WGERP9z8LpJdQnxJbk6h3Z4HZiZousSe3qDEqWh9leh1xxTd6KR7Tac3BIH2PpHlupUMOUn6fzugyfFOd4Ld8C6934m09ylzbTOKc+80ufMkm8LK74Lf5MFDTPuL/iYMhAzxOHgnPjxaOwLdW600UqWzoxZDBSSaYttW79Bu9j4hBdwxFhzlpotzTF6j2e88vndJQ72JDOSKdarIypF8SXp6ovl2h3QrGI2OX6EOtdFeyCsyo1bZruZeRskrIAvj+qJTbPAes5YN1tEfU+rlYPZbkH3m5CkuE9RbjxMHprxwyVzcXzxOQ3eN1/3p46b/dlpSxDalPAJu2oWtutLJDzTd9GSDMyC1SSg4W1dYjzGNQsoQypwYjxJyZ3ze9R2Egg8IFDrD5xDAobgE 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)(40470700004)(46966006)(36840700001)(83380400001)(8936002)(70586007)(5660300002)(2616005)(86362001)(508600001)(40460700003)(7696005)(426003)(47076005)(316002)(1076003)(36860700001)(8676002)(81166007)(4326008)(7406005)(44832011)(6666004)(336012)(7416002)(16526019)(82310400004)(186003)(356005)(110136005)(36756003)(26005)(54906003)(70206006)(2906002)(36900700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2022 17:19:02.3246 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d1e285ec-7178-4628-08d7-08d9e2824797 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: DM6NAM11FT021.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1201MB2527 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: CADF3140004 X-Stat-Signature: frrratbg9httyhk7c5rs78rjsi8nmfmr Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=YHjVMzs8; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf23.hostedemail.com: domain of brijesh.singh@amd.com designates 40.107.92.59 as permitted sender) smtp.mailfrom=brijesh.singh@amd.com X-Rspam-User: nil X-HE-Tag: 1643390345-125780 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/acpi.c | 25 ++++++------------ arch/x86/boot/compressed/efi.c | 45 +++++++++++++++++++++++++++++++++ arch/x86/boot/compressed/misc.h | 9 +++++++ 3 files changed, 62 insertions(+), 17 deletions(-) diff --git a/arch/x86/boot/compressed/acpi.c b/arch/x86/boot/compressed/acpi.c index 58a3d3f3e305..9a824af69961 100644 --- a/arch/x86/boot/compressed/acpi.c +++ b/arch/x86/boot/compressed/acpi.c @@ -118,10 +118,13 @@ 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_pa, config_tables; + unsigned long cfg_tbl_pa = 0; + unsigned int cfg_tbl_len; + unsigned long systab_pa; unsigned int nr_tables; enum efi_type et; bool efi_64; + int ret; et = efi_get_type(boot_params); if (et == EFI_TYPE_64) @@ -135,23 +138,11 @@ static acpi_physical_address efi_get_rsdp_addr(void) if (!systab_pa) 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_pa; - - config_tables = stbl->tables; - nr_tables = stbl->nr_tables; - } else { - efi_system_table_32_t *stbl = (efi_system_table_32_t *)systab_pa; - - config_tables = stbl->tables; - nr_tables = stbl->nr_tables; - } - - if (!config_tables) - error("EFI config tables not found."); + ret = efi_get_conf_table(boot_params, &cfg_tbl_pa, &cfg_tbl_len); + if (ret || !cfg_tbl_pa) + error("EFI config table not found."); - return __efi_get_rsdp_addr(config_tables, nr_tables, efi_64); + return __efi_get_rsdp_addr(cfg_tbl_pa, cfg_tbl_len, efi_64); #else return 0; #endif diff --git a/arch/x86/boot/compressed/efi.c b/arch/x86/boot/compressed/efi.c index bf99768cd229..feb00c6b4919 100644 --- a/arch/x86/boot/compressed/efi.c +++ b/arch/x86/boot/compressed/efi.c @@ -77,3 +77,48 @@ unsigned long efi_get_system_table(struct boot_params *boot_params) return sys_tbl_pa; } + +/** + * efi_get_conf_table - Given boot_params, locate EFI system table from it and + * return the physical address of EFI configuration table. + * + * @boot_params: pointer to boot_params + * @cfg_tbl_pa: location to store physical address of config table + * @cfg_tbl_len: location to store number of config table entries + * + * Return: 0 on success. On error, return params are left unchanged. + */ +int efi_get_conf_table(struct boot_params *boot_params, unsigned long *cfg_tbl_pa, + unsigned int *cfg_tbl_len) +{ + unsigned long sys_tbl_pa = 0; + enum efi_type et; + int ret; + + if (!cfg_tbl_pa || !cfg_tbl_len) + return -EINVAL; + + sys_tbl_pa = efi_get_system_table(boot_params); + if (!sys_tbl_pa) + return -EINVAL; + + /* Handle EFI bitness properly */ + et = efi_get_type(boot_params); + if (et == EFI_TYPE_64) { + efi_system_table_64_t *stbl = + (efi_system_table_64_t *)sys_tbl_pa; + + *cfg_tbl_pa = stbl->tables; + *cfg_tbl_len = stbl->nr_tables; + } else if (et == EFI_TYPE_32) { + efi_system_table_32_t *stbl = + (efi_system_table_32_t *)sys_tbl_pa; + + *cfg_tbl_pa = stbl->tables; + *cfg_tbl_len = stbl->nr_tables; + } else { + return -EINVAL; + } + + return 0; +} diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h index 24522be8c21d..162dbd7443eb 100644 --- a/arch/x86/boot/compressed/misc.h +++ b/arch/x86/boot/compressed/misc.h @@ -186,6 +186,8 @@ enum efi_type { /* helpers for early EFI config table access */ enum efi_type efi_get_type(struct boot_params *boot_params); unsigned long efi_get_system_table(struct boot_params *boot_params); +int efi_get_conf_table(struct boot_params *boot_params, unsigned long *cfg_tbl_pa, + unsigned int *cfg_tbl_len); #else static inline enum efi_type efi_get_type(struct boot_params *boot_params) { @@ -196,6 +198,13 @@ static inline unsigned long efi_get_system_table(struct boot_params *boot_params { return 0; } + +static inline int efi_get_conf_table(struct boot_params *boot_params, + unsigned long *cfg_tbl_pa, + unsigned int *cfg_tbl_len) +{ + return -ENOENT; +} #endif /* CONFIG_EFI */ #endif /* BOOT_COMPRESSED_MISC_H */