From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932823AbdDZSNy (ORCPT ); Wed, 26 Apr 2017 14:13:54 -0400 Received: from mga07.intel.com ([134.134.136.100]:50584 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932853AbdDZSNr (ORCPT ); Wed, 26 Apr 2017 14:13:47 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,255,1488873600"; d="scan'208";a="92517169" Message-ID: <1493230424.36058.35.camel@ranerica-desktop> Subject: Re: [v6 PATCH 05/21] x86/insn-eval: Add utility functions to get register offsets From: Ricardo Neri To: Borislav Petkov Cc: Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Andrew Morton , Brian Gerst , Chris Metcalf , Dave Hansen , Paolo Bonzini , 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, Adam Buchbinder , Colin Ian King , Lorenzo Stoakes , Qiaowei Ren , Arnaldo Carvalho de Melo , Adrian Hunter , Kees Cook , Thomas Garnier , Dmitry Vyukov Date: Wed, 26 Apr 2017 11:13:44 -0700 In-Reply-To: <20170412162850.huhhn6xfwls3qex6@pd.tnic> References: <20170308003254.27833-1-ricardo.neri-calderon@linux.intel.com> <20170308003254.27833-6-ricardo.neri-calderon@linux.intel.com> <20170412162850.huhhn6xfwls3qex6@pd.tnic> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2017-04-12 at 18:28 +0200, Borislav Petkov wrote: > On Tue, Mar 07, 2017 at 04:32:38PM -0800, Ricardo Neri wrote: > > The function insn_get_reg_offset takes as argument an enumeration that > > Please end function names with parentheses. Will do! > > And do you mean get_reg_offset(), per chance? Yes, I meant that. This was a copy/paste error. > > > indicates the type of offset that is returned: the R/M part of the ModRM > > byte, the index of the SIB byte or the base of the SIB byte. > > Err, you mean, it returns the offset to the register the argument > specifies. Yes. I will reword. > > > Callers of > > this function would need the definition of such enumeration. This is not > > needed. Instead, helper functions can be defined for this purpose can be > > added. > > "Instead, add helpers... " I will reword. > > > 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 mod part of the ModRM byte. > > > > 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/include/asm/insn-eval.h | 3 +++ > > arch/x86/lib/insn-eval.c | 51 ++++++++++++++++++++++++++++++++++++++++ > > 2 files changed, 54 insertions(+) > > > > diff --git a/arch/x86/include/asm/insn-eval.h b/arch/x86/include/asm/insn-eval.h > > index 5cab1b1..754211b 100644 > > --- a/arch/x86/include/asm/insn-eval.h > > +++ b/arch/x86/include/asm/insn-eval.h > > @@ -12,5 +12,8 @@ > > #include > > > > void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs *regs); > > +int insn_get_reg_offset_modrm_rm(struct insn *insn, struct pt_regs *regs); > > +int insn_get_reg_offset_sib_base(struct insn *insn, struct pt_regs *regs); > > +int insn_get_reg_offset_sib_base(struct insn *insn, struct pt_regs *regs); > > Forgotten to edit the copy-paste? > > Which means, nothing really needs insn_get_reg_offset_sib_index() and > you can get rid of it? Yes, I can get rid of it. > > > #endif /* _ASM_X86_INSN_EVAL_H */ > > diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c > > index 23cf010..78df1c9 100644 > > --- a/arch/x86/lib/insn-eval.c > > +++ b/arch/x86/lib/insn-eval.c > > @@ -98,6 +98,57 @@ static int get_reg_offset(struct insn *insn, struct pt_regs *regs, > > return regoff[regno]; > > } > > > > +/** > > + * insn_get_reg_offset_modrm_rm - Obtain register in r/m part of ModRM byte > > + * @insn: Instruction structure containing the ModRM byte > > + * @regs: Set of registers indicated by the ModRM byte > > That's simply struct pt_regs - not a set of registers indicated by > ModRM?!? I will reword it to say "A struct pt_regs containing register values indicated by the ModRM byte". > > > + * Obtain 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. > > Put that sentence under the "Return: " paragraph below so that it is > immediately obvious what the retvals are. Will do. > > > + * > > + * Return: Register indicated by r/m, as an offset within struct pt_regs > > + */ > > +int insn_get_reg_offset_modrm_rm(struct insn *insn, struct pt_regs *regs) > > That name is too long: insn_get_modrm_rm_off() should be enough. > > > +{ > > + return get_reg_offset(insn, regs, REG_TYPE_RM); > > +} > > + > > +/** > > + * insn_get_reg_offset_sib_base - Obtain register in base part of SiB byte > > + * @insn: Instruction structure containing the SiB byte > > + * @regs: Set of registers indicated by the SiB byte > > + * > > + * Obtain the register indicated by the base part of the SiB 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 SiB does not refer to a register. > > + * > > + * Return: Register indicated by SiB's base, as an offset within struct pt_regs Will make the spelling consistent. > > Let's stick to a single spelling: SIB, all caps. > > > + */ > > +int insn_get_reg_offset_sib_base(struct insn *insn, struct pt_regs *regs) > > insn_get_sib_base_off() > > Ditto for the rest of the comments on insn_get_reg_offset_modrm_rm() above. > > > +{ > > + return get_reg_offset(insn, regs, REG_TYPE_BASE); > > +} > > + > > +/** > > + * insn_get_reg_offset_sib_index - Obtain register in index part of SiB byte > > + * @insn: Instruction structure containing the SiB byte > > + * @regs: Set of registers indicated by the SiB byte > > + * > > + * Obtain the register indicated by the index part of the SiB byte. The > > + * register is obtained as an offset from the index of pt_regs. In specific > > + * cases, the returned value can be -EDOM to indicate that the particular value > > + * of SiB does not refer to a register. > > + * > > + * Return: Register indicated by SiB's base, as an offset within struct pt_regs > > + */ > > +int insn_get_reg_offset_sib_index(struct insn *insn, struct pt_regs *regs) > > insn_get_sib_idx_off() > > And again, if this function is unused, don't add it. Masami Hiramatsu had originally requested to add the two functions. I suppose the unneeded functions could be added if/when needed. Thanks and BR, Ricardo From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ricardo Neri Subject: Re: [v6 PATCH 05/21] x86/insn-eval: Add utility functions to get register offsets Date: Wed, 26 Apr 2017 11:13:44 -0700 Message-ID: <1493230424.36058.35.camel@ranerica-desktop> References: <20170308003254.27833-1-ricardo.neri-calderon@linux.intel.com> <20170308003254.27833-6-ricardo.neri-calderon@linux.intel.com> <20170412162850.huhhn6xfwls3qex6@pd.tnic> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20170412162850.huhhn6xfwls3qex6@pd.tnic> Sender: linux-msdos-owner@vger.kernel.org List-ID: Content-Type: text/plain; charset="us-ascii" To: Borislav Petkov Cc: Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Andrew Morton , Brian Gerst , Chris Metcalf , Dave Hansen , Paolo Bonzini , Masami Hiramatsu , Huang Rui , Jiri Slaby , Jonathan Corbet , "Michael S. Tsirkin" , Paul Gortmaker , Vlastimil Babka , Chen Yucong , Alexandre Julliard , Stas Sergeev , Fenghua Yu On Wed, 2017-04-12 at 18:28 +0200, Borislav Petkov wrote: > On Tue, Mar 07, 2017 at 04:32:38PM -0800, Ricardo Neri wrote: > > The function insn_get_reg_offset takes as argument an enumeration that > > Please end function names with parentheses. Will do! > > And do you mean get_reg_offset(), per chance? Yes, I meant that. This was a copy/paste error. > > > indicates the type of offset that is returned: the R/M part of the ModRM > > byte, the index of the SIB byte or the base of the SIB byte. > > Err, you mean, it returns the offset to the register the argument > specifies. Yes. I will reword. > > > Callers of > > this function would need the definition of such enumeration. This is not > > needed. Instead, helper functions can be defined for this purpose can be > > added. > > "Instead, add helpers... " I will reword. > > > 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 mod part of the ModRM byte. > > > > 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/include/asm/insn-eval.h | 3 +++ > > arch/x86/lib/insn-eval.c | 51 ++++++++++++++++++++++++++++++++++++++++ > > 2 files changed, 54 insertions(+) > > > > diff --git a/arch/x86/include/asm/insn-eval.h b/arch/x86/include/asm/insn-eval.h > > index 5cab1b1..754211b 100644 > > --- a/arch/x86/include/asm/insn-eval.h > > +++ b/arch/x86/include/asm/insn-eval.h > > @@ -12,5 +12,8 @@ > > #include > > > > void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs *regs); > > +int insn_get_reg_offset_modrm_rm(struct insn *insn, struct pt_regs *regs); > > +int insn_get_reg_offset_sib_base(struct insn *insn, struct pt_regs *regs); > > +int insn_get_reg_offset_sib_base(struct insn *insn, struct pt_regs *regs); > > Forgotten to edit the copy-paste? > > Which means, nothing really needs insn_get_reg_offset_sib_index() and > you can get rid of it? Yes, I can get rid of it. > > > #endif /* _ASM_X86_INSN_EVAL_H */ > > diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c > > index 23cf010..78df1c9 100644 > > --- a/arch/x86/lib/insn-eval.c > > +++ b/arch/x86/lib/insn-eval.c > > @@ -98,6 +98,57 @@ static int get_reg_offset(struct insn *insn, struct pt_regs *regs, > > return regoff[regno]; > > } > > > > +/** > > + * insn_get_reg_offset_modrm_rm - Obtain register in r/m part of ModRM byte > > + * @insn: Instruction structure containing the ModRM byte > > + * @regs: Set of registers indicated by the ModRM byte > > That's simply struct pt_regs - not a set of registers indicated by > ModRM?!? I will reword it to say "A struct pt_regs containing register values indicated by the ModRM byte". > > > + * Obtain 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. > > Put that sentence under the "Return: " paragraph below so that it is > immediately obvious what the retvals are. Will do. > > > + * > > + * Return: Register indicated by r/m, as an offset within struct pt_regs > > + */ > > +int insn_get_reg_offset_modrm_rm(struct insn *insn, struct pt_regs *regs) > > That name is too long: insn_get_modrm_rm_off() should be enough. > > > +{ > > + return get_reg_offset(insn, regs, REG_TYPE_RM); > > +} > > + > > +/** > > + * insn_get_reg_offset_sib_base - Obtain register in base part of SiB byte > > + * @insn: Instruction structure containing the SiB byte > > + * @regs: Set of registers indicated by the SiB byte > > + * > > + * Obtain the register indicated by the base part of the SiB 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 SiB does not refer to a register. > > + * > > + * Return: Register indicated by SiB's base, as an offset within struct pt_regs Will make the spelling consistent. > > Let's stick to a single spelling: SIB, all caps. > > > + */ > > +int insn_get_reg_offset_sib_base(struct insn *insn, struct pt_regs *regs) > > insn_get_sib_base_off() > > Ditto for the rest of the comments on insn_get_reg_offset_modrm_rm() above. > > > +{ > > + return get_reg_offset(insn, regs, REG_TYPE_BASE); > > +} > > + > > +/** > > + * insn_get_reg_offset_sib_index - Obtain register in index part of SiB byte > > + * @insn: Instruction structure containing the SiB byte > > + * @regs: Set of registers indicated by the SiB byte > > + * > > + * Obtain the register indicated by the index part of the SiB byte. The > > + * register is obtained as an offset from the index of pt_regs. In specific > > + * cases, the returned value can be -EDOM to indicate that the particular value > > + * of SiB does not refer to a register. > > + * > > + * Return: Register indicated by SiB's base, as an offset within struct pt_regs > > + */ > > +int insn_get_reg_offset_sib_index(struct insn *insn, struct pt_regs *regs) > > insn_get_sib_idx_off() > > And again, if this function is unused, don't add it. Masami Hiramatsu had originally requested to add the two functions. I suppose the unneeded functions could be added if/when needed. Thanks and BR, Ricardo