Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp219422pxb; Fri, 15 Jan 2021 11:12:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJwkqgYickpDpidekAIqd6Wq4Uslr46pQ8ZcxSeTtSMLH8XNr8BcT/8zQCmwyTeRzfo3aGo9 X-Received: by 2002:a17:906:c087:: with SMTP id f7mr10022585ejz.492.1610737942915; Fri, 15 Jan 2021 11:12:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610737942; cv=none; d=google.com; s=arc-20160816; b=OBBQhUT/a0Jz4LI7OldNBUn5ZG2lThClKATZF1gYm8NM0odOYQ8nnDDmKitPRZ94lj U1SUxx5FkF6+rVAcCLX6q/7NpQNtkn7L/i95R+YX/FQUzqEUotz3pn2N8Z3b/lh1uAfs xqxS39aXCEqedHB7Zl82c28/MlomhHbQAaKt6in0BLCOwQrRyOy4Na1flqdLpnu0qYOE 2eDOe/1nYY32FK9vZRLdzDAtYLc4Qakenjjy//OnoIZD8kOhnS15Cxp690YTZEoSDpDT 99j6j9swBElLeJnclAIlgh38XNeYtv2ctKIgJIOA0oC3IH7q7q/ClMua23Z3e14ez9Eo VnoA== 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:date:from:sender:dkim-signature; bh=6VFAEqW7kc3cIpTfEOGsqZWNF/6PRxbAffbJEVT5A/E=; b=fa/YpHYdJqerO4si0o+ZhO4eF7xTgNf1TQh3pFWDKMN3PP1M2cXYpM3Nvsy8CgNrDX aZdW43oBCcTB94LaSvD4mfB7LE2EmMvaUBEMIKJGgXYZRNqt9n2poHU2v7BpLtmXg2Fs 8ZhjoUPCLh8MICi5LGqGMu6DD3PzMub+/IqvYuLjJiK43Wv2qngoU+jBhHwVyJc4tgdZ Slyo9GW/OlLRp6RZvuhANj7gSczuMEle82hiZZcPxv/LRxnAgnSi6JOrShIAk82H3Y5w jdw6PA9YfIkj0jNPj1nM9WqcFCT+Ptpq1ZLVTzIwZPYXzw8yS8f3OTWU6W3HZeuEyDiC HCPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=h91vSr45; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g10si4519651ejf.168.2021.01.15.11.11.58; Fri, 15 Jan 2021 11:12:22 -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=@gmail.com header.s=20161025 header.b=h91vSr45; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388286AbhAOTIf (ORCPT + 99 others); Fri, 15 Jan 2021 14:08:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731073AbhAOTIf (ORCPT ); Fri, 15 Jan 2021 14:08:35 -0500 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09B97C0613C1; Fri, 15 Jan 2021 11:07:55 -0800 (PST) Received: by mail-qt1-x829.google.com with SMTP id c1so6806426qtc.1; Fri, 15 Jan 2021 11:07:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=6VFAEqW7kc3cIpTfEOGsqZWNF/6PRxbAffbJEVT5A/E=; b=h91vSr45JPkDC8BQ98q5pPfz0/KPLGI+bPBFlU40WOKHp6RZOB7rrnOHCAuD6sE9/7 XNNuqR5GhgkLG2+dO5hozC2WYoarwqjq9I8f+XvzeUufSyxd3J2QLAOrHOUZFUYMULkO tQ2YFMwfg391KHMVIoD1TcAncsQoRjgGKIHxbvHpRwAyUboVP/8PF6Il5RraYpuaPGnC NVyTg//2WiJsqU7pi3VLDp+pKlexkooQn4o3ZXJFtyZlq4NsY8n26XvUTDPGf3Zk0Bh1 L2GaZQZZN0cHOmnNhJMBxZhPlf0OlWamlfguKi5UxfKfxOaRhBWymDpmA9VzZ+6ehtn5 HM8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:date:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=6VFAEqW7kc3cIpTfEOGsqZWNF/6PRxbAffbJEVT5A/E=; b=sR0iUy8EJDbutFlM1R0+YSm9TSadb7uH2xOlBuNqxs792JJowYfHSuDvtt9zvI6Hpl WpgY9SSGlKNhqStJWGK0DWoFGgDp915Bi3WY3NSHTZTsiaOdr+TkCLq4Onk4aXc0pD14 rYSH4ep6mhVzOVK/veN6UVWQ9mW6dU+9dCmeqXYoZPTA1FfpkjWe74dmbgSQXuhIhrcd Md1nY+JYuGTyAmcoChk84divICEp2srD+wDMmD/k0W2+CyAgS8G1BNqssyrXhC3WCr1G 9Ti3FKhtM6pTKAV9Tp7XTxqwoRigpuig2rkQRdVKlKbXQKaCs7qw+MQIrWwV5ylTHPbr y4qA== X-Gm-Message-State: AOAM531HlF1D4Xem7Z4+LnRKboqrduM4u4+fL9LmoIJ3KT5k3OIb2n1I X4A/fWoAEMjdHrWS9W2qfmuWi2Ovi5k1YA== X-Received: by 2002:ac8:6f41:: with SMTP id n1mr13036465qtv.170.1610737674080; Fri, 15 Jan 2021 11:07:54 -0800 (PST) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id k42sm5469974qtk.17.2021.01.15.11.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 11:07:53 -0800 (PST) Sender: Arvind Sankar From: Arvind Sankar X-Google-Original-From: Arvind Sankar Date: Fri, 15 Jan 2021 14:07:51 -0500 To: Arnd Bergmann Cc: Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, Nathan Chancellor , Nick Desaulniers , Arnd Bergmann , Darren Hart , Andy Shevchenko , "H. Peter Anvin" , linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: Re: [PATCH] x86: efi: avoid BUILD_BUG_ON() for non-constant p4d_index Message-ID: References: <20210107223424.4135538-1-arnd@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210107223424.4135538-1-arnd@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 07, 2021 at 11:34:15PM +0100, Arnd Bergmann wrote: > From: Arnd Bergmann > > When 5-level page tables are enabled, clang triggers a BUILD_BUG_ON(): > > 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' > > Use the same method as in commit c65e774fb3f6 ("x86/mm: Make PGDIR_SHIFT > and PTRS_PER_P4D variable") and change it to MAYBE_BUILD_BUG_ON(), > so it only triggers for constant input. > > Link: https://github.com/ClangBuiltLinux/linux/issues/256 > Signed-off-by: Arnd Bergmann > --- > arch/x86/platform/efi/efi_64.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c > index e1e8d4e3a213..62bb1616b4a5 100644 > --- a/arch/x86/platform/efi/efi_64.c > +++ b/arch/x86/platform/efi/efi_64.c > @@ -137,8 +137,8 @@ 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)); > + MAYBE_BUILD_BUG_ON(p4d_index(EFI_VA_END) != p4d_index(MODULES_END)); > + MAYBE_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); > -- > 2.29.2 > I think this needs more explanation as to why clang is triggering this. The issue mentions clang not inline p4d_index(), and I guess not performing inter-procedural analysis either? For the second assertion there, everything is always constant AFAICT: EFI_VA_START, EFI_VA_END and P4D_MASK are all constants regardless of CONFIG_5LEVEL. For the first assertion, it isn't technically constant, but if p4d_index() gets inlined, the compiler should be able to see that the two are always equal, even though ptrs_per_p4d is not constant: EFI_VA_END >> 39 == MODULES_END >> 39 so the masking with ptrs_per_p4d-1 doesn't matter for the comparison. As a matter of fact, it seems like the four assertions could be combined into: BUILD_BUG_ON((EFI_VA_END & P4D_MASK) != (MODULES_END & P4D_MASK)); BUILD_BUG_ON((EFI_VA_START & P4D_MASK) != (EFI_VA_END & P4D_MASK)); instead of separately asserting they're the same PGD entry and the same P4D entry. Thanks.