Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp857734ybz; Fri, 17 Apr 2020 11:17:42 -0700 (PDT) X-Google-Smtp-Source: APiQypKmG+v0Y3vnc1dSNEzJL4huMMU0US1RLTiIZD1klwLs49yRuI+9jhjlG0MRwU71G9bJlwRo X-Received: by 2002:a17:906:ce4b:: with SMTP id se11mr4475445ejb.178.1587147462344; Fri, 17 Apr 2020 11:17:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587147462; cv=none; d=google.com; s=arc-20160816; b=HO+anjNes8ACYqkvMAqvzrmVH7iKUE4Vp7iKKHp5Xr8zruND9ensYU6U6El9pLDNUg mFfTOueUeTV/pdDfDogqSG8g07Ni7rIzLCkYysrGWdAs5g2vUHdLRSNrK1GCCtVEfuS7 hDTyiZ9cAAf6BlfgoCg967X4i9q8KiZHqNOA5StB7benH/h5VxLGzg0P56KQC4+SksZb Xt5bf+x65aE/EwoMw/SJyBA4RzJfh0tloaM7ANt0jHrWvhz2Pa8x39mt4QGYvxgovcUr OGJGwjWbF9vl9CoqO5f6Ercj82lbGfSRKKwt9z0p4r4xRz7Hz8B6Bz7bfcVE6j//1lBf 73ww== 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=I4fHilet2XhDAMF+As9jlarIXgW0hTCmpDKp2MtvP2w=; b=FJcLKSubB+a+/WH6qZWNBM8ptH3TN5rXsT+JRS+zFwvld0h0QphMGn81QOYy/UByIA RPDoYNTG2nTwVdDSCuowEHObTbl/QNhNd1pPiPJ2WxsDiBzFYYFX0es0eeg/Mdre+SNU R1Mh/KTX8MpsNeN4ON6ieYCP4n0b1OKPaSxzsWlUD941S0GLDoRgQ807ysGAp+im00wB y5YKc2lDrAD8zN1HqpiV+n1ZlRSFeNeB/YRYr4G0qlB/mDJn6SnoFovL0IQ7cOdFgz2J TI8u+L/9qfz4dUtmcm4fABV2CFLOlB1FBnpvfZEUzGALHLD02/T9lokNdWS6mlAgi7zD ySfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=QZEIBK4e; 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 g26si14002642eds.600.2020.04.17.11.17.12; Fri, 17 Apr 2020 11:17:42 -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=QZEIBK4e; 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 S1730423AbgDQSQK (ORCPT + 99 others); Fri, 17 Apr 2020 14:16:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1730374AbgDQSQJ (ORCPT ); Fri, 17 Apr 2020 14:16:09 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 587D6C061A0C for ; Fri, 17 Apr 2020 11:16:09 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id m21so1409529pff.13 for ; Fri, 17 Apr 2020 11:16:09 -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=I4fHilet2XhDAMF+As9jlarIXgW0hTCmpDKp2MtvP2w=; b=QZEIBK4eSGPV8YN8MlsB7I71KNXN2ok9chBy+4GrBVtAKYdqSf4pha5kW+khP77sOC F3z8z/BjMv4ZjIOEchErTeyMN1Syni0eXUfKoHV2TpqvCc96yM5VU3zWJ9+5Df2jZt9w nTF7H3V08tYe2JdQ9b+D8BTy1d1ozl9R6V+l/WSNrqAOJQyZuB5SNEtEMu/7WaxiArj6 YOZ+E9WNT3NpmpPJIw1cNRaElB/yF6h2DtP+iHM8fc8r1UyFLfroRfppqSr1qs7eYc2v jKWtX/v8WFQwDCJp1qIdhS5RGgtDoiNRpSTGsjHvfzOdwLYZuOH1OHMnj0Z0qvafTjOb nrMA== 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=I4fHilet2XhDAMF+As9jlarIXgW0hTCmpDKp2MtvP2w=; b=daVjsTMnkFxhys8Ij/4ltaPduZMhFwAsN6CQWhFMOYEQYYDPHm5k6Im9L+hL0mhNmK S+23PJvEzO+8MGMz+yG136Y5M10D6TVNxAiaq9O+4Zypzg0CCiVOGHi3y9TXvE9h0pzI 6fMod4IJyAQ6Mon4qx2u1H6DPcBqgl5GrKlWe0shayNnI+hEp2qSumgKgEhGx9iQydsf WcOG8GRK3wzefwqma1f01WHvD59jGPRsZTKqO4v/TVG6irsQnqhVH0MvHJzRXos17OSB 60FmJw/oRnPPQrQACzh+2ki6eBD4vXo6eClRvKSE7v4VjBA+QXKgFth4yDkStJrIrNCV ezkA== X-Gm-Message-State: AGi0PuZ/l2pF7CzlC0rdp1O3DIkWXNiq+RV7ncfys+CTvsLbnEF4QGqd ShjTVP9YNpQCmf/PMUqX3ENnQ8rzmRmFaAWRSt1o9g== X-Received: by 2002:a63:6604:: with SMTP id a4mr4037225pgc.381.1587147368501; Fri, 17 Apr 2020 11:16:08 -0700 (PDT) MIME-Version: 1.0 References: <20200328084858.421444-1-slyfox@gentoo.org> <20200413163540.GD3772@zn.tnic> <20200415074842.GA31016@zn.tnic> <20200415231930.19755bc7@sf> <20200417075739.GA7322@zn.tnic> <20200417080726.GS2424@tucnak> <20200417084224.GB7322@zn.tnic> <20200417085859.GU2424@tucnak> <20200417090909.GC7322@zn.tnic> In-Reply-To: <20200417090909.GC7322@zn.tnic> From: Nick Desaulniers Date: Fri, 17 Apr 2020 11:15:56 -0700 Message-ID: Subject: Re: [PATCH v2] x86: fix early boot crash on gcc-10 To: Borislav Petkov Cc: Jakub Jelinek , Sergei Trofimovich , Michael Matz , LKML , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , 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 Fri, Apr 17, 2020 at 2:09 AM Borislav Petkov wrote: > > On Fri, Apr 17, 2020 at 10:58:59AM +0200, Jakub Jelinek wrote: > > On Fri, Apr 17, 2020 at 10:42:24AM +0200, Borislav Petkov wrote: > > > On Fri, Apr 17, 2020 at 10:07:26AM +0200, Jakub Jelinek wrote: > > > > If you want minimal changes, you can as I said earlier either > > > > mark cpu_startup_entry noreturn (in the declaration in some header so that > > > > smpboot.c sees it), or you could add something after the cpu_startup_entry > > > > call to ensure it is not tail call optimized (e.g. just > > > > /* Prevent tail call to cpu_startup_entry because the stack > > > > protector guard has been changed in the middle of this function > > > > and must not be checked before tail calling another function. */ > > > > asm (""); > > > > > > That sounds ok-ish to me too. > > > > > > I know you probably can't tell the future :) but what stops gcc from > > > doing the tail-call optimization in the future? > > > > > > Or are optimization decisions behind an inline asm a no-no and will > > > pretty much always stay that way? > > > > GCC intentionally treats asm as a black box, the only thing which it does Yep, that's how I would describe how LLVM see's inline asm, too. > > with it is: non-volatile asm (but asm without outputs is implicitly > > volatile) can be CSEd, and if the compiler needs to estimate size, it > > uses some heuristics by counting ; and newlines. > > And it will stay this way. I recently implemented parsing support for `asm inline` in Clang; I could have sworn I saw code in LLVM parsing newlines for a size estimate years ago, but when implementing `asm inline`, I couldn't find it. And test cases I wrote that used the C preprocessor to create thousand+ line inline asm strings would always be inlined, regardless of the `inline` asm qualifier. Not sure about implied volatility (...inner stock trader had a laugh at that...) for output-less asm statements. > > > > > And I hope the clang folks don't come around and say, err, nope, we're > > > much more aggressive here. > > > > Unlike GCC, I think clang uses the builtin assembler to parse the string, > > but don't know if it still treats the asms more like black boxes or not. > > Certainly there is a lot of code in the wild that uses inline asm > > as optimization barriers, so if it doesn't, then it would cause a lot of > > problems. > > > > Or go with the for (;;);, I don't think any compiler optimizes those away; > > GCC 10 for C++ can optimize away infinite loops that have some conditional > > exit because the language guarantees forward progress, but the C language > > rules are different and for unconditional infinite loops GCC doesn't > > optimize them away even if explicitly asked to -ffinite-loops. > > Lemme add Nick for clang for an opinion: > > Nick, we're discussing what would be the cleanest and future-proof > way to disable stack protector for the function in the kernel which Oh, this reminds me of commit d0a8d9378d16 ("x86/paravirt: Make native_save_fl() extern inline"), where the insertion of stack guards was also causing some pain. The cleanest solution would be to have function attributes that say "yes, I know I said -fstack-protector*, but for this one lone function I really need -fno-stack-protector. I know what I'm doing and accept whatever the consequences are." But maybe the attribute would be shorter than all that? :P Compared to playing games with each other's inlining heuristics, that would be the cleanest and future-proof solution. (Then we can even revert d0a8d9378d16, and use such a function attribute. I somehow prefer gnu_inline's semantics to ISO C99's extern inline semantics, and simultaneously hate the problems for which it's used.) > generates the canary value as gcc10 ends up checking that value due to > tail-call optimizing the last function called by start_secondary()... > upthread are all the details. > > And question is, can Jakub's suggestions above prevent tail-call > optimization on clang too and how reliable and future proof would that > be if we end up going that way? Sorry, I don't quite follow. The idea is that an empty asm statement in foo() should prevent foo() from being inlined into bar()? https://godbolt.org/z/7xBRGY -- Thanks, ~Nick Desaulniers