Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1527461pxb; Thu, 4 Feb 2021 15:47:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJyfRYmqUltDu9sc3C4syhhIwQNB0ROWhwvfhoIkePmae7PJpHeURBJboDAnS9MKO9UtxS1i X-Received: by 2002:aa7:dd12:: with SMTP id i18mr987871edv.36.1612482439804; Thu, 04 Feb 2021 15:47:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612482439; cv=none; d=google.com; s=arc-20160816; b=MulqikpUdbxZdEDfzyTEvvJ3yejvYTdQ9EQUpeD4Ng+uVWkRsZWKx0fOXY1e/SR5Si 0cUVNQ+CZmTRJDob8BpHsA+coL35Fk6vdOoqAhq2SfyHR0MOC7UNvRLmgyrpAjPJU3Uq x7/MRGE+l/fASRUvK7oTT0XR/Xs04YsZ3f+ogC4/SvFWGjUUouq96Mj58LKv45nN//Wf DG5EFcu8exVEYq4Cauz8XIFLuFs0AZLSKzxZw1hQz0lAKxAyNaHL4QXYxwjHpJEr96uz 8ARiWZEhZdCyLYwE6ySYIBMk/tD4FxOZT8QcIfFCAVpLZyfreO9BZbCStM+Gny/rAxUv pF+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=UXUD6EWR/qgE8rG662QIKhDzNr1MtWDENMPpkds4F9k=; b=W6qYDmHWUaXMEzYdTIeMvLeoOSIq7ciipZc947AK+gMfn5VEw5dxULiVLaTElOiGvB Y6+HcWI3g7SSjZhwNcjz6Ui4L6NR3C62gECoISW9A1Y+w5P1KljY0ZDClfXZOdINZNCy CjeGodokXL6bGfhWMoOXo6VQ8uoJj0c1PWdE2dg+UBFG23Q37T33IXTdCOTDSzZrzi4l w9fEvgguHQSMPhAmpYt+OzREC+56rl2064xlja/aJWDkJEY09CRCa+thaCneyBgSL46e 6V+u2O+hNWNGyOH+DkMwJz62iTZtVJqME6ye40FS48AIypCI8ctU8t0By6wBxXgeIbQ2 0+aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JAA4iEQs; 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 u6si4218316ejg.478.2021.02.04.15.46.55; Thu, 04 Feb 2021 15:47:19 -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=JAA4iEQs; 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 S235512AbhBDLAD (ORCPT + 99 others); Thu, 4 Feb 2021 06:00:03 -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-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