From patchwork Wed May 31 11:57:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 101391 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2825636vqr; Wed, 31 May 2023 05:06:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7mLRIAPfjR4Pdt3hiPlsDb3IgzMSgiwOO7+3VmOrByVuynmM9lu6wQtvqBp97ATBe51TmM X-Received: by 2002:a17:902:d2c5:b0:1a6:9762:6eed with SMTP id n5-20020a170902d2c500b001a697626eedmr5900937plc.22.1685534778513; Wed, 31 May 2023 05:06:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685534778; cv=none; d=google.com; s=arc-20160816; b=VoPgi4Q52NCDCsU+IzZ/xgfc7IO3KUd38GJ+CzB5uiDWJhG+A6hsowy1xHel9dSyKT yNCRuUNyHZpvAm/0OCEyJ16ExYWL4qxze9ZTU86gNQ5TPtsxLLPL/CDZ4tSBbYOnUsOs oTksMFyX8eCMhH+OweX33xCuF+SiEtdMQg0St0wCHjsgub6mK0CUUvWg8MWpAGzeY1Y1 KR2xwPxQnQlBiNcheMdAh246LR4+CGZl9EekCWB65lB4lbkNLVayrpQE2BeouXveF6Ld XSXxuBDGxqlYGaLBvNGcVmHk6TlqemusMN8woL8aL4K7I+59hMcxF3xYSurpSQD2qwxj KCxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=oz+q/aRG7iEvO/yg/BT9Is3z4SPuuUOoyopbHSj7v40=; b=j9/DZwDfySd9pdMWbS+hEoJSS0Jv/2GMGg8otjYY/RMVcEmVVpC4Z/5BMcAv585bek jyok7jB1l6nCCadnGSle4GU20X4OVCFr7hZWSmYS0wtcfDAmTOWKM1ZT9l2BRxmsbxQN yko0a3jbQBXQ4UEbfaQtPcn18yPLF7oMXZgqnHZ0yxCIdRUl+W5Xb/N8uyxGK2c9psDh Xi4ny7y5hKJLymRrGx2e5uSU4ekBWicZylUUe2luWcmJ32cOtoLxWUSyNdl6QCEXcevo rd+iCBDGQ2hpZove7llGuZ9V8q/YSKBHRO2NjN4JcJZaxsJyRkjkSgoKKv7wyekH16pe ojvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=r69tS5M3; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=tzmekfbd; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h6-20020a170902ac8600b001ac68a1500esi702534plr.648.2023.05.31.05.06.04; Wed, 31 May 2023 05:06:18 -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=r69tS5M3; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=tzmekfbd; 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 S235627AbjEaL5Y (ORCPT + 99 others); Wed, 31 May 2023 07:57:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235636AbjEaL5V (ORCPT ); Wed, 31 May 2023 07:57:21 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF12B121; Wed, 31 May 2023 04:57:18 -0700 (PDT) Date: Wed, 31 May 2023 11:57:16 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1685534237; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oz+q/aRG7iEvO/yg/BT9Is3z4SPuuUOoyopbHSj7v40=; b=r69tS5M3dRnEzzj5khaZM5nU/GPpIPnGVZvekOCLZRB0xN1pnrO9LVeTcO9Hhh/i6uDfo7 0nOKzAg6dCXz+xHTAzBIO1QpScX0xQMMpmmha52wp6n1kUFDg83wV0dAZare02KowzmeaF Xbuy3s1qmdW7/V6/5IP7tQENhoakyS9+o0WiSWclA13UfrYhp0wR/2QFlojQ8fbh/WZsTv 598u859C/sjSI2Ml+WjvaCbLUj52zXBDWcQrLDI6Iw9HV0keGxjSXZ0DdBvI3a40y7Ivc5 lGRCDAaemcPoDY2eHXfG0yaf+3O1CDNCCi87AL4WxE4Ev+e07CkMn7dzLaQxMw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1685534237; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oz+q/aRG7iEvO/yg/BT9Is3z4SPuuUOoyopbHSj7v40=; b=tzmekfbdcGwDJLWjY6IBJjVNeFQEDJe0vqDe9QigR+1DQ6Gsf3Oxt9ZUQOYiE0bNI9S3Y2 HfMpaCtM2wXeYtCQ== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/alternatives] x86/alternatives: Add longer 64-bit NOPs Cc: "Peter Zijlstra (Intel)" , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230515093020.661756940@infradead.org> References: <20230515093020.661756940@infradead.org> MIME-Version: 1.0 Message-ID: <168553423659.404.5660759235465936351.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails 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,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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767411316153889109?= X-GMAIL-MSGID: =?utf-8?q?1767411316153889109?= The following commit has been merged into the x86/alternatives branch of tip: Commit-ID: df25edbac31ea87b488789d44a362063542b5967 Gitweb: https://git.kernel.org/tip/df25edbac31ea87b488789d44a362063542b5967 Author: Peter Zijlstra AuthorDate: Mon, 15 May 2023 11:28:05 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Wed, 31 May 2023 10:21:21 +02:00 x86/alternatives: Add longer 64-bit NOPs By adding support for longer NOPs there are a few more alternatives that can turn into a single instruction. Add up to NOP11, the same limit where GNU as .nops also stops generating longer nops. This is because a number of uarchs have severe decode penalties for more than 3 prefixes. [ bp: Sync up with the version in tools/ while at it. ] Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20230515093020.661756940@infradead.org --- arch/x86/include/asm/nops.h | 16 ++++++++++++++-- arch/x86/kernel/alternative.c | 10 ++++++++++ tools/arch/x86/include/asm/nops.h | 16 ++++++++++++++-- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/nops.h b/arch/x86/include/asm/nops.h index c5573ea..1c1b755 100644 --- a/arch/x86/include/asm/nops.h +++ b/arch/x86/include/asm/nops.h @@ -34,6 +34,8 @@ #define BYTES_NOP7 0x8d,0xb4,0x26,0x00,0x00,0x00,0x00 #define BYTES_NOP8 0x3e,BYTES_NOP7 +#define ASM_NOP_MAX 8 + #else /* @@ -47,6 +49,9 @@ * 6: osp nopl 0x00(%eax,%eax,1) * 7: nopl 0x00000000(%eax) * 8: nopl 0x00000000(%eax,%eax,1) + * 9: cs nopl 0x00000000(%eax,%eax,1) + * 10: osp cs nopl 0x00000000(%eax,%eax,1) + * 11: osp osp cs nopl 0x00000000(%eax,%eax,1) */ #define BYTES_NOP1 0x90 #define BYTES_NOP2 0x66,BYTES_NOP1 @@ -56,6 +61,15 @@ #define BYTES_NOP6 0x66,BYTES_NOP5 #define BYTES_NOP7 0x0f,0x1f,0x80,0x00,0x00,0x00,0x00 #define BYTES_NOP8 0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00 +#define BYTES_NOP9 0x2e,BYTES_NOP8 +#define BYTES_NOP10 0x66,BYTES_NOP9 +#define BYTES_NOP11 0x66,BYTES_NOP10 + +#define ASM_NOP9 _ASM_BYTES(BYTES_NOP9) +#define ASM_NOP10 _ASM_BYTES(BYTES_NOP10) +#define ASM_NOP11 _ASM_BYTES(BYTES_NOP11) + +#define ASM_NOP_MAX 11 #endif /* CONFIG_64BIT */ @@ -68,8 +82,6 @@ #define ASM_NOP7 _ASM_BYTES(BYTES_NOP7) #define ASM_NOP8 _ASM_BYTES(BYTES_NOP8) -#define ASM_NOP_MAX 8 - #ifndef __ASSEMBLY__ extern const unsigned char * const x86_nops[]; #endif diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 93aa95a..0747d29 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -98,6 +98,11 @@ static const unsigned char x86nops[] = BYTES_NOP6, BYTES_NOP7, BYTES_NOP8, +#ifdef CONFIG_64BIT + BYTES_NOP9, + BYTES_NOP10, + BYTES_NOP11, +#endif }; const unsigned char * const x86_nops[ASM_NOP_MAX+1] = @@ -111,6 +116,11 @@ const unsigned char * const x86_nops[ASM_NOP_MAX+1] = x86nops + 1 + 2 + 3 + 4 + 5, x86nops + 1 + 2 + 3 + 4 + 5 + 6, x86nops + 1 + 2 + 3 + 4 + 5 + 6 + 7, +#ifdef CONFIG_64BIT + x86nops + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8, + x86nops + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9, + x86nops + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10, +#endif }; /* diff --git a/tools/arch/x86/include/asm/nops.h b/tools/arch/x86/include/asm/nops.h index c5573ea..1c1b755 100644 --- a/tools/arch/x86/include/asm/nops.h +++ b/tools/arch/x86/include/asm/nops.h @@ -34,6 +34,8 @@ #define BYTES_NOP7 0x8d,0xb4,0x26,0x00,0x00,0x00,0x00 #define BYTES_NOP8 0x3e,BYTES_NOP7 +#define ASM_NOP_MAX 8 + #else /* @@ -47,6 +49,9 @@ * 6: osp nopl 0x00(%eax,%eax,1) * 7: nopl 0x00000000(%eax) * 8: nopl 0x00000000(%eax,%eax,1) + * 9: cs nopl 0x00000000(%eax,%eax,1) + * 10: osp cs nopl 0x00000000(%eax,%eax,1) + * 11: osp osp cs nopl 0x00000000(%eax,%eax,1) */ #define BYTES_NOP1 0x90 #define BYTES_NOP2 0x66,BYTES_NOP1 @@ -56,6 +61,15 @@ #define BYTES_NOP6 0x66,BYTES_NOP5 #define BYTES_NOP7 0x0f,0x1f,0x80,0x00,0x00,0x00,0x00 #define BYTES_NOP8 0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00 +#define BYTES_NOP9 0x2e,BYTES_NOP8 +#define BYTES_NOP10 0x66,BYTES_NOP9 +#define BYTES_NOP11 0x66,BYTES_NOP10 + +#define ASM_NOP9 _ASM_BYTES(BYTES_NOP9) +#define ASM_NOP10 _ASM_BYTES(BYTES_NOP10) +#define ASM_NOP11 _ASM_BYTES(BYTES_NOP11) + +#define ASM_NOP_MAX 11 #endif /* CONFIG_64BIT */ @@ -68,8 +82,6 @@ #define ASM_NOP7 _ASM_BYTES(BYTES_NOP7) #define ASM_NOP8 _ASM_BYTES(BYTES_NOP8) -#define ASM_NOP_MAX 8 - #ifndef __ASSEMBLY__ extern const unsigned char * const x86_nops[]; #endif