Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2009010pxa; Mon, 24 Aug 2020 02:21:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlh0L6cSYaU8tS2rGF7gD86OanSF/N/rJ1nWgSCp2jUjRJPRsXRH2Xb44eMsAkjGC4NJs6 X-Received: by 2002:aa7:c5c3:: with SMTP id h3mr4655247eds.246.1598260890428; Mon, 24 Aug 2020 02:21:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598260890; cv=none; d=google.com; s=arc-20160816; b=WTD9anXgi1FUr+PlnEsZQQiiaLm6DGpMJY9GDskcdIxH6sBGi1R0lyj7abCFyx/Dq1 HrE6yqZcZY9haQRyN5MOhcu3mtk4A/NTlbJdrqAmIv0dMD3wgQBMSLzBoa8G/WSvit8B c9+h2pKgqa5sLYoHz/4vNGdMuteMaasCFG3l82QXd0gCEmjA0qXoFv3MhLbIoC52Kt58 Ajg3d5ocJGcIrbzdoCTN2aJogF2JyCzE788Jq4rGQQmH+1H1XDV8c1a90FGyrmcOz9eE 3GthfOT2U6xuQC9MpwbxPXabHUFUygFHUFRYIyJ6sIEwyJgd3tTojBzxCSVAiB8S4Ca2 r9uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=x6KMcmdCI8IwbDFfPMcj5RBNn6V10HOgukQSJMdR+GM=; b=jYSBdXMRk19HyBlYVtyymWJ6BOtaqfj8gvCE6zjAaaSO5YAFh0xsB17Ora4hy+yQ5V FNt4GiMKCVgDLcfOAL6WfQfVP1xlABpO92QpkLTE5iTBgiwT7Mno5AMhtHCfr/9sJ0Jk bpIq3UeA6ME+8Px1U2r6Oi1/VpE/L6hHj/SYJL5JSDMoebhrZFW4zNdQT7sbnzRL6NCg iNdLXkxRywhido28mod7vNfMdPK11kQejJdW51PLJLaLBZY0tRdVHpGU5AGYw4UQlBpU GjFQKzVEnE0krykU9+tHZTGK7W7+zba7CJMu0X/Wl0Zff6vq0wjSblTS1huHdsl6hhVY 8cpQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n22si3997273ejx.529.2020.08.24.02.21.07; Mon, 24 Aug 2020 02:21:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730435AbgHXJS0 (ORCPT + 99 others); Mon, 24 Aug 2020 05:18:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730425AbgHXIz6 (ORCPT ); Mon, 24 Aug 2020 04:55:58 -0400 Received: from theia.8bytes.org (8bytes.org [IPv6:2a01:238:4383:600:38bc:a715:4b6d:a889]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D135BC061573; Mon, 24 Aug 2020 01:55:57 -0700 (PDT) Received: from cap.home.8bytes.org (p4ff2bb8d.dip0.t-ipconnect.de [79.242.187.141]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by theia.8bytes.org (Postfix) with ESMTPSA id 5FB1C664; Mon, 24 Aug 2020 10:55:51 +0200 (CEST) From: Joerg Roedel To: x86@kernel.org Cc: Joerg Roedel , Joerg Roedel , Masami Hiramatsu , hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , David Rientjes , Cfir Cohen , Erdem Aktas , Mike Stunes , Sean Christopherson , Martin Radev , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v6 10/76] x86/insn: Add insn_get_modrm_reg_off() Date: Mon, 24 Aug 2020 10:54:05 +0200 Message-Id: <20200824085511.7553-11-joro@8bytes.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200824085511.7553-1-joro@8bytes.org> References: <20200824085511.7553-1-joro@8bytes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel Add a function to the instruction decoder which returns the pt_regs offset of the register specified in the reg field of the modrm byte. Signed-off-by: Joerg Roedel Acked-by: Masami Hiramatsu Link: https://lore.kernel.org/r/20200724160336.5435-10-joro@8bytes.org --- arch/x86/include/asm/insn-eval.h | 1 + arch/x86/lib/insn-eval.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/arch/x86/include/asm/insn-eval.h b/arch/x86/include/asm/insn-eval.h index 392b4fe377f9..f748f57f1491 100644 --- a/arch/x86/include/asm/insn-eval.h +++ b/arch/x86/include/asm/insn-eval.h @@ -17,6 +17,7 @@ void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs *regs); int insn_get_modrm_rm_off(struct insn *insn, struct pt_regs *regs); +int insn_get_modrm_reg_off(struct insn *insn, struct pt_regs *regs); unsigned long insn_get_seg_base(struct pt_regs *regs, int seg_reg_idx); int insn_get_code_seg_params(struct pt_regs *regs); int insn_fetch_from_user(struct pt_regs *regs, diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c index f52046f90dd3..a8ac5c5e94f0 100644 --- a/arch/x86/lib/insn-eval.c +++ b/arch/x86/lib/insn-eval.c @@ -20,6 +20,7 @@ enum reg_type { REG_TYPE_RM = 0, + REG_TYPE_REG, REG_TYPE_INDEX, REG_TYPE_BASE, }; @@ -441,6 +442,13 @@ static int get_reg_offset(struct insn *insn, struct pt_regs *regs, regno += 8; break; + case REG_TYPE_REG: + regno = X86_MODRM_REG(insn->modrm.value); + + if (X86_REX_R(insn->rex_prefix.value)) + regno += 8; + break; + case REG_TYPE_INDEX: regno = X86_SIB_INDEX(insn->sib.value); if (X86_REX_X(insn->rex_prefix.value)) @@ -809,6 +817,21 @@ int insn_get_modrm_rm_off(struct insn *insn, struct pt_regs *regs) return get_reg_offset(insn, regs, REG_TYPE_RM); } +/** + * insn_get_modrm_reg_off() - Obtain register in reg part of the ModRM byte + * @insn: Instruction containing the ModRM byte + * @regs: Register values as seen when entering kernel mode + * + * Returns: + * + * The register indicated by the reg part of the ModRM byte. The + * register is obtained as an offset from the base of pt_regs. + */ +int insn_get_modrm_reg_off(struct insn *insn, struct pt_regs *regs) +{ + return get_reg_offset(insn, regs, REG_TYPE_REG); +} + /** * get_seg_base_limit() - obtain base address and limit of a segment * @insn: Instruction. Must be valid. -- 2.28.0