Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp863833ybz; Fri, 17 Apr 2020 11:24:47 -0700 (PDT) X-Google-Smtp-Source: APiQypLhspJbjhD5Xt40zO0ZFMkGI8N0ZkVd+qloxhKWsNMUjEYQwV3680jpF6M0HiTdo/+6gaqb X-Received: by 2002:a17:906:33d4:: with SMTP id w20mr4281852eja.284.1587147886930; Fri, 17 Apr 2020 11:24:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587147886; cv=none; d=google.com; s=arc-20160816; b=VRphHK2SVHcKOZtGoRy5an5hsgTpsbspNJGlOtfHXEIC9wXIXcSkSBoJwZvitKVyjv sNZSTlTlsf4yIp2d7nUMJ7/Bv5Np5Y6VpoIo3NY1gFLnQsS5gw+4ANTc65lm1qWfqlsF MOtpzjE/5w+v7ikQWzdLz1hMiBJ3I+qdDls1/I7zzNAYQPL8r3GEDLnJzU/BuCzzD1UP O8YxcYiU3WHz/4R6u2W7tKIwJwkf5bcxiV3DJ9uGCb5tlWsNoPSjRKfwuj9trRqfOLRm zIAGCynpDiDDBn6sXHHn0BrmWmUr/DjX3vDsdCBFZYzmfycN2PVLSvgwADypFd8qTrSi jqQA== 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=kTzWguc+avRhOZx3vuoNZJuv5gp1dk41dGxek09V0S4=; b=IwhAY//e2QixB81VRAy/OMLOUXKouIRN2RHEsubTU+zOJTRs/kZfOswoFdXGIk22IP D1TmDyvPxcAaciC+idghVlJVV2Oceqiu1cd5bAVVCqDzcH55+jd37yz42ftkHagkAwMr O3aLvfOq/paXnnXU0rUnk8IqusfZA53l8VLqYzYCOjOhI9kUGcq4dvFa6MspWhOVDaar p7C4UANZbiuwH31a7gs585vfwNv63gSBj3NLu6KyA8/xZqECtUiUuHJaTQ2dsrb66pib S8wMvzhoqoLcqwEvsgOlLGu0NBKZfyKAXuFeEy33KRtxL/KtVB5kgxsdbCv8qxu6rcuP Y4KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=AJDqMlnJ; 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 y4si15019473ejc.293.2020.04.17.11.24.22; Fri, 17 Apr 2020 11:24:46 -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=AJDqMlnJ; 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 S1730702AbgDQSWi (ORCPT + 99 others); Fri, 17 Apr 2020 14:22:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1730256AbgDQSWh (ORCPT ); Fri, 17 Apr 2020 14:22:37 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4F48C061A0C for ; Fri, 17 Apr 2020 11:22:37 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id d1so1452892pfh.1 for ; Fri, 17 Apr 2020 11:22:37 -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=kTzWguc+avRhOZx3vuoNZJuv5gp1dk41dGxek09V0S4=; b=AJDqMlnJghcc05jjEq8rvjOUGi5Mucds8GeYBmkKNwk+yUa+bcjsFBxBBA8mvWmCML nO8s0uBolgw3PlKBS7tdPMJzGaK4so5UZpN/3hysW6Jvv174B+fzipgAM6hRiwukIJiy In4znBRun0x8hrx31UQqKDR4tmAzKgmWGvaRT1aecEt9InpT62FidRX0omCGHoVPT/uv H70fm+SSbsfZqX86uPjT16F+7G+YewmMnaMoACHuojwAmhSMJAl36GXNnO1J40/liAXM dkk3o/KKQMcJ00Q3ei6hG1BgovFbuJqWSqFkpXv5PSeO0KtBkhL/n+A514h68ZwzoQ1a tMSQ== 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=kTzWguc+avRhOZx3vuoNZJuv5gp1dk41dGxek09V0S4=; b=oeCv6ua1obeL/nBJ+nLMlzVQKfv9ZhC7RVaIV91RO9lNBgLdaPOm3dM6ctM975Uc8q 5MNXyeAs0NYmhZ2jWI1uEecNL6IopeKx3ZiYyc/TnfDsFLTLNQUbUlCtP19B6z2EUMzA JHXJZL3VvfwRC4zHOcU30NN+0wEaTdqTyabGzjtf83/9/UePt+MJ/IqsNErir041DlDs HJzoBI3jZlu56gaE+xZJiCfndZvpv6L1y5lNdc5v1Mk5QzG1Q4hYcsMEykh1k5lHh7cs 1YaFlgPGZPr24FCgvuk0cQonZ2AqgGwQUKTYHO8rvDBIer+7RabGjn2DFOQjOeHa9jOi oLNw== X-Gm-Message-State: AGi0PuaAYrG4znvyRzUlhz9kEeNTG1kiDwhT+ha/BiiAFIOTXfNfLPL2 ctFTphyaE+NL3AVGzSKESphTnzu04VCvaMAYEkAqAw== X-Received: by 2002:a62:2a85:: with SMTP id q127mr4440579pfq.108.1587147756918; Fri, 17 Apr 2020 11:22:36 -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: From: Nick Desaulniers Date: Fri, 17 Apr 2020 11:22:25 -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 11:15 AM Nick Desaulniers wrote: > > 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 s/inlining/tail call/ > 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()? s/inlined/tail called/ > https://godbolt.org/z/7xBRGY -- Thanks, ~Nick Desaulniers