Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3686734imm; Fri, 25 May 2018 09:48:35 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpNSo0tKBc78aOEo0klZfpSClOId3nUkq6Bl2f17WlgQTZEUo3CKhWmUOIw9Ymzh2vxn34a X-Received: by 2002:a62:d8c7:: with SMTP id e190-v6mr3306300pfg.161.1527266914982; Fri, 25 May 2018 09:48:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527266914; cv=none; d=google.com; s=arc-20160816; b=DarktEPlxebETpH/LXp9fsGZsqXWrJEPvbyd7Lkg37XqfoI2zIezvnalJTxlOku9ON Qp7/ccyRVy4+5osQ5XbpIofeB7Vx4OZ3MvZT7zuluuTqwRAOnuszA3ZhqryLSMDCbKsa v94hZXocTuCIMz/1rNZdxTJAOgjMyTaNgtPwRyeiSKmSuX/8Zz6YZA8eMxqtPqYTB1fP yiJhaafILlUvRfofXVYE6X6DL42hPbuQYd/qsK7hOOsf3hjQg8VAp9NAHvZcaNc0G+GS bvTRj45Dcn7tHJKNUwn4BvBRfpjQy9RxybUtrfVXhX8YQD3z51JqfdcjNMMNxyCHG0y1 6nwA== 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=wt/nXZvB7/YpNpXA701KVsz0it2p3QneGe7EVVnLQoQ=; b=e8F2ycPIxTSM5RFL8EBi3S3s9zzzUQaE3SQzBVtN04QC7n+QQxA1g8wNFavz/Ea1iE by7rletnKkXsgcK8Y/fcTnO4Gf54iqnozyC1DOGrHo4ik64Tc1yIPeQQrYRDtISK5B7G 7GrMwnYDBsoZpcGTRZssK3mZeAK320vGVsXauy9bEXK43woJOQBMjLn2s7GsE/czIUEG TD0CnAGe4E8KvB2BcfLsF+ItXUm+KeV2uiojE7htvAxpUU8Vdlz8STIAZnf7vzAt/RF4 MxpS6EK/3iOZAydARiBJ3HUO3Y6pTbdgeApQJFJRYZBstM0J1sItV0Do0jjtwZNJrEZh Ospg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=YzKQAzAl; 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 e3-v6si18635063pga.487.2018.05.25.09.48.20; Fri, 25 May 2018 09:48:34 -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=YzKQAzAl; 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 S967413AbeEYQq4 (ORCPT + 99 others); Fri, 25 May 2018 12:46:56 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:46099 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967398AbeEYQqy (ORCPT ); Fri, 25 May 2018 12:46:54 -0400 Received: by mail-pl0-f65.google.com with SMTP id 30-v6so3464119pld.13 for ; Fri, 25 May 2018 09:46:54 -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=wt/nXZvB7/YpNpXA701KVsz0it2p3QneGe7EVVnLQoQ=; b=YzKQAzAlR7tmF4XqsM0tYoI7RTrk7hmWLwo4cS0i6prSsfmiZMcsB8FP/DCEWvYrWl Yg3eR7tkf6PKb9wddvVpzPysrTgYfVDsE1gzBGBlfl47eF3MV3oz2knvT6hpaSlBf2oA ODMbxZn4ifmkAZOGUKVoHXkv/erDYZTOJ0pruEA9s6LZaWPy0EHDV6/2rZpLuWjG8cy2 ez3xzHZq8VvXjR++Ubx3hyLDMvH/kTPNNzqaPEGl1+GnYMNmEyvm8cBu/MnI9adEBH0T tIzyblvm3o25uABRcPwf+mgLB+NsXSLb9PcqaBY351qtW+Lb3JGFJ3uXGTL/1Pi1WfQL yFXw== 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=wt/nXZvB7/YpNpXA701KVsz0it2p3QneGe7EVVnLQoQ=; b=D00sz9rLsiy8+XC4zggJZu4MMslDApLopEeNQLB9xaII3RZSlkgnryYShATpDMzNPl yEgeOxuEZHuusq2X7klpMf9aK37nIPParcfzoyIxUyxxnSztrsDbvHVZ44aabwTryYiw 461q72mWGFg74mwUCmrAFTCdIGYzy/7vUVSR2WaU1waBLYagG0xOEcWmW6eXefwghIXI L/jbJszMbcyYmUeF4N807nzlou8gNQNVWVvm0cDC8M4lHIAkOaIXME7KwZmM3UXCxYtn n1JvPIA6LBSGHK3iMoAGTNjmfrKn3xvebia7AqU8Oxac1SdMh4hJTlnFXn9BR/VQDMOh UXhA== X-Gm-Message-State: ALKqPwf/OjO+1OjPEQnb+AXZSqUn4lyhqxo4WOKHdUD8CojkNkEVdQvx H4To8sFiOJHrB6wfwq1Dp1K4vmLIz2hqcxpSXBjE7w== X-Received: by 2002:a17:902:710f:: with SMTP id a15-v6mr3445118pll.171.1527266813616; Fri, 25 May 2018 09:46:53 -0700 (PDT) MIME-Version: 1.0 References: <26B017D5-4063-46CB-8768-B0E5E7CD3838@zytor.com> <319FB971-ABB6-4BE7-969B-D87D84853196@zytor.com> In-Reply-To: <319FB971-ABB6-4BE7-969B-D87D84853196@zytor.com> From: Nick Desaulniers Date: Fri, 25 May 2018 09:46:42 -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 Fri, May 25, 2018 at 9:33 AM wrote: > On May 25, 2018 9:27:40 AM PDT, Nick Desaulniers wrote: > >On Thu, May 24, 2018 at 3:43 PM wrote: > >> On May 24, 2018 3:31:05 PM PDT, Nick Desaulniers > > > >wrote: > >> >On Thu, May 24, 2018 at 3:05 PM H. Peter Anvin > >wrote: > >> >> COMPILER AR: "=rm" should NEVER generate worse code than "=r". > >That > >> >is > >> >> unequivocally a compiler bug. > >> > > >> >Filed: https://bugs.llvm.org/show_bug.cgi?id=37583 > >> > > >> >> >> You are claiming it doesn't buy us anything, but you are only > >> >looking > >> >at > >> >> > the paravirt case which is kind of "special" (in the short bus > >kind > >> >of > >> >way), > >> >> > > >> >> > That's fair. Is another possible solution to have paravirt > >maybe > >> >not > >> >use > >> >> > native_save_fl() then, but its own > >> >non-static-inline-without-m-constraint > >> >> > implementation? > >> > > >> >> KERNEL AR: change native_save_fl() to an extern inline with an > >> >assembly > >> >> out-of-line implementation, to satisfy the paravirt requirement > >that > >> >no > >> >> GPRs other than %rax are clobbered. > >> > > >> >i'm happy to add that, do you have a recommendation if it should go > >in > >> >an > >> >existing .S file or a new one (and if so where/what shall I call > >it?). > > > >> How about irqflags.c since that is what the .h file is called. > > > >> It should simply be: > > > >> push %rdi > >> popf > >> ret > > > >> pushf > >> pop %rax > >> ret > > > >> ... but with all the regular assembly decorations, of course. > > > >Something like the following? > > > > > >diff --git a/arch/x86/kernel/irqflags.c b/arch/x86/kernel/irqflags.c > >new file mode 100644 > >index 000000000000..59dc21bd3327 > >--- /dev/null > >+++ b/arch/x86/kernel/irqflags.c > >@@ -0,0 +1,24 @@ > >+#include > >+ > >+extern unsigned long native_save_fl(void); > >+extern void native_restore_fl(unsigned long flags); > >+ > >+asm( > >+".pushsection .text;" > >+".global native_save_fl;" > >+".type native_save_fl, @function;" > >+"native_save_fl:" > >+"pushf;" > >+"pop %" _ASM_AX ";" > >+"ret;" > >+".popsection"); > >+ > >+asm( > >+".pushsection .text;" > >+".global native_restore_fl;" > >+".type native_restore_fl, @function;" > >+"native_restore_fl:" > >+"push %" _ASM_DI ";" > >+"popf;" > >+"ret;" > >+".popsection"); > > > >And change the declaration in arch/x86/include/asm/irqflags.h to: > >+extern inline unsigned long native_save_fl(void); > >+extern inline void native_restore_fl(unsigned long flags); > > > >This seems to work, but > >1. arch/x86/boot/compressed/misc.o warns that native_save_fl() is never > >defined (arch_local_save_flags() uses it). Does that mean > >arch_local_save_flags(), and friends would also have to move to the > >newly > >created .c file as well? > >2. `extern inline` doesn't inline any instances (from what I can tell > >from > >disassembling vmlinux). I think this is strictly worse. Don't we only > >want > >pv_irq_ops.save_fl to be non-inlined in a way that no stack protector > >can > >be added? If that's the case, should my assembly based implementation > >have > >a different identifier (`native_save_fl_paravirt` or something). That > >would > >also fix point #1 above. But now the paravirt code has its own copy of > >the > >function. > Sorry, I meant irqflags.S. > It still should be available as as inline, however, but now "extern inline". Heh, ok I was confused. But in testing, I had also created: arch/x86/lib/irqflags.S /* SPDX-License-Identifier: GPL-2.0 */ #include #include #include /* * unsigned long native_save_fl(void) */ ENTRY(native_save_fl) pushf pop %_ASM_AX ret ENDPROC(native_save_fl) EXPORT_SYMBOL(native_save_fl) /* * void native_restore_fl(unsigned long flags) * %rdi: flags */ ENTRY(native_restore_fl) push %_ASM_DI popf ret ENDPROC(native_restore_fl) EXPORT_SYMBOL(native_restore_fl) The issue is that this still has issues 1 & 2 listed earlier (and the disassembly has a lot more trailing nops added). When you say > It still should be available as as inline, however, but now "extern inline". Am I understanding correctly that native_save_fl should be inlined into all call sites (modulo the problematic pv_irq_ops.save_fl case)? Because for these two assembly implementations, it's not, but maybe there's something missing in my implementation? -- Thanks, ~Nick Desaulniers