From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752386AbdJLS1v (ORCPT ); Thu, 12 Oct 2017 14:27:51 -0400 Received: from mga14.intel.com ([192.55.52.115]:21459 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750722AbdJLS1u (ORCPT ); Thu, 12 Oct 2017 14:27:50 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,367,1503385200"; d="scan'208";a="161998970" Message-ID: <1507832835.17492.43.camel@linux.intel.com> Subject: Re: [PATCH v9 16/29] x86/insn-eval: Add function to get default params of code segment 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 , "Ravi V. Shankar" , Shuah Khan , linux-kernel@vger.kernel.org, x86@kernel.org, Adam Buchbinder , Colin Ian King , Lorenzo Stoakes , Qiaowei Ren , Arnaldo Carvalho de Melo , Adrian Hunter , Kees Cook , Thomas Garnier , Dmitry Vyukov Date: Thu, 12 Oct 2017 11:27:15 -0700 In-Reply-To: <20171012163141.mekj5hemwtkpxh32@pd.tnic> References: <1507089272-32733-1-git-send-email-ricardo.neri-calderon@linux.intel.com> <1507089272-32733-17-git-send-email-ricardo.neri-calderon@linux.intel.com> <20171012163141.mekj5hemwtkpxh32@pd.tnic> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2017-10-12 at 18:31 +0200, Borislav Petkov wrote: > On Tue, Oct 03, 2017 at 08:54:19PM -0700, Ricardo Neri wrote: > > > > Obtain the default values of the address and operand sizes as specified in > > the D and L bits of the the segment descriptor selected by the register > > CS. The function can be used for both protected and long modes. > > For virtual-8086 mode, the default address and operand sizes are always 2 > > bytes. > > > > The returned parameters are encoded in a signed 8-bit data type. Auxiliar > > macros are provided to encode and decode such values. > > > > 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 |  5 ++++ > >  arch/x86/lib/insn-eval.c         | 64 > > ++++++++++++++++++++++++++++++++++++++++ > >  2 files changed, 69 insertions(+) > Some cleanups ontop: > > --- > diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c > index 64924b7d5fff..3352b9d5164f 100644 > --- a/arch/x86/lib/insn-eval.c > +++ b/arch/x86/lib/insn-eval.c > @@ -614,14 +614,14 @@ static unsigned long get_seg_limit(struct pt_regs *regs, > int seg_reg_idx) >  } >   >  /** > - * insn_get_code_seg_defaults() - Obtain code segment default parameters > + * insn_get_code_seg_params() - Obtain code segment parameters >   * @regs: Structure with register values as seen when entering kernel > mode >   * > - * Obtain the default parameters of the code segment: address and operand > sizes. > - * The code segment is obtained from the selector contained in the CS > register > - * in regs. In protected mode, the default address is determined by > inspecting > - * the L and D bits of the segment descriptor. In virtual-8086 mode, the > default > - * is always two bytes for both address and operand sizes. > + * Obtain address and operand sizes of the code segment. It is obtained from > the > + * selector contained in the CS register in regs. In protected mode, the > default > + * address is determined by inspecting the L and D bits of the segment > descriptor. > + * In virtual-8086 mode, the default is always two bytes for both address and > + * operand sizes. >   * >   * Returns: >   * > @@ -629,7 +629,7 @@ static unsigned long get_seg_limit(struct pt_regs *regs, > int seg_reg_idx) >   * >   * -EINVAL on error. >   */ > -char insn_get_code_seg_defaults(struct pt_regs *regs) > +char insn_get_code_seg_params(struct pt_regs *regs) >  { >   struct desc_struct *desc; >   short sel; > @@ -640,7 +640,7 @@ char insn_get_code_seg_defaults(struct pt_regs *regs) >   >   sel = get_segment_selector(regs, INAT_SEG_REG_CS); >   if (sel < 0) > - return -1L; > + return sel; Thanks! I implemente these changes along with your Improvements-by. BR, Ricardo