From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751028AbdEESUb (ORCPT ); Fri, 5 May 2017 14:20:31 -0400 Received: from mga07.intel.com ([134.134.136.100]:39222 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751734AbdEESSH (ORCPT ); Fri, 5 May 2017 14:18:07 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,293,1491289200"; d="scan'208";a="96140771" From: Ricardo Neri To: Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , Andy Lutomirski , Borislav Petkov Cc: Peter Zijlstra , Andrew Morton , Brian Gerst , Chris Metcalf , Dave Hansen , Paolo Bonzini , Liang Z Li , Masami Hiramatsu , Huang Rui , Jiri Slaby , Jonathan Corbet , "Michael S. Tsirkin" , Paul Gortmaker , Vlastimil Babka , Chen Yucong , Alexandre Julliard , Stas Sergeev , Fenghua Yu , "Ravi V. Shankar" , Shuah Khan , linux-kernel@vger.kernel.org, x86@kernel.org, linux-msdos@vger.kernel.org, wine-devel@winehq.org, Ricardo Neri , Adam Buchbinder , Colin Ian King , Lorenzo Stoakes , Qiaowei Ren , Arnaldo Carvalho de Melo , Adrian Hunter , Kees Cook , Thomas Garnier , Dmitry Vyukov Subject: [PATCH v7 09/26] x86/insn-eval: Add utility function to identify string instructions Date: Fri, 5 May 2017 11:17:07 -0700 Message-Id: <20170505181724.55000-10-ricardo.neri-calderon@linux.intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170505181724.55000-1-ricardo.neri-calderon@linux.intel.com> References: <20170505181724.55000-1-ricardo.neri-calderon@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org String instructions are special because in protected mode, the linear address is always obtained via the ES segment register in operands that use the (E)DI register. Segment override prefixes are ignored. non- string instructions use DS as the default segment register and it can be overridden with a segment override prefix. This function will be used in a subsequent commmit that introduces a function to determine the segment register to use given the instruction, operands and segment override prefixes. Cc: Dave Hansen Cc: Adam Buchbinder Cc: Colin Ian King Cc: Lorenzo Stoakes Cc: Qiaowei Ren Cc: Arnaldo Carvalho de Melo Cc: Masami Hiramatsu Cc: Adrian Hunter Cc: Kees Cook Cc: Thomas Garnier Cc: Peter Zijlstra Cc: Borislav Petkov Cc: Dmitry Vyukov Cc: Ravi V. Shankar Cc: x86@kernel.org Signed-off-by: Ricardo Neri --- arch/x86/lib/insn-eval.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c index 8b16761..1634762 100644 --- a/arch/x86/lib/insn-eval.c +++ b/arch/x86/lib/insn-eval.c @@ -16,6 +16,73 @@ enum reg_type { REG_TYPE_BASE, }; +enum string_instruction { + INSB = 0x6c, + INSW_INSD = 0x6d, + OUTSB = 0x6e, + OUTSW_OUTSD = 0x6f, + MOVSB = 0xa4, + MOVSW_MOVSD = 0xa5, + CMPSB = 0xa6, + CMPSW_CMPSD = 0xa7, + STOSB = 0xaa, + STOSW_STOSD = 0xab, + LODSB = 0xac, + LODSW_LODSD = 0xad, + SCASB = 0xae, + SCASW_SCASD = 0xaf, +}; + +/** + * is_string_instruction - Determine if instruction is a string instruction + * @insn: Instruction structure containing the opcode + * + * Return: true if the instruction, determined by the opcode, is any of the + * string instructions as defined in the Intel Software Development manual. + * False otherwise. + */ +static bool is_string_instruction(struct insn *insn) +{ + insn_get_opcode(insn); + + /* all string instructions have a 1-byte opcode */ + if (insn->opcode.nbytes != 1) + return false; + + switch (insn->opcode.bytes[0]) { + case INSB: + /* fall through */ + case INSW_INSD: + /* fall through */ + case OUTSB: + /* fall through */ + case OUTSW_OUTSD: + /* fall through */ + case MOVSB: + /* fall through */ + case MOVSW_MOVSD: + /* fall through */ + case CMPSB: + /* fall through */ + case CMPSW_CMPSD: + /* fall through */ + case STOSB: + /* fall through */ + case STOSW_STOSD: + /* fall through */ + case LODSB: + /* fall through */ + case LODSW_LODSD: + /* fall through */ + case SCASB: + /* fall through */ + case SCASW_SCASD: + return true; + default: + return false; + } +} + static int get_reg_offset(struct insn *insn, struct pt_regs *regs, enum reg_type type) { -- 2.9.3