Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6868651rwr; Tue, 2 May 2023 06:40:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Ibb9QjWv4wQgDtPr7Hpz4DvrWxYDVt2RZtPqx5vS+U5e9mdmeWtuIk6CtSGUGnrU089KB X-Received: by 2002:a05:6a21:33a6:b0:f2:791f:7ce1 with SMTP id yy38-20020a056a2133a600b000f2791f7ce1mr21788307pzb.44.1683034839033; Tue, 02 May 2023 06:40:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683034839; cv=pass; d=google.com; s=arc-20160816; b=F0aHC3QoRSMJNQBq6OgPdA+2GNQBWxXpUtlzTSgVzMKwpBPGf7sNnLmPctYXtnVU/E C9lFZ/f1j1xvpX8P6hFaDvkBahm+7Nky/5ou68g1F0QUof880Fz6KRzmnOXSY+zSxBQY PuEAwwsoPTsnofjGyV0BAqKo7VEGB+ikzpOMp5pGvHtqJIHNshTKFMbirFsNRAYs1OvS WJL8nhyFan8lspalZqGT47jUB4in5SyiEF/kVfJmf06lPaferYfzp7bJ55OvLyUgPU7g VnDiblL7UGwC2Z2ethf16AzYRbC0iGV3evS8bCm7e7iWCslGPrhR2ea8WB4nkBINX1Sb E4tA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=9IS6///L7nhOx7hiWygU45Z1hpjnZGi2cAc41nvUb2A=; b=ejpeJY/R2EL6ckHTNc4Pp0TOQlCezFIpGjUKbbcvtAUapRDqyzAgnmfdyvy6yJIjSF 0+pxsfcXeuXjQMTg9caAUJ2x/xuiSoaBxhm4P9VmVhY4DoLQitq34Y9vEWVSanMFGKgf 2fax1i5K//wOlflluSZE8ad9QGM1hBVqOyhi1ef8r8y1yRw83Zb5QOq5GeypM7sUP3oL SZuLygoN8Mkmf2h00CkD718lEsumKFBVBSlJ2Cuv/xZShUn2lem6BbMpBg/E0eoPcy/y Jlb+dAdXvM6CgZzQ2ihFPipR9DWWIXDkdkVLdH8mmMgdqL51lIpqsJ0Mkj7RdN3s66xc 5nxA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=v9ZVdh87; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k64-20020a632443000000b0051b47fe799fsi29370458pgk.557.2023.05.02.06.40.26; Tue, 02 May 2023 06:40:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=v9ZVdh87; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234374AbjEBNid (ORCPT + 99 others); Tue, 2 May 2023 09:38:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234367AbjEBNiI (ORCPT ); Tue, 2 May 2023 09:38:08 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2057.outbound.protection.outlook.com [40.107.92.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E062F6EB2; Tue, 2 May 2023 06:37:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AJXpbakFV4M+jQqqOaAJti+ut5g+kep6sAMPEf8p0VAEwO89PAN7gzrFOiZVN+aPu6NPHsxuLfrAnJpnygaAi5YACKeQshHXNeJJr3ykrRHFrWujWUfQoIQBfByK5/toRBkeGHDAXBUn6FaDNkdkxxUoBazFHiZH5eZycSZX9IXMqraLxtt1vz6Y/wC6fI4FlIahC2ymDEyhdQLSEUB2Sf4ZsDD98SAEYypoPYJB3XDaVCeZWJ70FWzqhrCIt/wiHbIscCn8kIcW/iJ23KizNOx1DCd5BpxbS8N9mWKFhFa2uqfJnLTqIH0FfS8n76+2DXnn7A9AWKOj1RVxxWCaOQ== 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=9IS6///L7nhOx7hiWygU45Z1hpjnZGi2cAc41nvUb2A=; b=Xd04jETmcTzzOLNJZm7TZYMfkLA79udqGwF09tPfmjItjvGgYv9xVy1WxnKml4F2Yl/Li5YF62k7QQcGSuhaUOlWiFrSxcSe3wlQ+luf3faYsQO5E0tzVlO3HnMsQXTT9PMU2hq+4cyNkmcfAX/K/0wInDR0BESgJyweznIzX8N7nYkCVN4qrosOLD7tH3dOC4DmbRHjMLNYIhPQ3DtNGeArb7cFD1zquBwNDNiKiBqbAv3h5rV13pzfqonE5IhIE7/gO+983QZCJSxXtpEAo0tM3KIiU7ZUB5S7A+jObnDylLXl0efidTfHmNobCZITt5cI05mkLRjn1ORVqNsG1g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=9IS6///L7nhOx7hiWygU45Z1hpjnZGi2cAc41nvUb2A=; b=v9ZVdh87Uov3lDUiONUAgKYxw1GHXgk5p4jV3t2z3zMY376fzZnREWNmQhuDj2ELPLfMLniFIxGsR7ODXPPgscpSbdA5GC/YpLJepG5lEjdDv7wQUvAOUpyrWKe/SWsueUeY0A/6uiXsnjMAR7JdlNaxN5uWd0VK24He4gfjRQY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) by CH0PR12MB5172.namprd12.prod.outlook.com (2603:10b6:610:bb::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Tue, 2 May 2023 13:37:19 +0000 Received: from DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::ea32:baf8:cc85:9648]) by DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::ea32:baf8:cc85:9648%7]) with mapi id 15.20.6340.031; Tue, 2 May 2023 13:37:19 +0000 Message-ID: Date: Tue, 2 May 2023 08:37:16 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH 0/6] efi/x86: Avoid legacy decompressor during EFI boot Content-Language: en-US To: Ard Biesheuvel , linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Evgeniy Baskov , Borislav Petkov , Andy Lutomirski , Dave Hansen , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexey Khoroshilov , Peter Jones , Gerd Hoffmann , Dave Young , Mario Limonciello , Kees Cook , "Kirill A . Shutemov" , Linus Torvalds References: <20230424165726.2245548-1-ardb@kernel.org> From: Tom Lendacky In-Reply-To: <20230424165726.2245548-1-ardb@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: BLAPR03CA0064.namprd03.prod.outlook.com (2603:10b6:208:329::9) To DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR12MB5229:EE_|CH0PR12MB5172:EE_ X-MS-Office365-Filtering-Correlation-Id: 2c06cbbd-e25f-41bc-06ab-08db4b1259f8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: atz/mFCvNoLUnGFCFWPGhswsy5MuGvZUQbsswaK/de8DGSK80degqPVArCK3XjWCHLO9kic8anJ6RPPwLfPl1xYfsHUtEt9/b2QiADRTLOEBHpobcrOhzLQ6Owro//j4tZ7yQjEaKZ1EUH/C+/5XBxJHMdKnb3h4oyI1dSXZcBFhJyGIiyFn8oNAmzy390MGKnUB6nehQ+s8yBxbe8m/+u2ys8aK+vd9/Lr5htXDKH9F1ARm/zflZXrZE3nW/wnnX+lno4U3Bv28LZBEJyo1UXOEp2FpCRUjwvb6CgHV5Axo3CPO1s/YfHPgdwa5OBTEEhLfCRhScif56+jsFbiQgOEFv6KgX6kmF4Dhq/sw547FAPt4lC3vkQD8WwhAH11rA8ACcmM8LYd0BeHmqSb9AsMbGDl6SXEqZCi/MkPM1IYMetkwux11/K8ESJEuPt+nLpAVl/rBJPzrVT9cqDBTLHVfmt6MLRxlCrrslkmKMUv158O5ovmwSKRSSzBg0fD2Ri1ROExoAZKfqWSWjxvzfTda5CR5B487m/C8Iwb8+wFG/SVn15oKVNrV3znk2xPwuhj08zZi1GHI0VM53UcqOBGgbEVufSvOSBUMkwwtEDKCa6CVJvV93p8gd6lglPIzw9dxOlvFxv//uYdfv+KaB4/LD1pDK2wrYxUvos5J77G7PoeceYYtkpTvu7D4t6aw X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR12MB5229.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(376002)(346002)(39860400002)(366004)(136003)(451199021)(6666004)(6486002)(83380400001)(31696002)(6512007)(6506007)(26005)(53546011)(966005)(186003)(54906003)(2616005)(31686004)(36756003)(478600001)(4326008)(66476007)(66946007)(66556008)(316002)(38100700002)(8936002)(8676002)(5660300002)(41300700001)(86362001)(7416002)(2906002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?UXRORGlOVmptaDhubTZkZzVYTW16a28wdkcwVEs4ZXhlRG45dktTMjF6ZFpr?= =?utf-8?B?Y0R6M0RxM0NjbEoreCsxWXJzbEp2T0FXOU45elhLaWdOL256VVkvNzdkeEVp?= =?utf-8?B?cStuRVJvUUY0U0h0QWdiQ3phMi9kT05Fa1d1RlpkdllZWmtvZ2RUSXV5UWU5?= =?utf-8?B?OTRzd0szekVsZEJTQWt5Tm1DaGZOZVJEdytYWjArQ2Rnd0Y5TDZKUUNhdGNl?= =?utf-8?B?ai8xZzBGelNMS1JnK3RpdEhuQ0tBOXM1S1ROOTJkTjRONDByeEhoaU1JRFFh?= =?utf-8?B?MURpOHZFM28wdHB0Y1BYQXNzaDBzSEFTSkQ1TUxJdEQvQW5aSkUxUjI0V29y?= =?utf-8?B?elJFaTdobUVJM2IvQmcyemNxd3drc1VZNkN1RTFaZUhieEFJN1RiK3N6T2NG?= =?utf-8?B?STZsTVF0ejFyZ3pveXc3dFpDQ3BKRHZKWmlVQ2tvaDhRTUxRM1h4SlNLNDBm?= =?utf-8?B?T2did2kxYnh6SH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djlsaDlVcnMzT1ZyVG0zTHAvRXFYRnMwMUZjV295ZTBDc1lr?= =?utf-8?B?ckE2S3RBVTRzN210RlExV1hNRGJZMndxNHlWRXhlU0RGLzVTNjI0NHBNeVRn?= =?utf-8?B?VThpb29oQUZZanZiTFZ6Q096SjRvU0MvU2pIOXpuWkxWclBWTjI2SU93dFB6?= =?utf-8?B?UFdnTTdaWmQydXdoY2ZaR3NsWEhkZ0t1N29ZaWtpc1JkcVF1b0xlaDJuQmhw?= =?utf-8?B?ZGp6N3dtWkV3R3ZiR1lTYVMrSVc3a3JKelFxbWxxemF3dnBzaytoOWJuaFZ2?= =?utf-8?B?S2hOT2VxYVZvVHpPVGFJcGhsTHFsQ0xJVHRBcU1qdmk1REVGeURQaDhhY1BJ?= =?utf-8?B?bVB5ekIxUGhEN2NCLzJ0TmxxeW1KNFRTb1NXbytkenJVdE5sVjhNckxacVlB?= =?utf-8?B?b3FwZUc5WW1lTlYxRGJyWm5ZZGgydDdmK0kwN3JXV2RYNmZVRTZVdUlCNG8x?= =?utf-8?B?ZXd6WVhzTVdjV3k0QTZGMEdWY08xM3JIL0Y1ZFZNQ3ZVV1VDNVFMYWpveUky?= =?utf-8?B?Yjd6ZC92WnlWUUUyeHR3eHZXbUlJd3h4UjV1dVhXL3VrdkdjbWlMV3k2dzFn?= =?utf-8?B?c0sybEUwdWQ3aXVkTzFsL2hMQW1nNHY3eGtmQThjdU1BbFFiVnRaUEo1eitm?= =?utf-8?B?WGNXcjBxTkY4aWtNUHZMaDFzbHVKcVNkU3FqcTR6SFJ4eWtXTnhBR3YzSW5z?= =?utf-8?Q?M6yclbo9TLE/yZGcpgkhzFMBA?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2c06cbbd-e25f-41bc-06ab-08db4b1259f8 X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5229.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 13:37:19.5850 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Hr8nWr9houjn9Eom5AN97my7O95nvJ+J0CiR79nG1BjhfX2ewj82ejwcd+seBn7NYhH/FDsu2dMUjqXDNhBYaA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5172 X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/24/23 11:57, Ard Biesheuvel wrote: > This series is conceptually a combination of Evgeny's series [0] and > mine [1], both of which attempt to make the early decompressor code more > amenable to executing in the EFI environment with stricter handling of > memory permissions. > > My series [1] implemented zboot for x86, by getting rid of the entire > x86 decompressor, and replacing it with existing EFI code that does the > same but in a generic way. The downside of this is that only EFI boot is > supported, making it unviable for distros, which need to support BIOS > boot and hybrid EFI boot modes that omit the EFI stub. > > Evgeny's series [0] adapted the entire decompressor code flow to allow > it to execute in the EFI context as well as the bare metal context, and > this involves changes to the 1:1 mapping code and the page fault > handlers etc, none of which are really needed when doing EFI boot in the > first place. > > So this series attempts to occupy the middle ground here: it makes > minimal changes to the existing decompressor so some of it can be called > from the EFI stub. Then, it reimplements the EFI boot flow to decompress > the kernel and boot it directly, without relying on the trampoline code, > page table code or page fault handling code. This allows us to get rid > of quite a bit of unsavory EFI stub code, and replace it with two clear > invocations of the EFI firmware APIs to clear NX restrictions from > allocations that have been populated with executable code. > > The only code that is being reused is the decompression library itself, > along with the minimal ELF parsing that is required to copy the ELF > segments in place, and the relocation processing that fixes up absolute > symbol references to refer to the correct virtual addresses. > > Note that some of Evgeny's changes to clean up the PE/COFF header > generation will still be needed, but I've omitted those here for > brevity. I tried booting an SEV and an SEV-ES guest using this and both failed to boot: EFI stub: WARNING: Decompression failed: Out of memory while allocating z_stream I'll have to take a closer look as to why, but it might be a couple of days before I can get to it. Thanks, Tom > > Cc: Evgeniy Baskov > Cc: Borislav Petkov > Cc: Andy Lutomirski > Cc: Dave Hansen > Cc: Ingo Molnar > Cc: Peter Zijlstra > Cc: Thomas Gleixner > Cc: Alexey Khoroshilov > Cc: Peter Jones > Cc: Gerd Hoffmann > Cc: Dave Young > Cc: Mario Limonciello > Cc: Kees Cook > Cc: Tom Lendacky > Cc: Kirill A. Shutemov > Cc: Linus Torvalds > > [0] https://lore.kernel.org/all/cover.1678785672.git.baskov@ispras.ru/ > [1] https://lore.kernel.org/all/20230416120729.2470762-1-ardb@kernel.org/ > > Ard Biesheuvel (6): > x86: decompressor: Move global symbol references to C code > x86: decompressor: Factor out kernel decompression and relocation > x86: efistub: Obtain ACPI RSDP address while running in the stub > x86: efistub: Perform 4/5 level paging switch from the stub > x86: efistub: Prefer EFI memory attributes protocol over DXE services > x86: efistub: Avoid legacy decompressor when doing EFI boot > > arch/x86/boot/compressed/efi_mixed.S | 55 --- > arch/x86/boot/compressed/head_32.S | 24 -- > arch/x86/boot/compressed/head_64.S | 39 +-- > arch/x86/boot/compressed/misc.c | 44 ++- > arch/x86/include/asm/efi.h | 2 + > drivers/firmware/efi/libstub/efi-stub-helper.c | 4 + > drivers/firmware/efi/libstub/x86-stub.c | 360 +++++++++++++------- > 7 files changed, 279 insertions(+), 249 deletions(-) >