Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp5266432imw; Wed, 20 Jul 2022 02:18:11 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tlS7BlO25e9ieTmi5QQies2UEUcxNdBi6uQOd0rhx9kTD3/Tr3gGt5at30NzwWTuOsWbiH X-Received: by 2002:a05:6402:2287:b0:43b:a9d:ab1 with SMTP id cw7-20020a056402228700b0043b0a9d0ab1mr48640217edb.325.1658308691635; Wed, 20 Jul 2022 02:18:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658308691; cv=none; d=google.com; s=arc-20160816; b=G2dw4SaedYEj/fzumagb7evI6Eee3oVx7aJ2fGFovojllbpPxiaxn80sqWfyM554cF 5UKcFAxav4myV/HRHgkgvzXVU7cjb6SIsnU/paLJpc0UloyIpeLC2i8Lygjv4GIFUL74 OTa52gEkYUbcguuvxA5g7D/ALanA8RxfcQgE3Dn+12DvV9ld8x3qz9TjRLwDhMQx3h+E KLMdtSnyM7826lRIATkMfdRiAa0pPst5jYUOY70X28x216iq5N4LOTLycXtzHjaqyy4e wbgSOYw5tapM0lKzd+OsZhy7m8SNN/w2B/UTo44SjOVw3qmjV782eYGnRGkbJ3eYyiMm OGhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:in-reply-to:subject :cc:to:dkim-signature:dkim-signature:from; bh=etRkAHwvk0Yt4QTwR5k4d8TxbYS/cmxaPYmnF5tyJBE=; b=YLDPio36MAEp7O4f9XNGJ2+mtedXjvmOqVTWMFU6AkdJO8qOJaMygTpOHtvG71V2Rt 7+/2uGekH4YzYdx9kumrVVW5KlmAM6urTAf88iOTkK5AVjgNxoiszbrf69luXK08u7cY QCueioE6FXD0o/mN8vC0XQuNc+BVi87btyt8VddthUYVV0Dh1OM6lWnXAYJjVIcBUtTW mvrj3GvQJO4ctyDMWCPAJZx9gDa8zIKmUNudXrN+V9Q6918ArJtO03H/CW8DXV/d0+qH LpgrdgbYkEsvMzp99qDd1epWaIc2XysDF3uI+4vNmXFhZT9j2tpFrBCu9LZMXhBzCIUs 8R3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=KTs6Cji4; dkim=neutral (no key) header.i=@linutronix.de header.b=ITfUnXF2; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g14-20020a056402090e00b0043b59c69ac9si15966170edz.65.2022.07.20.02.17.47; Wed, 20 Jul 2022 02:18:11 -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=@linutronix.de header.s=2020 header.b=KTs6Cji4; dkim=neutral (no key) header.i=@linutronix.de header.b=ITfUnXF2; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231373AbiGTJAt (ORCPT + 99 others); Wed, 20 Jul 2022 05:00:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231143AbiGTJAs (ORCPT ); Wed, 20 Jul 2022 05:00:48 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47CB22872B for ; Wed, 20 Jul 2022 02:00:47 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1658307645; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=etRkAHwvk0Yt4QTwR5k4d8TxbYS/cmxaPYmnF5tyJBE=; b=KTs6Cji4o4bVnuNJ89tP2WMsiMCVMa8kCeozN7M6HGxit0+CrMPl3rmsCvYp2oG+nR0MG6 7JjxfWD/dknMoQcdS3ZkezLZsiq5LEpEWo9AN1QTbZt3ldHjGgyq1HEpsZmQW1Uy8VgIEl fM9Zm0Dh/Fc3XLLpVWx6TasQgUh+ntT3quLHk4XLwxN6RdKmwdX2q8IHOnAD38A4UyEMTQ Dl1UiwFUzAmU31aUOyD/TSHPoriQrdvIqEXmuxOhUPhL+woULyxYWrSPNxzN4yxTkoIJur TNUIje1iVFEpGmb5IjF0bmtJGgOoXB33f/vY4u8ZP+5YTTzQFOnjNN5ALNR3tA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1658307645; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=etRkAHwvk0Yt4QTwR5k4d8TxbYS/cmxaPYmnF5tyJBE=; b=ITfUnXF2OuRukEvoRM0TFudV7bK9IfOzC7vNK64OnLimIHvGfPfvQ2E5UYDKdawN0zwklP xFliR6lUEjU1eYCQ== To: Peter Zijlstra , Sami Tolvanen Cc: Linus Torvalds , LKML , the arch/x86 maintainers , Tim Chen , Josh Poimboeuf , Andrew Cooper , Pawan Gupta , Johannes Wikner , Alyssa Milburn , Jann Horn , "H.J. Lu" , Joao Moreira , Joseph Nuzman , Steven Rostedt , Juergen Gross , Masami Hiramatsu , Alexei Starovoitov , Daniel Borkmann Subject: Re: [patch 00/38] x86/retbleed: Call depth tracking mitigation In-Reply-To: Date: Wed, 20 Jul 2022 11:00:44 +0200 Message-ID: <87y1wotayr.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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 Tue, Jul 19 2022 at 01:51, Peter Zijlstra wrote: > On Mon, Jul 18, 2022 at 03:48:04PM -0700, Sami Tolvanen wrote: >> On Mon, Jul 18, 2022 at 2:18 PM Peter Zijlstra wrote: >> > Ofc, we can still put the whole: >> > >> > sarq $5, PER_CPU_VAR(__x86_call_depth); >> > jmp \func_direct >> > >> > thing in front of that. >> >> Sure, that would work. > > So if we assume \func starts with ENDBR, and further assume we've fixed > up every direct jmp/call to land at +4, we can overwrite the ENDBR with > part of the SARQ, that leaves us 6 more byte, placing the immediate at > -10 if I'm not mis-counting. > > Now, the call sites are: > > 41 81 7b fa 78 56 34 12 cmpl $0x12345678, -6(%r11) > 74 02 je 1f > 0f 0b ud2 > e8 00 00 00 00 1: call __x86_indirect_thunk_r11 > > That means the offset of +10 lands in the middle of the CALL > instruction, and since we only have 16 thunks there is a limited number > of byte patterns available there. > > This really isn't as nice as the -6 but might just work well enough, > hmm? So I added a 32byte padding and put the thunk at the start: sarq $5, PER_CPU_VAR(__x86_call_depth); jmp \func_direct For sockperf that costs about 1% performance vs. the 16 byte variant. For mitigations=off it's a ~0.5% drop. That's on a SKL. Did not check on other systems yet. Thanks, tglx