Content-Type: multipart/mixed; boundary="===============3242013584272626965==" MIME-Version: 1.0 From: Borislav Petkov To: kbuild-all@lists.01.org Subject: Re: [PATCH v1 11/19] x86/sev-es: Convert to insn_decode() Date: Fri, 25 Dec 2020 13:33:34 +0100 Message-ID: <20201225123334.GA5874@zn.tnic> In-Reply-To: <202012251838.G6eufP3Q-lkp@intel.com> List-Id: --===============3242013584272626965== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable On Fri, Dec 25, 2020 at 06:50:33PM +0800, kernel test robot wrote: > If you fix the issue, kindly add following tag as appropriate > Reported-by: kernel test robot > = > All warnings (new ones prefixed by >>): > = > >> arch/x86/kernel/sev-es.c:258:7: warning: variable 'ret' is used uninit= ialized whenever 'if' condition is false [-Wsometimes-uninitialized] > if (!insn_decode_regs(&ctxt->insn, ctxt->regs, buffer,= res)) > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~= ~~~~~ Yeah, good catch, thanks for reporting. Frankly, the readability and "extensiblity" of that function can be improved by splitting the two cases (diff ontop): --- diff --git a/arch/x86/kernel/sev-es.c b/arch/x86/kernel/sev-es.c index 564cc9fc693d..ea47037f1624 100644 --- a/arch/x86/kernel/sev-es.c +++ b/arch/x86/kernel/sev-es.c @@ -241,40 +241,53 @@ static int vc_fetch_insn_kernel(struct es_em_ctxt *ct= xt, return copy_from_kernel_nofault(buffer, (unsigned char *)ctxt->regs->ip, = MAX_INSN_SIZE); } = -static enum es_result vc_decode_insn(struct es_em_ctxt *ctxt) +static enum es_result __vc_decode_user_insn(struct es_em_ctxt *ctxt) { char buffer[MAX_INSN_SIZE]; - int res, ret; - - if (user_mode(ctxt->regs)) { - res =3D insn_fetch_from_user(ctxt->regs, buffer); - if (!res) { - ctxt->fi.vector =3D X86_TRAP_PF; - ctxt->fi.error_code =3D X86_PF_INSTR | X86_PF_USER; - ctxt->fi.cr2 =3D ctxt->regs->ip; - return ES_EXCEPTION; - } + int res; = - if (!insn_decode_regs(&ctxt->insn, ctxt->regs, buffer, res)) - return ES_DECODE_FAILED; - } else { - res =3D vc_fetch_insn_kernel(ctxt, buffer); - if (res) { - ctxt->fi.vector =3D X86_TRAP_PF; - ctxt->fi.error_code =3D X86_PF_INSTR; - ctxt->fi.cr2 =3D ctxt->regs->ip; - return ES_EXCEPTION; - } + res =3D insn_fetch_from_user(ctxt->regs, buffer); + if (!res) { + ctxt->fi.vector =3D X86_TRAP_PF; + ctxt->fi.error_code =3D X86_PF_INSTR | X86_PF_USER; + ctxt->fi.cr2 =3D ctxt->regs->ip; + return ES_EXCEPTION; + } + + if (!insn_decode_regs(&ctxt->insn, ctxt->regs, buffer, res)) + return ES_DECODE_FAILED; + else + return ES_OK; +} + +static enum es_result __vc_decode_kern_insn(struct es_em_ctxt *ctxt) +{ + char buffer[MAX_INSN_SIZE]; + int res; = - ret =3D insn_decode(&ctxt->insn, buffer, MAX_INSN_SIZE - res, INSN_MODE_= 64); + res =3D vc_fetch_insn_kernel(ctxt, buffer); + if (res) { + ctxt->fi.vector =3D X86_TRAP_PF; + ctxt->fi.error_code =3D X86_PF_INSTR; + ctxt->fi.cr2 =3D ctxt->regs->ip; + return ES_EXCEPTION; } = - if (ret < 0) + res =3D insn_decode(&ctxt->insn, buffer, MAX_INSN_SIZE - res, INSN_MODE_6= 4); + if (res < 0) return ES_DECODE_FAILED; else return ES_OK; } = +static enum es_result vc_decode_insn(struct es_em_ctxt *ctxt) +{ + if (user_mode(ctxt->regs)) + return __vc_decode_user_insn(ctxt); + else + return __vc_decode_kern_insn(ctxt); +} + static enum es_result vc_write_mem(struct es_em_ctxt *ctxt, char *dst, char *buf, size_t size) { -- = Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette --===============3242013584272626965==--