Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1887558pxb; Fri, 5 Feb 2021 04:06:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzs7Q5anNC0FuhFm3otfC04nvYOvuCphV7lgOEyUXtMTz40uLmXXxsGriLACtS+4/7iKHHV X-Received: by 2002:a17:906:c448:: with SMTP id ck8mr3768250ejb.55.1612526786808; Fri, 05 Feb 2021 04:06:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612526786; cv=none; d=google.com; s=arc-20160816; b=l4q4OHxR5cffjkozSlAXfP+q/C/TjeJnXACJEziJwktuhyLjjpCcGdYzjyfnYwxhb6 izvB0PRZtEE/wSQGS4V9jSV8n1ASZ2BO+jHqWMDD2zrsmRVCNxuaDnfk0gDxdbglZ6L7 GacMxau5B8NQr/Z0cj/346+Q3np69lZv4L7XGHqMgdEcKWkQEjXhuo8aA+RRl+iVyym0 Z4ddJKtpY935zTsEOIjyXrc9rnAa+PIScafQ6uEesbJhFygkHn/JflD2ie3bDSZMGOGQ xFVKkksYfGBDUfCs/gLHTvKZ2LNPwLBPVCLeLyFddW1phaM0cLVmnbBzEbGuMTwCvCtP 8hcw== 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=SOiwW8I/hsVjC8fyD3u4ss/tHAk9Sz4OtjmJvEU2W5U=; b=U8/Y3E57iGzA433hOUkYfSvJ/5CdtlGh1r2f9RV9UTwI8RcLBw3IDXwZTHViImQyZR KZOD/J2xuasrRyUbIkSatF0FJPwXIHSbQ/Thawt5oDBzXrxgX3VdHCSK5PZa2BxZSpsq gFOwbSTpZ9nT8H7abWohxLm/c1/CP/khNcLONbThz5COdIDx/Mk9gFlfFCiifYVN4QeV XELd+M5s2bmJCfOlI5mdxndiiGNYglt/iTQLvVyUxzAEgji64eB/b+RdhK3iglBr50zg v16CmZshvdVWttVlag20l/wkMLfdPb1cim4/9cEJHrtHgsfHGTwHbRdGZT5C6lUHX19Q QBkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eglJi6jj; 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 i13si1976984eje.417.2021.02.05.04.05.47; Fri, 05 Feb 2021 04:06:26 -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=eglJi6jj; 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 S232004AbhBEMBt (ORCPT + 99 others); Fri, 5 Feb 2021 07:01:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:36698 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232047AbhBEL6c (ORCPT ); Fri, 5 Feb 2021 06:58:32 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0C1B964FD0; Fri, 5 Feb 2021 11:57:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612526271; bh=U9so/rHyR0hVc2xX6oY2l2vg5J61lAZH93MEbQPViNE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=eglJi6jjeEmj9f+pc/aEPV2ah17Yn/ZUE8jr61fZIMavlMHKFbw/701G3R9gnxqus sdPX49nlbeCYFlHHRkWzB9+Plfqnaxon83sb6WgDWX0npsQRaDn1Bkl/DZYK0wHtnL ckluspV5lBz6/SkyYDfeBroj4vYEpgjNJTQlDvpkcP4S7vQ2zmXLSmP/ZqZb6t/4YX fGwdCxwTCoWe7lEOC7V/EogPqeENVKIutiaUZoOPwwQZoE05BUELOCQHVs5LfN73Nd inI/TVzxAuLiKR3nJEi7MthQhZOqzVUoxspFm596bXlH/zE2lTFQuXXYegbYqCk6c3 pCWuDyBexhV1g== Received: by mail-oi1-f179.google.com with SMTP id j25so7181111oii.0; Fri, 05 Feb 2021 03:57:50 -0800 (PST) X-Gm-Message-State: AOAM530ENH4y0fD9UFNh3n8fAxguAqwg3JjMNGMyV3jSJD6MpfIv6I9S T0kyiXAjbsHp2UNbsk9XCcCCbvBIUpffsCkbB/A= X-Received: by 2002:aca:ea0b:: with SMTP id i11mr2772699oih.33.1612526270014; Fri, 05 Feb 2021 03:57:50 -0800 (PST) MIME-Version: 1.0 References: <20210118202409.GG30090@zn.tnic> <20210203185148.GA1711888@localhost> <20210204105155.GA32255@zn.tnic> <20210204221318.GI32255@zn.tnic> <20210205113930.GD17488@zn.tnic> In-Reply-To: <20210205113930.GD17488@zn.tnic> From: Ard Biesheuvel Date: Fri, 5 Feb 2021 12:57:38 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] x86/efi: Remove EFI PGD build time checks To: Borislav Petkov Cc: Arvind Sankar , Nathan Chancellor , 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 Fri, 5 Feb 2021 at 12:39, Borislav Petkov wrote: > > From: Borislav Petkov > > With CONFIG_X86_5LEVEL, CONFIG_UBSAN and CONFIG_UBSAN_UNSIGNED_OVERFLOW > enabled, clang fails the build with > > x86_64-linux-ld: arch/x86/platform/efi/efi_64.o: in function `efi_sync_low_kernel_mappings': > efi_64.c:(.text+0x22c): undefined reference to `__compiletime_assert_354' > > which happens due to -fsanitize=unsigned-integer-overflow being enabled: > > -fsanitize=unsigned-integer-overflow: Unsigned integer overflow, where > the result of an unsigned integer computation cannot be represented > in its type. Unlike signed integer overflow, this is not undefined > behavior, but it is often unintentional. This sanitizer does not check > for lossy implicit conversions performed before such a computation > (see -fsanitize=implicit-conversion). > > and that fires when the (intentional) EFI_VA_START/END defines overflow > an unsigned long, leading to the assertion expressions not getting > optimized away (on GCC they do)... > > However, those checks are superfluous: the runtime services mapping > code already makes sure the ranges don't overshoot EFI_VA_END as the > EFI mapping range is hardcoded. On each runtime services call, it is > switched to the EFI-specific PGD and even if mappings manage to escape > that last PGD, this won't remain unnoticed for long. > > So rip them out. > > See https://github.com/ClangBuiltLinux/linux/issues/256 for more info. > > Reported-by: Arnd Bergmann > Link: http://lkml.kernel.org/r/20210107223424.4135538-1-arnd@kernel.org > Signed-off-by: Borislav Petkov Acked-by: Ard Biesheuvel > --- > arch/x86/platform/efi/efi_64.c | 19 ------------------- > 1 file changed, 19 deletions(-) > > diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c > index e1e8d4e3a213..8efd003540ca 100644 > --- a/arch/x86/platform/efi/efi_64.c > +++ b/arch/x86/platform/efi/efi_64.c > @@ -115,31 +115,12 @@ void efi_sync_low_kernel_mappings(void) > pud_t *pud_k, *pud_efi; > pgd_t *efi_pgd = efi_mm.pgd; > > - /* > - * We can share all PGD entries apart from the one entry that > - * covers the EFI runtime mapping space. > - * > - * Make sure the EFI runtime region mappings are guaranteed to > - * 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)); > - > pgd_efi = efi_pgd + pgd_index(PAGE_OFFSET); > pgd_k = pgd_offset_k(PAGE_OFFSET); > > num_entries = pgd_index(EFI_VA_END) - pgd_index(PAGE_OFFSET); > memcpy(pgd_efi, pgd_k, sizeof(pgd_t) * num_entries); > > - /* > - * 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)); > - > pgd_efi = efi_pgd + pgd_index(EFI_VA_END); > pgd_k = pgd_offset_k(EFI_VA_END); > p4d_efi = p4d_offset(pgd_efi, 0); > -- > 2.29.2 > > -- > Regards/Gruss, > Boris. > > https://people.kernel.org/tglx/notes-about-netiquette