From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752805AbdDLKDd (ORCPT ); Wed, 12 Apr 2017 06:03:33 -0400 Received: from mx2.suse.de ([195.135.220.15]:37956 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751876AbdDLKDb (ORCPT ); Wed, 12 Apr 2017 06:03:31 -0400 Date: Wed, 12 Apr 2017 12:03:08 +0200 From: Borislav Petkov To: Ricardo Neri 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 Subject: Re: [v6 PATCH 04/21] x86/mpx, x86/insn: Relocate insn util functions to a new insn-kernel Message-ID: <20170412100308.uuai3hf3l2fsavhb@pd.tnic> References: <20170308003254.27833-1-ricardo.neri-calderon@linux.intel.com> <20170308003254.27833-5-ricardo.neri-calderon@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20170308003254.27833-5-ricardo.neri-calderon@linux.intel.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 07, 2017 at 04:32:37PM -0800, Ricardo Neri wrote: > Other kernel submodules can benefit from using the utility functions > defined in mpx.c to obtain the addresses and values of operands contained > in the general purpose registers. An instance of this is the emulation code > used for instructions protected by the Intel User-Mode Instruction > Prevention feature. > > Thus, these functions are relocated to a new insn-eval.c file. The reason > to not relocate these utilities into insn.c is that the latter solely > analyses instructions given by a struct insn without any knowledge of the > meaning of the values of instruction operands. This new utility insn- > eval.c aims to be used to resolve effective and userspace linear addresses > based on the contents of the instruction operands as well as the contents > of pt_regs structure. > > These utilities come with a separate header. This is to avoid taking insn.c > out of sync from the instructions decoders under tools/obj and tools/perf. > This also avoids adding cumbersome #ifdef's for the #include'd files > required to decode instructions in a kernel context. > > Functions are simply relocated. There are not functional or indentation > changes. ... > + case REG_TYPE_BASE: > + regno = X86_SIB_BASE(insn->sib.value); > + /* > + * If mod is 0 and register R/EBP (regno=5) is indicated in the > + * base part of the SIB byte, the value of such register should > + * not be used in the address computation. Also, a 32-bit > + * displacement is expected in this case; the instruction > + * decoder takes care of it. This is true for both R13 and > + * R/EBP as REX.B will not be decoded. > + */ > + if (regno == 5 && X86_MODRM_MOD(insn->modrm.value) == 0) > + return -EDOM; > + > + if (X86_REX_B(insn->rex_prefix.value)) > + regno += 8; > + break; > + > + default: > + pr_err("invalid register type"); > + BUG(); WARNING: Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() or BUG_ON() #211: FILE: arch/x86/lib/insn-eval.c:90: + BUG(); And checkpatch is kinda right. We need to warn here, not explode. Oh and that function returns negative values on error... Please change that with a patch ontop of the move. Thanks. -- Regards/Gruss, Boris. SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg) --