Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2460608pxa; Mon, 3 Aug 2020 17:11:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwj+iBNudSJdd+gyY5GU6sdmztfkaD5u02sLU0meUhKVd6Rx9tPWnUUsXM1V5XdCsADho+y X-Received: by 2002:a17:906:dbd8:: with SMTP id yc24mr5619727ejb.176.1596499879370; Mon, 03 Aug 2020 17:11:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596499879; cv=none; d=google.com; s=arc-20160816; b=cmkqIwLqFoVJvgRlxi2bI20VUOMD+UR4La4eIA7SsxYrvOrkRFYBye2w7Z/TrzKdTz S/BJ70168REUTgiBJRCiRCvOcol/4fe5aQakarfuvz+cXawxFPDmbt0qdeoD9xUbzXhY mvH9mlk0638MJlAzm8E9mFHLrvtGqtSJBBY6em0L99PImvuP09zh84sPjeCQ0MyE7Alq cVpwf9lTdJ54DDisdteoYej5kbQFqmUwkAHut5EnjN+grQGfn/DkJ/Ubj2CIwSD2Ac+l Tq3wWtUz327w4h7ego+AmdcEmvMd7x+kGXNTHNSqZUliz57Xz+NpiZhpo5Agwpn/ZtaV JyYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=6kNl+hfthpZUs0DMOrCZCaKc5u5G5K72jxV4KQTYuVI=; b=Y/TiVpOK7NFPrTAjbw7UK3tk4heerJkT3H9k+lm2bUNDbtc8iHIPkGhpaOyN7XAdrj 4J7zuk/vBQiGhqAwPkM83DdV/tmKe1F/rgLk2NdAaMLf4iQKwiMHO/TmpOFs3uIFj6pY uLQi3DrSz49O7Ez5TGRXuGr0WiP+5dxjF8CO6AGbeQtbMIsQlbeecvnu2iF9P0dq4LiA 6otTALLYFHPsh37nfzWG+O+a1hlHtqoTCWRMoHsRAcxsDxw/PxZONrg0JNQMA+aaXw5N OBvWoyAXpQ1WuDAlcERgL2yvxwGyB2gz/4F5B14Mi0gpSx4BeumyUrhXXZ0uc7ta4JY1 up8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="h+Kr/xh5"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f16si12727062edy.386.2020.08.03.17.10.56; Mon, 03 Aug 2020 17:11:19 -0700 (PDT) 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=@google.com header.s=20161025 header.b="h+Kr/xh5"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729057AbgHDAJr (ORCPT + 99 others); Mon, 3 Aug 2020 20:09:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728010AbgHDAJq (ORCPT ); Mon, 3 Aug 2020 20:09:46 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5ABCC06174A for ; Mon, 3 Aug 2020 17:09:46 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id kr4so1019438pjb.2 for ; Mon, 03 Aug 2020 17:09:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6kNl+hfthpZUs0DMOrCZCaKc5u5G5K72jxV4KQTYuVI=; b=h+Kr/xh55EdeFvbqOwH1qCgT1MJDbkdSzzssRi3J4SJdcUBk753LMdTmgqZyGQpsDY 46RBxRJlBKw1ZJYSvY4LRP47rHRGbfXaav26RKpxEUYSY0F3ERbM9ibuDX7FGBNwIZA1 0Ei634B0IFroOMhs2tQFcZGngvzXA2Wk87NxtzMXDxLR/dA6Tx87Bbh1F2SrN8gjcs2K S1gLr3LftmQhYxYcR4aqaahXB6eLW90v4jbQRD41h7MFz8355d1jtzfur4XFJ0gr2OYf pTbMVCnyvk/WoVOBbuFffZJ8Uv0LlHs/X+lCgqcHyjfxDvO95+/if5qi6gsCe7SX1wGm 01kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6kNl+hfthpZUs0DMOrCZCaKc5u5G5K72jxV4KQTYuVI=; b=RELgFj6GGrMrnllrGgtGTY6mfMFjKzzuz325I+CXn//8sSdIG44EBmTtXVfBT62L6x FP3TCjVlZo83cnRouKDazG3yCd5OT7HGXk1b1ADNHEc56NYlOKmXbT4Ts3ZaA84ElgPN IFrxzjf2JFMnfFZOD4d3s7n3sF6FdtRExJkxG0kellQH2/smCHrPNJtLtiCQbP1M7C5p Gdp0xokfkJcakBgW+WqWh8UqWIwAKtunekwQIbMz2fU/Q2d5UZfc9rwvyoUGDgNa5LEM UzdzBobkJLHjDpNO03QfEIk05eql1UhWVLekaCcOLYsQaLP+pB5BGLlX/fiPLusOypn8 4enQ== X-Gm-Message-State: AOAM532hqrDADzEj2eRwyFXPu0UZxXjRz7g+dnJ8JSLKecDFRv9gYkZ0 Jl0v+zJV2IfScbY6QEFUUSbSac6d+uA1pq9olNY8Fg== X-Received: by 2002:a17:902:cb91:: with SMTP id d17mr16563102ply.223.1596499785878; Mon, 03 Aug 2020 17:09:45 -0700 (PDT) MIME-Version: 1.0 References: <20200527135329.1172644-1-arnd@arndb.de> In-Reply-To: <20200527135329.1172644-1-arnd@arndb.de> From: Nick Desaulniers Date: Mon, 3 Aug 2020 17:09:34 -0700 Message-ID: Subject: Re: [PATCH] x86: work around clang IAS bug referencing __force_order To: Arnd Bergmann , Peter Collingbourne Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , "Kirill A. Shutemov" , Zhenzhong Duan , Kees Cook , Peter Zijlstra , Juergen Gross , Andy Lutomirski , Andrew Cooper , LKML , clang-built-linux Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 27, 2020 at 6:53 AM Arnd Bergmann wrote: > > When using the clang integrated assembler, we get a reference > to __force_order that should normally get ignored in a few > rare cases: > > ERROR: modpost: "__force_order" [drivers/cpufreq/powernow-k6.ko] undefined! > > Add a 'static' definition so any file in which this happens can > have a local copy. > > Signed-off-by: Arnd Bergmann Hi Arnd, Looks like $ ARCH=i386 make CC=clang LLVM_IAS=1 -j71 defconfig+CONFIG_X86_POWERNOW_K6=m is the simplest reproducer. If I run $ llvm-readelf -s drivers/cpufreq/powernow-k6.o | grep __force_order 39: 00000000 0 NOTYPE GLOBAL DEFAULT UND __force_order we can indeed see an undefined reference to __force_order. If I build the .s file via $ ARCH=i386 make CC=clang LLVM_IAS=1 -j71 drivers/cpufreq/powernow-k6.s the only reference I see to __force_order is: 979 .addrsig_sym __force_order which is created by Clang's implicit -faddr-sig. If I disable that for this file via: ```diff diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile index f1b7e3dd6e5d..87d655d5af49 100644 --- a/drivers/cpufreq/Makefile +++ b/drivers/cpufreq/Makefile @@ -28,6 +28,9 @@ obj-$(CONFIG_X86_ACPI_CPUFREQ) += acpi-cpufreq.o obj-$(CONFIG_X86_POWERNOW_K8) += powernow-k8.o obj-$(CONFIG_X86_PCC_CPUFREQ) += pcc-cpufreq.o obj-$(CONFIG_X86_POWERNOW_K6) += powernow-k6.o +ifdef CONFIG_CC_IS_CLANG +CFLAGS_powernow-k6.o += -fno-addrsig +endif obj-$(CONFIG_X86_POWERNOW_K7) += powernow-k7.o obj-$(CONFIG_X86_LONGHAUL) += longhaul.o obj-$(CONFIG_X86_E_POWERSAVER) += e_powersaver.o ``` then the module links without error, and we get no hits for __force_order from llvm-readelf -s. This makes me think there may be a bug in Clang generating address significance tables for global variables that are otherwise unused, resulting in such linkage failures. +pcc@ for that. I ran a creduce job on drivers/cpufreq/powernow-k6.i where I'd compile twice, one with the implicit default value of -faddr-sig and look for the undefined __force_order, and again with -fno-addrsig and ensure there was no undefined __force_order, which coughed up: extern int __force_order; int a(void) { asm("" : "=m"(__force_order)); return 0; } as the bare minimum for an address significant table. https://godbolt.org/z/cjfaqM I'll bet this is coming from the call to read_cr0() in powernow_k6_set_cpu_multiplier(). If __force_order is defined in arch/x86/boot/compressed/pgtable_64.c, then I'm not sure it's a good idea to build drivers/cpufreq/powernow-k6.c as a kernel module (CONFIG_X86_POWERNOW_K6=m) vs statically compiled in. Wouldn't __force_order need to be EXPORT'ed for kernel modules to use it safely? > --- > arch/x86/boot/compressed/pgtable_64.c | 2 ++ > arch/x86/include/asm/special_insns.h | 7 +++++++ > 2 files changed, 9 insertions(+) > > diff --git a/arch/x86/boot/compressed/pgtable_64.c b/arch/x86/boot/compressed/pgtable_64.c > index c8862696a47b..8595194cea41 100644 > --- a/arch/x86/boot/compressed/pgtable_64.c > +++ b/arch/x86/boot/compressed/pgtable_64.c > @@ -12,7 +12,9 @@ > * It is not referenced from the code, but GCC < 5 with -fPIE would fail > * due to an undefined symbol. Define it to make these ancient GCCs work. > */ > +#ifndef CONFIG_CC_IS_CLANG > unsigned long __force_order; > +#endif > > #define BIOS_START_MIN 0x20000U /* 128K, less than this is insane */ > #define BIOS_START_MAX 0x9f000U /* 640K, absolute maximum */ > diff --git a/arch/x86/include/asm/special_insns.h b/arch/x86/include/asm/special_insns.h > index 82436cb04ccf..7081e587c1ea 100644 > --- a/arch/x86/include/asm/special_insns.h > +++ b/arch/x86/include/asm/special_insns.h > @@ -16,8 +16,15 @@ > * A memory clobber would solve the problem, but would prevent reordering of > * all loads stores around it, which can hurt performance. Solution is to > * use a variable and mimic reads and writes to it to enforce serialization > + * > + * Clang sometimes fails to kill the reference to the dummy variable, so > + * provide an actual copy. > */ > +#ifdef CONFIG_CC_IS_CLANG > +static unsigned long __force_order; > +#else > extern unsigned long __force_order; > +#endif > > void native_write_cr0(unsigned long val); > > -- > 2.26.2 > > -- -- Thanks, ~Nick Desaulniers