Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3732694imm; Fri, 25 May 2018 10:35:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoXyF6IITm19QulJsHEkMwfUT8Oe6WH9vc2OER7cunT9z8R5XItXCtRvW+fSK10QxdXsjqp X-Received: by 2002:a17:902:aa03:: with SMTP id be3-v6mr3538741plb.61.1527269746545; Fri, 25 May 2018 10:35:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527269746; cv=none; d=google.com; s=arc-20160816; b=UPfZBDuOxk773RMqYw8PQvisT5Em7bFqgSKUz3xOauzwFUIjz9UFRiZN6DbCSpuKw6 EYKZ5OaK1bw2B2f/wFxwNB7+YeZXB/gR7xotLGdtDeiAYQ7THatzSn2IL+9CRS6I0zoh Djos0ZuHGcPyqttSOhahjftd+BycQL39SEAUBSmNUD28YedGPLH8HjD6ZT4JWboHaacY jWX7yWNYT91ABvgK8vdwYlDoBVJ7xTfcYBEs+U//jw0LTmlVggBU9CHkFS/9tuU++QN3 KlE5VLaC4vFvdWEuhoWWeKBFnOr5zst/ZkO3opALB/4AOYEp8ENCAsgquyk2czJZJXCU nAaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject:reply-to :arc-authentication-results; bh=QNFcAM04t0B+PlTMC66Z9PM+ko5UjD5O0HSMSXJKnw0=; b=uVTHUcv51sAPASTMjNJfFjNgHUlTnpyu1eT+fZuzc8+we1dqBuat85MR5F1Krmxe1G fxQ77e5Ri2Y+zyzH2ZE4pFx0gqh9SZWviCW+rl6TlXRkXWLb1M+7gLdBdr96K+lrXbiR uFC0vfml+ScgLMSc9F8+mBqfNvwfw3sOTyU78XFrjA/1xZq4NIDHpzlW4+CNZdgq9kEG Pg88wBL0lFeSIJ6BmN/pPWqtKDvAMbNT6opt3Hnj5ysi4WEtEEClUaEQFWCfL8pldMMB chJcciQt/a0qNyeleTEzXhEvS4uSTAXFebAmUDiyBAD4ln3VfOS5A992RewtuvuCqzsS dw4A== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b2-v6si8159763pgt.283.2018.05.25.10.35.31; Fri, 25 May 2018 10:35:46 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967427AbeEYRfR (ORCPT + 99 others); Fri, 25 May 2018 13:35:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42138 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967305AbeEYRfQ (ORCPT ); Fri, 25 May 2018 13:35:16 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D7A5110B1B2; Fri, 25 May 2018 17:35:15 +0000 (UTC) Received: from tstellar.remote.csb (ovpn-117-161.phx2.redhat.com [10.3.117.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id D509E2B3A5; Fri, 25 May 2018 17:35:14 +0000 (UTC) Reply-To: tstellar@redhat.com Subject: Re: [clang] stack protector and f1f029c7bf To: Nick Desaulniers , hpa@zytor.com Cc: Alistair Strachan , Manoj Gupta , Matthias Kaehlcke , Greg Hackmann , sedat.dilek@gmail.com, LKML , Kees Cook References: <26B017D5-4063-46CB-8768-B0E5E7CD3838@zytor.com> <319FB971-ABB6-4BE7-969B-D87D84853196@zytor.com> <31A5469A-176F-451F-886A-ECD649DDC78C@zytor.com> From: Tom Stellard Organization: Red Hat Message-ID: <12a870df-5f9d-94d1-8318-42cfff1bedab@redhat.com> Date: Fri, 25 May 2018 10:35:14 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 25 May 2018 17:35:16 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/25/2018 10:31 AM, 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. > What about doing something like suggested here: https://bugs.llvm.org/show_bug.cgi?id=37512#c17 This would keep the definition in C and make it easier for compilers to inline. -Tom > 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? >