Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp5439855rwb; Wed, 17 Aug 2022 18:13:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR72EwA8ieguoS/OtqUJbKhDaBIDLs9VlxvBp1f3ucFNKIMe+RMzuTvt54PPdrMVIvz0xrIv X-Received: by 2002:a17:907:6e88:b0:730:e16e:b760 with SMTP id sh8-20020a1709076e8800b00730e16eb760mr390089ejc.5.1660785203731; Wed, 17 Aug 2022 18:13:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660785203; cv=none; d=google.com; s=arc-20160816; b=GsCH/uPAS0yjLW2ayJco2hQAD6yFcjUMfJIo+wrdtHMhHmw6Yn/g8SQZjDI8QfE69Z lhNjlgDWf0Zu03UDe5ANGFDBNQXaHXdT1DhojGZAF3OngyprTdTJzA0o0oee71j5r6mW tPf68k2U4UsGH6yrBcDTo5+y8HcYMKOzRDfVs8rWH1NIHmpqEA7uQl1bBSzwWmQ/ypk3 OcSiIuVXFSYLekHiALjwiuzfoq6zgVmtBTZ2Y3p/hwfH+TLrkcjjQj8GCBc8xEu5pyn+ +ZFNSE9CUrR6bApP7DffZSEVpklj4vMcK5YkHK6sIYcuD8CsQUubgwTMZVZl07hJZQnX uLcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=6KHmzlIEP4vuS/O2ktUDxZZjwwJueXTbP1O/goGqxDs=; b=oMd3ddHymIDNzJ+GzlsI0ndI/81VZTFlR+DJcmU1y03ucVtDNKPV1U9O46Fd86MC68 RHODlLVceQTABVq9RFYRtxmaN2BkNRlbCzVm+yMX41jccxwoAmnBnKxQAI9da0wg9UcJ FvdWkdkPsyDIXMPSjRKEcq8Ru3Ie8qg2gFvGAXlzWUUQ9aAeivGHk60S/JpQO9i5AhBb RyedegbCtT94KpW46ZrjPk/DiUeNBsunxBs7lIXuU7fJWKfOCCfSqMyt3iSPircCFxip F54JPaQz8xPSL/OgcrUlhlD1Wl10W2w4PyonLdca2P0pnwOJ9YPDDEpLzne4ZkfW8dGo bDaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BS8wPT+s; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dr2-20020a170907720200b0072eece129bdsi107322ejc.59.2022.08.17.18.12.57; Wed, 17 Aug 2022 18:13:23 -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=@kernel.org header.s=k20201202 header.b=BS8wPT+s; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242521AbiHRBKv (ORCPT + 99 others); Wed, 17 Aug 2022 21:10:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240011AbiHRBKu (ORCPT ); Wed, 17 Aug 2022 21:10:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63BC4910B6 for ; Wed, 17 Aug 2022 18:10:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E9080613FB for ; Thu, 18 Aug 2022 01:10:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3C8AC433C1; Thu, 18 Aug 2022 01:10:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660785048; bh=6KB9tpgcTIxFqPnh9VXpBIlNNMq96ADAauAYX3Ha3Ms=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BS8wPT+sFWVJrBo5vMWAQbbo9jn7ON0xwnvOD6fRye4Xticdh399W0jaQLTI2MZxE SuGcVFLVWVp8Bug9uKqnSNtkIeNVVSRIApS3SHykAs6ENdqNjIxT6FBfVR9+70mJDD z2x0AJryZnaOV3x+wADld0Bzbpx2ZnY4d32S9NNwbUblzs9loLArlvlmUyKOtoWP8c XNAew8W9wh4JlIXQcXUJTtgAY2WkX/LwPpaGNxEjh1xYcFo11Qz2iKIfIx10WZABvW X+APd44jqLv05/Rgd+DJNTMjUBJNKPniVtnD45Rdia0duRfkg2oTGPQP71hzg+6gI5 GG/osR90KWpcQ== Date: Wed, 17 Aug 2022 18:10:45 -0700 From: Josh Poimboeuf To: Peter Zijlstra Cc: "Xu, Pengfei" , "Yang, Weijiang" , "Su, Heng" , linux-kernel@vger.kernel.org, Josh Poimboeuf , pbonzini@redhat.com, x86@kernel.org Subject: Re: [PATCH] x86/kvm, objtool: Avoid fastop ENDBR from being sealed Message-ID: <20220818011045.v4baekgxajylqxvh@treble> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Wed, Aug 17, 2022 at 12:56:15PM +0200, Peter Zijlstra wrote: > Add (yet another) annotation to inhibit objtool from sealing a specific > ENDBR instance. Nah, just add a throwaway reference to the function. Then no objtool change is needed: diff --git a/arch/x86/include/asm/ibt.h b/arch/x86/include/asm/ibt.h index 689880eca9ba..3ae795150374 100644 --- a/arch/x86/include/asm/ibt.h +++ b/arch/x86/include/asm/ibt.h @@ -31,6 +31,16 @@ #define __noendbr __attribute__((nocf_check)) +/* + * Create a dummy function pointer reference to prevent objtool from marking + * the function as needing to be "sealed" (i.e. ENDBR converted to NOP by + * apply_ibt_endbr()). + */ +#define IBT_NOSEAL(fname) \ + ".pushsection .discard.endbr.noseal\n\t" \ + _ASM_PTR fname "\n\t" \ + ".popsection\n\t" + static inline __attribute_const__ u32 gen_endbr(void) { u32 endbr; diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index f8382abe22ff..88623add0db4 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -316,7 +316,8 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop); ".align " __stringify(FASTOP_SIZE) " \n\t" \ ".type " name ", @function \n\t" \ name ":\n\t" \ - ASM_ENDBR + ASM_ENDBR \ + IBT_NOSEAL(name) #define FOP_FUNC(name) \ __FOP_FUNC(#name)