Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4680530pxj; Tue, 8 Jun 2021 22:15:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9ZN+neMPH9YgP97MaSGf2z1hyaauhXrO4RGU19yb44A0jbBEoJNMgczxtNwltrN/XI9BC X-Received: by 2002:aa7:dd4f:: with SMTP id o15mr29438480edw.174.1623215735096; Tue, 08 Jun 2021 22:15:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623215735; cv=none; d=google.com; s=arc-20160816; b=LEp+DNLPAcslnLsjpBuc0ILfMcE1EmhnDLIZQc56zaxDoQVIhWh2wyly7P+/USxAaZ SuWKoc30aQtbfHLfJuO48p66CiBHagnWXdSeGeGYv5jzCGOwFJYWdmaWjxZx4kZ/zrb+ lbkhfbmqBFYlSMopY0JUYYJaom4fLryoP2V+ZzEce+ipPSaj6b50Bdb8y99AFBz7ghZE SRuMNY4/us2nOwMDHYefxPyrHVkLN7xwtPJ/xN9HvxO0sabRW0IE1DQL8jtrr5XDOOEy Z9uEGT1Vxy9cW+/u5TvamOii2sQR9u4qCkG/OL3vwXFJkYKNpVHKzF9jjazWFANXKkQe 5qig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=SuI74bMuFvKZPmZ+25gDromKXFssqKtWKgI+mFqXxPM=; b=v/p+RecGPe+56AxBOV8Hy0gKeOff0srGzYr31+UoW343QjkdxO2wOtHNUT55VuDAkO WcgwvFL+Y+GJVeN5hiXte6LTTwZYDqQwYdWh2Idcj+NGslTUrN64Gz2ie7SxZ1QA3L6Y FvaS86cew7/MbOQQFtb17ixAXiVuImj7OfL7y8f1slVW90eL1esj67tULRSTGgUe3QA8 1Q1zwcLA74TsiH/FCoTzndL33UNXf5XWajY66K6f6+2dfad+zmWnf7eVmqQd5KQhBKud qGFp+UiAcmbmLOzXrNE5I4MgfB8kMF94KoEVXW1FM8GpF5+KWp7b70d35mIGhqK85tMk +2/A== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z19si1631971edq.486.2021.06.08.22.15.12; Tue, 08 Jun 2021 22:15:35 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233213AbhFHQBx (ORCPT + 99 others); Tue, 8 Jun 2021 12:01:53 -0400 Received: from mga14.intel.com ([192.55.52.115]:60385 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232870AbhFHQBv (ORCPT ); Tue, 8 Jun 2021 12:01:51 -0400 IronPort-SDR: VH+bSvsBgPUa8/VIY+oayqi1XlpMRgnWzxsvWQNcPgjxN9Ei2Q1/ovAXP7gxj9kR3mXvqFKOTS +/b2k23pY0XA== X-IronPort-AV: E=McAfee;i="6200,9189,10009"; a="204688349" X-IronPort-AV: E=Sophos;i="5.83,258,1616482800"; d="scan'208";a="204688349" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2021 08:59:57 -0700 IronPort-SDR: 2aPfQ6nUw0NrnEczUxZ1DM/AVLTjEEJ17d3GJcgwLsJfP3IIJbCPS0ghpERNOllQrE5LrLuSZr vcAq0jvs9VeQ== X-IronPort-AV: E=Sophos;i="5.83,258,1616482800"; d="scan'208";a="637683401" Received: from ticela-az-103.amr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.254.36.77]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2021 08:59:56 -0700 From: Kuppuswamy Sathyanarayanan To: Peter Zijlstra , Andy Lutomirski , Dave Hansen , Tony Luck , Dan Williams Cc: Andi Kleen , Kirill Shutemov , Kuppuswamy Sathyanarayanan , Raj Ashok , Sean Christopherson , linux-kernel@vger.kernel.org, Kuppuswamy Sathyanarayanan Subject: [RFC v2-fix-v3 1/4] x86/insn-eval: Introduce insn_get_modrm_reg_ptr() Date: Tue, 8 Jun 2021 08:59:21 -0700 Message-Id: <2ee28ba6f7dd5383df4a959cc6de0dfbc859245e.1623167569.git.sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Kirill A. Shutemov" The helper returns a pointer to the register indicated by ModRM byte. It's going to replace vc_insn_get_reg() in the SEV MMIO implementation. TDX MMIO implementation will also use it. Signed-off-by: Kirill A. Shutemov Signed-off-by: Kuppuswamy Sathyanarayanan --- arch/x86/include/asm/insn-eval.h | 1 + arch/x86/lib/insn-eval.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/arch/x86/include/asm/insn-eval.h b/arch/x86/include/asm/insn-eval.h index 91d7182ad2d6..041f399153b9 100644 --- a/arch/x86/include/asm/insn-eval.h +++ b/arch/x86/include/asm/insn-eval.h @@ -19,6 +19,7 @@ bool insn_has_rep_prefix(struct insn *insn); 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); +void *insn_get_modrm_reg_ptr(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 a67afd74232c..9069d0703881 100644 --- a/arch/x86/lib/insn-eval.c +++ b/arch/x86/lib/insn-eval.c @@ -850,6 +850,26 @@ int insn_get_modrm_reg_off(struct insn *insn, struct pt_regs *regs) return get_reg_offset(insn, regs, REG_TYPE_REG); } +/** + * insn_get_modrm_reg_ptr() - Obtain register pointer based on 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 a pointer within pt_regs. + */ +void *insn_get_modrm_reg_ptr(struct insn *insn, struct pt_regs *regs) +{ + int offset; + + offset = insn_get_modrm_reg_off(insn, regs); + if (offset < 0) + return NULL; + return (void *)regs + offset; +} + /** * get_seg_base_limit() - obtain base address and limit of a segment * @insn: Instruction. Must be valid. -- 2.25.1