Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4937202pxb; Tue, 5 Oct 2021 13:43:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFqi07k62wmoB5fy36pVvIqYVNxtAG7PIxHvq7WVCtq8Re/mtjo54xHc5zWu5MEry3us2v X-Received: by 2002:a17:90b:1885:: with SMTP id mn5mr6307197pjb.75.1633466633078; Tue, 05 Oct 2021 13:43:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633466633; cv=none; d=google.com; s=arc-20160816; b=TFgsZFTeT0LccWHQVJEJzEgEuCrBAzeZaNGvbgtof+mwgmF/PTSLNLvyWDYdf22Tza gVg5SgnudkmvhLWqePG9DSrbL+r3/svSh+D+V91zkHkw0SbwN8wYEVZ8hsJA60U5eMJE 6XlvsZVKnT7K85VzSOWucB8QyhDvdNpK6FygIihmpXQFTnl9FYZuzVZEgq5sWoikoWxP T2rNfIx/XlQy+noHtyah+fIT8u26LnPOaodPOLQKuC3GIElVBD5yyEt41Wxv8nK9V73i 7Lq8SSTF16roYkDGFxQtFCFBuMESAohwbfq2JcnstPQeB0kWq2tjOrjTS/niZrkCVbgR Qjnw== 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; bh=Emb2rmNK5HQXs+uCVKSIvQMzl9CZH5886NgEM/aGSj0=; b=Q69B/PMFc2UGvKNXDkyKwhoYfnDzb0IQ9qdc8E27ruUe1XXMAB3S6GvLWUxBpV1JrD F+j+n1wBn7tiowwrykMSvI6Ueq45eBTOh7+Ef3NpDQlX/2PWKhK+rY22UEjPswQgk6fr rPK5rd4xZdcjXQI00IjcsoXLLw6Y1pUsk6vwtApFVIs7xuBVDk3NAoSPncez8iqpjXZg KWBb1IfDu5UDFf1gypg6CjNr64YH3AW9PNhhhh+/uUp0BRh9nZuxUrkp4o+3b67So3Sn N6ymA2o8wA2z9rRat0LzDoigSOizhdJYkOIn7kK42I3hxl7JK6HG2gLXWgQBCFcv0oFB dyEw== 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 u185si22631422pfb.31.2021.10.05.13.43.39; Tue, 05 Oct 2021 13:43:53 -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 S236654AbhJEUoH (ORCPT + 99 others); Tue, 5 Oct 2021 16:44:07 -0400 Received: from mga07.intel.com ([134.134.136.100]:11170 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235949AbhJEUnx (ORCPT ); Tue, 5 Oct 2021 16:43:53 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10128"; a="289354603" X-IronPort-AV: E=Sophos;i="5.85,349,1624345200"; d="scan'208";a="289354603" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2021 13:42:01 -0700 X-IronPort-AV: E=Sophos;i="5.85,349,1624345200"; d="scan'208";a="523979576" Received: from alyee-mobl.amr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.254.5.222]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2021 13:42:01 -0700 From: Kuppuswamy Sathyanarayanan To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, Paolo Bonzini , David Hildenbrand , Andrea Arcangeli , Josh Poimboeuf , "H . Peter Anvin" Cc: Dave Hansen , Tony Luck , Dan Williams , Andi Kleen , Kirill Shutemov , Sean Christopherson , Kuppuswamy Sathyanarayanan , linux-kernel@vger.kernel.org Subject: [PATCH v7 06/10] x86/insn-eval: Introduce insn_get_modrm_reg_ptr() Date: Tue, 5 Oct 2021 13:41:32 -0700 Message-Id: <20211005204136.1812078-7-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211005204136.1812078-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20211005204136.1812078-1-sathyanarayanan.kuppuswamy@linux.intel.com> 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 Reviewed-by: Andi Kleen Reviewed-by: Tony Luck Signed-off-by: Kuppuswamy Sathyanarayanan --- Changes since v6: * None Changes since v5: * None Changes since v4: * None Changes since v3: * None Changes since v2: * None 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 a1d24fdc07cf..fbaa3fa24bde 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