From patchwork Wed Aug 2 10:55:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 129837 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp462697vqx; Wed, 2 Aug 2023 06:37:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlGbrYgeP8cv1gZy6ZxcxN5GwHqlvIuNkgrvbAPeZe9m+yfkNrEXzOtQCHrTps5tMyf4lCNc X-Received: by 2002:a17:902:b784:b0:1bb:8c42:79ef with SMTP id e4-20020a170902b78400b001bb8c4279efmr16339053pls.46.1690983468773; Wed, 02 Aug 2023 06:37:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690983468; cv=none; d=google.com; s=arc-20160816; b=xHH/GrFtkicbrQBPhZKKaGvr53rQAhdHJ5Pl2iC/RNqp8UPqzxVTo8GTZPnOLdEJeO wCZJP7fiVsfZl+9FgG1hHcM5YI0SWdVykFbNTNwUTG6R/110GYus0qitQVEn+USI2he1 BGVUjMqwl2tC5ezFfjmdX4ErSljeezfksvm3vsbC5dttDUN/WDcDMNMGNp6RQn5IcxyY 8c4GN7V7xybCZfBm55NTN+6kQEWRuqW3rqx2q6Y3XBSu0w/S69Evm2kd2znQ9UiPJe+4 Xu1vGjRyNpWgvzpSTgN8JpyiB65acoU3bWceRIOXOwKcWpjEkh/rqgQpAV03jAQDUA5B NxoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature; bh=OJDFzby0ZnN0v9KkGBrIpBxHQA0M/SWomoqJPt4Ln9Y=; fh=IwK3LjPX56eu0FM8NtQeo2u9R5AUzZQlgvLLkSqFWCc=; b=qG/cf+bEIcBRCszXr657dBMkQZwFoeg8cqY7XLJ64eFCH0m8WfOUrpketQae5tNPS2 V8iwp0M6UbRUIfAY5DWgoNpnFdJ84RwonYEitOBLQ6PcWoTYfbS996p6smV1n6BFd2gy CJA2ZpatVZktm81gKVrkqP7y/Vel/pmfDjDs4RmprA9uVUsluGymuZWZo8MU+ob1tAup 81F6nNV0+YqJ8mjw9mK05/fSur2GS6TrTj9+BOEZ25P4jJ7EZbfqBERyyRxMUx/U0e6u feGwE0s/hDXKAxkVsBYUKG1YJPiLxXpbLTMlIo3WxPYeLOfc31oLOkjcL2R1Gpxq2Ejk Tfgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=kzTXafX2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p2-20020a170902e74200b001b841d54b7csi11196244plf.206.2023.08.02.06.37.35; Wed, 02 Aug 2023 06:37:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=kzTXafX2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233486AbjHBLEZ (ORCPT + 99 others); Wed, 2 Aug 2023 07:04:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234005AbjHBLEW (ORCPT ); Wed, 2 Aug 2023 07:04:22 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9831E1FC2 for ; Wed, 2 Aug 2023 04:04:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=OJDFzby0ZnN0v9KkGBrIpBxHQA0M/SWomoqJPt4Ln9Y=; b=kzTXafX28IJou13ECVF9CGzks4 9p3lDuem3HsbpaPsV6FxeKtg4Mg7vi8wa/2r3mDzHa5P6voZ4HQqDtWTDl8oa85++z2HpVto9WPoP L1rRgkFBrrBjTzPNHa9+vtZyZhSDliH4BesAb0Uf74WBDNtbTGxC/GGZnZ3+K3NY5Ul97NU7ckqV8 yMjAGmW4kNV3sdlmYOBDxQ70LWwfzWF5UEOh4Bbl+3kZyCEl79QgqcgvLwLL5TeVoXaCt+fFHaDGb /JANK/uTbwqL5qy/ceTeVJPnXMQNHatYUQzAej5EI/Ok2VkYPJJhfwKQweAJHlXL4MH3nPtWJN3Ou pSSZvOIA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qR9eE-00EaIn-Fy; Wed, 02 Aug 2023 11:04:10 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 283E6300301; Wed, 2 Aug 2023 13:04:10 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id F1F1021000C90; Wed, 2 Aug 2023 13:04:09 +0200 (CEST) Message-ID: <20230802110323.016197440@infradead.org> User-Agent: quilt/0.66 Date: Wed, 02 Aug 2023 12:55:46 +0200 From: Peter Zijlstra To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, jpoimboe@kernel.org, andrew.cooper3@citrix.com, David.Kaplan@amd.com Subject: [PATCH 1/2] x86/ibt: Suppress spurious ENDBR References: <20230802105545.594381530@infradead.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773124681535054044 X-GMAIL-MSGID: 1773124681535054044 It was reported that under certain circumstances GCC emits ENDBR instructions for _THIS_IP_ usage. Specifically, when it appears at the start of a basic block -- but not elsewhere. Since _THIS_IP_ is never used for control flow, these ENDBR instructions are completely superfluous. Override the _THIS_IP_ definition for x86_64 to avoid this. Less ENDBR instructions is better. Fixes: 156ff4a544ae ("x86/ibt: Base IBT bits") Reported-by: David Kaplan Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/linkage.h | 8 ++++++++ include/linux/instruction_pointer.h | 5 +++++ 2 files changed, 13 insertions(+) --- a/arch/x86/include/asm/linkage.h +++ b/arch/x86/include/asm/linkage.h @@ -8,6 +8,14 @@ #undef notrace #define notrace __attribute__((no_instrument_function)) +#ifdef CONFIG_64BIT +/* + * The generic version tends to create spurious ENDBR instructions under + * certain conditions. + */ +#define _THIS_IP_ ({ unsigned long __here; asm ("lea 0(%%rip), %0" : "=r" (__here)); __here; }) +#endif + #ifdef CONFIG_X86_32 #define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0))) #endif /* CONFIG_X86_32 */ --- a/include/linux/instruction_pointer.h +++ b/include/linux/instruction_pointer.h @@ -2,7 +2,12 @@ #ifndef _LINUX_INSTRUCTION_POINTER_H #define _LINUX_INSTRUCTION_POINTER_H +#include + #define _RET_IP_ (unsigned long)__builtin_return_address(0) + +#ifndef _THIS_IP_ #define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; }) +#endif #endif /* _LINUX_INSTRUCTION_POINTER_H */