Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1585113pxb; Thu, 4 Feb 2021 17:40:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJz24lESn2RSHQHW2LJh+GleiZ/26nRJcpfrKguSr6DvljOl4z6YbrQleZTiZXao1kS44bdR X-Received: by 2002:a17:906:7d4f:: with SMTP id l15mr1747648ejp.95.1612489210970; Thu, 04 Feb 2021 17:40:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612489210; cv=none; d=google.com; s=arc-20160816; b=AXM4twOq3XBV2WTf9RsCZlbttoIm3Bt+sYWtdVA+KF4xr+CPdQ2bYwYM53Pi860nVi xzXPPryOytcvx5YWrrDFPWHjlYNJmINIcl/0nLgmHmjdJs6/pp1Fxw0Rn/GgPDGRr+rV K9ETlXAssHtyrOVtOqDVw4HMcuCnUAJxfvg2YWMX8ngVN64EV2f5uo1mfXtL8ASjoEDX wFbMsCePU6tovQaGckkcUB3Ew+zXH/yul7Abv+iVvmxOqFrGdxvKZzapdoxx0lqUrQwt IVKk20/JjiNgvpUuBpa4ng2ax+DtZpvLYwlzIooKj0HWphRO3Zv26nrksLwXIl5wqVEl 3mqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Q1f0Xc1X8UgZZWqiIMuWyB6AWmbTXpSLZVvTN+c1Bjk=; b=L4qY3f6C43Uq0EhMCr7DWcgOy0vqC3u5MmnxSpVrFTMdOD4wAcjhQdGLbU+YHxaooN GjtPyvxOFf5G0sADXhx/Ev618YwfsgQoNWDVyhuMbNe90Bn3mRMsu2PAUHBtYRp94Yk6 vpLEyVbAkwF94fpu4ALPCkOwAtB/U/tIPkmK5Uf5tBPA1uoEjLPAfFyN4wD4b7swt648 Y7XdZstp8Prrh5dZAKKZ1g+ERsMyID82qSJ/iv4CU+c+OO69OUMjaVpDFvWoCGl43XUw MgeSPIX2cW5aky17YmqCmVeRqSYHkePqirCTb7znpK5eloxCcFzEPXP8y2+LVe+bzG2j nWjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KBQdU9Of; 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 v4si5389380edj.37.2021.02.04.17.39.46; Thu, 04 Feb 2021 17:40:10 -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=KBQdU9Of; 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 S239738AbhBDTRz (ORCPT + 99 others); Thu, 4 Feb 2021 14:17:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:52700 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239763AbhBDTRN (ORCPT ); Thu, 4 Feb 2021 14:17:13 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 18E0E64DF0; Thu, 4 Feb 2021 19:16:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612466192; bh=8S5BexxzoontSYmnpurHcAgfrHRcphSuCnzRExkPd30=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KBQdU9OfAeDFvPjximv/0NbVnU0DxHB1PLhQ16or8xmdZTZ87nHnQXFXmN3z5Yl0A W4HupY6kmmKxzcSXR8mVbo555bJ8ob6P+YQadMaR2ZzBc1MJKU0B54bmnSONqw3OoZ iEUixgEKA22YQrEegQ/Z6gR0Pz+z5Off1quJyrHnLzPpGBsFXztckjECDJsLiVQgD+ KImAtVJVC5UBzKmA3R4nACk2n+7PTeGH01KT4HjLQWZfNwFvKoR8FGZ8WEXTUqeIPe eMJbBbkj2Rd2I/ml7kl0MOMhJOabvlOigP1cXUjbVTdUf4ZJ18LJvlVKT/jKyqXBoT wWReByK6uWk8w== Date: Thu, 4 Feb 2021 12:16:28 -0700 From: Nathan Chancellor To: Borislav Petkov Cc: Ard Biesheuvel , Arvind Sankar , Arnd Bergmann , Thomas Gleixner , Ingo Molnar , X86 ML , Nathan Chancellor , Nick Desaulniers , Arnd Bergmann , Darren Hart , Andy Shevchenko , "H. Peter Anvin" , linux-efi , platform-driver-x86@vger.kernel.org, Linux Kernel Mailing List , clang-built-linux , "Kirill A. Shutemov" Subject: Re: [PATCH] x86: efi: avoid BUILD_BUG_ON() for non-constant p4d_index Message-ID: <20210204191628.GC2991903@localhost> References: <20210107223424.4135538-1-arnd@kernel.org> <20210118202409.GG30090@zn.tnic> <20210203185148.GA1711888@localhost> <20210204105155.GA32255@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210204105155.GA32255@zn.tnic> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 04, 2021 at 11:51:55AM +0100, Borislav Petkov wrote: > On Wed, Feb 03, 2021 at 09:29:18PM +0100, Ard Biesheuvel wrote: > > I think we have agreement on the approach but it is unclear who is > > going to write the patch. > > How's that below? > > And frankly, I'd even vote for removing those assertions altogether. If > somehow the EFI pgd lands somewhere else, the kernel will crash'n'burn > spectacularly and quickly so it's not like we won't catch it... > > --- This resolves the issue initially reported in this thread. Obviously removing the assertions will do that as well. Feel free to carry forward Tested-by: Nathan Chancellor on a patch if you send it out. > diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h > index 91ac10654570..b6be19c09841 100644 > --- a/arch/x86/include/asm/pgtable_64_types.h > +++ b/arch/x86/include/asm/pgtable_64_types.h > @@ -156,8 +156,8 @@ extern unsigned int ptrs_per_p4d; > #define CPU_ENTRY_AREA_PGD _AC(-4, UL) > #define CPU_ENTRY_AREA_BASE (CPU_ENTRY_AREA_PGD << P4D_SHIFT) > > -#define EFI_VA_START ( -4 * (_AC(1, UL) << 30)) > -#define EFI_VA_END (-68 * (_AC(1, UL) << 30)) > +#define EFI_VA_START ( -4UL * (_AC(1, UL) << 30)) > +#define EFI_VA_END (-68UL * (_AC(1, UL) << 30)) > > #define EARLY_DYNAMIC_PAGE_TABLES 64 > > diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c > index e1e8d4e3a213..56fdc0bbb554 100644 > --- a/arch/x86/platform/efi/efi_64.c > +++ b/arch/x86/platform/efi/efi_64.c > @@ -123,9 +123,7 @@ void efi_sync_low_kernel_mappings(void) > * only span a single PGD entry and that the entry also maps > * other important kernel regions. > */ > - MAYBE_BUILD_BUG_ON(pgd_index(EFI_VA_END) != pgd_index(MODULES_END)); > - MAYBE_BUILD_BUG_ON((EFI_VA_START & PGDIR_MASK) != > - (EFI_VA_END & PGDIR_MASK)); > + MAYBE_BUILD_BUG_ON((EFI_VA_START & PGDIR_MASK) != PGDIR_MASK); > > pgd_efi = efi_pgd + pgd_index(PAGE_OFFSET); > pgd_k = pgd_offset_k(PAGE_OFFSET); > @@ -137,8 +135,7 @@ void efi_sync_low_kernel_mappings(void) > * As with PGDs, we share all P4D entries apart from the one entry > * that covers the EFI runtime mapping space. > */ > - BUILD_BUG_ON(p4d_index(EFI_VA_END) != p4d_index(MODULES_END)); > - BUILD_BUG_ON((EFI_VA_START & P4D_MASK) != (EFI_VA_END & P4D_MASK)); > + BUILD_BUG_ON((EFI_VA_START & P4D_MASK) != P4D_MASK); > > pgd_efi = efi_pgd + pgd_index(EFI_VA_END); > pgd_k = pgd_offset_k(EFI_VA_END); > > > -- > Regards/Gruss, > Boris. > > https://people.kernel.org/tglx/notes-about-netiquette