Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2590204rdb; Mon, 4 Dec 2023 01:40:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IGttbrhwIxhbuY/qzFXYGYjBSvFzE90FW/BX8LEqEXZILPBiAW/halUDdccHDWZD/6IcWq1 X-Received: by 2002:a05:6358:52cf:b0:170:4035:420d with SMTP id z15-20020a05635852cf00b001704035420dmr44449rwz.18.1701682836714; Mon, 04 Dec 2023 01:40:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701682836; cv=none; d=google.com; s=arc-20160816; b=Fw3Qwk2IYPd1Zq6l22Be6/S/cAl0d1/WlN6DNvoz0GyqHZU4qmnJXmrdPYKi8T4M+E WF8TNSWEFz1B5wr4Wd4IiBNP/FvK1hZJMBKSCEA9FV7LCQp3W8ao21jhGmSJlwp8KeTZ 3B6PIL8J7EyMNAH3hmiV5xPdeusOn3FHPzZHw1uATk+5ISew7cM8fzbouVAOno7fHusj T3b/mNex7Ts6m0f6Lci84AKpj0mp97+ipz6mZdJqWmqSWs0mjHCkzZex7oiEf4YDmdGg Am/c/ZvMCi8ayZmDeujgvE1NVK5jz3VvqYaTxNSwLBBzMTb3aF/byHT2KD15kW3sRHnz lNtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:user-agent:message-id :dkim-signature; bh=nS5Rsn93xMSfaJg6MM0BWPbjMY5lqaSHh/D+5cLgBSs=; fh=abAVVA/4Ak+d0eJGu6DCh50I2ZCtyA1W4ewSFh8uvFU=; b=XMu3qddcao5Bdvzs6zyZr6n02UpZCN3nSy+MGPz0PLq7oTJbJJHX0DZgDLZw+hldC0 bUyIOxsFz3QpFd0JFJaqDa6k3PNX1dP4oF081gfly/vTxbJooiIIHMwuASRuuq9GYpfG dYQAaoiI2yNBVr/fLkhagqTnIftBz/pI6Hnm4sn0rc3NEbeA2woYQUYTwqEOld9rD8y1 lbGFATA4ra5VImdck+T6u1AgCaDEgDUYKKDx5BySJ7yQI1h4zVH8NhejJogd+ETGK/vG bbYHDqk56LAdsWl35HzfXPeEHqDBzm00RbiYkATWwuD3MraSU+qytUiifiKUau5m3jhi c61g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=KZgSgwnT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id bq24-20020a056a000e1800b006cd92bdabfdsi7609885pfb.48.2023.12.04.01.40.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 01:40:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=KZgSgwnT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id BDCE2805F2DF; Mon, 4 Dec 2023 01:40:33 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234886AbjLDJkM (ORCPT + 99 others); Mon, 4 Dec 2023 04:40:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234870AbjLDJjv (ORCPT ); Mon, 4 Dec 2023 04:39:51 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB672100; Mon, 4 Dec 2023 01:39:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Subject:Cc:To:From:Date:Message-Id: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To:References; bh=nS5Rsn93xMSfaJg6MM0BWPbjMY5lqaSHh/D+5cLgBSs=; b=KZgSgwnTG8TS45KxWg/Qe0QAGx S+34NCEOBngCbOpSj7+auXP7eiVr79GdtW398KNCL3lIuJLSySrzlgdkCg6sNzIiuKtDmZ0SYY39q M+rgoMNia0m2QPZcsBgg6LUHsPIODKSFmfbtgEuSQycJJQaHxMz3k5+NuCUA5UkhTMJF54/Gq3S6o Iznve1IATn3RQctDMIrKI/Bo+Uo+Ya+9zucQpSTAhanXVqQYusoHZTOD7Q9XYJft/cnyvUc8TouBk KGpLmypXP1Dbuw/D2XrVy0rYsOLq5AVYeLwfVlLYbPMMf0BK4K/U1LxiZy5g5/Z6w+2BHfCZ3+Vqn dBwcYMoQ==; 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 1rA5QY-000X0M-GC; Mon, 04 Dec 2023 09:39:46 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 876743003F0; Mon, 4 Dec 2023 10:39:45 +0100 (CET) Message-Id: <20231204093702.989848513@infradead.org> User-Agent: quilt/0.65 Date: Mon, 04 Dec 2023 10:37:02 +0100 From: Peter Zijlstra To: Sean Christopherson , Paolo Bonzini , Josh Poimboeuf , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, x86@kernel.org, kvm@vger.kernel.org Subject: [PATCH 00/11] x86/kvm/emulate: Avoid RET for FASTOPs X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 04 Dec 2023 01:40:33 -0800 (PST) Hi! Because I needed a new objtool annotation, and I'd promised Josh I'd clean all that up a while ago, now with a healy sprinking of objtool patches... Anyway... FASTOP is special in that it relies on RET to preserve FLAGS, while normal C calling convention does not. This has been a problem before, see ba5ca5e5e6a1 ("x86/retpoline: Don't clobber RFLAGS during srso_safe_ret()") but is also a problem for call depth tracking. Fixing the call-depth tracking return thunk would be significantly harder (and more expensive), so instead change fastops to not use return. There are two separate instances, test_cc() and fastop(). The first is basically a SETCC wrapper, which seems like a very complicated (and somewhat expensive) way to read FLAGS. Instead use the code we already have to emulate JCC to fully emulate the instruction. That then leaves fastop(), which when marked noinline is guaranteed to exist only once. As such, CALL+RET isn't needed, because we'll always be RETurning to the same location, as such replace with JMP+JMP. --- arch/x86/include/asm/alternative.h | 14 +- arch/x86/include/asm/nospec-branch.h | 45 ++++-- arch/x86/include/asm/text-patching.h | 20 ++- arch/x86/kvm/emulate.c | 54 +++---- include/linux/instrumentation.h | 11 +- include/linux/objtool.h | 62 +++++---- include/linux/objtool_types.h | 12 ++ tools/include/linux/objtool_types.h | 12 ++ tools/objtool/check.c | 263 +++++++++++------------------------ 9 files changed, 208 insertions(+), 285 deletions(-)