Content-Type: multipart/mixed; boundary="===============6495138997098922705==" MIME-Version: 1.0 From: Sean Christopherson To: kbuild-all@lists.01.org Subject: Re: [PATCH v1 11/19] x86/sev-es: Convert to insn_decode() Date: Mon, 28 Dec 2020 11:15:11 -0800 Message-ID: In-Reply-To: <20201225123334.GA5874@zn.tnic> List-Id: --===============6495138997098922705== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable On Fri, Dec 25, 2020, Borislav Petkov wrote: > 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 unin= itialized whenever 'if' condition is false [-Wsometimes-uninitialized] > > if (!insn_decode_regs(&ctxt->insn, ctxt->regs, buffe= r, 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): Alternatively, could the kernel case use insn_decode_regs()? If vc_fetch_insn_kernel() were also modified to mirror insn_fetch_from_user(),= the two code paths could be unified except for the the fetch and the PFEC. E.g. static int vc_fetch_insn_kernel(struct es_em_ctxt *ctxt, unsigned char *buffer) { if (copy_from_kernel_nofault(buffer, (unsigned char *)ctxt->regs->ip, MAX_= INSN_SIZE)) return 0; return MAX_INSN_SIZE; } static enum es_result vc_decode_insn(struct es_em_ctxt *ctxt) { char buffer[MAX_INSN_SIZE]; int nbytes; if (user_mode(ctxt->regs)) nbytes =3D insn_fetch_from_user(ctxt->regs, buffer); else nbytes =3D vc_fetch_insn_kernel(ctxt, buffer); if (!nbytes) { ctxt->fi.vector =3D X86_TRAP_PF; ctxt->fi.error_code =3D X86_PF_INSTR; if (user_mode(ctxt->regs)) ctxt->fi.error_code |=3D X86_PF_USER; ctxt->fi.cr2 =3D ctxt->regs->ip; return ES_EXCEPTION; } if (!insn_decode_regs(&ctxt->insn, ctxt->regs, buffer, nbytes)) return ES_DECODE_FAILED; return ctxt->insn.immediate.got ? ES_OK : ES_DECODE_FAILED; } --===============6495138997098922705==--