Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp277192rdb; Thu, 22 Feb 2024 03:32:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUuXh/k0gcDqD+LfejWHupJtsLgVjwNPDlc2sRsV6PzvzbD7f+iaLx1urJcsownaq+jFxG1IJTsHXfZVtwqeYZAJjEo14c6HPkijAAp7g== X-Google-Smtp-Source: AGHT+IG7Kmpm/bOYX6i47ZPElmEGynCPgqRcnaTJjemvbQP9I6y4Pyc5oqyuy6gJjnYcil3mXm8S X-Received: by 2002:a05:6402:505:b0:565:2468:7394 with SMTP id m5-20020a056402050500b0056524687394mr1698457edv.1.1708601546863; Thu, 22 Feb 2024 03:32:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708601546; cv=pass; d=google.com; s=arc-20160816; b=SSQjRr/jS3mWJqAob6CZBfAf1a3rjrLcUG40yXs3hAeamH0ToX8z16XXfw1ZZcLb4t 9XYndS3mizphmQ9IzHn3gUZvkwK/opufJr36gnLk8mG/1+EDFpOI861igs7nkIGJmeQz dRrNd4laOfWwg/X2dx8WWCJIvMctvUzx481qDPrydcDqWXdkLgiYOgFS4vSXtP+y9SPm t+HIVuBswtiGy/ZCZH2btsLsZS8LX7rVO0IIjEEBqNzxEKuYUwEvXa9s6NlErmw4XcJR kNAn0/NjUnsN5VVKk41CsljFWt3PZtCT09LSva5WIRrOwT0vsRLS+lgS61PwurjT64nP eJoA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=gO8KPtxyUezMZfkFT2x7lO+VYm55SC6jTQTVdpKarbw=; fh=TostJ64VshJEEaL4Ihe7w22OuhrK2pyj5+oyxFwI6HA=; b=tmWrT/KOSYFKPlnab1GgFmTTNI98VG9eZGBvqyebCrMIQQrMnlKTfiBxd91h1cNkLE nIi8QEzm8xRVJY8nzUckEeKEPALcpbFq9Hhn4RB3RbTDjRLNIjrsZSID+t+g6rXmQ5X5 OzA8uvs9eN12SIfP4T/+EHOSfSSXh0s3vOrlJ4SR9BisNi4PFBwj4T5X3DwbD96jSdSt y8eCdEfWjt2hJSFd6BLENFLiE2oEC1JIH9xjEPtUehdffKvDLU9jxsYh2JX5pgmCIvNt ohd2iXquhEaaCHSKICeJRzMtGAYVAKG5nh36JP/Ey8SPaaq7ASx0b5d71gRVUSNGzI8h nscg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=23gbb3FY; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-76411-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76411-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id d26-20020a50cd5a000000b00564646c2f65si4048981edj.52.2024.02.22.03.32.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 03:32:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76411-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=23gbb3FY; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-76411-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76411-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E42821F2647D for ; Thu, 22 Feb 2024 11:31:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 75D3F45C18; Thu, 22 Feb 2024 11:31:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="23gbb3FY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="oQgyZtfU" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EE0222099; Thu, 22 Feb 2024 11:31:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708601472; cv=none; b=emfVJPqLYPJP9lic2M3r7TcDPrX+uNY51+wmI6zlxEnaCqJsCgT7ssPcqdDAlf0ne9gfNlR9o0hdecFF4ol4LjeIM6uujHJaGLrhBo/mPSGUL4lUWvUoat3RTiDZOuqN74mFm4i1F3zsgh/EMePX6f+UtMqBSsasibLXJ2Qzuks= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708601472; c=relaxed/simple; bh=S5PpldvEfCWgMN5Vk/QEybamk2yANU02lkkVyahF9H8=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=V00gCegT7tY4Bu/7n41DMwm0DSJo098xagqMBnlfWLWr8UkyJyE6JWlF5pWMNYlJjGeKhNcQ1xXV7CL8a6Wu0P6J7Yxz6AVJSS0AnE6e1oee18HGsnsClagYa1v/CWXb4IXPRhHrXX0dYledwLvLy6iCNGTKcvI0wvgAE0vRqq0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=23gbb3FY; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=oQgyZtfU; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Thu, 22 Feb 2024 11:31:07 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708601468; 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=gO8KPtxyUezMZfkFT2x7lO+VYm55SC6jTQTVdpKarbw=; b=23gbb3FY2Okqnwa51OCLMp98oNM7XaJs+67IUDxGI6bf3O69G2Iu4h0AUSPg/HI7z5OkJU Vp9/vkKa3E7prNauWU409vL+6uMptHXPTsOT82g3SzN+gqW8Sr/4a/QUSUm4Wo56vWPDGv WiJaCjMksOkBx8B6FVUG2rM6+Ll03btdjnWrZSO54DLUZ7DogsaBoIwv5zClArPrhL5e/k D84FVQ8KvZ0AdI621aHIijDShGOZG2ubkKH9+GVeh3FDTp06qAXiGnY0e8esVqM5Csvn3Z G5ElVWKCegntt6GjffSZ6TtU/r4sr7DfFxl2JoW1vSqvFoS3P9kLsQbzyuY4ew== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708601468; 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=gO8KPtxyUezMZfkFT2x7lO+VYm55SC6jTQTVdpKarbw=; b=oQgyZtfUY5PwFXMzbsxfGNbodNXTkiY+Gpj41D5g2n3VndHhP/2+Mb69eUAZQ5TjLCfT1A fG8A4747UahgtbBg== From: "tip-bot2 for Nikolay Borisov" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/asm] x86/insn: Remove superfluous checks from instruction decoding routines Cc: Nikolay Borisov , Ingo Molnar , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240222111636.2214523-2-nik.borisov@suse.com> References: <20240222111636.2214523-2-nik.borisov@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170860146746.398.2924400958195588835.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the x86/asm branch of tip: Commit-ID: 427e1646f1ef6c714a5bade30ca0302edc5d46a0 Gitweb: https://git.kernel.org/tip/427e1646f1ef6c714a5bade30ca0302edc5d46a0 Author: Nikolay Borisov AuthorDate: Thu, 22 Feb 2024 13:16:35 +02:00 Committer: Ingo Molnar CommitterDate: Thu, 22 Feb 2024 12:23:04 +01:00 x86/insn: Remove superfluous checks from instruction decoding routines It's pointless checking if a particular part of an instruction is decoded before calling the routine responsible for decoding it as this check is duplicated in the routines itself. Streamline the code by removing the superfluous checks. No functional difference. Signed-off-by: Nikolay Borisov Signed-off-by: Ingo Molnar Cc: Josh Poimboeuf Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20240222111636.2214523-2-nik.borisov@suse.com --- arch/x86/lib/insn.c | 56 ++++++++++++++------------------------ tools/arch/x86/lib/insn.c | 56 ++++++++++++++------------------------ 2 files changed, 42 insertions(+), 70 deletions(-) diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c index 55e371c..3946bdc 100644 --- a/arch/x86/lib/insn.c +++ b/arch/x86/lib/insn.c @@ -268,11 +268,9 @@ int insn_get_opcode(struct insn *insn) if (opcode->got) return 0; - if (!insn->prefixes.got) { - ret = insn_get_prefixes(insn); - if (ret) - return ret; - } + ret = insn_get_prefixes(insn); + if (ret) + return ret; /* Get first opcode */ op = get_next(insn_byte_t, insn); @@ -339,11 +337,9 @@ int insn_get_modrm(struct insn *insn) if (modrm->got) return 0; - if (!insn->opcode.got) { - ret = insn_get_opcode(insn); - if (ret) - return ret; - } + ret = insn_get_opcode(insn); + if (ret) + return ret; if (inat_has_modrm(insn->attr)) { mod = get_next(insn_byte_t, insn); @@ -386,11 +382,9 @@ int insn_rip_relative(struct insn *insn) if (!insn->x86_64) return 0; - if (!modrm->got) { - ret = insn_get_modrm(insn); - if (ret) - return 0; - } + ret = insn_get_modrm(insn); + if (ret) + return 0; /* * For rip-relative instructions, the mod field (top 2 bits) * is zero and the r/m field (bottom 3 bits) is 0x5. @@ -417,11 +411,9 @@ int insn_get_sib(struct insn *insn) if (insn->sib.got) return 0; - if (!insn->modrm.got) { - ret = insn_get_modrm(insn); - if (ret) - return ret; - } + ret = insn_get_modrm(insn); + if (ret) + return ret; if (insn->modrm.nbytes) { modrm = insn->modrm.bytes[0]; @@ -460,11 +452,9 @@ int insn_get_displacement(struct insn *insn) if (insn->displacement.got) return 0; - if (!insn->sib.got) { - ret = insn_get_sib(insn); - if (ret) - return ret; - } + ret = insn_get_sib(insn); + if (ret) + return ret; if (insn->modrm.nbytes) { /* @@ -628,11 +618,9 @@ int insn_get_immediate(struct insn *insn) if (insn->immediate.got) return 0; - if (!insn->displacement.got) { - ret = insn_get_displacement(insn); - if (ret) - return ret; - } + ret = insn_get_displacement(insn); + if (ret) + return ret; if (inat_has_moffset(insn->attr)) { if (!__get_moffset(insn)) @@ -703,11 +691,9 @@ int insn_get_length(struct insn *insn) if (insn->length) return 0; - if (!insn->immediate.got) { - ret = insn_get_immediate(insn); - if (ret) - return ret; - } + ret = insn_get_immediate(insn); + if (ret) + return ret; insn->length = (unsigned char)((unsigned long)insn->next_byte - (unsigned long)insn->kaddr); diff --git a/tools/arch/x86/lib/insn.c b/tools/arch/x86/lib/insn.c index 8fd63a0..5d81924 100644 --- a/tools/arch/x86/lib/insn.c +++ b/tools/arch/x86/lib/insn.c @@ -268,11 +268,9 @@ int insn_get_opcode(struct insn *insn) if (opcode->got) return 0; - if (!insn->prefixes.got) { - ret = insn_get_prefixes(insn); - if (ret) - return ret; - } + ret = insn_get_prefixes(insn); + if (ret) + return ret; /* Get first opcode */ op = get_next(insn_byte_t, insn); @@ -339,11 +337,9 @@ int insn_get_modrm(struct insn *insn) if (modrm->got) return 0; - if (!insn->opcode.got) { - ret = insn_get_opcode(insn); - if (ret) - return ret; - } + ret = insn_get_opcode(insn); + if (ret) + return ret; if (inat_has_modrm(insn->attr)) { mod = get_next(insn_byte_t, insn); @@ -386,11 +382,9 @@ int insn_rip_relative(struct insn *insn) if (!insn->x86_64) return 0; - if (!modrm->got) { - ret = insn_get_modrm(insn); - if (ret) - return 0; - } + ret = insn_get_modrm(insn); + if (ret) + return 0; /* * For rip-relative instructions, the mod field (top 2 bits) * is zero and the r/m field (bottom 3 bits) is 0x5. @@ -417,11 +411,9 @@ int insn_get_sib(struct insn *insn) if (insn->sib.got) return 0; - if (!insn->modrm.got) { - ret = insn_get_modrm(insn); - if (ret) - return ret; - } + ret = insn_get_modrm(insn); + if (ret) + return ret; if (insn->modrm.nbytes) { modrm = insn->modrm.bytes[0]; @@ -460,11 +452,9 @@ int insn_get_displacement(struct insn *insn) if (insn->displacement.got) return 0; - if (!insn->sib.got) { - ret = insn_get_sib(insn); - if (ret) - return ret; - } + ret = insn_get_sib(insn); + if (ret) + return ret; if (insn->modrm.nbytes) { /* @@ -628,11 +618,9 @@ int insn_get_immediate(struct insn *insn) if (insn->immediate.got) return 0; - if (!insn->displacement.got) { - ret = insn_get_displacement(insn); - if (ret) - return ret; - } + ret = insn_get_displacement(insn); + if (ret) + return ret; if (inat_has_moffset(insn->attr)) { if (!__get_moffset(insn)) @@ -703,11 +691,9 @@ int insn_get_length(struct insn *insn) if (insn->length) return 0; - if (!insn->immediate.got) { - ret = insn_get_immediate(insn); - if (ret) - return ret; - } + ret = insn_get_immediate(insn); + if (ret) + return ret; insn->length = (unsigned char)((unsigned long)insn->next_byte - (unsigned long)insn->kaddr);