Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1012680pxb; Thu, 4 Feb 2021 02:55:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJzSfsRAXLuYIRKFd4dlfWEpMuyLRAXPJP0OuoaselJg2f91WD3IIRgi1g5lVZRRQGmzzIVP X-Received: by 2002:a50:fc06:: with SMTP id i6mr6765582edr.20.1612436137458; Thu, 04 Feb 2021 02:55:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612436137; cv=none; d=google.com; s=arc-20160816; b=W0DRS/kATZvTT0lUs/6RWg0bWXWXHCFSHhJMTVP9/yaCnTlXDVaMkVexkQtCcrn41k kAI4PCInEYhA+emf0lgmrJqe9zQAQxWF+DsO2ejlr1dS8M7TmVb1uIgqv2oupw1ycgvK KQ2MLWSlSwhae2Cguui6no84Ty0Ua91kryKBLTiLCT8wx5LuKvUC6NYgXL1S958RHHgh v8Cv90rwFgFDHEhDM6gftzFuLNJEgGQXeCp8ACqNDd96PR5GEKLeONcsPsXWKh1nj4tU WVtTZa9rCGROk5dwz/7AmTHDUE5m0NaB86QPI5qxiKM7eYjiULxxuuOXFYqGqFtPMGtP Rn3A== 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=x+q7M5BysVCq0z73BCA5GL6K1zhxLeh9Ep6YuQ1rvpw=; b=YOwY30DwuLdanz025o6hRIz8QDuY+axHRPnT5UK9CwcjbINTvKJH/peWjyN+J80gle ppFZsoKYXlFZ7h2kTfOdF+aicx0fCa4yhoRlywkRO0BpG9NxNkmcjFHxBQH4uGtl2s0C OWy+ZQbXikhsQTQdJz6FG1VK7oig1xN4g66pWFaHa7Kq0liF87IR1Gx32DgBN4euGtRX hij4dhobetCX0q6htdHSHJSj+BszWrsIfe+RjRGuDUbf5fT6ptIcz4S01Plk9g2a4cEo JFZnwFgV9F28zmcHHahA0lNCAtj3YZ9M/kL0bvlaq82qbnRBw84QSDS6y3fcj79zTW+h hoQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=NkbeH0s9; 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=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x1si3019629eju.744.2021.02.04.02.55.11; Thu, 04 Feb 2021 02:55:37 -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=@alien8.de header.s=dkim header.b=NkbeH0s9; 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=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235507AbhBDKwq (ORCPT + 99 others); Thu, 4 Feb 2021 05:52:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234873AbhBDKwp (ORCPT ); Thu, 4 Feb 2021 05:52:45 -0500 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33233C061573; Thu, 4 Feb 2021 02:52:05 -0800 (PST) Received: from zn.tnic (p200300ec2f0c7e00dc348a22cc2c06fb.dip0.t-ipconnect.de [IPv6:2003:ec:2f0c:7e00:dc34:8a22:cc2c:6fb]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id A80071EC00F8; Thu, 4 Feb 2021 11:52:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1612435921; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=x+q7M5BysVCq0z73BCA5GL6K1zhxLeh9Ep6YuQ1rvpw=; b=NkbeH0s9FBLOV+Wse/Y6c3Vc6CDqAD5AEy6ZGsLflQepqjqCjWV3lxVgMi6lbhBpftYVew 9QtP+ljkKRefd9fZoY1dFln9/Q9e2nFNnzMC/0s/gZU154j1HyoOWlWHrCTQqsJfebf8Q9 FrVVybE3qHTptJdYnKQsjd6ae3frQgg= Date: Thu, 4 Feb 2021 11:51:55 +0100 From: Borislav Petkov To: Ard Biesheuvel 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" Subject: Re: [PATCH] x86: efi: avoid BUILD_BUG_ON() for non-constant p4d_index Message-ID: <20210204105155.GA32255@zn.tnic> References: <20210107223424.4135538-1-arnd@kernel.org> <20210118202409.GG30090@zn.tnic> <20210203185148.GA1711888@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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... --- 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