From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6AF8C433EF for ; Wed, 9 Mar 2022 07:58:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230499AbiCIH7X (ORCPT ); Wed, 9 Mar 2022 02:59:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230496AbiCIH45 (ORCPT ); Wed, 9 Mar 2022 02:56:57 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 597EA167F8A; Tue, 8 Mar 2022 23:55:28 -0800 (PST) Date: Wed, 09 Mar 2022 07:55:17 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1646812518; 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=PauVIadOi8Ec6TlyqUEW+QIq0oZ2IIlFpuf0LighoLM=; b=p9mpHjP6Kzf7a3kpTo17ja16DOO6bxe4/D9eqAsxSUSqfITptOnZPghd+rSypL9yYJ6rCB w4t/l9Tj03Jg9vxJfS4O7MYCZrD740rfC4HiThR3heBmOWVNpStJmiCR/NFDzg5MbdYJCg octfpTB7nb3qK6N1hRX67MWfhuKUIt2xQftRUBXCBJAhQU1ljwjwvLlctzIJr7tvDBzvt0 7Uvc9UV4s86M1su437o+Gs6UHsEnwCtNfCFSGpYBVjRBcWTCsjuKc4/6vToCyQoGmeFKvo 5/o6WDN8y3oCuUoNIBL+CjF8LJbKbeYxNio07mIGrRmu1fR7nWkvdl7OSPKfTQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1646812518; 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=PauVIadOi8Ec6TlyqUEW+QIq0oZ2IIlFpuf0LighoLM=; b=2MSzeeh5NcnYf7QRM86Lxtbh3iGkpz33f1mbAP62OmIeW9GeGwVamE2UuMFriLCN2rn6wq heSLQWBgMLc9p7Bw== From: "tip-bot2 for Fenghua Yu" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/core] tools/objtool: Check for use of the ENQCMD instruction in the kernel Cc: Fenghua Yu , Borislav Petkov , Tony Luck , Josh Poimboeuf , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220207230254.3342514-11-fenghua.yu@intel.com> References: <20220207230254.3342514-11-fenghua.yu@intel.com> MIME-Version: 1.0 Message-ID: <164681251774.16921.8398427805729021263.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/core branch of tip: Commit-ID: 58ab8f3f37d0e51cd4206ce0588662cb7bfce5f1 Gitweb: https://git.kernel.org/tip/58ab8f3f37d0e51cd4206ce0588662cb7bfce5f1 Author: Fenghua Yu AuthorDate: Mon, 07 Feb 2022 15:02:53 -08:00 Committer: Peter Zijlstra CommitterDate: Tue, 08 Mar 2022 23:53:21 +01:00 tools/objtool: Check for use of the ENQCMD instruction in the kernel The ENQCMD instruction implicitly accesses the PASID_MSR to fill in the pasid field of the descriptor being submitted to an accelerator. But there is no precise (and stable across kernel changes) point at which the PASID_MSR is updated from the value for one task to the next. Kernel code that uses accelerators must always use the ENQCMDS instruction which does not access the PASID_MSR. Check for use of the ENQCMD instruction in the kernel and warn on its usage. Signed-off-by: Fenghua Yu Signed-off-by: Borislav Petkov Reviewed-by: Tony Luck Acked-by: Josh Poimboeuf Link: https://lore.kernel.org/r/20220207230254.3342514-11-fenghua.yu@intel.com --- tools/objtool/arch/x86/decode.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c index c10ef78..479e769 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -112,7 +112,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec const struct elf *elf = file->elf; struct insn insn; int x86_64, ret; - unsigned char op1, op2, + unsigned char op1, op2, op3, rex = 0, rex_b = 0, rex_r = 0, rex_w = 0, rex_x = 0, modrm = 0, modrm_mod = 0, modrm_rm = 0, modrm_reg = 0, sib = 0, /* sib_scale = 0, */ sib_index = 0, sib_base = 0; @@ -139,6 +139,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec op1 = insn.opcode.bytes[0]; op2 = insn.opcode.bytes[1]; + op3 = insn.opcode.bytes[2]; if (insn.rex_prefix.nbytes) { rex = insn.rex_prefix.bytes[0]; @@ -491,6 +492,14 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec /* nopl/nopw */ *type = INSN_NOP; + } else if (op2 == 0x38 && op3 == 0xf8) { + if (insn.prefixes.nbytes == 1 && + insn.prefixes.bytes[0] == 0xf2) { + /* ENQCMD cannot be used in the kernel. */ + WARN("ENQCMD instruction at %s:%lx", sec->name, + offset); + } + } else if (op2 == 0xa0 || op2 == 0xa8) { /* push fs/gs */