From: Masami Hiramatsu <mhiramat@kernel.org>
To: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
"H. Peter Anvin" <hpa@zytor.com>,
Andy Lutomirski <luto@kernel.org>, Borislav Petkov <bp@suse.de>,
Peter Zijlstra <peterz@infradead.org>,
Andrew Morton <akpm@linux-foundation.org>,
Brian Gerst <brgerst@gmail.com>,
Chris Metcalf <cmetcalf@mellanox.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Liang Z Li <liang.z.li@intel.com>, Huang Rui <ray.huang@amd.com>,
Jiri Slaby <jslaby@suse.cz>, Jonathan Corbet <corbet@lwn.net>,
"Michael S. Tsirkin" <mst@redhat.com>,
Paul Gortmaker <paul.gortmaker@windriver.com>,
Vlastimil Babka <vbabka@suse.cz>, Chen Yucong <slaoub@gmail.com>,
Alexandre Julliard <julliard@winehq.org>, Fenghua Yu <fenghu>
Subject: Re: [v3 PATCH 04/10] x86/insn-kernel: Add a function to obtain register offset in ModRM
Date: Fri, 27 Jan 2017 16:53:31 +0900 [thread overview]
Message-ID: <20170127165331.616cc678182a697ee0e6dfae@kernel.org> (raw)
In-Reply-To: <1485410836.41148.56.camel@ranerica-desktop>
On Wed, 25 Jan 2017 22:07:16 -0800
Ricardo Neri <ricardo.neri-calderon@linux.intel.com> wrote:
> Hi Masami,
>
> On Thu, 2017-01-26 at 11:11 +0900, Masami Hiramatsu wrote:
> > On Wed, 25 Jan 2017 12:23:47 -0800
> > Ricardo Neri <ricardo.neri-calderon@linux.intel.com> wrote:
> >
> > > The function insn_get_reg_offset requires a type to indicate whether
> > > the returned offset is that given by by the ModRM or the SIB byte.
> > > Callers of this function would need the definition of the type struct.
> > > This is not needed. Instead, auxiliary functions can be defined for
> > > this purpose.
> > >
> > > When the operand is a register, the emulation code for User-Mode
> > > Instruction Prevention needs to know the offset of the register indicated
> > > in the r/m part of the ModRM byte. Thus, start by adding an auxiliary
> > > function for this purpose.
> >
> > Hmm, why wouldn't you just rename it to insn_get_reg_offset() and export it?
>
> Do you mean exporting the structure that I mention above? The problem
> that I am trying to solve is that callers sometimes want to know the
> offset of the register encoded in the SiB or the ModRM bytes. I could
> use something
>
> insn_get_reg_offset(insn, regs, INSN_TYPE_MODRM)
> insn_get_reg_offset(insn, regs, INSN_TYPE_SIB)
>
> Instead, I opted for
>
> insn_get_reg_offset_rm(insn, regs)
> insn_get_reg_offset_sib(insn, regs)
>
> to avoid exposing an enum with the INSN_TYPE_MODRM, INSN_TYPE_SIB.
OK, if so, I think you should export both of them at once, not only
insn_get_reg_offset_rm().
Thank you,
>
> If you feel that the former makes more sense, I can change the
> implementation.
>
> Thanks and BR,
> Ricardo
> >
> > Thank you,
> >
> > >
> > > Cc: Dave Hansen <dave.hansen@linux.intel.com>
> > > Cc: Adam Buchbinder <adam.buchbinder@gmail.com>
> > > Cc: Colin Ian King <colin.king@canonical.com>
> > > Cc: Lorenzo Stoakes <lstoakes@gmail.com>
> > > Cc: Qiaowei Ren <qiaowei.ren@intel.com>
> > > Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> > > Cc: Masami Hiramatsu <mhiramat@kernel.org>
> > > Cc: Adrian Hunter <adrian.hunter@intel.com>
> > > Cc: Kees Cook <keescook@chromium.org>
> > > Cc: Thomas Garnier <thgarnie@google.com>
> > > Cc: Peter Zijlstra <peterz@infradead.org>
> > > Cc: Borislav Petkov <bp@suse.de>
> > > Cc: Dmitry Vyukov <dvyukov@google.com>
> > > Cc: Ravi V. Shankar <ravi.v.shankar@intel.com>
> > > Cc: x86@kernel.org
> > > Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
> > > ---
> > > arch/x86/include/asm/insn-kernel.h | 1 +
> > > arch/x86/lib/insn-kernel.c | 5 +++++
> > > 2 files changed, 6 insertions(+)
> > >
> > > diff --git a/arch/x86/include/asm/insn-kernel.h b/arch/x86/include/asm/insn-kernel.h
> > > index aef416a..3f34649 100644
> > > --- a/arch/x86/include/asm/insn-kernel.h
> > > +++ b/arch/x86/include/asm/insn-kernel.h
> > > @@ -12,5 +12,6 @@
> > > #include <asm/ptrace.h>
> > >
> > > void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs *regs);
> > > +int insn_get_reg_offset_rm(struct insn *insn, struct pt_regs *regs);
> > >
> > > #endif /* _ASM_X86_INSN_KERNEL_H */
> > > diff --git a/arch/x86/lib/insn-kernel.c b/arch/x86/lib/insn-kernel.c
> > > index 8072abe..267cab4 100644
> > > --- a/arch/x86/lib/insn-kernel.c
> > > +++ b/arch/x86/lib/insn-kernel.c
> > > @@ -95,6 +95,11 @@ static int get_reg_offset(struct insn *insn, struct pt_regs *regs,
> > > return regoff[regno];
> > > }
> > >
> > > +int insn_get_reg_offset_rm(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
> > > --
> > > 2.9.3
> > >
> >
> >
>
>
--
Masami Hiramatsu <mhiramat@kernel.org>
WARNING: multiple messages have this Message-ID (diff)
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
"H. Peter Anvin" <hpa@zytor.com>,
Andy Lutomirski <luto@kernel.org>, Borislav Petkov <bp@suse.de>,
Peter Zijlstra <peterz@infradead.org>,
Andrew Morton <akpm@linux-foundation.org>,
Brian Gerst <brgerst@gmail.com>,
Chris Metcalf <cmetcalf@mellanox.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Liang Z Li <liang.z.li@intel.com>, Huang Rui <ray.huang@amd.com>,
Jiri Slaby <jslaby@suse.cz>, Jonathan Corbet <corbet@lwn.net>,
"Michael S. Tsirkin" <mst@redhat.com>,
Paul Gortmaker <paul.gortmaker@windriver.com>,
Vlastimil Babka <vbabka@suse.cz>, Chen Yucong <slaoub@gmail.com>,
Alexandre Julliard <julliard@winehq.org>,
Fenghua Yu <fenghua.yu@intel.com>, Stas Sergeev <stsp@list.ru>,
"Ravi V. Shankar" <ravi.v.shankar@intel.com>,
Shuah Khan <shuah@kernel.org>,
linux-kernel@vger.kernel.org, x86@kernel.org,
linux-msdos@vger.kernel.org, wine-devel@winehq.org,
Adam Buchbinder <adam.buchbinder@gmail.com>,
Colin Ian King <colin.king@canonical.com>,
Lorenzo Stoakes <lstoakes@gmail.com>,
Qiaowei Ren <qiaowei.ren@intel.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Kees Cook <keescook@chromium.org>,
Thomas Garnier <thgarnie@google.com>,
Dmitry Vyukov <dvyukov@google.com>
Subject: Re: [v3 PATCH 04/10] x86/insn-kernel: Add a function to obtain register offset in ModRM
Date: Fri, 27 Jan 2017 16:53:31 +0900 [thread overview]
Message-ID: <20170127165331.616cc678182a697ee0e6dfae@kernel.org> (raw)
In-Reply-To: <1485410836.41148.56.camel@ranerica-desktop>
On Wed, 25 Jan 2017 22:07:16 -0800
Ricardo Neri <ricardo.neri-calderon@linux.intel.com> wrote:
> Hi Masami,
>
> On Thu, 2017-01-26 at 11:11 +0900, Masami Hiramatsu wrote:
> > On Wed, 25 Jan 2017 12:23:47 -0800
> > Ricardo Neri <ricardo.neri-calderon@linux.intel.com> wrote:
> >
> > > The function insn_get_reg_offset requires a type to indicate whether
> > > the returned offset is that given by by the ModRM or the SIB byte.
> > > Callers of this function would need the definition of the type struct.
> > > This is not needed. Instead, auxiliary functions can be defined for
> > > this purpose.
> > >
> > > When the operand is a register, the emulation code for User-Mode
> > > Instruction Prevention needs to know the offset of the register indicated
> > > in the r/m part of the ModRM byte. Thus, start by adding an auxiliary
> > > function for this purpose.
> >
> > Hmm, why wouldn't you just rename it to insn_get_reg_offset() and export it?
>
> Do you mean exporting the structure that I mention above? The problem
> that I am trying to solve is that callers sometimes want to know the
> offset of the register encoded in the SiB or the ModRM bytes. I could
> use something
>
> insn_get_reg_offset(insn, regs, INSN_TYPE_MODRM)
> insn_get_reg_offset(insn, regs, INSN_TYPE_SIB)
>
> Instead, I opted for
>
> insn_get_reg_offset_rm(insn, regs)
> insn_get_reg_offset_sib(insn, regs)
>
> to avoid exposing an enum with the INSN_TYPE_MODRM, INSN_TYPE_SIB.
OK, if so, I think you should export both of them at once, not only
insn_get_reg_offset_rm().
Thank you,
>
> If you feel that the former makes more sense, I can change the
> implementation.
>
> Thanks and BR,
> Ricardo
> >
> > Thank you,
> >
> > >
> > > Cc: Dave Hansen <dave.hansen@linux.intel.com>
> > > Cc: Adam Buchbinder <adam.buchbinder@gmail.com>
> > > Cc: Colin Ian King <colin.king@canonical.com>
> > > Cc: Lorenzo Stoakes <lstoakes@gmail.com>
> > > Cc: Qiaowei Ren <qiaowei.ren@intel.com>
> > > Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> > > Cc: Masami Hiramatsu <mhiramat@kernel.org>
> > > Cc: Adrian Hunter <adrian.hunter@intel.com>
> > > Cc: Kees Cook <keescook@chromium.org>
> > > Cc: Thomas Garnier <thgarnie@google.com>
> > > Cc: Peter Zijlstra <peterz@infradead.org>
> > > Cc: Borislav Petkov <bp@suse.de>
> > > Cc: Dmitry Vyukov <dvyukov@google.com>
> > > Cc: Ravi V. Shankar <ravi.v.shankar@intel.com>
> > > Cc: x86@kernel.org
> > > Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
> > > ---
> > > arch/x86/include/asm/insn-kernel.h | 1 +
> > > arch/x86/lib/insn-kernel.c | 5 +++++
> > > 2 files changed, 6 insertions(+)
> > >
> > > diff --git a/arch/x86/include/asm/insn-kernel.h b/arch/x86/include/asm/insn-kernel.h
> > > index aef416a..3f34649 100644
> > > --- a/arch/x86/include/asm/insn-kernel.h
> > > +++ b/arch/x86/include/asm/insn-kernel.h
> > > @@ -12,5 +12,6 @@
> > > #include <asm/ptrace.h>
> > >
> > > void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs *regs);
> > > +int insn_get_reg_offset_rm(struct insn *insn, struct pt_regs *regs);
> > >
> > > #endif /* _ASM_X86_INSN_KERNEL_H */
> > > diff --git a/arch/x86/lib/insn-kernel.c b/arch/x86/lib/insn-kernel.c
> > > index 8072abe..267cab4 100644
> > > --- a/arch/x86/lib/insn-kernel.c
> > > +++ b/arch/x86/lib/insn-kernel.c
> > > @@ -95,6 +95,11 @@ static int get_reg_offset(struct insn *insn, struct pt_regs *regs,
> > > return regoff[regno];
> > > }
> > >
> > > +int insn_get_reg_offset_rm(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
> > > --
> > > 2.9.3
> > >
> >
> >
>
>
--
Masami Hiramatsu <mhiramat@kernel.org>
next prev parent reply other threads:[~2017-01-27 7:53 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-25 20:23 [v3 PATCH 00/10] x86: Enable User-Mode Instruction Prevention Ricardo Neri
2017-01-25 20:23 ` Ricardo Neri
2017-01-25 20:23 ` [v3 PATCH 01/10] x86/mpx: Do not use SIB index if index points to R/ESP Ricardo Neri
2017-01-25 20:23 ` Ricardo Neri
2017-01-25 20:23 ` [v3 PATCH 02/10] x86/mpx: Fail decoding when SIB baseR/EBP is and no displacement is used Ricardo Neri
2017-01-25 20:23 ` Ricardo Neri
2017-01-25 20:23 ` [v3 PATCH 03/10] x86/mpx, x86/insn: Relocate insn util functions to a new insn-kernel Ricardo Neri
2017-01-25 20:23 ` Ricardo Neri
2017-01-26 2:23 ` Masami Hiramatsu
2017-01-26 2:23 ` Masami Hiramatsu
2017-01-25 20:23 ` [v3 PATCH 04/10] x86/insn-kernel: Add a function to obtain register offset in ModRM Ricardo Neri
2017-01-25 20:23 ` Ricardo Neri
2017-01-26 2:11 ` Masami Hiramatsu
2017-01-26 2:11 ` Masami Hiramatsu
2017-01-26 6:07 ` Ricardo Neri
2017-01-26 6:07 ` Ricardo Neri
2017-01-27 7:53 ` Masami Hiramatsu [this message]
2017-01-27 7:53 ` Masami Hiramatsu
2017-02-01 1:01 ` Ricardo Neri
2017-02-01 1:01 ` Ricardo Neri
2017-01-25 20:23 ` [v3 PATCH 05/10] x86/insn-kernel: Add support to resolve 16-bit addressing encodings Ricardo Neri
2017-01-25 20:23 ` Ricardo Neri
2017-01-25 21:58 ` Andy Lutomirski
2017-01-25 21:58 ` Andy Lutomirski
2017-01-25 22:04 ` H. Peter Anvin
2017-01-25 22:04 ` H. Peter Anvin
2017-01-26 5:50 ` Ricardo Neri
2017-01-26 5:50 ` Ricardo Neri
2017-01-26 17:05 ` Andy Lutomirski
2017-01-26 17:05 ` Andy Lutomirski
2017-01-27 3:44 ` Ricardo Neri
2017-01-27 3:44 ` Ricardo Neri
2017-01-25 20:23 ` [v3 PATCH 06/10] x86/cpufeature: Add User-Mode Instruction Prevention definitions Ricardo Neri
2017-01-25 20:23 ` Ricardo Neri
2017-01-25 20:23 ` [v3 PATCH 07/10] x86: Add emulation code for UMIP instructions Ricardo Neri
2017-01-25 20:23 ` Ricardo Neri
2017-01-25 20:38 ` H. Peter Anvin
2017-01-25 20:38 ` H. Peter Anvin
2017-01-26 5:54 ` Ricardo Neri
2017-01-26 5:54 ` Ricardo Neri
2017-01-25 20:23 ` [v3 PATCH 08/10] x86/traps: Fixup general protection faults caused by UMIP Ricardo Neri
2017-01-25 20:23 ` Ricardo Neri
2017-01-25 20:23 ` [v3 PATCH 09/10] x86: Enable User-Mode Instruction Prevention Ricardo Neri
2017-01-25 20:23 ` Ricardo Neri
2017-01-25 20:23 ` [v3 PATCH 10/10] selftests/x86: Add tests for " Ricardo Neri
2017-01-25 20:23 ` Ricardo Neri
2017-01-25 20:34 ` [v3 PATCH 00/10] x86: Enable " H. Peter Anvin
2017-01-25 20:34 ` H. Peter Anvin
2017-01-26 5:51 ` Ricardo Neri
2017-01-26 5:51 ` Ricardo Neri
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170127165331.616cc678182a697ee0e6dfae@kernel.org \
--to=mhiramat@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bp@suse.de \
--cc=brgerst@gmail.com \
--cc=cmetcalf@mellanox.com \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jslaby@suse.cz \
--cc=julliard@winehq.org \
--cc=liang.z.li@intel.com \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=mst@redhat.com \
--cc=paul.gortmaker@windriver.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=ray.huang@amd.com \
--cc=ricardo.neri-calderon@linux.intel.com \
--cc=slaoub@gmail.com \
--cc=tglx@linutronix.de \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.