Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp472328ybg; Tue, 9 Jun 2020 05:35:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJJrraIZGFEuFAibaifk4wEbFeIb3QXlzkBv7xB6lUUZDjQq+QesmjA6GC6glDL7HSNica X-Received: by 2002:a50:da03:: with SMTP id z3mr15919192edj.129.1591706145812; Tue, 09 Jun 2020 05:35:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591706145; cv=none; d=google.com; s=arc-20160816; b=rIONd+Yi3OYBv3TyxFd2gmF8sLIwA5oN5xPKt1v8BYZSpQ6tsza3nf4qWnQ64x59pl 9VqmFE/r9mG0Rwfu4LMaGz3BsevHC0nXh+W35AF7McaQ1z7FAaLgfU8EaQErhpPRWy+Q tphjIZ6nklkhmqYRYNtf21KD07n9lijr3vWdIbDW2Qe65zZklvAWSqY9ChGIuL55Z4rB OJ557HdPWZ72lsKm6ryUfyvbHqndL8Mi+zVbVlrMEbH3EHe0keaKCp4TYbbDkg3Zs8qw HJ3a5eOdd8NpX9L9ZseADO7KpVOv2nlWiCbkmSKskoSZ0BhYvf3eWtAXG7Eg0Nmouvhb df9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=UJO1sD/kBk8NDKJVVa1oASZwZ1MBDeAnzOxnQLjPAZ0=; b=BBkldIcrSHvtohf4YnkhX8JJsupYYCdXNQSE7XfxYbztrTlJCBba7R8ZO6qdksSPUs JD+VxFewZ1jsxNKZehaeEI8B+XRnj0tPWQSUAxsgupqTRzhZb4G0QQs9Zz2Z7xEJLqr2 Jp+jqFOP99x1NiRcPVwirajx1/ozGIZopMtqxuPk6v5Rn7LxVE9VCl/cr+yX2ZCO2YiI ojcFP8Vks7u/pSetUDNDpAZJwPH6cKimvM3uXb/WQOHDu0ziyv2WXz2X+StYZQQcPQTp h8t5e8UuNWfZ89AvfX3WtMcq7Ej3PIufHRa21P/Q9YoHYiYHw1F5Tx4y1N8FVQvGFn5n qNNg== ARC-Authentication-Results: i=1; mx.google.com; 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 u1si10951090ejt.637.2020.06.09.05.35.21; Tue, 09 Jun 2020 05:35:45 -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; 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 S1728292AbgFIIyC (ORCPT + 99 others); Tue, 9 Jun 2020 04:54:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728269AbgFIIx4 (ORCPT ); Tue, 9 Jun 2020 04:53:56 -0400 Received: from Galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A14EC03E97C; Tue, 9 Jun 2020 01:53:55 -0700 (PDT) Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1jia0y-0005c6-K2; Tue, 09 Jun 2020 10:53:48 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 376751C007F; Tue, 9 Jun 2020 10:53:48 +0200 (CEST) Date: Tue, 09 Jun 2020 08:53:48 -0000 From: "tip-bot2 for Bob Haarman" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86_64: Fix jiffies ODR violation Cc: Nathan Chancellor , Alistair Delva , Fangrui Song , Bob Haarman , Thomas Gleixner , Sedat Dilek , Andi Kleen , Josh Poimboeuf , stable@vger.kernel.org, x86 , LKML In-Reply-To: <20200602193100.229287-1-inglorion@google.com> References: <20200602193100.229287-1-inglorion@google.com> MIME-Version: 1.0 Message-ID: <159169282801.17951.17795632339002464231.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/urgent branch of tip: Commit-ID: d8ad6d39c35d2b44b3d48b787df7f3359381dcbf Gitweb: https://git.kernel.org/tip/d8ad6d39c35d2b44b3d48b787df7f3359381dcbf Author: Bob Haarman AuthorDate: Tue, 02 Jun 2020 12:30:59 -07:00 Committer: Thomas Gleixner CommitterDate: Tue, 09 Jun 2020 10:50:56 +02:00 x86_64: Fix jiffies ODR violation 'jiffies' and 'jiffies_64' are meant to alias (two different symbols that share the same address). Most architectures make the symbols alias to the same address via a linker script assignment in their arch//kernel/vmlinux.lds.S: jiffies = jiffies_64; which is effectively a definition of jiffies. jiffies and jiffies_64 are both forward declared for all architectures in include/linux/jiffies.h. jiffies_64 is defined in kernel/time/timer.c. x86_64 was peculiar in that it wasn't doing the above linker script assignment, but rather was: 1. defining jiffies in arch/x86/kernel/time.c instead via the linker script. 2. overriding the symbol jiffies_64 from kernel/time/timer.c in arch/x86/kernel/vmlinux.lds.s via 'jiffies_64 = jiffies;'. As Fangrui notes: In LLD, symbol assignments in linker scripts override definitions in object files. GNU ld appears to have the same behavior. It would probably make sense for LLD to error "duplicate symbol" but GNU ld is unlikely to adopt for compatibility reasons. This results in an ODR violation (UB), which seems to have survived thus far. Where it becomes harmful is when; 1. -fno-semantic-interposition is used: As Fangrui notes: Clang after LLVM commit 5b22bcc2b70d ("[X86][ELF] Prefer to lower MC_GlobalAddress operands to .Lfoo$local") defaults to -fno-semantic-interposition similar semantics which help -fpic/-fPIC code avoid GOT/PLT when the referenced symbol is defined within the same translation unit. Unlike GCC -fno-semantic-interposition, Clang emits such relocations referencing local symbols for non-pic code as well. This causes references to jiffies to refer to '.Ljiffies$local' when jiffies is defined in the same translation unit. Likewise, references to jiffies_64 become references to '.Ljiffies_64$local' in translation units that define jiffies_64. Because these differ from the names used in the linker script, they will not be rewritten to alias one another. 2. Full LTO Full LTO effectively treats all source files as one translation unit, causing these local references to be produced everywhere. When the linker processes the linker script, there are no longer any references to jiffies_64' anywhere to replace with 'jiffies'. And thus '.Ljiffies$local' and '.Ljiffies_64$local' no longer alias at all. In the process of porting patches enabling Full LTO from arm64 to x86_64, spooky bugs have been observed where the kernel appeared to boot, but init doesn't get scheduled. Avoid the ODR violation by matching other architectures and define jiffies only by linker script. For -fno-semantic-interposition + Full LTO, there is no longer a global definition of jiffies for the compiler to produce a local symbol which the linker script won't ensure aliases to jiffies_64. Fixes: 40747ffa5aa8 ("asmlinkage: Make jiffies visible") Reported-by: Nathan Chancellor Reported-by: Alistair Delva Debugged-by: Nick Desaulniers Debugged-by: Sami Tolvanen Suggested-by: Fangrui Song Signed-off-by: Bob Haarman Signed-off-by: Thomas Gleixner Tested-by: Sedat Dilek # build+boot on Reviewed-by: Andi Kleen Reviewed-by: Josh Poimboeuf Cc: stable@vger.kernel.org Link: https://github.com/ClangBuiltLinux/linux/issues/852 Link: https://lkml.kernel.org/r/20200602193100.229287-1-inglorion@google.com --- arch/x86/kernel/time.c | 4 ---- arch/x86/kernel/vmlinux.lds.S | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c index 106e7f8..f395729 100644 --- a/arch/x86/kernel/time.c +++ b/arch/x86/kernel/time.c @@ -25,10 +25,6 @@ #include #include -#ifdef CONFIG_X86_64 -__visible volatile unsigned long jiffies __cacheline_aligned_in_smp = INITIAL_JIFFIES; -#endif - unsigned long profile_pc(struct pt_regs *regs) { unsigned long pc = instruction_pointer(regs); diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 1bf7e31..7c35556 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -40,13 +40,13 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT) #ifdef CONFIG_X86_32 OUTPUT_ARCH(i386) ENTRY(phys_startup_32) -jiffies = jiffies_64; #else OUTPUT_ARCH(i386:x86-64) ENTRY(phys_startup_64) -jiffies_64 = jiffies; #endif +jiffies = jiffies_64; + #if defined(CONFIG_X86_64) /* * On 64-bit, align RODATA to 2MB so we retain large page mappings for