Message ID | 20230515092804.120600032@infradead.org |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp6791259vqo; Mon, 15 May 2023 02:45:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ZP8g4VMxAt/cnmERmj+0E3CKP8HWucgB+rX7yLFxlZVqLOJn1fePpEBNoFAqFe481OBUE X-Received: by 2002:a17:902:ab8f:b0:1ae:f37:c1a8 with SMTP id f15-20020a170902ab8f00b001ae0f37c1a8mr4517952plr.40.1684143958419; Mon, 15 May 2023 02:45:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684143958; cv=none; d=google.com; s=arc-20160816; b=O3JVZaGnbOMxTVUXSlWlwl0dD1mYP3dOq+rnDBjS7s9zb+Vi8HUYV3XAJ5h+8htWNd vVcqj61LFgFAjf5+gRfRxpmPU2kMiLr8DG4K7iyK9L/S7UqPbbzML875O7pSqOtC9Br5 Ll0buFsrebgnrHunZkbynIg/Lq83Q2ejnkBXtvSNwQd/3q5Iw7P+l6kq6rX14aG1BTVY IrVafnl1bDgT+Ah8Ux+K9YiXWv4uZMOw4lg/q1kxGkZCW4KZllcTKhnKVlXK3eOWW8WX EgvwUM2RUVs+vWSWgGGfKrcOvdioImKQVzgoXJTML1OP6U0qXJ7Q90tlWi/ToM00FFf9 oHYQ== 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=GDSo6fHJrQxhVodWxQP0Jzm08C1sRZl3ABMN/26j0Lo=; b=RpFfI6jAbbJ5gLmrhUFsIG3WcF/Yex1rswdt3MbvluQiTv+hrhiDK0eMlBk4MLrFIo kcB51lRdntYssPI+wXkV3TeK0rSNys5eSdOC8Pyeh8ljBWI7KESdiYDXPavWgAhg4fld BS0oWU8GAvqRHJeRlvlIhtWjbf5Xnh/4F87X4ym5RrPRwa1h0S2rnIW8I3vRyE+jo5Uu Qg4fR+Fe9kmjr/3NxjW2Q6mM6+vEdRYAwUqRST5a3+gLnTK6mMTXRuHE1tF/2LM98UWB MSxqmmOGM71rNMxcwG6svcEyOq+F3vNNbTsuKbspf/6/uCtsOQFsdilxC7jNtekhqVKQ yxFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Ezrj5IZn; 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 c5-20020a170902d48500b001add2ba445asi11212194plg.259.2023.05.15.02.45.45; Mon, 15 May 2023 02:45:58 -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=Ezrj5IZn; 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 S229829AbjEOJbO (ORCPT <rfc822;peekingduck44@gmail.com> + 99 others); Mon, 15 May 2023 05:31:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229603AbjEOJa6 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 15 May 2023 05:30:58 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90D7CE61 for <linux-kernel@vger.kernel.org>; Mon, 15 May 2023 02:30:56 -0700 (PDT) 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=GDSo6fHJrQxhVodWxQP0Jzm08C1sRZl3ABMN/26j0Lo=; b=Ezrj5IZnq1yfq+IwuHejrWWBPA XvKScRi27swMP/MnHdHTXjcJqDYhBR1gq+WixNNmLKKcxNvu7/u9QdAeBp3zel7XahbeZtFHognea d2IsO7GVZGeXG4uIpcgMt5fgLJ049en2MjzCe1TB8tTbytr5M9ctNR4ti6oh8+XzMw1ZB87I2vzKo WE7eLDNwxNYDf/9rxJdMeA5fIwr5BH2c5FQug8yhNjnGW/pSTIVmFzEDV6GOrPd3VVRCi3zBmRSJR oNWF98ktbHXeTp9qR04AC9lkLEg//dnnHHhFNKBZAZhOl8sHZ1nw1NBsLvYUAVDythDscbqKxCULv tqRL58JQ==; 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 1pyUXZ-003LiZ-SR; Mon, 15 May 2023 09:30:49 +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) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 6BF5F300244; Mon, 15 May 2023 11:30:48 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 3EB27202FCE90; Mon, 15 May 2023 11:30:48 +0200 (CEST) Message-ID: <20230515092804.120600032@infradead.org> User-Agent: quilt/0.66 Date: Mon, 15 May 2023 11:28:04 +0200 From: Peter Zijlstra <peterz@infradead.org> To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mhiramat@kernel.org, Andrew.Cooper3@citrix.com, jpoimboe@redhat.com Subject: [PATCH 0/2] x86/alternatives: More nops and some shrinkage 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_NONE,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765952935283003722?= X-GMAIL-MSGID: =?utf-8?q?1765952935283003722?= |
Series |
x86/alternatives: More nops and some shrinkage
|
|
Message
Peter Zijlstra
May 15, 2023, 9:28 a.m. UTC
Hi Boris, I went through my pile after seeing the x86/alternatives tip-bot messages and found these two stragglers hadn't yet made it out.
Comments
On Mon, May 15, 2023 at 10:47:42AM +0100, Andrew.Cooper3@citrix.com wrote: > On 15/05/2023 10:28 am, Peter Zijlstra wrote: > > Shrink it by 4 bytes: > > > > 0: 31 c0 xor %eax,%eax > > 2: 48 0f ba e8 3f bts $0x3f,%rax > > 7: 65 48 89 04 25 00 00 00 00 mov %rax,%gs:0x0 > > #define RESET_CALL_DEPTH \ > > - mov $0x80, %rax; \ > > - shl $56, %rax; \ > > + xor %eax, %eax; \ > > + bts $59, %rax; \ > > $63 ? > > The disassembly looks correct. Yeah, uhmm, clearly I fixed it somewhere but not on the version I send out :-( Too bad we need the RAX.W prefix... --- Subject: x86: Shorten RESET_CALL_DEPTH From: Peter Zijlstra <peterz@infradead.org> Date: Fri Feb 10 10:10:57 CET 2023 RESET_CALL_DEPTH is a pretty fat monster and blows up UNTRAIN_RET to 20 bytes: 19: 48 c7 c0 80 00 00 00 mov $0x80,%rax 20: 48 c1 e0 38 shl $0x38,%rax 24: 65 48 89 04 25 00 00 00 00 mov %rax,%gs:0x0 29: R_X86_64_32S pcpu_hot+0x10 Shrink it by 4 bytes: 0: 31 c0 xor %eax,%eax 2: 48 0f ba e8 3f bts $0x3f,%rax 7: 65 48 89 04 25 00 00 00 00 mov %rax,%gs:0x0 Shrink RESET_CALL_DEPTH_FROM_CALL by 5 bytes by only setting al, the other bits are shifted out (the same could be done for RESET_CALL_DEPTH, but the xor+bts sequence has less depencies due to the zeroing). Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- arch/x86/include/asm/nospec-branch.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -84,12 +84,12 @@ movq $-1, PER_CPU_VAR(pcpu_hot + X86_call_depth); #define RESET_CALL_DEPTH \ - mov $0x80, %rax; \ - shl $56, %rax; \ + xor %eax, %eax; \ + bts $63, %rax; \ movq %rax, PER_CPU_VAR(pcpu_hot + X86_call_depth); #define RESET_CALL_DEPTH_FROM_CALL \ - mov $0xfc, %rax; \ + movb $0xfc, %al; \ shl $56, %rax; \ movq %rax, PER_CPU_VAR(pcpu_hot + X86_call_depth); \ CALL_THUNKS_DEBUG_INC_CALLS