From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755293AbdKAVGX (ORCPT ); Wed, 1 Nov 2017 17:06:23 -0400 Received: from terminus.zytor.com ([65.50.211.136]:43911 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933434AbdKAVGT (ORCPT ); Wed, 1 Nov 2017 17:06:19 -0400 Date: Wed, 1 Nov 2017 13:59:18 -0700 From: tip-bot for Ricardo Neri Message-ID: Cc: thgarnie@google.com, mingo@kernel.org, acme@redhat.com, qiaowei.ren@intel.com, ricardo.neri-calderon@linux.intel.com, tglx@linutronix.de, pbonzini@redhat.com, hpa@zytor.com, corbet@lwn.net, vbabka@suse.cz, adrian.hunter@intel.com, colin.king@canonical.com, mst@redhat.com, slaoub@gmail.com, jslaby@suse.cz, luto@kernel.org, brgerst@gmail.com, keescook@chromium.org, akpm@linux-foundation.org, bp@suse.de, lstoakes@gmail.com, paul.gortmaker@windriver.com, ray.huang@amd.com, dave.hansen@linux.intel.com, peterz@infradead.org, shuah@kernel.org, adam.buchbinder@gmail.com, ravi.v.shankar@intel.com, cmetcalf@mellanox.com, mhiramat@kernel.org, linux-kernel@vger.kernel.org, dvyukov@google.com Reply-To: mingo@kernel.org, thgarnie@google.com, acme@redhat.com, qiaowei.ren@intel.com, hpa@zytor.com, pbonzini@redhat.com, tglx@linutronix.de, ricardo.neri-calderon@linux.intel.com, mst@redhat.com, adrian.hunter@intel.com, vbabka@suse.cz, colin.king@canonical.com, corbet@lwn.net, jslaby@suse.cz, slaoub@gmail.com, luto@kernel.org, brgerst@gmail.com, paul.gortmaker@windriver.com, ray.huang@amd.com, bp@suse.de, lstoakes@gmail.com, akpm@linux-foundation.org, keescook@chromium.org, dave.hansen@linux.intel.com, peterz@infradead.org, cmetcalf@mellanox.com, ravi.v.shankar@intel.com, adam.buchbinder@gmail.com, shuah@kernel.org, dvyukov@google.com, linux-kernel@vger.kernel.org, mhiramat@kernel.org In-Reply-To: <1509135945-13762-12-git-send-email-ricardo.neri-calderon@linux.intel.com> References: <1509135945-13762-12-git-send-email-ricardo.neri-calderon@linux.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/mpx] x86/insn-eval: Add a utility function to get register offsets Git-Commit-ID: e5e45f11110191740ecb365fa8c7a25814ce8ac8 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: e5e45f11110191740ecb365fa8c7a25814ce8ac8 Gitweb: https://git.kernel.org/tip/e5e45f11110191740ecb365fa8c7a25814ce8ac8 Author: Ricardo Neri AuthorDate: Fri, 27 Oct 2017 13:25:38 -0700 Committer: Thomas Gleixner CommitDate: Wed, 1 Nov 2017 21:50:11 +0100 x86/insn-eval: Add a utility function to get register offsets The function get_reg_offset() returns the offset to the register the argument specifies as indicated in an enumeration of type offset. Callers of this function would need the definition of such enumeration. This is not needed. Instead, add helper functions for this purpose. These functions are useful in cases when, for instance, the caller needs to decide whether the operand is a register or a memory location by looking at the rm part of the ModRM byte. As of now, this is the only helper function that is needed. Signed-off-by: Ricardo Neri Signed-off-by: Thomas Gleixner Reviewed-by: Borislav Petkov Cc: "Michael S. Tsirkin" Cc: Peter Zijlstra Cc: Dave Hansen Cc: ricardo.neri@intel.com Cc: Adrian Hunter Cc: Paul Gortmaker Cc: Huang Rui Cc: Qiaowei Ren Cc: Shuah Khan Cc: Kees Cook Cc: Jonathan Corbet Cc: Jiri Slaby Cc: Dmitry Vyukov Cc: "Ravi V. Shankar" Cc: Chris Metcalf Cc: Brian Gerst Cc: Arnaldo Carvalho de Melo Cc: Andy Lutomirski Cc: Colin Ian King Cc: Chen Yucong Cc: Adam Buchbinder Cc: Vlastimil Babka Cc: Lorenzo Stoakes Cc: Masami Hiramatsu Cc: Paolo Bonzini Cc: Andrew Morton Cc: Thomas Garnier Link: https://lkml.kernel.org/r/1509135945-13762-12-git-send-email-ricardo.neri-calderon@linux.intel.com --- arch/x86/include/asm/insn-eval.h | 1 + arch/x86/lib/insn-eval.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/arch/x86/include/asm/insn-eval.h b/arch/x86/include/asm/insn-eval.h index 5cab1b1..7e8c963 100644 --- a/arch/x86/include/asm/insn-eval.h +++ b/arch/x86/include/asm/insn-eval.h @@ -12,5 +12,6 @@ #include 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); #endif /* _ASM_X86_INSN_EVAL_H */ diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c index 4931d92..405ffeb 100644 --- a/arch/x86/lib/insn-eval.c +++ b/arch/x86/lib/insn-eval.c @@ -100,6 +100,23 @@ static int get_reg_offset(struct insn *insn, struct pt_regs *regs, return regoff[regno]; } +/** + * insn_get_modrm_rm_off() - Obtain register in r/m 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 r/m part of the ModRM byte. The + * register is obtained as an offset from the base of pt_regs. In specific + * cases, the returned value can be -EDOM to indicate that the particular value + * of ModRM does not refer to a register and shall be ignored. + */ +int insn_get_modrm_rm_off(struct insn *insn, struct pt_regs *regs) +{ + return get_reg_offset(insn, regs, REG_TYPE_RM); +} + /* * return the address being referenced be instruction * for rm=3 returning the content of the rm reg