From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60DDDC433E0 for ; Thu, 4 Feb 2021 11:00:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F162264F5E for ; Thu, 4 Feb 2021 11:00:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235520AbhBDLAF (ORCPT ); Thu, 4 Feb 2021 06:00:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:56080 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235451AbhBDLAB (ORCPT ); Thu, 4 Feb 2021 06:00:01 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A304364F78; Thu, 4 Feb 2021 10:59:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612436360; bh=TcXVmu+fm+5dg4n7lQxBdH6RO7TzX9jei0B4wo/LbuY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=JAA4iEQsYiPxU9pe1NjJZP4Ks2SZh9HQ0pJyFaJCegO6NXbLJqJrVaemxy2FGUnjw jsm+06QyRthDyIU2kL4jPmQky5QfBsvDZqjDuM+zubQ7voyOM72AuMXw0gFOUGBmUt 3TdXLyGd1zdS+U9YrpTEkFRyhINUu8CtcY+6eUAoKYxRoKTEvVVqwoic27LXCiwV/R ILPJ0u+/jldIcgqr1OPgpNETE1bW+HIDDoKJDKAR5c0AjHoVbPiPmCQVETDIFX8iAN 2/SUAxvaqcE9ahiMEpfU+teKtziSeNOCgIv8V20Evqm1fTCpwfGM70QvGH2aFGc5Mg TJh7esj9OaDWA== Received: by mail-oi1-f172.google.com with SMTP id k142so3251037oib.7; Thu, 04 Feb 2021 02:59:20 -0800 (PST) X-Gm-Message-State: AOAM530JUCqP4nr9aPiCzOczMPg9fi0mQu6jcVsFFfvhkPXMrGzoY1jC 1sLqp3ixqE/3zED8DoYDiL7CUcYoQ9JwalC+rZM= X-Google-Smtp-Source: ABdhPJxxoDZ9P85GGLeXQpSikdoj66A14Va5HEghinCcn8haB0ubF4ZEW3ly1sI8Xqq8qm1KRLA+a+bG6w67KbW+XJw= X-Received: by 2002:aca:b6c1:: with SMTP id g184mr4797190oif.47.1612436359805; Thu, 04 Feb 2021 02:59:19 -0800 (PST) MIME-Version: 1.0 References: <20210107223424.4135538-1-arnd@kernel.org> <20210118202409.GG30090@zn.tnic> <20210203185148.GA1711888@localhost> <20210204105155.GA32255@zn.tnic> In-Reply-To: <20210204105155.GA32255@zn.tnic> From: Ard Biesheuvel Date: Thu, 4 Feb 2021 11:59:08 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] x86: efi: avoid BUILD_BUG_ON() for non-constant p4d_index To: Borislav Petkov Cc: Nathan Chancellor , 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" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 4 Feb 2021 at 11:52, 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... > +1 for just removing them > --- > 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