Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2950910imm; Thu, 24 May 2018 19:44:50 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoNtqH39MkOWHUvyzool11lXeKLQa9PULDTj6iLrjzyAPoqOtYwUZvNTAjiyB4KQagv8VgE X-Received: by 2002:a63:730c:: with SMTP id o12-v6mr470761pgc.1.1527216290898; Thu, 24 May 2018 19:44:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527216290; cv=none; d=google.com; s=arc-20160816; b=T2ySUnZPUmakrnMp1INYRrYC3YM5rUpOhcZrw7zHbHN1EejBNDro2omYskFBESUfCL RxiQuRYZgcpXVuCThRNJ6LlIL4M4V/e3ZPL+5Ugd0L8HzfymZgkBZq8+RgXdPtmBhaOs aUoKiOOBfwr7jDfnECnUhjhlJMfgHrFoAkFARXTLqfauHzJvOZUWsYcbjuKRbyK+Yleg A7AfaH6wsg1PvrC7u879EsFpgG+7P7dZtdkDjHePiEiu4fpkb/dGzwg63a0NIhCJnCFI 3xFz/WCbtYnXoDCXWnqSThzpsvF107Me9ACUbS+RozzLqTUBmqQYXhWmDrYFn3ZobGO0 jPIA== 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 :arc-authentication-results; bh=zvsAm4UGpfGu9/oeHoysSihpeUQiaB4xZDqcfQkt/So=; b=IHXnEzHMEb0gMpvSvTieaeyZUmWxcf76+8+u2vdDecLP7VC5oJ5S4UIj4FUHTqG1Xe YT4eIZHmwLfIp0ON+dsvgkD5zymL9u10MaTp2RJC2NzQ85Jj8Ew7RLEJar9b3IIFVaPc wI7mwW2z4YZoCp0ufvldLRGuUqR7Fmx6BKOuf5Pk67y6q0Q/pJyiCmgcv0s0N/yp90MU ZubGdn1xsF8PrjjXKEs9SHMxJzroa4ftbx7J9hYKt5hhaxCeD+Ee98UImjKTNNYzvSLH 94ZXy+2AK168+iHUVV+rfF3PhnhtnVj1/9EyWS6fsFfAmIBVi4xPGhlK1X/WllBH2yhL kHTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=wV0MOBz5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id d10-v6si18395926pgu.626.2018.05.24.19.44.36; Thu, 24 May 2018 19:44:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=wV0MOBz5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1161308AbeEXV1W (ORCPT + 99 others); Thu, 24 May 2018 17:27:22 -0400 Received: from mail-vk0-f68.google.com ([209.85.213.68]:46495 "EHLO mail-vk0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033204AbeEXV1V (ORCPT ); Thu, 24 May 2018 17:27:21 -0400 Received: by mail-vk0-f68.google.com with SMTP id i190-v6so1938130vkd.13 for ; Thu, 24 May 2018 14:27:21 -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=zvsAm4UGpfGu9/oeHoysSihpeUQiaB4xZDqcfQkt/So=; b=wV0MOBz5F7GISVDHLVkOGq9n9y/igYS7eHnhMcEGLzl1DNeJoyYzq2MSSTMr1PZXeQ ob9aUjJuO6krZ0AYHGSVgwod2nH3AVd+YFmlGSz5wmlnqte8lAYPeHNG/RGoYIw2KxWf bI3fMik72/davZBzGEm22ZtUfrRQeLdXuF+WJYsLf13hEef5YhiPWkwwj+m1Bbii+D/7 ujzmuMGZoipfO6Wx1+JKpQsp4I/Yn5crlSdGpHyvX/Wcj5wmPijfJT8HNLtyiE5iY/ha 1ngSeGCm4cYyZ20t1jVcOXdtdLwVGqwEYm660JxrPtJgbU5aBG3tQNTzGe6oFyiGnDAG ni9g== 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=zvsAm4UGpfGu9/oeHoysSihpeUQiaB4xZDqcfQkt/So=; b=O0fmSOt9fdqdBVkBdvv9ctkKQRu4W3sZsqJoEqNS6Qvz0Q1CIsGS3AGKAZlhScLOzQ ypfaYTja5rUSQ7vtbJQ5pLveSSD8PstOBEIIxWalyAW+HXHma008N3SuhiJLByzdKssU dFMrDig4HWjdbRl9uM8qgflyzBmCT5rgtkEHK/xG3A+BtS2DoJ74nbFwxwxYlqwRGdhH gsAkYKTv1IDMhVl0YI2/Icd8u1Zj7ARp/oEmMoijcShj72Fw0aA78MwdmpLGpUNq+2fF F1PnA+pa0HgFosCzpjo25PuKa4MFTp4KntfavZBi9QwxGP2C2BDU07Ot5ArPhIrdblq1 y1Cw== X-Gm-Message-State: ALKqPwfxTIPR2WUmZ8QRQv0Q/zuQF3OdOmvyvoetyBWRUAjKNNoNz2JW KU/cRLUYEkxQd7muSAWB8KvP1kuW+OvJiKPCzpAnvQ== X-Received: by 2002:a1f:2ad8:: with SMTP id q207-v6mr5912146vkq.72.1527197240270; Thu, 24 May 2018 14:27:20 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Nick Desaulniers Date: Thu, 24 May 2018 14:27:08 -0700 Message-ID: Subject: Re: [clang] stack protector and f1f029c7bf To: hpa@zytor.com Cc: Alistair Strachan , Manoj Gupta , Matthias Kaehlcke , Greg Hackmann , sedat.dilek@gmail.com, tstellar@redhat.com, LKML , Kees Cook 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 Thu, May 24, 2018 at 2:12 PM Nick Desaulniers wrote: > On Thu, May 24, 2018 at 1:52 PM Nick Desaulniers > wrote: > > On Thu, May 24, 2018 at 1:26 PM Nick Desaulniers < ndesaulniers@google.com> > > wrote: > > > On Thu, May 24, 2018 at 11:59 AM wrote: > > > > Issue 3: Let's face it, reading and writing the flags should be > > builtins, > > > exactly because it has to do stack operations, which really means the > > > compiler should be involved. > > > I'm happy to propose that as a feature request to llvm+gcc. > > Oh, looks like both clang and gcc have: > > __builtin_ia32_readeflags_u64() > > https://godbolt.org/g/SwPjhq > > Maybe native_save_fl() and native_restore_fl() should be replaced in the > > kernel with > > __builtin_ia32_readeflags_u64() and __builtin_ia32_writeeflags_u64()? > > -- > > Thanks, > > ~Nick Desaulniers > Looks like those builtins got added to GCC around the 4.9 timeframe: > https://godbolt.org/g/9VS2E9 > Problematically, it seems that GCC does not have __has_builtin to do > feature detection: https://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros > https://godbolt.org/g/oku8ux Is there a more canonical way the kernel does feature detection that looks better than: diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h index 89f08955fff7..90974b5d023c 100644 --- a/arch/x86/include/asm/irqflags.h +++ b/arch/x86/include/asm/irqflags.h @@ -13,6 +13,8 @@ * Interrupt control: */ +#ifdef GCC_VERSION +#if GCC_VERSION < 40900 static inline unsigned long native_save_fl(void) { unsigned long flags; @@ -38,6 +40,17 @@ static inline void native_restore_fl(unsigned long flags) :"g" (flags) :"memory", "cc"); } +#else +static inline unsigned long native_save_fl(void) +{ + return __builtin_ia32_readeflags_u64(); +} +static inline void native_restore_fl(unsigned long flags) +{ + __builtin_ia32_writeeflags_u64(flags); +} +#endif + static inline void native_irq_disable(void) { -- Thanks, ~Nick Desaulniers