Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3750489imm; Fri, 25 May 2018 10:56:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq/Pia4/6rZrlpG4owJ0ziLVL9V9lIr6DFunEz1qvSWiKHOnOb/rkykSscIiblVeD0aSpc0 X-Received: by 2002:a62:c2:: with SMTP id 185-v6mr3575198pfa.238.1527271007549; Fri, 25 May 2018 10:56:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527271007; cv=none; d=google.com; s=arc-20160816; b=Eiy2KoiFKYeSwREApY3MuV0yWLRrn1Ww2m2hU5qkpA7ogtZLee/c6Cjvri1p+coYI6 GAGsL9DRhMqGCnrKSoXRNBWSBGf+Iuv+0qgFrqZU9dWMgI6C+ZNjxjzY+y7YKvt9wHMN 477tVUhxfNgnkzyN5TySPsnt66/7FJQE3aVoijM6vPINPNxVgsnU+sHwyDpzuY/YpUoS Hanc6qOkDuu+46fOOSror+X0f067J6ChMGo/Swot2KAM6BYOqWslX1dPnUTSL02s5655 fh2ftUod4hxFeRNN3XnclfNmzLEVkNEQwq7Ca1XHpuDD1hlVKopw7rTncPu9Ubn9GJe+ GKnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:from:cc:to:subject :content-transfer-encoding:mime-version:references:in-reply-to :user-agent:date:arc-authentication-results; bh=I1xn6IWPxPQMwf+OdD5n4/pGwLfNgrER/jBZCQpxfEI=; b=FmloPrnCWsQ0ugAOdAr495RnFG3D1/PUU9LpNnq/IzvBicKv2YyQ9ttzpIC7aGQXSt ZmRb/mqzHKEKjPXa/BZvy3+/M/95Y0qjDRGEuTXE+1StkYNG3c5z+Nqq82ADvfI842SW hM1dHlwoJIxjq/qwA75ObjYjULwKtZ41YgARN0r3bTZBZTcbjCeQD2/1Mi4VGa48T70l r5nAhMXQ87gEl5suraM18D4H35W3pkkSwuTekRz+Mc3heQLaaoTIJbhzKkJU80Xtzmxg NBBhbJZHWXBuwtLmuhkMyCVbHkvHfuhzcFrkmAbxwa5F2O74DKTdj1i3sxjIxjfeKUwc +hoQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b35-v6si24219717plh.36.2018.05.25.10.56.32; Fri, 25 May 2018 10:56:47 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967534AbeEYR4V convert rfc822-to-8bit (ORCPT + 99 others); Fri, 25 May 2018 13:56:21 -0400 Received: from terminus.zytor.com ([198.137.202.136]:42671 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967386AbeEYR4U (ORCPT ); Fri, 25 May 2018 13:56:20 -0400 Received: from wld62.hos.anvin.org (c-24-5-245-234.hsd1.ca.comcast.net [24.5.245.234] (may be forged)) (authenticated bits=0) by mail.zytor.com (8.15.2/8.15.2) with ESMTPSA id w4PHuGX61144019 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Fri, 25 May 2018 10:56:17 -0700 Date: Fri, 25 May 2018 10:56:10 -0700 User-Agent: K-9 Mail for Android In-Reply-To: References: <26B017D5-4063-46CB-8768-B0E5E7CD3838@zytor.com> <319FB971-ABB6-4BE7-969B-D87D84853196@zytor.com> <31A5469A-176F-451F-886A-ECD649DDC78C@zytor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Subject: Re: [clang] stack protector and f1f029c7bf To: Nick Desaulniers CC: Alistair Strachan , Manoj Gupta , Matthias Kaehlcke , Greg Hackmann , sedat.dilek@gmail.com, tstellar@redhat.com, LKML , Kees Cook From: hpa@zytor.com Message-ID: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On May 25, 2018 10:31:51 AM PDT, Nick Desaulniers wrote: >On Fri, May 25, 2018 at 9:53 AM wrote: >> On May 25, 2018 9:46:42 AM PDT, Nick Desaulniers > >wrote: >> >On Fri, May 25, 2018 at 9:33 AM wrote: >> >> On May 25, 2018 9:27:40 AM PDT, Nick Desaulniers >> > wrote: >> >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? > >> Yes, that's what "extern inline" means. Maybe it needs a must inline >annotation, but that's really messed up. > >I don't think it's possible to inline a function from an external >translation unit without something like LTO. > >If I move the implementation of native_save_fl() to a separate .c (with >out >of line assembly) or .S, neither clang nor gcc will inline that >assembly to >any call sites, whether the declaration of native_save_fl() looks like: > >extern inline unsigned long native_save_fl(void); > >or > >__attribute__((always_inline)) > >extern inline unsigned long native_save_fl(void); > >I think an external copy is the best approach for the paravirt code: > >diff --git a/arch/x86/kernel/irqflags.c b/arch/x86/kernel/irqflags.c >new file mode 100644 >index 000000000000..e173ba8bee7b >--- /dev/null >+++ b/arch/x86/kernel/irqflags.c >@@ -0,0 +1,24 @@ >+#include >+ >+extern unsigned long native_save_fl_no_stack_protector(void); >+extern void native_restore_fl_no_stack_protector(unsigned long flags); >+ >+asm( >+".pushsection .text;" >+".global native_save_fl_no_stack_protector;" >+".type native_save_fl_no_stack_protector, @function;" >+"native_save_fl_no_stack_protector:" >+"pushf;" >+"pop %" _ASM_AX ";" >+"ret;" >+".popsection"); >+ >+asm( >+".pushsection .text;" >+".global native_restore_fl_no_stack_protector;" >+".type native_restore_fl_no_stack_protector, @function;" >+"native_restore_fl_no_stack_protector:" >+"push %" _ASM_DI ";" >+"popf;" >+"ret;" >+".popsection"); >diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile >index 02d6f5cf4e70..8824d01c0c35 100644 >--- a/arch/x86/kernel/Makefile >+++ b/arch/x86/kernel/Makefile >@@ -61,6 +61,7 @@ obj-y += alternative.o i8253.o >hw_breakpoint.o > obj-y += tsc.o tsc_msr.o io_delay.o rtc.o > obj-y += pci-iommu_table.o > obj-y += resource.o >+obj-y += irqflags.o > > obj-y += process.o > obj-y += fpu/ >--- a/arch/x86/kernel/paravirt.c >+++ b/arch/x86/kernel/paravirt.c >@@ -322,9 +322,12 @@ struct pv_time_ops pv_time_ops = { > .steal_clock = native_steal_clock, > }; > >+extern unsigned long native_save_fl_no_stack_protector(void); >+extern void native_restore_fl_no_stack_protector(unsigned long flags); >+ > __visible struct pv_irq_ops pv_irq_ops = { >- .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl), >- .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl), >+ .save_fl = >__PV_IS_CALLEE_SAVE(native_save_fl_no_stack_protector), >+ .restore_fl = >__PV_IS_CALLEE_SAVE(native_restore_fl_no_stack_protector), > .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable), > .irq_enable = __PV_IS_CALLEE_SAVE(native_irq_enable), > .safe_halt = native_safe_halt, > >Thoughts? You need the extern inline in the .h file and the out-of-line .S file both. -- Sent from my Android device with K-9 Mail. Please excuse my brevity.