From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D628FC433EF for ; Fri, 15 Oct 2021 18:30:27 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9916D60F36 for ; Fri, 15 Oct 2021 18:30:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9916D60F36 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:Cc:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qErXVkhe8c2QXR7qJimDg9BukfohAAuXICLTa+ZAEK4=; b=kw+zrxbZHfr8gOevctPuANaKN/ y3MTWbt8h5uCBGsUTzMUHhO05UFJRNfIssPqZEnqwKhekfDZ1PzSUzwRTqa3V1KaxUNcGtnpmozmE CusAULcV7868BdV5GBJ3DeG+9NwLLHMbMOz8X5g5T5o2Mylufu7ilML2LgJ2gMGXjvLaQw9M9hdZF wq1MmGJdPdE3e0wHmnfVgMcBnWY1l/ozX9osWbFidvea5ZSzDmX3So1MUwwzNf6/Hb3TozQq7HFI7 hlNaDzG5ABVPkaZN588mRtrdg8Pi6HfV3udL6niDg4sHr4pbKPWBX7AriXcmDJR/NHN1S4xyrwYT8 uvqnumBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbRxA-008RaF-HV; Fri, 15 Oct 2021 18:29:12 +0000 Received: from out30-45.freemail.mail.aliyun.com ([115.124.30.45]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbRx5-008RXn-Ay for linux-arm-kernel@lists.infradead.org; Fri, 15 Oct 2021 18:29:09 +0000 X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R131e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=e01e04426; MF=ashimida@linux.alibaba.com; NM=1; PH=DS; RN=28; SR=0; TI=SMTPD_---0UsDzA4._1634322537; Received: from ashimida.local(mailfrom:ashimida@linux.alibaba.com fp:SMTPD_---0UsDzA4._1634322537) by smtp.aliyun-inc.com(127.0.0.1); Sat, 16 Oct 2021 02:29:01 +0800 Subject: Re: [PATCH] [PATCH V4]ARM64: SCS: Add gcc plugin to support Shadow Call Stack To: Nick Desaulniers Cc: masahiroy@kernel.org, michal.lkml@markovi.net, catalin.marinas@arm.com, will@kernel.org, keescook@chromium.org, nathan@kernel.org, tglx@linutronix.de, akpm@linux-foundation.org, samitolvanen@google.com, frederic@kernel.org, rppt@kernel.org, mark.rutland@arm.com, yifeifz2@illinois.edu, rostedt@goodmis.org, viresh.kumar@linaro.org, andreyknvl@gmail.com, colin.king@canonical.com, ojeda@kernel.org, luc.vanoostenryck@gmail.com, elver@google.com, nivedita@alum.mit.edu, ardb@kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hardening@vger.kernel.org, clang-built-linux@googlegroups.com References: <1634167668-60198-1-git-send-email-ashimida@linux.alibaba.com> From: Dan Li Message-ID: <722d9662-e27c-2efb-e8cf-d505b6950475@linux.alibaba.com> Date: Sat, 16 Oct 2021 02:28:56 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211015_112907_617771_B16CF83D X-CRM114-Status: GOOD ( 25.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 10/15/21 2:44 AM, Nick Desaulniers wrote: > On Wed, Oct 13, 2021 at 4:28 PM Dan Li wrote: >> --- a/include/linux/compiler-gcc.h >> +++ b/include/linux/compiler-gcc.h >> @@ -50,6 +50,10 @@ >> #define __latent_entropy __attribute__((latent_entropy)) >> #endif >> >> +#if defined(SHADOW_CALL_STACK_PLUGIN) && !defined(__CHECKER__) >> +#define __noscs __attribute__((no_shadow_call_stack)) >> +#endif > > Cool this is a nice addition, and something I don't think that clang > has. For any new feature, having a function attribute to disable it > at the function granularity is nice, and plays better with LTO than -f > group flags. Though that begs the question: what happens if a __noscs > callee is inlined into a non-__noscs caller, or vice versa? Thanks Nick, According to my understanding, all inline optimizations in gcc should happen before inserting scs insns (scs and paciasp/autiasp use the same insertion point). Therefore, the check for the __noscs attribute will also occur after all inlining is completed. As in the following example: - Since __noscs attribute is specified, scs_test1 does not insert scs insns - Since normal functions scs_test2/3 uses x30, it needs to insert scs insns - Since __noscs attribute is specified, scs_test4 after inlining does not need to insert scs insns __always_inline __noscs void scs_test1(void) { asm volatile("mov x1, x1\n\t":::"x30"); } //scs insns inserted after function inline void scs_test2(void) { scs_test1(); } __always_inline void scs_test3(void) { asm volatile("mov x3, x3\n\t":::"x30"); } //no scs insns inserted __noscs void scs_test4(void) { scs_test3(); } ffff800010012900 : ffff800010012900: a9bf7bfd stp x29, x30, [sp, #-16]! ffff800010012904: 910003fd mov x29, sp ffff800010012908: aa0103e1 mov x1, x1 ffff80001001290c: a8c17bfd ldp x29, x30, [sp], #16 ffff800010012910: d65f03c0 ret ffff800010012914 : ffff800010012914: f800865e str x30, [x18], #8 ffff800010012918: a9bf7bfd stp x29, x30, [sp, #-16]! ffff80001001291c: 910003fd mov x29, sp ffff800010012920: aa0103e1 mov x1, x1 ffff800010012924: a8c17bfd ldp x29, x30, [sp], #16 ffff800010012928: f85f8e5e ldr x30, [x18, #-8]! ffff80001001292c: d65f03c0 ret ffff800010012930 : ffff800010012930: f800865e str x30, [x18], #8 ffff800010012934: a9bf7bfd stp x29, x30, [sp, #-16]! ffff800010012938: 910003fd mov x29, sp ffff80001001293c: aa0303e3 mov x3, x3 ffff800010012940: a8c17bfd ldp x29, x30, [sp], #16 ffff800010012944: f85f8e5e ldr x30, [x18, #-8]! ffff800010012948: d65f03c0 ret ffff80001001294c: d503201f nop ffff800010012950 : ffff800010012950: a9bf7bfd stp x29, x30, [sp, #-16]! ffff800010012954: 910003fd mov x29, sp ffff800010012958: aa0303e3 mov x3, x3 ffff80001001295c: a8c17bfd ldp x29, x30, [sp], #16 ffff800010012960: d65f03c0 ret > I noticed that __noscs isn't actually applied anywhere in the kernel, > yet, at least in this series. Were there any places necessary that > you've found thus far? At present, I have not found a function that must use the __noscs attribute in the kernel. I have only used this attribute in test cases. > Overall, I'm happy with the patch and am ready to ack it, but I would > like to see a link to to the upstream GCC feature request for SCS (and > one created if it doesn't exist) cited explicitly in the commit > message. I think that would be a good demonstration that this can or > will be upstreamed into the compiler proper for the compiler vendors > to maintain, rather than the kernel folks. The compiler vendors may > have further feedback on the approach, such as my question above > pertaining to inlining. > I have submitted a feature request to the gcc community, and waiting for a follow-up response. Is it fine to add the following description in [PATCH V5]? A similar feature request has also been sent to gcc. link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102768 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel