Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1705291ybh; Tue, 14 Jul 2020 05:19:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynmeZbfOp3Gpmp2STsQpo4gyMw1SAuXpNK6FbHMmZ7UNRjuHNK9x1MtlELRDQc+/FHXaw5 X-Received: by 2002:a17:906:d8db:: with SMTP id re27mr4136052ejb.554.1594729140177; Tue, 14 Jul 2020 05:19:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594729140; cv=none; d=google.com; s=arc-20160816; b=bN2ZptPNJZhgopTq0M4ClLkfdJpwGjMlhk8ZuODDuf1xWpDqp3M7EfWiBVHZL4Z1XL njRE15Wf3FCMFe/oYLRU4UepXHOK5L/xzq9dJE9Y/WNgK48pJSBYbxKk0d6HahTnO6Lw QyM6UNQivwl46cPft7dJoD4E+oETAiv0G7z9KRWVxmiC8jv68ptY6GXoIAi4o1PbYVMU Slrv/7VdkLt1tbHBaVSe3RqawO2iORGWebYxmp9BVDVvRFSLgH249y3RJFzj2y/sXEv/ L1AwShgbq/CfeD3j+9y3J6fhGK1QEky3meODzpnaT3h8dM5FEGlOflsMOnZrNm57uoBI ISeg== 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=EhypJMHzxHj6B4i1jIcIHtZ8tWlJXSrPUQrWktwgtvs=; b=JbbxBRalH1yBb3EB1RUteXN3I8/cy/V2J+/iATLbyPBEan84DLVKK8J+q1t3BeonIn bR2ChMsWYffZACbyKpzj3ivJeYlEZNDwO2nsHfp2ypn9mutpSYcOlnXx79SY3D2419Jy +On28g+3dENgQ4Qts9zh4AGqJY9uFuabwa4MmZGShQHyaRr07yTSOgya9zheH7P+RYY+ u8Yi1DDy21bV5HUv4jnnvsGN+42H4CUbJtDpqmRnTqLjVw4qfDVs4w1G64qMB0j8eeuP SAvirbAxs0YMOA/NhcM0cOuhxz2Pgge2MALPhqCBZe3HHm3Hy5sfkWZroDVpxtGHHffb aKGA== 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 r23si10492336edy.317.2020.07.14.05.18.36; Tue, 14 Jul 2020 05:19:00 -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 S1728206AbgGNMKk (ORCPT + 99 others); Tue, 14 Jul 2020 08:10:40 -0400 Received: from 8bytes.org ([81.169.241.247]:52864 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728168AbgGNMKj (ORCPT ); Tue, 14 Jul 2020 08:10:39 -0400 Received: from cap.home.8bytes.org (p5b006776.dip0.t-ipconnect.de [91.0.103.118]) (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 E052E4CA; Tue, 14 Jul 2020 14:10:37 +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 v4 09/75] x86/insn: Add insn_get_modrm_reg_off() Date: Tue, 14 Jul 2020 14:08:11 +0200 Message-Id: <20200714120917.11253-10-joro@8bytes.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714120917.11253-1-joro@8bytes.org> References: <20200714120917.11253-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 --- 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.27.0